btservices_plat/bluetooth_engine_settings_api/tsrc/src/btapitestblocks.cpp
changeset 0 f63038272f30
child 22 613943a21004
equal deleted inserted replaced
-1:000000000000 0:f63038272f30
       
     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:  ?Description
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <e32std.h>
       
    22 #include <e32base.h>
       
    23 #include <e32cmn.h>
       
    24 #include <StifParser.h>
       
    25 #include <Stiftestinterface.h>
       
    26 
       
    27 #include <btengconnman.h>
       
    28 #include <btengdevman.h>
       
    29 #include <btengdiscovery.h>
       
    30 #include <btengsettings.h>
       
    31 
       
    32 #include "btapitest.h"
       
    33 #include "bttestlogger.h"
       
    34 #include "btapisettings.h"
       
    35 
       
    36 
       
    37 // EXTERNAL DATA STRUCTURES
       
    38 //extern  ?external_data;
       
    39 
       
    40 // EXTERNAL FUNCTION PROTOTYPES  
       
    41 //extern ?external_function( ?arg_type,?arg_type );
       
    42 
       
    43 // CONSTANTS
       
    44 //const ?type ?constant_var = ?constant;
       
    45 
       
    46 // MACROS
       
    47 //#define ?macro ?macro_def
       
    48 
       
    49 // LOCAL CONSTANTS AND MACROS
       
    50 //const ?type ?constant_var = ?constant;
       
    51 //#define ?macro_name ?macro_def
       
    52 
       
    53 // MODULE DATA STRUCTURES
       
    54 //enum ?declaration
       
    55 //typedef ?declaration
       
    56 
       
    57 // LOCAL FUNCTION PROTOTYPES
       
    58 //?type ?function_name( ?arg_type, ?arg_type );
       
    59 
       
    60 // FORWARD DECLARATIONS
       
    61 //class ?FORWARD_CLASSNAME;
       
    62 
       
    63 // ============================= LOCAL FUNCTIONS ===============================
       
    64 
       
    65 // ============================ MEMBER FUNCTIONS ===============================
       
    66 
       
    67 // -----------------------------------------------------------------------------
       
    68 // CBtApiTest::Delete
       
    69 // Delete here all resources allocated and opened from test methods. 
       
    70 // Called from destructor. 
       
    71 // -----------------------------------------------------------------------------
       
    72 //
       
    73 void CBtApiTest::Delete() 
       
    74     {
       
    75 
       
    76     }
       
    77 
       
    78 // -----------------------------------------------------------------------------
       
    79 // CBtApiTest::RunMethodL
       
    80 // Run specified method. Contains also table of test mothods and their names.
       
    81 // -----------------------------------------------------------------------------
       
    82 //
       
    83 TInt CBtApiTest::RunMethodL( 
       
    84     CStifItemParser& aItem ) 
       
    85     {
       
    86 
       
    87     static TStifFunctionInfo const KFunctions[] =
       
    88         {
       
    89         ENTRY( "PowerState", CBTEngSettings_GetAndSetPowerState ),
       
    90         ENTRY( "Visibility", CBTEngSettings_SetAndGetVisibility ),
       
    91         ENTRY( "LocalName", CBTEngSettings_SetAndGetLocalName ),
       
    92         ENTRY( "GetOfflineModeSettingsApi", CBTEngSettings_GetOfflineModeSettingsApi ),
       
    93         ENTRY( "ChangePowerStateTemporarily", CBTEngSettings_ChangePowerStateTemporarily ),
       
    94         ENTRY( "CP", CBTEngSettings_ChangePowerStateTemporarily ),
       
    95         };
       
    96 
       
    97     const TInt count = sizeof( KFunctions ) / 
       
    98                         sizeof( TStifFunctionInfo );
       
    99 
       
   100     return RunInternalL( KFunctions, count, aItem );
       
   101 
       
   102     }
       
   103 
       
   104 // -----------------------------------------------------------------------------
       
   105 // CBtApiTest::TestCompleted
       
   106 // -----------------------------------------------------------------------------
       
   107 //  
       
   108 void CBtApiTest::TestCompleted( TInt aErr, const TUint8* aFunc, const TDesC& aArg )
       
   109     {
       
   110     iTestLogger->LogResult( (TPtrC8( aFunc )), aArg, aErr );
       
   111     Signal( aErr );
       
   112     }
       
   113 
       
   114 // -----------------------------------------------------------------------------
       
   115 // CBtApiTest::Logger
       
   116 // -----------------------------------------------------------------------------
       
   117 //
       
   118 CBtTestLogger& CBtApiTest::Logger()
       
   119     {
       
   120     return *iTestLogger;
       
   121     }
       
   122 
       
   123 
       
   124 // -----------------------------------------------------------------------------
       
   125 // CBtApiTest::CBTEngSettings_SetAndGetPowerState
       
   126 // -----------------------------------------------------------------------------
       
   127 //
       
   128 TInt CBtApiTest::CBTEngSettings_GetAndSetPowerState( CStifItemParser& /*aItem*/ )
       
   129     {
       
   130   /*  
       
   131     TInt err = KErrNone;
       
   132     TBTPowerStateValue state, expState;
       
   133     TInt i = 0;
       
   134     
       
   135     for ( i=0 ; i<2 ; i++ )
       
   136     	{
       
   137     	state = EBTPowerOn;
       
   138     	err = iSettings->SetPowerState( state );
       
   139     	iSettings->GetExpectedState( expState );
       
   140     	iTestLogger->Log(CBtTestLogger::ETLDebug, _L( "CBTApiSettings::SetAndGetPowerState: %d) Error %d -:- state %d -:- expected state %d" ), i, err, state, expState );
       
   141     	iTestLogger->LogNewLine();
       
   142     	if ( err )
       
   143     		{
       
   144     		TestCompleted( err, TLFUNCLOG, _L("SetAndGetPowerState: Problem with state seting)"));	
       
   145     		return err;
       
   146     		}
       
   147     	}
       
   148     TestCompleted( err, TLFUNCLOG, _L("SetAndGetPowerState: Done)"));
       
   149     return err;
       
   150 */    
       
   151 /*    
       
   152     for ( i=0 ; i<2 ; i++ )
       
   153     	{
       
   154     	iSettings->GetExpectedState( expState );
       
   155     	err = iSettings->GetPowerState( state );
       
   156     	iTestLogger->Log(CBtTestLogger::ETLDebug, _L( "CBTApiSettings::SetAndGetPowerState: %d) Error %d -:- state %d -:- expected state %d" ), i, err, state, expState );
       
   157     	iTestLogger->LogNewLine();
       
   158     	if ( err )
       
   159     		{
       
   160     		TestCompleted( err, TLFUNCLOG, _L("SetAndGetPowerState: Problem with state reading)"));	
       
   161     		return err;
       
   162     		}
       
   163     	}
       
   164     TestCompleted( err, TLFUNCLOG, _L("SetAndGetPowerState: Done)"));
       
   165 	return err;
       
   166   */  
       
   167     
       
   168 /*************************
       
   169  * Working implementation
       
   170  * **********************
       
   171  
       
   172     TInt err = KErrNone;
       
   173     
       
   174     err = iSettings->TurnBtOn();
       
   175     if( err )
       
   176         {
       
   177         TestCompleted( err, TLFUNCLOG, _L("TurnBTOn"));
       
   178         return err;
       
   179         }
       
   180  */
       
   181     TInt err = KErrNone;
       
   182     
       
   183     err = iSettings->SwitchPowerState();
       
   184     if( err )
       
   185     	{
       
   186     	TestCompleted( err, TLFUNCLOG, _L("SwitchPowerState (1)"));
       
   187     	return err;
       
   188     	}
       
   189     
       
   190 	TestCompleted( err, TLFUNCLOG, _L("SetAndGetPowerState: Done)"));
       
   191     return err;    
       
   192      
       
   193 /*
       
   194     TInt ret = KErrNone;
       
   195         
       
   196     ret = iSettings->SwitchPowerState();
       
   197     _LIT(KSetAndGetPowerStateSwitchPowerState, "\nSetAndGetPowerState:> SwitchPowerState = %d");
       
   198     iLog->Log(KSetAndGetPowerStateSwitchPowerState, ret);    
       
   199     if( ret )
       
   200         {
       
   201         TestCompleted( ret, TLFUNCLOG, _L("SwitchPowerState 1"));
       
   202         return KErrNone;
       
   203         }
       
   204   
       
   205     ret = iSettings->GetPowerState();
       
   206     _LIT(KSetAndGetPowerStateGetPowerState, "\nSetAndGetPowerState:> GetPowerState err = %d");
       
   207     iLog->Log(KSetAndGetPowerStateGetPowerState, ret);
       
   208     if( ret )
       
   209         {
       
   210         TestCompleted( ret, TLFUNCLOG, _L("GetPowerState"));
       
   211         return KErrNone;
       
   212         }
       
   213 
       
   214     ret = iSettings->TurnBtOn();
       
   215     _LIT(KSetAndGetPowerStateTurnBtOn, "\nSetAndGetPowerState:> TurnBtOn = %d");
       
   216     iLog->Log(KSetAndGetPowerStateTurnBtOn, ret);
       
   217     
       
   218     TestCompleted( ret, TLFUNCLOG, _L("TurnBtOn)"));
       
   219     
       
   220     return KErrNone;
       
   221     */
       
   222     }
       
   223     
       
   224 // -----------------------------------------------------------------------------
       
   225 // CBtApiTest::CBTEngSettings_SetAndGetVisibility
       
   226 // -----------------------------------------------------------------------------
       
   227 //    
       
   228 TInt CBtApiTest::CBTEngSettings_SetAndGetVisibility( CStifItemParser& /*aItem*/ )
       
   229     {
       
   230     TInt ret = KErrNone;
       
   231     
       
   232     ret = iSettings->SetVisibilityNormalState();
       
   233     if( ret )
       
   234        	{
       
   235        		TestCompleted( ret, TLFUNCLOG, _L("SetVisibilityNormalState() method error"));
       
   236        		return KErrNone;
       
   237        	}
       
   238     
       
   239     
       
   240  	ret = iSettings->SetVisibilityMode( EBTVisibilityModeHidden );
       
   241    	if( ret )
       
   242    		{
       
   243    		TestCompleted( ret, TLFUNCLOG, _L("Set EBTVisibilityModeHidden"));
       
   244    		return KErrNone;
       
   245    		}
       
   246    	ret = iSettings->GetVisibilityMode();
       
   247    	if( ret )
       
   248    		{
       
   249    		TestCompleted( ret, TLFUNCLOG, _L("Get EBTVisibilityModeHidden"));
       
   250    		return KErrNone;
       
   251    		}
       
   252 
       
   253     ret = iSettings->SetVisibilityMode( EBTVisibilityModeTemporary, 1 );
       
   254     if( ret )
       
   255         {
       
   256         TestCompleted( ret, TLFUNCLOG, _L("Set EBTVisibilityModeTemporary"));
       
   257         return KErrNone;
       
   258         }
       
   259     
       
   260     ret = iSettings->GetVisibilityMode();
       
   261     if( ret )
       
   262         {
       
   263         TestCompleted( ret, TLFUNCLOG, _L("Get EBTVisibilityModeTemporary"));
       
   264         return KErrNone;
       
   265         }
       
   266 
       
   267     ret = iSettings->SetVisibilityMode( EBTVisibilityModeGeneral );
       
   268     if( ret )
       
   269         {
       
   270         TestCompleted( ret, TLFUNCLOG, _L("Set EBTVisibilityModeGeneral"));
       
   271         return KErrNone;
       
   272         }
       
   273     ret = iSettings->GetVisibilityMode();
       
   274     if( ret )
       
   275         {
       
   276         TestCompleted( ret, TLFUNCLOG, _L("Get EBTVisibilityModeGeneral"));
       
   277         return KErrNone;
       
   278         }
       
   279         
       
   280     TestCompleted( ret, TLFUNCLOG, _L(""));
       
   281     return KErrNone;
       
   282     }
       
   283 
       
   284 // -----------------------------------------------------------------------------
       
   285 // CBtApiTest::CBTEngSettings_SetAndGetLocalName
       
   286 // -----------------------------------------------------------------------------
       
   287 //
       
   288 TInt CBtApiTest::CBTEngSettings_SetAndGetLocalName( CStifItemParser& aItem )
       
   289     {
       
   290     TPtrC name(KNullDesC);
       
   291     TInt ret = aItem.GetNextString( name );
       
   292     iTestLogger->Log( CBtTestLogger::ETLInfo, _L( "Set new local name: %S" ),  &name);
       
   293     if ( ret )
       
   294         {
       
   295         TestCompleted( KErrArgument, TLFUNCLOG, name );
       
   296         return KErrNone;
       
   297         }
       
   298 
       
   299     ret = iSettings->SetLocalName( name );
       
   300     if( ret )
       
   301         {
       
   302         TestCompleted( ret, TLFUNCLOG, name );
       
   303         return KErrNone;
       
   304         }
       
   305     
       
   306     ret = iSettings->GetLocalName();
       
   307 
       
   308     TestCompleted( ret, TLFUNCLOG, name );
       
   309     return KErrNone;
       
   310     }
       
   311     
       
   312 
       
   313 TInt CBtApiTest::CBTEngSettings_GetOfflineModeSettingsApi( CStifItemParser& /*aItem*/ )
       
   314     {
       
   315     TPtrC name(KNullDesC);
       
   316     TInt err(KErrNone);
       
   317     
       
   318     TCoreAppUIsNetworkConnectionAllowed offline; 
       
   319     TBTEnabledInOfflineMode offlineAllowed; 
       
   320 
       
   321     err = iSettings->GetOfflineModeSettings(offline, offlineAllowed);
       
   322     iTestLogger->Log( CBtTestLogger::ETLInfo, _L( "Start GetOfflineModeSettingsApiTest> %d %d" ), offline, offlineAllowed);
       
   323     if( err )
       
   324         {
       
   325         TestCompleted( err, TLFUNCLOG, _L("") );
       
   326         return err;
       
   327         }
       
   328     
       
   329     switch( offline )
       
   330     	{
       
   331     	case ECoreAppUIsNetworkConnectionNotAllowed:
       
   332     		iTestLogger->Log( CBtTestLogger::ETLInfo, _L( "Network connection not allowed (%d)" ), ECoreAppUIsNetworkConnectionNotAllowed);
       
   333 			break;
       
   334     	case ECoreAppUIsNetworkConnectionAllowed:
       
   335     		iTestLogger->Log( CBtTestLogger::ETLInfo, _L( "Network connection allowed (%d)" ), ECoreAppUIsNetworkConnectionAllowed);
       
   336 			break;
       
   337     	}
       
   338 
       
   339     switch( offlineAllowed )
       
   340     	{
       
   341     	case EBTDisabledInOfflineMode:
       
   342     		iTestLogger->Log( CBtTestLogger::ETLInfo, _L( "BT activation disabled in offline mode (%d)" ), EBTDisabledInOfflineMode);
       
   343     		break;
       
   344 		case EBTEnabledInOfflineMode:
       
   345 			iTestLogger->Log( CBtTestLogger::ETLInfo, _L( "BT activation enabled in offline mode (%d)" ), EBTEnabledInOfflineMode);
       
   346    			break;
       
   347     	}    
       
   348     
       
   349     TestCompleted( err, TLFUNCLOG, _L("") );
       
   350     return err;
       
   351     }
       
   352     
       
   353 TInt CBtApiTest::CBTEngSettings_ChangePowerStateTemporarily( CStifItemParser& /*aItem*/ )
       
   354 {
       
   355 	TPtrC name(KNullDesC);
       
   356 	TInt err(KErrNone);
       
   357 	
       
   358 	err = iSettings->ChangePowerStateTemporarily();
       
   359 	if( err )
       
   360 	  	{
       
   361 			TestCompleted(err, TLFUNCLOG, _L(""));
       
   362 			return err;
       
   363 	    }
       
   364 	
       
   365 	TestCompleted(err, TLFUNCLOG, _L(""));
       
   366 	return err;
       
   367 }
       
   368 
       
   369 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   370 // None
       
   371 
       
   372 //  End of File