void CTzUserDataTest::TestDaylightSavingStateL(CTzId& aTzId, const RArray<TTime>& times, TBool aIsOn, RTz& aRTz)
	{
	aRTz.SetTimeZoneL(aTzId);
	TInt count = times.Count();
	for(TInt ii=0; ii<count; ++ii)
		{
		test (aIsOn == aRTz.IsDaylightSavingOnL(aTzId, times[ii]));
		}
	}
/** Setting of Time Zone using different Time Zone Servers
*/	
void CTestTZServer::MulitpleTZServerL()
	{
	_LIT8(KEuropeLondon, "Europe/London");
	CTzId* zoneId = CTzId::NewL(KEuropeLondon);
	CleanupStack::PushL(zoneId);
		
	_LIT8(KPacificPortMoresby, "Pacific/Port_Moresby");
	CTzId* zoneId1 = CTzId::NewL(KPacificPortMoresby);
	CleanupStack::PushL(zoneId1);
	
	_LIT8(KAfricaDar, "Africa/Dar_es_Salaam");
	CTzId* zoneId2 = CTzId::NewL(KAfricaDar);
	CleanupStack::PushL(zoneId2);
	
	RTz tz;
	CleanupClosePushL(tz);
	User::LeaveIfError(tz.Connect());
	
	RTz tz1;
	CleanupClosePushL(tz1);
	User::LeaveIfError(tz1.Connect());
	
	RTz tz2;
	CleanupClosePushL(tz2);
	User::LeaveIfError(tz2.Connect());
	
	CTzId* tzId = NULL;
	
	TRAPD(err,tz.SetTimeZoneL(*zoneId));
	TESTL(err == KErrNone);
	
	TRAP(err,tz1.SetTimeZoneL(*zoneId1));
	TESTL(err == KErrNone);
	
	TRAP(err,tz2.SetTimeZoneL(*zoneId2));
	TESTL(err == KErrNone);
	
	TRAP(err,tzId = tz.GetTimeZoneIdL());
	TESTL(err == KErrNone);
	TESTL(tzId != NULL);
	
	TRAP(err,tzId = tz1.GetTimeZoneIdL());
	TESTL(err == KErrNone);
	TESTL(tzId != NULL);
	
	TRAP(err,tzId = tz2.GetTimeZoneIdL());
	TESTL(err == KErrNone);
	TESTL(tzId != NULL);
	
	CleanupStack::PopAndDestroy(&tz2);
	CleanupStack::PopAndDestroy(&tz1);
	CleanupStack::PopAndDestroy(&tz);
	CleanupStack::PopAndDestroy(zoneId2);
	CleanupStack::PopAndDestroy(zoneId1);
	CleanupStack::PopAndDestroy(zoneId);
	}
TInt CDstIntUtils::SetHomeTimeZoneL(const TDesC8& aLocation, const RTz &aServer)
	{
	CTzId *timezoneid = CTzId::NewL(aLocation);
	CleanupStack::PushL(timezoneid);
	TInt err;
	TRAP(err, aServer.SetTimeZoneL(*timezoneid));
	CleanupStack::PopAndDestroy(timezoneid);

	return err;
	}
LOCAL_D void ResetTimeZoneToLondonL()
	{
	RTz tz;
	User::LeaveIfError(tz.Connect());
	CleanupClosePushL(tz);
	
	CTzId* id = CTzId::NewL(KTzLondon);
	CleanupStack::PushL(id);
	tz.SetTimeZoneL(*id);
	CleanupStack::PopAndDestroy(2, &tz);
	}
void CTzUserDataTest::CreateUserTzAndSetCurrentTimeToL(RTz& aTz, TInt aStandardOffSet, TInt aDSTOffset)
	{
	test.Next(_L("@SYMTestCaseID PIM-APPSERV-TZS-RC-0001 Test user-defined time zone is current time zone"));
	CTzId* usertzid = CreateUserDefinedTzL(aStandardOffSet, aDSTOffset, ETrue);
	CleanupStack::PushL(usertzid);
	aTz.SetTimeZoneL(*usertzid);
	CTzId* tzGot = aTz.GetTimeZoneIdL();
	test (*tzGot == *usertzid);
	delete tzGot;
	CleanupStack::PopAndDestroy(usertzid);
	}
