|
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 // INCLUDE FILES |
|
19 #include "ctlbsclientperiodictester.h" |
|
20 #include "ctlbsclientlog.h" |
|
21 |
|
22 // CONSTANTS |
|
23 const TInt KSmallestUpdateIntervalToLog = 4000000; //2000000 |
|
24 const TInt KMilliSecondTolerance = 2500000; //One second |
|
25 |
|
26 // ============================ MEMBER FUNCTIONS =============================== |
|
27 |
|
28 // ----------------------------------------------------------------------------- |
|
29 // CPeriodicTester::CPeriodicTester |
|
30 // C++ default constructor can NOT contain any code, that |
|
31 // might leave. |
|
32 // ----------------------------------------------------------------------------- |
|
33 // |
|
34 CT_LbsClientPeriodicTester::CT_LbsClientPeriodicTester() : CActive(CActive::EPriorityHigh), iError(EFalse), iErrorCode(KErrNone) |
|
35 { |
|
36 } |
|
37 |
|
38 // ----------------------------------------------------------------------------- |
|
39 // CPeriodicTester::ConstructL |
|
40 // |
|
41 // Symbian 2nd phase constructor can leave. |
|
42 // ----------------------------------------------------------------------------- |
|
43 // |
|
44 void CT_LbsClientPeriodicTester::ConstructL( |
|
45 TTimeIntervalMicroSeconds aInterval, |
|
46 const TDesC& aServiceName, |
|
47 CT_LbsClientLog* aLog, |
|
48 TUid aUid, |
|
49 TInt aNumberOfRuns) |
|
50 { |
|
51 iLog = aLog; |
|
52 iName = aServiceName; |
|
53 iNumberOfRuns = aNumberOfRuns; |
|
54 iInterval = aInterval; |
|
55 iUid = aUid; |
|
56 iNumberOfUpdates = 0; |
|
57 iPrematureChangeOfParameters = EFalse; |
|
58 iCanceledRequest = EFalse; |
|
59 iCancelRequest = EFalse; |
|
60 iWriteToLog = ETrue; //EFalse |
|
61 iRecentTime = TTime(0); |
|
62 iPositionInfo = TPositionInfo(); |
|
63 |
|
64 _LIT(KConnectErr, "Error when connecing to EPos server, %d"); |
|
65 TInt err = iPosServer.Connect(); |
|
66 AssertTrueL(err == KErrNone, KConnectErr, err); |
|
67 |
|
68 _LIT(KOpenErr, "Error when opening positioner, %d"); |
|
69 err = iPositioner.Open(iPosServer, aUid); |
|
70 AssertTrueL(err == KErrNone, KOpenErr, err); |
|
71 |
|
72 TPositionUpdateOptions posOption; |
|
73 posOption.SetUpdateInterval(aInterval); |
|
74 |
|
75 _LIT(KUpdateErr, "Error when setting update interval, %d"); |
|
76 err = iPositioner.SetUpdateOptions(posOption); |
|
77 AssertTrueL(err == KErrNone, KUpdateErr, err); |
|
78 |
|
79 iPositioner.SetRequestor(CRequestor::ERequestorService, |
|
80 CRequestor::EFormatApplication, aServiceName); |
|
81 |
|
82 CActiveScheduler::Add(this); |
|
83 } |
|
84 |
|
85 // ----------------------------------------------------------------------------- |
|
86 // CPeriodicTester::NewL |
|
87 // |
|
88 // Two-phased constructor. |
|
89 // ----------------------------------------------------------------------------- |
|
90 // |
|
91 CT_LbsClientPeriodicTester* CT_LbsClientPeriodicTester::NewL( |
|
92 TTimeIntervalMicroSeconds aInterval, |
|
93 const TDesC& aServiceName, |
|
94 CT_LbsClientLog* aLog, |
|
95 TUid aUid, |
|
96 TInt aNumberOfRuns) |
|
97 { |
|
98 CT_LbsClientPeriodicTester* self = new( ELeave ) CT_LbsClientPeriodicTester; |
|
99 |
|
100 CleanupStack::PushL(self); |
|
101 self->ConstructL(aInterval, aServiceName, aLog, aUid, aNumberOfRuns); |
|
102 CleanupStack::Pop(); |
|
103 |
|
104 return self; |
|
105 } |
|
106 |
|
107 |
|
108 // Destructor |
|
109 CT_LbsClientPeriodicTester::~CT_LbsClientPeriodicTester() |
|
110 { |
|
111 iPositioner.Close(); |
|
112 iPosServer.Close(); |
|
113 |
|
114 iLog = NULL; |
|
115 } |
|
116 |
|
117 // ----------------------------------------------------------------------------- |
|
118 // CPeriodicTester::RunL |
|
119 // |
|
120 // (other items were commented in a header). |
|
121 // ----------------------------------------------------------------------------- |
|
122 // |
|
123 void CT_LbsClientPeriodicTester::RunL() |
|
124 { |
|
125 iNumberOfUpdates++; |
|
126 //User::Leave(-10); //used for testing the test code |
|
127 TBuf<175> buf; |
|
128 _LIT(KStatus,"Status invalid in RunL, status = %d"); |
|
129 buf.Format(KStatus, iStatus.Int()); |
|
130 AssertTrueL((iStatus == KErrNone || iStatus == KPositionQualityLoss || |
|
131 iStatus == KErrCancel), buf, iStatus.Int()); |
|
132 if(iNumberOfUpdates <= iNumberOfRuns) |
|
133 { |
|
134 _LIT(KTime, "%F%H:%F%T:%F%S:%F%*C3"); |
|
135 TBuf<100> time; |
|
136 TTime now; |
|
137 now.UniversalTime(); |
|
138 TInt difference; |
|
139 TInt smallestIntervalToLog = KSmallestUpdateIntervalToLog; |
|
140 if(iNumberOfUpdates == 1) |
|
141 { |
|
142 difference = I64LOW(now.MicroSecondsFrom(iRecentTime).Int64()); |
|
143 } |
|
144 else |
|
145 { |
|
146 difference = I64LOW(now.MicroSecondsFrom(iRecentTime).Int64()); |
|
147 } |
|
148 |
|
149 _LIT(KInterval, "The interval is %d, and the difference is %d"); |
|
150 TBuf<150> buf; |
|
151 buf.Format(KInterval,iInterval.Int64(), difference); |
|
152 iLog->Put (buf); |
|
153 if((iInterval.Int64() > smallestIntervalToLog) && (I64LOW(iRecentTime.Int64()) != 0)) |
|
154 { |
|
155 _LIT(KTimeErr, "ERROR: Time difference greater than tolerated interval, time difference = %d"); |
|
156 AssertTrueL(difference < (iInterval.Int64() + KMilliSecondTolerance), KTimeErr, I64LOW(now.MicroSecondsFrom(iRecentTime).Int64())); |
|
157 |
|
158 if(difference < 0) |
|
159 { |
|
160 #ifdef __WINS__ |
|
161 _LIT(KEarlyErr, "ERROR: Negative time difference on WINS greater than 0.4s"); |
|
162 AssertTrueL((KToleratedEarliness > -(difference)), KEarlyErr, KErrTotalLossOfPrecision); |
|
163 #else |
|
164 _LIT(KEarlyErr, "ERROR: Time difference negative on target"); |
|
165 iLog->Put(KEarlyErr); |
|
166 User::LeaveIfError(KErrTotalLossOfPrecision); |
|
167 #endif |
|
168 |
|
169 } |
|
170 } |
|
171 |
|
172 if(iWriteToLog && ((iNumberOfUpdates % KTracePeriod) == 0)) |
|
173 { |
|
174 now.UniversalTime(); |
|
175 now.FormatL(time, KTime); |
|
176 _LIT(KLog, "Client got update no. %d at %S, Time-diff = %d, Status = "); |
|
177 TBuf<175> buf; |
|
178 buf.Format(KLog, iNumberOfUpdates, &time, difference); |
|
179 buf.AppendNum(iStatus.Int()); |
|
180 buf.Append(iName); |
|
181 _LIT(KNrOfRuns, "Nr of runs = "); |
|
182 buf.Append(KNrOfRuns); |
|
183 buf.AppendNum(iNumberOfRuns); |
|
184 iLog->Put(buf); |
|
185 } |
|
186 |
|
187 if(iPrematureChangeOfParameters) |
|
188 { |
|
189 iInterval = TTimeIntervalMicroSeconds(2000000); |
|
190 User::After(I64LOW(iInterval.Int64())); |
|
191 |
|
192 TPositionUpdateOptions posOption; |
|
193 posOption.SetUpdateInterval(iInterval); |
|
194 |
|
195 TInt err = iPositioner.SetUpdateOptions(posOption); |
|
196 _LIT(KChange, "ERROR: Got error code when setting update options prematurely in ChangeTestParameters"); |
|
197 AssertTrueL(err == KErrNone, KChange, err); |
|
198 iPrematureChangeOfParameters = EFalse; |
|
199 } |
|
200 |
|
201 RequestNotification(); |
|
202 |
|
203 if(iCancelRequest) |
|
204 { |
|
205 User::After(3000000); |
|
206 iPositioner.CancelRequest(EPositionerNotifyPositionUpdate); |
|
207 iCancelRequest = EFalse; |
|
208 iCanceledRequest = ETrue; |
|
209 } |
|
210 |
|
211 if(iCanceledRequest) |
|
212 { |
|
213 iCanceledRequest = EFalse; |
|
214 _LIT(KCancelErr, "ERROR: Status was not KErrCancel after CancelRequest"); |
|
215 AssertTrueL(iStatus.Int() == KErrCancel, KCancelErr, KErrCancel); |
|
216 } |
|
217 } |
|
218 else |
|
219 { |
|
220 CActiveScheduler::Stop(); |
|
221 } |
|
222 |
|
223 } |
|
224 |
|
225 |
|
226 // ----------------------------------------------------------------------------- |
|
227 // CT_LbsClientPeriodicTester::RunError |
|
228 // |
|
229 // (other items were commented in a header). |
|
230 // ----------------------------------------------------------------------------- |
|
231 // |
|
232 TInt CT_LbsClientPeriodicTester::RunError(TInt aError) |
|
233 { |
|
234 iError = ETrue; |
|
235 iErrorCode = aError; |
|
236 CActiveScheduler::Stop(); |
|
237 _LIT(KErrorInRunL, "Error code in RunError is, %d"); |
|
238 TBuf<100> buf; |
|
239 buf.Format(KErrorInRunL, aError); |
|
240 iLog -> Put(buf); |
|
241 return KErrNone; |
|
242 } |
|
243 |
|
244 |
|
245 // ----------------------------------------------------------------------------- |
|
246 // CT_LbsClientPeriodicTester::IsCompletedOK |
|
247 // |
|
248 // (other items were commented in a header). |
|
249 // ----------------------------------------------------------------------------- |
|
250 // |
|
251 TBool CT_LbsClientPeriodicTester::IsCompletedOK() |
|
252 { |
|
253 return !iError; |
|
254 } |
|
255 |
|
256 // ----------------------------------------------------------------------------- |
|
257 // CT_LbsClientPeriodicTester::GetError |
|
258 // |
|
259 // (other items were commented in a header). |
|
260 // ----------------------------------------------------------------------------- |
|
261 // |
|
262 TInt CT_LbsClientPeriodicTester::GetError() |
|
263 { |
|
264 return iErrorCode; |
|
265 } |
|
266 |
|
267 // ----------------------------------------------------------------------------- |
|
268 // CT_LbsClientPeriodicTester::ChangeTestParametersL |
|
269 // |
|
270 // (other items were commented in a header). |
|
271 // ----------------------------------------------------------------------------- |
|
272 // |
|
273 void CT_LbsClientPeriodicTester::ChangeTestParametersL(TTimeIntervalMicroSeconds aInterval, TInt aNumberOfRuns) |
|
274 { |
|
275 iNumberOfRuns = aNumberOfRuns; |
|
276 iNumberOfUpdates = 0; |
|
277 iInterval = aInterval; |
|
278 iRecentTime = TTime(0); |
|
279 iError = EFalse; |
|
280 iErrorCode = KErrNone; |
|
281 |
|
282 TPositionUpdateOptions posOption; |
|
283 posOption.SetUpdateInterval(aInterval); |
|
284 |
|
285 TInt err = iPositioner.SetUpdateOptions(posOption); |
|
286 _LIT(KChange, "ERROR: When setting update options in ChangeTestParameters, err: %d"); |
|
287 AssertTrueL(err == KErrNone, KChange, err); |
|
288 } |
|
289 |
|
290 // ----------------------------------------------------------------------------- |
|
291 // CT_LbsClientPeriodicTester::ChangeRequestorInformation |
|
292 // |
|
293 // (other items were commented in a header). |
|
294 // ----------------------------------------------------------------------------- |
|
295 // |
|
296 void CT_LbsClientPeriodicTester::ChangeRequestorInformation(const TDesC& aServiceName) |
|
297 { |
|
298 iPositioner.SetRequestor(CRequestor::ERequestorService, |
|
299 CRequestor::EFormatApplication, aServiceName); |
|
300 } |
|
301 |
|
302 // ----------------------------------------------------------------------------- |
|
303 // CT_LbsClientPeriodicTester::ClosePositioner |
|
304 // |
|
305 // (other items were commented in a header). |
|
306 // ----------------------------------------------------------------------------- |
|
307 // |
|
308 void CT_LbsClientPeriodicTester::ClosePositioner() |
|
309 { |
|
310 iPositioner.Close(); |
|
311 } |
|
312 |
|
313 // ----------------------------------------------------------------------------- |
|
314 // CT_LbsClientPeriodicTester::OpenPositionerL |
|
315 // |
|
316 // (other items were commented in a header). |
|
317 // ----------------------------------------------------------------------------- |
|
318 // |
|
319 void CT_LbsClientPeriodicTester::OpenPositionerL(const TDesC& aServiceName) |
|
320 { |
|
321 _LIT(KOpenErr, "Error when opening positioner, %d"); |
|
322 TInt err = iPositioner.Open(iPosServer, iUid); |
|
323 AssertTrueL(err == KErrNone, KOpenErr, err); |
|
324 |
|
325 iPositioner.SetRequestor(CRequestor::ERequestorService, |
|
326 CRequestor::EFormatApplication, aServiceName); |
|
327 } |
|
328 |
|
329 // ----------------------------------------------------------------------------- |
|
330 // CT_LbsClientPeriodicTester::SetMaxAgeL |
|
331 // |
|
332 // (other items were commented in a header). |
|
333 // ----------------------------------------------------------------------------- |
|
334 // |
|
335 void CT_LbsClientPeriodicTester::SetMaxAgeL(TTimeIntervalMicroSeconds aInterval) |
|
336 { |
|
337 TPositionUpdateOptions posOption; |
|
338 posOption.SetUpdateInterval(iInterval); |
|
339 posOption.SetMaxUpdateAge(aInterval); |
|
340 |
|
341 TInt err = iPositioner.SetUpdateOptions(posOption); |
|
342 _LIT(KChange, "ERROR: When setting max age in SetMaxAge, err: %d"); |
|
343 AssertTrueL(err == KErrNone, KChange, err); |
|
344 } |
|
345 |
|
346 // ----------------------------------------------------------------------------- |
|
347 // CT_LbsClientPeriodicTester::SetPartialUpdateL |
|
348 // |
|
349 // (other items were commented in a header). |
|
350 // ----------------------------------------------------------------------------- |
|
351 // |
|
352 void CT_LbsClientPeriodicTester::SetPartialUpdateL(TBool aUpdateOption) |
|
353 { |
|
354 TPositionUpdateOptions posOption; |
|
355 posOption.SetUpdateInterval(iInterval); |
|
356 posOption.SetAcceptPartialUpdates(aUpdateOption); |
|
357 |
|
358 TInt err = iPositioner.SetUpdateOptions(posOption); |
|
359 _LIT(KChange, "ERROR: When setting partial update in SetPartialUpdate, err: %d"); |
|
360 AssertTrueL(err == KErrNone, KChange, err); |
|
361 } |
|
362 |
|
363 // ----------------------------------------------------------------------------- |
|
364 // CT_LbsClientPeriodicTester::SetTimeOutL |
|
365 // |
|
366 // (other items were commented in a header). |
|
367 // ----------------------------------------------------------------------------- |
|
368 // |
|
369 void CT_LbsClientPeriodicTester::SetTimeOutL(TTimeIntervalMicroSeconds aInterval) |
|
370 { |
|
371 TPositionUpdateOptions posOption; |
|
372 posOption.SetUpdateInterval(iInterval); |
|
373 posOption.SetUpdateTimeOut(aInterval); |
|
374 |
|
375 TInt err = iPositioner.SetUpdateOptions(posOption); |
|
376 _LIT(KChange, "ERROR: When setting timeout in SetTimeOut"); |
|
377 AssertTrueL(err == KErrNone, KChange, err); |
|
378 } |
|
379 |
|
380 // ----------------------------------------------------------------------------- |
|
381 // CT_LbsClientPeriodicTester::SetChangeParametersPrematurely |
|
382 // |
|
383 // (other items were commented in a header). |
|
384 // ----------------------------------------------------------------------------- |
|
385 // |
|
386 void CT_LbsClientPeriodicTester::SetChangeParametersPrematurely(TBool aCondition) |
|
387 { |
|
388 iPrematureChangeOfParameters = aCondition; |
|
389 } |
|
390 |
|
391 // ----------------------------------------------------------------------------- |
|
392 // CT_LbsClientPeriodicTester::CancelRequest |
|
393 // |
|
394 // (other items were commented in a header). |
|
395 // ----------------------------------------------------------------------------- |
|
396 // |
|
397 void CT_LbsClientPeriodicTester::CancelRequest() |
|
398 { |
|
399 iCancelRequest= ETrue; |
|
400 iCanceledRequest = EFalse; |
|
401 } |
|
402 |
|
403 |
|
404 // ----------------------------------------------------------------------------- |
|
405 // CT_LbsClientPeriodicTester::RequestNotification |
|
406 // |
|
407 // (other items were commented in a header). |
|
408 // ----------------------------------------------------------------------------- |
|
409 // |
|
410 void CT_LbsClientPeriodicTester::RequestNotification() |
|
411 { |
|
412 TTime now; |
|
413 now.UniversalTime(); |
|
414 iRecentTime = now; |
|
415 iPositioner.NotifyPositionUpdate(iPositionInfo, iStatus); |
|
416 SetActive(); |
|
417 } |
|
418 |
|
419 // ----------------------------------------------------------------------------- |
|
420 // CT_LbsClientPeriodicTester::RequestNotification |
|
421 // |
|
422 // (other items were commented in a header). |
|
423 // ----------------------------------------------------------------------------- |
|
424 // |
|
425 void CT_LbsClientPeriodicTester::GetPosition(TPositionInfo& aPosInfo) |
|
426 { |
|
427 aPosInfo = iPositionInfo; |
|
428 } |
|
429 |
|
430 // ----------------------------------------------------------------------------- |
|
431 // CT_LbsClientPeriodicTester::DoCancel |
|
432 // |
|
433 // (other items were commented in a header). |
|
434 // ----------------------------------------------------------------------------- |
|
435 // |
|
436 void CT_LbsClientPeriodicTester::DoCancel() |
|
437 { |
|
438 } |
|
439 |
|
440 // --------------------------------------------------------- |
|
441 // CT_LbsClientPeriodicTester::AssertTrueL |
|
442 // |
|
443 // (other items were commented in a header). |
|
444 // --------------------------------------------------------- |
|
445 // |
|
446 void CT_LbsClientPeriodicTester::AssertTrueL(TBool aCondition, const TDesC& aErrorMsg, TInt aErrorCode) |
|
447 { |
|
448 if (!aCondition) |
|
449 { |
|
450 TBuf<100> buf; |
|
451 buf.Format(aErrorMsg, aErrorCode); |
|
452 iLog->Put(buf); |
|
453 User::Leave(aErrorCode); |
|
454 } |
|
455 } |
|
456 |
|
457 // End of File |