genericservices/taskscheduler/Test/TSUtils/Thelpers.h
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     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 #ifndef __THELPERS_H__
       
    17 #define __THELPERS_H__
       
    18 
       
    19 // User includes
       
    20 #include <e32test.h>
       
    21 #include <schinfo.h>
       
    22 #include <schinfointernal.h>
       
    23 #include <csch_cli.h>
       
    24 
       
    25 class RFs;
       
    26 
       
    27 // Numerical constants
       
    28 const TInt KPausePeriod						= 1; // 1 second
       
    29 const TInt KOneSecond = 1000000;
       
    30 const TInt KDefaultTimeout = KOneSecond * 120; // 2 Minutes
       
    31 
       
    32 class SchSvrHelpers
       
    33 	{
       
    34 
       
    35 public:							// STATIC COMPARISON FUNCTIONS
       
    36 	IMPORT_C static TBool	IsTimeTheSame(const TTime& aTime1, const TTime& aTime2);
       
    37 	IMPORT_C static TBool	IsDateTheSame(const TTime& aTime1, const TTime& aTime2);
       
    38 	IMPORT_C static TBool	IsTaskInfoTheSame(const TTaskInfo& aTaskInfo1, const TTaskInfo& aTaskInfo2);
       
    39 	IMPORT_C static TBool	IsItemRefTheSame(const TSchedulerItemRef& aItemRef1, const TSchedulerItemRef& aItemRef2);
       
    40 	IMPORT_C static TBool	IsScheduleStateTheSame(const TScheduleState& aScheduleState1, const TScheduleState& aScheduleState2);
       
    41 
       
    42 
       
    43 public:							// STATIC OBJECT CREATION FUNCTIONS
       
    44 	IMPORT_C static TScheduleEntryInfo		RandomScheduleEntryInfo(TInt64& aSeed);
       
    45 	IMPORT_C static TScheduleEntryInfo		ScheduleEntryInfo(TIntervalType aType, const TTime& aStartTime, TInt aInterval, TTimeIntervalMinutes aValidPeriod = 0);
       
    46 	IMPORT_C static TTaskInfo				TaskInfo(const TDesC& aName, TInt aPriority, TInt aRepeat = 1);
       
    47 
       
    48 
       
    49 public:							// STATIC COMPARISON FUNCTIONS - PREQ234 SUPPORT
       
    50 	IMPORT_C static TBool	IsTimeTheSame(const TTsTime& aTime1, const TTsTime& aTime2);
       
    51 	IMPORT_C static TBool	IsDateTheSame(const TTsTime& aTime1, const TTsTime& aTime2);
       
    52 	IMPORT_C static TBool	IsTimeTheSameNoSeconds(const TTsTime& aTime1, const TTsTime& aTime2);
       
    53 	IMPORT_C static TBool	IsScheduleStateTheSame(const TScheduleState2& aScheduleState1, const TScheduleState2& aScheduleState2);
       
    54 	
       
    55 public:							// STATIC OBJECT CREATION FUNCTIONS - PREQ234 SUPPORT
       
    56 	IMPORT_C static TScheduleEntryInfo2		RandomScheduleEntryInfoHometime(TInt64& aSeed);
       
    57 	IMPORT_C static TScheduleEntryInfo2		RandomScheduleEntryInfoUtc(TInt64& aSeed);
       
    58 	IMPORT_C static TScheduleEntryInfo2		ScheduleEntryInfo(TIntervalType aType, const TTsTime& aStartTime, TInt aInterval, TTimeIntervalMinutes aValidPeriod = 0);
       
    59 
       
    60 public:							// STATIC PRINTING FUNCTIONS - PREQ234 SUPPORT
       
    61 	IMPORT_C static void	Pause(TInt aPauseAmount = KPausePeriod);
       
    62 
       
    63 public:							// STATIC NEW TIME HANDLING FUNCTIONS - DEF061625 
       
    64 	IMPORT_C static TInt SetHomeTimeL(const TTime& aLocalTime);
       
    65 	IMPORT_C static TInt SetUTCTimeL(const TTime& aUTCTime);
       
    66 	
       
    67 public:							// STATIC PRINTING FUNCTIONS
       
    68 	IMPORT_C static TInt	Rand(const TInt aLow, const TInt aHigh, TInt64& aSeed);
       
    69 	IMPORT_C static void	Pause(RTest& aTest, TInt aPauseAmount = KPausePeriod);
       
    70 
       
    71 
       
    72 public:							// SCHEDULE DELETION FUNCTIONS
       
    73 	IMPORT_C static void DeleteScheduleFilesL();
       
    74 	IMPORT_C static void DeleteAllSchedulesL(RScheduler& aScheduler);
       
    75 
       
    76 
       
    77 public:							// client registration
       
    78 	IMPORT_C static TInt RegisterClientL(RScheduler& aScheduler);	
       
    79 	IMPORT_C static TInt RegisterPanicingClient(RScheduler& aScheduler);
       
    80 	IMPORT_C static TInt RegisterNonExistentClient(RScheduler& aScheduler);
       
    81 	
       
    82 
       
    83 public:							// MISC FUNCTIONS
       
    84 	IMPORT_C static TDateTime	TimeBasedOnOffset(TInt aSeconds, 
       
    85 												TInt aMinutes = 0, 
       
    86 												TInt aHours = 0, 
       
    87 												TInt aDays = 0, 
       
    88 												TInt aMonths = 0, 
       
    89 												TInt aYears = 0);	
       
    90 	IMPORT_C static TDateTime	UtcTimeBasedOnOffset(TInt aSeconds, 
       
    91 												TInt aMinutes = 0, 
       
    92 												TInt aHours = 0, 
       
    93 												TInt aDays = 0, 
       
    94 												TInt aMonths = 0, 
       
    95 												TInt aYears = 0);	
       
    96 	IMPORT_C static TInt CheckTaskFilesL();
       
    97 	IMPORT_C static TInt CreateTaskFilesL();
       
    98 	
       
    99 	IMPORT_C static  TInt LaunchTaskSchedulerL();
       
   100 	};
       
   101 	
       
   102 
       
   103 class CleanupHelpers
       
   104 	{
       
   105 	public:
       
   106 	//This function is used in the test code to kill SCHSVR or MinimalTaskHandler
       
   107 	//processes (or some other) when they leftover and may cause OOM condinitons.
       
   108 	IMPORT_C static TInt KillProcess(const TDesC& aProcessName);
       
   109 	
       
   110 	//Call this method before "TheTest(error == KErrNone);" statement.
       
   111 	//Otherwise if the error code is not KErrNone and the check fails, your 
       
   112 	//cleanup code never gets called - probably you will have low memory condition on the 
       
   113 	//test hardware and the rest of SCHSVR unit tests will fail sometimes and it will be very 
       
   114 	//hard to find out what is going on there.
       
   115 	IMPORT_C static void TestCleanupL();
       
   116 	};	
       
   117 												
       
   118 
       
   119 // Used for signaling between launched exe and test to check that the exe is launched.
       
   120 class STaskSemaphore
       
   121 	{
       
   122 public:
       
   123 	IMPORT_C void CreateL();
       
   124 	IMPORT_C static void WaitL();
       
   125 	IMPORT_C static TInt WaitL(TInt aTimeout);
       
   126 	IMPORT_C void Close();
       
   127 private:
       
   128 	RSemaphore iSemaphore;	
       
   129 	};
       
   130 
       
   131 #endif
       
   132