testexecfw/stf/stfui/uiengine/src/UIStore.cpp
changeset 2 8bb370ba6d1d
equal deleted inserted replaced
1:bbd31066657e 2:8bb370ba6d1d
       
     1 /* 
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 * 
       
    14 * Description: This module contains 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             _LIT(KTEFTestModule, "TEFTestModule");
       
   947             _LIT(KTEFTestModuleLite, "TEFTestModuleLite");
       
   948             if(fullName != KTestCombiner && fullName != KSUEvent && fullName != KTestScripter&& fullName != KTEFTestModule && fullName != KTEFTestModuleLite)
       
   949                 { 
       
   950                 HBufC* name = fullName.AllocLC();
       
   951                 iLogger->Log( _L("Found: %S"), name );
       
   952                 User::LeaveIfError( aModuleNames.Append( name ) );
       
   953                 CleanupStack::Pop( name );
       
   954                 }
       
   955             }
       
   956         delete testModules;
       
   957         testModules = NULL;
       
   958 		}
       
   959     
       
   960     CleanupStack::PopAndDestroy(); // fsSession 
       
   961     
       
   962     } 
       
   963     
       
   964 /*
       
   965 -------------------------------------------------------------------------------
       
   966 
       
   967     Class: CUIStore
       
   968 
       
   969     Method: CreateTestSet
       
   970 
       
   971     Description: Create new test set.
       
   972 
       
   973     Parameters: TDesC& aSetName: in: test set name (Max length is KMaxName)
       
   974     
       
   975     Return Values: Symbian OS error code
       
   976 
       
   977     Errors/Exceptions: None
       
   978 
       
   979     Status: Draft
       
   980 
       
   981 -------------------------------------------------------------------------------
       
   982 */ 
       
   983 EXPORT_C TInt CUIStore::CreateTestSet( const TDesC& aSetName )
       
   984     {
       
   985     
       
   986     TPtrC setName;
       
   987     TFileName tmp;
       
   988     TInt ret = ParseTestSetName( aSetName, setName, tmp );
       
   989     if( ret != KErrNone )
       
   990         {
       
   991         return ret;
       
   992         }
       
   993         
       
   994     CTestSetInfo* setInfo = NULL;
       
   995     if( FindSetByName( setName, setInfo ) == KErrNone )
       
   996         {
       
   997         return KErrAlreadyExists;
       
   998         }
       
   999     TRAPD( err, 
       
  1000         setInfo = CTestSetInfo::NewL( setName );
       
  1001         );
       
  1002     if( err != KErrNone )
       
  1003         {
       
  1004         return err;
       
  1005         }
       
  1006     if( iTestSets.Append( setInfo ) != KErrNone )
       
  1007         {
       
  1008         delete setInfo;
       
  1009         return KErrNoMemory;
       
  1010         }
       
  1011             
       
  1012     return KErrNone;
       
  1013     
       
  1014     }
       
  1015     
       
  1016 /*
       
  1017 -------------------------------------------------------------------------------
       
  1018 
       
  1019     Class: CUIStore
       
  1020 
       
  1021     Method: RemoveTestSet
       
  1022 
       
  1023     Description: Remove active test set.
       
  1024 
       
  1025     Parameters: TDesC& aSetName: in: test set name (Max length is KMaxName)
       
  1026     
       
  1027     Return Values: Symbian OS error code
       
  1028 
       
  1029     Errors/Exceptions: None
       
  1030 
       
  1031     Status: Draft
       
  1032 
       
  1033 -------------------------------------------------------------------------------
       
  1034 */ 
       
  1035 EXPORT_C TInt CUIStore::RemoveTestSet( const TDesC& aSetName )
       
  1036     {
       
  1037     
       
  1038     TPtrC setName;
       
  1039     TFileName tmp;
       
  1040     TInt ret = ParseTestSetName( aSetName, setName, tmp );
       
  1041     if( ret != KErrNone )
       
  1042         {
       
  1043         return ret;
       
  1044         }
       
  1045     
       
  1046     TInt count = iTestSets.Count();
       
  1047     TInt index = 0;
       
  1048     for( ; index < count; index++ )
       
  1049         {
       
  1050         if( iTestSets[index]->Name() == setName )
       
  1051             {
       
  1052             break;
       
  1053             }
       
  1054         }
       
  1055     if( index == count ) 
       
  1056         { 
       
  1057         return KErrNotFound;
       
  1058         }
       
  1059 
       
  1060     CTestSetInfo* setInfo = iTestSets[index];
       
  1061     iTestSets.Remove( index );
       
  1062     
       
  1063     // If started test set keeps info about currently removed test set
       
  1064     // then remove also this info
       
  1065     CStartedTestSet *stset;
       
  1066     for(index = 0; index < iStartedTestSets.Count(); index++)
       
  1067         {
       
  1068         stset = iStartedTestSets[index];
       
  1069         if(stset->GetOriginalTestSet() == setInfo)
       
  1070             {
       
  1071             stset->NullOriginalTestSet();
       
  1072             }
       
  1073         }
       
  1074     
       
  1075     delete setInfo;
       
  1076 
       
  1077     return KErrNone;
       
  1078     
       
  1079     }
       
  1080 
       
  1081 /*
       
  1082 -------------------------------------------------------------------------------
       
  1083 
       
  1084     Class: CUIStore
       
  1085 
       
  1086     Method: TestSets
       
  1087 
       
  1088     Description: Query test sets.
       
  1089 
       
  1090     Parameters:RRefArray<CTestSetInfo>& aSetInfos: out: list of test sets
       
  1091     
       
  1092     Return Values: Symbian OS error code
       
  1093 
       
  1094     Errors/Exceptions: None
       
  1095 
       
  1096     Status: Draft
       
  1097 
       
  1098 -------------------------------------------------------------------------------
       
  1099 */ 
       
  1100 EXPORT_C TInt CUIStore::TestSets( RRefArray<CTestSetInfo>& aSetInfos )
       
  1101     {
       
  1102     
       
  1103     TInt count = iTestSets.Count();
       
  1104     for( TInt i=0; i<count; i++ )
       
  1105         {
       
  1106         if( aSetInfos.Append( *iTestSets[i] ) != KErrNone )
       
  1107             {
       
  1108             return KErrNoMemory;
       
  1109             }
       
  1110         }
       
  1111     return KErrNone;
       
  1112     
       
  1113     }       
       
  1114 
       
  1115 /*
       
  1116 -------------------------------------------------------------------------------
       
  1117 
       
  1118     Class: CUIStore
       
  1119 
       
  1120     Method: TestSets
       
  1121 
       
  1122     Description: Query test sets.
       
  1123 
       
  1124     Parameters:RRefArray<CTestSetInfo>& aSetInfos: out: list of test sets
       
  1125     
       
  1126     Return Values: Symbian OS error code
       
  1127 
       
  1128     Errors/Exceptions: None
       
  1129 
       
  1130     Status: Draft
       
  1131 
       
  1132 -------------------------------------------------------------------------------
       
  1133 */ 
       
  1134 EXPORT_C const CTestSetInfo& CUIStore::TestSetL( const TDesC& aSetName  )
       
  1135     {
       
  1136     
       
  1137     TPtrC setName;
       
  1138     TFileName tmp;
       
  1139     User::LeaveIfError( ParseTestSetName( aSetName, setName, tmp ) );
       
  1140         
       
  1141     CTestSetInfo* setInfo = NULL;
       
  1142     User::LeaveIfError( FindSetByName( setName, setInfo ) );
       
  1143     return *setInfo;
       
  1144     
       
  1145     }                
       
  1146         
       
  1147 /*
       
  1148 -------------------------------------------------------------------------------
       
  1149 
       
  1150     Class: CUIStore
       
  1151 
       
  1152     Method: AddToTestSet
       
  1153 
       
  1154     Description: Add test case to test set.
       
  1155 
       
  1156     Parameters: TDesC& aSetName: out: test set name
       
  1157                 CTestInfo& aTestInfo: in: test case to add
       
  1158     
       
  1159     Return Values: Symbian OS error code
       
  1160 
       
  1161     Errors/Exceptions: None
       
  1162 
       
  1163     Status: Draft
       
  1164 
       
  1165 -------------------------------------------------------------------------------
       
  1166 */ 
       
  1167 EXPORT_C TInt CUIStore::AddToTestSet( const TDesC& aSetName, 
       
  1168                                       const CTestInfo& aTestInfo )
       
  1169     {
       
  1170     
       
  1171     TPtrC setName;
       
  1172     TFileName tmp;
       
  1173     TInt ret = ParseTestSetName( aSetName, setName, tmp );
       
  1174     if( ret != KErrNone )
       
  1175         {
       
  1176         return ret;
       
  1177         }
       
  1178         
       
  1179     CTestSetInfo* setInfo = NULL;
       
  1180     ret = FindSetByName( setName, setInfo );
       
  1181     if( ret != KErrNone )
       
  1182         {
       
  1183         return ret;
       
  1184         }
       
  1185     
       
  1186     return setInfo->AddTestCase( aTestInfo );
       
  1187         
       
  1188     }       
       
  1189 
       
  1190 /*
       
  1191 -------------------------------------------------------------------------------
       
  1192 
       
  1193     Class: CUIStore
       
  1194 
       
  1195     Method: InsertToTestSet
       
  1196 
       
  1197     Description: Insert test case to test set.
       
  1198 
       
  1199     Parameters: TDesC& aSetName: out: test set name
       
  1200                 CTestInfo& aTestInfo: in: test case to add
       
  1201                 TInt aPos: in: position to add
       
  1202     
       
  1203     Return Values: Symbian OS error code
       
  1204 
       
  1205     Errors/Exceptions: None
       
  1206 
       
  1207     Status: Draft
       
  1208 
       
  1209 -------------------------------------------------------------------------------
       
  1210 */ 
       
  1211 EXPORT_C TInt CUIStore::InsertToTestSet( const TDesC& aSetName, 
       
  1212                                          const CTestInfo& aTestInfo,
       
  1213                                          TInt aPos  )
       
  1214     {
       
  1215     
       
  1216     TPtrC setName;
       
  1217     TFileName tmp;
       
  1218     TInt ret = ParseTestSetName( aSetName, setName, tmp );
       
  1219     if( ret != KErrNone )
       
  1220         {
       
  1221         return ret;
       
  1222         }
       
  1223         
       
  1224     CTestSetInfo* setInfo = NULL;
       
  1225     ret = FindSetByName( setName, setInfo );
       
  1226     if( ret != KErrNone )
       
  1227         {
       
  1228         return ret;
       
  1229         }
       
  1230     
       
  1231     return setInfo->InsertTestCase( aTestInfo, aPos );
       
  1232         
       
  1233     }       
       
  1234     
       
  1235 /*
       
  1236 -------------------------------------------------------------------------------
       
  1237 
       
  1238     Class: CUIStore
       
  1239 
       
  1240     Method: RemoveFromTestSet
       
  1241 
       
  1242     Description: Remove test case from test set.
       
  1243 
       
  1244     Parameters: TDesC& aSetName: out: test set name
       
  1245                 CTestInfo& aTestInfo: in: test case to remove
       
  1246     
       
  1247     Return Values: Symbian OS error code
       
  1248 
       
  1249     Errors/Exceptions: None
       
  1250 
       
  1251     Status: Draft
       
  1252 
       
  1253 -------------------------------------------------------------------------------
       
  1254 */
       
  1255 EXPORT_C TInt CUIStore::RemoveFromTestSet( const TDesC& aSetName, 
       
  1256                                            const CTestInfo& aTestInfo )
       
  1257     {
       
  1258     
       
  1259     TPtrC setName;
       
  1260     TFileName tmp;
       
  1261     TInt ret = ParseTestSetName( aSetName, setName, tmp );
       
  1262     if( ret != KErrNone )
       
  1263         {
       
  1264         return ret;
       
  1265         }
       
  1266         
       
  1267     CTestSetInfo* setInfo = NULL;
       
  1268     ret = FindSetByName( setName, setInfo );
       
  1269     if( ret != KErrNone )
       
  1270         {
       
  1271         return ret;
       
  1272         }
       
  1273     
       
  1274     return setInfo->RemoveTestCase( aTestInfo );
       
  1275     
       
  1276     }       
       
  1277 
       
  1278 /*
       
  1279 -------------------------------------------------------------------------------
       
  1280 
       
  1281     Class: CUIStore
       
  1282 
       
  1283     Method: SaveTestSet
       
  1284 
       
  1285     Description: Save test set. Deprecated, SaveTestSet2 to be used instead 
       
  1286 
       
  1287     Parameters: TDesC&:  out: test set name
       
  1288     
       
  1289     Return Values: Symbian OS error code
       
  1290 
       
  1291     Errors/Exceptions: None
       
  1292 
       
  1293     Status: Draft
       
  1294 
       
  1295 -------------------------------------------------------------------------------
       
  1296 */
       
  1297 EXPORT_C TInt CUIStore::SaveTestSet( const TDesC& /* aSetName */ )
       
  1298     {  
       
  1299         
       
  1300     return KErrNotSupported;
       
  1301     
       
  1302     }  
       
  1303 
       
  1304 /*
       
  1305 -------------------------------------------------------------------------------
       
  1306 
       
  1307     Class: CUIStore
       
  1308 
       
  1309     Method: SaveTestSet2
       
  1310 
       
  1311     Description: Save test set.
       
  1312 
       
  1313     Parameters: TDes& aSetName: out: test set name
       
  1314     
       
  1315     Return Values: Symbian OS error code
       
  1316 
       
  1317     Errors/Exceptions: None
       
  1318 
       
  1319     Status: Draft
       
  1320 
       
  1321 -------------------------------------------------------------------------------
       
  1322 */
       
  1323 EXPORT_C TInt CUIStore::SaveTestSet2( TDes& aSetName )
       
  1324     {
       
  1325     
       
  1326     TPtrC setName;
       
  1327     TFileName tmp;
       
  1328 
       
  1329     TTime current;
       
  1330     TDateTime date_rep;
       
  1331     current.HomeTime();
       
  1332     date_rep = current.DateTime();
       
  1333     TBuf<32> currSetName;
       
  1334     _LIT(f_ext,".set");
       
  1335     
       
  1336     //create "test set name" string
       
  1337      currSetName.AppendNum(date_rep.Year());
       
  1338      currSetName.Append('_');
       
  1339      currSetName.AppendNum(date_rep.Month()+1); // Incrimination necessary, because Day and Month fields of TDateTime class are 0 based
       
  1340      currSetName.Append('_');
       
  1341      currSetName.AppendNum(date_rep.Day()+1);
       
  1342      currSetName.Append('_');
       
  1343      currSetName.AppendNum(date_rep.Hour());
       
  1344      currSetName.Append('_');
       
  1345      currSetName.AppendNum(date_rep.Minute());
       
  1346      currSetName.Append('_');
       
  1347      currSetName.AppendNum(date_rep.Second());
       
  1348      currSetName.Append(f_ext);
       
  1349 
       
  1350     TInt ret = ParseTestSetName( aSetName, setName, tmp );
       
  1351     if( ret != KErrNone )
       
  1352         {
       
  1353         return ret;
       
  1354         }
       
  1355         
       
  1356     CTestSetInfo* setInfo = NULL;
       
  1357     ret = FindSetByName( setName, setInfo );
       
  1358     if( ret != KErrNone )
       
  1359         {
       
  1360         return ret;
       
  1361         }
       
  1362      
       
  1363     TRAPD( err,
       
  1364         SaveTestSetL( *setInfo, currSetName );
       
  1365         );
       
  1366     
       
  1367     aSetName.Copy(currSetName);
       
  1368     
       
  1369     return err;
       
  1370     
       
  1371     }  
       
  1372 
       
  1373 /*
       
  1374 -------------------------------------------------------------------------------
       
  1375 
       
  1376     Class: CUIStore
       
  1377 
       
  1378     Method: LoadTestSet
       
  1379 
       
  1380     Description: Load test set.
       
  1381 
       
  1382     Parameters: TDesC& aSetName: out: test set name
       
  1383     
       
  1384     Return Values: Symbian OS error code
       
  1385 
       
  1386     Errors/Exceptions: None
       
  1387 
       
  1388     Status: Draft
       
  1389 
       
  1390 -------------------------------------------------------------------------------
       
  1391 */
       
  1392 EXPORT_C TInt CUIStore::LoadTestSet( const TDesC& aSetName )
       
  1393     {
       
  1394     
       
  1395     TPtrC setName;
       
  1396     TFileName tmp;
       
  1397     TInt ret = ParseTestSetName( aSetName, setName, tmp );
       
  1398     if( ret != KErrNone )
       
  1399         {
       
  1400         return ret;
       
  1401         }
       
  1402         
       
  1403     TRAPD( err,
       
  1404         LoadTestSetL( setName, aSetName );
       
  1405         );
       
  1406     
       
  1407      if( err != KErrNone && err != KErrAlreadyExists )
       
  1408         {
       
  1409         RemoveTestSet( setName );
       
  1410         }
       
  1411             
       
  1412     return err;
       
  1413     
       
  1414     }       
       
  1415 
       
  1416 /*
       
  1417 -------------------------------------------------------------------------------
       
  1418 
       
  1419     Class: CUIStore
       
  1420 
       
  1421     Method: UpdateTestSet
       
  1422 
       
  1423     Description: Updates (on storage) earlier saved test set.
       
  1424 
       
  1425     Parameters: CTestSetInfo& aSetInfo: in: test set
       
  1426     
       
  1427     Return Values: Symbian OS error code
       
  1428 
       
  1429     Errors/Exceptions: None
       
  1430 
       
  1431     Status: Approved
       
  1432 
       
  1433 -------------------------------------------------------------------------------
       
  1434 */
       
  1435 EXPORT_C TInt CUIStore::UpdateTestSet(CTestSetInfo& aSetInfo)
       
  1436     {
       
  1437     TRAPD(err,
       
  1438           UpdateTestSetL(aSetInfo, aSetInfo.Name());
       
  1439          );
       
  1440          
       
  1441     return err;
       
  1442     }  
       
  1443         
       
  1444 /*
       
  1445 -------------------------------------------------------------------------------
       
  1446 
       
  1447     Class: CUIStore
       
  1448 
       
  1449     Method: StartTestSet
       
  1450 
       
  1451     Description: Start selected test set identified with CTestSetInfo.
       
  1452 
       
  1453     Parameters: const CTestSetInfo& aTestSetInfo: in: Started test set
       
  1454                 TInt& anIndex: out index in StartedTestSet array, 
       
  1455                     which is valid only during execution of calling 
       
  1456                     function.
       
  1457     
       
  1458     Return Values: Symbian OS error code
       
  1459 
       
  1460     Errors/Exceptions: None
       
  1461 
       
  1462     Status: Draft
       
  1463 
       
  1464 -------------------------------------------------------------------------------
       
  1465 */      
       
  1466 EXPORT_C TInt CUIStore::StartTestSet( const CTestSetInfo& aTestSetInfo,
       
  1467                                       TInt& anIndex,
       
  1468                                       CStartedTestSet::TSetType aType )
       
  1469     {
       
  1470     return StartTestSet(aTestSetInfo, anIndex, aType, EFalse);    
       
  1471     }       
       
  1472 
       
  1473 /*
       
  1474 -------------------------------------------------------------------------------
       
  1475 
       
  1476     Class: CUIStore
       
  1477 
       
  1478     Method: StartTestSet
       
  1479 
       
  1480     Description: Start selected test set identified with CTestSetInfo.
       
  1481 
       
  1482     Parameters: const CTestSetInfo& aTestSetInfo: in: Started test set
       
  1483                 TInt& anIndex: out index in StartedTestSet array, 
       
  1484                     which is valid only during execution of calling 
       
  1485                     function.
       
  1486                 TSetType aType: sequential or paraller
       
  1487                 TBool aNotExecutedCasesMode: only test case which haven't been
       
  1488                     executed yet
       
  1489     
       
  1490     Return Values: Symbian OS error code
       
  1491 
       
  1492     Errors/Exceptions: None
       
  1493 
       
  1494     Status: Approved
       
  1495 
       
  1496 -------------------------------------------------------------------------------
       
  1497 */      
       
  1498 EXPORT_C TInt CUIStore::StartTestSet( const CTestSetInfo& aTestSetInfo,
       
  1499                                       TInt& anIndex,
       
  1500                                       CStartedTestSet::TSetType aType,
       
  1501                                       TBool aNotStartedCasesMode )
       
  1502     {
       
  1503     
       
  1504     TInt ret = KErrNone;
       
  1505     
       
  1506     CStartedTestSet* set = NULL;
       
  1507     TRAPD( err, 
       
  1508         set = CStartedTestSet::NewL( this, aTestSetInfo, aType );
       
  1509         );
       
  1510     if( err != KErrNone )
       
  1511         {
       
  1512         return err;
       
  1513         }
       
  1514 
       
  1515     if( iStartedTestSets.Append( set ) != KErrNone )
       
  1516         {
       
  1517         delete set;
       
  1518         return KErrNoMemory;
       
  1519         } 
       
  1520 
       
  1521     // Set mode in which only still not executed test cases will be run.
       
  1522     // It applies only to sequential execution.
       
  1523     set->SetNotStartedCasesMode(aNotStartedCasesMode);
       
  1524     
       
  1525     ret = set->StartNext();
       
  1526         
       
  1527     anIndex = iStartedTestSets.Find( set );
       
  1528     if( anIndex < 0 )
       
  1529         {
       
  1530         User::Panic( KUIStore, KErrNotFound );
       
  1531         }
       
  1532     // Check that testset starting was successful
       
  1533     if( ret != KErrNone )
       
  1534         {
       
  1535         iStartedTestSets.Remove( anIndex );
       
  1536         anIndex = KErrNotFound; // safety
       
  1537         delete set;
       
  1538         return ret;
       
  1539         }
       
  1540     
       
  1541     return KErrNone;
       
  1542     
       
  1543     }       
       
  1544 
       
  1545 /*
       
  1546 -------------------------------------------------------------------------------
       
  1547 
       
  1548     Class: CUIStore
       
  1549 
       
  1550     Method: AbortTestSet
       
  1551 
       
  1552     Description: Abort running test set.
       
  1553 
       
  1554     Parameters: None
       
  1555     
       
  1556     Return Values: Symbian OS error code
       
  1557 
       
  1558     Errors/Exceptions: None
       
  1559 
       
  1560     Status: Draft
       
  1561 
       
  1562 -------------------------------------------------------------------------------
       
  1563 */
       
  1564 EXPORT_C TInt CUIStore::AbortTestSet( CStartedTestSet& aSetInfo )
       
  1565     {
       
  1566         
       
  1567     return aSetInfo.Abort();
       
  1568     
       
  1569     } 
       
  1570 
       
  1571 
       
  1572 /*
       
  1573 -------------------------------------------------------------------------------
       
  1574 
       
  1575     Class: CUIStore
       
  1576 
       
  1577     Method: StartedTestSetL
       
  1578 
       
  1579     Description: Return started (running/runned) test set.
       
  1580 
       
  1581     Parameters: TInt anIndex: out index in StartedTestSet array 
       
  1582                         
       
  1583     Return Values: CStartedTestSet&: reference to test set
       
  1584 
       
  1585     Errors/Exceptions: Leaves on error.
       
  1586 
       
  1587     Status: Draft
       
  1588 
       
  1589 -------------------------------------------------------------------------------
       
  1590 */  
       
  1591 EXPORT_C CStartedTestSet& CUIStore::StartedTestSetL( TInt anIndex)
       
  1592     {
       
  1593     
       
  1594     if( anIndex < 0 ||
       
  1595         anIndex >= iStartedTestSets.Count() )
       
  1596         {
       
  1597         User::Leave( KErrNotFound );
       
  1598         }
       
  1599     
       
  1600     return *iStartedTestSets[ anIndex ];
       
  1601     
       
  1602     }       
       
  1603 
       
  1604 
       
  1605 /*
       
  1606 -------------------------------------------------------------------------------
       
  1607 
       
  1608     Class: CUIStore
       
  1609 
       
  1610     Method: StartedTestSets
       
  1611 
       
  1612     Description: Return started (running/runned) test cases
       
  1613 
       
  1614     Parameters: RRefArray<CStartedTestSet>& aTestCases: out: list of test sets
       
  1615                 TInt aStatus: in: status of queried sets
       
  1616                         
       
  1617     Return Values: Symbian OS error code
       
  1618 
       
  1619     Errors/Exceptions: None
       
  1620 
       
  1621     Status: Draft
       
  1622 
       
  1623 -------------------------------------------------------------------------------
       
  1624 */
       
  1625 EXPORT_C TInt CUIStore::StartedTestSets( RRefArray<CStartedTestSet>& aTestSets,
       
  1626                                          TInt aStatus )
       
  1627     {    
       
  1628     
       
  1629     TInt count = iStartedTestSets.Count();
       
  1630     
       
  1631     for( TInt i = 0; i < count; i++ )
       
  1632         {
       
  1633         if( ( aStatus != CUIStoreIf::ESetAll) &&
       
  1634             !( iStartedTestSets[i]->Status() & aStatus ) )
       
  1635             {
       
  1636             continue;
       
  1637             }
       
  1638         if( aTestSets.Append( *iStartedTestSets[i] ) != KErrNone )
       
  1639             {
       
  1640             return KErrNoMemory;
       
  1641             }
       
  1642         }        
       
  1643         
       
  1644     return KErrNone;
       
  1645     
       
  1646     }           
       
  1647 
       
  1648 /*
       
  1649 -------------------------------------------------------------------------------
       
  1650 
       
  1651     Class: CUIStore
       
  1652 
       
  1653     Method: LoadSavedTestCases
       
  1654 
       
  1655     Description: Load saved testcases.
       
  1656 
       
  1657     Parameters: None
       
  1658     
       
  1659     Return Values: Symbian OS error code
       
  1660 
       
  1661     Errors/Exceptions: None
       
  1662 
       
  1663     Status: Draft
       
  1664 
       
  1665 -------------------------------------------------------------------------------
       
  1666 */
       
  1667 EXPORT_C TInt CUIStore::LoadSavedTestCases()
       
  1668     {
       
  1669     
       
  1670     TRAPD( err,
       
  1671         LoadExecutedTestCasesL();
       
  1672         );
       
  1673     
       
  1674     return err;
       
  1675     
       
  1676     }       
       
  1677 /*
       
  1678 -------------------------------------------------------------------------------
       
  1679 
       
  1680     Class: CUIStore
       
  1681 
       
  1682     Method: GetTestSetsList
       
  1683 
       
  1684     Description: Returns menu item text.
       
  1685 
       
  1686     Parameters: const TInt                :in:      Menu index
       
  1687 
       
  1688     Return Values: const TDesC&                     Menu line text
       
  1689 
       
  1690     Errors/Exceptions: None
       
  1691 
       
  1692     Status: Draft
       
  1693 
       
  1694 -------------------------------------------------------------------------------
       
  1695 */
       
  1696 EXPORT_C TInt CUIStore::GetTestSetsList( RRefArray<TDesC>& aArray )
       
  1697     {
       
  1698     RFs fileReader;
       
  1699     CDir* dirContents = NULL;
       
  1700     _LIT(KSetPattern,".set");
       
  1701     TInt entNum = 0;
       
  1702     TInt ret = 0;
       
  1703     HBufC* fName = NULL;
       
  1704 
       
  1705     
       
  1706     ret = fileReader.Connect();
       
  1707 
       
  1708     if (ret != KErrNone)
       
  1709     	return ret;
       
  1710     
       
  1711     
       
  1712     ret = fileReader.GetDir(KUIStoreDefaultDir,
       
  1713     						KEntryAttNormal | KEntryAttHidden | KEntryAttSystem,
       
  1714     						ESortByName | EDirsFirst | EAscending,
       
  1715     						dirContents);
       
  1716     fileReader.Close();	
       
  1717     if (ret != KErrNone)
       
  1718     	{    		
       
  1719 	    delete dirContents;
       
  1720 	    return ret;
       
  1721 	    }
       
  1722     entNum = dirContents->Count();
       
  1723     for (int i = 0;i<entNum;i++)
       
  1724     	{
       
  1725     	if ((!dirContents->operator[](i).IsDir())&&
       
  1726     		 dirContents->operator[](i).iName.Find(KSetPattern)!=KErrNotFound)
       
  1727     			{
       
  1728     			  TRAPD( err, fName = HBufC::NewL(64) );		       			             
       
  1729     			  if( err != KErrNone )
       
  1730     			    {
       
  1731     			      delete dirContents;
       
  1732     			      return err;
       
  1733     			    }    		 	
       
  1734     		    *fName =  dirContents->operator[](i).iName;
       
  1735     		 	ret = iFileList.Append(fName);
       
  1736     		 	if (ret != KErrNone)
       
  1737     		 		{
       
  1738     					delete fName;
       
  1739     					delete dirContents;
       
  1740     					return ret;	
       
  1741     		 		}
       
  1742     		 	ret = aArray.Append(*fName);
       
  1743 			 	if (ret != KErrNone)
       
  1744     		 		{
       
  1745     					delete fName;
       
  1746     					delete dirContents;
       
  1747     					return ret;	
       
  1748     		 		}
       
  1749 
       
  1750     			}    
       
  1751     	}
       
  1752     delete dirContents;
       
  1753     return KErrNone; 
       
  1754 
       
  1755     }
       
  1756 
       
  1757 
       
  1758 /*
       
  1759 -------------------------------------------------------------------------------
       
  1760 
       
  1761     Class: CUIStore
       
  1762 
       
  1763     Method: FindSetByName
       
  1764 
       
  1765     Description: Finds test set by name.
       
  1766 
       
  1767     Parameters: const TDesC& aSetName: in: set name 
       
  1768                 CTestSetInfo*& aSetInfo: out: pointer to test set
       
  1769                         
       
  1770     Return Values: Symbian OS error code
       
  1771 
       
  1772     Errors/Exceptions: None
       
  1773 
       
  1774     Status: Draft
       
  1775 
       
  1776 -------------------------------------------------------------------------------
       
  1777 */
       
  1778 TInt CUIStore::FindSetByName( const TDesC& aSetName, 
       
  1779                               CTestSetInfo*& aSetInfo )
       
  1780     {
       
  1781     
       
  1782     TInt count = iTestSets.Count();
       
  1783     for( TInt i=0; i<count; i++ )
       
  1784         {
       
  1785         if( iTestSets[i]->Name() == aSetName )
       
  1786             {
       
  1787             aSetInfo = iTestSets[i];
       
  1788             return KErrNone;
       
  1789             }
       
  1790         }
       
  1791     
       
  1792     return KErrNotFound;
       
  1793     
       
  1794     }
       
  1795     
       
  1796 /*
       
  1797 -------------------------------------------------------------------------------
       
  1798 
       
  1799     Class: CUIStore
       
  1800 
       
  1801     Method: FindSetByCase
       
  1802 
       
  1803     Description: Finds test set by name.
       
  1804 
       
  1805     Parameters:  const CStartedTestCase* aTestCase: in: running test case 
       
  1806                  CStartedTestSet*& aSet: out: set running test case
       
  1807                         
       
  1808     Return Values: KErrNotFound: test case is not runned by any test set
       
  1809                    KErrNone: test case was runned by aSet
       
  1810                    
       
  1811 
       
  1812     Errors/Exceptions: None
       
  1813 
       
  1814     Status: Draft
       
  1815 
       
  1816 -------------------------------------------------------------------------------
       
  1817 */
       
  1818 TInt CUIStore::FindStartedSetByCase( const CStartedTestCase* aTestCase, 
       
  1819                                      CStartedTestSet*& aSet  )
       
  1820     {
       
  1821     
       
  1822     TInt count = iStartedTestSets.Count();
       
  1823     for( TInt i=0; i<count; i++ )
       
  1824         {
       
  1825         if( iStartedTestSets[i]->IsRunning( aTestCase ) )
       
  1826             {
       
  1827             aSet = iStartedTestSets[i];
       
  1828             return KErrNone;
       
  1829             }
       
  1830         }
       
  1831     
       
  1832     return KErrNotFound;
       
  1833     
       
  1834     }
       
  1835 
       
  1836 /*
       
  1837 -------------------------------------------------------------------------------
       
  1838 
       
  1839     Class: CUIStore
       
  1840 
       
  1841     Method: LoadTestSetL
       
  1842 
       
  1843     Description: Load test set.
       
  1844 
       
  1845     Parameters: TDesC& aSetName: out: test set name
       
  1846     
       
  1847     Return Values: Symbian OS error code
       
  1848 
       
  1849     Errors/Exceptions: None
       
  1850 
       
  1851     Status: Draft
       
  1852 
       
  1853 -------------------------------------------------------------------------------
       
  1854 */
       
  1855 void CUIStore::LoadTestSetL( const TDesC& aSetName, const TDesC& aSetFileName )
       
  1856     {
       
  1857     
       
  1858     TPtrC tmp;
       
  1859     TInt num;
       
  1860     TInt high;
       
  1861     TInt64 interval;
       
  1862     
       
  1863     CStifParser* parser = NULL;
       
  1864     
       
  1865     TRAPD( err,
       
  1866         parser = CStifParser::NewL( _L(""), aSetFileName );
       
  1867         );
       
  1868     if( err != KErrNone )
       
  1869         {
       
  1870         parser = CStifParser::NewL( KUIStoreDefaultDir, aSetName );
       
  1871         }
       
  1872         
       
  1873     CleanupStack::PushL( parser );
       
  1874     
       
  1875     CStifSectionParser* section = 
       
  1876         parser->SectionL( KUIStoreSetStart, KUIStoreSetEnd );
       
  1877     CleanupStack::PushL( section );
       
  1878     
       
  1879     CStifItemParser* item = section->GetItemLineL( KUIStoreSetName );
       
  1880     CleanupStack::PushL( item );
       
  1881     
       
  1882     User::LeaveIfError( item->GetString( KUIStoreSetName, tmp ) );
       
  1883     
       
  1884 	// get the standard method
       
  1885 	TCollationMethod method = *Mem::CollationMethodByIndex(0);
       
  1886 	// ignore case
       
  1887     method.iFlags |= TCollationMethod::EFoldCase;
       
  1888     
       
  1889 	TInt compare = aSetName.CompareC( tmp, 3, &method );
       
  1890 	if( compare != KErrNone )
       
  1891         {
       
  1892         User::LeaveIfError( KErrNotFound );
       
  1893         }
       
  1894         
       
  1895     CleanupStack::PopAndDestroy( item );
       
  1896         
       
  1897     // Get started test case (if possible)
       
  1898     TUint lastStartedCaseIndex = 0;
       
  1899     item = section->GetItemLineL(KUIStoreLastStartedCaseIndex);
       
  1900     if(item)
       
  1901         {
       
  1902         CleanupStack::PushL(item);
       
  1903         TInt r = item->GetInt(KUIStoreLastStartedCaseIndex, lastStartedCaseIndex);
       
  1904         CleanupStack::PopAndDestroy(item);
       
  1905         if(r != KErrNone)
       
  1906             {
       
  1907             __TRACE(KInit, (_L("Could not read [%S] from test set file. Result [%d]."), &KUIStoreLastStartedCaseIndex, r));
       
  1908             }
       
  1909         }
       
  1910     else
       
  1911         {
       
  1912         __TRACE(KInit, (_L("Could not find [%S] from test set file."), &KUIStoreLastStartedCaseIndex));
       
  1913         }
       
  1914 
       
  1915     User::LeaveIfError( CreateTestSet( aSetName ) );
       
  1916     
       
  1917     CTestSetInfo* setInfo = NULL;
       
  1918     User::LeaveIfError( FindSetByName( aSetName, setInfo ) );
       
  1919     
       
  1920     // Update started case
       
  1921     setInfo->SetLastStartedCaseIndex(lastStartedCaseIndex);
       
  1922     
       
  1923     CTestInfo* testInfo = CTestInfo::NewL();
       
  1924     CleanupStack::PushL( testInfo );    
       
  1925 
       
  1926     CStifSectionParser* subSection = 
       
  1927         section->SubSectionL( KUIStoreSetCaseStart, KUIStoreSetCaseEnd );
       
  1928     
       
  1929     while( subSection )
       
  1930         {
       
  1931         CleanupStack::PushL( subSection );    
       
  1932         
       
  1933         // Get module name
       
  1934         // Mandatory, leave if not found
       
  1935         User::LeaveIfError( 
       
  1936             subSection->GetLine( KUIStoreCaseModuleName, tmp, ENoTag ) );
       
  1937         testInfo->SetModuleName( tmp );
       
  1938     
       
  1939         // Get test case title
       
  1940         // Mandatory, leave if not found
       
  1941         User::LeaveIfError( 
       
  1942             subSection->GetLine( KUIStoreTestCaseTitle, tmp, ENoTag ) );
       
  1943         testInfo->SetTestCaseTitle( tmp );
       
  1944         
       
  1945         // Get test case file
       
  1946         num = subSection->GetLine( KUIStoreTestCaseFile, tmp, ENoTag );
       
  1947         if( ( num == KErrNone ) &&
       
  1948             ( tmp.Length() > 0 ) )
       
  1949             {
       
  1950             // Optional
       
  1951             testInfo->SetTestCaseFile( tmp );
       
  1952             }
       
  1953         
       
  1954         // Get test case number
       
  1955         item = subSection->GetItemLineL( KUIStoreTestCaseNum );
       
  1956         CleanupStack::PushL( item );
       
  1957         // Mandatory, leave if not found
       
  1958         User::LeaveIfError( item->GetInt( KUIStoreTestCaseNum, num ));
       
  1959         testInfo->SetTestCaseNumber( num );
       
  1960         CleanupStack::PopAndDestroy( item );    
       
  1961         
       
  1962         // Get test case priority
       
  1963         item = subSection->GetItemLineL( KUIStoreCasePriority );
       
  1964         CleanupStack::PushL( item );
       
  1965         // Mandatory, leave if not found
       
  1966         User::LeaveIfError( item->GetInt( KUIStoreCasePriority, num ));
       
  1967         testInfo->SetPriority( num );
       
  1968         CleanupStack::PopAndDestroy( item ); 
       
  1969         
       
  1970         // Get test case timeout
       
  1971         item = subSection->GetItemLineL( KUIStoreCaseTimeout );
       
  1972         CleanupStack::PushL( item );
       
  1973         // Mandatory, leave if not found
       
  1974         User::LeaveIfError( item->GetInt( KUIStoreCaseTimeout, num ));
       
  1975         User::LeaveIfError( item->GetNextInt( high ));
       
  1976         //@js<--remove--> interval.Set( high, num );
       
  1977         interval = MAKE_TINT64( high, num );
       
  1978         TTimeIntervalMicroSeconds timeout( interval );
       
  1979         testInfo->SetTimeout( timeout );
       
  1980         CleanupStack::PopAndDestroy( item ); 
       
  1981         
       
  1982         User::LeaveIfError( setInfo->AddTestCase( *testInfo ) );
       
  1983         
       
  1984         CleanupStack::PopAndDestroy( subSection );    
       
  1985         subSection = 
       
  1986             section->NextSubSectionL( KUIStoreSetCaseStart, KUIStoreSetCaseEnd );
       
  1987         } 
       
  1988         
       
  1989     CleanupStack::PopAndDestroy( testInfo );    
       
  1990     CleanupStack::PopAndDestroy( section );
       
  1991     CleanupStack::PopAndDestroy( parser );
       
  1992     
       
  1993     const RRefArray<const CTestInfo>& testCases = setInfo->TestCases();
       
  1994     LoadTestModulesAndTestCaseFilesL( testCases );
       
  1995      
       
  1996     }     
       
  1997     
       
  1998 /*
       
  1999 -------------------------------------------------------------------------------
       
  2000 
       
  2001     Class: CUIStore
       
  2002 
       
  2003     Method: SaveTestSetL
       
  2004 
       
  2005     Description: Save test set.
       
  2006 
       
  2007     Parameters: CTestSetInfo& aSetInfo: in: test set
       
  2008     
       
  2009     Return Values: Symbian OS error code
       
  2010 
       
  2011     Errors/Exceptions: None
       
  2012 
       
  2013     Status: Approved
       
  2014 
       
  2015 -------------------------------------------------------------------------------
       
  2016 */
       
  2017 void CUIStore::SaveTestSetL( CTestSetInfo& aSetInfo, const TDesC& aSetFileName )
       
  2018     {
       
  2019     //Extract path
       
  2020     TParse p;
       
  2021     p.Set(aSetFileName, NULL, NULL);
       
  2022     TPtrC path =  p.DriveAndPath(); // gives path for test set
       
  2023     TPtrC fn = p.NameAndExt(); // gives filename with extension
       
  2024     if(path.Length() == 0)
       
  2025         {
       
  2026         path.Set(KUIStoreDefaultDir);
       
  2027         }
       
  2028 
       
  2029     //Create file server
       
  2030     RFs fs;
       
  2031     User::LeaveIfError(fs.Connect());
       
  2032     CleanupClosePushL(fs);
       
  2033 
       
  2034     //Create or open file
       
  2035     RFile file;
       
  2036     TFileName filename = path;
       
  2037     filename.Append(fn);
       
  2038     
       
  2039     TInt r = file.Replace(fs, filename, EFileWrite);
       
  2040     if(r != KErrNone)
       
  2041         {
       
  2042         User::Leave(r);
       
  2043         }
       
  2044     else
       
  2045         {
       
  2046         CleanupClosePushL(file);
       
  2047         
       
  2048         RBuf buffer;
       
  2049         buffer.Create(256);
       
  2050         CleanupClosePushL(buffer);
       
  2051         
       
  2052         // Saving
       
  2053         buffer.Format(_L("%S"), &KUIStoreSetStart);
       
  2054         WriteLineL(file, buffer);
       
  2055         buffer.Format(_L("%S %S"), &KUIStoreSetName,&aSetFileName);
       
  2056         WriteLineL(file, buffer);
       
  2057 
       
  2058         // Saving test set causes reset of index
       
  2059         aSetInfo.SetLastStartedCaseIndex(0);
       
  2060         buffer.Format(_L("%S "), &KUIStoreLastStartedCaseIndex);
       
  2061         buffer.AppendNumFixedWidth(aSetInfo.GetLastStartedCaseIndex(), EDecimal, KFixedStartedCaseIndex);
       
  2062         WriteLineL(file, buffer);
       
  2063 
       
  2064         // Saving test cases
       
  2065         TInt count = aSetInfo.TestCases().Count();
       
  2066         for(TInt i = 0; i < count; i++)
       
  2067             {
       
  2068             WriteLineL(file, KNullDesC);
       
  2069             buffer.Format(_L("%S"), &KUIStoreSetCaseStart);
       
  2070             WriteLineL(file, buffer);
       
  2071             
       
  2072             buffer.Format(_L("%S %S"), &KUIStoreCaseModuleName, &aSetInfo.TestCases()[i].ModuleName());
       
  2073             WriteLineL(file, buffer);
       
  2074             buffer.Format(_L("%S %S"), &KUIStoreTestCaseTitle, &aSetInfo.TestCases()[i].TestCaseTitle());
       
  2075             WriteLineL(file, buffer);
       
  2076             if(aSetInfo.TestCases()[i].TestCaseFile().Length() > 0)
       
  2077                 {
       
  2078                 buffer.Format(_L("%S %S"), &KUIStoreTestCaseFile, &aSetInfo.TestCases()[i].TestCaseFile());
       
  2079             WriteLineL(file, buffer);
       
  2080                 }
       
  2081             buffer.Format(_L("%S %d"), &KUIStoreTestCaseNum, aSetInfo.TestCases()[i].TestCaseNum());
       
  2082             WriteLineL(file, buffer);
       
  2083             buffer.Format(_L("%S %d"), &KUIStoreCasePriority, aSetInfo.TestCases()[i].Priority());
       
  2084             WriteLineL(file, buffer);
       
  2085             buffer.Format(_L("%S %d %d"), &KUIStoreCaseTimeout, I64LOW(aSetInfo.TestCases()[i].Timeout().Int64()), 
       
  2086                                                                 I64HIGH(aSetInfo.TestCases()[i].Timeout().Int64()));
       
  2087             WriteLineL(file, buffer);
       
  2088             buffer.Format(_L("%S %d"), &KUIStoreCaseExpectedResult, aSetInfo.TestCases()[i].ExpectedResult());
       
  2089             WriteLineL(file, buffer);
       
  2090             buffer.Format(_L("%S"), &KUIStoreSetCaseEnd);    
       
  2091             WriteLineL(file, buffer);
       
  2092             }
       
  2093 
       
  2094         WriteLineL(file, KNullDesC);
       
  2095         buffer.Format(_L("%S"), &KUIStoreSetEnd);
       
  2096         WriteLineL(file, buffer);
       
  2097 
       
  2098         CleanupStack::PopAndDestroy(&buffer);
       
  2099         CleanupStack::PopAndDestroy(&file);
       
  2100         }
       
  2101     CleanupStack::PopAndDestroy(&fs);        
       
  2102     }           
       
  2103 
       
  2104 /*
       
  2105 -------------------------------------------------------------------------------
       
  2106 
       
  2107     Class: CUIStore
       
  2108 
       
  2109     Method: UpdateTestSetL
       
  2110 
       
  2111     Description: Updates information in test set file.
       
  2112 
       
  2113     Parameters: CTestSetInfo& aSetInfo: in: test set
       
  2114     
       
  2115     Return Values: Symbian OS error code
       
  2116 
       
  2117     Errors/Exceptions: Leaves when writing to file fails
       
  2118                        Leaves when file.seek fails
       
  2119                        Leaves when can't connect to file server
       
  2120 
       
  2121     Status: Approved
       
  2122 
       
  2123 -------------------------------------------------------------------------------
       
  2124 */
       
  2125 void CUIStore::UpdateTestSetL(CTestSetInfo& aSetInfo, const TDesC& aSetFileName)
       
  2126     {
       
  2127     // Get path
       
  2128     TParse p;
       
  2129     p.Set(aSetFileName, NULL, NULL);
       
  2130     TPtrC path = p.DriveAndPath(); // gives path for test set
       
  2131     TPtrC fn = p.NameAndExt(); // gives filename with extension
       
  2132     if(path.Length() == 0)
       
  2133         {
       
  2134         path.Set(KUIStoreDefaultDir);
       
  2135         }
       
  2136 
       
  2137     //Create file server
       
  2138     RFs fs;
       
  2139     User::LeaveIfError(fs.Connect());
       
  2140     CleanupClosePushL(fs);
       
  2141 
       
  2142     //Create or open file
       
  2143     RFile file;
       
  2144     TFileName filename = path;
       
  2145     filename.Append(fn);
       
  2146     TInt foundpos = KErrNotFound;
       
  2147     
       
  2148     TInt r = file.Open(fs, filename, EFileWrite);
       
  2149     if(r != KErrNone)
       
  2150         {
       
  2151         User::Leave(r);
       
  2152         }
       
  2153     else
       
  2154         {
       
  2155         CleanupClosePushL(file);
       
  2156 
       
  2157         //Search for line
       
  2158         RBuf buffer;
       
  2159         buffer.Create(256);
       
  2160         CleanupClosePushL(buffer);
       
  2161 
       
  2162         //Prepare file
       
  2163         TInt pos = 0;
       
  2164         User::LeaveIfError(file.Seek(ESeekStart, pos));
       
  2165         
       
  2166         //Read file
       
  2167         ReadLineL(file, buffer);
       
  2168         while(buffer.Length() > 0)
       
  2169             {
       
  2170             // Keep remembering current position
       
  2171             if(buffer.Find(KUIStoreLastStartedCaseIndex) == 0)
       
  2172                 {
       
  2173                 foundpos = pos;
       
  2174                 break;
       
  2175                 }
       
  2176             // What is current position
       
  2177             pos = 0;
       
  2178             User::LeaveIfError(file.Seek(ESeekCurrent, pos));
       
  2179             // Read next line from file
       
  2180             ReadLineL(file, buffer);
       
  2181             }
       
  2182 
       
  2183         if(foundpos != KErrNotFound)
       
  2184             {
       
  2185             // Position was found. Just update that line (save index of last 
       
  2186             // started test case)
       
  2187             RBuf8 b;
       
  2188             b.Create(40);
       
  2189             CleanupClosePushL(b);
       
  2190 
       
  2191             b.Copy(KUIStoreLastStartedCaseIndex);
       
  2192             b.Append(_L8(" "));
       
  2193             b.AppendNumFixedWidth(aSetInfo.GetLastStartedCaseIndex(), EDecimal, KFixedStartedCaseIndex);
       
  2194             User::LeaveIfError(file.Seek(ESeekStart, foundpos));
       
  2195             User::LeaveIfError(file.Write(b));
       
  2196             CleanupStack::PopAndDestroy(&b);
       
  2197             }
       
  2198 
       
  2199         CleanupStack::PopAndDestroy(&buffer);
       
  2200         CleanupStack::PopAndDestroy(&file);
       
  2201         }
       
  2202     CleanupStack::PopAndDestroy(&fs);        
       
  2203     
       
  2204     if(foundpos == KErrNotFound)
       
  2205         {
       
  2206         // Position of KUIStoreLastStartedCaseIndex could not be found.
       
  2207         // Store the whole file.
       
  2208         SaveTestSetL(aSetInfo, aSetFileName);
       
  2209         }
       
  2210     }
       
  2211 
       
  2212 /*
       
  2213 -------------------------------------------------------------------------------
       
  2214 
       
  2215     Class: CUIStore
       
  2216 
       
  2217     Method: ReadLineL
       
  2218 
       
  2219     Description: Read the whole line from the file. If there is enough space,
       
  2220                  the whole content of line will be returned in buffer.
       
  2221 
       
  2222     Parameters: RFile& file: in: file to be read
       
  2223                 TDes8& buffer: out: buffer to be returned
       
  2224     
       
  2225     Return Values: None
       
  2226 
       
  2227     Errors/Exceptions: Leaves if RFile::Read method fails
       
  2228 
       
  2229     Status: Approved
       
  2230 
       
  2231 -------------------------------------------------------------------------------
       
  2232 */
       
  2233 void CUIStore::ReadLineL(RFile &file, TDes& buffer)
       
  2234     {
       
  2235     TBuf8<1> c;
       
  2236     TBuf<1> c16;
       
  2237     buffer.Copy(KNullDesC);
       
  2238     
       
  2239     User::LeaveIfError(file.Read(c));
       
  2240     while(c.Length() > 0)
       
  2241         {
       
  2242         // There is still place to write to the dest buffer
       
  2243         if(buffer.Length() < buffer.MaxLength())
       
  2244             {
       
  2245             c16.Copy(c);
       
  2246             buffer.Append(c16);
       
  2247             }
       
  2248         // Stop reading if end of line
       
  2249         if(c[0] == 0x0A)
       
  2250             {
       
  2251             break;
       
  2252             }
       
  2253         User::LeaveIfError(file.Read(c));
       
  2254         }
       
  2255     }
       
  2256 
       
  2257 /*
       
  2258 -------------------------------------------------------------------------------
       
  2259 
       
  2260     Class: CUIStore
       
  2261 
       
  2262     Method: WriteLineL
       
  2263 
       
  2264     Description: Write given line to the file and adds end of line.
       
  2265 
       
  2266     Parameters: RFile& file: in: file to be written
       
  2267                 TDesC& buffer: in: buffer to be written
       
  2268     
       
  2269     Return Values: None
       
  2270 
       
  2271     Errors/Exceptions: Leaves if RFile::Write method fails
       
  2272 
       
  2273     Status: Approved
       
  2274 
       
  2275 -------------------------------------------------------------------------------
       
  2276 */
       
  2277 void CUIStore::WriteLineL(RFile &file, const TDesC& buffer)
       
  2278     {
       
  2279     if(buffer.Length() > 0)
       
  2280         {
       
  2281         // Create 8-bit buffer
       
  2282         RBuf8 buf;
       
  2283         buf.Create(buffer.Length());
       
  2284         CleanupClosePushL(buf);
       
  2285     
       
  2286         buf.Copy(buffer);
       
  2287     
       
  2288         // Write buffer to file + end of line
       
  2289         User::LeaveIfError(file.Write(buf));
       
  2290 
       
  2291         // Delete 8-bit buffer
       
  2292         CleanupStack::PopAndDestroy(&buf);
       
  2293         }
       
  2294 
       
  2295     // Write end of line
       
  2296     TBuf8<2> eoline;
       
  2297     eoline.Copy(_L("\r\n"));
       
  2298     User::LeaveIfError(file.Write(eoline));
       
  2299     }
       
  2300 
       
  2301 /*
       
  2302 -------------------------------------------------------------------------------
       
  2303 
       
  2304     Class: CUIStore
       
  2305 
       
  2306     Method: LoadTestModulesL
       
  2307 
       
  2308     Description: Load test modules. 
       
  2309 
       
  2310     Parameters: CTestSetInfo& aSetInfo: in: test set
       
  2311     
       
  2312     Return Values: Symbian OS error code
       
  2313 
       
  2314     Errors/Exceptions: None
       
  2315 
       
  2316     Status: Draft
       
  2317 
       
  2318 -------------------------------------------------------------------------------
       
  2319 */
       
  2320 void CUIStore::LoadTestModulesAndTestCaseFilesL( 
       
  2321     const RRefArray<const CTestInfo>& aTestCases )
       
  2322     {
       
  2323     
       
  2324     RRefArray<TDesC> testCaseFiles;
       
  2325     RRefArray<TDesC> testModules;
       
  2326     CleanupClosePushL( testCaseFiles );
       
  2327     CleanupClosePushL( testModules );
       
  2328     
       
  2329     User::LeaveIfError( Modules( testModules ) );
       
  2330     
       
  2331     TInt cCount = aTestCases.Count();
       
  2332     TInt mCount = 0;
       
  2333     TInt mInd=0;
       
  2334     TInt fCount = 0;
       
  2335     TInt fInd=0;
       
  2336     for( TInt cInd=0; cInd<cCount; cInd++ )
       
  2337         {
       
  2338         mCount = testModules.Count();
       
  2339         for( mInd=0; mInd<mCount; mInd++ )
       
  2340             {
       
  2341             if( aTestCases[cInd].ModuleName() == testModules[mInd] )
       
  2342                 {
       
  2343                 // Test module already loaded
       
  2344                 break;
       
  2345                 }
       
  2346             }
       
  2347         if( mInd == mCount )
       
  2348             {
       
  2349             // Not found, load test module
       
  2350             if( AddTestModule( aTestCases[cInd].ModuleName() ) == KErrNone )
       
  2351                 {
       
  2352                 User::LeaveIfError( 
       
  2353                     testModules.Append( aTestCases[cInd].ModuleName() ) );
       
  2354                 }
       
  2355             }                
       
  2356         if( aTestCases[cInd].TestCaseFile().Length() == 0 )
       
  2357             {
       
  2358             // Test case file is not used, continue
       
  2359             continue;
       
  2360             }    
       
  2361         testCaseFiles.Reset();
       
  2362         User::LeaveIfError( 
       
  2363             TestCaseFiles( testCaseFiles, aTestCases[cInd].ModuleName() ));
       
  2364         fCount = testCaseFiles.Count();
       
  2365         for( fInd=0; fInd<fCount; fInd++ )
       
  2366             {
       
  2367             if( aTestCases[cInd].TestCaseFile() == testCaseFiles[fInd] )
       
  2368                 {
       
  2369                 // Testcasefile already loaded
       
  2370                 break;
       
  2371                 }
       
  2372             }  
       
  2373         if( fInd == fCount )
       
  2374             {  
       
  2375             // Load test module
       
  2376             if( AddTestCaseFile( aTestCases[cInd].ModuleName(),
       
  2377                                  aTestCases[cInd].TestCaseFile() ) == KErrNone )
       
  2378                 {
       
  2379                 User::LeaveIfError( 
       
  2380                     testCaseFiles.Append( aTestCases[cInd].TestCaseFile() ) );
       
  2381                 }
       
  2382             }
       
  2383         }   
       
  2384 
       
  2385     CleanupStack::PopAndDestroy(); // testModules
       
  2386     CleanupStack::PopAndDestroy(); // testCaseFiles
       
  2387         
       
  2388     }
       
  2389                                
       
  2390 /*
       
  2391 -------------------------------------------------------------------------------
       
  2392 
       
  2393     Class: CUIStore
       
  2394 
       
  2395     Method: TestExecuted
       
  2396 
       
  2397     Description: Test case executed callback from UI engine.
       
  2398     
       
  2399     Parameters:  CUIEngineContainer* const aContainer: in: Execution container
       
  2400                  TFullTestResult& aFullTestResult: in: test result
       
  2401     
       
  2402     Return Values: None
       
  2403     
       
  2404     Errors/Exceptions: None
       
  2405 
       
  2406     Status: Draft
       
  2407 
       
  2408 -------------------------------------------------------------------------------
       
  2409 */    
       
  2410 void CUIStore::TestExecuted ( CUIEngineContainer* aContainer,
       
  2411                               TFullTestResult& aFullTestResult )
       
  2412     {
       
  2413     
       
  2414     CStartedTestCase* testCase = NULL;
       
  2415     
       
  2416     if( FindByContainer( aContainer, testCase ) != KErrNone )
       
  2417         {
       
  2418         __TRACE( KError, ( CStifLogger::EError, _L("CUIStore::TestExecuted: Not found")));
       
  2419         return;
       
  2420         }
       
  2421     CStartedTestSet* set = NULL;
       
  2422     TInt setStatus = 0;
       
  2423     if( FindStartedSetByCase( testCase, set ) == KErrNone )
       
  2424         {
       
  2425         setStatus = set->Status();
       
  2426         set->TestCompleted( testCase, aFullTestResult );        
       
  2427         setStatus |= set->Status();
       
  2428         }
       
  2429         
       
  2430     // Check and delete all pending popup windows for test case
       
  2431     TInt count = iPopups.Count();
       
  2432     for( TInt i = 0; i<count; i++ )
       
  2433         {
       
  2434         if( iPopups[i]->Container() == aContainer )
       
  2435             {
       
  2436             delete iPopups[i];
       
  2437             iPopups.Remove( i );
       
  2438             }
       
  2439         }
       
  2440         
       
  2441     // Get old status 
       
  2442     TInt status = testCase->Status();
       
  2443     // Set result
       
  2444     testCase->SetResult( aFullTestResult );
       
  2445     // Get new status 
       
  2446     status |= testCase->Status();
       
  2447     // Add set status flags
       
  2448     status |= setStatus;
       
  2449     
       
  2450     iUIStoreIf->Update( testCase, status ); 
       
  2451     
       
  2452     return;
       
  2453     
       
  2454     }
       
  2455 
       
  2456 /*
       
  2457 -------------------------------------------------------------------------------
       
  2458 
       
  2459     Class: CUIStore
       
  2460 
       
  2461     Method: PrintProg
       
  2462 
       
  2463     Description: Progress information from test case execution, 
       
  2464             callback from UI engine.
       
  2465     
       
  2466     Parameters:  CUIEngineContainer* const aContainer: in: Execution container
       
  2467                  TTestProgress& aProgress: in: print info
       
  2468     
       
  2469     Return Values: Symbian OS error code
       
  2470 
       
  2471     
       
  2472     Errors/Exceptions: None
       
  2473 
       
  2474     Status: Draft
       
  2475 
       
  2476 -------------------------------------------------------------------------------
       
  2477 */ 
       
  2478 TInt CUIStore::PrintProg ( CUIEngineContainer* aContainer,
       
  2479                            TTestProgress& aProgress )
       
  2480     {
       
  2481     if( aContainer == NULL )
       
  2482         {
       
  2483         return KErrArgument;
       
  2484         }
       
  2485     if( ( aProgress.iDescription.Length() == 0 ) &&
       
  2486         ( aProgress.iText.Length() == 0 ) )
       
  2487     
       
  2488         {
       
  2489         return KErrArgument;
       
  2490         }
       
  2491         
       
  2492     CStartedTestCase* testCase = NULL;
       
  2493     
       
  2494     if( FindByContainer( aContainer, testCase ) != KErrNone )
       
  2495         {
       
  2496         __TRACE( KError, ( CStifLogger::EError, _L("CUIStore::TestExecuted: Not found")));
       
  2497         return KErrNotFound;
       
  2498         }
       
  2499 
       
  2500     TInt position = KErrNotFound;
       
  2501     TInt smallPos = KErrNotFound;
       
  2502 
       
  2503     // Search the array to find the position
       
  2504     const TInt count = testCase->PrintArray().Count();
       
  2505     for (TInt i = 0; i < count; i++)
       
  2506         {
       
  2507 
       
  2508         // Check if that item is already on list
       
  2509         if ( testCase->PrintArray()[i]->iDescription == aProgress.iDescription &&
       
  2510              testCase->PrintArray()[i]->iPosition    == aProgress.iPosition )
       
  2511             {
       
  2512             // Set it to be updated
       
  2513             position = i;
       
  2514             break;
       
  2515             }
       
  2516 
       
  2517         // Found a smaller priority item from list
       
  2518         if ( aProgress.iPosition <  testCase->PrintArray()[i]->iPosition )
       
  2519             {              
       
  2520             smallPos = i;
       
  2521             break;
       
  2522             }
       
  2523         }
       
  2524 
       
  2525     // Either update item in array or add new item to array
       
  2526     if ( position != KErrNotFound )
       
  2527         {
       
  2528         // Replace existing text
       
  2529         testCase->PrintArray()[position]->ReplaceTextL( aProgress );
       
  2530         }
       
  2531     else 
       
  2532         {
       
  2533         CTestProgress* prog = NULL;
       
  2534         TRAPD( err,
       
  2535             // Allocate new
       
  2536             prog = CTestProgress::NewL( aProgress );
       
  2537             );
       
  2538         if( err != KErrNone )
       
  2539             {
       
  2540             return err;
       
  2541             }
       
  2542         if ( smallPos != KErrNotFound )
       
  2543             {
       
  2544             if( testCase->PrintArray().Insert( prog, smallPos ) != KErrNone )
       
  2545                 {
       
  2546                 delete prog;
       
  2547                 return KErrNoMemory;
       
  2548                 }
       
  2549             }
       
  2550         else 
       
  2551             {
       
  2552             if( testCase->PrintArray().Append( prog ) != KErrNone )
       
  2553                 {
       
  2554                 delete prog;
       
  2555                 return KErrNoMemory;
       
  2556                 }
       
  2557             }
       
  2558         }
       
  2559         
       
  2560     iUIStoreIf->Update( testCase, CUIStoreIf::EPrintUpdate ); 
       
  2561     
       
  2562     return KErrNone;
       
  2563     
       
  2564     }
       
  2565 
       
  2566 /*
       
  2567 -------------------------------------------------------------------------------
       
  2568 
       
  2569     Class: CUIStore
       
  2570 
       
  2571     Method: PrintProg
       
  2572 
       
  2573     Description: Error information from Test framework, 
       
  2574             callback from UI engine.
       
  2575     
       
  2576     Parameters:  CUIEngineContainer* const aContainer: in: Execution container
       
  2577                  TErrorNotification& aError: in: error info
       
  2578     
       
  2579     Return Values: Symbian OS error code
       
  2580     
       
  2581     Errors/Exceptions: None
       
  2582 
       
  2583     Status: Draft
       
  2584 
       
  2585 -------------------------------------------------------------------------------
       
  2586 */    
       
  2587 TInt CUIStore::ErrorPrint( TErrorNotification& aError )
       
  2588     {
       
  2589 
       
  2590     if( aError.iText.Length() == 0 )
       
  2591         {
       
  2592         return KErrArgument;
       
  2593         }
       
  2594     
       
  2595     iUIStoreIf->Error( aError );
       
  2596         
       
  2597     return KErrNone;
       
  2598     
       
  2599     }
       
  2600 
       
  2601 /*
       
  2602 -------------------------------------------------------------------------------
       
  2603 
       
  2604     Class: CUIStore
       
  2605 
       
  2606     Method: RemoteMsg
       
  2607 
       
  2608     Description: Remote protocol control messages handling.
       
  2609 
       
  2610     Parameters: const TDesC& aMessage: in: Remote message
       
  2611 
       
  2612     Return Values: None
       
  2613 
       
  2614     Errors/Exceptions: None
       
  2615 
       
  2616     Status: Draft
       
  2617 
       
  2618 -------------------------------------------------------------------------------
       
  2619 */
       
  2620 TInt CUIStore::RemoteMsg( CUIEngineContainer* aContainer,
       
  2621                           const TDesC& aMessage)
       
  2622     {
       
  2623 
       
  2624     if( ( aMessage.Length() == 0 ) ||
       
  2625         ( aContainer == NULL ) )
       
  2626         {
       
  2627         return KErrArgument;
       
  2628         }
       
  2629     
       
  2630     TInt ret = KErrNone;
       
  2631 
       
  2632     TInt error = KErrNone;
       
  2633     CStifTFwIfProt* msg = NULL;
       
  2634     CStifTFwIfProt* resp = NULL;
       
  2635     TRAPD( err, msg = CStifTFwIfProt::NewL(); );
       
  2636     if( err != KErrNone )
       
  2637         {
       
  2638         return err;
       
  2639         }
       
  2640     TRAP( err, resp = CStifTFwIfProt::NewL(); );
       
  2641     if( err != KErrNone )
       
  2642         {
       
  2643         delete msg;
       
  2644         return err;
       
  2645         }
       
  2646     
       
  2647     // Parse received message
       
  2648     TRAP( err, 
       
  2649         error = msg->SetL( aMessage ) 
       
  2650     );
       
  2651     if( err != KErrNone )
       
  2652         {
       
  2653         __TRACE( KError, ( _L( "CUIStore::RemoteMsg: message header parsing failed [%d]"), err ) );
       
  2654         delete msg;
       
  2655         delete resp;
       
  2656         return err;
       
  2657         }
       
  2658 
       
  2659     // Create response 
       
  2660     TRAP( err, resp->CreateL(); );
       
  2661     if( err != KErrNone )
       
  2662         {
       
  2663         delete msg;
       
  2664         delete resp;
       
  2665         return err;
       
  2666         }                
       
  2667 
       
  2668     resp->Append( CStifTFwIfProt::MsgType, CStifTFwIfProt::EMsgResponse );
       
  2669     
       
  2670     if( error != KErrNone )
       
  2671         {
       
  2672         __TRACE( KError, ( _L( "CUIStore::RemoteMsg: message parsing failed [%d]"), error ) );
       
  2673         resp->AppendId( SETID( (TInt32)DevId(), 0 ) );
       
  2674         resp->AppendId( msg->SrcId() );
       
  2675         resp->Append( CStifTFwIfProt::MsgType, msg->iMsgType );
       
  2676         resp->Append( CStifTFwIfProt::RespParam, CStifTFwIfProt::ERespResult, error );
       
  2677         
       
  2678         aContainer->RemoteReceive( resp->Message() );
       
  2679         
       
  2680         // Error reported with protocol message, return success
       
  2681         delete msg;
       
  2682         delete resp;
       
  2683         return KErrNone;
       
  2684         }                    
       
  2685     
       
  2686     TBool sendResp = ETrue;
       
  2687                         
       
  2688     switch( msg->iMsgType )
       
  2689         {
       
  2690         case CStifTFwIfProt::EMsgReserve:
       
  2691             {
       
  2692             // Check IDs
       
  2693             if( ( msg->SrcDevId() == 0 ) ||
       
  2694                 ( msg->SrcTestId() == 0 ) )
       
  2695                 {
       
  2696                 __TRACE( KError, ( _L( "CUIStore::RemoteMsg: reserve for illegal srcid received") ) );
       
  2697                 error = KErrGeneral;
       
  2698                 }
       
  2699             if( msg->DstId() != 0 ) 
       
  2700                 {
       
  2701                 // Not a broadcast 
       
  2702                 if( ( msg->DstDevId() != DevId() ) ||
       
  2703                     ( msg->DstTestId() != 0 ) )  
       
  2704                     {
       
  2705                     __TRACE( KError, ( _L( "CUIStore::RemoteMsg: reserve for illegal dstid received") ) );
       
  2706                     error = KErrGeneral;
       
  2707                     }
       
  2708                 }                
       
  2709                 
       
  2710             resp->AppendId( SETID( (TInt32)DevId(), 0 ) );
       
  2711             resp->AppendId( msg->SrcId() );
       
  2712             resp->Append( CStifTFwIfProt::MsgType, CStifTFwIfProt::EMsgReserve );
       
  2713             if( error != KErrNone )
       
  2714                 {
       
  2715                 resp->Append( CStifTFwIfProt::RespParam, CStifTFwIfProt::ERespResult, error );
       
  2716                 }
       
  2717             }
       
  2718             break;
       
  2719         case CStifTFwIfProt::EMsgRelease:
       
  2720             {
       
  2721             // Check protocol ids
       
  2722             if( ( msg->SrcDevId() == 0 ) ||
       
  2723                 ( msg->SrcTestId() == 0 ) ||
       
  2724                 ( msg->DstTestId() != 0 ) )
       
  2725                 {
       
  2726                 __TRACE( KError, ( _L( "CUIStore::RemoteMsg: release for illegal srcid or dstid received") ) );
       
  2727                 error = KErrGeneral;
       
  2728                 }   
       
  2729             else if( msg->DstDevId() != DevId() ) 
       
  2730                 {
       
  2731                 __TRACE( KError, ( _L( "CUIStore::RemoteMsg: release for illegal dstid received") ) );
       
  2732                 error = KErrNotFound;
       
  2733                 }   
       
  2734 
       
  2735             resp->AppendId( msg->DstId() );
       
  2736             resp->AppendId( msg->SrcId() );
       
  2737             resp->Append( CStifTFwIfProt::MsgType, CStifTFwIfProt::EMsgRelease );
       
  2738             
       
  2739             if( error != KErrNone )
       
  2740                 {
       
  2741                 resp->Append( CStifTFwIfProt::RespParam, CStifTFwIfProt::ERespResult, error );
       
  2742                 }            
       
  2743             }
       
  2744             break;
       
  2745         case CStifTFwIfProt::EMsgRemote:
       
  2746             {
       
  2747             // Check protocol ids
       
  2748             if( ( msg->SrcDevId() == 0 ) ||
       
  2749                 ( msg->SrcTestId() == 0 ) ||
       
  2750                 ( msg->DstDevId() == 0 ) )
       
  2751                 {
       
  2752                 __TRACE( KError, ( _L( "CUIStore::RemoteMsg: remote for illegal srcid or dstid received") ) );
       
  2753                 error = KErrGeneral;
       
  2754                 }
       
  2755             else
       
  2756                 {               
       
  2757                 __TRACE( KError, ( _L( "CUIStore::RemoteMsg: received remote call") ) );
       
  2758                 
       
  2759                 error = MsgRemote( aContainer, *msg, *resp );
       
  2760                 }
       
  2761                 
       
  2762             if( error != KErrNone )
       
  2763                 {
       
  2764                 resp->AppendId( msg->DstId() );
       
  2765                 resp->AppendId( msg->SrcId() );
       
  2766                 resp->Append( CStifTFwIfProt::MsgType, CStifTFwIfProt::EMsgRemote );
       
  2767                 resp->Append( msg->iCmdDes );
       
  2768                 resp->Append( CStifTFwIfProt::RespParam,     
       
  2769                              CStifTFwIfProt::ERespResult, 
       
  2770                              error );
       
  2771                 }
       
  2772             else
       
  2773                 {
       
  2774                 sendResp = EFalse;
       
  2775                 }
       
  2776                                 
       
  2777             }
       
  2778             break;
       
  2779         case CStifTFwIfProt::EMsgResponse:            
       
  2780         default:
       
  2781             __TRACE( KError, ( _L( "CUIStore::RemoteMsg: invalid message")) );
       
  2782             ret = KErrNotSupported;
       
  2783         }
       
  2784 
       
  2785     if( ( ret == KErrNone ) && sendResp ) 
       
  2786          {
       
  2787         aContainer->RemoteReceive( resp->Message() );
       
  2788         }
       
  2789         
       
  2790     delete msg;
       
  2791     delete resp;
       
  2792     
       
  2793     return ret;
       
  2794     
       
  2795     }
       
  2796 
       
  2797 
       
  2798 /*
       
  2799 -------------------------------------------------------------------------------
       
  2800 
       
  2801     Class: CUIStore
       
  2802 
       
  2803     Method: MsgRemote
       
  2804 
       
  2805     Description: Remote command
       
  2806     
       
  2807     Parameters: const TDesC& aMessage: in:
       
  2808 
       
  2809     Return Values: KErrNotSupported
       
  2810 
       
  2811     Errors/Exceptions: None
       
  2812 
       
  2813     Status: Draft
       
  2814 
       
  2815 -------------------------------------------------------------------------------
       
  2816 */
       
  2817 TInt CUIStore::MsgRemote( CUIEngineContainer* aContainer, 
       
  2818                           CStifTFwIfProt& aReq, 
       
  2819                           CStifTFwIfProt& aResp )
       
  2820     {
       
  2821     
       
  2822     TInt ret = KErrNone;    
       
  2823         
       
  2824     switch( aReq.iCmdType )
       
  2825         {
       
  2826         case CStifTFwIfProt::ECmdRun:
       
  2827             ret = MsgRemoteRun( aContainer, aReq, aResp );
       
  2828             break;
       
  2829         case CStifTFwIfProt::ECmdPause:
       
  2830         case CStifTFwIfProt::ECmdResume:
       
  2831         case CStifTFwIfProt::ECmdCancel:
       
  2832             ret = MsgRemoteTestCtl( aContainer, aReq, aResp );
       
  2833             break;
       
  2834         case CStifTFwIfProt::ECmdRequest:
       
  2835         case CStifTFwIfProt::ECmdRelease:
       
  2836         case CStifTFwIfProt::ECmdSetEvent:
       
  2837         case CStifTFwIfProt::ECmdUnsetEvent:            
       
  2838             ret = MsgRemoteEventCtl( aContainer, aReq, aResp );            
       
  2839             break;
       
  2840         case CStifTFwIfProt::ECmdSendReceive:
       
  2841             {
       
  2842             ret = MsgRemoteSendReceive( aContainer, aReq, aResp );
       
  2843             break;
       
  2844             }
       
  2845         default:
       
  2846             {
       
  2847             CStifTFwIfProt* resp = NULL;
       
  2848             TRAPD( err, 
       
  2849                 resp = CStifTFwIfProt::NewL(); 
       
  2850                 resp->CreateL();
       
  2851                 );
       
  2852             if( err != KErrNone )
       
  2853                 {
       
  2854                 delete resp;
       
  2855                 return err;
       
  2856                 }
       
  2857             resp->SetMsgType( CStifTFwIfProt::EMsgResponse );
       
  2858             resp->SetSrcId( aReq.DstId() );
       
  2859             resp->SetDstId( aReq.SrcId() );
       
  2860             resp->SetRespType( CStifTFwIfProt::EMsgRemote );
       
  2861             // Command type must be set separately, 
       
  2862             // because it is unspecified in this case
       
  2863             resp->iCmdType = aReq.iCmdType;
       
  2864             resp->Append( aReq.iCmdDes );
       
  2865                 
       
  2866             ret = RemotePopup( aContainer, aReq.Message(), resp );
       
  2867 
       
  2868             if( ret != KErrNone )
       
  2869                 {
       
  2870                 delete resp;
       
  2871                 }
       
  2872             }
       
  2873             break;
       
  2874         }
       
  2875     
       
  2876     return ret;
       
  2877     
       
  2878     }
       
  2879 
       
  2880 /*
       
  2881 -------------------------------------------------------------------------------
       
  2882 
       
  2883     Class: CUIStore
       
  2884 
       
  2885     Method: AtsRemoteRun
       
  2886 
       
  2887     Description: Remote run message
       
  2888     
       
  2889     Parameters: const TDesC& aMessage: in:
       
  2890 
       
  2891     Return Values: KErrNotSupported
       
  2892 
       
  2893     Errors/Exceptions: None
       
  2894 
       
  2895     Status: Draft
       
  2896 
       
  2897 -------------------------------------------------------------------------------
       
  2898 */        
       
  2899 TInt CUIStore::MsgRemoteRun( CUIEngineContainer* aContainer,
       
  2900                              CStifTFwIfProt& aReq, 
       
  2901                              CStifTFwIfProt& /* aResp */)
       
  2902     {
       
  2903     
       
  2904     TInt ret = KErrNone;    
       
  2905     TUint16 testid = 0;
       
  2906     
       
  2907     if( ( aReq.DstDevId() == 0 ) ||
       
  2908         ( aReq.DstTestId() != 0 ) ) 
       
  2909         {
       
  2910         // Protocol violation
       
  2911         __TRACE( KError, ( _L( "AtsReceive: remote run for illegal dstid received") ) );
       
  2912         return KErrGeneral;
       
  2913         }
       
  2914 
       
  2915     if ( aReq.DstDevId() != DevId() ) 
       
  2916         {
       
  2917         // Not our protocol message
       
  2918         __TRACE( KError, ( _L( "AtsReceive: remote run for illegal dstdevid received") ) );
       
  2919         return KErrNotFound;
       
  2920         }
       
  2921 
       
  2922     
       
  2923     if( aReq.iModule.Length() == 0 )
       
  2924         {
       
  2925         __TRACE( KError, ( _L("No mandatory test module name given as run parameter") ) );        
       
  2926         ret = KErrNotFound;
       
  2927         }    
       
  2928     else if( aReq.iTestCaseNumber < 0 )
       
  2929         {
       
  2930         __TRACE( KError, ( _L("No mandatory test case number given as run parameter") ) );        
       
  2931         ret = KErrNotFound;
       
  2932         }    
       
  2933     
       
  2934     testid = 1;
       
  2935     CStifTFwIfProt* resp = NULL;
       
  2936     TRAPD( err, 
       
  2937         resp = CStifTFwIfProt::NewL(); 
       
  2938         resp->CreateL();
       
  2939         );
       
  2940     if( err != KErrNone )
       
  2941         {
       
  2942         delete resp;
       
  2943         return err;
       
  2944         }
       
  2945 
       
  2946     CStifTFwIfProt* resp2 = NULL;
       
  2947     TRAP( err, 
       
  2948         resp2 = CStifTFwIfProt::NewL(); 
       
  2949         resp2->CreateL();
       
  2950         );
       
  2951     if( err != KErrNone )
       
  2952         {
       
  2953         delete resp2;
       
  2954         return err;
       
  2955         }              
       
  2956 
       
  2957     resp->SetMsgType( CStifTFwIfProt::EMsgResponse );
       
  2958     resp->SetSrcId( SETID( (TInt32)DevId(), testid ) );
       
  2959     resp->SetDstId( aReq.SrcId() );
       
  2960     resp->SetRespType( CStifTFwIfProt::EMsgRemote );
       
  2961     resp->SetCmdType( CStifTFwIfProt::ECmdRun );        
       
  2962 
       
  2963     resp2->SetMsgType( CStifTFwIfProt::EMsgResponse );
       
  2964     resp2->SetSrcId( SETID( (TInt32)DevId(), testid ) );
       
  2965     resp2->SetDstId( aReq.SrcId() );
       
  2966     resp2->SetRespType( CStifTFwIfProt::EMsgRemote );
       
  2967     resp2->SetCmdType( CStifTFwIfProt::ECmdRun );        
       
  2968    
       
  2969     // Remote run started popup call
       
  2970     ret = RemotePopup( aContainer, aReq.Message(), resp, EPopupPriorityHighest );
       
  2971     if( ret != KErrNone )
       
  2972         {
       
  2973         delete resp;
       
  2974         }
       
  2975     
       
  2976     // Remote run result popup call
       
  2977     ret = RemotePopup( aContainer, aReq.Message(), resp2 );
       
  2978     if( ret != KErrNone )
       
  2979         {
       
  2980         delete resp2;
       
  2981         }
       
  2982     
       
  2983     return ret;            
       
  2984     }
       
  2985 
       
  2986 /*
       
  2987 -------------------------------------------------------------------------------
       
  2988 
       
  2989     Class: CUIStore
       
  2990 
       
  2991     Method: MsgRemoteTestCtl
       
  2992 
       
  2993     Description: Remote test control message
       
  2994     
       
  2995     Parameters: const TDesC& aMessage: in:
       
  2996 
       
  2997     Return Values: KErrNotSupported
       
  2998 
       
  2999     Errors/Exceptions: None
       
  3000 
       
  3001     Status: Draft
       
  3002 
       
  3003 -------------------------------------------------------------------------------
       
  3004 */        
       
  3005 TInt CUIStore::MsgRemoteTestCtl( CUIEngineContainer* aContainer,
       
  3006                                  CStifTFwIfProt& aReq, 
       
  3007                                  CStifTFwIfProt& /*aResp*/ )
       
  3008     {
       
  3009     
       
  3010     TInt ret = KErrNone;    
       
  3011    
       
  3012     if( ( aReq.DstDevId() == 0 ) ||
       
  3013         ( aReq.DstTestId() == 0 ) ) 
       
  3014         {
       
  3015         // Protocol violation
       
  3016         __TRACE( KError, ( _L( "AtsReceive: remote test control for illegal dstid received") ) );
       
  3017         return KErrGeneral;
       
  3018         }
       
  3019 
       
  3020     if ( aReq.DstDevId() != DevId() ) 
       
  3021         {
       
  3022         // Not our protocol message
       
  3023         __TRACE( KError, ( _L( "AtsReceive: remote test control for illegal dstdevid received") ) );
       
  3024         return KErrNotFound;
       
  3025         }
       
  3026     
       
  3027     CStifTFwIfProt* resp = NULL;
       
  3028     TRAPD( err, 
       
  3029         resp = CStifTFwIfProt::NewL(); 
       
  3030         resp->CreateL();
       
  3031         );
       
  3032     if( err != KErrNone )
       
  3033         {
       
  3034         delete resp;
       
  3035         return err;
       
  3036         }
       
  3037         
       
  3038     resp->SetMsgType( CStifTFwIfProt::EMsgResponse );
       
  3039     resp->SetSrcId( aReq.DstId() );
       
  3040     resp->SetDstId( aReq.SrcId() );
       
  3041     resp->SetRespType( CStifTFwIfProt::EMsgRemote );
       
  3042     resp->SetCmdType( aReq.iCmdType );
       
  3043     
       
  3044     ret = RemotePopup( aContainer, aReq.Message(), resp );
       
  3045 
       
  3046     if( ret != KErrNone )
       
  3047         {
       
  3048         delete resp;
       
  3049         }
       
  3050 
       
  3051     return ret;
       
  3052     
       
  3053     }    
       
  3054 
       
  3055 /*
       
  3056 -------------------------------------------------------------------------------
       
  3057 
       
  3058     Class: CUIStore
       
  3059 
       
  3060     Method: MsgRemoteEventCtl
       
  3061 
       
  3062     Description: Remote run message
       
  3063     
       
  3064     Parameters: const TDesC& aMessage: in:
       
  3065 
       
  3066     Return Values: KErrNotSupported
       
  3067 
       
  3068     Errors/Exceptions: None
       
  3069 
       
  3070     Status: Draft
       
  3071 
       
  3072 -------------------------------------------------------------------------------
       
  3073 */        
       
  3074 TInt CUIStore::MsgRemoteEventCtl( CUIEngineContainer* aContainer,
       
  3075                                   CStifTFwIfProt& aReq, 
       
  3076                                   CStifTFwIfProt& aResp )
       
  3077     {
       
  3078     
       
  3079     if( ( aReq.DstDevId() == 0 ) ||
       
  3080         ( aReq.DstTestId() != 0 ) ) 
       
  3081         {
       
  3082         // Protocol violation
       
  3083         __TRACE( KError, ( _L( "AtsReceive: remote event control for illegal dstid received") ) );
       
  3084         return KErrGeneral;
       
  3085         }
       
  3086 
       
  3087     if ( aReq.DstDevId() != DevId() ) 
       
  3088         {
       
  3089         // Not our protocol message
       
  3090         __TRACE( KError, ( _L( "AtsReceive: remote event control for illegal dstdevid received") ) );
       
  3091         return KErrNotFound;
       
  3092         }
       
  3093         
       
  3094     if( aReq.iEventName.Length() == 0 )
       
  3095         {
       
  3096         __TRACE( KError, ( _L("No event name given") ) );        
       
  3097         return KErrNotFound;
       
  3098     }
       
  3099     
       
  3100     TInt ret = KErrNone;
       
  3101                     
       
  3102     switch( aReq.iCmdType )
       
  3103         {
       
  3104         case CStifTFwIfProt::ECmdRequest:
       
  3105             {
       
  3106             // Send event active information
       
  3107             CStifTFwIfProt* resp = NULL;
       
  3108             TRAP( ret, 
       
  3109                 resp = CStifTFwIfProt::NewL(); 
       
  3110                 resp->CreateL(); );
       
  3111             if( ret != KErrNone )
       
  3112                 {
       
  3113                 delete resp;
       
  3114                 return ret;
       
  3115                 }
       
  3116                 
       
  3117             resp->SetMsgType( CStifTFwIfProt::EMsgResponse );
       
  3118             resp->SetSrcId( aReq.DstId() );
       
  3119             resp->SetDstId( aReq.SrcId() );
       
  3120             resp->SetRespType( CStifTFwIfProt::EMsgRemote );
       
  3121             resp->SetCmdType( CStifTFwIfProt::ECmdRequest );
       
  3122             resp->Append( CStifTFwIfProt::EventStatus, 
       
  3123                           CStifTFwIfProt::EEventSet );
       
  3124             resp->Append( aReq.iEventName );
       
  3125             ret = RemotePopup( aContainer, aReq.Message(), resp, EPopupPriorityNormal );                
       
  3126 
       
  3127             if( ret != KErrNone )
       
  3128                 {
       
  3129                 delete resp;
       
  3130                 }
       
  3131                     
       
  3132             aResp.AppendId( aReq.DstId() );
       
  3133             aResp.AppendId( aReq.SrcId() );
       
  3134             aResp.Append( CStifTFwIfProt::MsgType, CStifTFwIfProt::EMsgRemote );
       
  3135             aResp.Append( CStifTFwIfProt::CmdType, CStifTFwIfProt::ECmdRequest );
       
  3136             if( ret == KErrNone )
       
  3137                 {
       
  3138                 aResp.Append( CStifTFwIfProt::EventStatus, 
       
  3139                               CStifTFwIfProt::EEventActive );
       
  3140                 aResp.Append( aReq.iEventName );
       
  3141                 }
       
  3142             else 
       
  3143                 {
       
  3144                 aResp.Append( CStifTFwIfProt::EventStatus, 
       
  3145                               CStifTFwIfProt::EEventError );
       
  3146                 aResp.Append( aReq.iEventName );                              
       
  3147                 aResp.Append( CStifTFwIfProt::EventStatusParams, 
       
  3148                              CStifTFwIfProt::EEventResult,
       
  3149                              ret );
       
  3150                 }
       
  3151 
       
  3152             ret = aContainer->RemoteReceive( aResp.Message() );    
       
  3153             ret = KErrNone;          
       
  3154             }
       
  3155             break;
       
  3156         case CStifTFwIfProt::ECmdSetEvent:
       
  3157             {
       
  3158             // Send event active information
       
  3159             CStifTFwIfProt* resp = NULL;
       
  3160             TRAP( ret, 
       
  3161                 resp = CStifTFwIfProt::NewL(); 
       
  3162                 resp->CreateL(); );
       
  3163             if( ret != KErrNone )
       
  3164                 {
       
  3165                 delete resp;
       
  3166                 return ret;
       
  3167                 }
       
  3168                 
       
  3169             resp->SetMsgType( CStifTFwIfProt::EMsgResponse );
       
  3170             resp->SetSrcId( aReq.DstId() );
       
  3171             resp->SetDstId( aReq.SrcId() );
       
  3172             resp->SetRespType( CStifTFwIfProt::EMsgRemote );
       
  3173             resp->SetCmdType( CStifTFwIfProt::ECmdSetEvent );
       
  3174             resp->Append( CStifTFwIfProt::EventStatus, 
       
  3175                           CStifTFwIfProt::EEventSet );
       
  3176             resp->Append( aReq.iEventName );
       
  3177             if ( aReq.iEventType == TEventIf::EState )
       
  3178                 {
       
  3179                 resp->Append( CStifTFwIfProt::EventStatusParams, 
       
  3180                                                              CStifTFwIfProt::EEventType,
       
  3181                                                              CStifTFwIfProt::EventType, 
       
  3182                                                              TEventIf::EState );
       
  3183                 }
       
  3184             
       
  3185             ret = RemotePopup( aContainer, aReq.Message(), resp, EPopupPriorityNormal );                
       
  3186 
       
  3187             if( ret != KErrNone )
       
  3188                 {
       
  3189                 delete resp;
       
  3190                 }
       
  3191                     
       
  3192             aResp.AppendId( aReq.DstId() );
       
  3193             aResp.AppendId( aReq.SrcId() );
       
  3194             aResp.Append( CStifTFwIfProt::MsgType, CStifTFwIfProt::EMsgRemote );
       
  3195             aResp.Append( CStifTFwIfProt::CmdType, CStifTFwIfProt::ECmdSetEvent );
       
  3196             if( ret == KErrNone )
       
  3197                 {
       
  3198                 aResp.Append( CStifTFwIfProt::EventStatus, 
       
  3199                               CStifTFwIfProt::EEventSet );                
       
  3200                 aResp.Append( aReq.iEventName );
       
  3201                 if ( aReq.iEventType == TEventIf::EState )
       
  3202                     {
       
  3203                     aResp.Append( CStifTFwIfProt::EventStatusParams, 
       
  3204                             CStifTFwIfProt::EEventType,
       
  3205                             CStifTFwIfProt::EventType, 
       
  3206                             TEventIf::EState );
       
  3207                     }
       
  3208                 }
       
  3209             else 
       
  3210                 {
       
  3211                 aResp.Append( CStifTFwIfProt::EventStatus, 
       
  3212                               CStifTFwIfProt::EEventError );                
       
  3213                 aResp.Append( CStifTFwIfProt::EventStatusParams, 
       
  3214                              CStifTFwIfProt::EEventResult,
       
  3215                              ret );
       
  3216                 }
       
  3217 
       
  3218             ret = aContainer->RemoteReceive( aResp.Message() );    
       
  3219             ret = KErrNone;          
       
  3220             }
       
  3221             break;
       
  3222         case CStifTFwIfProt::ECmdUnsetEvent:
       
  3223             {
       
  3224             // Send event active information
       
  3225             CStifTFwIfProt* resp = NULL;
       
  3226             TRAP( ret, 
       
  3227                 resp = CStifTFwIfProt::NewL(); 
       
  3228                 resp->CreateL(); );
       
  3229             if( ret != KErrNone )
       
  3230                 {
       
  3231                 delete resp;
       
  3232                 return ret;
       
  3233                 }
       
  3234                 
       
  3235             resp->SetMsgType( CStifTFwIfProt::EMsgResponse );
       
  3236             resp->SetSrcId( aReq.DstId() );
       
  3237             resp->SetDstId( aReq.SrcId() );
       
  3238             resp->SetRespType( CStifTFwIfProt::EMsgRemote );
       
  3239             resp->SetCmdType( CStifTFwIfProt::ECmdUnsetEvent );
       
  3240             resp->Append( CStifTFwIfProt::EventStatus, 
       
  3241                           CStifTFwIfProt::EEventUnset );
       
  3242             resp->Append( aReq.iEventName );
       
  3243             
       
  3244             ret = RemotePopup( aContainer, aReq.Message(), resp, EPopupPriorityNormal );                
       
  3245 
       
  3246             if( ret != KErrNone )
       
  3247                 {
       
  3248                 delete resp;
       
  3249                 }
       
  3250                     
       
  3251             aResp.AppendId( aReq.DstId() );
       
  3252             aResp.AppendId( aReq.SrcId() );
       
  3253             aResp.Append( CStifTFwIfProt::MsgType, CStifTFwIfProt::EMsgRemote );
       
  3254             aResp.Append( CStifTFwIfProt::CmdType, CStifTFwIfProt::ECmdUnsetEvent );
       
  3255             if( ret == KErrNone )
       
  3256                 {
       
  3257                 aResp.Append( CStifTFwIfProt::EventStatus, 
       
  3258                               CStifTFwIfProt::EEventUnset );
       
  3259                 aResp.Append( aReq.iEventName );
       
  3260                 }
       
  3261             else 
       
  3262                 {
       
  3263                 aResp.Append( CStifTFwIfProt::EventStatus, 
       
  3264                               CStifTFwIfProt::EEventError );
       
  3265                 aResp.Append( CStifTFwIfProt::EventStatusParams, 
       
  3266                              CStifTFwIfProt::EEventResult,
       
  3267                              ret );
       
  3268                 }
       
  3269 
       
  3270             ret = aContainer->RemoteReceive( aResp.Message() );    
       
  3271             ret = KErrNone;          
       
  3272             }
       
  3273             break;            
       
  3274             
       
  3275         case CStifTFwIfProt::ECmdRelease:
       
  3276             {
       
  3277             // Check and delete all pending event popup windows for test case
       
  3278             TInt count = iPopups.Count();
       
  3279             for( TInt i = 0; i<count; i++ )
       
  3280                 {
       
  3281                 if( ( iPopups[i]->Container() == aContainer ) &&
       
  3282                     iPopups[i]->IsEventPopup() )
       
  3283                     {
       
  3284                     delete iPopups[i];
       
  3285                     iPopups.Remove( i );
       
  3286                     }
       
  3287                 }
       
  3288                 
       
  3289             aResp.AppendId( aReq.DstId() );
       
  3290             aResp.AppendId( aReq.SrcId() );
       
  3291             aResp.Append( CStifTFwIfProt::MsgType, CStifTFwIfProt::EMsgRemote );
       
  3292             aResp.Append( CStifTFwIfProt::CmdType, CStifTFwIfProt::ECmdRelease );
       
  3293             aResp.Append( aReq.iEventName );
       
  3294 
       
  3295             ret = aContainer->RemoteReceive( aResp.Message() );    
       
  3296             ret = KErrNone;          
       
  3297             
       
  3298             }
       
  3299             break;
       
  3300         default:
       
  3301             return KErrNotSupported;
       
  3302         }
       
  3303         
       
  3304     return ret;
       
  3305     
       
  3306     }    
       
  3307 
       
  3308 /*
       
  3309 -------------------------------------------------------------------------------
       
  3310 
       
  3311     Class: CUIStore
       
  3312 
       
  3313     Method: MsgRemoteSendReceive
       
  3314 
       
  3315     Description: Asynchronous remote sendreceive message
       
  3316     
       
  3317     Parameters: CUIEngineContainer* aContainer: in:
       
  3318                 CStifTFwIfProt& aReq: in
       
  3319                 CStifTFwIfProt& aResp: in
       
  3320 
       
  3321     Return Values: KErrNotSupported
       
  3322 
       
  3323     Errors/Exceptions: None
       
  3324 
       
  3325     Status: Draft
       
  3326 
       
  3327 -------------------------------------------------------------------------------
       
  3328 */        
       
  3329 TInt CUIStore::MsgRemoteSendReceive( CUIEngineContainer* aContainer,
       
  3330                              CStifTFwIfProt& aReq, 
       
  3331                              CStifTFwIfProt& aResp )
       
  3332     {
       
  3333     
       
  3334     TInt ret = KErrNone;    
       
  3335     // TUint16 testid = 0;
       
  3336     
       
  3337     if( ( aReq.DstDevId() == 0 ) ||
       
  3338         ( aReq.DstTestId() != 0 ) ) 
       
  3339         {
       
  3340         // Protocol violation
       
  3341         __TRACE( KError, ( _L( "AtsReceive: remote run for illegal dstid received") ) );
       
  3342         return KErrGeneral;
       
  3343         }
       
  3344 
       
  3345     if ( aReq.DstDevId() != DevId() ) 
       
  3346         {
       
  3347         // Not our protocol message
       
  3348         __TRACE( KError, ( _L( "AtsReceive: remote run for illegal dstdevid received") ) );
       
  3349         return KErrNotFound;
       
  3350         }
       
  3351 
       
  3352     // testid = 1;
       
  3353     CStifTFwIfProt* resp = NULL;
       
  3354     TRAPD( err, 
       
  3355         resp = CStifTFwIfProt::NewL(); 
       
  3356         resp->CreateL();
       
  3357         );
       
  3358     if( err != KErrNone )
       
  3359         {
       
  3360         delete resp;
       
  3361         return err;
       
  3362         }
       
  3363         
       
  3364     resp->SetMsgType( CStifTFwIfProt::EMsgResponse );
       
  3365     //resp->SetSrcId( SETID( DevId(), testid ) );
       
  3366     resp->SetSrcId( aReq.DstId() );
       
  3367     resp->SetDstId( aReq.SrcId() );
       
  3368     resp->SetRespType( CStifTFwIfProt::EMsgRemote );
       
  3369     resp->SetCmdType( CStifTFwIfProt::ECmdSendReceive );        
       
  3370    
       
  3371     ret = RemotePopup( aContainer, aReq.Message(), resp );
       
  3372     if( ret != KErrNone )
       
  3373         {
       
  3374         delete resp;
       
  3375         }
       
  3376         
       
  3377     aResp.AppendId( aReq.DstId() );
       
  3378     aResp.AppendId( aReq.SrcId() );
       
  3379     aResp.Append( CStifTFwIfProt::MsgType, CStifTFwIfProt::EMsgRemote );
       
  3380     aResp.Append( CStifTFwIfProt::CmdType, CStifTFwIfProt::ECmdSendReceive );
       
  3381     if( ret != KErrNone )
       
  3382         {
       
  3383         aResp.Append( CStifTFwIfProt::RunStatus, 
       
  3384                       CStifTFwIfProt::ERunError );
       
  3385         aResp.Append( CStifTFwIfProt::RunStatusParams, 
       
  3386                       CStifTFwIfProt::ERunResult, ret );
       
  3387         }
       
  3388     else
       
  3389         {
       
  3390         aResp.Append( CStifTFwIfProt::RunStatus, 
       
  3391                       CStifTFwIfProt::ERunStarted );
       
  3392         }
       
  3393 
       
  3394     // Send response
       
  3395     aContainer->RemoteReceive( aResp.Message() );
       
  3396     
       
  3397     // Response is created, return success
       
  3398     ret = KErrNone;        
       
  3399     
       
  3400     return ret;
       
  3401             
       
  3402     }
       
  3403 
       
  3404 /*
       
  3405 -------------------------------------------------------------------------------
       
  3406 
       
  3407     Class: CUIStore
       
  3408 
       
  3409     Method: GoingToReboot
       
  3410 
       
  3411     Description: Reboot indication handling.
       
  3412 
       
  3413     Parameters: CUIEngineContainer* aContainer: in: Container
       
  3414 
       
  3415     Return Values: None
       
  3416 
       
  3417     Errors/Exceptions: None
       
  3418 
       
  3419     Status: Draft
       
  3420 
       
  3421 -------------------------------------------------------------------------------
       
  3422 */
       
  3423 TInt CUIStore::GoingToReboot( CUIEngineContainer* /* aContainer */,
       
  3424                               TRequestStatus& aStatus )
       
  3425     {
       
  3426     
       
  3427     _LIT( KDateString,"%H%T%S.%C" ); 
       
  3428        
       
  3429     const TInt KTimeFieldLength = 30;
       
  3430     TBuf<KTimeFieldLength> time;
       
  3431     
       
  3432     // Store info 
       
  3433     CStifLogger* logger = CStifLogger::NewL( KUIStoreDefaultDir,
       
  3434                                              KUIStoreDefaultRebootFile,
       
  3435                                              CStifLogger::EData,
       
  3436                                              CStifLogger::EFile,
       
  3437                                              ETrue,
       
  3438                                              EFalse,
       
  3439                                              EFalse,
       
  3440                                              EFalse,
       
  3441                                              EFalse,
       
  3442                                              ETrue );
       
  3443     
       
  3444     CleanupStack::PushL( logger );
       
  3445     TInt count = iStartedTestCases.Count();
       
  3446     for( TInt index=0; index<count; index++ )
       
  3447         {
       
  3448         logger->Log( _L("%S\r\n"), &KUIStoreStartTest );
       
  3449         
       
  3450         // First test case info
       
  3451         logger->Log( _L("%S %S\r\n"), &KUIStoreCaseModuleName, 
       
  3452             &iStartedTestCases[index]->TestInfo().ModuleName() );
       
  3453         logger->Log( _L("%S %S\r\n"), &KUIStoreTestCaseTitle, 
       
  3454             &iStartedTestCases[index]->TestInfo().TestCaseTitle() );
       
  3455         if( iStartedTestCases[index]->TestInfo().TestCaseFile().Length() > 0 )
       
  3456             {
       
  3457             logger->Log( _L("%S %S\r\n"), &KUIStoreTestCaseFile, 
       
  3458                 &iStartedTestCases[index]->TestInfo().TestCaseFile() );
       
  3459             }
       
  3460         logger->Log( _L("%S %d\r\n"), &KUIStoreTestCaseNum, 
       
  3461             iStartedTestCases[index]->TestInfo().TestCaseNum() );
       
  3462         logger->Log( _L("%S %d\r\n"), &KUIStoreCasePriority, 
       
  3463             iStartedTestCases[index]->TestInfo().Priority() );
       
  3464          //@js<--remove--> logger->Log( _L("%S %d %d\r\n"), &KUIStoreCaseTimeout,            
       
  3465          //@js<--remove--> iStartedTestCases[index]->TestInfo().Timeout().Int64().Low(),
       
  3466          //@js<--remove--> iStartedTestCases[index]->TestInfo().Timeout().Int64().High() );
       
  3467         logger->Log( _L("%S %d %d\r\n"), &KUIStoreCaseTimeout,            
       
  3468             I64LOW(iStartedTestCases[index]->TestInfo().Timeout().Int64()),
       
  3469             I64HIGH(iStartedTestCases[index]->TestInfo().Timeout().Int64()));     
       
  3470             
       
  3471         logger->Log( _L("%S %d\r\n"), &KUIStoreCaseExpectedResult, 
       
  3472             iStartedTestCases[index]->TestInfo().ExpectedResult() );    
       
  3473         
       
  3474         logger->Log( _L("%S %d\r\n"), &KUIStoreCaseStatus, 
       
  3475             iStartedTestCases[index]->Status() );    
       
  3476 
       
  3477         logger->Log( _L("%S %d %d\r\n"), &KUIStoreCaseExecutionResult, 
       
  3478             iStartedTestCases[index]->Result().iCaseExecutionResultType,
       
  3479             iStartedTestCases[index]->Result().iCaseExecutionResultCode );    
       
  3480         logger->Log( _L("%S %d %S\r\n"), &KUIStoreCaseResult, 
       
  3481             iStartedTestCases[index]->Result().iTestResult.iResult,
       
  3482             &iStartedTestCases[index]->Result().iTestResult.iResultDes );    
       
  3483         
       
  3484         // Start time
       
  3485         iStartedTestCases[index]->Result().iStartTime.FormatL(
       
  3486                     time, KDateString );
       
  3487         logger->Log( _L("%S %S\r\n"), &KUIStoreCaseStartTime, &time );
       
  3488 
       
  3489         // Start time
       
  3490         iStartedTestCases[index]->Result().iEndTime.FormatL(
       
  3491                     time, KDateString );
       
  3492         logger->Log( _L("%S %S\r\n"), &KUIStoreCaseEndTime, &time );
       
  3493 
       
  3494         logger->Log( _L("%S\r\n\r\n"), &KUIStoreStartTestEnd );
       
  3495         }
       
  3496     
       
  3497     CleanupStack::PopAndDestroy( logger );
       
  3498     
       
  3499     // Show popup
       
  3500     TKeyCode key;
       
  3501     iUIStoreIf->PopupMsg( _L("GoingToReboot"), 
       
  3502                           _L("Press any key to continue"), 
       
  3503                           KRebootPopupTimeout, key, aStatus );
       
  3504     
       
  3505     return KErrNone;
       
  3506 
       
  3507     }
       
  3508 
       
  3509 /*
       
  3510 -------------------------------------------------------------------------------
       
  3511 
       
  3512     Class: CUIStore
       
  3513 
       
  3514     Method: LoadExecutedTestCasesL
       
  3515 
       
  3516     Description: Load all executed testcases saved before reboot.
       
  3517     
       
  3518     Parameters: None
       
  3519 
       
  3520     Return Values: None
       
  3521 
       
  3522     Errors/Exceptions: Leaves on error
       
  3523 
       
  3524     Status: Draft
       
  3525 
       
  3526 -------------------------------------------------------------------------------
       
  3527 */
       
  3528 void CUIStore::LoadExecutedTestCasesL()
       
  3529     {
       
  3530     TPtrC tmp;
       
  3531     TInt num = 0;
       
  3532     TInt high = 0;
       
  3533     TInt64 interval;
       
  3534     TFullTestResult result;
       
  3535     TInt status = 0;
       
  3536     CStifItemParser* item = NULL;
       
  3537     TInt ret = KErrNone;
       
  3538 
       
  3539     CStifParser* parser = NULL;
       
  3540     TRAP( ret,
       
  3541         parser = CStifParser::NewL( KUIStoreDefaultDir,
       
  3542                                     KUIStoreDefaultRebootFile );
       
  3543         );
       
  3544     if( ret != KErrNone )
       
  3545         {
       
  3546         // reboot file not found
       
  3547         return; 
       
  3548         }
       
  3549     CleanupStack::PushL( parser );
       
  3550    
       
  3551     __TRACE( KInit, ( _L( "Reboot file is found(%S%S). Reboot testing ongoing..." ), &KUIStoreDefaultDir, &KUIStoreDefaultRebootFile ) );
       
  3552 
       
  3553     CTestInfo* testInfo = NULL;    
       
  3554      
       
  3555     CStifSectionParser* section = 
       
  3556         parser->SectionL( KUIStoreStartTest, KUIStoreStartTestEnd );
       
  3557    
       
  3558     while( section )
       
  3559         {
       
  3560         CleanupStack::PushL( section );    
       
  3561         
       
  3562         testInfo = CTestInfo::NewL();
       
  3563         CleanupStack::PushL( testInfo ); 
       
  3564     
       
  3565         // Get module name
       
  3566         // Mandatory, leave if not found
       
  3567         User::LeaveIfError( 
       
  3568             section->GetLine( KUIStoreCaseModuleName, tmp, ENoTag ) );
       
  3569         testInfo->SetModuleName( tmp );
       
  3570     
       
  3571         // Get test case title
       
  3572         // Mandatory, leave if not found
       
  3573         User::LeaveIfError( 
       
  3574             section->GetLine( KUIStoreTestCaseTitle, tmp, ENoTag ) );
       
  3575         testInfo->SetTestCaseTitle( tmp );
       
  3576         
       
  3577         // Get test case file
       
  3578         num = section->GetLine( KUIStoreTestCaseFile, tmp, ENoTag );
       
  3579         if( ( num == KErrNone ) &&
       
  3580             ( tmp.Length() > 0 ) )
       
  3581             {
       
  3582             // Optional
       
  3583             testInfo->SetTestCaseFile( tmp );
       
  3584             }
       
  3585         else
       
  3586             {
       
  3587             testInfo->SetTestCaseFile( KNullDesC );
       
  3588             }
       
  3589         
       
  3590         // Get test case number
       
  3591         item = section->GetItemLineL( KUIStoreTestCaseNum );
       
  3592         CleanupStack::PushL( item );
       
  3593         // Mandatory, leave if not found
       
  3594         User::LeaveIfError( item->GetInt( KUIStoreTestCaseNum, num ));
       
  3595         testInfo->SetTestCaseNumber( num );
       
  3596         CleanupStack::PopAndDestroy( item );    
       
  3597         
       
  3598         // Get test case priority
       
  3599         item = section->GetItemLineL( KUIStoreCasePriority );
       
  3600         CleanupStack::PushL( item );
       
  3601         // Mandatory, leave if not found
       
  3602         User::LeaveIfError( item->GetInt( KUIStoreCasePriority, num ));
       
  3603         testInfo->SetPriority( num );
       
  3604         CleanupStack::PopAndDestroy( item ); 
       
  3605         
       
  3606         // Get test case timeout
       
  3607         item = section->GetItemLineL( KUIStoreCaseTimeout );
       
  3608         CleanupStack::PushL( item );
       
  3609         // Mandatory, leave if not found
       
  3610         User::LeaveIfError( item->GetInt( KUIStoreCaseTimeout, num ));
       
  3611         User::LeaveIfError( item->GetNextInt( high ));
       
  3612         //interval.Set( high, num );
       
  3613         interval = MAKE_TINT64( high, num );      
       
  3614         TTimeIntervalMicroSeconds timeout( interval );
       
  3615         testInfo->SetTimeout( timeout );
       
  3616         CleanupStack::PopAndDestroy( item ); 
       
  3617         
       
  3618         // Get test case status
       
  3619         item = section->GetItemLineL( KUIStoreCaseStatus );
       
  3620         CleanupStack::PushL( item );
       
  3621         // Mandatory, leave if not found
       
  3622         User::LeaveIfError( item->GetInt( KUIStoreCaseStatus, status ));
       
  3623         CleanupStack::PopAndDestroy( item ); 
       
  3624 
       
  3625         // Get test case execution result
       
  3626         item = section->GetItemLineL( KUIStoreCaseExecutionResult );
       
  3627         CleanupStack::PushL( item );
       
  3628         // Mandatory, leave if not found
       
  3629         User::LeaveIfError( item->GetInt( KUIStoreCaseExecutionResult, num ));
       
  3630         result.iCaseExecutionResultType = ( TFullTestResult::TCaseExecutionResult) num;
       
  3631         // Mandatory, leave if not found
       
  3632         User::LeaveIfError( item->GetNextInt( result.iCaseExecutionResultCode ));
       
  3633         CleanupStack::PopAndDestroy( item );
       
  3634         
       
  3635         // Get test case result
       
  3636         item = section->GetItemLineL( KUIStoreCaseResult );
       
  3637         CleanupStack::PushL( item );
       
  3638         // Mandatory, leave if not found
       
  3639         User::LeaveIfError( item->GetInt( KUIStoreCaseResult, 
       
  3640                                           result.iTestResult.iResult ));
       
  3641         // Not mandatory
       
  3642         TBool first = ETrue;
       
  3643         result.iTestResult.iResultDes.Zero();
       
  3644         ret = item->GetNextString( tmp );
       
  3645         while( ret == KErrNone )
       
  3646             {
       
  3647             if( result.iTestResult.iResultDes.Length() + tmp.Length() + 1 > result.iTestResult.iResultDes.MaxLength() )
       
  3648                 {
       
  3649                 User::Leave( KErrGeneral );
       
  3650                 }
       
  3651             if(!first)
       
  3652                 result.iTestResult.iResultDes.Append(_L(" "));
       
  3653             result.iTestResult.iResultDes.Append( tmp );
       
  3654             first = EFalse;
       
  3655             ret = item->GetNextString( tmp );
       
  3656             }
       
  3657         /*
       
  3658         ret = item->GetNextString( tmp );
       
  3659         if( ret == KErrNone )
       
  3660             {
       
  3661             if( tmp.Length() > result.iTestResult.iResultDes.MaxLength() )
       
  3662                 {
       
  3663                 User::Leave( KErrGeneral );
       
  3664                 }
       
  3665             result.iTestResult.iResultDes.Copy( tmp );
       
  3666             }
       
  3667         */
       
  3668         CleanupStack::PopAndDestroy( item ); 
       
  3669 
       
  3670         // Get test start time
       
  3671         item = section->GetItemLineL( KUIStoreCaseStartTime );
       
  3672         CleanupStack::PushL( item );
       
  3673         // Mandatory, leave if not found
       
  3674         User::LeaveIfError( item->GetString( KUIStoreCaseStartTime, tmp ));
       
  3675         result.iStartTime.Set( tmp );
       
  3676         CleanupStack::PopAndDestroy( item ); 
       
  3677 
       
  3678         // Get test end time
       
  3679         item = section->GetItemLineL( KUIStoreCaseEndTime );
       
  3680         CleanupStack::PushL( item );
       
  3681         // Mandatory, leave if not found
       
  3682         User::LeaveIfError( item->GetString( KUIStoreCaseEndTime, tmp ));
       
  3683         result.iEndTime.Set( tmp );
       
  3684         CleanupStack::PopAndDestroy( item ); 
       
  3685              
       
  3686         if( status != CUIStoreIf::EStatusRunning )
       
  3687             {
       
  3688             // Add executed test cases to list
       
  3689             CStartedTestCase* startedCase = 
       
  3690                 new( ELeave )CStartedTestCase( testInfo, result, status );
       
  3691             User::LeaveIfError( iStartedTestCases.Append( startedCase ) );            
       
  3692             CleanupStack::Pop( testInfo );            
       
  3693 
       
  3694             // Fill data with test case info and send to test engine
       
  3695             TTestInfo *info = new (ELeave) TTestInfo;
       
  3696             CleanupStack::PushL(info);
       
  3697             info->iModuleName.Copy(testInfo->ModuleName());
       
  3698             info->iConfig.Copy(testInfo->TestCaseFile());
       
  3699             info->iTestCaseInfo.iCaseNumber = testInfo->TestCaseNum();
       
  3700             info->iTestCaseInfo.iTitle.Copy(testInfo->TestCaseTitle());
       
  3701             info->iTestCaseInfo.iTimeout = testInfo->Timeout();
       
  3702             info->iTestCaseInfo.iPriority = testInfo->Priority();
       
  3703             
       
  3704             iUIEngine->TestEngine().AddTestCaseResultToTestReport(*info, result, KErrNone);
       
  3705             CleanupStack::PopAndDestroy(info);
       
  3706             } 
       
  3707         else
       
  3708             {
       
  3709             // Restart testcase that was running when reset was done
       
  3710             CUIEngineContainer* container = NULL;
       
  3711             User::LeaveIfError(  
       
  3712                 iUIEngine->StartTestCase( container, *testInfo ) );
       
  3713             
       
  3714             CStartedTestCase* testCase = NULL;
       
  3715             TRAPD( retVal,
       
  3716                 testCase = CStartedTestCase::NewL( *testInfo, *container );
       
  3717                );
       
  3718             if( retVal != KErrNone )
       
  3719                 {
       
  3720                 iUIEngine->AbortStartedTestCase( container );
       
  3721                 User::Leave( retVal );
       
  3722                 }
       
  3723                 
       
  3724             retVal = iStartedTestCases.Append( testCase );
       
  3725             if( retVal != KErrNone )
       
  3726                 {
       
  3727                 iUIEngine->AbortStartedTestCase( container );
       
  3728                 delete testCase;
       
  3729                 User::Leave( retVal );
       
  3730                 }
       
  3731 
       
  3732             CleanupStack::PopAndDestroy( testInfo );
       
  3733 
       
  3734             }
       
  3735         
       
  3736         CleanupStack::PopAndDestroy( section );    
       
  3737         section = 
       
  3738             parser->NextSectionL( KUIStoreStartTest, KUIStoreStartTestEnd );
       
  3739         } 
       
  3740     
       
  3741     CleanupStack::PopAndDestroy( parser );
       
  3742     
       
  3743     // Delete file
       
  3744     RFs rf;
       
  3745     TInt retVal = rf.Connect();
       
  3746 	if( retVal != KErrNone )
       
  3747 		{
       
  3748 		User::Leave( retVal );
       
  3749 		}
       
  3750 		
       
  3751     TFileName file( KUIStoreDefaultDir );
       
  3752     file.Append( KUIStoreDefaultRebootFile );
       
  3753     rf.Delete( file );
       
  3754     rf.Close();
       
  3755     
       
  3756     return;
       
  3757     }    
       
  3758 /*
       
  3759 -------------------------------------------------------------------------------
       
  3760 
       
  3761     Class: CUIStore
       
  3762 
       
  3763     Method: FindByContainer
       
  3764 
       
  3765     Description: Find test case with UIEngine Container pointer.
       
  3766     
       
  3767     Parameters:  CUIEngineContainer* const aContainer: in: Execution container
       
  3768                  CStartedTestCase*& aTestCase: out: Testcase info
       
  3769     
       
  3770     Return Values: Symbian OS error code
       
  3771     
       
  3772     Errors/Exceptions: None
       
  3773 
       
  3774     Status: Draft
       
  3775 
       
  3776 -------------------------------------------------------------------------------
       
  3777 */ 
       
  3778 TInt CUIStore::FindByContainer( CUIEngineContainer* const aContainer,
       
  3779                                 CStartedTestCase*& aTestCase )
       
  3780     {
       
  3781     
       
  3782     TInt count = iStartedTestCases.Count();
       
  3783     TInt index = 0;
       
  3784     for( ; index < count; index++ )
       
  3785         {
       
  3786         if( ( iStartedTestCases[index]->Status() & 
       
  3787               CUIStoreIf::EStatusRunning ) &&
       
  3788             ( &iStartedTestCases[index]->UIEngineContainer() ==
       
  3789               aContainer ) )
       
  3790             {
       
  3791             aTestCase = iStartedTestCases[index];
       
  3792             return KErrNone;
       
  3793             }
       
  3794         }
       
  3795     
       
  3796     return KErrNotFound;
       
  3797     
       
  3798     }
       
  3799     
       
  3800 /*
       
  3801 -------------------------------------------------------------------------------
       
  3802 
       
  3803     Class: CUIStore
       
  3804 
       
  3805     Method: UpdateCases
       
  3806 
       
  3807     Description: Refreshs iTestCases array ie. fetches test cases from 
       
  3808                 test framework
       
  3809 
       
  3810     Parameters: None
       
  3811 
       
  3812     Return Values: None
       
  3813 
       
  3814     Errors/Exceptions: None
       
  3815 
       
  3816     Status: Draft
       
  3817 
       
  3818 -------------------------------------------------------------------------------
       
  3819 */
       
  3820 TInt CUIStore::UpdateCases()
       
  3821     {
       
  3822     
       
  3823     if( iUpdateNeeded )
       
  3824         {
       
  3825         TInt handle = iUIStoreIf->PopupMsg( 
       
  3826             _L("Updating"), _L("Test cases"), 60 );
       
  3827         iTestCases.ResetAndDestroy();
       
  3828         TRAPD( ret, 
       
  3829             ret = iUIEngine->GetTestCasesL( iTestCases );
       
  3830             );
       
  3831         iUpdateNeeded = EFalse;
       
  3832         // Close popup
       
  3833         iUIStoreIf->Close( handle );
       
  3834         if( iTestCases.Count() == 0 )
       
  3835             {
       
  3836             iUIStoreIf->PopupMsg( _L("No test cases found"), 
       
  3837                                   _L("e.g. check TestEngine log"), 
       
  3838                                   3 );
       
  3839             }
       
  3840         return ret;
       
  3841         }
       
  3842     
       
  3843     return KErrNone;
       
  3844             
       
  3845     }
       
  3846 
       
  3847 /*
       
  3848 -------------------------------------------------------------------------------
       
  3849 
       
  3850     Class: CUIStore
       
  3851 
       
  3852     Method: CheckIniL
       
  3853 
       
  3854     Description: Check ini file
       
  3855 
       
  3856     Parameters: None
       
  3857 
       
  3858     Return Values: None
       
  3859 
       
  3860     Errors/Exceptions: None
       
  3861 
       
  3862     Status: Draft
       
  3863 
       
  3864 -------------------------------------------------------------------------------
       
  3865 */
       
  3866 void CUIStore::CheckIniL( TFileName& aIni )
       
  3867     {
       
  3868     
       
  3869     RFs fs;
       
  3870     User::LeaveIfError( fs.Connect() );
       
  3871     RFile file;
       
  3872     TInt err = KErrNone;
       
  3873     TErrorNotification error;
       
  3874     error.iModule.Copy( KUIStore );
       
  3875 
       
  3876     TStifUtil::CorrectFilePathL( aIni );
       
  3877     
       
  3878     if ( aIni.Length() != 0 )
       
  3879         {
       
  3880         err = file.Open ( fs, aIni, EFileRead );
       
  3881 
       
  3882         if ( err == KErrNone )
       
  3883             {
       
  3884             // Use the file given as command line parameter
       
  3885             iUIStoreIf->PopupMsg( _L("Using given ini-file"), 
       
  3886                                   KNullDesC, 0 );
       
  3887             file.Close();
       
  3888             fs.Close(); 
       
  3889             return;
       
  3890             }
       
  3891         else
       
  3892             { 
       
  3893             error.iText.Copy( _L("Can't open given ini-file") );
       
  3894             iUIStoreIf->Error( error );  
       
  3895             aIni.Zero();       
       
  3896             }
       
  3897         }
       
  3898         
       
  3899     // Try to locate default ini file from every drive
       
  3900     TDriveList drivelist; 
       
  3901 	User::LeaveIfError( fs.DriveList(drivelist) );
       
  3902 	// A TDriveList (the list of available drives), is an array of 
       
  3903 	// 26 bytes. Each byte with a non zero value signifies that the 
       
  3904 	// corresponding drive is available.
       
  3905 
       
  3906     TInt driveNumber; 
       
  3907 	TChar driveLetter;
       
  3908 
       
  3909 	for( driveNumber=EDriveA; driveNumber<=EDriveZ; driveNumber++ )
       
  3910 		{
       
  3911 		if( !drivelist[driveNumber] ) 
       
  3912 			{
       
  3913 			// If drive-list entry is zero, drive is not available
       
  3914 			continue;
       
  3915 			}
       
  3916         User::LeaveIfError(
       
  3917             fs.DriveToChar( driveNumber, driveLetter ));
       
  3918         
       
  3919         aIni.Zero();
       
  3920         aIni.Append( driveLetter );
       
  3921         aIni.Append( _L(":") );
       
  3922         aIni.Append( KDefaultIni );
       
  3923 
       
  3924         // Try to open
       
  3925         err = file.Open ( fs, aIni, EFileRead );
       
  3926 
       
  3927         if ( err == KErrNone )
       
  3928             {
       
  3929             // Use default file
       
  3930             file.Close();
       
  3931             TFileName info( _L("Using default ini-file ") );
       
  3932             if( info.MaxLength()-info.Length() >  aIni.Length() )
       
  3933                 {
       
  3934                 // Show also filename if fits to descriptor
       
  3935                 info.Append( aIni );
       
  3936                 }
       
  3937             iUIStoreIf->PopupMsg( info, KNullDesC, 0 );
       
  3938             break;
       
  3939             }
       
  3940         }
       
  3941     if( err != KErrNone )
       
  3942         {
       
  3943         iUIStoreIf->PopupMsg( _L("Starting without ini-file"), 
       
  3944                               KNullDesC,  0);
       
  3945         aIni.Zero();            
       
  3946         }
       
  3947 
       
  3948     fs.Close();    
       
  3949 
       
  3950     }
       
  3951 
       
  3952 /*
       
  3953 -------------------------------------------------------------------------------
       
  3954 
       
  3955     Class: CUIStore
       
  3956 
       
  3957     Method: ParseTestSetName
       
  3958 
       
  3959     Description: Parses test set name from test set filename.
       
  3960 
       
  3961     Parameters: const TDesC& aSetFileName: in: Test set filename
       
  3962                 TPtrC& aSetName: out: testset name
       
  3963                 TFileName& aFileName: in: filenamebuffer
       
  3964 
       
  3965     Return Values: Symbian OS error code
       
  3966 
       
  3967     Errors/Exceptions: None
       
  3968 
       
  3969     Status: Draft
       
  3970 
       
  3971 -------------------------------------------------------------------------------
       
  3972 */
       
  3973 TInt CUIStore::ParseTestSetName( const TDesC& aSetFileName, 
       
  3974                                  TPtrC& aSetName,
       
  3975                                  TFileName& aFileName )
       
  3976     {
       
  3977     if( aSetFileName.Length() > KMaxFileName )
       
  3978         {
       
  3979         return KErrArgument;
       
  3980         }
       
  3981     
       
  3982     aFileName.Copy( aSetFileName );
       
  3983     TParsePtr p( aFileName );
       
  3984     aSetName.Set( p.NameAndExt() ); // gives test set name without path
       
  3985     
       
  3986     if( aSetName.Length() > KMaxName )
       
  3987         {
       
  3988         return KErrArgument;
       
  3989         }
       
  3990     
       
  3991     return KErrNone;
       
  3992     
       
  3993     }
       
  3994 
       
  3995 /*
       
  3996 -------------------------------------------------------------------------------
       
  3997 
       
  3998     Class: CUIStore
       
  3999 
       
  4000     Method: RemotePopup
       
  4001 
       
  4002     Description: Do remote message popup 
       
  4003 
       
  4004     Parameters: const TDesC& aReq: in: request
       
  4005 
       
  4006     Return Values: Symbian OS error code
       
  4007 
       
  4008     Errors/Exceptions: None
       
  4009 
       
  4010     Status: Draft
       
  4011 
       
  4012 -------------------------------------------------------------------------------
       
  4013 */
       
  4014 TInt CUIStore::RemotePopup( CUIEngineContainer* aContainer,
       
  4015                             const TDesC& aMsg, 
       
  4016                             CStifTFwIfProt* aResp,
       
  4017                             TPopupPriority aPopupPriority )
       
  4018     {
       
  4019     TInt ret = KErrNone;
       
  4020     
       
  4021     CUIStorePopup* popup = NULL;
       
  4022     TRAP( ret, popup = CUIStorePopup::NewL( this, aContainer, aResp, aPopupPriority, aMsg ); );
       
  4023     if( ret != KErrNone )
       
  4024         {
       
  4025         return ret;
       
  4026         }
       
  4027     ret = iPopups.Append( popup );
       
  4028     if( ret != KErrNone )
       
  4029         {
       
  4030         delete popup;
       
  4031         return ret;
       
  4032         }
       
  4033                 
       
  4034     // We'll put new popup to the top if there are no popups active or if
       
  4035     // currently active popup has lower priority than the new one               
       
  4036     if( !iPopupActive || iActivePopupPriority > popup->GetPriority() ) 
       
  4037         {       
       
  4038         SetRemotePopupFromQueue();
       
  4039         }
       
  4040 
       
  4041     return ret;
       
  4042     }
       
  4043 
       
  4044 /*
       
  4045 -------------------------------------------------------------------------------
       
  4046 
       
  4047     Class: CUIStore
       
  4048 
       
  4049     Method: SetRemotePopupFromQueue
       
  4050 
       
  4051     Description: Prints the highest priority popup to the UI from the popup 
       
  4052     queue
       
  4053 
       
  4054     Parameters: None
       
  4055 
       
  4056     Return Values: None
       
  4057 
       
  4058     Errors/Exceptions: None
       
  4059 
       
  4060     Status: Draft @js
       
  4061 
       
  4062 -------------------------------------------------------------------------------
       
  4063 */
       
  4064 
       
  4065 void CUIStore::SetRemotePopupFromQueue()
       
  4066     {
       
  4067     CUIStorePopup* popup = NULL;
       
  4068     
       
  4069     if(iPopups.Count() > 0 )
       
  4070         {        
       
  4071         TInt highest = 0;
       
  4072         
       
  4073         // Let's get the highest priority popup and print it to the UI
       
  4074         for( TInt x=0; x<iPopups.Count(); x++)
       
  4075             {            
       
  4076             if( iPopups[x]->GetPriority() < iPopups[highest]->GetPriority() )    
       
  4077                 {
       
  4078                 highest = x;
       
  4079                 }
       
  4080             }
       
  4081         
       
  4082         popup = iPopups[highest];
       
  4083         
       
  4084         if( popup == NULL )
       
  4085             {
       
  4086             // Some weird error
       
  4087             iPopupActive = EFalse;
       
  4088             return;        
       
  4089             }
       
  4090         
       
  4091         // Change the active popup priority        
       
  4092         iActivePopupPriority = popup->GetPriority();             
       
  4093                 
       
  4094         // Create proper popup        
       
  4095         if( popup->GetPriority() == EPopupPriorityHighest )
       
  4096             {                                 
       
  4097             popup->Start( popup->GetMessage().Right( popup->GetMessage().Length() - KRcpHeaderLen ),
       
  4098                 _L("Press any key to send 'remote run started' message"));                                  
       
  4099             }
       
  4100         else if( popup->GetPriority() == EPopupPriorityNormal )
       
  4101             {
       
  4102             popup->Start( popup->GetMessage().Right( popup->GetMessage().Length() - KRcpHeaderLen ),
       
  4103                 _L("Press any key to set event") );        
       
  4104             }
       
  4105         else if( popup->GetPriority() == EPopupPriorityLow )
       
  4106             {           
       
  4107             popup->Start( popup->GetMessage().Right( popup->GetMessage().Length() - KRcpHeaderLen ),
       
  4108                 _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") );                                    
       
  4109             }
       
  4110             
       
  4111         iPopupActive = ETrue;                                
       
  4112         }
       
  4113     }
       
  4114 /*
       
  4115 -------------------------------------------------------------------------------
       
  4116 
       
  4117     Class: CUIStore
       
  4118 
       
  4119     Method: ShuffleRemoteRunResultPopups
       
  4120 
       
  4121     Description: Shuffle remote run result popups 
       
  4122 
       
  4123     Parameters: CUIStorePopup* aPopup (currently active popup)
       
  4124 
       
  4125     Return Values: None
       
  4126 
       
  4127     Errors/Exceptions: None
       
  4128 
       
  4129     Status: Draft @js
       
  4130 
       
  4131 -------------------------------------------------------------------------------
       
  4132 */
       
  4133 void CUIStore::ShuffleRemoteRunResultPopups( CUIStorePopup* aPopup )
       
  4134     {    
       
  4135     TInt nextPopupId = -1;
       
  4136     
       
  4137     for( TInt x=0; x<iPopups.Count(); x++)
       
  4138         {            
       
  4139         // Lets find the next remote run result priority popup
       
  4140         if( iPopups[x]->GetPriority() == EPopupPriorityLow && iPopups[x] != aPopup )    
       
  4141             {
       
  4142             nextPopupId = x;
       
  4143             break;
       
  4144             }
       
  4145         }
       
  4146     
       
  4147     if( nextPopupId == -1 )            
       
  4148         {
       
  4149         // We'll print error message popup, because there weren't any other remote run 
       
  4150         // result popups active
       
  4151 
       
  4152         iUIStoreIf->PopupMsg( 
       
  4153             _L("Error! There weren't any other remote run result popups active."), 
       
  4154             _L(""), 
       
  4155             5 );        
       
  4156         User::After( 5000000 );
       
  4157         iPopups.Append( aPopup );
       
  4158         SetRemotePopupFromQueue();
       
  4159         return;
       
  4160         }
       
  4161 
       
  4162     // We'll add the popup to the end of the array    
       
  4163     TInt ret = iPopups.Append( aPopup );
       
  4164         
       
  4165     if( ret != KErrNone )
       
  4166         {
       
  4167         delete aPopup;
       
  4168         return;
       
  4169         }
       
  4170         
       
  4171     // Print the next popup from queue
       
  4172     SetRemotePopupFromQueue();
       
  4173     }
       
  4174 
       
  4175 /*
       
  4176 -------------------------------------------------------------------------------
       
  4177 
       
  4178     Class: CUIStore
       
  4179 
       
  4180     Method: RemotePopup
       
  4181 
       
  4182     Description: Do remote message popup 
       
  4183 
       
  4184     Parameters: const TDesC& aReq: in: request
       
  4185 
       
  4186     Return Values: Symbian OS error code
       
  4187 
       
  4188     Errors/Exceptions: None
       
  4189 
       
  4190     Status: Draft
       
  4191 
       
  4192 -------------------------------------------------------------------------------
       
  4193 */
       
  4194 TInt CUIStore::RemotePopupComplete( CUIStorePopup* aPopup, 
       
  4195                                     TInt aError,
       
  4196                                     CUIEngineContainer* aContainer,
       
  4197                                     CStifTFwIfProt* aResp,
       
  4198                                     TKeyCode aKeyCode )
       
  4199     {
       
  4200     
       
  4201     TInt ret = KErrNone;
       
  4202     TInt index = iPopups.Find( aPopup );
       
  4203     if( index < 0 )
       
  4204         {
       
  4205         User::Panic( KUIStore, KErrGeneral );
       
  4206         }
       
  4207     iPopups.Remove( index );   
       
  4208 
       
  4209     iPopupActive = EFalse;
       
  4210     iActivePopupPriority = EPopupPriorityLow;
       
  4211 
       
  4212     if( aError != KErrNone )
       
  4213         {
       
  4214         ret = aError;
       
  4215         }
       
  4216     else
       
  4217         {
       
  4218         TChar c( aKeyCode );
       
  4219         if( c.IsDigit() )
       
  4220             {
       
  4221             // Solve return value
       
  4222             ret = -( aKeyCode - '0' );
       
  4223             }
       
  4224         else
       
  4225             {
       
  4226             ret = KErrNone;
       
  4227             }
       
  4228         }
       
  4229     // If aResp is given, send it
       
  4230     if( aResp )
       
  4231         {     
       
  4232         switch( aResp->iCmdType )
       
  4233             {
       
  4234             case CStifTFwIfProt::ECmdRun:
       
  4235                 {
       
  4236                 TChar response( aKeyCode );  
       
  4237                 RDebug::Print(_L("CUIStore::RemotePopupComplete: user pressed key %c"), (char)response);
       
  4238                   
       
  4239                 if( aPopup->GetPriority() == EPopupPriorityHighest )
       
  4240                     {                                        
       
  4241                     // User has given response to remote run started- popup
       
  4242                     aResp->Append( CStifTFwIfProt::RunStatus, 
       
  4243                       CStifTFwIfProt::ERunStarted );                      
       
  4244                     }                
       
  4245                 else if( aPopup->GetPriority() == EPopupPriorityLow &&  response=='a' )
       
  4246                     {                                        
       
  4247                     // User wants to change current remote run result popup to other
       
  4248                     // remote run result popup. 
       
  4249                     
       
  4250                     ShuffleRemoteRunResultPopups( aPopup );                             
       
  4251                     return KErrNone;
       
  4252                     }
       
  4253                 else 
       
  4254                     {                                    
       
  4255                     // The test case result was given
       
  4256                     aResp->Append( CStifTFwIfProt::RunStatus, 
       
  4257                                CStifTFwIfProt::ERunReady );
       
  4258                     if( ret != KErrNone )
       
  4259                         {
       
  4260                         aResp->Append( CStifTFwIfProt::RunStatusParams, 
       
  4261                                        CStifTFwIfProt::ERunResult, ret );
       
  4262                         }                   
       
  4263                     }
       
  4264                 break;
       
  4265                 }
       
  4266             case CStifTFwIfProt::ECmdSendReceive:
       
  4267                 {
       
  4268                 aResp->Append( CStifTFwIfProt::RunStatus, 
       
  4269                                CStifTFwIfProt::ERunReady );
       
  4270                 if( ret != KErrNone )
       
  4271                     {
       
  4272                     aResp->Append( CStifTFwIfProt::RunStatusParams, 
       
  4273                                    CStifTFwIfProt::ERunResult, ret );
       
  4274                     }
       
  4275                 break;
       
  4276                 }
       
  4277             case CStifTFwIfProt::ECmdPause:
       
  4278             case CStifTFwIfProt::ECmdResume:
       
  4279             case CStifTFwIfProt::ECmdCancel:
       
  4280             case CStifTFwIfProt::ECmdRequest:
       
  4281             case CStifTFwIfProt::ECmdRelease:
       
  4282             default:
       
  4283                 if( ret != KErrNone )
       
  4284                     {
       
  4285                     aResp->Append( CStifTFwIfProt::RespParam, 
       
  4286                                    CStifTFwIfProt::ERespResult, 
       
  4287                                    ret );
       
  4288                     }
       
  4289                 break;
       
  4290             }
       
  4291         
       
  4292         ret = aContainer->RemoteReceive( aResp->Message() ); 
       
  4293         }
       
  4294                 
       
  4295     delete aPopup;      
       
  4296     
       
  4297     SetRemotePopupFromQueue();
       
  4298     
       
  4299     return ret;
       
  4300               
       
  4301     }
       
  4302 
       
  4303 /*
       
  4304 -------------------------------------------------------------------------------
       
  4305 
       
  4306     Class: CUIStore
       
  4307 
       
  4308     Method: ReadFiltersL
       
  4309 
       
  4310     Description: Reads filters from test framework initialization file.
       
  4311         
       
  4312     Parameters: RPointerArray<TDesC>& aFilters: array to be filled
       
  4313 
       
  4314     Return Values: None
       
  4315 
       
  4316     Errors/Exceptions: 
       
  4317 
       
  4318     Status: Draft
       
  4319 
       
  4320 -------------------------------------------------------------------------------
       
  4321 */
       
  4322 EXPORT_C void CUIStore::ReadFiltersL(RPointerArray<TDesC>& aFilters)
       
  4323     {
       
  4324     // Clean array
       
  4325     aFilters.ResetAndDestroy();
       
  4326     
       
  4327     // Locate file
       
  4328     _LIT(KFilterSectionStart, "[Filters]");
       
  4329     _LIT(KFilterSectionEnd, "[End_Filters]");
       
  4330     _LIT(KFilterDefinition, "filter=");
       
  4331 
       
  4332     // Parse initialization file
       
  4333     TInt err = KErrNone;
       
  4334     CStifParser* parser;
       
  4335     
       
  4336     RDebug::Print(_L("STIF: Try to read filters from [%S]"), &iTestFrameworkIni);
       
  4337     parser = CStifParser::NewL(KNullDesC, iTestFrameworkIni);
       
  4338     CleanupStack::PushL(parser);
       
  4339 
       
  4340     // Parser created (file exists), create section parser
       
  4341     CStifSectionParser* section;
       
  4342     section = parser->SectionL(KFilterSectionStart, KFilterSectionEnd);
       
  4343     if(section)
       
  4344         {
       
  4345         CleanupStack::PushL(section);
       
  4346             
       
  4347         // Get item lines
       
  4348         CStifItemParser* item = section->GetItemLineL(KFilterDefinition, ENoTag);
       
  4349             
       
  4350         TPtrC ptr;
       
  4351             
       
  4352         while(item)
       
  4353             {
       
  4354             CleanupStack::PushL(item);
       
  4355                 
       
  4356             // Read filter value
       
  4357             err = item->GetString(KNullDesC, ptr);
       
  4358             if(err == KErrNone)
       
  4359                 {
       
  4360                 HBufC* filter = ptr.AllocLC();
       
  4361                 User::LeaveIfError(aFilters.Append(filter));
       
  4362                 CleanupStack::Pop();
       
  4363                 }
       
  4364                 
       
  4365             CleanupStack::PopAndDestroy(item);
       
  4366             item = NULL;
       
  4367             item = section->GetNextItemLineL(KFilterDefinition, ENoTag);
       
  4368             }
       
  4369             
       
  4370         CleanupStack::PopAndDestroy(section);
       
  4371         }
       
  4372         
       
  4373     // Clean
       
  4374     CleanupStack::PopAndDestroy(parser);
       
  4375 
       
  4376     // If there are some filters added, first filter has to be "No filter"
       
  4377     if(aFilters.Count() > 0)
       
  4378         {
       
  4379         RDebug::Print(_L("STIF: Filters loaded"));
       
  4380         _LIT(KNoFilter, "No filter");
       
  4381         HBufC* name = KNoFilter().AllocLC();
       
  4382         User::LeaveIfError(aFilters.Insert(name, 0));
       
  4383         CleanupStack::Pop(name);    
       
  4384         }
       
  4385     }
       
  4386 
       
  4387 /*
       
  4388 -------------------------------------------------------------------------------
       
  4389 
       
  4390     DESCRIPTION
       
  4391 
       
  4392     This module contains implementation of CUIStoreIf class member functions.
       
  4393 
       
  4394 -------------------------------------------------------------------------------
       
  4395 */
       
  4396 
       
  4397 // ================= MEMBER FUNCTIONS =========================================
       
  4398 
       
  4399 /*
       
  4400 -------------------------------------------------------------------------------
       
  4401 
       
  4402     Class: CUIStoreIf
       
  4403 
       
  4404     Method: ConstructL
       
  4405 
       
  4406     Description: Second phase constructor.
       
  4407 
       
  4408     Parameters: None
       
  4409 
       
  4410     Return Values: None
       
  4411 
       
  4412     Errors/Exceptions: Leaves if..
       
  4413 
       
  4414     Status: Draft
       
  4415 
       
  4416 -------------------------------------------------------------------------------
       
  4417 */
       
  4418 EXPORT_C void CUIStoreIf::ConstructL( )
       
  4419     {
       
  4420     
       
  4421     iUIStore = CUIStore::NewL( this );
       
  4422     
       
  4423     }
       
  4424 
       
  4425 
       
  4426 /*
       
  4427 -------------------------------------------------------------------------------
       
  4428 
       
  4429     Class: CUIStoreIf
       
  4430 
       
  4431     Method: CUIStoreIf
       
  4432 
       
  4433     Description: Constructor.
       
  4434     
       
  4435     Parameters: None
       
  4436 
       
  4437     Return Values: None
       
  4438 
       
  4439     Errors/Exceptions: None
       
  4440 
       
  4441     Status: Draft
       
  4442 
       
  4443 -------------------------------------------------------------------------------
       
  4444 */
       
  4445 EXPORT_C CUIStoreIf::CUIStoreIf( )
       
  4446     {
       
  4447     }
       
  4448 
       
  4449 
       
  4450 /*
       
  4451 -------------------------------------------------------------------------------
       
  4452 
       
  4453     Class: CUIStoreIf
       
  4454 
       
  4455     Method: ~CUIStoreIf
       
  4456 
       
  4457     Description: Destructor
       
  4458 
       
  4459     Parameters: None
       
  4460 
       
  4461     Return Values: None
       
  4462 
       
  4463     Errors/Exceptions: None
       
  4464 
       
  4465     Status: Draft
       
  4466 
       
  4467 -------------------------------------------------------------------------------
       
  4468 */
       
  4469 EXPORT_C CUIStoreIf::~CUIStoreIf()
       
  4470     {	
       
  4471     
       
  4472     delete iUIStore;
       
  4473     iUIStore = NULL;
       
  4474     
       
  4475     }
       
  4476 
       
  4477 
       
  4478 /*
       
  4479 -------------------------------------------------------------------------------
       
  4480 
       
  4481     Class: CUIStoreIf
       
  4482 
       
  4483     Method: UIStore
       
  4484 
       
  4485     Description: Returns reference to CUIStore object, which handles test 
       
  4486                  cases and test modules.
       
  4487         
       
  4488     Parameters: None
       
  4489 
       
  4490     Return Values: CUIStore reference
       
  4491 
       
  4492     Errors/Exceptions: None
       
  4493 
       
  4494     Status: Draft
       
  4495 
       
  4496 -------------------------------------------------------------------------------
       
  4497 */
       
  4498 EXPORT_C CUIStore& CUIStoreIf::UIStore()
       
  4499     {
       
  4500     
       
  4501     __ASSERT_ALWAYS( iUIStore, User::Panic( KUIStoreIf, KErrNotFound ) );
       
  4502         
       
  4503     return *iUIStore;
       
  4504         
       
  4505     }
       
  4506 
       
  4507 /*
       
  4508 -------------------------------------------------------------------------------
       
  4509 
       
  4510     DESCRIPTION
       
  4511 
       
  4512     This module contains implementation of CTestSetInfo class member functions.
       
  4513 
       
  4514 -------------------------------------------------------------------------------
       
  4515 */
       
  4516 
       
  4517 // ================= MEMBER FUNCTIONS =========================================
       
  4518 
       
  4519 /*
       
  4520 -------------------------------------------------------------------------------
       
  4521 
       
  4522     Class: CTestSetInfo
       
  4523 
       
  4524     Method: NewL
       
  4525 
       
  4526     Description: Construct the CTestSetInfo class
       
  4527 
       
  4528     Parameters: None
       
  4529 
       
  4530     Return Values: CTestSetInfo*                    New object
       
  4531 
       
  4532     Errors/Exceptions: Leaves if memory allocation fails or
       
  4533                        ConstructL leaves.
       
  4534 
       
  4535     Status: Draft
       
  4536 
       
  4537 -------------------------------------------------------------------------------
       
  4538 */
       
  4539 CTestSetInfo* CTestSetInfo::NewL( const TDesC& aName )
       
  4540     {
       
  4541     
       
  4542     CTestSetInfo* self = new ( ELeave ) CTestSetInfo();
       
  4543     CleanupStack::PushL( self );
       
  4544     self->ConstructL( aName );
       
  4545     CleanupStack::Pop( self );
       
  4546 
       
  4547     return self;
       
  4548 
       
  4549     }
       
  4550             
       
  4551 /*
       
  4552 -------------------------------------------------------------------------------
       
  4553 
       
  4554     Class: CTestSetInfo
       
  4555 
       
  4556     Method: ConstructL
       
  4557 
       
  4558     Description: Second phase constructor.
       
  4559 
       
  4560     Parameters: None
       
  4561 
       
  4562     Return Values: None
       
  4563 
       
  4564     Errors/Exceptions: Leaves if..
       
  4565 
       
  4566     Status: Draft
       
  4567 
       
  4568 -------------------------------------------------------------------------------
       
  4569 */
       
  4570 void CTestSetInfo::ConstructL( const TDesC& aName )
       
  4571     {
       
  4572     
       
  4573     iName = aName.AllocL();
       
  4574     
       
  4575     }
       
  4576 
       
  4577 
       
  4578 /*
       
  4579 -------------------------------------------------------------------------------
       
  4580 
       
  4581     Class: CTestSetInfo
       
  4582 
       
  4583     Method: CTestSetInfo
       
  4584 
       
  4585     Description: Constructor.
       
  4586     
       
  4587     Parameters: None
       
  4588 
       
  4589     Return Values: None
       
  4590 
       
  4591     Errors/Exceptions: None
       
  4592 
       
  4593     Status: Draft
       
  4594 
       
  4595 -------------------------------------------------------------------------------
       
  4596 */
       
  4597 CTestSetInfo::CTestSetInfo()
       
  4598     {
       
  4599     iLastStartedCaseIndex = 0;
       
  4600     }
       
  4601 
       
  4602 
       
  4603 /*
       
  4604 -------------------------------------------------------------------------------
       
  4605 
       
  4606     Class: CTestSetInfo
       
  4607 
       
  4608     Method: ~CTestSetInfo
       
  4609 
       
  4610     Description: Destructor
       
  4611 
       
  4612     Parameters: None
       
  4613 
       
  4614     Return Values: None
       
  4615 
       
  4616     Errors/Exceptions: None
       
  4617 
       
  4618     Status: Draft
       
  4619 
       
  4620 -------------------------------------------------------------------------------
       
  4621 */
       
  4622 CTestSetInfo::~CTestSetInfo()
       
  4623     {	
       
  4624     
       
  4625     iTestCases.ResetAndDestroy();
       
  4626     iTestCaseRefs.Reset();
       
  4627     iTestCases.Close();
       
  4628     iTestCaseRefs.Close();
       
  4629     
       
  4630     delete iName;
       
  4631     iName = NULL;
       
  4632     
       
  4633     }
       
  4634 /*
       
  4635 -------------------------------------------------------------------------------
       
  4636 
       
  4637     Class: CTestSetInfo
       
  4638 
       
  4639     Method: AddTestCase
       
  4640 
       
  4641     Description: Add test case to test set.
       
  4642         
       
  4643     Parameters: const CTestInfo& aTestInfo: in: test info
       
  4644 
       
  4645     Return Values: Symbian OS error code
       
  4646 
       
  4647     Errors/Exceptions: None
       
  4648 
       
  4649     Status: Draft
       
  4650 
       
  4651 -------------------------------------------------------------------------------
       
  4652 */
       
  4653 TInt CTestSetInfo::AddTestCase( const CTestInfo& aTestInfo )
       
  4654     {
       
  4655     
       
  4656     CTestInfo* testInfo = NULL;
       
  4657     
       
  4658     TRAPD( err, 
       
  4659         testInfo = CTestInfo::NewL();
       
  4660         testInfo->CopyL( aTestInfo );
       
  4661         );
       
  4662     if( err != KErrNone )
       
  4663         {
       
  4664         return err;
       
  4665         }
       
  4666 
       
  4667     if( iTestCaseRefs.Append( *testInfo ) != KErrNone )
       
  4668         {
       
  4669         delete testInfo;
       
  4670         return KErrNoMemory;        
       
  4671         }
       
  4672     if( iTestCases.Append( testInfo ) != KErrNone ) 
       
  4673         {
       
  4674         iTestCaseRefs.Remove( iTestCaseRefs.Count()-1 );
       
  4675         delete testInfo;
       
  4676         return KErrNoMemory;
       
  4677         }
       
  4678 
       
  4679     return KErrNone;
       
  4680     
       
  4681     }
       
  4682 
       
  4683 /*
       
  4684 -------------------------------------------------------------------------------
       
  4685 
       
  4686     Class: CTestSetInfo
       
  4687 
       
  4688     Method: InsertTestCase
       
  4689 
       
  4690     Description: Insert test case to test set.
       
  4691         
       
  4692     Parameters: const CTestInfo& aTestInfo: in: test info
       
  4693                 TInt aPos: in: position to add
       
  4694 
       
  4695     Return Values: Symbian OS error code
       
  4696 
       
  4697     Errors/Exceptions: None
       
  4698 
       
  4699     Status: Draft
       
  4700 
       
  4701 -------------------------------------------------------------------------------
       
  4702 */
       
  4703 TInt CTestSetInfo::InsertTestCase( const CTestInfo& aTestInfo, TInt aPos )
       
  4704     {
       
  4705     
       
  4706     if( ( aPos < 0 ) ||
       
  4707         ( aPos >= iTestCases.Count() ) )
       
  4708         {
       
  4709         return KErrArgument;
       
  4710         }
       
  4711     
       
  4712     CTestInfo* testInfo = NULL;
       
  4713     
       
  4714     TRAPD( err, 
       
  4715         testInfo = CTestInfo::NewL();
       
  4716         testInfo->CopyL( aTestInfo );
       
  4717         );
       
  4718     if( err != KErrNone )
       
  4719         {
       
  4720         return err;
       
  4721         }
       
  4722      
       
  4723     if( iTestCaseRefs.Insert( *testInfo, aPos ) != KErrNone )
       
  4724         {
       
  4725         delete testInfo;
       
  4726         return KErrNoMemory;        
       
  4727         }
       
  4728     if( iTestCases.Insert( testInfo, aPos ) != KErrNone )
       
  4729         {
       
  4730         iTestCaseRefs.Remove( aPos );
       
  4731         delete testInfo;
       
  4732         return KErrNoMemory;
       
  4733         }
       
  4734     
       
  4735     return err;
       
  4736         
       
  4737     }
       
  4738         
       
  4739 /*
       
  4740 -------------------------------------------------------------------------------
       
  4741 
       
  4742     Class: CTestSetInfo
       
  4743 
       
  4744     Method: RemoveTestCase
       
  4745 
       
  4746     Description: Remove test case from test set.
       
  4747         
       
  4748     Parameters: const CTestInfo& aTestInfo: in: test info
       
  4749 
       
  4750     Return Values: Symbian OS error code
       
  4751 
       
  4752     Errors/Exceptions: None
       
  4753 
       
  4754     Status: Draft
       
  4755 
       
  4756 -------------------------------------------------------------------------------
       
  4757 */
       
  4758 TInt CTestSetInfo::RemoveTestCase( const CTestInfo& aTestInfo )
       
  4759     {
       
  4760     
       
  4761     TInt count = iTestCases.Count();
       
  4762     for( TInt i=0; i<count; i++ )
       
  4763         {
       
  4764         if( aTestInfo == *iTestCases[i] )
       
  4765             {
       
  4766             CTestInfo* testInfo = iTestCases[i];
       
  4767             iTestCases.Remove( i );
       
  4768             iTestCaseRefs.Remove( i );
       
  4769             delete testInfo;
       
  4770             return KErrNone;
       
  4771             }
       
  4772         }
       
  4773 
       
  4774     return KErrNotFound;
       
  4775     
       
  4776     }
       
  4777     
       
  4778 /*
       
  4779 -------------------------------------------------------------------------------
       
  4780 
       
  4781     Class: CTestSetInfo
       
  4782 
       
  4783     Method: CopyL
       
  4784 
       
  4785     Description: Remove test case from test set.
       
  4786         
       
  4787     Parameters: const CTestInfo& aTestInfo: in: test info
       
  4788 
       
  4789     Return Values: Symbian OS error code
       
  4790 
       
  4791     Errors/Exceptions: None
       
  4792 
       
  4793     Status: Draft
       
  4794 
       
  4795 -------------------------------------------------------------------------------
       
  4796 */
       
  4797 void CTestSetInfo::CopyL( const CTestSetInfo& aTestSetInfo )
       
  4798     {
       
  4799     
       
  4800     iTestCaseRefs.Reset();
       
  4801     iTestCases.ResetAndDestroy();
       
  4802     
       
  4803     TInt count = aTestSetInfo.TestCases().Count();
       
  4804     for( TInt i=0; i<count; i++ )
       
  4805         {
       
  4806         User::LeaveIfError( AddTestCase( aTestSetInfo.TestCases()[i] ) );
       
  4807         }
       
  4808     
       
  4809     delete iName;
       
  4810     iName = 0;    
       
  4811     iName = aTestSetInfo.Name().AllocL(); 
       
  4812     
       
  4813     iLastStartedCaseIndex = aTestSetInfo.iLastStartedCaseIndex;
       
  4814          
       
  4815     }    
       
  4816 
       
  4817 /*
       
  4818 -------------------------------------------------------------------------------
       
  4819 
       
  4820     Class: CTestSetInfo
       
  4821 
       
  4822     Method: SetLastStartedCaseIndex
       
  4823 
       
  4824     Description: Sets the info which test case has been started lately.
       
  4825         
       
  4826     Parameters: TInt aCaseStarted: index of started test case
       
  4827 
       
  4828     Return Values: None
       
  4829 
       
  4830     Errors/Exceptions: None
       
  4831 
       
  4832     Status: Approved
       
  4833 
       
  4834 -------------------------------------------------------------------------------
       
  4835 */
       
  4836 void CTestSetInfo::SetLastStartedCaseIndex(TUint aLastStartedCaseIndex)
       
  4837     {
       
  4838     iLastStartedCaseIndex = aLastStartedCaseIndex;
       
  4839     }    
       
  4840 
       
  4841 /*
       
  4842 -------------------------------------------------------------------------------
       
  4843 
       
  4844     Class: CTestSetInfo
       
  4845 
       
  4846     Method: GetLastStartedCaseIndex
       
  4847 
       
  4848     Description: Gets the info which test case has been started lately.
       
  4849         
       
  4850     Parameters: None
       
  4851 
       
  4852     Return Values: TInt: index of lately started test case
       
  4853 
       
  4854     Errors/Exceptions: None
       
  4855 
       
  4856     Status: Approved
       
  4857 
       
  4858 -------------------------------------------------------------------------------
       
  4859 */
       
  4860 TUint CTestSetInfo::GetLastStartedCaseIndex(void)
       
  4861     {
       
  4862     return iLastStartedCaseIndex;
       
  4863     }    
       
  4864 
       
  4865 // ================= OTHER EXPORTED FUNCTIONS =================================
       
  4866 
       
  4867 // End of File