stif/TestInterface/src/TestInterface.cpp
changeset 0 a03f92240627
child 9 8a14024f954a
equal deleted inserted replaced
-1:000000000000 0:a03f92240627
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 * 
       
    14 * Description: This file contains TestInterface implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include <e32base.h>
       
    20 #include <e32std.h>
       
    21 #include "StifTestInterface.h"
       
    22 #include "TestServerModuleIf.h"
       
    23 #include "StifTestModule.h"
       
    24 #include <stifinternal/TestServerClient.h>
       
    25 //#include <bautils.h>
       
    26 #include "version.h"
       
    27 
       
    28 // EXTERNAL DATA STRUCTURES
       
    29 // None
       
    30 
       
    31 // EXTERNAL FUNCTION PROTOTYPES  
       
    32 // None
       
    33 
       
    34 // CONSTANTS
       
    35 // None
       
    36 
       
    37 // MACROS
       
    38 // None
       
    39 
       
    40 // LOCAL CONSTANTS AND MACROS
       
    41 // None
       
    42 
       
    43 // MODULE DATA STRUCTURES
       
    44 // None
       
    45 
       
    46 // LOCAL FUNCTION PROTOTYPES
       
    47 // None
       
    48 /*
       
    49 -------------------------------------------------------------------------------
       
    50 
       
    51     Class: -
       
    52 
       
    53     Method: StifDriveLetters
       
    54 
       
    55     Description: This defines drive letters that is available in STIF TF.
       
    56 
       
    57     Parameters: TInt aDriveNumber: in: Number to indicate drive letter
       
    58                 TInt& aCount: inout: Counts of drives that is available
       
    59 
       
    60     Return Values: const TChar: Returns a drive letter that is select by
       
    61                    aDriveNumber
       
    62 
       
    63     Errors/Exceptions: None
       
    64 
       
    65     Status: Proposal
       
    66     
       
    67 -------------------------------------------------------------------------------
       
    68 */
       
    69 //@spe
       
    70 /*
       
    71 EXPORT_C const TChar StifDriveLetters( TInt aDriveNumber, TInt& aCount )
       
    72     {
       
    73     static TChar* const EStifDriveLetters[] =
       
    74         {
       
    75         ( TChar* )L"a",
       
    76         ( TChar* )L"b",
       
    77         ( TChar* )L"c",
       
    78         ( TChar* )L"d",
       
    79         ( TChar* )L"e",
       
    80         ( TChar* )L"f",
       
    81         ( TChar* )L"g",
       
    82         ( TChar* )L"h",
       
    83         ( TChar* )L"i",
       
    84         ( TChar* )L"j",
       
    85         ( TChar* )L"k",
       
    86         ( TChar* )L"l",
       
    87         ( TChar* )L"m",
       
    88         ( TChar* )L"n",
       
    89         ( TChar* )L"o",
       
    90         ( TChar* )L"p",
       
    91         ( TChar* )L"q",
       
    92         ( TChar* )L"r",
       
    93         ( TChar* )L"s",
       
    94         ( TChar* )L"t",
       
    95         ( TChar* )L"u",
       
    96         ( TChar* )L"v",
       
    97         ( TChar* )L"w",
       
    98         ( TChar* )L"x",
       
    99         ( TChar* )L"y",
       
   100         ( TChar* )L"z",
       
   101         };
       
   102     aCount = (sizeof( EStifDriveLetters )/sizeof(TChar*));
       
   103     return TChar( *EStifDriveLetters[aDriveNumber] );
       
   104 
       
   105     }
       
   106 */
       
   107 
       
   108 // FORWARD DECLARATIONS
       
   109 // None
       
   110 
       
   111 // ==================== LOCAL FUNCTIONS =======================================
       
   112 // None
       
   113 
       
   114 /*
       
   115 -------------------------------------------------------------------------------
       
   116 
       
   117     DESCRIPTION
       
   118 
       
   119     This module contains the implementation of TTestCaseInfo class 
       
   120     member function.
       
   121 
       
   122 -------------------------------------------------------------------------------
       
   123 */
       
   124 
       
   125 // ================= MEMBER FUNCTIONS =========================================
       
   126 
       
   127 /*
       
   128 -------------------------------------------------------------------------------
       
   129 
       
   130     Class: TTestCaseInfo
       
   131 
       
   132     Method: TTestCaseInfo
       
   133 
       
   134     Description: This method is the constructor of class TTestCaseInfo.
       
   135 
       
   136     Parameters: None
       
   137 
       
   138     Return Values: None
       
   139 
       
   140     Errors/Exceptions: None
       
   141 
       
   142     Status: Approved
       
   143     
       
   144 -------------------------------------------------------------------------------
       
   145 */
       
   146 EXPORT_C TTestCaseInfo::TTestCaseInfo() 
       
   147     {
       
   148     iCaseNumber = -1;
       
   149     iTitle.Zero();
       
   150     iTimeout = 0;
       
   151     iPriority = EPriorityNormal;
       
   152     
       
   153     }
       
   154 
       
   155 /*
       
   156 -------------------------------------------------------------------------------
       
   157 
       
   158     DESCRIPTION
       
   159 
       
   160     This module contains the implementation of TTestInfo class 
       
   161     member function.
       
   162 
       
   163 -------------------------------------------------------------------------------
       
   164 */
       
   165 
       
   166 // ================= MEMBER FUNCTIONS =========================================
       
   167 
       
   168 /*
       
   169 -------------------------------------------------------------------------------
       
   170 
       
   171     Class: TTestInfo
       
   172 
       
   173     Method: TTestInfo
       
   174 
       
   175     Description: This method is the constructor of class TTestInfo.
       
   176 
       
   177     Parameters: None
       
   178 
       
   179     Return Values: None
       
   180 
       
   181     Errors/Exceptions: None
       
   182 
       
   183     Status: Approved
       
   184     
       
   185 -------------------------------------------------------------------------------
       
   186 */
       
   187 EXPORT_C TTestInfo::TTestInfo()
       
   188     {
       
   189 
       
   190     iModuleName.Zero();
       
   191     iConfig.Zero();
       
   192     
       
   193     }
       
   194 
       
   195 /*
       
   196 -------------------------------------------------------------------------------
       
   197 
       
   198     DESCRIPTION
       
   199 
       
   200     This module contains the implementation of TTestResult class 
       
   201     member function.
       
   202 
       
   203 -------------------------------------------------------------------------------
       
   204 */
       
   205 
       
   206 // ================= MEMBER FUNCTIONS =========================================
       
   207 
       
   208 /*
       
   209 -------------------------------------------------------------------------------
       
   210 
       
   211     Class: TTestResult
       
   212 
       
   213     Method: TTestResult
       
   214 
       
   215     Description: This method is the constructor of class TTestResult.
       
   216 
       
   217     Parameters: None
       
   218 
       
   219     Return Values: None
       
   220 
       
   221     Errors/Exceptions: None
       
   222 
       
   223     Status: Approved
       
   224     
       
   225 -------------------------------------------------------------------------------
       
   226 */
       
   227 EXPORT_C TTestResult::TTestResult()
       
   228     {
       
   229     iResult = 0;
       
   230     iResultDes.Zero();
       
   231     
       
   232     }
       
   233 
       
   234 /*
       
   235 -------------------------------------------------------------------------------
       
   236 
       
   237     Class: TTestResult
       
   238 
       
   239     Method: TTestResult
       
   240 
       
   241     Description: Sets result and result description of the test case.
       
   242     
       
   243     Parameters: TInt aResultCode: in: Symbian error code
       
   244                 const TResultDes& aResultDes: in: Result description of the
       
   245                 test case
       
   246     
       
   247     Return Values: None
       
   248     
       
   249     Errors/Exceptions: None
       
   250     
       
   251     Status: Proposal
       
   252     
       
   253 -------------------------------------------------------------------------------
       
   254 */
       
   255 EXPORT_C void TTestResult::SetResult( TInt aResultCode,
       
   256                                         const TDesC& aResultDes )
       
   257     {
       
   258     iResult = aResultCode;
       
   259     // If description is too length then cut.
       
   260     if( aResultDes.Length() > KStifMaxResultDes )
       
   261         {
       
   262         iResultDes = aResultDes.Left( KStifMaxResultDes );
       
   263         }
       
   264     else
       
   265         {
       
   266         iResultDes = aResultDes;
       
   267         }
       
   268 
       
   269     }
       
   270 
       
   271 /*
       
   272 -------------------------------------------------------------------------------
       
   273 
       
   274     DESCRIPTION
       
   275 
       
   276     This module contains the implementation of TFullTestResult class 
       
   277     member function.
       
   278 
       
   279 -------------------------------------------------------------------------------
       
   280 */
       
   281 
       
   282 // ================= MEMBER FUNCTIONS =========================================
       
   283 
       
   284 /*
       
   285 -------------------------------------------------------------------------------
       
   286 
       
   287     Class: TFullTestResult
       
   288 
       
   289     Method: TFullTestResult
       
   290 
       
   291     Description: This method is the constructor of class TFullTestResult.
       
   292 
       
   293     Parameters: None
       
   294 
       
   295     Return Values: None
       
   296 
       
   297     Errors/Exceptions: None
       
   298 
       
   299     Status: Approved
       
   300     
       
   301 -------------------------------------------------------------------------------
       
   302 */
       
   303 EXPORT_C TFullTestResult::TFullTestResult():
       
   304     iStartTime( 0 ),
       
   305     iEndTime( 0 )
       
   306     {    
       
   307     }
       
   308 
       
   309 /*
       
   310 -------------------------------------------------------------------------------
       
   311 
       
   312     DESCRIPTION
       
   313 
       
   314     This module contains the implementation of TTestProgress class 
       
   315     member function.
       
   316 
       
   317 -------------------------------------------------------------------------------
       
   318 */
       
   319 
       
   320 // ================= MEMBER FUNCTIONS =========================================
       
   321 
       
   322 /*
       
   323 -------------------------------------------------------------------------------
       
   324 
       
   325     Class: TTestProgress
       
   326 
       
   327     Method: TTestProgress
       
   328 
       
   329     Description: This method is the constructor of class TTestProgress.
       
   330 
       
   331     Parameters: None
       
   332 
       
   333     Return Values: None
       
   334 
       
   335     Errors/Exceptions: None
       
   336 
       
   337     Status: Approved
       
   338     
       
   339 -------------------------------------------------------------------------------
       
   340 */
       
   341 EXPORT_C TTestProgress::TTestProgress()
       
   342     {
       
   343     iPosition = 0;
       
   344     iDescription.Zero();
       
   345     iText.Zero();
       
   346 
       
   347     }
       
   348 
       
   349 /*
       
   350 -------------------------------------------------------------------------------
       
   351 
       
   352     DESCRIPTION
       
   353 
       
   354     This module contains the implementation of TErrorNotification class 
       
   355     member function.
       
   356 
       
   357 -------------------------------------------------------------------------------
       
   358 */
       
   359 
       
   360 // ================= MEMBER FUNCTIONS =========================================
       
   361 
       
   362 /*
       
   363 -------------------------------------------------------------------------------
       
   364 
       
   365     Class: TErrorNotification
       
   366 
       
   367     Method: TErrorNotification
       
   368 
       
   369     Description: This method is the constructor of class TTestProgress.
       
   370 
       
   371     Parameters: None
       
   372 
       
   373     Return Values: None
       
   374 
       
   375     Errors/Exceptions: None
       
   376 
       
   377     Status: Approved
       
   378     
       
   379 -------------------------------------------------------------------------------
       
   380 */
       
   381 EXPORT_C TErrorNotification::TErrorNotification()
       
   382     {
       
   383     iPriority = 0;
       
   384     iModule.Zero();
       
   385     iText.Zero();
       
   386 
       
   387     }
       
   388 
       
   389 /*
       
   390 -------------------------------------------------------------------------------
       
   391 
       
   392     Class: -
       
   393 
       
   394     Method: StartSession
       
   395 
       
   396     Description: This works and used only in EKA2 environment and used from
       
   397                  STIF TestFramework internally.
       
   398                  Executable module uses defined capabilities(PlatSec's
       
   399                  Capability model) to start session. Function for starting
       
   400                  the TestServer and Testmodule/TestClass.
       
   401     
       
   402                  Starts a new server. Server will be running its own
       
   403                  thread and this functions returns when server is up and
       
   404                  running or server start-up fails.
       
   405 
       
   406     Parameters: None
       
   407     
       
   408     Return Values: TInt Error code / KErrNone
       
   409 
       
   410     Errors/Exceptions: None
       
   411 
       
   412     Status: Proposal
       
   413 
       
   414 -------------------------------------------------------------------------------
       
   415 */
       
   416 EXPORT_C TInt StartSession()
       
   417     {
       
   418     //__UHEAP_MARK;
       
   419 
       
   420     // Get module name from command line
       
   421 	const TInt length = User().CommandLineLength();
       
   422     HBufC* cmdLine = HBufC::New( length );
       
   423     
       
   424     if ( cmdLine == NULL )
       
   425         {
       
   426         //__UHEAP_MARKEND;
       
   427         return KErrNoMemory;
       
   428         }
       
   429 
       
   430     TPtr moduleName = cmdLine->Des();
       
   431     User().CommandLine( moduleName );
       
   432 
       
   433     RDebug::Print (moduleName);
       
   434    
       
   435     // Open start-up synchronization semaphore
       
   436     RSemaphore startup;
       
   437     RDebug::Print(_L(" Openingstart-up semaphore"));
       
   438     TName semaphoreName = _L("startupSemaphore");
       
   439     semaphoreName.Append( moduleName );
       
   440     
       
   441     TInt res = startup.OpenGlobal(semaphoreName);
       
   442     RDebug::Print(_L("Opening result %d"), res);    
       
   443 
       
   444 
       
   445     TFileName serverName;
       
   446     TInt r = StartNewServer ( moduleName, serverName, EFalse, startup);    
       
   447 
       
   448     if ( r ==   KErrAlreadyExists )
       
   449         {        
       
   450         // Ok, server was already started
       
   451         RDebug::Print(_L("Server already started, signaling semaphore and existing"));
       
   452         startup.Signal();        
       
   453         //__UHEAP_MARKEND;
       
   454         
       
   455         delete cmdLine;
       
   456         
       
   457         return KErrNone;
       
   458         }
       
   459     else
       
   460         {       
       
   461         RDebug::Print(_L("Server is finished, code %d"), r);
       
   462         }
       
   463 
       
   464     //__UHEAP_MARKEND;
       
   465 
       
   466 	// Program execution never comes here, because StartNewServer doesn't return
       
   467 	// unless server is already started.
       
   468 	
       
   469     delete cmdLine;
       
   470     
       
   471     // Return start-up result.
       
   472     return r;
       
   473 
       
   474     }
       
   475 
       
   476 /*
       
   477 -------------------------------------------------------------------------------
       
   478 
       
   479     Class: TStifUtil
       
   480 
       
   481     Method: CorrectFilePath
       
   482 
       
   483     Description: Checks if file path contains drive letter. If not file is serched
       
   484                  on all drives and first hit is added to file name.
       
   485 
       
   486     Parameters: TDes& aFilePath: in/out: file path to correct
       
   487 
       
   488     Return Values: None
       
   489 
       
   490     Errors/Exceptions: Leaves if some of called leaving methods leaves
       
   491 
       
   492 -------------------------------------------------------------------------------
       
   493 */
       
   494 EXPORT_C void TStifUtil::CorrectFilePathL( TDes& aFilePath )
       
   495 	{
       
   496 	_LIT( KDriveSelector, ":\\" );
       
   497 	_LIT( KDriveSelectorFormat_1, "%c:" );                                                                  
       
   498 	_LIT( KDriveSelectorFormat_2, "%c:\\" );                                                                
       
   499 	TChar KDriveZ = EDriveZ;//'Z';                                                                          
       
   500 	                                                                                                              
       
   501 	_LIT( KBackslash, "\\" );                                                                              
       
   502 	                                                                                                                
       
   503 	TInt length = aFilePath.Length();                                                                      
       
   504 	                                                                                                                
       
   505 	if (length == 0 )                                                                                     
       
   506 	   {                                                                                                  
       
   507 	   return;                                                                                            
       
   508 	   }                                                                                                  
       
   509 	if (length > 2 )                                                                                      
       
   510 	   {                                                                                                  
       
   511 	   // Check if file path contains drive selector                                                      
       
   512 	   if ( aFilePath.Mid( 1, 2 ) == KDriveSelector )                                                     
       
   513 	       {                                                                                               
       
   514 	       // File path contains selector letter so we have nothing to do here                             
       
   515 	       return;                                                                                         
       
   516 	       }                                                                                               
       
   517 	   }                                                                                                  
       
   518 	                                                                                                                
       
   519 	// Check if file path contains backslash at the begining and                                          
       
   520 	// select proper drive selector format according to this information                                  
       
   521 	TInt driveSelectorFormat = 2;                                                                         
       
   522 	if ( aFilePath.Mid( 0, 1 ) == KBackslash )                                                            
       
   523 	   {                                                                                               
       
   524 	   driveSelectorFormat = 1;                                                                        
       
   525 	   }                                                                                               
       
   526 	                                                                                                                
       
   527 	RFs rfs;                                                                                              
       
   528 	if ( rfs.Connect() != KErrNone )                                                                      
       
   529 	   {                                                                                                  
       
   530 	   return;                                                                                            
       
   531 	   }                                                                                                  
       
   532 	                                                                                                                
       
   533 	// Get available drives list, revers it order and move z drive at                                     
       
   534 	// the end of the list.  
       
   535 	TDriveList drivesList; 
       
   536 	rfs.DriveList(drivesList); 
       
   537 
       
   538 	// Set drive variable to last drive (except for Z, which will be checked at the end)
       
   539 	char drive = 'Y' ;
       
   540 
       
   541 	// Loop through all the drives in following order: YX..CBAZ
       
   542 	while(drive >= 'A' && drive <= 'Z')
       
   543 	     {
       
   544 	     // Do further action only if drive exists
       
   545 	     TInt driveint;
       
   546 	     rfs.CharToDrive(drive, driveint);
       
   547 	     if(drivesList[driveint])
       
   548 	          {
       
   549 	          //further checking (drive selector and file existence)
       
   550 	          
       
   551 	          // Prepare drive selector                                                                         
       
   552 	          TBuf<3> driveSelector;                                                                            
       
   553 	          if ( driveSelectorFormat == 1 )                                                                   
       
   554 	              {                                                                                           
       
   555 	              driveSelector.Format( KDriveSelectorFormat_1, drive );                                    
       
   556 	              }                                                                                           
       
   557 	          else if ( driveSelectorFormat == 2 )                                                              
       
   558 	              {                                                                                           
       
   559 	              driveSelector.Format( KDriveSelectorFormat_2, drive );                                    
       
   560 	              }                                                                                           
       
   561 	                                                                                                                
       
   562 	          aFilePath.Insert( 0, driveSelector );                                                             
       
   563 	                                                                                                                
       
   564 	          TEntry entry;                                                                                     
       
   565 	          if ( rfs.Entry(aFilePath, entry) == KErrNone )                                                    
       
   566 	              {                                                                                         
       
   567 	              rfs.Close();                                                                                
       
   568 	              return;                                                                                     
       
   569 	              }                                                                                           
       
   570 	                                                                                                                
       
   571 	          // File does not exists on selected drive. Restoring orginal file path                            
       
   572 	          aFilePath.Delete( 0, driveSelector.Length() );    	         
       
   573 	          }//if(drivesList[driveint])       
       
   574 	            
       
   575 	   // Select next drive
       
   576 	   if(drive == 'Z')
       
   577 	       break; // the last driver
       
   578 	   else if(drive ==  'A' )
       
   579 	       drive = 'Z'; //after checking A check Z
       
   580 	   else
       
   581 	       drive =  (TChar)(TInt(drive)-1) ; //after checking Y check X and so on in reverse alphabetical order
       
   582 	   } //while 
       
   583 	rfs.Close(); 
       
   584 	}
       
   585 
       
   586 /*
       
   587 -------------------------------------------------------------------------------
       
   588 
       
   589     Class: TStifUtil
       
   590 
       
   591     Method: STIFVersion
       
   592 
       
   593     Description: Method used to retrieve version of STIF by both STIF and STIF UI 
       
   594 
       
   595     Parameters: TInt& aMajorV - parameter used to pass major STIF version
       
   596      			TInt& aMinorV - parameter used to pass minor STIF version
       
   597      			TInt& aBuildV - parameter used to pass build version of STIF
       
   598      			TDes& aRelDate - parameter used to pass information about release date
       
   599 
       
   600     Return Values: None
       
   601 
       
   602 -------------------------------------------------------------------------------
       
   603 */
       
   604 EXPORT_C void TStifUtil::STIFVersion(TInt& aMajorV, TInt& aMinorV, TInt& aBuildV, TDes& aRelDate)
       
   605 	{
       
   606 	aMajorV = STIF_MAJOR_VERSION;
       
   607 	aMinorV = STIF_MINOR_VERSION;
       
   608 	aBuildV = STIF_BUILD_VERSION;
       
   609 	aRelDate = TO_UNICODE(STIF_REL_DATE);
       
   610 	}
       
   611 //  End of File