usbmgmt/usbmgrtest/t_usbmanager_suite/T_UsbManager/src/CCancelStopInterest.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 "CUsbTestStepBase.h"
       
    23 #include "CCancelStopInterest.h"
       
    24 
       
    25 CCancelStopInterest::CCancelStopInterest()
       
    26 
       
    27 	{
       
    28 	// Call base class method to set up the human readable name for logging
       
    29 	SetTestStepName(KCancelStopInterest);
       
    30 	}
       
    31 
       
    32 TVerdict CCancelStopInterest::doTestStepL()
       
    33 	{
       
    34 	SetTestStepResult(EFail);
       
    35 	TInt err;
       
    36 	err = SetIdle(iUsb);
       
    37 	if (err != KErrNone)
       
    38 		{
       
    39 		INFO_PRINTF2(_L("Can't stop USB service: %s"), err);
       
    40 		return TestStepResult();
       
    41 		}
       
    42 	
       
    43 	//Read personality from ini file
       
    44 	TInt personality;
       
    45 	_LIT(KPersonality, "personality"); 
       
    46 	if (!GetIntFromConfig(ConfigSection(), KPersonality, personality))
       
    47 		{
       
    48 		INFO_PRINTF1(_L("Can't get personality id from config file"));
       
    49 		return TestStepResult();
       
    50 		}
       
    51 	//Read timeout from ini file
       
    52 	TInt timeout;
       
    53 	_LIT(KTimeout, "timeout"); 
       
    54 	if (!GetIntFromConfig(ConfigSection(), KTimeout, timeout))
       
    55 		{
       
    56 		INFO_PRINTF1(_L("Can't get timeout from config file"));
       
    57 		return TestStepResult();
       
    58 		}
       
    59 	
       
    60 	//TryStart and wait for service to start
       
    61 	TRequestStatus status;
       
    62 	iUsb.TryStart(personality, status);
       
    63 	User::WaitForRequest(status);
       
    64 	
       
    65 	if (status != KErrNone)
       
    66 		{
       
    67 		INFO_PRINTF2(_L("TryStart finished with error code %d"), status.Int());
       
    68 		return TestStepResult();
       
    69 		}
       
    70 		
       
    71 	//TryStop and immidiately CancelInterest
       
    72 	iUsb.TryStop(status);
       
    73 	iUsb.CancelInterest(RUsb::ETryStop);
       
    74 	User::WaitForRequest(status);
       
    75 	if (status != KErrNone)
       
    76 		{
       
    77 		INFO_PRINTF2(_L("Bad error code after CancelInterest(EUsbTryStop): %d"), status.Int());
       
    78 		return TestStepResult();
       
    79 		}
       
    80 	//Make sure state is still stopping
       
    81 	TUsbServiceState state;
       
    82 	err = iUsb.GetServiceState(state);
       
    83 	if (err != KErrNone)
       
    84 		{
       
    85 		INFO_PRINTF2(_L("GetServiceState returned error code %d"), err);
       
    86 		return TestStepResult();
       
    87 		}
       
    88 	else if (state != EUsbServiceStopping)
       
    89 		{
       
    90 		INFO_PRINTF2(_L("Bad service state after CancelInterest(EUsbTryStop): %d"), state);
       
    91 		return TestStepResult();
       
    92 		}
       
    93 	
       
    94 	//The Usb service should stop even after CancelInterest.
       
    95 	//The timeout value from the config file is used so that we don't wait forever.
       
    96 	for (;;)
       
    97 		{
       
    98 		err = iUsb.GetServiceState(state);
       
    99 		if (err != KErrNone)
       
   100 			{
       
   101 			INFO_PRINTF2(_L("GetServiceState returned error code %d"), err);
       
   102 			break;
       
   103 			}
       
   104 		else if (state == EUsbServiceIdle)
       
   105 			{
       
   106 			SetTestStepResult(EPass);
       
   107 			break;
       
   108 			}
       
   109 		else if (state == EUsbServiceFatalError)
       
   110 			{
       
   111 			INFO_PRINTF1(_L("Service state is EUsbServiceFatalError"));
       
   112 			break;
       
   113 			}
       
   114 		else if (timeout == 0)
       
   115 			{
       
   116 			INFO_PRINTF1(_L("Timeout waiting for service to start"));
       
   117 			break;
       
   118 			}
       
   119 		User::After(1000000);
       
   120 		timeout--;
       
   121 		}
       
   122 
       
   123 	return TestStepResult();
       
   124 	}
       
   125