|
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 "testcase0462.h" |
|
27 |
|
28 |
|
29 |
|
30 // the name below is used to add a pointer to our construction method to a pointer MAP in |
|
31 // the class factory |
|
32 _LIT(KTestCaseId,"PBASE-USB_OTGDI-0462"); |
|
33 const TTestCaseFactoryReceipt<CTestCase0462> CTestCase0462::iFactoryReceipt(KTestCaseId); |
|
34 |
|
35 CTestCase0462* CTestCase0462::NewL(TBool aHost) |
|
36 { |
|
37 LOG_FUNC |
|
38 CTestCase0462* self = new (ELeave) CTestCase0462(aHost); |
|
39 CleanupStack::PushL(self); |
|
40 self->ConstructL(); |
|
41 CleanupStack::Pop(self); |
|
42 return self; |
|
43 } |
|
44 |
|
45 |
|
46 CTestCase0462::CTestCase0462(TBool aHost) |
|
47 : CTestCaseRoot(KTestCaseId, aHost) |
|
48 { |
|
49 LOG_FUNC |
|
50 |
|
51 } |
|
52 |
|
53 |
|
54 /** |
|
55 ConstructL |
|
56 */ |
|
57 void CTestCase0462::ConstructL() |
|
58 { |
|
59 LOG_FUNC |
|
60 iRepeats = KOperationRetriesMax; |
|
61 iWDTimer = CTestCaseWatchdog::NewL(); |
|
62 |
|
63 BaseConstructL(); |
|
64 } |
|
65 |
|
66 |
|
67 CTestCase0462::~CTestCase0462() |
|
68 { |
|
69 LOG_FUNC |
|
70 |
|
71 Cancel(); |
|
72 delete iWDTimer; |
|
73 } |
|
74 |
|
75 |
|
76 void CTestCase0462::ExecuteTestCaseL() |
|
77 { |
|
78 LOG_FUNC |
|
79 iCaseStep = ELoadLdd; |
|
80 |
|
81 CActiveScheduler::Add(this); |
|
82 SelfComplete(); |
|
83 |
|
84 } |
|
85 |
|
86 |
|
87 void CTestCase0462::DescribePreconditions() |
|
88 { |
|
89 test.Printf(_L("Insert 'A' connector beforehand.\n")); |
|
90 } |
|
91 |
|
92 |
|
93 void CTestCase0462::DoCancel() |
|
94 { |
|
95 LOG_FUNC |
|
96 |
|
97 // cancel our timer |
|
98 iTimer.Cancel(); |
|
99 } |
|
100 |
|
101 void CTestCase0462::CancelKB(CTestCaseRoot *pThis) |
|
102 { |
|
103 CTestCase0462 * p = REINTERPRET_CAST(CTestCase0462 *,pThis); |
|
104 // cancel any pending call, and then complete our active obj with a timeout value |
|
105 |
|
106 p->iConsole->ReadCancel(); |
|
107 |
|
108 } |
|
109 |
|
110 |
|
111 // handle event completion |
|
112 void CTestCase0462::RunStepL() |
|
113 { |
|
114 LOG_FUNC |
|
115 // Obtain the completion code for this CActive obj. |
|
116 TInt completionCode(iStatus.Int()); |
|
117 // NOTE: Look at its iStatus.iFlags. |
|
118 // If it's 1, it's b -> you called SetActive() but the service provider didn't set it to KRequestPending or it got overwritten. |
|
119 // If it's 2, it's a -> you didn't called SetActive() when issuing a request. |
|
120 |
|
121 TBuf<MAX_DSTRLEN> aDescription; |
|
122 |
|
123 switch(iCaseStep) |
|
124 { |
|
125 case EPreconditions: |
|
126 iCaseStep = ELoadLdd; |
|
127 if (iAutomated) |
|
128 { |
|
129 iCaseStep = ELoadLdd; |
|
130 SelfComplete(); |
|
131 break; |
|
132 } |
|
133 // prompt to insert connector |
|
134 test.Printf(KInsertAConnectorPrompt); |
|
135 test.Printf(KPressAnyKeyToContinue); |
|
136 RequestCharacter(); |
|
137 break; |
|
138 |
|
139 case ELoadLdd: |
|
140 if (!StepLoadLDD()) |
|
141 { |
|
142 break; |
|
143 } |
|
144 |
|
145 iCaseStep = ERegisterForEvents; |
|
146 iDequeAttempts = 0; |
|
147 SelfComplete(); |
|
148 break; |
|
149 |
|
150 // 2. wait on ID_PIN |
|
151 case ERegisterForEvents: |
|
152 // prompt to remove connector |
|
153 test.Printf(KRemoveAConnectorPrompt); |
|
154 if (iDequeAttempts > 3) |
|
155 { |
|
156 return (TestFailed(KErrCorrupt, _L("<Error> too many irrelevant/incorrect events"))); |
|
157 } |
|
158 |
|
159 otgQueueOtgEventRequest( iOTGEvent, iStatus); |
|
160 iCaseStep = EEmptyQueue; |
|
161 iIDcheckStart.HomeTime(); |
|
162 SetActive(); |
|
163 break; |
|
164 |
|
165 // 3. pick up events already buffered when we started test |
|
166 case EEmptyQueue: |
|
167 { |
|
168 |
|
169 TInt aMillisec; |
|
170 iIDcheckEnd.HomeTime(); |
|
171 TTimeIntervalMicroSeconds ivlMicro(iIDcheckEnd.MicroSecondsFrom(iIDcheckStart)); |
|
172 aMillisec = (TInt)(ivlMicro.Int64())/1000; // USB times are in uSec, but in ms for the user layer |
|
173 iCaseStep = EGetAndCancelEvent; |
|
174 // test if too quick! |
|
175 if(aMillisec < KDelayDurationForQEmpty) // use 200ms - clocked at 17ms |
|
176 { |
|
177 iCaseStep = ERegisterForEvents; |
|
178 iDequeAttempts++; |
|
179 SelfComplete(); |
|
180 break; |
|
181 } |
|
182 }// drop through to next step |
|
183 |
|
184 // 4. |
|
185 case EGetAndCancelEvent: |
|
186 OtgEventString(iOTGEvent, aDescription); |
|
187 test.Printf(_L("Received event %d '%S' status(%d)"), iOTGEvent, &aDescription, completionCode); |
|
188 if (RUsbOtgDriver::EEventAPlugRemoved == iOTGEvent) |
|
189 { |
|
190 otgQueueOtgEventRequest( iOTGEvent, iStatus); |
|
191 // cancel it and then generate 6 more events |
|
192 otgCancelOtgEventRequest(); |
|
193 // swallow the cancellation now too |
|
194 User::WaitForRequest(iStatus); |
|
195 |
|
196 iCaseStep = ECancelNotify; |
|
197 } |
|
198 else |
|
199 { |
|
200 // wrong event in the Q already, keep at it |
|
201 iCaseStep = ERegisterForEvents; |
|
202 iDequeAttempts++; |
|
203 } |
|
204 SelfComplete(); |
|
205 break; |
|
206 |
|
207 // 5. prepare to insert 'A' |
|
208 case ECancelNotify: |
|
209 iRepeats = KOperationRetriesMax; |
|
210 iCaseStep = EInsertA; |
|
211 SelfComplete(); |
|
212 break; |
|
213 |
|
214 case EInsertA: // 6. remove 'A' |
|
215 iConsole->ReadCancel(); |
|
216 test.Printf(KInsertAConnectorPrompt); |
|
217 |
|
218 iCaseStep = ERemoveA; |
|
219 test.Printf(KPressAnyKeyToContinue); |
|
220 RequestCharacter(); |
|
221 break; |
|
222 |
|
223 // 7. |
|
224 case ERemoveA: |
|
225 iConsole->ReadCancel(); |
|
226 test.Printf(KRemoveAConnectorPrompt); |
|
227 if (iRepeats-- >0) |
|
228 iCaseStep = EInsertA; |
|
229 else |
|
230 iCaseStep = ETallyEvents; |
|
231 test.Printf(KPressAnyKeyToContinue); |
|
232 RequestCharacter(); |
|
233 break; |
|
234 |
|
235 // 8. |
|
236 case ETallyEvents: |
|
237 iConsole->ReadCancel(); |
|
238 // tests if the object became signalled or not! |
|
239 // we expect if it did in fact do so, our Active object would panic (stray signal) |
|
240 SelfComplete(); |
|
241 iCaseStep = EUnloadLdd; |
|
242 break; |
|
243 |
|
244 // 9. |
|
245 case EUnloadLdd: |
|
246 case ELastStep: |
|
247 if (EFalse == StepUnloadLDD()) |
|
248 return TestFailed(KErrAbort,_L("unload Ldd failure")); |
|
249 |
|
250 return TestPassed(); |
|
251 |
|
252 default: |
|
253 test.Printf(_L("<Error> unknown test step")); |
|
254 Cancel(); |
|
255 return (TestFailed(KErrCorrupt, _L("<Error> unknown test step"))); |
|
256 |
|
257 } |
|
258 } |
|
259 |
|
260 |
|
261 |