stif/StifTFwIf/src/UIStore.cpp
changeset 0 a03f92240627
child 21 f5d4820de50d
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 CUIStore 
       
    15 * and CModule class member functions.
       
    16 *
       
    17 */
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <e32base.h>
       
    21 #include <e32svr.h>
       
    22 #include <f32file.h>
       
    23 #include <e32uid.h>
       
    24 #include <collate.h>
       
    25 
       
    26 #include <StifLogger.h>
       
    27 
       
    28 #include "Logging.h"
       
    29 #include <stifinternal/UIStore.h>
       
    30 #include <stifinternal/UIEngine.h>
       
    31 #include <stifinternal/UIStoreContainer.h>
       
    32 #include "UIStorePopup.h"
       
    33 #include <stifinternal/UIEngineContainer.h>
       
    34 
       
    35 
       
    36 // EXTERNAL DATA STRUCTURES
       
    37 
       
    38 // EXTERNAL FUNCTION PROTOTYPES  
       
    39 
       
    40 // CONSTANTS
       
    41 //@spe _LIT(KNameTxt,"TEST FRAMEWORK");
       
    42 //@spe _LIT(KNameBase,"BASE");
       
    43 _LIT( KUIStore, "CUiStore" );
       
    44 _LIT( KUIStoreIf, "CUiStoreIf" );
       
    45 //_LIT( KUIStoreDefaultDir, "C:\\TestFramework\\" );
       
    46 
       
    47 _LIT( KUIStoreSetStart, "[TestSetStart]" );
       
    48 _LIT( KUIStoreSetEnd, "[TestSetEnd]" );
       
    49 _LIT( KUIStoreSetName, "TestSetName=" );
       
    50 _LIT( KUIStoreSetCaseStart, "[TestSetCaseStart]" );
       
    51 _LIT( KUIStoreSetCaseEnd, "[TestSetCaseEnd]" );
       
    52 _LIT( KUIStoreCaseModuleName, "ModuleName=" );
       
    53 _LIT( KUIStoreTestCaseTitle, "Title=" );
       
    54 _LIT( KUIStoreTestCaseFile, "TestCaseFile="); 
       
    55 _LIT( KUIStoreTestCaseNum, "TestCaseNum=");
       
    56 _LIT( KUIStoreCaseExpectedResult, "ExpectedResult=");
       
    57 _LIT( KUIStoreCasePriority, "Priority="); 
       
    58 _LIT( KUIStoreCaseTimeout, "Timeout=");
       
    59 _LIT( KUIStoreLastStartedCaseIndex, "LastStartedCaseIndex=");
       
    60 
       
    61 
       
    62 _LIT( KUIStoreDefaultRebootFile, "TestFrameworkUIReboot.txt" );
       
    63 _LIT( KUIStoreStartTest, "[StartTestCase]" );
       
    64 _LIT( KUIStoreStartTestEnd, "[StartTestCaseEnd]" );
       
    65 
       
    66 _LIT( KUIStoreCaseStatus, "TestCaseStatus=");
       
    67 _LIT( KUIStoreCaseExecutionResult, "TestCaseExecutionResult=");
       
    68 _LIT( KUIStoreCaseResult, "TestCaseResult=");
       
    69 _LIT( KUIStoreCaseStartTime, "TestCaseStartTime=");
       
    70 _LIT( KUIStoreCaseEndTime, "TestCaseEndTime=");
       
    71 
       
    72 const TInt KRcpHeaderLen = 16;        
       
    73 const TInt KFixedStartedCaseIndex = 10;
       
    74 
       
    75 // MACROS
       
    76 #ifdef LOGGER
       
    77 #undef LOGGER
       
    78 #endif
       
    79 #define LOGGER iLogger
       
    80 
       
    81 // LOCAL CONSTANTS AND MACROS
       
    82 static const TUid KUidTestModule = { 0x101FB3E7 };
       
    83 
       
    84 // MODULE DATA STRUCTURES
       
    85 
       
    86 // LOCAL FUNCTION PROTOTYPES
       
    87 
       
    88 // FORWARD DECLARATIONS
       
    89 
       
    90 
       
    91 // ==================== LOCAL FUNCTIONS =======================================
       
    92 
       
    93 // None
       
    94 
       
    95 // ================= MEMBER FUNCTIONS =========================================
       
    96 
       
    97 /*
       
    98 -------------------------------------------------------------------------------
       
    99 
       
   100     Class: CUIStore
       
   101 
       
   102     Method: NewL
       
   103 
       
   104     Description: Construct the CUIStore class
       
   105 
       
   106     Parameters: None
       
   107 
       
   108     Return Values: CUIStore*                    New object
       
   109 
       
   110     Errors/Exceptions: Leaves if memory allocation fails or
       
   111                        ConstructL leaves.
       
   112 
       
   113     Status: Draft
       
   114 
       
   115 -------------------------------------------------------------------------------
       
   116 */
       
   117 CUIStore* CUIStore::NewL( CUIStoreIf* aUIStoreIf )
       
   118     {
       
   119     
       
   120     CUIStore* self = new ( ELeave ) CUIStore( aUIStoreIf );
       
   121     CleanupStack::PushL( self );
       
   122     self->ConstructL();
       
   123     CleanupStack::Pop( self );
       
   124 
       
   125     return self;
       
   126 
       
   127     }
       
   128 
       
   129 
       
   130 /*
       
   131 -------------------------------------------------------------------------------
       
   132 
       
   133     Class: CUIStore
       
   134 
       
   135     Method: ConstructL
       
   136 
       
   137     Description: Second level constructor.
       
   138 
       
   139     Construct the console
       
   140     Construct module and case containers
       
   141     Retrieve command line parameters
       
   142     Connect to test engine
       
   143 
       
   144     Parameters: None
       
   145 
       
   146     Return Values: None
       
   147 
       
   148     Errors/Exceptions: Leaves if memory allocation fails or fileserver or
       
   149                        test engine can't be connected.
       
   150 
       
   151     Status: Draft
       
   152 
       
   153 -------------------------------------------------------------------------------
       
   154 */
       
   155 void CUIStore::ConstructL( )
       
   156     {
       
   157     }
       
   158 
       
   159 
       
   160 /*
       
   161 -------------------------------------------------------------------------------
       
   162 
       
   163     Class: CUIStore
       
   164 
       
   165     Method: CUIStore
       
   166 
       
   167     Description: Constructor.
       
   168     Initialize non-zero member variables.
       
   169 
       
   170     Parameters: None
       
   171 
       
   172     Return Values: None
       
   173 
       
   174     Errors/Exceptions: None
       
   175 
       
   176     Status: Draft
       
   177 
       
   178 -------------------------------------------------------------------------------
       
   179 */
       
   180 CUIStore::CUIStore( CUIStoreIf* aUIStoreIf ):
       
   181     iUIStoreIf( aUIStoreIf ),
       
   182     iUpdateNeeded( ETrue ),
       
   183     iActivePopupPriority( EPopupPriorityLow )
       
   184     {
       
   185     }
       
   186 
       
   187 /*
       
   188 -------------------------------------------------------------------------------
       
   189 
       
   190     Class: CUIStore
       
   191 
       
   192     Method: ~CUIStore
       
   193 
       
   194     Description: Destructor
       
   195 
       
   196     Parameters: None
       
   197 
       
   198     Return Values: None
       
   199 
       
   200     Errors/Exceptions: None
       
   201 
       
   202     Status: Draft
       
   203 
       
   204 -------------------------------------------------------------------------------
       
   205 */
       
   206 CUIStore::~CUIStore( )
       
   207     {	
       
   208 
       
   209     iFileList.ResetAndDestroy();
       
   210     iFileList.Close(); 
       
   211     iStartedTestSets.ResetAndDestroy();
       
   212     iStartedTestSets.Close();  
       
   213 
       
   214     iStartedTestCases.ResetAndDestroy();
       
   215     iStartedTestCases.Close();
       
   216     
       
   217     iTestSets.ResetAndDestroy();
       
   218     iTestSets.Close();  
       
   219 
       
   220     iTestCases.ResetAndDestroy();
       
   221     iTestCases.Close();
       
   222     
       
   223     iPopups.ResetAndDestroy();
       
   224     iPopups.Close();
       
   225         
       
   226     delete iUIEngine;    
       
   227     iUIEngine = 0;
       
   228 
       
   229     }
       
   230 /*
       
   231 -------------------------------------------------------------------------------
       
   232 
       
   233     Class: CStifTFwIf
       
   234 
       
   235     Method: Open
       
   236 
       
   237     Description: Open test engine.
       
   238 
       
   239     Parameters: TDesC& aTestFrameworkIni: in: Initialization file to Test Framework
       
   240 
       
   241     Return Values: Symbian OS error: Error code
       
   242 
       
   243     Errors/Exceptions: None
       
   244 
       
   245     Status: Draft
       
   246 
       
   247 -------------------------------------------------------------------------------
       
   248 */
       
   249 EXPORT_C  TInt CUIStore::Open( const TDesC& aTestFrameworkIni )
       
   250     {
       
   251     
       
   252     if( aTestFrameworkIni.Length() > KMaxFileName )
       
   253         {
       
   254         return KErrArgument;
       
   255         }
       
   256     
       
   257     TRAPD( err, 
       
   258         iUIEngine = CUIEngine::NewL( this );
       
   259         );
       
   260     if( err != KErrNone )
       
   261         {
       
   262         return err;
       
   263         }
       
   264     
       
   265     TFileName ini( aTestFrameworkIni );
       
   266     // Check given ini file
       
   267     TRAP( err, CheckIniL( ini ) );
       
   268     
       
   269     // Store folder of initialization file to open it again when looking for filters
       
   270     RDebug::Print(_L("CUIStore stores name of ini file [%S]"), &ini);
       
   271     iTestFrameworkIni.Copy(ini);
       
   272     
       
   273     return iUIEngine->Open( ini );
       
   274     
       
   275     }
       
   276 
       
   277 
       
   278 /*
       
   279 -------------------------------------------------------------------------------
       
   280 
       
   281     Class: CUIStore
       
   282 
       
   283     Method: Close
       
   284 
       
   285     Description: Close test engine.
       
   286 
       
   287     Parameters: None
       
   288 
       
   289     Return Values: TInt KErrNone: Always returned KErrNone
       
   290 
       
   291     Errors/Exceptions: None
       
   292 
       
   293     Status: Draft
       
   294 
       
   295 -------------------------------------------------------------------------------
       
   296 */
       
   297 EXPORT_C TInt CUIStore::Close()
       
   298     {
       
   299     
       
   300     TInt ret = KErrNone;
       
   301     if( iUIEngine != NULL )
       
   302         {
       
   303         ret = iUIEngine->Close();
       
   304     
       
   305         delete iUIEngine;    
       
   306         iUIEngine = 0;
       
   307         }
       
   308         
       
   309     return ret;
       
   310 
       
   311     }
       
   312 
       
   313 /*
       
   314 -------------------------------------------------------------------------------
       
   315 
       
   316     Class: CUIStore
       
   317 
       
   318     Method: AddTestModule
       
   319 
       
   320     Description: Add test module to module list of test engine
       
   321 
       
   322     Parameters: TDesC& aModuleName: in: Testmodule, which is added to module list
       
   323                 TDesC& aIniFile: in: Initialization file to the test module
       
   324 
       
   325     Return Values: Symbian OS error: Error code
       
   326 
       
   327     Errors/Exceptions: None
       
   328 
       
   329     Status: Draft
       
   330 
       
   331 -------------------------------------------------------------------------------
       
   332 */
       
   333 EXPORT_C TInt CUIStore::AddTestModule( const TDesC& aModuleName, 
       
   334                                        const TDesC& aIniFile )
       
   335     {
       
   336 
       
   337     TInt ret = iUIEngine->AddTestModule( aModuleName, aIniFile );
       
   338          
       
   339     RefreshAllCases();
       
   340     
       
   341     return ret;
       
   342          
       
   343     }
       
   344 
       
   345 
       
   346 /*
       
   347 -------------------------------------------------------------------------------
       
   348 
       
   349     Class: CUIStore
       
   350 
       
   351     Method: RemoveTestModule
       
   352 
       
   353     Description: Add test module to module list of test engine
       
   354 
       
   355     Parameters: TDesC& aModuleName: in: Testmodule, which is removed of module list
       
   356 
       
   357     Return Values: Symbian OS error: Error code
       
   358 
       
   359     Errors/Exceptions: None
       
   360 
       
   361     Status: Draft
       
   362 
       
   363 -------------------------------------------------------------------------------
       
   364 */
       
   365 EXPORT_C TInt CUIStore::RemoveTestModule( const TDesC& aModuleName )
       
   366     {
       
   367 
       
   368     TInt ret = iUIEngine->RemoveTestModule( aModuleName );
       
   369      
       
   370     RefreshAllCases();
       
   371     
       
   372     return ret;
       
   373     
       
   374     }
       
   375 
       
   376 
       
   377 /*
       
   378 -------------------------------------------------------------------------------
       
   379 
       
   380     Class: CUIStore
       
   381 
       
   382     Method: AddTestCaseFile
       
   383 
       
   384     Description: Add test case file to test case file list of test engine
       
   385 
       
   386     Parameters: TDesC& aModuleName: in: Testmodule, which own test cases of test case list.
       
   387                 TDesC& aCaseFile: in: Test case list, which is added to test case list
       
   388 
       
   389     Return Values: Symbian OS error: Error code
       
   390 
       
   391     Errors/Exceptions: None
       
   392 
       
   393     Status: Draft
       
   394 
       
   395 -------------------------------------------------------------------------------
       
   396 */
       
   397 EXPORT_C TInt CUIStore::AddTestCaseFile( const TDesC& aModuleName, 
       
   398                                          const TDesC& aCaseFile )
       
   399     {
       
   400 
       
   401     TInt ret = iUIEngine->AddTestCaseFile( aModuleName, aCaseFile );
       
   402      
       
   403     RefreshAllCases();
       
   404     
       
   405     return ret;
       
   406     
       
   407     }
       
   408 
       
   409 
       
   410 /*
       
   411 -------------------------------------------------------------------------------
       
   412 
       
   413     Class: CUIStore
       
   414 
       
   415     Method: RemoveTestCaseFile
       
   416 
       
   417     Description: Remove test case file of test case file list of test engine
       
   418 
       
   419     Parameters: TDesC& aModuleName: in: Testmodule, which own test cases of test case list
       
   420                 TDesC& aCaseFile: in: Test case list, which is removed of test case list
       
   421 
       
   422     Return Values: Symbian OS error: Error code
       
   423 
       
   424     Errors/Exceptions: None
       
   425 
       
   426     Status: Draft
       
   427 
       
   428 -------------------------------------------------------------------------------
       
   429 */
       
   430 EXPORT_C TInt CUIStore::RemoveTestCaseFile( const TDesC& aModuleName, 
       
   431                                             const TDesC& aCaseFile )
       
   432     {   
       
   433     
       
   434     TInt ret = iUIEngine->RemoveTestCaseFile( aModuleName, aCaseFile );
       
   435          
       
   436     RefreshAllCases();
       
   437     
       
   438     return ret;
       
   439     
       
   440     }
       
   441     
       
   442 /*
       
   443 -------------------------------------------------------------------------------
       
   444 
       
   445     Class: CUIStore
       
   446 
       
   447     Method: StartTestCase
       
   448 
       
   449     Description: Start selected test case identified with CTestInfo.
       
   450                 anIndex contains index in StartedTestCase array, 
       
   451                 which is valid only during execution of calling 
       
   452                 function.
       
   453 
       
   454     Parameters: const CTestInfo& aTestInfo: in: Test case info
       
   455                 TInt& anIndex: out: Index to StartedTestCaseArray returned 
       
   456 
       
   457     Return Values: Symbian OS error code
       
   458 
       
   459     Errors/Exceptions: None
       
   460 
       
   461     Status: Draft
       
   462 
       
   463 -------------------------------------------------------------------------------
       
   464 */
       
   465 EXPORT_C TInt CUIStore::StartTestCase( const CTestInfo& aTestInfo, 
       
   466                                        TInt& anIndex )
       
   467     {
       
   468     
       
   469     CUIEngineContainer* container = NULL;
       
   470     TInt ret = iUIEngine->StartTestCase( container, aTestInfo );
       
   471     
       
   472     if( ret != KErrNone )
       
   473         {
       
   474         return ret;
       
   475         }
       
   476     
       
   477     CStartedTestCase* testCase = NULL;
       
   478     TRAP( ret,
       
   479         testCase = CStartedTestCase::NewL( aTestInfo, *container );
       
   480        );
       
   481     if( ret != KErrNone )
       
   482         {
       
   483         iUIEngine->AbortStartedTestCase( container );
       
   484         return ret;
       
   485         }
       
   486         
       
   487     ret = iStartedTestCases.Append( testCase );
       
   488     if( ret != KErrNone )
       
   489         {
       
   490         iUIEngine->AbortStartedTestCase( container );
       
   491         delete testCase;
       
   492         return ret;
       
   493         }
       
   494     
       
   495     anIndex =  iStartedTestCases.Find( testCase );
       
   496     
       
   497     if( anIndex < 0 )
       
   498         {
       
   499         User::Panic( KUIStore, KErrNotFound );
       
   500         }
       
   501     
       
   502     iUIStoreIf->Update( testCase, testCase->Status() ); 
       
   503                 
       
   504     return KErrNone;
       
   505     
       
   506     }
       
   507     
       
   508 /*
       
   509 -------------------------------------------------------------------------------
       
   510 
       
   511     Class: CUIStore
       
   512 
       
   513     Method: TestCases
       
   514 
       
   515     Description: Return array of existing test cases.
       
   516 
       
   517     Parameters: RRefArray<CTestInfo>& aTestCases: out: Array of test cases
       
   518                 TDesC& aTestModule: in: Test module name (optional)
       
   519                 TDesC& aTestCaseFile: in: Test case file name (optional) 
       
   520 
       
   521     Return Values: Symbian OS error code
       
   522 
       
   523     Errors/Exceptions: None
       
   524 
       
   525     Status: Draft
       
   526 
       
   527 -------------------------------------------------------------------------------
       
   528 */
       
   529 EXPORT_C TInt CUIStore::TestCases( RRefArray<CTestInfo>& aTestCases, 
       
   530                                    const TDesC& aTestModule,
       
   531                                    const TDesC& aTestCaseFile ) 
       
   532     {
       
   533     
       
   534     TInt ret = UpdateCases();
       
   535     if( ret != KErrNone )
       
   536         {
       
   537         return ret;
       
   538         }
       
   539     TInt count = iTestCases.Count();
       
   540     for( TInt i = 0; i < count; i++ )
       
   541         {
       
   542         if( ( aTestModule.Length() > 0 ) &&
       
   543             ( iTestCases[i]->ModuleName() != aTestModule ) )
       
   544             {
       
   545             continue;
       
   546             }
       
   547         else if( ( aTestCaseFile.Length() > 0 ) &&
       
   548                  ( iTestCases[i]->TestCaseFile() != aTestCaseFile ) )
       
   549             {
       
   550             continue;
       
   551             }
       
   552         aTestCases.Append( *iTestCases[i] );
       
   553         }
       
   554     
       
   555     return KErrNone;
       
   556     
       
   557     }
       
   558 
       
   559 /*
       
   560 -------------------------------------------------------------------------------
       
   561 
       
   562     Class: CUIStore
       
   563 
       
   564     Method: StartedTestCaseL
       
   565 
       
   566     Description: Return started (running/runned) test case
       
   567 
       
   568     Parameters: CStartedTestCase& aTestCase: out: Test case information
       
   569                 TInt anIndex: in: test case index in StartedTestCaseArray
       
   570 
       
   571     Return Values: Reference to CStartedTestCase object
       
   572 
       
   573     Errors/Exceptions: Leaves if anIndex out of range
       
   574 
       
   575     Status: Draft
       
   576 
       
   577 -------------------------------------------------------------------------------
       
   578 */      
       
   579 EXPORT_C CStartedTestCase& CUIStore::StartedTestCaseL( TInt anIndex )
       
   580     {
       
   581     
       
   582     TInt count = iStartedTestCases.Count();
       
   583     if( ( anIndex >= count ) ||
       
   584         ( anIndex < 0 ) )
       
   585         {
       
   586         User::Leave( KErrNotFound );
       
   587         }
       
   588         
       
   589     return *iStartedTestCases[anIndex];
       
   590          
       
   591     }
       
   592 
       
   593 /*
       
   594 -------------------------------------------------------------------------------
       
   595 
       
   596     Class: CUIStore
       
   597 
       
   598     Method: StartedTestCases
       
   599 
       
   600     Description: Return started (running/runned) test cases
       
   601 
       
   602     Parameters: RRefArray<CStartedTestCase>& aTestCases: out: array of test cases
       
   603                 TExecutionStatus aStatus: in: test case status (optional)
       
   604                 TDesC& aTestModule: in: test module name (optional)
       
   605                 TDesC& aTestCaseFile: in: test case file name (optional)
       
   606 
       
   607     Return Values: Symbian OS error code
       
   608 
       
   609     Errors/Exceptions: None
       
   610 
       
   611     Status: Draft
       
   612 
       
   613 -------------------------------------------------------------------------------
       
   614 */            
       
   615 EXPORT_C TInt CUIStore::StartedTestCases( RRefArray<CStartedTestCase>& aTestCases,
       
   616                                           TInt aStatus,
       
   617                                           const TDesC& aTestModule,
       
   618                                           const TDesC& aTestCaseFile )
       
   619     {
       
   620     
       
   621     TInt count = iStartedTestCases.Count();
       
   622     for( TInt i = 0; i < count; i++ )
       
   623         {
       
   624         if( ( aTestModule.Length() > 0 ) &&
       
   625             ( iStartedTestCases[i]->TestInfo().ModuleName() != aTestModule ) )
       
   626             {
       
   627             continue;
       
   628             }
       
   629         else if( ( aTestCaseFile.Length() > 0 ) &&
       
   630                  ( iStartedTestCases[i]->TestInfo().TestCaseFile() != aTestCaseFile ) )
       
   631             {
       
   632             continue;
       
   633             }
       
   634         else if( ( aStatus != CUIStoreIf::EStatusAll) &&
       
   635                  !( iStartedTestCases[i]->Status() & aStatus ) )
       
   636             {
       
   637             continue;
       
   638             }
       
   639         if( aTestCases.Append( *iStartedTestCases[i] ) != KErrNone )
       
   640             {
       
   641             return KErrNoMemory;
       
   642             }
       
   643         }
       
   644     
       
   645     
       
   646     return KErrNone;
       
   647     
       
   648     }
       
   649             
       
   650 /*
       
   651 -------------------------------------------------------------------------------
       
   652 
       
   653     Class: CUIStore
       
   654 
       
   655     Method: Modules
       
   656 
       
   657     Description: Return modules array
       
   658 
       
   659     Parameters: RRefArray<CModule>& aTestModules: out: modules array
       
   660 
       
   661     Return Values: Symbian OS error code
       
   662 
       
   663     Errors/Exceptions: None
       
   664 
       
   665     Status: Draft
       
   666 
       
   667 -------------------------------------------------------------------------------
       
   668 */     
       
   669 EXPORT_C TInt CUIStore::Modules( RRefArray<TDesC>& aTestModules )
       
   670     {
       
   671 
       
   672     TInt ret = UpdateCases();
       
   673     if( ret != KErrNone )
       
   674         {
       
   675         return ret;
       
   676         }
       
   677 
       
   678     // Go through test cases and search if there are new modules 
       
   679     // and add them to aTestModules array 
       
   680     TInt caseCount = iTestCases.Count();
       
   681     TInt moduleCount = 0;
       
   682     TInt caseIndex = 0;
       
   683     TInt moduleIndex = 0;
       
   684     for ( caseIndex = 0; caseIndex < caseCount; caseIndex++ )
       
   685         {
       
   686         // First check modules
       
   687         moduleCount = aTestModules.Count();
       
   688         for ( moduleIndex = 0; moduleIndex < moduleCount; moduleIndex++ )
       
   689             {
       
   690             if( iTestCases[caseIndex]->ModuleName() == 
       
   691                 aTestModules[moduleIndex] )
       
   692                 {
       
   693                 break;
       
   694                 }
       
   695             }
       
   696         if ( moduleIndex == moduleCount )
       
   697             {
       
   698             // New module found
       
   699             if( aTestModules.Append( iTestCases[caseIndex]->ModuleName() ) !=
       
   700                 KErrNone )
       
   701                 {
       
   702                 return KErrNoMemory;
       
   703                 } 
       
   704             }
       
   705         }
       
   706 
       
   707     return KErrNone;
       
   708 
       
   709     }
       
   710 
       
   711 /*
       
   712 -------------------------------------------------------------------------------
       
   713 
       
   714     Class: CUIStore
       
   715 
       
   716     Method: TestCaseFiles
       
   717 
       
   718     Description: Return test case files
       
   719 
       
   720     Parameters: RRefArray<TDesC>& aTestCaseFiles: out: Array of test case files
       
   721                 TDesC& aTestModule: in: test module name (optional)
       
   722 
       
   723     Return Values: Symbian OS error code
       
   724 
       
   725     Errors/Exceptions: None
       
   726 
       
   727     Status: Draft
       
   728 
       
   729 -------------------------------------------------------------------------------
       
   730 */     
       
   731 EXPORT_C TInt CUIStore::TestCaseFiles( RRefArray<TDesC>& aTestCaseFiles,
       
   732                                        const TDesC& aTestModule  )
       
   733     {
       
   734     
       
   735     TInt ret = UpdateCases();
       
   736     if( ret != KErrNone )
       
   737         {
       
   738         return ret;
       
   739         }
       
   740 
       
   741     // Go through test cases and search if there are new test case files 
       
   742     // for specified test module and add them to aTestCaseFiles array 
       
   743     TInt caseCount = iTestCases.Count();
       
   744     TInt fileCount = 0;
       
   745     TInt caseIndex = 0;
       
   746     TInt fileIndex = 0;
       
   747     for ( caseIndex = 0; caseIndex < caseCount; caseIndex++ )
       
   748         {
       
   749         if( ( aTestModule.Length() > 0 ) &&
       
   750             ( aTestModule != iTestCases[caseIndex]->ModuleName() ) )
       
   751             {
       
   752             // Test case file is not for specified module
       
   753             continue;
       
   754             }
       
   755             
       
   756         // First check modules
       
   757         fileCount = aTestCaseFiles.Count();
       
   758         for ( fileIndex = 0; fileIndex < fileCount; fileIndex++ )
       
   759             {
       
   760             if( iTestCases[caseIndex]->TestCaseFile() == 
       
   761                 aTestCaseFiles[fileIndex] )
       
   762                 {
       
   763                 break;
       
   764                 }
       
   765             }
       
   766         if ( fileIndex == fileCount )
       
   767             {
       
   768             // New test case file found
       
   769             if( aTestCaseFiles.Append( iTestCases[caseIndex]->TestCaseFile() ) !=
       
   770                 KErrNone )
       
   771                 {
       
   772                 return KErrNoMemory;
       
   773                 } 
       
   774             }
       
   775         }
       
   776 
       
   777     return KErrNone;
       
   778     
       
   779     }
       
   780 
       
   781 /*
       
   782 -------------------------------------------------------------------------------
       
   783 
       
   784     Class: CUIStore
       
   785 
       
   786     Method: LoadAllModules
       
   787 
       
   788     Description: Loads all TestFramework test modules from \system\libs\ directories 
       
   789                 of all drives. In Secure Platform from \sys\bin directories.
       
   790 
       
   791     Parameters: None
       
   792     
       
   793     Return Values: Symbian OS error code
       
   794 
       
   795     Errors/Exceptions: None
       
   796 
       
   797     Status: Draft
       
   798 
       
   799 -------------------------------------------------------------------------------
       
   800 */ 
       
   801 EXPORT_C TInt CUIStore::LoadAllModules()
       
   802     {
       
   803     
       
   804     RPointerArray<TDesC> testModules;
       
   805     
       
   806     TInt ret = ListAllModules( testModules );
       
   807     if( ret == KErrNone )
       
   808         {
       
   809         for (TInt i= 0; i < testModules.Count(); i++)
       
   810             {
       
   811             iLogger->Log( _L("Add test module: %S"), testModules[i] );
       
   812             ret = iUIEngine->AddTestModule( *testModules[i], KNullDesC );
       
   813             if( ret != KErrNone )
       
   814                 {
       
   815                 iLogger->Log( _L("Add test module %S failed %d"), 
       
   816                     testModules[i], ret );
       
   817                 break;
       
   818                 }
       
   819             }
       
   820         }
       
   821     RefreshAllCases();
       
   822     
       
   823     testModules.ResetAndDestroy();
       
   824     testModules.Close();
       
   825     
       
   826     return ret;
       
   827 
       
   828     }    
       
   829 
       
   830 /*
       
   831 -------------------------------------------------------------------------------
       
   832 
       
   833     Class: CUIStore
       
   834 
       
   835     Method: ListAllModules
       
   836 
       
   837     Description: Lists all TestFramework test modules from \system\libs\ directories 
       
   838                 of all drives. In Secure Platform from \sys\bin directories.
       
   839 
       
   840     Parameters: None
       
   841     
       
   842     Return Values: Symbian OS error code
       
   843 
       
   844     Errors/Exceptions: None
       
   845 
       
   846     Status: Draft
       
   847 
       
   848 -------------------------------------------------------------------------------
       
   849 */ 
       
   850 EXPORT_C TInt CUIStore::ListAllModules( RPointerArray<TDesC>& aModuleNames )
       
   851     {
       
   852     
       
   853     TRAPD( err, ListAllModulesL( aModuleNames ); );
       
   854     return err;
       
   855     
       
   856     }
       
   857     
       
   858 /*
       
   859 -------------------------------------------------------------------------------
       
   860 
       
   861     Class: CUIStore
       
   862 
       
   863     Method: ListAllModulesL
       
   864 
       
   865     Description: Lists all TestFramework test modules from \system\libs\ directories 
       
   866                 of all drives. In Secure Platform from \sys\bin directories.
       
   867 
       
   868     Parameters: None
       
   869     
       
   870     Return Values: Symbian OS error code
       
   871 
       
   872     Errors/Exceptions: None
       
   873 
       
   874     Status: Draft
       
   875 
       
   876 -------------------------------------------------------------------------------
       
   877 */ 
       
   878 void CUIStore::ListAllModulesL( RPointerArray<TDesC>& aModuleNames )
       
   879     {
       
   880 
       
   881     TFileName libDirectory;
       
   882     RFs fsSession;
       
   883     TFileName fullName;
       
   884 
       
   885     // Connect to file server
       
   886 	User::LeaveIfError( fsSession.Connect() ); // Start session
       
   887 	CleanupClosePushL( fsSession );
       
   888 
       
   889     TDriveList drivelist; 
       
   890 	User::LeaveIfError( fsSession.DriveList(drivelist) );
       
   891 	// A TDriveList (the list of available drives), is an array of 
       
   892 	// 26 bytes. Each byte with a non zero value signifies that the 
       
   893 	// corresponding drive is available.
       
   894 
       
   895     // 0x10000079, 0x1000008d, 0x101FB3E7
       
   896     TUidType anEntryUid( KDynamicLibraryUid, 
       
   897                          KSharedLibraryUid, 
       
   898                          KUidTestModule ); 
       
   899     TInt driveNumber; 
       
   900 	TChar driveLetter;
       
   901 
       
   902     CDir* testModules = NULL;
       
   903     
       
   904 	for( driveNumber=EDriveA; driveNumber<=EDriveZ; driveNumber++ )
       
   905 		{
       
   906 		if( !drivelist[driveNumber] ) 
       
   907 			{
       
   908 			// If drive-list entry is zero, drive is not available
       
   909 			continue;
       
   910 			}
       
   911         User::LeaveIfError(fsSession.DriveToChar(driveNumber,driveLetter));
       
   912 
       
   913         libDirectory.Zero();
       
   914         libDirectory.Append( driveLetter );
       
   915         libDirectory.Append( _L(":\\sys\\bin\\*") );
       
   916         
       
   917         iLogger->Log( _L("Searching modules from %S"), &libDirectory );
       
   918 
       
   919         fsSession.GetDir( libDirectory, anEntryUid, ESortNone, testModules );
       
   920 
       
   921         if( !testModules )
       
   922             {
       
   923             // Continue if no test modules found
       
   924             continue;
       
   925             }
       
   926         TInt count = testModules->Count();
       
   927         for (TInt i= 0; i < count; i++)
       
   928             {           
       
   929             fullName = (*testModules)[i].iName;
       
   930             
       
   931             fullName.LowerCase();
       
   932             // Remove optional '.DLL' from file name
       
   933             TParse parse;
       
   934             parse.Set( fullName, NULL, NULL );
       
   935     
       
   936             if ( parse.Ext() == _L(".dll") )
       
   937                 {
       
   938                 const TInt len = parse.Ext().Length();
       
   939                 fullName.Delete( fullName.Length()-len, len );
       
   940                 }
       
   941                         
       
   942             // Exclude internal test modules (testcombiner, testscripter, suevent)
       
   943             _LIT(KTestCombiner, "testcombiner");
       
   944             _LIT(KTestScripter, "testscripter");
       
   945             _LIT(KSUEvent, "suevent");
       
   946             if(fullName != KTestCombiner && fullName != KSUEvent && fullName != KTestScripter)
       
   947                 { 
       
   948                 HBufC* name = fullName.AllocLC();
       
   949                 iLogger->Log( _L("Found: %S"), name );
       
   950                 User::LeaveIfError( aModuleNames.Append( name ) );
       
   951                 CleanupStack::Pop( name );
       
   952                 }
       
   953             }
       
   954         delete testModules;
       
   955         testModules = NULL;
       
   956 		}
       
   957     
       
   958     CleanupStack::PopAndDestroy(); // fsSession 
       
   959     
       
   960     } 
       
   961     
       
   962 /*
       
   963 -------------------------------------------------------------------------------
       
   964 
       
   965     Class: CUIStore
       
   966 
       
   967     Method: CreateTestSet
       
   968 
       
   969     Description: Create new test set.
       
   970 
       
   971     Parameters: TDesC& aSetName: in: test set name (Max length is KMaxName)
       
   972     
       
   973     Return Values: Symbian OS error code
       
   974 
       
   975     Errors/Exceptions: None
       
   976 
       
   977     Status: Draft
       
   978 
       
   979 -------------------------------------------------------------------------------
       
   980 */ 
       
   981 EXPORT_C TInt CUIStore::CreateTestSet( const TDesC& aSetName )
       
   982     {
       
   983     
       
   984     TPtrC setName;
       
   985     TFileName tmp;
       
   986     TInt ret = ParseTestSetName( aSetName, setName, tmp );
       
   987     if( ret != KErrNone )
       
   988         {
       
   989         return ret;
       
   990         }
       
   991         
       
   992     CTestSetInfo* setInfo = NULL;
       
   993     if( FindSetByName( setName, setInfo ) == KErrNone )
       
   994         {
       
   995         return KErrAlreadyExists;
       
   996         }
       
   997     TRAPD( err, 
       
   998         setInfo = CTestSetInfo::NewL( setName );
       
   999         );
       
  1000     if( err != KErrNone )
       
  1001         {
       
  1002         return err;
       
  1003         }
       
  1004     if( iTestSets.Append( setInfo ) != KErrNone )
       
  1005         {
       
  1006         delete setInfo;
       
  1007         return KErrNoMemory;
       
  1008         }
       
  1009             
       
  1010     return KErrNone;
       
  1011     
       
  1012     }
       
  1013     
       
  1014 /*
       
  1015 -------------------------------------------------------------------------------
       
  1016 
       
  1017     Class: CUIStore
       
  1018 
       
  1019     Method: RemoveTestSet
       
  1020 
       
  1021     Description: Remove active test set.
       
  1022 
       
  1023     Parameters: TDesC& aSetName: in: test set name (Max length is KMaxName)
       
  1024     
       
  1025     Return Values: Symbian OS error code
       
  1026 
       
  1027     Errors/Exceptions: None
       
  1028 
       
  1029     Status: Draft
       
  1030 
       
  1031 -------------------------------------------------------------------------------
       
  1032 */ 
       
  1033 EXPORT_C TInt CUIStore::RemoveTestSet( const TDesC& aSetName )
       
  1034     {
       
  1035     
       
  1036     TPtrC setName;
       
  1037     TFileName tmp;
       
  1038     TInt ret = ParseTestSetName( aSetName, setName, tmp );
       
  1039     if( ret != KErrNone )
       
  1040         {
       
  1041         return ret;
       
  1042         }
       
  1043     
       
  1044     TInt count = iTestSets.Count();
       
  1045     TInt index = 0;
       
  1046     for( ; index < count; index++ )
       
  1047         {
       
  1048         if( iTestSets[index]->Name() == setName )
       
  1049             {
       
  1050             break;
       
  1051             }
       
  1052         }
       
  1053     if( index == count ) 
       
  1054         { 
       
  1055         return KErrNotFound;
       
  1056         }
       
  1057 
       
  1058     CTestSetInfo* setInfo = iTestSets[index];
       
  1059     iTestSets.Remove( index );
       
  1060     
       
  1061     // If started test set keeps info about currently removed test set
       
  1062     // then remove also this info
       
  1063     CStartedTestSet *stset;
       
  1064     for(index = 0; index < iStartedTestSets.Count(); index++)
       
  1065         {
       
  1066         stset = iStartedTestSets[index];
       
  1067         if(stset->GetOriginalTestSet() == setInfo)
       
  1068             {
       
  1069             stset->NullOriginalTestSet();
       
  1070             }
       
  1071         }
       
  1072     
       
  1073     delete setInfo;
       
  1074 
       
  1075     return KErrNone;
       
  1076     
       
  1077     }
       
  1078 
       
  1079 /*
       
  1080 -------------------------------------------------------------------------------
       
  1081 
       
  1082     Class: CUIStore
       
  1083 
       
  1084     Method: TestSets
       
  1085 
       
  1086     Description: Query test sets.
       
  1087 
       
  1088     Parameters:RRefArray<CTestSetInfo>& aSetInfos: out: list of test sets
       
  1089     
       
  1090     Return Values: Symbian OS error code
       
  1091 
       
  1092     Errors/Exceptions: None
       
  1093 
       
  1094     Status: Draft
       
  1095 
       
  1096 -------------------------------------------------------------------------------
       
  1097 */ 
       
  1098 EXPORT_C TInt CUIStore::TestSets( RRefArray<CTestSetInfo>& aSetInfos )
       
  1099     {
       
  1100     
       
  1101     TInt count = iTestSets.Count();
       
  1102     for( TInt i=0; i<count; i++ )
       
  1103         {
       
  1104         if( aSetInfos.Append( *iTestSets[i] ) != KErrNone )
       
  1105             {
       
  1106             return KErrNoMemory;
       
  1107             }
       
  1108         }
       
  1109     return KErrNone;
       
  1110     
       
  1111     }       
       
  1112 
       
  1113 /*
       
  1114 -------------------------------------------------------------------------------
       
  1115 
       
  1116     Class: CUIStore
       
  1117 
       
  1118     Method: TestSets
       
  1119 
       
  1120     Description: Query test sets.
       
  1121 
       
  1122     Parameters:RRefArray<CTestSetInfo>& aSetInfos: out: list of test sets
       
  1123     
       
  1124     Return Values: Symbian OS error code
       
  1125 
       
  1126     Errors/Exceptions: None
       
  1127 
       
  1128     Status: Draft
       
  1129 
       
  1130 -------------------------------------------------------------------------------
       
  1131 */ 
       
  1132 EXPORT_C const CTestSetInfo& CUIStore::TestSetL( const TDesC& aSetName  )
       
  1133     {
       
  1134     
       
  1135     TPtrC setName;
       
  1136     TFileName tmp;
       
  1137     User::LeaveIfError( ParseTestSetName( aSetName, setName, tmp ) );
       
  1138         
       
  1139     CTestSetInfo* setInfo = NULL;
       
  1140     User::LeaveIfError( FindSetByName( setName, setInfo ) );
       
  1141     return *setInfo;
       
  1142     
       
  1143     }                
       
  1144         
       
  1145 /*
       
  1146 -------------------------------------------------------------------------------
       
  1147 
       
  1148     Class: CUIStore
       
  1149 
       
  1150     Method: AddToTestSet
       
  1151 
       
  1152     Description: Add test case to test set.
       
  1153 
       
  1154     Parameters: TDesC& aSetName: out: test set name
       
  1155                 CTestInfo& aTestInfo: in: test case to add
       
  1156     
       
  1157     Return Values: Symbian OS error code
       
  1158 
       
  1159     Errors/Exceptions: None
       
  1160 
       
  1161     Status: Draft
       
  1162 
       
  1163 -------------------------------------------------------------------------------
       
  1164 */ 
       
  1165 EXPORT_C TInt CUIStore::AddToTestSet( const TDesC& aSetName, 
       
  1166                                       const CTestInfo& aTestInfo )
       
  1167     {
       
  1168     
       
  1169     TPtrC setName;
       
  1170     TFileName tmp;
       
  1171     TInt ret = ParseTestSetName( aSetName, setName, tmp );
       
  1172     if( ret != KErrNone )
       
  1173         {
       
  1174         return ret;
       
  1175         }
       
  1176         
       
  1177     CTestSetInfo* setInfo = NULL;
       
  1178     ret = FindSetByName( setName, setInfo );
       
  1179     if( ret != KErrNone )
       
  1180         {
       
  1181         return ret;
       
  1182         }
       
  1183     
       
  1184     return setInfo->AddTestCase( aTestInfo );
       
  1185         
       
  1186     }       
       
  1187 
       
  1188 /*
       
  1189 -------------------------------------------------------------------------------
       
  1190 
       
  1191     Class: CUIStore
       
  1192 
       
  1193     Method: InsertToTestSet
       
  1194 
       
  1195     Description: Insert test case to test set.
       
  1196 
       
  1197     Parameters: TDesC& aSetName: out: test set name
       
  1198                 CTestInfo& aTestInfo: in: test case to add
       
  1199                 TInt aPos: in: position to add
       
  1200     
       
  1201     Return Values: Symbian OS error code
       
  1202 
       
  1203     Errors/Exceptions: None
       
  1204 
       
  1205     Status: Draft
       
  1206 
       
  1207 -------------------------------------------------------------------------------
       
  1208 */ 
       
  1209 EXPORT_C TInt CUIStore::InsertToTestSet( const TDesC& aSetName, 
       
  1210                                          const CTestInfo& aTestInfo,
       
  1211                                          TInt aPos  )
       
  1212     {
       
  1213     
       
  1214     TPtrC setName;
       
  1215     TFileName tmp;
       
  1216     TInt ret = ParseTestSetName( aSetName, setName, tmp );
       
  1217     if( ret != KErrNone )
       
  1218         {
       
  1219         return ret;
       
  1220         }
       
  1221         
       
  1222     CTestSetInfo* setInfo = NULL;
       
  1223     ret = FindSetByName( setName, setInfo );
       
  1224     if( ret != KErrNone )
       
  1225         {
       
  1226         return ret;
       
  1227         }
       
  1228     
       
  1229     return setInfo->InsertTestCase( aTestInfo, aPos );
       
  1230         
       
  1231     }       
       
  1232     
       
  1233 /*
       
  1234 -------------------------------------------------------------------------------
       
  1235 
       
  1236     Class: CUIStore
       
  1237 
       
  1238     Method: RemoveFromTestSet
       
  1239 
       
  1240     Description: Remove test case from test set.
       
  1241 
       
  1242     Parameters: TDesC& aSetName: out: test set name
       
  1243                 CTestInfo& aTestInfo: in: test case to remove
       
  1244     
       
  1245     Return Values: Symbian OS error code
       
  1246 
       
  1247     Errors/Exceptions: None
       
  1248 
       
  1249     Status: Draft
       
  1250 
       
  1251 -------------------------------------------------------------------------------
       
  1252 */
       
  1253 EXPORT_C TInt CUIStore::RemoveFromTestSet( const TDesC& aSetName, 
       
  1254                                            const CTestInfo& aTestInfo )
       
  1255     {
       
  1256     
       
  1257     TPtrC setName;
       
  1258     TFileName tmp;
       
  1259     TInt ret = ParseTestSetName( aSetName, setName, tmp );
       
  1260     if( ret != KErrNone )
       
  1261         {
       
  1262         return ret;
       
  1263         }
       
  1264         
       
  1265     CTestSetInfo* setInfo = NULL;
       
  1266     ret = FindSetByName( setName, setInfo );
       
  1267     if( ret != KErrNone )
       
  1268         {
       
  1269         return ret;
       
  1270         }
       
  1271     
       
  1272     return setInfo->RemoveTestCase( aTestInfo );
       
  1273     
       
  1274     }       
       
  1275 
       
  1276 /*
       
  1277 -------------------------------------------------------------------------------
       
  1278 
       
  1279     Class: CUIStore
       
  1280 
       
  1281     Method: SaveTestSet
       
  1282 
       
  1283     Description: Save test set. Deprecated, SaveTestSet2 to be used instead 
       
  1284 
       
  1285     Parameters: TDesC&:  out: test set name
       
  1286     
       
  1287     Return Values: Symbian OS error code
       
  1288 
       
  1289     Errors/Exceptions: None
       
  1290 
       
  1291     Status: Draft
       
  1292 
       
  1293 -------------------------------------------------------------------------------
       
  1294 */
       
  1295 EXPORT_C TInt CUIStore::SaveTestSet( const TDesC& /* aSetName */ )
       
  1296     {  
       
  1297         
       
  1298     return KErrNotSupported;
       
  1299     
       
  1300     }  
       
  1301 
       
  1302 /*
       
  1303 -------------------------------------------------------------------------------
       
  1304 
       
  1305     Class: CUIStore
       
  1306 
       
  1307     Method: SaveTestSet2
       
  1308 
       
  1309     Description: Save test set.
       
  1310 
       
  1311     Parameters: TDes& aSetName: out: test set name
       
  1312     
       
  1313     Return Values: Symbian OS error code
       
  1314 
       
  1315     Errors/Exceptions: None
       
  1316 
       
  1317     Status: Draft
       
  1318 
       
  1319 -------------------------------------------------------------------------------
       
  1320 */
       
  1321 EXPORT_C TInt CUIStore::SaveTestSet2( TDes& aSetName )
       
  1322     {
       
  1323     
       
  1324     TPtrC setName;
       
  1325     TFileName tmp;
       
  1326 
       
  1327     TTime current;
       
  1328     TDateTime date_rep;
       
  1329     current.HomeTime();
       
  1330     date_rep = current.DateTime();
       
  1331     TBuf<32> currSetName;
       
  1332     _LIT(f_ext,".set");
       
  1333     
       
  1334     //create "test set name" string
       
  1335      currSetName.AppendNum(date_rep.Year());
       
  1336      currSetName.Append('_');
       
  1337      currSetName.AppendNum(date_rep.Month()+1); // Incrimination necessary, because Day and Month fields of TDateTime class are 0 based
       
  1338      currSetName.Append('_');
       
  1339      currSetName.AppendNum(date_rep.Day()+1);
       
  1340      currSetName.Append('_');
       
  1341      currSetName.AppendNum(date_rep.Hour());
       
  1342      currSetName.Append('_');
       
  1343      currSetName.AppendNum(date_rep.Minute());
       
  1344      currSetName.Append(f_ext);
       
  1345 
       
  1346     TInt ret = ParseTestSetName( aSetName, setName, tmp );
       
  1347     if( ret != KErrNone )
       
  1348         {
       
  1349         return ret;
       
  1350         }
       
  1351         
       
  1352     CTestSetInfo* setInfo = NULL;
       
  1353     ret = FindSetByName( setName, setInfo );
       
  1354     if( ret != KErrNone )
       
  1355         {
       
  1356         return ret;
       
  1357         }
       
  1358      
       
  1359     TRAPD( err,
       
  1360         SaveTestSetL( *setInfo, currSetName );
       
  1361         );
       
  1362     
       
  1363     aSetName.Copy(currSetName);
       
  1364     
       
  1365     return err;
       
  1366     
       
  1367     }  
       
  1368 
       
  1369 /*
       
  1370 -------------------------------------------------------------------------------
       
  1371 
       
  1372     Class: CUIStore
       
  1373 
       
  1374     Method: LoadTestSet
       
  1375 
       
  1376     Description: Load test set.
       
  1377 
       
  1378     Parameters: TDesC& aSetName: out: test set name
       
  1379     
       
  1380     Return Values: Symbian OS error code
       
  1381 
       
  1382     Errors/Exceptions: None
       
  1383 
       
  1384     Status: Draft
       
  1385 
       
  1386 -------------------------------------------------------------------------------
       
  1387 */
       
  1388 EXPORT_C TInt CUIStore::LoadTestSet( const TDesC& aSetName )
       
  1389     {
       
  1390     
       
  1391     TPtrC setName;
       
  1392     TFileName tmp;
       
  1393     TInt ret = ParseTestSetName( aSetName, setName, tmp );
       
  1394     if( ret != KErrNone )
       
  1395         {
       
  1396         return ret;
       
  1397         }
       
  1398         
       
  1399     TRAPD( err,
       
  1400         LoadTestSetL( setName, aSetName );
       
  1401         );
       
  1402     
       
  1403      if( err != KErrNone && err != KErrAlreadyExists )
       
  1404         {
       
  1405         RemoveTestSet( setName );
       
  1406         }
       
  1407             
       
  1408     return err;
       
  1409     
       
  1410     }       
       
  1411 
       
  1412 /*
       
  1413 -------------------------------------------------------------------------------
       
  1414 
       
  1415     Class: CUIStore
       
  1416 
       
  1417     Method: UpdateTestSet
       
  1418 
       
  1419     Description: Updates (on storage) earlier saved test set.
       
  1420 
       
  1421     Parameters: CTestSetInfo& aSetInfo: in: test set
       
  1422     
       
  1423     Return Values: Symbian OS error code
       
  1424 
       
  1425     Errors/Exceptions: None
       
  1426 
       
  1427     Status: Approved
       
  1428 
       
  1429 -------------------------------------------------------------------------------
       
  1430 */
       
  1431 EXPORT_C TInt CUIStore::UpdateTestSet(CTestSetInfo& aSetInfo)
       
  1432     {
       
  1433     TRAPD(err,
       
  1434           UpdateTestSetL(aSetInfo, aSetInfo.Name());
       
  1435          );
       
  1436          
       
  1437     return err;
       
  1438     }  
       
  1439         
       
  1440 /*
       
  1441 -------------------------------------------------------------------------------
       
  1442 
       
  1443     Class: CUIStore
       
  1444 
       
  1445     Method: StartTestSet
       
  1446 
       
  1447     Description: Start selected test set identified with CTestSetInfo.
       
  1448 
       
  1449     Parameters: const CTestSetInfo& aTestSetInfo: in: Started test set
       
  1450                 TInt& anIndex: out index in StartedTestSet array, 
       
  1451                     which is valid only during execution of calling 
       
  1452                     function.
       
  1453     
       
  1454     Return Values: Symbian OS error code
       
  1455 
       
  1456     Errors/Exceptions: None
       
  1457 
       
  1458     Status: Draft
       
  1459 
       
  1460 -------------------------------------------------------------------------------
       
  1461 */      
       
  1462 EXPORT_C TInt CUIStore::StartTestSet( const CTestSetInfo& aTestSetInfo,
       
  1463                                       TInt& anIndex,
       
  1464                                       CStartedTestSet::TSetType aType )
       
  1465     {
       
  1466     return StartTestSet(aTestSetInfo, anIndex, aType, EFalse);    
       
  1467     }       
       
  1468 
       
  1469 /*
       
  1470 -------------------------------------------------------------------------------
       
  1471 
       
  1472     Class: CUIStore
       
  1473 
       
  1474     Method: StartTestSet
       
  1475 
       
  1476     Description: Start selected test set identified with CTestSetInfo.
       
  1477 
       
  1478     Parameters: const CTestSetInfo& aTestSetInfo: in: Started test set
       
  1479                 TInt& anIndex: out index in StartedTestSet array, 
       
  1480                     which is valid only during execution of calling 
       
  1481                     function.
       
  1482                 TSetType aType: sequential or paraller
       
  1483                 TBool aNotExecutedCasesMode: only test case which haven't been
       
  1484                     executed yet
       
  1485     
       
  1486     Return Values: Symbian OS error code
       
  1487 
       
  1488     Errors/Exceptions: None
       
  1489 
       
  1490     Status: Approved
       
  1491 
       
  1492 -------------------------------------------------------------------------------
       
  1493 */      
       
  1494 EXPORT_C TInt CUIStore::StartTestSet( const CTestSetInfo& aTestSetInfo,
       
  1495                                       TInt& anIndex,
       
  1496                                       CStartedTestSet::TSetType aType,
       
  1497                                       TBool aNotStartedCasesMode )
       
  1498     {
       
  1499     
       
  1500     TInt ret = KErrNone;
       
  1501     
       
  1502     CStartedTestSet* set = NULL;
       
  1503     TRAPD( err, 
       
  1504         set = CStartedTestSet::NewL( this, aTestSetInfo, aType );
       
  1505         );
       
  1506     if( err != KErrNone )
       
  1507         {
       
  1508         return err;
       
  1509         }
       
  1510 
       
  1511     if( iStartedTestSets.Append( set ) != KErrNone )
       
  1512         {
       
  1513         delete set;
       
  1514         return KErrNoMemory;
       
  1515         } 
       
  1516 
       
  1517     // Set mode in which only still not executed test cases will be run.
       
  1518     // It applies only to sequential execution.
       
  1519     set->SetNotStartedCasesMode(aNotStartedCasesMode);
       
  1520     
       
  1521     ret = set->StartNext();
       
  1522         
       
  1523     anIndex = iStartedTestSets.Find( set );
       
  1524     if( anIndex < 0 )
       
  1525         {
       
  1526         User::Panic( KUIStore, KErrNotFound );
       
  1527         }
       
  1528     // Check that testset starting was successful
       
  1529     if( ret != KErrNone )
       
  1530         {
       
  1531         iStartedTestSets.Remove( anIndex );
       
  1532         anIndex = KErrNotFound; // safety
       
  1533         delete set;
       
  1534         return ret;
       
  1535         }
       
  1536     
       
  1537     return KErrNone;
       
  1538     
       
  1539     }       
       
  1540 
       
  1541 /*
       
  1542 -------------------------------------------------------------------------------
       
  1543 
       
  1544     Class: CUIStore
       
  1545 
       
  1546     Method: AbortTestSet
       
  1547 
       
  1548     Description: Abort running test set.
       
  1549 
       
  1550     Parameters: None
       
  1551     
       
  1552     Return Values: Symbian OS error code
       
  1553 
       
  1554     Errors/Exceptions: None
       
  1555 
       
  1556     Status: Draft
       
  1557 
       
  1558 -------------------------------------------------------------------------------
       
  1559 */
       
  1560 EXPORT_C TInt CUIStore::AbortTestSet( CStartedTestSet& aSetInfo )
       
  1561     {
       
  1562         
       
  1563     return aSetInfo.Abort();
       
  1564     
       
  1565     } 
       
  1566 
       
  1567 
       
  1568 /*
       
  1569 -------------------------------------------------------------------------------
       
  1570 
       
  1571     Class: CUIStore
       
  1572 
       
  1573     Method: StartedTestSetL
       
  1574 
       
  1575     Description: Return started (running/runned) test set.
       
  1576 
       
  1577     Parameters: TInt anIndex: out index in StartedTestSet array 
       
  1578                         
       
  1579     Return Values: CStartedTestSet&: reference to test set
       
  1580 
       
  1581     Errors/Exceptions: Leaves on error.
       
  1582 
       
  1583     Status: Draft
       
  1584 
       
  1585 -------------------------------------------------------------------------------
       
  1586 */  
       
  1587 EXPORT_C CStartedTestSet& CUIStore::StartedTestSetL( TInt anIndex)
       
  1588     {
       
  1589     
       
  1590     if( anIndex < 0 ||
       
  1591         anIndex >= iStartedTestSets.Count() )
       
  1592         {
       
  1593         User::Leave( KErrNotFound );
       
  1594         }
       
  1595     
       
  1596     return *iStartedTestSets[ anIndex ];
       
  1597     
       
  1598     }       
       
  1599 
       
  1600 
       
  1601 /*
       
  1602 -------------------------------------------------------------------------------
       
  1603 
       
  1604     Class: CUIStore
       
  1605 
       
  1606     Method: StartedTestSets
       
  1607 
       
  1608     Description: Return started (running/runned) test cases
       
  1609 
       
  1610     Parameters: RRefArray<CStartedTestSet>& aTestCases: out: list of test sets
       
  1611                 TInt aStatus: in: status of queried sets
       
  1612                         
       
  1613     Return Values: Symbian OS error code
       
  1614 
       
  1615     Errors/Exceptions: None
       
  1616 
       
  1617     Status: Draft
       
  1618 
       
  1619 -------------------------------------------------------------------------------
       
  1620 */
       
  1621 EXPORT_C TInt CUIStore::StartedTestSets( RRefArray<CStartedTestSet>& aTestSets,
       
  1622                                          TInt aStatus )
       
  1623     {    
       
  1624     
       
  1625     TInt count = iStartedTestSets.Count();
       
  1626     
       
  1627     for( TInt i = 0; i < count; i++ )
       
  1628         {
       
  1629         if( ( aStatus != CUIStoreIf::ESetAll) &&
       
  1630             !( iStartedTestSets[i]->Status() & aStatus ) )
       
  1631             {
       
  1632             continue;
       
  1633             }
       
  1634         if( aTestSets.Append( *iStartedTestSets[i] ) != KErrNone )
       
  1635             {
       
  1636             return KErrNoMemory;
       
  1637             }
       
  1638         }        
       
  1639         
       
  1640     return KErrNone;
       
  1641     
       
  1642     }           
       
  1643 
       
  1644 /*
       
  1645 -------------------------------------------------------------------------------
       
  1646 
       
  1647     Class: CUIStore
       
  1648 
       
  1649     Method: LoadSavedTestCases
       
  1650 
       
  1651     Description: Load saved testcases.
       
  1652 
       
  1653     Parameters: None
       
  1654     
       
  1655     Return Values: Symbian OS error code
       
  1656 
       
  1657     Errors/Exceptions: None
       
  1658 
       
  1659     Status: Draft
       
  1660 
       
  1661 -------------------------------------------------------------------------------
       
  1662 */
       
  1663 EXPORT_C TInt CUIStore::LoadSavedTestCases()
       
  1664     {
       
  1665     
       
  1666     TRAPD( err,
       
  1667         LoadExecutedTestCasesL();
       
  1668         );
       
  1669     
       
  1670     return err;
       
  1671     
       
  1672     }       
       
  1673 /*
       
  1674 -------------------------------------------------------------------------------
       
  1675 
       
  1676     Class: CUIStore
       
  1677 
       
  1678     Method: GetTestSetsList
       
  1679 
       
  1680     Description: Returns menu item text.
       
  1681 
       
  1682     Parameters: const TInt                :in:      Menu index
       
  1683 
       
  1684     Return Values: const TDesC&                     Menu line text
       
  1685 
       
  1686     Errors/Exceptions: None
       
  1687 
       
  1688     Status: Draft
       
  1689 
       
  1690 -------------------------------------------------------------------------------
       
  1691 */
       
  1692 EXPORT_C TInt CUIStore::GetTestSetsList( RRefArray<TDesC>& aArray )
       
  1693     {
       
  1694     RFs fileReader;
       
  1695     CDir* dirContents = NULL;
       
  1696     _LIT(KSetPattern,".set");
       
  1697     TInt entNum = 0;
       
  1698     TInt ret = 0;
       
  1699     HBufC* fName = NULL;
       
  1700 
       
  1701     
       
  1702     ret = fileReader.Connect();
       
  1703 
       
  1704     if (ret != KErrNone)
       
  1705     	return ret;
       
  1706     
       
  1707     
       
  1708     ret = fileReader.GetDir(KUIStoreDefaultDir,
       
  1709     						KEntryAttNormal | KEntryAttHidden | KEntryAttSystem,
       
  1710     						ESortByName | EDirsFirst | EAscending,
       
  1711     						dirContents);
       
  1712     fileReader.Close();	
       
  1713     if (ret != KErrNone)
       
  1714     	{    		
       
  1715 	    delete dirContents;
       
  1716 	    return ret;
       
  1717 	    }
       
  1718     entNum = dirContents->Count();
       
  1719     for (int i = 0;i<entNum;i++)
       
  1720     	{
       
  1721     	if ((!dirContents->operator[](i).IsDir())&&
       
  1722     		 dirContents->operator[](i).iName.Find(KSetPattern)!=KErrNotFound)
       
  1723     			{
       
  1724     			  TRAPD( err, fName = HBufC::NewL(64) );		       			             
       
  1725     			  if( err != KErrNone )
       
  1726     			    {
       
  1727     			      delete dirContents;
       
  1728     			      return err;
       
  1729     			    }    		 	
       
  1730     		    *fName =  dirContents->operator[](i).iName;
       
  1731     		 	ret = iFileList.Append(fName);
       
  1732     		 	if (ret != KErrNone)
       
  1733     		 		{
       
  1734     					delete fName;
       
  1735     					delete dirContents;
       
  1736     					return ret;	
       
  1737     		 		}
       
  1738     		 	ret = aArray.Append(*fName);
       
  1739 			 	if (ret != KErrNone)
       
  1740     		 		{
       
  1741     					delete fName;
       
  1742     					delete dirContents;
       
  1743     					return ret;	
       
  1744     		 		}
       
  1745 
       
  1746     			}    
       
  1747     	}
       
  1748     delete dirContents;
       
  1749     return KErrNone; 
       
  1750 
       
  1751     }
       
  1752 
       
  1753 
       
  1754 /*
       
  1755 -------------------------------------------------------------------------------
       
  1756 
       
  1757     Class: CUIStore
       
  1758 
       
  1759     Method: FindSetByName
       
  1760 
       
  1761     Description: Finds test set by name.
       
  1762 
       
  1763     Parameters: const TDesC& aSetName: in: set name 
       
  1764                 CTestSetInfo*& aSetInfo: out: pointer to test set
       
  1765                         
       
  1766     Return Values: Symbian OS error code
       
  1767 
       
  1768     Errors/Exceptions: None
       
  1769 
       
  1770     Status: Draft
       
  1771 
       
  1772 -------------------------------------------------------------------------------
       
  1773 */
       
  1774 TInt CUIStore::FindSetByName( const TDesC& aSetName, 
       
  1775                               CTestSetInfo*& aSetInfo )
       
  1776     {
       
  1777     
       
  1778     TInt count = iTestSets.Count();
       
  1779     for( TInt i=0; i<count; i++ )
       
  1780         {
       
  1781         if( iTestSets[i]->Name() == aSetName )
       
  1782             {
       
  1783             aSetInfo = iTestSets[i];
       
  1784             return KErrNone;
       
  1785             }
       
  1786         }
       
  1787     
       
  1788     return KErrNotFound;
       
  1789     
       
  1790     }
       
  1791     
       
  1792 /*
       
  1793 -------------------------------------------------------------------------------
       
  1794 
       
  1795     Class: CUIStore
       
  1796 
       
  1797     Method: FindSetByCase
       
  1798 
       
  1799     Description: Finds test set by name.
       
  1800 
       
  1801     Parameters:  const CStartedTestCase* aTestCase: in: running test case 
       
  1802                  CStartedTestSet*& aSet: out: set running test case
       
  1803                         
       
  1804     Return Values: KErrNotFound: test case is not runned by any test set
       
  1805                    KErrNone: test case was runned by aSet
       
  1806                    
       
  1807 
       
  1808     Errors/Exceptions: None
       
  1809 
       
  1810     Status: Draft
       
  1811 
       
  1812 -------------------------------------------------------------------------------
       
  1813 */
       
  1814 TInt CUIStore::FindStartedSetByCase( const CStartedTestCase* aTestCase, 
       
  1815                                      CStartedTestSet*& aSet  )
       
  1816     {
       
  1817     
       
  1818     TInt count = iStartedTestSets.Count();
       
  1819     for( TInt i=0; i<count; i++ )
       
  1820         {
       
  1821         if( iStartedTestSets[i]->IsRunning( aTestCase ) )
       
  1822             {
       
  1823             aSet = iStartedTestSets[i];
       
  1824             return KErrNone;
       
  1825             }
       
  1826         }
       
  1827     
       
  1828     return KErrNotFound;
       
  1829     
       
  1830     }
       
  1831 
       
  1832 /*
       
  1833 -------------------------------------------------------------------------------
       
  1834 
       
  1835     Class: CUIStore
       
  1836 
       
  1837     Method: LoadTestSetL
       
  1838 
       
  1839     Description: Load test set.
       
  1840 
       
  1841     Parameters: TDesC& aSetName: out: test set name
       
  1842     
       
  1843     Return Values: Symbian OS error code
       
  1844 
       
  1845     Errors/Exceptions: None
       
  1846 
       
  1847     Status: Draft
       
  1848 
       
  1849 -------------------------------------------------------------------------------
       
  1850 */
       
  1851 void CUIStore::LoadTestSetL( const TDesC& aSetName, const TDesC& aSetFileName )
       
  1852     {
       
  1853     
       
  1854     TPtrC tmp;
       
  1855     TInt num;
       
  1856     TInt high;
       
  1857     TInt64 interval;
       
  1858     
       
  1859     CStifParser* parser = NULL;
       
  1860     
       
  1861     TRAPD( err,
       
  1862         parser = CStifParser::NewL( _L(""), aSetFileName );
       
  1863         );
       
  1864     if( err != KErrNone )
       
  1865         {
       
  1866         parser = CStifParser::NewL( KUIStoreDefaultDir, aSetName );
       
  1867         }
       
  1868         
       
  1869     CleanupStack::PushL( parser );
       
  1870     
       
  1871     CStifSectionParser* section = 
       
  1872         parser->SectionL( KUIStoreSetStart, KUIStoreSetEnd );
       
  1873     CleanupStack::PushL( section );
       
  1874     
       
  1875     CStifItemParser* item = section->GetItemLineL( KUIStoreSetName );
       
  1876     CleanupStack::PushL( item );
       
  1877     
       
  1878     User::LeaveIfError( item->GetString( KUIStoreSetName, tmp ) );
       
  1879     
       
  1880 	// get the standard method
       
  1881 	TCollationMethod method = *Mem::CollationMethodByIndex(0);
       
  1882 	// ignore case
       
  1883     method.iFlags |= TCollationMethod::EFoldCase;
       
  1884     
       
  1885 	TInt compare = aSetName.CompareC( tmp, 3, &method );
       
  1886 	if( compare != KErrNone )
       
  1887         {
       
  1888         User::LeaveIfError( KErrNotFound );
       
  1889         }
       
  1890         
       
  1891     CleanupStack::PopAndDestroy( item );
       
  1892         
       
  1893     // Get started test case (if possible)
       
  1894     TUint lastStartedCaseIndex = 0;
       
  1895     item = section->GetItemLineL(KUIStoreLastStartedCaseIndex);
       
  1896     if(item)
       
  1897         {
       
  1898         CleanupStack::PushL(item);
       
  1899         TInt r = item->GetInt(KUIStoreLastStartedCaseIndex, lastStartedCaseIndex);
       
  1900         CleanupStack::PopAndDestroy(item);
       
  1901         if(r != KErrNone)
       
  1902             {
       
  1903             __TRACE(KInit, (_L("Could not read [%S] from test set file. Result [%d]."), &KUIStoreLastStartedCaseIndex, r));
       
  1904             }
       
  1905         }
       
  1906     else
       
  1907         {
       
  1908         __TRACE(KInit, (_L("Could not find [%S] from test set file."), &KUIStoreLastStartedCaseIndex));
       
  1909         }
       
  1910 
       
  1911     User::LeaveIfError( CreateTestSet( aSetName ) );
       
  1912     
       
  1913     CTestSetInfo* setInfo = NULL;
       
  1914     User::LeaveIfError( FindSetByName( aSetName, setInfo ) );
       
  1915     
       
  1916     // Update started case
       
  1917     setInfo->SetLastStartedCaseIndex(lastStartedCaseIndex);
       
  1918     
       
  1919     CTestInfo* testInfo = CTestInfo::NewL();
       
  1920     CleanupStack::PushL( testInfo );    
       
  1921 
       
  1922     CStifSectionParser* subSection = 
       
  1923         section->SubSectionL( KUIStoreSetCaseStart, KUIStoreSetCaseEnd );
       
  1924     
       
  1925     while( subSection )
       
  1926         {
       
  1927         CleanupStack::PushL( subSection );    
       
  1928         
       
  1929         // Get module name
       
  1930         // Mandatory, leave if not found
       
  1931         User::LeaveIfError( 
       
  1932             subSection->GetLine( KUIStoreCaseModuleName, tmp, ENoTag ) );
       
  1933         testInfo->SetModuleName( tmp );
       
  1934     
       
  1935         // Get test case title
       
  1936         // Mandatory, leave if not found
       
  1937         User::LeaveIfError( 
       
  1938             subSection->GetLine( KUIStoreTestCaseTitle, tmp, ENoTag ) );
       
  1939         testInfo->SetTestCaseTitle( tmp );
       
  1940         
       
  1941         // Get test case file
       
  1942         num = subSection->GetLine( KUIStoreTestCaseFile, tmp, ENoTag );
       
  1943         if( ( num == KErrNone ) &&
       
  1944             ( tmp.Length() > 0 ) )
       
  1945             {
       
  1946             // Optional
       
  1947             testInfo->SetTestCaseFile( tmp );
       
  1948             }
       
  1949         
       
  1950         // Get test case number
       
  1951         item = subSection->GetItemLineL( KUIStoreTestCaseNum );
       
  1952         CleanupStack::PushL( item );
       
  1953         // Mandatory, leave if not found
       
  1954         User::LeaveIfError( item->GetInt( KUIStoreTestCaseNum, num ));
       
  1955         testInfo->SetTestCaseNumber( num );
       
  1956         CleanupStack::PopAndDestroy( item );    
       
  1957         
       
  1958         // Get test case priority
       
  1959         item = subSection->GetItemLineL( KUIStoreCasePriority );
       
  1960         CleanupStack::PushL( item );
       
  1961         // Mandatory, leave if not found
       
  1962         User::LeaveIfError( item->GetInt( KUIStoreCasePriority, num ));
       
  1963         testInfo->SetPriority( num );
       
  1964         CleanupStack::PopAndDestroy( item ); 
       
  1965         
       
  1966         // Get test case timeout
       
  1967         item = subSection->GetItemLineL( KUIStoreCaseTimeout );
       
  1968         CleanupStack::PushL( item );
       
  1969         // Mandatory, leave if not found
       
  1970         User::LeaveIfError( item->GetInt( KUIStoreCaseTimeout, num ));
       
  1971         User::LeaveIfError( item->GetNextInt( high ));
       
  1972         //@js<--remove--> interval.Set( high, num );
       
  1973         interval = MAKE_TINT64( high, num );
       
  1974         TTimeIntervalMicroSeconds timeout( interval );
       
  1975         testInfo->SetTimeout( timeout );
       
  1976         CleanupStack::PopAndDestroy( item ); 
       
  1977         
       
  1978         User::LeaveIfError( setInfo->AddTestCase( *testInfo ) );
       
  1979         
       
  1980         CleanupStack::PopAndDestroy( subSection );    
       
  1981         subSection = 
       
  1982             section->NextSubSectionL( KUIStoreSetCaseStart, KUIStoreSetCaseEnd );
       
  1983         } 
       
  1984         
       
  1985     CleanupStack::PopAndDestroy( testInfo );    
       
  1986     CleanupStack::PopAndDestroy( section );
       
  1987     CleanupStack::PopAndDestroy( parser );
       
  1988     
       
  1989     const RRefArray<const CTestInfo>& testCases = setInfo->TestCases();
       
  1990     LoadTestModulesAndTestCaseFilesL( testCases );
       
  1991      
       
  1992     }     
       
  1993     
       
  1994 /*
       
  1995 -------------------------------------------------------------------------------
       
  1996 
       
  1997     Class: CUIStore
       
  1998 
       
  1999     Method: SaveTestSetL
       
  2000 
       
  2001     Description: Save test set.
       
  2002 
       
  2003     Parameters: CTestSetInfo& aSetInfo: in: test set
       
  2004     
       
  2005     Return Values: Symbian OS error code
       
  2006 
       
  2007     Errors/Exceptions: None
       
  2008 
       
  2009     Status: Approved
       
  2010 
       
  2011 -------------------------------------------------------------------------------
       
  2012 */
       
  2013 void CUIStore::SaveTestSetL( CTestSetInfo& aSetInfo, const TDesC& aSetFileName )
       
  2014     {
       
  2015     //Extract path
       
  2016     TParse p;
       
  2017     p.Set(aSetFileName, NULL, NULL);
       
  2018     TPtrC path =  p.DriveAndPath(); // gives path for test set
       
  2019     TPtrC fn = p.NameAndExt(); // gives filename with extension
       
  2020     if(path.Length() == 0)
       
  2021         {
       
  2022         path.Set(KUIStoreDefaultDir);
       
  2023         }
       
  2024 
       
  2025     //Create file server
       
  2026     RFs fs;
       
  2027     User::LeaveIfError(fs.Connect());
       
  2028     CleanupClosePushL(fs);
       
  2029 
       
  2030     //Create or open file
       
  2031     RFile file;
       
  2032     TFileName filename = path;
       
  2033     filename.Append(fn);
       
  2034     
       
  2035     TInt r = file.Replace(fs, filename, EFileWrite);
       
  2036     if(r != KErrNone)
       
  2037         {
       
  2038         User::Leave(r);
       
  2039         }
       
  2040     else
       
  2041         {
       
  2042         CleanupClosePushL(file);
       
  2043         
       
  2044         RBuf buffer;
       
  2045         buffer.Create(256);
       
  2046         CleanupClosePushL(buffer);
       
  2047         
       
  2048         // Saving
       
  2049         buffer.Format(_L("%S"), &KUIStoreSetStart);
       
  2050         WriteLineL(file, buffer);
       
  2051         buffer.Format(_L("%S %S"), &KUIStoreSetName,&aSetFileName);
       
  2052         WriteLineL(file, buffer);
       
  2053 
       
  2054         // Saving test set causes reset of index
       
  2055         aSetInfo.SetLastStartedCaseIndex(0);
       
  2056         buffer.Format(_L("%S "), &KUIStoreLastStartedCaseIndex);
       
  2057         buffer.AppendNumFixedWidth(aSetInfo.GetLastStartedCaseIndex(), EDecimal, KFixedStartedCaseIndex);
       
  2058         WriteLineL(file, buffer);
       
  2059 
       
  2060         // Saving test cases
       
  2061         TInt count = aSetInfo.TestCases().Count();
       
  2062         for(TInt i = 0; i < count; i++)
       
  2063             {
       
  2064             WriteLineL(file, KNullDesC);
       
  2065             buffer.Format(_L("%S"), &KUIStoreSetCaseStart);
       
  2066             WriteLineL(file, buffer);
       
  2067             
       
  2068             buffer.Format(_L("%S %S"), &KUIStoreCaseModuleName, &aSetInfo.TestCases()[i].ModuleName());
       
  2069             WriteLineL(file, buffer);
       
  2070             buffer.Format(_L("%S %S"), &KUIStoreTestCaseTitle, &aSetInfo.TestCases()[i].TestCaseTitle());
       
  2071             WriteLineL(file, buffer);
       
  2072             if(aSetInfo.TestCases()[i].TestCaseFile().Length() > 0)
       
  2073                 {
       
  2074                 buffer.Format(_L("%S %S"), &KUIStoreTestCaseFile, &aSetInfo.TestCases()[i].TestCaseFile());
       
  2075             WriteLineL(file, buffer);
       
  2076                 }
       
  2077             buffer.Format(_L("%S %d"), &KUIStoreTestCaseNum, aSetInfo.TestCases()[i].TestCaseNum());
       
  2078             WriteLineL(file, buffer);
       
  2079             buffer.Format(_L("%S %d"), &KUIStoreCasePriority, aSetInfo.TestCases()[i].Priority());
       
  2080             WriteLineL(file, buffer);
       
  2081             buffer.Format(_L("%S %d %d"), &KUIStoreCaseTimeout, I64LOW(aSetInfo.TestCases()[i].Timeout().Int64()), 
       
  2082                                                                 I64HIGH(aSetInfo.TestCases()[i].Timeout().Int64()));
       
  2083             WriteLineL(file, buffer);
       
  2084             buffer.Format(_L("%S %d"), &KUIStoreCaseExpectedResult, aSetInfo.TestCases()[i].ExpectedResult());
       
  2085             WriteLineL(file, buffer);
       
  2086             buffer.Format(_L("%S"), &KUIStoreSetCaseEnd);    
       
  2087             WriteLineL(file, buffer);
       
  2088             }
       
  2089 
       
  2090         WriteLineL(file, KNullDesC);
       
  2091         buffer.Format(_L("%S"), &KUIStoreSetEnd);
       
  2092         WriteLineL(file, buffer);
       
  2093 
       
  2094         CleanupStack::PopAndDestroy(&buffer);
       
  2095         CleanupStack::PopAndDestroy(&file);
       
  2096         }
       
  2097     CleanupStack::PopAndDestroy(&fs);        
       
  2098     }           
       
  2099 
       
  2100 /*
       
  2101 -------------------------------------------------------------------------------
       
  2102 
       
  2103     Class: CUIStore
       
  2104 
       
  2105     Method: UpdateTestSetL
       
  2106 
       
  2107     Description: Updates information in test set file.
       
  2108 
       
  2109     Parameters: CTestSetInfo& aSetInfo: in: test set
       
  2110     
       
  2111     Return Values: Symbian OS error code
       
  2112 
       
  2113     Errors/Exceptions: Leaves when writing to file fails
       
  2114                        Leaves when file.seek fails
       
  2115                        Leaves when can't connect to file server
       
  2116 
       
  2117     Status: Approved
       
  2118 
       
  2119 -------------------------------------------------------------------------------
       
  2120 */
       
  2121 void CUIStore::UpdateTestSetL(CTestSetInfo& aSetInfo, const TDesC& aSetFileName)
       
  2122     {
       
  2123     // Get path
       
  2124     TParse p;
       
  2125     p.Set(aSetFileName, NULL, NULL);
       
  2126     TPtrC path = p.DriveAndPath(); // gives path for test set
       
  2127     TPtrC fn = p.NameAndExt(); // gives filename with extension
       
  2128     if(path.Length() == 0)
       
  2129         {
       
  2130         path.Set(KUIStoreDefaultDir);
       
  2131         }
       
  2132 
       
  2133     //Create file server
       
  2134     RFs fs;
       
  2135     User::LeaveIfError(fs.Connect());
       
  2136     CleanupClosePushL(fs);
       
  2137 
       
  2138     //Create or open file
       
  2139     RFile file;
       
  2140     TFileName filename = path;
       
  2141     filename.Append(fn);
       
  2142     TInt foundpos = KErrNotFound;
       
  2143     
       
  2144     TInt r = file.Open(fs, filename, EFileWrite);
       
  2145     if(r != KErrNone)
       
  2146         {
       
  2147         User::Leave(r);
       
  2148         }
       
  2149     else
       
  2150         {
       
  2151         CleanupClosePushL(file);
       
  2152 
       
  2153         //Search for line
       
  2154         RBuf buffer;
       
  2155         buffer.Create(256);
       
  2156         CleanupClosePushL(buffer);
       
  2157 
       
  2158         //Prepare file
       
  2159         TInt pos = 0;
       
  2160         User::LeaveIfError(file.Seek(ESeekStart, pos));
       
  2161         
       
  2162         //Read file
       
  2163         ReadLineL(file, buffer);
       
  2164         while(buffer.Length() > 0)
       
  2165             {
       
  2166             // Keep remembering current position
       
  2167             if(buffer.Find(KUIStoreLastStartedCaseIndex) == 0)
       
  2168                 {
       
  2169                 foundpos = pos;
       
  2170                 break;
       
  2171                 }
       
  2172             // What is current position
       
  2173             pos = 0;
       
  2174             User::LeaveIfError(file.Seek(ESeekCurrent, pos));
       
  2175             // Read next line from file
       
  2176             ReadLineL(file, buffer);
       
  2177             }
       
  2178 
       
  2179         if(foundpos != KErrNotFound)
       
  2180             {
       
  2181             // Position was found. Just update that line (save index of last 
       
  2182             // started test case)
       
  2183             RBuf8 b;
       
  2184             b.Create(40);
       
  2185             CleanupClosePushL(b);
       
  2186 
       
  2187             b.Copy(KUIStoreLastStartedCaseIndex);
       
  2188             b.Append(_L8(" "));
       
  2189             b.AppendNumFixedWidth(aSetInfo.GetLastStartedCaseIndex(), EDecimal, KFixedStartedCaseIndex);
       
  2190             User::LeaveIfError(file.Seek(ESeekStart, foundpos));
       
  2191             User::LeaveIfError(file.Write(b));
       
  2192             CleanupStack::PopAndDestroy(&b);
       
  2193             }
       
  2194 
       
  2195         CleanupStack::PopAndDestroy(&buffer);
       
  2196         CleanupStack::PopAndDestroy(&file);
       
  2197         }
       
  2198     CleanupStack::PopAndDestroy(&fs);        
       
  2199     
       
  2200     if(foundpos == KErrNotFound)
       
  2201         {
       
  2202         // Position of KUIStoreLastStartedCaseIndex could not be found.
       
  2203         // Store the whole file.
       
  2204         SaveTestSetL(aSetInfo, aSetFileName);
       
  2205         }
       
  2206     }
       
  2207 
       
  2208 /*
       
  2209 -------------------------------------------------------------------------------
       
  2210 
       
  2211     Class: CUIStore
       
  2212 
       
  2213     Method: ReadLineL
       
  2214 
       
  2215     Description: Read the whole line from the file. If there is enough space,
       
  2216                  the whole content of line will be returned in buffer.
       
  2217 
       
  2218     Parameters: RFile& file: in: file to be read
       
  2219                 TDes8& buffer: out: buffer to be returned
       
  2220     
       
  2221     Return Values: None
       
  2222 
       
  2223     Errors/Exceptions: Leaves if RFile::Read method fails
       
  2224 
       
  2225     Status: Approved
       
  2226 
       
  2227 -------------------------------------------------------------------------------
       
  2228 */
       
  2229 void CUIStore::ReadLineL(RFile &file, TDes& buffer)
       
  2230     {
       
  2231     TBuf8<1> c;
       
  2232     TBuf<1> c16;
       
  2233     buffer.Copy(KNullDesC);
       
  2234     
       
  2235     User::LeaveIfError(file.Read(c));
       
  2236     while(c.Length() > 0)
       
  2237         {
       
  2238         // There is still place to write to the dest buffer
       
  2239         if(buffer.Length() < buffer.MaxLength())
       
  2240             {
       
  2241             c16.Copy(c);
       
  2242             buffer.Append(c16);
       
  2243             }
       
  2244         // Stop reading if end of line
       
  2245         if(c[0] == 0x0A)
       
  2246             {
       
  2247             break;
       
  2248             }
       
  2249         User::LeaveIfError(file.Read(c));
       
  2250         }
       
  2251     }
       
  2252 
       
  2253 /*
       
  2254 -------------------------------------------------------------------------------
       
  2255 
       
  2256     Class: CUIStore
       
  2257 
       
  2258     Method: WriteLineL
       
  2259 
       
  2260     Description: Write given line to the file and adds end of line.
       
  2261 
       
  2262     Parameters: RFile& file: in: file to be written
       
  2263                 TDesC& buffer: in: buffer to be written
       
  2264     
       
  2265     Return Values: None
       
  2266 
       
  2267     Errors/Exceptions: Leaves if RFile::Write method fails
       
  2268 
       
  2269     Status: Approved
       
  2270 
       
  2271 -------------------------------------------------------------------------------
       
  2272 */
       
  2273 void CUIStore::WriteLineL(RFile &file, const TDesC& buffer)
       
  2274     {
       
  2275     if(buffer.Length() > 0)
       
  2276         {
       
  2277         // Create 8-bit buffer
       
  2278         RBuf8 buf;
       
  2279         buf.Create(buffer.Length());
       
  2280         CleanupClosePushL(buf);
       
  2281     
       
  2282         buf.Copy(buffer);
       
  2283     
       
  2284         // Write buffer to file + end of line
       
  2285         User::LeaveIfError(file.Write(buf));
       
  2286 
       
  2287         // Delete 8-bit buffer
       
  2288         CleanupStack::PopAndDestroy(&buf);
       
  2289         }
       
  2290 
       
  2291     // Write end of line
       
  2292     TBuf8<2> eoline;
       
  2293     eoline.Copy(_L("\r\n"));
       
  2294     User::LeaveIfError(file.Write(eoline));
       
  2295     }
       
  2296 
       
  2297 /*
       
  2298 -------------------------------------------------------------------------------
       
  2299 
       
  2300     Class: CUIStore
       
  2301 
       
  2302     Method: LoadTestModulesL
       
  2303 
       
  2304     Description: Load test modules. 
       
  2305 
       
  2306     Parameters: CTestSetInfo& aSetInfo: in: test set
       
  2307     
       
  2308     Return Values: Symbian OS error code
       
  2309 
       
  2310     Errors/Exceptions: None
       
  2311 
       
  2312     Status: Draft
       
  2313 
       
  2314 -------------------------------------------------------------------------------
       
  2315 */
       
  2316 void CUIStore::LoadTestModulesAndTestCaseFilesL( 
       
  2317     const RRefArray<const CTestInfo>& aTestCases )
       
  2318     {
       
  2319     
       
  2320     RRefArray<TDesC> testCaseFiles;
       
  2321     RRefArray<TDesC> testModules;
       
  2322     CleanupClosePushL( testCaseFiles );
       
  2323     CleanupClosePushL( testModules );
       
  2324     
       
  2325     User::LeaveIfError( Modules( testModules ) );
       
  2326     
       
  2327     TInt cCount = aTestCases.Count();
       
  2328     TInt mCount = 0;
       
  2329     TInt mInd=0;
       
  2330     TInt fCount = 0;
       
  2331     TInt fInd=0;
       
  2332     for( TInt cInd=0; cInd<cCount; cInd++ )
       
  2333         {
       
  2334         mCount = testModules.Count();
       
  2335         for( mInd=0; mInd<mCount; mInd++ )
       
  2336             {
       
  2337             if( aTestCases[cInd].ModuleName() == testModules[mInd] )
       
  2338                 {
       
  2339                 // Test module already loaded
       
  2340                 break;
       
  2341                 }
       
  2342             }
       
  2343         if( mInd == mCount )
       
  2344             {
       
  2345             // Not found, load test module
       
  2346             if( AddTestModule( aTestCases[cInd].ModuleName() ) == KErrNone )
       
  2347                 {
       
  2348                 User::LeaveIfError( 
       
  2349                     testModules.Append( aTestCases[cInd].ModuleName() ) );
       
  2350                 }
       
  2351             }                
       
  2352         if( aTestCases[cInd].TestCaseFile().Length() == 0 )
       
  2353             {
       
  2354             // Test case file is not used, continue
       
  2355             continue;
       
  2356             }    
       
  2357         testCaseFiles.Reset();
       
  2358         User::LeaveIfError( 
       
  2359             TestCaseFiles( testCaseFiles, aTestCases[cInd].ModuleName() ));
       
  2360         fCount = testCaseFiles.Count();
       
  2361         for( fInd=0; fInd<fCount; fInd++ )
       
  2362             {
       
  2363             if( aTestCases[cInd].TestCaseFile() == testCaseFiles[fInd] )
       
  2364                 {
       
  2365                 // Testcasefile already loaded
       
  2366                 break;
       
  2367                 }
       
  2368             }  
       
  2369         if( fInd == fCount )
       
  2370             {  
       
  2371             // Load test module
       
  2372             if( AddTestCaseFile( aTestCases[cInd].ModuleName(),
       
  2373                                  aTestCases[cInd].TestCaseFile() ) == KErrNone )
       
  2374                 {
       
  2375                 User::LeaveIfError( 
       
  2376                     testCaseFiles.Append( aTestCases[cInd].TestCaseFile() ) );
       
  2377                 }
       
  2378             }
       
  2379         }   
       
  2380 
       
  2381     CleanupStack::PopAndDestroy(); // testModules
       
  2382     CleanupStack::PopAndDestroy(); // testCaseFiles
       
  2383         
       
  2384     }
       
  2385                                
       
  2386 /*
       
  2387 -------------------------------------------------------------------------------
       
  2388 
       
  2389     Class: CUIStore
       
  2390 
       
  2391     Method: TestExecuted
       
  2392 
       
  2393     Description: Test case executed callback from UI engine.
       
  2394     
       
  2395     Parameters:  CUIEngineContainer* const aContainer: in: Execution container
       
  2396                  TFullTestResult& aFullTestResult: in: test result
       
  2397     
       
  2398     Return Values: None
       
  2399     
       
  2400     Errors/Exceptions: None
       
  2401 
       
  2402     Status: Draft
       
  2403 
       
  2404 -------------------------------------------------------------------------------
       
  2405 */    
       
  2406 void CUIStore::TestExecuted ( CUIEngineContainer* aContainer,
       
  2407                               TFullTestResult& aFullTestResult )
       
  2408     {
       
  2409     
       
  2410     CStartedTestCase* testCase = NULL;
       
  2411     
       
  2412     if( FindByContainer( aContainer, testCase ) != KErrNone )
       
  2413         {
       
  2414         __TRACE( KError, ( CStifLogger::EError, _L("CUIStore::TestExecuted: Not found")));
       
  2415         return;
       
  2416         }
       
  2417     CStartedTestSet* set = NULL;
       
  2418     TInt setStatus = 0;
       
  2419     if( FindStartedSetByCase( testCase, set ) == KErrNone )
       
  2420         {
       
  2421         setStatus = set->Status();
       
  2422         set->TestCompleted( testCase, aFullTestResult );        
       
  2423         setStatus |= set->Status();
       
  2424         }
       
  2425         
       
  2426     // Check and delete all pending popup windows for test case
       
  2427     TInt count = iPopups.Count();
       
  2428     for( TInt i = 0; i<count; i++ )
       
  2429         {
       
  2430         if( iPopups[i]->Container() == aContainer )
       
  2431             {
       
  2432             delete iPopups[i];
       
  2433             iPopups.Remove( i );
       
  2434             }
       
  2435         }
       
  2436         
       
  2437     // Get old status 
       
  2438     TInt status = testCase->Status();
       
  2439     // Set result
       
  2440     testCase->SetResult( aFullTestResult );
       
  2441     // Get new status 
       
  2442     status |= testCase->Status();
       
  2443     // Add set status flags
       
  2444     status |= setStatus;
       
  2445     
       
  2446     iUIStoreIf->Update( testCase, status ); 
       
  2447     
       
  2448     return;
       
  2449     
       
  2450     }
       
  2451 
       
  2452 /*
       
  2453 -------------------------------------------------------------------------------
       
  2454 
       
  2455     Class: CUIStore
       
  2456 
       
  2457     Method: PrintProg
       
  2458 
       
  2459     Description: Progress information from test case execution, 
       
  2460             callback from UI engine.
       
  2461     
       
  2462     Parameters:  CUIEngineContainer* const aContainer: in: Execution container
       
  2463                  TTestProgress& aProgress: in: print info
       
  2464     
       
  2465     Return Values: Symbian OS error code
       
  2466 
       
  2467     
       
  2468     Errors/Exceptions: None
       
  2469 
       
  2470     Status: Draft
       
  2471 
       
  2472 -------------------------------------------------------------------------------
       
  2473 */ 
       
  2474 TInt CUIStore::PrintProg ( CUIEngineContainer* aContainer,
       
  2475                            TTestProgress& aProgress )
       
  2476     {
       
  2477     if( aContainer == NULL )
       
  2478         {
       
  2479         return KErrArgument;
       
  2480         }
       
  2481     if( ( aProgress.iDescription.Length() == 0 ) &&
       
  2482         ( aProgress.iText.Length() == 0 ) )
       
  2483     
       
  2484         {
       
  2485         return KErrArgument;
       
  2486         }
       
  2487         
       
  2488     CStartedTestCase* testCase = NULL;
       
  2489     
       
  2490     if( FindByContainer( aContainer, testCase ) != KErrNone )
       
  2491         {
       
  2492         __TRACE( KError, ( CStifLogger::EError, _L("CUIStore::TestExecuted: Not found")));
       
  2493         return KErrNotFound;
       
  2494         }
       
  2495 
       
  2496     TInt position = KErrNotFound;
       
  2497     TInt smallPos = KErrNotFound;
       
  2498 
       
  2499     // Search the array to find the position
       
  2500     const TInt count = testCase->PrintArray().Count();
       
  2501     for (TInt i = 0; i < count; i++)
       
  2502         {
       
  2503 
       
  2504         // Check if that item is already on list
       
  2505         if ( testCase->PrintArray()[i]->iDescription == aProgress.iDescription &&
       
  2506              testCase->PrintArray()[i]->iPosition    == aProgress.iPosition )
       
  2507             {
       
  2508             // Set it to be updated
       
  2509             position = i;
       
  2510             break;
       
  2511             }
       
  2512 
       
  2513         // Found a smaller priority item from list
       
  2514         if ( aProgress.iPosition <  testCase->PrintArray()[i]->iPosition )
       
  2515             {              
       
  2516             smallPos = i;
       
  2517             break;
       
  2518             }
       
  2519         }
       
  2520 
       
  2521     // Either update item in array or add new item to array
       
  2522     if ( position != KErrNotFound )
       
  2523         {
       
  2524         // Replace existing text
       
  2525         testCase->PrintArray()[position]->ReplaceTextL( aProgress );
       
  2526         }
       
  2527     else 
       
  2528         {
       
  2529         CTestProgress* prog = NULL;
       
  2530         TRAPD( err,
       
  2531             // Allocate new
       
  2532             prog = CTestProgress::NewL( aProgress );
       
  2533             );
       
  2534         if( err != KErrNone )
       
  2535             {
       
  2536             return err;
       
  2537             }
       
  2538         if ( smallPos != KErrNotFound )
       
  2539             {
       
  2540             if( testCase->PrintArray().Insert( prog, smallPos ) != KErrNone )
       
  2541                 {
       
  2542                 delete prog;
       
  2543                 return KErrNoMemory;
       
  2544                 }
       
  2545             }
       
  2546         else 
       
  2547             {
       
  2548             if( testCase->PrintArray().Append( prog ) != KErrNone )
       
  2549                 {
       
  2550                 delete prog;
       
  2551                 return KErrNoMemory;
       
  2552                 }
       
  2553             }
       
  2554         }
       
  2555         
       
  2556     iUIStoreIf->Update( testCase, CUIStoreIf::EPrintUpdate ); 
       
  2557     
       
  2558     return KErrNone;
       
  2559     
       
  2560     }
       
  2561 
       
  2562 /*
       
  2563 -------------------------------------------------------------------------------
       
  2564 
       
  2565     Class: CUIStore
       
  2566 
       
  2567     Method: PrintProg
       
  2568 
       
  2569     Description: Error information from Test framework, 
       
  2570             callback from UI engine.
       
  2571     
       
  2572     Parameters:  CUIEngineContainer* const aContainer: in: Execution container
       
  2573                  TErrorNotification& aError: in: error info
       
  2574     
       
  2575     Return Values: Symbian OS error code
       
  2576     
       
  2577     Errors/Exceptions: None
       
  2578 
       
  2579     Status: Draft
       
  2580 
       
  2581 -------------------------------------------------------------------------------
       
  2582 */    
       
  2583 TInt CUIStore::ErrorPrint( TErrorNotification& aError )
       
  2584     {
       
  2585 
       
  2586     if( aError.iText.Length() == 0 )
       
  2587         {
       
  2588         return KErrArgument;
       
  2589         }
       
  2590     
       
  2591     iUIStoreIf->Error( aError );
       
  2592         
       
  2593     return KErrNone;
       
  2594     
       
  2595     }
       
  2596 
       
  2597 /*
       
  2598 -------------------------------------------------------------------------------
       
  2599 
       
  2600     Class: CUIStore
       
  2601 
       
  2602     Method: RemoteMsg
       
  2603 
       
  2604     Description: Remote protocol control messages handling.
       
  2605 
       
  2606     Parameters: const TDesC& aMessage: in: Remote message
       
  2607 
       
  2608     Return Values: None
       
  2609 
       
  2610     Errors/Exceptions: None
       
  2611 
       
  2612     Status: Draft
       
  2613 
       
  2614 -------------------------------------------------------------------------------
       
  2615 */
       
  2616 TInt CUIStore::RemoteMsg( CUIEngineContainer* aContainer,
       
  2617                           const TDesC& aMessage)
       
  2618     {
       
  2619 
       
  2620     if( ( aMessage.Length() == 0 ) ||
       
  2621         ( aContainer == NULL ) )
       
  2622         {
       
  2623         return KErrArgument;
       
  2624         }
       
  2625     
       
  2626     TInt ret = KErrNone;
       
  2627 
       
  2628     TInt error = KErrNone;
       
  2629     CStifTFwIfProt* msg = NULL;
       
  2630     CStifTFwIfProt* resp = NULL;
       
  2631     TRAPD( err, msg = CStifTFwIfProt::NewL(); );
       
  2632     if( err != KErrNone )
       
  2633         {
       
  2634         return err;
       
  2635         }
       
  2636     TRAP( err, resp = CStifTFwIfProt::NewL(); );
       
  2637     if( err != KErrNone )
       
  2638         {
       
  2639         delete msg;
       
  2640         return err;
       
  2641         }
       
  2642     
       
  2643     // Parse received message
       
  2644     TRAP( err, 
       
  2645         error = msg->SetL( aMessage ) 
       
  2646     );
       
  2647     if( err != KErrNone )
       
  2648         {
       
  2649         __TRACE( KError, ( _L( "CUIStore::RemoteMsg: message header parsing failed [%d]"), err ) );
       
  2650         delete msg;
       
  2651         delete resp;
       
  2652         return err;
       
  2653         }
       
  2654 
       
  2655     // Create response 
       
  2656     TRAP( err, resp->CreateL(); );
       
  2657     if( err != KErrNone )
       
  2658         {
       
  2659         delete msg;
       
  2660         delete resp;
       
  2661         return err;
       
  2662         }                
       
  2663 
       
  2664     resp->Append( CStifTFwIfProt::MsgType, CStifTFwIfProt::EMsgResponse );
       
  2665     
       
  2666     if( error != KErrNone )
       
  2667         {
       
  2668         __TRACE( KError, ( _L( "CUIStore::RemoteMsg: message parsing failed [%d]"), error ) );
       
  2669         resp->AppendId( SETID( (TInt32)DevId(), 0 ) );
       
  2670         resp->AppendId( msg->SrcId() );
       
  2671         resp->Append( CStifTFwIfProt::MsgType, msg->iMsgType );
       
  2672         resp->Append( CStifTFwIfProt::RespParam, CStifTFwIfProt::ERespResult, error );
       
  2673         
       
  2674         aContainer->RemoteReceive( resp->Message() );
       
  2675         
       
  2676         // Error reported with protocol message, return success
       
  2677         delete msg;
       
  2678         delete resp;
       
  2679         return KErrNone;
       
  2680         }                    
       
  2681     
       
  2682     TBool sendResp = ETrue;
       
  2683                         
       
  2684     switch( msg->iMsgType )
       
  2685         {
       
  2686         case CStifTFwIfProt::EMsgReserve:
       
  2687             {
       
  2688             // Check IDs
       
  2689             if( ( msg->SrcDevId() == 0 ) ||
       
  2690                 ( msg->SrcTestId() == 0 ) )
       
  2691                 {
       
  2692                 __TRACE( KError, ( _L( "CUIStore::RemoteMsg: reserve for illegal srcid received") ) );
       
  2693                 error = KErrGeneral;
       
  2694                 }
       
  2695             if( msg->DstId() != 0 ) 
       
  2696                 {
       
  2697                 // Not a broadcast 
       
  2698                 if( ( msg->DstDevId() != DevId() ) ||
       
  2699                     ( msg->DstTestId() != 0 ) )  
       
  2700                     {
       
  2701                     __TRACE( KError, ( _L( "CUIStore::RemoteMsg: reserve for illegal dstid received") ) );
       
  2702                     error = KErrGeneral;
       
  2703                     }
       
  2704                 }                
       
  2705                 
       
  2706             resp->AppendId( SETID( (TInt32)DevId(), 0 ) );
       
  2707             resp->AppendId( msg->SrcId() );
       
  2708             resp->Append( CStifTFwIfProt::MsgType, CStifTFwIfProt::EMsgReserve );
       
  2709             if( error != KErrNone )
       
  2710                 {
       
  2711                 resp->Append( CStifTFwIfProt::RespParam, CStifTFwIfProt::ERespResult, error );
       
  2712                 }
       
  2713             }
       
  2714             break;
       
  2715         case CStifTFwIfProt::EMsgRelease:
       
  2716             {
       
  2717             // Check protocol ids
       
  2718             if( ( msg->SrcDevId() == 0 ) ||
       
  2719                 ( msg->SrcTestId() == 0 ) ||
       
  2720                 ( msg->DstTestId() != 0 ) )
       
  2721                 {
       
  2722                 __TRACE( KError, ( _L( "CUIStore::RemoteMsg: release for illegal srcid or dstid received") ) );
       
  2723                 error = KErrGeneral;
       
  2724                 }   
       
  2725             else if( msg->DstDevId() != DevId() ) 
       
  2726                 {
       
  2727                 __TRACE( KError, ( _L( "CUIStore::RemoteMsg: release for illegal dstid received") ) );
       
  2728                 error = KErrNotFound;
       
  2729                 }   
       
  2730 
       
  2731             resp->AppendId( msg->DstId() );
       
  2732             resp->AppendId( msg->SrcId() );
       
  2733             resp->Append( CStifTFwIfProt::MsgType, CStifTFwIfProt::EMsgRelease );
       
  2734             
       
  2735             if( error != KErrNone )
       
  2736                 {
       
  2737                 resp->Append( CStifTFwIfProt::RespParam, CStifTFwIfProt::ERespResult, error );
       
  2738                 }            
       
  2739             }
       
  2740             break;
       
  2741         case CStifTFwIfProt::EMsgRemote:
       
  2742             {
       
  2743             // Check protocol ids
       
  2744             if( ( msg->SrcDevId() == 0 ) ||
       
  2745                 ( msg->SrcTestId() == 0 ) ||
       
  2746                 ( msg->DstDevId() == 0 ) )
       
  2747                 {
       
  2748                 __TRACE( KError, ( _L( "CUIStore::RemoteMsg: remote for illegal srcid or dstid received") ) );
       
  2749                 error = KErrGeneral;
       
  2750                 }
       
  2751             else
       
  2752                 {               
       
  2753                 __TRACE( KError, ( _L( "CUIStore::RemoteMsg: received remote call") ) );
       
  2754                 
       
  2755                 error = MsgRemote( aContainer, *msg, *resp );
       
  2756                 }
       
  2757                 
       
  2758             if( error != KErrNone )
       
  2759                 {
       
  2760                 resp->AppendId( msg->DstId() );
       
  2761                 resp->AppendId( msg->SrcId() );
       
  2762                 resp->Append( CStifTFwIfProt::MsgType, CStifTFwIfProt::EMsgRemote );
       
  2763                 resp->Append( msg->iCmdDes );
       
  2764                 resp->Append( CStifTFwIfProt::RespParam,     
       
  2765                              CStifTFwIfProt::ERespResult, 
       
  2766                              error );
       
  2767                 }
       
  2768             else
       
  2769                 {
       
  2770                 sendResp = EFalse;
       
  2771                 }
       
  2772                                 
       
  2773             }
       
  2774             break;
       
  2775         case CStifTFwIfProt::EMsgResponse:            
       
  2776         default:
       
  2777             __TRACE( KError, ( _L( "CUIStore::RemoteMsg: invalid message")) );
       
  2778             ret = KErrNotSupported;
       
  2779         }
       
  2780 
       
  2781     if( ( ret == KErrNone ) && sendResp ) 
       
  2782          {
       
  2783         aContainer->RemoteReceive( resp->Message() );
       
  2784         }
       
  2785         
       
  2786     delete msg;
       
  2787     delete resp;
       
  2788     
       
  2789     return ret;
       
  2790     
       
  2791     }
       
  2792 
       
  2793 
       
  2794 /*
       
  2795 -------------------------------------------------------------------------------
       
  2796 
       
  2797     Class: CUIStore
       
  2798 
       
  2799     Method: MsgRemote
       
  2800 
       
  2801     Description: Remote command
       
  2802     
       
  2803     Parameters: const TDesC& aMessage: in:
       
  2804 
       
  2805     Return Values: KErrNotSupported
       
  2806 
       
  2807     Errors/Exceptions: None
       
  2808 
       
  2809     Status: Draft
       
  2810 
       
  2811 -------------------------------------------------------------------------------
       
  2812 */
       
  2813 TInt CUIStore::MsgRemote( CUIEngineContainer* aContainer, 
       
  2814                           CStifTFwIfProt& aReq, 
       
  2815                           CStifTFwIfProt& aResp )
       
  2816     {
       
  2817     
       
  2818     TInt ret = KErrNone;    
       
  2819         
       
  2820     switch( aReq.iCmdType )
       
  2821         {
       
  2822         case CStifTFwIfProt::ECmdRun:
       
  2823             ret = MsgRemoteRun( aContainer, aReq, aResp );
       
  2824             break;
       
  2825         case CStifTFwIfProt::ECmdPause:
       
  2826         case CStifTFwIfProt::ECmdResume:
       
  2827         case CStifTFwIfProt::ECmdCancel:
       
  2828             ret = MsgRemoteTestCtl( aContainer, aReq, aResp );
       
  2829             break;
       
  2830         case CStifTFwIfProt::ECmdRequest:
       
  2831         case CStifTFwIfProt::ECmdRelease:
       
  2832             ret = MsgRemoteEventCtl( aContainer, aReq, aResp );            
       
  2833             break;
       
  2834         case CStifTFwIfProt::ECmdSendReceive:
       
  2835             {
       
  2836             ret = MsgRemoteSendReceive( aContainer, aReq, aResp );
       
  2837             break;
       
  2838             }
       
  2839         default:
       
  2840             {
       
  2841             CStifTFwIfProt* resp = NULL;
       
  2842             TRAPD( err, 
       
  2843                 resp = CStifTFwIfProt::NewL(); 
       
  2844                 resp->CreateL();
       
  2845                 );
       
  2846             if( err != KErrNone )
       
  2847                 {
       
  2848                 delete resp;
       
  2849                 return err;
       
  2850                 }
       
  2851             resp->SetMsgType( CStifTFwIfProt::EMsgResponse );
       
  2852             resp->SetSrcId( aReq.DstId() );
       
  2853             resp->SetDstId( aReq.SrcId() );
       
  2854             resp->SetRespType( CStifTFwIfProt::EMsgRemote );
       
  2855             // Command type must be set separately, 
       
  2856             // because it is unspecified in this case
       
  2857             resp->iCmdType = aReq.iCmdType;
       
  2858             resp->Append( aReq.iCmdDes );
       
  2859                 
       
  2860             ret = RemotePopup( aContainer, aReq.Message(), resp );
       
  2861 
       
  2862             if( ret != KErrNone )
       
  2863                 {
       
  2864                 delete resp;
       
  2865                 }
       
  2866             }
       
  2867             break;
       
  2868         }
       
  2869     
       
  2870     return ret;
       
  2871     
       
  2872     }
       
  2873 
       
  2874 /*
       
  2875 -------------------------------------------------------------------------------
       
  2876 
       
  2877     Class: CUIStore
       
  2878 
       
  2879     Method: AtsRemoteRun
       
  2880 
       
  2881     Description: Remote run message
       
  2882     
       
  2883     Parameters: const TDesC& aMessage: in:
       
  2884 
       
  2885     Return Values: KErrNotSupported
       
  2886 
       
  2887     Errors/Exceptions: None
       
  2888 
       
  2889     Status: Draft
       
  2890 
       
  2891 -------------------------------------------------------------------------------
       
  2892 */        
       
  2893 TInt CUIStore::MsgRemoteRun( CUIEngineContainer* aContainer,
       
  2894                              CStifTFwIfProt& aReq, 
       
  2895                              CStifTFwIfProt& /* aResp */)
       
  2896     {
       
  2897     
       
  2898     TInt ret = KErrNone;    
       
  2899     TUint16 testid = 0;
       
  2900     
       
  2901     if( ( aReq.DstDevId() == 0 ) ||
       
  2902         ( aReq.DstTestId() != 0 ) ) 
       
  2903         {
       
  2904         // Protocol violation
       
  2905         __TRACE( KError, ( _L( "AtsReceive: remote run for illegal dstid received") ) );
       
  2906         return KErrGeneral;
       
  2907         }
       
  2908 
       
  2909     if ( aReq.DstDevId() != DevId() ) 
       
  2910         {
       
  2911         // Not our protocol message
       
  2912         __TRACE( KError, ( _L( "AtsReceive: remote run for illegal dstdevid received") ) );
       
  2913         return KErrNotFound;
       
  2914         }
       
  2915 
       
  2916     
       
  2917     if( aReq.iModule.Length() == 0 )
       
  2918         {
       
  2919         __TRACE( KError, ( _L("No mandatory test module name given as run parameter") ) );        
       
  2920         ret = KErrNotFound;
       
  2921         }    
       
  2922     else if( aReq.iTestCaseNumber < 0 )
       
  2923         {
       
  2924         __TRACE( KError, ( _L("No mandatory test case number given as run parameter") ) );        
       
  2925         ret = KErrNotFound;
       
  2926         }    
       
  2927     
       
  2928     testid = 1;
       
  2929     CStifTFwIfProt* resp = NULL;
       
  2930     TRAPD( err, 
       
  2931         resp = CStifTFwIfProt::NewL(); 
       
  2932         resp->CreateL();
       
  2933         );
       
  2934     if( err != KErrNone )
       
  2935         {
       
  2936         delete resp;
       
  2937         return err;
       
  2938         }
       
  2939 
       
  2940     CStifTFwIfProt* resp2 = NULL;
       
  2941     TRAP( err, 
       
  2942         resp2 = CStifTFwIfProt::NewL(); 
       
  2943         resp2->CreateL();
       
  2944         );
       
  2945     if( err != KErrNone )
       
  2946         {
       
  2947         delete resp2;
       
  2948         return err;
       
  2949         }              
       
  2950 
       
  2951     resp->SetMsgType( CStifTFwIfProt::EMsgResponse );
       
  2952     resp->SetSrcId( SETID( (TInt32)DevId(), testid ) );
       
  2953     resp->SetDstId( aReq.SrcId() );
       
  2954     resp->SetRespType( CStifTFwIfProt::EMsgRemote );
       
  2955     resp->SetCmdType( CStifTFwIfProt::ECmdRun );        
       
  2956 
       
  2957     resp2->SetMsgType( CStifTFwIfProt::EMsgResponse );
       
  2958     resp2->SetSrcId( SETID( (TInt32)DevId(), testid ) );
       
  2959     resp2->SetDstId( aReq.SrcId() );
       
  2960     resp2->SetRespType( CStifTFwIfProt::EMsgRemote );
       
  2961     resp2->SetCmdType( CStifTFwIfProt::ECmdRun );        
       
  2962    
       
  2963     // Remote run started popup call
       
  2964     ret = RemotePopup( aContainer, aReq.Message(), resp, EPopupPriorityHighest );
       
  2965     if( ret != KErrNone )
       
  2966         {
       
  2967         delete resp;
       
  2968         }
       
  2969     
       
  2970     // Remote run result popup call
       
  2971     ret = RemotePopup( aContainer, aReq.Message(), resp2 );
       
  2972     if( ret != KErrNone )
       
  2973         {
       
  2974         delete resp2;
       
  2975         }
       
  2976     
       
  2977     return ret;            
       
  2978     }
       
  2979 
       
  2980 /*
       
  2981 -------------------------------------------------------------------------------
       
  2982 
       
  2983     Class: CUIStore
       
  2984 
       
  2985     Method: MsgRemoteTestCtl
       
  2986 
       
  2987     Description: Remote test control message
       
  2988     
       
  2989     Parameters: const TDesC& aMessage: in:
       
  2990 
       
  2991     Return Values: KErrNotSupported
       
  2992 
       
  2993     Errors/Exceptions: None
       
  2994 
       
  2995     Status: Draft
       
  2996 
       
  2997 -------------------------------------------------------------------------------
       
  2998 */        
       
  2999 TInt CUIStore::MsgRemoteTestCtl( CUIEngineContainer* aContainer,
       
  3000                                  CStifTFwIfProt& aReq, 
       
  3001                                  CStifTFwIfProt& /*aResp*/ )
       
  3002     {
       
  3003     
       
  3004     TInt ret = KErrNone;    
       
  3005    
       
  3006     if( ( aReq.DstDevId() == 0 ) ||
       
  3007         ( aReq.DstTestId() == 0 ) ) 
       
  3008         {
       
  3009         // Protocol violation
       
  3010         __TRACE( KError, ( _L( "AtsReceive: remote test control for illegal dstid received") ) );
       
  3011         return KErrGeneral;
       
  3012         }
       
  3013 
       
  3014     if ( aReq.DstDevId() != DevId() ) 
       
  3015         {
       
  3016         // Not our protocol message
       
  3017         __TRACE( KError, ( _L( "AtsReceive: remote test control for illegal dstdevid received") ) );
       
  3018         return KErrNotFound;
       
  3019         }
       
  3020     
       
  3021     CStifTFwIfProt* resp = NULL;
       
  3022     TRAPD( err, 
       
  3023         resp = CStifTFwIfProt::NewL(); 
       
  3024         resp->CreateL();
       
  3025         );
       
  3026     if( err != KErrNone )
       
  3027         {
       
  3028         delete resp;
       
  3029         return err;
       
  3030         }
       
  3031         
       
  3032     resp->SetMsgType( CStifTFwIfProt::EMsgResponse );
       
  3033     resp->SetSrcId( aReq.DstId() );
       
  3034     resp->SetDstId( aReq.SrcId() );
       
  3035     resp->SetRespType( CStifTFwIfProt::EMsgRemote );
       
  3036     resp->SetCmdType( aReq.iCmdType );
       
  3037     
       
  3038     ret = RemotePopup( aContainer, aReq.Message(), resp );
       
  3039 
       
  3040     if( ret != KErrNone )
       
  3041         {
       
  3042         delete resp;
       
  3043         }
       
  3044 
       
  3045     return ret;
       
  3046     
       
  3047     }    
       
  3048 
       
  3049 /*
       
  3050 -------------------------------------------------------------------------------
       
  3051 
       
  3052     Class: CUIStore
       
  3053 
       
  3054     Method: MsgRemoteEventCtl
       
  3055 
       
  3056     Description: Remote run message
       
  3057     
       
  3058     Parameters: const TDesC& aMessage: in:
       
  3059 
       
  3060     Return Values: KErrNotSupported
       
  3061 
       
  3062     Errors/Exceptions: None
       
  3063 
       
  3064     Status: Draft
       
  3065 
       
  3066 -------------------------------------------------------------------------------
       
  3067 */        
       
  3068 TInt CUIStore::MsgRemoteEventCtl( CUIEngineContainer* aContainer,
       
  3069                                   CStifTFwIfProt& aReq, 
       
  3070                                   CStifTFwIfProt& aResp )
       
  3071     {
       
  3072     
       
  3073     if( ( aReq.DstDevId() == 0 ) ||
       
  3074         ( aReq.DstTestId() != 0 ) ) 
       
  3075         {
       
  3076         // Protocol violation
       
  3077         __TRACE( KError, ( _L( "AtsReceive: remote event control for illegal dstid received") ) );
       
  3078         return KErrGeneral;
       
  3079         }
       
  3080 
       
  3081     if ( aReq.DstDevId() != DevId() ) 
       
  3082         {
       
  3083         // Not our protocol message
       
  3084         __TRACE( KError, ( _L( "AtsReceive: remote event control for illegal dstdevid received") ) );
       
  3085         return KErrNotFound;
       
  3086         }
       
  3087         
       
  3088     if( aReq.iEventName.Length() == 0 )
       
  3089         {
       
  3090         __TRACE( KError, ( _L("No event name given") ) );        
       
  3091         return KErrNotFound;
       
  3092     }
       
  3093     
       
  3094     TInt ret = KErrNone;
       
  3095                     
       
  3096     switch( aReq.iCmdType )
       
  3097         {
       
  3098         case CStifTFwIfProt::ECmdRequest:
       
  3099             {
       
  3100             // Send event active information
       
  3101             CStifTFwIfProt* resp = NULL;
       
  3102             TRAP( ret, 
       
  3103                 resp = CStifTFwIfProt::NewL(); 
       
  3104                 resp->CreateL(); );
       
  3105             if( ret != KErrNone )
       
  3106                 {
       
  3107                 delete resp;
       
  3108                 return ret;
       
  3109                 }
       
  3110                 
       
  3111             resp->SetMsgType( CStifTFwIfProt::EMsgResponse );
       
  3112             resp->SetSrcId( aReq.DstId() );
       
  3113             resp->SetDstId( aReq.SrcId() );
       
  3114             resp->SetRespType( CStifTFwIfProt::EMsgRemote );
       
  3115             resp->SetCmdType( CStifTFwIfProt::ECmdRequest );
       
  3116             resp->Append( CStifTFwIfProt::EventStatus, 
       
  3117                           CStifTFwIfProt::EEventSet );
       
  3118             resp->Append( aReq.iEventName );
       
  3119             ret = RemotePopup( aContainer, aReq.Message(), resp, EPopupPriorityNormal );                
       
  3120 
       
  3121             if( ret != KErrNone )
       
  3122                 {
       
  3123                 delete resp;
       
  3124                 }
       
  3125                     
       
  3126             aResp.AppendId( aReq.DstId() );
       
  3127             aResp.AppendId( aReq.SrcId() );
       
  3128             aResp.Append( CStifTFwIfProt::MsgType, CStifTFwIfProt::EMsgRemote );
       
  3129             aResp.Append( CStifTFwIfProt::CmdType, CStifTFwIfProt::ECmdRequest );
       
  3130             if( ret == KErrNone )
       
  3131                 {
       
  3132                 aResp.Append( CStifTFwIfProt::EventStatus, 
       
  3133                               CStifTFwIfProt::EEventActive );
       
  3134                 aResp.Append( aReq.iEventName );
       
  3135                 }
       
  3136             else 
       
  3137                 {
       
  3138                 aResp.Append( CStifTFwIfProt::EventStatus, 
       
  3139                               CStifTFwIfProt::EEventError );
       
  3140                 aResp.Append( aReq.iEventName );                              
       
  3141                 aResp.Append( CStifTFwIfProt::EventStatusParams, 
       
  3142                              CStifTFwIfProt::EEventResult,
       
  3143                              ret );
       
  3144                 }
       
  3145 
       
  3146             ret = aContainer->RemoteReceive( aResp.Message() );    
       
  3147             ret = KErrNone;          
       
  3148             }
       
  3149             break;
       
  3150         case CStifTFwIfProt::ECmdRelease:
       
  3151             {
       
  3152             // Check and delete all pending event popup windows for test case
       
  3153             TInt count = iPopups.Count();
       
  3154             for( TInt i = 0; i<count; i++ )
       
  3155                 {
       
  3156                 if( ( iPopups[i]->Container() == aContainer ) &&
       
  3157                     iPopups[i]->IsEventPopup() )
       
  3158                     {
       
  3159                     delete iPopups[i];
       
  3160                     iPopups.Remove( i );
       
  3161                     }
       
  3162                 }
       
  3163                 
       
  3164             aResp.AppendId( aReq.DstId() );
       
  3165             aResp.AppendId( aReq.SrcId() );
       
  3166             aResp.Append( CStifTFwIfProt::MsgType, CStifTFwIfProt::EMsgRemote );
       
  3167             aResp.Append( CStifTFwIfProt::CmdType, CStifTFwIfProt::ECmdRelease );
       
  3168             aResp.Append( aReq.iEventName );
       
  3169 
       
  3170             ret = aContainer->RemoteReceive( aResp.Message() );    
       
  3171             ret = KErrNone;          
       
  3172             
       
  3173             }
       
  3174             break;
       
  3175         default:
       
  3176             return KErrNotSupported;
       
  3177         }
       
  3178         
       
  3179     return ret;
       
  3180     
       
  3181     }    
       
  3182 
       
  3183 /*
       
  3184 -------------------------------------------------------------------------------
       
  3185 
       
  3186     Class: CUIStore
       
  3187 
       
  3188     Method: MsgRemoteSendReceive
       
  3189 
       
  3190     Description: Asynchronous remote sendreceive message
       
  3191     
       
  3192     Parameters: CUIEngineContainer* aContainer: in:
       
  3193                 CStifTFwIfProt& aReq: in
       
  3194                 CStifTFwIfProt& aResp: in
       
  3195 
       
  3196     Return Values: KErrNotSupported
       
  3197 
       
  3198     Errors/Exceptions: None
       
  3199 
       
  3200     Status: Draft
       
  3201 
       
  3202 -------------------------------------------------------------------------------
       
  3203 */        
       
  3204 TInt CUIStore::MsgRemoteSendReceive( CUIEngineContainer* aContainer,
       
  3205                              CStifTFwIfProt& aReq, 
       
  3206                              CStifTFwIfProt& aResp )
       
  3207     {
       
  3208     
       
  3209     TInt ret = KErrNone;    
       
  3210     // TUint16 testid = 0;
       
  3211     
       
  3212     if( ( aReq.DstDevId() == 0 ) ||
       
  3213         ( aReq.DstTestId() != 0 ) ) 
       
  3214         {
       
  3215         // Protocol violation
       
  3216         __TRACE( KError, ( _L( "AtsReceive: remote run for illegal dstid received") ) );
       
  3217         return KErrGeneral;
       
  3218         }
       
  3219 
       
  3220     if ( aReq.DstDevId() != DevId() ) 
       
  3221         {
       
  3222         // Not our protocol message
       
  3223         __TRACE( KError, ( _L( "AtsReceive: remote run for illegal dstdevid received") ) );
       
  3224         return KErrNotFound;
       
  3225         }
       
  3226 
       
  3227     // testid = 1;
       
  3228     CStifTFwIfProt* resp = NULL;
       
  3229     TRAPD( err, 
       
  3230         resp = CStifTFwIfProt::NewL(); 
       
  3231         resp->CreateL();
       
  3232         );
       
  3233     if( err != KErrNone )
       
  3234         {
       
  3235         delete resp;
       
  3236         return err;
       
  3237         }
       
  3238         
       
  3239     resp->SetMsgType( CStifTFwIfProt::EMsgResponse );
       
  3240     //resp->SetSrcId( SETID( DevId(), testid ) );
       
  3241     resp->SetSrcId( aReq.DstId() );
       
  3242     resp->SetDstId( aReq.SrcId() );
       
  3243     resp->SetRespType( CStifTFwIfProt::EMsgRemote );
       
  3244     resp->SetCmdType( CStifTFwIfProt::ECmdSendReceive );        
       
  3245    
       
  3246     ret = RemotePopup( aContainer, aReq.Message(), resp );
       
  3247     if( ret != KErrNone )
       
  3248         {
       
  3249         delete resp;
       
  3250         }
       
  3251         
       
  3252     aResp.AppendId( aReq.DstId() );
       
  3253     aResp.AppendId( aReq.SrcId() );
       
  3254     aResp.Append( CStifTFwIfProt::MsgType, CStifTFwIfProt::EMsgRemote );
       
  3255     aResp.Append( CStifTFwIfProt::CmdType, CStifTFwIfProt::ECmdSendReceive );
       
  3256     if( ret != KErrNone )
       
  3257         {
       
  3258         aResp.Append( CStifTFwIfProt::RunStatus, 
       
  3259                       CStifTFwIfProt::ERunError );
       
  3260         aResp.Append( CStifTFwIfProt::RunStatusParams, 
       
  3261                       CStifTFwIfProt::ERunResult, ret );
       
  3262         }
       
  3263     else
       
  3264         {
       
  3265         aResp.Append( CStifTFwIfProt::RunStatus, 
       
  3266                       CStifTFwIfProt::ERunStarted );
       
  3267         }
       
  3268 
       
  3269     // Send response
       
  3270     aContainer->RemoteReceive( aResp.Message() );
       
  3271     
       
  3272     // Response is created, return success
       
  3273     ret = KErrNone;        
       
  3274     
       
  3275     return ret;
       
  3276             
       
  3277     }
       
  3278 
       
  3279 /*
       
  3280 -------------------------------------------------------------------------------
       
  3281 
       
  3282     Class: CUIStore
       
  3283 
       
  3284     Method: GoingToReboot
       
  3285 
       
  3286     Description: Reboot indication handling.
       
  3287 
       
  3288     Parameters: CUIEngineContainer* aContainer: in: Container
       
  3289 
       
  3290     Return Values: None
       
  3291 
       
  3292     Errors/Exceptions: None
       
  3293 
       
  3294     Status: Draft
       
  3295 
       
  3296 -------------------------------------------------------------------------------
       
  3297 */
       
  3298 TInt CUIStore::GoingToReboot( CUIEngineContainer* /* aContainer */,
       
  3299                               TRequestStatus& aStatus )
       
  3300     {
       
  3301     
       
  3302     _LIT( KDateString,"%H%T%S.%C" ); 
       
  3303        
       
  3304     const TInt KTimeFieldLength = 30;
       
  3305     TBuf<KTimeFieldLength> time;
       
  3306     
       
  3307     // Store info 
       
  3308     CStifLogger* logger = CStifLogger::NewL( KUIStoreDefaultDir,
       
  3309                                              KUIStoreDefaultRebootFile,
       
  3310                                              CStifLogger::EData,
       
  3311                                              CStifLogger::EFile,
       
  3312                                              ETrue,
       
  3313                                              EFalse,
       
  3314                                              EFalse,
       
  3315                                              EFalse,
       
  3316                                              EFalse,
       
  3317                                              ETrue );
       
  3318     
       
  3319     CleanupStack::PushL( logger );
       
  3320     TInt count = iStartedTestCases.Count();
       
  3321     for( TInt index=0; index<count; index++ )
       
  3322         {
       
  3323         logger->Log( _L("%S\r\n"), &KUIStoreStartTest );
       
  3324         
       
  3325         // First test case info
       
  3326         logger->Log( _L("%S %S\r\n"), &KUIStoreCaseModuleName, 
       
  3327             &iStartedTestCases[index]->TestInfo().ModuleName() );
       
  3328         logger->Log( _L("%S %S\r\n"), &KUIStoreTestCaseTitle, 
       
  3329             &iStartedTestCases[index]->TestInfo().TestCaseTitle() );
       
  3330         if( iStartedTestCases[index]->TestInfo().TestCaseFile().Length() > 0 )
       
  3331             {
       
  3332             logger->Log( _L("%S %S\r\n"), &KUIStoreTestCaseFile, 
       
  3333                 &iStartedTestCases[index]->TestInfo().TestCaseFile() );
       
  3334             }
       
  3335         logger->Log( _L("%S %d\r\n"), &KUIStoreTestCaseNum, 
       
  3336             iStartedTestCases[index]->TestInfo().TestCaseNum() );
       
  3337         logger->Log( _L("%S %d\r\n"), &KUIStoreCasePriority, 
       
  3338             iStartedTestCases[index]->TestInfo().Priority() );
       
  3339          //@js<--remove--> logger->Log( _L("%S %d %d\r\n"), &KUIStoreCaseTimeout,            
       
  3340          //@js<--remove--> iStartedTestCases[index]->TestInfo().Timeout().Int64().Low(),
       
  3341          //@js<--remove--> iStartedTestCases[index]->TestInfo().Timeout().Int64().High() );
       
  3342         logger->Log( _L("%S %d %d\r\n"), &KUIStoreCaseTimeout,            
       
  3343             I64LOW(iStartedTestCases[index]->TestInfo().Timeout().Int64()),
       
  3344             I64HIGH(iStartedTestCases[index]->TestInfo().Timeout().Int64()));     
       
  3345             
       
  3346         logger->Log( _L("%S %d\r\n"), &KUIStoreCaseExpectedResult, 
       
  3347             iStartedTestCases[index]->TestInfo().ExpectedResult() );    
       
  3348         
       
  3349         logger->Log( _L("%S %d\r\n"), &KUIStoreCaseStatus, 
       
  3350             iStartedTestCases[index]->Status() );    
       
  3351 
       
  3352         logger->Log( _L("%S %d %d\r\n"), &KUIStoreCaseExecutionResult, 
       
  3353             iStartedTestCases[index]->Result().iCaseExecutionResultType,
       
  3354             iStartedTestCases[index]->Result().iCaseExecutionResultCode );    
       
  3355         logger->Log( _L("%S %d %S\r\n"), &KUIStoreCaseResult, 
       
  3356             iStartedTestCases[index]->Result().iTestResult.iResult,
       
  3357             &iStartedTestCases[index]->Result().iTestResult.iResultDes );    
       
  3358         
       
  3359         // Start time
       
  3360         iStartedTestCases[index]->Result().iStartTime.FormatL(
       
  3361                     time, KDateString );
       
  3362         logger->Log( _L("%S %S\r\n"), &KUIStoreCaseStartTime, &time );
       
  3363 
       
  3364         // Start time
       
  3365         iStartedTestCases[index]->Result().iEndTime.FormatL(
       
  3366                     time, KDateString );
       
  3367         logger->Log( _L("%S %S\r\n"), &KUIStoreCaseEndTime, &time );
       
  3368 
       
  3369         logger->Log( _L("%S\r\n\r\n"), &KUIStoreStartTestEnd );
       
  3370         }
       
  3371     
       
  3372     CleanupStack::PopAndDestroy( logger );
       
  3373     
       
  3374     // Show popup
       
  3375     TKeyCode key;
       
  3376     iUIStoreIf->PopupMsg( _L("GoingToReboot"), 
       
  3377                           _L("Press any key to continue"), 
       
  3378                           KRebootPopupTimeout, key, aStatus );
       
  3379     
       
  3380     return KErrNone;
       
  3381 
       
  3382     }
       
  3383 
       
  3384 /*
       
  3385 -------------------------------------------------------------------------------
       
  3386 
       
  3387     Class: CUIStore
       
  3388 
       
  3389     Method: LoadExecutedTestCasesL
       
  3390 
       
  3391     Description: Load all executed testcases saved before reboot.
       
  3392     
       
  3393     Parameters: None
       
  3394 
       
  3395     Return Values: None
       
  3396 
       
  3397     Errors/Exceptions: Leaves on error
       
  3398 
       
  3399     Status: Draft
       
  3400 
       
  3401 -------------------------------------------------------------------------------
       
  3402 */
       
  3403 void CUIStore::LoadExecutedTestCasesL()
       
  3404     {
       
  3405     TPtrC tmp;
       
  3406     TInt num = 0;
       
  3407     TInt high = 0;
       
  3408     TInt64 interval;
       
  3409     TFullTestResult result;
       
  3410     TInt status = 0;
       
  3411     CStifItemParser* item = NULL;
       
  3412     TInt ret = KErrNone;
       
  3413 
       
  3414     CStifParser* parser = NULL;
       
  3415     TRAP( ret,
       
  3416         parser = CStifParser::NewL( KUIStoreDefaultDir,
       
  3417                                     KUIStoreDefaultRebootFile );
       
  3418         );
       
  3419     if( ret != KErrNone )
       
  3420         {
       
  3421         // reboot file not found
       
  3422         return; 
       
  3423         }
       
  3424     CleanupStack::PushL( parser );
       
  3425    
       
  3426     __TRACE( KInit, ( _L( "Reboot file is found(%S%S). Reboot testing ongoing..." ), &KUIStoreDefaultDir, &KUIStoreDefaultRebootFile ) );
       
  3427 
       
  3428     CTestInfo* testInfo = NULL;    
       
  3429      
       
  3430     CStifSectionParser* section = 
       
  3431         parser->SectionL( KUIStoreStartTest, KUIStoreStartTestEnd );
       
  3432    
       
  3433     while( section )
       
  3434         {
       
  3435         CleanupStack::PushL( section );    
       
  3436         
       
  3437         testInfo = CTestInfo::NewL();
       
  3438         CleanupStack::PushL( testInfo ); 
       
  3439     
       
  3440         // Get module name
       
  3441         // Mandatory, leave if not found
       
  3442         User::LeaveIfError( 
       
  3443             section->GetLine( KUIStoreCaseModuleName, tmp, ENoTag ) );
       
  3444         testInfo->SetModuleName( tmp );
       
  3445     
       
  3446         // Get test case title
       
  3447         // Mandatory, leave if not found
       
  3448         User::LeaveIfError( 
       
  3449             section->GetLine( KUIStoreTestCaseTitle, tmp, ENoTag ) );
       
  3450         testInfo->SetTestCaseTitle( tmp );
       
  3451         
       
  3452         // Get test case file
       
  3453         num = section->GetLine( KUIStoreTestCaseFile, tmp, ENoTag );
       
  3454         if( ( num == KErrNone ) &&
       
  3455             ( tmp.Length() > 0 ) )
       
  3456             {
       
  3457             // Optional
       
  3458             testInfo->SetTestCaseFile( tmp );
       
  3459             }
       
  3460         else
       
  3461             {
       
  3462             testInfo->SetTestCaseFile( KNullDesC );
       
  3463             }
       
  3464         
       
  3465         // Get test case number
       
  3466         item = section->GetItemLineL( KUIStoreTestCaseNum );
       
  3467         CleanupStack::PushL( item );
       
  3468         // Mandatory, leave if not found
       
  3469         User::LeaveIfError( item->GetInt( KUIStoreTestCaseNum, num ));
       
  3470         testInfo->SetTestCaseNumber( num );
       
  3471         CleanupStack::PopAndDestroy( item );    
       
  3472         
       
  3473         // Get test case priority
       
  3474         item = section->GetItemLineL( KUIStoreCasePriority );
       
  3475         CleanupStack::PushL( item );
       
  3476         // Mandatory, leave if not found
       
  3477         User::LeaveIfError( item->GetInt( KUIStoreCasePriority, num ));
       
  3478         testInfo->SetPriority( num );
       
  3479         CleanupStack::PopAndDestroy( item ); 
       
  3480         
       
  3481         // Get test case timeout
       
  3482         item = section->GetItemLineL( KUIStoreCaseTimeout );
       
  3483         CleanupStack::PushL( item );
       
  3484         // Mandatory, leave if not found
       
  3485         User::LeaveIfError( item->GetInt( KUIStoreCaseTimeout, num ));
       
  3486         User::LeaveIfError( item->GetNextInt( high ));
       
  3487         //interval.Set( high, num );
       
  3488         interval = MAKE_TINT64( high, num );      
       
  3489         TTimeIntervalMicroSeconds timeout( interval );
       
  3490         testInfo->SetTimeout( timeout );
       
  3491         CleanupStack::PopAndDestroy( item ); 
       
  3492         
       
  3493         // Get test case status
       
  3494         item = section->GetItemLineL( KUIStoreCaseStatus );
       
  3495         CleanupStack::PushL( item );
       
  3496         // Mandatory, leave if not found
       
  3497         User::LeaveIfError( item->GetInt( KUIStoreCaseStatus, status ));
       
  3498         CleanupStack::PopAndDestroy( item ); 
       
  3499 
       
  3500         // Get test case execution result
       
  3501         item = section->GetItemLineL( KUIStoreCaseExecutionResult );
       
  3502         CleanupStack::PushL( item );
       
  3503         // Mandatory, leave if not found
       
  3504         User::LeaveIfError( item->GetInt( KUIStoreCaseExecutionResult, num ));
       
  3505         result.iCaseExecutionResultType = ( TFullTestResult::TCaseExecutionResult) num;
       
  3506         // Mandatory, leave if not found
       
  3507         User::LeaveIfError( item->GetNextInt( result.iCaseExecutionResultCode ));
       
  3508         CleanupStack::PopAndDestroy( item );
       
  3509         
       
  3510         // Get test case result
       
  3511         item = section->GetItemLineL( KUIStoreCaseResult );
       
  3512         CleanupStack::PushL( item );
       
  3513         // Mandatory, leave if not found
       
  3514         User::LeaveIfError( item->GetInt( KUIStoreCaseResult, 
       
  3515                                           result.iTestResult.iResult ));
       
  3516         // Not mandatory
       
  3517         TBool first = ETrue;
       
  3518         result.iTestResult.iResultDes.Zero();
       
  3519         ret = item->GetNextString( tmp );
       
  3520         while( ret == KErrNone )
       
  3521             {
       
  3522             if( result.iTestResult.iResultDes.Length() + tmp.Length() + 1 > result.iTestResult.iResultDes.MaxLength() )
       
  3523                 {
       
  3524                 User::Leave( KErrGeneral );
       
  3525                 }
       
  3526             if(!first)
       
  3527                 result.iTestResult.iResultDes.Append(_L(" "));
       
  3528             result.iTestResult.iResultDes.Append( tmp );
       
  3529             first = EFalse;
       
  3530             ret = item->GetNextString( tmp );
       
  3531             }
       
  3532         /*
       
  3533         ret = item->GetNextString( tmp );
       
  3534         if( ret == KErrNone )
       
  3535             {
       
  3536             if( tmp.Length() > result.iTestResult.iResultDes.MaxLength() )
       
  3537                 {
       
  3538                 User::Leave( KErrGeneral );
       
  3539                 }
       
  3540             result.iTestResult.iResultDes.Copy( tmp );
       
  3541             }
       
  3542         */
       
  3543         CleanupStack::PopAndDestroy( item ); 
       
  3544 
       
  3545         // Get test start time
       
  3546         item = section->GetItemLineL( KUIStoreCaseStartTime );
       
  3547         CleanupStack::PushL( item );
       
  3548         // Mandatory, leave if not found
       
  3549         User::LeaveIfError( item->GetString( KUIStoreCaseStartTime, tmp ));
       
  3550         result.iStartTime.Set( tmp );
       
  3551         CleanupStack::PopAndDestroy( item ); 
       
  3552 
       
  3553         // Get test end time
       
  3554         item = section->GetItemLineL( KUIStoreCaseEndTime );
       
  3555         CleanupStack::PushL( item );
       
  3556         // Mandatory, leave if not found
       
  3557         User::LeaveIfError( item->GetString( KUIStoreCaseEndTime, tmp ));
       
  3558         result.iEndTime.Set( tmp );
       
  3559         CleanupStack::PopAndDestroy( item ); 
       
  3560              
       
  3561         if( status != CUIStoreIf::EStatusRunning )
       
  3562             {
       
  3563             // Add executed test cases to list
       
  3564             CStartedTestCase* startedCase = 
       
  3565                 new( ELeave )CStartedTestCase( testInfo, result, status );
       
  3566             User::LeaveIfError( iStartedTestCases.Append( startedCase ) );            
       
  3567             CleanupStack::Pop( testInfo );            
       
  3568 
       
  3569             // Fill data with test case info and send to test engine
       
  3570             TTestInfo *info = new (ELeave) TTestInfo;
       
  3571             CleanupStack::PushL(info);
       
  3572             info->iModuleName.Copy(testInfo->ModuleName());
       
  3573             info->iConfig.Copy(testInfo->TestCaseFile());
       
  3574             info->iTestCaseInfo.iCaseNumber = testInfo->TestCaseNum();
       
  3575             info->iTestCaseInfo.iTitle.Copy(testInfo->TestCaseTitle());
       
  3576             info->iTestCaseInfo.iTimeout = testInfo->Timeout();
       
  3577             info->iTestCaseInfo.iPriority = testInfo->Priority();
       
  3578             
       
  3579             iUIEngine->TestEngine().AddTestCaseResultToTestReport(*info, result, KErrNone);
       
  3580             CleanupStack::PopAndDestroy(info);
       
  3581             } 
       
  3582         else
       
  3583             {
       
  3584             // Restart testcase that was running when reset was done
       
  3585             CUIEngineContainer* container = NULL;
       
  3586             User::LeaveIfError(  
       
  3587                 iUIEngine->StartTestCase( container, *testInfo ) );
       
  3588             
       
  3589             CStartedTestCase* testCase = NULL;
       
  3590             TRAPD( retVal,
       
  3591                 testCase = CStartedTestCase::NewL( *testInfo, *container );
       
  3592                );
       
  3593             if( retVal != KErrNone )
       
  3594                 {
       
  3595                 iUIEngine->AbortStartedTestCase( container );
       
  3596                 User::Leave( retVal );
       
  3597                 }
       
  3598                 
       
  3599             retVal = iStartedTestCases.Append( testCase );
       
  3600             if( retVal != KErrNone )
       
  3601                 {
       
  3602                 iUIEngine->AbortStartedTestCase( container );
       
  3603                 delete testCase;
       
  3604                 User::Leave( retVal );
       
  3605                 }
       
  3606 
       
  3607             CleanupStack::PopAndDestroy( testInfo );
       
  3608 
       
  3609             }
       
  3610         
       
  3611         CleanupStack::PopAndDestroy( section );    
       
  3612         section = 
       
  3613             parser->NextSectionL( KUIStoreStartTest, KUIStoreStartTestEnd );
       
  3614         } 
       
  3615     
       
  3616     CleanupStack::PopAndDestroy( parser );
       
  3617     
       
  3618     // Delete file
       
  3619     RFs rf;
       
  3620     TInt retVal = rf.Connect();
       
  3621 	if( retVal != KErrNone )
       
  3622 		{
       
  3623 		User::Leave( retVal );
       
  3624 		}
       
  3625 		
       
  3626     TFileName file( KUIStoreDefaultDir );
       
  3627     file.Append( KUIStoreDefaultRebootFile );
       
  3628     rf.Delete( file );
       
  3629     rf.Close();
       
  3630     
       
  3631     return;
       
  3632     }    
       
  3633 /*
       
  3634 -------------------------------------------------------------------------------
       
  3635 
       
  3636     Class: CUIStore
       
  3637 
       
  3638     Method: FindByContainer
       
  3639 
       
  3640     Description: Find test case with UIEngine Container pointer.
       
  3641     
       
  3642     Parameters:  CUIEngineContainer* const aContainer: in: Execution container
       
  3643                  CStartedTestCase*& aTestCase: out: Testcase info
       
  3644     
       
  3645     Return Values: Symbian OS error code
       
  3646     
       
  3647     Errors/Exceptions: None
       
  3648 
       
  3649     Status: Draft
       
  3650 
       
  3651 -------------------------------------------------------------------------------
       
  3652 */ 
       
  3653 TInt CUIStore::FindByContainer( CUIEngineContainer* const aContainer,
       
  3654                                 CStartedTestCase*& aTestCase )
       
  3655     {
       
  3656     
       
  3657     TInt count = iStartedTestCases.Count();
       
  3658     TInt index = 0;
       
  3659     for( ; index < count; index++ )
       
  3660         {
       
  3661         if( ( iStartedTestCases[index]->Status() & 
       
  3662               CUIStoreIf::EStatusRunning ) &&
       
  3663             ( &iStartedTestCases[index]->UIEngineContainer() ==
       
  3664               aContainer ) )
       
  3665             {
       
  3666             aTestCase = iStartedTestCases[index];
       
  3667             return KErrNone;
       
  3668             }
       
  3669         }
       
  3670     
       
  3671     return KErrNotFound;
       
  3672     
       
  3673     }
       
  3674     
       
  3675 /*
       
  3676 -------------------------------------------------------------------------------
       
  3677 
       
  3678     Class: CUIStore
       
  3679 
       
  3680     Method: UpdateCases
       
  3681 
       
  3682     Description: Refreshs iTestCases array ie. fetches test cases from 
       
  3683                 test framework
       
  3684 
       
  3685     Parameters: None
       
  3686 
       
  3687     Return Values: None
       
  3688 
       
  3689     Errors/Exceptions: None
       
  3690 
       
  3691     Status: Draft
       
  3692 
       
  3693 -------------------------------------------------------------------------------
       
  3694 */
       
  3695 TInt CUIStore::UpdateCases()
       
  3696     {
       
  3697     
       
  3698     if( iUpdateNeeded )
       
  3699         {
       
  3700         TInt handle = iUIStoreIf->PopupMsg( 
       
  3701             _L("Updating"), _L("Test cases"), 60 );
       
  3702         iTestCases.ResetAndDestroy();
       
  3703         TRAPD( ret, 
       
  3704             ret = iUIEngine->GetTestCasesL( iTestCases );
       
  3705             );
       
  3706         iUpdateNeeded = EFalse;
       
  3707         // Close popup
       
  3708         iUIStoreIf->Close( handle );
       
  3709         if( iTestCases.Count() == 0 )
       
  3710             {
       
  3711             iUIStoreIf->PopupMsg( _L("No test cases found"), 
       
  3712                                   _L("e.g. check TestEngine log"), 
       
  3713                                   3 );
       
  3714             }
       
  3715         return ret;
       
  3716         }
       
  3717     
       
  3718     return KErrNone;
       
  3719             
       
  3720     }
       
  3721 
       
  3722 /*
       
  3723 -------------------------------------------------------------------------------
       
  3724 
       
  3725     Class: CUIStore
       
  3726 
       
  3727     Method: CheckIniL
       
  3728 
       
  3729     Description: Check ini file
       
  3730 
       
  3731     Parameters: None
       
  3732 
       
  3733     Return Values: None
       
  3734 
       
  3735     Errors/Exceptions: None
       
  3736 
       
  3737     Status: Draft
       
  3738 
       
  3739 -------------------------------------------------------------------------------
       
  3740 */
       
  3741 void CUIStore::CheckIniL( TFileName& aIni )
       
  3742     {
       
  3743     
       
  3744     RFs fs;
       
  3745     User::LeaveIfError( fs.Connect() );
       
  3746     RFile file;
       
  3747     TInt err = KErrNone;
       
  3748     TErrorNotification error;
       
  3749     error.iModule.Copy( KUIStore );
       
  3750 
       
  3751     TStifUtil::CorrectFilePathL( aIni );
       
  3752     
       
  3753     if ( aIni.Length() != 0 )
       
  3754         {
       
  3755         err = file.Open ( fs, aIni, EFileRead );
       
  3756 
       
  3757         if ( err == KErrNone )
       
  3758             {
       
  3759             // Use the file given as command line parameter
       
  3760             iUIStoreIf->PopupMsg( _L("Using given ini-file"), 
       
  3761                                   KNullDesC, 0 );
       
  3762             file.Close();
       
  3763             fs.Close(); 
       
  3764             return;
       
  3765             }
       
  3766         else
       
  3767             { 
       
  3768             error.iText.Copy( _L("Can't open given ini-file") );
       
  3769             iUIStoreIf->Error( error );  
       
  3770             aIni.Zero();       
       
  3771             }
       
  3772         }
       
  3773         
       
  3774     // Try to locate default ini file from every drive
       
  3775     TDriveList drivelist; 
       
  3776 	User::LeaveIfError( fs.DriveList(drivelist) );
       
  3777 	// A TDriveList (the list of available drives), is an array of 
       
  3778 	// 26 bytes. Each byte with a non zero value signifies that the 
       
  3779 	// corresponding drive is available.
       
  3780 
       
  3781     TInt driveNumber; 
       
  3782 	TChar driveLetter;
       
  3783 
       
  3784 	for( driveNumber=EDriveA; driveNumber<=EDriveZ; driveNumber++ )
       
  3785 		{
       
  3786 		if( !drivelist[driveNumber] ) 
       
  3787 			{
       
  3788 			// If drive-list entry is zero, drive is not available
       
  3789 			continue;
       
  3790 			}
       
  3791         User::LeaveIfError(
       
  3792             fs.DriveToChar( driveNumber, driveLetter ));
       
  3793         
       
  3794         aIni.Zero();
       
  3795         aIni.Append( driveLetter );
       
  3796         aIni.Append( _L(":") );
       
  3797         aIni.Append( KDefaultIni );
       
  3798 
       
  3799         // Try to open
       
  3800         err = file.Open ( fs, aIni, EFileRead );
       
  3801 
       
  3802         if ( err == KErrNone )
       
  3803             {
       
  3804             // Use default file
       
  3805             file.Close();
       
  3806             TFileName info( _L("Using default ini-file ") );
       
  3807             if( info.MaxLength()-info.Length() >  aIni.Length() )
       
  3808                 {
       
  3809                 // Show also filename if fits to descriptor
       
  3810                 info.Append( aIni );
       
  3811                 }
       
  3812             iUIStoreIf->PopupMsg( info, KNullDesC, 0 );
       
  3813             break;
       
  3814             }
       
  3815         }
       
  3816     if( err != KErrNone )
       
  3817         {
       
  3818         iUIStoreIf->PopupMsg( _L("Starting without ini-file"), 
       
  3819                               KNullDesC,  0);
       
  3820         aIni.Zero();            
       
  3821         }
       
  3822 
       
  3823     fs.Close();    
       
  3824 
       
  3825     }
       
  3826 
       
  3827 /*
       
  3828 -------------------------------------------------------------------------------
       
  3829 
       
  3830     Class: CUIStore
       
  3831 
       
  3832     Method: ParseTestSetName
       
  3833 
       
  3834     Description: Parses test set name from test set filename.
       
  3835 
       
  3836     Parameters: const TDesC& aSetFileName: in: Test set filename
       
  3837                 TPtrC& aSetName: out: testset name
       
  3838                 TFileName& aFileName: in: filenamebuffer
       
  3839 
       
  3840     Return Values: Symbian OS error code
       
  3841 
       
  3842     Errors/Exceptions: None
       
  3843 
       
  3844     Status: Draft
       
  3845 
       
  3846 -------------------------------------------------------------------------------
       
  3847 */
       
  3848 TInt CUIStore::ParseTestSetName( const TDesC& aSetFileName, 
       
  3849                                  TPtrC& aSetName,
       
  3850                                  TFileName& aFileName )
       
  3851     {
       
  3852     if( aSetFileName.Length() > KMaxFileName )
       
  3853         {
       
  3854         return KErrArgument;
       
  3855         }
       
  3856     
       
  3857     aFileName.Copy( aSetFileName );
       
  3858     TParsePtr p( aFileName );
       
  3859     aSetName.Set( p.NameAndExt() ); // gives test set name without path
       
  3860     
       
  3861     if( aSetName.Length() > KMaxName )
       
  3862         {
       
  3863         return KErrArgument;
       
  3864         }
       
  3865     
       
  3866     return KErrNone;
       
  3867     
       
  3868     }
       
  3869 
       
  3870 /*
       
  3871 -------------------------------------------------------------------------------
       
  3872 
       
  3873     Class: CUIStore
       
  3874 
       
  3875     Method: RemotePopup
       
  3876 
       
  3877     Description: Do remote message popup 
       
  3878 
       
  3879     Parameters: const TDesC& aReq: in: request
       
  3880 
       
  3881     Return Values: Symbian OS error code
       
  3882 
       
  3883     Errors/Exceptions: None
       
  3884 
       
  3885     Status: Draft
       
  3886 
       
  3887 -------------------------------------------------------------------------------
       
  3888 */
       
  3889 TInt CUIStore::RemotePopup( CUIEngineContainer* aContainer,
       
  3890                             const TDesC& aMsg, 
       
  3891                             CStifTFwIfProt* aResp,
       
  3892                             TPopupPriority aPopupPriority )
       
  3893     {
       
  3894     TInt ret = KErrNone;
       
  3895     
       
  3896     CUIStorePopup* popup = NULL;
       
  3897     TRAP( ret, popup = CUIStorePopup::NewL( this, aContainer, aResp, aPopupPriority, aMsg ); );
       
  3898     if( ret != KErrNone )
       
  3899         {
       
  3900         return ret;
       
  3901         }
       
  3902     ret = iPopups.Append( popup );
       
  3903     if( ret != KErrNone )
       
  3904         {
       
  3905         delete popup;
       
  3906         return ret;
       
  3907         }
       
  3908                 
       
  3909     // We'll put new popup to the top if there are no popups active or if
       
  3910     // currently active popup has lower priority than the new one               
       
  3911     if( !iPopupActive || iActivePopupPriority > popup->GetPriority() ) 
       
  3912         {       
       
  3913         SetRemotePopupFromQueue();
       
  3914         }
       
  3915 
       
  3916     return ret;
       
  3917     }
       
  3918 
       
  3919 /*
       
  3920 -------------------------------------------------------------------------------
       
  3921 
       
  3922     Class: CUIStore
       
  3923 
       
  3924     Method: SetRemotePopupFromQueue
       
  3925 
       
  3926     Description: Prints the highest priority popup to the UI from the popup 
       
  3927     queue
       
  3928 
       
  3929     Parameters: None
       
  3930 
       
  3931     Return Values: None
       
  3932 
       
  3933     Errors/Exceptions: None
       
  3934 
       
  3935     Status: Draft @js
       
  3936 
       
  3937 -------------------------------------------------------------------------------
       
  3938 */
       
  3939 
       
  3940 void CUIStore::SetRemotePopupFromQueue()
       
  3941     {
       
  3942     CUIStorePopup* popup = NULL;
       
  3943     
       
  3944     if(iPopups.Count() > 0 )
       
  3945         {        
       
  3946         TInt highest = 0;
       
  3947         
       
  3948         // Let's get the highest priority popup and print it to the UI
       
  3949         for( TInt x=0; x<iPopups.Count(); x++)
       
  3950             {            
       
  3951             if( iPopups[x]->GetPriority() < iPopups[highest]->GetPriority() )    
       
  3952                 {
       
  3953                 highest = x;
       
  3954                 }
       
  3955             }
       
  3956         
       
  3957         popup = iPopups[highest];
       
  3958         
       
  3959         if( popup == NULL )
       
  3960             {
       
  3961             // Some weird error
       
  3962             iPopupActive = EFalse;
       
  3963             return;        
       
  3964             }
       
  3965         
       
  3966         // Change the active popup priority        
       
  3967         iActivePopupPriority = popup->GetPriority();             
       
  3968                 
       
  3969         // Create proper popup        
       
  3970         if( popup->GetPriority() == EPopupPriorityHighest )
       
  3971             {                                 
       
  3972             popup->Start( popup->GetMessage().Right( popup->GetMessage().Length() - KRcpHeaderLen ),
       
  3973                 _L("Press any key to send 'remote run started' message"));                                  
       
  3974             }
       
  3975         else if( popup->GetPriority() == EPopupPriorityNormal )
       
  3976             {
       
  3977             popup->Start( popup->GetMessage().Right( popup->GetMessage().Length() - KRcpHeaderLen ),
       
  3978                 _L("Press any key to set event") );        
       
  3979             }
       
  3980         else if( popup->GetPriority() == EPopupPriorityLow )
       
  3981             {           
       
  3982             popup->Start( popup->GetMessage().Right( popup->GetMessage().Length() - KRcpHeaderLen ),
       
  3983                 _L("Press 1-9 to return negative error value, a to switch to another remote run result popup, or any other key to return 0") );                                    
       
  3984             }
       
  3985             
       
  3986         iPopupActive = ETrue;                                
       
  3987         }
       
  3988     }
       
  3989 /*
       
  3990 -------------------------------------------------------------------------------
       
  3991 
       
  3992     Class: CUIStore
       
  3993 
       
  3994     Method: ShuffleRemoteRunResultPopups
       
  3995 
       
  3996     Description: Shuffle remote run result popups 
       
  3997 
       
  3998     Parameters: CUIStorePopup* aPopup (currently active popup)
       
  3999 
       
  4000     Return Values: None
       
  4001 
       
  4002     Errors/Exceptions: None
       
  4003 
       
  4004     Status: Draft @js
       
  4005 
       
  4006 -------------------------------------------------------------------------------
       
  4007 */
       
  4008 void CUIStore::ShuffleRemoteRunResultPopups( CUIStorePopup* aPopup )
       
  4009     {    
       
  4010     TInt nextPopupId = -1;
       
  4011     
       
  4012     for( TInt x=0; x<iPopups.Count(); x++)
       
  4013         {            
       
  4014         // Lets find the next remote run result priority popup
       
  4015         if( iPopups[x]->GetPriority() == EPopupPriorityLow && iPopups[x] != aPopup )    
       
  4016             {
       
  4017             nextPopupId = x;
       
  4018             break;
       
  4019             }
       
  4020         }
       
  4021     
       
  4022     if( nextPopupId == -1 )            
       
  4023         {
       
  4024         // We'll print error message popup, because there weren't any other remote run 
       
  4025         // result popups active
       
  4026 
       
  4027         iUIStoreIf->PopupMsg( 
       
  4028             _L("Error! There weren't any other remote run result popups active."), 
       
  4029             _L(""), 
       
  4030             5 );        
       
  4031         User::After( 5000000 );
       
  4032         iPopups.Append( aPopup );
       
  4033         SetRemotePopupFromQueue();
       
  4034         return;
       
  4035         }
       
  4036 
       
  4037     // We'll add the popup to the end of the array    
       
  4038     TInt ret = iPopups.Append( aPopup );
       
  4039         
       
  4040     if( ret != KErrNone )
       
  4041         {
       
  4042         delete aPopup;
       
  4043         return;
       
  4044         }
       
  4045         
       
  4046     // Print the next popup from queue
       
  4047     SetRemotePopupFromQueue();
       
  4048     }
       
  4049 
       
  4050 /*
       
  4051 -------------------------------------------------------------------------------
       
  4052 
       
  4053     Class: CUIStore
       
  4054 
       
  4055     Method: RemotePopup
       
  4056 
       
  4057     Description: Do remote message popup 
       
  4058 
       
  4059     Parameters: const TDesC& aReq: in: request
       
  4060 
       
  4061     Return Values: Symbian OS error code
       
  4062 
       
  4063     Errors/Exceptions: None
       
  4064 
       
  4065     Status: Draft
       
  4066 
       
  4067 -------------------------------------------------------------------------------
       
  4068 */
       
  4069 TInt CUIStore::RemotePopupComplete( CUIStorePopup* aPopup, 
       
  4070                                     TInt aError,
       
  4071                                     CUIEngineContainer* aContainer,
       
  4072                                     CStifTFwIfProt* aResp,
       
  4073                                     TKeyCode aKeyCode )
       
  4074     {
       
  4075     
       
  4076     TInt ret = KErrNone;
       
  4077     TInt index = iPopups.Find( aPopup );
       
  4078     if( index < 0 )
       
  4079         {
       
  4080         User::Panic( KUIStore, KErrGeneral );
       
  4081         }
       
  4082     iPopups.Remove( index );   
       
  4083 
       
  4084     iPopupActive = EFalse;
       
  4085     iActivePopupPriority = EPopupPriorityLow;
       
  4086 
       
  4087     if( aError != KErrNone )
       
  4088         {
       
  4089         ret = aError;
       
  4090         }
       
  4091     else
       
  4092         {
       
  4093         TChar c( aKeyCode );
       
  4094         if( c.IsDigit() )
       
  4095             {
       
  4096             // Solve return value
       
  4097             ret = -( aKeyCode - '0' );
       
  4098             }
       
  4099         else
       
  4100             {
       
  4101             ret = KErrNone;
       
  4102             }
       
  4103         }
       
  4104     // If aResp is given, send it
       
  4105     if( aResp )
       
  4106         {     
       
  4107         switch( aResp->iCmdType )
       
  4108             {
       
  4109             case CStifTFwIfProt::ECmdRun:
       
  4110                 {
       
  4111                 TChar response( aKeyCode );  
       
  4112                 RDebug::Print(_L("CUIStore::RemotePopupComplete: user pressed key %c"), (char)response);
       
  4113                   
       
  4114                 if( aPopup->GetPriority() == EPopupPriorityHighest )
       
  4115                     {                                        
       
  4116                     // User has given response to remote run started- popup
       
  4117                     aResp->Append( CStifTFwIfProt::RunStatus, 
       
  4118                       CStifTFwIfProt::ERunStarted );                      
       
  4119                     }                
       
  4120                 else if( aPopup->GetPriority() == EPopupPriorityLow &&  response=='a' )
       
  4121                     {                                        
       
  4122                     // User wants to change current remote run result popup to other
       
  4123                     // remote run result popup. 
       
  4124                     
       
  4125                     ShuffleRemoteRunResultPopups( aPopup );                             
       
  4126                     return KErrNone;
       
  4127                     }
       
  4128                 else 
       
  4129                     {                                    
       
  4130                     // The test case result was given
       
  4131                     aResp->Append( CStifTFwIfProt::RunStatus, 
       
  4132                                CStifTFwIfProt::ERunReady );
       
  4133                     if( ret != KErrNone )
       
  4134                         {
       
  4135                         aResp->Append( CStifTFwIfProt::RunStatusParams, 
       
  4136                                        CStifTFwIfProt::ERunResult, ret );
       
  4137                         }                   
       
  4138                     }
       
  4139                 break;
       
  4140                 }
       
  4141             case CStifTFwIfProt::ECmdSendReceive:
       
  4142                 {
       
  4143                 aResp->Append( CStifTFwIfProt::RunStatus, 
       
  4144                                CStifTFwIfProt::ERunReady );
       
  4145                 if( ret != KErrNone )
       
  4146                     {
       
  4147                     aResp->Append( CStifTFwIfProt::RunStatusParams, 
       
  4148                                    CStifTFwIfProt::ERunResult, ret );
       
  4149                     }
       
  4150                 break;
       
  4151                 }
       
  4152             case CStifTFwIfProt::ECmdPause:
       
  4153             case CStifTFwIfProt::ECmdResume:
       
  4154             case CStifTFwIfProt::ECmdCancel:
       
  4155             case CStifTFwIfProt::ECmdRequest:
       
  4156             case CStifTFwIfProt::ECmdRelease:
       
  4157             default:
       
  4158                 if( ret != KErrNone )
       
  4159                     {
       
  4160                     aResp->Append( CStifTFwIfProt::RespParam, 
       
  4161                                    CStifTFwIfProt::ERespResult, 
       
  4162                                    ret );
       
  4163                     }
       
  4164                 break;
       
  4165             }
       
  4166         
       
  4167         ret = aContainer->RemoteReceive( aResp->Message() ); 
       
  4168         }
       
  4169                 
       
  4170     delete aPopup;      
       
  4171     
       
  4172     SetRemotePopupFromQueue();
       
  4173     
       
  4174     return ret;
       
  4175               
       
  4176     }
       
  4177 
       
  4178 /*
       
  4179 -------------------------------------------------------------------------------
       
  4180 
       
  4181     Class: CUIStore
       
  4182 
       
  4183     Method: ReadFiltersL
       
  4184 
       
  4185     Description: Reads filters from test framework initialization file.
       
  4186         
       
  4187     Parameters: RPointerArray<TDesC>& aFilters: array to be filled
       
  4188 
       
  4189     Return Values: None
       
  4190 
       
  4191     Errors/Exceptions: 
       
  4192 
       
  4193     Status: Draft
       
  4194 
       
  4195 -------------------------------------------------------------------------------
       
  4196 */
       
  4197 EXPORT_C void CUIStore::ReadFiltersL(RPointerArray<TDesC>& aFilters)
       
  4198     {
       
  4199     // Clean array
       
  4200     aFilters.ResetAndDestroy();
       
  4201     
       
  4202     // Locate file
       
  4203     _LIT(KFilterSectionStart, "[Filters]");
       
  4204     _LIT(KFilterSectionEnd, "[End_Filters]");
       
  4205     _LIT(KFilterDefinition, "filter=");
       
  4206 
       
  4207     // Parse initialization file
       
  4208     TInt err = KErrNone;
       
  4209     CStifParser* parser;
       
  4210     
       
  4211     RDebug::Print(_L("STIF: Try to read filters from [%S]"), &iTestFrameworkIni);
       
  4212     parser = CStifParser::NewL(KNullDesC, iTestFrameworkIni);
       
  4213     CleanupStack::PushL(parser);
       
  4214 
       
  4215     // Parser created (file exists), create section parser
       
  4216     CStifSectionParser* section;
       
  4217     section = parser->SectionL(KFilterSectionStart, KFilterSectionEnd);
       
  4218     if(section)
       
  4219         {
       
  4220         CleanupStack::PushL(section);
       
  4221             
       
  4222         // Get item lines
       
  4223         CStifItemParser* item = section->GetItemLineL(KFilterDefinition, ENoTag);
       
  4224             
       
  4225         TPtrC ptr;
       
  4226             
       
  4227         while(item)
       
  4228             {
       
  4229             CleanupStack::PushL(item);
       
  4230                 
       
  4231             // Read filter value
       
  4232             err = item->GetString(KNullDesC, ptr);
       
  4233             if(err == KErrNone)
       
  4234                 {
       
  4235                 HBufC* filter = ptr.AllocLC();
       
  4236                 User::LeaveIfError(aFilters.Append(filter));
       
  4237                 CleanupStack::Pop();
       
  4238                 }
       
  4239                 
       
  4240             CleanupStack::PopAndDestroy(item);
       
  4241             item = NULL;
       
  4242             item = section->GetNextItemLineL(KFilterDefinition, ENoTag);
       
  4243             }
       
  4244             
       
  4245         CleanupStack::PopAndDestroy(section);
       
  4246         }
       
  4247         
       
  4248     // Clean
       
  4249     CleanupStack::PopAndDestroy(parser);
       
  4250 
       
  4251     // If there are some filters added, first filter has to be "No filter"
       
  4252     if(aFilters.Count() > 0)
       
  4253         {
       
  4254         RDebug::Print(_L("STIF: Filters loaded"));
       
  4255         _LIT(KNoFilter, "No filter");
       
  4256         HBufC* name = KNoFilter().AllocLC();
       
  4257         User::LeaveIfError(aFilters.Insert(name, 0));
       
  4258         CleanupStack::Pop(name);    
       
  4259         }
       
  4260     }
       
  4261 
       
  4262 /*
       
  4263 -------------------------------------------------------------------------------
       
  4264 
       
  4265     DESCRIPTION
       
  4266 
       
  4267     This module contains implementation of CUIStoreIf class member functions.
       
  4268 
       
  4269 -------------------------------------------------------------------------------
       
  4270 */
       
  4271 
       
  4272 // ================= MEMBER FUNCTIONS =========================================
       
  4273 
       
  4274 /*
       
  4275 -------------------------------------------------------------------------------
       
  4276 
       
  4277     Class: CUIStoreIf
       
  4278 
       
  4279     Method: ConstructL
       
  4280 
       
  4281     Description: Second phase constructor.
       
  4282 
       
  4283     Parameters: None
       
  4284 
       
  4285     Return Values: None
       
  4286 
       
  4287     Errors/Exceptions: Leaves if..
       
  4288 
       
  4289     Status: Draft
       
  4290 
       
  4291 -------------------------------------------------------------------------------
       
  4292 */
       
  4293 EXPORT_C void CUIStoreIf::ConstructL( )
       
  4294     {
       
  4295     
       
  4296     iUIStore = CUIStore::NewL( this );
       
  4297     
       
  4298     }
       
  4299 
       
  4300 
       
  4301 /*
       
  4302 -------------------------------------------------------------------------------
       
  4303 
       
  4304     Class: CUIStoreIf
       
  4305 
       
  4306     Method: CUIStoreIf
       
  4307 
       
  4308     Description: Constructor.
       
  4309     
       
  4310     Parameters: None
       
  4311 
       
  4312     Return Values: None
       
  4313 
       
  4314     Errors/Exceptions: None
       
  4315 
       
  4316     Status: Draft
       
  4317 
       
  4318 -------------------------------------------------------------------------------
       
  4319 */
       
  4320 EXPORT_C CUIStoreIf::CUIStoreIf( )
       
  4321     {
       
  4322     }
       
  4323 
       
  4324 
       
  4325 /*
       
  4326 -------------------------------------------------------------------------------
       
  4327 
       
  4328     Class: CUIStoreIf
       
  4329 
       
  4330     Method: ~CUIStoreIf
       
  4331 
       
  4332     Description: Destructor
       
  4333 
       
  4334     Parameters: None
       
  4335 
       
  4336     Return Values: None
       
  4337 
       
  4338     Errors/Exceptions: None
       
  4339 
       
  4340     Status: Draft
       
  4341 
       
  4342 -------------------------------------------------------------------------------
       
  4343 */
       
  4344 EXPORT_C CUIStoreIf::~CUIStoreIf()
       
  4345     {	
       
  4346     
       
  4347     delete iUIStore;
       
  4348     iUIStore = NULL;
       
  4349     
       
  4350     }
       
  4351 
       
  4352 
       
  4353 /*
       
  4354 -------------------------------------------------------------------------------
       
  4355 
       
  4356     Class: CUIStoreIf
       
  4357 
       
  4358     Method: UIStore
       
  4359 
       
  4360     Description: Returns reference to CUIStore object, which handles test 
       
  4361                  cases and test modules.
       
  4362         
       
  4363     Parameters: None
       
  4364 
       
  4365     Return Values: CUIStore reference
       
  4366 
       
  4367     Errors/Exceptions: None
       
  4368 
       
  4369     Status: Draft
       
  4370 
       
  4371 -------------------------------------------------------------------------------
       
  4372 */
       
  4373 EXPORT_C CUIStore& CUIStoreIf::UIStore()
       
  4374     {
       
  4375     
       
  4376     __ASSERT_ALWAYS( iUIStore, User::Panic( KUIStoreIf, KErrNotFound ) );
       
  4377         
       
  4378     return *iUIStore;
       
  4379         
       
  4380     }
       
  4381 
       
  4382 /*
       
  4383 -------------------------------------------------------------------------------
       
  4384 
       
  4385     DESCRIPTION
       
  4386 
       
  4387     This module contains implementation of CTestSetInfo class member functions.
       
  4388 
       
  4389 -------------------------------------------------------------------------------
       
  4390 */
       
  4391 
       
  4392 // ================= MEMBER FUNCTIONS =========================================
       
  4393 
       
  4394 /*
       
  4395 -------------------------------------------------------------------------------
       
  4396 
       
  4397     Class: CTestSetInfo
       
  4398 
       
  4399     Method: NewL
       
  4400 
       
  4401     Description: Construct the CTestSetInfo class
       
  4402 
       
  4403     Parameters: None
       
  4404 
       
  4405     Return Values: CTestSetInfo*                    New object
       
  4406 
       
  4407     Errors/Exceptions: Leaves if memory allocation fails or
       
  4408                        ConstructL leaves.
       
  4409 
       
  4410     Status: Draft
       
  4411 
       
  4412 -------------------------------------------------------------------------------
       
  4413 */
       
  4414 CTestSetInfo* CTestSetInfo::NewL( const TDesC& aName )
       
  4415     {
       
  4416     
       
  4417     CTestSetInfo* self = new ( ELeave ) CTestSetInfo();
       
  4418     CleanupStack::PushL( self );
       
  4419     self->ConstructL( aName );
       
  4420     CleanupStack::Pop( self );
       
  4421 
       
  4422     return self;
       
  4423 
       
  4424     }
       
  4425             
       
  4426 /*
       
  4427 -------------------------------------------------------------------------------
       
  4428 
       
  4429     Class: CTestSetInfo
       
  4430 
       
  4431     Method: ConstructL
       
  4432 
       
  4433     Description: Second phase constructor.
       
  4434 
       
  4435     Parameters: None
       
  4436 
       
  4437     Return Values: None
       
  4438 
       
  4439     Errors/Exceptions: Leaves if..
       
  4440 
       
  4441     Status: Draft
       
  4442 
       
  4443 -------------------------------------------------------------------------------
       
  4444 */
       
  4445 void CTestSetInfo::ConstructL( const TDesC& aName )
       
  4446     {
       
  4447     
       
  4448     iName = aName.AllocL();
       
  4449     
       
  4450     }
       
  4451 
       
  4452 
       
  4453 /*
       
  4454 -------------------------------------------------------------------------------
       
  4455 
       
  4456     Class: CTestSetInfo
       
  4457 
       
  4458     Method: CTestSetInfo
       
  4459 
       
  4460     Description: Constructor.
       
  4461     
       
  4462     Parameters: None
       
  4463 
       
  4464     Return Values: None
       
  4465 
       
  4466     Errors/Exceptions: None
       
  4467 
       
  4468     Status: Draft
       
  4469 
       
  4470 -------------------------------------------------------------------------------
       
  4471 */
       
  4472 CTestSetInfo::CTestSetInfo()
       
  4473     {
       
  4474     iLastStartedCaseIndex = 0;
       
  4475     }
       
  4476 
       
  4477 
       
  4478 /*
       
  4479 -------------------------------------------------------------------------------
       
  4480 
       
  4481     Class: CTestSetInfo
       
  4482 
       
  4483     Method: ~CTestSetInfo
       
  4484 
       
  4485     Description: Destructor
       
  4486 
       
  4487     Parameters: None
       
  4488 
       
  4489     Return Values: None
       
  4490 
       
  4491     Errors/Exceptions: None
       
  4492 
       
  4493     Status: Draft
       
  4494 
       
  4495 -------------------------------------------------------------------------------
       
  4496 */
       
  4497 CTestSetInfo::~CTestSetInfo()
       
  4498     {	
       
  4499     
       
  4500     iTestCases.ResetAndDestroy();
       
  4501     iTestCaseRefs.Reset();
       
  4502     iTestCases.Close();
       
  4503     iTestCaseRefs.Close();
       
  4504     
       
  4505     delete iName;
       
  4506     iName = NULL;
       
  4507     
       
  4508     }
       
  4509 /*
       
  4510 -------------------------------------------------------------------------------
       
  4511 
       
  4512     Class: CTestSetInfo
       
  4513 
       
  4514     Method: AddTestCase
       
  4515 
       
  4516     Description: Add test case to test set.
       
  4517         
       
  4518     Parameters: const CTestInfo& aTestInfo: in: test info
       
  4519 
       
  4520     Return Values: Symbian OS error code
       
  4521 
       
  4522     Errors/Exceptions: None
       
  4523 
       
  4524     Status: Draft
       
  4525 
       
  4526 -------------------------------------------------------------------------------
       
  4527 */
       
  4528 TInt CTestSetInfo::AddTestCase( const CTestInfo& aTestInfo )
       
  4529     {
       
  4530     
       
  4531     CTestInfo* testInfo = NULL;
       
  4532     
       
  4533     TRAPD( err, 
       
  4534         testInfo = CTestInfo::NewL();
       
  4535         testInfo->CopyL( aTestInfo );
       
  4536         );
       
  4537     if( err != KErrNone )
       
  4538         {
       
  4539         return err;
       
  4540         }
       
  4541 
       
  4542     if( iTestCaseRefs.Append( *testInfo ) != KErrNone )
       
  4543         {
       
  4544         delete testInfo;
       
  4545         return KErrNoMemory;        
       
  4546         }
       
  4547     if( iTestCases.Append( testInfo ) != KErrNone ) 
       
  4548         {
       
  4549         iTestCaseRefs.Remove( iTestCaseRefs.Count()-1 );
       
  4550         delete testInfo;
       
  4551         return KErrNoMemory;
       
  4552         }
       
  4553 
       
  4554     return KErrNone;
       
  4555     
       
  4556     }
       
  4557 
       
  4558 /*
       
  4559 -------------------------------------------------------------------------------
       
  4560 
       
  4561     Class: CTestSetInfo
       
  4562 
       
  4563     Method: InsertTestCase
       
  4564 
       
  4565     Description: Insert test case to test set.
       
  4566         
       
  4567     Parameters: const CTestInfo& aTestInfo: in: test info
       
  4568                 TInt aPos: in: position to add
       
  4569 
       
  4570     Return Values: Symbian OS error code
       
  4571 
       
  4572     Errors/Exceptions: None
       
  4573 
       
  4574     Status: Draft
       
  4575 
       
  4576 -------------------------------------------------------------------------------
       
  4577 */
       
  4578 TInt CTestSetInfo::InsertTestCase( const CTestInfo& aTestInfo, TInt aPos )
       
  4579     {
       
  4580     
       
  4581     if( ( aPos < 0 ) ||
       
  4582         ( aPos >= iTestCases.Count() ) )
       
  4583         {
       
  4584         return KErrArgument;
       
  4585         }
       
  4586     
       
  4587     CTestInfo* testInfo = NULL;
       
  4588     
       
  4589     TRAPD( err, 
       
  4590         testInfo = CTestInfo::NewL();
       
  4591         testInfo->CopyL( aTestInfo );
       
  4592         );
       
  4593     if( err != KErrNone )
       
  4594         {
       
  4595         return err;
       
  4596         }
       
  4597      
       
  4598     if( iTestCaseRefs.Insert( *testInfo, aPos ) != KErrNone )
       
  4599         {
       
  4600         delete testInfo;
       
  4601         return KErrNoMemory;        
       
  4602         }
       
  4603     if( iTestCases.Insert( testInfo, aPos ) != KErrNone )
       
  4604         {
       
  4605         iTestCaseRefs.Remove( aPos );
       
  4606         delete testInfo;
       
  4607         return KErrNoMemory;
       
  4608         }
       
  4609     
       
  4610     return err;
       
  4611         
       
  4612     }
       
  4613         
       
  4614 /*
       
  4615 -------------------------------------------------------------------------------
       
  4616 
       
  4617     Class: CTestSetInfo
       
  4618 
       
  4619     Method: RemoveTestCase
       
  4620 
       
  4621     Description: Remove test case from test set.
       
  4622         
       
  4623     Parameters: const CTestInfo& aTestInfo: in: test info
       
  4624 
       
  4625     Return Values: Symbian OS error code
       
  4626 
       
  4627     Errors/Exceptions: None
       
  4628 
       
  4629     Status: Draft
       
  4630 
       
  4631 -------------------------------------------------------------------------------
       
  4632 */
       
  4633 TInt CTestSetInfo::RemoveTestCase( const CTestInfo& aTestInfo )
       
  4634     {
       
  4635     
       
  4636     TInt count = iTestCases.Count();
       
  4637     for( TInt i=0; i<count; i++ )
       
  4638         {
       
  4639         if( aTestInfo == *iTestCases[i] )
       
  4640             {
       
  4641             CTestInfo* testInfo = iTestCases[i];
       
  4642             iTestCases.Remove( i );
       
  4643             iTestCaseRefs.Remove( i );
       
  4644             delete testInfo;
       
  4645             return KErrNone;
       
  4646             }
       
  4647         }
       
  4648 
       
  4649     return KErrNotFound;
       
  4650     
       
  4651     }
       
  4652     
       
  4653 /*
       
  4654 -------------------------------------------------------------------------------
       
  4655 
       
  4656     Class: CTestSetInfo
       
  4657 
       
  4658     Method: CopyL
       
  4659 
       
  4660     Description: Remove test case from test set.
       
  4661         
       
  4662     Parameters: const CTestInfo& aTestInfo: in: test info
       
  4663 
       
  4664     Return Values: Symbian OS error code
       
  4665 
       
  4666     Errors/Exceptions: None
       
  4667 
       
  4668     Status: Draft
       
  4669 
       
  4670 -------------------------------------------------------------------------------
       
  4671 */
       
  4672 void CTestSetInfo::CopyL( const CTestSetInfo& aTestSetInfo )
       
  4673     {
       
  4674     
       
  4675     iTestCaseRefs.Reset();
       
  4676     iTestCases.ResetAndDestroy();
       
  4677     
       
  4678     TInt count = aTestSetInfo.TestCases().Count();
       
  4679     for( TInt i=0; i<count; i++ )
       
  4680         {
       
  4681         User::LeaveIfError( AddTestCase( aTestSetInfo.TestCases()[i] ) );
       
  4682         }
       
  4683     
       
  4684     delete iName;
       
  4685     iName = 0;    
       
  4686     iName = aTestSetInfo.Name().AllocL(); 
       
  4687     
       
  4688     iLastStartedCaseIndex = aTestSetInfo.iLastStartedCaseIndex;
       
  4689          
       
  4690     }    
       
  4691 
       
  4692 /*
       
  4693 -------------------------------------------------------------------------------
       
  4694 
       
  4695     Class: CTestSetInfo
       
  4696 
       
  4697     Method: SetLastStartedCaseIndex
       
  4698 
       
  4699     Description: Sets the info which test case has been started lately.
       
  4700         
       
  4701     Parameters: TInt aCaseStarted: index of started test case
       
  4702 
       
  4703     Return Values: None
       
  4704 
       
  4705     Errors/Exceptions: None
       
  4706 
       
  4707     Status: Approved
       
  4708 
       
  4709 -------------------------------------------------------------------------------
       
  4710 */
       
  4711 void CTestSetInfo::SetLastStartedCaseIndex(TUint aLastStartedCaseIndex)
       
  4712     {
       
  4713     iLastStartedCaseIndex = aLastStartedCaseIndex;
       
  4714     }    
       
  4715 
       
  4716 /*
       
  4717 -------------------------------------------------------------------------------
       
  4718 
       
  4719     Class: CTestSetInfo
       
  4720 
       
  4721     Method: GetLastStartedCaseIndex
       
  4722 
       
  4723     Description: Gets the info which test case has been started lately.
       
  4724         
       
  4725     Parameters: None
       
  4726 
       
  4727     Return Values: TInt: index of lately started test case
       
  4728 
       
  4729     Errors/Exceptions: None
       
  4730 
       
  4731     Status: Approved
       
  4732 
       
  4733 -------------------------------------------------------------------------------
       
  4734 */
       
  4735 TUint CTestSetInfo::GetLastStartedCaseIndex(void)
       
  4736     {
       
  4737     return iLastStartedCaseIndex;
       
  4738     }    
       
  4739 
       
  4740 // ================= OTHER EXPORTED FUNCTIONS =================================
       
  4741 
       
  4742 // End of File