commonappservices/alarmserver/Test/TBasicAlarms.cpp
changeset 0 2e3d3ce01487
equal deleted inserted replaced
-1:000000000000 0:2e3d3ce01487
       
     1 // Copyright (c) 1999-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 // System includes
       
    17 #include <e32base.h>
       
    18 #include <e32test.h>
       
    19 #include <f32file.h>
       
    20 
       
    21 // User includes
       
    22 #include <asshdalarm.h>
       
    23 #include <asclisession.h>
       
    24 #include <consolealarmalertservermain.h>
       
    25 #include <consolealarmalertservermain.h>
       
    26 #include "testserver.h"
       
    27 #include "ASTstAlarmTest.h"
       
    28 #include <asclisoundplay.h>
       
    29 #ifdef __WINS__
       
    30 #include "ConsoleANTestClient.h"
       
    31 #endif
       
    32 
       
    33 
       
    34 // Type definitions
       
    35 typedef void (*ThreadTestL)(void);
       
    36 typedef CArrayFixFlat<TASCliSoundPlayDefinition> CPlayIntervalArray;
       
    37 
       
    38 // Constants
       
    39 const TUid KServerUid2={0x1000008D};
       
    40 const TUid KServerUid3={0x101F502A};
       
    41 const TUidType serverUid(KNullUid,KServerUid2,KServerUid3);
       
    42 
       
    43 #define KNewAlarmCycleStartOffsetMinutes        {0,1,2,3,KErrNotFound};
       
    44 
       
    45 _LIT(KTestIniFile, "c:\\private\\101f5027\\AlarmServer.ini");
       
    46 
       
    47 // Globals
       
    48 static RASCliSession TheAlarmServerSession;
       
    49 
       
    50 #if defined(_DEBUG) && defined(__WINS__)
       
    51 _LIT(KDateTimeFormat, "%F %*E %*N %D %Y %J:%T:%S%B");
       
    52 
       
    53 static void PrintTimeL(const TTime& aTime, const TDesC& aPrefix)
       
    54 	{
       
    55 	TBuf<30> dateTimeString;
       
    56 	aTime.FormatL(dateTimeString, KDateTimeFormat);
       
    57 	TheAlarmTest.Test().Printf(_L("%S %S\n"), &aPrefix, &dateTimeString);
       
    58 	}
       
    59 #endif
       
    60 
       
    61 static void TestClearStoreL()
       
    62 	{
       
    63 	// Delete all alarms
       
    64 	RArray<TAlarmCategory> categories;
       
    65 	TheAlarmServerSession.GetAvailableCategoryListL(categories);
       
    66 	TInt count = categories.Count();
       
    67 	for(TInt i=0; i<count; i++)
       
    68 		{
       
    69 		const TAlarmCategory category = categories[i];
       
    70 		TheAlarmTest(TheAlarmServerSession.AlarmDeleteAllByCategory(category, EFalse) == KErrNone, __LINE__);
       
    71 		}
       
    72 	categories.Close();
       
    73 	}
       
    74 
       
    75 void WaitForNotificationBufferToBeEmptied()
       
    76 	{
       
    77 	TRequestStatus status = KErrNone;
       
    78 	TAlarmId alarmId;
       
    79 	if	(status == KRequestPending)
       
    80 		return;
       
    81 
       
    82 	TheAlarmServerSession.NotifyChange(status, alarmId);
       
    83 	User::After(1000000);
       
    84 	if	(status == KRequestPending)
       
    85 		return;
       
    86 	User::WaitForRequest(status);
       
    87 
       
    88 	// Because of event buffering inside the Alarm Server
       
    89 	// We need to wait until there aren't any more events
       
    90 	// in the buffer, and then attempt to cancel the request.
       
    91 	//
       
    92 	// Trying to cancel a request when the server has
       
    93 	// already completed the message (because something
       
    94 	// was in the buffer) results in the server panicing
       
    95 	// the client.
       
    96 	FOREVER
       
    97 		{
       
    98 		TheAlarmTest(status >= EAlarmChangeEventState && status <= EAlarmChangeEventLast);
       
    99 		TheAlarmServerSession.NotifyChange(status, alarmId);
       
   100 		//
       
   101 		// Wait a second so that we can tell if this really is
       
   102 		// waiting for an event, or just for the Alarm Server
       
   103 		// process to be given some scheduling time by the
       
   104 		// kernel
       
   105 		User::After(1000000);
       
   106 
       
   107 		// If its still pending, then we should attempt
       
   108 		// to cancel the request. Otherwise, if its not
       
   109 		// pending, then the Alarm Server probably just
       
   110 		// completed the request based upon the contents
       
   111 		// of the event buffer.
       
   112 		if	(status == KRequestPending)
       
   113 			break;
       
   114 		else
       
   115 			{
       
   116 			// Eat the request and try again
       
   117 			User::WaitForRequest(status);
       
   118 			}
       
   119 		}
       
   120 	}
       
   121 
       
   122 void testTimesEqual(const TTime& aTime1, const TTime& aTime2)
       
   123 	{
       
   124 	// determine the difference, in seconds
       
   125 	TTimeIntervalSeconds	timeDiffSeconds;
       
   126 	const TInt error = aTime2.SecondsFrom(aTime1, timeDiffSeconds);
       
   127 	TheAlarmTest(error == KErrNone);
       
   128 	// check the times are within 1 second
       
   129 	// as the tolerance for notifying alarms should be bigger than 1 second
       
   130 	const TTimeIntervalSeconds	maxDiff(1);
       
   131 	const TTimeIntervalSeconds	minDiff(-1);
       
   132 	TheAlarmTest(((timeDiffSeconds <= maxDiff) && (timeDiffSeconds >= minDiff)));
       
   133 	}
       
   134 
       
   135 
       
   136 /**
       
   137 @SYMTestCaseID PIM-TBASICALARMS-INC092682-0002
       
   138 @SYMTestType UT
       
   139 @SYMTestPriority High
       
   140 @SYMDEF INC092682
       
   141 @SYMTestCaseDesc Tests that re-enabling of a repeating alarm correctly maintains
       
   142 the next due alarm ID (the head alarm in the alarm queue).
       
   143 
       
   144 @SYMTestActions
       
   145 1. Create a workday alarm due to activate in 30 minutes time.
       
   146 2. Create a once only alarm due to activate in 90 minutes time.
       
   147 3. Check that their are 2 active alarms in the queue.
       
   148 4. Check that workday alarm is due to expire before once only alarm.
       
   149 5. Disable workday alarm and check that once only alarm is the next due alarm.
       
   150 6. Advance current time by 1 hour.  The repeating (workday) alarm should be
       
   151    rescheduled for the next workday, leaving the once only alarm as the next due
       
   152    alarm.
       
   153 7. Enable workday alarm.
       
   154 8. Check that once only alarm is next due alarm - workday alarm should be due
       
   155    next day now since time was advanced past today's workday alarm time.
       
   156 
       
   157 @SYMTestExpectedResults The next due alarm is as expected.
       
   158 */
       
   159 
       
   160 
       
   161 static void TestINC092682L()
       
   162 	{
       
   163 	TheAlarmTest.Next(_L("@SYMTestCaseID PIM-TBASICALARMS-INC092682-0002 Testing fix for INC092682."));
       
   164 
       
   165 	//
       
   166 	// Make sure we start with no alarms.
       
   167 	//
       
   168 	TestClearStoreL();
       
   169 
       
   170 	//
       
   171 	// 1. Create a workday alarm due to activate in 30 minutes time.
       
   172 	//
       
   173 	TASShdAlarm alarm;
       
   174 	alarm.RepeatDefinition() = EAlarmRepeatDefintionRepeatWorkday;
       
   175 	alarm.Message() = _L("This is workday alarm message");
       
   176 	alarm.NextDueTime().HomeTime();
       
   177 	alarm.NextDueTime() += TTimeIntervalMinutes(30);
       
   178 	TheAlarmTest(TheAlarmServerSession.AlarmAdd(alarm) == KErrNone, __LINE__);
       
   179 	const TAlarmId workdayId = alarm.Id();
       
   180 
       
   181 	//
       
   182 	// 2. Create a once only alarm due to activate in 90 minutes time.
       
   183 	//
       
   184 	alarm.RepeatDefinition() = EAlarmRepeatDefintionRepeatOnce;
       
   185 	alarm.Message() = _L("This is once only alarm message");
       
   186 	alarm.NextDueTime().HomeTime();
       
   187 	alarm.NextDueTime() += TTimeIntervalMinutes(90);
       
   188 	TheAlarmTest(TheAlarmServerSession.AlarmAdd(alarm) == KErrNone, __LINE__);
       
   189 	const TAlarmId onceOnlyId = alarm.Id();
       
   190 
       
   191 	//
       
   192 	// 3. Check that their are 2 active alarms in the queue.
       
   193 	//
       
   194 	TheAlarmTest(TheAlarmServerSession.NumberOfAlarmsActiveInQueue() == 2, __LINE__);
       
   195 
       
   196 	//
       
   197 	// 4. Check that workday alarm is due to expire before once only alarm.
       
   198 	//
       
   199 	TAlarmId nextAlarmId;
       
   200 	TInt r = TheAlarmServerSession.GetNextDueAlarmId(nextAlarmId);
       
   201 	TheAlarmTest(r == KErrNone, __LINE__);
       
   202 	TheAlarmTest(nextAlarmId == workdayId, __LINE__);
       
   203 
       
   204 	//
       
   205 	// 5. Disable workday alarm and check that once only alarm is the next due
       
   206 	// alarm.
       
   207 	//
       
   208 	TheAlarmTest(TheAlarmServerSession.SetAlarmStatus(workdayId, EAlarmStatusDisabled) == KErrNone, __LINE__);
       
   209 	r = TheAlarmServerSession.GetNextDueAlarmId(nextAlarmId);
       
   210 	TheAlarmTest(r == KErrNone, __LINE__);
       
   211 	TheAlarmTest(nextAlarmId == onceOnlyId, __LINE__);
       
   212 
       
   213 	//
       
   214 	// 6. Advance current time by 1 hour.  The repeating (workday) alarm should
       
   215 	// be rescheduled for the next workday, leaving the once only alarm as the
       
   216 	// next due alarm.
       
   217 	//
       
   218 	TTime oneHourLater;
       
   219 	oneHourLater.HomeTime();
       
   220 	oneHourLater += TTimeIntervalHours(1);
       
   221 	RPIMTestServer serv;
       
   222 	User::LeaveIfError(serv.Connect());
       
   223 	serv.SetHomeTime(oneHourLater);
       
   224 	// Wait for time change notifications to occur.
       
   225 	User::After(10000);
       
   226 	// Set again to ensure time value is correct when update occurs.
       
   227 	serv.SetHomeTime(oneHourLater);
       
   228 	serv.Close();
       
   229 
       
   230 	//
       
   231 	// 7. Enable workday alarm.
       
   232 	//
       
   233 	TheAlarmTest(TheAlarmServerSession.SetAlarmStatus(workdayId, EAlarmStatusEnabled) == KErrNone, __LINE__);
       
   234 
       
   235 	//
       
   236 	// 8. Check that once only alarm is next due alarm - workday alarm should be
       
   237 	// due next day now since time was advanced past today's workday alarm
       
   238 	// time.
       
   239 	//
       
   240 	r = TheAlarmServerSession.GetNextDueAlarmId(nextAlarmId);
       
   241 	TheAlarmTest(r == KErrNone, __LINE__);
       
   242 	TheAlarmTest(nextAlarmId == onceOnlyId, __LINE__);
       
   243 
       
   244 	//
       
   245 	// Tidy up.
       
   246 	//
       
   247 	TestClearStoreL();
       
   248 	WaitForNotificationBufferToBeEmptied();
       
   249 	}
       
   250 
       
   251 
       
   252 //*************************************************************************************
       
   253 static void CreateSingleAlarmL()
       
   254 	{
       
   255 #ifdef __WINS__
       
   256 	
       
   257 	
       
   258 	TheAlarmTest.Next(_L("Adding disabled alarm"));
       
   259 	//
       
   260 	TASShdAlarm alarm;
       
   261 	alarm.Category() = KASCliCategoryClock;
       
   262 	alarm.RepeatDefinition() = EAlarmRepeatDefintionRepeatDaily;
       
   263 	alarm.Message() = _L("This is an alarm message - alarm 1");
       
   264 	alarm.NextDueTime().HomeTime();
       
   265 	alarm.NextDueTime() += TTimeIntervalMinutes(1);
       
   266 	alarm.SoundName() = _L("Arf Arf Woop");
       
   267 	//
       
   268 	TTime now;
       
   269 	now.HomeTime();
       
   270 	//
       
   271 	TheAlarmTest(TheAlarmServerSession.AlarmAdd(alarm) == KErrNone, __LINE__);
       
   272 	const TAlarmId id = alarm.Id();
       
   273 	TheAlarmTest(id != KNullAlarmId, __LINE__);
       
   274 
       
   275 		
       
   276 	
       
   277 	TheAlarmTest.Next(_L("Get alarm details"));
       
   278 	TheAlarmTest(TheAlarmServerSession.GetAlarmDetails(id, alarm) == KErrNone, __LINE__);
       
   279 
       
   280 		
       
   281 	
       
   282 	TheAlarmTest.Next(_L("Enabling a disabled alarm"));
       
   283 	TheAlarmTest(TheAlarmServerSession.SetAlarmStatus(id, EAlarmStatusEnabled) == KErrNone, __LINE__);
       
   284 
       
   285 		
       
   286 	
       
   287 	TheAlarmTest.Next(_L("Waiting for alarm to expire..."));
       
   288 
       
   289 	TAlarmId alarmId;
       
   290 	TRequestStatus status;
       
   291 	FOREVER
       
   292 		{
       
   293 		TheAlarmServerSession.NotifyChange(status, alarmId);
       
   294 		User::WaitForRequest(status);
       
   295 		if	(status.Int() == EAlarmChangeEventTimerExpired)
       
   296 			{
       
   297 			TheAlarmTest(id == alarmId, __LINE__);
       
   298 			break;
       
   299 			}
       
   300 		}
       
   301 #endif
       
   302 	}
       
   303 
       
   304 
       
   305 //*************************************************************************************
       
   306 static void CreateAlarmAndIgnoreL()
       
   307     {
       
   308 #ifdef __WINS__
       
   309 	
       
   310     TheAlarmTest.Next(_L("Adding disabled alarm"));
       
   311     //
       
   312     TASShdAlarm alarm;
       
   313     alarm.Category() = KASCliCategoryClock;
       
   314     alarm.RepeatDefinition() = EAlarmRepeatDefintionRepeatDaily;
       
   315     alarm.Message() = _L("This is an alarm message - alarm 1");
       
   316     alarm.NextDueTime().HomeTime();
       
   317     alarm.NextDueTime() += TTimeIntervalMinutes(1);
       
   318     alarm.SoundName() = _L("Arf Arf Woop");
       
   319 
       
   320     //
       
   321     TTime now;
       
   322     now.HomeTime();
       
   323     //
       
   324     TheAlarmTest(TheAlarmServerSession.AlarmAdd(alarm) == KErrNone, __LINE__);
       
   325     const TAlarmId id = alarm.Id();
       
   326     TheAlarmTest(id != KNullAlarmId, __LINE__);
       
   327 
       
   328     // copy the current soundsettings
       
   329     CPlayIntervalArray* originalSoundArray = new(ELeave) CPlayIntervalArray(20);
       
   330     CleanupStack::PushL(originalSoundArray);
       
   331 
       
   332     TheAlarmServerSession.GetAlarmPlayIntervalsL(*originalSoundArray);
       
   333 
       
   334     // use shorted one
       
   335     CPlayIntervalArray* newSoundArray = new(ELeave) CPlayIntervalArray(10);
       
   336     CleanupStack::PushL(newSoundArray);
       
   337     const TInt minuteCycle[]=KNewAlarmCycleStartOffsetMinutes;
       
   338     TInt i(0);
       
   339     TInt offset(minuteCycle[i]);
       
   340     while (offset != KErrNotFound)
       
   341         {
       
   342         const TASCliSoundPlayDefinition item(offset, KDefaultSoundPlayDurationInSeconds);
       
   343         newSoundArray->AppendL(item);
       
   344         offset = minuteCycle[++i];
       
   345         }
       
   346     TheAlarmServerSession.SetAlarmPlayIntervalsL(*newSoundArray);
       
   347 
       
   348     
       
   349     TheAlarmTest.Next(_L("Get alarm details"));
       
   350     TheAlarmTest(TheAlarmServerSession.GetAlarmDetails(id, alarm) == KErrNone, __LINE__);
       
   351 
       
   352     
       
   353     TheAlarmTest.Next(_L("Enabling a disabled alarm"));
       
   354     TheAlarmTest(TheAlarmServerSession.SetAlarmStatus(id, EAlarmStatusEnabled) == KErrNone, __LINE__);
       
   355 
       
   356     
       
   357     TheAlarmTest.Next(_L("Waiting for alarm to expire..."));
       
   358     TInt numberOfIntervals(newSoundArray->Count());
       
   359     TInt count(0);
       
   360 
       
   361     TAlarmId alarmId;
       
   362     TRequestStatus status;
       
   363     FOREVER
       
   364         {
       
   365         TheAlarmServerSession.NotifyChange(status, alarmId);
       
   366         User::WaitForRequest(status);
       
   367         if    (status.Int() == EAlarmChangeEventSoundPlaying)
       
   368             {
       
   369             if(count > numberOfIntervals)
       
   370                 break;
       
   371             count++;
       
   372             }
       
   373         }
       
   374     // this to check that we have gone through all the time intervals in array
       
   375     TheAlarmTest(count > newSoundArray->Count(), __LINE__);
       
   376     // restore original sound settings
       
   377 	
       
   378     TheAlarmTest.Test().Next(_L("reset default sound intervals"));
       
   379     TheAlarmServerSession.SetAlarmPlayIntervalsL(*originalSoundArray);
       
   380     CleanupStack::PopAndDestroy(2);// originalSoundArray, newSoundArray
       
   381 
       
   382 #endif
       
   383     }
       
   384 
       
   385 //*************************************************************************************
       
   386 
       
   387 	
       
   388 static void CreateNotificationAlarmL()
       
   389 	{
       
   390 	TheAlarmTest.Next(_L("Creating notification alarm"));
       
   391 
       
   392 	// AlarmAddWithNotification
       
   393 	TASShdAlarm alarm;
       
   394 	alarm.NextDueTime().HomeTime();
       
   395 	alarm.NextDueTime() += TTimeIntervalMinutes(1);
       
   396 	TRequestStatus status;
       
   397 	TheAlarmServerSession.AlarmAddWithNotification(status, alarm);
       
   398 	TAlarmId id = alarm.Id();
       
   399 	TheAlarmTest(id != KNullAlarmId, __LINE__);
       
   400 	TheAlarmTest(status == KRequestPending, __LINE__);
       
   401 
       
   402 	// Wait for completion
       
   403 	TheAlarmTest(TheAlarmServerSession.SetAlarmStatus(id, EAlarmStatusEnabled) == KErrNone, __LINE__);
       
   404 	User::WaitForRequest(status);
       
   405 
       
   406 	// AlarmNotificationCancel
       
   407 	alarm.NextDueTime().HomeTime();
       
   408 	alarm.NextDueTime() += TTimeIntervalMinutes(1);
       
   409 	TheAlarmServerSession.AlarmAddWithNotification(status, alarm);
       
   410 	id = alarm.Id();
       
   411 	TheAlarmTest(id != KNullAlarmId, __LINE__);
       
   412 	TheAlarmTest(status == KRequestPending, __LINE__);
       
   413 	TheAlarmServerSession.AlarmNotificationCancelAndDequeue(id);
       
   414 
       
   415 	// Eat request
       
   416 	User::WaitForRequest(status);
       
   417 	TheAlarmTest(status == KErrCancel, __LINE__);
       
   418 	}
       
   419 
       
   420 
       
   421 //*************************************************************************************
       
   422 	
       
   423 
       
   424 static void CreateDailyRepeatingAlarmL()
       
   425 	{
       
   426 	TheAlarmTest.Next(_L("Creating daily repeating alarm"));
       
   427 
       
   428 	// AlarmAddWithNotification
       
   429 	TASShdAlarm alarm;
       
   430 	alarm.NextDueTime().HomeTime();
       
   431 	alarm.NextDueTime() += TTimeIntervalMinutes(1);
       
   432 	alarm.RepeatDefinition() = EAlarmRepeatDefintionRepeatDaily;
       
   433 
       
   434 	TheAlarmServerSession.AlarmAdd(alarm);
       
   435 	TAlarmId id = alarm.Id();
       
   436 	TheAlarmTest(id != KNullAlarmId, __LINE__);
       
   437 
       
   438 	TAlarmId alarmId;
       
   439 	TRequestStatus status;
       
   440 	TheAlarmServerSession.NotifyChange(status, alarmId);
       
   441 	TheAlarmTest(TheAlarmServerSession.SetAlarmStatus(id, EAlarmStatusEnabled) == KErrNone, __LINE__);
       
   442 	User::WaitForRequest(status);
       
   443 	}
       
   444 
       
   445 
       
   446 static void CreateAlarmsForPausingL()
       
   447 	{
       
   448 #ifdef __WINS__
       
   449 
       
   450 	TestClearStoreL();
       
   451 
       
   452 	TheAlarmTest.Next(_L("Test pausing alarm sounds"));
       
   453 	//
       
   454 	// Add an alarm, due in 3 seconds
       
   455 	TASShdAlarm alarm;
       
   456 	alarm.NextDueTime().HomeTime();
       
   457 	alarm.NextDueTime() += TTimeIntervalSeconds(1);
       
   458 
       
   459 	TheAlarmTest(TheAlarmServerSession.AlarmAdd(alarm) == KErrNone, __LINE__);
       
   460 	const TAlarmId id = alarm.Id();
       
   461 	TheAlarmTest(id != KNullAlarmId, __LINE__);
       
   462 	// Wait for the alarm to go off, and be paused
       
   463 	User::After(5 * 1000000);
       
   464 
       
   465 	// The alarm should still be notifying
       
   466 	TheAlarmTest(TheAlarmServerSession.GetAlarmDetails(id, alarm) == KErrNone, __LINE__);
       
   467 	TheAlarmTest(alarm.State() == EAlarmStateNotifying, __LINE__);
       
   468 	TheAlarmTest(TheAlarmServerSession.AlarmDelete(id) == KErrNone, __LINE__);
       
   469 
       
   470 	// Add 2 alarms, due in 3 and 13 seconds
       
   471 	TTime alarm1time;
       
   472 	TTime alarm2time;
       
   473 	alarm1time.HomeTime();
       
   474 	alarm1time += TTimeIntervalSeconds(3);
       
   475 	alarm2time = alarm1time + TTimeIntervalSeconds(10);
       
   476 
       
   477 	TASShdAlarm alarm1;
       
   478 	alarm1.NextDueTime() = alarm1time;
       
   479 	alarm1.Message() = _L("alarm 1");
       
   480 	TASShdAlarm alarm2;
       
   481 	alarm2.NextDueTime() = alarm2time;
       
   482 	alarm2.Message() = _L("alarm 2");
       
   483 
       
   484 	TheAlarmTest(TheAlarmServerSession.AlarmAdd(alarm1) == KErrNone, __LINE__);
       
   485 	const TAlarmId id1 = alarm1.Id();
       
   486 	TheAlarmTest(id1 != KNullAlarmId, __LINE__);
       
   487 	TheAlarmTest(TheAlarmServerSession.AlarmAdd(alarm2) == KErrNone, __LINE__);
       
   488 	const TAlarmId id2 = alarm2.Id();
       
   489 	TheAlarmTest(id2 != KNullAlarmId, __LINE__);
       
   490 	//
       
   491 	// Wait for the 1st alarm to go off, and be paused
       
   492 	User::After(5 * 1000000);
       
   493 
       
   494 	// The 1st alarm should still be notifying
       
   495 	alarm1.Reset();
       
   496 	TheAlarmTest(TheAlarmServerSession.GetAlarmDetails(id1, alarm1) == KErrNone, __LINE__);
       
   497 	TheAlarmTest(alarm1.State() == EAlarmStateNotifying, __LINE__);
       
   498 
       
   499 	// Wait for the time the 2nd alarm is due
       
   500 	User::After(10 * 1000000);
       
   501 	// The 1st alarm should be moved to snoozed, so as not to block the 2nd one
       
   502 	alarm1.Reset();
       
   503 	alarm2.Reset();
       
   504 	TheAlarmTest(TheAlarmServerSession.GetAlarmDetails(id1, alarm1) == KErrNone, __LINE__);
       
   505 	TheAlarmTest(TheAlarmServerSession.GetAlarmDetails(id2, alarm2) == KErrNone, __LINE__);
       
   506 	TheAlarmTest.Test().Printf(_L("\tALARM1 State => %u \n"),alarm1.State());
       
   507 	TheAlarmTest.Test().Printf(_L("\tALARM2 State => %u \n"),alarm2.State());
       
   508 	TheAlarmTest(alarm1.State() == EAlarmStateSnoozed, __LINE__);
       
   509 	TheAlarmTest(alarm2.State() == EAlarmStateNotified, __LINE__);
       
   510 	// the 1st alarm was paused, so the next due time is updated to
       
   511 	// the end of the pause period (1 minute for console alarm alert server)
       
   512 	testTimesEqual(alarm1.NextDueTime(), alarm1time + TTimeIntervalMinutes(1));
       
   513 	TheAlarmTest(alarm2.NextDueTime() == alarm2time, __LINE__);
       
   514 
       
   515 	// tidy up
       
   516 	TheAlarmTest(TheAlarmServerSession.AlarmDelete(id1) == KErrNone, __LINE__);
       
   517 	TheAlarmTest(TheAlarmServerSession.AlarmDelete(id2) == KErrNone, __LINE__);
       
   518 	WaitForNotificationBufferToBeEmptied();
       
   519 #endif
       
   520 	}
       
   521 
       
   522 //
       
   523 
       
   524 	
       
   525 static void CreateUtcAlarmsForPausingL()
       
   526 	{
       
   527 #ifdef __WINS__
       
   528 	TestClearStoreL();
       
   529 
       
   530 	TheAlarmTest.Next(_L("Test pausing alarm sounds"));
       
   531 	//
       
   532 	// Add an alarm, due in 3 seconds
       
   533 	TASShdAlarm alarm;
       
   534 	TTime time;
       
   535 	time.UniversalTime();
       
   536 	time += TTimeIntervalSeconds(3);
       
   537 	/*
       
   538 	_LIT(KFormatTime,"%D %H:%T:%S.   ");
       
   539 	TBuf<128> timeTxt;
       
   540 	time.FormatL(timeTxt,KFormatTime);
       
   541 	*/
       
   542 	alarm.SetUtcNextDueTime(time);
       
   543 	TheAlarmTest(TheAlarmServerSession.AlarmAdd(alarm) == KErrNone, __LINE__);
       
   544 	const TAlarmId id = alarm.Id();
       
   545 	TheAlarmTest(id != KNullAlarmId, __LINE__);
       
   546 	// Wait for the alarm to go off, and be paused
       
   547 	User::After(5 * 1000000);
       
   548 
       
   549 	// The alarm should still be notifying
       
   550 	TheAlarmTest(TheAlarmServerSession.GetAlarmDetails(id, alarm) == KErrNone, __LINE__);
       
   551 	TheAlarmTest(alarm.State() == EAlarmStateNotifying, __LINE__);
       
   552 	TheAlarmTest(TheAlarmServerSession.AlarmDelete(id) == KErrNone, __LINE__);
       
   553 
       
   554 	// Add 2 alarms, due in 3 and 13 seconds
       
   555 	TTime alarm1time;
       
   556 	TTime alarm2time;
       
   557 	alarm1time.UniversalTime();
       
   558 	alarm1time += TTimeIntervalSeconds(3);
       
   559 	alarm2time = alarm1time + TTimeIntervalSeconds(10);
       
   560 
       
   561 	TASShdAlarm alarm1;
       
   562 	alarm1.SetUtcNextDueTime(alarm1time);
       
   563 	alarm1.Message()=(_L("alarm 1"));
       
   564 	TASShdAlarm alarm2;
       
   565 	alarm2.SetUtcNextDueTime(alarm2time);
       
   566 	alarm2.Message()=(_L("alarm 2"));
       
   567 
       
   568 	TheAlarmTest(TheAlarmServerSession.AlarmAdd(alarm1) == KErrNone, __LINE__);
       
   569 	const TAlarmId id1 = alarm1.Id();
       
   570 	TheAlarmTest(id1 != KNullAlarmId, __LINE__);
       
   571 	TheAlarmTest(TheAlarmServerSession.AlarmAdd(alarm2) == KErrNone, __LINE__);
       
   572 	const TAlarmId id2 = alarm2.Id();
       
   573 	TheAlarmTest(id2 != KNullAlarmId, __LINE__);
       
   574 	//
       
   575 	// Wait for the 1st alarm to go off, and be paused
       
   576 	User::After(5 * 1000000);
       
   577 
       
   578 	// The 1st alarm should still be notifying
       
   579 	alarm1.Reset();
       
   580 	TheAlarmTest(TheAlarmServerSession.GetAlarmDetails(id1, alarm1) == KErrNone, __LINE__);
       
   581 	// delete below
       
   582 	TheAlarmTest(TheAlarmServerSession.GetAlarmDetails(id2, alarm2) == KErrNone, __LINE__);
       
   583 	TheAlarmTest(alarm1.State() == EAlarmStateNotifying, __LINE__);
       
   584 
       
   585 	// Wait for the time the 2nd alarm is due
       
   586 	User::After(10 * 1000000);
       
   587 	// The 1st alarm should be moved to snoozed, so as not to block the 2nd one
       
   588 	alarm1.Reset();
       
   589 	alarm2.Reset();
       
   590 	TheAlarmTest(TheAlarmServerSession.GetAlarmDetails(id1, alarm1) == KErrNone, __LINE__);
       
   591 	TheAlarmTest(TheAlarmServerSession.GetAlarmDetails(id2, alarm2) == KErrNone, __LINE__);
       
   592 	TheAlarmTest.Test().Printf(_L("\tALARM1 State => %u \n"),alarm1.State());
       
   593 	TheAlarmTest.Test().Printf(_L("\tALARM2 State => %u \n"),alarm2.State());
       
   594 	TheAlarmTest(alarm1.State() == EAlarmStateSnoozed, __LINE__);
       
   595 	TheAlarmTest(alarm2.State() == EAlarmStateNotified, __LINE__);
       
   596 	// the 1st alarm was paused, so the next due time is updated to
       
   597 	// the end of the pause period (1 minute for console alarm alert server)
       
   598 	testTimesEqual(alarm1.NextDueTime(), alarm1time + TTimeIntervalMinutes(1));
       
   599 	TheAlarmTest(alarm2.NextDueTime() == alarm2time, __LINE__);
       
   600 
       
   601 	// tidy up
       
   602 	TheAlarmTest(TheAlarmServerSession.AlarmDelete(id1) == KErrNone, __LINE__);
       
   603 	TheAlarmTest(TheAlarmServerSession.AlarmDelete(id2) == KErrNone, __LINE__);
       
   604 	WaitForNotificationBufferToBeEmptied();
       
   605 #endif
       
   606 	}
       
   607 
       
   608 
       
   609 static void CreateSingleUtcAlarmL()
       
   610 	{
       
   611 #ifdef __WINS__
       
   612 
       
   613 	
       
   614 	TheAlarmTest.Next(_L("Adding disabled alarm"));
       
   615 	//
       
   616 	TASShdAlarm alarm;
       
   617 	alarm.Category()=KASCliCategoryClock;
       
   618 	alarm.RepeatDefinition()=EAlarmRepeatDefintionRepeatDaily;
       
   619 	alarm.Message()=(_L("This is an alarm message - alarm 1"));
       
   620 	TTime time;
       
   621 	time.UniversalTime();
       
   622 	time += TTimeIntervalMinutes(1);
       
   623 	alarm.SetUtcNextDueTime(time);
       
   624 	alarm.SoundName()=(_L("Arf Arf Woop"));
       
   625 	//
       
   626 	TTime now;
       
   627 	now.HomeTime();
       
   628 //	TDateTime nowDT = now.DateTime();
       
   629 //	TDateTime dueDT = alarm.NextDueTime().DateTime();
       
   630 	//
       
   631 	TheAlarmTest(TheAlarmServerSession.AlarmAdd(alarm) == KErrNone, __LINE__);
       
   632 	const TAlarmId id = alarm.Id();
       
   633 	TheAlarmTest(id != KNullAlarmId, __LINE__);
       
   634 
       
   635 	//
       
   636 	
       
   637 	TheAlarmTest.Next(_L("Get alarm details"));
       
   638 	TheAlarmTest(TheAlarmServerSession.GetAlarmDetails(id, alarm) == KErrNone, __LINE__);
       
   639 
       
   640 	//
       
   641 	
       
   642 	
       
   643 	TheAlarmTest.Next(_L("Enabling a disabled alarm"));
       
   644 	TheAlarmTest(TheAlarmServerSession.SetAlarmStatus(id, EAlarmStatusEnabled) == KErrNone, __LINE__);
       
   645 
       
   646 	//
       
   647 	
       
   648 	
       
   649 	TheAlarmTest.Next(_L("Waiting for alarm to expire..."));
       
   650 
       
   651 	TAlarmId alarmId;
       
   652 	TRequestStatus status;
       
   653 	FOREVER
       
   654 		{
       
   655 		TheAlarmServerSession.NotifyChange(status, alarmId);
       
   656 		User::WaitForRequest(status);
       
   657 		if	(status.Int() == EAlarmChangeEventTimerExpired)
       
   658 			{
       
   659 			TheAlarmTest(id == alarmId, __LINE__);
       
   660 			break;
       
   661 			}
       
   662 		}
       
   663 #endif
       
   664 	}
       
   665 
       
   666 
       
   667 static void CreateNotificationUtcAlarmL()
       
   668 	{
       
   669 	TheAlarmTest.Next(_L("Creating notification alarm"));
       
   670 
       
   671 	// AlarmAddWithNotification
       
   672 	TASShdAlarm alarm;
       
   673 	TTime time;
       
   674 	time.UniversalTime();
       
   675 	time += TTimeIntervalMinutes(1);
       
   676 	alarm.SetUtcNextDueTime(time);
       
   677 	TRequestStatus status;
       
   678 	TheAlarmServerSession.AlarmAddWithNotification(status, alarm);
       
   679 	TAlarmId id = alarm.Id();
       
   680 	TheAlarmTest(id != KNullAlarmId, __LINE__);
       
   681 	TheAlarmTest(status == KRequestPending, __LINE__);
       
   682 
       
   683 	// Wait for completion
       
   684 	TheAlarmTest(TheAlarmServerSession.SetAlarmStatus(id, EAlarmStatusEnabled) == KErrNone, __LINE__);
       
   685 	User::WaitForRequest(status);
       
   686 
       
   687 	// AlarmNotificationCancel
       
   688 	time.UniversalTime();
       
   689 	time += TTimeIntervalMinutes(1);
       
   690 	alarm.SetUtcNextDueTime(time);
       
   691 	TheAlarmServerSession.AlarmAddWithNotification(status, alarm);
       
   692 	id = alarm.Id();
       
   693 	TheAlarmTest(id != KNullAlarmId, __LINE__);
       
   694 	TheAlarmTest(status == KRequestPending, __LINE__);
       
   695 	TheAlarmServerSession.AlarmNotificationCancelAndDequeue(id);
       
   696 
       
   697 	// Eat request
       
   698 	User::WaitForRequest(status);
       
   699 	TheAlarmTest(status == KErrCancel, __LINE__);
       
   700 	}
       
   701 
       
   702 	
       
   703 static void CreateDailyRepeatingUtcAlarmL()
       
   704 	{
       
   705 	TheAlarmTest.Next(_L("Creating daily repeating alarm"));
       
   706 
       
   707 	// AlarmAddWithNotification
       
   708 	TASShdAlarm alarm;
       
   709 	TTime time;
       
   710 	time.UniversalTime();
       
   711 	time += TTimeIntervalMinutes(1);
       
   712 	alarm.SetUtcNextDueTime(time);
       
   713 	alarm.RepeatDefinition()=EAlarmRepeatDefintionRepeatDaily;
       
   714 
       
   715 	TheAlarmServerSession.AlarmAdd(alarm);
       
   716 	TAlarmId id = alarm.Id();
       
   717 	TheAlarmTest(id != KNullAlarmId, __LINE__);
       
   718 
       
   719 	TAlarmId alarmId;
       
   720 	TRequestStatus status;
       
   721 	TheAlarmServerSession.NotifyChange(status, alarmId);
       
   722 	TheAlarmTest(TheAlarmServerSession.SetAlarmStatus(id, EAlarmStatusEnabled) == KErrNone, __LINE__);
       
   723 	User::WaitForRequest(status);
       
   724 	}
       
   725 
       
   726 
       
   727 //*************************************************************************************
       
   728 // defect INC082426
       
   729 
       
   730 #if defined(_DEBUG) && defined(__WINS__)
       
   731 static void CreateAlarmAndSnoozeL(TAlarmRepeatDefinition aRepeatDef)
       
   732 	{
       
   733 	TestClearStoreL();
       
   734 
       
   735 	
       
   736 	TheAlarmTest.Next(_L("Adding alarm and snooze it"));
       
   737 
       
   738 
       
   739 	//
       
   740 	TASShdAlarm alarm;
       
   741 	alarm.Category() = KASCliCategoryClock;
       
   742 	alarm.RepeatDefinition() = aRepeatDef;
       
   743 	alarm.Message() = _L("This is an alarm message - alarm to snooze");
       
   744 
       
   745 	TTime now1;
       
   746 	now1.UniversalTime();
       
   747 	now1 += TTimeIntervalMinutes(1);
       
   748 	alarm.SetUtcNextDueTime(now1);
       
   749 	alarm.SoundName() = _L("Hic hic");
       
   750 
       
   751 	//
       
   752 	TheAlarmTest(TheAlarmServerSession.AlarmAdd(alarm) == KErrNone, __LINE__);
       
   753 	const TAlarmId id = alarm.Id();
       
   754 	TheAlarmTest(id != KNullAlarmId, __LINE__);
       
   755 
       
   756 	
       
   757 	TheAlarmTest.Next(_L("Get alarm details"));
       
   758 	TheAlarmTest(TheAlarmServerSession.GetAlarmDetails(id, alarm) == KErrNone, __LINE__);
       
   759 
       
   760 	//
       
   761 	
       
   762 	TheAlarmTest.Next(_L("Enabling a disabled alarm"));
       
   763 	TheAlarmTest(TheAlarmServerSession.SetAlarmStatus(id, EAlarmStatusEnabled) == KErrNone, __LINE__);
       
   764 
       
   765 	
       
   766 	TheAlarmTest.Next(_L("Waiting for alarm to expire..."));
       
   767 
       
   768 	TAlarmId alarmId;
       
   769 	TRequestStatus status;
       
   770 
       
   771 
       
   772 	FOREVER
       
   773 		{
       
   774 		TheAlarmServerSession.NotifyChange(status, alarmId);
       
   775 		User::WaitForRequest(status);
       
   776 
       
   777 		if	(status.Int() == EAlarmChangeEventTimerExpired)
       
   778 			{
       
   779 			TheAlarmTest(id == alarmId, __LINE__);
       
   780 			break;
       
   781 			}
       
   782 		}
       
   783 
       
   784 		
       
   785 	
       
   786 	TheAlarmTest.Next(_L("Alarm expired"));
       
   787 
       
   788 	TBuf<100> buf;
       
   789 
       
   790 	TheAlarmTest(TheAlarmServerSession.GetAlarmDetails(id, alarm) == KErrNone, __LINE__);
       
   791 	TheAlarmTest(alarm.State() == EAlarmStateNotifying, __LINE__);
       
   792 	alarm.OriginalExpiryTime().FormatL(buf, _L("OriginalExpiryTime: %D %H:%T:%S\n"));
       
   793 	TheAlarmTest.Test().Printf(buf);
       
   794 	alarm.NextDueTime().FormatL(buf, _L("NextDueTime: %D %H:%T:%S\n"));
       
   795 	TheAlarmTest.Test().Printf(buf);
       
   796 
       
   797 	TheAlarmTest.Next(_L("Snooze alarm"));
       
   798 
       
   799 	TTime snooze(alarm.NextDueTime());
       
   800 	snooze += TTimeIntervalMinutes(2);
       
   801 	TInt r = TheAlarmServerSession.__DbgSnoozeAlarm(id, snooze);
       
   802 	TheAlarmTest(r == KErrNone, __LINE__);
       
   803 
       
   804 
       
   805 	// check the state is the correct one
       
   806 
       
   807 	TheAlarmTest(TheAlarmServerSession.GetAlarmDetails(id, alarm) == KErrNone, __LINE__);
       
   808 	TheAlarmTest(alarm.State() == EAlarmStateSnoozed, __LINE__);
       
   809 	alarm.OriginalExpiryTime().FormatL(buf, _L("OriginalExpiryTime: %D %H:%T:%S\n"));
       
   810 	TheAlarmTest.Test().Printf(buf);
       
   811 	alarm.NextDueTime().FormatL(buf, _L("NextDueTime: %D %H:%T:%S\n"));
       
   812 	TheAlarmTest.Test().Printf(buf);
       
   813 
       
   814 	TheAlarmTest((alarm.OriginalExpiryTime() + TTimeIntervalMinutes(2)) == alarm.NextDueTime(), __LINE__);
       
   815 
       
   816 
       
   817 	FOREVER
       
   818 		{
       
   819 		TheAlarmServerSession.NotifyChange(status, alarmId);
       
   820 		User::WaitForRequest(status);
       
   821 
       
   822 		if (status.Int() == EAlarmChangeEventSoundStopped)
       
   823 			{
       
   824 			TheAlarmTest(id == alarmId, __LINE__);
       
   825 			break;
       
   826 			}
       
   827 		}
       
   828 
       
   829 
       
   830 	// check the state is the correct one
       
   831 
       
   832 	TheAlarmTest(TheAlarmServerSession.GetAlarmDetails(id, alarm) == KErrNone, __LINE__);
       
   833 
       
   834 	alarm.OriginalExpiryTime().FormatL(buf, _L("OriginalExpiryTime: %D %H:%T:%S\n"));
       
   835 	TheAlarmTest.Test().Printf(buf);
       
   836 	alarm.NextDueTime().FormatL(buf, _L("NextDueTime: %D %H:%T:%S\n"));
       
   837 	TheAlarmTest.Test().Printf(buf);
       
   838 
       
   839 	TheAlarmTest(alarm.State() == EAlarmStateSnoozed, __LINE__);
       
   840 	TheAlarmTest((alarm.OriginalExpiryTime() + TTimeIntervalMinutes(2)) == alarm.NextDueTime(), __LINE__);
       
   841 
       
   842 	//wait for the alarm to expire
       
   843 	FOREVER
       
   844 		{
       
   845 		TheAlarmServerSession.NotifyChange(status, alarmId);
       
   846 		User::WaitForRequest(status);
       
   847 
       
   848 		if (status.Int() == EAlarmChangeEventTimerExpired)
       
   849 			{
       
   850 			TheAlarmTest(id == alarmId, __LINE__);
       
   851 			break;
       
   852 			}
       
   853 		}
       
   854 
       
   855 	TheAlarmTest(TheAlarmServerSession.GetAlarmDetails(id, alarm) == KErrNone, __LINE__);
       
   856 
       
   857 	alarm.OriginalExpiryTime().FormatL(buf, _L("OriginalExpiryTime: %D %H:%T:%S\n"));
       
   858 	TheAlarmTest.Test().Printf(buf);
       
   859 	alarm.NextDueTime().FormatL(buf, _L("NextDueTime: %D %H:%T:%S\n"));
       
   860 	TheAlarmTest.Test().Printf(buf);
       
   861 
       
   862 	TheAlarmTest(alarm.State() == EAlarmStateNotifying, __LINE__);
       
   863 	TheAlarmTest((alarm.OriginalExpiryTime() + TTimeIntervalMinutes(2)) == alarm.NextDueTime(), __LINE__);
       
   864 	}
       
   865 #endif
       
   866 
       
   867 //*************************************************************************************
       
   868 //
       
   869 // Using the RepeatDefinition passed in  aRepeatDef,
       
   870 //
       
   871 // Create an alarm
       
   872 // Use NextDueTime() to set the expiry time
       
   873 // Add alarm to server
       
   874 // Wait for alarm to expire
       
   875 // Snooze alarm using __DbgSnoozeAlarm() API
       
   876 // Retrieve alarm details from server
       
   877 // Test that the alarm snooze time was set correctly
       
   878 // Delete the alarm
       
   879 //
       
   880 // Repeat this using SetUtcNextDueTime() to set the original
       
   881 // expiry time
       
   882 //
       
   883 // NOTE: __DbgSnoozeAlarm expects time to be passed as UTC,
       
   884 //       depending how NextDueTime() was set, the time may have to be
       
   885 //       adjusted by removing the UTC offset
       
   886 //
       
   887 // Instigated by DEF083031
       
   888 //
       
   889 //*************************************************************************************
       
   890 #if defined(_DEBUG) && defined(__WINS__)
       
   891 
       
   892 static void DbgSnoozeAlarmSetsTimeCorrectlyL(TAlarmRepeatDefinition aRepeatDef)
       
   893         {
       
   894 			
       
   895 			
       
   896            TheAlarmTest.Next(_L("Checking DbgSnoozeTime with NextDueTime"));
       
   897            TASShdAlarm alarm;
       
   898            alarm.RepeatDefinition() = aRepeatDef;
       
   899            TTime now;
       
   900            now.HomeTime();  //using local time representation
       
   901 
       
   902            //      eliminate secs and usecs -- simplifies TTime comparison
       
   903            now.RoundUpToNextMinute();
       
   904 
       
   905            alarm.NextDueTime() = now;
       
   906 
       
   907            //      set alarm time one minute in future
       
   908            alarm.NextDueTime()+= TTimeIntervalMinutes(1);
       
   909 
       
   910            //      server adds alarm
       
   911            AlarmTest(TheAlarmServerSession.AlarmAdd(alarm) == KErrNone);
       
   912 
       
   913            //      wait for alarm to expire
       
   914            TAlarmId checkID;
       
   915            TRequestStatus status;
       
   916 
       
   917            FOREVER
       
   918            {
       
   919               TheAlarmServerSession.NotifyChange(status, checkID);
       
   920               User::WaitForRequest(status);
       
   921               if (status.Int() == EAlarmChangeEventTimerExpired)
       
   922                 {
       
   923                    AlarmTest(alarm.Id() == checkID);
       
   924                    break;
       
   925                 }
       
   926            }
       
   927 
       
   928            TTime snoozeTime = alarm.NextDueTime();
       
   929 
       
   930            //      set snooze for two minutes in future
       
   931            snoozeTime+= TTimeIntervalMinutes(2);
       
   932 
       
   933            // *** important bit ***
       
   934            //=====================================================
       
   935            //  snooze alarm
       
   936            //
       
   937            //  NOTE:  time passed to __DbgSnoozeAlarm must be UTC
       
   938            //  must 'undo' the offset within local time first
       
   939            //=====================================================
       
   940            AlarmTest(TheAlarmServerSession.__DbgSnoozeAlarm(alarm.Id(), snoozeTime - User::UTCOffset()) == KErrNone);
       
   941 
       
   942            //      server's view of alarm retrieved
       
   943            AlarmTest(TheAlarmServerSession.GetAlarmDetails(alarm.Id(), alarm) == KErrNone);
       
   944 
       
   945            //      check the time for the alarm
       
   946            AlarmTest(alarm.NextDueTime() == snoozeTime);
       
   947 
       
   948            // cleanup
       
   949            AlarmTest(TheAlarmServerSession.AlarmDelete(alarm.Id()) == KErrNone);
       
   950 
       
   951 		   
       
   952            TheAlarmTest.Next(_L("Checking DbgSnoozeTime with SetUtcNextDueTime"));
       
   953            now.UniversalTime();   //using UTC time representation
       
   954            now.RoundUpToNextMinute();
       
   955 
       
   956            alarm.SetUtcNextDueTime(now);
       
   957 
       
   958            //      set alarm time one minute in future
       
   959            alarm.NextDueTime() += TTimeIntervalMinutes(1);
       
   960 
       
   961            //      server adds alarm
       
   962            AlarmTest(TheAlarmServerSession.AlarmAdd(alarm) == KErrNone);
       
   963 
       
   964            //      wait for alarm to expire
       
   965            FOREVER
       
   966            {
       
   967               TheAlarmServerSession.NotifyChange(status, checkID);
       
   968               User::WaitForRequest(status);
       
   969               if (status.Int() == EAlarmChangeEventTimerExpired)
       
   970                 {
       
   971                    AlarmTest(alarm.Id() == checkID);
       
   972                    break;
       
   973                 }
       
   974           }
       
   975 
       
   976           snoozeTime = alarm.NextDueTime();
       
   977 
       
   978           //      set snooze for one hour and four minutes in future
       
   979           snoozeTime+= TTimeIntervalMinutes(4);
       
   980           snoozeTime+= TTimeIntervalHours(1);
       
   981 
       
   982           // *** important bit ***
       
   983           //=====================================================
       
   984           //  snooze alarm
       
   985           //
       
   986           //  NOTE:  time passed to __DbgSnoozeAlarm must be UTC
       
   987           //=====================================================
       
   988           AlarmTest(TheAlarmServerSession.__DbgSnoozeAlarm(alarm.Id(), snoozeTime) == KErrNone);
       
   989 
       
   990           //      server's view of alarm retrieved
       
   991           AlarmTest(TheAlarmServerSession.GetAlarmDetails(alarm.Id(), alarm) == KErrNone);
       
   992 
       
   993           //      check the time for the alarm
       
   994           AlarmTest(alarm.NextDueTime() == snoozeTime);
       
   995 
       
   996           // cleanup
       
   997           AlarmTest(TheAlarmServerSession.AlarmDelete(alarm.Id()) == KErrNone);
       
   998 
       
   999     }// end DbgSnoozeAlarmSetsTimeCorrectlyL
       
  1000 
       
  1001 #endif
       
  1002 
       
  1003 static void TestWorkdaysRepeatingAlarmL()
       
  1004     {
       
  1005     const TInt KGmtOffset = 3600;//London summer offset
       
  1006     _LIT(KBaselineTime, "20060416:225900.000000"); //In summer time
       
  1007     User::SetUTCTimeAndOffset(TTime(KBaselineTime), KGmtOffset);
       
  1008 
       
  1009     TestClearStoreL();
       
  1010 
       
  1011 	
       
  1012     TheAlarmTest.Next(_L("Adding repeating alarm"));
       
  1013 
       
  1014     //
       
  1015     TASShdAlarm alarm;
       
  1016     alarm.Category() = KASCliCategoryClock;
       
  1017     alarm.RepeatDefinition() = EAlarmRepeatDefintionRepeatWorkday;
       
  1018     alarm.Message() = _L("This is an alarm message");
       
  1019 
       
  1020     TTime now1;
       
  1021     now1.UniversalTime();
       
  1022     now1 += TTimeIntervalMinutes(2);//step over the midnight
       
  1023     alarm.SetUtcNextDueTime(now1);
       
  1024     alarm.SoundName() = _L("Hic hic");
       
  1025 
       
  1026     //
       
  1027     TheAlarmTest(TheAlarmServerSession.AlarmAdd(alarm) == KErrNone, __LINE__);
       
  1028     const TAlarmId id = alarm.Id();
       
  1029     TheAlarmTest(id != KNullAlarmId, __LINE__);
       
  1030 
       
  1031     
       
  1032     TheAlarmTest.Next(_L("Get alarm details"));
       
  1033     TheAlarmTest(TheAlarmServerSession.GetAlarmDetails(id, alarm) == KErrNone, __LINE__);
       
  1034 
       
  1035     
       
  1036     TheAlarmTest.Next(_L("Enabling a disabled alarm"));
       
  1037     TheAlarmTest(TheAlarmServerSession.SetAlarmStatus(id, EAlarmStatusEnabled) == KErrNone, __LINE__);
       
  1038 
       
  1039     	
       
  1040     TheAlarmTest.Next(_L("Waiting for alarm to expire..."));
       
  1041 
       
  1042     TAlarmId alarmId;
       
  1043     TRequestStatus status;
       
  1044 
       
  1045 
       
  1046     FOREVER
       
  1047         {
       
  1048         TheAlarmServerSession.NotifyChange(status, alarmId);
       
  1049         User::WaitForRequest(status);
       
  1050 #ifdef __PRINTDEBUGGING__
       
  1051         PrintEventDetails(status.Int());
       
  1052 #endif
       
  1053         if    (status.Int() == EAlarmChangeEventTimerExpired)
       
  1054             {
       
  1055             TheAlarmTest(id == alarmId, __LINE__);
       
  1056             break;
       
  1057             }
       
  1058         }
       
  1059 
       
  1060 		
       
  1061 	
       
  1062     TheAlarmTest.Next(_L("Alarm expired"));
       
  1063 
       
  1064     TBuf<100> buf;
       
  1065 
       
  1066     TheAlarmTest(TheAlarmServerSession.GetAlarmDetails(id, alarm) == KErrNone, __LINE__);
       
  1067     TheAlarmTest(alarm.State() == EAlarmStateNotifying, __LINE__);
       
  1068     TTime dueTime = alarm.NextDueTime();
       
  1069     alarm.OriginalExpiryTime().FormatL(buf, _L("OriginalExpiryTime: %D %H:%T:%S\n"));
       
  1070     TheAlarmTest.Test().Printf(buf);
       
  1071     alarm.NextDueTime().FormatL(buf, _L("NextDueTime: %D %H:%T:%S\n"));
       
  1072     TheAlarmTest.Test().Printf(buf);
       
  1073 
       
  1074     //Press 'Done'
       
  1075     TheAlarmServerSession.SetAlarmStatus(alarm.Id(), EAlarmStatusDisabled);
       
  1076     TheAlarmServerSession.SetAlarmStatus(alarm.Id(), EAlarmStatusEnabled);
       
  1077 
       
  1078     TheAlarmTest(TheAlarmServerSession.GetAlarmDetails(id, alarm) == KErrNone, __LINE__);
       
  1079     TTime newDueTime = alarm.NextDueTime();
       
  1080 
       
  1081     TheAlarmTest(newDueTime > dueTime);//the alarm was rescheduled
       
  1082 
       
  1083     }
       
  1084 
       
  1085 /**
       
  1086 Create an alarm that repeats on given days of the week.
       
  1087 Change the days on which a repeating alarm expires.
       
  1088 
       
  1089 @SYMTestCaseID		PIM-APPSRV-ALARMSERVER-WEEKLYGIVENDAYS-0001
       
  1090 										
       
  1091 @SYMTestCaseDesc	To verify that is possible to create an
       
  1092  					alarm that repeats on the same days every week.
       
  1093  					
       
  1094  					To verify that is possible to change the days 
       
  1095  					on which an alarm that repeats on the same 
       
  1096  					days every week will expire after it has been
       
  1097  					created.    
       
  1098 
       
  1099 @SYMTestActions 
       
  1100 For PIM-APPSRV-ALARMSERVER-WEEKLYGIVENDAYS-0001:   
       
  1101 1.	Create an alarm that repeats on Tuesday and Wednesday every week. [1]
       
  1102 
       
  1103 For PIM-APPSRV-ALARMSERVER-WEEKLYGIVENDAYS-0002:
       
  1104 1.	Create an alarm that repeats on Tuesday and Wednesday every week.
       
  1105 2. 	Update the days on which it expires to Friday. [2]
       
  1106 
       
  1107 @SYMTestExpectedResults [1] The alarm is created and expires on the 
       
  1108 							given days each week.
       
  1109 							
       
  1110 						[2] The alarm is updated and expires on the
       
  1111 						 	expected days each week.
       
  1112 
       
  1113 @SYMTestType                CT
       
  1114 @SYMTestPriority            1
       
  1115 */
       
  1116 void TestDailyOnGivenDaysAlarmExpiryL(void)
       
  1117 	{
       
  1118 #ifdef SYMBIAN_ALARM_REPEAT_EXTENSIONS
       
  1119 #if defined(_DEBUG) && defined(__WINS__)
       
  1120 	TheAlarmTest.Next(_L("@SYMTestCaseID PIM-APPSRV-ALARMSERVER-WEEKLYGIVENDAYS-0001   Test 'Daily On Given Days' Alarm Expiry"));
       
  1121 
       
  1122 	RANTestClient conAlarmAlertSrvSession;
       
  1123 	User::LeaveIfError(conAlarmAlertSrvSession.Connect());
       
  1124 	User::LeaveIfError(conAlarmAlertSrvSession.SetExtendedMode());
       
  1125 	CleanupClosePushL(conAlarmAlertSrvSession);
       
  1126 
       
  1127 	// Set baseline time.  This date/time falls on a Tuesday.
       
  1128 	_LIT(KBaselineTime, "20080000:120055");
       
  1129 	TheAlarmTest(User::SetUTCTimeAndOffset(TTime(KBaselineTime), 0) == KErrNone, __LINE__);
       
  1130 
       
  1131 	TTime now;
       
  1132 	now.HomeTime();
       
  1133 	PrintTimeL(now, _L("Current date/time is: "));
       
  1134 
       
  1135 	// Create a 'daily on given days' alarm that is active on Tuesday and
       
  1136 	// Wednesday of each week and that expires at 12:01pm (5 seconds from
       
  1137 	// baseline time).
       
  1138 	TASShdAlarm alarm;
       
  1139 	alarm.RepeatDefinition() = EAlarmRepeatDefinitionRepeatDailyOnGivenDays;
       
  1140 	alarm.SetAlarmDays(EAlarmDayTuesday | EAlarmDayWednesday);
       
  1141 	alarm.NextDueTime() = TTime(KBaselineTime) + TTimeIntervalSeconds(5);
       
  1142 	
       
  1143 	TheAlarmTest(TheAlarmServerSession.AlarmAdd(alarm) == KErrNone, __LINE__);
       
  1144 	const TAlarmId id = alarm.Id();
       
  1145 	TheAlarmTest(id != KNullAlarmId, __LINE__);
       
  1146 
       
  1147 	TheAlarmTest(TheAlarmServerSession.GetAlarmDetails(id, alarm) == KErrNone, __LINE__);
       
  1148 	PrintTimeL(alarm.NextDueTime(), _L("Alarm's next due date/time is: "));
       
  1149 	
       
  1150 	TheAlarmTest.Next(_L("Waiting for Tuesday alarm to expire..."));
       
  1151 	TRequestStatus status;
       
  1152 	conAlarmAlertSrvSession.NotifyOnAlarm(alarm, status);
       
  1153 	User::WaitForRequest(status);
       
  1154 	now.HomeTime();
       
  1155 	PrintTimeL(now, _L("Date/time of alarm expiry: "));
       
  1156 	TheAlarmTest(TheAlarmServerSession.GetAlarmDetails(id, alarm) == KErrNone, __LINE__);
       
  1157 	TheAlarmTest(alarm.NextDueTime().DayNoInWeek() == ETuesday);
       
  1158 	conAlarmAlertSrvSession.AcknowledgeAlarm(id);
       
  1159     
       
  1160     // Advance baseline time by 1 day to Wednesday.
       
  1161 	TheAlarmTest(User::SetUTCTimeAndOffset(TTime(KBaselineTime) +
       
  1162 		TTimeIntervalDays(1), 0) == KErrNone, __LINE__);
       
  1163 	now.HomeTime();
       
  1164 	PrintTimeL(now, _L("Current date/time is: "));
       
  1165 
       
  1166 	TheAlarmTest(TheAlarmServerSession.GetAlarmDetails(id, alarm) == KErrNone,
       
  1167 		__LINE__);
       
  1168 	PrintTimeL(alarm.NextDueTime(), _L("Alarm's next due date/time is: "));
       
  1169 
       
  1170 	TheAlarmTest.Next(_L("Waiting for Wednesday alarm to expire..."));
       
  1171 	conAlarmAlertSrvSession.NotifyOnAlarm(alarm, status);
       
  1172 	User::WaitForRequest(status);
       
  1173 	now.HomeTime();
       
  1174 	PrintTimeL(now, _L("Date/time of alarm expiry: "));
       
  1175 	TheAlarmTest(TheAlarmServerSession.GetAlarmDetails(id, alarm) == KErrNone,
       
  1176 			__LINE__);
       
  1177 	TheAlarmTest(alarm.NextDueTime().DayNoInWeek() == EWednesday);
       
  1178 	conAlarmAlertSrvSession.AcknowledgeAlarm(id);
       
  1179 
       
  1180     // Advance baseline time by 7 days to the following Tuesday to check that
       
  1181 	// subsequent repeat of the first active alarm day works. 
       
  1182 	TheAlarmTest(User::SetUTCTimeAndOffset(TTime(KBaselineTime) +
       
  1183 		TTimeIntervalDays(7), 0) == KErrNone, __LINE__);
       
  1184 	now.HomeTime();
       
  1185 	PrintTimeL(now, _L("Current date/time is: "));
       
  1186 
       
  1187 	TheAlarmTest(TheAlarmServerSession.GetAlarmDetails(id, alarm) == KErrNone,
       
  1188 		__LINE__);
       
  1189 	PrintTimeL(alarm.NextDueTime(), _L("Alarm's next due date/time is: "));
       
  1190 
       
  1191 	TheAlarmTest.Next(_L("Waiting for following Tuesday alarm to expire..."));
       
  1192 	conAlarmAlertSrvSession.NotifyOnAlarm(alarm, status);
       
  1193 	User::WaitForRequest(status);
       
  1194 	now.HomeTime();
       
  1195 	PrintTimeL(now, _L("Date/time of alarm expiry: "));
       
  1196 	TheAlarmTest(TheAlarmServerSession.GetAlarmDetails(id, alarm) == KErrNone,
       
  1197 			__LINE__);
       
  1198 	TheAlarmTest(alarm.NextDueTime().DayNoInWeek() == ETuesday);
       
  1199 	conAlarmAlertSrvSession.AcknowledgeAlarm(id);
       
  1200 	
       
  1201 	// Update alarm's active days to Friday only and check that the next day
       
  1202 	// that the alarm expires on is Friday not Wednesday. 
       
  1203 	TheAlarmTest(TheAlarmServerSession.SetAlarmDays(id, EAlarmDayFriday) ==
       
  1204 	    KErrNone, __LINE__);
       
  1205 	
       
  1206 	TheAlarmTest(TheAlarmServerSession.GetAlarmDetails(id, alarm) == KErrNone,
       
  1207 		__LINE__);
       
  1208 	PrintTimeL(alarm.NextDueTime(), _L("Alarm's next due date/time is: "));
       
  1209 
       
  1210     // Advance baseline time by 10 days to the following Friday to check that
       
  1211 	// the previous active day of Wednesday does not cause an alarm to expire
       
  1212 	// on that day and the expiry happens on Friday. 
       
  1213 	TheAlarmTest(User::SetUTCTimeAndOffset(TTime(KBaselineTime) +
       
  1214 		TTimeIntervalDays(10), 0) == KErrNone, __LINE__);
       
  1215 	now.HomeTime();
       
  1216 	PrintTimeL(now, _L("Current date/time is: "));
       
  1217 
       
  1218 	TheAlarmTest.Next(_L(" @SYMTestCaseID Waiting for Friday's alarm to expire..."));
       
  1219 	conAlarmAlertSrvSession.NotifyOnAlarm(alarm, status);
       
  1220 	User::WaitForRequest(status);
       
  1221 	now.HomeTime();
       
  1222 	PrintTimeL(now, _L("Date/time of alarm expiry: "));
       
  1223 	TheAlarmTest(TheAlarmServerSession.GetAlarmDetails(id, alarm) == KErrNone,
       
  1224 			__LINE__);
       
  1225 	TheAlarmTest(alarm.NextDueTime().DayNoInWeek() == EFriday);
       
  1226 	conAlarmAlertSrvSession.AcknowledgeAlarm(id);
       
  1227     
       
  1228 	conAlarmAlertSrvSession.UnsetExtendedMode();
       
  1229 	CleanupStack::PopAndDestroy();
       
  1230 #else
       
  1231     TheAlarmTest.Test().Printf(_L("THIS TEST IS A DEBUG, WINS TEST ONLY\r\n"));
       
  1232 #endif
       
  1233 #endif
       
  1234 	}
       
  1235 
       
  1236 /** Create an alarm that plays continuously.
       
  1237 @SYMTestCaseID		PIM-APPSRV-ALARMSERVER-CONTINUOUS-0001
       
  1238 @SYMTestCaseDesc	To verify that it is possible to 
       
  1239 					create an alarm that plays continuously.    
       
  1240 
       
  1241 @SYMTestActions    
       
  1242 1.	Create an alarm that plays continuously.
       
  1243 
       
  1244 @SYMTestExpectedResults The alarm plays continuously when it expires.
       
  1245 
       
  1246 @SYMTestType                CT
       
  1247 @SYMTestPriority            1
       
  1248 */
       
  1249 static void TestCreateAndSnoozeContinuousAlarmL()
       
  1250 	{
       
  1251 #ifdef SYMBIAN_ALARM_REPEAT_EXTENSIONS
       
  1252 #if defined(_DEBUG) && defined(__WINS__)
       
  1253 	TheAlarmTest.Next(_L(" @SYMTestCaseID PIM-APPSRV-ALARMSERVER-CONTINUOUS-0001  Test creating and snoozing continuous alarms \r\n"));
       
  1254 	TestClearStoreL();
       
  1255 	
       
  1256 	TASShdAlarm alarm;
       
  1257 	alarm.NextDueTime().HomeTime();
       
  1258 	alarm.NextDueTime() += TTimeIntervalMinutes(1);
       
  1259 	alarm.SetContinuous(ETrue);
       
  1260 	// Add an alarm due in a minute
       
  1261 	TheAlarmTest.Test().Printf(_L("Add an alarm to go off in one minute \r\n"));
       
  1262 	TheAlarmTest(TheAlarmServerSession.AlarmAdd(alarm) == KErrNone, __LINE__);
       
  1263 	const TAlarmId id = alarm.Id();
       
  1264 	TheAlarmTest(id != KNullAlarmId, __LINE__);
       
  1265 	TheAlarmTest.Test().Printf(_L("Check if the alarm is continuous \r\n"));
       
  1266 	TBool isContinuous = alarm.Continuous();
       
  1267 	TheAlarmTest(isContinuous, __LINE__);
       
  1268 	
       
  1269 	// For an existing alarm, verify that continuous state can be obtained and 
       
  1270 	// set.
       
  1271 	TheAlarmTest(TheAlarmServerSession.GetContinuous(id, isContinuous) ==
       
  1272 		KErrNone, __LINE__);
       
  1273 	TheAlarmTest(isContinuous, __LINE__);
       
  1274 	TheAlarmTest(TheAlarmServerSession.SetContinuous(id, EFalse) == KErrNone,
       
  1275 		__LINE__);
       
  1276 	TheAlarmTest(TheAlarmServerSession.GetContinuous(id, isContinuous) ==
       
  1277 		KErrNone, __LINE__);
       
  1278 	TheAlarmTest(!isContinuous, __LINE__);
       
  1279 	TheAlarmTest(TheAlarmServerSession.SetContinuous(id, ETrue) == KErrNone,
       
  1280 		__LINE__);
       
  1281 	
       
  1282 	TTime snoozeTime;
       
  1283 	snoozeTime.HomeTime();
       
  1284 	snoozeTime += TTimeIntervalMinutes(1);
       
  1285 	TheAlarmTest.Test().Printf(_L("Snooze the alarm for a minute and get the alarm details \r\n"));
       
  1286 	TheAlarmTest(TheAlarmServerSession.__DbgSnoozeAlarm(id, snoozeTime) == KErrNone);
       
  1287 	TheAlarmTest(TheAlarmServerSession.GetAlarmDetails(id, alarm) == KErrNone, __LINE__);
       
  1288 	TheAlarmTest(alarm.State() == EAlarmStateSnoozed, __LINE__);
       
  1289 	
       
  1290 	TheAlarmTest.Test().Printf(_L("Delete the alarm from server's list \r\n"));
       
  1291 	TheAlarmTest(TheAlarmServerSession.AlarmDelete(id) == KErrNone, __LINE__);
       
  1292 #else
       
  1293     TheAlarmTest.Test().Printf(_L("THIS TEST IS A DEBUG, WINS TEST ONLY\r\n"));
       
  1294 #endif
       
  1295 #endif
       
  1296 	}
       
  1297 
       
  1298 /** Alarm that expires when a continuous alarm is played.
       
  1299 @SYMTestCaseID		PIM-APPSRV-ALARMSERVER-CONTINUOUS-0002
       
  1300 @SYMTestCaseDesc	To verify that the alarm that expires
       
  1301  					when the continuous alarm is playing
       
  1302  					will be played when the continuous 
       
  1303  					alarm is stopped.
       
  1304 
       
  1305 @SYMTestActions    
       
  1306 1.	Create an alarm that plays continuously.
       
  1307 2. 	Create an alarm that expires 1 minute after the continuous alarm
       
  1308 
       
  1309 @SYMTestExpectedResults The second alarm will play after the continuous
       
  1310  						alarm is stopped.
       
  1311 
       
  1312 @SYMTestType                CT
       
  1313 @SYMTestPriority            1
       
  1314 */
       
  1315 
       
  1316 static void TestTwoAlarmsExpirySequenceL()
       
  1317 	{
       
  1318 #ifdef SYMBIAN_ALARM_REPEAT_EXTENSIONS
       
  1319 #if defined(_DEBUG) && defined(__WINS__)
       
  1320 	TheAlarmTest.Next(_L(" @SYMTestCaseID PIM-APPSRV-ALARMSERVER-CONTINUOUS-0002  Test expiry of two alarms, one being continuous"));
       
  1321 	TestClearStoreL();
       
  1322 	
       
  1323 	RANTestClient consoleAlarmAlertSrvSession;
       
  1324 	User::LeaveIfError(consoleAlarmAlertSrvSession.Connect());
       
  1325 	User::LeaveIfError(consoleAlarmAlertSrvSession.SetExtendedMode());
       
  1326 	CleanupClosePushL(consoleAlarmAlertSrvSession);
       
  1327 
       
  1328 	TASShdAlarm alarmContinuous;
       
  1329 	alarmContinuous.NextDueTime().HomeTime();
       
  1330 	alarmContinuous.NextDueTime() += TTimeIntervalSeconds(30);
       
  1331 	alarmContinuous.SetContinuous(ETrue);
       
  1332 	
       
  1333 	TheAlarmTest(TheAlarmServerSession.AlarmAdd(alarmContinuous) == KErrNone, __LINE__);
       
  1334 	TAlarmId idContinuous = alarmContinuous.Id();
       
  1335 	TheAlarmTest(idContinuous != KNullAlarmId, __LINE__);
       
  1336 	
       
  1337 	TASShdAlarm alarm;
       
  1338 	alarm.NextDueTime().HomeTime();	
       
  1339 	alarm.NextDueTime() += TTimeIntervalSeconds(30);
       
  1340 	TheAlarmTest(TheAlarmServerSession.AlarmAdd(alarm) == KErrNone, __LINE__);
       
  1341 	TAlarmId id = alarm.Id();
       
  1342 	TheAlarmTest(id != KNullAlarmId, __LINE__);
       
  1343 	
       
  1344 	TheAlarmTest(alarmContinuous.State() == EAlarmStateQueued);
       
  1345 	TheAlarmTest(alarm.State() == EAlarmStateQueued);
       
  1346 	
       
  1347 	TheAlarmTest.Test().Printf(_L("Wait for the first alarm to expire \r\n"));
       
  1348 	TRequestStatus status;
       
  1349 	consoleAlarmAlertSrvSession.NotifyOnAlarm(alarm, status);
       
  1350 	User::WaitForRequest(status);
       
  1351 	
       
  1352 	TheAlarmTest(TheAlarmServerSession.GetAlarmDetails(idContinuous, alarmContinuous) == KErrNone, __LINE__);
       
  1353 	TheAlarmTest(alarmContinuous.State() == EAlarmStateNotifying);
       
  1354 	TheAlarmTest(TheAlarmServerSession.GetAlarmDetails(id, alarm) == KErrNone, __LINE__);
       
  1355 	TheAlarmTest(alarm.State() == EAlarmStateWaitingToNotify);
       
  1356 	
       
  1357 	TheAlarmTest.Test().Printf(_L("Acknowledge the first alarm \r\n"));
       
  1358 	consoleAlarmAlertSrvSession.AcknowledgeAlarm(idContinuous);
       
  1359 	TheAlarmTest(TheAlarmServerSession.GetAlarmDetails(idContinuous, alarmContinuous) == KErrNone, __LINE__);
       
  1360 	TheAlarmTest(alarmContinuous.State() == EAlarmStateNotified);
       
  1361 	TheAlarmTest.Test().Printf(_L("The second alarm should immediately expire, check the alarm details \r\n"));
       
  1362 	TheAlarmTest(TheAlarmServerSession.GetAlarmDetails(id, alarm) == KErrNone, __LINE__);
       
  1363 	TheAlarmTest(alarm.State() == EAlarmStateNotifying);
       
  1364 	
       
  1365 	consoleAlarmAlertSrvSession.AcknowledgeAlarm(id);
       
  1366 	TheAlarmTest(TheAlarmServerSession.GetAlarmDetails(id, alarm) == KErrNone, __LINE__);
       
  1367 	TheAlarmTest(alarm.State() == EAlarmStateNotified);
       
  1368 		
       
  1369 	consoleAlarmAlertSrvSession.UnsetExtendedMode();
       
  1370 	CleanupStack::PopAndDestroy();
       
  1371 	TestClearStoreL();
       
  1372 #else
       
  1373     TheAlarmTest.Test().Printf(_L("THIS TEST IS A DEBUG, WINS TEST ONLY\r\n"));
       
  1374 #endif
       
  1375 #endif
       
  1376 	}
       
  1377 
       
  1378 
       
  1379 static void TestDoNotNotifyAlarmAlertServerL()
       
  1380 	{
       
  1381 	TheAlarmTest.Test().Next(_L("Test that EAlarmCharacteristicsDoNotNotifyAlarmAlertServer do not panic the alarm server when they expire"));
       
  1382 	
       
  1383 	TheAlarmTest.Test().Printf(_L("Set the system time to 1 second before the alarm time"));
       
  1384 	TTime alarmTime(TTime(TDateTime(2008, EApril, 1, 12, 0, 0, 0)));
       
  1385 	User::SetHomeTime(alarmTime - TTimeIntervalSeconds(1));
       
  1386 	
       
  1387 	TheAlarmTest.Test().Printf(_L("Add an alarm with EAlarmCharacteristicsDoNotNotifyAlarmAlertServer set"));
       
  1388 	TASShdAlarm alarm;
       
  1389 	alarm.Message() = _L("Do not notify the alarm alert server!!!");
       
  1390 	alarm.NextDueTime() = alarmTime;
       
  1391 	alarm.Characteristics().Set(EAlarmCharacteristicsDoNotNotifyAlarmAlertServer);
       
  1392 	alarm.RepeatDefinition() = EAlarmRepeatDefintionRepeatOnce;
       
  1393 	
       
  1394 	User::LeaveIfError(TheAlarmServerSession.AlarmAdd(alarm));
       
  1395 	
       
  1396 	TheAlarmTest.Test().Printf(_L("wait until the alarm sounds starts playing"));
       
  1397 	FOREVER
       
  1398 		{
       
  1399 		TRequestStatus status;
       
  1400 		TAlarmId id;
       
  1401 		TheAlarmServerSession.NotifyChange(status, id);
       
  1402 		User::WaitForRequest(status);
       
  1403 		
       
  1404 		TheAlarmTest.Test().Printf(_L("alarms event = %d\n"), status.Int());
       
  1405 		User::LeaveIfError(status.Int());
       
  1406 		
       
  1407 		if (status.Int() == EAlarmChangeEventSoundPlaying)
       
  1408 			{
       
  1409 			// the sound is now playing which is where the panic would have happened
       
  1410 			// so we can stop waiting now
       
  1411 			break;
       
  1412 			}
       
  1413 		}
       
  1414 	
       
  1415 	TheAlarmTest.Test().Printf(_L("delete the alarm"));
       
  1416 	
       
  1417 	// delete the alarm
       
  1418 	User::LeaveIfError(TheAlarmServerSession.AlarmDelete(alarm.Id()));
       
  1419 	}
       
  1420 
       
  1421 //*************************************************************************************
       
  1422 	
       
  1423 	
       
  1424 static void RunTestsL()
       
  1425 	{
       
  1426 	//get the initial time
       
  1427  	TTime homeTime;
       
  1428 	homeTime.HomeTime();
       
  1429 
       
  1430 	CActiveScheduler* scheduler = new (ELeave) CActiveScheduler;
       
  1431 	CleanupStack::PushL(scheduler);
       
  1432 	CActiveScheduler::Install(scheduler);
       
  1433 
       
  1434     RPIMTestServer serv;
       
  1435     User::LeaveIfError(serv.Connect());
       
  1436     serv.DeleteFileL(KTestIniFile);
       
  1437 
       
  1438 	// Set time before starting Alarm Server
       
  1439 	const TInt KGmtOffset = 3600;
       
  1440 	_LIT(KBaselineTime, "20040730:050000.000000"); //In summer time
       
  1441 	TInt err = User::SetUTCTimeAndOffset(TTime(KBaselineTime), KGmtOffset);
       
  1442 	TheAlarmTest(err == KErrNone, __LINE__);
       
  1443 	
       
  1444 #ifdef __WINS__
       
  1445 	_LIT(KConsoleAlarmAlertServerImg,"ConsoleAlarmAlertServer");
       
  1446     TBuf<256> cmdline;
       
  1447 	cmdline.Append('p');
       
  1448 	cmdline.Append('p');
       
  1449 	cmdline.Append(EKeyEscape);
       
  1450 	cmdline.Append(0);
       
  1451 	cmdline.Append('p');
       
  1452 	cmdline.Append('p');
       
  1453 	cmdline.Append(EKeyEscape);
       
  1454 	cmdline.Append(0);
       
  1455 	RProcess server;
       
  1456 	server.Create(KConsoleAlarmAlertServerImg,cmdline,serverUid);
       
  1457 	TRequestStatus stat;
       
  1458 	server.Rendezvous(stat);
       
  1459 	if (stat!=KRequestPending)
       
  1460 		{
       
  1461 		server.Kill(0);		// abort startup
       
  1462 		}
       
  1463 	else
       
  1464 		{
       
  1465 		server.Resume();	// logon OK - start the server
       
  1466 		}
       
  1467 #endif //  __WINS__
       
  1468 	// Connect to the alarm server
       
  1469 	TheAlarmTest.Next(_L("Creating alarm server"));
       
  1470 	User::LeaveIfError(TheAlarmServerSession.Connect());
       
  1471 	
       
  1472 	TestDailyOnGivenDaysAlarmExpiryL();
       
  1473 	TestCreateAndSnoozeContinuousAlarmL();
       
  1474 	TestTwoAlarmsExpirySequenceL();
       
  1475 	
       
  1476 	// The real tests
       
  1477     // The following 2 tests are only for WINS and WINSCW for console interface
       
  1478 
       
  1479 	CreateAlarmsForPausingL();
       
  1480 	CreateSingleAlarmL();
       
  1481 	CreateNotificationAlarmL();
       
  1482 	CreateDailyRepeatingAlarmL();
       
  1483 
       
  1484 	CreateUtcAlarmsForPausingL();
       
  1485 	CreateSingleUtcAlarmL();
       
  1486 	CreateNotificationUtcAlarmL();
       
  1487 	CreateDailyRepeatingUtcAlarmL();
       
  1488 
       
  1489 	CreateAlarmAndIgnoreL();
       
  1490     TestWorkdaysRepeatingAlarmL();
       
  1491 
       
  1492 #if defined(_DEBUG) && defined(__WINS__)
       
  1493 
       
  1494 	CreateAlarmAndSnoozeL(EAlarmRepeatDefintionRepeatDaily);
       
  1495 	CreateAlarmAndSnoozeL(EAlarmRepeatDefintionRepeatWorkday);
       
  1496 	CreateAlarmAndSnoozeL(EAlarmRepeatDefintionRepeatWeekly);
       
  1497 
       
  1498 	DbgSnoozeAlarmSetsTimeCorrectlyL(EAlarmRepeatDefintionRepeatOnce);
       
  1499 	DbgSnoozeAlarmSetsTimeCorrectlyL(EAlarmRepeatDefintionRepeatNext24Hours);
       
  1500 	DbgSnoozeAlarmSetsTimeCorrectlyL(EAlarmRepeatDefintionRepeatDaily);
       
  1501 	DbgSnoozeAlarmSetsTimeCorrectlyL(EAlarmRepeatDefintionRepeatWorkday);
       
  1502 	DbgSnoozeAlarmSetsTimeCorrectlyL(EAlarmRepeatDefintionRepeatWeekly);
       
  1503 
       
  1504 #endif //  __WINS__
       
  1505 
       
  1506 	TestINC092682L();
       
  1507 	TestDoNotNotifyAlarmAlertServerL();
       
  1508 
       
  1509 	TestClearStoreL();
       
  1510 
       
  1511 	//Set back the time to the initial time
       
  1512     serv.SetHomeTime(homeTime);
       
  1513     serv.Close();
       
  1514  	CleanupStack::PopAndDestroy(scheduler);
       
  1515 	}
       
  1516 
       
  1517 
       
  1518 
       
  1519 
       
  1520 //
       
  1521 // -----> Global Exports
       
  1522 //
       
  1523 
       
  1524 //*************************************************************************************
       
  1525 	
       
  1526 /**
       
  1527 @SYMTestCaseID PIM-TBASICALARMS-0001
       
  1528 */	
       
  1529 TInt E32Main()
       
  1530 	{
       
  1531 	__UHEAP_MARK;
       
  1532 	//
       
  1533 	TInt ret = KErrNone;
       
  1534 	TheAlarmTest.Title();
       
  1535 	CTrapCleanup* cleanup = CTrapCleanup::New();
       
  1536 	if	(!cleanup)
       
  1537 	    {
       
  1538 	    return KErrNoMemory;
       
  1539 	    }
       
  1540 	//
       
  1541 	TheAlarmTest.Start(_L("@SYMTestCaseID PIM-TBASICALARMS-0001"));
       
  1542 	//
       
  1543 	TRAPD(err, RunTestsL());
       
  1544 	TheAlarmTest(err == KErrNone, __LINE__);
       
  1545 
       
  1546 	delete cleanup;
       
  1547     TRAP(ret,TheAlarmTest.EndL());
       
  1548 	TheAlarmTest.Test().Close();
       
  1549 	ASTstAlarmTest::Close();
       
  1550 
       
  1551 	__UHEAP_MARKEND;
       
  1552 	return ret;
       
  1553 	}