|
1 /* |
|
2 * Copyright (c) 2005-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 "CCancelStartInterest.h" |
|
24 |
|
25 CCancelStartInterest::CCancelStartInterest() |
|
26 |
|
27 { |
|
28 // Call base class method to set up the human readable name for logging |
|
29 SetTestStepName(KCancelStartInterest); |
|
30 } |
|
31 |
|
32 TVerdict CCancelStartInterest::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 then cancel interest. |
|
61 TRequestStatus status; |
|
62 iUsb.TryStart(personality, status); |
|
63 iUsb.CancelInterest(RUsb::ETryStart); |
|
64 User::WaitForRequest(status); |
|
65 if (status != KErrNone) |
|
66 { |
|
67 INFO_PRINTF2(_L("Bad error code after CancelInterest(EUsbTryStart): %d"), status.Int()); |
|
68 return TestStepResult(); |
|
69 } |
|
70 //Make sure state is still starting |
|
71 TUsbServiceState state; |
|
72 err = iUsb.GetServiceState(state); |
|
73 if (err != KErrNone) |
|
74 { |
|
75 INFO_PRINTF2(_L("GetServiceState returned error code %d"), err); |
|
76 return TestStepResult(); |
|
77 } |
|
78 else if (state != EUsbServiceStarting) |
|
79 { |
|
80 INFO_PRINTF2(_L("Bad service state after CancelInterest(EUsbTryStart): %d"), state); |
|
81 return TestStepResult(); |
|
82 } |
|
83 |
|
84 |
|
85 //The Usb service should start even after CancelInterest. |
|
86 //The timeout value from the config file is used so that we don't wait forever. |
|
87 for (;;) |
|
88 { |
|
89 err = iUsb.GetServiceState(state); |
|
90 if (err != KErrNone) |
|
91 { |
|
92 INFO_PRINTF2(_L("GetServiceState returned error code %d"), err); |
|
93 break; |
|
94 } |
|
95 else if (state == EUsbServiceStarted) |
|
96 { |
|
97 SetTestStepResult(EPass); |
|
98 break; |
|
99 } |
|
100 else if (state == EUsbServiceFatalError) |
|
101 { |
|
102 INFO_PRINTF1(_L("Service state is EUsbServiceFatalError")); |
|
103 break; |
|
104 } |
|
105 else if (timeout == 0) |
|
106 { |
|
107 INFO_PRINTF1(_L("Timeout waiting for service to start")); |
|
108 break; |
|
109 } |
|
110 User::After(1000000); |
|
111 timeout--; |
|
112 } |
|
113 |
|
114 return TestStepResult(); |
|
115 } |
|
116 |