stif/ATSInterface/src/ATSInterfaceRunner.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: CATSInterfaceRunner: This object executes test 
       
    15 * cases from Test Framework.
       
    16 *
       
    17 */
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <e32base.h>
       
    21 #include <e32cons.h>
       
    22 #include <e32svr.h>
       
    23 #include "ATSInterface.h"
       
    24 #include "ATSInterfaceRunner.h"
       
    25 
       
    26 
       
    27 // EXTERNAL DATA STRUCTURES
       
    28 // None
       
    29 
       
    30 // EXTERNAL FUNCTION PROTOTYPES  
       
    31 // None
       
    32 
       
    33 // CONSTANTS
       
    34 // None
       
    35 
       
    36 // MACROS
       
    37 // None
       
    38 
       
    39 // LOCAL CONSTANTS AND MACROS
       
    40 // None
       
    41 
       
    42 // MODULE DATA STRUCTURES
       
    43 // None
       
    44 
       
    45 // LOCAL FUNCTION PROTOTYPES
       
    46 // None
       
    47 
       
    48 // FORWARD DECLARATIONS
       
    49 // None
       
    50 
       
    51 
       
    52 // ==================== LOCAL FUNCTIONS ======================================= 
       
    53 // None
       
    54 
       
    55 // ================= MEMBER FUNCTIONS ========================================= 
       
    56 
       
    57 
       
    58 /*
       
    59 -------------------------------------------------------------------------------
       
    60 
       
    61     DESCRIPTION
       
    62 
       
    63     CATSInterfaceRunner: This object executes test cases from Test Framework.
       
    64 
       
    65 -------------------------------------------------------------------------------
       
    66 */
       
    67 
       
    68 // ================= MEMBER FUNCTIONS =========================================
       
    69 
       
    70 /*
       
    71 -------------------------------------------------------------------------------
       
    72 
       
    73     Class: CATSInterfaceRunner
       
    74 
       
    75     Method: CATSInterfaceRunner
       
    76 
       
    77     Description: Default constructor
       
    78 
       
    79     C++ default constructor can NOT contain any code, that
       
    80     might leave.
       
    81     
       
    82     Parameters: None
       
    83     
       
    84     Return Values: None
       
    85 
       
    86     Errors/Exceptions: None
       
    87 
       
    88     Status: Approved
       
    89     
       
    90 -------------------------------------------------------------------------------
       
    91 */
       
    92 CATSInterfaceRunner::CATSInterfaceRunner( CATSInterface* aATSInterface,
       
    93                                    TTestInfo& aTestInfo ) : 
       
    94     CActive( CActive::EPriorityStandard ),
       
    95     iATSInterface( aATSInterface ),
       
    96     iTestInfo( aTestInfo ),
       
    97     iTestInfoPckg( iTestInfo ),
       
    98     iFullTestResultPckg( iFullTestResult )
       
    99     {
       
   100     __ASSERT_ALWAYS( aATSInterface, User::Panic( _L("Null pointer"), KErrGeneral ) );
       
   101 
       
   102     CActiveScheduler::Add( this );
       
   103 
       
   104     }
       
   105 
       
   106 /*
       
   107 -------------------------------------------------------------------------------
       
   108 
       
   109     Class: CATSInterfaceRunner
       
   110 
       
   111     Method: ConstructL
       
   112 
       
   113     Description: Symbian OS second phase constructor
       
   114 
       
   115     Symbian OS default constructor can leave.
       
   116     
       
   117     Parameters: None
       
   118 
       
   119     Return Values: None
       
   120 
       
   121     Errors/Exceptions: Leaves if called Open method returns error
       
   122 
       
   123     Status: Approved
       
   124     
       
   125 -------------------------------------------------------------------------------
       
   126 */
       
   127 void CATSInterfaceRunner::ConstructL()
       
   128     {
       
   129     iTestEngineServ = iATSInterface->TestEngineServer();
       
   130     iTestEngine = iATSInterface->TestEngine();
       
   131 
       
   132     User::LeaveIfError( iTestCase.Open( iTestEngineServ, iTestInfoPckg ) );
       
   133 
       
   134     }
       
   135 
       
   136 /*
       
   137 -------------------------------------------------------------------------------
       
   138 
       
   139     Class: CATSInterfaceRunner
       
   140 
       
   141     Method: NewL
       
   142 
       
   143     Description: Two-phased constructor.
       
   144     
       
   145     Parameters: CATSInterface* aATSInterface: in: pointer to ATS Interface
       
   146                 TTestInfo& aTestInfo: in: Test info
       
   147 
       
   148     Return Values: CATSInterfaceRunner* : pointer to created runner object
       
   149 
       
   150     Errors/Exceptions: Leaves if memory allocation for CATSInterfaceRunner fails
       
   151                        Leaves if ConstructL leaves
       
   152 
       
   153     Status: Approved
       
   154     
       
   155 -------------------------------------------------------------------------------
       
   156 */
       
   157 CATSInterfaceRunner* CATSInterfaceRunner::NewL( CATSInterface* aATSInterface,
       
   158                                          TTestInfo& aTestInfo )
       
   159     {
       
   160     CATSInterfaceRunner* self =  
       
   161         new ( ELeave ) CATSInterfaceRunner( aATSInterface, aTestInfo );
       
   162     CleanupStack::PushL( self );
       
   163     self->ConstructL();
       
   164     CleanupStack::Pop();
       
   165     return self;
       
   166     }
       
   167 
       
   168 /*
       
   169 -------------------------------------------------------------------------------
       
   170 
       
   171     Class: CATSInterfaceRunner
       
   172 
       
   173     Method: ~CATSInterfaceRunner
       
   174 
       
   175     Description: Destructor
       
   176     
       
   177     Parameters: None
       
   178 
       
   179     Return Values: None
       
   180 
       
   181     Errors/Exceptions: None
       
   182 
       
   183     Status: Approved
       
   184     
       
   185 -------------------------------------------------------------------------------
       
   186 */    
       
   187 CATSInterfaceRunner::~CATSInterfaceRunner()
       
   188     {
       
   189     Cancel();
       
   190     iTestCase.Close();
       
   191     }
       
   192 
       
   193 /*
       
   194 -------------------------------------------------------------------------------
       
   195 
       
   196     Class: CATSInterfaceRunner
       
   197 
       
   198     Method: StartTestL
       
   199 
       
   200     Description: Starts testing
       
   201 
       
   202     Parameters: None
       
   203 
       
   204     Return Values: None
       
   205 
       
   206     Errors/Exceptions: None
       
   207 
       
   208     Status: Approved
       
   209     
       
   210 -------------------------------------------------------------------------------
       
   211 */
       
   212 void CATSInterfaceRunner::StartTestL()
       
   213     {
       
   214 #ifdef _DEBUG
       
   215     RDebug::Print(_L("Start test case %d: "), iTestInfo.iTestCaseInfo.iCaseNumber );
       
   216 #endif
       
   217 
       
   218     if ( IsActive() )
       
   219         Cancel();
       
   220 
       
   221     iTestCase.RunTestCase( iFullTestResultPckg, iStatus );
       
   222 
       
   223     SetActive();
       
   224     }
       
   225 
       
   226 /*
       
   227 -------------------------------------------------------------------------------
       
   228 
       
   229     Class: CATSInterfaceRunner
       
   230 
       
   231     Method: RunL
       
   232 
       
   233     Description: RunL handles completed requests.
       
   234 
       
   235     Parameters: None
       
   236 
       
   237     Return Values: None
       
   238 
       
   239     Errors/Exceptions: Leaves if iStatus is not KErrNone, error is handled in
       
   240                        RunError called by CActiveObject
       
   241 
       
   242     Status: Proposal
       
   243     
       
   244 -------------------------------------------------------------------------------
       
   245 */
       
   246 void CATSInterfaceRunner::RunL()
       
   247     {
       
   248 #ifdef _DEBUG
       
   249     RDebug::Print(_L("RunTestCase completed: [%d] "), iStatus.Int() );
       
   250 #endif
       
   251     // Check if the test case could not be executed, error handled in RunError
       
   252     User::LeaveIfError ( iStatus.Int() );
       
   253 
       
   254     // Check if the test case crashed, error handler in RunError
       
   255     if ( iFullTestResult.iCaseExecutionResultType !=
       
   256          TFullTestResult::ECaseExecuted )
       
   257         {
       
   258 #ifdef _DEBUG
       
   259         RDebug::Print(_L("Test case execution failed: [%d] "), 
       
   260             iFullTestResult.iCaseExecutionResultCode );
       
   261 #endif
       
   262         // Complete with the result of the test case
       
   263         iATSInterface->TestCompleted( iFullTestResult.iCaseExecutionResultCode );
       
   264 
       
   265         }
       
   266     else
       
   267         {
       
   268 #ifdef _DEBUG
       
   269         // Debug test result
       
   270         RDebug::Print( _L("Test case execution completed[%d]: %S"), 
       
   271                             iFullTestResult.iTestResult.iResult,  
       
   272                             &iFullTestResult.iTestResult.iResultDes);
       
   273 #endif
       
   274 
       
   275         // Complete with the result of the test case
       
   276         iATSInterface->TestCompleted( iFullTestResult.iTestResult.iResult );
       
   277         }
       
   278 
       
   279     }
       
   280 
       
   281 /*
       
   282 -------------------------------------------------------------------------------
       
   283 
       
   284     Class: CATSInterfaceRunner
       
   285 
       
   286     Method: DoCancel
       
   287 
       
   288     Description: Cancel active request.
       
   289 
       
   290     Parameters: None
       
   291 
       
   292     Return Values: None
       
   293 
       
   294     Errors/Exceptions: None
       
   295 
       
   296     Status: Approved
       
   297     
       
   298 -------------------------------------------------------------------------------
       
   299 */
       
   300 void CATSInterfaceRunner::DoCancel()
       
   301     {
       
   302     // Cancel the active request
       
   303     iTestCase.CancelAsyncRequest( ETestCaseRunTestCase );
       
   304 
       
   305     }
       
   306 
       
   307 /*
       
   308 -------------------------------------------------------------------------------
       
   309 
       
   310     Class: CATSInterfaceRunner
       
   311 
       
   312     Method: RunError
       
   313 
       
   314     Description: Handle errors from TestFramework
       
   315 
       
   316     Parameters: TInt aError: in: Symbian OS error: Error code
       
   317     
       
   318     Return Values: TInt KErrNone: Always returned KErrNone
       
   319 
       
   320     Errors/Exceptions: None
       
   321 
       
   322     Status: Proposal
       
   323     
       
   324 -------------------------------------------------------------------------------
       
   325 */
       
   326 TInt CATSInterfaceRunner::RunError( TInt aError )
       
   327     {
       
   328 #ifdef _DEBUG
       
   329     RDebug::Print(_L("Test case execution failed: [%d] "), 
       
   330             aError );
       
   331 #endif
       
   332     iATSInterface->TestCompleted ( aError );
       
   333 
       
   334     return KErrNone;
       
   335     }
       
   336 
       
   337 /*
       
   338 -------------------------------------------------------------------------------
       
   339 
       
   340     DESCRIPTION
       
   341 
       
   342     CActiveTimer: This object prints running seconds to console screen.
       
   343 
       
   344 -------------------------------------------------------------------------------
       
   345 */
       
   346 
       
   347 // ================= MEMBER FUNCTIONS =========================================
       
   348 
       
   349 /*
       
   350 -------------------------------------------------------------------------------
       
   351 
       
   352     Class: CActiveTimer
       
   353 
       
   354     Method: CActiveTimer
       
   355 
       
   356     Description: Default constructor
       
   357 
       
   358     C++ default constructor can NOT contain any code, that
       
   359     might leave.
       
   360     
       
   361     Parameters: CConsoleBase* aConsole: in: Pointer to CConsoleBase
       
   362     
       
   363     Return Values: None
       
   364 
       
   365     Errors/Exceptions: None
       
   366 
       
   367     Status: Approved
       
   368     
       
   369 -------------------------------------------------------------------------------
       
   370 */
       
   371 CActiveTimer::CActiveTimer( CConsoleBase* aConsole ) : 
       
   372     CTimer( CActive::EPriorityStandard ),
       
   373     iConsole( aConsole )
       
   374     {
       
   375     CActiveScheduler::Add( this );
       
   376     }
       
   377 
       
   378 /*
       
   379 -------------------------------------------------------------------------------
       
   380 
       
   381     Class: CActiveTimer
       
   382 
       
   383     Method: ConstructL
       
   384 
       
   385     Description: Symbian OS second phase constructor
       
   386 
       
   387     Symbian OS default constructor can leave.
       
   388     
       
   389     Parameters: None
       
   390 
       
   391     Return Values: None
       
   392 
       
   393     Errors/Exceptions: None
       
   394 
       
   395     Status: Approved
       
   396     
       
   397 -------------------------------------------------------------------------------
       
   398 */
       
   399 void CActiveTimer::ConstructL()
       
   400     {
       
   401     //Base class 2nd phase constructor
       
   402     CTimer::ConstructL();
       
   403 
       
   404     // Set console positions
       
   405     iXPos = 0;
       
   406     iYPos = 1;
       
   407 
       
   408     }
       
   409 
       
   410 /*
       
   411 -------------------------------------------------------------------------------
       
   412 
       
   413     Class: CActiveTimer
       
   414 
       
   415     Method: NewL
       
   416 
       
   417     Description: Two-phased constructor.
       
   418     
       
   419     Parameters: CConsoleBase* aConsole: in: Pointer to CConsoleBase
       
   420 
       
   421     Return Values: CActiveTimer* : pointer to created CActiveTimer object
       
   422 
       
   423     Errors/Exceptions: Leaves if memory allocation for CATSInterface fails
       
   424                        Leaves if ConstructL leaves
       
   425 
       
   426     Status: Approved
       
   427     
       
   428 -------------------------------------------------------------------------------
       
   429 */
       
   430 CActiveTimer* CActiveTimer::NewL( CConsoleBase* aConsole )
       
   431     {
       
   432     CActiveTimer* self =  
       
   433         new ( ELeave ) CActiveTimer( aConsole );
       
   434     CleanupStack::PushL( self );
       
   435     self->ConstructL();
       
   436     CleanupStack::Pop();
       
   437     return self;
       
   438     }
       
   439 
       
   440 /*
       
   441 -------------------------------------------------------------------------------
       
   442 
       
   443     Class: CActiveTimer
       
   444 
       
   445     Method: ~CActiveTimer
       
   446 
       
   447     Description: Destructor
       
   448     
       
   449     Parameters: None
       
   450 
       
   451     Return Values: None
       
   452 
       
   453     Errors/Exceptions: None
       
   454 
       
   455     Status: Approved
       
   456     
       
   457 -------------------------------------------------------------------------------
       
   458 */    
       
   459 CActiveTimer::~CActiveTimer()
       
   460     {
       
   461     Cancel();
       
   462     }
       
   463 
       
   464 /*
       
   465 -------------------------------------------------------------------------------
       
   466 
       
   467     Class: CActiveTimer
       
   468 
       
   469     Method: StartTestL
       
   470 
       
   471     Description: Starts testing
       
   472 
       
   473     Parameters: None
       
   474 
       
   475     Return Values: None
       
   476 
       
   477     Errors/Exceptions: None
       
   478 
       
   479     Status: Approved
       
   480     
       
   481 -------------------------------------------------------------------------------
       
   482 */
       
   483 void CActiveTimer::StartL()
       
   484     {
       
   485     iStartTime.HomeTime();
       
   486     // Wait a moment
       
   487     CTimer::After( KPrintInterval );
       
   488     }
       
   489 
       
   490 /*
       
   491 -------------------------------------------------------------------------------
       
   492 
       
   493     Class: CActiveTimer
       
   494 
       
   495     Method: RunL
       
   496 
       
   497     Description: RunL handles completed requests.
       
   498 
       
   499     Parameters: None
       
   500 
       
   501     Return Values: None
       
   502 
       
   503     Errors/Exceptions: None
       
   504 
       
   505     Status: Approved
       
   506     
       
   507 -------------------------------------------------------------------------------
       
   508 */
       
   509 void CActiveTimer::RunL()
       
   510     {
       
   511     // Print time
       
   512     TTimeIntervalSeconds seconds;
       
   513     TTime time;
       
   514     time.HomeTime();
       
   515     time.SecondsFrom( iStartTime, seconds );
       
   516 
       
   517     TInt x = iConsole->WhereX();
       
   518     TInt y = iConsole->WhereY();
       
   519 
       
   520     // Print time to screen
       
   521     iConsole->SetPos( iXPos, iYPos );
       
   522     iConsole->ClearToEndOfLine();
       
   523     iConsole->Printf( _L("[Time: %d] "), seconds.Int() );
       
   524 
       
   525     iConsole->SetPos( x, y );
       
   526     // Wait a moment
       
   527     CTimer::After( KPrintInterval );
       
   528 
       
   529     }
       
   530 
       
   531 /*
       
   532 -------------------------------------------------------------------------------
       
   533 
       
   534     Class: CActiveTimer
       
   535 
       
   536     Method: DoCancel
       
   537 
       
   538     Description: Cancel
       
   539 
       
   540     Parameters: None
       
   541 
       
   542     Return Values: None
       
   543 
       
   544     Errors/Exceptions: None
       
   545 
       
   546     Status: Approved
       
   547     
       
   548 -------------------------------------------------------------------------------
       
   549 */
       
   550 void CActiveTimer::DoCancel()
       
   551     {
       
   552     // Print time
       
   553     TTimeIntervalSeconds seconds;
       
   554     TTime time;
       
   555     time.HomeTime();
       
   556     time.SecondsFrom( iStartTime, seconds );
       
   557 
       
   558     // Print time to screen
       
   559     iConsole->Printf( _L("Total Time: [%d] "), seconds.Int() );
       
   560     // Cancel the active request
       
   561     CTimer::DoCancel();
       
   562 
       
   563     }
       
   564 
       
   565 // ================= OTHER EXPORTED FUNCTIONS ================================= 
       
   566 // None
       
   567 
       
   568 // End of File