void CTzUserDataTest::TestUtcOffsetL(CTzId& aTzId, const CTzRules& rules, const RArray<TTime>& times, TInt aOffset, RTz& aRTz )
	{
	aRTz.SetTimeZoneL(aTzId);

	TInt count = times.Count();
	
	for(TInt ii=0; ii<count; ++ii)
		{
		test (aOffset == rules.GetOffsetL(times[ii], ETzUtcTimeReference));	
		TTime utc = times[ii];
		aRTz.ConvertToUniversalTime(utc);
		TTimeIntervalMinutes minutes;
		times[ii].MinutesFrom(utc, minutes);
		test (minutes == TTimeIntervalMinutes(aOffset));	
		}
	}
/** Soak/OOM tests for setting and getting time zones and testing of TimeZoneNameID api
*/
void CTestTZServer::OOMSetCurrentTimeZoneL()
	{
	_LIT8(KEuropeLondon, "Europe/London");
	CTzId* zoneId = CTzId::NewL(KEuropeLondon);
	
	CleanupStack::PushL(zoneId);
	
	_LIT8(KPacificPortMoresby, "Pacific/Port_Moresby");
	CTzId* zoneId1 = CTzId::NewL(KPacificPortMoresby);
	
	CleanupStack::PushL(zoneId1);
	
	RTz tz;
	CleanupClosePushL(tz);
	User::LeaveIfError(tz.Connect());

	TInt i = 0;

	for (i = 0; i < KRepeatApiNumber; i++)
		{
		TRAPD(err,tz.SetTimeZoneL(*zoneId));	
		TESTL(err == KErrNone);
		}
		
	
	for (i = 0; i < KRepeatApiNumber; i++)
		{
		TRAPD(err,tz.SetTimeZoneL(*zoneId1));	
		TESTL(err == KErrNone);
		}
	
	CTzId* tzId = NULL;
	
	iFailAt = 1;
	for ( ;; )
		{
		StartHeapCheck(iFailAt);
		TRAPD(err5,tzId = tz.GetTimeZoneIdL());
		
		if ( err5 == KErrNone )
			{
			TESTL(tzId != NULL);
			__UHEAP_RESET;
			INFO_PRINTF1(_L("OOM testing of GetTimeZoneIdL()) Api is done"));
			break;
			}
				
		if ( ErrorProcess( err5) )
			{
			EndHeapCheck();
			}
		else
			{
			break;
			}	
		}	

	CleanupStack::PopAndDestroy(&tz);
	CleanupStack::PopAndDestroy(zoneId1);
	CleanupStack::PopAndDestroy(zoneId);
	}
