|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "ctlbssimulationpsypostp600.h" |
|
20 #include "simulationpsyinternalcrkeys.h" |
|
21 |
|
22 const TInt KTrackingError = 2000000; // 2 seconds |
|
23 const TTimeIntervalMicroSeconds KClient1Interval(5000000); // 5 seconds |
|
24 const TTimeIntervalMicroSeconds KClient2Interval(10000000); // 10 seconds |
|
25 |
|
26 // Number of tests in this file. Increment when a new test is added. |
|
27 const TInt KNrOfTests = 4; |
|
28 |
|
29 _LIT(KName0, "TP600-0 - SPS Tracking (Independent Data Set)"); |
|
30 _LIT(KName1, "TP600-1 - NMEA Tracking (Common Data Set)"); |
|
31 _LIT(KName2, "TP600-2 - SPS Tracking (Independent Data Set)"); |
|
32 _LIT(KName3, "TP600-3 - NMEA Tracking (Common Data Set)"); |
|
33 |
|
34 // Data files |
|
35 #ifdef __WINS__ |
|
36 _LIT(KSimulationSource, "z:\\system\\test\\testdata\\simulationMoveNoError.sps"); |
|
37 _LIT(KMagellanTracker, "z:\\system\\test\\testdata\\MagellanTracker.nme"); |
|
38 #else |
|
39 _LIT(KSimulationSource, "c:\\system\\test\\testdata\\simulationMoveNoError.sps"); |
|
40 _LIT(KMagellanTracker, "c:\\system\\test\\testdata\\MagellanTracker.nme"); |
|
41 #endif |
|
42 |
|
43 _LIT(KService, "service"); |
|
44 |
|
45 CT_LbsSimulationPsyPosTp600::CT_LbsSimulationPsyPosTp600(CT_LbsServer& aParent, TInt aIndex) : |
|
46 CT_LbsPortedStepBase(aParent) |
|
47 { |
|
48 iIndex = aIndex; |
|
49 } |
|
50 |
|
51 void CT_LbsSimulationPsyPosTp600::StartL() |
|
52 { |
|
53 // Setup test environment |
|
54 SetTestStepName(GetIndexNameL(iIndex)); |
|
55 iNrOfRequests = 0; |
|
56 ConnectL(); |
|
57 SetupPsyL(iUidSimulationPsy); |
|
58 RunTestsL(iIndex); |
|
59 } |
|
60 |
|
61 /* |
|
62 * From CT_LbsPortedStepBase |
|
63 * Cleans up after a test. |
|
64 * Always called, even if the test leaves. |
|
65 */ |
|
66 void CT_LbsSimulationPsyPosTp600::CloseTest() |
|
67 { |
|
68 ClosePositioner(); |
|
69 Disconnect(); |
|
70 } |
|
71 |
|
72 TVerdict CT_LbsSimulationPsyPosTp600::doTestStepPostambleL() |
|
73 { |
|
74 SetCommonDataSetL(iOldTrpMode); |
|
75 return CT_LbsPortedStepBase::doTestStepPostambleL(); |
|
76 } |
|
77 |
|
78 /* |
|
79 * Gets the name of an individual test index |
|
80 * @param aIndex Indicates which test index name that is asked for. |
|
81 */ |
|
82 TPtrC CT_LbsSimulationPsyPosTp600::GetIndexNameL(TInt aIndex) const |
|
83 { |
|
84 ASSERT(aIndex < KNrOfTests); |
|
85 const TDesC* names[KNrOfTests] = |
|
86 { |
|
87 &KName0, &KName1, &KName2, &KName3 |
|
88 }; |
|
89 return *names[aIndex]; |
|
90 } |
|
91 |
|
92 /* |
|
93 * Contains calls to tests itself. |
|
94 * @param aIndex test number |
|
95 */ |
|
96 void CT_LbsSimulationPsyPosTp600::RunTestsL(TInt aIndex) |
|
97 { |
|
98 GetCommonDataSetL(iOldTrpMode); |
|
99 switch (aIndex) |
|
100 { |
|
101 case 0: |
|
102 RunTestL(KSimulationSource, EFalse, &CT_LbsSimulationPsyPosTp600::CheckSPSTrackingWithIndependentDataSetL); |
|
103 break; |
|
104 case 1: |
|
105 RunTestL(KMagellanTracker, EFalse, &CT_LbsSimulationPsyPosTp600::CheckNMEATrackingWithIndependentDataSetL); |
|
106 break; |
|
107 case 2: |
|
108 RunTestL(KSimulationSource, ETrue, &CT_LbsSimulationPsyPosTp600::CheckSPSTrackingWithCommonDataSetL); |
|
109 break; |
|
110 case 3: |
|
111 RunTestL(KMagellanTracker, ETrue, &CT_LbsSimulationPsyPosTp600::CheckNMEATrackingWithCommonDataSetL); |
|
112 break; |
|
113 |
|
114 default: |
|
115 User::Leave(KErrArgument); |
|
116 } |
|
117 } |
|
118 |
|
119 |
|
120 void CT_LbsSimulationPsyPosTp600::CheckSPSTrackingWithIndependentDataSetL( |
|
121 const TPositionRequest& aRequest1, |
|
122 const TPositionRequest& aRequest2, |
|
123 const TTime& aTimeCompleted, |
|
124 TInt aIndex) |
|
125 { |
|
126 TReal trackErr = 0.5; // possible tracking error |
|
127 _LIT(KDistanceError, "Client 2 is further from the starting position than client 1."); |
|
128 |
|
129 CheckRequestTimeL(aRequest1.iStatus, aTimeCompleted.Int64() - aRequest1.iRequestTime.Int64(), aIndex == 0, KClient1Interval.Int64()); |
|
130 CheckRequestTimeL(aRequest2.iStatus, aTimeCompleted.Int64() - aRequest2.iRequestTime.Int64(), aIndex == 1, KClient2Interval.Int64()); |
|
131 |
|
132 // If client 1 returned a position, it should be further than client 2's last position |
|
133 if (aRequest1.iStatus != KRequestPending) |
|
134 { |
|
135 TReal32 distance1; |
|
136 TReal32 distance2; |
|
137 |
|
138 GetDistanceL(aRequest1, distance1); |
|
139 GetDistanceL(aRequest2, distance2); |
|
140 |
|
141 if (distance1+trackErr < distance2) |
|
142 { |
|
143 INFO_PRINTF3(_L("FAILED distance1 = %f; distance2 = %f;"), distance1, distance2); |
|
144 LogErrorAndLeaveL(KDistanceError); |
|
145 } |
|
146 } |
|
147 } |
|
148 |
|
149 void CT_LbsSimulationPsyPosTp600::CheckNMEATrackingWithIndependentDataSetL( |
|
150 const TPositionRequest& aRequest1, |
|
151 const TPositionRequest& aRequest2, |
|
152 const TTime& aTimeCompleted, |
|
153 TInt aIndex) |
|
154 { |
|
155 CheckRequestTimeL(aRequest1.iStatus, aTimeCompleted.Int64() - aRequest1.iRequestTime.Int64(), aIndex == 0, KClient1Interval.Int64()); |
|
156 CheckRequestTimeL(aRequest2.iStatus, aTimeCompleted.Int64() - aRequest2.iRequestTime.Int64(), aIndex == 1, KClient2Interval.Int64()); |
|
157 |
|
158 const TCoordinate KFixes[] = |
|
159 { |
|
160 TCoordinate(61.4470216666667, 23.8645783333333), |
|
161 TCoordinate(61.4470350000000, 23.8645616666667), |
|
162 TCoordinate(61.4470383333333, 23.8645566666667), |
|
163 TCoordinate(61.4470666666667, 23.8645750000000), |
|
164 TCoordinate(61.4470855555556, 23.8645866666667), |
|
165 TCoordinate(61.4470916666667, 23.8645650000000), |
|
166 TCoordinate(61.4470950000000, 23.8645683333333) |
|
167 }; |
|
168 |
|
169 // Client 1 should receive every fix from the file |
|
170 if (aRequest1.iStatus != KRequestPending) |
|
171 { |
|
172 static TInt numFixes; |
|
173 CheckNthFixL(aRequest1.iPositionInfo, KFixes, numFixes++); |
|
174 } |
|
175 |
|
176 // Client 2 should receive every fix from the file |
|
177 if (aRequest2.iStatus != KRequestPending) |
|
178 { |
|
179 static TInt numFixes; |
|
180 CheckNthFixL(aRequest2.iPositionInfo, KFixes, numFixes++); |
|
181 } |
|
182 } |
|
183 |
|
184 void CT_LbsSimulationPsyPosTp600::CheckSPSTrackingWithCommonDataSetL( |
|
185 const TPositionRequest& aRequest1, |
|
186 const TPositionRequest& aRequest2, |
|
187 const TTime& aTimeCompleted, |
|
188 TInt aIndex) |
|
189 { |
|
190 _LIT(KDistanceError1, "Client 1 should be further from the start than Client 2."); |
|
191 _LIT(KDistanceError2, "Client 2 should be further from the start than Client 1."); |
|
192 |
|
193 CheckRequestTimeL(aRequest1.iStatus, aTimeCompleted.Int64() - aRequest1.iRequestTime.Int64(), aIndex == 0, KClient1Interval.Int64()); |
|
194 CheckRequestTimeL(aRequest2.iStatus, aTimeCompleted.Int64() - aRequest2.iRequestTime.Int64(), aIndex == 1, KClient2Interval.Int64()); |
|
195 |
|
196 TReal32 distance1; |
|
197 TReal32 distance2; |
|
198 |
|
199 GetDistanceL(aRequest1, distance1); |
|
200 GetDistanceL(aRequest2, distance2); |
|
201 |
|
202 // If client 1 returned a position, it should be further than client 2's last position |
|
203 if (aRequest1.iStatus != KRequestPending |
|
204 && distance1 < distance2) |
|
205 { |
|
206 LogErrorAndLeaveL(KDistanceError1); |
|
207 } |
|
208 |
|
209 // If client 2 returned a position, it should be further than client 1's last position |
|
210 if (aRequest2.iStatus != KRequestPending |
|
211 && distance2 < distance1) |
|
212 { |
|
213 LogErrorAndLeaveL(KDistanceError2); |
|
214 } |
|
215 } |
|
216 |
|
217 void CT_LbsSimulationPsyPosTp600::CheckNMEATrackingWithCommonDataSetL( |
|
218 const TPositionRequest& aRequest1, |
|
219 const TPositionRequest& aRequest2, |
|
220 const TTime& aTimeCompleted, |
|
221 TInt aIndex) |
|
222 { |
|
223 _LIT(KErrIncorrectFix, "Retrieved fixes are not the same."); |
|
224 |
|
225 CheckRequestTimeL(aRequest1.iStatus, aTimeCompleted.Int64() - aRequest1.iRequestTime.Int64(), aIndex == 0, KClient1Interval.Int64()); |
|
226 CheckRequestTimeL(aRequest2.iStatus, aTimeCompleted.Int64() - aRequest2.iRequestTime.Int64(), aIndex == 1, KClient2Interval.Int64()); |
|
227 |
|
228 if (aIndex > 0) |
|
229 { |
|
230 TPosition pos; |
|
231 TPosition pos2; |
|
232 TReal32 distance; |
|
233 if ( aRequest1.iStatus != KRequestPending && aRequest2.iStatus != KRequestPending ) |
|
234 { |
|
235 aRequest1.iPositionInfo.GetPosition(pos); |
|
236 aRequest2.iPositionInfo.GetPosition(pos2); |
|
237 pos.Distance(pos2, distance); |
|
238 if (distance != 0) |
|
239 { |
|
240 LogErrorAndLeaveL(KErrIncorrectFix); |
|
241 } |
|
242 } |
|
243 } |
|
244 } |
|
245 |
|
246 void CT_LbsSimulationPsyPosTp600::RunTestL(const TDesC& aDataFile, TBool aTrp, TCompareFunction aCheckL) |
|
247 { |
|
248 SetSimDataFileL(aDataFile); |
|
249 SetCommonDataSetL(aTrp); |
|
250 |
|
251 RPositioner secondPositioner; |
|
252 OpenPositionersLC(secondPositioner); |
|
253 |
|
254 // Set client 1 to track every 5 seconds |
|
255 TPositionUpdateOptions options(KClient1Interval); |
|
256 iPositioner.SetUpdateOptions(options); |
|
257 |
|
258 // Set client 2 to track every 10 seconds |
|
259 TPositionUpdateOptions options2(KClient2Interval); |
|
260 secondPositioner.SetUpdateOptions(options2); |
|
261 |
|
262 TTime initialTime; |
|
263 initialTime.UniversalTime(); |
|
264 |
|
265 { |
|
266 TPositionRequest request1(iPositioner); |
|
267 TPositionRequest request2(secondPositioner); |
|
268 |
|
269 for (TInt i = 0; i < 10; i++) |
|
270 { |
|
271 request1.MakeRequestL(); |
|
272 request2.MakeRequestL(); |
|
273 |
|
274 User::WaitForRequest(request1.iStatus, request2.iStatus); |
|
275 |
|
276 TTime timeAfterRequest; |
|
277 timeAfterRequest.UniversalTime(); |
|
278 |
|
279 // Check that requested positions meet test criteria |
|
280 (*this.*aCheckL)(request1, request2, timeAfterRequest, i); |
|
281 } |
|
282 } |
|
283 |
|
284 CleanupStack::PopAndDestroy(&secondPositioner); |
|
285 } |
|
286 |
|
287 void CT_LbsSimulationPsyPosTp600::CheckNthFixL(const TPositionInfo& aPosInfo, const TCoordinate* aFixes, TInt aIndex) |
|
288 { |
|
289 _LIT(KErrIncorrectFix, "Retrieved fix more than 1 metre away from fix in data file."); |
|
290 |
|
291 TPosition pos; |
|
292 aPosInfo.GetPosition(pos); |
|
293 |
|
294 TReal32 distance; |
|
295 pos.Distance(aFixes[aIndex], distance); |
|
296 if (distance >= 1) |
|
297 { |
|
298 LogErrorAndLeaveL(KErrIncorrectFix); |
|
299 } |
|
300 } |
|
301 |
|
302 void CT_LbsSimulationPsyPosTp600::GetDistanceL(const TRequestStatus& aStatus, const TPositionInfo& aPosInfo, TReal32& aDistance) |
|
303 { |
|
304 const TCoordinate KStartingPosition(78.3385, 56.3385); |
|
305 |
|
306 if (aStatus != KRequestPending) |
|
307 { |
|
308 TPosition pos; |
|
309 aPosInfo.GetPosition(pos); |
|
310 pos.Distance(KStartingPosition, aDistance); |
|
311 } |
|
312 } |
|
313 |
|
314 void CT_LbsSimulationPsyPosTp600::GetDistanceL(const TPositionRequest& aRequest, TReal32& aDistance) |
|
315 { |
|
316 GetDistanceL(aRequest.iStatus, aRequest.iPositionInfo, aDistance); |
|
317 } |
|
318 |
|
319 |
|
320 void CT_LbsSimulationPsyPosTp600::CheckRequestTimeL(const TRequestStatus& aStatus, TInt aDelta, TBool aFirst, TInt aExpected) |
|
321 { |
|
322 _LIT(KError, "Tracking time incorrect"); |
|
323 if (aStatus != KRequestPending && |
|
324 !aFirst && |
|
325 (aDelta > aExpected + KTrackingError)) |
|
326 { |
|
327 LogErrorAndLeaveL(KError); |
|
328 } |
|
329 } |
|
330 |
|
331 /* |
|
332 * The method sets new Data Mode value and stores it in central repository. |
|
333 * @param aCommonDataSet value to be set in central repository. |
|
334 */ |
|
335 void CT_LbsSimulationPsyPosTp600::SetCommonDataSetL(const TBool aCommonDataSet) const |
|
336 { |
|
337 TInt commonDataSet; |
|
338 if (aCommonDataSet) |
|
339 { |
|
340 commonDataSet = 1; // Common Data Set is enabled |
|
341 } |
|
342 else |
|
343 { |
|
344 commonDataSet = 0; |
|
345 } |
|
346 // Set Common Data Set behaviour in the Central Repository |
|
347 CRepository* repository = CRepository::NewLC(KCRUidSimulationPSY); |
|
348 User::LeaveIfError(repository-> Set(KCRKeySimPSYCommonDataSet, |
|
349 commonDataSet)); |
|
350 CleanupStack::PopAndDestroy(repository); |
|
351 } |
|
352 |
|
353 /* |
|
354 * The method gets Data Mote value from central repository. |
|
355 * @param aCommonDataSet value read from central repository. |
|
356 */ |
|
357 void CT_LbsSimulationPsyPosTp600::GetCommonDataSetL(TInt& aTrpMode) const |
|
358 { |
|
359 // Get the Common Data Set setting from Central Repository |
|
360 CRepository* repository = CRepository::NewLC(KCRUidSimulationPSY); |
|
361 User::LeaveIfError(repository->Get(KCRKeySimPSYCommonDataSet, aTrpMode)); |
|
362 CleanupStack::PopAndDestroy(repository); |
|
363 } |
|
364 |
|
365 /* |
|
366 * The method opens two positioners. First (iPositioner) one is taken from the base class. |
|
367 * They are expected to be constructed but not opened. |
|
368 * @param aPositioner additional positioner which needs to be opened. Requestor is set for it. |
|
369 * CleanupClosePushL() is used to push aPositioner onto the cleanup stack. |
|
370 */ |
|
371 void CT_LbsSimulationPsyPosTp600::OpenPositionersLC(RPositioner& aPositioner) |
|
372 { |
|
373 TInt err; |
|
374 |
|
375 INFO_PRINTF1(_L("Opening first positioner")); |
|
376 User::LeaveIfError(OpenPositionerByName(iUidSimulationPsy)); |
|
377 |
|
378 INFO_PRINTF1(_L("Opening second positioner")); |
|
379 err = aPositioner.Open(iPosServer, iUidSimulationPsy); |
|
380 User::LeaveIfError(err); |
|
381 CleanupClosePushL(aPositioner); |
|
382 err = aPositioner.SetRequestor(CRequestor::ERequestorService, |
|
383 CRequestor::EFormatApplication, KService); |
|
384 if (err != KErrNone) |
|
385 { |
|
386 _LIT(KErrRequestor, "Error when setting requestor."); |
|
387 LogErrorAndLeaveL(KErrRequestor, err); |
|
388 } |
|
389 } |
|
390 |
|
391 CT_LbsSimulationPsyPosTp600::TPositionRequest::TPositionRequest(RPositioner& aPositioner) : |
|
392 iPositioner(aPositioner) |
|
393 { |
|
394 } |
|
395 |
|
396 CT_LbsSimulationPsyPosTp600::TPositionRequest::~TPositionRequest() |
|
397 { |
|
398 if (iStatus == KRequestPending) |
|
399 { |
|
400 iPositioner.CancelRequest(EPositionerNotifyPositionUpdate); |
|
401 } |
|
402 } |
|
403 |
|
404 void CT_LbsSimulationPsyPosTp600::TPositionRequest::MakeRequestL() |
|
405 { |
|
406 if (iStatus != KRequestPending) |
|
407 { |
|
408 iPositioner.NotifyPositionUpdate(iPositionInfo, iStatus); |
|
409 iRequestTime.UniversalTime(); |
|
410 } |
|
411 } |