commonappservices/alarmserver/Test/TClientSession.cpp
changeset 0 2e3d3ce01487
equal deleted inserted replaced
-1:000000000000 0:2e3d3ce01487
       
     1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include "ASTstAlarmTest.h"
       
    17 
       
    18 // Globals
       
    19 static TRequestStatus TheStatus;
       
    20 
       
    21 // Constants
       
    22 const TAlarmCategory KASCliCategoryTest		= { 0x101F5031 };
       
    23 
       
    24 
       
    25 TAlarmId AddAlarm(TInt aMinutesFromNow, TAlarmCategory aAlarmCategory = KASCliCategoryClock)
       
    26 	{
       
    27 	TBuf<200> testTitle;
       
    28 	testTitle.Format(_L("\nAdding alarm to expire in %d minutes\n"), aMinutesFromNow);
       
    29 	TheAlarmTest.Test().Printf(testTitle);
       
    30 	//
       
    31 	TASShdAlarm alarm;
       
    32 	alarm.Category() = aAlarmCategory;
       
    33 	alarm.RepeatDefinition() = EAlarmRepeatDefintionRepeatOnce;
       
    34 	alarm.NextDueTime().HomeTime();
       
    35 	alarm.NextDueTime() += TTimeIntervalMinutes(aMinutesFromNow);
       
    36 	//
       
    37 	TheAlarmTest(TheAlarmTest.Session().AlarmAdd(alarm) == KErrNone, __LINE__);
       
    38 	const TAlarmId id = alarm.Id();
       
    39 	TheAlarmTest(id != KNullAlarmId, __LINE__);
       
    40 	TAlarmCategory category;
       
    41 	TheAlarmTest.Session().GetAlarmCategory(id, category);
       
    42 	TheAlarmTest(category == aAlarmCategory, __LINE__);
       
    43 
       
    44 	return id;
       
    45 	}
       
    46 
       
    47 TAlarmId AddAlarm(const TTime& aTime, TAlarmCategory aAlarmCategory = KASCliCategoryClock)
       
    48 	{
       
    49 	TheAlarmTest.Test().Printf(_L("\nAdding alarm\n"));
       
    50 	//
       
    51 	TASShdAlarm alarm;
       
    52 	alarm.Category() = aAlarmCategory;
       
    53 	alarm.RepeatDefinition() = EAlarmRepeatDefintionRepeatOnce;
       
    54 	alarm.NextDueTime()=aTime;
       
    55 	//
       
    56 	TheAlarmTest(TheAlarmTest.Session().AlarmAdd(alarm) == KErrNone, __LINE__);
       
    57 	const TAlarmId id = alarm.Id();
       
    58 	TheAlarmTest(id != KNullAlarmId, __LINE__);
       
    59 
       
    60 	return id;
       
    61 	}
       
    62 
       
    63 TAlarmId AddUtcAlarm(TInt aMinutesFromNow, TAlarmCategory aAlarmCategory = KASCliCategoryClock)
       
    64 	{
       
    65 	TBuf<200> testTitle;
       
    66 	testTitle.Format(_L("\nAdding UTC alarm to expire in %d minutes\n"), aMinutesFromNow);
       
    67 	TheAlarmTest.Test().Printf(testTitle);
       
    68 	//
       
    69 	TASShdAlarm alarm;
       
    70 	alarm.Category()=aAlarmCategory;
       
    71 	alarm.RepeatDefinition()=(EAlarmRepeatDefintionRepeatOnce);
       
    72 	TTime time;
       
    73 	time.UniversalTime();
       
    74 	time += TTimeIntervalMinutes(aMinutesFromNow);
       
    75 	alarm.SetUtcNextDueTime(time);
       
    76 	//
       
    77 	TheAlarmTest(TheAlarmTest.Session().AlarmAdd(alarm) == KErrNone, __LINE__);
       
    78 	const TAlarmId id = alarm.Id();
       
    79 	TheAlarmTest(id != KNullAlarmId, __LINE__);
       
    80 	TAlarmCategory category;
       
    81 	TheAlarmTest.Session().GetAlarmCategory(id, category);
       
    82 	TheAlarmTest(category == aAlarmCategory, __LINE__);
       
    83 
       
    84 	return id;
       
    85 	}
       
    86 
       
    87 TAlarmId AddUtcAlarm(const TTime& aTime, TAlarmCategory aAlarmCategory = KASCliCategoryClock)
       
    88 	{
       
    89 	TheAlarmTest.Test().Printf(_L("\nAdding UTC alarm\n"));
       
    90 	//
       
    91 	TASShdAlarm alarm;
       
    92 	alarm.Category()=aAlarmCategory;
       
    93 	alarm.RepeatDefinition()=EAlarmRepeatDefintionRepeatOnce;
       
    94 	alarm.SetUtcNextDueTime(aTime);
       
    95 	//
       
    96 	TheAlarmTest(TheAlarmTest.Session().AlarmAdd(alarm) == KErrNone, __LINE__);
       
    97 	const TAlarmId id = alarm.Id();
       
    98 	TheAlarmTest(id != KNullAlarmId, __LINE__);
       
    99 
       
   100 	return id;
       
   101 	}
       
   102 
       
   103 
       
   104 void WaitForAlarmToExpire()
       
   105 	{
       
   106 #if defined(_DEBUG) || defined(__WINSCW__)
       
   107 	TheAlarmTest.Test().Printf(_L("\nWaiting for alarm to expire...\n"));
       
   108 
       
   109 	TAlarmId alarmId;
       
   110 	TRequestStatus status;
       
   111 	FOREVER
       
   112 		{
       
   113 		TheAlarmTest.Session().NotifyChange(status, alarmId);
       
   114 		User::WaitForRequest(status);
       
   115 		if	(status.Int() == EAlarmChangeEventTimerExpired)
       
   116 			break;
       
   117 		}
       
   118 #endif
       
   119 	}
       
   120 
       
   121 
       
   122 void VerifyStates(TInt aQueued, TInt aNotifying=0, TInt aWaitingToNotify=0, TInt aNotified=0, TInt aSnoozed=0)
       
   123 	{
       
   124 #if defined(_DEBUG) || defined(__WINSCW__)
       
   125 	TInt queued = TheAlarmTest.Session().AlarmCountByState(EAlarmStateQueued);
       
   126 	TInt notifying = TheAlarmTest.Session().AlarmCountByState(EAlarmStateNotifying);
       
   127 	TInt waitingToNotify = TheAlarmTest.Session().AlarmCountByState(EAlarmStateWaitingToNotify);
       
   128 	TInt notified = TheAlarmTest.Session().AlarmCountByState(EAlarmStateNotified);
       
   129 	TInt snoozed = TheAlarmTest.Session().AlarmCountByState(EAlarmStateSnoozed);
       
   130 	//
       
   131 	TheAlarmTest(queued == aQueued, __LINE__);
       
   132 	// When TheAlarmTest.Session().__DbgPreventUserNotify() is set with ETrue (i.e. when
       
   133 	// on target platform), all notifying alarms immediately become notified.
       
   134 #if defined(__WINSCW__)
       
   135 	TheAlarmTest(notifying == aNotifying, __LINE__);
       
   136 	TheAlarmTest(waitingToNotify == aWaitingToNotify, __LINE__);
       
   137 	TheAlarmTest(notified == aNotified, __LINE__);
       
   138 #else   // __WINSCW__
       
   139 	TheAlarmTest(notifying == 0, __LINE__);
       
   140 	TheAlarmTest(waitingToNotify == 0, __LINE__);
       
   141 	TheAlarmTest(notified == aNotified + aWaitingToNotify + aNotifying, __LINE__);
       
   142 #endif  // __WINSCW__
       
   143 	TheAlarmTest(snoozed == aSnoozed, __LINE__);
       
   144 #endif
       
   145 	}
       
   146 
       
   147 void AlarmDeleteAllByCategoryIndirectlyL(TAlarmCategory aCategory)
       
   148 	{
       
   149 	if (TheAlarmTest.Session().GetAlarmCountForCategory(aCategory) == 0)
       
   150 		return;
       
   151 
       
   152 	//get ids of alarms with this category
       
   153 	RArray<TAlarmId> alarmIds;
       
   154 	CleanupClosePushL(alarmIds);
       
   155 
       
   156 	TheAlarmTest.Session().GetAlarmIdListForCategoryL(aCategory, alarmIds);
       
   157 
       
   158 	//delete alarms
       
   159 	for (TInt ii = alarmIds.Count() - 1; ii >= 0; ii--)
       
   160 		{
       
   161 		TheAlarmTest.Session().AlarmDelete(alarmIds[ii]);
       
   162 		TheAlarmTest(TheAlarmTest.Session().GetAlarmCountForCategory(aCategory) == ii, __LINE__);
       
   163 		}
       
   164 
       
   165 	CleanupStack::PopAndDestroy(&alarmIds); // Close array.
       
   166 	}
       
   167 
       
   168 //
       
   169 //
       
   170 //
       
   171 //
       
   172 //
       
   173 
       
   174 
       
   175 static void TestCategorySpecificFunctionalityL()
       
   176 	{
       
   177 	TheAlarmTest.Test().Next(_L("test category specific functionality"));
       
   178 
       
   179 	RArray<TAlarmCategory> categoryList;
       
   180 	CleanupClosePushL(categoryList);
       
   181 
       
   182 	TheAlarmTest.Session().GetAvailableCategoryListL(categoryList);
       
   183 	TheAlarmTest(categoryList.Count() == 0, __LINE__);
       
   184 	categoryList.Reset();
       
   185 
       
   186 	//add 5 alarms with category KASCliCategoryClock 1,3,5,7,9 minutes from now
       
   187 	TAlarmId id = KNullAlarmId;
       
   188 	for (TInt ii=1; ii<=5; ++ii)
       
   189 		{
       
   190 		const TAlarmId allocatedId = AddAlarm(2*ii - 1);
       
   191 		if (id == KNullAlarmId)
       
   192 			{
       
   193 			id = allocatedId;
       
   194 			}
       
   195 		TheAlarmTest(TheAlarmTest.Session().GetAlarmCountForCategory(KASCliCategoryClock) == ii, __LINE__);
       
   196 		}
       
   197 	TheAlarmTest.Session().GetAvailableCategoryListL(categoryList);
       
   198 	TheAlarmTest(categoryList.Count() == 1 && categoryList[0] == KASCliCategoryClock, __LINE__);
       
   199 	categoryList.Reset();
       
   200 
       
   201 	//add 5 alarms with category KASCliCategoryTest 2,4,6,8,10 minutes from now
       
   202 	for (TInt jj=1; jj<=5; ++jj)
       
   203 		{
       
   204 		AddAlarm(2*jj, KASCliCategoryTest);
       
   205 		TheAlarmTest(TheAlarmTest.Session().GetAlarmCountForCategory(KASCliCategoryTest) == jj, __LINE__);
       
   206 		}
       
   207 	TheAlarmTest.Session().GetAvailableCategoryListL(categoryList);
       
   208 	TheAlarmTest(categoryList.Count() == 2, __LINE__);
       
   209 	categoryList.Reset();
       
   210 
       
   211 	VerifyStates(10);
       
   212 	WaitForAlarmToExpire();
       
   213 	VerifyStates(9,1);
       
   214 	WaitForAlarmToExpire();
       
   215 	VerifyStates(8,1,1);
       
   216 
       
   217 	//delete all KASCliCategoryTest alarms
       
   218 	AlarmDeleteAllByCategoryIndirectlyL(KASCliCategoryTest);
       
   219 	TheAlarmTest.Session().GetAvailableCategoryListL(categoryList);
       
   220 	TheAlarmTest(categoryList.Count() == 1 && categoryList[0] == KASCliCategoryClock, __LINE__);
       
   221 	categoryList.Reset();
       
   222 
       
   223 	//delete all KASCliCategoryClock alarms
       
   224 	TheAlarmTest.Session().AlarmDeleteAllByCategory(KASCliCategoryClock, EFalse);
       
   225 	TheAlarmTest.Session().GetAvailableCategoryListL(categoryList);
       
   226 	TheAlarmTest(categoryList.Count() == 0, __LINE__);
       
   227 
       
   228     TheAlarmTest.TestClearStoreL();
       
   229 
       
   230 	CleanupStack::PopAndDestroy(&categoryList); // Close array.
       
   231 	}
       
   232 
       
   233 
       
   234 void TestOverlappingAlarmsL()
       
   235 	{
       
   236 	TheAlarmTest.Test().Next(_L("test overlapping alarms"));
       
   237 
       
   238 	//schedule 3 alarms for the same time
       
   239 	TTime time;
       
   240 	time.HomeTime();
       
   241 	time += TTimeIntervalSeconds(10);
       
   242 	for(TInt ii=0; ii<3; ii++)
       
   243 		{
       
   244 		AddAlarm(time);
       
   245 		}
       
   246 
       
   247 	VerifyStates(3);
       
   248 	WaitForAlarmToExpire();
       
   249 	User::After(1000000);
       
   250 	VerifyStates(0,1,2);
       
   251 
       
   252 	TheAlarmTest.TestClearStoreL();
       
   253     TRequestStatus status;
       
   254     TAlarmId alarmId;
       
   255     TheAlarmTest.WaitForNotificationBufferToBeEmptied(status, alarmId);
       
   256 
       
   257 	time.HomeTime();
       
   258 	time += TTimeIntervalSeconds(10);
       
   259 	TAlarmId id1 = AddAlarm(time);
       
   260 	time += TTimeIntervalSeconds(10);
       
   261 	TAlarmId id2 = AddAlarm(time);
       
   262 
       
   263 	TASShdAlarm alarm1;
       
   264 	TASShdAlarm alarm2;
       
   265 
       
   266 #if defined(_DEBUG)
       
   267 	WaitForAlarmToExpire();
       
   268 	TheAlarmTest(TheAlarmTest.Session().GetAlarmDetails(id1, alarm1) == KErrNone, __LINE__);
       
   269 	TheAlarmTest(TheAlarmTest.Session().GetAlarmDetails(id2, alarm2) == KErrNone, __LINE__);
       
   270 #if defined(__WINSCW__)
       
   271 	TheAlarmTest(alarm1.State() == EAlarmStateNotifying, __LINE__);
       
   272 	TheAlarmTest(alarm2.State() == EAlarmStateQueued, __LINE__);
       
   273 #else
       
   274 	TheAlarmTest(alarm1.State() == EAlarmStateNotified, __LINE__);
       
   275 	TheAlarmTest(alarm2.State() == EAlarmStateQueued, __LINE__);
       
   276 #endif
       
   277 
       
   278 	WaitForAlarmToExpire();
       
   279 	TheAlarmTest(TheAlarmTest.Session().GetAlarmDetails(id1, alarm1) == KErrNone, __LINE__);
       
   280 	TheAlarmTest(TheAlarmTest.Session().GetAlarmDetails(id2, alarm2) == KErrNone, __LINE__);
       
   281 #if defined(__WINSCW__)
       
   282 	TheAlarmTest(alarm1.State() == EAlarmStateNotifying, __LINE__);
       
   283 	TheAlarmTest(alarm2.State() == EAlarmStateWaitingToNotify, __LINE__);
       
   284 #else
       
   285 	TheAlarmTest(alarm1.State() == EAlarmStateNotified, __LINE__);
       
   286 	TheAlarmTest(alarm2.State() == EAlarmStateNotified, __LINE__);
       
   287 #endif
       
   288 #endif
       
   289 
       
   290 	TheAlarmTest.TestClearStoreL();
       
   291 	}
       
   292 
       
   293 
       
   294 void  TestAlarmDetails1L()
       
   295 	{
       
   296 	TheAlarmTest.Test().Next(_L("test alarm details - 1"));
       
   297 
       
   298 	TheAlarmTest.TestClearStoreL();
       
   299 
       
   300 	TInt id = AddAlarm(1);
       
   301 
       
   302 	TAlarmStatus status;
       
   303 	TheAlarmTest(TheAlarmTest.Session().GetAlarmStatus(id, status) == KErrNone, __LINE__);
       
   304 	TheAlarmTest(status == EAlarmStatusEnabled, __LINE__);
       
   305 	TheAlarmTest(TheAlarmTest.Session().SetAlarmStatus(id, EAlarmStatusDisabled) == KErrNone, __LINE__);
       
   306 	TheAlarmTest(TheAlarmTest.Session().GetAlarmStatus(id, status) == KErrNone, __LINE__);
       
   307 	TheAlarmTest(status == EAlarmStatusDisabled, __LINE__);
       
   308 	TheAlarmTest(TheAlarmTest.Session().SetAlarmStatusByCategory(KASCliCategoryClock, EAlarmStatusEnabled) == KErrNone, __LINE__);
       
   309 	TheAlarmTest(TheAlarmTest.Session().GetAlarmStatus(id, status) == KErrNone, __LINE__);
       
   310 	TheAlarmTest(status == EAlarmStatusEnabled, __LINE__);
       
   311 
       
   312 	WaitForAlarmToExpire();
       
   313 
       
   314 	TheAlarmTest.Session().AlarmDelete(id);
       
   315 	}
       
   316 	
       
   317 void TestAlarmDetails2L()
       
   318 	{
       
   319 	TheAlarmTest.Test().Next(_L("test alarm details - 2"));
       
   320 	//******************************************************************************
       
   321 	// tests
       
   322 	//
       
   323 	// AlarmAddL
       
   324 	// AlarmDeleteL
       
   325 	// AlarmCountByCategory
       
   326 	// AlarmCountByState
       
   327 	// AlarmIdListByStateLC
       
   328 	//******************************************************************************
       
   329 	TheAlarmTest.TestClearStoreL();
       
   330 
       
   331 	RArray<TAlarmId> alarmIds;
       
   332 	CleanupClosePushL(alarmIds);
       
   333 
       
   334 	//add 10 alarms (category KASCliCategoryClock)
       
   335 	for(TInt ii=1; ii<=10; ii++)
       
   336 		{
       
   337 		TInt minutesFromNow = (ii);
       
   338 		TAlarmId id = AddAlarm(minutesFromNow);
       
   339 		alarmIds.AppendL(id);
       
   340 
       
   341 		TInt numberOfAlarms = TheAlarmTest.Session().GetAlarmCountForCategory(KASCliCategoryClock);
       
   342 		TheAlarmTest(numberOfAlarms == ii, __LINE__);
       
   343 		}
       
   344 
       
   345 	//check states of alarms
       
   346 	TInt alarmCount=0;
       
   347 	//states should be:
       
   348 	// 10 x EAlarmStateQueued
       
   349 	alarmCount = TheAlarmTest.Session().AlarmCountByState(EAlarmStateQueued);
       
   350 	TheAlarmTest(alarmCount == 10, __LINE__);
       
   351 
       
   352 #if defined(_DEBUG)
       
   353 #if defined(__WINSCW__)
       
   354 	//wait for alarm to expire
       
   355 	WaitForAlarmToExpire();
       
   356 	//states should be:
       
   357 	// 1 x EAlarmStateNotifying
       
   358 	// 9 x EAlarmStateQueued
       
   359 	alarmCount = TheAlarmTest.Session().AlarmCountByState(EAlarmStateNotifying);
       
   360 	TheAlarmTest(alarmCount == 1, __LINE__);
       
   361 	alarmCount = TheAlarmTest.Session().AlarmCountByState(EAlarmStateQueued);
       
   362 	TheAlarmTest(alarmCount == 9, __LINE__);
       
   363 
       
   364 	//wait for another alarm to expire
       
   365 	WaitForAlarmToExpire();
       
   366 	//states should be:
       
   367 	// 1 x EAlarmStateNotifying
       
   368 	// 1 x EAlarmStateWaitingToNotify
       
   369 	// 8 x EAlarmStateQueued
       
   370 	alarmCount = TheAlarmTest.Session().AlarmCountByState(EAlarmStateNotifying);
       
   371 	TheAlarmTest(alarmCount == 1, __LINE__);
       
   372 	alarmCount = TheAlarmTest.Session().AlarmCountByState(EAlarmStateWaitingToNotify);
       
   373 	TheAlarmTest(alarmCount == 1, __LINE__);
       
   374 	alarmCount = TheAlarmTest.Session().AlarmCountByState(EAlarmStateQueued);
       
   375 	TheAlarmTest(alarmCount == 8, __LINE__);
       
   376 
       
   377 	//last 8 alarms in our array should correspond to array of alarms with state queued
       
   378 	RArray<TAlarmId> alarmsWithStateQueued;
       
   379 	CleanupClosePushL(alarmsWithStateQueued);
       
   380 
       
   381 	TheAlarmTest.Session().GetAlarmIdListByStateL(EAlarmStateQueued, alarmsWithStateQueued);
       
   382 		for(TInt jj=0; jj<8; jj++)
       
   383 		{
       
   384 		TheAlarmTest(alarmIds[jj+2] == alarmsWithStateQueued[jj], __LINE__);
       
   385 		}
       
   386 
       
   387 	CleanupStack::PopAndDestroy(&alarmsWithStateQueued);    // Close array.
       
   388 #else
       
   389 	//wait for alarm to expire
       
   390 	WaitForAlarmToExpire();
       
   391 	//states should be:
       
   392 	// 1 x EAlarmStateNotified
       
   393 	// 9 x EAlarmStateQueued
       
   394 	alarmCount = TheAlarmTest.Session().AlarmCountByState(EAlarmStateNotified);
       
   395 	TheAlarmTest(alarmCount == 1, __LINE__);
       
   396 	alarmCount = TheAlarmTest.Session().AlarmCountByState(EAlarmStateQueued);
       
   397 	TheAlarmTest(alarmCount == 9, __LINE__);
       
   398 
       
   399 	//wait for another alarm to expire
       
   400 	WaitForAlarmToExpire();
       
   401 	//states should be:
       
   402 	// 2 x EAlarmStateNotified
       
   403 	// 8 x EAlarmStateQueued
       
   404 	alarmCount = TheAlarmTest.Session().AlarmCountByState(EAlarmStateNotified);
       
   405 	TheAlarmTest(alarmCount == 2, __LINE__);
       
   406 	alarmCount = TheAlarmTest.Session().AlarmCountByState(EAlarmStateQueued);
       
   407 	TheAlarmTest(alarmCount == 8, __LINE__);
       
   408 
       
   409 	//last 8 alarms in our array should correspond to array of alarms with state queued
       
   410 	RArray<TAlarmId> alarmsWithStateQueued;
       
   411 	CleanupClosePushL(alarmsWithStateQueued);
       
   412 
       
   413 	TheAlarmTest.Session().GetAlarmIdListByStateL(EAlarmStateQueued, alarmsWithStateQueued);
       
   414 		for(TInt jj=0; jj<8; jj++)
       
   415 		{
       
   416 		TheAlarmTest(alarmIds[jj+2] == alarmsWithStateQueued[jj], __LINE__);
       
   417 		}
       
   418 
       
   419 	CleanupStack::PopAndDestroy(&alarmsWithStateQueued);    // Close array.
       
   420 #endif
       
   421 #endif
       
   422 
       
   423 	//delete all alarms individually
       
   424 	for (TInt count = alarmIds.Count() - 1; count >= 0; count--)
       
   425 		{
       
   426 		TheAlarmTest.Session().AlarmDelete(alarmIds[count]);
       
   427 		}
       
   428 
       
   429 	CleanupStack::PopAndDestroy(&alarmIds);    // Close array.
       
   430 	}
       
   431 
       
   432 
       
   433 void TestAlarmDetails3L()
       
   434 	{
       
   435 	TheAlarmTest.Test().Next(_L("test alarm details - 3"));
       
   436 	//******************************************************************************
       
   437 	// tests
       
   438 	//
       
   439 	// AlarmDetailsL
       
   440 	// AlarmCategoryL
       
   441 	// SetAlarmStatusByCategoryL
       
   442 	// AlarmCountByCategory
       
   443 	// DeleteAllAlarmsByCategoryL
       
   444 	// AlarmCategoryListLC
       
   445 	// AlarmIdListByCategoryLC
       
   446 	// SetAlarmStatusL
       
   447 	// AlarmStatus
       
   448 	//******************************************************************************
       
   449 	TheAlarmTest.TestClearStoreL();
       
   450 
       
   451 	//add 5 alarms with category KASCliCategoryClock
       
   452 	for(TInt ii=1; ii<=5; ii++)
       
   453 		{
       
   454 		AddAlarm(ii, KASCliCategoryClock);
       
   455 		}
       
   456 
       
   457 	//get list of categories - should contain only KASCliCategoryClock
       
   458 	RArray<TAlarmCategory> alarmCategories;
       
   459 	CleanupClosePushL(alarmCategories);
       
   460 
       
   461 	TheAlarmTest.Session().GetAvailableCategoryListL(alarmCategories);
       
   462 	TheAlarmTest(alarmCategories.Count() == 1 && alarmCategories[0] == KASCliCategoryClock, __LINE__);
       
   463 
       
   464 	//add 5 alarms with category KASCliCategoryTest
       
   465 	for(TInt jj=1; jj<=5; jj++)
       
   466 		{
       
   467 		AddAlarm(jj, KASCliCategoryTest);
       
   468 		}
       
   469 
       
   470 	alarmCategories.Reset();
       
   471 	TheAlarmTest.Session().GetAvailableCategoryListL(alarmCategories);
       
   472 	TheAlarmTest(alarmCategories.Count() == 2, __LINE__);
       
   473 
       
   474 	CleanupStack::PopAndDestroy(&alarmCategories);    // Close array.
       
   475 
       
   476 	//add another 10 alarms with category KASCliCategoryClock
       
   477 	for(TInt kk=1; kk<=10; kk++)
       
   478 		{
       
   479 		AddAlarm(kk, KASCliCategoryClock);
       
   480 		}
       
   481 
       
   482 	//get alarms with category KASCliCategoryClock
       
   483 	RArray<TAlarmId> alarms;
       
   484 	CleanupClosePushL(alarms);
       
   485 
       
   486 	TheAlarmTest.Session().GetAlarmIdListForCategoryL(KASCliCategoryClock, alarms);
       
   487 	TInt count = alarms.Count();
       
   488 	TheAlarmTest(count == 15, __LINE__);
       
   489 	//check each alarm has category KASCliCategoryClock
       
   490 	for(TInt mm=0; mm<15; mm++)
       
   491 		{
       
   492 		//directly
       
   493 		TAlarmCategory category;
       
   494 		TheAlarmTest(TheAlarmTest.Session().GetAlarmCategory(alarms[mm], category) == KErrNone, __LINE__);
       
   495 		TheAlarmTest(category == KASCliCategoryClock, __LINE__);
       
   496 		//indirectly
       
   497 		TASShdAlarm alarm;
       
   498 		TheAlarmTest(TheAlarmTest.Session().GetAlarmDetails(alarms[mm], alarm) == KErrNone, __LINE__);
       
   499 		TheAlarmTest(alarm.Category() == KASCliCategoryClock, __LINE__);
       
   500 		}
       
   501 
       
   502 	CleanupStack::PopAndDestroy(&alarms);    // Close array.
       
   503 
       
   504 	//should now have 15 alarms with category KASCliCategoryClock and 5 with category KASCliCategoryTest
       
   505 	TheAlarmTest(TheAlarmTest.Session().GetAlarmCountForCategory(KASCliCategoryClock)==15 &&
       
   506 		TheAlarmTest.Session().GetAlarmCountForCategory(KASCliCategoryTest)==5, __LINE__);
       
   507 	//disable all KASCliCategoryClock alarms
       
   508 	TheAlarmTest.Session().SetAlarmStatusByCategory(KASCliCategoryClock, EAlarmStatusDisabled);
       
   509 	TheAlarmTest(TheAlarmTest.Session().NumberOfAlarmsActiveInQueue()==5, __LINE__);
       
   510 	//try to delete all KASCliCategoryTest orphaned alarms (should be none)
       
   511 	TheAlarmTest.Session().AlarmDeleteAllByCategory(KASCliCategoryTest, ETrue);
       
   512 	TheAlarmTest(TheAlarmTest.Session().NumberOfAlarmsActiveInQueue()==5, __LINE__);
       
   513 	//delete all KASCliCategoryTest alarms
       
   514 	TheAlarmTest.Session().AlarmDeleteAllByCategory(KASCliCategoryTest, EFalse);
       
   515 	TheAlarmTest(TheAlarmTest.Session().NumberOfAlarmsActiveInQueue()==0, __LINE__);
       
   516 	//re-enable the KASCliCategoryClock alarms
       
   517 	TheAlarmTest.Session().SetAlarmStatusByCategory(KASCliCategoryClock, EAlarmStatusEnabled);
       
   518 	TheAlarmTest(TheAlarmTest.Session().NumberOfAlarmsActiveInQueue()==15, __LINE__);
       
   519 	//create a new enabled alarm
       
   520 	TAlarmId id = AddAlarm(1, KASCliCategoryClock);
       
   521 	TheAlarmTest(TheAlarmTest.Session().NumberOfAlarmsActiveInQueue()==16, __LINE__);
       
   522 	//check status
       
   523 	TAlarmStatus status;
       
   524 	TheAlarmTest(TheAlarmTest.Session().GetAlarmStatus(id, status) == KErrNone, __LINE__);
       
   525 	TheAlarmTest(status == EAlarmStatusEnabled, __LINE__);
       
   526 	//disable it
       
   527 	TheAlarmTest.Session().SetAlarmStatus(id, EAlarmStatusDisabled);
       
   528 	TheAlarmTest(TheAlarmTest.Session().NumberOfAlarmsActiveInQueue()==15, __LINE__);
       
   529 	TheAlarmTest(TheAlarmTest.Session().GetAlarmStatus(id, status) == KErrNone, __LINE__);
       
   530 	TheAlarmTest(status == EAlarmStatusDisabled, __LINE__);
       
   531 
       
   532 	//delete all remaining alarms
       
   533 	TheAlarmTest.Session().AlarmDeleteAllByCategory(KASCliCategoryClock, EFalse);
       
   534 	TheAlarmTest(TheAlarmTest.Session().NumberOfAlarmsActiveInQueue()==0, __LINE__);
       
   535 	}
       
   536 
       
   537 void TestDeleteSnoozedAlarmL()
       
   538 	{
       
   539 	TheAlarmTest.Test().Next(_L("test delete snoozed agenda alarm"));
       
   540 	//******************************************************************************
       
   541 	// tests
       
   542 	//
       
   543 	// AlarmDeleteByCategory
       
   544 	//******************************************************************************
       
   545 	TheAlarmTest.TestClearStoreL();
       
   546 
       
   547 	//add 1 alarm with category KUidAgendaModelAlarmCategory
       
   548 
       
   549 	const TUid KUidAgendaModelAlarmCategory = { 0x101F4A70 };
       
   550 	TAlarmId id=AddAlarm(1, KUidAgendaModelAlarmCategory);
       
   551 	TheAlarmTest(TheAlarmTest.Session().NumberOfAlarmsActiveInQueue()==1, __LINE__);
       
   552 	User::After(1000000 * 61);
       
   553 	TTime now;
       
   554 	now.UniversalTime();
       
   555 	TTime timeToSnoozeUntil = now+ TTimeIntervalMinutes(1);
       
   556 	TheAlarmTest(TheAlarmTest.Session().__DbgSnoozeAlarm(id, timeToSnoozeUntil) == KErrNone);
       
   557 
       
   558 	TDeleteType whatToDelete=0;
       
   559 	whatToDelete=EFuture|EExpired;
       
   560 	User::LeaveIfError(TheAlarmTest.Session().AlarmDeleteByCategory(KUidAgendaModelAlarmCategory, whatToDelete));
       
   561 	TheAlarmTest(TheAlarmTest.Session().NumberOfAlarmsActiveInQueue()==1, __LINE__);
       
   562 
       
   563 	//delete all alarms
       
   564 	TheAlarmTest.Session().AlarmDeleteAllByCategory(KUidAgendaModelAlarmCategory, EFalse);
       
   565 	TheAlarmTest(TheAlarmTest.Session().NumberOfAlarmsActiveInQueue()==0, __LINE__);
       
   566 	}
       
   567 
       
   568 	
       
   569 static void TestCategorySpecificFunctionalityUtcL()
       
   570 	{
       
   571 	TheAlarmTest.Test().Next(_L("test category specific functionality for UTC alarms"));
       
   572 
       
   573 	RArray<TAlarmCategory> categoryList;
       
   574 	CleanupClosePushL(categoryList);
       
   575 
       
   576 	TheAlarmTest.Session().GetAvailableCategoryListL(categoryList);
       
   577 	TheAlarmTest(categoryList.Count() == 0, __LINE__);
       
   578 	categoryList.Reset();
       
   579 
       
   580 	//add 5 alarms with category KASCliCategoryClock 1,3,5,7,9 minutes from now
       
   581 	TAlarmId id = KNullAlarmId;
       
   582 	for (TInt ii=1; ii<=5; ++ii)
       
   583 		{
       
   584 		const TAlarmId allocatedId = AddUtcAlarm(2*ii - 1);
       
   585 		if (id == KNullAlarmId)
       
   586 			{
       
   587 			id = allocatedId;
       
   588 			}
       
   589 		TheAlarmTest(TheAlarmTest.Session().GetAlarmCountForCategory(KASCliCategoryClock) == ii, __LINE__);
       
   590 		}
       
   591 	TheAlarmTest.Session().GetAvailableCategoryListL(categoryList);
       
   592 	TheAlarmTest(categoryList.Count() == 1 && categoryList[0] == KASCliCategoryClock, __LINE__);
       
   593 	categoryList.Reset();
       
   594 
       
   595 	//add 5 alarms with category KASCliCategoryTest 2,4,6,8,10 minutes from now
       
   596 	for (TInt jj=1; jj<=5; ++jj)
       
   597 		{
       
   598 		AddUtcAlarm(2*jj, KASCliCategoryTest);
       
   599 		TheAlarmTest(TheAlarmTest.Session().GetAlarmCountForCategory(KASCliCategoryTest) == jj, __LINE__);
       
   600 		}
       
   601 	TheAlarmTest.Session().GetAvailableCategoryListL(categoryList);
       
   602 	TheAlarmTest(categoryList.Count() == 2, __LINE__);
       
   603 	categoryList.Reset();
       
   604 
       
   605 	VerifyStates(10);
       
   606 	WaitForAlarmToExpire();
       
   607 	VerifyStates(9,1);
       
   608 	WaitForAlarmToExpire();
       
   609 	VerifyStates(8,1,1);
       
   610 
       
   611 	//delete all KASCliCategoryTest alarms
       
   612 	AlarmDeleteAllByCategoryIndirectlyL(KASCliCategoryTest);
       
   613 	TheAlarmTest.Session().GetAvailableCategoryListL(categoryList);
       
   614 	TheAlarmTest(categoryList.Count() == 1 && categoryList[0] == KASCliCategoryClock, __LINE__);
       
   615 	categoryList.Reset();
       
   616 
       
   617 	//delete all KASCliCategoryClock alarms
       
   618 	TheAlarmTest.Session().AlarmDeleteAllByCategory(KASCliCategoryClock, EFalse);
       
   619 	TheAlarmTest.Session().GetAvailableCategoryListL(categoryList);
       
   620 	TheAlarmTest(categoryList.Count() == 0, __LINE__);
       
   621 
       
   622 	CleanupStack::PopAndDestroy(&categoryList);    // Close array.
       
   623 	}
       
   624 
       
   625 
       
   626 void TestOverlappingUtcAlarmsL()
       
   627 	{
       
   628 	TheAlarmTest.Test().Next(_L("test overlapping alarms"));
       
   629 
       
   630 	//schedule 3 alarms for the same time
       
   631 	TTime time;
       
   632 	// TASShdAlarm::SetUtcNextDueTime(TTime aUtcTime), therefore can't use time.HomeTime()
       
   633 	time.UniversalTime();
       
   634 	time += TTimeIntervalSeconds(10);
       
   635 	for(TInt ii=0; ii<3; ii++)
       
   636 		{
       
   637 		AddUtcAlarm(time);
       
   638 		}
       
   639 
       
   640 	VerifyStates(3);
       
   641 	WaitForAlarmToExpire();
       
   642 	VerifyStates(0,1,2);
       
   643 
       
   644 	TheAlarmTest.TestClearStoreL();
       
   645 	TRequestStatus status;
       
   646 	TAlarmId alarmId;
       
   647 	TheAlarmTest.WaitForNotificationBufferToBeEmptied(status, alarmId);
       
   648 
       
   649 	// TASShdAlarm::SetUtcNextDueTime(TTime aUtcTime), therefore can't use time.HomeTime()
       
   650 	time.UniversalTime();
       
   651 	time += TTimeIntervalSeconds(10);
       
   652 	TAlarmId id1 = AddUtcAlarm(time);
       
   653 	time += TTimeIntervalSeconds(10);
       
   654 	TAlarmId id2 = AddUtcAlarm(time);
       
   655 
       
   656 	TASShdAlarm alarm1;
       
   657 	TASShdAlarm alarm2;
       
   658 
       
   659 #if defined(_DEBUG)
       
   660 	WaitForAlarmToExpire();
       
   661 	TheAlarmTest(TheAlarmTest.Session().GetAlarmDetails(id1, alarm1) == KErrNone, __LINE__);
       
   662 	TheAlarmTest(TheAlarmTest.Session().GetAlarmDetails(id2, alarm2) == KErrNone, __LINE__);
       
   663 #if defined(__WINSCW__)
       
   664 	TheAlarmTest(alarm1.State() == EAlarmStateNotifying, __LINE__);
       
   665 	TheAlarmTest(alarm2.State() == EAlarmStateQueued, __LINE__);
       
   666 #else
       
   667 	TheAlarmTest(alarm1.State() == EAlarmStateNotified, __LINE__);
       
   668 	TheAlarmTest(alarm2.State() == EAlarmStateQueued, __LINE__);
       
   669 #endif
       
   670 
       
   671 	WaitForAlarmToExpire();
       
   672 	TheAlarmTest(TheAlarmTest.Session().GetAlarmDetails(id1, alarm1) == KErrNone, __LINE__);
       
   673 	TheAlarmTest(TheAlarmTest.Session().GetAlarmDetails(id2, alarm2) == KErrNone, __LINE__);
       
   674 #if defined(__WINSCW__)
       
   675 	TheAlarmTest(alarm1.State() == EAlarmStateNotifying, __LINE__);
       
   676 	TheAlarmTest(alarm2.State() == EAlarmStateWaitingToNotify, __LINE__);
       
   677 #else
       
   678 	TheAlarmTest(alarm1.State() == EAlarmStateNotified, __LINE__);
       
   679 	TheAlarmTest(alarm2.State() == EAlarmStateNotified, __LINE__);
       
   680 #endif
       
   681 #endif
       
   682 
       
   683 	TheAlarmTest.TestClearStoreL();
       
   684 	}
       
   685 
       
   686 
       
   687 void TestUtcAlarmDetails1L()
       
   688 	{
       
   689 	TheAlarmTest.Test().Next(_L("test alarm details - 1"));
       
   690 
       
   691 	TheAlarmTest.TestClearStoreL();
       
   692 
       
   693 	TInt id = AddUtcAlarm(1);
       
   694 
       
   695 	TAlarmStatus status;
       
   696 	TheAlarmTest(TheAlarmTest.Session().GetAlarmStatus(id, status) == KErrNone, __LINE__);
       
   697 	TheAlarmTest(status == EAlarmStatusEnabled, __LINE__);
       
   698 	TheAlarmTest(TheAlarmTest.Session().SetAlarmStatus(id, EAlarmStatusDisabled) == KErrNone, __LINE__);
       
   699 	TheAlarmTest(TheAlarmTest.Session().GetAlarmStatus(id, status) == KErrNone, __LINE__);
       
   700 	TheAlarmTest(status == EAlarmStatusDisabled, __LINE__);
       
   701 	TheAlarmTest(TheAlarmTest.Session().SetAlarmStatusByCategory(KASCliCategoryClock, EAlarmStatusEnabled) == KErrNone, __LINE__);
       
   702 	TheAlarmTest(TheAlarmTest.Session().GetAlarmStatus(id, status) == KErrNone, __LINE__);
       
   703 	TheAlarmTest(status == EAlarmStatusEnabled, __LINE__);
       
   704 
       
   705 	WaitForAlarmToExpire();
       
   706 
       
   707 	TheAlarmTest.Session().AlarmDelete(id);
       
   708 	}
       
   709 
       
   710 
       
   711 void TestUtcAlarmDetails2L()
       
   712 	{
       
   713 	TheAlarmTest.Test().Next(_L("test alarm details - 2"));
       
   714 	//******************************************************************************
       
   715 	// tests
       
   716 	//
       
   717 	// AlarmAddL
       
   718 	// AlarmDeleteL
       
   719 	// AlarmCountByCategory
       
   720 	// AlarmCountByState
       
   721 	// AlarmIdListByStateLC
       
   722 	//******************************************************************************
       
   723 	TheAlarmTest.TestClearStoreL();
       
   724 
       
   725 	RArray<TAlarmId> alarmIds;
       
   726 	CleanupClosePushL(alarmIds);
       
   727 
       
   728 	//add 10 alarms (category KASCliCategoryClock)
       
   729 	for(TInt ii=1; ii<=10; ii++)
       
   730 		{
       
   731 		TInt minutesFromNow = (ii);
       
   732 		TAlarmId id = AddUtcAlarm(minutesFromNow);
       
   733 		alarmIds.AppendL(id);
       
   734 
       
   735 		TInt numberOfAlarms = TheAlarmTest.Session().GetAlarmCountForCategory(KASCliCategoryClock);
       
   736 		TheAlarmTest(numberOfAlarms == ii, __LINE__);
       
   737 		}
       
   738 
       
   739 	//check states of alarms
       
   740 	TInt alarmCount=0;
       
   741 	//states should be:
       
   742 	// 10 x EAlarmStateQueued
       
   743 	alarmCount = TheAlarmTest.Session().AlarmCountByState(EAlarmStateQueued);
       
   744 	TheAlarmTest(alarmCount == 10, __LINE__);
       
   745 
       
   746 #if defined(_DEBUG)
       
   747 #if defined(__WINSCW__)
       
   748 	//wait for alarm to expire
       
   749 	WaitForAlarmToExpire();
       
   750 	//states should be:
       
   751 	// 1 x EAlarmStateNotifying
       
   752 	// 9 x EAlarmStateQueued
       
   753 	alarmCount = TheAlarmTest.Session().AlarmCountByState(EAlarmStateNotifying);
       
   754 	TheAlarmTest(alarmCount == 1, __LINE__);
       
   755 	alarmCount = TheAlarmTest.Session().AlarmCountByState(EAlarmStateQueued);
       
   756 	TheAlarmTest(alarmCount == 9, __LINE__);
       
   757 
       
   758 	//wait for another alarm to expire
       
   759 	WaitForAlarmToExpire();
       
   760 	//states should be:
       
   761 	// 1 x EAlarmStateNotifying
       
   762 	// 1 x EAlarmStateWaitingToNotify
       
   763 	// 8 x EAlarmStateQueued
       
   764 	alarmCount = TheAlarmTest.Session().AlarmCountByState(EAlarmStateNotifying);
       
   765 	TheAlarmTest(alarmCount == 1, __LINE__);
       
   766 	alarmCount = TheAlarmTest.Session().AlarmCountByState(EAlarmStateWaitingToNotify);
       
   767 	TheAlarmTest(alarmCount == 1, __LINE__);
       
   768 	alarmCount = TheAlarmTest.Session().AlarmCountByState(EAlarmStateQueued);
       
   769 	TheAlarmTest(alarmCount == 8, __LINE__);
       
   770 
       
   771 	//last 8 alarms in our array should correspond to array of alarms with state queued
       
   772 	RArray<TAlarmId> alarmsWithStateQueued;
       
   773 	CleanupClosePushL(alarmsWithStateQueued);
       
   774 
       
   775 	TheAlarmTest.Session().GetAlarmIdListByStateL(EAlarmStateQueued, alarmsWithStateQueued);
       
   776 		for(TInt jj=0; jj<8; jj++)
       
   777 		{
       
   778 		TheAlarmTest(alarmIds[jj+2] == alarmsWithStateQueued[jj], __LINE__);
       
   779 		}
       
   780 
       
   781 	CleanupStack::PopAndDestroy(&alarmsWithStateQueued);    // Close array.
       
   782 #else
       
   783 	//wait for alarm to expire
       
   784 	WaitForAlarmToExpire();
       
   785 	//states should be:
       
   786 	// 1 x EAlarmStateNotified
       
   787 	// 9 x EAlarmStateQueued
       
   788 	alarmCount = TheAlarmTest.Session().AlarmCountByState(EAlarmStateNotified);
       
   789 	TheAlarmTest(alarmCount == 1, __LINE__);
       
   790 	alarmCount = TheAlarmTest.Session().AlarmCountByState(EAlarmStateQueued);
       
   791 	TheAlarmTest(alarmCount == 9, __LINE__);
       
   792 
       
   793 	//wait for another alarm to expire
       
   794 	WaitForAlarmToExpire();
       
   795 	//states should be:
       
   796 	// 2 x EAlarmStateNotified
       
   797 	// 8 x EAlarmStateQueued
       
   798 	alarmCount = TheAlarmTest.Session().AlarmCountByState(EAlarmStateNotified);
       
   799 	TheAlarmTest(alarmCount == 2, __LINE__);
       
   800 	alarmCount = TheAlarmTest.Session().AlarmCountByState(EAlarmStateQueued);
       
   801 	TheAlarmTest(alarmCount == 8, __LINE__);
       
   802 
       
   803 	//last 8 alarms in our array should correspond to array of alarms with state queued
       
   804 	RArray<TAlarmId> alarmsWithStateQueued;
       
   805 	CleanupClosePushL(alarmsWithStateQueued);
       
   806 
       
   807 	TheAlarmTest.Session().GetAlarmIdListByStateL(EAlarmStateQueued, alarmsWithStateQueued);
       
   808 		for(TInt jj=0; jj<8; jj++)
       
   809 		{
       
   810 		TheAlarmTest(alarmIds[jj+2] == alarmsWithStateQueued[jj], __LINE__);
       
   811 		}
       
   812 
       
   813 	CleanupStack::PopAndDestroy(&alarmsWithStateQueued);    // Close array.
       
   814 #endif
       
   815 #endif
       
   816 
       
   817 	//delete all alarms individually
       
   818 	for (TInt count = alarmIds.Count() - 1; count >= 0; count--)
       
   819 		{
       
   820 		TheAlarmTest.Session().AlarmDelete(alarmIds[count]);
       
   821 		}
       
   822 
       
   823 	CleanupStack::PopAndDestroy(&alarmIds);    // Close array.
       
   824 	}
       
   825 
       
   826 
       
   827 void TestUtcAlarmDetails3L()
       
   828 	{
       
   829 	TheAlarmTest.Test().Next(_L("test alarm details - 3"));
       
   830 	//******************************************************************************
       
   831 	// tests
       
   832 	//
       
   833 	// AlarmDetailsL
       
   834 	// AlarmCategoryL
       
   835 	// SetAlarmStatusByCategoryL
       
   836 	// AlarmCountByCategory
       
   837 	// DeleteAllAlarmsByCategoryL
       
   838 	// AlarmCategoryListLC
       
   839 	// AlarmIdListByCategoryLC
       
   840 	// SetAlarmStatusL
       
   841 	// AlarmStatus
       
   842 	//******************************************************************************
       
   843 	TheAlarmTest.TestClearStoreL();
       
   844 
       
   845 	//add 5 alarms with category KASCliCategoryClock
       
   846 	for(TInt ii=1; ii<=5; ii++)
       
   847 		{
       
   848 		AddUtcAlarm(ii, KASCliCategoryClock);
       
   849 		}
       
   850 
       
   851 	//get list of categories - should contain only KASCliCategoryClock
       
   852 	RArray<TAlarmCategory> alarmCategories;
       
   853 	CleanupClosePushL(alarmCategories);
       
   854 
       
   855 	TheAlarmTest.Session().GetAvailableCategoryListL(alarmCategories);
       
   856 	TheAlarmTest(alarmCategories.Count() == 1 && alarmCategories[0] == KASCliCategoryClock, __LINE__);
       
   857 
       
   858 	//add 5 alarms with category KASCliCategoryTest
       
   859 	for(TInt jj=1; jj<=5; jj++)
       
   860 		{
       
   861 		AddUtcAlarm(jj, KASCliCategoryTest);
       
   862 		}
       
   863 
       
   864 	alarmCategories.Reset();
       
   865 	TheAlarmTest.Session().GetAvailableCategoryListL(alarmCategories);
       
   866 	TheAlarmTest(alarmCategories.Count() == 2, __LINE__);
       
   867 
       
   868 	CleanupStack::PopAndDestroy(&alarmCategories);    // Close array.
       
   869 
       
   870 	//add another 10 alarms with category KASCliCategoryClock
       
   871 	for(TInt kk=1; kk<=10; kk++)
       
   872 		{
       
   873 		AddUtcAlarm(kk, KASCliCategoryClock);
       
   874 		}
       
   875 
       
   876 	//get alarms with category KASCliCategoryClock
       
   877 	RArray<TAlarmId> alarms;
       
   878 	CleanupClosePushL(alarms);
       
   879 
       
   880 	TheAlarmTest.Session().GetAlarmIdListForCategoryL(KASCliCategoryClock, alarms);
       
   881 	TInt count = alarms.Count();
       
   882 	TheAlarmTest(count == 15, __LINE__);
       
   883 	//check each alarm has category KASCliCategoryClock
       
   884 	for(TInt mm=0; mm<15; mm++)
       
   885 		{
       
   886 		//directly
       
   887 		TAlarmCategory category;
       
   888 		TheAlarmTest(TheAlarmTest.Session().GetAlarmCategory(alarms[mm], category) == KErrNone, __LINE__);
       
   889 		TheAlarmTest(category == KASCliCategoryClock, __LINE__);
       
   890 		//indirectly
       
   891 		TASShdAlarm alarm;
       
   892 		TheAlarmTest(TheAlarmTest.Session().GetAlarmDetails(alarms[mm], alarm) == KErrNone, __LINE__);
       
   893 		TheAlarmTest(alarm.Category() == KASCliCategoryClock, __LINE__);
       
   894 		}
       
   895 
       
   896 	CleanupStack::PopAndDestroy(&alarms);    // Close array.
       
   897 
       
   898 	//should now have 15 alarms with category KASCliCategoryClock and 5 with category KASCliCategoryTest
       
   899 	TheAlarmTest(TheAlarmTest.Session().GetAlarmCountForCategory(KASCliCategoryClock)==15 &&
       
   900 		TheAlarmTest.Session().GetAlarmCountForCategory(KASCliCategoryTest)==5, __LINE__);
       
   901 	//disable all KASCliCategoryClock alarms
       
   902 	TheAlarmTest.Session().SetAlarmStatusByCategory(KASCliCategoryClock, EAlarmStatusDisabled);
       
   903 	TheAlarmTest(TheAlarmTest.Session().NumberOfAlarmsActiveInQueue()==5, __LINE__);
       
   904 	//try to delete all KASCliCategoryTest orphaned alarms (should be none)
       
   905 	TheAlarmTest.Session().AlarmDeleteAllByCategory(KASCliCategoryTest, ETrue);
       
   906 	TheAlarmTest(TheAlarmTest.Session().NumberOfAlarmsActiveInQueue()==5, __LINE__);
       
   907 	//delete all KASCliCategoryTest alarms
       
   908 	TheAlarmTest.Session().AlarmDeleteAllByCategory(KASCliCategoryTest, EFalse);
       
   909 	TheAlarmTest(TheAlarmTest.Session().NumberOfAlarmsActiveInQueue()==0, __LINE__);
       
   910 	//re-enable the KASCliCategoryClock alarms
       
   911 	TheAlarmTest.Session().SetAlarmStatusByCategory(KASCliCategoryClock, EAlarmStatusEnabled);
       
   912 	TheAlarmTest(TheAlarmTest.Session().NumberOfAlarmsActiveInQueue()==15, __LINE__);
       
   913 	//create a new enabled alarm
       
   914 	TAlarmId id = AddUtcAlarm(1, KASCliCategoryClock);
       
   915 	TheAlarmTest(TheAlarmTest.Session().NumberOfAlarmsActiveInQueue()==16, __LINE__);
       
   916 	//check status
       
   917 	TAlarmStatus status;
       
   918 	TheAlarmTest(TheAlarmTest.Session().GetAlarmStatus(id, status) == KErrNone, __LINE__);
       
   919 	TheAlarmTest(status == EAlarmStatusEnabled, __LINE__);
       
   920 	//disable it
       
   921 	TheAlarmTest.Session().SetAlarmStatus(id, EAlarmStatusDisabled);
       
   922 	TheAlarmTest(TheAlarmTest.Session().NumberOfAlarmsActiveInQueue()==15, __LINE__);
       
   923 	TheAlarmTest(TheAlarmTest.Session().GetAlarmStatus(id, status) == KErrNone, __LINE__);
       
   924 	TheAlarmTest(status == EAlarmStatusDisabled, __LINE__);
       
   925 
       
   926 	//delete all remaining alarms
       
   927 	TheAlarmTest.Session().AlarmDeleteAllByCategory(KASCliCategoryClock, EFalse);
       
   928 	TheAlarmTest(TheAlarmTest.Session().NumberOfAlarmsActiveInQueue()==0, __LINE__);
       
   929 	}
       
   930 
       
   931 
       
   932 void TestDeleteSnoozedUtcAlarmL()
       
   933 	{
       
   934 	TheAlarmTest.Test().Next(_L("test delete snoozed agenda alarm"));
       
   935 	//******************************************************************************
       
   936 	// tests
       
   937 	//
       
   938 	// AlarmDeleteByCategory
       
   939 	//******************************************************************************
       
   940 	TheAlarmTest.TestClearStoreL();
       
   941 
       
   942 	//add 1 alarm with category KUidAgendaModelAlarmCategory
       
   943 
       
   944 	const TUid KUidAgendaModelAlarmCategory = { 0x101F4A70 };
       
   945 	TAlarmId id=AddUtcAlarm(1, KUidAgendaModelAlarmCategory);
       
   946 	TheAlarmTest(TheAlarmTest.Session().NumberOfAlarmsActiveInQueue()==1, __LINE__);
       
   947 	User::After(1000000 * 61);
       
   948 	TTime now;
       
   949 	now.UniversalTime();
       
   950 	TTime timeToSnoozeUntil = now+ TTimeIntervalMinutes(1);
       
   951 	TheAlarmTest(TheAlarmTest.Session().__DbgSnoozeAlarm(id, timeToSnoozeUntil) == KErrNone);
       
   952 
       
   953 	TDeleteType whatToDelete=0;
       
   954 	whatToDelete=EFuture|EExpired;
       
   955 	User::LeaveIfError(TheAlarmTest.Session().AlarmDeleteByCategory(KUidAgendaModelAlarmCategory, whatToDelete));
       
   956 	TheAlarmTest(TheAlarmTest.Session().NumberOfAlarmsActiveInQueue()==1, __LINE__);
       
   957 
       
   958 	//delete all alarms
       
   959 	TheAlarmTest.Session().AlarmDeleteAllByCategory(KUidAgendaModelAlarmCategory, EFalse);
       
   960 	TheAlarmTest(TheAlarmTest.Session().NumberOfAlarmsActiveInQueue()==0, __LINE__);
       
   961 	}
       
   962 
       
   963 /**
       
   964 @SYMTestCaseID PIM-TCLIENTSESSION-0001
       
   965 */
       
   966 	
       
   967 static void DoTestsL()
       
   968 	{
       
   969 	CActiveScheduler* scheduler = new (ELeave) CActiveScheduler;
       
   970 	CleanupStack::PushL(scheduler);
       
   971 	CActiveScheduler::Install(scheduler);
       
   972 
       
   973 	TheAlarmTest.Test().Start(_L("@SYMTestCaseID PIM-TCLIENTSESSION-0001 Connecting to server"));
       
   974 	TInt r = TheAlarmTest.Session().Connect();
       
   975 	TheAlarmTest(r == KErrNone, __LINE__);
       
   976 
       
   977 #if defined(_DEBUG)
       
   978 // The alarm should only be allowed to display notification in WINS builds.
       
   979 #if defined(__WINSCW__)
       
   980 	TheAlarmTest.Session().__DbgPreventUserNotify(EFalse);
       
   981 #else
       
   982 	TheAlarmTest.Session().__DbgPreventUserNotify(ETrue);
       
   983 #endif
       
   984 #endif
       
   985 
       
   986 	TheAlarmTest.TestClearStoreL();
       
   987 
       
   988 	TestCategorySpecificFunctionalityL();
       
   989 	TestOverlappingAlarmsL();
       
   990 	TestAlarmDetails1L();
       
   991 	TestAlarmDetails2L();
       
   992 	TestAlarmDetails3L();
       
   993 
       
   994 #if defined(_DEBUG) && defined(__WINS__)
       
   995 	TestDeleteSnoozedAlarmL();
       
   996 #endif
       
   997 
       
   998 	TheAlarmTest.TestClearStoreL();
       
   999 
       
  1000 	TestCategorySpecificFunctionalityUtcL();
       
  1001 	TestOverlappingUtcAlarmsL();
       
  1002 	TestUtcAlarmDetails1L();
       
  1003 	TestUtcAlarmDetails2L();
       
  1004 	TestUtcAlarmDetails3L();
       
  1005 
       
  1006 #if defined(_DEBUG) && defined(__WINS__)
       
  1007 	TestDeleteSnoozedUtcAlarmL();
       
  1008 #endif
       
  1009 
       
  1010 	TheAlarmTest.TestClearStoreL();
       
  1011 
       
  1012 	TheAlarmTest.Session().Close();
       
  1013 
       
  1014 	CleanupStack::PopAndDestroy(scheduler);
       
  1015 	}
       
  1016 
       
  1017 GLDEF_C TInt E32Main()
       
  1018 //
       
  1019 // Test the alarm server.
       
  1020 //
       
  1021 	{
       
  1022 	__UHEAP_MARK;
       
  1023 	TInt ret = KErrNone;
       
  1024 	CTrapCleanup* cleanup = CTrapCleanup::New();
       
  1025 	if (!cleanup)
       
  1026 	    {
       
  1027 	    return KErrNoMemory;
       
  1028 	    }
       
  1029 
       
  1030 	TheAlarmTest.Title();
       
  1031 	TheAlarmTest.TestStartServers();
       
  1032 	//
       
  1033 	TRAPD(error, DoTestsL());
       
  1034 	TheAlarmTest(error == KErrNone, __LINE__);
       
  1035 	//
       
  1036     TRAP(ret,TheAlarmTest.EndL());
       
  1037     TheAlarmTest.Test().Close();
       
  1038 	ASTstAlarmTest::Close();
       
  1039 
       
  1040 	delete cleanup;
       
  1041 	__UHEAP_MARKEND;
       
  1042 	return ret;
       
  1043 	}