stif/TestEngine/src/TestCaseController.cpp
changeset 0 a03f92240627
child 10 381827f66490
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 implementation of 
       
    15 * CTestCaseController class member functions.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <e32svr.h>
       
    22 #include <e32uid.h>
       
    23 #include <StifLogger.h>
       
    24 #include "StifTFwIfProt.h"
       
    25 #include "TestCaseController.h"
       
    26 #include "TestModuleController.h"
       
    27 #include "TestReport.h"
       
    28 #include "Logging.h"
       
    29 #include "StifHWReset.h"
       
    30 
       
    31 // EXTERNAL DATA STRUCTURES
       
    32 // None
       
    33 
       
    34 // EXTERNAL FUNCTION PROTOTYPES  
       
    35 // None
       
    36 
       
    37 // CONSTANTS
       
    38 // None
       
    39 
       
    40 // MACROS
       
    41 // None
       
    42 
       
    43 // LOCAL CONSTANTS AND MACROS
       
    44 // None
       
    45 
       
    46 // MODULE DATA STRUCTURES
       
    47 // None
       
    48 
       
    49 // LOCAL FUNCTION PROTOTYPES
       
    50 // None
       
    51 
       
    52 // FORWARD DECLARATIONS
       
    53 // None
       
    54 
       
    55 // ==================== LOCAL FUNCTIONS =======================================
       
    56 // None
       
    57 
       
    58 
       
    59 #define LOGGER iEngine->Logger()
       
    60 
       
    61 // ================= MEMBER FUNCTIONS =========================================
       
    62 
       
    63 /*
       
    64 -------------------------------------------------------------------------------
       
    65 
       
    66     Class: CTestCaseController
       
    67 
       
    68     Method: CTestCaseController
       
    69 
       
    70     Description: Default constructor
       
    71 
       
    72     C++ default constructor can NOT contain any code, that
       
    73     might leave.
       
    74 
       
    75     Parameters: CTestEngine* aEngine: in: Pointer to CTestEngine
       
    76                 RTestExecution aTestExecution: in: Handle to RTestExecution
       
    77                 CAtsLogger& aAtsLogger: in: Reference to CAtsLogger
       
    78                 RTestExecution aTestExecution: in: Handle to RTestExecution
       
    79                 const TTestInfo& aTestInfo: in: Test Info
       
    80 
       
    81     Return Values: None
       
    82 
       
    83     Errors/Exceptions: None
       
    84 
       
    85     Status: Approved
       
    86 
       
    87 -------------------------------------------------------------------------------
       
    88 */
       
    89 CTestCaseController::CTestCaseController( CTestEngine* aEngine,
       
    90                                           CTestReport* aTestReport,
       
    91                                           CAtsLogger& aAtsLogger,
       
    92                                           RTestExecution aTestExecution,
       
    93                                           const TTestInfo& aTestInfo ) :
       
    94     CActive( CActive::EPriorityStandard ),
       
    95     iEngine( aEngine ),
       
    96     iTestReport( aTestReport ),
       
    97     iTestExecution( aTestExecution ),
       
    98     iTestInfo( aTestInfo ),
       
    99     iState( ETestCaseIdle ),
       
   100     iResultPckg( iResult ),
       
   101     iAtsLogger( aAtsLogger )
       
   102     {
       
   103     CActiveScheduler::Add( this );
       
   104 
       
   105     }
       
   106 
       
   107 /*
       
   108 -------------------------------------------------------------------------------
       
   109 
       
   110     Class: CTestCaseController
       
   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: Proposal
       
   125 
       
   126 -------------------------------------------------------------------------------
       
   127 */
       
   128 void CTestCaseController::ConstructL()
       
   129     {
       
   130     __TRACE( KVerbose, ( _L( "CTestCaseController::ConstructL, [%S]" ), &iTestInfo.iTestCaseInfo.iTitle ) );
       
   131 
       
   132     // Logger settings
       
   133     TLoggerSettings loggerSettings;
       
   134     loggerSettings.iCreateLogDirectories = EFalse;
       
   135     loggerSettings.iOverwrite = ETrue;
       
   136     loggerSettings.iTimeStamp = EFalse;
       
   137     loggerSettings.iLineBreak = EFalse;
       
   138     loggerSettings.iEventRanking = EFalse;
       
   139     loggerSettings.iThreadId = EFalse;
       
   140     loggerSettings.iHardwareFormat = CStifLogger::ETxt;
       
   141     loggerSettings.iHardwareOutput = CStifLogger::ERDebug;
       
   142     loggerSettings.iEmulatorFormat = CStifLogger::ETxt;
       
   143     loggerSettings.iEmulatorOutput = CStifLogger::ERDebug;
       
   144     loggerSettings.iUnicode = EFalse;
       
   145     loggerSettings.iAddTestCaseTitle = EFalse;
       
   146 
       
   147     iRDebugLogger = CStifLogger::NewL( _L( "" ), _L( "" ), loggerSettings );
       
   148 
       
   149     // If timeout is specified, then create timeout handler.
       
   150     if ( iTestInfo.iTestCaseInfo.iTimeout > TTimeIntervalMicroSeconds(0) )
       
   151         {
       
   152         iTimeout = CTestCaseTimeout::NewL ( this,
       
   153                                             iTestInfo.iTestCaseInfo.iTimeout );
       
   154         }
       
   155 
       
   156     }
       
   157 
       
   158 /*
       
   159 -------------------------------------------------------------------------------
       
   160 
       
   161     Class: CTestCaseController
       
   162 
       
   163     Method: NewL
       
   164 
       
   165     Description: Two-phased constructor.
       
   166 
       
   167     Parameters: CTestEngine* aEngine: in: Pointer to CTestEngine
       
   168                 CTestReport* aTestReport: in: Pointer to CTestReport
       
   169                 CAtsLogger& aAtsLogger: in: Reference to CAtsLogger
       
   170                 RTestExecution aTestExecution: in: Handle to RTestExecution
       
   171                 const TTestInfo& aTestInfo: in: Test Info
       
   172 
       
   173     Return Values: CTestCaseController* : pointer to created object
       
   174 
       
   175     Errors/Exceptions: Leaves if construction of CTestCaseController fails
       
   176 
       
   177     Status: Approved
       
   178 
       
   179 -------------------------------------------------------------------------------
       
   180 */
       
   181 CTestCaseController* CTestCaseController::NewL( CTestEngine* aEngine,
       
   182                                                CTestReport* aTestReport,
       
   183                                                CAtsLogger& aAtsLogger,
       
   184                                                RTestExecution aTestExecution,
       
   185                                                const TTestInfo& aTestInfo )
       
   186     {
       
   187     CTestCaseController* self = new ( ELeave ) CTestCaseController( aEngine,
       
   188         aTestReport, aAtsLogger, aTestExecution, aTestInfo );
       
   189     CleanupStack::PushL( self );
       
   190     self->ConstructL();
       
   191     CleanupStack::Pop( self );
       
   192     return self;
       
   193 
       
   194     }
       
   195 
       
   196 /*
       
   197 -------------------------------------------------------------------------------
       
   198 
       
   199     Class: CTestCaseController
       
   200 
       
   201     Method: ~CTestCaseController
       
   202 
       
   203     Description: Destructor
       
   204 
       
   205     Parameters: None
       
   206 
       
   207     Return Values: None
       
   208 
       
   209     Errors/Exceptions: None
       
   210 
       
   211     Status: Proposal
       
   212 
       
   213 -------------------------------------------------------------------------------
       
   214 */
       
   215 CTestCaseController::~CTestCaseController()
       
   216     {
       
   217     __TRACE( KVerbose, ( _L( "CTestCaseController::~CTestCaseController" ) ) );
       
   218     Cancel();
       
   219 
       
   220     delete iRDebugLogger;
       
   221     delete iTimeout;
       
   222 
       
   223     }
       
   224 
       
   225 /*
       
   226 -------------------------------------------------------------------------------
       
   227 
       
   228     Class: CTestCaseController
       
   229 
       
   230     Method: StartL
       
   231 
       
   232     Description: Start active object
       
   233 
       
   234     Parameters: const RMessage& aMessage: in: Server message
       
   235 
       
   236     Return Values: None
       
   237 
       
   238     Errors/Exceptions: None
       
   239 
       
   240     Status: Proposal
       
   241 
       
   242 -------------------------------------------------------------------------------
       
   243 */
       
   244 void CTestCaseController::StartL( const RMessage2& aMessage )
       
   245     {
       
   246     iRDebugLogger->Log( _L( "Starting testcase [%S]" ), &iTestInfo.iTestCaseInfo.iTitle );
       
   247     __TRACE( KInit, ( _L(" Starting testcase [%S]"), &iTestInfo.iTestCaseInfo.iTitle ) );
       
   248 
       
   249     // Check that this request is not pending!!
       
   250     __ASSERT_ALWAYS( iState != ETestCaseRunning,
       
   251                             iEngine->PanicClient( EReqPending, aMessage ) );
       
   252     iMessage = aMessage;
       
   253 
       
   254     iState = ETestCaseRunning;
       
   255     
       
   256     SetActive();
       
   257 
       
   258     iTestExecution.RunTestCase( iResultPckg, iStatus );    
       
   259 
       
   260     // If testcase has timeout (handler), then start it
       
   261     if ( iTimeout )
       
   262         {
       
   263         iTimeout->Start();
       
   264         }
       
   265 
       
   266     }
       
   267 
       
   268 /*
       
   269 -------------------------------------------------------------------------------
       
   270 
       
   271     Class: CTestCaseController
       
   272 
       
   273     Method: Timeout
       
   274 
       
   275     Description: Timeouts active request.
       
   276     - Cancel request
       
   277 
       
   278     Parameters: None
       
   279 
       
   280     Return Values: None
       
   281 
       
   282     Errors/Exceptions: None
       
   283 
       
   284     Status: Proposal
       
   285 
       
   286 -------------------------------------------------------------------------------
       
   287 */
       
   288 void CTestCaseController::Timeout()
       
   289     {
       
   290     if ( iState == ETestCaseRunning )
       
   291         {
       
   292         iState = ETestCaseTimeout;
       
   293         Cancel();
       
   294         }
       
   295 
       
   296     }
       
   297 
       
   298 /*
       
   299 -------------------------------------------------------------------------------
       
   300 
       
   301     Class: CTestCaseController
       
   302 
       
   303     Method: RunL
       
   304 
       
   305     Description: RunL handles completed requests. Leaves are handled in
       
   306                  RunError method
       
   307 
       
   308     Parameters: None
       
   309 
       
   310     Return Values: None
       
   311 
       
   312     Errors/Exceptions: Leaves if AddTestCaseResultL leaves
       
   313 
       
   314     Status: Approved
       
   315 
       
   316 -------------------------------------------------------------------------------
       
   317 */
       
   318 void CTestCaseController::RunL()
       
   319     {
       
   320     iState = ETestCaseCompleted;
       
   321 
       
   322 
       
   323     // "iStatus.Int()" error code is received from system's framework not from
       
   324     // test case execution.
       
   325     if ( iStatus.Int() != KErrNone )
       
   326         {
       
   327             if ( iStatus.Int() == KErrServerTerminated )
       
   328             {
       
   329             // something went badly wrong!
       
   330             __TRACE( KInit, ( CStifLogger::ERed, 
       
   331                 _L( "TestCase [%S] cannot be executed, STIF panics with[%d]" ),
       
   332                 &iTestInfo.iTestCaseInfo.iTitle,
       
   333                 iStatus.Int() ) );       
       
   334                 
       
   335             __TRACE( KInit, ( CStifLogger::ERed, 
       
   336                 _L( "Possible reason: Test case has paniced seriously" ) ) );
       
   337 
       
   338             // We don't leave here but we write information to 
       
   339             // forward(testreport etc.)
       
   340             _LIT( KLeaveInfo, "Test case execution fails" );
       
   341             // Sets test case to crash category
       
   342             iResult.iCaseExecutionResultCode = iStatus.Int();
       
   343             // Test case result
       
   344             iResult.iTestResult.iResult = iStatus.Int();
       
   345             iResult.iTestResult.iResultDes = KLeaveInfo;
       
   346 
       
   347             } 
       
   348         
       
   349             else
       
   350             {   
       
   351         // For example testmodule's NewL or testmodule's constructor has
       
   352         // leaved and STIF cannot connect to test module
       
   353         __TRACE( KInit, ( CStifLogger::ERed, 
       
   354             _L( "TestCase [%S] cannot execute, TestModule loading operations fails with[%d]" ),
       
   355             &iTestInfo.iTestCaseInfo.iTitle,
       
   356             iStatus.Int() ) );
       
   357         __TRACE( KInit, ( CStifLogger::ERed, 
       
   358             _L( "Possible reason: TestModule's NewL or Constructor has leaved and STIF cannot connect to test module" ) ) );
       
   359 
       
   360         // We don't leave here but we write information to 
       
   361         // forward(testreport etc.)
       
   362         _LIT( KLeaveInfo, "TestModule loading fails, cannot connect to the TestModule" );
       
   363         // Sets test case to crash category
       
   364         iResult.iCaseExecutionResultCode = iStatus.Int();
       
   365         // Test case result
       
   366         iResult.iTestResult.iResult = iStatus.Int();
       
   367         iResult.iTestResult.iResultDes = KLeaveInfo;
       
   368             }
       
   369         }
       
   370         
       
   371 	else
       
   372 	{
       
   373 			
       
   374     // Cancel event request, because the testcase is completed
       
   375     iTestExecution.CancelAsyncRequest( ETestExecutionNotifyEvent );        
       
   376 	}
       
   377 
       
   378     // Test case is executed
       
   379     if( iTestInfo.iTestCaseInfo.iTitle.Length() > 0 )
       
   380         {
       
   381         iRDebugLogger->Log( _L( "TestCase [%S] finished with verdict[%d]" ),
       
   382                             &iTestInfo.iTestCaseInfo.iTitle,
       
   383                             iResult.iTestResult.iResult );
       
   384 
       
   385         __TRACE( KInit, ( _L( " TestCase [%S] finished with verdict[%d]" ),
       
   386                             &iTestInfo.iTestCaseInfo.iTitle,
       
   387                             iResult.iTestResult.iResult ) );
       
   388         }
       
   389     else
       
   390         {
       
   391         iRDebugLogger->Log( _L( "TestCase [%d] finished with verdict[%d]" ),
       
   392                             iTestInfo.iTestCaseInfo.iCaseNumber,
       
   393                             iResult.iTestResult.iResult );
       
   394 
       
   395         __TRACE( KInit, ( _L( " TestCase [%d] finished with verdict[%d]" ),
       
   396                             iTestInfo.iTestCaseInfo.iCaseNumber,
       
   397                             iResult.iTestResult.iResult ) );
       
   398         }
       
   399     __TRACE( KVerbose, ( 
       
   400             _L( "CTestCaseController::RunL: iStatus=[%d]" ), iStatus.Int() ));
       
   401 
       
   402     GenerateXmlLogL();
       
   403 
       
   404     // Report test case result
       
   405     if( iTestReport )
       
   406         {
       
   407         iTestReport->AddTestCaseResultL( iTestInfo, iResult, iStatus.Int() );
       
   408         iTestReport->UpdateReportSummaryL();
       
   409         }
       
   410 
       
   411     TRAPD( ret, iMessage.WriteL( 0, iResultPckg ) );
       
   412 
       
   413     // Case done
       
   414     iMessage.Complete( ret );
       
   415 
       
   416     }
       
   417 
       
   418 /*
       
   419 -------------------------------------------------------------------------------
       
   420 
       
   421     Class: CTestCaseController
       
   422 
       
   423     Method: DoCancel
       
   424 
       
   425     Description: Cancel active request
       
   426 
       
   427     Parameters: None
       
   428 
       
   429     Return Values: None
       
   430 
       
   431     Errors/Exceptions: None
       
   432 
       
   433     Status: Proposal
       
   434 
       
   435 -------------------------------------------------------------------------------
       
   436 */
       
   437 void CTestCaseController::DoCancel()
       
   438     {
       
   439 
       
   440     switch ( iState )
       
   441         {
       
   442         case ETestCaseRunning:
       
   443             iTestExecution.CancelAsyncRequest( ETestExecutionRunTestCase );
       
   444             if( iTestInfo.iTestCaseInfo.iTitle.Length() > 0 )
       
   445                 {
       
   446                 iRDebugLogger->Log( _L( "TestCase [%S] execution aborted" ),
       
   447                                     &iTestInfo.iTestCaseInfo.iTitle );
       
   448 
       
   449                 __TRACE( KInit, ( _L( "TestCase [%S] execution aborted" ),
       
   450                                     &iTestInfo.iTestCaseInfo.iTitle ) );
       
   451                 }
       
   452             else
       
   453                 {
       
   454                 iRDebugLogger->Log( _L( "TestCase [%S] execution aborted" ),
       
   455                                     iTestInfo.iTestCaseInfo.iCaseNumber );
       
   456 
       
   457                 __TRACE( KInit, ( _L( "TestCase [%S] execution aborted" ),
       
   458                                     iTestInfo.iTestCaseInfo.iCaseNumber ) );
       
   459                 }
       
   460             break;
       
   461         case ETestCaseTimeout:
       
   462             iTestExecution.CancelAsyncRequest( ETestExecutionRunTestCase );
       
   463             // Update result to timeout
       
   464             iResult.iCaseExecutionResultType = TFullTestResult::ECaseTimeout;
       
   465             iResult.iTestResult.iResultDes = _L("Test case was timeouted and cancelled");
       
   466 
       
   467             if( iTestReport )
       
   468                 {
       
   469                 iTestReport->AddTestCaseResultL( iTestInfo, iResult, KErrTimedOut );
       
   470                 }
       
   471 
       
   472             if( iTestInfo.iTestCaseInfo.iTitle.Length() > 0 )
       
   473                 {
       
   474                 iRDebugLogger->Log( _L( "TestCase [%S] finished with verdict[%d]" ),
       
   475                                     &iTestInfo.iTestCaseInfo.iTitle,
       
   476                                     iResult.iTestResult.iResult );
       
   477 
       
   478                 __TRACE( KInit, ( _L( " TestCase [%S] finished with verdict[%d]" ),
       
   479                                     &iTestInfo.iTestCaseInfo.iTitle,
       
   480                                     iResult.iTestResult.iResult ) );
       
   481                 }
       
   482             else
       
   483                 {
       
   484                 iRDebugLogger->Log( _L( "TestCase [%d] finished with verdict[%d]" ),
       
   485                                     iTestInfo.iTestCaseInfo.iCaseNumber,
       
   486                                     iResult.iTestResult.iResult );
       
   487 
       
   488                 __TRACE( KInit, ( _L( " TestCase [%d] finished with verdict[%d]" ),
       
   489                                     iTestInfo.iTestCaseInfo.iCaseNumber,
       
   490                                     iResult.iTestResult.iResult ) );
       
   491                 }            
       
   492             
       
   493             break;
       
   494         case ETestCaseSuicided:
       
   495             {
       
   496             //Store current results because cancel operation overwrites it
       
   497             TInt currentTestResult = iResult.iTestResult.iResult;
       
   498             TInt currentExecutionResult = iResult.iCaseExecutionResultCode;
       
   499             iTestExecution.CancelAsyncRequest(ETestExecutionRunTestCase);
       
   500             // Update result to suicide
       
   501             switch(iStopExecutionType)
       
   502                 {
       
   503                 case EOk:
       
   504                     iResult.iCaseExecutionResultType = TFullTestResult::ECaseExecuted;
       
   505                     iResult.iTestResult.iResultDes = _L("Test case passed (StopExecution())");
       
   506                     break;
       
   507                 case EFail:
       
   508                     iResult.iCaseExecutionResultType = TFullTestResult::ECaseExecuted;
       
   509                     iResult.iTestResult.iResultDes = _L("Test case failed (StopExecution())");
       
   510                     break;
       
   511                 default: //EAbort
       
   512                     iResult.iCaseExecutionResultType = TFullTestResult::ECaseSuicided;
       
   513                     iResult.iTestResult.iResultDes = _L("Test case killed (StopExecution())");
       
   514                 }
       
   515             iResult.iTestResult.iResult = currentTestResult;
       
   516             iResult.iCaseExecutionResultCode = currentExecutionResult;
       
   517             }
       
   518             if(iTestReport)
       
   519                 {
       
   520                 iTestReport->AddTestCaseResultL(iTestInfo, iResult, KErrNone);
       
   521                 }
       
   522 
       
   523             // Log some message
       
   524             if(iTestInfo.iTestCaseInfo.iTitle.Length() > 0)
       
   525                 {
       
   526                 _LIT(KTestCaseDesc, "TestCase [%S] finished with verdict [%d]");
       
   527                 switch(iStopExecutionType)
       
   528                     {
       
   529                     case EOk:
       
   530                         {
       
   531                         _LIT(KTestCaseResult, "***Testcase PASSED***");
       
   532 
       
   533                         iRDebugLogger->Log(KTestCaseResult);
       
   534                         __TRACE(KInit, (KTestCaseResult));
       
   535                         iRDebugLogger->Log(KTestCaseDesc, &iTestInfo.iTestCaseInfo.iTitle, iResult.iTestResult.iResult);
       
   536                         __TRACE(KInit, (KTestCaseDesc, &iTestInfo.iTestCaseInfo.iTitle, iResult.iTestResult.iResult));
       
   537                         break;
       
   538                         }
       
   539                     case EFail:
       
   540                         {
       
   541                         _LIT(KTestCaseResult, "***Testcase FAILED***");
       
   542 
       
   543                         iRDebugLogger->Log(KTestCaseResult);
       
   544                         __TRACE(KInit, (KTestCaseResult));
       
   545                         iRDebugLogger->Log(KTestCaseDesc, &iTestInfo.iTestCaseInfo.iTitle, iResult.iTestResult.iResult);
       
   546                         __TRACE(KInit, (KTestCaseDesc, &iTestInfo.iTestCaseInfo.iTitle, iResult.iTestResult.iResult));
       
   547                         break;
       
   548                         }
       
   549                     default: //EAbort
       
   550                         {
       
   551                         _LIT(KTestCaseResult, "***Testcase KILLED***");
       
   552 
       
   553                         iRDebugLogger->Log(KTestCaseResult);
       
   554                         __TRACE(KInit, (KTestCaseResult));
       
   555                         iRDebugLogger->Log(KTestCaseDesc, &iTestInfo.iTestCaseInfo.iTitle, iResult.iTestResult.iResult);
       
   556                         __TRACE(KInit, (KTestCaseDesc, &iTestInfo.iTestCaseInfo.iTitle, iResult.iTestResult.iResult));
       
   557                         }
       
   558                     }
       
   559                 }
       
   560             else
       
   561                 {
       
   562                 _LIT(KTestCaseDesc, "TestCase [%d] finished with verdict [%d]");
       
   563                 switch(iStopExecutionType)
       
   564                     {
       
   565                     case EOk:
       
   566                         {
       
   567                         _LIT(KTestCaseResult, "***Testcase PASSED***");
       
   568 
       
   569                         iRDebugLogger->Log(KTestCaseResult);
       
   570                         __TRACE(KInit, (KTestCaseResult));
       
   571                         iRDebugLogger->Log(KTestCaseDesc, iTestInfo.iTestCaseInfo.iCaseNumber, iResult.iTestResult.iResult);
       
   572                         __TRACE(KInit, (KTestCaseDesc, iTestInfo.iTestCaseInfo.iCaseNumber, iResult.iTestResult.iResult));
       
   573                         break;
       
   574                         }
       
   575                     case EFail:
       
   576                         {
       
   577                         _LIT(KTestCaseResult, "***Testcase FAILED***");
       
   578 
       
   579                         iRDebugLogger->Log(KTestCaseResult);
       
   580                         __TRACE(KInit, (KTestCaseResult));
       
   581                         iRDebugLogger->Log(KTestCaseDesc, iTestInfo.iTestCaseInfo.iCaseNumber, iResult.iTestResult.iResult);
       
   582                         __TRACE(KInit, (KTestCaseDesc, iTestInfo.iTestCaseInfo.iCaseNumber, iResult.iTestResult.iResult));
       
   583                         break;
       
   584                         }
       
   585                     default: //EAbort
       
   586                         {
       
   587                         _LIT(KTestCaseResult, "***Testcase KILLED***");
       
   588 
       
   589                         iRDebugLogger->Log(KTestCaseResult);
       
   590                         __TRACE(KInit, (KTestCaseResult));
       
   591                         iRDebugLogger->Log(KTestCaseDesc, iTestInfo.iTestCaseInfo.iCaseNumber, iResult.iTestResult.iResult);
       
   592                         __TRACE(KInit, (KTestCaseDesc, iTestInfo.iTestCaseInfo.iCaseNumber, iResult.iTestResult.iResult));
       
   593                         }
       
   594                     }
       
   595                 }
       
   596             break;
       
   597         case ETestCaseIdle:
       
   598         case ETestCaseCompleted:
       
   599         default:
       
   600             // DoCancel called in wrong state => Panic
       
   601             _LIT( KTestCaseController, "CTestCaseController" );
       
   602             User::Panic( KTestCaseController, EDoCancelDisorder );
       
   603             break;
       
   604         }
       
   605 
       
   606     // Write result and complete 
       
   607     TRAPD( ret, iMessage.WriteL( 0, iResultPckg ) );
       
   608 
       
   609     iMessage.Complete( ret );  
       
   610         
       
   611     iState = ETestCaseCompleted;
       
   612     
       
   613     // Generate xml result log
       
   614     GenerateXmlLogL();
       
   615 
       
   616     }
       
   617 
       
   618 /*
       
   619 -------------------------------------------------------------------------------
       
   620 
       
   621     Class: CTestCaseController
       
   622 
       
   623     Method: RunError
       
   624 
       
   625     Description: Handle errors.
       
   626 
       
   627     Parameters: TInt aError: in: Symbian OS error: Error code
       
   628 
       
   629     Return Values: TInt KErrNone: Always returned KErrNone
       
   630 
       
   631     Errors/Exceptions: None
       
   632 
       
   633     Status: Approved
       
   634 
       
   635 -------------------------------------------------------------------------------
       
   636 */
       
   637 TInt CTestCaseController::RunError( TInt aError )
       
   638     {
       
   639     __TRACE( KError, ( CStifLogger::ERed, 
       
   640         _L( "CTestCaseController::RunError: Test case execution has failed! aError=[%d]" ), aError ) );
       
   641     TInt completionError = aError;
       
   642 
       
   643     // Write result, because it could include descriptive result for
       
   644     // failed case
       
   645     TRAPD( err, iMessage.WriteL( 0, iResultPckg ); );
       
   646 
       
   647     if ( err != KErrNone )
       
   648         {
       
   649         completionError = err;
       
   650         }
       
   651 
       
   652     // Complete message with error
       
   653     iMessage.Complete( completionError );
       
   654 
       
   655     return KErrNone;
       
   656 
       
   657     }
       
   658 
       
   659 /*
       
   660 -------------------------------------------------------------------------------
       
   661 
       
   662     Class: CTestCaseController
       
   663 
       
   664     Method: GenerateXmlLogL
       
   665 
       
   666     Description: Generate XML log.
       
   667 
       
   668     Parameters: None
       
   669 
       
   670     Return Values: None
       
   671     
       
   672     Errors/Exceptions: None
       
   673 
       
   674     Status: Proposal
       
   675 
       
   676 -------------------------------------------------------------------------------
       
   677 */
       
   678 void CTestCaseController::GenerateXmlLogL()
       
   679     {
       
   680     
       
   681     // Report result with AtsLogger
       
   682     iAtsLogger.BeginTestCaseReportL( iTestInfo.iTestCaseInfo.iTitle, 
       
   683                                      KErrNone,  // Expected result not supported
       
   684                                      iResult.iStartTime );
       
   685     
       
   686     if( iResult.iCaseExecutionResultCode != KErrNone )
       
   687         {
       
   688         iAtsLogger.SetTestCaseResultL( iResult.iCaseExecutionResultCode );
       
   689         iAtsLogger.TestCaseFailed();  
       
   690         if( iResult.iTestResult.iResultDes.Length() > 0 )
       
   691             {
       
   692             iAtsLogger.ErrorL( iResult.iTestResult.iResultDes );   
       
   693             } 
       
   694         }
       
   695      else
       
   696         {
       
   697         iAtsLogger.SetTestCaseResultL( iResult.iTestResult.iResult ); 
       
   698         if( iResult.iTestResult.iResult == KErrNone )
       
   699             {
       
   700             iAtsLogger.TestCasePassed();  
       
   701             }
       
   702         else
       
   703             {
       
   704             iAtsLogger.TestCaseFailed();  
       
   705             if( iResult.iTestResult.iResultDes.Length() > 0 )
       
   706                 {
       
   707                 iAtsLogger.ErrorL( iResult.iTestResult.iResultDes );    
       
   708                 }
       
   709             }
       
   710         }
       
   711     // Set test case result to ATS Logger
       
   712     iAtsLogger.EndTestCaseL();
       
   713 
       
   714     }
       
   715 
       
   716 /*
       
   717 -------------------------------------------------------------------------------
       
   718 
       
   719     Class: CTestCaseController
       
   720 
       
   721     Method: GetTestCaseInfo
       
   722 
       
   723     Description: Get testcase info(test module, config file, test case, etc).
       
   724 
       
   725     Parameters: TTestInfo& aTestInfo: inout: Test information
       
   726 
       
   727     Return Values: None
       
   728     
       
   729     Errors/Exceptions: None
       
   730 
       
   731     Status: Proposal
       
   732 
       
   733 -------------------------------------------------------------------------------
       
   734 */
       
   735 void CTestCaseController::GetTestCaseInfo( TTestInfo& aTestInfo )
       
   736     {
       
   737     aTestInfo = iTestInfo;
       
   738 
       
   739     }
       
   740 
       
   741 /*
       
   742 -------------------------------------------------------------------------------
       
   743 
       
   744     Class: CTestCaseController
       
   745 
       
   746     Method: Suicide
       
   747 
       
   748     Description: Cancels active request.
       
   749 
       
   750     Parameters: aCode: the reason of suicide
       
   751 
       
   752     Return Values: None
       
   753 
       
   754     Errors/Exceptions: None
       
   755 
       
   756     Status: Proposal
       
   757 
       
   758 -------------------------------------------------------------------------------
       
   759 */
       
   760 void CTestCaseController::Suicide(TStopExecutionType aType, TInt aCode)
       
   761     {
       
   762     if(iState == ETestCaseRunning)
       
   763         {
       
   764         iStopExecutionType = aType;
       
   765         switch(iStopExecutionType)
       
   766             {
       
   767             case EOk:
       
   768                 iResult.iTestResult.iResult = KErrNone;
       
   769                 iResult.iCaseExecutionResultCode = KErrNone;
       
   770                 break;
       
   771             case EFail:
       
   772                 iResult.iTestResult.iResult = aCode;
       
   773                 iResult.iCaseExecutionResultCode = KErrNone;
       
   774                 break;
       
   775             default: //EAbort
       
   776                 iResult.iTestResult.iResult = aCode;
       
   777                 iResult.iCaseExecutionResultCode = aCode;
       
   778             }
       
   779         iState = ETestCaseSuicided;
       
   780         Cancel();
       
   781         }
       
   782     }
       
   783 
       
   784 /*
       
   785 -------------------------------------------------------------------------------
       
   786 
       
   787     DESCRIPTION
       
   788 
       
   789     This module contains implementation of CTestProgressNotifier class member
       
   790     functions.
       
   791 
       
   792 -------------------------------------------------------------------------------
       
   793 */
       
   794 
       
   795 // ================= MEMBER FUNCTIONS =========================================
       
   796 
       
   797 /*
       
   798 -------------------------------------------------------------------------------
       
   799 
       
   800     Class: CTestProgressNotifier
       
   801 
       
   802     Method: CTestProgressNotifier
       
   803 
       
   804     Description: Default constructor
       
   805 
       
   806     C++ default constructor can NOT contain any code, that
       
   807     might leave.
       
   808 
       
   809     Parameters: None
       
   810 
       
   811     Return Values: None
       
   812 
       
   813     Errors/Exceptions: None
       
   814 
       
   815     Status: Approved
       
   816 
       
   817 -------------------------------------------------------------------------------
       
   818 */
       
   819 CTestProgressNotifier::CTestProgressNotifier( CTestEngine* aEngine,
       
   820                              RTestExecution aTestExecution ) :
       
   821     CActive( CActive::EPriorityStandard ),
       
   822     iEngine( aEngine ),
       
   823     iTestExecution( aTestExecution ),
       
   824     iState( ETestProgressIdle ),
       
   825     iProgressPckg( iProgress )
       
   826     {
       
   827     CActiveScheduler::Add( this );
       
   828 
       
   829     }
       
   830 
       
   831 /*
       
   832 -------------------------------------------------------------------------------
       
   833 
       
   834     Class: CTestProgressNotifier
       
   835 
       
   836     Method: ConstructL
       
   837 
       
   838     Description: Symbian OS second phase constructor
       
   839 
       
   840     Symbian OS default constructor can leave.
       
   841 
       
   842     Parameters: None
       
   843 
       
   844     Return Values: None
       
   845 
       
   846     Errors/Exceptions: None
       
   847 
       
   848     Status: Approved
       
   849 
       
   850 -------------------------------------------------------------------------------
       
   851 */
       
   852 void CTestProgressNotifier::ConstructL()
       
   853     {
       
   854     __TRACE( KVerbose, ( _L( "CTestProgressNotifier::ConstructL" ) ) );
       
   855     }
       
   856 
       
   857 /*
       
   858 -------------------------------------------------------------------------------
       
   859 
       
   860     Class: CTestProgressNotifier
       
   861 
       
   862     Method: NewL
       
   863 
       
   864     Description: Two-phased constructor.
       
   865 
       
   866     Parameters: CTestEngine* aEngine: in: Pointer to CTestEngine
       
   867                 RTestExecution aTestExecution: in: Handle to RTestExecution
       
   868 
       
   869     Return Values: CTestProgressNotifier* : pointer to created object
       
   870 
       
   871     Errors/Exceptions: Leaves if construction of CTestProgressNotifier fails
       
   872 
       
   873     Status: Approved
       
   874 
       
   875 -------------------------------------------------------------------------------
       
   876 */
       
   877 CTestProgressNotifier* CTestProgressNotifier::NewL( CTestEngine* aEngine,
       
   878                              RTestExecution aTestExecution )
       
   879     {
       
   880     CTestProgressNotifier* self = new ( ELeave ) CTestProgressNotifier(
       
   881         aEngine, aTestExecution );
       
   882     CleanupStack::PushL( self );
       
   883     self->ConstructL();
       
   884     CleanupStack::Pop( self );
       
   885     return self;
       
   886 
       
   887     }
       
   888 
       
   889 /*
       
   890 -------------------------------------------------------------------------------
       
   891 
       
   892     Class: CTestProgressNotifier
       
   893 
       
   894     Method: ~CTestProgressNotifier
       
   895 
       
   896     Description: Destructor
       
   897 
       
   898     Parameters: None
       
   899 
       
   900     Return Values: None
       
   901 
       
   902     Errors/Exceptions: None
       
   903 
       
   904     Status: Approved
       
   905 
       
   906 -------------------------------------------------------------------------------
       
   907 */
       
   908 CTestProgressNotifier::~CTestProgressNotifier()
       
   909     {
       
   910     __TRACE( KVerbose, ( _L( "CTestProgressNotifier::~CTestProgressNotifier" ) ) );
       
   911     Cancel();
       
   912 
       
   913     }
       
   914 
       
   915 /*
       
   916 -------------------------------------------------------------------------------
       
   917 
       
   918     Class: CTestProgressNotifier
       
   919 
       
   920     Method: StartL
       
   921 
       
   922     Description: Start active object
       
   923 
       
   924     Parameters: const RMessage& aMessage: in: Server message
       
   925 
       
   926     Return Values: None
       
   927 
       
   928     Errors/Exceptions: None
       
   929 
       
   930     Status: Approved
       
   931 
       
   932 -------------------------------------------------------------------------------
       
   933 */
       
   934 void CTestProgressNotifier::StartL( const RMessage2& aMessage )
       
   935     {
       
   936     __TRACE( KVerbose, ( _L( "CTestProgressNotifier::StartL" ) ) );
       
   937     // Check that this request is not pending!!
       
   938     __ASSERT_ALWAYS( iState != ETestProgressPending,
       
   939                         iEngine->PanicClient( EReqPending, aMessage ) );
       
   940     iMessage = aMessage;
       
   941 
       
   942     iState = ETestProgressPending;
       
   943     SetActive();
       
   944 
       
   945     iTestExecution.NotifyProgress( iProgressPckg, iStatus );
       
   946 
       
   947     }
       
   948 
       
   949 /*
       
   950 -------------------------------------------------------------------------------
       
   951 
       
   952     Class: CTestProgressNotifier
       
   953 
       
   954     Method: RunL
       
   955 
       
   956     Description: RunL handles completed requests.
       
   957 
       
   958     Parameters: None
       
   959 
       
   960     Return Values: None
       
   961 
       
   962     Errors/Exceptions: Leaves if WriteL leaves
       
   963                        Leaves if iStatus is not KErrNone or KErrEof
       
   964                        Leaves are handled in RunError method
       
   965 
       
   966     Status: Approved
       
   967 
       
   968 -------------------------------------------------------------------------------
       
   969 */
       
   970 void CTestProgressNotifier::RunL()
       
   971     {
       
   972     __TRACE( KVerbose, (_L("CTestProgressNotifier::RunL: iStatus=[%d]" ), iStatus.Int() ));
       
   973 
       
   974     iState = ETestProgressCompleted;
       
   975 
       
   976     // Check that request was successful or completed with acceptable error
       
   977     // KErrEof is acceptable error and it means that the test case will not
       
   978     // send progresses anymore (because it is closed)
       
   979     if ( KErrNone == iStatus.Int() )
       
   980         {
       
   981         iMessage.WriteL( 0, iProgressPckg );
       
   982         }
       
   983     else if ( KErrEof != iStatus.Int() )
       
   984         {
       
   985         // Leave, error will be handled in RunError
       
   986         User::Leave( iStatus.Int() );
       
   987         }
       
   988 
       
   989     // Complete message
       
   990     iMessage.Complete( iStatus.Int() );
       
   991 
       
   992     }
       
   993 
       
   994 /*
       
   995 -------------------------------------------------------------------------------
       
   996 
       
   997     Class: CTestProgressNotifier
       
   998 
       
   999     Method: DoCancel
       
  1000 
       
  1001     Description: Cancel active request
       
  1002 
       
  1003     Parameters: None
       
  1004 
       
  1005     Return Values: None
       
  1006 
       
  1007     Errors/Exceptions: None
       
  1008 
       
  1009     Status: Approved
       
  1010 
       
  1011 -------------------------------------------------------------------------------
       
  1012 */
       
  1013 void CTestProgressNotifier::DoCancel()
       
  1014     {
       
  1015     switch ( iState )
       
  1016         {
       
  1017         case ETestProgressPending:
       
  1018             iTestExecution.CancelAsyncRequest( ETestExecutionNotifyProgress );
       
  1019             iMessage.Complete( KErrCancel );
       
  1020             break;
       
  1021         case ETestProgressIdle:
       
  1022         case ETestProgressCompleted:
       
  1023         default:
       
  1024             // DoCancel called in wrong state => Panic
       
  1025             _LIT( KTestProgressNotifier, "CTestProgressNotifier" );
       
  1026             User::Panic( KTestProgressNotifier, EDoCancelDisorder );
       
  1027             break;
       
  1028         }
       
  1029     iState = ETestProgressIdle;
       
  1030 
       
  1031     }
       
  1032 
       
  1033 /*
       
  1034 -------------------------------------------------------------------------------
       
  1035 
       
  1036     Class: CTestProgressNotifier
       
  1037 
       
  1038     Method: RunError
       
  1039 
       
  1040     Description: Handle errors.
       
  1041 
       
  1042     Parameters: TInt aError: in: Symbian OS error: Error code
       
  1043 
       
  1044     Return Values: TInt KErrNone: Always returned KErrNone
       
  1045 
       
  1046     Errors/Exceptions: None
       
  1047 
       
  1048     Status: Approved
       
  1049 
       
  1050 -------------------------------------------------------------------------------
       
  1051 */
       
  1052 TInt CTestProgressNotifier::RunError( TInt aError )
       
  1053     {
       
  1054     // Complete message with error
       
  1055     iMessage.Complete( aError );
       
  1056 
       
  1057     return KErrNone;
       
  1058 
       
  1059     }
       
  1060 
       
  1061 /*
       
  1062 -------------------------------------------------------------------------------
       
  1063 
       
  1064     DESCRIPTION
       
  1065 
       
  1066     This module contains implementation of CTestEventNotifier class member
       
  1067     functions.
       
  1068 
       
  1069 -------------------------------------------------------------------------------
       
  1070 */
       
  1071 
       
  1072 // ================= MEMBER FUNCTIONS =========================================
       
  1073 
       
  1074 /*
       
  1075 -------------------------------------------------------------------------------
       
  1076 
       
  1077     Class: CTestEventNotifier
       
  1078 
       
  1079     Method: CTestEventNotifier
       
  1080 
       
  1081     Description: Default constructor
       
  1082 
       
  1083     C++ default constructor can NOT contain any code, that
       
  1084     might leave.
       
  1085 
       
  1086     Parameters: CTestEngine* aEngine: in: Pointer to CTestEngine
       
  1087                 RTestExecution aTestExecution: in: Handle to RTestExecution
       
  1088 
       
  1089     Return Values: None
       
  1090 
       
  1091     Errors/Exceptions: None
       
  1092 
       
  1093     Status: Approved
       
  1094 
       
  1095 -------------------------------------------------------------------------------
       
  1096 */
       
  1097 CTestEventNotifier::CTestEventNotifier( CTestEngine* aEngine, 
       
  1098                                         RTestExecution aTestExecution ) :
       
  1099     CActive( CActive::EPriorityStandard ),
       
  1100     iEngine( aEngine ),
       
  1101     iTestExecution( aTestExecution ),
       
  1102     iState( ETestEventIdle ),
       
  1103     iEventPckg( iEvent ),
       
  1104     iEventNotifyPckg( iEventNotify ),
       
  1105     iController( NULL )
       
  1106     {
       
  1107     CActiveScheduler::Add( this );
       
  1108 
       
  1109     }
       
  1110 
       
  1111 /*
       
  1112 -------------------------------------------------------------------------------
       
  1113 
       
  1114     Class: CTestEventNotifier
       
  1115 
       
  1116     Method: ConstructL
       
  1117 
       
  1118     Description: Symbian OS second phase constructor
       
  1119 
       
  1120     Symbian OS default constructor can leave.
       
  1121 
       
  1122     Parameters: None
       
  1123 
       
  1124     Return Values: None
       
  1125 
       
  1126     Errors/Exceptions: None
       
  1127 
       
  1128     Status: Approved
       
  1129 
       
  1130 -------------------------------------------------------------------------------
       
  1131 */
       
  1132 void CTestEventNotifier::ConstructL( )
       
  1133     {
       
  1134     __TRACE( KVerbose, ( _L( "CTestEventNotifier::ConstructL" ) ) );
       
  1135 
       
  1136     }
       
  1137 
       
  1138 /*
       
  1139 -------------------------------------------------------------------------------
       
  1140 
       
  1141     Class: CTestEventNotifier
       
  1142 
       
  1143     Method: NewL
       
  1144 
       
  1145     Description: Two-phased constructor.
       
  1146 
       
  1147     Parameters: CTestEngine* aEngine: in: Pointer to CTestEngine
       
  1148                 RTestExecution aTestExecution: in: Handle to RTestExecution
       
  1149 
       
  1150     Return Values: CTestEventNotifier* : pointer to created object
       
  1151 
       
  1152     Errors/Exceptions: Leaves if construction of CTestEventNotifier fails
       
  1153 
       
  1154     Status: Approved
       
  1155 
       
  1156 -------------------------------------------------------------------------------
       
  1157 */
       
  1158 CTestEventNotifier* CTestEventNotifier::NewL( CTestEngine* aEngine,
       
  1159                                               RTestExecution aTestExecution )
       
  1160     {
       
  1161     CTestEventNotifier* self = new ( ELeave ) CTestEventNotifier(
       
  1162         aEngine, aTestExecution );
       
  1163     CleanupStack::PushL( self );
       
  1164     self->ConstructL();
       
  1165     CleanupStack::Pop( self );
       
  1166     return self;
       
  1167 
       
  1168     }
       
  1169 
       
  1170 /*
       
  1171 -------------------------------------------------------------------------------
       
  1172 
       
  1173     Class: CTestEventNotifier
       
  1174 
       
  1175     Method: ~CTestEventNotifier
       
  1176 
       
  1177     Description: Destructor
       
  1178 
       
  1179     Parameters: None
       
  1180 
       
  1181     Return Values: None
       
  1182 
       
  1183     Errors/Exceptions: None
       
  1184 
       
  1185     Status: Approved
       
  1186 
       
  1187 -------------------------------------------------------------------------------
       
  1188 */
       
  1189 CTestEventNotifier::~CTestEventNotifier()
       
  1190     {
       
  1191     __TRACE( KVerbose, ( _L( "CTestEventNotifier::~CTestEventNotifier" ) ) );
       
  1192     Cancel();
       
  1193     iEventArray.ResetAndDestroy();
       
  1194     iEventArray.Close();
       
  1195     delete iController;
       
  1196 
       
  1197     }
       
  1198 
       
  1199 /*
       
  1200 -------------------------------------------------------------------------------
       
  1201 
       
  1202     Class: CTestEventNotifier
       
  1203 
       
  1204     Method: StartL
       
  1205 
       
  1206     Description: Start active object
       
  1207 
       
  1208     Parameters: None
       
  1209 
       
  1210     Return Values: None
       
  1211 
       
  1212     Errors/Exceptions: None
       
  1213 
       
  1214     Status: Approved
       
  1215 
       
  1216 -------------------------------------------------------------------------------
       
  1217 */
       
  1218 void CTestEventNotifier::Start()
       
  1219     {
       
  1220     __TRACE( KVerbose, ( _L( "CTestEventNotifier::StartL" ) ) );
       
  1221     // Check that this request is not pending!!
       
  1222     __ASSERT_ALWAYS( iState != ETestEventPending,
       
  1223         User::Leave( KErrAlreadyExists ) );
       
  1224 
       
  1225     iEvent.SetType( TEventIf::EEnable );
       
  1226     iState = ETestEventPending;
       
  1227     iTestExecution.NotifyEvent( iEventPckg, iStatus );
       
  1228     SetActive();
       
  1229 
       
  1230     }
       
  1231 
       
  1232 /*
       
  1233 -------------------------------------------------------------------------------
       
  1234 
       
  1235     Class: CTestEventNotifier
       
  1236 
       
  1237     Method: RunL
       
  1238 
       
  1239     Description: RunL handles completed requests.
       
  1240 
       
  1241     Parameters: None
       
  1242 
       
  1243     Return Values: None
       
  1244 
       
  1245     Errors/Exceptions: Leaves if iStatus is not KErrNone
       
  1246                        Leaves if iState is not ETestEventPending
       
  1247                        Leaves if some leaving method called here leaves
       
  1248 
       
  1249     Status: Approved
       
  1250 
       
  1251 -------------------------------------------------------------------------------
       
  1252 */
       
  1253 void CTestEventNotifier::RunL()
       
  1254     {
       
  1255     __TRACE( KVerbose, ( _L( "CTestEventNotifier::RunL: iStatus=[%d]" ), iStatus.Int() ) );
       
  1256 
       
  1257     User::LeaveIfError( iStatus.Int() );
       
  1258 
       
  1259     switch( iState )
       
  1260         {
       
  1261         case ETestEventPending:
       
  1262             {
       
  1263             iState = ETestEventCompleted;
       
  1264             
       
  1265             switch( iEvent.Type() )
       
  1266                 {
       
  1267                 case TEventIf::EReqEvent:
       
  1268                     {
       
  1269                     __RDEBUG( ( _L("CTestEventNotifier(ReqEvent) %S"), 
       
  1270                         &iEvent.Name() ));
       
  1271                     if( iEngine->IsStateEventAndSet( iEvent.Name() ) )
       
  1272                         {
       
  1273                         __TRACE( KVerbose, ( _L( "CTestEventNotifier::RunL: Requested Global event already set" ) ) );
       
  1274                         TEventIf event( TEventIf::ESetEvent, iEvent.Name(),
       
  1275                                         TEventIf::EState );
       
  1276                         TEventIfPckg eventPckg( event );
       
  1277                         TRequestStatus status;
       
  1278                         iTestExecution.NotifyEvent( eventPckg, status );
       
  1279                         User::WaitForRequest( status );
       
  1280                         }
       
  1281                     //add to iEventArray
       
  1282                     HBufC* name = iEvent.Name().AllocLC();
       
  1283                     if( iEventArray.Append( name ) != KErrNone )
       
  1284                         {
       
  1285                         User::Leave( KErrNoMemory );
       
  1286                         }
       
  1287                     CleanupStack::Pop( name );
       
  1288                     }
       
  1289                     break;                    
       
  1290                 case TEventIf::ERelEvent:
       
  1291                     {
       
  1292                     __TRACE( KVerbose, ( _L( "CTestEventNotifier(RelEvent) %S" ), &iEvent.Name() ) );
       
  1293                     //remove from iEventArray
       
  1294                     TInt count = iEventArray.Count();
       
  1295                     const TDesC& eventName = iEvent.Name();
       
  1296                     TInt i;
       
  1297                     for( i = 0; i < count; i++ )
       
  1298                         {
       
  1299                         TPtrC name = iEventArray[i]->Des();
       
  1300                         if( name == eventName )
       
  1301                             {
       
  1302                             HBufC* tmp = iEventArray[i];
       
  1303                             iEventArray.Remove( i );
       
  1304                             delete tmp;
       
  1305                             break;
       
  1306                             }
       
  1307                         }
       
  1308                     // Check that event was found
       
  1309                     if( i == count )
       
  1310                         {
       
  1311                         User::Leave( KErrGeneral );
       
  1312                         }         
       
  1313                     }
       
  1314                     break;                    
       
  1315                 case TEventIf::ESetEvent:
       
  1316                     {
       
  1317                     __RDEBUG( ( _L("CTestEventNotifier(SetEvent) %S"), 
       
  1318                         &iEvent.Name() ));
       
  1319                     iController = iEngine->CtlEventL( iEvent, iStatus );
       
  1320                     SetActive();
       
  1321                     return;
       
  1322                     }
       
  1323                 case TEventIf::EUnsetEvent:
       
  1324                     {
       
  1325                     __RDEBUG( ( _L("CTestEventNotifier(UnsetEvent) %S"), 
       
  1326                         &iEvent.Name() ));
       
  1327                     iController = iEngine->CtlEventL( iEvent, iStatus );
       
  1328                     SetActive();
       
  1329                     return;
       
  1330                     }
       
  1331                 default:
       
  1332                     {
       
  1333                     User::Leave( KErrGeneral );
       
  1334                     }
       
  1335                 }
       
  1336             // Set request again
       
  1337             Start();                
       
  1338             // Otherwise request is enabled again later
       
  1339             }
       
  1340             break;
       
  1341         case ETestEventCompleted:
       
  1342             __RDEBUG( ( _L("CTestEventNotifier(Complete)")));
       
  1343             Start();
       
  1344             break;
       
  1345         default:
       
  1346             User::Leave( KErrGeneral );
       
  1347             break;
       
  1348         }
       
  1349 
       
  1350     }
       
  1351 
       
  1352 /*
       
  1353 -------------------------------------------------------------------------------
       
  1354 
       
  1355     Class: CTestEventNotifier
       
  1356 
       
  1357     Method: DoCancel
       
  1358 
       
  1359     Description: Cancel active request
       
  1360 
       
  1361     Parameters: None
       
  1362 
       
  1363     Return Values: None
       
  1364 
       
  1365     Errors/Exceptions: None
       
  1366 
       
  1367     Status: Approved
       
  1368 
       
  1369 -------------------------------------------------------------------------------
       
  1370 */
       
  1371 void CTestEventNotifier::DoCancel()
       
  1372     {
       
  1373     __TRACE( KVerbose, ( _L( "CTestEventNotifier::DoCancel" ) ) );
       
  1374 
       
  1375     switch ( iState )
       
  1376         {
       
  1377         case ETestEventPending:
       
  1378             iTestExecution.CancelAsyncRequest( ETestExecutionNotifyEvent );
       
  1379             break;
       
  1380         case ETestEventCompleted:
       
  1381             delete iController;
       
  1382             iController = NULL;
       
  1383             break;
       
  1384         default:
       
  1385             // DoCancel called in wrong state => Panic
       
  1386             _LIT( KTestEventNotifier, "CTestEventNotifier" );
       
  1387             User::Panic( KTestEventNotifier, EDoCancelDisorder );
       
  1388             break;
       
  1389         }
       
  1390 
       
  1391     iState = ETestEventIdle;
       
  1392     iEventArray.ResetAndDestroy();
       
  1393 
       
  1394     }
       
  1395 
       
  1396 /*
       
  1397 -------------------------------------------------------------------------------
       
  1398 
       
  1399     Class: CTestEventNotifier
       
  1400 
       
  1401     Method: RunError
       
  1402 
       
  1403     Description: Handle errors.
       
  1404 
       
  1405     Parameters: TInt aError: in: Symbian OS error: Error code
       
  1406 
       
  1407     Return Values: TInt KErrNone: Always returned KErrNone
       
  1408 
       
  1409     Errors/Exceptions: None
       
  1410 
       
  1411     Status: Approved
       
  1412 
       
  1413 -------------------------------------------------------------------------------
       
  1414 */
       
  1415 TInt CTestEventNotifier::RunError( TInt aError )
       
  1416     {
       
  1417     switch ( iState )
       
  1418         {
       
  1419         case ETestEventPending:
       
  1420             if( aError != KErrCancel )
       
  1421                 {
       
  1422                 __TRACE( KError, ( CStifLogger::ERed, _L( "CTestEventNotifier::RunError %d"), aError) );
       
  1423                 }
       
  1424             else
       
  1425                 {
       
  1426                 __TRACE( KVerbose, ( _L( "CTestEventNotifier stopped")) );
       
  1427                 }
       
  1428 
       
  1429             // We stop event notifier if we get error here
       
  1430             // Clear requested event list
       
  1431             iEventArray.ResetAndDestroy();
       
  1432             break;
       
  1433         case ETestEventCompleted:
       
  1434             // Do not close here
       
  1435             __TRACE( KError, ( CStifLogger::ERed, _L( "CTestEventNotifier::RunError %d"), aError) );
       
  1436             delete iController;
       
  1437             iController = NULL;
       
  1438             // forward error to testcase
       
  1439             iEvent.SetType( TEventIf::EEnable );
       
  1440             iState = ETestEventPending;
       
  1441             iTestExecution.NotifyEvent( iEventPckg, iStatus, aError );
       
  1442             SetActive();
       
  1443             break;
       
  1444         default:
       
  1445             __TRACE( KError, ( CStifLogger::ERed, _L( "CTestEventNotifier::RunError %d"), aError) );
       
  1446             // DoCancel called in wrong state => Panic
       
  1447             _LIT( KTestEventNotifier, "CTestEventNotifier" );
       
  1448             User::Panic( KTestEventNotifier, EDoCancelDisorder );
       
  1449             break;
       
  1450         }
       
  1451 
       
  1452     return KErrNone;
       
  1453 
       
  1454     }
       
  1455 
       
  1456 /*
       
  1457 -------------------------------------------------------------------------------
       
  1458 
       
  1459     Class: CTestEventNotifier
       
  1460 
       
  1461     Method: CtlEventL
       
  1462 
       
  1463     Description: Controls events
       
  1464 
       
  1465     Parameters: const TEventIf& aEvent: in: Event
       
  1466                 TRequestStatus& aStatus: in: Request status
       
  1467 
       
  1468     Return Values: None
       
  1469 
       
  1470     Errors/Exceptions: None
       
  1471 
       
  1472     Status: Approved
       
  1473 
       
  1474 -------------------------------------------------------------------------------
       
  1475 */
       
  1476 void CTestEventNotifier::CtlEvent( const TEventIf& aEvent, 
       
  1477                                     TRequestStatus& aStatus )
       
  1478     {
       
  1479     __TRACE( KVerbose, ( _L( "CTestEventNotifier::CtlEventL" ) ) );
       
  1480     const TDesC& eventName = aEvent.Name();
       
  1481     TInt count = iEventArray.Count();
       
  1482     for( TInt i = 0; i < count; i++ )
       
  1483         {
       
  1484         TPtrC name = iEventArray[i]->Des();
       
  1485         if( name == eventName )
       
  1486             {
       
  1487             iEventNotify.Copy( aEvent );
       
  1488             iTestExecution.NotifyEvent( iEventNotifyPckg, aStatus );
       
  1489             return;
       
  1490             }
       
  1491         }
       
  1492     }
       
  1493 
       
  1494 /*
       
  1495 -------------------------------------------------------------------------------
       
  1496 
       
  1497     Class: CTestEventNotifier
       
  1498 
       
  1499     Method: CheckCtlEventL
       
  1500 
       
  1501     Description: Checks if CtlEvent should be called
       
  1502 
       
  1503     Parameters: const TEventIf& aEvent: in: Event
       
  1504 
       
  1505     Return Values: ETrue: If CtlEvent sould be called.
       
  1506 
       
  1507     Errors/Exceptions: None
       
  1508 
       
  1509     Status: Approved
       
  1510 
       
  1511 -------------------------------------------------------------------------------
       
  1512 */
       
  1513 TBool CTestEventNotifier::CheckCtlEvent( const TEventIf& aEvent )
       
  1514     {
       
  1515     const TDesC& eventName = aEvent.Name();
       
  1516     TInt count = iEventArray.Count();
       
  1517     for( TInt i = 0; i < count; i++ )
       
  1518         {
       
  1519         TPtrC name = iEventArray[i]->Des();
       
  1520         if( name == eventName )
       
  1521             {
       
  1522             return ETrue;
       
  1523             }
       
  1524         }
       
  1525 
       
  1526     return EFalse;
       
  1527     }
       
  1528 
       
  1529 /*
       
  1530 -------------------------------------------------------------------------------
       
  1531 
       
  1532     DESCRIPTION
       
  1533 
       
  1534     This module contains implementation of CTestEventController class member
       
  1535     functions.
       
  1536 
       
  1537 -------------------------------------------------------------------------------
       
  1538 */
       
  1539 
       
  1540 // ================= MEMBER FUNCTIONS =========================================
       
  1541 
       
  1542 /*
       
  1543 -------------------------------------------------------------------------------
       
  1544 
       
  1545     Class: CTestEventController
       
  1546 
       
  1547     Method: CTestEventController
       
  1548 
       
  1549     Description: Default constructor
       
  1550 
       
  1551     C++ default constructor can NOT contain any code, that
       
  1552     might leave.
       
  1553 
       
  1554     Parameters: CTestEngine* aEngine: in: Pointer to CTestEngine
       
  1555                 const TEventIf& aEvent: in: Event
       
  1556 
       
  1557     Return Values: None
       
  1558 
       
  1559     Errors/Exceptions: None
       
  1560 
       
  1561     Status: Approved
       
  1562 
       
  1563 -------------------------------------------------------------------------------
       
  1564 */
       
  1565 CTestEventController::CTestEventController( CTestEngine* aEngine, 
       
  1566                                             const TEventIf& aEvent ) :
       
  1567     iEngine( aEngine ),
       
  1568     iRequestStatus( NULL ),
       
  1569     iEventPckg( iEvent ),
       
  1570     iActiveEventCmds( 0 )
       
  1571     {
       
  1572     iEvent.Copy( aEvent );
       
  1573 
       
  1574     }
       
  1575 
       
  1576 /*
       
  1577 -------------------------------------------------------------------------------
       
  1578 
       
  1579     Class: CTestEventController
       
  1580 
       
  1581     Method: ConstructL
       
  1582 
       
  1583     Description: Symbian OS second phase constructor
       
  1584 
       
  1585     Symbian OS default constructor can leave.
       
  1586 
       
  1587     Parameters: TRequestStatus* aStatus: in: Request status
       
  1588 
       
  1589     Return Values: None
       
  1590 
       
  1591     Errors/Exceptions: None
       
  1592 
       
  1593     Status: Approved
       
  1594 
       
  1595 -------------------------------------------------------------------------------
       
  1596 */
       
  1597 void CTestEventController::ConstructL( TRequestStatus* aStatus )
       
  1598     {
       
  1599     iEngine->Logger()->Log( _L( "CTestEventController::ConstructL" ) );
       
  1600 
       
  1601     if( CheckEventsL() == 0 )
       
  1602         {
       
  1603         // No request was pending, complete immediately
       
  1604         User::RequestComplete( aStatus, KErrNone );
       
  1605         }
       
  1606     else
       
  1607         {
       
  1608         iRequestStatus = aStatus;
       
  1609         }
       
  1610 
       
  1611     }
       
  1612 
       
  1613 /*
       
  1614 -------------------------------------------------------------------------------
       
  1615 
       
  1616     Class: CTestEventController
       
  1617 
       
  1618     Method: ConstructL
       
  1619 
       
  1620     Description: Symbian OS second phase constructor
       
  1621 
       
  1622     Symbian OS default constructor can leave.
       
  1623 
       
  1624     Parameters: RMessage& aMessage: inout: Message to be handled
       
  1625 
       
  1626     Return Values: None
       
  1627 
       
  1628     Errors/Exceptions: None
       
  1629 
       
  1630     Status: Approved
       
  1631 
       
  1632 -------------------------------------------------------------------------------
       
  1633 */
       
  1634 void CTestEventController::ConstructL( RMessage2& aMessage )
       
  1635     {
       
  1636     iEngine->Logger()->Log( _L( "CTestEventController::ConstructL" ) );
       
  1637 
       
  1638     if( CheckEventsL() == 0 )
       
  1639         {
       
  1640         // No request was pending, complete immediately
       
  1641         aMessage.Complete( KErrNone );
       
  1642         }
       
  1643     else
       
  1644         {
       
  1645         iMessage = aMessage;
       
  1646         }
       
  1647 
       
  1648     }
       
  1649 
       
  1650 /*
       
  1651 -------------------------------------------------------------------------------
       
  1652 
       
  1653     Class: CTestEventNotifier
       
  1654 
       
  1655     Method: NewL
       
  1656 
       
  1657     Description: Two-phased constructor.
       
  1658 
       
  1659     Parameters: CTestEngine* aEngine: in: Pointer to CTestEngine
       
  1660                 const TEventIf& aEvent: in: Event
       
  1661                 TRequestStatus* aStatus: in: Request status
       
  1662 
       
  1663     Return Values: CTestEventController* : pointer to created object
       
  1664 
       
  1665     Errors/Exceptions: Leaves if construction of CTestEventController fails
       
  1666 
       
  1667     Status: Approved
       
  1668 
       
  1669 -------------------------------------------------------------------------------
       
  1670 */
       
  1671 
       
  1672 CTestEventController* CTestEventController::NewL( CTestEngine* aEngine,
       
  1673                                                   const TEventIf& aEvent,
       
  1674                                                   TRequestStatus* aStatus )
       
  1675     {
       
  1676     CTestEventController* self = 
       
  1677         new ( ELeave )CTestEventController( aEngine, aEvent );
       
  1678     CleanupStack::PushL( self );
       
  1679     self->ConstructL( aStatus );
       
  1680     CleanupStack::Pop( self );
       
  1681     return self;
       
  1682 
       
  1683     }
       
  1684 
       
  1685 /*
       
  1686 -------------------------------------------------------------------------------
       
  1687 
       
  1688     Class: CTestEventNotifier
       
  1689 
       
  1690     Method: NewL
       
  1691 
       
  1692     Description: Two-phased constructor.
       
  1693 
       
  1694     Parameters: CTestEngine* aEngine: in: Pointer to CTestEngine
       
  1695                 const TEventIf& aEvent: in: Event
       
  1696                 RMessage& aMessage: inout: Message to be handled
       
  1697 
       
  1698     Return Values: CTestEventController* : pointer to created object
       
  1699 
       
  1700     Errors/Exceptions: Leaves if construction of CTestEventController fails
       
  1701 
       
  1702     Status: Approved
       
  1703 
       
  1704 -------------------------------------------------------------------------------
       
  1705 */
       
  1706 CTestEventController* CTestEventController::NewL( CTestEngine* aEngine,
       
  1707                                                   const TEventIf& aEvent,
       
  1708                                                   RMessage2& aMessage )
       
  1709     {
       
  1710     CTestEventController* self = 
       
  1711         new ( ELeave )CTestEventController( aEngine, aEvent );
       
  1712     CleanupStack::PushL( self );
       
  1713     self->ConstructL( aMessage );
       
  1714     CleanupStack::Pop( self );
       
  1715     return self;
       
  1716 
       
  1717     }
       
  1718 
       
  1719 /*
       
  1720 -------------------------------------------------------------------------------
       
  1721 
       
  1722     Class: CTestEventController
       
  1723 
       
  1724     Method: ~CTestEventController
       
  1725 
       
  1726     Description: Destructor
       
  1727 
       
  1728     Parameters: None
       
  1729 
       
  1730     Return Values: None
       
  1731 
       
  1732     Errors/Exceptions: None
       
  1733 
       
  1734     Status: Proposal
       
  1735 
       
  1736 -------------------------------------------------------------------------------
       
  1737 */
       
  1738 
       
  1739 CTestEventController::~CTestEventController()
       
  1740     {
       
  1741 	if( iEngine != NULL )
       
  1742 		{
       
  1743 		if( iEngine->Logger() != NULL )
       
  1744 			{
       
  1745 			iEngine->Logger()->Log( _L( "CTestEventController::~CTestEventController" ) );
       
  1746 			}
       
  1747 		}
       
  1748     
       
  1749     if( iRequestStatus )
       
  1750         {
       
  1751         // Must be completed if pending, otherwise  
       
  1752         // CTestEventNotifier::DoCancel blocks
       
  1753         User::RequestComplete( iRequestStatus, KErrCancel );
       
  1754         }
       
  1755             
       
  1756     iEventCallBacks.ResetAndDestroy();
       
  1757     iEventCallBacks.Close();
       
  1758 
       
  1759     }
       
  1760 
       
  1761 /*
       
  1762 -------------------------------------------------------------------------------
       
  1763 
       
  1764     Class: CTestEventController
       
  1765 
       
  1766     Method: CheckEventsL
       
  1767 
       
  1768     Description: Check all events.
       
  1769 
       
  1770     Parameters: None
       
  1771 
       
  1772     Return Values: TInt: Active event commands
       
  1773 
       
  1774     Errors/Exceptions: Leaves if CtlEventL leaves
       
  1775                        Leaves if memory allocation fails
       
  1776                        Leaves if unset event not found from pending 
       
  1777                             state event list 
       
  1778 
       
  1779     Status: Approved
       
  1780 
       
  1781 -------------------------------------------------------------------------------
       
  1782 */  
       
  1783 TInt CTestEventController::CheckEventsL()
       
  1784     {
       
  1785     iEngine->Logger()->Log( _L( "CTestEventController::CheckEventsL" ) );
       
  1786 
       
  1787     iActiveEventCmds += CheckClientEventsL();
       
  1788     iActiveEventCmds += CheckTestcaseEventsL();
       
  1789 
       
  1790     return iActiveEventCmds;
       
  1791 
       
  1792     }
       
  1793 
       
  1794 /*
       
  1795 -------------------------------------------------------------------------------
       
  1796 
       
  1797     Class: CTestEventController
       
  1798 
       
  1799     Method: CheckClientEventsL
       
  1800 
       
  1801     Description: Check client events.
       
  1802 
       
  1803     Parameters: None
       
  1804 
       
  1805     Return Values: TInt: Request of pending
       
  1806 
       
  1807     Errors/Exceptions: Leaves if CtlEventL leaves
       
  1808                        Leaves if memory allocation fails
       
  1809                        Leaves if unset event not found from pending 
       
  1810                             state event list 
       
  1811 
       
  1812     Status: Approved
       
  1813 
       
  1814 -------------------------------------------------------------------------------
       
  1815 */  
       
  1816 TInt CTestEventController::CheckClientEventsL()
       
  1817     {
       
  1818     iEngine->Logger()->Log( _L( "CTestEventController::CheckClientEventsL" ) );
       
  1819     TInt reqPending = 0;
       
  1820 
       
  1821     // Check client event requests
       
  1822     TInt count = iEngine->ClientEvents().Count();
       
  1823     for( TInt index = 0; index < count; index++ )
       
  1824         {
       
  1825         if( iEngine->ClientEvents()[index]->Name() == iEvent.Name() )
       
  1826             {
       
  1827             TEventMsg* event = iEngine->ClientEvents()[index]; 
       
  1828             if( iEvent.Type() == TEventIf::ESetEvent )
       
  1829                 {
       
  1830                 // Set found event 
       
  1831                 event->Set( iEvent.EventType() );
       
  1832                 }
       
  1833             else if( iEvent.Type() == TEventIf::EUnsetEvent )
       
  1834                 {
       
  1835                 // Unset found event
       
  1836                 // Create callback for change notifier
       
  1837                 TCallBack callBack( EventCallBack, this );
       
  1838                 CCallBack* eventCallBack = new (ELeave)CCallBack( callBack,
       
  1839                                                     CActive::EPriorityHigh );
       
  1840                 CleanupStack::PushL( eventCallBack );
       
  1841                 
       
  1842                 event->Unset( eventCallBack->Status() ); 
       
  1843                 reqPending++;
       
  1844                 eventCallBack->SetActive();
       
  1845                 User::LeaveIfError( iEventCallBacks.Append( eventCallBack ) );
       
  1846                 CleanupStack::Pop( eventCallBack );
       
  1847                 }       
       
  1848             break;
       
  1849             }
       
  1850         }
       
  1851 
       
  1852     return reqPending;
       
  1853 
       
  1854     }
       
  1855 
       
  1856 /*
       
  1857 -------------------------------------------------------------------------------
       
  1858 
       
  1859     Class: CTestEventController
       
  1860 
       
  1861     Method: CheckTestcaseEventsL
       
  1862 
       
  1863     Description: Check testcase events.
       
  1864 
       
  1865     Parameters: None
       
  1866 
       
  1867     Return Values: TInt: Request of pending
       
  1868 
       
  1869     Errors/Exceptions: Leaves if CtlEventL leaves
       
  1870                        Leaves if memory allocation fails
       
  1871                        Leaves if unset event not found from pending 
       
  1872                             state event list 
       
  1873 
       
  1874     Status: Approved
       
  1875 
       
  1876 -------------------------------------------------------------------------------
       
  1877 */
       
  1878 TInt CTestEventController::CheckTestcaseEventsL()
       
  1879     {
       
  1880     TInt reqPending = 0;
       
  1881     TCallBack callBack( EventCallBack, this );
       
  1882     CCallBack* eventCallBack = NULL;
       
  1883 
       
  1884     // Then check testcase event requests
       
  1885     TInt count = iEngine->TestCaseArray().Count();
       
  1886     eventCallBack = new (ELeave)CCallBack( callBack, 
       
  1887                                            CActive::EPriorityHigh );
       
  1888     CleanupStack::PushL( eventCallBack );
       
  1889     for ( TInt index = 0; index < count; index++ )
       
  1890         {
       
  1891 
       
  1892         if( iEngine->TestCaseArray()[index]->CheckCtlEvent( iEvent ))
       
  1893             {
       
  1894             reqPending++;
       
  1895             eventCallBack->SetActive();
       
  1896             iEngine->TestCaseArray()[index]->CtlEvent( iEvent, 
       
  1897                                                           eventCallBack->Status() );                                                          
       
  1898             User::LeaveIfError( iEventCallBacks.Append( eventCallBack ) );
       
  1899             CleanupStack::Pop( eventCallBack );
       
  1900             eventCallBack = new (ELeave)CCallBack( callBack, 
       
  1901                                                    CActive::EPriorityHigh );
       
  1902             CleanupStack::PushL( eventCallBack );    
       
  1903             }
       
  1904         }
       
  1905     CleanupStack::PopAndDestroy( eventCallBack );
       
  1906     return reqPending;
       
  1907 
       
  1908     }
       
  1909 
       
  1910 /*
       
  1911 -------------------------------------------------------------------------------
       
  1912 
       
  1913     Class: CTestEventController
       
  1914 
       
  1915     Method: EventComplete
       
  1916 
       
  1917     Description: EventComplete handles completed event requests.
       
  1918 
       
  1919     Parameters: None
       
  1920 
       
  1921     Return Values: None
       
  1922 
       
  1923     Errors/Exceptions: 
       
  1924 
       
  1925     Status: Approved
       
  1926 
       
  1927 -------------------------------------------------------------------------------
       
  1928 */
       
  1929 void CTestEventController::EventComplete()
       
  1930     {
       
  1931     iEngine->Logger()->Log( _L( "CTestEventController::EventComplete" ));
       
  1932 
       
  1933     iActiveEventCmds--;
       
  1934     
       
  1935     if( iActiveEventCmds == 0 )
       
  1936         {
       
  1937         TInt error = KErrNone;
       
  1938         TInt count = iEventCallBacks.Count();
       
  1939         for( TInt i=0; i<count; i++ )
       
  1940             {
       
  1941             if( iEventCallBacks[i]->iStatus.Int() != KErrNone )
       
  1942                 {
       
  1943                 error = iEventCallBacks[i]->iStatus.Int();
       
  1944                 break;
       
  1945                 }
       
  1946             }
       
  1947         iEventCallBacks.ResetAndDestroy();
       
  1948             
       
  1949         // All event commands are completed
       
  1950         if( iRequestStatus )
       
  1951             {
       
  1952             User::RequestComplete( iRequestStatus, error );
       
  1953             }
       
  1954         else
       
  1955             {
       
  1956             // No request was pending, complete immediately
       
  1957             iMessage.Complete( error );
       
  1958             }
       
  1959         }
       
  1960 
       
  1961     }
       
  1962 
       
  1963 /*
       
  1964 -------------------------------------------------------------------------------
       
  1965 
       
  1966     Class: CTestEventController
       
  1967 
       
  1968     Method: EventCallBack
       
  1969 
       
  1970     Description: static EventCallBack handles completed event requests.
       
  1971 
       
  1972     Parameters: TAny* aTestEventController: in: Test event controller
       
  1973 
       
  1974     Return Values: TInt: returns KErrNone
       
  1975 
       
  1976     Errors/Exceptions:None
       
  1977 
       
  1978     Status: Approved
       
  1979 
       
  1980 -------------------------------------------------------------------------------
       
  1981 */
       
  1982 TInt CTestEventController::EventCallBack( TAny* aTestEventController )
       
  1983     {
       
  1984     CTestEventController* controller =
       
  1985                                 (CTestEventController*) aTestEventController;
       
  1986     controller->EventComplete();
       
  1987     return KErrNone;
       
  1988 
       
  1989     }
       
  1990     
       
  1991     
       
  1992 /*
       
  1993 -------------------------------------------------------------------------------
       
  1994 
       
  1995     DESCRIPTION
       
  1996 
       
  1997     This module contains implementation of CTestRemoteCmdNotifier class member
       
  1998     functions.
       
  1999 
       
  2000 -------------------------------------------------------------------------------
       
  2001 */
       
  2002 
       
  2003 // ================= MEMBER FUNCTIONS =========================================
       
  2004 
       
  2005 /*
       
  2006 -------------------------------------------------------------------------------
       
  2007 
       
  2008     Class: CTestProgressNotifier
       
  2009 
       
  2010     Method: CTestRemoteCmdNotifier
       
  2011 
       
  2012     Description: Default constructor
       
  2013 
       
  2014     C++ default constructor can NOT contain any code, that
       
  2015     might leave.
       
  2016 
       
  2017     Parameters: None
       
  2018 
       
  2019     Return Values: None
       
  2020 
       
  2021     Errors/Exceptions: None
       
  2022 
       
  2023     Status: Draft
       
  2024 
       
  2025 -------------------------------------------------------------------------------
       
  2026 */
       
  2027 CTestRemoteCmdNotifier::CTestRemoteCmdNotifier( CTestEngine* aEngine,
       
  2028                              RTestExecution aTestExecution,
       
  2029                              CTestCaseController* aTestCaseController,
       
  2030                              CAtsLogger& aAtsLogger ) :
       
  2031     CActive( CActive::EPriorityStandard ),
       
  2032     iEngine( aEngine ),
       
  2033     iTestExecution( aTestExecution ),
       
  2034     iState( ETestProgressIdle ),
       
  2035     iRemoteTypePckg( iRemoteType ),
       
  2036     iMsgSizePckg( iMsgSize ),
       
  2037     iTestCaseController( aTestCaseController ),
       
  2038     iAtsLogger( aAtsLogger )
       
  2039     {
       
  2040     CActiveScheduler::Add( this );
       
  2041 
       
  2042     }
       
  2043 
       
  2044 /*
       
  2045 -------------------------------------------------------------------------------
       
  2046 
       
  2047     Class: CTestRemoteCmdNotifier
       
  2048 
       
  2049     Method: ConstructL
       
  2050 
       
  2051     Description: Symbian OS second phase constructor
       
  2052 
       
  2053     Symbian OS default constructor can leave.
       
  2054 
       
  2055     Parameters: None
       
  2056 
       
  2057     Return Values: None
       
  2058 
       
  2059     Errors/Exceptions: None
       
  2060 
       
  2061     Status: Draft
       
  2062 
       
  2063 -------------------------------------------------------------------------------
       
  2064 */
       
  2065 void CTestRemoteCmdNotifier::ConstructL( )
       
  2066     {
       
  2067     __TRACE( KVerbose, ( _L( "CTestRemoteCmdNotifier::ConstructL" ) ) );
       
  2068 
       
  2069     }
       
  2070 
       
  2071 /*
       
  2072 -------------------------------------------------------------------------------
       
  2073 
       
  2074     Class: CTestRemoteCmdNotifier
       
  2075 
       
  2076     Method: NewL
       
  2077 
       
  2078     Description: Two-phased constructor.
       
  2079 
       
  2080     Parameters: CTestEngine* aEngine: in: Pointer to CTestEngine
       
  2081                 RTestExecution aTestExecution: in: Handle to RTestExecution
       
  2082 
       
  2083     Return Values: CTestRemoteCmdNotifier* : pointer to created object
       
  2084 
       
  2085     Errors/Exceptions: Leaves if construction of CTestRemoteCmdNotifier fails
       
  2086 
       
  2087     Status: Draft
       
  2088 
       
  2089 -------------------------------------------------------------------------------
       
  2090 */
       
  2091 CTestRemoteCmdNotifier* CTestRemoteCmdNotifier::NewL( CTestEngine* aEngine,
       
  2092                              RTestExecution aTestExecution,
       
  2093                              CTestCaseController* aTestCaseController,
       
  2094                              CAtsLogger& aAtsLogger )
       
  2095     {
       
  2096     CTestRemoteCmdNotifier* self = new ( ELeave ) CTestRemoteCmdNotifier(
       
  2097         aEngine, aTestExecution, aTestCaseController, aAtsLogger );
       
  2098     CleanupStack::PushL( self );
       
  2099     self->ConstructL();
       
  2100     CleanupStack::Pop( self );
       
  2101     return self;
       
  2102 
       
  2103     }
       
  2104 
       
  2105 /*
       
  2106 -------------------------------------------------------------------------------
       
  2107 
       
  2108     Class: CTestRemoteCmdNotifier
       
  2109 
       
  2110     Method: ~CTestRemoteCmdNotifier
       
  2111 
       
  2112     Description: Destructor
       
  2113 
       
  2114     Parameters: None
       
  2115 
       
  2116     Return Values: None
       
  2117 
       
  2118     Errors/Exceptions: None
       
  2119 
       
  2120     Status: Draft
       
  2121 
       
  2122 -------------------------------------------------------------------------------
       
  2123 */
       
  2124 CTestRemoteCmdNotifier::~CTestRemoteCmdNotifier()
       
  2125     {
       
  2126     __TRACE( KVerbose, ( _L( "CTestRemoteCmdNotifier::~CTestRemoteCmdNotifier" ) ) );
       
  2127     Cancel();
       
  2128 
       
  2129     delete iReceivedMsg;
       
  2130     iReceivedMsg = 0;
       
  2131 
       
  2132     }
       
  2133 
       
  2134 /*
       
  2135 -------------------------------------------------------------------------------
       
  2136 
       
  2137     Class: CTestRemoteCmdNotifier
       
  2138 
       
  2139     Method: EnableReceive
       
  2140 
       
  2141     Description: Prepare to start active object
       
  2142 
       
  2143     Parameters: const RMessage& aMessage: in: Server message
       
  2144 
       
  2145     Return Values: None
       
  2146 
       
  2147     Errors/Exceptions: None
       
  2148 
       
  2149     Status: Draft
       
  2150 
       
  2151 -------------------------------------------------------------------------------
       
  2152 */
       
  2153 void CTestRemoteCmdNotifier::EnableReceive( const RMessage2& aMessage )
       
  2154     {
       
  2155     __TRACE( KVerbose, ( _L( "CTestRemoteCmdNotifier::EnableReceive" ) ) );
       
  2156     
       
  2157     iMessage = aMessage;
       
  2158     iMessageAvail = ETrue;
       
  2159     
       
  2160     Start( aMessage );
       
  2161 
       
  2162     }
       
  2163     
       
  2164 /*
       
  2165 -------------------------------------------------------------------------------
       
  2166 
       
  2167     Class: CTestRemoteCmdNotifier
       
  2168 
       
  2169     Method: GetReceivedMsg
       
  2170 
       
  2171     Description: Read received message
       
  2172 
       
  2173     Parameters: const RMessage& aMessage: in: Server message
       
  2174 
       
  2175     Return Values: None
       
  2176 
       
  2177     Errors/Exceptions: None
       
  2178 
       
  2179     Status: Draft
       
  2180 
       
  2181 -------------------------------------------------------------------------------
       
  2182 */
       
  2183 void CTestRemoteCmdNotifier::GetReceivedMsg( const RMessage2& aMessage )
       
  2184     {
       
  2185     __TRACE( KVerbose, ( _L( "CTestRemoteCmdNotifier::GetReceivedMsg" ) ) );
       
  2186     
       
  2187     TInt ret = KErrNone;
       
  2188     if( iReceivedMsg )
       
  2189         {
       
  2190         TRAP( ret, aMessage.WriteL( 0, iReceivedMsg->Des() ) );
       
  2191         delete iReceivedMsg;
       
  2192         iReceivedMsg = 0;
       
  2193         }
       
  2194     else
       
  2195         {
       
  2196         ret = KErrNotFound;
       
  2197         }
       
  2198         
       
  2199     // Complete message
       
  2200     aMessage.Complete( ret );
       
  2201                 
       
  2202     }
       
  2203 
       
  2204 /*
       
  2205 -------------------------------------------------------------------------------
       
  2206 
       
  2207     Class: CTestRemoteCmdNotifier
       
  2208 
       
  2209     Method: StartL
       
  2210 
       
  2211     Description: Start active object
       
  2212 
       
  2213     Parameters: None
       
  2214 
       
  2215     Return Values: None
       
  2216 
       
  2217     Errors/Exceptions: None
       
  2218 
       
  2219     Status: Draft
       
  2220 
       
  2221 -------------------------------------------------------------------------------
       
  2222 */
       
  2223 void CTestRemoteCmdNotifier::Start( const RMessage2& aMessage )
       
  2224     {
       
  2225     // Check that this request is not pending!!
       
  2226     __ASSERT_ALWAYS( iState != ETestProgressPending,
       
  2227                     iEngine->PanicClient( EReqPending, aMessage ) );
       
  2228     iState = ETestProgressPending;
       
  2229     SetActive();
       
  2230     // Start first phase of the remote command's operations
       
  2231     iTestExecution.NotifyRemoteCmd( iRemoteTypePckg, 
       
  2232                                     iMsgSizePckg, 
       
  2233                                     iStatus );
       
  2234 
       
  2235     }
       
  2236 
       
  2237 /*
       
  2238 -------------------------------------------------------------------------------
       
  2239 
       
  2240     Class: CTestRemoteCmdNotifier
       
  2241 
       
  2242     Method: CancelReq
       
  2243 
       
  2244     Description: Cancel the request.
       
  2245 
       
  2246     Parameters: None
       
  2247 
       
  2248     Return Values: None
       
  2249 
       
  2250     Errors/Exceptions: None
       
  2251 
       
  2252     Status: Draft
       
  2253 
       
  2254 -------------------------------------------------------------------------------
       
  2255 */
       
  2256 void CTestRemoteCmdNotifier::CancelReq()
       
  2257     {
       
  2258     if(iMessageAvail)
       
  2259         {
       
  2260         iMessageAvail = EFalse;
       
  2261         iMessage.Complete( KErrCancel );
       
  2262         }
       
  2263     }
       
  2264 
       
  2265 /*
       
  2266 -------------------------------------------------------------------------------
       
  2267 
       
  2268     Class: CTestRemoteCmdNotifier
       
  2269 
       
  2270     Method: RunL
       
  2271 
       
  2272     Description: RunL handles completed requests.
       
  2273 
       
  2274     Parameters: None
       
  2275 
       
  2276     Return Values: None
       
  2277 
       
  2278     Errors/Exceptions: Leaves if WriteL leaves
       
  2279                        Leaves if iStatus is not KErrNone or KErrEof
       
  2280                        Leaves are handled in RunError method
       
  2281 
       
  2282     Status: Approved
       
  2283 
       
  2284 -------------------------------------------------------------------------------
       
  2285 */
       
  2286 void CTestRemoteCmdNotifier::RunL()
       
  2287     {
       
  2288     __TRACE( KVerbose, ( _L( "CTestRemoteCmdNotifier::StartL: iStatus=[%d]" ), iStatus.Int() ) );
       
  2289 
       
  2290     User::LeaveIfError( iStatus.Int() );
       
  2291     
       
  2292     iState = ETestProgressCompleted;
       
  2293 
       
  2294     TInt ret( 0 );
       
  2295     switch( iRemoteType )
       
  2296         {
       
  2297         case EStifCmdSend:             // "Sending"
       
  2298             {
       
  2299             if( ( iMessageAvail == EFalse ) ||
       
  2300                 ( iMsgSize <= 0 ) )
       
  2301                 { 
       
  2302                 User::Leave( KErrGeneral );
       
  2303                 }
       
  2304             // Delete previous if exists
       
  2305             delete iReceivedMsg;
       
  2306             iReceivedMsg = 0;
       
  2307             // Create new buffer 
       
  2308             iReceivedMsg = HBufC8::NewL( iMsgSize );
       
  2309 
       
  2310             // Start second phase of the remote command's operations,
       
  2311             // buffer is read with GetReceivedMsg
       
  2312             TPtr8 tmp = iReceivedMsg->Des();
       
  2313             ret = iTestExecution.ReadRemoteCmdInfo( tmp, iRemoteType );
       
  2314 
       
  2315             // Writing received info to UI
       
  2316             iMessage.WriteL( 0, iRemoteTypePckg );
       
  2317             iMessage.WriteL( 1, iMsgSizePckg );
       
  2318             
       
  2319             // Complete message
       
  2320             iMessage.Complete( ret );
       
  2321             iMessageAvail = EFalse;
       
  2322 
       
  2323             break;
       
  2324             }
       
  2325         case EStifCmdReboot:           // "Sending"
       
  2326             {
       
  2327             TRebootParams remoteType;
       
  2328             TRebootParamsPckg remoteTypePckg( remoteType );
       
  2329             // Start second phase of the remote command's operations
       
  2330             ret = iTestExecution.ReadRemoteCmdInfo( remoteTypePckg, iRemoteType );
       
  2331             __TRACE( KInit, ( CStifLogger::ERed, _L("REBOOT PHONE (type %d)" ), remoteType.aType ) );
       
  2332 
       
  2333             if( remoteType.aType == CTestModuleIf::EKernelReset )
       
  2334                 {
       
  2335                 __TRACE( KInit, ( _L("Rebooting with kernel reset" ) ) );
       
  2336                 __TRACE( KInit, ( _L("Kernel reset implementation is ongoing, trying different reset..." ) ) );
       
  2337                 }
       
  2338 
       
  2339 #ifdef __WINS__
       
  2340             __TRACE( KInit, ( _L("Rebooting with Process kill(WINS)" ) ) );
       
  2341             RProcess thisProcess;
       
  2342             //thisProcess.SetSystem( ETrue );
       
  2343             thisProcess.Kill( KErrNone );
       
  2344             thisProcess.Close();
       
  2345 #else // Hardware specific
       
  2346             TInt r( KErrNone );
       
  2347             __TRACE( KInit, ( _L("Rebooting with reset module(HW)" ) ) );
       
  2348             r = DynamicResetModule( remoteType.aType );
       
  2349             if( r != KErrNone )
       
  2350                 {
       
  2351                 __TRACE( KInit, ( CStifLogger::EError, _L("This reseting type is failed, trying different reset...")) );
       
  2352                 }
       
  2353 #endif // Hardware specific
       
  2354 
       
  2355             // if( !remoteType.aType == CTestModuleIf::EDefaultReset )
       
  2356             // Note this change needs an error code tranceiver between reboot
       
  2357             // module and engine. (If reboot fails return error code, if reboot
       
  2358             // is default then kill process else error code returning)
       
  2359 
       
  2360             // Do process kill as a last option
       
  2361             __TRACE( KInit, ( _L("Rebooting with Process kill" ) ) );
       
  2362            
       
  2363             RProcess thisProcess2;         
       
  2364             thisProcess2.Kill( KErrNone );
       
  2365             thisProcess2.Close();
       
  2366 
       
  2367             // If this text is shown in UI something is wrong and this needs some investigation.
       
  2368             iEngine->ErrorPrint( 0, _L( "Reboot phone...E.g. disconnect battery!!!" ) );
       
  2369             break;
       
  2370             }
       
  2371         case EStifCmdStoreState:       // "Sending"
       
  2372             {
       
  2373             if( iMessageAvail == EFalse )
       
  2374                 { 
       
  2375                 User::Leave( KErrGeneral );
       
  2376                 }
       
  2377             TRebootStateParams remoteState;
       
  2378             TRebootStateParamsPckg remoteStatePckg( remoteState );
       
  2379 
       
  2380             // Start second phase of the remote command's operations
       
  2381             ret = iTestExecution.ReadRemoteCmdInfo( remoteStatePckg,
       
  2382                                                     iRemoteType );
       
  2383 
       
  2384             // Get test case information(test module, test case file, etc.)
       
  2385             TTestInfo testInfo;
       
  2386             iTestCaseController->GetTestCaseInfo( testInfo );
       
  2387 
       
  2388             // Write state informations to the file
       
  2389             iEngine->WriteRebootParams( testInfo, remoteState.aCode,
       
  2390                                         remoteState.aName );
       
  2391                                                         
       
  2392             // Write ATS loggers buffers to drive
       
  2393             iEngine->FlushAtsLogger();
       
  2394 
       
  2395             // Pause test cases that there cannot make e.g. new store state
       
  2396             // calls. iCaseNumber is index type value so increment by one to
       
  2397             // get current test case.
       
  2398             iEngine->PauseAllTestCases();
       
  2399             // Resume current test case
       
  2400             iTestCaseController->iTestExecution.Resume();
       
  2401 
       
  2402             // Writing received info to UI
       
  2403             iMessage.WriteL( 0, iRemoteTypePckg );
       
  2404 
       
  2405             // Complete message
       
  2406             iMessage.Complete( ret );
       
  2407             iMessageAvail = EFalse;
       
  2408             break;
       
  2409             }
       
  2410         case EStifCmdGetStoredState:   // "Reading, this must be done with two phase"
       
  2411             {
       
  2412             // Get test case information(test module, test case file, etc.)
       
  2413             TTestInfo testInfo;
       
  2414             iTestCaseController->GetTestCaseInfo( testInfo );
       
  2415 
       
  2416             TGetRebootStoredParams remoteStoredState;
       
  2417             // Read state informations from the file
       
  2418             TInt errorCodeToClient = 
       
  2419                 iEngine->ReadRebootParams( testInfo, 
       
  2420                                            remoteStoredState.aName,
       
  2421                                            remoteStoredState.aCode );
       
  2422 
       
  2423             TGetRebootStoredParamsPckg remoteStoredPckg( remoteStoredState );
       
  2424 
       
  2425             // Start second phase of the remote command's operations
       
  2426             ret = iTestExecution.ReadRemoteCmdInfo( remoteStoredPckg,
       
  2427                                                     iRemoteType,
       
  2428                                                     errorCodeToClient );
       
  2429             
       
  2430             Start( iMessage ); // Starts active object
       
  2431 
       
  2432             break;
       
  2433             }
       
  2434        case EStifCmdMeasurement:   // "Reading, this must be done with two phase"
       
  2435             {
       
  2436             TGetMeasurementOptions remoteMeasurementOptions;
       
  2437             remoteMeasurementOptions.iOptions = iEngine->StifMeasurement();
       
  2438 
       
  2439             TGetMeasurementOptionsPckg remoteMeasurementPckg( remoteMeasurementOptions );
       
  2440 
       
  2441             // Start second phase of the remote command's operations
       
  2442             ret = iTestExecution.ReadRemoteCmdInfo( remoteMeasurementPckg,
       
  2443                                                     iRemoteType,
       
  2444                                                     KErrNone );
       
  2445             
       
  2446             Start( iMessage ); // Starts active object
       
  2447 
       
  2448             break;
       
  2449             }
       
  2450 
       
  2451         case EStifCmdReceive:          // "Reading"
       
  2452         default:
       
  2453             User::Leave( KErrNotFound );
       
  2454             break;
       
  2455         }
       
  2456     
       
  2457     }
       
  2458 
       
  2459 /*
       
  2460 -------------------------------------------------------------------------------
       
  2461 
       
  2462     Class: CTestRemoteCmdNotifier
       
  2463 
       
  2464     Method: DoCancel
       
  2465 
       
  2466     Description: Cancel active request
       
  2467 
       
  2468     Parameters: None
       
  2469 
       
  2470     Return Values: None
       
  2471 
       
  2472     Errors/Exceptions: None
       
  2473 
       
  2474     Status: Draft
       
  2475 
       
  2476 -------------------------------------------------------------------------------
       
  2477 */
       
  2478 void CTestRemoteCmdNotifier::DoCancel()
       
  2479     {
       
  2480     switch ( iState )
       
  2481         {
       
  2482         case ETestProgressPending:
       
  2483             iTestExecution.CancelAsyncRequest( ETestExecutionNotifyRemoteCmd );
       
  2484             //iMessage.Complete( KErrCancel );
       
  2485             break;
       
  2486         case ETestProgressIdle:
       
  2487         case ETestProgressCompleted:
       
  2488         default:
       
  2489             // DoCancel called in wrong state => Panic
       
  2490             _LIT( KTestRemoteCmdNotifier, "CTestRemoteCmdNotifier" );
       
  2491             User::Panic( KTestRemoteCmdNotifier, EDoCancelDisorder );
       
  2492             break;
       
  2493         }
       
  2494     iState = ETestProgressIdle;
       
  2495 
       
  2496     }
       
  2497 
       
  2498 /*
       
  2499 -------------------------------------------------------------------------------
       
  2500 
       
  2501     Class: CTestRemoteCmdNotifier
       
  2502 
       
  2503     Method: RunError
       
  2504 
       
  2505     Description: Handle errors.
       
  2506 
       
  2507     Parameters: TInt aError: in: Symbian OS error: Error code
       
  2508 
       
  2509     Return Values: TInt KErrNone: Always returned KErrNone
       
  2510 
       
  2511     Errors/Exceptions: None
       
  2512 
       
  2513     Status: Draft
       
  2514 
       
  2515 -------------------------------------------------------------------------------
       
  2516 */
       
  2517 TInt CTestRemoteCmdNotifier::RunError( TInt aError )
       
  2518     {
       
  2519     // Complete message with error
       
  2520     if(iMessageAvail)
       
  2521         {
       
  2522         iMessageAvail = EFalse;
       
  2523         iMessage.Complete( aError );
       
  2524         }
       
  2525     
       
  2526     return KErrNone;
       
  2527 
       
  2528     }
       
  2529 
       
  2530 /*
       
  2531 -------------------------------------------------------------------------------
       
  2532 
       
  2533     Class: CTestRemoteCmdNotifier
       
  2534 
       
  2535     Method: ResetL
       
  2536 
       
  2537     Description: Reset HW/WINS. Loads dynamically reset module by name.
       
  2538 
       
  2539     Parameters: CTestModuleIf::TRebootType aResetType: in: Reset type
       
  2540 
       
  2541     Return Values: TInt: Symbian error code.
       
  2542 
       
  2543     Errors/Exceptions: None
       
  2544 
       
  2545     Status: Proposal
       
  2546 
       
  2547 -------------------------------------------------------------------------------
       
  2548 */
       
  2549 TInt CTestRemoteCmdNotifier::DynamicResetModule( 
       
  2550                                         CTestModuleIf::TRebootType aResetType )
       
  2551     {
       
  2552     __TRACE( KInit, (  _L( "DynamicResetModule()" ) ) );
       
  2553     RLibrary resetModule;
       
  2554     // Load the module
       
  2555     TPtrC dllName;
       
  2556     dllName.Set( iEngine->GetDeviceResetDllName() );
       
  2557     // Loading should work with and without '.dll' extension.
       
  2558     TInt r = resetModule.Load( dllName );
       
  2559     if ( r != KErrNone )
       
  2560         {
       
  2561         __TRACE( KError, ( CStifLogger::EError, _L("Can't initialize reset module[%S], code = %d"), &dllName, r ) );
       
  2562         return KErrNotFound;
       
  2563         }
       
  2564     else
       
  2565         {
       
  2566         // Print reset module name
       
  2567         __TRACE( KInit, (  _L("Loaded reset module[%S]"), &dllName ) );
       
  2568         }
       
  2569 
       
  2570     // Verify the UID
       
  2571     TUid KUidTestModule = TUid::Uid ( 0x101FB3E7 );
       
  2572     TUidType requiredUID( KDynamicLibraryUid, KSharedLibraryUid, KUidTestModule );
       
  2573 
       
  2574     TUidType moduleUID = resetModule.Type();    
       
  2575     if ( moduleUID != requiredUID )
       
  2576         {
       
  2577         // New instance can't be created
       
  2578         RDebug::Print( ( _L("STIF TF: Reset module has invalid UID. Aborting loading!") ) );
       
  2579         __TRACE ( KError, ( CStifLogger::EError, _L("Reset module has invalid UID. Aborting loading!" ) ) );
       
  2580         return KErrNotSupported;
       
  2581         }
       
  2582 
       
  2583     // Get pointer to first exported function
       
  2584     CTestInterfaceFactory libEntry;
       
  2585     libEntry = (CTestInterfaceFactory) resetModule.Lookup( 1 );
       
  2586     if ( libEntry == NULL )
       
  2587         {
       
  2588         // New instance can't be created
       
  2589         __TRACE ( KError, ( CStifLogger::EError, _L("Can't initialize reset module, NULL libEntry" ) ) );
       
  2590         return KErrNoMemory;
       
  2591         }
       
  2592     else
       
  2593         {
       
  2594         __TRACE ( KInit, ( _L("Pointer to 1st exported received")));
       
  2595         }
       
  2596 
       
  2597     CStifHWReset* reset;
       
  2598     reset = NULL;
       
  2599 
       
  2600     // initialize test module
       
  2601     __TRACE ( KVerbose, (_L("Calling 1st exported at 0x%x"), (TUint32) libEntry ));
       
  2602     TRAPD ( err, reset =  (*libEntry)() );
       
  2603 
       
  2604      // Handle leave from test module
       
  2605     if ( err != KErrNone )
       
  2606         {
       
  2607         __TRACE (KError, ( CStifLogger::EError, _L("Leave when calling 1st exported function, code %d"), err));
       
  2608         return err;
       
  2609         }
       
  2610     else if ( reset == NULL )     // Handle NULL from test module init
       
  2611         {
       
  2612         __TRACE (KError, ( CStifLogger::EError, _L("NULL pointer received when constructing test module")));
       
  2613         delete reset;
       
  2614 
       
  2615         // Set error codes
       
  2616         return KErrNoMemory;
       
  2617         }
       
  2618     else
       
  2619         {
       
  2620         __TRACE (KInit, (_L("Entrypoint successfully called, test module instance at 0x%x"), (TUint32)reset ) );
       
  2621         }
       
  2622 
       
  2623     // Calls dynamically loaded reset module's method.
       
  2624     TInt ret = reset->DoReset( aResetType );
       
  2625     if( ret != KErrNone )
       
  2626         {
       
  2627         __TRACE (KInit, (_L("DynamicResetModule; DoReset fails with error: %d"), ret ) );
       
  2628         return ret;
       
  2629         }
       
  2630 
       
  2631     return KErrNone;
       
  2632 
       
  2633     }
       
  2634 
       
  2635 /*
       
  2636 -------------------------------------------------------------------------------
       
  2637 
       
  2638     DESCRIPTION
       
  2639 
       
  2640     This module contains implementation of CTestCommandNotifier class member
       
  2641     functions.
       
  2642 
       
  2643 -------------------------------------------------------------------------------
       
  2644 */
       
  2645 
       
  2646 // ================= MEMBER FUNCTIONS =========================================
       
  2647 
       
  2648 /*
       
  2649 -------------------------------------------------------------------------------
       
  2650 
       
  2651     Class: CTestCommandNotifier
       
  2652 
       
  2653     Method: CTestCommandNotifier
       
  2654 
       
  2655     Description: Default constructor
       
  2656 
       
  2657     C++ default constructor can NOT contain any code, that
       
  2658     might leave.
       
  2659 
       
  2660     Parameters: CTestEngine* aEngine: in: Pointer to CTestEngine
       
  2661                 RTestExecution aTestExecution: in: Handle to RTestExecution
       
  2662 
       
  2663     Return Values: None
       
  2664 
       
  2665     Errors/Exceptions: None
       
  2666 
       
  2667     Status: Approved
       
  2668 
       
  2669 -------------------------------------------------------------------------------
       
  2670 */
       
  2671 CTestCommandNotifier::CTestCommandNotifier(CTestEngine* aEngine,
       
  2672                                            RTestExecution aTestExecution):
       
  2673     CActive(CActive::EPriorityStandard),
       
  2674     iEngine(aEngine),
       
  2675     iTestExecution(aTestExecution),
       
  2676     iCommandPckg(iCommand)
       
  2677     {
       
  2678     CActiveScheduler::Add(this);
       
  2679     }
       
  2680 
       
  2681 /*
       
  2682 -------------------------------------------------------------------------------
       
  2683 
       
  2684     Class: CTestCommandNotifier
       
  2685 
       
  2686     Method: ConstructL
       
  2687 
       
  2688     Description: Symbian OS second phase constructor
       
  2689 
       
  2690     Symbian OS default constructor can leave.
       
  2691 
       
  2692     Parameters: None
       
  2693 
       
  2694     Return Values: None
       
  2695 
       
  2696     Errors/Exceptions: None
       
  2697 
       
  2698     Status: Approved
       
  2699 
       
  2700 -------------------------------------------------------------------------------
       
  2701 */
       
  2702 void CTestCommandNotifier::ConstructL( )
       
  2703     {
       
  2704     __TRACE(KVerbose, (_L("CTestCommandNotifier::ConstructL")));
       
  2705     }
       
  2706 
       
  2707 /*
       
  2708 -------------------------------------------------------------------------------
       
  2709 
       
  2710     Class: CTestCommandNotifier
       
  2711 
       
  2712     Method: NewL
       
  2713 
       
  2714     Description: Two-phased constructor.
       
  2715 
       
  2716     Parameters: CTestEngine* aEngine: in: Pointer to CTestEngine
       
  2717                 RTestExecution aTestExecution: in: Handle to RTestExecution
       
  2718 
       
  2719     Return Values: CTestCommandNotifier* : pointer to created object
       
  2720 
       
  2721     Errors/Exceptions: Leaves if construction of CTestCommandNotifier fails
       
  2722 
       
  2723     Status: Approved
       
  2724 
       
  2725 -------------------------------------------------------------------------------
       
  2726 */
       
  2727 CTestCommandNotifier* CTestCommandNotifier::NewL(CTestEngine* aEngine,
       
  2728                                                  RTestExecution aTestExecution)
       
  2729     {
       
  2730     CTestCommandNotifier* self = new (ELeave) CTestCommandNotifier(aEngine, aTestExecution);
       
  2731     CleanupStack::PushL(self);
       
  2732     self->ConstructL();
       
  2733     CleanupStack::Pop(self);
       
  2734     return self;
       
  2735     }
       
  2736 
       
  2737 /*
       
  2738 -------------------------------------------------------------------------------
       
  2739 
       
  2740     Class: CTestCommandNotifier
       
  2741 
       
  2742     Method: ~CTestCommandNotifier
       
  2743 
       
  2744     Description: Destructor
       
  2745 
       
  2746     Parameters: None
       
  2747 
       
  2748     Return Values: None
       
  2749 
       
  2750     Errors/Exceptions: None
       
  2751 
       
  2752     Status: Approved
       
  2753 
       
  2754 -------------------------------------------------------------------------------
       
  2755 */
       
  2756 CTestCommandNotifier::~CTestCommandNotifier()
       
  2757     {
       
  2758     __TRACE(KVerbose, (_L("CTestEventNotifier::~CTestEventNotifier")));
       
  2759     Cancel();
       
  2760     }
       
  2761 
       
  2762 /*
       
  2763 -------------------------------------------------------------------------------
       
  2764 
       
  2765     Class: CTestCommandNotifier
       
  2766 
       
  2767     Method: StartL
       
  2768 
       
  2769     Description: Start active object
       
  2770 
       
  2771     Parameters: None
       
  2772 
       
  2773     Return Values: None
       
  2774 
       
  2775     Errors/Exceptions: None
       
  2776 
       
  2777     Status: Approved
       
  2778 
       
  2779 -------------------------------------------------------------------------------
       
  2780 */
       
  2781 void CTestCommandNotifier::Start()
       
  2782     {
       
  2783     __TRACE(KVerbose, (_L("CTestEventNotifier::StartL")));
       
  2784 
       
  2785     TInt res = iTestExecution.NotifyCommand2(iCommandPckg, iParamsPckg, iStatus, KErrNone);
       
  2786     SetActive();
       
  2787     }
       
  2788 
       
  2789 /*
       
  2790 -------------------------------------------------------------------------------
       
  2791 
       
  2792     Class: CTestCommandNotifier
       
  2793 
       
  2794     Method: RunL
       
  2795 
       
  2796     Description: RunL handles completed requests.
       
  2797 
       
  2798     Parameters: None
       
  2799 
       
  2800     Return Values: None
       
  2801 
       
  2802     Errors/Exceptions: Leaves if iStatus is not KErrNone
       
  2803                        Leaves if iState is not ETestEventPending
       
  2804                        Leaves if some leaving method called here leaves
       
  2805 
       
  2806     Status: Approved
       
  2807 
       
  2808 -------------------------------------------------------------------------------
       
  2809 */
       
  2810 void CTestCommandNotifier::RunL()
       
  2811     {
       
  2812     __TRACE(KVerbose, (_L("CTestCommandNotifier::RunL: iStatus=[%d]"), iStatus.Int()));
       
  2813 
       
  2814     User::LeaveIfError(iStatus.Int());
       
  2815 
       
  2816     iEngine->ExecuteCommandL(iCommand, iParamsPckg);
       
  2817 
       
  2818     // Set request again
       
  2819     Start();
       
  2820     }
       
  2821 
       
  2822 /*
       
  2823 -------------------------------------------------------------------------------
       
  2824 
       
  2825     Class: CTestCommandNotifier
       
  2826 
       
  2827     Method: DoCancel
       
  2828 
       
  2829     Description: Cancel active request
       
  2830 
       
  2831     Parameters: None
       
  2832 
       
  2833     Return Values: None
       
  2834 
       
  2835     Errors/Exceptions: None
       
  2836 
       
  2837     Status: Approved
       
  2838 
       
  2839 -------------------------------------------------------------------------------
       
  2840 */
       
  2841 void CTestCommandNotifier::DoCancel()
       
  2842     {
       
  2843     __TRACE(KVerbose, (_L( "CTestEventNotifier::DoCancel")));
       
  2844 
       
  2845     iTestExecution.CancelAsyncRequest(ETestExecutionNotifyCommand);
       
  2846     }
       
  2847 
       
  2848 /*
       
  2849 -------------------------------------------------------------------------------
       
  2850 
       
  2851     Class: CTestCommandNotifier
       
  2852 
       
  2853     Method: RunError
       
  2854 
       
  2855     Description: Handle errors.
       
  2856 
       
  2857     Parameters: TInt aError: in: Symbian OS error: Error code
       
  2858 
       
  2859     Return Values: TInt KErrNone: Always returned KErrNone
       
  2860 
       
  2861     Errors/Exceptions: None
       
  2862 
       
  2863     Status: Approved
       
  2864 
       
  2865 -------------------------------------------------------------------------------
       
  2866 */
       
  2867 TInt CTestCommandNotifier::RunError(TInt aError)
       
  2868     {
       
  2869     __TRACE(KError, (CStifLogger::ERed, _L("CTestCommandNotifier::RunError %d"), aError));
       
  2870     return KErrNone;
       
  2871     }
       
  2872 
       
  2873 
       
  2874 // ================= OTHER EXPORTED FUNCTIONS =================================
       
  2875 
       
  2876 // None
       
  2877 
       
  2878 // End of File