stif/TestInterface/src/TestModuleIf.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 TestModuleIf implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include <e32svr.h>
       
    20 #include "StifTFwIfProt.h"
       
    21 #include "StifTestInterface.h"
       
    22 #include "TestServerModuleIf.h"
       
    23 #include "StifTestModule.h"
       
    24 #include "TestThreadContainer.h"
       
    25 #include "STIFMeasurement.h"
       
    26 
       
    27 // EXTERNAL DATA STRUCTURES
       
    28 // None
       
    29 
       
    30 // EXTERNAL FUNCTION PROTOTYPES  
       
    31 // None
       
    32 
       
    33 // CONSTANTS
       
    34 // None
       
    35 
       
    36 // MACROS
       
    37 // Debugging is enabled with next define
       
    38 #define __TRACING_ENABLED
       
    39 #ifdef __TRACING_ENABLED
       
    40 #define __RDEBUG(p) RDebug::Print p 
       
    41 #else
       
    42 #define __RDEBUG(p)
       
    43 #endif
       
    44 
       
    45 // LOCAL CONSTANTS AND MACROS
       
    46 // None
       
    47 
       
    48 // MODULE DATA STRUCTURES
       
    49 // None
       
    50 
       
    51 // LOCAL FUNCTION PROTOTYPES
       
    52 // None
       
    53 
       
    54 // FORWARD DECLARATIONS
       
    55 // None
       
    56 
       
    57 // ==================== LOCAL FUNCTIONS =======================================
       
    58 
       
    59 /*
       
    60 -------------------------------------------------------------------------------
       
    61 
       
    62     DESCRIPTION
       
    63 
       
    64     TDesOverflowHandler class contains a simple overflow handler implementation.
       
    65 
       
    66 -------------------------------------------------------------------------------
       
    67 */
       
    68 class TDesOverflowHandler : public TDes16Overflow
       
    69     {
       
    70     public:
       
    71         TDesOverflowHandler( CTestModuleIf* aModuleIf, 
       
    72                              const TInt aPriority, 
       
    73                              const TDesC& aDefinition)
       
    74             {
       
    75             iModuleIf = aModuleIf;
       
    76             iPriority = aPriority;
       
    77             iDefinition = aDefinition;
       
    78             }
       
    79 
       
    80         void Overflow(TDes16& /*aDes*/ )
       
    81             { 
       
    82             }
       
    83     
       
    84         CTestModuleIf* iModuleIf;
       
    85         TInt iPriority;
       
    86         TStifInfoName iDefinition;
       
    87     };
       
    88 
       
    89 /*
       
    90 -------------------------------------------------------------------------------
       
    91 
       
    92     DESCRIPTION
       
    93 
       
    94     This module contains the implementation of CTestModuleIf class 
       
    95     member functions.
       
    96 
       
    97 -------------------------------------------------------------------------------
       
    98 */
       
    99 
       
   100 // ================= MEMBER FUNCTIONS =========================================
       
   101 
       
   102 /*
       
   103 -------------------------------------------------------------------------------
       
   104 
       
   105     Class: CTestModuleIf
       
   106 
       
   107     Method: CTestModuleIf
       
   108 
       
   109     Description: Default constructor
       
   110 
       
   111     C++ default constructor can NOT contain any code, that
       
   112     might leave.
       
   113     
       
   114     Parameters: None
       
   115     
       
   116     Return Values: None
       
   117     
       
   118     Errors/Exceptions: None
       
   119     
       
   120     Status: Approved
       
   121     
       
   122 -------------------------------------------------------------------------------
       
   123 */
       
   124 CTestModuleIf::CTestModuleIf( CTestThreadContainer* aTestExecution ) :
       
   125     iTestExecution( aTestExecution )
       
   126     {
       
   127     }
       
   128 
       
   129 /*
       
   130 -------------------------------------------------------------------------------
       
   131 
       
   132     Class: CTestModuleIf
       
   133 
       
   134     Method: ConstructL
       
   135 
       
   136     Description: Symbian OS second phase constructor
       
   137 
       
   138     Symbian OS default constructor can leave.
       
   139 
       
   140     Parameters: CTestExecution* aTestExecution: in: Pointer to TestExecution
       
   141                 CTestModuleBase* aTestModule: in: Pointer to TestModule
       
   142     
       
   143     Return Values: None
       
   144     
       
   145     Errors/Exceptions: None
       
   146     
       
   147     Status: Approved
       
   148     
       
   149 -------------------------------------------------------------------------------
       
   150 */
       
   151 void CTestModuleIf::ConstructL( CTestModuleBase* aTestModule )
       
   152     {
       
   153 
       
   154     if ( aTestModule->iTestModuleIf != NULL)
       
   155         {
       
   156         delete aTestModule->iTestModuleIf;
       
   157         aTestModule->iTestModuleIf = NULL;
       
   158         }
       
   159     aTestModule->iTestModuleIf = this; 
       
   160 
       
   161     iIsRebootReady = EFalse;
       
   162     iStoreStateCounter = 0;
       
   163 
       
   164     // Used to "resets" iTestCaseResults array
       
   165     iAllowTestCaseResultsCount = 0;
       
   166 
       
   167     }
       
   168 
       
   169 /*
       
   170 -------------------------------------------------------------------------------
       
   171 
       
   172     Class: CTestModuleIf
       
   173 
       
   174     Method: NewL
       
   175 
       
   176     Description: Two-phased constructor.
       
   177 
       
   178     Parameters: CTestExecution* aTestExecution: in: Pointer to TestExecution
       
   179                 CTestModuleBase* aTestModule: in: Pointer to TestModule
       
   180     
       
   181     Return Values: CTestModuleIf object.
       
   182 
       
   183     Errors/Exceptions: Leaves if memory allocation fails
       
   184                        Leaves if ConstructL leaves
       
   185 
       
   186     Status: Approved
       
   187     
       
   188 -------------------------------------------------------------------------------
       
   189 */
       
   190 EXPORT_C CTestModuleIf* CTestModuleIf::NewL( CTestThreadContainer* aExecutionSession, 
       
   191                                              CTestModuleBase* aTestModule )
       
   192     {
       
   193 
       
   194     CTestModuleIf* self = 
       
   195         new (ELeave) CTestModuleIf( aExecutionSession );
       
   196     
       
   197     CleanupStack::PushL( self );
       
   198     self->ConstructL( aTestModule );
       
   199 
       
   200     CleanupStack::Pop();
       
   201 
       
   202     return self;
       
   203 
       
   204     }
       
   205 
       
   206 /*
       
   207 -------------------------------------------------------------------------------
       
   208 
       
   209     Class: CTestModuleIf
       
   210 
       
   211     Method: ~CTestModuleIf
       
   212 
       
   213     Description: Destructor
       
   214     
       
   215     Parameters: None
       
   216     
       
   217     Return Values: None
       
   218 
       
   219     Errors/Exceptions: None
       
   220     
       
   221     Status: Approved
       
   222     
       
   223 -------------------------------------------------------------------------------
       
   224 */    
       
   225 CTestModuleIf::~CTestModuleIf()
       
   226     {
       
   227     iTestExecution = NULL;
       
   228 
       
   229     // Used to "resets" iTestCaseResults array
       
   230     iAllowTestCaseResultsCount = 0;
       
   231 
       
   232     }
       
   233 
       
   234 /*
       
   235 -------------------------------------------------------------------------------
       
   236 
       
   237     Class: CTestModuleIf
       
   238 
       
   239     Method: Printf
       
   240 
       
   241     Description: Printing
       
   242 
       
   243     Printf is used to provide different information up to the UI 
       
   244     that can be then printed e.g. to the Console Screen. 
       
   245     The priority can be used in the UI to decide if the information 
       
   246     received from the Test DLL will be discarded or not in 
       
   247     the different performance situations. The priority is also 
       
   248     used in the Test DLL server and in the Test Engine to queue 
       
   249     the Printf responses.
       
   250     This method is implemented in Test DLL Server and the Test DLL 
       
   251     can call it to provide printable information to the UI.
       
   252 
       
   253     Parameters:  const TInt aPriority: in: 
       
   254                     Importance of the returned information
       
   255                  const TDesC& aDefinition: in: 
       
   256                     Definition of data to be printed 
       
   257                  TRefByValue<const TDesC> aFmt: in: Printed data
       
   258     
       
   259     Return Values: None
       
   260     
       
   261     Errors/Exceptions: None
       
   262     
       
   263     Status: Approved
       
   264     
       
   265 -------------------------------------------------------------------------------
       
   266 */
       
   267 EXPORT_C void CTestModuleIf::Printf( const TInt aPriority, 
       
   268                                      const TDesC& aDefinition, 
       
   269                                      TRefByValue<const TDesC> aFmt,
       
   270                                      ... 
       
   271                                    )
       
   272     {           
       
   273 
       
   274     if( !IsServerAlive() )
       
   275         {
       
   276         return;
       
   277         }
       
   278 
       
   279     VA_LIST list;
       
   280     VA_START(list,aFmt);
       
   281     TName aBuf;
       
   282     RBuf buf;
       
   283     TInt ret = buf.Create(1024);
       
   284     if(ret != KErrNone)
       
   285         {
       
   286         __RDEBUG((_L("STF: Printf: Buffer creation failed [%d]"), ret));
       
   287         return;
       
   288         }
       
   289 
       
   290     // Cut the description length
       
   291     TInt len = aDefinition.Length();
       
   292     if ( len > KMaxInfoName )
       
   293         {
       
   294         len = KMaxInfoName;
       
   295         }
       
   296 
       
   297     TStifInfoName shortDescription = aDefinition.Left(len);
       
   298 
       
   299     // Create overflow handler
       
   300     TDesOverflowHandler overFlowHandler (this, aPriority, shortDescription);
       
   301 
       
   302     // Parse parameters
       
   303     buf.AppendFormatList(aFmt, list, &overFlowHandler);
       
   304     
       
   305     if(buf.Length() == 0)
       
   306         {
       
   307         __RDEBUG((_L("STF: Printf: Unable to prepare print buffer (probably printed string is too long)")));
       
   308         }
       
   309 
       
   310     // Print
       
   311     aBuf.Copy(buf.Left(aBuf.MaxLength()));
       
   312     buf.Close();
       
   313 
       
   314     iTestExecution->DoNotifyPrint( aPriority, shortDescription, aBuf );
       
   315 
       
   316     }
       
   317 
       
   318 /*
       
   319 -------------------------------------------------------------------------------
       
   320 
       
   321     Class: CTestModuleIf
       
   322 
       
   323     Method: Event
       
   324 
       
   325     Description: Event control.
       
   326 
       
   327     Event function is used to control and use the event system. 
       
   328     TEventIf &aEvent encapsulates the request type and 
       
   329     the event name, see StifTestEventInterface.h for more information.
       
   330     This method is implemented in Test DLL Server and the Test DLL 
       
   331     can call it to control the event system.
       
   332   
       
   333     Parameters: TEventIf& aEvent: in: Event command
       
   334     
       
   335     Return Values: Symbian OS error code.
       
   336 
       
   337     Errors/Exceptions: None
       
   338 
       
   339     Status: Approved
       
   340     
       
   341 -------------------------------------------------------------------------------
       
   342 */      
       
   343 EXPORT_C TInt CTestModuleIf::Event( TEventIf& aEvent )
       
   344     {
       
   345 
       
   346     if( !IsServerAlive() )
       
   347         {
       
   348         return KErrGeneral;
       
   349         }
       
   350 
       
   351     // All event commands are handled in testserver and testengine
       
   352     return iTestExecution->DoNotifyEvent( aEvent );
       
   353     
       
   354     }
       
   355 
       
   356 /*
       
   357 -------------------------------------------------------------------------------
       
   358 
       
   359     Class: CTestModuleIf
       
   360 
       
   361     Method: Event
       
   362 
       
   363     Description: Event control.
       
   364 
       
   365     Asynchronous version of event control function.
       
   366     It is used to control and use the event system asynchronously. 
       
   367     TEventIf &aEvent encapsulates the request type and 
       
   368     the event number, see StifTestEventInterface.h for more information.
       
   369     This method is implemented in Test DLL Server and the Test DLL 
       
   370     can call it to control the event system.
       
   371   
       
   372     Parameters: TEventIf& aEvent: in: Event command
       
   373                 TRequestStatus& aStatus: in: Request status parameter
       
   374 
       
   375     Return Values: None. 
       
   376     
       
   377     Errors/Exceptions: None
       
   378 
       
   379     Status: Approved
       
   380     
       
   381 -------------------------------------------------------------------------------
       
   382 */      
       
   383 EXPORT_C void CTestModuleIf::Event( TEventIf& aEvent, TRequestStatus& aStatus )
       
   384     {
       
   385     TInt ret = KErrNone;
       
   386 
       
   387     if( !IsServerAlive() )
       
   388         {
       
   389         __RDEBUG( (_L("iTestExecution not initialised")));
       
   390         ret = KErrGeneral;
       
   391         }
       
   392     else
       
   393         {        
       
   394         aStatus = KRequestPending;
       
   395 
       
   396         // All event commands are handled in testserver and testengine
       
   397         ret = iTestExecution->DoNotifyEvent( aEvent, &aStatus );
       
   398         }
       
   399     if( ret != KErrNone )
       
   400         {
       
   401         TRequestStatus* rs = &aStatus;
       
   402         User::RequestComplete( rs, ret );
       
   403         }
       
   404     
       
   405     }
       
   406     
       
   407 /*
       
   408 -------------------------------------------------------------------------------
       
   409 
       
   410     Class: CTestModuleIf
       
   411 
       
   412     Method: CancelEvent
       
   413 
       
   414     Description: Cancel asynchronous event control call.
       
   415   
       
   416     Parameters: TEventIf& aEvent: in: Event command to be cancelled.
       
   417                 const TRequestStatus* aStatus: in: 
       
   418                     Pointer to TRequestStatus parameter that is cancelled
       
   419 
       
   420     Return Values: Symbian OS error code.
       
   421     
       
   422     Errors/Exceptions: None
       
   423     
       
   424     Status: Approved
       
   425     
       
   426 -------------------------------------------------------------------------------
       
   427 */      
       
   428 EXPORT_C TInt CTestModuleIf::CancelEvent( TEventIf& aEvent,
       
   429                                           TRequestStatus* aStatus )
       
   430     {
       
   431      if( !IsServerAlive() )
       
   432         {
       
   433         __RDEBUG( (_L("iTestExecution not initialised")));
       
   434         return KErrGeneral;
       
   435         }
       
   436 
       
   437     // All event commands are handled in testserver and testengine
       
   438     iTestExecution->CancelEvent( aEvent, aStatus );
       
   439     
       
   440     return KErrNone;
       
   441     
       
   442     }
       
   443 
       
   444 
       
   445 /*
       
   446 -------------------------------------------------------------------------------
       
   447 
       
   448     Class: CTestModuleIf
       
   449 
       
   450     Method: SetExitReason
       
   451 
       
   452     Description: Set exit reason
       
   453   
       
   454     Parameters: const TExitReason aExitReason in: Exit reason
       
   455                 const TInt aExitCode in: Exit code
       
   456 
       
   457     Return Values: None
       
   458     
       
   459     Errors/Exceptions: None
       
   460     
       
   461     Status: Proposal
       
   462     
       
   463 -------------------------------------------------------------------------------
       
   464 */      
       
   465 EXPORT_C void CTestModuleIf::SetExitReason( const CTestModuleIf::TExitReason aExitReason, 
       
   466                                             const TInt aExitCode )
       
   467         
       
   468     {
       
   469 
       
   470      if( !IsServerAlive() )
       
   471         {
       
   472         __RDEBUG( (_L("iTestExecution not initialised")));
       
   473         return;
       
   474         }
       
   475     
       
   476     iTestExecution->SetExitReason( aExitReason, aExitCode );
       
   477     
       
   478     }
       
   479 
       
   480 /*
       
   481 -------------------------------------------------------------------------------
       
   482 
       
   483     Class: CTestModuleIf
       
   484 
       
   485     Method: RemoteSend
       
   486 
       
   487     Description: RemoteSend is used to send control protocol messages to slaves
       
   488         (e.g. another phone, call box, ...). 
       
   489     
       
   490     Parameters:  const TDesC& aRemoteMsg: in: 
       
   491                     Remote command protocol message 
       
   492                  
       
   493     Return Values: None
       
   494     
       
   495     Errors/Exceptions: None
       
   496     
       
   497     Status: Proposal
       
   498     
       
   499 -------------------------------------------------------------------------------
       
   500 */
       
   501 EXPORT_C TInt CTestModuleIf::RemoteSend( const TDesC& aRemoteMsg )
       
   502     {           
       
   503 
       
   504     if( !IsServerAlive() )
       
   505         {
       
   506         __RDEBUG( ( _L("iTestExecution not initialised") ) );
       
   507         return KErrNotReady;
       
   508         }
       
   509 
       
   510     TParams params;
       
   511     params.aRemoteMsgConstRef = &aRemoteMsg;
       
   512 
       
   513     TRequestStatus status = KRequestPending; 
       
   514 
       
   515     // Forward
       
   516     iTestExecution->DoRemoteReceive( EStifCmdSend, params, 
       
   517                                      aRemoteMsg.Length(), status );
       
   518     
       
   519     User::WaitForRequest( status );
       
   520 
       
   521     return status.Int();
       
   522 
       
   523     }
       
   524     
       
   525 /*
       
   526 -------------------------------------------------------------------------------
       
   527 
       
   528     Class: CTestModuleIf
       
   529 
       
   530     Method: RemoteReceive
       
   531 
       
   532     Description: RemoteReceive is used to receive control protocol messages to 
       
   533         slaves (e.g. another phone, call box, ...). 
       
   534     
       
   535     Parameters:  const TDesC& aRemoteMsg: in: 
       
   536                     Remote command protocol message 
       
   537                  TRequestStatus& aStatus: in: Request status parameter
       
   538 
       
   539     Return Values: None
       
   540     
       
   541     Errors/Exceptions: None
       
   542     
       
   543     Status: Proposal
       
   544     
       
   545 -------------------------------------------------------------------------------
       
   546 */
       
   547 EXPORT_C void CTestModuleIf::RemoteReceive( TDes& aRemoteMsg, 
       
   548                                             TRequestStatus& aStatus )
       
   549     {           
       
   550     aStatus = KRequestPending;
       
   551     if( !IsServerAlive() )
       
   552         {
       
   553         __RDEBUG( ( _L("iTestExecution not initialised") ) );
       
   554         TRequestStatus* rs = &aStatus;
       
   555         User::RequestComplete( rs, KErrNotReady );
       
   556         }
       
   557 
       
   558     TParams params;
       
   559     params.aRemoteMsgRef = &aRemoteMsg;
       
   560 
       
   561     iTestExecution->DoRemoteReceive( EStifCmdReceive, params, 
       
   562                                      aRemoteMsg.Length(), aStatus );
       
   563 
       
   564     }
       
   565     
       
   566 /*
       
   567 -------------------------------------------------------------------------------
       
   568 
       
   569     Class: CTestModuleIf
       
   570 
       
   571     Method: RemoteReceiveCancel
       
   572 
       
   573     Description: RemoteReceiveCancel is used to cancel RemoteReceive.
       
   574      
       
   575     Parameters:  None
       
   576     
       
   577     Return Values: None
       
   578     
       
   579     Errors/Exceptions: None
       
   580     
       
   581     Status: Proposal
       
   582     
       
   583 -------------------------------------------------------------------------------
       
   584 */
       
   585 EXPORT_C void CTestModuleIf::RemoteReceiveCancel()
       
   586     {           
       
   587     if( !IsServerAlive() )
       
   588         {
       
   589         __RDEBUG( ( _L("iTestExecution not initialised") ) );
       
   590         return;
       
   591         }
       
   592 
       
   593     // Forward
       
   594     iTestExecution->DoRemoteReceiveCancel();
       
   595 
       
   596     }
       
   597 
       
   598 /*
       
   599 -------------------------------------------------------------------------------
       
   600 
       
   601     Class: CTestModuleIf
       
   602 
       
   603     Method: Reboot
       
   604 
       
   605     Description: Start a reboot operation.
       
   606 
       
   607     Parameters: TInt aType: in: Reboot type
       
   608 
       
   609     Return Values: TInt: Symbian OS error code.
       
   610 
       
   611     Errors/Exceptions: KErrNotReady returned if iTestExecution is NULL.
       
   612                        KErrNotReady returned if reboot not allowed(Store state
       
   613                        not called).
       
   614 
       
   615     Status: Proposal
       
   616 
       
   617 -------------------------------------------------------------------------------
       
   618 */
       
   619 EXPORT_C TInt CTestModuleIf::Reboot( TInt aType )
       
   620     {           
       
   621     if ( !IsServerAlive() )
       
   622         {
       
   623         __RDEBUG( ( _L( "iTestExecution not initialised" ) ) );
       
   624         return KErrNotReady;
       
   625         }
       
   626     if( !iIsRebootReady )
       
   627         {
       
   628         __RDEBUG( ( _L( "Reboot operation not ready" ) ) );
       
   629         return KErrNotReady;
       
   630         }
       
   631      
       
   632 /*    switch( aType )
       
   633         {
       
   634         case EDefaultReset:
       
   635             __RDEBUG( ( _L( "Reboot, type default" )) );
       
   636             break;
       
   637         case EKernelReset:
       
   638             __RDEBUG( ( _L( "Reboot, type KernelReset" )) );
       
   639             break;
       
   640         case EDeviceReset0:
       
   641             __RDEBUG( ( _L( "Reboot, type Reset 0" )) );
       
   642             break;
       
   643         case EDeviceReset1:
       
   644             __RDEBUG( ( _L( "Reboot, type Reset 1" )) );
       
   645             break;
       
   646         case EDeviceReset2:
       
   647             __RDEBUG( ( _L( "Reboot, type Reset 2" )) );
       
   648             break;
       
   649         case EDeviceReset3:
       
   650             __RDEBUG( ( _L( "Reboot, type Reset 3" )) );
       
   651             break;
       
   652         case EDeviceReset4:
       
   653             __RDEBUG( ( _L( "Reboot, type Reset 4" )) );
       
   654             break;
       
   655         case EDeviceReset5:
       
   656             __RDEBUG( ( _L( "Reboot, type Reset 5" )) );
       
   657             break;
       
   658         default:
       
   659             __RDEBUG( ( _L( "Reboot type %d not supported" ), aType ) );
       
   660             return KErrNotSupported;    
       
   661         }
       
   662 */
       
   663 
       
   664     TParams params;
       
   665     TRebootParams rebootParams;
       
   666     
       
   667     params.aRebootType = &rebootParams;
       
   668     rebootParams.aType = ( TRebootType )aType;
       
   669     
       
   670     TRequestStatus status = KRequestPending; 
       
   671 
       
   672     // Forward
       
   673     iTestExecution->DoRemoteReceive( EStifCmdReboot, params, sizeof( aType ), status );
       
   674     
       
   675     User::WaitForRequest( status );
       
   676 
       
   677     return status.Int();
       
   678     
       
   679     }
       
   680 
       
   681 /*
       
   682 -------------------------------------------------------------------------------
       
   683 
       
   684     Class: CTestModuleIf
       
   685 
       
   686     Method: StoreState
       
   687 
       
   688     Description: Stores the current state before reboot.
       
   689 
       
   690     Parameters: TInt aCode: in: Reboot releated integer value.
       
   691                 TName& aName: in: Reboot related string value.
       
   692 
       
   693     Return Values: TInt: Symbian OS error code.
       
   694 
       
   695     Errors/Exceptions: KErrNotReady returned if iTestExecution is NULL.
       
   696                        KErrOverflow returned if aName length is over TName.
       
   697                        KErrInUse returned if method is called more than once.
       
   698 
       
   699     Status: Proposal
       
   700 
       
   701 -------------------------------------------------------------------------------
       
   702 */
       
   703 EXPORT_C TInt CTestModuleIf::StoreState( TInt aCode, TName& aName )
       
   704     {
       
   705     iStoreStateCounter++;   // Store state counter
       
   706 
       
   707     if ( !IsServerAlive() )
       
   708         {
       
   709         __RDEBUG( ( _L( "iTestExecution not initialised" ) ) );
       
   710         return KErrNotReady;
       
   711         }
       
   712     // Check aName length
       
   713     if ( aName.Length() > KMaxName )
       
   714         {
       
   715         __RDEBUG( ( _L( "CTestModuleIf::StoreState(): aName length is not valid" ) ) );
       
   716         return KErrOverflow;
       
   717         }
       
   718     // Only one store state call may be done
       
   719     if( iStoreStateCounter > 1 )
       
   720         {
       
   721         __RDEBUG( ( _L( "Store state allready called" ) ) );
       
   722         return KErrInUse;
       
   723         }
       
   724 
       
   725     TParams params;
       
   726     TRebootStateParams rebootStateParams;
       
   727     params.aRebootState = &rebootStateParams;
       
   728     rebootStateParams.aCode = aCode;
       
   729     rebootStateParams.aName = aName;
       
   730 
       
   731     TRequestStatus status = KRequestPending; 
       
   732 
       
   733     // Forward
       
   734     iTestExecution->DoRemoteReceive( EStifCmdStoreState, params,
       
   735                                      sizeof( TRebootStateParams), status );
       
   736     
       
   737     User::WaitForRequest( status );
       
   738 
       
   739     // If store state is done successfully reboot operation is allowed
       
   740     if( status.Int() == KErrNone )
       
   741         {
       
   742         iIsRebootReady = ETrue;
       
   743         }
       
   744 
       
   745     return status.Int();
       
   746 
       
   747     }
       
   748 
       
   749 /*
       
   750 -------------------------------------------------------------------------------
       
   751 
       
   752     Class: CTestModuleIf
       
   753 
       
   754     Method: GetStoredState
       
   755 
       
   756     Description: Get saved store information after the reboot.
       
   757 
       
   758     Parameters: TInt aCode: inout: Get reboot releated integer value.
       
   759                 TName& aName: inout: Get reboot related string value.
       
   760 
       
   761     Return Values: TInt: Symbian OS error code.
       
   762 
       
   763     Errors/Exceptions: KErrNotReady returned if iTestExecution is NULL.
       
   764 
       
   765     Status: Proposal
       
   766 
       
   767 -------------------------------------------------------------------------------
       
   768 */
       
   769 EXPORT_C TInt CTestModuleIf::GetStoredState( TInt& aCode, TName& aName )
       
   770     {           
       
   771     if( !IsServerAlive() )
       
   772         {
       
   773         __RDEBUG( ( _L( "iTestExecution not initialised" ) ) );
       
   774         return KErrNotReady;
       
   775         }
       
   776 
       
   777     TInt code;
       
   778     TName name;
       
   779     
       
   780     TParams params;
       
   781     TGetRebootStoredParamsRef getRebootStoredParamsRef( code, name );
       
   782     
       
   783     params.aRebootStoredRef = &getRebootStoredParamsRef;
       
   784 
       
   785     TRequestStatus status = KRequestPending; 
       
   786 
       
   787     // Forward
       
   788     iTestExecution->DoRemoteReceive( EStifCmdGetStoredState, params,
       
   789                                      sizeof( TRebootStateParams), status );
       
   790     
       
   791     User::WaitForRequest( status );
       
   792 
       
   793     // Return results if getting state is done without error
       
   794     if(status.Int() == KErrNone)
       
   795         {
       
   796         aCode = code;
       
   797         aName = name;
       
   798         }
       
   799 
       
   800     return status.Int();
       
   801 
       
   802     }
       
   803 
       
   804 /*
       
   805 -------------------------------------------------------------------------------
       
   806 
       
   807     Class: CTestModuleIf
       
   808 
       
   809     Method: SetBehavior
       
   810 
       
   811     Description: Set test case behavior.
       
   812 
       
   813     Parameters: TInt aCode: inout: Get reboot releated integer value.
       
   814                 TName& aName: inout: Get reboot related string value.
       
   815 
       
   816     Return Values: TInt: Symbian OS error code.
       
   817 
       
   818     Errors/Exceptions: KErrNotReady returned if iTestExecution is NULL.
       
   819 
       
   820     Status: Proposal
       
   821 
       
   822 -------------------------------------------------------------------------------
       
   823 */
       
   824 EXPORT_C TInt CTestModuleIf::SetBehavior( TTestBehavior aType, TAny* aPtr )
       
   825     {         
       
   826     
       
   827     if( !IsServerAlive() )
       
   828         {
       
   829         return KErrGeneral;
       
   830         }
       
   831 
       
   832     // All event commands are handled in testserver and testengine
       
   833     return iTestExecution->SetBehavior( aType, aPtr );
       
   834     
       
   835     }
       
   836 
       
   837 /*
       
   838 -------------------------------------------------------------------------------
       
   839 
       
   840     Class: CTestModuleIf
       
   841 
       
   842     Method: StifMacroError
       
   843 
       
   844     Description: STIF TF's macros. Saves information for later use.
       
   845 
       
   846     Parameters: TInt aMacroType: in: Macro type(0:TL, 1:T1L, 2:T2L, etc.)
       
   847                 const TText8* aFile: in: Uses __FILE__ macro and this includes
       
   848                 path and file name. Maximun length for this is
       
   849                 KStifMacroMaxFile. If length is more then cutted from left.
       
   850                 char* aFunction: in: Uses __FUNCTION__ macro and this includes
       
   851                 function name. Maximun length for this is
       
   852                 KStifMacroMaxFunction. If length is more then cutted from
       
   853                 rigth.
       
   854                 TInt aLine: in: Uses __LINE__ macro and includes line number.
       
   855                 TInt aResult: in: Result from called operations.
       
   856                 TInt aExpected1: in: Users expected result.
       
   857                 TInt aExpected2: in: Users expected result.
       
   858                 TInt aExpected3: in: Users expected result.
       
   859                 TInt aExpected4: in: Users expected result.
       
   860                 TInt aExpected5: in: Users expected result.
       
   861 
       
   862     Return Values: Symbian OS error code.
       
   863 
       
   864     Errors/Exceptions: None
       
   865 
       
   866     Status: Proposal
       
   867 
       
   868 -------------------------------------------------------------------------------
       
   869 */
       
   870 EXPORT_C TInt CTestModuleIf::StifMacroError( TInt aMacroType, 
       
   871                                              const TText8* aFile,
       
   872                                              const char* aFunction,
       
   873                                              TInt aLine,
       
   874                                              TInt aResult,
       
   875                                              TInt aExpected1,
       
   876                                              TInt aExpected2,
       
   877                                              TInt aExpected3,
       
   878                                              TInt aExpected4,
       
   879                                              TInt aExpected5 )
       
   880     {
       
   881     if( !IsServerAlive() )
       
   882         {
       
   883         return KErrGeneral;
       
   884         }
       
   885 
       
   886     return iTestExecution->StifMacroError( aMacroType, aFile,
       
   887                                            aFunction, aLine,
       
   888                                            aResult, aExpected1,
       
   889                                            aExpected2, aExpected3,
       
   890                                            aExpected4, aExpected5 );
       
   891 
       
   892     }
       
   893 
       
   894 /*
       
   895 -------------------------------------------------------------------------------
       
   896 
       
   897     Class: CTestModuleIf
       
   898 
       
   899     Method: ServerAlive
       
   900 
       
   901     Description: Get saved store information after the reboot.
       
   902 
       
   903     Parameters: TInt aCode: inout: Get reboot releated integer value.
       
   904                 TName& aName: inout: Get reboot related string value.
       
   905 
       
   906     Return Values: TInt: Symbian OS error code.
       
   907 
       
   908     Errors/Exceptions: KErrNotReady returned if iTestExecution is NULL.
       
   909 
       
   910     Status: Proposal
       
   911 
       
   912 -------------------------------------------------------------------------------
       
   913 */
       
   914 TBool CTestModuleIf::IsServerAlive()
       
   915     {
       
   916     
       
   917     if( iTestExecution == NULL )
       
   918         {
       
   919         __RDEBUG( ( _L( "iTestExecution not initialised" ) ) );
       
   920         // Execution not initialized
       
   921         return EFalse;
       
   922         }
       
   923        
       
   924     return ETrue;
       
   925     
       
   926     }
       
   927 
       
   928 /*
       
   929 -------------------------------------------------------------------------------
       
   930 
       
   931     Class: CTestModuleIf
       
   932 
       
   933     Method: AddInterferenceThread
       
   934 
       
   935     Description: 
       
   936 
       
   937     Parameters: RThread aSTIFTestInterference: in: Handle to RThread
       
   938 
       
   939     Return Values: TInt: Symbian OS error code.
       
   940 
       
   941     Errors/Exceptions: 
       
   942 
       
   943     Status: Proposal
       
   944 
       
   945 -------------------------------------------------------------------------------
       
   946 */
       
   947 TInt CTestModuleIf::AddInterferenceThread( RThread aSTIFTestInterference )
       
   948     {
       
   949     // Add thread to Array. Via array can handle test interference thread's
       
   950     // kill in panic etc. cases
       
   951     return iTestExecution->AddInterferenceThread( aSTIFTestInterference );
       
   952 
       
   953     }
       
   954 
       
   955 /*
       
   956 -------------------------------------------------------------------------------
       
   957 
       
   958     Class: CTestModuleIf
       
   959 
       
   960     Method: RemoveInterferenceThread
       
   961 
       
   962     Description: 
       
   963 
       
   964     Parameters: RThread aSTIFTestInterference: in: Handle to RThread
       
   965 
       
   966     Return Values: TInt: Symbian OS error code.
       
   967 
       
   968     Errors/Exceptions: 
       
   969 
       
   970     Status: Proposal
       
   971 
       
   972 -------------------------------------------------------------------------------
       
   973 */
       
   974 TInt CTestModuleIf::RemoveInterferenceThread( RThread aSTIFTestInterference )
       
   975     {
       
   976     // Remove thread from Array.Test interference thread is stopped and killed
       
   977     // successfully
       
   978     return iTestExecution->RemoveInterferenceThread( aSTIFTestInterference );
       
   979 
       
   980     }
       
   981 
       
   982 /*
       
   983 -------------------------------------------------------------------------------
       
   984 
       
   985     Class: CTestModuleIf
       
   986 
       
   987     Method: HandleMeasurementProcess
       
   988 
       
   989     Description: With this can be stored information about test measurement
       
   990                  to TestServer space.
       
   991 
       
   992     Parameters: RProcess aTestMeasurement: in: Handle to RProcess
       
   993 
       
   994     Return Values: TInt: Symbian OS error code.
       
   995 
       
   996     Errors/Exceptions: 
       
   997 
       
   998     Status: Approved
       
   999 
       
  1000 -------------------------------------------------------------------------------
       
  1001 */
       
  1002 TInt CTestModuleIf::HandleMeasurementProcess( 
       
  1003             CSTIFTestMeasurement::TStifMeasurementStruct aSTIFMeasurementInfo )
       
  1004     {
       
  1005     // Add process to Array. Via array can handle test measurement process's
       
  1006     // kill in panic etc. cases
       
  1007     return iTestExecution->HandleMeasurementProcess( aSTIFMeasurementInfo );
       
  1008 
       
  1009     }
       
  1010 
       
  1011 /*
       
  1012 -------------------------------------------------------------------------------
       
  1013 
       
  1014     Class: CTestModuleIf
       
  1015 
       
  1016     Method: GetMeasurementOptions
       
  1017 
       
  1018     Description: Get measurement option(s) given from initialization file etc.
       
  1019 
       
  1020     Parameters: TInt& aOptions: inout: Get measurement option(s)
       
  1021 
       
  1022     Return Values: TInt: Symbian OS error code.
       
  1023 
       
  1024     Errors/Exceptions: KErrNotReady returned if iTestExecution is NULL.
       
  1025 
       
  1026     Status: Approved
       
  1027 
       
  1028 -------------------------------------------------------------------------------
       
  1029 */
       
  1030 EXPORT_C TInt CTestModuleIf::GetMeasurementOptions( TInt& aOptions )
       
  1031     {           
       
  1032     if( !IsServerAlive() )
       
  1033         {
       
  1034         __RDEBUG( ( _L( "iTestExecution not initialised" ) ) );
       
  1035         return KErrNotReady;
       
  1036         }
       
  1037 
       
  1038     TParams params;
       
  1039     TGetMeasurementOptionsRef getMeasurementOptionsRef( aOptions );
       
  1040     params.aMeasurementOption = &getMeasurementOptionsRef;
       
  1041 
       
  1042     TRequestStatus status = KRequestPending; 
       
  1043 
       
  1044     // Forward
       
  1045     iTestExecution->DoRemoteReceive( EStifCmdMeasurement, params,
       
  1046                                      sizeof( TGetMeasurementOptions ), status );
       
  1047     
       
  1048     User::WaitForRequest( status );
       
  1049 
       
  1050     aOptions = getMeasurementOptionsRef.iOptions;
       
  1051     
       
  1052     return status.Int();
       
  1053 
       
  1054     }
       
  1055 
       
  1056 /*
       
  1057 -------------------------------------------------------------------------------
       
  1058 
       
  1059     Class: CTestModuleIf
       
  1060 
       
  1061     Method: SetAllowResult
       
  1062 
       
  1063     Description: Use with TAL, TA1L, TA2L, TA3L, TA4L and TA5L macros to allow
       
  1064                  results.
       
  1065                  Set test case allow result given by user. In TestScripter
       
  1066                  cases allow result can set by 'allownextresult' or
       
  1067                  'allowerrorcodes' keywords. In Normal and Hardcoded test
       
  1068                  modules allow result can be set with this method, reset should
       
  1069                  be done with ResetAllowResult method.
       
  1070 
       
  1071     Parameters: TInt aResult: in: Result value to be appended.
       
  1072 
       
  1073     Return Values: TInt: Symbian OS error code.
       
  1074 
       
  1075     Errors/Exceptions: None
       
  1076 
       
  1077     Status: Approved
       
  1078 
       
  1079 -------------------------------------------------------------------------------
       
  1080 */
       
  1081 EXPORT_C TInt CTestModuleIf::SetAllowResult( TInt aResult )
       
  1082     {
       
  1083     for( TInt a = 0; a < iAllowTestCaseResultsCount; a++ )
       
  1084         {
       
  1085         // Check that result is not given already
       
  1086         if ( iTestCaseResults[a] == aResult )
       
  1087             {
       
  1088             return KErrNone;
       
  1089             }
       
  1090         }
       
  1091     // If values are given more that allow(see KSTIFMacroResultArraySize).
       
  1092     // Array starts from 0...9 -> 10 => 10th should fail
       
  1093     if( iAllowTestCaseResultsCount >= KSTIFMacroResultArraySize )
       
  1094         {
       
  1095         __RDEBUG( ( 
       
  1096             _L( "STIF macro's SetAllowResult() allow only %d results, fails with %d" ),
       
  1097             KSTIFMacroResultArraySize, KErrOverflow  ) );
       
  1098         return KErrOverflow;
       
  1099         }
       
  1100 
       
  1101     // New result
       
  1102     iAllowTestCaseResultsCount++;
       
  1103     iTestCaseResults[iAllowTestCaseResultsCount-1] = aResult;
       
  1104 
       
  1105     return KErrNone;
       
  1106 
       
  1107     }
       
  1108 
       
  1109 /*
       
  1110 -------------------------------------------------------------------------------
       
  1111 
       
  1112     Class: CTestModuleIf
       
  1113 
       
  1114     Method: CheckAllowResult
       
  1115 
       
  1116     Description: This is mainly used by STIF's TAL-TA5L macros internally.
       
  1117                  Check is macros result allowed result.
       
  1118 
       
  1119     Parameters: TInt aResult: in: Result value to be checked.
       
  1120 
       
  1121     Return Values: TInt: Symbian OS error code.
       
  1122 
       
  1123     Errors/Exceptions: None
       
  1124 
       
  1125     Status: Approved
       
  1126 
       
  1127 -------------------------------------------------------------------------------
       
  1128 */
       
  1129 EXPORT_C TInt CTestModuleIf::CheckAllowResult( TInt aResult )
       
  1130     {
       
  1131     // Check is result allowed
       
  1132     for( TInt a = 0; a < iAllowTestCaseResultsCount; a++ )
       
  1133         {
       
  1134         if ( iTestCaseResults[a] == aResult )
       
  1135             {
       
  1136             // Result is allow
       
  1137             __RDEBUG( ( _L( "STIF TAL-TA5L macro's result check. Test case result[%d] allowed" ),
       
  1138                 aResult ) );
       
  1139             return KErrNone;
       
  1140             }
       
  1141         }
       
  1142 
       
  1143     __RDEBUG( ( 
       
  1144         _L( "STIF TAL-TA5L macro's result check. Test case result[%d] not allowed" ),
       
  1145         aResult ) );
       
  1146     // No match with allow result
       
  1147     return KErrGeneral;
       
  1148 
       
  1149     }
       
  1150 
       
  1151 /*
       
  1152 -------------------------------------------------------------------------------
       
  1153 
       
  1154     Class: CTestModuleIf
       
  1155 
       
  1156     Method: ResetAllowResult
       
  1157 
       
  1158     Description: Use with TAL, TA1L, TA2L, TA3L, TA4L and TA5L macros to reset
       
  1159                  allowed results.
       
  1160                  Reset allow result(s) given with SetAllowResult. In
       
  1161                  TestScripter cases this will be called automatically by STIF.
       
  1162                  Normal and Hardcoded cases this should be called by user.
       
  1163 
       
  1164     Parameters: None.
       
  1165 
       
  1166     Return Values: TInt: Symbian OS error code.
       
  1167 
       
  1168     Errors/Exceptions: None
       
  1169 
       
  1170     Status: Approved
       
  1171 
       
  1172 -------------------------------------------------------------------------------
       
  1173 */
       
  1174 EXPORT_C TInt CTestModuleIf::ResetAllowResult()
       
  1175     {
       
  1176     // Used to "resets" iTestCaseResults array
       
  1177     iAllowTestCaseResultsCount = 0;
       
  1178 
       
  1179     return KErrNone;
       
  1180 
       
  1181     }
       
  1182 
       
  1183 /*
       
  1184 -------------------------------------------------------------------------------
       
  1185 
       
  1186     Class: CTestModuleIf
       
  1187 
       
  1188     Method: StopExecution
       
  1189 
       
  1190     Description: Causes that test case is going to be cancelled.
       
  1191 
       
  1192     Parameters: None
       
  1193 
       
  1194     Return Values: Symbian OS error code.
       
  1195 
       
  1196     Errors/Exceptions: None
       
  1197 
       
  1198     Status: Approved
       
  1199 
       
  1200 -------------------------------------------------------------------------------
       
  1201 */
       
  1202 EXPORT_C TInt CTestModuleIf::StopExecution(TStopExecutionType aType, TInt aCode)
       
  1203     {
       
  1204 
       
  1205     //Check parameters
       
  1206     if((aType == EOk) && (aCode != KErrNone))
       
  1207         {
       
  1208         return KErrArgument;
       
  1209         }
       
  1210     else if((aType != EOk) && (aCode == KErrNone))
       
  1211         {
       
  1212         return KErrArgument;
       
  1213         }
       
  1214 
       
  1215     //Check server
       
  1216     if(!IsServerAlive())
       
  1217         {
       
  1218         return KErrGeneral;
       
  1219         }
       
  1220 
       
  1221     //Everything is ok, we can continue with processing command
       
  1222     _LIT(KStopExecution, "StopExecution");
       
  1223     const TInt KPrintPriority = 30;
       
  1224 
       
  1225     switch(aType)
       
  1226         {
       
  1227         case EOk:
       
  1228             Printf(KPrintPriority, KStopExecution, _L("***Test case PASSED***\n\n"));
       
  1229             break;
       
  1230         case EFail:
       
  1231             Printf(KPrintPriority, KStopExecution, _L("***Test case FAILED***\n\n"));
       
  1232             break;
       
  1233         case EAbort:
       
  1234             Printf(KPrintPriority, KStopExecution, _L("***Test case KILLED***\n\n"));
       
  1235             break;
       
  1236         default:
       
  1237             return KErrNotFound;
       
  1238         }
       
  1239 
       
  1240     TStopExecutionCommandParams params;
       
  1241     params.iType = aType;
       
  1242     params.iCode = aCode;
       
  1243     __RDEBUG((_L("CTestModuleIf::StopExecution(): type [%d] code [%d]"), TInt(aType), aCode));
       
  1244 
       
  1245     TStopExecutionCommandParamsPckg pckg(params);
       
  1246 
       
  1247     TInt res = Command(EStopExecution, pckg);
       
  1248     return res;
       
  1249     }
       
  1250 
       
  1251 /*
       
  1252 ------------------------------------------------------------------------------
       
  1253 
       
  1254 	Class: CTestModuleIf
       
  1255 
       
  1256     Method: SendTestModuleVersion
       
  1257     
       
  1258     Description: SendTestModuleVersion method is used to pass version of test module
       
  1259     
       
  1260 ------------------------------------------------------------------------------
       
  1261  */
       
  1262 EXPORT_C TInt CTestModuleIf::SendTestModuleVersion(TVersion aVersion, TFileName aModuleName)
       
  1263 	{
       
  1264 	if( aModuleName.Length() == 0 )
       
  1265 		{
       
  1266 		return KErrArgument;
       
  1267 		}
       
  1268 	
       
  1269 	//Check server
       
  1270 	if(!IsServerAlive())
       
  1271 	    {
       
  1272 	    return KErrGeneral;
       
  1273 	    }
       
  1274 	
       
  1275 	const TInt KPrintPriority = 30;
       
  1276 	_LIT(KVersion ,"SendTestModuleVersion");
       
  1277 	Printf(KPrintPriority, KVersion, _L("Sending test module version"));
       
  1278 	
       
  1279 	TSendTestModuleVesionCommandParams params;
       
  1280 	params.iMajor = aVersion.iMajor;
       
  1281 	params.iMinor = aVersion.iMinor;
       
  1282 	params.iBuild = aVersion.iBuild;
       
  1283 	params.iTestModuleName = aModuleName;
       
  1284 	
       
  1285 	TSendTestModuleVesionCommandParamsPckg pckg(params);
       
  1286 	TInt res = Command( ESendTestModuleVersion, pckg );
       
  1287 	return res;
       
  1288 	}
       
  1289 
       
  1290 
       
  1291 /*
       
  1292 ------------------------------------------------------------------------------
       
  1293 
       
  1294 	Class: CTestModuleIf
       
  1295 
       
  1296     Method: SendTestModuleVersion
       
  1297     
       
  1298     Description: SendTestModuleVersion method is used to pass version of test module.
       
  1299     			This version uses three parameters to enable the overloading of version with
       
  1300     			two parameters. The version with two params has params passed by value which
       
  1301     			is incorrect. The "old" version (with two parameters) is left here not to cause
       
  1302     			binary break. Only this version (with three parameters) should be used.
       
  1303     
       
  1304 ------------------------------------------------------------------------------
       
  1305  */
       
  1306 EXPORT_C TInt CTestModuleIf::SendTestModuleVersion(TVersion& aVersion, const TDesC& aModuleName, TBool /*aNewVersion*/)
       
  1307 	{
       
  1308 	if( aModuleName.Length() == 0 )
       
  1309 		{
       
  1310 		return KErrArgument;
       
  1311 		}
       
  1312 	
       
  1313 	//Check server
       
  1314 	if(!IsServerAlive())
       
  1315 	    {
       
  1316 	    return KErrGeneral;
       
  1317 	    }
       
  1318 	
       
  1319 	const TInt KPrintPriority = 30;
       
  1320 	_LIT(KVersion ,"SendTestModuleVersion");
       
  1321 	Printf(KPrintPriority, KVersion, _L("Sending test module version"));
       
  1322 	
       
  1323 	TSendTestModuleVesionCommandParams params;
       
  1324 	params.iMajor = aVersion.iMajor;
       
  1325 	params.iMinor = aVersion.iMinor;
       
  1326 	params.iBuild = aVersion.iBuild;
       
  1327 	params.iTestModuleName = aModuleName;
       
  1328 	
       
  1329 	TSendTestModuleVesionCommandParamsPckg pckg(params);
       
  1330 	TInt res = Command( ESendTestModuleVersion, pckg );
       
  1331 	return res;
       
  1332 	}
       
  1333 
       
  1334 /*
       
  1335 -------------------------------------------------------------------------------
       
  1336 
       
  1337     Class: CTestModuleIf
       
  1338 
       
  1339     Method: Command
       
  1340 
       
  1341     Description: Sends specific command to TestServer.
       
  1342 
       
  1343     Parameters: aCommand - command to be send
       
  1344 
       
  1345     Return Values: Symbian OS error code.
       
  1346 
       
  1347     Errors/Exceptions: None
       
  1348 
       
  1349     Status: Approved
       
  1350 
       
  1351 -------------------------------------------------------------------------------
       
  1352 */
       
  1353 TInt CTestModuleIf::Command(TCommand aCommand, const TDesC8& aParamsPckg)
       
  1354     {
       
  1355     TInt res = KErrNone;
       
  1356 
       
  1357     if( !IsServerAlive() )
       
  1358         {
       
  1359         return KErrGeneral;
       
  1360         }
       
  1361 
       
  1362     switch(aCommand)
       
  1363         {
       
  1364         case EStopExecution:
       
  1365             iTestExecution->DoNotifyCommand(aCommand, aParamsPckg);
       
  1366             break;
       
  1367         case ESendTestModuleVersion:
       
  1368         	iTestExecution->DoNotifyCommand(aCommand, aParamsPckg);
       
  1369         	break;
       
  1370         default:
       
  1371             __RDEBUG((_L("Command [%d] not recognized."), aCommand));
       
  1372         }
       
  1373 
       
  1374     return res;
       
  1375     }
       
  1376 
       
  1377 /*
       
  1378 -------------------------------------------------------------------------------
       
  1379 
       
  1380     Class: CTestModuleIf
       
  1381 
       
  1382     Method: GetTestCaseTitleL
       
  1383 
       
  1384     Description: Returns title of current test case.
       
  1385 
       
  1386     Parameters: aCommand - command to be send
       
  1387 
       
  1388     Return Values: Symbian OS error code.
       
  1389 
       
  1390     Errors/Exceptions: None
       
  1391 
       
  1392     Status: Approved
       
  1393 
       
  1394 -------------------------------------------------------------------------------
       
  1395 */
       
  1396 EXPORT_C void CTestModuleIf::GetTestCaseTitleL(TDes& aTestCaseTitle)
       
  1397     {
       
  1398     iTestExecution->GetTestCaseTitleL(aTestCaseTitle);
       
  1399     }
       
  1400 
       
  1401 /*
       
  1402 -------------------------------------------------------------------------------
       
  1403 
       
  1404     Class: CTestModuleIf
       
  1405 
       
  1406     Method: GetTestCaseArguments
       
  1407 
       
  1408     Description: Returns test case arguments.
       
  1409 
       
  1410     Parameters: none
       
  1411 
       
  1412     Return Values: test case arguments.
       
  1413 
       
  1414     Errors/Exceptions: None
       
  1415 
       
  1416     Status: proposal
       
  1417 
       
  1418 -------------------------------------------------------------------------------
       
  1419 */
       
  1420 EXPORT_C const TDesC& CTestModuleIf::GetTestCaseArguments() const
       
  1421     {
       
  1422     return iTestExecution->GetTestCaseArguments();
       
  1423     }
       
  1424 
       
  1425 /*
       
  1426 -------------------------------------------------------------------------------
       
  1427 
       
  1428     Class: CTestModuleIf
       
  1429 
       
  1430     Method: UITesting
       
  1431 
       
  1432     Description: Gets information if it is UI test or not
       
  1433 
       
  1434     Parameters: none
       
  1435 
       
  1436     Return Values: True if it is UI test, in other case it returns false.
       
  1437 
       
  1438     Errors/Exceptions: None
       
  1439 
       
  1440     Status: Approved
       
  1441 
       
  1442 -------------------------------------------------------------------------------
       
  1443 */
       
  1444 EXPORT_C TBool CTestModuleIf::UITesting()
       
  1445 	{
       
  1446 	return iTestExecution->UITesting();
       
  1447 	}
       
  1448 
       
  1449 /*
       
  1450 -------------------------------------------------------------------------------
       
  1451 
       
  1452     Class: CTestModuleIf
       
  1453 
       
  1454     Method: GetUiEnvProxy
       
  1455 
       
  1456     Description: Gets UiEnvProxy
       
  1457 
       
  1458     Parameters: none
       
  1459 
       
  1460     Return Values: Pointer to UiEnvProxy
       
  1461 
       
  1462     Errors/Exceptions: None
       
  1463 
       
  1464     Status: Approved
       
  1465 
       
  1466 -------------------------------------------------------------------------------
       
  1467 */
       
  1468 EXPORT_C CUiEnvProxy* CTestModuleIf::GetUiEnvProxy()
       
  1469 	{
       
  1470 	return iTestExecution->GetUiEnvProxy();
       
  1471 	}
       
  1472 
       
  1473 // ================= OTHER EXPORTED FUNCTIONS =================================
       
  1474 
       
  1475 
       
  1476 /*
       
  1477 -------------------------------------------------------------------------------
       
  1478 
       
  1479     DESCRIPTION
       
  1480 
       
  1481     This module contains the implementation of CSTIFTestMeasurement class 
       
  1482     member functions.
       
  1483 
       
  1484 -------------------------------------------------------------------------------
       
  1485 */
       
  1486 
       
  1487 // ================= MEMBER FUNCTIONS =========================================
       
  1488 
       
  1489 /*
       
  1490 -------------------------------------------------------------------------------
       
  1491 
       
  1492     Class: CSTIFTestMeasurement
       
  1493 
       
  1494     Method: CSTIFTestMeasurement
       
  1495 
       
  1496     Description: Default constructor
       
  1497 
       
  1498     C++ default constructor can NOT contain any code, that
       
  1499     might leave.
       
  1500 
       
  1501     Parameters: CTestModuleBase* aTestModuleBase: in: Pointer to STIF
       
  1502 
       
  1503     Return Values: None
       
  1504 
       
  1505     Errors/Exceptions: None
       
  1506 
       
  1507     Status: Approved
       
  1508 
       
  1509 -------------------------------------------------------------------------------
       
  1510 */
       
  1511 CSTIFTestMeasurement::CSTIFTestMeasurement( CTestModuleBase* aTestModuleBase ) :
       
  1512     iTestModuleBase( aTestModuleBase ),
       
  1513     iMeasurementOption( 0 )
       
  1514     {
       
  1515 
       
  1516     }
       
  1517 
       
  1518 /*
       
  1519 -------------------------------------------------------------------------------
       
  1520 
       
  1521     Class: CSTIFTestMeasurement
       
  1522 
       
  1523     Method: ConstructL
       
  1524 
       
  1525     Description: Symbian OS second phase constructor
       
  1526 
       
  1527     Symbian OS default constructor can leave.
       
  1528 
       
  1529     Parameters: TSTIFMeasurement aType: in: Measurement type
       
  1530                 const TDesC& aConfigurationInfo: in: Configuration issues
       
  1531 
       
  1532     Return Values: None
       
  1533 
       
  1534     Errors/Exceptions: Leaves if HandleMeasurementProcess returns error code
       
  1535 
       
  1536     Status: Approved
       
  1537 
       
  1538 -------------------------------------------------------------------------------
       
  1539 */
       
  1540 void CSTIFTestMeasurement::ConstructL( TSTIFMeasurementType aType,
       
  1541                                     const TDesC& aConfigurationInfo )
       
  1542     {
       
  1543     // aType into struct here. This is compared to
       
  1544     iMeasurementStruct.iMeasurementType = aType;
       
  1545 
       
  1546     // Check that measurement is not disabled(This is given from UI level or
       
  1547     // from TestFramework.ini file)
       
  1548     TInt ret( 0 );
       
  1549     ret = iTestModuleBase->TestModuleIf().GetMeasurementOptions( 
       
  1550                                                         iMeasurementOption );
       
  1551     if( ret != KErrNone )
       
  1552         {
       
  1553         __RDEBUG( ( _L( "GetMeasurementOptions() return an error[%d]" ), ret ) );
       
  1554         User::Leave( ret );
       
  1555         }
       
  1556 
       
  1557     // Check that measurement is not disabled
       
  1558     if( ( iMeasurementOption & EDisableAll ) == EDisableAll )
       
  1559         {
       
  1560         __RDEBUG( _L( "Measurement disable option [KStifMeasurementDisableAll] is given by user" ) );
       
  1561         return;
       
  1562         }
       
  1563     if( ( ( iMeasurementOption & EMeasurement01 ) == EMeasurement01 ) && aType == KStifMeasurementPlugin01 )
       
  1564         {
       
  1565         __RDEBUG( _L( "Measurement disable option [KStifMeasurement01] is given by user" ) );
       
  1566         return;
       
  1567         }
       
  1568     if( ( ( iMeasurementOption & EMeasurement02 ) == EMeasurement02 ) && aType == KStifMeasurementPlugin02 )
       
  1569         {
       
  1570         __RDEBUG( _L( "Measurement disable option [KStifMeasurement02] is given by user" ) );
       
  1571         return;
       
  1572         }
       
  1573     if( ( ( iMeasurementOption & EMeasurement03 ) == EMeasurement03 ) && aType == KStifMeasurementPlugin03 )
       
  1574         {
       
  1575         __RDEBUG( _L( "Measurement disable option [KStifMeasurement03] is given by user" ) );
       
  1576         return;
       
  1577         }
       
  1578     if( ( ( iMeasurementOption & EMeasurement04 ) == EMeasurement04 ) && aType == KStifMeasurementPlugin04 )
       
  1579         {
       
  1580         __RDEBUG( _L( "Measurement disable option [KStifMeasurement04] is given by user" ) );
       
  1581         return;
       
  1582         }
       
  1583     if( ( ( iMeasurementOption & EMeasurement05 ) == EMeasurement05 ) && aType == KStifMeasurementPlugin05 )
       
  1584         {
       
  1585         __RDEBUG( _L( "Measurement disable option [KStifMeasurement05] is given by user" ) );
       
  1586         return;
       
  1587         }
       
  1588     if( ( ( iMeasurementOption & EBappea ) == EBappea ) && aType == KStifMeasurementBappeaProfiler )
       
  1589         {
       
  1590         __RDEBUG( _L( "Measurement disable option [KStifMeasurementBappea] is given by user" ) );
       
  1591         return;
       
  1592         }
       
  1593 
       
  1594     iMeasurementStruct.iConfigurationInfo = aConfigurationInfo;
       
  1595     iMeasurementStruct.iMeasurementOperation = KMeasurementNew;
       
  1596     iMeasurementStruct.iPointerToMeasurementModule = iTestModuleBase;
       
  1597 
       
  1598     // Move measurement execution initialization forward to TestServer.
       
  1599     User::LeaveIfError( iTestModuleBase->iTestModuleIf->HandleMeasurementProcess(
       
  1600             iMeasurementStruct ) );
       
  1601 
       
  1602     }
       
  1603 
       
  1604 /*
       
  1605 -------------------------------------------------------------------------------
       
  1606 
       
  1607     Class: CSTIFTestMeasurement
       
  1608 
       
  1609     Method: NewL
       
  1610 
       
  1611     Description: Two-phased constructor.
       
  1612 
       
  1613     Parameters: CTestModuleBase* aTestModuleBase: in: Pointer to STIF.
       
  1614                 TSTIFMeasurement aType: in: Measurement type.
       
  1615                 const TDesC& aConfigurationInfo: in: Configuration info.
       
  1616     
       
  1617     Return Values: CSTIFTestMeasurement object.
       
  1618 
       
  1619     Errors/Exceptions: Leaves if memory allocation fails
       
  1620                        Leaves if ConstructL leaves
       
  1621 
       
  1622     Status: Approved
       
  1623 
       
  1624 -------------------------------------------------------------------------------
       
  1625 */
       
  1626 EXPORT_C CSTIFTestMeasurement* CSTIFTestMeasurement::NewL( 
       
  1627                                             CTestModuleBase* aTestModuleBase,
       
  1628                                             TSTIFMeasurementType aType, 
       
  1629                                             const TDesC& aConfigurationInfo )
       
  1630     {
       
  1631     CSTIFTestMeasurement* self = 
       
  1632             new (ELeave) CSTIFTestMeasurement( aTestModuleBase );
       
  1633 
       
  1634     CleanupStack::PushL( self );
       
  1635     self->ConstructL( aType, aConfigurationInfo );
       
  1636 
       
  1637     CleanupStack::Pop();
       
  1638 
       
  1639     return self;
       
  1640 
       
  1641     }
       
  1642 
       
  1643 /*
       
  1644 -------------------------------------------------------------------------------
       
  1645 
       
  1646     Class: CSTIFTestMeasurement
       
  1647 
       
  1648     Method: ~CSTIFTestMeasurement
       
  1649 
       
  1650     Description: Destructor
       
  1651 
       
  1652     Parameters: None
       
  1653 
       
  1654     Return Values: None
       
  1655 
       
  1656     Errors/Exceptions: None
       
  1657 
       
  1658     Status: Approved
       
  1659 
       
  1660 -------------------------------------------------------------------------------
       
  1661 */
       
  1662 CSTIFTestMeasurement::~CSTIFTestMeasurement()
       
  1663     {
       
  1664     // None
       
  1665 
       
  1666     }
       
  1667 
       
  1668 /*
       
  1669 -------------------------------------------------------------------------------
       
  1670 
       
  1671     Class: CSTIFTestMeasurement
       
  1672 
       
  1673     Method: Start
       
  1674 
       
  1675     Description: Start commant for measurement.
       
  1676 
       
  1677     Parameters: None
       
  1678 
       
  1679     Return Values: Symbian error code
       
  1680 
       
  1681     Errors/Exceptions: None
       
  1682 
       
  1683     Status: Approved
       
  1684 
       
  1685 -------------------------------------------------------------------------------
       
  1686 */
       
  1687 EXPORT_C TInt CSTIFTestMeasurement::Start()
       
  1688     {
       
  1689     // Check that measurement is not disabled
       
  1690     if( iMeasurementOption  == iMeasurementStruct.iMeasurementType )
       
  1691         {
       
  1692         __RDEBUG( ( _L( "Measurement with type[%d] is disabled by user" ), iMeasurementOption ) );
       
  1693         // Cannot return error code because this causes problems in
       
  1694         // TestScripter and TestCombiner error handling. Now testing continue
       
  1695         // without measurement.
       
  1696         return KErrNone;
       
  1697         }
       
  1698 
       
  1699     iMeasurementStruct.iMeasurementOperation = KMeasurementStart;
       
  1700 
       
  1701     // Move measurement start execution forward to TestServer.
       
  1702     return iTestModuleBase->iTestModuleIf->HandleMeasurementProcess(
       
  1703                                                         iMeasurementStruct );
       
  1704 
       
  1705     }
       
  1706 
       
  1707 /*
       
  1708 -------------------------------------------------------------------------------
       
  1709 
       
  1710     Class: CTestMeasurement
       
  1711 
       
  1712     Method: Stop
       
  1713 
       
  1714     Description: Stop command for measurement.
       
  1715 
       
  1716     Parameters: None
       
  1717 
       
  1718     Return Values: Symbian error code
       
  1719 
       
  1720     Errors/Exceptions: None
       
  1721 
       
  1722     Status: Approved
       
  1723 
       
  1724 -------------------------------------------------------------------------------
       
  1725 */
       
  1726 EXPORT_C TInt CSTIFTestMeasurement::Stop()
       
  1727     {
       
  1728     // Check that measurement is not disabled
       
  1729     if( iMeasurementOption  == iMeasurementStruct.iMeasurementType )
       
  1730         {
       
  1731         __RDEBUG( ( _L( "Measurement with type[%d] is disabled by user" ), iMeasurementOption ) );
       
  1732         // Cannot return error code because this causes problems in
       
  1733         // TestScripter and TestCombiner error handling. Now testing continue
       
  1734         // without measurement.
       
  1735         return KErrNone;
       
  1736         }
       
  1737 
       
  1738     iMeasurementStruct.iMeasurementOperation = KMeasurementStop;
       
  1739 
       
  1740     // Move measurement stop execution forward to TestServer.
       
  1741     return iTestModuleBase->iTestModuleIf->HandleMeasurementProcess(
       
  1742                                                         iMeasurementStruct );
       
  1743 
       
  1744     }
       
  1745 
       
  1746 // End of File