|
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 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 // |
|
15 |
|
16 |
|
17 |
|
18 // INCLUDES |
|
19 #include "ctlbsclientpostp218.h" |
|
20 #include <EPos_CPosModules.h> |
|
21 #include <EPos_CPosModuleUpdate.h> |
|
22 #include <EPos_CPosModuleIdList.h> |
|
23 #include <LbsSatellite.h> |
|
24 |
|
25 // CONSTANTS |
|
26 const TInt MAX_AGE_TIME = 10000000; // 10 sec |
|
27 const TInt HALF_MAX_AGE_TIME = 5000000; // 5 sec |
|
28 |
|
29 _LIT(KKallesService, "Kalles Service"); |
|
30 |
|
31 // ================= MEMBER FUNCTIONS ======================= |
|
32 |
|
33 // Constructor. |
|
34 CT_LbsClientPosTp218::CT_LbsClientPosTp218(CT_LbsServer& aParent): CT_LbsPortedStepBase(aParent) |
|
35 { |
|
36 _LIT(KTestName, "TP218 - Max Age, default Psy"); |
|
37 SetTestStepName(KTestName); |
|
38 } |
|
39 |
|
40 // --------------------------------------------------------- |
|
41 // Destructor. |
|
42 // --------------------------------------------------------- |
|
43 CT_LbsClientPosTp218::~CT_LbsClientPosTp218() |
|
44 { |
|
45 } |
|
46 |
|
47 // --------------------------------------------------------- |
|
48 // CT_LbsClientPosTp218::CloseTest |
|
49 // |
|
50 // (other items were commented in a header). |
|
51 // --------------------------------------------------------- |
|
52 // |
|
53 void CT_LbsClientPosTp218::CloseTest() |
|
54 { |
|
55 ClosePositioner(); |
|
56 iPositioner1.Close(); |
|
57 iPositioner2.Close(); |
|
58 Disconnect(); |
|
59 } |
|
60 |
|
61 // --------------------------------------------------------- |
|
62 // CT_LbsClientPosTp218::SetupDefaultPsyL |
|
63 // |
|
64 // (other items were commented in a header). |
|
65 // --------------------------------------------------------- |
|
66 // |
|
67 void CT_LbsClientPosTp218::SetupDefaultPsyL(const TUid aPsyUid) |
|
68 { |
|
69 CPosModules* db = CPosModules::OpenL(); |
|
70 CleanupStack::PushL(db); |
|
71 |
|
72 SetupPsyL(aPsyUid); |
|
73 //setting priority |
|
74 TPositionModuleInfo moduleInfoHp;//Hp - high prio; |
|
75 TPositionModuleInfo moduleInfoLp;//Lp - low prio; |
|
76 |
|
77 CPosModuleIdList* prioList = db->ModuleIdListLC(); |
|
78 |
|
79 db->GetModuleInfoL(prioList->At(0), moduleInfoHp); |
|
80 |
|
81 CPosModuleUpdate* moduleUpdate = CPosModuleUpdate::NewLC(); |
|
82 |
|
83 if (aPsyUid.iUid == moduleInfoHp.ModuleId().iUid) |
|
84 { |
|
85 moduleUpdate->SetUpdateAvailability(ETrue); |
|
86 db->UpdateModuleL((*prioList)[0], *moduleUpdate); |
|
87 } |
|
88 else |
|
89 { |
|
90 db->GetModuleInfoL(aPsyUid, moduleInfoLp); |
|
91 db->UpdateModuleL(aPsyUid, *moduleUpdate); |
|
92 TUint hp = db -> PriorityL(moduleInfoHp.ModuleId()); |
|
93 TUint lp = db -> PriorityL(moduleInfoLp.ModuleId()); |
|
94 db->SetModulePriorityL(aPsyUid, hp); //lp |
|
95 db->SetModulePriorityL((*prioList)[0], lp); //hp |
|
96 } |
|
97 |
|
98 moduleUpdate->SetUpdateAvailability(ETrue); |
|
99 db -> UpdateModuleL(aPsyUid, *moduleUpdate); |
|
100 |
|
101 CleanupStack::PopAndDestroy(moduleUpdate); |
|
102 CleanupStack::PopAndDestroy(2); // db, prioList |
|
103 } |
|
104 |
|
105 |
|
106 // This flag must be defined if MaxAge should NOT be tested |
|
107 #ifdef MAX_AGE_NOT_SUPPORTED |
|
108 // --------------------------------------------------------- |
|
109 // CT_LbsClientPosTp218::StartL |
|
110 // |
|
111 // (other items were commented in a header). |
|
112 // --------------------------------------------------------- |
|
113 // |
|
114 // >>>>>>>>>>>>>>>MaxAge NOT supported<<<<<<<<<<<<<<<<<<<<<< |
|
115 void CT_LbsClientPosTp218::StartL() |
|
116 { |
|
117 TTimeIntervalMicroSeconds maxAge = TTimeIntervalMicroSeconds(MAX_AGE_TIME); |
|
118 |
|
119 // Set iUidTestPsyMaxAge to defaultpsy |
|
120 SetupDefaultPsyL(iUidTestPsyMaxAge); |
|
121 |
|
122 //connect to EPos |
|
123 User::LeaveIfError(iPosServer.Connect()); |
|
124 TInt err = KErrNone; |
|
125 TRequestStatus myStatus; |
|
126 |
|
127 // Open default psy |
|
128 User::LeaveIfError(iPositioner.Open(iPosServer)); |
|
129 TBuf<150> buf; |
|
130 |
|
131 SetupGlobalPrivacyL(TPosPrivacy(TPosPrivacy::EAcceptAll, EFalse)); |
|
132 |
|
133 TPositionUpdateOptions posOption; |
|
134 posOption.SetMaxUpdateAge(maxAge); |
|
135 |
|
136 _LIT(KTestMaxAge, "Testing that MaxAge is not supported"); |
|
137 INFO_PRINTF1(KTestMaxAge); |
|
138 err = iPositioner.SetUpdateOptions(posOption); |
|
139 _LIT(KErr, "MaxAge should NOT be supported instead code %d was returned"); |
|
140 AssertTrueL(err == KErrNotSupported, KErr, err); |
|
141 |
|
142 TPositionInfo posInfo1 = TPositionInfo(); |
|
143 TPositionInfo posInfo2 = TPositionInfo(); |
|
144 |
|
145 iPositioner.SetRequestor(CRequestor::ERequestorService, |
|
146 CRequestor::EFormatApplication, KKallesService); |
|
147 |
|
148 // Get position, first position |
|
149 iPositioner.NotifyPositionUpdate(posInfo1, myStatus); |
|
150 |
|
151 User::WaitForRequest(myStatus); |
|
152 |
|
153 err = myStatus.Int(); |
|
154 _LIT(KNotifyPositionUpdate, "Error from NotifyPositionUpdate, err %d"); |
|
155 AssertTrueL(err == KErrNone, KNotifyPositionUpdate, err); |
|
156 |
|
157 _LIT(KWaitMaxAge, "Wait for half Max Age..."); |
|
158 INFO_PRINTF1(KWaitMaxAge); |
|
159 // Wait half MAX_AGE_TIME |
|
160 User::After(HALF_MAX_AGE_TIME); |
|
161 |
|
162 // Get position again, should be the same as first position |
|
163 iPositioner.NotifyPositionUpdate(posInfo2, myStatus); |
|
164 User::WaitForRequest(myStatus); |
|
165 err = myStatus.Int(); |
|
166 AssertTrueL(err == KErrNone, KNotifyPositionUpdate, err); |
|
167 |
|
168 if (ComparePositionL(posInfo1, posInfo2)) |
|
169 { |
|
170 _LIT(KErrorAndLeave, |
|
171 "The old position was returned from positioner, MaxAge seems to be supported!!!"); |
|
172 LogErrorAndLeaveL(KErrorAndLeave); |
|
173 } |
|
174 |
|
175 } |
|
176 |
|
177 #else |
|
178 // --------------------------------------------------------- |
|
179 // CT_LbsClientPosTp218::StartL |
|
180 // |
|
181 // (other items were commented in a header). |
|
182 // --------------------------------------------------------- |
|
183 // |
|
184 // >>>>>>>>>>>>>>>>>>>>MaxAge supported<<<<<<<<<<<<<<<<<<<<<< |
|
185 void CT_LbsClientPosTp218::StartL() |
|
186 { |
|
187 TTimeIntervalMicroSeconds maxAge = TTimeIntervalMicroSeconds(MAX_AGE_TIME); |
|
188 |
|
189 // Set iUidTestPsyMaxAge to defaultpsy |
|
190 SetupDefaultPsyL(iUidTestPsyMaxAge); |
|
191 |
|
192 //connect to EPos |
|
193 User::LeaveIfError(iPosServer.Connect()); |
|
194 TInt err = KErrNone; |
|
195 |
|
196 // Open default psy |
|
197 User::LeaveIfError(iPositioner.Open(iPosServer)); |
|
198 TBuf<150> buf; |
|
199 |
|
200 TPositionInfo posInfo = TPositionInfo(); |
|
201 TPositionInfo posInfo2 = TPositionInfo(); |
|
202 TRequestStatus myStatus; |
|
203 |
|
204 iPositioner.SetRequestor(CRequestor::ERequestorService, |
|
205 CRequestor::EFormatApplication, KKallesService); |
|
206 |
|
207 // Make sure that it is possible to get position from psy |
|
208 iPositioner.NotifyPositionUpdate(posInfo, myStatus); |
|
209 User::WaitForRequest(myStatus); |
|
210 err = myStatus.Int(); |
|
211 _LIT(KNotifyPositionUpdate, "Error from NotifyPositionUpdate, err %d"); |
|
212 AssertTrueL(err == KErrNone, KNotifyPositionUpdate, err); |
|
213 |
|
214 // Make sure that the psy returns differens positions |
|
215 iPositioner.NotifyPositionUpdate(posInfo2, myStatus); |
|
216 User::WaitForRequest(myStatus); |
|
217 err = myStatus.Int(); |
|
218 AssertTrueL(err == KErrNone, KNotifyPositionUpdate, err); |
|
219 |
|
220 |
|
221 TPositionUpdateOptions returnPosOption; |
|
222 iPositioner.GetUpdateOptions(returnPosOption); |
|
223 TTimeIntervalMicroSeconds returnInterval = returnPosOption.MaxUpdateAge(); |
|
224 |
|
225 _LIT(KMaxAge, "Max age should not hold a value"); |
|
226 AssertTrueL(returnInterval == TTimeIntervalMicroSeconds(0), KMaxAge, KErrGeneral); |
|
227 |
|
228 TPositionUpdateOptions posOption; |
|
229 posOption.SetMaxUpdateAge(maxAge); |
|
230 |
|
231 err = iPositioner.SetUpdateOptions(posOption); |
|
232 _LIT(KChange, "Error when setting max age in SetMaxAge, error %d"); |
|
233 AssertTrueL(err == KErrNone, KChange, err); |
|
234 |
|
235 TPositionUpdateOptions returnPosOption2; |
|
236 iPositioner.GetUpdateOptions(returnPosOption2); |
|
237 |
|
238 returnInterval = returnPosOption2.MaxUpdateAge(); |
|
239 _LIT(KMaxAgeNotMatch, "Max age does not match, %d %d "); |
|
240 buf.Format(KMaxAgeNotMatch, returnInterval.Int64(), MAX_AGE_TIME); |
|
241 AssertTrueL(returnInterval == maxAge, buf, KErrGeneral); |
|
242 |
|
243 TPositionInfo posInfo3 = TPositionInfo(); |
|
244 TPositionInfo posInfo4 = TPositionInfo(); |
|
245 TPositionInfo posInfo5 = TPositionInfo(); |
|
246 // Get position, first position |
|
247 iPositioner.NotifyPositionUpdate(posInfo3, myStatus); |
|
248 |
|
249 User::WaitForRequest(myStatus); |
|
250 |
|
251 err = myStatus.Int(); |
|
252 AssertTrueL(err == KErrNone, KNotifyPositionUpdate, err); |
|
253 |
|
254 _LIT(KWaitMAxAge, "Wait for half Max Age..."); |
|
255 INFO_PRINTF1(KWaitMAxAge); |
|
256 // Wait half MAX_AGE_TIME |
|
257 User::After(HALF_MAX_AGE_TIME); |
|
258 |
|
259 // Get position again, should be the same as first position |
|
260 iPositioner.NotifyPositionUpdate(posInfo4, myStatus); |
|
261 User::WaitForRequest(myStatus); |
|
262 err = myStatus.Int(); |
|
263 AssertTrueL(err == KErrNone, KNotifyPositionUpdate, err); |
|
264 |
|
265 if (!ComparePositionL(posInfo3, posInfo4)) |
|
266 { |
|
267 _LIT(KErrorAndLeave, "The old position was not returned from positioner!!!"); |
|
268 LogErrorAndLeaveL(KErrorAndLeave); |
|
269 } |
|
270 |
|
271 // Wait MAX_AGE_TIME |
|
272 _LIT(KWait, "Waiting waiting..."); |
|
273 INFO_PRINTF1(KWait); |
|
274 User::After(MAX_AGE_TIME); |
|
275 |
|
276 // Get position again, should NOT be the same as earlier |
|
277 iPositioner.NotifyPositionUpdate(posInfo5, myStatus); |
|
278 |
|
279 User::WaitForRequest(myStatus); |
|
280 err = myStatus.Int(); |
|
281 AssertTrueL(err == KErrNone, KNotifyPositionUpdate, err); |
|
282 |
|
283 if (ComparePositionL(posInfo4, posInfo5)) |
|
284 { |
|
285 _LIT(KErrorAndLeave, "(1)The old position was returned from positioner!!!"); |
|
286 LogErrorAndLeaveL(KErrorAndLeave); |
|
287 } |
|
288 |
|
289 _LIT(KChangePSY11, "Changing default psy to Psy11"); |
|
290 INFO_PRINTF1(KChangePSY11); |
|
291 // Set iUidTestPsy11 psy to defaultpsy |
|
292 SetupDefaultPsyL(iUidTestPsy11); |
|
293 |
|
294 // Wait some time to make changes occur |
|
295 User::After(5000000); |
|
296 TPositionInfo posInfo6 = TPositionInfo(); |
|
297 TPositionInfo posInfo7 = TPositionInfo(); |
|
298 |
|
299 // Get position again, should NOT be the same as earlier |
|
300 iPositioner.NotifyPositionUpdate(posInfo6, myStatus); |
|
301 |
|
302 User::WaitForRequest(myStatus); |
|
303 err = myStatus.Int(); |
|
304 _LIT(KErr1, "Error from NotifyPositionUpdate for default psy, err1: %d"); |
|
305 AssertTrueL(err == KErrNone, KErr1, err); |
|
306 |
|
307 if (ComparePositionL(posInfo5, posInfo6)) |
|
308 { |
|
309 _LIT(KErrorAndLeave, |
|
310 "(2)The old position was returned from positioner!!!"); |
|
311 LogErrorAndLeaveL(KErrorAndLeave); |
|
312 } |
|
313 |
|
314 // Get position again, should NOT be the same as earlier |
|
315 iPositioner.NotifyPositionUpdate(posInfo7, myStatus); |
|
316 |
|
317 User::WaitForRequest(myStatus); |
|
318 err = myStatus.Int(); |
|
319 // TestPsy11 returns error every second request |
|
320 _LIT(KErr2, "Error from NotifyPositionUpdate for default psy, err2: %d"); |
|
321 AssertTrueL(err == KPositionPartialUpdate, KErr2, err); |
|
322 |
|
323 if (ComparePositionL(posInfo6, posInfo7)) |
|
324 { |
|
325 _LIT(KErrorAndLeave, |
|
326 "The old position was returned from default positioner!!!"); |
|
327 LogErrorAndLeaveL(KErrorAndLeave); |
|
328 } |
|
329 |
|
330 ClosePositioner(); |
|
331 Disconnect(); |
|
332 } |
|
333 |
|
334 #endif |
|
335 |
|
336 // --------------------------------------------------------- |
|
337 // CT_LbsClientPosTp218::ComparePositionL |
|
338 // |
|
339 // (other items were commented in a header). |
|
340 // --------------------------------------------------------- |
|
341 // |
|
342 TBool CT_LbsClientPosTp218::ComparePositionL(TPositionInfo aPosInfo1, TPositionInfo aPosInfo2) |
|
343 { |
|
344 _LIT(KFunctionName, "We are inside ComparePositionL()"); |
|
345 INFO_PRINTF1(KFunctionName); |
|
346 TBool result = ETrue; |
|
347 TBuf<150> buf; |
|
348 |
|
349 TPosition pos1 = TPosition(); |
|
350 TPosition pos2 = TPosition(); |
|
351 aPosInfo1.GetPosition(pos1); |
|
352 aPosInfo2.GetPosition(pos2); |
|
353 |
|
354 TTime time1 = pos1.Time(); |
|
355 TTime time2 = pos2.Time(); |
|
356 |
|
357 if (time1 == time2) |
|
358 { |
|
359 _LIT(KEqualTime, "Equal Time"); |
|
360 INFO_PRINTF1(KEqualTime); |
|
361 } |
|
362 else |
|
363 { |
|
364 _LIT(KNotEqualTime, "NOT Equal Time"); |
|
365 INFO_PRINTF1(KNotEqualTime); |
|
366 } |
|
367 |
|
368 if ((time1 != time2) || (pos1.Latitude() != pos2.Latitude()) || |
|
369 (pos1.Longitude() != pos2.Longitude()) || |
|
370 (pos1.Altitude() != pos2.Altitude()) ) |
|
371 { |
|
372 // Not equal |
|
373 result = EFalse; |
|
374 _LIT(KNotEqual, "Not equal"); |
|
375 INFO_PRINTF1(KNotEqual); |
|
376 _LIT(KPosition1, "Position1: Lat %f Long %f Alt %f"); |
|
377 buf.Format(KPosition1, pos1.Latitude(), pos1.Longitude() ,pos1.Altitude()); |
|
378 INFO_PRINTF1(buf); |
|
379 _LIT(KPosition2, "Position2: Lat %f Long %f Alt %f"); |
|
380 buf.Format(KPosition2, pos2.Latitude(), pos2.Longitude() ,pos2.Altitude()); |
|
381 INFO_PRINTF1(buf); |
|
382 } |
|
383 else |
|
384 { |
|
385 _LIT(KEqual, "Equal"); |
|
386 INFO_PRINTF1(KEqual); |
|
387 result = ETrue; |
|
388 _LIT(KPosition1, "Position1: Lat %f Long %f Alt %f"); |
|
389 buf.Format( KPosition1, pos1.Latitude(), pos1.Longitude() ,pos1.Altitude()); |
|
390 INFO_PRINTF1(buf); |
|
391 } |
|
392 |
|
393 return result; |
|
394 } |
|
395 |
|
396 // --------------------------------------------------------- |
|
397 // CT_LbsClientPosTp218::AssertTrueSecL |
|
398 // |
|
399 // (other items were commented in a header). |
|
400 // --------------------------------------------------------- |
|
401 // |
|
402 void CT_LbsClientPosTp218::AssertTrueL(TBool aCondition, const TDesC& aErrorMsg, TInt aErrorCode) |
|
403 { |
|
404 if (!aCondition) |
|
405 { |
|
406 // LogErrorAndLeave does not leave if KErrNone is error |
|
407 if (aErrorCode == KErrNone) aErrorCode = KErrGeneral; |
|
408 TBuf<100> buf; |
|
409 buf.Format(aErrorMsg, aErrorCode); |
|
410 LogErrorAndLeaveL(buf, aErrorCode); |
|
411 } |
|
412 } |
|
413 |
|
414 |