usbmgmt/usbmgrtest/t_usbmanager_suite/T_UsbManager/src/CSimCablePulling.cpp
changeset 0 c9bc50fca66e
equal deleted inserted replaced
-1:000000000000 0:c9bc50fca66e
       
     1 /*
       
     2 * Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 /**
       
    19  @file
       
    20 */
       
    21 #include <test/testexecutelog.h>
       
    22 #include <d32usbc.h>
       
    23 #include "CUsbTestStepBase.h"
       
    24 #include "CSimCablePulling.h"
       
    25 
       
    26 CSimCablePulling::CSimCablePulling()
       
    27 
       
    28 	{
       
    29 	// Call base class method to set up the human readable name for logging
       
    30 	SetTestStepName(KSimCablePulling);
       
    31 	//We need the service to continue running after the test so that usbcheck
       
    32 	//can find the device connected to the PC.
       
    33 	iStopService = EFalse;
       
    34 	}
       
    35 
       
    36 /*
       
    37  This test simulates pulling and plugging of the usb cable while the service is starting.
       
    38  The device is actually connected to a host PC which checks the correct personality is loaded
       
    39  when the cable is plugged back in.
       
    40 */
       
    41 TVerdict CSimCablePulling::doTestStepL()
       
    42 	{
       
    43 	SetTestStepResult(EFail);
       
    44 	//Read personality from ini file
       
    45 	TInt personality;
       
    46 	_LIT(KPersonality, "personality"); 
       
    47 	if (!GetIntFromConfig(ConfigSection(), KPersonality, personality))
       
    48 		{
       
    49 		INFO_PRINTF1(_L("Can't get personality id from config file"));
       
    50 		return TestStepResult();
       
    51 		}
       
    52 	//Read waiting time from ini file
       
    53 	TInt wait;
       
    54 	_LIT(KWait, "wait"); 
       
    55 	if (!GetIntFromConfig(ConfigSection(), KWait, wait))
       
    56 		{
       
    57 		INFO_PRINTF1(_L("Can't get waiting time from config file"));
       
    58 		return TestStepResult();
       
    59 		}
       
    60 		
       
    61 	TUsbServiceState state;
       
    62 	TInt err;
       
    63 	err = SetIdle(iUsb);
       
    64 	if (err != KErrNone)
       
    65 		{
       
    66 		INFO_PRINTF2(_L("Unable to stop USB service: %d"), err);
       
    67 		return TestStepResult();
       
    68 		}
       
    69 		
       
    70 	//TryStart with new personality
       
    71 	TRequestStatus status;
       
    72 	iUsb.TryStart(personality, status);
       
    73 	
       
    74 	//Simulate cable pull, wait for specified amount of time and then simulate cable plug-in
       
    75 	RDevUsbcClient client;
       
    76 	client.Open(1);
       
    77 	err = client.DeviceDisconnectFromHost();
       
    78 	if (err != KErrNone)
       
    79 		{
       
    80 		INFO_PRINTF2(_L("DeviceDisconnectFromHost returned error code: %d"), err);
       
    81 		return TestStepResult();
       
    82 		}
       
    83 	User::After(wait*1000000);
       
    84 	err = client.DeviceConnectToHost();
       
    85 	if (err != KErrNone)
       
    86 		{
       
    87 		INFO_PRINTF2(_L("DeviceConnectToHost returned error code: %d"), err);
       
    88 		return TestStepResult();
       
    89 		}
       
    90 	client.Close();
       
    91 	
       
    92 
       
    93 	//Check TryStart result
       
    94 	User::WaitForRequest(status);
       
    95 	if (status != KErrNone)
       
    96 		{
       
    97 		INFO_PRINTF2(_L("Unable to start USB service: %d"), status.Int());
       
    98 		return TestStepResult();
       
    99 		}
       
   100 	err = iUsb.GetServiceState(state);
       
   101 	if (err != KErrNone)
       
   102 		{
       
   103 		INFO_PRINTF2(_L("GetServiceState returned error code %d"), err);
       
   104 		return TestStepResult();
       
   105 		}
       
   106 	if (state != EUsbServiceStarted)
       
   107 		{
       
   108 		INFO_PRINTF2(_L("USB service is in the wrong state: %d"), state);
       
   109 		return TestStepResult();
       
   110 		}
       
   111 	
       
   112 	SetTestStepResult(EPass);
       
   113 	return TestStepResult();
       
   114 	}
       
   115