stif/TestEngine/src/TestEngine.cpp
branchRCL_3
changeset 19 07b41fa8d1dd
parent 18 3406c99bc375
child 20 ca8a1b6995f6
equal deleted inserted replaced
18:3406c99bc375 19:07b41fa8d1dd
     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 * CTestEngineServer class member functions.
       
    16 *
       
    17 */
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <e32std.h>
       
    21 #include <e32svr.h>
       
    22 #include <f32file.h>
       
    23 #include "TestEngine.h"
       
    24 #include "TestEngineClient.h"
       
    25 #include "TestEngineCommon.h"
       
    26 #include <stifinternal/TestServerClient.h>
       
    27 #include "TestModuleController.h"
       
    28 #include "TestCaseController.h"
       
    29 #include "TestReport.h"
       
    30 #include "Logging.h"
       
    31 #include "SettingServerClient.h"
       
    32 //--PYTHON-- begin
       
    33 #include "StifPython.h"
       
    34 #include "StifPythonFunEng.h"
       
    35 //--PYTHON-- end
       
    36 
       
    37 // EXTERNAL DATA STRUCTURES
       
    38 // None
       
    39 
       
    40 // EXTERNAL FUNCTION PROTOTYPES  
       
    41 // None
       
    42 
       
    43 // CONSTANTS
       
    44 _LIT( KTestModule, "TestModule=" );
       
    45 _LIT( KTestCaseFile, "TestCaseFile=" );
       
    46 _LIT( KTestCaseNumber, "TestCaseNumber=" );
       
    47 _LIT( KTestCaseTitle, "TestCaseTitle=" );
       
    48 _LIT( KStateCode, "StateCode=" );
       
    49 _LIT( KStateName, "StateName=" );
       
    50     
       
    51 // MACROS
       
    52 // None
       
    53 
       
    54 // LOCAL CONSTANTS AND MACROS
       
    55 // None
       
    56 
       
    57 // MODULE DATA STRUCTURES
       
    58 struct TThreadStartTestEngine
       
    59     {   
       
    60     RThread    iEngineThread; // The server thread
       
    61     RSemaphore iStarted;      // Startup syncronisation semaphore   
       
    62     };
       
    63 
       
    64 // LOCAL FUNCTION PROTOTYPES
       
    65 // None
       
    66 
       
    67 // FORWARD DECLARATIONS
       
    68 // None
       
    69 
       
    70 // ==================== LOCAL FUNCTIONS =======================================
       
    71 // None
       
    72 
       
    73 // ================= MEMBER FUNCTIONS =========================================
       
    74 
       
    75 /*
       
    76 -------------------------------------------------------------------------------
       
    77 
       
    78     Class: CTestEngine
       
    79    
       
    80     Function: ErrorPrint
       
    81 
       
    82     Description: ErrorPrint
       
    83 
       
    84     Parameters: const TInt aPriority: in: Priority of error
       
    85                 TPtrC aError: in: Error description
       
    86 
       
    87     Return Values: None
       
    88 
       
    89     Errors/Exceptions: None
       
    90 
       
    91     Status: Approved
       
    92 
       
    93 -------------------------------------------------------------------------------
       
    94 */
       
    95 void CTestEngine::ErrorPrint( const TInt aPriority, 
       
    96                               TPtrC aError )
       
    97     {
       
    98     TErrorNotification error;
       
    99     TErrorNotificationPckg errorPckg ( error );
       
   100 
       
   101     error.iModule = _L("TestEngine");
       
   102     error.iPriority = aPriority;
       
   103     error.iText = aError;
       
   104 
       
   105     ErrorPrint( errorPckg );
       
   106 
       
   107     }
       
   108 
       
   109 /*
       
   110 -------------------------------------------------------------------------------
       
   111 
       
   112     Class: CTestModule
       
   113 
       
   114     Method: ErrorPrint
       
   115 
       
   116     Description: Sends error notification
       
   117 
       
   118     Parameters: TErrorNotificationPckg aError: in: Error
       
   119 
       
   120     Return Values: None
       
   121 
       
   122     Errors/Exceptions: None
       
   123 
       
   124     Status: Approved
       
   125 
       
   126 -------------------------------------------------------------------------------
       
   127 */
       
   128 void CTestEngine::ErrorPrint( TErrorNotificationPckg aError )
       
   129     {
       
   130     // Add new item to end of queue
       
   131      if ( iErrorQueue.Append ( aError() ) != KErrNone )
       
   132             {
       
   133             RDebug::Print (_L("Error message lost"));
       
   134             return;
       
   135             }
       
   136 
       
   137     ProcessErrorQueue();
       
   138 
       
   139     }
       
   140 
       
   141 /*
       
   142 -------------------------------------------------------------------------------
       
   143 
       
   144     Class: CTestModule
       
   145 
       
   146     Method: ProcessErrorQueue
       
   147 
       
   148     Description: Process error queue
       
   149 
       
   150     Parameters: None
       
   151 
       
   152     Return Values: None
       
   153 
       
   154     Errors/Exceptions: None
       
   155 
       
   156     Status: Approved
       
   157 
       
   158 -------------------------------------------------------------------------------
       
   159 */
       
   160 void CTestEngine::ProcessErrorQueue()
       
   161     {
       
   162     // If message is available, complete first item from queue
       
   163     if ( iErrorMessageAvailable )
       
   164         {
       
   165         
       
   166         if ( iErrorQueue.Count() > 0 )
       
   167             {
       
   168             TErrorNotification err = iErrorQueue[0];
       
   169             TErrorNotificationPckg errPckg(err);
       
   170             iErrorQueue.Remove(0);
       
   171         
       
   172         	TInt r( KErrNone );
       
   173         
       
   174             TRAP( r, iErrorMessage.WriteL( 0, errPckg ) );
       
   175 
       
   176             // Do not handle errors
       
   177 
       
   178             iErrorMessageAvailable = EFalse;
       
   179             iErrorMessage.Complete( KErrNone );
       
   180             }
       
   181         }
       
   182 
       
   183     }
       
   184 
       
   185 /*
       
   186 -------------------------------------------------------------------------------
       
   187    
       
   188     Function: LeaveIfErrorWithNotify
       
   189 
       
   190     Description: If error leave with notify
       
   191 
       
   192     Parameters: TInt aCode: in: Error code
       
   193     
       
   194     Return Values: None
       
   195 
       
   196     Errors/Exceptions: None
       
   197 
       
   198     Status: Approved
       
   199 
       
   200 -------------------------------------------------------------------------------
       
   201 */
       
   202 void CTestEngine::LeaveIfErrorWithNotify( TInt aCode )
       
   203       {
       
   204       LeaveIfErrorWithNotify ( aCode, _L("Check testengine log") );
       
   205 
       
   206       }
       
   207 
       
   208 /*
       
   209 -------------------------------------------------------------------------------
       
   210    
       
   211     Function: LeaveIfErrorWithNotify
       
   212 
       
   213     Description: If error leave with notify
       
   214 
       
   215     Parameters: TInt aCode: in: Error code
       
   216                 const TDesC& aText: in: Descriptive text
       
   217 
       
   218     Return Values: None
       
   219 
       
   220     Errors/Exceptions: None
       
   221 
       
   222     Status: Approved
       
   223 
       
   224 -------------------------------------------------------------------------------
       
   225 */
       
   226 void CTestEngine::LeaveIfErrorWithNotify( TInt aCode,
       
   227                                           const TDesC& aText )
       
   228     {
       
   229     if ( aCode != KErrNone )
       
   230         {
       
   231            LeaveWithNotifyL ( aCode, aText );
       
   232         }
       
   233 
       
   234     }
       
   235 
       
   236 /*
       
   237 -------------------------------------------------------------------------------
       
   238 
       
   239     Function: LeaveWithNotifyL
       
   240 
       
   241     Description: Leave with notify
       
   242 
       
   243     Parameters: TInt aCode: in: Error code
       
   244 
       
   245     Return Values: None
       
   246 
       
   247     Errors/Exceptions: None
       
   248 
       
   249     Status: Approved
       
   250 
       
   251 -------------------------------------------------------------------------------
       
   252 */
       
   253 void CTestEngine::LeaveWithNotifyL( TInt aCode )
       
   254     {
       
   255     LeaveWithNotifyL ( aCode, _L("Check testengine log") );
       
   256 
       
   257     }
       
   258 
       
   259 /*
       
   260 -------------------------------------------------------------------------------
       
   261 
       
   262     Function: LeaveWithNotifyL
       
   263 
       
   264     Description: Leave with notify
       
   265 
       
   266     Parameters: TInt aCode: in: Error code
       
   267                 const TDesC& aText: in: Descriptive text
       
   268 
       
   269     Return Values: None
       
   270 
       
   271     Errors/Exceptions: None
       
   272 
       
   273     Status: Approved
       
   274 
       
   275 -------------------------------------------------------------------------------
       
   276 */
       
   277 void CTestEngine::LeaveWithNotifyL( TInt aCode,
       
   278                                    const TDesC& aText )
       
   279     {
       
   280     ErrorPrint ( 0, aText );
       
   281     User::Leave ( aCode );
       
   282 
       
   283     }
       
   284 
       
   285 #define LOGGER iLogger
       
   286 
       
   287 /*
       
   288 -------------------------------------------------------------------------------
       
   289 
       
   290     Function: ThreadFunction
       
   291 
       
   292     Description: The thread function, where Test Engine lives in.
       
   293 
       
   294     Parameters: TAny* aStarted: in: Start info
       
   295 
       
   296     Return Values: TInt: Returns always KErrNone
       
   297 
       
   298     Errors/Exceptions: None
       
   299 
       
   300     Status: Approved
       
   301 
       
   302 -------------------------------------------------------------------------------
       
   303 */
       
   304 TInt CTestEngineServer::ThreadFunction( TAny* aStarted )
       
   305     {
       
   306 //    __UHEAP_MARK;
       
   307 
       
   308     // Create cleanup stack
       
   309     CTrapCleanup* cleanup = CTrapCleanup::New();
       
   310     __ASSERT_ALWAYS( cleanup, PanicServer( ECreateTrapCleanup ) );
       
   311 
       
   312     // Get start-up information
       
   313     TThreadStartTestEngine* startInfo = ( TThreadStartTestEngine* ) aStarted;
       
   314     __ASSERT_ALWAYS( startInfo, PanicServer( ENoStartupInformation ) );
       
   315 
       
   316     // Construct and install active scheduler
       
   317     CActiveScheduler* scheduler = new CActiveScheduler;
       
   318     __ASSERT_ALWAYS( scheduler, PanicServer( EMainSchedulerError ) );
       
   319     CActiveScheduler::Install( scheduler );
       
   320 
       
   321     // Construct server, an active object
       
   322     CTestEngineServer* server = NULL;
       
   323     TRAPD( err, server = CTestEngineServer::NewL() );
       
   324     __ASSERT_ALWAYS( !err, PanicServer( ESvrCreateServer ) );
       
   325 
       
   326     // Inform that we are up and running
       
   327     startInfo->iStarted.Signal();
       
   328 
       
   329     // Global mutex(handling according to the name)
       
   330     RMutex startupMutex;
       
   331     // Try to create global mutex, CREATE
       
   332     TInt ret = startupMutex.CreateGlobal( KStifTestServerStartupMutex );
       
   333     if( ret != KErrNone )
       
   334         {
       
   335         // Mutex already create, OPEN
       
   336         ret = startupMutex.OpenGlobal( KStifTestServerStartupMutex );
       
   337         }
       
   338     if( ret != KErrNone )
       
   339         {
       
   340         // Not able to create or open mutex
       
   341         return ret;
       
   342         }
       
   343 
       
   344     // Start handling requests
       
   345     CActiveScheduler::Start();
       
   346 
       
   347     startupMutex.Close();
       
   348 
       
   349     // Should come here after RTestEngineServer is closed
       
   350     delete server;
       
   351     delete scheduler;
       
   352     delete cleanup;
       
   353 
       
   354 //    __UHEAP_MARKEND;
       
   355 
       
   356     return KErrNone;
       
   357 
       
   358     }
       
   359 
       
   360 /*
       
   361 -------------------------------------------------------------------------------
       
   362 
       
   363     Class: CTestEngineServer
       
   364 
       
   365     Method: CTestEngineServer
       
   366 
       
   367     Description: Default constructor
       
   368 
       
   369     C++ default constructor can NOT contain any code, that
       
   370     might leave.
       
   371 
       
   372     Parameters: None
       
   373 
       
   374     Return Values: None
       
   375 
       
   376     Errors/Exceptions: None
       
   377 
       
   378     Status: Approved
       
   379 
       
   380 -------------------------------------------------------------------------------
       
   381 */
       
   382 CTestEngineServer::CTestEngineServer() :
       
   383     CServer2( CTestEngineServer::ETestEngineServerPriority ),
       
   384     iSessionCount( 0 )
       
   385     {
       
   386 
       
   387     }
       
   388 
       
   389 /*
       
   390 -------------------------------------------------------------------------------
       
   391 
       
   392     Class: CTestEngineServer
       
   393 
       
   394     Method: ConstructL
       
   395 
       
   396     Description: Symbian OS second phase constructor
       
   397 
       
   398     Symbian OS default constructor can leave.
       
   399 
       
   400     Parameters: None
       
   401 
       
   402     Return Values: None
       
   403 
       
   404     Errors/Exceptions: Leaves if CObjectConIx::NewL leaves
       
   405                        Leaves if CStifLogger::NewL leaves
       
   406                        Leaves if StartL leaves
       
   407 
       
   408     Status: Approved
       
   409 
       
   410 -------------------------------------------------------------------------------
       
   411 */
       
   412 void CTestEngineServer::ConstructL()
       
   413     {
       
   414     // Create report setting
       
   415     iTestReportSettings = CTestReportSettings::NewL();
       
   416     // Create container
       
   417     iContainerIndex = CObjectConIx::NewL();
       
   418 
       
   419     // Create logger, in Wins use HTML in HW default logger
       
   420     TLoggerSettings loggerSettings;
       
   421 
       
   422     // Directory must create by hand if test engine log wanted
       
   423     loggerSettings.iCreateLogDirectories = EFalse;
       
   424 
       
   425     loggerSettings.iOverwrite = ETrue;
       
   426     loggerSettings.iTimeStamp = ETrue;
       
   427     loggerSettings.iLineBreak = ETrue;
       
   428     loggerSettings.iEventRanking = EFalse;
       
   429     loggerSettings.iThreadId = EFalse;
       
   430     loggerSettings.iHardwareFormat = CStifLogger::ETxt;
       
   431 #ifndef FORCE_STIF_INTERNAL_LOGGING_TO_RDEBUG
       
   432     loggerSettings.iEmulatorFormat = CStifLogger::EHtml;
       
   433     loggerSettings.iEmulatorOutput = CStifLogger::EFile;
       
   434     loggerSettings.iHardwareOutput = CStifLogger::EFile;
       
   435 #else
       
   436     RDebug::Print( _L( "STIF Test Engine logging forced to RDebug" ) );
       
   437     loggerSettings.iEmulatorFormat = CStifLogger::ETxt;
       
   438     loggerSettings.iEmulatorOutput = CStifLogger::ERDebug;
       
   439     loggerSettings.iHardwareOutput = CStifLogger::ERDebug;
       
   440 #endif
       
   441     loggerSettings.iUnicode = EFalse;
       
   442     loggerSettings.iAddTestCaseTitle = EFalse;
       
   443 
       
   444     iLogger = CStifLogger::NewL( _L( "C:\\logs\\testframework\\testengine\\"),
       
   445                                     _L( "testengine" ),
       
   446                                     loggerSettings );
       
   447     // Start Server
       
   448     StartL( KTestEngineName );
       
   449 
       
   450     __TRACE(KVerbose, (_L( "CTestEngineServer::ConstructL: Server Created" ) ) );
       
   451 
       
   452     }
       
   453 
       
   454 /*
       
   455 -------------------------------------------------------------------------------
       
   456 
       
   457     Class: CTestEngineServer
       
   458 
       
   459     Method: NewL
       
   460 
       
   461     Description: Two-phased constructor.
       
   462 
       
   463     Parameters: None
       
   464 
       
   465     Return Values: CTestEngineServer* : pointer to CTestEngineServer object
       
   466 
       
   467     Errors/Exceptions: Leaves if construction of CBufferArray fails
       
   468 
       
   469     Status: Approved
       
   470 
       
   471 -------------------------------------------------------------------------------
       
   472 */
       
   473 CTestEngineServer* CTestEngineServer::NewL()
       
   474     {
       
   475     CTestEngineServer* self = new ( ELeave ) CTestEngineServer();
       
   476     CleanupStack::PushL( self );      
       
   477     self->ConstructL();
       
   478     CleanupStack::Pop();
       
   479 
       
   480     return self;
       
   481 
       
   482     }
       
   483 
       
   484 /*
       
   485 -------------------------------------------------------------------------------
       
   486 
       
   487     Class: CTestEngineServer
       
   488 
       
   489     Method: ~CTestEngineServer
       
   490 
       
   491     Description: Destructor
       
   492 
       
   493     Parameters: None
       
   494 
       
   495     Return Values: None
       
   496 
       
   497     Errors/Exceptions: None
       
   498 
       
   499     Status: Approved
       
   500 
       
   501 -------------------------------------------------------------------------------
       
   502 */
       
   503 CTestEngineServer::~CTestEngineServer()
       
   504     {
       
   505     delete iContainerIndex; 
       
   506 
       
   507     __TRACE(KAlways, ( _L( "---------------- Log Ended ----------------" ) ) );
       
   508     delete iLogger;
       
   509 
       
   510     delete iTestReportSettings;
       
   511     iTestReportSettings = NULL;
       
   512     }
       
   513 
       
   514 /*
       
   515 -------------------------------------------------------------------------------
       
   516 
       
   517     Class: CTestEngineServer
       
   518 
       
   519     Method: NewContainerL
       
   520 
       
   521     Description: Create new container
       
   522 
       
   523     Parameters: None
       
   524 
       
   525     Return Values: None
       
   526 
       
   527     Errors/Exceptions: Leaves if called CreateL method leaves
       
   528 
       
   529     Status: Approved
       
   530 
       
   531 -------------------------------------------------------------------------------
       
   532 */
       
   533 CObjectCon* CTestEngineServer::NewContainerL()
       
   534     {
       
   535     CObjectCon* container = iContainerIndex->CreateL();
       
   536 
       
   537     iSessionCount++;
       
   538 
       
   539     return container;
       
   540 
       
   541     }
       
   542 
       
   543 /*
       
   544 -------------------------------------------------------------------------------
       
   545 
       
   546     Class: CTestEngineServer
       
   547 
       
   548     Method: DeleteContainer
       
   549 
       
   550     Description: Deletes a container
       
   551 
       
   552     Parameters: CObjectCon* 
       
   553 
       
   554     Return Values: None
       
   555 
       
   556     Errors/Exceptions: None
       
   557 
       
   558     Status: Approved
       
   559 
       
   560 -------------------------------------------------------------------------------
       
   561 */
       
   562 void CTestEngineServer::DeleteContainer( CObjectCon* aContainer )
       
   563     {
       
   564     iContainerIndex->Remove( aContainer );
       
   565 
       
   566     }
       
   567 
       
   568 /*
       
   569 -------------------------------------------------------------------------------
       
   570 
       
   571     Class: CTestEngineServer
       
   572 
       
   573     Method: SessionClosed
       
   574 
       
   575     Description: Inform Server that session is closed.
       
   576 
       
   577     Parameters: None
       
   578 
       
   579     Return Values: None
       
   580 
       
   581     Errors/Exceptions: None
       
   582 
       
   583     Status: Approved
       
   584 
       
   585 -------------------------------------------------------------------------------
       
   586 */
       
   587 void CTestEngineServer::SessionClosed()
       
   588     {
       
   589     // Decrease session count
       
   590     iSessionCount--;
       
   591 
       
   592     // Check if last session is closed
       
   593     if ( iSessionCount <= 0 )
       
   594         {
       
   595         // Stop the active scheduler
       
   596         // Execution will continue in ThreadFunction()
       
   597         CActiveScheduler::Stop();
       
   598         }
       
   599 
       
   600     }
       
   601 
       
   602 /*
       
   603 -------------------------------------------------------------------------------
       
   604 
       
   605     Class: CTestEngineServer
       
   606 
       
   607     Method: NewSessionL
       
   608 
       
   609     Description: Create a new client session for this server.
       
   610 
       
   611     Parameters: const TVersion& aVersion: in: Client side version number
       
   612 
       
   613     Return Values: CSharableSession* : pointer to CSharableSession object
       
   614 
       
   615     Errors/Exceptions: Leaves if given version is incorrect
       
   616                        Leaves if CTestEngine::NewL leaves
       
   617 
       
   618     Status: Approved
       
   619 
       
   620 -------------------------------------------------------------------------------
       
   621 */
       
   622 CSession2* CTestEngineServer::NewSessionL( const TVersion &aVersion,
       
   623                                          const RMessage2& /*aMessage*/ ) const
       
   624     {
       
   625     // Check that version is ok
       
   626     TVersion v( KTestEngineMajorVersionNumber,
       
   627                 KTestEngineMinorVersionNumber,
       
   628                 KTestEngineBuildVersionNumber );
       
   629     if ( !User::QueryVersionSupported( v, aVersion ) )
       
   630         {
       
   631         User::Leave( KErrNotSupported );
       
   632         }
       
   633 
       
   634     return CTestEngine::NewL( ( CTestEngineServer* ) this );
       
   635     }
       
   636 
       
   637 /*
       
   638 -------------------------------------------------------------------------------
       
   639 
       
   640     Class: CTestEngineServer
       
   641 
       
   642     Method: PanicServer
       
   643 
       
   644     Description: Panic the server
       
   645 
       
   646     Parameters: TTestEnginePanic aPanic: in: Panic number
       
   647 
       
   648     Return Values: None
       
   649 
       
   650     Errors/Exceptions: None
       
   651 
       
   652     Status: Approved
       
   653 
       
   654 -------------------------------------------------------------------------------
       
   655 */
       
   656 void CTestEngineServer::PanicServer( TTestEnginePanic aPanic )
       
   657     {
       
   658     _LIT( KTestServer, "CTestEngineServer" );
       
   659     User::Panic( KTestServer, aPanic );
       
   660 
       
   661     }
       
   662 
       
   663 /*
       
   664 -------------------------------------------------------------------------------
       
   665 
       
   666     Class: CTestEngineServer
       
   667 
       
   668     Method: Logger
       
   669 
       
   670     Description: Return the pointer to iLogger.
       
   671 
       
   672     Parameters: None
       
   673 
       
   674     Return Values: CStifLogger*: Pointer to StifLogger
       
   675 
       
   676     Errors/Exceptions: None
       
   677 
       
   678     Status: Approved
       
   679 
       
   680 -------------------------------------------------------------------------------
       
   681 */
       
   682 CStifLogger* CTestEngineServer::Logger()
       
   683     {
       
   684     return iLogger;
       
   685 
       
   686     }
       
   687 
       
   688 /*
       
   689 -------------------------------------------------------------------------------
       
   690 
       
   691     DESCRIPTION
       
   692 
       
   693     This module contains implementation of CTestEngine class member functions.
       
   694 
       
   695 -------------------------------------------------------------------------------
       
   696 */
       
   697 #undef LOGGER
       
   698 #define LOGGER Logger()
       
   699 
       
   700 // ================= MEMBER FUNCTIONS =========================================
       
   701 
       
   702 /*
       
   703 -------------------------------------------------------------------------------
       
   704 
       
   705     Class: CTestEngine
       
   706 
       
   707     Method: CTestEngine
       
   708 
       
   709     Description: Default constructor
       
   710 
       
   711     C++ default constructor can NOT contain any code, that
       
   712     might leave.
       
   713 
       
   714     Parameters: RThread& aClient: in: Client's thread
       
   715 
       
   716     Return Values: None
       
   717 
       
   718     Errors/Exceptions: None
       
   719 
       
   720     Status: Approved
       
   721 
       
   722 -------------------------------------------------------------------------------
       
   723 */
       
   724     CTestEngine::CTestEngine() :
       
   725         CSession2(),
       
   726     iReportMode( CTestReport::ETestReportFull ),
       
   727     iReportOutput( CTestReport::ETestReportNone ),
       
   728     iEnumerateModuleCount( 0 ),
       
   729     iIsTestReportGenerated( EFalse ),
       
   730     iDisableMeasurement( EEnableAll)
       
   731     {
       
   732 
       
   733     }
       
   734 
       
   735 /*
       
   736 -------------------------------------------------------------------------------
       
   737 
       
   738     Class: CTestEngine
       
   739 
       
   740     Method: ConstructL
       
   741 
       
   742     Description: Symbian OS second phase constructor
       
   743 
       
   744     Symbian OS default constructor can leave.
       
   745 
       
   746     Parameters: CTestEngineServer* aServer: in: Pointer to CTestEngineServer
       
   747 
       
   748     Return Values: None
       
   749 
       
   750     Errors/Exceptions: Leaves if some of called leaving methods leaves
       
   751 
       
   752     Status: Approved
       
   753 
       
   754 -------------------------------------------------------------------------------
       
   755 */
       
   756 void CTestEngine::ConstructL( CTestEngineServer* aServer )
       
   757     {
       
   758     // Log version info
       
   759     TInt majorV;
       
   760     TInt minorV;
       
   761     TInt buildV;
       
   762     TBuf<30> relDate;
       
   763     TStifUtil::STIFVersion(majorV, minorV, buildV, relDate);
       
   764     RDebug::Print(_L( "STIF startup... version %d.%d.%d (%S)"), majorV, minorV, buildV, &relDate);
       
   765 
       
   766 
       
   767     // Second-phase construct base class
       
   768     //CSession2::CreateL();
       
   769 
       
   770     iTestEngineServer = aServer;
       
   771 
       
   772     // Create new object index
       
   773     iTestEngineSubSessions = CObjectIx::NewL();
       
   774 
       
   775     // Create new object index
       
   776     iTestCases = CObjectIx::NewL();
       
   777     
       
   778     // Initialize the object container from Server
       
   779     iContainer = iTestEngineServer->NewContainerL();
       
   780 
       
   781     __TRACE(KInit, (_L( "STIF startup... version %d.%d.%d (%S)"), majorV, minorV, buildV, &relDate));
       
   782     __TRACE( KInit, ( _L( "CTestEngine::ConstructL: Test Engine Created" ) ) );
       
   783 
       
   784    
       
   785     RFs iFs;
       
   786     User::LeaveIfError( iFs.Connect() );
       
   787     _LIT(KCSteve,"C:\\Testframework\\");
       
   788     iFs.MkDirAll(KCSteve);
       
   789       
       
   790     iFs.Close();
       
   791     
       
   792     iRebootDefaultPath.Set( _L( "C:\\TestFramework\\" ) );
       
   793     iRebootDefaultFilename.Set( _L( "Reboot.txt" ) );
       
   794 
       
   795     TPtrC dllName;
       
   796     dllName.Set( _L( "StifHWResetStub.dll" ) );
       
   797     iDeviceResetDllName = dllName.AllocL();
       
   798 
       
   799     iDefaultTimeout = 0;
       
   800     iUITestingSupport = EFalse;
       
   801     iSeparateProcesses = EFalse;
       
   802     
       
   803     iIndexTestModuleControllers = 1;
       
   804     }
       
   805 
       
   806 /*
       
   807 -------------------------------------------------------------------------------
       
   808 
       
   809     Class: CTestEngine
       
   810 
       
   811     Method: NewL
       
   812 
       
   813     Description: Two-phased constructor.
       
   814 
       
   815     Parameters: RThread& aClient : Client's thread
       
   816                 CTestEngineServer* aServer : Pointer to CTestEngineServer
       
   817 
       
   818     Return Values: CTestEngine* : pointer to CTestEngine object
       
   819 
       
   820     Errors/Exceptions: None
       
   821 
       
   822     Status: Approved
       
   823 
       
   824 -------------------------------------------------------------------------------
       
   825 */
       
   826 CTestEngine* CTestEngine::NewL( CTestEngineServer* aServer )
       
   827     {
       
   828     CTestEngine* self = new ( ELeave ) CTestEngine();
       
   829     CleanupStack::PushL( self );
       
   830     self->ConstructL( aServer );
       
   831     CleanupStack::Pop();
       
   832     return self;
       
   833 
       
   834     }
       
   835 
       
   836 /*
       
   837 -------------------------------------------------------------------------------
       
   838 
       
   839     Class: CTestEngine
       
   840 
       
   841     Method: CloseSession
       
   842 
       
   843     Description: Close client server session to Test Engine
       
   844 
       
   845     Parameters: None
       
   846 
       
   847     Return Values: None
       
   848 
       
   849     Errors/Exceptions: None
       
   850 
       
   851     Status: Approved
       
   852 
       
   853 -------------------------------------------------------------------------------
       
   854 */
       
   855 void CTestEngine::CloseSession() 
       
   856     {
       
   857     __TRACE( KInit, ( _L( "CTestEngine::CloseSession" ) ) );
       
   858 
       
   859     iErrorQueue.Close();
       
   860 
       
   861     // Delete test report
       
   862     delete iTestReport;
       
   863     iTestReport = NULL;
       
   864 
       
   865     // Delete device reset module's DLL name
       
   866     delete iDeviceResetDllName;
       
   867     iDeviceResetDllName = NULL;
       
   868 
       
   869     // Delete state events
       
   870     iStateEvents.ResetAndDestroy();
       
   871     iStateEvents.Close();
       
   872 
       
   873     //Delete Client events
       
   874     iClientEvents.ResetAndDestroy();
       
   875     iClientEvents.Close();
       
   876 
       
   877     // Remove contents of iTestCases
       
   878     if ( iTestCases )
       
   879         {
       
   880         TInt handle;
       
   881         CObject* object = NULL;
       
   882         TInt count = iTestCases->Count();
       
   883 
       
   884         for ( TInt i = 0; i < count; i++ )
       
   885             {
       
   886             object = iTestCases->operator[](i);
       
   887             if ( object )
       
   888                 {
       
   889                 handle = iTestCases->At( object );
       
   890                 iTestCases->Remove( handle );       
       
   891                 }
       
   892             }
       
   893 
       
   894         delete iTestCases;
       
   895         iTestCases = NULL;
       
   896         }
       
   897     
       
   898     iTestCaseArray.Close();    
       
   899     delete iTestEngineSubSessions;
       
   900     iTestEngineSubSessions = NULL;
       
   901 
       
   902     // Delete the object container
       
   903     // This provides unique ids for the objects of this session
       
   904     iTestEngineServer->DeleteContainer( iContainer );
       
   905 
       
   906     // Inform server that session is closed
       
   907     iTestEngineServer->SessionClosed();
       
   908 
       
   909     delete iIniFile;
       
   910     iIniFile = NULL;
       
   911 
       
   912     delete iRebootPath;
       
   913     iRebootPath = NULL;
       
   914 
       
   915     delete iRebootFilename;
       
   916     iRebootFilename = NULL;
       
   917 
       
   918     delete iRebootParams;
       
   919     iRebootParams = 0;
       
   920 
       
   921     __TRACE(KVerbose, ( _L( "CTestEngine::CloseSession finished" ) ) );
       
   922 
       
   923     }
       
   924 
       
   925 /*
       
   926 -------------------------------------------------------------------------------
       
   927 
       
   928     Class: CTestEngine
       
   929 
       
   930     Method: CountResources
       
   931 
       
   932     Description: Resource counding
       
   933 
       
   934     Parameters: None
       
   935 
       
   936     Return Values: TInt Resource count
       
   937 
       
   938     Errors/Exceptions: None
       
   939 
       
   940     Status: Approved
       
   941 
       
   942 -------------------------------------------------------------------------------
       
   943 */
       
   944 TInt CTestEngine::CountResources()
       
   945     {
       
   946     return iResourceCount;
       
   947 
       
   948     }
       
   949 
       
   950 /*
       
   951 -------------------------------------------------------------------------------
       
   952 
       
   953     Class: CTestEngine
       
   954 
       
   955     Method: NumResources
       
   956 
       
   957     Description: Get resources, writes to Message()
       
   958 
       
   959     Parameters: None
       
   960 
       
   961     Return Values: None
       
   962 
       
   963     Errors/Exceptions: None
       
   964 
       
   965     Status: Approved
       
   966 
       
   967 -------------------------------------------------------------------------------
       
   968 */
       
   969 void CTestEngine::NumResources( const RMessage2& aMessage )
       
   970     {
       
   971 
       
   972     TInt ret( 0 );
       
   973 
       
   974     TPckgBuf<TInt> countPckg( iResourceCount );
       
   975 
       
   976     TRAP( ret, aMessage.WriteL( 0, countPckg ) );
       
   977 
       
   978     if ( ret != KErrNone )
       
   979         {
       
   980         PanicClient( EBadDescriptor, aMessage );
       
   981         }
       
   982 
       
   983 
       
   984     }
       
   985 
       
   986 /*
       
   987 -------------------------------------------------------------------------------
       
   988 
       
   989     Class: CTestEngine
       
   990 
       
   991     Method: PanicClient
       
   992 
       
   993     Description: Panic the client
       
   994 
       
   995     Parameters: TTestEnginePanic aPanic: in: Panic number
       
   996 
       
   997     Return Values: None
       
   998 
       
   999     Errors/Exceptions: None
       
  1000 
       
  1001     Status: Approved
       
  1002 
       
  1003 -------------------------------------------------------------------------------
       
  1004 */
       
  1005 void CTestEngine::PanicClient( TTestEnginePanic aPanic,
       
  1006                                 const RMessage2& aMessage ) const
       
  1007     {
       
  1008     iTestEngineServer->Logger()->Log( CStifLogger::ERed, _L( "CTestEngine::PanicClient [%d]" ), aPanic );
       
  1009 
       
  1010     _LIT( KTestEngine, "CTestEngine" );
       
  1011 
       
  1012     aMessage.Panic( KTestEngine, aPanic );
       
  1013 
       
  1014     }
       
  1015 
       
  1016 /*
       
  1017 -------------------------------------------------------------------------------
       
  1018 
       
  1019     Class: CTestEngine
       
  1020 
       
  1021     Method: ServiceL
       
  1022 
       
  1023     Description: Message handling method that calls trapped DispatchMessageL
       
  1024 
       
  1025     Parameters: const RMessage& aMessage: in: Server message
       
  1026 
       
  1027     Return Values: None
       
  1028 
       
  1029     Errors/Exceptions: Error from DispatchMessageL is trapped and handled
       
  1030 
       
  1031     Status: Approved
       
  1032 
       
  1033 -------------------------------------------------------------------------------
       
  1034 */
       
  1035 void CTestEngine::ServiceL( const RMessage2& aMessage )
       
  1036     {
       
  1037     TRAPD( ret, DispatchMessageL( aMessage ) );
       
  1038     if ( ret != KErrNone )
       
  1039         {
       
  1040          __TRACE(KError, ( CStifLogger::ERed, _L( "CTestEngine::DispatchMessageL Function=[%d], left with [%d]" ),
       
  1041                                                 aMessage.Function(), ret ) );
       
  1042         if( ret == KErrNoMemory )
       
  1043             {
       
  1044             __TRACE( KError, ( CStifLogger::ERed, _L( "No memory available. Some possibility to do: 1. Reduce test case count. 2. Increase StifTestEngine's heap size." ) ) );
       
  1045             }
       
  1046         aMessage.Complete( ret );
       
  1047         }
       
  1048 
       
  1049     }
       
  1050 
       
  1051 /*
       
  1052 -------------------------------------------------------------------------------
       
  1053 
       
  1054     Class: CTestEngine
       
  1055 
       
  1056     Method: DispatchMessageL
       
  1057 
       
  1058     Description: Actual message handling
       
  1059 
       
  1060     Parameters: const RMessage& aMessage: in: Server message
       
  1061 
       
  1062     Return Values: None
       
  1063 
       
  1064     Errors/Exceptions: Leaves if some of called leaving methods leaves
       
  1065 
       
  1066     Status: Approved
       
  1067 
       
  1068 -------------------------------------------------------------------------------
       
  1069 */
       
  1070 void CTestEngine::DispatchMessageL( const RMessage2& aMessage )
       
  1071     {
       
  1072     iComplete = ETrue;
       
  1073     iReturn = KErrNone;
       
  1074 
       
  1075     switch ( aMessage.Function() )
       
  1076         {
       
  1077         case ETestEngineServerCloseSession:
       
  1078             {
       
  1079             if ( !iIsTestReportGenerated  && iTestReport )
       
  1080                 {
       
  1081                 iTestReport->GenerateReportL();
       
  1082                 iIsTestReportGenerated = ETrue;
       
  1083                 }               
       
  1084             CloseSession();
       
  1085             break;
       
  1086             }
       
  1087         case ETestEngineCreateSubSession:
       
  1088             {
       
  1089             InitEngineL( aMessage );
       
  1090             break;
       
  1091             }
       
  1092         case ETestEngineCloseSubSession:
       
  1093             {
       
  1094             CloseTestEngineL( aMessage.Int3() );
       
  1095             break;
       
  1096             }
       
  1097         case ETestEngineSetAttribute:
       
  1098             {
       
  1099             SetAttributeL( aMessage );
       
  1100             break;
       
  1101             }
       
  1102 
       
  1103         case ETestEngineAddTestModule:
       
  1104             {
       
  1105             AddTestModuleL( aMessage );
       
  1106             break;
       
  1107             }
       
  1108         case ETestEngineRemoveTestModule:
       
  1109             {
       
  1110             iReturn = RemoveTestModuleL( aMessage );
       
  1111             break;
       
  1112             }
       
  1113         case ETestEngineAddConfigFile:
       
  1114             {
       
  1115             AddConfigFileL( aMessage );
       
  1116             break;
       
  1117             }
       
  1118         case ETestEngineRemoveConfigFile:
       
  1119             {
       
  1120             RemoveConfigFileL( aMessage );
       
  1121             break;
       
  1122             }
       
  1123         case ETestEngineEnumerateTestCases:
       
  1124             {
       
  1125             EnumerateTestCasesL( aMessage );
       
  1126             break;
       
  1127             }
       
  1128         case ETestEngineGetTestCases:
       
  1129             {
       
  1130             GetTestCasesL( aMessage );
       
  1131             break;
       
  1132             }
       
  1133         case ETestEngineCancelAsyncRequest:
       
  1134             {
       
  1135             CancelAsyncRequest( aMessage );
       
  1136             break;
       
  1137             }
       
  1138         case ETestEngineEvent:
       
  1139             {
       
  1140             EventControlL( aMessage );
       
  1141             iComplete = EFalse;
       
  1142             break;
       
  1143             }
       
  1144         case ETestEngineErrorNotification:
       
  1145             {
       
  1146             HandleErrorNotificationL( aMessage );
       
  1147             iComplete = EFalse;
       
  1148             break;
       
  1149             }
       
  1150         case ETestEngineLoggerSettings:
       
  1151             {
       
  1152             LoggerSettings( aMessage );
       
  1153             break;
       
  1154             }
       
  1155         case ETestEngineCloseLoggerSettings:
       
  1156             {
       
  1157             CloseLoggerSettings();
       
  1158             break;
       
  1159             }
       
  1160         case ETestEngineReportTestCase:
       
  1161             {
       
  1162             iReturn = AddTestCaseToTestReport(aMessage);
       
  1163             break;
       
  1164             }
       
  1165         // Subsession specific functions
       
  1166         case ETestCaseCreateSubSession:
       
  1167             {
       
  1168             NewTestCaseL( aMessage );
       
  1169             break;
       
  1170             }
       
  1171         case ETestCaseCloseSubSession:
       
  1172             {
       
  1173             DeleteTestCase( aMessage.Int3() );
       
  1174             break;
       
  1175             }
       
  1176         case ETestCaseRunTestCase:
       
  1177             {
       
  1178             TestCaseByHandle( aMessage.Int3(), aMessage )->RunTestCaseL( aMessage );
       
  1179             iComplete = EFalse;
       
  1180             break;
       
  1181             }
       
  1182         case ETestCasePause:
       
  1183             {
       
  1184             iReturn = TestCaseByHandle( aMessage.Int3(), aMessage )->Pause();
       
  1185             break;
       
  1186             }
       
  1187         case ETestCaseResume:
       
  1188             {
       
  1189             iReturn = TestCaseByHandle( aMessage.Int3(), aMessage )->Resume();
       
  1190             break;
       
  1191             }
       
  1192         case ETestCaseNotifyProgress:
       
  1193             {
       
  1194             TestCaseByHandle( aMessage.Int3(), aMessage )->NotifyProgressL( aMessage );
       
  1195             iComplete = EFalse;
       
  1196             break;
       
  1197             }
       
  1198         case ETestCaseNotifyRemoteType:
       
  1199             {
       
  1200             TestCaseByHandle( aMessage.Int3(), aMessage )->NotifyRemoteTypeL( aMessage );
       
  1201             iComplete = EFalse;
       
  1202             break;
       
  1203             }
       
  1204         case ETestCaseNotifyRemoteMsg:
       
  1205             {
       
  1206             TestCaseByHandle( aMessage.Int3(), aMessage )->NotifyRemoteMsgL( aMessage );
       
  1207             iComplete = EFalse;
       
  1208             break;
       
  1209             }
       
  1210         case ETestCaseCancelAsyncRequest:
       
  1211             {
       
  1212             TestCaseByHandle( 
       
  1213                 aMessage.Int3(), aMessage )->CancelAsyncRequest( aMessage );
       
  1214             break;
       
  1215             }
       
  1216         default:
       
  1217             {
       
  1218             User::Leave( KErrNotSupported );
       
  1219             break;
       
  1220             }
       
  1221         }
       
  1222     
       
  1223     if ( iComplete )
       
  1224         {
       
  1225         aMessage.Complete( iReturn );
       
  1226         }
       
  1227 
       
  1228     }
       
  1229 
       
  1230 /*
       
  1231 -------------------------------------------------------------------------------
       
  1232 
       
  1233     Class: CTestEngine
       
  1234 
       
  1235     Method: InitTestReportAndLoggerVarL
       
  1236 
       
  1237     Description: Initialize Test report and Logger's overwrite parameters
       
  1238 
       
  1239     Parameters: None
       
  1240 
       
  1241     Return Values: None
       
  1242 
       
  1243     Errors/Exceptions: Leaves if memory allocation fails
       
  1244 
       
  1245     Status: Approved
       
  1246 
       
  1247 -------------------------------------------------------------------------------
       
  1248 */
       
  1249 void CTestEngine::InitTestReportAndLoggerVarL()
       
  1250     {
       
  1251     // Test report settings initialization
       
  1252     iTestEngineServer->iTestReportSettings->iCreateTestReport = ETrue;
       
  1253     _LIT( path, "C:\\LOGS\\TestFramework\\");
       
  1254     _LIT( name, "TestReport");
       
  1255     delete iTestEngineServer->iTestReportSettings->iPath;
       
  1256     iTestEngineServer->iTestReportSettings->iPath = NULL;
       
  1257     iTestEngineServer->iTestReportSettings->iPath = path().AllocL();
       
  1258     delete iTestEngineServer->iTestReportSettings->iName;
       
  1259     iTestEngineServer->iTestReportSettings->iName = NULL;
       
  1260     iTestEngineServer->iTestReportSettings->iName = name().AllocL();
       
  1261     iTestEngineServer->iTestReportSettings->iFormat = CStifLogger::ETxt;
       
  1262     iTestEngineServer->iTestReportSettings->iOutput = CStifLogger::EFile;
       
  1263     iTestEngineServer->iTestReportSettings->iOverwrite = ETrue;
       
  1264 
       
  1265     // Initializations to indicator is setting in use
       
  1266     iTestEngineServer->iLoggerSettings.iIsDefined.iCreateLogDir = EFalse;
       
  1267     iTestEngineServer->iLoggerSettings.iIsDefined.iPath = EFalse;
       
  1268     iTestEngineServer->iLoggerSettings.iIsDefined.iHwPath = EFalse;
       
  1269     iTestEngineServer->iLoggerSettings.iIsDefined.iFormat = EFalse;
       
  1270     iTestEngineServer->iLoggerSettings.iIsDefined.iHwFormat = EFalse;
       
  1271     iTestEngineServer->iLoggerSettings.iIsDefined.iOutput = EFalse;
       
  1272     iTestEngineServer->iLoggerSettings.iIsDefined.iHwOutput = EFalse;
       
  1273     iTestEngineServer->iLoggerSettings.iIsDefined.iOverwrite = EFalse;
       
  1274     iTestEngineServer->iLoggerSettings.iIsDefined.iLineBreak = EFalse;
       
  1275     iTestEngineServer->iLoggerSettings.iIsDefined.iTimeStamp = EFalse;
       
  1276     iTestEngineServer->iLoggerSettings.iIsDefined.iEventRanking = EFalse;
       
  1277     iTestEngineServer->iLoggerSettings.iIsDefined.iThreadId = EFalse;
       
  1278 
       
  1279     }
       
  1280 
       
  1281 /*
       
  1282 -------------------------------------------------------------------------------
       
  1283 
       
  1284     Class: CTestEngine
       
  1285 
       
  1286     Method: InitEngineL
       
  1287 
       
  1288     Description: Init the test engine
       
  1289 
       
  1290     Parameters: const RMessage& aMessage: in: Server message
       
  1291 
       
  1292     Return Values: None
       
  1293 
       
  1294     Errors/Exceptions: Leaves if some of called leaving methods leaves
       
  1295 
       
  1296     Status: Approved
       
  1297 
       
  1298 -------------------------------------------------------------------------------
       
  1299 */
       
  1300 void CTestEngine::InitEngineL( const RMessage2& aMessage )
       
  1301     {
       
  1302   
       
  1303     // Parse reboot file 
       
  1304     ParseRebootParamsL();
       
  1305 
       
  1306     TName iniFileName;
       
  1307 
       
  1308     // Read ini file name from aMessage
       
  1309     aMessage.ReadL( 0, iniFileName );
       
  1310     TStifUtil::CorrectFilePathL( iniFileName );
       
  1311 
       
  1312     iIniFile = iniFileName.AllocL();
       
  1313 
       
  1314     // HBufC to TPtrC
       
  1315     TPtrC iniFile( iIniFile->Des() );
       
  1316 
       
  1317     __TRACE( KInit, ( CStifLogger::EBold, _L( "CTestEngine::InitEngineL\t iIniFile=[%S]" ), iIniFile ) );
       
  1318 
       
  1319     // Connect to the Setting server and open handle(Handle will close when
       
  1320     // closing TestEngine).
       
  1321     TInt ret = iSettingServer.Connect();
       
  1322     if ( ret != KErrNone )
       
  1323         {
       
  1324         User::Leave( ret );
       
  1325         }
       
  1326 
       
  1327     InitTestReportAndLoggerVarL();
       
  1328 
       
  1329     if ( iniFile.Length() > 0 )
       
  1330         {
       
  1331         Logger()->WriteDelimiter();
       
  1332         __TRACE( KInit,( _L( "Starting to parse initialization file" ) ) );
       
  1333 
       
  1334         // Set initialization file information to Setting server's side.
       
  1335         ret = iSettingServer.SetIniFileInformation( iniFileName );
       
  1336         if ( ret != KErrNone )
       
  1337             {
       
  1338             User::Leave( ret );
       
  1339             }
       
  1340         // Struct to Logger settigs.
       
  1341         TLoggerSettings loggerSettings; 
       
  1342         // Parse Logger defaults from STIF initialization file.
       
  1343         ret = iSettingServer.ReadLoggerSettingsFromIniFile( loggerSettings );
       
  1344         if ( ret != KErrNone )
       
  1345             {
       
  1346             User::Leave( ret );
       
  1347             }
       
  1348 
       
  1349         // Create parser for parsing ini file
       
  1350         CStifParser* parser = NULL;
       
  1351         TRAPD( r, parser = CStifParser::NewL( _L(""), iniFile ) );
       
  1352         if ( r != KErrNone )
       
  1353             {
       
  1354             __TRACE( KError,( CStifLogger::ERed, _L( "Can't open ini-file [%S], code %d" ), &iniFile, r ) );
       
  1355             LeaveWithNotifyL(r);
       
  1356             }
       
  1357 
       
  1358         CleanupStack::PushL( parser );
       
  1359 
       
  1360         CSTIFTestFrameworkSettings* settings = NULL;
       
  1361         TRAPD( settings_ret, settings = CSTIFTestFrameworkSettings::NewL() );
       
  1362         CleanupStack::PushL( settings );
       
  1363         if ( settings_ret != KErrNone )
       
  1364             {
       
  1365             __TRACE( KError,( CStifLogger::ERed, _L( "CSTIFTestFrameworkSettings class object creation fails") ) );
       
  1366             LeaveWithNotifyL( settings_ret );
       
  1367             }
       
  1368 
       
  1369         ReadEngineDefaultsL( parser, settings );
       
  1370 
       
  1371         SetLoggerSettings( loggerSettings ) ;
       
  1372 
       
  1373         TRAP(r, ReadTestModulesL( parser ));
       
  1374         if(r != KErrNone)
       
  1375             {
       
  1376             __TRACE(KError, (CStifLogger::ERed, _L("Reading test modules finished with error [%d]"), r));
       
  1377             User::Leave(r);
       
  1378             }
       
  1379 
       
  1380         CleanupStack::PopAndDestroy( settings );
       
  1381         CleanupStack::PopAndDestroy( parser );
       
  1382         __TRACE( KInit, ( _L( "Configuration file reading finished" ) ) );
       
  1383         }
       
  1384     else
       
  1385         {
       
  1386         __TRACE( KInit,( CStifLogger::EBold, _L( "Initialisation file not specified." ) ) );
       
  1387         }
       
  1388 
       
  1389     Logger()->WriteDelimiter();
       
  1390     
       
  1391     // Create Test Reporter if allowed
       
  1392     if ( iTestEngineServer->iTestReportSettings->iCreateTestReport )
       
  1393         {
       
  1394         TRAPD(err, iTestReport = 
       
  1395             CTestReport::NewL( *(iTestEngineServer->iTestReportSettings), 
       
  1396                                ( CTestReport::TTestReportMode ) iReportMode ));
       
  1397         if(err!=KErrNone)
       
  1398             {
       
  1399             iTestReport = NULL;
       
  1400             __TRACE( KInit,( CStifLogger::ERed, _L( "Test report creation failed with error: %d, test report not created." ), err ) );
       
  1401             __TRACE( KInit,( CStifLogger::ERed, _L( "Check your testreport settings from testframework.ini file (e.g. TestReportFilePath)." ) ) );
       
  1402             }
       
  1403         }
       
  1404     
       
  1405     // Create test engine subsession object
       
  1406     CTestEngineSubSession* testEngineSubSession =
       
  1407     CTestEngineSubSession::NewL( this );
       
  1408     CleanupStack::PushL( testEngineSubSession );
       
  1409 
       
  1410     // Add object to object container to generate unique id
       
  1411     iContainer->AddL( testEngineSubSession );
       
  1412 
       
  1413     // Add object to object index
       
  1414     // This returns a unique handle so we can get it again
       
  1415     TInt handle = iTestEngineSubSessions->AddL( testEngineSubSession );
       
  1416 
       
  1417     // Write the handle to client
       
  1418     TPckg<TInt> handlePckg( handle );
       
  1419 
       
  1420     TRAPD( res, aMessage.WriteL( 3, handlePckg ) );
       
  1421     if ( res != KErrNone )
       
  1422         {
       
  1423         iTestEngineSubSessions->Remove( handle );
       
  1424         PanicClient( EBadDescriptor, aMessage );
       
  1425         return;
       
  1426         }
       
  1427 
       
  1428     CleanupStack::Pop( testEngineSubSession );
       
  1429 
       
  1430     // Notch up another resource
       
  1431     iResourceCount++;
       
  1432     }
       
  1433 
       
  1434 /*
       
  1435 -------------------------------------------------------------------------------
       
  1436 
       
  1437     Class: CTestEngine
       
  1438 
       
  1439     Method: ReadEngineDefaults
       
  1440 
       
  1441     Description: Parse Test Engine defaults from STIF 
       
  1442                  initialization file.
       
  1443 
       
  1444     Parameters: CStifParser& parser: in: CStifParser object
       
  1445                 CSTIFTestFrameworkSettings* aSettings: in:
       
  1446                 CSTIFTestFrameworkSettings object
       
  1447 
       
  1448     Return Values: None
       
  1449 
       
  1450     Errors/Exceptions: Leaves if some of called leaving methods leaves
       
  1451 
       
  1452     Status: Approved
       
  1453 
       
  1454 -------------------------------------------------------------------------------
       
  1455 */
       
  1456 void CTestEngine::ReadEngineDefaultsL( CStifParser* aParser,
       
  1457                                         CSTIFTestFrameworkSettings* aSettings )
       
  1458     {
       
  1459     __TRACE( KInit,( _L( "" ) ) );
       
  1460     __TRACE( KInit,( _L( "Start parsing engine defaults" ) ) );
       
  1461     TInt get_ret( KErrNone );
       
  1462 
       
  1463     CStifSectionParser* sectionParser = NULL;
       
  1464 
       
  1465     // Parse Engine's default values
       
  1466     _LIT( KDefaultsStart, "[Engine_Defaults]" );
       
  1467     _LIT( KDefaultsEnd, "[End_Defaults]" );
       
  1468     __TRACE( KInit,( _L( "Starting to search sections" ) ) );
       
  1469     sectionParser = aParser->SectionL( KDefaultsStart, KDefaultsEnd );
       
  1470     CleanupStack::PushL( sectionParser );
       
  1471     if ( sectionParser )
       
  1472         {
       
  1473         __TRACE( KInit,( _L( "Found '%S' and '%S' sections" ), &KDefaultsStart, &KDefaultsEnd ) );
       
  1474 
       
  1475         // Get Test Report Mode
       
  1476         __TRACE( KInit,( _L( "Parsing Test report mode" ) ) );
       
  1477         TUint reportMode( 0 );
       
  1478         get_ret = aSettings->GetReportModeL( sectionParser,
       
  1479                                         _L( "TestReportMode=" ), reportMode );
       
  1480         if ( get_ret == KErrNone )
       
  1481             {
       
  1482             __TRACE( KInit,( _L( "Report mode: %d"), reportMode ) );
       
  1483             iReportMode = reportMode;
       
  1484             }
       
  1485         else
       
  1486             {
       
  1487             __TRACE( KInit,( _L( "Report mode not found or not given" ) ) );
       
  1488             }
       
  1489 
       
  1490         // Indicator to test report creation
       
  1491         __TRACE( KInit,( _L( "Parsing Test report creation indicator" ) ) );
       
  1492         TBool createTestReport( 0 );
       
  1493         get_ret = aSettings->GetBooleanSettingsL( sectionParser,
       
  1494                                 _L( "CreateTestReport=" ), createTestReport );
       
  1495         if ( get_ret == KErrNone )
       
  1496             {
       
  1497             __TRACE( KInit,( _L( "Test report creation indicator: %d"), createTestReport ) );
       
  1498             iTestEngineServer->iTestReportSettings->iCreateTestReport = createTestReport;
       
  1499             }
       
  1500         else
       
  1501             {
       
  1502             __TRACE( KInit,( _L( "Creation indicator not found or not given" ) ) );
       
  1503             }
       
  1504 
       
  1505         // Get Test report path settings
       
  1506         if ( iTestEngineServer->iTestReportSettings->iCreateTestReport )
       
  1507             {
       
  1508             __TRACE( KInit,( _L( "Parsing Test report path" ) ) );
       
  1509             TPtrC path;
       
  1510             get_ret = aSettings->GetFileSetting( sectionParser,
       
  1511                                         _L( "TestReportFilePath=" ), path );
       
  1512             if ( get_ret == KErrNone )
       
  1513                 {
       
  1514                 __TRACE( KInit,( _L( "Test report path: %S"), &path ) );
       
  1515                 // Delete old one before setting new one
       
  1516                 delete iTestEngineServer->iTestReportSettings->iPath;
       
  1517 				iTestEngineServer->iTestReportSettings->iPath = NULL;
       
  1518                 iTestEngineServer->iTestReportSettings->iPath = path.AllocL();
       
  1519                 }
       
  1520             else
       
  1521                 {
       
  1522                 __TRACE( KInit,( _L( "Path not found or not given" ) ) );
       
  1523                 }
       
  1524             }
       
  1525 
       
  1526         // Get Test report name settings
       
  1527         if ( iTestEngineServer->iTestReportSettings->iCreateTestReport )
       
  1528             {
       
  1529             __TRACE( KInit,( _L( "Parsing Test report filename" ) ) );
       
  1530             TPtrC name;
       
  1531             get_ret = aSettings->GetFileSetting( sectionParser,
       
  1532                                         _L( "TestReportFileName=" ), name );
       
  1533             if ( get_ret == KErrNone )
       
  1534                 {
       
  1535                 __TRACE( KInit,( _L( "Test report filename: %S"), &name ) );
       
  1536                 // Delete old one before setting new one
       
  1537                 delete iTestEngineServer->iTestReportSettings->iName;
       
  1538 				iTestEngineServer->iTestReportSettings->iName = NULL;
       
  1539                 iTestEngineServer->iTestReportSettings->iName = name.AllocL();
       
  1540                 }
       
  1541             else
       
  1542                 {
       
  1543                 __TRACE( KInit,( _L( "Filename not found or not given" ) ) );
       
  1544                 }
       
  1545             }
       
  1546 
       
  1547         // Get Test report format settings
       
  1548         if ( iTestEngineServer->iTestReportSettings->iCreateTestReport )
       
  1549             {
       
  1550             __TRACE( KInit,( _L( "Parsing Test report format" ) ) );
       
  1551             CStifLogger::TLoggerType type;
       
  1552             TBool xml;
       
  1553             get_ret = aSettings->GetFormatL( sectionParser,
       
  1554                                             _L( "TestReportFormat=" ), type, xml );
       
  1555             if ( get_ret == KErrNone )
       
  1556                 {
       
  1557                 __TRACE( KInit,( _L( "Test report format: %d, xml: %d"), type, xml ) );
       
  1558                 iTestEngineServer->iTestReportSettings->iFormat = type;
       
  1559                 iTestEngineServer->iTestReportSettings->iXML = xml;
       
  1560                 }
       
  1561             else
       
  1562                 {
       
  1563                 __TRACE( KInit,( _L( "Format not found or not given" ) ) );
       
  1564                 }
       
  1565             }
       
  1566 
       
  1567         // Get Test report output settings
       
  1568         if ( iTestEngineServer->iTestReportSettings->iCreateTestReport )
       
  1569             {
       
  1570             __TRACE( KInit,( _L( "Parsing Test report output" ) ) );
       
  1571             CStifLogger::TOutput output;
       
  1572             get_ret = aSettings->GetOutputL( sectionParser,
       
  1573                                         _L( "TestReportOutput=" ), output );
       
  1574             if ( get_ret == KErrNone )
       
  1575                 {
       
  1576                 __TRACE( KInit,( _L( "Test report output: %d"), output ) );
       
  1577                 iTestEngineServer->iTestReportSettings->iOutput = output;
       
  1578                 }
       
  1579             else
       
  1580                 {
       
  1581                 __TRACE( KInit,( _L( "Output not found or not given" ) ) );
       
  1582                 }
       
  1583             }
       
  1584 
       
  1585         // Get Test report file creation mode (overwrite settings)
       
  1586         if ( iTestEngineServer->iTestReportSettings->iCreateTestReport )
       
  1587             {
       
  1588             __TRACE( KInit,( _L( "Parsing Test report file writing mode" ) ) );
       
  1589             TBool overwrite;
       
  1590             get_ret = aSettings->GetOverwriteL( sectionParser,
       
  1591                             _L( "TestReportFileCreationMode=" ), overwrite );
       
  1592             if ( get_ret == KErrNone )
       
  1593                 {
       
  1594                 __TRACE( KInit,( _L( "Test report file creation mode: %d"), overwrite ) );
       
  1595                 iTestEngineServer->iTestReportSettings->iOverwrite = overwrite;
       
  1596                 }
       
  1597             else
       
  1598                 {
       
  1599                 __TRACE( KInit,( _L( "Writing mode not found or not given" ) ) );
       
  1600                 }
       
  1601             }
       
  1602         // Get device reset module's DLL name
       
  1603         __TRACE( KInit,( _L( "Parsing device reset module's DLL name" ) ) );
       
  1604         TPtrC deviceResetName;
       
  1605         get_ret = aSettings->GetFileSetting( sectionParser,
       
  1606                                         _L( "DeviceResetDllName=" ), deviceResetName );
       
  1607         if ( get_ret == KErrNone )
       
  1608             {
       
  1609             __TRACE( KInit,( _L( "Device reset module's name: %S"), &deviceResetName ) );
       
  1610             // Delete old one before setting new one
       
  1611             delete iDeviceResetDllName;
       
  1612 			iDeviceResetDllName = NULL;
       
  1613             iDeviceResetDllName = deviceResetName.AllocL();
       
  1614             }
       
  1615         else
       
  1616             {
       
  1617             __TRACE( KInit,( _L( "Device reset module's name not found or not given" ) ) );
       
  1618             }
       
  1619 
       
  1620         // Get measurement disable option
       
  1621         CStifItemParser* item = NULL;
       
  1622         TRAPD( ret, item = sectionParser->GetItemLineL( _L( "DisableMeasurement=" ), ENoTag ) );
       
  1623         if( ( ret != KErrNone ) || ( item == NULL ) )
       
  1624             {
       
  1625              __TRACE( KInit,( _L( "Measurement 'DiableMeasurement=' not found or not given" ) ) );
       
  1626 			delete item; 
       
  1627             item = NULL;
       
  1628             }
       
  1629         else
       
  1630             {
       
  1631 			CleanupStack::PushL( item );			
       
  1632             TPtrC string;
       
  1633             ret = item->GetString( KNullDesC(), string );
       
  1634             while( ret == KErrNone )
       
  1635                 {
       
  1636                 HBufC* stringHbuf = string.AllocL();
       
  1637                 TPtr modifiableString = stringHbuf->Des();
       
  1638                 modifiableString.LowerCase();
       
  1639 
       
  1640                 if( modifiableString == KStifMeasurementDisableNone ||
       
  1641                     modifiableString == KStifMeasurementDisableAll ||
       
  1642                     modifiableString == KStifMeasurement01 ||
       
  1643                     modifiableString == KStifMeasurement02 ||
       
  1644                     modifiableString == KStifMeasurement03 ||
       
  1645                     modifiableString == KStifMeasurement04 ||
       
  1646                     modifiableString == KStifMeasurement05 ||
       
  1647                     modifiableString == KStifMeasurementBappea )
       
  1648                     {
       
  1649                     __TRACE( KInit,( _L( "Measurement disable option: %S"), &modifiableString ) );
       
  1650                     DisableStifMeasurement( modifiableString );
       
  1651                     }
       
  1652                 else if( modifiableString == _L( "#" ) )
       
  1653                     {
       
  1654 					delete stringHbuf;
       
  1655 					stringHbuf = NULL;
       
  1656                     break;
       
  1657                     }
       
  1658                 else
       
  1659                     {
       
  1660                     __TRACE( KInit,( _L( "Measurement disable option not found or not given" ) ) );
       
  1661                     delete stringHbuf;                    
       
  1662 					stringHbuf = NULL;
       
  1663                     break;
       
  1664                     }
       
  1665                 delete stringHbuf;
       
  1666                 ret = item->GetNextString( string );
       
  1667                 }
       
  1668 			CleanupStack::PopAndDestroy( item );
       
  1669 			item = NULL;
       
  1670             }
       
  1671 
       
  1672         // Get timeout value option
       
  1673         __TRACE(KInit, (_L("Parsing default timeout value")));
       
  1674         iDefaultTimeout = 0;
       
  1675         item = NULL;
       
  1676         TRAP(ret, item = sectionParser->GetItemLineL(_L("Timeout=" ), ENoTag));
       
  1677         if( ( ret != KErrNone ) || ( item == NULL ) )
       
  1678             {
       
  1679             __TRACE(KInit, (_L("'Timeout' option not found or not given")));
       
  1680             delete item;
       
  1681             item = NULL;
       
  1682             }
       
  1683         else
       
  1684             {
       
  1685             CleanupStack::PushL( item );
       
  1686             TPtrC string;
       
  1687             ret = item->GetString(KNullDesC(), string);
       
  1688             if(string.Length() > 0)
       
  1689                 {
       
  1690                 TLex lex(string);
       
  1691                 ret = lex.Val(iDefaultTimeout);
       
  1692                 if(ret != KErrNone)
       
  1693                     {
       
  1694                     __TRACE(KError, (_L("Could not convert timeout value '%S' to integer. Error %d. Ignoring this setting."), &string, ret));
       
  1695                     }
       
  1696                 if(iDefaultTimeout < 0)
       
  1697                     {
       
  1698                     __TRACE(KError, (_L("'Timeout' value cannot be negative. Resetting to 0.")));
       
  1699                     iDefaultTimeout = 0;
       
  1700                     }
       
  1701                 }
       
  1702             else
       
  1703                 {
       
  1704                 __TRACE(KInit, (_L("'Timeout' value not given")));
       
  1705                 }
       
  1706             CleanupStack::PopAndDestroy( item );
       
  1707             item = NULL;
       
  1708             }
       
  1709         __TRACE(KInit, (_L("'Timeout' value set to %d"), iDefaultTimeout));
       
  1710         iDefaultTimeout *= 1000;
       
  1711         
       
  1712         // Get UITestingSupport value option
       
  1713         __TRACE(KInit, (_L("Parsing UITestingSupport value")));
       
  1714         iUITestingSupport = EFalse;
       
  1715         item = NULL;
       
  1716         TRAP(ret, item = sectionParser->GetItemLineL(_L("UITestingSupport=" ), ENoTag));
       
  1717         if((ret != KErrNone) || (item == NULL))
       
  1718             {
       
  1719             __TRACE(KInit, (_L("'UITestingSupport' option not found")));
       
  1720             delete item;
       
  1721             item = NULL;
       
  1722             }
       
  1723         else
       
  1724             {
       
  1725             CleanupStack::PushL(item);
       
  1726             TPtrC string;
       
  1727             ret = item->GetString(KNullDesC(), string);
       
  1728             if(string.Length() > 0)
       
  1729                 {
       
  1730                 iUITestingSupport = (string == _L("YES"));
       
  1731                 }
       
  1732             else
       
  1733                 {
       
  1734                 __TRACE(KInit, (_L("'UITestingSupport' value not given")));
       
  1735                 }
       
  1736             CleanupStack::PopAndDestroy(item);
       
  1737             item = NULL;
       
  1738             }
       
  1739         __TRACE(KInit, (_L("'UITestingSupport' value set to %d"), iUITestingSupport));
       
  1740 
       
  1741         // Get SeparateProcesses value option
       
  1742         __TRACE(KInit, (_L("Parsing SeparateProcesses value")));
       
  1743         iSeparateProcesses = EFalse;
       
  1744         item = NULL;
       
  1745         TRAP(ret, item = sectionParser->GetItemLineL(_L("SeparateProcesses=" ), ENoTag));
       
  1746         if((ret != KErrNone) || (item == NULL))
       
  1747             {
       
  1748             __TRACE(KInit, (_L("'SeparateProcesses' option not found")));
       
  1749             delete item;
       
  1750             item = NULL;
       
  1751             }
       
  1752         else
       
  1753             {
       
  1754             CleanupStack::PushL(item);
       
  1755             TPtrC string;
       
  1756             ret = item->GetString(KNullDesC(), string);
       
  1757             if(string.Length() > 0)
       
  1758                 {
       
  1759                 iSeparateProcesses = (string == _L("YES"));
       
  1760                 }
       
  1761             else
       
  1762                 {
       
  1763                 __TRACE(KInit, (_L("'SeparateProcesses' value not given")));
       
  1764                 }
       
  1765             CleanupStack::PopAndDestroy(item);
       
  1766             item = NULL;
       
  1767             }
       
  1768         __TRACE(KInit, (_L("'SeparateProcesses' value set to %d"), iSeparateProcesses));
       
  1769         }
       
  1770     else
       
  1771         {
       
  1772         __TRACE( KInit,( _L( "Not found '%S' and '%S' sections" ), &KDefaultsStart, &KDefaultsEnd ) );
       
  1773         }
       
  1774     __TRACE( KInit,( _L( "End parsing engine defaults" ) ) );
       
  1775     CleanupStack::PopAndDestroy( sectionParser );
       
  1776     
       
  1777     // Store engine settings to SettingServer
       
  1778     RSettingServer settingServer;
       
  1779     TInt ret = settingServer.Connect();
       
  1780     if(ret != KErrNone)
       
  1781         {
       
  1782         __TRACE(KError, (_L("Could not connect to SettingServer [%d] and store engine settings"), ret));
       
  1783         }
       
  1784     else
       
  1785         {
       
  1786         TEngineSettings settings;
       
  1787         settings.iUITestingSupport = iUITestingSupport;
       
  1788         settings.iSeparateProcesses = iSeparateProcesses;
       
  1789         ret = settingServer.StoreEngineSettings(settings);
       
  1790         if(ret != KErrNone)
       
  1791             {
       
  1792             __TRACE(KError, (_L("Could not store engine settings to SettingServer [%d]"), ret));
       
  1793             }
       
  1794             else
       
  1795             {
       
  1796             __TRACE(KInit, (_L("Engine settings succesfully stored to SettingServer")));
       
  1797             }
       
  1798         settingServer.Close();
       
  1799         }
       
  1800     }
       
  1801 
       
  1802 /*
       
  1803 -------------------------------------------------------------------------------
       
  1804 
       
  1805     Class: CTestEngine
       
  1806 
       
  1807     Method: SetLoggerSettings
       
  1808 
       
  1809     Description: Set parsed logger's settings to TestEngine side.
       
  1810 
       
  1811     Parameters: TLoggerSettings& aLoggerSettings: in: Parsed logger settings
       
  1812 
       
  1813     Return Values: None
       
  1814 
       
  1815     Errors/Exceptions: None
       
  1816 
       
  1817     Status: Proposal
       
  1818 
       
  1819 -------------------------------------------------------------------------------
       
  1820 */
       
  1821 void CTestEngine::SetLoggerSettings( TLoggerSettings& aLoggerSettings )
       
  1822     {
       
  1823     iTestEngineServer->iLoggerSettings = aLoggerSettings;
       
  1824 
       
  1825     }
       
  1826 
       
  1827 /*
       
  1828 -------------------------------------------------------------------------------
       
  1829 
       
  1830     Class: CTestEngine
       
  1831 
       
  1832     Method: ParseTestModulesL
       
  1833 
       
  1834     Description: Parse and search for module info and fill list of modules.
       
  1835 
       
  1836     Parameters: CStifParser*     aParser:       in: CStifParser object
       
  1837                 CTestModuleList* aModuleList:   in: list of modules
       
  1838                 TPtrC&           aSectionStart: in: descriptor with start of section string
       
  1839                 TPTrC&           aSectionEnd:   in: descriptor with end of section string
       
  1840 
       
  1841     Return Values: None
       
  1842 
       
  1843     Errors/Exceptions: Leaves if some of called leaving methods leaves
       
  1844 
       
  1845     Status: Approved
       
  1846 
       
  1847 -------------------------------------------------------------------------------
       
  1848 */
       
  1849 void CTestEngine::ParseTestModulesL(CStifParser* aParser, CTestModuleList* aModuleList, const TDesC& aSectionStart, const TDesC& aSectionEnd)
       
  1850     {
       
  1851     //First let's find all modules given in Stif's ini file and store that info in CTestModuleList object
       
  1852     CStifSectionParser* sectionParser = NULL;
       
  1853     CStifItemParser* item = NULL;
       
  1854 
       
  1855     sectionParser = aParser->SectionL(aSectionStart, aSectionEnd);
       
  1856 
       
  1857     TBool sectionOK;
       
  1858 
       
  1859     while(sectionParser)
       
  1860         {
       
  1861         sectionOK = ETrue;
       
  1862         __TRACE(KInit, (_L("Found '%S' and '%S' sections"), &aSectionStart, &aSectionEnd));
       
  1863         CleanupStack::PushL(sectionParser);
       
  1864         __TRACE(KInit, (_L("Starting to read module information")));
       
  1865 
       
  1866         // Get name of module
       
  1867         _LIT(KModuleName, "ModuleName=");
       
  1868         item = sectionParser->GetItemLineL(KModuleName);
       
  1869         CleanupStack::PushL(item);
       
  1870         if(!item)
       
  1871             {
       
  1872             __TRACE(KError, (CStifLogger::ERed, _L("'%S' not found from Module section. Skipping whole section."), &KModuleName));
       
  1873             sectionOK = EFalse;
       
  1874             }
       
  1875         else
       
  1876             {
       
  1877             __TRACE(KInit, (_L("'%S' found"), &KModuleName));
       
  1878             }
       
  1879 
       
  1880         TName moduleName;
       
  1881         TInt ret(KErrNone);
       
  1882 
       
  1883         if(sectionOK)
       
  1884             {
       
  1885             TPtrC name;
       
  1886             ret = item->GetString(KModuleName, name);
       
  1887             if(ret != KErrNone)
       
  1888                 {
       
  1889                 __TRACE(KError, (CStifLogger::ERed, _L("Module name parsing ended with error [%d]. Skipping whole section"), ret));
       
  1890                 sectionOK = EFalse;
       
  1891                 }
       
  1892             else
       
  1893                 {
       
  1894                 __TRACE(KInit, (_L("Module '%S' found from ini-file"), &name));
       
  1895                 moduleName.Copy(name);
       
  1896                 moduleName.LowerCase();
       
  1897                 ret = aModuleList->AddTestModule(moduleName);
       
  1898                 if(ret != KErrNone && ret != KErrAlreadyExists)
       
  1899                     {
       
  1900                     CleanupStack::PopAndDestroy(item);
       
  1901                     __TRACE(KError, (CStifLogger::ERed, _L("Could not add module to list of modules. Error %d"), ret));
       
  1902                     LeaveIfErrorWithNotify(ret);
       
  1903                     }
       
  1904                 }
       
  1905             }
       
  1906         CleanupStack::PopAndDestroy(item);
       
  1907 
       
  1908         //Get pointer to added module
       
  1909         if(sectionOK)
       
  1910             {
       
  1911             CTestModuleInfo* moduleInfo = aModuleList->GetModule(moduleName);
       
  1912             if(!moduleInfo)
       
  1913                 {
       
  1914                 __TRACE(KError, (CStifLogger::ERed, _L("Could not add get module info from list")));
       
  1915                 LeaveIfErrorWithNotify(KErrNotFound);
       
  1916                 }
       
  1917     
       
  1918             // Get ini file, if it exists
       
  1919             __TRACE(KInit, (_L("Start parsing ini file")));
       
  1920             _LIT(KIniFile, "IniFile=");
       
  1921             item = sectionParser->GetItemLineL(KIniFile);
       
  1922             if(item)
       
  1923                 {
       
  1924                 __TRACE(KInit, (_L("'%S' found"), &KIniFile));
       
  1925                 CleanupStack::PushL(item);
       
  1926                 TPtrC iniFile;
       
  1927                 ret = item->GetString(KIniFile, iniFile);
       
  1928                 if(ret == KErrNone)
       
  1929                     {
       
  1930                     // Module inifile (might be empty) OK
       
  1931                     TFileName filename;
       
  1932                     filename.Copy(iniFile);
       
  1933                     TStifUtil::CorrectFilePathL( filename );
       
  1934                     filename.LowerCase();
       
  1935                     __TRACE(KInit, (CStifLogger::EBold, _L("Initialization file '%S' found, file can be empty"), &iniFile));
       
  1936                     moduleInfo->SetIniFile(filename);
       
  1937                     }
       
  1938                 else
       
  1939                     {
       
  1940                     __TRACE(KInit, (_L("Initialization file not found")));
       
  1941                     }
       
  1942                 CleanupStack::PopAndDestroy(item);
       
  1943                 }
       
  1944             else
       
  1945                 {
       
  1946                 __TRACE(KInit, (_L("'%S' not found"), &KIniFile));
       
  1947                 }
       
  1948     
       
  1949             // Get config (testcase) file
       
  1950             __TRACE(KInit, (_L("Start parsing cfg files")));
       
  1951             TPtrC cfgTag;
       
  1952             for(TInt i = 0; i < 2; i++)
       
  1953                 {
       
  1954                 //Set tag for config files
       
  1955                 if(i == 0)
       
  1956                     {
       
  1957                     cfgTag.Set(_L("ConfigFile="));
       
  1958                     }
       
  1959                     else
       
  1960                     {
       
  1961                     cfgTag.Set(_L("TestCaseFile="));
       
  1962                     }
       
  1963                 //Read data
       
  1964                 item = sectionParser->GetItemLineL(cfgTag);
       
  1965                 while(item)
       
  1966                     {
       
  1967                     CleanupStack::PushL(item);
       
  1968                     __TRACE(KInit, (_L("Item '%S' found"), &cfgTag));
       
  1969                     TPtrC cfgFile;
       
  1970                     ret = item->GetString(cfgTag, cfgFile);
       
  1971                     if(ret == KErrNone)
       
  1972                         {
       
  1973                         TFileName ifile;
       
  1974                         ifile.Copy(cfgFile);
       
  1975                         TStifUtil::CorrectFilePathL( ifile );
       
  1976                         ifile.LowerCase();
       
  1977                         __TRACE(KInit, (_L("Configuration file '%S' found"), &ifile));
       
  1978                         moduleInfo->AddCfgFile(ifile);
       
  1979                         }
       
  1980                     else
       
  1981                         {
       
  1982                         __TRACE(KInit, (_L("Configuration file not found")));
       
  1983                         }
       
  1984                     CleanupStack::PopAndDestroy(item);
       
  1985                     item = sectionParser->GetNextItemLineL(cfgTag);
       
  1986                     }
       
  1987                 }
       
  1988     
       
  1989             __TRACE(KInit, (_L("Module '%S' information read correctly"), &moduleName));
       
  1990             }
       
  1991         else
       
  1992             {
       
  1993             __TRACE(KError, (_L("Module '%S' information skipped"), &moduleName));
       
  1994             }
       
  1995 
       
  1996         // Get next section...
       
  1997         CleanupStack::PopAndDestroy(sectionParser);
       
  1998         sectionParser = aParser->NextSectionL(aSectionStart, aSectionEnd);
       
  1999         }
       
  2000     }
       
  2001 
       
  2002 /*
       
  2003 -------------------------------------------------------------------------------
       
  2004 
       
  2005     Class: CTestEngine
       
  2006 
       
  2007     Method: ReadTestModules
       
  2008 
       
  2009     Description: Parse Test modules and module information from
       
  2010                  STIF initialization file.
       
  2011 
       
  2012     Parameters: CStifParser& parser: in: CStifParser object
       
  2013 
       
  2014     Return Values: None
       
  2015 
       
  2016     Errors/Exceptions: Leaves if some of called leaving methods leaves
       
  2017 
       
  2018     Status: Approved
       
  2019 
       
  2020 -------------------------------------------------------------------------------
       
  2021 */
       
  2022 void CTestEngine::ReadTestModulesL(CStifParser* aParser)
       
  2023     {
       
  2024     __TRACE( KInit, (_L("")));
       
  2025     __TRACE( KInit, (CStifLogger::EBold, _L("Start parsing test modules")));
       
  2026 
       
  2027     //Create CTestModuleList object. It will keep information about all found test modules,
       
  2028     //its initialization files and test case (config) files.
       
  2029     CTestModuleList* moduleList = CTestModuleList::NewL(Logger());
       
  2030     CleanupStack::PushL(moduleList);
       
  2031 
       
  2032     // Parse Test Module information
       
  2033     _LIT(KTestModuleStart, "[New_Module]");
       
  2034     _LIT(KTestModuleEnd, "[End_Module]");
       
  2035 
       
  2036     __TRACE(KInit, (_L("Starting to search module sections")));
       
  2037     TRAPD(err, ParseTestModulesL(aParser, moduleList, KTestModuleStart, KTestModuleEnd));
       
  2038     if(err != KErrNone)
       
  2039         {
       
  2040         __TRACE(KError, (CStifLogger::ERed, _L("Parsing test modules returned error [%d]"), err));
       
  2041         User::Leave(err);
       
  2042         }
       
  2043     __TRACE(KInit, (CStifLogger::EBold, _L("End parsing test modules")));
       
  2044     __TRACE(KInit, (_L("")));
       
  2045 
       
  2046     //Now, find included test modules and also add them to CTestModuleList object.
       
  2047     _LIT(KIncludeModuleStart, "[New_Include_Module]");
       
  2048     _LIT(KIncludeModuleEnd, "[End_Include_Module]");
       
  2049 
       
  2050     __TRACE(KInit, (CStifLogger::EBold, _L("Start parsing included modules")));
       
  2051     CTestCaseFileInfo* finfo = moduleList->GetUncheckedCfgFile();
       
  2052     while(finfo)
       
  2053         {
       
  2054         TFileName fname;
       
  2055         finfo->GetCfgFileName(fname);
       
  2056 
       
  2057         __TRACE(KInit, (_L("checking file: '%S'"), &fname));
       
  2058         finfo->SetChecked();
       
  2059 
       
  2060         CStifParser* parser = NULL;
       
  2061 
       
  2062         TRAPD(err, parser = CStifParser::NewL(_L(""), fname));
       
  2063         if(err == KErrNotFound)
       
  2064             {
       
  2065             __TRACE(KError, (CStifLogger::ERed, _L("Could not open file '%S'"), &fname));
       
  2066             }
       
  2067         else if(err != KErrNone)
       
  2068             {
       
  2069             __TRACE(KError, (CStifLogger::ERed, _L("Could not create parser for file '%S'"), &fname));
       
  2070             LeaveIfErrorWithNotify(err);
       
  2071             }
       
  2072         else
       
  2073             {
       
  2074             CleanupStack::PushL(parser);
       
  2075 
       
  2076             ParseTestModulesL(parser, moduleList, KIncludeModuleStart, KIncludeModuleEnd);
       
  2077 
       
  2078             CleanupStack::PopAndDestroy(parser);
       
  2079             }
       
  2080 
       
  2081         finfo = moduleList->GetUncheckedCfgFile();
       
  2082         }
       
  2083 
       
  2084     __TRACE(KInit, (CStifLogger::EBold, _L("End parsing included modules")));
       
  2085     __TRACE(KInit, (_L("")));
       
  2086 
       
  2087     //Now, when all modules have been found, create them
       
  2088     __TRACE(KInit, (CStifLogger::EBold, _L("Start creating modules")));
       
  2089     TBool afterReset = EFalse;
       
  2090     if(iRebootParams)
       
  2091         {
       
  2092         afterReset = ETrue;
       
  2093         }
       
  2094     CTestModuleInfo* moduleInfo = NULL;
       
  2095     TInt i;
       
  2096     TInt modCnt = moduleList->Count();
       
  2097 
       
  2098     for(i = 0; i < modCnt; i++)
       
  2099         {
       
  2100         moduleInfo = moduleList->GetModule(i);
       
  2101         if(!moduleInfo)
       
  2102             {
       
  2103             __TRACE(KInit, (CStifLogger::ERed, _L("Could not get module info at index %d"), i));
       
  2104             TName error;
       
  2105             error.AppendFormat(_L("Could not get module info at index %d"), i);
       
  2106             ErrorPrint(1, error);
       
  2107             continue;
       
  2108             }
       
  2109 
       
  2110         TName moduleName;
       
  2111         moduleInfo->GetModuleName(moduleName);
       
  2112 
       
  2113         // Create module controller
       
  2114         __TRACE(KInit, (_L("Creating module controller for '%S'"), &moduleName));
       
  2115 		CTestModuleController* module = NULL;
       
  2116 		if( moduleName == _L( "testscripter" ) )
       
  2117 			{
       
  2118 			module = CTestModuleController::NewL(this, moduleName, afterReset, ETrue);
       
  2119 			}
       
  2120 		else
       
  2121 			{
       
  2122 			module = CTestModuleController::NewL(this, moduleName, afterReset);
       
  2123 			}
       
  2124         CleanupStack::PushL(module);
       
  2125         __TRACE(KInit, (_L("Module controller created")));
       
  2126 
       
  2127         // Get ini file, if exists
       
  2128         __TRACE(KInit, (_L("Checking ini file")));
       
  2129         TFileName ini;
       
  2130         moduleInfo->GetIniFileName(ini);
       
  2131         if(ini.Length() == 0)
       
  2132             {
       
  2133             __TRACE(KInit, (_L("Ini file not found")));
       
  2134             }
       
  2135 
       
  2136         TRAPD(err, module->InitL(ini, KNullDesC));
       
  2137         if(err != KErrNone)
       
  2138             {
       
  2139             __TRACE(KInit, (CStifLogger::ERed, _L("Module '%S' loading failed: %d"), &moduleName, err));
       
  2140             TName error;
       
  2141             error.AppendFormat(_L("Module '%S' loading failed: %d"), &moduleName, err);
       
  2142             ErrorPrint(1, error);
       
  2143 
       
  2144             CleanupStack::PopAndDestroy(module);
       
  2145             continue;
       
  2146             }
       
  2147 
       
  2148         //Add test case files
       
  2149         __TRACE(KInit, (_L("Checking cfg files")));
       
  2150         TInt cfgCnt = moduleInfo->CountCfgFiles();
       
  2151         TInt j;
       
  2152         TFileName cfgFile;
       
  2153         for(j = 0; j < cfgCnt; j++)
       
  2154             {
       
  2155             moduleInfo->GetCfgFileName(j, cfgFile);
       
  2156             if(cfgFile.Length() > 0)
       
  2157                 {
       
  2158                 __TRACE(KInit, (_L("Adding config file '%S'"), &cfgFile));
       
  2159                 module->AddConfigFileL(cfgFile);
       
  2160                 }
       
  2161             else
       
  2162                 {
       
  2163                 __TRACE(KInit, (_L("Got empty config filename")));
       
  2164                 }
       
  2165             }
       
  2166         if(cfgCnt == 0)
       
  2167             {
       
  2168             __TRACE(KInit, (_L("Cfg file not found")));
       
  2169             }
       
  2170 
       
  2171         __TRACE(KInit, (_L("Module '%S' created correctly"), &moduleName));
       
  2172 
       
  2173         // Store module for later use
       
  2174         User::LeaveIfError(iModules.Append(module));
       
  2175         CleanupStack::Pop(module);
       
  2176         }
       
  2177 
       
  2178     __TRACE(KInit, (CStifLogger::EBold, _L("End creating test modules")));
       
  2179     __TRACE(KInit, (_L("")));
       
  2180 
       
  2181     //Check if there are any modules added to Stif
       
  2182     if (iModules.Count() == 0)
       
  2183         {
       
  2184         __TRACE(KInit, (_L("Not found '%S' and '%S' sections"), &KTestModuleStart, &KTestModuleEnd));
       
  2185         __TRACE(KInit, (CStifLogger::EBold, _L("Test module(s) not defined in initialisation file")));
       
  2186         // Note is printed from UI, not from here anymore
       
  2187         // ErrorPrint( 0 , _L("Test modules not found. Check testengine log"));
       
  2188         }
       
  2189 
       
  2190     //Delete CTestModuleList object. It is not needed any more
       
  2191     CleanupStack::PopAndDestroy(moduleList);
       
  2192     }
       
  2193 
       
  2194 /*
       
  2195 -------------------------------------------------------------------------------
       
  2196 
       
  2197     Class: CTestEngine
       
  2198 
       
  2199     Method: TestModuleConfigFileL
       
  2200 
       
  2201     Description: Add config file to test module
       
  2202 
       
  2203     Parameters: CTestModuleController* aModule: in: CTestModuleController
       
  2204                                                     object.
       
  2205                 CStifSectionParser* aSectionParser: in: CStifSectionParser
       
  2206                 object.
       
  2207                 TDesC& aTag :in: Founded tag.
       
  2208 
       
  2209     Return Values: None
       
  2210 
       
  2211     Errors/Exceptions: Leaves if GetNextItemLineL leaves
       
  2212 
       
  2213     Status: Approved
       
  2214 
       
  2215 -------------------------------------------------------------------------------
       
  2216 */
       
  2217 void CTestEngine::TestModuleConfigFileL( CTestModuleController* aModule,
       
  2218                                             CStifSectionParser* aSectionParser,
       
  2219                                             TDesC& aTag )
       
  2220     {
       
  2221     // Add config files to Test Module
       
  2222     TPtrC configFile;
       
  2223     CStifItemParser* item = NULL;
       
  2224     item = aSectionParser->GetItemLineL( aTag );
       
  2225 
       
  2226     TInt cfgFiles = 0;
       
  2227     TFileName config;
       
  2228 
       
  2229     TInt ret( 0 );
       
  2230 
       
  2231     while ( item )
       
  2232         {
       
  2233         __TRACE( KInit,( _L( "Found '%S' section" ), &aTag ) );
       
  2234         CleanupStack::PushL( item );
       
  2235         ret = item->GetString( aTag, configFile );
       
  2236         if ( ret != KErrNone )
       
  2237             {
       
  2238             CleanupStack::PopAndDestroy( item );
       
  2239             __TRACE( KError, ( CStifLogger::ERed, _L( "File parsing left with error [%d]" ), ret ) );
       
  2240             }
       
  2241         else
       
  2242             {
       
  2243             config = configFile;
       
  2244             aModule->AddConfigFileL( config );
       
  2245 
       
  2246             // Module configfile (might be empty) OK
       
  2247             __TRACE( KInit,( _L( "Adding configuration file [%S]" ), &config ) );
       
  2248             cfgFiles++;
       
  2249             CleanupStack::PopAndDestroy( item );
       
  2250             }
       
  2251         item = aSectionParser->GetNextItemLineL( aTag );
       
  2252         }
       
  2253 
       
  2254     // Print trace
       
  2255     if ( cfgFiles == 0)
       
  2256         {  
       
  2257         __TRACE( KInit,( _L( "Module does not have '%S' files") , &aTag ) );
       
  2258         }
       
  2259 
       
  2260     }
       
  2261 
       
  2262 /*
       
  2263 -------------------------------------------------------------------------------
       
  2264 
       
  2265     Class: CTestEngine
       
  2266 
       
  2267     Method: ModuleControllerByName
       
  2268 
       
  2269     Description: Return the module controller specified by given parameter.
       
  2270 
       
  2271     Parameters: const TName& aModuleName: in: Test module name
       
  2272 
       
  2273     Return Values: CTestModuleController* : pointer to CTestModuleController
       
  2274 
       
  2275     Errors/Exceptions: None
       
  2276 
       
  2277     Status: Approved
       
  2278 
       
  2279 -------------------------------------------------------------------------------
       
  2280 */
       
  2281 CTestModuleController* CTestEngine::ModuleControllerByName(
       
  2282                                                     const TName& aModuleName )
       
  2283     {
       
  2284     TInt modules = iModules.Count();
       
  2285 
       
  2286     for ( TInt i = 0; i < modules; i++ )
       
  2287         {
       
  2288         if ( iModules[i]->ModuleName( aModuleName ) == aModuleName )
       
  2289             {
       
  2290             return iModules[i];
       
  2291             }
       
  2292         }
       
  2293     return NULL;
       
  2294     }
       
  2295 
       
  2296 /*
       
  2297 -------------------------------------------------------------------------------
       
  2298 
       
  2299     Class: CTestEngine
       
  2300 
       
  2301     Method: GetFreeOrCreateModuleControllerL
       
  2302 
       
  2303     Description: Return free module controller specified by given parameter.
       
  2304                  If it can't be found, new one will be created.
       
  2305 
       
  2306     Parameters: TTestInfo& aTestInfo: test info structure
       
  2307                 CTestModuleController** aRealModuleController: for test scripter a real module controller will be returned
       
  2308 
       
  2309     Return Values: CTestModuleController* : pointer to CTestModuleController
       
  2310 
       
  2311     Errors/Exceptions: None
       
  2312 
       
  2313     Status: Approved
       
  2314 
       
  2315 -------------------------------------------------------------------------------
       
  2316 */
       
  2317 CTestModuleController* CTestEngine::GetFreeOrCreateModuleControllerL(TTestInfo& aTestInfo,
       
  2318                                                                      CTestModuleController** aRealModuleController)
       
  2319     {
       
  2320     TInt i, j;
       
  2321     *aRealModuleController = NULL;
       
  2322     
       
  2323     TInt modules = iModules.Count();
       
  2324 
       
  2325     //Find out which way it should be processed
       
  2326     //New way means that Stif is going to find free test module controller
       
  2327     //(free means that it does not run any test case)
       
  2328     TBool oldWay = ETrue;
       
  2329     if((iUITestingSupport && aTestInfo.iModuleName.Find(KTestScripterName) == 0) 
       
  2330         || (aTestInfo.iModuleName == KPythonScripter)
       
  2331         || (iSeparateProcesses))
       
  2332         {
       
  2333         __TRACE(KInit, (_L("Module controllers handling mode: exclusive")));
       
  2334         //Exclusive mode means that every test case must be run in separate module controller.
       
  2335         oldWay = EFalse;
       
  2336         }
       
  2337     else
       
  2338         {
       
  2339         __TRACE(KInit, (_L("Module controllers handling mode: normal")));
       
  2340         oldWay = ETrue;
       
  2341         }
       
  2342         
       
  2343     //If option is not set and it is not python scripter case
       
  2344     //(python scripter always should look for free module controller)
       
  2345     //This is the old way
       
  2346     if(oldWay) 
       
  2347         {
       
  2348         __TRACE(KInit, (_L("Find test module controller for [%S]"), &aTestInfo.iModuleName));
       
  2349         for(i = 0; i < modules; i++)
       
  2350             {
       
  2351             if(iModules[i]->ModuleName(aTestInfo.iModuleName) == aTestInfo.iModuleName)
       
  2352                 {
       
  2353                 __TRACE(KInit, (_L("Found test module controller for [%S]"), &aTestInfo.iModuleName));
       
  2354                 return iModules[i];
       
  2355                 }
       
  2356             }
       
  2357         __TRACE(KInit, (_L("Test module controller for [%S] NOT FOUND"), &aTestInfo.iModuleName));
       
  2358         return NULL;
       
  2359         }
       
  2360     
       
  2361     //This is a new way
       
  2362     __TRACE(KInit, (_L("Find free test module controller for [%S]"), &aTestInfo.iModuleName));
       
  2363 
       
  2364     TName moduleName(aTestInfo.iModuleName);
       
  2365     CTestModuleController* parentController = NULL;
       
  2366 
       
  2367     //First find original test module controller (parent)
       
  2368     for(TInt i = 0; i < modules; i++)
       
  2369         {
       
  2370         if(iModules[i]->ModuleName(moduleName) ==  moduleName)
       
  2371             {
       
  2372             parentController = iModules[i];
       
  2373             __TRACE(KInit, (_L("Original (parent) module controller found [%S]"), &moduleName));
       
  2374             break;
       
  2375             }
       
  2376         }
       
  2377 
       
  2378     //Search free module controller among parent's children
       
  2379     if(parentController)
       
  2380         {
       
  2381         //TestScripter is handled in other way
       
  2382         if(moduleName.Find(KTestScripterName) == 0)
       
  2383             {
       
  2384             __TRACE(KInit, (_L("This is testscripter case. Searching real module controller.")));
       
  2385             *aRealModuleController = parentController->GetFreeOrCreateModuleControllerL(aTestInfo, iUITestingSupport);
       
  2386             return parentController;                 
       
  2387             }
       
  2388 
       
  2389         //When UITestingSupport always create new module controller!
       
  2390         TInt childrenCount = parentController->iChildrenControllers.Count();
       
  2391         for(TInt i = 0; i < childrenCount; i++)
       
  2392             {
       
  2393             if(parentController->iChildrenControllers[i]->iTestCaseCounter == 0)
       
  2394                 {
       
  2395                 if(iUITestingSupport && aTestInfo.iModuleName.Find(KTestScripterName) == 0)
       
  2396                     {
       
  2397                     __TRACE(KInit, (_L("Free module controller found but in UITestingSupport mode always new one will be created")));
       
  2398                     }
       
  2399                 else
       
  2400                     {
       
  2401                     __TRACE(KInit, (_L("Free module controller found [%S]"), parentController->iChildrenControllers[i]->iName));
       
  2402                     return parentController->iChildrenControllers[i];
       
  2403                     }
       
  2404                 }
       
  2405             else
       
  2406                 {
       
  2407                 __TRACE(KInit, (_L("Module controller [%S] found but it is not free (it runs %d test cases)"), parentController->iChildrenControllers[i]->iName, parentController->iChildrenControllers[i]->iTestCaseCounter));
       
  2408                 }
       
  2409             }
       
  2410         }
       
  2411     else
       
  2412         {
       
  2413         __TRACE(KError, (_L("Parent module controller NOT found [%S]"), &moduleName));
       
  2414         User::Leave(KErrNotFound);
       
  2415         }
       
  2416 
       
  2417     //No free module controller has been found. Create new one.
       
  2418     TBuf<10> ind;
       
  2419     ind.Format(_L("%d"), GetIndexForNewTestModuleController());
       
  2420     moduleName.Append(_L("@"));
       
  2421     moduleName.Append(ind);
       
  2422     __TRACE(KInit, (_L("Free module controller not found. Creating new one [%S]."), &moduleName));
       
  2423             
       
  2424     //Create server and active object (This uses CTestModuleController::InitL())
       
  2425     CTestModuleController* module = CTestModuleController::NewL(this, moduleName, parentController->iAfterReboot);
       
  2426     CleanupStack::PushL(module);
       
  2427     
       
  2428     TRAPD(err, module->InitL(parentController->iInifile, aTestInfo.iConfig));
       
  2429     if(err != KErrNone)
       
  2430         {
       
  2431         __TRACE(KInit, (_L("InitL fails with error: %d for module [%S]" ), err, &moduleName));
       
  2432         User::Leave(err);
       
  2433         }
       
  2434     __TRACE(KInit, (_L("New module controller created [%S]."), &moduleName));
       
  2435 
       
  2436     // Store module for later use
       
  2437     User::LeaveIfError(parentController->iChildrenControllers.Append(module));
       
  2438     CleanupStack::Pop(module);
       
  2439     __TRACE(KInit, (_L("Child added to [%S] controller. Currently it has %d children:"), parentController->iName, parentController->iChildrenControllers.Count()));
       
  2440     for(j = 0; j < parentController->iChildrenControllers.Count(); j++)
       
  2441         {
       
  2442         __TRACE(KInit, (_L("    %d. [%S]"), j + 1, parentController->iChildrenControllers[j]->iName));
       
  2443         }
       
  2444 
       
  2445     return module;
       
  2446     }
       
  2447 
       
  2448 /*
       
  2449 -------------------------------------------------------------------------------
       
  2450 
       
  2451     Class: CTestEngine
       
  2452 
       
  2453     Method: SetAttributeL
       
  2454 
       
  2455     Description: Sets attributes to Test Framework
       
  2456 
       
  2457     Parameters: const RMessage& aMessage: in: Server message
       
  2458 
       
  2459     Return Values: None
       
  2460 
       
  2461     Errors/Exceptions: Leave if ReadL leaves
       
  2462 
       
  2463     Status: Approved
       
  2464 
       
  2465 -------------------------------------------------------------------------------
       
  2466 */
       
  2467 void CTestEngine::SetAttributeL( const RMessage2& aMessage )
       
  2468     {
       
  2469     __TRACE( KVerbose, ( _L( "CTestEngine::SetAttributeL" ) ) );
       
  2470 
       
  2471     TAttribute attribute;
       
  2472     TName genericTName;
       
  2473 
       
  2474     // Read attribute from aMessage
       
  2475     attribute = (TAttribute)aMessage.Int0();
       
  2476 
       
  2477     switch( attribute )
       
  2478         {
       
  2479         // Path attribute
       
  2480         case ELogPath:
       
  2481             {
       
  2482             // Read path from aMessage. 
       
  2483             // NOTE!If message length is over TName, ReadL will cut the message
       
  2484             // to allowed size and won't return any error code or leave code.
       
  2485             aMessage.ReadL( 1, genericTName );
       
  2486 
       
  2487             // Handle to Setting server.
       
  2488             RSettingServer settingServer;
       
  2489             // Connect to the Setting server and create session
       
  2490             TInt ret = settingServer.Connect();
       
  2491             if ( ret != KErrNone )
       
  2492                 {
       
  2493                 User::Leave( ret );
       
  2494                 }
       
  2495             settingServer.SetNewIniFileSetting( genericTName );
       
  2496             // Close Setting server session
       
  2497             settingServer.Close();
       
  2498             break;
       
  2499             }
       
  2500         // Reboot directory
       
  2501         case ERebootPath:
       
  2502             {
       
  2503             // Read reboot path from aMessage. 
       
  2504             // NOTE!If message length is over TName, ReadL will cut the message
       
  2505             // to allowed size and won't return any error code or leave code.
       
  2506             aMessage.ReadL( 1, genericTName );
       
  2507             // Allocated dynamically iRebootPath size and copies aMessage path.
       
  2508             iRebootPath = genericTName.AllocL();
       
  2509             break;
       
  2510             }
       
  2511         // Reboot path
       
  2512         case ERebootFilename:
       
  2513             {
       
  2514             // Read reboot path from aMessage. 
       
  2515             // NOTE!If message length is over TName, ReadL will cut the message
       
  2516             // to allowed size and won't return any error code or leave code.
       
  2517             aMessage.ReadL( 1, genericTName );
       
  2518             // Allocated dynamically iRebootFilename size and copies aMessage
       
  2519             // filename.
       
  2520             iRebootFilename = genericTName.AllocL();
       
  2521             break;
       
  2522             }
       
  2523         // Measurement configuration info
       
  2524         case EStifMeasurementOn:
       
  2525             {
       
  2526             // Read Measurement configuration info from aMessage. 
       
  2527             aMessage.ReadL( 1, genericTName );
       
  2528 
       
  2529             // Set info to test engine
       
  2530             User::LeaveIfError( EnableStifMeasurement( genericTName ) );
       
  2531             break;
       
  2532             }
       
  2533         // Measurement configuration info
       
  2534         case EStifMeasurementOff:
       
  2535             {
       
  2536             // Read Measurement configuration info from aMessage. 
       
  2537             aMessage.ReadL( 1, genericTName );
       
  2538 
       
  2539             // Set info to test engine
       
  2540             User::LeaveIfError( DisableStifMeasurement( genericTName ) );
       
  2541             break;
       
  2542             }
       
  2543         default:
       
  2544             {
       
  2545             __TRACE( KVerbose, ( _L( "Not valid attribute" ) ) );
       
  2546             }
       
  2547         }
       
  2548 
       
  2549     }
       
  2550 
       
  2551 /*
       
  2552 -------------------------------------------------------------------------------
       
  2553 
       
  2554     Class: CTestEngine
       
  2555 
       
  2556     Method: AddTestModuleL
       
  2557 
       
  2558     Description: Adds new Test Module
       
  2559 
       
  2560     Parameters: const RMessage& aMessage: in: Server message
       
  2561 
       
  2562     Return Values: None
       
  2563 
       
  2564     Errors/Exceptions: Leaves if some of called leaving methods leaves
       
  2565                        Leaves if name length is zero
       
  2566 
       
  2567     Status: Approved: Proposal
       
  2568 
       
  2569 -------------------------------------------------------------------------------
       
  2570 */
       
  2571 void CTestEngine::AddTestModuleL( const RMessage2& aMessage )
       
  2572     {
       
  2573     __TRACE( KVerbose, ( _L( "CTestEngine::AddTestModuleL" ) ) );
       
  2574     TName name;
       
  2575     TFileName iniFile;
       
  2576 
       
  2577     // Read test module name from aMessage
       
  2578     aMessage.ReadL( 0, name );
       
  2579 
       
  2580     if( name.Length() == 0 )
       
  2581         {
       
  2582         LeaveWithNotifyL( KErrArgument );
       
  2583         }
       
  2584     // Read ini file name from aMessage
       
  2585     aMessage.ReadL( 1, iniFile );
       
  2586     
       
  2587     name.LowerCase();
       
  2588     // Remove optional '.DLL' from file name
       
  2589     TParse parse;
       
  2590     parse.Set( name, NULL, NULL );
       
  2591     
       
  2592     if ( parse.Ext() == _L(".dll") )
       
  2593         {
       
  2594         const TInt len = parse.Ext().Length();
       
  2595         name.Delete ( name.Length()-len, len );
       
  2596         }
       
  2597 
       
  2598     __TRACE( KInit, ( 
       
  2599         _L( "CTestEngine::AddTestModuleL, Adding Module:[%S]"), &name ) );
       
  2600 
       
  2601     // Check if test module already exists
       
  2602     CTestModuleController* testModule = ModuleControllerByName( name );
       
  2603     if ( testModule == NULL )
       
  2604         {
       
  2605         TBool afterReset = EFalse;
       
  2606         if( iRebootParams && iRebootParams->iTestModule == name )
       
  2607             {
       
  2608             afterReset = ETrue;
       
  2609             }
       
  2610         
       
  2611         // Create module controller
       
  2612 		CTestModuleController* module = NULL;
       
  2613 		if( name == _L( "testscripter" ) )
       
  2614 			{
       
  2615 			module = CTestModuleController::NewL( this, name, afterReset, ETrue );
       
  2616 			}
       
  2617 		else
       
  2618 			{
       
  2619 			//CTestModuleController* module = 
       
  2620 			module = CTestModuleController::NewL( this, name, afterReset );
       
  2621 			}
       
  2622         CleanupStack::PushL( module );
       
  2623 
       
  2624         module->InitL( iniFile, KNullDesC );
       
  2625 
       
  2626         // Store module for later use
       
  2627         User::LeaveIfError( iModules.Append( module ) );
       
  2628         CleanupStack::Pop( module );
       
  2629         // Done
       
  2630         iReturn = KErrNone;
       
  2631 
       
  2632         __TRACE( KInit, ( 
       
  2633         _L( "CTestEngine::AddTestModuleL, module added correctly") ) );
       
  2634         }
       
  2635     else
       
  2636         {
       
  2637         iReturn = KErrAlreadyExists;
       
  2638         __TRACE( KInit, ( 
       
  2639         _L( "CTestEngine::AddTestModuleL, module already added, all ok.") ) );
       
  2640         }
       
  2641 
       
  2642     }
       
  2643 
       
  2644 /*
       
  2645 -------------------------------------------------------------------------------
       
  2646 
       
  2647     Class: CTestEngine
       
  2648 
       
  2649     Method: RemoveTestModuleL
       
  2650 
       
  2651     Description: Removes Test Module
       
  2652 
       
  2653     Parameters: const RMessage& aMessage: in: Server message
       
  2654     
       
  2655     Return Values: TInt KErrNone: No errors occurred
       
  2656                         KErrNotFound: Test module not found
       
  2657                         KErrInUse: Test module is in use, cannot be removed
       
  2658 
       
  2659     Errors/Exceptions: Leaves if some of called leaving methods leaves
       
  2660                        Leaves if moduleName length is zero
       
  2661 
       
  2662     Status: Approved
       
  2663 
       
  2664 -------------------------------------------------------------------------------
       
  2665 */
       
  2666 TInt CTestEngine::RemoveTestModuleL( const RMessage2& aMessage )
       
  2667     {
       
  2668     __TRACE( KInit, ( _L( "CTestEngine::RemoveTestModuleL" ) ) );
       
  2669     // Read Module name from message
       
  2670     TName moduleName;
       
  2671     aMessage.ReadL( 0, moduleName );
       
  2672     if( moduleName.Length() == 0 )
       
  2673         {
       
  2674         LeaveWithNotifyL( KErrArgument );
       
  2675         }
       
  2676 
       
  2677     moduleName.LowerCase();
       
  2678     // Remove optional '.DLL' from file name
       
  2679     TParse parse;
       
  2680     parse.Set( moduleName, NULL, NULL );
       
  2681 
       
  2682     if ( parse.Ext() == _L(".dll") )
       
  2683         {
       
  2684         const TInt len = parse.Ext().Length();
       
  2685         moduleName.Delete ( moduleName.Length()-len, len );
       
  2686         }
       
  2687 
       
  2688     __TRACE(KInit, (_L("Going to remove module controller [%S]"), &moduleName));
       
  2689     // Check that the module that will be removed exists
       
  2690     TInt moduleCount = iModules.Count();
       
  2691     TBool found = EFalse;
       
  2692     TInt moduleIndex;
       
  2693     for ( moduleIndex = 0; moduleIndex < moduleCount; moduleIndex++ )
       
  2694         {
       
  2695         if ( iModules[moduleIndex]->ModuleName( moduleName ) == moduleName )
       
  2696             {
       
  2697             found = ETrue;
       
  2698             break;
       
  2699             }
       
  2700         }
       
  2701 
       
  2702     if ( !found )
       
  2703         {
       
  2704         // Test Module does not exists
       
  2705         __TRACE(KInit, (_L("Module controller [%S] to be removed NOT FOUND"), &moduleName));
       
  2706         return KErrNotFound;
       
  2707         }
       
  2708     // Check module controller and its children
       
  2709     if(iModules[moduleIndex]->iTestCaseCounter > 0)
       
  2710         {
       
  2711         __TRACE(KInit, (_L("Cannot remove module controller [%S], it is running %d test cases"), &moduleName, iModules[moduleIndex]->iTestCaseCounter));
       
  2712         return KErrInUse;
       
  2713         }
       
  2714     TInt j;
       
  2715     for(j = 0; j < iModules[moduleIndex]->iChildrenControllers.Count(); j++)
       
  2716         {
       
  2717         if(iModules[moduleIndex]->iChildrenControllers[j]->iTestCaseCounter > 0)
       
  2718             {
       
  2719             __TRACE(KInit, (_L("Cannot remove module controller [%S], its child [%S] is running %d test cases"), &moduleName, iModules[moduleIndex]->iChildrenControllers[j]->iName, iModules[moduleIndex]->iChildrenControllers[j]->iTestCaseCounter));
       
  2720             return KErrInUse;
       
  2721             }
       
  2722         }
       
  2723     // Test cases not running so we can remove the Test Module
       
  2724     __TRACE(KInit, (_L("Removing module controller [%S]"), &moduleName));
       
  2725     CTestModuleController* module = iModules[moduleIndex];
       
  2726     iModules.Remove(moduleIndex);
       
  2727     delete module;
       
  2728 
       
  2729     return KErrNone;
       
  2730 
       
  2731     }
       
  2732 
       
  2733 /*
       
  2734 -------------------------------------------------------------------------------
       
  2735 
       
  2736     Class: CTestEngine
       
  2737 
       
  2738     Method: CloseTestEngineL
       
  2739 
       
  2740     Description: Close test engine
       
  2741 
       
  2742     Parameters: None
       
  2743 
       
  2744     Return Values: None
       
  2745 
       
  2746     Errors/Exceptions: Leaves if GenerateReportL leaves
       
  2747 
       
  2748     Status: Approved
       
  2749 
       
  2750 -------------------------------------------------------------------------------
       
  2751 */
       
  2752 void CTestEngine::CloseTestEngineL( TUint aHandle )
       
  2753     {
       
  2754     __TRACE( KInit, ( _L( "CTestEngine::CloseTestEngineL" ) ) );
       
  2755     // Remove all module controllers
       
  2756     iModules.ResetAndDestroy();
       
  2757     iModules.Close();
       
  2758 
       
  2759     // If test report is created
       
  2760     if( iTestReport )
       
  2761         {
       
  2762         iTestReport->GenerateReportL();
       
  2763         iIsTestReportGenerated = ETrue;
       
  2764         }
       
  2765 
       
  2766     // Close Setting server, no handle available anymore
       
  2767     iSettingServer.Close();
       
  2768 
       
  2769     // Get test case from container
       
  2770     CTestEngineSubSession* testEngineSubSession = ( CTestEngineSubSession* )iTestEngineSubSessions->At( aHandle );
       
  2771 
       
  2772     // Do nothing if invalid handle
       
  2773     if ( testEngineSubSession == NULL )
       
  2774         {
       
  2775         // Handle might be already deleted, so do nothing.
       
  2776         return;
       
  2777         }
       
  2778 
       
  2779     iTestEngineSubSessions->Remove( aHandle );
       
  2780 
       
  2781     // Decrement resource count
       
  2782     iResourceCount--;
       
  2783     }
       
  2784 
       
  2785 /*
       
  2786 -------------------------------------------------------------------------------
       
  2787 
       
  2788     Class: CTestEngine
       
  2789 
       
  2790     Method: AddConfigFileL
       
  2791 
       
  2792     Description: Adds new config file to Test Module
       
  2793 
       
  2794     Parameters: const RMessage& aMessage: in: Server Message
       
  2795 
       
  2796     Return Values: None
       
  2797 
       
  2798     Errors/Exceptions: Leaves if some of called leaving methods leaves
       
  2799                        Leaves if module length is zero
       
  2800                        Leaves if configFile length is zero
       
  2801 
       
  2802     Status: Approved
       
  2803 
       
  2804 -------------------------------------------------------------------------------
       
  2805 */
       
  2806 void CTestEngine::AddConfigFileL( const RMessage2& aMessage )
       
  2807     {
       
  2808     TName module;
       
  2809     TFileName configFile;
       
  2810 
       
  2811     // Read module name from aMessage
       
  2812     aMessage.ReadL( 0, module );
       
  2813 
       
  2814     if( module.Length() == 0 )
       
  2815         {
       
  2816         LeaveWithNotifyL( KErrArgument );
       
  2817         }
       
  2818     // Read config file name from aMessage
       
  2819     aMessage.ReadL( 1, configFile );
       
  2820 
       
  2821     if( configFile.Length() == 0 )
       
  2822         {
       
  2823         LeaveWithNotifyL( KErrArgument );
       
  2824         }
       
  2825 
       
  2826     module.LowerCase();
       
  2827     // Remove optional '.DLL' from file name
       
  2828     TParse parse;
       
  2829     parse.Set( module, NULL, NULL );
       
  2830     
       
  2831     if ( parse.Ext() == _L(".dll") )
       
  2832         {
       
  2833         const TInt len = parse.Ext().Length();
       
  2834         module.Delete ( module.Length()-len, len );
       
  2835         }
       
  2836         
       
  2837     __TRACE( KInit, ( _L( "Adding config file [%S] to [%S] module"), &configFile, &module ) );
       
  2838     
       
  2839     // Get correct test module controller
       
  2840     CTestModuleController* testModule = ModuleControllerByName( module );
       
  2841     if ( testModule == NULL )
       
  2842         {        
       
  2843         __TRACE( KError, ( CStifLogger::ERed, _L( "Added configure file has an invalid module:[%S]"), &module ) );
       
  2844         LeaveWithNotifyL ( KErrNotFound );
       
  2845         }
       
  2846 
       
  2847     // Add config file to Module
       
  2848     testModule->AddConfigFileL( configFile );
       
  2849 
       
  2850     }
       
  2851     
       
  2852 /*
       
  2853 -------------------------------------------------------------------------------
       
  2854 
       
  2855     Class: CTestEngine
       
  2856 
       
  2857     Method: RemoveConfigFileL
       
  2858 
       
  2859     Description: Removes a config file from test module
       
  2860 
       
  2861     Parameters: const RMessage& aMessage: in: Server Message
       
  2862 
       
  2863     Return Values: None
       
  2864 
       
  2865     Errors/Exceptions: Leaves if some of called leaving methods leaves
       
  2866                        Leaves if module length is zero
       
  2867                        Leaves if configFile length is zero
       
  2868 
       
  2869     Status: Proposal
       
  2870 
       
  2871 -------------------------------------------------------------------------------
       
  2872 */
       
  2873 void CTestEngine::RemoveConfigFileL( const RMessage2& aMessage )
       
  2874     {
       
  2875     TName module;
       
  2876     TFileName configFile;
       
  2877 
       
  2878     // Read module name from aMessage
       
  2879     aMessage.ReadL( 0, module );
       
  2880 
       
  2881     if( module.Length() == 0 )
       
  2882         {
       
  2883         LeaveWithNotifyL( KErrArgument );
       
  2884         }
       
  2885     // Read config file name from aMessage
       
  2886     aMessage.ReadL( 1, configFile );
       
  2887 
       
  2888     if( configFile.Length() == 0 )
       
  2889         {
       
  2890         LeaveWithNotifyL( KErrArgument );
       
  2891         }
       
  2892 
       
  2893     module.LowerCase();
       
  2894     // Remove optional '.DLL' from file name
       
  2895     TParse parse;
       
  2896     parse.Set( module, NULL, NULL );
       
  2897     
       
  2898     if ( parse.Ext() == _L(".dll") )
       
  2899         {
       
  2900         const TInt len = parse.Ext().Length();
       
  2901         module.Delete ( module.Length()-len, len );
       
  2902         }
       
  2903         
       
  2904     __TRACE( KInit, ( _L( "Removing config file [%S] from [%S] module"), &configFile, &module ) );
       
  2905     
       
  2906     // Get correct test module controller
       
  2907     CTestModuleController* testModule = ModuleControllerByName( module );
       
  2908     if ( testModule == NULL )
       
  2909         {        
       
  2910         __TRACE( KError, ( CStifLogger::ERed, _L( "Added configure file has an invalid module:[%S]"), &module ) );
       
  2911         LeaveWithNotifyL ( KErrNotFound );
       
  2912         }
       
  2913 
       
  2914     // Remove config file from Module
       
  2915     testModule->RemoveConfigFileL( configFile );
       
  2916 
       
  2917     }
       
  2918 
       
  2919 
       
  2920 /*
       
  2921 -------------------------------------------------------------------------------
       
  2922 
       
  2923     Class: CTestEngine
       
  2924 
       
  2925     Method: EnumerateTestCasesL
       
  2926 
       
  2927     Description: Enumerates test cases
       
  2928 
       
  2929     Parameters: const RMessage& aMessage: in: Server message
       
  2930 
       
  2931     Return Values: None
       
  2932 
       
  2933     Errors/Exceptions: Panics the client if enumeration is already pending
       
  2934                        Leaves if called StartEnumerateL method leaves
       
  2935 
       
  2936     Status: Proposal
       
  2937 
       
  2938 -------------------------------------------------------------------------------
       
  2939 */
       
  2940 void CTestEngine::EnumerateTestCasesL( const RMessage2& aMessage )
       
  2941     {
       
  2942     __TRACE( KInit, ( _L( "CTestEngine::EnumerateTestCasesL" ) ) );
       
  2943     // Check if enumerate is ongoing!!
       
  2944     __ASSERT_ALWAYS( iEnumerateModuleCount == 0, PanicClient( EReqPending, aMessage ) );
       
  2945 
       
  2946     iCaseCount = 0;
       
  2947     iEnumError = KErrNone;
       
  2948 
       
  2949     TInt count = iModules.Count();
       
  2950     if ( count == 0 )
       
  2951         {
       
  2952 
       
  2953         __TRACE( KInit, ( CStifLogger::EBold, _L( "Test module(s) not loaded - returning 0 test cases" ) ) );
       
  2954         
       
  2955         // Note is printed from UI
       
  2956         // ErrorPrint(0, _L("No test modules, check testengine log"));
       
  2957         // Write test case count to client
       
  2958         TCaseCount countPckg( 0 );
       
  2959         TRAPD( err, aMessage.WriteL( 0, countPckg ) );
       
  2960 
       
  2961         // Request will be completed in DispatchMessageL
       
  2962         iReturn = err;
       
  2963         }
       
  2964     else
       
  2965         {
       
  2966         for ( TInt i = 0; i < count; i++ )
       
  2967             {
       
  2968             // Send enumerate request to each test module.
       
  2969             iModules[i]->StartEnumerateL();
       
  2970             iEnumerateModuleCount++;
       
  2971             }
       
  2972     
       
  2973         // Message is completed later from EnumerationCompleted function
       
  2974         iComplete = EFalse;
       
  2975 
       
  2976         // Store the message
       
  2977         iEnumerationMessage = aMessage;
       
  2978         }
       
  2979 
       
  2980     }
       
  2981 
       
  2982 /*
       
  2983 -------------------------------------------------------------------------------
       
  2984 
       
  2985     Class: CTestEngine
       
  2986 
       
  2987     Method: EnumerationCompleted
       
  2988 
       
  2989     Description: Return the module controller specified by given parameter.
       
  2990 
       
  2991     Parameters: TInt aCount: in: Count of test cases
       
  2992                 TInt aError: in: Symbian OS Error code: Error from Test Module
       
  2993 
       
  2994     Return Values: None
       
  2995 
       
  2996     Errors/Exceptions: None
       
  2997 
       
  2998     Status: Proposal
       
  2999 
       
  3000 -------------------------------------------------------------------------------
       
  3001 */
       
  3002 void CTestEngine::EnumerationCompleted( TInt aCount, TInt aError )
       
  3003     {
       
  3004     // Increment test case count by aCount
       
  3005     iCaseCount+= aCount;
       
  3006 
       
  3007     if ( aError != KErrNone )
       
  3008         {
       
  3009         iEnumError = aError;
       
  3010         }
       
  3011 
       
  3012     iEnumerateModuleCount--;
       
  3013     
       
  3014     if ( iEnumerateModuleCount == 0 )
       
  3015         {
       
  3016        
       
  3017         TInt attrib = CStifLogger::ENoStyle;
       
  3018         if ( iCaseCount == 0 )
       
  3019             {
       
  3020             attrib = CStifLogger::EBold;
       
  3021             }
       
  3022         __TRACE( KInit, ( attrib, _L( "Test case enumeration completed, testcase count %d"), iCaseCount ) );
       
  3023 
       
  3024         // Write test case count to client
       
  3025         TCaseCount countPckg( iCaseCount );
       
  3026         TRAPD( err, iEnumerationMessage.WriteL( 0, countPckg ) );
       
  3027 
       
  3028         if ( err != KErrNone )
       
  3029             {
       
  3030             iEnumError = err;
       
  3031             __TRACE( KError, ( CStifLogger::ERed,  _L( "CTestEngine::EnumerationCompleted: Failed %d"), iEnumError ) );
       
  3032             }
       
  3033         
       
  3034         // Complete request
       
  3035         iEnumerationMessage.Complete( iEnumError );
       
  3036         }
       
  3037 
       
  3038     }
       
  3039 
       
  3040 /*
       
  3041 -------------------------------------------------------------------------------
       
  3042 
       
  3043     Class: CTestEngine
       
  3044 
       
  3045     Method: GetTestCasesL
       
  3046 
       
  3047     Description: Get test cases
       
  3048 
       
  3049     Parameters: const RMessage& aMessage: in: Server message
       
  3050 
       
  3051     Return Values: None
       
  3052 
       
  3053     Errors/Exceptions: Leaves if enumeration is not yet complete
       
  3054 
       
  3055     Status: Approved
       
  3056 
       
  3057 -------------------------------------------------------------------------------
       
  3058 */
       
  3059 void CTestEngine::GetTestCasesL( const RMessage2& aMessage )
       
  3060     {
       
  3061     __TRACE( KVerbose, ( _L( "CTestEngine::GetTestCasesL" ) ) );
       
  3062 
       
  3063     const TInt len = sizeof( TTestInfo );
       
  3064 
       
  3065     // Loop through all test modules
       
  3066     TInt moduleCount = iModules.Count();
       
  3067     TInt pos = 0;
       
  3068     TInt totalCount = 0;
       
  3069     for ( TInt i = 0; i < moduleCount; i++ )
       
  3070         {
       
  3071         CTestModuleController* module = iModules[i];
       
  3072 
       
  3073         // Check that test cases are enumerated first
       
  3074         if ( !module->EnumerationComplete() )
       
  3075             {
       
  3076             __TRACE( KError, ( CStifLogger::ERed, _L( "CTestEngine::GetTestCasesL, Test Cases not yet enumerated!" ) ) );
       
  3077             LeaveIfErrorWithNotify( KErrNotFound );
       
  3078             }
       
  3079 
       
  3080         CFixedFlatArray<TTestInfo>* testCases = module->TestCasesL();
       
  3081         CleanupStack::PushL( testCases );
       
  3082         
       
  3083         // Loop through all test cases got from test module
       
  3084         const TInt caseCount = testCases->Count();
       
  3085         totalCount+=caseCount;
       
  3086 
       
  3087         for ( TInt j = 0; j < caseCount; j++ )
       
  3088             {
       
  3089             if(((*testCases)[j]).iTestCaseInfo.iTimeout == 0 && iDefaultTimeout > 0)
       
  3090                 {
       
  3091                 ((*testCases)[j]).iTestCaseInfo.iTimeout = iDefaultTimeout;
       
  3092                 }
       
  3093 
       
  3094             // Construct package for source data
       
  3095             TTestInfoPckg tmpPackage( ( *testCases )[j] );
       
  3096 
       
  3097             // Copy test case package to client's memory
       
  3098             aMessage.WriteL( 0, tmpPackage, pos ) ;
       
  3099 
       
  3100             pos = pos + len;
       
  3101             }
       
  3102         CleanupStack::PopAndDestroy( testCases );
       
  3103 
       
  3104         // Free allocated test cases because not needed anymore
       
  3105         module->FreeTestCases();
       
  3106 
       
  3107         }
       
  3108 
       
  3109     __TRACE( KVerbose, ( _L( "CTestEngine::GetTestCasesL, case count %d" ), totalCount ) );
       
  3110 
       
  3111     // Finished
       
  3112     iReturn = KErrNone;
       
  3113     }
       
  3114 
       
  3115 /*
       
  3116 -------------------------------------------------------------------------------
       
  3117 
       
  3118     Class: CTestEngine
       
  3119 
       
  3120     Method: CancelAsyncRequest
       
  3121 
       
  3122     Description: Asynchronous requests are canceled by this function.
       
  3123 
       
  3124     Parameters: const RMessage aMessage
       
  3125 
       
  3126     Return Values: None
       
  3127 
       
  3128     Errors/Exceptions: None
       
  3129 
       
  3130     Status: Proposal
       
  3131 
       
  3132 -------------------------------------------------------------------------------
       
  3133 */
       
  3134 void CTestEngine::CancelAsyncRequest( const RMessage2& aMessage )
       
  3135     {
       
  3136     switch ( aMessage.Int0() )
       
  3137         {
       
  3138         case ETestEngineEnumerateTestCases:
       
  3139             {
       
  3140             TInt count = iModules.Count();
       
  3141             for ( TInt i=0; i < count; i++ )
       
  3142                 {
       
  3143                 // Cancel enumerate  
       
  3144                 iModules[i]->Cancel();
       
  3145                 }
       
  3146             break;
       
  3147             }
       
  3148 
       
  3149         case ETestEngineErrorNotification:
       
  3150             {
       
  3151             if ( iErrorMessageAvailable )
       
  3152                 {
       
  3153                 iErrorMessageAvailable = EFalse;
       
  3154                 iErrorMessage.Complete ( KErrCancel );
       
  3155                 }
       
  3156             }
       
  3157             break;
       
  3158         case ETestEngineEvent:
       
  3159             // Event command cannot be cancelled
       
  3160             // Only EWaitEvent can be cancelled with ECancelWait
       
  3161         default:
       
  3162             PanicClient( EBadRequest, aMessage );
       
  3163             break;
       
  3164         }
       
  3165 
       
  3166     }
       
  3167 
       
  3168 /*
       
  3169 -------------------------------------------------------------------------------
       
  3170 
       
  3171     Class: CTestEngine
       
  3172 
       
  3173     Method: EventControlL
       
  3174 
       
  3175     Description: Controls event system.
       
  3176 
       
  3177     Parameters: const RMessage& aMessage: in: Server message
       
  3178 
       
  3179     Return Values: None
       
  3180 
       
  3181     Errors/Exceptions: Leaves if some of called leaving methods leaves
       
  3182 
       
  3183     Status: Proposal
       
  3184 
       
  3185 -------------------------------------------------------------------------------
       
  3186 */
       
  3187 void CTestEngine::EventControlL( const RMessage2& aMessage )
       
  3188 
       
  3189     {
       
  3190     __TRACE( KVerbose, ( _L( "CTestEngine::EventControlL" ) ) );
       
  3191     TInt ret = KErrNone;
       
  3192 
       
  3193     // Read EventIf from aMessage
       
  3194     TEventIf event;
       
  3195     TEventIfPckg eventIfPckg( event );
       
  3196     aMessage.ReadL( 0, eventIfPckg );
       
  3197 
       
  3198     // EWaitEvent, EReqEvent and ERelEvent need processing here
       
  3199     if( ( event.Type() == TEventIf::EWaitEvent ) ||
       
  3200         ( event.Type() == TEventIf::EReqEvent ) ||
       
  3201         ( event.Type() == TEventIf::ERelEvent ) ||
       
  3202         ( event.Type() == TEventIf::ECancelWait ) )
       
  3203         {
       
  3204         TInt ind = 0; 
       
  3205         TInt count = iClientEvents.Count();
       
  3206         const TDesC& eventName = event.Name();
       
  3207         // Search event from client event list
       
  3208         for( ind=0; ind < count; ind++ )
       
  3209             {
       
  3210             if( iClientEvents[ind]->Name() == eventName )
       
  3211                 {
       
  3212                 break;
       
  3213                 }
       
  3214             }
       
  3215 
       
  3216         switch( event.Type() )
       
  3217             {
       
  3218             // Handle event waiting  
       
  3219             case TEventIf::EWaitEvent:
       
  3220                 {
       
  3221                 // Check that we found event from client events list
       
  3222                 if( ind == count )
       
  3223                     {
       
  3224                     ret = KErrNotFound;
       
  3225                     }
       
  3226                 else
       
  3227                     {
       
  3228                     TEventMsg* eventEntry = iClientEvents[ind];
       
  3229                     
       
  3230                     __TRACE( KVerbose, ( _L( "CTestEngine::EventControlL: Waiting %S (count %i)"), 
       
  3231                         &event.Name(), count ) );
       
  3232 
       
  3233                     // Waiting is completed either from here in Wait method 
       
  3234                     // if event is already pending,
       
  3235                     // or from Set method in CtlEvent when event is set.
       
  3236                     eventEntry->Wait( aMessage );
       
  3237                     return;
       
  3238                     }
       
  3239                 }
       
  3240                 break;
       
  3241             case TEventIf::ECancelWait:
       
  3242                 {
       
  3243                 // Check that we found event from client events list
       
  3244                 if( ind == count )
       
  3245                     {
       
  3246                     ret = KErrNotFound;
       
  3247                     }
       
  3248                 else
       
  3249                     {
       
  3250                     TEventMsg* eventEntry = iClientEvents[ind];
       
  3251                     
       
  3252                     __TRACE( KVerbose, ( _L( "CTestEngine::EventControlL: Cancel waiting %S (count %i)"), 
       
  3253                         &event.Name(), count ) );
       
  3254 
       
  3255                     eventEntry->CancelWait();
       
  3256                     }
       
  3257                 }
       
  3258                 break;
       
  3259             // Handle event request
       
  3260             case TEventIf::EReqEvent:
       
  3261                 {
       
  3262                 // Check that event is not already requested
       
  3263                 if( ind < count )
       
  3264                     {
       
  3265                     // Already exists
       
  3266                     ret = KErrArgument;
       
  3267                     }
       
  3268                 else
       
  3269                     { 
       
  3270                     // Requested events are added to iClientEvents
       
  3271                     TEventMsg* eventEntry = new TEventMsg;
       
  3272                     if( eventEntry == NULL )
       
  3273                         {
       
  3274                         ret = KErrNoMemory;
       
  3275                         }
       
  3276                     else
       
  3277                         {
       
  3278                         CleanupStack::PushL( eventEntry );
       
  3279                         eventEntry->Copy( event );
       
  3280                         // Check if state event is set already
       
  3281                         if( IsStateEventAndSet( event.Name() ) )
       
  3282                             { 
       
  3283                             // If it was set already, set the event
       
  3284                             eventEntry->Set( TEventIf::EState );
       
  3285                             }
       
  3286                         ret = iClientEvents.Append( eventEntry ); 
       
  3287                         if( ret != KErrNone )
       
  3288                             {
       
  3289                             CleanupStack::PopAndDestroy( eventEntry );
       
  3290                             }
       
  3291                         else
       
  3292                             {   
       
  3293                             CleanupStack::Pop( eventEntry );
       
  3294                                
       
  3295                             __TRACE( KVerbose, ( _L( "CTestEngine::EventControlL: Req added %S (count %i)"),
       
  3296                                 &event.Name(), iClientEvents.Count() ) );
       
  3297                             } 
       
  3298                         }
       
  3299                     }
       
  3300                 }
       
  3301                 break;
       
  3302             // Release event 
       
  3303             case TEventIf::ERelEvent:
       
  3304                 {
       
  3305                 // Released events are deleted from iClientEvents
       
  3306                 // Check that we found entry from client events list
       
  3307                 if( ind == count )
       
  3308                     {
       
  3309                     ret = KErrNotFound;
       
  3310                     }
       
  3311                 else
       
  3312                     {
       
  3313                     __TRACE( KVerbose, ( _L( "CTestEngine::EventControlL: Release event %S (count %i)"), 
       
  3314                         &event.Name(), iClientEvents.Count() ) );
       
  3315 
       
  3316                     TEventMsg* eventEntry = iClientEvents[ind];
       
  3317                     iClientEvents.Remove( ind );
       
  3318                     eventEntry->Release();
       
  3319                     delete eventEntry;
       
  3320                     }
       
  3321                 }
       
  3322                 break;
       
  3323             default: // This should never happen!!!
       
  3324                 { 
       
  3325                 _LIT( KEngine, "CTestEngine" );
       
  3326                 User::Panic( KEngine, KErrGeneral );
       
  3327                 }
       
  3328                 break;
       
  3329             }
       
  3330         }
       
  3331     else
       
  3332         {
       
  3333         // ESetEvent and EUnsetEvent are only forwarded
       
  3334         TRequestStatus req;
       
  3335         CtlEventL( event, req );
       
  3336         User::WaitForRequest( req );
       
  3337         }
       
  3338         
       
  3339     aMessage.Complete( ret );
       
  3340 
       
  3341     }
       
  3342 
       
  3343 /*
       
  3344 -------------------------------------------------------------------------------
       
  3345 
       
  3346     Class: CTestEngine
       
  3347 
       
  3348     Method: HandleErrorNotificationL
       
  3349 
       
  3350     Description: Handle error notifications.
       
  3351 
       
  3352     Parameters: const RMessage& aMessage: in: Server message
       
  3353 
       
  3354     Return Values: None
       
  3355 
       
  3356     Errors/Exceptions: None
       
  3357 
       
  3358     Status: Approved
       
  3359 
       
  3360 -------------------------------------------------------------------------------
       
  3361 */
       
  3362 void CTestEngine::HandleErrorNotificationL( const RMessage2& aMessage )
       
  3363     {
       
  3364     iErrorMessage = aMessage;
       
  3365     iErrorMessageAvailable = ETrue;
       
  3366 
       
  3367     ProcessErrorQueue();
       
  3368 
       
  3369     }
       
  3370 
       
  3371 /*
       
  3372 -------------------------------------------------------------------------------
       
  3373 
       
  3374     Class: CTestEngine
       
  3375 
       
  3376     Method: LoggerSettings
       
  3377 
       
  3378     Description: Get Logger's overwrite parameters
       
  3379 
       
  3380     Parameters: const RMessage& aMessage: in: Server message
       
  3381 
       
  3382     Return Values: None
       
  3383 
       
  3384     Errors/Exceptions: Panics if WriteL fails
       
  3385 
       
  3386     Status: Approved
       
  3387 
       
  3388 -------------------------------------------------------------------------------
       
  3389 */
       
  3390 void CTestEngine::LoggerSettings( const RMessage2& aMessage )
       
  3391     {
       
  3392     __TRACE( KInit, ( _L( "CTestEngine::LoggerSettings" ) ) );
       
  3393 
       
  3394     // Copies logger settings to the package
       
  3395     TPckg<TLoggerSettings> loggerSettingsPckg( iTestEngineServer->iLoggerSettings );
       
  3396 
       
  3397     // Writes a packege that includes the logger overwrite settings to aMessage
       
  3398     TRAPD( err, aMessage.WriteL( 0, loggerSettingsPckg ) );
       
  3399     if ( err != KErrNone )
       
  3400         {
       
  3401         PanicClient( EBadDescriptor, aMessage );
       
  3402         }
       
  3403 
       
  3404     }
       
  3405 
       
  3406 /*
       
  3407 -------------------------------------------------------------------------------
       
  3408 
       
  3409     Class: CTestEngine
       
  3410 
       
  3411     Method: CloseLoggerSettings
       
  3412 
       
  3413     Description: Close logger settings
       
  3414 
       
  3415     Parameters: None
       
  3416 
       
  3417     Return Values: None
       
  3418 
       
  3419     Errors/Exceptions: None
       
  3420 
       
  3421     Status: Approved
       
  3422 
       
  3423 -------------------------------------------------------------------------------
       
  3424 */
       
  3425 void CTestEngine::CloseLoggerSettings()
       
  3426     {
       
  3427     __TRACE( KInit, ( _L( "CTestEngine::CloseLoggerSettings" ) ) );
       
  3428 
       
  3429     }
       
  3430 
       
  3431 /*
       
  3432 -------------------------------------------------------------------------------
       
  3433 
       
  3434     Class: CTestEngine
       
  3435 
       
  3436     Method: TestCaseByHandle
       
  3437 
       
  3438     Description: Return test case specified by aHandle
       
  3439 
       
  3440     Parameters: TUint aHandle : in : TUint : Handle to TestCase subsession
       
  3441 
       
  3442     Return Values: CTestCase* : pointer to CTestCase object
       
  3443 
       
  3444     Errors/Exceptions: None
       
  3445 
       
  3446     Status: Approved
       
  3447 
       
  3448 -------------------------------------------------------------------------------
       
  3449 */
       
  3450 CTestCase* CTestEngine::TestCaseByHandle( TUint aHandle, const RMessage2& aMessage )
       
  3451     {
       
  3452     // Try to get test case from test case container
       
  3453     CTestCase* testCase =
       
  3454         ( CTestCase* )iTestCases->At( aHandle );
       
  3455     if ( testCase == NULL )
       
  3456         {
       
  3457         PanicClient( EBadSubsessionHandle, aMessage ); 
       
  3458         }
       
  3459 
       
  3460     return testCase;
       
  3461 
       
  3462     }
       
  3463 
       
  3464 /*
       
  3465 -------------------------------------------------------------------------------
       
  3466 
       
  3467     Class: CTestEngine
       
  3468 
       
  3469     Method: NewTestCaseL
       
  3470 
       
  3471     Description: Create new test execution subsession
       
  3472 
       
  3473     Parameters: const RMessage& aMessage: in: Server Message
       
  3474 
       
  3475     Return Values: None
       
  3476 
       
  3477     Errors/Exceptions: Leaves if some of called leaving method leaves
       
  3478 
       
  3479     Status: Proposal
       
  3480 
       
  3481 -------------------------------------------------------------------------------
       
  3482 */
       
  3483 void CTestEngine::NewTestCaseL( const RMessage2& aMessage )
       
  3484     {
       
  3485     __TRACE( KVerbose, ( _L( "CTestEngine::NewTestCaseL start" ) ) );
       
  3486 
       
  3487     // Get data from message
       
  3488     TTestInfo testInfo;
       
  3489     TTestInfoPckg testInfoPckg = testInfo;
       
  3490 
       
  3491     TRAPD( res, aMessage.ReadL( 0, testInfoPckg ) );
       
  3492     if ( res != KErrNone )
       
  3493         {
       
  3494         PanicClient( EBadDescriptor, aMessage );
       
  3495         return;
       
  3496         }
       
  3497 
       
  3498     testInfo.iModuleName.LowerCase();
       
  3499     // Remove optional '.DLL' from file name
       
  3500     TParse parse;
       
  3501     parse.Set( testInfo.iModuleName, NULL, NULL );
       
  3502 
       
  3503     if ( parse.Ext() == _L(".dll") )
       
  3504         {
       
  3505         const TInt len = parse.Ext().Length();
       
  3506         testInfo.iModuleName.Delete ( testInfo.iModuleName.Length()-len, len );
       
  3507         }
       
  3508 
       
  3509     // Get correct test module controller
       
  3510     CTestModuleController* scrModule = NULL;
       
  3511     CTestModuleController* module = GetFreeOrCreateModuleControllerL(testInfo, &scrModule);
       
  3512     if ( module == NULL )
       
  3513         {
       
  3514         //@spe PanicClient( EInvalidModuleName, aMessage );
       
  3515         //@spe return;
       
  3516         __TRACE( KError, ( CStifLogger::ERed, _L( "Invalid module:[%S]"), &testInfo.iModuleName ) );
       
  3517         LeaveWithNotifyL ( KErrNotFound );
       
  3518         }
       
  3519 
       
  3520     // Create test case object
       
  3521     CTestCase* testCase =
       
  3522         CTestCase::NewL( this, module, iTestReport, testInfo, scrModule);
       
  3523     CleanupStack::PushL( testCase );
       
  3524 
       
  3525     // Add object to object container to generate unique id
       
  3526     iContainer->AddL( testCase );
       
  3527 
       
  3528     // Add object to object index
       
  3529     // This returns a unique handle so we can get it again
       
  3530     TInt handle = iTestCases->AddL( testCase );
       
  3531 
       
  3532     // Write the handle to client
       
  3533     TPckg<TInt> handlePckg( handle );
       
  3534 
       
  3535     TRAP( res, aMessage.WriteL( 3, handlePckg ) );
       
  3536     if ( res != KErrNone )
       
  3537         {
       
  3538         iTestCases->Remove( handle );
       
  3539         PanicClient( EBadDescriptor, aMessage );
       
  3540         return;
       
  3541         }
       
  3542 
       
  3543     // Add new test case to testcase array
       
  3544     User::LeaveIfError( iTestCaseArray.Append( testCase ) );
       
  3545     CleanupStack::Pop( testCase );
       
  3546 
       
  3547     // Notch up another resource
       
  3548     iResourceCount++;
       
  3549 
       
  3550     iReturn = KErrNone;
       
  3551 
       
  3552     __TRACE( KVerbose, ( _L( "CTestEngine::NewTestCaseL done" ) ) );
       
  3553 
       
  3554     }
       
  3555 
       
  3556 /*
       
  3557 -------------------------------------------------------------------------------
       
  3558 
       
  3559     Class: CTestEngine
       
  3560 
       
  3561     Method: DeleteTestCase
       
  3562 
       
  3563     Description: Delete test case from container list
       
  3564 
       
  3565     Parameters: TUint aHandle: in: Handle to test case to be removed
       
  3566 
       
  3567     Return Values: None
       
  3568 
       
  3569     Errors/Exceptions: None
       
  3570 
       
  3571     Status: Approved
       
  3572 
       
  3573 -------------------------------------------------------------------------------
       
  3574 */
       
  3575 void CTestEngine::DeleteTestCase( TUint aHandle ) 
       
  3576     {
       
  3577     __TRACE( KVerbose, ( _L( "CTestEngine::DeleteTestCase" ) ) );
       
  3578 
       
  3579     // Get test case from container
       
  3580     CTestCase* testCase = ( CTestCase* )iTestCases->At( aHandle );
       
  3581 
       
  3582     // Do nothing if invalid handle
       
  3583     if ( testCase == NULL )
       
  3584         {
       
  3585         // Handle might be already deleted, so do nothing.
       
  3586         return;
       
  3587         }
       
  3588 
       
  3589     //Get controllers
       
  3590     CTestModuleController* moduleController;
       
  3591     CTestModuleController* realModuleController;
       
  3592     
       
  3593     moduleController = testCase->GetModuleControllers(&realModuleController);
       
  3594     
       
  3595     // Check if module controllers have crashed
       
  3596     TBool moduleControllerCrashed = EFalse;
       
  3597     TBool realModuleControllerCrashed = EFalse;
       
  3598 
       
  3599     if(moduleController)
       
  3600         {
       
  3601         moduleControllerCrashed = moduleController->iTestModuleCrashDetected;
       
  3602         }
       
  3603     if(realModuleController)
       
  3604         {
       
  3605         realModuleControllerCrashed = realModuleController->iTestModuleCrashDetected;
       
  3606         }
       
  3607 
       
  3608     //__TRACE(KInit, (_L("CTestEngine::DeleteTestCase moduleController=[%x] crashed=[%d] realModuleController=[%x] crashed=[%d]"), moduleController, moduleControllerCrashed, realModuleController, realModuleControllerCrashed));
       
  3609     // For UITestingSupport, SeparateProcesses and PythonSupport, when module is crashed,
       
  3610     // remove it from module lists, because it will be deleted when closing test case.
       
  3611     if(moduleController)
       
  3612         {
       
  3613         if(moduleControllerCrashed && iUITestingSupport && moduleController->iName->Find(KTestScripterName) == 0
       
  3614            || moduleControllerCrashed && iSeparateProcesses
       
  3615            || moduleControllerCrashed &&  moduleController->iName->Find(KPythonScripter) == 0
       
  3616           )
       
  3617             {
       
  3618             __TRACE(KInit, (_L("Removing module controller from module list because of crash")));
       
  3619             //Look for specific module controller and delete it
       
  3620             TInt i;
       
  3621             TInt j, children;
       
  3622             TInt modules = iModules.Count();
       
  3623             for(i = 0; i < modules; i++)
       
  3624                 {
       
  3625                 if(iModules[i] == moduleController)
       
  3626                     {
       
  3627                     __TRACE(KInit, (_L("Module controller found - removing")));
       
  3628                     iModules.Remove(i);
       
  3629                     break;
       
  3630                     }
       
  3631 
       
  3632                 //Check children of the module and if module to be deleted found there, remove it
       
  3633                 children = iModules[i]->iChildrenControllers.Count();
       
  3634                 __TRACE(KInit, (_L("Checking %d children of [%S]"), children, iModules[i]->iName));
       
  3635                 for(j = 0; j < children; j++)
       
  3636                     {
       
  3637                     if(iModules[i]->iChildrenControllers[j] == moduleController)
       
  3638                         {
       
  3639                         __TRACE(KInit, (_L("Module controller found (child) - removing")));
       
  3640                         
       
  3641                         iModules[i]->iChildrenControllers.Remove(j);
       
  3642 
       
  3643                         __TRACE(KInit, (_L("Child removed from [%S] controller. Currently it has %d children:"), iModules[i]->iName, iModules[i]->iChildrenControllers.Count()));
       
  3644                         for(TInt k = 0; k < iModules[i]->iChildrenControllers.Count(); k++)
       
  3645                             {
       
  3646                             __TRACE(KInit, (_L("    %d. [%S]"), k + 1, iModules[i]->iChildrenControllers[k]->iName));
       
  3647                             }                            
       
  3648                         break;
       
  3649                         }
       
  3650                     }
       
  3651                 }
       
  3652             }
       
  3653         }
       
  3654     if(moduleController && realModuleController)
       
  3655         {
       
  3656         if(realModuleControllerCrashed && iUITestingSupport && realModuleController->iName->Find(KTestScripterName) == 0
       
  3657            || realModuleControllerCrashed && iSeparateProcesses
       
  3658            || realModuleControllerCrashed &&  realModuleController->iName->Find(KPythonScripter) == 0
       
  3659           )
       
  3660             {
       
  3661             __TRACE(KInit, (_L("Removing real module controller from module list because of crash")));
       
  3662             //Remove module controller from scripter controller
       
  3663             moduleController->RemoveModuleController(realModuleController);
       
  3664             }
       
  3665         }
       
  3666 
       
  3667     // Close test case and remove it from container
       
  3668     //testCase->CloseTestCase();
       
  3669     iTestCases->Remove( aHandle );
       
  3670 
       
  3671     // Decrement resource count
       
  3672     iResourceCount--;
       
  3673 
       
  3674     // Remove from testcase array
       
  3675     iTestCaseArray.Remove( iTestCaseArray.Find( testCase ) );
       
  3676 
       
  3677     //If this is UITestingSupport and module is not crashed, delete controller 
       
  3678     //(in other words, kill process, because we need somehow reset the test server).
       
  3679     if(moduleController && !moduleControllerCrashed)
       
  3680         {        
       
  3681         if(iUITestingSupport && moduleController->iName->Find(KTestScripterName) == 0)
       
  3682             {
       
  3683             if(realModuleController)
       
  3684                 {
       
  3685                 if(!realModuleControllerCrashed)
       
  3686                     {
       
  3687                     __TRACE(KInit, (_L("Delete module controller (and kill process in which test case was run).")));
       
  3688                     __TRACE(KInit, (_L("Real module controller provided - processing")));
       
  3689                     //Remove module controller from scripter controller
       
  3690                     moduleController->DeleteModuleController(realModuleController);
       
  3691                     }
       
  3692                 }
       
  3693             else
       
  3694                 {
       
  3695                  __TRACE(KInit, (_L("Delete module controller (and kill process in which test case was run).")));
       
  3696                  __TRACE(KInit, (_L("Real module controller not provided, checking normal controllers")));
       
  3697                 //Look for specific module controller and delete it
       
  3698                 TInt i;
       
  3699                 TInt j, children;
       
  3700                 TInt modules = iModules.Count();
       
  3701                 for(i = 0; i < modules; i++)
       
  3702                     {
       
  3703                     if(iModules[i] == moduleController)
       
  3704                         {
       
  3705                         __TRACE(KInit, (_L("Module controller found - deleting")));
       
  3706                         delete iModules[i];
       
  3707                         iModules.Remove(i);
       
  3708                         break;
       
  3709                         }
       
  3710 
       
  3711                     //Check children of the module and if module to be deleted found there, remove it
       
  3712                     children = iModules[i]->iChildrenControllers.Count();
       
  3713                     __TRACE(KInit, (_L("Checking %d children of [%S]"), children, iModules[i]->iName));
       
  3714                     for(j = 0; j < children; j++)
       
  3715                         {
       
  3716                         if(iModules[i]->iChildrenControllers[j] == moduleController)
       
  3717                             {
       
  3718                             __TRACE(KInit, (_L("Module controller found (child) - deleting")));
       
  3719                             
       
  3720                             delete iModules[i]->iChildrenControllers[j];
       
  3721                             iModules[i]->iChildrenControllers.Remove(j);
       
  3722     
       
  3723                             __TRACE(KInit, (_L("Child removed from [%S] controller. Currently it has %d children:"), iModules[i]->iName, iModules[i]->iChildrenControllers.Count()));
       
  3724                             for(TInt k = 0; k < iModules[i]->iChildrenControllers.Count(); k++)
       
  3725                                 {
       
  3726                                 __TRACE(KInit, (_L("    %d. [%S]"), k + 1, iModules[i]->iChildrenControllers[k]->iName));
       
  3727                                 }                            
       
  3728                             break;
       
  3729                             }
       
  3730                         }
       
  3731                     }
       
  3732                 }
       
  3733             }
       
  3734         }
       
  3735     }
       
  3736 
       
  3737 /*
       
  3738 -------------------------------------------------------------------------------
       
  3739 
       
  3740     Class: CTestEngine
       
  3741 
       
  3742     Method: IsStateEventAndSet
       
  3743 
       
  3744     Description: Callback to check state event status.
       
  3745 
       
  3746     Parameters: const TName& aEventName: in: Event name
       
  3747 
       
  3748     Return Values: ETrue: event is set 
       
  3749                    EFalse: event is not set
       
  3750 
       
  3751     Errors/Exceptions: None
       
  3752 
       
  3753     Status: Approved
       
  3754 
       
  3755 -------------------------------------------------------------------------------
       
  3756 */
       
  3757 TBool CTestEngine::IsStateEventAndSet( const TName& aEventName )
       
  3758     {
       
  3759     TInt count = iStateEvents.Count();
       
  3760     for( TInt i = 0; i < count; i++ ) 
       
  3761         {
       
  3762         TPtrC name = iStateEvents[i]->Des();
       
  3763         if( name == aEventName )
       
  3764             {
       
  3765             // Requested state event set already
       
  3766             return ETrue;
       
  3767             }
       
  3768         }
       
  3769     return EFalse;
       
  3770 
       
  3771     }
       
  3772 
       
  3773 /*
       
  3774 -------------------------------------------------------------------------------
       
  3775 
       
  3776     Class: CTestEngine
       
  3777 
       
  3778     Method: CtlEventL
       
  3779 
       
  3780     Description: Callback to control events.
       
  3781 
       
  3782     Parameters: const TEventIf& aEvent: in: event information
       
  3783                 TRequestStatus& aStatus: in: Request status
       
  3784 
       
  3785     Return Values: CTestEventController*: CTestEventController object
       
  3786 
       
  3787     Errors/Exceptions: Leaves if CtlEventL leaves
       
  3788                        Leaves if memory allocation fails
       
  3789                        Leaves if unset event not found from pending 
       
  3790                        state event list
       
  3791 
       
  3792     Status: Approved
       
  3793 
       
  3794 -------------------------------------------------------------------------------
       
  3795 */
       
  3796 CTestEventController* CTestEngine::CtlEventL( const TEventIf& aEvent, 
       
  3797                                               TRequestStatus& aStatus )
       
  3798     {
       
  3799     __TRACE( KVerbose, ( _L( "CTestEngine::CtlEventL" ) ) );
       
  3800     
       
  3801     aStatus = KRequestPending;
       
  3802 
       
  3803     UpdateEventL( aEvent );
       
  3804     return CTestEventController::NewL( this, aEvent, &aStatus );
       
  3805 
       
  3806     }
       
  3807 
       
  3808 /*
       
  3809 -------------------------------------------------------------------------------
       
  3810 
       
  3811     Class: CTestEngine
       
  3812 
       
  3813     Method: UpdateEventL
       
  3814 
       
  3815     Description: Update event lists.
       
  3816 
       
  3817     Parameters: const TEventIf& aEvent: in: event information
       
  3818 
       
  3819     Return Values: None
       
  3820 
       
  3821     Errors/Exceptions: Leaves if CtlEventL leaves
       
  3822                        Leaves if memory allocation fails
       
  3823                        Leaves if unset event not found from pending
       
  3824                        state event list
       
  3825 
       
  3826     Status: Approved
       
  3827 
       
  3828 -------------------------------------------------------------------------------
       
  3829 */
       
  3830 void CTestEngine::UpdateEventL( const TEventIf& aEvent )
       
  3831     {
       
  3832     // Handle ESetEvent and EUnsetEvent for state events here
       
  3833     if( aEvent.EventType() == TEventIf::EState )
       
  3834         {
       
  3835         // Find event from the list
       
  3836         TInt count = iStateEvents.Count();
       
  3837         TInt index = 0;
       
  3838         const TDesC& eventName = aEvent.Name();
       
  3839         for( ; index < count; index++ ) 
       
  3840             {
       
  3841             TPtrC name = iStateEvents[index]->Des();
       
  3842             if( name == eventName )
       
  3843                 {
       
  3844                 break;
       
  3845                 }
       
  3846             }
       
  3847 
       
  3848         if( aEvent.Type() == TEventIf::ESetEvent )
       
  3849             {
       
  3850             // Check that event is not already pending
       
  3851             if( index < count )
       
  3852                 {
       
  3853                 User::Leave( KErrAlreadyExists );
       
  3854                 }
       
  3855 
       
  3856             // Add set event to pending state event list
       
  3857             HBufC* name = aEvent.Name().AllocLC();
       
  3858             User::LeaveIfError( iStateEvents.Append( name ) );
       
  3859             CleanupStack::Pop( name );
       
  3860             }
       
  3861         else if( aEvent.Type() == TEventIf::EUnsetEvent )
       
  3862             {
       
  3863             if( index == count )
       
  3864                 {
       
  3865                 // Not found from state event list
       
  3866                 User::Leave( KErrNotFound );
       
  3867                 }
       
  3868             HBufC* tmp = iStateEvents[index];
       
  3869             iStateEvents.Remove( index );
       
  3870             delete tmp;
       
  3871             }
       
  3872         }
       
  3873     else if( aEvent.Type() == TEventIf::EUnsetEvent )
       
  3874         {
       
  3875         // Can not give Unset for indication event
       
  3876         User::Leave( KErrNotSupported );
       
  3877         }
       
  3878 
       
  3879     }
       
  3880 
       
  3881 /*
       
  3882 -------------------------------------------------------------------------------
       
  3883 
       
  3884     Class: CTestEngine
       
  3885 
       
  3886     Method: Logger
       
  3887 
       
  3888     Description: Return the pointer to Logger.
       
  3889 
       
  3890     Parameters: None
       
  3891 
       
  3892     Return Values: CStifLogger*: Pointer to StifLogger
       
  3893 
       
  3894     Errors/Exceptions: None
       
  3895 
       
  3896     Status: Approved
       
  3897 
       
  3898 -------------------------------------------------------------------------------
       
  3899 */
       
  3900 CStifLogger* CTestEngine::Logger()
       
  3901     {
       
  3902     return iTestEngineServer->Logger();
       
  3903 
       
  3904     }
       
  3905 
       
  3906 /*
       
  3907 -------------------------------------------------------------------------------
       
  3908 
       
  3909     Class: CTestEngine
       
  3910 
       
  3911     Method: WriteRebootParams
       
  3912 
       
  3913     Description: Write the Reboot's state parameters.
       
  3914 
       
  3915     Parameters: TTestInfo& aTestInfo: in: Test case information.
       
  3916                 TInt& aCode: in: Reboot related integer information.
       
  3917                 TDesC& aName: in: Reboot related string information.
       
  3918 
       
  3919     Return Values: TInt: Symbian OS error
       
  3920 
       
  3921     Errors/Exceptions: Error code returned if Logger creation fails.
       
  3922 
       
  3923     Status: Proposal
       
  3924 
       
  3925 -------------------------------------------------------------------------------
       
  3926 */
       
  3927 TInt CTestEngine::WriteRebootParams( TTestInfo& aTestInfo,
       
  3928                                         TInt& aCode,
       
  3929                                         TDesC& aName )
       
  3930     {
       
  3931     __TRACE( KVerbose, ( _L( "WriteRebootParams() starts..." ) ) );
       
  3932     
       
  3933     // Logger's setting definitions
       
  3934     TLoggerSettings loggerSettings;
       
  3935 
       
  3936     loggerSettings.iCreateLogDirectories = ETrue;
       
  3937     loggerSettings.iOverwrite = ETrue;
       
  3938     loggerSettings.iTimeStamp = EFalse;
       
  3939     loggerSettings.iLineBreak = EFalse;
       
  3940     loggerSettings.iEventRanking = EFalse;
       
  3941     loggerSettings.iThreadId = EFalse;
       
  3942     // EData format because now we don't have to check file type when
       
  3943     // parsing this.
       
  3944     loggerSettings.iHardwareFormat = CStifLogger::EData;
       
  3945     loggerSettings.iHardwareOutput = CStifLogger::EFile;
       
  3946     loggerSettings.iEmulatorFormat = CStifLogger::EData;
       
  3947     loggerSettings.iEmulatorOutput = CStifLogger::EFile;
       
  3948     loggerSettings.iUnicode = EFalse;
       
  3949     loggerSettings.iAddTestCaseTitle = EFalse;
       
  3950 
       
  3951     // Use default setting if path or filename are not set by SetAttribute()
       
  3952     if( iRebootPath == NULL )
       
  3953         {
       
  3954         iRebootPath= iRebootDefaultPath.Alloc();
       
  3955         }
       
  3956     if( iRebootFilename == NULL )
       
  3957         {
       
  3958         iRebootFilename= iRebootDefaultFilename.Alloc();
       
  3959         }
       
  3960 
       
  3961     CStifLogger* logger = NULL;
       
  3962     TRAPD( ret, logger = CStifLogger::NewL( *iRebootPath,
       
  3963                                         *iRebootFilename,
       
  3964                                         loggerSettings ) );
       
  3965     if( ret != KErrNone )
       
  3966         {
       
  3967         __TRACE( KError, ( _L( "WriteRebootParams() Logger creation fails with error: " ), ret ) );
       
  3968         delete logger;
       
  3969         return ret;
       
  3970         }
       
  3971 
       
  3972     // Write reboot parameters
       
  3973     // Because logging format is EData we need add line breaks by hand.
       
  3974     logger->Log( _L( "\r\n" ) );
       
  3975     logger->Log( _L( "This is TestFramework's file which includes Reboot related informations" ) );
       
  3976     logger->Log( _L( "\r\n" ) );
       
  3977     logger->Log( _L( "\r\n" ) );
       
  3978     logger->Log( _L( "Reboot case's related information:" ) );
       
  3979     logger->Log( _L( "\r\n" ) );
       
  3980     logger->Log( _L( "%S %S" ), &KTestModule, &aTestInfo.iModuleName );
       
  3981     logger->Log( _L( "\r\n" ) );
       
  3982     logger->Log( _L( "%S %S" ), &KTestCaseFile, &aTestInfo.iConfig );
       
  3983     logger->Log( _L( "\r\n" ) );
       
  3984     logger->Log( _L( "%S %d" ), &KTestCaseNumber, aTestInfo.iTestCaseInfo.iCaseNumber );
       
  3985     logger->Log( _L( "\r\n" ) );
       
  3986     logger->Log( _L( "%S %S" ), &KTestCaseTitle, &aTestInfo.iTestCaseInfo.iTitle );
       
  3987     logger->Log( _L( "\r\n" ) );
       
  3988     logger->Log( _L( "\r\n" ) );
       
  3989     logger->Log( _L( "%S %d" ), &KStateCode, aCode );
       
  3990     logger->Log( _L( "\r\n" ) );
       
  3991     logger->Log( _L( "%S " ), &KStateName );
       
  3992     logger->Log( aName );
       
  3993     logger->Log( _L( "\r\n" ) );
       
  3994     logger->Log( _L( "\r\n" ) );
       
  3995 
       
  3996     delete logger;
       
  3997 
       
  3998     __TRACE( KVerbose, ( _L( "WriteRebootParams() ends" ) ) );
       
  3999 
       
  4000     return KErrNone;
       
  4001 
       
  4002     }
       
  4003 
       
  4004 /*
       
  4005 -------------------------------------------------------------------------------
       
  4006 
       
  4007     Class: CTestEngine
       
  4008 
       
  4009     Method: ReadRebootParams
       
  4010 
       
  4011     Description: Read the Reboot parameters.
       
  4012 
       
  4013     Parameters: TTestInfo& aTestInfo: in: Test case information.
       
  4014 
       
  4015     Return Values: TInt: Symbian OS error
       
  4016 
       
  4017     Errors/Exceptions: Error code returned if Parser creation fails.
       
  4018                        Error code returned if section creation fails.
       
  4019                        Error code returned if item creation fails.
       
  4020                        Error code returned if parsing operation fails.
       
  4021                        KErrArgument returned if parsed values and test case
       
  4022                        values are different.
       
  4023 
       
  4024     Status: Proposal
       
  4025 
       
  4026 -------------------------------------------------------------------------------
       
  4027 */
       
  4028 TInt CTestEngine::ReadRebootParams( TTestInfo& aTestInfo, 
       
  4029                                     TDes& aStateDes, 
       
  4030                                     TInt& aState )
       
  4031     {
       
  4032     __TRACE( KVerbose, ( _L( "ReadRebootParams() starts..." ) ) );
       
  4033 
       
  4034     if( iRebootParams == NULL )
       
  4035         {
       
  4036         __TRACE( KVerbose, ( _L( "ReadRebootParams(): Reboot not done" )) );
       
  4037         return KErrNotFound;
       
  4038         }
       
  4039         
       
  4040     // --.--.--.--.--.--.--.--.--.--.--.--.--.--.--.--.--.--
       
  4041     // Checks parsed values and test case values
       
  4042     // --.--.--.--.--.--.--.--.--.--.--.--.--.--.--.--.--.--
       
  4043     if( iRebootParams->iTestModule != aTestInfo.iModuleName ||
       
  4044         iRebootParams->iTestCaseFile != aTestInfo.iConfig ||
       
  4045         iRebootParams->iCaseNumber != aTestInfo.iTestCaseInfo.iCaseNumber )
       
  4046         {
       
  4047         __TRACE( KVerbose, 
       
  4048             ( _L( "ReadRebootParams(): Reboot not done by %S" ), 
       
  4049                 &aTestInfo.iModuleName) );
       
  4050         return KErrArgument;
       
  4051         }
       
  4052    
       
  4053     aStateDes.Copy( iRebootParams->iStateName );
       
  4054     aState = iRebootParams->iStateCode;
       
  4055    
       
  4056     // delete reboot params, to ensure that same test case 
       
  4057     // does not get indication about reboot again
       
  4058     delete iRebootParams;
       
  4059     iRebootParams = 0;
       
  4060 
       
  4061     __TRACE( KVerbose, ( _L("ReadRebootParams() ends" ) ) );
       
  4062     
       
  4063     return KErrNone;
       
  4064 
       
  4065     }
       
  4066 
       
  4067 /*
       
  4068 -------------------------------------------------------------------------------
       
  4069 
       
  4070     Class: CTestEngine
       
  4071 
       
  4072     Method: ParseRebootParamsL
       
  4073 
       
  4074     Description: Parse the Reboot parameters.
       
  4075 
       
  4076     Parameters: None
       
  4077 
       
  4078     Return Values: TInt: Symbian OS error
       
  4079 
       
  4080     Errors/Exceptions: Error code returned if Parser creation fails.
       
  4081                        Error code returned if section creation fails.
       
  4082                        Error code returned if item creation fails.
       
  4083                        Error code returned if parsing operation fails.
       
  4084                        KErrArgument returned if parsed values and test case
       
  4085                        values are different.
       
  4086 
       
  4087     Status: Proposal
       
  4088 
       
  4089 -------------------------------------------------------------------------------
       
  4090 */
       
  4091 TInt CTestEngine::ParseRebootParamsL()
       
  4092     {
       
  4093     __TRACE( KVerbose, ( _L( "ParseRebootParamsL() starts..." ) ) );
       
  4094 
       
  4095     TInt ret_parsing( 0 );
       
  4096     TPtrC tmp;
       
  4097 
       
  4098     // Use default setting if path or filename are not set by SetAttribute()
       
  4099     if( iRebootPath == NULL )
       
  4100         {
       
  4101         iRebootPath= iRebootDefaultPath.Alloc();
       
  4102         }
       
  4103     if( iRebootFilename == NULL )
       
  4104         {
       
  4105         iRebootFilename= iRebootDefaultFilename.Alloc();
       
  4106         }
       
  4107 
       
  4108     // Create parser object
       
  4109     CStifParser* parser = NULL;
       
  4110     TRAPD( ret, parser = CStifParser::NewL( *iRebootPath,
       
  4111                                         *iRebootFilename ) );
       
  4112     if( ret != KErrNone )
       
  4113         {
       
  4114         __TRACE( KError, ( _L( "ReadRebootParams(): Reboot file not found" )) );
       
  4115         return ret;        
       
  4116         }
       
  4117     CleanupStack::PushL( parser );
       
  4118     
       
  4119     // Create section object
       
  4120     CStifSectionParser* section = parser->SectionL( KNullDesC, KNullDesC );
       
  4121     CleanupStack::PushL( section );
       
  4122     
       
  4123     // Delete old reboot params
       
  4124     delete iRebootParams;
       
  4125     iRebootParams = 0;
       
  4126     iRebootParams = CRebootParams::NewL();
       
  4127     
       
  4128     // ----------------------Test module parsing
       
  4129     CStifItemParser* item = section->GetItemLineL( KTestModule );
       
  4130     CleanupStack::PushL( item );
       
  4131 
       
  4132     // Parsing integer
       
  4133     ret_parsing = item->GetString( KTestModule, tmp );
       
  4134     if( ret_parsing == KErrNone || ret_parsing == KErrNotFound )
       
  4135         {
       
  4136         __TRACE( KVerbose, ( _L("ReadRebootParams(): TestModule: %S" ), &tmp ) );
       
  4137         }
       
  4138     else
       
  4139         {
       
  4140         __TRACE( KError, 
       
  4141             ( _L("ReadRebootParams(): TestModule parsing fails with error: " ), 
       
  4142                 ret_parsing ) );
       
  4143         User::Leave( ret_parsing );        
       
  4144         }
       
  4145     iRebootParams->SetTestModuleNameL( tmp );
       
  4146     CleanupStack::PopAndDestroy( item );
       
  4147 
       
  4148     // ----------------------Testcase parsing
       
  4149     item = section->GetItemLineL( KTestCaseFile );
       
  4150     CleanupStack::PushL( item );
       
  4151 
       
  4152     // Parsing string
       
  4153     ret_parsing = item->GetString( KTestCaseFile, tmp );
       
  4154     if( ret_parsing == KErrNone ) 
       
  4155         {
       
  4156         __TRACE( KVerbose, ( _L("ReadRebootParams(): TestCaseFile: %S" ), &tmp ) );
       
  4157         iRebootParams->SetTestCaseFileNameL( tmp );
       
  4158         }
       
  4159     else if( ret_parsing == KErrNotFound )
       
  4160         {
       
  4161         __TRACE( KVerbose, 
       
  4162             ( _L("ReadRebootParams(): No testcasefile defined for test module" )) );
       
  4163         }
       
  4164     else
       
  4165         {
       
  4166         __TRACE( KError, 
       
  4167             ( _L("ReadRebootParams(): TestCaseFile parsing fails with error: %d " ), 
       
  4168                 ret_parsing ) );
       
  4169         User::Leave( ret_parsing );  
       
  4170         }
       
  4171     CleanupStack::PopAndDestroy( item );
       
  4172 
       
  4173     // ----------------------Testcase number parsing
       
  4174     item = section->GetItemLineL( KTestCaseNumber );
       
  4175     CleanupStack::PushL( item );    
       
  4176     
       
  4177     // Parsing integer
       
  4178     ret_parsing = item->GetInt( KTestCaseNumber, iRebootParams->iCaseNumber );
       
  4179     if( ret_parsing == KErrNone || ret_parsing == KErrNotFound )
       
  4180         {
       
  4181         __TRACE( KVerbose, ( _L("ReadRebootParams(): TestCaseNumber: %d" ), 
       
  4182             iRebootParams->iCaseNumber ) );
       
  4183         }
       
  4184     else
       
  4185         {
       
  4186         __TRACE( KError,
       
  4187             ( _L("ReadRebootParams(): TestCaseNumber parsing fails with error: %d " ), 
       
  4188                 ret_parsing ) );
       
  4189          User::Leave( ret_parsing );  
       
  4190         }
       
  4191     CleanupStack::PopAndDestroy( item );
       
  4192 
       
  4193     // --.--.--.--.--.--.--.--.--.--.--.--.--.--.--.--.--.--
       
  4194     // --.--.--.--.--.--.--.--.--.--.--.--.--.--.--.--.--.--
       
  4195     // Next state code and name parsing if no error found
       
  4196     // --.--.--.--.--.--.--.--.--.--.--.--.--.--.--.--.--.--
       
  4197 
       
  4198     // ----------------------State code parsing
       
  4199     item = section->GetItemLineL( KStateCode );
       
  4200     CleanupStack::PushL( item );   
       
  4201 
       
  4202     // Parsing integer
       
  4203     ret_parsing = item->GetInt( KStateCode, iRebootParams->iStateCode );
       
  4204     if( ret_parsing == KErrNone || ret_parsing == KErrNotFound )
       
  4205         {
       
  4206         __TRACE( KVerbose, ( _L("ReadRebootParams(): StateCode: %d" ), 
       
  4207             iRebootParams->iStateCode ) );
       
  4208         }
       
  4209     else
       
  4210         {
       
  4211         __TRACE( KError, 
       
  4212             ( _L("ReadRebootParams(): StateCode parsing fails with error: %d " ), 
       
  4213             ret_parsing ) );
       
  4214         User::Leave( ret_parsing );  
       
  4215         }
       
  4216     CleanupStack::PopAndDestroy( item );
       
  4217     
       
  4218     // ----------------------State name parsing
       
  4219     ret_parsing = section->GetLine( KStateName, tmp, ENoTag );
       
  4220     if( ret_parsing != KErrNone )
       
  4221         {
       
  4222         __TRACE( KError, 
       
  4223             ( _L("ReadRebootParams(): State name parsing fails with error: %d " ), 
       
  4224             ret_parsing ) );
       
  4225         User::Leave( ret_parsing );         
       
  4226         }
       
  4227 
       
  4228     iRebootParams->SetTestCaseStateL( tmp );
       
  4229 
       
  4230     __TRACE( KVerbose, ( _L("ReadRebootParams() ends" ) ) );
       
  4231 
       
  4232     CleanupStack::PopAndDestroy( section );
       
  4233     CleanupStack::PopAndDestroy( parser );
       
  4234 
       
  4235     // Delete file
       
  4236     RFs rf;
       
  4237     TInt retVal = rf.Connect();
       
  4238 	if( retVal != KErrNone )
       
  4239 		{
       
  4240 		User::Leave( retVal ); 
       
  4241 		}
       
  4242 		
       
  4243     TFileName file( *iRebootPath );
       
  4244     file.Append( *iRebootFilename );
       
  4245     rf.Delete( file );
       
  4246     rf.Close();
       
  4247     
       
  4248     return KErrNone;
       
  4249 
       
  4250     }
       
  4251 
       
  4252 /*
       
  4253 -------------------------------------------------------------------------------
       
  4254 
       
  4255     Class: CTestEngine
       
  4256 
       
  4257     Method: PauseAllTestCases
       
  4258 
       
  4259     Description: Pause all test case(s) which are/is running.
       
  4260 
       
  4261     Parameters: None
       
  4262 
       
  4263     Return Values: None
       
  4264 
       
  4265     Errors/Exceptions: None
       
  4266 
       
  4267     Status: Draft
       
  4268 
       
  4269 -------------------------------------------------------------------------------
       
  4270 */
       
  4271 void CTestEngine::PauseAllTestCases()
       
  4272     {
       
  4273     __TRACE( KVerbose, ( _L( "CTestEngine::PauseAllTestCases()" ) ) );
       
  4274 
       
  4275     TInt count( 0 );
       
  4276     count = iTestCaseArray.Count();
       
  4277 
       
  4278     for( TInt a = 0; a < count; a++ )
       
  4279         {
       
  4280          // Pause test case
       
  4281          iTestCaseArray[a]->Pause();
       
  4282         }
       
  4283 
       
  4284     }
       
  4285 
       
  4286 /*
       
  4287 -------------------------------------------------------------------------------
       
  4288 
       
  4289     Class: CTestEngine
       
  4290 
       
  4291     Method: FlushAtsLogger
       
  4292 
       
  4293     Description: Flush ATS logger's
       
  4294 
       
  4295     Parameters: None
       
  4296 
       
  4297     Return Values: None
       
  4298 
       
  4299     Errors/Exceptions: None
       
  4300 
       
  4301     Status: Draft
       
  4302 
       
  4303 -------------------------------------------------------------------------------
       
  4304 */
       
  4305 void CTestEngine::FlushAtsLogger()
       
  4306     {
       
  4307     __TRACE( KVerbose, ( _L( "CTestEngine::FlushAtsLogger()" ) ) );
       
  4308 
       
  4309     TInt count( 0 );
       
  4310     count = iModules.Count();
       
  4311 
       
  4312     for( TInt a = 0; a < count; a++ )
       
  4313         {
       
  4314          // Pause test case
       
  4315          iModules[a]->AtsLogger().SaveForRebootL();
       
  4316         }
       
  4317 
       
  4318     }
       
  4319 
       
  4320 /*
       
  4321 -------------------------------------------------------------------------------
       
  4322 
       
  4323     Class: CTestEngine
       
  4324 
       
  4325     Method: GetDeviceResetDllName
       
  4326 
       
  4327     Description: Get device reset module's DLL name.
       
  4328 
       
  4329     Parameters: None
       
  4330 
       
  4331     Return Values: TPtrC
       
  4332 
       
  4333     Errors/Exceptions: None
       
  4334 
       
  4335     Status: Draft
       
  4336 
       
  4337 -------------------------------------------------------------------------------
       
  4338 */
       
  4339 TPtrC CTestEngine::GetDeviceResetDllName()
       
  4340     {
       
  4341     __TRACE( KVerbose, ( _L( "CTestEngine::GetDeviceResetDllName()" ) ) );
       
  4342 
       
  4343     return iDeviceResetDllName->Des();
       
  4344 
       
  4345     }
       
  4346 
       
  4347 /*
       
  4348 -------------------------------------------------------------------------------
       
  4349 
       
  4350     Class: CTestEngine
       
  4351 
       
  4352     Method: EnableStifMeasurement
       
  4353 
       
  4354     Description: Set measurements related information, enable measurement.
       
  4355 
       
  4356     Parameters: const TName& aInfoType: in: Enabled measurement type
       
  4357 
       
  4358     Return Values: TInt: Symbian error code
       
  4359 
       
  4360     Errors/Exceptions: None
       
  4361 
       
  4362     Status: Approved
       
  4363 
       
  4364 -------------------------------------------------------------------------------
       
  4365 */
       
  4366 TInt CTestEngine::EnableStifMeasurement( const TDesC& aInfoType )
       
  4367     {
       
  4368     __TRACE( KInit, ( _L( "Measurement [%S] enabled" ), &aInfoType ) );
       
  4369 
       
  4370     if( aInfoType == KStifMeasurement01 )
       
  4371         {
       
  4372         iDisableMeasurement &= ~EMeasurement01;
       
  4373         }
       
  4374     else if( aInfoType == KStifMeasurement02 )
       
  4375         {
       
  4376         iDisableMeasurement &= ~EMeasurement02;
       
  4377         }
       
  4378     else if( aInfoType == KStifMeasurement03 )
       
  4379         {
       
  4380         iDisableMeasurement &= ~EMeasurement03;
       
  4381         }
       
  4382     else if( aInfoType == KStifMeasurement04 )
       
  4383         {
       
  4384         iDisableMeasurement &= ~EMeasurement04;
       
  4385         }
       
  4386     else if( aInfoType == KStifMeasurement05 )
       
  4387         {
       
  4388         iDisableMeasurement &= ~EMeasurement05;
       
  4389         }
       
  4390     else if( aInfoType == KStifMeasurementBappea )
       
  4391         {
       
  4392         iDisableMeasurement &= ~EBappea;
       
  4393         }
       
  4394     else if( aInfoType == KStifMeasurementDisableAll )
       
  4395         {
       
  4396         __TRACE( KInit, ( _L( "All measurements are disabled" ) ) );
       
  4397         iDisableMeasurement &= EDisableAll; // Does change anything !!!
       
  4398         }
       
  4399     else if( aInfoType ==  KStifMeasurementEnableAll )
       
  4400         {
       
  4401         __TRACE( KInit, ( _L( "All measurements types are enabled" ) ) );
       
  4402         iDisableMeasurement &= EEnableAll;
       
  4403         }
       
  4404     else
       
  4405         {
       
  4406         __TRACE( KInit, ( _L( "Measurement [%S] not recognized" ), &aInfoType ) );
       
  4407         return KErrArgument;
       
  4408         }
       
  4409 
       
  4410     return KErrNone;
       
  4411 
       
  4412     }
       
  4413 
       
  4414 /*
       
  4415 -------------------------------------------------------------------------------
       
  4416 
       
  4417     Class: CTestEngine
       
  4418 
       
  4419     Method: DisableStifMeasurement
       
  4420 
       
  4421     Description: Set measurements related information, disable measurement.
       
  4422 
       
  4423     Parameters: const TName& aInfoType: in: Disabled measurement type 
       
  4424 
       
  4425     Return Values: TInt: Symbian error code
       
  4426 
       
  4427     Errors/Exceptions: None
       
  4428 
       
  4429     Status: Approved
       
  4430 
       
  4431 -------------------------------------------------------------------------------
       
  4432 */
       
  4433 TInt CTestEngine::DisableStifMeasurement( const TDesC& aInfoType )
       
  4434     {
       
  4435     __TRACE( KInit, ( _L( "Measurement [%S] disabled" ), &aInfoType ) );
       
  4436 
       
  4437     if( aInfoType == KStifMeasurement01 )
       
  4438         {
       
  4439         iDisableMeasurement |=  EMeasurement01;
       
  4440         }
       
  4441     else if( aInfoType ==  KStifMeasurement02 )
       
  4442         {
       
  4443         iDisableMeasurement |=  EMeasurement02;
       
  4444         }
       
  4445     else if( aInfoType ==  KStifMeasurement03 )
       
  4446         {
       
  4447         iDisableMeasurement |= EMeasurement03;
       
  4448         }
       
  4449     else if( aInfoType ==  KStifMeasurement04 )
       
  4450         {
       
  4451         iDisableMeasurement |=  EMeasurement04;
       
  4452         }
       
  4453     else if( aInfoType ==  KStifMeasurement05 )
       
  4454         {
       
  4455         iDisableMeasurement |=  EMeasurement05;
       
  4456         }
       
  4457     else if( aInfoType ==  KStifMeasurementBappea )
       
  4458         {
       
  4459         iDisableMeasurement |=  EBappea;
       
  4460         }
       
  4461     else if( aInfoType ==  KStifMeasurementDisableAll )
       
  4462         {
       
  4463         __TRACE( KInit, ( _L( "All measurements are disabled" ) ) );
       
  4464         iDisableMeasurement |=  EDisableAll;
       
  4465         }
       
  4466     else if( aInfoType ==  KStifMeasurementEnableAll )
       
  4467         {
       
  4468         __TRACE( KInit, ( _L( "All measurements types are enabled" ) ) );
       
  4469         iDisableMeasurement |=  EEnableAll; // Does change anything !!!
       
  4470         }
       
  4471     // This option can be defined in TestFramework.ini file
       
  4472     else if( aInfoType ==  KStifMeasurementDisableNone )
       
  4473         {
       
  4474         __TRACE( KInit, ( _L( "All measurements types are enabled" ) ) );
       
  4475         iDisableMeasurement =  EEnableAll; // Sets to 0
       
  4476         }
       
  4477     else
       
  4478         {
       
  4479         __TRACE( KInit, ( _L( "Measurement [%S] not recognized" ), &aInfoType ) );
       
  4480         return KErrArgument;
       
  4481         }
       
  4482 
       
  4483     return KErrNone;
       
  4484 
       
  4485     }
       
  4486 
       
  4487 /*
       
  4488 -------------------------------------------------------------------------------
       
  4489 
       
  4490     Class: CTestEngine
       
  4491 
       
  4492     Method: StifMeasurement
       
  4493 
       
  4494     Description: Get measurements related information. Returns is measurement
       
  4495                  disable.
       
  4496 
       
  4497     Parameters: None
       
  4498 
       
  4499     Return Values: TInt: Indication what measurement types is/are disabled.
       
  4500 
       
  4501     Errors/Exceptions: None
       
  4502 
       
  4503     Status: Approved
       
  4504 
       
  4505 -------------------------------------------------------------------------------
       
  4506 */
       
  4507 TInt CTestEngine::StifMeasurement()
       
  4508     {
       
  4509     return iDisableMeasurement;
       
  4510 
       
  4511     }
       
  4512 /*
       
  4513 -------------------------------------------------------------------------------
       
  4514 
       
  4515     Class: CTestEngine
       
  4516 
       
  4517     Method: TestModuleCrash
       
  4518 
       
  4519     Description: This method is called only when test module crashed 
       
  4520                  with KErrServerTerminated (-15). 
       
  4521                  Clones new TestModuleController:
       
  4522                  - Find crashed testmodulecontroller
       
  4523                  - Creates new copy of that testmodulecontroller
       
  4524                  - Replaces old crashed testmodulecontroller with this new one
       
  4525 
       
  4526     Parameters: CTestModuleController* aTestModuleController: in: TestModuleController
       
  4527     Return Values: None
       
  4528 
       
  4529     Errors/Exceptions: Leaves if error happens when adding clone to the list
       
  4530 
       
  4531     Status: Approved
       
  4532 
       
  4533 -------------------------------------------------------------------------------
       
  4534 */
       
  4535 void CTestEngine::TestModuleCrash(CTestModuleController* aTestModuleController)
       
  4536     {
       
  4537     TName crashModuleName = aTestModuleController->ModuleName(KNullDesC);
       
  4538     __TRACE(KInit, (_L("Handling crashed test module [%S]"), &crashModuleName));
       
  4539     TBool isTestScripter(EFalse);
       
  4540     
       
  4541     // Find crashed test module controller
       
  4542     CTestScripterController* testScripterController = aTestModuleController->iTestScripterController;
       
  4543     if(testScripterController)
       
  4544         {
       
  4545         isTestScripter = ETrue;
       
  4546         }
       
  4547 
       
  4548     // If UITestingSupport or SeparateProcesses is enabled, there is no need
       
  4549     // to create clone of Test Module Controller, because it will be created
       
  4550     // automatically when needed.
       
  4551     if(iUITestingSupport && crashModuleName.Find(KTestScripterName) == 0 
       
  4552        || iSeparateProcesses
       
  4553        || (crashModuleName.Find(KPythonScripter) == 0)
       
  4554       )
       
  4555         {
       
  4556         __TRACE(KInit, (_L("Handling crashed test module with enabled UITestingSupport or SeparateProcesses is not needed")));
       
  4557         aTestModuleController->iTestModuleCrashDetected = ETrue;
       
  4558         return;
       
  4559         }
       
  4560         
       
  4561     // Clone crashed module
       
  4562     TBool afterReset = EFalse;
       
  4563     if(iRebootParams && iRebootParams->iTestModule == crashModuleName)
       
  4564         {
       
  4565         afterReset = ETrue;
       
  4566         }  
       
  4567     
       
  4568     CTestModuleController* clone;    
       
  4569     clone = aTestModuleController->CloneL(aTestModuleController, afterReset, testScripterController);  
       
  4570     
       
  4571     // Replaces crashed testmodulecontroller with this new one    
       
  4572     // Note: Old Testmodulecontroller is deleted in CTestModuleController::CaseFinished 
       
  4573     //       that is called from  CTestCase::~CTestCase() 
       
  4574 
       
  4575     TInt index = KErrNotFound;
       
  4576     if(isTestScripter)
       
  4577         {
       
  4578         index = testScripterController->iTestScripter.Find(aTestModuleController);
       
  4579         __TRACE(KInit, (_L("Crashed module index [%d]"), index));
       
  4580         if(index != KErrNotFound)
       
  4581             {
       
  4582             testScripterController->iTestScripter.Remove(index);
       
  4583             }
       
  4584         testScripterController->iTestScripter.Append(clone);            
       
  4585         }
       
  4586     else
       
  4587         {
       
  4588         index = iModules.Find(aTestModuleController);
       
  4589         __TRACE(KInit, (_L("Crashed module index [%d]"), index));
       
  4590         if(index != KErrNotFound)
       
  4591             {
       
  4592             iModules.Remove(index);
       
  4593             }
       
  4594         iModules.Append(clone);
       
  4595         }
       
  4596     __TRACE(KInit, (_L("End of handling crashed test module")));
       
  4597     }
       
  4598 
       
  4599 /*
       
  4600 -------------------------------------------------------------------------------
       
  4601 
       
  4602     Class: CTestEngine
       
  4603 
       
  4604     Method: ExecuteCommandL
       
  4605 
       
  4606     Description: Executes command received from test case.
       
  4607                  The method was created to allow test case to kill itself.
       
  4608 
       
  4609     Parameters: aTestCaseHandle: handler to test case
       
  4610     Return Values: None
       
  4611 
       
  4612     Errors/Exceptions: Leaves if error happens when adding clone to the list
       
  4613 
       
  4614     Status: Approved
       
  4615 
       
  4616 -------------------------------------------------------------------------------
       
  4617 */
       
  4618 void CTestEngine::ExecuteCommandL(TCommand aCommand, TDesC8& aParamsPckg)
       
  4619     {
       
  4620     TInt testCaseHandle = 0;
       
  4621     // Get params
       
  4622     switch(aCommand)
       
  4623         {
       
  4624         case EStopExecution:
       
  4625             {
       
  4626             //Unpack received parameters
       
  4627             TStopExecutionCommandParams par;
       
  4628             TStopExecutionCommandParamsPckg parPack(par);
       
  4629             parPack.Copy(aParamsPckg);
       
  4630 
       
  4631             __TRACE(KInit, (_L("CTestEngine::ExecuteCommandL received command [%d] type [%d] code [%d] test handle [%d]"), TInt(aCommand), TInt(par.iType), TInt(par.iCode), par.iTestCaseHandle));
       
  4632 
       
  4633             //Get test case handle
       
  4634             testCaseHandle = par.iTestCaseHandle;
       
  4635 
       
  4636             break;
       
  4637             }
       
  4638         case ESendTestModuleVersion:
       
  4639         	{
       
  4640         	TSendTestModuleVesionCommandParams par;
       
  4641         	TSendTestModuleVesionCommandParamsPckg parPack(par);
       
  4642         	parPack.Copy(aParamsPckg);
       
  4643 
       
  4644         	TTestModuleVersionInfo testModuleVersionInfo;
       
  4645         	testModuleVersionInfo.iMajor = par.iMajor;
       
  4646         	testModuleVersionInfo.iMinor = par.iMinor;
       
  4647         	testModuleVersionInfo.iBuild = par.iBuild;
       
  4648         	testModuleVersionInfo.iTestModuleName = par.iTestModuleName;
       
  4649         	if(iTestReport)
       
  4650         	    {
       
  4651         	    iTestReport->AddTestModuleVersion(testModuleVersionInfo);
       
  4652         	    }
       
  4653         	
       
  4654         	return;
       
  4655         	}
       
  4656         default:
       
  4657             __TRACE(KError, (_L("CTestEngine::ExecuteCommandL Unknown command [%d]"), TInt(aCommand)));
       
  4658             return;
       
  4659         }
       
  4660 
       
  4661     // Get test case from container
       
  4662     CTestCase* testCase = (CTestCase*)iTestCases->At(testCaseHandle);
       
  4663 
       
  4664     // Log some info if invalid handle
       
  4665     if(testCase == NULL)
       
  4666         {
       
  4667         __TRACE(KInit, ( _L( "CTestEngine::ExecuteCommandL - invalid handle. Unable to get test case to execute command [%d]"), TInt(aCommand)));
       
  4668         return;
       
  4669         }
       
  4670 
       
  4671     testCase->ExecuteCommandL(aCommand, aParamsPckg);
       
  4672 
       
  4673     }
       
  4674 
       
  4675 /*
       
  4676 -------------------------------------------------------------------------------
       
  4677 
       
  4678     Class: CTestEngine
       
  4679 
       
  4680     Method: GetIndexForNewTestModuleController
       
  4681 
       
  4682     Description: Returns new index for test module controller.
       
  4683                  This number is appended to module controller name.
       
  4684                  This method is used when option to run every test case in 
       
  4685                  separate process is set to on.
       
  4686 
       
  4687     Parameters: aTestCaseHandle: handler to test case
       
  4688     Return Values: None
       
  4689 
       
  4690     Errors/Exceptions: Leaves if error happens when adding clone to the list
       
  4691 
       
  4692     Status: Approved
       
  4693 
       
  4694 -------------------------------------------------------------------------------
       
  4695 */
       
  4696 TInt CTestEngine::GetIndexForNewTestModuleController(void)
       
  4697     {
       
  4698     return iIndexTestModuleControllers++;
       
  4699     }
       
  4700 
       
  4701 /*
       
  4702 -------------------------------------------------------------------------------
       
  4703 
       
  4704     Class: CTestEngine
       
  4705 
       
  4706     Method: AddTestCaseToTestReport
       
  4707 
       
  4708     Description: Get parameters from message and add test case to test report.
       
  4709 
       
  4710     Parameters: aMessage: message
       
  4711     Return Values: error id
       
  4712 
       
  4713     Status: Approved
       
  4714 
       
  4715 -------------------------------------------------------------------------------
       
  4716 */
       
  4717 TInt CTestEngine::AddTestCaseToTestReport(const RMessage2& aMessage)
       
  4718     {
       
  4719     if(iTestReport)
       
  4720         {
       
  4721         // Read test data
       
  4722         TTestInfo testInfo;
       
  4723         TTestInfoPckg testInfoPckg(testInfo);
       
  4724     
       
  4725         TFullTestResult fullTestResult;
       
  4726         TFullTestResultPckg fullTestResultPckg(fullTestResult);
       
  4727         
       
  4728         TRAPD(err, aMessage.ReadL(0, testInfoPckg));
       
  4729         if(err)
       
  4730             {
       
  4731             __TRACE(KError, (_L("Leave when reading TTestInfo in AddTestCaseToTestReport [%d]"), err));
       
  4732             return err;
       
  4733             }
       
  4734     
       
  4735         TRAP(err, aMessage.ReadL(1, fullTestResultPckg));
       
  4736         if(err)
       
  4737             {
       
  4738             __TRACE(KError, (_L("Leave when reading TFullTestResult in AddTestCaseToTestReport [%d]"), err));
       
  4739             return err;
       
  4740             }
       
  4741             
       
  4742         TRAP(err, iTestReport->AddTestCaseResultL(testInfo, fullTestResult, aMessage.Int2()));
       
  4743         if(err)
       
  4744             {
       
  4745             __TRACE(KError, (_L("Leave from test report in AddTestCaseToTestReport [%d]"), err));
       
  4746             return err;
       
  4747             }
       
  4748         }
       
  4749     else
       
  4750         {
       
  4751         __TRACE(KError, (_L("TestReport not initialized in AddTestCaseToTestReport")));
       
  4752         return KErrNotReady;
       
  4753         }
       
  4754 
       
  4755     return KErrNone;
       
  4756     }
       
  4757 
       
  4758 /*
       
  4759 -------------------------------------------------------------------------------
       
  4760 
       
  4761     DESCRIPTION
       
  4762 
       
  4763     This module contains implementation of CTestEngineSubSession class member functions.
       
  4764 
       
  4765 -------------------------------------------------------------------------------
       
  4766 */
       
  4767 
       
  4768 // ================= MEMBER FUNCTIONS =========================================
       
  4769 
       
  4770 /*
       
  4771 -------------------------------------------------------------------------------
       
  4772 
       
  4773     Class: CTestEngineSubSession
       
  4774 
       
  4775     Method: CTestEngineSubSession
       
  4776 
       
  4777     Description: Default constructor
       
  4778 
       
  4779     C++ default constructor can NOT contain any code, that
       
  4780     might leave.
       
  4781     
       
  4782     Parameters: CTestEngine* aEngine: in: Pointer to Test Engine
       
  4783 
       
  4784     Return Values: None
       
  4785 
       
  4786     Errors/Exceptions: None
       
  4787 
       
  4788     Status: Proposal
       
  4789 
       
  4790 -------------------------------------------------------------------------------
       
  4791 */
       
  4792 CTestEngineSubSession::CTestEngineSubSession( CTestEngine* aEngine ) :
       
  4793     iTestEngine( aEngine )
       
  4794     {
       
  4795     }
       
  4796 
       
  4797 /*
       
  4798 -------------------------------------------------------------------------------
       
  4799 
       
  4800     Class: CTestEngineSubSession
       
  4801 
       
  4802     Method: ConstructL
       
  4803 
       
  4804     Description: Symbian OS second phase constructor
       
  4805 
       
  4806     Symbian OS default constructor can leave.
       
  4807 
       
  4808     Parameters: None
       
  4809 
       
  4810     Return Values: None
       
  4811 
       
  4812     Errors/Exceptions: Leaves if some of called leaving methods leaves
       
  4813 
       
  4814     Status: Approved
       
  4815 
       
  4816 -------------------------------------------------------------------------------
       
  4817 */
       
  4818 void CTestEngineSubSession::ConstructL()
       
  4819     {
       
  4820     }
       
  4821 
       
  4822 /*
       
  4823 -------------------------------------------------------------------------------
       
  4824 
       
  4825     Class: CTestEngineSubSession
       
  4826 
       
  4827     Method: NewL
       
  4828 
       
  4829     Description: Two-phased constructor.
       
  4830 
       
  4831     Parameters: CTestEngine* aEngine: in: Pointer to Test Engine
       
  4832 
       
  4833     Return Values: CTestEngineSubSession* : pointer to created CTestEngineSubSession object
       
  4834 
       
  4835     Errors/Exceptions: Leaves if ConstructL leaves
       
  4836 
       
  4837     Status: Approved
       
  4838 
       
  4839 -------------------------------------------------------------------------------
       
  4840 */
       
  4841 CTestEngineSubSession* CTestEngineSubSession::NewL( CTestEngine* aEngine )    
       
  4842     {
       
  4843     CTestEngineSubSession* self = new ( ELeave ) CTestEngineSubSession( aEngine );
       
  4844     CleanupClosePushL( *self );
       
  4845     self->ConstructL();
       
  4846     CleanupStack::Pop();
       
  4847     return self;
       
  4848     }
       
  4849 
       
  4850 /*
       
  4851 -------------------------------------------------------------------------------
       
  4852 
       
  4853     Class: CTestEngineSubSession
       
  4854 
       
  4855     Method: ~CTestEngineSubSession
       
  4856 
       
  4857     Description: Destructor
       
  4858 
       
  4859     Parameters: None
       
  4860 
       
  4861     Return Values: None
       
  4862 
       
  4863     Errors/Exceptions: None
       
  4864 
       
  4865     Status: Approved
       
  4866 
       
  4867 -------------------------------------------------------------------------------
       
  4868 */
       
  4869 CTestEngineSubSession::~CTestEngineSubSession()
       
  4870     {
       
  4871     }
       
  4872 
       
  4873 
       
  4874 /*
       
  4875 -------------------------------------------------------------------------------
       
  4876 
       
  4877     DESCRIPTION
       
  4878 
       
  4879     This module contains implementation of CTestCase class member functions.
       
  4880 
       
  4881 -------------------------------------------------------------------------------
       
  4882 */
       
  4883 
       
  4884 // ================= MEMBER FUNCTIONS =========================================
       
  4885 
       
  4886 /*
       
  4887 -------------------------------------------------------------------------------
       
  4888 
       
  4889     Class: CTestCase
       
  4890 
       
  4891     Method: CTestCase
       
  4892 
       
  4893     Description: Default constructor
       
  4894 
       
  4895     C++ default constructor can NOT contain any code, that
       
  4896     might leave.
       
  4897     
       
  4898     Parameters: CTestEngine* aEngine: in: Pointer to Test Engine
       
  4899                 CTestModuleController* aModuleController: in: Pointer to 
       
  4900                   Module Controller
       
  4901                 TTestInfo& aTestInfo: in: Test info for this test case
       
  4902                 CTestModuleController* aRealModuleController: in: Pointer to
       
  4903                   module controller used inside in scripter controller
       
  4904 
       
  4905     Return Values: None
       
  4906 
       
  4907     Errors/Exceptions: None
       
  4908 
       
  4909     Status: Proposal
       
  4910 
       
  4911 -------------------------------------------------------------------------------
       
  4912 */
       
  4913 CTestCase::CTestCase( CTestEngine* aEngine,
       
  4914                      CTestModuleController* aModuleController,
       
  4915                      TTestInfo& aTestInfo,
       
  4916                      CTestModuleController* aRealModuleController ) :
       
  4917     iTestEngine( aEngine ),
       
  4918     iTestModule( aModuleController ),
       
  4919     iRealModuleController (aRealModuleController)
       
  4920     {
       
  4921     
       
  4922     // This method must be called to find out how
       
  4923     // many testcases are currently ongoing by increasing iTestCaseCounter. 
       
  4924     // This is a part of the implementation for 
       
  4925     //  supporting test module crashing with -15
       
  4926     iTestModule->CaseCreated();  
       
  4927 
       
  4928     // Store handle to RTestServer
       
  4929     //If test scripter is used (it uses internally module controllers)
       
  4930     //then use it (real module controller). 
       
  4931     if(iRealModuleController)
       
  4932         {
       
  4933         iTestServer = iRealModuleController->Server(aTestInfo); 
       
  4934         }
       
  4935     else
       
  4936         {
       
  4937         iTestServer = iTestModule->Server( aTestInfo );
       
  4938         }
       
  4939 
       
  4940     //If real test module controller is provided, increase test case count
       
  4941     if(iRealModuleController)
       
  4942         {
       
  4943         iRealModuleController->CaseCreated();
       
  4944         }
       
  4945     }
       
  4946 
       
  4947 /*
       
  4948 -------------------------------------------------------------------------------
       
  4949 
       
  4950     Class: CTestCase
       
  4951 
       
  4952     Method: ConstructL
       
  4953 
       
  4954     Description: Symbian OS second phase constructor
       
  4955 
       
  4956     Symbian OS default constructor can leave.
       
  4957 
       
  4958     Parameters: CTestReport* aTestReport: in: Pointer to Test Report
       
  4959                 TTestInfo& aTestInfo: in: Test Info for this test case
       
  4960 
       
  4961     Return Values: None
       
  4962 
       
  4963     Errors/Exceptions: Leaves if RTestExecution::Open returns error
       
  4964                        Leaves if some of called leaving methods leaves
       
  4965 
       
  4966     Status: Approved
       
  4967 
       
  4968 -------------------------------------------------------------------------------
       
  4969 */
       
  4970 void CTestCase::ConstructL( CTestReport* aTestReport,
       
  4971                            TTestInfo& aTestInfo )
       
  4972     {
       
  4973     __TRACE( KVerbose, ( _L( "CTestCase::ConstructL" ) ) );
       
  4974 
       
  4975     // Open handle to RTestExecution
       
  4976     User::LeaveIfError( iTestExecution.Open( iTestServer,
       
  4977         aTestInfo.iTestCaseInfo.iCaseNumber, aTestInfo.iConfig ) );
       
  4978 
       
  4979     // Make new test case runner
       
  4980     iTestCaseController = CTestCaseController::NewL( iTestEngine,
       
  4981         aTestReport, iTestModule->AtsLogger(), iTestExecution, aTestInfo );
       
  4982 
       
  4983     // Make new test case printer
       
  4984     iTestCasePrint = CTestProgressNotifier::NewL( iTestEngine,
       
  4985                                                   iTestExecution );
       
  4986 
       
  4987     iTestCaseEvent = CTestEventNotifier::NewL( iTestEngine, iTestExecution );
       
  4988 
       
  4989     iTestCaseRemoteCmd = CTestRemoteCmdNotifier::NewL( iTestEngine,
       
  4990                                                     iTestExecution,
       
  4991                                                     iTestCaseController,
       
  4992                                                     iTestModule->AtsLogger() );
       
  4993 
       
  4994     iTestCaseCommand = CTestCommandNotifier::NewL(iTestEngine, iTestExecution);
       
  4995     }
       
  4996 
       
  4997 /*
       
  4998 -------------------------------------------------------------------------------
       
  4999 
       
  5000     Class: CTestCase
       
  5001 
       
  5002     Method: NewL
       
  5003 
       
  5004     Description: Two-phased constructor.
       
  5005 
       
  5006     Parameters: CTestEngine* aEngine: in: Pointer to Test Engine
       
  5007                 CTestModuleController* aModuleController: in: Pointer to
       
  5008                  Module Controller
       
  5009                 CTestReport* aTestReport: in: Pointer to Test Report
       
  5010                 TTestInfo& aTestInfo: in: Test Info for this test case
       
  5011 
       
  5012     Return Values: CTestCase* : pointer to created CTestCase object
       
  5013 
       
  5014     Errors/Exceptions: Leaves if ConstructL leaves
       
  5015 
       
  5016     Status: Approved
       
  5017 
       
  5018 -------------------------------------------------------------------------------
       
  5019 */
       
  5020 CTestCase* CTestCase::NewL( CTestEngine* aEngine,
       
  5021             CTestModuleController* aModuleController,
       
  5022             CTestReport* aTestReport,
       
  5023             TTestInfo& aTestInfo,
       
  5024             CTestModuleController* aRealModuleController )    
       
  5025     {
       
  5026     CTestCase* self = new ( ELeave ) CTestCase( aEngine, aModuleController, aTestInfo, aRealModuleController );
       
  5027     CleanupClosePushL( *self );
       
  5028     self->ConstructL( aTestReport, aTestInfo );
       
  5029     CleanupStack::Pop();
       
  5030     return self;
       
  5031 
       
  5032     }
       
  5033 
       
  5034 /*
       
  5035 -------------------------------------------------------------------------------
       
  5036 
       
  5037     Class: CTestCase
       
  5038 
       
  5039     Method: ~CTestCase
       
  5040 
       
  5041     Description: Destructor
       
  5042 
       
  5043     Parameters: None
       
  5044 
       
  5045     Return Values: None
       
  5046 
       
  5047     Errors/Exceptions: None
       
  5048 
       
  5049     Status: Approved
       
  5050 
       
  5051 -------------------------------------------------------------------------------
       
  5052 */
       
  5053 CTestCase::~CTestCase()
       
  5054     {
       
  5055     CloseTestCase();
       
  5056     
       
  5057     // This added method call is a part of the implementation for 
       
  5058     // supporting test module crashing with -15.
       
  5059     // It checks that can old Testmodulecontroller be deletd or not 
       
  5060 	if( iTestModule != NULL )
       
  5061 		{
       
  5062 		iTestModule->CaseFinished();    
       
  5063 		}
       
  5064 	
       
  5065     //If real test module controller is provided, decrease test case count
       
  5066     if( iRealModuleController != NULL )
       
  5067         {
       
  5068         iRealModuleController->CaseFinished();
       
  5069         }
       
  5070     }
       
  5071 
       
  5072 /*
       
  5073 -------------------------------------------------------------------------------
       
  5074 
       
  5075     Class: CTestCase
       
  5076 
       
  5077     Method: CloseTestCase
       
  5078 
       
  5079     Description: Close session
       
  5080 
       
  5081     Parameters: None
       
  5082 
       
  5083     Return Values: None
       
  5084 
       
  5085     Errors/Exceptions: None
       
  5086 
       
  5087     Status: Approved
       
  5088 
       
  5089 -------------------------------------------------------------------------------
       
  5090 */
       
  5091 void CTestCase::CloseTestCase()
       
  5092     {
       
  5093     __TRACE( KVerbose, ( _L( "CTestCase::CloseTestCase" ) ) );
       
  5094 
       
  5095     // Free allocated resources
       
  5096     delete iTestCaseController;
       
  5097     iTestCaseController = NULL;
       
  5098     delete iTestCasePrint;
       
  5099     iTestCasePrint = NULL;
       
  5100     delete iTestCaseRemoteCmd;
       
  5101     iTestCaseRemoteCmd = NULL;
       
  5102 
       
  5103     delete iTestCaseEvent;
       
  5104     iTestCaseEvent = NULL;
       
  5105 
       
  5106     delete iTestCaseCommand;
       
  5107     iTestCaseCommand = NULL;
       
  5108 
       
  5109     iTestExecution.Close();
       
  5110 
       
  5111     }
       
  5112 
       
  5113 /*
       
  5114 -------------------------------------------------------------------------------
       
  5115 
       
  5116     Class: CTestCase
       
  5117 
       
  5118     Method: RunTestCaseL
       
  5119 
       
  5120     Description: Enumerates test cases
       
  5121 
       
  5122     Parameters: const RMessage& aMessage: in: Server Message
       
  5123 
       
  5124     Return Values: None
       
  5125 
       
  5126     Errors/Exceptions: Leaves if some of called leaving methods leaves
       
  5127 
       
  5128     Status: Approved
       
  5129 
       
  5130 -------------------------------------------------------------------------------
       
  5131 */
       
  5132 void CTestCase::RunTestCaseL( const RMessage2& aMessage )
       
  5133     {
       
  5134     __TRACE( KVerbose, ( _L( "CTestCase::RunTestCaseL" ) ) );
       
  5135     // Start active objects for running test case
       
  5136     iTestCaseController->StartL( aMessage );
       
  5137     iTestCaseEvent->Start();
       
  5138     iTestCaseCommand->Start();
       
  5139     }
       
  5140 
       
  5141 /*
       
  5142 -------------------------------------------------------------------------------
       
  5143 
       
  5144     Class: CTestCase
       
  5145 
       
  5146     Method: Pause
       
  5147 
       
  5148     Description: Suspend the test case execution
       
  5149 
       
  5150     Parameters: None
       
  5151 
       
  5152     Return Values: TInt: Return value from RTestExecution::Pause
       
  5153 
       
  5154     Errors/Exceptions: None
       
  5155 
       
  5156     Status: Approved
       
  5157 
       
  5158 -------------------------------------------------------------------------------
       
  5159 */
       
  5160 TInt CTestCase::Pause()
       
  5161     {
       
  5162     __TRACE( KVerbose, ( _L( "CTestCase::Pause" ) ) );
       
  5163 
       
  5164     return iTestExecution.Pause();
       
  5165 
       
  5166     }
       
  5167 
       
  5168 /*
       
  5169 -------------------------------------------------------------------------------
       
  5170 
       
  5171     Class: CTestCase
       
  5172 
       
  5173     Method: Resume
       
  5174 
       
  5175     Description: Resume the suspended test case execution
       
  5176 
       
  5177     Parameters: None
       
  5178 
       
  5179     Return Values: TInt: Return value from RTestExecution::Resume
       
  5180 
       
  5181     Errors/Exceptions: None
       
  5182 
       
  5183     Status: Approved
       
  5184 
       
  5185 -------------------------------------------------------------------------------
       
  5186 */
       
  5187 TInt CTestCase::Resume()
       
  5188     {
       
  5189     __TRACE( KVerbose, ( _L( "CTestCase::Resume" ) ) );
       
  5190 
       
  5191     return iTestExecution.Resume();
       
  5192 
       
  5193     }
       
  5194 
       
  5195 /*
       
  5196 -------------------------------------------------------------------------------
       
  5197 
       
  5198     Class: CTestCase
       
  5199 
       
  5200     Method: NotifyProgressL
       
  5201 
       
  5202     Description: Notifies progresses from Test Module
       
  5203 
       
  5204     Parameters: const RMessage& aMessage: in: Server message
       
  5205 
       
  5206     Return Values: None
       
  5207 
       
  5208     Errors/Exceptions: Leaves if called StartL method leaves
       
  5209 
       
  5210     Status: Approved
       
  5211 
       
  5212 -------------------------------------------------------------------------------
       
  5213 */
       
  5214 void CTestCase::NotifyProgressL( const RMessage2& aMessage )
       
  5215     {
       
  5216     __TRACE( KVerbose, ( _L( "CTestCase::NotifyProgressL" ) ) );
       
  5217     iTestCasePrint->StartL( aMessage );
       
  5218 
       
  5219     }
       
  5220     
       
  5221 /*
       
  5222 -------------------------------------------------------------------------------
       
  5223 
       
  5224     Class: CTestCase
       
  5225 
       
  5226     Method: NotifyRemoteTypeL
       
  5227 
       
  5228     Description: Notifies remote commands from Test Module
       
  5229 
       
  5230     Parameters: const RMessage& aMessage: in: Server message
       
  5231 
       
  5232     Return Values: None
       
  5233 
       
  5234     Errors/Exceptions: Leaves if called StartL method leaves
       
  5235 
       
  5236     Status: Approved
       
  5237 
       
  5238 -------------------------------------------------------------------------------
       
  5239 */
       
  5240 void CTestCase::NotifyRemoteTypeL( const RMessage2& aMessage )
       
  5241     {
       
  5242     
       
  5243     __TRACE( KVerbose, ( _L( "CTestCase::NotifyRemoteTypeL" ) ) );
       
  5244     iTestCaseRemoteCmd->EnableReceive( aMessage );
       
  5245 
       
  5246     }
       
  5247 
       
  5248 /*
       
  5249 -------------------------------------------------------------------------------
       
  5250 
       
  5251     Class: CTestCase
       
  5252 
       
  5253     Method: NotifyRemoteMsgL
       
  5254 
       
  5255     Description: Notifies remote commands from Test Module
       
  5256 
       
  5257     Parameters: const RMessage& aMessage: in: Server message
       
  5258 
       
  5259     Return Values: None
       
  5260 
       
  5261     Errors/Exceptions: Leaves if called StartL method leaves
       
  5262 
       
  5263     Status: Approved
       
  5264 
       
  5265 -------------------------------------------------------------------------------
       
  5266 */
       
  5267 void CTestCase::NotifyRemoteMsgL( const RMessage2& aMessage )
       
  5268     {
       
  5269     
       
  5270     __TRACE( KVerbose, ( _L( "CTestCase::NotifyRemoteMsgL" ) ) );
       
  5271     switch( aMessage.Int1() )
       
  5272         {
       
  5273         case EStifCmdSend:
       
  5274             {
       
  5275             iTestCaseRemoteCmd->GetReceivedMsg( aMessage );
       
  5276             }
       
  5277             break;
       
  5278         case EStifCmdReceive:
       
  5279             {
       
  5280             TInt len = aMessage.Int2();
       
  5281             if( len <= 0 )
       
  5282                 {
       
  5283                 User::Leave( KErrGeneral );
       
  5284                 }
       
  5285             HBufC8* buf = HBufC8::NewLC( len );
       
  5286 
       
  5287             TPtr8 tmp = buf->Des();
       
  5288             aMessage.ReadL( 0, tmp );
       
  5289 
       
  5290             TInt ret = iTestExecution.ReadRemoteCmdInfo( tmp, EStifCmdReceive );
       
  5291 
       
  5292             CleanupStack::PopAndDestroy( buf );
       
  5293             
       
  5294             aMessage.Complete( ret );
       
  5295             }
       
  5296             break;
       
  5297         case EStifCmdRebootProceed:
       
  5298             {
       
  5299             TInt value = 0;
       
  5300             TPckg<TInt> tmp( value );
       
  5301             aMessage.ReadL( 0, tmp );
       
  5302 
       
  5303             TInt ret = iTestExecution.ReadRemoteCmdInfo( tmp, 
       
  5304                                                          EStifCmdRebootProceed,
       
  5305                                                          value );        
       
  5306             aMessage.Complete( ret );
       
  5307             }
       
  5308             break;
       
  5309         default:
       
  5310             {
       
  5311             User::Leave( KErrGeneral );
       
  5312             }  
       
  5313         }            
       
  5314     }
       
  5315 
       
  5316 /*
       
  5317 -------------------------------------------------------------------------------
       
  5318 
       
  5319     Class: CTestCase
       
  5320 
       
  5321     Method: CancelAsyncRequest
       
  5322 
       
  5323     Description: Asynchronous requests are canceled by this function.
       
  5324 
       
  5325     Parameters: const RMessage aMessage
       
  5326 
       
  5327     Return Values: None
       
  5328 
       
  5329     Errors/Exceptions: None
       
  5330 
       
  5331     Status: Approved
       
  5332 
       
  5333 -------------------------------------------------------------------------------
       
  5334 */
       
  5335 void CTestCase::CancelAsyncRequest( const RMessage2& aMessage )
       
  5336     {
       
  5337     switch ( aMessage.Int0() )
       
  5338         {
       
  5339         case ETestCaseRunTestCase:
       
  5340             {
       
  5341             iTestCaseController->Cancel();
       
  5342             iTestCaseEvent->Cancel();
       
  5343             break;
       
  5344             }
       
  5345         case ETestCaseNotifyProgress:
       
  5346             {
       
  5347             iTestCasePrint->Cancel();
       
  5348             break;
       
  5349             }
       
  5350         case ETestCaseNotifyRemoteType:
       
  5351             {
       
  5352             iTestCaseRemoteCmd->CancelReq();
       
  5353             break;
       
  5354             }
       
  5355         case ETestCaseNotifyCommand:
       
  5356             {
       
  5357             iTestCaseCommand->Cancel();
       
  5358             break;
       
  5359             }
       
  5360         default:
       
  5361             iTestEngine->PanicClient( EBadRequest, aMessage );
       
  5362             break;
       
  5363         }
       
  5364 
       
  5365     }
       
  5366 
       
  5367 /*
       
  5368 -------------------------------------------------------------------------------
       
  5369 
       
  5370     Class: CTestCase
       
  5371 
       
  5372     Method: ModuleName
       
  5373 
       
  5374     Description: Return the name of Test Module.
       
  5375 
       
  5376     Parameters: None
       
  5377 
       
  5378     Return Values: const TFileName& : Test Module owning this test case
       
  5379 
       
  5380     Errors/Exceptions: None
       
  5381 
       
  5382     Status: Approved
       
  5383 
       
  5384 -------------------------------------------------------------------------------
       
  5385 */
       
  5386 const TDesC& CTestCase::ModuleName()
       
  5387     {
       
  5388     return iTestModule->ModuleName( KNullDesC );
       
  5389 
       
  5390     }
       
  5391 
       
  5392 /*
       
  5393 -------------------------------------------------------------------------------
       
  5394 
       
  5395     Class: CTestCase
       
  5396 
       
  5397     Method: CtlEvent
       
  5398 
       
  5399     Description: Control events
       
  5400 
       
  5401     Parameters: const TEventIf& aEvent: in: Event
       
  5402                 TRequestStatus& aStatus: in: Request status
       
  5403 
       
  5404     Return Values: None
       
  5405 
       
  5406     Errors/Exceptions: None
       
  5407 
       
  5408     Status: Approved
       
  5409 
       
  5410 -------------------------------------------------------------------------------
       
  5411 */
       
  5412 void CTestCase::CtlEvent( const TEventIf& aEvent, TRequestStatus& aStatus )
       
  5413     {
       
  5414     __ASSERT_ALWAYS( iTestCaseEvent, User::Panic( _L( "TestEngine event panic" ), KErrArgument ) );
       
  5415         
       
  5416     iTestCaseEvent->CtlEvent( aEvent, aStatus );
       
  5417     }
       
  5418 
       
  5419 /*
       
  5420 -------------------------------------------------------------------------------
       
  5421 
       
  5422     Class: CTestCase
       
  5423 
       
  5424     Method: CheckCtlEvent
       
  5425 
       
  5426     Description: Check if CtlEvent should be called
       
  5427 
       
  5428     Parameters: const TEventIf& aEvent: in: Event
       
  5429 
       
  5430     Return Values: None
       
  5431 
       
  5432     Errors/Exceptions: None
       
  5433 
       
  5434     Status: Approved
       
  5435 
       
  5436 -------------------------------------------------------------------------------
       
  5437 */
       
  5438 TBool CTestCase::CheckCtlEvent( const TEventIf& aEvent )
       
  5439     {
       
  5440     return iTestCaseEvent->CheckCtlEvent( aEvent );
       
  5441     }
       
  5442 
       
  5443 
       
  5444 /*
       
  5445 -------------------------------------------------------------------------------
       
  5446 
       
  5447     Class: CTestCase
       
  5448 
       
  5449     Method: Logger
       
  5450 
       
  5451     Description: Return the pointer to Logger.
       
  5452 
       
  5453     Parameters: None
       
  5454 
       
  5455     Return Values: CStifLogger*: Pointer to StifLogger
       
  5456 
       
  5457     Errors/Exceptions: None
       
  5458 
       
  5459     Status: Approved
       
  5460 
       
  5461 -------------------------------------------------------------------------------
       
  5462 */
       
  5463 CStifLogger* CTestCase::Logger()
       
  5464     {
       
  5465     return iTestEngine->Logger();
       
  5466 
       
  5467     }
       
  5468 
       
  5469 /*
       
  5470 -------------------------------------------------------------------------------
       
  5471 
       
  5472     Class: CTestCase
       
  5473 
       
  5474     Method: ExecuteCommaandL
       
  5475 
       
  5476     Description: Executes command received from test case.
       
  5477 
       
  5478     Parameters: aStifCommand command to be executed
       
  5479                 aParam1      parameter to command
       
  5480 
       
  5481     Return Values: None
       
  5482 
       
  5483     Errors/Exceptions: None
       
  5484 
       
  5485     Status: Approved
       
  5486 
       
  5487 -------------------------------------------------------------------------------
       
  5488 */
       
  5489 void CTestCase::ExecuteCommandL(TCommand aCommand, TDesC8& aParamsPckg)
       
  5490     {
       
  5491     switch(aCommand)
       
  5492         {
       
  5493         case EStopExecution:
       
  5494             {
       
  5495             //Unpack received parameters
       
  5496             TStopExecutionCommandParams par;
       
  5497             TStopExecutionCommandParamsPckg parPack(par);
       
  5498             parPack.Copy(aParamsPckg);
       
  5499 
       
  5500             __TRACE(KVerbose, (_L("CTestCase::ExecuteCommandL command [%d] type [%d] code [%d]"), TInt(aCommand), TInt(par.iType), par.iCode));
       
  5501 
       
  5502             iTestCaseController->Suicide(par.iType, par.iCode);
       
  5503             break;
       
  5504             }
       
  5505         default:
       
  5506             __TRACE(KVerbose, (_L("CTestCase::ExecuteCommandL unknown command [%d]"), TInt(aCommand)));
       
  5507             return;
       
  5508         }
       
  5509 
       
  5510     }
       
  5511 
       
  5512 /*
       
  5513 -------------------------------------------------------------------------------
       
  5514 
       
  5515     Class: CTestCase
       
  5516 
       
  5517     Method: GetModuleControllers
       
  5518 
       
  5519     Description: Return module controller and real module controller
       
  5520 
       
  5521     Parameters: aRealModuleController: out: real module controller
       
  5522 
       
  5523     Return Values: module controller
       
  5524 
       
  5525     Errors/Exceptions: None
       
  5526 
       
  5527     Status: Approved
       
  5528 
       
  5529 -------------------------------------------------------------------------------
       
  5530 */
       
  5531 CTestModuleController* CTestCase::GetModuleControllers(CTestModuleController** aRealModuleController)
       
  5532     {
       
  5533     *aRealModuleController = iRealModuleController;
       
  5534     return iTestModule;
       
  5535     }
       
  5536 
       
  5537 /*
       
  5538 -------------------------------------------------------------------------------
       
  5539 
       
  5540     Class: CTestCase
       
  5541 
       
  5542     Method: ResetModuleController
       
  5543 
       
  5544     Description: Set new module controller for test case (only in case when 
       
  5545                  original controller crashed)
       
  5546 
       
  5547     Parameters: aModuleController: in: new module controller
       
  5548 
       
  5549     Return Values: None
       
  5550 
       
  5551     Errors/Exceptions: None
       
  5552 
       
  5553     Status: Approved
       
  5554 
       
  5555 -------------------------------------------------------------------------------
       
  5556 */
       
  5557 void CTestCase::ResetModuleController(CTestModuleController* aModuleController)
       
  5558     {
       
  5559     iTestModule = aModuleController;
       
  5560     }
       
  5561 
       
  5562 /*
       
  5563 -------------------------------------------------------------------------------
       
  5564 
       
  5565     Class: CTestCase
       
  5566 
       
  5567     Method: ResetRealModuleController
       
  5568 
       
  5569     Description: Set new real module controller for test case (only in case 
       
  5570                  when original controller crashed).
       
  5571 
       
  5572     Parameters: aRealModuleController: in: new real module controller
       
  5573 
       
  5574     Return Values: None
       
  5575 
       
  5576     Errors/Exceptions: None
       
  5577 
       
  5578     Status: Approved
       
  5579 
       
  5580 -------------------------------------------------------------------------------
       
  5581 */
       
  5582 void CTestCase::ResetRealModuleController(CTestModuleController* aRealModuleController)
       
  5583     {
       
  5584     iRealModuleController = aRealModuleController;
       
  5585     }
       
  5586 
       
  5587 /*
       
  5588 -------------------------------------------------------------------------------
       
  5589 
       
  5590     DESCRIPTION
       
  5591 
       
  5592     Default constructor
       
  5593 
       
  5594 -------------------------------------------------------------------------------
       
  5595 */
       
  5596 CTestReportSettings::CTestReportSettings()
       
  5597     {
       
  5598     iCreateTestReport = ETrue;
       
  5599     iPath = NULL;
       
  5600     iName = NULL;
       
  5601     iFormat = CStifLogger::ETxt;
       
  5602     iOutput = CStifLogger::EFile;
       
  5603     iOverwrite = ETrue; 
       
  5604     iXML = EFalse;
       
  5605     }
       
  5606 
       
  5607 /*
       
  5608 -------------------------------------------------------------------------------
       
  5609 
       
  5610     DESCRIPTION
       
  5611 
       
  5612     Two-phased constructor.
       
  5613 
       
  5614 -------------------------------------------------------------------------------
       
  5615 */
       
  5616 CTestReportSettings* CTestReportSettings::NewL()
       
  5617     {
       
  5618     CTestReportSettings* self = new ( ELeave ) CTestReportSettings();
       
  5619     CleanupStack::PushL( self );
       
  5620     self->ConstructL();
       
  5621     CleanupStack::Pop();
       
  5622     return self;
       
  5623     }
       
  5624 
       
  5625 /*
       
  5626 -------------------------------------------------------------------------------
       
  5627 
       
  5628     DESCRIPTION
       
  5629 
       
  5630     Symbian OS second phase constructor
       
  5631 
       
  5632 -------------------------------------------------------------------------------
       
  5633 */
       
  5634 void CTestReportSettings::ConstructL()
       
  5635     {
       
  5636     
       
  5637     }
       
  5638 /*
       
  5639 -------------------------------------------------------------------------------
       
  5640 
       
  5641     DESCRIPTION
       
  5642 
       
  5643     Destructor
       
  5644 
       
  5645 -------------------------------------------------------------------------------
       
  5646 */
       
  5647 CTestReportSettings::~CTestReportSettings()
       
  5648     { 
       
  5649     delete iPath; 
       
  5650     iPath = NULL;
       
  5651     delete iName;
       
  5652     iName = NULL;
       
  5653     } 
       
  5654 
       
  5655 /*
       
  5656 -------------------------------------------------------------------------------
       
  5657 
       
  5658     DESCRIPTION
       
  5659 
       
  5660     This module contains implementation of CRebootParams class member functions.
       
  5661 
       
  5662 -------------------------------------------------------------------------------
       
  5663 */
       
  5664 
       
  5665 // ================= MEMBER FUNCTIONS =========================================
       
  5666 
       
  5667 /*
       
  5668 -------------------------------------------------------------------------------
       
  5669 
       
  5670     Class: CRebootParams
       
  5671 
       
  5672     Method: CRebootParams
       
  5673 
       
  5674     Description: Default constructor
       
  5675     
       
  5676     Parameters: None
       
  5677     
       
  5678     Return Values: None
       
  5679 
       
  5680     Errors/Exceptions: None
       
  5681 
       
  5682     Status: Draft
       
  5683 
       
  5684 -------------------------------------------------------------------------------
       
  5685 */
       
  5686 CRebootParams::CRebootParams()
       
  5687     {
       
  5688     }
       
  5689 
       
  5690 /*
       
  5691 -------------------------------------------------------------------------------
       
  5692 
       
  5693     Class: CRebootParams
       
  5694 
       
  5695     Method: ConstructL
       
  5696 
       
  5697     Description: Symbian OS second phase constructor
       
  5698 
       
  5699 
       
  5700     Parameters: None
       
  5701 
       
  5702     Return Values: None
       
  5703 
       
  5704     Errors/Exceptions: Leaves if RTestExecution::Open returns error
       
  5705                        Leaves if some of called leaving methods leaves
       
  5706 
       
  5707     Status: Draft
       
  5708 
       
  5709 -------------------------------------------------------------------------------
       
  5710 */
       
  5711 void CRebootParams::ConstructL()
       
  5712     {
       
  5713     }
       
  5714 
       
  5715 /*
       
  5716 -------------------------------------------------------------------------------
       
  5717 
       
  5718     Class: CRebootParams
       
  5719 
       
  5720     Method: NewL
       
  5721 
       
  5722     Description: Two-phased constructor.
       
  5723 
       
  5724     Parameters: none
       
  5725     
       
  5726     Return Values: CRebootParams* : pointer to created CRebootParams object
       
  5727 
       
  5728     Errors/Exceptions: Leaves if ConstructL leaves
       
  5729 
       
  5730     Status: Draft
       
  5731 
       
  5732 -------------------------------------------------------------------------------
       
  5733 */
       
  5734 CRebootParams* CRebootParams::NewL()    
       
  5735     {
       
  5736     
       
  5737     CRebootParams* self = new ( ELeave ) CRebootParams();
       
  5738     CleanupStack::PushL( self );
       
  5739     self->ConstructL();
       
  5740     CleanupStack::Pop();
       
  5741     return self;
       
  5742 
       
  5743     }
       
  5744 
       
  5745 /*
       
  5746 -------------------------------------------------------------------------------
       
  5747 
       
  5748     Class: CRebootParams
       
  5749 
       
  5750     Method: ~CRebootParams
       
  5751 
       
  5752     Description: Destructor
       
  5753 
       
  5754     Parameters: None
       
  5755 
       
  5756     Return Values: None
       
  5757 
       
  5758     Errors/Exceptions: None
       
  5759 
       
  5760     Status: Draft
       
  5761 
       
  5762 -------------------------------------------------------------------------------
       
  5763 */
       
  5764 CRebootParams::~CRebootParams()
       
  5765     {
       
  5766     
       
  5767     delete iTestModuleBuf;
       
  5768     iTestModuleBuf = 0;
       
  5769     delete iTestCaseFileBuf;
       
  5770     iTestCaseFileBuf = 0;
       
  5771     delete iTestCaseTitleBuf;
       
  5772     iTestCaseTitleBuf = 0;
       
  5773     delete iStateNameBuf;
       
  5774     iStateNameBuf = 0;
       
  5775     
       
  5776     }
       
  5777 
       
  5778 
       
  5779 /*
       
  5780 -------------------------------------------------------------------------------
       
  5781 
       
  5782     Class: CRebootParams
       
  5783 
       
  5784     Method: SetTestModuleNameL
       
  5785 
       
  5786     Description: Setter
       
  5787 
       
  5788     Parameters: const TDesC& aName: in: name to set
       
  5789 
       
  5790     Return Values: None
       
  5791 
       
  5792     Errors/Exceptions: Leaves if memory allocation fails
       
  5793     
       
  5794     Status: Draft
       
  5795 
       
  5796 -------------------------------------------------------------------------------
       
  5797 */        
       
  5798 void CRebootParams::SetTestModuleNameL( const TDesC& aName )
       
  5799     {
       
  5800     
       
  5801     delete iTestModuleBuf;
       
  5802     iTestModuleBuf = 0;
       
  5803     iTestModuleBuf = aName.AllocLC();
       
  5804     iTestModule.Set( iTestModuleBuf->Des() );
       
  5805     CleanupStack::Pop( iTestModuleBuf );
       
  5806     
       
  5807     }
       
  5808 
       
  5809 /*
       
  5810 -------------------------------------------------------------------------------
       
  5811 
       
  5812     Class: CRebootParams
       
  5813 
       
  5814     Method: SetTestModuleNameL
       
  5815 
       
  5816     Description: Setter
       
  5817 
       
  5818     Parameters: const TDesC& aName: in: name to set
       
  5819 
       
  5820     Return Values: None
       
  5821 
       
  5822     Errors/Exceptions:  Leaves if memory allocation fails
       
  5823 
       
  5824     Status: Draft
       
  5825 
       
  5826 -------------------------------------------------------------------------------
       
  5827 */        
       
  5828 void CRebootParams::SetTestCaseFileNameL( const TDesC& aName )
       
  5829     {
       
  5830     
       
  5831     delete iTestCaseFileBuf;
       
  5832     iTestCaseFileBuf = 0;
       
  5833     iTestCaseFileBuf = aName.AllocLC();
       
  5834     iTestCaseFile.Set( iTestCaseFileBuf->Des() );
       
  5835     CleanupStack::Pop( iTestCaseFileBuf );
       
  5836     
       
  5837     }
       
  5838     
       
  5839 /*
       
  5840 -------------------------------------------------------------------------------
       
  5841 
       
  5842     Class: CRebootParams
       
  5843 
       
  5844     Method: SetTestModuleNameL
       
  5845 
       
  5846     Description: Setter
       
  5847 
       
  5848     Parameters: const TDesC& aName: in: name to set
       
  5849 
       
  5850     Return Values: None
       
  5851 
       
  5852     Errors/Exceptions:  Leaves if memory allocation fails
       
  5853 
       
  5854     Status: Draft
       
  5855 
       
  5856 -------------------------------------------------------------------------------
       
  5857 */        
       
  5858 void CRebootParams::SetTestCaseTitleL( const TDesC& aName )
       
  5859     {
       
  5860     
       
  5861     delete iTestCaseTitleBuf;
       
  5862     iTestCaseTitleBuf = 0;
       
  5863     iTestCaseTitleBuf = aName.AllocLC();
       
  5864     iTestCaseTitle.Set( iTestCaseTitleBuf->Des() );
       
  5865     CleanupStack::Pop( iTestCaseTitleBuf );
       
  5866     
       
  5867     }
       
  5868     
       
  5869 /*
       
  5870 -------------------------------------------------------------------------------
       
  5871 
       
  5872     Class: CRebootParams
       
  5873 
       
  5874     Method: SetTestModuleNameL
       
  5875 
       
  5876     Description: Setter
       
  5877 
       
  5878     Parameters: const TDesC& aName: in: name to set
       
  5879 
       
  5880     Return Values: None
       
  5881 
       
  5882     Errors/Exceptions: Leaves if memory allocation fails
       
  5883 
       
  5884     Status: Draft
       
  5885 
       
  5886 -------------------------------------------------------------------------------
       
  5887 */        
       
  5888 void CRebootParams::SetTestCaseStateL( const TDesC& aName )
       
  5889     {
       
  5890     
       
  5891     delete iStateNameBuf;
       
  5892     iStateNameBuf = 0;
       
  5893     iStateNameBuf = aName.AllocLC();
       
  5894     iStateName.Set( iStateNameBuf->Des() );
       
  5895     CleanupStack::Pop( iStateNameBuf );
       
  5896     
       
  5897     }
       
  5898 
       
  5899     
       
  5900 /*
       
  5901 -------------------------------------------------------------------------------
       
  5902 
       
  5903     DESCRIPTION
       
  5904 
       
  5905     This module contains implementation of TEventMsg class member functions.
       
  5906 
       
  5907 -------------------------------------------------------------------------------
       
  5908 */
       
  5909 
       
  5910 // ================= MEMBER FUNCTIONS =========================================
       
  5911 
       
  5912 /*
       
  5913 -------------------------------------------------------------------------------
       
  5914 
       
  5915     Class: TEventMsg
       
  5916 
       
  5917     Method: TEventMsg
       
  5918 
       
  5919     Description: Default constructor
       
  5920     
       
  5921     Parameters: None
       
  5922     
       
  5923     Return Values: None
       
  5924 
       
  5925     Errors/Exceptions: None
       
  5926 
       
  5927     Status: Proposal
       
  5928 
       
  5929 -------------------------------------------------------------------------------
       
  5930 */    
       
  5931 TEventMsg::TEventMsg():
       
  5932     TEventIf(),
       
  5933     iWaitPending(EFalse), 
       
  5934     iStateEventPending(EFalse),
       
  5935     iStatus( NULL )
       
  5936     {
       
  5937     }
       
  5938 
       
  5939 /*
       
  5940 -------------------------------------------------------------------------------
       
  5941 
       
  5942     Class: TEventMsg
       
  5943 
       
  5944     Method: ~TEventMsg
       
  5945 
       
  5946     Description: Destructor
       
  5947     
       
  5948     Parameters: None
       
  5949     
       
  5950     Return Values: None
       
  5951 
       
  5952     Errors/Exceptions: None
       
  5953 
       
  5954     Status: Proposal
       
  5955 
       
  5956 -------------------------------------------------------------------------------
       
  5957 */    
       
  5958 TEventMsg::~TEventMsg()
       
  5959     {
       
  5960     if( iWaitPending )
       
  5961         {
       
  5962         iWaitMsg.Complete( KErrCancel );
       
  5963         iWaitPending = EFalse;
       
  5964         }
       
  5965         
       
  5966     if( iStatus )
       
  5967         {
       
  5968         User::RequestComplete( iStatus, KErrCancel );
       
  5969         }
       
  5970 
       
  5971     }
       
  5972 
       
  5973 /*
       
  5974 -------------------------------------------------------------------------------
       
  5975 
       
  5976     Class: TEventMsg
       
  5977 
       
  5978     Method: Set
       
  5979 
       
  5980     Description: Set event.
       
  5981     
       
  5982     Parameters: TEventType aEventType: in: Event type
       
  5983     
       
  5984     Return Values: None
       
  5985 
       
  5986     Errors/Exceptions: None
       
  5987 
       
  5988     Status: Proposal
       
  5989 
       
  5990 -------------------------------------------------------------------------------
       
  5991 */    
       
  5992 void TEventMsg::Set( TEventType aEventType )
       
  5993     {
       
  5994     iEventType = aEventType;
       
  5995     if( aEventType == EState )
       
  5996         {
       
  5997         iStateEventPending = ETrue;
       
  5998         }
       
  5999     if( iWaitPending )
       
  6000         {
       
  6001         TEventIf event;
       
  6002         event.Copy( *this );
       
  6003         TEventIfPckg eventIfPckg( event );
       
  6004         iWaitMsg.WriteL( 0, eventIfPckg );
       
  6005 
       
  6006         iWaitMsg.Complete( KErrNone );
       
  6007         iWaitPending = EFalse;
       
  6008         }
       
  6009     } 
       
  6010 
       
  6011 /*
       
  6012 -------------------------------------------------------------------------------
       
  6013 
       
  6014     Class: TEventMsg
       
  6015 
       
  6016     Method: Wait
       
  6017 
       
  6018     Description: Wait event.
       
  6019     
       
  6020     Parameters: const RMessage& aMessage: in: Message
       
  6021     
       
  6022     Return Values: None
       
  6023 
       
  6024     Errors/Exceptions: None
       
  6025 
       
  6026     Status: Proposal
       
  6027 
       
  6028 -------------------------------------------------------------------------------
       
  6029 */
       
  6030 void TEventMsg::Wait( const RMessage2& aMessage )
       
  6031     { 
       
  6032     if( iStateEventPending )
       
  6033         {
       
  6034         TEventIf event;
       
  6035         event.Copy( *this );
       
  6036         TEventIfPckg eventIfPckg( event );
       
  6037         aMessage.WriteL( 0, eventIfPckg );
       
  6038         aMessage.Complete( KErrNone );
       
  6039         }
       
  6040     else
       
  6041         {
       
  6042         iWaitMsg = aMessage;
       
  6043         iWaitPending = ETrue;
       
  6044         }
       
  6045     }
       
  6046 
       
  6047 /*
       
  6048 -------------------------------------------------------------------------------
       
  6049 
       
  6050     Class: TEventMsg
       
  6051 
       
  6052     Method: CancelWait
       
  6053 
       
  6054     Description: Cancel pending Wait
       
  6055     
       
  6056     Parameters: None
       
  6057     
       
  6058     Return Values: None
       
  6059 
       
  6060     Errors/Exceptions: None
       
  6061 
       
  6062     Status: Proposal
       
  6063 
       
  6064 -------------------------------------------------------------------------------
       
  6065 */    
       
  6066 void TEventMsg::CancelWait()
       
  6067     {
       
  6068     if( iWaitPending )
       
  6069         {
       
  6070         iWaitMsg.Complete( KErrCancel );
       
  6071         iWaitPending = EFalse;
       
  6072         } 
       
  6073     } 
       
  6074              
       
  6075 /*
       
  6076 -------------------------------------------------------------------------------
       
  6077 
       
  6078     Class: TEventMsg
       
  6079 
       
  6080     Method: Release
       
  6081 
       
  6082     Description: Release event. Unset released.
       
  6083     
       
  6084     Parameters: None
       
  6085     
       
  6086     Return Values: None
       
  6087 
       
  6088     Errors/Exceptions: None
       
  6089 
       
  6090     Status: Proposal
       
  6091 
       
  6092 -------------------------------------------------------------------------------
       
  6093 */    
       
  6094 void TEventMsg::Release()
       
  6095     { 
       
  6096     
       
  6097     if( iStatus )
       
  6098         {
       
  6099         User::RequestComplete( iStatus, KErrNone );
       
  6100         }
       
  6101         
       
  6102     } 
       
  6103 /*
       
  6104 -------------------------------------------------------------------------------
       
  6105 
       
  6106     Class: TEventMsg
       
  6107 
       
  6108     Method: Unset
       
  6109 
       
  6110     Description: Unset event. Blocks until Release is called.
       
  6111     
       
  6112     Parameters: TRequestStatus& aStatus: in: Status 
       
  6113     
       
  6114     Return Values: None
       
  6115 
       
  6116     Errors/Exceptions: None
       
  6117 
       
  6118     Status: Proposal
       
  6119 
       
  6120 -------------------------------------------------------------------------------
       
  6121 */    
       
  6122 void TEventMsg::Unset( TRequestStatus& aStatus )
       
  6123     { 
       
  6124     
       
  6125     iStatus = &aStatus;
       
  6126     
       
  6127     } 
       
  6128 
       
  6129 // ================= OTHER EXPORTED FUNCTIONS =================================
       
  6130 
       
  6131 /*
       
  6132 -------------------------------------------------------------------------------
       
  6133 
       
  6134     Function: StartEngine
       
  6135 
       
  6136     Description: This is called from the client.
       
  6137 
       
  6138     Parameters: None
       
  6139 
       
  6140     Return Values: TInt KErrNone: No errors occured
       
  6141                         KErrNoMemory: Memory is too low to create Test Engine
       
  6142                         Other error code: Error got from iEngineThread.Create()
       
  6143 
       
  6144     Errors/Exceptions: None
       
  6145 
       
  6146     Status: Approved
       
  6147 
       
  6148 -------------------------------------------------------------------------------
       
  6149 */
       
  6150 EXPORT_C TInt StartEngine()
       
  6151     {
       
  6152     __UHEAP_MARK;
       
  6153 
       
  6154     // check server not already started
       
  6155     TFindServer findTestEngineServer( KTestEngineName );
       
  6156     TFullName name;
       
  6157     if ( findTestEngineServer.Next( name ) == KErrNone )
       
  6158         {   
       
  6159         // Server already started, nothing to do    
       
  6160         __UHEAP_MARKEND;
       
  6161         return KErrNone;
       
  6162         }
       
  6163 
       
  6164     // Construct start-up information object
       
  6165     TThreadStartTestEngine* startInfo = new TThreadStartTestEngine();
       
  6166     if ( startInfo == NULL )
       
  6167         {
       
  6168         __UHEAP_MARKEND;
       
  6169         return KErrNoMemory;
       
  6170         }
       
  6171 
       
  6172     startInfo->iStarted.CreateLocal( 0 );     // Create start-up semaphore
       
  6173 
       
  6174     // Create thread    
       
  6175     TInt ret = startInfo->iEngineThread.Create(
       
  6176         KTestEngineName ,                               // name of thread
       
  6177         CTestEngineServer::ThreadFunction,              // thread function
       
  6178         KDefaultStackSize*4,                            // stack
       
  6179         KTestEngineMinHeapSize,KTestEngineMaxHeapSize*4,// Heap
       
  6180         startInfo                                       // parameter to thread
       
  6181                                                         // function
       
  6182         );
       
  6183 
       
  6184     if ( ret != KErrNone )
       
  6185         {
       
  6186         startInfo->iStarted.Close();
       
  6187         delete startInfo;
       
  6188         __UHEAP_MARKEND;
       
  6189         return ret;
       
  6190         }
       
  6191 
       
  6192     // Now start thread
       
  6193     startInfo->iEngineThread.SetPriority( EPriorityMuchMore );  // set its
       
  6194                                                                 // priority
       
  6195     startInfo->iEngineThread.Resume();                          // kick it
       
  6196                                                                 // into life
       
  6197 
       
  6198     // Wait until the thread is started
       
  6199     startInfo->iStarted.Wait(); 
       
  6200 
       
  6201     // Clean-up 
       
  6202     startInfo->iEngineThread.Close();
       
  6203     startInfo->iStarted.Close(); 
       
  6204 
       
  6205 
       
  6206     delete startInfo;
       
  6207 
       
  6208     __UHEAP_MARKEND;
       
  6209 
       
  6210     return KErrNone;
       
  6211 
       
  6212     }
       
  6213 
       
  6214 // End of File