stif/TestInterface/src/TestInterface.cpp
branchRCL_3
changeset 59 8ad140f3dd41
equal deleted inserted replaced
49:7fdc9a71d314 59:8ad140f3dd41
       
     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(_L("StartSession() Received data [%S]"), &moduleName);
       
   434 
       
   435     // Extract semaphore name passed in data    
       
   436     TInt index = moduleName.Find(_L(" "));
       
   437     RDebug::Print(_L("StartSession() Space separator found at position [%d]"), index);
       
   438     TPtrC semaphoreName = moduleName.Mid(index + 1);
       
   439     moduleName = moduleName.Left(index);
       
   440 
       
   441     RDebug::Print(_L("StartSession() Extracted module name [%S] and sempahore name [%S]"), &moduleName, &semaphoreName);
       
   442    
       
   443     // Open start-up synchronization semaphore
       
   444     RSemaphore startup;
       
   445     RDebug::Print(_L(" Opening start-up semaphore"));
       
   446 //    TName semaphoreName = _L("startupSemaphore");
       
   447 //    semaphoreName.Append( moduleName );
       
   448     
       
   449     TInt res = startup.OpenGlobal(semaphoreName);
       
   450     RDebug::Print(_L("Opening result %d"), res);    
       
   451 
       
   452 
       
   453     TFileName serverName;
       
   454     TInt r = StartNewServer ( moduleName, serverName, EFalse, startup);    
       
   455 
       
   456     if ( r ==   KErrAlreadyExists )
       
   457         {        
       
   458         // Ok, server was already started
       
   459         RDebug::Print(_L("Server already started, signaling semaphore and exiting"));
       
   460         startup.Signal();        
       
   461         //__UHEAP_MARKEND;
       
   462         
       
   463         delete cmdLine;
       
   464         
       
   465         return KErrNone;
       
   466         }
       
   467     else
       
   468         {       
       
   469         RDebug::Print(_L("Server is finished, code %d"), r);
       
   470         }
       
   471 
       
   472     //__UHEAP_MARKEND;
       
   473 
       
   474 	// Program execution never comes here, because StartNewServer doesn't return
       
   475 	// unless server is already started.
       
   476 	
       
   477     delete cmdLine;
       
   478     
       
   479     // Return start-up result.
       
   480     return r;
       
   481 
       
   482     }
       
   483 
       
   484 /*
       
   485 -------------------------------------------------------------------------------
       
   486 
       
   487     Class: TStifUtil
       
   488 
       
   489     Method: CorrectFilePath
       
   490 
       
   491     Description: Checks if file path contains drive letter. If not file is serched
       
   492                  on all drives and first hit is added to file name.
       
   493 
       
   494     Parameters: TDes& aFilePath: in/out: file path to correct
       
   495 
       
   496     Return Values: None
       
   497 
       
   498     Errors/Exceptions: Leaves if some of called leaving methods leaves
       
   499 
       
   500 -------------------------------------------------------------------------------
       
   501 */
       
   502 EXPORT_C void TStifUtil::CorrectFilePathL( TDes& aFilePath )
       
   503 	{
       
   504 	_LIT( KDriveSelector, ":\\" );
       
   505 	_LIT( KDriveSelectorFormat_1, "%c:" );                                                                  
       
   506 	_LIT( KDriveSelectorFormat_2, "%c:\\" );                                                                
       
   507 	TChar KDriveZ = EDriveZ;//'Z';                                                                          
       
   508 	                                                                                                              
       
   509 	_LIT( KBackslash, "\\" );                                                                              
       
   510 	                                                                                                                
       
   511 	TInt length = aFilePath.Length();                                                                      
       
   512 	                                                                                                                
       
   513 	if (length == 0 )                                                                                     
       
   514 	   {                                                                                                  
       
   515 	   return;                                                                                            
       
   516 	   }                                                                                                  
       
   517 	if (length > 2 )                                                                                      
       
   518 	   {                                                                                                  
       
   519 	   // Check if file path contains drive selector                                                      
       
   520 	   if ( aFilePath.Mid( 1, 2 ) == KDriveSelector )                                                     
       
   521 	       {                                                                                               
       
   522 	       // File path contains selector letter so we have nothing to do here                             
       
   523 	       return;                                                                                         
       
   524 	       }                                                                                               
       
   525 	   }                                                                                                  
       
   526 	                                                                                                                
       
   527 	// Check if file path contains backslash at the begining and                                          
       
   528 	// select proper drive selector format according to this information                                  
       
   529 	TInt driveSelectorFormat = 2;                                                                         
       
   530 	if ( aFilePath.Mid( 0, 1 ) == KBackslash )                                                            
       
   531 	   {                                                                                               
       
   532 	   driveSelectorFormat = 1;                                                                        
       
   533 	   }                                                                                               
       
   534 	                                                                                                                
       
   535 	RFs rfs;                                                                                              
       
   536 	if ( rfs.Connect() != KErrNone )                                                                      
       
   537 	   {                                                                                                  
       
   538 	   return;                                                                                            
       
   539 	   }                                                                                                  
       
   540 	                                                                                                                
       
   541 	// Get available drives list, revers it order and move z drive at                                     
       
   542 	// the end of the list.  
       
   543 	TDriveList drivesList; 
       
   544 	rfs.DriveList(drivesList); 
       
   545 
       
   546 	// Set drive variable to last drive (except for Z, which will be checked at the end)
       
   547 	char drive = 'Y' ;
       
   548 
       
   549 	// Loop through all the drives in following order: YX..CBAZ
       
   550 	while(drive >= 'A' && drive <= 'Z')
       
   551 	     {
       
   552 	     // Do further action only if drive exists
       
   553 	     TInt driveint;
       
   554 	     rfs.CharToDrive(drive, driveint);
       
   555 	     if(drivesList[driveint])
       
   556 	          {
       
   557 	          //further checking (drive selector and file existence)
       
   558 	          
       
   559 	          // Prepare drive selector                                                                         
       
   560 	          TBuf<3> driveSelector;                                                                            
       
   561 	          if ( driveSelectorFormat == 1 )                                                                   
       
   562 	              {                                                                                           
       
   563 	              driveSelector.Format( KDriveSelectorFormat_1, drive );                                    
       
   564 	              }                                                                                           
       
   565 	          else if ( driveSelectorFormat == 2 )                                                              
       
   566 	              {                                                                                           
       
   567 	              driveSelector.Format( KDriveSelectorFormat_2, drive );                                    
       
   568 	              }                                                                                           
       
   569 	                                                                                                                
       
   570 	          aFilePath.Insert( 0, driveSelector );                                                             
       
   571 	                                                                                                                
       
   572 	          TEntry entry;                                                                                     
       
   573 	          if ( rfs.Entry(aFilePath, entry) == KErrNone )                                                    
       
   574 	              {                                                                                         
       
   575 	              rfs.Close();                                                                                
       
   576 	              return;                                                                                     
       
   577 	              }                                                                                           
       
   578 	                                                                                                                
       
   579 	          // File does not exists on selected drive. Restoring orginal file path                            
       
   580 	          aFilePath.Delete( 0, driveSelector.Length() );    	         
       
   581 	          }//if(drivesList[driveint])       
       
   582 	            
       
   583 	   // Select next drive
       
   584 	   if(drive == 'Z')
       
   585 	       break; // the last driver
       
   586 	   else if(drive ==  'A' )
       
   587 	       drive = 'Z'; //after checking A check Z
       
   588 	   else
       
   589 	       drive =  (TChar)(TInt(drive)-1) ; //after checking Y check X and so on in reverse alphabetical order
       
   590 	   } //while 
       
   591 	rfs.Close(); 
       
   592 	}
       
   593 
       
   594 /*
       
   595 -------------------------------------------------------------------------------
       
   596 
       
   597     Class: TStifUtil
       
   598 
       
   599     Method: STIFVersion
       
   600 
       
   601     Description: Method used to retrieve version of STIF by both STIF and STIF UI 
       
   602 
       
   603     Parameters: TInt& aMajorV - parameter used to pass major STIF version
       
   604      			TInt& aMinorV - parameter used to pass minor STIF version
       
   605      			TInt& aBuildV - parameter used to pass build version of STIF
       
   606      			TDes& aRelDate - parameter used to pass information about release date
       
   607 
       
   608     Return Values: None
       
   609 
       
   610 -------------------------------------------------------------------------------
       
   611 */
       
   612 EXPORT_C void TStifUtil::STIFVersion(TInt& aMajorV, TInt& aMinorV, TInt& aBuildV, TDes& aRelDate)
       
   613 	{
       
   614 	aMajorV = STIF_MAJOR_VERSION;
       
   615 	aMinorV = STIF_MINOR_VERSION;
       
   616 	aBuildV = STIF_BUILD_VERSION;
       
   617 	aRelDate = TO_UNICODE(STIF_REL_DATE);
       
   618 	}
       
   619 
       
   620 // End of File