commonappservices/alarmserver/Test/ssm/TWakeupAlarms.cpp
changeset 0 2e3d3ce01487
equal deleted inserted replaced
-1:000000000000 0:2e3d3ce01487
       
     1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include "ASTstAlarmTest.h"
       
    17 #include "asclisoundplay.h"
       
    18 #include "testserver.h"
       
    19 #include <tz.h>
       
    20 #include <e32property.h> 
       
    21 #ifdef SYMBIAN_SYSTEM_STATE_MANAGEMENT
       
    22 #include <ssm/ssmstates.hrh>
       
    23 #endif
       
    24 #ifdef __WINS__
       
    25 #include "consoleantestclient.h"
       
    26 #endif
       
    27 
       
    28 _LIT(KTestName, "@SYMTestCaseID:PIM-TWAKEUPALARMS-0001 Wakeup Alarms");
       
    29 _LIT(KFormatDateTime, "%D%M%Y%/0%1%/1%2%/2%3%/3 %H:%T:%S.%C");
       
    30 _LIT(KAlarmServerFile, "c:\\private\\101f5027\\AlarmServer.ini");
       
    31 _LIT(KAlarmServerProcessNameMatch, "alarmserver.exe*");
       
    32 
       
    33 const TTimeIntervalMicroSeconds32 KAlarmWaitToNotifyPeriod(500000);
       
    34 
       
    35 #ifdef SYMBIAN_SYSTEM_STATE_MANAGEMENT
       
    36 _LIT8(KAlarmData, "sausage");
       
    37 
       
    38 _LIT8(KTokyo, "Asia/Tokyo"); // No DST changes in Tokyo
       
    39 _LIT8(KSydney, "Australia/Sydney"); // Large positive standard offset
       
    40 #endif
       
    41 _LIT8(KLondon, "Europe/London"); // Large positive standard offset
       
    42 #ifdef SYMBIAN_SYSTEM_STATE_MANAGEMENT
       
    43 _LIT8(KChicago, "America/Chicago"); // Large negative standard offset
       
    44 
       
    45 const TUid KAlarmServerUID = {0x101f5027};
       
    46 const TInt KRTCValueKey = 200;
       
    47 const TInt KSystemStateChangeKey = 301;
       
    48 const TInt KSystemStateChangeAckKey = 302;
       
    49 
       
    50 TAlarmCategory KAlarmCategory = {0x10101010};
       
    51 #endif
       
    52 
       
    53 class CAlarmTestApp : public CBase
       
    54 	{
       
    55 public:
       
    56 	static CAlarmTestApp* NewLC();
       
    57 	~CAlarmTestApp();
       
    58 	
       
    59 	void RunTestsL();
       
    60 	
       
    61 private: // the test cases
       
    62 
       
    63 	void TestAlarmMissingHourRepeatOnce1L();
       
    64 	void TestAlarmMissingHourRepeatOnce2L();
       
    65 	void TestAlarmMissingHourRepeatOnce3L();
       
    66 	void TestAlarmMissingHourRepeatDailyL();
       
    67 #ifdef SYMBIAN_SYSTEM_STATE_MANAGEMENT
       
    68 	void TestWakeupFlagPersistanceL();
       
    69 	void TestSetWakeupSessionAlarmL();
       
    70 	void TestDeleteWakeupAlarmL();
       
    71 	void TestDisableWakeupAlarmL();
       
    72 	void TestUnsetWakeupFlagL();
       
    73 	void TestWakeupAlarmRobustnessL();
       
    74 	
       
    75 	void TestSnoozeWakeupAlarmL();
       
    76 	
       
    77 	void TestFixedAlarmL();
       
    78 	
       
    79 	void TestRTCSetOnDSTRolloverL();
       
    80 	void TestSetRTCOnDeviceShutdownL();
       
    81 	void TestRTCSetOnTimeZoneChangeL();
       
    82 	void TestRTCSetOnSystemTimeChangeL();
       
    83 	
       
    84 	void TestHeadWakeupAlarmL();
       
    85 	
       
    86 	void TestWakeupAlarmTimeL();
       
    87 	void DoTestWakeupAlarmTimeL(const TTime& aSystemLocalTime, const TTime& aAlarmTimeUTC, TTimeIntervalMinutes aNextUTCOffset, const TDesC8& aTimeZoneName);
       
    88 	
       
    89 	void TestReadOnlyInShutDownL();
       
    90 	void TestAlarmFileNotWrittenOnTimeZoneChangeL();
       
    91 	void TestAlarmFileNotWrittenOnSystemTimeChangeL();
       
    92 		
       
    93 	void TestWriteCommandsL(TASShdAlarm& aASShdAlarm, TInt aExpectedErrorCode);
       
    94 	void TestReadCommandsL(TASShdAlarm& aASShdAlarm);
       
    95 #endif
       
    96 		
       
    97 private:
       
    98 	CAlarmTestApp();
       
    99 	void ConstructL();
       
   100 
       
   101 	// Utility methods
       
   102 #ifdef SYMBIAN_SYSTEM_STATE_MANAGEMENT
       
   103 	TASShdAlarm CreateAlarm(const TTime& aAlarmTime, TBool aWakeup);
       
   104 #endif
       
   105 	void AddAlarmL(TASShdAlarm& aAlarm);
       
   106 	void DeleteAlarmL(TAlarmId aAlarmId);
       
   107 	void DeleteAllAlarmsL();
       
   108 	
       
   109 	void TestAlarmNotifyL(TASShdAlarm& aAlarm, const TTime& aNotifyTime, TBool aExpectedToNotify);
       
   110 	
       
   111 	void SetTimeZoneL(const TDesC8& aTimeZoneName);
       
   112 	void SetHomeTimeL(const TTime& aSystemLocalTime);
       
   113 	
       
   114 	void RestartAlarmServerL();
       
   115 	
       
   116 #ifdef SYMBIAN_SYSTEM_STATE_MANAGEMENT
       
   117 	void TestRTCValueL(const TTime& aRTCValue);
       
   118 #endif
       
   119 	void PrintTimeL(const TTime& aTime, const TDesC& aPrefix);
       
   120 	
       
   121 #ifdef SYMBIAN_SYSTEM_STATE_MANAGEMENT
       
   122 	void SendSsmSystemMessageL(TSsmMainSystemStates aSsmMessage);
       
   123 #endif
       
   124 	
       
   125 private:
       
   126 	RPIMTestServer iPIMTestServer;
       
   127 	RTz iTz;
       
   128 	CTzId* iSavedTzID;
       
   129 #ifdef __WINS__
       
   130 	RANTestClient iClient;
       
   131 #endif
       
   132 	};
       
   133 
       
   134 CAlarmTestApp* CAlarmTestApp::NewLC()
       
   135 	{
       
   136 	CAlarmTestApp* self = new (ELeave) CAlarmTestApp();
       
   137 	CleanupStack::PushL(self);
       
   138 	self->ConstructL();
       
   139 	//CleanupStack::Pop(self);
       
   140 	return self;
       
   141 	}
       
   142 	
       
   143 CAlarmTestApp::CAlarmTestApp()
       
   144 	{
       
   145 	}
       
   146 
       
   147 void CAlarmTestApp::ConstructL()
       
   148 	{
       
   149 #ifdef SYMBIAN_SYSTEM_STATE_MANAGEMENT
       
   150 	User::LeaveIfError(RProperty::Define(KAlarmServerUID, KRTCValueKey, RProperty::EByteArray, sizeof(TPckgC<TTime>) ) );
       
   151 	User::LeaveIfError(RProperty::Define(KAlarmServerUID, KSystemStateChangeKey, RProperty::EInt));
       
   152 	User::LeaveIfError(RProperty::Define(KAlarmServerUID, KSystemStateChangeAckKey, RProperty::EInt));
       
   153 #endif
       
   154 	
       
   155 	// The time zone server must be running with auto dst updates enabled for this test to work 
       
   156 	User::LeaveIfError(iTz.Connect());
       
   157 	iTz.SetAutoUpdateBehaviorL(RTz::ETZAutoDSTUpdateOn);
       
   158 	
       
   159 	// save the current time zone
       
   160 	iSavedTzID = iTz.GetTimeZoneIdL();
       
   161 	User::LeaveIfError(iPIMTestServer.Connect());
       
   162 	
       
   163 	TheAlarmTest.TestStartServers();
       
   164 	User::LeaveIfError(TheAlarmTest.Session().Connect());
       
   165 	
       
   166 	// Make sure the test starts without any alarms set
       
   167 	DeleteAllAlarmsL();
       
   168 	
       
   169 #ifdef __WINS__
       
   170 	User::LeaveIfError(iClient.Connect());
       
   171 	User::LeaveIfError(iClient.SetExtendedMode());
       
   172 #endif
       
   173 	}
       
   174 
       
   175 CAlarmTestApp::~CAlarmTestApp()
       
   176 	{
       
   177 #ifdef __WINS__
       
   178 	iClient.UnsetExtendedMode();
       
   179 	iClient.Close();
       
   180 #endif
       
   181 	
       
   182 	iPIMTestServer.Close();
       
   183 	
       
   184 	// restore the saved time zone
       
   185 	TRAP_IGNORE(SetTimeZoneL(iSavedTzID->TimeZoneNameID()));
       
   186 	delete iSavedTzID;
       
   187 	iTz.Close();
       
   188 	}
       
   189 	
       
   190 #ifdef SYMBIAN_SYSTEM_STATE_MANAGEMENT
       
   191 void CAlarmTestApp::SendSsmSystemMessageL(TSsmMainSystemStates aSsmMessage)
       
   192 	{
       
   193 	TheAlarmTest.Test().Printf(_L("Entering system state %d"), aSsmMessage);
       
   194 
       
   195 	RProperty ackProperty;
       
   196 	User::LeaveIfError(ackProperty.Attach(KAlarmServerUID, KSystemStateChangeAckKey));
       
   197 	TRequestStatus status;
       
   198 	ackProperty.Subscribe(status);
       
   199 	
       
   200 	User::LeaveIfError(RProperty::Set(KAlarmServerUID, KSystemStateChangeKey, aSsmMessage));
       
   201 	
       
   202 	User::WaitForRequest(status);
       
   203 	}
       
   204 #endif
       
   205 
       
   206 void CAlarmTestApp::SetHomeTimeL(const TTime& aSystemLocalTime)
       
   207 	{
       
   208 	PrintTimeL(aSystemLocalTime, _L("Set Home Time to : "));
       
   209 	User::LeaveIfError(iTz.SetHomeTime(aSystemLocalTime));
       
   210 	}
       
   211 
       
   212 #ifdef SYMBIAN_SYSTEM_STATE_MANAGEMENT
       
   213 void CAlarmTestApp::TestRTCValueL(const TTime& aRTCValue)
       
   214 	{
       
   215 	TheAlarmTest.Test().Printf(_L("Test the RTC Value"));
       
   216 	
       
   217 	User::After(200000);
       
   218 	TPckgBuf<TTime> rtcValuePckgBuf;
       
   219 	RProperty::Get(KAlarmServerUID, KRTCValueKey, rtcValuePckgBuf);
       
   220 	
       
   221 	if (aRTCValue == Time::NullTTime())
       
   222 		{
       
   223 		TheAlarmTest.Test().Printf(_L("Check the RTC is not set"));
       
   224 		}
       
   225 	else
       
   226 		{
       
   227 		PrintTimeL(aRTCValue, _L("Check the RTC is set to : "));
       
   228 		}
       
   229 	
       
   230 	if (rtcValuePckgBuf() == Time::NullTTime())
       
   231 		{
       
   232 		TheAlarmTest.Test().Printf(_L("The RTC is not set"));
       
   233 		}
       
   234 	else
       
   235 		{
       
   236 		PrintTimeL(rtcValuePckgBuf(), _L("The RTC is set to : "));
       
   237 		}
       
   238 		
       
   239 	TheAlarmTest(rtcValuePckgBuf() == aRTCValue); 
       
   240 	}
       
   241 
       
   242 TASShdAlarm CAlarmTestApp::CreateAlarm(const TTime& aAlarmTime, TBool aWakeup)
       
   243 	{
       
   244 	TASShdAlarm alarm;
       
   245 	alarm.RepeatDefinition() = EAlarmRepeatDefintionRepeatOnce;
       
   246 	_LIT(KMessage, "An alarm");
       
   247 	alarm.Message() = KMessage;
       
   248 	alarm.SetWakeup(aWakeup);
       
   249 	
       
   250 	if (aAlarmTime == Time::NullTTime())
       
   251 		{
       
   252 		alarm.NextDueTime().HomeTime();
       
   253 		alarm.NextDueTime() += TTimeIntervalDays(1);
       
   254 		}
       
   255 	else
       
   256 		{
       
   257 		alarm.NextDueTime() = aAlarmTime;
       
   258 		}
       
   259 	
       
   260 	return alarm;
       
   261 	}
       
   262 #endif
       
   263 
       
   264 void CAlarmTestApp::AddAlarmL(TASShdAlarm& aAlarm)
       
   265 	{
       
   266 	TheAlarmTest.Test().Printf(_L("Adding an alarm"));
       
   267 	TRequestStatus status;
       
   268 	iPIMTestServer.FileServerNotifyChange(ENotifyAll, status, KAlarmServerFile);
       
   269 	TInt addError = TheAlarmTest.Session().AlarmAdd(aAlarm);
       
   270 	
       
   271 	if (addError != KErrNone)
       
   272 		{
       
   273 		iPIMTestServer.FileServerNotifyChangeCancel();
       
   274 		}
       
   275 	else
       
   276 		{
       
   277 		TheAlarmTest.Test().Printf(_L("Added alarm %d"), aAlarm.Id());
       
   278 		}
       
   279 
       
   280 	User::WaitForRequest(status);
       
   281 	User::LeaveIfError(addError);
       
   282 	}
       
   283 
       
   284 void CAlarmTestApp::DeleteAlarmL(TAlarmId aAlarmId)
       
   285 	{
       
   286 	TheAlarmTest.Test().Printf(_L("Deleting alarm %d"), aAlarmId);
       
   287 	TRequestStatus status;
       
   288 	iPIMTestServer.FileServerNotifyChange(ENotifyAll, status, KAlarmServerFile);
       
   289 	TheAlarmTest.Session().AlarmDelete(aAlarmId);
       
   290 	RTimer timeoutTimer;
       
   291 	User::LeaveIfError(timeoutTimer.CreateLocal());
       
   292 	TRequestStatus timeoutTimerStatus;
       
   293 	timeoutTimer.After(timeoutTimerStatus, 2000000);
       
   294 	User::WaitForRequest(status, timeoutTimerStatus);
       
   295 	timeoutTimer.Cancel();
       
   296 	iPIMTestServer.FileServerNotifyChangeCancel();
       
   297 	User::WaitForRequest(status, timeoutTimerStatus);
       
   298 	}
       
   299 
       
   300 void CAlarmTestApp::SetTimeZoneL(const TDesC8& aTimeZoneName)
       
   301 	{
       
   302 	TBuf<50> timeZoneName;
       
   303 	timeZoneName.Copy(aTimeZoneName);
       
   304 	TheAlarmTest.Test().Printf(_L("Changing TimeZone to : %S"), &timeZoneName);
       
   305 	
       
   306 	CTzId* tzID = CTzId::NewL(aTimeZoneName);
       
   307 	CleanupStack::PushL(tzID);
       
   308 	iTz.SetTimeZoneL(*tzID);
       
   309 	CleanupStack::PopAndDestroy(tzID);
       
   310 	}
       
   311 
       
   312 void CAlarmTestApp::PrintTimeL(const TTime& aTime, const TDesC& aPrefix)
       
   313 	{
       
   314 	TFileName dateString;
       
   315 	aTime.FormatL(dateString, KFormatDateTime);
       
   316 	TheAlarmTest.Test().Printf(_L("%S %S\n"),&aPrefix, &dateString);
       
   317 	}
       
   318 
       
   319 void CAlarmTestApp::DeleteAllAlarmsL()
       
   320 	{
       
   321 	RArray<TAlarmId> alarmIds;
       
   322 	CleanupClosePushL(alarmIds);
       
   323 	TheAlarmTest.Session().GetAlarmIdListL(alarmIds);
       
   324 	
       
   325 	const TInt KAlarmCount(alarmIds.Count());
       
   326 	for (TInt i(0) ; i < KAlarmCount ; ++i )
       
   327 		{
       
   328 		TheAlarmTest.Test().Printf(_L("deleting an alarm"));
       
   329 		User::LeaveIfError(TheAlarmTest.Session().AlarmDelete(alarmIds[i]));
       
   330 		}
       
   331 	
       
   332 	CleanupStack::PopAndDestroy(&alarmIds);
       
   333 	}
       
   334 
       
   335 void CAlarmTestApp::RestartAlarmServerL()
       
   336 	{
       
   337 	TheAlarmTest.Test().Printf(_L("Restarting the alarm server"));
       
   338 	TheAlarmTest.Session().Close();
       
   339 	
       
   340 	iPIMTestServer.KillProcessL(KAlarmServerProcessNameMatch);
       
   341 	
       
   342 	User::LeaveIfError(TheAlarmTest.Session().Connect());
       
   343 	}
       
   344 
       
   345 #ifndef __WINS__
       
   346 void CAlarmTestApp::TestAlarmNotifyL(TASShdAlarm& /*aAlarm*/, const TTime& /*aNotifyTime*/, TBool /*aExpectedToNotify*/)
       
   347 	{
       
   348 	TheAlarmTest.Test().Printf(_L("This cannot be tested on hardware"));
       
   349 #else
       
   350 void CAlarmTestApp::TestAlarmNotifyL(TASShdAlarm& aAlarm, const TTime& aNotifyTime, TBool aExpectedToNotify)
       
   351 	{
       
   352 	aExpectedToNotify?
       
   353 	TheAlarmTest.Test().Printf(_L("Test that the alarm will notify")):
       
   354 	TheAlarmTest.Test().Printf(_L("Test that the alarm will NOT notify"));
       
   355 	
       
   356 	TheAlarmTest.Test().Printf(_L("Close the alarm server"));
       
   357 	TheAlarmTest.Session().Close();
       
   358 	iPIMTestServer.KillProcessL(KAlarmServerProcessNameMatch);
       
   359 	
       
   360 	SetHomeTimeL(aNotifyTime);	
       
   361 	
       
   362 	// start observing the alarm notification
       
   363 	TRequestStatus alarmStatus;
       
   364 	iClient.NotifyOnAlarm(aAlarm, alarmStatus);
       
   365 	
       
   366 	TheAlarmTest.Test().Printf(_L("Start the alarm server"));
       
   367 	User::LeaveIfError(TheAlarmTest.Session().Connect());
       
   368 	
       
   369 	// Create timeout timer
       
   370 	RTimer timeoutTimer;
       
   371 	User::LeaveIfError(timeoutTimer.CreateLocal());
       
   372 	TRequestStatus timeoutTimerStatus;
       
   373 	timeoutTimer.After(timeoutTimerStatus, KAlarmWaitToNotifyPeriod);
       
   374 	
       
   375 	// Wait for the alarm to expire
       
   376 	User::WaitForRequest(alarmStatus, timeoutTimerStatus);
       
   377 	
       
   378 	if (alarmStatus.Int() == KErrNone)
       
   379 		{
       
   380 		TheAlarmTest.Test().Printf(_L("The alarm notified"));
       
   381 		
       
   382 		iClient.AcknowledgeAlarm(aAlarm.Id());
       
   383 		timeoutTimer.Cancel();
       
   384 		User::WaitForRequest(timeoutTimerStatus);
       
   385 		
       
   386 		TheAlarmTest(aExpectedToNotify);
       
   387 		}
       
   388 	else
       
   389 		{
       
   390 		TheAlarmTest.Test().Printf(_L("The alarm DID NOT notify"));
       
   391 		iClient.CancelNotifications();
       
   392 		User::WaitForRequest(alarmStatus);
       
   393 		
       
   394 		TheAlarmTest(!aExpectedToNotify);
       
   395 		}
       
   396 	
       
   397 	// Make sure there are no other alarms notifying
       
   398 	RArray<TAlarmId> alarmIds;
       
   399 	CleanupClosePushL(alarmIds);
       
   400 	TheAlarmTest.Session().GetAlarmIdListByStateL(EAlarmStateNotifying, alarmIds);
       
   401 	TheAlarmTest(alarmIds.Count() == 0);
       
   402 	CleanupStack::PopAndDestroy(&alarmIds);
       
   403 #endif
       
   404 	}
       
   405 
       
   406 void CAlarmTestApp::TestAlarmMissingHourRepeatDailyL()
       
   407 	{
       
   408 	TheAlarmTest.Test().Next(_L("Test a repeating alarm in the missing hour"));
       
   409 	SetTimeZoneL(KLondon);
       
   410 	
       
   411 	// Set home time to (before DST threshold)
       
   412 	// Saturday, 29 March 2008, 00:12:00
       
   413 	SetHomeTimeL(TDateTime(2008, EMarch, 28, 12, 0, 0, 0));	
       
   414 	
       
   415 	// Set a daily repeating alarm during the missing local hour
       
   416 	// Sunday, 30 March 2008, 00:01:15
       
   417 	TASShdAlarm alarm;
       
   418 	alarm.RepeatDefinition() = EAlarmRepeatDefintionRepeatDaily;
       
   419 	alarm.NextDueTime() = TTime(TDateTime(2008, EMarch, 29, 1, 15, 0, 0));
       
   420 	alarm.Message().Append(_L("Missing hour alarm"));
       
   421 	
       
   422 	AddAlarmL(alarm);
       
   423 	
       
   424 	TestAlarmNotifyL(alarm, TTime(TDateTime(2008, EMarch, 29, 2, 14, 30, 0)), EFalse);
       
   425 	TestAlarmNotifyL(alarm, TTime(TDateTime(2008, EMarch, 29, 2, 15, 30, 0)), ETrue);
       
   426 	
       
   427 #ifdef __WINS__
       
   428 	TheAlarmTest.Test().Printf(_L("make sure that the next repeat of the alarm is correct"));
       
   429 	// Monday, 31 March 2008, 00:01:15
       
   430 	TASShdAlarm fetchedAlarm;
       
   431 	TheAlarmTest.Session().GetAlarmDetails(alarm.Id(), fetchedAlarm);
       
   432 	
       
   433 	TTime fetchedAlarmTime = fetchedAlarm.NextDueTime();
       
   434 	TheAlarmTest(fetchedAlarmTime == TTime(TDateTime(2008, EMarch, 30, 1, 15, 0, 0)));
       
   435 	
       
   436 #endif // __WINS__
       
   437 	
       
   438 	// delete the alarm
       
   439 	DeleteAlarmL(alarm.Id());
       
   440 	}
       
   441 
       
   442 /* Use case 1:
       
   443 Missing hour is from 1am (local time) to 2am (local time).
       
   444 Alarm is set for 1:15am (local time).
       
   445 No other alarm is set.
       
   446 
       
   447 The alarm will expire at 2:15 (local time) instead of 1:15 (local time).
       
   448 */
       
   449 void CAlarmTestApp::TestAlarmMissingHourRepeatOnce1L()
       
   450 	{
       
   451 	TheAlarmTest.Test().Next(_L("Test an alarm in the missing hour"));
       
   452 	SetTimeZoneL(KLondon);
       
   453 	
       
   454 	// set home time to (before DST threshold)
       
   455 	// Saturday, 29 March 2008, 00:12:00
       
   456 	SetHomeTimeL(TDateTime(2008, EMarch, 28, 12, 0, 0, 0));	
       
   457 	
       
   458 	// set an alarm during the missing local hour
       
   459 	// Sunday, 30 March 2008, 00:01:15
       
   460 	TASShdAlarm alarm;
       
   461 	alarm.RepeatDefinition() = EAlarmRepeatDefintionRepeatOnce;
       
   462 	alarm.NextDueTime() = TTime(TDateTime(2008, EMarch, 29, 1, 15, 0, 0));
       
   463 	alarm.Message().Append(_L("Missing hour alarm"));
       
   464 	
       
   465 	AddAlarmL(alarm);
       
   466 	
       
   467 	TestAlarmNotifyL(alarm, TTime(TDateTime(2008, EMarch, 29, 2, 14, 30, 0)), EFalse);
       
   468 	TestAlarmNotifyL(alarm, TTime(TDateTime(2008, EMarch, 29, 2, 15, 30, 0)), ETrue);
       
   469 	
       
   470 	// delete the alarm
       
   471 	DeleteAlarmL(alarm.Id());
       
   472 	}
       
   473 
       
   474 /** Use case 2:
       
   475 Missing hour is from 1am (local time) to 2am (local time).
       
   476 Alarm1 is set for 1:15am (local time)
       
   477 Alarm2 is set for 1:45am (local time)
       
   478 
       
   479 The alarms will expire at 2:15 (local time)  and 2:45 (local time).
       
   480 */
       
   481 void CAlarmTestApp::TestAlarmMissingHourRepeatOnce2L()
       
   482 	{
       
   483 	TheAlarmTest.Test().Next(_L("Test two alarms in the missing hour"));
       
   484 	SetTimeZoneL(KLondon);
       
   485 	
       
   486 	// set home time to (before DST threshold)
       
   487 	// Saturday, 29 March 2008, 00:12:00
       
   488 	SetHomeTimeL(TDateTime(2008, EMarch, 28, 12, 0, 0, 0));	
       
   489 	
       
   490 	// set an alarm during the missing local hour
       
   491 	// Sunday, 30 March 2008, 00:01:15
       
   492 	TASShdAlarm alarm1;
       
   493 	alarm1.RepeatDefinition() = EAlarmRepeatDefintionRepeatOnce;
       
   494 	alarm1.NextDueTime() = TTime(TDateTime(2008, EMarch, 29, 1, 15, 0, 0));
       
   495 	alarm1.Message().Append(_L("Missing hour alarm"));
       
   496 	
       
   497 	AddAlarmL(alarm1);
       
   498 	
       
   499 	// Set an alarm during the missing local hour
       
   500 	// Sunday, 30 March 2008, 00:01:45
       
   501 	TASShdAlarm alarm2;
       
   502 	alarm2.RepeatDefinition() = EAlarmRepeatDefintionRepeatOnce;
       
   503 	alarm2.NextDueTime() = TTime(TDateTime(2008, EMarch, 29, 1, 45, 0, 0));
       
   504 	alarm2.Message().Append(_L("Missing hour alarm"));
       
   505 	
       
   506 	AddAlarmL(alarm2);
       
   507 	
       
   508 	TestAlarmNotifyL(alarm1, TTime(TDateTime(2008, EMarch, 29, 2, 14, 30, 0)), EFalse);
       
   509 	TestAlarmNotifyL(alarm1, TTime(TDateTime(2008, EMarch, 29, 2, 15, 30, 0)), ETrue);
       
   510 	TestAlarmNotifyL(alarm2, TTime(TDateTime(2008, EMarch, 29, 2, 44, 30, 0)), EFalse);
       
   511 	TestAlarmNotifyL(alarm2, TTime(TDateTime(2008, EMarch, 29, 2, 45, 30, 0)), ETrue);
       
   512 	
       
   513 	// delete the alarm
       
   514 	DeleteAlarmL(alarm1.Id());
       
   515 	DeleteAlarmL(alarm2.Id());
       
   516 	}
       
   517 
       
   518 /** Use case 3:
       
   519 Missing hour  is from 1am (local time) to 2am (local time).
       
   520 Alarm1 is set for 1:15am (local time).
       
   521 Alarm2 is set for 2:05am (local time).
       
   522 Alarm3 is set for 3:05am (local time).
       
   523 Alarm1 is the only alarm that happens during the missing hour
       
   524 but the presence of other alarms may complicate the behaviour as well.
       
   525 
       
   526 The expiry times of the alarms become:
       
   527 2:05 : Alarm2
       
   528 2:15 : Alarm1
       
   529 3:05 : Alarm3
       
   530 Notice the change in the order of the alarms. This is because we remap
       
   531 the alarms of the missing hour in the hour afterwards so between 2am and 3am
       
   532 in our example we have the alarms for 1am to 3am and so they can get reordered.
       
   533 Alarms after 3am are not impacted.
       
   534 */
       
   535 void CAlarmTestApp::TestAlarmMissingHourRepeatOnce3L()
       
   536 	{
       
   537 	TheAlarmTest.Test().Next(_L("Test alarms changing order because of the missing hour"));
       
   538 	SetTimeZoneL(KLondon);
       
   539 	
       
   540 	// set home time to (before DST threshold)
       
   541 	// Saturday, 29 March 2008, 00:12:00
       
   542 	SetHomeTimeL(TDateTime(2008, EMarch, 28, 12, 0, 0, 0));	
       
   543 	
       
   544 	// set an alarm during the missing local hour
       
   545 	// Sunday, 30 March 2008, 00:01:15
       
   546 	TASShdAlarm alarm1;
       
   547 	alarm1.RepeatDefinition() = EAlarmRepeatDefintionRepeatOnce;
       
   548 	alarm1.NextDueTime() = TTime(TDateTime(2008, EMarch, 29, 1, 15, 0, 0));
       
   549 	alarm1.Message().Append(_L("Missing hour alarm"));
       
   550 	AddAlarmL(alarm1);
       
   551 	
       
   552 	// Set an alarm during the missing local hour
       
   553 	// Sunday, 30 March 2008, 00:02:05
       
   554 	TASShdAlarm alarm2;
       
   555 	alarm2.RepeatDefinition() = EAlarmRepeatDefintionRepeatOnce;
       
   556 	alarm2.NextDueTime() = TTime(TDateTime(2008, EMarch, 29, 2, 05, 0, 0));
       
   557 	alarm2.Message().Append(_L("Missing hour alarm"));
       
   558 	AddAlarmL(alarm2);
       
   559 	
       
   560 	// Set an alarm during the missing local hour
       
   561 	// Sunday, 30 March 2008, 00:03:05
       
   562 	TASShdAlarm alarm3;
       
   563 	alarm3.RepeatDefinition() = EAlarmRepeatDefintionRepeatOnce;
       
   564 	alarm3.NextDueTime() = TTime(TDateTime(2008, EMarch, 29, 3, 05, 0, 0));
       
   565 	alarm3.Message().Append(_L("Missing hour alarm"));
       
   566 	AddAlarmL(alarm3);
       
   567 	
       
   568 	TestAlarmNotifyL(alarm2, TTime(TDateTime(2008, EMarch, 29, 2, 04, 30, 0)), EFalse);
       
   569 	TestAlarmNotifyL(alarm2, TTime(TDateTime(2008, EMarch, 29, 2, 05, 30, 0)), ETrue);
       
   570 	TestAlarmNotifyL(alarm1, TTime(TDateTime(2008, EMarch, 29, 2, 14, 30, 0)), EFalse);
       
   571 	TestAlarmNotifyL(alarm1, TTime(TDateTime(2008, EMarch, 29, 2, 15, 30, 0)), ETrue);
       
   572 	TestAlarmNotifyL(alarm3, TTime(TDateTime(2008, EMarch, 29, 3, 04, 30, 0)), EFalse);
       
   573 	TestAlarmNotifyL(alarm3, TTime(TDateTime(2008, EMarch, 29, 3, 05, 30, 0)), ETrue);
       
   574 	
       
   575 	// delete the alarm
       
   576 	DeleteAlarmL(alarm1.Id());
       
   577 	DeleteAlarmL(alarm2.Id());
       
   578 	DeleteAlarmL(alarm3.Id());
       
   579 	}
       
   580 
       
   581 #ifdef SYMBIAN_SYSTEM_STATE_MANAGEMENT
       
   582 void CAlarmTestApp::TestWakeupAlarmRobustnessL()
       
   583 	{
       
   584 	TheAlarmTest.Test().Next(_L("Test that the RTC is not set when a wakeup alarm fails to be written to file"));
       
   585 	
       
   586 	TheAlarmTest.Test().Printf(_L("Create a wakeup alarm"));
       
   587 	TASShdAlarm alarm;
       
   588 	alarm.RepeatDefinition() = EAlarmRepeatDefintionRepeatOnce;
       
   589 	// Set the wakeup flag for the alarm
       
   590 	alarm.SetWakeup(ETrue);
       
   591 	alarm.Message() = KTestName;
       
   592 	alarm.NextDueTime().HomeTime();
       
   593 	alarm.NextDueTime() += TTimeIntervalMinutes(90);
       
   594 	
       
   595 	TheAlarmTest.Test().Printf(_L("Add the wakeup alarm"));
       
   596 	User::LeaveIfError(TheAlarmTest.Session().AlarmAdd(alarm));
       
   597 	
       
   598 	TheAlarmTest.Test().Printf(_L("kill the alarm server before the alarm has been written to file"));
       
   599 	RestartAlarmServerL();
       
   600 	
       
   601 	TheAlarmTest.Test().Printf(_L("Test that the alarm was not written to the file"));
       
   602 	
       
   603 	RArray<TAlarmId> alarmIds;
       
   604 	CleanupClosePushL(alarmIds);
       
   605 	TheAlarmTest.Session().GetAlarmIdListL(alarmIds);
       
   606 	TheAlarmTest.Test().Printf(_L("There should be zero alarms in the queue.  There are %d alarms"), alarmIds.Count());
       
   607 	TheAlarmTest(alarmIds.Count() == 1  || alarmIds.Count()== 0);
       
   608 	if(alarmIds.Count()== 0)
       
   609 		{
       
   610 		TestRTCValueL(Time::NullTTime());
       
   611 		}
       
   612 	CleanupStack::PopAndDestroy(&alarmIds);
       
   613 	}
       
   614 
       
   615 void CAlarmTestApp::TestWakeupFlagPersistanceL()
       
   616 	{
       
   617 	TheAlarmTest.Test().Next(_L("TestWakeupFlagPersistanceL"));
       
   618 
       
   619 	TheAlarmTest.Test().Printf(_L("Create a wakeup alarm"));
       
   620 	TASShdAlarm alarm;
       
   621 	alarm.RepeatDefinition() = EAlarmRepeatDefintionRepeatOnce;
       
   622 	// Set the wakeup flag for the alarm
       
   623 	alarm.SetWakeup(ETrue);
       
   624 	_LIT(KMessage, "Wakeup alarm");
       
   625 	alarm.Message() = KMessage;
       
   626 	alarm.NextDueTime().HomeTime();
       
   627 	alarm.NextDueTime() += TTimeIntervalMinutes(90);
       
   628 	
       
   629 	AddAlarmL(alarm);
       
   630 	User::After(100000);
       
   631 	RestartAlarmServerL();
       
   632 	
       
   633 	TheAlarmTest.Test().Printf(_L("Fetch the wakeup alarm characteristics and make sure the flag is set"));
       
   634 	TASShdAlarm alarm2;
       
   635 	TheAlarmTest.Session().GetAlarmDetails(alarm.Id(), alarm2);
       
   636 	TheAlarmTest(alarm2.IsWakeup());
       
   637 	
       
   638 	DeleteAlarmL(alarm.Id());
       
   639 	
       
   640 	TestRTCValueL(Time::NullTTime());
       
   641 	}
       
   642 
       
   643 
       
   644 void CAlarmTestApp::TestSetWakeupSessionAlarmL()
       
   645 	{
       
   646 	SetTimeZoneL(KLondon);
       
   647 	
       
   648 	TheAlarmTest.Test().Next(_L("TestSetWakeupFlagOnSessionAlarmL"));
       
   649 	
       
   650 	TheAlarmTest.Test().Printf(_L("Create a wakeup alarm"));
       
   651 	TASShdAlarm alarm;
       
   652 	alarm.RepeatDefinition() = EAlarmRepeatDefintionRepeatOnce;
       
   653 	// Set the wakeup flag for the alarm
       
   654 	alarm.SetWakeup(ETrue);
       
   655 	alarm.Characteristics().Set(EAlarmCharacteristicsSessionSpecific);
       
   656 	alarm.Message() = KTestName;
       
   657 	alarm.NextDueTime().HomeTime();
       
   658 	alarm.NextDueTime() += TTimeIntervalMinutes(90);
       
   659 	
       
   660 	TRAPD(err, AddAlarmL(alarm));
       
   661 	
       
   662 	TheAlarmTest(err == KErrArgument);
       
   663 	
       
   664 	alarm.SetWakeup(EFalse);
       
   665 	
       
   666 	TheAlarmTest.Test().Printf(_L("add the session alarm"));
       
   667 	AddAlarmL(alarm);
       
   668 	
       
   669 	TInt setWakeupError1 = TheAlarmTest.Session().SetWakeup(alarm.Id(), ETrue);
       
   670 	
       
   671 	TheAlarmTest(setWakeupError1 == KErrArgument);
       
   672 	
       
   673 	TheAlarmTest.Test().Printf(_L("clear the session specific alarm flag"));
       
   674 	TAlarmCharacteristicsFlags alarmCharacteristicsFlags;
       
   675 	TheAlarmTest.Session().GetAlarmCharacteristics(alarm.Id(), alarmCharacteristicsFlags);
       
   676 	alarmCharacteristicsFlags.Clear(EAlarmCharacteristicsSessionSpecific);
       
   677 	TheAlarmTest.Session().SetAlarmCharacteristics(alarm.Id(), alarmCharacteristicsFlags);
       
   678 	
       
   679 	TheAlarmTest.Test().Printf(_L("make it a wakeup alarm"));
       
   680 	TInt setWakeupError2 = TheAlarmTest.Session().SetWakeup(alarm.Id(), ETrue);
       
   681 	
       
   682 	TheAlarmTest.Test().Printf(_L("set the  session specific alarm flag"));
       
   683 	TheAlarmTest.Session().GetAlarmCharacteristics(alarm.Id(), alarmCharacteristicsFlags);
       
   684 	alarmCharacteristicsFlags.Set(EAlarmCharacteristicsSessionSpecific);
       
   685 	TInt setSessionSpecificError = TheAlarmTest.Session().SetAlarmCharacteristics(alarm.Id(), alarmCharacteristicsFlags);
       
   686 	
       
   687 	TheAlarmTest(setSessionSpecificError == KErrArgument);
       
   688 	
       
   689 	DeleteAlarmL(alarm.Id());
       
   690 	}
       
   691 
       
   692 void CAlarmTestApp::TestDeleteWakeupAlarmL()
       
   693 	{
       
   694 	TheAlarmTest.Test().Next(_L("TestDeleteWakeupAlarmL"));
       
   695 	
       
   696 	TheAlarmTest.Test().Printf(_L("Create a wakeup alarm"));
       
   697 	TASShdAlarm alarm;
       
   698 	alarm.RepeatDefinition() = EAlarmRepeatDefintionRepeatOnce;
       
   699 	// Set the wakeup flag for the alarm
       
   700 	alarm.SetWakeup(ETrue);
       
   701 	alarm.Message() = KTestName;
       
   702 	alarm.NextDueTime().HomeTime();
       
   703 	alarm.NextDueTime() += TTimeIntervalMinutes(90);
       
   704 	
       
   705 	AddAlarmL(alarm);
       
   706 	
       
   707 	DeleteAlarmL(alarm.Id());
       
   708 	
       
   709 	// Test that the RTC is not set
       
   710 	TestRTCValueL(Time::NullTTime());
       
   711 	}
       
   712 
       
   713 void CAlarmTestApp::TestDisableWakeupAlarmL()
       
   714 	{
       
   715 	SetTimeZoneL(KLondon);
       
   716 	
       
   717 	TheAlarmTest.Test().Next(_L("set a wakeup alarm"));
       
   718 	TTime systemLocalTime(TDateTime(2006, EMarch, 3, 12, 0, 0, 0)); // March the 23rd
       
   719 	TTime alarmTimeUTC(TDateTime(2006, EMarch, 6, 12, 0, 0, 0)); // March the 29th
       
   720 	
       
   721 	SetHomeTimeL(systemLocalTime);
       
   722 	
       
   723 	TheAlarmTest.Test().Printf(_L("Create a wakeup alarm"));
       
   724 	TASShdAlarm alarm;
       
   725 	alarm.RepeatDefinition() = EAlarmRepeatDefintionRepeatOnce;
       
   726 	// Set the wakeup flag for the alarm
       
   727 	alarm.SetWakeup(ETrue);
       
   728 	alarm.Message() = KTestName;
       
   729 	alarm.NextDueTime() = alarmTimeUTC; // there is no utc offset in london at this time of year
       
   730 	
       
   731 	AddAlarmL(alarm);
       
   732 	
       
   733 	// test that the rtc is set to the uts alarm time
       
   734 	TestRTCValueL(alarmTimeUTC);
       
   735 	
       
   736 	TheAlarmTest.Test().Printf(_L("Disable the alarm"));
       
   737 	TRequestStatus status;
       
   738 	iPIMTestServer.FileServerNotifyChange(ENotifyAll, status, KAlarmServerFile);
       
   739 	TheAlarmTest.Session().SetAlarmStatus(alarm.Id(), EAlarmStatusDisabled);
       
   740 	User::WaitForRequest(status);
       
   741 	
       
   742 	// test that the RTC is unset now that we have disabled the alarm
       
   743 	TestRTCValueL(Time::NullTTime());
       
   744 	
       
   745 	TheAlarmTest.Test().Printf(_L("Enable the alarm"));
       
   746 	iPIMTestServer.FileServerNotifyChange(ENotifyAll, status, KAlarmServerFile);
       
   747 	TheAlarmTest.Session().SetAlarmStatus(alarm.Id(), EAlarmStatusEnabled);
       
   748 	User::WaitForRequest(status);
       
   749 	
       
   750 	// test that the rtc is set now that we have re-enabled the alarm
       
   751 	TestRTCValueL(alarmTimeUTC);
       
   752 	
       
   753 	DeleteAlarmL(alarm.Id());
       
   754 	}
       
   755 
       
   756 void CAlarmTestApp::TestUnsetWakeupFlagL()
       
   757 	{
       
   758 	SetTimeZoneL(KLondon);
       
   759 	
       
   760 	TheAlarmTest.Test().Next(_L("set a wakeup alarm"));
       
   761 	TTime systemLocalTime(TDateTime(2006, EMarch, 3, 12, 0, 0, 0)); // March the 23rd
       
   762 	TTime alarmTimeUTC(TDateTime(2006, EMarch, 4, 12, 0, 0, 0)); // March the 29th
       
   763 	
       
   764 	SetHomeTimeL(systemLocalTime);
       
   765 	
       
   766 	TheAlarmTest.Test().Printf(_L("Create a wakeup alarm"));
       
   767 	TASShdAlarm alarm;
       
   768 	alarm.RepeatDefinition() = EAlarmRepeatDefintionRepeatOnce;
       
   769 	// Set the wakeup flag for the alarm
       
   770 	alarm.SetWakeup(ETrue);
       
   771 	alarm.Message() = KTestName;
       
   772 	alarm.NextDueTime() = alarmTimeUTC;
       
   773 	
       
   774 	AddAlarmL(alarm);
       
   775 	
       
   776 	// Test that the rtc is set to the utc alarm time
       
   777 	TestRTCValueL(alarmTimeUTC);
       
   778 	
       
   779 	TheAlarmTest.Test().Printf(_L("unset the wakeup flag"));
       
   780 	TRequestStatus status;
       
   781 	iPIMTestServer.FileServerNotifyChange(ENotifyAll, status, KAlarmServerFile);
       
   782 	TheAlarmTest.Session().SetWakeup(alarm.Id(), EFalse);
       
   783 	User::WaitForRequest(status);
       
   784 	
       
   785 	// Test that the rtc is not set now that the alarm is no longer a wakeup alarm
       
   786 	TestRTCValueL(Time::NullTTime());
       
   787 	
       
   788 	TheAlarmTest.Test().Printf(_L("re-set the wakeup flag"));
       
   789 	iPIMTestServer.FileServerNotifyChange(ENotifyAll, status, KAlarmServerFile);
       
   790 	TheAlarmTest.Session().SetWakeup(alarm.Id(), ETrue);
       
   791 	User::WaitForRequest(status);
       
   792 	
       
   793 	// Test that the rtc is set now that the alarm has been set back to a wakeup alarm
       
   794 	TestRTCValueL(alarmTimeUTC);
       
   795 	
       
   796 	DeleteAlarmL(alarm.Id());
       
   797 	}
       
   798 
       
   799 void CAlarmTestApp::TestWakeupAlarmTimeL()
       
   800 	{
       
   801 	TheAlarmTest.Test().Next(_L("Test London over March DST rollover 2006"));
       
   802 	DoTestWakeupAlarmTimeL(TDateTime(2006, EMarch, 22, 12, 0, 0, 0),
       
   803 							TDateTime(2006, EMarch, 28, 12, 0, 0, 0),
       
   804 							60,
       
   805 							KLondon);
       
   806 	
       
   807 	TheAlarmTest.Test().Next(_L("Test London over October DST rollover 2006"));
       
   808 	DoTestWakeupAlarmTimeL(TDateTime(2006, EOctober, 26, 12, 0, 0, 0),
       
   809 							TDateTime(2006, EOctober, 30, 12, 0, 0, 0),
       
   810 							0,
       
   811 							KLondon);
       
   812 	
       
   813 	TheAlarmTest.Test().Next(_L("Test Chicago over April DST rollover 2006"));
       
   814 	DoTestWakeupAlarmTimeL(TDateTime(2006, EApril, 1, 12, 0, 0, 0),
       
   815 							TDateTime(2006, EApril, 5, 12, 0, 0, 0),
       
   816 							-300,
       
   817 							KChicago);
       
   818 	
       
   819 	TheAlarmTest.Test().Next(_L("Test Chicago over October DST rollover 2006"));
       
   820 	DoTestWakeupAlarmTimeL(TDateTime(2006, EOctober, 27, 12, 0, 0, 0),
       
   821 							TDateTime(2006, EOctober, 29, 12, 0, 0, 0),
       
   822 							-360,
       
   823 							KChicago);
       
   824 	
       
   825 	TheAlarmTest.Test().Next(_L("Test Sydney over April DST rollover 2006"));
       
   826 	DoTestWakeupAlarmTimeL(TDateTime(2006, EApril, 1, 12, 0, 0, 0),
       
   827 							TDateTime(2006, EApril, 5, 12, 0, 0, 0),
       
   828 							600,
       
   829 							KSydney);
       
   830 	
       
   831 	TheAlarmTest.Test().Next(_L("Test Sydney over October DST rollover 2006"));
       
   832 	DoTestWakeupAlarmTimeL(TDateTime(2006, EOctober, 27, 12, 0, 0, 0),
       
   833 							TDateTime(2006, EOctober, 29, 12, 0, 0, 0),
       
   834 							660,
       
   835 							KSydney);
       
   836 	
       
   837 	TheAlarmTest.Test().Next(_L("Test Tokyo (there are no DST events in Tokyo)"));
       
   838 	DoTestWakeupAlarmTimeL(TDateTime(2006, EApril, 1, 12, 0, 0, 0),
       
   839 							TDateTime(2006, ENovember, 5, 12, 0, 0, 0),
       
   840 							540,
       
   841 							KTokyo);
       
   842 	}
       
   843 
       
   844 void CAlarmTestApp::DoTestWakeupAlarmTimeL(const TTime& aSystemLocalTime,
       
   845 											const TTime& aAlarmTimeUTC,
       
   846 											TTimeIntervalMinutes aNextUTCOffset,
       
   847 											const TDesC8& aTimeZoneName)
       
   848 	{
       
   849 	SetTimeZoneL(aTimeZoneName);
       
   850 	SetHomeTimeL(aSystemLocalTime);
       
   851 	
       
   852 	TASShdAlarm alarm;
       
   853 	alarm.RepeatDefinition() = EAlarmRepeatDefintionRepeatOnce;
       
   854 	// Set the wakeup flag for the alarm
       
   855 	alarm.SetWakeup(ETrue);
       
   856 	alarm.Message() = KTestName;
       
   857 	// Add the UTC offset from when the alarm will happen to get the local time
       
   858 	alarm.NextDueTime() = aAlarmTimeUTC + aNextUTCOffset;
       
   859 	
       
   860 	AddAlarmL(alarm);
       
   861 	
       
   862 	TestRTCValueL(aAlarmTimeUTC);
       
   863 	
       
   864 	DeleteAlarmL(alarm.Id());
       
   865 	}
       
   866 
       
   867 void CAlarmTestApp::TestFixedAlarmL()
       
   868 	{
       
   869 	SetHomeTimeL(TDateTime(2006, EMarch, 20, 12, 0, 0, 0));
       
   870 	SetTimeZoneL(KLondon);
       
   871 	
       
   872 	TheAlarmTest.Test().Printf(_L("Create fixed a wakeup alarm"));
       
   873 	
       
   874 	TASShdAlarm alarm;
       
   875 	alarm.RepeatDefinition() = EAlarmRepeatDefintionRepeatOnce;
       
   876 	// Set the wakeup flag for the alarm
       
   877 	alarm.SetWakeup(ETrue);
       
   878 	alarm.Message() = KTestName;
       
   879 	
       
   880 	// set the time of the alarm so that it is fixed
       
   881 	alarm.SetUtcNextDueTime(TDateTime(2006, EMarch, 21, 12, 0, 0, 0));
       
   882 	AddAlarmL(alarm);
       
   883 	
       
   884 	TestRTCValueL(TDateTime(2006, EMarch, 21, 12, 0, 0, 0));
       
   885 	
       
   886 	DeleteAlarmL(alarm.Id());
       
   887 	
       
   888 	// set the time of the alarm so that it is fixed
       
   889 	alarm.SetUtcNextDueTime(TDateTime(2006, EApril, 5, 12, 0, 0, 0));
       
   890 	AddAlarmL(alarm);
       
   891 	
       
   892 	TestRTCValueL(TDateTime(2006, EApril, 5, 12, 0, 0, 0));
       
   893 	
       
   894 	DeleteAlarmL(alarm.Id());
       
   895 	}
       
   896 	
       
   897 void CAlarmTestApp::TestSetRTCOnDeviceShutdownL()
       
   898 	{
       
   899 	TheAlarmTest.Test().Next(_L("Test that the RTC is set on device shutdown"));
       
   900 
       
   901 	TASShdAlarm alarm = CreateAlarm(Time::NullTTime(), ETrue);
       
   902 
       
   903 	RProperty property;
       
   904 	CleanupClosePushL(property);
       
   905 	User::LeaveIfError(property.Attach(KAlarmServerUID, KRTCValueKey));
       
   906 	TRequestStatus status;
       
   907 	property.Subscribe(status);
       
   908 
       
   909 	TheAlarmTest.Test().Printf(_L("Add a wakeup alarm"));
       
   910 	User::LeaveIfError(TheAlarmTest.Session().AlarmAdd(alarm));
       
   911 
       
   912 	TheAlarmTest.Test().Printf(_L("Wait for the alarm to be set when it is added"));
       
   913 	User::WaitForRequest(status);
       
   914 
       
   915 	property.Subscribe(status);
       
   916 	SendSsmSystemMessageL(ESsmShutdown);
       
   917 
       
   918 	TheAlarmTest.Test().Printf(_L("Wait for the RTC to be set on shutdown"));
       
   919 	User::WaitForRequest(status);
       
   920 
       
   921 	TheAlarmTest.Test().Printf(_L("Return to a normal system state"));
       
   922 	SendSsmSystemMessageL(ESsmNormal);
       
   923 
       
   924 	User::LeaveIfError(TheAlarmTest.Session().AlarmDelete(alarm.Id()));
       
   925 
       
   926 	CleanupStack::PopAndDestroy(&property);
       
   927 	}
       
   928 
       
   929 void CAlarmTestApp::TestRTCSetOnDSTRolloverL()
       
   930 	{
       
   931 	TheAlarmTest.Test().Next(_L("Test that the RTC is set on DST Rollover"));
       
   932 	
       
   933 	// make sure we are in london
       
   934 	SetTimeZoneL(KLondon);
       
   935 	
       
   936 	// 30 secodns before DST Rollover
       
   937 	SetHomeTimeL(TDateTime(2006, EMarch, 25, 0, 59, 58, 0));
       
   938 
       
   939 	TASShdAlarm alarm;
       
   940 	alarm.RepeatDefinition() = EAlarmRepeatDefintionRepeatOnce;
       
   941 	_LIT(KMessage, "An alarm");
       
   942 	alarm.SetWakeup(ETrue);
       
   943 	alarm.Message() = KMessage;
       
   944 	// 5 seconds after the DST Rollover
       
   945 	alarm.NextDueTime() = TTime(TDateTime(2006, EMarch, 25, 2, 0, 5, 0));
       
   946 
       
   947 	TheAlarmTest.Test().Printf(_L("Add a wakeup alarm"));
       
   948 	AddAlarmL(alarm);
       
   949 	
       
   950 	RProperty property;
       
   951 	CleanupClosePushL(property);
       
   952 	User::LeaveIfError(property.Attach(KAlarmServerUID, KRTCValueKey));
       
   953 	TRequestStatus rtcStatus;
       
   954 	property.Subscribe(rtcStatus);
       
   955 	
       
   956 	RTimer timer;
       
   957 	CleanupClosePushL(timer);
       
   958 	User::LeaveIfError(timer.CreateLocal());
       
   959 	TRequestStatus timerStatus;
       
   960 	// 2 seconds after the DST rollover
       
   961 	timer.After(timerStatus, 4000000);
       
   962 
       
   963 	TheAlarmTest.Test().Printf(_L("Wait for the RTC to be set on the DST rollover"));
       
   964 	User::WaitForRequest(rtcStatus, timerStatus);
       
   965 	
       
   966 	TheAlarmTest.Test().Printf(_L("Test that the RTC was set"));
       
   967 	TheAlarmTest(rtcStatus == KErrNone);
       
   968 	TheAlarmTest.Test().Printf(_L("Test that we did not time out"));
       
   969 	TheAlarmTest(timerStatus == KRequestPending);
       
   970 	
       
   971 	timer.Cancel();
       
   972 	User::WaitForRequest(timerStatus);
       
   973 	TheAlarmTest(timerStatus == KErrCancel);
       
   974 	CleanupStack::PopAndDestroy(&timer);
       
   975 
       
   976 	DeleteAlarmL(alarm.Id());
       
   977 
       
   978 	CleanupStack::PopAndDestroy(&property);
       
   979 	}
       
   980 
       
   981 void CAlarmTestApp::TestRTCSetOnTimeZoneChangeL()
       
   982 	{
       
   983 	TheAlarmTest.Test().Next(_L("Test that the RTC is set on time zone change"));
       
   984 	
       
   985 	// make sure we are in london
       
   986 	SetTimeZoneL(KLondon);
       
   987 	
       
   988 	// 30 secodns before DST Rollover
       
   989 	SetHomeTimeL(TDateTime(2006, EMarch, 25, 0, 59, 58, 0));
       
   990 
       
   991 	TASShdAlarm alarm;
       
   992 	alarm.RepeatDefinition() = EAlarmRepeatDefintionRepeatOnce;
       
   993 	_LIT(KMessage, "An alarm");
       
   994 	alarm.SetWakeup(ETrue);
       
   995 	alarm.Message() = KMessage;
       
   996 	// 5 seconds after the DST Rollover
       
   997 	alarm.NextDueTime() = TTime(TDateTime(2006, EMarch, 25, 2, 0, 5, 0));
       
   998 
       
   999 	TheAlarmTest.Test().Printf(_L("Add a wakeup alarm"));
       
  1000 	AddAlarmL(alarm);
       
  1001 	
       
  1002 	RProperty property;
       
  1003 	CleanupClosePushL(property);
       
  1004 	User::LeaveIfError(property.Attach(KAlarmServerUID, KRTCValueKey));
       
  1005 	TRequestStatus rtcStatus;
       
  1006 	property.Subscribe(rtcStatus);
       
  1007 	
       
  1008 	SetTimeZoneL(KChicago);
       
  1009 
       
  1010 	TheAlarmTest.Test().Printf(_L("Wait for the RTC to be set on the time zone change"));
       
  1011 	User::WaitForRequest(rtcStatus);
       
  1012 	
       
  1013 	TheAlarmTest.Test().Printf(_L("Test that the RTC was set"));
       
  1014 	TheAlarmTest(rtcStatus == KErrNone);
       
  1015 
       
  1016 	DeleteAlarmL(alarm.Id());
       
  1017 
       
  1018 	CleanupStack::PopAndDestroy(&property);
       
  1019 	}
       
  1020 
       
  1021 void CAlarmTestApp::TestRTCSetOnSystemTimeChangeL()
       
  1022 	{
       
  1023 	TheAlarmTest.Test().Next(_L("Test that the RTC is set on system time change"));
       
  1024 	
       
  1025 	// make sure we are in london
       
  1026 	SetTimeZoneL(KLondon);
       
  1027 	
       
  1028 	// 30 secodns before DST Rollover
       
  1029 	SetHomeTimeL(TDateTime(2006, EMarch, 25, 0, 59, 58, 0));
       
  1030 
       
  1031 	TASShdAlarm alarm;
       
  1032 	alarm.RepeatDefinition() = EAlarmRepeatDefintionRepeatOnce;
       
  1033 	_LIT(KMessage, "An alarm");
       
  1034 	alarm.SetWakeup(ETrue);
       
  1035 	alarm.Message() = KMessage;
       
  1036 	// 5 seconds after the DST Rollover
       
  1037 	alarm.NextDueTime() = TTime(TDateTime(2006, EMarch, 25, 3, 0, 5, 0));
       
  1038 
       
  1039 	TheAlarmTest.Test().Printf(_L("Add a wakeup alarm"));
       
  1040 	AddAlarmL(alarm);
       
  1041 	
       
  1042 	RProperty property;
       
  1043 	CleanupClosePushL(property);
       
  1044 	User::LeaveIfError(property.Attach(KAlarmServerUID, KRTCValueKey));
       
  1045 	TRequestStatus rtcStatus;
       
  1046 	property.Subscribe(rtcStatus);
       
  1047 	
       
  1048 	// set the system time to a timejust after the DST rollover
       
  1049 	SetHomeTimeL(TDateTime(2006, EMarch, 25, 2, 0, 5, 0));
       
  1050 	
       
  1051 	TheAlarmTest.Test().Printf(_L("Wait for the RTC to be set on the system time change"));
       
  1052 	User::WaitForRequest(rtcStatus);
       
  1053 	
       
  1054 	TheAlarmTest.Test().Printf(_L("Test that the RTC was set"));
       
  1055 	TheAlarmTest(rtcStatus == KErrNone);
       
  1056 
       
  1057 	DeleteAlarmL(alarm.Id());
       
  1058 
       
  1059 	CleanupStack::PopAndDestroy(&property);
       
  1060 	}
       
  1061 
       
  1062 #ifdef __WINS__
       
  1063 void CAlarmTestApp::TestSnoozeWakeupAlarmL()
       
  1064 	{
       
  1065 	TheAlarmTest.Test().Next(_L("Test snoozing a wakeup alarm"));
       
  1066 	
       
  1067 	const TTime KAlarmTime(TDateTime(2006, EMarch, 25, 12, 0, 0, 0));
       
  1068 	
       
  1069 	SetTimeZoneL(KLondon);
       
  1070 	SetHomeTimeL(KAlarmTime - TTimeIntervalSeconds(1));
       
  1071 	
       
  1072 	// add a wakeup alarm
       
  1073 	TASShdAlarm alarm;
       
  1074 	alarm.RepeatDefinition() = EAlarmRepeatDefintionRepeatOnce;
       
  1075 	_LIT(KMessage, "An alarm");
       
  1076 	alarm.SetWakeup(ETrue);
       
  1077 	alarm.Message() = KMessage;
       
  1078 	alarm.NextDueTime() = KAlarmTime;
       
  1079 	AddAlarmL(alarm);
       
  1080 	
       
  1081 	// wait for it to go off
       
  1082 	TRequestStatus status;
       
  1083 	iClient.NotifyOnAlarm(alarm, status);
       
  1084 	User::WaitForRequest(status);
       
  1085 	
       
  1086 	// subscribe to the RTC
       
  1087 	RProperty property;
       
  1088 	CleanupClosePushL(property);
       
  1089 	User::LeaveIfError(property.Attach(KAlarmServerUID, KRTCValueKey));
       
  1090 	TRequestStatus propertyStatus;
       
  1091 	property.Subscribe(propertyStatus);
       
  1092 	
       
  1093 	// snooze the alarm
       
  1094 	TheAlarmTest.Test().Printf(_L("Snooze the alarm"));
       
  1095 	User::LeaveIfError(iClient.SnoozeAlarm(alarm.Id(), KAlarmTime + TTimeIntervalMinutes(5)));
       
  1096 	
       
  1097 	// wait for the RTC to change
       
  1098 	User::WaitForRequest(propertyStatus);
       
  1099 	CleanupStack::PopAndDestroy(&property);
       
  1100 	
       
  1101 	// make sure the RTC is set for the snooze time
       
  1102 	TestRTCValueL(KAlarmTime + TTimeIntervalMinutes(5));
       
  1103 	
       
  1104 	// delete the alarm
       
  1105 	DeleteAlarmL(alarm.Id());
       
  1106 	}
       
  1107 #endif
       
  1108 
       
  1109 void CAlarmTestApp::TestHeadWakeupAlarmL()
       
  1110 	{
       
  1111 	TheAlarmTest.Test().Next(_L("Test the head wakeup alarm"));
       
  1112 	
       
  1113 	SetTimeZoneL(KLondon);
       
  1114 	SetHomeTimeL(TDateTime(2006, EApril, 9, 12, 0, 0, 0));
       
  1115 	
       
  1116 	// Add a few wakeup alarms
       
  1117 	TASShdAlarm wakeupAlarm1 = CreateAlarm(TDateTime(2006, EApril, 10, 15, 0, 0, 0), ETrue);
       
  1118 	AddAlarmL(wakeupAlarm1);
       
  1119 	TASShdAlarm wakeupAlarm2 = CreateAlarm(TDateTime(2006, EApril, 11, 15, 0, 0, 0), ETrue);
       
  1120 	AddAlarmL(wakeupAlarm2);
       
  1121 	TASShdAlarm wakeupAlarm3 = CreateAlarm(TDateTime(2006, EApril, 12, 15, 0, 0, 0), ETrue);
       
  1122 	AddAlarmL(wakeupAlarm3);
       
  1123 	TASShdAlarm wakeupAlarm4 = CreateAlarm(TDateTime(2006, EApril, 13, 15, 0, 0, 0), ETrue);
       
  1124 	AddAlarmL(wakeupAlarm4);
       
  1125 	
       
  1126 	// Add a few non-wakeup alarms
       
  1127 	TASShdAlarm normAlarm1 = CreateAlarm(TDateTime(2006, EApril, 10, 11, 0, 0, 0), EFalse);
       
  1128 	AddAlarmL(normAlarm1);
       
  1129 	TASShdAlarm normAlarm2 = CreateAlarm(TDateTime(2006, EApril, 11, 11, 0, 0, 0), EFalse);
       
  1130 	AddAlarmL(normAlarm2);
       
  1131 	TASShdAlarm normAlarm3 = CreateAlarm(TDateTime(2006, EApril, 12, 11, 0, 0, 0), EFalse);
       
  1132 	AddAlarmL(normAlarm2);
       
  1133 	TASShdAlarm normAlarm4 = CreateAlarm(TDateTime(2006, EApril, 13, 11, 0, 0, 0), EFalse);
       
  1134 	AddAlarmL(normAlarm4);
       
  1135 	
       
  1136 	
       
  1137 	RProperty property;
       
  1138 	CleanupClosePushL(property);
       
  1139 	User::LeaveIfError(property.Attach(KAlarmServerUID, KRTCValueKey));
       
  1140 	TRequestStatus rtcStatus;
       
  1141 	property.Subscribe(rtcStatus);
       
  1142 	
       
  1143 	// Set system time to somewhere in the middle of the alarms
       
  1144 	SetHomeTimeL(TDateTime(2006, EApril, 12, 9, 0, 0, 0));
       
  1145 	
       
  1146 	// wait for the RTC to change
       
  1147 	User::WaitForRequest(rtcStatus);
       
  1148 	property.Subscribe(rtcStatus);
       
  1149 	
       
  1150 	// test that the head wakeup alarm is set with the RTC and not any other times 
       
  1151 	TestRTCValueL(TDateTime(2006, EApril, 12, 14, 0, 0, 0));
       
  1152 	
       
  1153 	TheAlarmTest.Session().SetAlarmStatus(wakeupAlarm3.Id(), EAlarmStatusDisabled);
       
  1154 	
       
  1155 	User::WaitForRequest(rtcStatus);
       
  1156 	property.Subscribe(rtcStatus);
       
  1157 	
       
  1158 	// test that the second alarm is now set with the RTC
       
  1159 	TestRTCValueL(TDateTime(2006, EApril, 13, 14, 0, 0, 0));
       
  1160 	
       
  1161 	TheAlarmTest.Session().SetAlarmStatus(wakeupAlarm3.Id(), EAlarmStatusEnabled);
       
  1162 	
       
  1163 	User::WaitForRequest(rtcStatus);
       
  1164 	property.Subscribe(rtcStatus);
       
  1165 	
       
  1166 	// test that the first alarm is set with the RTC again
       
  1167 	TestRTCValueL(TDateTime(2006, EApril, 12, 14, 0, 0, 0));
       
  1168 	
       
  1169 	TheAlarmTest.Session().SetWakeup(wakeupAlarm3.Id(), EFalse);
       
  1170 	User::WaitForRequest(rtcStatus);
       
  1171 	property.Subscribe(rtcStatus);
       
  1172 	
       
  1173 	// test that the first alarm is set with the RTC again
       
  1174 	TestRTCValueL(TDateTime(2006, EApril, 13, 14, 0, 0, 0));
       
  1175 	
       
  1176 	TheAlarmTest.Session().SetWakeup(wakeupAlarm3.Id(), ETrue);
       
  1177 	User::WaitForRequest(rtcStatus);
       
  1178 	property.Subscribe(rtcStatus);
       
  1179 	
       
  1180 	// test that the first alarm is set with the RTC again
       
  1181 	TestRTCValueL(TDateTime(2006, EApril, 12, 14, 0, 0, 0));
       
  1182 	
       
  1183 	DeleteAlarmL(wakeupAlarm3.Id());
       
  1184 	
       
  1185 	User::WaitForRequest(rtcStatus);
       
  1186 	
       
  1187 	// test that the second alarm is now set with the RTC
       
  1188 	TestRTCValueL(TDateTime(2006, EApril, 13, 14, 0, 0, 0));
       
  1189 	
       
  1190 	DeleteAllAlarmsL();
       
  1191 	
       
  1192 	CleanupStack::PopAndDestroy(&property);
       
  1193 	}
       
  1194 
       
  1195 void CAlarmTestApp::TestAlarmFileNotWrittenOnTimeZoneChangeL()
       
  1196 	{
       
  1197 	TRequestStatus alarmServerFileStatus;
       
  1198 	iPIMTestServer.FileServerNotifyChange(ENotifyAll, alarmServerFileStatus, KAlarmServerFile);
       
  1199 
       
  1200 	SetTimeZoneL(KSydney);
       
  1201 
       
  1202 	RTimer timer;
       
  1203 	CleanupClosePushL(timer);
       
  1204 	User::LeaveIfError(timer.CreateLocal());
       
  1205 	TRequestStatus timerStatus;
       
  1206 	timer.After(timerStatus, 2000000);
       
  1207 
       
  1208 	TheAlarmTest.Test().Printf(_L("Wait for two seconds"));
       
  1209 
       
  1210 	User::WaitForRequest(alarmServerFileStatus, timerStatus);
       
  1211 
       
  1212 	TheAlarmTest.Test().Printf(_L("Test the timer completed"));
       
  1213 	TheAlarmTest(timerStatus.Int() == KErrNone);
       
  1214 	TheAlarmTest.Test().Printf(_L("Test the alarm server file did not change completed"));
       
  1215 	TheAlarmTest(alarmServerFileStatus.Int() == KRequestPending);
       
  1216 
       
  1217 	iPIMTestServer.FileServerNotifyChangeCancel();
       
  1218 
       
  1219 	User::WaitForRequest(alarmServerFileStatus);
       
  1220 
       
  1221 	CleanupStack::PopAndDestroy(&timer);
       
  1222 
       
  1223 	SetTimeZoneL(KLondon);
       
  1224 	}
       
  1225 
       
  1226 void CAlarmTestApp::TestAlarmFileNotWrittenOnSystemTimeChangeL()
       
  1227 	{
       
  1228 	TRequestStatus alarmServerFileStatus;
       
  1229 	iPIMTestServer.FileServerNotifyChange(ENotifyAll, alarmServerFileStatus, KAlarmServerFile);
       
  1230 
       
  1231 	TTime now;
       
  1232 	now.HomeTime();
       
  1233 	
       
  1234 	SetHomeTimeL(TDateTime(2005, EMarch, 15, 12, 0, 0, 0));
       
  1235 
       
  1236 	RTimer timer;
       
  1237 	CleanupClosePushL(timer);
       
  1238 	User::LeaveIfError(timer.CreateLocal());
       
  1239 	TRequestStatus timerStatus;
       
  1240 	timer.After(timerStatus, 2000000);
       
  1241 
       
  1242 	TheAlarmTest.Test().Printf(_L("Wait for two seconds"));
       
  1243 
       
  1244 	User::WaitForRequest(alarmServerFileStatus, timerStatus);
       
  1245 
       
  1246 	TheAlarmTest.Test().Printf(_L("Test the timer completed"));
       
  1247 	TheAlarmTest(timerStatus.Int() == KErrNone);
       
  1248 	TheAlarmTest.Test().Printf(_L("Test the alarm server file did not change completed"));
       
  1249 	TheAlarmTest(alarmServerFileStatus.Int() == KRequestPending);
       
  1250 
       
  1251 	iPIMTestServer.FileServerNotifyChangeCancel();
       
  1252 
       
  1253 	User::WaitForRequest(alarmServerFileStatus);
       
  1254 
       
  1255 	CleanupStack::PopAndDestroy(&timer);
       
  1256 
       
  1257 	SetHomeTimeL(now);
       
  1258 	}
       
  1259 
       
  1260 void CAlarmTestApp::TestWriteCommandsL(TASShdAlarm& aASShdAlarm, TInt aExpectedError)
       
  1261 	{	
       
  1262 	if (aExpectedError != KErrNone)
       
  1263 		{
       
  1264 		TASShdAlarm alarm = CreateAlarm(Time::NullTTime(), EFalse);
       
  1265 		TheAlarmTest.Test().Printf(_L("AlarmAdd"));
       
  1266 		TInt alarmAddError = TheAlarmTest.Session().AlarmAdd(alarm);
       
  1267 		TheAlarmTest(alarmAddError == aExpectedError);
       
  1268 		}
       
  1269 
       
  1270 	TASShdAlarm alarmAddWithNotification = CreateAlarm(Time::NullTTime(), EFalse);
       
  1271 	TheAlarmTest.Test().Printf(_L("AlarmAddWithNotification"));
       
  1272 	TRequestStatus status;
       
  1273 	TheAlarmTest.Session().AlarmAddWithNotification(status, alarmAddWithNotification);
       
  1274 
       
  1275 	if (aExpectedError != KErrNone)
       
  1276 		{
       
  1277 		// we expected an error so wait for failure with the error code
       
  1278 		User::WaitForRequest(status);
       
  1279 		TheAlarmTest(status.Int() == aExpectedError);
       
  1280 		}
       
  1281 	else
       
  1282 		{
       
  1283 		// the alarm should be added sucessfully so cancel the notification and dequeue it
       
  1284 		TheAlarmTest.Test().Printf(_L("AlarmNotificationCancelAndDequeue"));
       
  1285 		TheAlarmTest.Session().AlarmNotificationCancelAndDequeue(alarmAddWithNotification.Id());
       
  1286 		User::WaitForRequest(status);
       
  1287 		TheAlarmTest(status.Int() == KErrCancel);
       
  1288 		}
       
  1289 
       
  1290 	TheAlarmTest.Test().Printf(_L("AlarmDataAttachL"));
       
  1291 	TInt alarmDataAttachError = TheAlarmTest.Session().AlarmDataAttachL(aASShdAlarm.Id(), KAlarmData);
       
  1292 	TheAlarmTest(alarmDataAttachError == aExpectedError);
       
  1293 
       
  1294 	TheAlarmTest.Test().Printf(_L("AlarmDataDetach"));
       
  1295 	TInt alarmDataDetachError = TheAlarmTest.Session().AlarmDataDetach(aASShdAlarm.Id());
       
  1296 	TheAlarmTest(alarmDataDetachError == aExpectedError);
       
  1297 
       
  1298 	TheAlarmTest.Test().Printf(_L("SetAlarmCharacteristics"));
       
  1299 	TAlarmCharacteristicsFlags alarmCharacteristicsFlags; 
       
  1300 	TInt setAlarmCharacteristicsError = TheAlarmTest.Session().SetAlarmCharacteristics(aASShdAlarm.Id(), alarmCharacteristicsFlags);
       
  1301 	TheAlarmTest(setAlarmCharacteristicsError == aExpectedError);
       
  1302 
       
  1303 	TheAlarmTest.Test().Printf(_L("SetAlarmDayOrTimed"));
       
  1304 	TInt setAlarmDayOrTimedError = TheAlarmTest.Session().SetAlarmDayOrTimed(aASShdAlarm.Id(), EASShdAlarmTypeTimed);
       
  1305 	TheAlarmTest(setAlarmDayOrTimedError == aExpectedError);
       
  1306 
       
  1307 	TheAlarmTest.Test().Printf(_L("SetAlarmPlayIntervalsL"));
       
  1308 	CArrayFix<TASCliSoundPlayDefinition>* intervals = new(ELeave) CArrayFixFlat<TASCliSoundPlayDefinition>(8);
       
  1309 	CleanupStack::PushL(intervals);
       
  1310 	TASCliSoundPlayDefinition soundPlayDefinition1(TTimeIntervalMinutes(0), TTimeIntervalSeconds(30));
       
  1311 	intervals->AppendL(soundPlayDefinition1);
       
  1312 	TASCliSoundPlayDefinition soundPlayDefinition2(TTimeIntervalMinutes(5), TTimeIntervalSeconds(30));
       
  1313 	intervals->AppendL(soundPlayDefinition2);
       
  1314 	TRAPD(setAlarmPlayIntervalsError, TheAlarmTest.Session().SetAlarmPlayIntervalsL(*intervals));
       
  1315 	TheAlarmTest(setAlarmPlayIntervalsError == aExpectedError);
       
  1316 	CleanupStack::PopAndDestroy(intervals);
       
  1317 
       
  1318 	TheAlarmTest.Test().Printf(_L("SetAlarmStatus"));
       
  1319 	TInt setAlarmStatusError = TheAlarmTest.Session().SetAlarmStatus(aASShdAlarm.Id(), EAlarmStatusEnabled);
       
  1320 	TheAlarmTest(setAlarmStatusError == aExpectedError);
       
  1321 
       
  1322 	TheAlarmTest.Test().Printf(_L("SetAlarmStatusByCategory"));
       
  1323 	TInt SetAlarmStatusByCategoryError = TheAlarmTest.Session().SetAlarmStatusByCategory(KAlarmCategory, EAlarmStatusEnabled);
       
  1324 	TheAlarmTest(SetAlarmStatusByCategoryError == aExpectedError);
       
  1325 
       
  1326 	TheAlarmTest.Test().Printf(_L("AlarmDelete"));
       
  1327 	TInt alarmDeleteError = TheAlarmTest.Session().AlarmDelete(aASShdAlarm.Id());
       
  1328 	TheAlarmTest(alarmDeleteError == aExpectedError);
       
  1329 
       
  1330 	if (alarmDeleteError == KErrNone)
       
  1331 		{
       
  1332 		// We deleted the alarm so add it again
       
  1333 		User::LeaveIfError(TheAlarmTest.Session().AlarmAdd(aASShdAlarm));
       
  1334 		}
       
  1335 
       
  1336 	TheAlarmTest.Test().Printf(_L("AlarmDeleteAllByCategory"));
       
  1337 	TInt alarmDeleteAllByCategoryError = TheAlarmTest.Session().AlarmDeleteAllByCategory(KAlarmCategory, EFalse);
       
  1338 	TheAlarmTest(alarmDeleteAllByCategoryError == aExpectedError);
       
  1339 
       
  1340 	TheAlarmTest.Test().Printf(_L("AlarmDeleteByCategory"));
       
  1341 	TInt alarmDeleteByCategoryError = TheAlarmTest.Session().AlarmDeleteByCategory(KAlarmCategory, 0);
       
  1342 	TheAlarmTest(alarmDeleteByCategoryError == aExpectedError);
       
  1343 	}
       
  1344 
       
  1345 void CAlarmTestApp::TestReadCommandsL(TASShdAlarm& aASShdAlarm)
       
  1346 	{	
       
  1347 	TheAlarmTest.Test().Printf(_L("SetClientData"));
       
  1348 	TInt setClientDataError = TheAlarmTest.Session().SetClientData(aASShdAlarm);
       
  1349 	TheAlarmTest(setClientDataError == KErrNone);
       
  1350 
       
  1351 	TheAlarmTest.Test().Printf(_L("SetAlarmSoundState"));
       
  1352 	TInt setAlarmSoundStateError = TheAlarmTest.Session().SetAlarmSoundState(EAlarmGlobalSoundStateOn);
       
  1353 	TheAlarmTest(setAlarmSoundStateError == KErrNone);
       
  1354 
       
  1355 	TheAlarmTest.Test().Printf(_L("SetAlarmSoundsSilentFor"));
       
  1356 	TInt setAlarmSoundsSilentForError = TheAlarmTest.Session().SetAlarmSoundsSilentFor(30);
       
  1357 	TheAlarmTest(setAlarmSoundsSilentForError == KErrNone);
       
  1358 
       
  1359 	TheAlarmTest.Test().Printf(_L("SetAlarmSoundsSilentUntil"));
       
  1360 	TTime silentUntilTime;
       
  1361 	silentUntilTime.HomeTime();
       
  1362 	silentUntilTime += TTimeIntervalMinutes(5);
       
  1363 	TInt setAlarmSoundsSilentUntilError = TheAlarmTest.Session().SetAlarmSoundsSilentUntil(silentUntilTime);
       
  1364 	TheAlarmTest(setAlarmSoundsSilentUntilError == KErrNone);
       
  1365 
       
  1366 	TheAlarmTest.Test().Printf(_L("CancelAlarmSilence"));
       
  1367 	TInt cancelAlarmSilenceError = TheAlarmTest.Session().CancelAlarmSilence();
       
  1368 	TheAlarmTest(cancelAlarmSilenceError == KErrNone);
       
  1369 
       
  1370 	TheAlarmTest.Test().Printf(_L("AlarmCountByState"));
       
  1371 	TInt alarmCountQueued = TheAlarmTest.Session().AlarmCountByState(EAlarmStateQueued);
       
  1372 	TheAlarmTest(alarmCountQueued == 1);
       
  1373 
       
  1374 	TheAlarmTest.Test().Printf(_L("AlarmDataSize"));
       
  1375 	TInt alarmDataSize = TheAlarmTest.Session().AlarmDataSize(aASShdAlarm.Id());
       
  1376 	TheAlarmTest(alarmDataSize == KErrNotFound);
       
  1377 
       
  1378 	TheAlarmTest.Test().Printf(_L("AlarmSoundsTemporarilySilenced"));
       
  1379 	TBool alarmSoundsTemporarilySilenced = TheAlarmTest.Session().AlarmSoundsTemporarilySilenced();
       
  1380 	TheAlarmTest(alarmSoundsTemporarilySilenced == EFalse);
       
  1381 
       
  1382 	TheAlarmTest.Test().Printf(_L("GetAlarmCategory"));
       
  1383 	TAlarmCategory alarmCategory;
       
  1384 	TInt getAlarmCategoryError = TheAlarmTest.Session().GetAlarmCategory(aASShdAlarm.Id(), alarmCategory);
       
  1385 	TheAlarmTest(getAlarmCategoryError == KErrNone);
       
  1386 
       
  1387 	TheAlarmTest.Test().Printf(_L("GetAlarmCharacteristics"));
       
  1388 	TAlarmCharacteristicsFlags TAlarmCharacteristicsFlags;
       
  1389 	TInt getAlarmCharacteristicsError = TheAlarmTest.Session().GetAlarmCharacteristics(aASShdAlarm.Id(), TAlarmCharacteristicsFlags);
       
  1390 	TheAlarmTest(getAlarmCharacteristicsError == KErrNone);
       
  1391 
       
  1392 	TheAlarmTest.Test().Printf(_L("GetAlarmCountForCategory"));
       
  1393 	TInt AlarmCountForCategory = TheAlarmTest.Session().GetAlarmCountForCategory(KAlarmCategory);
       
  1394 	TheAlarmTest(AlarmCountForCategory == 0);
       
  1395 
       
  1396 	TheAlarmTest.Test().Printf(_L("GetAlarmData"));
       
  1397 	HBufC8* sink = NULL;
       
  1398 	TInt getAlarmDataError = TheAlarmTest.Session().GetAlarmData(aASShdAlarm.Id(), sink);
       
  1399 	TheAlarmTest(getAlarmDataError == KErrNone || getAlarmDataError == KErrNotFound);
       
  1400 	delete sink;
       
  1401 
       
  1402 	TheAlarmTest.Test().Printf(_L("GetAlarmDayOrTimed"));
       
  1403 	TAlarmDayOrTimed alarmDayOrTimed;
       
  1404 	TInt getAlarmDayOrTimedError = TheAlarmTest.Session().GetAlarmDayOrTimed(aASShdAlarm.Id(), alarmDayOrTimed);
       
  1405 	TheAlarmTest(getAlarmDayOrTimedError == KErrNone);
       
  1406 
       
  1407 	TheAlarmTest.Test().Printf(_L("GetAlarmDetails"));
       
  1408 	TASShdAlarm alarm;
       
  1409 	TInt getAlarmDetails = TheAlarmTest.Session().GetAlarmDetails(aASShdAlarm.Id(), alarm);
       
  1410 	TheAlarmTest(getAlarmDetails == KErrNone);
       
  1411 
       
  1412 	TheAlarmTest.Test().Printf(_L("GetAlarmIdListByStateL"));
       
  1413 	RArray<TAlarmId> alarmIds;
       
  1414 	CleanupClosePushL(alarmIds);
       
  1415 	TheAlarmTest.Session().GetAlarmIdListByStateL(EAlarmStateQueued, alarmIds);
       
  1416 	TheAlarmTest.Test().Printf(_L("GetAlarmIdListByStateL = %d"), alarmIds.Count());
       
  1417 	TheAlarmTest(alarmIds.Count() == 1);
       
  1418 	alarmIds.Reset();
       
  1419 
       
  1420 	TheAlarmTest.Test().Printf(_L("GetAlarmIdListForCategoryL"));
       
  1421 	TheAlarmTest.Session().GetAlarmIdListForCategoryL(KAlarmCategory, alarmIds);
       
  1422 	TheAlarmTest.Test().Printf(_L("GetAlarmIdListForCategoryL = %d"), alarmIds.Count());	
       
  1423 	TheAlarmTest(alarmIds.Count() == 0);
       
  1424 	alarmIds.Reset();
       
  1425 
       
  1426 	TheAlarmTest.Test().Printf(_L("GetAlarmIdListL"));
       
  1427 	TheAlarmTest.Session().GetAlarmIdListL(alarmIds);
       
  1428 	TheAlarmTest.Test().Printf(_L("GetAlarmIdListL = %d"), alarmIds.Count());	
       
  1429 	TheAlarmTest(alarmIds.Count() == 1);
       
  1430 	CleanupStack::PopAndDestroy(&alarmIds); // alarmIds.Close()
       
  1431 
       
  1432 	TheAlarmTest.Test().Printf(_L("GetAlarmOwner"));
       
  1433 	TFullName fullName;
       
  1434 	TInt getAlarmOwnerError = TheAlarmTest.Session().GetAlarmOwner(aASShdAlarm.Id(), fullName);
       
  1435 	TheAlarmTest(getAlarmOwnerError == KErrNone);
       
  1436 
       
  1437 	TheAlarmTest.Test().Printf(_L("GetAlarmPlayIntervalsL"));
       
  1438 	CArrayFix<TASCliSoundPlayDefinition>* intervals = new(ELeave) CArrayFixFlat<TASCliSoundPlayDefinition>(8);
       
  1439 	CleanupStack::PushL(intervals);
       
  1440 	TheAlarmTest.Session().GetAlarmPlayIntervalsL(*intervals);
       
  1441 	CleanupStack::PopAndDestroy(intervals);
       
  1442 
       
  1443 	TheAlarmTest.Test().Printf(_L("GetAlarmSoundState"));
       
  1444 	TAlarmGlobalSoundState alarmGlobalSoundState;
       
  1445 	TInt getAlarmSoundStateError = TheAlarmTest.Session().GetAlarmSoundState(alarmGlobalSoundState);
       
  1446 	TheAlarmTest(getAlarmSoundStateError == KErrNone);
       
  1447 
       
  1448 	TheAlarmTest.Test().Printf(_L("GetAlarmSoundsSilentUntil"));
       
  1449 	TTime silentUntil;
       
  1450 	TInt getAlarmSoundsSilentUntilError = TheAlarmTest.Session().GetAlarmSoundsSilentUntil(silentUntil);
       
  1451 	TheAlarmTest.Test().Printf(_L("getAlarmSoundsSilentUntilError = %d"), getAlarmSoundsSilentUntilError);	
       
  1452 	//TheAlarmTest(getAlarmSoundsSilentUntilError == KErrNone);
       
  1453 
       
  1454 	TheAlarmTest.Test().Printf(_L("GetAlarmStatus"));
       
  1455 	TAlarmStatus alarmStatus;
       
  1456 	TInt getAlarmStatusError = TheAlarmTest.Session().GetAlarmStatus(aASShdAlarm.Id(), alarmStatus);
       
  1457 	TheAlarmTest(getAlarmStatusError == KErrNone);
       
  1458 
       
  1459 	TheAlarmTest.Test().Printf(_L("GetAvailableCategoryListL"));
       
  1460 	RArray<TAlarmCategory> categories;
       
  1461 	CleanupClosePushL(categories);
       
  1462 	TheAlarmTest.Session().GetAvailableCategoryListL(categories);
       
  1463 	CleanupStack::PopAndDestroy(&categories);
       
  1464 
       
  1465 	TheAlarmTest.Test().Printf(_L("GetNextDueAlarmId"));
       
  1466 	TAlarmId alarmId;
       
  1467 	TInt getNextDueAlarmIdError = TheAlarmTest.Session().GetNextDueAlarmId(alarmId);
       
  1468 	TheAlarmTest(getNextDueAlarmIdError == KErrNone);
       
  1469 
       
  1470 	TheAlarmTest.Test().Printf(_L("NumberOfAlarmsActiveInQueue"));
       
  1471 	TInt numberOfAlarmsActiveInQueue = TheAlarmTest.Session().NumberOfAlarmsActiveInQueue();
       
  1472 	TheAlarmTest.Test().Printf(_L("numberOfAlarmsActiveInQueue = %d"), numberOfAlarmsActiveInQueue);
       
  1473 	}
       
  1474 
       
  1475 void CAlarmTestApp::TestReadOnlyInShutDownL()
       
  1476 	{
       
  1477 	TASShdAlarm alarm = CreateAlarm(Time::NullTTime(), EFalse);
       
  1478 	User::LeaveIfError(TheAlarmTest.Session().AlarmAdd(alarm));
       
  1479 
       
  1480 	SendSsmSystemMessageL(ESsmShutdown);
       
  1481 	TheAlarmTest.Next(_L("Test that write commands leave with locked"));
       
  1482 	TestWriteCommandsL(alarm, KErrLocked);
       
  1483 	TheAlarmTest.Next(_L("Test alarm file not written on time zone change"));
       
  1484 	TestAlarmFileNotWrittenOnTimeZoneChangeL();
       
  1485 	TheAlarmTest.Next(_L("Test alarm file not written on system time change"));
       
  1486 	TestAlarmFileNotWrittenOnSystemTimeChangeL();
       
  1487 	TheAlarmTest.Next(_L("Test that read commands still work"));
       
  1488 	TestReadCommandsL(alarm);
       
  1489 
       
  1490 	SendSsmSystemMessageL(ESsmNormal);
       
  1491 	TheAlarmTest.Next(_L("Test that write commands work again"));
       
  1492 	TestWriteCommandsL(alarm, KErrNone);
       
  1493 	TheAlarmTest.Next(_L("Test that read commands still work"));
       
  1494 	TestReadCommandsL(alarm);
       
  1495 
       
  1496 	User::LeaveIfError(TheAlarmTest.Session().AlarmDelete(alarm.Id()));
       
  1497 	}
       
  1498 #endif
       
  1499 
       
  1500 void CAlarmTestApp::RunTestsL()
       
  1501 	{
       
  1502 	DeleteAllAlarmsL();
       
  1503 	TestAlarmMissingHourRepeatDailyL();
       
  1504 	TestAlarmMissingHourRepeatOnce1L();
       
  1505 	TestAlarmMissingHourRepeatOnce2L();
       
  1506 	TestAlarmMissingHourRepeatOnce3L();
       
  1507 #ifdef SYMBIAN_SYSTEM_STATE_MANAGEMENT
       
  1508 	TestWakeupFlagPersistanceL();
       
  1509 	TestSetWakeupSessionAlarmL();
       
  1510 	TestDeleteWakeupAlarmL();
       
  1511 	TestDisableWakeupAlarmL();
       
  1512 	TestUnsetWakeupFlagL();
       
  1513 	TestWakeupAlarmTimeL();	
       
  1514 	TestWakeupAlarmRobustnessL();
       
  1515 	TestFixedAlarmL();
       
  1516 #ifdef __WINS__
       
  1517 	TestSnoozeWakeupAlarmL();
       
  1518 #endif	
       
  1519 	TestReadOnlyInShutDownL();
       
  1520 	TestSetRTCOnDeviceShutdownL();
       
  1521 	TestRTCSetOnDSTRolloverL();
       
  1522 	TestRTCSetOnTimeZoneChangeL();
       
  1523 	TestRTCSetOnSystemTimeChangeL();
       
  1524 	TestHeadWakeupAlarmL();
       
  1525 #endif
       
  1526 	}
       
  1527 
       
  1528 void doTestL()
       
  1529 	{
       
  1530 	CAlarmTestApp* alarmTestApp = CAlarmTestApp::NewLC();
       
  1531 	alarmTestApp->RunTestsL();
       
  1532 	CleanupStack::PopAndDestroy(alarmTestApp);
       
  1533 	}
       
  1534 
       
  1535 /**
       
  1536 
       
  1537 @SYMTestCaseID PIM-TWAKEUPALARMS-0001
       
  1538 
       
  1539 */
       
  1540 
       
  1541 GLDEF_C TInt E32Main()
       
  1542     {
       
  1543     __UHEAP_MARK;
       
  1544     
       
  1545 	CActiveScheduler* scheduler = new  CActiveScheduler;
       
  1546 	CActiveScheduler::Install(scheduler);
       
  1547 	
       
  1548 	CTrapCleanup* cleanup = CTrapCleanup::New();
       
  1549 	
       
  1550 	TTime now;
       
  1551 	now.HomeTime();
       
  1552 	TheAlarmTest.Title();
       
  1553 	TheAlarmTest.Start(KTestName);
       
  1554 	
       
  1555 	TRAPD(testError, doTestL());
       
  1556 		
       
  1557 	// Check there are no alarm left active
       
  1558 	TInt n=TheAlarmTest.Session().NumberOfAlarmsActiveInQueue();
       
  1559 	TheAlarmTest(n==0, __LINE__);
       
  1560 	
       
  1561     TheAlarmTest.Session().Close();
       
  1562 	TheAlarmTest.EndL();
       
  1563 	TheAlarmTest.Test().Close();
       
  1564 	ASTstAlarmTest::Close();
       
  1565 	
       
  1566 	delete cleanup;
       
  1567 	delete scheduler;
       
  1568 
       
  1569 	__UHEAP_MARKEND;
       
  1570 	
       
  1571 	return testError;
       
  1572     }