os/ossrv/genericservices/taskscheduler/Test/Scheduling/TC_TSCH_SCHEDULING1.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
#include <e32base.h>
sl@0
    17
#include <e32test.h>
sl@0
    18
#include <csch_cli.h>
sl@0
    19
#include <f32file.h>
sl@0
    20
#include "Thelpers.h"
sl@0
    21
sl@0
    22
#include "TestUtils.h"
sl@0
    23
sl@0
    24
// Globals
sl@0
    25
RTest					TheTest(_L("TC_TSCH_SCHEDULING1"));
sl@0
    26
static RScheduler		TheScheduler;
sl@0
    27
static RFs				TheFsSession;
sl@0
    28
sl@0
    29
typedef CArrayFixFlat<TScheduleEntryInfo>	CScheduleEntryInfoArray;
sl@0
    30
typedef CArrayFixFlat<TTaskInfo>			CTaskInfoArray;
sl@0
    31
typedef CArrayFixFlat<TSchedulerItemRef>    CSchItemRefArray;
sl@0
    32
sl@0
    33
_LIT(KMinimalTaskHandler, "MinimalTaskHandler");
sl@0
    34
sl@0
    35
_LIT(KTimeFormatString,						"%-B%:0%J%:1%T%:2%S%.%*C4%:3%+B");
sl@0
    36
_LIT(KCurrentDateTimeChanged,				"Date & Time changed to: [%S]\n");
sl@0
    37
sl@0
    38
const TInt KTimeToWait = 4*1000*1000;
sl@0
    39
sl@0
    40
sl@0
    41
//***********************************************************************************
sl@0
    42
sl@0
    43
// Sets time to before specified time by aTimeBeforeInSeconds
sl@0
    44
static void SetTimeBeforeL(RTest& aTest, TTime& aTime, TInt aTimeBeforeInSeconds)
sl@0
    45
	{
sl@0
    46
	TTimeIntervalSeconds secs(aTimeBeforeInSeconds);
sl@0
    47
	TTime time = aTime-secs;
sl@0
    48
	SchSvrHelpers::SetHomeTimeL(time);
sl@0
    49
	TBuf<30> dateString;
sl@0
    50
	time.FormatL(dateString, KTimeFormatString);
sl@0
    51
	aTest.Printf(KCurrentDateTimeChanged, &dateString);
sl@0
    52
	}
sl@0
    53
sl@0
    54
// gets the due time for this schedule
sl@0
    55
static TTime GetDueTimeL(TInt aScheduleId)
sl@0
    56
	{
sl@0
    57
	TTime nextTimeScheduleIsDue;
sl@0
    58
	TScheduleState state;
sl@0
    59
	CScheduleEntryInfoArray* entries 
sl@0
    60
		= new (ELeave) CScheduleEntryInfoArray(3);
sl@0
    61
	CleanupStack::PushL(entries);
sl@0
    62
	CTaskInfoArray* tasks = new (ELeave) CTaskInfoArray(3);
sl@0
    63
	CleanupStack::PushL(tasks);
sl@0
    64
sl@0
    65
	TInt res = TheScheduler.GetScheduleL(aScheduleId, state, *entries, *tasks, nextTimeScheduleIsDue);
sl@0
    66
	TEST2(res, KErrNone);
sl@0
    67
sl@0
    68
	CleanupStack::PopAndDestroy(2); // entries, tasks
sl@0
    69
	return state.iDueTime;
sl@0
    70
	}
sl@0
    71
	
sl@0
    72
// Forces the task to be exectued aCount times.
sl@0
    73
static void ForceTaskExecutionForSpecifiedIdL(TInt aId, TInt aCount)
sl@0
    74
	{
sl@0
    75
	TheTest.Printf(_L("Executing %d times\n"), aCount);
sl@0
    76
	TTime time;
sl@0
    77
	for (TInt i=0; i<aCount; ++i)
sl@0
    78
		{
sl@0
    79
		TheTest.Printf(_L("Execution %d\n"), i+1);
sl@0
    80
		time = GetDueTimeL(aId);	
sl@0
    81
		
sl@0
    82
		SetTimeBeforeL(TheTest, time, 5 /*seconds*/);		
sl@0
    83
		
sl@0
    84
		// Wait for notification that schedule has executed.
sl@0
    85
		TEST2(STaskSemaphore::WaitL(KDefaultTimeout), KErrNone);
sl@0
    86
		CleanupHelpers::KillProcess(KMinimalTaskHandler);
sl@0
    87
		}
sl@0
    88
	}
sl@0
    89
sl@0
    90
//creates a daily schedule with StartTime of aStartTime
sl@0
    91
static TInt CreateScheduleL(TSchedulerItemRef& aRef, 
sl@0
    92
							RScheduler& aScheduler, 
sl@0
    93
							const TTime& aStartTime)
sl@0
    94
	{
sl@0
    95
	CScheduleEntryInfoArray* entryList 
sl@0
    96
		= new (ELeave) CScheduleEntryInfoArray(1);
sl@0
    97
	CleanupStack::PushL(entryList);
sl@0
    98
sl@0
    99
	TScheduleEntryInfo entry1;
sl@0
   100
	entry1.iStartTime		= aStartTime;
sl@0
   101
	entry1.iInterval		= 1; // TTimeIntervalDays
sl@0
   102
	entry1.iIntervalType	= EDaily;
sl@0
   103
	entry1.iValidityPeriod	= 30; // minutes
sl@0
   104
	entryList->AppendL(entry1);
sl@0
   105
	TInt res = aScheduler.CreatePersistentSchedule(aRef, *entryList);
sl@0
   106
	CleanupStack::PopAndDestroy(); // entryList
sl@0
   107
	return res;
sl@0
   108
	}
