stif/TestCombiner/src/TestCombiner.cpp
changeset 0 a03f92240627
child 8 ecff51f1e7fb
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 module contains the implementation of 
       
    15 * CTestCombiner class member functions.
       
    16 *
       
    17 */
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <StifTestEventInterface.h>
       
    21 #include <StifLogger.h>
       
    22 #include "TestCombiner.h"
       
    23 #include "TestKeywords.h"
       
    24 #include "TestCase.h"
       
    25 #include "TestCombinerEvent.h"
       
    26 #include "Logging.h"
       
    27 //--PYTHON-- begin
       
    28 #include "StifPython.h"
       
    29 #include "StifPythonFunComb.h"
       
    30 //--PYTHON-- end
       
    31 #include "SettingServerClient.h"
       
    32 
       
    33 // EXTERNAL DATA STRUCTURES
       
    34 // None
       
    35 
       
    36 // EXTERNAL FUNCTION PROTOTYPES  
       
    37 // None
       
    38 
       
    39 // CONSTANTS
       
    40 _LIT( KTestRunner, "CTestRunner" );
       
    41 _LIT( KRemoteTimer, "CRemoteTimer" );
       
    42 _LIT( KRemoteReceiver, "CRemoteReceiver" );
       
    43 
       
    44 // MACROS
       
    45 #ifdef LOGGER
       
    46 #undef LOGGER
       
    47 #endif
       
    48 #define LOGGER iLog
       
    49 
       
    50 // LOCAL CONSTANTS AND MACROS
       
    51 _LIT(KTitle, "title");
       
    52 _LIT(KTimeout, "timeout");
       
    53 _LIT(KPriority, "priority");
       
    54 
       
    55 //printing macros
       
    56  _LIT( KExecute, "Execute");
       
    57  
       
    58 // MODULE DATA STRUCTURES
       
    59 // None
       
    60 
       
    61 // LOCAL FUNCTION PROTOTYPES
       
    62 // None
       
    63 
       
    64 // FORWARD DECLARATIONS
       
    65 // None
       
    66 
       
    67 // ==================== LOCAL FUNCTIONS =======================================
       
    68 // None
       
    69 
       
    70 // ================= MEMBER FUNCTIONS =========================================
       
    71 
       
    72 /*
       
    73 -------------------------------------------------------------------------------
       
    74 
       
    75      Class: CTestCombiner
       
    76 
       
    77      Method: CTestCombiner
       
    78 
       
    79      Description: Default constructor
       
    80 
       
    81      C++ default constructor can NOT contain any code, that
       
    82      might leave.
       
    83      
       
    84      Parameters:    None
       
    85 
       
    86      Return Values: None
       
    87 
       
    88      Errors/Exceptions: None
       
    89 
       
    90      Status: Approved
       
    91     
       
    92 -------------------------------------------------------------------------------
       
    93 */
       
    94 CTestCombiner::CTestCombiner(): 
       
    95     iSchedulerActive( EFalse ),
       
    96     iRunningTests( 0 ), 
       
    97     iResult( KErrNone ),
       
    98     iEventPckg( iEvent ),
       
    99     iRemoteTimeout( KRemoteProtocolTimeout ),
       
   100     iCancelIfError( EFalse ),
       
   101     iFailedTestCase( 0 ),
       
   102     iLoopIsUsed( EFalse )
       
   103     {
       
   104 
       
   105     }
       
   106 
       
   107 /*
       
   108 -------------------------------------------------------------------------------
       
   109 
       
   110      Class: CTestCombiner
       
   111 
       
   112      Method: ConstructL
       
   113 
       
   114      Description: Symbian OS second phase constructor
       
   115 
       
   116      Symbian OS default constructor can leave.
       
   117 
       
   118      Parameters:    None
       
   119 
       
   120      Return Values: None
       
   121 
       
   122      Errors/Exceptions: None.
       
   123 
       
   124      Status: Approved
       
   125 
       
   126 -------------------------------------------------------------------------------
       
   127 */
       
   128 void CTestCombiner::ConstructL()
       
   129     {
       
   130     // TRAPed to avoid crashing if logfile creation fails,
       
   131     // so we can run test without logging to file
       
   132     TRAPD( err, iStdLog = CStifLogger::NewL( KTestCombinerLogDir, 
       
   133                                       KTestCombinerLogFile );
       
   134         );
       
   135     if( err != KErrNone )
       
   136         {
       
   137         iStdLog = NULL;
       
   138         __RDEBUG( (_L("Creating logfile failed") ) );
       
   139         }  
       
   140     iLog = iStdLog;
       
   141 
       
   142     //Read logger settings to check whether test case name is to be
       
   143     //appended to log file name.
       
   144     RSettingServer settingServer;
       
   145     TInt ret = settingServer.Connect();
       
   146     if(ret != KErrNone)
       
   147         {
       
   148         User::Leave(ret);
       
   149         }
       
   150     // Struct to StifLogger settigs.
       
   151     TLoggerSettings loggerSettings; 
       
   152     // Parse StifLogger defaults from STIF initialization file.
       
   153     ret = settingServer.GetLoggerSettings(loggerSettings);
       
   154     if(ret != KErrNone)
       
   155         {
       
   156         User::Leave(ret);
       
   157         }
       
   158 
       
   159     // Get engine settings
       
   160     TEngineSettings engineSettings;
       
   161     ret = settingServer.GetEngineSettings(engineSettings);
       
   162     if(ret != KErrNone)
       
   163         {
       
   164         __TRACE(KError, (_L("Could not retrieve engine settings from SettingServer [%d]"), ret));
       
   165         iUITestingSupport = EFalse;
       
   166         iSeparateProcesses = EFalse;
       
   167         }
       
   168         else
       
   169         {
       
   170         iUITestingSupport = engineSettings.iUITestingSupport;
       
   171         iSeparateProcesses = engineSettings.iSeparateProcesses;
       
   172         __TRACE(KMessage, (_L("Engine settings retrieved from SettingServer. UITestingSupport [%d] SeparateProcesses [%d]"), iUITestingSupport, iSeparateProcesses));
       
   173         }
       
   174 
       
   175     // Close Setting server session
       
   176     settingServer.Close();
       
   177     iAddTestCaseTitleToLogName = loggerSettings.iAddTestCaseTitle;
       
   178 
       
   179     iIndexTestModuleControllers = 1;
       
   180     
       
   181     __TRACE( KPrint, ( _L("New TestCombiner") ) );
       
   182 
       
   183     }
       
   184 
       
   185 /*
       
   186 -------------------------------------------------------------------------------
       
   187 
       
   188      Class: CTestCombiner
       
   189 
       
   190      Method: NewL
       
   191 
       
   192      Description: Two-phased constructor.
       
   193           
       
   194      Parameters:    None
       
   195 
       
   196      Return Values: CTestCombiner*: new object
       
   197 
       
   198      Errors/Exceptions: Leaves if new or ConstructL leaves.
       
   199 
       
   200      Status: Approved
       
   201     
       
   202 -------------------------------------------------------------------------------
       
   203 */
       
   204 CTestCombiner* CTestCombiner::NewL()
       
   205     {
       
   206      
       
   207     CTestCombiner* self = new (ELeave) CTestCombiner();
       
   208     
       
   209     CleanupStack::PushL( self );
       
   210     self->ConstructL();
       
   211     CleanupStack::Pop();
       
   212 
       
   213     return self;
       
   214      
       
   215     }
       
   216 
       
   217 /*
       
   218 -------------------------------------------------------------------------------
       
   219 
       
   220      Class: CTestCombiner
       
   221 
       
   222      Method: ~CTestCombiner
       
   223 
       
   224      Description: Destructor
       
   225      
       
   226      Parameters:    None
       
   227 
       
   228      Return Values: None
       
   229 
       
   230      Errors/Exceptions: None
       
   231 
       
   232      Status: Approved
       
   233     
       
   234 -------------------------------------------------------------------------------
       
   235 */
       
   236 CTestCombiner::~CTestCombiner()
       
   237     {
       
   238     iLoopAllocationArray.Reset();
       
   239     iLoopAllocationArray.Close();
       
   240     iLoopIsUsed = EFalse;
       
   241 
       
   242     iTestCases.ResetAndDestroy();
       
   243     iTestModules.ResetAndDestroy();
       
   244     iEventArray.ResetAndDestroy();
       
   245     iSlaveArray.ResetAndDestroy();
       
   246     iSendReceive.ResetAndDestroy();
       
   247 
       
   248     iTestCases.Close();
       
   249     iTestModules.Close();
       
   250     iEventArray.Close();
       
   251     iSlaveArray.Close();
       
   252     iSendReceive.Close();
       
   253 
       
   254     // Stop all remaining measurement modules
       
   255     const TInt count_meas = iTestMeasurementArray.Count();
       
   256     for( TInt b = 0; b < count_meas; b++ )
       
   257         {
       
   258         iTestMeasurementArray[b]->iMeasurement->Stop();
       
   259         }
       
   260     iTestMeasurementArray.ResetAndDestroy();
       
   261     iTestMeasurementArray.Close();
       
   262 
       
   263     delete iSectionParser;
       
   264     delete iRemoteReceiver;
       
   265     delete iTestRunner;
       
   266 
       
   267     iLog = NULL;
       
   268     delete iStdLog;
       
   269     iStdLog = NULL;
       
   270     delete iTCLog;
       
   271     iTCLog = NULL;
       
   272     }
       
   273 
       
   274 /*
       
   275 -------------------------------------------------------------------------------
       
   276 
       
   277      Class: CTestCombiner
       
   278 
       
   279      Method: InitL
       
   280 
       
   281      Description: InitL is used to initialize the Test Module.
       
   282 
       
   283      Parameters: const TFileName& aIniFile: in: Initialization file
       
   284                  TBool aFirstTime: in: First time flag 
       
   285 
       
   286      Return Values: Symbian OS error code
       
   287 
       
   288      Errors/Exceptions: Leaves if ReadInitializationL leaves
       
   289 
       
   290      Status: Draft
       
   291 
       
   292 -------------------------------------------------------------------------------
       
   293 */
       
   294 TInt CTestCombiner::InitL( TFileName& aIniFile, 
       
   295                            TBool /*aFirstTime*/ )
       
   296     {
       
   297 
       
   298     __TRACEFUNC();
       
   299 
       
   300     if( aIniFile.Length() > 0 )
       
   301         {
       
   302         // Read initialization from test case file
       
   303         ReadInitializationL( aIniFile );
       
   304         }
       
   305 
       
   306     return KErrNone;
       
   307 
       
   308     }
       
   309 
       
   310 /*
       
   311 -------------------------------------------------------------------------------
       
   312 
       
   313      Class: CTestCombiner
       
   314 
       
   315      Method: GetTestCases
       
   316 
       
   317      Description: GetTestCases is used to inquired test cases
       
   318 
       
   319      Parameters:    const TFileName& aConfigFile: in: Config file name
       
   320                     RPointerArray<RTestEngine::TTestCaseInfo>& aTestCases: out: 
       
   321                           Array of TestCases 
       
   322 
       
   323      Return Values: KErrNone: Success
       
   324                     KErrNotFound: Testcases not found
       
   325 
       
   326      Errors/Exceptions: Leaves if CStifParser::NewL leaves
       
   327                         Leaves if CStifParser::SectionL leaves
       
   328                         Leaves if CStifParser::NextSectionL leaves
       
   329                         Leaves if memory allocation fails
       
   330 
       
   331      Status: Approved
       
   332 
       
   333 -------------------------------------------------------------------------------
       
   334 */
       
   335 TInt CTestCombiner::GetTestCasesL( const TFileName& aConfigFile, 
       
   336                                    RPointerArray<TTestCaseInfo>& aTestCases )
       
   337     {
       
   338     __TRACEFUNC();
       
   339 
       
   340     if( aConfigFile.Length() == 0 )
       
   341         {
       
   342         __TRACE( KError, (_L("No test case script file given") ) );
       
   343         __RDEBUG( (_L("No test case script file given") ) );
       
   344         return KErrNotFound;
       
   345         }
       
   346 
       
   347     CStifParser* parser = NULL;
       
   348     TRAPD( err, parser = 
       
   349         CStifParser::NewL( _L(""), aConfigFile, CStifParser::ECStyleComments ) );
       
   350     if( err != KErrNone )
       
   351         {
       
   352         __TRACE( KError, (_L("Test case script file not found") ) );
       
   353         __RDEBUG( (_L("Test case script file not found") ) );
       
   354         return KErrNotFound;
       
   355         }
       
   356     CleanupStack::PushL( parser );
       
   357     CStifSectionParser* section;
       
   358     TPtrC tmp;
       
   359     TInt index = 0;
       
   360     TInt ret = KErrNone;
       
   361 
       
   362     section = parser->SectionL( KTestStartTag, KTestEndTag );
       
   363     if( section == NULL )
       
   364         {
       
   365         ret = KErrNotFound;
       
   366         }
       
   367     else
       
   368         {    
       
   369         while( section )
       
   370             {
       
   371             CleanupStack::PushL( section );
       
   372              
       
   373             if( section->GetLine( KTitle,  tmp, ENoTag ) == KErrNone )
       
   374                  {
       
   375                  if( tmp.Length() > KMaxName )
       
   376                     {
       
   377                     tmp.Set( tmp.Left( KMaxName ) );
       
   378                     }                    
       
   379                  TTestCaseInfo* tc = new ( ELeave ) TTestCaseInfo();
       
   380                  CleanupStack::PushL( tc );
       
   381                  __TRACE( KVerbose, (_L("TestCase: %S"), &tmp));
       
   382                  tc->iTitle.Copy( tmp );
       
   383                  tc->iCaseNumber = ++index;
       
   384                  CStifItemParser* item = section->GetItemLineL( KTimeout );
       
   385                  if( item )
       
   386                     {
       
   387                     TInt timeout; // In milliseconds
       
   388                     ret = item->GetInt( KTimeout, timeout ); 
       
   389                     if( ret != KErrNone )
       
   390                         {
       
   391                         __TRACE( KError, (_L("Illegal timeout")));
       
   392                         User::Leave( ret ); 
       
   393                         }
       
   394                     tc->iTimeout = (TInt64)timeout*1000;
       
   395                     __TRACE( KMessage, (_L("Timeout: %i"), tc->iTimeout.Int64() ));
       
   396                     }
       
   397                  item = section->GetItemLineL( KPriority );
       
   398                  if( item )
       
   399                     {
       
   400                     ret = item->GetInt( KPriority, tc->iPriority ); 
       
   401                     if( ret != KErrNone )
       
   402                         {
       
   403                         TPtrC priority;
       
   404                         ret = item->GetString( KPriority, priority );
       
   405                         if( ret != KErrNone )
       
   406                             {
       
   407                             __TRACE( KError, (_L("Illegal priority")));
       
   408                             User::Leave( ret ); 
       
   409                             }
       
   410                         switch( TTCKeywords::Parse( priority, 
       
   411                                                     TTCKeywords::Priority ) )
       
   412                             {
       
   413                             case TTCKeywords::EPriHigh:
       
   414                                 tc->iPriority = TTestCaseInfo::EPriorityHigh;
       
   415                                 break;
       
   416                             case TTCKeywords::EPriNormal:
       
   417                                 tc->iPriority = TTestCaseInfo::EPriorityNormal;
       
   418                                 break;
       
   419                             case TTCKeywords::EPriLow:
       
   420                                 tc->iPriority = TTestCaseInfo::EPriorityLow;
       
   421                                 break;
       
   422                             default:
       
   423                                 __TRACE( KError, (_L("Illegal priority")));
       
   424                                 User::Leave( KErrArgument ); 
       
   425                             }
       
   426                         }
       
   427                     __TRACE( KMessage, (_L("Priority: %i"), tc->iPriority ));
       
   428                     }
       
   429 
       
   430                  aTestCases.Append(tc);
       
   431                  CleanupStack::Pop( tc );
       
   432                  }
       
   433             CleanupStack::PopAndDestroy( section );
       
   434             section = parser->NextSectionL( KTestStartTag, KTestEndTag );
       
   435             }
       
   436         }
       
   437 
       
   438     CleanupStack::PopAndDestroy( parser );
       
   439 
       
   440     __TRACE( KPrint, (  _L( "Configfile '%S', testcases %d" ),
       
   441         &aConfigFile, index ));
       
   442 
       
   443     return ret;
       
   444 
       
   445     }
       
   446 
       
   447 /*
       
   448 -------------------------------------------------------------------------------
       
   449 
       
   450      Class: CTestCombiner
       
   451 
       
   452      Method: RunTestCaseL
       
   453 
       
   454      Description: Run a specified testcase.
       
   455 
       
   456      RunTestCaseL is used to run an individual test case specified 
       
   457      by aTestCase. 
       
   458 
       
   459      Parameters:    const TInt aCaseNumber: in: Testcase number 
       
   460                     const TFileName& aConfig: in: Configuration file name
       
   461                     TTestResult& aResult: out; test case result
       
   462 
       
   463      Return Values: KErrNone: Test case started succesfully.
       
   464                     KErrNotFound: Testcase not found
       
   465                     KErrUnknown: Unknown TestCombiner error
       
   466                     Any other SymbianOS error
       
   467 
       
   468      Errors/Exceptions: Leaves if GetTestCaseL leaves
       
   469                         Leaves if RunTestL leaves
       
   470                         Leaves if memory allocation fails
       
   471 
       
   472      Status: Approved
       
   473 
       
   474 -------------------------------------------------------------------------------
       
   475 */
       
   476 TInt CTestCombiner::RunTestCaseL( const TInt aCaseNumber, 
       
   477                                   const TFileName& aConfig, 
       
   478                                   TTestResult& aResult )
       
   479     {
       
   480     __TRACEFUNC();
       
   481 
       
   482     __TRACE( KMessage, (_L("***Testcase started***")));
       
   483 
       
   484     //Open new log file with test case title in file name
       
   485     if(iAddTestCaseTitleToLogName)
       
   486         {
       
   487         //Close test case log if exists
       
   488         if(iTCLog)
       
   489             {
       
   490             delete iTCLog;
       
   491             iTCLog = NULL;
       
   492             }
       
   493         TFileName logFileName;
       
   494         TName title;
       
   495         TestModuleIf().GetTestCaseTitleL(title);
       
   496         
       
   497         logFileName.Format(KTestCombinerLogFileWithTitle, &title);
       
   498         iTCLog = CStifLogger::NewL(KTestCombinerLogDir, logFileName);
       
   499         iLog = iTCLog;
       
   500         }
       
   501 
       
   502     /* 
       
   503     * Allow memory leaks, because Defines are leaved untouched 
       
   504     * after test case execution. Real memory leaks are detected with 
       
   505     * UHEAP macros.
       
   506     */
       
   507     TestModuleIf().SetBehavior( CTestModuleIf::ETestLeaksMem );
       
   508 
       
   509     // Read initialization from test case file
       
   510     ReadInitializationL( aConfig );
       
   511 
       
   512     __UHEAP_MARK;
       
   513         
       
   514     iSectionParser = GetTestCaseL( aCaseNumber, aConfig );
       
   515 
       
   516     // Check parsing result
       
   517     if( iSectionParser == NULL )
       
   518         {
       
   519         __TRACE( KError, (_L("***Parsing testcase failed***")));
       
   520         __UHEAP_MARKEND;
       
   521         return KErrNotFound;
       
   522         }
       
   523 
       
   524     CActiveScheduler* activeScheduler = 
       
   525         new ( ELeave ) CActiveScheduler();
       
   526     CleanupStack::PushL( activeScheduler );
       
   527     CActiveScheduler::Install( activeScheduler );
       
   528 
       
   529     // Resetting these variables to normal state @js             
       
   530     iFailedTestCase = 0;    
       
   531     iCancelIfError = EFalse;
       
   532     iScriptFailed = KErrNone;
       
   533     iScriptFailedDescription.Copy(KNullDesC);
       
   534 
       
   535     // Run the given testcase described in iSectionParser section
       
   536     RunTestL();
       
   537 
       
   538     CleanupStack::PopAndDestroy( activeScheduler );
       
   539 
       
   540     delete iSectionParser;
       
   541     iSectionParser = NULL;
       
   542 
       
   543     TInt ret = KErrNone;
       
   544     // Check if test case starting failed
       
   545     if( iResult != KErrNone )
       
   546         {
       
   547         TestModuleIf().Printf( KPrintPriHigh, _L("Result"), _L("Starting FAILED"));
       
   548          __TRACE( KError, (_L("***Starting testcase FAILED***")));
       
   549         ret = iResult;
       
   550         aResult.iResult = -2;
       
   551         aResult.iResultDes = _L("Testcase script execution failed");
       
   552         }
       
   553     else if(iScriptFailed != KErrNone)
       
   554         {
       
   555         TestModuleIf().Printf( KPrintPriHigh, _L("Result"), _L("Script execution FAILED"));
       
   556         __TRACE( KError, (_L("***Sscript execution FAILED***")));
       
   557         aResult.iResult = iScriptFailed;
       
   558         if(iScriptFailedDescription != KNullDesC)
       
   559             {
       
   560             aResult.iResultDes.Copy(iScriptFailedDescription);
       
   561             }
       
   562         else
       
   563             {
       
   564             aResult.iResultDes = _L("Testcase script execution failed");
       
   565             }
       
   566         }
       
   567     else
       
   568         {
       
   569         __TRACE( KPrint, (_L("***Testcase completed***")));
       
   570               
       
   571         // Testcombiner succeeded to start all testcases, 
       
   572         // check individual testcase results
       
   573         TInt count = iTestCases.Count();
       
   574         TInt i = iFailedTestCase;
       
   575         // iFailedTestCase is either 0 or the number of failed test case if 
       
   576         // canceliferror was given and a test case has failed
       
   577 
       
   578         for(; i < count; i++ )
       
   579             {
       
   580             // All cases should be completed now
       
   581             if( iTestCases[i]->State() != CTCTestCase::ETestCaseCompleted )
       
   582                 {
       
   583                 // This is some unknown internal TestCombiner error
       
   584                 // Should not happen
       
   585                 __TRACE( KError, (_L("TestCase (%S) not completed"), 
       
   586                     &iTestCases[i]->TestId() ));
       
   587                 ret = KErrUnknown;
       
   588                 break;
       
   589                 }
       
   590 
       
   591             // Interpret execution result type from returned result
       
   592             TInt executionResult = TFullTestResult::ECaseExecuted; // Ok
       
   593             if( iTestCases[i]->iResult.iCaseExecutionResultType >= 
       
   594                 TFullTestResult::ECaseLeave )
       
   595                 {
       
   596                 // Some abnormal execution result type
       
   597                 executionResult = iTestCases[i]->iResult.iCaseExecutionResultType;
       
   598                 }
       
   599 
       
   600             // Check expected execution result type
       
   601             if( executionResult != iTestCases[i]->ExpectedResultCategory() ) 
       
   602                 {
       
   603                 // expected and returned result types differ
       
   604                 aResult.iResult = KErrGeneral;
       
   605                 aResult.iResultDes.Copy( _L("Test case completed with ") );
       
   606                 aResult.iResultDes.Append( 
       
   607                     TTCKeywords::ResultCategory( 
       
   608                     iTestCases[i]->iResult.iCaseExecutionResultType ));
       
   609                 aResult.iResultDes.Append( _L(" and expected was ") );
       
   610                 aResult.iResultDes.Append( 
       
   611                     TTCKeywords::ResultCategory( 
       
   612                     iTestCases[i]->ExpectedResultCategory() ));
       
   613                 AppendTestResultToResultDes(aResult.iResultDes, iTestCases[i]->iResult.iTestResult.iResultDes);
       
   614                 __TRACE( KPrint, ( _L( "%S"), &aResult.iResultDes ) );
       
   615                 break;
       
   616                 }
       
   617 
       
   618             // Check normal test result
       
   619             if( iTestCases[i]->ExpectedResultCategory() == 
       
   620                 TFullTestResult:: ECaseExecuted )
       
   621                 {
       
   622                 // Normal completion, check result
       
   623                 if( iTestCases[i]->iResult.iTestResult.iResult != 
       
   624                       iTestCases[i]->ExpectedResult() )
       
   625                     {
       
   626                      __TRACE( KPrint, ( _L( "Test failed, expect(%d) != result(%d)"), 
       
   627                          iTestCases[i]->ExpectedResult(),
       
   628                          iTestCases[i]->iResult.iTestResult.iResult ));
       
   629                     // We return the first error result as aResult
       
   630                     if( iTestCases[i]->iResult.iTestResult.iResult != KErrNone )
       
   631                         {
       
   632                         aResult = iTestCases[i]->iResult.iTestResult;
       
   633                         }
       
   634                     else
       
   635                         {
       
   636                         aResult.iResult = KErrGeneral;
       
   637                         aResult.iResultDes.Copy( _L("Test case completed with KErrNone and expected "));
       
   638                         aResult.iResultDes.AppendNum( iTestCases[i]->ExpectedResult() );
       
   639                         AppendTestResultToResultDes(aResult.iResultDes, iTestCases[i]->iResult.iTestResult.iResultDes);
       
   640                         }
       
   641                     break;
       
   642                     }
       
   643                 }
       
   644             else 
       
   645                 {
       
   646                 // Abnormal completion, i.e. panic, leave, exception or timeout
       
   647                 if( iTestCases[i]->iResult.iCaseExecutionResultCode != 
       
   648                       iTestCases[i]->ExpectedResult() )
       
   649                     {
       
   650                     __TRACE( KPrint, ( _L( "Test failed, expect errorcode(%d) != result(%d)"), 
       
   651                          iTestCases[i]->ExpectedResult(),
       
   652                          iTestCases[i]->iResult.iCaseExecutionResultCode ) );
       
   653                     // We return the first error result as aResult
       
   654                     aResult = iTestCases[i]->iResult.iTestResult;
       
   655                     // override result with real error code
       
   656                     aResult.iResult = iTestCases[i]->iResult.iCaseExecutionResultCode;
       
   657                     break;
       
   658                     }
       
   659                 }
       
   660             }
       
   661         if( i == count )
       
   662             {
       
   663             TestModuleIf().Printf( KPrintPriHigh, _L("Result"), _L("PASSED"));
       
   664             __TRACE( KPrint, (_L("***Test case result: PASSED***")));
       
   665             aResult.iResult = KErrNone;
       
   666             aResult.iResultDes.Copy( _L("Test case succeeded") );
       
   667             }
       
   668         else
       
   669             {
       
   670             TestModuleIf().Printf( KPrintPriHigh, _L("Result"), _L("FAILED"));        
       
   671             __TRACE( KPrint, (_L("***Test case result: FAILED***")));
       
   672             }
       
   673         }
       
   674 
       
   675     // Release all pending event requests
       
   676     TEventIf event( TEventIf::ERelEvent );
       
   677     TInt eventCount = iEventArray.Count();
       
   678     for( TInt ind=0; ind < eventCount; ind++ )
       
   679         {
       
   680         event.SetName( iEventArray[ind]->Name() );
       
   681         TestModuleIf().Event( event );
       
   682         }
       
   683 
       
   684     iLoopAllocationArray.Reset();
       
   685     iLoopAllocationArray.Close();
       
   686     iLoopIsUsed = EFalse;
       
   687 
       
   688     // Delete all completed and checked testcases
       
   689     // Do not change the deletion order of events and test cases!!!
       
   690     iEventArray.ResetAndDestroy();
       
   691     iTestCases.ResetAndDestroy();
       
   692     iTestModules.ResetAndDestroy();
       
   693     iSlaveArray.ResetAndDestroy();
       
   694 
       
   695     iSendReceive.ResetAndDestroy();
       
   696 
       
   697     // Stop all remaining measurement modules
       
   698     const TInt count_meas = iTestMeasurementArray.Count();
       
   699     for( TInt b = 0; b < count_meas; b++ )
       
   700         {
       
   701         iTestMeasurementArray[b]->iMeasurement->Stop();
       
   702         }
       
   703     iTestMeasurementArray.ResetAndDestroy();
       
   704     iTestMeasurementArray.Close();
       
   705 
       
   706     __UHEAP_MARKEND;
       
   707 
       
   708     //If log was replaced then restore it
       
   709     if(iAddTestCaseTitleToLogName)
       
   710         {
       
   711         iLog = iStdLog;
       
   712         delete iTCLog;
       
   713         iTCLog = NULL;
       
   714         }
       
   715 
       
   716     return ret;
       
   717 
       
   718     }
       
   719 
       
   720 /*
       
   721 -------------------------------------------------------------------------------
       
   722 
       
   723      Class: CTestCombiner
       
   724 
       
   725      Method: GetTestCaseL
       
   726 
       
   727      Description: Get specified test case section from configfile.
       
   728 
       
   729      Parameters:    const TInt aCaseNumber: in: Test case number
       
   730                     const TFileName& aConfig: in: Configfile name 
       
   731 
       
   732      Return Values: CSectionParser*: pointer to test case section
       
   733 
       
   734      Errors/Exceptions: Leaves if CStifParser::NewL leaves
       
   735                         Leaves if CStifParser::SectionL leaves
       
   736                         Leaves if memory allocation fails
       
   737 
       
   738      Status: Approved
       
   739 
       
   740 -------------------------------------------------------------------------------
       
   741 */
       
   742 CStifSectionParser* CTestCombiner::GetTestCaseL( const TInt aCaseNumber, 
       
   743                                              const TFileName& aConfig )
       
   744     {
       
   745     __TRACEFUNC();
       
   746     CStifParser* parser = 
       
   747         CStifParser::NewL( _L(""), aConfig, CStifParser::ECStyleComments );
       
   748     CleanupStack::PushL( parser );
       
   749 
       
   750     CStifSectionParser* section = 
       
   751         parser->SectionL( KTestStartTag, KTestEndTag, aCaseNumber );
       
   752 
       
   753     CleanupStack::PopAndDestroy( parser );
       
   754     return section;
       
   755     }
       
   756 
       
   757 /*
       
   758 -------------------------------------------------------------------------------
       
   759 
       
   760      Class: CTestCombiner
       
   761 
       
   762      Method: ReadInitializationL
       
   763 
       
   764      Description: Read initialization from file.
       
   765 
       
   766      Parameters:    const TDesC& aIniFile: in: File that contains initialization
       
   767 
       
   768      Return Values: None
       
   769 
       
   770      Errors/Exceptions: None
       
   771 
       
   772      Status: Draft
       
   773 
       
   774 -------------------------------------------------------------------------------
       
   775 */
       
   776 void CTestCombiner::ReadInitializationL( const TDesC& aIniFile )
       
   777     {
       
   778     CStifParser* parser = NULL; 
       
   779 
       
   780     // Open file
       
   781     TRAPD( err, parser = 
       
   782         CStifParser::NewL( _L(""), aIniFile, CStifParser::ECStyleComments ) );
       
   783     if( ( err == KErrNone ) && parser )
       
   784         {
       
   785         CleanupStack::PushL( parser );
       
   786         __TRACE( KMessage, (_L("Read initialization from [%S]"),
       
   787             &aIniFile ) );
       
   788         
       
   789         // Read initialization parameters 
       
   790         CStifSectionParser* section = parser->SectionL( KInitStartTag,
       
   791                                                         KInitEndTag );
       
   792         if( section  )
       
   793             {
       
   794             CleanupStack::PushL( section );
       
   795             __TRACE( KMessage, (_L("Read initializations")) );
       
   796 
       
   797             // Read RCP timeout            
       
   798             CStifItemParser* item = section->GetItemLineL( KInitRcpTimeout );
       
   799             if( item != NULL )
       
   800                 {
       
   801                 __TRACE( KMessage, (_L("Got RCP timeout definition")) );
       
   802                 CleanupStack::PushL( item );
       
   803                 
       
   804                 TInt value;
       
   805                 if( item->GetInt( KInitRcpTimeout, value ) 
       
   806                         != KErrNone )
       
   807                     {
       
   808                     __TRACE( KError, (_L("No RCP timeout value given")) );
       
   809                     User::Leave( KErrGeneral );                    
       
   810                     } 
       
   811                 // Change from seconds to milliseconds
       
   812                 iRemoteTimeout = value*1000*1000;
       
   813                 CleanupStack::PopAndDestroy( item );
       
   814                 }
       
   815 
       
   816             CleanupStack::PopAndDestroy( section );
       
   817             }
       
   818            
       
   819         // Read defines
       
   820         section = parser->SectionL( KDefineStartTag, KDefineEndTag );
       
   821         while(section)
       
   822             {
       
   823             CleanupStack::PushL( section );
       
   824             __TRACE( KMessage, (_L("Read defines")) );
       
   825 
       
   826             TPtrC name;
       
   827             TPtrC value;
       
   828             CStifItemParser* item = section->GetItemLineL( _L("") );
       
   829             while( item )
       
   830                 {
       
   831                 CleanupStack::PushL( item );
       
   832                 
       
   833                 if( item->GetString( _L(""), name ) != KErrNone )
       
   834                     {
       
   835                     __TRACE( KError, (_L("No define name given")) );
       
   836                     User::Leave( KErrGeneral );
       
   837                     } 
       
   838                 if( item->Remainder( value ) != KErrNone )
       
   839                     {
       
   840                     __TRACE( KError, (_L("No define value given")) );
       
   841                     User::Leave( KErrGeneral );
       
   842                     } 
       
   843                 TInt count = iDefined.Count();
       
   844                 TInt i = 0;
       
   845                 for( ; i < count; i++ )
       
   846                     {
       
   847                     if( iDefined[i]->Name() == name )
       
   848                         {
       
   849                         __TRACE( KMessage, (_L("Update define %S:%S"), &name, &value ) );
       
   850                         // Update existing
       
   851                         iDefined[i]->SetValueL( value );
       
   852                         break;
       
   853                         }
       
   854                     }
       
   855                 if( i == count) 
       
   856                     {
       
   857                     // New define, store it
       
   858                     CDefinedValue* define = CDefinedValue::NewL( name, value );
       
   859                     CleanupStack::PushL( define );
       
   860                     User::LeaveIfError( iDefined.Append( define ) );
       
   861                     CleanupStack::Pop( define );
       
   862                     }
       
   863 
       
   864                 CleanupStack::PopAndDestroy( item );
       
   865                 item = section->GetNextItemLineL();
       
   866                 }
       
   867             CleanupStack::PopAndDestroy( section );
       
   868             section = parser->NextSectionL(KDefineStartTag, KDefineEndTag);
       
   869             }
       
   870         CleanupStack::PopAndDestroy( parser );
       
   871         }
       
   872     }
       
   873 
       
   874 /*
       
   875 -------------------------------------------------------------------------------
       
   876 
       
   877      Class: CTestCombiner
       
   878 
       
   879      Method: RunTestL
       
   880 
       
   881      Description: Run a testcase specified by iSectionParser.
       
   882 
       
   883      Parameters:    None
       
   884      
       
   885      Return Values: None.
       
   886 
       
   887      Errors/Exceptions: Leaves if CSectionParser::GetItemLineL leaves
       
   888                         Leaves if CTestRunner::NewL leaves
       
   889                         Leaves if memory allocation fails                                
       
   890 
       
   891      Status: Approved
       
   892     
       
   893 -------------------------------------------------------------------------------
       
   894 */
       
   895 void CTestCombiner::RunTestL()
       
   896     {
       
   897     __TRACEFUNC();
       
   898     iResult = KErrNone;
       
   899 
       
   900     TPtrC line;
       
   901     // "title" keyword must be in the first line
       
   902     User::LeaveIfError( iSectionParser->GetLine( KTitle, line, ENoTag ) );
       
   903      
       
   904     iTestRunner = CTestRunner::NewL( this ); 
       
   905     iRemoteReceiver = CRemoteReceiver::NewL( this );
       
   906     iRemoteReceiver->Start();
       
   907 
       
   908     __TRACE( KMessage, (_L("Run: %S"), &line));
       
   909     
       
   910     TestModuleIf().Printf( KPrintPriNorm, _L("Run"), _L("%S"), &line);
       
   911     // Rest of the job is done by test runner
       
   912     iTestRunner->SetRunnerActive();
       
   913 
       
   914     // Start activeScheduler looping testcase lines
       
   915     iSchedulerActive = ETrue;
       
   916     __TRACE( KMessage, (_L("Start CActiveScheduler")));
       
   917     CActiveScheduler::Current()->Start();
       
   918 
       
   919     TestModuleIf().Printf( KPrintPriNorm, _L("Executed"), _L("%S"), &line);
       
   920     __TRACE( KMessage, (_L("Executed: %S"), &line));
       
   921         
       
   922     delete iRemoteReceiver;
       
   923     iRemoteReceiver = NULL;
       
   924     delete iTestRunner;
       
   925     iTestRunner = NULL;
       
   926 
       
   927     }     
       
   928 
       
   929 /*
       
   930 -------------------------------------------------------------------------------
       
   931 
       
   932      Class: CTestCombiner
       
   933 
       
   934      Method: GetTestModuleL
       
   935 
       
   936      Description: Load testmodule if not already loaded, otherwise return
       
   937                   description of the loaded testmodule.
       
   938 
       
   939      Parameters:    TDesC& aModule: in: Module name.
       
   940                     TDesC& aIniFile: in: Ini file name.
       
   941                     const TDesC& aConfigFile: in: Test case(config) file name.
       
   942      
       
   943      Return Values: CTCTestModule*: pointer to testmodules description
       
   944      
       
   945      Errors/Exceptions: Leaves if CTCTestModule::NewL leaves
       
   946                         Leaves if RPointerArray::Append fails  
       
   947 
       
   948      Status: Proposal
       
   949     
       
   950 -------------------------------------------------------------------------------
       
   951 */
       
   952 CTCTestModule* CTestCombiner::GetTestModuleL( TDesC& aModule,
       
   953                                               TDesC& aIniFile,
       
   954                                               const TDesC& aConfigFile )
       
   955     {
       
   956     __TRACEFUNC();
       
   957     TInt count = iTestModules.Count();
       
   958     TInt i, j;
       
   959     TInt counttc;
       
   960     TInt running;
       
   961     TBool newWay = EFalse;
       
   962     
       
   963     __TRACE(KMessage, (_L("Find test module for [%S]"), &aModule));
       
   964 
       
   965     //Name for new module controller
       
   966     TName newModuleName = aModule;
       
   967 
       
   968     //Check if it is python case or UITestingSupport or SeparateProcesses mode
       
   969     newWay = (aModule.Find(KPythonScripter) == 0)
       
   970              || (iUITestingSupport && aModule.Find(KTestScripterName) == 0)
       
   971              || (iSeparateProcesses); 
       
   972 
       
   973     if(newWay)
       
   974         {
       
   975         __TRACE(KMessage, (_L("TCTestModule operating mode: exclusive")));
       
   976 
       
   977         //Find module of given name
       
   978         __TRACE(KMessage, (_L("Looking for module [%S]"), &aModule));
       
   979         if(iUITestingSupport && aModule.Find(KTestScripterName) == 0)
       
   980             {
       
   981             __TRACE(KMessage, (_L("UITestingSupport option is on. New module controller will be created always")));
       
   982             }
       
   983         else
       
   984             {
       
   985             for(i = 0; i < count; i++)
       
   986                 {
       
   987                 TPtrC modName = iTestModules[i]->ModuleName();
       
   988                 if(modName.Find(aModule) == 0)
       
   989                     {
       
   990                     //Check if there is running test case
       
   991                     counttc = iTestCases.Count();
       
   992                     running = 0;
       
   993                     for(j = 0; j < counttc; j++)
       
   994                         {
       
   995                         if(iTestCases[j]->TestModule() == iTestModules[i] && iTestCases[j]->State() != CTestCase::ETestCaseCompleted)
       
   996                             {
       
   997                             //We have found at least one running test case. There is no reason to find any more,
       
   998                             //because there shouldn't be because test module may run only one python scripter test case.
       
   999                             running++;
       
  1000                             __TRACE(KMessage, (_L("Module controller found [%S], but it has running test cases"), &modName));
       
  1001                             break;
       
  1002                             }
       
  1003                         }
       
  1004                     if(running == 0)
       
  1005                         {
       
  1006                         __TRACE(KMessage, (_L("Free module controller has been found [%S]"), &modName));
       
  1007                         return iTestModules[i];
       
  1008                         }
       
  1009                     }
       
  1010                 }
       
  1011             }
       
  1012         //Update name of new module to be created
       
  1013         newModuleName.AppendFormat(_L("@%d_"), GetIndexForNewTestModuleController());
       
  1014         newModuleName.LowerCase();
       
  1015         }
       
  1016     else
       
  1017         {
       
  1018         __TRACE(KMessage, (_L("TCTestModule operating mode: normal")));
       
  1019         for(i = 0; i < count; i++)
       
  1020             {
       
  1021             if(iTestModules[i]->ModuleName() == aModule)
       
  1022                 {
       
  1023                 // Found test module, return description
       
  1024                 __TRACE(KMessage, (_L("Module controller [%S] found"), &aModule));
       
  1025                 return iTestModules[i];
       
  1026                 }
       
  1027             }
       
  1028         }
       
  1029 
       
  1030     __TRACE(KMessage, (_L("Creating new test module controller [%S] with ini [%S]"), &newModuleName, &aIniFile));
       
  1031     CTCTestModule* module = CTCTestModule::NewL(this, newModuleName, aIniFile, aConfigFile);
       
  1032     CleanupStack::PushL(module);
       
  1033 
       
  1034     //Enumerate test cases
       
  1035     module->GetTestCasesForCombiner(aConfigFile);
       
  1036 
       
  1037     //Append new module to list
       
  1038     User::LeaveIfError(iTestModules.Append(module));
       
  1039     CleanupStack::Pop(module);
       
  1040 
       
  1041     //Log some info
       
  1042     if(newWay)
       
  1043         {    
       
  1044         __TRACE(KMessage, (_L("Module [%S] added to list. Currently there are following controllers of [%S] type:"), &newModuleName, &aModule));
       
  1045         j = 1;
       
  1046         for(i = 0; i < iTestModules.Count(); i++)
       
  1047             {
       
  1048             if(iTestModules[i]->ModuleName().Find(aModule) == 0)
       
  1049                 {
       
  1050                 __TRACE(KMessage, (_L("    %d. [%S]"), j, &iTestModules[i]->ModuleName()));
       
  1051                 j++;
       
  1052                 }
       
  1053             }
       
  1054         }
       
  1055 
       
  1056     if( iLoopIsUsed )
       
  1057         {
       
  1058         User::LeaveIfError( iLoopAllocationArray.Append( module ) );
       
  1059         }
       
  1060 
       
  1061     return module;
       
  1062     }
       
  1063 
       
  1064 /*
       
  1065 -------------------------------------------------------------------------------
       
  1066 
       
  1067      Class: CTestCombiner
       
  1068 
       
  1069      Method: GetTest
       
  1070 
       
  1071      Description: Get test case from testcase array.
       
  1072 
       
  1073      Parameters:    TDesC& aTestId: in: TestId for testcase
       
  1074      
       
  1075      Return Values: CTCTestCase*: running/runned testcase
       
  1076                     NULL: Testcase with aTestId not running/runned
       
  1077 
       
  1078      Errors/Exceptions: None
       
  1079 
       
  1080      Status: Approved
       
  1081     
       
  1082 -------------------------------------------------------------------------------
       
  1083 */
       
  1084 CTestCase* CTestCombiner::GetTest( TDesC& aTestId )
       
  1085     {
       
  1086     __TRACEFUNC();
       
  1087     // TestId is not mandatory, so length may be zero
       
  1088     if( aTestId.Length() == 0 )
       
  1089         {
       
  1090         return NULL;
       
  1091         }
       
  1092 
       
  1093     TInt count = iTestCases.Count();
       
  1094     for( TInt i=0; i < count; i++ )
       
  1095         {
       
  1096         if( iTestCases[i]->TestId() == aTestId )
       
  1097             {
       
  1098             // Found testcase with specified TestId
       
  1099             return iTestCases[i];
       
  1100             }
       
  1101         }
       
  1102     // Test case with aTestId not found
       
  1103     return NULL;
       
  1104     
       
  1105     }
       
  1106     
       
  1107 /*
       
  1108 -------------------------------------------------------------------------------
       
  1109 
       
  1110      Class: CTestCombiner
       
  1111 
       
  1112      Method: GetRunningTest
       
  1113 
       
  1114      Description: Get running test case.
       
  1115 
       
  1116      Parameters: TDesC& aTestId: in: TestId for testcase
       
  1117      
       
  1118      Return Values: CTCTestCase*: running testcase
       
  1119                     NULL: Testcase with aTestId not running 
       
  1120 
       
  1121      Errors/Exceptions: None
       
  1122 
       
  1123      Status: Approved
       
  1124 
       
  1125 -------------------------------------------------------------------------------
       
  1126 */
       
  1127 CTestCase* CTestCombiner::GetRunningTest( TDesC& aTestId )
       
  1128     {
       
  1129     __TRACEFUNC();
       
  1130      
       
  1131     CTestCase* test = GetTest( aTestId );
       
  1132     if( test ) 
       
  1133         {
       
  1134         if( test->State() == CTestCase::ETestCaseRunning )
       
  1135             {
       
  1136             return test;
       
  1137             }
       
  1138         else
       
  1139             {
       
  1140              __TRACE( KMessage, (_L("GetTest: Searched task (%S) not running (%i)"), 
       
  1141                 &aTestId, test->State() ));
       
  1142             }
       
  1143         }
       
  1144 
       
  1145     return NULL;
       
  1146     
       
  1147     }
       
  1148     
       
  1149 /*
       
  1150 -------------------------------------------------------------------------------
       
  1151 
       
  1152      Class: CTestCombiner
       
  1153 
       
  1154      Method: GetLocalTest
       
  1155 
       
  1156      Description: Get local test case from testcase array.
       
  1157 
       
  1158      Parameters:    TDesC& aTestId: in: TestId for testcase
       
  1159      
       
  1160      Return Values: CTCTestCase*: running/runned testcase
       
  1161                     NULL: Testcase with aTestId not running/runned 
       
  1162 
       
  1163      Errors/Exceptions: None
       
  1164 
       
  1165      Status: Proposal
       
  1166     
       
  1167 -------------------------------------------------------------------------------
       
  1168 */
       
  1169 CTCTestCase* CTestCombiner::GetLocalTest( TDesC& aTestId )
       
  1170     {
       
  1171     __TRACEFUNC();
       
  1172     CTestCase* testCase = GetTest( aTestId );
       
  1173     if( testCase )
       
  1174         {    
       
  1175         if( testCase->Type() != CTestCase::ECaseLocal )
       
  1176             {
       
  1177             __TRACE( KMessage, (_L("GetLocalTest: Searched task (%S) not local"), 
       
  1178                       &aTestId ));
       
  1179             return NULL;
       
  1180             }
       
  1181         }
       
  1182     return ( CTCTestCase* ) testCase;
       
  1183     
       
  1184     }
       
  1185     
       
  1186 /*
       
  1187 -------------------------------------------------------------------------------
       
  1188 
       
  1189      Class: CTestCombiner
       
  1190 
       
  1191      Method: GetLocalRunningTest
       
  1192 
       
  1193      Description:  Get local running test case.
       
  1194 
       
  1195      Parameters:    TDesC& aTestId: in: TestId for testcase
       
  1196      
       
  1197      Return Values: CTCTestCase*: running/runned testcase
       
  1198                     NULL: Testcase with aTestId not running/runned 
       
  1199 
       
  1200      Errors/Exceptions: None
       
  1201 
       
  1202      Status: Proposal
       
  1203     
       
  1204 -------------------------------------------------------------------------------
       
  1205 */
       
  1206 CTCTestCase* CTestCombiner::GetLocalRunningTest( TDesC& aTestId )
       
  1207     {
       
  1208     __TRACEFUNC();
       
  1209     CTestCase* testCase = GetRunningTest( aTestId );
       
  1210     if( testCase )
       
  1211         {    
       
  1212         if( testCase->Type() != CTestCase::ECaseLocal )
       
  1213             {
       
  1214             __TRACE( KMessage, (_L("GetLocalRunningTest: Searched task (%S) not local"), 
       
  1215                       &aTestId ));
       
  1216             return NULL;
       
  1217             }
       
  1218         }
       
  1219         
       
  1220     return ( CTCTestCase* ) testCase;
       
  1221     
       
  1222     }
       
  1223     
       
  1224 /*
       
  1225 -------------------------------------------------------------------------------
       
  1226 
       
  1227      Class: CTestCombiner
       
  1228 
       
  1229      Method: GetRemoteTest
       
  1230 
       
  1231      Description: Get local test case from testcase array.
       
  1232 
       
  1233      Parameters:    TDesC& aTestId: in: TestId for testcase
       
  1234      
       
  1235      Return Values: CTCTestCase*: running/runned testcase
       
  1236                     NULL: Testcase with aTestId not running/runned 
       
  1237 
       
  1238      Errors/Exceptions: None
       
  1239 
       
  1240      Status: Proposal
       
  1241     
       
  1242 -------------------------------------------------------------------------------
       
  1243 */
       
  1244 CRemoteTestCase* CTestCombiner::GetRemoteTest( TDesC& aTestId )
       
  1245     {
       
  1246     __TRACEFUNC();
       
  1247     CTestCase* testCase = GetTest( aTestId );
       
  1248     if( testCase )
       
  1249         {    
       
  1250         if( testCase->Type() != CTestCase::ECaseRemote )
       
  1251             {
       
  1252             __TRACE( KMessage, (_L("GetRemoteTest: Searched task (%S) not remote"), 
       
  1253                       &aTestId ));
       
  1254             return NULL;
       
  1255             }
       
  1256         }
       
  1257         
       
  1258     return ( CRemoteTestCase* ) testCase;
       
  1259     
       
  1260     }
       
  1261         
       
  1262 /*
       
  1263 -------------------------------------------------------------------------------
       
  1264 
       
  1265      Class: CTestCombiner
       
  1266 
       
  1267      Method: GetRemoteTest
       
  1268 
       
  1269      Description: Get remote test case from slave array.
       
  1270 
       
  1271      Parameters:    TUint32 aSlaveId: in: Slave id for testcase
       
  1272      
       
  1273      Return Values: TCaseInfo*: running/runned testcase
       
  1274                     NULL: Testcase with aTestId not running/runned 
       
  1275 
       
  1276      Errors/Exceptions: None
       
  1277 
       
  1278      Status: Proposal
       
  1279     
       
  1280 -------------------------------------------------------------------------------
       
  1281 */
       
  1282 CRemoteTestCase* CTestCombiner::GetRemoteTest( TUint32 aSlaveId )
       
  1283     {
       
  1284     
       
  1285     __TRACEFUNC();
       
  1286     
       
  1287     // Check all remote testcases
       
  1288     TInt caseCount = iTestCases.Count(); 
       
  1289     CRemoteTestCase* testCase = NULL;
       
  1290     for( TInt caseInd = 0; caseInd < caseCount; caseInd++ )
       
  1291         {
       
  1292         if( iTestCases[caseInd]->Type() == CTestCase::ECaseRemote )
       
  1293             {
       
  1294             testCase = ( CRemoteTestCase* )iTestCases[caseInd];
       
  1295             if( testCase->iSlaveId == aSlaveId )
       
  1296                 {
       
  1297                 return testCase;
       
  1298                 }
       
  1299             }
       
  1300         }
       
  1301     
       
  1302     return NULL;
       
  1303         
       
  1304     }   
       
  1305 
       
  1306 /*
       
  1307 -------------------------------------------------------------------------------
       
  1308 
       
  1309      Class: CTestCombiner
       
  1310 
       
  1311      Method: GetRemoteTestRunSent
       
  1312 
       
  1313      Description: Get remote test case from slave array
       
  1314 
       
  1315      Parameters:    TUint32 aSlaveId: in: Slave id for testcase
       
  1316 
       
  1317      Return Values: TCaseInfo*: running/runned testcase
       
  1318                     NULL: Testcase with aTestId not running/runned 
       
  1319 
       
  1320      Errors/Exceptions: None
       
  1321 
       
  1322      Status: Draft @js
       
  1323     
       
  1324 -------------------------------------------------------------------------------
       
  1325 */
       
  1326     
       
  1327 CRemoteTestCase* CTestCombiner::GetRemoteTestRunSent( TUint32 aSlaveId )
       
  1328     {
       
  1329     
       
  1330     __TRACEFUNC();
       
  1331     
       
  1332     // Check all remote testcases
       
  1333     TInt caseCount = iTestCases.Count(); 
       
  1334     CRemoteTestCase* testCase = NULL;
       
  1335     for( TInt caseInd = 0; caseInd < caseCount; caseInd++ )
       
  1336         {
       
  1337         if( iTestCases[caseInd]->Type() == CTestCase::ECaseRemote )
       
  1338             {
       
  1339             testCase = ( CRemoteTestCase* )iTestCases[caseInd];
       
  1340             
       
  1341             if( testCase->iRemoteState != CRemoteTestCase::ECaseRunSent )
       
  1342                 {
       
  1343                 continue;
       
  1344                 }
       
  1345             if( testCase->iSlaveId == aSlaveId )
       
  1346                 {
       
  1347                 return testCase;
       
  1348                 }
       
  1349             }
       
  1350         }
       
  1351     
       
  1352     return NULL;
       
  1353         
       
  1354     }       
       
  1355   
       
  1356 /*
       
  1357 -------------------------------------------------------------------------------
       
  1358 
       
  1359      Class: CTestCombiner
       
  1360 
       
  1361      Method: GetRemoteTest
       
  1362 
       
  1363      Description: Get remote test case from slave array.
       
  1364 
       
  1365      Parameters:    TUint32 aSlaveId: in: Slave id for testcase
       
  1366      
       
  1367      Return Values: TCaseInfo*: running/runned testcase
       
  1368                     NULL: Testcase with aTestId not running/runned 
       
  1369 
       
  1370      Errors/Exceptions: None
       
  1371 
       
  1372      Status: Proposal
       
  1373     
       
  1374 -------------------------------------------------------------------------------
       
  1375 */
       
  1376 CRemoteTestCase* CTestCombiner::GetRunningRemoteTest( TUint32 aSlaveId )
       
  1377     {
       
  1378     
       
  1379     __TRACEFUNC();
       
  1380     
       
  1381     // Check all remote testcases
       
  1382     TInt caseCount = iTestCases.Count(); 
       
  1383     CRemoteTestCase* testCase = NULL;
       
  1384     for( TInt caseInd = 0; caseInd < caseCount; caseInd++ )
       
  1385         {
       
  1386         if( ( iTestCases[caseInd]->Type() == CTestCase::ECaseRemote ) &&
       
  1387             ( iTestCases[caseInd]->State() == CTestCase::ETestCaseRunning ) )
       
  1388             {
       
  1389             testCase = ( CRemoteTestCase* )iTestCases[caseInd];
       
  1390             
       
  1391             if( ( testCase->iRemoteState != CRemoteTestCase::ECaseRunSent ) &&
       
  1392                 ( testCase->iRemoteState != CRemoteTestCase::ECaseRunning ) && 
       
  1393                 ( testCase->iRemoteState != CRemoteTestCase::ECaseCancelled ))
       
  1394                 {
       
  1395                 //User::Leave( KErrGeneral ); 
       
  1396                 continue;                       
       
  1397                 }
       
  1398                 
       
  1399             if( testCase->iSlaveId == aSlaveId )
       
  1400                 {
       
  1401                 return testCase;
       
  1402                 }
       
  1403             }
       
  1404         }
       
  1405     
       
  1406     return NULL;
       
  1407         
       
  1408     }   
       
  1409 
       
  1410     
       
  1411 /*
       
  1412 -------------------------------------------------------------------------------
       
  1413 
       
  1414      Class: CTestCombiner
       
  1415 
       
  1416      Method: GetRemoteTestSlave
       
  1417 
       
  1418      Description: Get remote test case running on slave
       
  1419 
       
  1420      Parameters:    TUint32 aSlaveDevId: in: Slave id for testcase
       
  1421      
       
  1422      Return Values: CRemoteTestCase*: running/runned testcase
       
  1423                     NULL: Testcase with aTestId not running/runned 
       
  1424 
       
  1425      Errors/Exceptions: None
       
  1426 
       
  1427      Status: Proposal
       
  1428     
       
  1429 -------------------------------------------------------------------------------
       
  1430 */
       
  1431 CRemoteTestCase* CTestCombiner::GetRemoteRunningTestOnSlave( 
       
  1432                                                     TUint32 aSlaveDevId )
       
  1433     {
       
  1434     
       
  1435     __TRACEFUNC();
       
  1436     
       
  1437     // Check all remote testcases
       
  1438     TInt caseCount = iTestCases.Count(); 
       
  1439     CRemoteTestCase* testCase = NULL;
       
  1440     for( TInt caseInd = 0; caseInd < caseCount; caseInd++ )
       
  1441         {
       
  1442         if( ( iTestCases[caseInd]->Type() == CTestCase::ECaseRemote ) &&
       
  1443             ( iTestCases[caseInd]->State() == CTestCase::ETestCaseRunning ) )
       
  1444             {
       
  1445             testCase = ( CRemoteTestCase* )iTestCases[caseInd];
       
  1446             if( DEVID( testCase->iSlaveId ) == DEVID( aSlaveDevId ) )
       
  1447                 {
       
  1448                 return testCase;
       
  1449                 }
       
  1450             }
       
  1451         }
       
  1452     
       
  1453     return NULL;
       
  1454         
       
  1455     }   
       
  1456 
       
  1457 /*
       
  1458 -------------------------------------------------------------------------------
       
  1459 
       
  1460      Class: CTestCombiner
       
  1461 
       
  1462      Method: GetRemoteTestSlave
       
  1463 
       
  1464      Description: Gets a correct CRemoteSendReceive object on slave with
       
  1465                   aSlaveId.
       
  1466 
       
  1467      Parameters:    TUint32 aSlaveId: in: Slave id CRemoteSendReceive object
       
  1468      
       
  1469      Return Values: CRemoteSendReceive*: Current CRemoteSendReceive object.
       
  1470                     NULL: CRemoteSendReceive object do not exist or found.
       
  1471 
       
  1472      Errors/Exceptions: None
       
  1473 
       
  1474      Status: Proposal
       
  1475     
       
  1476 -------------------------------------------------------------------------------
       
  1477 */
       
  1478 CRemoteSendReceive* CTestCombiner::GetRemoteSendReceive( TUint32 aSlaveId )
       
  1479     {
       
  1480     __TRACEFUNC();
       
  1481     
       
  1482     for( TInt sr = 0; sr < iSendReceive.Count(); sr++ )
       
  1483         {
       
  1484         if( iSendReceive[sr]->iSlaveId == aSlaveId )
       
  1485             {
       
  1486             return iSendReceive[sr];
       
  1487             }
       
  1488         }
       
  1489 
       
  1490     return NULL;
       
  1491 
       
  1492     }
       
  1493 
       
  1494 /*
       
  1495 -------------------------------------------------------------------------------
       
  1496 
       
  1497      Class: CTestCombiner
       
  1498 
       
  1499      Method: GetSlave
       
  1500 
       
  1501      Description: Get remote slave.
       
  1502 
       
  1503      Parameters:    TUint32 aSlaveId: in: Slave id 
       
  1504      
       
  1505      Return Values: CSlaveInfo*: reserved slave
       
  1506                     NULL: slave with aSlaveId not reserved 
       
  1507 
       
  1508      Errors/Exceptions: None
       
  1509 
       
  1510      Status: Proposal
       
  1511     
       
  1512 -------------------------------------------------------------------------------
       
  1513 */
       
  1514 CSlaveInfo* CTestCombiner::GetSlave( TUint32 aSlaveId )
       
  1515     {
       
  1516     
       
  1517     __TRACEFUNC();
       
  1518     
       
  1519     TInt count = iSlaveArray.Count();
       
  1520     for( TInt index = 0; index < count; index++ )
       
  1521         {
       
  1522         if( DEVID( iSlaveArray[index]->iSlaveDevId ) == DEVID( aSlaveId) )
       
  1523             {
       
  1524             return iSlaveArray[index];
       
  1525             }
       
  1526         }
       
  1527     
       
  1528     return NULL;
       
  1529     
       
  1530     }
       
  1531 
       
  1532 /*
       
  1533 -------------------------------------------------------------------------------
       
  1534 
       
  1535      Class: CTestCombiner
       
  1536 
       
  1537      Method: GetSlave
       
  1538 
       
  1539      Description: Get remote slave.
       
  1540 
       
  1541      Parameters:    TDesC& aSlaveName: in: Slave name 
       
  1542      
       
  1543      Return Values: CSlaveInfo*: reserved slave
       
  1544                     NULL: slave with aSlaveId not reserved 
       
  1545 
       
  1546      Errors/Exceptions: None
       
  1547 
       
  1548      Status: Proposal
       
  1549     
       
  1550 -------------------------------------------------------------------------------
       
  1551 */
       
  1552 CSlaveInfo* CTestCombiner::GetSlave( TDesC& aSlaveName )
       
  1553     {
       
  1554     
       
  1555     __TRACEFUNC();
       
  1556 
       
  1557     TInt count = iSlaveArray.Count();
       
  1558     for( TInt index = 0; index < count; index++ )
       
  1559         {
       
  1560         if( iSlaveArray[index]->iName == aSlaveName )
       
  1561             {
       
  1562             return iSlaveArray[index];
       
  1563             }
       
  1564         }
       
  1565     
       
  1566     return NULL;
       
  1567     
       
  1568     }        
       
  1569 
       
  1570 /*
       
  1571 -------------------------------------------------------------------------------
       
  1572 
       
  1573      Class: CTestCombiner
       
  1574 
       
  1575      Method: StartTestL
       
  1576 
       
  1577      Description: Start specified test case from testmodule.
       
  1578 
       
  1579      Parameters:    CStartInfo& aStartInfo: in: Test case information
       
  1580      
       
  1581      Return Values: KErrNone: Testcase started
       
  1582                     KErrAlreadyExists: testcase with same aTestId is already 
       
  1583                                        running
       
  1584                     Any other SymbianOS errorcode
       
  1585 
       
  1586      Errors/Exceptions: Leaves if CTCTestCase::NewL leaves
       
  1587                         Leaves if arguments are illegal
       
  1588                         Leaves if GetTestModuleL leaves
       
  1589                         Leaves if CTestExecution::Open fails
       
  1590                         Leaves if CTCTestCase::StartL leaves
       
  1591                         Leaves if RPointerArray::Append fails
       
  1592 
       
  1593      Status: Proposal
       
  1594 
       
  1595 -------------------------------------------------------------------------------
       
  1596 */
       
  1597 TInt CTestCombiner::StartTestL(  CStartInfo& aStartInfo )
       
  1598     {
       
  1599     __TRACEFUNC();
       
  1600     // Check that TestId is unique.
       
  1601     if( GetTest( aStartInfo.iTestId ) != NULL )
       
  1602         {
       
  1603         // If loop testing is ongoing, allow already defined testid.
       
  1604         if( iLoopIsUsed )
       
  1605             {
       
  1606             __TRACE( KVerbose, ( _L("StartTestL: TestId (%S) already in use. Loop allows already defined TestId"), 
       
  1607              &aStartInfo.iTestId ));
       
  1608             }
       
  1609         else
       
  1610             {
       
  1611             __TRACE( KError, ( _L("StartTestL: TestId (%S) already in use"), 
       
  1612                  &aStartInfo.iTestId ));
       
  1613             return KErrAlreadyExists;
       
  1614             }
       
  1615         }
       
  1616 
       
  1617     __ASSERT_ALWAYS( aStartInfo.iModule.Length() < KMaxFileName, 
       
  1618         User::Leave( KErrArgument ) );
       
  1619     __ASSERT_ALWAYS( aStartInfo.iIniFile.Length() < KMaxFileName, 
       
  1620         User::Leave( KErrArgument ) );
       
  1621     __ASSERT_ALWAYS( aStartInfo.iConfig.Length() < KMaxFileName, 
       
  1622         User::Leave( KErrArgument ) );
       
  1623     __ASSERT_ALWAYS( aStartInfo.iTestId.Length() < KMaxName, 
       
  1624         User::Leave( KErrArgument ) );
       
  1625 
       
  1626     __TRACE( KMessage, ( _L("Call GetTestModuleL") ));
       
  1627 
       
  1628     // Load Test Module
       
  1629     CTCTestModule* module = NULL;
       
  1630     if( (aStartInfo.iModule.Find( KTestScripterName ) != KErrNotFound) 
       
  1631         || (aStartInfo.iModule.Find( KPythonScripter ) != KErrNotFound)
       
  1632         || (aStartInfo.iModule.Find( KTestCombinerName ) != KErrNotFound) 
       
  1633         )
       
  1634         {
       
  1635         // TestScripter in use. Give config file for parsing STIF Settings.
       
  1636         module = GetTestModuleL( aStartInfo.iModule,
       
  1637                                  aStartInfo.iIniFile,
       
  1638                                  aStartInfo.iConfig );
       
  1639         }
       
  1640     else
       
  1641         {
       
  1642         module = GetTestModuleL( aStartInfo.iModule,
       
  1643                                  aStartInfo.iIniFile,
       
  1644                                  KNullDesC );
       
  1645         }
       
  1646 
       
  1647     __TRACE( KMessage, ( _L("Create CTCTestCase") ));
       
  1648 
       
  1649     CTCTestCase* tc = 
       
  1650         CTCTestCase::NewL( this, 
       
  1651                            aStartInfo.iModule, 
       
  1652                            aStartInfo.iTestId, 
       
  1653                            aStartInfo.iExpectedResult, 
       
  1654                            aStartInfo.iCategory,
       
  1655                            module ); //--PYTHON--
       
  1656 
       
  1657     CleanupStack::PushL( tc );
       
  1658     
       
  1659     //If name of testcase was given, find testcase number
       
  1660     if(aStartInfo.iTitle != KNullDesC)
       
  1661         {
       
  1662         __TRACE(KMessage, (_L("Trying to find test case entitled \"%S\""), &aStartInfo.iTitle));
       
  1663         aStartInfo.iCaseNum = -1;
       
  1664         TInt ret = module->GetCaseNumByTitle(aStartInfo.iTitle, aStartInfo.iCaseNum);
       
  1665         if(ret != KErrNone)
       
  1666             {
       
  1667             __TRACE(KError, (_L("Couldn't find test case entitled \"%S\". Error %d"), &aStartInfo.iTitle, ret));
       
  1668             }
       
  1669         else
       
  1670             {
       
  1671             __TRACE(KMessage, (_L("Found test case entitled \"%S\". Case num %d"), &aStartInfo.iTitle, aStartInfo.iCaseNum));
       
  1672             }
       
  1673         }
       
  1674 
       
  1675     __TRACE( KMessage, ( _L("Open TestExecution") ));
       
  1676     
       
  1677     User::LeaveIfError( tc->TestExecution().Open( module->TestServer(), 
       
  1678                                                   aStartInfo.iCaseNum, 
       
  1679                                                   aStartInfo.iConfig ) );
       
  1680 
       
  1681     __TRACE( KMessage, ( _L("Start testcase runner") ));
       
  1682 
       
  1683       // Enable testcase control before calling RunTestCase
       
  1684     tc->StartL();
       
  1685 
       
  1686     __TRACE( KMessage, 
       
  1687         ( _L("Start: testid(%S), module(%S), ini(%S), config(%S), case(%d), expect(%d/%d), timeout(%d)"), 
       
  1688         &aStartInfo.iTestId, &aStartInfo.iModule, &aStartInfo.iIniFile, 
       
  1689         &aStartInfo.iConfig, aStartInfo.iCaseNum, aStartInfo.iExpectedResult, 
       
  1690         aStartInfo.iCategory, aStartInfo.iTimeout ));
       
  1691 
       
  1692     TestModuleIf().Printf( KPrintPriLow, _L("Start"),
       
  1693         _L("testid(%S), module(%S), ini(%S), config(%S), case(%d), expect(%d)"), 
       
  1694          &aStartInfo.iTestId, &aStartInfo.iModule, &aStartInfo.iIniFile, 
       
  1695          &aStartInfo.iConfig, aStartInfo.iCaseNum, aStartInfo.iExpectedResult );
       
  1696 
       
  1697     tc->TestExecution().RunTestCase( tc->iResultPckg, tc->iStatus );
       
  1698 
       
  1699     iRunningTests++;
       
  1700 
       
  1701     User::LeaveIfError( iTestCases.Append( tc ) );
       
  1702     if( iLoopIsUsed )
       
  1703         {
       
  1704         User::LeaveIfError( iLoopAllocationArray.Append( tc ) );
       
  1705         }
       
  1706     CleanupStack::Pop( tc );
       
  1707 
       
  1708     return KErrNone;
       
  1709 
       
  1710 }
       
  1711 
       
  1712 /*
       
  1713 -------------------------------------------------------------------------------
       
  1714 
       
  1715      Class: CTestCombiner
       
  1716 
       
  1717      Method: Complete
       
  1718 
       
  1719      Description: Handle completed test case.
       
  1720 
       
  1721      Parameters:    CTCTestCase* aTestCase: in: Test case to complete
       
  1722 
       
  1723      Return Values: None.
       
  1724 
       
  1725      Errors/Exceptions: None
       
  1726 
       
  1727      Status: Approved
       
  1728 
       
  1729 -------------------------------------------------------------------------------
       
  1730 */
       
  1731 void CTestCombiner::Complete( CTestCase* aTestCase, TInt aError )
       
  1732     {
       
  1733     __TRACEFUNC();
       
  1734     
       
  1735     if( aError != KErrNone )
       
  1736         {
       
  1737         iResult = aError;
       
  1738         }
       
  1739 
       
  1740     TInt count = iTestCases.Count();
       
  1741     TInt i = 0;
       
  1742     for(; i < count; i++ )
       
  1743         {
       
  1744         if( iTestCases[i] == aTestCase )
       
  1745             {
       
  1746             // Test Case completed
       
  1747             __TRACE( KPrint, (  _L( "Complete: %S result: %d, execution result: %d, expected: %d"), 
       
  1748                  &aTestCase->TestId(), aTestCase->iResult.iTestResult.iResult, 
       
  1749                  aTestCase->iResult.iCaseExecutionResultCode, aTestCase->ExpectedResult()  ));
       
  1750             TestModuleIf().Printf( KPrintPriLow, _L("Complete"),
       
  1751                 _L( "%S results: test(%d) exe(%d) expect(%d)"), 
       
  1752                  &aTestCase->TestId(), aTestCase->iResult.iTestResult.iResult,
       
  1753                  aTestCase->iResult.iCaseExecutionResultCode, aTestCase->ExpectedResult() );
       
  1754             iRunningTests--;
       
  1755             break;
       
  1756             }
       
  1757         }
       
  1758     if( i == count )
       
  1759         {
       
  1760         __TRACE( KError, (_L("CTestCombiner::Complete: Test case not found!!")));
       
  1761         }
       
  1762 
       
  1763     // Check if we were waiting this case to complete
       
  1764     if( ( iWaitTestCase.Length() > 0 ) && 
       
  1765         ( iWaitTestCase == aTestCase->TestId() ) )
       
  1766         {
       
  1767         // We were waiting this case to complete 
       
  1768         // Now we can proceed executing the testcase
       
  1769         __TRACE( KMessage, (_L("TestCase was waiting, set runner active")));
       
  1770         iTestRunner->SetRunnerActive();
       
  1771         iWaitTestCase.Zero();
       
  1772         
       
  1773      //return; - return removed due to STIF-509 CancelIfError won't work when used together with complete command
       
  1774      
       
  1775         }
       
  1776     else if( aTestCase->Type() == CTestCase::ECaseRemote )
       
  1777         {
       
  1778         __TRACE( KMessage, (_L("CTestCombiner::Complete: Remote case complete")));
       
  1779         // Completed testcase was remote case,
       
  1780         // check if slave should be freed
       
  1781         CRemoteTestCase* remote = ( CRemoteTestCase* )aTestCase;
       
  1782         if( remote->iFreeSlave )
       
  1783             {
       
  1784             CSlaveInfo* slave = GetSlave( remote->iSlaveId );
       
  1785             if( slave )
       
  1786                 {
       
  1787                 // Free slave now
       
  1788                 TRAPD( err, iTestRunner->ExecuteFreeL( slave ) );
       
  1789                 // Continue if freeing fails
       
  1790                 if( err == KErrNone )
       
  1791                     {
       
  1792                     __TRACE( KMessage, (_L("Complete: Freeing slave")));
       
  1793                     return;
       
  1794                     }
       
  1795                 else
       
  1796                     {
       
  1797                     __TRACE( KError, (_L("Complete: Freeing slave failed")));
       
  1798                     }
       
  1799                 }
       
  1800             else 
       
  1801                 {
       
  1802                 __TRACE( KError, (_L("Complete: Slave not found")));
       
  1803                 }
       
  1804             }
       
  1805         }
       
  1806 
       
  1807     // If running test is 0, active scheduler is active and CTestRunner is
       
  1808     // ready then stop active scheduler.(Operations continue from 
       
  1809     // CTestCombiner::RunTestL() after active scheduler start).
       
  1810     if( ( iRunningTests == 0 ) &&
       
  1811           iSchedulerActive &&
       
  1812         ( iTestRunner->iState == CTestRunner::ERunnerReady ) )
       
  1813         {
       
  1814         // This was last running testcase, so we can stop 
       
  1815         // activescheduler
       
  1816         __TRACE( KMessage, (_L("All TestCases completed, stop CActiveScheduler")));
       
  1817         CActiveScheduler::Current()->Stop();
       
  1818         iSchedulerActive = EFalse;
       
  1819         }
       
  1820     else 
       
  1821         {
       
  1822         __TRACE( KMessage, 
       
  1823             (_L("CTestCombiner::Complete: %d test cases running"), iRunningTests ));
       
  1824         __TRACE( KMessage, 
       
  1825             (_L("CTestCombiner::Complete: active %d"), iSchedulerActive ));
       
  1826         if(iSchedulerActive)    
       
  1827             {             
       
  1828             __TRACE( KMessage, 
       
  1829                 (_L("CTestCombiner::Complete: state %d"), iTestRunner->iState ));
       
  1830             }
       
  1831         }
       
  1832 
       
  1833     // Checking if user wants to skip the rest of the execution in case of error @js
       
  1834     if(iCancelIfError && iSchedulerActive)    
       
  1835         {
       
  1836         // Interpret execution result type from returned result
       
  1837         TInt executionResult = TFullTestResult::ECaseExecuted; // Ok
       
  1838         if( (aTestCase->iResult.iCaseExecutionResultType >= 
       
  1839             TFullTestResult::ECaseLeave ))
       
  1840             {
       
  1841             __TRACE( KMessage, (_L("The test case ended with error!")));
       
  1842 
       
  1843             // Some abnormal execution result type
       
  1844             executionResult = iTestCases[i]->iResult.iCaseExecutionResultType;
       
  1845             }
       
  1846 
       
  1847          // Check expected execution result type
       
  1848         if( executionResult != aTestCase->ExpectedResultCategory() ) 
       
  1849             {
       
  1850             // expected and returned result types differ
       
  1851             __TRACE( KMessage, (_L("The test case has wrong result category!")));
       
  1852             // There was an error and we must stop test case execution
       
  1853             iFailedTestCase = i;
       
  1854             iRunningTests--;
       
  1855             __TRACE( KMessage, (_L("Stopping the CActiveScheduler.")));
       
  1856             CActiveScheduler::Current()->Stop();
       
  1857             iSchedulerActive = EFalse;
       
  1858             }
       
  1859 
       
  1860         // Check normal test result if activescheduler is still up & running
       
  1861         if( iSchedulerActive )
       
  1862             {
       
  1863             if( aTestCase->ExpectedResultCategory() == 
       
  1864             TFullTestResult:: ECaseExecuted)
       
  1865                 {
       
  1866                 // Normal completion, check result
       
  1867                 if( iTestCases[i]->iResult.iTestResult.iResult != 
       
  1868                     iTestCases[i]->ExpectedResult() )
       
  1869                     { 
       
  1870                     __TRACE( KMessage, (_L("Result category is not what was expected!")));
       
  1871                     // There was an error and we must stop test case execution
       
  1872                     iFailedTestCase = i;
       
  1873                     iRunningTests = 0; //The whole test is stopped. Reset value of running tests.
       
  1874                     //This line caused that variable value to be -1. Test could not finish. //iRunningTests--;
       
  1875                     __TRACE( KMessage, (_L("Stopping the CActiveScheduler.")));
       
  1876                     CActiveScheduler::Current()->Stop();
       
  1877                     iSchedulerActive = EFalse;
       
  1878                     }
       
  1879                 }
       
  1880             else 
       
  1881                 {
       
  1882                 // Abnormal completion, i.e. panic, leave, exception or timeout
       
  1883                 if( aTestCase->iResult.iCaseExecutionResultCode != 
       
  1884                     aTestCase->ExpectedResult())
       
  1885                     {
       
  1886                     __TRACE( KMessage, (_L("The test case has abnormal completion!")));
       
  1887                     // There was an error and we must stop test case execution
       
  1888                     iFailedTestCase = i;
       
  1889                     iRunningTests--;
       
  1890                     __TRACE( KMessage, (_L("Stopping the CActiveScheduler.")));
       
  1891                     CActiveScheduler::Current()->Stop();
       
  1892                     iSchedulerActive = EFalse;
       
  1893                     }
       
  1894                 }
       
  1895             }
       
  1896         }
       
  1897     }
       
  1898 
       
  1899 /*
       
  1900 -------------------------------------------------------------------------------
       
  1901 
       
  1902      Class: CTestCombiner
       
  1903 
       
  1904      Method: NotifyEvent
       
  1905 
       
  1906      Description: Asynchronous event command interface
       
  1907      
       
  1908      Check requested events and send unset to first requested
       
  1909      
       
  1910      Parameters: TEventIf& aEvent: in: Event command 
       
  1911                 TRequestStatus& aStatus: in: TRequestStatus used in 
       
  1912                                                           asynchronous command 
       
  1913      
       
  1914      Return Values: ETrue: asynchronous command given
       
  1915                           EFalse: asyncronous command not given
       
  1916 
       
  1917      Errors/Exceptions: None
       
  1918      
       
  1919      Status: Proposal
       
  1920      
       
  1921 -------------------------------------------------------------------------------
       
  1922 */
       
  1923 TBool CTestCombiner::UnsetEvent( TEventIf& aEvent, 
       
  1924                                  TRequestStatus& aStatus )
       
  1925     {
       
  1926     
       
  1927     __TRACE( KMessage, ( _L("CTestCombiner::NotifyEvent")));    
       
  1928     
       
  1929     // First check TestCombiner events
       
  1930     TInt eventCount = iEventArray.Count();
       
  1931     for( TInt i = 0; i < eventCount; i++ )
       
  1932         {
       
  1933         if( aEvent.Name() == iEventArray[i]->Name() )
       
  1934             {
       
  1935             __TRACE( KMessage, (  
       
  1936                 _L( "Set unset pending for testcombiner's %S event"),  
       
  1937                     &aEvent.Name()  ));
       
  1938             iEventArray[i]->SetRequestStatus( &aStatus );
       
  1939             return ETrue;
       
  1940             }
       
  1941         }
       
  1942     
       
  1943     // Check all local testcases
       
  1944     TInt caseCount = iTestCases.Count(); 
       
  1945     TInt eventInd;
       
  1946     CTCTestCase* testCase = NULL;
       
  1947     for( TInt caseInd = 0; caseInd < caseCount; caseInd++ )
       
  1948         {
       
  1949         if( iTestCases[caseInd]->Type() == CTestCase::ECaseLocal )
       
  1950             {
       
  1951             testCase = ( CTCTestCase* )iTestCases[caseInd];
       
  1952             eventCount = testCase->EventArray().Count();
       
  1953              
       
  1954              // Check all requested events
       
  1955             for( eventInd = 0; eventInd < eventCount; eventInd++)
       
  1956                 {
       
  1957                 const TName& eventName = 
       
  1958                     testCase->EventArray()[eventInd]->Event().Name();
       
  1959                 if( eventName == aEvent.Name() )
       
  1960                     {
       
  1961                       // Event request is pending, send control command
       
  1962                     iEvent.Copy( aEvent );
       
  1963                     __TRACE( KMessage, (  
       
  1964                         _L( "Set unset pending for client's %S event"),  
       
  1965                         &aEvent.Name()  ));
       
  1966                     testCase->TestExecution().NotifyEvent( iEventPckg, 
       
  1967                                                              aStatus );
       
  1968                     return ETrue;
       
  1969                     }
       
  1970                 }
       
  1971             }
       
  1972         }
       
  1973      
       
  1974     return EFalse;
       
  1975      
       
  1976     }
       
  1977      
       
  1978 /*
       
  1979 -------------------------------------------------------------------------------
       
  1980 
       
  1981      Class: CTestCombiner
       
  1982 
       
  1983      Method: ReceiveResponse
       
  1984 
       
  1985      Description: Handles responce received from slave
       
  1986   
       
  1987      Parameters:    None
       
  1988      
       
  1989      Return Values: None
       
  1990 
       
  1991      Errors/Exceptions: None
       
  1992 
       
  1993      Status: Draft
       
  1994     
       
  1995 -------------------------------------------------------------------------------
       
  1996 */
       
  1997 void CTestCombiner::ReceiveResponse( TDesC& aMsg )
       
  1998     {
       
  1999     
       
  2000     __TRACEFUNC();
       
  2001     
       
  2002     TBool continueTask = ETrue;
       
  2003     TRAPD( err, continueTask = iTestRunner->ReceiveResponseL( aMsg ) );
       
  2004         
       
  2005     // We start receiver again, even in error situation
       
  2006     iRemoteReceiver->Start();
       
  2007 
       
  2008     if( err != KErrNone )
       
  2009         {
       
  2010         __TRACE( KError, ( _L("CTestCombiner::ReceiveResponse ERROR")));
       
  2011         iResult = err;
       
  2012         if( iTestRunner->IsActive() )
       
  2013             {
       
  2014             iTestRunner->Cancel();
       
  2015             }
       
  2016         else
       
  2017             {
       
  2018             iTestRunner->CancelTestCases();
       
  2019             }
       
  2020         return;
       
  2021         }
       
  2022         
       
  2023     if( continueTask && !iTestRunner->IsActive() )
       
  2024         {
       
  2025         iTestRunner->SetRunnerActive();
       
  2026         }
       
  2027     
       
  2028     }
       
  2029     
       
  2030 /*
       
  2031 -------------------------------------------------------------------------------
       
  2032 
       
  2033      Class: CTestCombiner
       
  2034 
       
  2035      Method: RemoteTimeout
       
  2036 
       
  2037      Description: Handles timeouts.
       
  2038   
       
  2039      Parameters:    None
       
  2040      
       
  2041      Return Values: None
       
  2042 
       
  2043      Errors/Exceptions: None
       
  2044 
       
  2045      Status: Draft
       
  2046     
       
  2047 -------------------------------------------------------------------------------
       
  2048 */
       
  2049 void CTestCombiner::RemoteTimeout()
       
  2050     {
       
  2051     
       
  2052     __TRACEFUNC();
       
  2053     
       
  2054     iResult = KErrTimedOut;
       
  2055     if( iTestRunner->IsActive() )
       
  2056         {
       
  2057         __TRACE( KError, (_L("Remote timeout, Cancel runner")));
       
  2058         iTestRunner->Cancel();
       
  2059         }
       
  2060     else
       
  2061         {
       
  2062         __TRACE( KError, (_L("Remote timeout, Cancel test cases")));
       
  2063         iTestRunner->CancelTestCases();
       
  2064         }
       
  2065     
       
  2066     }
       
  2067     
       
  2068 /*
       
  2069 -------------------------------------------------------------------------------
       
  2070 
       
  2071      Class: CTestCombiner
       
  2072 
       
  2073      Method: ExecuteMeasurementL
       
  2074 
       
  2075      Description: Executes measurement script line.
       
  2076   
       
  2077      Parameters: CStifItemParser* aItem: in: parsed line
       
  2078      
       
  2079      Return Values: TBool: in no error ETrue returned
       
  2080 
       
  2081      Errors/Exceptions: None
       
  2082 
       
  2083      Status: Approved
       
  2084     
       
  2085 -------------------------------------------------------------------------------
       
  2086 */
       
  2087 void CTestCombiner::ExecuteMeasurementL( CStifItemParser* aItem )
       
  2088     {
       
  2089     __TRACEFUNC();
       
  2090     
       
  2091      __TRACEFUNC();
       
  2092     TPtrC type;
       
  2093     TPtrC command;
       
  2094 
       
  2095     // Get command
       
  2096     if( aItem->GetNextString( command ) != KErrNone )
       
  2097         {
       
  2098         __TRACE( KError, ( 
       
  2099             _L( "Unknown argument for 'measurement' command" ) ) );
       
  2100         User::Leave( KErrArgument ); // Error in parsing => Leave
       
  2101         }
       
  2102     // Get name
       
  2103     if( aItem->GetNextString( type ) != KErrNone )
       
  2104         {
       
  2105         __TRACE( KError, ( 
       
  2106             _L( "Unknown argument for 'measurement' type" ) ) );
       
  2107         User::Leave( KErrArgument ); // Error in parsing => Leave
       
  2108         }
       
  2109 
       
  2110     // Verify measurement type
       
  2111     if( !( type == KParamMeasurement01 ||
       
  2112                 type == KParamMeasurement02 ||
       
  2113                 type == KParamMeasurement03 ||
       
  2114                 type == KParamMeasurement04 ||
       
  2115                 type == KParamMeasurement05 ||
       
  2116                 type == KParamMeasurementBappea ) )
       
  2117 
       
  2118         {
       
  2119         __TRACE( KError, ( 
       
  2120             _L( "Unknown measurement type:[%S]" ), &type ) );
       
  2121         User::Leave( KErrArgument ); // Error in types => Leave
       
  2122         }
       
  2123 
       
  2124     // Verify command
       
  2125    if( command == _L( "start" ) )
       
  2126         {
       
  2127         // START measurement's process
       
  2128         __TRACE( KMessage, ( _L( "Start 'measurement' with '%S'"), &type ) );
       
  2129         StartMeasurementL( type, aItem );
       
  2130         }
       
  2131     else if( command == _L( "stop" ) )
       
  2132         {
       
  2133         // STOP measurement's process
       
  2134         __TRACE( KMessage, ( _L( "'Stop 'measurement' with '%S'"), &type ) );
       
  2135         StopMeasurementL( type );
       
  2136         }
       
  2137     else
       
  2138         {
       
  2139         __TRACE( KError, ( 
       
  2140             _L( "Unknown command for 'measurement' command:[%S] or type:[%S]" ), &command, &type ) );
       
  2141         User::Leave( KErrArgument ); // Error in commands => Leave
       
  2142         }
       
  2143 
       
  2144     }
       
  2145 
       
  2146 /*
       
  2147 -------------------------------------------------------------------------------
       
  2148 
       
  2149      Class: CTestCombiner
       
  2150 
       
  2151      Method: StartMeasurementL
       
  2152 
       
  2153      Description: 
       
  2154   
       
  2155      Parameters: const TDesC& aType: in: Plugin type.
       
  2156                  CStifItemParser* aItem: in: Item object for parsing.
       
  2157 
       
  2158      Return Values: None.
       
  2159 
       
  2160      Errors/Exceptions: Leaves is bappea start or timed operation fails.
       
  2161 
       
  2162      Status: Proposal
       
  2163     
       
  2164 -------------------------------------------------------------------------------
       
  2165 */
       
  2166 void CTestCombiner::StartMeasurementL( const TDesC& aType,
       
  2167                                            CStifItemParser* aItem )
       
  2168     {
       
  2169     __TRACEFUNC();
       
  2170 
       
  2171     CSTIFTestMeasurement* testMeasurement = NULL;
       
  2172 
       
  2173     // Get Measurement configuration info
       
  2174     TPtrC configurationInfo( KNullDesC() );
       
  2175     if( aItem->Remainder( configurationInfo ) != KErrNone )
       
  2176         {
       
  2177         __TRACE( KInit, ( 
       
  2178             _L( "Using default path and file name for measurement configure" ) ) );
       
  2179         } 
       
  2180 
       
  2181     if( aType == KParamMeasurement01 )
       
  2182         {
       
  2183         testMeasurement = CSTIFTestMeasurement::NewL( 
       
  2184                     this, 
       
  2185                     CSTIFTestMeasurement::KStifMeasurementPlugin01,
       
  2186                     configurationInfo );
       
  2187         }
       
  2188     else if( aType == KParamMeasurement02 )
       
  2189         {
       
  2190         testMeasurement = CSTIFTestMeasurement::NewL( 
       
  2191                     this, 
       
  2192                     CSTIFTestMeasurement::KStifMeasurementPlugin02,
       
  2193                     configurationInfo );
       
  2194         }
       
  2195     else if( aType == KParamMeasurement03 )
       
  2196         {
       
  2197         testMeasurement = CSTIFTestMeasurement::NewL( 
       
  2198                     this, 
       
  2199                     CSTIFTestMeasurement::KStifMeasurementPlugin03,
       
  2200                     configurationInfo );
       
  2201         }
       
  2202     else if( aType == KParamMeasurement04 )
       
  2203         {
       
  2204         testMeasurement = CSTIFTestMeasurement::NewL( 
       
  2205                     this, 
       
  2206                     CSTIFTestMeasurement::KStifMeasurementPlugin04,
       
  2207                     configurationInfo );
       
  2208         }
       
  2209     else if( aType == KParamMeasurement05 )
       
  2210         {
       
  2211         testMeasurement = CSTIFTestMeasurement::NewL( 
       
  2212                     this, 
       
  2213                     CSTIFTestMeasurement::KStifMeasurementPlugin05,
       
  2214                     configurationInfo );
       
  2215         }
       
  2216     else if( aType == KParamMeasurementBappea )
       
  2217         {
       
  2218         testMeasurement = CSTIFTestMeasurement::NewL( 
       
  2219                     this, 
       
  2220                     CSTIFTestMeasurement::KStifMeasurementBappeaProfiler,
       
  2221                     configurationInfo );
       
  2222         }
       
  2223     else
       
  2224         {
       
  2225         __TRACE( KError, ( _L( "Unknown plugin[%S] for 'measurement'" ), &aType ) );
       
  2226         User::Leave( KErrArgument );
       
  2227         }
       
  2228 
       
  2229    // Start test measurement
       
  2230     TInt start_ret( KErrNone );
       
  2231     start_ret = testMeasurement->Start();
       
  2232     if( start_ret != KErrNone )
       
  2233         {
       
  2234         delete testMeasurement;
       
  2235         __TRACE( KError, ( 
       
  2236             _L( "CTestCombiner::StartMeasurementL(): Measurement Start() fails:[%d]" ), start_ret ) );
       
  2237         User::Leave( start_ret );
       
  2238         }
       
  2239 
       
  2240     TTestMeasurement* object = new (ELeave) TTestMeasurement();
       
  2241     object->iName = aType;
       
  2242     object->iMeasurement = testMeasurement;
       
  2243 
       
  2244     // Array for handling test measurement between different objects
       
  2245     TInt ret = iTestMeasurementArray.Append( object );
       
  2246     if( ret != KErrNone )
       
  2247         {
       
  2248         delete object;
       
  2249         __TRACE( KError, ( 
       
  2250             _L( "CTestCombiner::StartMeasurementL(): iTestMeasurementArray.Append fails:[%d]" ), ret ) );
       
  2251         User::Leave( ret );
       
  2252         }
       
  2253 
       
  2254     }
       
  2255 
       
  2256 /*
       
  2257 -------------------------------------------------------------------------------
       
  2258 
       
  2259      Class: CTestCombiner
       
  2260 
       
  2261      Method: StopMeasurementL
       
  2262 
       
  2263      Description: Stops test measurement.
       
  2264   
       
  2265      Parameters: None.
       
  2266 
       
  2267      Return Values: None.
       
  2268 
       
  2269      Errors/Exceptions: None.
       
  2270 
       
  2271      Status: Proposal
       
  2272     
       
  2273 -------------------------------------------------------------------------------
       
  2274 */
       
  2275 void CTestCombiner::StopMeasurementL( const TDesC& aType )
       
  2276     {
       
  2277     __TRACEFUNC();
       
  2278 
       
  2279     TInt count = iTestMeasurementArray.Count();
       
  2280     for( TInt i = 0; i < count; i++ )
       
  2281         {
       
  2282         if( iTestMeasurementArray[i]->iName == aType )
       
  2283             {
       
  2284             // Found measurement module, stop
       
  2285             iTestMeasurementArray[i]->iMeasurement->Stop();
       
  2286             // Delete data
       
  2287             delete iTestMeasurementArray[i];
       
  2288             // Remove pointer to deleted data(Append())
       
  2289             iTestMeasurementArray.Remove( i );
       
  2290             // iTestMeasurementArray can contain only one type of measurement
       
  2291             // so we can break when type is removed.
       
  2292             break;
       
  2293             }
       
  2294         }
       
  2295 
       
  2296     }
       
  2297 
       
  2298 /*
       
  2299 -------------------------------------------------------------------------------
       
  2300 
       
  2301      Class: CTestCombiner
       
  2302 
       
  2303      Method: AppendTestResultToResultDes
       
  2304 
       
  2305      Description: Append to TC's result description (if possible due to length) 
       
  2306                   limitation provided text in [] brackets.
       
  2307   
       
  2308      Parameters: None.
       
  2309 
       
  2310      Return Values: None.
       
  2311 
       
  2312      Errors/Exceptions: None.
       
  2313 
       
  2314      Status: Proposal
       
  2315     
       
  2316 -------------------------------------------------------------------------------
       
  2317 */
       
  2318 void CTestCombiner::AppendTestResultToResultDes(TDes& aResultDescr, const TDesC& aTestCaseResultDescr)
       
  2319     {
       
  2320     if(aTestCaseResultDescr != KNullDesC)
       
  2321         {
       
  2322         _LIT(KAdditionalInfo, " [%S]");
       
  2323         TInt len = aResultDescr.Length() + KAdditionalInfo().Length() + aTestCaseResultDescr.Length();
       
  2324 
       
  2325         if(len > KStifMaxResultDes)
       
  2326             {
       
  2327             len = KStifMaxResultDes - aResultDescr.Length() - KAdditionalInfo().Length();
       
  2328             if(len > 0)
       
  2329                 {
       
  2330                 TPtrC descr = aTestCaseResultDescr.Mid(0, len); 
       
  2331                 aResultDescr.AppendFormat(KAdditionalInfo, &descr);
       
  2332                 }
       
  2333             }
       
  2334         else
       
  2335             {
       
  2336             aResultDescr.AppendFormat(KAdditionalInfo, &aTestCaseResultDescr);
       
  2337             }
       
  2338         }
       
  2339     }
       
  2340 
       
  2341 /*
       
  2342 -------------------------------------------------------------------------------
       
  2343 
       
  2344     Class: CTestCombiner
       
  2345 
       
  2346     Method: GetIndexForNewTestModuleController
       
  2347 
       
  2348     Description: Returns new index for test module controller.
       
  2349                  This number is appended to module controller name.
       
  2350                  This method is used when option to run every test case in 
       
  2351                  separate process is set to on.
       
  2352 
       
  2353     Parameters: None
       
  2354     
       
  2355     Return Values: None
       
  2356 
       
  2357     Errors/Exceptions: None
       
  2358 
       
  2359     Status: Approved
       
  2360 
       
  2361 -------------------------------------------------------------------------------
       
  2362 */
       
  2363 TInt CTestCombiner::GetIndexForNewTestModuleController(void)
       
  2364     {
       
  2365     return iIndexTestModuleControllers++;
       
  2366     }
       
  2367     
       
  2368 /*
       
  2369 -------------------------------------------------------------------------------
       
  2370 
       
  2371     DESCRIPTION
       
  2372 
       
  2373     This module contains the implementation of CTestRunner class 
       
  2374     member functions. CTestRunner is used to execute TestCombiner testcase by 
       
  2375     CTestCombiner.
       
  2376 
       
  2377 -------------------------------------------------------------------------------
       
  2378 */
       
  2379 // MACROS
       
  2380 #ifdef LOGGER
       
  2381 #undef LOGGER
       
  2382 #endif
       
  2383 #define LOGGER iTestCombiner->iLog
       
  2384 
       
  2385 // ================= MEMBER FUNCTIONS =========================================
       
  2386 
       
  2387 /*
       
  2388 -------------------------------------------------------------------------------
       
  2389 
       
  2390      Class: CTestRunner
       
  2391 
       
  2392      Method: CTestRunner
       
  2393 
       
  2394      Description: Default constructor
       
  2395 
       
  2396      C++ default constructor can NOT contain any code, that
       
  2397      might leave.
       
  2398      
       
  2399      Parameters: CTestCombiner* aTestCombiner: in: Backpointer to CTestCombiner
       
  2400 
       
  2401      Return Values: None
       
  2402 
       
  2403      Errors/Exceptions: None
       
  2404 
       
  2405      Status: Approved
       
  2406     
       
  2407 -------------------------------------------------------------------------------
       
  2408 */
       
  2409 CTestRunner::CTestRunner( CTestCombiner* aTestCombiner ): 
       
  2410     CActive(  CActive::EPriorityLow ), // Executed with lowest priority 
       
  2411     iState( ERunnerIdle ),
       
  2412     iTestCombiner( aTestCombiner )
       
  2413     {
       
  2414     CActiveScheduler::Add( this );
       
  2415     __TRACEFUNC();
       
  2416     
       
  2417     }
       
  2418 
       
  2419 /*
       
  2420 -------------------------------------------------------------------------------
       
  2421 
       
  2422      Class: CTestRunner
       
  2423 
       
  2424      Method: ConstructL
       
  2425 
       
  2426      Description: Symbian OS second phase constructor
       
  2427 
       
  2428      Symbian OS default constructor can leave.
       
  2429 
       
  2430      Parameters:    None
       
  2431 
       
  2432      Return Values: None
       
  2433 
       
  2434      Errors/Exceptions: None
       
  2435 
       
  2436      Status: Approved
       
  2437     
       
  2438 -------------------------------------------------------------------------------
       
  2439 */
       
  2440 void CTestRunner::ConstructL()
       
  2441     {
       
  2442     
       
  2443     iPauseTimer.CreateLocal();
       
  2444     
       
  2445     iRemoteTimer = CRemoteTimer::NewL( iTestCombiner );
       
  2446     
       
  2447     }
       
  2448 
       
  2449 /*
       
  2450 -------------------------------------------------------------------------------
       
  2451 
       
  2452      Class: CTestRunner
       
  2453 
       
  2454      Method: NewL
       
  2455 
       
  2456      Description: Two-phased constructor.
       
  2457           
       
  2458      Parameters: CTestCombiner* aTestCombiner: in: Backpointer to CTestCombiner
       
  2459 
       
  2460      Return Values: CTestRunner*: new object
       
  2461 
       
  2462      Errors/Exceptions: Leaves if new or ConstructL leaves
       
  2463 
       
  2464      Status: Approved
       
  2465     
       
  2466 -------------------------------------------------------------------------------
       
  2467 */
       
  2468 
       
  2469 CTestRunner* CTestRunner::NewL( CTestCombiner* aTestCombiner )
       
  2470     {
       
  2471     CTestRunner* self = new (ELeave) CTestRunner( aTestCombiner );
       
  2472      
       
  2473     CleanupStack::PushL( self );
       
  2474     self->ConstructL();
       
  2475     CleanupStack::Pop();
       
  2476 
       
  2477     return self;
       
  2478     }
       
  2479 
       
  2480 /*
       
  2481 -------------------------------------------------------------------------------
       
  2482 
       
  2483      Class: CTestRunner
       
  2484 
       
  2485      Method: ~CTestRunner
       
  2486 
       
  2487      Description: Destructor
       
  2488      
       
  2489      Parameters:    None
       
  2490 
       
  2491      Return Values: None
       
  2492 
       
  2493      Errors/Exceptions: None
       
  2494 
       
  2495      Status: Approved
       
  2496     
       
  2497 -------------------------------------------------------------------------------
       
  2498 */     
       
  2499 
       
  2500 CTestRunner::~CTestRunner()
       
  2501     {
       
  2502     __TRACEFUNC();
       
  2503     Cancel();
       
  2504     
       
  2505     delete iRemoteTimer;
       
  2506     iRemoteTimer = 0;
       
  2507     
       
  2508     delete iLine;
       
  2509     iLine = 0;
       
  2510     
       
  2511     iPauseTimer.Close();
       
  2512          
       
  2513     }
       
  2514 
       
  2515 /*
       
  2516 -------------------------------------------------------------------------------
       
  2517 
       
  2518      Class: CTestRunner
       
  2519 
       
  2520      Method: RunL
       
  2521 
       
  2522      Description: Derived from CActive, handles testcase execution.
       
  2523 
       
  2524      Parameters:    None.
       
  2525 
       
  2526      Return Values: None.
       
  2527 
       
  2528      Errors/Exceptions: Leaves on error situations.
       
  2529 
       
  2530      Status: Approved
       
  2531     
       
  2532 -------------------------------------------------------------------------------
       
  2533 */
       
  2534 void CTestRunner::RunL()
       
  2535     {
       
  2536     __TRACEFUNC();
       
  2537     __TRACE( KMessage, (_L("CTestRunner::RunL: [%d] "), iStatus.Int() ));
       
  2538      
       
  2539     User::LeaveIfError( iStatus.Int() );
       
  2540 
       
  2541     if( ( iTestCombiner == NULL ) || 
       
  2542         ( iTestCombiner->iSectionParser == NULL ) )
       
  2543         {
       
  2544         User::Leave( KErrGeneral );
       
  2545         }
       
  2546         
       
  2547     TBool continueTask = EFalse; 
       
  2548         
       
  2549     switch( iState )
       
  2550         {
       
  2551         case ERunnerWaitTimeout:
       
  2552             {
       
  2553             __TRACE( KMessage, (_L("Resume %S"), &iPausedTestCase));
       
  2554             iTestCombiner->TestModuleIf().Printf( KPrintPriExec, 
       
  2555                 KExecute, _L("Resume %S"), &iPausedTestCase);
       
  2556              // Get running testcase identified with testid
       
  2557             CTestCase* testCase = iTestCombiner->GetRunningTest( iPausedTestCase ); 
       
  2558             if( testCase == NULL ) User::Leave( KErrNotFound );
       
  2559             iPausedTestCase.Zero();
       
  2560             if( testCase->Type() == CTestCase::ECaseLocal )
       
  2561                 {
       
  2562                 CTCTestCase* localTestCase = ( CTCTestCase* )testCase;
       
  2563                 // Resume execution
       
  2564                 User::LeaveIfError( localTestCase->TestExecution().Resume() );
       
  2565                 continueTask = ETrue;
       
  2566                 }
       
  2567             else // ECaseRemote
       
  2568                 {
       
  2569                 CRemoteTestCase* remoteTestCase = ( CRemoteTestCase* )testCase;
       
  2570                 // Resume execution
       
  2571                 if( ExecuteRemoteTestCtlL( NULL, 
       
  2572                                            remoteTestCase, 
       
  2573                                            TTCKeywords::EResume ) )
       
  2574                     {
       
  2575                     continueTask = ETrue;
       
  2576                     }
       
  2577                 }               
       
  2578             }
       
  2579             break;
       
  2580         case ERunnerWaitUnset:
       
  2581             iState = ERunnerIdle;
       
  2582 
       
  2583             // Check Unset event 
       
  2584             if( !CheckUnsetEvent() )
       
  2585                 {
       
  2586                 // Got event and unset has not completed 
       
  2587                 // Should never come here
       
  2588                 User::Panic( KTestRunner, KErrGeneral );
       
  2589                  }
       
  2590             break;
       
  2591                          
       
  2592         case ERunnerRunning:
       
  2593             {
       
  2594             iState = ERunnerIdle;
       
  2595             
       
  2596             // Get next execution line from configuration section
       
  2597             iEndLoopStartPos = iTestCombiner->iSectionParser->GetPosition();
       
  2598             TPtrC line;
       
  2599             if( iTestCombiner->iSectionParser->GetNextLine( line ) == KErrNone )
       
  2600                 {
       
  2601                 // Got new execution line 
       
  2602                 __TRACE( KMessage, (_L("CTestRunner got line")));
       
  2603         
       
  2604                 CStifItemParser* item = PreprocessLineL( line );
       
  2605             
       
  2606                 if( item )
       
  2607                     {     
       
  2608                      // Got new execution line 
       
  2609                     CleanupStack::PushL( item ); 
       
  2610                       
       
  2611                     // Execute script line 
       
  2612                     if( ExecuteLineL( item ) )
       
  2613                         {
       
  2614                           __TRACE( KMessage, (_L("RunL: continueTask")));
       
  2615                          // Set CTestRunner active again to perform 
       
  2616                          // next execution line
       
  2617                          // from testcase section 
       
  2618                         continueTask = ETrue;
       
  2619                         }
       
  2620                     CleanupStack::PopAndDestroy( item );
       
  2621                     }
       
  2622                 }
       
  2623             else 
       
  2624                 {
       
  2625                 // No more execution lines in testcase section
       
  2626                 __TRACE( KMessage, 
       
  2627                     (_L("CTestRunner::RunL: Testcase script done (%d running)"), 
       
  2628                         iTestCombiner->iRunningTests));
       
  2629  
       
  2630                 if( ( iTestCombiner->iRunningTests == 0 ) &&
       
  2631                     iTestCombiner->iSchedulerActive )
       
  2632                     {
       
  2633                     __TRACE( KMessage, 
       
  2634                         (_L("RunL: All TestCases done, stop CActiveScheduler")));                     
       
  2635                     CActiveScheduler::Current()->Stop();
       
  2636                     iTestCombiner->iSchedulerActive = EFalse;
       
  2637                     }
       
  2638                 // Now testcase section is executed, 
       
  2639                 // so CTestRunner has done its job and stops
       
  2640                 iState = ERunnerReady;
       
  2641 
       
  2642                 //If we're inside loop, then we have error
       
  2643                 if(iTestCombiner->iLoopIsUsed)
       
  2644                     {
       
  2645                     __TRACE(KError, (_L("Endloop keyword not found. Cannot finish test case properly.")));
       
  2646                     iTestCombiner->iResult = KErrGeneral;
       
  2647                     }
       
  2648                 }
       
  2649             }
       
  2650             break;
       
  2651         case ERunnerAllocate:
       
  2652         case ERunnerFree:
       
  2653         case ERunnerRemote:
       
  2654         default:
       
  2655             __TRACE( KError, 
       
  2656                 (_L("CTestRunner::RunL: Entered in illegal state(%d)"), iState ));
       
  2657             User::Panic( KTestRunner, KErrGeneral );  
       
  2658             break;
       
  2659         }   
       
  2660     if( continueTask )
       
  2661         {
       
  2662         SetRunnerActive();
       
  2663         }
       
  2664            
       
  2665     }
       
  2666      
       
  2667 /*
       
  2668 -------------------------------------------------------------------------------
       
  2669 
       
  2670      Class: CTestRunner
       
  2671 
       
  2672      Method: DoCancel
       
  2673 
       
  2674      Description: Derived from CActive handles the Cancel
       
  2675 
       
  2676      Parameters:    None.
       
  2677 
       
  2678      Return Values: None.
       
  2679 
       
  2680      Errors/Exceptions: None.
       
  2681 
       
  2682      Status: Approved
       
  2683     
       
  2684 -------------------------------------------------------------------------------
       
  2685 */
       
  2686 void CTestRunner::DoCancel()
       
  2687     {
       
  2688     __TRACEFUNC();
       
  2689     __TRACE( KMessage, (_L("CTestRunner::DoCancel")));
       
  2690     iTestCombiner->TestModuleIf().Printf( KPrintPriLow, _L("Runner"), _L("DoCancel"));
       
  2691     
       
  2692     switch( iState )
       
  2693         {
       
  2694         case ERunnerWaitTimeout:
       
  2695             iPauseTimer.Cancel();
       
  2696             break;
       
  2697         case ERunnerWaitUnset:
       
  2698             break;             
       
  2699         case ERunnerRunning:
       
  2700             break;
       
  2701         case ERunnerAllocate:
       
  2702         case ERunnerFree:
       
  2703         case ERunnerRemote:
       
  2704             // Cancel remote test cases
       
  2705             break;
       
  2706         default:
       
  2707             __TRACE( KError, 
       
  2708                 (_L("CTestRunner::DoCancel: Entered in illegal state(%d)"), iState ));
       
  2709             User::Panic( KTestRunner, KErrGeneral );  
       
  2710             break;
       
  2711         }                  
       
  2712     
       
  2713     // Cancel all testcases
       
  2714     CancelTestCases();
       
  2715          
       
  2716     iState = ERunnerCancel;
       
  2717       
       
  2718     }
       
  2719 
       
  2720 /*
       
  2721 -------------------------------------------------------------------------------
       
  2722 
       
  2723      Class: CTestRunner
       
  2724 
       
  2725      Method: RunError
       
  2726 
       
  2727      Description: Derived from CActive handles errors from active handler.
       
  2728   
       
  2729      Parameters:    TInt aError: in: error from CActive
       
  2730      
       
  2731      Return Values: KErrNone: success
       
  2732 
       
  2733      Errors/Exceptions: None.
       
  2734 
       
  2735      Status: Approved
       
  2736     
       
  2737 -------------------------------------------------------------------------------
       
  2738 */
       
  2739 TInt CTestRunner::RunError( TInt aError )
       
  2740     {
       
  2741     __TRACEFUNC();
       
  2742     __TRACE( KMessage, (_L("CTestRunner::RunError %d"), aError));
       
  2743         
       
  2744     if ( iRunErrorMessage.Length() != 0 )
       
  2745     	{
       
  2746     	iTestCombiner->TestModuleIf().Printf( KPrintPriLow, _L("Runner"), 
       
  2747 	            _L("RunError : %S"), &iRunErrorMessage );  
       
  2748 	    iRunErrorMessage = KNullDesC;
       
  2749     	}
       
  2750     else
       
  2751     	{
       
  2752     	iTestCombiner->TestModuleIf().Printf( KPrintPriLow, _L("Runner"), 
       
  2753 	            _L("RunError"));        	
       
  2754     	}    
       
  2755     
       
  2756     iState = ERunnerError;
       
  2757         
       
  2758     // Return error from here
       
  2759     iTestCombiner->iResult = aError;
       
  2760 
       
  2761     CancelTestCases();
       
  2762     return KErrNone;
       
  2763     }
       
  2764 
       
  2765 /*
       
  2766 -------------------------------------------------------------------------------
       
  2767 
       
  2768      Class: CTestRunner
       
  2769 
       
  2770      Method: PreprocessLineL
       
  2771 
       
  2772      Description: Preprocesses script line
       
  2773   
       
  2774      Parameters:  TPtrC& line: in: script line
       
  2775                   CStifItemParser*& aItem: out: New CStifItemParser for script
       
  2776                   line.
       
  2777                     
       
  2778      Return Values: HBufC* pointer if new memory that has been allocated
       
  2779 
       
  2780      Errors/Exceptions: Leaves on error situations.
       
  2781 
       
  2782      Status: Draft
       
  2783     
       
  2784 -------------------------------------------------------------------------------
       
  2785 */        
       
  2786 CStifItemParser* CTestRunner::PreprocessLineL( TDesC& line )
       
  2787     {
       
  2788     
       
  2789     CStifItemParser* item = NULL;
       
  2790     TPtrC tmp;
       
  2791     TInt len = 0;
       
  2792         
       
  2793     // Decide how long buffer should be allocated
       
  2794     if( line.Length() < KMaxName/2 )
       
  2795         {
       
  2796         len = KMaxName;
       
  2797         }
       
  2798     else 
       
  2799         {
       
  2800         len = line.Length() + KMaxName;
       
  2801         }
       
  2802     delete iLine;
       
  2803     iLine = 0;
       
  2804     iLine = HBufC::NewL( len );
       
  2805     TPtr parsedLine( iLine->Des() );
       
  2806     len = 0;
       
  2807     
       
  2808     item = CStifItemParser::NewL( line, 0, line.Length() );
       
  2809     CleanupStack::PushL( item);
       
  2810     
       
  2811     TInt ret = item->GetString( _L(""), tmp );
       
  2812     while( ret == KErrNone )
       
  2813         {
       
  2814         len += CheckDefined( tmp );
       
  2815         if( ( parsedLine.Length() + tmp.Length() + 1 ) > parsedLine.MaxLength() )
       
  2816             {
       
  2817             // Allocate bigger buffer
       
  2818             HBufC* tmpBuf = HBufC::NewL( parsedLine.MaxLength() + KMaxName );
       
  2819             CleanupStack::PushL( tmpBuf );
       
  2820             TPtrC ptr( iLine->Des() );
       
  2821             parsedLine.Set( tmpBuf->Des() );
       
  2822             parsedLine.Copy( ptr );
       
  2823             delete iLine;
       
  2824             iLine = tmpBuf;
       
  2825             CleanupStack::Pop( tmpBuf );
       
  2826             } 
       
  2827         parsedLine.Append( tmp );        
       
  2828         parsedLine.Append( _L(" ") );        
       
  2829         ret = item->GetNextString( tmp );
       
  2830         }
       
  2831         
       
  2832     CleanupStack::PopAndDestroy( item );
       
  2833     
       
  2834     item = CStifItemParser::NewL( parsedLine, 0, parsedLine.Length() );
       
  2835     
       
  2836     return item;
       
  2837     
       
  2838     }
       
  2839 
       
  2840 /*
       
  2841 -------------------------------------------------------------------------------
       
  2842 
       
  2843      Class: CTestRunner
       
  2844 
       
  2845      Method: CheckDefined
       
  2846 
       
  2847      Description: Check if aWord is some defined word
       
  2848   
       
  2849      Parameters:  TPtrC& aWord: inout: Parsed word, defined or original returned
       
  2850 
       
  2851      Return Values: TInt: Length difference between new and old word
       
  2852 
       
  2853      Errors/Exceptions: None.
       
  2854 
       
  2855      Status: Approved
       
  2856 
       
  2857 -------------------------------------------------------------------------------
       
  2858 */
       
  2859 TInt CTestRunner::CheckDefined( TPtrC& aWord )
       
  2860     {
       
  2861     TInt len = 0;
       
  2862 
       
  2863     // KLoopCounter word changing to current loop count value.
       
  2864     if( aWord == KLoopCounter )
       
  2865         {
       
  2866         iLoopCounterDes.Zero();
       
  2867         iLoopCounterDes.AppendNum( iLoopCounter );
       
  2868         len = iLoopCounterDes.Length() - aWord.Length();
       
  2869         aWord.Set( iLoopCounterDes );
       
  2870         return len;
       
  2871         }
       
  2872 
       
  2873     TInt count = iTestCombiner->iDefined.Count();
       
  2874     for( TInt i = 0; i < count; i++ )
       
  2875         {
       
  2876         if( iTestCombiner->iDefined[i]->Name() == aWord )
       
  2877             { 
       
  2878             len = iTestCombiner->iDefined[i]->Value().Length() - aWord.Length();
       
  2879             aWord.Set( iTestCombiner->iDefined[i]->Value() );
       
  2880             break;
       
  2881             }
       
  2882         }
       
  2883     return len;
       
  2884 
       
  2885     }
       
  2886 
       
  2887 /*
       
  2888 -------------------------------------------------------------------------------
       
  2889 
       
  2890      Class: CTestRunner
       
  2891 
       
  2892      Method: ExecuteLineL
       
  2893 
       
  2894      Description: Executes script line
       
  2895   
       
  2896      Parameters:    CStifItemParser* aItem: in: script line
       
  2897                     TTCKeywords::TKeywords aKeyword: in: keyword index
       
  2898 
       
  2899      Return Values: ETrue: continue script file execution
       
  2900                     EFalse: stop script file execution
       
  2901 
       
  2902      Errors/Exceptions: Leaves on error situations.
       
  2903 
       
  2904      Status: Approved
       
  2905 
       
  2906 -------------------------------------------------------------------------------
       
  2907 */
       
  2908 TBool CTestRunner::ExecuteLineL( CStifItemParser* aItem )
       
  2909     {
       
  2910     _LIT( KErrMsgUnknownKeyword, "Unknown or illegal keyword %S" );
       
  2911     _LIT( KErrMsgMeasurementInvalidArgument, "Measurement : Invalid argument" );
       
  2912     TBool continueTask = ETrue;
       
  2913     TPtrC tmp;
       
  2914 
       
  2915     TPtrC keywordItem;
       
  2916     // Get first word from line, i.e. keyword
       
  2917     User::LeaveIfError( aItem->GetString( _L(""), keywordItem ) );
       
  2918     // Parse keyword
       
  2919     TInt keyword = TTCKeywords::Parse( keywordItem, TTCKeywords::Keyword );
       
  2920         
       
  2921     switch( keyword )
       
  2922         {
       
  2923         // Test case execution control cases
       
  2924         case TTCKeywords::EPauseCombiner:
       
  2925         	continueTask = ExecuteCombinerPauseL( aItem );
       
  2926         	break;
       
  2927         case TTCKeywords::ERun:
       
  2928             continueTask = ExecuteRunL( aItem );
       
  2929             break;
       
  2930         case TTCKeywords::EPause:
       
  2931         case TTCKeywords::EComplete:
       
  2932         case TTCKeywords::ECancel:
       
  2933         case TTCKeywords::EResume:
       
  2934             continueTask = ExecuteTestCtlL( aItem, (TTCKeywords::TKeywords)keyword );
       
  2935             break;
       
  2936 
       
  2937         // Event control cases
       
  2938         case TTCKeywords::ESet:
       
  2939               continueTask = ExecuteEventSetL( aItem );
       
  2940             break;
       
  2941         case TTCKeywords::EUnset:
       
  2942               continueTask = ExecuteEventUnsetL( aItem );
       
  2943             break;
       
  2944         case TTCKeywords::ERequest:
       
  2945         case TTCKeywords::EWait:
       
  2946         case TTCKeywords::ERelease:
       
  2947             continueTask = ExecuteEventCtlL( aItem, (TTCKeywords::TKeywords)keyword );
       
  2948             break;
       
  2949         case TTCKeywords::EPrint:
       
  2950             {
       
  2951             TName buf;
       
  2952             while( aItem->GetNextString( tmp ) == KErrNone )
       
  2953                 {
       
  2954                 if( buf.Length() + tmp.Length() >= buf.MaxLength() )
       
  2955                     {
       
  2956                     break;
       
  2957                     }
       
  2958                 buf.Append( tmp );
       
  2959                 buf.Append( _L(" ") );
       
  2960                 }
       
  2961 
       
  2962             __TRACE( KMessage, (_L("Test: %S"), &buf ));
       
  2963             iTestCombiner->TestModuleIf().Printf( KPrintPriHigh, 
       
  2964                 _L("Test"), 
       
  2965                 _L("%S"), &buf);
       
  2966            }
       
  2967            break;
       
  2968         case TTCKeywords::EAllocate:
       
  2969             continueTask = ExecuteAllocateL( aItem );
       
  2970             break;
       
  2971         case TTCKeywords::EFree:
       
  2972             continueTask = ExecuteFreeL( aItem );
       
  2973             break;
       
  2974         case TTCKeywords::ERemote:
       
  2975             continueTask = ExecuteRemoteL( aItem );
       
  2976             break;
       
  2977         case TTCKeywords::ETimeout:
       
  2978         case TTCKeywords::EPriority:
       
  2979             // not used here
       
  2980             break;
       
  2981         case TTCKeywords::ECancelIfError:
       
  2982             // @js
       
  2983             iTestCombiner->iCancelIfError = ETrue;
       
  2984             break;
       
  2985         case TTCKeywords::EMeasurement:
       
  2986             TRAPD( retErr, iTestCombiner->ExecuteMeasurementL( aItem ) );
       
  2987         	if ( retErr == KErrArgument )
       
  2988         		{
       
  2989         		iRunErrorMessage = KErrMsgMeasurementInvalidArgument;
       
  2990         		}
       
  2991         	if ( retErr != KErrNone )
       
  2992         		{
       
  2993         		User::Leave( retErr );
       
  2994         		}
       
  2995             break;
       
  2996         case TTCKeywords::ELoop:
       
  2997             ExecuteLoopL( aItem );
       
  2998             iTestCombiner->iLoopIsUsed = ETrue;
       
  2999             break;
       
  3000         case TTCKeywords::EEndLoop:
       
  3001             continueTask = ExecuteEndLoopL();
       
  3002             break;
       
  3003         case TTCKeywords::ETitle:
       
  3004             // title has been handled already, this is duplicate
       
  3005         default:
       
  3006             {
       
  3007               __TRACE( KError, (_L("Unknown or illegal keyword") ) );
       
  3008             // Unknown or illegal keyword
       
  3009             iRunErrorMessage.Format( KErrMsgUnknownKeyword, &keywordItem );
       
  3010             User::Leave( KErrGeneral );
       
  3011             }
       
  3012             break;
       
  3013         }
       
  3014 
       
  3015     __TRACE( KMessage, (_L("RunL: TestCase line executed")));
       
  3016 
       
  3017     return continueTask;
       
  3018 
       
  3019     }
       
  3020 
       
  3021 /*
       
  3022 -------------------------------------------------------------------------------
       
  3023 
       
  3024      Class: CTestRunner
       
  3025 
       
  3026      Method: ExecuteRunL
       
  3027 
       
  3028      Description: Executes run line
       
  3029   
       
  3030      Parameters:    CStifItemParser* aItem: in: script line
       
  3031      
       
  3032      Return Values: ETrue: continue script file execution
       
  3033                     EFalse: stop script file execution
       
  3034 
       
  3035      Errors/Exceptions: Leaves on error situations.
       
  3036 
       
  3037      Status: Proposal
       
  3038     
       
  3039 -------------------------------------------------------------------------------
       
  3040 */
       
  3041 TBool CTestRunner::ExecuteRunL( CStifItemParser* aItem )
       
  3042     {
       
  3043     _LIT( KErrMsgCaseRunError, "Run : %S[case=%d] run error" );
       
  3044     __TRACE( KMessage, (_L("Run")));
       
  3045     iTestCombiner->TestModuleIf().Printf( KPrintPriExec, KExecute, _L("Run"));
       
  3046     
       
  3047     CStartInfo* startInfo = CStartInfo::NewL();
       
  3048     CleanupStack::PushL( startInfo );
       
  3049 
       
  3050     ParseRunParamsL( aItem, *startInfo );
       
  3051              
       
  3052     // Start new case with configurations parsed above                
       
  3053     
       
  3054     iRunErrorMessage.Format( KErrMsgCaseRunError, &startInfo->iModule, startInfo->iCaseNum );
       
  3055     User::LeaveIfError( 
       
  3056         iTestCombiner->StartTestL( *startInfo ) );
       
  3057     iRunErrorMessage = KNullDesC;
       
  3058     
       
  3059     CleanupStack::PopAndDestroy( startInfo );
       
  3060         
       
  3061     return ETrue;
       
  3062     
       
  3063 }
       
  3064 
       
  3065  
       
  3066 /*
       
  3067 -------------------------------------------------------------------------------
       
  3068 
       
  3069      Class: CTestRunner
       
  3070 
       
  3071      Method: ParseRunParamsL
       
  3072 
       
  3073      Description: Parses run parameters
       
  3074   
       
  3075      Parameters:    CStifItemParser* aItem: in: script line
       
  3076                     CStartInfo& aStartInfo: out: Parsed information
       
  3077      
       
  3078      Return Values: None
       
  3079      
       
  3080      Errors/Exceptions: Leaves on error situations.
       
  3081 
       
  3082      Status: Draft
       
  3083     
       
  3084 -------------------------------------------------------------------------------
       
  3085 */
       
  3086 void CTestRunner::ParseRunParamsL( CStifItemParser* aItem,
       
  3087                                     CStartInfo& aStartInfo )
       
  3088     {
       
  3089     _LIT( KErrMsgRunTestmoduleNameNotDefined, "Run : Testmodule name is not defined " );
       
  3090     _LIT( KErrMsgRunCfgFileNotDefined, "Run : Testmodule configuration file is not defined" );
       
  3091     _LIT( KErrMsgRunTestcaseNumberNotDefined, "Run : Testcase number is not defined or has invalid value" );
       
  3092     _LIT( KErrMsgRunCfgFileNameToLong, "Run : TestScripter test case file(config)'s name is too long. Current length[%d], allowed max length[%d]. Cannot continue" );
       
  3093     _LIT( KErrMsgRunInvalidExpectValue, "Run : Invalid expected result value" );
       
  3094     _LIT( KErrMsgRunUnknownOrIllegalCategory, "Run : Unknown or illegal result category" );
       
  3095     _LIT( KErrMsgRunInvalidTimeoutValue, "Run: Invalid testcase timeout value" );
       
  3096     _LIT( KErrMsgRunUnknowOrIllegalKeyword, "Run: Unknown or illegal keyword %S" );
       
  3097     
       
  3098     TPtrC tmp;
       
  3099     TInt ret = KErrNone;
       
  3100 
       
  3101     // Get mandatory run arguments
       
  3102     // Testmodule name
       
  3103     ret = aItem->GetNextString( tmp );
       
  3104     if ( ret != KErrNone )
       
  3105     	{
       
  3106     	iRunErrorMessage = KErrMsgRunTestmoduleNameNotDefined;
       
  3107     	User::Leave( ret );
       
  3108     	}
       
  3109     
       
  3110     aStartInfo.SetModuleNameL( tmp );
       
  3111     __TRACE( KMessage, (_L("module: %S"), &aStartInfo.iModule ));
       
  3112     
       
  3113     // Configuration file
       
  3114     ret = aItem->GetNextString( tmp );
       
  3115     if ( ret != KErrNone )
       
  3116     	{
       
  3117     	iRunErrorMessage = KErrMsgRunCfgFileNotDefined;
       
  3118     	User::Leave( ret );
       
  3119     	}
       
  3120     
       
  3121     TFileName cfgFileName( tmp );
       
  3122     TStifUtil::CorrectFilePathL( cfgFileName );    
       
  3123     aStartInfo.SetConfigL( cfgFileName );
       
  3124     
       
  3125     __TRACE( KMessage, (_L("config: %S"), &aStartInfo.iConfig ));
       
  3126 
       
  3127     // Check is TestScripter
       
  3128     if( aStartInfo.iModule.Find( KTestScripterName ) != KErrNotFound )
       
  3129         {
       
  3130         // TestScripter name is format: 'testscripter_testcasefilename'
       
  3131 
       
  3132         TParse parse;
       
  3133         parse.Set( aStartInfo.iConfig, NULL, NULL );
       
  3134 
       
  3135         // Maximum length of TestScripter's name(Max limitation from
       
  3136         // CTestModuleController creation)
       
  3137         TInt maximumLength = KMaxName - ( KTestScripterNameLength + 1 );
       
  3138 
       
  3139         TFileName testScripterAndTestCaseFile; // InitL() takes TFileName
       
  3140         testScripterAndTestCaseFile.Copy( KTestScripterName );
       
  3141         testScripterAndTestCaseFile.Append( _L( "_" ) );
       
  3142         if( parse.Name().Length() < maximumLength )
       
  3143             {
       
  3144             testScripterAndTestCaseFile.Append( parse.Name() );
       
  3145             }
       
  3146         else
       
  3147             {
       
  3148             __TRACE( KInit, ( CStifLogger::ERed,
       
  3149                 _L( "TestScripter test case file(config)'s name is too long. Current length[%d], allowed max length[%d]. Cannot continue" ),
       
  3150                 parse.Name().Length(), maximumLength ) );
       
  3151             iRunErrorMessage.Format( KErrMsgRunCfgFileNameToLong, parse.Name().Length(), maximumLength );
       
  3152             User::Leave( KErrArgument );
       
  3153             }
       
  3154 // ----
       
  3155         aStartInfo.DeleteModuleName(); // Delete old name buffer for new one
       
  3156         aStartInfo.SetModuleNameL( testScripterAndTestCaseFile );
       
  3157         }
       
  3158 
       
  3159     // Testcase number
       
  3160     ret = aItem->GetInt( tmp, aStartInfo.iCaseNum );
       
  3161     if ( ret != KErrNone )
       
  3162     	{
       
  3163     	iRunErrorMessage = KErrMsgRunTestcaseNumberNotDefined;
       
  3164     	User::Leave( ret );
       
  3165     	}
       
  3166     
       
  3167     __TRACE( KMessage, (_L("testcasenum: %d"), aStartInfo.iCaseNum ) );
       
  3168      
       
  3169     // Set mode of item parser to be able to read titles with spaces inside
       
  3170     aItem->SetParsingType(CStifItemParser::EQuoteStyleParsing);
       
  3171 
       
  3172     // Get optional run arguments
       
  3173     while( aItem->GetNextString( tmp ) == KErrNone )
       
  3174         {
       
  3175         TPtrC val;   
       
  3176         TPtrC arg;
       
  3177         ParseOptArgL( tmp, arg, val );
       
  3178         CheckDefined( val );
       
  3179               
       
  3180         // Parse optional argument
       
  3181         switch( TTCKeywords::Parse( arg, TTCKeywords::RunOptArg ) )
       
  3182             {
       
  3183             case TTCKeywords::EExpect:
       
  3184                 {
       
  3185                 TLex ptr( val );
       
  3186                 ret = ptr.Val( aStartInfo.iExpectedResult );
       
  3187                 if ( ret != KErrNone )
       
  3188                 	{
       
  3189                 	iRunErrorMessage = KErrMsgRunInvalidExpectValue;
       
  3190                     User::Leave( ret );
       
  3191                 	}
       
  3192                 __TRACE( KMessage, (_L("expect=%d"), aStartInfo.iExpectedResult));
       
  3193                 }
       
  3194                 break;
       
  3195             case TTCKeywords::ETestid:
       
  3196 				{
       
  3197                 aStartInfo.SetTestIdL( val );
       
  3198                 __TRACE( KMessage, (_L("TestId=%S"), &val));
       
  3199 				}
       
  3200                 break;
       
  3201             case TTCKeywords::EIni:
       
  3202 				{
       
  3203                 __TRACE( KMessage, (_L("ini=%S"), &val));
       
  3204 	        	TFileName iniFileName( val );
       
  3205 	        	TStifUtil::CorrectFilePathL( iniFileName );
       
  3206 	            aStartInfo.SetIniFileL( iniFileName );
       
  3207 				}
       
  3208                 break;
       
  3209             case TTCKeywords::ECategory:
       
  3210 				{
       
  3211                 __TRACE( KMessage, (_L("category=%S"), &val));
       
  3212                 aStartInfo.iCategory = TTCKeywords::GetResultCategory( val );
       
  3213                 if( aStartInfo.iCategory == TFullTestResult::ECaseOngoing )
       
  3214                     {
       
  3215                     __TRACE( KError, (_L("Unknown or illegal result category")));
       
  3216                     //Unknown or illegal category
       
  3217                     iRunErrorMessage = KErrMsgRunUnknownOrIllegalCategory;
       
  3218                     User::Leave( KErrGeneral );
       
  3219                     }
       
  3220 				}
       
  3221                 break;
       
  3222             case TTCKeywords::ECaseTimeout:
       
  3223                 {
       
  3224                 TLex ptr( val );
       
  3225                 ret = ptr.Val( aStartInfo.iTimeout );
       
  3226                 if ( ret != KErrNone )
       
  3227                 	{
       
  3228                 	iRunErrorMessage = KErrMsgRunInvalidTimeoutValue;
       
  3229                     User::Leave( ret );
       
  3230                 	}
       
  3231                 __TRACE( KMessage, (_L("timeout=%d"), aStartInfo.iTimeout ) );
       
  3232                 }
       
  3233                 break;
       
  3234            	case TTCKeywords::ECaseTitle:
       
  3235            	    {
       
  3236                 __TRACE( KMessage, (_L("case title=%S"), &val));
       
  3237                 aStartInfo.SetTitleL(val);
       
  3238                 break;
       
  3239            	    }
       
  3240             default:
       
  3241 				{
       
  3242                 __TRACE( KError, (_L("Unknown or illegal keyword")));
       
  3243                 //Unknown or illegal keyword
       
  3244                 iRunErrorMessage.Format( KErrMsgRunUnknowOrIllegalKeyword, &arg );
       
  3245                 User::Leave( KErrGeneral );
       
  3246 				}
       
  3247             }
       
  3248         }             
       
  3249     } 
       
  3250 
       
  3251 /*
       
  3252 -------------------------------------------------------------------------------
       
  3253 
       
  3254      Class: CTestRunner
       
  3255 
       
  3256      Method: ExecuteTestCtlL
       
  3257 
       
  3258      Description: Executes script line
       
  3259   
       
  3260      Parameters:    CStifItemParser* aItem: in: script line
       
  3261                     TTCKeywords::TKeywords aKeyword: in: keyword index
       
  3262      
       
  3263      Return Values: ETrue: continue script file execution
       
  3264                     EFalse: stop script file execution
       
  3265 
       
  3266      Errors/Exceptions: Leaves on error situations.
       
  3267 
       
  3268      Status: Approved
       
  3269     
       
  3270 -------------------------------------------------------------------------------
       
  3271 */
       
  3272 TBool CTestRunner::ExecuteTestCtlL( CStifItemParser* aItem, 
       
  3273                                     TTCKeywords::TKeywords aKeyword )
       
  3274     {
       
  3275     _LIT( KErrMsgTestIdNotDefined, "%S : testid is not defined" );
       
  3276     _LIT( KErrMsgTestCaseNotFound, "%S : Test case %S not found" );
       
  3277     TBool continueTask = ETrue;
       
  3278     TPtrC tmp;
       
  3279     
       
  3280     TInt ret = KErrNone;
       
  3281 
       
  3282 	TPtrC keywordStr = TTCKeywords::Keyword( aKeyword );
       
  3283 
       
  3284     // Parse testid
       
  3285     ret = aItem->GetNextString( tmp );
       
  3286     if( ret != KErrNone )
       
  3287     	{
       
  3288     	iRunErrorMessage.Format( KErrMsgTestIdNotDefined, &keywordStr );
       
  3289         User::Leave( ret );            	
       
  3290     	}
       
  3291 
       
  3292     // Get testcase identified with testid
       
  3293     CTestCase* testCase = iTestCombiner->GetTest( tmp ); 
       
  3294     if( testCase == NULL )
       
  3295         {
       
  3296         __TRACE( KError, (_L("ExecuteTestCtlL: Test case %S not found"), 
       
  3297             &tmp));
       
  3298         iRunErrorMessage.Format( KErrMsgTestCaseNotFound, &keywordStr, &tmp );
       
  3299         User::Leave( KErrNotFound );
       
  3300         }  
       
  3301                               
       
  3302     switch( aKeyword )
       
  3303         {
       
  3304         // Test case execution control cases
       
  3305         case TTCKeywords::EPause:
       
  3306             continueTask = ExecutePauseL( aItem, testCase );
       
  3307             break;
       
  3308         case TTCKeywords::EComplete:
       
  3309             continueTask = ExecuteCompleteL( aItem, testCase );
       
  3310             break;
       
  3311         case TTCKeywords::ECancel:
       
  3312             __TRACE( KMessage, (_L("Cancel %S"), &tmp));
       
  3313             iTestCombiner->TestModuleIf().Printf( KPrintPriExec, 
       
  3314                 KExecute, _L("Cancel %S"), &tmp);
       
  3315             if( testCase->Type() == CTestCase::ECaseRemote )
       
  3316                 {
       
  3317                 continueTask = 
       
  3318                     ExecuteRemoteTestCtlL( aItem, testCase, aKeyword ); 
       
  3319                 }
       
  3320             else 
       
  3321                 {
       
  3322                 if( testCase->State() != CTestCase::ETestCaseRunning )
       
  3323                     {
       
  3324                     __TRACE( KMessage, (_L("Cancelled task (%S) not running (%i)"), 
       
  3325                         &tmp, testCase->State() )); 
       
  3326                     User::Leave( KErrNotFound );                   
       
  3327                     }
       
  3328                 CTCTestCase* test = ( CTCTestCase* )testCase;
       
  3329                 // Cancel local testcase
       
  3330                 test->TestExecution().CancelAsyncRequest( ETestExecutionRunTestCase );
       
  3331                 }
       
  3332             break;
       
  3333         case TTCKeywords::EResume:
       
  3334             {
       
  3335             __TRACE( KMessage, (_L("Resume %S"), &tmp));
       
  3336             iTestCombiner->TestModuleIf().Printf( KPrintPriExec, 
       
  3337                 KExecute, _L("Resume %S"), &tmp);
       
  3338             if( testCase->Type() == CTestCase::ECaseRemote )
       
  3339                 {
       
  3340                 continueTask = 
       
  3341                     ExecuteRemoteTestCtlL( aItem, testCase, aKeyword ); 
       
  3342                 }
       
  3343             else 
       
  3344                 {
       
  3345                 if( testCase->State() != CTestCase::ETestCaseRunning )
       
  3346                     {
       
  3347                     __TRACE( KMessage, (_L("Resumed task (%S) not running (%i)"), 
       
  3348                         &tmp, testCase->State() )); 
       
  3349                     User::Leave( KErrNotFound );                   
       
  3350                     }
       
  3351                 CTCTestCase* test = ( CTCTestCase* )testCase;
       
  3352                 // Resume execution
       
  3353                 User::LeaveIfError( test->TestExecution().Resume() );
       
  3354                 }
       
  3355             }
       
  3356             break;
       
  3357             
       
  3358         default:
       
  3359             // Should never come here
       
  3360             User::Leave( KErrGeneral );
       
  3361             break;
       
  3362         }      
       
  3363     
       
  3364     return continueTask;
       
  3365     
       
  3366     }
       
  3367 
       
  3368 
       
  3369 /*
       
  3370 -------------------------------------------------------------------------------
       
  3371 
       
  3372      Class: CTestRunner
       
  3373 
       
  3374      Method: ExecuteCombinerPauseL
       
  3375 
       
  3376      Description: Executes causes pause in TestCombiner
       
  3377   
       
  3378      Parameters:    CStifItemParser* aItem: in: script line
       
  3379                          
       
  3380      Return Values: ETrue: continue script file execution
       
  3381                     EFalse: stop script file execution
       
  3382 
       
  3383      Errors/Exceptions: Leaves on error situations.
       
  3384 
       
  3385      Status: Proposal
       
  3386     
       
  3387 -------------------------------------------------------------------------------
       
  3388 */
       
  3389 TBool CTestRunner::ExecuteCombinerPauseL( CStifItemParser* aItem )
       
  3390 {
       
  3391 	_LIT( KErrMsgPauseTimeoutNotDefined, "PauseCombiner : No timeout value given or value has invalid format" );
       
  3392 	_LIT( KErrMsgPauseTimeoutNotPositive, "PauseCombiner : Timeout value can't be <0" );
       
  3393 
       
  3394     TBool continueTask = ETrue;
       
  3395     TInt pauseTime;
       
  3396     TInt ret = KErrNone;
       
  3397     
       
  3398     // Parse testid
       
  3399     ret = aItem->GetNextInt( pauseTime );
       
  3400     if ( ret != KErrNone )
       
  3401     	{
       
  3402     	iRunErrorMessage = KErrMsgPauseTimeoutNotDefined;
       
  3403         User::Leave( ret );    	
       
  3404     	}
       
  3405 
       
  3406     if( pauseTime < 0 )
       
  3407         {
       
  3408         __TRACE( KError, (_L("CTestRunner::ExecuteCombinerPauseL: Given pause value < 0")));
       
  3409         iRunErrorMessage = KErrMsgPauseTimeoutNotPositive;
       
  3410         User::Leave( KErrArgument );
       
  3411         }    
       
  3412     
       
  3413     //Time given by End User should be given in miliseconds
       
  3414     pauseTime*=1000;
       
  3415 
       
  3416     __TRACE( KMessage, (_L("time=%d"), pauseTime ) );
       
  3417 
       
  3418     User::After( pauseTime );
       
  3419     
       
  3420     return continueTask;
       
  3421 }
       
  3422      
       
  3423 /*
       
  3424 -------------------------------------------------------------------------------
       
  3425 
       
  3426      Class: CTestRunner
       
  3427 
       
  3428      Method: ExecutePauseL
       
  3429 
       
  3430      Description: Executes pause line
       
  3431   
       
  3432      Parameters:    CStifItemParser* aItem: in: script line
       
  3433                     CTestCase* aTestcase: in: test case
       
  3434      
       
  3435      Return Values: ETrue: continue script file execution
       
  3436                     EFalse: stop script file execution
       
  3437 
       
  3438      Errors/Exceptions: Leaves on error situations.
       
  3439 
       
  3440      Status: Approved
       
  3441     
       
  3442 -------------------------------------------------------------------------------
       
  3443 */
       
  3444 TBool CTestRunner::ExecutePauseL( CStifItemParser* aItem,
       
  3445                                     CTestCase* aTestcase )
       
  3446     {
       
  3447     _LIT( KErrMsgPauseUnknownKeyword, "Pause : Unknown or illegal keyword %S" );
       
  3448     _LIT( KErrMsgPauseTimeInvalidValue, "Pause : Pause time is not defined or has invalid value" );
       
  3449     _LIT( KErrMsgPauseTimeNotPositive, "Pause : Pause time can't be <0" );
       
  3450     TBool continueTask = ETrue;
       
  3451 
       
  3452     // Get optional pause arguments
       
  3453     TPtrC tmp;
       
  3454     iPauseTime = 0;
       
  3455     while( aItem->GetNextString( tmp ) == KErrNone )
       
  3456         {
       
  3457         TPtrC val;   
       
  3458         TPtrC arg;
       
  3459         ParseOptArgL( tmp, arg, val );
       
  3460         CheckDefined( val );
       
  3461               
       
  3462         // Parse optional argument
       
  3463         switch( TTCKeywords::Parse( arg, TTCKeywords::PauseOptArg ) )
       
  3464             {
       
  3465             case TTCKeywords::ETime:
       
  3466                 {
       
  3467                 TLex ptr( val );
       
  3468                 TInt ret = KErrNone;
       
  3469                 ret = ptr.Val( iPauseTime );
       
  3470                 if ( ret != KErrNone )
       
  3471                 	{
       
  3472                 	iRunErrorMessage = KErrMsgPauseTimeInvalidValue;
       
  3473                 	User::Leave( ret );
       
  3474                 	}                
       
  3475                 if ( iPauseTime < 0 )
       
  3476                 	{
       
  3477                 	iRunErrorMessage = KErrMsgPauseTimeNotPositive;
       
  3478                 	User::Leave( KErrArgument );                	
       
  3479                 	}
       
  3480                 __TRACE( KMessage, (_L("time=%d"), iPauseTime ));
       
  3481                 }
       
  3482                 break;
       
  3483             default:
       
  3484                 __TRACE( KError, (_L("Unknown or illegal keyword")));
       
  3485                 //Unknown or illegal keyword
       
  3486                 iRunErrorMessage.Format( KErrMsgPauseUnknownKeyword, &arg );
       
  3487                 User::Leave( KErrGeneral );
       
  3488             }
       
  3489         }             
       
  3490     
       
  3491     // Store paused testcase id if timeout was given as pause argument 
       
  3492     if( iPauseTime != 0 )
       
  3493         {
       
  3494         iPausedTestCase.Copy( aTestcase->TestId() );
       
  3495         }
       
  3496     
       
  3497     if( aTestcase->Type() == CTestCase::ECaseRemote )
       
  3498         {
       
  3499         return ExecuteRemoteTestCtlL( aItem, aTestcase, TTCKeywords::EPause );
       
  3500         }
       
  3501     if( aTestcase->State() != CTestCase::ETestCaseRunning )
       
  3502         {
       
  3503         __TRACE( KMessage, (_L("Paused task (%S) not running (%i)"), 
       
  3504             &aTestcase->TestId(), aTestcase->State() )); 
       
  3505         User::Leave( KErrNotFound );                   
       
  3506         }
       
  3507     CTCTestCase* test = ( CTCTestCase* )aTestcase;
       
  3508     
       
  3509     // Pause execution
       
  3510     User::LeaveIfError( test->TestExecution().Pause() );
       
  3511     
       
  3512     // Resume paused case if timeout was given 
       
  3513     if( iPauseTime != 0 )
       
  3514         {
       
  3515         continueTask = EFalse;
       
  3516         iState = ERunnerWaitTimeout;
       
  3517         iPauseTimer.After( iStatus, iPauseTime*1000 );
       
  3518         SetActive();         
       
  3519         }
       
  3520         
       
  3521     return continueTask;
       
  3522     }
       
  3523 
       
  3524 /*
       
  3525 -------------------------------------------------------------------------------
       
  3526 
       
  3527      Class: CTestRunner
       
  3528 
       
  3529      Method: ExecuteCompleteL
       
  3530 
       
  3531      Description: Executes complete line
       
  3532   
       
  3533      Parameters:    CStifItemParser* aItem: in: script line
       
  3534                     CTestCase* aTestcase: in: test case
       
  3535      
       
  3536      Return Values: ETrue: continue script file execution
       
  3537                     EFalse: stop script file execution
       
  3538 
       
  3539      Errors/Exceptions: Leaves on error situations.
       
  3540 
       
  3541      Status: Approved
       
  3542     
       
  3543 -------------------------------------------------------------------------------
       
  3544 */
       
  3545 TBool CTestRunner::ExecuteCompleteL( CStifItemParser* /* aItem */, 
       
  3546                                      CTestCase* aTestcase )
       
  3547     {
       
  3548     TBool ret = ETrue;
       
  3549     
       
  3550     if( aTestcase->State() == CTestCase::ETestCaseCompleted )
       
  3551          {
       
  3552          // Requested testcase is completed already,
       
  3553          // proceed testcase execution
       
  3554           __TRACE( KMessage, (_L("Already completed")));
       
  3555          }
       
  3556     else if( aTestcase->State() == CTCTestCase::ETestCaseRunning )
       
  3557          {
       
  3558          // Wait testcase to complete                    
       
  3559          iTestCombiner->iWaitTestCase.Copy( aTestcase->TestId() );
       
  3560          // Stop testcase execution until testcase completed 
       
  3561          ret = EFalse;
       
  3562          iState = ERunnerWaitTestCase;
       
  3563          }
       
  3564     else
       
  3565         {
       
  3566         // This should newer happen
       
  3567         User::Leave( KErrGeneral );
       
  3568         }
       
  3569         
       
  3570     return ret;
       
  3571     
       
  3572     }
       
  3573     
       
  3574 /*
       
  3575 -------------------------------------------------------------------------------
       
  3576 
       
  3577      Class: CTestRunner
       
  3578 
       
  3579      Method: ExecuteEventSetL
       
  3580 
       
  3581      Description: Executes event set line
       
  3582   
       
  3583      Parameters:    CStifItemParser* aItem: in: script line
       
  3584      
       
  3585      Return Values: ETrue: continue script file execution
       
  3586                     EFalse: stop script file execution
       
  3587 
       
  3588      Errors/Exceptions: Leaves on error situations.
       
  3589 
       
  3590      Status: Approved
       
  3591     
       
  3592 -------------------------------------------------------------------------------
       
  3593 */
       
  3594 TBool CTestRunner::ExecuteEventSetL( CStifItemParser* aItem )
       
  3595     {
       
  3596     _LIT( KErrMsgSetEventNameNotDefined, "Set : event name is not defined" );
       
  3597     _LIT( KErrMsgSetUnknownOrIllegalKeyword, "Set :Unknown or illegal keyword %S" );
       
  3598     _LIT( KErrMsgSetStateInvalidValue, "Set : State value is not defined or has invalid format" );
       
  3599     TPtrC tmp;
       
  3600     TPtrC eventName;
       
  3601     TInt ret = KErrNone;
       
  3602     
       
  3603     // Get event name
       
  3604     ret = aItem->GetNextString( eventName );
       
  3605     if( ret != KErrNone )
       
  3606     	{
       
  3607     	iRunErrorMessage = KErrMsgSetEventNameNotDefined;
       
  3608         User::Leave( ret );        
       
  3609     	}
       
  3610     __TRACE( KMessage, (_L("Set %S"), &eventName));
       
  3611     iTestCombiner->TestModuleIf().Printf( KPrintPriExec, KExecute, 
       
  3612         _L("Set %S"), &eventName);
       
  3613     iEvent.SetName( eventName );
       
  3614     iEvent.SetType( TEventIf::ESetEvent );
       
  3615 
       
  3616     // Get optional set arguments
       
  3617     while( aItem->GetNextString( tmp ) == KErrNone )
       
  3618         {
       
  3619         TPtrC val;   
       
  3620         TPtrC arg;
       
  3621         ParseOptArgL( tmp, arg, val );
       
  3622         CheckDefined( val );
       
  3623               
       
  3624         // Parse optional set argument
       
  3625         switch( TTCKeywords::Parse( arg, TTCKeywords::EventOptArg ) )
       
  3626             {
       
  3627             case TTCKeywords::EState:
       
  3628                 {
       
  3629                 TLex ptr( val );
       
  3630                 TInt tmpVal = 0;
       
  3631                 ret = ptr.Val( tmpVal );
       
  3632                 if ( ret != KErrNone )
       
  3633                 	{
       
  3634                 	iRunErrorMessage = KErrMsgSetStateInvalidValue;
       
  3635                 	User::Leave( ret );
       
  3636                 	}
       
  3637                 
       
  3638                 // Only value 1 has special meaning, others are ignored
       
  3639                 if( tmpVal == 1 )
       
  3640                     {
       
  3641                      __TRACE( KMessage, (_L("State event")));
       
  3642                      iEvent.SetEventType( TEventIf::EState );
       
  3643                     }
       
  3644                 }
       
  3645                 break;
       
  3646             default:
       
  3647                 __TRACE( KError, (_L("Unknown or illegal keyword")));
       
  3648                 //Unknown or illegal keyword
       
  3649                 iRunErrorMessage.Format( KErrMsgSetUnknownOrIllegalKeyword, &arg );
       
  3650                 User::Leave( KErrGeneral );
       
  3651             }
       
  3652         }      
       
  3653 
       
  3654     // Set event
       
  3655     iTestCombiner->TestModuleIf().Event( iEvent, iStatus );
       
  3656     iState = ERunnerRunning;
       
  3657     SetActive();
       
  3658             
       
  3659     return EFalse;
       
  3660     
       
  3661     }
       
  3662     
       
  3663 /*
       
  3664 -------------------------------------------------------------------------------
       
  3665 
       
  3666      Class: CTestRunner
       
  3667 
       
  3668      Method: ExecuteEventUnsetL
       
  3669 
       
  3670      Description: Executes event unset line
       
  3671   
       
  3672      Parameters:    CStifItemParser* aItem: in: script line
       
  3673      
       
  3674      Return Values: ETrue: continue script file execution
       
  3675                     EFalse: stop script file execution
       
  3676 
       
  3677      Errors/Exceptions: Leaves on error situations.
       
  3678 
       
  3679      Status: Approved
       
  3680     
       
  3681 -------------------------------------------------------------------------------
       
  3682 */
       
  3683 TBool CTestRunner::ExecuteEventUnsetL( CStifItemParser* aItem )
       
  3684     {
       
  3685     _LIT( KErrMsgUnsetEventNameNotDefined, "Unset : Event name is not defined" );
       
  3686     TPtrC eventName;
       
  3687     TInt ret = KErrNone;
       
  3688     // Get event name
       
  3689     ret = aItem->GetNextString( eventName );
       
  3690     if ( ret != KErrNone )
       
  3691     	{
       
  3692     	iRunErrorMessage = KErrMsgUnsetEventNameNotDefined;
       
  3693     	User::Leave( ret );        
       
  3694     	}
       
  3695     
       
  3696     __TRACE( KMessage, (_L("Unset %S"), &eventName));
       
  3697     iTestCombiner->TestModuleIf().Printf( KPrintPriExec, KExecute, 
       
  3698         _L("Unset %S"), &eventName);
       
  3699     iEvent.Set( TEventIf::EUnsetEvent, eventName, TEventIf::EState );
       
  3700     
       
  3701     // Check if trying to unset an event that is requested 
       
  3702     // by testcombiner (otherwise testcombiner would deadlock)
       
  3703     TInt count = iTestCombiner->iEventArray.Count();
       
  3704     TInt ind = 0;
       
  3705     for(; ind < count; ind++ )
       
  3706         {
       
  3707         if( eventName == iTestCombiner->iEventArray[ind]->Name() )
       
  3708             {
       
  3709             User::Leave( KErrInUse );
       
  3710             }
       
  3711         }
       
  3712 
       
  3713     // Check if some testmodule below 
       
  3714     // has event request pending
       
  3715     if( iTestCombiner->UnsetEvent( iEvent, 
       
  3716                                    iStatus ) == EFalse )
       
  3717         {
       
  3718         // If they haven't requested event,
       
  3719         // then check others above
       
  3720         iTestCombiner->TestModuleIf().Event( iEvent, iStatus );
       
  3721         iState = ERunnerRunning;
       
  3722         SetActive();
       
  3723             
       
  3724         }
       
  3725     else
       
  3726         {
       
  3727         // Some testmodule below has requested the event
       
  3728         // Wait unset to complete
       
  3729         SetActive();
       
  3730         __TRACE( KPrint, ( _L("Unset: Start" ) ) );
       
  3731         iState = ERunnerWaitUnset;
       
  3732         // Stop execution until unset has completed
       
  3733         }
       
  3734     return EFalse;
       
  3735     }
       
  3736 
       
  3737 /*
       
  3738 -------------------------------------------------------------------------------
       
  3739 
       
  3740      Class: CTestRunner
       
  3741 
       
  3742      Method: ExecuteLineL
       
  3743 
       
  3744      Description: Executes script line
       
  3745   
       
  3746      Parameters:    CStifItemParser* aItem: in: script line
       
  3747                     TTCKeywords::TKeywords aKeyword: in: keyword index
       
  3748      
       
  3749      Return Values: ETrue: continue script file execution
       
  3750                     EFalse: stop script file execution
       
  3751 
       
  3752      Errors/Exceptions: Leaves on error situations.
       
  3753 
       
  3754      Status: Approved
       
  3755     
       
  3756 -------------------------------------------------------------------------------
       
  3757 */
       
  3758 TBool CTestRunner::ExecuteEventCtlL( CStifItemParser* aItem, 
       
  3759                                      TTCKeywords::TKeywords aKeyword )
       
  3760     {
       
  3761     _LIT( KErrMsgEventNameNotDefined, "%S : Event name is not defined" );
       
  3762     _LIT( KErrMsgEequestEventAlreadyExist, "Request : Requested event %S already exists" );
       
  3763     _LIT( KErrMsgWaitEventNotRequested, "Wait :Waited event %S is not requested" );
       
  3764     _LIT( KErrMsgReleaseEventNotRequested, "Release : Released event %S is not requested" );
       
  3765     
       
  3766     TBool continueTask = ETrue;
       
  3767     TPtrC eventName;
       
  3768     TInt ret = KErrNone;
       
  3769 	TPtrC keywordStr = TTCKeywords::Keyword( aKeyword );
       
  3770     // Get event name
       
  3771     ret = aItem->GetNextString( eventName );
       
  3772     if ( ret != KErrNone )
       
  3773     	{
       
  3774     	iRunErrorMessage.Format( KErrMsgEventNameNotDefined, &keywordStr );
       
  3775     	User::Leave( ret );
       
  3776     	}
       
  3777     
       
  3778     TInt count = iTestCombiner->iEventArray.Count();
       
  3779     TInt ind = 0;
       
  3780     for(; ind < count; ind++ )
       
  3781         {
       
  3782         if( eventName == iTestCombiner->iEventArray[ind]->Name() )
       
  3783             {
       
  3784             break;
       
  3785             }
       
  3786         }
       
  3787                     
       
  3788     switch( aKeyword )
       
  3789         {
       
  3790         case TTCKeywords::ERequest:
       
  3791             {
       
  3792             __TRACE( KMessage, (_L("Request %S"), &eventName));
       
  3793             iTestCombiner->TestModuleIf().Printf( KPrintPriExec, 
       
  3794                 KExecute, _L("Request %S"), &eventName);
       
  3795                 
       
  3796             // Check that event is not already requested           
       
  3797             if( ind < count )
       
  3798                 {
       
  3799                 __TRACE( KError, (_L("Requested event %S already exists"), 
       
  3800                     &eventName));
       
  3801                 iRunErrorMessage.Format( KErrMsgEequestEventAlreadyExist, &eventName );
       
  3802                 User::Leave( KErrAlreadyExists );
       
  3803                 }
       
  3804                 
       
  3805             // Add event to event array
       
  3806             iEvent.SetName( eventName );
       
  3807             iEvent.SetType( TEventIf::EReqEvent );
       
  3808             TEventTc* event = new (ELeave) TEventTc( iTestCombiner->iLog );
       
  3809             CleanupStack::PushL( event );
       
  3810             event->Copy( iEvent );
       
  3811             User::LeaveIfError( iTestCombiner->iEventArray.Append( event ));
       
  3812             if( iTestCombiner->iLoopIsUsed )
       
  3813                 {
       
  3814                 User::LeaveIfError( iTestCombiner->iLoopAllocationArray.Append( event ) );
       
  3815                 }
       
  3816             CleanupStack::Pop( event );
       
  3817             
       
  3818             // Request event
       
  3819             iTestCombiner->TestModuleIf().Event( iEvent, iStatus );
       
  3820             iState = ERunnerRunning;
       
  3821             SetActive();
       
  3822             continueTask = EFalse;
       
  3823             }
       
  3824             break;
       
  3825         case TTCKeywords::EWait:
       
  3826               {
       
  3827             __TRACE( KMessage, (_L("Wait %S"), &eventName));
       
  3828             iTestCombiner->TestModuleIf().Printf( KPrintPriExec, KExecute, 
       
  3829                 _L("Wait %S"), &eventName);
       
  3830 
       
  3831             // Check that event is requested           
       
  3832             if( ind == count )
       
  3833                 {
       
  3834                 __TRACE( KError, (_L("Waited event %S is not requested"), 
       
  3835                     &eventName));
       
  3836                 iRunErrorMessage.Format( KErrMsgWaitEventNotRequested, &eventName );
       
  3837                 User::Leave( KErrNotFound );
       
  3838                 }            
       
  3839             iEvent.SetName( eventName );    
       
  3840             iEvent.SetType( TEventIf::EWaitEvent );     
       
  3841             // Wait event
       
  3842             iTestCombiner->TestModuleIf().Event( iEvent, iStatus );
       
  3843             iState = ERunnerRunning;
       
  3844             SetActive();
       
  3845             continueTask = EFalse;
       
  3846             }
       
  3847             break;
       
  3848         case TTCKeywords::ERelease:
       
  3849             {
       
  3850             __TRACE( KMessage, (_L("Release %S"), &eventName));
       
  3851             iTestCombiner->TestModuleIf().Printf( KPrintPriExec, KExecute, 
       
  3852                 _L("Release %S"), &eventName);
       
  3853             // Check that event is requested           
       
  3854             if( ind == count )
       
  3855                 {
       
  3856                 __TRACE( KError, (_L("Released event %S is not requested"), 
       
  3857                     &eventName));
       
  3858                 iRunErrorMessage.Format( KErrMsgReleaseEventNotRequested, &eventName );
       
  3859                 User::Leave( KErrNotFound );
       
  3860                 }            
       
  3861             // Remove event from array
       
  3862             TEventTc* event = iTestCombiner->iEventArray[ind];
       
  3863             iTestCombiner->iEventArray.Remove( ind );
       
  3864             delete event;
       
  3865             iEvent.SetName( eventName );
       
  3866             iEvent.SetType( TEventIf::ERelEvent );
       
  3867             
       
  3868             // Release event
       
  3869             iTestCombiner->TestModuleIf().Event( iEvent, iStatus );
       
  3870             iState = ERunnerRunning;
       
  3871             SetActive();
       
  3872             continueTask = EFalse;
       
  3873             }
       
  3874             break;
       
  3875         default:
       
  3876             {
       
  3877               __TRACE( KError, (_L("Illegal keyword") ) );
       
  3878             
       
  3879             // Unknown or illegal keyword
       
  3880             User::Leave( KErrGeneral );
       
  3881             }
       
  3882             break;
       
  3883      
       
  3884         }
       
  3885     return continueTask;
       
  3886     }
       
  3887 
       
  3888 /*
       
  3889 -------------------------------------------------------------------------------
       
  3890 
       
  3891      Class: CTestRunner
       
  3892 
       
  3893      Method: ExecuteAllocateL
       
  3894 
       
  3895      Description: Executes allocate line
       
  3896   
       
  3897      Parameters:    CStifItemParser* aItem: in: script line
       
  3898      
       
  3899      Return Values: ETrue: continue script file execution
       
  3900                     EFalse: stop script file execution
       
  3901 
       
  3902      Errors/Exceptions: Leaves on error situations.
       
  3903 
       
  3904      Status: Draft
       
  3905     
       
  3906 -------------------------------------------------------------------------------
       
  3907 */
       
  3908 TBool CTestRunner::ExecuteAllocateL( CStifItemParser* aItem )
       
  3909     {
       
  3910     _LIT( KErrMsgAllocateSlaveTypeNotDefined, "Allocate : Slave type was not given for allocate" );
       
  3911     _LIT( KErrMsgAllocateSlaveNameNotDefined, "Allocate : Slave name is not defined" );
       
  3912     _LIT( KErrMsgAllocateSlaveAlreadyAllocated, "Allocate : Slave with name %S already allocated" );
       
  3913     __TRACE( KMessage, (_L("Allocate")));
       
  3914        
       
  3915     TPtrC type;
       
  3916     TPtrC name;
       
  3917     // Get slave type
       
  3918     TInt ret = aItem->GetNextString( type );
       
  3919     if( ret != KErrNone )
       
  3920         {
       
  3921         __TRACE( KError, (_L("Slave type was not given for allocate")));
       
  3922         iRunErrorMessage = KErrMsgAllocateSlaveTypeNotDefined;
       
  3923         User::Leave( KErrArgument );
       
  3924         }
       
  3925     
       
  3926     // Get slave name
       
  3927     ret = aItem->GetNextString( name );
       
  3928     if( ret != KErrNone )
       
  3929         {
       
  3930         __TRACE( KError, (_L("Slave name was not given for allocate")));
       
  3931         iRunErrorMessage = KErrMsgAllocateSlaveNameNotDefined;
       
  3932         User::Leave( KErrArgument );
       
  3933         }
       
  3934 
       
  3935     iTestCombiner->TestModuleIf().Printf( KPrintPriExec, KExecute, 
       
  3936         _L("Allocate %S"), &name );
       
  3937         
       
  3938     __TRACE( KMessage, (_L("Allocate %S [name: %S]"), &type, &name));
       
  3939     
       
  3940     if( iTestCombiner->GetSlave( name ) )
       
  3941         {
       
  3942         __TRACE( KError, (_L("Slave with name %S already allocated"), 
       
  3943             &name ) );
       
  3944         iRunErrorMessage.Format( KErrMsgAllocateSlaveAlreadyAllocated, &name );
       
  3945         User::Leave( KErrAlreadyExists );
       
  3946         } 
       
  3947         
       
  3948     CSlaveInfo* slave = CSlaveInfo::NewL( name, KRemoteProtocolMasterId );
       
  3949     CleanupStack::PushL( slave );
       
  3950     User::LeaveIfError( iTestCombiner->iSlaveArray.Append( slave ) );
       
  3951     if( iTestCombiner->iLoopIsUsed )
       
  3952         {
       
  3953         User::LeaveIfError( iTestCombiner->iLoopAllocationArray.Append( slave ) );
       
  3954         }
       
  3955     CleanupStack::Pop( slave );
       
  3956 
       
  3957     CStifTFwIfProt* req = CStifTFwIfProt::NewL();
       
  3958     CleanupStack::PushL( req );
       
  3959     req->CreateL();
       
  3960     
       
  3961     // Reserve message
       
  3962     User::LeaveIfError(
       
  3963         req->Append( CStifTFwIfProt::MsgType, CStifTFwIfProt::EMsgReserve ) );
       
  3964     // Srcid. i.e. master id
       
  3965     User::LeaveIfError(
       
  3966         req->AppendId( slave->iMasterId ) );
       
  3967     // DstId, broacast id
       
  3968     User::LeaveIfError(
       
  3969         req->AppendId( slave->iSlaveDevId ) );
       
  3970     // Slave type
       
  3971     User::LeaveIfError( req->Append( type ) );
       
  3972 
       
  3973     User::LeaveIfError( 
       
  3974         iTestCombiner->TestModuleIf().RemoteSend( req->Message() ) );
       
  3975         
       
  3976     iState = ERunnerAllocate;
       
  3977     slave->iState = CSlaveInfo::ESlaveReserveSent;
       
  3978 
       
  3979     // Start timer    
       
  3980     iRemoteTimer->SetTimerActive( iTestCombiner->iRemoteTimeout );
       
  3981 
       
  3982     CleanupStack::PopAndDestroy( req );
       
  3983 
       
  3984     return EFalse;
       
  3985     
       
  3986     }
       
  3987     
       
  3988 /*
       
  3989 -------------------------------------------------------------------------------
       
  3990 
       
  3991      Class: CTestRunner
       
  3992 
       
  3993      Method: ExecuteFreeL
       
  3994 
       
  3995      Description: Executes free line
       
  3996   
       
  3997      Parameters:    CStifItemParser* aItem: in: script line
       
  3998      
       
  3999      Return Values: ETrue: continue script file execution
       
  4000                     EFalse: stop script file execution
       
  4001 
       
  4002      Errors/Exceptions: Leaves on error situations.
       
  4003 
       
  4004      Status: Draft
       
  4005     
       
  4006 -------------------------------------------------------------------------------
       
  4007 */
       
  4008 TBool CTestRunner::ExecuteFreeL( CStifItemParser* aItem )
       
  4009     {
       
  4010     _LIT( KErrMsgFreeSlaveNameNotDefined, "Free : Slave name is not defined" );
       
  4011     _LIT( KErrMsgFreeSlaveNotFound, "Free : Slave %S not found" );
       
  4012     _LIT( KErrMsgFreeSlaveReserved, "Free : Slave %S in illegal state %d, cannot be released" );
       
  4013     __TRACE( KMessage, (_L("Free")));
       
  4014     
       
  4015     TPtrC name;    
       
  4016     // Get slave name
       
  4017     TInt ret = aItem->GetNextString( name );
       
  4018     if( ret != KErrNone )
       
  4019         {
       
  4020         __TRACE( KError, (_L("Slave name was not given for free")));
       
  4021         iRunErrorMessage = KErrMsgFreeSlaveNameNotDefined;
       
  4022         User::Leave( KErrArgument );
       
  4023         }
       
  4024 
       
  4025     iTestCombiner->TestModuleIf().Printf( KPrintPriExec, KExecute, 
       
  4026         _L("Free %S"), &name );
       
  4027         
       
  4028     __TRACE( KMessage, (_L("Free %S"), &name ) );
       
  4029     
       
  4030     CSlaveInfo* slave = iTestCombiner->GetSlave( name );
       
  4031     if( slave == NULL )
       
  4032         {
       
  4033         __TRACE( KError, (_L("Slave %S not found"), &name ));
       
  4034         iRunErrorMessage.Format( KErrMsgFreeSlaveNotFound, &name );
       
  4035         User::Leave( KErrNotFound );
       
  4036         }
       
  4037     if( slave->iState != CSlaveInfo::ESlaveReserved )
       
  4038         {
       
  4039         __TRACE( KError, (_L("Slave %S in illegal state %d, cannot be released"), 
       
  4040             &name, slave->iState ));
       
  4041         iRunErrorMessage.Format( KErrMsgFreeSlaveReserved, &name, slave->iState );
       
  4042         User::Leave( KErrGeneral );
       
  4043         } 
       
  4044         
       
  4045     ExecuteFreeL( slave );
       
  4046     
       
  4047     return EFalse;
       
  4048     
       
  4049     }
       
  4050 
       
  4051 /*
       
  4052 -------------------------------------------------------------------------------
       
  4053 
       
  4054      Class: CTestRunner
       
  4055 
       
  4056      Method: ExecuteFreeL
       
  4057 
       
  4058      Description: Executes free line
       
  4059   
       
  4060      Parameters:    CSlaveInfo* aSlave: in: slave info
       
  4061      
       
  4062      Return Values: None
       
  4063 
       
  4064      Errors/Exceptions: Leaves on error situations.
       
  4065 
       
  4066      Status: Draft
       
  4067     
       
  4068 -------------------------------------------------------------------------------
       
  4069 */
       
  4070 void CTestRunner::ExecuteFreeL( CSlaveInfo* aSlave )
       
  4071     {    
       
  4072     
       
  4073     CRemoteTestCase* testCase = 
       
  4074         iTestCombiner->GetRemoteRunningTestOnSlave( aSlave->iSlaveDevId );
       
  4075           
       
  4076     if( testCase )
       
  4077         {
       
  4078         __TRACE( KMessage, 
       
  4079             (_L("Postpone free until testcases completed")));
       
  4080         // Test cases still running on slave,
       
  4081         // Free slave after test case has completed
       
  4082         testCase->iFreeSlave = ETrue;
       
  4083         return;
       
  4084         }
       
  4085     
       
  4086     CStifTFwIfProt* req = CStifTFwIfProt::NewL();
       
  4087     CleanupStack::PushL( req );
       
  4088     req->CreateL();
       
  4089     
       
  4090     // Release message
       
  4091     User::LeaveIfError( 
       
  4092         req->Append( CStifTFwIfProt::MsgType, CStifTFwIfProt::EMsgRelease ) );
       
  4093     // Srcid. i.e. master id
       
  4094     User::LeaveIfError( 
       
  4095         req->AppendId( aSlave->iMasterId ) );
       
  4096     // DstId is device broadcast
       
  4097     User::LeaveIfError( 
       
  4098         req->AppendId( SETID( DEVID( aSlave->iSlaveDevId ), 0 ) ) );
       
  4099     
       
  4100     User::LeaveIfError( 
       
  4101         iTestCombiner->TestModuleIf().RemoteSend( req->Message() ) );
       
  4102         
       
  4103     iState = ERunnerFree;
       
  4104     aSlave->iState = CSlaveInfo::ESlaveReleaseSent;
       
  4105 
       
  4106     // Start timer    
       
  4107     iRemoteTimer->SetTimerActive( iTestCombiner->iRemoteTimeout );
       
  4108    
       
  4109     CleanupStack::PopAndDestroy( req );
       
  4110     
       
  4111     }
       
  4112     
       
  4113 /*
       
  4114 -------------------------------------------------------------------------------
       
  4115 
       
  4116      Class: CTestRunner
       
  4117 
       
  4118      Method: ExecuteRemoteL
       
  4119 
       
  4120      Description: Executes remote line
       
  4121   
       
  4122      Parameters:    CStifItemParser* aItem: in: script line
       
  4123      
       
  4124      Return Values: ETrue: continue script file execution
       
  4125                     EFalse: stop script file execution
       
  4126 
       
  4127      Errors/Exceptions: Leaves on error situations.
       
  4128 
       
  4129      Status: Draft
       
  4130     
       
  4131 -------------------------------------------------------------------------------
       
  4132 */
       
  4133 TBool CTestRunner::ExecuteRemoteL( CStifItemParser* aItem )
       
  4134     {
       
  4135     _LIT( KErrMsgRemoteSlaveNameNotDefined, "Remote : Slave name is not defined" );
       
  4136     _LIT( KErrMsgRemoteSlaveNotFound, "Remore : Slave %S not found" );
       
  4137     _LIT( KErrMsgRemoteIllegalState, "Remote : Slave %S in illegal state %d, cannot send remote call" );
       
  4138     _LIT( KErrMsgRemoteCommandNotDefined, "Slave command name was not given for remote" );
       
  4139     TPtrC name;    
       
  4140     TPtrC command;    
       
  4141     // Get slave name
       
  4142     TInt ret = aItem->GetNextString( name );
       
  4143     if( ret != KErrNone )
       
  4144         {
       
  4145         __TRACE( KError, (_L("Slave name was not given for remote")));
       
  4146         iRunErrorMessage = KErrMsgRemoteSlaveNameNotDefined;
       
  4147         User::Leave( KErrArgument );
       
  4148         }
       
  4149         
       
  4150     __TRACE( KMessage, (_L("Remote command to %S"), &name));
       
  4151     
       
  4152     CSlaveInfo* slave = iTestCombiner->GetSlave( name );
       
  4153     if( slave == NULL )
       
  4154         {
       
  4155         __TRACE( KError, (_L("Slave %S not found"), &name ));
       
  4156         iRunErrorMessage.Format( KErrMsgRemoteSlaveNotFound, &name );
       
  4157         User::Leave( KErrArgument );
       
  4158         }
       
  4159     if( slave->iState != CSlaveInfo::ESlaveReserved )
       
  4160         {
       
  4161         __TRACE( KError, (_L("Slave %S in illegal state %d, cannot send remote call"), 
       
  4162             &name, slave->iState ));
       
  4163         iRunErrorMessage.Format( KErrMsgRemoteIllegalState, &name, slave->iState );
       
  4164         User::Leave( KErrNotReady );
       
  4165         } 
       
  4166         
       
  4167     // Get remote command name
       
  4168     ret = aItem->GetNextString( command );
       
  4169     if( ret != KErrNone )
       
  4170         {
       
  4171         __TRACE( KError, (_L("Slave command name was not given for remote")));
       
  4172         iRunErrorMessage = KErrMsgRemoteCommandNotDefined;
       
  4173         User::Leave( KErrArgument );
       
  4174         }
       
  4175 
       
  4176     iTestCombiner->TestModuleIf().Printf( KPrintPriExec, KExecute, 
       
  4177         _L("remote %S %S"), &name, &command );
       
  4178 
       
  4179     __TRACE( KPrint, (_L("remote %S %S"), &name, &command ) );
       
  4180 
       
  4181     // Parse command name
       
  4182     TInt key = TTCKeywords::Parse( command, TTCKeywords::Keyword );    
       
  4183     TBool continueTask = ETrue;
       
  4184     
       
  4185     switch( key )
       
  4186         {
       
  4187         // Test case starting
       
  4188         case TTCKeywords::ERun:
       
  4189             continueTask = ExecuteRemoteRunL( aItem, slave );
       
  4190             break;
       
  4191                    
       
  4192         // Event control cases
       
  4193         case TTCKeywords::ERequest:
       
  4194         case TTCKeywords::EWait:
       
  4195         case TTCKeywords::ERelease:
       
  4196             continueTask = ExecuteRemoteEventCtlL( aItem, slave, key );
       
  4197             break;
       
  4198 
       
  4199         case TTCKeywords::ESet:
       
  4200         case TTCKeywords::EUnset:
       
  4201             continueTask = ExecuteRemoteSetUnsetEventL(aItem, slave, key);
       
  4202 			break;
       
  4203         // asynchronous 'sendreceive'
       
  4204         case TTCKeywords::ESendReceive:
       
  4205             continueTask = ExecuteRemoteSendReceiveL( aItem, slave );
       
  4206             break;
       
  4207 
       
  4208         default:
       
  4209             // Some unknown remote command, forward as such 
       
  4210             continueTask = ExecuteRemoteUnknownL( aItem, slave, command );
       
  4211             break;
       
  4212         }
       
  4213     
       
  4214     return continueTask;
       
  4215     
       
  4216     }
       
  4217 
       
  4218 /*
       
  4219 -------------------------------------------------------------------------------
       
  4220 
       
  4221      Class: CTestRunner
       
  4222 
       
  4223      Method: ExecuteRemoteRunL
       
  4224 
       
  4225      Description: Handles remote run 
       
  4226   
       
  4227      Parameters:    CStifItemParser* aItem: in: script line
       
  4228                     CSlaveInfo* aSlave: in: slave info
       
  4229                     HBufC *aSetUnsetEvent: in: data needed for startInfo
       
  4230                     TInt aCaseNumber: in: data needed for startInfo
       
  4231      
       
  4232      Return Values: ETrue: continue script file execution
       
  4233                     EFalse: stop script file execution and wait response
       
  4234 
       
  4235      Errors/Exceptions: Leaves on error situations.
       
  4236 
       
  4237      Status: Draft
       
  4238     
       
  4239 -------------------------------------------------------------------------------
       
  4240 */
       
  4241 TBool CTestRunner::ExecuteRemoteRunL( CStifItemParser* aItem,
       
  4242                                         CSlaveInfo* aSlave,
       
  4243                                         HBufC *aSetUnsetEvent,
       
  4244                                         TInt aCaseNumber )
       
  4245     {
       
  4246     
       
  4247     CStifTFwIfProt* req = CStifTFwIfProt::NewL();
       
  4248     CleanupStack::PushL( req );
       
  4249     req->CreateL();
       
  4250     
       
  4251     CStartInfo* startInfo = CStartInfo::NewL();
       
  4252     CleanupStack::PushL( startInfo );
       
  4253     //if aSetUnsetEvent is given, then get start info from this argument
       
  4254     if(aSetUnsetEvent != NULL)
       
  4255     	{
       
  4256     	TBuf<10> tmpModuleName;
       
  4257     	tmpModuleName.Copy(_L("suevent"));
       
  4258     	startInfo->SetModuleNameL(tmpModuleName);
       
  4259     	startInfo->SetConfigL(*aSetUnsetEvent);
       
  4260     	startInfo->iCaseNum = aCaseNumber;
       
  4261     	}
       
  4262     else
       
  4263     	{
       
  4264     ParseRunParamsL( aItem, *startInfo );   
       
  4265 }
       
  4266     
       
  4267     if( iTestCombiner->GetTest( startInfo->iTestId ) )
       
  4268         {
       
  4269         /*        
       
  4270         __TRACE( KError, (_L("´Slave test running already with testid %S"), 
       
  4271             &startInfo->iTestId  ) );
       
  4272         */
       
  4273         User::Leave( KErrAlreadyExists );
       
  4274         }
       
  4275         
       
  4276     CRemoteTestCase* remote = 
       
  4277         CRemoteTestCase::NewL( iTestCombiner, 
       
  4278                                startInfo->iTestId,
       
  4279                                startInfo->iExpectedResult,
       
  4280                                startInfo->iCategory ); 
       
  4281     
       
  4282     CleanupStack::PushL( remote );
       
  4283         
       
  4284     // Remote message
       
  4285     User::LeaveIfError( 
       
  4286         req->Append( CStifTFwIfProt::MsgType, CStifTFwIfProt::EMsgRemote ) );
       
  4287     // Srcid. i.e. master id
       
  4288     User::LeaveIfError( req->AppendId( aSlave->iMasterId ) );
       
  4289     // DstId is device broadcast
       
  4290     User::LeaveIfError( 
       
  4291         req->AppendId( SETID( DEVID( aSlave->iSlaveDevId ), 0 ) ) );
       
  4292     // Run command
       
  4293     User::LeaveIfError( 
       
  4294         req->Append( CStifTFwIfProt::CmdType, CStifTFwIfProt::ECmdRun ) );
       
  4295     // Run parameters
       
  4296     User::LeaveIfError(
       
  4297         req->Append( CStifTFwIfProt::RunParams, 
       
  4298                 CStifTFwIfProt::ERunModule, 
       
  4299                 startInfo->iModule ) );
       
  4300     User::LeaveIfError(
       
  4301         req->Append( CStifTFwIfProt::RunParams, 
       
  4302                 CStifTFwIfProt::ERunTestcasenum, 
       
  4303                 startInfo->iCaseNum ));
       
  4304     if( startInfo->iIniFile.Length() > 0 )
       
  4305         {
       
  4306         // Initialization file
       
  4307         __TRACE( KMessage, (_L("ini: %S"), &startInfo->iIniFile ));     
       
  4308         User::LeaveIfError(
       
  4309             req->Append( CStifTFwIfProt::RunParams, 
       
  4310                     CStifTFwIfProt::ERunInifile, 
       
  4311                     startInfo->iIniFile ) );
       
  4312         }
       
  4313     if( startInfo->iConfig.Length() > 0 )
       
  4314         {
       
  4315         // Initialization file
       
  4316         __TRACE( KMessage, (_L("config: %S"), &startInfo->iConfig ));     
       
  4317         User::LeaveIfError(
       
  4318             req->Append( CStifTFwIfProt::RunParams, 
       
  4319                     CStifTFwIfProt::ERunTestcasefile, 
       
  4320                     startInfo->iConfig ));
       
  4321         } 
       
  4322     //Title (must be given between quotation marks in case of any spaces inside
       
  4323     if( startInfo->iTitle.Length() > 0 )
       
  4324         {
       
  4325         __TRACE(KMessage, (_L("title: %S"), &startInfo->iTitle));
       
  4326         TName tit;
       
  4327         tit.Format(_L("\"title=%S\""), &startInfo->iTitle);
       
  4328         User::LeaveIfError(req->Append(tit));
       
  4329         }
       
  4330     
       
  4331     User::LeaveIfError(
       
  4332         iTestCombiner->TestModuleIf().RemoteSend( req->Message() ) );
       
  4333         
       
  4334     remote->iRemoteState = CRemoteTestCase::ECaseRunSent;
       
  4335     remote->iSlaveId = aSlave->iSlaveDevId;
       
  4336     remote->StartL();
       
  4337     User::LeaveIfError( iTestCombiner->iTestCases.Append( remote ) );
       
  4338     if( iTestCombiner->iLoopIsUsed )
       
  4339         {
       
  4340         User::LeaveIfError( iTestCombiner->iLoopAllocationArray.Append( remote ) );
       
  4341         }
       
  4342     CleanupStack::Pop( remote );
       
  4343     
       
  4344     CleanupStack::PopAndDestroy( startInfo );
       
  4345     
       
  4346     iTestCombiner->iRunningTests++;
       
  4347     
       
  4348     // Start timer    
       
  4349     iRemoteTimer->SetTimerActive( iTestCombiner->iRemoteTimeout );
       
  4350 
       
  4351     iState = ERunnerRemote;
       
  4352 
       
  4353     CleanupStack::PopAndDestroy( req );
       
  4354 
       
  4355     return EFalse;
       
  4356          
       
  4357     }
       
  4358     
       
  4359     
       
  4360 /*
       
  4361 -------------------------------------------------------------------------------
       
  4362 
       
  4363      Class: CTestRunner
       
  4364 
       
  4365      Method: ExecuteRemoteTestCtlL
       
  4366 
       
  4367      Description: Handles remote testcase controlling
       
  4368   
       
  4369      Parameters:    CStifItemParser* aItem: in: script line
       
  4370                     CTestCase* aTestCase: in: test case
       
  4371                     TInt aCmd: in: remote command 
       
  4372      
       
  4373      Return Values: ETrue: continue script file execution
       
  4374                     EFalse: stop script file execution and wait response
       
  4375 
       
  4376      Errors/Exceptions: Leaves on error situations.
       
  4377 
       
  4378      Status: Draft
       
  4379     
       
  4380 -------------------------------------------------------------------------------
       
  4381 */
       
  4382 TBool CTestRunner::ExecuteRemoteTestCtlL( CStifItemParser* /* aItem */, 
       
  4383                                           CTestCase* aTestCase, 
       
  4384                                           TInt aCmd )
       
  4385     {
       
  4386     
       
  4387     CRemoteTestCase* caseInfo = ( CRemoteTestCase* ) aTestCase;
       
  4388     
       
  4389     CStifTFwIfProt* req = CStifTFwIfProt::NewL();
       
  4390     CleanupStack::PushL( req );
       
  4391     req->CreateL();
       
  4392     // Remote message
       
  4393     User::LeaveIfError( 
       
  4394         req->Append( CStifTFwIfProt::MsgType, CStifTFwIfProt::EMsgRemote ) );
       
  4395     // Srcid. i.e. master id
       
  4396     //req->AppendId( ( TUint32 ) this );
       
  4397     User::LeaveIfError(
       
  4398         req->AppendId( KRemoteProtocolMasterId ));
       
  4399     // DstId, i.e.slave id
       
  4400     User::LeaveIfError(
       
  4401         req->AppendId( caseInfo->iSlaveId ));
       
  4402     
       
  4403     switch( aCmd )
       
  4404         {
       
  4405         case TTCKeywords::EPause:
       
  4406             if( caseInfo->iRemoteState != CRemoteTestCase::ECaseRunning )
       
  4407                 {
       
  4408                 __TRACE( KError, (_L("Test case with testid %S not running"), 
       
  4409                     &aTestCase->TestId() ));
       
  4410                 User::Leave( KErrGeneral );
       
  4411                 }
       
  4412             // Pause command
       
  4413             User::LeaveIfError(
       
  4414                 req->Append( CStifTFwIfProt::CmdType, CStifTFwIfProt::ECmdPause ) );
       
  4415             caseInfo->iRemoteState = CRemoteTestCase::ECasePauseSent;
       
  4416             break;
       
  4417         case TTCKeywords::EResume:
       
  4418             if( caseInfo->iRemoteState != CRemoteTestCase::ECasePaused )
       
  4419                 {
       
  4420                 __TRACE( KError, (_L("Test case with testid %S not paused"), 
       
  4421                     &aTestCase->TestId() ));
       
  4422                 User::Leave( KErrGeneral );
       
  4423                 }
       
  4424             // Resume command
       
  4425             User::LeaveIfError( 
       
  4426                 req->Append( CStifTFwIfProt::CmdType, CStifTFwIfProt::ECmdResume ));
       
  4427             caseInfo->iRemoteState = CRemoteTestCase::ECaseResumeSent;
       
  4428             break;            
       
  4429         case TTCKeywords::ECancel:
       
  4430             if( ( caseInfo->iRemoteState != CRemoteTestCase::ECaseRunning ) &&
       
  4431                 ( caseInfo->iRemoteState != CRemoteTestCase::ECasePaused ) )
       
  4432                 {
       
  4433                 __TRACE( KError, (_L("Test case with testid %S not running"),
       
  4434                     &aTestCase->TestId() ));
       
  4435                 User::Leave( KErrGeneral );
       
  4436                 }
       
  4437             // Cancel command
       
  4438             User::LeaveIfError( 
       
  4439                 req->Append( CStifTFwIfProt::CmdType, CStifTFwIfProt::ECmdCancel ));    
       
  4440             caseInfo->iRemoteState = CRemoteTestCase::ECaseCancelSent;
       
  4441             break;      
       
  4442         case TTCKeywords::EComplete:
       
  4443             if( caseInfo->iRemoteState == CRemoteTestCase::ECaseCompleted )
       
  4444                 {
       
  4445                 __TRACE( KError, (_L("Test case with testid %S already completed"), 
       
  4446                     &aTestCase->TestId() ));
       
  4447                 CleanupStack::PopAndDestroy( req );
       
  4448                 return ETrue;
       
  4449                 }
       
  4450             else
       
  4451                 {
       
  4452                 iTestCombiner->iWaitTestCase = aTestCase->TestId();
       
  4453                 CleanupStack::PopAndDestroy( req );
       
  4454                 return EFalse;
       
  4455                 }    
       
  4456         default:
       
  4457             // Should never come here
       
  4458             User::Leave( KErrGeneral );            
       
  4459         }
       
  4460     
       
  4461     User::LeaveIfError( 
       
  4462         iTestCombiner->TestModuleIf().RemoteSend( req->Message() ) );
       
  4463 
       
  4464     // Start timer    
       
  4465     iRemoteTimer->SetTimerActive( iTestCombiner->iRemoteTimeout );
       
  4466             
       
  4467     iState = ERunnerRemote;
       
  4468     
       
  4469     CleanupStack::PopAndDestroy( req );
       
  4470     
       
  4471     return EFalse;
       
  4472    
       
  4473     }
       
  4474 
       
  4475 /*
       
  4476 -------------------------------------------------------------------------------
       
  4477 
       
  4478      Class: CTestRunner
       
  4479 
       
  4480      Method: ExecuteRemoteEventCtlL
       
  4481 
       
  4482      Description: Handles remote event controlling
       
  4483   
       
  4484      Parameters:    CStifItemParser* aItem: in: script line
       
  4485                     CSlaveInfo* aSlave: in: slave info
       
  4486                     TInt aCmd: in: remote command 
       
  4487      
       
  4488      Return Values: ETrue: continue script file execution
       
  4489                     EFalse: stop script file execution and wait response
       
  4490 
       
  4491      Errors/Exceptions: Leaves on error situations.
       
  4492 
       
  4493      Status: Draft
       
  4494     
       
  4495 -------------------------------------------------------------------------------
       
  4496 */
       
  4497 TBool CTestRunner::ExecuteRemoteEventCtlL( CStifItemParser* aItem, 
       
  4498                                            CSlaveInfo* aSlave, 
       
  4499                                            TInt aCmd )
       
  4500     {
       
  4501     
       
  4502     TPtrC eventName;
       
  4503     // Get event name
       
  4504     TInt ret = aItem->GetNextString( eventName );
       
  4505     if( ret != KErrNone )
       
  4506         {
       
  4507         __TRACE( KError, (_L("Event name was not given for remote")));
       
  4508         User::Leave( KErrArgument );
       
  4509         }
       
  4510     
       
  4511     if( aCmd == TTCKeywords::EWait )
       
  4512         {
       
  4513         TEventTc* event = aSlave->GetEvent( eventName );
       
  4514         if( event == NULL )
       
  4515             {
       
  4516             __TRACE( KError, (_L("Waited event %S not requested"), 
       
  4517                 &eventName  ) );
       
  4518             User::Leave( KErrNotFound );
       
  4519             }
       
  4520         iState = ERunnerRunning;
       
  4521         SetActive();
       
  4522         event->WaitEvent( iStatus );     
       
  4523         // Execution continue if waited event is set or after it is set       
       
  4524         return EFalse;
       
  4525         }
       
  4526     
       
  4527     CStifTFwIfProt* req = CStifTFwIfProt::NewL();
       
  4528     CleanupStack::PushL( req );
       
  4529     
       
  4530     req->CreateL();
       
  4531     // Remote message
       
  4532     User::LeaveIfError( 
       
  4533         req->Append( CStifTFwIfProt::MsgType, CStifTFwIfProt::EMsgRemote ));
       
  4534     // Srcid. i.e. master id
       
  4535     User::LeaveIfError( req->AppendId( aSlave->iMasterId ) );
       
  4536     // DstId, i.e.slave device id
       
  4537     User::LeaveIfError( req->AppendId( aSlave->iSlaveDevId ) );
       
  4538            
       
  4539     switch( aCmd )
       
  4540         {       
       
  4541         // Event control cases
       
  4542         case TTCKeywords::ERequest:
       
  4543             {
       
  4544             TEventTc* event = aSlave->GetEvent( eventName );
       
  4545             if( event != NULL )
       
  4546                 {
       
  4547                 __TRACE( KError, (_L("Event %S already requested"), 
       
  4548                     &eventName  ) );
       
  4549                 User::Leave( KErrNotFound );
       
  4550                 }
       
  4551             event = new( ELeave ) TEventTc( (TName&)eventName, 
       
  4552                                              iTestCombiner->iLog );
       
  4553             CleanupStack::PushL( event );
       
  4554             User::LeaveIfError( aSlave->iEvents.Append( event ) );
       
  4555             CleanupStack::Pop( event );
       
  4556             // Request event
       
  4557             User::LeaveIfError( 
       
  4558                 req->Append( CStifTFwIfProt::CmdType, CStifTFwIfProt::ECmdRequest ));  
       
  4559             }
       
  4560             break;
       
  4561                         
       
  4562         case TTCKeywords::ERelease:
       
  4563             {
       
  4564             TEventIf* event = NULL;
       
  4565             TInt count = aSlave->iEvents.Count();
       
  4566             TInt i = 0;
       
  4567             for( ; i < count; i++ )
       
  4568                 {
       
  4569                 if( aSlave->iEvents[i]->Name() == eventName )
       
  4570                     {
       
  4571                     event = aSlave->iEvents[i];
       
  4572                     break;
       
  4573                     }
       
  4574                 }
       
  4575             if( event == NULL )
       
  4576                 {
       
  4577                 __TRACE( KError, (_L("Event not found %S"), 
       
  4578                     &eventName  ) );
       
  4579                 User::Leave( KErrNotFound );
       
  4580                 }
       
  4581                                                   
       
  4582             aSlave->iEvents.Remove(i);
       
  4583             delete event;
       
  4584             // Release event
       
  4585             User::LeaveIfError(
       
  4586                 req->Append( CStifTFwIfProt::CmdType, CStifTFwIfProt::ECmdRelease ));  
       
  4587             }
       
  4588             break;
       
  4589         
       
  4590         case TTCKeywords::ESet:
       
  4591         	{
       
  4592         		__TRACE( KPrint, (_L("JIRA51 CTestRunner::ExecuteRemoteEventCtlL case ESet")));
       
  4593 	            User::LeaveIfError(req->Append(CStifTFwIfProt::CmdType, CStifTFwIfProt::ECmdSetEvent));
       
  4594         		break;
       
  4595         	}
       
  4596        	case TTCKeywords::EUnset:
       
  4597         	{
       
  4598         		__TRACE( KPrint, (_L("JIRA51 CTestRunner::ExecuteRemoteEventCtlL case EUnset")));
       
  4599 	            User::LeaveIfError(req->Append(CStifTFwIfProt::CmdType, CStifTFwIfProt::ECmdUnsetEvent));
       
  4600         		break;
       
  4601         	}
       
  4602         default:
       
  4603              // Should never come here
       
  4604             User::Leave( KErrGeneral );            
       
  4605         }
       
  4606         
       
  4607     // Event name
       
  4608     User::LeaveIfError( req->Append( eventName ) );  
       
  4609     
       
  4610 	if(aCmd == TTCKeywords::ESet)
       
  4611 		{
       
  4612  		TPtrC stateEvent;
       
  4613 		TInt ret = aItem->GetNextString(stateEvent);
       
  4614 		if(ret == KErrNotFound) //indication event - add indicate keyword to message
       
  4615 			{
       
  4616 	            User::LeaveIfError(req->Append(CStifTFwIfProt::EventType, TEventIf::EIndication));
       
  4617 			}
       
  4618 		else if(ret == KErrNone) //possibly state event
       
  4619 			{
       
  4620 			if(stateEvent.Compare(_L("state")) == 0) //state event - add state keyword to message
       
  4621 				{
       
  4622 	            User::LeaveIfError(req->Append(CStifTFwIfProt::EventType, TEventIf::EState));
       
  4623 				}
       
  4624 			else //syntax error in the line
       
  4625 				{
       
  4626 		        __TRACE(KError, (_L("Unknown keyword %S"), &stateEvent));
       
  4627 				}
       
  4628 			}
       
  4629 		else //syntax error in the line
       
  4630 			{
       
  4631 	        __TRACE(KError, (_L("Unknown keyword (2) %S"), &stateEvent));
       
  4632 			}
       
  4633 		}
       
  4634     User::LeaveIfError( 
       
  4635         iTestCombiner->TestModuleIf().RemoteSend( req->Message() ) );
       
  4636                 
       
  4637     // Start timer    
       
  4638     iRemoteTimer->SetTimerActive( iTestCombiner->iRemoteTimeout );
       
  4639 
       
  4640     iState = ERunnerRemote;
       
  4641     
       
  4642     CleanupStack::PopAndDestroy( req );
       
  4643     
       
  4644     return EFalse;
       
  4645     
       
  4646     }    
       
  4647 
       
  4648 TBool CTestRunner::ExecuteRemoteSetUnsetEventL(CStifItemParser* aItem,
       
  4649                                                CSlaveInfo* aSlave,
       
  4650                                                TInt aCmd)
       
  4651 	{
       
  4652 	TPtrC eventName;
       
  4653 	// Get event name
       
  4654 	TInt ret = aItem->GetNextString(eventName);
       
  4655 	if(ret != KErrNone)
       
  4656 		{
       
  4657 		__TRACE(KError, (_L("Event name was not given for remote")));
       
  4658 		User::Leave(KErrArgument);
       
  4659 		}
       
  4660 	// Check if this is a state set, indication set, or unset command
       
  4661 	TInt caseNumber = -1;
       
  4662 	if(aCmd == TTCKeywords::ESet)
       
  4663 		{
       
  4664  		TPtrC stateEvent;
       
  4665 		TInt ret = aItem->GetNextString(stateEvent);
       
  4666 		if(ret == KErrNotFound) //indication event - add indicate keyword to message
       
  4667 			{
       
  4668 			caseNumber = 1;
       
  4669 			}
       
  4670 		else if(ret == KErrNone) //possibly state event
       
  4671 			{
       
  4672 			if(stateEvent.Compare(_L("state")) == 0) //state event - add state keyword to message
       
  4673 				{
       
  4674 				caseNumber = 0;
       
  4675 				}
       
  4676 			else //syntax error in the line
       
  4677 				{
       
  4678 				__TRACE(KError, (_L("Unknown keyword %S"), &stateEvent));
       
  4679 				}
       
  4680 			}
       
  4681 		else //syntax error in the line
       
  4682 			{
       
  4683 			}
       
  4684 		}
       
  4685 	else //TTCKeyword::EUnset
       
  4686 		{
       
  4687 		caseNumber = 2;
       
  4688 		}
       
  4689 
       
  4690 	if(caseNumber == -1)
       
  4691 		{
       
  4692 			__TRACE(KError, _L("Should never occur"));
       
  4693 		}
       
  4694 	// Build new descriptor with command to run hardcoded suevent test case on remote phone
       
  4695 	HBufC* cmd = HBufC::NewL(100);
       
  4696 	CleanupStack::PushL(cmd);
       
  4697 	TPtr cmdPtr(cmd->Des());
       
  4698 	cmdPtr.Copy(eventName);
       
  4699 	// Run remotely test case
       
  4700 RDebug::Print(_L("CTestRunner::ExecuteRemoteSetUnsetEventL calling ExecuteRemoteRun"));
       
  4701 	TBool retval = ExecuteRemoteRunL(aItem, aSlave, cmd, caseNumber);
       
  4702 	// Clean data
       
  4703 	CleanupStack::PopAndDestroy(cmd);
       
  4704 RDebug::Print(_L("CTestRunner::ExecuteRemoteSetUnsetEventL end"));
       
  4705 	return retval;
       
  4706     }
       
  4707 /*
       
  4708 -------------------------------------------------------------------------------
       
  4709 
       
  4710      Class: CTestRunner
       
  4711 
       
  4712      Method: ExecuteRemoteSendReceiveL
       
  4713 
       
  4714      Description: Handles asynchronous remote sendreceive controlling
       
  4715   
       
  4716      Parameters:    CStifItemParser* aItem: in: script line
       
  4717                     CSlaveInfo* aSlave: in: slave info
       
  4718 
       
  4719      Return Values: ETrue: continue script file execution
       
  4720                     EFalse: stop script file execution and wait response
       
  4721 
       
  4722      Errors/Exceptions: Leaves on error situations.
       
  4723 
       
  4724      Status: Draft
       
  4725     
       
  4726 -------------------------------------------------------------------------------
       
  4727 */
       
  4728 TBool CTestRunner::ExecuteRemoteSendReceiveL( CStifItemParser* aItem, 
       
  4729                                            CSlaveInfo* aSlave )
       
  4730     {
       
  4731     CStifTFwIfProt* req = CStifTFwIfProt::NewL();
       
  4732     CleanupStack::PushL( req );
       
  4733     
       
  4734     // Create CRemoteSendReceive object for taking sendreceive information to
       
  4735     // save for later use.
       
  4736     CRemoteSendReceive* remoteSendReceive = 
       
  4737         CRemoteSendReceive::NewL( iTestCombiner );
       
  4738     
       
  4739     CleanupStack::PushL( remoteSendReceive );
       
  4740 
       
  4741     req->CreateL();
       
  4742     // Remote message
       
  4743     User::LeaveIfError(
       
  4744         req->Append( CStifTFwIfProt::MsgType, CStifTFwIfProt::EMsgRemote ) );
       
  4745     // Srcid. i.e. master id
       
  4746     User::LeaveIfError( req->AppendId( aSlave->iMasterId ) );
       
  4747     // DstId, i.e.slave device id
       
  4748     User::LeaveIfError( req->AppendId( aSlave->iSlaveDevId ) );
       
  4749     // Run command
       
  4750     User::LeaveIfError( req->Append( 
       
  4751         CStifTFwIfProt::CmdType, CStifTFwIfProt::ECmdSendReceive ) );
       
  4752     // asynchronous sendreceive's parameters    
       
  4753     TPtrC tmp;    
       
  4754 
       
  4755     while( aItem->GetNextString( tmp ) == KErrNone )
       
  4756         {        
       
  4757         // Append parameters
       
  4758         User::LeaveIfError( req->Append( tmp ) );  
       
  4759         }
       
  4760     
       
  4761     User::LeaveIfError( 
       
  4762         iTestCombiner->TestModuleIf().RemoteSend( req->Message() ) );
       
  4763 
       
  4764     remoteSendReceive->iRemoteState = CRemoteSendReceive::ECaseSend;
       
  4765     remoteSendReceive->iSlaveId = aSlave->iSlaveDevId;
       
  4766 
       
  4767     // Take CRemoteSendReceive object to save in array. This can be used in
       
  4768     // TestCombiner when handling responses.
       
  4769     User::LeaveIfError( 
       
  4770             iTestCombiner->iSendReceive.Append( remoteSendReceive ) );
       
  4771     if( iTestCombiner->iLoopIsUsed )
       
  4772         {
       
  4773         User::LeaveIfError( 
       
  4774             iTestCombiner->iLoopAllocationArray.Append( remoteSendReceive ) );
       
  4775         }
       
  4776     CleanupStack::Pop( remoteSendReceive );
       
  4777 
       
  4778     // Start timer    
       
  4779     iRemoteTimer->SetTimerActive( iTestCombiner->iRemoteTimeout );
       
  4780 
       
  4781     iState = ERunnerRemote;
       
  4782     
       
  4783     CleanupStack::PopAndDestroy( req );
       
  4784     
       
  4785     // Return EFalse=>start waiting response...
       
  4786     return EFalse;
       
  4787 
       
  4788     }
       
  4789 
       
  4790 /*
       
  4791 -------------------------------------------------------------------------------
       
  4792 
       
  4793      Class: CTestRunner
       
  4794 
       
  4795      Method: ExecuteRemoteUnknownL
       
  4796 
       
  4797      Description: Forwards messages as such
       
  4798   
       
  4799      Parameters:    CStifItemParser* aItem: in: script line
       
  4800                     CSlaveInfo* aSlave: in: slave info
       
  4801                     TInt aCmd: in: remote command 
       
  4802      
       
  4803      Return Values: ETrue: continue script file execution
       
  4804                     EFalse: stop script file execution and wait response
       
  4805 
       
  4806      Errors/Exceptions: Leaves on error situations.
       
  4807 
       
  4808      Status: Draft
       
  4809     
       
  4810 -------------------------------------------------------------------------------
       
  4811 */
       
  4812 TBool CTestRunner::ExecuteRemoteUnknownL( CStifItemParser* aItem, 
       
  4813                                           CSlaveInfo* aSlave,
       
  4814                                           TDesC& aCommand )
       
  4815     {
       
  4816     
       
  4817     CStifTFwIfProt* req = CStifTFwIfProt::NewL();
       
  4818     CleanupStack::PushL( req );
       
  4819     
       
  4820     req->CreateL();
       
  4821     // Remote message
       
  4822     User::LeaveIfError(
       
  4823         req->Append( CStifTFwIfProt::MsgType, CStifTFwIfProt::EMsgRemote ) );
       
  4824     // Srcid. i.e. master id
       
  4825     User::LeaveIfError( req->AppendId( aSlave->iMasterId ) );
       
  4826     // DstId, i.e.slave device id
       
  4827     User::LeaveIfError( req->AppendId( aSlave->iSlaveDevId ) );
       
  4828     
       
  4829     // Append command name
       
  4830     User::LeaveIfError( req->Append( aCommand ) );
       
  4831     
       
  4832     TPtrC tmp;         
       
  4833     while( aItem->GetNextString( tmp ) == KErrNone )
       
  4834         {        
       
  4835         // Append parameters
       
  4836         User::LeaveIfError( req->Append( tmp ) );  
       
  4837         }
       
  4838     
       
  4839     User::LeaveIfError( 
       
  4840         iTestCombiner->TestModuleIf().RemoteSend( req->Message() ) );
       
  4841                 
       
  4842     // Start timer    
       
  4843     iRemoteTimer->SetTimerActive( iTestCombiner->iRemoteTimeout );
       
  4844 
       
  4845     iState = ERunnerRemote;
       
  4846     
       
  4847     CleanupStack::PopAndDestroy( req );
       
  4848     
       
  4849     return EFalse;
       
  4850     
       
  4851     }    
       
  4852 /*
       
  4853 -------------------------------------------------------------------------------
       
  4854 
       
  4855      Class: CTestRunner
       
  4856 
       
  4857      Method: ReceiveResponseL
       
  4858 
       
  4859      Description: Handles responce received from slave
       
  4860   
       
  4861      Parameters:    TDesC& aMsg: in: message
       
  4862      
       
  4863      Return Values: ETrue: continue script file execution
       
  4864                     EFalse: stop script file execution
       
  4865 
       
  4866      Errors/Exceptions: Leaves on error situations.
       
  4867 
       
  4868      Status: Draft
       
  4869     
       
  4870 -------------------------------------------------------------------------------
       
  4871 */
       
  4872 TBool CTestRunner::ReceiveResponseL( TDesC& aMsg )
       
  4873     {
       
  4874     __TRACE( KMessage, (_L("ReceiveResponse")));
       
  4875     
       
  4876     iRemoteTimer->Cancel();
       
  4877     
       
  4878     CStifTFwIfProt* msg = CStifTFwIfProt::NewL();
       
  4879     CleanupStack::PushL( msg );
       
  4880     TRAPD( err, msg->SetL( aMsg ); );
       
  4881     if( err != KErrNone )
       
  4882         {
       
  4883         __TRACE( KError, (_L("Response parsing failed")));
       
  4884         User::Leave( err );
       
  4885         }
       
  4886     
       
  4887     // Check protocol identifiers
       
  4888     if( ( msg->SrcDevId() == 0 ) ||
       
  4889         ( msg->DstDevId() == 0 ) ||
       
  4890         ( msg->DstTestId() == 0 ) )
       
  4891         {
       
  4892         __TRACE( KError, (_L("Illegal deviceid received")));
       
  4893         User::Leave( KErrGeneral );
       
  4894         }
       
  4895     
       
  4896     // This is master, cannot receive anything else but responses
       
  4897     if( msg->iMsgType != CStifTFwIfProt::EMsgResponse )
       
  4898         {
       
  4899         __TRACE( KError, (_L("Illegal message received %d"), 
       
  4900             msg->iMsgType ));
       
  4901         User::Leave( KErrGeneral );        
       
  4902         }
       
  4903         
       
  4904     TBool continueTask = ETrue;
       
  4905     switch( msg->iRespType )
       
  4906         {
       
  4907         case CStifTFwIfProt::EMsgReserve:
       
  4908             {
       
  4909             __TRACE( KMessage, (_L("ReceiveResponse Reserve")));
       
  4910             if( iState != ERunnerAllocate )
       
  4911                 {
       
  4912                 __TRACE( KError, (_L("Response reserve received in illegal state %d"), 
       
  4913                     iState ));
       
  4914                 User::Leave( KErrGeneral );    
       
  4915                 }
       
  4916             // Check protocol Src test id
       
  4917             if( msg->SrcTestId() != 0 )
       
  4918                 {
       
  4919                 __TRACE( KError, (_L("Illegal deviceid received")));
       
  4920                 User::Leave( KErrGeneral );
       
  4921                 }
       
  4922             if( msg->iResult != KErrNone )
       
  4923                 {
       
  4924                 __TRACE( KError, (_L("Response with error %d"), msg->iResult ));
       
  4925                 User::Leave( msg->iResult );
       
  4926                 }
       
  4927             CSlaveInfo* slave = NULL;
       
  4928             TInt count = iTestCombiner->iSlaveArray.Count();
       
  4929             for( TInt index = 0; index < count; index++ )
       
  4930                 {
       
  4931                 slave = iTestCombiner->iSlaveArray[index];
       
  4932                 if( ( slave->iSlaveDevId == 0 ) &&
       
  4933                     ( slave->iState ==  CSlaveInfo::ESlaveReserveSent ) )
       
  4934                     {
       
  4935                     break;
       
  4936                     }
       
  4937                 slave = NULL;
       
  4938                 }
       
  4939             if( slave == NULL )
       
  4940                 {
       
  4941                 User::Leave( KErrNotFound );
       
  4942                 }
       
  4943             slave->iSlaveDevId = msg->SrcId();
       
  4944             slave->iState = CSlaveInfo::ESlaveReserved;
       
  4945             __TRACE( KMessage, (_L("Slave allocated succesfully, continue execution")));
       
  4946             }
       
  4947             break;
       
  4948         case CStifTFwIfProt::EMsgRelease:
       
  4949             {
       
  4950             __TRACE( KMessage, (_L("ReceiveResponse Release")));
       
  4951             if( iState != ERunnerFree )
       
  4952                 {
       
  4953                 __TRACE( KError, (_L("Response release received in illegal state %d"), 
       
  4954                     iState ));
       
  4955                 User::Leave( KErrGeneral );    
       
  4956                 }
       
  4957             // Check protocol Src test id
       
  4958             if( msg->SrcTestId() != 0 )
       
  4959                 {
       
  4960                 __TRACE( KError, (_L("Illegal deviceid received")));
       
  4961                 User::Leave( KErrGeneral );
       
  4962                 }                
       
  4963             if( msg->iResult != KErrNone )
       
  4964                 {
       
  4965                 __TRACE( KError, (_L("Response with error %d"), msg->iResult ));
       
  4966                 User::Leave( msg->iResult );
       
  4967                 }
       
  4968 
       
  4969             CSlaveInfo* slave = iTestCombiner->GetSlave( msg->SrcId() );
       
  4970             if( slave == NULL )
       
  4971                 {
       
  4972                 User::Leave( KErrNotFound );
       
  4973                 }
       
  4974             slave->iState = CSlaveInfo::ESlaveReleased;
       
  4975             __TRACE( KMessage, (_L("Slave freed succesfully, continue execution")));
       
  4976             }            
       
  4977             break;
       
  4978         case CStifTFwIfProt::EMsgRemote:
       
  4979             {         
       
  4980             __TRACE( KMessage, (_L("ReceiveResponse Remote")));
       
  4981             switch( msg->iCmdType )
       
  4982                 {
       
  4983                 case CStifTFwIfProt::ECmdRun:
       
  4984                     continueTask = ReceiveResponseRunL( *msg );
       
  4985                     break;
       
  4986                 case CStifTFwIfProt::ECmdPause:
       
  4987                 case CStifTFwIfProt::ECmdResume:
       
  4988                 case CStifTFwIfProt::ECmdCancel:
       
  4989                     continueTask = ReceiveResponseTestCtlL( *msg );
       
  4990                     break;
       
  4991                 case CStifTFwIfProt::ECmdRequest:
       
  4992                 case CStifTFwIfProt::ECmdRelease:
       
  4993                 case CStifTFwIfProt::ECmdSetEvent:
       
  4994                 case CStifTFwIfProt::ECmdUnsetEvent:
       
  4995                     continueTask = ReceiveResponseEventCtlL( *msg );                    
       
  4996                     break;
       
  4997                 case CStifTFwIfProt::ECmdSendReceive:
       
  4998                     continueTask = ReceiveResponseSendReceiveL( *msg );                    
       
  4999                     break;
       
  5000                 default:
       
  5001                     continueTask = ReceiveResponseUnknownL( *msg );                    
       
  5002                     break;
       
  5003                 }
       
  5004             }            
       
  5005             break;
       
  5006         default:
       
  5007             User::Leave( KErrGeneral );
       
  5008         } 
       
  5009                
       
  5010     
       
  5011     CleanupStack::PopAndDestroy( msg );    
       
  5012     return continueTask;
       
  5013     
       
  5014     }
       
  5015 
       
  5016 /*
       
  5017 -------------------------------------------------------------------------------
       
  5018 
       
  5019      Class: CTestRunner
       
  5020 
       
  5021      Method: ReceiveResponseRunL
       
  5022 
       
  5023      Description: Handles response for run received from slave
       
  5024   
       
  5025      Parameters:    CStifTFwIfProt& aMsg: in: protocol message parser
       
  5026      
       
  5027      Return Values: ETrue: continue script file execution
       
  5028                     EFalse: stop script file execution
       
  5029 
       
  5030      Errors/Exceptions: Leaves on error situations.
       
  5031 
       
  5032      Status: Draft
       
  5033     
       
  5034 -------------------------------------------------------------------------------
       
  5035 */    
       
  5036 TBool CTestRunner::ReceiveResponseRunL( CStifTFwIfProt& aMsg )
       
  5037     {
       
  5038 
       
  5039     TPtrC tmp = CStifTFwIfProt::RunStatus(aMsg.iRunStatus); 
       
  5040     __TRACE( KMessage, (_L("ReceiveResponse Remote Run %S"), &tmp ));
       
  5041 
       
  5042     TBool continueTask = ETrue; 
       
  5043     switch( aMsg.iRunStatus )
       
  5044         {
       
  5045         case CStifTFwIfProt::ERunStarted:
       
  5046             {
       
  5047             // Locate testcase    
       
  5048             CRemoteTestCase* tcase = 
       
  5049                 iTestCombiner->GetRemoteTestRunSent( GETDEVID( aMsg.SrcId() ) );
       
  5050             if( tcase == NULL ) 
       
  5051                 {
       
  5052                 __TRACE( KError, (_L("Testcase not found")));
       
  5053                 User::Leave( KErrNotFound );        
       
  5054                 }
       
  5055             tcase->iSlaveId = aMsg.SrcId();
       
  5056 
       
  5057             tcase->iRemoteState = CRemoteTestCase::ECaseRunning;
       
  5058             }
       
  5059             break;
       
  5060         case CStifTFwIfProt::ERunError:
       
  5061         case CStifTFwIfProt::ERunReady:
       
  5062             {
       
  5063             // Locate testcase    
       
  5064             CRemoteTestCase* tcase = 
       
  5065                 iTestCombiner->GetRunningRemoteTest( aMsg.SrcId() );
       
  5066             if( tcase == NULL ) 
       
  5067                 {
       
  5068                 __TRACE( KError, (_L("Testcase not found")));
       
  5069                 User::Leave( KErrNotFound );        
       
  5070                 }
       
  5071 
       
  5072             switch( aMsg.iResultCategory )
       
  5073                 {
       
  5074                 case CStifTFwIfProt::EResultNormal:
       
  5075                     tcase->iResult.iCaseExecutionResultType = 
       
  5076                         TFullTestResult::ECaseExecuted;
       
  5077                     tcase->iResult.iTestResult.iResult = aMsg.iResult;
       
  5078                     tcase->iResult.iCaseExecutionResultCode = 0;
       
  5079                     break;
       
  5080                 case CStifTFwIfProt::EResultPanic:
       
  5081                     tcase->iResult.iCaseExecutionResultType = 
       
  5082                         TFullTestResult::ECasePanic;
       
  5083                     tcase->iResult.iTestResult.iResult = KErrGeneral;
       
  5084                     tcase->iResult.iCaseExecutionResultCode = aMsg.iResult;
       
  5085                     break;
       
  5086                 case CStifTFwIfProt::EResultException:
       
  5087                     tcase->iResult.iCaseExecutionResultType = 
       
  5088                         TFullTestResult::ECaseException;
       
  5089                     tcase->iResult.iTestResult.iResult = KErrGeneral;
       
  5090                     tcase->iResult.iCaseExecutionResultCode = aMsg.iResult;
       
  5091                     break;
       
  5092                 case CStifTFwIfProt::EResultTimeout:
       
  5093                     tcase->iResult.iCaseExecutionResultType = 
       
  5094                         TFullTestResult::ECaseTimeout;                
       
  5095                     tcase->iResult.iTestResult.iResult = KErrGeneral;
       
  5096                     tcase->iResult.iCaseExecutionResultCode = aMsg.iResult;
       
  5097                     break;
       
  5098                 case CStifTFwIfProt::EResultLeave:
       
  5099                     tcase->iResult.iCaseExecutionResultType = 
       
  5100                         TFullTestResult::ECaseLeave;                
       
  5101                     tcase->iResult.iTestResult.iResult = KErrGeneral;
       
  5102                     tcase->iResult.iCaseExecutionResultCode = aMsg.iResult;
       
  5103                     break;
       
  5104                 default:
       
  5105                     User::Leave( KErrGeneral );
       
  5106                 }
       
  5107                     
       
  5108             if( ( tcase->iRemoteState == CRemoteTestCase::ECaseCancelled ) ||
       
  5109                 ( tcase->iRemoteState == CRemoteTestCase::ECaseRunSent ) )
       
  5110                 {
       
  5111                 // Complete for cancelled testcase or error for run request, 
       
  5112                 // set runner active again
       
  5113                 continueTask = ETrue; 
       
  5114                 }
       
  5115             else
       
  5116                 {
       
  5117                 // Continued from Complete in state ECaseRunning
       
  5118                 continueTask = EFalse; 
       
  5119                 }
       
  5120                 
       
  5121             tcase->iRemoteState = CRemoteTestCase::ECaseCompleted;
       
  5122 
       
  5123         __TRACE( KMessage, (_L("ReceiveResponse Remote Run rq comp")));
       
  5124             
       
  5125             TRequestStatus* rs = &tcase->iStatus;
       
  5126             // Complete testcase
       
  5127             User::RequestComplete( rs, KErrNone );
       
  5128             
       
  5129             }
       
  5130             break;
       
  5131         default:
       
  5132             // Should never come here
       
  5133             User::Leave( KErrGeneral );    
       
  5134         }        
       
  5135     
       
  5136     return continueTask;
       
  5137     
       
  5138     }
       
  5139     
       
  5140 /*
       
  5141 -------------------------------------------------------------------------------
       
  5142 
       
  5143      Class: CTestRunner
       
  5144 
       
  5145      Method: ReceiveResponseTestCtlL
       
  5146 
       
  5147      Description: Handles responses for test control commands 
       
  5148         received from slave
       
  5149   
       
  5150      Parameters:    CStifTFwIfProt& aMsg: in: protocol message parser
       
  5151      
       
  5152      Return Values: ETrue: continue script file execution
       
  5153                     EFalse: stop script file execution
       
  5154 
       
  5155      Errors/Exceptions: Leaves on error situations.
       
  5156 
       
  5157      Status: Draft
       
  5158     
       
  5159 -------------------------------------------------------------------------------
       
  5160 */    
       
  5161 TBool CTestRunner::ReceiveResponseTestCtlL( CStifTFwIfProt& aMsg )
       
  5162     {
       
  5163 
       
  5164     if( aMsg.iResult != KErrNone )
       
  5165         {
       
  5166         __TRACE( KError, (_L("Response with error %d"), aMsg.iResult ));
       
  5167         User::Leave( aMsg.iResult );
       
  5168         }
       
  5169     
       
  5170     // Locate testcase    
       
  5171     CRemoteTestCase* tcase = iTestCombiner->GetRemoteTest( aMsg.SrcId() );
       
  5172     if( tcase == NULL ) 
       
  5173         {
       
  5174         __TRACE( KError, (_L("Testcase not found")));
       
  5175         User::Leave( KErrNotFound );        
       
  5176         }
       
  5177     
       
  5178     TBool continueTask = ETrue;
       
  5179     
       
  5180     switch( aMsg.iCmdType )
       
  5181         {
       
  5182         case CStifTFwIfProt::ECmdPause:
       
  5183             __TRACE( KMessage, (_L("ReceiveResponse Remote Pause")));
       
  5184 
       
  5185             if( tcase->iRemoteState != CRemoteTestCase::ECasePauseSent )
       
  5186                 {
       
  5187                 __TRACE( KError, (_L("Pause response received in illegal state")));
       
  5188                 User::Leave( KErrGeneral );                        
       
  5189                 }
       
  5190             tcase->iRemoteState = CRemoteTestCase::ECasePaused;
       
  5191             
       
  5192             // Start pause timer if timeout was given 
       
  5193             if( ( iPausedTestCase.Length() > 0 ) &&
       
  5194                 ( iPauseTime != 0 ) )
       
  5195                 {
       
  5196                 continueTask = EFalse;
       
  5197                 iState = ERunnerWaitTimeout;
       
  5198                 iPauseTimer.After( iStatus, iPauseTime*1000 );
       
  5199                 SetActive();         
       
  5200                 }
       
  5201             break;
       
  5202         case CStifTFwIfProt::ECmdResume:
       
  5203             __TRACE( KMessage, (_L("ReceiveResponse Remote Resume")));
       
  5204 
       
  5205             if( tcase->iRemoteState != CRemoteTestCase::ECaseResumeSent )
       
  5206                 {
       
  5207                 __TRACE( KError, (_L("Resume response received in illegal state")));
       
  5208                 User::Leave( KErrGeneral );                        
       
  5209                 }
       
  5210             tcase->iRemoteState = CRemoteTestCase::ECaseRunning;
       
  5211             break;
       
  5212         case CStifTFwIfProt::ECmdCancel:
       
  5213             __TRACE( KMessage, (_L("ReceiveResponse Remote Cancel")));
       
  5214 
       
  5215             if( tcase->iRemoteState != CRemoteTestCase::ECaseCancelSent )
       
  5216                 {
       
  5217                 __TRACE( KError, (_L("Cancel response received in illegal state")));
       
  5218                 User::Leave( KErrGeneral );                        
       
  5219                 }
       
  5220             tcase->iRemoteState = CRemoteTestCase::ECaseCancelled;
       
  5221             // Need to wait Run response with KErrCancel
       
  5222             continueTask = EFalse;
       
  5223             // Start timer    
       
  5224             iRemoteTimer->SetTimerActive( iTestCombiner->iRemoteTimeout );
       
  5225             break;
       
  5226         default:
       
  5227             // Should never come here
       
  5228             User::Leave( KErrGeneral );
       
  5229         }
       
  5230     
       
  5231     return continueTask;
       
  5232     }
       
  5233 
       
  5234 /*
       
  5235 -------------------------------------------------------------------------------
       
  5236 
       
  5237      Class: CTestRunner
       
  5238 
       
  5239      Method: ReceiveResponseEventCtlL
       
  5240 
       
  5241      Description: Handles responses for event system control commands 
       
  5242         received from slave
       
  5243   
       
  5244      Parameters:    CStifTFwIfProt& aMsg: in: protocol message parser
       
  5245      
       
  5246      Return Values: ETrue: continue script file execution
       
  5247                     EFalse: stop script file execution 
       
  5248 
       
  5249      Errors/Exceptions: Leaves on error situations.
       
  5250 
       
  5251      Status: Draft
       
  5252     
       
  5253 -------------------------------------------------------------------------------
       
  5254 */
       
  5255 TBool CTestRunner::ReceiveResponseEventCtlL( CStifTFwIfProt& aMsg )
       
  5256     {
       
  5257         
       
  5258     CSlaveInfo* slave = iTestCombiner->GetSlave( aMsg.SrcId() );
       
  5259     if( slave == NULL )
       
  5260         {
       
  5261         User::Leave( KErrNotFound );
       
  5262         }
       
  5263     
       
  5264     TBool continueTask = ETrue;
       
  5265     switch( aMsg.iCmdType )
       
  5266         {
       
  5267         case CStifTFwIfProt::ECmdRequest:
       
  5268             {
       
  5269             __TRACE( KMessage, (_L("ReceiveResponse Request")));
       
  5270  
       
  5271             TEventTc* event = slave->GetEvent( aMsg.iEventName );
       
  5272             if( event == NULL )
       
  5273                 {
       
  5274                 User::Leave( KErrNotFound );
       
  5275                 }
       
  5276             switch( aMsg.iEventStatus )
       
  5277                 {
       
  5278                 case CStifTFwIfProt::EEventActive:
       
  5279                     __TRACE( KMessage, (_L("Event %S active"), &aMsg.iEventName ));
       
  5280                     break;
       
  5281                 case CStifTFwIfProt::EEventSet:
       
  5282                     __TRACE( KMessage, (_L("Event %S set"), &aMsg.iEventName ));
       
  5283                     // Set event
       
  5284                     event->SetEvent( aMsg.iEventType );
       
  5285                     continueTask = EFalse;
       
  5286                     break;
       
  5287                 case CStifTFwIfProt::EEventError:
       
  5288                     __TRACE( KMessage, (_L("Event %S error %d"), 
       
  5289                         &aMsg.iEventName, aMsg.iResult ));
       
  5290                     User::Leave( aMsg.iResult );
       
  5291                 default:
       
  5292                     User::Leave( KErrGeneral );
       
  5293                 }
       
  5294             }
       
  5295             break;
       
  5296         case CStifTFwIfProt::ECmdRelease:
       
  5297             __TRACE( KMessage, (_L("ReceiveResponse Release")));
       
  5298             if( aMsg.iResult != KErrNone )
       
  5299                 {
       
  5300                 __TRACE( KError, (_L("Response with error %d"), aMsg.iResult ));
       
  5301                 User::Leave( aMsg.iResult );
       
  5302                 }
       
  5303 
       
  5304             // Everything ok, no need to do anything
       
  5305             break;
       
  5306         case CStifTFwIfProt::ECmdSetEvent:
       
  5307             __TRACE( KMessage, (_L("ReceiveResponse SetEvent")));
       
  5308             if( aMsg.iResult != KErrNone )
       
  5309                 {
       
  5310                 __TRACE( KError, (_L("Response with error %d"), aMsg.iResult ));
       
  5311                 User::Leave( aMsg.iResult );
       
  5312                 }
       
  5313 
       
  5314             // Everything ok, no need to do anything
       
  5315             break;
       
  5316         case CStifTFwIfProt::ECmdUnsetEvent:
       
  5317             __TRACE( KMessage, (_L("ReceiveResponse Unset")));
       
  5318             if( aMsg.iResult != KErrNone )
       
  5319                 {
       
  5320                 __TRACE( KError, (_L("Response with error %d"), aMsg.iResult ));
       
  5321                 User::Leave( aMsg.iResult );
       
  5322                 }
       
  5323             // Everything ok, no need to do anything
       
  5324             break;
       
  5325         default:
       
  5326             // Should never come here
       
  5327             User::Leave( KErrGeneral );
       
  5328         }
       
  5329 
       
  5330     return continueTask;
       
  5331     
       
  5332     }
       
  5333 
       
  5334 /*
       
  5335 -------------------------------------------------------------------------------
       
  5336 
       
  5337      Class: CTestRunner
       
  5338 
       
  5339      Method: ReceiveResponseSendReceiveL
       
  5340 
       
  5341      Description: Handles responses for asynchronous sendreceive commands 
       
  5342                   received from slave
       
  5343   
       
  5344      Parameters: CStifTFwIfProt& aMsg: in: protocol message parser
       
  5345      
       
  5346      Return Values: ETrue: continue script file execution
       
  5347                     EFalse: stop script file execution 
       
  5348 
       
  5349      Errors/Exceptions: Leaves on error situations.
       
  5350 
       
  5351      Status: Draft
       
  5352     
       
  5353 -------------------------------------------------------------------------------
       
  5354 */
       
  5355 TBool CTestRunner::ReceiveResponseSendReceiveL( CStifTFwIfProt& aMsg )
       
  5356     {
       
  5357         
       
  5358     TPtrC tmp = CStifTFwIfProt::RunStatus(aMsg.iRunStatus); 
       
  5359     __TRACE( KMessage, (
       
  5360         _L("ReceiveResponseSendReceiveL asynchronous Remote SendReceive %S"),
       
  5361         &tmp ) );
       
  5362 
       
  5363     TBool continueTask = EFalse; 
       
  5364     switch( aMsg.iRunStatus )
       
  5365         {
       
  5366         case CStifTFwIfProt::ERunStarted:
       
  5367             {
       
  5368             // Locate CRemoteSendReceive object
       
  5369             CRemoteSendReceive* sendreceive = 
       
  5370                             iTestCombiner->GetRemoteSendReceive( GETDEVID(
       
  5371                             aMsg.SrcId() ) );
       
  5372             if( sendreceive == NULL ) 
       
  5373                 {
       
  5374                 __TRACE( KError, (_L("CRemoteSendReceive object not found")));
       
  5375                 User::Leave( KErrNotFound );        
       
  5376                 }
       
  5377             sendreceive->iRemoteState = CRemoteSendReceive::ECaseSend;
       
  5378 
       
  5379             // continueTask is EFalse=>stop script file execution
       
  5380             break;
       
  5381             }
       
  5382         case CStifTFwIfProt::ERunError:
       
  5383         case CStifTFwIfProt::ERunReady:
       
  5384             {
       
  5385             if( aMsg.iResult != KErrNone )
       
  5386                     {
       
  5387                     __TRACE( KError, (_L("sendreceive response with error %d"), aMsg.iResult ));
       
  5388                     User::Leave( aMsg.iResult );
       
  5389                     }
       
  5390 
       
  5391             // Locate CRemoteSendReceive object
       
  5392             CRemoteSendReceive* sendreceive = 
       
  5393                 iTestCombiner->GetRemoteSendReceive( aMsg.SrcId() );
       
  5394             if( sendreceive == NULL ) 
       
  5395                 {
       
  5396                 __TRACE( KError, (_L("CRemoteSendReceive object not found")));
       
  5397                 User::Leave( KErrNotFound );        
       
  5398                 }
       
  5399 
       
  5400             // continueTask is ETrue=>continue script file execution
       
  5401             continueTask = ETrue;
       
  5402               
       
  5403             sendreceive->iRemoteState = CRemoteSendReceive::ECaseCompleted;
       
  5404 
       
  5405             __TRACE( KMessage, (
       
  5406                 _L( "ReceiveResponseSendReceiveL asynchronous Remote SendReceive rq comp" ) ) );
       
  5407             break;
       
  5408             }
       
  5409         default:
       
  5410             {
       
  5411             // Should never come here
       
  5412             User::Leave( KErrGeneral );    
       
  5413             }
       
  5414         }
       
  5415     return continueTask;
       
  5416 
       
  5417     }
       
  5418 
       
  5419 /*
       
  5420 -------------------------------------------------------------------------------
       
  5421 
       
  5422      Class: CTestRunner
       
  5423 
       
  5424      Method: ReceiveResponseUnknownL
       
  5425 
       
  5426      Description: Handles responses for unspecified commands
       
  5427   
       
  5428      Parameters:    CStifTFwIfProt& aMsg: in: protocol message parser
       
  5429      
       
  5430      Return Values: ETrue: continue script file execution
       
  5431                     EFalse: stop script file execution 
       
  5432 
       
  5433      Errors/Exceptions: Leaves on error situations.
       
  5434 
       
  5435      Status: Draft
       
  5436     
       
  5437 -------------------------------------------------------------------------------
       
  5438 */
       
  5439 TBool CTestRunner::ReceiveResponseUnknownL( CStifTFwIfProt& aMsg )
       
  5440     {
       
  5441         
       
  5442     CSlaveInfo* slave = iTestCombiner->GetSlave( aMsg.SrcId() );
       
  5443     if( slave == NULL )
       
  5444         {
       
  5445         User::Leave( KErrNotFound );
       
  5446         }
       
  5447     if( aMsg.iResult != KErrNone )
       
  5448         {
       
  5449         __TRACE( KError, (_L("Response with error %d"), aMsg.iResult ));
       
  5450         User::Leave( aMsg.iResult );
       
  5451         }
       
  5452     
       
  5453     return ETrue;
       
  5454     
       
  5455     }
       
  5456 
       
  5457 /*
       
  5458 -------------------------------------------------------------------------------
       
  5459 
       
  5460      Class: CTestRunner
       
  5461 
       
  5462      Method: ParseOptArgL
       
  5463 
       
  5464      Description: Parses optional argument 
       
  5465   
       
  5466      Parameters: const TDesC& aOptArg: in: 
       
  5467                     argument-value pair (format arg=value)
       
  5468                  TPtrC& aArg: out: parsed argument  
       
  5469                  TPtrC& aVal: out: parsed value
       
  5470      
       
  5471      Return Values: None
       
  5472 
       
  5473      Errors/Exceptions: Leaves if parsing fails.
       
  5474 
       
  5475      Status: Approved
       
  5476     
       
  5477 -------------------------------------------------------------------------------
       
  5478 */
       
  5479 void CTestRunner::ParseOptArgL( const TDesC& aOptArg, TPtrC& aArg, TPtrC& aVal)
       
  5480     { 
       
  5481     _LIT( KErrMsgUnknownOrIllegalKeyword, "Unknown or illegal argument %S" );
       
  5482     _LIT( KErrMsgValueNotDefined, "Value of optional argument %S is not defined" );
       
  5483     TInt length = aOptArg.Length();
       
  5484     for( TInt i=0; i < length; i++) 
       
  5485         {
       
  5486         // find the '=' sign 
       
  5487         if( aOptArg[i] == '=' )
       
  5488             {
       
  5489             if( i+1 >= length )
       
  5490                 {
       
  5491                 __TRACE( KError, 
       
  5492                     (_L("Illegal optional argument(%S), no value"), 
       
  5493                     &aOptArg ));    
       
  5494 				TPtrC tmp = aOptArg.Left( i );
       
  5495                 iRunErrorMessage.Format( KErrMsgValueNotDefined, &tmp );
       
  5496                 User::Leave( KErrArgument );
       
  5497                 }
       
  5498             aArg.Set( aOptArg.Left( i ) );
       
  5499             aVal.Set( aOptArg.Mid( i+1 ) );
       
  5500             __TRACE( KMessage, (  _L( "arg '%S', val '%S'" ),
       
  5501                 &aArg, &aVal ));        
       
  5502             return;
       
  5503             }
       
  5504         }
       
  5505     __TRACE( KError, (_L("Illegal optional argument(%S)"), &aOptArg ));    
       
  5506     iRunErrorMessage.Format( KErrMsgUnknownOrIllegalKeyword, &aOptArg );
       
  5507     User::Leave( KErrArgument );
       
  5508     
       
  5509     }     
       
  5510      
       
  5511 /*
       
  5512 -------------------------------------------------------------------------------
       
  5513 
       
  5514      Class: CTestRunner
       
  5515 
       
  5516      Method: CancelTestCases
       
  5517 
       
  5518      Description: Cancels all running testcases
       
  5519   
       
  5520      Parameters:    None
       
  5521      
       
  5522      Return Values: None
       
  5523 
       
  5524      Errors/Exceptions: None.
       
  5525 
       
  5526      Status: Approved
       
  5527     
       
  5528 -------------------------------------------------------------------------------
       
  5529 */
       
  5530 void CTestRunner::CancelTestCases()
       
  5531     {
       
  5532     __TRACEFUNC();
       
  5533 
       
  5534     TInt count = iTestCombiner->iTestCases.Count();
       
  5535     for( TInt i=0; i < count; i++ )
       
  5536         {
       
  5537         if( iTestCombiner->iTestCases[i]->State() == 
       
  5538             CTCTestCase::ETestCaseRunning )
       
  5539             {
       
  5540             iTestCombiner->iTestCases[i]->Cancel();
       
  5541             }
       
  5542         }
       
  5543         
       
  5544     if( ( iTestCombiner->iRunningTests == 0 ) &&
       
  5545         iTestCombiner->iSchedulerActive ) 
       
  5546         {
       
  5547         // Stop execution
       
  5548         CActiveScheduler::Current()->Stop();
       
  5549         iTestCombiner->iSchedulerActive = EFalse;
       
  5550         return;
       
  5551         }
       
  5552         
       
  5553     }
       
  5554 
       
  5555 /*
       
  5556 -------------------------------------------------------------------------------
       
  5557 
       
  5558      Class: CTestRunner
       
  5559 
       
  5560      Method: SetRunnerActive
       
  5561 
       
  5562      Description: Set CTestRunner active and complete.
       
  5563   
       
  5564      Parameters:    None.
       
  5565 
       
  5566      Return Values: None.
       
  5567 
       
  5568      Errors/Exceptions: None.
       
  5569 
       
  5570      Status: Approved
       
  5571     
       
  5572 -------------------------------------------------------------------------------
       
  5573 */
       
  5574 void CTestRunner::SetRunnerActive()
       
  5575      {
       
  5576      __TRACEFUNC();
       
  5577      
       
  5578      if( IsActive() )
       
  5579         {
       
  5580         __TRACE( KError, ( _L("Runner already active %d"), iState ));
       
  5581         User::Panic( KTestRunner, KErrInUse );
       
  5582         }
       
  5583  
       
  5584      // Update state
       
  5585      iState = ERunnerRunning;
       
  5586  
       
  5587      iStatus = KRequestPending;
       
  5588      TRequestStatus* rs = &iStatus;
       
  5589      SetActive();
       
  5590      User::RequestComplete( rs, KErrNone );
       
  5591      
       
  5592      }
       
  5593      
       
  5594 /*
       
  5595 -------------------------------------------------------------------------------
       
  5596 
       
  5597      Class: CTestRunner
       
  5598 
       
  5599      Method: CheckUnsetEvent
       
  5600 
       
  5601      Description: Check unset event.
       
  5602      
       
  5603      Parameters: None
       
  5604          
       
  5605      Return Values: ETrue: Unset event completed
       
  5606                     EFalse: No unset event pending
       
  5607 
       
  5608      Errors/Exceptions: None
       
  5609 
       
  5610      Status: Approved
       
  5611     
       
  5612 -------------------------------------------------------------------------------
       
  5613 */
       
  5614 TBool CTestRunner::CheckUnsetEvent()
       
  5615     {
       
  5616     if( iEvent.Name().Length() == 0 )
       
  5617         {
       
  5618         return EFalse;
       
  5619         }
       
  5620         
       
  5621     __TRACE( KMessage, (_L("Unset event completed") ));
       
  5622     // Check if some testmodule below has still event request pending
       
  5623     if( iTestCombiner->UnsetEvent( iEvent, iStatus ) == EFalse )
       
  5624         {
       
  5625          // No event request pending
       
  5626         // then check other testmodules (may block)
       
  5627         TInt res = iTestCombiner->TestModuleIf().Event( iEvent );
       
  5628         if( res != KErrNone )
       
  5629             {
       
  5630             iTestCombiner->iResult = res;
       
  5631             }
       
  5632             
       
  5633         __TRACE( KPrint, (_L("Unset: Complete") ) );
       
  5634         iEvent.SetName( _L("") );
       
  5635         // Proceed testcase section execution
       
  5636         SetRunnerActive();
       
  5637         }    
       
  5638     else
       
  5639         {
       
  5640         iState = ERunnerWaitUnset;
       
  5641         // Wait for unset to complete 
       
  5642         SetActive();
       
  5643         }
       
  5644          
       
  5645     return ETrue;
       
  5646     }
       
  5647 
       
  5648 
       
  5649 /*
       
  5650 -------------------------------------------------------------------------------
       
  5651 
       
  5652      Class: CTestRunner
       
  5653 
       
  5654      Method: ExecuteLoopL
       
  5655 
       
  5656      Description: Handle the loop keyword operations.
       
  5657 
       
  5658      Parameters: CStifItemParser* aItem: in: Pointer to parsed item object.
       
  5659 
       
  5660      Return Values: None.
       
  5661 
       
  5662      Errors/Exceptions: None.
       
  5663 
       
  5664      Status: Proposal
       
  5665 
       
  5666 -------------------------------------------------------------------------------
       
  5667 */
       
  5668 void CTestRunner::ExecuteLoopL( CStifItemParser* aItem )
       
  5669     {
       
  5670     _LIT( KErrMsgLoopNestedLoop, "Loop: Nested loops are not supported " );
       
  5671     _LIT( KErrMsgLoopInvalidLoopCountParam, "Loop: No loop count value given for loop or value has invalid format" );
       
  5672     _LIT( KErrMsgLoopUnknownUnexpectedOption, "Loop: Unknown or unexpected loop option");
       
  5673     _LIT( KErrMsgLoopPasslimitInvalidValue, "Loop: No passlimit value given for loop or value has invalid format" );
       
  5674     _LIT( KErrMsgLoopPasslimitNotInRange, "Loop: Passlimit value is lower than 0 or higher than loop count" );
       
  5675     __TRACEFUNC();
       
  5676 
       
  5677     if( iLoopTimes != 0 )
       
  5678         {
       
  5679         __TRACE( KError, (_L("ExecuteLoopL: Nested loop are not supported")));
       
  5680         iRunErrorMessage = KErrMsgLoopNestedLoop;
       
  5681         User::Leave( KErrNotSupported );
       
  5682         }
       
  5683 
       
  5684     iLoopTimes = 0;
       
  5685     iLoopCounter = 0;
       
  5686     iPasslimitEnabled = EFalse;
       
  5687     iTimedLoop = EFalse;
       
  5688     
       
  5689     if( aItem->GetNextInt( iLoopTimes ) != KErrNone )
       
  5690         {
       
  5691         __TRACE( KError, (_L("ExecuteLoopL: No loop count value given for loop")));
       
  5692         iRunErrorMessage = KErrMsgLoopInvalidLoopCountParam;
       
  5693         User::Leave( KErrArgument );
       
  5694         }
       
  5695     __TRACE( KMessage, (_L("ExecuteLoopL: Loop for %d times" ), iLoopTimes ) );
       
  5696 
       
  5697     //Check loop options
       
  5698     TPtrC option;
       
  5699     TInt ret = aItem->GetNextString(option); 
       
  5700     if(ret == KErrNone)
       
  5701         {
       
  5702         if(option.Compare(_L("msec")) == 0) //time loop option
       
  5703             {
       
  5704             iTimedLoop = ETrue;
       
  5705             iStartTime.HomeTime();
       
  5706             iExpectedLoopTime = TInt64(iLoopTimes) * TInt64(1000); //convert to micro seconds
       
  5707             __TRACE(KMessage, (_L("ExecuteLoopL: Timed loop for %d msec" ), iLoopTimes));
       
  5708             
       
  5709             ret = aItem->GetNextString(option); //Get next option
       
  5710             }
       
  5711         }
       
  5712         
       
  5713     if(ret == KErrNone)
       
  5714         {
       
  5715         if(option.Compare(_L("passlimit")) == 0) //passlimit option
       
  5716             {
       
  5717             iPasslimit = 0;
       
  5718             if( aItem->GetNextInt( iPasslimit ) != KErrNone )
       
  5719                 {
       
  5720                 __TRACE( KError, ( _L( "ExecuteLoopL: No passlimit value given for loop." ) ) );
       
  5721                 iRunErrorMessage = KErrMsgLoopPasslimitInvalidValue;
       
  5722                 User::Leave( KErrArgument );
       
  5723                 }
       
  5724             __TRACE( KMessage, ( _L( "ExecuteLoopL: Passlimit set on %d" ), iPasslimit ) );
       
  5725             //Check if passlimit has valid value
       
  5726             if(iPasslimit < 0 || (iPasslimit > iLoopTimes && !iTimedLoop))
       
  5727                 {
       
  5728                 __TRACE( KError, ( _L( "ExecuteLoopL: Passlimit value is lower than 0 or higher than loop count." ) ) );
       
  5729                 iRunErrorMessage = KErrMsgLoopPasslimitNotInRange;
       
  5730                 User::Leave( KErrArgument );
       
  5731                 }
       
  5732             iPasslimitEnabled = ETrue;
       
  5733 
       
  5734             ret = aItem->GetNextString(option); //Get next option
       
  5735             }
       
  5736         }
       
  5737         
       
  5738     if(ret == KErrNone)
       
  5739         {
       
  5740         __TRACE( KError, ( _L( "ExecuteLoopL: Unknown or unexpected loop option [%S]" ), &option ) );
       
  5741         iRunErrorMessage = KErrMsgLoopUnknownUnexpectedOption;
       
  5742         User::Leave( KErrNotSupported );
       
  5743         }
       
  5744 
       
  5745 	iPassedIterationCnt = 0;
       
  5746 
       
  5747     iLoopStartPos = iTestCombiner->iSectionParser->GetPosition();
       
  5748     }
       
  5749 
       
  5750 /*
       
  5751 -------------------------------------------------------------------------------
       
  5752 
       
  5753      Class: CTestRunner
       
  5754 
       
  5755      Method: ExecuteEndLoopL
       
  5756 
       
  5757      Description: Handle the endloop keyword operations.
       
  5758 
       
  5759      Parameters: None.
       
  5760 
       
  5761      Return Values: TBool: Boolean value for indicate can testing continue.
       
  5762 
       
  5763      Errors/Exceptions: None.
       
  5764 
       
  5765      Status: Proposal
       
  5766 
       
  5767 -------------------------------------------------------------------------------
       
  5768 */
       
  5769 TBool CTestRunner::ExecuteEndLoopL()
       
  5770     {
       
  5771     __TRACEFUNC();
       
  5772 
       
  5773     // Fail test case if there was no loop started
       
  5774     if(iTestCombiner->iLoopIsUsed == EFalse)
       
  5775         {
       
  5776         __TRACE(KError, (_L("Encountered \'endloop\' without \'loop\'. Aborting test case.")));
       
  5777         iTestCombiner->iResult = KErrGeneral;
       
  5778         iState = ERunnerError;
       
  5779         CancelTestCases();
       
  5780         return ETrue; // Test case file parsing can be continue
       
  5781         }
       
  5782 
       
  5783 	TBool iterationFailed = EFalse; //Has last iteration failed (at least one of test cases has failed)
       
  5784 
       
  5785     // First we check is all test cases that is set to run inside the loop
       
  5786     // completed. If not completed we wait until test case completes.
       
  5787     // Is some loop executions fails that is not allowed then loop execution
       
  5788     // will be stopped and error result is given to TestCombiner
       
  5789 
       
  5790     for( TInt s = 0; s < iTestCombiner->iTestCases.Count(); s++ )
       
  5791         {
       
  5792         CTestCase* testCase = (CTestCase*)iTestCombiner->iTestCases[s]; 
       
  5793         if( testCase == NULL )
       
  5794             {
       
  5795             __TRACE( KError, (_L("ExecuteEndLoopL: CTestCase object not found") ) );
       
  5796             return ETrue;
       
  5797             }
       
  5798         // Check that testCase object is allocated inside the loop
       
  5799         TBool isLoopTestCase( EFalse );
       
  5800         for( TInt p = 0; p < iTestCombiner->iLoopAllocationArray.Count(); p++ )
       
  5801             {
       
  5802             if( iTestCombiner->iLoopAllocationArray[p] == testCase )
       
  5803                 {
       
  5804                 isLoopTestCase = ETrue;
       
  5805                 break;
       
  5806                 }
       
  5807             }
       
  5808         // testCase object is allocated inside loop
       
  5809         if( isLoopTestCase )
       
  5810             {
       
  5811             // Test case is completed
       
  5812             //if( testCase->State() == CTCTestCase::ETestCaseCompleted )
       
  5813             if(testCase->IsCompletelyFinished())
       
  5814                 {
       
  5815                 // Check normal test result
       
  5816                 if( testCase->iExpectedResultCategory == TFullTestResult:: ECaseExecuted )
       
  5817                     {
       
  5818                     // Normal completion, check result
       
  5819                     if( testCase->iResult.iTestResult.iResult != testCase->iExpectedResult )
       
  5820                         {
       
  5821                         __TRACE( KPrint, ( _L( "Test failed, expect(%d) != result(%d)"), 
       
  5822                              testCase->iExpectedResult,
       
  5823                              testCase->iResult.iTestResult.iResult ));
       
  5824                         //If no passlimit is provided behave in old way
       
  5825                         if( !iPasslimitEnabled )
       
  5826                              {
       
  5827                             // We return the first error result as aResult
       
  5828                             if( testCase->iResult.iTestResult.iResult != KErrNone )
       
  5829                                 {
       
  5830                                 iTestCombiner->iScriptFailed = testCase->iResult.iCaseExecutionResultCode;
       
  5831                                 iTestCombiner->iScriptFailedDescription.Copy(testCase->iResult.iTestResult.iResultDes);
       
  5832                                 }
       
  5833                             else
       
  5834                                 {
       
  5835                                 iTestCombiner->iScriptFailed = testCase->iResult.iCaseExecutionResultCode;
       
  5836                                 iTestCombiner->iScriptFailedDescription.Copy(_L("Test case has not finished with expected result (in loop)."));
       
  5837                                 }
       
  5838 
       
  5839                             iState = ERunnerError;
       
  5840                             CancelTestCases();
       
  5841                             return ETrue; // Test case file parsing can be continue
       
  5842                             }
       
  5843                         else
       
  5844                             {
       
  5845                             // Set flag that one of test cases has failed, so whole iteration is failed
       
  5846                             iterationFailed = ETrue;
       
  5847                             }
       
  5848                         }
       
  5849                     }
       
  5850                 // Abnormal completion, i.e. panic, leave, exception or timeout
       
  5851                 else 
       
  5852                     {
       
  5853                     if( testCase->iResult.iCaseExecutionResultCode != testCase->iExpectedResult )
       
  5854                         {
       
  5855                         __TRACE( KPrint, ( _L( "Test failed, expect errorcode(%d) != result(%d)"), 
       
  5856                              testCase->iExpectedResult,
       
  5857                              testCase->iResult.iCaseExecutionResultCode ) );
       
  5858                         //If no passlimit is provided behave in old way
       
  5859                         if( !iPasslimitEnabled )
       
  5860                             {
       
  5861                             // We return the first error result as aResult
       
  5862                             iTestCombiner->iScriptFailed = testCase->iResult.iCaseExecutionResultCode;
       
  5863                             iTestCombiner->iScriptFailedDescription.Copy(_L("Test case has not finished with expected execution error (in loop)."));
       
  5864 
       
  5865                             iState = ERunnerError;
       
  5866                             // Return error from here
       
  5867                             CancelTestCases();
       
  5868                             return ETrue; // Test case file parsing can be continue
       
  5869                             }
       
  5870                         else
       
  5871                             {
       
  5872                             // Set flag that one of test cases has failed, so whole iteration is failed
       
  5873                             iterationFailed = ETrue;
       
  5874                             }
       
  5875                         }
       
  5876 
       
  5877                     // Requested testcase is completed already,
       
  5878                     // proceed testcase execution
       
  5879                     __TRACE( KMessage, (_L("Already completed")));
       
  5880                     }
       
  5881                 } // End "Test case is completed"
       
  5882             // Test case is running state, set to wait the test case complete
       
  5883             else if( testCase->State() == CTCTestCase::ETestCaseRunning )
       
  5884                  {
       
  5885                  // Wait testcase to complete. If no id there should generate
       
  5886                  // id that test case complete will be handled correctly
       
  5887                  if( testCase->TestId().Length() == 0 )
       
  5888                     {
       
  5889                     TPtrC generatedTestId( _L( "stif" ) );
       
  5890                     delete testCase->iTestId;
       
  5891                     testCase->iTestId = generatedTestId.Alloc();
       
  5892                     }
       
  5893                 iTestCombiner->iWaitTestCase.Copy( testCase->TestId() );
       
  5894                  // Stop testcase execution until testcase completed 
       
  5895                  iState = ERunnerWaitTestCase;
       
  5896                 // Go to beginning of the endloop
       
  5897                 User::LeaveIfError(
       
  5898                     iTestCombiner->iSectionParser->SetPosition( iEndLoopStartPos ));
       
  5899 
       
  5900                 // Testing is ongoing, test case file parsing cannot
       
  5901                 // be continue. Next line will be run when some AO
       
  5902                 // will be complete and allow parsing to continue
       
  5903                 return EFalse; 
       
  5904                 }
       
  5905             else if(testCase->State() == CTCTestCase::ETestCaseCompleted)
       
  5906                 {
       
  5907                 // Go to beginning of the endloop
       
  5908                 User::LeaveIfError(iTestCombiner->iSectionParser->SetPosition(iEndLoopStartPos));
       
  5909 
       
  5910                 // Testing is ongoing, test case file parsing cannot
       
  5911                 // be continue. Next line will be run when some AO
       
  5912                 // will be complete and allow parsing to continue
       
  5913                 return ETrue;
       
  5914                 }
       
  5915             else
       
  5916                 {
       
  5917                 // This should newer happen
       
  5918                 __TRACE( KError, (_L("ExecuteEndLoopL: Illegal branch") ) );
       
  5919                 }
       
  5920             }
       
  5921         } // end for-loop
       
  5922 
       
  5923     iLoopCounter++;
       
  5924     __TRACE( KMessage, (_L("ExecuteLineL: Loop executed for %d times" ), 
       
  5925             iLoopCounter ) );
       
  5926 
       
  5927     //If passlimit (endurance) is enabled, we must check if any of test case in this iteration has failed
       
  5928     if( iPasslimitEnabled && !iterationFailed )
       
  5929     	{
       
  5930     	iPassedIterationCnt++;
       
  5931     	}
       
  5932 
       
  5933     TTime currTime;
       
  5934     currTime.HomeTime();
       
  5935     //if( iLoopCounter < iLoopTimes )
       
  5936     if(((!iTimedLoop) && (iLoopCounter < iLoopTimes)) //Normal loop
       
  5937        ||
       
  5938        iTimedLoop && (currTime.MicroSecondsFrom(iStartTime) < iExpectedLoopTime)) //Timed loop
       
  5939         {
       
  5940         // Go to beginning of the loop
       
  5941         User::LeaveIfError(
       
  5942             iTestCombiner->iSectionParser->SetPosition( iLoopStartPos ));
       
  5943         }
       
  5944     else
       
  5945         {
       
  5946         // End looping
       
  5947         if( iPasslimitEnabled )
       
  5948         	{
       
  5949 	        __TRACE(KMessage, (_L("ExecuteLoopL: Loop executed. Iterations: %d, passed: %d, expected: %d"), iLoopCounter, iPassedIterationCnt, iPasslimit));
       
  5950         	}
       
  5951 
       
  5952         iLoopCounter = 0;
       
  5953         iLoopTimes = 0;
       
  5954         iLoopStartPos = 0;
       
  5955         // Loop related initializations
       
  5956         iTestCombiner->iLoopIsUsed = EFalse;
       
  5957         //--LOOPBUG-- Do not zero counter because there could be some test cases run before the loop (Stif-83)
       
  5958         //--LOOPBUG-- iTestCombiner->iRunningTests = 0;
       
  5959 
       
  5960         //If passlimit was given and number of passed test is less then expected, stop execution of combiner's test case
       
  5961         if( iPasslimitEnabled && iPassedIterationCnt < iPasslimit )
       
  5962         	{
       
  5963 	        __TRACE( KMessage, ( _L( "ExecuteLoopL: Loop has failed (passlimit). Finishing with KErrCompletion." ) ) );
       
  5964             iTestCombiner->iScriptFailed = KErrCompletion;
       
  5965             iTestCombiner->iScriptFailedDescription = _L("Loop has not reached passlimit requirement.");
       
  5966             iState = ERunnerError;
       
  5967             CancelTestCases();
       
  5968             return ETrue; // Test case file parsing can be continue
       
  5969         	}
       
  5970         else if( iPasslimitEnabled && iPassedIterationCnt >= iPasslimit )
       
  5971         	{
       
  5972 	        __TRACE( KMessage, ( _L( "ExecuteLoopL: Loop has passed (passlimit)" ) ) );
       
  5973         	}
       
  5974         iPassedIterationCnt = 0;
       
  5975         iPasslimit = 0;
       
  5976         iPasslimitEnabled = EFalse;
       
  5977         }
       
  5978 
       
  5979     // Loop time is executed, free allocations that is allocated during loop
       
  5980     TInt a( 0 );
       
  5981     TInt b( 0 );
       
  5982 
       
  5983     for( b = 0; b < iTestCombiner->iLoopAllocationArray.Count(); b++ )
       
  5984         {
       
  5985         //for( a = 0; a < iTestCombiner->iLoopAllocationArray.Count(); a++ )
       
  5986         for( a = 0; a < iTestCombiner->iTestCases.Count(); a++ )
       
  5987             {
       
  5988             if( a < iTestCombiner->iTestCases.Count() && iTestCombiner->iTestCases[a] == iTestCombiner->iLoopAllocationArray[b] )
       
  5989                 {
       
  5990                 delete iTestCombiner->iTestCases[a];
       
  5991                 iTestCombiner->iTestCases.Remove( a );
       
  5992                 }
       
  5993             }
       
  5994         }
       
  5995 
       
  5996     for( b = 0; b < iTestCombiner->iLoopAllocationArray.Count(); b++ )
       
  5997         {
       
  5998         //for( a = 0; a < iTestCombiner->iLoopAllocationArray.Count(); a++ )
       
  5999         for( a = 0; a < iTestCombiner->iTestModules.Count(); a++ )
       
  6000             {
       
  6001             if( a < iTestCombiner->iTestModules.Count() && iTestCombiner->iTestModules[a] == iTestCombiner->iLoopAllocationArray[b] )
       
  6002                 {
       
  6003                 delete iTestCombiner->iTestModules[a];
       
  6004                 iTestCombiner->iTestModules.Remove( a );
       
  6005                 }
       
  6006             }
       
  6007         }
       
  6008 
       
  6009     for( b = 0; b < iTestCombiner->iLoopAllocationArray.Count(); b++ )
       
  6010         {
       
  6011         //for( a = 0; a < iTestCombiner->iLoopAllocationArray.Count(); a++ )
       
  6012         for( a = 0; a < iTestCombiner->iEventArray.Count(); a++ )
       
  6013             {
       
  6014             if( a < iTestCombiner->iEventArray.Count() && iTestCombiner->iEventArray[a] == iTestCombiner->iLoopAllocationArray[b] )
       
  6015                 {
       
  6016                 delete iTestCombiner->iEventArray[a];
       
  6017                 iTestCombiner->iEventArray.Remove( a );
       
  6018                 }
       
  6019             }
       
  6020         }
       
  6021     for( b = 0; b < iTestCombiner->iLoopAllocationArray.Count(); b++ )
       
  6022         {
       
  6023         //for( a = 0; a < iTestCombiner->iLoopAllocationArray.Count(); a++ )
       
  6024         for( a = 0; a < iTestCombiner->iSlaveArray.Count(); a++ )
       
  6025             {
       
  6026             if( a < iTestCombiner->iSlaveArray.Count() && iTestCombiner->iSlaveArray[a] == iTestCombiner->iLoopAllocationArray[b] )
       
  6027                 {
       
  6028                 delete iTestCombiner->iSlaveArray[a];
       
  6029                 iTestCombiner->iSlaveArray.Remove( a );
       
  6030                 }
       
  6031             }
       
  6032         }
       
  6033     for( b = 0; b < iTestCombiner->iLoopAllocationArray.Count(); b++ )
       
  6034         {
       
  6035         //for( a = 0; a < iTestCombiner->iLoopAllocationArray.Count(); a++ )
       
  6036         for( a = 0; a < iTestCombiner->iSendReceive.Count(); a++ )
       
  6037             {
       
  6038             if( a < iTestCombiner->iSendReceive.Count() && iTestCombiner->iSendReceive[a] == iTestCombiner->iLoopAllocationArray[b] )
       
  6039                 {
       
  6040                 delete iTestCombiner->iSendReceive[a];
       
  6041                 iTestCombiner->iSendReceive.Remove( a );
       
  6042                 }
       
  6043             }
       
  6044         }
       
  6045 
       
  6046     // Test operation can be continued
       
  6047     return ETrue; // Test case file parsing can be continue
       
  6048 
       
  6049     }
       
  6050 
       
  6051 /*
       
  6052 -------------------------------------------------------------------------------
       
  6053 
       
  6054     DESCRIPTION
       
  6055 
       
  6056     This module contains the implementation of CRemoteTimer class 
       
  6057     member functions. 
       
  6058 
       
  6059 -------------------------------------------------------------------------------
       
  6060 */
       
  6061 // MACROS
       
  6062 #ifdef LOGGER
       
  6063 #undef LOGGER
       
  6064 #endif
       
  6065 #define LOGGER iTestRunner->iTestCombiner->iLog
       
  6066 
       
  6067 // ================= MEMBER FUNCTIONS =========================================
       
  6068 
       
  6069 /*
       
  6070 -------------------------------------------------------------------------------
       
  6071 
       
  6072      Class: CRemoteTimer
       
  6073 
       
  6074      Method: CRemoteTimer
       
  6075 
       
  6076      Description: Default constructor
       
  6077 
       
  6078      C++ default constructor can NOT contain any code, that
       
  6079      might leave.
       
  6080      
       
  6081      Parameters: CTestRunner* aTestRunner: in: Backpointer to CTestRunner
       
  6082 
       
  6083      Return Values: None
       
  6084 
       
  6085      Errors/Exceptions: None
       
  6086 
       
  6087      Status: Proposal
       
  6088     
       
  6089 -------------------------------------------------------------------------------
       
  6090 */
       
  6091 CRemoteTimer::CRemoteTimer( CTestCombiner* aTestCombiner ): 
       
  6092     CActive(  CActive::EPriorityLow ), // Executed with lowest priority 
       
  6093     iState( ETimerIdle ),
       
  6094     iTestCombiner( aTestCombiner )
       
  6095     {
       
  6096     CActiveScheduler::Add( this );
       
  6097     
       
  6098     }
       
  6099 
       
  6100 /*
       
  6101 -------------------------------------------------------------------------------
       
  6102 
       
  6103      Class: CRemoteTimer
       
  6104 
       
  6105      Method: ConstructL
       
  6106 
       
  6107      Description: Symbian OS second phase constructor
       
  6108 
       
  6109      Symbian OS default constructor can leave.
       
  6110 
       
  6111      Parameters:    None
       
  6112 
       
  6113      Return Values: None
       
  6114 
       
  6115      Errors/Exceptions: None
       
  6116 
       
  6117      Status: Proposal
       
  6118     
       
  6119 -------------------------------------------------------------------------------
       
  6120 */
       
  6121 void CRemoteTimer::ConstructL()
       
  6122     {
       
  6123     
       
  6124     iTimer.CreateLocal();
       
  6125     
       
  6126     }
       
  6127 
       
  6128 /*
       
  6129 -------------------------------------------------------------------------------
       
  6130 
       
  6131      Class: CRemoteTimer
       
  6132 
       
  6133      Method: NewL
       
  6134 
       
  6135      Description: Two-phased constructor.
       
  6136           
       
  6137      Parameters: CTestCombiner* aTestCombiner: in: Backpointer to CTestCombiner
       
  6138 
       
  6139      Return Values: CRemoteTimer*: new object
       
  6140 
       
  6141      Errors/Exceptions: Leaves if new or ConstructL leaves
       
  6142 
       
  6143      Status: Proposal
       
  6144     
       
  6145 -------------------------------------------------------------------------------
       
  6146 */
       
  6147 
       
  6148 CRemoteTimer* CRemoteTimer::NewL(  CTestCombiner* aTestCombiner )
       
  6149     {
       
  6150     
       
  6151     CRemoteTimer* self = new (ELeave) CRemoteTimer( aTestCombiner );
       
  6152      
       
  6153     CleanupStack::PushL( self );
       
  6154     self->ConstructL();
       
  6155     CleanupStack::Pop();
       
  6156 
       
  6157     return self;
       
  6158     
       
  6159     }
       
  6160 
       
  6161 /*
       
  6162 -------------------------------------------------------------------------------
       
  6163 
       
  6164      Class: CRemoteTimer
       
  6165 
       
  6166      Method: ~CRemoteTimer
       
  6167 
       
  6168      Description: Destructor
       
  6169      
       
  6170      Parameters:    None
       
  6171 
       
  6172      Return Values: None
       
  6173 
       
  6174      Errors/Exceptions: None
       
  6175 
       
  6176      Status: Proposal
       
  6177     
       
  6178 -------------------------------------------------------------------------------
       
  6179 */     
       
  6180 
       
  6181 CRemoteTimer::~CRemoteTimer()
       
  6182     {
       
  6183     
       
  6184     Cancel();
       
  6185     
       
  6186     iTimer.Close();
       
  6187          
       
  6188     }
       
  6189 
       
  6190 /*
       
  6191 -------------------------------------------------------------------------------
       
  6192 
       
  6193      Class: CRemoteTimer
       
  6194 
       
  6195      Method: RunL
       
  6196 
       
  6197      Description: Derived from CActive, handles testcase execution.
       
  6198 
       
  6199      Parameters:    None.
       
  6200 
       
  6201      Return Values: None.
       
  6202 
       
  6203      Errors/Exceptions: Leaves on error situations.
       
  6204 
       
  6205      Status: Proposal
       
  6206     
       
  6207 -------------------------------------------------------------------------------
       
  6208 */
       
  6209 void CRemoteTimer::RunL()
       
  6210     {
       
  6211         
       
  6212     if( iState != ETimerPending )
       
  6213         {
       
  6214         User::Panic( KRemoteTimer, KErrGeneral );
       
  6215         }
       
  6216     
       
  6217     if( iStatus.Int() != KErrNone )
       
  6218         {
       
  6219         User::Panic( KRemoteTimer, KErrDied );
       
  6220         }
       
  6221     
       
  6222     iState = ETimerIdle;
       
  6223     
       
  6224     iTestCombiner->RemoteTimeout();
       
  6225     
       
  6226     }
       
  6227      
       
  6228 /*
       
  6229 -------------------------------------------------------------------------------
       
  6230 
       
  6231      Class: CRemoteTimer
       
  6232 
       
  6233      Method: DoCancel
       
  6234 
       
  6235      Description: Derived from CActive handles the Cancel
       
  6236 
       
  6237      Parameters:    None.
       
  6238 
       
  6239      Return Values: None.
       
  6240 
       
  6241      Errors/Exceptions: None.
       
  6242 
       
  6243      Status: Draft
       
  6244     
       
  6245 -------------------------------------------------------------------------------
       
  6246 */
       
  6247 void CRemoteTimer::DoCancel()
       
  6248     {
       
  6249     iTimer.Cancel();
       
  6250     iState = ETimerIdle;
       
  6251       
       
  6252     }
       
  6253 
       
  6254 /*
       
  6255 -------------------------------------------------------------------------------
       
  6256 
       
  6257      Class: CRemoteTimer
       
  6258 
       
  6259      Method: SetTimerActive
       
  6260 
       
  6261      Description: Starts timer
       
  6262 
       
  6263      Parameters:   TTimeIntervalMicroSeconds32 anInterval: in: Timeout
       
  6264 
       
  6265      Return Values: None.
       
  6266 
       
  6267      Errors/Exceptions: None.
       
  6268 
       
  6269      Status: Draft
       
  6270     
       
  6271 -------------------------------------------------------------------------------
       
  6272 */
       
  6273 void CRemoteTimer::SetTimerActive( TTimeIntervalMicroSeconds32 anInterval )
       
  6274     {
       
  6275     if( iState != ETimerIdle )
       
  6276         {
       
  6277         User::Panic( KRemoteTimer, KErrGeneral );
       
  6278         }
       
  6279         
       
  6280     iState = ETimerPending;
       
  6281     
       
  6282     iTimer.After( iStatus, anInterval );
       
  6283     SetActive();         
       
  6284     
       
  6285     }
       
  6286     
       
  6287 /*
       
  6288 -------------------------------------------------------------------------------
       
  6289 
       
  6290     DESCRIPTION
       
  6291 
       
  6292     This module contains the implementation of CRemoteReceiver class 
       
  6293     member functions. 
       
  6294 
       
  6295 -------------------------------------------------------------------------------
       
  6296 */
       
  6297 // MACROS
       
  6298 #ifdef LOGGER
       
  6299 #undef LOGGER
       
  6300 #endif
       
  6301 #define LOGGER iTestCombiner->iLog
       
  6302 
       
  6303 // ================= MEMBER FUNCTIONS =========================================
       
  6304 
       
  6305 /*
       
  6306 -------------------------------------------------------------------------------
       
  6307 
       
  6308      Class: CRemoteReceiver
       
  6309 
       
  6310      Method: CRemoteReceiver
       
  6311 
       
  6312      Description: Default constructor
       
  6313 
       
  6314      C++ default constructor can NOT contain any code, that
       
  6315      might leave.
       
  6316      
       
  6317      Parameters: CTestCombiner* aTestCombiner: in: Backpointer to CTestCombiner
       
  6318 
       
  6319      Return Values: None
       
  6320 
       
  6321      Errors/Exceptions: None
       
  6322 
       
  6323      Status: Proposal
       
  6324     
       
  6325 -------------------------------------------------------------------------------
       
  6326 */
       
  6327 CRemoteReceiver::CRemoteReceiver( CTestCombiner* aTestCombiner ): 
       
  6328     CActive(  CActive::EPriorityStandard ), 
       
  6329     iState( EReceiverIdle ),
       
  6330     iTestCombiner( aTestCombiner )
       
  6331     {
       
  6332     CActiveScheduler::Add( this );
       
  6333     __TRACEFUNC();
       
  6334     
       
  6335     }
       
  6336 
       
  6337 /*
       
  6338 -------------------------------------------------------------------------------
       
  6339 
       
  6340      Class: CRemoteReceiver
       
  6341 
       
  6342      Method: ConstructL
       
  6343 
       
  6344      Description: Symbian OS second phase constructor
       
  6345 
       
  6346      Symbian OS default constructor can leave.
       
  6347 
       
  6348      Parameters:    None
       
  6349 
       
  6350      Return Values: None
       
  6351 
       
  6352      Errors/Exceptions: None
       
  6353 
       
  6354      Status: Proposal
       
  6355     
       
  6356 -------------------------------------------------------------------------------
       
  6357 */
       
  6358 void CRemoteReceiver::ConstructL()
       
  6359     {
       
  6360     
       
  6361 
       
  6362     }
       
  6363 
       
  6364 /*
       
  6365 -------------------------------------------------------------------------------
       
  6366 
       
  6367      Class: CRemoteReceiver
       
  6368 
       
  6369      Method: NewL
       
  6370 
       
  6371      Description: Two-phased constructor.
       
  6372           
       
  6373      Parameters: CTestCombiner* aTestCombiner: in: Backpointer to CTestCombiner
       
  6374 
       
  6375      Return Values: CRemoteReceiver*: new object
       
  6376 
       
  6377      Errors/Exceptions: Leaves if new or ConstructL leaves
       
  6378 
       
  6379      Status: Proposal
       
  6380     
       
  6381 -------------------------------------------------------------------------------
       
  6382 */
       
  6383 
       
  6384 CRemoteReceiver* CRemoteReceiver::NewL( CTestCombiner* aTestCombiner )
       
  6385     {
       
  6386     CRemoteReceiver* self = new (ELeave) CRemoteReceiver( aTestCombiner );
       
  6387      
       
  6388     CleanupStack::PushL( self );
       
  6389     self->ConstructL();
       
  6390     CleanupStack::Pop();
       
  6391 
       
  6392     return self;
       
  6393     }
       
  6394 
       
  6395 /*
       
  6396 -------------------------------------------------------------------------------
       
  6397 
       
  6398      Class: CRemoteReceiver
       
  6399 
       
  6400      Method: ~CRemoteReceiver
       
  6401 
       
  6402      Description: Destructor
       
  6403      
       
  6404      Parameters:    None
       
  6405 
       
  6406      Return Values: None
       
  6407 
       
  6408      Errors/Exceptions: None
       
  6409 
       
  6410      Status: Proposal
       
  6411     
       
  6412 -------------------------------------------------------------------------------
       
  6413 */     
       
  6414 
       
  6415 CRemoteReceiver::~CRemoteReceiver()
       
  6416     {
       
  6417     __TRACEFUNC();
       
  6418     Cancel();
       
  6419 
       
  6420          
       
  6421     }
       
  6422     
       
  6423 /*
       
  6424 -------------------------------------------------------------------------------
       
  6425 
       
  6426      Class: CRemoteReceiver
       
  6427 
       
  6428      Method: StartL
       
  6429 
       
  6430      Description: Activates receiving.
       
  6431 
       
  6432      Parameters:    None.
       
  6433 
       
  6434      Return Values: None.
       
  6435 
       
  6436      Errors/Exceptions: None.
       
  6437 
       
  6438      Status: Proposal
       
  6439     
       
  6440 -------------------------------------------------------------------------------
       
  6441 */
       
  6442 void CRemoteReceiver::Start()
       
  6443     {
       
  6444     __TRACEFUNC();
       
  6445     __ASSERT_ALWAYS( iState == EReceiverIdle, 
       
  6446         User::Panic( KRemoteReceiver, KErrGeneral ) );
       
  6447     iState = EReceiverPending;
       
  6448     
       
  6449     iTestCombiner->TestModuleIf().RemoteReceive( iRemoteMsg, iStatus );        
       
  6450     SetActive();
       
  6451                  
       
  6452     }
       
  6453 
       
  6454 /*
       
  6455 -------------------------------------------------------------------------------
       
  6456 
       
  6457      Class: CRemoteReceiver
       
  6458 
       
  6459      Method: RunL
       
  6460 
       
  6461      Description: Derived from CActive, handles testcase execution.
       
  6462 
       
  6463      Parameters:    None.
       
  6464 
       
  6465      Return Values: None.
       
  6466 
       
  6467      Errors/Exceptions: Leaves on error situations.
       
  6468 
       
  6469      Status: Proposal
       
  6470     
       
  6471 -------------------------------------------------------------------------------
       
  6472 */
       
  6473 void CRemoteReceiver::RunL()
       
  6474     {
       
  6475     __TRACEFUNC();
       
  6476     
       
  6477     __ASSERT_ALWAYS( iState == EReceiverPending, 
       
  6478         User::Panic( KRemoteReceiver, KErrGeneral ) );
       
  6479     iState = EReceiverIdle;
       
  6480     
       
  6481     iTestCombiner->ReceiveResponse( iRemoteMsg );
       
  6482                  
       
  6483     }
       
  6484      
       
  6485 /*
       
  6486 -------------------------------------------------------------------------------
       
  6487 
       
  6488      Class: CRemoteReceiver
       
  6489 
       
  6490      Method: DoCancel
       
  6491 
       
  6492      Description: Derived from CActive handles the Cancel
       
  6493 
       
  6494      Parameters:    None.
       
  6495 
       
  6496      Return Values: None.
       
  6497 
       
  6498      Errors/Exceptions: None.
       
  6499 
       
  6500      Status: Proposal
       
  6501     
       
  6502 -------------------------------------------------------------------------------
       
  6503 */
       
  6504 void CRemoteReceiver::DoCancel()
       
  6505     {
       
  6506     __TRACEFUNC();
       
  6507     
       
  6508     iTestCombiner->TestModuleIf().RemoteReceiveCancel();
       
  6509  
       
  6510     }
       
  6511     
       
  6512 // ================= OTHER EXPORTED FUNCTIONS =================================
       
  6513 
       
  6514 /*
       
  6515 -------------------------------------------------------------------------------
       
  6516     
       
  6517      Function: LibEntryL
       
  6518 
       
  6519      Description: Polymorphic Dll Entry Point
       
  6520 
       
  6521      Parameters:    None.
       
  6522 
       
  6523      Return Values: CTestCombiner*: pointer to new CTestCombiner
       
  6524 
       
  6525      Errors/Exceptions: Leaves if NewL leaves.
       
  6526 
       
  6527      Status: Approved
       
  6528      
       
  6529 -------------------------------------------------------------------------------
       
  6530 */
       
  6531 
       
  6532 EXPORT_C CTestCombiner* LibEntryL()
       
  6533     {
       
  6534     return CTestCombiner::NewL();
       
  6535     }
       
  6536 
       
  6537 
       
  6538 
       
  6539 //  End of File