stif/StifTFwIf/src/UIEngine.cpp
changeset 0 a03f92240627
child 30 86a2e675b80a
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: CUIEngine: This object executes test cases from 
       
    15 * STIF Test Framework.
       
    16 * 
       
    17 */
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <e32base.h>
       
    21 #include <e32svr.h>
       
    22 #include <collate.h>
       
    23 #include "UIEngineEvent.h"
       
    24 #include <stifinternal/UIEngineContainer.h>
       
    25 #include "UIEngineError.h"
       
    26 #include <stifinternal/UIEngine.h>
       
    27 #include "Logging.h"
       
    28 
       
    29 // EXTERNAL DATA STRUCTURES
       
    30 // None
       
    31 
       
    32 // EXTERNAL FUNCTION PROTOTYPES
       
    33 // None
       
    34 
       
    35 // CONSTANTS
       
    36 _LIT( KUIEngine, "CUIEngine" );
       
    37 
       
    38 // MACROS
       
    39 #ifdef LOGGER
       
    40 #undef LOGGER
       
    41 #endif
       
    42 #define LOGGER iLogger
       
    43 
       
    44 // LOCAL CONSTANTS AND MACROS
       
    45 // None
       
    46 
       
    47 // MODULE DATA STRUCTURES
       
    48 // None
       
    49 
       
    50 // LOCAL FUNCTION PROTOTYPES
       
    51 // None
       
    52 
       
    53 // FORWARD DECLARATIONS
       
    54 // None
       
    55 
       
    56 // ==================== LOCAL FUNCTIONS ======================================= 
       
    57 
       
    58 // ================= MEMBER FUNCTIONS =========================================
       
    59 
       
    60 /*
       
    61 -------------------------------------------------------------------------------
       
    62 
       
    63     Class: CUIEngine
       
    64 
       
    65     Method: CUIEngine
       
    66 
       
    67     Description: Default constructor
       
    68 
       
    69     C++ default constructor can NOT contain any code, that
       
    70     might leave.
       
    71     
       
    72     Parameters: None
       
    73     
       
    74     Return Values: None
       
    75 
       
    76     Errors/Exceptions: None
       
    77 
       
    78     Status: Draft
       
    79 
       
    80 -------------------------------------------------------------------------------
       
    81 */
       
    82 CUIEngine::CUIEngine( CUIIf* aUi  ):
       
    83     iUi( aUi )
       
    84     {
       
    85 
       
    86     __RDEBUG( _L( "CUIEngine::CUIEngine()" ) );
       
    87     
       
    88     }
       
    89 
       
    90 /*
       
    91 -------------------------------------------------------------------------------
       
    92 
       
    93     Class: CUIEngine
       
    94 
       
    95     Method: ConstructL
       
    96 
       
    97     Description: Symbian OS second phase constructor
       
    98 
       
    99     Symbian OS default constructor can leave.
       
   100 
       
   101     Parameters: None
       
   102 
       
   103     Return Values: None
       
   104 
       
   105     Errors/Exceptions: Leaves if called Open method returns error
       
   106 
       
   107     Status: Draft
       
   108 
       
   109 -------------------------------------------------------------------------------
       
   110 */
       
   111 void CUIEngine::ConstructL()
       
   112     {
       
   113     // Logger's setting definitions
       
   114     TLoggerSettings loggerSettings;
       
   115     loggerSettings.iCreateLogDirectories = EFalse;
       
   116     loggerSettings.iOverwrite = ETrue;
       
   117     loggerSettings.iTimeStamp = ETrue;
       
   118     loggerSettings.iLineBreak = ETrue;
       
   119     loggerSettings.iEventRanking = EFalse;
       
   120     loggerSettings.iThreadId = EFalse;
       
   121     loggerSettings.iHardwareFormat = CStifLogger::ETxt;
       
   122     loggerSettings.iHardwareOutput = CStifLogger::EFile;
       
   123     loggerSettings.iEmulatorFormat = CStifLogger::ETxt;
       
   124     loggerSettings.iEmulatorOutput = CStifLogger::EFile;
       
   125     loggerSettings.iUnicode = EFalse;
       
   126     loggerSettings.iAddTestCaseTitle = EFalse;
       
   127 
       
   128     // Create Logger, Note: Use protected NewL because initialization file not
       
   129     // readed yet.
       
   130     iLogger = CStifLogger::NewL( KUiLogDir, KUiLogFile, loggerSettings );
       
   131     
       
   132     // Initialize logger    
       
   133     iUi->InitializeLogger( iLogger );
       
   134 
       
   135     }
       
   136 
       
   137 
       
   138 /*
       
   139 -------------------------------------------------------------------------------
       
   140 
       
   141     Class: CUIEngine
       
   142 
       
   143     Method: NewL
       
   144 
       
   145     Description: Two-phased constructor.
       
   146     
       
   147     Parameters: None
       
   148     
       
   149     Return Values: CUIEngine* : Pointer to created UI engine object
       
   150 
       
   151     Errors/Exceptions: Leaves if memory allocation for CUIEngine fails
       
   152                        Leaves if ConstructL leaves
       
   153 
       
   154     Status: Draft
       
   155 
       
   156 -------------------------------------------------------------------------------
       
   157 */
       
   158 CUIEngine* CUIEngine::NewL( CUIIf* aUi )
       
   159     {
       
   160     
       
   161     CUIEngine* self =  
       
   162         new ( ELeave ) CUIEngine( aUi );
       
   163     CleanupStack::PushL( self );
       
   164     self->ConstructL();
       
   165     CleanupStack::Pop();
       
   166     return self;
       
   167     
       
   168     }
       
   169 
       
   170 
       
   171 
       
   172 /*
       
   173 -------------------------------------------------------------------------------
       
   174 
       
   175     Class: CUIEngine
       
   176 
       
   177     Method: ~CUIEngine
       
   178 
       
   179     Description: Destructor
       
   180     
       
   181     Parameters: None
       
   182 
       
   183     Return Values: None
       
   184 
       
   185     Errors/Exceptions: None
       
   186 
       
   187     Status: Draft
       
   188 
       
   189 -------------------------------------------------------------------------------
       
   190 */
       
   191 CUIEngine::~CUIEngine()
       
   192     {
       
   193     
       
   194     __RDEBUG( _L( "CUIEngine::~CUIEngine()" ) );
       
   195     
       
   196     // Delete all containers, cannot use ResetAndDestroy,
       
   197     // because destructor is private
       
   198     TInt count = iContainerArray.Count();
       
   199     for( TInt i=0; i< count; i++ )
       
   200         {
       
   201         delete iContainerArray[i];
       
   202         }
       
   203     iContainerArray.Reset();    
       
   204     iContainerArray.Close();
       
   205 
       
   206     delete iLogger;
       
   207     iLogger = NULL;
       
   208     
       
   209     delete iError;
       
   210     iError = 0;
       
   211         
       
   212     }
       
   213 
       
   214 
       
   215 /*
       
   216 -------------------------------------------------------------------------------
       
   217 
       
   218     Class: VUIEngine
       
   219 
       
   220     Method: Open
       
   221 
       
   222     Description: Open test engine.
       
   223 
       
   224     Parameters: TDesC& aTestFrameworkIni: in: Initialization file to Test Framework
       
   225 
       
   226     Return Values: Symbian OS error: Error code
       
   227 
       
   228     Errors/Exceptions: None
       
   229 
       
   230     Status: Draft
       
   231 
       
   232 -------------------------------------------------------------------------------
       
   233 */
       
   234 TInt CUIEngine::Open( const TDesC& aTestFrameworkIni )
       
   235     {
       
   236     
       
   237     if( ( iTestEngine.SubSessionHandle() != 0 ) ||
       
   238         ( iTestEngineServ.Handle() != 0 ) )
       
   239         {
       
   240         __TRACE( KError, ( CStifLogger::EError, _L( "CUIEngine::Open() Already open" ) ) );
       
   241         return KErrInUse;     
       
   242         }
       
   243 
       
   244     // Check aTestFrameworkIni max length
       
   245     if( aTestFrameworkIni.Length() > KMaxFileName )
       
   246         {
       
   247         __TRACE( KPrint, ( CStifLogger::EError, _L( "CUIEngine::Open() method's parameter length is incorrect" ) ) );
       
   248         return KErrArgument;        
       
   249         }
       
   250 
       
   251     // Create Test Engine
       
   252     TInt ret = iTestEngineServ.Connect();
       
   253 
       
   254     if ( ret != KErrNone )
       
   255         {
       
   256         __TRACE( KPrint, ( _L( "CUIEngine::Open. Engine server open failed: ret = %d"), ret ) );
       
   257 
       
   258         return ret;
       
   259         }
       
   260 
       
   261     ret = iTestEngine.Open( iTestEngineServ, aTestFrameworkIni );
       
   262 
       
   263     if ( ret != KErrNone )
       
   264         {
       
   265         __TRACE( KPrint, ( _L( "CUIEngine::Open. Engine. Open failed: ret = %d"), ret ) );
       
   266 
       
   267         return ret;
       
   268         }
       
   269 
       
   270     TErrorNotification error;
       
   271     if( ErrorPrint( error ) != KErrNotSupported )
       
   272         {
       
   273         // Start printer
       
   274         iError = CUIEngineErrorPrinter::NewL( this );
       
   275         iError->StartL( iTestEngine );
       
   276         }
       
   277 
       
   278     return ret;
       
   279     }
       
   280 
       
   281 
       
   282 /*
       
   283 -------------------------------------------------------------------------------
       
   284 
       
   285     Class: CUIEngine
       
   286 
       
   287     Method: Close
       
   288 
       
   289     Description: Close test engine.
       
   290 
       
   291     Parameters: None
       
   292 
       
   293     Return Values: TInt KErrNone: Always returned KErrNone
       
   294 
       
   295     Errors/Exceptions: None
       
   296 
       
   297     Status: Draft
       
   298 
       
   299 -------------------------------------------------------------------------------
       
   300 */
       
   301 TInt CUIEngine::Close()
       
   302     {
       
   303     
       
   304     delete iError;
       
   305     iError = 0;
       
   306     
       
   307     // Delete all containers, cannot use ResetAndDestroy,
       
   308     // because destructor is private
       
   309     TInt count = iContainerArray.Count();
       
   310     for( TInt i=0; i< count; i++ )
       
   311         {
       
   312         delete iContainerArray[i];
       
   313 		iContainerArray[i] = NULL;
       
   314         }
       
   315     iContainerArray.Reset();
       
   316     
       
   317     iTestEngine.Close();
       
   318     iTestEngineServ.Close();
       
   319 
       
   320     __TRACE( KPrint, ( _L( "CUIEngine::Close." ) ) );
       
   321 
       
   322     return KErrNone;
       
   323     }
       
   324 
       
   325 /*
       
   326 -------------------------------------------------------------------------------
       
   327 
       
   328     Class: CUIEngine
       
   329 
       
   330     Method: AddTestModule
       
   331 
       
   332     Description: Add test module to module list of test engine
       
   333 
       
   334     Parameters: TDesC& aModuleName: in: Testmodule, which is added to module list
       
   335                 TDesC& aIniFile: in: Initialization file to the test module
       
   336 
       
   337     Return Values: Symbian OS error: Error code
       
   338 
       
   339     Errors/Exceptions: None
       
   340 
       
   341     Status: Draft
       
   342 
       
   343 -------------------------------------------------------------------------------
       
   344 */
       
   345 TInt CUIEngine::AddTestModule( const TDesC& aModuleName, 
       
   346                                const TDesC& aIniFile )
       
   347     {
       
   348     // Check aModuleName max length
       
   349     if( aModuleName.Length() > KMaxName )
       
   350         {
       
   351         __TRACE( KPrint, ( CStifLogger::EError, _L( "CUIEngine::AddTestModule() method's first parameter length is incorrect" ) ) );
       
   352         return KErrArgument;        
       
   353         }
       
   354     // Check aIniFile max length
       
   355     if( aIniFile.Length() > KMaxFileName )
       
   356         {
       
   357         __TRACE( KPrint, ( CStifLogger::EError, _L( "CUIEngine::AddTestModule() method's second parameter length is incorrect" ) ) );
       
   358         return KErrArgument;        
       
   359         }    
       
   360 
       
   361 
       
   362     TInt ret = iTestEngine.AddTestModule( aModuleName, aIniFile );
       
   363 
       
   364     if ( ret != KErrNone && ret != KErrAlreadyExists )
       
   365         {
       
   366 		__TRACE( KPrint, ( _L( "CUIEngine::AddTestModule. Add module failed: ret = %d" ), ret  ) );
       
   367 
       
   368         return ret;
       
   369         }
       
   370 
       
   371     return KErrNone;
       
   372     
       
   373     }
       
   374 
       
   375 
       
   376 /*
       
   377 -------------------------------------------------------------------------------
       
   378 
       
   379     Class: CUIEngine
       
   380 
       
   381     Method: RemoveTestModule
       
   382 
       
   383     Description: Remove test module from test engine
       
   384 
       
   385     Parameters: TDesC& aModuleName: in: Testmodule, which is removed of module list
       
   386 
       
   387     Return Values: Symbian OS error: Error code
       
   388 
       
   389     Errors/Exceptions: None
       
   390 
       
   391     Status: Draft
       
   392 
       
   393 -------------------------------------------------------------------------------
       
   394 */
       
   395 TInt CUIEngine::RemoveTestModule( const TDesC& aModuleName )
       
   396     {
       
   397     // Remove test module of module list of test engine
       
   398     TInt ret = iTestEngine.RemoveTestModule( aModuleName );
       
   399 
       
   400     if ( ret != KErrNone )
       
   401         {
       
   402         __TRACE( KPrint, ( _L( "CUIEngine::RemoveTestModule. Remove module failed: ret = %d"), ret  ) );
       
   403 
       
   404         return ret;
       
   405         }
       
   406 
       
   407     return ret;
       
   408     }
       
   409 
       
   410 
       
   411 /*
       
   412 -------------------------------------------------------------------------------
       
   413 
       
   414     Class: CUIEngine
       
   415 
       
   416     Method: AddTestCaseFile
       
   417 
       
   418     Description: Add test case file to test case file list of test engine
       
   419 
       
   420     Parameters: TDesC& aModuleName: in: Testmodule, which own test cases of test case list.
       
   421                 TDesC& aCaseFile: in: Test case list, which is added to test case list
       
   422 
       
   423     Return Values: Symbian OS error: Error code
       
   424 
       
   425     Errors/Exceptions: None
       
   426 
       
   427     Status: Draft
       
   428 
       
   429 -------------------------------------------------------------------------------
       
   430 */
       
   431 TInt CUIEngine::AddTestCaseFile( const TDesC& aModuleName, 
       
   432                                  const TDesC& aCaseFile )
       
   433     {
       
   434     // Check aModuleName max length
       
   435     if( aModuleName.Length() > KMaxName )
       
   436         {
       
   437         __TRACE( KPrint, ( CStifLogger::EError, _L( "CUIEngine::AddTestCaseFile() method's first parameter length is incorrect" ) ) );
       
   438         return KErrArgument;        
       
   439         }
       
   440     // Check aCaseFile max length
       
   441     if( aCaseFile.Length() > KMaxFileName )
       
   442         {
       
   443         __TRACE( KPrint, ( CStifLogger::EError, _L( "CUIEngine::AddTestCaseFile() method's second parameter length is incorrect" ) ) );
       
   444         return KErrArgument;        
       
   445         }
       
   446     
       
   447     TInt ret( KErrNone );
       
   448 
       
   449     // Add given test case file to test module
       
   450     if ( aCaseFile.Length() == 0 )
       
   451         {
       
   452         ret = KErrArgument;
       
   453         __TRACE( KPrint, (  _L( "CUIEngine::AddTestCaseFile. Test case file not defined: ret = %d"), ret  ) );
       
   454         }
       
   455     else
       
   456         {
       
   457         // Add test case file to test case file list of test engine 
       
   458         ret = iTestEngine.AddConfigFile( aModuleName, aCaseFile );
       
   459 
       
   460         if ( ret != KErrNone && ret != KErrAlreadyExists )
       
   461             {
       
   462             __TRACE( KPrint, ( _L( "CUIEngine::AddTestCaseFile. Add test case file failed: ret = %d"), ret  ) );
       
   463             }
       
   464         }
       
   465 
       
   466     return ret;
       
   467     }
       
   468 
       
   469 
       
   470 /*
       
   471 -------------------------------------------------------------------------------
       
   472 
       
   473     Class: CUIEngine
       
   474 
       
   475     Method: RemoveTestCaseFile
       
   476 
       
   477     Description: Remove test case file of test case file list of test engine
       
   478 
       
   479     Parameters: TDesC& aModuleName: in: Testmodule, which own test cases of test case list
       
   480                 TDesC& aCaseFile: in: Test case list, which is removed of test case list
       
   481 
       
   482     Return Values: Symbian OS error: Error code
       
   483 
       
   484     Errors/Exceptions: None
       
   485 
       
   486     Status: Draft
       
   487 
       
   488 -------------------------------------------------------------------------------
       
   489 */
       
   490 TInt CUIEngine::RemoveTestCaseFile( const TDesC& aModuleName, 
       
   491                                     const TDesC& aCaseFile )
       
   492     {   
       
   493     
       
   494     TInt ret( KErrNone );
       
   495 
       
   496     // Remove given test case file from test module
       
   497     if ( aCaseFile.Length() == 0 )
       
   498         {
       
   499         ret = KErrArgument;
       
   500         __TRACE( KPrint, (  _L( "CUIEngine::RemoveTestCaseFile. Test case file not defined: ret = %d"), ret  ) );
       
   501         }
       
   502     else
       
   503         {
       
   504         // Remove test case file  
       
   505         ret = iTestEngine.RemoveConfigFile( aModuleName, aCaseFile );
       
   506 
       
   507         if ( ret != KErrNone )
       
   508             {
       
   509             __TRACE( KPrint, ( _L( "CUIEngine::RemoveTestCaseFile. Remove test case file failed: ret = %d"), ret  ) );
       
   510             }
       
   511         }
       
   512 
       
   513     return ret;
       
   514 
       
   515     }
       
   516 
       
   517 
       
   518 /*
       
   519 -------------------------------------------------------------------------------
       
   520 
       
   521     Class: CUIEngine
       
   522 
       
   523     Method: GetTestCases
       
   524 
       
   525     Description: Get test cases of enumerated list of test engine. Method is copied 
       
   526                  list of test cases to aTestCaseInfo. Copied tests are test cases 
       
   527                  of test module (aTestModule) and defined
       
   528                  in test case file (aTestCaseFile), which are given as argument
       
   529 
       
   530                  Method copied all enumerated test cases if aTestModule
       
   531                  and aTestCaseFile are not defined
       
   532     
       
   533     Parameters: RPointerArray<CTestInfo>& aTestCaseInfo: inout: List of test cases
       
   534                 TDesC& aModuleName: in: Testmodule, which own test cases of test case list
       
   535                 TDesC& aTestCaseFile: in: Test case list, which is got of test case list
       
   536 
       
   537     Return Values: Symbian OS error: Error code
       
   538 
       
   539     Errors/Exceptions: None
       
   540 
       
   541     Status: Draft
       
   542 
       
   543 -------------------------------------------------------------------------------
       
   544 */
       
   545 TInt CUIEngine::GetTestCasesL( RPointerArray<CTestInfo>& aTestCaseInfo,
       
   546                                const TDesC& aTestModule, 
       
   547                                const TDesC& aTestCaseFile )
       
   548     { 
       
   549 	__TRACE( KPrint, (  _L( "GetTestCasesL()") ) );
       
   550 
       
   551     TInt ret(KErrNone);
       
   552     TInt count(0);
       
   553 
       
   554     // Enumerate test cases
       
   555     TCaseCount caseCount;
       
   556 
       
   557     TRequestStatus status;
       
   558     iTestEngine.EnumerateTestCases( caseCount, status );
       
   559     User::WaitForRequest( status );
       
   560     ret = status.Int();
       
   561 
       
   562     // Check that enumerate succeeded
       
   563     if ( ret != KErrNone )
       
   564         {
       
   565         __TRACE( KPrint, (  _L( "CUIEngine::GetTestCases. Test case enumerate failed: ret = %d"), ret ) );
       
   566         TErrorNotification error;
       
   567         error.iText = _L("Can't get test cases");
       
   568         iUi->ErrorPrint ( error );  
       
   569         return ret;
       
   570         }
       
   571 
       
   572     CFixedFlatArray<TTestInfo>* testCases = NULL;
       
   573 
       
   574     // Create test cases to buffer
       
   575     TRAPD( err, testCases = CFixedFlatArray<TTestInfo>::NewL( caseCount() ) );
       
   576     if( err != KErrNone )
       
   577         {        
       
   578         if( err == KErrNoMemory )
       
   579             {
       
   580             _LIT( KNotEnoughHeapMemory, 
       
   581                 "Not enough heap memory available. Either reduce the test case count or increase UI's heap size in mmp file using EPOCHEAPSIZE.");
       
   582             RDebug::Print( KNotEnoughHeapMemory );
       
   583         	__TRACE( KError, ( KNotEnoughHeapMemory ) );        
       
   584         	}
       
   585         else
       
   586            {
       
   587             _LIT( KGeneralError,
       
   588                 "CUIEngine::GetTestCasesL: CFixedFlatArray<TTestInfo>::NewL fails with value: %d");
       
   589             RDebug::Print( KGeneralError, err );
       
   590         	__TRACE( KError, ( KGeneralError, err ) );                   
       
   591            }        	
       
   592         User::Leave( err );
       
   593         }    
       
   594             
       
   595     CleanupStack::PushL( testCases );
       
   596 
       
   597     // Get test cases from Engine.
       
   598     ret = iTestEngine.GetTestCases( *testCases );
       
   599 
       
   600     if ( ret != KErrNone )
       
   601         {
       
   602         __TRACE( KPrint, (  _L( "CUIEngine::GetTestCases. Get test cases failed: ret = %d"), ret ) );
       
   603 
       
   604         CleanupStack::PopAndDestroy( testCases );
       
   605         return ret;
       
   606         }
       
   607 
       
   608     // count of test cases.
       
   609     count = caseCount();
       
   610 
       
   611     __TRACE( KPrint, (  _L( "Test case count: %d"), count ) );
       
   612     
       
   613     HBufC* moduleNameBuf = aTestModule.AllocLC();
       
   614     TPtr moduleName( moduleNameBuf->Des() );
       
   615     TCollationMethod method = 
       
   616         *Mem::CollationMethodByIndex(0); // get the standard method
       
   617     method.iFlags |= TCollationMethod::EFoldCase; // ignore case
       
   618 
       
   619     moduleName.LowerCase();
       
   620 
       
   621     // Remove optional '.DLL' from test module file name
       
   622     TParse parse;
       
   623     parse.Set( moduleName, NULL, NULL );
       
   624     
       
   625     if( !parse.Ext().CompareC(  _L(".dll"), 3, &method ) )
       
   626         {
       
   627         const TInt len = parse.Ext().Length();
       
   628         moduleName.Delete ( moduleName.Length()-len, len );
       
   629         }
       
   630         
       
   631     TBool found = EFalse;
       
   632     // Update iTestCaseTable.
       
   633     for (TInt j=0;j<count;j++, found = EFalse)
       
   634         {
       
   635         // Check, if module defined.
       
   636         if ( aTestModule.Length() > 0 )
       
   637             {
       
   638             // Check, if test case defined.
       
   639             if ( aTestCaseFile.Length() > 0)
       
   640                 {
       
   641                 if( moduleName == KTestScripterName )
       
   642                     {
       
   643                     if( !( *testCases )[j].iConfig.CompareC( aTestCaseFile, 3, &method ) )
       
   644                         {
       
   645                         found = ETrue;
       
   646                         }
       
   647                     }
       
   648                 if( !( *testCases )[j].iModuleName.CompareC( moduleName, 3, &method )
       
   649                     && !( *testCases )[j].iConfig.CompareC( aTestCaseFile, 3, &method ) )
       
   650                     {
       
   651                     found = ETrue;
       
   652                     }
       
   653                 }
       
   654             else
       
   655                 {
       
   656                 if( moduleName == KTestScripterName )
       
   657                     {
       
   658                     // Test Module is TestScripter
       
   659                     if( ( *testCases )[j].iModuleName.Find( KTestScripterName ) != KErrNotFound )
       
   660                         {
       
   661                         // iModuleName name is in 'testscripter_testcasefile'
       
   662                         // format => Find()
       
   663                         found = ETrue;
       
   664                         }
       
   665                     }
       
   666                 if( !( *testCases )[j].iModuleName.CompareC( 
       
   667                                             moduleName, 3, &method ) )
       
   668                     {
       
   669                     found = ETrue;
       
   670                     }
       
   671                 }
       
   672             }
       
   673         else
       
   674             {
       
   675             found = ETrue;
       
   676             }
       
   677         
       
   678         if( found )
       
   679             {
       
   680             // Create tmpTestInfo.
       
   681             CTestInfo *tmpTestInfo = CTestInfo::NewL();
       
   682              
       
   683             CleanupStack::PushL( tmpTestInfo );            
       
   684 
       
   685             // Copy TTestInfo to CTestInfo.
       
   686             tmpTestInfo->SetModuleName( ( *testCases )[j].iModuleName );
       
   687             tmpTestInfo->SetTestCaseTitle( ( *testCases )[j].iTestCaseInfo.iTitle );
       
   688             tmpTestInfo->SetTestCaseNumber( ( *testCases )[j].iTestCaseInfo.iCaseNumber );
       
   689             tmpTestInfo->SetPriority( ( *testCases )[j].iTestCaseInfo.iPriority );
       
   690             tmpTestInfo->SetTimeout( ( *testCases )[j].iTestCaseInfo.iTimeout );
       
   691             tmpTestInfo->SetTestCaseFile( ( *testCases )[j].iConfig );
       
   692             ret = aTestCaseInfo.Append(tmpTestInfo);
       
   693             if( ret != KErrNone )
       
   694                 {
       
   695                 CleanupStack::PopAndDestroy( tmpTestInfo );
       
   696                 }
       
   697             else
       
   698                 {
       
   699                 CleanupStack::Pop( tmpTestInfo );
       
   700                 }
       
   701             }
       
   702         }
       
   703     
       
   704     CleanupStack::PopAndDestroy( moduleNameBuf );
       
   705 
       
   706     CleanupStack::PopAndDestroy( testCases );
       
   707 
       
   708     return ret;
       
   709     }
       
   710 
       
   711 
       
   712 /*
       
   713 -------------------------------------------------------------------------------
       
   714 
       
   715     Class: CUIEngine
       
   716 
       
   717     Method: StartTestCase
       
   718 
       
   719     Description: Start test case execution.
       
   720 
       
   721     Parameters: TInt& aTestId: in: ID for test case. Test ID given of address of
       
   722                 current UIEngineContainer.
       
   723 
       
   724                 const CTestInfo& aTestInfo: in: Test case information
       
   725 
       
   726     Return Values: Symbian OS error: Error code
       
   727 
       
   728     Errors/Exceptions: None
       
   729 
       
   730     Status: Draft
       
   731 
       
   732 -------------------------------------------------------------------------------
       
   733 */
       
   734 TInt CUIEngine::StartTestCase( CUIEngineContainer*& aContainer,
       
   735                               const CTestInfo& aTestInfo )
       
   736     {
       
   737     TInt ret( KErrNone );
       
   738 
       
   739     // Copy CTestInfo to TTestInfo.
       
   740     TTestInfo testCase; 
       
   741     testCase.iModuleName = aTestInfo.ModuleName();
       
   742     testCase.iTestCaseInfo.iTitle = aTestInfo.TestCaseTitle();
       
   743     testCase.iTestCaseInfo.iCaseNumber = aTestInfo.TestCaseNum();
       
   744     testCase.iTestCaseInfo.iPriority = aTestInfo.Priority();
       
   745     testCase.iTestCaseInfo.iTimeout = aTestInfo.Timeout();
       
   746     testCase.iConfig = aTestInfo.TestCaseFile();
       
   747 
       
   748     CUIEngineContainer* container = NULL;
       
   749     TRAP( ret,
       
   750         // Create container.
       
   751         container = 
       
   752             CUIEngineContainer::NewL( this, testCase, iTestEngineServ, iTestEngine );
       
   753     );
       
   754     if( ret != KErrNone )
       
   755         {
       
   756         return ret;
       
   757         }
       
   758     
       
   759     ret = iContainerArray.Append( container );
       
   760     if( ret != KErrNone )
       
   761         {
       
   762         __TRACE( KError, ( CStifLogger::EError, 
       
   763             _L( "CUIEngine::StartTestCase() Append failed, cannot start test case" ) ) );
       
   764         delete container;
       
   765         return ret;
       
   766         }
       
   767         
       
   768     // Call Container to starting test case execution.
       
   769     TRAPD( trapError,
       
   770     // Call Container to starting test case execution.
       
   771     ret = container->StartContainerL();
       
   772     );
       
   773 
       
   774     if(trapError != KErrNone)
       
   775         {
       
   776         __TRACE( KPrint, (  _L( "CUIEngine::StartTestCase. Test case starting failed: trapError = %d"), ret ) );
       
   777         delete container;
       
   778         return trapError;
       
   779         }
       
   780         
       
   781     aContainer = container;
       
   782 
       
   783     return ret;
       
   784     
       
   785     }
       
   786     
       
   787 /*
       
   788 -------------------------------------------------------------------------------
       
   789 
       
   790     Class: CUIEngine
       
   791 
       
   792     Method: AbortStartedTestCase
       
   793 
       
   794     Description: Abort started test case execution.
       
   795 
       
   796     Parameters: CUIEngineContainer* aContainer: in: Container running testcase
       
   797 
       
   798     Return Values: Symbian OS error: Error code
       
   799 
       
   800     Errors/Exceptions: Panics if test case is not found or is already executed
       
   801 
       
   802     Status: Draft
       
   803 
       
   804 -------------------------------------------------------------------------------
       
   805 */
       
   806 void CUIEngine::AbortStartedTestCase( CUIEngineContainer* aContainer )
       
   807     {
       
   808     
       
   809     // Locate container from array
       
   810     TInt index = iContainerArray.Find( aContainer );
       
   811     
       
   812     if( ( index < 0) ||
       
   813         ( aContainer->State() == CUIEngineContainer::EExecuted ) )
       
   814         {
       
   815         __TRACE( KError, ( CStifLogger::EError, 
       
   816             _L( "CUIEngine::AbortStartedTestCase() Testcase executed" ) ) );
       
   817         User::Panic( KUIEngine, KErrAccessDenied );
       
   818         }
       
   819         
       
   820     // Remove and delete container
       
   821     iContainerArray.Remove( index );
       
   822     delete aContainer;
       
   823     
       
   824     }
       
   825 
       
   826     
       
   827 /*
       
   828 -------------------------------------------------------------------------------
       
   829 
       
   830     Class: CUIEngine
       
   831 
       
   832     Method: TestExecuted
       
   833 
       
   834     Description: 
       
   835 
       
   836     Parameters: CUIEngineContainer* aUIEngineContainer: Address of current
       
   837                 CUIEngineContainer is test case ID.
       
   838 
       
   839                 TFullTestResult& aFullTestResult: in: Test result of executed test case
       
   840 
       
   841     Return Values: TInt KErrNone: Always returned KErrNone
       
   842 
       
   843     Errors/Exceptions: None
       
   844 
       
   845     Status: Draft
       
   846 
       
   847 -------------------------------------------------------------------------------
       
   848 */
       
   849 void CUIEngine::TestExecuted( CUIEngineContainer* aContainer, 
       
   850                                TFullTestResult& aFullTestResult )
       
   851     {
       
   852      // Locate container from array
       
   853     TInt index = iContainerArray.Find( aContainer );
       
   854     
       
   855     if( index < 0 )
       
   856         {
       
   857         __TRACE( KError, ( CStifLogger::EError, 
       
   858             _L( "CUIEngine::TestExecuted() Testcase not found" ) ) );
       
   859         User::Panic( KUIEngine, KErrNotFound );
       
   860         }
       
   861     
       
   862     iUi->TestExecuted( aContainer, aFullTestResult );
       
   863     
       
   864     // Remove and delete container.
       
   865     // It is safe to do here,
       
   866     // because container and runner does not have any code after
       
   867     // this function returns.
       
   868     iContainerArray.Remove( index );
       
   869     delete aContainer;
       
   870    
       
   871     }
       
   872 
       
   873 
       
   874 /*
       
   875 -------------------------------------------------------------------------------
       
   876 
       
   877     Class: CUIEngine
       
   878 
       
   879     Method: PrintProg
       
   880 
       
   881     Description: 
       
   882 
       
   883     Parameters: CUIEngineContainer* aContainer: in: Address of current
       
   884                 CUIEngineContainer is test case ID
       
   885 
       
   886                 TTestProgress& aProgress: in: Progress information from test case
       
   887 
       
   888     Return Values: SymbianOS error code
       
   889 
       
   890     Errors/Exceptions: None
       
   891 
       
   892     Status: Draft
       
   893 
       
   894 -------------------------------------------------------------------------------
       
   895 */
       
   896 TInt CUIEngine::PrintProg( CUIEngineContainer* aContainer, 
       
   897                           TTestProgress& aProgress )
       
   898     {
       
   899 
       
   900     return iUi->PrintProg( aContainer, aProgress );
       
   901         
       
   902     }
       
   903 
       
   904 /*
       
   905 -------------------------------------------------------------------------------
       
   906 
       
   907     Class: CUIEngine
       
   908 
       
   909     Method: ErrorPrint
       
   910 
       
   911     Description: 
       
   912 
       
   913     Parameters: TErrorNotification& aError: in: Error information from framework
       
   914 
       
   915     Return Values: SymbianOS error code
       
   916 
       
   917     Errors/Exceptions: None
       
   918 
       
   919     Status: Draft
       
   920 
       
   921 -------------------------------------------------------------------------------
       
   922 */
       
   923 TInt CUIEngine::ErrorPrint( TErrorNotification& aError )
       
   924     {
       
   925 
       
   926     return iUi->ErrorPrint( aError );
       
   927         
       
   928     }
       
   929    
       
   930 /*
       
   931 -------------------------------------------------------------------------------
       
   932 
       
   933     Class: CUIEngine
       
   934 
       
   935     Method: RemoteMsg
       
   936 
       
   937     Description: Forward Ats send.
       
   938 
       
   939     Parameters: const TDesC& aMessage: in: message
       
   940     
       
   941     Return Values: SymbianOS error code
       
   942 
       
   943     Errors/Exceptions: None
       
   944 
       
   945     Status: Draft
       
   946 
       
   947 -------------------------------------------------------------------------------
       
   948 */
       
   949 TInt CUIEngine::RemoteMsg( CUIEngineContainer* aContainer, 
       
   950                            const TDesC& aMessage )
       
   951     {
       
   952 
       
   953     return iUi->RemoteMsg( aContainer, aMessage );
       
   954         
       
   955     }
       
   956 
       
   957 /*
       
   958 -------------------------------------------------------------------------------
       
   959 
       
   960     Class: CUIEngine
       
   961 
       
   962     Method: GoingToReboot
       
   963 
       
   964     Description: Forward reboot indication.
       
   965 
       
   966     Parameters: None
       
   967     
       
   968     Return Values: SymbianOS error code
       
   969 
       
   970     Errors/Exceptions: None
       
   971 
       
   972     Status: Draft
       
   973 
       
   974 -------------------------------------------------------------------------------
       
   975 */
       
   976 TInt CUIEngine::GoingToReboot( CUIEngineContainer* aContainer,
       
   977                                TRequestStatus& aStatus )
       
   978     {
       
   979 
       
   980     return iUi->GoingToReboot( aContainer, aStatus );
       
   981         
       
   982     }
       
   983 
       
   984 
       
   985 /*
       
   986 -------------------------------------------------------------------------------
       
   987 
       
   988     DESCRIPTION
       
   989 
       
   990     CTestInfo: This object contains test case information.
       
   991 
       
   992 -------------------------------------------------------------------------------
       
   993 */
       
   994 
       
   995 // ================= MEMBER FUNCTIONS =========================================
       
   996 
       
   997 
       
   998 /*
       
   999 -------------------------------------------------------------------------------
       
  1000 
       
  1001     Class: CTestInfo
       
  1002 
       
  1003     Method: NewL
       
  1004 
       
  1005     Description:
       
  1006 
       
  1007     Parameters: None
       
  1008 
       
  1009     Return Values: None
       
  1010 
       
  1011     Errors/Exceptions: None
       
  1012 
       
  1013     Status: Draft
       
  1014 
       
  1015 -------------------------------------------------------------------------------
       
  1016 */
       
  1017 EXPORT_C CTestInfo* CTestInfo::NewL()
       
  1018     {
       
  1019     
       
  1020     //RDebug::Print(_L("CTestInfo::NewL()"));
       
  1021     CTestInfo* self =  
       
  1022         new ( ELeave ) CTestInfo();
       
  1023     CleanupStack::PushL( self );
       
  1024     self->ConstructL();
       
  1025     CleanupStack::Pop();
       
  1026     return self;
       
  1027     
       
  1028     }
       
  1029 
       
  1030 /*
       
  1031 -------------------------------------------------------------------------------
       
  1032 
       
  1033     Class: CTestInfo
       
  1034 
       
  1035     Method: CTestInfo
       
  1036 
       
  1037     Description: Default constructor
       
  1038 
       
  1039     C++ default constructor can NOT contain any code, that
       
  1040     might leave.
       
  1041     
       
  1042     Parameters: None
       
  1043     
       
  1044     Return Values: None
       
  1045 
       
  1046     Errors/Exceptions: None
       
  1047 
       
  1048     Status: Draft
       
  1049 
       
  1050 -------------------------------------------------------------------------------
       
  1051 */
       
  1052 CTestInfo::CTestInfo()
       
  1053     {
       
  1054     }
       
  1055 
       
  1056 /*
       
  1057 -------------------------------------------------------------------------------
       
  1058 
       
  1059     Class: CTestInfo
       
  1060 
       
  1061     Method: ConstructL
       
  1062 
       
  1063     Description: Symbian OS second phase constructor
       
  1064 
       
  1065     Symbian OS default constructor can leave.
       
  1066 
       
  1067     Parameters: None
       
  1068 
       
  1069     Return Values: None
       
  1070 
       
  1071     Errors/Exceptions: Leaves if called Open method returns error
       
  1072 
       
  1073     Status: Draft
       
  1074 
       
  1075 -------------------------------------------------------------------------------
       
  1076 */
       
  1077 void CTestInfo::ConstructL()
       
  1078     {   
       
  1079     }
       
  1080     
       
  1081 /*
       
  1082 -------------------------------------------------------------------------------
       
  1083 
       
  1084     Class: CTestInfo
       
  1085 
       
  1086     Method: ~CTestInfo
       
  1087 
       
  1088     Description: Destructor
       
  1089     
       
  1090     Parameters: None
       
  1091 
       
  1092     Return Values: None
       
  1093 
       
  1094     Errors/Exceptions: None
       
  1095 
       
  1096     Status: Draft
       
  1097 
       
  1098 -------------------------------------------------------------------------------
       
  1099 */
       
  1100 CTestInfo::~CTestInfo()
       
  1101     {
       
  1102     
       
  1103     delete iModuleNameBuf;
       
  1104     delete iTitleBuf;
       
  1105     delete iTestCaseFileBuf;
       
  1106     iModuleNameBuf = 0;
       
  1107     iTitleBuf = 0;
       
  1108     iTestCaseFileBuf = 0;
       
  1109     
       
  1110     }
       
  1111 
       
  1112 /*
       
  1113 -------------------------------------------------------------------------------
       
  1114 
       
  1115     Class: CTestInfo
       
  1116 
       
  1117     Method: SetModuleName
       
  1118 
       
  1119     Description: Set module name.
       
  1120     
       
  1121     Parameters: None
       
  1122 
       
  1123     Return Values: Symbian OS error code
       
  1124 
       
  1125     Errors/Exceptions: None
       
  1126 
       
  1127     Status: Draft
       
  1128 
       
  1129 -------------------------------------------------------------------------------
       
  1130 */
       
  1131 TInt CTestInfo::SetModuleName ( const TDesC& aModuleName ) 
       
  1132     {
       
  1133     
       
  1134     iModuleName.Set(0,0); 
       
  1135     delete iModuleNameBuf;
       
  1136 
       
  1137     if( aModuleName.Length() < KTestScripterNameLength )
       
  1138 		{
       
  1139 		iModuleNameBuf = aModuleName.Alloc();
       
  1140 		}
       
  1141     else
       
  1142         {
       
  1143         // Check is TestScripter
       
  1144 	    TPtrC check( aModuleName.Mid( 0, KTestScripterNameLength ) );
       
  1145 	    TInt ret = check.Compare( KTestScripterName );
       
  1146 	    if( ret == KErrNone )
       
  1147 		    {
       
  1148             iModuleNameBuf = ( aModuleName.Mid( 0, KTestScripterNameLength ) ).Alloc();
       
  1149 		    }
       
  1150 	    else
       
  1151 		    {
       
  1152 		    iModuleNameBuf = aModuleName.Alloc();
       
  1153 		    }
       
  1154         }
       
  1155 
       
  1156     if( iModuleNameBuf == NULL )
       
  1157         {
       
  1158         return KErrNoMemory;
       
  1159         }
       
  1160     
       
  1161     iModuleName.Set( iModuleNameBuf->Des() ); 
       
  1162     
       
  1163     return KErrNone;
       
  1164     
       
  1165     }
       
  1166     
       
  1167 /*
       
  1168 -------------------------------------------------------------------------------
       
  1169 
       
  1170     Class: CTestInfo
       
  1171 
       
  1172     Method: SetTestCaseTitle
       
  1173 
       
  1174     Description: Set module name.
       
  1175     
       
  1176     Parameters: None
       
  1177 
       
  1178     Return Values: Symbian OS error code
       
  1179 
       
  1180     Errors/Exceptions: None
       
  1181 
       
  1182     Status: Draft
       
  1183 
       
  1184 -------------------------------------------------------------------------------
       
  1185 */
       
  1186 TInt CTestInfo::SetTestCaseTitle ( const TDesC& aTitle )
       
  1187     { 
       
  1188     
       
  1189     iTitle.Set(0,0); 
       
  1190     delete iTitleBuf;
       
  1191     iTitleBuf = aTitle.Alloc();
       
  1192     if( iTitleBuf == NULL )
       
  1193         {
       
  1194         return KErrNoMemory;
       
  1195         }
       
  1196     
       
  1197     iTitle.Set( iTitleBuf->Des() ); 
       
  1198     
       
  1199     return KErrNone;
       
  1200     
       
  1201     };
       
  1202     
       
  1203 /*
       
  1204 -------------------------------------------------------------------------------
       
  1205 
       
  1206     Class: CTestInfo
       
  1207 
       
  1208     Method: SetTestCaseFile
       
  1209 
       
  1210     Description: Set test case file name.
       
  1211     
       
  1212     Parameters: None
       
  1213 
       
  1214     Return Values: Symbian OS error code
       
  1215 
       
  1216     Errors/Exceptions: None
       
  1217 
       
  1218     Status: Draft
       
  1219 
       
  1220 -------------------------------------------------------------------------------
       
  1221 */
       
  1222 TInt CTestInfo::SetTestCaseFile ( const TDesC& aTestCaseFile )
       
  1223     { 
       
  1224     iTestCaseFile.Set(0,0); 
       
  1225     delete iTestCaseFileBuf;
       
  1226     iTestCaseFileBuf = aTestCaseFile.Alloc();
       
  1227     if( iTestCaseFileBuf == NULL )
       
  1228         {
       
  1229         return KErrNoMemory;
       
  1230         }
       
  1231     
       
  1232     iTestCaseFile.Set( iTestCaseFileBuf->Des() );
       
  1233     
       
  1234     return KErrNone;
       
  1235      
       
  1236     };
       
  1237 
       
  1238 
       
  1239 /*
       
  1240 -------------------------------------------------------------------------------
       
  1241 
       
  1242     Class: CTestInfo
       
  1243 
       
  1244     Method: CopyL
       
  1245 
       
  1246     Description: Copy existing CTestInfo.
       
  1247     
       
  1248     Parameters: None
       
  1249 
       
  1250     Return Values: None
       
  1251 
       
  1252     Errors/Exceptions: Leaves on error
       
  1253 
       
  1254     Status: Draft
       
  1255 
       
  1256 -------------------------------------------------------------------------------
       
  1257 */
       
  1258 void CTestInfo::CopyL( const CTestInfo& aTestInfo )
       
  1259     {
       
  1260 
       
  1261     User::LeaveIfError( SetModuleName( aTestInfo.ModuleName() ));
       
  1262     User::LeaveIfError( SetTestCaseTitle( aTestInfo.TestCaseTitle() ));
       
  1263     User::LeaveIfError( SetTestCaseFile( aTestInfo.TestCaseFile() ));
       
  1264     
       
  1265     iCaseNumber = aTestInfo.TestCaseNum();
       
  1266     iPriority = aTestInfo.Priority();
       
  1267     iTimeout = aTestInfo.Timeout();
       
  1268     iExpectedResult = aTestInfo.ExpectedResult();
       
  1269     
       
  1270     }
       
  1271     
       
  1272 /*
       
  1273 -------------------------------------------------------------------------------
       
  1274 
       
  1275     Class: CTestInfo
       
  1276 
       
  1277     Method: SetTestCaseFile
       
  1278 
       
  1279     Description: Set test case file name.
       
  1280     
       
  1281     Parameters: None
       
  1282 
       
  1283     Return Values: Symbian OS error code
       
  1284 
       
  1285     Errors/Exceptions: None
       
  1286 
       
  1287     Status: Draft
       
  1288 
       
  1289 -------------------------------------------------------------------------------
       
  1290 */
       
  1291 TBool CTestInfo::operator== ( const CTestInfo& aTestInfo ) const
       
  1292     {
       
  1293     
       
  1294     if( ( aTestInfo.ModuleName() == ModuleName() ) &&
       
  1295         ( aTestInfo.Priority() == Priority() ) &&
       
  1296         ( aTestInfo.TestCaseFile() == TestCaseFile() ) &&
       
  1297         ( aTestInfo.TestCaseNum() == TestCaseNum() ) &&
       
  1298         ( aTestInfo.Timeout() == Timeout() ) )
       
  1299         {
       
  1300         return ETrue;
       
  1301         }
       
  1302         
       
  1303              
       
  1304     return EFalse;
       
  1305     
       
  1306     }
       
  1307     
       
  1308 // ================= OTHER EXPORTED FUNCTIONS ================================= 
       
  1309 
       
  1310 //  End of File