sl@0
   109
sl@0
   110
// counts the number of scheduled items based on the supplied filter.
sl@0
   111
static TInt CountScheduledItemsL(TScheduleFilter aFilter, 
sl@0
   112
								RScheduler& aScheduler)
sl@0
   113
	// Extract schedule references from the schedule server based on a filter. If
sl@0
   114
	{
sl@0
   115
	CSchItemRefArray* refs = new (ELeave) CSchItemRefArray(3);
sl@0
   116
	CleanupStack::PushL(refs);
sl@0
   117
sl@0
   118
	TInt res = aScheduler.GetScheduleRefsL(*refs, aFilter);
sl@0
   119
	TEST2(res, KErrNone);
sl@0
   120
sl@0
   121
	TInt count = refs->Count();
sl@0
   122
	CleanupStack::PopAndDestroy(); // refs
sl@0
   123
	return count;
sl@0
   124
	}	
sl@0
   125
sl@0
   126
// Extract task references from the schedule server based on a ID
sl@0
   127
static void GetTaskInfoL(CTaskInfoArray& aTaskInfoArray,
sl@0
   128
						TInt aScheduleId)
sl@0
   129
	{
sl@0
   130
	aTaskInfoArray.Reset();
sl@0
   131
	TTime nextTimeScheduleIsDue;
sl@0
   132
	TScheduleState state;
sl@0
   133
	CScheduleEntryInfoArray* entries 
sl@0
   134
		= new (ELeave) CScheduleEntryInfoArray(3);
sl@0
   135
	CleanupStack::PushL(entries);
sl@0
   136
	TInt res = TheScheduler.GetScheduleL(aScheduleId, 
sl@0
   137
										state, 
sl@0
   138
										*entries, 
sl@0
   139
										aTaskInfoArray, 
sl@0
   140
										nextTimeScheduleIsDue);
sl@0
   141
	TEST2(res, KErrNone);
sl@0
   142
	CleanupStack::PopAndDestroy(entries);
sl@0
   143
	}
sl@0
   144
sl@0
   145
sl@0
   146
sl@0
   147
sl@0
   148
// schedules a transient task	
sl@0
   149
static TInt ScheduleTransientTaskL(TInt& aTaskId, 
sl@0
   150
								TSchedulerItemRef& aRef, 
sl@0
   151
								TInt aRepeat, 
sl@0
   152
								RScheduler& aScheduler)
sl@0
   153
	{
sl@0
   154
	CScheduleEntryInfoArray* entryList = new(ELeave) CScheduleEntryInfoArray(3);
sl@0
   155
	CleanupStack::PushL(entryList);
sl@0
   156
sl@0
   157
	aRef.iName = _L("transient one");
sl@0
   158
sl@0
   159
	// SCEHDULES
sl@0
   160
	TScheduleEntryInfo entry1;
sl@0
   161
	entry1.iStartTime = SchSvrHelpers::TimeBasedOnOffset(0, 1); // 1 min in the future
sl@0
   162
	entry1.iInterval = 1;
sl@0
   163
	entry1.iIntervalType = EDaily;
sl@0
   164
	entry1.iValidityPeriod = 20;
sl@0
   165
	entryList->AppendL(entry1);
sl@0
   166
	
sl@0
   167
	TScheduleEntryInfo entry2;
sl@0
   168
	entry2.iStartTime = SchSvrHelpers::TimeBasedOnOffset(0, 2); // 2 mins in the future
sl@0
   169
	entry2.iInterval = 1;
sl@0
   170
	entry2.iIntervalType = EDaily;
sl@0
   171
	entry2.iValidityPeriod = 500;
sl@0
   172
	entryList->AppendL(entry2);
sl@0
   173
sl@0
   174
	TScheduleEntryInfo entry3;
sl@0
   175
	entry3.iStartTime = SchSvrHelpers::TimeBasedOnOffset(0, 3); // 3 mins in the future
sl@0
   176
	entry3.iInterval = 1;
sl@0
   177
	entry3.iIntervalType = EDaily;
sl@0
   178
	entry3.iValidityPeriod = 5;
sl@0
   179
	entryList->AppendL(entry3);
sl@0
   180
sl@0
   181
	// TASK
sl@0
   182
	TTaskInfo taskInfo;
sl@0
   183
	taskInfo.iName = _L("mail");
sl@0
   184
	taskInfo.iTaskId = aTaskId;
sl@0
   185
	taskInfo.iRepeat = aRepeat;
sl@0
   186
	taskInfo.iPriority = 2;
sl@0
   187
	HBufC* data = _L("the data, some strange new name ").AllocLC();
sl@0
   188
sl@0
   189
	// Schedule the item
sl@0
   190
	TInt res = aScheduler.ScheduleTask(taskInfo, *data, aRef, *entryList);
sl@0
   191
	CleanupStack::PopAndDestroy(2); // data, entryList
sl@0
   192
sl@0
   193
	aTaskId = taskInfo.iTaskId;
sl@0
   194
	return res;
sl@0
   195
	}
sl@0
   196
sl@0
   197
