os/ossrv/genericservices/taskscheduler/Test/Scheduling/TC_TSCH_SCHEDULING1_UTC.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericservices/taskscheduler/Test/Scheduling/TC_TSCH_SCHEDULING1_UTC.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,570 @@
1.4 +// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include <e32base.h>
1.20 +#include <e32test.h>
1.21 +#include <csch_cli.h>
1.22 +#include <f32file.h>
1.23 +#include "Thelpers.h"
1.24 +
1.25 +#include "TestUtils.h"
1.26 +
1.27 +// Globals
1.28 +RTest TheTest(_L("TC_TSCH_SCHEDULING1 - UTC"));
1.29 +static RScheduler TheScheduler;
1.30 +static RFs TheFsSession;
1.31 +
1.32 +typedef CArrayFixFlat<TScheduleEntryInfo2> CScheduleEntryInfoArray;
1.33 +typedef CArrayFixFlat<TTaskInfo> CTaskInfoArray;
1.34 +typedef CArrayFixFlat<TSchedulerItemRef> CSchItemRefArray;
1.35 +
1.36 +_LIT(KMinimalTaskHandler, "MinimalTaskHandler");
1.37 +
1.38 +_LIT(KTimeFormatString, "%-B%:0%J%:1%T%:2%S%.%*C4%:3%+B");
1.39 +_LIT(KCurrentDateTimeChanged, "Date & Time changed to: [%S]\n");
1.40 +
1.41 +//***********************************************************************************
1.42 +
1.43 +// Sets time to before specified time by aTimeBeforeInSeconds
1.44 +static void SetTimeBeforeL(RTest& aTest, TTsTime& aTime, TInt aTimeBeforeInSeconds)
1.45 + {
1.46 + TTimeIntervalSeconds secs(aTimeBeforeInSeconds);
1.47 + TTime time = aTime.GetLocalTime()-secs;
1.48 + SchSvrHelpers::SetHomeTimeL(time);
1.49 + TBuf<30> dateString;
1.50 + time.FormatL(dateString, KTimeFormatString);
1.51 + aTest.Printf(KCurrentDateTimeChanged, &dateString);
1.52 + }
1.53 +
1.54 +// gets the due time for this schedule
1.55 +static TTsTime GetDueTimeL(TInt aScheduleId)
1.56 + {
1.57 + TTsTime nextTimeScheduleIsDue;
1.58 + TScheduleState2 state;
1.59 + CScheduleEntryInfoArray* entries
1.60 + = new (ELeave) CScheduleEntryInfoArray(3);
1.61 + CleanupStack::PushL(entries);
1.62 + CTaskInfoArray* tasks = new (ELeave) CTaskInfoArray(3);
1.63 + CleanupStack::PushL(tasks);
1.64 +
1.65 + TInt res = TheScheduler.GetScheduleL(aScheduleId, state, *entries, *tasks, nextTimeScheduleIsDue);
1.66 + TEST2(res, KErrNone);
1.67 +
1.68 + CleanupStack::PopAndDestroy(2); // entries, tasks
1.69 +
1.70 + return state.DueTime();
1.71 + }
1.72 +
1.73 +// Forces the task to be exectued aCount times.
1.74 +static void ForceTaskExecutionForSpecifiedIdL(TInt aId, TInt aCount)
1.75 + {
1.76 + TheTest.Printf(_L("Executing %d times\n"), aCount);
1.77 + TTsTime time;
1.78 + for (TInt i=0; i<aCount; ++i)
1.79 + {
1.80 + TheTest.Printf(_L("Execution %d\n"), i+1);
1.81 + time = GetDueTimeL(aId);
1.82 +
1.83 + SetTimeBeforeL(TheTest, time, 5 /*seconds*/);
1.84 +
1.85 + // Wait for notification that schedule has executed.
1.86 + TEST2(STaskSemaphore::WaitL(KDefaultTimeout), KErrNone);
1.87 + CleanupHelpers::KillProcess(KMinimalTaskHandler);
1.88 + }
1.89 + }
1.90 +
1.91 +//creates a daily schedule with StartTime of aStartTime
1.92 +static TInt CreateScheduleL(TSchedulerItemRef& aRef,
1.93 + RScheduler& aScheduler,
1.94 + const TTsTime& aStartTime)
1.95 + {
1.96 + CScheduleEntryInfoArray* entryList
1.97 + = new (ELeave) CScheduleEntryInfoArray(1);
1.98 + CleanupStack::PushL(entryList);
1.99 +
1.100 + TScheduleEntryInfo2 entry1 (aStartTime, EDaily, 1, 30);
1.101 + entryList->AppendL(entry1);
1.102 + TInt res = aScheduler.CreatePersistentSchedule(aRef, *entryList);
1.103 + CleanupStack::PopAndDestroy(); // entryList
1.104 + return res;
1.105 + }
1.106 +
1.107 +// counts the number of scheduled items based on the supplied filter.
1.108 +static TInt CountScheduledItemsL(TScheduleFilter aFilter,
1.109 + RScheduler& aScheduler)
1.110 + // Extract schedule references from the schedule server based on a filter. If
1.111 + {
1.112 + CSchItemRefArray* refs = new (ELeave) CSchItemRefArray(3);
1.113 + CleanupStack::PushL(refs);
1.114 +
1.115 + TInt res = aScheduler.GetScheduleRefsL(*refs, aFilter);
1.116 + TEST2(res, KErrNone);
1.117 +
1.118 + TInt count = refs->Count();
1.119 + CleanupStack::PopAndDestroy(); // refs
1.120 + return count;
1.121 + }
1.122 +
1.123 +// Extract task references from the schedule server based on a ID
1.124 +static void GetTaskInfoL(CTaskInfoArray& aTaskInfoArray,
1.125 + TInt aScheduleId)
1.126 + {
1.127 + aTaskInfoArray.Reset();
1.128 + TTsTime nextTimeScheduleIsDue;
1.129 + TScheduleState2 state;
1.130 + CScheduleEntryInfoArray* entries
1.131 + = new (ELeave) CScheduleEntryInfoArray(3);
1.132 + CleanupStack::PushL(entries);
1.133 + TInt res = TheScheduler.GetScheduleL(aScheduleId,
1.134 + state,
1.135 + *entries,
1.136 + aTaskInfoArray,
1.137 + nextTimeScheduleIsDue);
1.138 + TEST2(res, KErrNone);
1.139 + CleanupStack::PopAndDestroy(entries);
1.140 + }
1.141 +
1.142 +// schedules a transient task
1.143 +static TInt ScheduleTransientTaskL(TInt& aTaskId,
1.144 + TSchedulerItemRef& aRef,
1.145 + TInt aRepeat,
1.146 + RScheduler& aScheduler)
1.147 + {
1.148 + CScheduleEntryInfoArray* entryList = new(ELeave) CScheduleEntryInfoArray(3);
1.149 + CleanupStack::PushL(entryList);
1.150 +
1.151 + aRef.iName = _L("transient one");
1.152 +
1.153 + // SCHEDULES
1.154 + TTime ttime1(SchSvrHelpers::UtcTimeBasedOnOffset(0, 1));
1.155 + TTsTime startTime1 (ttime1,ETrue); // 1 min in the future
1.156 + TScheduleEntryInfo2 entry1 (startTime1, EDaily, 1, 20);
1.157 + entryList->AppendL(entry1);
1.158 + TTime ttime2(SchSvrHelpers::UtcTimeBasedOnOffset(0, 2));
1.159 + TTsTime startTime2 (ttime2,ETrue); // 2 min in the future
1.160 + TScheduleEntryInfo2 entry2 (startTime2, EDaily, 1, 500);
1.161 + entryList->AppendL(entry2);
1.162 +
1.163 + TTime ttime3(SchSvrHelpers::UtcTimeBasedOnOffset(0, 3));
1.164 + TTsTime startTime3 (ttime3,ETrue); // 3 min in the future
1.165 + TScheduleEntryInfo2 entry3 (startTime3, EDaily, 1, 5);
1.166 + entryList->AppendL(entry3);
1.167 +
1.168 + // TASK
1.169 + TTaskInfo taskInfo;
1.170 + taskInfo.iName = _L("mail");
1.171 + taskInfo.iTaskId = aTaskId;
1.172 + taskInfo.iRepeat = aRepeat;
1.173 + taskInfo.iPriority = 2;
1.174 + HBufC* data = _L("the data, some strange new name ").AllocLC();
1.175 +
1.176 + // Schedule the item
1.177 + TInt res = aScheduler.ScheduleTask(taskInfo, *data, aRef, *entryList);
1.178 + CleanupStack::PopAndDestroy(2); // data, entryList
1.179 +
1.180 + aTaskId = taskInfo.iTaskId;
1.181 + return res;
1.182 + }
1.183 +
1.184 +
1.185 +//***********************************************************************************
1.186 +
1.187 +/**
1.188 +@file
1.189 +@SYMTestCaseID SYSLIB-SCHSVR-CT-0254
1.190 +@SYMTestCaseDesc Replicated test for for defect (EDNEMHE-4Q69BG) - UTC
1.191 +@SYMTestPriority High
1.192 +@SYMTestActions Create time based schedules and then jump to a time after the due time but within the validity period and check it schedule still fires
1.193 +@SYMTestExpectedResults The test must not fail.
1.194 +@SYMPREQ PREQ234
1.195 +*/
1.196 +static void Test1L()
1.197 + {
1.198 + _LIT(KTaskData1, "This is some really exciting task data (number 1)");
1.199 + _LIT(KTaskData2, "This is some really exciting task data (number 2)");
1.200 + _LIT(KTestName, "SmsTest");
1.201 +
1.202 + TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0254 TheTest3: SMS:Sending to multiple recipients "));
1.203 +
1.204 + TheTest.Next(_L("Connect to Scheduler"));
1.205 + TInt res = TheScheduler.Connect();
1.206 + TEST2(res, KErrNone);
1.207 +
1.208 + TheTest.Next(_L("Registering Client"));
1.209 + TEST2(SchSvrHelpers::RegisterClientL(TheScheduler), KErrNone);
1.210 +
1.211 + // Set the time to a known value, since this makes testing much easier (and more
1.212 + // repeatable).
1.213 + SchSvrHelpers::SetHomeTimeL(TTime(TDateTime(2000, EJanuary, 1, 9, 55, 0, 0))); // 9:55 am
1.214 +
1.215 + // This is the time when we want the schedule to fire
1.216 + TDateTime datetime(2000, EJanuary, 1, 10, 0, 0, 0);
1.217 + TTsTime startTimeForSchedule(datetime, ETrue); // 10:00 am
1.218 +
1.219 +
1.220 + // Prepare a schedule describing when we want the tasks to run (10:00 am)
1.221 + TSchedulerItemRef ref;
1.222 + User::LeaveIfError(CreateScheduleL(ref, TheScheduler, startTimeForSchedule));
1.223 +
1.224 + // Disable the schedule whilst we set it up
1.225 + User::LeaveIfError(TheScheduler.DisableSchedule(ref.iHandle));
1.226 +
1.227 + // Associate a task with the schedule
1.228 + TTaskInfo taskInfo1;
1.229 + taskInfo1.iRepeat = 0;
1.230 + taskInfo1.iName = KTestName;
1.231 + taskInfo1.iPriority = 2;
1.232 +
1.233 + // Create some data associated with this task
1.234 + HBufC* taskData1 = KTaskData1().AllocLC();
1.235 + User::LeaveIfError(TheScheduler.ScheduleTask(taskInfo1, *taskData1, ref.iHandle));
1.236 + CleanupStack::PopAndDestroy(); // taskData1
1.237 +
1.238 + // Associate a task (2) with the schedule
1.239 + TTaskInfo taskInfo2;
1.240 + taskInfo2.iRepeat = 0;
1.241 + taskInfo2.iName = KTestName;
1.242 + taskInfo2.iPriority = 2;
1.243 +
1.244 + // Create some data associated with this task
1.245 + HBufC* taskData2 = KTaskData2().AllocLC();
1.246 + User::LeaveIfError(TheScheduler.ScheduleTask(taskInfo2, *taskData2, ref.iHandle));
1.247 + CleanupStack::PopAndDestroy(); // taskData2
1.248 +
1.249 + // We should now have two tasks scheduled at exactly the same time...
1.250 + User::LeaveIfError(TheScheduler.EnableSchedule(ref.iHandle));
1.251 +
1.252 + // Set the time to 5 minutes *AFTER* the schedule was due to run (10:05am). In this instance,
1.253 + // based on the new fixed Schedule Server, the schedule should still execute since
1.254 + // it falls within the validity period (30 mins), however, in the old scheme of things,
1.255 + // the schedule would not be valid again until tomorrow (2/1/2000) at 10:00am and hence
1.256 + // would not execute until then.
1.257 + SchSvrHelpers::SetHomeTimeL(TTime(TDateTime(2000, EJanuary, 1, 10, 5, 0, 0))); // 10:05 am
1.258 +
1.259 + // Now wait for something to happen...
1.260 + TEST2(STaskSemaphore::WaitL(KDefaultTimeout), KErrNone);
1.261 + CleanupHelpers::KillProcess(KMinimalTaskHandler);
1.262 + }
1.263 +
1.264 +//***********************************************************************************
1.265 +
1.266 +/**
1.267 +@file
1.268 +@SYMTestCaseID SYSLIB-SCHSVR-CT-0255
1.269 +@SYMTestCaseDesc Replicated test for for defect (EDNEMHE-4Q69BG) - UTC
1.270 +@SYMTestPriority High
1.271 +@SYMTestActions Create time based schedules and then jump to a time after the due time but within the validity period and check it schedule still fires
1.272 +@SYMTestExpectedResults The test must not fail.
1.273 +@SYMPREQ PREQ234
1.274 +*/
1.275 +static void Test2L()
1.276 + {
1.277 + TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0255 Testing creation of transient schedule with task repeating 5 times "));
1.278 + TInt tTask = 0;
1.279 + TSchedulerItemRef ref;
1.280 + // schedule has 3 entries - +1min, +2min and +3min
1.281 + TInt res = ScheduleTransientTaskL(tTask, ref, 5, TheScheduler);//5 repeats
1.282 + TEST2(res, KErrNone);
1.283 +
1.284 + TheTest.Printf(_L("Get Task count and repeat count\n"));
1.285 +
1.286 + CTaskInfoArray* tasks = new (ELeave) CTaskInfoArray(3);
1.287 + CleanupStack::PushL(tasks);
1.288 + GetTaskInfoL(*tasks, ref.iHandle);
1.289 + TEST(tasks->Count() == 1);
1.290 + TTaskInfo info = tasks->At(0);
1.291 + TEST(info.iRepeat == 5);
1.292 + ForceTaskExecutionForSpecifiedIdL(ref.iHandle, 3);
1.293 + GetTaskInfoL(*tasks, ref.iHandle);
1.294 + TEST(tasks->Count() == 1);
1.295 + info = tasks->At(0);
1.296 + TEST(info.iRepeat == 2); // still 2 repeats to go.
1.297 + ForceTaskExecutionForSpecifiedIdL(ref.iHandle, 2);
1.298 +
1.299 + CleanupStack::PopAndDestroy(tasks);
1.300 +
1.301 + TInt scheduleCount = CountScheduledItemsL(EPendingSchedules, TheScheduler);
1.302 + // There should be no schedules as its a transient one and last schedule
1.303 + // should have deleted itself.
1.304 + TEST(scheduleCount == 0);
1.305 + SchSvrHelpers::Pause(TheTest);
1.306 + }
1.307 +
1.308 +//***********************************************************************************
1.309 +
1.310 +/**
1.311 +@file
1.312 +@SYMTestCaseID SYSLIB-SCHSVR-CT-0256
1.313 +@SYMTestCaseDesc Replicated test for for defect (DEF055586L) - UTC
1.314 +@SYMTestPriority High
1.315 +@SYMTestActions Create a time-based schedule check that there are 0 entries in the scehule after it fires
1.316 +@SYMTestExpectedResults The test must not fail.
1.317 +@SYMPREQ PREQ234
1.318 +*/
1.319 +static void DEF055586L()
1.320 + {
1.321 + TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0256 DEF055586 - Last element in array missed by loop "));
1.322 + TheTest.Next(_L("Connect to Scheduler"));
1.323 + TInt res = TheScheduler.Connect();
1.324 + TEST2(res, KErrNone);
1.325 +
1.326 + TheTest.Next(_L("Registering Client"));
1.327 + TEST2(SchSvrHelpers::RegisterClientL(TheScheduler), KErrNone);
1.328 +
1.329 + // Set the time to a known value, since this makes testing much easier (and more
1.330 + // repeatable).
1.331 + SchSvrHelpers::SetHomeTimeL(TTime(TDateTime(2000, EJanuary, 1, 9, 55, 0, 0))); // 9:55 am
1.332 +
1.333 + // This is the time when we want the schedule to fire
1.334 + TDateTime datetime(2000, EJanuary, 1, 10, 0, 0, 0);
1.335 + TTsTime startTimeForSchedule(datetime, ETrue); // 10:00 am
1.336 +
1.337 + // Prepare a schedule describing when we want the tasks to run (10:00 am)
1.338 + TSchedulerItemRef ref;
1.339 +
1.340 + CScheduleEntryInfoArray* entryList = new (ELeave) CScheduleEntryInfoArray(1);
1.341 + CleanupStack::PushL(entryList);
1.342 +
1.343 + TScheduleEntryInfo2 entry1 (startTimeForSchedule, EDaily, 0, 30); // TTimeIntervalDays: set to 0 to induce an error
1.344 + entryList->AppendL(entry1);
1.345 + TInt err = TheScheduler.CreatePersistentSchedule(ref, *entryList);
1.346 +
1.347 + TEST2(err, KErrArgument);
1.348 +
1.349 + TheTest.Next(_L("DEF055586 - Now checking 0 entries in schedule"));
1.350 + entryList->Reset();
1.351 +
1.352 + err = TheScheduler.CreatePersistentSchedule(ref, *entryList);
1.353 +
1.354 + TEST2(err, KErrArgument);
1.355 +
1.356 + CleanupStack::PopAndDestroy(); // entryList
1.357 + }
1.358 +
1.359 +//DEF061595 Schedule timers incorrectly expire when system time is changed
1.360 +//The test will create and submit one schedule which execution time is one year later.
1.361 +//Then the test will change the system time to be current time + 1 day.
1.362 +//Although the schedule time is set to be current time + 1 year, the schedule task(s) will
1.363 +//be executed immediately because the schedule timer expires when the system time changes.
1.364 +void DEF061595L()
1.365 + {
1.366 + TheTest.Next(_L("DEF061595 Schedule timers incorrectly expire when system time is changed"));
1.367 + //Get current time in currTime variable
1.368 + TTime currTime;
1.369 + currTime.HomeTime();
1.370 + //Prepare the task time (in taskTime variable) to be currTime + 1 year.
1.371 + TTime taskTime(currTime + TTimeIntervalYears(1));
1.372 + TInt taskYear = taskTime.DateTime().Year();
1.373 + //Connect to the Task Scheduler Server
1.374 + RScheduler scheduler;
1.375 + CleanupClosePushL(scheduler);
1.376 + TInt res = scheduler.Connect();
1.377 + TEST2(res, KErrNone);
1.378 + TEST2(SchSvrHelpers::RegisterClientL(scheduler), KErrNone);
1.379 + //Create new schedule. The new schedule task will run 1 year later.
1.380 + TTsTime taskTsTime(taskTime, EFalse);
1.381 + TSchedulerItemRef ref;
1.382 + TEST2(::CreateScheduleL(ref, scheduler, taskTsTime), KErrNone);
1.383 + // Disable the schedule whilst we set it up
1.384 + TEST2(scheduler.DisableSchedule(ref.iHandle), KErrNone);
1.385 + // Associate a task with the schedule
1.386 + _LIT(KTaskInfo, "DEF061595");
1.387 + TTaskInfo taskInfo;
1.388 + taskInfo.iRepeat = 0;
1.389 + taskInfo.iName = KTaskInfo;
1.390 + taskInfo.iPriority = 2;
1.391 + const TInt KTaskDataLen = 1;
1.392 + HBufC* taskData = HBufC::NewLC(KTaskDataLen);
1.393 + TEST2(scheduler.ScheduleTask(taskInfo, *taskData, ref.iHandle), KErrNone);
1.394 + //We should now have one tasks scheduled to be executed after 1 year.
1.395 + //Enable schedule.
1.396 + TEST2(scheduler.EnableSchedule(ref.iHandle), KErrNone);
1.397 + //Get the scheduled task info. The task year should be the same as it was set in the schedule.
1.398 + TTime nextTime;
1.399 + TPtr pTaskData = taskData->Des();
1.400 + TEST2(scheduler.GetTaskInfoL(taskInfo.iTaskId, taskInfo, pTaskData, ref, nextTime), KErrNone);
1.401 + TInt nextTaskYear = nextTime.DateTime().Year();
1.402 + TEST(nextTaskYear == taskYear);
1.403 + //Change the system time to be current time + 1 day
1.404 + TEST2(SchSvrHelpers::SetUTCTimeL(currTime + TTimeIntervalDays(1)), KErrNone);
1.405 + //Get the scheduled task info again. If the defect is not fixed, the call will fail
1.406 + //with KErrNotFound (because SchSvrHelpers::SetUTCTimeL() call will make the schedule timer to expire)
1.407 + TInt err = scheduler.GetTaskInfoL(taskInfo.iTaskId, taskInfo, pTaskData, ref, nextTime);
1.408 +//TODO TEST2(err, KErrNone);
1.409 +//TODO nextTaskYear = nextTime.DateTime().Year();
1.410 +//TODO TEST(nextTaskYear == taskYear);
1.411 +
1.412 + CleanupStack::PopAndDestroy(taskData);
1.413 + CleanupStack::PopAndDestroy(&scheduler);
1.414 + CleanupHelpers::KillProcess(KMinimalTaskHandler);
1.415 + }
1.416 +
1.417 +/**
1.418 +@SYMTestCaseID SYSLIB-SCHSVR-CT-1655
1.419 +@SYMTestCaseDesc Tests for defect number DEF079983
1.420 +@SYMTestPriority High
1.421 +@SYMTestActions Check to ensure all task files have been cleaned up
1.422 + after scheduled tasks completed
1.423 +@SYMTestExpectedResults Test must not fail
1.424 +@SYMDEF DEF079983
1.425 +*/
1.426 +static void DEF079983L()
1.427 + {
1.428 + TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-1655 DEF079983: Private directory of schsvr flooded with files "));
1.429 + // A dummy scheduled task:
1.430 + // Create some transient schedule task and repeat 5 times
1.431 + TheTest.Printf(_L("DEF079983: Create a dummy scheduled task"));
1.432 + TInt tTask = 0;
1.433 + TSchedulerItemRef ref;
1.434 + // 5 repeats
1.435 + TInt res = ScheduleTransientTaskL(tTask, ref, 5, TheScheduler);
1.436 + TEST2(res, KErrNone);
1.437 + ForceTaskExecutionForSpecifiedIdL(ref.iHandle, 5);
1.438 +
1.439 + // Check for left task files after scheduled tasks completed
1.440 + // To access private data cage, uses SchSvrHelplers::CheckTaskFilesL()
1.441 + TheTest.Next(_L("DEF079983: Now checking no files left when tasks completed"));
1.442 + TInt err = SchSvrHelpers::CheckTaskFilesL();
1.443 + // If there's any task files left, test fails with error code KErrGeneral
1.444 + TEST(err == KErrNone);
1.445 + }
1.446 +
1.447 +/**
1.448 +@SYMTestCaseID SYSLIB-SCHSVR-CT-3362
1.449 +@SYMTestCaseDesc Replicated test for for defect (INC098909) - UTC
1.450 +@SYMTestPriority High
1.451 +@SYMTestActions Mark heap of Scheduler then create a schedule & task wait for its
1.452 + execution then check heap again for memory leaks
1.453 +@SYMTestExpectedResults Test must not fail (i.e. No memory leaks)
1.454 +@SYMDEF INC098909: Process !TaskScheluder leaks memory in mail polls.
1.455 +*/
1.456 +static void INC098909()
1.457 + {
1.458 + const TInt KTimeToWait = 10*1000*1000;
1.459 + SchSvrHelpers::DeleteScheduleFilesL();
1.460 +
1.461 + TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-3362 INC098909: Process !TaskScheluder leaks memory in mail polls "));
1.462 + TheTest.Next(_L("Connect to Scheduler"));
1.463 + TEST2(TheScheduler.Connect(),KErrNone);
1.464 +
1.465 + TheTest.Next(_L("Registering Client"));
1.466 + TEST2(SchSvrHelpers::RegisterClientL(TheScheduler), KErrNone);
1.467 +
1.468 + User::LeaveIfError(TheScheduler.__DbgMarkHeap());
1.469 +
1.470 + //Create Schedule
1.471 + CArrayFixFlat<TScheduleEntryInfo2>* entryList = new(ELeave) CArrayFixFlat<TScheduleEntryInfo2>(1);
1.472 + CleanupStack::PushL(entryList);
1.473 + TSchedulerItemRef ref;
1.474 +
1.475 + TTsTime startTime1(SchSvrHelpers::UtcTimeBasedOnOffset(0, 0), ETrue); // 0m:0s from "now"
1.476 +
1.477 + TScheduleEntryInfo2 entry1 (startTime1, EDaily, 1, 20);
1.478 + entryList->AppendL(entry1);
1.479 +
1.480 + // Create the schedule for the task...
1.481 + TEST2(TheScheduler.CreatePersistentSchedule(ref, *entryList),KErrNone);
1.482 +
1.483 + //Create Task
1.484 + TTaskInfo task;
1.485 + task.iRepeat = 1; // repeat once
1.486 + task.iName = _L("Test ");
1.487 + task.iPriority = 100;
1.488 +
1.489 + HBufC* taskData = HBufC::NewLC(1);
1.490 + TEST2(TheScheduler.ScheduleTask(task, *taskData,ref.iHandle), KErrNone);
1.491 +
1.492 + CleanupStack::PopAndDestroy(taskData);
1.493 + CleanupStack::PopAndDestroy(entryList);
1.494 +
1.495 + //Wait schedule to complete
1.496 + User::After(KTimeToWait);
1.497 +
1.498 + User::LeaveIfError(TheScheduler.__DbgMarkEnd(0));
1.499 +
1.500 + TheScheduler.Close();
1.501 + // really clean out the scheduler (get rid of all the files and process)
1.502 + SchSvrHelpers::DeleteScheduleFilesL();
1.503 + CleanupHelpers::KillProcess(KMinimalTaskHandler);
1.504 + // Now wait for something to happen...
1.505 + TEST2(STaskSemaphore::WaitL(KDefaultTimeout), KErrNone);
1.506 + }
1.507 +
1.508 +GLDEF_C TInt DoTheTestsL()
1.509 + {
1.510 + //Delete old files.
1.511 + SchSvrHelpers::DeleteScheduleFilesL();
1.512 +
1.513 + STaskSemaphore sem;
1.514 + sem.CreateL();
1.515 +
1.516 + TheTest.Next(_L("Start tests"));
1.517 + // Add tests here:-
1.518 + Test1L();
1.519 + Test2L();
1.520 + INC098909();
1.521 + DEF055586L();
1.522 + DEF061595L();
1.523 + DEF079983L(); // task file check test
1.524 +
1.525 + sem.Close();
1.526 +
1.527 + //Tidying up so next test will be clear.
1.528 + TheTest.Next(_L("Delete all schedules"));
1.529 + SchSvrHelpers::DeleteAllSchedulesL(TheScheduler);
1.530 + SchSvrHelpers::Pause(TheTest, 2);
1.531 + TheTest.Next(_L("Delete old files\n"));
1.532 + SchSvrHelpers::DeleteScheduleFilesL();
1.533 +
1.534 + TheScheduler.Close();
1.535 +
1.536 + return KErrNone;
1.537 + }
1.538 +
1.539 +//***********************************************************************************
1.540 +GLDEF_C TInt E32Main()
1.541 + {
1.542 + __UHEAP_MARK;
1.543 + TheTest.Title();
1.544 + TheTest.Start(_L("TC_TSCH_SCHEDULING1 - UTC"));
1.545 +
1.546 + TInt error = KErrNone;
1.547 + CTrapCleanup* cleanup = CTrapCleanup::New();
1.548 + if (!cleanup)
1.549 + return KErrNoMemory;
1.550 + //If the previous test fails, SCHSVR.exe may stay in memory.
1.551 + TRAP(error,CleanupHelpers::TestCleanupL());
1.552 + TEST2(error, KErrNone);
1.553 +
1.554 + TTime now;
1.555 + now.HomeTime();
1.556 + // Used to Set the system UTC time and UTC offset
1.557 + // so that correct UTC Time values are returned while using time based APIs.
1.558 + SchSvrHelpers::SetHomeTimeL(now);
1.559 +
1.560 + TEST2(TheFsSession.Connect(), KErrNone);
1.561 + TheTest.Next(_L("Do the tests"));
1.562 + TRAP(error, DoTheTestsL());
1.563 + TEST2(error,KErrNone);
1.564 + TheFsSession.Close();
1.565 + TRAP(error,CleanupHelpers::TestCleanupL());
1.566 + TEST2(error, KErrNone);
1.567 + delete cleanup;
1.568 +
1.569 + TheTest.End();
1.570 + TheTest.Close();
1.571 + __UHEAP_MARKEND;
1.572 + return KErrNone;
1.573 + }