testexecfw/stf/stfext/testmodules/scriptermod/src/SubTestCaseRunner.cpp
changeset 2 8bb370ba6d1d
equal deleted inserted replaced
1:bbd31066657e 2:8bb370ba6d1d
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 * 
       
    14 * Description: This file contains TestScripter implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include "SubTestCaseRunner.h"
       
    20 #include <TestEngineClient.h>
       
    21 #include "TestScripter.h"
       
    22 #include "Logging.h"
       
    23 // EXTERNAL DATA STRUCTURES
       
    24 // None
       
    25 
       
    26 // EXTERNAL FUNCTION PROTOTYPES  
       
    27 // None
       
    28 
       
    29 // CONSTANTS
       
    30 // None
       
    31 
       
    32 // MACROS
       
    33 #ifdef LOGGER
       
    34 #undef LOGGER
       
    35 #endif
       
    36 #define LOGGER iTestRunner->GetLogger()
       
    37 
       
    38 // LOCAL CONSTANTS AND MACROS
       
    39 // None
       
    40 
       
    41 // MODULE DATA STRUCTURES
       
    42 // None
       
    43 
       
    44 // LOCAL FUNCTION PROTOTYPES
       
    45 // None
       
    46 
       
    47 // FORWARD DECLARATIONS
       
    48 // None
       
    49 
       
    50 // ==================== LOCAL FUNCTIONS =======================================
       
    51 
       
    52 // ================= MEMBER FUNCTIONS =========================================
       
    53 
       
    54 /*
       
    55 -------------------------------------------------------------------------------
       
    56 
       
    57      Class: CSubTestCaseRunner
       
    58 
       
    59      Method: CSubTestCaseRunner
       
    60 
       
    61      Description: Constructor
       
    62 
       
    63      Constructor.
       
    64      
       
    65      Parameters: CTestRunner* aTestRunner : in: Pointer to test runner which 
       
    66                          should be notified about test case end
       
    67 
       
    68      Return Values: None
       
    69 
       
    70      Errors/Exceptions: None
       
    71 
       
    72      Status: Draft
       
    73     
       
    74 -------------------------------------------------------------------------------
       
    75 */
       
    76 CSubTestCaseRunner::CSubTestCaseRunner()
       
    77 :CActive( EPriorityStandard ), iState( ESTSIdle )
       
    78     {
       
    79     }
       
    80 
       
    81 CSubTestCaseRunner::TSubTestCaseState CSubTestCaseRunner::GetState() const
       
    82     {
       
    83     return iState;
       
    84     }
       
    85 
       
    86 
       
    87 /*
       
    88 -------------------------------------------------------------------------------
       
    89 
       
    90      Class: CLocalSubTestCaseRunner
       
    91 
       
    92      Method: NewLC
       
    93 
       
    94      Description: Two-phased constructor.
       
    95 
       
    96      Two-phased constructor.
       
    97      
       
    98      Parameters: CTestRunner* aTestRunner : in: Pointer to test runner which 
       
    99                          should be notified about test case end
       
   100 
       
   101      Return Values: Pointer to newly created CLocalSubTestCaseRunner object.
       
   102 
       
   103      Errors/Exceptions: Leaves if there is some problem during method execution
       
   104 
       
   105      Status: Draft
       
   106     
       
   107 -------------------------------------------------------------------------------
       
   108 */
       
   109 CLocalSubTestCaseRunner* CLocalSubTestCaseRunner::NewLC( CTestRunner* aTestRunner )
       
   110     {
       
   111     CLocalSubTestCaseRunner* self = new(ELeave)CLocalSubTestCaseRunner( aTestRunner );
       
   112     CleanupStack::PushL( self );
       
   113     self->ConstructL();
       
   114     return self;
       
   115     }
       
   116 
       
   117 /*
       
   118 -------------------------------------------------------------------------------
       
   119 
       
   120      Class: CLocalSubTestCaseRunner
       
   121 
       
   122      Method: NewL
       
   123 
       
   124      Description: Two-phased constructor.
       
   125 
       
   126      Two-phased constructor.
       
   127      
       
   128      Parameters: CTestRunner* aTestRunner : in: Pointer to test runner which 
       
   129                          should be notified about test case end
       
   130 
       
   131      Return Values: Pointer to newly created CLocalSubTestCaseRunner object.
       
   132 
       
   133      Errors/Exceptions: Leaves if there is some problem during method execution
       
   134 
       
   135      Status: Draft
       
   136     
       
   137 -------------------------------------------------------------------------------
       
   138 */
       
   139 CLocalSubTestCaseRunner* CLocalSubTestCaseRunner::NewL( CTestRunner* aTestRunner )
       
   140     {
       
   141     CLocalSubTestCaseRunner* self = NewL( aTestRunner );
       
   142     CleanupStack::Pop( self );
       
   143     return self;
       
   144     }
       
   145 
       
   146 /*
       
   147 -------------------------------------------------------------------------------
       
   148 
       
   149      Class: CLocalSubTestCaseRunner
       
   150 
       
   151      Method: CLocalSubTestCaseRunner
       
   152 
       
   153      Description: Destructor
       
   154 
       
   155      Destructor
       
   156      
       
   157      Parameters: none
       
   158 
       
   159      Return Values: none
       
   160 
       
   161      Errors/Exceptions: none
       
   162 
       
   163      Status: Draft
       
   164     
       
   165 -------------------------------------------------------------------------------
       
   166 */
       
   167 CLocalSubTestCaseRunner::~CLocalSubTestCaseRunner()
       
   168     {
       
   169     CancelSubTestCaseL();
       
   170     
       
   171     delete iStartInfo;
       
   172     iTestCase.Close();
       
   173     iTestEngine.Close();
       
   174     }
       
   175 
       
   176 /*
       
   177 -------------------------------------------------------------------------------
       
   178 
       
   179      Class: CLocalSubTestCaseRunner
       
   180 
       
   181      Method: CLocalSubTestCaseRunner
       
   182 
       
   183      Description: Constructor
       
   184 
       
   185      Constructor.
       
   186      
       
   187      Parameters: CTestRunner* aTestRunner : in: Pointer to test runner which 
       
   188                          should be notified about test case end
       
   189 
       
   190      Return Values: None
       
   191 
       
   192      Errors/Exceptions: None
       
   193 
       
   194      Status: Draft
       
   195     
       
   196 -------------------------------------------------------------------------------
       
   197 */
       
   198 CLocalSubTestCaseRunner::CLocalSubTestCaseRunner( CTestRunner* aTestRunner )
       
   199 :iTestRunner( aTestRunner ), iResultPckg( iResult )
       
   200     {
       
   201     CActiveScheduler::Add( this );    
       
   202     }
       
   203 
       
   204 /*
       
   205 -------------------------------------------------------------------------------
       
   206 
       
   207      Class: CLocalSubTestCaseRunner
       
   208 
       
   209      Method: ConstructL
       
   210 
       
   211      Description: Second phase of two-phased constructor.
       
   212 
       
   213      Second phase of two-phased constructor.
       
   214      
       
   215      Parameters: None
       
   216 
       
   217      Return Values: None
       
   218 
       
   219      Errors/Exceptions: None
       
   220 
       
   221      Status: Draft
       
   222     
       
   223 -------------------------------------------------------------------------------
       
   224 */
       
   225 void CLocalSubTestCaseRunner::ConstructL()
       
   226     {
       
   227     }
       
   228 
       
   229 /*
       
   230 -------------------------------------------------------------------------------
       
   231 
       
   232      Class: CLocalSubTestCaseRunner
       
   233 
       
   234      Method: NewL
       
   235 
       
   236      Description: Handles test case execution end.
       
   237 
       
   238      Handles test case execution end and pass test case execution result to 
       
   239      proper CTestCaseRunner.
       
   240      
       
   241      Parameters: None
       
   242 
       
   243      Return Values: None
       
   244 
       
   245      Errors/Exceptions: Leaves if there is some problem during method execution
       
   246 
       
   247      Status: Draft
       
   248     
       
   249 -------------------------------------------------------------------------------
       
   250 */
       
   251 void CLocalSubTestCaseRunner::RunL()
       
   252     {
       
   253     // Store run result
       
   254     iRunResult = iStatus.Int();
       
   255     
       
   256     iTestCase.Close();
       
   257     iTestEngine.Close();    
       
   258     
       
   259     iState = ESTSIdle;
       
   260     
       
   261     // Report sub test case result to  CTestRunner
       
   262     iTestRunner->SubTestCaseFinishedL( this );
       
   263     }
       
   264 
       
   265 /*
       
   266 -------------------------------------------------------------------------------
       
   267 
       
   268      Class: CLocalSubTestCaseRunner
       
   269 
       
   270      Method: DoCancel
       
   271 
       
   272      Description: Cancels test case execution
       
   273 
       
   274      Cancels test case execution
       
   275      
       
   276      Parameters: None
       
   277 
       
   278      Return Values: None
       
   279 
       
   280      Errors/Exceptions: None
       
   281 
       
   282      Status: Draft
       
   283     
       
   284 -------------------------------------------------------------------------------
       
   285 */
       
   286 void CLocalSubTestCaseRunner::DoCancel()
       
   287     {
       
   288     TInt ret = iTestCase.CancelAsyncRequest( RTestCase::ERunTestCase );
       
   289     if ( ret != KErrNone )
       
   290         {
       
   291         // There was some error during sub test case cancel
       
   292         // Only put message to log.
       
   293         __TRACE( KMessage, ( _L( "Unexpected error during sub test case testid=%S cancel." ), &iStartInfo->GetTestId() ) );
       
   294         }
       
   295 
       
   296     iTestCase.Close();
       
   297     iTestEngine.Close();    
       
   298     
       
   299     // Mart test case as canceled
       
   300     iResult.iTestResult.SetResult( KErrNone, KNullDesC );
       
   301     iResult.iCaseExecutionResultCode = KErrCancel;
       
   302     iResult.iCaseExecutionResultType = TFullTestResult::ECaseCancelled;
       
   303     iState = ESTSIdle;
       
   304     }
       
   305 
       
   306 /*
       
   307 -------------------------------------------------------------------------------
       
   308 
       
   309      Class: CLocalSubTestCaseRunner
       
   310 
       
   311      Method: RunSubTestCaseL
       
   312 
       
   313      Description: Starts test case execution.
       
   314 
       
   315      Starts test case execution.
       
   316      
       
   317      Parameters: CStartInfo* aStartInfo : in: Pointer to structure which hold
       
   318                           information about test case which should be executed.
       
   319 
       
   320      Return Values: None
       
   321 
       
   322      Errors/Exceptions: Leaves if there is some problem during method execution
       
   323 
       
   324      Status: Draft
       
   325     
       
   326 -------------------------------------------------------------------------------
       
   327 */
       
   328 void CLocalSubTestCaseRunner::RunSubTestCaseL( CStartInfo& aStartTestCaseInfo )
       
   329     {
       
   330     // Check if this AO is already running some sub test case
       
   331     if ( IsActive() )
       
   332         {
       
   333         User::Leave( KErrInUse );
       
   334         }
       
   335     
       
   336     // Reset runner internal state
       
   337     Reset();
       
   338     
       
   339     // Copy sub test case startup information
       
   340     CStartInfo* startInfo = CStartInfo::NewL();
       
   341     CleanupStack::PushL( startInfo );
       
   342     startInfo->CopyL( aStartTestCaseInfo );
       
   343     CleanupStack::Pop( startInfo );
       
   344     iStartInfo = startInfo;
       
   345     
       
   346     // Connect to TestEngine
       
   347     TInt ret = iTestEngine.Connect();
       
   348     if ( ret != KErrNone )
       
   349         {
       
   350         User::Leave( ret );
       
   351         }
       
   352 
       
   353     // Initialize TestEngine session
       
   354     CleanupClosePushL( iTestEngine );
       
   355     ret = iTestEngine.LoadConfiguration( KNullDesC() );    
       
   356     if ( ret != KErrNone )
       
   357         {
       
   358         User::Leave( ret );
       
   359         }
       
   360 
       
   361     // Load selected test module with specified ini file
       
   362     ret = iTestEngine.AddTestModule( iStartInfo->GetModuleName(),
       
   363             iStartInfo->GetIniFile() );
       
   364     if ( ret != KErrNone )
       
   365         {
       
   366         User::Leave( ret );
       
   367         }
       
   368 
       
   369     // Set optional cfg file
       
   370     if ( iStartInfo->GetConfig() != KNullDesC )
       
   371         {
       
   372         ret = iTestEngine.AddConfigFile( iStartInfo->GetModuleName(),
       
   373                 iStartInfo->GetConfig() );
       
   374         if ( ret != KErrNone )
       
   375             {
       
   376             User::Leave( ret );
       
   377             }
       
   378         }
       
   379 
       
   380     // Get list of available test cases from test engine
       
   381     TRequestStatus enumerationRequestStatus;
       
   382     TCaseCount testCasesCount;
       
   383     iTestEngine.EnumerateTestCases( testCasesCount, enumerationRequestStatus );
       
   384     User::WaitForRequest( enumerationRequestStatus );
       
   385     if ( enumerationRequestStatus.Int() != KErrNone )
       
   386         {
       
   387         User::Leave( enumerationRequestStatus.Int() );
       
   388         }
       
   389 
       
   390     CFixedFlatArray<TTestInfo>* testCasesList = CFixedFlatArray<TTestInfo>::NewL( testCasesCount() );
       
   391     CleanupStack::PushL( testCasesList );
       
   392 
       
   393     ret = iTestEngine.GetTestCases( *testCasesList );
       
   394     if ( ret != KErrNone )
       
   395         {
       
   396         User::Leave( ret );
       
   397         }
       
   398 
       
   399     // Find requested test case in test cases enumerated from TestEngine 
       
   400     TBool findByTitle = ( iStartInfo->GetTitle() != KNullDesC );    
       
   401     TTestInfo testInfo;
       
   402     TBool foundTestCase = EFalse;
       
   403     if ( findByTitle )
       
   404         {
       
   405         iStartInfo->SetTestCaseNumber( -1 );
       
   406         }
       
   407     for ( TInt i = 0; i < testCasesList->Count(); i++ )
       
   408         {
       
   409         if ( ( findByTitle && ( (*testCasesList)[ i ].iTestCaseInfo.iTitle == iStartInfo->GetTitle() ) ) ||
       
   410              ( (*testCasesList)[ i ].iTestCaseInfo.iCaseNumber == iStartInfo->GetTestCaseNumber() ) )
       
   411             {
       
   412             testInfo = (*testCasesList)[ i ];
       
   413             foundTestCase = ETrue;
       
   414             }
       
   415         }
       
   416 
       
   417     // Store test case title
       
   418     iStartInfo->SetTitleL( testInfo.iTestCaseInfo.iTitle );
       
   419 
       
   420     // Check if requested test case is availabe or not
       
   421     if ( !foundTestCase )
       
   422         {
       
   423         User::Leave( KErrNotFound );
       
   424         }
       
   425 
       
   426     CleanupStack::PopAndDestroy( testCasesList );
       
   427 
       
   428     // Open test case subsession
       
   429     TTestInfoPckg testInfoPckg( testInfo );
       
   430     ret = iTestCase.Open( iTestEngine, testInfoPckg );
       
   431     if ( ret != KErrNone )
       
   432         {
       
   433         User::Leave( ret );
       
   434         }
       
   435 
       
   436     // Run sub test case
       
   437     CleanupClosePushL( iTestCase );
       
   438     iTestCase.RunTestCase( iResultPckg, iStatus );
       
   439     SetActive();
       
   440     CleanupStack::Pop(); // Remove iTestCase from cleanup stack
       
   441     CleanupStack::Pop(); // Remove iTestEngine from cleanup stack
       
   442     iState = ESTSRunning;
       
   443     }
       
   444 
       
   445 /*
       
   446 -------------------------------------------------------------------------------
       
   447 
       
   448      Class: CLocalSubTestCaseRunner
       
   449 
       
   450      Method: PauseSubTestCaseL
       
   451 
       
   452      Description: Pauses selected sub test case.
       
   453 
       
   454      Pauses selected sub test case.
       
   455      
       
   456      Parameters: None
       
   457 
       
   458      Return Values: None
       
   459 
       
   460      Errors/Exceptions: Leaves if sub test case is not running
       
   461 
       
   462      Status: Draft
       
   463     
       
   464 -------------------------------------------------------------------------------
       
   465 */
       
   466 void CLocalSubTestCaseRunner::PauseSubTestCaseL()
       
   467     {
       
   468     // Check if sub test case is running
       
   469     if ( !IsActive() )
       
   470         {
       
   471         User::Leave( KErrNotReady );
       
   472         }
       
   473     
       
   474     User::LeaveIfError( iTestCase.Pause() );
       
   475     iState = ESTSPaused;
       
   476     }
       
   477 
       
   478 /*
       
   479 -------------------------------------------------------------------------------
       
   480 
       
   481      Class: CLocalSubTestCaseRunner
       
   482 
       
   483      Method: ReasumeSubTestCaseL
       
   484 
       
   485      Description: Reasume selected sub test case.
       
   486 
       
   487      Reasume selected sub test case.
       
   488      
       
   489      Parameters: None
       
   490 
       
   491      Return Values: None
       
   492 
       
   493      Errors/Exceptions: Leaves if sub test case is not running
       
   494 
       
   495      Status: Draft
       
   496     
       
   497 -------------------------------------------------------------------------------
       
   498 */
       
   499 void CLocalSubTestCaseRunner::ResumeSubTestCaseL()
       
   500     {    
       
   501     // Check if sub test case is running
       
   502     if ( !IsActive() )
       
   503         {
       
   504         User::Leave( KErrNotReady );
       
   505         }
       
   506     
       
   507     User::LeaveIfError( iTestCase.Resume() );
       
   508     iState = ESTSRunning;
       
   509     }
       
   510 
       
   511 void CLocalSubTestCaseRunner::CancelSubTestCaseL()
       
   512     {
       
   513     Cancel();
       
   514     }
       
   515 
       
   516 
       
   517 /*
       
   518 -------------------------------------------------------------------------------
       
   519 
       
   520      Class: CLocalSubTestCaseRunner
       
   521 
       
   522      Method: Reset
       
   523 
       
   524      Description: Resets sub test case runner internal state.
       
   525 
       
   526      Resets sub test case runner internal state.
       
   527      
       
   528      Parameters: None
       
   529 
       
   530      Return Values: None
       
   531 
       
   532      Errors/Exceptions: None
       
   533 
       
   534      Status: Draft
       
   535     
       
   536 -------------------------------------------------------------------------------
       
   537 */
       
   538 void CLocalSubTestCaseRunner::Reset()
       
   539     {
       
   540     delete iStartInfo;
       
   541     iStartInfo = NULL;
       
   542         
       
   543     iRunResult = KErrNone;
       
   544     
       
   545     iResult.iCaseExecutionResultCode = KErrNone;
       
   546     iResult.iCaseExecutionResultType = TFullTestResult::ECaseOngoing;
       
   547     iResult.iTestResult.SetResult( KErrNone, KNullDesC );
       
   548     
       
   549     iState = ESTSIdle;
       
   550     }
       
   551 
       
   552 /*
       
   553 -------------------------------------------------------------------------------
       
   554 
       
   555      Class: CLocalSubTestCaseRunner
       
   556 
       
   557      Method: GetRunResult
       
   558 
       
   559      Description: Returns execution result.
       
   560 
       
   561      Returns execution result.
       
   562      
       
   563      Parameters: None
       
   564 
       
   565      Return Values: Execution result
       
   566 
       
   567      Errors/Exceptions: 
       
   568 
       
   569      Status: Draft
       
   570     
       
   571 -------------------------------------------------------------------------------
       
   572 */
       
   573 TInt CLocalSubTestCaseRunner::GetRunResult() const
       
   574     {
       
   575     return iRunResult;
       
   576     }
       
   577 
       
   578 /*
       
   579 -------------------------------------------------------------------------------
       
   580 
       
   581      Class: CLocalSubTestCaseRunner
       
   582 
       
   583      Method: GetTestCaseResult
       
   584 
       
   585      Description: Returns test case execution result.
       
   586 
       
   587      Returns test case execution result.
       
   588      
       
   589      Parameters: None
       
   590 
       
   591      Return Values: Test case execution result.
       
   592 
       
   593      Errors/Exceptions: None
       
   594 
       
   595      Status: Draft
       
   596     
       
   597 -------------------------------------------------------------------------------
       
   598 */
       
   599 const TFullTestResult& CLocalSubTestCaseRunner::GetTestCaseResult() const    
       
   600     {
       
   601     return iResult;
       
   602     }
       
   603 
       
   604 /*
       
   605 -------------------------------------------------------------------------------
       
   606 
       
   607      Class: CLocalSubTestCaseRunner
       
   608 
       
   609      Method: GetStartInfo
       
   610 
       
   611      Description: Returns informations about started test case.
       
   612 
       
   613      Returns informations about started test case.
       
   614      
       
   615      Parameters: None
       
   616 
       
   617      Return Values: Returns information about started test case.
       
   618 
       
   619      Errors/Exceptions: None
       
   620 
       
   621      Status: Draft
       
   622     
       
   623 -------------------------------------------------------------------------------
       
   624 */
       
   625 const CStartInfo* CLocalSubTestCaseRunner::GetStartInfo() const
       
   626     {
       
   627     return iStartInfo;
       
   628     }
       
   629 
       
   630 CSubTestCaseRunner::TSubTestCaseType CLocalSubTestCaseRunner::GetType() const
       
   631     {
       
   632     return ESTTLocal;
       
   633     }
       
   634 
       
   635 
       
   636 
       
   637 
       
   638 CRemoteSubTestCaseRunner* CRemoteSubTestCaseRunner::NewL( CTestRunner* aTestRunner, 
       
   639         CSlave* aSlave, CRemoteCallsProxy* aRemoteCallsProxy )
       
   640     {
       
   641     CRemoteSubTestCaseRunner* self = new(ELeave)CRemoteSubTestCaseRunner( 
       
   642             aTestRunner, aSlave, aRemoteCallsProxy );
       
   643     CleanupStack::PushL( self );
       
   644     self->ConstructL();
       
   645     CleanupStack::Pop( self );
       
   646     return self;    
       
   647     }
       
   648 
       
   649 CRemoteSubTestCaseRunner* CRemoteSubTestCaseRunner::NewLC( CTestRunner* aTestRunner, 
       
   650         CSlave* aSlave, CRemoteCallsProxy* aRemoteCallsProxy )
       
   651     {    
       
   652     CRemoteSubTestCaseRunner* self = new(ELeave)CRemoteSubTestCaseRunner( 
       
   653             aTestRunner, aSlave, aRemoteCallsProxy );
       
   654     CleanupStack::PushL( self );
       
   655     self->ConstructL();
       
   656     return self;    
       
   657     }
       
   658 
       
   659 CRemoteSubTestCaseRunner::~CRemoteSubTestCaseRunner()
       
   660     {
       
   661     Cancel();
       
   662     
       
   663     iTimeoutTimer.Close();
       
   664     
       
   665     delete iNestedASLoop;
       
   666     iNestedASLoop = NULL;
       
   667     
       
   668     delete iStartInfo;
       
   669     iStartInfo = NULL;
       
   670     
       
   671     TRAPD( err, iSlave->UnregisterSubTestCaseL( this ) );
       
   672     if ( err != KErrNone )
       
   673         {
       
   674         RDebug::Print( _L("Unexpected error during slave subtestcase deregistration %d"), err );
       
   675         }
       
   676     }
       
   677 
       
   678 void CRemoteSubTestCaseRunner::RunSubTestCaseL( CStartInfo& aStartTestCaseInfo )
       
   679     {
       
   680     // Check if this AO is already running some sub test case
       
   681     if ( IsActive() || ( iState != ESTSIdle ) )
       
   682         {
       
   683         User::Leave( KErrInUse );
       
   684         }
       
   685     
       
   686     // Reset runner internal state
       
   687     Reset();
       
   688     
       
   689     // Copy sub test case startup information
       
   690     CStartInfo* startInfo = CStartInfo::NewL();
       
   691     CleanupStack::PushL( startInfo );
       
   692     startInfo->CopyL( aStartTestCaseInfo );
       
   693     CleanupStack::Pop( startInfo );
       
   694     iStartInfo = startInfo;
       
   695     
       
   696     // Connect to TestEngine
       
   697     iRemoteCallsProxy->RunTestCaseL( iSlave->GetMasterId(), iSlave->GetSlaveId(), iStartInfo );
       
   698     
       
   699     iCurrentOperation = ECORunSubtestCase;
       
   700     
       
   701     iTimeoutTimer.After( iStatus, iOperationTimeout );
       
   702     SetActive();
       
   703     
       
   704     iNestedASLoop->Start();
       
   705     
       
   706     User::LeaveIfError( iOperationResult );
       
   707     iState = ESTSRunning;
       
   708     }
       
   709 
       
   710 void CRemoteSubTestCaseRunner::PauseSubTestCaseL()
       
   711     {
       
   712     // Check if sub test case is running
       
   713     if ( IsActive() || ( iState != ESTSRunning ) )
       
   714         {
       
   715         User::Leave( KErrNotReady );
       
   716         }
       
   717 
       
   718     iRemoteCallsProxy->PauseTestCaseL( iSlave->GetMasterId(), iSlave->GetSlaveId(), iTestCaseId );
       
   719 
       
   720     iCurrentOperation = ECOPauseSubtestCase;
       
   721     
       
   722     iTimeoutTimer.After( iStatus, iOperationTimeout );
       
   723     SetActive();
       
   724     
       
   725     iNestedASLoop->Start();
       
   726     
       
   727     User::LeaveIfError( iOperationResult );
       
   728     iState = ESTSPaused;
       
   729     }
       
   730 
       
   731 void CRemoteSubTestCaseRunner::ResumeSubTestCaseL()
       
   732     {    
       
   733     // Check if sub test case is running
       
   734     if ( IsActive() || ( iState != ESTSPaused ) )
       
   735         {
       
   736         User::Leave( KErrNotReady );
       
   737         }
       
   738     
       
   739     iRemoteCallsProxy->ResumeTestCaseL( iSlave->GetMasterId(), iSlave->GetSlaveId(), iTestCaseId );
       
   740 
       
   741     iCurrentOperation = ECOResumeSubtestCase;
       
   742     
       
   743     iTimeoutTimer.After( iStatus, iOperationTimeout );
       
   744     SetActive();
       
   745     
       
   746     iNestedASLoop->Start();
       
   747     
       
   748     User::LeaveIfError( iOperationResult );
       
   749     iState = ESTSRunning;
       
   750     }
       
   751 
       
   752 void CRemoteSubTestCaseRunner::CancelSubTestCaseL()
       
   753     {
       
   754     // Check if sub test case is running
       
   755     if ( IsActive() || ( iState != ESTSIdle ) )
       
   756         {
       
   757         User::Leave( KErrNotReady );
       
   758         }
       
   759     
       
   760     iRemoteCallsProxy->CancelTestCaseL( iSlave->GetMasterId(), iSlave->GetSlaveId(), iTestCaseId );
       
   761 
       
   762     iCurrentOperation = ECOCancelSubtestCase;
       
   763     
       
   764     iTimeoutTimer.After( iStatus, iOperationTimeout );
       
   765     SetActive();
       
   766     
       
   767     iNestedASLoop->Start();
       
   768     
       
   769     User::LeaveIfError( iOperationResult );
       
   770     
       
   771     iRunResult = KErrCancel;
       
   772     // Mart test case as canceled
       
   773     iResult.iTestResult.SetResult( KErrNone, KNullDesC );
       
   774     iResult.iCaseExecutionResultCode = KErrCancel;
       
   775     iResult.iCaseExecutionResultType = TFullTestResult::ECaseCancelled;
       
   776     
       
   777     iState = ESTSIdle;
       
   778     }
       
   779 
       
   780 TInt CRemoteSubTestCaseRunner::GetRunResult() const
       
   781     {
       
   782     return iRunResult;
       
   783     }
       
   784 
       
   785 const TFullTestResult& CRemoteSubTestCaseRunner::GetTestCaseResult() const
       
   786     {
       
   787     return iResult;
       
   788     }
       
   789 
       
   790 const CStartInfo* CRemoteSubTestCaseRunner::GetStartInfo() const
       
   791     {
       
   792     return iStartInfo;
       
   793     }
       
   794 
       
   795 CSubTestCaseRunner::TSubTestCaseType CRemoteSubTestCaseRunner::GetType() const
       
   796     {
       
   797     return ESTTRemote;
       
   798     }
       
   799 
       
   800 CRemoteSubTestCaseRunner::CRemoteSubTestCaseRunner( CTestRunner* aTestRunner, 
       
   801         CSlave* aSlave, CRemoteCallsProxy* aRemoteCallsProxy )
       
   802 :iTestRunner( aTestRunner ), iSlave( aSlave ), 
       
   803  iRemoteCallsProxy( aRemoteCallsProxy ), iOperationTimeout( 30000000 )
       
   804     {
       
   805     CActiveScheduler::Add( this );
       
   806     }
       
   807 
       
   808 void CRemoteSubTestCaseRunner::ConstructL()
       
   809     {
       
   810     User::LeaveIfError( iTimeoutTimer.CreateLocal() );
       
   811     iNestedASLoop = new(ELeave)CActiveSchedulerWait;
       
   812     iSlave->RegisterSubTestCaseL( this );
       
   813     }
       
   814 
       
   815 void CRemoteSubTestCaseRunner::RunL()
       
   816     {
       
   817     // Test case timeouted.
       
   818     iCurrentOperation = ECONone;
       
   819     iOperationResult = KErrTimedOut;
       
   820     iNestedASLoop->AsyncStop();
       
   821     }
       
   822 
       
   823 void CRemoteSubTestCaseRunner::DoCancel()
       
   824     {
       
   825     if ( GetState() == ESTSRunning )
       
   826         {
       
   827         TRAPD( err, CancelSubTestCaseL() );
       
   828         if ( err != KErrNone )
       
   829             {
       
   830             RDebug::Print( _L("Unexpected error during slave subtestcase cancel %d"), err );
       
   831             }
       
   832         }
       
   833     
       
   834     iTimeoutTimer.Cancel();
       
   835     }
       
   836 
       
   837 void CRemoteSubTestCaseRunner::Reset()
       
   838     {
       
   839     delete iStartInfo;
       
   840     iStartInfo = NULL;
       
   841     iTestCaseId = 0;
       
   842     iRunResult = 0;
       
   843     iResult = TFullTestResult();
       
   844     }
       
   845 
       
   846 CSlave* CRemoteSubTestCaseRunner::GetSlave()
       
   847     {
       
   848     return iSlave;
       
   849     }
       
   850 
       
   851 TUint16 CRemoteSubTestCaseRunner::GetTestCaseId() const
       
   852     {
       
   853     return iTestCaseId;
       
   854     }
       
   855 
       
   856 void CRemoteSubTestCaseRunner::NotifyTestCaseStartedL( TUint16 aTestCaseId )
       
   857     {
       
   858     if ( !iNestedASLoop->IsStarted() || ( iCurrentOperation != ECORunSubtestCase ) )
       
   859         {
       
   860         User::Leave( KErrNotReady );
       
   861         }
       
   862     
       
   863     iTestCaseId = aTestCaseId;
       
   864 
       
   865     Cancel();
       
   866     
       
   867     iNestedASLoop->AsyncStop();
       
   868     iCurrentOperation = ECONone;
       
   869     iOperationResult = KErrNone;
       
   870     }
       
   871 
       
   872 void CRemoteSubTestCaseRunner::NotifyTestCaseRunError( const TFullTestResult& aTestCaseResult )
       
   873     {
       
   874     if ( !iNestedASLoop->IsStarted() || ( iCurrentOperation != ECORunSubtestCase ) )
       
   875         {
       
   876         User::Leave( KErrNotReady );
       
   877         }
       
   878     
       
   879     Cancel();
       
   880     
       
   881     iResult = aTestCaseResult;
       
   882     
       
   883     iNestedASLoop->AsyncStop();
       
   884     iCurrentOperation = ECONone;
       
   885     iOperationResult = iResult.iCaseExecutionResultCode;
       
   886     }
       
   887 
       
   888 void CRemoteSubTestCaseRunner::NotifyTestCasePausedL()
       
   889     {
       
   890     if ( !iNestedASLoop->IsStarted() || ( iCurrentOperation != ECOPauseSubtestCase ) )
       
   891         {
       
   892         User::Leave( KErrNotReady );
       
   893         }
       
   894     
       
   895     Cancel();
       
   896     
       
   897     iNestedASLoop->AsyncStop();
       
   898     iCurrentOperation = ECONone;
       
   899     iOperationResult = KErrNone;
       
   900     }
       
   901 
       
   902 void CRemoteSubTestCaseRunner::NotifyTestCaseResumedL()
       
   903     {
       
   904     if ( !iNestedASLoop->IsStarted() || ( iCurrentOperation != ECOResumeSubtestCase ) )
       
   905         {
       
   906         User::Leave( KErrNotReady );
       
   907         }
       
   908     
       
   909     Cancel();
       
   910     
       
   911     iNestedASLoop->AsyncStop();
       
   912     iCurrentOperation = ECONone;
       
   913     iOperationResult = KErrNone;
       
   914     }
       
   915 
       
   916 void CRemoteSubTestCaseRunner::NotifyTestCaseCancelledL()
       
   917     {
       
   918     if ( !iNestedASLoop->IsStarted() || ( iCurrentOperation != ECOCancelSubtestCase ) )
       
   919         {
       
   920         User::Leave( KErrNotReady );
       
   921         }
       
   922     
       
   923     Cancel();
       
   924     
       
   925     iNestedASLoop->AsyncStop();
       
   926     iCurrentOperation = ECONone;
       
   927     iOperationResult = KErrNone;
       
   928     }
       
   929 
       
   930 void CRemoteSubTestCaseRunner::NotifyTestCaseFinishedL( const TFullTestResult& aTestCaseResult )
       
   931     {
       
   932     iRunResult = KErrNone;
       
   933     iResult = aTestCaseResult;
       
   934     
       
   935     iState = ESTSIdle;
       
   936     
       
   937     // Report sub test case result to  CTestRunner
       
   938     iTestRunner->SubTestCaseFinishedL( this );    
       
   939     }
       
   940 
       
   941 TBool CRemoteSubTestCaseRunner::IsRunSubTestCaseRequestOngoing() const
       
   942     {
       
   943     if ( iCurrentOperation == ECORunSubtestCase )
       
   944         {
       
   945         return ETrue;
       
   946         }
       
   947     return EFalse;
       
   948     }
       
   949 
       
   950 // EOF