|
1 // Copyright (c) 1997-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 // Test effects of changing TLocale on clock alarms |
|
15 // Test alarms which are skipped over by advancing the time or revived by putting back the time. |
|
16 // Test for when time is advanced or put back by changes to the locale, i.e: |
|
17 // Turning daylight saving on and off and |
|
18 // Increasing and decreasing GMT offset. |
|
19 // The expected results for advancing or putting back the time are the same whether caused by changes |
|
20 // to daylight saving or GMT offset. |
|
21 // Test effects of altering workdays on workday repeated alarms |
|
22 // |
|
23 // |
|
24 |
|
25 #include "ASTstAlarmTest.h" |
|
26 #include "testserver.h" |
|
27 #include <tz.h> |
|
28 |
|
29 static TRequestStatus TheStatus; |
|
30 static TTime TheInitialAlarmTime; |
|
31 static TTime TheExtendedAlarmTime; |
|
32 static TTime TheOriginalTime; |
|
33 static TTime TheCurrentTime; |
|
34 static TAlarmId TheClockAlarmSlots[8] = { KNullAlarmId, KNullAlarmId, KNullAlarmId, KNullAlarmId, KNullAlarmId, KNullAlarmId, KNullAlarmId, KNullAlarmId }; |
|
35 |
|
36 // Use the Time Zone Server if available. |
|
37 static RTz timezone; |
|
38 |
|
39 // This gets us a time which isn't close to a minute boundary: |
|
40 // It also sets the microseconds to 0, since alarms ignore it and comparison functions don't. |
|
41 static void SafeHomeTime(TTime& aTime) |
|
42 { |
|
43 TInt sec; |
|
44 do |
|
45 { |
|
46 aTime.HomeTime(); |
|
47 TDateTime dt(aTime.DateTime()); |
|
48 sec = dt.Second(); |
|
49 |
|
50 if(sec > 55 || sec < 5) |
|
51 { |
|
52 // dont loop full speed, there's no point: |
|
53 User::After(1000000); |
|
54 } |
|
55 else |
|
56 { |
|
57 dt.SetMicroSecond(0); |
|
58 aTime = dt; |
|
59 } |
|
60 } |
|
61 while(sec > 55 || sec < 5); |
|
62 } |
|
63 |
|
64 static void CheckTimesAreEqual(const TTime& aExpectedTime, const TTime& aActualTime, TInt aLineNum) |
|
65 // |
|
66 // Compare times to required degree of precision |
|
67 // |
|
68 { |
|
69 // determine the difference, in seconds |
|
70 TTimeIntervalSeconds timeDiffSeconds; |
|
71 const TInt error = aExpectedTime.SecondsFrom(aActualTime, timeDiffSeconds); |
|
72 |
|
73 TheAlarmTest(error == KErrNone, __LINE__); |
|
74 |
|
75 // check the times are within 1min |
|
76 // as alarms are rounded to the minute |
|
77 const TTimeIntervalSeconds maxDiff(60); |
|
78 const TTimeIntervalSeconds minDiff(-60); |
|
79 |
|
80 if ((timeDiffSeconds > maxDiff) || (timeDiffSeconds < minDiff)) |
|
81 { |
|
82 TheAlarmTest.Test().Printf( |
|
83 _L("Compared times more than 1 minute different (%u) at line %u"), |
|
84 timeDiffSeconds.Int(), |
|
85 aLineNum); |
|
86 TheAlarmTest(EFalse, __LINE__); |
|
87 } |
|
88 } |
|
89 |
|
90 /** |
|
91 Sets the system time of the device to the given local (wall-clock) time. |
|
92 |
|
93 @param aTime The time to set. |
|
94 @internalComponent |
|
95 */ |
|
96 static void SetHomeTime(const TTime& aTime) |
|
97 { |
|
98 TInt err = timezone.SetHomeTime(aTime); |
|
99 TheAlarmTest(err == KErrNone, __LINE__); |
|
100 } |
|
101 |
|
102 |
|
103 |
|
104 // If aDszOn is true, set to a time in BST. |
|
105 // If aDszOn is false, set to a time in GMT. |
|
106 static void EnableDaylightSavingL(TBool aDszOn) |
|
107 { |
|
108 // Using TLocale to set daylight saving mode no longer works, since this is controlled by |
|
109 // the Time Zone Server. Instead the time must be set such that DST rules are in force in a |
|
110 // locale where such rules apply, e.g. 01-06-2004 12:00 BST. |
|
111 |
|
112 // Set the time zone to a known location. |
|
113 _LIT8(KTZName, "Europe/London"); |
|
114 CTzId* zoneId = CTzId::NewL(KTZName); |
|
115 CleanupStack::PushL(zoneId); |
|
116 timezone.SetTimeZoneL(*zoneId); |
|
117 CleanupStack::PopAndDestroy(zoneId); |
|
118 |
|
119 // Set daylight saving time on/off. Note that when DST is set 'on' a DST change event occurs |
|
120 // almost immediately - this tests that the Alarm Queue is updated correctly for DST events. |
|
121 |
|
122 if (aDszOn) |
|
123 { |
|
124 // Set the system time to a time in the British Summer: 31-10-2004 01:59:58 BST = 00:59:00 UTC |
|
125 const TInt KBstOffset = 3600; |
|
126 _LIT(KTime, "20040930:005958.000000"); // Just before the DST change. |
|
127 TInt err = User::SetUTCTimeAndOffset(TTime(KTime), KBstOffset); |
|
128 TheAlarmTest(err == KErrNone, __LINE__); |
|
129 } |
|
130 else |
|
131 { |
|
132 // Set the system time to a time in the British Winter: 31-10-2004 01:00:00 GMT = 01:00:00 UTC |
|
133 const TInt KGmtOffset = 0; |
|
134 _LIT(KTime, "20040930:010000.000000"); // Just after the DST change. |
|
135 TInt err = User::SetUTCTimeAndOffset(TTime(KTime), KGmtOffset); |
|
136 TheAlarmTest(err == KErrNone, __LINE__); |
|
137 } |
|
138 } |
|
139 |
|
140 |
|
141 static TTime SetClockAlarms(const TTime& aBaseTime, const TTimeIntervalMinutes& aOffset) |
|
142 // |
|
143 // Set Alarms. |
|
144 // Extra alarm when putting clocks back to see what happen to |
|
145 // weekly alarm set for 6 days & 23 1/2 hours time |
|
146 // |
|
147 { |
|
148 TInt r; |
|
149 TASShdAlarm alarm; |
|
150 const TInt n = TheAlarmTest.Session().NumberOfAlarmsActiveInQueue(); |
|
151 TheAlarmTest(n == 0, __LINE__); |
|
152 // |
|
153 TTime timeForAlarms(aBaseTime); |
|
154 timeForAlarms += aOffset; |
|
155 |
|
156 // Once Only |
|
157 alarm.Reset(); |
|
158 alarm.Message().Num(0); |
|
159 alarm.NextDueTime() = timeForAlarms; |
|
160 alarm.RepeatDefinition() = EAlarmRepeatDefintionRepeatOnce; |
|
161 r = TheAlarmTest.Session().AlarmAdd(alarm); |
|
162 TheAlarmTest(r == KErrNone, __LINE__); |
|
163 TheClockAlarmSlots[0] = alarm.Id(); |
|
164 |
|
165 // Next 24 hours |
|
166 alarm.Reset(); |
|
167 alarm.Message().Num(1); |
|
168 alarm.NextDueTime() = timeForAlarms; |
|
169 alarm.RepeatDefinition() = EAlarmRepeatDefintionRepeatNext24Hours; |
|
170 r = TheAlarmTest.Session().AlarmAdd(alarm); |
|
171 TheAlarmTest(r == KErrNone, __LINE__); |
|
172 TheClockAlarmSlots[1] = alarm.Id(); |
|
173 |
|
174 // Clock daily |
|
175 alarm.Reset(); |
|
176 alarm.Message().Num(2); |
|
177 alarm.NextDueTime() = timeForAlarms; |
|
178 alarm.RepeatDefinition() = EAlarmRepeatDefintionRepeatDaily; |
|
179 r = TheAlarmTest.Session().AlarmAdd(alarm); |
|
180 TheAlarmTest(r == KErrNone, __LINE__); |
|
181 TheClockAlarmSlots[2] = alarm.Id(); |
|
182 |
|
183 // Clock weekly |
|
184 alarm.Reset(); |
|
185 alarm.Message().Num(3); |
|
186 alarm.NextDueTime() = timeForAlarms; |
|
187 alarm.RepeatDefinition() = EAlarmRepeatDefintionRepeatWeekly; |
|
188 r = TheAlarmTest.Session().AlarmAdd(alarm); |
|
189 TheAlarmTest(r == KErrNone, __LINE__); |
|
190 TheClockAlarmSlots[3] = alarm.Id(); |
|
191 |
|
192 if (aOffset.Int() < 0) |
|
193 { |
|
194 TheExtendedAlarmTime = timeForAlarms; |
|
195 TheExtendedAlarmTime += TTimeIntervalDays(7); |
|
196 alarm.Message().Num(4); |
|
197 alarm.RepeatDefinition() = EAlarmRepeatDefintionRepeatWeekly; |
|
198 alarm.NextDueTime() = TheExtendedAlarmTime; |
|
199 r = TheAlarmTest.Session().AlarmAdd(alarm); |
|
200 TheAlarmTest(r == KErrNone, __LINE__); |
|
201 TheClockAlarmSlots[4] = alarm.Id(); |
|
202 } |
|
203 |
|
204 return timeForAlarms; |
|
205 } |
|
206 |
|
207 /** |
|
208 Checks that the alarms are correct. |
|
209 |
|
210 // |
|
211 // We expect and test that: |
|
212 // |
|
213 // 1) Once alarm to remain unchanged at initial alarm time |
|
214 // unless allowed time to complete. |
|
215 // |
|
216 // 2) Next24 to advance to the first 'initial alarm time' |
|
217 // falling due after the original time |
|
218 // |
|
219 // 3a) If before clocks go back, Weekly (set previously) to |
|
220 // advance to the 'initial alarm time' in the next week |
|
221 // |
|
222 // 3b) If after clocks go back, Weekly (set previously) to |
|
223 // return to the 'initial alarm time' in the current week |
|
224 // |
|
225 // 4a) If before clocks go back, Weekly (set for next week) |
|
226 // to remain at the 'extended alarm time' in the next week |
|
227 // |
|
228 // 4b) If after clocks go back, Weekly (set for next week) to |
|
229 // move back to 'initial alarm time' in the current week |
|
230 // |
|
231 |
|
232 @param aInterveningOffsetChange True when a change in the UTC offset occurs |
|
233 between setting the alarms and testing them. |
|
234 @param aOnceCompleted True if the "Repeat Once" alarm has completed. |
|
235 @internalComponent |
|
236 */ |
|
237 static void VerifyAlarmsAreCorrect(TBool aInterveningOffsetChange, TBool aOnceCompleted) |
|
238 { |
|
239 TInt ret; |
|
240 TTime setTime; |
|
241 TASShdAlarm alarm; |
|
242 TAlarmId alarmId; |
|
243 TTime time; |
|
244 time.HomeTime(); |
|
245 |
|
246 // Check Once repeat if it has not completed. |
|
247 if (!aOnceCompleted) |
|
248 { |
|
249 alarmId = TheClockAlarmSlots[0]; |
|
250 TheAlarmTest(alarmId != KNullAlarmId, __LINE__); |
|
251 ret = TheAlarmTest.Session().GetAlarmDetails(alarmId, alarm); |
|
252 TheAlarmTest(ret == KErrNone, __LINE__); |
|
253 CheckTimesAreEqual(TheInitialAlarmTime, alarm.NextDueTime(), __LINE__); |
|
254 } |
|
255 |
|
256 // Check Next 24 hours repeat |
|
257 alarmId = TheClockAlarmSlots[1]; |
|
258 TheAlarmTest(alarmId != KNullAlarmId, __LINE__); |
|
259 ret = TheAlarmTest.Session().GetAlarmDetails(alarmId, alarm); |
|
260 TheAlarmTest(ret == KErrNone, __LINE__); |
|
261 setTime = TheInitialAlarmTime; |
|
262 |
|
263 // The alarm was set in the past, so add repeat interval. |
|
264 setTime += TTimeIntervalHours(+24); |
|
265 |
|
266 CheckTimesAreEqual(setTime, alarm.NextDueTime(), __LINE__); |
|
267 |
|
268 // Check daily repeat |
|
269 alarmId = TheClockAlarmSlots[2]; |
|
270 TheAlarmTest(alarmId != KNullAlarmId, __LINE__); |
|
271 ret = TheAlarmTest.Session().GetAlarmDetails(alarmId, alarm); |
|
272 TheAlarmTest(ret == KErrNone, __LINE__); |
|
273 setTime = TheInitialAlarmTime; |
|
274 |
|
275 if (aInterveningOffsetChange) |
|
276 { |
|
277 // The alarm was set in the past, so add repeat interval. |
|
278 setTime += TTimeIntervalHours(+24); |
|
279 } |
|
280 |
|
281 CheckTimesAreEqual(setTime, alarm.NextDueTime(), __LINE__); |
|
282 |
|
283 // Check weekly repeat |
|
284 alarmId = TheClockAlarmSlots[3]; |
|
285 TheAlarmTest(alarmId != KNullAlarmId, __LINE__); |
|
286 ret = TheAlarmTest.Session().GetAlarmDetails(alarmId, alarm); |
|
287 TheAlarmTest(ret == KErrNone, __LINE__); |
|
288 setTime = TheInitialAlarmTime; |
|
289 |
|
290 if (aInterveningOffsetChange) |
|
291 { |
|
292 // The alarm was set in the past, so add repeat interval. |
|
293 setTime += TTimeIntervalDays(+7); |
|
294 } |
|
295 |
|
296 CheckTimesAreEqual(setTime, alarm.NextDueTime(), __LINE__); |
|
297 |
|
298 // Check weekly repeat |
|
299 alarmId = TheClockAlarmSlots[4]; |
|
300 TheAlarmTest(alarmId != KNullAlarmId, __LINE__); |
|
301 ret = TheAlarmTest.Session().GetAlarmDetails(alarmId, alarm); |
|
302 TheAlarmTest(ret == KErrNone, __LINE__); |
|
303 |
|
304 if (aInterveningOffsetChange) |
|
305 { |
|
306 setTime = TheExtendedAlarmTime; |
|
307 } |
|
308 else |
|
309 { |
|
310 setTime = TheInitialAlarmTime; |
|
311 } |
|
312 |
|
313 CheckTimesAreEqual(setTime, alarm.NextDueTime(), __LINE__); |
|
314 } |
|
315 |
|
316 static void testAlarmsOnForwardingClocks(TBool aAfterClocksGoForward, TBool aAlarmsSetInPast, TBool aAlarmsShouldAllBeQueued = ETrue) |
|
317 // |
|
318 // We expect and test that: |
|
319 // 1) Once alarm to remain unchanged at 'initial alarm time' |
|
320 // 2) Next24 to remain at the 'initial alarm time' |
|
321 // 3a) If before clocks go forward, Weekly to remain at the |
|
322 // 'initial alarm time' |
|
323 // 3b) If after clocks go forward, Weekly to advance to 'initial |
|
324 // alarm time' in the next week |
|
325 // |
|
326 { |
|
327 TInt ret; |
|
328 TASShdAlarm alarm; |
|
329 TAlarmId alarmId; |
|
330 TTime setTime; |
|
331 |
|
332 // Check Once repeat |
|
333 alarmId = TheClockAlarmSlots[0]; |
|
334 ret = TheAlarmTest.Session().GetAlarmDetails(alarmId, alarm); |
|
335 setTime = TheInitialAlarmTime; |
|
336 |
|
337 // Note that the time of the expected alarm should be the same as when |
|
338 // originally set. No adjustment for any UTC offset is required. |
|
339 if (aAlarmsShouldAllBeQueued) |
|
340 { |
|
341 TheAlarmTest(ret == KErrNone, __LINE__); |
|
342 } |
|
343 |
|
344 if (ret == KErrNone && alarm.Status() == EAlarmStatusEnabled) |
|
345 { |
|
346 CheckTimesAreEqual(setTime, alarm.NextDueTime(), __LINE__); |
|
347 } |
|
348 |
|
349 // Check Next 24 hours repeat |
|
350 alarmId = TheClockAlarmSlots[1]; |
|
351 ret = TheAlarmTest.Session().GetAlarmDetails(alarmId, alarm); |
|
352 setTime = TheInitialAlarmTime; |
|
353 |
|
354 if (aAlarmsShouldAllBeQueued) |
|
355 { |
|
356 TheAlarmTest(ret == KErrNone, __LINE__); |
|
357 } |
|
358 |
|
359 if (ret == KErrNone && alarm.Status() == EAlarmStatusEnabled) |
|
360 { |
|
361 CheckTimesAreEqual(setTime, alarm.NextDueTime(), __LINE__); |
|
362 } |
|
363 |
|
364 // Check daily repeat |
|
365 alarmId = TheClockAlarmSlots[2]; |
|
366 TheAlarmTest(alarmId != KNullAlarmId, __LINE__); |
|
367 ret = TheAlarmTest.Session().GetAlarmDetails(alarmId, alarm); |
|
368 setTime = TheInitialAlarmTime; |
|
369 |
|
370 if (aAlarmsShouldAllBeQueued) |
|
371 { |
|
372 TheAlarmTest(ret == KErrNone, __LINE__); |
|
373 } |
|
374 |
|
375 CheckTimesAreEqual(setTime, alarm.NextDueTime(), __LINE__); |
|
376 |
|
377 // Check weekly repeat |
|
378 alarmId = TheClockAlarmSlots[3]; |
|
379 TheAlarmTest(alarmId != KNullAlarmId, __LINE__); |
|
380 ret = TheAlarmTest.Session().GetAlarmDetails(alarmId, alarm); |
|
381 |
|
382 if (aAlarmsShouldAllBeQueued) |
|
383 { |
|
384 TheAlarmTest(ret == KErrNone, __LINE__); |
|
385 } |
|
386 // |
|
387 setTime = TheInitialAlarmTime; |
|
388 |
|
389 #if defined(_DEBUG) |
|
390 // In udeb the alarm goes from the state EAlarmStateQueued to the state EAlarmStateNotified |
|
391 // (skipping the state ENotifying).In EAlarmStateNotified the nextTime for the alarm is |
|
392 // recalculated and the expected value (called setTime here) needs adjustment to reflect this. |
|
393 // In urel the EAlarmStateNotified state (where the NextTime for an alarm is recalculated) |
|
394 // is never reached so the adjustement in the expected value (called setTime) is not necessary . |
|
395 |
|
396 if (aAfterClocksGoForward && aAlarmsSetInPast) |
|
397 { |
|
398 setTime += TTimeIntervalDays(+7); |
|
399 } |
|
400 #else |
|
401 //Just to get rid of warning |
|
402 (void)aAfterClocksGoForward; |
|
403 (void)aAlarmsSetInPast; |
|
404 #endif |
|
405 |
|
406 CheckTimesAreEqual(setTime, alarm.NextDueTime(), __LINE__); |
|
407 } |
|
408 |
|
409 static void TestAlarmsWithDaylightSavingChange1L() |
|
410 // |
|
411 // Test effects of changing daylight saving on clock alarms1 |
|
412 // |
|
413 { |
|
414 TheAlarmTest.Test().Next(_L("Initialise with daylight saving on")); |
|
415 EnableDaylightSavingL(ETrue); |
|
416 TheCurrentTime.HomeTime(); |
|
417 // |
|
418 TheAlarmTest.Test().Next(_L("Setting alarms half an hour in the past")); |
|
419 TheInitialAlarmTime = SetClockAlarms(TheCurrentTime, TTimeIntervalMinutes(-30)); |
|
420 // |
|
421 TheAlarmTest.Test().Next(_L("Testing alarms when daylight saving is on")); |
|
422 |
|
423 // Wait for DST to end. |
|
424 User::After(3000000); |
|
425 VerifyAlarmsAreCorrect(ETrue, EFalse); |
|
426 |
|
427 // |
|
428 TheAlarmTest.Test().Next(_L("Turning daylight saving off")); |
|
429 EnableDaylightSavingL(EFalse); |
|
430 // |
|
431 TheAlarmTest.Test().Next(_L("Testing alarms when daylight saving is off")); |
|
432 |
|
433 VerifyAlarmsAreCorrect(EFalse, ETrue); |
|
434 |
|
435 // |
|
436 TheAlarmTest.Test().Next(_L("Removing all alarms")); |
|
437 TheAlarmTest.TestClearStoreL(); |
|
438 } |
|
439 |
|
440 static void TestAlarmsWithDaylightSavingChange2L() |
|
441 // |
|
442 // Test effects of changing daylight saving on clock alarms2 |
|
443 // |
|
444 { |
|
445 TheAlarmTest.Test().Next(_L("Initialise with daylight saving off")); |
|
446 EnableDaylightSavingL(EFalse); |
|
447 TheCurrentTime.HomeTime(); |
|
448 // |
|
449 TheAlarmTest.Test().Next(_L("Setting alarms an hour and a half in the future")); |
|
450 // Used to set 30 minutes into future, but a defect in User::SetHomeTime() requires |
|
451 // times not to be set between 31-10-2004 1.59 (BST) and 31-10-2004 1.59 (GMT). |
|
452 TheInitialAlarmTime = SetClockAlarms(TheCurrentTime, TTimeIntervalMinutes(90)); |
|
453 // |
|
454 TheAlarmTest.Test().Next(_L("Testing alarms with daylight saving off")); |
|
455 testAlarmsOnForwardingClocks(EFalse, EFalse, ETrue); |
|
456 // |
|
457 TheAlarmTest.Test().Next(_L("Turning daylight saving on")); |
|
458 EnableDaylightSavingL(ETrue); |
|
459 // |
|
460 TheAlarmTest.Test().Next(_L("Testing alarms with daylight saving on")); |
|
461 testAlarmsOnForwardingClocks(ETrue, EFalse, EFalse); |
|
462 // |
|
463 TheAlarmTest.Test().Next(_L("Removing all alarms")); |
|
464 TheAlarmTest.TestClearStoreL(); |
|
465 } |
|
466 |
|
467 // |
|
468 // Test changes in workdays |
|
469 // |
|
470 |
|
471 static void testSetWithNoWorkdays() |
|
472 // |
|
473 // Test what happens when setting a workday alarm with no workdays set |
|
474 // |
|
475 { |
|
476 TheAlarmTest.Test().Next(_L("Setting workday alarm with no workday set")); |
|
477 |
|
478 // Set no workdays |
|
479 TUint workdayMask = 0; |
|
480 TLocale locale; |
|
481 locale.SetWorkDays(workdayMask); |
|
482 locale.Set(); |
|
483 |
|
484 // Have to wait a bit here because the kernel takes some time |
|
485 // to notify client-side environment change objects and so |
|
486 // we need to allow the alarm server to do its thing... |
|
487 User::After(100000); |
|
488 // |
|
489 TInt ret = TheAlarmTest.Session().NumberOfAlarmsActiveInQueue(); |
|
490 TheAlarmTest(ret == 0, __LINE__); |
|
491 // |
|
492 TheOriginalTime.HomeTime(); |
|
493 TheInitialAlarmTime = TheOriginalTime; |
|
494 TheInitialAlarmTime += TTimeIntervalHours(1); |
|
495 // |
|
496 TASShdAlarm alarm; |
|
497 alarm.Message() = _L("Clock alarm in slot 0"); |
|
498 alarm.NextDueTime() = TheInitialAlarmTime; |
|
499 alarm.RepeatDefinition() = EAlarmRepeatDefintionRepeatWorkday; |
|
500 ret = TheAlarmTest.Session().AlarmAdd(alarm); |
|
501 TheAlarmTest(ret == KErrNone, __LINE__); |
|
502 TheAlarmTest(alarm.Id() != KNullAlarmId, __LINE__); |
|
503 TheClockAlarmSlots[0] = alarm.Id(); |
|
504 |
|
505 // Test alarm state, should be disabled |
|
506 TASShdAlarm alarm2; |
|
507 ret = TheAlarmTest.Session().GetAlarmDetails(alarm.Id(), alarm2); |
|
508 TheAlarmTest(ret == KErrNone, __LINE__); |
|
509 TheAlarmTest(alarm2.Status() == EAlarmStatusDisabled, __LINE__); |
|
510 } |
|
511 |
|
512 static void testDisabledAlarmWithWorkdays() |
|
513 // |
|
514 // Test before-disabled alarm when workdays set is changed. |
|
515 // |
|
516 { |
|
517 TheAlarmTest.Test().Next(_L("Testing disabled alarm when workdays set is changed")); |
|
518 |
|
519 const TAlarmId id = TheClockAlarmSlots[0]; |
|
520 TheAlarmTest(id != KNullAlarmId, __LINE__); |
|
521 |
|
522 //Set workdays on Monday |
|
523 TLocale locale; |
|
524 locale.SetWorkDays(0x1); //Monday |
|
525 locale.Set(); |
|
526 User::After(100000); |
|
527 |
|
528 //Make sure the status of alarm being changed to enabled automatically |
|
529 TAlarmStatus alarmStatus; |
|
530 TInt r = TheAlarmTest.Session().GetAlarmStatus(id, alarmStatus); |
|
531 TheAlarmTest(r == KErrNone, __LINE__); |
|
532 TheAlarmTest(alarmStatus == EAlarmStatusEnabled, __LINE__); |
|
533 |
|
534 //Set the alarm manually disabled |
|
535 alarmStatus = EAlarmStatusDisabled; |
|
536 r = TheAlarmTest.Session().SetAlarmStatus(id, alarmStatus); |
|
537 TheAlarmTest(r == KErrNone, __LINE__); |
|
538 r = TheAlarmTest.Session().GetAlarmStatus(id, alarmStatus); |
|
539 TheAlarmTest(r == KErrNone, __LINE__); |
|
540 TheAlarmTest(alarmStatus == EAlarmStatusDisabled, __LINE__); |
|
541 |
|
542 //Change the workday to check if it is still disabled(not be enabled automatically) |
|
543 locale.SetWorkDays(0x2); //Tuesday |
|
544 locale.Set(); |
|
545 User::After(100000); |
|
546 r = TheAlarmTest.Session().GetAlarmStatus(id, alarmStatus); |
|
547 TheAlarmTest(r == KErrNone, __LINE__); |
|
548 TheAlarmTest(alarmStatus == EAlarmStatusDisabled, __LINE__); |
|
549 |
|
550 //Set locale to be no workdays |
|
551 locale.SetWorkDays(0); |
|
552 locale.Set(); |
|
553 User::After(100000); |
|
554 r = TheAlarmTest.Session().GetAlarmStatus(id, alarmStatus); |
|
555 TheAlarmTest(r == KErrNone, __LINE__); |
|
556 TheAlarmTest(alarmStatus == EAlarmStatusDisabled, __LINE__); |
|
557 |
|
558 //Alarm should not be enabled in no workdays |
|
559 alarmStatus = EAlarmStatusEnabled; |
|
560 r = TheAlarmTest.Session().SetAlarmStatus(id, alarmStatus); |
|
561 TheAlarmTest(r != KErrNone, __LINE__); |
|
562 r = TheAlarmTest.Session().GetAlarmStatus(id, alarmStatus); |
|
563 TheAlarmTest(r == KErrNone, __LINE__); |
|
564 TheAlarmTest(alarmStatus == EAlarmStatusDisabled, __LINE__); |
|
565 |
|
566 //Change the workday to check if it is still disabled(not be enabled automatically) |
|
567 locale.SetWorkDays(0x2); //Tuesday |
|
568 locale.Set(); |
|
569 User::After(100000); |
|
570 r = TheAlarmTest.Session().GetAlarmStatus(id, alarmStatus); |
|
571 TheAlarmTest(r == KErrNone, __LINE__); |
|
572 TheAlarmTest(alarmStatus == EAlarmStatusDisabled, __LINE__); |
|
573 |
|
574 //Alarm should not be enabled in no workdays |
|
575 alarmStatus = EAlarmStatusEnabled; |
|
576 r = TheAlarmTest.Session().SetAlarmStatus(id, alarmStatus); |
|
577 TheAlarmTest(r == KErrNone, __LINE__); |
|
578 r = TheAlarmTest.Session().GetAlarmStatus(id, alarmStatus); |
|
579 TheAlarmTest(r == KErrNone, __LINE__); |
|
580 TheAlarmTest(alarmStatus == EAlarmStatusEnabled, __LINE__); |
|
581 } |
|
582 |
|
583 static void testSetWorkdays() |
|
584 // |
|
585 // Create workdays and test |
|
586 // |
|
587 { |
|
588 TheAlarmTest.Test().Next(_L("Creating and testing workdays")); |
|
589 // |
|
590 TInt todayMaskOffset = TheInitialAlarmTime.DayNoInWeek(); |
|
591 TUint workdayMask = 1; |
|
592 // |
|
593 for (TInt count = 0; count < 7; count++) |
|
594 { |
|
595 workdayMask = 1; |
|
596 const TInt dayOfWeek = (todayMaskOffset + count) % 7; |
|
597 workdayMask <<= dayOfWeek; |
|
598 // |
|
599 TLocale locale; |
|
600 locale.SetWorkDays(workdayMask); |
|
601 locale.Set(); |
|
602 User::After(100000); |
|
603 // |
|
604 const TAlarmId id = TheClockAlarmSlots[0]; |
|
605 TheAlarmTest(id != KNullAlarmId, __LINE__); |
|
606 // |
|
607 TASShdAlarm alarm; |
|
608 const TInt r = TheAlarmTest.Session().GetAlarmDetails(id, alarm); |
|
609 TheAlarmTest(r == KErrNone, __LINE__); |
|
610 TheAlarmTest(alarm.Status() == EAlarmStatusEnabled, __LINE__); |
|
611 // |
|
612 TTime expectedTime = TheInitialAlarmTime; |
|
613 expectedTime += TTimeIntervalDays(count); |
|
614 CheckTimesAreEqual(expectedTime, alarm.NextDueTime(), __LINE__); |
|
615 } |
|
616 } |
|
617 |
|
618 static void testMakeAllWorkdaysL() |
|
619 // |
|
620 // Make all days workdays |
|
621 // Advance time a day at a time to test alarm for each day of the week |
|
622 // |
|
623 { |
|
624 TheAlarmTest.Test().Next(_L("Make all days workdays")); |
|
625 // |
|
626 TBuf<60> dateTimeStr; |
|
627 _LIT(KTimeDateFormat,"%*E%*D%X%*N%*Y %1 %2 '%3 - %-B%:0%J%:1%T%:2%S%:3%+B"); |
|
628 |
|
629 const TUint workdayMask = 127;// Seven 1's |
|
630 TLocale locale; |
|
631 locale.SetWorkDays(workdayMask); |
|
632 locale.Set(); |
|
633 User::After(100000); |
|
634 |
|
635 for (TInt count = 0; count < 7; count++) |
|
636 { |
|
637 if (count) |
|
638 { |
|
639 // Advance time |
|
640 TTime advTime(TheOriginalTime + TTimeIntervalDays(count)); |
|
641 User::SetUTCTime(advTime); |
|
642 advTime.FormatL(dateTimeStr, KTimeDateFormat); |
|
643 TheAlarmTest.Test().Printf(_L("Advance time : %S\n"), &dateTimeStr); |
|
644 } |
|
645 |
|
646 const TAlarmId id = TheClockAlarmSlots[0]; |
|
647 TheAlarmTest(id != KNullAlarmId, __LINE__); |
|
648 // |
|
649 TASShdAlarm alarm; |
|
650 const TInt r = TheAlarmTest.Session().GetAlarmDetails(id, alarm); |
|
651 TheAlarmTest(r == KErrNone, __LINE__); |
|
652 TheAlarmTest(alarm.Status() == EAlarmStatusEnabled, __LINE__); |
|
653 // |
|
654 TTime expectedTime = TheInitialAlarmTime; |
|
655 TheInitialAlarmTime.FormatL(dateTimeStr,KTimeDateFormat); |
|
656 TheAlarmTest.Test().Printf(_L("TheInitialAlarmTime: %S\n"), &dateTimeStr); |
|
657 |
|
658 expectedTime += TTimeIntervalDays(count); |
|
659 // |
|
660 const TInt days = expectedTime.DaysFrom(alarm.NextDueTime()).Int(); |
|
661 |
|
662 if (days != 0) //In that case, the next due time is within 24 hours in the past |
|
663 { |
|
664 expectedTime -= TTimeIntervalDays(1); |
|
665 } |
|
666 // |
|
667 expectedTime.FormatL(dateTimeStr,KTimeDateFormat); |
|
668 TheAlarmTest.Test().Printf(_L("expectedTime : %S\n"), &dateTimeStr); |
|
669 |
|
670 alarm.NextDueTime().FormatL(dateTimeStr,KTimeDateFormat); |
|
671 TheAlarmTest.Test().Printf(_L("NextDueTime(): %S\n"), &dateTimeStr); |
|
672 |
|
673 CheckTimesAreEqual(expectedTime, alarm.NextDueTime(), __LINE__); |
|
674 } |
|
675 } |
|
676 |
|
677 static void testRemoveWorkdays() |
|
678 // |
|
679 // Remove all workdays and test |
|
680 // |
|
681 { |
|
682 const TAlarmId id = TheClockAlarmSlots[0]; |
|
683 TheAlarmTest(id != KNullAlarmId, __LINE__); |
|
684 // |
|
685 TLocale locale; |
|
686 locale.SetWorkDays(0); |
|
687 locale.Set(); |
|
688 User::After(100000); |
|
689 // |
|
690 TASShdAlarm alarm; |
|
691 const TInt r = TheAlarmTest.Session().GetAlarmDetails(id, alarm); |
|
692 // |
|
693 TheAlarmTest(r == KErrNone, __LINE__); |
|
694 TheAlarmTest(alarm.Status() == EAlarmStatusDisabled, __LINE__); |
|
695 } |
|
696 |
|
697 static void testLocaleChangeWorkdaysL() |
|
698 // |
|
699 // Test effects of changing workdays on alarms |
|
700 // |
|
701 { |
|
702 TheAlarmTest.TestClearStoreL(); |
|
703 testSetWithNoWorkdays(); |
|
704 testDisabledAlarmWithWorkdays(); |
|
705 testSetWorkdays(); |
|
706 testMakeAllWorkdaysL(); |
|
707 testRemoveWorkdays(); |
|
708 TheAlarmTest.TestClearStoreL(); |
|
709 } |
|
710 |
|
711 static void test24HourToOnceOnlyAlarms() |
|
712 { |
|
713 TheAlarmTest.Test().Next(_L("Test update of 24 hour alarms to once only alarms")); |
|
714 |
|
715 // Next 24 hour alarms which are more than 1 day in the future after a system time |
|
716 // update should be updated to once only alarms |
|
717 |
|
718 // Set 'next 24 hour' alarms due in 5, just under and over 18, and 21 hours time |
|
719 TTime now; |
|
720 now.HomeTime(); |
|
721 TTime alarmTime(now); |
|
722 |
|
723 TASShdAlarm alarm; |
|
724 alarm.RepeatDefinition() = EAlarmRepeatDefintionRepeatNext24Hours; |
|
725 |
|
726 alarmTime += TTimeIntervalHours(5); |
|
727 alarm.NextDueTime() = alarmTime; |
|
728 TheAlarmTest(TheAlarmTest.Session().AlarmAdd(alarm) == KErrNone, __LINE__); |
|
729 TAlarmId id1 = alarm.Id(); |
|
730 TheAlarmTest(id1 != KNullAlarmId, __LINE__); |
|
731 |
|
732 alarmTime += TTimeIntervalHours(13); |
|
733 alarmTime -= TTimeIntervalMinutes(1); |
|
734 alarm.NextDueTime() = alarmTime; |
|
735 TheAlarmTest(TheAlarmTest.Session().AlarmAdd(alarm) == KErrNone, __LINE__); |
|
736 TAlarmId id2 = alarm.Id(); |
|
737 TheAlarmTest(id2 != KNullAlarmId, __LINE__); |
|
738 |
|
739 alarmTime += TTimeIntervalMinutes(2); |
|
740 alarm.NextDueTime() = alarmTime; |
|
741 TheAlarmTest(TheAlarmTest.Session().AlarmAdd(alarm) == KErrNone, __LINE__); |
|
742 TAlarmId id3 = alarm.Id(); |
|
743 TheAlarmTest(id3 != KNullAlarmId, __LINE__); |
|
744 |
|
745 alarmTime += TTimeIntervalHours(3); |
|
746 alarm.NextDueTime() = alarmTime; |
|
747 TheAlarmTest(TheAlarmTest.Session().AlarmAdd(alarm) == KErrNone, __LINE__); |
|
748 TAlarmId id4 = alarm.Id(); |
|
749 TheAlarmTest(id4 != KNullAlarmId, __LINE__); |
|
750 |
|
751 // Set system time back 6 hours - alarms are now due in 11, just under and over 24, and 27 hours |
|
752 |
|
753 SetHomeTime(now - TTimeIntervalHours(6)); |
|
754 |
|
755 User::After(KTimeToWait); |
|
756 |
|
757 TheAlarmTest(TheAlarmTest.Session().GetAlarmDetails(id1,alarm) == KErrNone, __LINE__); |
|
758 TheAlarmTest(alarm.RepeatDefinition() == EAlarmRepeatDefintionRepeatNext24Hours, __LINE__); |
|
759 TheAlarmTest(TheAlarmTest.Session().GetAlarmDetails(id2,alarm) == KErrNone, __LINE__); |
|
760 TheAlarmTest(alarm.RepeatDefinition() == EAlarmRepeatDefintionRepeatNext24Hours, __LINE__); |
|
761 TheAlarmTest(TheAlarmTest.Session().GetAlarmDetails(id3,alarm) == KErrNone, __LINE__); |
|
762 TheAlarmTest(alarm.RepeatDefinition() == EAlarmRepeatDefintionRepeatOnce, __LINE__); |
|
763 TheAlarmTest(TheAlarmTest.Session().GetAlarmDetails(id4,alarm) == KErrNone, __LINE__); |
|
764 TheAlarmTest(alarm.RepeatDefinition() == EAlarmRepeatDefintionRepeatOnce, __LINE__); |
|
765 } |
|
766 |
|
767 static void testAlarmPersistenceAfterSystemTimeUpdateL() |
|
768 { |
|
769 // Following a system time update, queued alarms may or may not |
|
770 // be removed, depending on the following conditions |
|
771 // |
|
772 // * EAlarmRepeatDefintionRepeatOnce |
|
773 // * EAlarmRepeatDefintionRepeatNext24Hours |
|
774 // Alarm is removed if more than 1 day in the past |
|
775 // |
|
776 // * EAlarmRepeatDefintionRepeatDaily |
|
777 // * EAlarmRepeatDefintionRepeatWorkday |
|
778 // * EAlarmRepeatDefintionRepeatWeekly |
|
779 // All repeating alarms queue the next repeat of the alarm |
|
780 |
|
781 TheAlarmTest.Test().Next(_L("update system time whilst alarm notifying")); |
|
782 |
|
783 #if defined(_DEBUG) |
|
784 TheAlarmTest.Session().__DbgPreventUserNotify(ETrue); |
|
785 #define KAlarmStateNotify EAlarmStateNotified |
|
786 #else |
|
787 #define KAlarmStateNotify EAlarmStateNotifying |
|
788 #endif |
|
789 |
|
790 |
|
791 for (TInt ii = 0; ii < 4; ++ii) |
|
792 { |
|
793 // Get current alarm counts |
|
794 TInt previousQueued = TheAlarmTest.Session().AlarmCountByState(EAlarmStateQueued); |
|
795 TInt previousNotifying = TheAlarmTest.Session().AlarmCountByState(KAlarmStateNotify) + |
|
796 TheAlarmTest.Session().AlarmCountByState(EAlarmStateWaitingToNotify); |
|
797 |
|
798 TTime time; |
|
799 SafeHomeTime(time); |
|
800 time += TTimeIntervalSeconds(2); |
|
801 |
|
802 TTime systemTime(time); |
|
803 |
|
804 switch (ii) |
|
805 { |
|
806 case 0: |
|
807 TheAlarmTest.Test().Next(_L("set time back 1 hour")); |
|
808 systemTime -= TTimeIntervalHours(1); |
|
809 break; |
|
810 case 1: |
|
811 TheAlarmTest.Test().Next(_L("set time forward 1 hour")); |
|
812 systemTime += TTimeIntervalHours(1); |
|
813 break; |
|
814 case 2: |
|
815 TheAlarmTest.Test().Next(_L("set time back 2 days")); |
|
816 systemTime -= TTimeIntervalDays(2); |
|
817 break; |
|
818 case 3: |
|
819 TheAlarmTest.Test().Next(_L("set time forward 2 days")); |
|
820 systemTime += TTimeIntervalDays(2); |
|
821 break; |
|
822 default: |
|
823 TheAlarmTest(EFalse, __LINE__); |
|
824 break; |
|
825 } |
|
826 |
|
827 // add an alarm of each repeat type due now |
|
828 TASShdAlarm alarm; |
|
829 |
|
830 alarm.NextDueTime() = time; |
|
831 alarm.RepeatDefinition() = EAlarmRepeatDefintionRepeatOnce; |
|
832 TheAlarmTest(TheAlarmTest.Session().AlarmAdd(alarm) == KErrNone, __LINE__); |
|
833 TAlarmId idOnce = alarm.Id(); |
|
834 TheAlarmTest(idOnce != KNullAlarmId, __LINE__); |
|
835 |
|
836 alarm.NextDueTime() = time; |
|
837 alarm.RepeatDefinition() = EAlarmRepeatDefintionRepeatNext24Hours; |
|
838 TheAlarmTest(TheAlarmTest.Session().AlarmAdd(alarm) == KErrNone, __LINE__); |
|
839 TAlarmId id24hr = alarm.Id(); |
|
840 TheAlarmTest(id24hr != KNullAlarmId, __LINE__); |
|
841 |
|
842 alarm.NextDueTime() = time; |
|
843 alarm.RepeatDefinition() = EAlarmRepeatDefintionRepeatDaily; |
|
844 TheAlarmTest(TheAlarmTest.Session().AlarmAdd(alarm) == KErrNone, __LINE__); |
|
845 TAlarmId idDaily = alarm.Id(); |
|
846 TheAlarmTest(idDaily != KNullAlarmId, __LINE__); |
|
847 |
|
848 alarm.NextDueTime() = time; |
|
849 alarm.RepeatDefinition() = EAlarmRepeatDefintionRepeatWorkday; |
|
850 TheAlarmTest(TheAlarmTest.Session().AlarmAdd(alarm) == KErrNone, __LINE__); |
|
851 TAlarmId idWorkday = alarm.Id(); |
|
852 TheAlarmTest(idWorkday != KNullAlarmId, __LINE__); |
|
853 |
|
854 alarm.NextDueTime() = time; |
|
855 alarm.RepeatDefinition() = EAlarmRepeatDefintionRepeatWeekly; |
|
856 TheAlarmTest(TheAlarmTest.Session().AlarmAdd(alarm) == KErrNone, __LINE__); |
|
857 TAlarmId idWeekly = alarm.Id(); |
|
858 TheAlarmTest(idWeekly != KNullAlarmId, __LINE__); |
|
859 |
|
860 TInt queued = TheAlarmTest.Session().AlarmCountByState(EAlarmStateQueued); |
|
861 TInt notifying = TheAlarmTest.Session().AlarmCountByState(KAlarmStateNotify) + |
|
862 TheAlarmTest.Session().AlarmCountByState(EAlarmStateWaitingToNotify); |
|
863 TheAlarmTest(queued == previousQueued + 5, __LINE__); |
|
864 TheAlarmTest(notifying == previousNotifying, __LINE__); |
|
865 |
|
866 // wait for the alarms to go off |
|
867 User::After(10 * KTimeToWait); |
|
868 queued = TheAlarmTest.Session().AlarmCountByState(EAlarmStateQueued); |
|
869 notifying = TheAlarmTest.Session().AlarmCountByState(KAlarmStateNotify) + |
|
870 TheAlarmTest.Session().AlarmCountByState(EAlarmStateWaitingToNotify); |
|
871 TheAlarmTest(queued == previousQueued + 4, __LINE__); |
|
872 TheAlarmTest(notifying == previousNotifying + 1, __LINE__); |
|
873 |
|
874 // update the system time |
|
875 |
|
876 SetHomeTime(systemTime); |
|
877 |
|
878 User::After(KTimeToWait); |
|
879 |
|
880 // check the queue of alarms |
|
881 queued = TheAlarmTest.Session().AlarmCountByState(EAlarmStateQueued); |
|
882 notifying = TheAlarmTest.Session().AlarmCountByState(KAlarmStateNotify) + |
|
883 TheAlarmTest.Session().AlarmCountByState(EAlarmStateWaitingToNotify); |
|
884 |
|
885 switch (ii) |
|
886 { |
|
887 case 0: // set time back 1 hour |
|
888 case 1: // set time forward 1 hour |
|
889 case 2: // set time back 2 days |
|
890 { |
|
891 // No alarms should be removed |
|
892 TheAlarmTest(queued == previousQueued + 4, __LINE__); |
|
893 TheAlarmTest(notifying == previousNotifying + 1, __LINE__); |
|
894 TheAlarmTest(TheAlarmTest.Session().GetAlarmDetails(idOnce,alarm) == KErrNone, __LINE__); |
|
895 TheAlarmTest(alarm.State() == EAlarmStateQueued || alarm.State() == KAlarmStateNotify || alarm.State() == EAlarmStateWaitingToNotify, __LINE__); |
|
896 TheAlarmTest(TheAlarmTest.Session().GetAlarmDetails(id24hr,alarm) == KErrNone, __LINE__); |
|
897 TheAlarmTest(alarm.State() == EAlarmStateQueued || alarm.State() == KAlarmStateNotify || alarm.State() == EAlarmStateWaitingToNotify, __LINE__); |
|
898 TheAlarmTest(TheAlarmTest.Session().GetAlarmDetails(idDaily,alarm) == KErrNone, __LINE__); |
|
899 TheAlarmTest(alarm.State() == EAlarmStateQueued || alarm.State() == KAlarmStateNotify || alarm.State() == EAlarmStateWaitingToNotify, __LINE__); |
|
900 TheAlarmTest(TheAlarmTest.Session().GetAlarmDetails(idWorkday,alarm) == KErrNone, __LINE__); |
|
901 TheAlarmTest(alarm.State() == EAlarmStateQueued || alarm.State() == KAlarmStateNotify || alarm.State() == EAlarmStateWaitingToNotify, __LINE__); |
|
902 TheAlarmTest(TheAlarmTest.Session().GetAlarmDetails(idWeekly,alarm) == KErrNone, __LINE__); |
|
903 TheAlarmTest(alarm.State() == EAlarmStateQueued || alarm.State() == KAlarmStateNotify || alarm.State() == EAlarmStateWaitingToNotify, __LINE__); |
|
904 break; |
|
905 } |
|
906 case 3: // set time forward 2 days |
|
907 { |
|
908 // once only and 24hr alarms should be removed |
|
909 TheAlarmTest(queued + notifying == previousQueued + previousNotifying + 3, __LINE__); |
|
910 TheAlarmTest(TheAlarmTest.Session().GetAlarmDetails(idOnce,alarm) == KErrNotFound, __LINE__); |
|
911 TheAlarmTest(TheAlarmTest.Session().GetAlarmDetails(id24hr,alarm) == KErrNotFound, __LINE__); |
|
912 TheAlarmTest(TheAlarmTest.Session().GetAlarmDetails(idDaily,alarm) == KErrNone, __LINE__); |
|
913 TheAlarmTest(alarm.State() == EAlarmStateQueued || alarm.State() == KAlarmStateNotify || alarm.State() == EAlarmStateWaitingToNotify, __LINE__); |
|
914 TheAlarmTest(TheAlarmTest.Session().GetAlarmDetails(idWorkday,alarm) == KErrNone, __LINE__); |
|
915 TheAlarmTest(alarm.State() == EAlarmStateQueued || alarm.State() == KAlarmStateNotify || alarm.State() == EAlarmStateWaitingToNotify, __LINE__); |
|
916 TheAlarmTest(TheAlarmTest.Session().GetAlarmDetails(idWeekly,alarm) == KErrNone, __LINE__); |
|
917 TheAlarmTest(alarm.State() == EAlarmStateQueued || alarm.State() == KAlarmStateNotify || alarm.State() == EAlarmStateWaitingToNotify, __LINE__); |
|
918 break; |
|
919 } |
|
920 default: |
|
921 TheAlarmTest(EFalse, __LINE__); |
|
922 break; |
|
923 } |
|
924 |
|
925 TheAlarmTest.Session().AlarmDelete(idOnce); |
|
926 TheAlarmTest.Session().AlarmDelete(id24hr); |
|
927 TheAlarmTest.Session().AlarmDelete(idDaily); |
|
928 TheAlarmTest.Session().AlarmDelete(idWorkday); |
|
929 TheAlarmTest.Session().AlarmDelete(idWeekly); |
|
930 } |
|
931 } |
|
932 |
|
933 static TTime SetUtcClockAlarms(const TTime& aBaseTime, const TTimeIntervalMinutes& aOffset) |
|
934 // |
|
935 // Set Alarms. |
|
936 // Extra alarm when putting clocks back to see what happen to |
|
937 // weekly alarm set for 6 days & 23 1/2 hours time |
|
938 // |
|
939 { |
|
940 TInt r; |
|
941 TASShdAlarm alarm; |
|
942 const TInt n = TheAlarmTest.Session().NumberOfAlarmsActiveInQueue(); |
|
943 TheAlarmTest(n == 0, __LINE__); |
|
944 TBuf<KMaxAlarmMessageLength> message; |
|
945 // |
|
946 TTime timeForAlarms(aBaseTime); |
|
947 timeForAlarms += aOffset; |
|
948 |
|
949 // Once Only |
|
950 alarm.Reset(); |
|
951 message.Num(0); |
|
952 alarm.Message()=message; |
|
953 alarm.SetUtcNextDueTime(timeForAlarms); |
|
954 alarm.RepeatDefinition()=(EAlarmRepeatDefintionRepeatOnce); |
|
955 r = TheAlarmTest.Session().AlarmAdd(alarm); |
|
956 TheAlarmTest(r == KErrNone, __LINE__); |
|
957 TheClockAlarmSlots[0] = alarm.Id(); |
|
958 |
|
959 // Next 24 hours |
|
960 alarm.Reset(); |
|
961 message.Num(1); |
|
962 alarm.Message()=(message); |
|
963 alarm.SetUtcNextDueTime(timeForAlarms); |
|
964 alarm.RepeatDefinition()=(EAlarmRepeatDefintionRepeatNext24Hours); |
|
965 r = TheAlarmTest.Session().AlarmAdd(alarm); |
|
966 TheAlarmTest(r == KErrNone, __LINE__); |
|
967 TheClockAlarmSlots[1] = alarm.Id(); |
|
968 |
|
969 // Clock daily |
|
970 alarm.Reset(); |
|
971 message.Num(2); |
|
972 alarm.Message()=(message); |
|
973 alarm.SetUtcNextDueTime(timeForAlarms); |
|
974 alarm.RepeatDefinition()=(EAlarmRepeatDefintionRepeatDaily); |
|
975 r = TheAlarmTest.Session().AlarmAdd(alarm); |
|
976 TheAlarmTest(r == KErrNone, __LINE__); |
|
977 TheClockAlarmSlots[2] = alarm.Id(); |
|
978 |
|
979 // Clock weekly |
|
980 alarm.Reset(); |
|
981 message.Num(3); |
|
982 alarm.Message()=message; |
|
983 alarm.SetUtcNextDueTime(timeForAlarms); |
|
984 alarm.RepeatDefinition()=EAlarmRepeatDefintionRepeatWeekly; |
|
985 r = TheAlarmTest.Session().AlarmAdd(alarm); |
|
986 TheAlarmTest(r == KErrNone, __LINE__); |
|
987 TheClockAlarmSlots[3] = alarm.Id(); |
|
988 |
|
989 if (aOffset.Int() < 0) |
|
990 { |
|
991 TheExtendedAlarmTime = timeForAlarms; |
|
992 TheExtendedAlarmTime += TTimeIntervalDays(7); |
|
993 message.Num(4); |
|
994 alarm.Message()=message; |
|
995 alarm.RepeatDefinition()=EAlarmRepeatDefintionRepeatWeekly; |
|
996 alarm.SetUtcNextDueTime(TheExtendedAlarmTime); |
|
997 r = TheAlarmTest.Session().AlarmAdd(alarm); |
|
998 TheAlarmTest(r == KErrNone, __LINE__); |
|
999 TheClockAlarmSlots[4] = alarm.Id(); |
|
1000 } |
|
1001 return timeForAlarms; |
|
1002 } |
|
1003 |
|
1004 /** |
|
1005 Checks that the alarms are correct. |
|
1006 |
|
1007 // |
|
1008 // We expect and test that: |
|
1009 // |
|
1010 // 1) Once alarm to remain unchanged at initial alarm time |
|
1011 // unless allowed time to complete. |
|
1012 // |
|
1013 // 2) Next24 to advance to the first 'initial alarm time' |
|
1014 // falling due after the original time |
|
1015 // |
|
1016 // 3a) If before clocks go back, Weekly (set previously) to |
|
1017 // advance to the 'initial alarm time' in the next week |
|
1018 // |
|
1019 // 3b) If after clocks go back, Weekly (set previously) to |
|
1020 // return to the 'initial alarm time' in the current week |
|
1021 // |
|
1022 // 4a) If before clocks go back, Weekly (set for next week) |
|
1023 // to remain at the 'extended alarm time' in the next week |
|
1024 // |
|
1025 // 4b) If after clocks go back, Weekly (set for next week) to |
|
1026 // move back to 'initial alarm time' in the current week |
|
1027 // |
|
1028 |
|
1029 @param aInterveningOffsetChange True when a change in the UTC offset occurs |
|
1030 between setting the alarms and testing them. |
|
1031 @param aOnceCompleted True if the "Repeat Once" alarm has completed. |
|
1032 @internalComponent |
|
1033 */ |
|
1034 static void VerifyUtcAlarmsAreCorrect(TBool aInterveningOffsetChange, TBool aOnceCompleted) |
|
1035 { |
|
1036 TInt ret; |
|
1037 TTime setTime; |
|
1038 TASShdAlarm alarm; |
|
1039 TAlarmId alarmId; |
|
1040 TTime time; |
|
1041 time.UniversalTime(); |
|
1042 |
|
1043 // Check Once repeat if it has not completed. |
|
1044 if (!aOnceCompleted) |
|
1045 { |
|
1046 alarmId = TheClockAlarmSlots[0]; |
|
1047 TheAlarmTest(alarmId != KNullAlarmId, __LINE__); |
|
1048 ret = TheAlarmTest.Session().GetAlarmDetails(alarmId, alarm); |
|
1049 TheAlarmTest(ret == KErrNone, __LINE__); |
|
1050 CheckTimesAreEqual(TheInitialAlarmTime, alarm.NextDueTime(), __LINE__); |
|
1051 } |
|
1052 |
|
1053 // Check Next 24 hours repeat |
|
1054 alarmId = TheClockAlarmSlots[1]; |
|
1055 TheAlarmTest(alarmId != KNullAlarmId, __LINE__); |
|
1056 ret = TheAlarmTest.Session().GetAlarmDetails(alarmId, alarm); |
|
1057 TheAlarmTest(ret == KErrNone, __LINE__); |
|
1058 setTime = TheInitialAlarmTime; |
|
1059 |
|
1060 if (aInterveningOffsetChange) |
|
1061 { |
|
1062 // The alarm was set in the past, so add repeat interval. |
|
1063 setTime += TTimeIntervalHours(+24); |
|
1064 } |
|
1065 |
|
1066 CheckTimesAreEqual(setTime, alarm.NextDueTime(), __LINE__); |
|
1067 |
|
1068 // Check daily repeat |
|
1069 alarmId = TheClockAlarmSlots[2]; |
|
1070 TheAlarmTest(alarmId != KNullAlarmId, __LINE__); |
|
1071 ret = TheAlarmTest.Session().GetAlarmDetails(alarmId, alarm); |
|
1072 TheAlarmTest(ret == KErrNone, __LINE__); |
|
1073 setTime = TheInitialAlarmTime; |
|
1074 |
|
1075 if (aInterveningOffsetChange) |
|
1076 { |
|
1077 // The alarm was set in the past, so add repeat interval. |
|
1078 setTime += TTimeIntervalHours(+24); |
|
1079 } |
|
1080 |
|
1081 CheckTimesAreEqual(setTime, alarm.NextDueTime(), __LINE__); |
|
1082 |
|
1083 // Check weekly repeat |
|
1084 alarmId = TheClockAlarmSlots[3]; |
|
1085 TheAlarmTest(alarmId != KNullAlarmId, __LINE__); |
|
1086 ret = TheAlarmTest.Session().GetAlarmDetails(alarmId, alarm); |
|
1087 TheAlarmTest(ret == KErrNone, __LINE__); |
|
1088 setTime = TheInitialAlarmTime; |
|
1089 |
|
1090 if (aInterveningOffsetChange) |
|
1091 { |
|
1092 // The alarm was set in the past, so add repeat interval. |
|
1093 setTime += TTimeIntervalDays(+7); |
|
1094 } |
|
1095 |
|
1096 CheckTimesAreEqual(setTime, alarm.NextDueTime(), __LINE__); |
|
1097 |
|
1098 // Check weekly repeat |
|
1099 alarmId = TheClockAlarmSlots[4]; |
|
1100 TheAlarmTest(alarmId != KNullAlarmId, __LINE__); |
|
1101 ret = TheAlarmTest.Session().GetAlarmDetails(alarmId, alarm); |
|
1102 TheAlarmTest(ret == KErrNone, __LINE__); |
|
1103 |
|
1104 if (aInterveningOffsetChange) |
|
1105 { |
|
1106 setTime = TheExtendedAlarmTime; |
|
1107 } |
|
1108 else |
|
1109 { |
|
1110 setTime = TheInitialAlarmTime; |
|
1111 } |
|
1112 |
|
1113 CheckTimesAreEqual(setTime, alarm.NextDueTime(), __LINE__); |
|
1114 } |
|
1115 |
|
1116 static void testUtcAlarmsOnForwardingClocks(TBool aAfterClocksGoForward, TBool aAlarmsSetInPast, TBool aAlarmsShouldAllBeQueued = ETrue) |
|
1117 // |
|
1118 // We expect and test that: |
|
1119 // 1) Once alarm to remain unchanged at 'initial alarm time' |
|
1120 // 2) Next24 to remain at the 'initial alarm time' |
|
1121 // 3a) If before clocks go forward, Weekly to remain at the |
|
1122 // 'initial alarm time' |
|
1123 // 3b) If after clocks go forward, Weekly to advance to 'initial |
|
1124 // alarm time' in the next week |
|
1125 // |
|
1126 { |
|
1127 TInt ret; |
|
1128 TASShdAlarm alarm; |
|
1129 TAlarmId alarmId; |
|
1130 TTime setTime; |
|
1131 |
|
1132 // Check Once repeat |
|
1133 alarmId = TheClockAlarmSlots[0]; |
|
1134 ret = TheAlarmTest.Session().GetAlarmDetails(alarmId, alarm); |
|
1135 setTime = TheInitialAlarmTime; |
|
1136 |
|
1137 if (aAlarmsShouldAllBeQueued) |
|
1138 { |
|
1139 TheAlarmTest(ret == KErrNone, __LINE__); |
|
1140 } |
|
1141 |
|
1142 if (ret == KErrNone && alarm.Status() == EAlarmStatusEnabled) |
|
1143 { |
|
1144 CheckTimesAreEqual(setTime, alarm.NextDueTime(), __LINE__); |
|
1145 } |
|
1146 |
|
1147 // Check Next 24 hours repeat |
|
1148 alarmId = TheClockAlarmSlots[1]; |
|
1149 ret = TheAlarmTest.Session().GetAlarmDetails(alarmId, alarm); |
|
1150 setTime = TheInitialAlarmTime; |
|
1151 |
|
1152 if (aAlarmsShouldAllBeQueued) |
|
1153 { |
|
1154 TheAlarmTest(ret == KErrNone, __LINE__); |
|
1155 } |
|
1156 |
|
1157 if (ret == KErrNone && alarm.Status() == EAlarmStatusEnabled) |
|
1158 { |
|
1159 CheckTimesAreEqual(setTime, alarm.NextDueTime(), __LINE__); |
|
1160 } |
|
1161 |
|
1162 // Check daily repeat |
|
1163 alarmId = TheClockAlarmSlots[2]; |
|
1164 TheAlarmTest(alarmId != KNullAlarmId, __LINE__); |
|
1165 ret = TheAlarmTest.Session().GetAlarmDetails(alarmId, alarm); |
|
1166 setTime = TheInitialAlarmTime; |
|
1167 |
|
1168 if (aAlarmsShouldAllBeQueued) |
|
1169 { |
|
1170 TheAlarmTest(ret == KErrNone, __LINE__); |
|
1171 } |
|
1172 |
|
1173 CheckTimesAreEqual(setTime, alarm.NextDueTime(), __LINE__); |
|
1174 |
|
1175 // Check weekly repeat |
|
1176 alarmId = TheClockAlarmSlots[3]; |
|
1177 TheAlarmTest(alarmId != KNullAlarmId, __LINE__); |
|
1178 ret = TheAlarmTest.Session().GetAlarmDetails(alarmId, alarm); |
|
1179 |
|
1180 if (aAlarmsShouldAllBeQueued) |
|
1181 { |
|
1182 TheAlarmTest(ret == KErrNone, __LINE__); |
|
1183 } |
|
1184 // |
|
1185 setTime=TheInitialAlarmTime; |
|
1186 |
|
1187 #if defined(_DEBUG) |
|
1188 // In udeb the alarm goes from the state EAlarmStateQueued to the state EAlarmStateNotified |
|
1189 // (skipping the state ENotifying).In EAlarmStateNotified the nextTime for the alarm is |
|
1190 // recalculated and the expected value (called setTime here) needs adjustmentto reflect this. |
|
1191 // In urel the the EAlarmStateNotified state (where the NextTime for an alarm is recalculated) |
|
1192 // is never reached so the adjustement in the expected value (called setTime)is not necessary . |
|
1193 if (aAfterClocksGoForward && aAlarmsSetInPast) |
|
1194 { |
|
1195 setTime += TTimeIntervalDays(+7); |
|
1196 } |
|
1197 #else |
|
1198 //Just to get rid of warning |
|
1199 (void)aAfterClocksGoForward; |
|
1200 (void)aAlarmsSetInPast; |
|
1201 #endif |
|
1202 |
|
1203 CheckTimesAreEqual(setTime, alarm.NextDueTime(), __LINE__); |
|
1204 } |
|
1205 |
|
1206 static void TestUtcAlarmsWithDaylightSavingChange1L() |
|
1207 // |
|
1208 // Test effects of changing daylight saving on clock alarms1 |
|
1209 // |
|
1210 { |
|
1211 TheAlarmTest.Test().Next(_L("Initialise with daylight saving on")); |
|
1212 EnableDaylightSavingL(ETrue); |
|
1213 TheCurrentTime.UniversalTime(); |
|
1214 // |
|
1215 TheAlarmTest.Test().Next(_L("Setting UTC alarms half an hour in the past")); |
|
1216 TheInitialAlarmTime = SetUtcClockAlarms(TheCurrentTime, TTimeIntervalMinutes(-30)); |
|
1217 // |
|
1218 TheAlarmTest.Test().Next(_L("Testing UTC alarms when daylight saving is on")); |
|
1219 VerifyUtcAlarmsAreCorrect(ETrue, EFalse); |
|
1220 // |
|
1221 TheAlarmTest.Test().Next(_L("Turning daylight saving off")); |
|
1222 EnableDaylightSavingL(EFalse); |
|
1223 // |
|
1224 TheAlarmTest.Test().Next(_L("Testing UTC alarms when daylight saving is off")); |
|
1225 VerifyUtcAlarmsAreCorrect(ETrue, ETrue); |
|
1226 // |
|
1227 TheAlarmTest.Test().Next(_L("Removing all alarms")); |
|
1228 TheAlarmTest.TestClearStoreL(); |
|
1229 } |
|
1230 |
|
1231 static void TestUtcAlarmsWithDaylightSavingChange2L() |
|
1232 // |
|
1233 // Test effects of changing daylight saving on clock alarms2 |
|
1234 // |
|
1235 { |
|
1236 TheAlarmTest.Test().Next(_L("Initialise with daylight saving off")); |
|
1237 EnableDaylightSavingL(EFalse); |
|
1238 TheCurrentTime.UniversalTime(); |
|
1239 // |
|
1240 TheAlarmTest.Test().Next(_L("Setting UTC alarms an hour and a half in the future")); |
|
1241 // Used to set 30 minutes into future, but a defect in User::SetHomeTime() requires times |
|
1242 // not to be set between 31-10-2004 1.59 (BST) and 31-10-2004 1.59 (GMT). |
|
1243 TheInitialAlarmTime = SetUtcClockAlarms(TheCurrentTime, TTimeIntervalMinutes(90)); |
|
1244 // |
|
1245 TheAlarmTest.Test().Next(_L("Testing UTC alarms with daylight saving off")); |
|
1246 testUtcAlarmsOnForwardingClocks(EFalse, EFalse, ETrue); |
|
1247 // |
|
1248 TheAlarmTest.Test().Next(_L("Turning daylight saving on")); |
|
1249 EnableDaylightSavingL(ETrue); |
|
1250 // |
|
1251 TheAlarmTest.Test().Next(_L("Testing alarms with daylight saving on")); |
|
1252 testUtcAlarmsOnForwardingClocks(ETrue, EFalse, EFalse); |
|
1253 // |
|
1254 TheAlarmTest.Test().Next(_L("Removing all UTC alarms")); |
|
1255 TheAlarmTest.TestClearStoreL(); |
|
1256 } |
|
1257 |
|
1258 // |
|
1259 // Test changes in workdays |
|
1260 // |
|
1261 |
|
1262 static void testSetWithNoWorkdaysUtc() |
|
1263 // |
|
1264 // Test what happens when setting a workday alarm with no workdays set |
|
1265 // |
|
1266 { |
|
1267 TheAlarmTest.Test().Next(_L("Setting workday UTC alarm with no workday set")); |
|
1268 |
|
1269 // Set no workdays |
|
1270 TUint workdayMask = 0; |
|
1271 TLocale locale; |
|
1272 locale.SetWorkDays(workdayMask); |
|
1273 locale.Set(); |
|
1274 |
|
1275 // Have to wait a bit here because the kernel takes some time |
|
1276 // to notify client-side environment change objects and so |
|
1277 // we need to allow the alarm server to do its thing... |
|
1278 User::After(100000); |
|
1279 // |
|
1280 TInt ret = TheAlarmTest.Session().NumberOfAlarmsActiveInQueue(); |
|
1281 TheAlarmTest(ret == 0, __LINE__); |
|
1282 // |
|
1283 TheOriginalTime.UniversalTime(); |
|
1284 TheInitialAlarmTime = TheOriginalTime; |
|
1285 TheInitialAlarmTime += TTimeIntervalHours(1); |
|
1286 // |
|
1287 TASShdAlarm alarm; |
|
1288 alarm.Message()=(_L("Clock alarm in slot 0")); |
|
1289 alarm.SetUtcNextDueTime(TheInitialAlarmTime); |
|
1290 alarm.RepeatDefinition()=EAlarmRepeatDefintionRepeatWorkday; |
|
1291 ret = TheAlarmTest.Session().AlarmAdd(alarm); |
|
1292 TheAlarmTest(ret == KErrNone, __LINE__); |
|
1293 TheAlarmTest(alarm.Id() != KNullAlarmId, __LINE__); |
|
1294 TheClockAlarmSlots[0] = alarm.Id(); |
|
1295 |
|
1296 // Test alarm state, should be disabled |
|
1297 TASShdAlarm alarm2; |
|
1298 ret = TheAlarmTest.Session().GetAlarmDetails(alarm.Id(), alarm2); |
|
1299 TheAlarmTest(ret == KErrNone, __LINE__); |
|
1300 TheAlarmTest(alarm2.Status() == EAlarmStatusDisabled, __LINE__); |
|
1301 } |
|
1302 |
|
1303 static void testSetWorkdaysUtc() |
|
1304 // |
|
1305 // Create workdays and test |
|
1306 // |
|
1307 { |
|
1308 TheAlarmTest.Test().Next(_L("Creating and testing workdays")); |
|
1309 // |
|
1310 TInt todayMaskOffset = TheInitialAlarmTime.DayNoInWeek(); |
|
1311 TUint workdayMask = 1; |
|
1312 // |
|
1313 for (TInt count = 0; count < 7; count++) |
|
1314 { |
|
1315 workdayMask = 1; |
|
1316 const TInt dayOfWeek = (todayMaskOffset+count)%7; |
|
1317 workdayMask <<= dayOfWeek; |
|
1318 // |
|
1319 TLocale locale; |
|
1320 locale.SetWorkDays(workdayMask); |
|
1321 locale.Set(); |
|
1322 User::After(100000); |
|
1323 // |
|
1324 const TAlarmId id = TheClockAlarmSlots[0]; |
|
1325 TheAlarmTest(id != KNullAlarmId, __LINE__); |
|
1326 // |
|
1327 TASShdAlarm alarm; |
|
1328 const TInt r = TheAlarmTest.Session().GetAlarmDetails(id, alarm); |
|
1329 TheAlarmTest(r == KErrNone, __LINE__); |
|
1330 TheAlarmTest(alarm.Status() == EAlarmStatusEnabled, __LINE__); |
|
1331 // |
|
1332 TTime expectedTime = TheInitialAlarmTime; |
|
1333 expectedTime += TTimeIntervalDays(count); |
|
1334 CheckTimesAreEqual(expectedTime, alarm.NextDueTime(), __LINE__); |
|
1335 } |
|
1336 } |
|
1337 |
|
1338 static void testMakeAllWorkdaysUtcL() |
|
1339 // |
|
1340 // Make all days workdays |
|
1341 // Advance time a day at a time to test alarm for each day of the week |
|
1342 // |
|
1343 { |
|
1344 TheAlarmTest.Test().Next(_L("Make all days workdays")); |
|
1345 // |
|
1346 TBuf<60> dateTimeStr; |
|
1347 _LIT(KTimeDateFormat,"%*E%*D%X%*N%*Y %1 %2 '%3 - %-B%:0%J%:1%T%:2%S%:3%+B"); |
|
1348 |
|
1349 const TUint workdayMask = 127;// Seven 1's |
|
1350 TLocale locale; |
|
1351 locale.SetWorkDays(workdayMask); |
|
1352 locale.Set(); |
|
1353 User::After(100000); |
|
1354 |
|
1355 for (TInt count = 0; count < 7; count++) |
|
1356 { |
|
1357 if (count) |
|
1358 { |
|
1359 // Advance time |
|
1360 TTime advTime(TheOriginalTime + TTimeIntervalDays(count)); |
|
1361 User::SetUTCTime(advTime); |
|
1362 advTime.FormatL(dateTimeStr, KTimeDateFormat); |
|
1363 TheAlarmTest.Test().Printf(_L("Advance time : %S\n"), &dateTimeStr); |
|
1364 } |
|
1365 |
|
1366 const TAlarmId id = TheClockAlarmSlots[0]; |
|
1367 TheAlarmTest(id != KNullAlarmId, __LINE__); |
|
1368 // |
|
1369 TASShdAlarm alarm; |
|
1370 const TInt r = TheAlarmTest.Session().GetAlarmDetails(id, alarm); |
|
1371 TheAlarmTest(r == KErrNone, __LINE__); |
|
1372 TheAlarmTest(alarm.Status() == EAlarmStatusEnabled, __LINE__); |
|
1373 // |
|
1374 TTime expectedTime = TheInitialAlarmTime; |
|
1375 TheInitialAlarmTime.FormatL(dateTimeStr,KTimeDateFormat); |
|
1376 TheAlarmTest.Test().Printf(_L("TheInitialAlarmTime: %S\n"), &dateTimeStr); |
|
1377 |
|
1378 expectedTime += TTimeIntervalDays(count); |
|
1379 // |
|
1380 const TInt days = expectedTime.DaysFrom(alarm.NextDueTime()).Int(); |
|
1381 |
|
1382 if (days != 0) //In that case, the next due time is within 24 hours in the past |
|
1383 { |
|
1384 expectedTime -= TTimeIntervalDays(1); |
|
1385 } |
|
1386 |
|
1387 expectedTime.FormatL(dateTimeStr,KTimeDateFormat); |
|
1388 TheAlarmTest.Test().Printf(_L("expectedTime : %S\n"), &dateTimeStr); |
|
1389 |
|
1390 alarm.NextDueTime().FormatL(dateTimeStr,KTimeDateFormat); |
|
1391 TheAlarmTest.Test().Printf(_L("NextDueTime(): %S\n"), &dateTimeStr); |
|
1392 |
|
1393 CheckTimesAreEqual(expectedTime, alarm.NextDueTime(), __LINE__); |
|
1394 } |
|
1395 } |
|
1396 |
|
1397 static void testRemoveWorkdaysUtc() |
|
1398 // |
|
1399 // Remove all workdays and test |
|
1400 // |
|
1401 { |
|
1402 const TAlarmId id = TheClockAlarmSlots[0]; |
|
1403 TheAlarmTest(id != KNullAlarmId, __LINE__); |
|
1404 // |
|
1405 TLocale locale; |
|
1406 locale.SetWorkDays(0); |
|
1407 locale.Set(); |
|
1408 User::After(100000); |
|
1409 // |
|
1410 TASShdAlarm alarm; |
|
1411 const TInt r = TheAlarmTest.Session().GetAlarmDetails(id, alarm); |
|
1412 // |
|
1413 TheAlarmTest(r == KErrNone, __LINE__); |
|
1414 TheAlarmTest(alarm.Status() == EAlarmStatusDisabled, __LINE__); |
|
1415 } |
|
1416 |
|
1417 static void testLocaleChangeWorkdaysUtcL() |
|
1418 // |
|
1419 // Test effects of changing workdays on alarms |
|
1420 // |
|
1421 { |
|
1422 TheAlarmTest.TestClearStoreL(); |
|
1423 testSetWithNoWorkdaysUtc(); |
|
1424 testSetWorkdaysUtc(); |
|
1425 testMakeAllWorkdaysUtcL(); |
|
1426 testRemoveWorkdaysUtc(); |
|
1427 TheAlarmTest.TestClearStoreL(); |
|
1428 } |
|
1429 |
|
1430 static void test24HourToOnceOnlyUtcAlarms() |
|
1431 { |
|
1432 TheAlarmTest.Test().Next(_L("Test update of 24 hour alarms to once only alarms")); |
|
1433 |
|
1434 // Next 24 hour alarms which are more than 1 day in the future after a system time |
|
1435 // update should be updated to once only alarms |
|
1436 |
|
1437 // Set 'next 24 hour' alarms due in 5, just under and over 18, and 21 hours time |
|
1438 TTime now; |
|
1439 now.UniversalTime(); |
|
1440 TTime alarmTime(now); |
|
1441 |
|
1442 TASShdAlarm alarm; |
|
1443 alarm.RepeatDefinition()=EAlarmRepeatDefintionRepeatNext24Hours; |
|
1444 |
|
1445 alarmTime += TTimeIntervalHours(5); |
|
1446 alarm.SetUtcNextDueTime(alarmTime); |
|
1447 TheAlarmTest(TheAlarmTest.Session().AlarmAdd(alarm) == KErrNone, __LINE__); |
|
1448 TAlarmId id1 = alarm.Id(); |
|
1449 TheAlarmTest(id1 != KNullAlarmId, __LINE__); |
|
1450 |
|
1451 alarmTime += TTimeIntervalHours(13); |
|
1452 alarmTime -= TTimeIntervalMinutes(1); |
|
1453 alarm.SetUtcNextDueTime(alarmTime); |
|
1454 TheAlarmTest(TheAlarmTest.Session().AlarmAdd(alarm) == KErrNone, __LINE__); |
|
1455 TAlarmId id2 = alarm.Id(); |
|
1456 TheAlarmTest(id2 != KNullAlarmId, __LINE__); |
|
1457 |
|
1458 alarmTime += TTimeIntervalMinutes(2); |
|
1459 alarm.SetUtcNextDueTime(alarmTime); |
|
1460 TheAlarmTest(TheAlarmTest.Session().AlarmAdd(alarm) == KErrNone, __LINE__); |
|
1461 TAlarmId id3 = alarm.Id(); |
|
1462 TheAlarmTest(id3 != KNullAlarmId, __LINE__); |
|
1463 |
|
1464 alarmTime += TTimeIntervalHours(3); |
|
1465 alarm.SetUtcNextDueTime(alarmTime); |
|
1466 TheAlarmTest(TheAlarmTest.Session().AlarmAdd(alarm) == KErrNone, __LINE__); |
|
1467 TAlarmId id4 = alarm.Id(); |
|
1468 TheAlarmTest(id4 != KNullAlarmId, __LINE__); |
|
1469 |
|
1470 // Set system time back 6 hours - alarms are now due in 11, just under and over 24, and 27 hours |
|
1471 |
|
1472 now -= TTimeIntervalHours(6); |
|
1473 User::SetUTCTime(now); |
|
1474 |
|
1475 User::After(KTimeToWait); |
|
1476 |
|
1477 TheAlarmTest(TheAlarmTest.Session().GetAlarmDetails(id1,alarm) == KErrNone, __LINE__); |
|
1478 TheAlarmTest(alarm.RepeatDefinition() == EAlarmRepeatDefintionRepeatNext24Hours, __LINE__); |
|
1479 TheAlarmTest(TheAlarmTest.Session().GetAlarmDetails(id2,alarm) == KErrNone, __LINE__); |
|
1480 TheAlarmTest(alarm.RepeatDefinition() == EAlarmRepeatDefintionRepeatNext24Hours, __LINE__); |
|
1481 TheAlarmTest(TheAlarmTest.Session().GetAlarmDetails(id3,alarm) == KErrNone, __LINE__); |
|
1482 TheAlarmTest(alarm.RepeatDefinition() == EAlarmRepeatDefintionRepeatOnce, __LINE__); |
|
1483 TheAlarmTest(TheAlarmTest.Session().GetAlarmDetails(id4,alarm) == KErrNone, __LINE__); |
|
1484 TheAlarmTest(alarm.RepeatDefinition() == EAlarmRepeatDefintionRepeatOnce, __LINE__); |
|
1485 } |
|
1486 |
|
1487 static void testUtcAlarmPersistenceAfterSystemTimeUpdateL() |
|
1488 { |
|
1489 // Following a system time update, queued alarms may or may not |
|
1490 // be removed, depending on the following conditions |
|
1491 // |
|
1492 // * EAlarmRepeatDefintionRepeatOnce |
|
1493 // * EAlarmRepeatDefintionRepeatNext24Hours |
|
1494 // Alarm is removed if more than 1 day in the past |
|
1495 // |
|
1496 // * EAlarmRepeatDefintionRepeatDaily |
|
1497 // * EAlarmRepeatDefintionRepeatWorkday |
|
1498 // * EAlarmRepeatDefintionRepeatWeekly |
|
1499 // All repeating alarms queue the next repeat of the alarm |
|
1500 |
|
1501 TheAlarmTest.Test().Next(_L("update system time whilst UTC alarm notifying")); |
|
1502 |
|
1503 #if defined(_DEBUG) |
|
1504 TheAlarmTest.Session().__DbgPreventUserNotify(ETrue); |
|
1505 #define KAlarmStateNotify EAlarmStateNotified |
|
1506 #else |
|
1507 #define KAlarmStateNotify EAlarmStateNotifying |
|
1508 #endif |
|
1509 |
|
1510 for (TInt ii = 0; ii < 4; ++ii) |
|
1511 { |
|
1512 // Get current alarm counts |
|
1513 TInt previousQueued = TheAlarmTest.Session().AlarmCountByState(EAlarmStateQueued); |
|
1514 TInt previousNotifying = TheAlarmTest.Session().AlarmCountByState(KAlarmStateNotify) + |
|
1515 TheAlarmTest.Session().AlarmCountByState(EAlarmStateWaitingToNotify); |
|
1516 |
|
1517 TTime time; |
|
1518 SafeHomeTime(time); |
|
1519 time -= User::UTCOffset(); |
|
1520 time += TTimeIntervalSeconds(2); |
|
1521 |
|
1522 TTime systemTime(time); |
|
1523 |
|
1524 switch (ii) |
|
1525 { |
|
1526 case 0: |
|
1527 TheAlarmTest.Test().Next(_L("set time back 1 hour")); |
|
1528 systemTime -= TTimeIntervalHours(1); |
|
1529 break; |
|
1530 case 1: |
|
1531 TheAlarmTest.Test().Next(_L("set time forward 1 hour")); |
|
1532 systemTime += TTimeIntervalHours(1); |
|
1533 break; |
|
1534 case 2: |
|
1535 TheAlarmTest.Test().Next(_L("set time back 2 days")); |
|
1536 systemTime -= TTimeIntervalDays(2); |
|
1537 break; |
|
1538 case 3: |
|
1539 TheAlarmTest.Test().Next(_L("set time forward 2 days")); |
|
1540 systemTime += TTimeIntervalDays(2); |
|
1541 break; |
|
1542 default: |
|
1543 TheAlarmTest(EFalse, __LINE__); |
|
1544 break; |
|
1545 } |
|
1546 |
|
1547 // add a UTC alarm of each repeat type due now |
|
1548 TASShdAlarm alarm; |
|
1549 |
|
1550 alarm.SetUtcNextDueTime(time); |
|
1551 alarm.RepeatDefinition()=EAlarmRepeatDefintionRepeatOnce; |
|
1552 TheAlarmTest(TheAlarmTest.Session().AlarmAdd(alarm) == KErrNone, __LINE__); |
|
1553 TAlarmId idOnce = alarm.Id(); |
|
1554 TheAlarmTest(idOnce != KNullAlarmId, __LINE__); |
|
1555 |
|
1556 alarm.SetUtcNextDueTime(time); |
|
1557 alarm.RepeatDefinition()=EAlarmRepeatDefintionRepeatNext24Hours; |
|
1558 TheAlarmTest(TheAlarmTest.Session().AlarmAdd(alarm) == KErrNone, __LINE__); |
|
1559 TAlarmId id24hr = alarm.Id(); |
|
1560 TheAlarmTest(id24hr != KNullAlarmId, __LINE__); |
|
1561 |
|
1562 alarm.SetUtcNextDueTime(time); |
|
1563 alarm.RepeatDefinition()=EAlarmRepeatDefintionRepeatDaily; |
|
1564 TheAlarmTest(TheAlarmTest.Session().AlarmAdd(alarm) == KErrNone, __LINE__); |
|
1565 TAlarmId idDaily = alarm.Id(); |
|
1566 TheAlarmTest(idDaily != KNullAlarmId, __LINE__); |
|
1567 |
|
1568 alarm.SetUtcNextDueTime(time); |
|
1569 alarm.RepeatDefinition()=EAlarmRepeatDefintionRepeatWorkday; |
|
1570 TheAlarmTest(TheAlarmTest.Session().AlarmAdd(alarm) == KErrNone, __LINE__); |
|
1571 TAlarmId idWorkday = alarm.Id(); |
|
1572 TheAlarmTest(idWorkday != KNullAlarmId, __LINE__); |
|
1573 |
|
1574 alarm.SetUtcNextDueTime(time); |
|
1575 alarm.RepeatDefinition()=EAlarmRepeatDefintionRepeatWeekly; |
|
1576 TheAlarmTest(TheAlarmTest.Session().AlarmAdd(alarm) == KErrNone, __LINE__); |
|
1577 TAlarmId idWeekly = alarm.Id(); |
|
1578 TheAlarmTest(idWeekly != KNullAlarmId, __LINE__); |
|
1579 |
|
1580 TInt queued = TheAlarmTest.Session().AlarmCountByState(EAlarmStateQueued); |
|
1581 TInt notifying = TheAlarmTest.Session().AlarmCountByState(KAlarmStateNotify) + |
|
1582 TheAlarmTest.Session().AlarmCountByState(EAlarmStateWaitingToNotify); |
|
1583 TheAlarmTest(queued == previousQueued + 5, __LINE__); |
|
1584 TheAlarmTest(notifying == previousNotifying, __LINE__); |
|
1585 |
|
1586 // wait for the alarms to go off |
|
1587 User::After(10 * KTimeToWait); |
|
1588 queued = TheAlarmTest.Session().AlarmCountByState(EAlarmStateQueued); |
|
1589 notifying = TheAlarmTest.Session().AlarmCountByState(KAlarmStateNotify) + |
|
1590 TheAlarmTest.Session().AlarmCountByState(EAlarmStateWaitingToNotify); |
|
1591 TheAlarmTest(queued == previousQueued + 4, __LINE__); |
|
1592 TheAlarmTest(notifying == previousNotifying + 1, __LINE__); |
|
1593 |
|
1594 // update the system time |
|
1595 |
|
1596 User::SetUTCTime(systemTime); |
|
1597 |
|
1598 User::After(KTimeToWait); |
|
1599 |
|
1600 // check the queue of alarms |
|
1601 queued = TheAlarmTest.Session().AlarmCountByState(EAlarmStateQueued); |
|
1602 notifying = TheAlarmTest.Session().AlarmCountByState(KAlarmStateNotify) + |
|
1603 TheAlarmTest.Session().AlarmCountByState(EAlarmStateWaitingToNotify); |
|
1604 |
|
1605 switch (ii) |
|
1606 { |
|
1607 case 0: // set time back 1 hour |
|
1608 case 1: // set time forward 1 hour |
|
1609 case 2: // set time back 2 days |
|
1610 { |
|
1611 // No alarms should be removed |
|
1612 TheAlarmTest(queued == previousQueued + 4, __LINE__); |
|
1613 TheAlarmTest(notifying == previousNotifying + 1, __LINE__); |
|
1614 TheAlarmTest(TheAlarmTest.Session().GetAlarmDetails(idOnce,alarm) == KErrNone, __LINE__); |
|
1615 TheAlarmTest(alarm.State() == EAlarmStateQueued || alarm.State() == KAlarmStateNotify || alarm.State() == EAlarmStateWaitingToNotify, __LINE__); |
|
1616 TheAlarmTest(TheAlarmTest.Session().GetAlarmDetails(id24hr,alarm) == KErrNone, __LINE__); |
|
1617 TheAlarmTest(alarm.State() == EAlarmStateQueued || alarm.State() == KAlarmStateNotify || alarm.State() == EAlarmStateWaitingToNotify, __LINE__); |
|
1618 TheAlarmTest(TheAlarmTest.Session().GetAlarmDetails(idDaily,alarm) == KErrNone, __LINE__); |
|
1619 TheAlarmTest(alarm.State() == EAlarmStateQueued || alarm.State() == KAlarmStateNotify || alarm.State() == EAlarmStateWaitingToNotify, __LINE__); |
|
1620 TheAlarmTest(TheAlarmTest.Session().GetAlarmDetails(idWorkday,alarm) == KErrNone, __LINE__); |
|
1621 TheAlarmTest(alarm.State() == EAlarmStateQueued || alarm.State() == KAlarmStateNotify || alarm.State() == EAlarmStateWaitingToNotify, __LINE__); |
|
1622 TheAlarmTest(TheAlarmTest.Session().GetAlarmDetails(idWeekly,alarm) == KErrNone, __LINE__); |
|
1623 TheAlarmTest(alarm.State() == EAlarmStateQueued || alarm.State() == KAlarmStateNotify || alarm.State() == EAlarmStateWaitingToNotify, __LINE__); |
|
1624 break; |
|
1625 } |
|
1626 case 3: // set time forward 2 days |
|
1627 { |
|
1628 // once only and 24hr alarms should be removed |
|
1629 TheAlarmTest(queued + notifying == previousQueued + previousNotifying + 3, __LINE__); |
|
1630 TheAlarmTest(TheAlarmTest.Session().GetAlarmDetails(idOnce,alarm) == KErrNotFound, __LINE__); |
|
1631 TheAlarmTest(TheAlarmTest.Session().GetAlarmDetails(id24hr,alarm) == KErrNotFound, __LINE__); |
|
1632 TheAlarmTest(TheAlarmTest.Session().GetAlarmDetails(idDaily,alarm) == KErrNone, __LINE__); |
|
1633 TheAlarmTest(alarm.State() == EAlarmStateQueued || alarm.State() == KAlarmStateNotify || alarm.State() == EAlarmStateWaitingToNotify, __LINE__); |
|
1634 TheAlarmTest(TheAlarmTest.Session().GetAlarmDetails(idWorkday,alarm) == KErrNone, __LINE__); |
|
1635 TheAlarmTest(alarm.State() == EAlarmStateQueued || alarm.State() == KAlarmStateNotify || alarm.State() == EAlarmStateWaitingToNotify, __LINE__); |
|
1636 TheAlarmTest(TheAlarmTest.Session().GetAlarmDetails(idWeekly,alarm) == KErrNone, __LINE__); |
|
1637 TheAlarmTest(alarm.State() == EAlarmStateQueued || alarm.State() == KAlarmStateNotify || alarm.State() == EAlarmStateWaitingToNotify, __LINE__); |
|
1638 break; |
|
1639 } |
|
1640 default: |
|
1641 TheAlarmTest(EFalse, __LINE__); |
|
1642 break; |
|
1643 } |
|
1644 |
|
1645 TheAlarmTest.Session().AlarmDelete(idOnce); |
|
1646 TheAlarmTest.Session().AlarmDelete(id24hr); |
|
1647 TheAlarmTest.Session().AlarmDelete(idDaily); |
|
1648 TheAlarmTest.Session().AlarmDelete(idWorkday); |
|
1649 TheAlarmTest.Session().AlarmDelete(idWeekly); |
|
1650 } |
|
1651 } |
|
1652 |
|
1653 |
|
1654 static void doTestsL() |
|
1655 { |
|
1656 //get the initial time |
|
1657 TTime homeTime; |
|
1658 homeTime.HomeTime(); |
|
1659 |
|
1660 CActiveScheduler* scheduler = new (ELeave) CActiveScheduler; |
|
1661 CleanupStack::PushL(scheduler); |
|
1662 CActiveScheduler::Install(scheduler); |
|
1663 |
|
1664 User::LeaveIfError(timezone.Connect()); |
|
1665 |
|
1666 // safeguard against leaving |
|
1667 CleanupClosePushL(timezone); |
|
1668 |
|
1669 timezone.SetAutoUpdateBehaviorL(RTz::ETZAutoDSTUpdateOn); |
|
1670 |
|
1671 TheAlarmTest.TestStartServers(); |
|
1672 TheAlarmTest(TheAlarmTest.Session().Connect() == KErrNone, __LINE__); |
|
1673 TheAlarmTest.TestClearStoreL(); |
|
1674 |
|
1675 #if defined(_DEBUG) |
|
1676 TheAlarmTest.Session().__DbgPreventUserNotify(ETrue); |
|
1677 #endif |
|
1678 |
|
1679 |
|
1680 // Disable Daylight Saving |
|
1681 EnableDaylightSavingL(EFalse); |
|
1682 |
|
1683 User::After(100000); |
|
1684 |
|
1685 // |
|
1686 // Test the local API. |
|
1687 |
|
1688 TheAlarmTest.Test().Printf(_L("Begin local API tests.")); |
|
1689 |
|
1690 TestAlarmsWithDaylightSavingChange1L(); |
|
1691 TestAlarmsWithDaylightSavingChange2L(); |
|
1692 /* |
|
1693 Changes to the UTC offset due to a DST change produce equivalent behaviour |
|
1694 to changes to the UTC offset due to a locale change, therefore, there is no |
|
1695 need to test DST and locale changes separately. |
|
1696 */ |
|
1697 |
|
1698 // Reset locale for workday testing |
|
1699 // Disable Daylight Saving |
|
1700 EnableDaylightSavingL(EFalse); |
|
1701 User::After(100000); |
|
1702 testLocaleChangeWorkdaysL(); |
|
1703 test24HourToOnceOnlyAlarms(); |
|
1704 // |
|
1705 // The workdays enabled. |
|
1706 TInt workdays = (1 << EMonday) | (1 << ETuesday) | (1 << EWednesday) | (1 << EThursday) | (1 << EFriday); |
|
1707 |
|
1708 TLocale locale; |
|
1709 locale.SetWorkDays(workdays); |
|
1710 locale.Set(); |
|
1711 User::After(100000); |
|
1712 |
|
1713 // Update system time while alarm is notifying |
|
1714 testAlarmPersistenceAfterSystemTimeUpdateL(); |
|
1715 |
|
1716 // Clean up after the local API test if it was run. |
|
1717 TheAlarmTest.TestClearStoreL(); |
|
1718 |
|
1719 // |
|
1720 // Test the UTC API. |
|
1721 |
|
1722 TheAlarmTest.Test().Printf(_L("Begin UTC API tests.")); |
|
1723 |
|
1724 TestUtcAlarmsWithDaylightSavingChange1L(); |
|
1725 TestUtcAlarmsWithDaylightSavingChange2L(); |
|
1726 /* |
|
1727 Changes to the UTC offset due to a DST change produce equivalent behaviour |
|
1728 to changes to the UTC offset due to a locale change, therefore, there is no |
|
1729 need to test DST and locale changes separately. |
|
1730 */ |
|
1731 |
|
1732 // Reset locale for workday testing |
|
1733 // Disable Daylight Saving |
|
1734 EnableDaylightSavingL(EFalse); |
|
1735 User::After(100000); |
|
1736 testLocaleChangeWorkdaysUtcL(); |
|
1737 test24HourToOnceOnlyUtcAlarms(); |
|
1738 // |
|
1739 workdays = (1 << EMonday) | (1 << ETuesday) | (1 << EWednesday) | (1 << EThursday) | (1 << EFriday); |
|
1740 locale.SetWorkDays(workdays); |
|
1741 locale.Set(); |
|
1742 User::After(100000); |
|
1743 |
|
1744 // Update system time while alarm is notifying |
|
1745 testUtcAlarmPersistenceAfterSystemTimeUpdateL(); |
|
1746 |
|
1747 CleanupStack::PopAndDestroy(&timezone); |
|
1748 |
|
1749 |
|
1750 //Set back the time to the initial time |
|
1751 RPIMTestServer testserver; |
|
1752 User::LeaveIfError(testserver.Connect()); |
|
1753 testserver.SetHomeTime(homeTime); |
|
1754 testserver.Close(); |
|
1755 |
|
1756 CleanupStack::PopAndDestroy(scheduler); |
|
1757 } |
|
1758 |
|
1759 /** |
|
1760 |
|
1761 @SYMTestCaseID PIM-TALARMLOCALECHANGES-0001 |
|
1762 |
|
1763 */ |
|
1764 |
|
1765 GLDEF_C TInt E32Main() |
|
1766 // |
|
1767 // Test the alarm server. |
|
1768 // |
|
1769 { |
|
1770 TInt ret = KErrNone; |
|
1771 TheAlarmTest.Title(); |
|
1772 TheAlarmTest.Start(_L("@SYMTestCaseID:PIM-TALARMLOCALECHANGES-0001 \"Clock\" alarms")); |
|
1773 |
|
1774 __UHEAP_MARK; |
|
1775 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
1776 TRAP_IGNORE(doTestsL()); |
|
1777 delete cleanup; |
|
1778 __UHEAP_MARKEND; |
|
1779 |
|
1780 TheAlarmTest.Session().Close(); |
|
1781 TRAP(ret,TheAlarmTest.EndL()); |
|
1782 |
|
1783 TheAlarmTest.Test().Close(); |
|
1784 ASTstAlarmTest::Close(); |
|
1785 // |
|
1786 return ret; |
|
1787 } |