accessoryservices/accessorymonitor/tsrc/public/basic/accmonitoringtestmodule/src/accMonitoringTestModuleCases.cpp
changeset 0 4e1aa6a622a0
child 21 ccb4f6b3db21
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 /*
       
     2 * Copyright (c) 2002 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 <e32math.h>
       
    22 #include <e32base.h>
       
    23 #include <s32mem.h>
       
    24 #include <e32property.h>
       
    25 #include <AccMonitorInfo.h>
       
    26 #include <AccMonitor.h>
       
    27 #include <AccMonitorCapabilities.h>
       
    28 #include <AccMonConnectionEmulator.h>
       
    29 #include <AccMonTestTimer.h>
       
    30 #include "accMonitoringTestModule.h"
       
    31 #include "acc_debug.h"
       
    32 
       
    33 // EXTERNAL DATA STRUCTURES
       
    34 //extern  ?external_data;
       
    35 
       
    36 // EXTERNAL FUNCTION PROTOTYPES  
       
    37 //extern ?external_function( ?arg_type,?arg_type );
       
    38 
       
    39 // CONSTANTS
       
    40 _LIT( KEnter, "Enter" );
       
    41 _LIT( KOnGoing, "On-going" );
       
    42 _LIT( KExit, "Exit" );
       
    43 
       
    44 // MACROS
       
    45 //#define ?macro ?macro_def
       
    46 
       
    47 // LOCAL CONSTANTS AND MACROS
       
    48 //const ?type ?constant_var = ?constant;
       
    49 //#define ?macro_name ?macro_def
       
    50 
       
    51 // MODULE DATA STRUCTURES
       
    52 //enum ?declaration
       
    53 //typedef ?declaration
       
    54 
       
    55 // LOCAL FUNCTION PROTOTYPES
       
    56 //?type ?function_name( ?arg_type, ?arg_type );
       
    57 
       
    58 // FORWARD DECLARATIONS
       
    59 //class ?FORWARD_CLASSNAME;
       
    60 
       
    61 // ============================= LOCAL FUNCTIONS ===============================
       
    62 
       
    63 // -----------------------------------------------------------------------------
       
    64 // ?function_name ?description.
       
    65 // ?description
       
    66 // Returns: ?value_1: ?description
       
    67 //          ?value_n: ?description_line1
       
    68 //                    ?description_line2
       
    69 // -----------------------------------------------------------------------------
       
    70 //
       
    71 /*
       
    72 ?type ?function_name(
       
    73     ?arg_type arg,  // ?description
       
    74     ?arg_type arg)  // ?description
       
    75     {
       
    76 
       
    77     ?code  // ?comment
       
    78 
       
    79     // ?comment
       
    80     ?code
       
    81     }
       
    82 */
       
    83 
       
    84 // ============================ MEMBER FUNCTIONS ===============================
       
    85 
       
    86 // -----------------------------------------------------------------------------
       
    87 // CAccMonitoringTestModule::Case
       
    88 // Returns a test case by number.
       
    89 //
       
    90 // This function contains an array of all available test cases 
       
    91 // i.e pair of case name and test function. If case specified by parameter
       
    92 // aCaseNumber is found from array, then that item is returned.
       
    93 // 
       
    94 // The reason for this rather complicated function is to specify all the
       
    95 // test cases only in one place. It is not necessary to understand how
       
    96 // function pointers to class member functions works when adding new test
       
    97 // cases. See function body for instructions how to add new test case.
       
    98 // -----------------------------------------------------------------------------
       
    99 //
       
   100 const TCaseInfo CAccMonitoringTestModule::Case ( 
       
   101     const TInt aCaseNumber ) const 
       
   102      {
       
   103 
       
   104     /**
       
   105     * To add new test cases, implement new test case function and add new 
       
   106     * line to KCases array specify the name of the case and the function 
       
   107     * doing the test case
       
   108     * In practice, do following
       
   109     * 1) Make copy of existing test case function and change its name
       
   110     *    and functionality. Note that the function must be added to 
       
   111     *    headsetTestModule.cpp file and to headsetTestModule.h 
       
   112     *    header file.
       
   113     *
       
   114     * 2) Add entry to following KCases array either by using:
       
   115     *
       
   116     * 2.1: FUNCENTRY or ENTRY macro
       
   117     * ENTRY macro takes two parameters: test case name and test case 
       
   118     * function name.
       
   119     *
       
   120     * FUNCENTRY macro takes only test case function name as a parameter and
       
   121     * uses that as a test case name and test case function name.
       
   122     *
       
   123     * Or
       
   124     *
       
   125     * 2.2: OOM_FUNCENTRY or OOM_ENTRY macro. Note that these macros are used
       
   126     * only with OOM (Out-Of-Memory) testing!
       
   127     *
       
   128     * OOM_ENTRY macro takes five parameters: test case name, test case 
       
   129     * function name, TBool which specifies is method supposed to be run using
       
   130     * OOM conditions, TInt value for first heap memory allocation failure and 
       
   131     * TInt value for last heap memory allocation failure.
       
   132     * 
       
   133     * OOM_FUNCENTRY macro takes test case function name as a parameter and uses
       
   134     * that as a test case name, TBool which specifies is method supposed to be
       
   135     * run using OOM conditions, TInt value for first heap memory allocation 
       
   136     * failure and TInt value for last heap memory allocation failure. 
       
   137     */ 
       
   138 
       
   139     static TCaseInfoInternal const KCases[] =
       
   140         {
       
   141         // To add new test cases, add new items to this array
       
   142         ENTRY( "Get connected accessories (no accessories connected)", 	AccMonitorTestNoL ),
       
   143         ENTRY( "Get connected accessories test(one accessory)", 	    AccMonitorTestOneL ),
       
   144         ENTRY( "Get connected accessories test(multiple accessories)", 	AccMonitorTestMultiL ),
       
   145         ENTRY( "Test has accessory capa", 								TestHasAccessoryCapaL ),
       
   146         ENTRY( "Test has accessory different capas", 					TestHasAccessoryDifferentCapasL ),
       
   147         ENTRY( "Start Observer test(all connections)",      			StartObservingL ),
       
   148         ENTRY( "Start Observer test(defined type)",   					StartObserving1L ),
       
   149         ENTRY( "Start Observer test(defined accessory)",   				StartObserving2L ),
       
   150         ENTRY( "Start Observer test(wrong accessory)",   				StartObserving3L ),
       
   151         ENTRY( "Start Observer test(monitor non-existing accessory)",   StartObserving4L ),
       
   152         ENTRY( "StopObserving test",    								StopObservingL ),
       
   153         ENTRY( "Compare Infos test",    								CompareInfosL ),
       
   154         ENTRY( "Get value test",    									GetValueTestL ),
       
   155         ENTRY( "Run error test",    									RunErrTestL ),
       
   156         ENTRY( "Start observing all capas test",						StartObserverAllCapasL )        
       
   157         };
       
   158 
       
   159     // Verify that case number is valid
       
   160     if( (TUint) aCaseNumber >= sizeof( KCases ) / 
       
   161                                sizeof( TCaseInfoInternal ) )
       
   162         {
       
   163         // Invalid case, construct empty object
       
   164         TCaseInfo null( (const TText*) L"" );
       
   165         null.iMethod = NULL;
       
   166         null.iIsOOMTest = EFalse;
       
   167         null.iFirstMemoryAllocation = 0;
       
   168         null.iLastMemoryAllocation = 0;
       
   169         return null;
       
   170         } 
       
   171 
       
   172     // Construct TCaseInfo object and return it
       
   173     TCaseInfo tmp ( KCases[ aCaseNumber ].iCaseName );
       
   174     tmp.iMethod = KCases[ aCaseNumber ].iMethod;
       
   175     tmp.iIsOOMTest = KCases[ aCaseNumber ].iIsOOMTest;
       
   176     tmp.iFirstMemoryAllocation = KCases[ aCaseNumber ].iFirstMemoryAllocation;
       
   177     tmp.iLastMemoryAllocation = KCases[ aCaseNumber ].iLastMemoryAllocation;
       
   178         
       
   179     return tmp;
       
   180 
       
   181     }
       
   182 
       
   183 // -----------------------------------------------------------------------------
       
   184 // CAccMonitoringTestModule::AccMonitoringStatusChangedL
       
   185 // Get the information from the connected accessory. Inherited from 
       
   186 // MAccMonitorObserver. After receiving information stop Active Scheduler.
       
   187 // -----------------------------------------------------------------------------
       
   188 //							   
       
   189 void CAccMonitoringTestModule::ConnectedL( CAccMonitorInfo* aInfo )
       
   190     {
       
   191     if( iLeaveFlag )
       
   192     	{
       
   193     	User::Leave( KErrGeneral );
       
   194     	}
       
   195     else
       
   196     	{
       
   197     	/**
       
   198 	    * Get the capabilities from the connected accessory and store 'em to 
       
   199 	    * iConnectedAccessory
       
   200 	    */
       
   201 	    iConnectedAccessory->CopyL( aInfo );
       
   202 	    
       
   203 	    if( iTestTimer->IsActive() )
       
   204 	    	{
       
   205 	    	iTestTimer->Cancel();
       
   206 	    	}
       
   207 	 	// Stop the scheduler
       
   208 	 	CActiveScheduler::Stop();
       
   209     	}
       
   210     }
       
   211 
       
   212 // -----------------------------------------------------------------------------
       
   213 // CAccMonitoringTestModule::AccMonitoringStatusChangedL
       
   214 // Get the information from the disconnected accessory. Inherited from 
       
   215 // MAccMonitorObserver. After receiving information stop Active Scheduler.
       
   216 // -----------------------------------------------------------------------------
       
   217 //							   
       
   218 void CAccMonitoringTestModule::DisconnectedL( CAccMonitorInfo* aInfo )
       
   219     {
       
   220     /**
       
   221     * Get the capabilities from the connected accessory and store 'em to 
       
   222     * iConnectedAccessory
       
   223     */
       
   224     if( iTestTimer->IsActive() )
       
   225     	{
       
   226     	iTestTimer->Cancel();
       
   227     	}
       
   228     iConnectedAccessory->CopyL( aInfo );
       
   229  	// Stop the scheduler
       
   230     CActiveScheduler::Stop();
       
   231     }
       
   232 // -----------------------------------------------------------------------------
       
   233 // CAccMonitoringTestModule::HeadsetStatusError
       
   234 // Test just that this function works.
       
   235 // -----------------------------------------------------------------------------
       
   236 //
       
   237 void CAccMonitoringTestModule::AccMonitorObserverError( TInt /*aError*/ )
       
   238     {
       
   239     iRunErrorCheck = ETrue;
       
   240     if( iTestTimer->IsActive() )
       
   241 	    {
       
   242 	    iTestTimer->Cancel();
       
   243 	    }
       
   244 	iLeaveFlag = EFalse;
       
   245     // Stop the scheduler
       
   246  	CActiveScheduler::Stop();
       
   247     }
       
   248 
       
   249 // -----------------------------------------------------------------------------
       
   250 // CAccMonitoringTestModule::AccMonitorTestNoL
       
   251 // A simple test which creates an instance of the CAccMonitor and uses
       
   252 // GetConnectedAccessoriesL method. Expected result is KErrNotFound since no
       
   253 // accessories are connected.
       
   254 // -----------------------------------------------------------------------------
       
   255 //
       
   256 TInt CAccMonitoringTestModule::AccMonitorTestNoL( 
       
   257     TTestResult& aResult )
       
   258     {
       
   259     __UHEAP_MARK;
       
   260     // Create an instance of the CAccMonitor
       
   261     TInt err( 0 );
       
   262     CAccMonitor* api = CAccMonitor::NewLC();
       
   263     RConnectedAccessories array;
       
   264     CleanupClosePushL ( array );
       
   265     TInt amount;
       
   266     // Get the connected accessories, no accessories should be connected.
       
   267     amount = api->GetConnectedAccessoriesL( array );
       
   268     
       
   269     CAccMonitorInfo* info = CAccMonitorInfo::NewL();
       
   270     CleanupStack::PushL ( info );
       
   271     TRAPD( err1, api->StartObservingL( this, info ) );
       
   272     api->StopObserving();
       
   273     CleanupStack::PopAndDestroy( info );
       
   274     
       
   275     if( amount == KErrNone )
       
   276     	{
       
   277     	err = KErrNone;
       
   278     	_LIT( KDescription, "Function used properly, test passed");
       
   279     	aResult.SetResult( err, KDescription );
       
   280     	}
       
   281     else
       
   282     	{
       
   283     	err = KErrGeneral;
       
   284     	_LIT( KDescription, "Some accessory was connected or something went wrong, test failed" );
       
   285     	aResult.SetResult( err, KDescription );
       
   286     	}
       
   287     
       
   288     array.ResetAndDestroy();
       
   289     CleanupStack::PopAndDestroy( &array );
       
   290     CleanupStack::PopAndDestroy( api );
       
   291     
       
   292     __UHEAP_MARKEND;
       
   293     // Case was executed
       
   294     return err;
       
   295     }
       
   296 
       
   297 // -----------------------------------------------------------------------------
       
   298 // CAccMonitoringTestModule::AccMonitorTestOneL
       
   299 // A test to connect some accessory and then getting the information from 
       
   300 // Accessory Monitoring API. The information is then checked to be correct.
       
   301 // -----------------------------------------------------------------------------
       
   302 //
       
   303 TInt CAccMonitoringTestModule::AccMonitorTestOneL( 
       
   304     TTestResult& aResult )
       
   305     {
       
   306     __UHEAP_MARK;
       
   307     
       
   308     TInt amount;
       
   309     TInt err( 0 );
       
   310     // Connect a wired headset.
       
   311 	CConnectionEmulator* con = CConnectionEmulator::NewL();
       
   312 	CleanupStack::PushL( con );
       
   313 	TBool sync( ETrue );
       
   314 	TRAPD( conErr, con->ConnectAccessoryL( CConnectionEmulator::EWiredHeadSetCon, sync ) );
       
   315 	
       
   316 	RConnectedAccessories array;
       
   317     CleanupClosePushL( array );
       
   318 	// Create an instance of the api.
       
   319     CAccMonitor* api = CAccMonitor::NewL();
       
   320     CleanupStack::PushL( api );
       
   321     // Get the connected accessories.
       
   322     err = GetConnectedAccessoriesL(api, array, amount);
       
   323     CleanupStack::PopAndDestroy( api );
       
   324     if( amount == 1 )
       
   325         {
       
   326         err = KErrNone;
       
   327         }
       
   328     else
       
   329         {
       
   330         err = KErrGeneral;
       
   331         }
       
   332     // Get information about the connected accessory to info instance.
       
   333     CAccMonitorInfo* info = CAccMonitorInfo::NewLC( array[ 0 ] );
       
   334     
       
   335     // Check if capabilities were correct.
       
   336     TBool result( EFalse );
       
   337     result = info->Exists( KAccMonHeadset );
       
   338     array.ResetAndDestroy();
       
   339     if( ( err == KErrNone ) && result )
       
   340     	{
       
   341     	_LIT( KDescription, "Accessory was connected, test passed" );
       
   342     	aResult.SetResult( err, KDescription );
       
   343     	}
       
   344     else
       
   345     	{
       
   346     	err = KErrNone;
       
   347     	_LIT( KDescription, "Something went wrong, test failed" );
       
   348     	aResult.SetResult( err, KDescription );
       
   349     	}
       
   350     
       
   351     CleanupStack::PopAndDestroy( info );
       
   352     // Disconnect the accessory that was connected.
       
   353     TRAPD( disconErr, con->DisconnectAccessoryL( CConnectionEmulator::EWiredHeadSetCon, sync ) );
       
   354     array.ResetAndDestroy();
       
   355     CleanupStack::PopAndDestroy( &array );
       
   356     CleanupStack::PopAndDestroy( con );
       
   357 	if( ( conErr != KErrNone ) && ( disconErr != KErrNone ) )
       
   358     	{
       
   359     	_LIT( KDescription, "Error in connection" );
       
   360     	if( conErr != KErrNone )
       
   361     		{
       
   362     		aResult.SetResult( conErr, KDescription );
       
   363     		}
       
   364     	else
       
   365     		{
       
   366     		aResult.SetResult( disconErr, KDescription );
       
   367     		}
       
   368     	}
       
   369 	__UHEAP_MARKEND;
       
   370     // Case was executed
       
   371     return err;
       
   372 
       
   373     }
       
   374 
       
   375 // -----------------------------------------------------------------------------
       
   376 // CAccMonitoringTestModule::AccMonitorTestMultiL
       
   377 // A test to connect multiple accessories and then getting the information from
       
   378 // Accessory Monitoring API. The information is then checked to be correct.
       
   379 // -----------------------------------------------------------------------------
       
   380 //
       
   381 TInt CAccMonitoringTestModule::AccMonitorTestMultiL( 
       
   382     TTestResult& aResult )
       
   383     {
       
   384     __UHEAP_MARK;
       
   385     TInt amount;
       
   386     TInt err;
       
   387     TInt disconErr( KErrNone );
       
   388     CConnectionEmulator* con = CConnectionEmulator::NewL();
       
   389 	CleanupStack::PushL( con );
       
   390 	TBool sync( ETrue );
       
   391 	// Connect a wired headset
       
   392 	TRAPD( conErr, con->ConnectAccessoryL( CConnectionEmulator::EWiredHeadSetCon, sync ) );
       
   393 	// Connect a wireless headset
       
   394 	//TRAPD( conErr1, con->ConnectAccessoryL( CConnectionEmulator::EWirelessHeadSetCon, sync ) );
       
   395     
       
   396     CAccMonitor* api = CAccMonitor::NewL();
       
   397     CleanupStack::PushL( api );
       
   398     RConnectedAccessories array;
       
   399     CleanupClosePushL( array );
       
   400     // Get the connected accessories from the API
       
   401     err = GetConnectedAccessoriesL(api, array, amount);
       
   402     TBool result( EFalse );
       
   403     // Check the connected accessories and disconnect after being checked.
       
   404     for( TInt i = 0; i != array.Count(); i++ )
       
   405     	{
       
   406     	CAccMonitorInfo* info = CAccMonitorInfo::NewLC( array[ i ] );
       
   407     	if( ( info->AccDeviceType() == KAccMonHeadset ) && ( info->AccPhysicalConnection() == KAccMonWired ) )
       
   408     		{
       
   409     		result = info->Exists( iWiredHeadsetAccessory );
       
   410     		}
       
   411     	if( ( info->AccDeviceType() == KAccMonHeadset ) && ( info->AccPhysicalConnection() == KAccMonBluetooth ) )
       
   412     		{
       
   413     		result = info->Exists( iWirelessHeadsetAccessory );
       
   414     		}
       
   415     	if( ( info->AccDeviceType() == KAccMonCarKit ) && ( info->AccPhysicalConnection() == KAccMonWired ) )
       
   416     		{
       
   417     		result = info->Exists( iWiredCarKitAccessory );
       
   418     		}
       
   419     	if( ( info->AccDeviceType() == KAccMonCarKit ) && ( info->AccPhysicalConnection() == KAccMonBluetooth ) )
       
   420     		{
       
   421     		result = info->Exists( iWirelessCarKitAccessory );
       
   422     		}
       
   423     	if( ( info->AccDeviceType() == KAccMonAVDevice ) && ( info->AccPhysicalConnection() == KAccMonWired ) )
       
   424     		{
       
   425     		result = info->Exists( iTVOutAccessory );
       
   426     		}
       
   427     	if( ( info->AccDeviceType() == KAccMonOffice ) && ( info->AccPhysicalConnection() == KAccMonWired ) )
       
   428     		{
       
   429     		result = info->Exists( iMusicStandAccessory );
       
   430     		}
       
   431     	if( !result )
       
   432     		{
       
   433     		break;
       
   434     		}
       
   435     	TRAPD( disconErr, con->DisconnectAccessoryL( info, sync ) );
       
   436     	CleanupStack::PopAndDestroy( info );
       
   437     	}
       
   438     
       
   439     array.ResetAndDestroy();
       
   440     CleanupStack::PopAndDestroy( &array ); 
       
   441     CleanupStack::PopAndDestroy( api );
       
   442     CleanupStack::PopAndDestroy( con );       
       
   443     
       
   444     // Check result
       
   445     if( ( err == KErrNone ) && result )
       
   446     	{
       
   447     	_LIT( KDescription, "Accessory was connected, test passed" );
       
   448     	aResult.SetResult( err, KDescription );
       
   449     	}
       
   450     else
       
   451     	{
       
   452     	_LIT( KDescription, "Something went wrong, test failed" );
       
   453     	aResult.SetResult( err, KDescription );
       
   454     	}
       
   455     
       
   456     if( ( conErr != KErrNone ) && ( disconErr != KErrNone ) )
       
   457     	{
       
   458     	_LIT( KDescription, "Error in connection" );
       
   459     	if( conErr != KErrNone )
       
   460     		{
       
   461     		aResult.SetResult( conErr, KDescription );
       
   462     		}
       
   463     	else
       
   464     		{
       
   465     		aResult.SetResult( disconErr, KDescription );
       
   466     		}
       
   467     	}
       
   468     __UHEAP_MARKEND;
       
   469     // Case was executed
       
   470     return err;
       
   471 
       
   472     }
       
   473 
       
   474 // -----------------------------------------------------------------------------
       
   475 // CAccMonitoringTestModule::TestHasAccessoryCapa
       
   476 // In this test a wired headset is connected and then the information is fetched
       
   477 // from the API. 
       
   478 // -----------------------------------------------------------------------------
       
   479 //
       
   480 TInt CAccMonitoringTestModule::TestHasAccessoryCapaL( 
       
   481     TTestResult& aResult )
       
   482     {
       
   483     __UHEAP_MARK;
       
   484     TInt amount;
       
   485     TInt err(-999);
       
   486 	CConnectionEmulator* con = CConnectionEmulator::NewL();
       
   487 	CleanupStack::PushL( con );
       
   488 	TBool sync( ETrue );
       
   489 	TRAPD( conErr, con->ConnectAccessoryL( CConnectionEmulator::EWiredHeadSetCon, sync ) );
       
   490 	COM_TRACE_1( "[AccFw:AccMon] CAccMonitoringTestModule::TestHasAccessoryCapaL - conErr = %d", conErr );
       
   491 	
       
   492 	if(conErr == KErrNone)
       
   493 	    {
       
   494 		RConnectedAccessories array;
       
   495 		CleanupClosePushL( array );
       
   496 	
       
   497 		// Create an instance of the api and get the connected accessories
       
   498 		CAccMonitor* api = CAccMonitor::NewL();
       
   499     	CleanupStack::PushL( api );    
       
   500 		COM_TRACE_1( "[AccFw:AccMon] CAccMonitoringTestModule::TestHasAccessoryCapaL before - err = %d", err );
       
   501 	    err = GetConnectedAccessoriesL(api, array, amount);
       
   502 	 
       
   503 	    CleanupStack::PopAndDestroy( api );
       
   504 	    
       
   505 	    if( array.Count() == 0 )
       
   506 	        return KErrGeneral;
       
   507 	    
       
   508 	    if(err == KErrNone)
       
   509 	        {
       
   510 	        COM_TRACE_( "[AccFw:AccMon] CAccMonitoringTestModule::TestHasAccessoryCapaL - Inside if(err == KErrNone)" );
       
   511 	        // Get the information about the accessory
       
   512 	        CAccMonitorInfo* info = CAccMonitorInfo::NewL( array[ 0 ] );
       
   513 	        COM_TRACE_( "[AccFw:AccMon] CAccMonitoringTestModule::TestHasAccessoryCapaL - CAccMonitorInfo object created using array index 0" );
       
   514 	 
       
   515 	        CleanupStack::PushL( info );
       
   516 	        TBool result( EFalse );
       
   517 	        // Use Exists inline function to check if the capability existed
       
   518 	        result = info->Exists( KAccMonStereoAudio );
       
   519 	        COM_TRACE_1( "[AccFw:AccMon] CAccMonitoringTestModule::TestHasAccessoryCapaL after - result = %d", result );
       
   520 	                    
       
   521 	        /**
       
   522 	        * Check that accessories were fetched correctly and that it had the
       
   523 	        * capability.
       
   524 	        */
       
   525 	        if( result || ( err != KErrNone ) )
       
   526 	            {
       
   527 	            _LIT( KDescription, "Accessory has that capability" );
       
   528 	            aResult.SetResult( err, KDescription );
       
   529 	            }
       
   530 	        else
       
   531 	            {
       
   532 	            _LIT( KDescription, "Something went wrong, test case failed" );
       
   533 	            err = KErrGeneral;
       
   534 	            aResult.SetResult( err, KDescription );
       
   535 	            }
       
   536 	        CleanupStack::PopAndDestroy( info );
       
   537 	        COM_TRACE_( "[AccFw:AccMon] CAccMonitoringTestModule::TestHasAccessoryCapaL - After CleanupStack::PopAndDestroy( info ) " );
       
   538 	        }
       
   539 	    array.ResetAndDestroy();
       
   540 	    CleanupStack::PopAndDestroy( &array );
       
   541 	    }
       
   542 	
       
   543     // Disconnect the accessory	
       
   544 	COM_TRACE_( "[AccFw:AccMon] CAccMonitoringTestModule::TestHasAccessoryCapaL - Before Disconnect Accessory" );
       
   545     TRAPD( disconErr, con->DisconnectAccessoryL( CConnectionEmulator::EWiredHeadSetCon, sync ) );
       
   546     COM_TRACE_1( "[AccFw:AccMon] CAccMonitoringTestModule::TestHasAccessoryCapaL disconErr = %d", disconErr );
       
   547     
       
   548     CleanupStack::PopAndDestroy( con );
       
   549     
       
   550     if( ( conErr != KErrNone ) && ( disconErr != KErrNone ) )
       
   551     	{
       
   552     	_LIT( KDescription, "Error in connection" );
       
   553     	if( conErr != KErrNone )
       
   554     		{
       
   555     		aResult.SetResult( conErr, KDescription );
       
   556     		}
       
   557     	else
       
   558     		{
       
   559     		aResult.SetResult( disconErr, KDescription );
       
   560     		}
       
   561     	}
       
   562     __UHEAP_MARKEND;
       
   563     // Case was executed
       
   564     COM_TRACE_1( "[AccFw:AccMon] CAccMonitoringTestModule::TestHasAccessoryCapaL test case executed successfully, returning err = %d", err );
       
   565     return err;
       
   566     }
       
   567 
       
   568 // -----------------------------------------------------------------------------
       
   569 // CAccMonitoringTestModule::TestHasAccessoryDifferentCapasL
       
   570 // In this test a wired headset is connected and then the information is fetched
       
   571 // from the API. 
       
   572 // -----------------------------------------------------------------------------
       
   573 //
       
   574 TInt CAccMonitoringTestModule::TestHasAccessoryDifferentCapasL( 
       
   575     TTestResult& aResult )
       
   576     {
       
   577     __UHEAP_MARK;
       
   578     TInt amount;
       
   579     TInt err;
       
   580 	CConnectionEmulator* con = CConnectionEmulator::NewL();
       
   581 	CleanupStack::PushL( con );
       
   582 	TBool sync( ETrue );
       
   583 	TRAPD( conErr, con->ConnectAccessoryL( CConnectionEmulator::EWiredHeadSetCon, sync ) );
       
   584 	RConnectedAccessories array;
       
   585 	CleanupClosePushL( array );
       
   586 	
       
   587 	// Create an instance of the api and get the connected accessories
       
   588 	CAccMonitor* api = CAccMonitor::NewL();
       
   589     CleanupStack::PushL( api );    
       
   590     err = GetConnectedAccessoriesL(api, array, amount);
       
   591     CleanupStack::PopAndDestroy( api );
       
   592     
       
   593     // Get the information about the accessory
       
   594     CAccMonitorInfo* info = CAccMonitorInfo::NewLC( array[ 0 ] );
       
   595     TBool result( EFalse );
       
   596     TBool result1( EFalse );
       
   597     TBool result2( EFalse );
       
   598     TBool result3( ETrue );
       
   599     TBool result4( ETrue );
       
   600     TBool result5( ETrue );
       
   601     TBool result6( ETrue );
       
   602     
       
   603     TUint64 address = info->AccDeviceAddress();
       
   604     
       
   605     // Use Exists inline function to check if the capability existed
       
   606     result = info->Exists( KAccMonStereoAudio );
       
   607     result1 = info->Exists( KAccMonWired );
       
   608     
       
   609     RAccMonCapabilityArray capaArray;
       
   610     CleanupClosePushL( capaArray );
       
   611     capaArray.Append( KAccMonWired );
       
   612     capaArray.Append( KAccMonStereoAudio );
       
   613     result2 = info->Exists( capaArray );
       
   614     
       
   615     RAccMonCapabilityArray capaArray1;
       
   616     CleanupClosePushL( capaArray1 );
       
   617     capaArray1.Append( KAccMonBluetooth );
       
   618     capaArray1.Append( KAccMonVideoOut );
       
   619     result3 = info->Exists( capaArray1 );
       
   620     
       
   621     RAccMonCapabilityArray capaArray2;
       
   622     CleanupClosePushL( capaArray2 );
       
   623     capaArray2.Append( KAccMonWired );
       
   624     capaArray2.Append( KAccMonVideoOut );
       
   625     result4 = info->Exists( capaArray2 );
       
   626     
       
   627     RAccMonCapabilityArray capaArray3;
       
   628     CleanupClosePushL( capaArray3 );
       
   629     capaArray3.Append( KAccMonVideoOut );
       
   630     capaArray3.Append( KAccMonWired );
       
   631     result5 = info->Exists( capaArray3 );
       
   632     
       
   633     result6 = info->Exists( KAccMonVideoOut );
       
   634     
       
   635     /**
       
   636     * Check that accessories were fetched correctly and that it had the
       
   637     * capability.
       
   638     */
       
   639     if( result && result1 && result2 && !result3 && !result4 && !result5 && !result6 )
       
   640     	{
       
   641     	_LIT( KDescription, "Capability checks OK" );
       
   642     	aResult.SetResult( err, KDescription );
       
   643     	}
       
   644     else
       
   645     	{
       
   646     	_LIT( KDescription, "Something went wrong, test case failed" );
       
   647     	err = KErrGeneral;
       
   648     	aResult.SetResult( err, KDescription );
       
   649     	}
       
   650     // Disconnect the accessory	
       
   651     TRAPD( disconErr, con->DisconnectAccessoryL( CConnectionEmulator::EWiredHeadSetCon, sync ) );
       
   652     
       
   653     CleanupStack::PopAndDestroy( &capaArray3 );
       
   654     CleanupStack::PopAndDestroy( &capaArray2 );
       
   655     CleanupStack::PopAndDestroy( &capaArray1 );
       
   656     CleanupStack::PopAndDestroy( &capaArray );
       
   657         
       
   658     CleanupStack::PopAndDestroy( info );
       
   659     array.ResetAndDestroy();
       
   660     CleanupStack::PopAndDestroy( &array );
       
   661     CleanupStack::PopAndDestroy( con );
       
   662     
       
   663     if( ( conErr != KErrNone ) && ( disconErr != KErrNone ) )
       
   664     	{
       
   665     	_LIT( KDescription, "Error in connection" );
       
   666     	if( conErr != KErrNone )
       
   667     		{
       
   668     		aResult.SetResult( conErr, KDescription );
       
   669     		}
       
   670     	else
       
   671     		{
       
   672     		aResult.SetResult( disconErr, KDescription );
       
   673     		}
       
   674     	}
       
   675     
       
   676     __UHEAP_MARKEND;
       
   677     // Case was executed
       
   678     return err;
       
   679     }
       
   680 
       
   681 // -----------------------------------------------------------------------------
       
   682 // CAccMonitoringTestModule::StartObservingL
       
   683 // This test case just creates the observer and then destroys it.
       
   684 // -----------------------------------------------------------------------------
       
   685 //
       
   686 TInt CAccMonitoringTestModule::StartObservingL( 
       
   687     TTestResult& aResult )
       
   688     {
       
   689     __UHEAP_MARK;
       
   690     TBool is( EFalse );
       
   691     // Create an instance of the API
       
   692     CAccMonitor* api = CAccMonitor::NewL();
       
   693     CleanupStack::PushL( api );
       
   694     
       
   695     // Create the observer by StartObserving function
       
   696 	is = api->IsObserving();
       
   697     TRAPD( err, api->StartObservingL( this ) );
       
   698     
       
   699     CConnectionEmulator* con = CConnectionEmulator::NewLC();
       
   700 	TBool sync( ETrue );
       
   701 	TRAPD( conErr, con->ConnectAccessoryL( CConnectionEmulator::EWiredHeadSetCon, sync ) );
       
   702 	
       
   703 	TInt seconds( 1000000 );
       
   704     iTestTimer->WairForSecondsTest( seconds );
       
   705         
       
   706 	TRAPD( disconErr, con->DisconnectAccessoryL( CConnectionEmulator::EWiredHeadSetCon, sync ) );
       
   707 	CleanupStack::PopAndDestroy( con );
       
   708     
       
   709     // Check results
       
   710     if( err == KErrNone )
       
   711     	{
       
   712     	_LIT( KDescription, "Observer set without errors");
       
   713     	aResult.SetResult( err, KDescription );
       
   714     	}
       
   715     else
       
   716     	{
       
   717     	_LIT( KDescription, "Something went wrong, test failed");
       
   718     	aResult.SetResult( err, KDescription );
       
   719     	}
       
   720     TRAPD( err1, api->StartObservingL( this ) );
       
   721     if( err1 == KErrAlreadyExists )
       
   722     	{
       
   723     	err = KErrNone;
       
   724     	}
       
   725     else
       
   726         {
       
   727         err = KErrGeneral;
       
   728         }
       
   729     CleanupStack::PopAndDestroy( api );
       
   730     
       
   731     iConnectedAccessory->Reset();
       
   732     
       
   733     __UHEAP_MARKEND;
       
   734     // Case executed
       
   735     
       
   736     return err;
       
   737     }
       
   738 
       
   739 // -----------------------------------------------------------------------------
       
   740 // CAccMonitoringTestModule::StartObserving1L
       
   741 // In this test case the observer is set to listen for headset connections that
       
   742 // have stereo audio capability. After the accessory is connected the
       
   743 // capabilities are checked.
       
   744 // -----------------------------------------------------------------------------
       
   745 //
       
   746 TInt CAccMonitoringTestModule::StartObserving1L( 
       
   747     TTestResult& aResult )
       
   748     {
       
   749     __UHEAP_MARK;
       
   750     _LIT( KStatusTest, "StartObservingTest" );
       
   751 	
       
   752 	iConnectedAccessory->Reset();
       
   753 	// Enter
       
   754     CAccMonitor* api = CAccMonitor::NewL();
       
   755     CleanupStack::PushL( api );
       
   756     RAccMonCapabilityArray someArray;
       
   757     CleanupClosePushL ( someArray );
       
   758     someArray.Append( KAccMonStereoAudio );
       
   759     someArray.Append( KAccMonHeadset );
       
   760     // Start observing for stereo headsets
       
   761     TRAPD( err, api->StartObservingL( this, someArray ) );
       
   762     if( err == KErrNone )
       
   763     	{
       
   764     	TRAPD( err, api->StartObservingL( this, someArray ) );
       
   765 	    if( err == KErrAlreadyExists )
       
   766 	    	{
       
   767 	    	err = KErrNone;
       
   768 	    	}
       
   769     	}
       
   770 	CConnectionEmulator* con = CConnectionEmulator::NewLC();
       
   771 	TBool sync( ETrue );
       
   772 	TRAPD( conErr, con->ConnectAccessoryL( CConnectionEmulator::EWiredHeadSetCon, sync ) );
       
   773     
       
   774 //	CActiveScheduler::Start();
       
   775 	TInt seconds( 10000000 );
       
   776     iTestTimer->WairForSecondsTest( seconds );
       
   777 	// Disconnect accessory and destroy the pointters
       
   778 	TRAPD( disconErr, con->DisconnectAccessoryL( CConnectionEmulator::EWiredHeadSetCon, sync ) );
       
   779 	CleanupStack::PopAndDestroy( con );
       
   780 	CleanupStack::PopAndDestroy( &someArray );
       
   781 	CleanupStack::PopAndDestroy( api );    
       
   782     
       
   783     // Check if mono audio and headset capabilities exist
       
   784     TBool result( EFalse );
       
   785     result = iConnectedAccessory->Exists( KAccMonStereoAudio );
       
   786     if( result )
       
   787     	{
       
   788     	result = iConnectedAccessory->Exists( KAccMonHeadset );
       
   789     	}
       
   790     
       
   791     // Check results
       
   792     if( ( err == KErrNone ) && result )
       
   793     	{
       
   794     	_LIT( KDescription, "Observer set without errors");
       
   795     	aResult.SetResult( err, KDescription );
       
   796     	}
       
   797     else
       
   798     	{
       
   799     	_LIT( KDescription, "Something went wrong, test failed");
       
   800     	aResult.SetResult( err, KDescription );
       
   801     	}
       
   802     
       
   803     if( ( conErr != KErrNone ) && ( disconErr != KErrNone ) )
       
   804     	{
       
   805     	_LIT( KDescription, "Error in connection" );
       
   806     	if( conErr != KErrNone )
       
   807     		{
       
   808     		aResult.SetResult( conErr, KDescription );
       
   809     		}
       
   810     	else
       
   811     		{
       
   812     		aResult.SetResult( disconErr, KDescription );
       
   813     		}
       
   814     	
       
   815     	}
       
   816     iConnectedAccessory->Reset();
       
   817     __UHEAP_MARKEND;
       
   818     // Case executed
       
   819     return err;
       
   820     }
       
   821     
       
   822 // -----------------------------------------------------------------------------
       
   823 // CAccMonitoringTestModule::StartObserving2L
       
   824 // In this test case first an accessory is connected. After connection the
       
   825 // accessory information is set to an instance of CAccMonitorInfo. This instance
       
   826 // is then forwarded to observer and the observer starts to listen just
       
   827 // connection/disconnection notifications from this accessory. This accessory is
       
   828 // then connected and checked if the accessory was the correct one.
       
   829 // -----------------------------------------------------------------------------
       
   830 //
       
   831 TInt CAccMonitoringTestModule::StartObserving2L( 
       
   832     TTestResult& aResult )
       
   833     {
       
   834     __UHEAP_MARK;
       
   835 	TBool sync( ETrue );
       
   836 	TInt amount;
       
   837 	TInt err;
       
   838 
       
   839 	iConnectedAccessory->Reset();
       
   840 	TRAPD( conErr, iConnectionEmulator->ConnectAccessoryL( CConnectionEmulator::EWiredHeadSetCon, sync ) );
       
   841 	
       
   842 	// Conncect a wired headset so that this accessory can be observed.
       
   843 	CAccMonitor* api = CAccMonitor::NewL();
       
   844     CleanupStack::PushL( api );
       
   845 	
       
   846 	RConnectedAccessories accessoriesArray;
       
   847     CleanupClosePushL( accessoriesArray );
       
   848 	err = GetConnectedAccessoriesL(api, accessoriesArray, amount);
       
   849     
       
   850     CAccMonitorInfo* info = CAccMonitorInfo::NewLC( accessoriesArray[ 0 ] );
       
   851     TRAPD( err1, api->StartObservingL( this, info ) );
       
   852     if( err1 == KErrNone )
       
   853     	{
       
   854     	TRAPD( err2, api->StartObservingL( this, info ) );
       
   855 	    if( err2 == KErrAlreadyExists )
       
   856 	    	{
       
   857 	    	err = KErrNone;
       
   858 	    	}
       
   859     	}
       
   860     TRAPD( disconErr, iConnectionEmulator->DisconnectAccessoryL( CConnectionEmulator::EWiredHeadSetCon, sync ) );
       
   861     // Start scheduler so that RunL in AccMonitor will get to run
       
   862     TInt seconds( 1000000 );
       
   863     iTestTimer->WairForSecondsTest( seconds );	
       
   864     
       
   865  	// Check results
       
   866     TBool result( EFalse );
       
   867     RAccMonCapabilityArray array;
       
   868     CleanupClosePushL( array );
       
   869     for( TInt i = 0; i != iConnectedAccessory->Count(); i++ )
       
   870     	{
       
   871     	TAccMonCapability capa = iConnectedAccessory->AccCapabilityAtIndex( i );
       
   872     	array.Append( capa );
       
   873     	}
       
   874     
       
   875     result = iConnectedAccessory->Exists( array );
       
   876     if( ( err == KErrNone ) && result )
       
   877     	{
       
   878     	_LIT( KDescription, "Observer set without errors");
       
   879     	aResult.SetResult( err, KDescription );
       
   880     	}
       
   881     else
       
   882     	{
       
   883     	_LIT( KDescription, "Something went wrong, test failed");
       
   884     	aResult.SetResult( err, KDescription );
       
   885     	}
       
   886     CleanupStack::PopAndDestroy( &array );
       
   887     CleanupStack::PopAndDestroy( info );
       
   888     accessoriesArray.ResetAndDestroy();
       
   889  	CleanupStack::PopAndDestroy( &accessoriesArray );	
       
   890     CleanupStack::PopAndDestroy( api );
       
   891  	
       
   892  	
       
   893  	if( ( conErr != KErrNone ) && ( disconErr != KErrNone ) )
       
   894     	{
       
   895     	_LIT( KDescription, "Error in connection" );
       
   896     	if( conErr != KErrNone )
       
   897     		{
       
   898     		aResult.SetResult( conErr, KDescription );
       
   899     		}
       
   900     	else
       
   901     		{
       
   902     		aResult.SetResult( disconErr, KDescription );
       
   903     		}
       
   904     	}
       
   905  	
       
   906  	iConnectedAccessory->Reset();
       
   907  	    
       
   908  	__UHEAP_MARKEND;
       
   909  	    
       
   910     // Case executed
       
   911     return err;
       
   912     }
       
   913     
       
   914 // -----------------------------------------------------------------------------
       
   915 // CAccMonitoringTestModule::StartObserving3L
       
   916 // In this test case first an accessory is connected. After connection the
       
   917 // accessory information is set to an instance of CAccMonitorInfo. This instance
       
   918 // is then forwarded to observer and the observer starts to listen just
       
   919 // connection/disconnection notifications from this accessory. This accessory is
       
   920 // then connected and checked if the accessory was the correct one.
       
   921 // -----------------------------------------------------------------------------
       
   922 //
       
   923 TInt CAccMonitoringTestModule::StartObserving3L( 
       
   924     TTestResult& aResult )
       
   925     {    
       
   926     __UHEAP_MARK;
       
   927     TInt amount;
       
   928     TInt err;
       
   929 	iWrongAccessory = ETrue;
       
   930 	TBool sync( ETrue );
       
   931 	iConnectedAccessory->Reset();
       
   932 	
       
   933 	iConnectionEmulator->ConnectAccessoryL( CConnectionEmulator::EWiredHeadSetCon, sync );
       
   934 	
       
   935 	// Conncect a wired headset so that this accessory can be observed.
       
   936 	CAccMonitor* api = CAccMonitor::NewL();
       
   937     CleanupStack::PushL( api );
       
   938 	
       
   939 	RConnectedAccessories accessoriesArray;
       
   940     CleanupClosePushL( accessoriesArray );
       
   941 	err = GetConnectedAccessoriesL(api, accessoriesArray, amount);
       
   942     
       
   943     CAccMonitorInfo* info = CAccMonitorInfo::NewLC( accessoriesArray[ 0 ] );
       
   944     TRAPD( err1, api->StartObservingL( this, info ) );
       
   945     
       
   946     //iConnectionEmulator->ConnectAccessoryL( CConnectionEmulator::EWirelessCarKitCon, sync );
       
   947 
       
   948     TInt seconds( 1000000 );
       
   949     iTestTimer->WairForSecondsTest( seconds );
       
   950             
       
   951     TRAPD( conErr, iConnectionEmulator->DisconnectAccessoryL( info, sync ) );
       
   952     // Start scheduler so that RunL in AccMonitor will get to run
       
   953 	iTestTimer->WairForSecondsTest( seconds );
       
   954 		
       
   955  	// Check results
       
   956     TBool result( EFalse );
       
   957     RAccMonCapabilityArray array;
       
   958     CleanupClosePushL ( array );
       
   959     for( TInt i = 0; i != iConnectedAccessory->Count(); i++ )
       
   960     	{
       
   961     	TAccMonCapability capa = iConnectedAccessory->AccCapabilityAtIndex( i );
       
   962     	array.Append( capa );
       
   963     	}
       
   964     
       
   965     result = iConnectedAccessory->Exists( array );
       
   966     if( ( err = KErrNone ) && result )
       
   967     	{
       
   968     	_LIT( KDescription, "Observer set without errors");
       
   969     	aResult.SetResult( err, KDescription );
       
   970     	}
       
   971     else
       
   972     	{
       
   973     	_LIT( KDescription, "Something went wrong, test failed");
       
   974     	aResult.SetResult( err, KDescription );
       
   975     	}
       
   976     
       
   977     CleanupStack::PopAndDestroy( &array );
       
   978     //TRAPD( disconErr, iConnectionEmulator->DisconnectAccessoryL( CConnectionEmulator::EWirelessCarKitCon, sync ) );
       
   979 
       
   980  	CleanupStack::PopAndDestroy( info );
       
   981  	accessoriesArray.ResetAndDestroy();
       
   982     CleanupStack::PopAndDestroy( &accessoriesArray );
       
   983     CleanupStack::PopAndDestroy( api );
       
   984  	iWrongAccessory = EFalse;
       
   985  	
       
   986  	if( ( conErr != KErrNone ) )//&& ( disconErr != KErrNone ) )
       
   987     	{
       
   988     	_LIT( KDescription, "Error in connection" );
       
   989     	if( conErr != KErrNone )
       
   990     		{
       
   991     		aResult.SetResult( conErr, KDescription );
       
   992     		}
       
   993     	else
       
   994     		{
       
   995     	//	aResult.SetResult( disconErr, KDescription );
       
   996     		}
       
   997     	}
       
   998  	
       
   999  	iConnectedAccessory->Reset();
       
  1000  	
       
  1001  	 __UHEAP_MARKEND;
       
  1002     // Case executed
       
  1003     return err;
       
  1004     }
       
  1005 
       
  1006 // -------------------------------------------------------------------------------------------------------
       
  1007 // CAccMonitoringTestModule::StartObserving4L
       
  1008 // This is a Negative Test, where observer is set to listen for headset connections that
       
  1009 // has VideoOut capability. After the accessory is connected the
       
  1010 // capabilities are checked. If the Accessory Monitor reports HeadSet Accessory test is failed else passed.
       
  1011 // --------------------------------------------------------------------------------------------------------
       
  1012 //
       
  1013 TInt CAccMonitoringTestModule::StartObserving4L( 
       
  1014     TTestResult& aResult )
       
  1015     {
       
  1016     __UHEAP_MARK;
       
  1017     _LIT( KStatusTest, "StartObservingTest" );
       
  1018     iConnectedAccessory->Reset();
       
  1019     
       
  1020     // Enter
       
  1021     CAccMonitor* api = CAccMonitor::NewL();
       
  1022     CleanupStack::PushL( api );
       
  1023     RAccMonCapabilityArray someArray;
       
  1024     CleanupClosePushL ( someArray );
       
  1025     someArray.Append ( KAccMonVideoOut );
       
  1026     // Start observing for Video Out
       
  1027     TRAPD( err, api->StartObservingL( this, someArray ) );
       
  1028     if( err == KErrNone )
       
  1029         {
       
  1030         TRAPD( err, api->StartObservingL( this, someArray ) );
       
  1031         if( err == KErrAlreadyExists )
       
  1032             {
       
  1033             err = KErrNone;
       
  1034             }
       
  1035         }
       
  1036     
       
  1037     // Connect Accessory Other than the one that is being observed.
       
  1038     CConnectionEmulator* con = CConnectionEmulator::NewLC();
       
  1039     TBool sync( ETrue );
       
  1040     TRAPD( conErr, con->ConnectAccessoryL( CConnectionEmulator::EWiredHeadSetCon, sync ) );
       
  1041     
       
  1042     TInt seconds( 10000000 );
       
  1043     iTestTimer->WairForSecondsTest( seconds );
       
  1044     // Disconnect accessory and destroy the pointters
       
  1045     TRAPD( disconErr, con->DisconnectAccessoryL( CConnectionEmulator::EWiredHeadSetCon, sync ) );
       
  1046     CleanupStack::PopAndDestroy( con );
       
  1047     CleanupStack::PopAndDestroy( &someArray );
       
  1048     CleanupStack::PopAndDestroy( api ); 
       
  1049     
       
  1050     // Check if mono audio and headset capabilities exist
       
  1051     TBool result( EFalse );
       
  1052     result = iConnectedAccessory->Exists( KAccMonVideoOut );
       
  1053     
       
  1054     _LIT( KDescription, "Error in Acc Monitor Observation" );
       
  1055     if ( result )
       
  1056         {
       
  1057         aResult.SetResult( KErrGeneral, KDescription );
       
  1058         }
       
  1059     
       
  1060     iConnectedAccessory->Reset();
       
  1061     __UHEAP_MARKEND;
       
  1062     // Case executed
       
  1063     return err;
       
  1064     }
       
  1065 
       
  1066 // -----------------------------------------------------------------------------
       
  1067 // CAccMonitoringTestModule::StopObservingL
       
  1068 // A test case for just testing the StobObserving method.
       
  1069 // -----------------------------------------------------------------------------
       
  1070 //
       
  1071 TInt CAccMonitoringTestModule::StopObservingL( 
       
  1072     TTestResult& aResult )
       
  1073     {
       
  1074     __UHEAP_MARK;
       
  1075     TInt err( KErrNone );
       
  1076     // Create an instance of the api an stop the observer.
       
  1077     CAccMonitor* api = CAccMonitor::NewL();
       
  1078     CleanupStack::PushL( api );
       
  1079     api->StopObserving();
       
  1080     CleanupStack::PopAndDestroy( api );
       
  1081     
       
  1082     // Test was executed so test OK
       
  1083     _LIT( KDescription, "Observer stopped, test case passed" );
       
  1084     aResult.SetResult( err, KDescription );
       
  1085     __UHEAP_MARKEND;
       
  1086     return err;
       
  1087     }
       
  1088 
       
  1089 // -----------------------------------------------------------------------------
       
  1090 // CAccMonitoringTestModule::CompareInfosL
       
  1091 // A test case for comparing different kind of CAccMonitorInfos.
       
  1092 // -----------------------------------------------------------------------------
       
  1093 //    
       
  1094 TInt CAccMonitoringTestModule::CompareInfosL( 
       
  1095     TTestResult& aResult )
       
  1096     {
       
  1097     __UHEAP_MARK;
       
  1098     TInt amount;
       
  1099     TInt err;
       
  1100     // Create an instance of the CAccMonitorInfo.
       
  1101     
       
  1102     TRAPD( conErr, iConnectionEmulator->ConnectAccessoryL( CConnectionEmulator::EWiredHeadSetCon, ETrue ) );
       
  1103         
       
  1104     iTestTimer->WairForSecondsTest( 10000000 );
       
  1105     
       
  1106     CAccMonitor* api = CAccMonitor::NewL();
       
  1107     CleanupStack::PushL( api );
       
  1108     RConnectedAccessories acc;
       
  1109     CleanupClosePushL( acc );
       
  1110     err = GetConnectedAccessoriesL(api, acc, amount);
       
  1111     CAccMonitorInfo* info = CAccMonitorInfo::NewLC();
       
  1112     CAccMonitorInfo* info1 = CAccMonitorInfo::NewLC();
       
  1113     info->CopyL( acc[ 0 ] );
       
  1114     info1->CopyL( info );
       
  1115     if( info->CompareL( info1 ) )
       
  1116     	{
       
  1117     	err = KErrNone;
       
  1118     	}
       
  1119     else
       
  1120     	{
       
  1121     	err = KErrGeneral;
       
  1122     	}
       
  1123     TRAPD( disconErr, iConnectionEmulator->DisconnectAccessoryL( info, ETrue ) );
       
  1124     CleanupStack::PopAndDestroy( info1 );
       
  1125     CleanupStack::PopAndDestroy( info );
       
  1126     acc.ResetAndDestroy();
       
  1127     CleanupStack::PopAndDestroy( &acc );	
       
  1128     CleanupStack::PopAndDestroy( api );
       
  1129     
       
  1130     // Test was executed so test OK
       
  1131     if( ( conErr != KErrNone ) && ( disconErr != KErrNone ) )
       
  1132     	{
       
  1133     	_LIT( KDescription, "Error in connection" );
       
  1134     	if( conErr != KErrNone )
       
  1135     		{
       
  1136     		aResult.SetResult( conErr, KDescription );
       
  1137     		}
       
  1138     	else
       
  1139     		{
       
  1140     		aResult.SetResult( disconErr, KDescription );
       
  1141     		}
       
  1142     	}
       
  1143     else
       
  1144     	{
       
  1145     	_LIT( KDescription, "Comparison succesful" );
       
  1146     	aResult.SetResult( err, KDescription );
       
  1147     	}
       
  1148     __UHEAP_MARKEND;
       
  1149     return err;
       
  1150     }
       
  1151 
       
  1152 // -----------------------------------------------------------------------------
       
  1153 // CAccMonitoringTestModule::GetValueTestL
       
  1154 // A test case for comparing different kind of CAccMonitorInfos.
       
  1155 // -----------------------------------------------------------------------------
       
  1156 //    
       
  1157 TInt CAccMonitoringTestModule::GetValueTestL( 
       
  1158     TTestResult& aResult )
       
  1159     {
       
  1160     __UHEAP_MARK;
       
  1161     RAccMonCapabilityArray array;
       
  1162     CleanupClosePushL( array );
       
  1163     TInt amount;
       
  1164     TInt err;
       
  1165     array.Append( KAccMonHeadset );
       
  1166     array.Append( KAccMonWired );
       
  1167     array.Append( KAccMonMonoAudio );
       
  1168     array.Append( KAccMonMicAudioInput );
       
  1169     array.Append( KAccMonSpeakerAudioOutput );
       
  1170     TRAPD( conErr, iConnectionEmulator->ConnectAccessoryL( CConnectionEmulator::EWiredHeadSetCon, ETrue ) );
       
  1171     CAccMonitor* api = CAccMonitor::NewL();
       
  1172     CleanupStack::PushL( api );
       
  1173     RConnectedAccessories acc;
       
  1174     CleanupClosePushL( acc );
       
  1175     err = GetConnectedAccessoriesL(api, acc, amount);
       
  1176     CAccMonitorInfo* info = CAccMonitorInfo::NewLC();
       
  1177     TInt value;
       
  1178     if( acc.Count() != 0 )
       
  1179         {
       
  1180         info->CopyL( acc[ 0 ] );
       
  1181         TRAPD( err2, api->GetCapabilityValueL( info, KAccMonVideoOut, value ) );
       
  1182     	if( err2 == KErrNotFound )
       
  1183     		{
       
  1184     		CAccMonitorInfo* info1 = CAccMonitorInfo::NewLC();
       
  1185     		TRAPD( err3, api->GetCapabilityValueL( info1, KAccMonVideoOut, value ) );
       
  1186     		if( err3 == KErrArgument )
       
  1187     			{
       
  1188     			TRAPD( err5, api->GetCapabilityValueL( info1, KAccMonWired, value ) );
       
  1189     			_LIT( KDescription, "Test passed" );
       
  1190     			err = KErrNone;
       
  1191     			aResult.SetResult( err, KDescription );
       
  1192     			}
       
  1193     		else
       
  1194     			{
       
  1195     			_LIT( KDescription, "Test failed in accessory info" );
       
  1196     			aResult.SetResult( err, KDescription );
       
  1197     			}
       
  1198     		CleanupStack::PopAndDestroy( info1 );
       
  1199     		}
       
  1200     	else
       
  1201     		{
       
  1202     		_LIT( KDescription, "Test failed in capability" );
       
  1203     		aResult.SetResult( err, KDescription );
       
  1204 	    	}
       
  1205         }
       
  1206     TRAPD( conErr1, iConnectionEmulator->DisconnectAccessoryL( info, ETrue ) );
       
  1207     TRAPD( err4, api->GetCapabilityValueL( info, KAccMonVideoOut, value ) );
       
  1208     CleanupStack::PopAndDestroy( info );
       
  1209     acc.ResetAndDestroy();
       
  1210     CleanupStack::PopAndDestroy( &acc );
       
  1211     CleanupStack::PopAndDestroy( api );
       
  1212     CleanupStack::PopAndDestroy( &array );
       
  1213     
       
  1214     __UHEAP_MARKEND;
       
  1215     return err;
       
  1216     }
       
  1217     
       
  1218 TInt CAccMonitoringTestModule::RunErrTestL( 
       
  1219     TTestResult& aResult )
       
  1220     {
       
  1221     __UHEAP_MARK;
       
  1222     iLeaveFlag = ETrue;
       
  1223     CAccMonitor* api = CAccMonitor::NewL();
       
  1224     CleanupStack::PushL( api );
       
  1225     api->StartObservingL( this );
       
  1226     TRAPD( err, iConnectionEmulator->ConnectAccessoryL( CConnectionEmulator::EWiredHeadSetCon, ETrue ) );
       
  1227     TInt seconds( 1000000 );
       
  1228     iTestTimer->WairForSecondsTest( seconds );	
       
  1229     CleanupStack::PopAndDestroy( api );
       
  1230     iLeaveFlag = EFalse;
       
  1231     TRAPD( err1, iConnectionEmulator->DisconnectAccessoryL( CConnectionEmulator::EWiredHeadSetCon, ETrue ) );
       
  1232     if( err == KErrNone )
       
  1233         {
       
  1234         _LIT( KDescription, "Test passed" );
       
  1235 		aResult.SetResult( err, KDescription );
       
  1236         }
       
  1237     __UHEAP_MARKEND;
       
  1238     return err;
       
  1239     }
       
  1240     
       
  1241 TInt CAccMonitoringTestModule::StartObserverAllCapasL( 
       
  1242     TTestResult& aResult )
       
  1243     {
       
  1244     __UHEAP_MARK;
       
  1245     CAccMonitor* api = CAccMonitor::NewL();
       
  1246     CleanupStack::PushL( api );
       
  1247     RAccMonCapabilityArray array;
       
  1248     CleanupClosePushL( array );
       
  1249     array.Append( KAccMonHeadset );
       
  1250     array.Append( KAccMonCarKit );
       
  1251     array.Append( KAccMonOffice );
       
  1252     array.Append( KAccMonLoopset );
       
  1253     array.Append( KAccMonTTY );
       
  1254     array.Append( KAccMonAVDevice );
       
  1255     array.Append( KAccMonWired );
       
  1256     array.Append( KAccMonBluetooth );
       
  1257     array.Append( KAccMonStereoAudio );
       
  1258     array.Append( KAccMonMonoAudio );
       
  1259     array.Append( KAccMonSpeakerAudioOutput );
       
  1260     array.Append( KAccMonMicAudioInput );
       
  1261     array.Append( KAccMonAudioOut );
       
  1262     array.Append( KAccMonBTHSP );
       
  1263     array.Append( KAccMonBTHFP );
       
  1264     array.Append( KAccMonBTAVRCP );
       
  1265     array.Append( KAccMonBTA2DP );
       
  1266     array.Append( KAccMonVideoOut );
       
  1267     TRAPD( err, api->StartObservingL( this, array ) );
       
  1268     TInt seconds( 1000000 );
       
  1269     TRAPD( err1, iConnectionEmulator->ConnectAccessoryL( CConnectionEmulator::EWiredHeadSetCon, ETrue ) );
       
  1270     iTestTimer->WairForSecondsTest( seconds );	
       
  1271     CleanupStack::PopAndDestroy( &array );
       
  1272     CleanupStack::PopAndDestroy( api );
       
  1273     
       
  1274     TRAPD( err2, iConnectionEmulator->DisconnectAccessoryL( CConnectionEmulator::EWiredHeadSetCon, ETrue ) );
       
  1275     if( err == KErrNone )
       
  1276         {
       
  1277         _LIT( KDescription, "Test passed" );
       
  1278 		aResult.SetResult( err, KDescription );
       
  1279         }
       
  1280     __UHEAP_MARKEND;
       
  1281     return err;
       
  1282     }
       
  1283     
       
  1284 TInt CAccMonitoringTestModule::ConnectHeadsetL( 
       
  1285     TTestResult& aResult )
       
  1286     {
       
  1287     /*__UHEAP_MARK;
       
  1288     CAccMonitor* api = CAccMonitor::NewL();
       
  1289     CleanupStack::PushL( api );
       
  1290     RAccMonCapabilityArray someArray;
       
  1291     someArray.Append( KAccMonStereoAudio );
       
  1292     someArray.Append( KAccMonHeadset );
       
  1293     // Start observing for stereo headsets
       
  1294     TRAPD( err, api->StartObservingL( this, someArray ) );
       
  1295     */
       
  1296 	TBool sync( ETrue );
       
  1297 	TRAPD( err, iConnectionEmulator->ConnectAccessoryL( CConnectionEmulator::EWiredHeadSetCon, sync ) );
       
  1298     /*
       
  1299     TInt seconds( 10000000 );
       
  1300     iTestTimer->WairForSecondsTest( seconds );
       
  1301     CActiveScheduler::Start();
       
  1302     
       
  1303     CleanupStack::Pop( api );
       
  1304     delete api;
       
  1305     someArray.Close();
       
  1306     __UHEAP_MARKEND;
       
  1307     return err;*/
       
  1308     }
       
  1309 
       
  1310 TInt CAccMonitoringTestModule::ConnectBTHeadsetL( 
       
  1311     TTestResult& aResult )
       
  1312     {
       
  1313     TRAPD( err, iConnectionEmulator->ConnectAccessoryL( CConnectionEmulator::ETTY, ETrue ) );
       
  1314     RConnectedAccessories array;
       
  1315     
       
  1316 	// Create an instance of the api.
       
  1317     CAccMonitor* api = CAccMonitor::NewL();
       
  1318     CleanupStack::PushL( api );
       
  1319     // Get the connected accessories.
       
  1320     //TInt amount = api->GetConnectedAccessoriesL( array );
       
  1321     TInt amount;
       
  1322     err = GetConnectedAccessoriesL(api, array, amount);
       
  1323     CleanupStack::PopAndDestroy( api );
       
  1324     
       
  1325     TRAPD( err1, iConnectionEmulator->DisconnectAccessoryL( CConnectionEmulator::ETTY, ETrue ) );
       
  1326     return KErrNone;
       
  1327     }
       
  1328 
       
  1329 TInt CAccMonitoringTestModule::DisconnectHeadsetL( 
       
  1330     TTestResult& aResult )
       
  1331     {
       
  1332     //TRAPD( err, iConnectionEmulator->ConnectAccessoryL( CConnectionEmulator::ELoopset, ETrue ) );
       
  1333     //RConnectedAccessories array;
       
  1334     
       
  1335 	// Create an instance of the api.
       
  1336     //CAccMonitor* api = CAccMonitor::NewL();
       
  1337     //CleanupStack::PushL( api );
       
  1338     // Get the connected accessories.
       
  1339     //TInt amount = api->GetConnectedAccessoriesL( array );
       
  1340     //CleanupStack::PopAndDestroy( api );
       
  1341     
       
  1342     TRAPD( err1, iConnectionEmulator->DisconnectAccessoryL( CConnectionEmulator::ELoopset, ETrue ) );
       
  1343     return err1;
       
  1344     }
       
  1345     
       
  1346 TInt CAccMonitoringTestModule::DisconnectBTHeadsetL( 
       
  1347     TTestResult& aResult )
       
  1348     {
       
  1349    // TRAPD( err, iConnectionEmulator->DisconnectAccessoryL( CConnectionEmulator::EWirelessHeadSetCon, ETrue ) );
       
  1350     return KErrNone;
       
  1351     }
       
  1352    
       
  1353 TInt CAccMonitoringTestModule::GetConnectedAccessoriesL( CAccMonitor* aApi, RConnectedAccessories& aArray, TInt& aAmount )
       
  1354     {
       
  1355     for( ; ; )
       
  1356         {
       
  1357         aAmount = aApi->GetConnectedAccessoriesL( aArray );
       
  1358         User::After(1000000);
       
  1359         if ( aAmount )
       
  1360             {
       
  1361             break;
       
  1362             }
       
  1363         }
       
  1364     
       
  1365     if((aArray.Count() == 0))
       
  1366         User::Leave(KErrGeneral);
       
  1367     
       
  1368     return KErrNone;
       
  1369     }
       
  1370 
       
  1371 //  End of File