testexecfw/stf/stfui/atsui/src/ATSInterface.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: CATSInterface: This object executes test cases from 
       
    15 * STIF Test Framework.
       
    16 *
       
    17 */
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <e32base.h>
       
    21 #include <e32cons.h>
       
    22 #include <e32svr.h>
       
    23 #include "ATSInterface.h"
       
    24 #include "ATSInterfaceRunner.h"
       
    25 
       
    26 #include "StifTestInterface.h"
       
    27 
       
    28 
       
    29 // EXTERNAL DATA STRUCTURES
       
    30 // None
       
    31 
       
    32 // EXTERNAL FUNCTION PROTOTYPES  
       
    33 // None
       
    34 
       
    35 // CONSTANTS
       
    36 // None
       
    37 
       
    38 // MACROS
       
    39 // None
       
    40 
       
    41 // LOCAL CONSTANTS AND MACROS
       
    42 // None
       
    43 
       
    44 // MODULE DATA STRUCTURES
       
    45 // None
       
    46 
       
    47 // LOCAL FUNCTION PROTOTYPES
       
    48 // None
       
    49 
       
    50 // FORWARD DECLARATIONS
       
    51 // None
       
    52 
       
    53 // ==================== LOCAL FUNCTIONS ======================================= 
       
    54 // None
       
    55 
       
    56 // ================= MEMBER FUNCTIONS ========================================= 
       
    57 
       
    58 
       
    59 // ================= MEMBER FUNCTIONS =========================================
       
    60 
       
    61 
       
    62 /*
       
    63 -------------------------------------------------------------------------------
       
    64 
       
    65     Class: CATSInterface
       
    66 
       
    67     Method: CATSInterface
       
    68 
       
    69     Description: Default constructor
       
    70 
       
    71     C++ default constructor can NOT contain any code, that
       
    72     might leave.
       
    73     
       
    74     Parameters: None
       
    75     
       
    76     Return Values: None
       
    77 
       
    78     Errors/Exceptions: None
       
    79 
       
    80     Status: Approved
       
    81     
       
    82 -------------------------------------------------------------------------------
       
    83 */
       
    84 CATSInterface::CATSInterface()
       
    85     {
       
    86     // Initialize buffers to zero
       
    87     iEngineIniFile.Zero();
       
    88     iModuleIniFile.Zero();
       
    89     iConfigFile.Zero();
       
    90     iTestModule.Zero();
       
    91 
       
    92     }
       
    93 
       
    94 
       
    95 /*
       
    96 -------------------------------------------------------------------------------
       
    97 
       
    98     Class: CATSInterface
       
    99 
       
   100     Method: ConstructL
       
   101 
       
   102     Description: Symbian OS second phase constructor
       
   103 
       
   104     Symbian OS default constructor can leave.
       
   105     
       
   106     Parameters: None
       
   107 
       
   108     Return Values: None
       
   109 
       
   110     Errors/Exceptions: Leaves if some of called leaving functions leaves
       
   111                        Leaves each time the LogErrorAndLeaveL is called
       
   112 
       
   113     Status: Proposal
       
   114     
       
   115 -------------------------------------------------------------------------------
       
   116 */
       
   117 void CATSInterface::ConstructL()
       
   118     {
       
   119     RDebug::Print(_L("Creating module list object"));
       
   120     TRAPD(err, iModuleList = CTestModuleList::NewL(NULL));
       
   121     if(err != KErrNone)
       
   122         {
       
   123         LogErrorAndLeaveL(_L("CATSInterface::ConstructL"), _L("CTestModuleList::NewL"), err);
       
   124         return;
       
   125         }
       
   126     if(!iModuleList)
       
   127         {
       
   128         LogErrorAndLeaveL(_L("CATSInterface::ConstructL"), _L("CTestModuleList::NewL - iModuleList is NULL"), KErrGeneral);
       
   129         return;
       
   130         }
       
   131 
       
   132     // Read command line
       
   133     ParseCommandLineL();
       
   134 
       
   135     // Add to module list info about module taken from command line
       
   136     RDebug::Print(_L("Adding command line module to list"));
       
   137     TName moduleName;
       
   138     moduleName.Copy(iTestModule);
       
   139     moduleName.LowerCase();
       
   140     err = iModuleList->AddTestModule(moduleName);
       
   141     if(err != KErrNone && err != KErrAlreadyExists)
       
   142         {
       
   143         LogErrorAndLeaveL(_L("CATSInterface::ConstructL"), _L("CTestModuleList::AddTestModule - Could not add module to list of modules"), err);
       
   144         return;
       
   145         }
       
   146 
       
   147     //Get added module
       
   148     CTestModuleInfo* moduleInfo = iModuleList->GetModule(moduleName);
       
   149     if(!moduleInfo)
       
   150         {
       
   151         LogErrorAndLeaveL(_L("CATSInterface::ConstructL"), _L("CTestModuleList::GetModule - Could not add get module info from list"), KErrGeneral);
       
   152         return;
       
   153         }
       
   154 
       
   155     //Add ini file if given
       
   156     if(iModuleIniFile.Length() > 0)
       
   157         {
       
   158         TFileName filename;
       
   159         filename.Copy(iModuleIniFile);
       
   160         filename.LowerCase();
       
   161         moduleInfo->SetIniFile(filename);
       
   162         }
       
   163 
       
   164     //Add config file if given
       
   165     if(iConfigFile.Length() > 0)
       
   166         {
       
   167         TFileName filename;
       
   168         filename.Copy(iConfigFile);
       
   169         filename.LowerCase();
       
   170         moduleInfo->AddCfgFile(filename);
       
   171         }
       
   172 
       
   173     //Now check all config files if there are included modules
       
   174     _LIT(KIncludeModuleStart, "[New_Include_Module]");
       
   175     _LIT(KIncludeModuleEnd, "[End_Include_Module]");
       
   176 
       
   177     RDebug::Print(_L("Start parsing included modules"));
       
   178     CTestCaseFileInfo* finfo = iModuleList->GetUncheckedCfgFile();
       
   179     while(finfo)
       
   180         {
       
   181         TFileName fname;
       
   182         finfo->GetCfgFileName(fname);
       
   183 
       
   184         RDebug::Print(_L("Checking file: '%S'"), &fname);
       
   185         finfo->SetChecked();
       
   186 
       
   187         CStifParser* parser = NULL;
       
   188 
       
   189         TRAP(err, parser = CStifParser::NewL(_L(""), fname));
       
   190         if(err != KErrNone)
       
   191             {
       
   192             LogErrorAndLeaveL(_L("CATSInterface::ConstructL"), _L("CStifParser::NewL - Could not create parser"), err);
       
   193             return;
       
   194             }
       
   195         CleanupStack::PushL(parser);
       
   196 
       
   197         ParseTestModulesL(parser, iModuleList, KIncludeModuleStart, KIncludeModuleEnd);
       
   198 
       
   199         CleanupStack::PopAndDestroy(parser);
       
   200         finfo = iModuleList->GetUncheckedCfgFile();
       
   201         }
       
   202     RDebug::Print(_L("End parsing included modules"));
       
   203 
       
   204     // Create Test Engine
       
   205     RDebug::Print(_L("Creating test engine"));
       
   206     TInt ret = iTestEngine.Connect();
       
   207     if ( ret != KErrNone )
       
   208         {
       
   209         // Log error
       
   210         LogErrorAndLeaveL( _L("CATSInterface::ConstructL"), _L("iTestEngineServ.Connect"), ret );
       
   211         return;
       
   212         }
       
   213 
       
   214     ret = iTestEngine.LoadConfiguration( iEngineIniFile );
       
   215     if ( ret != KErrNone )
       
   216         {
       
   217         // Log error
       
   218         LogErrorAndLeaveL( _L("CATSInterface::ConstructL"), _L("iTestEngine.Open"), ret );
       
   219         return;
       
   220         }
       
   221 
       
   222 /*
       
   223     // Add test module
       
   224     ret = iTestEngine.AddTestModule( iTestModule, iModuleIniFile );
       
   225     if ( ret != KErrNone && ret != KErrAlreadyExists )
       
   226         {
       
   227         // Log error
       
   228         LogErrorAndLeaveL( _L("CATSInterface::ConstructL"), _L("iTestEngine.AddTestModule"), ret );
       
   229         return;
       
   230         }
       
   231 */
       
   232     // Add all test modules and config files
       
   233     RDebug::Print(_L("Start creating test modules"));
       
   234     moduleInfo = NULL;
       
   235     TInt i;
       
   236     TInt modCnt = iModuleList->Count();
       
   237 
       
   238     for(i = 0; i < modCnt; i++)
       
   239         {
       
   240         RDebug::Print(_L("Processing module"));
       
   241         // Get module
       
   242         moduleInfo = iModuleList->GetModule(i);
       
   243         if(!moduleInfo)
       
   244             {
       
   245             RDebug::Print(_L("Could not get module info at index %d"), i);
       
   246             continue;
       
   247             }
       
   248 
       
   249         // Get module name
       
   250         TName moduleName;
       
   251         moduleInfo->GetModuleName(moduleName);
       
   252         RDebug::Print(_L("module name: '%S'"), &moduleName);
       
   253 
       
   254         // Get ini file, if exists
       
   255         TFileName ini;
       
   256         moduleInfo->GetIniFileName(ini);
       
   257         if(ini.Length() == 0)
       
   258             {
       
   259             RDebug::Print(_L("ini file not found"));
       
   260             }
       
   261         else
       
   262             {
       
   263             RDebug::Print(_L("ini file: '%S'"), &ini);
       
   264             }
       
   265 
       
   266         // Create test module
       
   267         RDebug::Print(_L("Adding module to test engine"));
       
   268         ret = iTestEngine.AddTestModule(moduleName, ini);
       
   269         if(ret != KErrNone && ret != KErrAlreadyExists)
       
   270             {
       
   271             LogErrorAndLeaveL(_L("CATSInterface::ConstructL"), _L("iTestEngine.AddTestModule"), ret);
       
   272             return;
       
   273             }
       
   274 
       
   275         //Add test case files
       
   276         TInt cfgCnt = moduleInfo->CountCfgFiles();
       
   277         TInt j;
       
   278         TFileName cfgFile;
       
   279         for(j = 0; j < cfgCnt; j++)
       
   280             {
       
   281             moduleInfo->GetCfgFileName(j, cfgFile);
       
   282             if(cfgFile.Length() > 0)
       
   283                 {
       
   284                 RDebug::Print(_L("config file: '%S'"), &cfgFile);
       
   285 
       
   286                 ret = iTestEngine.AddConfigFile(moduleName, cfgFile);
       
   287                 if(ret != KErrNone && ret != KErrAlreadyExists)
       
   288                     {
       
   289                     // Log error
       
   290                     LogErrorAndLeaveL(_L("CATSInterface::ConstructL"), _L("RTestEngine::AddConfigFile"), ret);
       
   291                     return;
       
   292                     }
       
   293                 }
       
   294             else
       
   295                 {
       
   296                 RDebug::Print(_L("Got empty cfg file"));
       
   297                 }
       
   298             }
       
   299         if(cfgCnt == 0)
       
   300             {
       
   301             RDebug::Print(_L("cfg file not found"));
       
   302             }
       
   303 
       
   304         RDebug::Print(_L("Module '%S' processed correctly"), &moduleName);
       
   305         }
       
   306 
       
   307     RDebug::Print(_L("End creating test modules"));
       
   308 
       
   309     // Create console screen
       
   310     iConsole = Console::NewL(
       
   311         iTestModule, TSize( KConsFullScreen, KConsFullScreen ) );
       
   312     }
       
   313 
       
   314 
       
   315 /*
       
   316 -------------------------------------------------------------------------------
       
   317 
       
   318     Class: CATSInterface
       
   319 
       
   320     Method: NewL
       
   321 
       
   322     Description: Two-phased constructor.
       
   323 
       
   324     Parameters: None
       
   325 
       
   326     Return Values: CATSInterface* : pointer to created CATSInterface object
       
   327 
       
   328     Errors/Exceptions: Leaves if memory allocation for CATSInterface fails
       
   329                        Leaves if ConstructL leaves
       
   330 
       
   331     Status: Approved
       
   332     
       
   333 -------------------------------------------------------------------------------
       
   334 */
       
   335 CATSInterface* CATSInterface::NewL()
       
   336     {
       
   337     // Create CATSInterface and return it
       
   338     CATSInterface* self =  new ( ELeave ) CATSInterface();
       
   339     CleanupStack::PushL( self );
       
   340     self->ConstructL();
       
   341     CleanupStack::Pop();
       
   342     return self;
       
   343     }
       
   344 
       
   345 
       
   346 /*
       
   347 -------------------------------------------------------------------------------
       
   348 
       
   349     Class: CATSInterface
       
   350 
       
   351     Method: ~CATSInterface
       
   352 
       
   353     Description: Destructor
       
   354 
       
   355     Parameters: None
       
   356 
       
   357     Return Values: None
       
   358 
       
   359     Errors/Exceptions: None
       
   360 
       
   361     Status: Approved
       
   362 
       
   363 -------------------------------------------------------------------------------
       
   364 */
       
   365 CATSInterface::~CATSInterface()
       
   366     {
       
   367     // Close Test Engine
       
   368     iTestEngine.Close();
       
   369 
       
   370     delete iModuleList;
       
   371     delete iConsole;
       
   372 
       
   373     }
       
   374 
       
   375 /*
       
   376 -------------------------------------------------------------------------------
       
   377 
       
   378     Class: CATSInterface
       
   379 
       
   380     Method: ParseTestModulesL
       
   381 
       
   382     Description: Parse and search for module info and fill list of modules.
       
   383 
       
   384     Parameters: CStifParser*     aParser:       in: CStifParser object
       
   385                 CTestModuleList* aModuleList:   in: list of modules
       
   386                 TPtrC&           aSectionStart: in: descriptor with start of section string
       
   387                 TPTrC&           aSectionEnd:   in: descriptor with end of section string
       
   388 
       
   389     Return Values: None
       
   390 
       
   391     Errors/Exceptions: Leaves if some of called leaving methods leaves
       
   392 
       
   393     Status: Approved
       
   394 
       
   395 -------------------------------------------------------------------------------
       
   396 */
       
   397 void CATSInterface::ParseTestModulesL(CStifParser* aParser, CTestModuleList* aModuleList, const TDesC& aSectionStart, const TDesC& aSectionEnd)
       
   398     {
       
   399     //First let's find all modules given in Stif's ini file and store that info in CTestModuleList object
       
   400     CStifSectionParser* sectionParser = NULL;
       
   401     CStifItemParser* item = NULL;
       
   402 
       
   403     sectionParser = aParser->SectionL(aSectionStart, aSectionEnd);
       
   404 
       
   405     while(sectionParser)
       
   406         {
       
   407         RDebug::Print(_L("Found '%S' and '%S' sections"), &aSectionStart, &aSectionEnd);
       
   408         CleanupStack::PushL(sectionParser);
       
   409         RDebug::Print(_L("Starting to read module information"));
       
   410 
       
   411         // Get name of module
       
   412         _LIT(KModuleName, "ModuleName=");
       
   413         item = sectionParser->GetItemLineL(KModuleName);
       
   414         CleanupStack::PushL(item);
       
   415         if(!item)
       
   416             {
       
   417             CleanupStack::PopAndDestroy(item);
       
   418             LogErrorAndLeaveL(_L("CATSInterface::ParseTestModulesL"), _L("CStifItemParser::GetItemLineL - line not found from module section"), KErrNotFound);
       
   419             return;
       
   420             }
       
   421         else
       
   422             {
       
   423             RDebug::Print(_L("'%S' found"), &KModuleName);
       
   424             }
       
   425 
       
   426         TPtrC name;
       
   427         TName moduleName;
       
   428         TInt ret(KErrNone);
       
   429         ret = item->GetString(KModuleName, name);
       
   430         if(ret != KErrNone)
       
   431             {
       
   432             CleanupStack::PopAndDestroy(item);
       
   433             LogErrorAndLeaveL(_L("CATSInterface::ParseTestModulesL"), _L("CStifItemParser::GetString - Module name parsing left with error"), ret);
       
   434             return;
       
   435             }
       
   436         else
       
   437             {
       
   438             RDebug::Print(_L("Module '%S' found from ini-file"), &name);
       
   439             moduleName.Copy(name);
       
   440             moduleName.LowerCase();
       
   441             ret = aModuleList->AddTestModule(moduleName);
       
   442             if(ret != KErrNone && ret != KErrAlreadyExists)
       
   443                 {
       
   444                 LogErrorAndLeaveL(_L("CATSInterface::ParseTestModulesL"), _L("CTestModuleList::AddTestModule - Could not add module to list of modules"), ret);
       
   445                 return;
       
   446                 }
       
   447             }
       
   448         CleanupStack::PopAndDestroy(item);
       
   449 
       
   450         //Get pointer to added module
       
   451         CTestModuleInfo* moduleInfo = aModuleList->GetModule(moduleName);
       
   452         if(!moduleInfo)
       
   453             {
       
   454                 LogErrorAndLeaveL(_L("CATSInterface::ParseTestModulesL"), _L("CTestModuleList::GetModule - Could not add get module info from list"), KErrNotFound);
       
   455                 return;
       
   456             }
       
   457 
       
   458         // Get ini file, if it exists
       
   459         RDebug::Print(_L("Start parsing ini file"));
       
   460         _LIT(KIniFile, "IniFile=");
       
   461         item = sectionParser->GetItemLineL(KIniFile);
       
   462         if(item)
       
   463             {
       
   464             RDebug::Print(_L("'%S' found"), &KIniFile);
       
   465             CleanupStack::PushL(item);
       
   466             TPtrC iniFile;
       
   467             ret = item->GetString(KIniFile, iniFile);
       
   468             if(ret == KErrNone)
       
   469                 {
       
   470                 RDebug::Print(_L("Initialization file '%S' found, file can be empty"), &iniFile);
       
   471                 TFileName filename;
       
   472                 filename.Copy(iniFile);
       
   473                 filename.LowerCase();
       
   474                 TStifUtil::CorrectFilePathL( filename );
       
   475                 moduleInfo->SetIniFile(filename);
       
   476                 }
       
   477             else
       
   478                 {
       
   479                 RDebug::Print(_L("Initialization file not found"));
       
   480                 }
       
   481             CleanupStack::PopAndDestroy(item);
       
   482             }
       
   483         else
       
   484             {
       
   485             RDebug::Print(_L("'%S' not found"), &KIniFile);
       
   486             }
       
   487 
       
   488         // Get config (testcase) file
       
   489         RDebug::Print(_L("Start parsing cfg files"));
       
   490         TPtrC cfgTag;
       
   491         for(TInt i = 0; i < 2; i++)
       
   492             {
       
   493             //Set tag for config files
       
   494             if(i == 0)
       
   495                 {
       
   496                 cfgTag.Set(_L("ConfigFile="));
       
   497                 }
       
   498                 else
       
   499                 {
       
   500                 cfgTag.Set(_L("TestCaseFile="));
       
   501                 }
       
   502             //Read data
       
   503             item = sectionParser->GetItemLineL(cfgTag);
       
   504             while(item)
       
   505                 {
       
   506                 CleanupStack::PushL(item);
       
   507                 RDebug::Print(_L("Item '%S' found"), &cfgTag);
       
   508                 TPtrC cfgFile;
       
   509                 ret = item->GetString(cfgTag, cfgFile);
       
   510                 if(ret == KErrNone)
       
   511                     {
       
   512                     TFileName ifile;
       
   513                     ifile.Copy(cfgFile);
       
   514                     ifile.LowerCase();
       
   515                     TStifUtil::CorrectFilePathL( ifile );
       
   516                     RDebug::Print(_L("Configuration file '%S' found"), &ifile);
       
   517                     moduleInfo->AddCfgFile(ifile);
       
   518                     }
       
   519                 else
       
   520                     {
       
   521                     RDebug::Print(_L("Configuration file not found"));
       
   522                     }
       
   523                 CleanupStack::PopAndDestroy(item);
       
   524                 item = sectionParser->GetNextItemLineL(cfgTag);
       
   525                 }
       
   526             }
       
   527 
       
   528         RDebug::Print(_L("Module '%S' information read correctly"), &moduleName);
       
   529 
       
   530         // Get next section
       
   531         CleanupStack::PopAndDestroy(sectionParser);
       
   532         sectionParser = aParser->NextSectionL(aSectionStart, aSectionEnd);
       
   533         }
       
   534     }
       
   535 
       
   536 /*
       
   537 -------------------------------------------------------------------------------
       
   538 
       
   539     Class: CATSInterface
       
   540 
       
   541     Method: ParseCommandLineL
       
   542 
       
   543     Description: Parse command line parameters
       
   544 
       
   545     Parameters: None
       
   546 
       
   547     Return Values: None
       
   548 
       
   549     Errors/Exceptions: Leaves if module name not found from command line
       
   550 
       
   551     Status: Approved
       
   552     
       
   553 -------------------------------------------------------------------------------
       
   554 */
       
   555 void CATSInterface::ParseCommandLineL()
       
   556     {
       
   557     // Command line params
       
   558     _LIT( KTestModule, "-testmodule" );
       
   559     _LIT( KConfigFile, "-config" );
       
   560     _LIT( KEngineIniFile, "-engineini" );
       
   561     _LIT( KModuleIniFile, "-moduleini" );
       
   562 
       
   563 	const TInt length = User().CommandLineLength();
       
   564 
       
   565     HBufC* cmdLine = HBufC::NewLC( length );
       
   566     TPtr ptr = cmdLine->Des();
       
   567 
       
   568 	User().CommandLine( ptr );
       
   569 
       
   570     TBool moduleFound( EFalse );
       
   571     TLex lex( ptr );
       
   572     // Parse the command line
       
   573     while ( !lex.Eos() )
       
   574         {
       
   575         TPtrC tmpPtr = lex.NextToken();
       
   576         // Check the test module name
       
   577         if ( tmpPtr == KTestModule )
       
   578             {
       
   579             TPtrC module = lex.NextToken();
       
   580             if ( module.Ptr() )
       
   581                 {
       
   582                 iTestModule.Copy( module );
       
   583                 moduleFound = ETrue;
       
   584                 }
       
   585             }
       
   586         // Check the module's config file
       
   587         else if ( tmpPtr == KConfigFile )
       
   588             {
       
   589             TPtrC config = lex.NextToken();
       
   590             if ( config.Ptr() )
       
   591                 {
       
   592                 iConfigFile.Copy( config );
       
   593                 TStifUtil::CorrectFilePathL( iConfigFile );
       
   594                 }
       
   595             }
       
   596         // Check the engine's ini file
       
   597         else if ( tmpPtr == KEngineIniFile )
       
   598             {
       
   599             TPtrC iniFile = lex.NextToken();
       
   600             if ( iniFile.Ptr() )
       
   601                 {
       
   602                 iEngineIniFile.Copy( iniFile );
       
   603                 TStifUtil::CorrectFilePathL( iEngineIniFile );
       
   604                 }
       
   605             }
       
   606         // Check the module's ini file
       
   607         else if ( tmpPtr == KModuleIniFile )
       
   608             {
       
   609             TPtrC iniFile = lex.NextToken();
       
   610             if ( iniFile.Ptr() )
       
   611                 {
       
   612                 iModuleIniFile.Copy( iniFile );
       
   613                 TStifUtil::CorrectFilePathL( iModuleIniFile );
       
   614                 }
       
   615             }
       
   616         else
       
   617             {
       
   618             // Skip unknown commands
       
   619             }
       
   620         } // while
       
   621 
       
   622     // Destroy command line buffer
       
   623     CleanupStack::PopAndDestroy( cmdLine );
       
   624 
       
   625     // Module name has to exists
       
   626     if ( !moduleFound )
       
   627         {
       
   628         User::Leave( KErrArgument );
       
   629         }
       
   630     }
       
   631 
       
   632 
       
   633 /*
       
   634 -------------------------------------------------------------------------------
       
   635 
       
   636     Class: CATSInterface
       
   637 
       
   638     Method: RunTestsL
       
   639 
       
   640     Description: Starts testing
       
   641 
       
   642     Parameters: None
       
   643 
       
   644     Return Values: None
       
   645 
       
   646     Errors/Exceptions: Leaves if RunAllTestCasesL leaves
       
   647                        Leaves if RemoveTestModule returns error
       
   648 
       
   649     Status: Approved
       
   650     
       
   651 -------------------------------------------------------------------------------
       
   652 */
       
   653 void CATSInterface::RunTestsL()
       
   654     {
       
   655     // Run all test cases
       
   656     RunAllTestCasesL();
       
   657 
       
   658     /*
       
   659     // Remove test module
       
   660     User::LeaveIfError( iTestEngine.RemoveTestModule( iTestModule ) );
       
   661     */
       
   662     RDebug::Print(_L("Start removing test modules"));
       
   663     CTestModuleInfo* moduleInfo = NULL;
       
   664     TInt i;
       
   665     TInt modCnt = iModuleList->Count();
       
   666 
       
   667     for(i = 0; i < modCnt; i++)
       
   668         {
       
   669         RDebug::Print(_L("Processing module"));
       
   670         // Get module
       
   671         moduleInfo = iModuleList->GetModule(i);
       
   672         if(!moduleInfo)
       
   673             {
       
   674             RDebug::Print(_L("Could not get module info at index %d"), i);
       
   675             continue;
       
   676             }
       
   677 
       
   678         // Get module name
       
   679         TName moduleName;
       
   680         moduleInfo->GetModuleName(moduleName);
       
   681         RDebug::Print(_L("module name: '%S'"), &moduleName);
       
   682 
       
   683         // Remove test module
       
   684         User::LeaveIfError(iTestEngine.RemoveTestModule(moduleName));
       
   685         RDebug::Print(_L("Module '%S' removed"), &moduleName);
       
   686         }
       
   687 
       
   688     RDebug::Print(_L("End removing test modules"));
       
   689     }
       
   690 
       
   691 /*
       
   692 -------------------------------------------------------------------------------
       
   693 
       
   694     Class: CATSInterface
       
   695 
       
   696     Method: RunAllTestCasesL
       
   697 
       
   698     Description: Run all test cases from test module.
       
   699 
       
   700     Parameters: None
       
   701 
       
   702     Return Values: None
       
   703 
       
   704     Errors/Exceptions: Leaves if some of called leaving methods leaves
       
   705 
       
   706     Status: Proposal
       
   707 
       
   708 -------------------------------------------------------------------------------
       
   709 */
       
   710 void CATSInterface::RunAllTestCasesL()
       
   711     {
       
   712     TInt ret( KErrNone );
       
   713 
       
   714     /*
       
   715     // Add given config file to test module
       
   716     if ( iConfigFile.Length() > 0 )
       
   717         {
       
   718         ret = iTestEngine.AddConfigFile( iTestModule, iConfigFile );
       
   719         if ( ret != KErrNone && ret != KErrAlreadyExists )
       
   720             {
       
   721             // Log error
       
   722             LogErrorAndLeaveL( _L("CATSInterface::RunAllTestCasesL"), _L("iTestEngine.AddConfigFile"), ret );
       
   723             return;
       
   724             }
       
   725         }
       
   726     */
       
   727 
       
   728     // Enumerate test cases
       
   729     TCaseCount caseCount;
       
   730     TRequestStatus status;
       
   731     iTestEngine.EnumerateTestCases( caseCount, status );
       
   732     User::WaitForRequest( status );
       
   733 
       
   734     // Check that enumerate succeeded
       
   735     if ( status != KErrNone )
       
   736         {
       
   737         // Log error 
       
   738         LogErrorAndLeaveL( _L("CATSInterface::RunAllTestCasesL"), _L("iTestEngine.EnumerateTestCases"), status.Int() );
       
   739         return;
       
   740         }
       
   741 
       
   742     // Get test cases to buffer
       
   743     CFixedFlatArray<TTestInfo>* testCases = 
       
   744         CFixedFlatArray<TTestInfo>::NewL( caseCount() );
       
   745     CleanupStack::PushL( testCases );
       
   746 
       
   747     ret = iTestEngine.GetTestCases( *testCases );
       
   748     if ( ret != KErrNone )
       
   749         {
       
   750         // Log error 
       
   751         LogErrorAndLeaveL( _L("CATSInterface::RunAllTestCasesL"), _L("iTestEngine.GetTestCases"), status.Int() );
       
   752         return;
       
   753         }
       
   754 
       
   755     //variables used to get version of STIF
       
   756     TInt majorV;
       
   757     TInt minorV;
       
   758     TInt buildV;
       
   759     TBuf<30> relDate;
       
   760     TStifUtil::STIFVersion(majorV, minorV, buildV, relDate);
       
   761     
       
   762     TBuf<50> version;
       
   763     version.Format(_L("STF v%d.%d.%d - "), majorV, minorV, buildV);
       
   764     version.Append(relDate);
       
   765     version.Append(_L("\n"));
       
   766     
       
   767     iConsole->Printf(version);	//printing STIF version information (version and release date)
       
   768     iConsole->Printf( _L("Test case count: [%d]\n\n\n"), testCases->Count() );
       
   769 
       
   770     // Loop through all test cases in buffer and run them
       
   771     const TInt count = testCases->Count();
       
   772     for ( TInt i = 0; i < count; i++ )
       
   773         {
       
   774 #ifdef _DEBUG
       
   775         RDebug::Print( ( *testCases)[i].iTestCaseInfo.iTitle );
       
   776 #endif
       
   777         iConsole->Printf( _L("Now running test case: [%d] [%S] "), i+1,
       
   778             &( *testCases )[i].iTestCaseInfo.iTitle );
       
   779 
       
   780         // Run test case
       
   781         RunTestCaseL( ( *testCases )[i] );
       
   782         }
       
   783 
       
   784     // End test set
       
   785     CleanupStack::PopAndDestroy( testCases );
       
   786 
       
   787     }
       
   788 
       
   789 
       
   790 /*
       
   791 -------------------------------------------------------------------------------
       
   792 
       
   793     Class: CATSInterface
       
   794 
       
   795     Method: RunTestCaseL
       
   796 
       
   797     Description: Run test case
       
   798 
       
   799     Parameters: TTestInfo& aTestInfo: in: TTestInfo: Test info
       
   800 
       
   801     Return Values: None
       
   802 
       
   803     Errors/Exceptions: Leaves if some of called leaving methods leaves
       
   804 
       
   805     Status: Proposal
       
   806 
       
   807 -------------------------------------------------------------------------------
       
   808 */
       
   809 void CATSInterface::RunTestCaseL( TTestInfo& aTestInfo )
       
   810     {
       
   811     TInt testResult( KErrNone );
       
   812     CATSInterfaceRunner* runner;
       
   813 
       
   814     // Trap to catch errors from test case executing
       
   815     TRAPD( trapError,
       
   816         runner = CATSInterfaceRunner::NewL( this, aTestInfo );
       
   817         CleanupStack::PushL( runner );
       
   818 
       
   819         testResult = RunATestCaseL( runner );
       
   820 
       
   821         CleanupStack::PopAndDestroy( runner );
       
   822         );
       
   823 
       
   824     if ( trapError != KErrNone )
       
   825         {
       
   826         testResult = trapError;
       
   827         }
       
   828 
       
   829     if ( testResult != KErrNone ) // Test case is FAILED
       
   830         {
       
   831         // Test case failed, print out the error
       
   832         iConsole->Printf( _L("\nTest case FAILED! err=[%d]\n"), testResult );
       
   833         }
       
   834 
       
   835     else // Test case is PASSED
       
   836         {
       
   837         iConsole->Printf( _L("\nTest case PASSED!\n") );
       
   838         testResult = KErrNone;
       
   839         }
       
   840     }
       
   841 
       
   842 
       
   843 /*
       
   844 -------------------------------------------------------------------------------
       
   845 
       
   846     Class: CATSInterface
       
   847 
       
   848     Method: RunATestCaseL
       
   849 
       
   850     Description: Run a test case
       
   851 
       
   852     Parameters: CATSInterfaceRunner* aTestCase: in: Pointer to test case runner
       
   853 
       
   854     Return Values: TInt KErrNone: Test case passed
       
   855                    other error code: Test case failed or cannot be executed
       
   856 
       
   857     Errors/Exceptions: None
       
   858 
       
   859     Status: Approved
       
   860 
       
   861 -------------------------------------------------------------------------------
       
   862 */
       
   863 TInt CATSInterface::RunATestCaseL( CATSInterfaceRunner* aTestCase )
       
   864     {
       
   865     iTestCompletedError = KErrNone;
       
   866 
       
   867     // Create timer
       
   868     CActiveTimer* timer = CActiveTimer::NewL( iConsole );
       
   869     CleanupStack::PushL( timer );
       
   870 
       
   871     // Start test case and timer
       
   872     aTestCase->StartTestL();
       
   873     timer->StartL();
       
   874 
       
   875     // Wait for test case completed
       
   876     CActiveScheduler::Start();
       
   877 
       
   878     timer->Cancel();
       
   879     CleanupStack::PopAndDestroy( timer );
       
   880 
       
   881     // test completion error is set in TestCompleted method
       
   882     return iTestCompletedError;
       
   883     }
       
   884 
       
   885 /*
       
   886 -------------------------------------------------------------------------------
       
   887 
       
   888     Class: CATSInterface
       
   889 
       
   890     Method: TestEngine
       
   891 
       
   892     Description: Return handle to Test Engine.
       
   893 
       
   894     Parameters: None
       
   895     
       
   896     Return Values: RTestEngine&: reference to RTestEngine handle
       
   897 
       
   898     Errors/Exceptions: None
       
   899 
       
   900     Status: Approved
       
   901     
       
   902 -------------------------------------------------------------------------------
       
   903 */
       
   904 RTestEngine& CATSInterface::TestEngine()
       
   905     {
       
   906     return iTestEngine;
       
   907 
       
   908     }
       
   909 
       
   910 
       
   911 /*
       
   912 -------------------------------------------------------------------------------
       
   913 
       
   914     Class: CATSInterface
       
   915 
       
   916     Method: TestCompleted
       
   917 
       
   918     Description: Test case completed
       
   919 
       
   920     This method is called when test case is completed or error occurred
       
   921     during the test.
       
   922 
       
   923     Parameters: TInt aError: in: Symbian OS error: Test result
       
   924     
       
   925     Return Values: None
       
   926 
       
   927     Errors/Exceptions: None
       
   928 
       
   929     Status: Approved
       
   930     
       
   931 -------------------------------------------------------------------------------
       
   932 */
       
   933 void CATSInterface::TestCompleted( TInt aError )
       
   934     {
       
   935     // Store completion error
       
   936     iTestCompletedError = aError;
       
   937 
       
   938     // Stop the scheduler
       
   939     CActiveScheduler::Stop();
       
   940 
       
   941     }
       
   942     
       
   943 /*
       
   944 -------------------------------------------------------------------------------
       
   945 
       
   946     Class: CATSInterface
       
   947 
       
   948     Method: LogErrorAndLeaveL
       
   949 
       
   950     Description: Write error Logger and leave.
       
   951 
       
   952     This function is called if some function returns error and the error cannot
       
   953     be logged another way Logger, e.g. RTestEngineServer and
       
   954     RTestEngine methods.
       
   955 
       
   956     Parameters: const TDesC& aFunction: in: any string: Function where the error
       
   957                  occurred
       
   958                 const TDesC& aDescription: in: any string: Description for error
       
   959                 const TInt aError: in: Symbian OS error: Test result
       
   960     
       
   961     Return Values: None
       
   962 
       
   963     Errors/Exceptions: None
       
   964 
       
   965     Status: Proposal
       
   966     
       
   967 -------------------------------------------------------------------------------
       
   968 */
       
   969 void CATSInterface::LogErrorAndLeaveL( const TDesC& aFunction, 
       
   970                                       const TDesC& aDescription, 
       
   971                                       const TInt aError )
       
   972     {
       
   973 
       
   974     RDebug::Print( _L("%S: %S [%d]"), &aFunction, &aDescription, aError );
       
   975     User::Leave( aError );
       
   976 
       
   977     }
       
   978 
       
   979 // ================= OTHER EXPORTED FUNCTIONS ================================= 
       
   980 
       
   981 /*
       
   982 -------------------------------------------------------------------------------
       
   983    
       
   984     Function: E32Main
       
   985 
       
   986     Description: Main function called by E32.
       
   987 
       
   988     Parameters: None
       
   989 
       
   990     Return Values: TInt: KErrNone :No errors occurred
       
   991                    TInt: Other Symbian OS Error :Error catch by TRAP
       
   992 
       
   993     Errors/Exceptions: TRAP is used to catch errors from leaving methods.
       
   994 
       
   995     Status: Approved
       
   996 
       
   997 -------------------------------------------------------------------------------
       
   998 */
       
   999 GLDEF_C TInt E32Main()
       
  1000     {
       
  1001  
       
  1002     TInt processHandleCountBefore;
       
  1003     TInt threadHandleCountBefore;
       
  1004     RThread().HandleCount( processHandleCountBefore, threadHandleCountBefore );
       
  1005     TInt reqsBefore = RThread().RequestCount();
       
  1006 
       
  1007     TInt processHandleCountAfter;
       
  1008     TInt threadHandleCountAfter;
       
  1009     TInt reqsAfter;
       
  1010 
       
  1011     __UHEAP_MARK;
       
  1012 
       
  1013     CTrapCleanup* cleanup = CTrapCleanup::New();
       
  1014     if ( cleanup == NULL )
       
  1015         {
       
  1016         __UHEAP_MARKEND;
       
  1017         return KErrNoMemory;
       
  1018         }
       
  1019 
       
  1020     CActiveScheduler* activeScheduler = new CActiveScheduler;
       
  1021     if ( activeScheduler == NULL )
       
  1022         {
       
  1023         delete cleanup;
       
  1024         __UHEAP_MARKEND;
       
  1025         return KErrNoMemory;
       
  1026         }
       
  1027     CActiveScheduler::Install( activeScheduler );
       
  1028 
       
  1029     // Construct the test client
       
  1030     CATSInterface* test = NULL;
       
  1031     TRAPD( err, test = CATSInterface::NewL() );
       
  1032     if ( err != KErrNone )
       
  1033         {
       
  1034 #ifdef _DEBUG
       
  1035         RDebug::Print(_L("ATSInterface construction failed %d: "), err );
       
  1036 #endif
       
  1037         delete cleanup;
       
  1038         delete activeScheduler;
       
  1039         __UHEAP_MARKEND;
       
  1040         return err;
       
  1041         }
       
  1042 
       
  1043     // Run tests
       
  1044     TRAP( err, test->RunTestsL() );
       
  1045     if ( err != KErrNone )
       
  1046         {
       
  1047 #ifdef _DEBUG
       
  1048         RDebug::Print(_L("RunTestsL left with %d: "), err );
       
  1049 #endif
       
  1050         }
       
  1051 
       
  1052 
       
  1053     // Deallocate resources
       
  1054     delete test;
       
  1055     delete activeScheduler;
       
  1056     delete cleanup;
       
  1057 
       
  1058     reqsAfter = RThread().RequestCount();
       
  1059     RThread().HandleCount( processHandleCountAfter, threadHandleCountAfter );
       
  1060 
       
  1061     if ( reqsAfter != reqsBefore )
       
  1062         {
       
  1063 #ifdef _DEBUG
       
  1064         RDebug::Print(_L("Request count not matching! %d vs. %d: "),
       
  1065             reqsBefore, reqsAfter );
       
  1066 #endif
       
  1067         }
       
  1068     if ( threadHandleCountAfter != threadHandleCountBefore )
       
  1069         {
       
  1070 #ifdef _DEBUG
       
  1071         RDebug::Print(_L("Handle count not matching! %d vs. %d: "),
       
  1072             threadHandleCountBefore, threadHandleCountAfter );
       
  1073 #endif
       
  1074         }
       
  1075 
       
  1076     __UHEAP_MARKEND;
       
  1077 
       
  1078     return err;
       
  1079     }
       
  1080 
       
  1081 //  End of File
       
  1082 
       
  1083 // End of File