/*
@file
@SYMTestCaseID				SYSLIB-SCHSVR-CIT-0279
@SYMTestCaseDesc 			Persistant schedule - UTC & Hometime
@SYMTestPriority 			High
@SYMTestActions  			For time and condition based test schedule task and check it fires
@SYMTestExpectedResults		The test must not fail.
@SYMPREQ					PREQ234
*/
TVerdict Cpersist_mixedStep::doTestStepL()
/**
 * @return - TVerdict code
 * Override of base class pure virtual
 * Our implementation only gets called if the base class doTestStepPreambleL() did
 * not leave. That being the case, the current test result value will be EPass.
 */
	{
	SetTestStepResult(EFail);
	
	_LIT(KTestName1, "Persistant Mixed - Hometime");
	_LIT(KTaskData1, "This is some really exciting task data (number 1)");
	_LIT(KTestName2, "Persistant Mixed - UTC");
	_LIT(KTaskData2, "This is some really exciting task data (number 2)");
	
	// Tests with timezone set to Europe, London
	RTz tz;
	tz.Connect();
	CTzId* tzId = CTzId::NewL(2592); //set the timezone to Europe/London
	CleanupStack::PushL(tzId);
	tz.SetTimeZoneL(*tzId);
	
	// Set the time to a known value, since this makes testing much easier (and more
	// repeatable).
	SchSvrHelpers::SetUTCTimeL(TTime(TDateTime(2000, EJanuary, 1, 9, 55, 0, 0))); // 9:55 am

	// Prepare schedules describing when we want the tasks to run (10:00 am & 10.00)
	
	// Creates a hometime based daily persistant schedule	
	TSchedulerItemRef ref1;

	// This is the time when we want the Hometime time-based schedule to fire
	TDateTime datetime1(2000, EJanuary, 1, 11, 0, 0, 0);
	TTsTime startTimeForSchedule1(datetime1, EFalse); // 11:00 am
	
	{
	CScheduleEntryInfoArray* entryList = new (ELeave) CScheduleEntryInfoArray(1);
	CleanupStack::PushL(entryList);
	TScheduleEntryInfo2 entry1 (startTimeForSchedule1, EDaily, 1, 30);
	entryList->AppendL(entry1);

	TInt res = TheScheduler.CreatePersistentSchedule(ref1, *entryList);
	TESTL(res==KErrNone);
	CleanupStack::PopAndDestroy(); // entryList
	}
	
	// Disable the schedule whilst we set it up
	User::LeaveIfError(TheScheduler.DisableSchedule(ref1.iHandle));
	
	
	// Creates a UTC based daily persistant schedule	
	TSchedulerItemRef ref2;

	// This is the time when we want the UTC time-based schedule to fire
	TDateTime datetime2(2000, EJanuary, 1, 10, 0, 0, 0);
	TTsTime startTimeForSchedule2(datetime2, ETrue); // 10:00 am
	
	{
	CScheduleEntryInfoArray* entryList = new (ELeave) CScheduleEntryInfoArray(1);
	CleanupStack::PushL(entryList);
	TScheduleEntryInfo2 entry1 (startTimeForSchedule2, EDaily, 1, 30);
	entryList->AppendL(entry1);

	TInt res = TheScheduler.CreatePersistentSchedule(ref2, *entryList);
	TESTL(res==KErrNone);
	CleanupStack::PopAndDestroy(); // entryList
	}
	
	// Disable the schedule whilst we set it up
	User::LeaveIfError(TheScheduler.DisableSchedule(ref2.iHandle));
	
	// Kill the server to check if persisted schedules have been stored
	// Need to turn off JIT dubugging as we are panicking server and we 
	// want test to keep running.
	TBool jit = User::JustInTime();
	User::SetJustInTime(EFalse);

	TheScheduler.__FaultServer();
	
	// Change UTC Offset whilst server is down	
	// Set UTC offset to +1Hr by moving to Europe, Paris
	tzId = CTzId::NewL(2656); //set the timezone to Europe/Paris
	tz.SetTimeZoneL(*tzId);
	
	User::After(1000000);
	
	// Turn on JIT again.
	User::SetJustInTime(jit);
	
	// Connect to the server again
	TInt res = TheScheduler.Connect();
	TESTL(res==KErrNone);

	// Re-register
	TESTL(SchSvrHelpers::RegisterClientL(TheScheduler)==KErrNone);


	// Associate a task with the time-based schedule
	TTaskInfo taskInfo1;
	taskInfo1.iName = KTestName1;
	taskInfo1.iPriority = 2;
	taskInfo1.iRepeat = 0;
	// Create some data associated with this task	
	HBufC* taskData1 = KTaskData1().AllocLC();
	User::LeaveIfError(TheScheduler.ScheduleTask(taskInfo1, *taskData1, ref1.iHandle));
	CleanupStack::PopAndDestroy();	// taskData1
		
	// Associate a task with the condition-based schedule
	TTaskInfo taskInfo2;
	taskInfo2.iName = KTestName2;
	taskInfo2.iPriority = 2;
	taskInfo2.iRepeat = 0;
	// Create some data associated with this task
	HBufC* taskData2 = KTaskData2().AllocLC();
	User::LeaveIfError(TheScheduler.ScheduleTask(taskInfo2, *taskData2, ref2.iHandle));
	CleanupStack::PopAndDestroy(); // taskData2

	// Set the UTC time such that both schedules fire at the same time
	SchSvrHelpers::SetUTCTimeL(TTime(TDateTime(2000, EJanuary, 1, 9, 59, 50, 0))); // 9:59.50 am

	User::LeaveIfError(TheScheduler.EnableSchedule(ref1.iHandle));
	User::LeaveIfError(TheScheduler.EnableSchedule(ref2.iHandle));
	
	// Now wait for the time-based schedule to fire
	TESTL(STaskSemaphore::WaitL(KDefaultTimeout) == KErrNone); 
	// Now wait for the condition-based schedule to fire
	TESTL(STaskSemaphore::WaitL(KDefaultTimeout) == KErrNone); 
	
	TTime timeNow;
	timeNow.HomeTime();
	TESTL(SchSvrHelpers::IsTimeTheSameNoSeconds(TTsTime(timeNow, EFalse), startTimeForSchedule1));

	timeNow.UniversalTime();
	TESTL(SchSvrHelpers::IsTimeTheSameNoSeconds(TTsTime(timeNow, ETrue), startTimeForSchedule2));
	
	CleanupStack::PopAndDestroy(); // timezone ID
	CleanupHelpers::KillProcess(KMinimalTaskHandler);
	SetTestStepResult(EPass);	
	return TestStepResult();
	}