commonappservices/alarmserver/Test/TQueueRestoration.cpp
changeset 0 2e3d3ce01487
equal deleted inserted replaced
-1:000000000000 0:2e3d3ce01487
       
     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 //
       
    15 
       
    16 #include "ASTstAlarmTest.h"
       
    17 #include "testserver.h"
       
    18 
       
    19 // Globals
       
    20 static TRequestStatus TheStatus;
       
    21 static TTime TheTimeBefore;
       
    22 static TTime TheTimeAfter;
       
    23 static TAlarmId TheClockAlarmIds[10];
       
    24 
       
    25 
       
    26 void TestInitAlarmsL()
       
    27 //
       
    28 //	Set up alarms for before test
       
    29 //	1.	clock 0 between shutdown time and restart time
       
    30 //	2.	clock 1 daily alarm
       
    31 //	3.	clock 2 workday alarm
       
    32 //	4.	clock 3 after restart time
       
    33 //	5.	orphaned alarm
       
    34 //	6.	session alarm
       
    35 //	7.	clock 4 in 24 hours
       
    36 //	8.	clock 5 in past (for review alarm)
       
    37 //
       
    38 	{
       
    39 	TheAlarmTest.Test().Next(_L("Setting up alarms before shut down"));
       
    40 	//
       
    41 	TInt r;
       
    42 	TInt count;
       
    43 	TASShdAlarm alarm;
       
    44 	TheTimeBefore.HomeTime();
       
    45 	//
       
    46 	count = TheAlarmTest.Session().NumberOfAlarmsActiveInQueue();
       
    47 	TheAlarmTest(count == 0, __LINE__);
       
    48 
       
    49 	//	8. Clock 0 in past (for review alarm)
       
    50 	TheTimeBefore -= TTimeIntervalHours(1);
       
    51 	alarm.NextDueTime() = TheTimeBefore;
       
    52 	alarm.Message() = _L("past");
       
    53 	alarm.RepeatDefinition() = EAlarmRepeatDefintionRepeatOnce;
       
    54 	r = TheAlarmTest.Session().AlarmAdd(alarm);
       
    55 	TheAlarmTest(r == KErrNone, __LINE__);
       
    56 	TheClockAlarmIds[0] = alarm.Id();
       
    57 	//
       
    58 	User::After(KTimeToWait);
       
    59 	r = TheAlarmTest.Session().GetAlarmDetails(alarm.Id(), alarm);
       
    60 	TheAlarmTest(alarm.State() == EAlarmStateNotified, __LINE__);
       
    61 	//
       
    62 	count = TheAlarmTest.Session().NumberOfAlarmsActiveInQueue();
       
    63 	TheAlarmTest(count == 0, __LINE__);
       
    64 
       
    65 	//	1. Clock 1 between shutdown time and restart time
       
    66 	TheTimeBefore += TTimeIntervalDays(1);
       
    67 	alarm.NextDueTime() = TheTimeBefore;
       
    68 	alarm.Message() = _L("once");
       
    69 	alarm.RepeatDefinition() = EAlarmRepeatDefintionRepeatOnce;
       
    70 	r = TheAlarmTest.Session().AlarmAdd(alarm);
       
    71 	TheAlarmTest(r == KErrNone, __LINE__);
       
    72 	TheClockAlarmIds[1] = alarm.Id();
       
    73 	//
       
    74 	r = TheAlarmTest.Session().GetAlarmDetails(alarm.Id(), alarm);
       
    75 	TheAlarmTest(alarm.State() == EAlarmStateQueued, __LINE__);
       
    76 
       
    77 	//	2. Clock 2 daily alarm
       
    78 	alarm.NextDueTime() = TheTimeBefore;
       
    79 	alarm.Message() = _L("daily");
       
    80 	alarm.RepeatDefinition() = EAlarmRepeatDefintionRepeatDaily;
       
    81 	r = TheAlarmTest.Session().AlarmAdd(alarm);
       
    82 	TheAlarmTest(r == KErrNone, __LINE__);
       
    83 	TheClockAlarmIds[2] = alarm.Id();
       
    84 	//
       
    85 	count = TheAlarmTest.Session().NumberOfAlarmsActiveInQueue();
       
    86 	TheAlarmTest(count == 2, __LINE__);
       
    87 
       
    88 	//	3. Clock 3 workday alarm
       
    89 	alarm.NextDueTime() = TheTimeBefore;
       
    90 	alarm.Message() = _L("workday");
       
    91 	alarm.RepeatDefinition() = EAlarmRepeatDefintionRepeatWorkday;
       
    92 	r = TheAlarmTest.Session().AlarmAdd(alarm);
       
    93 	TheAlarmTest(r == KErrNone, __LINE__);
       
    94 	TheClockAlarmIds[3] = alarm.Id();
       
    95 
       
    96 	//	4. Clock 4 after restart time
       
    97 	TheTimeAfter = TheTimeBefore + TTimeIntervalDays(2);
       
    98 	alarm.NextDueTime() = TheTimeAfter;
       
    99 	alarm.Message() = _L("after");
       
   100 	alarm.RepeatDefinition() = EAlarmRepeatDefintionRepeatWorkday;
       
   101 	r = TheAlarmTest.Session().AlarmAdd(alarm);
       
   102 	TheAlarmTest(r == KErrNone, __LINE__);
       
   103 	TheClockAlarmIds[4] = alarm.Id();
       
   104 	//
       
   105 	count = TheAlarmTest.Session().NumberOfAlarmsActiveInQueue();
       
   106 	TheAlarmTest(count == 4, __LINE__);
       
   107 
       
   108 	//	5. Orphaned alarm
       
   109 	alarm.NextDueTime() = TheTimeAfter;
       
   110 	alarm.Message() = _L("orphaned");
       
   111 	alarm.RepeatDefinition() = EAlarmRepeatDefintionRepeatOnce;
       
   112 	TheAlarmTest.Session().AlarmAddWithNotification(TheStatus, alarm);
       
   113 	TheAlarmTest(alarm.Id() != KNullAlarmId, __LINE__);
       
   114 	TheAlarmTest(TheStatus == KRequestPending, __LINE__);
       
   115 	r = TheAlarmTest.Session().SetAlarmCharacteristics(alarm.Id(), 0);
       
   116 	TheAlarmTest(r == KErrNone, __LINE__);
       
   117 	User::WaitForRequest(TheStatus);
       
   118 	TheClockAlarmIds[5] = alarm.Id();
       
   119 	//
       
   120 	count = TheAlarmTest.Session().NumberOfAlarmsActiveInQueue();
       
   121 	TheAlarmTest(count == 5, __LINE__);
       
   122 
       
   123 	//	7. Clock 5 in 24 hours
       
   124 	alarm.Characteristics() = 0;
       
   125 	alarm.NextDueTime() = TheTimeAfter;
       
   126 	alarm.Message() = _L("next24");
       
   127 	alarm.RepeatDefinition() = EAlarmRepeatDefintionRepeatNext24Hours;
       
   128 	r = TheAlarmTest.Session().AlarmAdd(alarm);
       
   129 	TheAlarmTest(r == KErrNone, __LINE__);
       
   130 	TheClockAlarmIds[6] = alarm.Id();
       
   131 	//
       
   132 	count = TheAlarmTest.Session().NumberOfAlarmsActiveInQueue();
       
   133 	TheAlarmTest(count == 6, __LINE__);
       
   134 
       
   135 	//	6. Session alarm
       
   136 	alarm.NextDueTime() = TheTimeAfter;
       
   137 	alarm.Message() =_L("different");
       
   138 	alarm.RepeatDefinition() = EAlarmRepeatDefintionRepeatOnce;
       
   139 	TheAlarmTest.Session().AlarmAddWithNotification(TheStatus, alarm);
       
   140 	TheAlarmTest(alarm.Id() != KNullAlarmId, __LINE__);
       
   141 	TheAlarmTest(TheStatus == KRequestPending, __LINE__);
       
   142 	TheClockAlarmIds[7] = alarm.Id();
       
   143 
       
   144 	// Verification
       
   145 	count = TheAlarmTest.Session().NumberOfAlarmsActiveInQueue();
       
   146 	TheAlarmTest(count == 7, __LINE__);
       
   147 	//
       
   148 	count = TheAlarmTest.CountOrphanedAlarmsL();
       
   149 	TheAlarmTest(count == 1, __LINE__);
       
   150 	}
       
   151 
       
   152 	
       
   153 void TestPostShutDownL()
       
   154 //
       
   155 //	Check persisted correct information
       
   156 //	1.	Clock 0 alarm deleted - its added to the queue when the backup store
       
   157 //		is internalized, but as soon as the server starts the scheduler, the
       
   158 //		change notifier runs and the date/time change is reported. At this point
       
   159 //		the alarm is more than 2 days in the past, and as such, any "Once only"
       
   160 //		alarm (regardless of State()) which is set in the past is deleted from
       
   161 //		the queue.
       
   162 //	2.	Clock 1 set between shutdown and restart time. Again this is deleted
       
   163 //		because when the change notifier runs, its more than a day old and
       
   164 //		so its automatically dequeued.
       
   165 //	3.	Clock 2 (daily repeat). This is just reset for the next valid repeat.
       
   166 //	4.	Clock 3 (workday repeat). This is just reset for the next valid repeat.
       
   167 //	5.	Clock 4 (workday repeat). This still uses the original "after the restart"
       
   168 //		expiry time.
       
   169 //	6.	Alarm 5 (orphaned alarm). This is still orphaned and is still valid.
       
   170 //		Effectively, this is a change in behaviour from the old EALWL, where
       
   171 //		old orphaned alarms were deleted when internalized.
       
   172 //	7.	Clock 5 (was next 24 hours repeat, is now RepeatOnce and orphaned).
       
   173 //	8.	Session alarm (which was pending when the server shut down). This is
       
   174 //		cleaned up and dequeued as part of the server shut-down process. When
       
   175 //		the session disconnects, any session alarms for that session are
       
   176 //		dequeued (by matching against the session id).
       
   177 //
       
   178 	{
       
   179 	TheAlarmTest.Test().Next(_L("Comparing persisted alarms"));
       
   180 	//
       
   181 	TInt c;
       
   182 	c = TheAlarmTest.CountOrphanedAlarmsL();
       
   183 	TheAlarmTest(c == 1, __LINE__);
       
   184 	//
       
   185 	c = TheAlarmTest.Session().NumberOfAlarmsActiveInQueue();
       
   186 	TheAlarmTest(c == 4, __LINE__);
       
   187 	//
       
   188 	TInt r;
       
   189 	TASShdAlarm alarm;
       
   190 	//
       
   191 	r = TheAlarmTest.Session().GetAlarmDetails(TheClockAlarmIds[0], alarm);
       
   192 	TheAlarmTest(r == KErrNone, __LINE__);
       
   193 	//
       
   194 	r = TheAlarmTest.Session().GetAlarmDetails(TheClockAlarmIds[1], alarm);
       
   195 	TheAlarmTest(r == KErrNotFound, __LINE__);
       
   196 	//
       
   197 	r = TheAlarmTest.Session().GetAlarmDetails(TheClockAlarmIds[2], alarm);
       
   198 	TheAlarmTest(r == KErrNone, __LINE__);
       
   199 	TheAlarmTest(alarm.Status() == EAlarmStatusEnabled, __LINE__);
       
   200 	TheAlarmTest(alarm.Message() == _L("daily"), __LINE__);
       
   201 	TheAlarmTest(alarm.RepeatDefinition() == EAlarmRepeatDefintionRepeatDaily, __LINE__);
       
   202 	//
       
   203 	r = TheAlarmTest.Session().GetAlarmDetails(TheClockAlarmIds[3], alarm);
       
   204 	TheAlarmTest(r == KErrNone, __LINE__);
       
   205 	TheAlarmTest(alarm.Status() == EAlarmStatusEnabled, __LINE__);
       
   206 	TheAlarmTest(alarm.Message() == _L("workday"), __LINE__);
       
   207 	TheAlarmTest(alarm.RepeatDefinition() == EAlarmRepeatDefintionRepeatWorkday, __LINE__);
       
   208 	//
       
   209 	r = TheAlarmTest.Session().GetAlarmDetails(TheClockAlarmIds[4], alarm);
       
   210 	TheAlarmTest(r == KErrNone, __LINE__);
       
   211 	TheAlarmTest(alarm.Status() == EAlarmStatusEnabled, __LINE__);
       
   212 	TheAlarmTest(alarm.Message() == _L("after"), __LINE__);
       
   213 	TheAlarmTest(alarm.RepeatDefinition() == EAlarmRepeatDefintionRepeatWorkday, __LINE__);
       
   214 	//
       
   215 	r = TheAlarmTest.Session().GetAlarmDetails(TheClockAlarmIds[5], alarm);
       
   216 	TheAlarmTest(r == KErrNone, __LINE__);
       
   217 	TheAlarmTest(alarm.Status() == EAlarmStatusEnabled, __LINE__);
       
   218 	TheAlarmTest(alarm.Message() == _L("orphaned"), __LINE__);
       
   219 	TheAlarmTest(alarm.HasBecomeOrphaned(), __LINE__);
       
   220 	TheAlarmTest(alarm.RepeatDefinition() == EAlarmRepeatDefintionRepeatOnce, __LINE__);
       
   221 	//
       
   222 	r = TheAlarmTest.Session().GetAlarmDetails(TheClockAlarmIds[6], alarm);
       
   223 	TheAlarmTest(r == KErrNotFound, __LINE__);
       
   224 	TheAlarmTest(alarm.Status() == EAlarmStatusEnabled, __LINE__);
       
   225 	TheAlarmTest(alarm.Message() == _L("orphaned"), __LINE__);
       
   226 	TheAlarmTest(alarm.RepeatDefinition() == EAlarmRepeatDefintionRepeatOnce, __LINE__);
       
   227 	}
       
   228 
       
   229 	
       
   230 void TestInitUtcAlarmsL()
       
   231 //
       
   232 //	Set up alarms for before test
       
   233 //	1.	clock 0 between shutdown time and restart time
       
   234 //	2.	clock 1 daily alarm
       
   235 //	3.	clock 2 workday alarm
       
   236 //	4.	clock 3 after restart time
       
   237 //	5.	orphaned alarm
       
   238 //	6.	session alarm
       
   239 //	7.	clock 4 in 24 hours
       
   240 //	8.	clock 5 in past (for review alarm)
       
   241 //
       
   242 	{
       
   243 	TheAlarmTest.Test().Next(_L("Setting up UTC alarms before shut down"));
       
   244 	//
       
   245 	TInt r;
       
   246 	TInt count;
       
   247 	TASShdAlarm alarm;
       
   248 	TheTimeBefore.UniversalTime();
       
   249 	//
       
   250 	count = TheAlarmTest.Session().NumberOfAlarmsActiveInQueue();
       
   251 	TheAlarmTest(count == 0, __LINE__);
       
   252 
       
   253 	//	8. Clock 0 in past (for review alarm)
       
   254 	TheTimeBefore -= TTimeIntervalHours(1);
       
   255 	alarm.SetUtcNextDueTime(TheTimeBefore);
       
   256 	alarm.Message()=(_L("past"));
       
   257 	alarm.RepeatDefinition()=EAlarmRepeatDefintionRepeatOnce;
       
   258 	r = TheAlarmTest.Session().AlarmAdd(alarm);
       
   259 	TheAlarmTest(r == KErrNone, __LINE__);
       
   260 	TheClockAlarmIds[0] = alarm.Id();
       
   261 	//
       
   262 	User::After(KTimeToWait);
       
   263 	r = TheAlarmTest.Session().GetAlarmDetails(alarm.Id(), alarm);
       
   264 	TheAlarmTest(alarm.State() == EAlarmStateNotified, __LINE__);
       
   265 	//
       
   266 	count = TheAlarmTest.Session().NumberOfAlarmsActiveInQueue();
       
   267 	TheAlarmTest(count == 0, __LINE__);
       
   268 
       
   269 	//	1. Clock 1 between shutdown time and restart time
       
   270 	TheTimeBefore += TTimeIntervalDays(1);
       
   271 	alarm.SetUtcNextDueTime(TheTimeBefore);
       
   272 	alarm.Message()=(_L("once"));
       
   273 	alarm.RepeatDefinition()=(EAlarmRepeatDefintionRepeatOnce);
       
   274 	r = TheAlarmTest.Session().AlarmAdd(alarm);
       
   275 	TheAlarmTest(r == KErrNone, __LINE__);
       
   276 	TheClockAlarmIds[1] = alarm.Id();
       
   277 	//
       
   278 	r = TheAlarmTest.Session().GetAlarmDetails(alarm.Id(), alarm);
       
   279 	TheAlarmTest(alarm.State() == EAlarmStateQueued, __LINE__);
       
   280 
       
   281 	//	2. Clock 2 daily alarm
       
   282 	alarm.SetUtcNextDueTime(TheTimeBefore);
       
   283 	alarm.Message()=(_L("daily"));
       
   284 	alarm.RepeatDefinition()=EAlarmRepeatDefintionRepeatDaily;
       
   285 	r = TheAlarmTest.Session().AlarmAdd(alarm);
       
   286 	TheAlarmTest(r == KErrNone, __LINE__);
       
   287 	TheClockAlarmIds[2] = alarm.Id();
       
   288 	//
       
   289 	count = TheAlarmTest.Session().NumberOfAlarmsActiveInQueue();
       
   290 	TheAlarmTest(count == 2, __LINE__);
       
   291 
       
   292 	//	3. Clock 3 workday alarm
       
   293 	alarm.SetUtcNextDueTime(TheTimeBefore);
       
   294 	alarm.Message()=(_L("workday"));
       
   295 	alarm.RepeatDefinition()=EAlarmRepeatDefintionRepeatWorkday;
       
   296 	r = TheAlarmTest.Session().AlarmAdd(alarm);
       
   297 	TheAlarmTest(r == KErrNone, __LINE__);
       
   298 	TheClockAlarmIds[3] = alarm.Id();
       
   299 
       
   300 	//	4. Clock 4 after restart time
       
   301 	TheTimeAfter = TheTimeBefore + TTimeIntervalDays(2);
       
   302 	alarm.SetUtcNextDueTime(TheTimeAfter);
       
   303 	alarm.Message()=(_L("after"));
       
   304 	alarm.RepeatDefinition()=EAlarmRepeatDefintionRepeatWorkday;
       
   305 	r = TheAlarmTest.Session().AlarmAdd(alarm);
       
   306 	TheAlarmTest(r == KErrNone, __LINE__);
       
   307 	TheClockAlarmIds[4] = alarm.Id();
       
   308 	//
       
   309 	count = TheAlarmTest.Session().NumberOfAlarmsActiveInQueue();
       
   310 	TheAlarmTest(count == 4, __LINE__);
       
   311 
       
   312 	//	5. Orphaned alarm
       
   313 	alarm.SetUtcNextDueTime(TheTimeAfter);
       
   314 	alarm.Message()=(_L("orphaned"));
       
   315 	alarm.RepeatDefinition()=EAlarmRepeatDefintionRepeatOnce;
       
   316 	TheAlarmTest.Session().AlarmAddWithNotification(TheStatus, alarm);
       
   317 	TheAlarmTest(alarm.Id() != KNullAlarmId, __LINE__);
       
   318 	TheAlarmTest(TheStatus == KRequestPending, __LINE__);
       
   319 	r = TheAlarmTest.Session().SetAlarmCharacteristics(alarm.Id(), 0);
       
   320 	TheAlarmTest(r == KErrNone, __LINE__);
       
   321 	User::WaitForRequest(TheStatus);
       
   322 	TheClockAlarmIds[5] = alarm.Id();
       
   323 	//
       
   324 	count = TheAlarmTest.Session().NumberOfAlarmsActiveInQueue();
       
   325 	TheAlarmTest(count == 5, __LINE__);
       
   326 
       
   327 	//	7. Clock 5 in 24 hours
       
   328 	alarm.Reset();
       
   329 	alarm.Characteristics().ClearAll();
       
   330 	alarm.SetUtcNextDueTime(TheTimeAfter);
       
   331 	alarm.Message()=(_L("next24"));
       
   332 	alarm.RepeatDefinition()=EAlarmRepeatDefintionRepeatNext24Hours;
       
   333 	r = TheAlarmTest.Session().AlarmAdd(alarm);
       
   334 	TheAlarmTest(r == KErrNone, __LINE__);
       
   335 	TheClockAlarmIds[6] = alarm.Id();
       
   336 	//
       
   337 	count = TheAlarmTest.Session().NumberOfAlarmsActiveInQueue();
       
   338 	TheAlarmTest(count == 6, __LINE__);
       
   339 
       
   340 	//	6. Session alarm
       
   341 	alarm.SetUtcNextDueTime(TheTimeAfter);
       
   342 	alarm.Message()=(_L("different"));
       
   343 	alarm.RepeatDefinition()=EAlarmRepeatDefintionRepeatOnce;
       
   344 	TheAlarmTest.Session().AlarmAddWithNotification(TheStatus, alarm);
       
   345 	TheAlarmTest(alarm.Id() != KNullAlarmId, __LINE__);
       
   346 	TheAlarmTest(TheStatus == KRequestPending, __LINE__);
       
   347 	TheClockAlarmIds[7] = alarm.Id();
       
   348 
       
   349 	// Verification
       
   350 	count = TheAlarmTest.Session().NumberOfAlarmsActiveInQueue();
       
   351 	TheAlarmTest(count == 7, __LINE__);
       
   352 	//
       
   353 	count = TheAlarmTest.CountOrphanedAlarmsL();
       
   354 	TheAlarmTest(count == 1, __LINE__);
       
   355 	}
       
   356 
       
   357 
       
   358 void TestPostShutDownUtcL()
       
   359 //
       
   360 //	Check persisted correct information
       
   361 //	1.	Clock 0 alarm deleted - its added to the queue when the backup store
       
   362 //		is internalized, but as soon as the server starts the scheduler, the
       
   363 //		change notifier runs and the date/time change is reported. At this point
       
   364 //		the alarm is more than 2 days in the past, and as such, any "Once only"
       
   365 //		alarm (regardless of State()) which is set in the past is deleted from
       
   366 //		the queue.
       
   367 //	2.	Clock 1 set between shutdown and restart time. Again this is deleted
       
   368 //		because when the change notifier runs, its more than a day old and
       
   369 //		so its automatically dequeued.
       
   370 //	3.	Clock 2 (daily repeat). This is just reset for the next valid repeat.
       
   371 //	4.	Clock 3 (workday repeat). This is just reset for the next valid repeat.
       
   372 //	5.	Clock 4 (workday repeat). This still uses the original "after the restart"
       
   373 //		expiry time.
       
   374 //	6.	Alarm 5 (orphaned alarm). This is still orphaned and is still valid.
       
   375 //		Effectively, this is a change in behaviour from the old EALWL, where
       
   376 //		old orphaned alarms were deleted when internalized.
       
   377 //	7.	Clock 5 (was next 24 hours repeat, is now RepeatOnce and orphaned).
       
   378 //	8.	Session alarm (which was pending when the server shut down). This is
       
   379 //		cleaned up and dequeued as part of the server shut-down process. When
       
   380 //		the session disconnects, any session alarms for that session are
       
   381 //		dequeued (by matching against the session id).
       
   382 //
       
   383 	{
       
   384 	TheAlarmTest.Test().Next(_L("Comparing persisted UTC alarms"));
       
   385 	//
       
   386 	TInt c;
       
   387 	c = TheAlarmTest.CountOrphanedAlarmsL();
       
   388 	TheAlarmTest(c == 1, __LINE__);
       
   389 	//
       
   390 	c = TheAlarmTest.Session().NumberOfAlarmsActiveInQueue();
       
   391 	TheAlarmTest(c == 4, __LINE__);
       
   392 	//
       
   393 	TInt r;
       
   394 	TASShdAlarm alarm;
       
   395 	//
       
   396 	r = TheAlarmTest.Session().GetAlarmDetails(TheClockAlarmIds[0], alarm);
       
   397 	TheAlarmTest(r == KErrNone, __LINE__);
       
   398 	//
       
   399 	r = TheAlarmTest.Session().GetAlarmDetails(TheClockAlarmIds[1], alarm);
       
   400 	TheAlarmTest(r == KErrNotFound, __LINE__);
       
   401 	//
       
   402 	r = TheAlarmTest.Session().GetAlarmDetails(TheClockAlarmIds[2], alarm);
       
   403 	TheAlarmTest(r == KErrNone, __LINE__);
       
   404 	TheAlarmTest(alarm.Status() == EAlarmStatusEnabled, __LINE__);
       
   405 	TheAlarmTest(alarm.Message() == _L("daily"), __LINE__);
       
   406 	TheAlarmTest(alarm.RepeatDefinition() == EAlarmRepeatDefintionRepeatDaily, __LINE__);
       
   407 	//
       
   408 	r = TheAlarmTest.Session().GetAlarmDetails(TheClockAlarmIds[3], alarm);
       
   409 	TheAlarmTest(r == KErrNone, __LINE__);
       
   410 	TheAlarmTest(alarm.Status() == EAlarmStatusEnabled, __LINE__);
       
   411 	TheAlarmTest(alarm.Message() == _L("workday"), __LINE__);
       
   412 	TheAlarmTest(alarm.RepeatDefinition() == EAlarmRepeatDefintionRepeatWorkday, __LINE__);
       
   413 	//
       
   414 	r = TheAlarmTest.Session().GetAlarmDetails(TheClockAlarmIds[4], alarm);
       
   415 	TheAlarmTest(r == KErrNone, __LINE__);
       
   416 	TheAlarmTest(alarm.Status() == EAlarmStatusEnabled, __LINE__);
       
   417 	TheAlarmTest(alarm.Message() == _L("after"), __LINE__);
       
   418 	TheAlarmTest(alarm.RepeatDefinition() == EAlarmRepeatDefintionRepeatWorkday, __LINE__);
       
   419 	//
       
   420 	r = TheAlarmTest.Session().GetAlarmDetails(TheClockAlarmIds[5], alarm);
       
   421 	TheAlarmTest(r == KErrNone, __LINE__);
       
   422 	TheAlarmTest(alarm.Status() == EAlarmStatusEnabled, __LINE__);
       
   423 	TheAlarmTest(alarm.Message() == _L("orphaned"), __LINE__);
       
   424 	TheAlarmTest(alarm.HasBecomeOrphaned(), __LINE__);
       
   425 	TheAlarmTest(alarm.RepeatDefinition() == EAlarmRepeatDefintionRepeatOnce, __LINE__);
       
   426 	//
       
   427 	r = TheAlarmTest.Session().GetAlarmDetails(TheClockAlarmIds[6], alarm);
       
   428 	TheAlarmTest(r == KErrNotFound, __LINE__);
       
   429 	TheAlarmTest(alarm.Status() == EAlarmStatusEnabled, __LINE__);
       
   430 	TheAlarmTest(alarm.Message() == _L("orphaned"), __LINE__);
       
   431 	TheAlarmTest(alarm.RepeatDefinition() == EAlarmRepeatDefintionRepeatOnce, __LINE__);
       
   432 	}
       
   433 
       
   434 static void DoTestsL()
       
   435 	{
       
   436 	CActiveScheduler* scheduler = new(ELeave) CActiveScheduler;
       
   437 	CleanupStack::PushL(scheduler);
       
   438 	CActiveScheduler::Install(scheduler);
       
   439 
       
   440 #if defined(__WINS__) && defined(_DEBUG)
       
   441 	RPIMTestServer pimServ;
       
   442 	User::LeaveIfError(pimServ.Connect());
       
   443 #endif
       
   444 
       
   445 #ifdef __WINS__
       
   446 	// This instance of TASShdAlarm is needed to avoid a link error under wins/urel
       
   447 	// It's not actually used for anything
       
   448 	TASShdAlarm dummy;
       
   449 #endif  // __WINS__
       
   450 
       
   451 	
       
   452 	TheAlarmTest.Next(_L("Connecting to server"));
       
   453 	TInt r = TheAlarmTest.Session().Connect();
       
   454 	TheAlarmTest(r == KErrNone, __LINE__);
       
   455 	//
       
   456 	TheAlarmTest.TestClearStoreL();
       
   457 	TInt count = TheAlarmTest.Session().NumberOfAlarmsActiveInQueue();
       
   458 	TheAlarmTest(count == 0, __LINE__);
       
   459 	//
       
   460 #if !defined(_DEBUG)
       
   461 	TheAlarmTest.Test().Printf(_L("THIS TEST IS A DEBUG TEST ONLY\n"));
       
   462 #else   // _DEBUG
       
   463 #ifdef __WINS__
       
   464 	TheAlarmTest.Session().__DbgPreventUserNotify(ETrue);
       
   465 	TestInitAlarmsL();
       
   466 	
       
   467 		
       
   468 	TheAlarmTest.Test().Next(_L("Closing Alarm Server"));
       
   469 	TheAlarmTest.Session().__DbgShutDownServer();
       
   470     TheAlarmTest.Session().Close();
       
   471 	//
       
   472 	TTime newTime;
       
   473 	newTime.HomeTime();
       
   474 	newTime += TTimeIntervalDays(2);
       
   475     User::LeaveIfError(pimServ.SetHomeTime(newTime));
       
   476 
       
   477 	User::After(KTimeToWait);
       
   478 	//
       
   479 	
       
   480 	
       
   481 	TheAlarmTest.Next(_L("Restarting Alarm Server"));
       
   482 	TheAlarmTest.TestStartServers();
       
   483 	r=TheAlarmTest.Session().Connect();
       
   484 	TheAlarmTest(r==KErrNone, __LINE__);
       
   485 	//
       
   486 	TestPostShutDownL();
       
   487 #endif  // __WINS__
       
   488 #endif  // _DEBUG
       
   489 
       
   490 	
       
   491 	TheAlarmTest.Next(_L("Connecting to server"));
       
   492 	r = TheAlarmTest.Session().Connect();
       
   493 	TheAlarmTest(r == KErrNone, __LINE__);
       
   494 	//
       
   495 	TheAlarmTest.TestClearStoreL();
       
   496 	count = TheAlarmTest.Session().NumberOfAlarmsActiveInQueue();
       
   497 	TheAlarmTest(count == 0, __LINE__);
       
   498 
       
   499 	//
       
   500 #if !defined(_DEBUG)
       
   501 	TheAlarmTest.Test().Printf(_L("THIS TEST IS A DEBUG TEST ONLY\n"));
       
   502 #else   // _DEBUG
       
   503 #ifdef __WINS__
       
   504 	TheAlarmTest.Session().__DbgPreventUserNotify(ETrue);
       
   505 	TestInitUtcAlarmsL();
       
   506 	
       
   507 	TheAlarmTest.Test().Next(_L("Closing Alarm Server"));
       
   508 	TheAlarmTest.Session().__DbgShutDownServer();
       
   509     TheAlarmTest.Session().Close();
       
   510 	//
       
   511 	newTime.HomeTime();
       
   512 	newTime += TTimeIntervalDays(2);
       
   513 
       
   514     pimServ.SetHomeTime(newTime);
       
   515 
       
   516 	User::After(KTimeToWait);
       
   517 	//
       
   518 	
       
   519 	TheAlarmTest.Next(_L("Restarting Alarm Server"));
       
   520 	TheAlarmTest.TestStartServers();
       
   521 	r=TheAlarmTest.Session().Connect();
       
   522 	TheAlarmTest(r==KErrNone, __LINE__);
       
   523 	//
       
   524 	TestPostShutDownUtcL();
       
   525 #endif  // __WINS__
       
   526 #endif  // _DEBUG
       
   527 
       
   528 	TheAlarmTest.TestClearStoreL();
       
   529 	TheAlarmTest.Session().Close();
       
   530 
       
   531 #if defined(__WINS__) && defined(_DEBUG)
       
   532     pimServ.Close();
       
   533 #endif
       
   534 
       
   535 	CleanupStack::PopAndDestroy(scheduler);
       
   536 	}
       
   537 
       
   538 /**
       
   539 @SYMTestCaseID PIM-TQUEUERESTORATION-0001
       
   540 */	
       
   541 GLDEF_C TInt E32Main()
       
   542 //
       
   543 // Test the alarm server.
       
   544 //
       
   545     {
       
   546 	__UHEAP_MARK;
       
   547 	TInt ret = KErrNone;
       
   548 	CTrapCleanup* cleanup = CTrapCleanup::New();
       
   549 	if (!cleanup)
       
   550 		{
       
   551 		return KErrNoMemory;
       
   552 		}
       
   553 
       
   554 	TheAlarmTest.Title();
       
   555 	TheAlarmTest.Start(_L("@SYMTestCaseID PIM-TQUEUERESTORATION-0001 TQueueRestoration"));
       
   556 	TheAlarmTest.TestStartServers();
       
   557 	//
       
   558 	TRAPD(error, DoTestsL());
       
   559 	TheAlarmTest(error == KErrNone, __LINE__);
       
   560 	//
       
   561     TRAP(ret,TheAlarmTest.EndL());
       
   562     	TheAlarmTest.Test().Close();
       
   563 	ASTstAlarmTest::Close();
       
   564 
       
   565 	delete cleanup;
       
   566 	__UHEAP_MARKEND;
       
   567 	return ret;
       
   568     }