|
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 // |
|
15 |
|
16 |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include "ctlbsclientpostp203.h" |
|
20 #include "ctlbsrequester.h" |
|
21 #include <lbspositioninfo.h> |
|
22 #include <lbs.h> |
|
23 #include <lbscommon.h> |
|
24 #include <lbsrequestor.h> |
|
25 #include <lbs/epos_cposmodules.h> |
|
26 #include <lbs/epos_cposmoduleupdate.h> |
|
27 |
|
28 // ================= MEMBER FUNCTIONS ======================= |
|
29 |
|
30 // Constructor. |
|
31 CT_LbsClientPosTp203::CT_LbsClientPosTp203(CT_LbsServer& aParent): CT_LbsPortedStepBase(aParent) |
|
32 { |
|
33 _LIT(KTestName, "TP203 - Periodic Update, default psy"); |
|
34 SetTestStepName(KTestName); |
|
35 } |
|
36 |
|
37 // Destructor |
|
38 CT_LbsClientPosTp203::~CT_LbsClientPosTp203() |
|
39 { |
|
40 } |
|
41 |
|
42 // --------------------------------------------------------- |
|
43 // CPosTp203::CloseTest |
|
44 // |
|
45 // (other items were commented in a header). |
|
46 // --------------------------------------------------------- |
|
47 // |
|
48 void CT_LbsClientPosTp203::CloseTest() |
|
49 { |
|
50 delete iPeriodicTimer; |
|
51 iPeriodicTimer = NULL; |
|
52 } |
|
53 |
|
54 // --------------------------------------------------------- |
|
55 // CPosTp203::StartL |
|
56 // |
|
57 // (other items were commented in a header). |
|
58 // --------------------------------------------------------- |
|
59 // |
|
60 void CT_LbsClientPosTp203::StartL() |
|
61 { |
|
62 const TInt KLongErrorInterval = 3000000; |
|
63 |
|
64 #ifdef __WINS__ |
|
65 const TInt KNormalErrorInterval = 1500000; |
|
66 #else |
|
67 const TInt KNormalErrorInterval = 500000; |
|
68 #endif |
|
69 |
|
70 |
|
71 TInt numberOfRuns = 6; |
|
72 TInt normalInterval = 4500000; |
|
73 // Using the same interval as the slow psy (TestPsy3) to make things easy. |
|
74 TTimeIntervalMicroSeconds interval = TTimeIntervalMicroSeconds(normalInterval); |
|
75 TTimeIntervalMicroSeconds shortInterval = TTimeIntervalMicroSeconds(1500000); |
|
76 |
|
77 // Will happen the first time when default is changed |
|
78 //It is required because we change the PSY being in the tracking mode. So, we may have to wait up to |
|
79 //the tracking interval first and then wait a liitle more than the PSY time to fix. |
|
80 TInt longInterval = 8500000; |
|
81 TInt errorInterval = KNormalErrorInterval; |
|
82 |
|
83 TInt requestUpdate = normalInterval; |
|
84 |
|
85 RPositionServer posServer; |
|
86 CleanupClosePushL(posServer); |
|
87 TInt err = posServer.Connect(); |
|
88 _LIT(KConnectErr, "Error when connecing to EPos server, %d"); |
|
89 AssertTrueL(err == KErrNone, KConnectErr, err); |
|
90 |
|
91 SetupPsyL(iUidMultiPsy); |
|
92 |
|
93 RPositioner positioner; |
|
94 CleanupClosePushL(positioner); |
|
95 err = positioner.Open(posServer); // Use Default PSY |
|
96 _LIT(KOpenErr, "Error when opening positioner, %d"); |
|
97 AssertTrueL(err == KErrNone, KOpenErr, err); |
|
98 |
|
99 TPositionInfo positionInfo = TPositionInfo(); |
|
100 TPositionUpdateOptions posOption; |
|
101 posOption.SetUpdateInterval(interval); |
|
102 |
|
103 err = positioner.SetUpdateOptions(posOption); |
|
104 _LIT(KUpdateErr, "Error when setting update interval, %d"); |
|
105 AssertTrueL(err == KErrNone, KUpdateErr, err); |
|
106 |
|
107 _LIT(KService ,"Service"); |
|
108 positioner.SetRequestor(CRequestor::ERequestorService, |
|
109 CRequestor::EFormatApplication, KService); |
|
110 |
|
111 // Do a couple of request and check the times between requests. |
|
112 TTime now, startTime; |
|
113 TTimeIntervalMicroSeconds requestTime; |
|
114 _LIT(KErrorRequest, "Error in request"); |
|
115 TRequestStatus status; |
|
116 TInt64 reqTime; |
|
117 |
|
118 for (TInt i = 0; i < numberOfRuns; i++) |
|
119 { |
|
120 TBuf<100> info; |
|
121 _LIT(KInfo, "Making request %d"); |
|
122 info.Format(KInfo, i); |
|
123 INFO_PRINTF1(info); |
|
124 if (i == 2) |
|
125 { |
|
126 _LIT(KSetTestPSY3, "Setting up TestPsy3"); |
|
127 INFO_PRINTF1(KSetTestPSY3); |
|
128 SetupPsyL(iUidTestPsy3); |
|
129 User::After(1000000); |
|
130 requestUpdate = longInterval; |
|
131 errorInterval = KLongErrorInterval; |
|
132 } |
|
133 else |
|
134 { |
|
135 requestUpdate = normalInterval; |
|
136 errorInterval = KNormalErrorInterval; |
|
137 } |
|
138 |
|
139 _LIT(KWaitStatus1, "Waiting for status after NotifyPositionUpdate1"); |
|
140 INFO_PRINTF1(KWaitStatus1); |
|
141 |
|
142 startTime.UniversalTime(); |
|
143 positioner.NotifyPositionUpdate(positionInfo, status); |
|
144 User::WaitForRequest(status); |
|
145 now.UniversalTime(); |
|
146 |
|
147 err = status.Int(); |
|
148 AssertTrueL(err == KErrNone, KErrorRequest, err); |
|
149 |
|
150 requestTime = now.MicroSecondsFrom(startTime); |
|
151 _LIT(KError, "Request time, %d microsecs."); |
|
152 TBuf<100> buf; |
|
153 reqTime = requestTime.Int64(); |
|
154 buf.Format(KError, reqTime); |
|
155 INFO_PRINTF1(buf); |
|
156 |
|
157 if (i != 0) |
|
158 { |
|
159 // Check that the time is ok, by accepting an error interval |
|
160 if (reqTime > (requestUpdate + errorInterval) || |
|
161 reqTime < (normalInterval - errorInterval)) |
|
162 { |
|
163 _LIT(KErrorInterval, "The update is not within valid range"); |
|
164 LogErrorAndLeaveL(KErrorInterval); |
|
165 } |
|
166 } |
|
167 |
|
168 // Check that position was returned from correct PSY: |
|
169 if (i < 2) |
|
170 { |
|
171 VerifyPositionFromL(positionInfo, iUidMultiPsy); |
|
172 } |
|
173 else |
|
174 { |
|
175 VerifyPositionFromL(positionInfo, iUidTestPsy3); |
|
176 } |
|
177 } |
|
178 |
|
179 _LIT(KSetUpdateOptions, "Calling SetUpdateOptions"); |
|
180 INFO_PRINTF1(KSetUpdateOptions); |
|
181 posOption.SetUpdateInterval(shortInterval); |
|
182 err = positioner.SetUpdateOptions(posOption); |
|
183 AssertTrueL(err == KErrNone, KUpdateErr, err); |
|
184 |
|
185 // Set up three PSYs the two onces with top priorities supports tracking |
|
186 // and the third one does not |
|
187 CPosModules* db = CPosModules::OpenL(); |
|
188 CleanupStack::PushL(db); |
|
189 CPosModuleUpdate* moduleUpdate = CPosModuleUpdate::NewLC(); |
|
190 |
|
191 _LIT(KSetPriority0, "Enabling Tracking PSY with priority 0"); |
|
192 INFO_PRINTF1(KSetPriority0); |
|
193 moduleUpdate->SetUpdateAvailability(ETrue); |
|
194 User::After(1000000); |
|
195 |
|
196 db->UpdateModuleL(iUidTestTrackingPsy, *moduleUpdate); |
|
197 db->SetModulePriorityL(iUidTestTrackingPsy, 0); |
|
198 User::After(1000000); |
|
199 |
|
200 |
|
201 |
|
202 _LIT(KSetPriority1, "Enabling Timer PSY with priority 1"); |
|
203 /*INFO_PRINTF1(KSetPriority1); |
|
204 db->UpdateModuleL(iUidTestTimerPsy, *moduleUpdate); |
|
205 db -> SetModulePriorityL(iUidTestTimerPsy, 1); |
|
206 User::After(1000000);*/ |
|
207 |
|
208 _LIT(KSetPriority2, "Enabling Multi PSY with priority 2"); |
|
209 /*INFO_PRINTF1(KSetPriority2); |
|
210 db->UpdateModuleL(iUidMultiPsy, *moduleUpdate); |
|
211 db -> SetModulePriorityL(iUidMultiPsy, 2); |
|
212 User::After(1000000); // just to let the events happen in the server.*/ |
|
213 |
|
214 |
|
215 // Make one request to ensure that Start tracking is called. |
|
216 positioner.NotifyPositionUpdate(positionInfo, status); |
|
217 _LIT(KWaitStatus2, "Waiting for status after NotifyPositionUpdate2"); |
|
218 INFO_PRINTF1(KWaitStatus2); |
|
219 User::WaitForRequest(status); |
|
220 err = status.Int(); |
|
221 AssertTrueL(err == KErrNone || err == KPositionQualityLoss, KErrorRequest, err); |
|
222 |
|
223 TPosition pos; |
|
224 positionInfo.GetPosition(pos); |
|
225 User::After(1000000); |
|
226 |
|
227 // TestTrackingPsy returns 65.0 for Tracking requests and 30.0 for ordinary position requests |
|
228 _LIT(KErrorAndLeave, "Wrong position returned from tracking PSY"); |
|
229 if (pos.Latitude() != 65.0 || pos.Longitude() != 65.0 || pos.Altitude() != 65.0) |
|
230 { |
|
231 LogErrorAndLeaveL(KErrorAndLeave); |
|
232 } |
|
233 |
|
234 INFO_PRINTF1(KSetPriority1); |
|
235 db->UpdateModuleL(iUidTestTimerPsy, *moduleUpdate); |
|
236 db -> SetModulePriorityL(iUidTestTimerPsy, 1); |
|
237 User::After(2000000); // MH move |
|
238 |
|
239 // Disable the psy with top priority, should result in switch of psy |
|
240 _LIT(KDisablePSY, "Disabling Tracking PSY"); |
|
241 INFO_PRINTF1(KDisablePSY); |
|
242 moduleUpdate->SetUpdateAvailability(EFalse); |
|
243 db->UpdateModuleL(iUidTestTrackingPsy, *moduleUpdate); |
|
244 // To let the events happen in the server. |
|
245 User::After(2000000); |
|
246 |
|
247 // Make one request to enable tracking |
|
248 positioner.NotifyPositionUpdate(positionInfo, status); |
|
249 _LIT(KWaitStatus4, "Waiting for status after NotifyPositionUpdate4"); |
|
250 INFO_PRINTF1(KWaitStatus4); |
|
251 User::WaitForRequest(status); |
|
252 err = status.Int(); |
|
253 AssertTrueL(err == KErrNone || err == KPositionQualityLoss, KErrorRequest, err); |
|
254 |
|
255 positionInfo.GetPosition(pos); |
|
256 |
|
257 // To let the events happen in the server. |
|
258 User::After(2000000); |
|
259 |
|
260 // TestTimerPsy returns 55.0 for Tracking requests and 20.0 for ordinary position requests |
|
261 if (pos.Latitude() != 55.0 || pos.Longitude() != 55.0 || pos.Altitude() != 55.0) |
|
262 { |
|
263 LogErrorAndLeaveL(KErrorAndLeave); |
|
264 } |
|
265 |
|
266 // Enable the psy with top priority, should result in switch back to that psy |
|
267 _LIT(KEnablePSY, "Enabling tracking PSY"); |
|
268 INFO_PRINTF1(KEnablePSY); |
|
269 moduleUpdate->SetUpdateAvailability(ETrue); |
|
270 db->UpdateModuleL(iUidTestTrackingPsy, *moduleUpdate); |
|
271 User::After(2000000); // just to let the events happen in the server. |
|
272 |
|
273 // To enable tracking |
|
274 positioner.NotifyPositionUpdate(positionInfo, status); |
|
275 _LIT(KWaitStatus6, "Waiting for status after NotifyPositionUpdate6"); |
|
276 INFO_PRINTF1(KWaitStatus6); |
|
277 User::WaitForRequest(status); |
|
278 err = status.Int(); |
|
279 AssertTrueL(err == KErrNone || err == KPositionQualityLoss, KErrorRequest, err); |
|
280 |
|
281 // To let the events happen in the server. |
|
282 User::After(2000000); |
|
283 |
|
284 positionInfo.GetPosition(pos); |
|
285 // TestTrackingPsy returns 65.0 for Tracking requests and 30.0 for ordinary position requests |
|
286 if (pos.Latitude() != 65.0 || pos.Longitude() != 65.0 || pos.Altitude() != 65.0) |
|
287 { |
|
288 LogErrorAndLeaveL(KErrorAndLeave); |
|
289 } |
|
290 |
|
291 INFO_PRINTF1(KSetPriority2); |
|
292 db->UpdateModuleL(iUidMultiPsy, *moduleUpdate); |
|
293 db -> SetModulePriorityL(iUidMultiPsy, 2); |
|
294 // To let the events happen in the server. //MH |
|
295 User::After(1000000); |
|
296 |
|
297 // Disable two psys with top priority that supports tracking. |
|
298 _LIT(KDisableTimer,"Disabling Timer and Tracking PSY"); |
|
299 INFO_PRINTF1(KDisableTimer); |
|
300 moduleUpdate->SetUpdateAvailability(EFalse); |
|
301 db->UpdateModuleL(iUidTestTimerPsy, *moduleUpdate); |
|
302 db->UpdateModuleL(iUidTestTrackingPsy, *moduleUpdate); |
|
303 User::After(2000000); // just to let the events happen in the server. |
|
304 |
|
305 positioner.NotifyPositionUpdate(positionInfo, status); |
|
306 _LIT(KWaitStatus8, "Waiting for status after NotifyPositionUpdate8"); |
|
307 INFO_PRINTF1(KWaitStatus8); |
|
308 User::WaitForRequest(status); |
|
309 err = status.Int(); |
|
310 AssertTrueL(err == KErrNone, KErrorRequest, err); |
|
311 |
|
312 if (iUidMultiPsy.iUid != positionInfo.ModuleId().iUid) |
|
313 { |
|
314 _LIT(KIncorrectPsyError, |
|
315 "Position from wrong PSY received"); |
|
316 LogErrorAndLeaveL(KIncorrectPsyError); |
|
317 } |
|
318 |
|
319 // Disable a PSY during ongoing requesting |
|
320 // Enable the the top three PSYs |
|
321 _LIT(KEnableTimer,"Enabling Timer PSY"); |
|
322 INFO_PRINTF1(KEnableTimer); |
|
323 moduleUpdate->SetUpdateAvailability(ETrue); |
|
324 db->UpdateModuleL(iUidTestTimerPsy, *moduleUpdate); |
|
325 db->UpdateModuleL(iUidTestTrackingPsy, *moduleUpdate); |
|
326 moduleUpdate->SetUpdateAvailability(EFalse); |
|
327 db->UpdateModuleL(iUidMultiPsy, *moduleUpdate); |
|
328 // To let the events happen in the server. |
|
329 User::After(2000000); |
|
330 |
|
331 const TInt KRequestInterval = 4000000; |
|
332 TCallBack callback(DisablePsyL, this); |
|
333 iPeriodicTimer = CPeriodic::NewL(CActive::EPriorityStandard); |
|
334 TTimeIntervalMicroSeconds32 disableTime = TTimeIntervalMicroSeconds32(2000000); |
|
335 iPeriodicTimer->Start(disableTime, disableTime, callback); |
|
336 CT_LbsRequester* request = CT_LbsRequester::NewL(this, KRequestInterval, Logger()); // TTF = 0s |
|
337 CleanupStack::PushL(request); |
|
338 |
|
339 // To enable tracking |
|
340 _LIT(KRequest1, "Calling request->StartRequest1"); |
|
341 INFO_PRINTF1(KRequest1); |
|
342 request->StartRequest(); // only one request should exist |
|
343 |
|
344 CActiveScheduler::Start(); |
|
345 |
|
346 err = request ->CompletionCode(); |
|
347 _LIT(KErrCode, "Competion code is not KErrNone"); |
|
348 AssertTrueL(err == KErrNone, KErrCode, err); |
|
349 |
|
350 request->GetPositionInfo(positionInfo); |
|
351 User::After(2000000); |
|
352 |
|
353 // Should get tracking data |
|
354 _LIT(KRequest2, "Calling request->StartRequest2"); |
|
355 INFO_PRINTF1(KRequest2); |
|
356 request->StartRequest(); // only one request should exist in reqlog |
|
357 |
|
358 CActiveScheduler::Start(); |
|
359 |
|
360 err = request ->CompletionCode(); |
|
361 AssertTrueL(err == KErrNone, KErrCode, err); |
|
362 |
|
363 request ->GetPositionInfo(positionInfo); |
|
364 positionInfo.GetPosition(pos); |
|
365 |
|
366 if (iUidTestTimerPsy.iUid != positionInfo.ModuleId().iUid) |
|
367 { |
|
368 _LIT(KIncorrectPsyError, |
|
369 "Position from wrong PSY received"); |
|
370 LogErrorAndLeaveL(KIncorrectPsyError); |
|
371 } |
|
372 // TestTimerPsy returns 55.0 for Tracking requests and 20.0 for ordinary position requests |
|
373 if (pos.Latitude() != 55.0 || pos.Longitude() != 55.0 || pos.Altitude() != 55.0) |
|
374 { |
|
375 LogErrorAndLeaveL(KErrorAndLeave); |
|
376 } |
|
377 |
|
378 _LIT(KSetPSY, "Setting up Tracking PSY"); |
|
379 INFO_PRINTF1(KSetPSY); |
|
380 SetupPsyL(iUidTestTrackingPsy); |
|
381 User::After(1500000); // just to let the events happen in the server. |
|
382 |
|
383 CT_LbsRequester* request2 = CT_LbsRequester::NewL(this, interval, Logger()); // TTF = 0s |
|
384 CleanupStack::PushL(request2); |
|
385 |
|
386 iPeriodicTimer->Start(disableTime, disableTime, callback); |
|
387 _LIT(KRequest3, "Calling request2->StartRequest"); |
|
388 INFO_PRINTF1(KRequest3); |
|
389 request2->StartRequest(); // only one request should exist in reqlog |
|
390 |
|
391 CActiveScheduler::Start(); |
|
392 |
|
393 err = request2 ->CompletionCode(); |
|
394 _LIT(KErrNotFoundCode, "Competion code is not KErrNone"); |
|
395 AssertTrueL(err == KErrNone, KErrNotFoundCode, err); |
|
396 |
|
397 CleanupStack::PopAndDestroy(request2); |
|
398 CleanupStack::PopAndDestroy(request); |
|
399 CleanupStack::PopAndDestroy(moduleUpdate); |
|
400 CleanupStack::PopAndDestroy(db); |
|
401 |
|
402 CleanupStack::PopAndDestroy(&positioner); |
|
403 CleanupStack::PopAndDestroy(&posServer); |
|
404 } |
|
405 |
|
406 TInt CT_LbsClientPosTp203::DisablePsyL(TAny* aSelf) |
|
407 { |
|
408 // Do not forget to cancel the timer |
|
409 CT_LbsClientPosTp203* self = static_cast<CT_LbsClientPosTp203*> (aSelf); |
|
410 self -> iPeriodicTimer -> Cancel(); |
|
411 CPosModules* db = CPosModules::OpenL(); |
|
412 CleanupStack::PushL(db); |
|
413 CPosModuleUpdate* moduleUpdate = CPosModuleUpdate::NewLC(); |
|
414 moduleUpdate->SetUpdateAvailability(EFalse); |
|
415 TUid trackingId; |
|
416 trackingId.iUid = KUidTestTrackingPsy; |
|
417 db->UpdateModuleL(trackingId, *moduleUpdate); |
|
418 CleanupStack::PopAndDestroy(moduleUpdate); |
|
419 CleanupStack::PopAndDestroy(db); |
|
420 return KErrNone; |
|
421 } |
|
422 |
|
423 void CT_LbsClientPosTp203::RequestCompleteL() |
|
424 { |
|
425 CActiveScheduler::Stop(); |
|
426 } |
|
427 |
|
428 // End of File |