sl@0: // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0: // All rights reserved.
sl@0: // This component and the accompanying materials are made available
sl@0: // under the terms of "Eclipse Public License v1.0"
sl@0: // which accompanies this distribution, and is available
sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0: //
sl@0: // Initial Contributors:
sl@0: // Nokia Corporation - initial contribution.
sl@0: //
sl@0: // Contributors:
sl@0: //
sl@0: // Description:
sl@0: //
sl@0: 
sl@0: #ifndef __THELPERS_H__
sl@0: #define __THELPERS_H__
sl@0: 
sl@0: // User includes
sl@0: #include <e32test.h>
sl@0: #include <schinfo.h>
sl@0: #include <schinfointernal.h>
sl@0: #include <csch_cli.h>
sl@0: 
sl@0: class RFs;
sl@0: 
sl@0: // Numerical constants
sl@0: const TInt KPausePeriod						= 1; // 1 second
sl@0: const TInt KOneSecond = 1000000;
sl@0: const TInt KDefaultTimeout = KOneSecond * 120; // 2 Minutes
sl@0: 
sl@0: class SchSvrHelpers
sl@0: 	{
sl@0: 
sl@0: public:							// STATIC COMPARISON FUNCTIONS
sl@0: 	IMPORT_C static TBool	IsTimeTheSame(const TTime& aTime1, const TTime& aTime2);
sl@0: 	IMPORT_C static TBool	IsDateTheSame(const TTime& aTime1, const TTime& aTime2);
sl@0: 	IMPORT_C static TBool	IsTaskInfoTheSame(const TTaskInfo& aTaskInfo1, const TTaskInfo& aTaskInfo2);
sl@0: 	IMPORT_C static TBool	IsItemRefTheSame(const TSchedulerItemRef& aItemRef1, const TSchedulerItemRef& aItemRef2);
sl@0: 	IMPORT_C static TBool	IsScheduleStateTheSame(const TScheduleState& aScheduleState1, const TScheduleState& aScheduleState2);
sl@0: 
sl@0: 
sl@0: public:							// STATIC OBJECT CREATION FUNCTIONS
sl@0: 	IMPORT_C static TScheduleEntryInfo		RandomScheduleEntryInfo(TInt64& aSeed);
sl@0: 	IMPORT_C static TScheduleEntryInfo		ScheduleEntryInfo(TIntervalType aType, const TTime& aStartTime, TInt aInterval, TTimeIntervalMinutes aValidPeriod = 0);
sl@0: 	IMPORT_C static TTaskInfo				TaskInfo(const TDesC& aName, TInt aPriority, TInt aRepeat = 1);
sl@0: 
sl@0: 
sl@0: public:							// STATIC COMPARISON FUNCTIONS - PREQ234 SUPPORT
sl@0: 	IMPORT_C static TBool	IsTimeTheSame(const TTsTime& aTime1, const TTsTime& aTime2);
sl@0: 	IMPORT_C static TBool	IsDateTheSame(const TTsTime& aTime1, const TTsTime& aTime2);
sl@0: 	IMPORT_C static TBool	IsTimeTheSameNoSeconds(const TTsTime& aTime1, const TTsTime& aTime2);
sl@0: 	IMPORT_C static TBool	IsScheduleStateTheSame(const TScheduleState2& aScheduleState1, const TScheduleState2& aScheduleState2);
sl@0: 	
sl@0: public:							// STATIC OBJECT CREATION FUNCTIONS - PREQ234 SUPPORT
sl@0: 	IMPORT_C static TScheduleEntryInfo2		RandomScheduleEntryInfoHometime(TInt64& aSeed);
sl@0: 	IMPORT_C static TScheduleEntryInfo2		RandomScheduleEntryInfoUtc(TInt64& aSeed);
sl@0: 	IMPORT_C static TScheduleEntryInfo2		ScheduleEntryInfo(TIntervalType aType, const TTsTime& aStartTime, TInt aInterval, TTimeIntervalMinutes aValidPeriod = 0);
sl@0: 
sl@0: public:							// STATIC PRINTING FUNCTIONS - PREQ234 SUPPORT
sl@0: 	IMPORT_C static void	Pause(TInt aPauseAmount = KPausePeriod);
sl@0: 
sl@0: public:							// STATIC NEW TIME HANDLING FUNCTIONS - DEF061625 
sl@0: 	IMPORT_C static TInt SetHomeTimeL(const TTime& aLocalTime);
sl@0: 	IMPORT_C static TInt SetUTCTimeL(const TTime& aUTCTime);
sl@0: 	
sl@0: public:							// STATIC PRINTING FUNCTIONS
sl@0: 	IMPORT_C static TInt	Rand(const TInt aLow, const TInt aHigh, TInt64& aSeed);
sl@0: 	IMPORT_C static void	Pause(RTest& aTest, TInt aPauseAmount = KPausePeriod);
sl@0: 
sl@0: 
sl@0: public:							// SCHEDULE DELETION FUNCTIONS
sl@0: 	IMPORT_C static void DeleteScheduleFilesL();
sl@0: 	IMPORT_C static void DeleteAllSchedulesL(RScheduler& aScheduler);
sl@0: 
sl@0: 
sl@0: public:							// client registration
sl@0: 	IMPORT_C static TInt RegisterClientL(RScheduler& aScheduler);	
sl@0: 	IMPORT_C static TInt RegisterPanicingClient(RScheduler& aScheduler);
sl@0: 	IMPORT_C static TInt RegisterNonExistentClient(RScheduler& aScheduler);
sl@0: 	
sl@0: 
sl@0: public:							// MISC FUNCTIONS
sl@0: 	IMPORT_C static TDateTime	TimeBasedOnOffset(TInt aSeconds, 
sl@0: 												TInt aMinutes = 0, 
sl@0: 												TInt aHours = 0, 
sl@0: 												TInt aDays = 0, 
sl@0: 												TInt aMonths = 0, 
sl@0: 												TInt aYears = 0);	
sl@0: 	IMPORT_C static TDateTime	UtcTimeBasedOnOffset(TInt aSeconds, 
sl@0: 												TInt aMinutes = 0, 
sl@0: 												TInt aHours = 0, 
sl@0: 												TInt aDays = 0, 
sl@0: 												TInt aMonths = 0, 
sl@0: 												TInt aYears = 0);	
sl@0: 	IMPORT_C static TInt CheckTaskFilesL();
sl@0: 	IMPORT_C static TInt CreateTaskFilesL();
sl@0: 	
sl@0: 	IMPORT_C static  TInt LaunchTaskSchedulerL();
sl@0: 	};
sl@0: 	
sl@0: 
sl@0: class CleanupHelpers
sl@0: 	{
sl@0: 	public:
sl@0: 	//This function is used in the test code to kill SCHSVR or MinimalTaskHandler
sl@0: 	//processes (or some other) when they leftover and may cause OOM condinitons.
sl@0: 	IMPORT_C static TInt KillProcess(const TDesC& aProcessName);
sl@0: 	
sl@0: 	//Call this method before "TheTest(error == KErrNone);" statement.
sl@0: 	//Otherwise if the error code is not KErrNone and the check fails, your 
sl@0: 	//cleanup code never gets called - probably you will have low memory condition on the 
sl@0: 	//test hardware and the rest of SCHSVR unit tests will fail sometimes and it will be very 
sl@0: 	//hard to find out what is going on there.
sl@0: 	IMPORT_C static void TestCleanupL();
sl@0: 	};	
sl@0: 												
sl@0: 
sl@0: // Used for signaling between launched exe and test to check that the exe is launched.
sl@0: class STaskSemaphore
sl@0: 	{
sl@0: public:
sl@0: 	IMPORT_C void CreateL();
sl@0: 	IMPORT_C static void WaitL();
sl@0: 	IMPORT_C static TInt WaitL(TInt aTimeout);
sl@0: 	IMPORT_C void Close();
sl@0: private:
sl@0: 	RSemaphore iSemaphore;	
sl@0: 	};
sl@0: 
sl@0: #endif
sl@0: