|
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 session notification of alarms |
|
15 // |
|
16 // |
|
17 |
|
18 #include "ASTstAlarmTest.h" |
|
19 #include "testserver.h" |
|
20 |
|
21 // Constants |
|
22 const TUint KHeapMinSize=0x01000; |
|
23 const TUint KHeapMaxSize=0x10000; |
|
24 |
|
25 // Globals |
|
26 static TAlarmId TheAlarmId = KNullAlarmId; |
|
27 static TBool TheNotifyFlag=EFalse; |
|
28 static TBool TheNotifyThread=ETrue; |
|
29 static TRequestStatus TheCurrentRequest=KErrNone; |
|
30 static TRequestStatus TheSessionStatus; |
|
31 // |
|
32 static void testOtherNotify(TBool aExpected); |
|
33 static void testThisNotify(TInt aExpected=KErrNone); |
|
34 |
|
35 |
|
36 static TInt ntfThreadMain(TAny* /*aPtr*/) |
|
37 // |
|
38 // Main thread of notification thread |
|
39 // |
|
40 { |
|
41 RASCliSession almSvr; |
|
42 const TInt r=almSvr.Connect(); |
|
43 TheAlarmTest(r==KErrNone, __LINE__); |
|
44 // |
|
45 TAlarmId alarmId; |
|
46 TRequestStatus stat; |
|
47 FOREVER |
|
48 { |
|
49 FOREVER |
|
50 { |
|
51 almSvr.NotifyChange(stat, alarmId); |
|
52 User::After(KTimeToWait); |
|
53 if (stat == KRequestPending) |
|
54 break; |
|
55 User::WaitForRequest(stat); |
|
56 } |
|
57 User::WaitForRequest(stat); |
|
58 // |
|
59 if (!TheNotifyThread) |
|
60 break; |
|
61 // |
|
62 TheAlarmTest(stat >= EAlarmChangeEventState && stat <= EAlarmChangeEventLast, __LINE__); |
|
63 TheNotifyFlag = ETrue; |
|
64 } |
|
65 // |
|
66 TheNotifyFlag=ETrue; |
|
67 return(KErrNone); |
|
68 } |
|
69 |
|
70 |
|
71 static void startNotifyThread() |
|
72 // |
|
73 // Start the thread that determines NotifyOnChange |
|
74 // |
|
75 { |
|
76 TheAlarmTest.Test().Next(_L("Starting the notification test thread")); |
|
77 RThread t; |
|
78 TInt r=t.Create(_L("NtfThread"),ntfThreadMain,KDefaultStackSize,KHeapMinSize,KHeapMaxSize,NULL); |
|
79 TheAlarmTest(r==KErrNone, __LINE__); |
|
80 TRequestStatus tStat; |
|
81 t.Logon(tStat); |
|
82 t.SetPriority(EPriorityMore); |
|
83 TheAlarmTest(tStat==KRequestPending, __LINE__); |
|
84 t.Resume(); |
|
85 TheAlarmTest(tStat==KRequestPending, __LINE__); |
|
86 User::After(KTimeToWait); |
|
87 } |
|
88 |
|
89 |
|
90 static void testSetupNotify() |
|
91 // |
|
92 // Set up the notify requests |
|
93 // |
|
94 { |
|
95 TheNotifyFlag=EFalse; |
|
96 startNotifyThread(); |
|
97 // |
|
98 TheAlarmTest.Test().Next(_L("Set up notification requests")); |
|
99 // |
|
100 TheAlarmTest.WaitForNotificationBufferToBeEmptied(TheCurrentRequest, TheAlarmId); |
|
101 TheAlarmTest.Session().NotifyChangeCancel(); |
|
102 // |
|
103 TheAlarmTest(TheCurrentRequest == KErrCancel, __LINE__); |
|
104 TheAlarmTest(TheNotifyFlag == EFalse, __LINE__); |
|
105 // |
|
106 #if defined(_DEBUG) |
|
107 TheAlarmTest.Session().__DbgPreventUserNotify(ETrue); |
|
108 #endif |
|
109 // |
|
110 TheAlarmTest.WaitForNotificationBufferToBeEmptied(TheCurrentRequest, TheAlarmId); |
|
111 } |
|
112 |
|
113 static void testOtherNotify(TBool aExpected) |
|
114 // |
|
115 // Check there was a notification to the notify thread |
|
116 // |
|
117 { |
|
118 User::After(KTimeToWait); |
|
119 TheAlarmTest(TheNotifyFlag==aExpected, __LINE__); |
|
120 TheNotifyFlag=EFalse; |
|
121 } |
|
122 |
|
123 static void testThisNotify(TInt aExpected) |
|
124 // |
|
125 // Check there the notification of this thread. Because notifications |
|
126 // in the new Alarm Server are bufferred, then the first notification |
|
127 // may not be the one we are looking for. Therefore we continue to |
|
128 // request notifications until the buffer is exhausted, at which point, |
|
129 // if we haven't yet seent the notification we were looking for, we |
|
130 // panic. |
|
131 // |
|
132 { |
|
133 if (TheCurrentRequest != aExpected) |
|
134 { |
|
135 // Need to exhaust the event buffer |
|
136 |
|
137 // If the buffer is empty (server side) then the current |
|
138 // request will still be outstanding, therefore the test |
|
139 // has failed. |
|
140 User::After(KTimeToWait); |
|
141 TheAlarmTest(TheCurrentRequest != KRequestPending, __LINE__); |
|
142 |
|
143 // Eat current request |
|
144 User::WaitForRequest(TheCurrentRequest); |
|
145 |
|
146 // Now go through each item in the buffer, requesting them |
|
147 // one by one |
|
148 FOREVER |
|
149 { |
|
150 TheAlarmTest.Session().NotifyChange(TheCurrentRequest, TheAlarmId); |
|
151 User::After(KTimeToWait); |
|
152 TheAlarmTest(TheCurrentRequest != KRequestPending, __LINE__); |
|
153 User::WaitForRequest(TheCurrentRequest); |
|
154 if (TheCurrentRequest == aExpected) |
|
155 break; |
|
156 } |
|
157 } |
|
158 |
|
159 // Request another notification |
|
160 if (TheCurrentRequest != KRequestPending) |
|
161 { |
|
162 // Eat all the rest |
|
163 TheAlarmTest.WaitForNotificationBufferToBeEmptied(TheCurrentRequest, TheAlarmId); |
|
164 } |
|
165 } |
|
166 |
|
167 |
|
168 static void testTimeChangeL() |
|
169 // |
|
170 // Test that time notifications work |
|
171 // |
|
172 { |
|
173 RPIMTestServer serv; |
|
174 User::LeaveIfError(serv.Connect()); |
|
175 |
|
176 TheAlarmTest.Test().Next(_L("Time changes and alarms set with local wall-clock time.")); |
|
177 // |
|
178 testOtherNotify(EFalse); |
|
179 testThisNotify(KRequestPending); |
|
180 // |
|
181 testThisNotify(KRequestPending); |
|
182 testOtherNotify(EFalse); |
|
183 // |
|
184 TTime home; |
|
185 home.HomeTime(); |
|
186 home+=TTimeIntervalMinutes(2); |
|
187 |
|
188 serv.SetHomeTime(home); |
|
189 |
|
190 User::After(KTimeToWait); |
|
191 // |
|
192 testThisNotify(EAlarmChangeEventSystemDateTimeChanged); |
|
193 testOtherNotify(ETrue); |
|
194 testOtherNotify(EFalse); |
|
195 testThisNotify(KRequestPending); |
|
196 // |
|
197 TASShdAlarm alarm; |
|
198 alarm.Message() = _L("Time"); |
|
199 alarm.NextDueTime().HomeTime(); |
|
200 alarm.NextDueTime() += TTimeIntervalMinutes(30); |
|
201 TheAlarmTest.Session().AlarmAddWithNotification(TheSessionStatus, alarm); |
|
202 TheAlarmTest(TheSessionStatus == KRequestPending, __LINE__); |
|
203 // |
|
204 testOtherNotify(ETrue); |
|
205 testThisNotify(EAlarmChangeEventAlarmAddition); |
|
206 TheAlarmTest.WaitForNotificationBufferToBeEmptied(TheCurrentRequest, TheAlarmId); |
|
207 // |
|
208 TInt r; |
|
209 TAlarmId nextDueAlarmId; |
|
210 // |
|
211 r = TheAlarmTest.Session().GetNextDueAlarmId(nextDueAlarmId); |
|
212 TheAlarmTest(r == KErrNone, __LINE__); |
|
213 TheAlarmTest(nextDueAlarmId = alarm.Id(), __LINE__); |
|
214 // |
|
215 TASShdAlarm retrievedAlarm; |
|
216 r = TheAlarmTest.Session().GetAlarmDetails(nextDueAlarmId, retrievedAlarm); |
|
217 TheAlarmTest(r == KErrNone, __LINE__); |
|
218 TheAlarmTest(retrievedAlarm.Message() == _L("Time"), __LINE__); |
|
219 // |
|
220 serv.SetHomeTime(retrievedAlarm.NextDueTime()); |
|
221 serv.Close(); |
|
222 |
|
223 User::After(KTimeToWait); |
|
224 // |
|
225 testOtherNotify(ETrue); |
|
226 testThisNotify(EAlarmChangeEventSystemDateTimeChanged); |
|
227 TheAlarmTest(TheSessionStatus != KRequestPending, __LINE__); |
|
228 User::WaitForRequest(TheSessionStatus); |
|
229 // |
|
230 r = TheAlarmTest.Session().GetNextDueAlarmId(nextDueAlarmId); |
|
231 TheAlarmTest(r == KErrNone, __LINE__); |
|
232 TheAlarmTest(nextDueAlarmId == KNullAlarmId, __LINE__); |
|
233 // |
|
234 TheAlarmTest.Session().AlarmNotificationCancelAndDequeue(alarm.Id()); |
|
235 testThisNotify(EAlarmChangeEventAlarmDeletion); |
|
236 testOtherNotify(ETrue); |
|
237 // |
|
238 alarm.NextDueTime() += TTimeIntervalDays(1); |
|
239 alarm.Message() = _L("DayTime"); |
|
240 TheAlarmTest.Session().AlarmAddWithNotification(TheSessionStatus, alarm); |
|
241 testThisNotify(EAlarmChangeEventAlarmAddition); |
|
242 // |
|
243 TheAlarmTest.Session().AlarmNotificationCancelAndDequeue(alarm.Id()); |
|
244 testThisNotify(EAlarmChangeEventAlarmDeletion); |
|
245 // |
|
246 TheAlarmTest.Session().AlarmAddWithNotification(TheSessionStatus, alarm); |
|
247 testThisNotify(EAlarmChangeEventAlarmAddition); |
|
248 testOtherNotify(ETrue); |
|
249 // |
|
250 TheAlarmTest.Session().AlarmNotificationCancelAndDequeue(alarm.Id()); |
|
251 testThisNotify(EAlarmChangeEventAlarmDeletion); |
|
252 // |
|
253 TheAlarmTest(TheSessionStatus==KErrCancel, __LINE__); |
|
254 testOtherNotify(ETrue); |
|
255 } |
|
256 |
|
257 |
|
258 static void testSetAndCancelPast() |
|
259 // |
|
260 // Test that each type of alarm goes off if set in the past. |
|
261 // Careful of DayAlarms - cant be sure if a time in today is past/before the current time. |
|
262 // |
|
263 { |
|
264 TheAlarmTest.Test().Next(_L("Set alarms with local wall-clock time in past")); |
|
265 testOtherNotify(EFalse); |
|
266 // |
|
267 TASShdAlarm alarm; |
|
268 alarm.Message() = _L("Past"); |
|
269 alarm.SoundName() = _L("none"); |
|
270 alarm.NextDueTime().HomeTime(); |
|
271 alarm.NextDueTime() += TTimeIntervalDays(-2); |
|
272 // |
|
273 testThisNotify(KRequestPending); |
|
274 testOtherNotify(EFalse); |
|
275 // |
|
276 TInt r; |
|
277 // |
|
278 r = TheAlarmTest.Session().AlarmAdd(alarm); |
|
279 TheAlarmTest(r == KErrNone, __LINE__); |
|
280 TheAlarmTest(alarm.Id() != KNullAlarmId, __LINE__); |
|
281 TAlarmId clockAlarmId = alarm.Id(); |
|
282 // |
|
283 testThisNotify(EAlarmChangeEventAlarmAddition); |
|
284 testOtherNotify(ETrue); |
|
285 TheAlarmTest.WaitForNotificationBufferToBeEmptied(TheCurrentRequest, TheAlarmId); |
|
286 // |
|
287 testThisNotify(KRequestPending); |
|
288 testOtherNotify(EFalse); |
|
289 testThisNotify(KRequestPending); |
|
290 // |
|
291 TheAlarmTest.Session().AlarmAddWithNotification(TheSessionStatus, alarm); |
|
292 TheAlarmTest(alarm.Id() != KNullAlarmId, __LINE__); |
|
293 testOtherNotify(ETrue); |
|
294 testThisNotify(EAlarmChangeEventAlarmAddition); |
|
295 TheAlarmTest(TheSessionStatus == KErrNone, __LINE__); |
|
296 User::WaitForRequest(TheSessionStatus); |
|
297 // |
|
298 TheAlarmTest.Session().AlarmNotificationCancelAndDequeue(alarm.Id()); |
|
299 testThisNotify(EAlarmChangeEventAlarmDeletion); |
|
300 testOtherNotify(ETrue); |
|
301 // |
|
302 r = TheAlarmTest.Session().AlarmDelete(clockAlarmId); |
|
303 TheAlarmTest(r == 0, __LINE__); |
|
304 testThisNotify(EAlarmChangeEventAlarmDeletion); |
|
305 testOtherNotify(ETrue); |
|
306 } |
|
307 |
|
308 |
|
309 static void testSetAndCancelFuture() |
|
310 // |
|
311 // Set alarms in future |
|
312 // |
|
313 { |
|
314 TheAlarmTest.Test().Next(_L("Set alarms with local wall-clock time in future")); |
|
315 TheAlarmTest(TheNotifyFlag==EFalse, __LINE__); |
|
316 // |
|
317 TASShdAlarm alarm; |
|
318 alarm.Message() = _L("Future"); |
|
319 alarm.NextDueTime().HomeTime(); |
|
320 alarm.NextDueTime() += TTimeIntervalDays(1); |
|
321 alarm.NextDueTime() += TTimeIntervalMinutes(30); |
|
322 // |
|
323 testOtherNotify(EFalse); |
|
324 testThisNotify(KRequestPending); |
|
325 // |
|
326 TheAlarmTest.Session().AlarmAddWithNotification(TheSessionStatus, alarm); |
|
327 TheAlarmTest(alarm.Id() != KNullAlarmId, __LINE__); |
|
328 TheAlarmTest(TheSessionStatus == KRequestPending, __LINE__); |
|
329 testOtherNotify(ETrue); |
|
330 testThisNotify(EAlarmChangeEventAlarmAddition); |
|
331 // |
|
332 TAlarmId id; |
|
333 TASShdAlarm retrievedAlarm; |
|
334 TInt r; |
|
335 // |
|
336 r = TheAlarmTest.Session().GetNextDueAlarmId(id); |
|
337 TheAlarmTest(r == KErrNone, __LINE__); |
|
338 TheAlarmTest(id == alarm.Id(), __LINE__); |
|
339 r = TheAlarmTest.Session().GetAlarmDetails(alarm.Id(), retrievedAlarm); |
|
340 TheAlarmTest(r == KErrNone, __LINE__); |
|
341 TheAlarmTest(retrievedAlarm.Id() == alarm.Id(), __LINE__); |
|
342 // |
|
343 TheAlarmTest.Session().AlarmNotificationCancelAndDequeue(alarm.Id()); |
|
344 testOtherNotify(ETrue); |
|
345 TheAlarmTest(TheSessionStatus==KErrCancel, __LINE__); |
|
346 testThisNotify(EAlarmChangeEventAlarmDeletion); |
|
347 // |
|
348 r = TheAlarmTest.Session().GetNextDueAlarmId(id); |
|
349 TheAlarmTest(r == KErrNone, __LINE__); |
|
350 TheAlarmTest(r == KNullAlarmId, __LINE__); |
|
351 // |
|
352 alarm.Reset(); |
|
353 alarm.Message() = _L("Clock"); |
|
354 alarm.NextDueTime().HomeTime(); |
|
355 alarm.NextDueTime() += TTimeIntervalDays(1); |
|
356 alarm.NextDueTime() += TTimeIntervalMinutes(30); |
|
357 r = TheAlarmTest.Session().AlarmAdd(alarm); |
|
358 TheAlarmTest(r == KErrNone, __LINE__); |
|
359 TheAlarmTest(alarm.Id() != KNullAlarmId, __LINE__); |
|
360 testOtherNotify(ETrue); |
|
361 testThisNotify(EAlarmChangeEventAlarmAddition); |
|
362 // |
|
363 r = TheAlarmTest.Session().GetNextDueAlarmId(id); |
|
364 TheAlarmTest(r == KErrNone, __LINE__); |
|
365 TheAlarmTest(id == alarm.Id(), __LINE__); |
|
366 r = TheAlarmTest.Session().GetAlarmDetails(alarm.Id(), retrievedAlarm); |
|
367 TheAlarmTest(r == KErrNone, __LINE__); |
|
368 TheAlarmTest(retrievedAlarm.Id() = alarm.Id(), __LINE__); |
|
369 // |
|
370 r = TheAlarmTest.Session().SetAlarmStatus(alarm.Id(), EAlarmStatusDisabled); |
|
371 TheAlarmTest(r == KErrNone, __LINE__); |
|
372 testOtherNotify(ETrue); |
|
373 testThisNotify(EAlarmChangeEventStatus); |
|
374 // |
|
375 r = TheAlarmTest.Session().AlarmDelete(alarm.Id()); |
|
376 testOtherNotify(ETrue); |
|
377 testThisNotify(EAlarmChangeEventAlarmDeletion); |
|
378 } |
|
379 |
|
380 |
|
381 static void testSoundChange() |
|
382 // |
|
383 // Test that sound notifications work |
|
384 // |
|
385 { |
|
386 TheAlarmTest.Test().Next(_L("Sound changes")); |
|
387 testOtherNotify(EFalse); |
|
388 testThisNotify(KRequestPending); |
|
389 TheAlarmTest.Session().CancelAlarmSilence(); |
|
390 testThisNotify(KRequestPending); |
|
391 testOtherNotify(EFalse); |
|
392 TheAlarmTest.Session().SetAlarmSoundsSilentFor(60); |
|
393 testThisNotify(EAlarmChangeEventSoundSilence); |
|
394 testOtherNotify(ETrue); |
|
395 TheAlarmTest.Session().CancelAlarmSilence(); |
|
396 testThisNotify(EAlarmChangeEventSoundSilence); |
|
397 testOtherNotify(ETrue); |
|
398 TheAlarmTest.Session().SetAlarmSoundsSilentFor(60); |
|
399 testThisNotify(EAlarmChangeEventSoundSilence); |
|
400 testOtherNotify(ETrue); |
|
401 TheAlarmTest.Session().SetAlarmSoundsSilentFor(0); |
|
402 testThisNotify(EAlarmChangeEventSoundSilence); |
|
403 testOtherNotify(ETrue); |
|
404 TheAlarmTest.Session().SetAlarmSoundState(EAlarmGlobalSoundStateOn); |
|
405 testThisNotify(KRequestPending); |
|
406 testOtherNotify(EFalse); |
|
407 TheAlarmTest.Session().SetAlarmSoundState(EAlarmGlobalSoundStateOff); |
|
408 testThisNotify(EAlarmChangeEventGlobalSoundStateChanged); |
|
409 testOtherNotify(ETrue); |
|
410 TheAlarmTest.Session().SetAlarmSoundState(EAlarmGlobalSoundStateOn); |
|
411 testThisNotify(EAlarmChangeEventGlobalSoundStateChanged); |
|
412 testOtherNotify(ETrue); |
|
413 } |
|
414 |
|
415 |
|
416 static void testTimeChangeUtcL() |
|
417 { |
|
418 RPIMTestServer serv; |
|
419 User::LeaveIfError(serv.Connect()); |
|
420 |
|
421 TheAlarmTest.Test().Next(_L("Time changes and alarms set with UTC time.")); |
|
422 // |
|
423 testOtherNotify(EFalse); |
|
424 testThisNotify(KRequestPending); |
|
425 // |
|
426 testThisNotify(KRequestPending); |
|
427 testOtherNotify(EFalse); |
|
428 // |
|
429 TTime home; |
|
430 home.HomeTime(); |
|
431 home+=TTimeIntervalMinutes(2); |
|
432 |
|
433 serv.SetHomeTime(home); |
|
434 |
|
435 User::After(KTimeToWait); |
|
436 // |
|
437 testThisNotify(EAlarmChangeEventSystemDateTimeChanged); |
|
438 testOtherNotify(ETrue); |
|
439 testOtherNotify(EFalse); |
|
440 testThisNotify(KRequestPending); |
|
441 // |
|
442 TASShdAlarm alarm; |
|
443 alarm.Message()=(_L("Time")); |
|
444 TTime time; |
|
445 time.UniversalTime(); |
|
446 time += TTimeIntervalMinutes(30); |
|
447 alarm.SetUtcNextDueTime(time); |
|
448 TheAlarmTest.Session().AlarmAddWithNotification(TheSessionStatus, alarm); |
|
449 TheAlarmTest(TheSessionStatus == KRequestPending, __LINE__); |
|
450 // |
|
451 testOtherNotify(ETrue); |
|
452 testThisNotify(EAlarmChangeEventAlarmAddition); |
|
453 TheAlarmTest.WaitForNotificationBufferToBeEmptied(TheCurrentRequest, TheAlarmId); |
|
454 // |
|
455 TInt r; |
|
456 TAlarmId nextDueAlarmId; |
|
457 // |
|
458 r = TheAlarmTest.Session().GetNextDueAlarmId(nextDueAlarmId); |
|
459 TheAlarmTest(r == KErrNone, __LINE__); |
|
460 TheAlarmTest(nextDueAlarmId = alarm.Id(), __LINE__); |
|
461 // |
|
462 TASShdAlarm retrievedAlarm; |
|
463 r = TheAlarmTest.Session().GetAlarmDetails(nextDueAlarmId, retrievedAlarm); |
|
464 TheAlarmTest(r == KErrNone, __LINE__); |
|
465 TheAlarmTest(retrievedAlarm.Message() == _L("Time"), __LINE__); |
|
466 // |
|
467 User::SetUTCTime(retrievedAlarm.NextDueTime()); |
|
468 |
|
469 serv.Close(); |
|
470 |
|
471 User::After(KTimeToWait); |
|
472 // |
|
473 testOtherNotify(ETrue); |
|
474 testThisNotify(EAlarmChangeEventSystemDateTimeChanged); |
|
475 TheAlarmTest(TheSessionStatus != KRequestPending, __LINE__); |
|
476 User::WaitForRequest(TheSessionStatus); |
|
477 // |
|
478 r = TheAlarmTest.Session().GetNextDueAlarmId(nextDueAlarmId); |
|
479 TheAlarmTest(r == KErrNone, __LINE__); |
|
480 TheAlarmTest(nextDueAlarmId == KNullAlarmId, __LINE__); |
|
481 // |
|
482 TheAlarmTest.Session().AlarmNotificationCancelAndDequeue(alarm.Id()); |
|
483 testThisNotify(EAlarmChangeEventAlarmDeletion); |
|
484 testOtherNotify(ETrue); |
|
485 // |
|
486 time = alarm.NextDueTime(); |
|
487 time += TTimeIntervalDays(1); |
|
488 alarm.SetUtcNextDueTime(time); |
|
489 alarm.Message()=(_L("DayTime")); |
|
490 TheAlarmTest.Session().AlarmAddWithNotification(TheSessionStatus, alarm); |
|
491 testThisNotify(EAlarmChangeEventAlarmAddition); |
|
492 // |
|
493 TheAlarmTest.Session().AlarmNotificationCancelAndDequeue(alarm.Id()); |
|
494 testThisNotify(EAlarmChangeEventAlarmDeletion); |
|
495 // |
|
496 TheAlarmTest.Session().AlarmAddWithNotification(TheSessionStatus, alarm); |
|
497 testThisNotify(EAlarmChangeEventAlarmAddition); |
|
498 testOtherNotify(ETrue); |
|
499 // |
|
500 TheAlarmTest.Session().AlarmNotificationCancelAndDequeue(alarm.Id()); |
|
501 testThisNotify(EAlarmChangeEventAlarmDeletion); |
|
502 // |
|
503 TheAlarmTest(TheSessionStatus==KErrCancel, __LINE__); |
|
504 testOtherNotify(ETrue); |
|
505 } |
|
506 |
|
507 |
|
508 static void testSetAndCancelFutureUtc() |
|
509 { |
|
510 TheAlarmTest.Test().Next(_L("Set alarms with UTC time in future")); |
|
511 TheAlarmTest(TheNotifyFlag==EFalse, __LINE__); |
|
512 // |
|
513 TASShdAlarm alarm; |
|
514 alarm.Message()=(_L("Future")); |
|
515 TTime time; |
|
516 time.UniversalTime(); |
|
517 time += TTimeIntervalDays(1); |
|
518 time += TTimeIntervalMinutes(30); |
|
519 alarm.SetUtcNextDueTime(time); |
|
520 // |
|
521 testOtherNotify(EFalse); |
|
522 testThisNotify(KRequestPending); |
|
523 // |
|
524 TheAlarmTest.Session().AlarmAddWithNotification(TheSessionStatus, alarm); |
|
525 TheAlarmTest(alarm.Id() != KNullAlarmId, __LINE__); |
|
526 TheAlarmTest(TheSessionStatus == KRequestPending, __LINE__); |
|
527 testOtherNotify(ETrue); |
|
528 testThisNotify(EAlarmChangeEventAlarmAddition); |
|
529 // |
|
530 TAlarmId id; |
|
531 TASShdAlarm retrievedAlarm; |
|
532 TInt r; |
|
533 // |
|
534 r = TheAlarmTest.Session().GetNextDueAlarmId(id); |
|
535 TheAlarmTest(r == KErrNone, __LINE__); |
|
536 TheAlarmTest(id == alarm.Id(), __LINE__); |
|
537 r = TheAlarmTest.Session().GetAlarmDetails(alarm.Id(), retrievedAlarm); |
|
538 TheAlarmTest(r == KErrNone, __LINE__); |
|
539 TheAlarmTest(retrievedAlarm.Id() == alarm.Id(), __LINE__); |
|
540 // |
|
541 TheAlarmTest.Session().AlarmNotificationCancelAndDequeue(alarm.Id()); |
|
542 testOtherNotify(ETrue); |
|
543 TheAlarmTest(TheSessionStatus==KErrCancel, __LINE__); |
|
544 testThisNotify(EAlarmChangeEventAlarmDeletion); |
|
545 // |
|
546 r = TheAlarmTest.Session().GetNextDueAlarmId(id); |
|
547 TheAlarmTest(r == KErrNone, __LINE__); |
|
548 TheAlarmTest(r == KNullAlarmId, __LINE__); |
|
549 // |
|
550 alarm.Reset(); |
|
551 alarm.Message()=(_L("Clock")); |
|
552 time.UniversalTime(); |
|
553 time += TTimeIntervalDays(1); |
|
554 time += TTimeIntervalMinutes(30); |
|
555 alarm.SetUtcNextDueTime(time); |
|
556 r = TheAlarmTest.Session().AlarmAdd(alarm); |
|
557 TheAlarmTest(r == KErrNone, __LINE__); |
|
558 TheAlarmTest(alarm.Id() != KNullAlarmId, __LINE__); |
|
559 testOtherNotify(ETrue); |
|
560 testThisNotify(EAlarmChangeEventAlarmAddition); |
|
561 // |
|
562 r = TheAlarmTest.Session().GetNextDueAlarmId(id); |
|
563 TheAlarmTest(r == KErrNone, __LINE__); |
|
564 TheAlarmTest(id == alarm.Id(), __LINE__); |
|
565 r = TheAlarmTest.Session().GetAlarmDetails(alarm.Id(), retrievedAlarm); |
|
566 TheAlarmTest(r == KErrNone, __LINE__); |
|
567 TheAlarmTest(retrievedAlarm.Id() == alarm.Id(), __LINE__); |
|
568 // |
|
569 r = TheAlarmTest.Session().SetAlarmStatus(alarm.Id(), EAlarmStatusDisabled); |
|
570 TheAlarmTest(r == KErrNone, __LINE__); |
|
571 testOtherNotify(ETrue); |
|
572 testThisNotify(EAlarmChangeEventStatus); |
|
573 // |
|
574 r = TheAlarmTest.Session().AlarmDelete(alarm.Id()); |
|
575 testOtherNotify(ETrue); |
|
576 testThisNotify(EAlarmChangeEventAlarmDeletion); |
|
577 } |
|
578 |
|
579 static void testSetAndCancelPastUtc() |
|
580 { |
|
581 TheAlarmTest.Test().Next(_L("Set alarms with UTC time in past")); |
|
582 testOtherNotify(EFalse); |
|
583 // |
|
584 TASShdAlarm alarm; |
|
585 alarm.Message()=(_L("Past")); |
|
586 alarm.SoundName()=(_L("none")); |
|
587 TTime time; |
|
588 time.UniversalTime(); |
|
589 time += TTimeIntervalDays(-2); |
|
590 alarm.SetUtcNextDueTime(time); |
|
591 // |
|
592 testThisNotify(KRequestPending); |
|
593 testOtherNotify(EFalse); |
|
594 // |
|
595 TInt r; |
|
596 // |
|
597 r = TheAlarmTest.Session().AlarmAdd(alarm); |
|
598 TheAlarmTest(r == KErrNone, __LINE__); |
|
599 TheAlarmTest(alarm.Id() != KNullAlarmId, __LINE__); |
|
600 TAlarmId clockAlarmId = alarm.Id(); |
|
601 // |
|
602 testThisNotify(EAlarmChangeEventAlarmAddition); |
|
603 testOtherNotify(ETrue); |
|
604 TheAlarmTest.WaitForNotificationBufferToBeEmptied(TheCurrentRequest, TheAlarmId); |
|
605 // |
|
606 testThisNotify(KRequestPending); |
|
607 testOtherNotify(EFalse); |
|
608 testThisNotify(KRequestPending); |
|
609 // |
|
610 TheAlarmTest.Session().AlarmAddWithNotification(TheSessionStatus, alarm); |
|
611 TheAlarmTest(alarm.Id() != KNullAlarmId, __LINE__); |
|
612 testOtherNotify(ETrue); |
|
613 testThisNotify(EAlarmChangeEventAlarmAddition); |
|
614 TheAlarmTest(TheSessionStatus == KErrNone, __LINE__); |
|
615 User::WaitForRequest(TheSessionStatus); |
|
616 // |
|
617 TheAlarmTest.Session().AlarmNotificationCancelAndDequeue(alarm.Id()); |
|
618 testThisNotify(EAlarmChangeEventAlarmDeletion); |
|
619 testOtherNotify(ETrue); |
|
620 // |
|
621 r = TheAlarmTest.Session().AlarmDelete(clockAlarmId); |
|
622 TheAlarmTest(r == 0, __LINE__); |
|
623 testThisNotify(EAlarmChangeEventAlarmDeletion); |
|
624 testOtherNotify(ETrue); |
|
625 } |
|
626 |
|
627 |
|
628 static void doTestsL() |
|
629 { |
|
630 const TInt KGmtOffset = 3600; |
|
631 _LIT(KTime, "20040730:050000.000000"); //Summertime |
|
632 TInt err = User::SetUTCTimeAndOffset(TTime(KTime), KGmtOffset); |
|
633 TheAlarmTest(err == KErrNone, __LINE__); |
|
634 |
|
635 TheAlarmTest.TestStartServers(); |
|
636 __UHEAP_FAILNEXT(1); |
|
637 TheAlarmTest(TheAlarmTest.Session().Connect() == KErrNone, __LINE__); |
|
638 __UHEAP_RESET; |
|
639 |
|
640 CActiveScheduler* scheduler = new (ELeave) CActiveScheduler; |
|
641 CleanupStack::PushL(scheduler); |
|
642 CActiveScheduler::Install(scheduler); |
|
643 |
|
644 // |
|
645 TheAlarmTest.TestClearStoreL(); |
|
646 testSetupNotify(); |
|
647 testSoundChange(); |
|
648 |
|
649 // Alarms set with local wall-clock times. |
|
650 testTimeChangeL(); |
|
651 testSetAndCancelFuture(); |
|
652 testSetAndCancelPast(); |
|
653 |
|
654 // Alarms set with UTC times. |
|
655 testTimeChangeUtcL(); |
|
656 testSetAndCancelFutureUtc(); |
|
657 testSetAndCancelPastUtc(); |
|
658 |
|
659 CleanupStack::PopAndDestroy(scheduler); |
|
660 |
|
661 TheAlarmTest.TestClearStoreL(); |
|
662 } |
|
663 |
|
664 /** |
|
665 @SYMTestCaseID PIM-TALARMNOTIFICATIONS-0001 |
|
666 */ |
|
667 GLDEF_C TInt E32Main() |
|
668 // |
|
669 // Test the alarm server. |
|
670 // |
|
671 { |
|
672 TInt ret = KErrNone; |
|
673 TheAlarmTest.Title(); |
|
674 TheAlarmTest.Start(_L("@SYMTestCaseID PIM-TALARMNOTIFICATIONS-0001 Session alarms")); |
|
675 |
|
676 __UHEAP_MARK; |
|
677 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
678 TRAPD(err, doTestsL()); |
|
679 TheAlarmTest(err == KErrNone, __LINE__); |
|
680 delete cleanup; |
|
681 __UHEAP_MARKEND; |
|
682 |
|
683 TheAlarmTest.Session().Close(); |
|
684 TRAP(ret,TheAlarmTest.EndL()); |
|
685 TheAlarmTest.Test().Close(); |
|
686 ASTstAlarmTest::Close(); |
|
687 // |
|
688 return ret; |
|
689 } |