usbuis/usbui/tsrc/usbuiapitest/src/usbuiapitestblocks.cpp
changeset 25 8c311f9acc5e
equal deleted inserted replaced
8:7e15987c4500 25:8c311f9acc5e
       
     1 /*
       
     2 * Copyright (c) 2002 - 2007 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:
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // [INCLUDE FILES] - do not remove
       
    22 #include <e32svr.h>
       
    23 #include <StifParser.h>
       
    24 #include <Stiftestinterface.h>
       
    25 #include "USBUiApiTest.h"
       
    26 
       
    27 // EXTERNAL DATA STRUCTURES
       
    28 //extern  ?external_data;
       
    29 
       
    30 // EXTERNAL FUNCTION PROTOTYPES  
       
    31 //extern ?external_function( ?arg_type,?arg_type );
       
    32 
       
    33 // CONSTANTS
       
    34 //const ?type ?constant_var = ?constant;
       
    35 
       
    36 // MACROS
       
    37 //#define ?macro ?macro_def
       
    38 
       
    39 // LOCAL CONSTANTS AND MACROS
       
    40 //const ?type ?constant_var = ?constant;
       
    41 //#define ?macro_name ?macro_def
       
    42 
       
    43 // MODULE DATA STRUCTURES
       
    44 //enum ?declaration
       
    45 //typedef ?declaration
       
    46 
       
    47 // LOCAL FUNCTION PROTOTYPES
       
    48 //?type ?function_name( ?arg_type, ?arg_type );
       
    49 
       
    50 // FORWARD DECLARATIONS
       
    51 //class ?FORWARD_CLASSNAME;
       
    52 
       
    53 // ============================= LOCAL FUNCTIONS ===============================
       
    54 
       
    55 // -----------------------------------------------------------------------------
       
    56 // ?function_name ?description.
       
    57 // ?description
       
    58 // Returns: ?value_1: ?description
       
    59 //          ?value_n: ?description_line1
       
    60 //                    ?description_line2
       
    61 // -----------------------------------------------------------------------------
       
    62 //
       
    63 /*
       
    64 ?type ?function_name(
       
    65     ?arg_type arg,  // ?description
       
    66     ?arg_type arg)  // ?description
       
    67     {
       
    68 
       
    69     ?code  // ?comment
       
    70 
       
    71     // ?comment
       
    72     ?code
       
    73     }
       
    74 */
       
    75 
       
    76 // ============================ MEMBER FUNCTIONS ===============================
       
    77 
       
    78 // -----------------------------------------------------------------------------
       
    79 // CUSBUiApiTest::Delete
       
    80 // Delete here all resources allocated and opened from test methods. 
       
    81 // Called from destructor. 
       
    82 // -----------------------------------------------------------------------------
       
    83 //
       
    84 void CUSBUiApiTest::Delete() 
       
    85     {
       
    86     iApaLsSession.Close();
       
    87     delete iCommandLine;
       
    88     iCommandLine = NULL;
       
    89     delete iRepository;
       
    90     iRepository = NULL;
       
    91     }
       
    92 
       
    93 // -----------------------------------------------------------------------------
       
    94 // CUSBUiApiTest::RunMethodL
       
    95 // Run specified method. Contains also table of test mothods and their names.
       
    96 // -----------------------------------------------------------------------------
       
    97 //
       
    98 TInt CUSBUiApiTest::RunMethodL( 
       
    99     CStifItemParser& aItem ) 
       
   100     {
       
   101 
       
   102     static TStifFunctionInfo const KFunctions[] =
       
   103         {  
       
   104         //ADD NEW ENTRY HERE
       
   105         // [test cases entries] - Do not remove
       
   106 	    ENTRY( "ExecuteApiTestBlock", CUSBUiApiTest::ExecuteApiTestBlock ),
       
   107         ENTRY( "ExecuteModuleTestBlock", CUSBUiApiTest::ExecuteModuleTestBlock ),
       
   108         ENTRY( "ExecuteBranchTestBlock", CUSBUiApiTest::ExecuteBranchTestBlock ),
       
   109         };
       
   110 
       
   111     const TInt count = sizeof( KFunctions ) / 
       
   112                         sizeof( TStifFunctionInfo );
       
   113 
       
   114     return RunInternalL( KFunctions, count, aItem );
       
   115 
       
   116     }
       
   117 
       
   118 // -----------------------------------------------------------------------------
       
   119 // CUSBUiApiTest::GetTestBlockParamsL
       
   120 // -----------------------------------------------------------------------------
       
   121 
       
   122 void CUSBUiApiTest::GetTestBlockParamsL( CStifItemParser& aItem )
       
   123     {
       
   124     TRACE_INFO( _L(">>> GetTestBlockParamsL") );
       
   125     
       
   126     // Add new test block branches below, get all required test parameters    
       
   127     if ( !iTestBlockParams.iTestBlockName.Compare( _L( "ExampleTestL" ) ) )
       
   128         {       
       
   129         User::LeaveIfError( aItem.GetNextString( iTestBlockParams.iTestOption1 ) );        
       
   130         User::LeaveIfError( aItem.GetNextString( iTestBlockParams.iTestOption2 ) );
       
   131         User::LeaveIfError( aItem.GetNextInt( iTestBlockParams.iTestIntOption1 ) );        
       
   132         User::LeaveIfError( aItem.GetNextChar( iTestBlockParams.iTestCharOption1 ) );        
       
   133         }
       
   134     else if ( !iTestBlockParams.iTestBlockName.Compare( _L( "LaunchUsbUiApp" ) ) )
       
   135         {       
       
   136         User::LeaveIfError( aItem.GetNextString( iTestBlockParams.iTestOption1 ) );        
       
   137         User::LeaveIfError( aItem.GetNextString( iTestBlockParams.iTestOption2 ) );      
       
   138         }
       
   139 	else if ( !iTestBlockParams.iTestBlockName.Compare( _L( "TurnLightsOn" ) ) )
       
   140 		{         
       
   141 		}
       
   142 	else if ( !iTestBlockParams.iTestBlockName.Compare( _L( "FinishTest" ) ) )
       
   143 		{       
       
   144 		User::LeaveIfError( aItem.GetNextString( iTestBlockParams.iTestOption1 ) ); 
       
   145 		if( iTestBlockParams.iTestOption1.Compare(_L("CANCELLED")) == KErrNotFound )
       
   146 			{
       
   147 			User::LeaveIfError( aItem.GetNextString( iTestBlockParams.iTestOption2 ) );        
       
   148 			User::LeaveIfError( aItem.GetNextString( iTestBlockParams.iTestOption3 ) );
       
   149 			}
       
   150 		}
       
   151     else
       
   152         {
       
   153         TRACE_INFO( _L("GetTestBlockParamsL() Test type: not found") );
       
   154         User::Leave( KErrNotFound );
       
   155         }
       
   156     TRACE_INFO( _L("<<< GetTestBlockParamsL") );
       
   157     }
       
   158 
       
   159 // -----------------------------------------------------------------------------
       
   160 // CUSBUiApiTest::ExecuteApiTestBlock
       
   161 // -----------------------------------------------------------------------------
       
   162 
       
   163 TInt CUSBUiApiTest::ExecuteApiTestBlock( CStifItemParser& aItem )
       
   164     {
       
   165     TRACE_INFO( _L(">>> ExecuteApiTestBlock") );
       
   166 	
       
   167 	TInt res;
       
   168     TUSBUiApiTestResult testResult;
       
   169 	
       
   170     TRAP( res, DoExecuteApiTestBlockL( aItem, testResult ) );
       
   171     if ( res != KErrNone )
       
   172         {
       
   173         TRACE_INFO( (_L("DoExecuteApiTestBlockL error: %d"), res) );
       
   174         return res;
       
   175         }
       
   176     
       
   177     STIF_ASSERT_EQUALS( ETestCasePassed, testResult );
       
   178     TRACE_INFO( _L("Test case passed") );
       
   179     TRACE_INFO( _L("<<< ExecuteApiTestBlock") );
       
   180 	
       
   181     return KErrNone;
       
   182     }
       
   183 	
       
   184 	
       
   185 void CUSBUiApiTest::DoExecuteApiTestBlockL( CStifItemParser& aItem, TUSBUiApiTestResult& aTestResult )
       
   186     {
       
   187     TRACE_INFO( _L(">>>DoExecuteApiTestBlockL") );
       
   188 
       
   189 	User::LeaveIfError( aItem.GetString( _L( "ExecuteApiTestBlock" ), iTestBlockParams.iTestBlockName ) );
       
   190         TRACE_INFO( (_L("Api test type: %S"), &iTestBlockParams.iTestBlockName) );
       
   191 	
       
   192 	GetTestBlockParamsL( aItem );
       
   193 	
       
   194 	// Add new API test block branches with optional test parameters here	
       
   195     if ( !iTestBlockParams.iTestBlockName.Compare( _L( "ExampleTestL" ) ) )
       
   196         {      
       
   197         ExampleTestL( iTestBlockParams.iTestOption1, iTestBlockParams.iTestOption2, 
       
   198                 iTestBlockParams.iTestIntOption1, iTestBlockParams.iTestCharOption1, aTestResult );
       
   199         }
       
   200     else if ( !iTestBlockParams.iTestBlockName.Compare( _L( "LaunchUsbUiApp" ) ) )
       
   201         {      
       
   202         LaunchUsbUiApp( iTestBlockParams.iTestOption1, iTestBlockParams.iTestOption2, aTestResult );
       
   203         }
       
   204     else if ( !iTestBlockParams.iTestBlockName.Compare( _L( "FinishTest" ) ) )
       
   205         {      
       
   206         FinishTest( iTestBlockParams.iTestOption1, iTestBlockParams.iTestOption2, iTestBlockParams.iTestOption3, aTestResult );
       
   207         }
       
   208     else if ( !iTestBlockParams.iTestBlockName.Compare( _L( "TurnLightsOn" ) ) )
       
   209         {      
       
   210         TurnLightsOn(  );
       
   211         }
       
   212     else
       
   213         {
       
   214     TRACE_INFO( _L("DoExecuteApiTestBlockL() Test type: not found") );
       
   215         User::Leave( KErrNotFound );
       
   216         }
       
   217 	
       
   218     TRACE_INFO( _L("<<<DoExecuteApiTestBlockL") );
       
   219     }
       
   220 	
       
   221 // -----------------------------------------------------------------------------
       
   222 // CUSBUiApiTest::ExecuteModuleTestBlock
       
   223 // -----------------------------------------------------------------------------	
       
   224 
       
   225 TInt CUSBUiApiTest::ExecuteModuleTestBlock( CStifItemParser& aItem )
       
   226     {
       
   227     TRACE_INFO( _L(">>>ExecuteModuleTestBlock") );
       
   228 	
       
   229     TInt res;
       
   230     TUSBUiApiTestResult testResult;
       
   231     
       
   232     TRAP( res, DoExecuteModuleTestBlockL( aItem, testResult ) );
       
   233     if ( res != KErrNone )
       
   234         {
       
   235         TRACE_INFO( (_L("DoExecuteModuleTestBlockL error: %d"), res) );
       
   236         return res;
       
   237         }
       
   238     
       
   239     STIF_ASSERT_EQUALS( ETestCasePassed, testResult );
       
   240     TRACE_INFO( _L("Test case passed") );
       
   241     TRACE_INFO( _L("<<<ExecuteModuleTestBlock") );
       
   242     return KErrNone;
       
   243     }	
       
   244 	
       
   245 	
       
   246 void CUSBUiApiTest::DoExecuteModuleTestBlockL( CStifItemParser& aItem, TUSBUiApiTestResult& aTestResult )
       
   247     {
       
   248     TRACE_INFO( _L(">>>DoExecuteModuleTestBlockL") );
       
   249 	
       
   250     User::LeaveIfError( aItem.GetString( _L( "ExecuteModuleTestBlock" ), iTestBlockParams.iTestBlockName ) );
       
   251     TRACE_INFO( (_L("Module test type: %S"), &iTestBlockParams.iTestBlockName) );
       
   252     
       
   253     GetTestBlockParamsL( aItem );
       
   254     
       
   255     // Add new module test block branches with optional test parameters here   
       
   256     if ( !iTestBlockParams.iTestBlockName.Compare( _L( "ExampleTestL" ) ) )
       
   257         {      
       
   258         ExampleTestL( iTestBlockParams.iTestOption1, iTestBlockParams.iTestOption2, 
       
   259                 iTestBlockParams.iTestIntOption1, iTestBlockParams.iTestCharOption1, aTestResult );
       
   260         }
       
   261     else
       
   262         {
       
   263     TRACE_INFO( _L("DoExecuteModuleTestBlockL() Test type: not found") );
       
   264         User::Leave( KErrNotFound );
       
   265         }
       
   266     
       
   267     TRACE_INFO( _L("<<<DoExecuteModuleTestBlockL") );
       
   268     }
       
   269 	
       
   270 // -----------------------------------------------------------------------------
       
   271 // CUSBUiApiTest::ExecuteBranchTestBlock
       
   272 // -----------------------------------------------------------------------------
       
   273 	
       
   274 TInt CUSBUiApiTest::ExecuteBranchTestBlock( CStifItemParser& aItem )
       
   275     {
       
   276     TRACE_INFO( _L(">>>ExecuteBranchTestBlock") );
       
   277 	
       
   278     TInt res;
       
   279     TUSBUiApiTestResult testResult;
       
   280     
       
   281     TRAP( res, DoExecuteBranchTestBlockL( aItem, testResult ) );
       
   282     if ( res != KErrNone )
       
   283         {
       
   284         TRACE_INFO( (_L("DoExecuteBranchTestBlockL error: %d"), res) );
       
   285         return res;
       
   286         }   
       
   287     
       
   288     STIF_ASSERT_EQUALS( ETestCasePassed, testResult );
       
   289     TRACE_INFO( _L("Test case passed") );
       
   290     TRACE_INFO( _L("<<<ExecuteBranchTestBlock") );
       
   291     return KErrNone;
       
   292     }
       
   293 
       
   294 	
       
   295 void CUSBUiApiTest::DoExecuteBranchTestBlockL( CStifItemParser& aItem, TUSBUiApiTestResult& aTestResult )
       
   296     {
       
   297     TRACE_INFO( _L(">>>DoExecuteBranchTestBlockL") );
       
   298 	
       
   299     User::LeaveIfError( aItem.GetString( _L( "ExecuteBranchTestBlock" ), iTestBlockParams.iTestBlockName ) );
       
   300     TRACE_INFO( (_L("Branch test type: %S"), &iTestBlockParams.iTestBlockName) );
       
   301     
       
   302     GetTestBlockParamsL( aItem );
       
   303     
       
   304     // Add new branch test block branches with optional test parameters here   
       
   305     if ( !iTestBlockParams.iTestBlockName.Compare( _L( "ExampleTestL" ) ) )
       
   306         {      
       
   307         ExampleTestL( iTestBlockParams.iTestOption1, iTestBlockParams.iTestOption2, 
       
   308                 iTestBlockParams.iTestIntOption1, iTestBlockParams.iTestCharOption1, aTestResult );
       
   309         }
       
   310     else
       
   311         {
       
   312     TRACE_INFO( _L("DoExecuteBranchTestBlockL() Test type: not found") );
       
   313         User::Leave( KErrNotFound );
       
   314         }
       
   315     
       
   316     TRACE_INFO( _L("<<<DoExecuteBranchTestBlockL") );
       
   317     }
       
   318 
       
   319 // Add test block methods implementation here
       
   320 // -----------------------------------------------------------------------------
       
   321 // CUSBUiApiTest::ExampleTestL
       
   322 // -----------------------------------------------------------------------------
       
   323 
       
   324 void CUSBUiApiTest::ExampleTestL( TPtrC aTestOption, TPtrC aTestSubOption, 
       
   325         TInt aTestIntOption, TInt aTestCharOption, TUSBUiApiTestResult& aTestResult )
       
   326     {
       
   327     
       
   328     if ( !aTestOption.Compare( _L( "API" ) ) )
       
   329         {
       
   330     TRACE_INFO( (_L("Api test option: %S"), &aTestOption) );
       
   331     TRACE_INFO( (_L("Api test sub-option: %S"), &aTestSubOption) );
       
   332     TRACE_INFO( (_L("Api test int option: %d"), aTestIntOption) );
       
   333     TRACE_INFO( (_L("Api test char option: %c"), aTestCharOption) );
       
   334         }
       
   335     else if ( !aTestOption.Compare( _L( "MODULE" ) ) )
       
   336         {
       
   337     TRACE_INFO( (_L("Module test option: %S"), &aTestOption) );
       
   338     TRACE_INFO( (_L("Module test sub-option: %S"), &aTestSubOption) );
       
   339     TRACE_INFO( (_L("Module test int option: %d"), aTestIntOption) );
       
   340     TRACE_INFO( (_L("Module test char option: %c"), aTestCharOption) );
       
   341         }
       
   342     else if ( !aTestOption.Compare( _L( "BRANCH" ) ) )
       
   343         {
       
   344     TRACE_INFO( (_L("Branch test option: %S"), &aTestOption) );
       
   345     TRACE_INFO( (_L("Branch test sub-option: %S"), &aTestSubOption) );
       
   346     TRACE_INFO( (_L("Branch test int option: %d"), aTestIntOption) );
       
   347     TRACE_INFO( (_L("Branch test char option: %c"), aTestCharOption) );
       
   348         }
       
   349     else
       
   350         {
       
   351         TRACE_INFO( _L("Invalid test parameter") );
       
   352         User::Leave( KErrNotFound );
       
   353         }
       
   354     
       
   355     aTestResult = ETestCasePassed;
       
   356     
       
   357     TRACE_INFO( _L("<<<ExampleTestL") );
       
   358     }
       
   359 
       
   360 
       
   361 // -----------------------------------------------------------------------------
       
   362 // CUSBUiApiTest::LaunchUsbUiApp
       
   363 // -----------------------------------------------------------------------------
       
   364 
       
   365 TInt CUSBUiApiTest::LaunchUsbUiApp( TPtrC aTestOption, TPtrC aTestSubOption, TUSBUiApiTestResult& aTestResult )
       
   366     {
       
   367     TInt res;
       
   368     TInt testAskOnConnectionSetting;
       
   369     TInt testUsbPersonalityId;
       
   370         
       
   371     res = GetAskOnConnectionOptionFromString( aTestOption, testAskOnConnectionSetting );   
       
   372     if ( res != KErrNone )
       
   373         {
       
   374         TRACE_INFO( (_L("GetAskOnConnectionOptionFromString failed with value: %d"), res) );
       
   375         iApaLsSession.Close();
       
   376         return res;
       
   377         }
       
   378     TRACE_INFO( (_L("GetAskOnConnectionOptionFromString OK:  %d"), testAskOnConnectionSetting) );
       
   379     
       
   380     
       
   381     res = GetUsbPersonalityOptionFromString( aTestSubOption, testUsbPersonalityId );   
       
   382     if ( res != KErrNone )
       
   383         {
       
   384         TRACE_INFO( (_L("GetUsbPersonalityOptionFromString failed with value: %d"), res) );
       
   385         iApaLsSession.Close();
       
   386         return res;
       
   387         }
       
   388     TRACE_INFO( (_L("GetUsbPersonalityOptionFromString OK: %d"),testUsbPersonalityId) );
       
   389     
       
   390     res = GetUsbSettings( iUsbPersonalityBackup, iAskOnConnectionSettingBackup );
       
   391     if ( res != KErrNone )
       
   392         {
       
   393         TRACE_INFO( (_L("Failed to backup usb settings with value: %d"), res) );
       
   394         return res;
       
   395         }
       
   396     TRACE_INFO( (_L("GetUsbSettings OK: %d, %d"), iUsbPersonalityBackup, iAskOnConnectionSettingBackup) );
       
   397     
       
   398     res = SetUsbSettings( testUsbPersonalityId, testAskOnConnectionSetting );
       
   399     if ( res != KErrNone )
       
   400         {
       
   401         TRACE_INFO( (_L("Changing usb settings failed with value (cenrep): %d"), res) );
       
   402         return res;
       
   403         }
       
   404     TRACE_INFO( (_L("SetUsbSettings OK: %d, %d"), testUsbPersonalityId, testAskOnConnectionSetting) );
       
   405   
       
   406     iCommandLine->SetCommandL( EApaCommandRun );
       
   407     iCommandLine->SetExecutableNameL( KUsbAppFileName );
       
   408 
       
   409     res = iApaLsSession.Connect();
       
   410     if ( res != KErrNone )
       
   411         {
       
   412         TRACE_INFO( (_L("Connecting to application server failed with value: %d"), res) );
       
   413         return res;
       
   414 
       
   415         }
       
   416     STIF_LOG("iApaLsSession.Connect OK");
       
   417 
       
   418     res = iApaLsSession.StartApp( *iCommandLine );
       
   419     if ( res != KErrNone )
       
   420         {
       
   421         TRACE_INFO( (_L("Starting application failed with value: %d"), res) );
       
   422         iApaLsSession.Close();
       
   423         return res;
       
   424         }
       
   425     STIF_LOG("iApaLsSession.StartApp OK");
       
   426     
       
   427     if ( !IsUsbAppRunning() )
       
   428         {
       
   429         TRACE_INFO( _L("Usb application launch error") );
       
   430         iApaLsSession.Close();
       
   431         return KErrGeneral;
       
   432         }
       
   433     STIF_LOG("IsUsbAppRunning OK");
       
   434 
       
   435     TRACE_INFO( _L("Usb application started") );
       
   436 
       
   437     aTestResult = ETestCasePassed;
       
   438     
       
   439     return KErrNone;
       
   440     }
       
   441 
       
   442 // -----------------------------------------------------------------------------
       
   443 // CUSBUiApiTest::FinishTest
       
   444 // -----------------------------------------------------------------------------
       
   445 
       
   446 TInt CUSBUiApiTest::FinishTest( TPtrC aTestOption, TPtrC aTestSubOption, TPtrC aTestSubOption2, TUSBUiApiTestResult& aTestResult )
       
   447     {
       
   448     TRACE_INFO( _L(">>>FinishTest") );
       
   449     
       
   450     TInt res;
       
   451     TUSBAppTestOption option;
       
   452     TBool isAppRunning;
       
   453     TInt actualAskOnConnectionSetting;
       
   454     TInt expectedAskOnConnectionSetting;
       
   455     TInt actualPersonalityIdSetting;
       
   456     TInt expectedPersonalityIdSetting;
       
   457         
       
   458     res = GetTestOption( aTestOption, option );
       
   459     if ( res != KErrNone )
       
   460         {
       
   461         TRACE_INFO( (_L("GetTestOption failed with value: %d"), res) );
       
   462         iApaLsSession.Close();
       
   463         return res;
       
   464         }
       
   465     TRACE_INFO( (_L("GetTestOption OK: %d"),option) );
       
   466     
       
   467     if ( option == EAskOnConnectionSettingChanged || option == EUsbConnectionModeSettingChanged )
       
   468         {     
       
   469         res = GetAskOnConnectionOptionFromString( aTestSubOption, expectedAskOnConnectionSetting );   
       
   470         if ( res != KErrNone )
       
   471             {
       
   472             TRACE_INFO( (_L("GetAskOnConnectionOptionFromString failed with value: %d"), res) );
       
   473             iApaLsSession.Close();
       
   474             return res;
       
   475             }
       
   476         TRACE_INFO( (_L("GetAskOnConnectionOptionFromString OK: %d"), expectedAskOnConnectionSetting) );
       
   477                 
       
   478         res = GetUsbPersonalityOptionFromString( aTestSubOption2, expectedPersonalityIdSetting );   
       
   479         if ( res != KErrNone )
       
   480             {
       
   481             TRACE_INFO( (_L("GetUsbPersonalityOptionFromString failed with value: %d"), res) );
       
   482             iApaLsSession.Close();
       
   483             return res;
       
   484             }
       
   485         TRACE_INFO( (_L("GetUsbPersonalityOptionFromString OK %d"), expectedPersonalityIdSetting) );
       
   486         }
       
   487     
       
   488     isAppRunning = IsUsbAppRunning();
       
   489 
       
   490     res = GetUsbSettings( actualPersonalityIdSetting, actualAskOnConnectionSetting );
       
   491     if ( res != KErrNone )
       
   492         {
       
   493         TRACE_INFO( (_L("Getting usb settings failed with value (cenrep): %d"), res) );
       
   494         iApaLsSession.Close();
       
   495         return res;
       
   496         }
       
   497     TRACE_INFO( (_L("GetUsbSettings OK: %d, %d"), actualPersonalityIdSetting, actualAskOnConnectionSetting) );
       
   498     
       
   499     res = SetUsbSettings( iUsbPersonalityBackup, iAskOnConnectionSettingBackup );
       
   500     if ( res != KErrNone )
       
   501         TRACE_INFO( _L("Failed to restore original usb settings!") );
       
   502     TRACE_INFO( (_L("SetUsbSettings OK: %d, %d"), iUsbPersonalityBackup, iAskOnConnectionSettingBackup) );
       
   503     
       
   504     iApaLsSession.Close();
       
   505     
       
   506     switch( option )
       
   507         {
       
   508         case EAskOnConnectionSettingChanged:       
       
   509         case EUsbConnectionModeSettingChanged:
       
   510             TRACE_INFO( (_L("Actual USB ask on connection setting value: %d, expected: %d"), actualAskOnConnectionSetting, expectedAskOnConnectionSetting) );
       
   511             STIF_ASSERT_EQUALS( expectedAskOnConnectionSetting, actualAskOnConnectionSetting );
       
   512             TRACE_INFO( (_L("Actual USB personality setting value: %d, expected: %d"), actualPersonalityIdSetting, expectedPersonalityIdSetting) );
       
   513             STIF_ASSERT_EQUALS( expectedPersonalityIdSetting, actualPersonalityIdSetting );   
       
   514             TRACE_INFO( (_L("USB app is running: %d, expected: %d"), isAppRunning, EFalse) );
       
   515             STIF_ASSERT_FALSE( isAppRunning );
       
   516             break;
       
   517         case EAppCancelled:
       
   518             TRACE_INFO( (_L("USB app is running: %d, expected: %d"), isAppRunning, EFalse) );
       
   519             STIF_ASSERT_FALSE( isAppRunning );
       
   520             break;
       
   521         default:
       
   522             return KErrNotFound;
       
   523         }
       
   524       
       
   525     TRACE_INFO( _L("Test case passed!") );
       
   526     aTestResult = ETestCasePassed;
       
   527     
       
   528     TRACE_INFO( _L("<<<FinishTest") );
       
   529     
       
   530     return KErrNone;
       
   531     }
       
   532 
       
   533 // -----------------------------------------------------------------------------
       
   534 // CUSBUiApiTest::GetTestOption
       
   535 // -----------------------------------------------------------------------------
       
   536 
       
   537 TInt CUSBUiApiTest::GetTestOption( TPtrC aOptionString, TUSBAppTestOption& aOption )
       
   538     {    
       
   539     if ( !aOptionString.Compare( _L( "USB_CONN_MODE" ) ) )
       
   540         {
       
   541         aOption = EUsbConnectionModeSettingChanged;
       
   542         TRACE_INFO( _L("Test type: EUsbConnectionModeSettingChanged") );
       
   543         }
       
   544     else if ( !aOptionString.Compare( _L( "ASK_ON_CONN" ) ) )
       
   545         {
       
   546         aOption = EAskOnConnectionSettingChanged;
       
   547         TRACE_INFO( _L("Test type: EAskOnConnectionSettingChanged") );
       
   548         }
       
   549     else if ( !aOptionString.Compare( _L( "CANCELLED" ) ) )
       
   550         {
       
   551         aOption = EAppCancelled;
       
   552         TRACE_INFO( _L("Test type: EAppCancelled") );
       
   553         }
       
   554     else
       
   555         {
       
   556         TRACE_INFO( _L("Test type: not supported") );
       
   557         return KErrNotFound;
       
   558         }
       
   559  
       
   560     return KErrNone;
       
   561     }
       
   562 
       
   563 // -----------------------------------------------------------------------------
       
   564 // CUSBUiApiTest::GetAskOnConnectionOptionFromString
       
   565 // -----------------------------------------------------------------------------
       
   566 
       
   567 TInt CUSBUiApiTest::GetAskOnConnectionOptionFromString( TPtrC aOptionString, TInt& aOption )
       
   568     {    
       
   569     if ( !aOptionString.Compare( _L( "ON" ) ) )
       
   570         {
       
   571         aOption = KUsbWatcherChangeOnConnectionOn;
       
   572         TRACE_INFO( _L("Ask on connection option: ON") );
       
   573         }
       
   574     else if ( !aOptionString.Compare( _L( "OFF" ) ) )
       
   575         {
       
   576         aOption = KUsbWatcherChangeOnConnectionOff;
       
   577         TRACE_INFO( _L("Ask on connection option: OFF") );
       
   578         }
       
   579     else
       
   580         {
       
   581         TRACE_INFO( _L("Ask on connection option: not supported") );
       
   582         return KErrNotFound;
       
   583         }
       
   584  
       
   585     return KErrNone;
       
   586     }
       
   587 
       
   588 // -----------------------------------------------------------------------------
       
   589 // CUSBUiApiTest::GetUsbPersonalityOptionFromString
       
   590 // -----------------------------------------------------------------------------
       
   591 
       
   592 TInt CUSBUiApiTest::GetUsbPersonalityOptionFromString( TPtrC aOptionString, TInt& aOption )
       
   593     {    
       
   594     if ( !aOptionString.Compare( _L( "PCSUITE" ) ) )
       
   595         {
       
   596         aOption = KUsbPersonalityIdPCSuiteMTP;
       
   597         TRACE_INFO( _L("Usb personality option: KUsbPersonalityIdPCSuiteMTP") );
       
   598         }
       
   599     else if ( !aOptionString.Compare( _L( "MS" ) ) )
       
   600         {
       
   601         aOption = KUsbPersonalityIdMS;
       
   602         TRACE_INFO( _L("Usb personality option: KUsbPersonalityIdMS") );
       
   603         }
       
   604     else if ( !aOptionString.Compare( _L( "PTP" ) ) )
       
   605         {
       
   606         aOption = KUsbPersonalityIdPTP;
       
   607         TRACE_INFO( _L("Usb personality option: KUsbPersonalityIdPTP") );
       
   608         }
       
   609     else if ( !aOptionString.Compare( _L( "MTP" ) ) )
       
   610         {
       
   611         aOption = KUsbPersonalityIdMTP;
       
   612         TRACE_INFO( _L("Usb personality option: KUsbPersonalityIdMTP") );
       
   613         }
       
   614 	else if ( !aOptionString.Compare( _L( "MODEM" ) ) )
       
   615 		{
       
   616 		aOption = KUsbPersonalityIdModemInst;
       
   617 		TRACE_INFO( _L("Usb personality option: KUsbPersonalityIdModemInst") );
       
   618 		}
       
   619     else
       
   620         {
       
   621         TRACE_INFO( _L("Usb personality option: not supported") );
       
   622         return KErrNotFound;
       
   623         }
       
   624  
       
   625     return KErrNone;
       
   626     }
       
   627 
       
   628 // -----------------------------------------------------------------------------
       
   629 // CUSBUiApiTest::IsUsbAppRunning
       
   630 // -----------------------------------------------------------------------------
       
   631 
       
   632 TBool CUSBUiApiTest::IsUsbAppRunning()
       
   633     {
       
   634     TFindProcess processFinder;
       
   635     TFullName processName;
       
   636     TBool isAppRunning = EFalse;
       
   637     RProcess matchedProcess;
       
   638     
       
   639     while ( processFinder.Next( processName ) == KErrNone )
       
   640             {
       
   641             matchedProcess.Open( processFinder );
       
   642             if ( matchedProcess.SecureId() == iUsbAppSecureId )
       
   643                 isAppRunning = ETrue;
       
   644             }
       
   645     
       
   646     matchedProcess.Close();    
       
   647     return isAppRunning;
       
   648     }
       
   649 
       
   650 // -----------------------------------------------------------------------------
       
   651 // CUSBUiApiTest::GetUsbSettings
       
   652 // -----------------------------------------------------------------------------
       
   653 
       
   654 TInt CUSBUiApiTest::GetUsbSettings( TInt& aUsbPersonalityId, TInt& aAskOnConnectionSetting )
       
   655     {
       
   656     TInt res;   
       
   657     res = iRepository -> Get( KUsbWatcherChangeOnConnectionSetting, aAskOnConnectionSetting );
       
   658     if ( res != KErrNone )
       
   659         return res;
       
   660     
       
   661     res = iRepository -> Get( KUsbWatcherPersonality, aUsbPersonalityId );
       
   662     if ( res != KErrNone )
       
   663         return res;
       
   664     
       
   665     return KErrNone;
       
   666     }
       
   667 
       
   668 // -----------------------------------------------------------------------------
       
   669 // CUSBUiApiTest::SetUsbSettings
       
   670 // -----------------------------------------------------------------------------
       
   671 
       
   672 TInt CUSBUiApiTest::SetUsbSettings( TInt aUsbPersonalityId, TInt aAskOnConnectionSetting )
       
   673     {
       
   674     TInt res;   
       
   675     res = iRepository -> Set( KUsbWatcherChangeOnConnectionSetting, aAskOnConnectionSetting );
       
   676     if ( res != KErrNone )
       
   677         return res;
       
   678     
       
   679     res = iRepository -> Set( KUsbWatcherPersonality, aUsbPersonalityId );
       
   680     if ( res != KErrNone )
       
   681         return res;
       
   682     
       
   683     return KErrNone;
       
   684     }
       
   685 
       
   686 // -----------------------------------------------------------------------------
       
   687 // CUSBUiApiTest::TurnLightsOn
       
   688 // -----------------------------------------------------------------------------
       
   689 
       
   690 TInt CUSBUiApiTest::TurnLightsOn(  )
       
   691     {
       
   692     TInt res;
       
   693     res = RProperty::Set(KPSUidCoreApplicationUIs, KLightsControl, ELightsOn);
       
   694     res = RProperty::Set(KPSUidCoreApplicationUIs, KLightsVTForcedLightsOn, EForcedLightsOn);
       
   695     return res;
       
   696     }
       
   697 
       
   698 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   699 // None
       
   700 
       
   701 //  [End of File] - Do not remove