/*
sl@0
   198
 * Add Persistent and long term schedules to SchedulessBackup.dat files. this function 
sl@0
   199
 * is part of the DEF108026 defect testing called by DEF108026() 		
sl@0
   200
 * It is part of the manual test SYSLIB-SCHSVR-CT-4003
sl@0
   201
 * should be commented and will run as manual test only.
sl@0
   202
 * 
sl@0
   203
 * 
sl@0
   204
  
sl@0
   205
 static void DEF108026_AddPersistentSchedulesL( TBool aImmediate )
sl@0
   206
	{	
sl@0
   207
	
sl@0
   208
	_LIT(KTaskData1, "This is some really exciting task data (number 1)");
sl@0
   209
	_LIT(KTaskData2, "This is some really exciting task data (number 2)");	
sl@0
   210
	_LIT(KTestName,	"Def108026_test");
sl@0
   211
sl@0
   212
	TheTest.Next(_L("Def108026_test: Adding schedules"));
sl@0
   213
	
sl@0
   214
	RDebug::Print(_L("DEF108026_AddPersistentSchedulesL"));
sl@0
   215
	
sl@0
   216
	TheTest.Next(_L("Connect to Scheduler"));
sl@0
   217
	TInt res = TheScheduler.Connect();
sl@0
   218
	TEST2(res, KErrNone);
sl@0
   219
sl@0
   220
	TheTest.Next(_L("Registering Client"));
sl@0
   221
	TEST2(SchSvrHelpers::RegisterClientL(TheScheduler), KErrNone);
sl@0
   222
sl@0
   223
	
sl@0
   224
sl@0
   225
	TTime startTimeForSchedule;
sl@0
   226
	if ( aImmediate )
sl@0
   227
		{
sl@0
   228
		// This is the time when we want the schedule to fire
sl@0
   229
		startTimeForSchedule = TTime( (TDateTime(2007, EJune, 20, 10, 00, 0, 0)) ); 
sl@0
   230
		RDebug::Print( _L("Added immediate schedule"));
sl@0
   231
		}
sl@0
   232
	else
sl@0
   233
		{
sl@0
   234
		startTimeForSchedule = TTime( (TDateTime(2037, EJune, 20, 10, 00, 0, 0)) ); // These schedules are due in the future.
sl@0
   235
		RDebug::Print( _L("Added long-term schedule"));	
sl@0
   236
		}
sl@0
   237
sl@0
   238
sl@0
   239
	// Prepare a schedule describing when we want the tasks to run (10:00 am)
sl@0
   240
	TSchedulerItemRef ref;
sl@0
   241
	User::LeaveIfError(CreateScheduleL(ref, TheScheduler, startTimeForSchedule));
sl@0
   242
sl@0
   243
	// Disable the schedule whilst we set it up
sl@0
   244
	User::LeaveIfError(TheScheduler.DisableSchedule(ref.iHandle));
sl@0
   245
sl@0
   246
	// Associate a task with the schedule
sl@0
   247
	TTaskInfo taskInfo1;
sl@0
   248
	taskInfo1.iRepeat = 0;
sl@0
   249
	taskInfo1.iName = KTestName;
sl@0
   250
	taskInfo1.iPriority = 2;
sl@0
   251
sl@0
   252
	// Create some data associated with this task
sl@0
   253
	HBufC* taskData1 = KTaskData1().AllocLC();
sl@0
   254
	User::LeaveIfError(TheScheduler.ScheduleTask(taskInfo1, *taskData1, ref.iHandle));
sl@0
   255
	CleanupStack::PopAndDestroy(); // taskData1
sl@0
   256
sl@0
   257
	// Associate a task (2) with the schedule
sl@0
   258
	TTaskInfo taskInfo2;
sl@0
   259
	taskInfo2.iRepeat = 0;
sl@0
   260
	taskInfo2.iName = KTestName;
sl@0
   261
	taskInfo2.iPriority = 2;
sl@0
   262
sl@0
   263
	// Create some data associated with this task
sl@0
   264
	HBufC* taskData2 = KTaskData2().AllocLC();
sl@0
   265
	User::LeaveIfError(TheScheduler.ScheduleTask(taskInfo2, *taskData2, ref.iHandle));
sl@0
   266
	CleanupStack::PopAndDestroy(); // taskData2
sl@0
   267
	
sl@0
   268
	// We should now have two tasks scheduled at exactly the same time...
sl@0
   269
	User::LeaveIfError(TheScheduler.EnableSchedule(ref.iHandle));
sl@0
   270
	
sl@0
   271
	CleanupHelpers::KillProcess(KMinimalTaskHandler);
sl@0
   272
	}
sl@0
   273
	
sl@0
   274
*
sl@0
   275
** end of DEF108026_AddPersistentSchedulesL() **/
sl@0
   276
	
sl@0
   277
sl@0
   278
/**
sl@0
   279
@SYMTestCaseID          SYSLIB-SCHSVR-CT-1031
sl@0
   280
@SYMTestCaseDesc	    Test code for defect "Sending SMS to multiple recipients
sl@0
   281
						sends message to only one recipient" (EDNEMHE-4Q69BG)
sl@0
   282
@SYMTestPriority 	    High
sl@0
   283
@SYMTestActions  	    Schedule two tasks to run at same time
sl@0
   284
@SYMTestExpectedResults Test must not fail
sl@0
   285
@SYMREQ                 REQ0000
sl@0
   286
*/		
sl@0
   287
