|
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 // @file testcaseroot.cpp |
|
15 // @internalComponent |
|
16 // |
|
17 // |
|
18 |
|
19 #include <e32std.h> |
|
20 #include <e32std_private.h> |
|
21 #include <u32std.h> // unicode builds |
|
22 #include <e32base.h> |
|
23 #include <e32base_private.h> |
|
24 #include <e32cons.h> |
|
25 #include <e32Test.h> // RTest header |
|
26 //#include <e32ver.h> |
|
27 #include <e32def.h> |
|
28 #include <e32def_private.h> |
|
29 #include <d32otgdi.h> // OTGDI header |
|
30 #include <d32usbc.h> // USBCC header |
|
31 #include "testcaseroot.h" |
|
32 |
|
33 /* Implemention of classes CTestCaseRoot, CTestCaseB2BRoot |
|
34 * |
|
35 */ |
|
36 |
|
37 /* =============================================================== |
|
38 * The root test-case class, provides test-framework features |
|
39 */ |
|
40 CTestCaseRoot::CTestCaseRoot(const TDesC& aTestCaseId, TBool aAutomation) |
|
41 : CActive(EPriorityUserInput), |
|
42 COtgRoot(), |
|
43 iAutomated(aAutomation) |
|
44 { |
|
45 iTestCaseId.Copy(aTestCaseId); |
|
46 } |
|
47 |
|
48 |
|
49 void CTestCaseRoot::BaseConstructL() |
|
50 { |
|
51 LOG_FUNC |
|
52 |
|
53 |
|
54 TInt err(iTimer.CreateLocal()); |
|
55 if (err == KErrNone) |
|
56 { |
|
57 LOG_VERBOSE1(_L("Test case timer created")); |
|
58 } |
|
59 else |
|
60 { |
|
61 RDebug::Printf("<Error %d> Test case timer could not be created",err); |
|
62 User::Leave(err); |
|
63 } |
|
64 // |
|
65 iConsole = test.Console(); |
|
66 iRequestedChar = EFalse; |
|
67 } |
|
68 |
|
69 |
|
70 CTestCaseRoot::~CTestCaseRoot() |
|
71 { |
|
72 LOG_FUNC |
|
73 Cancel(); |
|
74 } |
|
75 |
|
76 // utility GUI methods |
|
77 void CTestCaseRoot::DisplayTestCaseOptions() |
|
78 { |
|
79 LOG_FUNC |
|
80 |
|
81 // commonly overridden to display any options for that test |
|
82 test.Printf(_L("Press <ESC> to end the test.\n")); |
|
83 } |
|
84 |
|
85 |
|
86 /***********************************************************************/ |
|
87 // |
|
88 void CTestCaseRoot::SetTestPolicy(CBasicTestPolicy* aTestPolicy) |
|
89 { |
|
90 iTestPolicy = aTestPolicy; |
|
91 iAutomated = gSemiAutomated; // read the global flag at this time |
|
92 } |
|
93 |
|
94 |
|
95 CBasicTestPolicy& CTestCaseRoot::TestPolicy() |
|
96 { |
|
97 return *iTestPolicy; |
|
98 } |
|
99 |
|
100 |
|
101 void CTestCaseRoot::DoCancel() |
|
102 { |
|
103 LOG_FUNC |
|
104 } |
|
105 |
|
106 |
|
107 /** ProcessKey |
|
108 override this method to perform other tasks, the base-class does nothing so that |
|
109 child classes can use it as an any-key-to-continue helper |
|
110 */ |
|
111 void CTestCaseRoot::ProcessKey(TKeyCode &aKey) |
|
112 {// default implementation - reads the key. |
|
113 iKeyCodeInput = aKey; |
|
114 } |
|
115 |
|
116 |
|
117 void CTestCaseRoot::ProcessEngineKey(TKeyCode &aKey) |
|
118 { |
|
119 LOG_FUNC |
|
120 |
|
121 if (EKeyEscape == aKey) |
|
122 { |
|
123 AssertionFailed( 1, _L("Test aborted by the user <ESC>\n")); |
|
124 CActiveScheduler::Stop(); |
|
125 } |
|
126 else |
|
127 { |
|
128 |
|
129 // call virtual method here to invoke the test's overridden method |
|
130 ProcessKey(aKey); |
|
131 // note, we do not go ask for another, that is done by the console handler |
|
132 } |
|
133 } |
|
134 |
|
135 |
|
136 void CTestCaseRoot::RequestCharacter() |
|
137 { |
|
138 LOG_FUNC |
|
139 // A request is issued to the CConsoleBase to accept a |
|
140 // character from the keyboard. |
|
141 |
|
142 __ASSERT_ALWAYS(!IsActive(), User::Panic(KMsgAlreadyActive, EPanicAlreadyActive)); |
|
143 |
|
144 iConsole->Read(iStatus); |
|
145 SetActive(); |
|
146 iRequestedChar = ETrue; |
|
147 } |
|
148 |
|
149 |
|
150 void CTestCaseRoot::RunL() |
|
151 { |
|
152 LOG_FUNC |
|
153 TInt complCode(iStatus.Int()); |
|
154 if (iRequestedChar) |
|
155 { |
|
156 |
|
157 TKeyCode k(iConsole->KeyCode()); |
|
158 |
|
159 // WARNING! |
|
160 // EMULATOR QUIRK! |
|
161 // When debugging if you have a breakpoint just before you read/process a key, |
|
162 // the EMULATOR will read the key sent to the IDE and you get a (F5) key that |
|
163 // you did not want from the IDE not the emulator. |
|
164 |
|
165 ProcessEngineKey(k); |
|
166 iRequestedChar = EFalse; |
|
167 |
|
168 // complete so that other tasks (there are none) can run |
|
169 // we will then be scheduled by the ActiveScheduler again to run the next test step. |
|
170 SelfComplete(); |
|
171 } |
|
172 else |
|
173 { |
|
174 // run the next test step |
|
175 TInt currentStep(GetStepIndex()); |
|
176 PreRunStep(); |
|
177 LOG_VERBOSE2(_L("\n<< RunStepL() step=%d\n"), currentStep); |
|
178 RunStepL(); |
|
179 LOG_VERBOSE3(_L(">> RunStepL() step=%d->%d\n"), currentStep, GetStepIndex()); |
|
180 PostRunStep(); |
|
181 } |
|
182 } |
|
183 |
|
184 |
|
185 void CTestCaseRoot::PostRunStep() |
|
186 { |
|
187 // default impl. |
|
188 } |
|
189 |
|
190 void CTestCaseRoot::PreRunStep() |
|
191 { |
|
192 // default impl. |
|
193 } |
|
194 |
|
195 TInt CTestCaseRoot::RunError(TInt aError) |
|
196 { |
|
197 LOG_FUNC |
|
198 test.Printf(_L("Test case C%lS::RunL left with %d"), &iTestCaseId, aError); |
|
199 AssertionFailed(aError, _L("RunError")); |
|
200 return KErrNone; |
|
201 } |
|
202 |
|
203 |
|
204 TDesC& CTestCaseRoot::TestCaseId() |
|
205 { |
|
206 return iTestCaseId; |
|
207 } |
|
208 |
|
209 |
|
210 TInt CTestCaseRoot::TestResult() const |
|
211 { |
|
212 return iTestResult; |
|
213 } |
|
214 |
|
215 |
|
216 void CTestCaseRoot::PerformTestL() |
|
217 { |
|
218 // tell user what they should have done before starting! |
|
219 DescribePreconditions(); |
|
220 // run it |
|
221 ExecuteTestCaseL(); |
|
222 } |
|
223 |
|
224 |
|
225 void CTestCaseRoot::TestFailed(TInt aFailResult, const TDesC &aErrorDescription) |
|
226 { |
|
227 LOG_FUNC |
|
228 iTestResult = aFailResult; |
|
229 test.Printf(_L("Test %S\n"), &TestCaseId()); |
|
230 test.Printf(_L("Failed (%d)\n"), aFailResult); |
|
231 test.Printf(_L("%S!\n"), &aErrorDescription); |
|
232 if (!iAutomated) |
|
233 { |
|
234 test.Printf(_L("\n")); |
|
235 test.Printf(KPressAnyKeyToContinue); |
|
236 iConsole->Getch(); |
|
237 } |
|
238 // the next call panics the framework! |
|
239 TestPolicy().SignalTestComplete(iTestResult); |
|
240 } |
|
241 |
|
242 |
|
243 void CTestCaseRoot::TestFailed2(TInt aFailResult, const TDesC &aErrorDescription, TInt errorCode) |
|
244 { |
|
245 LOG_FUNC |
|
246 iTestResult = aFailResult; |
|
247 test.Printf(_L("Test %S FAILED %d '%S %d'!\n"), |
|
248 &TestCaseId(), |
|
249 aFailResult, |
|
250 &aErrorDescription, |
|
251 errorCode); |
|
252 // the next call panics the framework! |
|
253 TestPolicy().SignalTestComplete(iTestResult); |
|
254 } |
|
255 |
|
256 |
|
257 |
|
258 void CTestCaseRoot::TestPassed() |
|
259 { |
|
260 LOG_FUNC |
|
261 iTestResult = KErrNone; |
|
262 TestPolicy().SignalTestComplete(iTestResult); |
|
263 } |
|
264 |
|
265 |
|
266 |
|
267 |
|
268 /** Complete the servicing of the Active object and signal it ready to run again |
|
269 in next scheduler slot. This method works as drop-through when a test step has |
|
270 nothing more to do . |
|
271 */ |
|
272 void CTestCaseRoot::SelfComplete(TInt aCode) |
|
273 { |
|
274 TRequestStatus* s = &iStatus; |
|
275 iStatus = KRequestPending; |
|
276 User::RequestComplete(s, aCode); |
|
277 SetActive(); |
|
278 } |
|
279 |
|
280 /* Prints a little banner at the top of a test-step : |
|
281 * B2B tests also display the duration of the last step, and the current OTG state |
|
282 */ |
|
283 void CTestCaseRoot::PrintStepName(const TDesC &aStepName) |
|
284 { |
|
285 if (gVerboseOutput) |
|
286 { |
|
287 test.Printf(_L("--------------\n %S "), &aStepName); |
|
288 // B2B class method dumps the engine state |
|
289 // |
|
290 test.Printf(_L("\n--------------\n")); |
|
291 } |
|
292 } |
|
293 |
|
294 |
|
295 /* ************************************************************************************** |
|
296 * |
|
297 */ |
|
298 CTestCaseB2BRoot::CTestCaseB2BRoot(const TDesC& aTestCaseId, TBool aHost, TRequestStatus &aStatus) |
|
299 : CTestCaseRoot(aTestCaseId, aHost) , iCollector(aStatus) |
|
300 { |
|
301 LOG_FUNC |
|
302 |
|
303 } |
|
304 |
|
305 |
|
306 CTestCaseB2BRoot::~CTestCaseB2BRoot() |
|
307 { |
|
308 LOG_FUNC |
|
309 |
|
310 } |
|
311 |
|
312 /* Print step name : B2B override displays the OTG Engine state as well |
|
313 */ |
|
314 void CTestCaseB2BRoot::PrintStepName(const TDesC &aStepName) |
|
315 { |
|
316 if (gVerboseOutput) |
|
317 { |
|
318 test.Printf(_L("--------------\n %S "), &aStepName); |
|
319 // engine state |
|
320 CNotifyWatcherBase *pWatcher = iCollector.GetWatcher(EWatcherState); |
|
321 if (pWatcher) |
|
322 { |
|
323 TBuf<MAX_DSTRLEN> aDescription; |
|
324 RUsbOtgDriver::TOtgState aState = static_cast<RUsbOtgDriver::TOtgState>(pWatcher->GetEventValue()); |
|
325 |
|
326 OtgStateString(aState, aDescription); |
|
327 LOG_VERBOSE3(_L("OTGState %d '%S' \n"), aState, &aDescription); |
|
328 } |
|
329 test.Printf(_L(" : time = %dms\n--------------\n"), iCollector.DurationElapsed()); |
|
330 } |
|
331 } |
|
332 |
|
333 /* Default implementation which describes this as a B2B test-case |
|
334 */ |
|
335 void CTestCaseB2BRoot::DescribePreconditions() |
|
336 { |
|
337 test.Printf(KTestTypeB2BMsg); // B2B |
|
338 if (gTestRoleMaster) |
|
339 test.Printf(KRoleMasterMsg); |
|
340 else |
|
341 test.Printf(KRoleSlaveMsg); |
|
342 } |
|
343 |
|
344 |
|
345 void CTestCaseB2BRoot::StepB2BPreconditions() |
|
346 { |
|
347 // prompt to insert connector |
|
348 if (gTestRoleMaster) |
|
349 { // "B" device |
|
350 test.Printf(KInsertBCablePrompt); |
|
351 } |
|
352 else |
|
353 { |
|
354 test.Printf(KInsertACablePrompt); |
|
355 } |
|
356 if (iAutomated) |
|
357 { |
|
358 |
|
359 SelfComplete(); |
|
360 return; |
|
361 } |
|
362 test.Printf(KPressAnyKeyToContinue); |
|
363 RequestCharacter(); |
|
364 } |
|
365 |
|
366 |
|
367 /* Test for A or B plug as relevant for MASTER/SLAVE role, fail the test if wrong |
|
368 */ |
|
369 void CTestCaseB2BRoot::CheckRoleConnections() |
|
370 { |
|
371 if (gTestRoleMaster) |
|
372 { |
|
373 if (otgIdPinPresent()) |
|
374 { // oops |
|
375 test.Printf(KMsgErrorPreconditionFailed); |
|
376 return TestFailed(KErrAbort, KMsgBPlugNotFound); |
|
377 } |
|
378 } |
|
379 else |
|
380 { |
|
381 if (!otgIdPinPresent()) |
|
382 { // oops |
|
383 test.Printf(KMsgErrorPreconditionFailed); |
|
384 return TestFailed(KErrAbort, KMsgAPlugNotFound); |
|
385 } |
|
386 } |
|
387 } |
|
388 |
|
389 |
|
390 /* Clears the expected event Q just before calling the step, but not the |
|
391 * recieved Q since the step may still inspect it using the EventReceivedAlready() method. |
|
392 */ |
|
393 void CTestCaseB2BRoot::PreRunStep() |
|
394 { |
|
395 LOG_FUNC |
|
396 |
|
397 iCollector.ClearAllEvents(EFalse, ETrue); |
|
398 } |
|
399 |
|
400 |
|
401 void CTestCaseB2BRoot::PostRunStep() |
|
402 { |
|
403 LOG_FUNC |
|
404 // clear the recieved event Q, but not the expected Q |
|
405 iCollector.ClearAllEvents(ETrue, EFalse); |
|
406 |
|
407 } |
|
408 |
|
409 |
|
410 |