stif/TestScripter/src/TestScripter.cpp
changeset 0 a03f92240627
child 8 cfe32394fcd5
equal deleted inserted replaced
-1:000000000000 0:a03f92240627
       
     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 
       
    27 #include <stifinternal/UiEnvProxy.h>
       
    28 
       
    29 // EXTERNAL DATA STRUCTURES
       
    30 // None
       
    31 
       
    32 // EXTERNAL FUNCTION PROTOTYPES  
       
    33 // None
       
    34 
       
    35 // CONSTANTS
       
    36 // None
       
    37 
       
    38 // MACROS
       
    39 #ifdef LOGGER
       
    40 #undef LOGGER
       
    41 #endif
       
    42 #define LOGGER iLog
       
    43 
       
    44 // LOCAL CONSTANTS AND MACROS
       
    45 // None
       
    46  
       
    47 // MODULE DATA STRUCTURES
       
    48 // None
       
    49 
       
    50 // LOCAL FUNCTION PROTOTYPES
       
    51 // None
       
    52 
       
    53 // FORWARD DECLARATIONS
       
    54 // None
       
    55 
       
    56 // ==================== LOCAL FUNCTIONS =======================================
       
    57 
       
    58 /*
       
    59 -------------------------------------------------------------------------------
       
    60 
       
    61      Class: -
       
    62 
       
    63      Method: CallBack
       
    64 
       
    65      Description: (Function pointer) Called from CScriptBase class. Generic
       
    66                   method for call back operations from Test Script Class to
       
    67                   TestScripter.
       
    68   
       
    69      Parameters: CTestScripter* aTestScripter: in: Pointer to TestScripter
       
    70                  TStifTSCallBackType aCallType: in: Call back type
       
    71                  const TDesC& aLine: in Script line
       
    72                     
       
    73      Return Values: TInt: Symbian error code
       
    74 
       
    75      Errors/Exceptions: None
       
    76 
       
    77      Status: Draft
       
    78     
       
    79 -------------------------------------------------------------------------------
       
    80 */
       
    81 TInt CallBack( CTestScripter* aTestScripter,
       
    82                 TStifTSCallBackType aCallType,
       
    83                 const TDesC& aLine )
       
    84     {
       
    85     TInt ret( 0 );
       
    86     switch( aCallType )
       
    87         {
       
    88         case EStifTSCallClass:
       
    89             {
       
    90             ret = aTestScripter->CallTestClass( aLine );
       
    91             break;
       
    92             }
       
    93         case EStifTSGetObject:
       
    94             {
       
    95             ret = aTestScripter->GetTestScriptObject( aLine );
       
    96             break;
       
    97             }
       
    98         default:
       
    99             {
       
   100             ret = KErrArgument;
       
   101             break;
       
   102             }
       
   103         }
       
   104 
       
   105     return ret;
       
   106 
       
   107     }
       
   108 
       
   109 /*
       
   110 -------------------------------------------------------------------------------
       
   111 
       
   112     DESCRIPTION
       
   113 
       
   114     This module contains the implementation of CTestScripter class 
       
   115     member functions.
       
   116 
       
   117 -------------------------------------------------------------------------------
       
   118 */
       
   119 
       
   120 // ================= MEMBER FUNCTIONS =========================================
       
   121 
       
   122 /*
       
   123 -------------------------------------------------------------------------------
       
   124 
       
   125      Class: CTestScripter
       
   126 
       
   127      Method: CTestScripter
       
   128 
       
   129      Description: Default constructor
       
   130 
       
   131      C++ default constructor can NOT contain any code, that
       
   132      might leave.
       
   133      
       
   134      Parameters:    None
       
   135 
       
   136      Return Values: None
       
   137 
       
   138      Errors/Exceptions: None
       
   139 
       
   140      Status: Draft
       
   141     
       
   142 -------------------------------------------------------------------------------
       
   143 */
       
   144 CTestScripter::CTestScripter()
       
   145     {
       
   146 
       
   147     }
       
   148 
       
   149 /*
       
   150 -------------------------------------------------------------------------------
       
   151 
       
   152      Class: CTestScripter
       
   153 
       
   154      Method: ConstructL
       
   155 
       
   156      Description: Symbian OS second phase constructor
       
   157 
       
   158      Symbian OS default constructor can leave.
       
   159 
       
   160      Parameters:    None
       
   161 
       
   162      Return Values: None
       
   163 
       
   164      Errors/Exceptions: None.
       
   165 
       
   166      Status: Draft
       
   167 
       
   168 -------------------------------------------------------------------------------
       
   169 */
       
   170 void CTestScripter::ConstructL()
       
   171     {
       
   172     __TRACE( KPrint, ( _L("New TestScripter") ) );
       
   173     iStdLog = CStifLogger::NewL( KTestScripterLogDir,
       
   174                                 KTestScripterLogFile );
       
   175     iLog = iStdLog;
       
   176 
       
   177     iOOMIgnoreFailure = EFalse; // OFF for default
       
   178 
       
   179     iCheckHeapBalance = EFalse; // No checking heap balance by default
       
   180 
       
   181     //Read logger settings to check whether test case name is to be
       
   182     //appended to log file name.
       
   183     RSettingServer settingServer;
       
   184     TInt ret = settingServer.Connect();
       
   185     if(ret != KErrNone)
       
   186         {
       
   187         User::Leave(ret);
       
   188         }
       
   189     // Struct to StifLogger settigs.
       
   190     TLoggerSettings loggerSettings; 
       
   191     // Parse StifLogger defaults from STIF initialization file.
       
   192     ret = settingServer.GetLoggerSettings(loggerSettings);
       
   193     if(ret != KErrNone)
       
   194         {
       
   195         User::Leave(ret);
       
   196         } 
       
   197     // Close Setting server session
       
   198     settingServer.Close();
       
   199     iAddTestCaseTitleToLogName = loggerSettings.iAddTestCaseTitle;
       
   200     
       
   201     // Initialize parser variables
       
   202     iCurrentParser = NULL;
       
   203     iCurrentParserReadFirstLine = EFalse;
       
   204     }
       
   205 
       
   206 /*
       
   207 -------------------------------------------------------------------------------
       
   208 
       
   209      Class: CTestScripter
       
   210 
       
   211      Method: NewL
       
   212 
       
   213      Description: Two-phased constructor.
       
   214           
       
   215      Parameters:    None
       
   216 
       
   217      Return Values: CTestScripter*: new object
       
   218 
       
   219      Errors/Exceptions: Leaves if new or ConstructL leaves.
       
   220 
       
   221      Status: Draft
       
   222     
       
   223 -------------------------------------------------------------------------------
       
   224 */
       
   225 CTestScripter* CTestScripter::NewL()
       
   226     {
       
   227      
       
   228     CTestScripter* self = new (ELeave) CTestScripter();
       
   229     
       
   230     CleanupStack::PushL( self );
       
   231     self->ConstructL();
       
   232     CleanupStack::Pop();
       
   233 
       
   234     return self;
       
   235      
       
   236     }
       
   237 
       
   238 /*
       
   239 -------------------------------------------------------------------------------
       
   240 
       
   241      Class: CTestScripter
       
   242 
       
   243      Method: ~CTestScripter
       
   244 
       
   245      Description: Destructor
       
   246      
       
   247      Parameters:    None
       
   248 
       
   249      Return Values: None
       
   250 
       
   251      Errors/Exceptions: None
       
   252 
       
   253      Status: Draft
       
   254     
       
   255 -------------------------------------------------------------------------------
       
   256 */
       
   257 CTestScripter::~CTestScripter()
       
   258     {
       
   259     iTestObjects.ResetAndDestroy();
       
   260     iTestModules.ResetAndDestroy();
       
   261     iDefinedIni.ResetAndDestroy();
       
   262     iDefinedRuntime.ResetAndDestroy();
       
   263     iDefinedLocal.ResetAndDestroy();
       
   264     iParserStack.ResetAndDestroy();
       
   265     iTestObjects.Close();
       
   266     iTestModules.Close();
       
   267     iDefinedIni.Close();
       
   268     iDefinedRuntime.Close();
       
   269     iDefinedLocal.Close();
       
   270     iParserStack.Close();
       
   271 
       
   272     iCurrentParser = NULL;
       
   273     delete iSectionParser;
       
   274     delete iTestRunner;
       
   275 
       
   276     iLog = NULL;
       
   277     delete iStdLog;
       
   278     iStdLog = NULL;
       
   279     delete iTCLog;
       
   280     iTCLog = NULL;
       
   281     }
       
   282 
       
   283 /*
       
   284 -------------------------------------------------------------------------------
       
   285 
       
   286      Class: CTestScripter
       
   287 
       
   288      Method: InitL
       
   289 
       
   290      Description: InitL is used to initialize the Test Module.
       
   291 
       
   292      Parameters: const TFileName& aIniFile: in: Initialization file
       
   293                  TBool aFirstTime: in: First time flag 
       
   294                          
       
   295      Return Values: Symbian OS error code
       
   296 
       
   297      Errors/Exceptions: Leaves if ReadInitializationL leaves
       
   298      
       
   299      Status: Draft
       
   300 
       
   301 -------------------------------------------------------------------------------
       
   302 */        
       
   303 TInt CTestScripter::InitL( TFileName& aIniFile, 
       
   304                            TBool /*aFirstTime*/ )
       
   305     {
       
   306  
       
   307     __TRACEFUNC();
       
   308  
       
   309     if( aIniFile.Length() > 0 )
       
   310         {
       
   311         // Read initialization from test case file
       
   312         ReadInitializationL( aIniFile, iDefinedIni );
       
   313         }
       
   314         
       
   315     return KErrNone;
       
   316     
       
   317     }
       
   318 
       
   319 /*
       
   320 -------------------------------------------------------------------------------
       
   321 
       
   322      Class: CTestScripter
       
   323 
       
   324      Method: GetTestCases
       
   325 
       
   326      Description: GetTestCases is used to inquired test cases
       
   327 
       
   328      Parameters:    const TFileName& aConfigFile: in: Test case file
       
   329                     RPointerArray<RTestEngine::TTestCaseInfo>& aTestCases: out: 
       
   330                           Array of TestCases 
       
   331      
       
   332      Return Values: KErrNone: Success
       
   333                     Symbian OS error code
       
   334 
       
   335      Errors/Exceptions: Leaves if CStifParser::SectionL leaves
       
   336                         Leaves if CStifParser::NextSectionL leaves
       
   337                         Leaves if memory allocation fails
       
   338 
       
   339      Status: Draft
       
   340     
       
   341 -------------------------------------------------------------------------------
       
   342 */        
       
   343 TInt CTestScripter::GetTestCasesL( const TFileName& aConfigFile, 
       
   344                                    RPointerArray<TTestCaseInfo>& aTestCases )
       
   345     {
       
   346     __TRACEFUNC();
       
   347     
       
   348     if( aConfigFile.Length() == 0 )
       
   349         {
       
   350         __TRACE( KError, (_L("No test case script file given") ) );
       
   351         __RDEBUG( (_L("No test case script file given") ) );
       
   352         return KErrNotFound;
       
   353         }
       
   354 
       
   355     CStifParser* parser = NULL; 
       
   356     
       
   357     // Open test case file
       
   358     TRAPD( err, 
       
   359         parser = CStifParser::NewL( _L(""), 
       
   360                                     aConfigFile, 
       
   361                                     CStifParser::ECStyleComments ) );
       
   362     if( err != KErrNone )
       
   363         {
       
   364         __TRACE( KError, (_L("Given test case script file [%S] not found"),
       
   365             &aConfigFile ) );
       
   366         __RDEBUG( (_L("Given test case script file [%S] not found"),
       
   367             &aConfigFile ) );
       
   368         return err;
       
   369         }
       
   370         
       
   371     CleanupStack::PushL( parser );
       
   372     CStifSectionParser* section;
       
   373     TPtrC tmp;
       
   374     TInt index = 0;
       
   375     TInt ret = KErrNone;
       
   376 
       
   377     // Find first section
       
   378     section = parser->SectionL( KTestStartTag, KTestEndTag );
       
   379     if( section == NULL )
       
   380         {
       
   381         ret = KErrNotFound;
       
   382         }
       
   383     else
       
   384         {    
       
   385         // Parse all sections
       
   386         while( section )
       
   387             {
       
   388             CleanupStack::PushL( section );
       
   389              
       
   390             // Get title line
       
   391             if( section->GetLine( TTestKeywords::Keyword( TTestKeywords::ETitle ),
       
   392                 tmp, ENoTag ) != KErrNone )
       
   393                 {
       
   394                 __TRACE( KError, (_L("Title not given for test case")));
       
   395                 User::Leave( KErrNotFound );
       
   396                 }
       
   397             else
       
   398                 {
       
   399                 if( tmp.Length() > KMaxName )
       
   400                     {
       
   401                     tmp.Set( tmp.Left( KMaxName ) );
       
   402                     }   
       
   403                 TTestCaseInfo* tc = new ( ELeave ) TTestCaseInfo();
       
   404                 CleanupStack::PushL( tc );
       
   405                 __TRACE( KVerbose, (_L("TestCase: %S"), &tmp));
       
   406                 tc->iTitle.Copy( tmp );
       
   407                 tc->iCaseNumber = ++index;
       
   408                  
       
   409                  // Get timeout if defined
       
   410                 CStifItemParser* item = section->GetItemLineL(  
       
   411                    TTestKeywords::Keyword( TTestKeywords::ETimeout ) );
       
   412                 if( item )
       
   413                     {
       
   414                     TInt timeout; // In milliseconds
       
   415                     ret = item->GetInt( 
       
   416                         TTestKeywords::Keyword( TTestKeywords::ETimeout ), 
       
   417                         timeout ); 
       
   418                     if( ret != KErrNone )
       
   419                         {
       
   420                         __TRACE( KError, (_L("Illegal timeout")));
       
   421                         User::Leave( ret ); 
       
   422                         }
       
   423                         
       
   424                     // Type cast timeout to TInt64    
       
   425                     tc->iTimeout = TInt64( timeout ) * 1000;
       
   426                     __TRACE( KMessage, (_L("Timeout: %i"), tc->iTimeout.Int64() ));
       
   427                     }
       
   428                     
       
   429                  // Get priority if defined
       
   430                 item = section->GetItemLineL(  
       
   431                    TTestKeywords::Keyword( TTestKeywords::EPriority ) );
       
   432                 if( item )
       
   433                     {
       
   434                     // First try to interpret as integer
       
   435                     ret = item->GetInt( 
       
   436                         TTestKeywords::Keyword( TTestKeywords::EPriority ), 
       
   437                         tc->iPriority ); 
       
   438                     if( ret != KErrNone )
       
   439                         {
       
   440                         TPtrC priority;
       
   441                         // If priority was not given as integer, it must be 
       
   442                         // one of the predefined values
       
   443                         ret = item->GetString( 
       
   444                             TTestKeywords::Keyword( TTestKeywords::EPriority ),
       
   445                             priority );
       
   446                         if( ret != KErrNone )
       
   447                             {
       
   448                             __TRACE( KError, (_L("Illegal priority")));
       
   449                             User::Leave( ret ); 
       
   450                             }
       
   451                         switch( TTestKeywords::Parse( priority, 
       
   452                                                        TTestKeywords::Priority ) )
       
   453                             {
       
   454                             case TTestKeywords::EPriHigh:
       
   455                                 tc->iPriority = TTestCaseInfo::EPriorityHigh;
       
   456                                 break;
       
   457                             case TTestKeywords::EPriNormal:
       
   458                                 tc->iPriority = TTestCaseInfo::EPriorityNormal;
       
   459                                 break;
       
   460                             case TTestKeywords::EPriLow:
       
   461                                 tc->iPriority = TTestCaseInfo::EPriorityLow;
       
   462                                 break;
       
   463                             default:
       
   464                                 __TRACE( KError, (_L("Illegal priority")));
       
   465                                 User::Leave( KErrArgument ); 
       
   466                             }
       
   467                         }
       
   468                     __TRACE( KMessage, (_L("Priority: %i"), tc->iPriority ));
       
   469                     }
       
   470                     
       
   471                 aTestCases.Append(tc);
       
   472                 CleanupStack::Pop( tc );
       
   473                 }
       
   474             CleanupStack::PopAndDestroy( section );
       
   475             section = parser->NextSectionL( KTestStartTag, KTestEndTag );
       
   476             }
       
   477         }
       
   478           
       
   479     CleanupStack::PopAndDestroy( parser );
       
   480 
       
   481     __TRACE( KPrint, (  _L( "Configfile '%S', testcases %d" ),
       
   482         &aConfigFile, index ));     
       
   483      
       
   484     return ret;
       
   485      
       
   486     }
       
   487 
       
   488 /*
       
   489 -------------------------------------------------------------------------------
       
   490 
       
   491      Class: CTestScripter
       
   492 
       
   493      Method: GetConstantValue
       
   494 
       
   495      Description: Internal fuction to get const value defined in 
       
   496                   [Define]...[Enddefine] section of script file
       
   497 
       
   498      GetConstantValue gets const value defined in [Define]...[Enddefine] 
       
   499      section of script file
       
   500 
       
   501      Parameters:    const TDesC& aName: in: constant name 
       
   502                     TDes& avalue: out: constant value
       
   503 
       
   504      Return Values: KErrNone: Value is returned succesfully.
       
   505                     KErrNotFound: Constant was not found
       
   506                     Any other SymbianOS error
       
   507                     
       
   508 -------------------------------------------------------------------------------
       
   509 */
       
   510 EXPORT_C TInt CTestScripter::GetConstantValue( const TDesC& aName, TDes& aValue )
       
   511 	{
       
   512 	
       
   513 	__TRACEFUNC();
       
   514 
       
   515     TInt count = iDefinedLocal.Count();
       
   516     for(TInt i = 0; i < count; i++)
       
   517         {
       
   518         if(iDefinedLocal[i]->Name() == aName)
       
   519             {
       
   520             aValue.Copy(iDefinedLocal[i]->Value());
       
   521             return KErrNone;
       
   522             }
       
   523         }	
       
   524 
       
   525 	  count = iDefinedIni.Count();
       
   526     for( TInt i = 0; i < count; i++ )
       
   527         {
       
   528         if( iDefinedIni[i]->Name() == aName )
       
   529             {
       
   530             aValue.Copy( iDefinedIni[i]->Value() );
       
   531             return KErrNone;
       
   532             }
       
   533         }	
       
   534 	
       
   535     count = iDefinedRuntime.Count();
       
   536     for( TInt i = 0; i < count; i++ )
       
   537         {
       
   538         if( iDefinedRuntime[i]->Name() == aName )
       
   539             {
       
   540             aValue.Copy( iDefinedRuntime[i]->Value() );
       
   541             return KErrNone;
       
   542             }
       
   543         }	
       
   544     return KErrNotFound;
       
   545 	}
       
   546 
       
   547 
       
   548 /*
       
   549 -------------------------------------------------------------------------------
       
   550 
       
   551      Class: CTestScripter
       
   552 
       
   553      Method: RunTestCaseL
       
   554 
       
   555      Description: Run a specified testcase.
       
   556 
       
   557      RunTestCaseL is used to run an individual test case. 
       
   558   
       
   559      Parameters:    const TInt aCaseNumber: in: Testcase number 
       
   560                     const TFileName& aConfig: in: Test case file
       
   561                     TTestResult& aResult: out: test case result
       
   562 
       
   563      Return Values: KErrNone: Test case started succesfully.
       
   564                     KErrNotFound: Testcase not found
       
   565                     KErrUnknown: Unknown TestScripter error
       
   566                     Any other SymbianOS error
       
   567 
       
   568      Errors/Exceptions: Leaves if GetTestCaseL leaves
       
   569                         Leaves if RunTestL leaves
       
   570                         Leaves if memory allocation fails
       
   571      
       
   572      Status: Draft
       
   573 
       
   574 -------------------------------------------------------------------------------
       
   575 */
       
   576 TInt CTestScripter::RunTestCaseL( const TInt aCaseNumber,
       
   577                                   const TFileName& aConfig,
       
   578                                   TTestResult& aResult )
       
   579     {
       
   580 
       
   581     // Heap is checked by test server
       
   582     //__UHEAP_MARK;
       
   583 
       
   584     __TRACEFUNC();
       
   585 
       
   586     //Open new log file with test case title in file name
       
   587     if(iAddTestCaseTitleToLogName)
       
   588         {
       
   589         //Delete test case logger if exists
       
   590         if(iTCLog)
       
   591             {
       
   592             delete iTCLog;
       
   593             iTCLog = NULL;
       
   594             }
       
   595             
       
   596         TFileName logFileName;
       
   597         TName title;
       
   598         TestModuleIf().GetTestCaseTitleL(title);
       
   599         
       
   600         logFileName.Format(KTestScripterLogFileWithTitle, &title);
       
   601         iTCLog = CStifLogger::NewL(KTestScripterLogDir, logFileName);
       
   602         iLog = iTCLog;
       
   603         }
       
   604 
       
   605     __TRACE( KMessage, (_L("\n\n***Testcase started***")));
       
   606 
       
   607     // Remove locally defined variables 
       
   608     iDefinedLocal.ResetAndDestroy();
       
   609     // Remove existing function parsers (there shouldn't be any)
       
   610     iParserStack.ResetAndDestroy();
       
   611     
       
   612     // Keep file name of config file
       
   613     iConfig = aConfig;
       
   614 
       
   615     // Read initialization from test case file
       
   616     ReadInitializationL( aConfig, iDefinedRuntime );
       
   617 
       
   618     // Get case from test case file
       
   619     iSectionParser = GetTestCaseL( aCaseNumber, aConfig );
       
   620     iCurrentParser = iSectionParser;
       
   621     iCurrentParserReadFirstLine = EFalse;
       
   622 
       
   623     // Check parsing result
       
   624     if( iSectionParser == NULL )
       
   625         {
       
   626         __TRACE( KError, (_L("***Parsing testcase failed***\n\n")));
       
   627         // Delete runtime defines
       
   628         iDefinedRuntime.ResetAndDestroy();
       
   629         //__UHEAP_MARKEND;
       
   630         return KErrNotFound;
       
   631         }
       
   632 
       
   633     // When option is set in cfg file, on EKA2 env memory leaking is enabled
       
   634 	TInt memCellsBef = 0; //memory in current thread allocated before the test case is run
       
   635 	TInt memCellsAft = 0; //memory in current thread allocated after the test case has run
       
   636 
       
   637    	memCellsBef = User::Heap().Count();
       
   638 	__TRACE(KMessage, (_L("Allocated memory cells before the test case: %d"), memCellsBef));
       
   639 
       
   640     CActiveScheduler* activeScheduler =
       
   641         new ( ELeave ) CActiveScheduler();
       
   642     CleanupStack::PushL( activeScheduler );
       
   643      
       
   644     if ( CActiveScheduler::Current() == NULL )
       
   645     	{
       
   646     	CActiveScheduler::Install( activeScheduler );
       
   647     	}
       
   648 
       
   649     // Run the given testcase described in iSectionParser section
       
   650     RunTestL();
       
   651 
       
   652     iTestObjects.ResetAndDestroy();
       
   653     iTestModules.ResetAndDestroy();
       
   654 
       
   655     // TestScripter must stop Active Scheduler after test
       
   656     // object is destroyed. Otherwise if unexpected error occurs
       
   657     // handling is erronous.
       
   658     CleanupStack::PopAndDestroy( activeScheduler );
       
   659 
       
   660 	// Check for memory leak.
       
   661 	// It is reported in log always, but result of test case is changed only
       
   662 	// when option in cfg file is enabled.
       
   663 	memCellsAft = User::Heap().Count();
       
   664 	__TRACE(KMessage, (_L("Allocated memory cells after the test case: %d"), memCellsAft));
       
   665 
       
   666 	// if there is a difference report memory leak
       
   667 	if(memCellsAft != memCellsBef)
       
   668 		{
       
   669 		__TRACE(KError, (_L("Memory leak, %d cell(s) is missing"), memCellsAft - memCellsBef));
       
   670 		if(iCheckHeapBalance)
       
   671 			{
       
   672 			// Memory leaks detection is disabled for UI components testing
       
   673 			if ( !( TestModuleIf().UITesting() ) )
       
   674 				{
       
   675 				UpdateTestCaseResult(KErrGeneral, _L("Memory leak has occured"));
       
   676 				}
       
   677 			}
       
   678 		}
       
   679 
       
   680     // Delete parser and set current parser to NULL
       
   681     iCurrentParser = NULL;
       
   682     delete iSectionParser;
       
   683     iSectionParser = NULL;  
       
   684     
       
   685     // Erase config file name
       
   686     iConfig = KNullDesC; 
       
   687     
       
   688     // Return result 
       
   689     aResult = iResult;
       
   690     
       
   691     if( iResult.iResult == KErrNone )
       
   692         {
       
   693         __TRACE( KPrint, (_L("***Testcase PASSED***\n\n")));
       
   694         TestModuleIf().Printf( KPrintPriNorm, _L("TestScripter"), 
       
   695             _L("***Testcase PASSED***\n\n"));
       
   696         }
       
   697     else
       
   698         {        
       
   699         __TRACE( KPrint, (_L("***Testcase FAILED***\n\n")));
       
   700         TestModuleIf().Printf( KPrintPriNorm, _L("TestScripter"), 
       
   701             _L("***Testcase FAILED***\n\n"));
       
   702         }
       
   703     User::After(300000);
       
   704     // Delete runtime defines
       
   705     iDefinedRuntime.ResetAndDestroy();
       
   706     
       
   707     //__UHEAP_MARKEND;
       
   708              
       
   709     //If log was replaced then restore it
       
   710     if(iAddTestCaseTitleToLogName)
       
   711         {
       
   712         iLog = iStdLog;
       
   713         delete iTCLog;
       
   714         iTCLog = NULL;
       
   715         }
       
   716     
       
   717     return KErrNone;
       
   718      
       
   719     }
       
   720     
       
   721 /*
       
   722 -------------------------------------------------------------------------------
       
   723 
       
   724      Class: CTestScripter
       
   725 
       
   726      Method: ReadInitializationL
       
   727 
       
   728      Description: Read initialization from file.
       
   729 
       
   730      Parameters:    const TDesC& aIniFile: in: File that contains initialization
       
   731                     
       
   732      Return Values: None
       
   733      
       
   734      Errors/Exceptions: None
       
   735      
       
   736      Status: Draft
       
   737 
       
   738 -------------------------------------------------------------------------------
       
   739 */
       
   740 void CTestScripter::ReadInitializationL(
       
   741     const TDesC& aIniFile,
       
   742     RPointerArray<CDefinedValue>& aDefines )
       
   743     {
       
   744 
       
   745     CStifParser* parser = NULL;
       
   746 
       
   747     // Open file
       
   748     TRAPD( err,
       
   749         parser = CStifParser::NewL( _L(""),
       
   750                                     aIniFile,
       
   751                                     CStifParser::ECStyleComments ) );
       
   752     if( ( err == KErrNone ) && parser )
       
   753         {
       
   754         CleanupStack::PushL( parser );
       
   755         __TRACE( KMessage, (_L("Read initialization from [%S]"),
       
   756             &aIniFile ) );
       
   757 
       
   758         CStifSectionParser* section = parser->SectionL( KDefineStartTag,
       
   759                                                         KDefineEndTag );
       
   760         while(section)
       
   761             {
       
   762             CleanupStack::PushL( section );
       
   763             __TRACE( KMessage, (_L("Read defines")) );
       
   764 
       
   765             TPtrC name;
       
   766             TPtrC value;
       
   767             CStifItemParser* item = section->GetItemLineL( _L("") );
       
   768             while( item )
       
   769                 {
       
   770                 CleanupStack::PushL( item );
       
   771 
       
   772                 if( item->GetString( _L(""), name ) != KErrNone )
       
   773                     {
       
   774                     __TRACE( KError, (_L("No define name given")) );
       
   775                     User::Leave( KErrGeneral );
       
   776                     }
       
   777                 if( item->Remainder( value ) != KErrNone )
       
   778                     {
       
   779                     __TRACE( KError, (_L("No define value given")) );
       
   780                     User::Leave( KErrGeneral );
       
   781                     }
       
   782                 TInt count = aDefines.Count();
       
   783                 TInt i = 0;
       
   784                 for( ; i < count; i++ )
       
   785                     {
       
   786                     if( aDefines[i]->Name() == name )
       
   787                         {
       
   788                         // Update existing
       
   789                         aDefines[i]->SetValueL( value );
       
   790                         __TRACE(KMessage, (_L("Update define [%S]: [%S]"), &name, &value));
       
   791                         break;
       
   792                         }
       
   793                     }
       
   794                 if( i == count)
       
   795                     {
       
   796                     // New define, store it
       
   797                     CDefinedValue* define = CDefinedValue::NewL( name, value );
       
   798                     CleanupStack::PushL( define );
       
   799                     User::LeaveIfError( aDefines.Append( define ) );
       
   800                     CleanupStack::Pop( define );
       
   801                     }
       
   802 
       
   803                 CleanupStack::PopAndDestroy( item );
       
   804                 item = section->GetNextItemLineL();
       
   805                 }
       
   806             CleanupStack::PopAndDestroy( section );
       
   807             section = parser->NextSectionL(KDefineStartTag, KDefineEndTag);
       
   808             }
       
   809 
       
   810 		//Read StifSettings section and find value for CheckHeapBalance.
       
   811 		//(In cfg file in settings section User may also set CapsModifier
       
   812 		// option. This is handled in TestServerClient.cpp in 
       
   813 		// RTestServer::GetCapsModifier method).
       
   814 		section = parser->SectionL(KStifSettingsStartTag, KStifSettingsEndTag);
       
   815 
       
   816 		if(section)
       
   817 			{
       
   818 			CleanupStack::PushL(section);
       
   819 			__TRACE(KMessage, (_L("Read stif settings")));
       
   820 
       
   821 			TPtrC value;
       
   822 			CStifItemParser* item = section->GetItemLineL(_L(""));
       
   823 			while(item)
       
   824 				{
       
   825 				CleanupStack::PushL(item);
       
   826 				__TRACE( KMessage, (_L("Got settings line")));
       
   827 
       
   828 				if(item->GetString(_L("CheckHeapBalance="), value) == KErrNone)
       
   829 					{
       
   830 					__TRACE(KMessage, (_L("Got CheckHeapBalance item, value=%S"), &value));
       
   831 					if(value.Compare(_L("off")) == 0)
       
   832 		       			{
       
   833 		       			iCheckHeapBalance = EFalse;
       
   834 		       			}
       
   835 					else if(value.Compare(_L("on")) == 0)
       
   836 						{
       
   837 						iCheckHeapBalance = ETrue;
       
   838 		       			}
       
   839 					else
       
   840 						{
       
   841 						__TRACE(KError, (_L("Value '%S' for CheckHeapBalance setting is not supported. Aborting"), &value));
       
   842 						User::Leave(KErrNotSupported);
       
   843 						}
       
   844 					}
       
   845 				CleanupStack::PopAndDestroy(item);
       
   846 				item = section->GetNextItemLineL();
       
   847 				}
       
   848 			CleanupStack::PopAndDestroy(section);
       
   849 			}
       
   850 
       
   851         CleanupStack::PopAndDestroy( parser );
       
   852         }
       
   853     }
       
   854 
       
   855 
       
   856 /*
       
   857 -------------------------------------------------------------------------------
       
   858 
       
   859      Class: CTestScripter
       
   860 
       
   861      Method: GetTestCaseL
       
   862 
       
   863      Description: Get specified test case section from configfile.
       
   864 
       
   865      Parameters:    const TInt aCaseNumber: in: Test case number
       
   866                     const TFileName& aConfig: in: Configfile name 
       
   867      
       
   868      Return Values: CStifSectionParser*: pointer to test case section
       
   869 
       
   870      Errors/Exceptions: Leaves if CStifParser::NewL leaves
       
   871                         Leaves if CStifParser::SectionL leaves
       
   872                         Leaves if memory allocation fails
       
   873                                 
       
   874 
       
   875      Status: Draft
       
   876     
       
   877 -------------------------------------------------------------------------------
       
   878 */
       
   879 CStifSectionParser* CTestScripter::GetTestCaseL( const TInt aCaseNumber, 
       
   880                                              const TFileName& aConfig )
       
   881     {
       
   882     __TRACEFUNC();
       
   883     CStifParser* parser = NULL;
       
   884     
       
   885     TRAPD( err, 
       
   886         parser = CStifParser::NewL( _L(""), 
       
   887                                     aConfig, 
       
   888                                     CStifParser::ECStyleComments ); );
       
   889     if( err != KErrNone )
       
   890         {
       
   891         __TRACE( KError, (_L("Test case file [%S] not found"), &aConfig ));
       
   892         User::Leave( err );
       
   893         }
       
   894     CleanupStack::PushL( parser );
       
   895 
       
   896     CStifSectionParser* section = NULL;
       
   897     TRAP( err, 
       
   898         section =parser->SectionL( KTestStartTag, KTestEndTag, aCaseNumber ););
       
   899     if( err != KErrNone )
       
   900         {
       
   901         __TRACE( KError, 
       
   902             (_L("Section [%S/%d] not found"), &aConfig, aCaseNumber ));
       
   903         User::Leave( err );
       
   904         }
       
   905 
       
   906     CleanupStack::PopAndDestroy( parser );
       
   907     return section;
       
   908     
       
   909     }
       
   910 
       
   911 /*
       
   912 -------------------------------------------------------------------------------
       
   913 
       
   914      Class: CTestScripter
       
   915 
       
   916      Method: GetSubL
       
   917 
       
   918      Description: Get specified function (sub) from stored config file.
       
   919 
       
   920      Parameters:    const TDesC& aSubName: in: function name 
       
   921      
       
   922      Return Values: CStifSectionParser*: pointer to test function section
       
   923 
       
   924      Errors/Exceptions: Leaves if CStifParser::NewL leaves
       
   925                         Leaves if CStifParser::SectionL leaves
       
   926                         Leaves if memory allocation fails
       
   927                                 
       
   928      Status: Draft
       
   929     
       
   930 -------------------------------------------------------------------------------
       
   931 */
       
   932 CStifSectionParser* CTestScripter::GetSubL(const TDesC& aSubName)
       
   933     {
       
   934     __TRACE(KMessage, (_L("Searching sub [%S]."), &aSubName));
       
   935     // Check if config file is set
       
   936     if(iConfig.Length() == 0)
       
   937         {
       
   938         __TRACE(KError, (_L("Searching sub [%S]. Config file is not set."), &aSubName));
       
   939         User::Leave(KErrBadName);
       
   940         }
       
   941         
       
   942     // Create parser
       
   943     CStifParser* parser = NULL;
       
   944     CStifSectionParser* section = NULL;
       
   945         
       
   946     TRAPD(err, 
       
   947           parser = CStifParser::NewL(_L(""), iConfig, CStifParser::ECStyleComments);
       
   948          );
       
   949     if(err != KErrNone)
       
   950         {
       
   951         __TRACE(KError, (_L("Searching sub [%S]. Error [%d] when loading config file [%S]."), &aSubName, err, &iConfig));
       
   952         User::Leave(err);
       
   953         }
       
   954     CleanupStack::PushL(parser);
       
   955 
       
   956     // Set section tags
       
   957     _LIT(KEndSubTag, "[EndSub]");
       
   958     TName startSubTag;
       
   959     startSubTag.Copy(_L("[Sub "));
       
   960     startSubTag.Append(aSubName);
       
   961     startSubTag.Append(_L("]"));
       
   962     
       
   963     // Load section
       
   964     TRAP(err, 
       
   965          section = parser->SectionL(startSubTag, KEndSubTag, 1);
       
   966         );
       
   967     if(err != KErrNone)
       
   968         {
       
   969         __TRACE(KError, (_L("Searching sub [%S]. Searching section %S%S ended with error [%d]."), &aSubName, &startSubTag, &KEndSubTag, err));
       
   970         User::Leave(err);
       
   971         }
       
   972     if(!section)
       
   973         {
       
   974         __TRACE(KError, (_L("Searching sub [%S]. Section %S%S not found."), &aSubName, &startSubTag, &KEndSubTag));
       
   975         User::Leave(err);
       
   976         }
       
   977     else
       
   978         {
       
   979         __TRACE(KMessage, (_L("Searching sub [%S]. Section %S%S found."), &aSubName, &startSubTag, &KEndSubTag));
       
   980         }
       
   981 
       
   982     CleanupStack::PopAndDestroy(parser);
       
   983     return section;
       
   984     }
       
   985 
       
   986 /*
       
   987 -------------------------------------------------------------------------------
       
   988 
       
   989      Class: CTestScripter
       
   990 
       
   991      Method: RunTestL
       
   992 
       
   993      Description: Run a testcase specified by iSectionParser.
       
   994 
       
   995      Parameters:    None
       
   996      
       
   997      Return Values: None.
       
   998 
       
   999      Errors/Exceptions: Leaves if CSectionParser::GetItemLineL leaves
       
  1000                         Leaves if CTestRunner::NewL leaves
       
  1001                         Leaves if memory allocation fails                                
       
  1002 
       
  1003      Status: Draft
       
  1004     
       
  1005 -------------------------------------------------------------------------------
       
  1006 */
       
  1007 void CTestScripter::RunTestL()
       
  1008     {
       
  1009     __TRACEFUNC();
       
  1010     iResult.iResult = KErrNone;
       
  1011     iResult.iResultDes.Zero();
       
  1012      
       
  1013     // "title" keyword must be in the first line
       
  1014     TPtrC title;
       
  1015     if( iCurrentParser->GetLine( 
       
  1016         TTestKeywords::Keyword( TTestKeywords::ETitle ), title, ENoTag ) 
       
  1017         != KErrNone )
       
  1018         {
       
  1019         __TRACE( KError, (_L("title not found from section")));
       
  1020         User::Leave( KErrNotFound ); 
       
  1021         }
       
  1022     iCurrentParserReadFirstLine = ETrue;
       
  1023 
       
  1024     __TRACE( KMessage, (_L("RunTest: %S"), &title ));
       
  1025      
       
  1026     iTestRunner = CTestRunner::NewL( this );
       
  1027 
       
  1028     TestModuleIf().Printf( KPrintPriNorm, _L("RunTest"), _L("%S"), &title );
       
  1029     
       
  1030     // Rest of the job is done by test runner
       
  1031     iTestRunner->SetRunnerActive();
       
  1032 
       
  1033     // Start activeScheduler looping testcase lines
       
  1034     __TRACE( KMessage, (_L("Start CActiveScheduler")));
       
  1035     CActiveScheduler::Current()->Start();
       
  1036   
       
  1037     delete iTestRunner;
       
  1038     iTestRunner = NULL;
       
  1039     __TRACE( KMessage, ( _L("RunTestL: Done")));
       
  1040  
       
  1041     // Destroy locally defined variables 
       
  1042     iDefinedLocal.ResetAndDestroy();
       
  1043     // Destroy function parsers (there shouldn't be any)
       
  1044     iParserStack.ResetAndDestroy();
       
  1045     }     
       
  1046 
       
  1047 /*
       
  1048 -------------------------------------------------------------------------------
       
  1049 
       
  1050      Class: CTestScripter
       
  1051 
       
  1052      Method: GetTestModuleL
       
  1053 
       
  1054      Description: Load testmodule if not already loaded, otherwise return
       
  1055                   description of the loaded testmodule.
       
  1056 
       
  1057      Parameters:    TDesC& aModule: in: module name
       
  1058                     TDesC& aIniFile: in: ini file name
       
  1059      
       
  1060      Return Values: CTCTestModule*: pointer to testmodules description
       
  1061      
       
  1062      Errors/Exceptions: Leaves if CTCTestModule::NewL leaves
       
  1063                         Leaves if RPointerArray::Append fails  
       
  1064 
       
  1065      Status: Draft
       
  1066     
       
  1067 -------------------------------------------------------------------------------
       
  1068 */              
       
  1069 TTestModule* CTestScripter::LoadTestModuleL( TDesC& aModule )
       
  1070     {     
       
  1071     __TRACEFUNC();
       
  1072     TInt count = iTestModules.Count();
       
  1073     for( TInt i=0; i < count; i++ )
       
  1074         {
       
  1075         if( iTestModules[i]->ModuleName() == aModule )
       
  1076             {
       
  1077             // Found test module, return description
       
  1078             __TRACE( KMessage, 
       
  1079                 (_L("GetTestModuleL: Use already loaded TestModule (%S)"), 
       
  1080                 &aModule ));
       
  1081             return iTestModules[i];
       
  1082             }
       
  1083         }
       
  1084          
       
  1085     __TRACE( KMessage, (_L("GetTestModuleL: Load new TestModule (%S)"), 
       
  1086         &aModule ));
       
  1087     TTestModule* module = new (ELeave) TTestModule();
       
  1088     CleanupStack::PushL( module );
       
  1089     module->ModuleName() = aModule;
       
  1090     User::LeaveIfError( iTestModules.Append( module ) );
       
  1091     CleanupStack::Pop( module );
       
  1092 
       
  1093     TInt ret = module->iLibrary.Load ( aModule );
       
  1094     
       
  1095     if( ret != KErrNone )
       
  1096         {
       
  1097         __TRACE( KMessage, (_L("GetTestModuleL: %S loading failed"), 
       
  1098             &aModule ));
       
  1099         TestModuleIf().Printf( KMessage, _L("Load dll"), _L("%S failed"), 
       
  1100             &aModule );
       
  1101         
       
  1102         User::Leave( ret );
       
  1103         }
       
  1104          
       
  1105     // Get pointer to first exported function    
       
  1106     module->iLibEntry = (CInterfaceFactory) module->iLibrary.Lookup(1);
       
  1107     return module;
       
  1108     
       
  1109     }
       
  1110     
       
  1111 /*
       
  1112 -------------------------------------------------------------------------------
       
  1113 
       
  1114      Class: CTestScripter
       
  1115 
       
  1116      Method: CreateObjectL
       
  1117 
       
  1118      Description: Load testmodule if not already loaded, otherwise return
       
  1119                   description of the loaded testmodule.
       
  1120 
       
  1121      Parameters:    TDesC& aModule: in: module name
       
  1122                     TDesC& aObjectId: in: object id name
       
  1123      
       
  1124      Return Values: None
       
  1125      
       
  1126      Errors/Exceptions: Leaves on error
       
  1127 
       
  1128      Status: Draft
       
  1129     
       
  1130 -------------------------------------------------------------------------------
       
  1131 */
       
  1132 void CTestScripter::CreateObjectL( TDesC& aModule, TDesC& aObjectId )
       
  1133     {     
       
  1134     __TRACEFUNC();
       
  1135 
       
  1136     // Load module and get pointer
       
  1137     TTestModule* module = LoadTestModuleL( aModule );
       
  1138     TTestObject* object = new (ELeave) TTestObject();
       
  1139     CleanupStack::PushL( object );
       
  1140     object->ObjectId() = aObjectId;
       
  1141     User::LeaveIfError( iTestObjects.Append( object ) );
       
  1142     CleanupStack::Pop( object );
       
  1143         
       
  1144     // Create object    
       
  1145     object->iScript = module->iLibEntry( TestModuleIf() );
       
  1146     //User::LeaveIfNull ( object->iScript );
       
  1147     if( object->iScript == NULL )
       
  1148         {
       
  1149         User::Leave( KErrGeneral );
       
  1150         }
       
  1151 
       
  1152     // Create continue callback 
       
  1153     object->iContinue = CTestContinue::NewL( this, object );
       
  1154 
       
  1155     // Create function pointer operation to possible
       
  1156     object->iScript->SetScripter( &CallBack, this );
       
  1157     
       
  1158     }
       
  1159     
       
  1160 /*
       
  1161 -------------------------------------------------------------------------------
       
  1162 
       
  1163      Class: CTestScripter
       
  1164 
       
  1165      Method: CreateKernelObjectL
       
  1166 
       
  1167      Description: Load testdriver if not already loaded, otherwise return
       
  1168                   description of the loaded testdriver.
       
  1169 
       
  1170      Parameters:    TDesC& aDriver: in: driver name
       
  1171                     TDesC& aObjectId: in: object id name
       
  1172      
       
  1173      Return Values: None
       
  1174      
       
  1175      Errors/Exceptions: Leaves on error
       
  1176 
       
  1177      Status: Draft
       
  1178     
       
  1179 -------------------------------------------------------------------------------
       
  1180 */
       
  1181 void CTestScripter::CreateKernelObjectL( TDesC& aDriver, TDesC& aObjectId )
       
  1182     {     
       
  1183 
       
  1184     __TRACEFUNC();
       
  1185     
       
  1186     if( ( aDriver.Length() > KMaxName ) ||
       
  1187         ( aObjectId.Length() > KMaxName ) )
       
  1188         {
       
  1189         __TRACE( KError, (_L("CreateKernelObjectL: Max lenght exceeded") ) );
       
  1190         User::Leave( KErrArgument );
       
  1191         }
       
  1192     TInt ret = User::LoadLogicalDevice( aDriver );
       
  1193     if( ( ret != KErrNone ) && ( ret != KErrAlreadyExists ) )
       
  1194         {
       
  1195         __TRACE( KError, 
       
  1196             (_L("CreateKernelObjectL: User::LoadLogicalDevice failed %d"), 
       
  1197                 ret ) );
       
  1198         User::Leave( ret );
       
  1199         } 
       
  1200         
       
  1201     TTestObjectKernel* object = new (ELeave) TTestObjectKernel();
       
  1202     CleanupStack::PushL( object );
       
  1203     object->ObjectId() = aObjectId;
       
  1204     object->LddName().Copy( aDriver );
       
  1205     ret = object->KernelTestClass().Open( 
       
  1206                 object->KernelTestClass().VersionRequired(), 
       
  1207                 aDriver );
       
  1208     if( ret != KErrNone )
       
  1209         {
       
  1210         __TRACE( KError, 
       
  1211             (_L("CreateKernelObjectL: KernelTestClass().Open failed %d"), 
       
  1212                 ret ) );
       
  1213         User::Leave( ret );
       
  1214         }
       
  1215         
       
  1216     User::LeaveIfError( iTestObjects.Append( object ) );
       
  1217     CleanupStack::Pop( object );
       
  1218         
       
  1219     }
       
  1220     
       
  1221 /*
       
  1222 -------------------------------------------------------------------------------
       
  1223 
       
  1224      Class: CTestScripter
       
  1225 
       
  1226      Method: GetTestModuleL
       
  1227 
       
  1228      Description: Load testmodule if not already loaded, otherwise return
       
  1229                   description of the loaded testmodule.
       
  1230 
       
  1231      Parameters:    TDesC& aModule: in: module name
       
  1232                     TDesC& aIniFile: in: ini file name
       
  1233      
       
  1234      Return Values: CTCTestModule*: pointer to testmodules description
       
  1235      
       
  1236      Errors/Exceptions: Leaves if CTCTestModule::NewL leaves
       
  1237                         Leaves if RPointerArray::Append fails  
       
  1238 
       
  1239      Status: Draft
       
  1240     
       
  1241 -------------------------------------------------------------------------------
       
  1242 */
       
  1243 TInt CTestScripter::DeleteObjectL( TDesC& aObjectId )
       
  1244     {     
       
  1245     __TRACEFUNC();
       
  1246 
       
  1247     TInt count = iTestObjects.Count();
       
  1248     for( TInt i=0; i < count; i++ )
       
  1249         {
       
  1250         if( iTestObjects[i]->ObjectId() == aObjectId )
       
  1251             {
       
  1252             TTestObjectBase* object = iTestObjects[i];
       
  1253             iTestObjects.Remove( i );
       
  1254             delete object;
       
  1255             return KErrNone;
       
  1256             }
       
  1257         }
       
  1258      
       
  1259     return KErrNone;
       
  1260     }
       
  1261 
       
  1262 /*
       
  1263 -------------------------------------------------------------------------------
       
  1264 
       
  1265      Class: CTestScripter
       
  1266 
       
  1267      Method: GetTest
       
  1268 
       
  1269      Description: Get test case from testcase array.
       
  1270 
       
  1271      Parameters:    TDesC& aTestId: in: TestId for testcase
       
  1272      
       
  1273      Return Values: CTCTestCase*: running/runned testcase
       
  1274                     NULL: Testcase with aTestId not running/runned 
       
  1275 
       
  1276      Errors/Exceptions: None
       
  1277 
       
  1278      Status: Draft
       
  1279     
       
  1280 -------------------------------------------------------------------------------
       
  1281 */
       
  1282 TTestObjectBase* CTestScripter::GetObject( const TDesC& aObjectId )
       
  1283     {
       
  1284     __TRACEFUNC();
       
  1285     
       
  1286     TInt count = iTestObjects.Count();
       
  1287     for( TInt i=0; i < count; i++ )
       
  1288         {
       
  1289         if( iTestObjects[i]->ObjectId() == aObjectId )
       
  1290             {
       
  1291             // Found testcase with specified TestId
       
  1292             return iTestObjects[i];
       
  1293             }
       
  1294         }
       
  1295     // Object with iTestObjects not found
       
  1296     return NULL;
       
  1297     
       
  1298     }
       
  1299 
       
  1300 /*
       
  1301 -------------------------------------------------------------------------------
       
  1302 
       
  1303      Class: CTestScripter
       
  1304 
       
  1305      Method: CallTestClass
       
  1306 
       
  1307      Description: For sub classing operations.
       
  1308   
       
  1309      Parameters: const TDesC& aLine: in: script line
       
  1310                     
       
  1311      Return Values: TInt: Symbian error code
       
  1312 
       
  1313      Errors/Exceptions: None
       
  1314 
       
  1315      Status: Draft
       
  1316     
       
  1317 -------------------------------------------------------------------------------
       
  1318 */
       
  1319 TInt CTestScripter::CallTestClass( const TDesC& aLine )
       
  1320     {
       
  1321     CStifItemParser* item = CStifItemParser::NewL( aLine, 0, aLine.Length() );
       
  1322     CleanupStack::PushL( item );
       
  1323 
       
  1324     TPtrC objectName;
       
  1325     TInt ret( KErrNone );
       
  1326     ret = item->GetString( _L( "" ), objectName );
       
  1327     if( ret != KErrNone )
       
  1328         {
       
  1329         CleanupStack::PopAndDestroy( item);
       
  1330         return ret;
       
  1331         }
       
  1332 
       
  1333     TTestObjectBase* obj = GetObject( objectName );
       
  1334     if( obj == NULL )
       
  1335         {
       
  1336         CleanupStack::PopAndDestroy(item );
       
  1337         return KErrNotFound;
       
  1338         }
       
  1339 
       
  1340     TRAPD( commandResult, commandResult = obj->RunMethodL( *item ) );
       
  1341 
       
  1342     CleanupStack::PopAndDestroy(item );
       
  1343 
       
  1344     return commandResult;
       
  1345     
       
  1346     }
       
  1347     
       
  1348 /*
       
  1349 -------------------------------------------------------------------------------
       
  1350 
       
  1351      Class: CTestScripter
       
  1352 
       
  1353      Method: GetTestScriptObject
       
  1354 
       
  1355      Description: Get object address.
       
  1356   
       
  1357      Parameters: const TDesC& aObjectName: in: object name
       
  1358                     
       
  1359      Return Values: TInt: Symbian error code
       
  1360 
       
  1361      Errors/Exceptions: None
       
  1362 
       
  1363      Status: Draft
       
  1364     
       
  1365 -------------------------------------------------------------------------------
       
  1366 */
       
  1367 TInt CTestScripter::GetTestScriptObject( const TDesC& aObjectName )
       
  1368     {
       
  1369 
       
  1370     TTestObjectBase* objBase = GetObject( aObjectName );
       
  1371     if( ( objBase == NULL ) || 
       
  1372         ( objBase->ObjectType() != TTestObjectBase::EObjectNormal ) )
       
  1373         {
       
  1374         return KErrNotFound;
       
  1375         }
       
  1376     
       
  1377     TTestObject* object = ( TTestObject* )objBase;
       
  1378     
       
  1379     return (TInt) object->iScript;
       
  1380     
       
  1381     }
       
  1382 
       
  1383 /*
       
  1384 -------------------------------------------------------------------------------
       
  1385 
       
  1386      Class: CTestScripter
       
  1387 
       
  1388      Method: UpdateTestCaseResult
       
  1389 
       
  1390      Description: Updates result of test case. If there is already some
       
  1391                   description stored, it is put in the [] brackets.
       
  1392   
       
  1393      Parameters: const TInt aResult: in: error code
       
  1394                  const TDesC& aDescr: in: description
       
  1395                     
       
  1396      Return Values: None
       
  1397 
       
  1398      Errors/Exceptions: None
       
  1399 
       
  1400      Status: Draft
       
  1401     
       
  1402 -------------------------------------------------------------------------------
       
  1403 */
       
  1404 void CTestScripter::UpdateTestCaseResult(const TInt aResult, const TDesC& aDescr)
       
  1405     {
       
  1406     // Create buffer
       
  1407     RBuf buf;
       
  1408 
       
  1409     TInt ret = buf.Create(iResult.iResultDes.Length() + aDescr.Length() + 5);
       
  1410     if(ret != KErrNone)
       
  1411         {
       
  1412         __TRACE(KError, (_L("UpdateResultDescription: descriptor creation failed [%d]"), ret));
       
  1413         return;
       
  1414         }
       
  1415     CleanupClosePushL(buf);
       
  1416 
       
  1417     // Update result
       
  1418     iResult.iResult = aResult;
       
  1419     if(iResult.iResultDes.Length() > 0)
       
  1420         {
       
  1421         buf.Format(_L("%S [%S]"), &aDescr, &iResult.iResultDes);
       
  1422         }
       
  1423     else
       
  1424         {
       
  1425         buf.Copy(aDescr);
       
  1426         }
       
  1427 
       
  1428     SetResultDescription(buf);
       
  1429     
       
  1430     // Close buffer
       
  1431     CleanupStack::PopAndDestroy(&buf);
       
  1432     }
       
  1433 
       
  1434 /*
       
  1435 -------------------------------------------------------------------------------
       
  1436 
       
  1437      Class: CTestScripter
       
  1438 
       
  1439      Method: SetResultDescription
       
  1440 
       
  1441      Description: Sets result description of test case.
       
  1442   
       
  1443      Parameters: const TDesC& aDescr: in: new description
       
  1444                     
       
  1445      Return Values: None
       
  1446 
       
  1447      Errors/Exceptions: None
       
  1448 
       
  1449      Status: Draft
       
  1450     
       
  1451 -------------------------------------------------------------------------------
       
  1452 */
       
  1453 EXPORT_C void CTestScripter::SetResultDescription(const TDesC& aDescr)
       
  1454     {
       
  1455     if(aDescr.Length() > KStifMaxResultDes)
       
  1456         {
       
  1457         iResult.iResultDes.Copy(aDescr.Mid(0, KStifMaxResultDes));
       
  1458         }
       
  1459     else
       
  1460         {
       
  1461         iResult.iResultDes.Copy(aDescr);
       
  1462         }
       
  1463     }
       
  1464 
       
  1465 /*
       
  1466 -------------------------------------------------------------------------------
       
  1467 
       
  1468      Class: CTestScripter
       
  1469 
       
  1470      Method: SetLocalValue
       
  1471 
       
  1472      Description: Internal fuction to set value of local variable defined in script 
       
  1473 
       
  1474      Parameters:    const TDesC& aName: in: local variable name 
       
  1475                     const TDesC& avalue: in: local variable value
       
  1476 
       
  1477      Return Values: KErrNone: Value is returned succesfully.
       
  1478                     KErrNotFound: Variable was not found
       
  1479                     Any other SymbianOS error
       
  1480                     
       
  1481 -------------------------------------------------------------------------------
       
  1482 */
       
  1483 EXPORT_C TInt CTestScripter::SetLocalValue(const TDesC& aName, const TDesC& aValue)
       
  1484     {	
       
  1485     __TRACEFUNC();
       
  1486 
       
  1487     TInt count = iDefinedLocal.Count();
       
  1488     for(TInt i = 0; i < count; i++)
       
  1489         {
       
  1490         if(iDefinedLocal[i]->Name() == aName)
       
  1491             {
       
  1492             iDefinedLocal[i]->SetValueL(const_cast<TDesC&>(aValue));
       
  1493             return KErrNone;
       
  1494             }
       
  1495         }	
       
  1496 
       
  1497     return KErrNotFound;
       
  1498     }
       
  1499 
       
  1500 /*
       
  1501 -------------------------------------------------------------------------------
       
  1502 
       
  1503      Class: CTestScripter
       
  1504 
       
  1505      Method: GetLocalValue
       
  1506 
       
  1507      Description: Internal fuction to get value of local variable 
       
  1508 
       
  1509      Parameters:    const TDesC& aName: in: local variable name 
       
  1510                     const TDesC& avalue: in: local variable value
       
  1511 
       
  1512      Return Values: KErrNone: Value is returned succesfully.
       
  1513                     KErrNotFound: Variable was not found
       
  1514                     Any other SymbianOS error
       
  1515                     
       
  1516 -------------------------------------------------------------------------------
       
  1517 */
       
  1518 EXPORT_C TInt CTestScripter::GetLocalValue(const TDesC& aName, TDes& aValue)
       
  1519     {
       
  1520     __TRACEFUNC();
       
  1521 
       
  1522     TInt count = iDefinedLocal.Count();
       
  1523     for(TInt i = 0; i < count; i++)
       
  1524         {
       
  1525         if(iDefinedLocal[i]->Name() == aName)
       
  1526             {
       
  1527             aValue.Copy(iDefinedLocal[i]->Value());
       
  1528             return KErrNone;
       
  1529             }
       
  1530         }	
       
  1531 
       
  1532     return KErrNotFound;
       
  1533     }
       
  1534 
       
  1535 /*
       
  1536 -------------------------------------------------------------------------------
       
  1537 
       
  1538     DESCRIPTION
       
  1539 
       
  1540     This module contains the implementation of CTestRunner class 
       
  1541     member functions. CTestRunner is used to execute TestScripter testcase by 
       
  1542     CTestScripter.
       
  1543 
       
  1544 -------------------------------------------------------------------------------
       
  1545 */
       
  1546 // MACROS
       
  1547 #ifdef LOGGER
       
  1548 #undef LOGGER
       
  1549 #endif
       
  1550 #define LOGGER iTestScripter->iLog
       
  1551 
       
  1552 // ================= MEMBER FUNCTIONS =========================================
       
  1553 
       
  1554 /*
       
  1555 -------------------------------------------------------------------------------
       
  1556 
       
  1557      Class: CTestRunner
       
  1558 
       
  1559      Method: CTestRunner
       
  1560 
       
  1561      Description: Default constructor
       
  1562 
       
  1563      C++ default constructor can NOT contain any code, that
       
  1564      might leave.
       
  1565      
       
  1566      Parameters: CTestScripter* aTestScripter: in: Backpointer to CTestScripter
       
  1567 
       
  1568      Return Values: None
       
  1569 
       
  1570      Errors/Exceptions: None
       
  1571 
       
  1572      Status: Draft
       
  1573     
       
  1574 -------------------------------------------------------------------------------
       
  1575 */
       
  1576 CTestRunner::CTestRunner( CTestScripter* aTestScripter ): 
       
  1577     CActive(  CActive::EPriorityHigh ), // Executed with highest priority 
       
  1578     iState( ERunnerIdle ),
       
  1579     iTestScripter( aTestScripter ),
       
  1580     iRemainingTimeValue( 0 )
       
  1581     {
       
  1582     CActiveScheduler::Add( this );
       
  1583     __TRACEFUNC();
       
  1584     
       
  1585     }
       
  1586 
       
  1587 /*
       
  1588 -------------------------------------------------------------------------------
       
  1589 
       
  1590      Class: CTestRunner
       
  1591 
       
  1592      Method: ConstructL
       
  1593 
       
  1594      Description: Symbian OS second phase constructor
       
  1595 
       
  1596      Symbian OS default constructor can leave.
       
  1597 
       
  1598      Parameters:    None
       
  1599 
       
  1600      Return Values: None
       
  1601 
       
  1602      Errors/Exceptions: None
       
  1603 
       
  1604      Status: Draft
       
  1605     
       
  1606 -------------------------------------------------------------------------------
       
  1607 */
       
  1608 void CTestRunner::ConstructL()
       
  1609     {
       
  1610     
       
  1611     iPauseTimer.CreateLocal();
       
  1612     
       
  1613     // Initiaze all OOM related variables to default.
       
  1614     OOMHeapToNormal();
       
  1615 
       
  1616     }
       
  1617 
       
  1618 /*
       
  1619 -------------------------------------------------------------------------------
       
  1620 
       
  1621      Class: CTestRunner
       
  1622 
       
  1623      Method: NewL
       
  1624 
       
  1625      Description: Two-phased constructor.
       
  1626           
       
  1627      Parameters: CTestScripter* aTestScripter: in: Backpointer to CTestScripter
       
  1628 
       
  1629      Return Values: CTestRunner*: new object
       
  1630 
       
  1631      Errors/Exceptions: Leaves if new or ConstructL leaves
       
  1632 
       
  1633      Status: Draft
       
  1634     
       
  1635 -------------------------------------------------------------------------------
       
  1636 */
       
  1637 
       
  1638 CTestRunner* CTestRunner::NewL( CTestScripter* aTestScripter )
       
  1639     {
       
  1640     CTestRunner* self = new (ELeave) CTestRunner( aTestScripter );
       
  1641      
       
  1642     CleanupStack::PushL( self );
       
  1643     self->ConstructL();
       
  1644     CleanupStack::Pop();
       
  1645 
       
  1646     return self;
       
  1647     }
       
  1648 
       
  1649 /*
       
  1650 -------------------------------------------------------------------------------
       
  1651 
       
  1652      Class: CTestRunner
       
  1653 
       
  1654      Method: ~CTestRunner
       
  1655 
       
  1656      Description: Destructor
       
  1657      
       
  1658      Parameters:    None
       
  1659 
       
  1660      Return Values: None
       
  1661 
       
  1662      Errors/Exceptions: None
       
  1663 
       
  1664      Status: Approved
       
  1665     
       
  1666 -------------------------------------------------------------------------------
       
  1667 */     
       
  1668 
       
  1669 CTestRunner::~CTestRunner()
       
  1670     {
       
  1671     __TRACEFUNC();
       
  1672     Cancel();
       
  1673 
       
  1674     iPauseTimer.Close();
       
  1675     
       
  1676     delete iLine;
       
  1677     iLine = NULL;
       
  1678     
       
  1679     TInt count = iEventArray.Count();
       
  1680     TEventIf event( TEventIf::ERelEvent ); 
       
  1681     for( TInt i = 0; i < count; i++ )
       
  1682         {
       
  1683         HBufC* tmp = iEventArray[0];
       
  1684         event.SetName( iEventArray[0]->Des() );
       
  1685         iEventArray.Remove(0);
       
  1686 		if( iTestScripter != NULL )
       
  1687 			{
       
  1688 			iTestScripter->TestModuleIf().Event( event );
       
  1689 			}
       
  1690         delete tmp;
       
  1691         }
       
  1692      
       
  1693     iTestCaseResults.Reset();
       
  1694     iEventArray.ResetAndDestroy();
       
  1695     iTestCaseResults.Close();
       
  1696     iEventArray.Close();
       
  1697 
       
  1698     // Reset test case allow result to CTestModuleIf side too. This is
       
  1699     // used in TAL-TA5L macro handling.
       
  1700 	if( iTestScripter != NULL )
       
  1701 		{
       
  1702 		User::LeaveIfError( 
       
  1703 			iTestScripter->TestModuleIf().ResetAllowResult() );
       
  1704 		}
       
  1705 		
       
  1706     // Stop all remaining interference object
       
  1707     TInt count_inter = iTestInterferenceArray.Count();
       
  1708     for( TInt a = 0; a < count_inter; a++ )
       
  1709         {
       
  1710 		if( iTestInterferenceArray[a] != NULL )
       
  1711 			{
       
  1712 			iTestInterferenceArray[a]->iInterference->Stop();
       
  1713 			}
       
  1714         }
       
  1715     iTestInterferenceArray.ResetAndDestroy();
       
  1716     iTestInterferenceArray.Close();
       
  1717     
       
  1718     // Stop all remaining measurement modules
       
  1719     const TInt count_meas = iTestMeasurementArray.Count();
       
  1720     for( TInt b = 0; b < count_meas; b++ )
       
  1721         {
       
  1722 		if( iTestMeasurementArray[b] != NULL )
       
  1723 			{
       
  1724 			iTestMeasurementArray[b]->iMeasurement->Stop();
       
  1725 			}
       
  1726         }
       
  1727     iTestMeasurementArray.ResetAndDestroy();
       
  1728     iTestMeasurementArray.Close();
       
  1729 
       
  1730     }
       
  1731 
       
  1732 /*
       
  1733 -------------------------------------------------------------------------------
       
  1734 
       
  1735      Class: CTestRunner
       
  1736 
       
  1737      Method: RunL
       
  1738 
       
  1739      Description: Derived from CActive, handles testcase execution.
       
  1740 
       
  1741      Parameters:    None.
       
  1742 
       
  1743      Return Values: None.
       
  1744 
       
  1745      Errors/Exceptions: Leaves on error situations.
       
  1746 
       
  1747      Status: Draft
       
  1748     
       
  1749 -------------------------------------------------------------------------------
       
  1750 */
       
  1751 void CTestRunner::RunL()
       
  1752     {
       
  1753     __TRACEFUNC();
       
  1754     __TRACE( KMessage, (_L("CTestRunner::RunL: [%d] "), iStatus.Int() ));
       
  1755      
       
  1756     // Check if we need to Pause test case again  
       
  1757     if( iStatus == KErrNone && iRemainingTimeValue > 0 )
       
  1758         {           
       
  1759         // Maximum time for one RTimer::After request                   
       
  1760         TInt maximumTime = KMaxTInt / 1000;                       
       
  1761         
       
  1762         __TRACE( KMessage, (_L("CTestRunner::RunL: Going to reissue After request ") ) );           
       
  1763         __TRACE( KMessage, (_L("CTestRunner::RunL: iRemainingTimeValue = %d"), iRemainingTimeValue ) );        
       
  1764         
       
  1765         if( iRemainingTimeValue < maximumTime )
       
  1766             {                           
       
  1767             iPauseTimer.After( iStatus, ( iRemainingTimeValue * 1000  ) );
       
  1768             iRemainingTimeValue = 0;
       
  1769             }
       
  1770         else
       
  1771             {            
       
  1772             iRemainingTimeValue -= maximumTime;
       
  1773             iPauseTimer.After( iStatus, ( maximumTime * 1000 ) );                
       
  1774             }     
       
  1775         SetActive();
       
  1776         }     
       
  1777     else    
       
  1778         {  
       
  1779         TBool continueTask = EFalse;
       
  1780 
       
  1781         User::LeaveIfError( iStatus.Int() );
       
  1782 
       
  1783         if( ( iTestScripter == NULL ) || 
       
  1784             ( iTestScripter->iCurrentParser == NULL ) )
       
  1785             {
       
  1786             __TRACE( KError, (_L("CTestRunner invalid arguments")));
       
  1787             User::Leave( KErrGeneral );
       
  1788             }
       
  1789            
       
  1790         iState = ERunnerIdle;
       
  1791 
       
  1792         // Get next execution line from configuration section
       
  1793         TPtrC line;
       
  1794         // If current parser already has read the first line, then read next line.
       
  1795         // Otherwise read the first line.
       
  1796         if(iTestScripter->iCurrentParserReadFirstLine && iTestScripter->iCurrentParser->GetNextLine(line) == KErrNone 
       
  1797            || !iTestScripter->iCurrentParserReadFirstLine && iTestScripter->iCurrentParser->GetLine(KNullDesC, line) == KErrNone)
       
  1798             {
       
  1799             iTestScripter->iCurrentParserReadFirstLine = ETrue;
       
  1800             
       
  1801             // Got new execution line 
       
  1802             __TRACE( KMessage, (_L("Executing line [%S]"), &line));
       
  1803             
       
  1804             CStifItemParser* item = PreprocessLineL( line );
       
  1805                 
       
  1806             CleanupStack::PushL( item ); 
       
  1807               
       
  1808             TPtrC keyword;
       
  1809              // Get first word from line, i.e. keyword
       
  1810             User::LeaveIfError( item->GetString( _L(""), keyword ) );
       
  1811 
       
  1812             __TRACE( KMessage, (_L("CTestRunner execute %S"), &keyword ));
       
  1813 
       
  1814             // Execute script line 
       
  1815             continueTask = ExecuteLineL( keyword, item );
       
  1816             __TRACE( KMessage, (_L("CTestRunner %S executed"), &keyword ));
       
  1817                          
       
  1818             if( continueTask )
       
  1819                 {
       
  1820                   __TRACE( KMessage, (_L("RunL: continueTask")));
       
  1821                  // Set CTestRunner active again to perform 
       
  1822                  // next execution line
       
  1823                  // from testcase section 
       
  1824                 SetRunnerActive();
       
  1825                 }
       
  1826 
       
  1827             CleanupStack::PopAndDestroy( item );
       
  1828             }
       
  1829         else // Stop execution if end of test case
       
  1830             {
       
  1831             __TRACE( KMessage, (_L("Executing line: no more lines from this section")));
       
  1832             // There is no more lines in current parser, but it needs to be
       
  1833             // checked if the parser is not taken for function (sub).
       
  1834             // If this is true, then we have to get back to the parser which
       
  1835             // has called the function.
       
  1836             TInt lastParserIndex = iTestScripter->iParserStack.Count() - 1;
       
  1837             if(lastParserIndex >= 0)
       
  1838                 {
       
  1839                 // Delete current (the last one) parser
       
  1840                 delete iTestScripter->iParserStack[lastParserIndex];
       
  1841                 iTestScripter->iParserStack.Remove(lastParserIndex);
       
  1842                 if(lastParserIndex >= 1) //There is some other parser on the stack
       
  1843                     {
       
  1844                     iTestScripter->iCurrentParser = iTestScripter->iParserStack[lastParserIndex - 1];
       
  1845                     }
       
  1846                 else //The parser stack is empty
       
  1847                     {
       
  1848                     iTestScripter->iCurrentParser = iTestScripter->iSectionParser;
       
  1849                     }
       
  1850                 __TRACE(KMessage, (_L("Returning to calling parser stored on section stack")));
       
  1851                 
       
  1852                 // Continue with the test case
       
  1853                 __TRACE(KMessage, (_L("RunL: continueTask (end of Sub reached)")));
       
  1854                 SetRunnerActive();
       
  1855                 return;
       
  1856                 }
       
  1857             // No more execution lines in testcase section
       
  1858             __TRACE( KMessage, 
       
  1859                 (_L("CTestRunner::RunL: Testcase script done") ));
       
  1860             iTestScripter->TestModuleIf().Printf( KPrintPriLow, 
       
  1861                 _L("RunL"), _L("Script done"));
       
  1862             
       
  1863        
       
  1864             __TRACE( KMessage, 
       
  1865                 (_L("RunL: All TestCases done, stop CActiveScheduler")));
       
  1866             CActiveScheduler::Current()->Stop();
       
  1867             // Now testcase section is executed, 
       
  1868             // so CTestRunner has done its job and stops
       
  1869             }
       
  1870         }
       
  1871     }
       
  1872      
       
  1873 /*
       
  1874 -------------------------------------------------------------------------------
       
  1875 
       
  1876      Class: CTestRunner
       
  1877 
       
  1878      Method: DoCancel
       
  1879 
       
  1880      Description: Derived from CActive handles the Cancel
       
  1881 
       
  1882      Parameters:    None.
       
  1883 
       
  1884      Return Values: None.
       
  1885 
       
  1886      Errors/Exceptions: None.
       
  1887 
       
  1888      Status: Draft
       
  1889     
       
  1890 -------------------------------------------------------------------------------
       
  1891 */
       
  1892 void CTestRunner::DoCancel()
       
  1893     {
       
  1894     __TRACEFUNC();
       
  1895     __TRACE( KMessage, (_L("CTestRunner::DoCancel")));
       
  1896     iTestScripter->TestModuleIf().Printf( KPrintPriLow, _L("Runner"), _L("DoCancel"));
       
  1897     
       
  1898     if( iState == ERunnerPaused )
       
  1899         {
       
  1900         iPauseTimer.Cancel();
       
  1901         }
       
  1902    
       
  1903     CActiveScheduler::Current()->Stop();
       
  1904          
       
  1905     iState = ERunnerCancel;
       
  1906       
       
  1907     }
       
  1908 
       
  1909 /*
       
  1910 -------------------------------------------------------------------------------
       
  1911 
       
  1912      Class: CTestRunner
       
  1913 
       
  1914      Method: RunError
       
  1915 
       
  1916      Description: Derived from CActive handles errors from active handler.
       
  1917   
       
  1918      Parameters:    TInt aError: in: error from CActive
       
  1919      
       
  1920      Return Values: KErrNone: success
       
  1921 
       
  1922      Errors/Exceptions: None.
       
  1923 
       
  1924      Status: Draft
       
  1925     
       
  1926 -------------------------------------------------------------------------------
       
  1927 */
       
  1928 TInt CTestRunner::RunError( TInt aError )
       
  1929     {
       
  1930     __TRACEFUNC();
       
  1931     __TRACE( KMessage, (_L("CTestRunner::RunError %d"), aError));
       
  1932 
       
  1933     if ( iRunErrorMessage.Length() != 0 )
       
  1934     	{
       
  1935 	    iTestScripter->TestModuleIf().Printf( KPrintPriLow, _L("Runner"), 
       
  1936 	            _L("RunError : %S"), &iRunErrorMessage );  
       
  1937 	    iRunErrorMessage = KNullDesC;
       
  1938     	}
       
  1939     else
       
  1940     	{
       
  1941 	    iTestScripter->TestModuleIf().Printf( KPrintPriLow, _L("Runner"), 
       
  1942 	            _L("RunError"));        	
       
  1943     	}
       
  1944 
       
  1945     iState = ERunnerError;
       
  1946     
       
  1947     // Return error from here, if none given from execution
       
  1948     if( iTestScripter->iResult.iResult == KErrNone )
       
  1949         {
       
  1950         iTestScripter->UpdateTestCaseResult(aError, _L("CTestRunner::RunError"));
       
  1951         }
       
  1952         
       
  1953     CActiveScheduler::Current()->Stop();
       
  1954         
       
  1955     return KErrNone;
       
  1956     
       
  1957     }
       
  1958 
       
  1959 /*
       
  1960 -------------------------------------------------------------------------------
       
  1961 
       
  1962      Class: CTestRunner
       
  1963 
       
  1964      Method: PreprocessLineL
       
  1965 
       
  1966      Description: Preprocesses script line
       
  1967   
       
  1968      Parameters:  TPtrC& line: in: script line
       
  1969                   CStifItemParser*& aItem: out: New CItemParser for script line.
       
  1970                     
       
  1971      Return Values: HBufC* pointer if new memory that has been allocated
       
  1972 
       
  1973      Errors/Exceptions: Leaves on error situations.
       
  1974 
       
  1975      Status: Draft
       
  1976     
       
  1977 -------------------------------------------------------------------------------
       
  1978 */        
       
  1979 CStifItemParser* CTestRunner::PreprocessLineL( TDesC& line )
       
  1980     {
       
  1981     CStifItemParser* item = NULL;
       
  1982     TPtrC tmp;
       
  1983     TInt len = 0;
       
  1984     TInt ret = 0;
       
  1985         
       
  1986     // Decide how long buffer should be allocated
       
  1987     if( line.Length() < KMaxName/2 )
       
  1988         {
       
  1989         len = KMaxName;
       
  1990         }
       
  1991     else 
       
  1992         {
       
  1993         len = line.Length() + KMaxName;
       
  1994         }
       
  1995     delete iLine;
       
  1996     iLine = 0;
       
  1997     iLine = HBufC::NewL(len);
       
  1998     TPtr parsedLine(iLine->Des());
       
  1999     len = 0;
       
  2000     
       
  2001     HBufC* sourceLine = line.AllocL();
       
  2002     CleanupStack::PushL(sourceLine);
       
  2003     
       
  2004     //Check for local variable definitions
       
  2005     item = CStifItemParser::NewL(sourceLine->Des(), 0, sourceLine->Length());
       
  2006     CleanupStack::PushL(item);
       
  2007     
       
  2008     ret = item->GetString(KNullDesC, tmp);
       
  2009     TBool isVarDefinition = (tmp == TTestKeywords::Keyword(TTestKeywords::EVar));
       
  2010          
       
  2011     if(!isVarDefinition)
       
  2012         {
       
  2013         while( ret == KErrNone )
       
  2014             {
       
  2015             len += CheckDefinedLocals(tmp);
       
  2016             if((parsedLine.Length() + tmp.Length() + 1) > parsedLine.MaxLength())
       
  2017                 {
       
  2018                 // Allocate bigger buffer
       
  2019                 HBufC* tmpBuf = HBufC::NewL(parsedLine.MaxLength() + KMaxName);
       
  2020                 CleanupStack::PushL(tmpBuf);
       
  2021                 TPtrC ptr(iLine->Des());
       
  2022                 parsedLine.Set(tmpBuf->Des());
       
  2023                 parsedLine.Copy(ptr);
       
  2024                 delete iLine;
       
  2025                 iLine = tmpBuf;
       
  2026                 CleanupStack::Pop(tmpBuf);
       
  2027                 } 
       
  2028             parsedLine.Append(tmp);        
       
  2029             ret = item->GetNextString(tmp);
       
  2030             if(ret == KErrNone)
       
  2031                 {
       
  2032                 // Add space only if we got new string
       
  2033                 parsedLine.Append(_L(" "));        
       
  2034                 }
       
  2035             }
       
  2036         CleanupStack::PopAndDestroy(item);
       
  2037         item = NULL;
       
  2038         CleanupStack::PopAndDestroy(sourceLine);
       
  2039         sourceLine = NULL;
       
  2040         
       
  2041         //Prepare data for checking for defines
       
  2042         sourceLine = parsedLine.AllocL();
       
  2043         CleanupStack::PushL(sourceLine);
       
  2044         parsedLine.Zero();
       
  2045         
       
  2046         item = CStifItemParser::NewL(sourceLine->Des(), 0, sourceLine->Length());
       
  2047         CleanupStack::PushL(item);
       
  2048     
       
  2049         ret = item->GetString(KNullDesC, tmp);
       
  2050         }
       
  2051 
       
  2052     //Check for defines
       
  2053     while(ret == KErrNone)
       
  2054         {
       
  2055         if(!isVarDefinition)
       
  2056             {
       
  2057             len += CheckDefined(tmp);
       
  2058             }
       
  2059         
       
  2060         if((parsedLine.Length() + tmp.Length() + 1) > parsedLine.MaxLength())
       
  2061             {
       
  2062             // Allocate bigger buffer
       
  2063             HBufC* tmpBuf = HBufC::NewL(parsedLine.MaxLength() + KMaxName);
       
  2064             CleanupStack::PushL(tmpBuf);
       
  2065             TPtrC ptr(iLine->Des());
       
  2066             parsedLine.Set(tmpBuf->Des());
       
  2067             parsedLine.Copy(ptr);
       
  2068             delete iLine;
       
  2069             iLine = tmpBuf;
       
  2070             CleanupStack::Pop(tmpBuf);
       
  2071             } 
       
  2072         parsedLine.Append(tmp);        
       
  2073         ret = item->GetNextString(tmp);
       
  2074         if( ret == KErrNone )
       
  2075             {
       
  2076             // Add space only if we got new string
       
  2077             parsedLine.Append(_L(" "));        
       
  2078             }
       
  2079         }
       
  2080     
       
  2081     //Cleaning...
       
  2082     CleanupStack::PopAndDestroy(item);
       
  2083     item = NULL;
       
  2084     CleanupStack::PopAndDestroy(sourceLine);
       
  2085     sourceLine = NULL;
       
  2086 
       
  2087     __TRACE(KMessage, (_L("Preprocessed line [%S]"), &parsedLine));
       
  2088     item = CStifItemParser::NewL( parsedLine, 0, parsedLine.Length() );
       
  2089     
       
  2090     return item;
       
  2091     }
       
  2092 
       
  2093 /*
       
  2094 -------------------------------------------------------------------------------
       
  2095 
       
  2096      Class: CTestRunner
       
  2097 
       
  2098      Method: CheckDefined
       
  2099 
       
  2100      Description: Check if aWord is some defined word
       
  2101   
       
  2102      Parameters:  TPtrC& aWord: inout: Parsed word, defined or original returned
       
  2103                     
       
  2104      Return Values: TInt: length diference between new and old word
       
  2105      
       
  2106      Errors/Exceptions: None.
       
  2107 
       
  2108      Status: Draft
       
  2109     
       
  2110 -------------------------------------------------------------------------------
       
  2111 */   
       
  2112 TInt CTestRunner::CheckDefined( TPtrC& aWord )
       
  2113     {
       
  2114     
       
  2115     TInt len = 0;
       
  2116     TInt i = 0;
       
  2117 
       
  2118     // KLoopCounter word changing to current loop count value.
       
  2119     if( aWord == KLoopCounter )
       
  2120         {
       
  2121         iLoopCounterDes.Zero();
       
  2122         iLoopCounterDes.AppendNum( iLoopCounter );
       
  2123         len = iLoopCounterDes.Length() - aWord.Length();
       
  2124         aWord.Set( iLoopCounterDes );
       
  2125         return len;
       
  2126         }
       
  2127 
       
  2128     // First, check values defined in test case file
       
  2129     TInt count = iTestScripter->iDefinedRuntime.Count();
       
  2130     for( i = 0; i < count; i++ )
       
  2131         {
       
  2132         if( iTestScripter->iDefinedRuntime[i]->Name() == aWord )
       
  2133             { 
       
  2134             len = iTestScripter->iDefinedRuntime[i]->Value().Length() - aWord.Length();
       
  2135             aWord.Set( iTestScripter->iDefinedRuntime[i]->Value() );
       
  2136             return len;
       
  2137             }
       
  2138         }
       
  2139 
       
  2140     // Second, check values defined in test module initialization file
       
  2141     count = iTestScripter->iDefinedIni.Count();
       
  2142     for( i = 0; i < count; i++ )
       
  2143         {
       
  2144         if( iTestScripter->iDefinedIni[i]->Name() == aWord )
       
  2145             { 
       
  2146             len = iTestScripter->iDefinedIni[i]->Value().Length() - aWord.Length();
       
  2147             aWord.Set( iTestScripter->iDefinedIni[i]->Value() );
       
  2148             return len;
       
  2149             }
       
  2150         }
       
  2151 
       
  2152     return len;
       
  2153     }
       
  2154 
       
  2155 /*
       
  2156 -------------------------------------------------------------------------------
       
  2157 
       
  2158      Class: CTestRunner
       
  2159 
       
  2160      Method: CheckDefinedLocals
       
  2161 
       
  2162      Description: Check if aWord is a local variable
       
  2163   
       
  2164      Parameters:  TPtrC& aWord: inout: Parsed word, defined or original returned
       
  2165                     
       
  2166      Return Values: TInt: length diference between new and old word
       
  2167      
       
  2168      Errors/Exceptions: None.
       
  2169 
       
  2170      Status: Draft
       
  2171     
       
  2172 -------------------------------------------------------------------------------
       
  2173 */   
       
  2174 TInt CTestRunner::CheckDefinedLocals( TPtrC& aWord )
       
  2175     {
       
  2176     
       
  2177     TInt len = 0;
       
  2178     TInt i = 0;
       
  2179 
       
  2180     TInt count = iTestScripter->iDefinedLocal.Count();
       
  2181     for(i = 0; i < count; i++)
       
  2182         {
       
  2183         if(iTestScripter->iDefinedLocal[i]->Name() == aWord)
       
  2184             { 
       
  2185             len = iTestScripter->iDefinedLocal[i]->Value().Length() - aWord.Length();
       
  2186             aWord.Set(iTestScripter->iDefinedLocal[i]->Value());
       
  2187             return len;
       
  2188             }
       
  2189         }
       
  2190 
       
  2191     return len;
       
  2192     }
       
  2193 
       
  2194 /*
       
  2195 -------------------------------------------------------------------------------
       
  2196 
       
  2197      Class: CTestRunner
       
  2198 
       
  2199      Method: ExecuteLineL
       
  2200 
       
  2201      Description: Executes script line
       
  2202   
       
  2203      Parameters:    TDesC& aKeyword: in: keyword string
       
  2204                     CStifItemParser* aItem: in: script line
       
  2205                     
       
  2206      Return Values: ETrue: continue script file execution
       
  2207                     EFalse: stop script file execution
       
  2208 
       
  2209      Errors/Exceptions: Leaves on error situations.
       
  2210 
       
  2211      Status: Approved
       
  2212     
       
  2213 -------------------------------------------------------------------------------
       
  2214 */
       
  2215 TBool CTestRunner::ExecuteLineL( TDesC& aKeyword,
       
  2216                                  CStifItemParser* aItem )
       
  2217     {
       
  2218     _LIT( KErrMsgDeleteNoParam, "Delete: Name of object is not defined" );
       
  2219     _LIT( KErrMsgDeleteObjNotFound, "Delete: Can't delete object %S. Object does not exists." );
       
  2220     _LIT( KErrMsgPauseTimeoutNotDefined, "Pause: No timeout value given or value has invalid format" );
       
  2221     _LIT( KErrMsgPauseTimeoutNotPositive, "Pause: Timeout value can't be <0" );
       
  2222     _LIT( KErrMsgCreateTestModeleNotDefined, "Create: Name of test module is not defined" );
       
  2223     _LIT( KErrMsgCreateObjectIdNotDefined, "Create: Name of test module object is not defined" );
       
  2224     _LIT( KErrMsgCreateKernelDriverNotDefined, "CreateKernel: Kernel driver name is not defined" );
       
  2225     _LIT( KErrMsgCreateKernelObjectNameNotDefined, "CreateKernel: Kernel driver object name is not defined" );
       
  2226     _LIT( KErrMsgCreateKernelFailed, "CreateKernel: Can't creeate kernel driver %S" );
       
  2227     _LIT( KErrMsgWaitTestClassNameNotDefined, "WaitTestClass: Test class object name is not defined" );
       
  2228     _LIT( KErrMsgWaitTestClassObjNotFound, "WaitTestClass: Test class object %S does not exists" );
       
  2229     _LIT( KErrMsgLoopNested, "Loop: Nested loop are not supported" );
       
  2230     _LIT( KErrMsgLoopNoParam, "Loop: No loop iterations count given or value has invalid format" );
       
  2231     _LIT( KErrMsgLoopInvalidParam, "Loop: Loop count must be >0" );
       
  2232     _LIT( KErrMsgLoopUnknownUnexpectedOption, "Loop: Unknown or unexpected loop option");
       
  2233     _LIT( KErrMsgEndLoopNotOpened, "Endloop: Can't execute endloop. No opened loop exists" );
       
  2234     _LIT( KErrMsgBringToForegroundNotSupported, "BringToForeground: BringToForeground is not supported in non s60 environment" );
       
  2235     _LIT( KErrMsgSendToBackgroundNotSupported, "SendToBackground: SendToBackground is not supported in non s60 environment" );    
       
  2236     _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" );
       
  2237     _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" );
       
  2238     _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" );
       
  2239     _LIT( KErrVarNameError, "Variable: Could not get variable name");
       
  2240     _LIT( KErrVarValueError, "Variable: Value too long");
       
  2241     _LIT( KErrSubNameError, "Sub: Could not get name of Sub to be called");
       
  2242     _LIT( KErrSubGetError, "Sub: Could not get Sub section");
       
  2243     
       
  2244     iRunErrorMessage = KNullDesC;    
       
  2245     TBool continueTask = ETrue;
       
  2246     
       
  2247     TInt key = TTestKeywords::Parse( aKeyword, TTestKeywords::Keyword );
       
  2248 
       
  2249     switch( key )
       
  2250         {
       
  2251         // Test case execution control cases
       
  2252         case TTestKeywords::ECreate:
       
  2253         case TTestKeywords::ECreateX:
       
  2254             {
       
  2255             TPtrC tmp;
       
  2256             TName module;
       
  2257 
       
  2258             // Testmodule name
       
  2259             TInt ret = aItem->GetNextString( tmp );
       
  2260             if ( ret != KErrNone )
       
  2261             	{
       
  2262             	iRunErrorMessage = KErrMsgCreateTestModeleNotDefined;
       
  2263             	User::Leave( KErrArgument );
       
  2264             	}
       
  2265             TParse p;
       
  2266             p.Set( tmp, NULL, NULL );
       
  2267             // Check if exists in module name
       
  2268             if( p.ExtPresent() )
       
  2269                 {
       
  2270                 module.Copy( tmp );
       
  2271                 }
       
  2272             else 
       
  2273                 {
       
  2274                 // No extension in module name, add it here
       
  2275                 _LIT( KDllExtension, ".dll");
       
  2276                 module.Copy( tmp );
       
  2277                 module.Append( KDllExtension );
       
  2278                 }
       
  2279 
       
  2280             // objectid
       
  2281             ret = aItem->GetNextString( tmp );
       
  2282             if ( ret != KErrNone )
       
  2283             	{
       
  2284             	iRunErrorMessage = KErrMsgCreateObjectIdNotDefined;
       
  2285             	User::Leave( KErrArgument );
       
  2286             	}        
       
  2287 
       
  2288             __TRACE( KMessage, (_L("%S %S"), &aKeyword, &tmp));
       
  2289             iTestScripter->TestModuleIf().Printf( KPrintPriLow, _L("Runner"), 
       
  2290                 _L("%S %S"), &aKeyword, &tmp);
       
  2291 
       
  2292             iTestScripter->CreateObjectL( module, tmp );
       
  2293             }
       
  2294             break;
       
  2295         case TTestKeywords::ECreateKernel:
       
  2296             {
       
  2297             TPtrC obj;
       
  2298             TPtrC driver;
       
  2299 
       
  2300             // Testdriver name
       
  2301             TInt ret = aItem->GetNextString( driver );
       
  2302             if ( ret != KErrNone )
       
  2303             	{
       
  2304             	iRunErrorMessage = KErrMsgCreateKernelDriverNotDefined;
       
  2305             	User::Leave( ret );
       
  2306             	}
       
  2307 
       
  2308             // objectid            
       
  2309             ret = aItem->GetNextString( obj );
       
  2310             if ( ret != KErrNone )
       
  2311             	{
       
  2312             	iRunErrorMessage = KErrMsgCreateKernelObjectNameNotDefined;
       
  2313             	User::Leave( ret );
       
  2314             	}
       
  2315 
       
  2316             __TRACE( KMessage, (_L("%S %S"), &aKeyword, &obj));
       
  2317             iTestScripter->TestModuleIf().Printf( KPrintPriLow, _L("Runner"), 
       
  2318                 _L("%S %S"), &aKeyword, &obj);
       
  2319             TInt leaveErr = KErrNone;
       
  2320             TRAP( leaveErr, iTestScripter->CreateKernelObjectL( driver, obj ));
       
  2321             if ( leaveErr != KErrNone )
       
  2322             	{
       
  2323             	iRunErrorMessage.Format( KErrMsgCreateKernelFailed, &driver );
       
  2324                 User::Leave( leaveErr );
       
  2325             	}
       
  2326             }
       
  2327             break;
       
  2328         case TTestKeywords::EDelete:
       
  2329             {
       
  2330             TPtrC tmp;
       
  2331             // objectid
       
  2332             TInt ret = aItem->GetNextString( tmp );
       
  2333             if ( ret != KErrNone )
       
  2334             	{
       
  2335                 iRunErrorMessage = KErrMsgDeleteNoParam;
       
  2336             	User::Leave( ret );
       
  2337             	}
       
  2338 
       
  2339             __TRACE( KMessage, (_L("%S %S"), &aKeyword, &tmp));
       
  2340             iTestScripter->TestModuleIf().Printf( KPrintPriLow, _L("Runner"), 
       
  2341                 _L("%S %S"), &aKeyword, &tmp);
       
  2342 
       
  2343             ret = iTestScripter->DeleteObjectL( tmp );
       
  2344             if ( ret != KErrNone )
       
  2345             	{
       
  2346             	iRunErrorMessage.Format( KErrMsgDeleteObjNotFound, &tmp );
       
  2347             	User::Leave( ret );
       
  2348             	}
       
  2349             }
       
  2350             break;
       
  2351         case TTestKeywords::ERequest:
       
  2352         case TTestKeywords::EWait:
       
  2353         case TTestKeywords::ERelease:
       
  2354         case TTestKeywords::ESet:
       
  2355         case TTestKeywords::EUnset:
       
  2356             continueTask = ExecuteEventL( aKeyword, aItem );
       
  2357             break;
       
  2358         case TTestKeywords::EPrint:
       
  2359             {
       
  2360             __TRACE( KMessage, (_L("%S"), &aKeyword));
       
  2361             iTestScripter->TestModuleIf().Printf( KPrintPriLow, _L("Runner"), 
       
  2362                 _L("%S"), &aKeyword );
       
  2363 
       
  2364             TName buf;
       
  2365             TPtrC tmp;
       
  2366 
       
  2367             while( aItem->GetNextString( tmp ) == KErrNone )
       
  2368                 {
       
  2369                 if( buf.Length() + tmp.Length() >= buf.MaxLength() )
       
  2370                     {
       
  2371                     break;
       
  2372                     }
       
  2373                 buf.Append( tmp );
       
  2374                 buf.Append( _L(" ") );
       
  2375                 }
       
  2376             
       
  2377             iTestScripter->TestModuleIf().Printf( KPrintPriNorm, 
       
  2378                 _L("Test"), 
       
  2379                 _L("%S"), &buf);
       
  2380             RDebug::Print( _L("Print : Test : %S"), &buf );
       
  2381             }
       
  2382             break;
       
  2383         case TTestKeywords::EAllowNextResult:
       
  2384             {
       
  2385             AddTestCaseResultL( aItem );
       
  2386             }
       
  2387             break;
       
  2388         case TTestKeywords::EWaitTestClass:
       
  2389             {
       
  2390             // Just stop script running, continue event is signaled 
       
  2391             // from test class with specified object name
       
  2392             TPtrC objectName;
       
  2393             // Get Object name
       
  2394             TInt ret = aItem->GetNextString( objectName );
       
  2395             if ( ret != KErrNone )
       
  2396             	{
       
  2397                	iRunErrorMessage = KErrMsgWaitTestClassNameNotDefined;
       
  2398             	User::Leave( ret );
       
  2399             	}
       
  2400             TTestObjectBase* obj = iTestScripter->GetObject ( objectName );
       
  2401             //User::LeaveIfNull( obj );
       
  2402             if( obj == NULL )
       
  2403                 {
       
  2404                	iRunErrorMessage.Format( KErrMsgWaitTestClassObjNotFound, &objectName );
       
  2405                 User::Leave( KErrGeneral );
       
  2406                 }
       
  2407             continueTask = obj->Wait();
       
  2408             
       
  2409             if( continueTask )
       
  2410                 {
       
  2411                 // If OOM testing is ongoing ignore result check(given by user)
       
  2412                 if( !iTestScripter->iOOMIgnoreFailure )
       
  2413                     {
       
  2414                     if( iTestCaseResults.Count() == 0 )
       
  2415                         {
       
  2416                         // KErrNone is the default result expected 
       
  2417                         // if nothing else is given 
       
  2418                         User::LeaveIfError( iTestCaseResults.Append( 
       
  2419                                                                 KErrNone ) );
       
  2420                         }
       
  2421                     
       
  2422                     if( iTestCaseResults.Find( obj->iAsyncResult ) < 0 ) 
       
  2423                         {
       
  2424                         __TRACE( KError, ( _L("Command for [%S] failed (%d)"), 
       
  2425                                 &objectName, obj->iAsyncResult ));
       
  2426                         iTestScripter->UpdateTestCaseResult(obj->iAsyncResult, _L("CTestRunner::ExecuteLineL: asynchronous method returned error"));
       
  2427                         // Stops execution from CTestRunner::RunError
       
  2428                         User::Leave( KErrGeneral );
       
  2429                         }
       
  2430                     }
       
  2431                 else
       
  2432                     {
       
  2433                     __TRACE( KMessage, ( 
       
  2434                         _L( "OOM test: 'oomignorefailure' is ON, test case result will reset" ) ) );
       
  2435                     }
       
  2436 
       
  2437                 iTestCaseResults.Reset();
       
  2438                 // Reset test case allow result to CTestModuleIf side too. This is
       
  2439                 // used in TAL-TA5L macro handling.
       
  2440                 User::LeaveIfError( 
       
  2441                     iTestScripter->TestModuleIf().ResetAllowResult() );
       
  2442                 }
       
  2443 
       
  2444             }
       
  2445             break;
       
  2446         case TTestKeywords::EPause:
       
  2447             {
       
  2448             // Maximum time for one RTimer::After request
       
  2449             TInt maximumTime = KMaxTInt / 1000;
       
  2450             // Set iRemainingTimeValue to zero
       
  2451             iRemainingTimeValue = 0;
       
  2452 
       
  2453             TInt timeout;
       
  2454             // Read valid results to timeout
       
  2455             if( aItem->GetNextInt( timeout ) != KErrNone )
       
  2456                 {
       
  2457                 __TRACE( KError, (_L("CTestRunner::ExecuteLineL: No timeout value given for pause")));
       
  2458                 iRunErrorMessage = KErrMsgPauseTimeoutNotDefined;
       
  2459                 User::Leave( KErrArgument );
       
  2460                 }
       
  2461 
       
  2462             // Test case file parsing was success
       
  2463 
       
  2464             __TRACE( KMessage, (_L("CTestRunner::ExecuteLineL: Pause for %d milliseconds"), timeout));
       
  2465 
       
  2466             if( timeout < 0 )
       
  2467                 {
       
  2468                 __TRACE( KError, (_L("CTestRunner::ExecuteLineL: Given pause value < 0")));
       
  2469                 iRunErrorMessage = KErrMsgPauseTimeoutNotPositive;
       
  2470                 User::Leave( KErrArgument );
       
  2471                 }
       
  2472             else
       
  2473                 {
       
  2474                 // Check is pause value suitable for RTimer::After
       
  2475                 if( timeout < maximumTime )
       
  2476                     {
       
  2477                     iPauseTimer.After( iStatus, ( timeout * 1000  ) );
       
  2478                     }
       
  2479                 else
       
  2480                     {
       
  2481                     // Given pause value after multiplication with 1000 is
       
  2482                     // larger than KMaxTInt, so we need to split it and 
       
  2483                     // re-request After with remaining value from RunL
       
  2484 
       
  2485                     iRemainingTimeValue =  timeout - maximumTime;
       
  2486                     iPauseTimer.After( iStatus, maximumTime * 1000 );
       
  2487                     }
       
  2488 
       
  2489                 SetActive();
       
  2490 
       
  2491                 // Stop execution after paused for given timeout
       
  2492                 continueTask = EFalse;
       
  2493                 }
       
  2494             }
       
  2495             break;
       
  2496         case TTestKeywords::ELoop:
       
  2497             {
       
  2498             if( iLoopTimes > 0 )
       
  2499                 {
       
  2500                 __TRACE( KError, (_L("ExecuteLineL: Nested loop are not supported")));
       
  2501                 iRunErrorMessage = KErrMsgLoopNested;
       
  2502                 User::Leave( KErrNotSupported );
       
  2503                 }
       
  2504             iLoopTimes = 0;
       
  2505             iLoopCounter = 0;
       
  2506             iTimedLoop = EFalse;
       
  2507             if( aItem->GetNextInt( iLoopTimes ) != KErrNone )
       
  2508                 {
       
  2509                 __TRACE( KError, (_L("ExecuteLineL: No loop count value given for loop")));
       
  2510                 iRunErrorMessage = KErrMsgLoopNoParam;
       
  2511                 User::Leave( KErrArgument );
       
  2512                 }
       
  2513             if( iLoopTimes < 1 )
       
  2514             	{
       
  2515                 __TRACE( KError, (_L("ExecuteLineL: Loop count must be >0")));
       
  2516                 iRunErrorMessage = KErrMsgLoopInvalidParam;
       
  2517                 User::Leave( KErrArgument );
       
  2518             	}
       
  2519             __TRACE( KMessage, (_L("ExecuteLineL: Loop for %d times" ), iLoopTimes ) );
       
  2520             
       
  2521             //Check loop options
       
  2522             TPtrC option;
       
  2523             TInt ret = aItem->GetNextString(option);
       
  2524             if(ret == KErrNone)
       
  2525                 {
       
  2526                 if(option.Compare(_L("msec")) == 0) //time loop option
       
  2527                     {
       
  2528                     iTimedLoop = ETrue;
       
  2529                     iStartTime.HomeTime();
       
  2530                     iExpectedLoopTime = TInt64(iLoopTimes) * TInt64(1000); //convert to micro seconds
       
  2531                     __TRACE(KMessage, (_L("ExecuteLineL: Timed loop for %d msec" ), iLoopTimes));
       
  2532                     
       
  2533                     ret = aItem->GetNextString(option); //Get next option
       
  2534                     }
       
  2535                 }
       
  2536                 
       
  2537             if(ret == KErrNone)
       
  2538                 {
       
  2539                 __TRACE( KError, (_L("ExecuteLineL: Unknown or unexpected loop option [%S]"), &option));
       
  2540                 iRunErrorMessage = KErrMsgLoopUnknownUnexpectedOption;
       
  2541                 User::Leave( KErrNotSupported );
       
  2542                 }
       
  2543             
       
  2544             iLoopStartPos = iTestScripter->iCurrentParser->GetPosition();
       
  2545             }
       
  2546             break;
       
  2547         case TTestKeywords::EEndLoop:
       
  2548             {
       
  2549             if( iLoopTimes == 0 )
       
  2550             	{
       
  2551             	__TRACE( KError, (_L("ExecuteLineL: Can't execute endloop. No opened loop exists")));
       
  2552             	iRunErrorMessage = KErrMsgEndLoopNotOpened;
       
  2553             	User::Leave( KErrNotFound );
       
  2554             	}
       
  2555             iLoopCounter++;
       
  2556             __TRACE( KMessage, 
       
  2557                 (_L("ExecuteLineL: Loop executed for %d times" ), 
       
  2558                     iLoopCounter ) );
       
  2559 
       
  2560             TTime currTime;
       
  2561             currTime.HomeTime();
       
  2562             if(((!iTimedLoop) && (iLoopCounter < iLoopTimes)) //Normal loop
       
  2563                ||
       
  2564                iTimedLoop && (currTime.MicroSecondsFrom(iStartTime) < iExpectedLoopTime)) //Timed loop
       
  2565                 {
       
  2566                 // Go to beginning of the loop
       
  2567                 User::LeaveIfError(
       
  2568                     iTestScripter->iCurrentParser->SetPosition( iLoopStartPos ));
       
  2569                 }
       
  2570             else
       
  2571                 {            
       
  2572                 // End looping
       
  2573                 iLoopCounter = 0;
       
  2574                 iLoopTimes = 0;
       
  2575                 iLoopStartPos = 0;
       
  2576                 }
       
  2577             }
       
  2578             break;
       
  2579         case TTestKeywords::ETimeout:
       
  2580         case TTestKeywords::EPriority:
       
  2581             // not used here
       
  2582             break;
       
  2583         case TTestKeywords::EOOMIgnoreFailure:
       
  2584             {
       
  2585             OOMIgnoreFailureL( aItem );  // Handle parsing
       
  2586             break;
       
  2587             }
       
  2588         case TTestKeywords::EOOMHeapFailNext:
       
  2589             {
       
  2590             OOMHeapFailNextL( aItem );   // Handle parsing
       
  2591             break;
       
  2592             }
       
  2593         case TTestKeywords::EOOMHeapSetFail:
       
  2594             {
       
  2595             OOMHeapSetFailL( aItem );    // Handle parsing
       
  2596             break;
       
  2597             }
       
  2598        case TTestKeywords::EOOMHeapToNormal:
       
  2599             {
       
  2600             // Initialize all OOM related variables back to default.
       
  2601             OOMHeapToNormal();
       
  2602             __TRACE( KMessage, (
       
  2603                 _L( "'oomheaptonormal' called, OOM initialization or ending OOM test") ) );
       
  2604             break;
       
  2605             }
       
  2606        case TTestKeywords::ETestInterference:
       
  2607             {
       
  2608             TestInterferenceL( aItem );  // Handle parsing
       
  2609             break;
       
  2610             }
       
  2611        case TTestKeywords::EMeasurement:
       
  2612             {
       
  2613             MeasurementL( aItem );      // Handle parsing
       
  2614             break;
       
  2615             }
       
  2616        case TTestKeywords::EAllowErrorCodes:
       
  2617             {
       
  2618             // Check is KErrNone already appended to iTestCaseResults array.
       
  2619             if( iTestCaseResults.Find( KErrNone ) < 0 )
       
  2620                 {
       
  2621                 // 'allowerrorcodes' keyword sets KErrNone as a default
       
  2622                 User::LeaveIfError( iTestCaseResults.Append( KErrNone ) );
       
  2623                 // Set test case allow result to CTestModuleIf side too. This
       
  2624                 // is used in TAL-TA5L macro handling.
       
  2625                 User::LeaveIfError( 
       
  2626                     iTestScripter->TestModuleIf().SetAllowResult( KErrNone ) );
       
  2627                 }
       
  2628 
       
  2629             // Set user given specific error code to be allowed.
       
  2630             AddTestCaseResultL( aItem );
       
  2631             }
       
  2632             break;
       
  2633 
       
  2634        case TTestKeywords::EBringToForeground:
       
  2635     	   {
       
  2636     	   if ( iTestScripter->TestModuleIf().UITesting() == true )
       
  2637     		   {
       
  2638     		   iTestScripter->TestModuleIf().GetUiEnvProxy()->BringToForeground();
       
  2639     		   }
       
  2640     	   else
       
  2641     		   {
       
  2642 	           	__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")));
       
  2643 	        	iRunErrorMessage = KErrMsgBringToForegroundNotSupported;
       
  2644 	        	User::Leave( KErrNotSupported );    		   
       
  2645     		   }
       
  2646     	   }
       
  2647        		break;
       
  2648        case TTestKeywords::ESendToBackground:
       
  2649     	   {
       
  2650     	   if ( iTestScripter->TestModuleIf().UITesting() == true )
       
  2651     		   {
       
  2652     		   iTestScripter->TestModuleIf().GetUiEnvProxy()->SendToBackground();
       
  2653     		   }
       
  2654     	   else
       
  2655     		   {
       
  2656 	           	__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")));
       
  2657 	        	iRunErrorMessage = KErrMsgSendToBackgroundNotSupported;
       
  2658 	        	User::Leave( KErrNotSupported );    		   
       
  2659     		   }
       
  2660     	   }
       
  2661        		break;
       
  2662        case TTestKeywords::EPressKey:
       
  2663     	   {
       
  2664     	   if ( iTestScripter->TestModuleIf().UITesting() == true )
       
  2665     		   {
       
  2666     		   continueTask = PressKeyL( aItem );
       
  2667     		   }
       
  2668     	   else
       
  2669     		   {
       
  2670     		   __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")));
       
  2671     		   iRunErrorMessage = KErrMsgPressKeyNotSupported;
       
  2672     		   User::Leave( KErrNotSupported );    		   
       
  2673     		   }	
       
  2674 
       
  2675     	   // Check if it was global or local presskey
       
  2676     	   if ( !continueTask )
       
  2677     		   {
       
  2678 	           // Stop execution after key is pressed and wait until it is handled
       
  2679 	           SetActive();
       
  2680     		   }           
       
  2681     	   }
       
  2682        		break;
       
  2683        case TTestKeywords::ETypeText:
       
  2684     	   {
       
  2685     	   if ( iTestScripter->TestModuleIf().UITesting() == true )
       
  2686     		   {
       
  2687     		   continueTask = TypeTextL( aItem );
       
  2688     		   }
       
  2689     	   else
       
  2690     		   {
       
  2691     		   __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")));
       
  2692     		   iRunErrorMessage = KErrMsgTypeTextNotSupported;
       
  2693     		   User::Leave( KErrNotSupported );    		   
       
  2694     		   }
       
  2695 
       
  2696     	   // Check if it was global or local typetext
       
  2697     	   if ( !continueTask )
       
  2698     		   {
       
  2699 	           // Stop execution after key is pressed and wait until it is handled
       
  2700 	           SetActive();
       
  2701     		   }           
       
  2702     	   }
       
  2703        		break;
       
  2704         case TTestKeywords::EVar:
       
  2705             {
       
  2706             TName name;
       
  2707             TName buf;
       
  2708             TPtrC tmp;
       
  2709             
       
  2710             //Get variable name
       
  2711             if(aItem->GetNextString(tmp) == KErrNone)
       
  2712                 {
       
  2713                 name.Copy(tmp);
       
  2714                 }
       
  2715             else
       
  2716                 {
       
  2717                 //Error when getting variable name
       
  2718                 __TRACE(KError, (_L("ExecuteLineL: Could not read variable name")));
       
  2719                 iRunErrorMessage = KErrVarNameError;
       
  2720                 User::Leave(KErrArgument);                
       
  2721                 }
       
  2722 
       
  2723             //Get value for variable
       
  2724             while(aItem->GetNextString(tmp) == KErrNone)
       
  2725                 {
       
  2726                 if(buf.Length() + tmp.Length() >= buf.MaxLength())
       
  2727                     {
       
  2728                     //Error when getting variable name
       
  2729                     __TRACE(KError, (_L("ExecuteLineL: Variable value too long")));
       
  2730                     iRunErrorMessage = KErrVarValueError;
       
  2731                     User::Leave(KErrArgument);                
       
  2732                     }
       
  2733                 buf.Append(tmp);
       
  2734                 buf.Append(_L(" "));
       
  2735                 }
       
  2736             //Remove last space
       
  2737             if(buf.Length() > 0)
       
  2738                 {
       
  2739                 buf.SetLength(buf.Length() - 1);
       
  2740                 }
       
  2741                 
       
  2742             //Store local variable
       
  2743             TInt count = iTestScripter->iDefinedLocal.Count();
       
  2744             TInt i;
       
  2745             for(i = 0; i < count; i++)
       
  2746                 {
       
  2747                 if(iTestScripter->iDefinedLocal[i]->Name() == name)
       
  2748                     {
       
  2749                     // Update existing
       
  2750                     iTestScripter->iDefinedLocal[i]->SetValueL(buf);
       
  2751                     __TRACE(KMessage, (_L("Update local variable [%S]: [%S]"), &name, &buf));
       
  2752                     break;
       
  2753                     }
       
  2754                 }
       
  2755             if(i == count)
       
  2756                 {
       
  2757                 // New define, store it
       
  2758                 CDefinedValue* define = CDefinedValue::NewL(name, buf);
       
  2759                 CleanupStack::PushL(define);
       
  2760                 User::LeaveIfError(iTestScripter->iDefinedLocal.Append(define));
       
  2761                 CleanupStack::Pop(define);
       
  2762                 __TRACE(KMessage, (_L("Add local variable [%S]: [%S]"), &name, &buf));
       
  2763                 }
       
  2764             }
       
  2765             break;
       
  2766         case TTestKeywords::ECallSub:
       
  2767             {
       
  2768             // Get sub name
       
  2769             TPtrC subName;
       
  2770             
       
  2771             //Get sub name
       
  2772             TInt err = aItem->GetNextString(subName);
       
  2773             if(err != KErrNone)
       
  2774                 {
       
  2775                 //Error when getting sub name
       
  2776                 __TRACE(KError, (_L("ExecuteLineL: Could not read sub name [%d]"), err));
       
  2777                 iRunErrorMessage = KErrSubNameError;
       
  2778                 User::Leave(KErrArgument);                
       
  2779                 }
       
  2780             
       
  2781             // Load section
       
  2782             CStifSectionParser* subSection = NULL;
       
  2783             TRAP(err, 
       
  2784                  subSection = iTestScripter->GetSubL(subName);
       
  2785                 );
       
  2786             if((err != KErrNone) || (!subSection))
       
  2787                 {
       
  2788                 //Error when getting sub name
       
  2789                 if(err == KErrNone)
       
  2790                     {
       
  2791                     err = KErrArgument;
       
  2792                     }
       
  2793                 __TRACE(KError, (_L("ExecuteLineL: Could not get section for sub [%d]"), err));
       
  2794                 iRunErrorMessage = KErrSubGetError;
       
  2795                 User::Leave(err);                
       
  2796                 }
       
  2797             
       
  2798             // Handle new section parser
       
  2799             CleanupStack::PushL(subSection);
       
  2800             iTestScripter->iParserStack.AppendL(subSection);
       
  2801             __TRACE(KMessage, (_L("ExecuteLineL: Section for sub [%S] appended to section stack"), &subName));
       
  2802             CleanupStack::Pop(subSection);
       
  2803             iTestScripter->iCurrentParser = subSection;
       
  2804             iTestScripter->iCurrentParserReadFirstLine = EFalse; //Change it to false, becaue subSection is a new parser and it has nothing read
       
  2805             }
       
  2806             break;
       
  2807         case TTestKeywords::ESetResultDescription:
       
  2808             {
       
  2809             __TRACE(KMessage, (_L("%S"), &aKeyword));
       
  2810             iTestScripter->TestModuleIf().Printf(KPrintPriLow, _L("Runner"), _L("%S"), &aKeyword);
       
  2811 
       
  2812             TName buf;
       
  2813             TPtrC tmp;
       
  2814 
       
  2815             while(aItem->GetNextString(tmp) == KErrNone)
       
  2816                 {
       
  2817                 if(buf.Length() + tmp.Length() >= buf.MaxLength())
       
  2818                     {
       
  2819                     break;
       
  2820                     }
       
  2821                 if(buf.Length() > 0)
       
  2822                     {
       
  2823                     buf.Append(_L(" "));
       
  2824                     }
       
  2825                 buf.Append(tmp);
       
  2826                 }
       
  2827             
       
  2828             iTestScripter->SetResultDescription(buf);
       
  2829             RDebug::Print( _L("SetDescription to [%S]"), &buf );
       
  2830             }
       
  2831             break;
       
  2832         case TTestKeywords::ESendPointerEvent:
       
  2833      	   {
       
  2834      	   if ( iTestScripter->TestModuleIf().UITesting() == true )
       
  2835      		   {
       
  2836      		   continueTask = SendPointerEventL( aItem );
       
  2837      		   }
       
  2838      	   else
       
  2839      		   {
       
  2840      		   __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")));
       
  2841      		   iRunErrorMessage = KErrMsgSendPointerEventNotSupported;
       
  2842      		   User::Leave( KErrNotSupported );    		   
       
  2843      		   }
       
  2844 
       
  2845      	   // Check if it was global or local sendpointerevent
       
  2846      	   if ( !continueTask )
       
  2847      		   {
       
  2848  	           // Stop execution after pointer event is send and wait until it is handled
       
  2849  	           SetActive();
       
  2850      		   }           
       
  2851      	   }
       
  2852      	   break;
       
  2853         default:
       
  2854             {
       
  2855             continueTask = ExecuteCommandL( aKeyword, aItem );
       
  2856             }
       
  2857             break;
       
  2858         }
       
  2859 
       
  2860     __TRACE( KMessage, (_L("ExecuteLineL: TestCase line executed")));
       
  2861 
       
  2862     return continueTask;
       
  2863     }
       
  2864 
       
  2865 /*
       
  2866 -------------------------------------------------------------------------------
       
  2867 
       
  2868      Class: CTestRunner
       
  2869 
       
  2870      Method: PressKeyL
       
  2871 
       
  2872      Description: Send key press event to AppUi
       
  2873   
       
  2874      Parameters:    CStifItemParser* aItem: in: script line
       
  2875      
       
  2876      Return Values: None
       
  2877 
       
  2878      Errors/Exceptions: Leaves on error situations.
       
  2879 
       
  2880      Status: Draft
       
  2881     
       
  2882 -------------------------------------------------------------------------------
       
  2883 */
       
  2884 TBool CTestRunner::PressKeyL( CStifItemParser* aItem )
       
  2885 	{
       
  2886     _LIT( KErrMsgSendKeyEventInvalidParameterValue, "PressKey: Invalid parameter %s value " );
       
  2887     _LIT( KErrMsgSendKeyEventInvalidParameter, "PressKey: Invalid parameter %s" );    
       
  2888     
       
  2889     _LIT( KKeyCodeParameter, "keycode=" );
       
  2890     _LIT( KKeyScanCodeParameter, "keyscancode=" );
       
  2891     _LIT( KModifierParameter, "modifier=" );
       
  2892     _LIT( KRepeatsParameter, "repeats=" );
       
  2893     
       
  2894     _LIT( KModeGlobal, "global" );
       
  2895     _LIT( KModeLocal, "local" );
       
  2896     
       
  2897     TBool globalMode = EFalse;
       
  2898 	TUint keyCode = 0; 
       
  2899 	TInt keyScanCode = 0; 
       
  2900 	TUint keyModifiers = 0; 
       
  2901 	TInt keyRepeats = 0;
       
  2902 		
       
  2903 	TPtrC parameter;
       
  2904 		
       
  2905 	CUiEnvProxy* uiEnvProxy = iTestScripter->TestModuleIf().GetUiEnvProxy();
       
  2906 	
       
  2907 	while( aItem->GetNextString( parameter ) == KErrNone )
       
  2908 		{
       
  2909 		if ( parameter.Find( KKeyCodeParameter ) == 0 )
       
  2910 			{
       
  2911 			TPtrC parameterValue = parameter.Right( parameter.Length() - KKeyCodeParameter().Length() );
       
  2912 			TLex parameterValueParser( parameterValue );
       
  2913 			if ( parameterValueParser.Val( keyCode ) != KErrNone )
       
  2914 				{
       
  2915 					if ( uiEnvProxy->ParseKeyCode( parameterValue, keyCode ) != KErrNone )
       
  2916 						{
       
  2917 						__TRACE( KError, (_L("SendKeyEvent: Invalid parameter value")));
       
  2918 						TBuf<128> errMsg;
       
  2919 						errMsg.Format( KErrMsgSendKeyEventInvalidParameterValue, &KKeyCodeParameter() );
       
  2920 						iRunErrorMessage = errMsg;
       
  2921 						User::Leave( KErrArgument );    		   				
       
  2922 						}
       
  2923 				}
       
  2924 			}
       
  2925 		else if ( parameter.Find( KKeyScanCodeParameter ) == 0 )
       
  2926 			{
       
  2927 			TPtrC parameterValue = parameter.Right( parameter.Length() - KKeyScanCodeParameter().Length() );
       
  2928 			TLex parameterValueParser( parameterValue );
       
  2929 			if ( parameterValueParser.Val( keyScanCode ) != KErrNone )
       
  2930 				{
       
  2931 				if ( uiEnvProxy->ParseKeyScanCode( parameterValue, keyScanCode ) != KErrNone )
       
  2932 					{
       
  2933 					__TRACE( KError, (_L("SendKeyEvent: Invalid parameter value")));
       
  2934 					TBuf<128> errMsg;
       
  2935 					errMsg.Format( KErrMsgSendKeyEventInvalidParameterValue, &KKeyCodeParameter() );
       
  2936 					iRunErrorMessage = errMsg;
       
  2937 					User::Leave( KErrArgument );    		   				
       
  2938 					}
       
  2939 				}
       
  2940 			}
       
  2941 		else if ( parameter.Find( KModifierParameter ) == 0 )
       
  2942 			{
       
  2943 			TPtrC parameterValue = parameter.Right( parameter.Length() - KModifierParameter().Length() );
       
  2944 			TLex parameterValueParser( parameterValue );
       
  2945 			if ( parameterValueParser.Val( keyModifiers ) != KErrNone )
       
  2946 				{
       
  2947 				if ( uiEnvProxy->ParseModifier( parameterValue, keyModifiers ) != KErrNone )
       
  2948 					{
       
  2949 					__TRACE( KError, (_L("SendKeyEvent: Invalid parameter value")));
       
  2950 					TBuf<128> errMsg;
       
  2951 					errMsg.Format( KErrMsgSendKeyEventInvalidParameterValue, &KModifierParameter() );
       
  2952 					iRunErrorMessage = errMsg;
       
  2953 					User::Leave( KErrArgument );    		   				
       
  2954 					}
       
  2955 				}
       
  2956 			}
       
  2957 		else if ( parameter.Find( KRepeatsParameter ) == 0 )
       
  2958 			{
       
  2959 			TPtrC parameterValue = parameter.Right( parameter.Length() - KRepeatsParameter().Length() );
       
  2960 			TLex parameterValueParser( parameterValue );
       
  2961 			if ( parameterValueParser.Val( keyRepeats ) != KErrNone )
       
  2962 				{
       
  2963 				__TRACE( KError, (_L("SendKeyEvent: Invalid parameter value")));
       
  2964 				TBuf<128> errMsg;
       
  2965 				errMsg.Format( KErrMsgSendKeyEventInvalidParameterValue, &KRepeatsParameter() );
       
  2966 				iRunErrorMessage = errMsg;
       
  2967 				User::Leave( KErrArgument );    		   				
       
  2968 				}
       
  2969 			}
       
  2970 		else if ( parameter == KModeGlobal )
       
  2971 			{
       
  2972 			globalMode = ETrue;
       
  2973 			}
       
  2974 		else if ( parameter == KModeLocal )
       
  2975 			{
       
  2976 			globalMode = EFalse;
       
  2977 			}
       
  2978 		else if ( uiEnvProxy->ParseKeyCode( parameter, keyCode ) == KErrNone ) 
       
  2979 			{			
       
  2980 			}			
       
  2981 		else if ( parameter.Length() == 1 )
       
  2982 			{
       
  2983 			keyCode = parameter[ 0 ];
       
  2984 			}
       
  2985 		else
       
  2986 			{
       
  2987 			__TRACE( KError, (_L("PressKey: Invalid parameter")));
       
  2988 			TBuf<128> errMsg;
       
  2989 			errMsg.Format( KErrMsgSendKeyEventInvalidParameter, &parameter );
       
  2990 			iRunErrorMessage = errMsg;
       
  2991 			User::Leave( KErrArgument );   			
       
  2992 			}
       
  2993 		}
       
  2994 	
       
  2995 	if ( globalMode )
       
  2996 		{
       
  2997 		uiEnvProxy->PressKeyL( keyCode, keyScanCode, keyModifiers, keyRepeats );			
       
  2998 		}
       
  2999 	else
       
  3000 		{
       
  3001 		uiEnvProxy->PressKeyL( &iStatus, keyCode, keyScanCode, keyModifiers, keyRepeats );
       
  3002 		}
       
  3003 		
       
  3004 	return globalMode;
       
  3005 	}
       
  3006 
       
  3007 /*
       
  3008 -------------------------------------------------------------------------------
       
  3009 
       
  3010      Class: CTestRunner
       
  3011 
       
  3012      Method: TypeTextL
       
  3013 
       
  3014      Description: Sends text to AppUi
       
  3015   
       
  3016      Parameters:    CStifItemParser* aItem: in: script line
       
  3017      
       
  3018      Return Values: None
       
  3019 
       
  3020      Errors/Exceptions: Leaves on error situations.
       
  3021 
       
  3022      Status: Draft
       
  3023     
       
  3024 -------------------------------------------------------------------------------
       
  3025 */
       
  3026 TBool CTestRunner::TypeTextL( CStifItemParser* aItem )
       
  3027 	{
       
  3028 	_LIT( KErrMsgTypeTextInvalidParameter, "TypeText: Invalid parameter %S" );
       
  3029 	_LIT( KErrMsgTypeTextNotEnoughParameters, "TypeText: Not enough parameters" );
       
  3030 	
       
  3031 	TBool globalMode = EFalse;
       
  3032 	
       
  3033 	TPtrC command;
       
  3034 	TPtrC text;
       
  3035 	aItem->SetParsingType( CStifItemParser::EQuoteStyleParsing );
       
  3036 	
       
  3037 	// Read first parameter
       
  3038 	TInt ret = aItem->GetNextString( command );
       
  3039 	
       
  3040 	if ( ret != KErrNone )
       
  3041 		{
       
  3042 		__TRACE( KError, (_L("TypeText: Not enough parameters")));
       
  3043 		iRunErrorMessage = KErrMsgTypeTextNotEnoughParameters;
       
  3044 		User::Leave( ret );
       
  3045 		}
       
  3046 	
       
  3047 	// Read second parameter
       
  3048 	ret = aItem->GetNextString( text );
       
  3049 	
       
  3050 	// Check if second can be read. if yes then check if first parameters is
       
  3051 	// 'global' parameter
       
  3052 	if ( ret != KErrNone )
       
  3053 		{
       
  3054 		// normal type text
       
  3055 		text.Set( command );
       
  3056 		iTestScripter->TestModuleIf().GetUiEnvProxy()->TypeTextL( &iStatus, text );
       
  3057 		globalMode = EFalse;
       
  3058 		}
       
  3059 	else if ( command == _L("global") )
       
  3060 		{
       
  3061 		iTestScripter->TestModuleIf().GetUiEnvProxy()->TypeTextL( text );
       
  3062 		globalMode = ETrue;
       
  3063 		}
       
  3064 	else
       
  3065 		{
       
  3066 		__TRACE( KError, (_L("TypeText: Invalid parameter")));
       
  3067 		TBuf<128> errMsg;
       
  3068 		errMsg.Format( KErrMsgTypeTextInvalidParameter, &command );
       
  3069 		iRunErrorMessage = errMsg;
       
  3070 		User::Leave( KErrNotSupported );
       
  3071 		}
       
  3072 		
       
  3073 	return globalMode;
       
  3074 	}
       
  3075 
       
  3076 /*
       
  3077 -------------------------------------------------------------------------------
       
  3078 
       
  3079      Class: CTestRunner
       
  3080 
       
  3081      Method: SendPointerEventL
       
  3082 
       
  3083      Description: Send key press event to AppUi
       
  3084   
       
  3085      Parameters:    CStifItemParser* aItem: in: script line
       
  3086      
       
  3087      Return Values: None
       
  3088 
       
  3089      Errors/Exceptions: Leaves on error situations.
       
  3090 
       
  3091      Status: Draft
       
  3092     
       
  3093 -------------------------------------------------------------------------------
       
  3094 */
       
  3095 TBool CTestRunner::SendPointerEventL( CStifItemParser* aItem )
       
  3096 	{
       
  3097 	// Error messages
       
  3098     _LIT( KErrMsgNotEnoughParameters, "SendPointerEvent: Not enough parameters" );
       
  3099     _LIT( KErrMsgPointerEventTypeNotDefined, "SendPointerEvent: Pointer event type not defined" );
       
  3100     _LIT( KErrMsgInvalidUnknownPointerEventType, "SendPointerEvent: Invalid/Unknown pointer event type %S" );
       
  3101     _LIT( KErrMsgPositionXNotDefined, "SendPointerEvent: x co-ordinate is not defined" );
       
  3102     _LIT( KErrMsgPositionYNotDefined, "SendPointerEvent: y co-ordinate is not defined" );
       
  3103     _LIT( KErrMsgPositionXInvalidValue, "SendPointerEvent: Invalid value of x co-ordinate" );
       
  3104     _LIT( KErrMsgPositionYInvalidValue, "SendPointerEvent: Invalid value of y co-ordinate" );
       
  3105 
       
  3106     // Parameters keywords
       
  3107     _LIT( KModeGlobal, "global" );
       
  3108     _LIT( KModeLocal, "local" );
       
  3109     
       
  3110     TBool globalMode = EFalse;
       
  3111 	TUint eventType = 0; 
       
  3112 	TPoint position( 0, 0 );
       
  3113 	TPoint parentPosition( 0, 0 );
       
  3114 		
       
  3115 	TPtrC parameter;
       
  3116 
       
  3117 	CUiEnvProxy* uiEnvProxy = iTestScripter->TestModuleIf().GetUiEnvProxy();
       
  3118 
       
  3119 	// Get first parameter
       
  3120 	if ( aItem->GetNextString( parameter ) != KErrNone )
       
  3121 		{
       
  3122 		__TRACE( KError, (_L("SendPointerEvent: Not enough parameters")));
       
  3123 		iRunErrorMessage = KErrMsgNotEnoughParameters;
       
  3124 		User::Leave( KErrArgument );   			
       
  3125 		}
       
  3126 	else
       
  3127 		{
       
  3128 		TBool modeSelected = EFalse;
       
  3129 		// Check if global/local mode is defined
       
  3130 		if ( parameter == KModeLocal )
       
  3131 			{
       
  3132 			globalMode = false;
       
  3133 			modeSelected = ETrue;
       
  3134 			}
       
  3135 		else if ( parameter == KModeGlobal )
       
  3136 			{
       
  3137 			globalMode = true;
       
  3138 			modeSelected = ETrue;
       
  3139 			}
       
  3140 		
       
  3141 		if ( modeSelected )
       
  3142 			{
       
  3143 			// First parameter was mode so we need get next parameter which should 
       
  3144 			// contain event type
       
  3145 			if ( aItem->GetNextString( parameter ) != KErrNone )
       
  3146 				{
       
  3147 				__TRACE( KError, (_L("SendPointerEvent: Pointer event type not defined")));
       
  3148 				iRunErrorMessage = KErrMsgPointerEventTypeNotDefined;
       
  3149 				User::Leave( KErrArgument );   			
       
  3150 				}
       
  3151 			}
       
  3152 		}
       
  3153 	
       
  3154 	// Parse event type
       
  3155 	if ( uiEnvProxy->ParsePointerEventType( parameter, eventType ) != KErrNone )
       
  3156 		{
       
  3157 		__TRACE( KError, (_L("PressKey: Invalid/Unknown pointer event type %S"), &parameter ));
       
  3158 		iRunErrorMessage.Format( KErrMsgInvalidUnknownPointerEventType, &parameter );
       
  3159 		User::Leave( KErrArgument );   			
       
  3160 		}
       
  3161 	
       
  3162 	if ( aItem->GetNextString( parameter ) != KErrNone )
       
  3163 		{
       
  3164 		__TRACE( KError, (_L("SendPointerEvent: x co-ordinate is not defined")));
       
  3165 		iRunErrorMessage = KErrMsgPositionXNotDefined;
       
  3166 		User::Leave( KErrArgument );   			
       
  3167 		}
       
  3168 
       
  3169 	TLex parameterParser( parameter );
       
  3170 	if ( parameterParser.Val( position.iX ) != KErrNone )
       
  3171 		{
       
  3172 		__TRACE( KError, (_L("SendPointerEvent: Invalid value of x co-ordinate")));
       
  3173 		iRunErrorMessage = KErrMsgPositionXInvalidValue;
       
  3174 		User::Leave( KErrArgument );   			
       
  3175 		}
       
  3176 
       
  3177 	if ( aItem->GetNextString( parameter ) != KErrNone )
       
  3178 		{
       
  3179 		__TRACE( KError, (_L("SendPointerEvent: y co-ordinate is not defined")));
       
  3180 		iRunErrorMessage = KErrMsgPositionYNotDefined;
       
  3181 		User::Leave( KErrArgument );   			
       
  3182 		}
       
  3183 
       
  3184 	parameterParser.Assign( parameter );
       
  3185 	if ( parameterParser.Val( position.iY ) != KErrNone )
       
  3186 		{
       
  3187 		__TRACE( KError, (_L("SendPointerEvent: Invalid value of y co-ordinate")));
       
  3188 		iRunErrorMessage = KErrMsgPositionYInvalidValue;
       
  3189 		User::Leave( KErrArgument );   			
       
  3190 		}		
       
  3191 		
       
  3192 	// Send pointer event
       
  3193 	if ( globalMode )
       
  3194 		{
       
  3195 		uiEnvProxy->SendPointerEventL( eventType, position );			
       
  3196 		}
       
  3197 	else
       
  3198 		{
       
  3199 		uiEnvProxy->SendPointerEventL( &iStatus, eventType, position );
       
  3200 		}
       
  3201 
       
  3202 	return globalMode;
       
  3203 	}
       
  3204 
       
  3205 
       
  3206 /*
       
  3207 -------------------------------------------------------------------------------
       
  3208 
       
  3209      Class: CTestRunner
       
  3210 
       
  3211      Method: ExecuteEventL
       
  3212 
       
  3213      Description: Executes event command script line
       
  3214   
       
  3215      Parameters:    TDesC& aKeyword: in: keyword string
       
  3216                     CStifItemParser* aItem: in: script line
       
  3217      
       
  3218      Return Values: ETrue: continue script file execution
       
  3219                     EFalse: stop script file execution
       
  3220 
       
  3221      Errors/Exceptions: Leaves on error situations.
       
  3222 
       
  3223      Status: Draft
       
  3224     
       
  3225 -------------------------------------------------------------------------------
       
  3226 */
       
  3227 TBool CTestRunner::ExecuteEventL( TDesC& aKeyword,
       
  3228                                   CStifItemParser* aItem )
       
  3229     {
       
  3230     _LIT( KErrMsgEventNameNotDefined, "%S : Event name not defined" );
       
  3231     _LIT( KErrMsgUnknowKeyword, "Unknow keyword %S" );
       
  3232     
       
  3233     TInt ret = KErrNone;
       
  3234     TInt key = TTestKeywords::Parse( aKeyword, TTestKeywords::Keyword );
       
  3235     TBool continueTask = ETrue;
       
  3236      
       
  3237     TPtrC eventName;
       
  3238     // read eventname
       
  3239     ret = aItem->GetNextString( eventName );
       
  3240     if ( ret != KErrNone )
       
  3241     	{
       
  3242     	iRunErrorMessage.Format( KErrMsgEventNameNotDefined, &aKeyword );
       
  3243     	User::Leave( ret );
       
  3244     	}
       
  3245     
       
  3246     TEventIf event;
       
  3247     event.SetName( eventName );
       
  3248     
       
  3249     __TRACE( KMessage, (_L("%S %S"), &aKeyword, &eventName));
       
  3250     iTestScripter->TestModuleIf().Printf( KPrintPriLow, _L("Event"), 
       
  3251         _L("%S %S"), &aKeyword, &eventName);
       
  3252 
       
  3253     switch( key )
       
  3254         {
       
  3255         case TTestKeywords::ERequest:
       
  3256             {
       
  3257             HBufC* eName = eventName.AllocLC();
       
  3258             User::LeaveIfError( iEventArray.Append( eName ) );
       
  3259             CleanupStack::Pop( eName );
       
  3260             event.SetType( TEventIf::EReqEvent );
       
  3261             ret = iTestScripter->TestModuleIf().Event( event );
       
  3262             }
       
  3263             break;
       
  3264         case TTestKeywords::EWait:
       
  3265             {
       
  3266             event.SetType( TEventIf::EWaitEvent );
       
  3267             iTestScripter->TestModuleIf().Event( event, iStatus );
       
  3268             SetActive();
       
  3269             continueTask = EFalse;
       
  3270             }
       
  3271             break;
       
  3272         case TTestKeywords::ERelease:
       
  3273             {
       
  3274             event.SetType( TEventIf::ERelEvent );
       
  3275             ret = iTestScripter->TestModuleIf().Event( event );
       
  3276             if( ret == KErrNone )
       
  3277                 {
       
  3278                 TPtrC eName;
       
  3279                 TInt count = iEventArray.Count();
       
  3280                 for( TInt i = 0; i < count; i++ )
       
  3281                     {
       
  3282                     eName.Set( iEventArray[i]->Des() );
       
  3283                     if( eName == eventName )
       
  3284                         {
       
  3285                         HBufC* tmp = iEventArray[i];
       
  3286                         iEventArray.Remove(i);
       
  3287                         delete tmp;
       
  3288                         break;
       
  3289                         }
       
  3290                     }
       
  3291                 }
       
  3292             }
       
  3293             break;
       
  3294         case TTestKeywords::ESet:
       
  3295             {
       
  3296             event.SetType( TEventIf::ESetEvent );
       
  3297             
       
  3298             TPtrC tmp;
       
  3299             // Get optional set argument
       
  3300             if( aItem->GetNextString( tmp ) == KErrNone )
       
  3301                 {                      
       
  3302                 // Parse optional set argument
       
  3303                 if( tmp == _L("state") )
       
  3304                     {
       
  3305                     __TRACE( KMessage, (_L("State event")));
       
  3306                     event.SetEventType( TEventIf::EState );
       
  3307                     }
       
  3308                 else
       
  3309                     {
       
  3310                     __TRACE( KError, 
       
  3311                         (_L("Unknown argument for set %S"), 
       
  3312                         &tmp));
       
  3313                     }
       
  3314                 }      
       
  3315             
       
  3316             ret = iTestScripter->TestModuleIf().Event( event );
       
  3317             }
       
  3318             break;
       
  3319         case TTestKeywords::EUnset:
       
  3320             {
       
  3321             event.SetType( TEventIf::EUnsetEvent );
       
  3322             event.SetEventType( TEventIf::EState );
       
  3323             ret = iTestScripter->TestModuleIf().Event( event );
       
  3324             }
       
  3325             break;
       
  3326         default:
       
  3327             __TRACE( KError, (_L("Unknown keyword %S"), &aKeyword));
       
  3328             iRunErrorMessage.Format( KErrMsgUnknowKeyword, &aKeyword );
       
  3329             User::Leave( KErrGeneral );
       
  3330             break;
       
  3331         }
       
  3332     if( ret != KErrNone )
       
  3333         {
       
  3334         TName resultDescr;
       
  3335         resultDescr.Format(_L("Event %S returned error: %d"), &aKeyword, ret);
       
  3336         iTestScripter->UpdateTestCaseResult(ret, resultDescr);
       
  3337         // Stops execution from CTestRunner::RunError
       
  3338         User::Leave( KErrGeneral );
       
  3339         }
       
  3340 
       
  3341     return continueTask;
       
  3342 
       
  3343     }
       
  3344 
       
  3345 /*
       
  3346 -------------------------------------------------------------------------------
       
  3347 
       
  3348      Class: CTestRunner
       
  3349 
       
  3350      Method: ExecuteCommandL
       
  3351 
       
  3352      Description: Executes script line
       
  3353 
       
  3354      Parameters:    TDesC& aObject: in: object name 
       
  3355                     CStifItemParser* aItem: in: script line
       
  3356 
       
  3357      Return Values: ETrue: continue script file execution
       
  3358                     EFalse: stop script file execution
       
  3359 
       
  3360      Errors/Exceptions: Leaves on error situations.
       
  3361 
       
  3362      Status: Proposal
       
  3363 
       
  3364 -------------------------------------------------------------------------------
       
  3365 */
       
  3366 TBool CTestRunner::ExecuteCommandL( TDesC& aObject, CStifItemParser* aItem)
       
  3367     {
       
  3368     _LIT( KErrMsgUnknownObjOrKeyword, "Unknow keyword/object %S" );
       
  3369     
       
  3370     TTestObjectBase* obj = iTestScripter->GetObject ( aObject );    
       
  3371     if( obj == NULL )
       
  3372         {
       
  3373         iRunErrorMessage.Format( KErrMsgUnknownObjOrKeyword, &aObject );
       
  3374         User::Leave( KErrGeneral );
       
  3375         }
       
  3376 
       
  3377     if( iTestCaseResults.Count() == 0 )
       
  3378         {
       
  3379         // KErrNone is the default result expected if nothing else is given 
       
  3380         User::LeaveIfError( iTestCaseResults.Append( KErrNone ) );
       
  3381         }
       
  3382 
       
  3383     // OOM heap testing with FAILNEXT
       
  3384     if( iHeapFailNext > 0 )
       
  3385         {
       
  3386         __TRACE( KPrint, ( 
       
  3387             _L( "OOM FAILNEXT is used with count value: %d " ),
       
  3388             iHeapFailNext) );
       
  3389         User::__DbgSetAllocFail( RHeap::EUser, RHeap::EFailNext, iHeapFailNext  );
       
  3390         }
       
  3391     // OOM heap testing with SETFAIL
       
  3392     if( iHeapSetFailValue > 0 )
       
  3393         {
       
  3394         __TRACE( KPrint, (
       
  3395             _L("OOM SETFAIL is used with type:[%d] and value(rate):[%d]"),
       
  3396             iHeapSetFailType, iHeapSetFailValue ) );
       
  3397         User::__DbgSetAllocFail( RHeap::EUser, iHeapSetFailType, iHeapSetFailValue );
       
  3398         }
       
  3399 
       
  3400     TInt commandResult = KErrNone;
       
  3401     TRAP( commandResult, commandResult = obj->RunMethodL( *aItem ) );
       
  3402 
       
  3403     
       
  3404     // Reset OOM macro immediately(Otherwise other allocations
       
  3405     // will be blocked)
       
  3406     User::__DbgSetAllocFail( RHeap::EUser, RHeap::ENone, 1 );
       
  3407 
       
  3408     // OOM test class's build block handling
       
  3409     if( iTestScripter->iOOMIgnoreFailure )
       
  3410         {
       
  3411         __TRACE( KPrint, ( 
       
  3412             _L( "----------< OOM related test information >----------" ) ) );
       
  3413         if( iHeapFailNext > 0 )
       
  3414             {
       
  3415             __TRACE( KPrint, ( 
       
  3416                 _L( "'oomignorefailure' is:[ON] and 'failnextvalue' count is:[%d]" ),
       
  3417                 iHeapFailNext ) );
       
  3418             }
       
  3419         if( iHeapSetFailValue > 0 )
       
  3420             {
       
  3421             __TRACE( KPrint, ( 
       
  3422                 _L( "'oomignorefailure' is:[ON], 'setfailtype' type is:[%d] and value is:[%d]" ),
       
  3423                 iHeapSetFailType, iHeapSetFailValue ) );
       
  3424             }
       
  3425         __TRACE( KPrint, ( 
       
  3426             _L( "Test class build block execution with result:[%d]" ),
       
  3427             commandResult ) );
       
  3428         __TRACE( KPrint, ( 
       
  3429             _L( "----------------------------------------------------" ) ) );
       
  3430 
       
  3431         // Continue testing, despite the memory error situations
       
  3432         iTestCaseResults.Reset();
       
  3433         return ETrue; // Continue script executions
       
  3434         }
       
  3435 
       
  3436     // Normal test class's build block handling
       
  3437     if( iTestCaseResults.Find( commandResult ) < 0 ) 
       
  3438         {
       
  3439         __TRACE( KError, ( _L("Command for [%S] failed (%d)"), 
       
  3440                 &aObject, commandResult ));
       
  3441 
       
  3442         // Added more logging for this special case
       
  3443         if( commandResult == KErrNone )
       
  3444             {
       
  3445             __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)")));    
       
  3446             }
       
  3447            
       
  3448         iTestScripter->UpdateTestCaseResult(commandResult, _L("CTestRunner::ExecuteCommandL returned error"));
       
  3449 
       
  3450         // Stops execution from CTestRunner::RunError
       
  3451         User::Leave( KErrGeneral );
       
  3452         }
       
  3453         
       
  3454     iTestCaseResults.Reset();
       
  3455     // Reset test case allow result to CTestModuleIf side too. This is
       
  3456     // used in TAL-TA5L macro handling.
       
  3457     User::LeaveIfError( 
       
  3458         iTestScripter->TestModuleIf().ResetAllowResult() );
       
  3459         
       
  3460     return ETrue;
       
  3461     }
       
  3462     
       
  3463 /*
       
  3464 -------------------------------------------------------------------------------
       
  3465 
       
  3466      Class: CTestRunner
       
  3467 
       
  3468      Method: SetRunnerActive
       
  3469 
       
  3470      Description: Set CTestRunner active and complete.
       
  3471 
       
  3472      Parameters:    None.
       
  3473 
       
  3474      Return Values: None.
       
  3475 
       
  3476      Errors/Exceptions: None.
       
  3477 
       
  3478      Status: Draft
       
  3479 
       
  3480 -------------------------------------------------------------------------------
       
  3481 */
       
  3482 void CTestRunner::SetRunnerActive()
       
  3483      {
       
  3484      __TRACEFUNC();
       
  3485      // Update state
       
  3486      iState = ERunnerRunning;
       
  3487 
       
  3488      iStatus = KRequestPending;
       
  3489      TRequestStatus* rs = &iStatus;
       
  3490      SetActive();
       
  3491      User::RequestComplete( rs, KErrNone );
       
  3492 
       
  3493      }
       
  3494 
       
  3495 /*
       
  3496 -------------------------------------------------------------------------------
       
  3497 
       
  3498      Class: CTestRunner
       
  3499 
       
  3500      Method: OOMIgnoreFailure
       
  3501 
       
  3502      Description: Handles 'oomignorefailure' keyword parsing.
       
  3503   
       
  3504      Parameters: CStifItemParser* aItem: in: Item object for parsing.
       
  3505 
       
  3506      Return Values: None.
       
  3507 
       
  3508      Errors/Exceptions: None.
       
  3509 
       
  3510      Status: Proposal
       
  3511     
       
  3512 -------------------------------------------------------------------------------
       
  3513 */
       
  3514 void CTestRunner::OOMIgnoreFailureL( CStifItemParser* aItem )
       
  3515     {
       
  3516     _LIT( KerrMsgOOMIgnoreFailureUnknownArgument, "OOMIgnoreFailure : Invalid argument %S" );
       
  3517     _LIT( KerrMsgOOMIgnoreFailureNoArgument, "OOMIgnoreFailure : Parameter not defined" );
       
  3518     
       
  3519     __TRACEFUNC();
       
  3520 
       
  3521     TPtrC tmp;
       
  3522     // Get result
       
  3523     if( aItem->GetNextString( tmp ) == KErrNone )
       
  3524         {                      
       
  3525         if( tmp == _L("ON") || tmp == _L("on") )
       
  3526             {
       
  3527             __TRACE( KMessage, (_L("OOM related 'oomignorefailure': ON")));
       
  3528             iTestScripter->iOOMIgnoreFailure = ETrue;
       
  3529             }
       
  3530         else if( tmp == _L("OFF") || tmp == _L("off") )
       
  3531             {
       
  3532             __TRACE( KMessage, (_L("OOM related 'oomignorefailure': OFF")));
       
  3533             iTestScripter->iOOMIgnoreFailure = EFalse;
       
  3534             }
       
  3535         else
       
  3536             {
       
  3537             __TRACE( KError, 
       
  3538                 (_L("Unknown argument for 'oomignorefailure': [%S]"), 
       
  3539                 &tmp));
       
  3540             iRunErrorMessage.Format( KerrMsgOOMIgnoreFailureUnknownArgument, &tmp );
       
  3541             User::Leave( KErrArgument );
       
  3542             }
       
  3543         }
       
  3544     else
       
  3545         {
       
  3546         __TRACE( KError, ( _L( "Unknown argument for 'oomignorefailure'" ) ) );
       
  3547         iRunErrorMessage = KerrMsgOOMIgnoreFailureNoArgument;
       
  3548         User::Leave( KErrArgument );
       
  3549         }
       
  3550     }
       
  3551 
       
  3552 /*
       
  3553 -------------------------------------------------------------------------------
       
  3554 
       
  3555      Class: CTestRunner
       
  3556 
       
  3557      Method: OOMHeapFailNext
       
  3558 
       
  3559      Description: Handles 'oomheapfailnext' keyword parsing.
       
  3560   
       
  3561      Parameters: CStifItemParser* aItem: in: Item object for parsing.
       
  3562 
       
  3563      Return Values: None.
       
  3564 
       
  3565      Errors/Exceptions: None.
       
  3566 
       
  3567      Status: Proposal
       
  3568     
       
  3569 -------------------------------------------------------------------------------
       
  3570 */
       
  3571 void CTestRunner::OOMHeapFailNextL( CStifItemParser* aItem )
       
  3572     {
       
  3573     _LIT( KErrMsgHeapFailNextNoArgument, "HeapFailNext : Parameters is not defined or has invalid value" );
       
  3574     _LIT( KErrMsgHeapFailNextInvalidValue, "HeapFailNext : Argument value can't be <0" );
       
  3575     __TRACEFUNC();
       
  3576 
       
  3577     TInt heapfailNext( 0 );
       
  3578     // If LOOP_COUNTER is used the GetNextInt returns a correct
       
  3579     // value(Because of the LOOP_COUNTER implementation).
       
  3580     if( aItem->GetNextInt( heapfailNext ) == KErrNone )
       
  3581         {
       
  3582         if( heapfailNext < 0 )
       
  3583         	{
       
  3584         	__TRACE( KError, ( _L( "Argument value must be >0" ) ) );
       
  3585             iRunErrorMessage = KErrMsgHeapFailNextInvalidValue;
       
  3586             User::Leave( KErrArgument );        	
       
  3587         	}
       
  3588         // OOM heap's FAILNEXT range is from 1 to n
       
  3589         iHeapFailNext = heapfailNext + 1;
       
  3590         __TRACE( KMessage, ( _L( "'oomheapfailnext' count value(rate): %d" ),
       
  3591             iHeapFailNext ) );
       
  3592         }
       
  3593     else
       
  3594         {
       
  3595         __TRACE( KError, ( _L( "Unknown argument for 'oomheapfailnext'" ) ) );
       
  3596         iRunErrorMessage = KErrMsgHeapFailNextNoArgument;
       
  3597         User::Leave( KErrArgument );
       
  3598         }
       
  3599     }
       
  3600 
       
  3601 /*
       
  3602 -------------------------------------------------------------------------------
       
  3603 
       
  3604      Class: CTestRunner
       
  3605 
       
  3606      Method: OOMHeapSetFail
       
  3607 
       
  3608      Description: Handles 'oomheapsetfail' keyword parsing.
       
  3609   
       
  3610      Parameters: CStifItemParser* aItem: in: Item object for parsing.
       
  3611 
       
  3612      Return Values: None.
       
  3613 
       
  3614      Errors/Exceptions: None.
       
  3615 
       
  3616      Status: Proposal
       
  3617     
       
  3618 -------------------------------------------------------------------------------
       
  3619 */
       
  3620 void CTestRunner::OOMHeapSetFailL( CStifItemParser* aItem )
       
  3621     {
       
  3622     _LIT( KErrMsgOOMHeapSetFailTypeNotDefined, "OOMHeapSetFail : Parameter type is not defined" );
       
  3623     _LIT( KErrMsgOOMHeapSetFailRateNotDefined, "OOMHeapSetFail : Parameter rate is not defined" );
       
  3624     _LIT( KErrMsgOOMHeapSetFailTypeInvalidValue, "OOMHeapSetFail : Parameter type has invalid value" );
       
  3625     _LIT( KErrMsgOOMHeapSetFailRateInvalidValue, "OOMHeapSetFail : Parameter rate can't be <0" );
       
  3626     __TRACEFUNC();
       
  3627 
       
  3628     TPtrC type;
       
  3629     TInt value( 0 );
       
  3630 
       
  3631     // NOTE: If error in type or value parsing => return without changing
       
  3632     //       iHeapSetFailType or iHeapSetFailValue valiables.
       
  3633 
       
  3634     // Get type
       
  3635     if( aItem->GetNextString( type ) != KErrNone )
       
  3636         {
       
  3637         __TRACE( KError, ( 
       
  3638             _L( "Unknown argument for 'oomheapsetfail' type" ) ) );
       
  3639         iRunErrorMessage = KErrMsgOOMHeapSetFailTypeNotDefined;
       
  3640         User::Leave( KErrArgument );
       
  3641         }
       
  3642     // Get value(rate)
       
  3643     if( aItem->GetNextInt( value ) != KErrNone )
       
  3644         {
       
  3645         __TRACE( KError, ( 
       
  3646             _L( "Unknown argument for 'oomheapsetfail' value(rate)" ) ) );
       
  3647         iRunErrorMessage = KErrMsgOOMHeapSetFailRateNotDefined;
       
  3648         User::Leave( KErrArgument );
       
  3649         }    
       
  3650     
       
  3651     // All parsing operations are passed, get type and value
       
  3652 
       
  3653     // Get type
       
  3654     if( type == _L("random") )
       
  3655         {
       
  3656         __TRACE( KMessage, (_L("'oomheapsetfail' type: random")));
       
  3657         iHeapSetFailType = RHeap::ERandom;
       
  3658         }
       
  3659     else if( type == _L("truerandom") )
       
  3660         {
       
  3661         __TRACE( KMessage, (_L("'oomheapsetfail' type: truerandom")));
       
  3662         iHeapSetFailType = RHeap::ETrueRandom;
       
  3663         }
       
  3664     else if( type == _L("deterministic") )
       
  3665         {
       
  3666         __TRACE( KMessage, (_L("'oomheapsetfail' type: deterministic")));
       
  3667         iHeapSetFailType = RHeap::EDeterministic;
       
  3668         }
       
  3669     else if( type == _L("none") )
       
  3670         {
       
  3671         __TRACE( KMessage, (_L("'oomheapsetfail' type: none")));
       
  3672         iHeapSetFailType = RHeap::ENone;
       
  3673         }
       
  3674     else if( type == _L("failnext") )
       
  3675         {
       
  3676         __TRACE( KMessage, (_L("'oomheapsetfail' type: failnext")));
       
  3677         iHeapSetFailType = RHeap::EFailNext;
       
  3678         }
       
  3679     else
       
  3680         {
       
  3681         __TRACE( KError, 
       
  3682             ( _L( "Unknown argument for 'oomheapsetfail' type: [%S]" ),
       
  3683             &type ) );
       
  3684         iRunErrorMessage = KErrMsgOOMHeapSetFailTypeInvalidValue;
       
  3685         User::Leave( KErrArgument );
       
  3686         }
       
  3687 
       
  3688     if( value < 0 )
       
  3689     	{
       
  3690         __TRACE( KError, _L( "'oomheapsetfail' value(rate) can't be <0" ) );    	    	
       
  3691         iRunErrorMessage = KErrMsgOOMHeapSetFailRateInvalidValue;
       
  3692         User::Leave( KErrArgument );
       
  3693     	}
       
  3694     // Get value
       
  3695     // OOM heap's SETFAIL range is from 1 to n
       
  3696     iHeapSetFailValue = value + 1;
       
  3697     __TRACE( KMessage, ( 
       
  3698         _L( "'oomheapsetfail' value(rate): %d" ), iHeapSetFailValue ) );
       
  3699 
       
  3700     }
       
  3701 
       
  3702 /*
       
  3703 -------------------------------------------------------------------------------
       
  3704 
       
  3705      Class: CTestRunner
       
  3706 
       
  3707      Method: OOMHeapToNormal
       
  3708 
       
  3709      Description: Initialize all OOM related variables.
       
  3710   
       
  3711      Parameters: None.
       
  3712 
       
  3713      Return Values: None.
       
  3714 
       
  3715      Errors/Exceptions: None.
       
  3716 
       
  3717      Status: Proposal
       
  3718     
       
  3719 -------------------------------------------------------------------------------
       
  3720 */
       
  3721 void CTestRunner::OOMHeapToNormal()
       
  3722     {
       
  3723     __TRACEFUNC();
       
  3724 
       
  3725     if( iTestScripter )
       
  3726         {
       
  3727         // This should initialize also
       
  3728         iTestScripter->iOOMIgnoreFailure = EFalse;
       
  3729         }
       
  3730 
       
  3731     iHeapFailNext = 0;
       
  3732     iHeapSetFailType = RHeap::ENone;
       
  3733     iHeapSetFailValue = 0;
       
  3734 
       
  3735     }
       
  3736 
       
  3737 /*
       
  3738 -------------------------------------------------------------------------------
       
  3739 
       
  3740      Class: CTestRunner
       
  3741 
       
  3742      Method: TestInterference
       
  3743 
       
  3744      Description: Starts test interference.
       
  3745   
       
  3746      Parameters: CStifItemParser* aItem: in: Item object for parsing.
       
  3747 
       
  3748      Return Values: None.
       
  3749 
       
  3750      Errors/Exceptions: None.
       
  3751 
       
  3752      Status: Approved
       
  3753     
       
  3754 -------------------------------------------------------------------------------
       
  3755 */
       
  3756 void CTestRunner::TestInterferenceL( CStifItemParser* aItem )
       
  3757     {
       
  3758     _LIT( KErrMsgTestInterferenceNameNotDefined, "TestInterference : Parameter name is not defined" );
       
  3759     _LIT( KErrMsgTestInterferenceCommandNotDefined, "TestInterference : Parameter command is not defined" );
       
  3760     _LIT( KErrMsgTestInterferenceCommandInvalidValue, "TestInterference : Parameter command has invalid value" );
       
  3761     __TRACEFUNC();
       
  3762     TPtrC name;
       
  3763     TPtrC command;
       
  3764 
       
  3765     // Get name
       
  3766     if( aItem->GetNextString( name ) != KErrNone )
       
  3767         {
       
  3768         __TRACE( KError, ( 
       
  3769             _L( "Unknown argument for 'testinterference' name" ) ) );
       
  3770         iRunErrorMessage = KErrMsgTestInterferenceNameNotDefined;
       
  3771         User::Leave( KErrArgument ); // Error in parsing => Leave
       
  3772         }
       
  3773     // Get command
       
  3774     if( aItem->GetNextString( command ) != KErrNone )
       
  3775         {
       
  3776         __TRACE( KError, ( 
       
  3777             _L( "Unknown argument for 'testinterference' command" ) ) );
       
  3778         iRunErrorMessage = KErrMsgTestInterferenceCommandNotDefined;
       
  3779         User::Leave( KErrArgument ); // Error in parsing => Leave
       
  3780         }
       
  3781 
       
  3782     if( command == _L( "start" ) )
       
  3783         {
       
  3784         __TRACE( KMessage, ( _L( "'testinterference' called, starts test interference") ) );
       
  3785         StartInterferenceL( name, aItem );
       
  3786         }
       
  3787     else if( command == _L( "stop" ) )
       
  3788         {
       
  3789         __TRACE( KMessage, ( _L( "'testinterference' called, stops and releases test interference") ) );
       
  3790         StopInterferenceL( name );
       
  3791         }
       
  3792     else
       
  3793         {
       
  3794         __TRACE( KError, ( 
       
  3795             _L( "Unknown command for 'testinterference'[%S]" ), &command ) );
       
  3796         iRunErrorMessage = KErrMsgTestInterferenceCommandInvalidValue;
       
  3797         User::Leave( KErrArgument ); // Error in parsing => Leave
       
  3798         }
       
  3799 
       
  3800     }
       
  3801 
       
  3802 /*
       
  3803 -------------------------------------------------------------------------------
       
  3804 
       
  3805      Class: CTestRunner
       
  3806 
       
  3807      Method: StartInterference
       
  3808 
       
  3809      Description: 
       
  3810   
       
  3811      Parameters: CStifItemParser* aItem: in: Item object for parsing.
       
  3812 
       
  3813      Return Values: None.
       
  3814 
       
  3815      Errors/Exceptions: None.
       
  3816 
       
  3817      Status: Approved
       
  3818     
       
  3819 -------------------------------------------------------------------------------
       
  3820 */
       
  3821 void CTestRunner::StartInterferenceL( TDesC& aName, CStifItemParser* aItem )
       
  3822     {
       
  3823     _LIT( KErrMsgStartInterferenceCategoryNotDefined, "TestInterference : Parameter category is not defined" );
       
  3824     _LIT( KErrMsgStartInterferenceCategoryInvalidValue, "TestInterference : Parameter category has invalid value" );
       
  3825     _LIT( KErrMsgStartInterferenceTypeNotDefined, "TestInterference : Parameter type is not defined" );
       
  3826     _LIT( KErrMsgStartInterferenceTypeInvalidValue, "TestInterference : Parameter type has invalid value" );
       
  3827     _LIT( KErrMsgStartInterferenceIdleNotDefined, "TestInterference : Parameter idle is not defined or has invalid value" );
       
  3828     _LIT( KErrMsgStartInterferenceIdleInvalidValue, "TestInterference : Parameter idle has invalid value" );
       
  3829     _LIT( KErrMsgStartInterferenceActiveNotDefined, "TestInterference : Parameter active is not defined or has invalid value" );
       
  3830     _LIT( KErrMsgStartInterferenceActiveInvalidValue, "TestInterference : Parameter active has invalid value" );
       
  3831     
       
  3832     __TRACEFUNC();
       
  3833     TPtrC category;
       
  3834     TPtrC type;
       
  3835     TInt idle( 0 );
       
  3836     TInt active( 0 );
       
  3837     TInt priority( 0 );
       
  3838 
       
  3839     // Get category
       
  3840     if( aItem->GetNextString( category ) != KErrNone )
       
  3841         {
       
  3842         __TRACE( KError, ( 
       
  3843             _L( "Unknown argument for 'testinterference' category" ) ) );
       
  3844         iRunErrorMessage = KErrMsgStartInterferenceCategoryNotDefined;
       
  3845         User::Leave( KErrArgument ); // Error in parsing => Leave
       
  3846         }
       
  3847     // Get type
       
  3848     if( aItem->GetNextString( type ) != KErrNone )
       
  3849         {
       
  3850         __TRACE( KError, ( 
       
  3851             _L( "Unknown argument for 'testinterference' type" ) ) );
       
  3852         iRunErrorMessage = KErrMsgStartInterferenceTypeNotDefined;
       
  3853         User::Leave( KErrArgument ); // Error in parsing => Leave
       
  3854         }
       
  3855 
       
  3856     TPtrC timeStr;
       
  3857     TReal time;
       
  3858     // Get idle time
       
  3859     if( aItem->GetNextString( timeStr ) != KErrNone )
       
  3860         {        
       
  3861         __TRACE( KError, ( 
       
  3862             _L( "Unknown argument for 'testinterference' idle" ) ) );
       
  3863         iRunErrorMessage = KErrMsgStartInterferenceIdleNotDefined;
       
  3864         User::Leave( KErrArgument ); // Error in parsing => Leave
       
  3865         }
       
  3866     if ( TLex( timeStr ).Val( time, '.' ) != KErrNone )
       
  3867     	{
       
  3868         __TRACE( KError, ( 
       
  3869             _L( "Unknown argument for 'testinterference' idle" ) ) );
       
  3870         iRunErrorMessage = KErrMsgStartInterferenceIdleNotDefined;
       
  3871         User::Leave( KErrArgument ); // Error in parsing => Leave    	
       
  3872     	}
       
  3873     // Convert idle time from milli to micro seconds
       
  3874    	idle = time * 1000.0;
       
  3875 
       
  3876     if( idle < 0 )
       
  3877     	{
       
  3878         __TRACE( KError, ( 
       
  3879                 _L( "Argument 'testinterference' idle can't be <0" ) ) );
       
  3880     	iRunErrorMessage = KErrMsgStartInterferenceIdleInvalidValue;
       
  3881     	User::Leave( KErrArgument );
       
  3882     	}
       
  3883    // Get active time
       
  3884     if( aItem->GetNextString( timeStr ) != KErrNone )
       
  3885         {
       
  3886         __TRACE( KError, ( 
       
  3887             _L( "Unknown argument for 'testinterference' active" ) ) );
       
  3888         iRunErrorMessage = KErrMsgStartInterferenceActiveNotDefined;
       
  3889         User::Leave( KErrArgument ); // Error in parsing => Leave
       
  3890         }
       
  3891     if ( TLex( timeStr ).Val( time, '.' ) != KErrNone )
       
  3892     	{
       
  3893         __TRACE( KError, ( 
       
  3894             _L( "Unknown argument for 'testinterference' idle" ) ) );
       
  3895         iRunErrorMessage = KErrMsgStartInterferenceIdleNotDefined;
       
  3896         User::Leave( KErrArgument ); // Error in parsing => Leave    	
       
  3897     	}
       
  3898     
       
  3899     // Convert active time from milli to micro seconds
       
  3900    	active = time * 1000.0;
       
  3901    	
       
  3902     if( active < 0 )
       
  3903     	{
       
  3904         __TRACE( KError, ( 
       
  3905                 _L( "Argument 'testinterference' active can't be <0" ) ) );
       
  3906     	iRunErrorMessage = KErrMsgStartInterferenceActiveInvalidValue;
       
  3907     	User::Leave( KErrArgument );
       
  3908     	}
       
  3909     
       
  3910    // Get priority
       
  3911     if( aItem->GetNextInt( priority ) != KErrNone )
       
  3912         {
       
  3913         // Log information only do not return. Priority value is optional.
       
  3914         __TRACE( KInit, ( 
       
  3915             _L( "Unknown argument for 'testinterference' priority or value not given, default priority will be used" ) ) );
       
  3916         }    
       
  3917 
       
  3918     MSTIFTestInterference* interference = NULL;
       
  3919 
       
  3920     // Get category
       
  3921     if( category == _L("activeobject") )
       
  3922         {
       
  3923         interference = MSTIFTestInterference::NewL( iTestScripter,
       
  3924                             MSTIFTestInterference::EActiveObject );
       
  3925         }
       
  3926     else if( category == _L("thread") )
       
  3927         {
       
  3928         interference = MSTIFTestInterference::NewL( iTestScripter,
       
  3929                             MSTIFTestInterference::EThread );
       
  3930         }
       
  3931     else
       
  3932         {
       
  3933         __TRACE( KError, ( 
       
  3934             _L( "Unknown argument for 'testinterference' category[%S]" ), &category ) );
       
  3935         iRunErrorMessage = KErrMsgStartInterferenceCategoryInvalidValue;
       
  3936         User::Leave( KErrArgument ); // Error in parsing => Leave
       
  3937         }
       
  3938 
       
  3939     // Create object that include test interference information and append this
       
  3940     // to array.
       
  3941     TTestInterference* object = new (ELeave) TTestInterference();
       
  3942     object->iName = aName;
       
  3943     object->iInterference = interference;
       
  3944 
       
  3945     // Array for handling test interference between different objects
       
  3946     TInt ret = iTestInterferenceArray.Append( object );
       
  3947     if( ret != KErrNone )
       
  3948         {
       
  3949         delete object;
       
  3950         __TRACE( KError, ( 
       
  3951             _L( "CTestRunner::StartInterference: iTestInterferenceArray.Append fails:[%d]" ), ret ) );
       
  3952         User::Leave( ret );
       
  3953         }
       
  3954 
       
  3955     // Set priority if user given
       
  3956     if( priority != 0 )
       
  3957         {
       
  3958         interference->SetPriority( priority );
       
  3959         }
       
  3960 
       
  3961     // Get type
       
  3962     if( type == _L("cpuload") )
       
  3963         {
       
  3964         interference->StartL( MSTIFTestInterference::ECpuLoadMicroSeconds, idle , active );
       
  3965         }
       
  3966     else if( type == _L("filesystemreadc") )
       
  3967         {
       
  3968         interference->StartL( MSTIFTestInterference::EFileSystemReadCMicroSeconds, idle , active );
       
  3969         }
       
  3970     else if( type == _L("filesystemreadd") )
       
  3971         {
       
  3972         interference->StartL( MSTIFTestInterference::EFileSystemReadDMicroSeconds, idle , active );
       
  3973         }
       
  3974     else if( type == _L("filesystemreade") )
       
  3975         {
       
  3976         interference->StartL( MSTIFTestInterference::EFileSystemReadEMicroSeconds, idle , active );
       
  3977         }
       
  3978     else if( type == _L("filesystemreadz") )
       
  3979         {
       
  3980         interference->StartL( MSTIFTestInterference::EFileSystemReadZMicroSeconds, idle , active );
       
  3981         }
       
  3982     else if( type == _L("filesystemwritec") )
       
  3983         {
       
  3984         interference->StartL( MSTIFTestInterference::EFileSystemWriteCMicroSeconds, idle , active );
       
  3985         }
       
  3986     else if( type == _L("filesystemwrited") )
       
  3987         {
       
  3988         interference->StartL( MSTIFTestInterference::EFileSystemWriteDMicroSeconds, idle , active );
       
  3989         }
       
  3990     else if( type == _L("filesystemwritee") )
       
  3991         {
       
  3992         interference->StartL( MSTIFTestInterference::EFileSystemWriteEMicroSeconds, idle , active );
       
  3993         }
       
  3994     else if( type == _L("filesystemfillandemptyc") )
       
  3995         {
       
  3996         interference->StartL( MSTIFTestInterference::EFileSystemFillAndEmptyCMicroSeconds, idle , active );
       
  3997         }
       
  3998     else if( type == _L("filesystemfillandemptyd") )
       
  3999         {
       
  4000         interference->StartL( MSTIFTestInterference::EFileSystemFillAndEmptyDMicroSeconds, idle , active );
       
  4001         }
       
  4002     else if( type == _L("filesystemfillandemptye") )
       
  4003         {
       
  4004         interference->StartL( MSTIFTestInterference::EFileSystemFillAndEmptyEMicroSeconds, idle , active );
       
  4005         }
       
  4006     else
       
  4007         {
       
  4008         __TRACE( KError, ( 
       
  4009             _L( "Unknown argument for 'testinterference' type[%S]" ), &type ) );
       
  4010         iRunErrorMessage = KErrMsgStartInterferenceTypeInvalidValue;
       
  4011         User::Leave( KErrArgument ); // Error in parsing => Leave
       
  4012         }
       
  4013 
       
  4014     }
       
  4015 
       
  4016 /*
       
  4017 -------------------------------------------------------------------------------
       
  4018 
       
  4019      Class: CTestRunner
       
  4020 
       
  4021      Method: StopInterference
       
  4022 
       
  4023      Description: Stops test interference.
       
  4024   
       
  4025      Parameters: TDesC& aName: in: Indicates right test interference object.
       
  4026 
       
  4027      Return Values: None.
       
  4028 
       
  4029      Errors/Exceptions: None.
       
  4030 
       
  4031      Status: Approved
       
  4032     
       
  4033 -------------------------------------------------------------------------------
       
  4034 */
       
  4035 void CTestRunner::StopInterferenceL( TDesC& aName )
       
  4036     {    
       
  4037     _LIT( KErrMsgStopInterference, "TestInterference : testinterference %S was not start" );
       
  4038     __TRACEFUNC();
       
  4039     
       
  4040     TInt count = iTestInterferenceArray.Count();
       
  4041     for( TInt i = 0; i < count; i++ )
       
  4042         {
       
  4043         if( iTestInterferenceArray[i]->iName == aName )
       
  4044             {
       
  4045             // Found test module, return description
       
  4046             iTestInterferenceArray[i]->iInterference->Stop();
       
  4047             // Delete data
       
  4048             delete iTestInterferenceArray[i];
       
  4049             // Remove pointer to deleted data(Append())
       
  4050             iTestInterferenceArray.Remove( i );
       
  4051             // iTestMeasurementArray can contain only one type of measurement
       
  4052             // so we can break when type is removed.
       
  4053             return;
       
  4054             }
       
  4055         }
       
  4056     __TRACE( KError, ( 
       
  4057             _L( "'testinterference' type[%S] was not start" ), &aName ) );
       
  4058     iRunErrorMessage.Format( KErrMsgStopInterference, &aName );
       
  4059     User::Leave( KErrArgument ); // Error in parsing => Leave
       
  4060     }
       
  4061 
       
  4062 /*
       
  4063 -------------------------------------------------------------------------------
       
  4064 
       
  4065      Class: CTestRunner
       
  4066 
       
  4067      Method: MeasurementL
       
  4068 
       
  4069      Description: Starts test measurement.
       
  4070   
       
  4071      Parameters: CStifItemParser* aItem: in: Item object for parsing.
       
  4072 
       
  4073      Return Values: None.
       
  4074 
       
  4075      Errors/Exceptions: Leaves if StartBappeaMeasurementL() fails.
       
  4076                         Leaves if StopBappeaMeasurementL() fails.
       
  4077 
       
  4078      Status: Approved
       
  4079     
       
  4080 -------------------------------------------------------------------------------
       
  4081 */
       
  4082 void CTestRunner::MeasurementL( CStifItemParser* aItem )
       
  4083     {
       
  4084     _LIT( KErrMsgMeasurementCommandNotDefined, "TestMeasurement : Parameter command is not defined" );
       
  4085     _LIT( KErrMsgMeasurementTypeNotDefined, "TestMeasurement : Parameter type is not defined" );
       
  4086     _LIT( KErrMsgMeasurementUnknownType, "TestMeasurement : Unknown measurement type %S" );
       
  4087     _LIT( KErrMsgMeasurementUnknownCommand, "TestMeasurement : Unknown command %S" );
       
  4088     __TRACEFUNC();
       
  4089     TPtrC type;
       
  4090     TPtrC command;
       
  4091 
       
  4092     // Get command
       
  4093     if( aItem->GetNextString( command ) != KErrNone )
       
  4094         {
       
  4095         __TRACE( KError, ( 
       
  4096             _L( "Unknown argument for 'measurement' command" ) ) );
       
  4097         iRunErrorMessage = KErrMsgMeasurementCommandNotDefined;
       
  4098         User::Leave( KErrArgument ); // Error in parsing => Leave
       
  4099         }
       
  4100     // Get name
       
  4101     if( aItem->GetNextString( type ) != KErrNone )
       
  4102         {
       
  4103         __TRACE( KError, ( 
       
  4104             _L( "Unknown argument for 'measurement' type" ) ) );
       
  4105         iRunErrorMessage = KErrMsgMeasurementTypeNotDefined;
       
  4106         User::Leave( KErrArgument ); // Error in parsing => Leave
       
  4107         }
       
  4108 
       
  4109     // Verify measurement type
       
  4110     if( !( type == KParamMeasurement01 ||
       
  4111                 type == KParamMeasurement02 ||
       
  4112                 type == KParamMeasurement03 ||
       
  4113                 type == KParamMeasurement04 ||
       
  4114                 type == KParamMeasurement05 ||
       
  4115                 type == KParamMeasurementBappea ) )
       
  4116 
       
  4117         {
       
  4118         __TRACE( KError, ( 
       
  4119             _L( "Unknown measurement type:[%S]" ), &type ) );
       
  4120         iRunErrorMessage.Format( KErrMsgMeasurementUnknownType, &type );
       
  4121         User::Leave( KErrArgument ); // Error in types => Leave
       
  4122         }
       
  4123 
       
  4124     // Verify command
       
  4125    if( command == _L( "start" ) )
       
  4126         {
       
  4127         // START measurement's process
       
  4128         __TRACE( KMessage, ( _L( "Start 'measurement' with '%S'"), &type ) );
       
  4129         StartMeasurementL( type, aItem );
       
  4130         }
       
  4131     else if( command == _L( "stop" ) )
       
  4132         {
       
  4133         // STOP measurement's process
       
  4134         __TRACE( KMessage, ( _L( "'Stop 'measurement' with '%S'"), &type ) );
       
  4135         StopMeasurementL( type );
       
  4136         }
       
  4137     else
       
  4138         {
       
  4139         __TRACE( KError, ( 
       
  4140             _L( "Unknown command for 'measurement' command:[%S] or type:[%S]" ), &command, &type ) );
       
  4141         iRunErrorMessage.Format( KErrMsgMeasurementUnknownCommand, &command );
       
  4142         User::Leave( KErrArgument ); // Error in commands => Leave
       
  4143         }
       
  4144 
       
  4145     }
       
  4146 
       
  4147 /*
       
  4148 -------------------------------------------------------------------------------
       
  4149 
       
  4150      Class: CTestRunner
       
  4151 
       
  4152      Method: StartMeasurementL
       
  4153 
       
  4154      Description: Start measurement
       
  4155   
       
  4156      Parameters: const TDesC& aType: in: Plugin type.
       
  4157                  CStifItemParser* aItem: in: Item object for parsing.
       
  4158 
       
  4159      Return Values: None.
       
  4160 
       
  4161      Errors/Exceptions: Leaves is measurement operation fails.
       
  4162 
       
  4163      Status: Approved
       
  4164     
       
  4165 -------------------------------------------------------------------------------
       
  4166 */
       
  4167 void CTestRunner::StartMeasurementL( const TDesC& aType,
       
  4168                                            CStifItemParser* aItem )
       
  4169     {
       
  4170     _LIT( KErrMsgMeasurementUnknownPlugin, "Measurement : Unknown measurement plugin %S" );
       
  4171     _LIT( KErrMsgMeasurementStartFail, "Measurement : Measurement start fails" );
       
  4172     __TRACEFUNC();
       
  4173 
       
  4174     CSTIFTestMeasurement* testMeasurement = NULL;
       
  4175 
       
  4176     // Get Measurement configuration info
       
  4177     TPtrC configurationInfo( KNullDesC() );
       
  4178     if( aItem->Remainder( configurationInfo ) != KErrNone )
       
  4179         {
       
  4180         __TRACE( KInit, ( 
       
  4181             _L( "Using default path and file name for measurement configure" ) ) );
       
  4182         } 
       
  4183 
       
  4184     if( aType == KParamMeasurement01 )
       
  4185         {
       
  4186         testMeasurement = CSTIFTestMeasurement::NewL( 
       
  4187                     iTestScripter, 
       
  4188                     CSTIFTestMeasurement::KStifMeasurementPlugin01,
       
  4189                     configurationInfo );
       
  4190         }
       
  4191     else if( aType == KParamMeasurement02 )
       
  4192         {
       
  4193         testMeasurement = CSTIFTestMeasurement::NewL( 
       
  4194                     iTestScripter, 
       
  4195                     CSTIFTestMeasurement::KStifMeasurementPlugin02,
       
  4196                     configurationInfo );
       
  4197         }
       
  4198     else if( aType == KParamMeasurement03 )
       
  4199         {
       
  4200         testMeasurement = CSTIFTestMeasurement::NewL( 
       
  4201                     iTestScripter, 
       
  4202                     CSTIFTestMeasurement::KStifMeasurementPlugin03,
       
  4203                     configurationInfo );
       
  4204         }
       
  4205     else if( aType == KParamMeasurement04 )
       
  4206         {
       
  4207         testMeasurement = CSTIFTestMeasurement::NewL( 
       
  4208                     iTestScripter, 
       
  4209                     CSTIFTestMeasurement::KStifMeasurementPlugin04,
       
  4210                     configurationInfo );
       
  4211         }
       
  4212     else if( aType == KParamMeasurement05 )
       
  4213         {
       
  4214         testMeasurement = CSTIFTestMeasurement::NewL( 
       
  4215                     iTestScripter, 
       
  4216                     CSTIFTestMeasurement::KStifMeasurementPlugin05,
       
  4217                     configurationInfo );
       
  4218         }
       
  4219     else if( aType == KParamMeasurementBappea )
       
  4220         {
       
  4221         testMeasurement = CSTIFTestMeasurement::NewL( 
       
  4222                     iTestScripter, 
       
  4223                     CSTIFTestMeasurement::KStifMeasurementBappeaProfiler,
       
  4224                     configurationInfo );
       
  4225         }
       
  4226     else
       
  4227         {
       
  4228         __TRACE( KError, ( _L( "Unknown plugin[%S] for 'measurement'" ), &aType ) );
       
  4229         iRunErrorMessage.Format( KErrMsgMeasurementUnknownPlugin, &aType );        
       
  4230         User::Leave( KErrArgument );
       
  4231         }
       
  4232 
       
  4233     // Start test measurement
       
  4234     TInt start_ret( KErrNone );
       
  4235     start_ret = testMeasurement->Start();
       
  4236     if( start_ret != KErrNone )
       
  4237         {
       
  4238         delete testMeasurement;
       
  4239         //CleanupStack::PopAndDestroy( setting_buf );
       
  4240         __TRACE( KError, ( 
       
  4241             _L( "CTestRunner::StartMeasurementL(): Measurement Start() fails:[%d]" ), start_ret ) );
       
  4242         iRunErrorMessage = KErrMsgMeasurementStartFail;
       
  4243         User::Leave( start_ret );
       
  4244         }
       
  4245 
       
  4246     TTestMeasurement* object = new (ELeave) TTestMeasurement();
       
  4247     object->iName = aType;
       
  4248     object->iMeasurement = testMeasurement;
       
  4249 
       
  4250     // Array for handling test measurement between different objects
       
  4251     TInt ret = iTestMeasurementArray.Append( object );
       
  4252     if( ret != KErrNone )
       
  4253         {
       
  4254         delete object;
       
  4255         __TRACE( KError, ( 
       
  4256             _L( "CTestRunner::StartMeasurementL(): iTestMeasurementArray.Append fails:[%d]" ), ret ) );
       
  4257         User::Leave( ret );
       
  4258         }
       
  4259 
       
  4260     }
       
  4261 
       
  4262 /*
       
  4263 -------------------------------------------------------------------------------
       
  4264 
       
  4265      Class: CTestRunner
       
  4266 
       
  4267      Method: StopMeasurementL
       
  4268 
       
  4269      Description: Stops test measurement.
       
  4270   
       
  4271      Parameters: None.
       
  4272 
       
  4273      Return Values: None.
       
  4274 
       
  4275      Errors/Exceptions: None.
       
  4276 
       
  4277      Status: Approved
       
  4278     
       
  4279 -------------------------------------------------------------------------------
       
  4280 */
       
  4281 void CTestRunner::StopMeasurementL( const TDesC& aType )
       
  4282     {
       
  4283     _LIT( KErrMsgMeasurementNotStarted, "Measurement : Measurement %S was not start" );
       
  4284     __TRACEFUNC();
       
  4285 
       
  4286     TInt count = iTestMeasurementArray.Count();
       
  4287     for( TInt i = 0; i < count; i++ )
       
  4288         {
       
  4289         if( iTestMeasurementArray[i]->iName == aType )
       
  4290             {
       
  4291             // Found measurement module, stop
       
  4292             iTestMeasurementArray[i]->iMeasurement->Stop();
       
  4293             // Delete data
       
  4294             delete iTestMeasurementArray[i];
       
  4295             // Remove pointer to deleted data(Append())
       
  4296             iTestMeasurementArray.Remove( i );
       
  4297             // iTestMeasurementArray can contain only one type of measurement
       
  4298             // so we can break when type is removed.
       
  4299             return;
       
  4300             }
       
  4301         }
       
  4302 
       
  4303     __TRACE( KError, ( 
       
  4304             _L( "CTestRunner::StopMeasurementL(): Measurement %S was not start" ), &aType ) );
       
  4305     iRunErrorMessage.Format( KErrMsgMeasurementNotStarted, &aType  );
       
  4306     User::Leave( KErrArgument );
       
  4307     }
       
  4308 
       
  4309 /*
       
  4310 -------------------------------------------------------------------------------
       
  4311 
       
  4312      Class: CTestRunner
       
  4313 
       
  4314      Method: AddTestCaseResultL
       
  4315 
       
  4316      Description: Adds new test case result. Used with 'allownextresult'
       
  4317                   and 'allowerrorcodes' keywords.
       
  4318   
       
  4319      Parameters: CStifItemParser* aItem: in: Item object for parsing.
       
  4320 
       
  4321      Return Values: None.
       
  4322 
       
  4323      Errors/Exceptions: Leaves if iTestCaseResults.Append fails.
       
  4324                         Leaves if aItem->GetNextInt() fails.
       
  4325 
       
  4326      Status: Approved
       
  4327     
       
  4328 -------------------------------------------------------------------------------
       
  4329 */
       
  4330 void CTestRunner::AddTestCaseResultL( CStifItemParser* aItem )
       
  4331     {
       
  4332     _LIT( KErrMsgAllowNextResultInvalidValue, "No expected result value given or value has invalid format" );
       
  4333     TInt result;
       
  4334 
       
  4335     TPtrC codeBuf;
       
  4336     TBool found = EFalse;
       
  4337     while( aItem->GetNextString( codeBuf ) == KErrNone )
       
  4338     	{
       
  4339     	TLex codeParser( codeBuf );
       
  4340     	if ( codeParser.Val( result ) != KErrNone )
       
  4341     		{
       
  4342             __TRACE( KError, (_L("ExecuteLineL: No expected result value given")));
       
  4343             iRunErrorMessage = KErrMsgAllowNextResultInvalidValue;
       
  4344             User::Leave( KErrArgument );    		
       
  4345     		}
       
  4346     	else
       
  4347     		{
       
  4348     	    User::LeaveIfError( iTestCaseResults.Append( result ) );
       
  4349     	    // Set test case allow result to CTestModuleIf side too. This is
       
  4350     	    // used in TAL-TA5L macro handling.
       
  4351     	    User::LeaveIfError( 
       
  4352     	        iTestScripter->TestModuleIf().SetAllowResult( result ) );
       
  4353     	    found = ETrue;
       
  4354     		}
       
  4355     	}
       
  4356 
       
  4357     if ( !found )
       
  4358     	{
       
  4359         __TRACE( KError, (_L("ExecuteLineL: No expected result value given")));
       
  4360         iRunErrorMessage = KErrMsgAllowNextResultInvalidValue;
       
  4361         User::Leave( KErrArgument );
       
  4362     	}    
       
  4363     }
       
  4364 
       
  4365 
       
  4366 /*
       
  4367 -------------------------------------------------------------------------------
       
  4368 
       
  4369     DESCRIPTION
       
  4370 
       
  4371     This module contains the implementation of CTestContinue class
       
  4372     member functions. CTestContinue handles ContinueScript calls from 
       
  4373     TestScripter.
       
  4374 
       
  4375 -------------------------------------------------------------------------------
       
  4376 */
       
  4377 // MACROS
       
  4378 #ifdef LOGGER
       
  4379 #undef LOGGER
       
  4380 #endif
       
  4381 #define LOGGER iTestScripter->iLog
       
  4382 
       
  4383 // ================= MEMBER FUNCTIONS =========================================
       
  4384 
       
  4385 /*
       
  4386 -------------------------------------------------------------------------------
       
  4387 
       
  4388      Class: CTestContinue
       
  4389 
       
  4390      Method: CTestContinue
       
  4391 
       
  4392      Description: Default constructor
       
  4393 
       
  4394      Parameters: CTestRunner* aTestRunner: in: Backpointer to CTestRunner
       
  4395 
       
  4396      Return Values: None
       
  4397 
       
  4398      Errors/Exceptions: None
       
  4399 
       
  4400      Status: Draft
       
  4401     
       
  4402 -------------------------------------------------------------------------------
       
  4403 */
       
  4404 CTestContinue::CTestContinue( CTestScripter* aTestScripter,
       
  4405                               TTestObject* aObject ): 
       
  4406     // Executed with lowest priority, must be lower than CTesRunner priority 
       
  4407     CActive(  CActive::EPriorityLow ),
       
  4408     iTestScripter( aTestScripter ),
       
  4409     iObject( aObject )
       
  4410     {
       
  4411     CActiveScheduler::Add( this );
       
  4412     __TRACEFUNC();
       
  4413     
       
  4414     }
       
  4415 
       
  4416 /*
       
  4417 -------------------------------------------------------------------------------
       
  4418 
       
  4419      Class: CTestContinue
       
  4420 
       
  4421      Method: ConstructL
       
  4422 
       
  4423      Description: Symbian OS second phase constructor
       
  4424 
       
  4425      Parameters:    None
       
  4426 
       
  4427      Return Values: None
       
  4428 
       
  4429      Errors/Exceptions: None
       
  4430 
       
  4431      Status: Draft
       
  4432     
       
  4433 -------------------------------------------------------------------------------
       
  4434 */
       
  4435 void CTestContinue::ConstructL()
       
  4436     {
       
  4437     
       
  4438     iObject->iScript->EnableSignal( iStatus );
       
  4439     SetActive();
       
  4440     
       
  4441     }
       
  4442 
       
  4443 /*
       
  4444 -------------------------------------------------------------------------------
       
  4445 
       
  4446      Class: CTestContinue
       
  4447 
       
  4448      Method: NewL
       
  4449 
       
  4450      Description: Two-phased constructor.
       
  4451           
       
  4452      Parameters: CTestRunner* aTestRunner: in: Backpointer to CTestRunner
       
  4453 
       
  4454      Return Values: CTestContinue*: new object
       
  4455 
       
  4456      Errors/Exceptions: Leaves if new or ConstructL leaves
       
  4457 
       
  4458      Status: Draft
       
  4459     
       
  4460 -------------------------------------------------------------------------------
       
  4461 */
       
  4462 
       
  4463 CTestContinue* CTestContinue::NewL( CTestScripter* aTestScripter,
       
  4464                                     TTestObject* aObject )
       
  4465     {
       
  4466     CTestContinue* self = 
       
  4467         new (ELeave) CTestContinue( aTestScripter, aObject );
       
  4468      
       
  4469     CleanupStack::PushL( self );
       
  4470     self->ConstructL();
       
  4471     CleanupStack::Pop();
       
  4472 
       
  4473     return self;
       
  4474     }
       
  4475 
       
  4476 /*
       
  4477 -------------------------------------------------------------------------------
       
  4478 
       
  4479      Class: CTestContinue
       
  4480 
       
  4481      Method: ~CTestContinue
       
  4482 
       
  4483      Description: Destructor
       
  4484      
       
  4485      Parameters:    None
       
  4486 
       
  4487      Return Values: None
       
  4488 
       
  4489      Errors/Exceptions: None
       
  4490 
       
  4491      Status: Draft
       
  4492     
       
  4493 -------------------------------------------------------------------------------
       
  4494 */     
       
  4495 
       
  4496 CTestContinue::~CTestContinue()
       
  4497     {
       
  4498     __TRACEFUNC();
       
  4499     Cancel();
       
  4500     
       
  4501     }
       
  4502 
       
  4503 /*
       
  4504 -------------------------------------------------------------------------------
       
  4505 
       
  4506      Class: CTestContinue
       
  4507 
       
  4508      Method: RunL
       
  4509 
       
  4510      Description: Derived from CActive, handles testcase execution.
       
  4511 
       
  4512      Parameters:    None.
       
  4513 
       
  4514      Return Values: None.
       
  4515 
       
  4516      Errors/Exceptions: Leaves on error situations.
       
  4517 
       
  4518      Status: Draft
       
  4519     
       
  4520 -------------------------------------------------------------------------------
       
  4521 */
       
  4522 void CTestContinue::RunL()
       
  4523     {
       
  4524 
       
  4525     __TRACEFUNC();
       
  4526     __TRACE( KMessage, (_L("CTestContinue::RunL: [%d] "), iStatus.Int() ));
       
  4527 
       
  4528     if( iObject->Signal() ) 
       
  4529         {
       
  4530         // If OOM testing is ongoing ignore result check(given by user).
       
  4531         if( !iTestScripter->iOOMIgnoreFailure )
       
  4532             {
       
  4533             // Erronous case RunError will called and test handling continue 
       
  4534             // from there.
       
  4535             if( iTestScripter->TestRunner().TestCaseResults().Count() == 0 )
       
  4536                 {
       
  4537                 // KErrNone is the default result expected 
       
  4538                 // if nothing else is given 
       
  4539                 User::LeaveIfError( iTestScripter->TestRunner().
       
  4540                     TestCaseResults().Append( KErrNone ) );
       
  4541                 }
       
  4542             
       
  4543             if( iTestScripter->TestRunner().TestCaseResults().
       
  4544                     Find( iStatus.Int() ) < 0 ) 
       
  4545                 {
       
  4546                 __TRACE( KError, ( _L("Command for [%S] failed (%d)"), 
       
  4547                     &iObject->ObjectId(), iStatus.Int() ));
       
  4548 
       
  4549 
       
  4550                 if( iStatus.Int() == KErrNone )
       
  4551                     {
       
  4552                     User::Leave( KErrGeneral );
       
  4553                     }
       
  4554                 else
       
  4555                     {
       
  4556                     User::Leave( iStatus.Int() );
       
  4557                     }
       
  4558                 }
       
  4559             }
       
  4560         else
       
  4561             {
       
  4562             __TRACE( KMessage, ( 
       
  4563                 _L( "OOM test: 'oomignorefailure' is ON, signal result[%d] ignored" ),
       
  4564                 iStatus.Int() ));
       
  4565             }
       
  4566 
       
  4567         iTestScripter->TestRunner().TestCaseResults().Reset();
       
  4568         
       
  4569          __TRACE( KMessage, (_L("CTestContinue::RunL: Set runner active ")));
       
  4570         iTestScripter->iTestRunner->SetRunnerActive();   
       
  4571         }
       
  4572     else
       
  4573         {
       
  4574         // Signal called from test side but 'waittestclass' not yet processed
       
  4575         iObject->iAsyncResult = iStatus.Int();
       
  4576         }        
       
  4577         
       
  4578     iObject->iScript->EnableSignal( iStatus );
       
  4579     SetActive();
       
  4580     
       
  4581     }
       
  4582      
       
  4583 /*
       
  4584 -------------------------------------------------------------------------------
       
  4585 
       
  4586      Class: CTestContinue
       
  4587 
       
  4588      Method: DoCancel
       
  4589 
       
  4590      Description: Derived from CActive handles the Cancel
       
  4591 
       
  4592      Parameters:    None.
       
  4593 
       
  4594      Return Values: None.
       
  4595 
       
  4596      Errors/Exceptions: None.
       
  4597 
       
  4598      Status: Draft
       
  4599     
       
  4600 -------------------------------------------------------------------------------
       
  4601 */
       
  4602 void CTestContinue::DoCancel()
       
  4603     {
       
  4604 
       
  4605     __TRACEFUNC();
       
  4606     __TRACE( KMessage, (_L("CTestContinue::DoCancel")));
       
  4607 
       
  4608     iObject->iScript->CancelSignal();
       
  4609     
       
  4610     }
       
  4611 
       
  4612 /*
       
  4613 -------------------------------------------------------------------------------
       
  4614 
       
  4615      Class: CTestContinue
       
  4616 
       
  4617      Method: RunError
       
  4618 
       
  4619      Description: Derived from CActive handles the Cancel
       
  4620 
       
  4621      Parameters:    None.
       
  4622 
       
  4623      Return Values: None.
       
  4624 
       
  4625      Errors/Exceptions: None.
       
  4626 
       
  4627      Status: Draft
       
  4628     
       
  4629 -------------------------------------------------------------------------------
       
  4630 */
       
  4631 TInt CTestContinue::RunError( TInt aError )
       
  4632     {
       
  4633 
       
  4634     // Return error from here, if none given from execution
       
  4635     if( iTestScripter->iResult.iResult == KErrNone )
       
  4636         {
       
  4637         iTestScripter->UpdateTestCaseResult(aError, _L("CTestContinue::RunError"));
       
  4638         }
       
  4639     CActiveScheduler::Current()->Stop();
       
  4640      
       
  4641     return KErrNone;
       
  4642     
       
  4643     }
       
  4644     
       
  4645 /*
       
  4646 -------------------------------------------------------------------------------
       
  4647 
       
  4648     DESCRIPTION
       
  4649 
       
  4650     This module contains the implementation of CDefinedValue class
       
  4651     member functions. 
       
  4652 -------------------------------------------------------------------------------
       
  4653 */
       
  4654 
       
  4655 // ================= MEMBER FUNCTIONS =========================================
       
  4656 /*
       
  4657 -------------------------------------------------------------------------------
       
  4658 
       
  4659      Class: CDefinedValue
       
  4660 
       
  4661      Method: CDefinedValue
       
  4662 
       
  4663      Description: Default constructor
       
  4664 
       
  4665      C++ default constructor can NOT contain any code, that
       
  4666      might leave.
       
  4667      
       
  4668      Parameters: None
       
  4669 
       
  4670      Return Values: None
       
  4671 
       
  4672      Errors/Exceptions: None
       
  4673 
       
  4674      Status: Draft
       
  4675     
       
  4676 -------------------------------------------------------------------------------
       
  4677 */
       
  4678 CDefinedValue::CDefinedValue()
       
  4679     {
       
  4680     }
       
  4681      
       
  4682 /*
       
  4683 -------------------------------------------------------------------------------
       
  4684 
       
  4685      Class: CDefinedValue
       
  4686 
       
  4687      Method: ConstructL
       
  4688 
       
  4689      Description: Symbian OS second phase constructor
       
  4690 
       
  4691      Symbian OS default constructor can leave.
       
  4692 
       
  4693      Parameters:    TDesC& aName: in: Define name
       
  4694                     TDesC& aValue: in: Define value
       
  4695 
       
  4696      Return Values: None
       
  4697 
       
  4698      Errors/Exceptions: None
       
  4699 
       
  4700      Status: Draft
       
  4701     
       
  4702 -------------------------------------------------------------------------------
       
  4703 */
       
  4704 void CDefinedValue::ConstructL( TDesC& aName, TDesC& aValue )
       
  4705     {    
       
  4706 
       
  4707     iNameBuf = aName.AllocLC();
       
  4708     iName.Set( iNameBuf->Des() );
       
  4709     iValueBuf = aValue.AllocLC();
       
  4710     iValue.Set( iValueBuf->Des() );
       
  4711     CleanupStack::Pop( iValueBuf );
       
  4712     CleanupStack::Pop( iNameBuf );
       
  4713 
       
  4714     }
       
  4715 
       
  4716 /*
       
  4717 -------------------------------------------------------------------------------
       
  4718 
       
  4719      Class: CDefinedValue
       
  4720 
       
  4721      Method: NewL
       
  4722 
       
  4723      Description: Two-phased constructor.
       
  4724           
       
  4725      Parameters:    TDesC& aName: in: Define name
       
  4726                     TDesC& aValue: in: Define value
       
  4727 
       
  4728      Return Values: CDefinedValue*: new object
       
  4729 
       
  4730      Errors/Exceptions: Leaves if new or ConstructL leaves.
       
  4731 
       
  4732      Status: Draft
       
  4733     
       
  4734 -------------------------------------------------------------------------------
       
  4735 */
       
  4736 CDefinedValue* CDefinedValue::NewL( TDesC& aName, TDesC& aValue )
       
  4737     {
       
  4738 
       
  4739     CDefinedValue* self = new (ELeave) CDefinedValue();
       
  4740      
       
  4741     CleanupStack::PushL( self );
       
  4742     self->ConstructL( aName, aValue );
       
  4743     CleanupStack::Pop();
       
  4744 
       
  4745     return self;
       
  4746 
       
  4747     }    
       
  4748     
       
  4749 /*
       
  4750 -------------------------------------------------------------------------------
       
  4751 
       
  4752      Class: CDefinedValue
       
  4753 
       
  4754      Method: ~CDefinedValue
       
  4755 
       
  4756      Description: Destructor
       
  4757      
       
  4758      Parameters:    None
       
  4759 
       
  4760      Return Values: None
       
  4761 
       
  4762      Errors/Exceptions: None
       
  4763 
       
  4764      Status: Draft
       
  4765     
       
  4766 -------------------------------------------------------------------------------
       
  4767 */     
       
  4768 CDefinedValue::~CDefinedValue()
       
  4769     {
       
  4770     
       
  4771     delete iValueBuf;
       
  4772     delete iNameBuf;
       
  4773     
       
  4774     }
       
  4775     
       
  4776 /*
       
  4777 -------------------------------------------------------------------------------
       
  4778 
       
  4779      Class: CDefinedValue
       
  4780 
       
  4781      Method: SetValueL
       
  4782 
       
  4783      Description: Set new define value
       
  4784 
       
  4785      Parameters:    TDesC& aValue: in: Define value
       
  4786 
       
  4787      Return Values: None
       
  4788 
       
  4789      Errors/Exceptions: Leaves on error.
       
  4790 
       
  4791      Status: Draft
       
  4792     
       
  4793 -------------------------------------------------------------------------------
       
  4794 */
       
  4795 void CDefinedValue::SetValueL( TDesC& aValue )
       
  4796     {
       
  4797     delete iValueBuf;
       
  4798     iValueBuf = 0;
       
  4799     iValueBuf = aValue.AllocLC();
       
  4800     iValue.Set( iValueBuf->Des() );
       
  4801     CleanupStack::Pop( iValueBuf );
       
  4802     
       
  4803     }
       
  4804 
       
  4805     
       
  4806 /*
       
  4807 -------------------------------------------------------------------------------
       
  4808 
       
  4809      Class: CDefinedValue
       
  4810 
       
  4811      Method: Name
       
  4812 
       
  4813      Description: Returns define name.
       
  4814 
       
  4815      Parameters:  None
       
  4816 
       
  4817      Return Values: TDesC: Define name
       
  4818 
       
  4819      Errors/Exceptions: None
       
  4820 
       
  4821      Status: Draft
       
  4822     
       
  4823 -------------------------------------------------------------------------------
       
  4824 */
       
  4825 TDesC& CDefinedValue::Name()
       
  4826     { 
       
  4827     return iName; 
       
  4828     }
       
  4829         
       
  4830 /*
       
  4831 -------------------------------------------------------------------------------
       
  4832 
       
  4833      Class: CDefinedValue
       
  4834 
       
  4835      Method: Value
       
  4836 
       
  4837      Description: Returns define value.
       
  4838 
       
  4839      Parameters:  None
       
  4840 
       
  4841      Return Values: TDesC: Define value
       
  4842 
       
  4843      Errors/Exceptions: None
       
  4844 
       
  4845      Status: Draft
       
  4846     
       
  4847 -------------------------------------------------------------------------------
       
  4848 */
       
  4849 TDesC& CDefinedValue::Value()
       
  4850     { 
       
  4851     return iValue; 
       
  4852     }
       
  4853     
       
  4854 
       
  4855 /*
       
  4856 -------------------------------------------------------------------------------
       
  4857 
       
  4858     DESCRIPTION
       
  4859 
       
  4860     This module contains the implementation of TTestObjectBase class
       
  4861     member functions. 
       
  4862 -------------------------------------------------------------------------------
       
  4863 */
       
  4864 
       
  4865 // ================= MEMBER FUNCTIONS =========================================
       
  4866 /*
       
  4867 -------------------------------------------------------------------------------
       
  4868 
       
  4869      Class: TTestObjectBase
       
  4870 
       
  4871      Method: TTestObjectBase
       
  4872 
       
  4873      Description: Constructor
       
  4874 
       
  4875      Parameters: None
       
  4876 
       
  4877      Return Values: None
       
  4878 
       
  4879      Errors/Exceptions: None
       
  4880 
       
  4881      Status: Draft
       
  4882     
       
  4883 -------------------------------------------------------------------------------
       
  4884 */    
       
  4885 TTestObjectBase::TTestObjectBase( TObjectType aType ) : 
       
  4886     iAsyncResult( KErrNone ),
       
  4887     iType( aType )
       
  4888     {
       
  4889     
       
  4890     RDebug::Print( _L("TTestObjectBase::TTestObjectBase") );
       
  4891     iName.Zero(); 
       
  4892     
       
  4893     }
       
  4894     
       
  4895     /*
       
  4896 -------------------------------------------------------------------------------
       
  4897 
       
  4898      Class: TTestObjectBase
       
  4899 
       
  4900      Method: ~TTestObjectBase
       
  4901 
       
  4902      Description: Destructor
       
  4903 
       
  4904      Parameters: None
       
  4905 
       
  4906      Return Values: None
       
  4907 
       
  4908      Errors/Exceptions: None
       
  4909 
       
  4910      Status: Draft
       
  4911     
       
  4912 -------------------------------------------------------------------------------
       
  4913 */    
       
  4914 TTestObjectBase::~TTestObjectBase()
       
  4915     {
       
  4916     
       
  4917     RDebug::Print( _L("TTestObjectBase::~TTestObjectBase") );
       
  4918 
       
  4919     }
       
  4920 
       
  4921 /*
       
  4922 -------------------------------------------------------------------------------
       
  4923 
       
  4924     DESCRIPTION
       
  4925 
       
  4926     This module contains the implementation of TTestObject class
       
  4927     member functions. 
       
  4928 -------------------------------------------------------------------------------
       
  4929 */
       
  4930 // ================= MEMBER FUNCTIONS =========================================
       
  4931 
       
  4932 /*
       
  4933 -------------------------------------------------------------------------------
       
  4934 
       
  4935      Class: TTestObject
       
  4936 
       
  4937      Method: TTestObject
       
  4938 
       
  4939      Description: Constructor
       
  4940 
       
  4941      Parameters: None
       
  4942 
       
  4943      Return Values: None
       
  4944 
       
  4945      Errors/Exceptions: None
       
  4946 
       
  4947      Status: Draft
       
  4948     
       
  4949 -------------------------------------------------------------------------------
       
  4950 */    
       
  4951 TTestObject::TTestObject() :
       
  4952     TTestObjectBase( EObjectNormal ),
       
  4953     iScript(0),
       
  4954     iContinue(0),
       
  4955     iCount(0)
       
  4956     {
       
  4957 
       
  4958     RDebug::Print( _L("TTestObject::TTestObject") );
       
  4959 
       
  4960     }
       
  4961 
       
  4962 /*
       
  4963 -------------------------------------------------------------------------------
       
  4964 
       
  4965      Class: TTestObject
       
  4966 
       
  4967      Method: ~TTestObject
       
  4968 
       
  4969      Description: Destructor
       
  4970 
       
  4971      Parameters: None
       
  4972 
       
  4973      Return Values: None
       
  4974 
       
  4975      Errors/Exceptions: None
       
  4976 
       
  4977      Status: Draft
       
  4978     
       
  4979 -------------------------------------------------------------------------------
       
  4980 */
       
  4981 TTestObject::~TTestObject()
       
  4982     { 
       
  4983     
       
  4984     RDebug::Print( _L("TTestObject::~TTestObject") );
       
  4985     delete iContinue; 
       
  4986     delete iScript;
       
  4987     
       
  4988     }
       
  4989         
       
  4990 /*
       
  4991 -------------------------------------------------------------------------------
       
  4992 
       
  4993      Class: TTestObject
       
  4994 
       
  4995      Method: RunMethodL
       
  4996 
       
  4997      Description: Run specified method from testclass.
       
  4998 
       
  4999      Parameters: CStifItemParser* aItem: in: itemparser
       
  5000 
       
  5001      Return Values: Symbian OS error code
       
  5002 
       
  5003      Errors/Exceptions: None
       
  5004 
       
  5005      Status: Draft
       
  5006     
       
  5007 -------------------------------------------------------------------------------
       
  5008 */
       
  5009 TInt TTestObject::RunMethodL( CStifItemParser& aItem )
       
  5010     { 
       
  5011     
       
  5012     return iScript->RunMethodL( aItem ); 
       
  5013     
       
  5014     }
       
  5015     
       
  5016 /*
       
  5017 -------------------------------------------------------------------------------
       
  5018 
       
  5019     DESCRIPTION
       
  5020 
       
  5021     This module contains the implementation of TTestObjectKernel class
       
  5022     member functions. 
       
  5023 -------------------------------------------------------------------------------
       
  5024 */
       
  5025 // ================= MEMBER FUNCTIONS =========================================
       
  5026 
       
  5027 
       
  5028 /*
       
  5029 -------------------------------------------------------------------------------
       
  5030 
       
  5031      Class: TTestObjectKernel
       
  5032 
       
  5033      Method: TTestObjectKernel
       
  5034 
       
  5035      Description: Constructor
       
  5036 
       
  5037      Parameters: None
       
  5038 
       
  5039      Return Values: None
       
  5040 
       
  5041      Errors/Exceptions: None
       
  5042 
       
  5043      Status: Draft
       
  5044     
       
  5045 -------------------------------------------------------------------------------
       
  5046 */    
       
  5047 TTestObjectKernel::TTestObjectKernel() : 
       
  5048     TTestObjectBase( EObjectKernel )
       
  5049     {
       
  5050     
       
  5051     RDebug::Print( _L("TTestObjectKernel::TTestObjectKernel") );
       
  5052     
       
  5053     }
       
  5054     
       
  5055 /*
       
  5056 -------------------------------------------------------------------------------
       
  5057 
       
  5058      Class: TTestObjectKernel
       
  5059 
       
  5060      Method: ~TTestObjectKernel
       
  5061 
       
  5062      Description: Destructor
       
  5063 
       
  5064      Parameters: None
       
  5065 
       
  5066      Return Values: None
       
  5067 
       
  5068      Errors/Exceptions: None
       
  5069 
       
  5070      Status: Draft
       
  5071     
       
  5072 -------------------------------------------------------------------------------
       
  5073 */
       
  5074 TTestObjectKernel::~TTestObjectKernel()
       
  5075     { 
       
  5076     
       
  5077     RDebug::Print( _L("TTestObjectKernel::~TTestObjectKernel") );
       
  5078     
       
  5079     iTestClass.Close(); 
       
  5080     User::FreeLogicalDevice( iLddName );
       
  5081     
       
  5082     }
       
  5083    
       
  5084 /*
       
  5085 -------------------------------------------------------------------------------
       
  5086 
       
  5087      Class: TTestObjectKernel
       
  5088 
       
  5089      Method: RunMethodL
       
  5090 
       
  5091      Description: Run specified method from kernel testclass.
       
  5092 
       
  5093      Parameters: CStifItemParser& aItem: in: itemparser
       
  5094 
       
  5095      Return Values: Symbian OS error code
       
  5096 
       
  5097      Errors/Exceptions: None
       
  5098 
       
  5099      Status: Draft
       
  5100     
       
  5101 -------------------------------------------------------------------------------
       
  5102 */
       
  5103 TInt TTestObjectKernel::RunMethodL( CStifItemParser& aItem )
       
  5104     { 
       
  5105     
       
  5106     TPtrC method;
       
  5107     TPtrC params;
       
  5108     
       
  5109     User::LeaveIfError( aItem.GetNextString( method ) );
       
  5110     aItem.Remainder( params );
       
  5111     
       
  5112     TInt result;
       
  5113     TMethodResultDes resultDes;
       
  5114           
       
  5115     // Need to change descriptors from 16bit to 8bit for EKA2 kernel
       
  5116     // because STIF Parser doesn't support 8bit parsing
       
  5117     HBufC8 * myBuf1 = HBufC8::NewL( method.Length() );
       
  5118     TPtr8 met8 = myBuf1->Des();   
       
  5119     met8.Copy( method );
       
  5120         
       
  5121     HBufC8 * myBuf2 = HBufC8::NewL( params.Length() );
       
  5122     TPtr8 par8 = myBuf2->Des();   
       
  5123     par8.Copy( params );
       
  5124     
       
  5125     TInt ret =  iTestClass.RunMethod( met8, par8, result, resultDes );
       
  5126 
       
  5127     delete myBuf1;
       
  5128     delete myBuf2;
       
  5129     
       
  5130     if( ret != KErrNone )
       
  5131         {
       
  5132         return ret;
       
  5133         }
       
  5134     
       
  5135     return result;                             
       
  5136                                      
       
  5137     };
       
  5138     
       
  5139 // ================= OTHER EXPORTED FUNCTIONS =================================
       
  5140 
       
  5141 /*
       
  5142 -------------------------------------------------------------------------------
       
  5143     
       
  5144      Function: LibEntryL
       
  5145 
       
  5146      Description: Polymorphic Dll Entry Point
       
  5147 
       
  5148      Parameters:    None.
       
  5149 
       
  5150      Return Values: CTestScripter*: pointer to new CTestScripter
       
  5151 
       
  5152      Errors/Exceptions: Leaves if NewL leaves.
       
  5153 
       
  5154      Status: Draft
       
  5155      
       
  5156 -------------------------------------------------------------------------------
       
  5157 */
       
  5158 
       
  5159 EXPORT_C CTestScripter* LibEntryL()
       
  5160     {
       
  5161     return CTestScripter::NewL();
       
  5162     
       
  5163     }
       
  5164 
       
  5165 
       
  5166 //  End of File