static void Test1L()
sl@0
   288
	{	
sl@0
   289
	_LIT(KTaskData1, "This is some really exciting task data (number 1)");
sl@0
   290
	_LIT(KTaskData2, "This is some really exciting task data (number 2)");
sl@0
   291
	_LIT(KTestName,	"SmsTest");
sl@0
   292
sl@0
   293
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-1031 TheTest3: SMS:Sending to multiple recipients"));
sl@0
   294
	
sl@0
   295
	TheTest.Next(_L("Connect to Scheduler"));
sl@0
   296
	TInt res = TheScheduler.Connect();
sl@0
   297
	TEST2(res, KErrNone);
sl@0
   298
sl@0
   299
	TheTest.Next(_L("Registering Client"));
sl@0
   300
	TEST2(SchSvrHelpers::RegisterClientL(TheScheduler), KErrNone);
sl@0
   301
sl@0
   302
	// Set the time to a known value, since this makes testing much easier (and more
sl@0
   303
	// repeatable).	
sl@0
   304
	SchSvrHelpers::SetHomeTimeL(TTime(TDateTime(2000, EJanuary, 1, 9, 55, 0, 0))); // 9:55 am
sl@0
   305
sl@0
   306
	// This is the time when we want the schedule to fire
sl@0
   307
	TTime startTimeForSchedule(TDateTime(2000, EJanuary, 1, 10, 0, 0, 0)); // 10:00 am
sl@0
   308
sl@0
   309
	// Prepare a schedule describing when we want the tasks to run (10:00 am)
sl@0
   310
	TSchedulerItemRef ref;
sl@0
   311
	User::LeaveIfError(CreateScheduleL(ref, TheScheduler, startTimeForSchedule));
sl@0
   312
sl@0
   313
	// Disable the schedule whilst we set it up
sl@0
   314
	User::LeaveIfError(TheScheduler.DisableSchedule(ref.iHandle));
sl@0
   315
sl@0
   316
	// Associate a task with the schedule
sl@0
   317
	TTaskInfo taskInfo1;
sl@0
   318
	taskInfo1.iRepeat = 0;
sl@0
   319
	taskInfo1.iName = KTestName;
sl@0
   320
	taskInfo1.iPriority = 2;
sl@0
   321
sl@0
   322
	// Create some data associated with this task
sl@0
   323
	HBufC* taskData1 = KTaskData1().AllocLC();
sl@0
   324
	User::LeaveIfError(TheScheduler.ScheduleTask(taskInfo1, *taskData1, ref.iHandle));
sl@0
   325
	CleanupStack::PopAndDestroy(); // taskData1
sl@0
   326
sl@0
   327
	// Associate a task (2) with the schedule
sl@0
   328
	TTaskInfo taskInfo2;
sl@0
   329
	taskInfo2.iRepeat = 0;
sl@0
   330
	taskInfo2.iName = KTestName;
sl@0
   331
	taskInfo2.iPriority = 2;
sl@0
   332
sl@0
   333
	// Create some data associated with this task
sl@0
   334
	HBufC* taskData2 = KTaskData2().AllocLC();
sl@0
   335
	User::LeaveIfError(TheScheduler.ScheduleTask(taskInfo2, *taskData2, ref.iHandle));
sl@0
   336
	CleanupStack::PopAndDestroy(); // taskData2
sl@0
   337
sl@0
   338
	// We should now have two tasks scheduled at exactly the same time...
sl@0
   339
	User::LeaveIfError(TheScheduler.EnableSchedule(ref.iHandle));
sl@0
   340
sl@0
   341
	// Set the time to 5 minutes *AFTER* the schedule was due to run (10:05am). In this instance,
sl@0
   342
	// based on the new fixed Schedule Server, the schedule should still execute since 
sl@0
   343
	// it falls within the validity period (30 mins), however, in the old scheme of things,
sl@0
   344
	// the schedule would not be valid again until tomorrow (2/1/2000) at 10:00am and hence
sl@0
   345
	// would not execute until then.	
sl@0
   346
	SchSvrHelpers::SetHomeTimeL(TTime(TDateTime(2000, EJanuary, 1, 10, 5, 0, 0))); // 10:05 am
sl@0
   347
sl@0
   348
	// Now wait for something to happen...
sl@0
   349
	TEST2(STaskSemaphore::WaitL(KDefaultTimeout), KErrNone);
sl@0
   350
	CleanupHelpers::KillProcess(KMinimalTaskHandler);
sl@0
   351
	}
sl@0
   352
sl@0
   353
/**
sl@0
   354
@SYMTestCaseID          SYSLIB-SCHSVR-CT-1032
sl@0
   355
@SYMTestCaseDesc	    Tests for creation of transient schedule with task repeating 5 times
sl@0
   356
@SYMTestPriority 	    High
sl@0
   357
@SYMTestActions  	    There should be no schedules as its a transient one and last schedule
sl@0
   358
						should have deleted by itself.
sl@0
   359
@SYMTestExpectedResults Test must not fail
sl@0
   360
@SYMREQ                 REQ0000
sl@0
   361
*/		
sl@0
   362
static void Test2L()
sl@0
   363
	{	
sl@0
   364
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-1032 Testing creation of transient schedule with task repeating 5 times "));
sl@0
   365
sl@0
   366
	TInt tTask = 0;
sl@0
   367
	TSchedulerItemRef ref;
sl@0
   368
	// schedule has 3 entries - +1min, +2min and +3min
sl@0
   369
	TInt res = ScheduleTransientTaskL(tTask, ref, 5, TheScheduler);//5 repeats
sl@0
   370
	TEST2(res, KErrNone);
sl@0
   371
	
sl@0
   372
	TheTest.Printf(_L("Get Task count and repeat count\n"));
sl@0
   373
sl@0
   374
	CTaskInfoArray* tasks = new (ELeave) CTaskInfoArray(3);
sl@0
   375
	CleanupStack::PushL(tasks);
sl@0
   376
	GetTaskInfoL(*tasks, ref.iHandle);
sl@0
   377
	TEST(tasks->Count() == 1);
sl@0
   378
	TTaskInfo info = tasks->At(0);
sl@0
   379
	TEST(info.iRepeat == 5);
sl@0
   380
	ForceTaskExecutionForSpecifiedIdL(ref.iHandle, 3);
sl@0
   381
	GetTaskInfoL(*tasks, ref.iHandle);
sl@0
   382
	TEST(tasks->Count() == 1);
sl@0
   383
	info = tasks->At(0);
sl@0
   384
	TEST(info.iRepeat == 2); // still 2 repeats to go.
sl@0
   385
	ForceTaskExecutionForSpecifiedIdL(ref.iHandle, 2);
sl@0
   386
sl@0
   387
	CleanupStack::PopAndDestroy(tasks);
sl@0
   388
	
sl@0
   389
	TInt scheduleCount = CountScheduledItemsL(EPendingSchedules, TheScheduler);
sl@0
   390
	// There should be no schedules as its a transient one and last schedule
sl@0
   391
	// should have deleted itself.
sl@0
   392
	TEST(scheduleCount == 0); 
sl@0
   393
	SchSvrHelpers::Pause(TheTest);
sl@0
   394
	}
sl@0
   395
sl@0
   396
/**
sl@0
   397
@SYMTestCaseID          SYSLIB-SCHSVR-CT-1341
sl@0
   398
@SYMTestCaseDesc	    Tests for defect number DEF055586L
sl@0
   399
@SYMTestPriority 	    High
sl@0
   400
@SYMTestActions  	    Check to ensure that last element in schedule entries
sl@0
   401
                        array not skipped by schedule checking functions
sl@0
   402
@SYMTestExpectedResults Test must not fail
sl@0
   403
@SYMREQ                 REQ0000
sl@0
   404
*/		
sl@0
   405
static void DEF055586L()
sl@0
   406
	{	
sl@0
   407
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-1041 DEF055586 - Last element in array missed by loop"));
sl@0
   408
	
sl@0
   409
	TheTest.Next(_L("Connect to Scheduler"));
sl@0
   410
	TInt res = TheScheduler.Connect();
sl@0
   411
	TEST2(res, KErrNone);
sl@0
   412
sl@0
   413
	TheTest.Next(_L("Registering Client"));
sl@0
   414
	TEST2(SchSvrHelpers::RegisterClientL(TheScheduler), KErrNone);
sl@0
   415
sl@0
   416
	// Set the time to a known value, since this makes testing much easier (and more
sl@0
   417
	// repeatable).
sl@0
   418
	SchSvrHelpers::SetHomeTimeL(TTime(TDateTime(2000, EJanuary, 1, 9, 55, 0, 0))); // 9:55 am
sl@0
   419
sl@0
   420
	// This is the time when we want the schedule to fire
sl@0
   421
	TTime startTimeForSchedule(TDateTime(2000, EJanuary, 1, 10, 0, 0, 0)); // 10:00 am
sl@0
   422
sl@0
   423
	// Prepare a schedule describing when we want the tasks to run (10:00 am)
sl@0
   424
	TSchedulerItemRef ref;
sl@0
   425
sl@0
   426
	CScheduleEntryInfoArray* entryList = new (ELeave) CScheduleEntryInfoArray(1);
sl@0
   427
	CleanupStack::PushL(entryList);
sl@0
   428
sl@0
   429
	TScheduleEntryInfo entry1;
sl@0
   430
	entry1.iStartTime		= startTimeForSchedule;
sl@0
   431
	entry1.iInterval		= 0; // TTimeIntervalDays: set to 0 to induce an error
sl@0
   432
	entry1.iIntervalType	= EDaily;
sl@0
   433
	entry1.iValidityPeriod	= 30; // minutes
sl@0
   434
	entryList->AppendL(entry1);
sl@0
   435
	TInt err = TheScheduler.CreatePersistentSchedule(ref, *entryList);
sl@0
   436
sl@0
   437
	TEST2(err, KErrArgument);
sl@0
   438
sl@0
   439
	TheTest.Next(_L("DEF055586 - Now checking 0 entries in schedule"));
sl@0
   440
	entryList->Reset();
sl@0
   441
	
sl@0
   442
	err = TheScheduler.CreatePersistentSchedule(ref, *entryList);
sl@0
   443
	
sl@0
   444
	TEST2(err, KErrArgument);
sl@0
   445
	
sl@0
   446
	CleanupStack::PopAndDestroy(); // entryList
sl@0
   447
	}
sl@0
   448
	
sl@0
   449
/**
sl@0
   450
@SYMTestCaseID          SYSLIB-SCHSVR-CT-3159
sl@0
   451
@SYMTestCaseDesc	    Tests for defect number DEF094149
sl@0
   452
@SYMTestPriority 	    Normal
sl@0
   453
@SYMTestActions  	    Create one Schedule and two task in it, then delete one task
sl@0
   454
						check whether Task Scheduler execute disabled Schedule 
sl@0
   455
@SYMTestExpectedResults Test must not fail
sl@0
   456
@SYMREQ                 REQ0000
sl@0
   457
*/		
sl@0
   458
