|
1 // Copyright (c) 2006-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 "Symbian Foundation License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // @file ctlbsclientstepmodstatus.cpp |
|
15 // This is the class implementation for the Module Information Tests |
|
16 // |
|
17 // |
|
18 |
|
19 #include "ctlbsclientstepmodstatus.h" |
|
20 #include "ctlbsclientstep.h" |
|
21 |
|
22 #include <e32property.h> |
|
23 #include <lbs.h> |
|
24 |
|
25 #include "tlbsutils.h" |
|
26 #include "ctlbsasyncwaiter.h" |
|
27 |
|
28 /** |
|
29 * Destructor |
|
30 */ |
|
31 CT_LbsClientStep_ModStat::~CT_LbsClientStep_ModStat() |
|
32 { |
|
33 } |
|
34 |
|
35 |
|
36 /** |
|
37 * Constructor |
|
38 */ |
|
39 CT_LbsClientStep_ModStat::CT_LbsClientStep_ModStat(CT_LbsClientServer& aParent) : CT_LbsClientStep(aParent) |
|
40 { |
|
41 SetTestStepName(KLbsClientStep_ModStatus); |
|
42 } |
|
43 |
|
44 |
|
45 /** |
|
46 Static Constructor |
|
47 */ |
|
48 CT_LbsClientStep_ModStat* CT_LbsClientStep_ModStat::New(CT_LbsClientServer& aParent) |
|
49 { |
|
50 return new CT_LbsClientStep_ModStat(aParent); |
|
51 // Note the lack of ELeave. |
|
52 // This means that having insufficient memory will return NULL; |
|
53 } |
|
54 |
|
55 /** |
|
56 * Sets requested event mask as specified for supplied module. |
|
57 * Kicks test module to cause events requested then waits for event(s) |
|
58 * Updates the supplied module status |
|
59 * returns TRUE if everything went as expected, FALSE otherwise |
|
60 */ |
|
61 /** |
|
62 * Sets requested event mask as specified for supplied module. |
|
63 * Kicks test module to cause events requested then waits for event(s) |
|
64 * Updates the supplied module status |
|
65 * returns TRUE if everything went as expected, FALSE otherwise |
|
66 */ |
|
67 TBool CT_LbsClientStep_ModStat::DoRequestAndVerifyModStatusEventsL(TPositionModuleStatusEvent::TModuleEvent aReqEventsMask, TPositionModuleStatus& aModStatus, TPositionModuleId aModId = KPositionNullModuleId ) |
|
68 { |
|
69 TBool result = TRUE; |
|
70 TPositionModuleStatusEvent statusEvent; |
|
71 TPositionModuleId agpsmodId; |
|
72 |
|
73 // we're interested in the agps module id |
|
74 T_LbsUtils utils; |
|
75 agpsmodId = utils.GetAGpsModuleIdL(iServer); |
|
76 |
|
77 // Set event mask to select requested status events |
|
78 statusEvent.SetRequestedEvents(aReqEventsMask); |
|
79 |
|
80 // verify the set worked |
|
81 if(statusEvent.RequestedEvents() != aReqEventsMask) |
|
82 { |
|
83 INFO_PRINTF2(_L("Requested Events don't match. Got0x%x"), statusEvent.RequestedEvents()); |
|
84 return FALSE; |
|
85 } |
|
86 |
|
87 CT_LbsAsyncWaiter* waiter = CT_LbsAsyncWaiter::NewL(); |
|
88 |
|
89 // Request module status event using supplied module id |
|
90 iServer.NotifyModuleStatusEvent(statusEvent, waiter->iStatus, aModId); |
|
91 |
|
92 TPositionModuleStatusEvent::TModuleEvent eventsExpected = 0; |
|
93 |
|
94 // assume we are interested in the agps module since we can't control events from network module |
|
95 ASSERT(aModId == agpsmodId || aModId == KPositionNullModuleId); |
|
96 |
|
97 // kick the test agps module to cause the requested status event(s) |
|
98 TPckgBuf<TModuleDataIn> modDataInBuf; |
|
99 TModuleDataIn& modDataIn = modDataInBuf(); |
|
100 |
|
101 modDataIn.iRequestType = TModuleDataIn::EModuleRequestEventKickOff; |
|
102 modDataIn.iKickOffEventType = 0; |
|
103 if(aReqEventsMask & TPositionModuleStatusEvent::EEventDeviceStatus) |
|
104 { |
|
105 modDataIn.iKickOffEventType |= TModuleDataIn::EKickOffEventTypeDevice; |
|
106 eventsExpected |= TPositionModuleStatusEvent::EEventDeviceStatus; |
|
107 } |
|
108 |
|
109 if(aReqEventsMask & TPositionModuleStatusEvent::EEventDataQualityStatus) |
|
110 { |
|
111 modDataIn.iKickOffEventType |= TModuleDataIn::EKickOffEventTypeDataQuality; |
|
112 eventsExpected |= TPositionModuleStatusEvent::EEventDataQualityStatus; |
|
113 } |
|
114 |
|
115 User::LeaveIfError(RProperty::Set(KUidSystemCategory, ELbsTestAGpsModuleIn, modDataInBuf)); |
|
116 |
|
117 |
|
118 // Wait for event(s) |
|
119 while(result && eventsExpected) |
|
120 { |
|
121 waiter->StartAndWait(); |
|
122 User::LeaveIfError(waiter->Result()); |
|
123 |
|
124 |
|
125 TInt result = waiter->Result(); |
|
126 |
|
127 TPositionModuleStatusEvent::TModuleEvent eventsOccurred = statusEvent.OccurredEvents(); |
|
128 |
|
129 ASSERT(eventsOccurred); |
|
130 |
|
131 if(result) |
|
132 { |
|
133 INFO_PRINTF2(_L("Unexpected error returned %d"), result); |
|
134 result = FALSE; |
|
135 } |
|
136 // Verify correct event(s) happenned |
|
137 else |
|
138 { |
|
139 |
|
140 if(eventsOccurred & ~(eventsExpected)) |
|
141 { |
|
142 INFO_PRINTF2(_L("Unexpected event received 0x%x"), statusEvent.OccurredEvents()); |
|
143 result = FALSE; |
|
144 } |
|
145 |
|
146 if(statusEvent.ModuleId() == agpsmodId) |
|
147 { |
|
148 eventsExpected &= ~eventsOccurred; |
|
149 } |
|
150 |
|
151 // Request next module status event |
|
152 if (eventsExpected) |
|
153 { |
|
154 iServer.NotifyModuleStatusEvent(statusEvent, waiter->iStatus/*request*/, aModId); |
|
155 } |
|
156 } |
|
157 } |
|
158 |
|
159 // TODO - appropriate to do this here? |
|
160 // device status event happened. Read in new status (this will be verified in future test step): |
|
161 statusEvent.GetModuleStatus(aModStatus); |
|
162 |
|
163 delete waiter; |
|
164 |
|
165 return result; |
|
166 } |
|
167 |
|
168 /** |
|
169 * Sets requested event mask as specified for agps module. |
|
170 * Kicks test module to cause events requested then waits for event(s) |
|
171 * Updates the supplied module status |
|
172 * returns TRUE if everything went as expected, FALSE otherwise |
|
173 */ |
|
174 TBool CT_LbsClientStep_ModStat::DoRequestAndVerifyAGPSModStatusEventsL(TPositionModuleStatusEvent::TModuleEvent aReqEventsMask, TPositionModuleStatus& aModStatus) |
|
175 { |
|
176 TPositionModuleId modId; |
|
177 |
|
178 // we're interested in the agps module id |
|
179 T_LbsUtils utils; |
|
180 modId = utils.GetAGpsModuleIdL(iServer); |
|
181 |
|
182 return DoRequestAndVerifyModStatusEventsL(aReqEventsMask, aModStatus, modId); |
|
183 } |
|
184 |
|
185 |
|
186 /** |
|
187 * Sets requested event mask as specified for supplied module and asks to be notified of events |
|
188 * (note does not kick test module to cause events; use only if expect error to be returned) |
|
189 * Waits for event and returns error |
|
190 */ |
|
191 TInt CT_LbsClientStep_ModStat::DoRequestModStatusEventsWithError(TPositionModuleStatusEvent::TModuleEvent aReqEventsMask, TPositionModuleId aModId) |
|
192 { |
|
193 //TRequestStatus request; |
|
194 TPositionModuleStatusEvent statusEvent; |
|
195 |
|
196 statusEvent.SetRequestedEvents(aReqEventsMask); |
|
197 |
|
198 CT_LbsAsyncWaiter* waiter = CT_LbsAsyncWaiter::NewL(); |
|
199 |
|
200 iServer.NotifyModuleStatusEvent(statusEvent, waiter->iStatus, aModId); |
|
201 |
|
202 waiter->StartAndWait(); |
|
203 |
|
204 TInt result = waiter->Result(); |
|
205 |
|
206 //User::WaitForRequest(request); |
|
207 delete waiter; |
|
208 |
|
209 return result; |
|
210 |
|
211 } |
|
212 |
|
213 TBool CT_LbsClientStep_ModStat::DoVerifyModStatus(TPositionModuleStatusEvent::TModuleEvent aExpectedModStatus,TPositionModuleId aModId) |
|
214 { |
|
215 // Initialise current module status. |
|
216 TPositionModuleStatus& currentModStatus = iParent.iSharedData->iCurrentModuleStatus; |
|
217 iServer.GetModuleStatus(currentModStatus,aModId); |
|
218 |
|
219 if(currentModStatus.DeviceStatus()!=aExpectedModStatus) |
|
220 { |
|
221 INFO_PRINTF3(_L("Module in Unexpected State - %d and not %d"),currentModStatus.DeviceStatus(),aExpectedModStatus); |
|
222 SetTestStepResult(EFail); |
|
223 return EFalse; |
|
224 } |
|
225 else |
|
226 { |
|
227 INFO_PRINTF2(_L("Module in Expected State %d"),aExpectedModStatus); |
|
228 return ETrue; |
|
229 } |
|
230 } |
|
231 |
|
232 /** |
|
233 * @return - TVerdict code |
|
234 * Override of base class pure virtual |
|
235 * Our implementation only gets called if the base class doTestStepPreambleL() did |
|
236 * not leave. That being the case, the current test result value will be EPass. |
|
237 */ |
|
238 TVerdict CT_LbsClientStep_ModStat::doTestStepL() |
|
239 { |
|
240 // Generic test step used to test the LBS Client Notify position update API. |
|
241 INFO_PRINTF1(_L(">>CT_LbsClientStep_ModStat::doTestStepL()")); |
|
242 |
|
243 if (TestStepResult() == EPass) |
|
244 { |
|
245 TInt err = KErrNone; |
|
246 |
|
247 // Connect to self locate server. |
|
248 User::LeaveIfError(iServer.Connect()); |
|
249 CleanupClosePushL(iServer); |
|
250 |
|
251 // Carryout unique test actions. |
|
252 TInt testCaseId; |
|
253 if (GetIntFromConfig(ConfigSection(), KTestCaseId, testCaseId)) |
|
254 { |
|
255 switch (testCaseId) |
|
256 { |
|
257 // Test case LBS-ModStatus-0001 to 0004 |
|
258 case 01: |
|
259 case 02: |
|
260 case 03: |
|
261 case 04: |
|
262 { |
|
263 TPositionModuleId testmodId; |
|
264 |
|
265 T_LbsUtils utils; |
|
266 testmodId = utils.GetAGpsModuleIdL(iServer); |
|
267 |
|
268 // Get the module device status. |
|
269 TPositionModuleStatus& modStatus = iParent.iSharedData->iCurrentModuleStatus; |
|
270 err = iServer.GetModuleStatus(modStatus, testmodId); |
|
271 if(KErrNone != err) |
|
272 { |
|
273 INFO_PRINTF2(_L("Failed with err %d"), err); |
|
274 SetTestStepResult(EFail); |
|
275 } |
|
276 } |
|
277 break; |
|
278 |
|
279 // Test case LBS-ModStatus-0005 |
|
280 case 05: |
|
281 { |
|
282 TPositionModuleId badmodId; |
|
283 T_LbsUtils utils; |
|
284 badmodId = utils.GetBadModuleId(); |
|
285 |
|
286 // Get the module device status. |
|
287 TPositionModuleStatus moduleStatus; |
|
288 |
|
289 err = iServer.GetModuleStatus(moduleStatus, badmodId); |
|
290 if(KErrNotFound != err) |
|
291 { |
|
292 INFO_PRINTF2(_L("Failed with err %d. Should have been KErrNotFound(-1)"), err); |
|
293 SetTestStepResult(EFail); |
|
294 } |
|
295 } |
|
296 break; |
|
297 |
|
298 // LBS-Mod-Status-Event-0002 |
|
299 case 22: |
|
300 { |
|
301 TPositionModuleStatus& testmodStatus = iParent.iSharedData->iCurrentModuleStatus; |
|
302 |
|
303 // Get device status events for any module: |
|
304 if(!DoRequestAndVerifyModStatusEventsL(TPositionModuleStatusEvent::EEventDeviceStatus, testmodStatus)) |
|
305 { |
|
306 SetTestStepResult(EFail); |
|
307 } |
|
308 } |
|
309 break; |
|
310 |
|
311 // LBS-Mod-Status-Event-0003 |
|
312 case 23: |
|
313 { |
|
314 TPositionModuleStatus& testmodStatus = iParent.iSharedData->iCurrentModuleStatus; |
|
315 |
|
316 // Get device status events for (test) agps module |
|
317 if(!DoRequestAndVerifyAGPSModStatusEventsL(TPositionModuleStatusEvent::EEventDeviceStatus, testmodStatus)) |
|
318 { |
|
319 SetTestStepResult(EFail); |
|
320 } |
|
321 |
|
322 // Get device status events again |
|
323 if(!DoRequestAndVerifyModStatusEventsL(TPositionModuleStatusEvent::EEventDeviceStatus, testmodStatus)) |
|
324 { |
|
325 SetTestStepResult(EFail); |
|
326 } |
|
327 } |
|
328 break; |
|
329 |
|
330 // LBS-Mod-Status-Event-0004 |
|
331 case 24: |
|
332 { |
|
333 TPositionModuleStatus& testmodStatus = iParent.iSharedData->iCurrentModuleStatus; |
|
334 |
|
335 // Get device status events |
|
336 if(!DoRequestAndVerifyAGPSModStatusEventsL(TPositionModuleStatusEvent::EEventDeviceStatus, testmodStatus)) |
|
337 { |
|
338 SetTestStepResult(EFail); |
|
339 } |
|
340 } |
|
341 break; |
|
342 |
|
343 // LBS-Mod-Status-Event-0005 |
|
344 case 25: |
|
345 { |
|
346 TPositionModuleStatus& testmodStatus = iParent.iSharedData->iCurrentModuleStatus; |
|
347 // Get device status events |
|
348 if(!DoRequestAndVerifyAGPSModStatusEventsL(TPositionModuleStatusEvent::EEventDataQualityStatus, testmodStatus)) |
|
349 { |
|
350 SetTestStepResult(EFail); |
|
351 } |
|
352 } |
|
353 break; |
|
354 |
|
355 // LBS-Mod-Status-Event-0009 |
|
356 case 29: |
|
357 { |
|
358 TPositionModuleStatus& testmodStatus = iParent.iSharedData->iCurrentModuleStatus; |
|
359 |
|
360 //In feature when system events support, change TPositionModuleStatusEvent::EEventAll |
|
361 // Get device status events |
|
362 if(!DoRequestAndVerifyAGPSModStatusEventsL(((TPositionModuleStatusEvent::EEventDeviceStatus)|(TPositionModuleStatusEvent::EEventDataQualityStatus)), testmodStatus)) |
|
363 { |
|
364 SetTestStepResult(EFail); |
|
365 } |
|
366 } |
|
367 break; |
|
368 |
|
369 // LBS-Mod-Status-Event-0010 |
|
370 case 30: |
|
371 { |
|
372 TPositionModuleId modId; |
|
373 TInt err; |
|
374 |
|
375 // use bad module id |
|
376 T_LbsUtils utils; |
|
377 modId = utils.GetBadModuleId(); |
|
378 |
|
379 err = DoRequestModStatusEventsWithError(TPositionModuleStatusEvent::EEventDataQualityStatus, modId); |
|
380 if(KErrNotFound != err) |
|
381 { |
|
382 SetTestStepResult(EFail); |
|
383 } |
|
384 } |
|
385 break; |
|
386 |
|
387 // LBS-Mod-Status-Event-0011 |
|
388 case 31: |
|
389 { |
|
390 TPositionModuleId modId; |
|
391 TInt err; |
|
392 |
|
393 // use agps module id |
|
394 T_LbsUtils utils; |
|
395 modId = utils.GetAGpsModuleIdL(iServer); |
|
396 |
|
397 err = DoRequestModStatusEventsWithError(0, modId); |
|
398 if(KErrArgument != err) |
|
399 { |
|
400 SetTestStepResult(EFail); |
|
401 } |
|
402 } |
|
403 break; |
|
404 |
|
405 // LBS-Mod-Status-Event-0012 |
|
406 case 32: |
|
407 { |
|
408 TPositionModuleId modId; |
|
409 TRequestStatus request; |
|
410 TPositionModuleStatusEvent statusEvent; |
|
411 |
|
412 // use agps module id |
|
413 T_LbsUtils utils; |
|
414 modId = utils.GetAGpsModuleIdL(iServer); |
|
415 |
|
416 statusEvent.SetRequestedEvents(TPositionModuleStatusEvent::EEventDeviceStatus); |
|
417 |
|
418 iServer.NotifyModuleStatusEvent(statusEvent, request, modId); |
|
419 |
|
420 TInt err = iServer.CancelRequest(EPositionServerNotifyModuleStatusEvent); |
|
421 if(KErrNone == err) |
|
422 { |
|
423 User::WaitForRequest(request); |
|
424 if(KErrCancel != request.Int()) |
|
425 { |
|
426 INFO_PRINTF2(_L("Failed: KErrCancel not returned, Got %d"), request.Int()); |
|
427 SetTestStepResult(EFail); |
|
428 } |
|
429 } |
|
430 else |
|
431 { |
|
432 INFO_PRINTF2(_L("Failed: CancelRequest returned error %d"), err); |
|
433 SetTestStepResult(EFail); |
|
434 } |
|
435 } |
|
436 break; |
|
437 |
|
438 // LBS-Mod-Status-Event-0013 |
|
439 case 33: |
|
440 { |
|
441 TInt err = iServer.CancelRequest(EPositionServerNotifyModuleStatusEvent); |
|
442 if(KErrNotFound != err) |
|
443 { |
|
444 INFO_PRINTF2(_L("Failed: CancelRequest returned error %d, expecting KErrNotFound"), err); |
|
445 SetTestStepResult(EFail); |
|
446 } |
|
447 } |
|
448 break; |
|
449 |
|
450 // LBS-Mod-Status-Event-0014 |
|
451 case 34: |
|
452 { |
|
453 // close server since we don't want to be connected for this test |
|
454 iServer.Close(); |
|
455 |
|
456 TInt err = iServer.CancelRequest(EPositionServerNotifyModuleStatusEvent); |
|
457 |
|
458 // if we get here, something went wrong, so panic |
|
459 SetTestStepResult(EFail); |
|
460 |
|
461 User::Panic(KLbsClientStep_ModStatus, KErrGeneral); |
|
462 } |
|
463 break; |
|
464 |
|
465 // LBS-Mod-Status-Event-0015 |
|
466 case 35: |
|
467 { |
|
468 TPositionModuleId modId; |
|
469 TRequestStatus request; |
|
470 TPositionModuleStatusEvent statusEvent; |
|
471 |
|
472 // use agps module id |
|
473 T_LbsUtils utils; |
|
474 modId = utils.GetAGpsModuleIdL(iServer); |
|
475 |
|
476 // set requested events mask |
|
477 statusEvent.SetRequestedEvents(TPositionModuleStatusEvent::EEventDeviceStatus); |
|
478 |
|
479 // ask to be notified of requested events |
|
480 iServer.NotifyModuleStatusEvent(statusEvent, request, modId); |
|
481 |
|
482 // ask to be notified of requested events a second time (panics) |
|
483 iServer.NotifyModuleStatusEvent(statusEvent, request, modId); |
|
484 |
|
485 // if we get here, something went wrong, so panic |
|
486 SetTestStepResult(EFail); |
|
487 |
|
488 User::Panic(KLbsClientStep_ModStatus, KErrGeneral); |
|
489 } |
|
490 break; |
|
491 case 101: |
|
492 { |
|
493 // This test requires net sim to be open. |
|
494 OpenNetSim(); |
|
495 |
|
496 // Select the network module. |
|
497 T_LbsUtils utils; |
|
498 TPositionModuleId modId; |
|
499 modId = utils.GetNetworkModuleIdL(iServer); |
|
500 User::LeaveIfError(iPositioner.Open(iServer, modId)); |
|
501 CleanupClosePushL(iPositioner); |
|
502 |
|
503 // Initialise the position info variable. |
|
504 TPositionInfo* posInfo = new(ELeave) TPositionInfo(); |
|
505 CleanupStack::PushL(posInfo); |
|
506 |
|
507 // set requested events mask so we get notified on EEventDeviceStatus (any status change) |
|
508 TPositionModuleStatusEvent statusEvent; |
|
509 statusEvent.SetRequestedEvents(TPositionModuleStatusEvent::EEventDeviceStatus); |
|
510 CT_LbsAsyncWaiter* waiter = CT_LbsAsyncWaiter::NewL(); |
|
511 iServer.NotifyModuleStatusEvent(statusEvent, waiter->iStatus, modId); |
|
512 |
|
513 // Verify that the module status is ready before we make any requests. |
|
514 DoVerifyModStatus(TPositionModuleStatus::EDeviceReady,modId); |
|
515 |
|
516 // Request a position update, we should then see a state change to EDeviceActive |
|
517 TRequestStatus status; |
|
518 INFO_PRINTF1(_L("Performing NotifyPositionUpdate()")); |
|
519 iPositioner.NotifyPositionUpdate(*posInfo,status); |
|
520 // Use the waiter object so that we can get the device status change. |
|
521 waiter->StartAndWait(); |
|
522 waiter->Result(); |
|
523 |
|
524 // Check that the change that happened was the correct thing. |
|
525 TPositionModuleStatusEvent::TModuleEvent eventsExpected = TPositionModuleStatusEvent::EEventDeviceStatus; |
|
526 TPositionModuleStatusEvent::TModuleEvent eventsOccurred = statusEvent.OccurredEvents(); |
|
527 |
|
528 if(eventsOccurred!=eventsExpected) |
|
529 { |
|
530 INFO_PRINTF1(_L("No Module Status Event have Occured")); |
|
531 SetTestStepResult(EFail); |
|
532 } |
|
533 |
|
534 |
|
535 // Verify the device is now active |
|
536 DoVerifyModStatus(TPositionModuleStatus::EDeviceActive,modId); |
|
537 |
|
538 INFO_PRINTF1(_L("Position Received")); |
|
539 User::WaitForRequest(status); |
|
540 |
|
541 //Verify that the position is EDeviceReady again |
|
542 DoVerifyModStatus(TPositionModuleStatus::EDeviceReady,modId); |
|
543 |
|
544 // Tidy up everything |
|
545 CloseNetSim(); |
|
546 delete waiter; |
|
547 CleanupStack::PopAndDestroy(posInfo); |
|
548 CleanupStack::PopAndDestroy(&iPositioner); |
|
549 } |
|
550 break; |
|
551 default: |
|
552 { |
|
553 User::Panic(KLbsClientStep_ModStatus, KErrUnknown); |
|
554 } |
|
555 } |
|
556 |
|
557 |
|
558 } |
|
559 |
|
560 // All done, clean up. |
|
561 CleanupStack::PopAndDestroy(&iServer); |
|
562 } |
|
563 |
|
564 INFO_PRINTF1(_L("<<CT_LbsClientStep_ModStat::doTestStepL()")); |
|
565 |
|
566 return TestStepResult(); |
|
567 } |