testexecfw/stf/stfui/atsui/src/ATSInterfaceRunner.cpp
changeset 2 8bb370ba6d1d
equal deleted inserted replaced
1:bbd31066657e 2:8bb370ba6d1d
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 * 
       
    14 * Description: 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     iTestEngine = iATSInterface->TestEngine();
       
   130 
       
   131     User::LeaveIfError( iTestCase.Open( iTestEngine, iTestInfoPckg ) );
       
   132 
       
   133     }
       
   134 
       
   135 /*
       
   136 -------------------------------------------------------------------------------
       
   137 
       
   138     Class: CATSInterfaceRunner
       
   139 
       
   140     Method: NewL
       
   141 
       
   142     Description: Two-phased constructor.
       
   143     
       
   144     Parameters: CATSInterface* aATSInterface: in: pointer to ATS Interface
       
   145                 TTestInfo& aTestInfo: in: Test info
       
   146 
       
   147     Return Values: CATSInterfaceRunner* : pointer to created runner object
       
   148 
       
   149     Errors/Exceptions: Leaves if memory allocation for CATSInterfaceRunner fails
       
   150                        Leaves if ConstructL leaves
       
   151 
       
   152     Status: Approved
       
   153     
       
   154 -------------------------------------------------------------------------------
       
   155 */
       
   156 CATSInterfaceRunner* CATSInterfaceRunner::NewL( CATSInterface* aATSInterface,
       
   157                                          TTestInfo& aTestInfo )
       
   158     {
       
   159     CATSInterfaceRunner* self =  
       
   160         new ( ELeave ) CATSInterfaceRunner( aATSInterface, aTestInfo );
       
   161     CleanupStack::PushL( self );
       
   162     self->ConstructL();
       
   163     CleanupStack::Pop();
       
   164     return self;
       
   165     }
       
   166 
       
   167 /*
       
   168 -------------------------------------------------------------------------------
       
   169 
       
   170     Class: CATSInterfaceRunner
       
   171 
       
   172     Method: ~CATSInterfaceRunner
       
   173 
       
   174     Description: Destructor
       
   175     
       
   176     Parameters: None
       
   177 
       
   178     Return Values: None
       
   179 
       
   180     Errors/Exceptions: None
       
   181 
       
   182     Status: Approved
       
   183     
       
   184 -------------------------------------------------------------------------------
       
   185 */    
       
   186 CATSInterfaceRunner::~CATSInterfaceRunner()
       
   187     {
       
   188     Cancel();
       
   189     iTestCase.Close();
       
   190     }
       
   191 
       
   192 /*
       
   193 -------------------------------------------------------------------------------
       
   194 
       
   195     Class: CATSInterfaceRunner
       
   196 
       
   197     Method: StartTestL
       
   198 
       
   199     Description: Starts testing
       
   200 
       
   201     Parameters: None
       
   202 
       
   203     Return Values: None
       
   204 
       
   205     Errors/Exceptions: None
       
   206 
       
   207     Status: Approved
       
   208     
       
   209 -------------------------------------------------------------------------------
       
   210 */
       
   211 void CATSInterfaceRunner::StartTestL()
       
   212     {
       
   213 #ifdef _DEBUG
       
   214     RDebug::Print(_L("Start test case %d: "), iTestInfo.iTestCaseInfo.iCaseNumber );
       
   215 #endif
       
   216 
       
   217     if ( IsActive() )
       
   218         Cancel();
       
   219 
       
   220     iTestCase.RunTestCase( iFullTestResultPckg, iStatus );
       
   221 
       
   222     SetActive();
       
   223     }
       
   224 
       
   225 /*
       
   226 -------------------------------------------------------------------------------
       
   227 
       
   228     Class: CATSInterfaceRunner
       
   229 
       
   230     Method: RunL
       
   231 
       
   232     Description: RunL handles completed requests.
       
   233 
       
   234     Parameters: None
       
   235 
       
   236     Return Values: None
       
   237 
       
   238     Errors/Exceptions: Leaves if iStatus is not KErrNone, error is handled in
       
   239                        RunError called by CActiveObject
       
   240 
       
   241     Status: Proposal
       
   242     
       
   243 -------------------------------------------------------------------------------
       
   244 */
       
   245 void CATSInterfaceRunner::RunL()
       
   246     {
       
   247 #ifdef _DEBUG
       
   248     RDebug::Print(_L("RunTestCase completed: [%d] "), iStatus.Int() );
       
   249 #endif
       
   250     // Check if the test case could not be executed, error handled in RunError
       
   251     User::LeaveIfError ( iStatus.Int() );
       
   252 
       
   253     // Check if the test case crashed, error handler in RunError
       
   254     if ( iFullTestResult.iCaseExecutionResultType !=
       
   255          TFullTestResult::ECaseExecuted )
       
   256         {
       
   257 #ifdef _DEBUG
       
   258         RDebug::Print(_L("Test case execution failed: [%d] "), 
       
   259             iFullTestResult.iCaseExecutionResultCode );
       
   260 #endif
       
   261         // Complete with the result of the test case
       
   262         iATSInterface->TestCompleted( iFullTestResult.iCaseExecutionResultCode );
       
   263 
       
   264         }
       
   265     else
       
   266         {
       
   267 #ifdef _DEBUG
       
   268         // Debug test result
       
   269         RDebug::Print( _L("Test case execution completed[%d]: %S"), 
       
   270                             iFullTestResult.iTestResult.iResult,  
       
   271                             &iFullTestResult.iTestResult.iResultDes);
       
   272 #endif
       
   273 
       
   274         // Complete with the result of the test case
       
   275         iATSInterface->TestCompleted( iFullTestResult.iTestResult.iResult );
       
   276         }
       
   277 
       
   278     }
       
   279 
       
   280 /*
       
   281 -------------------------------------------------------------------------------
       
   282 
       
   283     Class: CATSInterfaceRunner
       
   284 
       
   285     Method: DoCancel
       
   286 
       
   287     Description: Cancel active request.
       
   288 
       
   289     Parameters: None
       
   290 
       
   291     Return Values: None
       
   292 
       
   293     Errors/Exceptions: None
       
   294 
       
   295     Status: Approved
       
   296     
       
   297 -------------------------------------------------------------------------------
       
   298 */
       
   299 void CATSInterfaceRunner::DoCancel()
       
   300     {
       
   301     // Cancel the active request
       
   302     iTestCase.CancelAsyncRequest( RTestCase::ERunTestCase );
       
   303 
       
   304     }
       
   305 
       
   306 /*
       
   307 -------------------------------------------------------------------------------
       
   308 
       
   309     Class: CATSInterfaceRunner
       
   310 
       
   311     Method: RunError
       
   312 
       
   313     Description: Handle errors from TestFramework
       
   314 
       
   315     Parameters: TInt aError: in: Symbian OS error: Error code
       
   316     
       
   317     Return Values: TInt KErrNone: Always returned KErrNone
       
   318 
       
   319     Errors/Exceptions: None
       
   320 
       
   321     Status: Proposal
       
   322     
       
   323 -------------------------------------------------------------------------------
       
   324 */
       
   325 TInt CATSInterfaceRunner::RunError( TInt aError )
       
   326     {
       
   327 #ifdef _DEBUG
       
   328     RDebug::Print(_L("Test case execution failed: [%d] "), 
       
   329             aError );
       
   330 #endif
       
   331     iATSInterface->TestCompleted ( aError );
       
   332 
       
   333     return KErrNone;
       
   334     }
       
   335 
       
   336 /*
       
   337 -------------------------------------------------------------------------------
       
   338 
       
   339     DESCRIPTION
       
   340 
       
   341     CActiveTimer: This object prints running seconds to console screen.
       
   342 
       
   343 -------------------------------------------------------------------------------
       
   344 */
       
   345 
       
   346 // ================= MEMBER FUNCTIONS =========================================
       
   347 
       
   348 /*
       
   349 -------------------------------------------------------------------------------
       
   350 
       
   351     Class: CActiveTimer
       
   352 
       
   353     Method: CActiveTimer
       
   354 
       
   355     Description: Default constructor
       
   356 
       
   357     C++ default constructor can NOT contain any code, that
       
   358     might leave.
       
   359     
       
   360     Parameters: CConsoleBase* aConsole: in: Pointer to CConsoleBase
       
   361     
       
   362     Return Values: None
       
   363 
       
   364     Errors/Exceptions: None
       
   365 
       
   366     Status: Approved
       
   367     
       
   368 -------------------------------------------------------------------------------
       
   369 */
       
   370 CActiveTimer::CActiveTimer( CConsoleBase* aConsole ) : 
       
   371     CTimer( CActive::EPriorityStandard ),
       
   372     iConsole( aConsole )
       
   373     {
       
   374     CActiveScheduler::Add( this );
       
   375     }
       
   376 
       
   377 /*
       
   378 -------------------------------------------------------------------------------
       
   379 
       
   380     Class: CActiveTimer
       
   381 
       
   382     Method: ConstructL
       
   383 
       
   384     Description: Symbian OS second phase constructor
       
   385 
       
   386     Symbian OS default constructor can leave.
       
   387     
       
   388     Parameters: None
       
   389 
       
   390     Return Values: None
       
   391 
       
   392     Errors/Exceptions: None
       
   393 
       
   394     Status: Approved
       
   395     
       
   396 -------------------------------------------------------------------------------
       
   397 */
       
   398 void CActiveTimer::ConstructL()
       
   399     {
       
   400     //Base class 2nd phase constructor
       
   401     CTimer::ConstructL();
       
   402 
       
   403     // Set console positions
       
   404     iXPos = 0;
       
   405     iYPos = 1;
       
   406 
       
   407     }
       
   408 
       
   409 /*
       
   410 -------------------------------------------------------------------------------
       
   411 
       
   412     Class: CActiveTimer
       
   413 
       
   414     Method: NewL
       
   415 
       
   416     Description: Two-phased constructor.
       
   417     
       
   418     Parameters: CConsoleBase* aConsole: in: Pointer to CConsoleBase
       
   419 
       
   420     Return Values: CActiveTimer* : pointer to created CActiveTimer object
       
   421 
       
   422     Errors/Exceptions: Leaves if memory allocation for CATSInterface fails
       
   423                        Leaves if ConstructL leaves
       
   424 
       
   425     Status: Approved
       
   426     
       
   427 -------------------------------------------------------------------------------
       
   428 */
       
   429 CActiveTimer* CActiveTimer::NewL( CConsoleBase* aConsole )
       
   430     {
       
   431     CActiveTimer* self =  
       
   432         new ( ELeave ) CActiveTimer( aConsole );
       
   433     CleanupStack::PushL( self );
       
   434     self->ConstructL();
       
   435     CleanupStack::Pop();
       
   436     return self;
       
   437     }
       
   438 
       
   439 /*
       
   440 -------------------------------------------------------------------------------
       
   441 
       
   442     Class: CActiveTimer
       
   443 
       
   444     Method: ~CActiveTimer
       
   445 
       
   446     Description: Destructor
       
   447     
       
   448     Parameters: None
       
   449 
       
   450     Return Values: None
       
   451 
       
   452     Errors/Exceptions: None
       
   453 
       
   454     Status: Approved
       
   455     
       
   456 -------------------------------------------------------------------------------
       
   457 */    
       
   458 CActiveTimer::~CActiveTimer()
       
   459     {
       
   460     Cancel();
       
   461     }
       
   462 
       
   463 /*
       
   464 -------------------------------------------------------------------------------
       
   465 
       
   466     Class: CActiveTimer
       
   467 
       
   468     Method: StartTestL
       
   469 
       
   470     Description: Starts testing
       
   471 
       
   472     Parameters: None
       
   473 
       
   474     Return Values: None
       
   475 
       
   476     Errors/Exceptions: None
       
   477 
       
   478     Status: Approved
       
   479     
       
   480 -------------------------------------------------------------------------------
       
   481 */
       
   482 void CActiveTimer::StartL()
       
   483     {
       
   484     iStartTime.HomeTime();
       
   485     // Wait a moment
       
   486     CTimer::After( KPrintInterval );
       
   487     }
       
   488 
       
   489 /*
       
   490 -------------------------------------------------------------------------------
       
   491 
       
   492     Class: CActiveTimer
       
   493 
       
   494     Method: RunL
       
   495 
       
   496     Description: RunL handles completed requests.
       
   497 
       
   498     Parameters: None
       
   499 
       
   500     Return Values: None
       
   501 
       
   502     Errors/Exceptions: None
       
   503 
       
   504     Status: Approved
       
   505     
       
   506 -------------------------------------------------------------------------------
       
   507 */
       
   508 void CActiveTimer::RunL()
       
   509     {
       
   510     // Print time
       
   511     TTimeIntervalSeconds seconds;
       
   512     TTime time;
       
   513     time.HomeTime();
       
   514     time.SecondsFrom( iStartTime, seconds );
       
   515 
       
   516     TInt x = iConsole->WhereX();
       
   517     TInt y = iConsole->WhereY();
       
   518 
       
   519     // Print time to screen
       
   520     iConsole->SetPos( iXPos, iYPos );
       
   521     
       
   522     // ClearToEndOfLine will cause console crash in debug mode. 
       
   523     //iConsole->ClearToEndOfLine();
       
   524     
       
   525     iConsole->Printf( _L("[Time: %d] "), seconds.Int() );
       
   526 
       
   527     iConsole->SetPos( x, y );
       
   528     // Wait a moment
       
   529     CTimer::After( KPrintInterval );
       
   530 
       
   531     }
       
   532 
       
   533 /*
       
   534 -------------------------------------------------------------------------------
       
   535 
       
   536     Class: CActiveTimer
       
   537 
       
   538     Method: DoCancel
       
   539 
       
   540     Description: Cancel
       
   541 
       
   542     Parameters: None
       
   543 
       
   544     Return Values: None
       
   545 
       
   546     Errors/Exceptions: None
       
   547 
       
   548     Status: Approved
       
   549     
       
   550 -------------------------------------------------------------------------------
       
   551 */
       
   552 void CActiveTimer::DoCancel()
       
   553     {
       
   554     // Print time
       
   555     TTimeIntervalSeconds seconds;
       
   556     TTime time;
       
   557     time.HomeTime();
       
   558     time.SecondsFrom( iStartTime, seconds );
       
   559 
       
   560     // Print time to screen
       
   561     iConsole->Printf( _L("Total Time: [%d] "), seconds.Int() );
       
   562     // Cancel the active request
       
   563     CTimer::DoCancel();
       
   564 
       
   565     }
       
   566 
       
   567 // ================= OTHER EXPORTED FUNCTIONS ================================= 
       
   568 // None
       
   569 
       
   570 //  End of File
       
   571 
       
   572 // End of File