void DEF094149L()
sl@0
   459
	{	
sl@0
   460
	// Create  scheduling entries
sl@0
   461
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-3159 DEF094149: RF Task Scheduler execute deleted tasks (in stress conditions) "));
sl@0
   462
	TTime time;
sl@0
   463
	time.HomeTime();
sl@0
   464
	time += TTimeIntervalSeconds(2); // Scheduler will run task in 2 seconds
sl@0
   465
sl@0
   466
	TScheduleEntryInfo entry;
sl@0
   467
	entry.iIntervalType	= EHourly;
sl@0
   468
	entry.iStartTime		= time;
sl@0
   469
	entry.iInterval		= 1;
sl@0
   470
	entry.iValidityPeriod	= 20;
sl@0
   471
	
sl@0
   472
	CArrayFixFlat<TScheduleEntryInfo>* entries = new(ELeave) CArrayFixFlat<TScheduleEntryInfo>(10);
sl@0
   473
	CleanupStack::PushL(entries);
sl@0
   474
sl@0
   475
	entries->AppendL(entry);
sl@0
   476
	TSchedulerItemRef ref;
sl@0
   477
	// Create the schedule for the task... and disable it
sl@0
   478
	TheScheduler.Connect();
sl@0
   479
	TheScheduler.CreatePersistentSchedule(ref, *entries);
sl@0
   480
	TheScheduler.DisableSchedule(ref.iHandle);
sl@0
   481
	
sl@0
   482
// CreateNewTask
sl@0
   483
	TTaskInfo task;
sl@0
   484
	task.iRepeat	= 1; // repeat once
sl@0
   485
	task.iName		= _L("Test Task For Defect Verification");
sl@0
   486
	task.iPriority	= 100;
sl@0
   487
	
sl@0
   488
	
sl@0
   489
	TBuf<255>fileName = _L("Some task");
sl@0
   490
	TheScheduler.Register( fileName, 1 );
sl@0
   491
	HBufC* taskData = HBufC::NewLC(1);
sl@0
   492
sl@0
   493
	//first task
sl@0
   494
	TheScheduler.ScheduleTask(task, *taskData,ref.iHandle);
sl@0
   495
	TInt taskid1;
sl@0
   496
	taskid1 = task.iTaskId;
sl@0
   497
	
sl@0
   498
	//Second task
sl@0
   499
	TheScheduler.ScheduleTask(task, *taskData,ref.iHandle);
sl@0
   500
	TInt taskid2;
sl@0
   501
	taskid2 = task.iTaskId;
sl@0
   502
sl@0
   503
	TInt err = TheScheduler.DeleteTask(taskid1);
sl@0
   504
	
sl@0
   505
	User::After(KTimeToWait);
sl@0
   506
	err = TheScheduler.DeleteTask(taskid2);
sl@0
   507
	
sl@0
   508
	//check whether Task Scheduler execute the second task after deleting first tasks 
sl@0
   509
	//If the Schedule executed then err == KErrNotFound
sl@0
   510
	TEST2(err, KErrNone);
sl@0
   511
	CleanupStack::PopAndDestroy(taskData);	
sl@0
   512
	CleanupStack::PopAndDestroy(entries);	
sl@0
   513
sl@0
   514
	}
sl@0
   515
sl@0
   516
/**
sl@0
   517
@SYMTestCaseID          SYSLIB-SCHSVR-CT-3358
sl@0
   518
@SYMTestCaseDesc	    Tests for defect number  INC098909 
sl@0
   519
@SYMTestPriority 	    High
sl@0
   520
@SYMTestActions  	    Mark heap of Scheduler then create a schedule & task wait for its 
sl@0
   521
						execution then check heap again for memory leaks
sl@0
   522
@SYMTestExpectedResults Test must not fail
sl@0
   523
@SYMDEF                 INC098909: Process !TaskScheluder leaks memory in mail polls.
sl@0
   524
*/
sl@0
   525
static void INC098909()
sl@0
   526
	{
sl@0
   527
	const TInt KTimeToWait = 5*1000*1000; 
sl@0
   528
	//SchSvrHelpers::DeleteScheduleFilesL();
sl@0
   529
	
sl@0
   530
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-3358 INC098909: Process !TaskScheluder leaks memory in mail polls "));
sl@0
   531
	TheTest.Next(_L("Connect to Scheduler"));
sl@0
   532
	TEST2(TheScheduler.Connect(),KErrNone);
sl@0
   533
sl@0
   534
	TheTest.Next(_L("Registering Client"));
sl@0
   535
	TEST2(SchSvrHelpers::RegisterClientL(TheScheduler), KErrNone);
sl@0
   536
	
sl@0
   537
	User::LeaveIfError(TheScheduler.__DbgMarkHeap());
sl@0
   538
sl@0
   539
	//Create Schedule
sl@0
   540
	CArrayFixFlat<TScheduleEntryInfo>* entryList = new(ELeave) CArrayFixFlat<TScheduleEntryInfo>(1);
sl@0
   541
	CleanupStack::PushL(entryList);
sl@0
   542
	TSchedulerItemRef ref;
sl@0
   543
	
sl@0
   544
	TTime time;
sl@0
   545
	time.HomeTime();
sl@0
   546
	time += TTimeIntervalSeconds(0); // Scheduler will run task in  5 sec
sl@0
   547
sl@0
   548
	TScheduleEntryInfo entry1;
sl@0
   549
	entry1.iIntervalType	= EHourly;
sl@0
   550
	entry1.iStartTime		= time;
sl@0
   551
	entry1.iInterval		= 1;
sl@0
   552
	entry1.iValidityPeriod	= 20;
sl@0
   553
	entryList->AppendL(entry1);
sl@0
   554
	
sl@0
   555
	// Create the schedule for the task...
sl@0
   556
	TEST2(TheScheduler.CreatePersistentSchedule(ref, *entryList),KErrNone);
sl@0
   557
	
sl@0
   558
	//Create Task
sl@0
   559
	TTaskInfo task;
sl@0
   560
	task.iRepeat	= 1; // repeat once
sl@0
   561
	task.iName		= _L("Test ");
sl@0
   562
	task.iPriority	= 100;
sl@0
   563
	
sl@0
   564
	HBufC* taskData = HBufC::NewLC(1);
sl@0
   565
	TEST2(TheScheduler.ScheduleTask(task, *taskData,ref.iHandle), KErrNone);
sl@0
   566
	
sl@0
   567
	CleanupStack::PopAndDestroy(taskData);
sl@0
   568
	CleanupStack::PopAndDestroy(entryList);	
sl@0
   569
	
sl@0
   570
	//Wait schedule to complete
sl@0
   571
	User::After(KTimeToWait);
sl@0
   572
sl@0
   573
	User::LeaveIfError(TheScheduler.__DbgMarkEnd(0));
sl@0
   574
sl@0
   575
	SchSvrHelpers::DeleteAllSchedulesL(TheScheduler);
sl@0
   576
	
sl@0
   577
	// really clean out the scheduler (get rid of all the files and process)
sl@0
   578
	TheScheduler.Close();
sl@0
   579
	SchSvrHelpers::DeleteScheduleFilesL();
sl@0
   580
	CleanupHelpers::KillProcess(KMinimalTaskHandler);
sl@0
   581
	// Now wait for something to happen...
sl@0
   582
	TEST2(STaskSemaphore::WaitL(KDefaultTimeout), KErrNone);
sl@0
   583
	}
