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