|
1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of the License "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // @internalComponent |
|
15 // |
|
16 // |
|
17 |
|
18 #include <e32std.h> |
|
19 #include <e32std_private.h> |
|
20 #include <u32std.h> // unicode builds |
|
21 #include <e32base.h> |
|
22 #include <e32base_private.h> |
|
23 #include <e32Test.h> // RTest headder |
|
24 #include "testcaseroot.h" |
|
25 #include "testcasewd.h" |
|
26 #include "testcase0467.h" |
|
27 |
|
28 |
|
29 |
|
30 // # times to repeat the steps (default=3) |
|
31 #define INSERT_REPEATS gOpenIterations |
|
32 |
|
33 // the name below is used to add a pointer to our construction method to a pointer MAP in |
|
34 // the class factory |
|
35 _LIT(KTestCaseId,"PBASE-USB_OTGDI-0467"); |
|
36 const TTestCaseFactoryReceipt<CTestCase0467> CTestCase0467::iFactoryReceipt(KTestCaseId); |
|
37 |
|
38 CTestCase0467* CTestCase0467::NewL(TBool aHost) |
|
39 { |
|
40 LOG_FUNC |
|
41 CTestCase0467* self = new (ELeave) CTestCase0467(aHost); |
|
42 CleanupStack::PushL(self); |
|
43 self->ConstructL(); |
|
44 CleanupStack::Pop(self); |
|
45 return self; |
|
46 } |
|
47 |
|
48 |
|
49 CTestCase0467::CTestCase0467(TBool aHost) |
|
50 : CTestCaseRoot(KTestCaseId, aHost) |
|
51 { |
|
52 LOG_FUNC |
|
53 |
|
54 } |
|
55 |
|
56 |
|
57 /** |
|
58 ConstructL |
|
59 */ |
|
60 void CTestCase0467::ConstructL() |
|
61 { |
|
62 LOG_FUNC |
|
63 iRepeats = INSERT_REPEATS; |
|
64 iWDTimer = CTestCaseWatchdog::NewL(); |
|
65 |
|
66 BaseConstructL(); |
|
67 } |
|
68 |
|
69 |
|
70 CTestCase0467::~CTestCase0467() |
|
71 { |
|
72 LOG_FUNC |
|
73 |
|
74 Cancel(); |
|
75 delete iWDTimer; |
|
76 |
|
77 } |
|
78 |
|
79 |
|
80 void CTestCase0467::ExecuteTestCaseL() |
|
81 { |
|
82 LOG_FUNC |
|
83 iCaseStep = EPreconditions; |
|
84 |
|
85 iRepeats = KOperationRetriesMax; // VBus event rise retries |
|
86 |
|
87 CActiveScheduler::Add(this); |
|
88 SelfComplete(); |
|
89 |
|
90 } |
|
91 |
|
92 |
|
93 void CTestCase0467::DoCancel() |
|
94 { |
|
95 LOG_FUNC |
|
96 |
|
97 // cancel our timer |
|
98 iTimer.Cancel(); |
|
99 } |
|
100 |
|
101 |
|
102 void CTestCase0467::CancelKB(CTestCaseRoot *pThis) |
|
103 { |
|
104 CTestCase0467 * p = REINTERPRET_CAST(CTestCase0467 *,pThis); |
|
105 // cancel the pending call |
|
106 |
|
107 p->iConsole->ReadCancel(); |
|
108 |
|
109 } |
|
110 |
|
111 |
|
112 void CTestCase0467::CancelIdPin(CTestCaseRoot *pThis) |
|
113 { |
|
114 LOG_FUNC |
|
115 |
|
116 CTestCase0467 * p = REINTERPRET_CAST(CTestCase0467 *,pThis); |
|
117 // cancel any pending call, and then complete our active obj with a timeout value |
|
118 p->otgCancelOtgIdPinNotification(); |
|
119 p->SelfComplete(KTestCaseWatchdogTO); |
|
120 } |
|
121 |
|
122 |
|
123 // This test result depends on all the ID detection tests and the VBus driving and dropping tests have not yet passed |
|
124 void CTestCase0467::DescribePreconditions() |
|
125 { |
|
126 test.Printf(_L("Remove 'A' connector beforehand.\n")); |
|
127 test.Printf(_L("ID_PIN detection and VBus driving tests must already pass.\n")); |
|
128 } |
|
129 |
|
130 |
|
131 // handle event completion |
|
132 void CTestCase0467::RunStepL() |
|
133 { |
|
134 LOG_FUNC |
|
135 // Obtain the completion code for this CActive obj. |
|
136 TInt completionCode(iStatus.Int()); |
|
137 TBuf<MAX_DSTRLEN> aDescription; |
|
138 |
|
139 switch(iCaseStep) |
|
140 { |
|
141 case EPreconditions: |
|
142 iCaseStep = ELoadLdd; |
|
143 if (iAutomated) |
|
144 { |
|
145 iCaseStep = ELoadLdd; |
|
146 SelfComplete(); |
|
147 break; |
|
148 } |
|
149 // prompt to remove connector |
|
150 test.Printf(KRemoveAConnectorPrompt); |
|
151 test.Printf(KPressAnyKeyToContinue); |
|
152 RequestCharacter(); |
|
153 break; |
|
154 |
|
155 case ELoadLdd: |
|
156 // 1. load the LDD and init. |
|
157 if (!StepLoadLDD()) |
|
158 { |
|
159 break; |
|
160 } |
|
161 // initialize variables for loop control |
|
162 |
|
163 iCaseStep = EWaitForIDPresent; |
|
164 SelfComplete(); |
|
165 break; |
|
166 |
|
167 case ERepeatLoop: // 2 |
|
168 test.Printf(_L("Repeat test %d/%d\n"), INSERT_REPEATS-iRepeats+1, INSERT_REPEATS); |
|
169 |
|
170 if (--iRepeats) |
|
171 iCaseStep = EWaitForIDPresent; |
|
172 else |
|
173 iCaseStep = EUnloadLdd; |
|
174 SelfComplete(); |
|
175 break; |
|
176 |
|
177 case EWaitForIDPresent: |
|
178 // 3. prompt for insertion |
|
179 test.Printf(KInsertAConnectorPrompt); |
|
180 otgQueueOtgIdPinNotification( iOTGIdPin, iStatus ); |
|
181 |
|
182 SetActive(); |
|
183 iCaseStep = EVerifyIDPresent; |
|
184 iDetectionRetry = 0; |
|
185 break; |
|
186 |
|
187 case EVerifyIDPresent: |
|
188 // 4. detect id_pin event |
|
189 LOG_VERBOSE1(_L("STEP4 - detect id_pin event 'A'\n")); |
|
190 |
|
191 // retrieve the current ID_PIN value |
|
192 otgQueueOtgIdPinNotification( iOTGIdPin, iStatus ); |
|
193 otgCancelOtgIdPinNotification(); |
|
194 User::WaitForRequest(iStatus); // swallow the cancellation event (serves to test that it does cancel) |
|
195 |
|
196 |
|
197 if (iOTGIdPin != RUsbOtgDriver::EIdPinAPlug) |
|
198 { |
|
199 if (iDetectionRetry++ < 3) |
|
200 { |
|
201 iCaseStep = EVerifyIDPresent; |
|
202 otgQueueOtgIdPinNotification( iOTGIdPin, iStatus ); |
|
203 |
|
204 SetActive(); |
|
205 break; |
|
206 } |
|
207 else |
|
208 { |
|
209 return TestFailed(KErrAbort, _L("ID_PIN NOT 'seen' - FAILED!")); |
|
210 } |
|
211 } |
|
212 |
|
213 // check using the API in a syncronous way too |
|
214 // NOTE: we test this twice to explore and expose timing problems |
|
215 if (!otgIdPinPresent()) |
|
216 { |
|
217 return TestFailed(KErrAbort, _L("ID_PIN syncronous call error - FAILED!")); |
|
218 } |
|
219 iCaseStep = EWaitForIDGone; |
|
220 SelfComplete(); |
|
221 iDetectionRetry = 0; |
|
222 break; |
|
223 |
|
224 case EWaitForIDGone: |
|
225 // 5. prompt for insertion |
|
226 test.Printf(KRemoveAConnectorPrompt); |
|
227 otgQueueOtgIdPinNotification( iOTGIdPin, iStatus ); |
|
228 SetActive(); |
|
229 iCaseStep = EVerifyIDGone; |
|
230 break; |
|
231 |
|
232 case EVerifyIDGone: |
|
233 // 6. detect id_pin gone event |
|
234 LOG_VERBOSE1(_L("STEP4 - detect id_pin remove event 'B'\n")); |
|
235 test.Printf(_L("ID_PIN=%d\n"), iOTGIdPin); |
|
236 |
|
237 User::After(5000); // 5ms |
|
238 otgQueueOtgIdPinNotification( iOTGIdPin, iStatus ); |
|
239 otgCancelOtgIdPinNotification(); |
|
240 User::WaitForRequest(iStatus); // swallow it |
|
241 test.Printf(_L("ID_PIN=%d\n"), iOTGIdPin); |
|
242 |
|
243 if (iOTGIdPin != RUsbOtgDriver::EIdPinBPlug) |
|
244 { |
|
245 if (iDetectionRetry++ < 3) |
|
246 { |
|
247 iCaseStep = EVerifyIDGone; |
|
248 otgQueueOtgIdPinNotification( iOTGIdPin, iStatus ); |
|
249 SetActive(); |
|
250 break; |
|
251 } |
|
252 else |
|
253 { |
|
254 return TestFailed(KErrAbort, _L("ID_PIN NOT 'removed' - FAILED!")); |
|
255 } |
|
256 } |
|
257 // check using the API in a syncronous way too |
|
258 if (otgIdPinPresent()) |
|
259 { |
|
260 return TestFailed(KErrAbort, _L("ID_PIN syncronous call error - FAILED!")); |
|
261 } |
|
262 iCaseStep = ERepeatLoop; |
|
263 SelfComplete(); |
|
264 break; |
|
265 |
|
266 case EUnloadLdd: |
|
267 // 7. unload |
|
268 if (EFalse == StepUnloadLDD()) |
|
269 return TestFailed(KErrAbort,_L("Unload Ldd failure")); |
|
270 |
|
271 iCaseStep = ELastStep; |
|
272 SelfComplete(); |
|
273 break; |
|
274 |
|
275 case ELastStep: |
|
276 TestPassed(); |
|
277 break; |
|
278 |
|
279 default: |
|
280 test.Printf(_L("<Error> unknown test step")); |
|
281 Cancel(); |
|
282 return (TestFailed(KErrCorrupt, _L("<Error> unknown test step"))); |
|
283 } |
|
284 } |
|
285 |