|
1 // Copyright (c) 2005-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 // Example CTestStep derived implementation |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file SimPsyStep.cpp |
|
20 @internalTechnology |
|
21 */ |
|
22 #include "simpsystep.h" |
|
23 #include "te_lbssimulationpsysuitedefs.h" |
|
24 #include "lbssystemcontroller.h" |
|
25 |
|
26 #include <lbs.h> |
|
27 |
|
28 #include <centralrepository.h> |
|
29 #include <lbs/simulationpsyinternalcrkeys.h> |
|
30 |
|
31 #include "CPosFileReader.h" |
|
32 #include "EPos_TDesTokeniser.h" |
|
33 #include "CSimPsyMultiRequester.h" |
|
34 #include "CSimPsyRequester.h" |
|
35 //#include "CSimPsyMultiNmeaRequester.h" |
|
36 |
|
37 |
|
38 // A few useful macros |
|
39 #define MAX(x,y) ((x)<(y))?(y):(x) |
|
40 #define MIN(x,y) ((x)<(y))?(x):(y) |
|
41 |
|
42 GLREF_C TPositionModuleStatus ModuleStatus(); |
|
43 GLREF_C TPositionModuleStatus PrevModuleStatus(); |
|
44 |
|
45 // CONSTANTS |
|
46 //_LIT(KSimPsyName,"Simulation PSY"); |
|
47 _LIT(KSimPsyName,"Simulation"); |
|
48 _LIT(KSimFile, "c:\\system\\data\\simulationdata.sps"); |
|
49 |
|
50 _LIT(KDeterministicFile, "c:\\system\\data\\simulationData_deterministic.sps"); |
|
51 _LIT(KRandomFile, "c:\\system\\data\\simulationData_random.sps"); |
|
52 _LIT(KSimMoveAndBundFile, "c:\\system\\data\\simulationData_simmove_bund.sps"); |
|
53 _LIT(KSimSamePlace, "c:\\system\\data\\simulationdata_same_place.sps"); |
|
54 |
|
55 _LIT(KSimPositiveLongitudeWrapAroundFile, "c:\\system\\data\\simulationData_longwrap1.sps"); |
|
56 _LIT(KSimNegativeLongitudeWrapAroundFile, "c:\\system\\data\\simulationData_longwrap2.sps"); |
|
57 |
|
58 _LIT(KSimWrongHorAcc_File, "c:\\system\\data\\simulationData_wrongHorAcc.sps"); |
|
59 _LIT(KSimWrongVerAcc_File, "c:\\system\\data\\simulationData_wrongVerAcc.sps"); |
|
60 _LIT(KSimWrongLongitude_File, "c:\\system\\data\\simulationData_wrongLongitude.sps"); |
|
61 _LIT(KSimWrongLongitudeMax_File, "c:\\system\\data\\simulationData_wrongLongitudeMax.sps"); |
|
62 _LIT(KSimWrongLatitude_File, "c:\\system\\data\\simulationData_wrongLatitude.sps"); |
|
63 _LIT(KSimWrongLatitudeMax_File, "c:\\system\\data\\simulationData_wrongLatitudeMax.sps"); |
|
64 _LIT(KSimWrongSpeed_File, "c:\\system\\data\\simulationData_wrongSpeed.sps"); |
|
65 _LIT(KSimWrongCourse_File, "c:\\system\\data\\simulationData_wrongCourse.sps"); |
|
66 _LIT(KSimWrongTTF_min_File, "c:\\system\\data\\simulationData_wrongTTF_min.sps"); |
|
67 _LIT(KSimWrongTTF_max_File, "c:\\system\\data\\simulationData_wrongTTF_max.sps"); |
|
68 _LIT(KSimWrongPowerupTimeFile, "c:\\system\\data\\simulationData_wrong_poweruptime.sps"); |
|
69 _LIT(KSimWrongDeterministicFile, "c:\\system\\data\\simulationData_wrong_deterministic.sps"); |
|
70 _LIT(KSimWrongNumOfItemsFile, "c:\\system\\data\\simulationData_wrongNumberOfItems.sps"); |
|
71 _LIT(KSimWrongWordFile, "c:\\system\\data\\simulationData_wrongWordDoc.sps"); |
|
72 |
|
73 const TReal KEarthRadius = 6371010; |
|
74 const TReal KPI = 3.1415926535897932384626433832795; |
|
75 |
|
76 const TInt32 KSimModuleId = 270498433; |
|
77 |
|
78 CSimPsyStep::~CSimPsyStep() |
|
79 /** |
|
80 * Destructor |
|
81 */ |
|
82 { |
|
83 iFileReader->CloseResources(); |
|
84 delete iFileReader; |
|
85 iFileReader = NULL; |
|
86 delete iSimDataArray; |
|
87 iSimDataArray = NULL; |
|
88 |
|
89 #ifdef __CTC__ |
|
90 #pragma CTC APPEND |
|
91 #endif |
|
92 } |
|
93 |
|
94 CSimPsyStep::CSimPsyStep() |
|
95 /** |
|
96 * Constructor |
|
97 */ |
|
98 { |
|
99 // **MUST** call SetTestStepName in the constructor as the controlling |
|
100 // framework uses the test step name immediately following construction to set |
|
101 // up the step's unique logging ID. |
|
102 SetTestStepName(KSimPsyStep); |
|
103 } |
|
104 |
|
105 TVerdict CSimPsyStep::doTestStepPreambleL() |
|
106 /** |
|
107 * @return - TVerdict code |
|
108 * Override of base class virtual |
|
109 */ |
|
110 { |
|
111 // uncomment the following 3 lines if you have common pre setting to all the test steps in there |
|
112 CTe_LbsSimulationPSYSuiteStepBase::doTestStepPreambleL(); |
|
113 // if (TestStepResult()!=EPass) |
|
114 // return TestStepResult(); |
|
115 // process some pre setting to this test step then set SetTestStepResult to EFail or Epass. |
|
116 SetTestStepResult(EPass); |
|
117 |
|
118 TTime time; |
|
119 time.UniversalTime(); |
|
120 iSeed = time.Int64(); |
|
121 iSimDataArray = new (ELeave) CDesC8ArrayFlat(10); |
|
122 iFileReader = CPosFileReader::NewL(); |
|
123 SetSimDataFileL(KSimFile); |
|
124 ReadSimDataFromFileL(KSimFile); |
|
125 return TestStepResult(); |
|
126 } |
|
127 |
|
128 |
|
129 TVerdict CSimPsyStep::doTestStepL() |
|
130 /** |
|
131 * @return - TVerdict code |
|
132 * Override of base class pure virtual |
|
133 * Our implementation only gets called if the base class doTestStepPreambleL() did |
|
134 * not leave. That being the case, the current test result value will be EPass. |
|
135 */ |
|
136 { |
|
137 if (TestStepResult()==EPass) |
|
138 { |
|
139 TInt test; |
|
140 if(!GetIntFromConfig(ConfigSection(),KTe_LbsSimulationPSYSuiteInt,test) |
|
141 ) |
|
142 { |
|
143 // Leave if there's any error. |
|
144 User::Leave(KErrNotFound); |
|
145 } |
|
146 SetTestStepResult(EPass); |
|
147 StartL(test); |
|
148 } |
|
149 |
|
150 return TestStepResult(); |
|
151 } |
|
152 |
|
153 |
|
154 |
|
155 TVerdict CSimPsyStep::doTestStepPostambleL() |
|
156 /** |
|
157 * @return - TVerdict code |
|
158 * Override of base class virtual |
|
159 */ |
|
160 { |
|
161 // process something post setting to the test step |
|
162 // uncomment the following line if you have common post setting to all the test steps in there |
|
163 // CTe_LbsSimulationPSYSuiteStepBase::doTestStepPostambleL(); |
|
164 // uncomment the following line if you have post process or remove the following line if no post process |
|
165 // SetTestStepResult(EPass); // or EFail |
|
166 return TestStepResult(); |
|
167 } |
|
168 |
|
169 |
|
170 // --------------------------------------------------------- |
|
171 // CSimPsyStep::StartL |
|
172 // (other items were commented in a header). |
|
173 // --------------------------------------------------------- |
|
174 // |
|
175 void CSimPsyStep::StartL(TInt aIndex) |
|
176 { |
|
177 switch (aIndex) |
|
178 { |
|
179 case 0: |
|
180 _LIT(KSingleTestName, "**** Single request test ****"); |
|
181 INFO_PRINTF1(KSingleTestName); |
|
182 TestSingleRequestL(); |
|
183 break; |
|
184 case 1: |
|
185 _LIT(KSingleCancelTest, "**** Single cancel test ****"); |
|
186 INFO_PRINTF1(KSingleCancelTest); |
|
187 TestSingleCancelTestL(); |
|
188 break; |
|
189 case 2: |
|
190 _LIT(KMultCancelTest, "**** Multiple cancel test %d ****"); |
|
191 INFO_PRINTF1(KMultCancelTest); |
|
192 TestMultipleCancelTestL(EFalse, EFalse, ETrue); |
|
193 break; |
|
194 case 3: TestMultipleCancelTestL(ETrue, EFalse, ETrue); break; |
|
195 case 4: TestMultipleCancelTestL(ETrue, ETrue, ETrue); break; |
|
196 case 5: |
|
197 _LIT(KSimulatedMovements, "**** Simulated movements ****"); |
|
198 INFO_PRINTF1(KSimulatedMovements); |
|
199 TestSimulatedMovementsL(5); |
|
200 break; |
|
201 case 6: |
|
202 _LIT(KDeterministicFailure, "**** Deterministic failure ****"); |
|
203 INFO_PRINTF1(KDeterministicFailure); |
|
204 TestDeterministicFailureL(); |
|
205 break; |
|
206 case 7: |
|
207 _LIT(KRandomFailure, "**** Random failure ****"); |
|
208 INFO_PRINTF1(KRandomFailure); |
|
209 TestRandomFailureL(); |
|
210 break; |
|
211 case 8: |
|
212 _LIT(KMultipleRequestsMemoryTestName, "**** Multiple requests memory leak test ****"); |
|
213 INFO_PRINTF1(KMultipleRequestsMemoryTestName); |
|
214 //TestMultipleRequestsL(20); |
|
215 HeapTestL(aIndex); |
|
216 break; |
|
217 case 9: |
|
218 _LIT(KMultipleRequestsAndCancelMemoryTestName, "**** Multiple requests and cancel memory leak test ****"); |
|
219 INFO_PRINTF1(KMultipleRequestsAndCancelMemoryTestName); |
|
220 //TestMultipleRequestsAndCancelL(2/*20*/, EFalse, ETrue, EFalse); |
|
221 HeapTestL(aIndex); |
|
222 break; |
|
223 case 10: |
|
224 _LIT(KLongitudeWraparoundTestName, "**** Longitude wraparound test ****"); |
|
225 INFO_PRINTF1(KLongitudeWraparoundTestName); |
|
226 TestLongitudeWrapAroundL(); |
|
227 break; |
|
228 case 11: |
|
229 _LIT(KBadSimFile, "**** Bad Simulation Data file ****"); |
|
230 INFO_PRINTF1(KBadSimFile); |
|
231 TestBadSimulationDataFileL(); |
|
232 break; |
|
233 case 12: |
|
234 _LIT(KReqTimeAfterCancel, "**** Request Time after Cancel ****"); |
|
235 INFO_PRINTF1(KReqTimeAfterCancel); |
|
236 TestRequestTimeAfterCancelL(); |
|
237 break; |
|
238 case 13: |
|
239 _LIT(KReqCancelReq, "**** Request Cancel Request with Time ****"); |
|
240 INFO_PRINTF1(KReqCancelReq); |
|
241 TestRequestCancelRequestL(); |
|
242 break; |
|
243 case 14: |
|
244 _LIT(KStatusEvent, "**** Status Event test ****"); |
|
245 INFO_PRINTF1(KStatusEvent); |
|
246 TestStatusEventL(); |
|
247 break; |
|
248 case 15: |
|
249 _LIT(KModuleInfo, "**** Module Info test ****"); |
|
250 INFO_PRINTF1(KModuleInfo); |
|
251 TestModuleInfoL(); |
|
252 break; |
|
253 case 16: |
|
254 _LIT(KStillStanding, "**** Standing still test ****"); |
|
255 INFO_PRINTF1(KStillStanding); |
|
256 TestStandingStillL(); |
|
257 break; |
|
258 default: break; |
|
259 } |
|
260 } |
|
261 |
|
262 |
|
263 void CSimPsyStep::DoTestL(TInt aIndex) |
|
264 { |
|
265 switch (aIndex) |
|
266 { |
|
267 case 0: TestSingleRequestL(); break; |
|
268 case 1: TestSingleCancelTestL(); break; |
|
269 case 2: TestMultipleCancelTestL(EFalse, EFalse, ETrue); break; |
|
270 case 3: TestMultipleCancelTestL(ETrue, EFalse, ETrue); break; |
|
271 case 4: TestMultipleCancelTestL(ETrue, ETrue, ETrue); break; |
|
272 case 5: TestSimulatedMovementsL(5); break; |
|
273 case 6: TestDeterministicFailureL(); break; |
|
274 case 7: TestRandomFailureL(); break; |
|
275 case 8: TestMultipleRequestsL(20); break; |
|
276 case 9: TestMultipleRequestsAndCancelL(2/*20*/, EFalse, ETrue, EFalse); break; |
|
277 case 10: TestLongitudeWrapAroundL(); break; |
|
278 case 11: TestBadSimulationDataFileL(); break; |
|
279 case 12: TestRequestTimeAfterCancelL(); break; |
|
280 case 13: TestRequestCancelRequestL(); break; |
|
281 case 14: TestStatusEventL(); break; |
|
282 case 15: TestModuleInfoL(); break; |
|
283 case 16: TestStandingStillL(); break; |
|
284 default: break; |
|
285 } |
|
286 } |
|
287 |
|
288 // --------------------------------------------------------- |
|
289 // CSimPsyStep::TestSingleRequestL |
|
290 // (other items were commented in a header). |
|
291 // --------------------------------------------------------- |
|
292 // |
|
293 void CSimPsyStep::TestSingleRequestL() |
|
294 { |
|
295 CSimPsyMultiRequester* requester = CSimPsyMultiRequester::NewLC(); |
|
296 |
|
297 TInt status; |
|
298 TPositionInfo position; |
|
299 TPosition pos, pos2; |
|
300 TTimeIntervalMicroSeconds requestTime; |
|
301 |
|
302 requester->MakeRequests(); |
|
303 requester->GetResult(status, position, requestTime); |
|
304 CheckRequestResultL(status, position); |
|
305 CheckRequestTimeL(KSimFile, ETrue, position, requestTime); |
|
306 position.GetPosition(pos); |
|
307 |
|
308 requester->MakeRequests(); |
|
309 requester->GetResult(status, position, requestTime); |
|
310 CheckRequestTimeL(KSimFile, EFalse, position, requestTime); |
|
311 position.GetPosition(pos2); |
|
312 |
|
313 // Check if first altitude is != 0.0 |
|
314 if (pos.Altitude() != 0.0) |
|
315 { |
|
316 _LIT(KLong, "Expected altitude == 0.0, but got: %d."); |
|
317 TBuf<60> buf; |
|
318 buf.Format(KLong, pos.Altitude()); |
|
319 LogErrorAndFail(buf); |
|
320 } |
|
321 // Check if first altitude is same as the second |
|
322 if (pos.Altitude() == pos2.Altitude()) |
|
323 { |
|
324 _LIT(KLong, "Expected altitude != previous altitude. %d."); |
|
325 TBuf<50> buf; |
|
326 buf.Format(KLong, pos2.Altitude()); |
|
327 LogErrorAndFail(buf); |
|
328 } |
|
329 |
|
330 CleanupStack::PopAndDestroy(); // requester |
|
331 _LIT(KSingleTestName, "Ended: **** Single request test ****"); |
|
332 INFO_PRINTF1(KSingleTestName); |
|
333 } |
|
334 |
|
335 // --------------------------------------------------------- |
|
336 // CSimPsyStep::TestSingleCancelTestL |
|
337 // (other items were commented in a header). |
|
338 // --------------------------------------------------------- |
|
339 // |
|
340 void CSimPsyStep::TestSingleCancelTestL() |
|
341 { |
|
342 SetSimDataFileL(KSimMoveAndBundFile); |
|
343 |
|
344 CSimPsyMultiRequester* requester = CSimPsyMultiRequester::NewLC(); |
|
345 requester->SetRequesterWillCancelL(); |
|
346 |
|
347 TPositionInfo position; |
|
348 TInt status; |
|
349 TTimeIntervalMicroSeconds requestTime; |
|
350 |
|
351 requester->StopRequests(); |
|
352 requester->MakeRequests(); |
|
353 requester->GetResult(status, position, requestTime); |
|
354 if (status != KErrCancel) |
|
355 { |
|
356 _LIT(KReqWasNotCancelled, "The request was not cancelled"); |
|
357 LogErrorAndFail(KReqWasNotCancelled); |
|
358 } |
|
359 TPosition pos; |
|
360 position.GetPosition(pos); |
|
361 if (pos.Time().Int64() != 0.0) |
|
362 { |
|
363 _LIT(KHasPosition, "The cancelled request returned a position"); |
|
364 LogErrorAndFail(KHasPosition); |
|
365 } |
|
366 |
|
367 CleanupStack::PopAndDestroy(); // requester |
|
368 _LIT(KSingleCancelTest, "Ended: **** Single cancel test ****"); |
|
369 INFO_PRINTF1(KSingleCancelTest); |
|
370 } |
|
371 |
|
372 // --------------------------------------------------------- |
|
373 // CSimPsyStep::TestSimpleCancelTestL |
|
374 // (other items were commented in a header). |
|
375 // --------------------------------------------------------- |
|
376 // |
|
377 void CSimPsyStep::TestMultipleCancelTestL( |
|
378 TBool aFirstWillCancel, |
|
379 TBool aSecondWillCancel, |
|
380 TBool aThirdWillCancel) |
|
381 { |
|
382 SetSimDataFileL(KSimMoveAndBundFile); |
|
383 |
|
384 CSimPsyMultiRequester* requester = CSimPsyMultiRequester::NewLC(3); |
|
385 if (aFirstWillCancel) |
|
386 { |
|
387 requester->SetRequesterWillCancelL(0); |
|
388 } |
|
389 if (aSecondWillCancel) |
|
390 { |
|
391 requester->SetRequesterWillCancelL(1); |
|
392 } |
|
393 if (aThirdWillCancel) |
|
394 { |
|
395 requester->SetRequesterWillCancelL(2); |
|
396 } |
|
397 |
|
398 TPositionInfo position; |
|
399 TInt status; |
|
400 TTimeIntervalMicroSeconds requestTime; |
|
401 |
|
402 requester->MakeRequests(); |
|
403 |
|
404 for (TInt i = 0; i < 3; i++) |
|
405 { |
|
406 requester->GetResult(status, position, requestTime, i); |
|
407 |
|
408 TPosition pos; |
|
409 position.GetPosition(pos); |
|
410 TBool shouldHaveCancelled = |
|
411 (i == 0) ? aFirstWillCancel |
|
412 : (i == 1) ? aSecondWillCancel |
|
413 : aThirdWillCancel; |
|
414 |
|
415 if (shouldHaveCancelled) |
|
416 { |
|
417 if (status != KErrCancel) |
|
418 { |
|
419 _LIT(KReqWasNotCancelled, "The request was not cancelled"); |
|
420 LogErrorAndFail(KReqWasNotCancelled); |
|
421 } |
|
422 if (pos.Time().Int64() != 0.0) |
|
423 { |
|
424 _LIT(KHasPosition, "The cancelled request returned a position"); |
|
425 LogErrorAndFail(KHasPosition); |
|
426 } |
|
427 } |
|
428 else |
|
429 { |
|
430 if (status != KErrNone) |
|
431 { |
|
432 _LIT(KReqFailed, "The request failed"); |
|
433 LogErrorAndFail(KReqFailed); |
|
434 } |
|
435 if (pos.Time().Int64() == 0.0) |
|
436 { |
|
437 _LIT(KHasNoPosition, "The request did not return a position"); |
|
438 LogErrorAndFail(KHasNoPosition); |
|
439 } |
|
440 } |
|
441 } |
|
442 CleanupStack::PopAndDestroy(); // requester |
|
443 _LIT(KMultCancelTest, "Ended: **** Multiple cancel test ****"); |
|
444 INFO_PRINTF1(KMultCancelTest); |
|
445 } |
|
446 |
|
447 // --------------------------------------------------------- |
|
448 // CSimPsyStep::TestDeterministicFailureL |
|
449 // (other items were commented in a header). |
|
450 // --------------------------------------------------------- |
|
451 // |
|
452 void CSimPsyStep::TestDeterministicFailureL() |
|
453 { |
|
454 _LIT8(KDeterministic, "Deterministic*"); |
|
455 const TUint8 KPosDataSeparator = '='; |
|
456 const TUint8 KPosDefaultDataEndMarker = ';'; |
|
457 |
|
458 SetSimDataFileL(KDeterministicFile); |
|
459 ReadSimDataFromFileL(KDeterministicFile); |
|
460 CSimPsyMultiRequester* requester = CSimPsyMultiRequester::NewLC(); |
|
461 |
|
462 TInt status; |
|
463 TPositionInfo position; |
|
464 TTimeIntervalMicroSeconds requestTime; |
|
465 |
|
466 TInt failFrequency = 0; |
|
467 for (TInt i = 0; i < iSimDataArray->Count(); i++) |
|
468 { |
|
469 if (iSimDataArray->MdcaPoint(i).MatchF(KDeterministic) |
|
470 != KErrNotFound) |
|
471 { |
|
472 TDesTokeniser tokeniser(iSimDataArray->MdcaPoint(i)); |
|
473 tokeniser.NextToken(KPosDataSeparator); |
|
474 TPtrC8 value = tokeniser.NextToken(KPosDefaultDataEndMarker); |
|
475 TLex8 lexer(value); |
|
476 lexer.Val(failFrequency); |
|
477 break; |
|
478 } |
|
479 } |
|
480 |
|
481 TBuf<20> buf; |
|
482 TInt request; |
|
483 TInt numberOfRequests = 10; |
|
484 TBool requestShouldFail = EFalse; |
|
485 for (request = 1; request <= numberOfRequests; request++) |
|
486 { |
|
487 if (failFrequency == 0) |
|
488 { |
|
489 requestShouldFail = EFalse; |
|
490 } |
|
491 else if (request % failFrequency == 0) |
|
492 { |
|
493 requestShouldFail = ETrue; |
|
494 } |
|
495 requester->MakeRequests(); |
|
496 requester->GetResult(status, position, requestTime); |
|
497 if (request > 1) |
|
498 { |
|
499 CheckRequestTimeL(KDeterministicFile, EFalse, position, requestTime); |
|
500 } |
|
501 |
|
502 if (requestShouldFail) |
|
503 { |
|
504 requestShouldFail = EFalse; |
|
505 TPosition pos; |
|
506 position.GetPosition(pos); |
|
507 if (status != KPositionQualityLoss) |
|
508 { |
|
509 TBuf<40> output; |
|
510 _LIT(KStatusError, "KPositionQualityLoss was expected, but got %d"); |
|
511 output.Format(KStatusError, status); |
|
512 LogErrorAndFail(output); |
|
513 } |
|
514 TBuf<30> buf; |
|
515 _LIT(KOut, "Failing request no : %d."); |
|
516 buf.Format(KOut, numberOfRequests); |
|
517 } |
|
518 else |
|
519 { |
|
520 CheckThatPositionExistsL(position); |
|
521 } |
|
522 } |
|
523 CleanupStack::PopAndDestroy(); //requester |
|
524 |
|
525 TInt noOfClients = 4; |
|
526 requester = NULL; |
|
527 requester = CSimPsyMultiRequester::NewLC(noOfClients); |
|
528 |
|
529 for (TInt j = 1; j <= 10; j++) |
|
530 { |
|
531 requester->MakeRequests(); |
|
532 for (TInt i = 0; i < noOfClients; i++) |
|
533 { |
|
534 requester->GetResult(status, position, requestTime, i); |
|
535 if (failFrequency == 0) |
|
536 { |
|
537 CheckThatPositionExistsL(position); |
|
538 } |
|
539 else if (j % failFrequency == 0) |
|
540 { |
|
541 if (status != KPositionQualityLoss) |
|
542 { |
|
543 TBuf<40> output; |
|
544 _LIT(KStatusError, "KPositionQualityLoss was expected, but got %d"); |
|
545 output.Format(KStatusError, status); |
|
546 LogErrorAndFail(output); |
|
547 } |
|
548 TBuf<40> out; |
|
549 _LIT(KOut, "Fail succeeded for request %d"); |
|
550 out.Format(KOut, j-1); |
|
551 } |
|
552 } |
|
553 } |
|
554 CleanupStack::PopAndDestroy(); //requester |
|
555 _LIT(KDeterministicFailure, "Ended: **** Deterministic failure ****"); |
|
556 INFO_PRINTF1(KDeterministicFailure); |
|
557 } |
|
558 |
|
559 // --------------------------------------------------------- |
|
560 // CSimPsyStep::TestRandomFailureL |
|
561 // (other items were commented in a header). |
|
562 // --------------------------------------------------------- |
|
563 // |
|
564 void CSimPsyStep::TestRandomFailureL() |
|
565 { |
|
566 _LIT8(KRandom, "Random*"); |
|
567 const TUint8 KPosDataSeparator = '='; |
|
568 const TUint8 KPosDefaultDataEndMarker = ';'; |
|
569 |
|
570 SetSimDataFileL(KRandomFile); |
|
571 ReadSimDataFromFileL(KRandomFile); |
|
572 |
|
573 TInt status; |
|
574 TPositionInfo position; |
|
575 TTimeIntervalMicroSeconds requestTime; |
|
576 |
|
577 TInt failFrequency = 0; |
|
578 for (TInt i = 0; i < iSimDataArray->Count(); i++) |
|
579 { |
|
580 if (iSimDataArray->MdcaPoint(i).MatchF(KRandom) |
|
581 != KErrNotFound) |
|
582 { |
|
583 TDesTokeniser tokeniser(iSimDataArray->MdcaPoint(i)); |
|
584 tokeniser.NextToken(KPosDataSeparator); |
|
585 TPtrC8 value = tokeniser.NextToken(KPosDefaultDataEndMarker); |
|
586 TLex8 lexer(value); |
|
587 lexer.Val(failFrequency); |
|
588 } |
|
589 } |
|
590 |
|
591 TInt failedRequests = 0; |
|
592 TInt succeededRequests = 0; |
|
593 |
|
594 TInt noOfRequests = 25; |
|
595 TInt noOfClients = 20; |
|
596 |
|
597 CSimPsyMultiRequester* requester = CSimPsyMultiRequester::NewLC(noOfClients); |
|
598 |
|
599 for (TInt j = 1; j <= noOfRequests; j++) |
|
600 { |
|
601 requester->MakeRequests(); |
|
602 for (TInt i = 0; i < noOfClients; i++) |
|
603 { |
|
604 requester->GetResult(status, position, requestTime, i); |
|
605 |
|
606 TPosition pos; |
|
607 position.GetPosition(pos); |
|
608 if (status != KErrNone) |
|
609 { |
|
610 } |
|
611 if (status == KErrGeneral) |
|
612 { |
|
613 failedRequests++; |
|
614 } |
|
615 else if (position.ModuleId().iUid != KSimModuleId && status != KErrGeneral) |
|
616 { |
|
617 _LIT(KRequestError, "Corrupt status or position encountered."); |
|
618 LogErrorAndFail(KRequestError); |
|
619 } |
|
620 else |
|
621 { |
|
622 succeededRequests++; |
|
623 CheckThatPositionExistsL(position); |
|
624 } |
|
625 } |
|
626 } |
|
627 TInt timesToFail = noOfRequests * noOfClients / failFrequency; |
|
628 if (failedRequests > timesToFail+noOfClients && |
|
629 failedRequests < timesToFail-noOfClients) |
|
630 { |
|
631 _LIT(KRandomError, "Random failure failed."); |
|
632 LogErrorAndFail(KRandomError); |
|
633 } |
|
634 |
|
635 CleanupStack::PopAndDestroy(); //requester |
|
636 _LIT(KRandomFailure, "Ended: **** Random failure ****"); |
|
637 INFO_PRINTF1(KRandomFailure); |
|
638 } |
|
639 |
|
640 // --------------------------------------------------------- |
|
641 // CSimPsyStep::TestSimulatedMovementsL |
|
642 // (other items were commented in a header). |
|
643 // --------------------------------------------------------- |
|
644 // |
|
645 void CSimPsyStep::TestSimulatedMovementsL(TInt aNumberOfRequests) |
|
646 { |
|
647 _LIT(KAltError, "Incorrect altitude."); |
|
648 |
|
649 SetSimDataFileL(KSimMoveAndBundFile); |
|
650 ReadSimDataFromFileL(KSimMoveAndBundFile); |
|
651 CSimPsyMultiRequester* requester = CSimPsyMultiRequester::NewLC(); |
|
652 TPositionInfo position; |
|
653 TInt status; |
|
654 TTimeIntervalMicroSeconds requestTime; |
|
655 TTime requestStartTime; |
|
656 TTime lastRequestTime; |
|
657 |
|
658 // Make requests to sim psy and check that the results are equal |
|
659 //to the sim data in the simulation file |
|
660 requestStartTime.UniversalTime(); |
|
661 lastRequestTime = requestStartTime; |
|
662 requester->MakeRequests(); |
|
663 requester->GetResult(status, position, requestTime); |
|
664 CheckRequestResultL(status, position); |
|
665 CheckRequestTimeL(KSimMoveAndBundFile, ETrue, position, requestTime); |
|
666 |
|
667 TPositionInfoBase oldPosition = position; |
|
668 |
|
669 //Check that new simulation data is received when performing further requests |
|
670 TPositionInfo newPosition; |
|
671 for (TInt i = 0; i < aNumberOfRequests; i++) |
|
672 { |
|
673 requestStartTime.UniversalTime(); |
|
674 requester->MakeRequests(); |
|
675 requester->GetResult(status, newPosition, requestTime); |
|
676 CheckRequestTimeL(KSimMoveAndBundFile, EFalse, newPosition, requestTime); |
|
677 |
|
678 if (status == KErrNone) |
|
679 { |
|
680 TPosition newPos; |
|
681 newPosition.GetPosition(newPos); |
|
682 |
|
683 if (newPos.VerticalAccuracy() != 0) |
|
684 { |
|
685 if (newPos.Altitude() == 0) |
|
686 { |
|
687 LogErrorAndFail(KAltError); |
|
688 } |
|
689 } |
|
690 lastRequestTime = requestStartTime; |
|
691 } |
|
692 else |
|
693 { |
|
694 User::Leave(status); |
|
695 } |
|
696 } |
|
697 CleanupStack::PopAndDestroy(); // requester |
|
698 _LIT(KSimulatedMovements, "Ended: **** Simulated movements ****"); |
|
699 INFO_PRINTF1(KSimulatedMovements); |
|
700 } |
|
701 |
|
702 // --------------------------------------------------------- |
|
703 // CSimPsyStep::TestMultRequestsL |
|
704 // (other items were commented in a header). |
|
705 // --------------------------------------------------------- |
|
706 // |
|
707 void CSimPsyStep::TestMultipleRequestsL(TInt aNumberOfRequests) |
|
708 { |
|
709 CSimPsyMultiRequester* requester = CSimPsyMultiRequester::NewLC(); |
|
710 |
|
711 TInt status; |
|
712 TPositionInfo position; |
|
713 TTimeIntervalMicroSeconds requestTime; |
|
714 _LIT(k, "status = %d"); |
|
715 TBuf<20> buf; |
|
716 for (TInt i = 0; i < aNumberOfRequests; i++) |
|
717 { |
|
718 requester->MakeRequests(); |
|
719 requester->GetResult(status, position, requestTime); |
|
720 buf.Format(k, status); |
|
721 } |
|
722 CleanupStack::PopAndDestroy(); // requester |
|
723 _LIT(KMultipleRequestsMemoryTestName, "Ended: **** Multiple requests memory leak test ****"); |
|
724 INFO_PRINTF1(KMultipleRequestsMemoryTestName); |
|
725 } |
|
726 |
|
727 // --------------------------------------------------------- |
|
728 // CSimPsyStep::TestMultipleRequestsAndCancelL |
|
729 // (other items were commented in a header). |
|
730 // --------------------------------------------------------- |
|
731 // |
|
732 void CSimPsyStep::TestMultipleRequestsAndCancelL( |
|
733 TInt aNumberOfRequests, TBool aFirstWillCancel, |
|
734 TBool aSecondWillCancel, TBool aThirdWillCancel) |
|
735 { |
|
736 TBuf8<256> output; |
|
737 |
|
738 CSimPsyMultiRequester* requester = CSimPsyMultiRequester::NewLC(3); |
|
739 if (aFirstWillCancel) |
|
740 { |
|
741 requester->SetRequesterWillCancelL(0); |
|
742 } |
|
743 if (aSecondWillCancel) |
|
744 { |
|
745 requester->SetRequesterWillCancelL(1); |
|
746 } |
|
747 if (aThirdWillCancel) |
|
748 { |
|
749 requester->SetRequesterWillCancelL(2); |
|
750 } |
|
751 |
|
752 TPositionInfo position; |
|
753 TInt status; |
|
754 TTimeIntervalMicroSeconds requestTime; |
|
755 TBuf<50> buf; |
|
756 _LIT(K, "CSimPsyStep::GetResult %d"); |
|
757 |
|
758 for (TInt i = 0; i < aNumberOfRequests; i++) |
|
759 { |
|
760 requester->MakeRequests(); |
|
761 |
|
762 for (TInt j = 0; j < 3; j++) |
|
763 { |
|
764 requester->GetResult(status, position, requestTime, j); |
|
765 buf.Format(K, status); |
|
766 } |
|
767 } |
|
768 CleanupStack::PopAndDestroy(); // requester |
|
769 _LIT(KMultipleRequestsAndCancelMemoryTestName, "Ended: **** Multiple requests and cancel memory leak test ****"); |
|
770 INFO_PRINTF1(KMultipleRequestsAndCancelMemoryTestName); |
|
771 } |
|
772 |
|
773 // --------------------------------------------------------- |
|
774 // CSimPsyStep::TestLongitudeWrapAroundL |
|
775 // (other items were commented in a header). |
|
776 // --------------------------------------------------------- |
|
777 // |
|
778 void CSimPsyStep::TestLongitudeWrapAroundL() |
|
779 { |
|
780 const TInt KMaxNofRequests = 10; |
|
781 const TReal KDeltaLongitude = 1.0; |
|
782 const TReal KMaxLongitude = 180.0; |
|
783 |
|
784 TInt status; |
|
785 TPositionInfo position; |
|
786 TTimeIntervalMicroSeconds requestTime; |
|
787 TPosition pos; |
|
788 |
|
789 { // Positive longitude wrap around |
|
790 SetSimDataFileL(KSimPositiveLongitudeWrapAroundFile); |
|
791 ReadSimDataFromFileL(KSimPositiveLongitudeWrapAroundFile); |
|
792 |
|
793 CSimPsyMultiRequester* requester = CSimPsyMultiRequester::NewLC(); |
|
794 |
|
795 TInt i; |
|
796 for (i = 0; i < KMaxNofRequests; i++) |
|
797 { |
|
798 requester->MakeRequests(); |
|
799 requester->GetResult(status, position, requestTime); |
|
800 position.GetPosition(pos); |
|
801 |
|
802 if (pos.Longitude() <= -KMaxLongitude || |
|
803 pos.Longitude() > KMaxLongitude) |
|
804 { |
|
805 _LIT(KError, "Invalid longitude. Wraparound did not work properly"); |
|
806 LogErrorAndFail(KError); |
|
807 } |
|
808 |
|
809 if (pos.Longitude() < -KMaxLongitude + KDeltaLongitude) |
|
810 { // Longitude has wrapped around ok. |
|
811 break; |
|
812 } |
|
813 } |
|
814 |
|
815 if (i == KMaxNofRequests) |
|
816 { |
|
817 _LIT(KError, "Longitude never wrapped around."); |
|
818 LogErrorAndFail(KError); |
|
819 } |
|
820 |
|
821 CleanupStack::PopAndDestroy(requester); |
|
822 } |
|
823 |
|
824 { // Negative longitude wrap around |
|
825 SetSimDataFileL(KSimNegativeLongitudeWrapAroundFile); |
|
826 ReadSimDataFromFileL(KSimNegativeLongitudeWrapAroundFile); |
|
827 |
|
828 CSimPsyMultiRequester* requester = CSimPsyMultiRequester::NewLC(); |
|
829 |
|
830 TInt i; |
|
831 for (i = 0; i < KMaxNofRequests; i++) |
|
832 { |
|
833 requester->MakeRequests(); |
|
834 requester->GetResult(status, position, requestTime); |
|
835 position.GetPosition(pos); |
|
836 |
|
837 if (pos.Longitude() <= -KMaxLongitude || |
|
838 pos.Longitude() > KMaxLongitude) |
|
839 { |
|
840 _LIT(KError, "Invalid longitude. Wraparound did not work properly"); |
|
841 LogErrorAndFail(KError); |
|
842 } |
|
843 |
|
844 if (pos.Longitude() > KMaxLongitude - KDeltaLongitude) |
|
845 { // Longitude has wrapped around ok. |
|
846 break; |
|
847 } |
|
848 |
|
849 } |
|
850 |
|
851 if (i == KMaxNofRequests) |
|
852 { |
|
853 _LIT(KError, "Longitude never wrapped around."); |
|
854 LogErrorAndFail(KError); |
|
855 } |
|
856 |
|
857 CleanupStack::PopAndDestroy(requester); |
|
858 } |
|
859 _LIT(KLongitudeWraparoundTestName, "Ended: **** Longitude wraparound test ****"); |
|
860 INFO_PRINTF1(KLongitudeWraparoundTestName); |
|
861 } |
|
862 |
|
863 // --------------------------------------------------------- |
|
864 // CSimPsyStep::TestBadSimulationDataFileL |
|
865 // (other items were commented in a header). |
|
866 // --------------------------------------------------------- |
|
867 // |
|
868 void CSimPsyStep::TestBadSimulationDataFileL() |
|
869 { |
|
870 TInt status = KErrNone; |
|
871 CSimPsyMultiRequester* requester = NULL; |
|
872 |
|
873 // Hor Acc |
|
874 SetSimDataFileL(KSimWrongHorAcc_File); |
|
875 TRAP(status, requester = CSimPsyMultiRequester::NewLC()); |
|
876 if (status != KErrCorrupt) |
|
877 { |
|
878 User::Leave(KErrGeneral); |
|
879 } |
|
880 status = KErrNone; |
|
881 |
|
882 // Vert Acc |
|
883 SetSimDataFileL(KSimWrongVerAcc_File); |
|
884 TRAP(status, requester = CSimPsyMultiRequester::NewLC()); |
|
885 if (status != KErrCorrupt) |
|
886 { |
|
887 User::Leave(KErrGeneral); |
|
888 } |
|
889 status = KErrNone; |
|
890 |
|
891 // Time To Fix Min |
|
892 SetSimDataFileL(KSimWrongTTF_min_File); |
|
893 TRAP(status, requester = CSimPsyMultiRequester::NewLC()); |
|
894 if (status != KErrCorrupt) |
|
895 { |
|
896 User::Leave(KErrGeneral); |
|
897 } |
|
898 status = KErrNone; |
|
899 |
|
900 // Time To Fix Max |
|
901 SetSimDataFileL(KSimWrongTTF_max_File); |
|
902 TRAP(status, requester = CSimPsyMultiRequester::NewLC()); |
|
903 if (status != KErrCorrupt) |
|
904 { |
|
905 User::Leave(KErrGeneral); |
|
906 } |
|
907 status = KErrNone; |
|
908 |
|
909 // Power up time |
|
910 SetSimDataFileL(KSimWrongPowerupTimeFile); |
|
911 TRAP(status, requester = CSimPsyMultiRequester::NewLC()); |
|
912 if (status != KErrCorrupt) |
|
913 { |
|
914 User::Leave(KErrGeneral); |
|
915 } |
|
916 status = KErrNone; |
|
917 |
|
918 // Longitude |
|
919 SetSimDataFileL(KSimWrongLongitude_File); |
|
920 TRAP(status, requester = CSimPsyMultiRequester::NewLC()); |
|
921 if (status != KErrCorrupt) |
|
922 { |
|
923 User::Leave(KErrGeneral); |
|
924 } |
|
925 status = KErrNone; |
|
926 |
|
927 // Longitude, Max |
|
928 SetSimDataFileL(KSimWrongLongitudeMax_File); |
|
929 TRAP(status, requester = CSimPsyMultiRequester::NewLC()); |
|
930 if (status != KErrCorrupt) |
|
931 { |
|
932 User::Leave(KErrGeneral); |
|
933 } |
|
934 status = KErrNone; |
|
935 |
|
936 // Latitude |
|
937 SetSimDataFileL(KSimWrongLatitude_File); |
|
938 TRAP(status, requester = CSimPsyMultiRequester::NewLC()); |
|
939 if (status != KErrCorrupt) |
|
940 { |
|
941 User::Leave(KErrGeneral); |
|
942 } |
|
943 status = KErrNone; |
|
944 |
|
945 // Latitude, Max |
|
946 SetSimDataFileL(KSimWrongLatitudeMax_File); |
|
947 TRAP(status, requester = CSimPsyMultiRequester::NewLC()); |
|
948 if (status != KErrCorrupt) |
|
949 { |
|
950 User::Leave(KErrGeneral); |
|
951 } |
|
952 status = KErrNone; |
|
953 |
|
954 // Speed |
|
955 SetSimDataFileL(KSimWrongSpeed_File); |
|
956 TRAP(status, requester = CSimPsyMultiRequester::NewLC()); |
|
957 if (status != KErrCorrupt) |
|
958 { |
|
959 User::Leave(KErrGeneral); |
|
960 } |
|
961 status = KErrNone; |
|
962 |
|
963 // Course |
|
964 SetSimDataFileL(KSimWrongCourse_File); |
|
965 TRAP(status, requester = CSimPsyMultiRequester::NewLC()); |
|
966 if (status != KErrCorrupt) |
|
967 { |
|
968 User::Leave(KErrGeneral); |
|
969 } |
|
970 status = KErrNone; |
|
971 |
|
972 // Deterministic |
|
973 SetSimDataFileL(KSimWrongDeterministicFile); |
|
974 TRAP(status, requester = CSimPsyMultiRequester::NewLC()); |
|
975 if (status != KErrCorrupt) |
|
976 { |
|
977 User::Leave(KErrGeneral); |
|
978 } |
|
979 status = KErrNone; |
|
980 |
|
981 // Wrong number of items in file |
|
982 SetSimDataFileL(KSimWrongNumOfItemsFile); |
|
983 TRAP(status, requester = CSimPsyMultiRequester::NewLC()); |
|
984 if (status != KErrCorrupt) |
|
985 { |
|
986 User::Leave(KErrGeneral); |
|
987 } |
|
988 status = KErrNone; |
|
989 |
|
990 // Wrong number of items in file |
|
991 SetSimDataFileL(KSimWrongWordFile); |
|
992 TRAP(status, requester = CSimPsyMultiRequester::NewLC()); |
|
993 if (status != KErrCorrupt) |
|
994 { |
|
995 User::Leave(KErrGeneral); |
|
996 } |
|
997 status = KErrNone; |
|
998 if(requester) |
|
999 { |
|
1000 User::Leave(KErrGeneral); |
|
1001 } |
|
1002 _LIT(KBadSimFile, "Ended: **** Bad Simulation Data file ****"); |
|
1003 INFO_PRINTF1(KBadSimFile); |
|
1004 } |
|
1005 |
|
1006 // --------------------------------------------------------- |
|
1007 // CSimPsyStep::TestRequestTimeAfterCancelL |
|
1008 // (other items were commented in a header). |
|
1009 // --------------------------------------------------------- |
|
1010 // |
|
1011 void CSimPsyStep::TestRequestTimeAfterCancelL() |
|
1012 { |
|
1013 // SetSimDataFileL(KSimFile); |
|
1014 // ReadSimDataFromFileL(KSimFile); |
|
1015 |
|
1016 _LIT8(KTTFmin, "TimeToFix min*"); |
|
1017 _LIT8(KTTFmax, "TimeToFix max*"); |
|
1018 const TUint8 KPosDataSeparator = '='; |
|
1019 const TUint8 KPosDefaultDataEndMarker = ';'; |
|
1020 const TInt KEmulatorErrorTiming = 100000; |
|
1021 |
|
1022 TInt ttfMin = 0; |
|
1023 TInt ttfMax = 0; |
|
1024 for (TInt i = 0; i < iSimDataArray->Count(); i++) |
|
1025 { |
|
1026 if (iSimDataArray->MdcaPoint(i).MatchF(KTTFmin) |
|
1027 != KErrNotFound) |
|
1028 { |
|
1029 TDesTokeniser tokeniser(iSimDataArray->MdcaPoint(i)); |
|
1030 tokeniser.NextToken(KPosDataSeparator); |
|
1031 TPtrC8 value = tokeniser.NextToken(KPosDefaultDataEndMarker); |
|
1032 TLex8 lexer(value); |
|
1033 lexer.Val(ttfMin); |
|
1034 } |
|
1035 if (iSimDataArray->MdcaPoint(i).MatchF(KTTFmax) |
|
1036 != KErrNotFound) |
|
1037 { |
|
1038 TDesTokeniser tokeniser(iSimDataArray->MdcaPoint(i)); |
|
1039 tokeniser.NextToken(KPosDataSeparator); |
|
1040 TPtrC8 value = tokeniser.NextToken(KPosDefaultDataEndMarker); |
|
1041 TLex8 lexer(value); |
|
1042 lexer.Val(ttfMax); |
|
1043 } |
|
1044 } |
|
1045 if (ttfMin == 0) |
|
1046 { |
|
1047 User::Leave(KErrGeneral); |
|
1048 } |
|
1049 if (ttfMax == 0) |
|
1050 { |
|
1051 User::Leave(KErrGeneral); |
|
1052 } |
|
1053 |
|
1054 TInt numberOfTests = 5; |
|
1055 TInt status; |
|
1056 TPositionInfo position; |
|
1057 TPosition pos, pos2; |
|
1058 TTimeIntervalMicroSeconds requestTime; |
|
1059 for (TInt j = 0; j < numberOfTests; j++) |
|
1060 { |
|
1061 CSimPsyMultiRequester* requester = CSimPsyMultiRequester::NewLC(); |
|
1062 requester->SetRequesterWillCancelL(); |
|
1063 requester->MakeRequests(); |
|
1064 requester->GetResult(status, position, requestTime); |
|
1065 if (status != KErrCancel) |
|
1066 { |
|
1067 User::Leave(KErrGeneral); |
|
1068 } |
|
1069 |
|
1070 User::After(1 * 100000); // 100 ms |
|
1071 requester->SetRequesterWillCancelL(0, EFalse); |
|
1072 requester->MakeRequests(); |
|
1073 requester->GetResult(status, position, requestTime); |
|
1074 CheckThatPositionExistsL(position); |
|
1075 User::LeaveIfError(status); |
|
1076 |
|
1077 if (ttfMin * 1000000 - KEmulatorErrorTiming > requestTime.Int64() || |
|
1078 ttfMax * 1000000 + KEmulatorErrorTiming < requestTime.Int64()) |
|
1079 { |
|
1080 User::Leave(KErrGeneral); |
|
1081 } |
|
1082 |
|
1083 CleanupStack::PopAndDestroy(); // requester |
|
1084 } |
|
1085 _LIT(KReqTimeAfterCancel, "Ended: **** Request Time after Cancel ****"); |
|
1086 INFO_PRINTF1(KReqTimeAfterCancel); |
|
1087 } |
|
1088 |
|
1089 // --------------------------------------------------------- |
|
1090 // CSimPsyStep::TestRequestCancelRequestL |
|
1091 // (other items were commented in a header). |
|
1092 // --------------------------------------------------------- |
|
1093 // |
|
1094 void CSimPsyStep::TestRequestCancelRequestL() |
|
1095 { |
|
1096 _LIT8(KTTFmin, "TimeToFix min*"); |
|
1097 _LIT8(KTTFmax, "TimeToFix max*"); |
|
1098 const TUint8 KPosDataSeparator = '='; |
|
1099 const TUint8 KPosDefaultDataEndMarker = ';'; |
|
1100 const TInt KEmulatorErrorTiming = 100000; |
|
1101 |
|
1102 TInt ttfMin = 0; |
|
1103 TInt ttfMax = 0; |
|
1104 for (TInt i = 0; i < iSimDataArray->Count(); i++) |
|
1105 { |
|
1106 if (iSimDataArray->MdcaPoint(i).MatchF(KTTFmin) |
|
1107 != KErrNotFound) |
|
1108 { |
|
1109 TDesTokeniser tokeniser(iSimDataArray->MdcaPoint(i)); |
|
1110 tokeniser.NextToken(KPosDataSeparator); |
|
1111 TPtrC8 value = tokeniser.NextToken(KPosDefaultDataEndMarker); |
|
1112 TLex8 lexer(value); |
|
1113 lexer.Val(ttfMin); |
|
1114 } |
|
1115 if (iSimDataArray->MdcaPoint(i).MatchF(KTTFmax) |
|
1116 != KErrNotFound) |
|
1117 { |
|
1118 TDesTokeniser tokeniser(iSimDataArray->MdcaPoint(i)); |
|
1119 tokeniser.NextToken(KPosDataSeparator); |
|
1120 TPtrC8 value = tokeniser.NextToken(KPosDefaultDataEndMarker); |
|
1121 TLex8 lexer(value); |
|
1122 lexer.Val(ttfMax); |
|
1123 } |
|
1124 } |
|
1125 if (ttfMin == 0) |
|
1126 { |
|
1127 User::Leave(KErrGeneral); |
|
1128 } |
|
1129 if (ttfMax == 0) |
|
1130 { |
|
1131 User::Leave(KErrGeneral); |
|
1132 } |
|
1133 |
|
1134 TInt numberOfTests = 5; |
|
1135 TInt status; |
|
1136 TPositionInfo position; |
|
1137 TPosition pos, pos2; |
|
1138 TTimeIntervalMicroSeconds requestTime; |
|
1139 for (TInt j = 0; j < numberOfTests; j++) |
|
1140 { |
|
1141 CSimPsyMultiRequester* requester = CSimPsyMultiRequester::NewLC(); |
|
1142 requester->MakeRequests(); |
|
1143 requester->GetResult(status, position, requestTime); |
|
1144 User::LeaveIfError(status); |
|
1145 |
|
1146 requester->SetRequesterWillCancelL(); |
|
1147 requester->MakeRequests(); |
|
1148 requester->GetResult(status, position, requestTime); |
|
1149 if (status != KErrCancel) |
|
1150 { |
|
1151 User::Leave(KErrGeneral); |
|
1152 } |
|
1153 |
|
1154 User::After(1 * 100000); // 100 ms |
|
1155 requester->SetRequesterWillCancelL(0, EFalse); |
|
1156 requester->MakeRequests(); |
|
1157 requester->GetResult(status, position, requestTime); |
|
1158 CheckThatPositionExistsL(position); |
|
1159 User::LeaveIfError(status); |
|
1160 |
|
1161 if (ttfMin * 1000000 - KEmulatorErrorTiming > requestTime.Int64() || |
|
1162 ttfMax * 1000000 + KEmulatorErrorTiming < requestTime.Int64()) |
|
1163 { |
|
1164 User::Leave(KErrGeneral); |
|
1165 } |
|
1166 |
|
1167 CleanupStack::PopAndDestroy(); // requester |
|
1168 } |
|
1169 _LIT(KReqCancelReq, "Ended: **** Request Cancel Request with Time ****"); |
|
1170 INFO_PRINTF1(KReqCancelReq); |
|
1171 } |
|
1172 |
|
1173 // --------------------------------------------------------- |
|
1174 // CSimPsyStep::TestStatusEventL |
|
1175 // (other items were commented in a header). |
|
1176 // --------------------------------------------------------- |
|
1177 // |
|
1178 void CSimPsyStep::TestStatusEventL() |
|
1179 { |
|
1180 // SetSimDataFileL(KSimFile); |
|
1181 // ReadSimDataFromFileL(KSimFile); |
|
1182 |
|
1183 TInt numberOfTests = 2; |
|
1184 TInt status; |
|
1185 TPositionInfo position; |
|
1186 TTimeIntervalMicroSeconds requestTime; |
|
1187 for (TInt j = 0; j < numberOfTests; j++) |
|
1188 { |
|
1189 // Open PSY |
|
1190 CSimPsyMultiRequester* requester = CSimPsyMultiRequester::NewLC(); |
|
1191 |
|
1192 // Check that module status is correct |
|
1193 if (!requester->GetModuleStatus()) |
|
1194 { |
|
1195 User::Leave(KErrGeneral); |
|
1196 } |
|
1197 // Check that number of reported statuses is correct |
|
1198 if (requester->ReportedStatuses() != 1) |
|
1199 { |
|
1200 User::Leave(KErrGeneral); |
|
1201 } |
|
1202 requester->ResetReportedStatuses(); |
|
1203 |
|
1204 TPositionModuleStatus modStatus = requester->ModuleStatus(); |
|
1205 if (modStatus.DeviceStatus() != TPositionModuleStatus::EDeviceReady) |
|
1206 { |
|
1207 User::Leave(KErrGeneral); |
|
1208 } |
|
1209 if (modStatus.DataQualityStatus() != TPositionModuleStatus::EDataQualityNormal) |
|
1210 { |
|
1211 User::Leave(KErrGeneral); |
|
1212 } |
|
1213 |
|
1214 // Make requests |
|
1215 requester->MakeRequests(); |
|
1216 |
|
1217 // Check that module status is correct |
|
1218 if (!requester->GetModuleStatus()) |
|
1219 { |
|
1220 User::Leave(KErrGeneral); |
|
1221 } |
|
1222 // Check that number of reported statuses is correct |
|
1223 if (requester->ReportedStatuses() != 0) |
|
1224 { |
|
1225 User::Leave(KErrGeneral); |
|
1226 } |
|
1227 requester->ResetReportedStatuses(); |
|
1228 |
|
1229 modStatus = requester->ModuleStatus(); |
|
1230 if (modStatus.DeviceStatus() != TPositionModuleStatus::EDeviceReady) |
|
1231 { |
|
1232 User::Leave(KErrGeneral); |
|
1233 } |
|
1234 if (modStatus.DataQualityStatus() != TPositionModuleStatus::EDataQualityNormal) |
|
1235 { |
|
1236 User::Leave(KErrGeneral); |
|
1237 } |
|
1238 |
|
1239 requester->GetResult(status, position, requestTime); |
|
1240 User::LeaveIfError(status); |
|
1241 |
|
1242 // Close PSY |
|
1243 requester->ClosePositioner(); |
|
1244 |
|
1245 // Check that module status is correct |
|
1246 if (!requester->GetModuleStatus()) |
|
1247 { |
|
1248 User::Leave(KErrGeneral); |
|
1249 } |
|
1250 // Check that number of reported statuses is correct |
|
1251 if (requester->ReportedStatuses() != 1) |
|
1252 { |
|
1253 User::Leave(KErrGeneral); |
|
1254 } |
|
1255 requester->ResetReportedStatuses(); |
|
1256 |
|
1257 modStatus = requester->ModuleStatus(); |
|
1258 if (modStatus.DeviceStatus() != TPositionModuleStatus::EDeviceInactive) |
|
1259 { |
|
1260 User::Leave(KErrGeneral); |
|
1261 } |
|
1262 if (modStatus.DataQualityStatus() != TPositionModuleStatus::EDataQualityUnknown) |
|
1263 { |
|
1264 User::Leave(KErrGeneral); |
|
1265 } |
|
1266 CleanupStack::PopAndDestroy(); // requester |
|
1267 } |
|
1268 |
|
1269 SetSimDataFileL(KSimPsyName); |
|
1270 CSimPsyMultiRequester* requester = NULL; |
|
1271 TRAPD(err, requester = CSimPsyMultiRequester::NewLC()); |
|
1272 |
|
1273 // Check that module status is correct |
|
1274 if (err != KErrNotSupported) |
|
1275 { |
|
1276 User::Leave(KErrGeneral); |
|
1277 } |
|
1278 if (requester) |
|
1279 { |
|
1280 User::Leave(KErrGeneral); |
|
1281 } |
|
1282 |
|
1283 TPositionModuleStatus modStatus = ModuleStatus(); |
|
1284 if (modStatus.DeviceStatus() != TPositionModuleStatus::EDeviceInactive) |
|
1285 { |
|
1286 User::Leave(KErrGeneral); |
|
1287 } |
|
1288 if (modStatus.DataQualityStatus() != TPositionModuleStatus::EDataQualityUnknown) |
|
1289 { |
|
1290 User::Leave(KErrGeneral); |
|
1291 } |
|
1292 |
|
1293 modStatus = PrevModuleStatus(); |
|
1294 if (modStatus.DeviceStatus() != TPositionModuleStatus::EDeviceError) |
|
1295 { |
|
1296 User::Leave(KErrGeneral); |
|
1297 } |
|
1298 if (modStatus.DataQualityStatus() != TPositionModuleStatus::EDataQualityUnknown) |
|
1299 { |
|
1300 User::Leave(KErrGeneral); |
|
1301 } |
|
1302 _LIT(KStatusEvent, "Ended: **** Status Event test ****"); |
|
1303 INFO_PRINTF1(KStatusEvent); |
|
1304 } |
|
1305 |
|
1306 // --------------------------------------------------------- |
|
1307 // CSimPsyStep::TestModuleInfoL |
|
1308 // (other items were commented in a header). |
|
1309 // --------------------------------------------------------- |
|
1310 // |
|
1311 void CSimPsyStep::TestModuleInfoL() |
|
1312 { |
|
1313 #ifndef NO_LFW_SERVER |
|
1314 RLbsSystemController lbsSysController; |
|
1315 lbsSysController.OpenL(TUid::Uid(0x12345678)); |
|
1316 CleanupClosePushL(lbsSysController); |
|
1317 lbsSysController.InitializeL(); |
|
1318 User::LeaveIfError(lbsSysController.RequestSystemStartup()); |
|
1319 |
|
1320 RPositionServer ps; |
|
1321 CleanupClosePushL(ps); |
|
1322 User::LeaveIfError(ps.Connect()); |
|
1323 |
|
1324 TUid uid = { KSimModuleId }; |
|
1325 TPositionModuleInfo modInfo; |
|
1326 TInt err = ps.GetModuleInfoById(uid, modInfo); |
|
1327 |
|
1328 if (err == KErrNotFound) |
|
1329 { |
|
1330 INFO_PRINTF1(_L("Simulation PSY not found in Location Server")); |
|
1331 User::LeaveIfError(ps.GetModuleInfoById(uid, modInfo)); |
|
1332 } |
|
1333 |
|
1334 // Check info |
|
1335 if (!modInfo.IsAvailable()) |
|
1336 { |
|
1337 INFO_PRINTF1(_L("Simulation PSY not available")); |
|
1338 } |
|
1339 if (modInfo.ModuleId() != uid) |
|
1340 { |
|
1341 ERR_PRINTF1(_L("Simulation PSY has wrong module id")); |
|
1342 User::Leave(KErrGeneral); |
|
1343 } |
|
1344 TBuf<30> modName; |
|
1345 modInfo.GetModuleName(modName); |
|
1346 if (modName != KSimPsyName) |
|
1347 { |
|
1348 ERR_PRINTF1(_L("Simulation PSY has wrong name")); |
|
1349 User::Leave(KErrGeneral); |
|
1350 } |
|
1351 |
|
1352 if (modInfo.DeviceLocation() != TPositionModuleInfo::EDeviceInternal) |
|
1353 { |
|
1354 ERR_PRINTF1(_L("Simulation PSY has wrong device location")); |
|
1355 User::Leave(KErrGeneral); |
|
1356 } |
|
1357 if (modInfo.TechnologyType() != TPositionModuleInfo::ETechnologyTerminal) |
|
1358 { |
|
1359 ERR_PRINTF1(_L("Simulation PSY has technology type")); |
|
1360 User::Leave(KErrGeneral); |
|
1361 } |
|
1362 |
|
1363 TUint32 classesSupp = (EPositionInfoClass | EPositionSatelliteInfoClass | |
|
1364 EPositionCourseInfoClass | EPositionGenericInfoClass); |
|
1365 if (modInfo.ClassesSupported(EPositionInfoFamily) != classesSupp) |
|
1366 { |
|
1367 ERR_PRINTF1(_L("Simulation PSY supports wrong classes")); |
|
1368 User::Leave(KErrGeneral); |
|
1369 } |
|
1370 |
|
1371 TUint32 capsSupp = (TPositionModuleInfo::ECapabilityHorizontal | |
|
1372 TPositionModuleInfo::ECapabilityVertical | |
|
1373 TPositionModuleInfo::ECapabilitySpeed | |
|
1374 TPositionModuleInfo::ECapabilitySatellite | |
|
1375 TPositionModuleInfo::ECapabilityCompass | |
|
1376 TPositionModuleInfo::ECapabilityNmea); |
|
1377 if (modInfo.Capabilities() != capsSupp) |
|
1378 { |
|
1379 ERR_PRINTF1(_L("Simulation PSY has wrong capabilities")); |
|
1380 User::Leave(KErrGeneral); |
|
1381 } |
|
1382 |
|
1383 CleanupStack::PopAndDestroy(&ps); |
|
1384 |
|
1385 User::LeaveIfError(lbsSysController.RequestCompleteCloseDown()); |
|
1386 CleanupStack::PopAndDestroy(&lbsSysController); |
|
1387 #endif |
|
1388 |
|
1389 _LIT(KModuleInfoErrorTxt, "Incorrect Centrep value at line %d, got %d expected %d"); |
|
1390 _LIT(KModuleFloatInfoErrorTxt, "Incorrect Centrep value at line %d, got %f expected %d"); |
|
1391 TInt testInt; |
|
1392 TReal testReal; |
|
1393 CRepository* repository = CRepository::NewLC(KCRUidSimulationPSY); |
|
1394 User::LeaveIfError(repository->Get(KPSYInterfaceVersion, testInt)); |
|
1395 if (testInt != 1) |
|
1396 { |
|
1397 ERR_PRINTF4(KModuleInfoErrorTxt, __LINE__, testInt, 1); |
|
1398 SetTestStepResult(EFail); |
|
1399 } |
|
1400 |
|
1401 User::LeaveIfError(repository->Get(KPSYPriority, testInt)); |
|
1402 if (testInt != 1) |
|
1403 { |
|
1404 ERR_PRINTF4(KModuleInfoErrorTxt, __LINE__, testInt, 1); |
|
1405 SetTestStepResult(EFail); |
|
1406 } |
|
1407 |
|
1408 User::LeaveIfError(repository->Get(KPSYStatus, testInt)); |
|
1409 if (testInt != 1) |
|
1410 { |
|
1411 ERR_PRINTF4(KModuleInfoErrorTxt, __LINE__, testInt, 1); |
|
1412 SetTestStepResult(EFail); |
|
1413 } |
|
1414 |
|
1415 // 4 |
|
1416 User::LeaveIfError(repository->Get(KPSYTimeToFirstFix, testInt)); |
|
1417 if (testInt != 5000000) |
|
1418 { |
|
1419 ERR_PRINTF4(KModuleInfoErrorTxt, __LINE__, testInt, 5000000); |
|
1420 SetTestStepResult(EFail); |
|
1421 } |
|
1422 |
|
1423 User::LeaveIfError(repository->Get(KPSYTimeToNextFix, testInt)); |
|
1424 if (testInt != 5000000) |
|
1425 { |
|
1426 ERR_PRINTF4(KModuleInfoErrorTxt, __LINE__, testInt, 5000000); |
|
1427 SetTestStepResult(EFail); |
|
1428 } |
|
1429 |
|
1430 User::LeaveIfError(repository->Get(KPSYHorizontalAccuracy, testReal)); |
|
1431 if (testReal != 30) |
|
1432 { |
|
1433 ERR_PRINTF4(KModuleFloatInfoErrorTxt, __LINE__, testReal, 30); |
|
1434 SetTestStepResult(EFail); |
|
1435 } |
|
1436 |
|
1437 User::LeaveIfError(repository->Get(KPSYVerticalAccuracy, testReal)); |
|
1438 if (testReal != 45) |
|
1439 { |
|
1440 ERR_PRINTF4(KModuleFloatInfoErrorTxt, __LINE__, testReal, 45); |
|
1441 SetTestStepResult(EFail); |
|
1442 } |
|
1443 |
|
1444 // 8 |
|
1445 User::LeaveIfError(repository->Get(KPSYCostIndicator, testInt)); |
|
1446 if (testInt != 1) |
|
1447 { |
|
1448 ERR_PRINTF4(KModuleInfoErrorTxt, __LINE__, testInt, 1); |
|
1449 SetTestStepResult(EFail); |
|
1450 } |
|
1451 |
|
1452 User::LeaveIfError(repository->Get(KPSYPowerConsumption, testInt)); |
|
1453 if (testInt != 1) |
|
1454 { |
|
1455 ERR_PRINTF4(KModuleInfoErrorTxt, __LINE__, testInt, 1); |
|
1456 SetTestStepResult(EFail); |
|
1457 } |
|
1458 |
|
1459 User::LeaveIfError(repository->Get(KPSYTechnologyType, testInt)); |
|
1460 if (testInt != 1) |
|
1461 { |
|
1462 ERR_PRINTF4(KModuleInfoErrorTxt, __LINE__, testInt, 1); |
|
1463 SetTestStepResult(EFail); |
|
1464 } |
|
1465 |
|
1466 User::LeaveIfError(repository->Get(KPSYDeviceLocation, testInt)); |
|
1467 if (testInt != 1) |
|
1468 { |
|
1469 ERR_PRINTF4(KModuleInfoErrorTxt, __LINE__, testInt, 1); |
|
1470 SetTestStepResult(EFail); |
|
1471 } |
|
1472 |
|
1473 // 12 |
|
1474 User::LeaveIfError(repository->Get(KPSYCapabilities, testInt)); |
|
1475 if (testInt != 119) |
|
1476 { |
|
1477 ERR_PRINTF4(KModuleInfoErrorTxt, __LINE__, testInt, 119); |
|
1478 SetTestStepResult(EFail); |
|
1479 } |
|
1480 |
|
1481 User::LeaveIfError(repository->Get(KPSYClassesSupported, testInt)); |
|
1482 if (testInt != 15) |
|
1483 { |
|
1484 ERR_PRINTF4(KModuleInfoErrorTxt, __LINE__, testInt, 15); |
|
1485 SetTestStepResult(EFail); |
|
1486 } |
|
1487 |
|
1488 User::LeaveIfError(repository->Get(KPSYVisibility, testInt)); |
|
1489 if (testInt != 1) |
|
1490 { |
|
1491 ERR_PRINTF4(KModuleInfoErrorTxt, __LINE__, testInt, 1); |
|
1492 SetTestStepResult(EFail); |
|
1493 } |
|
1494 |
|
1495 CleanupStack::PopAndDestroy(repository); |
|
1496 _LIT(KModuleInfo, "Ended: **** Module Info test ****"); |
|
1497 INFO_PRINTF1(KModuleInfo); |
|
1498 } |
|
1499 |
|
1500 // --------------------------------------------------------- |
|
1501 // CSimPsyStep::TestStandingStillL |
|
1502 // (other items were commented in a header). |
|
1503 // --------------------------------------------------------- |
|
1504 // |
|
1505 void CSimPsyStep::TestStandingStillL() |
|
1506 { |
|
1507 SetSimDataFileL(KSimSamePlace); |
|
1508 |
|
1509 CSimPsyMultiRequester* requester = CSimPsyMultiRequester::NewLC(); |
|
1510 |
|
1511 TInt status; |
|
1512 TPositionInfo position; |
|
1513 TPosition pos, pos2; |
|
1514 TTimeIntervalMicroSeconds requestTime; |
|
1515 |
|
1516 requester->MakeRequests(); |
|
1517 requester->GetResult(status, position, requestTime); |
|
1518 CheckRequestTimeL(KSimFile, ETrue, position, requestTime); |
|
1519 position.GetPosition(pos); |
|
1520 |
|
1521 // Check if first altitude is != 0.0 |
|
1522 if (pos.Altitude() != 0.0) |
|
1523 { |
|
1524 _LIT(KLong, "Expected altitude == 0.0, but got: %d."); |
|
1525 TBuf<60> buf; |
|
1526 buf.Format(KLong, pos.Altitude()); |
|
1527 LogErrorAndFail(buf); |
|
1528 } |
|
1529 |
|
1530 |
|
1531 TReal32 distSum = 0; |
|
1532 TInt nrOfReq = 100; |
|
1533 TReal32 expectedAcc = 20; |
|
1534 TInt moreAcc = 0; |
|
1535 TReal32 delta; |
|
1536 |
|
1537 for(TInt i=0; i<nrOfReq; i++) |
|
1538 { |
|
1539 |
|
1540 INFO_PRINTF2(_L("for loop count=%d"), i); |
|
1541 |
|
1542 requester->MakeRequests(); |
|
1543 requester->GetResult(status, position, requestTime); |
|
1544 CheckRequestTimeL(KSimFile, EFalse, position, requestTime); |
|
1545 position.GetPosition(pos2); |
|
1546 |
|
1547 TReal32 distance; |
|
1548 TReal32 distance2; |
|
1549 TInt err = pos.Distance(pos2, distance, delta); |
|
1550 TInt err2 = pos.Distance(pos2, distance2); |
|
1551 |
|
1552 distSum += distance; |
|
1553 if (distance > expectedAcc) |
|
1554 { |
|
1555 moreAcc++; |
|
1556 } |
|
1557 } |
|
1558 |
|
1559 TReal32 median = distSum/nrOfReq; |
|
1560 |
|
1561 // 60 percent of requests should not be over expectedAcc |
|
1562 if (moreAcc > (nrOfReq * 0.6)) |
|
1563 { |
|
1564 _LIT(KLong, "Expected hor. acc. not normalized."); |
|
1565 LogErrorAndFail(KLong); |
|
1566 } |
|
1567 |
|
1568 // Median should be less than expectedAcc plus 20 percent of expectedAcc |
|
1569 if (median > (expectedAcc * 1.4)) |
|
1570 { |
|
1571 _LIT(KLong, "Expected hor. acc. over expected. %f > %f"); |
|
1572 TBuf<80> buf; |
|
1573 buf.Format(KLong, median, expectedAcc); |
|
1574 LogErrorAndFail(buf); |
|
1575 } |
|
1576 |
|
1577 // Check if first altitude is same as the second |
|
1578 if (pos.Altitude() != pos2.Altitude()) |
|
1579 { |
|
1580 _LIT(KLong, "Expected altitude != previous altitude. %d."); |
|
1581 TBuf<50> buf; |
|
1582 buf.Format(KLong, pos2.Altitude()); |
|
1583 LogErrorAndFail(buf); |
|
1584 } |
|
1585 |
|
1586 CleanupStack::PopAndDestroy(); // requester |
|
1587 _LIT(KStillStanding, "Ended: **** Standing still test ****"); |
|
1588 INFO_PRINTF1(KStillStanding); |
|
1589 } |
|
1590 |
|
1591 // --------------------------------------------------------- |
|
1592 // CSimPsyStep::ComputeNewLongAndLat |
|
1593 // (other items were commented in a header). |
|
1594 // --------------------------------------------------------- |
|
1595 // |
|
1596 TInt CSimPsyStep::ComputeNewLongAndLat( |
|
1597 TPositionInfoBase& aPosition, TReal aAlpha, TReal& aLon, TReal& aLat) |
|
1598 { |
|
1599 TReal cHdng1; |
|
1600 TReal cLat1; |
|
1601 TReal sAlpha; |
|
1602 TReal sLat1; |
|
1603 TReal cAlpha; |
|
1604 TReal toRadians = KPI/180; |
|
1605 TReal toDegrees = 180/KPI; |
|
1606 TPositionInfo& aPositionInfo = static_cast<TPositionInfo&> (aPosition); |
|
1607 TPosition position; |
|
1608 aPositionInfo.GetPosition(position); |
|
1609 TReal64 latitude = position.Latitude(); |
|
1610 TReal32 trueCourse = 0.0; // = aPosition->AdvancedInfo()->TrueCourse(); |
|
1611 |
|
1612 Math::Cos(cHdng1, trueCourse * toRadians); |
|
1613 Math::Cos(cLat1, latitude * toRadians); |
|
1614 Math::Sin(sAlpha, aAlpha); |
|
1615 Math::Sin(sLat1, latitude * toRadians); |
|
1616 Math::Cos(cAlpha, aAlpha); |
|
1617 |
|
1618 TReal sLat2 = cHdng1*cLat1*sAlpha+sLat1*cAlpha; |
|
1619 TReal lat2; |
|
1620 TInt err = Math::ASin(lat2, sLat2); |
|
1621 if (err != KErrNone) |
|
1622 { |
|
1623 return err; |
|
1624 } |
|
1625 |
|
1626 lat2 *= toDegrees; |
|
1627 aLat = lat2; |
|
1628 |
|
1629 TReal cLat2; |
|
1630 Math::Cos(cLat2, lat2*toRadians); |
|
1631 TReal tmp =(cAlpha-sLat1*sLat2)/(cLat1*cLat2); |
|
1632 if (tmp > 1.0) |
|
1633 { |
|
1634 tmp = 1.0; |
|
1635 } |
|
1636 err = Math::ACos(aLon, tmp); |
|
1637 if (err != KErrNone) |
|
1638 { |
|
1639 return err; |
|
1640 } |
|
1641 aLon *= toDegrees; |
|
1642 TPosition pos; |
|
1643 aPositionInfo.GetPosition(pos); |
|
1644 aLon += pos.Longitude(); |
|
1645 |
|
1646 TReal latError = 0; |
|
1647 TInt timesToRandom = 20; |
|
1648 for (TInt i = 0; i < timesToRandom; i++) |
|
1649 { |
|
1650 latError += Math::FRand(iSeed); |
|
1651 } |
|
1652 |
|
1653 latError -= timesToRandom/2; |
|
1654 TReal longError = latError; |
|
1655 latError *= pos.HorizontalAccuracy(); |
|
1656 longError *= pos.HorizontalAccuracy(); |
|
1657 |
|
1658 aLat += (latError*360)/(2*KEarthRadius*KPI); |
|
1659 aLon += (longError*360)/(2*KEarthRadius*KPI); |
|
1660 |
|
1661 return KErrNone; |
|
1662 } |
|
1663 |
|
1664 // --------------------------------------------------------- |
|
1665 // CSimPsyStep::CheckRequestResultL |
|
1666 // (other items were commented in a header). |
|
1667 // --------------------------------------------------------- |
|
1668 // |
|
1669 void CSimPsyStep::CheckRequestResultL( |
|
1670 TInt aStatus, TPositionInfo& aPosition) |
|
1671 { |
|
1672 if (aStatus != KErrNone) |
|
1673 { |
|
1674 User::Leave(aStatus); |
|
1675 } |
|
1676 |
|
1677 TReal longitudeMin = 56.33; |
|
1678 TReal longitudeMax = 56.34; |
|
1679 TReal latitudeMin = 78.33; |
|
1680 TReal latitudeMax = 78.34; |
|
1681 //should be the same as the values in simulationdata.txt, |
|
1682 TReal32 hacc = 20.0; //else the check below will fail |
|
1683 TReal32 vacc = 30.0; |
|
1684 |
|
1685 TPosition position; |
|
1686 aPosition.GetPosition(position); |
|
1687 |
|
1688 TBuf<100> buf; |
|
1689 if (aPosition.ModuleId().iUid != KSimModuleId) |
|
1690 { |
|
1691 _LIT(KWrongUid, "Expected simulationpsy uid"); |
|
1692 LogErrorAndFail(KWrongUid); |
|
1693 } |
|
1694 if (aPosition.UpdateType() != EPositionUpdateGeneral) |
|
1695 { |
|
1696 _LIT(KWrongUpType, "Expected Update Type General"); |
|
1697 LogErrorAndFail(KWrongUpType); |
|
1698 } |
|
1699 |
|
1700 if (position.VerticalAccuracy() != vacc) |
|
1701 { |
|
1702 _LIT(KVAcc, "Expected vacc %d."); |
|
1703 buf.Format(KVAcc, vacc); |
|
1704 LogErrorAndFail(buf); |
|
1705 } |
|
1706 if (position.HorizontalAccuracy() != hacc) |
|
1707 { |
|
1708 _LIT(KHAcc, "Expected hacc %d."); |
|
1709 buf.Format(KHAcc, hacc); |
|
1710 LogErrorAndFail(buf); |
|
1711 } |
|
1712 if (position.Latitude() < latitudeMin || |
|
1713 position.Latitude() > latitudeMax) |
|
1714 { |
|
1715 _LIT(KLat, "Expected latitudeMin %.4f, latidueMax %.4f."); |
|
1716 buf.Format(KLat, latitudeMin, latitudeMax); |
|
1717 LogErrorAndFail(buf); |
|
1718 } |
|
1719 if (position.Longitude() < longitudeMin || |
|
1720 position.Longitude() > longitudeMax) |
|
1721 { |
|
1722 _LIT(KLong, "Expected longitudeMin %.4f, longitudeMax %.4f."); |
|
1723 buf.Format(KLong, longitudeMin, longitudeMax); |
|
1724 LogErrorAndFail(buf); |
|
1725 } |
|
1726 } |
|
1727 |
|
1728 // --------------------------------------------------------- |
|
1729 // CSimPsyStep::CheckRequestTimeL |
|
1730 // (other items were commented in a header). |
|
1731 // --------------------------------------------------------- |
|
1732 // |
|
1733 void CSimPsyStep::CheckRequestTimeL( |
|
1734 const TDesC& aSimFile, TBool aPowerUp, |
|
1735 const TPositionInfo& aPos, |
|
1736 TTimeIntervalMicroSeconds& aReqTime, |
|
1737 TTimeIntervalMicroSeconds aTolerance) |
|
1738 { |
|
1739 _LIT8(KPowerUpTime, "Powerup time*"); |
|
1740 _LIT8(KTTFmin, "TimeToFix min*"); |
|
1741 _LIT8(KTTFmax, "TimeToFix max*"); |
|
1742 const TUint8 KPosDataSeparator = '='; |
|
1743 const TUint8 KPosDefaultDataEndMarker = ';'; |
|
1744 const TInt KToMs = 1000000; |
|
1745 |
|
1746 ReadSimDataFromFileL(aSimFile); |
|
1747 |
|
1748 TInt powerUpTime = 0; |
|
1749 TInt ttfMin = 0; |
|
1750 TInt ttfMax = 0; |
|
1751 for (TInt i = 0; i < iSimDataArray->Count(); i++) |
|
1752 { |
|
1753 if (iSimDataArray->MdcaPoint(i).MatchF(KPowerUpTime) |
|
1754 != KErrNotFound) |
|
1755 { |
|
1756 TDesTokeniser tokeniser(iSimDataArray->MdcaPoint(i)); |
|
1757 tokeniser.NextToken(KPosDataSeparator); |
|
1758 TPtrC8 value = tokeniser.NextToken(KPosDefaultDataEndMarker); |
|
1759 TLex8 lexer(value); |
|
1760 lexer.Val(powerUpTime); |
|
1761 } |
|
1762 if (iSimDataArray->MdcaPoint(i).MatchF(KTTFmin) |
|
1763 != KErrNotFound) |
|
1764 { |
|
1765 TDesTokeniser tokeniser(iSimDataArray->MdcaPoint(i)); |
|
1766 tokeniser.NextToken(KPosDataSeparator); |
|
1767 TPtrC8 value = tokeniser.NextToken(KPosDefaultDataEndMarker); |
|
1768 TLex8 lexer(value); |
|
1769 lexer.Val(ttfMin); |
|
1770 } |
|
1771 if (iSimDataArray->MdcaPoint(i).MatchF(KTTFmax) |
|
1772 != KErrNotFound) |
|
1773 { |
|
1774 TDesTokeniser tokeniser(iSimDataArray->MdcaPoint(i)); |
|
1775 tokeniser.NextToken(KPosDataSeparator); |
|
1776 TPtrC8 value = tokeniser.NextToken(KPosDefaultDataEndMarker); |
|
1777 TLex8 lexer(value); |
|
1778 lexer.Val(ttfMax); |
|
1779 } |
|
1780 } |
|
1781 if (powerUpTime == 0) |
|
1782 { |
|
1783 User::Leave(KErrGeneral); |
|
1784 } |
|
1785 if (ttfMin == 0) |
|
1786 { |
|
1787 User::Leave(KErrGeneral); |
|
1788 } |
|
1789 if (ttfMax == 0) |
|
1790 { |
|
1791 User::Leave(KErrGeneral); |
|
1792 } |
|
1793 |
|
1794 TTimeIntervalMicroSeconds ttfMinMs; |
|
1795 TTimeIntervalMicroSeconds ttfMaxMs; |
|
1796 if (aPowerUp) |
|
1797 { |
|
1798 ttfMinMs = ttfMin * KToMs - aTolerance.Int64() + powerUpTime * KToMs; |
|
1799 ttfMaxMs = ttfMax * KToMs + aTolerance.Int64() + powerUpTime * KToMs; |
|
1800 } |
|
1801 else |
|
1802 { |
|
1803 ttfMinMs = ttfMin * KToMs - aTolerance.Int64(); |
|
1804 ttfMaxMs = ttfMax * KToMs + aTolerance.Int64(); |
|
1805 } |
|
1806 |
|
1807 if (ttfMinMs.Int64() > aReqTime.Int64() || |
|
1808 ttfMaxMs.Int64() < aReqTime.Int64()) |
|
1809 { |
|
1810 TBuf<50> output; |
|
1811 _LIT(KTTFTime, "TTFMin %d, TTFmax %d. TimeToFix was: %d"); |
|
1812 output.Format(KTTFTime, ttfMinMs.Int64(), ttfMaxMs.Int64(), aReqTime.Int64()); |
|
1813 LogErrorAndFail(output); |
|
1814 // User::Leave(KErrGeneral); |
|
1815 } |
|
1816 |
|
1817 TPosition pos; |
|
1818 aPos.GetPosition(pos); |
|
1819 TTime now; |
|
1820 now.UniversalTime(); |
|
1821 TInt nowInt = now.Int64(); |
|
1822 TInt reqIntDiff = (aReqTime.Int64() * 80) / 100; |
|
1823 TInt posInt = pos.Time().Int64(); |
|
1824 |
|
1825 if (nowInt != posInt && (nowInt - reqIntDiff) > posInt) |
|
1826 { |
|
1827 _LIT(KTime, "Position fix was made before 80% of requesttime."); |
|
1828 LogErrorAndFail(KTime); |
|
1829 } |
|
1830 } |
|
1831 |
|
1832 // --------------------------------------------------------- |
|
1833 // CSimPsyStep::CheckThatPositionExistsL |
|
1834 // (other items were commented in a header). |
|
1835 // --------------------------------------------------------- |
|
1836 // |
|
1837 void CSimPsyStep::CheckThatPositionExistsL(TPositionInfoBase& aInfo) |
|
1838 { |
|
1839 if (!&aInfo || aInfo.ModuleId().iUid != KSimModuleId) |
|
1840 { |
|
1841 _LIT(KNoPosition, "Request did not return a position"); |
|
1842 ERR_PRINTF1(KNoPosition); |
|
1843 User::Leave(KErrGeneral); |
|
1844 } |
|
1845 |
|
1846 if (aInfo.ModuleId().iUid != KSimModuleId) |
|
1847 { |
|
1848 _LIT(KWrongUid, "Expected simulationpsy uid"); |
|
1849 LogErrorAndFail(KWrongUid); |
|
1850 } |
|
1851 if (aInfo.UpdateType() != EPositionUpdateGeneral) |
|
1852 { |
|
1853 _LIT(KWrongUpType, "Expected Update Type General"); |
|
1854 LogErrorAndFail(KWrongUpType); |
|
1855 } |
|
1856 |
|
1857 } |
|
1858 |
|
1859 // --------------------------------------------------------- |
|
1860 // CSimPsyStep::ReadSimDataFromFileL |
|
1861 // (other items were commented in a header). |
|
1862 // --------------------------------------------------------- |
|
1863 // |
|
1864 void CSimPsyStep::ReadSimDataFromFileL(const TDesC& aFileName) |
|
1865 { |
|
1866 iFileReader->CloseResources(); |
|
1867 iSimDataArray->Reset(); |
|
1868 User::LeaveIfError(iFileReader->PrepareForRead(aFileName)); |
|
1869 iFileReader->ReadL(iSimDataArray, 10, EFalse); |
|
1870 iFileReader->CloseResources(); |
|
1871 } |
|
1872 |
|
1873 // --------------------------------------------------------- |
|
1874 // CSimPsyStep::SetSimDataFileL |
|
1875 // (other items were commented in a header). |
|
1876 // --------------------------------------------------------- |
|
1877 // |
|
1878 void CSimPsyStep::SetSimDataFileL(const TDesC& aFileName) |
|
1879 { |
|
1880 // Third version of settings simulation psy file |
|
1881 TFileName fileName = aFileName; |
|
1882 CRepository* repository = CRepository::NewLC(KCRUidSimulationPSY); |
|
1883 User::LeaveIfError(repository->Set(KCRKeySimPSYSimulationFile, fileName)); |
|
1884 CleanupStack::PopAndDestroy(repository); |
|
1885 } |
|
1886 |
|
1887 |
|
1888 TInt CSimPsyStep::Replace( |
|
1889 const TDesC& aFilename, |
|
1890 const TInt aFileMode) |
|
1891 { |
|
1892 _LIT(KIniFileBasePathFmt, "\\system\\data\\%S.ini"); |
|
1893 const TInt KPosIniFileNameMaxLength = 40; |
|
1894 RFs fsSession; |
|
1895 RFile file; |
|
1896 TInt err = KErrNone; |
|
1897 TBuf<KPosIniFileNameMaxLength> filename; |
|
1898 |
|
1899 filename.Format(KIniFileBasePathFmt, &aFilename); |
|
1900 if ((err = fsSession.Connect()) != KErrNone) |
|
1901 { |
|
1902 return err; |
|
1903 } |
|
1904 if ((err = file.Replace(fsSession, filename, aFileMode)) != KErrNone) |
|
1905 { |
|
1906 fsSession.Close(); |
|
1907 return err; |
|
1908 } |
|
1909 file.Close(); |
|
1910 fsSession.Close(); |
|
1911 |
|
1912 return KErrNone; |
|
1913 } |
|
1914 |
|
1915 // End of File |