testexecfw/stf/stfext/testmodules/scriptermod/src/TestScripter.cpp
changeset 2 8bb370ba6d1d
equal deleted inserted replaced
1:bbd31066657e 2:8bb370ba6d1d
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 * 
       
    14 * Description: This file contains TestScripter implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include <StifTestEventInterface.h>
       
    20 #include <StifLogger.h>
       
    21 #include "TestScripter.h"
       
    22 #include "TestKeywords.h"
       
    23 #include "Logging.h"
       
    24 #include "TestEngineClient.h"
       
    25 #include "SettingServerClient.h"
       
    26 #include "TestScripterInternal.h"
       
    27 #include "SubTestCaseRunner.h"
       
    28 #include <stifinternal/TestServerClient.h>
       
    29 
       
    30 
       
    31 #include <stifinternal/UiEnvProxy.h>
       
    32 
       
    33 // EXTERNAL DATA STRUCTURES
       
    34 // None
       
    35 
       
    36 // EXTERNAL FUNCTION PROTOTYPES  
       
    37 // None
       
    38 
       
    39 // CONSTANTS
       
    40 // None
       
    41 
       
    42 const TUid KPropertyCat =
       
    43     {
       
    44     0x101FB3DE
       
    45     };
       
    46 const TUint KPropertyKey = 0x00000001;
       
    47 // MACROS
       
    48 #ifdef LOGGER
       
    49 #undef LOGGER
       
    50 #endif
       
    51 #define LOGGER iLog
       
    52 
       
    53 // LOCAL CONSTANTS AND MACROS
       
    54 _LIT( KExecute, "Execute");
       
    55 // Printing priorities
       
    56 const TInt KPrintPriExec = 400;
       
    57 
       
    58 // MODULE DATA STRUCTURES
       
    59 // None
       
    60 
       
    61 // LOCAL FUNCTION PROTOTYPES
       
    62 // None
       
    63 
       
    64 // FORWARD DECLARATIONS
       
    65 // None
       
    66 
       
    67 // ==================== LOCAL FUNCTIONS =======================================
       
    68 
       
    69 /*
       
    70 -------------------------------------------------------------------------------
       
    71 
       
    72      Class: -
       
    73 
       
    74      Method: CallBack
       
    75 
       
    76      Description: (Function pointer) Called from CScriptBase class. Generic
       
    77                   method for call back operations from Test Script Class to
       
    78                   TestScripter.
       
    79   
       
    80      Parameters: CTestScripter* aTestScripter: in: Pointer to TestScripter
       
    81                  TStifTSCallBackType aCallType: in: Call back type
       
    82                  const TDesC& aLine: in Script line
       
    83                     
       
    84      Return Values: TInt: Symbian error code
       
    85 
       
    86      Errors/Exceptions: None
       
    87 
       
    88      Status: Draft
       
    89     
       
    90 -------------------------------------------------------------------------------
       
    91 */
       
    92 TInt CallBack( CTestScripter* aTestScripter,
       
    93                 TStifTSCallBackType aCallType,
       
    94                 const TDesC& aLine )
       
    95     {
       
    96     TInt ret( 0 );
       
    97     switch( aCallType )
       
    98         {
       
    99         case EStifTSCallClass:
       
   100             {
       
   101             ret = aTestScripter->CallTestClass( aLine );
       
   102             break;
       
   103             }
       
   104         case EStifTSGetObject:
       
   105             {
       
   106             ret = aTestScripter->GetTestScriptObject( aLine );
       
   107             break;
       
   108             }
       
   109         default:
       
   110             {
       
   111             ret = KErrArgument;
       
   112             break;
       
   113             }
       
   114         }
       
   115 
       
   116     return ret;
       
   117 
       
   118     }
       
   119 
       
   120 /*
       
   121 -------------------------------------------------------------------------------
       
   122 
       
   123     DESCRIPTION
       
   124 
       
   125     This module contains the implementation of CTestScripter class 
       
   126     member functions.
       
   127 
       
   128 -------------------------------------------------------------------------------
       
   129 */
       
   130 
       
   131 // ================= MEMBER FUNCTIONS =========================================
       
   132 
       
   133 /*
       
   134 -------------------------------------------------------------------------------
       
   135 
       
   136      Class: CTestScripter
       
   137 
       
   138      Method: CTestScripter
       
   139 
       
   140      Description: Default constructor
       
   141 
       
   142      C++ default constructor can NOT contain any code, that
       
   143      might leave.
       
   144      
       
   145      Parameters:    None
       
   146 
       
   147      Return Values: None
       
   148 
       
   149      Errors/Exceptions: None
       
   150 
       
   151  Status: Draft
       
   152  
       
   153  -------------------------------------------------------------------------------
       
   154  */
       
   155 CTestScripter::CTestScripter() :
       
   156     iObjects(NULL)
       
   157     {
       
   158 
       
   159     }
       
   160 
       
   161 /*
       
   162 -------------------------------------------------------------------------------
       
   163 
       
   164      Class: CTestScripter
       
   165 
       
   166      Method: ConstructL
       
   167 
       
   168      Description: Symbian OS second phase constructor
       
   169 
       
   170      Symbian OS default constructor can leave.
       
   171 
       
   172      Parameters:    None
       
   173 
       
   174      Return Values: None
       
   175 
       
   176      Errors/Exceptions: None.
       
   177 
       
   178      Status: Draft
       
   179 
       
   180 -------------------------------------------------------------------------------
       
   181 */
       
   182 void CTestScripter::ConstructL()
       
   183     {
       
   184     __TRACE( KPrint, ( _L("New TestScripter") ) );
       
   185     iStdLog = CStifLogger::NewL( KTestScripterLogDir,
       
   186                                 KTestScripterLogFile );
       
   187     iLog = iStdLog;
       
   188 
       
   189     iOOMIgnoreFailure = EFalse; // OFF for default
       
   190 
       
   191     iCheckHeapBalance = EFalse; // No checking heap balance by default
       
   192 
       
   193     //Read logger settings to check whether test case name is to be
       
   194     //appended to log file name.
       
   195     RSettingServer settingServer;
       
   196     TInt ret = settingServer.Connect();
       
   197     if(ret != KErrNone)
       
   198         {
       
   199         User::Leave(ret);
       
   200         }
       
   201     // Struct to StifLogger settigs.
       
   202     TLoggerSettings loggerSettings; 
       
   203     // Parse StifLogger defaults from STIF initialization file.
       
   204     ret = settingServer.GetLoggerSettings(loggerSettings);
       
   205     if(ret != KErrNone)
       
   206         {
       
   207         User::Leave(ret);
       
   208         } 
       
   209     // Close Setting server session
       
   210     settingServer.Close();
       
   211     iAddTestCaseTitleToLogName = loggerSettings.iAddTestCaseTitle;
       
   212     
       
   213     // Initialize parser variables
       
   214     iCurrentParser = NULL;
       
   215     iCurrentParserReadFirstLine = EFalse;
       
   216 
       
   217     TUint ProperKey = RProcess().Id().Id();
       
   218     TInt err = RProperty::Define(KPropertyCat, ProperKey, RProperty::EInt);
       
   219 
       
   220     iObjects = new (ELeave) RPointerArray<TScriptObject> ;
       
   221     err = RProperty::Set(KPropertyCat, ProperKey, (TInt) iObjects);
       
   222     User::LeaveIfError(err);
       
   223     }
       
   224 
       
   225 /*
       
   226 -------------------------------------------------------------------------------
       
   227 
       
   228      Class: CTestScripter
       
   229 
       
   230      Method: NewL
       
   231 
       
   232      Description: Two-phased constructor.
       
   233           
       
   234      Parameters:    None
       
   235 
       
   236      Return Values: CTestScripter*: new object
       
   237 
       
   238      Errors/Exceptions: Leaves if new or ConstructL leaves.
       
   239 
       
   240      Status: Draft
       
   241     
       
   242 -------------------------------------------------------------------------------
       
   243 */
       
   244 CTestScripter* CTestScripter::NewL()
       
   245     {
       
   246      
       
   247     CTestScripter* self = new (ELeave) CTestScripter();
       
   248     
       
   249     CleanupStack::PushL( self );
       
   250     self->ConstructL();
       
   251     CleanupStack::Pop();
       
   252 
       
   253     return self;
       
   254      
       
   255     }
       
   256 
       
   257 /*
       
   258 -------------------------------------------------------------------------------
       
   259 
       
   260      Class: CTestScripter
       
   261 
       
   262      Method: ~CTestScripter
       
   263 
       
   264      Description: Destructor
       
   265      
       
   266      Parameters:    None
       
   267 
       
   268      Return Values: None
       
   269 
       
   270      Errors/Exceptions: None
       
   271 
       
   272      Status: Draft
       
   273     
       
   274 -------------------------------------------------------------------------------
       
   275 */
       
   276 CTestScripter::~CTestScripter()
       
   277     {
       
   278     iTestObjects.ResetAndDestroy();
       
   279     iTestModules.ResetAndDestroy();
       
   280     iDefinedIni.ResetAndDestroy();
       
   281     iDefinedRuntime.ResetAndDestroy();
       
   282     iDefinedLocal.ResetAndDestroy();
       
   283     iParserStack.ResetAndDestroy();
       
   284     iGlobalObjects.ResetAndDestroy();
       
   285     iSharedTestModules.ResetAndDestroy();
       
   286     iObjects->Reset();
       
   287     iTestObjects.Close();
       
   288     iTestModules.Close();
       
   289     iDefinedIni.Close();
       
   290     iGlobalObjects.Close();
       
   291     iDefinedRuntime.Close();
       
   292     iDefinedLocal.Close();
       
   293     iParserStack.Close();
       
   294     iObjects->Close();
       
   295     iSharedTestModules.Close();
       
   296 
       
   297     iCurrentParser = NULL;
       
   298     delete iSectionParser;
       
   299     delete iTestRunner;
       
   300     delete iObjects;
       
   301 
       
   302     iLog = NULL;
       
   303     delete iStdLog;
       
   304     iStdLog = NULL;
       
   305     delete iTCLog;
       
   306     iTCLog = NULL;   
       
   307     
       
   308     TUint ProperKey = RProcess().Id().Id(); 
       
   309     TInt err = RProperty::Delete(KPropertyCat, ProperKey);
       
   310     }
       
   311 
       
   312 /*
       
   313 -------------------------------------------------------------------------------
       
   314 
       
   315      Class: CTestScripter
       
   316 
       
   317      Method: InitL
       
   318 
       
   319      Description: InitL is used to initialize the Test Module.
       
   320 
       
   321      Parameters: const TFileName& aIniFile: in: Initialization file
       
   322                  TBool aFirstTime: in: First time flag 
       
   323                          
       
   324      Return Values: Symbian OS error code
       
   325 
       
   326      Errors/Exceptions: Leaves if ReadInitializationL leaves
       
   327      
       
   328      Status: Draft
       
   329 
       
   330 -------------------------------------------------------------------------------
       
   331 */        
       
   332 TInt CTestScripter::InitL( TFileName& aIniFile, 
       
   333                            TBool /*aFirstTime*/ )
       
   334     {
       
   335  
       
   336     __TRACEFUNC();
       
   337  
       
   338     if( aIniFile.Length() > 0 )
       
   339         {
       
   340         // Read initialization from test case file
       
   341         ReadInitializationL( aIniFile, iDefinedIni );
       
   342         }
       
   343         
       
   344     return KErrNone;
       
   345     
       
   346     }
       
   347 
       
   348 /*
       
   349 -------------------------------------------------------------------------------
       
   350 
       
   351      Class: CTestScripter
       
   352 
       
   353      Method: GetTestCases
       
   354 
       
   355      Description: GetTestCases is used to inquired test cases
       
   356 
       
   357      Parameters:    const TFileName& aConfigFile: in: Test case file
       
   358                     RPointerArray<RTestEngine::TTestCaseInfo>& aTestCases: out: 
       
   359                           Array of TestCases 
       
   360      
       
   361      Return Values: KErrNone: Success
       
   362                     Symbian OS error code
       
   363 
       
   364      Errors/Exceptions: Leaves if CStifParser::SectionL leaves
       
   365                         Leaves if CStifParser::NextSectionL leaves
       
   366                         Leaves if memory allocation fails
       
   367 
       
   368      Status: Draft
       
   369     
       
   370 -------------------------------------------------------------------------------
       
   371 */        
       
   372 TInt CTestScripter::GetTestCasesL( const TFileName& aConfigFile, 
       
   373                                    RPointerArray<TTestCaseInfo>& aTestCases )
       
   374     {
       
   375     __TRACEFUNC();
       
   376     
       
   377     if( aConfigFile.Length() == 0 )
       
   378         {
       
   379         __TRACE( KError, (_L("No test case script file given") ) );
       
   380         __RDEBUG( (_L("No test case script file given") ) );
       
   381         return KErrNotFound;
       
   382         }
       
   383 
       
   384     CStifParser* parser = NULL; 
       
   385     
       
   386     // Open test case file
       
   387     TRAPD( err, 
       
   388         parser = CStifParser::NewL( _L(""), 
       
   389                                     aConfigFile, 
       
   390                                     CStifParser::ECStyleComments ) );
       
   391     if( err != KErrNone )
       
   392         {
       
   393         __TRACE( KError, (_L("Given test case script file [%S] not found"),
       
   394             &aConfigFile ) );
       
   395         __RDEBUG( (_L("Given test case script file [%S] not found"),
       
   396             &aConfigFile ) );
       
   397         return err;
       
   398         }
       
   399         
       
   400     CleanupStack::PushL( parser );
       
   401     CStifSectionParser* section;
       
   402     TPtrC tmp;
       
   403     TInt index = 0;
       
   404     TInt ret = KErrNone;
       
   405 
       
   406     // Find first section
       
   407     section = parser->SectionL( KTestStartTag, KTestEndTag );
       
   408     if( section == NULL )
       
   409         {
       
   410         ret = KErrNotFound;
       
   411         }
       
   412     else
       
   413         {    
       
   414         // Parse all sections
       
   415         while( section )
       
   416             {
       
   417             CleanupStack::PushL( section );
       
   418              
       
   419             // Get title line
       
   420             if( section->GetLine( TTestKeywords::Keyword( TTestKeywords::ETitle ),
       
   421                 tmp, ENoTag ) != KErrNone )
       
   422                 {
       
   423                 __TRACE( KError, (_L("Title not given for test case")));
       
   424                 User::Leave( KErrNotFound );
       
   425                 }
       
   426             else
       
   427                 {
       
   428                 if( tmp.Length() > KMaxName )
       
   429                     {
       
   430                     tmp.Set( tmp.Left( KMaxName ) );
       
   431                     }   
       
   432                 TTestCaseInfo* tc = new ( ELeave ) TTestCaseInfo();
       
   433                 CleanupStack::PushL( tc );
       
   434                 __TRACE( KVerbose, (_L("TestCase: %S"), &tmp));
       
   435                 tc->iTitle.Copy( tmp );
       
   436                 tc->iCaseNumber = ++index;
       
   437                  
       
   438                  // Get timeout if defined
       
   439                 CStifItemParser* item = section->GetItemLineL(  
       
   440                    TTestKeywords::Keyword( TTestKeywords::ETimeout ) );
       
   441                 if( item )
       
   442                     {
       
   443                     TInt timeout; // In milliseconds
       
   444                     ret = item->GetInt( 
       
   445                         TTestKeywords::Keyword( TTestKeywords::ETimeout ), 
       
   446                         timeout ); 
       
   447                     if( ret != KErrNone )
       
   448                         {
       
   449                         __TRACE( KError, (_L("Illegal timeout")));
       
   450                         User::Leave( ret ); 
       
   451                         }
       
   452                         
       
   453                     // Type cast timeout to TInt64    
       
   454                     tc->iTimeout = TInt64( timeout ) * 1000;
       
   455                     __TRACE( KMessage, (_L("Timeout: %i"), tc->iTimeout.Int64() ));
       
   456                     }
       
   457                     
       
   458                  // Get priority if defined
       
   459                 item = section->GetItemLineL(  
       
   460                    TTestKeywords::Keyword( TTestKeywords::EPriority ) );
       
   461                 if( item )
       
   462                     {
       
   463                     // First try to interpret as integer
       
   464                     ret = item->GetInt( 
       
   465                         TTestKeywords::Keyword( TTestKeywords::EPriority ), 
       
   466                         tc->iPriority ); 
       
   467                     if( ret != KErrNone )
       
   468                         {
       
   469                         TPtrC priority;
       
   470                         // If priority was not given as integer, it must be 
       
   471                         // one of the predefined values
       
   472                         ret = item->GetString( 
       
   473                             TTestKeywords::Keyword( TTestKeywords::EPriority ),
       
   474                             priority );
       
   475                         if( ret != KErrNone )
       
   476                             {
       
   477                             __TRACE( KError, (_L("Illegal priority")));
       
   478                             User::Leave( ret ); 
       
   479                             }
       
   480                         switch( TTestKeywords::Parse( priority, 
       
   481                                                        TTestKeywords::Priority ) )
       
   482                             {
       
   483                             case TTestKeywords::EPriHigh:
       
   484                                 tc->iPriority = TTestCaseInfo::EPriorityHigh;
       
   485                                 break;
       
   486                             case TTestKeywords::EPriNormal:
       
   487                                 tc->iPriority = TTestCaseInfo::EPriorityNormal;
       
   488                                 break;
       
   489                             case TTestKeywords::EPriLow:
       
   490                                 tc->iPriority = TTestCaseInfo::EPriorityLow;
       
   491                                 break;
       
   492                             default:
       
   493                                 __TRACE( KError, (_L("Illegal priority")));
       
   494                                 User::Leave( KErrArgument ); 
       
   495                             }
       
   496                         }
       
   497                     __TRACE( KMessage, (_L("Priority: %i"), tc->iPriority ));
       
   498                     }
       
   499                     
       
   500                 aTestCases.Append(tc);
       
   501                 CleanupStack::Pop( tc );
       
   502                 }
       
   503             CleanupStack::PopAndDestroy( section );
       
   504             section = parser->NextSectionL( KTestStartTag, KTestEndTag );
       
   505             }
       
   506         }
       
   507           
       
   508     CleanupStack::PopAndDestroy( parser );
       
   509 
       
   510     __TRACE( KPrint, (  _L( "Configfile '%S', testcases %d" ),
       
   511         &aConfigFile, index ));     
       
   512      
       
   513     return ret;
       
   514      
       
   515     }
       
   516 
       
   517 /*
       
   518 -------------------------------------------------------------------------------
       
   519 
       
   520      Class: CTestScripter
       
   521 
       
   522      Method: GetConstantValue
       
   523 
       
   524      Description: Internal fuction to get const value defined in 
       
   525                   [Define]...[Enddefine] section of script file
       
   526 
       
   527      GetConstantValue gets const value defined in [Define]...[Enddefine] 
       
   528      section of script file
       
   529 
       
   530      Parameters:    const TDesC& aName: in: constant name 
       
   531                     TDes& avalue: out: constant value
       
   532 
       
   533      Return Values: KErrNone: Value is returned succesfully.
       
   534                     KErrNotFound: Constant was not found
       
   535                     Any other SymbianOS error
       
   536                     
       
   537 -------------------------------------------------------------------------------
       
   538 */
       
   539 EXPORT_C TInt CTestScripter::GetConstantValue( const TDesC& aName, TDes& aValue )
       
   540     {
       
   541     
       
   542     __TRACEFUNC();
       
   543 
       
   544     TInt count = iDefinedLocal.Count();
       
   545     for(TInt i = 0; i < count; i++)
       
   546         {
       
   547         if(iDefinedLocal[i]->Name() == aName)
       
   548             {
       
   549             aValue.Copy(iDefinedLocal[i]->Value());
       
   550             return KErrNone;
       
   551             }
       
   552         }   
       
   553 
       
   554       count = iDefinedIni.Count();
       
   555     for( TInt i = 0; i < count; i++ )
       
   556         {
       
   557         if( iDefinedIni[i]->Name() == aName )
       
   558             {
       
   559             aValue.Copy( iDefinedIni[i]->Value() );
       
   560             return KErrNone;
       
   561             }
       
   562         }   
       
   563     
       
   564     count = iDefinedRuntime.Count();
       
   565     for( TInt i = 0; i < count; i++ )
       
   566         {
       
   567         if( iDefinedRuntime[i]->Name() == aName )
       
   568             {
       
   569             aValue.Copy( iDefinedRuntime[i]->Value() );
       
   570             return KErrNone;
       
   571             }
       
   572         }   
       
   573     return KErrNotFound;
       
   574     }
       
   575 
       
   576 
       
   577 /*
       
   578 -------------------------------------------------------------------------------
       
   579 
       
   580      Class: CTestScripter
       
   581 
       
   582      Method: RunTestCaseL
       
   583 
       
   584      Description: Run a specified testcase.
       
   585 
       
   586      RunTestCaseL is used to run an individual test case. 
       
   587   
       
   588      Parameters:    const TInt aCaseNumber: in: Testcase number 
       
   589                     const TFileName& aConfig: in: Test case file
       
   590                     TTestResult& aResult: out: test case result
       
   591 
       
   592      Return Values: KErrNone: Test case started succesfully.
       
   593                     KErrNotFound: Testcase not found
       
   594                     KErrUnknown: Unknown TestScripter error
       
   595                     Any other SymbianOS error
       
   596 
       
   597      Errors/Exceptions: Leaves if GetTestCaseL leaves
       
   598                         Leaves if RunTestL leaves
       
   599                         Leaves if memory allocation fails
       
   600      
       
   601      Status: Draft
       
   602 
       
   603 -------------------------------------------------------------------------------
       
   604 */
       
   605 TInt CTestScripter::RunTestCaseL( const TInt aCaseNumber,
       
   606                                   const TFileName& aConfig,
       
   607                                   TTestResult& aResult )
       
   608     {
       
   609 
       
   610     // Heap is checked by test server
       
   611     //__UHEAP_MARK;
       
   612 
       
   613     __TRACEFUNC();
       
   614 
       
   615     //Open new log file with test case title in file name
       
   616     if(iAddTestCaseTitleToLogName)
       
   617         {
       
   618         //Delete test case logger if exists
       
   619         if(iTCLog)
       
   620             {
       
   621             delete iTCLog;
       
   622             iTCLog = NULL;
       
   623             }
       
   624             
       
   625         TFileName logFileName;
       
   626         TName title;
       
   627         TestModuleIf().GetTestCaseTitleL(title);
       
   628         
       
   629         logFileName.Format(KTestScripterLogFileWithTitle, &title);
       
   630         iTCLog = CStifLogger::NewL(KTestScripterLogDir, logFileName);
       
   631         iLog = iTCLog;
       
   632         }
       
   633 
       
   634     __TRACE( KMessage, (_L("\n\n***Testcase started***")));
       
   635 
       
   636     // Remove locally defined variables 
       
   637     iDefinedLocal.ResetAndDestroy();
       
   638     // Remove existing function parsers (there shouldn't be any)
       
   639     iParserStack.ResetAndDestroy();
       
   640     
       
   641     // Keep file name of config file
       
   642     iConfig = aConfig;
       
   643 
       
   644     // Read initialization from test case file
       
   645     ReadInitializationL( aConfig, iDefinedRuntime );
       
   646 
       
   647     // Get case from test case file
       
   648     iSectionParser = GetTestCaseL( aCaseNumber, aConfig );
       
   649     iCurrentParser = iSectionParser;
       
   650     iCurrentParserReadFirstLine = EFalse;
       
   651 
       
   652     // Check parsing result
       
   653     if( iSectionParser == NULL )
       
   654         {
       
   655         __TRACE( KError, (_L("***Parsing testcase failed***\n\n")));
       
   656         // Delete runtime defines
       
   657         iDefinedRuntime.ResetAndDestroy();
       
   658         //__UHEAP_MARKEND;
       
   659         return KErrNotFound;
       
   660         }
       
   661 
       
   662     // When option is set in cfg file, on EKA2 env memory leaking is enabled
       
   663     TInt memCellsBef = 0; //memory in current thread allocated before the test case is run
       
   664     TInt memCellsAft = 0; //memory in current thread allocated after the test case has run
       
   665 
       
   666     memCellsBef = User::Heap().Count();
       
   667     __TRACE(KMessage, (_L("Allocated memory cells before the test case: %d"), memCellsBef));
       
   668     
       
   669     __TRACE(KMessage, (_L("Memory usage in global objects before the execution:")));
       
   670     TInt beforeGlobalMemCells = TraceGlobalObjectsMemoryUsage();
       
   671         
       
   672 
       
   673     CActiveScheduler* activeScheduler =
       
   674         new ( ELeave ) CActiveScheduler();
       
   675     CleanupStack::PushL( activeScheduler );
       
   676      
       
   677     if ( CActiveScheduler::Current() == NULL )
       
   678         {
       
   679         CActiveScheduler::Install( activeScheduler );
       
   680         }
       
   681 
       
   682     // Run the given testcase described in iSectionParser section
       
   683     RunTestL();
       
   684 
       
   685     iTestObjects.ResetAndDestroy();
       
   686     iTestModules.ResetAndDestroy();
       
   687     iObjects->Reset();
       
   688 
       
   689     // TestScripter must stop Active Scheduler after test
       
   690     // object is destroyed. Otherwise if unexpected error occurs
       
   691     // handling is erronous.
       
   692     CleanupStack::PopAndDestroy( activeScheduler );
       
   693 
       
   694     // Check for memory leak.
       
   695     // It is reported in log always, but result of test case is changed only
       
   696     // when option in cfg file is enabled.
       
   697     memCellsAft = User::Heap().Count();
       
   698     __TRACE(KMessage, (_L("Allocated memory cells after the test case: %d"), memCellsAft));
       
   699 
       
   700 
       
   701     __TRACE(KMessage, (_L("Memory usage in global objects after the execution:")));
       
   702     TInt afterGlobalMemCells = TraceGlobalObjectsMemoryUsage();
       
   703         
       
   704     memCellsAft = memCellsAft - afterGlobalMemCells + beforeGlobalMemCells; 
       
   705     
       
   706     // if there is a difference report memory leak
       
   707     if(memCellsAft != memCellsBef)
       
   708         {
       
   709         __TRACE(KError, (_L("Memory leak, %d cell(s) is missing"), memCellsAft - memCellsBef));
       
   710         if(iCheckHeapBalance)
       
   711             {
       
   712             // Memory leaks detection is disabled for UI components testing
       
   713             if ( !( TestModuleIf().UITesting() ) )
       
   714                 {
       
   715                 UpdateTestCaseResult(KErrGeneral, _L("Memory leak has occured"));
       
   716                 }
       
   717             }
       
   718         }
       
   719 
       
   720     // Delete parser and set current parser to NULL
       
   721     iCurrentParser = NULL;
       
   722     delete iSectionParser;
       
   723     iSectionParser = NULL;  
       
   724     
       
   725     // Erase config file name
       
   726     iConfig = KNullDesC; 
       
   727     
       
   728     // Return result 
       
   729     aResult = iResult;
       
   730     
       
   731     if( iResult.iResult == KErrNone )
       
   732         {
       
   733         __TRACE( KPrint, (_L("***Testcase PASSED***\n\n")));
       
   734         TestModuleIf().Printf( KPrintPriNorm, _L("TestScripter"), 
       
   735             _L("***Testcase PASSED***\n\n"));
       
   736         }
       
   737     else
       
   738         {        
       
   739         __TRACE( KPrint, (_L("***Testcase FAILED***\n\n")));
       
   740         TestModuleIf().Printf( KPrintPriNorm, _L("TestScripter"), 
       
   741             _L("***Testcase FAILED***\n\n"));
       
   742         }
       
   743     User::After(300000);
       
   744     // Delete runtime defines
       
   745     iDefinedRuntime.ResetAndDestroy();
       
   746     
       
   747     //__UHEAP_MARKEND;
       
   748              
       
   749     //If log was replaced then restore it
       
   750     if(iAddTestCaseTitleToLogName)
       
   751         {
       
   752         iLog = iStdLog;
       
   753         delete iTCLog;
       
   754         iTCLog = NULL;
       
   755         }
       
   756     
       
   757     return KErrNone;
       
   758      
       
   759     }
       
   760 
       
   761 TInt CTestScripter::TraceGlobalObjectsMemoryUsage()
       
   762     {
       
   763     __TRACEFUNC();
       
   764     
       
   765     TInt moduleNumber = iSharedTestModules.Count();
       
   766     TInt shareObjNumber = iGlobalObjects.Count();
       
   767     __TRACE(KMessage, (_L("There are %d item(s) in shared modules list"),moduleNumber));
       
   768     __TRACE(KMessage, (_L("There are %d item(s) in shared objects list"),shareObjNumber));
       
   769     
       
   770     TInt listNumber = 0;
       
   771     
       
   772     if(moduleNumber != 0)
       
   773         {
       
   774         listNumber++;
       
   775         __TRACE(KMessage, (_L("Shared module list used 1 cell.")));        
       
   776         __TRACE(KMessage, (_L("There are %d shared module(s), they used %d cells"), moduleNumber , moduleNumber * 2));        
       
   777         }
       
   778 
       
   779     if(shareObjNumber != 0)
       
   780         {
       
   781         listNumber++;
       
   782         __TRACE(KMessage, (_L("Shared object list used 1 cell.")));        
       
   783         __TRACE(KMessage, (_L("There are %d shared object(s), they used %d cells"), shareObjNumber, shareObjNumber * 4));     
       
   784         }
       
   785     TInt result = listNumber + moduleNumber * 2 + shareObjNumber * 4;
       
   786     __TRACE(KMessage, (_L("There are %d cells used by shared objects and their modules."), result));        
       
   787             
       
   788     return result;
       
   789     }
       
   790 
       
   791 /*
       
   792 -------------------------------------------------------------------------------
       
   793 
       
   794      Class: CTestScripter
       
   795 
       
   796      Method: ReadInitializationL
       
   797 
       
   798      Description: Read initialization from file.
       
   799 
       
   800      Parameters:    const TDesC& aIniFile: in: File that contains initialization
       
   801                     
       
   802      Return Values: None
       
   803      
       
   804      Errors/Exceptions: None
       
   805      
       
   806      Status: Draft
       
   807 
       
   808 -------------------------------------------------------------------------------
       
   809 */
       
   810 void CTestScripter::ReadInitializationL(
       
   811     const TDesC& aIniFile,
       
   812     RPointerArray<CDefinedValue>& aDefines )
       
   813     {
       
   814 
       
   815     CStifParser* parser = NULL;
       
   816 
       
   817     // Open file
       
   818     TRAPD( err,
       
   819         parser = CStifParser::NewL( _L(""),
       
   820                                     aIniFile,
       
   821                                     CStifParser::ECStyleComments ) );
       
   822     if( ( err == KErrNone ) && parser )
       
   823         {
       
   824         CleanupStack::PushL( parser );
       
   825         __TRACE( KMessage, (_L("Read initialization from [%S]"),
       
   826             &aIniFile ) );
       
   827 
       
   828         CStifSectionParser* section = parser->SectionL( KDefineStartTag,
       
   829                                                         KDefineEndTag );
       
   830         while(section)
       
   831             {
       
   832             CleanupStack::PushL( section );
       
   833             __TRACE( KMessage, (_L("Read defines")) );
       
   834 
       
   835             TPtrC name;
       
   836             TPtrC value;
       
   837             CStifItemParser* item = section->GetItemLineL( _L("") );
       
   838             while( item )
       
   839                 {
       
   840                 CleanupStack::PushL( item );
       
   841 
       
   842                 if( item->GetString( _L(""), name ) != KErrNone )
       
   843                     {
       
   844                     __TRACE( KError, (_L("No define name given")) );
       
   845                     User::Leave( KErrGeneral );
       
   846                     }
       
   847                 if( item->Remainder( value ) != KErrNone )
       
   848                     {
       
   849                     __TRACE( KError, (_L("No define value given")) );
       
   850                     User::Leave( KErrGeneral );
       
   851                     }
       
   852                 TInt count = aDefines.Count();
       
   853                 TInt i = 0;
       
   854                 for( ; i < count; i++ )
       
   855                     {
       
   856                     if( aDefines[i]->Name() == name )
       
   857                         {
       
   858                         // Update existing
       
   859                         aDefines[i]->SetValueL( value );
       
   860                         __TRACE(KMessage, (_L("Update define [%S]: [%S]"), &name, &value));
       
   861                         break;
       
   862                         }
       
   863                     }
       
   864                 if( i == count)
       
   865                     {
       
   866                     // New define, store it
       
   867                     CDefinedValue* define = CDefinedValue::NewL( name, value );
       
   868                     CleanupStack::PushL( define );
       
   869                     User::LeaveIfError( aDefines.Append( define ) );
       
   870                     CleanupStack::Pop( define );
       
   871                     }
       
   872 
       
   873                 CleanupStack::PopAndDestroy( item );
       
   874                 item = section->GetNextItemLineL();
       
   875                 }
       
   876             CleanupStack::PopAndDestroy( section );
       
   877             section = parser->NextSectionL(KDefineStartTag, KDefineEndTag);
       
   878             }
       
   879 
       
   880         //Read StifSettings section and find value for CheckHeapBalance.
       
   881         //(In cfg file in settings section User may also set CapsModifier
       
   882         // option. This is handled in TestServerClient.cpp in 
       
   883         // RTestServer::GetCapsModifier method).
       
   884         section = parser->SectionL(KStifSettingsStartTag, KStifSettingsEndTag);
       
   885 
       
   886         if(section)
       
   887             {
       
   888             CleanupStack::PushL(section);
       
   889             __TRACE(KMessage, (_L("Read stif settings")));
       
   890 
       
   891             TPtrC value;
       
   892             CStifItemParser* item = section->GetItemLineL(_L(""));
       
   893             while(item)
       
   894                 {
       
   895                 CleanupStack::PushL(item);
       
   896                 __TRACE( KMessage, (_L("Got settings line")));
       
   897 
       
   898                 if(item->GetString(_L("CheckHeapBalance="), value) == KErrNone)
       
   899                     {
       
   900                     __TRACE(KMessage, (_L("Got CheckHeapBalance item, value=%S"), &value));
       
   901                     if(value.Compare(_L("off")) == 0)
       
   902                         {
       
   903                         iCheckHeapBalance = EFalse;
       
   904                         }
       
   905                     else if(value.Compare(_L("on")) == 0)
       
   906                         {
       
   907                         iCheckHeapBalance = ETrue;
       
   908                         }
       
   909                     else
       
   910                         {
       
   911                         __TRACE(KError, (_L("Value '%S' for CheckHeapBalance setting is not supported. Aborting"), &value));
       
   912                         User::Leave(KErrNotSupported);
       
   913                         }
       
   914                     }
       
   915                 CleanupStack::PopAndDestroy(item);
       
   916                 item = section->GetNextItemLineL();
       
   917                 }
       
   918             CleanupStack::PopAndDestroy(section);
       
   919             }
       
   920         
       
   921         
       
   922         
       
   923         
       
   924         //Read data section 
       
   925     section = parser->SectionL(KDataStartTag, KDataEndTag);
       
   926 
       
   927     if(section)
       
   928         {
       
   929         CleanupStack::PushL(section);
       
   930         __TRACE(KMessage, (_L("Read data section")));
       
   931 
       
   932         
       
   933         CStifItemParser* item = section->GetItemLineL(_L(""));
       
   934         
       
   935         while(item)
       
   936             {
       
   937             CleanupStack::PushL(item);
       
   938             __TRACE( KMessage, (_L("Got data section line")));
       
   939             TPtrC inifile;
       
   940             TPtrC inisection;
       
   941             if(item->GetString(_L("File"), inifile) == KErrNone)
       
   942                 {
       
   943                
       
   944                 __TRACE(KMessage, (_L("Got ini file name: %S"), &inifile));
       
   945                 
       
   946                 iCurrentFile.Zero();
       
   947                 
       
   948               
       
   949                 if(inifile.Find(_L("\\"))==KErrNotFound)
       
   950                     {
       
   951                     iCurrentFile.Append(_L("c:\\TestFramework\\"));
       
   952                     }
       
   953                
       
   954                 iCurrentFile.Append(inifile);
       
   955                
       
   956                 
       
   957                 
       
   958                 TPtrC alias;
       
   959                 err=item->GetNextString(alias);
       
   960                 __TRACE(KMessage, (_L("Got ini file alias: %S"), &alias));
       
   961                 
       
   962                 iCurrentFileAlias.Zero();
       
   963                 if(err==KErrNone)
       
   964                     {
       
   965                     iCurrentFileAlias.Copy(alias);
       
   966                     }
       
   967                 else
       
   968                     {
       
   969                     TParsePtr filespec(iCurrentFile);
       
   970                     iCurrentFileAlias.Copy(filespec.NameAndExt());
       
   971                     }
       
   972                 
       
   973                 
       
   974               
       
   975                 }
       
   976             else if(item->GetString(_L("Section"), inisection) == KErrNone)
       
   977                 {
       
   978                 
       
   979                 __TRACE(KMessage, (_L("Got Section name: %S"), &inisection));
       
   980                 
       
   981                 iCurrentSection.Zero();
       
   982                 iCurrentSection.Copy(inisection);
       
   983                 
       
   984                 
       
   985                 TPtrC alias;
       
   986                 TInt err=item->GetNextString(alias);
       
   987                 __TRACE(KMessage, (_L("Got Section alias: %S"), &alias));
       
   988                
       
   989                 iCurrentSectionFileAlias.Zero();
       
   990                 
       
   991                 if(err==KErrNone)
       
   992                     {
       
   993                     iCurrentSectionFileAlias.Copy(alias);
       
   994                     }
       
   995                 else
       
   996                     {
       
   997                     iCurrentSectionFileAlias.Copy(iCurrentSection);
       
   998                     }
       
   999                 
       
  1000                 TParsePtr filespec(iCurrentFile);
       
  1001           
       
  1002                 CStifParser* parser=CStifParser::NewL(filespec.DriveAndPath(),filespec.NameAndExt());
       
  1003                 
       
  1004                 TBuf<KMaxFileName> section;
       
  1005                 section.Append(_L("["));
       
  1006                 section.Append(iCurrentSection);
       
  1007                 section.Append(_L("]"));
       
  1008                 CStifSectionParser* sectionparser=parser->SectionL(section,KNullDesC,1,EFalse);
       
  1009                 
       
  1010                 CStifItemParser* itemparser=sectionparser->GetItemLineL(KNullDesC);
       
  1011                 
       
  1012                 while(itemparser)
       
  1013                 {
       
  1014                     itemparser->SetParsingType(CStifItemParser::EQuoteStyleParsing);
       
  1015                     TPtrC temp;
       
  1016                    
       
  1017                     itemparser->Remainder(temp);
       
  1018                     __TRACE(KMessage, (_L("Got item string: %S"), &temp));
       
  1019                     iCurrentKey.Zero();
       
  1020                     iCurrentKey.Append(KFileFlag);
       
  1021                     iCurrentKey.Append(iCurrentFileAlias);
       
  1022                     iCurrentKey.Append(KSectionFlag);
       
  1023                     iCurrentKey.Append(iCurrentSectionFileAlias);
       
  1024                     iCurrentKey.Append(KKeyFlag);
       
  1025                     
       
  1026                     TBuf<KMaxFileName> tempkey;
       
  1027                     TBuf<KMaxFileName> tempvalue;
       
  1028                     TLex lex(temp);
       
  1029                     TChar ch;
       
  1030                     while((ch = lex.Get()) != 0 )
       
  1031                        {
       
  1032                        while ((ch = lex.Peek()) != '=') 
       
  1033                        lex.Inc();
       
  1034                        tempkey.Append(lex.MarkedToken());
       
  1035                        lex.Inc();
       
  1036                        lex.Mark();
       
  1037                        break;
       
  1038                        }
       
  1039                     tempkey.TrimAll();
       
  1040                     iCurrentKey.Append(tempkey);
       
  1041                     iKeys.Append(iCurrentKey);
       
  1042                    
       
  1043                     
       
  1044                     tempvalue.Append(lex.Remainder());
       
  1045                     tempvalue.TrimAll();
       
  1046                     
       
  1047                     
       
  1048                     iCurrentvalues.Zero();
       
  1049                     iCurrentvalues.Copy(tempvalue);
       
  1050                    
       
  1051                   
       
  1052                    
       
  1053                     iValues.Append(iCurrentvalues);
       
  1054                     delete itemparser;
       
  1055                     itemparser=NULL;
       
  1056                     itemparser=sectionparser->GetNextItemLineL();
       
  1057                     
       
  1058                 }
       
  1059                 
       
  1060                 
       
  1061            
       
  1062                      
       
  1063                 delete sectionparser;
       
  1064                 delete parser;
       
  1065                 
       
  1066                 
       
  1067                 
       
  1068               
       
  1069                     
       
  1070                 
       
  1071                 
       
  1072                 }
       
  1073             CleanupStack::PopAndDestroy(item);
       
  1074             item = section->GetNextItemLineL();
       
  1075             }
       
  1076         CleanupStack::PopAndDestroy(section);
       
  1077         }
       
  1078 
       
  1079         
       
  1080 
       
  1081         CleanupStack::PopAndDestroy( parser );
       
  1082         }
       
  1083     }
       
  1084 
       
  1085 
       
  1086 /*
       
  1087 -------------------------------------------------------------------------------
       
  1088 
       
  1089      Class: CTestScripter
       
  1090 
       
  1091      Method: GetTestCaseL
       
  1092 
       
  1093      Description: Get specified test case section from configfile.
       
  1094 
       
  1095      Parameters:    const TInt aCaseNumber: in: Test case number
       
  1096                     const TFileName& aConfig: in: Configfile name 
       
  1097      
       
  1098      Return Values: CStifSectionParser*: pointer to test case section
       
  1099 
       
  1100      Errors/Exceptions: Leaves if CStifParser::NewL leaves
       
  1101                         Leaves if CStifParser::SectionL leaves
       
  1102                         Leaves if memory allocation fails
       
  1103                                 
       
  1104 
       
  1105      Status: Draft
       
  1106     
       
  1107 -------------------------------------------------------------------------------
       
  1108 */
       
  1109 CStifSectionParser* CTestScripter::GetTestCaseL( const TInt aCaseNumber, 
       
  1110                                              const TFileName& aConfig )
       
  1111     {
       
  1112     __TRACEFUNC();
       
  1113     CStifParser* parser = NULL;
       
  1114     
       
  1115     TRAPD( err, 
       
  1116         parser = CStifParser::NewL( _L(""), 
       
  1117                                     aConfig, 
       
  1118                                     CStifParser::ECStyleComments ); );
       
  1119     if( err != KErrNone )
       
  1120         {
       
  1121         __TRACE( KError, (_L("Test case file [%S] not found"), &aConfig ));
       
  1122         User::Leave( err );
       
  1123         }
       
  1124     CleanupStack::PushL( parser );
       
  1125 
       
  1126     CStifSectionParser* section = NULL;
       
  1127     TRAP( err, 
       
  1128         section =parser->SectionL( KTestStartTag, KTestEndTag, aCaseNumber ););
       
  1129     if( err != KErrNone )
       
  1130         {
       
  1131         __TRACE( KError, 
       
  1132             (_L("Section [%S/%d] not found"), &aConfig, aCaseNumber ));
       
  1133         User::Leave( err );
       
  1134         }
       
  1135 
       
  1136     CleanupStack::PopAndDestroy( parser );
       
  1137     return section;
       
  1138     
       
  1139     }
       
  1140 
       
  1141 /*
       
  1142 -------------------------------------------------------------------------------
       
  1143 
       
  1144      Class: CTestScripter
       
  1145 
       
  1146      Method: GetSubL
       
  1147 
       
  1148      Description: Get specified function (sub) from stored config file.
       
  1149 
       
  1150      Parameters:    const TDesC& aSubName: in: function name 
       
  1151      
       
  1152      Return Values: CStifSectionParser*: pointer to test function section
       
  1153 
       
  1154      Errors/Exceptions: Leaves if CStifParser::NewL leaves
       
  1155                         Leaves if CStifParser::SectionL leaves
       
  1156                         Leaves if memory allocation fails
       
  1157                                 
       
  1158      Status: Draft
       
  1159     
       
  1160 -------------------------------------------------------------------------------
       
  1161 */
       
  1162 CStifSectionParser* CTestScripter::GetSubL(const TDesC& aSubName)
       
  1163     {
       
  1164     __TRACE(KMessage, (_L("Searching sub [%S]."), &aSubName));
       
  1165     // Check if config file is set
       
  1166     if(iConfig.Length() == 0)
       
  1167         {
       
  1168         __TRACE(KError, (_L("Searching sub [%S]. Config file is not set."), &aSubName));
       
  1169         User::Leave(KErrBadName);
       
  1170         }
       
  1171         
       
  1172     // Create parser
       
  1173     CStifParser* parser = NULL;
       
  1174     CStifSectionParser* section = NULL;
       
  1175         
       
  1176     TRAPD(err, 
       
  1177           parser = CStifParser::NewL(_L(""), iConfig, CStifParser::ECStyleComments);
       
  1178          );
       
  1179     if(err != KErrNone)
       
  1180         {
       
  1181         __TRACE(KError, (_L("Searching sub [%S]. Error [%d] when loading config file [%S]."), &aSubName, err, &iConfig));
       
  1182         User::Leave(err);
       
  1183         }
       
  1184     CleanupStack::PushL(parser);
       
  1185 
       
  1186     // Set section tags
       
  1187     _LIT(KEndSubTag, "[EndSub]");
       
  1188     TName startSubTag;
       
  1189     startSubTag.Copy(_L("[Sub "));
       
  1190     startSubTag.Append(aSubName);
       
  1191     startSubTag.Append(_L("]"));
       
  1192     
       
  1193     // Load section
       
  1194     TRAP(err, 
       
  1195          section = parser->SectionL(startSubTag, KEndSubTag, 1);
       
  1196         );
       
  1197     if(err != KErrNone)
       
  1198         {
       
  1199         __TRACE(KError, (_L("Searching sub [%S]. Searching section %S%S ended with error [%d]."), &aSubName, &startSubTag, &KEndSubTag, err));
       
  1200         User::Leave(err);
       
  1201         }
       
  1202     if(!section)
       
  1203         {
       
  1204         __TRACE(KError, (_L("Searching sub [%S]. Section %S%S not found."), &aSubName, &startSubTag, &KEndSubTag));
       
  1205         User::Leave(err);
       
  1206         }
       
  1207     else
       
  1208         {
       
  1209         __TRACE(KMessage, (_L("Searching sub [%S]. Section %S%S found."), &aSubName, &startSubTag, &KEndSubTag));
       
  1210         }
       
  1211 
       
  1212     CleanupStack::PopAndDestroy(parser);
       
  1213     return section;
       
  1214     }
       
  1215 
       
  1216 /*
       
  1217 -------------------------------------------------------------------------------
       
  1218 
       
  1219      Class: CTestScripter
       
  1220 
       
  1221      Method: RunTestL
       
  1222 
       
  1223      Description: Run a testcase specified by iSectionParser.
       
  1224 
       
  1225      Parameters:    None
       
  1226      
       
  1227      Return Values: None.
       
  1228 
       
  1229      Errors/Exceptions: Leaves if CSectionParser::GetItemLineL leaves
       
  1230                         Leaves if CTestRunner::NewL leaves
       
  1231                         Leaves if memory allocation fails                                
       
  1232 
       
  1233      Status: Draft
       
  1234     
       
  1235 -------------------------------------------------------------------------------
       
  1236 */
       
  1237 void CTestScripter::RunTestL()
       
  1238     {
       
  1239     __TRACEFUNC();
       
  1240     iResult.iResult = KErrNone;
       
  1241     iResult.iResultDes.Zero();
       
  1242      
       
  1243     // "title" keyword must be in the first line
       
  1244     TPtrC title;
       
  1245     if( iCurrentParser->GetLine( 
       
  1246         TTestKeywords::Keyword( TTestKeywords::ETitle ), title, ENoTag ) 
       
  1247         != KErrNone )
       
  1248         {
       
  1249         __TRACE( KError, (_L("title not found from section")));
       
  1250         User::Leave( KErrNotFound ); 
       
  1251         }
       
  1252     iCurrentParserReadFirstLine = ETrue;
       
  1253 
       
  1254     __TRACE( KMessage, (_L("RunTest: %S"), &title ));
       
  1255      
       
  1256     iTestRunner = CTestRunner::NewL( this );
       
  1257 
       
  1258     TestModuleIf().Printf( KPrintPriNorm, _L("RunTest"), _L("%S"), &title );
       
  1259     
       
  1260     // Rest of the job is done by test runner
       
  1261     iTestRunner->SetRunnerActive();
       
  1262 
       
  1263     // Start activeScheduler looping testcase lines
       
  1264     __TRACE( KMessage, (_L("Start CActiveScheduler")));
       
  1265     CActiveScheduler::Current()->Start();
       
  1266   
       
  1267     if ( iTestRunner->IsFailedSubTestCaseReported() && !(iPassLimitNotMet) )
       
  1268         {
       
  1269         TFullTestResult testResult = iTestRunner->GetFailedSubTestCaseResult();
       
  1270         const CStartInfo* startInfo = iTestRunner->GetFailedSubTestCaseInfo();
       
  1271         if( testResult.iCaseExecutionResultType == TFullTestResult::ECaseExecuted )
       
  1272             {
       
  1273             iResult.iResult = testResult.iTestResult.iResult;
       
  1274             }
       
  1275         else
       
  1276             {
       
  1277             iResult.iResult = testResult.iCaseExecutionResultCode;
       
  1278             }
       
  1279         iResult.iResultDes.Format( _L("Sub test case \"%S\" execution failed. "), &startInfo->GetTitle() );
       
  1280         iResult.iResultDes.AppendFormat( _L("Result [%d], expected result [%d]"), iResult.iResult, startInfo->GetExpectedResult() );
       
  1281         }
       
  1282     
       
  1283     delete iTestRunner;
       
  1284     iTestRunner = NULL;
       
  1285     __TRACE( KMessage, ( _L("RunTestL: Done")));
       
  1286  
       
  1287     // Destroy locally defined variables 
       
  1288     iDefinedLocal.ResetAndDestroy();
       
  1289     // Destroy function parsers (there shouldn't be any)
       
  1290     iParserStack.ResetAndDestroy();
       
  1291     }     
       
  1292 
       
  1293 /*
       
  1294 -------------------------------------------------------------------------------
       
  1295 
       
  1296      Class: CTestScripter
       
  1297 
       
  1298      Method: GetTestModuleL
       
  1299 
       
  1300      Description: Load testmodule if not already loaded, otherwise return
       
  1301                   description of the loaded testmodule.
       
  1302 
       
  1303      Parameters:    TDesC& aModule: in: module name
       
  1304                     TDesC& aIniFile: in: ini file name
       
  1305      
       
  1306      Return Values: CTCTestModule*: pointer to testmodules description
       
  1307      
       
  1308      Errors/Exceptions: Leaves if CTCTestModule::NewL leaves
       
  1309                         Leaves if RPointerArray::Append fails  
       
  1310 
       
  1311      Status: Draft
       
  1312     
       
  1313 -------------------------------------------------------------------------------
       
  1314 */              
       
  1315 TTestModule* CTestScripter::LoadTestModuleL( TDesC& aModule )
       
  1316     {     
       
  1317     __TRACEFUNC();
       
  1318     TInt count = iTestModules.Count();
       
  1319     for( TInt i=0; i < count; i++ )
       
  1320         {
       
  1321         if( iTestModules[i]->ModuleName() == aModule )
       
  1322             {
       
  1323             // Found test module, return description
       
  1324             __TRACE( KMessage, 
       
  1325                 (_L("GetTestModuleL: Use already loaded TestModule (%S)"), 
       
  1326                 &aModule ));
       
  1327             return iTestModules[i];
       
  1328             }
       
  1329         }
       
  1330          
       
  1331     __TRACE( KMessage, (_L("GetTestModuleL: Load new TestModule (%S)"), 
       
  1332         &aModule ));
       
  1333     TTestModule* module = new (ELeave) TTestModule();
       
  1334     CleanupStack::PushL( module );
       
  1335     module->ModuleName() = aModule;
       
  1336     User::LeaveIfError( iTestModules.Append( module ) );
       
  1337     CleanupStack::Pop( module );
       
  1338 
       
  1339     TInt ret = module->iLibrary.Load ( aModule );
       
  1340     
       
  1341     if( ret != KErrNone )
       
  1342         {
       
  1343         __TRACE( KMessage, (_L("GetTestModuleL: %S loading failed"), 
       
  1344             &aModule ));
       
  1345         TestModuleIf().Printf( KMessage, _L("Load dll"), _L("%S failed"), 
       
  1346             &aModule );
       
  1347         
       
  1348         User::Leave( ret );
       
  1349         }
       
  1350          
       
  1351     // Get pointer to first exported function    
       
  1352     module->iLibEntry = (CInterfaceFactory) module->iLibrary.Lookup(1);
       
  1353     return module;
       
  1354     
       
  1355     }
       
  1356 
       
  1357 /*
       
  1358  -------------------------------------------------------------------------------
       
  1359 
       
  1360  Class: CTestScripter
       
  1361 
       
  1362  Method: LoadSharedTestModuleL
       
  1363 
       
  1364  Description: Load testmodule if not already loaded, otherwise return
       
  1365  description of the loaded testmodule.
       
  1366 
       
  1367  Parameters:    TDesC& aModule: in: module name
       
  1368  TDesC& aIniFile: in: ini file name
       
  1369  
       
  1370  Return Values: CTCTestModule*: pointer to testmodules description
       
  1371  
       
  1372  Errors/Exceptions: Leaves if CTCTestModule::NewL leaves
       
  1373  Leaves if RPointerArray::Append fails  
       
  1374 
       
  1375  Status: Draft
       
  1376  
       
  1377  -------------------------------------------------------------------------------
       
  1378  */
       
  1379 
       
  1380 TTestModule* CTestScripter::LoadSharedTestModuleL(TDesC& aModule)
       
  1381     {
       
  1382     __TRACEFUNC();
       
  1383     TInt count = iSharedTestModules.Count();
       
  1384     for (TInt i = 0; i < count; i++)
       
  1385         {
       
  1386         if (iSharedTestModules[i]->ModuleName() == aModule)
       
  1387             {
       
  1388             // Found test module, return description
       
  1389             __TRACE( KMessage,
       
  1390                     (_L("GetTestModuleL: Use already loaded TestModule (%S)"),
       
  1391                             &aModule ));
       
  1392             return iSharedTestModules[i]->Get();
       
  1393             }
       
  1394         }
       
  1395 
       
  1396     __TRACE( KMessage, (_L("GetTestModuleL: Load new TestModule (%S)"),
       
  1397                     &aModule ));
       
  1398     TTestModule* module = new (ELeave) TTestModule();
       
  1399     CleanupStack::PushL(module);
       
  1400     module->ModuleName() = aModule;
       
  1401     User::LeaveIfError(iSharedTestModules.Append(
       
  1402             new (ELeave) TSharedTestModule(module)));
       
  1403     CleanupStack::Pop(module);
       
  1404 
       
  1405     TInt ret = module->iLibrary.Load(aModule);
       
  1406     TestModuleIf().iNumberInGlbDict++;
       
  1407 
       
  1408     if (ret != KErrNone)
       
  1409         {
       
  1410         __TRACE( KMessage, (_L("GetTestModuleL: %S loading failed"),
       
  1411                         &aModule ));
       
  1412         TestModuleIf().Printf(KMessage, _L("Load dll"), _L("%S failed"),
       
  1413                 &aModule);
       
  1414 
       
  1415         User::Leave(ret);
       
  1416         }
       
  1417 
       
  1418     // Get pointer to first exported function    
       
  1419     module->iLibEntry = (CInterfaceFactory) module->iLibrary.Lookup(1);
       
  1420     return module;
       
  1421     }
       
  1422 
       
  1423 /*
       
  1424 -------------------------------------------------------------------------------
       
  1425 
       
  1426      Class: CTestScripter
       
  1427 
       
  1428      Method: CreateObjectL
       
  1429 
       
  1430      Description: Load testmodule if not already loaded, otherwise return
       
  1431                   description of the loaded testmodule.
       
  1432 
       
  1433      Parameters:    TDesC& aModule: in: module name
       
  1434                     TDesC& aObjectId: in: object id name
       
  1435      
       
  1436      Return Values: None
       
  1437      
       
  1438      Errors/Exceptions: Leaves on error
       
  1439 
       
  1440      Status: Draft
       
  1441     
       
  1442 -------------------------------------------------------------------------------
       
  1443 */
       
  1444 void CTestScripter::CreateObjectL( TDesC& aModule, TDesC& aObjectId )
       
  1445     {     
       
  1446     __TRACEFUNC();
       
  1447 
       
  1448     // Load module and get pointer
       
  1449     TTestModule* module = LoadTestModuleL( aModule );
       
  1450     TTestObject* object = new (ELeave) TTestObject();
       
  1451     CleanupStack::PushL( object );
       
  1452     object->ObjectId() = aObjectId;
       
  1453     object->iModule.Copy(aModule);
       
  1454     User::LeaveIfError( iTestObjects.Append( object ) );
       
  1455     CleanupStack::Pop( object );
       
  1456         
       
  1457     // Create object    
       
  1458     object->iScript = module->iLibEntry( TestModuleIf() );
       
  1459     //User::LeaveIfNull ( object->iScript );
       
  1460     if( object->iScript == NULL )
       
  1461         {
       
  1462         User::Leave( KErrGeneral );
       
  1463         }
       
  1464 
       
  1465     // Create continue callback 
       
  1466     object->iContinue = CTestContinue::NewL( this, object );
       
  1467 
       
  1468     // Create function pointer operation to possible
       
  1469     object->iScript->SetScripter( &CallBack, this );
       
  1470     
       
  1471     TestModuleIf().AddTestObjToCaseDictL(object);
       
  1472     }
       
  1473 
       
  1474 /*
       
  1475 -------------------------------------------------------------------------------
       
  1476 
       
  1477      Class: CTestScripter
       
  1478 
       
  1479      Method: CreateShareObjectL
       
  1480 
       
  1481      Description: Load testmodule if not already loaded, otherwise return
       
  1482                   description of the loaded testmodule.
       
  1483 
       
  1484      Parameters:    TDesC& aModule: in: module name
       
  1485                     TDesC& aObjectId: in: object id name
       
  1486      
       
  1487      Return Values: None
       
  1488      
       
  1489      Errors/Exceptions: Leaves on error
       
  1490 
       
  1491      Status: Draft
       
  1492     
       
  1493 -------------------------------------------------------------------------------
       
  1494 */
       
  1495 void CTestScripter::CreateShareObjectL( TDesC& aModule, TDesC& aObjectId )
       
  1496     {     
       
  1497     __TRACEFUNC();
       
  1498 
       
  1499     // Load module and get pointer
       
  1500     TTestModule* module = LoadSharedTestModuleL(aModule);
       
  1501     TTestObject* object = new (ELeave) TTestObject();
       
  1502     CleanupStack::PushL( object );
       
  1503     object->ObjectId() = aObjectId;
       
  1504     CleanupStack::Pop( object );
       
  1505     object->iModule.Copy(aModule);    
       
  1506     // Create object    
       
  1507     object->iScript = module->iLibEntry( TestModuleIf() );
       
  1508     //User::LeaveIfNull ( object->iScript );
       
  1509     if( object->iScript == NULL )
       
  1510         {
       
  1511         User::Leave( KErrGeneral );
       
  1512         }  
       
  1513 
       
  1514     TestModuleIf().AddTestObjToCaseDictL(object);
       
  1515     AddTestObjToScripterDictL(object);
       
  1516     TestModuleIf().iNumberInGlbDict++; 
       
  1517     }
       
  1518 
       
  1519 /*
       
  1520 -------------------------------------------------------------------------------
       
  1521 
       
  1522      Class: CTestScripter
       
  1523 
       
  1524      Method: RestoreShareObjectL
       
  1525 
       
  1526      Description: Load testmodule if not already loaded, otherwise return
       
  1527                   description of the loaded testmodule.
       
  1528 
       
  1529      Parameters:    TDesC& aModule: in: module name
       
  1530                     TDesC& aObjectId: in: object id name
       
  1531      
       
  1532      Return Values: None
       
  1533      
       
  1534      Errors/Exceptions: Leaves on error
       
  1535 
       
  1536      Status: Draft
       
  1537     
       
  1538 -------------------------------------------------------------------------------
       
  1539 */
       
  1540 void CTestScripter::RestoreShareObjectL( TDesC& aObjectId )
       
  1541     {     
       
  1542     __TRACEFUNC();  
       
  1543   
       
  1544     TTestObject* object = NULL;
       
  1545     object = (TTestObject*)GetTestObjFromScripterDict( aObjectId );
       
  1546     
       
  1547     if( NULL == object )
       
  1548         {
       
  1549         User::Leave( KErrGeneral );
       
  1550         }
       
  1551 
       
  1552     //User::LeaveIfNull ( object->iScript );
       
  1553     if( object->iScript == NULL )
       
  1554         {
       
  1555         User::Leave( KErrGeneral );
       
  1556         }  
       
  1557     
       
  1558     TestModuleIf().AddTestObjToCaseDictL(object);     
       
  1559     }
       
  1560   
       
  1561 /*
       
  1562 -------------------------------------------------------------------------------
       
  1563 
       
  1564      Class: CTestScripter
       
  1565 
       
  1566      Method: CreateKernelObjectL
       
  1567 
       
  1568      Description: Load testdriver if not already loaded, otherwise return
       
  1569                   description of the loaded testdriver.
       
  1570 
       
  1571      Parameters:    TDesC& aDriver: in: driver name
       
  1572                     TDesC& aObjectId: in: object id name
       
  1573      
       
  1574      Return Values: None
       
  1575      
       
  1576      Errors/Exceptions: Leaves on error
       
  1577 
       
  1578      Status: Draft
       
  1579     
       
  1580 -------------------------------------------------------------------------------
       
  1581 */
       
  1582 void CTestScripter::CreateKernelObjectL( TDesC& aDriver, TDesC& aObjectId )
       
  1583     {     
       
  1584 
       
  1585     __TRACEFUNC();
       
  1586     
       
  1587     if( ( aDriver.Length() > KMaxName ) ||
       
  1588         ( aObjectId.Length() > KMaxName ) )
       
  1589         {
       
  1590         __TRACE( KError, (_L("CreateKernelObjectL: Max lenght exceeded") ) );
       
  1591         User::Leave( KErrArgument );
       
  1592         }
       
  1593     TInt ret = User::LoadLogicalDevice( aDriver );
       
  1594     if( ( ret != KErrNone ) && ( ret != KErrAlreadyExists ) )
       
  1595         {
       
  1596         __TRACE( KError, 
       
  1597             (_L("CreateKernelObjectL: User::LoadLogicalDevice failed %d"), 
       
  1598                 ret ) );
       
  1599         User::Leave( ret );
       
  1600         } 
       
  1601         
       
  1602     TTestObjectKernel* object = new (ELeave) TTestObjectKernel();
       
  1603     CleanupStack::PushL( object );
       
  1604     object->ObjectId() = aObjectId;
       
  1605     object->LddName().Copy( aDriver );
       
  1606     ret = object->KernelTestClass().Open( 
       
  1607                 object->KernelTestClass().VersionRequired(), 
       
  1608                 aDriver );
       
  1609     if( ret != KErrNone )
       
  1610         {
       
  1611         __TRACE( KError, 
       
  1612             (_L("CreateKernelObjectL: KernelTestClass().Open failed %d"), 
       
  1613                 ret ) );
       
  1614         User::Leave( ret );
       
  1615         }
       
  1616         
       
  1617     User::LeaveIfError( iTestObjects.Append( object ) );
       
  1618     CleanupStack::Pop( object );
       
  1619         
       
  1620     }
       
  1621     
       
  1622 /*
       
  1623 -------------------------------------------------------------------------------
       
  1624 
       
  1625      Class: CTestScripter
       
  1626 
       
  1627      Method: GetTestModuleL
       
  1628 
       
  1629      Description: Load testmodule if not already loaded, otherwise return
       
  1630                   description of the loaded testmodule.
       
  1631 
       
  1632      Parameters:    TDesC& aModule: in: module name
       
  1633                     TDesC& aIniFile: in: ini file name
       
  1634      
       
  1635      Return Values: CTCTestModule*: pointer to testmodules description
       
  1636      
       
  1637      Errors/Exceptions: Leaves if CTCTestModule::NewL leaves
       
  1638                         Leaves if RPointerArray::Append fails  
       
  1639 
       
  1640      Status: Draft
       
  1641     
       
  1642 -------------------------------------------------------------------------------
       
  1643 */
       
  1644 TInt CTestScripter::DeleteObjectL( TDesC& aObjectId )
       
  1645     {     
       
  1646     __TRACEFUNC();
       
  1647     
       
  1648     TestModuleIf().DelTestObjFromCaseDict(aObjectId);
       
  1649     
       
  1650     TInt count = iTestObjects.Count();
       
  1651     for( TInt i=0; i < count; i++ )
       
  1652         {
       
  1653         if( iTestObjects[i]->ObjectId() == aObjectId )
       
  1654             {
       
  1655             TTestObjectBase* object = iTestObjects[i];
       
  1656             iTestObjects.Remove( i );
       
  1657             delete object;
       
  1658             return KErrNone;
       
  1659             }
       
  1660         }
       
  1661      
       
  1662     return KErrNone;
       
  1663     }
       
  1664 
       
  1665 /*
       
  1666 -------------------------------------------------------------------------------
       
  1667 
       
  1668      Class: CTestScripter
       
  1669 
       
  1670      Method: DeleteGlobalObjectL
       
  1671 
       
  1672      Description: Delete test object from dictionary
       
  1673 
       
  1674      Parameters:    TDesC& aObjectId: in: object name
       
  1675      
       
  1676      Return Values: void
       
  1677      
       
  1678      Errors/Exceptions: Leaves if CTCTestModule::NewL leaves
       
  1679                         Leaves if RPointerArray::Append fails  
       
  1680 
       
  1681      Status: Draft
       
  1682     
       
  1683 -------------------------------------------------------------------------------
       
  1684 */
       
  1685 TInt CTestScripter::DeleteScripterObjectL( TDesC& aObjectId )
       
  1686     {     
       
  1687     __TRACEFUNC();
       
  1688     
       
  1689     TScriptObject* obj = TestModuleIf().GetTestObjFromCaseDict(aObjectId);
       
  1690     if(obj == NULL)
       
  1691         {
       
  1692         return KErrNotFound;
       
  1693         }
       
  1694     
       
  1695     TestModuleIf().DelTestObjFromCaseDict(aObjectId);
       
  1696     DelTestObjFromScripterDict(aObjectId);    
       
  1697     
       
  1698     return KErrNone;   
       
  1699     }
       
  1700 
       
  1701 /*
       
  1702 -------------------------------------------------------------------------------
       
  1703 
       
  1704      Class: CTestScripter
       
  1705 
       
  1706      Method: GetTest
       
  1707 
       
  1708      Description: Get test case from testcase array.
       
  1709 
       
  1710      Parameters:    TDesC& aTestId: in: TestId for testcase
       
  1711      
       
  1712      Return Values: CTCTestCase*: running/runned testcase
       
  1713                     NULL: Testcase with aTestId not running/runned 
       
  1714 
       
  1715      Errors/Exceptions: None
       
  1716 
       
  1717      Status: Draft
       
  1718     
       
  1719 -------------------------------------------------------------------------------
       
  1720 */
       
  1721 TTestObjectBase* CTestScripter::GetObject( const TDesC& aObjectId )
       
  1722     {
       
  1723     __TRACEFUNC();
       
  1724     
       
  1725     TInt count = iTestObjects.Count();
       
  1726     for( TInt i=0; i < count; i++ )
       
  1727         {
       
  1728         if( iTestObjects[i]->ObjectId() == aObjectId )
       
  1729             {
       
  1730             // Found testcase with specified TestId
       
  1731             return iTestObjects[i];
       
  1732             }
       
  1733         }
       
  1734     
       
  1735     TTestObject* object = NULL;
       
  1736     object = (TTestObject*)TestModuleIf().GetTestObjFromCaseDict( aObjectId );
       
  1737     
       
  1738     return object; 
       
  1739     }
       
  1740 
       
  1741 /*
       
  1742 -------------------------------------------------------------------------------
       
  1743 
       
  1744      Class: CTestScripter
       
  1745 
       
  1746      Method: CallTestClass
       
  1747 
       
  1748      Description: For sub classing operations.
       
  1749   
       
  1750      Parameters: const TDesC& aLine: in: script line
       
  1751                     
       
  1752      Return Values: TInt: Symbian error code
       
  1753 
       
  1754      Errors/Exceptions: None
       
  1755 
       
  1756      Status: Draft
       
  1757     
       
  1758 -------------------------------------------------------------------------------
       
  1759 */
       
  1760 TInt CTestScripter::CallTestClass( const TDesC& aLine )
       
  1761     {
       
  1762     CStifItemParser* item = CStifItemParser::NewL( aLine, 0, aLine.Length() );
       
  1763     CleanupStack::PushL( item );
       
  1764 
       
  1765     TPtrC objectName;
       
  1766     TInt ret( KErrNone );
       
  1767     ret = item->GetString( _L( "" ), objectName );
       
  1768     if( ret != KErrNone )
       
  1769         {
       
  1770         CleanupStack::PopAndDestroy( item);
       
  1771         return ret;
       
  1772         }
       
  1773 
       
  1774     TTestObjectBase* obj = GetObject( objectName );
       
  1775     if( obj == NULL )
       
  1776         {
       
  1777         CleanupStack::PopAndDestroy(item );
       
  1778         return KErrNotFound;
       
  1779         }
       
  1780 
       
  1781     TRAPD( commandResult, commandResult = obj->RunMethodL( *item ) );
       
  1782 
       
  1783     CleanupStack::PopAndDestroy(item );
       
  1784 
       
  1785     return commandResult;
       
  1786     
       
  1787     }
       
  1788     
       
  1789 /*
       
  1790 -------------------------------------------------------------------------------
       
  1791 
       
  1792      Class: CTestScripter
       
  1793 
       
  1794      Method: GetTestScriptObject
       
  1795 
       
  1796      Description: Get object address.
       
  1797   
       
  1798      Parameters: const TDesC& aObjectName: in: object name
       
  1799                     
       
  1800      Return Values: TInt: Symbian error code
       
  1801 
       
  1802      Errors/Exceptions: None
       
  1803 
       
  1804      Status: Draft
       
  1805     
       
  1806 -------------------------------------------------------------------------------
       
  1807 */
       
  1808 TInt CTestScripter::GetTestScriptObject( const TDesC& aObjectName )
       
  1809     {
       
  1810 
       
  1811     TTestObjectBase* objBase = GetObject( aObjectName );
       
  1812     if( ( objBase == NULL ) || 
       
  1813         ( objBase->ObjectType() != TTestObjectBase::EObjectNormal ) )
       
  1814         {
       
  1815         return KErrNotFound;
       
  1816         }
       
  1817     
       
  1818     TTestObject* object = ( TTestObject* )objBase;
       
  1819     
       
  1820     return (TInt) object->iScript;
       
  1821     
       
  1822     }
       
  1823 
       
  1824 /*
       
  1825 -------------------------------------------------------------------------------
       
  1826 
       
  1827      Class: CTestScripter
       
  1828 
       
  1829      Method: UpdateTestCaseResult
       
  1830 
       
  1831      Description: Updates result of test case. If there is already some
       
  1832                   description stored, it is put in the [] brackets.
       
  1833   
       
  1834      Parameters: const TInt aResult: in: error code
       
  1835                  const TDesC& aDescr: in: description
       
  1836                     
       
  1837      Return Values: None
       
  1838 
       
  1839      Errors/Exceptions: None
       
  1840 
       
  1841      Status: Draft
       
  1842     
       
  1843 -------------------------------------------------------------------------------
       
  1844 */
       
  1845 void CTestScripter::UpdateTestCaseResult(const TInt aResult, const TDesC& aDescr)
       
  1846     {
       
  1847     // Create buffer
       
  1848     RBuf buf;
       
  1849 
       
  1850     TInt ret = buf.Create(iResult.iResultDes.Length() + aDescr.Length() + 5);
       
  1851     if(ret != KErrNone)
       
  1852         {
       
  1853         __TRACE(KError, (_L("UpdateResultDescription: descriptor creation failed [%d]"), ret));
       
  1854         return;
       
  1855         }
       
  1856     CleanupClosePushL(buf);
       
  1857 
       
  1858     // Update result
       
  1859     iResult.iResult = aResult;
       
  1860     if(iResult.iResultDes.Length() > 0)
       
  1861         {
       
  1862         buf.Format(_L("%S [%S]"), &aDescr, &iResult.iResultDes);
       
  1863         }
       
  1864     else
       
  1865         {
       
  1866         buf.Copy(aDescr);
       
  1867         }
       
  1868 
       
  1869     SetResultDescription(buf);
       
  1870     
       
  1871     // Close buffer
       
  1872     CleanupStack::PopAndDestroy(&buf);
       
  1873     }
       
  1874 
       
  1875 /*
       
  1876 -------------------------------------------------------------------------------
       
  1877 
       
  1878      Class: CTestScripter
       
  1879 
       
  1880      Method: SetResultDescription
       
  1881 
       
  1882      Description: Sets result description of test case.
       
  1883   
       
  1884      Parameters: const TDesC& aDescr: in: new description
       
  1885                     
       
  1886      Return Values: None
       
  1887 
       
  1888      Errors/Exceptions: None
       
  1889 
       
  1890      Status: Draft
       
  1891     
       
  1892 -------------------------------------------------------------------------------
       
  1893 */
       
  1894 EXPORT_C void CTestScripter::SetResultDescription(const TDesC& aDescr)
       
  1895     {
       
  1896     if(aDescr.Length() > KStifMaxResultDes)
       
  1897         {
       
  1898         iResult.iResultDes.Copy(aDescr.Mid(0, KStifMaxResultDes));
       
  1899         }
       
  1900     else
       
  1901         {
       
  1902         iResult.iResultDes.Copy(aDescr);
       
  1903         }
       
  1904     }
       
  1905 
       
  1906 /*
       
  1907 -------------------------------------------------------------------------------
       
  1908 
       
  1909      Class: CTestScripter
       
  1910 
       
  1911      Method: SetLocalValue
       
  1912 
       
  1913      Description: Internal fuction to set value of local variable defined in script 
       
  1914 
       
  1915      Parameters:    const TDesC& aName: in: local variable name 
       
  1916                     const TDesC& avalue: in: local variable value
       
  1917 
       
  1918      Return Values: KErrNone: Value is returned succesfully.
       
  1919                     KErrNotFound: Variable was not found
       
  1920                     Any other SymbianOS error
       
  1921                     
       
  1922 -------------------------------------------------------------------------------
       
  1923 */
       
  1924 EXPORT_C TInt CTestScripter::SetLocalValue(const TDesC& aName, const TDesC& aValue)
       
  1925     {   
       
  1926     __TRACEFUNC();
       
  1927 
       
  1928     TInt count = iDefinedLocal.Count();
       
  1929     for(TInt i = 0; i < count; i++)
       
  1930         {
       
  1931         if(iDefinedLocal[i]->Name() == aName)
       
  1932             {
       
  1933             iDefinedLocal[i]->SetValueL(const_cast<TDesC&>(aValue));
       
  1934             return KErrNone;
       
  1935             }
       
  1936         }   
       
  1937 
       
  1938     return KErrNotFound;
       
  1939     }
       
  1940 
       
  1941 /*
       
  1942 -------------------------------------------------------------------------------
       
  1943 
       
  1944      Class: CTestScripter
       
  1945 
       
  1946      Method: GetLocalValue
       
  1947 
       
  1948      Description: Internal fuction to get value of local variable 
       
  1949 
       
  1950      Parameters:    const TDesC& aName: in: local variable name 
       
  1951                     const TDesC& avalue: in: local variable value
       
  1952 
       
  1953      Return Values: KErrNone: Value is returned succesfully.
       
  1954                     KErrNotFound: Variable was not found
       
  1955                     Any other SymbianOS error
       
  1956                     
       
  1957 -------------------------------------------------------------------------------
       
  1958 */
       
  1959 EXPORT_C TInt CTestScripter::GetLocalValue(const TDesC& aName, TDes& aValue)
       
  1960     {
       
  1961     __TRACEFUNC();
       
  1962 
       
  1963     TInt count = iDefinedLocal.Count();
       
  1964     for(TInt i = 0; i < count; i++)
       
  1965         {
       
  1966         if(iDefinedLocal[i]->Name() == aName)
       
  1967             {
       
  1968             aValue.Copy(iDefinedLocal[i]->Value());
       
  1969             return KErrNone;
       
  1970             }
       
  1971         }   
       
  1972 
       
  1973     return KErrNotFound;
       
  1974     }
       
  1975 
       
  1976 TBool CompareTBuf(const TBuf<KMaxFileName>& aLeft,const TBuf<KMaxFileName>& aRight)
       
  1977 {
       
  1978     return aLeft.Compare(aRight) == 0 ? ETrue : EFalse;
       
  1979     
       
  1980 }
       
  1981 
       
  1982 void CTestScripter::Substitute(const TDesC& aSrc,TDes& aDest)
       
  1983 {
       
  1984     TIdentityRelation<TBuf<KMaxFileName> > relation(CompareTBuf);
       
  1985     
       
  1986     
       
  1987    
       
  1988            
       
  1989  
       
  1990            
       
  1991     
       
  1992     
       
  1993     
       
  1994     TInt fileindex=aSrc.Find(KFileFlag);
       
  1995     TInt sectionindex=aSrc.Find(KSectionFlag);
       
  1996     TInt keyindex=aSrc.Find(KKeyFlag);
       
  1997     TBuf<KMaxFileName> srcbuf;
       
  1998     if(fileindex==KErrNotFound&&sectionindex==KErrNotFound&&keyindex!=KErrNotFound)
       
  1999         {
       
  2000         srcbuf.Append(KFileFlag);
       
  2001         srcbuf.Append(iCurrentFileAlias);
       
  2002         srcbuf.Append(KSectionFlag);
       
  2003         srcbuf.Append(iCurrentSectionFileAlias);
       
  2004        
       
  2005         srcbuf.Append(aSrc);
       
  2006         
       
  2007         }
       
  2008     else if(fileindex==KErrNotFound&&sectionindex!=KErrNotFound&&keyindex!=KErrNotFound)
       
  2009         {
       
  2010         srcbuf.Append(KFileFlag);
       
  2011         srcbuf.Append(iCurrentFileAlias);
       
  2012      
       
  2013         
       
  2014         srcbuf.Append(aSrc);
       
  2015         
       
  2016         }
       
  2017     else
       
  2018         {
       
  2019         srcbuf.Append(aSrc);
       
  2020         }
       
  2021     
       
  2022     
       
  2023     TInt index=iKeys.Find(srcbuf,relation);
       
  2024     if(index==KErrNotFound)
       
  2025         {
       
  2026         
       
  2027         aDest.Append(aSrc);
       
  2028         }
       
  2029     else
       
  2030         {
       
  2031         
       
  2032         aDest.Append(iValues[index]);
       
  2033         }
       
  2034   
       
  2035 }
       
  2036 
       
  2037 /*
       
  2038 -------------------------------------------------------------------------------
       
  2039 
       
  2040      Class: CTestScripter
       
  2041 
       
  2042      Method: AddTestObjToDictL
       
  2043 
       
  2044      Description: Add Test Object to dictionary
       
  2045   
       
  2046      Parameters: TTestObject* aObject: in: test object
       
  2047                      
       
  2048      Return Values: None
       
  2049 
       
  2050      Errors/Exceptions: None
       
  2051 
       
  2052      Status: Draft
       
  2053     
       
  2054 -------------------------------------------------------------------------------
       
  2055 */
       
  2056 void CTestScripter::AddTestObjToScripterDictL(TTestObject* aObject)
       
  2057     {
       
  2058     __TRACEFUNC();
       
  2059     
       
  2060     User::LeaveIfNull( (TAny*)aObject );
       
  2061    
       
  2062     TInt count = iGlobalObjects.Count();
       
  2063     for (TInt i = 0; i < count; i++)
       
  2064         {
       
  2065         if (iGlobalObjects[i]->ObjectId() == aObject->ObjectId())
       
  2066             {
       
  2067             // Found testcase with specified TestId
       
  2068             return;
       
  2069             }
       
  2070         }
       
  2071     
       
  2072     User::LeaveIfError( iGlobalObjects.Append(aObject) );
       
  2073     }
       
  2074 
       
  2075 /*
       
  2076 -------------------------------------------------------------------------------
       
  2077 
       
  2078      Class: CTestScripter
       
  2079 
       
  2080      Method: DelTestObjFromDict
       
  2081 
       
  2082      Description: delete Test Object from dictionary
       
  2083   
       
  2084      Parameters: const TDesC& aObjectId: in: id
       
  2085                     
       
  2086      Return Values: None
       
  2087 
       
  2088      Errors/Exceptions: None
       
  2089 
       
  2090      Status: Draft
       
  2091     
       
  2092 -------------------------------------------------------------------------------
       
  2093 */
       
  2094 void CTestScripter::DelTestObjFromScripterDict(const TDesC& aObjectId)
       
  2095     {
       
  2096     __TRACEFUNC();
       
  2097 
       
  2098     TInt count = iGlobalObjects.Count();
       
  2099     for (TInt i = 0; i < count; i++)
       
  2100         {
       
  2101         if (iGlobalObjects[i]->ObjectId() == aObjectId)
       
  2102             {
       
  2103             // Found testcase with specified TestId
       
  2104             TTestObject *object = (TTestObject*) iGlobalObjects[i];
       
  2105             iGlobalObjects.Remove(i);
       
  2106             TInt count2 = iSharedTestModules.Count();
       
  2107             for (TInt j = 0; j < count2; j++)
       
  2108                 {
       
  2109                 if (iSharedTestModules[j]->ModuleName() == object->iModule)
       
  2110                     {
       
  2111                     delete object;
       
  2112                     TestModuleIf().iNumberInGlbDict--;
       
  2113                     iSharedTestModules[j]->Del();
       
  2114                     if (iSharedTestModules[j]->RefCount() <= 0)
       
  2115                         {
       
  2116                         TestModuleIf().iNumberInGlbDict--;
       
  2117                         }
       
  2118                     delete iSharedTestModules[j];
       
  2119                     iSharedTestModules.Remove(j);
       
  2120                     break;
       
  2121                     }
       
  2122                 }
       
  2123             if(iSharedTestModules.Count() == 0)
       
  2124                 {
       
  2125                 iSharedTestModules.Reset();
       
  2126                 }
       
  2127             if(iGlobalObjects.Count() == 0)            
       
  2128                 {
       
  2129                 iGlobalObjects.Reset();
       
  2130                 }
       
  2131             return;
       
  2132             }
       
  2133         }
       
  2134     }
       
  2135 
       
  2136 /*
       
  2137 -------------------------------------------------------------------------------
       
  2138 
       
  2139      Class: CTestScripter
       
  2140 
       
  2141      Method: GetTestObjFromDict
       
  2142 
       
  2143      Description: delete Test Object from dictionary
       
  2144   
       
  2145      Parameters: const TDesC& aObjectId: in: id
       
  2146                     
       
  2147      Return Values: TTestObject* : pointer to TTestObject
       
  2148 
       
  2149      Errors/Exceptions: None
       
  2150 
       
  2151      Status: Draft
       
  2152     
       
  2153 -------------------------------------------------------------------------------
       
  2154 */
       
  2155 TTestObject* CTestScripter::GetTestObjFromScripterDict(const TDesC& aObjectId) const
       
  2156     {
       
  2157     __TRACEFUNC();
       
  2158     
       
  2159     TInt count = iGlobalObjects.Count();
       
  2160     for (TInt i = 0; i < count; i++)
       
  2161         {
       
  2162         if (iGlobalObjects[i]->ObjectId() == aObjectId)
       
  2163             {
       
  2164             // Found testcase with specified TestId
       
  2165             return iGlobalObjects[i];
       
  2166             }
       
  2167         }
       
  2168     
       
  2169     return NULL;
       
  2170     }
       
  2171 
       
  2172 /*
       
  2173 -------------------------------------------------------------------------------
       
  2174 
       
  2175      Class: CTestScripter
       
  2176 
       
  2177      Method: AppendTestResultToResultDes
       
  2178 
       
  2179      Description: Append to TC's result description (if possible due to length) 
       
  2180                   limitation provided text in [] brackets.
       
  2181   
       
  2182      Parameters: None.
       
  2183 
       
  2184      Return Values: None.
       
  2185 
       
  2186      Errors/Exceptions: None.
       
  2187 
       
  2188      Status: Proposal
       
  2189     
       
  2190 -------------------------------------------------------------------------------
       
  2191 */
       
  2192 void CTestScripter::AppendTestResultToResultDes(TDes& aResultDescr, const TDesC& aTestCaseResultDescr)
       
  2193     {
       
  2194     if(aTestCaseResultDescr != KNullDesC)
       
  2195         {
       
  2196         _LIT(KAdditionalInfo, " [%S]");
       
  2197         TInt len = aResultDescr.Length() + KAdditionalInfo().Length() + aTestCaseResultDescr.Length();
       
  2198 
       
  2199         if(len > KStifMaxResultDes)
       
  2200             {
       
  2201             len = KStifMaxResultDes - aResultDescr.Length() - KAdditionalInfo().Length();
       
  2202             if(len > 0)
       
  2203                 {
       
  2204                 TPtrC descr = aTestCaseResultDescr.Mid(0, len); 
       
  2205                 aResultDescr.AppendFormat(KAdditionalInfo, &descr);
       
  2206                 }
       
  2207             }
       
  2208         else
       
  2209             {
       
  2210             aResultDescr.AppendFormat(KAdditionalInfo, &aTestCaseResultDescr);
       
  2211             }
       
  2212         }
       
  2213     }
       
  2214 
       
  2215 /*
       
  2216 -------------------------------------------------------------------------------
       
  2217 
       
  2218     DESCRIPTION
       
  2219 
       
  2220     This module contains the implementation of CTestRunner class 
       
  2221     member functions. CTestRunner is used to execute TestScripter testcase by 
       
  2222     CTestScripter.
       
  2223 
       
  2224 -------------------------------------------------------------------------------
       
  2225 */
       
  2226 // MACROS
       
  2227 #ifdef LOGGER
       
  2228 #undef LOGGER
       
  2229 #endif
       
  2230 #define LOGGER iTestScripter->iLog
       
  2231 
       
  2232 // ================= MEMBER FUNCTIONS =========================================
       
  2233 
       
  2234 /*
       
  2235 -------------------------------------------------------------------------------
       
  2236 
       
  2237      Class: CTestRunner
       
  2238 
       
  2239      Method: CTestRunner
       
  2240 
       
  2241      Description: Default constructor
       
  2242 
       
  2243      C++ default constructor can NOT contain any code, that
       
  2244      might leave.
       
  2245      
       
  2246      Parameters: CTestScripter* aTestScripter: in: Backpointer to CTestScripter
       
  2247 
       
  2248      Return Values: None
       
  2249 
       
  2250      Errors/Exceptions: None
       
  2251 
       
  2252      Status: Draft
       
  2253     
       
  2254 -------------------------------------------------------------------------------
       
  2255 */
       
  2256 CTestRunner::CTestRunner( CTestScripter* aTestScripter ): 
       
  2257     CActive(  CActive::EPriorityHigh ), // Executed with highest priority 
       
  2258     iState( ERunnerIdle ),
       
  2259     iInternalStateForSubTestCases( EISNotStarted ),
       
  2260     iTestScripter( aTestScripter ),
       
  2261     iRemainingTimeValue( 0 )
       
  2262     {
       
  2263     CActiveScheduler::Add( this );
       
  2264     __TRACEFUNC();
       
  2265     
       
  2266     }
       
  2267 
       
  2268 /*
       
  2269 -------------------------------------------------------------------------------
       
  2270 
       
  2271      Class: CTestRunner
       
  2272 
       
  2273      Method: ConstructL
       
  2274 
       
  2275      Description: Symbian OS second phase constructor
       
  2276 
       
  2277      Symbian OS default constructor can leave.
       
  2278 
       
  2279      Parameters:    None
       
  2280 
       
  2281      Return Values: None
       
  2282 
       
  2283      Errors/Exceptions: None
       
  2284 
       
  2285      Status: Draft
       
  2286     
       
  2287 -------------------------------------------------------------------------------
       
  2288 */
       
  2289 void CTestRunner::ConstructL()
       
  2290     {
       
  2291     
       
  2292     iPauseTimer.CreateLocal();
       
  2293     
       
  2294     // Initiaze all OOM related variables to default.
       
  2295     OOMHeapToNormal();
       
  2296     
       
  2297     iLoopHelper = CLoopHelper::NewL( this );
       
  2298     
       
  2299     iSlavesManager = CSlavesManager::NewL( this, iTestScripter->TestModuleIf() );
       
  2300     }
       
  2301 
       
  2302 /*
       
  2303 -------------------------------------------------------------------------------
       
  2304 
       
  2305      Class: CTestRunner
       
  2306 
       
  2307      Method: NewL
       
  2308 
       
  2309      Description: Two-phased constructor.
       
  2310           
       
  2311      Parameters: CTestScripter* aTestScripter: in: Backpointer to CTestScripter
       
  2312 
       
  2313      Return Values: CTestRunner*: new object
       
  2314 
       
  2315      Errors/Exceptions: Leaves if new or ConstructL leaves
       
  2316 
       
  2317      Status: Draft
       
  2318     
       
  2319 -------------------------------------------------------------------------------
       
  2320 */
       
  2321 
       
  2322 CTestRunner* CTestRunner::NewL( CTestScripter* aTestScripter )
       
  2323     {
       
  2324     CTestRunner* self = new (ELeave) CTestRunner( aTestScripter );
       
  2325      
       
  2326     CleanupStack::PushL( self );
       
  2327     self->ConstructL();
       
  2328     CleanupStack::Pop();
       
  2329 
       
  2330     return self;
       
  2331     }
       
  2332 
       
  2333 /*
       
  2334 -------------------------------------------------------------------------------
       
  2335 
       
  2336      Class: CTestRunner
       
  2337 
       
  2338      Method: ~CTestRunner
       
  2339 
       
  2340      Description: Destructor
       
  2341      
       
  2342      Parameters:    None
       
  2343 
       
  2344      Return Values: None
       
  2345 
       
  2346      Errors/Exceptions: None
       
  2347 
       
  2348      Status: Approved
       
  2349     
       
  2350 -------------------------------------------------------------------------------
       
  2351 */     
       
  2352 
       
  2353 CTestRunner::~CTestRunner()
       
  2354     {
       
  2355     __TRACEFUNC();
       
  2356     Cancel();
       
  2357 
       
  2358     iPauseTimer.Close();
       
  2359     
       
  2360     delete iLine;
       
  2361     iLine = NULL;
       
  2362     
       
  2363     delete iLoopHelper;
       
  2364     iLoopHelper = NULL;
       
  2365     
       
  2366     iSubTestCases.ResetAndDestroy();
       
  2367     iSubTestCases.Close();
       
  2368         
       
  2369     delete iTestIdForComplete;
       
  2370     iTestIdForComplete = NULL;
       
  2371     
       
  2372     delete iFailedSubTestCaseInfo;
       
  2373     iFailedSubTestCaseInfo = NULL;
       
  2374     
       
  2375     TInt count = iEventArray.Count();
       
  2376     TEventIf event( TEventIf::ERelEvent ); 
       
  2377     for( TInt i = 0; i < count; i++ )
       
  2378         {
       
  2379         HBufC* tmp = iEventArray[0];
       
  2380         event.SetName( iEventArray[0]->Des() );
       
  2381         iEventArray.Remove(0);
       
  2382         if( iTestScripter != NULL )
       
  2383             {
       
  2384             iTestScripter->TestModuleIf().Event( event );
       
  2385             }
       
  2386         delete tmp;
       
  2387         }
       
  2388      
       
  2389     iTestCaseResults.Reset();
       
  2390     iEventArray.ResetAndDestroy();
       
  2391     iTestCaseResults.Close();
       
  2392     iEventArray.Close();
       
  2393 
       
  2394     delete iSlavesManager;
       
  2395     iSlavesManager = NULL;
       
  2396     
       
  2397     // Reset test case allow result to CTestModuleIf side too. This is
       
  2398     // used in TAL-TA5L macro handling.
       
  2399     if( iTestScripter != NULL )
       
  2400         {
       
  2401         User::LeaveIfError( 
       
  2402             iTestScripter->TestModuleIf().ResetAllowResult() );
       
  2403         }
       
  2404         
       
  2405     // Stop all remaining interference object
       
  2406     TInt count_inter = iTestInterferenceArray.Count();
       
  2407     for( TInt a = 0; a < count_inter; a++ )
       
  2408         {
       
  2409         if( iTestInterferenceArray[a] != NULL )
       
  2410             {
       
  2411             iTestInterferenceArray[a]->iInterference->Stop();
       
  2412             }
       
  2413         }
       
  2414     iTestInterferenceArray.ResetAndDestroy();
       
  2415     iTestInterferenceArray.Close();
       
  2416     
       
  2417     // Stop all remaining measurement modules
       
  2418     const TInt count_meas = iTestMeasurementArray.Count();
       
  2419     for( TInt b = 0; b < count_meas; b++ )
       
  2420         {
       
  2421         if( iTestMeasurementArray[b] != NULL )
       
  2422             {
       
  2423             iTestMeasurementArray[b]->iMeasurement->Stop();
       
  2424             }
       
  2425         }
       
  2426     iTestMeasurementArray.ResetAndDestroy();
       
  2427     iTestMeasurementArray.Close();
       
  2428     iPlugins.ResetAndDestroy();
       
  2429     iPlugins.Close();
       
  2430     iPluginnames.ResetAndDestroy();
       
  2431     iPluginnames.Close();
       
  2432     iLibrary.Close();
       
  2433    
       
  2434 
       
  2435     }
       
  2436 
       
  2437 /*
       
  2438 -------------------------------------------------------------------------------
       
  2439 
       
  2440      Class: CTestRunner
       
  2441 
       
  2442      Method: RunL
       
  2443 
       
  2444      Description: Derived from CActive, handles testcase execution.
       
  2445 
       
  2446      Parameters:    None.
       
  2447 
       
  2448      Return Values: None.
       
  2449 
       
  2450      Errors/Exceptions: Leaves on error situations.
       
  2451 
       
  2452      Status: Draft
       
  2453     
       
  2454 -------------------------------------------------------------------------------
       
  2455 */
       
  2456 void CTestRunner::RunL()
       
  2457     {
       
  2458     __TRACEFUNC();
       
  2459     __TRACE( KMessage, (_L("CTestRunner::RunL: [%d] "), iStatus.Int() ));
       
  2460      
       
  2461     if ( iInternalStateForSubTestCases == EISNotStarted )
       
  2462         {
       
  2463         iInternalStateForSubTestCases = EISRuning;
       
  2464         }
       
  2465     
       
  2466     // Check if we need to Pause test case again  
       
  2467     if( iStatus == KErrNone && iRemainingTimeValue > 0 )
       
  2468         {           
       
  2469         // Maximum time for one RTimer::After request                   
       
  2470         TInt maximumTime = KMaxTInt / 1000;                       
       
  2471         
       
  2472         __TRACE( KMessage, (_L("CTestRunner::RunL: Going to reissue After request ") ) );           
       
  2473         __TRACE( KMessage, (_L("CTestRunner::RunL: iRemainingTimeValue = %d"), iRemainingTimeValue ) );        
       
  2474         
       
  2475         if( iRemainingTimeValue < maximumTime )
       
  2476             {                           
       
  2477             iPauseTimer.After( iStatus, ( iRemainingTimeValue * 1000  ) );
       
  2478             iRemainingTimeValue = 0;
       
  2479             }
       
  2480         else
       
  2481             {            
       
  2482             iRemainingTimeValue -= maximumTime;
       
  2483             iPauseTimer.After( iStatus, ( maximumTime * 1000 ) );                
       
  2484             }     
       
  2485         SetActive();
       
  2486         }     
       
  2487     else    
       
  2488         {  
       
  2489         TBool continueTask = EFalse;
       
  2490 
       
  2491         User::LeaveIfError( iStatus.Int() );
       
  2492 
       
  2493         if( ( iTestScripter == NULL ) || 
       
  2494             ( iTestScripter->iCurrentParser == NULL ) )
       
  2495             {
       
  2496             __TRACE( KError, (_L("CTestRunner invalid arguments")));
       
  2497             User::Leave( KErrGeneral );
       
  2498             }
       
  2499            
       
  2500         iState = ERunnerIdle;
       
  2501 
       
  2502         // Get next execution line from configuration section
       
  2503         TPtrC line;
       
  2504         // If current parser already has read the first line, then read next line.
       
  2505         // Otherwise read the first line.
       
  2506         if(iTestScripter->iCurrentParserReadFirstLine && iTestScripter->iCurrentParser->GetNextLine(line) == KErrNone 
       
  2507            || !iTestScripter->iCurrentParserReadFirstLine && iTestScripter->iCurrentParser->GetLine(KNullDesC, line) == KErrNone)
       
  2508             {
       
  2509             iTestScripter->iCurrentParserReadFirstLine = ETrue;
       
  2510             
       
  2511             // Got new execution line 
       
  2512             __TRACE( KMessage, (_L("Executing line [%S]"), &line));
       
  2513             
       
  2514             CStifItemParser* item = PreprocessLineL( line );
       
  2515                 
       
  2516             CleanupStack::PushL( item ); 
       
  2517               
       
  2518             TPtrC keyword;
       
  2519              // Get first word from line, i.e. keyword
       
  2520             User::LeaveIfError( item->GetString( _L(""), keyword ) );
       
  2521 
       
  2522             __TRACE( KMessage, (_L("CTestRunner execute %S"), &keyword ));
       
  2523 
       
  2524             // Execute script line 
       
  2525             continueTask = ExecuteLineL( keyword, item );
       
  2526             __TRACE( KMessage, (_L("CTestRunner %S executed"), &keyword ));
       
  2527                          
       
  2528             if( continueTask )
       
  2529                 {
       
  2530                   __TRACE( KMessage, (_L("RunL: continueTask")));
       
  2531                  // Set CTestRunner active again to perform 
       
  2532                  // next execution line
       
  2533                  // from testcase section 
       
  2534                 SetRunnerActive();
       
  2535                 }
       
  2536 
       
  2537             CleanupStack::PopAndDestroy( item );
       
  2538             }
       
  2539         else // Stop execution if end of test case
       
  2540             {
       
  2541             __TRACE( KMessage, (_L("Executing line: no more lines from this section")));
       
  2542             // There is no more lines in current parser, but it needs to be
       
  2543             // checked if the parser is not taken for function (sub).
       
  2544             // If this is true, then we have to get back to the parser which
       
  2545             // has called the function.
       
  2546             TInt lastParserIndex = iTestScripter->iParserStack.Count() - 1;
       
  2547             if(lastParserIndex >= 0)
       
  2548                 {
       
  2549                 // Delete current (the last one) parser
       
  2550                 delete iTestScripter->iParserStack[lastParserIndex];
       
  2551                 iTestScripter->iParserStack.Remove(lastParserIndex);
       
  2552                 if(lastParserIndex >= 1) //There is some other parser on the stack
       
  2553                     {
       
  2554                     iTestScripter->iCurrentParser = iTestScripter->iParserStack[lastParserIndex - 1];
       
  2555                     }
       
  2556                 else //The parser stack is empty
       
  2557                     {
       
  2558                     iTestScripter->iCurrentParser = iTestScripter->iSectionParser;
       
  2559                     }
       
  2560                 __TRACE(KMessage, (_L("Returning to calling parser stored on section stack")));
       
  2561                 
       
  2562                 // Continue with the test case
       
  2563                 __TRACE(KMessage, (_L("RunL: continueTask (end of Sub reached)")));
       
  2564                 SetRunnerActive();
       
  2565                 return;
       
  2566                 }
       
  2567             // No more execution lines in testcase section
       
  2568             // Check if there are running test cases
       
  2569             if ( iSubTestCases.Count() > 0 )
       
  2570                 {
       
  2571                 if ( iInternalStateForSubTestCases != EISFinishedWaitingForSubTestCases )
       
  2572                     {
       
  2573                     iInternalStateForSubTestCases = EISFinishedWaitingForSubTestCases;
       
  2574                     }
       
  2575                 // Continue with the test case
       
  2576                 // proper sub test case runner should activate test runner                 
       
  2577                 return;
       
  2578                 }
       
  2579             
       
  2580             iInternalStateForSubTestCases = EISFinished;
       
  2581             
       
  2582             
       
  2583             // Release remote resources
       
  2584             RPointerArray<CSlave>& slaves = iSlavesManager->GetSlaves();
       
  2585             
       
  2586             while ( slaves.Count() > 0 )
       
  2587                 {
       
  2588                 slaves[ 0 ]->WaitForSubTestCasesL();
       
  2589             
       
  2590                 RPointerArray<TEventTS>& slaveEvents = slaves[ 0 ]->GetEvents();
       
  2591                 for ( TInt k = 0; k < slaveEvents.Count(); k++ )
       
  2592                     {
       
  2593                     iSlavesManager->EventReleaseL( slaves[ 0 ], slaveEvents[ k ]->Name() );
       
  2594                     }
       
  2595                 slaveEvents.ResetAndDestroy();
       
  2596                 
       
  2597                 iSlavesManager->SlaveFreeL( slaves[ 0 ]->GetName() );
       
  2598                 }
       
  2599             
       
  2600             __TRACE( KMessage, 
       
  2601                 (_L("CTestRunner::RunL: Testcase script done") ));
       
  2602             iTestScripter->TestModuleIf().Printf( KPrintPriLow, 
       
  2603                 _L("RunL"), _L("Script done"));
       
  2604             
       
  2605        
       
  2606             __TRACE( KMessage, 
       
  2607                 (_L("RunL: All TestCases done, stop CActiveScheduler")));
       
  2608             CActiveScheduler::Current()->Stop();
       
  2609             // Now testcase section is executed, 
       
  2610             // so CTestRunner has done its job and stops
       
  2611             }
       
  2612         }
       
  2613     }
       
  2614      
       
  2615 /*
       
  2616 -------------------------------------------------------------------------------
       
  2617 
       
  2618      Class: CTestRunner
       
  2619 
       
  2620      Method: DoCancel
       
  2621 
       
  2622      Description: Derived from CActive handles the Cancel
       
  2623 
       
  2624      Parameters:    None.
       
  2625 
       
  2626      Return Values: None.
       
  2627 
       
  2628      Errors/Exceptions: None.
       
  2629 
       
  2630      Status: Draft
       
  2631     
       
  2632 -------------------------------------------------------------------------------
       
  2633 */
       
  2634 void CTestRunner::DoCancel()
       
  2635     {
       
  2636     __TRACEFUNC();
       
  2637     __TRACE( KMessage, (_L("CTestRunner::DoCancel")));
       
  2638     iTestScripter->TestModuleIf().Printf( KPrintPriLow, _L("Runner"), _L("DoCancel"));
       
  2639     
       
  2640     iPauseTimer.Cancel();
       
  2641    
       
  2642     CActiveScheduler::Current()->Stop();
       
  2643          
       
  2644     iState = ERunnerCancel;
       
  2645     }
       
  2646 
       
  2647 /*
       
  2648 -------------------------------------------------------------------------------
       
  2649 
       
  2650      Class: CTestRunner
       
  2651 
       
  2652      Method: RunError
       
  2653 
       
  2654      Description: Derived from CActive handles errors from active handler.
       
  2655   
       
  2656      Parameters:    TInt aError: in: error from CActive
       
  2657      
       
  2658      Return Values: KErrNone: success
       
  2659 
       
  2660      Errors/Exceptions: None.
       
  2661 
       
  2662      Status: Draft
       
  2663     
       
  2664 -------------------------------------------------------------------------------
       
  2665 */
       
  2666 TInt CTestRunner::RunError( TInt aError )
       
  2667     {
       
  2668     __TRACEFUNC();
       
  2669     __TRACE( KMessage, (_L("CTestRunner::RunError %d"), aError));
       
  2670 
       
  2671     if ( iRunErrorMessage.Length() != 0 )
       
  2672         {
       
  2673         iTestScripter->TestModuleIf().Printf( KPrintPriLow, _L("Runner"), 
       
  2674                 _L("RunError : %S"), &iRunErrorMessage );  
       
  2675         iRunErrorMessage = KNullDesC;
       
  2676         }
       
  2677     else
       
  2678         {
       
  2679         iTestScripter->TestModuleIf().Printf( KPrintPriLow, _L("Runner"), 
       
  2680                 _L("RunError"));            
       
  2681         }
       
  2682 
       
  2683     iState = ERunnerError;
       
  2684     
       
  2685     // Return error from here, if none given from execution
       
  2686     if( iTestScripter->iResult.iResult == KErrNone )
       
  2687         {
       
  2688         iTestScripter->UpdateTestCaseResult(aError, _L("CTestRunner::RunError"));
       
  2689         }
       
  2690         
       
  2691     CActiveScheduler::Current()->Stop();
       
  2692         
       
  2693     return KErrNone;
       
  2694     
       
  2695     }
       
  2696 
       
  2697 /*
       
  2698 -------------------------------------------------------------------------------
       
  2699 
       
  2700      Class: CTestRunner
       
  2701 
       
  2702      Method: GetLogger
       
  2703 
       
  2704      Description: Returns TestScripter logger
       
  2705   
       
  2706      Parameters: None
       
  2707      
       
  2708      Return Values: Pointer to TestScripter logger.
       
  2709 
       
  2710      Errors/Exceptions: None.
       
  2711 
       
  2712      Status: Draft
       
  2713     
       
  2714 -------------------------------------------------------------------------------
       
  2715 */
       
  2716 CStifLogger* CTestRunner::GetLogger()
       
  2717     {
       
  2718     return iTestScripter->iLog;
       
  2719     }
       
  2720 
       
  2721 /*
       
  2722 -------------------------------------------------------------------------------
       
  2723 
       
  2724      Class: CTestRunner
       
  2725 
       
  2726      Method: PreprocessLineL
       
  2727 
       
  2728      Description: Preprocesses script line
       
  2729   
       
  2730      Parameters:  TPtrC& line: in: script line
       
  2731                   CStifItemParser*& aItem: out: New CItemParser for script line.
       
  2732                     
       
  2733      Return Values: HBufC* pointer if new memory that has been allocated
       
  2734 
       
  2735      Errors/Exceptions: Leaves on error situations.
       
  2736 
       
  2737      Status: Draft
       
  2738     
       
  2739 -------------------------------------------------------------------------------
       
  2740 */        
       
  2741 CStifItemParser* CTestRunner::PreprocessLineL( TDesC& line )
       
  2742     {
       
  2743     CStifItemParser* item = NULL;
       
  2744     TPtrC tmp;
       
  2745     TInt len = 0;
       
  2746     TInt ret = 0;
       
  2747         
       
  2748     // Decide how long buffer should be allocated
       
  2749     if( line.Length() < KMaxName/2 )
       
  2750         {
       
  2751         len = KMaxName;
       
  2752         }
       
  2753     else 
       
  2754         {
       
  2755         len = line.Length() + KMaxName;
       
  2756         }
       
  2757     delete iLine;
       
  2758     iLine = 0;
       
  2759     iLine = HBufC::NewL(len);
       
  2760     TPtr parsedLine(iLine->Des());
       
  2761     len = 0;
       
  2762     
       
  2763     HBufC* sourceLine = line.AllocL();
       
  2764     CleanupStack::PushL(sourceLine);
       
  2765     
       
  2766     //Check for local variable definitions
       
  2767     item = CStifItemParser::NewL(sourceLine->Des(), 0, sourceLine->Length());
       
  2768     CleanupStack::PushL(item);
       
  2769     
       
  2770     ret = item->GetString(KNullDesC, tmp);
       
  2771     TBool isVarDefinition = (tmp == TTestKeywords::Keyword(TTestKeywords::EVar));
       
  2772          
       
  2773     if(!isVarDefinition)
       
  2774         {
       
  2775         while( ret == KErrNone )
       
  2776             {
       
  2777             len += CheckDefinedLocals(tmp);
       
  2778             if((parsedLine.Length() + tmp.Length() + 1) > parsedLine.MaxLength())
       
  2779                 {
       
  2780                 // Allocate bigger buffer
       
  2781                 HBufC* tmpBuf = HBufC::NewL(parsedLine.MaxLength() + KMaxName);
       
  2782                 CleanupStack::PushL(tmpBuf);
       
  2783                 TPtrC ptr(iLine->Des());
       
  2784                 parsedLine.Set(tmpBuf->Des());
       
  2785                 parsedLine.Copy(ptr);
       
  2786                 delete iLine;
       
  2787                 iLine = tmpBuf;
       
  2788                 CleanupStack::Pop(tmpBuf);
       
  2789                 } 
       
  2790             parsedLine.Append(tmp);        
       
  2791             ret = item->GetNextString(tmp);
       
  2792             if(ret == KErrNone)
       
  2793                 {
       
  2794                 // Add space only if we got new string
       
  2795                 parsedLine.Append(_L(" "));        
       
  2796                 }
       
  2797             }
       
  2798         CleanupStack::PopAndDestroy(item);
       
  2799         item = NULL;
       
  2800         CleanupStack::PopAndDestroy(sourceLine);
       
  2801         sourceLine = NULL;
       
  2802         
       
  2803         //Prepare data for checking for defines
       
  2804         sourceLine = parsedLine.AllocL();
       
  2805         CleanupStack::PushL(sourceLine);
       
  2806         parsedLine.Zero();
       
  2807         
       
  2808         item = CStifItemParser::NewL(sourceLine->Des(), 0, sourceLine->Length());
       
  2809         CleanupStack::PushL(item);
       
  2810     
       
  2811         ret = item->GetString(KNullDesC, tmp);
       
  2812         }
       
  2813 
       
  2814     //Check for defines
       
  2815     while(ret == KErrNone)
       
  2816         {
       
  2817         if(!isVarDefinition)
       
  2818             {
       
  2819             len += CheckDefined(tmp);
       
  2820             }
       
  2821         
       
  2822         if((parsedLine.Length() + tmp.Length() + 1) > parsedLine.MaxLength())
       
  2823             {
       
  2824             // Allocate bigger buffer
       
  2825             HBufC* tmpBuf = HBufC::NewL(parsedLine.MaxLength() + KMaxName);
       
  2826             CleanupStack::PushL(tmpBuf);
       
  2827             TPtrC ptr(iLine->Des());
       
  2828             parsedLine.Set(tmpBuf->Des());
       
  2829             parsedLine.Copy(ptr);
       
  2830             delete iLine;
       
  2831             iLine = tmpBuf;
       
  2832             CleanupStack::Pop(tmpBuf);
       
  2833             } 
       
  2834         parsedLine.Append(tmp);        
       
  2835         ret = item->GetNextString(tmp);
       
  2836         if( ret == KErrNone )
       
  2837             {
       
  2838             // Add space only if we got new string
       
  2839             parsedLine.Append(_L(" "));        
       
  2840             }
       
  2841         }
       
  2842     
       
  2843     //Cleaning...
       
  2844     CleanupStack::PopAndDestroy(item);
       
  2845     item = NULL;
       
  2846     CleanupStack::PopAndDestroy(sourceLine);
       
  2847     sourceLine = NULL;
       
  2848 
       
  2849     __TRACE(KMessage, (_L("Preprocessed line [%S]"), &parsedLine));
       
  2850     item = CStifItemParser::NewL( parsedLine, 0, parsedLine.Length() );
       
  2851     
       
  2852     return item;
       
  2853     }
       
  2854 
       
  2855 /*
       
  2856 -------------------------------------------------------------------------------
       
  2857 
       
  2858      Class: CTestRunner
       
  2859 
       
  2860      Method: CheckDefined
       
  2861 
       
  2862      Description: Check if aWord is some defined word
       
  2863   
       
  2864      Parameters:  TPtrC& aWord: inout: Parsed word, defined or original returned
       
  2865                     
       
  2866      Return Values: TInt: length diference between new and old word
       
  2867      
       
  2868      Errors/Exceptions: None.
       
  2869 
       
  2870      Status: Draft
       
  2871     
       
  2872 -------------------------------------------------------------------------------
       
  2873 */   
       
  2874 TInt CTestRunner::CheckDefined( TPtrC& aWord )
       
  2875     {
       
  2876     
       
  2877     TInt len = 0;
       
  2878     TInt i = 0;
       
  2879 
       
  2880     // KLoopCounter word changing to current loop count value.
       
  2881     if( aWord == KLoopCounter )
       
  2882         {
       
  2883         iLoopCounterDes.Zero();
       
  2884         iLoopCounterDes.AppendNum( iLoopCounter );
       
  2885         len = iLoopCounterDes.Length() - aWord.Length();
       
  2886         aWord.Set( iLoopCounterDes );
       
  2887         return len;
       
  2888         }
       
  2889 
       
  2890     // First, check values defined in test case file
       
  2891     TInt count = iTestScripter->iDefinedRuntime.Count();
       
  2892     for( i = 0; i < count; i++ )
       
  2893         {
       
  2894         if( iTestScripter->iDefinedRuntime[i]->Name() == aWord )
       
  2895             { 
       
  2896             len = iTestScripter->iDefinedRuntime[i]->Value().Length() - aWord.Length();
       
  2897             aWord.Set( iTestScripter->iDefinedRuntime[i]->Value() );
       
  2898             return len;
       
  2899             }
       
  2900         }
       
  2901 
       
  2902     // Second, check values defined in test module initialization file
       
  2903     count = iTestScripter->iDefinedIni.Count();
       
  2904     for( i = 0; i < count; i++ )
       
  2905         {
       
  2906         if( iTestScripter->iDefinedIni[i]->Name() == aWord )
       
  2907             { 
       
  2908             len = iTestScripter->iDefinedIni[i]->Value().Length() - aWord.Length();
       
  2909             aWord.Set( iTestScripter->iDefinedIni[i]->Value() );
       
  2910             return len;
       
  2911             }
       
  2912         }
       
  2913 
       
  2914     return len;
       
  2915     }
       
  2916 
       
  2917 /*
       
  2918 -------------------------------------------------------------------------------
       
  2919 
       
  2920      Class: CTestRunner
       
  2921 
       
  2922      Method: CheckDefinedLocals
       
  2923 
       
  2924      Description: Check if aWord is a local variable
       
  2925   
       
  2926      Parameters:  TPtrC& aWord: inout: Parsed word, defined or original returned
       
  2927                     
       
  2928      Return Values: TInt: length diference between new and old word
       
  2929      
       
  2930      Errors/Exceptions: None.
       
  2931 
       
  2932      Status: Draft
       
  2933     
       
  2934 -------------------------------------------------------------------------------
       
  2935 */   
       
  2936 TInt CTestRunner::CheckDefinedLocals( TPtrC& aWord )
       
  2937     {
       
  2938     
       
  2939     TInt len = 0;
       
  2940     TInt i = 0;
       
  2941 
       
  2942     TInt count = iTestScripter->iDefinedLocal.Count();
       
  2943     for(i = 0; i < count; i++)
       
  2944         {
       
  2945         if(iTestScripter->iDefinedLocal[i]->Name() == aWord)
       
  2946             { 
       
  2947             len = iTestScripter->iDefinedLocal[i]->Value().Length() - aWord.Length();
       
  2948             aWord.Set(iTestScripter->iDefinedLocal[i]->Value());
       
  2949             return len;
       
  2950             }
       
  2951         }
       
  2952 
       
  2953     return len;
       
  2954     }
       
  2955 
       
  2956 /*
       
  2957 -------------------------------------------------------------------------------
       
  2958 
       
  2959      Class: CTestRunner
       
  2960 
       
  2961      Method: ExecuteLineL
       
  2962 
       
  2963      Description: Executes script line
       
  2964   
       
  2965      Parameters:    TDesC& aKeyword: in: keyword string
       
  2966                     CStifItemParser* aItem: in: script line
       
  2967                     
       
  2968      Return Values: ETrue: continue script file execution
       
  2969                     EFalse: stop script file execution
       
  2970 
       
  2971      Errors/Exceptions: Leaves on error situations.
       
  2972 
       
  2973      Status: Approved
       
  2974     
       
  2975 -------------------------------------------------------------------------------
       
  2976 */
       
  2977 TBool CTestRunner::ExecuteLineL( TDesC& aKeyword,
       
  2978                                  CStifItemParser* aItem )
       
  2979     {
       
  2980     _LIT( KErrMsgDeleteNoParam, "Delete: Name of object is not defined" );
       
  2981     _LIT( KErrMsgDeleteObjNotFound, "Delete: Can't delete object %S. Object does not exists." );
       
  2982     _LIT( KErrMsgPauseTimeoutNotDefined, "Pause: No timeout value given or value has invalid format" );
       
  2983     _LIT( KErrMsgPauseTimeoutNotPositive, "Pause: Timeout value can't be <0" );
       
  2984     _LIT( KErrMsgCreateTestModeleNotDefined, "Create: Name of test module is not defined" );
       
  2985     _LIT( KErrMsgCreateObjectIdNotDefined, "Create: Name of test module object is not defined" );
       
  2986     _LIT( KErrMsgCreateKernelDriverNotDefined, "CreateKernel: Kernel driver name is not defined" );
       
  2987     _LIT( KErrMsgCreateKernelObjectNameNotDefined, "CreateKernel: Kernel driver object name is not defined" );
       
  2988     _LIT( KErrMsgCreateKernelFailed, "CreateKernel: Can't creeate kernel driver %S" );
       
  2989     _LIT( KErrMsgWaitTestClassNameNotDefined, "WaitTestClass: Test class object name is not defined" );
       
  2990     _LIT( KErrMsgWaitTestClassObjNotFound, "WaitTestClass: Test class object %S does not exists" );
       
  2991     _LIT( KErrMsgBringToForegroundNotSupported, "BringToForeground: BringToForeground is not supported in non s60 environment" );
       
  2992     _LIT( KErrMsgSendToBackgroundNotSupported, "SendToBackground: SendToBackground is not supported in non s60 environment" );    
       
  2993     _LIT( KErrMsgPressKeyNotSupported, "PressKey: PressKey is not supported in non s60 environment. Check if .cfg file name contains ui_ prefix and UITestingSupport= YES entry is defined in TestFrameworkd.ini" );
       
  2994     _LIT( KErrMsgTypeTextNotSupported, "TypeText: TypeText is not supported in non s60 environment. Check if .cfg file name contains ui_ prefix and UITestingSupport= YES entry is defined in TestFrameworkd.ini" );
       
  2995     _LIT( KErrMsgSendPointerEventNotSupported, "SendPointerEvent: SendPointerEvent is not supported in non s60 environment. Check if .cfg file name contains ui_ prefix and UITestingSupport= YES entry is defined in TestFrameworkd.ini" );
       
  2996     _LIT( KErrVarNameError, "Variable: Could not get variable name");
       
  2997     _LIT( KErrVarValueError, "Variable: Value too long");
       
  2998     _LIT( KErrSubNameError, "Sub: Could not get name of Sub to be called");
       
  2999     _LIT( KErrSubGetError, "Sub: Could not get Sub section");
       
  3000     
       
  3001     TPtrC temp;
       
  3002     RBuf buf;
       
  3003     buf.Create(512);
       
  3004     CleanupClosePushL(buf);
       
  3005     buf.Append(aKeyword);
       
  3006     buf.Append(_L(" "));
       
  3007     while(aItem->GetNextString(temp)==KErrNone)
       
  3008       {
       
  3009       
       
  3010       
       
  3011         RBuf tempbuf;
       
  3012         tempbuf.Create(512);
       
  3013         iTestScripter->Substitute(temp,tempbuf);
       
  3014         buf.Append(tempbuf);
       
  3015         
       
  3016         buf.Append(_L(" "));
       
  3017         tempbuf.Close();
       
  3018       }
       
  3019     
       
  3020     delete aItem;
       
  3021     aItem=NULL;
       
  3022     
       
  3023     temp.Set((TUint16 *)buf.Ptr(),buf.Length());
       
  3024     aItem=CStifItemParser::NewL(temp,0,temp.Length());
       
  3025     
       
  3026     aItem->GetString(KNullDesC,temp);
       
  3027     
       
  3028     
       
  3029     iRunErrorMessage = KNullDesC;    
       
  3030     TBool continueTask = ETrue;
       
  3031     
       
  3032     TInt key = TTestKeywords::Parse( aKeyword, TTestKeywords::Keyword );
       
  3033 
       
  3034     switch( key )
       
  3035         {
       
  3036         // Test case execution control cases
       
  3037         case TTestKeywords::ECreate:
       
  3038         case TTestKeywords::ECreateX:
       
  3039         case TTestKeywords::ECreateShareObj:
       
  3040             {
       
  3041             TPtrC tmp;
       
  3042             TName module;
       
  3043 
       
  3044             // Testmodule name
       
  3045             TInt ret = aItem->GetNextString( tmp );
       
  3046             
       
  3047             if ( ret != KErrNone )
       
  3048                 {
       
  3049                 iRunErrorMessage = KErrMsgCreateTestModeleNotDefined;
       
  3050                 User::Leave( KErrArgument );
       
  3051                 }
       
  3052             TParse p;
       
  3053             p.Set( tmp, NULL, NULL );
       
  3054             // Check if exists in module name
       
  3055             if( p.ExtPresent() )
       
  3056                 {
       
  3057                 module.Copy( tmp );
       
  3058                 }
       
  3059             else 
       
  3060                 {
       
  3061                 // No extension in module name, add it here
       
  3062                 _LIT( KDllExtension, ".dll");
       
  3063                 module.Copy( tmp );
       
  3064                 module.Append( KDllExtension );
       
  3065                 }
       
  3066 
       
  3067             // objectid
       
  3068             ret = aItem->GetNextString( tmp );
       
  3069             
       
  3070             if ( ret != KErrNone )
       
  3071                 {
       
  3072                 iRunErrorMessage = KErrMsgCreateObjectIdNotDefined;
       
  3073                 User::Leave( KErrArgument );
       
  3074                 }        
       
  3075 
       
  3076             __TRACE( KMessage, (_L("%S %S"), &aKeyword, &tmp));
       
  3077             iTestScripter->TestModuleIf().Printf( KPrintPriLow, _L("Runner"), 
       
  3078                 _L("%S %S"), &aKeyword, &tmp);
       
  3079 
       
  3080             if( TTestKeywords::ECreateShareObj == key )
       
  3081                 {
       
  3082                 iTestScripter->CreateShareObjectL( module, tmp ); 
       
  3083                 }
       
  3084             else
       
  3085                 {
       
  3086                 iTestScripter->CreateObjectL( module, tmp );
       
  3087                 }
       
  3088             }
       
  3089             break;        
       
  3090         case TTestKeywords::ERestoreShareObj:
       
  3091             {
       
  3092             TPtrC tmp;
       
  3093 
       
  3094             // objectid
       
  3095             TInt ret = aItem->GetNextString( tmp );
       
  3096             
       
  3097             if ( ret != KErrNone )
       
  3098                 {
       
  3099                 iRunErrorMessage = KErrMsgCreateObjectIdNotDefined;
       
  3100                 User::Leave( KErrArgument );
       
  3101                 }        
       
  3102 
       
  3103             __TRACE( KMessage, (_L("%S %S"), &aKeyword, &tmp));
       
  3104             iTestScripter->TestModuleIf().Printf( KPrintPriLow, _L("Runner"), 
       
  3105                 _L("%S %S"), &aKeyword, &tmp);
       
  3106 
       
  3107           
       
  3108             iTestScripter->RestoreShareObjectL( tmp );
       
  3109             }
       
  3110             break;            
       
  3111         case TTestKeywords::ECreateKernel:
       
  3112             {
       
  3113             TPtrC obj;
       
  3114             TPtrC driver;
       
  3115 
       
  3116             // Testdriver name
       
  3117             TInt ret = aItem->GetNextString( driver );
       
  3118             if ( ret != KErrNone )
       
  3119                 {
       
  3120                 iRunErrorMessage = KErrMsgCreateKernelDriverNotDefined;
       
  3121                 User::Leave( ret );
       
  3122                 }
       
  3123 
       
  3124             // objectid            
       
  3125             ret = aItem->GetNextString( obj );
       
  3126             if ( ret != KErrNone )
       
  3127                 {
       
  3128                 iRunErrorMessage = KErrMsgCreateKernelObjectNameNotDefined;
       
  3129                 User::Leave( ret );
       
  3130                 }
       
  3131 
       
  3132             __TRACE( KMessage, (_L("%S %S"), &aKeyword, &obj));
       
  3133             iTestScripter->TestModuleIf().Printf( KPrintPriLow, _L("Runner"), 
       
  3134                 _L("%S %S"), &aKeyword, &obj);
       
  3135             TInt leaveErr = KErrNone;
       
  3136             TRAP( leaveErr, iTestScripter->CreateKernelObjectL( driver, obj ));
       
  3137             if ( leaveErr != KErrNone )
       
  3138                 {
       
  3139                 iRunErrorMessage.Format( KErrMsgCreateKernelFailed, &driver );
       
  3140                 User::Leave( leaveErr );
       
  3141                 }
       
  3142             }
       
  3143             break;
       
  3144         case TTestKeywords::EDelete:
       
  3145             {
       
  3146             TPtrC tmp;
       
  3147             // objectid
       
  3148             TInt ret = aItem->GetNextString( tmp );
       
  3149             if ( ret != KErrNone )
       
  3150                 {
       
  3151                 iRunErrorMessage = KErrMsgDeleteNoParam;
       
  3152                 User::Leave( ret );
       
  3153                 }
       
  3154 
       
  3155             __TRACE( KMessage, (_L("%S %S"), &aKeyword, &tmp));
       
  3156             iTestScripter->TestModuleIf().Printf( KPrintPriLow, _L("Runner"), 
       
  3157                 _L("%S %S"), &aKeyword, &tmp);
       
  3158 
       
  3159             ret = iTestScripter->DeleteObjectL( tmp );
       
  3160             if ( ret != KErrNone )
       
  3161                 {
       
  3162                 iRunErrorMessage.Format( KErrMsgDeleteObjNotFound, &tmp );
       
  3163                 User::Leave( ret );
       
  3164                 }
       
  3165             }
       
  3166             break;
       
  3167         case TTestKeywords::EDeleteShareObj:
       
  3168             {
       
  3169             TPtrC tmp;
       
  3170             // objectid
       
  3171             TInt ret = aItem->GetNextString( tmp );
       
  3172             if ( ret != KErrNone )
       
  3173                 {
       
  3174                 iRunErrorMessage = KErrMsgDeleteNoParam;
       
  3175                 User::Leave( ret );
       
  3176                 }
       
  3177 
       
  3178             __TRACE( KMessage, (_L("%S %S"), &aKeyword, &tmp));
       
  3179             iTestScripter->TestModuleIf().Printf( KPrintPriLow, _L("Runner"), 
       
  3180                 _L("%S %S"), &aKeyword, &tmp);
       
  3181 
       
  3182             ret = iTestScripter->DeleteScripterObjectL( tmp );
       
  3183             if(ret)
       
  3184                 {
       
  3185                 iRunErrorMessage.Format( KErrMsgDeleteObjNotFound, &tmp );
       
  3186                 User::Leave( ret );            
       
  3187                 }
       
  3188             }
       
  3189             break;
       
  3190         case TTestKeywords::ERun:
       
  3191             continueTask = ExecuteRunL( aItem );
       
  3192             break;
       
  3193         case TTestKeywords::ECancelIfError:
       
  3194             iCancelIfError = ETrue;
       
  3195             break;            
       
  3196         case TTestKeywords::EComplete:
       
  3197             continueTask = ExecuteCompleteL( aItem );
       
  3198             break;
       
  3199         case TTestKeywords::EPauseTest:
       
  3200             continueTask = ControlSubTestCaseL( TTestKeywords::EPauseTest, aItem );
       
  3201             break;            
       
  3202         case TTestKeywords::EResume:            
       
  3203             continueTask = ControlSubTestCaseL( TTestKeywords::EResume, aItem );
       
  3204             break;
       
  3205         case TTestKeywords::ECancel:
       
  3206             continueTask = ControlSubTestCaseL( TTestKeywords::ECancel, aItem );
       
  3207             break;
       
  3208         case TTestKeywords::ERequest:
       
  3209         case TTestKeywords::EWait:
       
  3210         case TTestKeywords::ERelease:
       
  3211         case TTestKeywords::ESet:
       
  3212         case TTestKeywords::EUnset:
       
  3213             continueTask = ExecuteEventL( aKeyword, aItem );
       
  3214             break;
       
  3215         case TTestKeywords::EPrint:
       
  3216             {
       
  3217             __TRACE( KMessage, (_L("%S"), &aKeyword));
       
  3218             iTestScripter->TestModuleIf().Printf( KPrintPriLow, _L("Runner"), 
       
  3219                 _L("%S"), &aKeyword );
       
  3220 
       
  3221             RBuf buf;
       
  3222             buf.CreateL(1024);
       
  3223             CleanupClosePushL(buf);
       
  3224             
       
  3225             TPtrC tmp;
       
  3226 
       
  3227             while( aItem->GetNextString( tmp ) == KErrNone )
       
  3228                 {
       
  3229                 if( buf.Length() + tmp.Length() >= buf.MaxLength() )
       
  3230                     {
       
  3231                     buf.ReAllocL(buf.MaxLength() + tmp.Length() * 10);
       
  3232                     }
       
  3233                 buf.Append( tmp );
       
  3234                 buf.Append( _L(" ") );
       
  3235                 }
       
  3236             
       
  3237             iTestScripter->TestModuleIf().Printf( KPrintPriNorm, 
       
  3238                 _L("Test"), 
       
  3239                 _L("%S"), &buf);
       
  3240             RDebug::Print( _L("Print : Test : %S"), &buf );
       
  3241             CleanupStack::PopAndDestroy(&buf);
       
  3242             }
       
  3243             break;
       
  3244         case TTestKeywords::EAllowNextResult:
       
  3245             {
       
  3246             AddTestCaseResultL( aItem );
       
  3247             }
       
  3248             break;
       
  3249         case TTestKeywords::EExpectedPanic:
       
  3250             {
       
  3251             AddTestCasePanicL( aItem );
       
  3252             }
       
  3253             break;            
       
  3254         case TTestKeywords::EWaitTestClass:
       
  3255             {
       
  3256             // Just stop script running, continue event is signaled 
       
  3257             // from test class with specified object name
       
  3258             TPtrC objectName;
       
  3259             // Get Object name
       
  3260             TInt ret = aItem->GetNextString( objectName );
       
  3261             if ( ret != KErrNone )
       
  3262                 {
       
  3263                 iRunErrorMessage = KErrMsgWaitTestClassNameNotDefined;
       
  3264                 User::Leave( ret );
       
  3265                 }
       
  3266             TTestObjectBase* obj = iTestScripter->GetObject ( objectName );
       
  3267             //User::LeaveIfNull( obj );
       
  3268             if( obj == NULL )
       
  3269                 {
       
  3270                 iRunErrorMessage.Format( KErrMsgWaitTestClassObjNotFound, &objectName );
       
  3271                 User::Leave( KErrGeneral );
       
  3272                 }
       
  3273             continueTask = obj->Wait();
       
  3274             
       
  3275             if( continueTask )
       
  3276                 {
       
  3277                 // If OOM testing is ongoing ignore result check(given by user)
       
  3278                 if( !iTestScripter->iOOMIgnoreFailure )
       
  3279                     {
       
  3280                     if( iTestCaseResults.Count() == 0 )
       
  3281                         {
       
  3282                         // KErrNone is the default result expected 
       
  3283                         // if nothing else is given 
       
  3284                         User::LeaveIfError( iTestCaseResults.Append( 
       
  3285                                                                 KErrNone ) );
       
  3286                         }
       
  3287                     
       
  3288                     if( iTestCaseResults.Find( obj->iAsyncResult ) < 0 ) 
       
  3289                         {
       
  3290                         __TRACE( KError, ( _L("Command for [%S] failed (%d)"), 
       
  3291                                 &objectName, obj->iAsyncResult ));
       
  3292                         iTestScripter->UpdateTestCaseResult(obj->iAsyncResult, _L("CTestRunner::ExecuteLineL: asynchronous method returned error"));
       
  3293                         // Stops execution from CTestRunner::RunError
       
  3294                         User::Leave( KErrGeneral );
       
  3295                         }
       
  3296                     }
       
  3297                 else
       
  3298                     {
       
  3299                     __TRACE( KMessage, ( 
       
  3300                         _L( "OOM test: 'oomignorefailure' is ON, test case result will reset" ) ) );
       
  3301                     }
       
  3302 
       
  3303                 iTestCaseResults.Reset();
       
  3304                 // Reset test case allow result to CTestModuleIf side too. This is
       
  3305                 // used in TAL-TA5L macro handling.
       
  3306                 User::LeaveIfError( 
       
  3307                     iTestScripter->TestModuleIf().ResetAllowResult() );
       
  3308                 }
       
  3309 
       
  3310             }
       
  3311             break;
       
  3312         case TTestKeywords::EPause:
       
  3313             {
       
  3314             // Maximum time for one RTimer::After request
       
  3315             TInt maximumTime = KMaxTInt / 1000;
       
  3316             // Set iRemainingTimeValue to zero
       
  3317             iRemainingTimeValue = 0;
       
  3318 
       
  3319             TInt timeout;
       
  3320             // Read valid results to timeout
       
  3321             if( aItem->GetNextInt( timeout ) != KErrNone )
       
  3322                 {
       
  3323                 __TRACE( KError, (_L("CTestRunner::ExecuteLineL: No timeout value given for pause")));
       
  3324                 iRunErrorMessage = KErrMsgPauseTimeoutNotDefined;
       
  3325                 User::Leave( KErrArgument );
       
  3326                 }
       
  3327 
       
  3328             // Test case file parsing was success
       
  3329 
       
  3330             __TRACE( KMessage, (_L("CTestRunner::ExecuteLineL: Pause for %d milliseconds"), timeout));
       
  3331 
       
  3332             if( timeout < 0 )
       
  3333                 {
       
  3334                 __TRACE( KError, (_L("CTestRunner::ExecuteLineL: Given pause value < 0")));
       
  3335                 iRunErrorMessage = KErrMsgPauseTimeoutNotPositive;
       
  3336                 User::Leave( KErrArgument );
       
  3337                 }
       
  3338             else
       
  3339                 {
       
  3340                 // Check is pause value suitable for RTimer::After
       
  3341                 if( timeout < maximumTime )
       
  3342                     {
       
  3343                     iPauseTimer.After( iStatus, ( timeout * 1000  ) );
       
  3344                     }
       
  3345                 else
       
  3346                     {
       
  3347                     // Given pause value after multiplication with 1000 is
       
  3348                     // larger than KMaxTInt, so we need to split it and 
       
  3349                     // re-request After with remaining value from RunL
       
  3350 
       
  3351                     iRemainingTimeValue =  timeout - maximumTime;
       
  3352                     iPauseTimer.After( iStatus, maximumTime * 1000 );
       
  3353                     }
       
  3354 
       
  3355                 SetActive();
       
  3356 
       
  3357                 // Stop execution after paused for given timeout
       
  3358                 continueTask = EFalse;
       
  3359                 }
       
  3360             }
       
  3361             break;
       
  3362         case TTestKeywords::EAllocate:
       
  3363             continueTask = ExecuteAllocateL( aItem );
       
  3364             break;
       
  3365         case TTestKeywords::EFree:
       
  3366             continueTask = ExecuteFreeL( aItem );
       
  3367             break;
       
  3368         case TTestKeywords::ERemote:
       
  3369             continueTask = ExecuteRemoteL( aItem );
       
  3370             break;            
       
  3371         case TTestKeywords::ELoop:
       
  3372             continueTask = ExecuteLoopL( aItem );
       
  3373             break;
       
  3374         case TTestKeywords::EEndLoop:
       
  3375             continueTask = ExecuteEndLoopL( aItem );
       
  3376             break;
       
  3377         case TTestKeywords::ETimeout:
       
  3378         case TTestKeywords::EPriority:
       
  3379             // not used here
       
  3380             break;
       
  3381         case TTestKeywords::EOOMIgnoreFailure:
       
  3382             {
       
  3383             OOMIgnoreFailureL( aItem );  // Handle parsing
       
  3384             break;
       
  3385             }
       
  3386         case TTestKeywords::EOOMHeapFailNext:
       
  3387             {
       
  3388             OOMHeapFailNextL( aItem );   // Handle parsing
       
  3389             break;
       
  3390             }
       
  3391         case TTestKeywords::EOOMHeapSetFail:
       
  3392             {
       
  3393             OOMHeapSetFailL( aItem );    // Handle parsing
       
  3394             break;
       
  3395             }
       
  3396        case TTestKeywords::EOOMHeapToNormal:
       
  3397             {
       
  3398             // Initialize all OOM related variables back to default.
       
  3399             OOMHeapToNormal();
       
  3400             __TRACE( KMessage, (
       
  3401                 _L( "'oomheaptonormal' called, OOM initialization or ending OOM test") ) );
       
  3402             break;
       
  3403             }
       
  3404        case TTestKeywords::ETestInterference:
       
  3405             {
       
  3406             TestInterferenceL( aItem );  // Handle parsing
       
  3407             break;
       
  3408             }
       
  3409        case TTestKeywords::EMeasurement:
       
  3410             {
       
  3411             MeasurementL( aItem );      // Handle parsing
       
  3412             break;
       
  3413             }
       
  3414        case TTestKeywords::EAllowErrorCodes:
       
  3415             {
       
  3416             // Check is KErrNone already appended to iTestCaseResults array.
       
  3417             if( iTestCaseResults.Find( KErrNone ) < 0 )
       
  3418                 {
       
  3419                 // 'allowerrorcodes' keyword sets KErrNone as a default
       
  3420                 User::LeaveIfError( iTestCaseResults.Append( KErrNone ) );
       
  3421                 // Set test case allow result to CTestModuleIf side too. This
       
  3422                 // is used in TAL-TA5L macro handling.
       
  3423                 User::LeaveIfError( 
       
  3424                     iTestScripter->TestModuleIf().SetAllowResult( KErrNone ) );
       
  3425                 }
       
  3426 
       
  3427             // Set user given specific error code to be allowed.
       
  3428             AddTestCaseResultL( aItem );
       
  3429             }
       
  3430             break;
       
  3431 
       
  3432        case TTestKeywords::EBringToForeground:
       
  3433            {
       
  3434            if ( iTestScripter->TestModuleIf().UITesting() == true )
       
  3435                {
       
  3436                iTestScripter->TestModuleIf().GetUiEnvProxy()->BringToForeground();
       
  3437                }
       
  3438            else
       
  3439                {
       
  3440                 __TRACE( KError, (_L("ExecuteLineL: Can't execute bringtoforeground in non s60 environment. Check if .cfg file name contains ui_ prefix and UITestingSupport= YES entry is defined in TestFrameworkd.ini")));
       
  3441                 iRunErrorMessage = KErrMsgBringToForegroundNotSupported;
       
  3442                 User::Leave( KErrNotSupported );               
       
  3443                }
       
  3444            }
       
  3445             break;
       
  3446        case TTestKeywords::ESendToBackground:
       
  3447            {
       
  3448            if ( iTestScripter->TestModuleIf().UITesting() == true )
       
  3449                {
       
  3450                iTestScripter->TestModuleIf().GetUiEnvProxy()->SendToBackground();
       
  3451                }
       
  3452            else
       
  3453                {
       
  3454                 __TRACE( KError, (_L("ExecuteLineL: Can't execute sendtobackground in non s60 environment. Check if .cfg file name contains ui_ prefix and UITestingSupport= YES entry is defined in TestFrameworkd.ini")));
       
  3455                 iRunErrorMessage = KErrMsgSendToBackgroundNotSupported;
       
  3456                 User::Leave( KErrNotSupported );               
       
  3457                }
       
  3458            }
       
  3459             break;
       
  3460        case TTestKeywords::EPressKey:
       
  3461            {
       
  3462            if ( iTestScripter->TestModuleIf().UITesting() == true )
       
  3463                {
       
  3464                continueTask = PressKeyL( aItem );
       
  3465                }
       
  3466            else
       
  3467                {
       
  3468                __TRACE( KError, (_L("ExecuteLineL: Can't execute presskey in non s60 environment. Check if .cfg file name contains ui_ prefix and UITestingSupport= YES entry is defined in TestFrameworkd.ini")));
       
  3469                iRunErrorMessage = KErrMsgPressKeyNotSupported;
       
  3470                User::Leave( KErrNotSupported );            
       
  3471                }    
       
  3472 
       
  3473            // Check if it was global or local presskey
       
  3474            if ( !continueTask )
       
  3475                {
       
  3476                // Stop execution after key is pressed and wait until it is handled
       
  3477                SetActive();
       
  3478                }           
       
  3479            }
       
  3480             break;
       
  3481        case TTestKeywords::ETypeText:
       
  3482            {
       
  3483            if ( iTestScripter->TestModuleIf().UITesting() == true )
       
  3484                {
       
  3485                continueTask = TypeTextL( aItem );
       
  3486                }
       
  3487            else
       
  3488                {
       
  3489                __TRACE( KError, (_L("ExecuteLineL: Can't execute typetext in non s60 environment. Check if .cfg file name contains ui_ prefix and UITestingSupport= YES entry is defined in TestFrameworkd.ini")));
       
  3490                iRunErrorMessage = KErrMsgTypeTextNotSupported;
       
  3491                User::Leave( KErrNotSupported );            
       
  3492                }
       
  3493 
       
  3494            // Check if it was global or local typetext
       
  3495            if ( !continueTask )
       
  3496                {
       
  3497                // Stop execution after key is pressed and wait until it is handled
       
  3498                SetActive();
       
  3499                }           
       
  3500            }
       
  3501             break;
       
  3502         case TTestKeywords::EVar:
       
  3503             {
       
  3504             TName name;
       
  3505             TName buf;
       
  3506             TPtrC tmp;
       
  3507             
       
  3508             //Get variable name
       
  3509             if(aItem->GetNextString(tmp) == KErrNone)
       
  3510                 {
       
  3511                 name.Copy(tmp);
       
  3512                 }
       
  3513             else
       
  3514                 {
       
  3515                 //Error when getting variable name
       
  3516                 __TRACE(KError, (_L("ExecuteLineL: Could not read variable name")));
       
  3517                 iRunErrorMessage = KErrVarNameError;
       
  3518                 User::Leave(KErrArgument);                
       
  3519                 }
       
  3520 
       
  3521             //Get value for variable
       
  3522             while(aItem->GetNextString(tmp) == KErrNone)
       
  3523                 {
       
  3524                 if(buf.Length() + tmp.Length() >= buf.MaxLength())
       
  3525                     {
       
  3526                     //Error when getting variable name
       
  3527                     __TRACE(KError, (_L("ExecuteLineL: Variable value too long")));
       
  3528                     iRunErrorMessage = KErrVarValueError;
       
  3529                     User::Leave(KErrArgument);                
       
  3530                     }
       
  3531                 buf.Append(tmp);
       
  3532                 buf.Append(_L(" "));
       
  3533                 }
       
  3534             //Remove last space
       
  3535             if(buf.Length() > 0)
       
  3536                 {
       
  3537                 buf.SetLength(buf.Length() - 1);
       
  3538                 }
       
  3539                 
       
  3540             //Store local variable
       
  3541             TInt count = iTestScripter->iDefinedLocal.Count();
       
  3542             TInt i;
       
  3543             for(i = 0; i < count; i++)
       
  3544                 {
       
  3545                 if(iTestScripter->iDefinedLocal[i]->Name() == name)
       
  3546                     {
       
  3547                     // Update existing
       
  3548                     iTestScripter->iDefinedLocal[i]->SetValueL(buf);
       
  3549                     __TRACE(KMessage, (_L("Update local variable [%S]: [%S]"), &name, &buf));
       
  3550                     break;
       
  3551                     }
       
  3552                 }
       
  3553             if(i == count)
       
  3554                 {
       
  3555                 // New define, store it
       
  3556                 CDefinedValue* define = CDefinedValue::NewL(name, buf);
       
  3557                 CleanupStack::PushL(define);
       
  3558                 User::LeaveIfError(iTestScripter->iDefinedLocal.Append(define));
       
  3559                 CleanupStack::Pop(define);
       
  3560                 __TRACE(KMessage, (_L("Add local variable [%S]: [%S]"), &name, &buf));
       
  3561                 }
       
  3562             }
       
  3563             break;
       
  3564         case TTestKeywords::ECallSub:
       
  3565             {
       
  3566             // Get sub name
       
  3567             TPtrC subName;
       
  3568             
       
  3569             //Get sub name
       
  3570             TInt err = aItem->GetNextString(subName);
       
  3571             if(err != KErrNone)
       
  3572                 {
       
  3573                 //Error when getting sub name
       
  3574                 __TRACE(KError, (_L("ExecuteLineL: Could not read sub name [%d]"), err));
       
  3575                 iRunErrorMessage = KErrSubNameError;
       
  3576                 User::Leave(KErrArgument);                
       
  3577                 }
       
  3578             
       
  3579             // Load section
       
  3580             CStifSectionParser* subSection = NULL;
       
  3581             TRAP(err, 
       
  3582                  subSection = iTestScripter->GetSubL(subName);
       
  3583                 );
       
  3584             if((err != KErrNone) || (!subSection))
       
  3585                 {
       
  3586                 //Error when getting sub name
       
  3587                 if(err == KErrNone)
       
  3588                     {
       
  3589                     err = KErrArgument;
       
  3590                     }
       
  3591                 __TRACE(KError, (_L("ExecuteLineL: Could not get section for sub [%d]"), err));
       
  3592                 iRunErrorMessage = KErrSubGetError;
       
  3593                 User::Leave(err);                
       
  3594                 }
       
  3595             
       
  3596             // Handle new section parser
       
  3597             CleanupStack::PushL(subSection);
       
  3598             iTestScripter->iParserStack.AppendL(subSection);
       
  3599             __TRACE(KMessage, (_L("ExecuteLineL: Section for sub [%S] appended to section stack"), &subName));
       
  3600             CleanupStack::Pop(subSection);
       
  3601             iTestScripter->iCurrentParser = subSection;
       
  3602             iTestScripter->iCurrentParserReadFirstLine = EFalse; //Change it to false, becaue subSection is a new parser and it has nothing read
       
  3603             }
       
  3604             break;
       
  3605         case TTestKeywords::ESetResultDescription:
       
  3606             {
       
  3607             __TRACE(KMessage, (_L("%S"), &aKeyword));
       
  3608             iTestScripter->TestModuleIf().Printf(KPrintPriLow, _L("Runner"), _L("%S"), &aKeyword);
       
  3609 
       
  3610             TName buf;
       
  3611             TPtrC tmp;
       
  3612 
       
  3613             while(aItem->GetNextString(tmp) == KErrNone)
       
  3614                 {
       
  3615                 if(buf.Length() + tmp.Length() >= buf.MaxLength())
       
  3616                     {
       
  3617                     break;
       
  3618                     }
       
  3619                 if(buf.Length() > 0)
       
  3620                     {
       
  3621                     buf.Append(_L(" "));
       
  3622                     }
       
  3623                 buf.Append(tmp);
       
  3624                 }
       
  3625             
       
  3626             iTestScripter->SetResultDescription(buf);
       
  3627             RDebug::Print( _L("SetDescription to [%S]"), &buf );
       
  3628             }
       
  3629             break;
       
  3630         case TTestKeywords::ESendPointerEvent:
       
  3631            {
       
  3632            if ( iTestScripter->TestModuleIf().UITesting() == true )
       
  3633                {
       
  3634                continueTask = SendPointerEventL( aItem );
       
  3635                }
       
  3636            else
       
  3637                {
       
  3638                __TRACE( KError, (_L("ExecuteLineL: Can't execute sendpointerevent in non s60 environment. Check if .cfg file name contains ui_ prefix and UITestingSupport= YES entry is defined in TestFrameworkd.ini")));
       
  3639                iRunErrorMessage = KErrMsgSendPointerEventNotSupported;
       
  3640                User::Leave( KErrNotSupported );            
       
  3641                }
       
  3642 
       
  3643            // Check if it was global or local sendpointerevent
       
  3644            if ( !continueTask )
       
  3645                {
       
  3646                // Stop execution after pointer event is send and wait until it is handled
       
  3647                SetActive();
       
  3648                }           
       
  3649            }
       
  3650            break;
       
  3651         case TTestKeywords::EUsing:
       
  3652              {
       
  3653              TInt err;
       
  3654              TPtrC dll;
       
  3655              err=aItem->GetNextString(dll);
       
  3656              err=iLibrary.Load(dll);
       
  3657            
       
  3658              User::LeaveIfError(err);
       
  3659              TLibraryFunction LibEntryL=iLibrary.Lookup(1);
       
  3660              iPlugins.Append((CStfTestLibPlugin*)LibEntryL());
       
  3661              TPtrC temp;
       
  3662              err=aItem->GetNextString(temp);
       
  3663              HBufC* alias=HBufC::NewL(temp.Length());
       
  3664              alias->Des().Copy(temp);
       
  3665              iPluginnames.Append(alias);
       
  3666            
       
  3667              break;
       
  3668              }
       
  3669         default:
       
  3670             {
       
  3671             if(ExecuteLibL(aKeyword, aItem))
       
  3672                 {
       
  3673                 
       
  3674                 }
       
  3675             else
       
  3676                 {
       
  3677             continueTask = ExecuteCommandL( aKeyword, aItem );
       
  3678                 }
       
  3679             }
       
  3680             break;
       
  3681         }
       
  3682 
       
  3683     __TRACE( KMessage, (_L("ExecuteLineL: TestCase line executed")));
       
  3684     CleanupStack::PopAndDestroy(&buf);
       
  3685     return continueTask;
       
  3686     }
       
  3687 
       
  3688 /*
       
  3689 -------------------------------------------------------------------------------
       
  3690 
       
  3691      Class: CTestRunner
       
  3692 
       
  3693      Method: ExecuteRunL
       
  3694 
       
  3695      Description: Executes run line
       
  3696   
       
  3697      Parameters:    CStifItemParser* aItem: in: script line
       
  3698      
       
  3699      Return Values: ETrue: continue script file execution
       
  3700                     EFalse: stop script file execution
       
  3701 
       
  3702      Errors/Exceptions: Leaves on error situations.
       
  3703 
       
  3704      Status: Proposal
       
  3705     
       
  3706 -------------------------------------------------------------------------------
       
  3707 */
       
  3708 TBool CTestRunner::ExecuteRunL( CStifItemParser* aItem )
       
  3709     {
       
  3710     _LIT( KErrMsgCaseRunError, "Run : %S[case=%d] run error" );
       
  3711     __TRACE( KMessage, (_L("Run")));
       
  3712     iTestScripter->TestModuleIf().Printf( KPrintPriExec, KExecute, _L("Run"));
       
  3713     
       
  3714     CStartInfo* startInfo = CStartInfo::NewL();
       
  3715     CleanupStack::PushL( startInfo );
       
  3716 
       
  3717     ParseRunParamsL( aItem, *startInfo );
       
  3718              
       
  3719     // Start new case with configurations parsed above                
       
  3720     
       
  3721     iRunErrorMessage.Format( KErrMsgCaseRunError, &startInfo->GetModuleName(), startInfo->GetTestCaseNumber() );
       
  3722     
       
  3723     CSubTestCaseRunner* subTestCaseRunner = CLocalSubTestCaseRunner::NewLC( this );
       
  3724 
       
  3725     __TRACE( KMessage, ( _L( "Executing sub test case: module=%S cfg=%S tcnum=%d id=%S" ),
       
  3726          &startInfo->GetModuleName(), &startInfo->GetConfig(), 
       
  3727          startInfo->GetTestCaseNumber(), &startInfo->GetTestId()) );
       
  3728 
       
  3729     RDebug::Print( _L( "Executing sub test case: module=%S cfg=%S tcnum=%d id=%S" ),
       
  3730             &startInfo->GetModuleName(), &startInfo->GetConfig(), 
       
  3731             startInfo->GetTestCaseNumber(), &startInfo->GetTestId() );
       
  3732     
       
  3733     subTestCaseRunner->RunSubTestCaseL( *startInfo );
       
  3734     iSubTestCases.AppendL( subTestCaseRunner );
       
  3735     if ( iLoopHelper->LoopInProgress() )
       
  3736         {
       
  3737         iLoopHelper->RegisterInLoopSubTestCaseL( subTestCaseRunner );
       
  3738         }
       
  3739     
       
  3740     CleanupStack::Pop( subTestCaseRunner );
       
  3741     
       
  3742     iRunErrorMessage = KNullDesC;
       
  3743     
       
  3744     CleanupStack::PopAndDestroy( startInfo );
       
  3745         
       
  3746     return ETrue;
       
  3747     }
       
  3748 
       
  3749 /*
       
  3750 -------------------------------------------------------------------------------
       
  3751 
       
  3752      Class: CTestRunner
       
  3753 
       
  3754      Method: ExecuteCompleteL
       
  3755 
       
  3756      Description: Executes complete line
       
  3757   
       
  3758      Parameters:    CStifItemParser* aItem: in: script line
       
  3759      
       
  3760      Return Values: ETrue: continue script file execution
       
  3761                     EFalse: stop script file execution
       
  3762 
       
  3763      Errors/Exceptions: Leaves on error situations.
       
  3764 
       
  3765      Status: Proposal
       
  3766     
       
  3767 -------------------------------------------------------------------------------
       
  3768 */
       
  3769 TBool CTestRunner::ExecuteCompleteL( CStifItemParser* aItem )
       
  3770     {
       
  3771     _LIT( KErrMsgTestIdNotDefined, "%S : testid is not defined" );
       
  3772     TPtrC testId;
       
  3773 
       
  3774     TInt ret = KErrNone;
       
  3775 
       
  3776     TPtrC keywordStr = TTestKeywords::Keyword( TTestKeywords::EComplete );
       
  3777 
       
  3778     // Parse testid
       
  3779     ret = aItem->GetNextString( testId );
       
  3780     if( ret != KErrNone )
       
  3781         {
       
  3782         iRunErrorMessage.Format( KErrMsgTestIdNotDefined, &keywordStr );
       
  3783         User::Leave( ret );
       
  3784         }
       
  3785 
       
  3786     for ( TInt i = 0; i < iSubTestCases.Count(); i++ )
       
  3787         {
       
  3788         if ( iSubTestCases[ i ]->GetStartInfo()->GetTestId() == testId )
       
  3789             {
       
  3790             delete iTestIdForComplete;
       
  3791             iTestIdForComplete = testId.AllocL();
       
  3792             iInternalStateForSubTestCases = EISWaitingForComplete;
       
  3793             return EFalse;
       
  3794             }
       
  3795         }   
       
  3796     
       
  3797     return ETrue;
       
  3798     }
       
  3799 
       
  3800 
       
  3801 /*
       
  3802 -------------------------------------------------------------------------------
       
  3803 
       
  3804      Class: CTestRunner
       
  3805 
       
  3806      Method: ParseRunParamsL
       
  3807 
       
  3808      Description: Parses run parameters
       
  3809   
       
  3810      Parameters:    CStifItemParser* aItem: in: script line
       
  3811                     CStartInfo& aStartInfo: out: Parsed information
       
  3812      
       
  3813      Return Values: None
       
  3814      
       
  3815      Errors/Exceptions: Leaves on error situations.
       
  3816 
       
  3817      Status: Draft
       
  3818     
       
  3819 -------------------------------------------------------------------------------
       
  3820 */
       
  3821 void CTestRunner::ParseRunParamsL( CStifItemParser* aItem,
       
  3822                                     CStartInfo& aStartInfo )
       
  3823     {
       
  3824     _LIT( KErrMsgRunTestmoduleNameNotDefined, "Run : Testmodule name is not defined " );
       
  3825     _LIT( KErrMsgRunCfgFileNotDefined, "Run : Testmodule configuration file is not defined" );
       
  3826     _LIT( KErrMsgRunTestcaseNumberNotDefined, "Run : Testcase number is not defined or has invalid value" );
       
  3827     _LIT( KErrMsgRunCfgFileNameToLong, "Run : TestScripter test case file(config)'s name is too long. Current length[%d], allowed max length[%d]. Cannot continue" );
       
  3828     _LIT( KErrMsgRunInvalidExpectValue, "Run : Invalid expected result value" );
       
  3829     _LIT( KErrMsgRunUnknownOrIllegalCategory, "Run : Unknown or illegal result category" );
       
  3830     _LIT( KErrMsgRunInvalidTimeoutValue, "Run: Invalid testcase timeout value" );
       
  3831     _LIT( KErrMsgRunUnknowOrIllegalKeyword, "Run: Unknown or illegal keyword %S" );
       
  3832     
       
  3833     TPtrC tmp;
       
  3834     TInt ret = KErrNone;
       
  3835 
       
  3836     // Get mandatory run arguments
       
  3837     // Testmodule name
       
  3838     ret = aItem->GetNextString( tmp );
       
  3839     if ( ret != KErrNone )
       
  3840         {
       
  3841         iRunErrorMessage = KErrMsgRunTestmoduleNameNotDefined;
       
  3842         User::Leave( ret );
       
  3843         }
       
  3844     
       
  3845     aStartInfo.SetModuleNameL( tmp );
       
  3846     __TRACE( KMessage, (_L("module: %S"), &aStartInfo.GetModuleName() ));
       
  3847     
       
  3848     // Configuration file
       
  3849     ret = aItem->GetNextString( tmp );
       
  3850     if ( ret != KErrNone )
       
  3851         {
       
  3852         iRunErrorMessage = KErrMsgRunCfgFileNotDefined;
       
  3853         User::Leave( ret );
       
  3854         }
       
  3855     
       
  3856     TFileName cfgFileName( tmp );
       
  3857     TStifUtil::CorrectFilePathL( cfgFileName );    
       
  3858     aStartInfo.SetConfigL( cfgFileName );
       
  3859     
       
  3860     __TRACE( KMessage, (_L("config: %S"), &aStartInfo.GetConfig() ));
       
  3861 
       
  3862     // Check is TestScripter
       
  3863     if( aStartInfo.GetModuleName().Find( KTestScripterName ) != KErrNotFound )
       
  3864         {
       
  3865         // TestScripter name is format: 'testscripter_testcasefilename'
       
  3866 
       
  3867         TParse parse;
       
  3868         parse.Set( aStartInfo.GetConfig(), NULL, NULL );
       
  3869 
       
  3870         // Maximum length of TestScripter's name(Max limitation from
       
  3871         // CTestModuleController creation)
       
  3872         TInt maximumLength = KMaxName - ( KTestScripterNameLength + 1 );
       
  3873 
       
  3874         TFileName testScripterAndTestCaseFile; // InitL() takes TFileName
       
  3875         testScripterAndTestCaseFile.Copy( KTestScripterName );
       
  3876         testScripterAndTestCaseFile.Append( _L( "_" ) );
       
  3877         if( parse.Name().Length() < maximumLength )
       
  3878             {
       
  3879             testScripterAndTestCaseFile.Append( parse.Name() );
       
  3880             }
       
  3881         else
       
  3882             {
       
  3883             __TRACE( KInit, ( CStifLogger::ERed,
       
  3884                 _L( "TestScripter test case file(config)'s name is too long. Current length[%d], allowed max length[%d]. Cannot continue" ),
       
  3885                 parse.Name().Length(), maximumLength ) );
       
  3886             iRunErrorMessage.Format( KErrMsgRunCfgFileNameToLong, parse.Name().Length(), maximumLength );
       
  3887             User::Leave( KErrArgument );
       
  3888             }
       
  3889         aStartInfo.SetModuleNameL( testScripterAndTestCaseFile );
       
  3890         }
       
  3891 
       
  3892     // Testcase number
       
  3893     TInt testCaseNumber;
       
  3894     ret = aItem->GetInt( tmp, testCaseNumber );
       
  3895     if ( ret != KErrNone )
       
  3896         {
       
  3897         iRunErrorMessage = KErrMsgRunTestcaseNumberNotDefined;
       
  3898         User::Leave( ret );
       
  3899         }
       
  3900     aStartInfo.SetTestCaseNumber( testCaseNumber );
       
  3901     
       
  3902     __TRACE( KMessage, (_L("testcasenum: %d"), testCaseNumber ) );
       
  3903      
       
  3904     // Set mode of item parser to be able to read titles with spaces inside
       
  3905     aItem->SetParsingType(CStifItemParser::EQuoteStyleParsing);
       
  3906 
       
  3907     // Get optional run arguments
       
  3908     while( aItem->GetNextString( tmp ) == KErrNone )
       
  3909         {
       
  3910         TPtrC val;   
       
  3911         TPtrC arg;
       
  3912         ParseOptArgL( tmp, arg, val );
       
  3913         CheckDefined( val );
       
  3914               
       
  3915         // Parse optional argument
       
  3916         switch( TTestKeywords::Parse( arg, TTestKeywords::RunOptArg ) )
       
  3917             {
       
  3918             case TTestKeywords::EExpect:
       
  3919                 {
       
  3920                 TLex ptr( val );
       
  3921                 TInt expectedResult;
       
  3922                 ret = ptr.Val( expectedResult );
       
  3923                 if ( ret != KErrNone )
       
  3924                     {
       
  3925                     iRunErrorMessage = KErrMsgRunInvalidExpectValue;
       
  3926                     User::Leave( ret );
       
  3927                     }
       
  3928                 aStartInfo.SetExpectedResult( expectedResult );
       
  3929                 __TRACE( KMessage, (_L("expect=%d"), expectedResult ));
       
  3930                 }
       
  3931                 break;
       
  3932             case TTestKeywords::ETestid:
       
  3933                 {
       
  3934                 aStartInfo.SetTestIdL( val );
       
  3935                 __TRACE( KMessage, (_L("TestId=%S"), &val));
       
  3936                 }
       
  3937                 break;
       
  3938             case TTestKeywords::EIni:
       
  3939                 {
       
  3940                 __TRACE( KMessage, (_L("ini=%S"), &val));
       
  3941                 TFileName iniFileName( val );
       
  3942                 TStifUtil::CorrectFilePathL( iniFileName );
       
  3943                 aStartInfo.SetIniFileL( iniFileName );
       
  3944                 }
       
  3945                 break;
       
  3946             case TTestKeywords::ECategory:
       
  3947                 {
       
  3948                 __TRACE( KMessage, (_L("category=%S"), &val));
       
  3949                 aStartInfo.SetExpectedResultCategory( TTestKeywords::GetResultCategory( val ) );
       
  3950                 if( aStartInfo.GetExpectedResultCategory() == TFullTestResult::ECaseOngoing )
       
  3951                     {
       
  3952                     __TRACE( KError, (_L("Unknown or illegal result category")));
       
  3953                     //Unknown or illegal category
       
  3954                     iRunErrorMessage = KErrMsgRunUnknownOrIllegalCategory;
       
  3955                     User::Leave( KErrGeneral );
       
  3956                     }
       
  3957                 }
       
  3958                 break;
       
  3959             case TTestKeywords::ECaseTimeout:
       
  3960                 {
       
  3961                 TInt timeout;
       
  3962                 TLex ptr( val );
       
  3963                 ret = ptr.Val( timeout );
       
  3964                 if ( ret != KErrNone )
       
  3965                     {
       
  3966                     iRunErrorMessage = KErrMsgRunInvalidTimeoutValue;
       
  3967                     User::Leave( ret );
       
  3968                     }
       
  3969                 aStartInfo.SetTimeout( timeout );
       
  3970                 __TRACE( KMessage, (_L("timeout=%d"), timeout ) );
       
  3971                 }
       
  3972                 break;
       
  3973             case TTestKeywords::ECaseTitle:
       
  3974                 {
       
  3975                 __TRACE( KMessage, (_L("case title=%S"), &val));
       
  3976                 aStartInfo.SetTitleL(val);
       
  3977                 break;
       
  3978                 }
       
  3979             default:
       
  3980                 {
       
  3981                 __TRACE( KError, (_L("Unknown or illegal keyword")));
       
  3982                 //Unknown or illegal keyword
       
  3983                 iRunErrorMessage.Format( KErrMsgRunUnknowOrIllegalKeyword, &arg );
       
  3984                 User::Leave( KErrGeneral );
       
  3985                 }
       
  3986             }
       
  3987         }             
       
  3988     } 
       
  3989 
       
  3990 /*
       
  3991 -------------------------------------------------------------------------------
       
  3992 
       
  3993      Class: CTestRunner
       
  3994 
       
  3995      Method: ParseOptArgL
       
  3996 
       
  3997      Description: Parses optional argument 
       
  3998   
       
  3999      Parameters: const TDesC& aOptArg: in: 
       
  4000                     argument-value pair (format arg=value)
       
  4001                  TPtrC& aArg: out: parsed argument  
       
  4002                  TPtrC& aVal: out: parsed value
       
  4003      
       
  4004      Return Values: None
       
  4005 
       
  4006      Errors/Exceptions: Leaves if parsing fails.
       
  4007 
       
  4008      Status: Approved
       
  4009     
       
  4010 -------------------------------------------------------------------------------
       
  4011 */
       
  4012 void CTestRunner::ParseOptArgL( const TDesC& aOptArg, TPtrC& aArg, TPtrC& aVal)
       
  4013     { 
       
  4014     _LIT( KErrMsgUnknownOrIllegalKeyword, "Unknown or illegal argument %S" );
       
  4015     _LIT( KErrMsgValueNotDefined, "Value of optional argument %S is not defined" );
       
  4016     TInt length = aOptArg.Length();
       
  4017     for( TInt i=0; i < length; i++) 
       
  4018         {
       
  4019         // find the '=' sign 
       
  4020         if( aOptArg[i] == '=' )
       
  4021             {
       
  4022             if( i+1 >= length )
       
  4023                 {
       
  4024                 __TRACE( KError, 
       
  4025                     (_L("Illegal optional argument(%S), no value"), 
       
  4026                     &aOptArg ));    
       
  4027                 TPtrC tmp = aOptArg.Left( i );
       
  4028                 iRunErrorMessage.Format( KErrMsgValueNotDefined, &tmp );
       
  4029                 User::Leave( KErrArgument );
       
  4030                 }
       
  4031             aArg.Set( aOptArg.Left( i ) );
       
  4032             aVal.Set( aOptArg.Mid( i+1 ) );
       
  4033             __TRACE( KMessage, (  _L( "arg '%S', val '%S'" ),
       
  4034                 &aArg, &aVal ));        
       
  4035             return;
       
  4036             }
       
  4037         }
       
  4038     __TRACE( KError, (_L("Illegal optional argument(%S)"), &aOptArg ));    
       
  4039     iRunErrorMessage.Format( KErrMsgUnknownOrIllegalKeyword, &aOptArg );
       
  4040     User::Leave( KErrArgument );
       
  4041     
       
  4042     }
       
  4043 
       
  4044 TBool CompareTDesC(const TDesC8& aLeft,const TDesC8& aRight)
       
  4045 {
       
  4046     return aLeft.Compare(aRight) == 0 ? ETrue : EFalse;
       
  4047     
       
  4048 }
       
  4049 
       
  4050 
       
  4051 
       
  4052 /**
       
  4053 * Executes method call to object script line.
       
  4054 */
       
  4055 TBool CTestRunner::ExecuteLibL( TDesC& lib,
       
  4056                       CStifItemParser* aItem )
       
  4057 {
       
  4058     TBool result=EFalse;
       
  4059     TIdentityRelation<TDesC8 > relation(CompareTDesC);
       
  4060     TInt count=iPluginnames.Count();
       
  4061     TInt index;
       
  4062     for( index=0;index<count;index++)
       
  4063         {
       
  4064         HBufC* temp=iPluginnames[index];
       
  4065         TPtr tempptr=temp->Des();
       
  4066         if(tempptr==lib)
       
  4067             {
       
  4068             TPtrC partcommand;
       
  4069             TBuf<300> commandline;
       
  4070             TBuf<100> command;
       
  4071             result=ETrue;
       
  4072             TInt i=0;
       
  4073             while(aItem->GetNextString(partcommand)==KErrNone)
       
  4074                 {
       
  4075                 if(i==0)
       
  4076                     {
       
  4077                     command.Append(partcommand);
       
  4078                     }
       
  4079                 commandline.Append(partcommand);
       
  4080                 commandline.Append(_L(" "));
       
  4081                 i++;
       
  4082                 }
       
  4083             commandline.TrimAll();
       
  4084             if(iPlugins[index]->IsCommandSupported(command))
       
  4085                 
       
  4086                 {
       
  4087                 iPlugins[index]->ExecuteCommandL(commandline);
       
  4088                 }
       
  4089             break;
       
  4090             }
       
  4091         }
       
  4092     return result;
       
  4093 }
       
  4094 /*
       
  4095 -------------------------------------------------------------------------------
       
  4096 
       
  4097      Class: CTestRunner
       
  4098 
       
  4099      Method: PressKeyL
       
  4100 
       
  4101      Description: Send key press event to AppUi
       
  4102   
       
  4103      Parameters:    CStifItemParser* aItem: in: script line
       
  4104      
       
  4105      Return Values: None
       
  4106 
       
  4107      Errors/Exceptions: Leaves on error situations.
       
  4108 
       
  4109      Status: Draft
       
  4110     
       
  4111 -------------------------------------------------------------------------------
       
  4112 */
       
  4113 TBool CTestRunner::PressKeyL( CStifItemParser* aItem )
       
  4114     {
       
  4115     _LIT( KErrMsgSendKeyEventInvalidParameterValue, "PressKey: Invalid parameter %s value " );
       
  4116     _LIT( KErrMsgSendKeyEventInvalidParameter, "PressKey: Invalid parameter %s" );    
       
  4117     
       
  4118     _LIT( KKeyCodeParameter, "keycode=" );
       
  4119     _LIT( KKeyScanCodeParameter, "keyscancode=" );
       
  4120     _LIT( KModifierParameter, "modifier=" );
       
  4121     _LIT( KRepeatsParameter, "repeats=" );
       
  4122     
       
  4123     _LIT( KModeGlobal, "global" );
       
  4124     _LIT( KModeLocal, "local" );
       
  4125     
       
  4126     TBool globalMode = EFalse;
       
  4127     TUint keyCode = 0; 
       
  4128     TInt keyScanCode = 0; 
       
  4129     TUint keyModifiers = 0; 
       
  4130     TInt keyRepeats = 0;
       
  4131         
       
  4132     TPtrC parameter;
       
  4133         
       
  4134     CUiEnvProxy* uiEnvProxy = iTestScripter->TestModuleIf().GetUiEnvProxy();
       
  4135     
       
  4136     while( aItem->GetNextString( parameter ) == KErrNone )
       
  4137         {
       
  4138         if ( parameter.Find( KKeyCodeParameter ) == 0 )
       
  4139             {
       
  4140             TPtrC parameterValue = parameter.Right( parameter.Length() - KKeyCodeParameter().Length() );
       
  4141             TLex parameterValueParser( parameterValue );
       
  4142             if ( parameterValueParser.Val( keyCode ) != KErrNone )
       
  4143                 {
       
  4144                     if ( uiEnvProxy->ParseKeyCode( parameterValue, keyCode ) != KErrNone )
       
  4145                         {
       
  4146                         __TRACE( KError, (_L("SendKeyEvent: Invalid parameter value")));
       
  4147                         TBuf<128> errMsg;
       
  4148                         errMsg.Format( KErrMsgSendKeyEventInvalidParameterValue, &KKeyCodeParameter() );
       
  4149                         iRunErrorMessage = errMsg;
       
  4150                         User::Leave( KErrArgument );                            
       
  4151                         }
       
  4152                 }
       
  4153             }
       
  4154         else if ( parameter.Find( KKeyScanCodeParameter ) == 0 )
       
  4155             {
       
  4156             TPtrC parameterValue = parameter.Right( parameter.Length() - KKeyScanCodeParameter().Length() );
       
  4157             TLex parameterValueParser( parameterValue );
       
  4158             if ( parameterValueParser.Val( keyScanCode ) != KErrNone )
       
  4159                 {
       
  4160                 if ( uiEnvProxy->ParseKeyScanCode( parameterValue, keyScanCode ) != KErrNone )
       
  4161                     {
       
  4162                     __TRACE( KError, (_L("SendKeyEvent: Invalid parameter value")));
       
  4163                     TBuf<128> errMsg;
       
  4164                     errMsg.Format( KErrMsgSendKeyEventInvalidParameterValue, &KKeyCodeParameter() );
       
  4165                     iRunErrorMessage = errMsg;
       
  4166                     User::Leave( KErrArgument );                            
       
  4167                     }
       
  4168                 }
       
  4169             }
       
  4170         else if ( parameter.Find( KModifierParameter ) == 0 )
       
  4171             {
       
  4172             TPtrC parameterValue = parameter.Right( parameter.Length() - KModifierParameter().Length() );
       
  4173             TLex parameterValueParser( parameterValue );
       
  4174             if ( parameterValueParser.Val( keyModifiers ) != KErrNone )
       
  4175                 {
       
  4176                 if ( uiEnvProxy->ParseModifier( parameterValue, keyModifiers ) != KErrNone )
       
  4177                     {
       
  4178                     __TRACE( KError, (_L("SendKeyEvent: Invalid parameter value")));
       
  4179                     TBuf<128> errMsg;
       
  4180                     errMsg.Format( KErrMsgSendKeyEventInvalidParameterValue, &KModifierParameter() );
       
  4181                     iRunErrorMessage = errMsg;
       
  4182                     User::Leave( KErrArgument );                            
       
  4183                     }
       
  4184                 }
       
  4185             }
       
  4186         else if ( parameter.Find( KRepeatsParameter ) == 0 )
       
  4187             {
       
  4188             TPtrC parameterValue = parameter.Right( parameter.Length() - KRepeatsParameter().Length() );
       
  4189             TLex parameterValueParser( parameterValue );
       
  4190             if ( parameterValueParser.Val( keyRepeats ) != KErrNone )
       
  4191                 {
       
  4192                 __TRACE( KError, (_L("SendKeyEvent: Invalid parameter value")));
       
  4193                 TBuf<128> errMsg;
       
  4194                 errMsg.Format( KErrMsgSendKeyEventInvalidParameterValue, &KRepeatsParameter() );
       
  4195                 iRunErrorMessage = errMsg;
       
  4196                 User::Leave( KErrArgument );                            
       
  4197                 }
       
  4198             }
       
  4199         else if ( parameter == KModeGlobal )
       
  4200             {
       
  4201             globalMode = ETrue;
       
  4202             }
       
  4203         else if ( parameter == KModeLocal )
       
  4204             {
       
  4205             globalMode = EFalse;
       
  4206             }
       
  4207         else if ( uiEnvProxy->ParseKeyCode( parameter, keyCode ) == KErrNone ) 
       
  4208             {           
       
  4209             }           
       
  4210         else if ( parameter.Length() == 1 )
       
  4211             {
       
  4212             keyCode = parameter[ 0 ];
       
  4213             }
       
  4214         else
       
  4215             {
       
  4216             __TRACE( KError, (_L("PressKey: Invalid parameter")));
       
  4217             TBuf<128> errMsg;
       
  4218             errMsg.Format( KErrMsgSendKeyEventInvalidParameter, &parameter );
       
  4219             iRunErrorMessage = errMsg;
       
  4220             User::Leave( KErrArgument );            
       
  4221             }
       
  4222         }
       
  4223     
       
  4224     if ( globalMode )
       
  4225         {
       
  4226         uiEnvProxy->PressKeyL( keyCode, keyScanCode, keyModifiers, keyRepeats );            
       
  4227         }
       
  4228     else
       
  4229         {
       
  4230         uiEnvProxy->PressKeyL( &iStatus, keyCode, keyScanCode, keyModifiers, keyRepeats );
       
  4231         }
       
  4232         
       
  4233     return globalMode;
       
  4234     }
       
  4235 
       
  4236 /*
       
  4237 -------------------------------------------------------------------------------
       
  4238 
       
  4239      Class: CTestRunner
       
  4240 
       
  4241      Method: TypeTextL
       
  4242 
       
  4243      Description: Sends text to AppUi
       
  4244   
       
  4245      Parameters:    CStifItemParser* aItem: in: script line
       
  4246      
       
  4247      Return Values: None
       
  4248 
       
  4249      Errors/Exceptions: Leaves on error situations.
       
  4250 
       
  4251      Status: Draft
       
  4252     
       
  4253 -------------------------------------------------------------------------------
       
  4254 */
       
  4255 TBool CTestRunner::TypeTextL( CStifItemParser* aItem )
       
  4256     {
       
  4257     _LIT( KErrMsgTypeTextInvalidParameter, "TypeText: Invalid parameter %S" );
       
  4258     _LIT( KErrMsgTypeTextNotEnoughParameters, "TypeText: Not enough parameters" );
       
  4259     
       
  4260     TBool globalMode = EFalse;
       
  4261     
       
  4262     TPtrC command;
       
  4263     TPtrC text;
       
  4264     aItem->SetParsingType( CStifItemParser::EQuoteStyleParsing );
       
  4265     
       
  4266     // Read first parameter
       
  4267     TInt ret = aItem->GetNextString( command );
       
  4268     
       
  4269     if ( ret != KErrNone )
       
  4270         {
       
  4271         __TRACE( KError, (_L("TypeText: Not enough parameters")));
       
  4272         iRunErrorMessage = KErrMsgTypeTextNotEnoughParameters;
       
  4273         User::Leave( ret );
       
  4274         }
       
  4275     
       
  4276     // Read second parameter
       
  4277     ret = aItem->GetNextString( text );
       
  4278     
       
  4279     // Check if second can be read. if yes then check if first parameters is
       
  4280     // 'global' parameter
       
  4281     if ( ret != KErrNone )
       
  4282         {
       
  4283         // normal type text
       
  4284         text.Set( command );
       
  4285         iTestScripter->TestModuleIf().GetUiEnvProxy()->TypeTextL( &iStatus, text );
       
  4286         globalMode = EFalse;
       
  4287         }
       
  4288     else if ( command == _L("global") )
       
  4289         {
       
  4290         iTestScripter->TestModuleIf().GetUiEnvProxy()->TypeTextL( text );
       
  4291         globalMode = ETrue;
       
  4292         }
       
  4293     else
       
  4294         {
       
  4295         __TRACE( KError, (_L("TypeText: Invalid parameter")));
       
  4296         TBuf<128> errMsg;
       
  4297         errMsg.Format( KErrMsgTypeTextInvalidParameter, &command );
       
  4298         iRunErrorMessage = errMsg;
       
  4299         User::Leave( KErrNotSupported );
       
  4300         }
       
  4301         
       
  4302     return globalMode;
       
  4303     }
       
  4304 
       
  4305 /*
       
  4306 -------------------------------------------------------------------------------
       
  4307 
       
  4308      Class: CTestRunner
       
  4309 
       
  4310      Method: SendPointerEventL
       
  4311 
       
  4312      Description: Send key press event to AppUi
       
  4313   
       
  4314      Parameters:    CStifItemParser* aItem: in: script line
       
  4315      
       
  4316      Return Values: None
       
  4317 
       
  4318      Errors/Exceptions: Leaves on error situations.
       
  4319 
       
  4320      Status: Draft
       
  4321     
       
  4322 -------------------------------------------------------------------------------
       
  4323 */
       
  4324 TBool CTestRunner::SendPointerEventL( CStifItemParser* aItem )
       
  4325     {
       
  4326     // Error messages
       
  4327     _LIT( KErrMsgNotEnoughParameters, "SendPointerEvent: Not enough parameters" );
       
  4328     _LIT( KErrMsgPointerEventTypeNotDefined, "SendPointerEvent: Pointer event type not defined" );
       
  4329     _LIT( KErrMsgInvalidUnknownPointerEventType, "SendPointerEvent: Invalid/Unknown pointer event type %S" );
       
  4330     _LIT( KErrMsgPositionXNotDefined, "SendPointerEvent: x co-ordinate is not defined" );
       
  4331     _LIT( KErrMsgPositionYNotDefined, "SendPointerEvent: y co-ordinate is not defined" );
       
  4332     _LIT( KErrMsgPositionXInvalidValue, "SendPointerEvent: Invalid value of x co-ordinate" );
       
  4333     _LIT( KErrMsgPositionYInvalidValue, "SendPointerEvent: Invalid value of y co-ordinate" );
       
  4334 
       
  4335     // Parameters keywords
       
  4336     _LIT( KModeGlobal, "global" );
       
  4337     _LIT( KModeLocal, "local" );
       
  4338     
       
  4339     TBool globalMode = EFalse;
       
  4340     TUint eventType = 0; 
       
  4341     TPoint position( 0, 0 );
       
  4342     TPoint parentPosition( 0, 0 );
       
  4343         
       
  4344     TPtrC parameter;
       
  4345 
       
  4346     CUiEnvProxy* uiEnvProxy = iTestScripter->TestModuleIf().GetUiEnvProxy();
       
  4347 
       
  4348     // Get first parameter
       
  4349     if ( aItem->GetNextString( parameter ) != KErrNone )
       
  4350         {
       
  4351         __TRACE( KError, (_L("SendPointerEvent: Not enough parameters")));
       
  4352         iRunErrorMessage = KErrMsgNotEnoughParameters;
       
  4353         User::Leave( KErrArgument );            
       
  4354         }
       
  4355     else
       
  4356         {
       
  4357         TBool modeSelected = EFalse;
       
  4358         // Check if global/local mode is defined
       
  4359         if ( parameter == KModeLocal )
       
  4360             {
       
  4361             globalMode = false;
       
  4362             modeSelected = ETrue;
       
  4363             }
       
  4364         else if ( parameter == KModeGlobal )
       
  4365             {
       
  4366             globalMode = true;
       
  4367             modeSelected = ETrue;
       
  4368             }
       
  4369         
       
  4370         if ( modeSelected )
       
  4371             {
       
  4372             // First parameter was mode so we need get next parameter which should 
       
  4373             // contain event type
       
  4374             if ( aItem->GetNextString( parameter ) != KErrNone )
       
  4375                 {
       
  4376                 __TRACE( KError, (_L("SendPointerEvent: Pointer event type not defined")));
       
  4377                 iRunErrorMessage = KErrMsgPointerEventTypeNotDefined;
       
  4378                 User::Leave( KErrArgument );            
       
  4379                 }
       
  4380             }
       
  4381         }
       
  4382     
       
  4383     // Parse event type
       
  4384     if ( uiEnvProxy->ParsePointerEventType( parameter, eventType ) != KErrNone )
       
  4385         {
       
  4386         __TRACE( KError, (_L("PressKey: Invalid/Unknown pointer event type %S"), &parameter ));
       
  4387         iRunErrorMessage.Format( KErrMsgInvalidUnknownPointerEventType, &parameter );
       
  4388         User::Leave( KErrArgument );            
       
  4389         }
       
  4390     
       
  4391     if ( aItem->GetNextString( parameter ) != KErrNone )
       
  4392         {
       
  4393         __TRACE( KError, (_L("SendPointerEvent: x co-ordinate is not defined")));
       
  4394         iRunErrorMessage = KErrMsgPositionXNotDefined;
       
  4395         User::Leave( KErrArgument );            
       
  4396         }
       
  4397 
       
  4398     TLex parameterParser( parameter );
       
  4399     if ( parameterParser.Val( position.iX ) != KErrNone )
       
  4400         {
       
  4401         __TRACE( KError, (_L("SendPointerEvent: Invalid value of x co-ordinate")));
       
  4402         iRunErrorMessage = KErrMsgPositionXInvalidValue;
       
  4403         User::Leave( KErrArgument );            
       
  4404         }
       
  4405 
       
  4406     if ( aItem->GetNextString( parameter ) != KErrNone )
       
  4407         {
       
  4408         __TRACE( KError, (_L("SendPointerEvent: y co-ordinate is not defined")));
       
  4409         iRunErrorMessage = KErrMsgPositionYNotDefined;
       
  4410         User::Leave( KErrArgument );            
       
  4411         }
       
  4412 
       
  4413     parameterParser.Assign( parameter );
       
  4414     if ( parameterParser.Val( position.iY ) != KErrNone )
       
  4415         {
       
  4416         __TRACE( KError, (_L("SendPointerEvent: Invalid value of y co-ordinate")));
       
  4417         iRunErrorMessage = KErrMsgPositionYInvalidValue;
       
  4418         User::Leave( KErrArgument );            
       
  4419         }       
       
  4420         
       
  4421     // Send pointer event
       
  4422     if ( globalMode )
       
  4423         {
       
  4424         uiEnvProxy->SendPointerEventL( eventType, position );           
       
  4425         }
       
  4426     else
       
  4427         {
       
  4428         uiEnvProxy->SendPointerEventL( &iStatus, eventType, position );
       
  4429         }
       
  4430 
       
  4431     return globalMode;
       
  4432     }
       
  4433 
       
  4434 
       
  4435 /*
       
  4436 -------------------------------------------------------------------------------
       
  4437 
       
  4438      Class: CTestRunner
       
  4439 
       
  4440      Method: ExecuteEventL
       
  4441 
       
  4442      Description: Executes event command script line
       
  4443   
       
  4444      Parameters:    TDesC& aKeyword: in: keyword string
       
  4445                     CStifItemParser* aItem: in: script line
       
  4446      
       
  4447      Return Values: ETrue: continue script file execution
       
  4448                     EFalse: stop script file execution
       
  4449 
       
  4450      Errors/Exceptions: Leaves on error situations.
       
  4451 
       
  4452      Status: Draft
       
  4453     
       
  4454 -------------------------------------------------------------------------------
       
  4455 */
       
  4456 TBool CTestRunner::ExecuteEventL( TDesC& aKeyword,
       
  4457                                   CStifItemParser* aItem )
       
  4458     {
       
  4459     _LIT( KErrMsgEventNameNotDefined, "%S : Event name not defined" );
       
  4460     _LIT( KErrMsgUnknowKeyword, "Unknow keyword %S" );
       
  4461     
       
  4462     TInt ret = KErrNone;
       
  4463     TInt key = TTestKeywords::Parse( aKeyword, TTestKeywords::Keyword );
       
  4464     TBool continueTask = ETrue;
       
  4465      
       
  4466     TPtrC eventName;
       
  4467     // read eventname
       
  4468     ret = aItem->GetNextString( eventName );
       
  4469     if ( ret != KErrNone )
       
  4470         {
       
  4471         iRunErrorMessage.Format( KErrMsgEventNameNotDefined, &aKeyword );
       
  4472         User::Leave( ret );
       
  4473         }
       
  4474     
       
  4475     TEventIf event;
       
  4476     event.SetName( eventName );
       
  4477     
       
  4478     __TRACE( KMessage, (_L("%S %S"), &aKeyword, &eventName));
       
  4479     iTestScripter->TestModuleIf().Printf( KPrintPriLow, _L("Event"), 
       
  4480         _L("%S %S"), &aKeyword, &eventName);
       
  4481 
       
  4482     switch( key )
       
  4483         {
       
  4484         case TTestKeywords::ERequest:
       
  4485             {
       
  4486             HBufC* eName = eventName.AllocLC();
       
  4487             User::LeaveIfError( iEventArray.Append( eName ) );
       
  4488             CleanupStack::Pop( eName );
       
  4489             event.SetType( TEventIf::EReqEvent );
       
  4490             ret = iTestScripter->TestModuleIf().Event( event );
       
  4491             }
       
  4492             break;
       
  4493         case TTestKeywords::EWait:
       
  4494             {
       
  4495             event.SetType( TEventIf::EWaitEvent );
       
  4496             iTestScripter->TestModuleIf().Event( event, iStatus );
       
  4497             SetActive();
       
  4498             continueTask = EFalse;
       
  4499             }
       
  4500             break;
       
  4501         case TTestKeywords::ERelease:
       
  4502             {
       
  4503             event.SetType( TEventIf::ERelEvent );
       
  4504             ret = iTestScripter->TestModuleIf().Event( event );
       
  4505             if( ret == KErrNone )
       
  4506                 {
       
  4507                 TPtrC eName;
       
  4508                 TInt count = iEventArray.Count();
       
  4509                 for( TInt i = 0; i < count; i++ )
       
  4510                     {
       
  4511                     eName.Set( iEventArray[i]->Des() );
       
  4512                     if( eName == eventName )
       
  4513                         {
       
  4514                         HBufC* tmp = iEventArray[i];
       
  4515                         iEventArray.Remove(i);
       
  4516                         delete tmp;
       
  4517                         break;
       
  4518                         }
       
  4519                     }
       
  4520                 }
       
  4521             }
       
  4522             break;
       
  4523         case TTestKeywords::ESet:
       
  4524             {
       
  4525             event.SetType( TEventIf::ESetEvent );
       
  4526             
       
  4527             TPtrC tmp;
       
  4528             // Get optional set argument
       
  4529             if( aItem->GetNextString( tmp ) == KErrNone )
       
  4530                 {                      
       
  4531                 // Parse optional set argument
       
  4532                 if( tmp == _L("state") )
       
  4533                     {
       
  4534                     __TRACE( KMessage, (_L("State event")));
       
  4535                     event.SetEventType( TEventIf::EState );
       
  4536                     }
       
  4537                 else
       
  4538                     {
       
  4539                     __TRACE( KError, 
       
  4540                         (_L("Unknown argument for set %S"), 
       
  4541                         &tmp));
       
  4542                     }
       
  4543                 }      
       
  4544             
       
  4545             ret = iTestScripter->TestModuleIf().Event( event );
       
  4546             }
       
  4547             break;
       
  4548         case TTestKeywords::EUnset:
       
  4549             {
       
  4550             event.SetType( TEventIf::EUnsetEvent );
       
  4551             event.SetEventType( TEventIf::EState );
       
  4552             ret = iTestScripter->TestModuleIf().Event( event );
       
  4553             }
       
  4554             break;
       
  4555         default:
       
  4556             __TRACE( KError, (_L("Unknown keyword %S"), &aKeyword));
       
  4557             iRunErrorMessage.Format( KErrMsgUnknowKeyword, &aKeyword );
       
  4558             User::Leave( KErrGeneral );
       
  4559             break;
       
  4560         }
       
  4561     if( ret != KErrNone )
       
  4562         {
       
  4563         TName resultDescr;
       
  4564         resultDescr.Format(_L("Event %S returned error: %d"), &aKeyword, ret);
       
  4565         iTestScripter->UpdateTestCaseResult(ret, resultDescr);
       
  4566         // Stops execution from CTestRunner::RunError
       
  4567         User::Leave( KErrGeneral );
       
  4568         }
       
  4569 
       
  4570     return continueTask;
       
  4571 
       
  4572     }
       
  4573 
       
  4574 /*
       
  4575 -------------------------------------------------------------------------------
       
  4576 
       
  4577      Class: CTestRunner
       
  4578 
       
  4579      Method: ExecuteCommandL
       
  4580 
       
  4581      Description: Executes script line
       
  4582 
       
  4583      Parameters:    TDesC& aObject: in: object name 
       
  4584                     CStifItemParser* aItem: in: script line
       
  4585 
       
  4586      Return Values: ETrue: continue script file execution
       
  4587                     EFalse: stop script file execution
       
  4588 
       
  4589      Errors/Exceptions: Leaves on error situations.
       
  4590 
       
  4591      Status: Proposal
       
  4592 
       
  4593 -------------------------------------------------------------------------------
       
  4594 */
       
  4595 TBool CTestRunner::ExecuteCommandL( TDesC& aObject, CStifItemParser* aItem)
       
  4596     {
       
  4597     _LIT( KErrMsgUnknownObjOrKeyword, "Unknow keyword/object %S" );
       
  4598     
       
  4599    
       
  4600     TTestObjectBase* obj = iTestScripter->GetObject ( aObject );    
       
  4601     if( obj == NULL )
       
  4602         {
       
  4603         iRunErrorMessage.Format( KErrMsgUnknownObjOrKeyword, &aObject );
       
  4604         User::Leave( KErrGeneral );
       
  4605         }
       
  4606 
       
  4607     if( iTestCaseResults.Count() == 0 )
       
  4608         {
       
  4609         // KErrNone is the default result expected if nothing else is given 
       
  4610         User::LeaveIfError( iTestCaseResults.Append( KErrNone ) );
       
  4611         }
       
  4612 
       
  4613     // OOM heap testing with FAILNEXT
       
  4614     if( iHeapFailNext > 0 )
       
  4615         {
       
  4616         __TRACE( KPrint, ( 
       
  4617             _L( "OOM FAILNEXT is used with count value: %d " ),
       
  4618             iHeapFailNext) );
       
  4619         User::__DbgSetAllocFail( RHeap::EUser, RHeap::EFailNext, iHeapFailNext  );
       
  4620         }
       
  4621     // OOM heap testing with SETFAIL
       
  4622     if( iHeapSetFailValue > 0 )
       
  4623         {
       
  4624         __TRACE( KPrint, (
       
  4625             _L("OOM SETFAIL is used with type:[%d] and value(rate):[%d]"),
       
  4626             iHeapSetFailType, iHeapSetFailValue ) );
       
  4627         User::__DbgSetAllocFail( RHeap::EUser, iHeapSetFailType, iHeapSetFailValue );
       
  4628         }
       
  4629 
       
  4630     TInt commandResult = KErrNone;
       
  4631     TRAP( commandResult, commandResult = obj->RunMethodL( *aItem ) );
       
  4632 
       
  4633     
       
  4634     // Reset OOM macro immediately(Otherwise other allocations
       
  4635     // will be blocked)
       
  4636     User::__DbgSetAllocFail( RHeap::EUser, RHeap::ENone, 1 );
       
  4637 
       
  4638     // OOM test class's build block handling
       
  4639     if( iTestScripter->iOOMIgnoreFailure )
       
  4640         {
       
  4641         __TRACE( KPrint, ( 
       
  4642             _L( "----------< OOM related test information >----------" ) ) );
       
  4643         if( iHeapFailNext > 0 )
       
  4644             {
       
  4645             __TRACE( KPrint, ( 
       
  4646                 _L( "'oomignorefailure' is:[ON] and 'failnextvalue' count is:[%d]" ),
       
  4647                 iHeapFailNext ) );
       
  4648             }
       
  4649         if( iHeapSetFailValue > 0 )
       
  4650             {
       
  4651             __TRACE( KPrint, ( 
       
  4652                 _L( "'oomignorefailure' is:[ON], 'setfailtype' type is:[%d] and value is:[%d]" ),
       
  4653                 iHeapSetFailType, iHeapSetFailValue ) );
       
  4654             }
       
  4655         __TRACE( KPrint, ( 
       
  4656             _L( "Test class build block execution with result:[%d]" ),
       
  4657             commandResult ) );
       
  4658         __TRACE( KPrint, ( 
       
  4659             _L( "----------------------------------------------------" ) ) );
       
  4660 
       
  4661         // Continue testing, despite the memory error situations
       
  4662         iTestCaseResults.Reset();
       
  4663         return ETrue; // Continue script executions
       
  4664         }
       
  4665 
       
  4666     // Normal test class's build block handling
       
  4667     if( iTestCaseResults.Find( commandResult ) < 0 ) 
       
  4668         {
       
  4669         __TRACE( KError, ( _L("Command for [%S] failed (%d)"), 
       
  4670                 &aObject, commandResult ));
       
  4671 
       
  4672         // Added more logging for this special case
       
  4673         if( commandResult == KErrNone )
       
  4674             {
       
  4675             __TRACE( KError, (_L("Test fails with result KErrGeneral, because execution result was KErrNone and expected results given with 'allownextresult' were Symbian's error codes (<0)")));    
       
  4676             }
       
  4677            
       
  4678         iTestScripter->UpdateTestCaseResult(commandResult, _L("CTestRunner::ExecuteCommandL returned error"));
       
  4679 
       
  4680         // Stops execution from CTestRunner::RunError
       
  4681         User::Leave( KErrGeneral );
       
  4682         }
       
  4683         
       
  4684     iTestCaseResults.Reset();
       
  4685     // Reset test case allow result to CTestModuleIf side too. This is
       
  4686     // used in TAL-TA5L macro handling.
       
  4687     User::LeaveIfError( 
       
  4688         iTestScripter->TestModuleIf().ResetAllowResult() );
       
  4689         
       
  4690     return ETrue;
       
  4691     }
       
  4692     
       
  4693 /*
       
  4694 -------------------------------------------------------------------------------
       
  4695 
       
  4696      Class: CTestRunner
       
  4697 
       
  4698      Method: SetRunnerActive
       
  4699 
       
  4700      Description: Set CTestRunner active and complete.
       
  4701 
       
  4702      Parameters:    None.
       
  4703 
       
  4704      Return Values: None.
       
  4705 
       
  4706      Errors/Exceptions: None.
       
  4707 
       
  4708      Status: Draft
       
  4709 
       
  4710 -------------------------------------------------------------------------------
       
  4711 */
       
  4712 void CTestRunner::SetRunnerActive()
       
  4713      {
       
  4714      __TRACEFUNC();
       
  4715      // Update state
       
  4716      iState = ERunnerRunning;
       
  4717 
       
  4718      iStatus = KRequestPending;
       
  4719      TRequestStatus* rs = &iStatus;
       
  4720      SetActive();
       
  4721      User::RequestComplete( rs, KErrNone );
       
  4722 
       
  4723      }
       
  4724 
       
  4725 /*
       
  4726 -------------------------------------------------------------------------------
       
  4727 
       
  4728      Class: CTestRunner
       
  4729 
       
  4730      Method: OOMIgnoreFailure
       
  4731 
       
  4732      Description: Handles 'oomignorefailure' keyword parsing.
       
  4733   
       
  4734      Parameters: CStifItemParser* aItem: in: Item object for parsing.
       
  4735 
       
  4736      Return Values: None.
       
  4737 
       
  4738      Errors/Exceptions: None.
       
  4739 
       
  4740      Status: Proposal
       
  4741     
       
  4742 -------------------------------------------------------------------------------
       
  4743 */
       
  4744 void CTestRunner::OOMIgnoreFailureL( CStifItemParser* aItem )
       
  4745     {
       
  4746     _LIT( KerrMsgOOMIgnoreFailureUnknownArgument, "OOMIgnoreFailure : Invalid argument %S" );
       
  4747     _LIT( KerrMsgOOMIgnoreFailureNoArgument, "OOMIgnoreFailure : Parameter not defined" );
       
  4748     
       
  4749     __TRACEFUNC();
       
  4750 
       
  4751     TPtrC tmp;
       
  4752     // Get result
       
  4753     if( aItem->GetNextString( tmp ) == KErrNone )
       
  4754         {                      
       
  4755         if( tmp == _L("ON") || tmp == _L("on") )
       
  4756             {
       
  4757             __TRACE( KMessage, (_L("OOM related 'oomignorefailure': ON")));
       
  4758             iTestScripter->iOOMIgnoreFailure = ETrue;
       
  4759             }
       
  4760         else if( tmp == _L("OFF") || tmp == _L("off") )
       
  4761             {
       
  4762             __TRACE( KMessage, (_L("OOM related 'oomignorefailure': OFF")));
       
  4763             iTestScripter->iOOMIgnoreFailure = EFalse;
       
  4764             }
       
  4765         else
       
  4766             {
       
  4767             __TRACE( KError, 
       
  4768                 (_L("Unknown argument for 'oomignorefailure': [%S]"), 
       
  4769                 &tmp));
       
  4770             iRunErrorMessage.Format( KerrMsgOOMIgnoreFailureUnknownArgument, &tmp );
       
  4771             User::Leave( KErrArgument );
       
  4772             }
       
  4773         }
       
  4774     else
       
  4775         {
       
  4776         __TRACE( KError, ( _L( "Unknown argument for 'oomignorefailure'" ) ) );
       
  4777         iRunErrorMessage = KerrMsgOOMIgnoreFailureNoArgument;
       
  4778         User::Leave( KErrArgument );
       
  4779         }
       
  4780     }
       
  4781 
       
  4782 /*
       
  4783 -------------------------------------------------------------------------------
       
  4784 
       
  4785      Class: CTestRunner
       
  4786 
       
  4787      Method: OOMHeapFailNext
       
  4788 
       
  4789      Description: Handles 'oomheapfailnext' keyword parsing.
       
  4790   
       
  4791      Parameters: CStifItemParser* aItem: in: Item object for parsing.
       
  4792 
       
  4793      Return Values: None.
       
  4794 
       
  4795      Errors/Exceptions: None.
       
  4796 
       
  4797      Status: Proposal
       
  4798     
       
  4799 -------------------------------------------------------------------------------
       
  4800 */
       
  4801 void CTestRunner::OOMHeapFailNextL( CStifItemParser* aItem )
       
  4802     {
       
  4803     _LIT( KErrMsgHeapFailNextNoArgument, "HeapFailNext : Parameters is not defined or has invalid value" );
       
  4804     _LIT( KErrMsgHeapFailNextInvalidValue, "HeapFailNext : Argument value can't be <0" );
       
  4805     __TRACEFUNC();
       
  4806 
       
  4807     TInt heapfailNext( 0 );
       
  4808     // If LOOP_COUNTER is used the GetNextInt returns a correct
       
  4809     // value(Because of the LOOP_COUNTER implementation).
       
  4810     if( aItem->GetNextInt( heapfailNext ) == KErrNone )
       
  4811         {
       
  4812         if( heapfailNext < 0 )
       
  4813             {
       
  4814             __TRACE( KError, ( _L( "Argument value must be >0" ) ) );
       
  4815             iRunErrorMessage = KErrMsgHeapFailNextInvalidValue;
       
  4816             User::Leave( KErrArgument );            
       
  4817             }
       
  4818         // OOM heap's FAILNEXT range is from 1 to n
       
  4819         iHeapFailNext = heapfailNext + 1;
       
  4820         __TRACE( KMessage, ( _L( "'oomheapfailnext' count value(rate): %d" ),
       
  4821             iHeapFailNext ) );
       
  4822         }
       
  4823     else
       
  4824         {
       
  4825         __TRACE( KError, ( _L( "Unknown argument for 'oomheapfailnext'" ) ) );
       
  4826         iRunErrorMessage = KErrMsgHeapFailNextNoArgument;
       
  4827         User::Leave( KErrArgument );
       
  4828         }
       
  4829     }
       
  4830 
       
  4831 /*
       
  4832 -------------------------------------------------------------------------------
       
  4833 
       
  4834      Class: CTestRunner
       
  4835 
       
  4836      Method: OOMHeapSetFail
       
  4837 
       
  4838      Description: Handles 'oomheapsetfail' keyword parsing.
       
  4839   
       
  4840      Parameters: CStifItemParser* aItem: in: Item object for parsing.
       
  4841 
       
  4842      Return Values: None.
       
  4843 
       
  4844      Errors/Exceptions: None.
       
  4845 
       
  4846      Status: Proposal
       
  4847     
       
  4848 -------------------------------------------------------------------------------
       
  4849 */
       
  4850 void CTestRunner::OOMHeapSetFailL( CStifItemParser* aItem )
       
  4851     {
       
  4852     _LIT( KErrMsgOOMHeapSetFailTypeNotDefined, "OOMHeapSetFail : Parameter type is not defined" );
       
  4853     _LIT( KErrMsgOOMHeapSetFailRateNotDefined, "OOMHeapSetFail : Parameter rate is not defined" );
       
  4854     _LIT( KErrMsgOOMHeapSetFailTypeInvalidValue, "OOMHeapSetFail : Parameter type has invalid value" );
       
  4855     _LIT( KErrMsgOOMHeapSetFailRateInvalidValue, "OOMHeapSetFail : Parameter rate can't be <0" );
       
  4856     __TRACEFUNC();
       
  4857     
       
  4858     _LIT( KRandom,        "random");
       
  4859     _LIT( KTrueRandom,    "truerandom");
       
  4860     _LIT( KDeterministic, "deterministic");
       
  4861     _LIT( KNone,          "none");
       
  4862     _LIT( KFailNext,      "failnext");
       
  4863 
       
  4864     TPtrC type;
       
  4865     TInt value( 0 );
       
  4866 
       
  4867     // NOTE: If error in type or value parsing => return without changing
       
  4868     //       iHeapSetFailType or iHeapSetFailValue variables.
       
  4869 
       
  4870     // Get type
       
  4871     if( aItem->GetNextString( type ) != KErrNone )
       
  4872         {
       
  4873         __TRACE( KError, ( 
       
  4874             _L( "Unknown argument for 'oomheapsetfail' type" ) ) );
       
  4875         iRunErrorMessage = KErrMsgOOMHeapSetFailTypeNotDefined;
       
  4876         User::Leave( KErrArgument );
       
  4877         }
       
  4878     // Get value(rate)
       
  4879     if( aItem->GetNextInt( value ) != KErrNone )
       
  4880         {
       
  4881         if(type == KNone)
       
  4882             {
       
  4883             value = 0;
       
  4884             }
       
  4885         else
       
  4886             {
       
  4887             __TRACE( KError, (_L( "Unknown argument for 'oomheapsetfail' value(rate)" ) ) );
       
  4888             iRunErrorMessage = KErrMsgOOMHeapSetFailRateNotDefined;
       
  4889             User::Leave( KErrArgument );
       
  4890             }
       
  4891         }
       
  4892     
       
  4893     // All parsing operations are passed, get type and value
       
  4894 
       
  4895     // Get type
       
  4896     if(type == KRandom)
       
  4897         {
       
  4898         __TRACE( KMessage, (_L("'oomheapsetfail' type: random")));
       
  4899         iHeapSetFailType = RHeap::ERandom;
       
  4900         }
       
  4901     else if(type == KTrueRandom)
       
  4902         {
       
  4903         __TRACE( KMessage, (_L("'oomheapsetfail' type: truerandom")));
       
  4904         iHeapSetFailType = RHeap::ETrueRandom;
       
  4905         }
       
  4906     else if(type == KDeterministic)
       
  4907         {
       
  4908         __TRACE( KMessage, (_L("'oomheapsetfail' type: deterministic")));
       
  4909         iHeapSetFailType = RHeap::EDeterministic;
       
  4910         }
       
  4911     else if(type == KNone)
       
  4912         {
       
  4913         __TRACE( KMessage, (_L("'oomheapsetfail' type: none")));
       
  4914         iHeapSetFailType = RHeap::ENone;
       
  4915         }
       
  4916     else if(type == KFailNext)
       
  4917         {
       
  4918         __TRACE( KMessage, (_L("'oomheapsetfail' type: failnext")));
       
  4919         iHeapSetFailType = RHeap::EFailNext;
       
  4920         }
       
  4921     else
       
  4922         {
       
  4923         __TRACE( KError, 
       
  4924             ( _L( "Unknown argument for 'oomheapsetfail' type: [%S]" ),
       
  4925             &type ) );
       
  4926         iRunErrorMessage = KErrMsgOOMHeapSetFailTypeInvalidValue;
       
  4927         User::Leave( KErrArgument );
       
  4928         }
       
  4929 
       
  4930     if( value < 0 )
       
  4931         {
       
  4932         __TRACE( KError, _L( "'oomheapsetfail' value(rate) can't be <0" ) );                
       
  4933         iRunErrorMessage = KErrMsgOOMHeapSetFailRateInvalidValue;
       
  4934         User::Leave( KErrArgument );
       
  4935         }
       
  4936     // Get value
       
  4937     // OOM heap's SETFAIL range is from 1 to n
       
  4938     iHeapSetFailValue = value + 1;
       
  4939     __TRACE(KMessage, (_L( "'oomheapsetfail' value(rate): [%d]" ), iHeapSetFailValue));
       
  4940 
       
  4941     }
       
  4942 
       
  4943 /*
       
  4944 -------------------------------------------------------------------------------
       
  4945 
       
  4946      Class: CTestRunner
       
  4947 
       
  4948      Method: OOMHeapToNormal
       
  4949 
       
  4950      Description: Initialize all OOM related variables.
       
  4951   
       
  4952      Parameters: None.
       
  4953 
       
  4954      Return Values: None.
       
  4955 
       
  4956      Errors/Exceptions: None.
       
  4957 
       
  4958      Status: Proposal
       
  4959     
       
  4960 -------------------------------------------------------------------------------
       
  4961 */
       
  4962 void CTestRunner::OOMHeapToNormal()
       
  4963     {
       
  4964     __TRACEFUNC();
       
  4965 
       
  4966     if( iTestScripter )
       
  4967         {
       
  4968         // This should initialize also
       
  4969         iTestScripter->iOOMIgnoreFailure = EFalse;
       
  4970         }
       
  4971 
       
  4972     iHeapFailNext = 0;
       
  4973     iHeapSetFailType = RHeap::ENone;
       
  4974     iHeapSetFailValue = 0;
       
  4975 
       
  4976     }
       
  4977 
       
  4978 /*
       
  4979 -------------------------------------------------------------------------------
       
  4980 
       
  4981      Class: CTestRunner
       
  4982 
       
  4983      Method: TestInterference
       
  4984 
       
  4985      Description: Starts test interference.
       
  4986   
       
  4987      Parameters: CStifItemParser* aItem: in: Item object for parsing.
       
  4988 
       
  4989      Return Values: None.
       
  4990 
       
  4991      Errors/Exceptions: None.
       
  4992 
       
  4993      Status: Approved
       
  4994     
       
  4995 -------------------------------------------------------------------------------
       
  4996 */
       
  4997 void CTestRunner::TestInterferenceL( CStifItemParser* aItem )
       
  4998     {
       
  4999     _LIT( KErrMsgTestInterferenceNameNotDefined, "TestInterference : Parameter name is not defined" );
       
  5000     _LIT( KErrMsgTestInterferenceCommandNotDefined, "TestInterference : Parameter command is not defined" );
       
  5001     _LIT( KErrMsgTestInterferenceCommandInvalidValue, "TestInterference : Parameter command has invalid value" );
       
  5002     __TRACEFUNC();
       
  5003     TPtrC name;
       
  5004     TPtrC command;
       
  5005 
       
  5006     // Get name
       
  5007     if( aItem->GetNextString( name ) != KErrNone )
       
  5008         {
       
  5009         __TRACE( KError, ( 
       
  5010             _L( "Unknown argument for 'testinterference' name" ) ) );
       
  5011         iRunErrorMessage = KErrMsgTestInterferenceNameNotDefined;
       
  5012         User::Leave( KErrArgument ); // Error in parsing => Leave
       
  5013         }
       
  5014     // Get command
       
  5015     if( aItem->GetNextString( command ) != KErrNone )
       
  5016         {
       
  5017         __TRACE( KError, ( 
       
  5018             _L( "Unknown argument for 'testinterference' command" ) ) );
       
  5019         iRunErrorMessage = KErrMsgTestInterferenceCommandNotDefined;
       
  5020         User::Leave( KErrArgument ); // Error in parsing => Leave
       
  5021         }
       
  5022 
       
  5023     if( command == _L( "start" ) )
       
  5024         {
       
  5025         __TRACE( KMessage, ( _L( "'testinterference' called, starts test interference") ) );
       
  5026         StartInterferenceL( name, aItem );
       
  5027         }
       
  5028     else if( command == _L( "stop" ) )
       
  5029         {
       
  5030         __TRACE( KMessage, ( _L( "'testinterference' called, stops and releases test interference") ) );
       
  5031         StopInterferenceL( name );
       
  5032         }
       
  5033     else
       
  5034         {
       
  5035         __TRACE( KError, ( 
       
  5036             _L( "Unknown command for 'testinterference'[%S]" ), &command ) );
       
  5037         iRunErrorMessage = KErrMsgTestInterferenceCommandInvalidValue;
       
  5038         User::Leave( KErrArgument ); // Error in parsing => Leave
       
  5039         }
       
  5040 
       
  5041     }
       
  5042 
       
  5043 /*
       
  5044 -------------------------------------------------------------------------------
       
  5045 
       
  5046      Class: CTestRunner
       
  5047 
       
  5048      Method: StartInterference
       
  5049 
       
  5050      Description: 
       
  5051   
       
  5052      Parameters: CStifItemParser* aItem: in: Item object for parsing.
       
  5053 
       
  5054      Return Values: None.
       
  5055 
       
  5056      Errors/Exceptions: None.
       
  5057 
       
  5058      Status: Approved
       
  5059     
       
  5060 -------------------------------------------------------------------------------
       
  5061 */
       
  5062 void CTestRunner::StartInterferenceL( TDesC& aName, CStifItemParser* aItem )
       
  5063     {
       
  5064     _LIT( KErrMsgStartInterferenceCategoryNotDefined, "TestInterference : Parameter category is not defined" );
       
  5065     _LIT( KErrMsgStartInterferenceCategoryInvalidValue, "TestInterference : Parameter category has invalid value" );
       
  5066     _LIT( KErrMsgStartInterferenceTypeNotDefined, "TestInterference : Parameter type is not defined" );
       
  5067     _LIT( KErrMsgStartInterferenceTypeInvalidValue, "TestInterference : Parameter type has invalid value" );
       
  5068     _LIT( KErrMsgStartInterferenceIdleNotDefined, "TestInterference : Parameter idle is not defined or has invalid value" );
       
  5069     _LIT( KErrMsgStartInterferenceIdleInvalidValue, "TestInterference : Parameter idle has invalid value" );
       
  5070     _LIT( KErrMsgStartInterferenceActiveNotDefined, "TestInterference : Parameter active is not defined or has invalid value" );
       
  5071     _LIT( KErrMsgStartInterferenceActiveInvalidValue, "TestInterference : Parameter active has invalid value" );
       
  5072     
       
  5073     __TRACEFUNC();
       
  5074     TPtrC category;
       
  5075     TPtrC type;
       
  5076     TInt idle( 0 );
       
  5077     TInt active( 0 );
       
  5078     TInt priority( 0 );
       
  5079 
       
  5080     // Get category
       
  5081     if( aItem->GetNextString( category ) != KErrNone )
       
  5082         {
       
  5083         __TRACE( KError, ( 
       
  5084             _L( "Unknown argument for 'testinterference' category" ) ) );
       
  5085         iRunErrorMessage = KErrMsgStartInterferenceCategoryNotDefined;
       
  5086         User::Leave( KErrArgument ); // Error in parsing => Leave
       
  5087         }
       
  5088     // Get type
       
  5089     if( aItem->GetNextString( type ) != KErrNone )
       
  5090         {
       
  5091         __TRACE( KError, ( 
       
  5092             _L( "Unknown argument for 'testinterference' type" ) ) );
       
  5093         iRunErrorMessage = KErrMsgStartInterferenceTypeNotDefined;
       
  5094         User::Leave( KErrArgument ); // Error in parsing => Leave
       
  5095         }
       
  5096 
       
  5097     TPtrC timeStr;
       
  5098     TReal time;
       
  5099     // Get idle time
       
  5100     if( aItem->GetNextString( timeStr ) != KErrNone )
       
  5101         {        
       
  5102         __TRACE( KError, ( 
       
  5103             _L( "Unknown argument for 'testinterference' idle" ) ) );
       
  5104         iRunErrorMessage = KErrMsgStartInterferenceIdleNotDefined;
       
  5105         User::Leave( KErrArgument ); // Error in parsing => Leave
       
  5106         }
       
  5107     if ( TLex( timeStr ).Val( time, '.' ) != KErrNone )
       
  5108         {
       
  5109         __TRACE( KError, ( 
       
  5110             _L( "Unknown argument for 'testinterference' idle" ) ) );
       
  5111         iRunErrorMessage = KErrMsgStartInterferenceIdleNotDefined;
       
  5112         User::Leave( KErrArgument ); // Error in parsing => Leave       
       
  5113         }
       
  5114     // Convert idle time from milli to micro seconds
       
  5115     idle = time * 1000.0;
       
  5116 
       
  5117     if( idle < 0 )
       
  5118         {
       
  5119         __TRACE( KError, ( 
       
  5120                 _L( "Argument 'testinterference' idle can't be <0" ) ) );
       
  5121         iRunErrorMessage = KErrMsgStartInterferenceIdleInvalidValue;
       
  5122         User::Leave( KErrArgument );
       
  5123         }
       
  5124    // Get active time
       
  5125     if( aItem->GetNextString( timeStr ) != KErrNone )
       
  5126         {
       
  5127         __TRACE( KError, ( 
       
  5128             _L( "Unknown argument for 'testinterference' active" ) ) );
       
  5129         iRunErrorMessage = KErrMsgStartInterferenceActiveNotDefined;
       
  5130         User::Leave( KErrArgument ); // Error in parsing => Leave
       
  5131         }
       
  5132     if ( TLex( timeStr ).Val( time, '.' ) != KErrNone )
       
  5133         {
       
  5134         __TRACE( KError, ( 
       
  5135             _L( "Unknown argument for 'testinterference' idle" ) ) );
       
  5136         iRunErrorMessage = KErrMsgStartInterferenceIdleNotDefined;
       
  5137         User::Leave( KErrArgument ); // Error in parsing => Leave       
       
  5138         }
       
  5139     
       
  5140     // Convert active time from milli to micro seconds
       
  5141     active = time * 1000.0;
       
  5142     
       
  5143     if( active < 0 )
       
  5144         {
       
  5145         __TRACE( KError, ( 
       
  5146                 _L( "Argument 'testinterference' active can't be <0" ) ) );
       
  5147         iRunErrorMessage = KErrMsgStartInterferenceActiveInvalidValue;
       
  5148         User::Leave( KErrArgument );
       
  5149         }
       
  5150     
       
  5151    // Get priority
       
  5152     if( aItem->GetNextInt( priority ) != KErrNone )
       
  5153         {
       
  5154         // Log information only do not return. Priority value is optional.
       
  5155         __TRACE( KInit, ( 
       
  5156             _L( "Unknown argument for 'testinterference' priority or value not given, default priority will be used" ) ) );
       
  5157         }    
       
  5158 
       
  5159     MSTIFTestInterference* interference = NULL;
       
  5160 
       
  5161     // Get category
       
  5162     if( category == _L("activeobject") )
       
  5163         {
       
  5164         interference = MSTIFTestInterference::NewL( iTestScripter,
       
  5165                             MSTIFTestInterference::EActiveObject );
       
  5166         }
       
  5167     else if( category == _L("thread") )
       
  5168         {
       
  5169         interference = MSTIFTestInterference::NewL( iTestScripter,
       
  5170                             MSTIFTestInterference::EThread );
       
  5171         }
       
  5172     else
       
  5173         {
       
  5174         __TRACE( KError, ( 
       
  5175             _L( "Unknown argument for 'testinterference' category[%S]" ), &category ) );
       
  5176         iRunErrorMessage = KErrMsgStartInterferenceCategoryInvalidValue;
       
  5177         User::Leave( KErrArgument ); // Error in parsing => Leave
       
  5178         }
       
  5179 
       
  5180     // Create object that include test interference information and append this
       
  5181     // to array.
       
  5182     TTestInterference* object = new (ELeave) TTestInterference();
       
  5183     object->iName = aName;
       
  5184     object->iInterference = interference;
       
  5185 
       
  5186     // Array for handling test interference between different objects
       
  5187     TInt ret = iTestInterferenceArray.Append( object );
       
  5188     if( ret != KErrNone )
       
  5189         {
       
  5190         delete object;
       
  5191         __TRACE( KError, ( 
       
  5192             _L( "CTestRunner::StartInterference: iTestInterferenceArray.Append fails:[%d]" ), ret ) );
       
  5193         User::Leave( ret );
       
  5194         }
       
  5195 
       
  5196     // Set priority if user given
       
  5197     if( priority != 0 )
       
  5198         {
       
  5199         interference->SetPriority( priority );
       
  5200         }
       
  5201 
       
  5202     // Get type
       
  5203     if( type == _L("cpuload") )
       
  5204         {
       
  5205         interference->StartL( MSTIFTestInterference::ECpuLoadMicroSeconds, idle , active );
       
  5206         }
       
  5207     else if( type == _L("filesystemreadc") )
       
  5208         {
       
  5209         interference->StartL( MSTIFTestInterference::EFileSystemReadCMicroSeconds, idle , active );
       
  5210         }
       
  5211     else if( type == _L("filesystemreadd") )
       
  5212         {
       
  5213         interference->StartL( MSTIFTestInterference::EFileSystemReadDMicroSeconds, idle , active );
       
  5214         }
       
  5215     else if( type == _L("filesystemreade") )
       
  5216         {
       
  5217         interference->StartL( MSTIFTestInterference::EFileSystemReadEMicroSeconds, idle , active );
       
  5218         }
       
  5219     else if( type == _L("filesystemreadz") )
       
  5220         {
       
  5221         interference->StartL( MSTIFTestInterference::EFileSystemReadZMicroSeconds, idle , active );
       
  5222         }
       
  5223     else if( type == _L("filesystemwritec") )
       
  5224         {
       
  5225         interference->StartL( MSTIFTestInterference::EFileSystemWriteCMicroSeconds, idle , active );
       
  5226         }
       
  5227     else if( type == _L("filesystemwrited") )
       
  5228         {
       
  5229         interference->StartL( MSTIFTestInterference::EFileSystemWriteDMicroSeconds, idle , active );
       
  5230         }
       
  5231     else if( type == _L("filesystemwritee") )
       
  5232         {
       
  5233         interference->StartL( MSTIFTestInterference::EFileSystemWriteEMicroSeconds, idle , active );
       
  5234         }
       
  5235     else if( type == _L("filesystemfillandemptyc") )
       
  5236         {
       
  5237         interference->StartL( MSTIFTestInterference::EFileSystemFillAndEmptyCMicroSeconds, idle , active );
       
  5238         }
       
  5239     else if( type == _L("filesystemfillandemptyd") )
       
  5240         {
       
  5241         interference->StartL( MSTIFTestInterference::EFileSystemFillAndEmptyDMicroSeconds, idle , active );
       
  5242         }
       
  5243     else if( type == _L("filesystemfillandemptye") )
       
  5244         {
       
  5245         interference->StartL( MSTIFTestInterference::EFileSystemFillAndEmptyEMicroSeconds, idle , active );
       
  5246         }
       
  5247     else
       
  5248         {
       
  5249         __TRACE( KError, ( 
       
  5250             _L( "Unknown argument for 'testinterference' type[%S]" ), &type ) );
       
  5251         iRunErrorMessage = KErrMsgStartInterferenceTypeInvalidValue;
       
  5252         User::Leave( KErrArgument ); // Error in parsing => Leave
       
  5253         }
       
  5254 
       
  5255     }
       
  5256 
       
  5257 /*
       
  5258 -------------------------------------------------------------------------------
       
  5259 
       
  5260      Class: CTestRunner
       
  5261 
       
  5262      Method: StopInterference
       
  5263 
       
  5264      Description: Stops test interference.
       
  5265   
       
  5266      Parameters: TDesC& aName: in: Indicates right test interference object.
       
  5267 
       
  5268      Return Values: None.
       
  5269 
       
  5270      Errors/Exceptions: None.
       
  5271 
       
  5272      Status: Approved
       
  5273     
       
  5274 -------------------------------------------------------------------------------
       
  5275 */
       
  5276 void CTestRunner::StopInterferenceL( TDesC& aName )
       
  5277     {    
       
  5278     _LIT( KErrMsgStopInterference, "TestInterference : testinterference %S was not start" );
       
  5279     __TRACEFUNC();
       
  5280     
       
  5281     TInt count = iTestInterferenceArray.Count();
       
  5282     for( TInt i = 0; i < count; i++ )
       
  5283         {
       
  5284         if( iTestInterferenceArray[i]->iName == aName )
       
  5285             {
       
  5286             // Found test module, return description
       
  5287             iTestInterferenceArray[i]->iInterference->Stop();
       
  5288             // Delete data
       
  5289             delete iTestInterferenceArray[i];
       
  5290             // Remove pointer to deleted data(Append())
       
  5291             iTestInterferenceArray.Remove( i );
       
  5292             // iTestMeasurementArray can contain only one type of measurement
       
  5293             // so we can break when type is removed.
       
  5294             return;
       
  5295             }
       
  5296         }
       
  5297     __TRACE( KError, ( 
       
  5298             _L( "'testinterference' type[%S] was not start" ), &aName ) );
       
  5299     iRunErrorMessage.Format( KErrMsgStopInterference, &aName );
       
  5300     User::Leave( KErrArgument ); // Error in parsing => Leave
       
  5301     }
       
  5302 
       
  5303 /*
       
  5304 -------------------------------------------------------------------------------
       
  5305 
       
  5306      Class: CTestRunner
       
  5307 
       
  5308      Method: MeasurementL
       
  5309 
       
  5310      Description: Starts test measurement.
       
  5311   
       
  5312      Parameters: CStifItemParser* aItem: in: Item object for parsing.
       
  5313 
       
  5314      Return Values: None.
       
  5315 
       
  5316      Errors/Exceptions: Leaves if StartBappeaMeasurementL() fails.
       
  5317                         Leaves if StopBappeaMeasurementL() fails.
       
  5318 
       
  5319      Status: Approved
       
  5320     
       
  5321 -------------------------------------------------------------------------------
       
  5322 */
       
  5323 void CTestRunner::MeasurementL( CStifItemParser* aItem )
       
  5324     {
       
  5325     _LIT( KErrMsgMeasurementCommandNotDefined, "TestMeasurement : Parameter command is not defined" );
       
  5326     _LIT( KErrMsgMeasurementTypeNotDefined, "TestMeasurement : Parameter type is not defined" );
       
  5327     _LIT( KErrMsgMeasurementUnknownType, "TestMeasurement : Unknown measurement type %S" );
       
  5328     _LIT( KErrMsgMeasurementUnknownCommand, "TestMeasurement : Unknown command %S" );
       
  5329     __TRACEFUNC();
       
  5330     TPtrC type;
       
  5331     TPtrC command;
       
  5332 
       
  5333     // Get command
       
  5334     if( aItem->GetNextString( command ) != KErrNone )
       
  5335         {
       
  5336         __TRACE( KError, ( 
       
  5337             _L( "Unknown argument for 'measurement' command" ) ) );
       
  5338         iRunErrorMessage = KErrMsgMeasurementCommandNotDefined;
       
  5339         User::Leave( KErrArgument ); // Error in parsing => Leave
       
  5340         }
       
  5341     // Get name
       
  5342     if( aItem->GetNextString( type ) != KErrNone )
       
  5343         {
       
  5344         __TRACE( KError, ( 
       
  5345             _L( "Unknown argument for 'measurement' type" ) ) );
       
  5346         iRunErrorMessage = KErrMsgMeasurementTypeNotDefined;
       
  5347         User::Leave( KErrArgument ); // Error in parsing => Leave
       
  5348         }
       
  5349 
       
  5350     // Verify measurement type
       
  5351     if( !( type == KParamMeasurement01 ||
       
  5352                 type == KParamMeasurement02 ||
       
  5353                 type == KParamMeasurement03 ||
       
  5354                 type == KParamMeasurement04 ||
       
  5355                 type == KParamMeasurement05 ||
       
  5356                 type == KParamMeasurementBappea ) )
       
  5357 
       
  5358         {
       
  5359         __TRACE( KError, ( 
       
  5360             _L( "Unknown measurement type:[%S]" ), &type ) );
       
  5361         iRunErrorMessage.Format( KErrMsgMeasurementUnknownType, &type );
       
  5362         User::Leave( KErrArgument ); // Error in types => Leave
       
  5363         }
       
  5364 
       
  5365     // Verify command
       
  5366    if( command == _L( "start" ) )
       
  5367         {
       
  5368         // START measurement's process
       
  5369         __TRACE( KMessage, ( _L( "Start 'measurement' with '%S'"), &type ) );
       
  5370         StartMeasurementL( type, aItem );
       
  5371         }
       
  5372     else if( command == _L( "stop" ) )
       
  5373         {
       
  5374         // STOP measurement's process
       
  5375         __TRACE( KMessage, ( _L( "'Stop 'measurement' with '%S'"), &type ) );
       
  5376         StopMeasurementL( type );
       
  5377         }
       
  5378     else
       
  5379         {
       
  5380         __TRACE( KError, ( 
       
  5381             _L( "Unknown command for 'measurement' command:[%S] or type:[%S]" ), &command, &type ) );
       
  5382         iRunErrorMessage.Format( KErrMsgMeasurementUnknownCommand, &command );
       
  5383         User::Leave( KErrArgument ); // Error in commands => Leave
       
  5384         }
       
  5385 
       
  5386     }
       
  5387 
       
  5388 /*
       
  5389 -------------------------------------------------------------------------------
       
  5390 
       
  5391      Class: CTestRunner
       
  5392 
       
  5393      Method: StartMeasurementL
       
  5394 
       
  5395      Description: Start measurement
       
  5396   
       
  5397      Parameters: const TDesC& aType: in: Plugin type.
       
  5398                  CStifItemParser* aItem: in: Item object for parsing.
       
  5399 
       
  5400      Return Values: None.
       
  5401 
       
  5402      Errors/Exceptions: Leaves is measurement operation fails.
       
  5403 
       
  5404      Status: Approved
       
  5405     
       
  5406 -------------------------------------------------------------------------------
       
  5407 */
       
  5408 void CTestRunner::StartMeasurementL( const TDesC& aType,
       
  5409                                            CStifItemParser* aItem )
       
  5410     {
       
  5411     _LIT( KErrMsgMeasurementUnknownPlugin, "Measurement : Unknown measurement plugin %S" );
       
  5412     _LIT( KErrMsgMeasurementStartFail, "Measurement : Measurement start fails" );
       
  5413     __TRACEFUNC();
       
  5414 
       
  5415     CSTIFTestMeasurement* testMeasurement = NULL;
       
  5416 
       
  5417     // Get Measurement configuration info
       
  5418     TPtrC configurationInfo( KNullDesC() );
       
  5419     if( aItem->Remainder( configurationInfo ) != KErrNone )
       
  5420         {
       
  5421         __TRACE( KInit, ( 
       
  5422             _L( "Using default path and file name for measurement configure" ) ) );
       
  5423         } 
       
  5424 
       
  5425     if( aType == KParamMeasurement01 )
       
  5426         {
       
  5427         testMeasurement = CSTIFTestMeasurement::NewL( 
       
  5428                     iTestScripter, 
       
  5429                     CSTIFTestMeasurement::KStifMeasurementPlugin01,
       
  5430                     configurationInfo );
       
  5431         }
       
  5432     else if( aType == KParamMeasurement02 )
       
  5433         {
       
  5434         testMeasurement = CSTIFTestMeasurement::NewL( 
       
  5435                     iTestScripter, 
       
  5436                     CSTIFTestMeasurement::KStifMeasurementPlugin02,
       
  5437                     configurationInfo );
       
  5438         }
       
  5439     else if( aType == KParamMeasurement03 )
       
  5440         {
       
  5441         testMeasurement = CSTIFTestMeasurement::NewL( 
       
  5442                     iTestScripter, 
       
  5443                     CSTIFTestMeasurement::KStifMeasurementPlugin03,
       
  5444                     configurationInfo );
       
  5445         }
       
  5446     else if( aType == KParamMeasurement04 )
       
  5447         {
       
  5448         testMeasurement = CSTIFTestMeasurement::NewL( 
       
  5449                     iTestScripter, 
       
  5450                     CSTIFTestMeasurement::KStifMeasurementPlugin04,
       
  5451                     configurationInfo );
       
  5452         }
       
  5453     else if( aType == KParamMeasurement05 )
       
  5454         {
       
  5455         testMeasurement = CSTIFTestMeasurement::NewL( 
       
  5456                     iTestScripter, 
       
  5457                     CSTIFTestMeasurement::KStifMeasurementPlugin05,
       
  5458                     configurationInfo );
       
  5459         }
       
  5460     else if( aType == KParamMeasurementBappea )
       
  5461         {
       
  5462         testMeasurement = CSTIFTestMeasurement::NewL( 
       
  5463                     iTestScripter, 
       
  5464                     CSTIFTestMeasurement::KStifMeasurementBappeaProfiler,
       
  5465                     configurationInfo );
       
  5466         }
       
  5467     else
       
  5468         {
       
  5469         __TRACE( KError, ( _L( "Unknown plugin[%S] for 'measurement'" ), &aType ) );
       
  5470         iRunErrorMessage.Format( KErrMsgMeasurementUnknownPlugin, &aType );        
       
  5471         User::Leave( KErrArgument );
       
  5472         }
       
  5473 
       
  5474     // Start test measurement
       
  5475     TInt start_ret( KErrNone );
       
  5476     start_ret = testMeasurement->Start();
       
  5477     if( start_ret != KErrNone )
       
  5478         {
       
  5479         delete testMeasurement;
       
  5480         //CleanupStack::PopAndDestroy( setting_buf );
       
  5481         __TRACE( KError, ( 
       
  5482             _L( "CTestRunner::StartMeasurementL(): Measurement Start() fails:[%d]" ), start_ret ) );
       
  5483         iRunErrorMessage = KErrMsgMeasurementStartFail;
       
  5484         User::Leave( start_ret );
       
  5485         }
       
  5486 
       
  5487     TTestMeasurement* object = new (ELeave) TTestMeasurement();
       
  5488     object->iName = aType;
       
  5489     object->iMeasurement = testMeasurement;
       
  5490 
       
  5491     // Array for handling test measurement between different objects
       
  5492     TInt ret = iTestMeasurementArray.Append( object );
       
  5493     if( ret != KErrNone )
       
  5494         {
       
  5495         delete object;
       
  5496         __TRACE( KError, ( 
       
  5497             _L( "CTestRunner::StartMeasurementL(): iTestMeasurementArray.Append fails:[%d]" ), ret ) );
       
  5498         User::Leave( ret );
       
  5499         }
       
  5500 
       
  5501     }
       
  5502 
       
  5503 /*
       
  5504 -------------------------------------------------------------------------------
       
  5505 
       
  5506      Class: CTestRunner
       
  5507 
       
  5508      Method: StopMeasurementL
       
  5509 
       
  5510      Description: Stops test measurement.
       
  5511   
       
  5512      Parameters: None.
       
  5513 
       
  5514      Return Values: None.
       
  5515 
       
  5516      Errors/Exceptions: None.
       
  5517 
       
  5518      Status: Approved
       
  5519     
       
  5520 -------------------------------------------------------------------------------
       
  5521 */
       
  5522 void CTestRunner::StopMeasurementL( const TDesC& aType )
       
  5523     {
       
  5524     _LIT( KErrMsgMeasurementNotStarted, "Measurement : Measurement %S was not start" );
       
  5525     __TRACEFUNC();
       
  5526 
       
  5527     TInt count = iTestMeasurementArray.Count();
       
  5528     for( TInt i = 0; i < count; i++ )
       
  5529         {
       
  5530         if( iTestMeasurementArray[i]->iName == aType )
       
  5531             {
       
  5532             // Found measurement module, stop
       
  5533             iTestMeasurementArray[i]->iMeasurement->Stop();
       
  5534             // Delete data
       
  5535             delete iTestMeasurementArray[i];
       
  5536             // Remove pointer to deleted data(Append())
       
  5537             iTestMeasurementArray.Remove( i );
       
  5538             // iTestMeasurementArray can contain only one type of measurement
       
  5539             // so we can break when type is removed.
       
  5540             return;
       
  5541             }
       
  5542         }
       
  5543 
       
  5544     __TRACE( KError, ( 
       
  5545             _L( "CTestRunner::StopMeasurementL(): Measurement %S was not start" ), &aType ) );
       
  5546     iRunErrorMessage.Format( KErrMsgMeasurementNotStarted, &aType  );
       
  5547     User::Leave( KErrArgument );
       
  5548     }
       
  5549 
       
  5550 /*
       
  5551 -------------------------------------------------------------------------------
       
  5552 
       
  5553      Class: CTestRunner
       
  5554 
       
  5555      Method: AddTestCaseResultL
       
  5556 
       
  5557      Description: Adds new test case result. Used with 'allownextresult'
       
  5558                   and 'allowerrorcodes' keywords.
       
  5559   
       
  5560      Parameters: CStifItemParser* aItem: in: Item object for parsing.
       
  5561 
       
  5562      Return Values: None.
       
  5563 
       
  5564      Errors/Exceptions: Leaves if iTestCaseResults.Append fails.
       
  5565                         Leaves if aItem->GetNextInt() fails.
       
  5566 
       
  5567      Status: Approved
       
  5568     
       
  5569 -------------------------------------------------------------------------------
       
  5570 */
       
  5571 void CTestRunner::AddTestCaseResultL( CStifItemParser* aItem )
       
  5572     {
       
  5573     _LIT( KErrMsgAllowNextResultInvalidValue, "No expected result value given or value has invalid format" );
       
  5574     TInt result;
       
  5575 
       
  5576     TPtrC codeBuf;
       
  5577     TBool found = EFalse;
       
  5578     while( aItem->GetNextString( codeBuf ) == KErrNone )
       
  5579         {
       
  5580         TLex codeParser( codeBuf );
       
  5581         if ( codeParser.Val( result ) != KErrNone )
       
  5582             {
       
  5583             __TRACE( KError, (_L("ExecuteLineL: No expected result value given")));
       
  5584             iRunErrorMessage = KErrMsgAllowNextResultInvalidValue;
       
  5585             User::Leave( KErrArgument );            
       
  5586             }
       
  5587         else
       
  5588             {
       
  5589             User::LeaveIfError( iTestCaseResults.Append( result ) );
       
  5590             // Set test case allow result to CTestModuleIf side too. This is
       
  5591             // used in TAL-TA5L macro handling.
       
  5592             User::LeaveIfError( 
       
  5593                 iTestScripter->TestModuleIf().SetAllowResult( result ) );
       
  5594             found = ETrue;
       
  5595             }
       
  5596         }
       
  5597 
       
  5598     if ( !found )
       
  5599         {
       
  5600         __TRACE( KError, (_L("ExecuteLineL: No expected result value given")));
       
  5601         iRunErrorMessage = KErrMsgAllowNextResultInvalidValue;
       
  5602         User::Leave( KErrArgument );
       
  5603         }    
       
  5604     }
       
  5605     
       
  5606 /*
       
  5607 -------------------------------------------------------------------------------
       
  5608 
       
  5609      Class: CTestRunner
       
  5610 
       
  5611      Method: AddTestCasePanicL
       
  5612 
       
  5613      Description: Adds new test case result. Used with 'allowpanic'
       
  5614                   and 'allowerrorcodes' keywords.
       
  5615   
       
  5616      Parameters: CStifItemParser* aItem: in: Item object for parsing.
       
  5617 
       
  5618      Return Values: None.
       
  5619 
       
  5620      Errors/Exceptions: Leaves if iTestCaseResults.Append fails.
       
  5621                         Leaves if aItem->GetNextInt() fails.
       
  5622 
       
  5623      Status: Approved
       
  5624     
       
  5625 -------------------------------------------------------------------------------
       
  5626 */
       
  5627 
       
  5628 void CTestRunner::AddTestCasePanicL( CStifItemParser* aItem )
       
  5629     {
       
  5630     _LIT( KErrMsgAllowNextPanicInvalidValue, "No expected panic value given or value has invalid format" );
       
  5631     TInt panic;
       
  5632 
       
  5633     TPtrC codeBuf;
       
  5634     while( aItem->GetNextString( codeBuf ) == KErrNone )
       
  5635         {
       
  5636         TLex codeParser( codeBuf );
       
  5637         if ( codeParser.Val( panic ) != KErrNone )
       
  5638             {
       
  5639             __TRACE( KError, (_L("ExecuteLineL: No expected panic value given")));
       
  5640             iRunErrorMessage = KErrMsgAllowNextPanicInvalidValue;
       
  5641             User::Leave( KErrArgument );            
       
  5642             }
       
  5643         else
       
  5644             {
       
  5645             //do not add panic result to allowed result of case.
       
  5646             //User::LeaveIfError( iTestCaseResults.Append( panic ) );
       
  5647             // Set test case allow result to CTestModuleIf side too. This is
       
  5648             // used in TAL-TA5L macro handling.
       
  5649             iTestScripter->TestModuleIf().SetExitReason( CTestModuleIf::EPanic, panic );
       
  5650             break;
       
  5651             }
       
  5652         }  
       
  5653     }    
       
  5654 
       
  5655 /*
       
  5656 -------------------------------------------------------------------------------
       
  5657 
       
  5658      Class: CTestRunner
       
  5659 
       
  5660      Method: SubTestCaseFinishedL
       
  5661 
       
  5662      Description: Recieves and handles notification about finished sub test 
       
  5663      \            case execution.
       
  5664   
       
  5665      Parameters:    CSubTestCaseRunner* aSubTestCaseRunner: in: sub test case
       
  5666                          runner used to run test case.
       
  5667      
       
  5668      Return Values: None
       
  5669 
       
  5670      Errors/Exceptions: Leaves on error situations.
       
  5671 
       
  5672      Status: Proposal
       
  5673     
       
  5674 -------------------------------------------------------------------------------
       
  5675 */
       
  5676 void CTestRunner::SubTestCaseFinishedL( CSubTestCaseRunner* aSubTestCaseRunner )
       
  5677     {
       
  5678     if ( iInternalStateForSubTestCases == EISFinished )
       
  5679         {
       
  5680         if ( aSubTestCaseRunner->GetTestCaseResult().iCaseExecutionResultCode == KErrCancel )
       
  5681             {
       
  5682             // Test was canceled. Do nothing.
       
  5683             return;
       
  5684             }
       
  5685         else
       
  5686             {
       
  5687             User::Leave( KErrGeneral );
       
  5688             }
       
  5689         }
       
  5690     
       
  5691     TInt index = iSubTestCases.Find( aSubTestCaseRunner );
       
  5692     if ( index < 0 )
       
  5693         {
       
  5694         // Debug info
       
  5695         return;
       
  5696         }
       
  5697     
       
  5698     CSubTestCaseRunner* subTestCaseRunner = iSubTestCases[ index ];
       
  5699     iSubTestCases.Remove( index );
       
  5700     CleanupStack::PushL( subTestCaseRunner );
       
  5701     
       
  5702     TInt runResult = subTestCaseRunner->GetRunResult();
       
  5703     TFullTestResult testCaseResult = subTestCaseRunner->GetTestCaseResult();
       
  5704     const CStartInfo* startInfo = subTestCaseRunner->GetStartInfo();
       
  5705 
       
  5706     __TRACE( KMessage, ( _L( "Sub test case execution finished: module=%S cfg=%S tcnum=%d id=%S" ),
       
  5707          &startInfo->GetModuleName(), &startInfo->GetConfig(), 
       
  5708          startInfo->GetTestCaseNumber(), &startInfo->GetTestId()) );
       
  5709 
       
  5710     __TRACE( KMessage, ( _L( "Sub test case execution result: execution_result=%d, test_result=%d, des=%S" ),
       
  5711          testCaseResult.iCaseExecutionResultCode, testCaseResult.iTestResult.iResult,
       
  5712          &testCaseResult.iTestResult.iResultDes ) );
       
  5713 
       
  5714     RDebug::Print( _L( "Sub test case execution finished: module=%S cfg=%S tcnum=%d id=%S" ),
       
  5715             &startInfo->GetModuleName(), &startInfo->GetConfig(), 
       
  5716             startInfo->GetTestCaseNumber(), &startInfo->GetTestId() );
       
  5717 
       
  5718     RDebug::Print( _L( "Sub test case execution result: execution_result=%d, test_result=%d, des=%S" ),
       
  5719             testCaseResult.iCaseExecutionResultCode, testCaseResult.iTestResult.iResult,
       
  5720             &testCaseResult.iTestResult.iResultDes );
       
  5721     
       
  5722     // Check expected execution result type
       
  5723     TBool reportFailedSubTestCase = EFalse;
       
  5724     if( testCaseResult.iCaseExecutionResultType != startInfo->GetExpectedResultCategory() ) 
       
  5725         {
       
  5726         reportFailedSubTestCase = true;
       
  5727         }
       
  5728     else
       
  5729         {
       
  5730         if( startInfo->GetExpectedResultCategory() == TFullTestResult::ECaseExecuted )
       
  5731             {
       
  5732             if ( startInfo->GetExpectedResult() != testCaseResult.iTestResult.iResult )
       
  5733                 {
       
  5734                 reportFailedSubTestCase = true;
       
  5735                 }
       
  5736             }
       
  5737         else
       
  5738             {
       
  5739             if ( startInfo->GetExpectedResult() != testCaseResult.iCaseExecutionResultCode )
       
  5740                 {
       
  5741                 reportFailedSubTestCase = true;
       
  5742                 }
       
  5743             }
       
  5744         }    
       
  5745 
       
  5746     if ( reportFailedSubTestCase )
       
  5747         {
       
  5748         // Only remember first failed sub test case
       
  5749         if ( iFailedSubTestCaseReported == EFalse )
       
  5750             {
       
  5751             // If passlimit is enabled and loop is in progress ignore sub test case fail. 
       
  5752             // Fail will be reported only if passlimit is not met.
       
  5753             // It is done in ReportLoopEndResultL
       
  5754             if ( !( iLoopHelper->LoopInProgress() && iPasslimitEnabled ) || iCancelIfError )
       
  5755                 {
       
  5756                 iFailedSubTestCaseReported = true;
       
  5757                 iFailedSubTestCaseResult = testCaseResult;
       
  5758                 iFailedSubTestCaseInfo = CStartInfo::NewL();
       
  5759                 iFailedSubTestCaseInfo->CopyL( *startInfo );
       
  5760                 }
       
  5761             }
       
  5762         }
       
  5763     
       
  5764     switch( iInternalStateForSubTestCases )
       
  5765         {
       
  5766         case EISRuning:
       
  5767             // Do noting
       
  5768             if ( iLoopHelper->LoopInProgress() )
       
  5769                 {
       
  5770                 iLoopHelper->NotifySubTestCaseEndL( subTestCaseRunner, !reportFailedSubTestCase );
       
  5771                 }
       
  5772             break;
       
  5773         case EISWaitingForComplete:
       
  5774             if ( iLoopHelper->LoopInProgress() )
       
  5775                 {
       
  5776                 iLoopHelper->NotifySubTestCaseEndL( subTestCaseRunner, !reportFailedSubTestCase );
       
  5777                 }
       
  5778             // Do noting
       
  5779             if ( subTestCaseRunner->GetStartInfo()->GetTestId() == *iTestIdForComplete )
       
  5780                 {
       
  5781                 delete iTestIdForComplete;
       
  5782                 iTestIdForComplete = NULL;
       
  5783                 SetRunnerActive(); // Continue test case execution after complete
       
  5784                 iInternalStateForSubTestCases = EISRuning;
       
  5785                 }
       
  5786             break;
       
  5787         case EISFinishedWaitingForSubTestCases:
       
  5788             if ( iSubTestCases.Count() <= 0 )
       
  5789                 {
       
  5790                 SetRunnerActive();
       
  5791                 }
       
  5792             break;
       
  5793         default:
       
  5794             break;
       
  5795         }
       
  5796 
       
  5797     CleanupStack::PopAndDestroy( subTestCaseRunner );
       
  5798     
       
  5799     if ( iCancelIfError && iFailedSubTestCaseReported )
       
  5800         {
       
  5801         // Make sure that DoCancel will be executed 
       
  5802         if ( !IsActive() )
       
  5803             {
       
  5804             SetRunnerActive();
       
  5805             }
       
  5806         // Stop Test Case execution
       
  5807         Cancel();
       
  5808         }    
       
  5809     }
       
  5810 
       
  5811 /*
       
  5812 -------------------------------------------------------------------------------
       
  5813 
       
  5814      Class: CTestRunner
       
  5815 
       
  5816      Method: ReportLoopEndResultL
       
  5817 
       
  5818      Description: Recives report from CLoopHelper about result of loop execution
       
  5819   
       
  5820      Parameters: TInt aPassedIterations: in: number of passed loop iterations
       
  5821      
       
  5822      Return Values: None
       
  5823 
       
  5824      Errors/Exceptions: None
       
  5825 
       
  5826      Status: Proposal
       
  5827     
       
  5828 -------------------------------------------------------------------------------
       
  5829 */
       
  5830 void CTestRunner::ReportLoopEndResultL( TInt aPassedIterations )
       
  5831     {
       
  5832     //If passlimit was given and number of passed test is less then expected, stop execution of scripter's test case
       
  5833     if( iPasslimitEnabled && ( aPassedIterations < iPasslimit ) )
       
  5834         {
       
  5835         __TRACE( KMessage, ( _L( "Loop has failed (passlimit). Finishing with KErrCompletion." ) ) );
       
  5836         iTestScripter->iPassLimitNotMet = ETrue;
       
  5837         iTestScripter->iResult.iResult = KErrCompletion;
       
  5838         iTestScripter->iResult.iResultDes = _L("Loop has not reached passlimit requirement.");
       
  5839         Cancel();
       
  5840         }
       
  5841     else if( iPasslimitEnabled && ( aPassedIterations >= iPasslimit ) )
       
  5842         {
       
  5843         __TRACE( KMessage, ( _L( "Loop has passed (passlimit)" ) ) );
       
  5844         }
       
  5845 
       
  5846     iPasslimit = 0;
       
  5847     iPasslimitEnabled = EFalse;    
       
  5848     }
       
  5849 
       
  5850 void CTestRunner::ReleaseRemoteResourcesAllocatedInLoopL()
       
  5851     {
       
  5852     RPointerArray<CSlave>& inLoopSlaves = iLoopHelper->GetRegisteredInLoopSlaves();
       
  5853     
       
  5854     for ( TInt i = 0; i < inLoopSlaves.Count(); i++ )
       
  5855         {
       
  5856         inLoopSlaves[ i ]->WaitForSubTestCasesL();
       
  5857     
       
  5858         RPointerArray<TEventTS>& slaveEvents = inLoopSlaves[ i ]->GetEvents();
       
  5859         for ( TInt k = 0; k < slaveEvents.Count(); k++ )
       
  5860             {
       
  5861             iSlavesManager->EventReleaseL( inLoopSlaves[ i ], slaveEvents[ k ]->Name() );
       
  5862             }
       
  5863         slaveEvents.ResetAndDestroy();
       
  5864         
       
  5865         iSlavesManager->SlaveFreeL( inLoopSlaves[ i ]->GetName() );
       
  5866         }
       
  5867     
       
  5868     inLoopSlaves.Reset();
       
  5869     }
       
  5870 
       
  5871 /*
       
  5872 -------------------------------------------------------------------------------
       
  5873 
       
  5874      Class: CTestRunner
       
  5875 
       
  5876      Method: IsFailedSubTestCaseReported
       
  5877 
       
  5878      Description: Gets information if there was reported executed sub test 
       
  5879                   case which failed.
       
  5880   
       
  5881      Parameters:    None
       
  5882      
       
  5883      Return Values: ETrue: test case was reported
       
  5884                     EFalse: test case was not reported
       
  5885 
       
  5886      Errors/Exceptions: None
       
  5887 
       
  5888      Status: Proposal
       
  5889     
       
  5890 -------------------------------------------------------------------------------
       
  5891 */
       
  5892 TBool CTestRunner::IsFailedSubTestCaseReported() const
       
  5893     {
       
  5894     return iFailedSubTestCaseReported;
       
  5895     }
       
  5896         
       
  5897 /*
       
  5898 -------------------------------------------------------------------------------
       
  5899 
       
  5900      Class: CTestRunner
       
  5901 
       
  5902      Method: GetFailedSubTestCaseResult
       
  5903 
       
  5904      Description: Returns first failed sub test case result.
       
  5905   
       
  5906      Parameters:    None
       
  5907      
       
  5908      Return Values: First failed sub test case result.
       
  5909 
       
  5910      Errors/Exceptions: None
       
  5911 
       
  5912      Status: Proposal
       
  5913     
       
  5914 -------------------------------------------------------------------------------
       
  5915 */
       
  5916 TFullTestResult CTestRunner::GetFailedSubTestCaseResult() const
       
  5917     {
       
  5918     return iFailedSubTestCaseResult;
       
  5919     }
       
  5920 
       
  5921 /*
       
  5922 -------------------------------------------------------------------------------
       
  5923 
       
  5924      Class: CTestRunner
       
  5925 
       
  5926      Method: GetFailedSubTestCaseInfo
       
  5927 
       
  5928      Description: Returns first failed sub test case info.
       
  5929   
       
  5930      Parameters:    None
       
  5931      
       
  5932      Return Values: First failed sub test case info.
       
  5933 
       
  5934      Errors/Exceptions: None
       
  5935 
       
  5936      Status: Proposal
       
  5937     
       
  5938 -------------------------------------------------------------------------------
       
  5939 */
       
  5940 const CStartInfo* CTestRunner::GetFailedSubTestCaseInfo() const
       
  5941     {
       
  5942     return iFailedSubTestCaseInfo;
       
  5943     }
       
  5944 
       
  5945 void CTestRunner::HandleRemoteReceiveError( TInt aError, const TDesC& aErrorDescription )
       
  5946     {
       
  5947     iTestScripter->UpdateTestCaseResult( aError, aErrorDescription );
       
  5948     CActiveScheduler::Current()->Stop();
       
  5949     }
       
  5950 
       
  5951 /*
       
  5952 -------------------------------------------------------------------------------
       
  5953 
       
  5954      Class: CTestRunner
       
  5955 
       
  5956      Method: ControlSubTestCaseL
       
  5957 
       
  5958      Description: Controls sub test case execution
       
  5959   
       
  5960      Parameters:    Sub test case id
       
  5961      
       
  5962      Return Values: ETrue: continue script file execution
       
  5963                     EFalse: stop script file execution
       
  5964 
       
  5965      Errors/Exceptions: None
       
  5966 
       
  5967      Status: Proposal
       
  5968     
       
  5969 -------------------------------------------------------------------------------
       
  5970 */
       
  5971 TBool CTestRunner::ControlSubTestCaseL( TTestKeywords::TKeywords aOperation, CStifItemParser* aItem )
       
  5972     {
       
  5973     _LIT( KErrMsgInvalidTestId, "testid is not specified or it has invalid value" );
       
  5974     _LIT( KErrMsgUnknownCall, "Unknown operation call on sub test case" );
       
  5975     
       
  5976     TPtrC subTestId;
       
  5977     TInt ret = aItem->GetNextString( subTestId );
       
  5978     if ( ret != KErrNone )
       
  5979         {
       
  5980         iRunErrorMessage = KErrMsgInvalidTestId;
       
  5981         User::Leave( KErrArgument );
       
  5982         }
       
  5983     
       
  5984     TInt subTestCasesCount = iSubTestCases.Count();
       
  5985     for ( TInt i = 0; i < subTestCasesCount; i++ )
       
  5986         {
       
  5987         if ( iSubTestCases[ i ]->GetStartInfo()->GetTestId() == subTestId )
       
  5988             {
       
  5989             switch ( aOperation )
       
  5990                 {
       
  5991                 case TTestKeywords::EPauseTest:
       
  5992                     {
       
  5993                     __TRACE( KMessage, ( _L( "Pause sub test case testid=%S" ), &subTestId ) );
       
  5994                     iSubTestCases[ i ]->PauseSubTestCaseL();
       
  5995                     }
       
  5996                     break;
       
  5997                 case TTestKeywords::EResume:
       
  5998                     {
       
  5999                     __TRACE( KMessage, ( _L( "Reasume sub test case testid=%S" ), &subTestId ) );
       
  6000                     iSubTestCases[ i ]->ResumeSubTestCaseL();
       
  6001                     }
       
  6002                     break;
       
  6003                 case TTestKeywords::ECancel:
       
  6004                     {
       
  6005                     __TRACE( KMessage, ( _L( "Cancel sub test case testid=%S" ), &subTestId ) );
       
  6006                     CSubTestCaseRunner* subTestCaseRunner = iSubTestCases[ i ];
       
  6007                     subTestCaseRunner->CancelSubTestCaseL();
       
  6008                     if ( subTestCaseRunner->GetType() == CSubTestCaseRunner::ESTTRemote )
       
  6009                         {
       
  6010                         CRemoteSubTestCaseRunner* remoteSubTestCaseRunner = 
       
  6011                                 (CRemoteSubTestCaseRunner*)subTestCaseRunner;
       
  6012                         CSlave* slave = remoteSubTestCaseRunner->GetSlave();
       
  6013                         slave->UnregisterSubTestCaseL( remoteSubTestCaseRunner );
       
  6014                         }
       
  6015                     if ( iLoopHelper->LoopInProgress() )
       
  6016                         {
       
  6017                         iLoopHelper->UnregisterInLoopSubTestCaseL( subTestCaseRunner );
       
  6018                         }
       
  6019                     delete iSubTestCases[ i ];
       
  6020                     iSubTestCases.Remove( i );
       
  6021                     }
       
  6022                     break;
       
  6023                 default:
       
  6024                     {
       
  6025                     iRunErrorMessage = KErrMsgUnknownCall;
       
  6026                     User::Leave( KErrArgument );
       
  6027                     }
       
  6028                     break;
       
  6029                 }
       
  6030             
       
  6031             return true;
       
  6032             }
       
  6033         }
       
  6034     
       
  6035     __TRACE( KMessage, ( _L( "Sub test case testid=%S not found" ), &subTestId ) );
       
  6036     RDebug::Print( _L( "Sub test case testid=%S not found" ), &subTestId );
       
  6037 
       
  6038     return true;
       
  6039     }
       
  6040 
       
  6041 /*
       
  6042 -------------------------------------------------------------------------------
       
  6043 
       
  6044      Class: CTestRunner
       
  6045 
       
  6046      Method: ExecuteLoopL
       
  6047 
       
  6048      Description: Executes loop keyword
       
  6049   
       
  6050      Parameters: CStifItemParser* aItem: in: script line
       
  6051      
       
  6052      Return Values: None
       
  6053 
       
  6054      Errors/Exceptions: None
       
  6055 
       
  6056      Status: Proposal
       
  6057     
       
  6058 -------------------------------------------------------------------------------
       
  6059 */
       
  6060 TBool CTestRunner::ExecuteLoopL( CStifItemParser* aItem )
       
  6061     {
       
  6062     _LIT( KErrMsgLoopNested, "Loop: Nested loop are not supported" );
       
  6063     _LIT( KErrMsgLoopNoParam, "Loop: No loop iterations count given or value has invalid format" );
       
  6064     _LIT( KErrMsgLoopInvalidParam, "Loop: Loop count must be >0" );
       
  6065     _LIT( KErrMsgLoopUnknownUnexpectedOption, "Loop: Unknown or unexpected loop option");
       
  6066     _LIT( KErrMsgLoopPasslimitInvalidValue, "Loop: No passlimit value given for loop or value has invalid format" );
       
  6067     _LIT( KErrMsgLoopPasslimitNotInRange, "Loop: Passlimit value is lower than 0 or higher than loop count" );
       
  6068     
       
  6069     if( iLoopTimes > 0 )
       
  6070         {
       
  6071         __TRACE( KError, (_L("ExecuteLineL: Nested loop are not supported")));
       
  6072         iRunErrorMessage = KErrMsgLoopNested;
       
  6073         User::Leave( KErrNotSupported );
       
  6074         }
       
  6075     
       
  6076     iLoopTimes = 0;
       
  6077     iLoopCounter = 0;
       
  6078     iTimedLoop = EFalse;
       
  6079     
       
  6080     if( aItem->GetNextInt( iLoopTimes ) != KErrNone )
       
  6081         {
       
  6082         __TRACE( KError, (_L("ExecuteLineL: No loop count value given for loop")));
       
  6083         iRunErrorMessage = KErrMsgLoopNoParam;
       
  6084         User::Leave( KErrArgument );
       
  6085         }
       
  6086     
       
  6087     if( iLoopTimes < 1 )
       
  6088         {
       
  6089         __TRACE( KError, (_L("ExecuteLineL: Loop count must be >0")));
       
  6090         iRunErrorMessage = KErrMsgLoopInvalidParam;
       
  6091         User::Leave( KErrArgument );
       
  6092         }
       
  6093     
       
  6094     __TRACE( KMessage, (_L("ExecuteLineL: Loop for %d times" ), iLoopTimes ) );
       
  6095     
       
  6096     //Check loop options
       
  6097     TPtrC option;
       
  6098     TInt ret = aItem->GetNextString(option);
       
  6099     if(ret == KErrNone)
       
  6100         {
       
  6101         if(option.Compare(_L("msec")) == 0) //time loop option
       
  6102             {
       
  6103             iTimedLoop = ETrue;
       
  6104             iStartTime.HomeTime();
       
  6105             iExpectedLoopTime = TInt64(iLoopTimes) * TInt64(1000); //convert to micro seconds
       
  6106             __TRACE(KMessage, (_L("ExecuteLineL: Timed loop for %d msec" ), iLoopTimes));
       
  6107             
       
  6108             ret = aItem->GetNextString(option); //Get next option
       
  6109             }
       
  6110         }
       
  6111         
       
  6112     if(ret == KErrNone)
       
  6113         {
       
  6114         if(option.Compare(_L("passlimit")) == 0) //passlimit option
       
  6115             {
       
  6116             iPasslimit = 0;
       
  6117             if( aItem->GetNextInt( iPasslimit ) != KErrNone )
       
  6118                 {
       
  6119                 __TRACE( KError, ( _L( "ExecuteLoopL: No passlimit value given for loop." ) ) );
       
  6120                 iRunErrorMessage = KErrMsgLoopPasslimitInvalidValue;
       
  6121                 User::Leave( KErrArgument );
       
  6122                 }
       
  6123             __TRACE( KMessage, ( _L( "ExecuteLoopL: Passlimit set on %d" ), iPasslimit ) );
       
  6124             //Check if passlimit has valid value
       
  6125             if(iPasslimit < 0 || (iPasslimit > iLoopTimes && !iTimedLoop))
       
  6126                 {
       
  6127                 __TRACE( KError, ( _L( "ExecuteLoopL: Passlimit value is lower than 0 or higher than loop count." ) ) );
       
  6128                 iRunErrorMessage = KErrMsgLoopPasslimitNotInRange;
       
  6129                 User::Leave( KErrArgument );
       
  6130                 }
       
  6131             iPasslimitEnabled = ETrue;
       
  6132 
       
  6133             ret = aItem->GetNextString(option); //Get next option
       
  6134             }
       
  6135         }    
       
  6136     
       
  6137     if(ret == KErrNone)
       
  6138         {
       
  6139         __TRACE( KError, (_L("ExecuteLineL: Unknown or unexpected loop option [%S]"), &option));
       
  6140         iRunErrorMessage = KErrMsgLoopUnknownUnexpectedOption;
       
  6141         User::Leave( KErrNotSupported );
       
  6142         }
       
  6143     
       
  6144     iLoopStartPos = iTestScripter->iCurrentParser->GetPosition();
       
  6145     
       
  6146     iLoopHelper->LoopStartL();
       
  6147     
       
  6148     return ETrue;
       
  6149     }
       
  6150 
       
  6151 /*
       
  6152 -------------------------------------------------------------------------------
       
  6153 
       
  6154      Class: CTestRunner
       
  6155 
       
  6156      Method: ExecuteEndLoopL
       
  6157 
       
  6158      Description: Executes endloop keyword
       
  6159   
       
  6160      Parameters: CStifItemParser* aItem: in: script line
       
  6161      
       
  6162      Return Values: None
       
  6163 
       
  6164      Errors/Exceptions: None
       
  6165 
       
  6166      Status: Proposal
       
  6167     
       
  6168 -------------------------------------------------------------------------------
       
  6169 */
       
  6170 TBool CTestRunner::ExecuteEndLoopL( CStifItemParser* /*aItem*/ )
       
  6171     {
       
  6172     _LIT( KErrMsgEndLoopNotOpened, "Endloop: Can't execute endloop. No opened loop exists" );
       
  6173 
       
  6174     if( iLoopTimes == 0 )
       
  6175         {
       
  6176         __TRACE( KError, (_L("ExecuteLineL: Can't execute endloop. No opened loop exists")));
       
  6177         iRunErrorMessage = KErrMsgEndLoopNotOpened;
       
  6178         User::Leave( KErrNotFound );
       
  6179         }
       
  6180     
       
  6181     iLoopCounter++;
       
  6182     __TRACE( KMessage, 
       
  6183         (_L("ExecuteLineL: Loop executed for %d times" ), 
       
  6184             iLoopCounter ) );
       
  6185 
       
  6186     TTime currTime;
       
  6187     currTime.HomeTime();
       
  6188     
       
  6189     if(((!iTimedLoop) && (iLoopCounter < iLoopTimes)) //Normal loop
       
  6190        ||
       
  6191        iTimedLoop && (currTime.MicroSecondsFrom(iStartTime) < iExpectedLoopTime)) //Timed loop
       
  6192         {
       
  6193         // Go to beginning of the loop
       
  6194         User::LeaveIfError(
       
  6195             iTestScripter->iCurrentParser->SetPosition( iLoopStartPos ));
       
  6196         iLoopHelper->IterationEndStartNextIterationL();
       
  6197         }
       
  6198     else
       
  6199         {            
       
  6200         // End looping
       
  6201         iLoopCounter = 0;
       
  6202         iLoopTimes = 0;
       
  6203         iLoopStartPos = 0;
       
  6204         
       
  6205         iLoopHelper->LoopEndL();
       
  6206         }
       
  6207     
       
  6208     // iLoopHelper will activate runner in proper moment
       
  6209     return EFalse;
       
  6210     }
       
  6211 
       
  6212 TBool CTestRunner::ExecuteAllocateL( CStifItemParser* aItem )
       
  6213     {
       
  6214     _LIT( KErrMsgAllocateSlaveTypeNotDefined, "Allocate : Slave type was not given for allocate" );
       
  6215     _LIT( KErrMsgAllocateSlaveNameNotDefined, "Allocate : Slave name is not defined" );
       
  6216     _LIT( KErrMsgAllocateSlaveAlreadyAllocated, "Allocate : Slave with name %S already allocated" );
       
  6217     __TRACE( KMessage, (_L("Allocate")));
       
  6218        
       
  6219     TPtrC type;
       
  6220     TPtrC name;
       
  6221     // Get slave type
       
  6222     TInt ret = aItem->GetNextString( type );
       
  6223     if( ret != KErrNone )
       
  6224         {
       
  6225         __TRACE( KError, (_L("Slave type was not given for allocate")));
       
  6226         iRunErrorMessage = KErrMsgAllocateSlaveTypeNotDefined;
       
  6227         User::Leave( KErrArgument );
       
  6228         }
       
  6229     
       
  6230     // Get slave name
       
  6231     ret = aItem->GetNextString( name );
       
  6232     if( ret != KErrNone )
       
  6233         {
       
  6234         __TRACE( KError, (_L("Slave name was not given for allocate")));
       
  6235         iRunErrorMessage = KErrMsgAllocateSlaveNameNotDefined;
       
  6236         User::Leave( KErrArgument );
       
  6237         }
       
  6238 
       
  6239     iTestScripter->TestModuleIf().Printf( KPrintPriExec, KExecute, 
       
  6240         _L("Allocate %S"), &name );
       
  6241         
       
  6242     __TRACE( KMessage, (_L("Allocate %S [name: %S]"), &type, &name));
       
  6243     
       
  6244     if( iSlavesManager->GetSlave( name ) )
       
  6245         {
       
  6246         __TRACE( KError, (_L("Slave with name %S already allocated"), 
       
  6247             &name ) );
       
  6248         iRunErrorMessage.Format( KErrMsgAllocateSlaveAlreadyAllocated, &name );
       
  6249         User::Leave( KErrAlreadyExists );
       
  6250         } 
       
  6251 
       
  6252     iSlavesManager->SlaveAllocateL( name, type );
       
  6253     
       
  6254     if ( iLoopHelper->LoopInProgress() )
       
  6255         {
       
  6256         CSlave* slave = iSlavesManager->GetSlave( name );
       
  6257         iLoopHelper->RegisterInLoopSlaveL( slave );
       
  6258         }
       
  6259     
       
  6260     return ETrue;    
       
  6261     }
       
  6262 
       
  6263 TBool CTestRunner::ExecuteFreeL( CStifItemParser* aItem )
       
  6264     {
       
  6265     _LIT( KErrMsgFreeSlaveNameNotDefined, "Free : Slave name is not defined" );
       
  6266     _LIT( KErrMsgFreeSlaveNotFound, "Free : Slave %S not found" );
       
  6267     __TRACE( KMessage, (_L("Free")));
       
  6268     
       
  6269     TPtrC name;    
       
  6270     // Get slave name
       
  6271     TInt ret = aItem->GetNextString( name );
       
  6272     if( ret != KErrNone )
       
  6273         {
       
  6274         __TRACE( KError, (_L("Slave name was not given for free")));
       
  6275         iRunErrorMessage = KErrMsgFreeSlaveNameNotDefined;
       
  6276         User::Leave( KErrArgument );
       
  6277         }
       
  6278 
       
  6279     iTestScripter->TestModuleIf().Printf( KPrintPriExec, KExecute, 
       
  6280         _L("Free %S"), &name );
       
  6281         
       
  6282     __TRACE( KMessage, (_L("Free %S"), &name ) );
       
  6283     
       
  6284     CSlave* slave = iSlavesManager->GetSlave( name );
       
  6285     if( slave == NULL )
       
  6286         {
       
  6287         __TRACE( KError, (_L("Slave %S not found"), &name ));
       
  6288         iRunErrorMessage.Format( KErrMsgFreeSlaveNotFound, &name );
       
  6289         User::Leave( KErrNotFound );
       
  6290         }
       
  6291     
       
  6292     if ( iLoopHelper->LoopInProgress() )
       
  6293         {        
       
  6294         iLoopHelper->UnregisterInLoopSlaveL( slave );
       
  6295         }
       
  6296     
       
  6297     if ( slave->HasRunningTestCases() )
       
  6298         {
       
  6299         slave->WaitForSubTestCasesL();
       
  6300         }
       
  6301     
       
  6302     iSlavesManager->SlaveFreeL( name );
       
  6303     
       
  6304     return ETrue;
       
  6305     }
       
  6306 
       
  6307 TBool CTestRunner::ExecuteRemoteL( CStifItemParser* aItem )
       
  6308     {
       
  6309     _LIT( KErrMsgRemoteSlaveNameNotDefined, "Remote : Slave name is not defined" );
       
  6310     _LIT( KErrMsgRemoteSlaveNotFound, "Remore : Slave %S not found" );
       
  6311     _LIT( KErrMsgRemoteCommandNotDefined, "Slave command name was not given for remote" );
       
  6312 
       
  6313     TPtrC name;
       
  6314     TPtrC command;    
       
  6315     
       
  6316     // Get slave name
       
  6317     TInt ret = aItem->GetNextString( name );
       
  6318     if( ret != KErrNone )
       
  6319         {
       
  6320         __TRACE( KError, (_L("Slave name was not given for remote")));
       
  6321         iRunErrorMessage = KErrMsgRemoteSlaveNameNotDefined;
       
  6322         User::Leave( KErrArgument );
       
  6323         }
       
  6324         
       
  6325     __TRACE( KMessage, (_L("Remote command to %S"), &name));
       
  6326     
       
  6327     CSlave* slave = iSlavesManager->GetSlave( name );
       
  6328     if( slave == NULL )
       
  6329         {
       
  6330         __TRACE( KError, (_L("Slave %S not found"), &name ));
       
  6331         iRunErrorMessage.Format( KErrMsgRemoteSlaveNotFound, &name );
       
  6332         User::Leave( KErrArgument );
       
  6333         }
       
  6334         
       
  6335     // Get remote command name
       
  6336     ret = aItem->GetNextString( command );
       
  6337     if( ret != KErrNone )
       
  6338         {
       
  6339         __TRACE( KError, (_L("Slave command name was not given for remote")));
       
  6340         iRunErrorMessage = KErrMsgRemoteCommandNotDefined;
       
  6341         User::Leave( KErrArgument );
       
  6342         }
       
  6343 
       
  6344     iTestScripter->TestModuleIf().Printf( KPrintPriExec, KExecute, 
       
  6345         _L("remote %S %S"), &name, &command );
       
  6346 
       
  6347     __TRACE( KPrint, (_L("remote %S %S"), &name, &command ) );
       
  6348 
       
  6349     // Parse command name
       
  6350     TInt key = TTestKeywords::Parse( command, TTestKeywords::Keyword );    
       
  6351     TBool continueTask = ETrue;
       
  6352     
       
  6353     switch( key )
       
  6354         {
       
  6355         // Test case starting
       
  6356         case TTestKeywords::ERun:
       
  6357             continueTask = ExecuteRemoteRunL( aItem, slave );
       
  6358             break;
       
  6359                    
       
  6360         // Event control cases
       
  6361         case TTestKeywords::ERequest:
       
  6362         case TTestKeywords::EWait:
       
  6363         case TTestKeywords::ERelease:
       
  6364         case TTestKeywords::ESet:
       
  6365         case TTestKeywords::EUnset:
       
  6366             continueTask = ExecuteRemoteEventCtlL( aItem, slave, key );
       
  6367             break;
       
  6368         // asynchronous 'sendreceive'
       
  6369         case TTestKeywords::ESendReceive:
       
  6370             continueTask = ExecuteRemoteSendReceiveL( aItem, slave );
       
  6371             break;
       
  6372 
       
  6373         default:
       
  6374             // Some unknown remote command, forward as such 
       
  6375             continueTask = ExecuteRemoteUnknownL( aItem, slave, command );
       
  6376             break;
       
  6377         }
       
  6378     
       
  6379     return continueTask;    
       
  6380     }
       
  6381 
       
  6382 
       
  6383 TBool CTestRunner::ExecuteRemoteRunL( CStifItemParser* aItem, CSlave* aSlave,
       
  6384                          HBufC *aSetUnsetEvent,
       
  6385                          TInt aCaseNumber )
       
  6386     {
       
  6387     CStartInfo* startInfo = CStartInfo::NewL();
       
  6388     CleanupStack::PushL( startInfo );
       
  6389     //if aSetUnsetEvent is given, then get start info from this argument
       
  6390     if( aSetUnsetEvent != NULL )
       
  6391         {
       
  6392         TBuf<10> tmpModuleName;
       
  6393         tmpModuleName.Copy( _L( "suevent" ) );
       
  6394         startInfo->SetModuleNameL( tmpModuleName );
       
  6395         startInfo->SetConfigL( *aSetUnsetEvent );
       
  6396         startInfo->SetTestCaseNumber( aCaseNumber );
       
  6397         }
       
  6398     else
       
  6399         {
       
  6400         ParseRunParamsL( aItem, *startInfo );   
       
  6401         }
       
  6402 
       
  6403     CRemoteSubTestCaseRunner* remoteSubTestCase = CRemoteSubTestCaseRunner::NewL( 
       
  6404             this, 
       
  6405             aSlave, 
       
  6406             iSlavesManager->GetRemoteCallsProxy() );
       
  6407     CleanupStack::PushL( remoteSubTestCase );
       
  6408 
       
  6409     __TRACE( KMessage, ( _L( "Executing sub test case: module=%S cfg=%S tcnum=%d id=%S" ),
       
  6410          &startInfo->GetModuleName(), &startInfo->GetConfig(), 
       
  6411          startInfo->GetTestCaseNumber(), &startInfo->GetTestId()) );
       
  6412 
       
  6413     RDebug::Print( _L( "Executing sub test case: module=%S cfg=%S tcnum=%d id=%S" ),
       
  6414             &startInfo->GetModuleName(), &startInfo->GetConfig(), 
       
  6415             startInfo->GetTestCaseNumber(), &startInfo->GetTestId() );
       
  6416     
       
  6417     remoteSubTestCase->RunSubTestCaseL( *startInfo );
       
  6418     iSubTestCases.AppendL( remoteSubTestCase );
       
  6419     if ( iLoopHelper->LoopInProgress() )
       
  6420         {
       
  6421         iLoopHelper->RegisterInLoopSubTestCaseL( remoteSubTestCase );
       
  6422         }
       
  6423     
       
  6424     CleanupStack::Pop( remoteSubTestCase );
       
  6425     
       
  6426     iRunErrorMessage = KNullDesC;
       
  6427     
       
  6428     CleanupStack::PopAndDestroy( startInfo );    
       
  6429 
       
  6430     return ETrue;    
       
  6431     }
       
  6432 
       
  6433 TBool CTestRunner::ExecuteRemoteEventCtlL( CStifItemParser* aItem, 
       
  6434                               CSlave* aSlave, 
       
  6435                               TInt aCmd  )
       
  6436     {
       
  6437     TPtrC eventName;
       
  6438     // Get event name
       
  6439     TInt ret = aItem->GetNextString( eventName );
       
  6440     if( ret != KErrNone )
       
  6441         {
       
  6442         __TRACE( KError, (_L("Event name was not given for remote")));
       
  6443         User::Leave( KErrArgument );
       
  6444         }
       
  6445     
       
  6446     TBool continueTask = ETrue;
       
  6447     switch( aCmd )
       
  6448         {       
       
  6449         // Event control cases
       
  6450         case TTestKeywords::ERequest:
       
  6451             {
       
  6452             TEventTS* event = aSlave->GetEvent( eventName );
       
  6453             if( event != NULL )
       
  6454                 {
       
  6455                 __TRACE( KError, (_L("Event %S already requested"), 
       
  6456                     &eventName  ) );
       
  6457                 User::Leave( KErrNotFound );
       
  6458                 }
       
  6459             event = new( ELeave ) TEventTS( (TName&)eventName );
       
  6460             CleanupStack::PushL( event );
       
  6461             iSlavesManager->EventRequestL( aSlave, event );
       
  6462             aSlave->AddEventL( event );
       
  6463             CleanupStack::Pop( event );
       
  6464             }
       
  6465             break;
       
  6466         case TTestKeywords::ERelease:
       
  6467             {
       
  6468             TEventTS* event = aSlave->GetEvent( eventName );            
       
  6469             if( event == NULL )
       
  6470                 {
       
  6471                 __TRACE( KError, (_L("Event not found %S"), 
       
  6472                     &eventName  ) );
       
  6473                 User::Leave( KErrNotFound );
       
  6474                 }
       
  6475                                                   
       
  6476             aSlave->RemoveEventL( event );
       
  6477             delete event;
       
  6478             // Release event
       
  6479             iSlavesManager->EventReleaseL( aSlave, eventName );
       
  6480             }
       
  6481             break;
       
  6482         case TTestKeywords::EWait:
       
  6483             {
       
  6484             TEventTS* event = aSlave->GetEvent( eventName );
       
  6485             if( event == NULL )
       
  6486                 {
       
  6487                 __TRACE( KError, (_L("Waited event %S not requested"), 
       
  6488                     &eventName  ) );
       
  6489                 User::Leave( KErrNotFound );
       
  6490                 }
       
  6491             
       
  6492             iState = ERunnerRunning;
       
  6493             SetActive();
       
  6494             event->WaitEvent( iStatus );
       
  6495             // Execution continue if waited event is set or after it is set       
       
  6496             continueTask = EFalse;            
       
  6497             }
       
  6498             break;
       
  6499         case TTestKeywords::ESet:
       
  6500             {
       
  6501             TPtrC optParam;
       
  6502             ret = aItem->GetNextString( optParam );
       
  6503             TEventIf::TEventType eventType = TEventIf::EIndication;
       
  6504             if( ret == KErrNone )
       
  6505                 {
       
  6506                 if ( optParam != _L("state") )
       
  6507                     {
       
  6508                     __TRACE( KError, (_L("Invalid optional argument")));
       
  6509                     User::Leave( KErrArgument );
       
  6510                     }
       
  6511                 eventType = TEventIf::EState;
       
  6512                 }
       
  6513             iSlavesManager->EventSetL( aSlave, eventName, eventType );
       
  6514             }            
       
  6515             break;
       
  6516         case TTestKeywords::EUnset:
       
  6517             {
       
  6518             iSlavesManager->EventUnsetL( aSlave, eventName );
       
  6519             }
       
  6520             break;            
       
  6521         default:
       
  6522              // Should never come here
       
  6523             User::Leave( KErrGeneral );            
       
  6524         }
       
  6525             
       
  6526     return continueTask;
       
  6527     }
       
  6528 
       
  6529 TBool CTestRunner::ExecuteRemoteSendReceiveL( CStifItemParser* aItem, 
       
  6530                               CSlave* aSlave )
       
  6531     {
       
  6532     TPtrC message;
       
  6533     aItem->Remainder( message );
       
  6534     
       
  6535     iSlavesManager->SendReceiveL( aSlave, message );
       
  6536     return ETrue;
       
  6537     }
       
  6538 
       
  6539 TBool CTestRunner::ExecuteRemoteUnknownL( CStifItemParser* aItem, 
       
  6540                              CSlave* aSlave,
       
  6541                              TDesC& aCommand )
       
  6542     {
       
  6543     TPtrC message;
       
  6544     aItem->Remainder( message );
       
  6545     
       
  6546     iSlavesManager->SendUnknownL( aSlave, aCommand, message );
       
  6547     return ETrue;
       
  6548     }
       
  6549 
       
  6550 /*
       
  6551 -------------------------------------------------------------------------------
       
  6552 
       
  6553     DESCRIPTION
       
  6554 
       
  6555     This module contains the implementation of CTestContinue class
       
  6556     member functions. CTestContinue handles ContinueScript calls from 
       
  6557     TestScripter.
       
  6558 
       
  6559 -------------------------------------------------------------------------------
       
  6560 */
       
  6561 // MACROS
       
  6562 #ifdef LOGGER
       
  6563 #undef LOGGER
       
  6564 #endif
       
  6565 #define LOGGER iTestScripter->iLog
       
  6566 
       
  6567 // ================= MEMBER FUNCTIONS =========================================
       
  6568 
       
  6569 /*
       
  6570 -------------------------------------------------------------------------------
       
  6571 
       
  6572      Class: CTestContinue
       
  6573 
       
  6574      Method: CTestContinue
       
  6575 
       
  6576      Description: Default constructor
       
  6577 
       
  6578      Parameters: CTestRunner* aTestRunner: in: Backpointer to CTestRunner
       
  6579 
       
  6580      Return Values: None
       
  6581 
       
  6582      Errors/Exceptions: None
       
  6583 
       
  6584      Status: Draft
       
  6585     
       
  6586 -------------------------------------------------------------------------------
       
  6587 */
       
  6588 CTestContinue::CTestContinue( CTestScripter* aTestScripter,
       
  6589                               TTestObject* aObject ): 
       
  6590     // Executed with lowest priority, must be lower than CTesRunner priority 
       
  6591     CActive(  CActive::EPriorityLow ),
       
  6592     iTestScripter( aTestScripter ),
       
  6593     iObject( aObject )
       
  6594     {
       
  6595     CActiveScheduler::Add( this );
       
  6596     __TRACEFUNC();
       
  6597     
       
  6598     }
       
  6599 
       
  6600 /*
       
  6601 -------------------------------------------------------------------------------
       
  6602 
       
  6603      Class: CTestContinue
       
  6604 
       
  6605      Method: ConstructL
       
  6606 
       
  6607      Description: Symbian OS second phase constructor
       
  6608 
       
  6609      Parameters:    None
       
  6610 
       
  6611      Return Values: None
       
  6612 
       
  6613      Errors/Exceptions: None
       
  6614 
       
  6615      Status: Draft
       
  6616     
       
  6617 -------------------------------------------------------------------------------
       
  6618 */
       
  6619 void CTestContinue::ConstructL()
       
  6620     {
       
  6621     
       
  6622     iObject->iScript->EnableSignal( iStatus );
       
  6623     SetActive();
       
  6624     
       
  6625     }
       
  6626 
       
  6627 /*
       
  6628 -------------------------------------------------------------------------------
       
  6629 
       
  6630      Class: CTestContinue
       
  6631 
       
  6632      Method: NewL
       
  6633 
       
  6634      Description: Two-phased constructor.
       
  6635           
       
  6636      Parameters: CTestRunner* aTestRunner: in: Backpointer to CTestRunner
       
  6637 
       
  6638      Return Values: CTestContinue*: new object
       
  6639 
       
  6640      Errors/Exceptions: Leaves if new or ConstructL leaves
       
  6641 
       
  6642      Status: Draft
       
  6643     
       
  6644 -------------------------------------------------------------------------------
       
  6645 */
       
  6646 
       
  6647 CTestContinue* CTestContinue::NewL( CTestScripter* aTestScripter,
       
  6648                                     TTestObject* aObject )
       
  6649     {
       
  6650     CTestContinue* self = 
       
  6651         new (ELeave) CTestContinue( aTestScripter, aObject );
       
  6652      
       
  6653     CleanupStack::PushL( self );
       
  6654     self->ConstructL();
       
  6655     CleanupStack::Pop();
       
  6656 
       
  6657     return self;
       
  6658     }
       
  6659 
       
  6660 /*
       
  6661 -------------------------------------------------------------------------------
       
  6662 
       
  6663      Class: CTestContinue
       
  6664 
       
  6665      Method: ~CTestContinue
       
  6666 
       
  6667      Description: Destructor
       
  6668      
       
  6669      Parameters:    None
       
  6670 
       
  6671      Return Values: None
       
  6672 
       
  6673      Errors/Exceptions: None
       
  6674 
       
  6675      Status: Draft
       
  6676     
       
  6677 -------------------------------------------------------------------------------
       
  6678 */     
       
  6679 
       
  6680 CTestContinue::~CTestContinue()
       
  6681     {
       
  6682     __TRACEFUNC();
       
  6683     Cancel();
       
  6684     
       
  6685     }
       
  6686 
       
  6687 /*
       
  6688 -------------------------------------------------------------------------------
       
  6689 
       
  6690      Class: CTestContinue
       
  6691 
       
  6692      Method: RunL
       
  6693 
       
  6694      Description: Derived from CActive, handles testcase execution.
       
  6695 
       
  6696      Parameters:    None.
       
  6697 
       
  6698      Return Values: None.
       
  6699 
       
  6700      Errors/Exceptions: Leaves on error situations.
       
  6701 
       
  6702      Status: Draft
       
  6703     
       
  6704 -------------------------------------------------------------------------------
       
  6705 */
       
  6706 void CTestContinue::RunL()
       
  6707     {
       
  6708 
       
  6709     __TRACEFUNC();
       
  6710     __TRACE( KMessage, (_L("CTestContinue::RunL: [%d] "), iStatus.Int() ));
       
  6711 
       
  6712     if( iObject->Signal() ) 
       
  6713         {
       
  6714         // If OOM testing is ongoing ignore result check(given by user).
       
  6715         if( !iTestScripter->iOOMIgnoreFailure )
       
  6716             {
       
  6717             // Erronous case RunError will called and test handling continue 
       
  6718             // from there.
       
  6719             if( iTestScripter->TestRunner().TestCaseResults().Count() == 0 )
       
  6720                 {
       
  6721                 // KErrNone is the default result expected 
       
  6722                 // if nothing else is given 
       
  6723                 User::LeaveIfError( iTestScripter->TestRunner().
       
  6724                     TestCaseResults().Append( KErrNone ) );
       
  6725                 }
       
  6726             
       
  6727             if( iTestScripter->TestRunner().TestCaseResults().
       
  6728                     Find( iStatus.Int() ) < 0 ) 
       
  6729                 {
       
  6730                 __TRACE( KError, ( _L("Command for [%S] failed (%d)"), 
       
  6731                     &iObject->ObjectId(), iStatus.Int() ));
       
  6732 
       
  6733 
       
  6734                 if( iStatus.Int() == KErrNone )
       
  6735                     {
       
  6736                     User::Leave( KErrGeneral );
       
  6737                     }
       
  6738                 else
       
  6739                     {
       
  6740                     User::Leave( iStatus.Int() );
       
  6741                     }
       
  6742                 }
       
  6743             }
       
  6744         else
       
  6745             {
       
  6746             __TRACE( KMessage, ( 
       
  6747                 _L( "OOM test: 'oomignorefailure' is ON, signal result[%d] ignored" ),
       
  6748                 iStatus.Int() ));
       
  6749             }
       
  6750 
       
  6751         iTestScripter->TestRunner().TestCaseResults().Reset();
       
  6752         
       
  6753          __TRACE( KMessage, (_L("CTestContinue::RunL: Set runner active ")));
       
  6754         iTestScripter->iTestRunner->SetRunnerActive();   
       
  6755         }
       
  6756     else
       
  6757         {
       
  6758         // Signal called from test side but 'waittestclass' not yet processed
       
  6759         iObject->iAsyncResult = iStatus.Int();
       
  6760         }        
       
  6761         
       
  6762     iObject->iScript->EnableSignal( iStatus );
       
  6763     SetActive();
       
  6764     
       
  6765     }
       
  6766      
       
  6767 /*
       
  6768 -------------------------------------------------------------------------------
       
  6769 
       
  6770      Class: CTestContinue
       
  6771 
       
  6772      Method: DoCancel
       
  6773 
       
  6774      Description: Derived from CActive handles the Cancel
       
  6775 
       
  6776      Parameters:    None.
       
  6777 
       
  6778      Return Values: None.
       
  6779 
       
  6780      Errors/Exceptions: None.
       
  6781 
       
  6782      Status: Draft
       
  6783     
       
  6784 -------------------------------------------------------------------------------
       
  6785 */
       
  6786 void CTestContinue::DoCancel()
       
  6787     {
       
  6788 
       
  6789     __TRACEFUNC();
       
  6790     __TRACE( KMessage, (_L("CTestContinue::DoCancel")));
       
  6791 
       
  6792     iObject->iScript->CancelSignal();
       
  6793     
       
  6794     }
       
  6795 
       
  6796 /*
       
  6797 -------------------------------------------------------------------------------
       
  6798 
       
  6799      Class: CTestContinue
       
  6800 
       
  6801      Method: RunError
       
  6802 
       
  6803      Description: Derived from CActive handles the Cancel
       
  6804 
       
  6805      Parameters:    None.
       
  6806 
       
  6807      Return Values: None.
       
  6808 
       
  6809      Errors/Exceptions: None.
       
  6810 
       
  6811      Status: Draft
       
  6812     
       
  6813 -------------------------------------------------------------------------------
       
  6814 */
       
  6815 TInt CTestContinue::RunError( TInt aError )
       
  6816     {
       
  6817 
       
  6818     // Return error from here, if none given from execution
       
  6819     if( iTestScripter->iResult.iResult == KErrNone )
       
  6820         {
       
  6821         iTestScripter->UpdateTestCaseResult(aError, _L("CTestContinue::RunError"));
       
  6822         }
       
  6823     CActiveScheduler::Current()->Stop();
       
  6824      
       
  6825     return KErrNone;
       
  6826     
       
  6827     }
       
  6828     
       
  6829 /*
       
  6830 -------------------------------------------------------------------------------
       
  6831 
       
  6832     DESCRIPTION
       
  6833 
       
  6834     This module contains the implementation of CDefinedValue class
       
  6835     member functions. 
       
  6836 -------------------------------------------------------------------------------
       
  6837 */
       
  6838 
       
  6839 // ================= MEMBER FUNCTIONS =========================================
       
  6840 /*
       
  6841 -------------------------------------------------------------------------------
       
  6842 
       
  6843      Class: CDefinedValue
       
  6844 
       
  6845      Method: CDefinedValue
       
  6846 
       
  6847      Description: Default constructor
       
  6848 
       
  6849      C++ default constructor can NOT contain any code, that
       
  6850      might leave.
       
  6851      
       
  6852      Parameters: None
       
  6853 
       
  6854      Return Values: None
       
  6855 
       
  6856      Errors/Exceptions: None
       
  6857 
       
  6858      Status: Draft
       
  6859     
       
  6860 -------------------------------------------------------------------------------
       
  6861 */
       
  6862 CDefinedValue::CDefinedValue()
       
  6863     {
       
  6864     }
       
  6865      
       
  6866 /*
       
  6867 -------------------------------------------------------------------------------
       
  6868 
       
  6869      Class: CDefinedValue
       
  6870 
       
  6871      Method: ConstructL
       
  6872 
       
  6873      Description: Symbian OS second phase constructor
       
  6874 
       
  6875      Symbian OS default constructor can leave.
       
  6876 
       
  6877      Parameters:    TDesC& aName: in: Define name
       
  6878                     TDesC& aValue: in: Define value
       
  6879 
       
  6880      Return Values: None
       
  6881 
       
  6882      Errors/Exceptions: None
       
  6883 
       
  6884      Status: Draft
       
  6885     
       
  6886 -------------------------------------------------------------------------------
       
  6887 */
       
  6888 void CDefinedValue::ConstructL( TDesC& aName, TDesC& aValue )
       
  6889     {    
       
  6890 
       
  6891     iNameBuf = aName.AllocLC();
       
  6892     iName.Set( iNameBuf->Des() );
       
  6893     iValueBuf = aValue.AllocLC();
       
  6894     iValue.Set( iValueBuf->Des() );
       
  6895     CleanupStack::Pop( iValueBuf );
       
  6896     CleanupStack::Pop( iNameBuf );
       
  6897 
       
  6898     }
       
  6899 
       
  6900 /*
       
  6901 -------------------------------------------------------------------------------
       
  6902 
       
  6903      Class: CDefinedValue
       
  6904 
       
  6905      Method: NewL
       
  6906 
       
  6907      Description: Two-phased constructor.
       
  6908           
       
  6909      Parameters:    TDesC& aName: in: Define name
       
  6910                     TDesC& aValue: in: Define value
       
  6911 
       
  6912      Return Values: CDefinedValue*: new object
       
  6913 
       
  6914      Errors/Exceptions: Leaves if new or ConstructL leaves.
       
  6915 
       
  6916      Status: Draft
       
  6917     
       
  6918 -------------------------------------------------------------------------------
       
  6919 */
       
  6920 CDefinedValue* CDefinedValue::NewL( TDesC& aName, TDesC& aValue )
       
  6921     {
       
  6922 
       
  6923     CDefinedValue* self = new (ELeave) CDefinedValue();
       
  6924      
       
  6925     CleanupStack::PushL( self );
       
  6926     self->ConstructL( aName, aValue );
       
  6927     CleanupStack::Pop();
       
  6928 
       
  6929     return self;
       
  6930 
       
  6931     }    
       
  6932     
       
  6933 /*
       
  6934 -------------------------------------------------------------------------------
       
  6935 
       
  6936      Class: CDefinedValue
       
  6937 
       
  6938      Method: ~CDefinedValue
       
  6939 
       
  6940      Description: Destructor
       
  6941      
       
  6942      Parameters:    None
       
  6943 
       
  6944      Return Values: None
       
  6945 
       
  6946      Errors/Exceptions: None
       
  6947 
       
  6948      Status: Draft
       
  6949     
       
  6950 -------------------------------------------------------------------------------
       
  6951 */     
       
  6952 CDefinedValue::~CDefinedValue()
       
  6953     {
       
  6954     
       
  6955     delete iValueBuf;
       
  6956     delete iNameBuf;
       
  6957     
       
  6958     }
       
  6959     
       
  6960 /*
       
  6961 -------------------------------------------------------------------------------
       
  6962 
       
  6963      Class: CDefinedValue
       
  6964 
       
  6965      Method: SetValueL
       
  6966 
       
  6967      Description: Set new define value
       
  6968 
       
  6969      Parameters:    TDesC& aValue: in: Define value
       
  6970 
       
  6971      Return Values: None
       
  6972 
       
  6973      Errors/Exceptions: Leaves on error.
       
  6974 
       
  6975      Status: Draft
       
  6976     
       
  6977 -------------------------------------------------------------------------------
       
  6978 */
       
  6979 void CDefinedValue::SetValueL( TDesC& aValue )
       
  6980     {
       
  6981     delete iValueBuf;
       
  6982     iValueBuf = 0;
       
  6983     iValueBuf = aValue.AllocLC();
       
  6984     iValue.Set( iValueBuf->Des() );
       
  6985     CleanupStack::Pop( iValueBuf );
       
  6986     
       
  6987     }
       
  6988 
       
  6989     
       
  6990 /*
       
  6991 -------------------------------------------------------------------------------
       
  6992 
       
  6993      Class: CDefinedValue
       
  6994 
       
  6995      Method: Name
       
  6996 
       
  6997      Description: Returns define name.
       
  6998 
       
  6999      Parameters:  None
       
  7000 
       
  7001      Return Values: TDesC: Define name
       
  7002 
       
  7003      Errors/Exceptions: None
       
  7004 
       
  7005      Status: Draft
       
  7006     
       
  7007 -------------------------------------------------------------------------------
       
  7008 */
       
  7009 TDesC& CDefinedValue::Name()
       
  7010     { 
       
  7011     return iName; 
       
  7012     }
       
  7013         
       
  7014 /*
       
  7015 -------------------------------------------------------------------------------
       
  7016 
       
  7017      Class: CDefinedValue
       
  7018 
       
  7019      Method: Value
       
  7020 
       
  7021      Description: Returns define value.
       
  7022 
       
  7023      Parameters:  None
       
  7024 
       
  7025      Return Values: TDesC: Define value
       
  7026 
       
  7027      Errors/Exceptions: None
       
  7028 
       
  7029      Status: Draft
       
  7030     
       
  7031 -------------------------------------------------------------------------------
       
  7032 */
       
  7033 TDesC& CDefinedValue::Value()
       
  7034     { 
       
  7035     return iValue; 
       
  7036     }
       
  7037     
       
  7038 
       
  7039 /*
       
  7040 -------------------------------------------------------------------------------
       
  7041 
       
  7042     DESCRIPTION
       
  7043 
       
  7044     This module contains the implementation of TTestObjectBase class
       
  7045     member functions. 
       
  7046 -------------------------------------------------------------------------------
       
  7047 */
       
  7048 
       
  7049 // ================= MEMBER FUNCTIONS =========================================
       
  7050 /*
       
  7051 -------------------------------------------------------------------------------
       
  7052 
       
  7053      Class: TTestObjectBase
       
  7054 
       
  7055      Method: TTestObjectBase
       
  7056 
       
  7057      Description: Constructor
       
  7058 
       
  7059      Parameters: None
       
  7060 
       
  7061      Return Values: None
       
  7062 
       
  7063      Errors/Exceptions: None
       
  7064 
       
  7065      Status: Draft
       
  7066     
       
  7067 -------------------------------------------------------------------------------
       
  7068 */    
       
  7069 TTestObjectBase::TTestObjectBase( TObjectType aType ) : 
       
  7070     iAsyncResult( KErrNone ),
       
  7071     iType( aType )
       
  7072     {
       
  7073     
       
  7074     RDebug::Print( _L("TTestObjectBase::TTestObjectBase") );
       
  7075     iName.Zero(); 
       
  7076     
       
  7077     }
       
  7078     
       
  7079     /*
       
  7080 -------------------------------------------------------------------------------
       
  7081 
       
  7082      Class: TTestObjectBase
       
  7083 
       
  7084      Method: ~TTestObjectBase
       
  7085 
       
  7086      Description: Destructor
       
  7087 
       
  7088      Parameters: None
       
  7089 
       
  7090      Return Values: None
       
  7091 
       
  7092      Errors/Exceptions: None
       
  7093 
       
  7094      Status: Draft
       
  7095     
       
  7096 -------------------------------------------------------------------------------
       
  7097 */    
       
  7098 TTestObjectBase::~TTestObjectBase()
       
  7099     {
       
  7100     
       
  7101     RDebug::Print( _L("TTestObjectBase::~TTestObjectBase") );
       
  7102 
       
  7103     }
       
  7104 
       
  7105 /*
       
  7106 -------------------------------------------------------------------------------
       
  7107 
       
  7108     DESCRIPTION
       
  7109 
       
  7110     This module contains the implementation of TTestObject class
       
  7111     member functions. 
       
  7112 -------------------------------------------------------------------------------
       
  7113 */
       
  7114 // ================= MEMBER FUNCTIONS =========================================
       
  7115 
       
  7116 /*
       
  7117 -------------------------------------------------------------------------------
       
  7118 
       
  7119      Class: TTestObject
       
  7120 
       
  7121      Method: TTestObject
       
  7122 
       
  7123      Description: Constructor
       
  7124 
       
  7125      Parameters: None
       
  7126 
       
  7127      Return Values: None
       
  7128 
       
  7129      Errors/Exceptions: None
       
  7130 
       
  7131      Status: Draft
       
  7132     
       
  7133 -------------------------------------------------------------------------------
       
  7134 */    
       
  7135 TTestObject::TTestObject() :
       
  7136     TTestObjectBase( EObjectNormal ),
       
  7137     iContinue(0),
       
  7138     iCount(0)
       
  7139     {
       
  7140     iScript = 0;
       
  7141     RDebug::Print( _L("TTestObject::TTestObject") );
       
  7142 
       
  7143     }
       
  7144 
       
  7145 /*
       
  7146 -------------------------------------------------------------------------------
       
  7147 
       
  7148      Class: TTestObject
       
  7149 
       
  7150      Method: ~TTestObject
       
  7151 
       
  7152      Description: Destructor
       
  7153 
       
  7154      Parameters: None
       
  7155 
       
  7156      Return Values: None
       
  7157 
       
  7158      Errors/Exceptions: None
       
  7159 
       
  7160      Status: Draft
       
  7161     
       
  7162 -------------------------------------------------------------------------------
       
  7163 */
       
  7164 TTestObject::~TTestObject()
       
  7165     { 
       
  7166     
       
  7167     RDebug::Print( _L("TTestObject::~TTestObject") );
       
  7168     delete iContinue;
       
  7169     iContinue = 0;
       
  7170 
       
  7171     }
       
  7172         
       
  7173 /*
       
  7174 -------------------------------------------------------------------------------
       
  7175 
       
  7176      Class: TTestObject
       
  7177 
       
  7178      Method: RunMethodL
       
  7179 
       
  7180      Description: Run specified method from testclass.
       
  7181 
       
  7182      Parameters: CStifItemParser* aItem: in: itemparser
       
  7183 
       
  7184      Return Values: Symbian OS error code
       
  7185 
       
  7186      Errors/Exceptions: None
       
  7187 
       
  7188      Status: Draft
       
  7189     
       
  7190 -------------------------------------------------------------------------------
       
  7191 */
       
  7192 TInt TTestObject::RunMethodL( CStifItemParser& aItem )
       
  7193     { 
       
  7194     
       
  7195     return iScript->RunMethodL( aItem ); 
       
  7196     
       
  7197     }
       
  7198     
       
  7199 /*
       
  7200 -------------------------------------------------------------------------------
       
  7201 
       
  7202     DESCRIPTION
       
  7203 
       
  7204     This module contains the implementation of TTestObjectKernel class
       
  7205     member functions. 
       
  7206 -------------------------------------------------------------------------------
       
  7207 */
       
  7208 // ================= MEMBER FUNCTIONS =========================================
       
  7209 
       
  7210 
       
  7211 /*
       
  7212 -------------------------------------------------------------------------------
       
  7213 
       
  7214      Class: TTestObjectKernel
       
  7215 
       
  7216      Method: TTestObjectKernel
       
  7217 
       
  7218      Description: Constructor
       
  7219 
       
  7220      Parameters: None
       
  7221 
       
  7222      Return Values: None
       
  7223 
       
  7224      Errors/Exceptions: None
       
  7225 
       
  7226      Status: Draft
       
  7227     
       
  7228 -------------------------------------------------------------------------------
       
  7229 */    
       
  7230 TTestObjectKernel::TTestObjectKernel() : 
       
  7231     TTestObjectBase( EObjectKernel )
       
  7232     {
       
  7233     
       
  7234     RDebug::Print( _L("TTestObjectKernel::TTestObjectKernel") );
       
  7235     
       
  7236     }
       
  7237     
       
  7238 /*
       
  7239 -------------------------------------------------------------------------------
       
  7240 
       
  7241      Class: TTestObjectKernel
       
  7242 
       
  7243      Method: ~TTestObjectKernel
       
  7244 
       
  7245      Description: Destructor
       
  7246 
       
  7247      Parameters: None
       
  7248 
       
  7249      Return Values: None
       
  7250 
       
  7251      Errors/Exceptions: None
       
  7252 
       
  7253      Status: Draft
       
  7254     
       
  7255 -------------------------------------------------------------------------------
       
  7256 */
       
  7257 TTestObjectKernel::~TTestObjectKernel()
       
  7258     { 
       
  7259     
       
  7260     RDebug::Print( _L("TTestObjectKernel::~TTestObjectKernel") );
       
  7261     
       
  7262     iTestClass.Close(); 
       
  7263     User::FreeLogicalDevice( iLddName );
       
  7264     
       
  7265     }
       
  7266    
       
  7267 /*
       
  7268 -------------------------------------------------------------------------------
       
  7269 
       
  7270      Class: TTestObjectKernel
       
  7271 
       
  7272      Method: RunMethodL
       
  7273 
       
  7274      Description: Run specified method from kernel testclass.
       
  7275 
       
  7276      Parameters: CStifItemParser& aItem: in: itemparser
       
  7277 
       
  7278      Return Values: Symbian OS error code
       
  7279 
       
  7280      Errors/Exceptions: None
       
  7281 
       
  7282      Status: Draft
       
  7283     
       
  7284 -------------------------------------------------------------------------------
       
  7285 */
       
  7286 TInt TTestObjectKernel::RunMethodL( CStifItemParser& aItem )
       
  7287     { 
       
  7288     
       
  7289     TPtrC method;
       
  7290     TPtrC params;
       
  7291     
       
  7292     User::LeaveIfError( aItem.GetNextString( method ) );
       
  7293     aItem.Remainder( params );
       
  7294     
       
  7295     TInt result;
       
  7296     TMethodResultDes resultDes;
       
  7297           
       
  7298     // Need to change descriptors from 16bit to 8bit for EKA2 kernel
       
  7299     // because STIF Parser doesn't support 8bit parsing
       
  7300     HBufC8 * myBuf1 = HBufC8::NewL( method.Length() );
       
  7301     TPtr8 met8 = myBuf1->Des();   
       
  7302     met8.Copy( method );
       
  7303         
       
  7304     HBufC8 * myBuf2 = HBufC8::NewL( params.Length() );
       
  7305     TPtr8 par8 = myBuf2->Des();   
       
  7306     par8.Copy( params );
       
  7307     
       
  7308     TInt ret =  iTestClass.RunMethod( met8, par8, result, resultDes );
       
  7309 
       
  7310     delete myBuf1;
       
  7311     delete myBuf2;
       
  7312     
       
  7313     if( ret != KErrNone )
       
  7314         {
       
  7315         return ret;
       
  7316         }
       
  7317     
       
  7318     return result;                             
       
  7319                                      
       
  7320     };
       
  7321 
       
  7322 
       
  7323 // ================= OTHER EXPORTED FUNCTIONS =================================
       
  7324 
       
  7325 /*
       
  7326 -------------------------------------------------------------------------------
       
  7327     
       
  7328      Function: LibEntryL
       
  7329 
       
  7330      Description: Polymorphic Dll Entry Point
       
  7331 
       
  7332      Parameters:    None.
       
  7333 
       
  7334      Return Values: CTestScripter*: pointer to new CTestScripter
       
  7335 
       
  7336      Errors/Exceptions: Leaves if NewL leaves.
       
  7337 
       
  7338      Status: Draft
       
  7339      
       
  7340 -------------------------------------------------------------------------------
       
  7341 */
       
  7342 
       
  7343 EXPORT_C CTestScripter* LibEntryL()
       
  7344     {
       
  7345     return CTestScripter::NewL();
       
  7346     
       
  7347     }
       
  7348 
       
  7349 
       
  7350 //  End of File