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