|
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 "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 ctlbsclientstepmultireq.cpp |
|
15 // This is the class implementation for the Multi-Request Tests |
|
16 // |
|
17 // |
|
18 |
|
19 #include "ctlbsclientstepmultireq.h" |
|
20 |
|
21 #include <lbs.h> |
|
22 #include <lbscommon.h> |
|
23 #include <lbspositioninfo.h> |
|
24 #include <lbsipc.h> |
|
25 |
|
26 #include <lbs/test/tlbsutils.h> |
|
27 |
|
28 // constant definitions |
|
29 _LIT(KLbsClientStepMultiReq, "LbsClientStepMultiReq"); |
|
30 |
|
31 |
|
32 /** |
|
33 * Destructor |
|
34 */ |
|
35 CT_LbsClientStep_MultiReq::~CT_LbsClientStep_MultiReq() |
|
36 { |
|
37 delete iGetLastKnownPosAO; |
|
38 delete iNotifyPosUpdateAO; |
|
39 delete iTimer; |
|
40 delete iTempPosInfo; |
|
41 } |
|
42 |
|
43 |
|
44 /** |
|
45 * Constructor |
|
46 */ |
|
47 CT_LbsClientStep_MultiReq::CT_LbsClientStep_MultiReq(CT_LbsClientServer& aParent) : CT_LbsClientStep(aParent), iState(EStateUnknown), iTempPosInfo(NULL) |
|
48 { |
|
49 SetTestStepName(KLbsClientStep_MultiReq); |
|
50 } |
|
51 |
|
52 |
|
53 /** |
|
54 Static Constructor |
|
55 */ |
|
56 CT_LbsClientStep_MultiReq* CT_LbsClientStep_MultiReq::NewL(CT_LbsClientServer& aParent) |
|
57 { |
|
58 return new(ELeave) CT_LbsClientStep_MultiReq(aParent); |
|
59 } |
|
60 |
|
61 |
|
62 /** |
|
63 Static Constructor |
|
64 */ |
|
65 CT_LbsClientStep_MultiReq* CT_LbsClientStep_MultiReq::New(CT_LbsClientServer& aParent) |
|
66 { |
|
67 return new CT_LbsClientStep_MultiReq(aParent); |
|
68 // Note the lack of ELeave. |
|
69 // This means that having insufficient memory will return NULL; |
|
70 } |
|
71 |
|
72 |
|
73 /** |
|
74 * Callback - called when NotifyPositionUpdate request completes |
|
75 */ |
|
76 void CT_LbsClientStep_MultiReq::NotifyPositionUpdateCallback(TRequestStatus& aStatus) |
|
77 /** |
|
78 * Called when async NotifyPositionUpdate completes |
|
79 */ |
|
80 { |
|
81 TInt testCaseId; |
|
82 |
|
83 if (GetIntFromConfig(ConfigSection(), KTestCaseId, testCaseId)) |
|
84 { |
|
85 switch (testCaseId) |
|
86 { |
|
87 case 01: // multiple requests of different types |
|
88 { |
|
89 if(KErrNone == aStatus.Int()) |
|
90 { |
|
91 switch(iState) |
|
92 { |
|
93 case EStateUnknown: |
|
94 { |
|
95 iState = EStateLastNotifyPositionUpdateComplete; |
|
96 } |
|
97 break; |
|
98 |
|
99 case EStateLastKnownPositionComplete: |
|
100 { |
|
101 iState = EStateDone; |
|
102 AsyncTidyUp(); |
|
103 // note: we'll now drop back into the main test step |
|
104 } |
|
105 break; |
|
106 |
|
107 case EStateLastNotifyPositionUpdateComplete: |
|
108 case EStateDone : |
|
109 // fall through |
|
110 default: |
|
111 { |
|
112 User::Panic(KLbsClientStepMultiReq, KErrUnknown); |
|
113 } |
|
114 break; |
|
115 } |
|
116 } |
|
117 else |
|
118 { |
|
119 INFO_PRINTF2(_L("NotifyModuleStatusEvent completed. Status = %d"), aStatus.Int()); |
|
120 SetTestStepResult(EFail); |
|
121 AsyncTidyUp(); |
|
122 } |
|
123 }// end case 01 |
|
124 break; |
|
125 case 02: // |
|
126 { |
|
127 switch(iState) |
|
128 { |
|
129 case EStateUnknown: |
|
130 { |
|
131 iState = EStateLastNotifyPositionUpdateComplete; |
|
132 } |
|
133 break; |
|
134 |
|
135 case EStateLastKnownPositionComplete: |
|
136 { |
|
137 iState = EStateDone; |
|
138 AsyncTidyUp(); |
|
139 } |
|
140 break; |
|
141 |
|
142 case EStateLastNotifyPositionUpdateComplete: |
|
143 case EStateDone : |
|
144 // fall through |
|
145 default: |
|
146 { |
|
147 User::Panic(KLbsClientStepMultiReq, KErrUnknown); |
|
148 } |
|
149 break; |
|
150 } |
|
151 } |
|
152 break; |
|
153 default: |
|
154 { |
|
155 User::Panic(KLbsClientStepMultiReq, KErrUnknown); |
|
156 } |
|
157 |
|
158 }// end switch testCaseId |
|
159 }// end if GetIntFromConfig |
|
160 } |
|
161 |
|
162 |
|
163 |
|
164 /** |
|
165 * Callback - called when GetLastKnownPosition request completes |
|
166 */ |
|
167 void CT_LbsClientStep_MultiReq::GetLastKnownPositionCallback(TRequestStatus& aStatus) |
|
168 /** |
|
169 * Called when NotifyModuleStatusEvent completes |
|
170 */ |
|
171 { |
|
172 TInt testCaseId; |
|
173 |
|
174 if (GetIntFromConfig(ConfigSection(), KTestCaseId, testCaseId)) |
|
175 { |
|
176 switch (testCaseId) |
|
177 { |
|
178 case 01: // multiple requests of different types |
|
179 { |
|
180 if(KErrNone == aStatus.Int()) |
|
181 { |
|
182 switch(iState) |
|
183 { |
|
184 case EStateUnknown: |
|
185 { |
|
186 iState = EStateLastKnownPositionComplete; |
|
187 } |
|
188 break; |
|
189 |
|
190 case EStateLastNotifyPositionUpdateComplete: |
|
191 { |
|
192 iState = EStateDone; |
|
193 AsyncTidyUp(); |
|
194 // note: we'll now drop back into the main test step |
|
195 } |
|
196 break; |
|
197 |
|
198 case EStateLastKnownPositionComplete: |
|
199 case EStateDone : |
|
200 // fall through |
|
201 default: |
|
202 { |
|
203 User::Panic(KLbsClientStepMultiReq, KErrUnknown); |
|
204 } |
|
205 break; |
|
206 |
|
207 } |
|
208 } |
|
209 else |
|
210 { |
|
211 INFO_PRINTF2(_L("NotifyModuleStatusEvent completed. Status =%d"), aStatus.Int()); |
|
212 SetTestStepResult(EFail); |
|
213 AsyncTidyUp(); |
|
214 } |
|
215 |
|
216 }// end case 01 |
|
217 break; |
|
218 case 02: // NotifyPositionUpdate then GetLKP, latter cancelled |
|
219 { |
|
220 switch(iState) |
|
221 { |
|
222 case EStateUnknown: |
|
223 { |
|
224 iState = EStateLastKnownPositionComplete; |
|
225 TInt err = aStatus.Int(); |
|
226 switch(err) |
|
227 { |
|
228 case KErrNone: |
|
229 { |
|
230 INFO_PRINTF1(_L("MultiReq test: Last Known Position request completed successfully")); |
|
231 } |
|
232 break; |
|
233 case KErrCancel: |
|
234 { |
|
235 INFO_PRINTF1(_L("MultiReq test: Last Known Position request completed with KErrCancel")); |
|
236 } |
|
237 break; |
|
238 case KErrUnknown: |
|
239 { |
|
240 INFO_PRINTF1(_L("MultiReq test: Last Known Position request completed with KErrUnknown")); |
|
241 } |
|
242 break; |
|
243 default: |
|
244 { |
|
245 |
|
246 SetTestStepResult(EFail); |
|
247 AsyncTidyUp(); |
|
248 } |
|
249 break; |
|
250 } |
|
251 } |
|
252 break; |
|
253 |
|
254 case EStateLastNotifyPositionUpdateComplete: |
|
255 { |
|
256 iState = EStateDone; |
|
257 TInt err = aStatus.Int(); |
|
258 if(KErrNone != err) |
|
259 { |
|
260 SetTestStepResult(EFail); |
|
261 } |
|
262 AsyncTidyUp(); |
|
263 } |
|
264 break; |
|
265 |
|
266 case EStateLastKnownPositionComplete: |
|
267 case EStateDone : |
|
268 // fall through |
|
269 default: |
|
270 { |
|
271 User::Panic(KLbsClientStepMultiReq, KErrUnknown); |
|
272 } |
|
273 }// end switch(iState) |
|
274 }// end case 2 |
|
275 break; |
|
276 |
|
277 default: |
|
278 { |
|
279 User::Panic(KLbsClientStepMultiReq, KErrUnknown); |
|
280 } |
|
281 break; |
|
282 } |
|
283 } |
|
284 } |
|
285 |
|
286 |
|
287 /** |
|
288 * tidy up everything |
|
289 */ |
|
290 void CT_LbsClientStep_MultiReq::AsyncTidyUp() |
|
291 { |
|
292 if ( iTimer->IsActive() ) |
|
293 { |
|
294 iTimer->Cancel(); |
|
295 } |
|
296 // Cancel any outstanding requests (to be tested): |
|
297 if(iNotifyPosUpdateAO->IsActive()) |
|
298 { |
|
299 iNotifyPosUpdateAO->Cancel(); |
|
300 } |
|
301 if(iGetLastKnownPosAO->IsActive()) |
|
302 { |
|
303 iGetLastKnownPosAO->Cancel(); |
|
304 } |
|
305 CActiveScheduler::Stop(); |
|
306 } |
|
307 |
|
308 |
|
309 /** |
|
310 * Callback function - called if timer fires (requests did not all complete in time) |
|
311 */ |
|
312 static TInt TimerCallback(TAny* aPointer) |
|
313 { |
|
314 //the timer expired and we have not got the responses to our lbs requests |
|
315 static_cast<CT_LbsClientStep_MultiReq*>(aPointer)->INFO_PRINTF1(_L(">>TEST FAILED: timer fired")); |
|
316 static_cast<CT_LbsClientStep_MultiReq*>(aPointer)->AsyncTidyUp(); |
|
317 static_cast<CT_LbsClientStep_MultiReq*>(aPointer)->SetTestStepResult(EFail); |
|
318 |
|
319 return KErrNone; |
|
320 } |
|
321 |
|
322 /** |
|
323 * @return - TVerdict code |
|
324 * Override of base class pure virtual |
|
325 * Our implementation only gets called if the base class doTestStepPreambleL() did |
|
326 * not leave. That being the case, the current test result value will be EPass. |
|
327 */ |
|
328 TVerdict CT_LbsClientStep_MultiReq::doTestStepL() |
|
329 { |
|
330 // Generic test step used to test the LBS Client Notify position update API. |
|
331 INFO_PRINTF1(_L(">>CT_LbsClientStep_MultiReq::doTestStepL()")); |
|
332 |
|
333 if (TestStepResult()==EPass) |
|
334 { |
|
335 // Connect to self locate server. |
|
336 User::LeaveIfError(iServer.Connect()); |
|
337 CleanupClosePushL(iServer); |
|
338 |
|
339 TInt testCaseId; |
|
340 if (GetIntFromConfig(ConfigSection(), KTestCaseId, testCaseId)) |
|
341 { |
|
342 switch (testCaseId) |
|
343 { |
|
344 case 01: // multiple requests of different types |
|
345 { |
|
346 // Open positioner. |
|
347 User::LeaveIfError(iPositioner.Open(iServer)); |
|
348 CleanupClosePushL(iPositioner); |
|
349 |
|
350 // Carry out a notify update to ensure last known cache is filled (note: this blocks!) |
|
351 TPositionInfo notifyPosInfo; |
|
352 User::LeaveIfError(DoNotifyUpdateL(notifyPosInfo)); |
|
353 |
|
354 // Create 2 posinfos and store in our shared array for later verification. |
|
355 RPointerArray<TAny>& posInfoArr = iParent.iSharedData->iCurrentPosInfoArr; |
|
356 TPositionInfo* posInfoLastKnown = new(ELeave) TPositionInfo(); |
|
357 TPositionInfo* posInfoNotifyUpd = new(ELeave) TPositionInfo(); |
|
358 |
|
359 T_LbsUtils utils; |
|
360 utils.ResetAndDestroy_PosInfoArr(posInfoArr); // Clear previous entries before new entry is appended. |
|
361 |
|
362 // these get deleted by the base class destructor |
|
363 posInfoArr.Append(posInfoLastKnown); |
|
364 posInfoArr.Append(posInfoNotifyUpd); |
|
365 |
|
366 // Start GetLastKnownPosition request: |
|
367 iGetLastKnownPosAO = CT_LbsClientGetLastKnownPosAO::NewL(*this); |
|
368 |
|
369 iGetLastKnownPosAO->GetLastKnownPosL(iPositioner, *posInfoLastKnown); |
|
370 |
|
371 // Start NotifyPositionUpdate request: |
|
372 iNotifyPosUpdateAO = CT_LbsClientNotifyPosUpdAO::NewL(*this); |
|
373 |
|
374 iNotifyPosUpdateAO->NotifyPosUpdateL(iPositioner, *posInfoNotifyUpd); |
|
375 |
|
376 // Start a timer to make sure neither of above times out: |
|
377 iTimer = CPeriodic::New(CActive::EPriorityStandard); |
|
378 TCallBack callbackFunction = TCallBack(TimerCallback, this); |
|
379 iTimer->Start( delay10Seconds, 0, callbackFunction); |
|
380 |
|
381 // can start the scheduler now as there are async requests issued |
|
382 CActiveScheduler::Start(); |
|
383 |
|
384 // All requests have now completed (and scheduler stopped) |
|
385 |
|
386 CleanupStack::PopAndDestroy(&iPositioner); |
|
387 } // end case 1 |
|
388 break; |
|
389 |
|
390 case 02: // cancel one of two outstanding requests |
|
391 { |
|
392 TInt expected_error; |
|
393 // For the S60 Loc Server the test will return KErrNone instead of KErrNotFound. |
|
394 if(!GetIntFromConfig(ConfigSection(), KExpected_Error, expected_error)) |
|
395 { |
|
396 expected_error = KErrNotFound; |
|
397 } |
|
398 // Open positioner. |
|
399 User::LeaveIfError(iPositioner.Open(iServer)); |
|
400 CleanupClosePushL(iPositioner); |
|
401 |
|
402 // Create a posinfo and store in our shared array for later verification. |
|
403 RPointerArray<TAny>& posInfoArr = iParent.iSharedData->iCurrentPosInfoArr; |
|
404 TPositionInfo* posInfoNotifyUpd = new(ELeave) TPositionInfo(); |
|
405 |
|
406 T_LbsUtils utils; |
|
407 utils.ResetAndDestroy_PosInfoArr(posInfoArr); // Clear previous entries before new entry is appended. |
|
408 |
|
409 // this gets deleted by the base class destructor: |
|
410 posInfoArr.Append(posInfoNotifyUpd); |
|
411 |
|
412 // Start NotifyPositionUpdate request: |
|
413 iNotifyPosUpdateAO = CT_LbsClientNotifyPosUpdAO::NewL(*this); |
|
414 |
|
415 iNotifyPosUpdateAO->NotifyPosUpdateL(iPositioner, *posInfoNotifyUpd); |
|
416 |
|
417 // Start a GetLastKnownPosition: |
|
418 // don't put in verify array as this may be cancelled: |
|
419 iTempPosInfo = new(ELeave) TPositionInfo(); |
|
420 |
|
421 iGetLastKnownPosAO = CT_LbsClientGetLastKnownPosAO::NewL(*this); |
|
422 |
|
423 iGetLastKnownPosAO->GetLastKnownPosL(iPositioner, *iTempPosInfo); |
|
424 |
|
425 // cancel the last known position. Note that we do this directly, NOT by calling the AO's cancel() |
|
426 // so that the AO's RunL(), and therefore our callback, will be called and we can check the result |
|
427 TInt err; |
|
428 err = iPositioner.CancelRequest(EPositionerGetLastKnownPosition); |
|
429 if(expected_error != err) |
|
430 { |
|
431 SetTestStepResult(EFail); |
|
432 } |
|
433 |
|
434 // Start a timer to make sure neither of above times out: |
|
435 iTimer = CPeriodic::New(CActive::EPriorityStandard); |
|
436 TCallBack callbackFunction = TCallBack(TimerCallback, this); |
|
437 |
|
438 // |
|
439 // |
|
440 // NB - THIS VALUE WAS 10 SEC AND THE TIMER EXPIRED, CAUSING THE TEST |
|
441 // TO FAIL. NEED TO FIND OUT WHY THIS VALUE IS OK BUT THAT ONE WAS NOT. |
|
442 // PUT BACK TEMPORARILY TO GET RID OF REGRESSION FAILURE |
|
443 // |
|
444 iTimer->Start(22000000, 0, callbackFunction); |
|
445 |
|
446 // can start the scheduler now as there are async requests issued |
|
447 CActiveScheduler::Start(); |
|
448 |
|
449 // All requests have now completed |
|
450 |
|
451 CleanupStack::PopAndDestroy(&iPositioner); |
|
452 } |
|
453 break; |
|
454 |
|
455 default: |
|
456 { |
|
457 User::Leave(KErrArgument); |
|
458 } |
|
459 }// end switch |
|
460 }//end if GetIntFromConfig |
|
461 |
|
462 CleanupStack::PopAndDestroy(&iServer); |
|
463 |
|
464 } // end if TestStepResult |
|
465 |
|
466 INFO_PRINTF1(_L("<<CT_LbsClientStep_MultiReq::doTestStepL()")); |
|
467 |
|
468 return TestStepResult(); |
|
469 } |
|
470 |