sl@0
   584
sl@0
   585
sl@0
   586
	
sl@0
   587
/**
sl@0
   588
@SYMTestCaseID          SYSLIB-SCHSVR-CT-4003
sl@0
   589
@SYMTestCaseDesc	    Test for DEF108026:
sl@0
   590
						The aim of this test is to create enough persistent schedules. This reproduce the defect, when 
sl@0
   591
						SysStart startup. task scheduler will see that these schedules are due. It will then add them 
sl@0
   592
						immediately to the timer during SSA phase. As this operation consumes a long time and CSchStartupStateMgr::RunL() 
sl@0
   593
						is blocking, the domain manager fails to be ackowleged about the state transition, therefore certain processes like 
sl@0
   594
						Esock workers does not complete.  These schedules are due immediately (at the time we run this test), we need then to 
sl@0
   595
						set the time of the device at the time where the schedules are due. We set the home time of the device in CSchServer::ConstructL(). 
sl@0
   596
						I add in comment the modified CSchServer::ConstructL().
sl@0
   597
						ssch_svr.dll must be rebuilt.
sl@0
   598
						I could reproduces this defect only on Uiq. I could not reproduce it on techview!
sl@0
   599
@SYMTestPriority 	    Normal
sl@0
   600
@SYMTestActions  	    Create persistent and long-term schedules.
sl@0
   601
@SYMTestExpectedResults Test must create a 
sl@0
   602
@SYMDEF                 DEF108026:SCHSVR performs SSA-driven actions before acknowledging transition.
sl@0
   603
*/
sl@0
   604
/*********************** constructL() modified.Needed to explain the manual test DEF108026() ********************************
sl@0
   605
**
sl@0
   606
**
sl@0
   607
void CSchServer::ConstructL()
sl@0
   608
	{
sl@0
   609
#ifdef __SCHLOGGING__
sl@0
   610
	iTheLog = CSheduleServerLog::NewL(_L("SchSvr"));
sl@0
   611
	Dll::SetTls(iTheLog);
sl@0
   612
#endif
sl@0
   613
sl@0
   614
 	// Create server storage path
sl@0
   615
 	RFs fs;
sl@0
   616
 	User::LeaveIfError(fs.Connect());
sl@0
   617
sl@0
   618
#ifdef __SECURE_DATA__
sl@0
   619
	TInt err = fs.CreatePrivatePath(EDriveC);
sl@0
   620
#else
sl@0
   621
	_LIT(KDirPath, "C:\\System\\Schedules\\");
sl@0
   622
	TInt err = fs.MkDirAll(KDirPath);
sl@0
   623
#endif
sl@0
   624
sl@0
   625
	if(err != KErrNone && err != KErrAlreadyExists)
sl@0
   626
		User::Leave(err);
sl@0
   627
	
sl@0
   628
	fs.Close();
sl@0
   629
	
sl@0
   630
	
sl@0
   631
	
sl@0
   632
	
sl@0
   633
	// The process that we need to add to set the time of the device.
sl@0
   634
	// We need to set it to the same time that the schedules added are due.
sl@0
   635
TTime newTime ( (TDateTime(2007, EJune, 20, 10, 00, 00, 00)) ); // 10:00 am
sl@0
   636
	{
sl@0
   637
sl@0
   638
	_LIT(KSetHomeTime, "TSetHomeTime");
sl@0
   639
	_LIT(KTimeFormat, "%F%Y%M%D:%H%T%S.%*C6");
sl@0
   640
	
sl@0
   641
	RProcess p;	
sl@0
   642
	TRequestStatus stat;
sl@0
   643
	TBuf<128> bufLocalTime;	
sl@0
   644
	
sl@0
   645
	newTime.FormatL(bufLocalTime, KTimeFormat);
sl@0
   646
	
sl@0
   647
	User::LeaveIfError(p.Create(KSetHomeTime, bufLocalTime));
sl@0
   648
	
sl@0
   649
	// Asynchronous logon: completes when process terminates with process exit code
sl@0
   650
	p.Logon(stat);
sl@0
   651
	p.Resume();
sl@0
   652
sl@0
   653
	User::WaitForRequest(stat);
sl@0
   654
	TInt exitReason = p.ExitReason();
sl@0
   655
	p.Close();
sl@0
   656
   //return (exitReason);
sl@0
   657
	}	
sl@0
   658
	
sl@0
   659
	
sl@0
   660
	
sl@0
   661
	
sl@0
   662
	iTaskScheduler = CTaskScheduler::NewL();
sl@0
   663
sl@0
   664
	iSSAMgr = new(ELeave) CSchStartupStateMgr(KDmHierarchyIdStartup, KBaseServicesDomain3);
sl@0
   665
	iSSAMgr->RegisterObserverL(iTaskScheduler);
sl@0
   666
	iSSAMgr->InitialiseL();
sl@0
   667
sl@0
   668
	StartL(KSchSvrName);
sl@0
   669
	}
sl@0
   670
**
sl@0
   671
** end of the changes we need to do in ssch_svr.cpp **/
sl@0
   672
sl@0
   673
