1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericservices/taskscheduler/Test/Scheduling/TC_TSCH_SCHEDULING2.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,1231 @@
1.4 +// Copyright (c) 2004-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 <csch_cli.h>
1.20 +#include "Thelpers.h"
1.21 +
1.22 +#include <e32base.h>
1.23 +#include <e32test.h>
1.24 +#include <f32file.h>
1.25 +#include <s32file.h>
1.26 +
1.27 +#include "TestUtils.h"
1.28 +
1.29 +
1.30 +//If suddenly all SCHSVR tests begin failing, the OOM conditions might be the reason.
1.31 +//TScheduling test tries to create KNumberOfSchedulesToCreate tasks, loading enormously
1.32 +//the task scheduling server. The task scheduling server fails and stays loaded in memory
1.33 +//with many scheduling tasks holding large amounts of allocated memory in this way.
1.34 +//The next SCHSVR tests may fail because of OOM.
1.35 +//KNumberOfSchedulesToCreate value was 100 originally. Now it is 20.
1.36 +
1.37 +//
1.38 +// Literal constants
1.39 +//
1.40 +_LIT(KTestName, "TC_TSCH_SCHEDULING2");
1.41 +
1.42 +//
1.43 +// Type definitions
1.44 +//
1.45 +typedef CArrayFixFlat<TScheduleEntryInfo> CSchEntryInfoArray;
1.46 +typedef CArrayFixFlat<TTaskInfo> CTaskInfoArray;
1.47 +typedef CArrayFixFlat<TSchedulerItemRef> CSchItemRefArray;
1.48 +
1.49 +//
1.50 +// Global data
1.51 +//
1.52 +RTest TheTest(KTestName);
1.53 +static TInt64 TheSeed;
1.54 +static RScheduler TheScheduler;
1.55 +static CTrapCleanup* TheCleanup;
1.56 +static RFs TheFsSession;
1.57 +
1.58 +_LIT(KMinimalTaskHandler, "MinimalTaskHandler");
1.59 +
1.60 +
1.61 +//***********************************************************************************
1.62 +// Extract task info from the schedule server based on a schedule ID
1.63 +static void GetTaskInfoL(CTaskInfoArray& aTaskInfoArray,
1.64 + TInt aScheduleId)
1.65 + {
1.66 + aTaskInfoArray.Reset();
1.67 + TTime nextTimeScheduleIsDue;
1.68 + TScheduleState state;
1.69 + CSchEntryInfoArray* entries
1.70 + = new (ELeave) CSchEntryInfoArray(3);
1.71 + CleanupStack::PushL(entries);
1.72 + TInt res = TheScheduler.GetScheduleL(aScheduleId,
1.73 + state,
1.74 + *entries,
1.75 + aTaskInfoArray,
1.76 + nextTimeScheduleIsDue);
1.77 + TEST2(res, KErrNone);
1.78 + CleanupStack::PopAndDestroy(entries);
1.79 + }
1.80 +
1.81 +// count the number of tasks associated with this schedule
1.82 +static TInt CountTasksL(TInt aScheduleId)
1.83 + {
1.84 + CTaskInfoArray* tasks = new (ELeave) CTaskInfoArray(3);
1.85 + CleanupStack::PushL(tasks);
1.86 + GetTaskInfoL(*tasks, aScheduleId);
1.87 + TInt ret = tasks->Count();
1.88 + CleanupStack::PopAndDestroy(tasks);
1.89 + return ret;
1.90 + }
1.91 +
1.92 +// count the number of schedules based on a filter.
1.93 +static TInt CountScheduledItemsL(TScheduleFilter aFilter,
1.94 + RScheduler& aScheduler)
1.95 + {
1.96 + CSchItemRefArray* refs = new (ELeave) CSchItemRefArray(3);
1.97 + CleanupStack::PushL(refs);
1.98 +
1.99 + TInt res = aScheduler.GetScheduleRefsL(*refs, aFilter);
1.100 + TEST2(res, KErrNone);
1.101 +
1.102 + TInt count = refs->Count();
1.103 + CleanupStack::PopAndDestroy(); // refs
1.104 + return count;
1.105 + }
1.106 +
1.107 +//creates a daily schedule with StartTime of aStartTime
1.108 +static TInt CreateScheduleL(TSchedulerItemRef& aRef,
1.109 + RScheduler& aScheduler,
1.110 + const TTime& aStartTime)
1.111 + {
1.112 + CSchEntryInfoArray* entryList
1.113 + = new (ELeave) CSchEntryInfoArray(1);
1.114 + CleanupStack::PushL(entryList);
1.115 +
1.116 + TScheduleEntryInfo entry1;
1.117 + entry1.iStartTime = aStartTime;
1.118 + entry1.iInterval = 1; // TTimeIntervalDays
1.119 + entry1.iIntervalType = EDaily;
1.120 + entry1.iValidityPeriod = 30; // minutes
1.121 + entryList->AppendL(entry1);
1.122 + TInt res = aScheduler.CreatePersistentSchedule(aRef, *entryList);
1.123 + CleanupStack::PopAndDestroy(); // entryList
1.124 + return res;
1.125 + }
1.126 +
1.127 +// creates a schedule with numerous entries
1.128 +static TInt CreateSchedule1L(TSchedulerItemRef& aRef, RScheduler& aScheduler)
1.129 + {
1.130 + aRef.iName = _L("Schedule created using \"CreateSchedule1L\"");
1.131 +
1.132 + CSchEntryInfoArray* entryList = new (ELeave) CSchEntryInfoArray(3);
1.133 + CleanupStack::PushL(entryList);
1.134 +
1.135 + {
1.136 + TScheduleEntryInfo entry1;
1.137 + entry1.iStartTime = SchSvrHelpers::TimeBasedOnOffset(20, 0); // 0m:20s from "now"
1.138 + entry1.iInterval = 1;
1.139 + entry1.iIntervalType = EDaily;
1.140 + entry1.iValidityPeriod = 20;
1.141 + entryList->AppendL(entry1);
1.142 + }
1.143 + {
1.144 + TScheduleEntryInfo entry2;
1.145 + entry2.iStartTime = SchSvrHelpers::TimeBasedOnOffset(00, 1); // 1m:00s from "now"
1.146 + entry2.iInterval = 1;
1.147 + entry2.iIntervalType = EDaily;
1.148 + entry2.iValidityPeriod = 20;
1.149 + entryList->AppendL(entry2);
1.150 + }
1.151 + {
1.152 + TScheduleEntryInfo entry3;
1.153 + entry3.iStartTime = SchSvrHelpers::TimeBasedOnOffset(0, 0, 0, 0, 0, -1); // -1 year from "now"
1.154 + entry3.iInterval = 1;
1.155 + entry3.iIntervalType = EDaily;
1.156 + entry3.iValidityPeriod = 20;
1.157 + entryList->AppendL(entry3);
1.158 + }
1.159 +
1.160 + TInt res = aScheduler.CreatePersistentSchedule(aRef, *entryList);
1.161 + CleanupStack::PopAndDestroy(); // entryList
1.162 + return res;
1.163 + }
1.164 +
1.165 +// creates a schedule with numerous entries
1.166 +static TInt CreateSchedule2L(TSchedulerItemRef& aRef, RScheduler& aScheduler)
1.167 + {
1.168 + CSchEntryInfoArray* entryList = new (ELeave) CSchEntryInfoArray(3);
1.169 + CleanupStack::PushL(entryList);
1.170 +
1.171 + aRef.iName = _L("Schedule created using \"CreateSchedule2L\"");
1.172 +
1.173 + {
1.174 + TScheduleEntryInfo entry1;
1.175 + entry1.iStartTime = SchSvrHelpers::TimeBasedOnOffset(30, 2); // 2m:30s from "now"
1.176 + entry1.iInterval = 1;
1.177 + entry1.iIntervalType = EDaily;
1.178 + entry1.iValidityPeriod = 20;
1.179 + entryList->AppendL(entry1);
1.180 + }
1.181 + {
1.182 + TScheduleEntryInfo entry2;
1.183 + entry2.iStartTime = SchSvrHelpers::TimeBasedOnOffset(0, 5); // 5m:00s from "now"
1.184 + entry2.iInterval = 1;
1.185 + entry2.iIntervalType = EDaily;
1.186 + entry2.iValidityPeriod = 20;
1.187 + entryList->AppendL(entry2);
1.188 + }
1.189 +
1.190 + TInt res = aScheduler.CreatePersistentSchedule(aRef, *entryList);
1.191 + CleanupStack::PopAndDestroy(); // entryList
1.192 + return res;
1.193 + }
1.194 +
1.195 +// creates a schedule with numerous entries
1.196 +static TInt CreateSchedule3L(TSchedulerItemRef& aRef, RScheduler& aScheduler)
1.197 + {
1.198 + CSchEntryInfoArray* entryList = new (ELeave) CSchEntryInfoArray(3);
1.199 + CleanupStack::PushL(entryList);
1.200 +
1.201 + aRef.iName = _L("Schedule created using \"CreateSchedule3L\"");
1.202 +
1.203 + {
1.204 + TScheduleEntryInfo entry1;
1.205 + entry1.iIntervalType = EDaily;
1.206 + entry1.iInterval = 1; // repeat every day
1.207 + entry1.iValidityPeriod = 5; // valid for only 5 minutes
1.208 + entry1.iStartTime = SchSvrHelpers::TimeBasedOnOffset(0, 9, 0, 20); // 9mins and 20days in the future
1.209 + entryList->AppendL(entry1);
1.210 + }
1.211 +
1.212 + {
1.213 + TScheduleEntryInfo entry2;
1.214 + entry2.iIntervalType = EDaily;
1.215 + entry2.iInterval = 1;
1.216 + entry2.iValidityPeriod = 5;
1.217 + entry2.iStartTime = SchSvrHelpers::TimeBasedOnOffset(0, 11, 0, 20); // 11mins and 20days in the future
1.218 + entryList->AppendL(entry2);
1.219 + }
1.220 +
1.221 + TInt res = aScheduler.CreatePersistentSchedule(aRef, *entryList);
1.222 + CleanupStack::PopAndDestroy(); // entryList
1.223 +
1.224 + return res;
1.225 + }
1.226 +
1.227 +// schedules a persistent task associated with the supplied schedule ID
1.228 +static TInt SchedulePersistentTaskL(const TName& aName,
1.229 + TInt& aNewId,
1.230 + TInt aScheduleId,
1.231 + TInt aRepeat,
1.232 + RScheduler& aScheduler)
1.233 + {
1.234 + TTaskInfo taskInfo;
1.235 + taskInfo.iTaskId = aNewId;
1.236 + taskInfo.iName = aName;
1.237 + taskInfo.iPriority = 2;
1.238 + taskInfo.iRepeat = aRepeat;
1.239 + HBufC* data = _L("the data").AllocLC();
1.240 + TInt res = aScheduler.ScheduleTask(taskInfo, *data, aScheduleId);
1.241 + aNewId = taskInfo.iTaskId;
1.242 +
1.243 + CleanupStack::PopAndDestroy(); // data
1.244 + return res;
1.245 + }
1.246 +
1.247 +/**
1.248 +@SYMTestCaseID SYSLIB-SCHSVR-CT-1033
1.249 +@SYMTestCaseDesc Test 1 - verifies fix for defect:
1.250 + Registering twice with the task scheduler causes a memory leak(EDNAWIR-4FQJ6A)
1.251 +@SYMTestPriority High
1.252 +@SYMTestActions Connect to scheduler and register twice with the task scheduler.Check for memory errors,
1.253 +@SYMTestExpectedResults Test must not fail
1.254 +@SYMREQ REQ0000
1.255 +*/
1.256 +static void Test1L()
1.257 + {
1.258 + TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-1033 TheTest1: Registering with the tasks scheduler without disconnecting "));
1.259 + __UHEAP_MARK;
1.260 + TheTest.Next(_L("Connect to Scheduler"));
1.261 + TInt res = TheScheduler.Connect();
1.262 + TEST2(res, KErrNone);
1.263 +
1.264 + TheTest.Next(_L("Registering Client"));
1.265 + TEST2(SchSvrHelpers::RegisterClientL(TheScheduler), KErrNone);
1.266 +
1.267 + TheScheduler.Close();
1.268 + __UHEAP_MARKEND;
1.269 +
1.270 + __UHEAP_MARK;
1.271 + TheTest.Next(_L("Connect to Scheduler again"));
1.272 + res = TheScheduler.Connect();
1.273 + TEST2(res, KErrNone);
1.274 +
1.275 + TheTest.Next(_L("Registering client again"));
1.276 + TEST2(SchSvrHelpers::RegisterClientL(TheScheduler), KErrNone);
1.277 + TheScheduler.__DbgMarkHeap();
1.278 +
1.279 + TheTest.Next(_L("Register when already registered"));
1.280 + TEST2(SchSvrHelpers::RegisterClientL(TheScheduler), KErrNone);
1.281 +
1.282 + TheTest.Next(_L("Cancel registering client and check for memory leak"));
1.283 + TheScheduler.__DbgMarkEnd(0);
1.284 + TheScheduler.Close();
1.285 + __UHEAP_MARKEND;
1.286 + }
1.287 +
1.288 +/**
1.289 +@SYMTestCaseID SYSLIB-SCHSVR-CT-1034
1.290 +@SYMTestCaseDesc Test 2 - verifies fix for defect
1.291 + Messages with "Resend" status are not sent after reboot (EDNHLJT-4TRAAE)
1.292 +@SYMTestPriority High
1.293 +@SYMTestActions Add a task to the schedule,kill the server and re-register the client,wait for one minute for task to fire
1.294 +@SYMTestExpectedResults Test must not fail
1.295 +@SYMREQ REQ0000
1.296 +*/
1.297 +static void Test2L()
1.298 +//
1.299 +//
1.300 + {
1.301 + TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-1034 TheTest2: Resend after hard reset (simulation) "));
1.302 +
1.303 + TheTest.Next(_L("Connect to Scheduler"));
1.304 + TInt res = TheScheduler.Connect();
1.305 + TEST2(res, KErrNone);
1.306 +
1.307 + TheTest.Next(_L("Registering Client"));
1.308 + TEST2(SchSvrHelpers::RegisterClientL(TheScheduler), KErrNone);
1.309 +
1.310 + // Create a schedule
1.311 + TheTest.Next(_L("Creating schedule"));
1.312 + TSchedulerItemRef scheduleHandle;
1.313 + TTime time;
1.314 + time.HomeTime();
1.315 + time += TTimeIntervalSeconds(2); //Task to go off two seconds from now
1.316 + User::LeaveIfError(CreateScheduleL(scheduleHandle, TheScheduler, time));
1.317 +
1.318 + // Add a task to the schedule
1.319 + TheTest.Next(_L("Creating task for schedule"));
1.320 + {
1.321 + TTaskInfo taskInfo;
1.322 + taskInfo.iName = _L("MyTaskName");
1.323 + taskInfo.iPriority = 2;
1.324 + taskInfo.iTaskId = 0;
1.325 + taskInfo.iRepeat = 1;
1.326 + HBufC* data = _L("Task Data").AllocLC();
1.327 + TInt res = TheScheduler.ScheduleTask(taskInfo, *data, scheduleHandle.iHandle);
1.328 + CleanupStack::PopAndDestroy(); // data
1.329 + TEST2(res, KErrNone);
1.330 + }
1.331 +
1.332 + // Kill the server !!
1.333 + TheTest.Next(_L("Killing server"));
1.334 + // Need to turn off JIT dubugging as we are panicking server and we
1.335 + // want test to keep running.
1.336 + TBool jit = User::JustInTime();
1.337 + User::SetJustInTime(EFalse);
1.338 +
1.339 + TheScheduler.__FaultServer();
1.340 + User::After(100000);
1.341 +
1.342 + // Turn on JIT again.
1.343 + User::SetJustInTime(jit);
1.344 +
1.345 + // Connect to the server again
1.346 + TheTest.Next(_L("Re-connect to Scheduler"));
1.347 + res = TheScheduler.Connect();
1.348 + TEST2(res, KErrNone);
1.349 +
1.350 + // Re-register
1.351 + TheTest.Next(_L("Re-register Client"));
1.352 + TEST2(SchSvrHelpers::RegisterClientL(TheScheduler), KErrNone);
1.353 +
1.354 + TheTest.Next(_L("Check schedule count and task count"));
1.355 + TInt scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
1.356 + TEST(scheduleCount == 1);
1.357 + TInt taskCount = CountTasksL(scheduleHandle.iHandle);
1.358 + TEST(taskCount == 1);
1.359 +
1.360 + // Wait for task to fire... It should happen in about 2 seconds
1.361 + TheTest.Next(_L("Waiting for task to complete"));
1.362 + TEST2(STaskSemaphore::WaitL(KDefaultTimeout), KErrNone);
1.363 + CleanupHelpers::KillProcess(KMinimalTaskHandler);
1.364 + }
1.365 +
1.366 +/**
1.367 +@SYMTestCaseID SYSLIB-SCHSVR-CT-1035
1.368 +@SYMTestCaseDesc This test establishes that the change to RScheduler::GetScheduleL is functionally correct
1.369 +@SYMTestPriority High
1.370 +@SYMTestActions Tests changes to Schedule Server API as of Change Request document AALR-4EDG75
1.371 +@SYMTestExpectedResults Test must not fail
1.372 +@SYMREQ REQ0000
1.373 +*/
1.374 +static void Test3L()
1.375 + {
1.376 + //
1.377 + //
1.378 + // Test changes to Schedule Server API as of Change Request document AALR-4EDG75
1.379 + // (GT change requests database)
1.380 + //
1.381 + //
1.382 + //
1.383 + // This test establishes that the change to...
1.384 + //
1.385 + // RScheduler::GetScheduleL(const TInt aScheduleHandle,
1.386 + // TScheduleState& aState,
1.387 + // CArrayFixFlat<TScheduleEntryInfo>& aEntries,
1.388 + // CArrayFixFlat<TTaskInfo>& aTasks,
1.389 + // TTime& aNextDue)
1.390 + //
1.391 + // ...is functionally correct.
1.392 + //
1.393 + //
1.394 + TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-1035 Test change request AALR-4EDG75 implementation "));
1.395 +
1.396 + TheTest.Next(_L("Connect to Scheduler"));
1.397 + TInt res = TheScheduler.Connect();
1.398 + TEST2(res, KErrNone);
1.399 +
1.400 + TheTest.Next(_L("Registering Client"));
1.401 + TEST2(SchSvrHelpers::RegisterClientL(TheScheduler), KErrNone);
1.402 +
1.403 + const TDateTime KTimeToStartTask(2000, EJanuary, 10, 15, 30, 0, 0);
1.404 +
1.405 + TSchedulerItemRef schedulerItemReference;
1.406 + CSchEntryInfoArray* entryArray = new(ELeave) CSchEntryInfoArray(1);
1.407 + CleanupStack::PushL(entryArray);
1.408 +
1.409 + HBufC* taskData = _L("This is some dummy task data created for testing").AllocL();
1.410 + CleanupStack::PushL(taskData);
1.411 +
1.412 + // Prepare the task info - this describes the tasks that are contained within the task
1.413 + // entry array
1.414 + TTaskInfo taskInfo = SchSvrHelpers::TaskInfo(_L("A transient test task"), 100);
1.415 +
1.416 + // Create a schedule entry and append it to the entry array
1.417 + {
1.418 + TScheduleEntryInfo scheduleEntry = SchSvrHelpers::ScheduleEntryInfo(EDaily, TTime(KTimeToStartTask), 7, 2);
1.419 + entryArray->AppendL(scheduleEntry);
1.420 + }
1.421 +
1.422 + // Create the transient task
1.423 + TInt ret = TheScheduler.ScheduleTask(taskInfo, *taskData, schedulerItemReference, *entryArray);
1.424 + TEST2(ret, KErrNone);
1.425 +
1.426 + // Check that the task Id after scheduling the event is not
1.427 + // the same as it was prior to the requesting the service
1.428 + TEST(taskInfo.iTaskId != -1);
1.429 +
1.430 + //
1.431 + // Now obtain info about the scheduled transient task...
1.432 + //
1.433 + TScheduleState scheduleState;
1.434 + TTime nextTaskDueTime;
1.435 +
1.436 + // Reset the schedule entry info array as the server now has copies of this and it is
1.437 + // no longer required client-side
1.438 + entryArray->Reset();
1.439 + CTaskInfoArray* taskInfoArray = new(ELeave) CTaskInfoArray(4);
1.440 + CleanupStack::PushL(taskInfoArray);
1.441 +
1.442 + // Request task schedule information from the server
1.443 + ret = TheScheduler.GetScheduleL(schedulerItemReference.iHandle, scheduleState, *entryArray, *taskInfoArray, nextTaskDueTime);
1.444 + TEST2(ret, KErrNone);
1.445 +
1.446 + // Because this is a daily task which is scheduled to occur at a specific time (but the date
1.447 + // cannot necessarily be established, we can perform a simple check to ensure that the
1.448 + // time when the task is next scheduled to run falls within the 15:30 - 17:30 bracket.
1.449 + TEST(SchSvrHelpers::IsTimeTheSame(nextTaskDueTime, TTime(KTimeToStartTask)) == (TInt) ETrue);
1.450 +
1.451 + // Establish and test the size of the task data for the specified task object
1.452 + TInt sizeOfTaskData = 0;
1.453 + TEST2(TheScheduler.GetTaskDataSize(taskInfo.iTaskId, sizeOfTaskData), KErrNone);
1.454 + TEST(sizeOfTaskData == taskData->Length());
1.455 +
1.456 + // Now check the information return from the server pertaining to a specific task...
1.457 + {
1.458 + TTaskInfo taskFromServer;
1.459 + HBufC* taskDataFromServer = HBufC::NewLC(sizeOfTaskData);
1.460 + TPtr pTaskDataFromServer = taskDataFromServer->Des();
1.461 + TTime nextDueTimeFromServer = Time::NullTTime();
1.462 + TSchedulerItemRef schedulerRefFromServer;
1.463 + TEST2(TheScheduler.GetTaskInfoL(taskInfo.iTaskId, taskFromServer, pTaskDataFromServer, schedulerRefFromServer, nextDueTimeFromServer), KErrNone);
1.464 + TEST(SchSvrHelpers::IsTimeTheSame(nextTaskDueTime, TTime(KTimeToStartTask)) == (TInt) ETrue);
1.465 + TEST(SchSvrHelpers::IsTaskInfoTheSame(taskFromServer, taskInfo) == (TInt) ETrue);
1.466 + TEST(SchSvrHelpers::IsItemRefTheSame(schedulerRefFromServer, schedulerItemReference) == (TInt) ETrue);
1.467 + CleanupStack::PopAndDestroy(); // taskDataFromServer
1.468 + }
1.469 +
1.470 + // Disable the schedule and check when it is next schedule to run
1.471 + TEST2(TheScheduler.DisableSchedule(schedulerItemReference.iHandle), KErrNone);
1.472 +
1.473 + // Get the new schedule info - check that the nextDueTime is still reported even
1.474 + // though the schedule has been disabled
1.475 + nextTaskDueTime = Time::NullTTime();
1.476 + TEST2(TheScheduler.GetScheduleL(schedulerItemReference.iHandle, scheduleState, *entryArray, *taskInfoArray, nextTaskDueTime), KErrNone);
1.477 + TEST(SchSvrHelpers::IsTimeTheSame(nextTaskDueTime, TTime(KTimeToStartTask)) == (TInt) ETrue);
1.478 + TEST(SchSvrHelpers::IsTaskInfoTheSame(taskInfoArray->At(0), taskInfo) == (TInt) ETrue);
1.479 +
1.480 + // Re-enable the schedule
1.481 + TEST2(TheScheduler.EnableSchedule(schedulerItemReference.iHandle), KErrNone);
1.482 +
1.483 + // Delete the only task (relating to this test) from the server
1.484 + TEST2(TheScheduler.DeleteTask(taskInfo.iTaskId), KErrNone);
1.485 + ret = TheScheduler.GetScheduleL(schedulerItemReference.iHandle, scheduleState, *entryArray, *taskInfoArray, nextTaskDueTime);
1.486 + TEST2(ret, KErrNotFound); // there is no longer any tasks associated with this schedule
1.487 +
1.488 + CleanupStack::PopAndDestroy(3); // taskInfoArray, entryArray, taskData
1.489 + }
1.490 +
1.491 +/**
1.492 +@SYMTestCaseID SYSLIB-SCHSVR-CT-1036
1.493 +@SYMTestCaseDesc Tests for defect EDNAALR-4JKEFC
1.494 +@SYMTestPriority High
1.495 +@SYMTestActions Create the schedule for the task,re-register the client with the server.
1.496 + check for the information that the scheduler knows about.
1.497 +@SYMTestExpectedResults Test must not fail
1.498 +@SYMREQ REQ0000
1.499 +*/
1.500 +static void Test4L()
1.501 + {
1.502 + // Test title
1.503 + TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-1036 \nTest for defect EDNAALR-4JKEFC "));
1.504 +
1.505 + TheTest.Next(_L("Connect to Scheduler"));
1.506 + TInt res = TheScheduler.Connect();
1.507 + TEST2(res, KErrNone);
1.508 +
1.509 + TheTest.Next(_L("Registering Client"));
1.510 + TEST2(SchSvrHelpers::RegisterClientL(TheScheduler), KErrNone);
1.511 +
1.512 + // Constants / vars used in this function
1.513 + TSchedulerItemRef itemRef;
1.514 +
1.515 + // Create some scheduling entries
1.516 + CArrayFixFlat<TScheduleEntryInfo>* entries = new(ELeave) CArrayFixFlat<TScheduleEntryInfo>(10);
1.517 + CleanupStack::PushL(entries);
1.518 +
1.519 + TScheduleEntryInfo entry1;
1.520 + entry1.iIntervalType = EHourly;
1.521 + entry1.iStartTime = SchSvrHelpers::TimeBasedOnOffset(1, 1); // 1m:01s from "now"
1.522 + entry1.iInterval = 1;
1.523 + entry1.iValidityPeriod = 20;
1.524 + entries->AppendL(entry1);
1.525 +
1.526 + TScheduleEntryInfo entry2;
1.527 + entry2.iIntervalType = EHourly;
1.528 + entry2.iStartTime = SchSvrHelpers::TimeBasedOnOffset(5, 5); // 5m:05s from "now"
1.529 + entry2.iInterval = 1;
1.530 + entry2.iValidityPeriod = 20;
1.531 + entries->AppendL(entry2);
1.532 +
1.533 + // Create the schedule for the task...
1.534 + res = TheScheduler.CreatePersistentSchedule(itemRef, *entries);
1.535 + TEST2(res, KErrNone);
1.536 +
1.537 + // Create the tasks themselves..
1.538 + TTaskInfo task;
1.539 + task.iRepeat = 10; // repeat once
1.540 + task.iName = _L("Test Task For Defect Verification");
1.541 + task.iPriority = 100;
1.542 + HBufC* taskData = task.iName.AllocLC();
1.543 + res = TheScheduler.ScheduleTask(task, *taskData, itemRef.iHandle);
1.544 + CleanupStack::PopAndDestroy(); // taskData
1.545 +
1.546 + {
1.547 + CArrayFixFlat<TSchedulerItemRef>* refs = new CArrayFixFlat<TSchedulerItemRef>(3);
1.548 + CleanupStack::PushL(refs);
1.549 + TInt res = TheScheduler.GetScheduleRefsL(*refs, EAllSchedules);
1.550 + TEST2(res, KErrNone);
1.551 + CleanupStack::PopAndDestroy(); // refs
1.552 + }
1.553 +
1.554 + // Re-register theclient with the server
1.555 + for(TInt i=0; i<5; i++)
1.556 + {
1.557 + // Log off from the task scheduler
1.558 + TheScheduler.Close();
1.559 + res = TheScheduler.Connect();
1.560 + TEST2(res, KErrNone);
1.561 +
1.562 + User::After(1000000);
1.563 +
1.564 + TheTest.Next(_L("===== Re-registering Client (wait 10 secs) ====="));
1.565 + res = SchSvrHelpers::RegisterClientL(TheScheduler);
1.566 + TEST2(res, KErrNone);
1.567 + {
1.568 + CArrayFixFlat<TSchedulerItemRef>* refs = new CArrayFixFlat<TSchedulerItemRef>(3);
1.569 + CleanupStack::PushL(refs);
1.570 + TInt res = TheScheduler.GetScheduleRefsL(*refs, EAllSchedules);
1.571 + TEST2(res, 0);
1.572 + CleanupStack::PopAndDestroy(); // refs
1.573 + }
1.574 +
1.575 + // Check the information that the scheduler knows about...
1.576 + TInt taskDataSize = 0;
1.577 + res = TheScheduler.GetTaskDataSize(task.iTaskId, taskDataSize);
1.578 + TEST2(res, KErrNone);
1.579 + TEST(taskDataSize == task.iName.Length());
1.580 + TTaskInfo taskInfoFromServer;
1.581 + taskData = HBufC::NewLC(taskDataSize);
1.582 + TPtr pTaskData = taskData->Des();
1.583 +
1.584 + TTime nextDueTime(Time::NullTTime());
1.585 + res = TheScheduler.GetTaskInfoL(task.iTaskId, taskInfoFromServer, pTaskData, itemRef, nextDueTime);
1.586 + TEST2(res, KErrNone);
1.587 + TEST(pTaskData == task.iName);
1.588 + CleanupStack::PopAndDestroy(); // taskData
1.589 + }
1.590 +
1.591 + CleanupStack::PopAndDestroy(); // entries
1.592 +
1.593 + }
1.594 +
1.595 +/**
1.596 +@SYMTestCaseID SYSLIB-SCHSVR-CT-1037
1.597 +@SYMTestCaseDesc Tests for basic scheduler implementations
1.598 +@SYMTestPriority High
1.599 +@SYMTestActions Mark heap,create persistent schedules, schedule tasks,transient schedules,
1.600 + delete tasks,delete remaing schedules,check heap
1.601 +@SYMTestExpectedResults Test must not fail
1.602 +@SYMREQ REQ0000
1.603 +*/
1.604 +static void Test5L()
1.605 + {
1.606 + TInt res = KErrNone;
1.607 + TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-1037 ===== Starting test 1 ====="));
1.608 + __UHEAP_MARK;
1.609 +
1.610 + TSchedulerItemRef ref1;
1.611 + TSchedulerItemRef ref2;
1.612 + TSchedulerItemRef ref3;
1.613 +
1.614 + // Remove all existing schedules before starting the test
1.615 + SchSvrHelpers::DeleteAllSchedulesL(TheScheduler);
1.616 +
1.617 + TInt scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
1.618 + TEST(scheduleCount == 0); // check that no schedules are present.
1.619 +
1.620 + TheTest.Printf(_L("Create some schedules\n"));
1.621 + res = CreateSchedule1L(ref1, TheScheduler); // +20sec, +1min, -1year
1.622 + TEST2(res, KErrNone);
1.623 + res = CreateSchedule2L(ref2, TheScheduler); // +2min 30sec, +5min
1.624 + TEST2(res, KErrNone);
1.625 + res = CreateSchedule3L(ref3, TheScheduler); // +20day 9min, +20day 11min
1.626 + TEST2(res, KErrNone);
1.627 +
1.628 + TSchedulerItemRef ref4;
1.629 + TSchedulerItemRef ref5;
1.630 + res = CreateSchedule2L(ref4, TheScheduler); // +2min 30sec, 5min
1.631 + TEST2(res, KErrNone);
1.632 + res = CreateSchedule3L(ref5, TheScheduler); // +20day 9min, +20day 11min
1.633 + TEST2(res, KErrNone);
1.634 +
1.635 + TInt task1 = 0;
1.636 + TInt task2 = 0;
1.637 + TInt task3 = 0;
1.638 + TInt task4 = 0;
1.639 + TName name1 = (_L("web subscription"));
1.640 + TName name2 = (_L("another web subscription"));
1.641 + TName name3 = (_L("third web subscription"));
1.642 +
1.643 + TheTest.Printf(_L("Schedule some tasks\n"));
1.644 +
1.645 + // NOTE: have to put repeats here of > 0 otherwise the task will run immediately
1.646 + // (because it's schedule specifies a date of 1 year in the past!) and be
1.647 + // removed (by the server) before we have a chance to delete it....
1.648 + res = SchedulePersistentTaskL(name1, task1, ref1.iHandle, 3, TheScheduler);
1.649 + TEST2(res, KErrNone);
1.650 + res = SchedulePersistentTaskL(name2, task2, ref2.iHandle, 3, TheScheduler);
1.651 + TEST2(res, KErrNone);
1.652 + res = SchedulePersistentTaskL(name3, task3, ref3.iHandle, 3, TheScheduler);
1.653 + TEST2(res, KErrNone);
1.654 + res = SchedulePersistentTaskL(name3, task4, ref3.iHandle, 3, TheScheduler);
1.655 + TEST2(res, KErrNone);
1.656 +
1.657 + scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
1.658 + TEST(scheduleCount == 5); // 5 persistant
1.659 + CleanupHelpers::KillProcess(KMinimalTaskHandler);
1.660 +
1.661 + TheTest.Printf(_L("Deleting task with id %d\n"), task1);
1.662 + res = TheScheduler.DeleteTask(task1);
1.663 + TEST2(res, KErrNone);
1.664 + TheTest.Printf(_L("Deleting schedule with id %d\n"), ref1.iHandle);
1.665 + res = TheScheduler.DeleteSchedule(ref1.iHandle);
1.666 + TEST2(res, KErrNone);
1.667 + scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
1.668 + // 4 persistant expected as we have deleted one
1.669 + TEST(scheduleCount == 4);
1.670 +
1.671 + TheTest.Printf(_L("Deleting task with id %d\n"), task2);
1.672 + res = TheScheduler.DeleteTask(task2);
1.673 + TEST2(res, KErrNone);
1.674 + TheTest.Printf(_L("Deleting schedule with id %d\n"), ref2.iHandle);
1.675 + res = TheScheduler.DeleteSchedule(ref2.iHandle);
1.676 + TEST2(res, KErrNone);
1.677 + scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
1.678 + // 3 persistant expected as we have deleted one
1.679 + TEST(scheduleCount == 3);
1.680 +
1.681 + TheTest.Printf(_L("Deleting task with id %d\n"), task3);
1.682 + res = TheScheduler.DeleteTask(task3);
1.683 + TEST2(res, KErrNone);
1.684 + TheTest.Printf(_L("Deleting task with id %d\n"), task4);
1.685 + res = TheScheduler.DeleteTask(task4);
1.686 + TEST2(res, KErrNone);
1.687 + TheTest.Printf(_L("Deleting schedule with id %d\n"), ref3.iHandle);
1.688 + res = TheScheduler.DeleteSchedule(ref3.iHandle);
1.689 + TEST2(res, KErrNone);
1.690 + scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
1.691 + // 2 persistant expected as we have deleted one
1.692 + TEST(scheduleCount == 2);
1.693 +
1.694 + TheTest.Printf(_L("Deleting schedule with id %d\n"), ref4.iHandle);
1.695 + res = TheScheduler.DeleteSchedule(ref4.iHandle);
1.696 + TEST2(res, KErrNone);
1.697 + TheTest.Printf(_L("Deleting schedule with id %d\n"), ref5.iHandle);
1.698 + res = TheScheduler.DeleteSchedule(ref5.iHandle);
1.699 + TEST2(res, KErrNone);
1.700 +
1.701 + scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
1.702 + TEST(scheduleCount == 0);
1.703 +
1.704 + SchSvrHelpers::Pause(TheTest);
1.705 + __UHEAP_MARKEND;
1.706 + }
1.707 +
1.708 +/**
1.709 +@SYMTestCaseID SYSLIB-SCHSVR-CT-1038
1.710 +@SYMTestCaseDesc Tests for Transient,non-repeating - waits for schedule to activate
1.711 +@SYMTestPriority High
1.712 +@SYMTestActions Create transient schedule with non-repeating task
1.713 + Tests for no items as schedule deletes itself after task has completed
1.714 +@SYMTestExpectedResults Test must not fail
1.715 +@SYMREQ REQ0000
1.716 +*/
1.717 +static void Test6L()
1.718 + {
1.719 + // Heap testing removed because this is a flakey bit of code.
1.720 + TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-1038 Transient, non-repeating - waits for schedule to activate "));
1.721 +
1.722 + // Remove all existing schedules before starting the test
1.723 + SchSvrHelpers::DeleteAllSchedulesL(TheScheduler);
1.724 +
1.725 + // Create transient schedule
1.726 + TheTest.Printf(_L("Create transient schedule with non-repeating task\n"));
1.727 + TSchedulerItemRef ref;
1.728 + CSchEntryInfoArray* entryList = new(ELeave) CSchEntryInfoArray(1);
1.729 + CleanupStack::PushL(entryList);
1.730 + ref.iName = _L("A Transient Schedule");
1.731 +
1.732 + // Create schedule entry
1.733 + TScheduleEntryInfo entry;
1.734 + entry.iStartTime = SchSvrHelpers::TimeBasedOnOffset(5); // 5 secs in the future
1.735 + entry.iInterval = 1;
1.736 + entry.iIntervalType = EDaily;
1.737 + entry.iValidityPeriod = 20;
1.738 + entryList->AppendL(entry);
1.739 +
1.740 + // Create schedule task
1.741 + TTaskInfo taskInfo;
1.742 + taskInfo.iName = _L("mail");
1.743 + taskInfo.iTaskId = 0;
1.744 + taskInfo.iRepeat = 1;
1.745 + taskInfo.iPriority = 2;
1.746 + HBufC* data = _L("This is the data for the task").AllocLC();
1.747 +
1.748 + // Schedule the item
1.749 + TInt res = TheScheduler.ScheduleTask(taskInfo, *data, ref, *entryList);
1.750 + TEST2(res, KErrNone);
1.751 + CleanupStack::PopAndDestroy(2, entryList); // data, entryList
1.752 +
1.753 + // Should be one item
1.754 + TEST(CountScheduledItemsL(EAllSchedules, TheScheduler) == 1);
1.755 +
1.756 + // Waiting for entry to complete
1.757 + TheTest.Next(_L("Waiting for task to complete"));
1.758 + TEST2(STaskSemaphore::WaitL(KDefaultTimeout), KErrNone);
1.759 + CleanupHelpers::KillProcess(KMinimalTaskHandler);
1.760 + // Should be no items as schedule deletes itself after task has completed
1.761 + TEST(CountScheduledItemsL(EAllSchedules, TheScheduler) == 0);
1.762 +
1.763 + SchSvrHelpers::Pause(TheTest);
1.764 + }
1.765 +
1.766 +/**
1.767 +@SYMTestCaseID SYSLIB-SCHSVR-CT-1039
1.768 +@SYMTestCaseDesc Tests for persistent scheduling, repeating and non-repeating task schedules
1.769 +@SYMTestPriority High
1.770 +@SYMTestActions Persistent schedule,repeating task,non-repeating task,go off,check task's still there,
1.771 + go off again,check it's still there,delete task,delete schedule
1.772 +@SYMTestExpectedResults Test must not fail
1.773 +@SYMREQ REQ0000
1.774 +*/
1.775 +static void Test7L()
1.776 + {
1.777 + TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-1039 Test persistent scheduling, repeating and non-repeating task schedules "));
1.778 + SchSvrHelpers::DeleteAllSchedulesL(TheScheduler);
1.779 +
1.780 + // Transient
1.781 + TSchedulerItemRef ref;
1.782 +
1.783 + // We shouldn't have any outstanding schedules registered with the server
1.784 + TInt count = CountScheduledItemsL(EAllSchedules, TheScheduler);
1.785 + TEST(count == 0);
1.786 +
1.787 + // This creates 3 schedule entries, each with a validity period of 20 minutes, and are
1.788 + // due to run in 20s, 1m, and over a year ago (a year in the past)
1.789 + TheTest.Printf(_L("Create Persistent schedule\n"));
1.790 + TInt res = CreateSchedule1L(ref, TheScheduler);
1.791 + TEST2(res, KErrNone);
1.792 +
1.793 + // We should now have one registered schedule
1.794 + count = CountScheduledItemsL(EAllSchedules, TheScheduler);
1.795 + TEST(count == 1);
1.796 +
1.797 + //
1.798 + TheTest.Printf(_L("\nSchedule two tasks: one repeating....\n"));
1.799 + //
1.800 + TInt task1 = 0;
1.801 + TName name1 = (_L("web subscription(rpts)"));
1.802 + // -1 indicates repeating schedule
1.803 + res = SchedulePersistentTaskL(name1, task1, ref.iHandle, -1, TheScheduler); // -1 indicates repeat until explicitly deleted
1.804 + TEST2(res, KErrNone);
1.805 +
1.806 + // List those schedules that are pending
1.807 + count = CountScheduledItemsL(EPendingSchedules, TheScheduler);
1.808 + TEST(count == 1);
1.809 +
1.810 + //
1.811 + TheTest.Printf(_L("\n... and one non-repeating\n"));
1.812 + //
1.813 + TInt task2 = 0;
1.814 + TName name2 = (_L("non-repeating"));
1.815 + res = SchedulePersistentTaskL(name2, task2, ref.iHandle, 1, TheScheduler); // only runs once
1.816 + TEST2(res, KErrNone);
1.817 +
1.818 + TheTest.Printf(_L("Waiting for tasks to run\n"));
1.819 + // Wait for notification that schedule has executed.
1.820 + TEST2(STaskSemaphore::WaitL(KDefaultTimeout), KErrNone);
1.821 + CleanupHelpers::KillProcess(KMinimalTaskHandler);
1.822 +
1.823 + TheTest.Printf(_L("...and wait again for repeating one to execute again\n"));
1.824 + // Wait for notification that schedule has executed.
1.825 + TEST2(STaskSemaphore::WaitL(KDefaultTimeout), KErrNone);
1.826 + CleanupHelpers::KillProcess(KMinimalTaskHandler);
1.827 +
1.828 + TheTest.Printf(_L("Delete the repeating task, and the schedule \n"));
1.829 + res = TheScheduler.DeleteTask(task1);
1.830 + TEST2(res, KErrNone);
1.831 + res = TheScheduler.DeleteTask(task2);
1.832 + TEST2(res, KErrNotFound); //Should be not found since its only executed once.
1.833 + res = TheScheduler.DeleteSchedule(ref.iHandle);
1.834 + TEST2(res, KErrNone);
1.835 +
1.836 + count = CountScheduledItemsL(EPendingSchedules, TheScheduler);
1.837 + TEST(count == 0);
1.838 + SchSvrHelpers::Pause(TheTest);
1.839 + }
1.840 +
1.841 +
1.842 +static CSchEntryInfoArray* CreateSchEntryInfoArrayLC(TInt aGranularity)
1.843 + {
1.844 + CSchEntryInfoArray* scheduleEntries = new (ELeave) CSchEntryInfoArray(aGranularity);
1.845 + CleanupStack::PushL(scheduleEntries);
1.846 + return scheduleEntries;
1.847 + }
1.848 +
1.849 +static CArrayFixFlat<TTaskInfo>* CreateTaskInfoLC(TInt aGranularity)
1.850 + {
1.851 + CArrayFixFlat<TTaskInfo>* taskInfos = new (ELeave) CArrayFixFlat<TTaskInfo>(aGranularity);
1.852 + CleanupStack::PushL(taskInfos);
1.853 + return taskInfos;
1.854 + }
1.855 +
1.856 +static CSchItemRefArray* CreateScheduleRefsLC(TInt aGranularity)
1.857 + {
1.858 + CSchItemRefArray* scheduleReferences = new (ELeave) CSchItemRefArray(aGranularity);
1.859 + CleanupStack::PushL(scheduleReferences);
1.860 + return scheduleReferences;
1.861 + }
1.862 +
1.863 +static void CreateTransientScheduledTasksL(TInt aNumScheduleEntries,
1.864 + TInt aNumSchedules,
1.865 + CSchEntryInfoArray* aScheduleEntries,
1.866 + CArrayFixFlat<TTaskInfo>* aTaskInfos,
1.867 + CSchItemRefArray* aScheduleReferences)
1.868 + {
1.869 + const TTimeIntervalMicroSeconds timeToAdd = 10000000; //10 seconds
1.870 + const TTimeIntervalMicroSeconds timeLimit = 5000000; // 5 seconds
1.871 + _LIT(KTaskDataPrefix, "Task Data Entry: ");
1.872 + // Prepare keys required
1.873 + TKeyArrayFix KTaskInfoSortKey(_FOFF(TTaskInfo, iTaskId), ECmpTInt);
1.874 +
1.875 + for(TInt i=0;i<aNumSchedules;i++)
1.876 + {
1.877 + // Remove any existing schedule entry info's
1.878 + aScheduleEntries->Reset();
1.879 + //
1.880 + // Populate the schedule entry array with a varying list of
1.881 + // start-times, intervals, etc for this particular task
1.882 + //
1.883 + for(TInt j=0; j<aNumScheduleEntries; ++j)
1.884 + {
1.885 + TScheduleEntryInfo scheduleEntry = SchSvrHelpers::RandomScheduleEntryInfo(TheSeed);
1.886 + TTime now;
1.887 + now.HomeTime(); // sets now to home time
1.888 + //if iStartTime is set lower then 5 sec into the future, postpone iStartTime 10 sec into the future
1.889 + if(scheduleEntry.iStartTime < now + timeLimit)
1.890 + scheduleEntry.iStartTime = now + timeToAdd;
1.891 + aScheduleEntries->AppendL(scheduleEntry);
1.892 + }
1.893 + //
1.894 + // Create some dummy task data
1.895 + //
1.896 + HBufC* taskData = HBufC::NewLC(KTaskDataPrefix().Length()+4);
1.897 + taskData->Des().Copy(KTaskDataPrefix());
1.898 + taskData->Des().AppendNum(i);
1.899 + //
1.900 + // Munge the task name
1.901 + //
1.902 + TTaskInfo taskInfo;
1.903 + taskInfo.iName = *taskData;
1.904 + taskInfo.iRepeat = 1;
1.905 + taskInfo.iPriority = 1;
1.906 + // Schedule the transient task
1.907 + TSchedulerItemRef scheduleReference;
1.908 + TInt result = TheScheduler.ScheduleTask(taskInfo,
1.909 + *taskData,
1.910 + scheduleReference,
1.911 + *aScheduleEntries);
1.912 + TEST2(result, KErrNone);
1.913 + TheTest.Printf(_L("TaskId: %d => TaskName: %S\n"), taskInfo.iTaskId, &taskInfo.iName);
1.914 + CleanupStack::PopAndDestroy(taskData);
1.915 + //
1.916 + // Save the taskInfo so we can check it later - this inserts the taskinfo into
1.917 + // the array (preserves sorted order by TTaskInfo.iTaskId) but also has the
1.918 + // added bonus of preventing duplicate task ids...
1.919 + //
1.920 + aTaskInfos->InsertIsqL(taskInfo, KTaskInfoSortKey);
1.921 + // Disable all schedules once added, just to stop them going off
1.922 + // and therefore being deleted when we are trying to compare them
1.923 + result = TheScheduler.DisableSchedule(scheduleReference.iHandle);
1.924 + TEST2(result, KErrNone);
1.925 + // Save the sever generated schedule reference and taskId for checking later
1.926 + aScheduleReferences->AppendL(scheduleReference);
1.927 + }
1.928 + }
1.929 +
1.930 +static void CheckScheduledRefs(TInt aNumSchedules)
1.931 + {
1.932 + CSchItemRefArray* refs = new (ELeave) CSchItemRefArray(3);
1.933 + CleanupStack::PushL(refs);
1.934 + TInt res = TheScheduler.GetScheduleRefsL(*refs, EAllSchedules);
1.935 + TEST2(res, KErrNone);
1.936 + TInt count = refs->Count();
1.937 + TEST(count == aNumSchedules);
1.938 + CleanupStack::PopAndDestroy(refs);
1.939 + }
1.940 +
1.941 +/**
1.942 +@SYMTestCaseID SYSLIB-SCHSVR-CT-1342
1.943 +@SYMTestCaseDesc Scheduling tasks test
1.944 +@SYMTestPriority High
1.945 +@SYMTestActions Tests for RScheduler::GetTaskDataSize(),RScheduler::GetTaskInfoL() functions
1.946 +@SYMTestExpectedResults Test must not fail
1.947 +@SYMREQ REQ0000
1.948 +*/
1.949 +static void TestScheduledTasksL(TInt aNumSchedules,
1.950 + CArrayFixFlat<TTaskInfo>* aTaskInfos)
1.951 + {
1.952 + for(TInt n=0; n<aNumSchedules; ++n)
1.953 + {
1.954 + const TTaskInfo& taskInfo = aTaskInfos->At(n);
1.955 + TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-1342 "));
1.956 +
1.957 + // First retrieve the task size
1.958 + TInt taskSize;
1.959 + TInt result = TheScheduler.GetTaskDataSize(taskInfo.iTaskId, taskSize);
1.960 + TEST2(result, KErrNone);
1.961 + TEST(taskSize > 0);
1.962 +
1.963 + // Next retrieve the task info associated with a particular task Id
1.964 + HBufC* taskData = HBufC::NewLC(taskSize);
1.965 + TPtr pTaskData = taskData->Des();
1.966 +
1.967 + TTime scheduleNextDueTime;
1.968 + TTaskInfo taskFromServer;
1.969 + TSchedulerItemRef scheduleReference;
1.970 +
1.971 + result = TheScheduler.GetTaskInfoL(taskInfo.iTaskId,
1.972 + taskFromServer,
1.973 + pTaskData,
1.974 + scheduleReference,
1.975 + scheduleNextDueTime);
1.976 + TEST2(result, KErrNone);
1.977 + TEST(taskData->Length() == taskSize);
1.978 +
1.979 + // Now check that the task returned by the server matches that held locallly....
1.980 + TBool bbb = SchSvrHelpers::IsTaskInfoTheSame(taskFromServer, taskInfo);
1.981 + if(!bbb)
1.982 + {
1.983 + RDebug::Print(_L("TaskInfo1. repeat=%x, id=%d, name=%S, priority=%x\n"),
1.984 + taskFromServer.iRepeat, taskFromServer.iTaskId, &taskFromServer.iName, taskFromServer.iPriority);
1.985 + RDebug::Print(_L("TaskInfo2. repeat=%x, id=%d, name=%S, priority=%x\n"),
1.986 + taskInfo.iRepeat, taskInfo.iTaskId, &taskInfo.iName, taskInfo.iPriority);
1.987 + }
1.988 + TEST(bbb);
1.989 +
1.990 + // Check taskData is the same (was originally held in the TTaskInfo.iName field)
1.991 + const TDesC& des1 = taskInfo.iName;
1.992 + TDes& des2 = pTaskData;
1.993 + TEST(des1 == des2);
1.994 + CleanupStack::PopAndDestroy(taskData);
1.995 + }
1.996 + }
1.997 +/**
1.998 +@SYMTestCaseID SYSLIB-SCHSVR-CT-1040
1.999 +@SYMTestCaseDesc Tests for retrieving of task data and info.
1.1000 +@SYMTestPriority High
1.1001 +@SYMTestActions Create a large number of transient scheduled tasks to test Id generation
1.1002 + Tests tasks for a given taskid is the same
1.1003 + Tests reference can be retrieved for a given handle.
1.1004 +@SYMTestExpectedResults Test must not fail
1.1005 +@SYMREQ REQ0000
1.1006 +*/
1.1007 +static void Test8L()
1.1008 + {
1.1009 + // Test title
1.1010 + TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-1040 Create a large number of tasks, test retrieval of task data and task info "));
1.1011 +
1.1012 + SchSvrHelpers::DeleteAllSchedulesL(TheScheduler);
1.1013 +
1.1014 + // Constants used in this function
1.1015 + const TInt KNumberOfSchedulesToCreate = 20;
1.1016 + const TInt KNumberOfScheduleEntriesToCreate = 5;
1.1017 +
1.1018 + // Prepare arrays required for the tests below
1.1019 + CSchEntryInfoArray* scheduleEntries = ::CreateSchEntryInfoArrayLC(KNumberOfScheduleEntriesToCreate);
1.1020 + CArrayFixFlat<TTaskInfo>* taskInfos = ::CreateTaskInfoLC(KNumberOfSchedulesToCreate);
1.1021 + CSchItemRefArray* scheduleReferences = ::CreateScheduleRefsLC(KNumberOfSchedulesToCreate);
1.1022 +
1.1023 + //
1.1024 + // Create a large number of transient scheduled tasks
1.1025 + // to test Id generation
1.1026 + //
1.1027 + ::CreateTransientScheduledTasksL(KNumberOfScheduleEntriesToCreate,
1.1028 + KNumberOfSchedulesToCreate,
1.1029 + scheduleEntries,
1.1030 + taskInfos,
1.1031 + scheduleReferences);
1.1032 +
1.1033 +
1.1034 + ::CheckScheduledRefs(KNumberOfSchedulesToCreate);
1.1035 +
1.1036 + // Test tasks for a given taskid is the same
1.1037 + ::TestScheduledTasksL(KNumberOfSchedulesToCreate, taskInfos);
1.1038 +
1.1039 + // Test reference can be retrieved for a given handle.
1.1040 + CleanupStack::PopAndDestroy(scheduleReferences);
1.1041 + CleanupStack::PopAndDestroy(taskInfos);
1.1042 + CleanupStack::PopAndDestroy(scheduleEntries);
1.1043 +
1.1044 + // now delete all schedules
1.1045 + SchSvrHelpers::DeleteAllSchedulesL(TheScheduler);
1.1046 + TInt ccc = CountScheduledItemsL(EAllSchedules, TheScheduler);
1.1047 + TEST(ccc == 0);
1.1048 +
1.1049 + SchSvrHelpers::Pause(TheTest);
1.1050 + }
1.1051 +/**
1.1052 +@SYMTestCaseID SYSLIB-SCHSVR-CT-3544
1.1053 +@SYMTestCaseDesc This test establishes transient tasks do not persist to disk.
1.1054 +@SYMTestPriority High
1.1055 +@SYMTestActions create persistent and transient schedules with tasks. Wait for tasks to execute.
1.1056 + Cause server to shutdown and restart. Check file size against known good size.
1.1057 +@SYMTestExpectedResults Persistent schedules and tasks are saved to file, but transient ones are not.
1.1058 +@SYMDEF DEF109371
1.1059 +*/
1.1060 +static void Test9L()
1.1061 + {
1.1062 +//Clean up before running test
1.1063 + SchSvrHelpers::DeleteScheduleFilesL();
1.1064 + TheScheduler.Close();
1.1065 +
1.1066 + TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-3544 Test transient schedules and tasks do not persist after power outages "));
1.1067 +
1.1068 + TheTest.Next(_L("Connect to Scheduler"));
1.1069 + TInt res = TheScheduler.Connect();
1.1070 + TEST2(res, KErrNone);
1.1071 +
1.1072 + TheTest.Next(_L("Registering Client"));
1.1073 + TEST2(SchSvrHelpers::RegisterClientL(TheScheduler), KErrNone);
1.1074 +
1.1075 +
1.1076 + //Create a transient schedule with a task set to go off 10 minutes from server time.
1.1077 + const TDateTime KTimeToStartTask(2000, EJanuary, 10, 15, 30, 0, 0);
1.1078 +
1.1079 + TSchedulerItemRef schedulerItemReference;
1.1080 + CSchEntryInfoArray* entryArray = new(ELeave) CSchEntryInfoArray(1);
1.1081 + CleanupStack::PushL(entryArray);
1.1082 +
1.1083 + HBufC* taskData = _L("This is some transient task data created for testing").AllocL();
1.1084 + CleanupStack::PushL(taskData);
1.1085 +
1.1086 + // Prepare the task info - this describes the tasks that are contained within the task
1.1087 + // entry array
1.1088 + TTaskInfo taskInfo = SchSvrHelpers::TaskInfo(_L("A transient test task"), 100);
1.1089 +
1.1090 + // Create a schedule entry and append it to the entry array
1.1091 + {
1.1092 + TScheduleEntryInfo scheduleEntry = SchSvrHelpers::ScheduleEntryInfo(EDaily, TTime(KTimeToStartTask), 7, 2);
1.1093 + entryArray->AppendL(scheduleEntry);
1.1094 + }
1.1095 +
1.1096 + // Create the transient task
1.1097 + TInt ret = TheScheduler.ScheduleTask(taskInfo, *taskData, schedulerItemReference, *entryArray);
1.1098 + TEST2(ret, KErrNone);
1.1099 +
1.1100 + // Check that the task Id after scheduling the event is not
1.1101 + // the same as it was prior to the requesting the service
1.1102 + TEST(taskInfo.iTaskId != -1);
1.1103 +
1.1104 +
1.1105 + // Create a persistent schedule
1.1106 + TheTest.Next(_L("Creating Persistent schedule"));
1.1107 + //Set server time to known time
1.1108 + SchSvrHelpers::SetHomeTimeL(TTime(TDateTime(2000, EJanuary, 1, 10, 5, 0, 0))); // 10:05 am
1.1109 +
1.1110 + TSchedulerItemRef scheduleHandle;
1.1111 + TTime time;
1.1112 + time.HomeTime();//Get time
1.1113 + time += TTimeIntervalSeconds(5); //Task to go off five seconds from now
1.1114 + User::LeaveIfError(CreateScheduleL(scheduleHandle, TheScheduler, time));
1.1115 +
1.1116 + // Add a repeating task to the persistent schedule
1.1117 + TheTest.Next(_L("Creating task for persistent schedule"));
1.1118 + TTaskInfo persisttaskInfo;
1.1119 + {
1.1120 + persisttaskInfo.iName = _L("MyPersistent TaskName");
1.1121 + persisttaskInfo.iPriority = 2;
1.1122 + persisttaskInfo.iTaskId = 0;
1.1123 + persisttaskInfo.iRepeat = 3;
1.1124 + HBufC* data = _L("Persistent Task Data").AllocLC();
1.1125 + TInt res = TheScheduler.ScheduleTask(persisttaskInfo, *data, scheduleHandle.iHandle);
1.1126 + CleanupStack::PopAndDestroy(); // data
1.1127 + TEST2(res, KErrNone);
1.1128 + }
1.1129 +
1.1130 + //Now get the filesize of the servers schedule.dat.
1.1131 + TFileName templateFileName;
1.1132 + _LIT(KFileName,"C:\\private\\10005399\\SchedulesBackup.dat");
1.1133 + templateFileName.Copy(KFileName);
1.1134 + templateFileName[0] = 'A' + static_cast<TInt>(RFs::GetSystemDrive());
1.1135 + RFile file;
1.1136 + CleanupClosePushL(file);
1.1137 +
1.1138 + SchSvrHelpers::Pause(TheTest);
1.1139 + //AllFiles capability required to access the private cage of the server
1.1140 + TInt ferr = file.Open(TheFsSession, templateFileName, EFileShareReadersOrWriters | EFileRead);
1.1141 + TEST2(ferr,KErrNone);
1.1142 + TInt filesize1 = 0;
1.1143 + //The below const is the measured file size for the creation of the above schedule.
1.1144 + //It will change if new data members are added to task or schedule classes
1.1145 + const TInt KExpectedFileSize = 374;
1.1146 + TInt sErr = file.Size(filesize1);
1.1147 + TEST2(sErr,KErrNone);
1.1148 + TheTest.Printf(_L("Expected filesize is 374b Filesize is [%db]\n"), filesize1);
1.1149 + TEST(filesize1 == KExpectedFileSize);
1.1150 +
1.1151 + CleanupStack::PopAndDestroy(3);
1.1152 +}
1.1153 +
1.1154 +
1.1155 +//***********************************************************************************
1.1156 +static TInt RunTestsL()
1.1157 + {
1.1158 + TheTest.Next(_L("Delete old files"));
1.1159 + SchSvrHelpers::DeleteScheduleFilesL();
1.1160 +
1.1161 + TheTest.Next(_L("Create Task notification semaphore"));
1.1162 + //initialise task notification semaphore
1.1163 + STaskSemaphore sem;
1.1164 + sem.CreateL();
1.1165 +
1.1166 + // Prepare random number seed
1.1167 + TheTest.Next(_L("Prepare random number"));
1.1168 + TTime now;
1.1169 + now.UniversalTime();
1.1170 + TheSeed = now.Int64();
1.1171 +
1.1172 + // Connect to the server
1.1173 + TheTest.Next(_L("===== Connect to Scheduler ====="));
1.1174 + TInt res = TheScheduler.Connect();
1.1175 + TEST2(res, KErrNone);
1.1176 +
1.1177 + // Register a client with the server
1.1178 + TheTest.Next(_L("===== Registering Client ====="));
1.1179 + res = SchSvrHelpers::RegisterClientL(TheScheduler);
1.1180 + TEST2(res, KErrNone);
1.1181 +
1.1182 + TheTest.Next(_L("Start tests"));
1.1183 + Test1L();
1.1184 + Test2L();
1.1185 + Test3L();
1.1186 + Test4L();
1.1187 + Test5L();
1.1188 + Test6L();
1.1189 + Test7L();
1.1190 + Test8L();
1.1191 + Test9L();
1.1192 +
1.1193 + TheTest.Next(_L("Tidying up"));
1.1194 + //Tidying up so next test will be clear.
1.1195 + TheTest.Next(_L("Delete all schedules"));
1.1196 + SchSvrHelpers::DeleteAllSchedulesL(TheScheduler);
1.1197 + SchSvrHelpers::Pause(TheTest, 2);
1.1198 + TheTest.Next(_L("Delete old files\n"));
1.1199 + SchSvrHelpers::DeleteScheduleFilesL();
1.1200 +
1.1201 + TheScheduler.Close();
1.1202 +
1.1203 + //close handle to semaphore
1.1204 + sem.Close();
1.1205 +
1.1206 + return KErrNone;
1.1207 + }
1.1208 +
1.1209 +//***********************************************************************************
1.1210 +GLDEF_C TInt E32Main()
1.1211 +//
1.1212 +// TheTest the scheduler
1.1213 +//
1.1214 + {
1.1215 + __UHEAP_MARK;
1.1216 + TheTest.Start(_L("TC_TSCH_SCHEDULING2"));
1.1217 + TheTest.Title();
1.1218 + TheCleanup = CTrapCleanup::New();
1.1219 + //If the previous test fails, SCHSVR.exe may stay in memory.
1.1220 + TRAPD(error,CleanupHelpers::TestCleanupL());
1.1221 + TEST2(error, KErrNone);
1.1222 +
1.1223 + TEST2(TheFsSession.Connect(), KErrNone);;
1.1224 + TRAP(error, RunTestsL());
1.1225 + TRAP(error,CleanupHelpers::TestCleanupL());
1.1226 + TEST2(error, KErrNone);
1.1227 + delete TheCleanup;
1.1228 +
1.1229 + TheFsSession.Close();
1.1230 + TheTest.End();
1.1231 + TheTest.Close();
1.1232 + __UHEAP_MARKEND;
1.1233 + return(KErrNone);
1.1234 + }