commonappservices/alarmserver/Test/TAlarmIdArrays.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 
       
    18 // Globals
       
    19 static TRequestStatus TheStatus;
       
    20 #if defined(__WINS__)
       
    21 static TInt TheNumberOfReviewAlarms=0;
       
    22 #endif  // __WINS__
       
    23 
       
    24 
       
    25 static void testSetAlarmsL()
       
    26 //
       
    27 //	Set alarms in future and past
       
    28 //		3 orphan alarms (one, three, four)
       
    29 //		1 clock alarm (two)
       
    30 //		1 session alarm (five)
       
    31 //		1 review alarm (six, clock)
       
    32 //	This test is only performed when simulating, i.e. it is not active on hardware
       
    33 //  The reason is that we can not give any instruction set to the alarm alert server on HW
       
    34 	{
       
    35 #if defined(__WINS__)
       
    36 	TheAlarmTest.Test().Next(_L("Set orphan review clock and session alarms"));
       
    37 	TheAlarmTest(TheAlarmTest.CountOrphanedAlarmsL() == 0, __LINE__);
       
    38 	TheAlarmTest(TheAlarmTest.Session().AlarmCountByState(EAlarmStateSnoozed) == 0, __LINE__);
       
    39 	TheAlarmTest(TheAlarmTest.Session().AlarmCountByState(EAlarmStateNotified) == TheNumberOfReviewAlarms, __LINE__);
       
    40 	TheAlarmTest(TheAlarmTest.Session().NumberOfAlarmsActiveInQueue() == 0, __LINE__);
       
    41 	//
       
    42 	TInt r;
       
    43 	TAlarmId id;
       
    44 	TASShdAlarm alarm;
       
    45 	TASShdAlarm alarmInfo;
       
    46 	//
       
    47 	alarm.NextDueTime().HomeTime();
       
    48 	alarm.NextDueTime() += TTimeIntervalDays(1);
       
    49 	alarm.Message() = _L("one");
       
    50 	alarm.Characteristics() = EAlarmCharacteristicsSessionSpecific;
       
    51 	TheAlarmTest.Session().AlarmAddWithNotification(TheStatus, alarm);
       
    52 	TheAlarmTest(alarm.Id() != KNullAlarmId, __LINE__);
       
    53 	//
       
    54 	r = TheAlarmTest.Session().GetNextDueAlarmId(id);
       
    55 	TheAlarmTest(id == alarm.Id(), __LINE__);
       
    56 	r = TheAlarmTest.Session().GetAlarmDetails(id, alarmInfo);
       
    57 	TheAlarmTest(r==KErrNone, __LINE__);
       
    58 	TheAlarmTest(alarmInfo.Message() == alarm.Message(), __LINE__);
       
    59 	//
       
    60 	TASShdAlarm alarm2;
       
    61 	alarm2.NextDueTime().HomeTime();
       
    62 	alarm2.NextDueTime() += TTimeIntervalDays(1);
       
    63 	alarm2.NextDueTime() += TTimeIntervalMinutes(1);
       
    64 	alarm2.Message() = _L("two");
       
    65 	alarm2.RepeatDefinition() = EAlarmRepeatDefintionRepeatOnce;
       
    66 	r = TheAlarmTest.Session().AlarmAdd(alarm2);
       
    67 	TheAlarmTest(r == KErrNone, __LINE__);
       
    68 	TheAlarmTest(alarm2.Id() != KNullAlarmId, __LINE__);
       
    69 	//
       
    70 	r = TheAlarmTest.Session().GetNextDueAlarmId(id);
       
    71 	TheAlarmTest(id == alarm.Id(), __LINE__);
       
    72 	r = TheAlarmTest.Session().GetAlarmDetails(id, alarmInfo);
       
    73 	TheAlarmTest(r==KErrNone, __LINE__);
       
    74 	TheAlarmTest(alarmInfo.Message() == alarm.Message(), __LINE__);
       
    75 	//
       
    76 	r = TheAlarmTest.Session().SetAlarmCharacteristics(alarm.Id(), 0);
       
    77 	TheAlarmTest(r==KErrNone, __LINE__);
       
    78 	TheAlarmTest(TheStatus != KRequestPending, __LINE__);
       
    79 	User::WaitForRequest(TheStatus);
       
    80 	//
       
    81 	r = TheAlarmTest.Session().GetNextDueAlarmId(id);
       
    82 	TheAlarmTest(id == alarm.Id(), __LINE__);
       
    83 	r = TheAlarmTest.Session().GetAlarmDetails(id, alarmInfo);
       
    84 	TheAlarmTest(r==KErrNone, __LINE__);
       
    85 	TheAlarmTest(alarmInfo.Message() == alarm.Message(), __LINE__);
       
    86 	//
       
    87 	alarm.NextDueTime() += TTimeIntervalDays(1);
       
    88 	alarm.Message() = _L("three");
       
    89 	alarm.Characteristics() = EAlarmCharacteristicsSessionSpecific;
       
    90 	//
       
    91 	TheAlarmTest.Session().AlarmAddWithNotification(TheStatus, alarm);
       
    92 	TheAlarmTest(alarm.Id() != KErrNone, __LINE__);
       
    93 	r = TheAlarmTest.Session().SetAlarmCharacteristics(alarm.Id(), 0);
       
    94 	TheAlarmTest(r==KErrNone, __LINE__);
       
    95 	TheAlarmTest(TheStatus != KRequestPending, __LINE__);
       
    96 	User::WaitForRequest(TheStatus);
       
    97 	//
       
    98 	alarm.NextDueTime() += TTimeIntervalDays(1);
       
    99 	alarm.Message() = _L("four");
       
   100 	alarm.Characteristics() = EAlarmCharacteristicsSessionSpecific;
       
   101 	//
       
   102 	TheAlarmTest.Session().AlarmAddWithNotification(TheStatus, alarm);
       
   103 	TheAlarmTest(alarm.Id() != KErrNone, __LINE__);
       
   104 	r = TheAlarmTest.Session().SetAlarmCharacteristics(alarm.Id(), 0);
       
   105 	TheAlarmTest(r==KErrNone, __LINE__);
       
   106 	TheAlarmTest(TheStatus != KRequestPending, __LINE__);
       
   107 	User::WaitForRequest(TheStatus);
       
   108 	//
       
   109 	alarm.Characteristics() = EAlarmCharacteristicsSessionSpecific;
       
   110 	alarm.NextDueTime() += TTimeIntervalDays(1);
       
   111 	alarm.NextDueTime() += TTimeIntervalMinutes(1);
       
   112 	alarm.Message() = _L("five");
       
   113 	TheAlarmTest.Session().AlarmAddWithNotification(TheStatus, alarm);
       
   114 	const TAlarmId sessionAlarmId = alarm.Id();
       
   115 	//
       
   116 	TheAlarmTest(TheAlarmTest.CountOrphanedAlarmsL() == 3, __LINE__);
       
   117 	TheAlarmTest(TheAlarmTest.Session().AlarmCountByState(EAlarmStateSnoozed) == 0, __LINE__);
       
   118 	TheAlarmTest(TheAlarmTest.Session().AlarmCountByState(EAlarmStateNotified) == TheNumberOfReviewAlarms, __LINE__);
       
   119 	TheAlarmTest(TheAlarmTest.Session().NumberOfAlarmsActiveInQueue() == 5, __LINE__);
       
   120 	//
       
   121 	User::After(5000000);
       
   122 	//
       
   123 	alarm.NextDueTime().HomeTime();
       
   124 	alarm.NextDueTime() += TTimeIntervalMinutes(-1);
       
   125 	alarm.Message() = _L("six");
       
   126 	alarm.SoundName() = _L("rings");
       
   127 	alarm.Characteristics() = 0;
       
   128 	alarm.RepeatDefinition() = EAlarmRepeatDefintionRepeatOnce;
       
   129 	//
       
   130 	r = TheAlarmTest.Session().AlarmAdd(alarm);
       
   131 	TheAlarmTest(r == KErrNone, __LINE__);
       
   132 	TheAlarmTest(alarm.Id() != KNullAlarmId, __LINE__);
       
   133 	//
       
   134 	User::After(5000000);
       
   135 	//
       
   136 	TInt count;
       
   137 	count = TheAlarmTest.CountOrphanedAlarmsL();
       
   138 	TheAlarmTest(count == 3, __LINE__);
       
   139 	count = TheAlarmTest.Session().AlarmCountByState(EAlarmStateSnoozed);
       
   140 	TheAlarmTest(count == 0, __LINE__);
       
   141 	count = TheAlarmTest.Session().NumberOfAlarmsActiveInQueue();
       
   142 	TheAlarmTest(count == 5, __LINE__);
       
   143 	count = TheAlarmTest.Session().AlarmCountByState(EAlarmStateNotified);
       
   144 	TheAlarmTest(count == TheNumberOfReviewAlarms + 1, __LINE__);
       
   145 	//
       
   146 	r = TheAlarmTest.Session().SetAlarmCharacteristics(sessionAlarmId, 0);
       
   147 	TheAlarmTest(r==KErrNone, __LINE__);
       
   148 	TheAlarmTest(TheStatus != KRequestPending, __LINE__);
       
   149 	User::WaitForRequest(TheStatus);
       
   150 #endif  // __WINS__
       
   151 	}
       
   152 
       
   153 
       
   154 static void testSnoozeArrayL()
       
   155 //
       
   156 //	Test the snooze debug alarm
       
   157 //
       
   158 	{
       
   159 	TheAlarmTest.Test().Next(_L("Snoozed alarms"));
       
   160 #if !defined(_DEBUG)
       
   161 	TheAlarmTest.Test().Printf(_L("This is a debug test only!\n"));
       
   162 	return;
       
   163 #else   // _DEBUG
       
   164 	TheAlarmTest(TheAlarmTest.Session().NumberOfAlarmsActiveInQueue() == 0, __LINE__);
       
   165 	TheAlarmTest(TheAlarmTest.Session().AlarmCountByState(EAlarmStateSnoozed) == 0, __LINE__);
       
   166 	TheAlarmTest(TheAlarmTest.CountOrphanedAlarmsL() == 0, __LINE__);
       
   167 
       
   168 	TASShdAlarm alarm;
       
   169 	alarm.NextDueTime().HomeTime();
       
   170 	alarm.NextDueTime() += TTimeIntervalDays(1);
       
   171 	alarm.NextDueTime().RoundUpToNextMinute();
       
   172 	alarm.Message() =_L("one");
       
   173 	TheAlarmTest.Session().AlarmAddWithNotification(TheStatus, alarm);
       
   174 	TheAlarmTest(alarm.Id() != KNullAlarmId, __LINE__);
       
   175 	TheAlarmTest(TheStatus == KRequestPending, __LINE__);
       
   176 	//
       
   177 	TASShdAlarm alarm2;
       
   178 	TInt r = TheAlarmTest.Session().GetAlarmDetails(alarm.Id(), alarm2);
       
   179 	TheAlarmTest(r == KErrNone, __LINE__);
       
   180 	//
       
   181 	TheAlarmTest(TheAlarmTest.Session().NumberOfAlarmsActiveInQueue() == 1, __LINE__);
       
   182 	TheAlarmTest(TheAlarmTest.Session().AlarmCountByState(EAlarmStateSnoozed) == 0, __LINE__);
       
   183 	TheAlarmTest(TheAlarmTest.CountOrphanedAlarmsL() == 0, __LINE__);
       
   184 	//
       
   185 	r = TheAlarmTest.Session().AlarmDelete(alarm.Id());
       
   186 	TheAlarmTest(r == KErrAccessDenied, __LINE__);
       
   187 	//
       
   188 	TTime snooze = alarm.NextDueTime() + TTimeIntervalMinutes(20);
       
   189 	r = TheAlarmTest.Session().__DbgSnoozeAlarm(alarm.Id(), snooze - User::UTCOffset());
       
   190 	TheAlarmTest(r == KErrNone, __LINE__);
       
   191 	//
       
   192 	TInt count;
       
   193 	count = TheAlarmTest.Session().NumberOfAlarmsActiveInQueue();
       
   194 	TheAlarmTest(count == 1, __LINE__);
       
   195 	count = TheAlarmTest.Session().AlarmCountByState(EAlarmStateSnoozed);
       
   196 	TheAlarmTest(count == 1, __LINE__);
       
   197 	count = TheAlarmTest.CountOrphanedAlarmsL();
       
   198 	TheAlarmTest(count == 0, __LINE__);
       
   199 	//
       
   200 	TAlarmId nextAlarmId;
       
   201 	r = TheAlarmTest.Session().GetNextDueAlarmId(nextAlarmId);
       
   202 	TheAlarmTest(r == KErrNone, __LINE__);
       
   203 	TASShdAlarm nextAlarm;
       
   204 	r = TheAlarmTest.Session().GetAlarmDetails(nextAlarmId, nextAlarm);
       
   205 	TheAlarmTest(r == KErrNone, __LINE__);
       
   206 	//
       
   207 	TheAlarmTest(nextAlarm.State() == EAlarmStateSnoozed, __LINE__);
       
   208 	TheAlarmTest(nextAlarm.NextDueTime() == snooze, __LINE__);
       
   209 	//
       
   210 	RArray<TAlarmId> ids;
       
   211 	TheAlarmTest.Session().GetAlarmIdListByStateL(EAlarmStateSnoozed, ids);
       
   212 	TheAlarmTest(ids.Count() == 1, __LINE__);
       
   213 	TheAlarmTest(ids[0] == nextAlarm.Id(), __LINE__);
       
   214 	TheAlarmTest(nextAlarmId == alarm.Id(), __LINE__);
       
   215 	TheAlarmTest.Session().AlarmNotificationCancelAndDequeue(alarm.Id());
       
   216 	ids.Close();
       
   217 #endif  // _DEBUG
       
   218 	}
       
   219 
       
   220 	
       
   221 static void testSnoozeArrayUtcL()
       
   222 	{
       
   223 	TheAlarmTest.Test().Next(_L("Snoozed UTC alarms"));
       
   224 #if !defined(_DEBUG)
       
   225 	TheAlarmTest.Test().Printf(_L("THis is a debug test only!\n"));
       
   226 	return;
       
   227 #else   // _DEBUG
       
   228 	TheAlarmTest(TheAlarmTest.Session().NumberOfAlarmsActiveInQueue() == 0, __LINE__);
       
   229 	TheAlarmTest(TheAlarmTest.Session().AlarmCountByState(EAlarmStateSnoozed) == 0, __LINE__);
       
   230 	TheAlarmTest(TheAlarmTest.CountOrphanedAlarmsL() == 0, __LINE__);
       
   231 
       
   232 	TASShdAlarm alarm;
       
   233 	TTime time;
       
   234 	time.UniversalTime();
       
   235 	time += TTimeIntervalDays(1);
       
   236 	time.RoundUpToNextMinute();
       
   237 	alarm.SetUtcNextDueTime(time);
       
   238 	alarm.Message()=(_L("one"));
       
   239 	TheAlarmTest.Session().AlarmAddWithNotification(TheStatus, alarm);
       
   240 	TheAlarmTest(alarm.Id() != KNullAlarmId, __LINE__);
       
   241 	TheAlarmTest(TheStatus == KRequestPending, __LINE__);
       
   242 	//
       
   243 	TASShdAlarm alarm2;
       
   244 	TInt r = TheAlarmTest.Session().GetAlarmDetails(alarm.Id(), alarm2);
       
   245 	TheAlarmTest(r == KErrNone, __LINE__);
       
   246 	//
       
   247 	TheAlarmTest(TheAlarmTest.Session().NumberOfAlarmsActiveInQueue() == 1, __LINE__);
       
   248 	TheAlarmTest(TheAlarmTest.Session().AlarmCountByState(EAlarmStateSnoozed) == 0, __LINE__);
       
   249 	TheAlarmTest(TheAlarmTest.CountOrphanedAlarmsL() == 0, __LINE__);
       
   250 	//
       
   251 	r = TheAlarmTest.Session().AlarmDelete(alarm.Id());
       
   252 	TheAlarmTest(r == KErrAccessDenied, __LINE__);
       
   253 	//
       
   254 	TTime snooze = alarm.NextDueTime() + TTimeIntervalMinutes(20);
       
   255 	r = TheAlarmTest.Session().__DbgSnoozeAlarm(alarm.Id(), snooze);
       
   256 	TheAlarmTest(r == KErrNone, __LINE__);
       
   257 	//
       
   258 	TInt count;
       
   259 	count = TheAlarmTest.Session().NumberOfAlarmsActiveInQueue();
       
   260 	TheAlarmTest(count == 1, __LINE__);
       
   261 	count = TheAlarmTest.Session().AlarmCountByState(EAlarmStateSnoozed);
       
   262 	TheAlarmTest(count == 1, __LINE__);
       
   263 	count = TheAlarmTest.CountOrphanedAlarmsL();
       
   264 	TheAlarmTest(count == 0, __LINE__);
       
   265 	//
       
   266 	TAlarmId nextAlarmId;
       
   267 	r = TheAlarmTest.Session().GetNextDueAlarmId(nextAlarmId);
       
   268 	TheAlarmTest(r == KErrNone, __LINE__);
       
   269 	TASShdAlarm nextAlarm;
       
   270 	r = TheAlarmTest.Session().GetAlarmDetails(nextAlarmId, nextAlarm);
       
   271 	TheAlarmTest(r == KErrNone, __LINE__);
       
   272 	//
       
   273 	TheAlarmTest(nextAlarm.State() == EAlarmStateSnoozed, __LINE__);
       
   274 	TheAlarmTest(nextAlarm.NextDueTime() == snooze, __LINE__);
       
   275 	//
       
   276 	RArray<TAlarmId> ids;
       
   277 	TheAlarmTest.Session().GetAlarmIdListByStateL(EAlarmStateSnoozed, ids);
       
   278 	TheAlarmTest(ids.Count() == 1, __LINE__);
       
   279 	TheAlarmTest(ids[0] == nextAlarm.Id(), __LINE__);
       
   280 	TheAlarmTest(nextAlarmId == alarm.Id(), __LINE__);
       
   281 	TheAlarmTest.Session().AlarmNotificationCancelAndDequeue(alarm.Id());
       
   282 	ids.Close();
       
   283 #endif  // _DEBUG
       
   284 	}
       
   285 
       
   286 
       
   287 static void testSetUtcAlarmsL()
       
   288 	{
       
   289 #if defined(__WINS__)
       
   290 	TheAlarmTest.Test().Next(_L("Set orphan review clock and session alarms"));
       
   291 	TheAlarmTest(TheAlarmTest.CountOrphanedAlarmsL() == 0, __LINE__);
       
   292 	TheAlarmTest(TheAlarmTest.Session().AlarmCountByState(EAlarmStateSnoozed) == 0, __LINE__);
       
   293 	TheAlarmTest(TheAlarmTest.Session().AlarmCountByState(EAlarmStateNotified) == TheNumberOfReviewAlarms, __LINE__);
       
   294 	TheAlarmTest(TheAlarmTest.Session().NumberOfAlarmsActiveInQueue() == 0, __LINE__);
       
   295 	//
       
   296 	TInt r;
       
   297 	TAlarmId id;
       
   298 	TASShdAlarm alarm;
       
   299 	TASShdAlarm alarmInfo;
       
   300 	TLocale locale;
       
   301 	//
       
   302 	TTime time;
       
   303 	time.UniversalTime();
       
   304 	time += TTimeIntervalDays(1);
       
   305 	alarm.SetUtcNextDueTime(time);
       
   306 	alarm.Message()=(_L("one"));
       
   307 	alarm.Characteristics().Set(EAlarmCharacteristicsSessionSpecific);
       
   308 	TheAlarmTest.Session().AlarmAddWithNotification(TheStatus, alarm);
       
   309 	TheAlarmTest(alarm.Id() != KNullAlarmId, __LINE__);
       
   310 	//
       
   311 	r = TheAlarmTest.Session().GetNextDueAlarmId(id);
       
   312 	TheAlarmTest(id == alarm.Id(), __LINE__);
       
   313 	r = TheAlarmTest.Session().GetAlarmDetails(id, alarmInfo);
       
   314 	TheAlarmTest(r==KErrNone, __LINE__);
       
   315 	TheAlarmTest(alarmInfo.Message() == alarm.Message(), __LINE__);
       
   316 	//
       
   317 	TASShdAlarm alarm2;
       
   318 	time.HomeTime();
       
   319 	time -= locale.UniversalTimeOffset();
       
   320 	time += TTimeIntervalDays(1);
       
   321 	time += TTimeIntervalMinutes(1);
       
   322 	alarm2.SetUtcNextDueTime(time);
       
   323 	alarm2.Message()=(_L("two"));
       
   324 	alarm2.RepeatDefinition()=(EAlarmRepeatDefintionRepeatOnce);
       
   325 	r = TheAlarmTest.Session().AlarmAdd(alarm2);
       
   326 	TheAlarmTest(r == KErrNone, __LINE__);
       
   327 	TheAlarmTest(alarm2.Id() != KNullAlarmId, __LINE__);
       
   328 	//
       
   329 	r = TheAlarmTest.Session().GetNextDueAlarmId(id);
       
   330 	TheAlarmTest(id == alarm.Id(), __LINE__);
       
   331 	r = TheAlarmTest.Session().GetAlarmDetails(id, alarmInfo);
       
   332 	TheAlarmTest(r==KErrNone, __LINE__);
       
   333 	TheAlarmTest(alarmInfo.Message() == alarm.Message(), __LINE__);
       
   334 	//
       
   335 	r = TheAlarmTest.Session().SetAlarmCharacteristics(alarm.Id(), 0);
       
   336 	TheAlarmTest(r==KErrNone, __LINE__);
       
   337 	User::WaitForRequest(TheStatus);
       
   338 	TheAlarmTest(TheStatus != KRequestPending, __LINE__);
       
   339 	//
       
   340 	r = TheAlarmTest.Session().GetNextDueAlarmId(id);
       
   341 	TheAlarmTest(id == alarm.Id(), __LINE__);
       
   342 	r = TheAlarmTest.Session().GetAlarmDetails(id, alarmInfo);
       
   343 	TheAlarmTest(r==KErrNone, __LINE__);
       
   344 	TheAlarmTest(alarmInfo.Message() == alarm.Message(), __LINE__);
       
   345 	//
       
   346 	time = alarm.NextDueTime() + TTimeIntervalDays(1);
       
   347 	alarm.SetUtcNextDueTime(time);
       
   348 	alarm.Message()=(_L("three"));
       
   349 	alarm.Characteristics().Set(EAlarmCharacteristicsSessionSpecific);
       
   350 	//
       
   351 	TheAlarmTest.Session().AlarmAddWithNotification(TheStatus, alarm);
       
   352 	TheAlarmTest(alarm.Id() != KErrNone, __LINE__);
       
   353 	r = TheAlarmTest.Session().SetAlarmCharacteristics(alarm.Id(), 0);
       
   354 	TheAlarmTest(r==KErrNone, __LINE__);
       
   355 	TheAlarmTest(TheStatus != KRequestPending, __LINE__);
       
   356 	User::WaitForRequest(TheStatus);
       
   357 	//
       
   358 	time = alarm.NextDueTime() + TTimeIntervalDays(1);
       
   359 	alarm.SetUtcNextDueTime(time);
       
   360 	alarm.Message()=(_L("four"));
       
   361 	alarm.Characteristics().Set(EAlarmCharacteristicsSessionSpecific);
       
   362 	//
       
   363 	TheAlarmTest.Session().AlarmAddWithNotification(TheStatus, alarm);
       
   364 	TheAlarmTest(alarm.Id() != KErrNone, __LINE__);
       
   365 	r = TheAlarmTest.Session().SetAlarmCharacteristics(alarm.Id(), 0);
       
   366 	TheAlarmTest(r==KErrNone, __LINE__);
       
   367 	TheAlarmTest(TheStatus != KRequestPending, __LINE__);
       
   368 	User::WaitForRequest(TheStatus);
       
   369 	//
       
   370 	alarm.Characteristics().Set(EAlarmCharacteristicsSessionSpecific);
       
   371 	time = alarm.NextDueTime() + TTimeIntervalDays(1);
       
   372 	time += TTimeIntervalMinutes(1);
       
   373 	alarm.SetUtcNextDueTime(time);
       
   374 	alarm.Message()=(_L("five"));
       
   375 	TheAlarmTest.Session().AlarmAddWithNotification(TheStatus, alarm);
       
   376 	const TAlarmId sessionAlarmId = alarm.Id();
       
   377 	//
       
   378 	TheAlarmTest(TheAlarmTest.CountOrphanedAlarmsL() == 3, __LINE__);
       
   379 	TheAlarmTest(TheAlarmTest.Session().AlarmCountByState(EAlarmStateSnoozed) == 0, __LINE__);
       
   380 	TheAlarmTest(TheAlarmTest.Session().AlarmCountByState(EAlarmStateNotified) == TheNumberOfReviewAlarms, __LINE__);
       
   381 	TheAlarmTest(TheAlarmTest.Session().NumberOfAlarmsActiveInQueue() == 5, __LINE__);
       
   382 	//
       
   383 	User::After(5000000);
       
   384 	//
       
   385 	time.UniversalTime();
       
   386 	time += TTimeIntervalMinutes(-1);
       
   387 	alarm.SetUtcNextDueTime(time);
       
   388 	alarm.Message()=(_L("six"));
       
   389 	alarm.SoundName()=(_L("rings"));
       
   390 	alarm.Characteristics().Set(0);
       
   391 	alarm.RepeatDefinition()=EAlarmRepeatDefintionRepeatOnce;
       
   392 	//
       
   393 	r = TheAlarmTest.Session().AlarmAdd(alarm);
       
   394 	TheAlarmTest(r == KErrNone, __LINE__);
       
   395 	TheAlarmTest(alarm.Id() != KNullAlarmId, __LINE__);
       
   396 	//
       
   397 	User::After(5000000);
       
   398 	//
       
   399 	TInt count;
       
   400 	count = TheAlarmTest.CountOrphanedAlarmsL();
       
   401 	TheAlarmTest(count == 3, __LINE__);
       
   402 	count = TheAlarmTest.Session().AlarmCountByState(EAlarmStateSnoozed);
       
   403 	TheAlarmTest(count == 0, __LINE__);
       
   404 	count = TheAlarmTest.Session().NumberOfAlarmsActiveInQueue();
       
   405 	TheAlarmTest(count == 5, __LINE__);
       
   406 	count = TheAlarmTest.Session().AlarmCountByState(EAlarmStateNotified);
       
   407 	TheAlarmTest(count == TheNumberOfReviewAlarms + 1, __LINE__);
       
   408 	//
       
   409 	r = TheAlarmTest.Session().SetAlarmCharacteristics(sessionAlarmId, 0);
       
   410 	TheAlarmTest(r==KErrNone, __LINE__);
       
   411 	TheAlarmTest(TheStatus != KRequestPending, __LINE__);
       
   412 	User::WaitForRequest(TheStatus);
       
   413 #endif  // __WINS__
       
   414 	}
       
   415 
       
   416 
       
   417 static void doTestsL()
       
   418 	{
       
   419 	const TInt KGmtOffset = 0;
       
   420 	_LIT(KTime, "20041130:050000.000000"); //In winter time
       
   421 	TInt err = User::SetUTCTimeAndOffset(TTime(KTime), KGmtOffset);
       
   422 
       
   423 	RArray<TInt> instructionSet;
       
   424 	instructionSet.AppendL(EKeyEscape);
       
   425 	instructionSet.AppendL(EKeyEscape);
       
   426 	TheAlarmTest.TestStartServers(&instructionSet);
       
   427 	TheAlarmTest.Test().Next(_L("Connecting to the alarm server"));
       
   428 	TheAlarmTest(TheAlarmTest.Session().Connect()==KErrNone, __LINE__);
       
   429 	//
       
   430 #if defined(__WINS__)
       
   431 	TheNumberOfReviewAlarms = TheAlarmTest.Session().AlarmCountByState(EAlarmStateNotified);
       
   432 #else   // __WINS__
       
   433 	TheAlarmTest.Session().AlarmCountByState(EAlarmStateNotified);
       
   434 #endif  // __WINS__
       
   435 
       
   436 	TheAlarmTest.TestClearStoreL();
       
   437 	testSnoozeArrayL();
       
   438 	testSetAlarmsL();
       
   439 	//
       
   440 	TheAlarmTest.TestClearStoreL();
       
   441 	testSnoozeArrayUtcL();
       
   442 	testSetUtcAlarmsL();
       
   443 
       
   444 	TheAlarmTest.TestClearStoreL();
       
   445 	TheAlarmTest.Session().Close();
       
   446 	instructionSet.Close();
       
   447 	}
       
   448 
       
   449 /**
       
   450 @SYMTestCaseID PIM-TALARMIDARRAYS-0001
       
   451 */
       
   452 GLDEF_C TInt E32Main()
       
   453 //
       
   454 // Test the alarm server.
       
   455 //
       
   456     {
       
   457 	__UHEAP_MARK;
       
   458 	//
       
   459 	TInt ret = KErrNone;
       
   460 	CTrapCleanup* cleanup = CTrapCleanup::New();
       
   461 	//
       
   462 	TheAlarmTest.Title();
       
   463 	TheAlarmTest.Start(_L("@SYMTestCaseID PIM-TALARMIDARRAYS-0001 Alarm arrays"));
       
   464 	TRAPD(err, doTestsL());
       
   465 	TheAlarmTest(err == KErrNone, __LINE__);
       
   466 	TRAP(ret,TheAlarmTest.EndL());
       
   467 	TheAlarmTest.Test().Close();
       
   468 	ASTstAlarmTest::Close();
       
   469 	//
       
   470 	delete cleanup;
       
   471 	//
       
   472 	__UHEAP_MARKEND;
       
   473 	return ret;
       
   474     }