testexecfw/stf/stfext/testmodules/testcombiner/src/TestCase.cpp
changeset 2 8bb370ba6d1d
equal deleted inserted replaced
1:bbd31066657e 2:8bb370ba6d1d
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 * 
       
    14 * Description: This module contains the implementation of 
       
    15 * CTestCase class member functions.
       
    16 *
       
    17 */
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "TestCombiner.h"
       
    21 #include "TestCase.h"
       
    22 #include "TestCaseNotify.h"
       
    23 #include "Logging.h"
       
    24 #include "StifPython.h"
       
    25 
       
    26 // EXTERNAL DATA STRUCTURES
       
    27 // None
       
    28 
       
    29 // EXTERNAL FUNCTION PROTOTYPES  
       
    30 // None
       
    31 
       
    32 // CONSTANTS
       
    33 // None
       
    34 
       
    35 // MACROS
       
    36 #ifdef LOGGER
       
    37 #undef LOGGER
       
    38 #endif
       
    39 #define LOGGER iTestCombiner->iLog
       
    40 
       
    41 // LOCAL CONSTANTS AND MACROS
       
    42 // None
       
    43 
       
    44 // MODULE DATA STRUCTURES
       
    45 // None
       
    46 
       
    47 // LOCAL FUNCTION PROTOTYPES
       
    48 // None
       
    49 
       
    50 // FORWARD DECLARATIONS
       
    51 // None
       
    52 
       
    53 // ================= MEMBER FUNCTIONS =========================================
       
    54 
       
    55 /*
       
    56 -------------------------------------------------------------------------------
       
    57 
       
    58      Class: CTestCase
       
    59 
       
    60      Method: CTestCase
       
    61 
       
    62      Description: Default constructor
       
    63 
       
    64      C++ default constructor can NOT contain any code, that
       
    65      might leave.
       
    66 
       
    67      Parameters: CTestCombiner* testCombiner: in: Backpointer to CTestCombiner
       
    68                  TDesC& aModuleName: in: name of the used test module
       
    69                  TDesC& aTestId: in: TestId for testcase
       
    70                  TInt aExpectedResult: in: expected result for the testcase
       
    71      
       
    72      Return Values: None.
       
    73 
       
    74      Errors/Exceptions: None.
       
    75 
       
    76      Status: Draft
       
    77     
       
    78 -------------------------------------------------------------------------------
       
    79 */
       
    80 
       
    81 CTestCase::CTestCase( CTestCombiner* testCombiner,
       
    82                       TInt aExpectedResult,
       
    83                       TFullTestResult::TCaseExecutionResult aCategory,
       
    84                       TCaseType aType,
       
    85                       CTCTestModule* aModule ): //--PYTHON
       
    86     CActive(  CActive::EPriorityStandard ),
       
    87     iType( aType ),
       
    88     iTestCombiner( testCombiner ),
       
    89     iState( ETestCaseIdle ),
       
    90     iExpectedResult( aExpectedResult ),
       
    91     iExpectedResultCategory( aCategory ),
       
    92     iTestModule( aModule ) //--PYTHON
       
    93     {
       
    94     
       
    95     CActiveScheduler::Add( this );   
       
    96     
       
    97     }
       
    98 
       
    99 /*
       
   100 -------------------------------------------------------------------------------
       
   101 
       
   102      Class: CTestCase
       
   103 
       
   104      Method: ConstructL
       
   105 
       
   106      Description: Symbian OS second phase constructor
       
   107 
       
   108      Symbian OS default constructor can leave.     
       
   109 
       
   110      Parameters: TDesC& aTestId: in: Test identifier
       
   111 
       
   112      Return Values: None.
       
   113 
       
   114      Errors/Exceptions: None
       
   115 
       
   116      Status: Proposal
       
   117     
       
   118 -------------------------------------------------------------------------------
       
   119 */
       
   120 
       
   121 void CTestCase::ConstructL( TDesC& aTestId )
       
   122     {
       
   123     __ASSERT_ALWAYS( aTestId.Length() < KMaxFileName, User::Leave( KErrArgument ) );
       
   124     iTestId = aTestId.AllocL();
       
   125     
       
   126     }
       
   127 
       
   128 /*
       
   129 -------------------------------------------------------------------------------
       
   130 
       
   131      Class: CTestCase
       
   132 
       
   133      Method: ~CTestCase
       
   134 
       
   135      Description: Destructor
       
   136      
       
   137      Parameters: None.
       
   138 
       
   139      Return Values: None.
       
   140 
       
   141      Errors/Exceptions: None.
       
   142      
       
   143      Status: Proposal
       
   144     
       
   145 -------------------------------------------------------------------------------
       
   146 */     
       
   147 
       
   148 CTestCase::~CTestCase()
       
   149     {    
       
   150 
       
   151     Cancel();    
       
   152     delete iTestId;
       
   153     
       
   154     }
       
   155 
       
   156 /*
       
   157 -------------------------------------------------------------------------------
       
   158 
       
   159      Class: CTestCase
       
   160 
       
   161      Method: RunL
       
   162 
       
   163      Description: Derived from CActive. Handles the completed testcase.
       
   164 
       
   165      Parameters: None.
       
   166 
       
   167      Return Values: None.
       
   168 
       
   169      Errors/Exceptions: Leaves if completed with error. 
       
   170 
       
   171      Status: Proposal
       
   172     
       
   173 -------------------------------------------------------------------------------
       
   174 */
       
   175 
       
   176 void CTestCase::RunL()
       
   177     {
       
   178     __TRACE( KMessage, ( _L("CTestCase::RunL: [%d] "), iStatus.Int() ));
       
   179     
       
   180     Complete( iStatus.Int() );
       
   181 
       
   182     __TRACE( KMessage, ( _L( "CTestCase::RunL: Testcase completed" )));
       
   183 
       
   184     }
       
   185 
       
   186 /*
       
   187 -------------------------------------------------------------------------------
       
   188 
       
   189      Class: CTestCase
       
   190 
       
   191      Method: DoCancel
       
   192 
       
   193      Description: Derived from CActive, handles the Cancel.
       
   194 
       
   195      Parameters: None.
       
   196 
       
   197      Return Values: None.
       
   198 
       
   199      Errors/Exceptions: None.
       
   200 
       
   201      Status: Proposal
       
   202     
       
   203 -------------------------------------------------------------------------------
       
   204 */
       
   205 void CTestCase::DoCancel()
       
   206     {
       
   207     __TRACE( KMessage, ( _L("CTestCase::DoCancel")));
       
   208     
       
   209     TRequestStatus* rs = &iStatus;
       
   210     User::RequestComplete( rs, KErrCancel );
       
   211     Complete( KErrCancel );
       
   212      
       
   213     }
       
   214 
       
   215 /*
       
   216 -------------------------------------------------------------------------------
       
   217 
       
   218      Class: CTestCase
       
   219 
       
   220      Method: Start
       
   221 
       
   222      Description: Start progress and event notifiers and set CTestCase active.
       
   223   
       
   224      Parameters: None.
       
   225 
       
   226      Return Values: None.
       
   227 
       
   228      Errors/Exceptions: None.
       
   229 
       
   230      Status: Proposal
       
   231     
       
   232 -------------------------------------------------------------------------------
       
   233 */
       
   234 void CTestCase::StartL()
       
   235     {
       
   236 
       
   237     iState = ETestCaseRunning;
       
   238     iStatus = KRequestPending;
       
   239     SetActive();
       
   240      
       
   241     }
       
   242 
       
   243 /*
       
   244 -------------------------------------------------------------------------------
       
   245 
       
   246      Class: CTestCase
       
   247 
       
   248      Method: Complete
       
   249 
       
   250      Description: Completes testcase to CTestCombiner.
       
   251   
       
   252      Parameters: TInt aError: in: Completion error
       
   253      
       
   254      Return Values: None.
       
   255 
       
   256      Errors/Exceptions: None.
       
   257 
       
   258      Status: Proposal
       
   259     
       
   260 -------------------------------------------------------------------------------
       
   261 */
       
   262 void CTestCase::Complete( TInt aError )
       
   263     {
       
   264 
       
   265     __TRACE( KMessage, ( _L("CTestCase::Complete: %d "), aError ));
       
   266     iState = ETestCaseCompleted;
       
   267     
       
   268     iTestCombiner->Complete( this, aError );
       
   269     
       
   270     }
       
   271 
       
   272 /*
       
   273 -------------------------------------------------------------------------------
       
   274 
       
   275      Class: CTestCase
       
   276 
       
   277      Method: IsCompletelyFinished
       
   278 
       
   279      Description: Checks state.
       
   280 
       
   281      Parameters: None
       
   282 
       
   283      Return Values: TBool.
       
   284 
       
   285      Errors/Exceptions: None.
       
   286 
       
   287      Status: Proposal
       
   288 
       
   289 -------------------------------------------------------------------------------
       
   290 */
       
   291 TBool CTestCase::IsCompletelyFinished(void)
       
   292     {
       
   293     TBool result = (iState == CTestCase::ETestCaseCompleted);
       
   294     return result;
       
   295     }
       
   296 
       
   297 /*
       
   298 -------------------------------------------------------------------------------
       
   299 
       
   300     DESCRIPTION
       
   301 
       
   302     This module contains the implementation of CTCTestCase class 
       
   303     member functions.
       
   304 
       
   305 -------------------------------------------------------------------------------
       
   306 */
       
   307 
       
   308 // ================= MEMBER FUNCTIONS =========================================
       
   309 
       
   310 /*
       
   311 -------------------------------------------------------------------------------
       
   312 
       
   313      Class: CTCTestCase
       
   314 
       
   315      Method: CTCTestCase
       
   316 
       
   317      Description: Default constructor
       
   318 
       
   319      C++ default constructor can NOT contain any code, that
       
   320      might leave.
       
   321 
       
   322      Parameters: CTestCombiner* testCombiner: in: Backpointer to CTestCombiner
       
   323                  TDesC& aModuleName: in: name of the used test module
       
   324                  TDesC& aTestId: in: TestId for testcase
       
   325                  TInt aExpectedResult: in: expected result for the testcase
       
   326      
       
   327      Return Values: None.
       
   328 
       
   329      Errors/Exceptions: None.
       
   330 
       
   331      Status: Proposal
       
   332     
       
   333 -------------------------------------------------------------------------------
       
   334 */
       
   335 
       
   336 CTCTestCase::CTCTestCase( CTestCombiner* testCombiner,
       
   337                           TInt aExpectedResult,
       
   338                           TFullTestResult::TCaseExecutionResult aCategory,
       
   339                           CTCTestModule* aModule ): //--PYTHON
       
   340     CTestCase( testCombiner, aExpectedResult, aCategory, ECaseLocal, aModule ), //--PYTHON
       
   341     iResultPckg( iResult )
       
   342     {
       
   343     }
       
   344 
       
   345 /*
       
   346 -------------------------------------------------------------------------------
       
   347 
       
   348      Class: CTCTestCase
       
   349 
       
   350      Method: ConstructL
       
   351 
       
   352      Description: Symbian OS second phase constructor
       
   353 
       
   354      Symbian OS default constructor can leave.     
       
   355 
       
   356      Parameters: None. 
       
   357 
       
   358      Return Values: None.
       
   359 
       
   360      Errors/Exceptions: None
       
   361 
       
   362      Status: Proposal
       
   363     
       
   364 -------------------------------------------------------------------------------
       
   365 */
       
   366 
       
   367 void CTCTestCase::ConstructL( TDesC& aModuleName,
       
   368                               TDesC& aTestId )
       
   369     {
       
   370     __ASSERT_ALWAYS( aModuleName.Length() < KMaxFileName, User::Leave( KErrArgument ) );
       
   371     CTestCase::ConstructL( aTestId );
       
   372     iModuleName = aModuleName.AllocL();
       
   373     
       
   374     }
       
   375 
       
   376 /*
       
   377 -------------------------------------------------------------------------------
       
   378 
       
   379      Class: CTCTestCase
       
   380 
       
   381      Method: NewL
       
   382 
       
   383      Description: Two-phased constructor.
       
   384 
       
   385      Parameters: CTestCombiner* testCombiner: in: Backpointer to CTestCombiner
       
   386 
       
   387      Return Values: CTCTestCase*: pointer to new CTCTestCase object
       
   388 
       
   389      Errors/Exceptions: Leaves if new or ConstructL leaves.
       
   390 
       
   391      Status: Proposal
       
   392     
       
   393 -------------------------------------------------------------------------------
       
   394 */
       
   395 
       
   396 CTCTestCase* CTCTestCase::NewL( CTestCombiner* testCombiner,
       
   397                                 TDesC& aModuleName,
       
   398                                 TDesC& aTestId,
       
   399                                 TInt aExpectedResult,
       
   400                                 TFullTestResult::TCaseExecutionResult
       
   401                                     aCategory,
       
   402                                 CTCTestModule* aModule ) //--PYTHON
       
   403     {
       
   404     CTCTestCase* self = new (ELeave) CTCTestCase( testCombiner,
       
   405                                                    aExpectedResult,
       
   406                                                    aCategory,
       
   407                                                    aModule ); //--PYTHON
       
   408      
       
   409     CleanupStack::PushL( self );
       
   410     self->ConstructL( aModuleName, aTestId );
       
   411     CleanupStack::Pop();
       
   412     return self;
       
   413      
       
   414     }
       
   415 
       
   416 /*
       
   417 -------------------------------------------------------------------------------
       
   418 
       
   419      Class: CTCTestCase
       
   420 
       
   421      Method: ~CTCTestCase
       
   422 
       
   423      Description: Destructor
       
   424      
       
   425      Parameters: None.
       
   426 
       
   427      Return Values: None.
       
   428 
       
   429      Errors/Exceptions: None.
       
   430      
       
   431      Status: Proposal
       
   432     
       
   433 -------------------------------------------------------------------------------
       
   434 */     
       
   435 
       
   436 CTCTestCase::~CTCTestCase()
       
   437     {    
       
   438     Cancel();
       
   439     
       
   440     delete iEvent;
       
   441     
       
   442     // Unset all set events
       
   443     TInt count = iStateEventArray.Count();
       
   444     TInt i = 0;
       
   445     for( i = 0; i < count; i++ )
       
   446         {
       
   447 		if( iStateEventArray[i] != NULL )
       
   448 			{
       
   449 			iStateEventArray[i]->SetType( TEventIf::EUnsetEvent );
       
   450 			}
       
   451 		if( iTestCombiner != NULL )
       
   452 			{
       
   453 			iTestCombiner->TestModuleIf().Event( *iStateEventArray[i] );
       
   454 			}
       
   455         }
       
   456     iStateEventArray.ResetAndDestroy();
       
   457     iStateEventArray.Close();
       
   458     
       
   459     // to be sure..
       
   460     count = iEventArray.Count();
       
   461     TEventIf event;
       
   462     for( i = 0; i < count; i++ )
       
   463         {
       
   464         event.Copy( iEventArray[i]->Event() );
       
   465         event.SetType( TEventIf::ERelEvent );
       
   466 		if( iTestCombiner != NULL )
       
   467 			{
       
   468 			iTestCombiner->TestModuleIf().Event( event );
       
   469 			}
       
   470         }
       
   471 
       
   472 
       
   473     iEventArray.ResetAndDestroy();
       
   474     iEventArray.Close();
       
   475     
       
   476     delete iProgress;
       
   477     delete iModuleName;
       
   478     
       
   479     delete iCommand;
       
   480     }
       
   481 
       
   482 /*
       
   483 -------------------------------------------------------------------------------
       
   484 
       
   485      Class: CTCTestCase
       
   486 
       
   487      Method: DoCancel
       
   488 
       
   489      Description: Derived from CActive, handles the Cancel.
       
   490 
       
   491      Parameters: None.
       
   492 
       
   493      Return Values: None.
       
   494 
       
   495      Errors/Exceptions: None.
       
   496 
       
   497      Status: Proposal
       
   498     
       
   499 -------------------------------------------------------------------------------
       
   500 */
       
   501 void CTCTestCase::DoCancel()
       
   502     {
       
   503     __TRACE( KMessage, ( _L("CTCTestCase::DoCancel")));
       
   504     iTestExecution.CancelAsyncRequest( ETestExecutionRunTestCase );
       
   505     Complete( KErrCancel );
       
   506      
       
   507     }    
       
   508 
       
   509 /*
       
   510 -------------------------------------------------------------------------------
       
   511 
       
   512      Class: CTCTestCase
       
   513 
       
   514      Method: Start
       
   515 
       
   516      Description: Start progress and event notifiers and set CTCTestCase active.
       
   517   
       
   518      Parameters: None.
       
   519 
       
   520      Return Values: None.
       
   521 
       
   522      Errors/Exceptions: None.
       
   523 
       
   524      Status: Proposal
       
   525     
       
   526 -------------------------------------------------------------------------------
       
   527 */
       
   528 void CTCTestCase::StartL()
       
   529     {
       
   530     iProgress = CTestProgressNotifier::NewL( iTestCombiner, this );
       
   531     iEvent = CTestEventNotifier::NewL( iTestCombiner, this );
       
   532     iCommand = CTestCommandNotifier::NewL(iTestCombiner, this);
       
   533     iState = ETestCaseRunning;
       
   534     SetActive();
       
   535      
       
   536     }
       
   537 
       
   538 /*
       
   539 -------------------------------------------------------------------------------
       
   540 
       
   541      Class: CTCTestCase
       
   542 
       
   543      Method: Complete
       
   544 
       
   545      Description: Start complete the testcase to CTestCombiner (Complete2 make
       
   546                   the final complete).
       
   547   
       
   548      Parameters: TInt aError: in: Completion error
       
   549      
       
   550      Return Values: None.
       
   551 
       
   552      Errors/Exceptions: None.
       
   553 
       
   554      Status: Proposal
       
   555     
       
   556 -------------------------------------------------------------------------------
       
   557 */
       
   558 void CTCTestCase::Complete( TInt aError )
       
   559     {
       
   560     if( iState == ETestCaseRunning )
       
   561         {
       
   562         // Testcase is in running state, complete and delete notifiers
       
   563         if( aError != KErrNone )
       
   564             {
       
   565             iResult.iTestResult.iResult = aError;
       
   566             }
       
   567             
       
   568         iState = ETestCaseCompleted;
       
   569         __TRACE( KMessage, ( _L("CTCTestCase::Complete: %d "), aError ));
       
   570         
       
   571         }
       
   572 
       
   573 	if( iProgress->IsPrintProgressFinished() )
       
   574         {
       
   575         // Print process is finished to UI => make final complete of
       
   576         // the test case
       
   577 		Complete2();
       
   578         }
       
   579 
       
   580     }
       
   581 
       
   582 /*
       
   583 -------------------------------------------------------------------------------
       
   584 
       
   585      Class: CTCTestCase
       
   586 
       
   587      Method: Complete2
       
   588 
       
   589      Description: Testcase final complete to CTestCombiner.
       
   590   
       
   591      Parameters: None
       
   592      
       
   593      Return Values: None.
       
   594 
       
   595      Errors/Exceptions: None.
       
   596 
       
   597      Status: Proposal
       
   598     
       
   599 -------------------------------------------------------------------------------
       
   600 */
       
   601 void CTCTestCase::Complete2()
       
   602     {
       
   603  	// to be sure..
       
   604     TInt count = iEventArray.Count();
       
   605     TEventIf event;
       
   606     for( TInt i = 0; i < count; i++ )
       
   607         {
       
   608         event.Copy( iEventArray[0]->Event() );
       
   609         event.SetType( TEventIf::ERelEvent );
       
   610         CTestEventNotify* eventEntry = iEventArray[0];
       
   611         iEventArray.Remove( 0 );
       
   612         delete eventEntry;
       
   613         iTestCombiner->TestModuleIf().Event( event );
       
   614         }
       
   615       
       
   616     iEventArray.ResetAndDestroy();
       
   617     iEventArray.Close();
       
   618     
       
   619     delete iEvent;
       
   620     iEvent = NULL;
       
   621     delete iProgress;
       
   622     iProgress = NULL;
       
   623     delete iCommand;
       
   624     iCommand = NULL;
       
   625 
       
   626     iTestCombiner->Complete( this );
       
   627 
       
   628     // Close execution handle
       
   629     iTestExecution.Close();
       
   630     
       
   631     }
       
   632 
       
   633 /*
       
   634 -------------------------------------------------------------------------------
       
   635 
       
   636      Class: CTCTestCase
       
   637 
       
   638      Method: IsCompletelyFinished
       
   639 
       
   640      Description: Checks state and progress notifier.
       
   641 
       
   642      Parameters: None
       
   643 
       
   644      Return Values: TBool.
       
   645 
       
   646      Errors/Exceptions: None.
       
   647 
       
   648      Status: Proposal
       
   649 
       
   650 -------------------------------------------------------------------------------
       
   651 */
       
   652 TBool CTCTestCase::IsCompletelyFinished(void)
       
   653     {
       
   654     TBool result = (iState == CTCTestCase::ETestCaseCompleted);
       
   655 	if(iProgress)
       
   656 	    {
       
   657 		result = result && (iProgress->IsPrintProgressFinished());
       
   658 		}
       
   659     return result;
       
   660     }
       
   661 
       
   662 /*
       
   663 -------------------------------------------------------------------------------
       
   664 
       
   665     DESCRIPTION
       
   666 
       
   667     This module contains the implementation of CRemoteTestCase class 
       
   668     member functions.
       
   669 
       
   670 -------------------------------------------------------------------------------
       
   671 */
       
   672 
       
   673 // ================= MEMBER FUNCTIONS =========================================
       
   674 
       
   675 /*
       
   676 -------------------------------------------------------------------------------
       
   677 
       
   678      Class: CRemoteTestCase
       
   679 
       
   680      Method: CRemoteTestCase
       
   681 
       
   682      Description: Default constructor
       
   683 
       
   684      C++ default constructor can NOT contain any code, that
       
   685      might leave.
       
   686 
       
   687      Parameters: CTestCombiner* testCombiner: in: Backpointer to CTestCombiner
       
   688                  TInt aExpectedResult: in: expected result for the testcase
       
   689                  TFullTestResult::TCaseExecutionResult aCategory: in: 
       
   690                     result category
       
   691      Return Values: None.
       
   692 
       
   693      Errors/Exceptions: None.
       
   694 
       
   695      Status: Proposal
       
   696     
       
   697 -------------------------------------------------------------------------------
       
   698 */
       
   699 
       
   700 CRemoteTestCase::CRemoteTestCase( CTestCombiner* testCombiner,
       
   701                           TInt aExpectedResult,
       
   702                           TFullTestResult::TCaseExecutionResult aCategory ):
       
   703     CTestCase( testCombiner, aExpectedResult, aCategory, ECaseRemote, NULL ), //--PYTHON
       
   704     iRemoteState( ECaseIdle ),
       
   705     iFreeSlave( EFalse ) 
       
   706     {
       
   707     }
       
   708 
       
   709 /*
       
   710 -------------------------------------------------------------------------------
       
   711 
       
   712      Class: CRemoteTestCase
       
   713 
       
   714      Method: ConstructL
       
   715 
       
   716      Description: Symbian OS second phase constructor
       
   717 
       
   718      Symbian OS default constructor can leave.     
       
   719 
       
   720      Parameters: None. 
       
   721 
       
   722      Return Values: None.
       
   723 
       
   724      Errors/Exceptions: None
       
   725 
       
   726      Status: Proposal
       
   727     
       
   728 -------------------------------------------------------------------------------
       
   729 */
       
   730 
       
   731 void CRemoteTestCase::ConstructL( TDesC& aTestId )
       
   732     {
       
   733     CTestCase::ConstructL( aTestId );
       
   734     
       
   735     }
       
   736 
       
   737 /*
       
   738 -------------------------------------------------------------------------------
       
   739 
       
   740      Class: CRemoteTestCase
       
   741 
       
   742      Method: NewL
       
   743 
       
   744      Description: Two-phased constructor.
       
   745 
       
   746      Parameters: CTestCombiner* testCombiner: in: Backpointer to CTestCombiner
       
   747 
       
   748      Return Values: CRemoteTestCase*: pointer to new CRemoteTestCase object
       
   749 
       
   750      Errors/Exceptions: Leaves if new or ConstructL leaves.
       
   751 
       
   752      Status: Proposal
       
   753     
       
   754 -------------------------------------------------------------------------------
       
   755 */
       
   756 
       
   757 CRemoteTestCase* CRemoteTestCase::NewL( CTestCombiner* testCombiner,
       
   758                                 TDesC& aTestId, 
       
   759                                 TInt aExpectedResult,
       
   760                                 TFullTestResult::TCaseExecutionResult 
       
   761                                     aCategory )
       
   762     {
       
   763     CRemoteTestCase* self = new (ELeave) CRemoteTestCase( testCombiner, 
       
   764                                                    aExpectedResult,
       
   765                                                    aCategory );
       
   766      
       
   767     CleanupStack::PushL( self );
       
   768     self->ConstructL( aTestId );
       
   769     CleanupStack::Pop();
       
   770     return self;
       
   771      
       
   772     }
       
   773 
       
   774 /*
       
   775 -------------------------------------------------------------------------------
       
   776 
       
   777      Class: CRemoteTestCase
       
   778 
       
   779      Method: ~CRemoteTestCase
       
   780 
       
   781      Description: Destructor
       
   782      
       
   783      Parameters: None.
       
   784 
       
   785      Return Values: None.
       
   786 
       
   787      Errors/Exceptions: None.
       
   788      
       
   789      Status: Proposal
       
   790     
       
   791 -------------------------------------------------------------------------------
       
   792 */     
       
   793 
       
   794 CRemoteTestCase::~CRemoteTestCase()
       
   795     {        
       
   796     }
       
   797     
       
   798 /*
       
   799 -------------------------------------------------------------------------------
       
   800 
       
   801     DESCRIPTION
       
   802 
       
   803     This module contains the implementation of CTCTestModule class 
       
   804     member functions.
       
   805 
       
   806 -------------------------------------------------------------------------------
       
   807 */
       
   808 
       
   809 // ================= MEMBER FUNCTIONS =========================================
       
   810 
       
   811 /*
       
   812 -------------------------------------------------------------------------------
       
   813 
       
   814      Class: CTCTestModule
       
   815 
       
   816      Method: CTCTestModule
       
   817 
       
   818      Description: Default constructor
       
   819 
       
   820      C++ default constructor can NOT contain any code, that
       
   821      might leave.
       
   822 
       
   823      Parameters: TDesC& aModule: in: module name
       
   824                  TDesC& aIni: in: inifile name
       
   825      
       
   826      Return Values: None.
       
   827 
       
   828      Errors/Exceptions: None.
       
   829 
       
   830      Status: Approved
       
   831     
       
   832 -------------------------------------------------------------------------------
       
   833 */
       
   834 CTCTestModule::CTCTestModule( CTestCombiner* testCombiner ):
       
   835     iTestCombiner( testCombiner )
       
   836     {
       
   837     iTestCases = NULL;
       
   838     }
       
   839 
       
   840 /*
       
   841 -------------------------------------------------------------------------------
       
   842 
       
   843      Class: CTCTestModule
       
   844 
       
   845      Method: ConstructL
       
   846 
       
   847      Description: Symbian OS second phase constructor
       
   848 
       
   849      Symbian OS default constructor can leave.     
       
   850 
       
   851      Parameters: TDesC& aModule: in: Module name.
       
   852                  TDesC& aIni: in: Inifile name.
       
   853                  const TDesC& aConfigFile: in: Test case(config) file name. 
       
   854 
       
   855      Return Values: None.
       
   856 
       
   857      Errors/Exceptions: None
       
   858 
       
   859      Status: Proposal
       
   860     
       
   861 -------------------------------------------------------------------------------
       
   862 */
       
   863 
       
   864 void CTCTestModule::ConstructL( TDesC& aModule,
       
   865                                 TDesC& aIni,
       
   866                                 const TDesC& aConfigFile )
       
   867     {
       
   868     __TRACE( KMessage, ( _L("CTCTestModule::ConstructL [%S]"), &aModule));
       
   869     
       
   870     __ASSERT_ALWAYS( aModule.Length() < KMaxFileName, User::Leave( KErrArgument ) );
       
   871     __ASSERT_ALWAYS( aIni.Length() < KMaxFileName, User::Leave( KErrArgument ) );
       
   872     iModuleName = aModule.AllocL();
       
   873     iIniFile = aIni.AllocL();
       
   874     
       
   875     TFileName ini = *iIniFile;
       
   876     // Open handles
       
   877     __TRACE( KMessage, ( _L("CTCTestModule: Server connect")));    
       
   878     User::LeaveIfError( iTestServer.Connect( ModuleName(), aConfigFile ) ); 
       
   879     __TRACE( KMessage, ( _L("CTCTestModule: Module open")));
       
   880     User::LeaveIfError( iTestModule.Open( iTestServer, ini ) );
       
   881     
       
   882     iErrorPrinter = CTestErrorNotifier::NewL( iTestCombiner, this );
       
   883   
       
   884     }
       
   885 
       
   886 /*
       
   887 -------------------------------------------------------------------------------
       
   888 
       
   889      Class: CTCTestModule
       
   890 
       
   891      Method: NewL
       
   892 
       
   893      Description: Two-phased constructor.
       
   894 
       
   895      Parameters: None
       
   896      
       
   897      Return Values: TDesC& aModule: in: Module name.
       
   898                     TDesC& aIni: in: Inifile name.
       
   899                     const TDesC& aConfigFile: in: Test case(config) file name.
       
   900      
       
   901      Errors/Exceptions: Leaves if ConstructL leaves
       
   902                         Leaves if memory allocation fails
       
   903                         Leaves if illegal arguments are given
       
   904 
       
   905      Status: Proposal
       
   906     
       
   907 -------------------------------------------------------------------------------
       
   908 */
       
   909 
       
   910 CTCTestModule* CTCTestModule::NewL( CTestCombiner* testCombiner,
       
   911                                     TDesC& aModule, 
       
   912                                     TDesC& aIni,
       
   913                                     const TDesC& aConfigFile )
       
   914     {
       
   915     CTCTestModule* self = new (ELeave) CTCTestModule( testCombiner );
       
   916     
       
   917     CleanupStack::PushL( self );
       
   918     self->ConstructL( aModule, aIni, aConfigFile );
       
   919     CleanupStack::Pop();
       
   920 
       
   921     return self;
       
   922      
       
   923     }
       
   924 
       
   925 /*
       
   926 
       
   927 -------------------------------------------------------------------------------
       
   928 
       
   929      Class: CTCTestModule
       
   930 
       
   931      Method: ~CTCTestModule
       
   932 
       
   933      Description: Destructor
       
   934      
       
   935      Parameters:    None.
       
   936 
       
   937      Return Values: None.
       
   938 
       
   939      Errors/Exceptions: None.
       
   940      
       
   941      Status: Approved
       
   942     
       
   943 -------------------------------------------------------------------------------
       
   944 */     
       
   945 
       
   946 CTCTestModule::~CTCTestModule()
       
   947     {
       
   948     __TRACE( KMessage, ( _L("CTCTestModule::~CTCTestModule [%S]"), iModuleName));
       
   949     
       
   950     // delete error printer
       
   951     delete iErrorPrinter;
       
   952     // Close handles
       
   953     if( iTestServer.Handle() != 0 )
       
   954         {
       
   955         iTestModule.Close();
       
   956         iTestServer.Close();
       
   957         }
       
   958     delete iModuleName;
       
   959     delete iIniFile;
       
   960     delete iTestCases;
       
   961     }
       
   962 
       
   963 /*
       
   964 -------------------------------------------------------------------------------
       
   965 
       
   966      Class: CTCTestModule
       
   967 
       
   968      Method: GetTestCasesForCombiner
       
   969 
       
   970      Description: Get array of test cases (used to find test case number by title)
       
   971      
       
   972      Parameters:    const TDesC& aConfigFile: in: config file name.
       
   973 
       
   974      Return Values: None.
       
   975 
       
   976      Errors/Exceptions: None.
       
   977      
       
   978      Status: Proposal
       
   979     
       
   980 -------------------------------------------------------------------------------
       
   981 */
       
   982 void CTCTestModule::GetTestCasesForCombiner(const TDesC& aConfigFile)
       
   983     {
       
   984     __TRACE(KMessage, (_L("Going to enumerate test cases for TestCombiner")));
       
   985     TName configFile(aConfigFile);
       
   986 
       
   987     // Enumerate test cases
       
   988     TCaseCount caseCount;
       
   989     TRequestStatus status;
       
   990     iTestModule.EnumerateTestCases(configFile, caseCount, status);
       
   991     User::WaitForRequest(status);
       
   992 
       
   993     // Check that enumerate succeeded
       
   994     if(status != KErrNone)
       
   995         {
       
   996         __TRACE(KMessage, (_L("Enumerating test cases from module returned error. Status %d."), status.Int()));
       
   997         return;
       
   998     	}
       
   999     __TRACE(KMessage, (_L("Enumeration for TestCombiner returned %d cases"), caseCount()));
       
  1000 
       
  1001     // Get test cases to buffer
       
  1002     iTestCases = CFixedFlatArray<TTestCaseInfo>::NewL(caseCount());
       
  1003 
       
  1004     TInt ret = iTestModule.GetTestCases(*iTestCases);
       
  1005     if(ret != KErrNone)
       
  1006         {
       
  1007         __TRACE(KMessage, (_L("Getting test cases from module returned error %d."), ret));
       
  1008         return;
       
  1009         }
       
  1010 
       
  1011     __TRACE(KMessage, (_L("Test cases for TestCombiner have been enumerated")));
       
  1012     }
       
  1013 
       
  1014 
       
  1015 /*
       
  1016 -------------------------------------------------------------------------------
       
  1017 
       
  1018      Class: CTCTestModule
       
  1019 
       
  1020      Method: GetCaseNumByTitle
       
  1021 
       
  1022      Description: Finds test case index by title
       
  1023 
       
  1024      Parameters:    TDesC& aTitle: in: test case title.
       
  1025                     TInt& aCaseNum: in out: test case index
       
  1026 
       
  1027      Return Values: KErrNone if everything is ok
       
  1028                     KErrNotFound if there is no such test case
       
  1029 
       
  1030      Errors/Exceptions: None.
       
  1031 
       
  1032      Status: Proposal
       
  1033 
       
  1034 -------------------------------------------------------------------------------
       
  1035 */
       
  1036 TInt CTCTestModule::GetCaseNumByTitle(TDesC& aTitle, TInt& aCaseNum)
       
  1037     {
       
  1038     for(TInt i = 0; i < iTestCases->Count(); i++)
       
  1039         {
       
  1040         if((*iTestCases)[i].iTitle == aTitle)
       
  1041             {
       
  1042             aCaseNum = i;
       
  1043             //TestScripter relies on 1-based indexing
       
  1044             if((iModuleName->Find(KTestScripterName) != KErrNotFound) || (iModuleName->Find(KPythonScripter) != KErrNotFound) || (iModuleName->Find(KTestCombinerName) != KErrNotFound))
       
  1045                 aCaseNum++;
       
  1046             return KErrNone;
       
  1047             }
       
  1048         }
       
  1049     
       
  1050     return KErrNotFound;
       
  1051     }
       
  1052 
       
  1053 /*
       
  1054 -------------------------------------------------------------------------------
       
  1055 
       
  1056     DESCRIPTION
       
  1057 
       
  1058     This module contains the implementation of CRemoteSendReceive class 
       
  1059     member functions.
       
  1060 
       
  1061 -------------------------------------------------------------------------------
       
  1062 */
       
  1063 
       
  1064 // ================= MEMBER FUNCTIONS =========================================
       
  1065 
       
  1066 /*
       
  1067 -------------------------------------------------------------------------------
       
  1068 
       
  1069      Class: CRemoteSendReceive
       
  1070 
       
  1071      Method: CRemoteSendReceive
       
  1072 
       
  1073      Description: Default constructor
       
  1074 
       
  1075      C++ default constructor can NOT contain any code, that
       
  1076      might leave.
       
  1077 
       
  1078      Parameters: 
       
  1079 
       
  1080      Return Values: None.
       
  1081 
       
  1082      Errors/Exceptions: None.
       
  1083 
       
  1084      Status: Proposal
       
  1085     
       
  1086 -------------------------------------------------------------------------------
       
  1087 */
       
  1088 CRemoteSendReceive::CRemoteSendReceive( CTestCombiner* aTestCombiner  ) :
       
  1089     iTestCombiner( aTestCombiner )
       
  1090     {
       
  1091     // None
       
  1092 
       
  1093     }
       
  1094 
       
  1095 /*
       
  1096 -------------------------------------------------------------------------------
       
  1097 
       
  1098      Class: CRemoteSendReceive
       
  1099 
       
  1100      Method: ConstructL
       
  1101 
       
  1102      Description: Symbian OS second phase constructor
       
  1103 
       
  1104      Symbian OS default constructor can leave.     
       
  1105 
       
  1106      Parameters: None. 
       
  1107 
       
  1108      Return Values: None.
       
  1109 
       
  1110      Errors/Exceptions: None
       
  1111 
       
  1112      Status: Proposal
       
  1113     
       
  1114 -------------------------------------------------------------------------------
       
  1115 */
       
  1116 void CRemoteSendReceive::ConstructL()
       
  1117     {
       
  1118     // None
       
  1119     
       
  1120     }
       
  1121 
       
  1122 /*
       
  1123 -------------------------------------------------------------------------------
       
  1124 
       
  1125      Class: CRemoteSendReceive
       
  1126 
       
  1127      Method: NewL
       
  1128 
       
  1129      Description: Two-phased constructor.
       
  1130 
       
  1131      Parameters: 
       
  1132 
       
  1133      Return Values: CRemoteTestCase*: pointer to new CRemoteTestCase object
       
  1134 
       
  1135      Errors/Exceptions: Leaves if new or ConstructL leaves.
       
  1136 
       
  1137      Status: Proposal
       
  1138     
       
  1139 -------------------------------------------------------------------------------
       
  1140 */
       
  1141 CRemoteSendReceive* CRemoteSendReceive::NewL( CTestCombiner* aTestCombiner )
       
  1142     {
       
  1143     CRemoteSendReceive* self = new (ELeave) CRemoteSendReceive( aTestCombiner );
       
  1144      
       
  1145     CleanupStack::PushL( self );
       
  1146     self->ConstructL();
       
  1147     CleanupStack::Pop();
       
  1148     return self;
       
  1149      
       
  1150     }
       
  1151 
       
  1152 /*
       
  1153 -------------------------------------------------------------------------------
       
  1154 
       
  1155      Class: CRemoteSendReceive
       
  1156 
       
  1157      Method: ~CRemoteSendReceive
       
  1158 
       
  1159      Description: Destructor
       
  1160      
       
  1161      Parameters: None.
       
  1162 
       
  1163      Return Values: None.
       
  1164 
       
  1165      Errors/Exceptions: None.
       
  1166      
       
  1167      Status: Proposal
       
  1168     
       
  1169 -------------------------------------------------------------------------------
       
  1170 */     
       
  1171 CRemoteSendReceive::~CRemoteSendReceive()
       
  1172     {
       
  1173     // None
       
  1174 
       
  1175     }
       
  1176 
       
  1177 //  End of File