|
1 // Copyright (c) 2001-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 "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 // This contains ESock Test cases from section 15 |
|
15 // |
|
16 // |
|
17 |
|
18 #include "StateMachineStep.h" |
|
19 #include <testexecutelog.h> |
|
20 |
|
21 void CElementStateMachineTestBase::Setup() |
|
22 { |
|
23 iActiveScheduler = CStateMachineImpl::StartActiveSchedulerL(); |
|
24 CleanupStack::PushL(iActiveScheduler); |
|
25 iStateMachine = CStateMachineImpl::NewL(); |
|
26 } |
|
27 |
|
28 void CElementStateMachineTestBase::Destroy() |
|
29 { |
|
30 CleanupStack::PopAndDestroy(iStateMachine); |
|
31 CActiveScheduler::Install(NULL); |
|
32 CleanupStack::PopAndDestroy(iActiveScheduler); |
|
33 } |
|
34 |
|
35 CElementStateMachineStep1_1::CElementStateMachineStep1_1() |
|
36 /** |
|
37 * Constructor |
|
38 */ |
|
39 { |
|
40 // Call base class method to set up the human readable name for logging |
|
41 SetTestStepName(KElementStateMachineStep1_1); |
|
42 } |
|
43 |
|
44 TVerdict CElementStateMachineStep1_1::doTestStepPreambleL() |
|
45 /** |
|
46 * @return - TVerdict code |
|
47 * Override of base class virtual |
|
48 */ |
|
49 { |
|
50 SetTestStepResult(EFail); |
|
51 iResult = EFail; |
|
52 Setup(); |
|
53 GetIntFromConfig(KElementStateMachineStep1_1, KElementStateMachineHistory, iHistory); |
|
54 iResult = EPass; |
|
55 return TestStepResult(); |
|
56 } |
|
57 |
|
58 TVerdict CElementStateMachineStep1_1::doTestStepL() |
|
59 /** |
|
60 * @return - TVerdict code |
|
61 * Tests that the history member of a state machine can be set and retreived correctly |
|
62 */ |
|
63 { |
|
64 INFO_PRINTF2(_L("Check history can be set and retrieved as %d."), iHistory); |
|
65 iStateMachine->UpdateHistory(iHistory); |
|
66 TInt returnHistory = iStateMachine->History(); |
|
67 INFO_PRINTF3(_L("Expected history: %d, returned history: %d"), iHistory, returnHistory); |
|
68 if (returnHistory != iHistory) |
|
69 iResult = EFail; |
|
70 return TestStepResult(); |
|
71 } |
|
72 |
|
73 TVerdict CElementStateMachineStep1_1::doTestStepPostambleL() |
|
74 /** |
|
75 * @return - TVerdict code |
|
76 * Override of base class virtual |
|
77 */ |
|
78 { |
|
79 Destroy(); |
|
80 SetTestStepResult(iResult); |
|
81 return TestStepResult(); |
|
82 } |
|
83 |
|
84 CElementStateMachineStep1_2::CElementStateMachineStep1_2() |
|
85 /** |
|
86 * Constructor |
|
87 */ |
|
88 { |
|
89 // Call base class method to set up the human readable name for logging |
|
90 SetTestStepName(KElementStateMachineStep1_2); |
|
91 } |
|
92 |
|
93 TVerdict CElementStateMachineStep1_2::doTestStepPreambleL() |
|
94 /** |
|
95 * @return - TVerdict code |
|
96 * Override of base class virtual |
|
97 */ |
|
98 { |
|
99 SetTestStepResult(EFail); |
|
100 iResult = EFail; |
|
101 Setup(); |
|
102 GetIntFromConfig(KElementStateMachineStep1_2, KElementStateMachineLastError, iLastError); |
|
103 iResult = EPass; |
|
104 return TestStepResult(); |
|
105 } |
|
106 |
|
107 TVerdict CElementStateMachineStep1_2::doTestStepL() |
|
108 /** |
|
109 * @return - TVerdict code |
|
110 * Tests that the last error member of a state machine can be set and retreived correctly |
|
111 */ |
|
112 { |
|
113 INFO_PRINTF2(_L("Check last error can be set and retrieved as %d."), iLastError); |
|
114 iStateMachine->SetLastError(iLastError); |
|
115 TInt returnLastError = iStateMachine->LastError(); |
|
116 INFO_PRINTF3(_L("Expected last error: %d, returned : %d"), iLastError, returnLastError); |
|
117 if (returnLastError != iLastError) |
|
118 iResult = EFail; |
|
119 return TestStepResult(); |
|
120 } |
|
121 |
|
122 TVerdict CElementStateMachineStep1_2::doTestStepPostambleL() |
|
123 /** |
|
124 * @return - TVerdict code |
|
125 * Override of base class virtual |
|
126 */ |
|
127 { |
|
128 Destroy(); |
|
129 SetTestStepResult(iResult); |
|
130 return TestStepResult(); |
|
131 } |
|
132 |
|
133 CElementStateMachineStep1_3::CElementStateMachineStep1_3() |
|
134 /** |
|
135 * Constructor |
|
136 */ |
|
137 { |
|
138 // Call base class method to set up the human readable name for logging |
|
139 SetTestStepName(KElementStateMachineStep1_3); |
|
140 } |
|
141 |
|
142 TVerdict CElementStateMachineStep1_3::doTestStepPreambleL() |
|
143 /** |
|
144 * @return - TVerdict code |
|
145 * Override of base class virtual |
|
146 */ |
|
147 { |
|
148 SetTestStepResult(EFail); |
|
149 iResult = EFail; |
|
150 Setup(); |
|
151 iResult = EPass; |
|
152 return TestStepResult(); |
|
153 } |
|
154 |
|
155 TVerdict CElementStateMachineStep1_3::doTestStepL() |
|
156 /** |
|
157 * @return - TVerdict code |
|
158 * Tests that the suspend reques member of a state machine can be set and retreived correctly |
|
159 */ |
|
160 { |
|
161 INFO_PRINTF1(_L("Check suspend request can be set and retrieved.")); |
|
162 iStateMachine->SetSuspendRequest(EFalse); |
|
163 TBool returnBool = iStateMachine->SuspendRequest(); |
|
164 if (returnBool) |
|
165 iResult = EFail; |
|
166 iStateMachine->SetSuspendRequest(ETrue); |
|
167 returnBool = iStateMachine->SuspendRequest(); |
|
168 if (!returnBool) |
|
169 iResult = EFail; |
|
170 return TestStepResult(); |
|
171 } |
|
172 |
|
173 TVerdict CElementStateMachineStep1_3::doTestStepPostambleL() |
|
174 /** |
|
175 * @return - TVerdict code |
|
176 * Override of base class virtual |
|
177 */ |
|
178 { |
|
179 Destroy(); |
|
180 SetTestStepResult(iResult); |
|
181 return TestStepResult(); |
|
182 } |
|
183 |
|
184 CElementStateMachineStep1_4::CElementStateMachineStep1_4() |
|
185 /** |
|
186 * Constructor |
|
187 */ |
|
188 { |
|
189 // Call base class method to set up the human readable name for logging |
|
190 SetTestStepName(KElementStateMachineStep1_4); |
|
191 } |
|
192 |
|
193 TVerdict CElementStateMachineStep1_4::doTestStepPreambleL() |
|
194 /** |
|
195 * @return - TVerdict code |
|
196 * Override of base class virtual |
|
197 */ |
|
198 { |
|
199 SetTestStepResult(EFail); |
|
200 iResult = EFail; |
|
201 Setup(); |
|
202 GetIntFromConfig(KElementStateMachineStep1_4, KElementStateMachNullRAllcLngth, iNullReAllocLength); |
|
203 GetIntFromConfig(KElementStateMachineStep1_4, KElementStateMachSetRAllocLngth, iSetReAllocLength); |
|
204 iResult = EPass; |
|
205 return TestStepResult(); |
|
206 } |
|
207 |
|
208 TVerdict CElementStateMachineStep1_4::doTestStepL() |
|
209 /** |
|
210 * @return - TVerdict code |
|
211 * Tests that the fragment member of a state machine can be allocated and returned |
|
212 */ |
|
213 { |
|
214 INFO_PRINTF1(_L("Check fragmentation reallocation when fragment is null.")); |
|
215 iStateMachine->SetFragment(NULL); |
|
216 HBufC8* fragment = iStateMachine->ReAllocL(iNullReAllocLength); |
|
217 TInt fragmentLength = fragment->Des().MaxSize(); |
|
218 INFO_PRINTF3(_L("Expected length at least: %d, returned length: %d"), iNullReAllocLength, fragmentLength); |
|
219 //Length returned is slightly bigger initially |
|
220 if (fragmentLength < iNullReAllocLength) |
|
221 iResult = EFail; |
|
222 INFO_PRINTF1(_L("Check fragmentation reallocation when fragment is already set.")); |
|
223 fragment = iStateMachine->ReAllocL(iSetReAllocLength); |
|
224 fragmentLength = fragment->Des().MaxSize(); |
|
225 INFO_PRINTF3(_L("Expected length at least: %d, returned length: %d"), iSetReAllocLength, fragmentLength); |
|
226 if (fragmentLength < iSetReAllocLength) |
|
227 iResult = EFail; |
|
228 INFO_PRINTF1(_L("Check fragmentation reallocation isn't done when new length is greater than Des().MaxLength()")); |
|
229 fragment = iStateMachine->ReAllocL((fragment->Des().MaxLength() - iSetReAllocLength) + 1); |
|
230 fragmentLength = fragment->Des().MaxSize(); |
|
231 INFO_PRINTF3(_L("Expected length at least: %d, returned length: %d"), iSetReAllocLength, fragmentLength); |
|
232 if (fragmentLength < iSetReAllocLength) |
|
233 iResult = EFail; |
|
234 INFO_PRINTF1(_L("Check fragment return equals expected object")); |
|
235 if (fragment != iStateMachine->Fragment()) |
|
236 iResult = EFail; |
|
237 return TestStepResult(); |
|
238 } |
|
239 |
|
240 TVerdict CElementStateMachineStep1_4::doTestStepPostambleL() |
|
241 /** |
|
242 * @return - TVerdict code |
|
243 * Override of base class virtual |
|
244 */ |
|
245 { |
|
246 Destroy(); |
|
247 SetTestStepResult(iResult); |
|
248 return TestStepResult(); |
|
249 } |
|
250 |
|
251 CElementStateMachineStep1_5::CElementStateMachineStep1_5() |
|
252 /** |
|
253 * Constructor |
|
254 */ |
|
255 { |
|
256 // Call base class method to set up the human readable name for logging |
|
257 SetTestStepName(KElementStateMachineStep1_5); |
|
258 } |
|
259 |
|
260 TVerdict CElementStateMachineStep1_5::doTestStepPreambleL() |
|
261 /** |
|
262 * @return - TVerdict code |
|
263 * Override of base class virtual |
|
264 */ |
|
265 { |
|
266 SetTestStepResult(EFail); |
|
267 iResult = EFail; |
|
268 Setup(); |
|
269 iResult = EPass; |
|
270 return TestStepResult(); |
|
271 } |
|
272 |
|
273 TVerdict CElementStateMachineStep1_5::doTestStepL() |
|
274 /** |
|
275 * @return - TVerdict code |
|
276 * Tests state machine notifier member can be registered and deregistered |
|
277 */ |
|
278 { |
|
279 CStateMachineNotifyImpl stateMachineNotify = CStateMachineNotifyImpl(); |
|
280 INFO_PRINTF1(_L("Check that initial state machine notifier is NULL")); |
|
281 MStateMachineNotify* stateMachineNotifyReturn = iStateMachine->StateMachineNotifier(); |
|
282 if (stateMachineNotifyReturn != NULL) |
|
283 iResult = EFail; |
|
284 INFO_PRINTF1(_L("Check that the notifier can be set")); |
|
285 iStateMachine->RegisterNotify(&stateMachineNotify); |
|
286 stateMachineNotifyReturn = iStateMachine->StateMachineNotifier(); |
|
287 if (stateMachineNotifyReturn != &stateMachineNotify) |
|
288 iResult = EFail; |
|
289 INFO_PRINTF1(_L("Check that the notifier can be cleared")); |
|
290 iStateMachine->DeRegisterNotify(&stateMachineNotify); |
|
291 stateMachineNotifyReturn = iStateMachine->StateMachineNotifier(); |
|
292 if (stateMachineNotifyReturn != NULL) |
|
293 iResult = EFail; |
|
294 return TestStepResult(); |
|
295 } |
|
296 |
|
297 TVerdict CElementStateMachineStep1_5::doTestStepPostambleL() |
|
298 /** |
|
299 * @return - TVerdict code |
|
300 * Override of base class virtual |
|
301 */ |
|
302 { |
|
303 Destroy(); |
|
304 SetTestStepResult(iResult); |
|
305 return TestStepResult(); |
|
306 } |
|
307 |
|
308 CElementStateMachineStep2_1::CElementStateMachineStep2_1() |
|
309 /** |
|
310 * Constructor |
|
311 */ |
|
312 { |
|
313 // Call base class method to set up the human readable name for logging |
|
314 SetTestStepName(KElementStateMachineStep2_1); |
|
315 } |
|
316 |
|
317 TVerdict CElementStateMachineStep2_1::doTestStepPreambleL() |
|
318 /** |
|
319 * @return - TVerdict code |
|
320 * Override of base class virtual |
|
321 */ |
|
322 { |
|
323 SetTestStepResult(EFail); |
|
324 iResult = EFail; |
|
325 Setup(); |
|
326 iExpectedAsyncEvent = EGreenAsyncEvent; |
|
327 iResult = EPass; |
|
328 return TestStepResult(); |
|
329 } |
|
330 |
|
331 TVerdict CElementStateMachineStep2_1::doTestStepL() |
|
332 /** |
|
333 * @return - TVerdict code |
|
334 * Tests that the state machine can be started correctly and moves through a set of states |
|
335 */ |
|
336 { |
|
337 INFO_PRINTF1(_L("Check that state machine correctly moves through states GREEN, YELLOW, RED before stopping")); |
|
338 INFO_PRINTF1(_L("Create asynchronous events (states)")); |
|
339 CAsyncEventImpl greenAsync = CAsyncEventImpl(EGreenAsyncEvent, this, *iStateMachine, KErrNone); |
|
340 CAsyncEventImpl yellowAsync = CAsyncEventImpl(EYellowAsyncEvent, this, *iStateMachine, KErrNone); |
|
341 CAsyncEventImpl redAsync = CAsyncEventImpl(ERedAsyncEvent, this, *iStateMachine, KErrNone); |
|
342 greenAsync.SetNext(&yellowAsync); |
|
343 yellowAsync.SetNext(&redAsync); |
|
344 redAsync.SetNext(NULL); |
|
345 TRequestStatus startStatus; |
|
346 INFO_PRINTF1(_L("Set state machine first active event to GREEN")); |
|
347 iStateMachine->SetActiveEvent(&greenAsync); |
|
348 INFO_PRINTF1(_L("Start state machine")); |
|
349 iStateMachine->Start(&startStatus, NULL, NULL); |
|
350 iActiveScheduler->Start(); |
|
351 User::WaitForRequest(startStatus); |
|
352 return TestStepResult(); |
|
353 } |
|
354 |
|
355 void CElementStateMachineStep2_1::LogStateChange(TAsyncEventTest aAsyncEvent) |
|
356 { |
|
357 if (iExpectedAsyncEvent == EGreenAsyncEvent) |
|
358 { |
|
359 if (aAsyncEvent == EGreenAsyncEvent) |
|
360 INFO_PRINTF1(_L("Received expected GREEN state")); |
|
361 else |
|
362 { |
|
363 INFO_PRINTF1(_L("Did not receive expected GREEN state")); |
|
364 iResult = EFail; |
|
365 } |
|
366 iExpectedAsyncEvent = EYellowAsyncEvent; |
|
367 } |
|
368 else if (iExpectedAsyncEvent == EYellowAsyncEvent) |
|
369 { |
|
370 if (aAsyncEvent == EYellowAsyncEvent) |
|
371 INFO_PRINTF1(_L("Received expected YELLOW state")); |
|
372 else |
|
373 { |
|
374 INFO_PRINTF1(_L("Did not receive expected YELLOW state")); |
|
375 iResult = EFail; |
|
376 } |
|
377 iExpectedAsyncEvent = ERedAsyncEvent; |
|
378 } |
|
379 else if (iExpectedAsyncEvent == ERedAsyncEvent) |
|
380 { |
|
381 if (aAsyncEvent == ERedAsyncEvent) |
|
382 INFO_PRINTF1(_L("Received expected RED state")); |
|
383 else |
|
384 { |
|
385 INFO_PRINTF1(_L("Did not receive expected RED state")); |
|
386 iResult = EFail; |
|
387 } |
|
388 } |
|
389 } |
|
390 |
|
391 TVerdict CElementStateMachineStep2_1::doTestStepPostambleL() |
|
392 /** |
|
393 * @return - TVerdict code |
|
394 * Override of base class virtual |
|
395 */ |
|
396 { |
|
397 Destroy(); |
|
398 SetTestStepResult(iResult); |
|
399 return TestStepResult(); |
|
400 } |
|
401 |
|
402 CElementStateMachineStep2_2::CElementStateMachineStep2_2() |
|
403 /** |
|
404 * Constructor |
|
405 */ |
|
406 { |
|
407 // Call base class method to set up the human readable name for logging |
|
408 SetTestStepName(KElementStateMachineStep2_2); |
|
409 } |
|
410 |
|
411 TVerdict CElementStateMachineStep2_2::doTestStepPreambleL() |
|
412 /** |
|
413 * @return - TVerdict code |
|
414 * Override of base class virtual |
|
415 */ |
|
416 { |
|
417 SetTestStepResult(EFail); |
|
418 iResult = EFail; |
|
419 Setup(); |
|
420 iExpectedAsyncEvent = ERedAsyncEvent; |
|
421 iResult = EPass; |
|
422 return TestStepResult(); |
|
423 } |
|
424 |
|
425 TVerdict CElementStateMachineStep2_2::doTestStepL() |
|
426 /** |
|
427 * @return - TVerdict code |
|
428 * Tests that the state machine does nothing when started without a client status, |
|
429 * and runs when one is attached with KRequestPending |
|
430 */ |
|
431 { |
|
432 INFO_PRINTF1(_L("Create asynchronous RED event (state)")); |
|
433 CAsyncEventImpl redAsync = CAsyncEventImpl(ERedAsyncEvent, this, *iStateMachine, KErrNone); |
|
434 redAsync.SetNext(NULL); |
|
435 INFO_PRINTF1(_L("Set state machine first active event to RED")); |
|
436 iStateMachine->SetActiveEvent(&redAsync); |
|
437 INFO_PRINTF1(_L("Start state machine with NULL client status")); |
|
438 iStateMachine->Start(NULL, NULL, NULL); |
|
439 TRequestStatus* nullClientStatus = iStateMachine->ClientStatus(); |
|
440 INFO_PRINTF1(_L("Check returned client status from state machine is NULL")); |
|
441 if (nullClientStatus != NULL) |
|
442 { |
|
443 INFO_PRINTF1(_L("NULL TRequestStatus not recieved from state machine!")); |
|
444 iResult = EFail; |
|
445 } |
|
446 TRequestStatus clientStatus; |
|
447 clientStatus = KRequestPending; |
|
448 INFO_PRINTF1(_L("Set client status of state machine to KRequestPending")); |
|
449 iStateMachine->SetClientStatus(&clientStatus); |
|
450 INFO_PRINTF1(_L("Start state machine")); |
|
451 iActiveScheduler->Start(); |
|
452 User::WaitForRequest(clientStatus); |
|
453 return TestStepResult(); |
|
454 } |
|
455 |
|
456 void CElementStateMachineStep2_2::LogStateChange(TAsyncEventTest aAsyncEvent) |
|
457 { |
|
458 if (aAsyncEvent == ERedAsyncEvent) |
|
459 INFO_PRINTF1(_L("Received expected RED state")); |
|
460 else |
|
461 { |
|
462 INFO_PRINTF1(_L("Did not receive expected RED state")); |
|
463 iResult = EFail; |
|
464 } |
|
465 } |
|
466 |
|
467 TVerdict CElementStateMachineStep2_2::doTestStepPostambleL() |
|
468 /** |
|
469 * @return - TVerdict code |
|
470 * Override of base class virtual |
|
471 */ |
|
472 { |
|
473 Destroy(); |
|
474 SetTestStepResult(iResult); |
|
475 return TestStepResult(); |
|
476 } |
|
477 |
|
478 CElementStateMachineStep2_3::CElementStateMachineStep2_3() |
|
479 /** |
|
480 * Constructor |
|
481 */ |
|
482 { |
|
483 // Call base class method to set up the human readable name for logging |
|
484 SetTestStepName(KElementStateMachineStep2_3); |
|
485 } |
|
486 |
|
487 TVerdict CElementStateMachineStep2_3::doTestStepPreambleL() |
|
488 /** |
|
489 * @return - TVerdict code |
|
490 * Override of base class virtual |
|
491 */ |
|
492 { |
|
493 SetTestStepResult(EFail); |
|
494 iResult = EFail; |
|
495 Setup(); |
|
496 iExpectedAsyncEvent = EPanicAsyncEvent; |
|
497 iResult = EPass; |
|
498 return TestStepResult(); |
|
499 } |
|
500 |
|
501 TVerdict CElementStateMachineStep2_3::doTestStepL() |
|
502 /** |
|
503 * @return - TVerdict code |
|
504 * Tests that the state machine handles error upon an active event leaving in ProcessL |
|
505 */ |
|
506 { |
|
507 INFO_PRINTF1(_L("Create asynchronous panicing event (state)")); |
|
508 CAsyncEventImpl panicAsync = CAsyncEventImpl(EPanicAsyncEvent, this, *iStateMachine, KErrNone); |
|
509 panicAsync.SetNext(NULL); |
|
510 INFO_PRINTF1(_L("Set state machine first active event to PANIC")); |
|
511 iStateMachine->SetActiveEvent(&panicAsync); |
|
512 INFO_PRINTF1(_L("Start state machine")); |
|
513 TRequestStatus clientStatus; |
|
514 iStateMachine->Start(&clientStatus, NULL, NULL); |
|
515 iActiveScheduler->Start(); |
|
516 User::WaitForRequest(clientStatus); |
|
517 TInt errorCode = iStateMachine->LastError(); |
|
518 INFO_PRINTF1(_L("Check returned error is expected error (from iLastError member)")); |
|
519 INFO_PRINTF3(_L("Expected error: %d, received error: %d"), KElementStateMachineError, errorCode); |
|
520 if (errorCode != KElementStateMachineError) |
|
521 iResult = EFail; |
|
522 return TestStepResult(); |
|
523 } |
|
524 |
|
525 void CElementStateMachineStep2_3::LogStateChange(TAsyncEventTest aAsyncEvent) |
|
526 { |
|
527 if (iExpectedAsyncEvent == EPanicAsyncEvent) |
|
528 { |
|
529 if (aAsyncEvent == EPanicAsyncEvent) |
|
530 INFO_PRINTF1(_L("Received expected PANIC state")); |
|
531 else |
|
532 { |
|
533 INFO_PRINTF1(_L("Did not receive expected PANIC state")); |
|
534 iResult = EFail; |
|
535 } |
|
536 } |
|
537 } |
|
538 |
|
539 TVerdict CElementStateMachineStep2_3::doTestStepPostambleL() |
|
540 /** |
|
541 * @return - TVerdict code |
|
542 * Override of base class virtual |
|
543 */ |
|
544 { |
|
545 Destroy(); |
|
546 SetTestStepResult(iResult); |
|
547 return TestStepResult(); |
|
548 } |
|
549 |
|
550 CElementStateMachineStep2_4::CElementStateMachineStep2_4() |
|
551 /** |
|
552 * Constructor |
|
553 */ |
|
554 { |
|
555 // Call base class method to set up the human readable name for logging |
|
556 SetTestStepName(KElementStateMachineStep2_4); |
|
557 } |
|
558 |
|
559 TVerdict CElementStateMachineStep2_4::doTestStepPreambleL() |
|
560 /** |
|
561 * @return - TVerdict code |
|
562 * Override of base class virtual |
|
563 */ |
|
564 { |
|
565 SetTestStepResult(EFail); |
|
566 iResult = EFail; |
|
567 Setup(); |
|
568 iExpectedAsyncEvent = EErroringAsyncEvent; |
|
569 iResult = EPass; |
|
570 return TestStepResult(); |
|
571 } |
|
572 |
|
573 TVerdict CElementStateMachineStep2_4::doTestStepL() |
|
574 /** |
|
575 * @return - TVerdict code |
|
576 * Tests that the state machine sets and runs an error event if an active event returns an error |
|
577 */ |
|
578 { |
|
579 INFO_PRINTF1(_L("Create asynchronous erroring and error events (states)")); |
|
580 CAsyncEventImpl erroringAsync = CAsyncEventImpl(EErroringAsyncEvent, this, *iStateMachine, KElementStateMachineError); |
|
581 CAsyncEventImpl errorAsync = CAsyncEventImpl(EErrorAsyncEvent, this, *iStateMachine, KErrNone); |
|
582 erroringAsync.SetNext(NULL); |
|
583 errorAsync.SetNext(NULL); |
|
584 INFO_PRINTF1(_L("Set state machine first active event to ERRORING")); |
|
585 iStateMachine->SetActiveEvent(&erroringAsync); |
|
586 INFO_PRINTF1(_L("Start state machine")); |
|
587 TRequestStatus clientStatus; |
|
588 iStateMachine->Start(&clientStatus, NULL, NULL); |
|
589 iStateMachine->SetErrorEvent(&errorAsync); |
|
590 iActiveScheduler->Start(); |
|
591 User::WaitForRequest(clientStatus); |
|
592 TInt error = iStateMachine->LastError(); |
|
593 INFO_PRINTF1(_L("Check returned error is expected error (from iLastError member)")); |
|
594 INFO_PRINTF3(_L("Expected error: %d, received error: %d"), KElementStateMachineError, error); |
|
595 if (error != KElementStateMachineError) |
|
596 iResult = EFail; |
|
597 return TestStepResult(); |
|
598 } |
|
599 |
|
600 void CElementStateMachineStep2_4::LogStateChange(TAsyncEventTest aAsyncEvent) |
|
601 { |
|
602 if (iExpectedAsyncEvent == EErroringAsyncEvent) |
|
603 { |
|
604 if (aAsyncEvent == EErroringAsyncEvent) |
|
605 INFO_PRINTF1(_L("Received expected ERRORING state")); |
|
606 else |
|
607 { |
|
608 INFO_PRINTF1(_L("Did not receive expected ERRORING state")); |
|
609 iResult = EFail; |
|
610 } |
|
611 iExpectedAsyncEvent = EErrorAsyncEvent; |
|
612 } |
|
613 else if (iExpectedAsyncEvent == EErrorAsyncEvent) |
|
614 { |
|
615 if (aAsyncEvent == EErrorAsyncEvent) |
|
616 INFO_PRINTF1(_L("Received expected ERROR state")); |
|
617 else |
|
618 { |
|
619 INFO_PRINTF1(_L("Did not receive expected ERROR state")); |
|
620 iResult = EFail; |
|
621 } |
|
622 } |
|
623 } |
|
624 |
|
625 TVerdict CElementStateMachineStep2_4::doTestStepPostambleL() |
|
626 /** |
|
627 * @return - TVerdict code |
|
628 * Override of base class virtual |
|
629 */ |
|
630 { |
|
631 Destroy(); |
|
632 SetTestStepResult(iResult); |
|
633 return TestStepResult(); |
|
634 } |
|
635 |
|
636 CElementStateMachineStep2_5::CElementStateMachineStep2_5() |
|
637 /** |
|
638 * Constructor |
|
639 */ |
|
640 { |
|
641 // Call base class method to set up the human readable name for logging |
|
642 SetTestStepName(KElementStateMachineStep2_5); |
|
643 } |
|
644 |
|
645 TVerdict CElementStateMachineStep2_5::doTestStepPreambleL() |
|
646 /** |
|
647 * @return - TVerdict code |
|
648 * Override of base class virtual |
|
649 */ |
|
650 { |
|
651 SetTestStepResult(EFail); |
|
652 iResult = EFail; |
|
653 Setup(); |
|
654 iExpectedAsyncEvent = EForcedErrorAsyncEvent; |
|
655 iResult = EPass; |
|
656 return TestStepResult(); |
|
657 } |
|
658 |
|
659 TVerdict CElementStateMachineStep2_5::doTestStepL() |
|
660 /** |
|
661 * @return - TVerdict code |
|
662 * Tests that the state machine responds to retrospective errors being set in the async event |
|
663 */ |
|
664 { |
|
665 INFO_PRINTF1(_L("Create asynchronous erroring and error events (states)")); |
|
666 CAsyncEventImpl forcedErroringAsync = CAsyncEventImpl(EForcedErrorAsyncEvent, this, *iStateMachine, KElementStateMachineError); |
|
667 forcedErroringAsync.SetNext(&forcedErroringAsync); |
|
668 INFO_PRINTF1(_L("Set state machine first active event to FORCEDERRORING")); |
|
669 iStateMachine->SetActiveEvent(&forcedErroringAsync); |
|
670 INFO_PRINTF1(_L("Start state machine")); |
|
671 TRequestStatus clientStatus; |
|
672 iStateMachine->Start(&clientStatus, &forcedErroringAsync, NULL); |
|
673 iActiveScheduler->Start(); |
|
674 User::WaitForRequest(clientStatus); |
|
675 TInt error = iStateMachine->LastError(); |
|
676 INFO_PRINTF1(_L("Check returned error is expected error (from iLastError member)")); |
|
677 INFO_PRINTF3(_L("Expected error: %d, received error: %d"), KElementStateMachineError, error); |
|
678 if (error != KElementStateMachineError) |
|
679 iResult = EFail; |
|
680 INFO_PRINTF1(_L("Check number of runs of async ProcessL")); |
|
681 TInt runs = forcedErroringAsync.iRuns; |
|
682 INFO_PRINTF2(_L("Expected runs: 2, actual runs: %d"), runs); |
|
683 if (runs != 2) |
|
684 iResult = EFail; |
|
685 return TestStepResult(); |
|
686 } |
|
687 |
|
688 void CElementStateMachineStep2_5::LogStateChange(TAsyncEventTest aAsyncEvent) |
|
689 { |
|
690 if (iExpectedAsyncEvent == EForcedErrorAsyncEvent) |
|
691 { |
|
692 if (aAsyncEvent == EForcedErrorAsyncEvent) |
|
693 INFO_PRINTF1(_L("Received expected FORCEDERRORING state")); |
|
694 else |
|
695 { |
|
696 INFO_PRINTF1(_L("Did not receive expected FORCEDERRORING state")); |
|
697 iResult = EFail; |
|
698 } |
|
699 } |
|
700 } |
|
701 |
|
702 TVerdict CElementStateMachineStep2_5::doTestStepPostambleL() |
|
703 /** |
|
704 * @return - TVerdict code |
|
705 * Override of base class virtual |
|
706 */ |
|
707 { |
|
708 Destroy(); |
|
709 SetTestStepResult(iResult); |
|
710 return TestStepResult(); |
|
711 } |
|
712 |
|
713 CElementStateMachineStep2_6::CElementStateMachineStep2_6() |
|
714 /** |
|
715 * Constructor |
|
716 */ |
|
717 { |
|
718 // Call base class method to set up the human readable name for logging |
|
719 SetTestStepName(KElementStateMachineStep2_6); |
|
720 } |
|
721 |
|
722 TVerdict CElementStateMachineStep2_6::doTestStepPreambleL() |
|
723 /** |
|
724 * @return - TVerdict code |
|
725 * Override of base class virtual |
|
726 */ |
|
727 { |
|
728 SetTestStepResult(EFail); |
|
729 iResult = EFail; |
|
730 Setup(); |
|
731 iExpectedAsyncEvent = ECancelAsyncEvent; |
|
732 iResult = EPass; |
|
733 return TestStepResult(); |
|
734 } |
|
735 |
|
736 TVerdict CElementStateMachineStep2_6::doTestStepL() |
|
737 /** |
|
738 * @return - TVerdict code |
|
739 * Tests cancelling the state machine with no error |
|
740 */ |
|
741 { |
|
742 INFO_PRINTF1(_L("Create asynchronous cancelling event (state)")); |
|
743 CAsyncEventImpl cancelAsync = CAsyncEventImpl(ECancelAsyncEvent, this, *iStateMachine, KErrNone); |
|
744 cancelAsync.SetNext(NULL); |
|
745 INFO_PRINTF1(_L("Set state machine first active event to CANCEL")); |
|
746 iStateMachine->SetActiveEvent(&cancelAsync); |
|
747 INFO_PRINTF1(_L("Start state machine")); |
|
748 TRequestStatus clientStatus; |
|
749 iStateMachine->Start(&clientStatus, NULL, NULL); |
|
750 iActiveScheduler->Start(); |
|
751 User::WaitForRequest(clientStatus); |
|
752 TInt error = clientStatus.Int(); |
|
753 INFO_PRINTF1(_L("Check returned error is expected error")); |
|
754 INFO_PRINTF3(_L("Expected error: %d, received error: %d"), KErrNone, error); |
|
755 if (error != KErrNone) |
|
756 iResult = EFail; |
|
757 return TestStepResult(); |
|
758 } |
|
759 |
|
760 void CElementStateMachineStep2_6::LogStateChange(TAsyncEventTest aAsyncEvent) |
|
761 { |
|
762 if (iExpectedAsyncEvent == ECancelAsyncEvent) |
|
763 { |
|
764 if (aAsyncEvent == ECancelAsyncEvent) |
|
765 INFO_PRINTF1(_L("Received expected CANCEL state")); |
|
766 else |
|
767 { |
|
768 INFO_PRINTF1(_L("Did not receive expected CANCEL state")); |
|
769 iResult = EFail; |
|
770 } |
|
771 } |
|
772 } |
|
773 |
|
774 TVerdict CElementStateMachineStep2_6::doTestStepPostambleL() |
|
775 /** |
|
776 * @return - TVerdict code |
|
777 * Override of base class virtual |
|
778 */ |
|
779 { |
|
780 Destroy(); |
|
781 SetTestStepResult(iResult); |
|
782 return TestStepResult(); |
|
783 } |
|
784 |
|
785 CElementStateMachineStep2_7::CElementStateMachineStep2_7() |
|
786 /** |
|
787 * Constructor |
|
788 */ |
|
789 { |
|
790 // Call base class method to set up the human readable name for logging |
|
791 SetTestStepName(KElementStateMachineStep2_7); |
|
792 } |
|
793 |
|
794 TVerdict CElementStateMachineStep2_7::doTestStepPreambleL() |
|
795 /** |
|
796 * @return - TVerdict code |
|
797 * Override of base class virtual |
|
798 */ |
|
799 { |
|
800 SetTestStepResult(EFail); |
|
801 iResult = EFail; |
|
802 Setup(); |
|
803 iExpectedAsyncEvent = ECancelAsyncEvent; |
|
804 iResult = EPass; |
|
805 return TestStepResult(); |
|
806 } |
|
807 |
|
808 TVerdict CElementStateMachineStep2_7::doTestStepL() |
|
809 /** |
|
810 * @return - TVerdict code |
|
811 * Tests cancelling the state machine with an error |
|
812 */ |
|
813 { |
|
814 INFO_PRINTF1(_L("Create asynchronous cancelling and error events (states)")); |
|
815 CAsyncEventImpl cancelAsync = CAsyncEventImpl(ECancelAsyncEvent, this, *iStateMachine, KElementStateMachineError); |
|
816 CAsyncEventImpl errorAsync = CAsyncEventImpl(EErrorAsyncEvent, this, *iStateMachine, KErrNone); |
|
817 cancelAsync.SetNext(NULL); |
|
818 errorAsync.SetNext(NULL); |
|
819 INFO_PRINTF1(_L("Set state machine first active event to CANCEL")); |
|
820 iStateMachine->SetActiveEvent(&cancelAsync); |
|
821 INFO_PRINTF1(_L("Start state machine")); |
|
822 TRequestStatus clientStatus; |
|
823 iStateMachine->Start(&clientStatus, &errorAsync, NULL); |
|
824 iActiveScheduler->Start(); |
|
825 User::WaitForRequest(clientStatus); |
|
826 TInt error = clientStatus.Int(); |
|
827 INFO_PRINTF1(_L("Check returned error is expected error")); |
|
828 INFO_PRINTF3(_L("Expected error: %d, received error: %d"), KErrCancel, error); |
|
829 if (error != KErrCancel) |
|
830 iResult = EFail; |
|
831 return TestStepResult(); |
|
832 } |
|
833 |
|
834 void CElementStateMachineStep2_7::LogStateChange(TAsyncEventTest aAsyncEvent) |
|
835 { |
|
836 if (iExpectedAsyncEvent == ECancelAsyncEvent) |
|
837 { |
|
838 if (aAsyncEvent == ECancelAsyncEvent) |
|
839 INFO_PRINTF1(_L("Received expected CANCEL state")); |
|
840 else |
|
841 { |
|
842 INFO_PRINTF1(_L("Did not receive expected CANCEL state")); |
|
843 iResult = EFail; |
|
844 } |
|
845 iExpectedAsyncEvent = EErrorAsyncEvent; |
|
846 } |
|
847 else if (iExpectedAsyncEvent == EErrorAsyncEvent) |
|
848 { |
|
849 if (aAsyncEvent == EErrorAsyncEvent) |
|
850 INFO_PRINTF1(_L("Received expected ERROR state")); |
|
851 else |
|
852 { |
|
853 INFO_PRINTF1(_L("Did not receive expected ERROR state")); |
|
854 iResult = EFail; |
|
855 } |
|
856 } |
|
857 } |
|
858 |
|
859 TVerdict CElementStateMachineStep2_7::doTestStepPostambleL() |
|
860 /** |
|
861 * @return - TVerdict code |
|
862 * Override of base class virtual |
|
863 */ |
|
864 { |
|
865 Destroy(); |
|
866 SetTestStepResult(iResult); |
|
867 return TestStepResult(); |
|
868 } |
|
869 |
|
870 CElementStateMachineStep2_8::CElementStateMachineStep2_8() |
|
871 /** |
|
872 * Constructor |
|
873 */ |
|
874 { |
|
875 // Call base class method to set up the human readable name for logging |
|
876 SetTestStepName(KElementStateMachineStep2_8); |
|
877 } |
|
878 |
|
879 TVerdict CElementStateMachineStep2_8::doTestStepPreambleL() |
|
880 /** |
|
881 * @return - TVerdict code |
|
882 * Override of base class virtual |
|
883 */ |
|
884 { |
|
885 SetTestStepResult(EFail); |
|
886 iResult = EFail; |
|
887 Setup(); |
|
888 iExpectedAsyncEvent = EGreenAsyncEvent; |
|
889 iResult = EPass; |
|
890 return TestStepResult(); |
|
891 } |
|
892 |
|
893 TVerdict CElementStateMachineStep2_8::doTestStepL() |
|
894 /** |
|
895 * @return - TVerdict code |
|
896 * Tests suspending and restarting the state machine |
|
897 */ |
|
898 { |
|
899 INFO_PRINTF1(_L("Create asynchronous green, red and suspend events (states)")); |
|
900 CAsyncEventImpl greenAsync = CAsyncEventImpl(EGreenAsyncEvent, this, *iStateMachine, KErrNone); |
|
901 CAsyncEventImpl suspendAsync = CAsyncEventImpl(ESuspendAsyncEvent, this, *iStateMachine, KErrNone); |
|
902 CAsyncEventImpl redAsync = CAsyncEventImpl(ERedAsyncEvent, this, *iStateMachine, KErrNone); |
|
903 greenAsync.SetNext(&suspendAsync); |
|
904 suspendAsync.SetNext(&redAsync); |
|
905 redAsync.SetNext(NULL); |
|
906 INFO_PRINTF1(_L("Set state machine first active event to GREEN")); |
|
907 iStateMachine->SetActiveEvent(&greenAsync); |
|
908 CStateMachineNotifyImpl stateMachineNotify = CStateMachineNotifyImpl(); |
|
909 INFO_PRINTF1(_L("Start state machine")); |
|
910 TRequestStatus clientStatus; |
|
911 iStateMachine->Start(&clientStatus, NULL, &stateMachineNotify); |
|
912 iActiveScheduler->Start(); |
|
913 User::WaitForRequest(clientStatus); |
|
914 TInt greenRuns = greenAsync.iRuns; |
|
915 INFO_PRINTF2(_L("Check that GREEN has been run once, runs: %d"), greenRuns); |
|
916 if (greenRuns != 1) |
|
917 iResult = EFail; |
|
918 TInt suspendRuns = suspendAsync.iRuns; |
|
919 INFO_PRINTF2(_L("Check that SUSPEND has been run once, runs: %d"), suspendRuns); |
|
920 if (suspendRuns != 1) |
|
921 iResult = EFail; |
|
922 TInt redRuns = redAsync.iRuns; |
|
923 INFO_PRINTF2(_L("Check that RED has been run once, runs: %d"), redRuns); |
|
924 if (redRuns != 1) |
|
925 iResult = EFail; |
|
926 return TestStepResult(); |
|
927 } |
|
928 |
|
929 void CElementStateMachineStep2_8::LogStateChange(TAsyncEventTest aAsyncEvent) |
|
930 { |
|
931 if (iExpectedAsyncEvent == EGreenAsyncEvent) |
|
932 { |
|
933 if (aAsyncEvent == EGreenAsyncEvent) |
|
934 INFO_PRINTF1(_L("Received expected GREEN state")); |
|
935 else |
|
936 { |
|
937 INFO_PRINTF1(_L("Did not receive expected GREEN state")); |
|
938 iResult = EFail; |
|
939 } |
|
940 iExpectedAsyncEvent = ESuspendAsyncEvent; |
|
941 } |
|
942 else if (iExpectedAsyncEvent == ESuspendAsyncEvent) |
|
943 { |
|
944 if (aAsyncEvent == ESuspendAsyncEvent) |
|
945 INFO_PRINTF1(_L("Received expected SUSPEND state")); |
|
946 else |
|
947 { |
|
948 INFO_PRINTF1(_L("Did not receive expected SUSPEND state")); |
|
949 iResult = EFail; |
|
950 } |
|
951 iExpectedAsyncEvent = ERedAsyncEvent; |
|
952 } |
|
953 else if (iExpectedAsyncEvent == ERedAsyncEvent) |
|
954 { |
|
955 if (aAsyncEvent == ERedAsyncEvent) |
|
956 INFO_PRINTF1(_L("Received expected RED state")); |
|
957 else |
|
958 { |
|
959 INFO_PRINTF1(_L("Did not receive expected RED state")); |
|
960 iResult = EFail; |
|
961 } |
|
962 } |
|
963 } |
|
964 |
|
965 TVerdict CElementStateMachineStep2_8::doTestStepPostambleL() |
|
966 /** |
|
967 * @return - TVerdict code |
|
968 * Override of base class virtual |
|
969 */ |
|
970 { |
|
971 Destroy(); |
|
972 SetTestStepResult(iResult); |
|
973 return TestStepResult(); |
|
974 } |