/*
sl@0
   674
 * This should be called by DoTheTestsL () . It is part of the manual test SYSLIB-SCHSVR-CT-4003
sl@0
   675
 * should be commented and will run as manual test only.
sl@0
   676
 *
sl@0
   677
 * 
sl@0
   678
static void DEF108026()
sl@0
   679
	{
sl@0
   680
	TheTest.Next(_L("DEF108026: Creating enough persistent and long-term schedules to make task scheduler slower while adding them to the timer"));
sl@0
   681
	
sl@0
   682
	for ( TInt i = 0; i < 500; i++ )
sl@0
   683
		{
sl@0
   684
		DEF108026_AddPersistentSchedulesL( ETrue );
sl@0
   685
		HBufC* debugTxt = HBufC::NewLC( 256 );
sl@0
   686
		debugTxt->Des().Append( _L( "Added Test... " ) );
sl@0
   687
		debugTxt->Des().AppendNum( i++ );				
sl@0
   688
		RDebug::Print( *debugTxt );	
sl@0
   689
		CleanupStack::PopAndDestroy( debugTxt );		
sl@0
   690
		}
sl@0
   691
	
sl@0
   692
	
sl@0
   693
	for ( TInt i = 0; i < 1000; i++ )
sl@0
   694
		{
sl@0
   695
		DEF108026_AddPersistentSchedulesL( EFalse );
sl@0
   696
		HBufC* debugTxt = HBufC::NewLC( 256 );
sl@0
   697
		debugTxt->Des().Append( _L( "Added Test... " ) );
sl@0
   698
		debugTxt->Des().AppendNum( i++ );				
sl@0
   699
		RDebug::Print( *debugTxt );	
sl@0
   700
		CleanupStack::PopAndDestroy( debugTxt );		
sl@0
   701
		}			
sl@0
   702
		
sl@0
   703
	}
sl@0
   704
** end of DEF108026 () **/
sl@0
   705
sl@0
   706
GLDEF_C TInt DoTheTestsL()
sl@0
   707
	{
sl@0
   708
	
sl@0
   709
	//Delete old files.
sl@0
   710
	SchSvrHelpers::DeleteScheduleFilesL();
sl@0
   711
	
sl@0
   712
	STaskSemaphore sem;
sl@0
   713
	sem.CreateL();
sl@0
   714
	
sl@0
   715
	TheTest.Next(_L("Start tests"));
sl@0
   716
	// Add tests here:-
sl@0
   717
	
sl@0
   718
	//DEF108026(); //This is a manual test. This test runs only under certain condition,
sl@0
   719
				 //Read the condition required to run this test in the implementation of the DEF108026() comments.
sl@0
   720
	
sl@0
   721
	INC098909();	// Should be commented while running def108026
sl@0
   722
	DEF094149L();   // Should be commented while running def108026
sl@0
   723
	Test1L();		//Should be commented while running def108026
sl@0
   724
	Test2L();		//Should be commented while running def108026
sl@0
   725
	DEF055586L();	//Should be commented while running def108026
sl@0
   726
	
sl@0
   727
	sem.Close();
sl@0
   728
	
sl@0
   729
	//Tidying up so next test will be clear.
sl@0
   730
	TheTest.Next(_L("Delete all schedules"));
sl@0
   731
	SchSvrHelpers::DeleteAllSchedulesL(TheScheduler); // While running def108026() manual test, this should be commented. We
sl@0
   732
														// want keep the persistent schedules.
sl@0
   733
	SchSvrHelpers::Pause(TheTest, 2);
sl@0
   734
	TheTest.Next(_L("Delete old files\n"));
sl@0
   735
	SchSvrHelpers::DeleteScheduleFilesL(); // While running def108026() manual test, this should be commented. We
sl@0
   736
											// want keep the persistent schedules.
sl@0
   737
	TheScheduler.Close();
sl@0
   738
sl@0
   739
	return KErrNone;
sl@0
   740
	}
sl@0
   741
sl@0
   742
sl@0
   743
//***********************************************************************************
sl@0
   744
GLDEF_C TInt E32Main()
sl@0
   745
    {
sl@0
   746
	__UHEAP_MARK;
sl@0
   747
	TheTest.Title();
sl@0
   748
	TheTest.Start(_L("TC_TSCH_SCHEDULING1"));
sl@0
   749
sl@0
   750
	TInt error = KErrNone;
sl@0
   751
	CTrapCleanup* cleanup = CTrapCleanup::New();
sl@0
   752
	if	(!cleanup)
sl@0
   753
		return KErrNoMemory;
sl@0
   754
	//If the previous test fails, SCHSVR.exe may stay in memory.
sl@0
   755
	TRAP(error,CleanupHelpers::TestCleanupL());
sl@0
   756
	TEST2(error, KErrNone);
sl@0
   757
sl@0
   758
	TEST2(TheFsSession.Connect(), KErrNone);
sl@0
   759
	TheTest.Next(_L("Do the tests"));
sl@0
   760
	TRAP(error, DoTheTestsL());
sl@0
   761
	TEST2(error,KErrNone); // While running DEF108026 this line should be commented. If not, error = -4 (no memory) and this leaves. 
sl@0
   762
						   //The reason is that our generated schedules take a lot of space. But this is the aim of this manual test:
sl@0
   763
						   // The SchedulesBackup.dat must be bigger as possible to reproduce the defect
sl@0
   764
	TheFsSession.Close();
sl@0
   765
	TRAP(error,CleanupHelpers::TestCleanupL());
sl@0
   766
	TEST2(error, KErrNone);
sl@0
   767
	delete cleanup;	
sl@0
   768
sl@0
   769
	TheTest.End();
sl@0
   770
	TheTest.Close();
sl@0
   771
	__UHEAP_MARKEND;
sl@0
   772
	return KErrNone;
sl@0
   773
	}