pimappservices/calendar/tsrc/tcal_servershutdown.cpp
changeset 0 f979ecb2b13e
equal deleted inserted replaced
-1:000000000000 0:f979ecb2b13e
       
     1 // Copyright (c) 2007-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 // tcal_servershutdown:
       
    15 // This test is intended to test the delay timer added to the calendar file before it is closed
       
    16 // 
       
    17 //
       
    18 
       
    19 #include "tcal_servershutdown.h"
       
    20 #include "calinstanceview.h"
       
    21 #include "calinstance.h" 
       
    22 #include "calrrule.h" 
       
    23 #include <caliterator.h>
       
    24 #include "calalarm.h" 
       
    25 
       
    26 
       
    27 CServerShutdownTestManager::CServerShutdownTestManager(TInt aPriority):CActive(aPriority)
       
    28 	{
       
    29 	CActiveScheduler::Add(this);
       
    30 	}
       
    31 
       
    32 // Record a timestamp before initiating server shutdown
       
    33 // Server shutdown period is checked against the expected range when the process exits
       
    34 void CServerShutdownTestManager::RecordTimeStampBeforeServerShutdown()
       
    35 	{
       
    36 	iSrvTimerStartTicks = User::NTickCount();
       
    37 	}
       
    38 
       
    39 // Calculate server shutdown period and test that it is within the expected range
       
    40 void CServerShutdownTestManager::TestServerShutdownTime()
       
    41 	{
       
    42 	TUint32 srvTimerStopTicks = User::NTickCount();
       
    43 	TUint32 srvTimerShutdownPeriodTicks = srvTimerStopTicks - iSrvTimerStartTicks;
       
    44 	TTimeIntervalMicroSeconds32 srvTimerShutdownPeriod = srvTimerShutdownPeriodTicks * iNanoTickPeriod;
       
    45 	_LIT(KAgendaServerShutdownPeriod, "Agenda server shutdown period - %d microseconds\n");
       
    46 	test.Printf(KAgendaServerShutdownPeriod, srvTimerShutdownPeriod);
       
    47 	test(srvTimerShutdownPeriod >= KServerShutdownDelayMin);
       
    48 	test(srvTimerShutdownPeriod <= KServerShutdownDelayMax);
       
    49 	}
       
    50 
       
    51 // Entry view progress callback
       
    52 void CServerShutdownTestManager::Progress(TInt /*aPercentageCompleted*/)
       
    53 	{
       
    54 	_LIT(KDot, ".");
       
    55 	test.Printf(KDot);
       
    56 		
       
    57 	_LIT(KUnexpectedCallback, "The index should already be built so we should not get progress callbacks\n");
       
    58 	
       
    59 	switch (iTestCase)
       
    60 		{
       
    61 		case ETestServerShutdownCancelWithIndexCancelled:
       
    62 		case ETestServerShutdownCancelWithIndexShutdown:
       
    63 			{
       
    64 			test.Printf(KUnexpectedCallback);
       
    65 			test(EFalse);
       
    66 			}
       
    67 			break;
       
    68 		case ETestServerSingleSessionOpenTwiceShutdown:
       
    69 		case ETestServerMultiSessionSingleFileOpen:
       
    70 			{
       
    71 			test.Printf(KUnexpectedCallback);
       
    72 			test(EFalse);
       
    73 			}
       
    74 		break;
       
    75 		default:
       
    76 			{
       
    77 			// do nothing
       
    78 			}
       
    79 			break;
       
    80 		}
       
    81 	}
       
    82 
       
    83 // Entry view complete callback
       
    84 void CServerShutdownTestManager::Completed(TInt aError)
       
    85 	{
       
    86 	_LIT(KEntryViewCompletedWithErr, "Entry View open complete with error = %d\n");
       
    87 	test.Printf(KEntryViewCompletedWithErr, aError);
       
    88 	
       
    89 	switch(iTestCase)
       
    90 		{
       
    91 		case ETestServerShutdownOpenInvalidFileLeave:
       
    92 			{
       
    93 			test(aError == KErrNotFound);
       
    94 			}
       
    95 		break;
       
    96 		case ETestServerShutdownOOMDeleteFile:
       
    97 		case ETestServerShutdownOOMOpenCloseFile:
       
    98 			{
       
    99 			// OOM test will expectedly fail with KErrNoMemory
       
   100 			test(aError == KErrNoMemory);
       
   101 			}
       
   102 		break;
       
   103 #ifdef SYMBIAN_SYSTEM_STATE_MANAGEMENT
       
   104 		case ETestServerShutdownWithSystemStateNotificationAsync:
       
   105 			{
       
   106 			test(aError == KErrNone || aError == KErrCancel);
       
   107 			}
       
   108 		break;
       
   109 #endif
       
   110 		default:
       
   111 			{
       
   112 			test(aError == KErrNone);
       
   113 			}
       
   114 		break;
       
   115 		}
       
   116 	
       
   117 	CActiveScheduler::Stop();
       
   118  	}
       
   119 
       
   120 TBool CServerShutdownTestManager::NotifyProgress()
       
   121 	{
       
   122 	return ETrue;
       
   123 	}
       
   124 
       
   125 // The RunL is called when the agenda server process exits as a result of the logon to the process
       
   126 // The process can exit in unexpected test cases' states and will result in an error
       
   127 // If the process exits in an expected the test cases' state, the server shutdown period is calculated and checked against the expected time range
       
   128 // There are other test cases' states where we expect the server to shutdown immediately e.g. after deleting a file, hence we do nothing
       
   129 void CServerShutdownTestManager::RunL()
       
   130 	{
       
   131 	_LIT(KAgendaServerClosedWithStatus, "The agenda server has closed with iStatus = %d\n");
       
   132 	_LIT(KAgendaServerUnexpectedClose, "The server closed down when it shouldn't have\n");
       
   133 	_LIT(KInvalidTestCaseVariable, "The test case state variable was not set or was set to an invalid value\n");
       
   134 	
       
   135 	test.Printf(KAgendaServerClosedWithStatus, iStatus.Int());
       
   136 	
       
   137 	__ASSERT_ALWAYS(iStatus.Int() == KErrNone, User::Invariant());
       
   138 
       
   139 	switch (iTestCase)
       
   140 		{
       
   141 		case ETestServerShutdownWithIndex:
       
   142 			{
       
   143 			// Calculate server shutdown period and test that it is within the expected range
       
   144 			TestServerShutdownTime();
       
   145 			}
       
   146 		break;
       
   147 		case ETestServerShutdownCancelWithIndexStart:
       
   148 		case ETestServerShutdownCancelWithIndexCancelled:
       
   149 			{
       
   150 			// The server should not have shut down here
       
   151 			test.Printf(KAgendaServerUnexpectedClose);
       
   152 			test(EFalse);
       
   153 			}
       
   154 			break;
       
   155 		case ETestServerShutdownCancelWithIndexShutdown:
       
   156 			{
       
   157 			// Calculate server shutdown period and test that it is within the expected range
       
   158 			TestServerShutdownTime();
       
   159 			}
       
   160 			break;
       
   161 		case ETestServerShutdownDeleteFile:
       
   162 			{
       
   163 			// Expecting the agenda server to shutdown immediately
       
   164 			}
       
   165 			break;
       
   166 		case ETestServerShutdownDeleteMultiFiles:
       
   167 			{
       
   168 			// Calculate server shutdown period and test that it is within the expected range
       
   169 			TestServerShutdownTime();
       
   170 			}
       
   171 			break;
       
   172 		case ETestServerShutdownProcessExit:
       
   173 			{
       
   174 			// Expecting the agenda server to shutdown immediately
       
   175 			}
       
   176 			break;
       
   177 		case ETestServerSingleSessionOpenTwiceStart:
       
   178 			{
       
   179 			// the server should not have shut down here since opening the file the second time should cancel the delay timer
       
   180 			test.Printf(KAgendaServerUnexpectedClose);
       
   181 			test(EFalse);
       
   182 			}
       
   183 			break;
       
   184 		case ETestServerSingleSessionOpenTwiceShutdown:
       
   185 			{
       
   186 			// Calculate server shutdown period and test that it is within the expected range
       
   187 			TestServerShutdownTime();
       
   188 			}
       
   189 			break;
       
   190 		case ETestServerMultiSessionSingleFileOpenStart:
       
   191 			{
       
   192 			// the server should not have shut down here when a session out of multiple file sessions to multiple files is closed
       
   193 			test.Printf(KAgendaServerUnexpectedClose);
       
   194 			test(EFalse);
       
   195 			}
       
   196 			break;
       
   197 		case ETestServerMultiSessionSingleFileOpenShutdown:
       
   198 			{
       
   199 			// Calculate server shutdown period and test that it is within the expected range
       
   200 			TestServerShutdownTime();
       
   201 			}
       
   202 			break;
       
   203 		case ETestServerMultiSessionMultiFileOpenStart:
       
   204 			{
       
   205 			// the server should not have shut down here when the last session to a calendar file is closed but there are other files open
       
   206 			test.Printf(KAgendaServerUnexpectedClose);
       
   207 			test(EFalse);
       
   208 			}
       
   209 			break;
       
   210 		case ETestServerMultiSessionMultiFileOpenShutdown:
       
   211 			{
       
   212 			// Calculate server shutdown period and test that it is within the expected range
       
   213 			TestServerShutdownTime();
       
   214 			}
       
   215 			break;				
       
   216 		case ETestServerShutdownOpenInvalidFileLeave:
       
   217 			{
       
   218 			// Expecting the agenda server to shutdown immediately (not with a delay)
       
   219 			}
       
   220 			break;			
       
   221 		case ETestServerShutdownv91CalendarFileConversion:
       
   222 			{
       
   223 			// Calculate server shutdown period and test that it is within the expected range
       
   224 			TestServerShutdownTime();
       
   225 			}
       
   226 			break;
       
   227 #ifdef SYMBIAN_SYSTEM_STATE_MANAGEMENT
       
   228 		case ETestServerShutdownWithSystemStateNotification:
       
   229 		
       
   230 			{
       
   231 			TestSystemAckNotification();
       
   232 			test (iAlarmServer.AlarmCountByState(EAlarmStateQueued) == 1);
       
   233 			ClearAllAlarmsL();
       
   234 			}
       
   235 			break;
       
   236 		case ETestServerShutdownWithSystemStateNotificationAsync:	
       
   237 		case ETestServerShutdownWithSystemStateNotificationNormal:	
       
   238 		case ETestServerShutdownWithSystemStateNotificationInstance:
       
   239 			{
       
   240 			TestSystemAckNotification();
       
   241 			}
       
   242 			break;
       
   243 #endif
       
   244 		default:
       
   245 			{
       
   246 			// The test case state variable was not set or was set to an invalid value
       
   247 			test.Printf(KInvalidTestCaseVariable);
       
   248 			test(EFalse);
       
   249 			}
       
   250 			break;
       
   251 		};
       
   252 
       
   253 	// Close the handle to the agenda server process
       
   254 	iProcess.Close();
       
   255 	// Stop the active scheduler since the agenda server process has now exited
       
   256 	CActiveScheduler::Stop();
       
   257 	}
       
   258 
       
   259 void CServerShutdownTestManager::DoCancel()
       
   260 	{
       
   261 	iProcess.LogonCancel(iStatus);
       
   262 	}
       
   263 
       
   264 // Trigger an asynchronous delay which allows the server to shutdown and flag an error if it was unexpected
       
   265 void CServerShutdownTestManager::AsyncDelay(TTimeIntervalMicroSeconds32 aMicroseconds)
       
   266 	{
       
   267 	_LIT(KAsyncDelayStart, "Async delay for %d microseconds is starting...\n");
       
   268 	
       
   269 	test.Printf(KAsyncDelayStart, aMicroseconds.Int());
       
   270 	TCallBack callBack(CServerShutdownTestManager::AsyncDelayCallBack, this);
       
   271 	iPeriodic->Start(aMicroseconds, aMicroseconds, callBack);
       
   272 	CActiveScheduler::Start();
       
   273 	}
       
   274 
       
   275 // Called when the asynchronous delay expires
       
   276 TInt CServerShutdownTestManager::AsyncDelayCallBack(TAny* aPtr)
       
   277 	{
       
   278 	_LIT(KAsyncDelayFinish, "...the delay has finished\n");
       
   279 	test.Printf(KAsyncDelayFinish);
       
   280 	
       
   281 	static_cast<CServerShutdownTestManager*>(aPtr)->iPeriodic->Cancel();
       
   282 	CActiveScheduler::Stop();
       
   283 	return KErrNone;
       
   284 	}
       
   285 
       
   286 // Create a session to the agenda server
       
   287 void CServerShutdownTestManager::CreateSessionL()
       
   288 	{
       
   289 	_LIT(KCreatingCalSession, "Creating a session\n");
       
   290 	test.Printf(KCreatingCalSession);
       
   291 	
       
   292 	delete iSession;
       
   293 	iSession = NULL;
       
   294 	iSession = CCalSession::NewL();
       
   295 	}
       
   296 
       
   297 // Create an additional session to the agenda server
       
   298 void CServerShutdownTestManager::CreateAdditionalSessionL()
       
   299 	{
       
   300 	_LIT(KCreatingCalAdditionalSession, "Creating an additional session\n");
       
   301 	test.Printf(KCreatingCalAdditionalSession);
       
   302 	
       
   303 	delete iAdditionalSession;
       
   304 	iAdditionalSession = NULL;
       
   305 	iAdditionalSession = CCalSession::NewL();
       
   306 	}
       
   307 
       
   308 // Close the session and wait / do not wait for the agenda server to close
       
   309 void CServerShutdownTestManager::CloseSession(TBool aWaitToClose)
       
   310 	{
       
   311 	_LIT(KClosingCalSession, "Closing the session\n");
       
   312 	test.Printf(KClosingCalSession);
       
   313 	
       
   314 	delete iSession;
       
   315 	iSession = NULL;
       
   316 	
       
   317 	if (aWaitToClose)
       
   318 		{
       
   319 		// Make sure any ecom sessions are destroyed before waiting for the agenda server to close
       
   320 		REComSession::FinalClose();
       
   321 		_LIT(KWaitingForAgendaServerClose, "Wait for the agenda server to close...\n");
       
   322 		test.Printf(KWaitingForAgendaServerClose);
       
   323 		CActiveScheduler::Start();
       
   324 		}
       
   325 	}
       
   326 
       
   327 // Close the additional session to the agenda server
       
   328 void CServerShutdownTestManager::CloseAdditionalSession(TBool aWaitToClose)
       
   329 	{
       
   330 	_LIT(KClosingAdditionalCalSession, "Closing the additional session\n");
       
   331 	test.Printf(KClosingAdditionalCalSession);
       
   332 	
       
   333 	delete iAdditionalSession;
       
   334 	iAdditionalSession = NULL;
       
   335 	
       
   336 	if (aWaitToClose)
       
   337 		{
       
   338 		// Make sure any ecom sessions are destroyed before waiting for the agenda server to close
       
   339 		REComSession::FinalClose();
       
   340 		_LIT(KWaitingForAgendaServerClose, "Wait for the agenda server to close...\n");
       
   341 		test.Printf(KWaitingForAgendaServerClose);
       
   342 		CActiveScheduler::Start();
       
   343 		}
       
   344 	}
       
   345 
       
   346 // Create a calendar entry view 
       
   347 void CServerShutdownTestManager::CreateEntryViewL(const TDesC& aCalFile, TBool aWaitToOpen)
       
   348 	{
       
   349 	_LIT(KCreatingCalEntryView, "Creating the Entry View\n");
       
   350 	test.Printf(KCreatingCalEntryView);
       
   351 		
       
   352 	iSession->OpenL(aCalFile);
       
   353 
       
   354 	iEntryView = CCalEntryView::NewL(*iSession, *this);
       
   355 	
       
   356 	if (aWaitToOpen)
       
   357 		{
       
   358 		CActiveScheduler::Start();
       
   359 		}
       
   360 	}
       
   361 #ifdef SYMBIAN_SYSTEM_STATE_MANAGEMENT
       
   362 void CServerShutdownTestManager::CreateInstanceViewL(TBool aWaitToOpen)
       
   363 	{
       
   364 	_LIT(KCreatingCalInstanceView, "Creating an Instance View\n");
       
   365 	test.Printf(KCreatingCalInstanceView);
       
   366 	
       
   367 	iInstanceView = CCalInstanceView::NewL(*iSession, *this);
       
   368 	
       
   369 	if (aWaitToOpen)
       
   370 		{
       
   371 		CActiveScheduler::Start();
       
   372 		}
       
   373 	}
       
   374 
       
   375 // Create a test entry
       
   376 void CServerShutdownTestManager::CreateEntry(const TDesC8& aGuid)
       
   377 	{
       
   378 	RPointerArray<CCalEntry> entryArray;
       
   379 	CleanupClosePushL(entryArray);
       
   380 //	TRAP_IGNORE(iEntryView->FetchL(aGuid, entryArray)); //If not found then this function leaves!
       
   381 
       
   382 //	const TDateTime KEntryDateTime(2008, EApril, 17, 9, 0, 0, 0);
       
   383 	TTime now;
       
   384 	now.HomeTime();
       
   385 	
       
   386 	HBufC8* guid = aGuid.AllocLC();
       
   387 	CCalEntry* entry = CCalEntry::NewL(CCalEntry::EAppt, guid, CCalEntry::EMethodNone, 0);
       
   388 	CleanupStack::Pop(guid);
       
   389 	CleanupStack::PushL(entry);
       
   390 
       
   391 	TCalTime startTime;
       
   392 	TCalTime endTime;
       
   393 	startTime.SetTimeLocalL(now + TTimeIntervalHours(1));
       
   394 	endTime.SetTimeLocalL(now + TTimeIntervalHours(2));
       
   395 	entry->SetStartAndEndTimeL(startTime, endTime);
       
   396     //Add an alarm
       
   397 	CCalAlarm* alarm = CCalAlarm::NewL();
       
   398 	CleanupStack::PushL(alarm);
       
   399 	TTimeIntervalMinutes alarmMinutes(20);
       
   400 	alarm->SetTimeOffset(alarmMinutes);
       
   401 	entry->SetAlarmL(alarm);
       
   402 	CleanupStack::PopAndDestroy(alarm);
       
   403 
       
   404 	TInt success = 0;
       
   405 	entryArray.AppendL(entry);
       
   406 
       
   407 	test (entryArray.Count()==1);
       
   408 	TRAPD(errStore, iEntryView->StoreL(entryArray, success));
       
   409 	CleanupStack::PopAndDestroy(entry);
       
   410 	CleanupStack::PopAndDestroy(&entryArray);
       
   411 	}
       
   412 #endif
       
   413 // Create an additional calendar entry view 
       
   414 void CServerShutdownTestManager::CreateAdditionalEntryViewL(const TDesC& aCalFile, TBool aWaitToOpen)
       
   415 	{
       
   416 	_LIT(KCreatingCalEntryView, "Creating an additional Entry View\n");
       
   417 	test.Printf(KCreatingCalEntryView);
       
   418 		
       
   419 	iAdditionalSession->OpenL(aCalFile);
       
   420 
       
   421 	iAdditionalEntryView = CCalEntryView::NewL(*iAdditionalSession, *this);
       
   422 	
       
   423 	if (aWaitToOpen)
       
   424 		{
       
   425 		CActiveScheduler::Start();
       
   426 		}
       
   427 	}
       
   428 
       
   429 // Close the calendar file entry view 
       
   430 void CServerShutdownTestManager::CloseEntryView()
       
   431 	{
       
   432 	_LIT(KClosingCalEntryView, "Closing the Entry View\n");
       
   433 	test.Printf(KClosingCalEntryView);
       
   434 	
       
   435 	delete iEntryView;
       
   436 	iEntryView = NULL;
       
   437 	}
       
   438 
       
   439 // Close the additional calendar file entry view 
       
   440 void CServerShutdownTestManager::CloseAdditionalEntryView()
       
   441 	{
       
   442 	_LIT(KClosingCalAdditionalEntryView, "Closing the additional Entry View\n");
       
   443 	test.Printf(KClosingCalAdditionalEntryView);
       
   444 	
       
   445 	delete iAdditionalEntryView;
       
   446 	iAdditionalEntryView = NULL;
       
   447 	}
       
   448 #ifdef SYMBIAN_SYSTEM_STATE_MANAGEMENT
       
   449 void CServerShutdownTestManager::CloseInstanceView()
       
   450 	{
       
   451 	_LIT(KClosingCalInstanceView, "Closing the Instance View\n");
       
   452 	test.Printf(KClosingCalInstanceView);
       
   453 	
       
   454 	delete iInstanceView;
       
   455 	iInstanceView = NULL;
       
   456 	}
       
   457 #endif
       
   458 CServerShutdownTestManager* CServerShutdownTestManager::NewLC(TInt aPriority)
       
   459 	{
       
   460 	CServerShutdownTestManager* self = new (ELeave) CServerShutdownTestManager(aPriority);
       
   461 	CleanupStack::PushL(self);
       
   462 	self->ConstructL();
       
   463 
       
   464 	return (self);
       
   465 	}
       
   466 
       
   467 CServerShutdownTestManager::~CServerShutdownTestManager()
       
   468 	{
       
   469 #ifdef SYMBIAN_SYSTEM_STATE_MANAGEMENT
       
   470 	iSystemStateNotification.Close();
       
   471 #endif
       
   472 	delete iFileRegister;
       
   473 	iPIMTestServer.Close();
       
   474 
       
   475 	delete iPeriodic;
       
   476 	iProcess.Close();
       
   477 	delete iSession;
       
   478 	delete iAdditionalSession;
       
   479 	
       
   480 	delete iEntryView;
       
   481 #ifdef SYMBIAN_SYSTEM_STATE_MANAGEMENT
       
   482 	delete iInstanceView;
       
   483 #endif
       
   484 	delete iAdditionalEntryView;
       
   485 	}
       
   486 
       
   487 void CServerShutdownTestManager::ConstructL()
       
   488 	{
       
   489 	iPeriodic = CPeriodic::NewL(EPriorityIdle);
       
   490 
       
   491 	User::LeaveIfError(HAL::Get(HAL::ENanoTickPeriod, iNanoTickPeriod));
       
   492 	User::LeaveIfError(iPIMTestServer.Connect());
       
   493 	
       
   494 	// Copy the test Calendar files from the ROM drive to the C: used by the test cases later
       
   495 	iPIMTestServer.CopyFileL(KServerShutdownCalFileROM, KServerShutdownCalFileRAM);
       
   496 	iPIMTestServer.CopyFileL(KServerShutdownCalFileMultiFileROM, KServerShutdownCalFileMultiFileRAM);
       
   497 	iPIMTestServer.CopyFileL(KServerShutdown91CalFileROM, KServerShutdown91CalFileRAM);
       
   498 	
       
   499 	iFileRegister = CTestRegister::NewL();
       
   500 		
       
   501 	iFileRegister->RegisterL(KServerShutdownCalFile, EFileTypeAgn);
       
   502 	iFileRegister->RegisterL(KServerShutdownCalFileMultifFile, EFileTypeAgn);
       
   503 	iFileRegister->RegisterL(KServerShutdown91CalFile, EFileTypeAgn);
       
   504 		
       
   505 	// Start the console alarm alert server required by the agenda server
       
   506 	
       
   507 #if __WINS__
       
   508 	CCalTestLibrary::StartAlarmServerL();
       
   509 #endif
       
   510 	
       
   511 #ifdef SYMBIAN_SYSTEM_STATE_MANAGEMENT	
       
   512 	CreateSystemStateNotificationProperty();
       
   513 	// Connect to the alarm server
       
   514 	User::LeaveIfError(iAlarmServer.Connect());
       
   515 
       
   516 	// Make sure that the alarm queue is empty.
       
   517 	ClearAllAlarmsL();
       
   518 #endif
       
   519 	}
       
   520 
       
   521 // Run all the test cases the delay added to the calendar file before it is closed
       
   522 void CServerShutdownTestManager::RunAllTestsL()
       
   523 	{
       
   524 	
       
   525 	// Test the file close delay timer with a single calendar file
       
   526 	TestServerShutdownWithIndexL();
       
   527 	
       
   528 	// Test the cancellation of a file close delay timer with a single calendar file
       
   529 	TestServerShutdownCancelWithIndexL();
       
   530 
       
   531 	// Test the file close delay timer avoids the rebuilding of indexes when the same calendar file is opened twice in the same session
       
   532 	TestServerShutdownSingleSessionOpenTwiceL();
       
   533 	
       
   534 	// Test the file close delay timer does not shutdown the server when a session out of multiple sessions to a single calendar file is closed and
       
   535 	// that the indexes are not rebuilt when another session reconnects to the same calendar file
       
   536 	TestServerShutdownMultiSessionSingleFileOpenL();
       
   537 	
       
   538 	// Test the file close delay timer does not shutdown the server when a session out of multiple sessions to two separate calendar files is closed
       
   539 	TestServerShutdownMultiSessionMultiFileOpenL();
       
   540 
       
   541 	// Test the file close delay timer is not triggered and the calendar file is closed immediately when opening a calendar file leaves
       
   542 	TestServerShutdownOpenInvalidFileLeaveL();
       
   543 	
       
   544 	// Test the file close delay timer is not triggered when the server is killed and terminated both with or without an entry view
       
   545 	TestServerShutdownProcessExitL();
       
   546 	
       
   547 	// Test the file close delay timer is not triggered when the calendar file is deleted
       
   548 	TestServerShutdownDeleteFileL();
       
   549 	
       
   550 	// Test the file close delay timer is cancelled on a calendar file if a session associated with a different calendar file deletes it
       
   551 	// It should not return with KErrInUse because of the delay timer
       
   552 	TestServerShutdownDeleteMultiFilesL();
       
   553 	
       
   554 #ifdef SYMBIAN_SYSTEM_STATE_MANAGEMENT
       
   555 	
       
   556 	//Test harness to simulate the system state shutdown notifications
       
   557 	TestServerShutdownWithSystemStateNotificationsL();
       
   558 	
       
   559 	TestServerShutdownWithSystemStateNotificationsAsyncL();
       
   560 	
       
   561 	TestServerShutdownWithNormalSystemStateNotification();
       
   562 	
       
   563 	TestServerShutdownWithStateNotificationAndInstanceViewL();
       
   564 	
       
   565 #endif
       
   566 	
       
   567 #if __WINS__
       
   568 	// Test the file close delay timer with opening and closing and deleting a calendar file under OOM conditions
       
   569 //	TestServerShutdownOOML();
       
   570 #endif	
       
   571 	}
       
   572 
       
   573 // Logon to the agenda server process in order to be notified when the process exits / dies
       
   574 void CServerShutdownTestManager::ProcessLogonL()
       
   575 	{
       
   576 	_LIT(KAgendaServerUIDMatch, "*[10003a5b]*");
       
   577 	_LIT(KAgendaServerProcessLogon, "Logon to agenda server shutdown\n");
       
   578 	_LIT(KAgendaServerProcessNotFound, "Couldnt find the agenda server process\n");
       
   579 
       
   580 	// the name of the agenda server process includes - [10003a5b]
       
   581 	TFindProcess findProcess(KAgendaServerUIDMatch);
       
   582 	
       
   583 	TFullName fullName(KNullDesC);
       
   584 	
       
   585 	TInt findProcessResult(KErrNone);
       
   586 	findProcessResult = findProcess.Next(fullName);
       
   587 	
       
   588 	User::LeaveIfError(findProcessResult);
       
   589 	
       
   590 	while (findProcessResult == KErrNone)
       
   591 		{
       
   592 		findProcessResult = findProcess.Next(fullName);
       
   593 		}
       
   594 	
       
   595 	// The agenda server process is running 
       
   596 	User::LeaveIfError(iProcess.Open(fullName));
       
   597 
       
   598 	if(!IsActive())
       
   599 		{
       
   600 		iProcess.Logon(iStatus); // ask for a callback when the process ends
       
   601 		SetActive();
       
   602 		test.Printf(KAgendaServerProcessLogon);
       
   603 		}
       
   604 	else
       
   605 		{
       
   606 		test.Printf(KAgendaServerProcessNotFound);
       
   607 		User::Leave(KErrNotFound);
       
   608 		}
       
   609 	}
       
   610 
       
   611 void CServerShutdownTestManager::ShutdownProcessL(const TDesC& aProcessUid)
       
   612 	{
       
   613 	_LIT(KAgendaServerProcessNotFound, "Couldnt find the agenda server process\n");
       
   614 
       
   615 	// the name of the agenda server process includes the uid
       
   616 	TFindProcess findProcess(aProcessUid);
       
   617 
       
   618 	TFullName fullName(KNullDesC);
       
   619 
       
   620 	TInt findProcessResult(KErrNone);
       
   621 	findProcessResult = findProcess.Next(fullName);
       
   622 
       
   623 	User::LeaveIfError(findProcessResult);
       
   624 
       
   625 	while (findProcessResult == KErrNone)
       
   626 		{
       
   627 		findProcessResult = findProcess.Next(fullName);
       
   628 		}
       
   629 	RProcess process;
       
   630 	User::LeaveIfError(process.Open(fullName));
       
   631 	process.Kill(0);
       
   632 	}
       
   633 
       
   634 // Test the file close delay timer with a single calendar file
       
   635 
       
   636 void CServerShutdownTestManager::TestServerShutdownWithIndexL()
       
   637 	{
       
   638 	_LIT(KTestServerShutdownWithIndex,"Testing calendar file close timer...");
       
   639 	test.Next(KTestServerShutdownWithIndex);
       
   640 
       
   641 	
       
   642 	iTestCase = ETestServerShutdownWithIndex;
       
   643 	
       
   644 	CreateSessionL();
       
   645 	
       
   646 	// Logon to the agenda server process in order to be notified when the process exits / dies
       
   647 	ProcessLogonL();
       
   648 
       
   649 	CreateEntryViewL(KServerShutdownCalFile, ETrue);  // the index should be built here
       
   650 	CloseEntryView();
       
   651 
       
   652 	// Record a timestamp before initiating server shutdown
       
   653 	// Server shutdown period is checked against the expected range when the process exits
       
   654 	RecordTimeStampBeforeServerShutdown();
       
   655 	
       
   656 	// Close the session which will trigger the delay timer and wait for the agenda server to close since this is the end of the test case
       
   657 	CloseSession(ETrue);
       
   658 	}
       
   659 
       
   660 // Test the cancellation of a file close delay timer with a single calendar file
       
   661 
       
   662 void CServerShutdownTestManager::TestServerShutdownCancelWithIndexL()
       
   663 	{
       
   664 	_LIT(KTestServerShutdownCancelWithIndex,"Testing calendar file close timer cancellation...");
       
   665 	test.Next(KTestServerShutdownCancelWithIndex);
       
   666 
       
   667 
       
   668 	iTestCase = ETestServerShutdownCancelWithIndexStart;
       
   669 	
       
   670 	CreateSessionL();
       
   671 	
       
   672 	// Logon to the agenda server process in order to be notified when the process exits / dies
       
   673 	ProcessLogonL();
       
   674 
       
   675 	CreateEntryViewL(KServerShutdownCalFile, ETrue);  // the index should be built here
       
   676 	CloseEntryView();
       
   677 	
       
   678 	// Close the session which will trigger the delay timer but do not wait for the agenda server to close since we need proceed with the rest of the test case
       
   679 	CloseSession(EFalse);
       
   680 
       
   681 	// Trigger an asynchronous delay with more than half the period of the expected sever shutdown period
       
   682 	// We will trigger another identical asynchronous delay with the same period and then test that the server is still alive
       
   683 	AsyncDelay(KServerCancelDelay);
       
   684 	
       
   685 	CreateSessionL();
       
   686 
       
   687 	iTestCase = ETestServerShutdownCancelWithIndexCancelled;
       
   688 	CreateEntryViewL(KServerShutdownCalFile, ETrue);  // the index should NOT be rebuilt here
       
   689 
       
   690 	_LIT(KAgendaServerCloseNotExpected,"The agenda shutdown should be cancelled agenda server should not close now\n");
       
   691 	test.Printf(KAgendaServerCloseNotExpected);
       
   692 	
       
   693 	// The agenda server should not shutdown in the course of this asynchronous delay 
       
   694 	AsyncDelay(KServerCancelDelay);
       
   695 
       
   696 	iTestCase = ETestServerShutdownCancelWithIndexShutdown;
       
   697 	
       
   698 	// Record the time before initiating server shutdown
       
   699 	// Server shutdown period is checked against the expected range when the process exits
       
   700 	RecordTimeStampBeforeServerShutdown();
       
   701 	
       
   702 	CloseEntryView();
       
   703 	
       
   704 	// Close the session which will trigger the delay timer and wait for the agenda server to close since this is the end of the test case
       
   705 	CloseSession(ETrue);
       
   706 	}
       
   707 
       
   708 // Test the file close delay timer by opening and closing a calendar file under OOM conditions
       
   709 // This function is called by the OOM callback
       
   710 
       
   711 
       
   712 void CServerShutdownTestManager::TestServerShutdownOpenCloseFileOOML()
       
   713 	{
       
   714 	_LIT(KTestServerShutdownOpenCloseFileOOM,"Testing open and close calendar file under OOM conditions");
       
   715 	test.Next(KTestServerShutdownOpenCloseFileOOM);
       
   716 
       
   717 	
       
   718 	CCalSession* calSession = CCalSession::NewL();
       
   719 	CleanupStack::PushL(calSession);
       
   720 	
       
   721 	_LIT(KCreatingCalEntryViewOOM, "Creating the Entry View under OOM\n");
       
   722 	test.Printf(KCreatingCalEntryViewOOM);
       
   723 	
       
   724 	calSession->OpenL(KServerShutdownCalFile);
       
   725 
       
   726 	CCalEntryView* calEntryView = CCalEntryView::NewL(*calSession);
       
   727 	CleanupStack::PushL(calEntryView); 
       
   728 		
       
   729 	CleanupStack::PopAndDestroy(calEntryView);
       
   730 	CleanupStack::PopAndDestroy(calSession);
       
   731 	}
       
   732 
       
   733 // Test the file close delay timer by deleting a calendar file under OOM conditions
       
   734 // The calendar file must exist before deletion. This is ensured by OOM callback which then calls this test case
       
   735 
       
   736 
       
   737 void CServerShutdownTestManager::TestServerShutdownDeleteFileOOML(TInt aFailAt)
       
   738 	{
       
   739 	_LIT(KTestServerShutdownDeleteFileOOM, "Testing calendar file deletion under OOM conditions");
       
   740 	test.Next(KTestServerShutdownDeleteFileOOM);
       
   741 
       
   742 
       
   743 	// Set an invalid file position
       
   744 	TInt filePostion = -1;
       
   745 	
       
   746 	CCalSession* calSession = CCalSession::NewL();
       
   747 	CleanupStack::PushL(calSession);	
       
   748 
       
   749 	// Reset the server side OOM allocation failure until we invoke the deletion
       
   750 	calSession->_DebugSetHeapFailL(RAllocator::ENone, 0);
       
   751 
       
   752 	_LIT(KCheckFileExistsBeforeDeletionOOM, "Ensure that the calendar file exists before deletion - OOM test");
       
   753 	test.Printf(KCheckFileExistsBeforeDeletionOOM);
       
   754 	
       
   755 	// Check the calendar file exists before deletion
       
   756 	CDesCArray* fileArray = NULL;
       
   757 	fileArray = calSession->ListCalFilesL();
       
   758 	CleanupStack::PushL(fileArray);
       
   759 
       
   760 	fileArray->Find(KServerShutdownCalFileToDeleteOOM,filePostion);
       
   761 	test(fileArray->Count());
       
   762 	test(filePostion != fileArray->Count());
       
   763 	
       
   764 	CleanupStack::PopAndDestroy(fileArray);
       
   765 	
       
   766 	// Set the server side OOM allocation failure
       
   767 	calSession->_DebugSetHeapFailL(RAllocator::EDeterministic, aFailAt);
       
   768 	
       
   769 	// Time the delete operation and test that the delay timer is not triggered
       
   770 	TPerformanceTimer deleteTimer (test);
       
   771 	deleteTimer.Start();
       
   772 	calSession->DeleteCalFileL(KServerShutdownCalFileToDeleteOOM);
       
   773 	deleteTimer.Stop();
       
   774 	test(deleteTimer.ElapsedTime() < KServerShutdownDelayMin);
       
   775 	
       
   776 	// Reset the server side OOM allocation failure
       
   777 	calSession->_DebugSetHeapFailL(RAllocator::ENone, 0);
       
   778 	
       
   779 	fileArray = calSession->ListCalFilesL();
       
   780 
       
   781 	CleanupStack::PushL(fileArray);
       
   782 	fileArray->Find(KServerShutdownCalFileToDeleteOOM,filePostion);
       
   783 
       
   784 	// Ensure that the file was deleted
       
   785 	if(fileArray->Count())
       
   786 		{
       
   787 		test(filePostion == fileArray->Count());	
       
   788 		}
       
   789 	else
       
   790 		{
       
   791 		test(filePostion == 0);
       
   792 		}
       
   793 
       
   794 	_LIT(KFileSuccessfullyDeletedOOM, "Calendar file deleted successfully - OOM test");
       
   795 	test.Next(KFileSuccessfullyDeletedOOM);
       
   796 
       
   797 	
       
   798 	CleanupStack::PopAndDestroy(fileArray);
       
   799 	CleanupStack::PopAndDestroy(calSession);
       
   800 	}
       
   801 
       
   802 // Test the file close delay timer is not triggered when the calendar file is deleted
       
   803 
       
   804 
       
   805 void CServerShutdownTestManager::TestServerShutdownDeleteFileL()
       
   806 	{
       
   807 	_LIT(KTestServerShutdownDeleteFile, "Testing calendar file deletion...");
       
   808 
       
   809 	test.Next(KTestServerShutdownDeleteFile);
       
   810 
       
   811 	
       
   812 	iTestCase = ETestServerShutdownDeleteFile;
       
   813 	
       
   814 	// Make a copy of the calendar file before testing its deletion
       
   815 	iPIMTestServer.CopyFileL(KServerShutdownCalFileRAM, KServerShutdownCalFileToDeleteRAM);
       
   816 	// In case this test case fails, the register will cleanup the file
       
   817 	iFileRegister->RegisterL(KServerShutdownCalFileToDelete, EFileTypeAgn);
       
   818 	
       
   819 	// Set an invalid file position
       
   820 	TInt filePostion = -1;
       
   821 	
       
   822 	// Create a session - this will start the agenda server
       
   823 	CreateSessionL();
       
   824 	// Logon to the agenda server process in order to be notified when the process exits / dies
       
   825 	ProcessLogonL();
       
   826 	CreateEntryViewL(KServerShutdownCalFileToDelete, ETrue);
       
   827 	CloseEntryView();
       
   828 	
       
   829 	_LIT(KCheckFileExistsBeforeDeletion, "Ensure that the calendar file exists before deletion");
       
   830 	test.Printf(KCheckFileExistsBeforeDeletion);
       
   831 
       
   832 	CDesCArray* fileArray = NULL;
       
   833 	fileArray = iSession->ListCalFilesL();
       
   834 	CleanupStack::PushL(fileArray);
       
   835 	
       
   836 	fileArray->Find(KServerShutdownCalFileToDelete,filePostion);
       
   837 	test(fileArray->Count());
       
   838 	test(filePostion != fileArray->Count());
       
   839 	
       
   840 	CleanupStack::PopAndDestroy(fileArray);
       
   841 
       
   842 	// Time the delete operation and test that the delay timer is not triggered
       
   843 	TPerformanceTimer deleteTimer (test);
       
   844 	deleteTimer.Start();
       
   845 	TRAPD(err, iSession->DeleteCalFileL(KServerShutdownCalFileToDelete));
       
   846 	test(err==KErrNone);
       
   847 	deleteTimer.Stop();
       
   848 	test(deleteTimer.ElapsedTime() < KServerShutdownDelayMin);
       
   849 	
       
   850 	fileArray = iSession->ListCalFilesL();
       
   851 
       
   852 	CleanupStack::PushL(fileArray);
       
   853 	
       
   854 	fileArray->Find(KServerShutdownCalFileToDelete,filePostion);
       
   855 	
       
   856 	// Ensure that the file was deleted
       
   857 	if(fileArray->Count())
       
   858 		{
       
   859 		test(filePostion == fileArray->Count());	
       
   860 		}
       
   861 	else
       
   862 		{
       
   863 		test(filePostion == 0);
       
   864 		}
       
   865 
       
   866 	_LIT(KFileSuccessfullyDeleted, "Calendar file deleted successfully");
       
   867 
       
   868 	test.Next(KFileSuccessfullyDeleted);
       
   869 
       
   870 
       
   871 	CleanupStack::PopAndDestroy(fileArray);
       
   872 	
       
   873 	// Close the session which will trigger the delay timer and wait for the agenda server to close since this is the end of the test case
       
   874 	CloseSession(ETrue);
       
   875 	}
       
   876 
       
   877 // Test the file close delay timer is cancelled on a calendar file if a session associated with a different calendar file deletes it
       
   878 // It should not return with KErrInUse because of the delay timer
       
   879 
       
   880 void CServerShutdownTestManager::TestServerShutdownDeleteMultiFilesL()
       
   881 	{
       
   882 	_LIT(KTestServerShutdownDeleteMultiFiles, "Testing  calendar file deletion with multiple files...");
       
   883 	test.Next(KTestServerShutdownDeleteMultiFiles);
       
   884 
       
   885 	
       
   886 	iTestCase = ETestServerShutdownDeleteMultiFiles;
       
   887 	
       
   888 	// Make a copy of the calendar file before testing its deletion
       
   889 	iPIMTestServer.CopyFileL(KServerShutdownCalFileRAM, KServerShutdownCalFileToDeleteRAM);
       
   890 	// In case this test case fails, the register will cleanup the file
       
   891 	iFileRegister->RegisterL(KServerShutdownCalFileToDelete, EFileTypeAgn);
       
   892 	
       
   893 	// Create two sessions and open two entry views on different files
       
   894 	CreateSessionL();
       
   895 	// Logon to the agenda server process in order to be notified when the process exits / dies
       
   896 	ProcessLogonL();
       
   897 	CreateEntryViewL(KServerShutdownCalFileToDelete, ETrue);
       
   898 	CloseEntryView();
       
   899 	
       
   900 	// Close the session which will trigger the delay timer but do not wait for the agenda server to close since we need proceed with the rest of the test case
       
   901 	CloseSession(EFalse);
       
   902 		
       
   903 	CreateAdditionalSessionL();
       
   904 	CreateAdditionalEntryViewL(KServerShutdownCalFileMultifFile, ETrue);
       
   905 	CloseAdditionalEntryView();
       
   906 	
       
   907 	// Delete a calendar file NOT associated with the current session
       
   908 	TRAPD(err, iAdditionalSession->DeleteCalFileL(KServerShutdownCalFileToDelete));
       
   909 	// Should cancel  the timer on the calendar file and then delete it. It should not return with KErrInUse because of the delay timer
       
   910 	test(err ==KErrNone);
       
   911 	
       
   912 	// Record the time before initiating server shutdown
       
   913 	// Server shutdown period is checked against the expected range when the process exits
       
   914 	RecordTimeStampBeforeServerShutdown();
       
   915 	
       
   916 	// Wait for the agenda server to close
       
   917 	CloseAdditionalSession(ETrue);	
       
   918 	}
       
   919 
       
   920 // Test the file close delay timer is not triggered when the server is killed and terminated both with or without an entry view
       
   921 
       
   922 void CServerShutdownTestManager::TestServerShutdownProcessExitL()
       
   923 	{
       
   924 	_LIT(KTestServerShutdownProcessExit, "Testing agenda server shutdown by killing or terminating the server process");
       
   925 	test.Next(KTestServerShutdownProcessExit);
       
   926 
       
   927 	
       
   928 	iTestCase = ETestServerShutdownProcessExit;
       
   929 
       
   930 	TPerformanceTimer killTimer(test);
       
   931 	
       
   932 	CreateSessionL();
       
   933 	// Logon to the agenda server process in order to be notified when the process exits / dies
       
   934 	ProcessLogonL();
       
   935 	killTimer .Start();
       
   936 	// Close the session which will trigger the delay timer but do not wait for the agenda server to close since we need proceed with the rest of the test case
       
   937 	CloseSession(EFalse);
       
   938 	// Test Kill - Session only
       
   939 	iProcess.Kill(KErrNone);
       
   940 	CActiveScheduler::Start();
       
   941 	killTimer .Stop();
       
   942 	test(killTimer .ElapsedTime() < KServerShutdownDelayMin);
       
   943 
       
   944 	CreateSessionL();
       
   945 	// Logon to the agenda server process in order to be notified when the process exits / dies
       
   946 	ProcessLogonL();
       
   947 	killTimer .Start();
       
   948 	// Close the session which will trigger the delay timer but do not wait for the agenda server to close since we need proceed with the rest of the test case
       
   949 	CloseSession(EFalse);
       
   950 	// Test Terminate - Session only
       
   951 	iProcess.Terminate(KErrNone);
       
   952 	CActiveScheduler::Start();
       
   953 	killTimer .Stop();
       
   954 	test(killTimer .ElapsedTime() < KServerShutdownDelayMin);
       
   955 	
       
   956 	CreateSessionL();
       
   957 	// Logon to the agenda server process in order to be notified when the process exits / dies
       
   958 	ProcessLogonL();
       
   959 
       
   960 	CreateEntryViewL(KServerShutdownCalFile, ETrue);  // the index should be built here
       
   961 	CloseEntryView();
       
   962 	killTimer .Start();
       
   963 	// Close the session which will trigger the delay timer but do not wait for the agenda server to close since we need proceed with the rest of the test case
       
   964 	CloseSession(EFalse);
       
   965 	// Test Kill - Session and Entry View
       
   966 	iProcess.Kill(KErrNone);
       
   967 	CActiveScheduler::Start();
       
   968 	killTimer .Stop();
       
   969 	test(killTimer .ElapsedTime() < KServerShutdownDelayMin);
       
   970 	
       
   971 	CreateSessionL();
       
   972 	// Logon to the agenda server process in order to be notified when the process exits / dies
       
   973 	ProcessLogonL();
       
   974 	CreateEntryViewL(KServerShutdownCalFile, ETrue);  // the index should be built here
       
   975 	CloseEntryView();
       
   976 	killTimer .Start();
       
   977 	// Close the session which will trigger the delay timer but do not wait for the agenda server to close since we need proceed with the rest of the test case
       
   978 	CloseSession(EFalse);
       
   979 	// Test Terminate - Session and Entry View
       
   980 	iProcess.Terminate(KErrNone);
       
   981 	CActiveScheduler::Start();
       
   982 	killTimer .Stop();
       
   983 	test(killTimer .ElapsedTime() < KServerShutdownDelayMin);
       
   984 	}
       
   985 
       
   986 // OOM Callback 
       
   987 // Test the file close delay timer by opening and closing and deleting a calendar file under OOM conditions
       
   988 void CServerShutdownTestManager::OomTestL(TType aType, TInt aFailAt)
       
   989 	{
       
   990 	if(aType == EServer)
       
   991 		{
       
   992 		_LIT(KOOMFailAt, "OOM %d\n");
       
   993 		test.Printf(KOOMFailAt, aFailAt);
       
   994 	
       
   995 		switch(iTestCase)
       
   996 			{
       
   997 			case ETestServerShutdownOOMDeleteFile:
       
   998 				{
       
   999 				// Test deleting a calendar file under OOM conditions
       
  1000 				TestServerShutdownDeleteFileOOML(aFailAt);
       
  1001 				}
       
  1002 			break;		
       
  1003 			case ETestServerShutdownOOMOpenCloseFile:
       
  1004 				{
       
  1005 				// Test opening and closing a calendar file under OOM conditions
       
  1006 				TestServerShutdownOpenCloseFileOOML();
       
  1007 				}
       
  1008 			break;		
       
  1009 			default:
       
  1010 				{
       
  1011 				}
       
  1012 			break;
       
  1013 			}
       
  1014 		}
       
  1015 
       
  1016 	}
       
  1017 
       
  1018 // Test the file close delay timer under OOM conditions whilst opening and closing and deleting a calendar file
       
  1019 
       
  1020 void CServerShutdownTestManager::TestServerShutdownOOML()
       
  1021 	{
       
  1022 	_LIT(KTestServerShutdownOOM, "Test opening and closing the session, deleting calendar file and B&R under OOM conditions");
       
  1023 	test.Next(KTestServerShutdownOOM);
       
  1024 
       
  1025 
       
  1026 	// Make a copy of the calendar file before testing its deletion
       
  1027 	iPIMTestServer.CopyFileL(KServerShutdownCalFileRAM, KServerShutdownCalFileToDeleteRAM_OOM);
       
  1028 	iFileRegister->RegisterL(KServerShutdownCalFileToDeleteOOM, EFileTypeAgn);
       
  1029 	
       
  1030 
       
  1031 	//OutOfMemoryTestL() needs a calsession.
       
  1032 	CreateSessionL();
       
  1033 	
       
  1034 	// Test open and close of a calendar file under OOM conditions
       
  1035 	iTestCase = ETestServerShutdownOOMOpenCloseFile; 
       
  1036 	CalTestOom::OutOfMemoryTestL(*this, EServer, *iSession); 
       
  1037 	
       
  1038 	// Test deletion of a calendar file under OOM conditions
       
  1039 	iTestCase = ETestServerShutdownOOMDeleteFile;
       
  1040 	CalTestOom::OutOfMemoryTestL(*this, EServer, *iSession); 
       
  1041 	}
       
  1042 
       
  1043 // Test the file close delay timer avoids the rebuilding of indexes when the same calendar file is opened twice in the same session
       
  1044 
       
  1045 void CServerShutdownTestManager::TestServerShutdownSingleSessionOpenTwiceL()
       
  1046 	{
       
  1047 	_LIT(KTestServerShutdownSingleSessionOpenTwice, "Test that open agenda twice in a single session prevents the rebuilding of indexes");
       
  1048 	test.Next(KTestServerShutdownSingleSessionOpenTwice);
       
  1049 
       
  1050 	
       
  1051 	iTestCase = ETestServerSingleSessionOpenTwiceStart;
       
  1052 	
       
  1053 	// Create a session - this will start the agenda server
       
  1054 	CreateSessionL();
       
  1055 	// Logon to the agenda server process in order to be notified when the process exits / dies
       
  1056 	ProcessLogonL();
       
  1057 	CreateEntryViewL(KServerShutdownCalFile, ETrue);
       
  1058 	CloseEntryView();
       
  1059 	
       
  1060 	iTestCase = ETestServerSingleSessionOpenTwiceShutdown;
       
  1061 
       
  1062 	CreateEntryViewL(KServerShutdownCalFile, ETrue); // Indexes should NOT be rebuilt here
       
  1063 	CloseEntryView();
       
  1064 	
       
  1065 	// Record the time before initiating server shutdown
       
  1066 	// Server shutdown period is checked against the expected range when the process exits
       
  1067 	RecordTimeStampBeforeServerShutdown();
       
  1068 	
       
  1069 	// Close the session which will trigger the delay timer and wait for the agenda server to close since this is the end of the test case
       
  1070 	CloseSession(ETrue);
       
  1071 	}
       
  1072 
       
  1073 // Test the file close delay timer does not shutdown the server when a session out of multiple sessions to a single calendar file is closed and
       
  1074 // that the indexes are not rebuilt when another session reconnects to the file
       
  1075 
       
  1076 void CServerShutdownTestManager::TestServerShutdownMultiSessionSingleFileOpenL()
       
  1077 	{
       
  1078 	_LIT(KTestServerShutdownMultiSessionSingleFileOpen, "Testing agenda server's shutdown behaviour when closing a session out of multiple sessions to a calendar file");
       
  1079 	test.Next(KTestServerShutdownMultiSessionSingleFileOpen);
       
  1080 
       
  1081 	
       
  1082 	iTestCase = ETestServerMultiSessionSingleFileOpenStart;
       
  1083 	
       
  1084 	// Create two sessions: Open two entry views on the same file, close one, wait and reopen the first one
       
  1085 	// and ensure that the indexes dont get rebuilt
       
  1086 	CreateSessionL();
       
  1087 	// Logon to the agenda server process in order to be notified when the process exits / dies
       
  1088 	ProcessLogonL();
       
  1089 	CreateEntryViewL(KServerShutdownCalFile, ETrue);
       
  1090 	CloseEntryView();
       
  1091 	
       
  1092 	CreateAdditionalSessionL();
       
  1093 	CreateAdditionalEntryViewL(KServerShutdownCalFile, ETrue);
       
  1094 	CloseAdditionalEntryView();
       
  1095 	
       
  1096 	// Close the session which will trigger the delay timer but do not wait for the agenda server to close since we need proceed with the rest of the test case
       
  1097 	CloseSession(EFalse);
       
  1098 	
       
  1099 	// The agenda server should NOT shutdown in the course of this asynchronous delay
       
  1100 	AsyncDelay(KServerShutdownDelayMax);
       
  1101 
       
  1102 	iTestCase = ETestServerMultiSessionSingleFileOpen;
       
  1103 	
       
  1104 	// Re-open the same calendar file to ensure that the indexes are NOT rebuilt
       
  1105 	CreateSessionL();
       
  1106 	CreateEntryViewL(KServerShutdownCalFile, ETrue);
       
  1107 	CloseEntryView();
       
  1108 
       
  1109 	// Close the session which will trigger the delay timer but do not wait for the agenda server to close since we need proceed with the rest of the test case
       
  1110 	CloseSession(EFalse);
       
  1111 
       
  1112 	iTestCase = ETestServerMultiSessionSingleFileOpenShutdown;
       
  1113 	
       
  1114 	// Record the time before initiating server shutdown
       
  1115 	// Server shutdown period is checked against the expected range when the process exits
       
  1116 	RecordTimeStampBeforeServerShutdown();
       
  1117 
       
  1118 	// Wait for the agenda server to close
       
  1119 	CloseAdditionalSession(ETrue);
       
  1120 	}
       
  1121 
       
  1122 // Test the file close delay timer does not shutdown the server when a session out of multiple sessions to two separate calendar files is closed
       
  1123 
       
  1124 void CServerShutdownTestManager::TestServerShutdownMultiSessionMultiFileOpenL()
       
  1125 	{
       
  1126 	_LIT(KTestServerShutdownMultiSessionMultiFileOpen, "Testing agenda server's shutdown behaviour when closing a session out of multiple sessions to a multiple calendar files");
       
  1127 	test.Next(KTestServerShutdownMultiSessionMultiFileOpen);
       
  1128 
       
  1129 
       
  1130 	iTestCase = ETestServerMultiSessionMultiFileOpenStart;
       
  1131 	
       
  1132 	// Create two sessions and open two entry views on different files
       
  1133 	CreateSessionL();
       
  1134 	// Logon to the agenda server process in order to be notified when the process exits / dies
       
  1135 	ProcessLogonL();
       
  1136 	CreateEntryViewL(KServerShutdownCalFile, ETrue);
       
  1137 	CloseEntryView();
       
  1138 
       
  1139 	CreateAdditionalSessionL();
       
  1140 	CreateAdditionalEntryViewL(KServerShutdownCalFileMultifFile, ETrue);
       
  1141 	CloseAdditionalEntryView();
       
  1142 	
       
  1143 	// Close the session which will trigger the delay timer but do not wait for the agenda server to close since we need proceed with the rest of the test case
       
  1144 	CloseAdditionalSession(EFalse);	
       
  1145 	
       
  1146 	// Trigger an asynchronous delay with more than half the period of the expected sever shutdown period
       
  1147 	// We will trigger another identical asynchronous delay with the same period and then test that the server is still alive
       
  1148 	AsyncDelay(KServerCancelDelay);
       
  1149 	
       
  1150 	// Record the time before initiating server shutdown
       
  1151 	// Server shutdown period is checked against the expected range when the process exits
       
  1152 	RecordTimeStampBeforeServerShutdown();
       
  1153 
       
  1154 	// Close the session which will trigger the delay timer but do not wait for the agenda server to close since we need proceed with the rest of the test case
       
  1155 	CloseSession(EFalse);
       
  1156 
       
  1157 	// The agenda server should not shutdown in the course of this asynchronous delay 
       
  1158 	AsyncDelay(KServerCancelDelay);
       
  1159 
       
  1160 	iTestCase = ETestServerMultiSessionMultiFileOpenShutdown;
       
  1161 	// Wait for the agenda server to shutdown
       
  1162 	CActiveScheduler::Start();
       
  1163 	}
       
  1164 
       
  1165 // Test the file close delay timer is not triggered and the calendar file is closed immediately when opening a calendar file leaves
       
  1166 
       
  1167 void CServerShutdownTestManager::TestServerShutdownOpenInvalidFileLeaveL()
       
  1168 	{
       
  1169 	_LIT(KTestServerShutdownOpenInvalidFileLeave, "Testing agenda server's behaviour when a leave occurs when opening an invalid calendar file");
       
  1170 	test.Next(KTestServerShutdownOpenInvalidFileLeave);
       
  1171 
       
  1172 
       
  1173 	iTestCase = ETestServerShutdownOpenInvalidFileLeave;
       
  1174 	
       
  1175 	// Create two sessions and open two entry views on different files
       
  1176 	CreateSessionL();
       
  1177 	// Logon to the agenda server process in order to be notified when the process exits / dies
       
  1178 	ProcessLogonL();
       
  1179 	
       
  1180 	TPerformanceTimer deleteTimer (test);
       
  1181 	deleteTimer.Start();
       
  1182 	TRAPD(err, CreateEntryViewL(KServerShutdownBadCalFileName, ETrue));
       
  1183 	test(err==KErrNotFound);
       
  1184 	deleteTimer.Stop();
       
  1185 	test(deleteTimer.ElapsedTime() < KServerShutdownDelayMin);
       
  1186 
       
  1187 	// Close the session which will trigger the delay timer and wait for the agenda server to close since this is the end of the test case
       
  1188 	CloseSession(ETrue);
       
  1189 	}
       
  1190 
       
  1191 void CServerShutdownTestManager::TestServerShutdownTestOldCalendarFileConversionL()
       
  1192 	{
       
  1193 	_LIT(KTestServerShutdownTestOldCalendarFileConversion, "Testing closing of calender file when conversion is required");
       
  1194 	test.Next(KTestServerShutdownTestOldCalendarFileConversion);
       
  1195 
       
  1196 	
       
  1197 	iTestCase = ETestServerShutdownv91CalendarFileConversion;
       
  1198 	
       
  1199 	// Create a session to the agenda server
       
  1200 	CreateSessionL();
       
  1201 	// Logon to the agenda server process in order to be notified when the process exits / dies
       
  1202 	ProcessLogonL();
       
  1203 	// Open a older verison of the calendar file - v9.1. This will initiate conversion and test the closing of the calendar file
       
  1204 	CreateEntryViewL(KServerShutdown91CalFile, ETrue);
       
  1205 	CloseEntryView();
       
  1206 
       
  1207 	// Record the time before initiating server shutdown
       
  1208 	// Server shutdown period is checked against the expected range when the process exits
       
  1209 	RecordTimeStampBeforeServerShutdown();
       
  1210 	
       
  1211 	// Close the session which will trigger the delay timer and wait for the agenda server to close since this is the end of the test case
       
  1212 	CloseSession(ETrue);
       
  1213 	}
       
  1214 #ifdef SYMBIAN_SYSTEM_STATE_MANAGEMENT
       
  1215 
       
  1216 
       
  1217 void CServerShutdownTestManager::TestServerShutdownWithSystemStateNotificationsL()
       
  1218 	{
       
  1219 	_LIT(KTestServerShutdownTestSystemStateShutdown, "Testing closing of calender file after system state shutdown notifications.");
       
  1220 	_LIT8(KTestSystemShutdown,"system shutdown test1");
       
  1221 	test.Next(KTestServerShutdownTestSystemStateShutdown);
       
  1222 
       
  1223 	iTestCase = ETestServerShutdownWithSystemStateNotification;
       
  1224 	
       
  1225 	// Create a session to the agenda server
       
  1226 	CreateSessionL();
       
  1227 	CreateEntryViewL(KServerShutdownCalFile, ETrue);
       
  1228 	CreateEntry(KTestSystemShutdown);
       
  1229 	// Logon to the agenda server process in order to be notified when the process exits / dies
       
  1230 	ProcessLogonL();
       
  1231 	SubscribeToSystemNotification();
       
  1232 	SendSystemStateNotification(ESystemStateShutdown);
       
  1233 	TestPostShutdownOperationsL(KTestSystemShutdown, KErrLocked, 1);
       
  1234 	CloseEntryView();
       
  1235 	CloseSession(EFalse);
       
  1236 	User::WaitForRequest(iStatus);
       
  1237 	CActiveScheduler::Start();
       
  1238 	}
       
  1239 
       
  1240 
       
  1241 void CServerShutdownTestManager::TestServerShutdownWithNormalSystemStateNotification()
       
  1242 	{
       
  1243 	_LIT(KTestServerShutdownTestSystemStateShutdown, "Testing closing of calender file after system state shutdown notifications.");
       
  1244 	_LIT8(KTestSystemShutdown,"system shutdown normal");
       
  1245 	test.Next(KTestServerShutdownTestSystemStateShutdown);
       
  1246 
       
  1247 	iTestCase = ETestServerShutdownWithSystemStateNotificationNormal;
       
  1248 
       
  1249 	// Create a session to the agenda server
       
  1250 	CreateSessionL();
       
  1251 	CreateEntryViewL(KServerShutdownCalFile, ETrue);
       
  1252 	CreateEntry(KTestSystemShutdown);
       
  1253 	// Logon to the agenda server process in order to be notified when the process exits / dies
       
  1254 	ProcessLogonL();
       
  1255 	SubscribeToSystemNotification();
       
  1256 	SendSystemStateNotification(ESystemStateShutdown);
       
  1257 	TestPostShutdownOperationsL(KTestSystemShutdown, KErrLocked, 1);
       
  1258 	SendSystemStateNotification(ESystemStateNormal);
       
  1259 	TestPostShutdownOperationsL(KTestSystemShutdown, KErrNone, 1);
       
  1260 	CloseEntryView();
       
  1261 	CloseSession(EFalse);
       
  1262 	User::WaitForRequest(iStatus);
       
  1263 	CActiveScheduler::Start();
       
  1264 	}
       
  1265 
       
  1266 void CServerShutdownTestManager::TestServerShutdownWithSystemStateNotificationsAsyncL()
       
  1267 	{
       
  1268 	_LIT(KTestServerShutdownTestSystemStateShutdownAsync, "Testing closing of calender file after system state shutdown notifications and an asychronous delete operation.");
       
  1269 	test.Next(KTestServerShutdownTestSystemStateShutdownAsync);
       
  1270 
       
  1271 	_LIT8(KTestServerShutdown, "shutdown test async");
       
  1272 	iTestCase = ETestServerShutdownWithSystemStateNotificationAsync;
       
  1273 
       
  1274 	// Create a session to the agenda server
       
  1275 	CreateSessionL();
       
  1276 	CreateEntryViewL(KServerShutdownCalFile, ETrue);
       
  1277 	CreateEntry(KTestServerShutdown);
       
  1278 	// Logon to the agenda server process in order to be notified when the process exits / dies
       
  1279 	ProcessLogonL();
       
  1280 	TestAsycnDeleteOperationL();
       
  1281 	SubscribeToSystemNotification();
       
  1282 	SendSystemStateNotification(ESystemStateShutdown);
       
  1283 	CloseEntryView();
       
  1284 	CloseSession(EFalse);
       
  1285 	User::WaitForRequest(iStatus);
       
  1286 	CActiveScheduler::Start();
       
  1287 	}
       
  1288 
       
  1289 void CServerShutdownTestManager::CreateRecurringEntriesL(const TDesC8& aGuid)
       
  1290 	{
       
  1291 	
       
  1292 	RPointerArray<CCalEntry> entries;
       
  1293 	CleanupResetAndDestroyPushL(entries);
       
  1294 
       
  1295 	test.Printf(_L("creating an entry on 3rd September at 9:30\n"));
       
  1296     HBufC8* guid = aGuid.AllocLC();
       
  1297 	// creating a todo entry
       
  1298 	CCalEntry* calEntry = CCalEntry::NewL(CCalEntry::ETodo, guid, CCalEntry::EMethodNone, 0);
       
  1299 	CleanupStack::Pop(guid);
       
  1300 	CleanupStack::PushL(calEntry);
       
  1301 
       
  1302 	TDateTime dtStart(2008,ESeptember,10,10,30,0,0);
       
  1303 	TCalTime startCalTime;
       
  1304 	TCalTime endCalTime;
       
  1305 
       
  1306 	startCalTime.SetTimeUtcL(dtStart);
       
  1307 
       
  1308 	endCalTime.SetTimeUtcL(dtStart);   
       
  1309 
       
  1310 	calEntry->SetStartAndEndTimeL(startCalTime,endCalTime);
       
  1311 
       
  1312 	//setting the repeat rule
       
  1313 	TCalRRule calRule(TCalRRule::EYearly);
       
  1314 	calRule.SetDtStart(startCalTime);
       
  1315 	calRule.SetInterval(1);
       
  1316 	calRule.SetCount( 5 );
       
  1317 
       
  1318 	calEntry->SetRRuleL(calRule);
       
  1319 
       
  1320 	TCalTime rDate1;
       
  1321 	TCalTime rDate2;
       
  1322 	TCalTime rDate3;
       
  1323 	TCalTime rDate4;
       
  1324 	TCalTime rDate5;
       
  1325 
       
  1326 	rDate1.SetTimeUtcL(TDateTime(2008, EOctober, 2, 10, 0, 0, 0));
       
  1327 	rDate2.SetTimeUtcL(TDateTime(2008, EOctober, 2, 10, 40, 0, 0)); // Same date like before but differs only by time
       
  1328 	rDate3.SetTimeUtcL(TDateTime(2008, EOctober, 2, 10, 40, 25, 0)); // Same date like before but differs only by time
       
  1329 	rDate4.SetTimeUtcL(TDateTime(2008, EOctober, 2, 10, 40, 25, 12)); // Same date like before but differs only by time
       
  1330 	rDate5.SetTimeUtcL(TDateTime(2008, EOctober, 3, 10, 0, 0, 0));
       
  1331 	
       
  1332 	RArray<TCalTime> rDateArray;
       
  1333 	CleanupClosePushL(rDateArray);
       
  1334 	rDateArray.AppendL(rDate1);
       
  1335 	rDateArray.AppendL(rDate2);
       
  1336 	rDateArray.AppendL(rDate3);
       
  1337 	rDateArray.AppendL(rDate4);
       
  1338 	rDateArray.AppendL(rDate5);
       
  1339 
       
  1340 	calEntry->SetRDatesL(rDateArray);
       
  1341 	CleanupStack::PopAndDestroy(&rDateArray);
       
  1342 	TInt stored(0);
       
  1343 	entries.AppendL(calEntry);
       
  1344 	CleanupStack::Pop(calEntry);
       
  1345 	iEntryView->StoreL(entries, stored);
       
  1346 	test(stored == entries.Count());
       
  1347 	CleanupStack::PopAndDestroy(&entries);//entries
       
  1348 	}
       
  1349 
       
  1350 void CServerShutdownTestManager::TestInstanceViewOperationsL()
       
  1351 	{
       
  1352 	TCalTime calTimeStart;
       
  1353 	TCalTime calTimeEnd;
       
  1354 
       
  1355 	calTimeStart.SetTimeUtcL(TDateTime(2008, EAugust, 30, 2, 7, 0, 0));
       
  1356 	calTimeEnd.SetTimeUtcL(TDateTime(2011, EOctober, 30, 2, 10, 0, 0));
       
  1357 
       
  1358 	RPointerArray<CCalInstance> instances;
       
  1359 	CleanupResetAndDestroyPushL(instances);
       
  1360 	CalCommon::TCalViewFilter filter(CalCommon::EIncludeAll);
       
  1361 	CalCommon::TCalTimeRange timeRange(calTimeStart, calTimeEnd);
       
  1362 
       
  1363 	test.Printf(_L("Calling FindInstance\n"));
       
  1364 
       
  1365 	TRAPD(err, iInstanceView->FindInstanceL(instances, filter, timeRange));
       
  1366 	
       
  1367 	TInt instanceCount = instances.Count();
       
  1368 //	test ( instances.Count() == 10 );//5 Repeat instances + 5 Sporadic instances
       
  1369 
       
  1370 	TRAPD(errDelete, iInstanceView->DeleteL(instances[0],CalCommon::EThisAndAll));//delete all the instances for other tests
       
  1371 	test (errDelete == KErrLocked);
       
  1372 	CleanupStack::PopAndDestroy(&instances);
       
  1373 	}
       
  1374 
       
  1375 
       
  1376 void CServerShutdownTestManager::TestServerShutdownWithStateNotificationAndInstanceViewL()
       
  1377 	{
       
  1378 	_LIT(KTestServerShutdownWithStateNotificationAndInstanceView, "Testing making Instance view operations after shutdown notification");
       
  1379 	test.Next(KTestServerShutdownWithStateNotificationAndInstanceView);
       
  1380 
       
  1381 	_LIT8(KInstanceView, "Instance View test2");
       
  1382 	iTestCase = ETestServerShutdownWithSystemStateNotificationInstance;
       
  1383 	// Create a session to the agenda server
       
  1384 	CreateSessionL();
       
  1385 	CreateEntryViewL(KServerShutdownCalFile, ETrue);
       
  1386 	CreateInstanceViewL(ETrue);
       
  1387 	CreateRecurringEntriesL(KInstanceView);
       
  1388 	// Logon to the agenda server process in order to be notified when the process exits / dies
       
  1389 	ProcessLogonL();
       
  1390 	SubscribeToSystemNotification();
       
  1391 	SendSystemStateNotification(ESystemStateShutdown);
       
  1392 	TestInstanceViewOperationsL();
       
  1393 	CloseInstanceView();
       
  1394 	CloseEntryView();
       
  1395 	CloseSession(ETrue);
       
  1396 	}
       
  1397 
       
  1398 void CServerShutdownTestManager::SubscribeToSystemNotification()
       
  1399 	{
       
  1400 	TInt err = iSystemStateNotification.Attach(iMyUid, itcal_key);
       
  1401 	iSystemStateNotification.Subscribe(iStatus);
       
  1402 	}
       
  1403 
       
  1404 void CServerShutdownTestManager::CreateSystemStateNotificationProperty()
       
  1405 	{
       
  1406 	itcal_key = 111;
       
  1407 	TUid myUid = {0xE6AEDA09};
       
  1408 	iMyUid = myUid;
       
  1409 	iSystemStateNotification.Define(iMyUid, itcal_key, RProperty::EInt);
       
  1410 	}
       
  1411 
       
  1412 void CServerShutdownTestManager::SendSystemStateNotification(TSystemStateNotifications aSystemStateNotification)
       
  1413 	{
       
  1414 	iSystemStateNotification.Set(iMyUid, itcal_key, aSystemStateNotification);
       
  1415 	}
       
  1416 
       
  1417 void CServerShutdownTestManager::TestSystemAckNotification()
       
  1418 	{
       
  1419 	TInt value;
       
  1420 	iSystemStateNotification.Get(value);
       
  1421 	test(value == ESystemStateAck);
       
  1422 	}
       
  1423 void CServerShutdownTestManager::TestPostShutdownOperationsL(const TDesC8& aGuid, TInt aErr, TInt aAlarmCount)
       
  1424 	{
       
  1425 	_LIT(KLocation, "London");
       
  1426 
       
  1427 	RPointerArray<CCalEntry> entryList;
       
  1428 	CleanupResetAndDestroyPushL(entryList);
       
  1429 	TRAPD(errFetch, iEntryView->FetchL(aGuid, entryList));
       
  1430 //	test (errFetch == KErrNone);
       
  1431 	CCalEntry* entry = entryList[0];
       
  1432 	entry->SetLocationL(KLocation());
       
  1433 	
       
  1434 	//Check that a single alarm has been queued.
       
  1435 	test (iAlarmServer.AlarmCountByState(EAlarmStateQueued) == aAlarmCount);
       
  1436 	TInt numEntries = 0;
       
  1437 	TRAPD(errUpdate, iEntryView->UpdateL(entryList, numEntries));
       
  1438 	test (errUpdate == aErr);
       
  1439 	TRAPD(errDelete, iEntryView->DeleteL(*entry));
       
  1440 	test (errDelete == aErr);
       
  1441 	
       
  1442 	CleanupStack::PopAndDestroy(&entryList);
       
  1443 	}
       
  1444 
       
  1445 void CServerShutdownTestManager::TestAsycnDeleteOperationL()
       
  1446 	{
       
  1447 	TCalTime minTime;
       
  1448 	minTime.SetTimeUtcL(TCalTime::MinTime());
       
  1449 	TCalTime maxTime;
       
  1450 	maxTime.SetTimeUtcL(TCalTime::MaxTime());
       
  1451 	CalCommon::TCalTimeRange timeRange(minTime, maxTime);
       
  1452 	CalCommon::TCalViewFilter filter = CalCommon::EIncludeAll;
       
  1453 	TRAPD(err, iEntryView->DeleteL(timeRange, filter, *this));
       
  1454 	test (err == KErrNone);
       
  1455 	
       
  1456 	CActiveScheduler::Start();
       
  1457 	}
       
  1458 
       
  1459 void CServerShutdownTestManager::ClearAllAlarmsL()
       
  1460 	{
       
  1461 	// Delete all alarms
       
  1462 	RArray<TAlarmCategory> categories;
       
  1463 	
       
  1464 	iAlarmServer.GetAvailableCategoryListL(categories);
       
  1465 	
       
  1466 	const TInt KCount = categories.Count();
       
  1467 	for(TInt i = 0; i < KCount; ++i)
       
  1468 		{
       
  1469 		const TAlarmCategory KCategory = categories[i];
       
  1470 		test(iAlarmServer.AlarmDeleteAllByCategory(KCategory, EFalse) == KErrNone);
       
  1471 		}
       
  1472 		
       
  1473 	categories.Close();
       
  1474 
       
  1475 	// Restore alarm sound
       
  1476 	iAlarmServer.SetAlarmSoundState(EAlarmGlobalSoundStateOn);
       
  1477 	}
       
  1478 #endif
       
  1479 
       
  1480 // Run all the test cases
       
  1481 static void DoTestsL()
       
  1482 	{
       
  1483 	CServerShutdownTestManager* testManager = CServerShutdownTestManager::NewLC(CActive::EPriorityIdle);
       
  1484 
       
  1485 	// Run all the test cases the delay added to the calendar file before it is closed
       
  1486 	testManager->RunAllTestsL();
       
  1487 	
       
  1488 	CleanupStack::PopAndDestroy(testManager);
       
  1489 	}
       
  1490 
       
  1491 /**
       
  1492 
       
  1493 @SYMTestCaseID     PIM-TCAL-SERVERSHUTDOWN-0001
       
  1494 
       
  1495 */
       
  1496 
       
  1497 TInt E32Main()
       
  1498 	{
       
  1499 	__UHEAP_MARK;
       
  1500 
       
  1501 	_LIT(KTCalServerShutdownStart, "@SYMTESTCaseID:PIM-TCAL-SERVERSHUTDOWN-0001 Agenda Server Shutdown Test");
       
  1502 	test.Start(KTCalServerShutdownStart);
       
  1503 
       
  1504 	
       
  1505 	test.Title();
       
  1506 
       
  1507 	CTrapCleanup* trapCleanup = CTrapCleanup::New();
       
  1508 	CActiveScheduler* scheduler = new CActiveScheduler;
       
  1509 	CActiveScheduler::Install(scheduler);	
       
  1510 
       
  1511 	TRAPD(ret, DoTestsL());
       
  1512 
       
  1513 	_LIT(KTestResult, "Test steps returned with - %d");
       
  1514 	test.Printf(KTestResult, ret);
       
  1515 	
       
  1516 	test(ret == KErrNone);
       
  1517 
       
  1518 	delete scheduler;
       
  1519 	delete trapCleanup;	
       
  1520 
       
  1521 	_LIT(KTCalServerShutdownEnd, "Done\n");
       
  1522 	test.Printf(KTCalServerShutdownEnd);
       
  1523 
       
  1524 	test.End();
       
  1525 	test.Close();
       
  1526 
       
  1527 	__UHEAP_MARKEND;
       
  1528 
       
  1529 	return (KErrNone);
       
  1530 	}
       
  1531 
       
  1532