1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericservices/taskscheduler/Test/Conditions/TC_TSCH_CONDITION_UTC.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,678 @@
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 +#include <e32property.h>
1.27 +#include <schinfointernal.h>
1.28 +#include "TestUtils.h"
1.29 +
1.30 +_LIT(KTestName, "Task Scheduler Condition Scheduling Test - UTC");
1.31 +
1.32 +RTest TheTest(KTestName);
1.33 +
1.34 +typedef CArrayFixFlat<TTaskInfo> CTaskInfoArray;
1.35 +typedef CArrayFixFlat<TSchedulerItemRef> CSchItemRefArray;
1.36 +typedef CArrayFixFlat<TTaskSchedulerCondition> CSchConditionArray;
1.37 +
1.38 +static RScheduler TheScheduler;
1.39 +static CTrapCleanup* TheCleanup;
1.40 +static RFs TheFsSession;
1.41 +
1.42 +const TInt KTestKey1 = 1;
1.43 +const TInt KTestKey2 = 2;
1.44 +const TInt KTestKey3 = 3;
1.45 +
1.46 +_LIT(KMinimalTaskHandler, "MinimalTaskHandler");
1.47 +_LIT(KSeparator, "|"); // Invalid filepath char used to separate filenames
1.48 +
1.49 +// This function launches the TPropertyDefine process which
1.50 +// has WriteDeviceData Capabilities enabling it to create the P&S
1.51 +// variables used by this test.
1.52 +static void LaunchHelperL(TUid aCategory, TInt aKey, TInt aAttr)
1.53 + {
1.54 + _LIT(KConditionHelper, "TPropertyDefine");
1.55 + TRequestStatus stat;
1.56 + RProcess p;
1.57 + TBuf<32> args;
1.58 + args.AppendNum(aCategory.iUid);
1.59 + args.Append(KSeparator);
1.60 + args.AppendNum(aKey);
1.61 + args.Append(KSeparator);
1.62 + args.AppendNum(aAttr);
1.63 + User::LeaveIfError(p.Create(KConditionHelper, args,EOwnerProcess));
1.64 +
1.65 + // Asynchronous logon: completes when process terminates with process exit code
1.66 + p.Logon(stat);
1.67 + p.Resume();
1.68 +
1.69 + User::WaitForRequest(stat);
1.70 + TInt exitReason = p.ExitReason();
1.71 + p.Close();
1.72 + User::LeaveIfError(exitReason);
1.73 + }
1.74 +static void CreateTestVariables()
1.75 + {
1.76 + LaunchHelperL(KUidSystemCategory, KTestKey1,RProperty::EInt);
1.77 + LaunchHelperL(KUidSystemCategory, KTestKey2,RProperty::EInt);
1.78 + LaunchHelperL(KUidSystemCategory, KTestKey3,RProperty::EInt);
1.79 + }
1.80 +
1.81 +static void ResetVariablesL(TInt aKey1Val,
1.82 + TInt aKey2Val,
1.83 + TInt aKey3Val)
1.84 + {
1.85 + User::LeaveIfError(RProperty::Set(KUidSystemCategory, KTestKey1,aKey1Val));
1.86 + User::LeaveIfError(RProperty::Set(KUidSystemCategory, KTestKey2,aKey2Val));
1.87 + User::LeaveIfError(RProperty::Set(KUidSystemCategory, KTestKey3,aKey3Val));
1.88 + }
1.89 +
1.90 +static void GetTaskInfoL(CTaskInfoArray& aTaskInfoArray,
1.91 + TInt aScheduleId)
1.92 + // Extract schedule references from the schedule server based on a filter. If
1.93 + {
1.94 + aTaskInfoArray.Reset();
1.95 + TTsTime defaultTime;
1.96 + TScheduleState2 state;
1.97 + CSchConditionArray* conditionList
1.98 + = new (ELeave) CSchConditionArray(3);
1.99 + CleanupStack::PushL(conditionList);
1.100 + TInt res = TheScheduler.GetScheduleL(aScheduleId,
1.101 + state,
1.102 + *conditionList,
1.103 + defaultTime,
1.104 + aTaskInfoArray);
1.105 + TEST2(res, KErrNone);
1.106 + CleanupStack::PopAndDestroy(conditionList);
1.107 + }
1.108 +
1.109 +static TInt CountTasksL(TInt aScheduleId)
1.110 + {
1.111 + CTaskInfoArray* tasks = new (ELeave) CTaskInfoArray(3);
1.112 + CleanupStack::PushL(tasks);
1.113 + GetTaskInfoL(*tasks, aScheduleId);
1.114 + TInt ret = tasks->Count();
1.115 + CleanupStack::PopAndDestroy(tasks);
1.116 + return ret;
1.117 + }
1.118 +
1.119 +
1.120 +static TInt CountScheduledItemsL(TScheduleFilter aFilter,
1.121 + RScheduler& aScheduler)
1.122 + // Extract schedule references from the schedule server based on a filter. If
1.123 + {
1.124 + CSchItemRefArray* refs = new (ELeave) CSchItemRefArray(3);
1.125 + CleanupStack::PushL(refs);
1.126 +
1.127 + TInt res = aScheduler.GetScheduleRefsL(*refs, aFilter);
1.128 + TEST2(res, KErrNone);
1.129 +
1.130 + TInt count = refs->Count();
1.131 + CleanupStack::PopAndDestroy(); // refs
1.132 + return count;
1.133 + }
1.134 +
1.135 +static CSchConditionArray* CreateSingleConditionLC(const TUid& aConditionUID,
1.136 + TUint aConditionUInt)
1.137 + {
1.138 + CSchConditionArray* conditionList = new (ELeave) CSchConditionArray(3);
1.139 + CleanupStack::PushL(conditionList);
1.140 +
1.141 + {
1.142 + TTaskSchedulerCondition condition1;
1.143 + condition1.iCategory = aConditionUID;
1.144 + condition1.iKey = aConditionUInt;
1.145 + condition1.iState = 10;
1.146 + condition1.iType = TTaskSchedulerCondition::EEquals;
1.147 + conditionList->AppendL(condition1);
1.148 + }
1.149 + return conditionList;
1.150 + }
1.151 +
1.152 +static CSchConditionArray* CreateMultipleConditionsLC()
1.153 + {
1.154 + CSchConditionArray* conditionList = new (ELeave) CSchConditionArray(3);
1.155 + CleanupStack::PushL(conditionList);
1.156 + {
1.157 + TTaskSchedulerCondition condition1;
1.158 + condition1.iCategory = KUidSystemCategory;
1.159 + condition1.iKey = KTestKey1;
1.160 + condition1.iState = 10;
1.161 + condition1.iType = TTaskSchedulerCondition::EEquals;
1.162 + conditionList->AppendL(condition1);
1.163 + }
1.164 + {
1.165 + TTaskSchedulerCondition condition2;
1.166 + condition2.iCategory = KUidSystemCategory;
1.167 + condition2.iKey = KTestKey2;
1.168 + condition2.iState = 10;
1.169 + condition2.iType = TTaskSchedulerCondition::ENotEquals;
1.170 + conditionList->AppendL(condition2);
1.171 + }
1.172 + {
1.173 + TTaskSchedulerCondition condition3;
1.174 + condition3.iCategory = KUidSystemCategory;
1.175 + condition3.iKey = KTestKey3;
1.176 + condition3.iState = 10;
1.177 + condition3.iType = TTaskSchedulerCondition::ELessThan;
1.178 + conditionList->AppendL(condition3);
1.179 + }
1.180 + return conditionList;
1.181 + }
1.182 +
1.183 +// single condition with default time set to 1 year in the future
1.184 +// As this is a valid time a CTimer object actually gets set unlike
1.185 +// if Time::TTimeMax() is used, hence we need to test for both cases.
1.186 +static TInt CreateScheduleSingle1L(TSchedulerItemRef& aRef,
1.187 + RScheduler& aScheduler,
1.188 + const TUid& aConditionUID,
1.189 + TUint aConditionUInt)
1.190 + {
1.191 + aRef.iName = _L("Schedule created using CreateScheduleSingle");
1.192 +
1.193 + CSchConditionArray* conditionList
1.194 + = CreateSingleConditionLC(aConditionUID, aConditionUInt);
1.195 +
1.196 + TTime ttime(SchSvrHelpers::UtcTimeBasedOnOffset(0, 0, 0, 0, 0, 1));
1.197 + TTsTime time(ttime, ETrue); //1 year in the future
1.198 + TInt res = aScheduler.CreatePersistentSchedule(aRef, *conditionList, time);
1.199 + CleanupStack::PopAndDestroy(); // conditionList
1.200 + return res;
1.201 + }
1.202 +
1.203 +// single condition with default time set to Time::MaxTTime()
1.204 +static TInt CreateScheduleSingle2L(TSchedulerItemRef& aRef,
1.205 + RScheduler& aScheduler,
1.206 + const TUid& aConditionUID,
1.207 + TUint aConditionUInt)
1.208 + {
1.209 + aRef.iName = _L("Schedule created using CreateScheduleSingle");
1.210 +
1.211 + CSchConditionArray* conditionList
1.212 + = CreateSingleConditionLC(aConditionUID, aConditionUInt);
1.213 + TTime ttime(Time::MaxTTime());
1.214 + TTsTime time(ttime, ETrue);
1.215 + TInt res = aScheduler.CreatePersistentSchedule(aRef, *conditionList, time);
1.216 + CleanupStack::PopAndDestroy(); // conditionList
1.217 + return res;
1.218 + }
1.219 +
1.220 +// An empty schedule list.
1.221 +static TInt CreateScheduleEmpty3L(TSchedulerItemRef& aRef,
1.222 + RScheduler& aScheduler,
1.223 + const TUid&,
1.224 + TUint )
1.225 + {
1.226 + aRef.iName = _L("Empty Schedule list created");
1.227 +
1.228 + CSchConditionArray* conditionList = new (ELeave) CSchConditionArray(3);
1.229 + CleanupStack::PushL(conditionList);
1.230 + TTime ttime(SchSvrHelpers::UtcTimeBasedOnOffset(0, 0, 0, 0, 0, 1));
1.231 + TTsTime time(ttime, ETrue); //1 year in the future
1.232 + TInt res = aScheduler.CreatePersistentSchedule(aRef, *conditionList, time);
1.233 + CleanupStack::PopAndDestroy(); // conditionList
1.234 +
1.235 + return res;
1.236 + }
1.237 +
1.238 +// A null schedule.
1.239 +static TInt CreateScheduleSingleNull4L(TSchedulerItemRef& aRef,
1.240 + RScheduler& aScheduler,
1.241 + const TUid&,
1.242 + TUint )
1.243 + {
1.244 + aRef.iName = _L("One schedule in the list with a NULL uid");
1.245 +
1.246 + CSchConditionArray* conditionList
1.247 + = CreateSingleConditionLC(KNullUid, 0);
1.248 + TTime ttime(SchSvrHelpers::UtcTimeBasedOnOffset(0, 0, 0, 0, 0, 1));
1.249 + TTsTime time(ttime, ETrue); //1 year in the future
1.250 + TInt res = aScheduler.CreatePersistentSchedule(aRef, *conditionList, time);
1.251 + CleanupStack::PopAndDestroy(); // conditionList
1.252 +
1.253 + return res;
1.254 + }
1.255 +
1.256 +static TInt CreateScheduleMultipleL(TSchedulerItemRef& aRef, RScheduler& aScheduler)
1.257 + {
1.258 + aRef.iName = _L("Schedule created using CreateScheduleMultiple");
1.259 +
1.260 + CSchConditionArray* conditionList = CreateMultipleConditionsLC();
1.261 + TTime ttime(SchSvrHelpers::UtcTimeBasedOnOffset(0, 0, 0, 0, 0, 1));
1.262 + TTsTime time(ttime, ETrue); //1 year in the future
1.263 + TInt res = aScheduler.CreatePersistentSchedule(aRef, *conditionList, time);
1.264 + CleanupStack::PopAndDestroy(); // conditionList
1.265 + return res;
1.266 + }
1.267 +
1.268 +static TInt SchedulePersistentTaskL(const TDesC& aName,
1.269 + TInt& aNewId,
1.270 + TInt aScheduleId,
1.271 + RScheduler& aScheduler)
1.272 + {
1.273 + TTaskInfo taskInfo;
1.274 + taskInfo.iTaskId = aNewId;
1.275 + taskInfo.iName = aName;
1.276 + taskInfo.iPriority = 2;
1.277 + taskInfo.iRepeat = 0;
1.278 + HBufC* data = _L("the data").AllocLC();
1.279 + TInt res = aScheduler.ScheduleTask(taskInfo, *data, aScheduleId);
1.280 + aNewId = taskInfo.iTaskId;
1.281 +
1.282 + CleanupStack::PopAndDestroy(); // data
1.283 + return res;
1.284 + }
1.285 +
1.286 +/**
1.287 +@file
1.288 +@SYMTestCaseID SYSLIB-SCHSVR-CT-0244
1.289 +@SYMTestCaseDesc Single condition based test - UTC
1.290 +@SYMTestPriority High
1.291 +@SYMTestActions Create a condition based schedule & check schedule auto deletes
1.292 +@SYMTestExpectedResults The test must not fail.
1.293 +@SYMPREQ PREQ234
1.294 +*/
1.295 +static void DoTest1L()
1.296 + {
1.297 + TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0244 "));
1.298 + // create a simple condition based schedule, and see if it runs.
1.299 + TInt res = KErrNone;
1.300 + TheTest.Next(_L("single condition based test"));
1.301 + __UHEAP_MARK;
1.302 +
1.303 + //reset the p&s variables before creating the schedule
1.304 + ResetVariablesL(0,0,0);
1.305 + TSchedulerItemRef ref1;
1.306 + TheTest.Printf(_L("Create a schedule\n"));
1.307 + res = CreateScheduleSingle1L(ref1, TheScheduler, KUidSystemCategory, KTestKey1);
1.308 + TEST2(res, KErrNone);
1.309 +
1.310 + TInt task1 = 0;
1.311 + _LIT(KName1, "toothpaste");
1.312 + TheTest.Printf(_L("Schedule some tasks\n"));
1.313 +
1.314 + res = SchedulePersistentTaskL(KName1, task1, ref1.iHandle, TheScheduler);
1.315 + TEST2(res, KErrNone);
1.316 +
1.317 + res = TheScheduler.__DbgMarkHeap();
1.318 + User::LeaveIfError(res); //#1
1.319 + TInt scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
1.320 + TEST(scheduleCount == 1);
1.321 +
1.322 + // Check that schedule is of condition type
1.323 + TScheduleType scheduleType;
1.324 + res = TheScheduler.GetScheduleTypeL(ref1.iHandle, scheduleType);
1.325 + TEST2(res, KErrNone);
1.326 + TEST(scheduleType == EConditionSchedule );
1.327 +
1.328 + res = TheScheduler.__DbgMarkEnd(0);
1.329 + User::LeaveIfError(res); //#1
1.330 +
1.331 + TheScheduler.Close();
1.332 + SchSvrHelpers::Pause(TheTest);
1.333 +
1.334 + // wait for condition to be satisfied
1.335 + res = RProperty::Set(KUidSystemCategory, KTestKey1,10);
1.336 + User::LeaveIfError(res);
1.337 + TEST2(STaskSemaphore::WaitL(KDefaultTimeout), KErrNone);
1.338 + CleanupHelpers::KillProcess(KMinimalTaskHandler);
1.339 +
1.340 + res = TheScheduler.Connect();
1.341 + TEST2(res, KErrNone);
1.342 + // Register a client with the server
1.343 + TheTest.Next(_L("===== Registering Client ====="));
1.344 + res = SchSvrHelpers::RegisterClientL(TheScheduler);
1.345 + TEST2(res, KErrNone);
1.346 +
1.347 + // can't check scheduler to see if any tasks left because it's been
1.348 + // deleted as last task has completed
1.349 +
1.350 + //Check that persistent schedule has auto-deleted
1.351 +
1.352 + TheTest.Printf(_L("DEF46200 - Check schedule has auto deleted\n"));
1.353 + scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
1.354 + TEST(scheduleCount == 0);
1.355 +
1.356 + // Attempt to delete auto-deleted schedule, should fail
1.357 +
1.358 + TheTest.Printf(_L("DEF46200 - Attempting to delete schedule with id %d\n"), ref1.iHandle);
1.359 + res = TheScheduler.DeleteSchedule(ref1.iHandle);
1.360 + TEST2(res, KErrNotFound);
1.361 +
1.362 + // now repeat process with singleschedule2
1.363 + ResetVariablesL(0,0,0);
1.364 +
1.365 + TheTest.Printf(_L("Create another schedule\n"));
1.366 + res = CreateScheduleSingle2L(ref1, TheScheduler, KUidSystemCategory, KTestKey1);
1.367 + TEST2(res, KErrNone);
1.368 +
1.369 + TheTest.Printf(_L("Create an empty schedule list\n"));
1.370 + res = CreateScheduleEmpty3L(ref1, TheScheduler, KUidSystemCategory, KTestKey1);
1.371 + TEST2(res, KErrArgument);
1.372 +
1.373 + TheTest.Printf(_L("Create an empty schedule list\n"));
1.374 + res = CreateScheduleSingleNull4L(ref1, TheScheduler, KUidSystemCategory, KTestKey1);
1.375 + TEST2(res, KErrArgument);
1.376 +
1.377 + res = SchedulePersistentTaskL(KName1, task1, ref1.iHandle, TheScheduler);
1.378 + TEST2(res, KErrNone);
1.379 + SchSvrHelpers::Pause(TheTest);
1.380 +
1.381 + // we should have one outstanding task (without the check in
1.382 + // schtimer.cpp specifically for Time::MaxTTime() the timer would have
1.383 + // gone off immediately in the past.)
1.384 + TEST(CountTasksL(ref1.iHandle) == 1);
1.385 +
1.386 + scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
1.387 + TEST(scheduleCount == 1);
1.388 + // wait for condition to be satisfied
1.389 + User::LeaveIfError(RProperty::Set(KUidSystemCategory, KTestKey1,10));
1.390 + TEST2(STaskSemaphore::WaitL(KDefaultTimeout), KErrNone);
1.391 + CleanupHelpers::KillProcess(KMinimalTaskHandler);
1.392 +
1.393 + // can't check scheduler to see if any tasks left because it's been
1.394 + // deleted as last task has completed
1.395 +
1.396 + TheTest.Printf(_L("DEF46200 - Check schedule has auto deleted\n"));
1.397 + scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
1.398 + TEST(scheduleCount == 0);
1.399 +
1.400 + // Attempt to delete auto-deleted schedule, should fail
1.401 +
1.402 + TheTest.Printf(_L("DEF46200 - Attempting to delete schedule with id %d\n"), ref1.iHandle);
1.403 + res = TheScheduler.DeleteSchedule(ref1.iHandle);
1.404 + TEST2(res, KErrNotFound);
1.405 +
1.406 + SchSvrHelpers::Pause(TheTest);
1.407 + __UHEAP_MARKEND;
1.408 + }
1.409 +
1.410 +/**
1.411 +@file
1.412 +@SYMTestCaseID SYSLIB-SCHSVR-CT-0245
1.413 +@SYMTestCaseDesc Multiple condition based test - UTC
1.414 +@SYMTestPriority High
1.415 +@SYMTestActions Create a condition based schedule with multiple entries, and see if it runs.
1.416 + Try auto deleting the last schedule and test for not found error.
1.417 +@SYMTestExpectedResults The test must not fail.
1.418 +@SYMPREQ PREQ234
1.419 +*/
1.420 +static void DoTest2L()
1.421 + {
1.422 + TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0245 "));
1.423 + // create a condition based schedule with multiple entries, and see if it runs.
1.424 + TInt res = KErrNone;
1.425 + TheTest.Next(_L("multiple condition based test"));
1.426 + __UHEAP_MARK;
1.427 +
1.428 + //reset the p&s variables before creating the schedule
1.429 + ResetVariablesL(0,10,20);
1.430 + TSchedulerItemRef ref1;
1.431 + TheTest.Printf(_L("Create a schedule\n"));
1.432 + res = CreateScheduleMultipleL(ref1, TheScheduler);
1.433 + TEST2(res, KErrNone);
1.434 +
1.435 + TInt task1 = 0;
1.436 + _LIT(KName1, "web subscription");
1.437 + TheTest.Printf(_L("Schedule some tasks\n"));
1.438 + res = SchedulePersistentTaskL(KName1, task1, ref1.iHandle, TheScheduler);
1.439 + TEST2(res, KErrNone);
1.440 +
1.441 + TInt scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
1.442 + TEST(scheduleCount == 1);
1.443 +
1.444 + // we should have one task scheduled to run
1.445 + CTaskInfoArray* tasks = new (ELeave) CTaskInfoArray(3);
1.446 + CleanupStack::PushL(tasks);
1.447 + GetTaskInfoL(*tasks, ref1.iHandle);
1.448 + TEST(tasks->Count() == 1);
1.449 + tasks->Reset();
1.450 +
1.451 + // wait for conditions to be satisfied
1.452 + User::LeaveIfError(RProperty::Set(KUidSystemCategory, KTestKey1,10));//"=="
1.453 + User::LeaveIfError(RProperty::Set(KUidSystemCategory, KTestKey2,1234));//"!="
1.454 + User::LeaveIfError(RProperty::Set(KUidSystemCategory, KTestKey3,9));//"<"
1.455 + TEST2(STaskSemaphore::WaitL(KDefaultTimeout), KErrNone);
1.456 + CleanupHelpers::KillProcess(KMinimalTaskHandler);
1.457 +
1.458 + // Can't check schedule for task info because it's gone
1.459 +
1.460 +
1.461 + // we should have no schedule, it has auto-deleted
1.462 + scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
1.463 + TEST(scheduleCount == 0);
1.464 +
1.465 + // Reset variables
1.466 + TheTest.Printf(_L("Reseting variables"));
1.467 + ResetVariablesL(0,10,20);
1.468 +
1.469 + TheTest.Printf(_L("DEF46200 - Attempting to delete schedule with id %d\n"), ref1.iHandle);
1.470 + res = TheScheduler.DeleteSchedule(ref1.iHandle);
1.471 + TEST2(res, KErrNotFound);
1.472 + scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
1.473 + TEST(scheduleCount == 0);
1.474 +
1.475 + CleanupStack::PopAndDestroy(tasks);
1.476 +
1.477 + SchSvrHelpers::Pause(TheTest);
1.478 + __UHEAP_MARKEND;
1.479 + }
1.480 +
1.481 +/**
1.482 +@file
1.483 +@SYMTestCaseID SYSLIB-SCHSVR-CT-0246
1.484 +@SYMTestCaseDesc Error checking test - UTC
1.485 +@SYMTestPriority High
1.486 +@SYMTestActions Create a schedule with a P&S variables that doesnt exist & create a schedule with a P&S variable that isnt an integer.
1.487 +@SYMTestExpectedResults The test must not fail.
1.488 +@SYMPREQ PREQ234
1.489 +*/
1.490 +static void DoTest3L()
1.491 + {
1.492 + TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0246 "));
1.493 + // create a simple condition based schedule, and see if it runs.
1.494 + TInt res = KErrNone;
1.495 + TheTest.Next(_L("error checking test"));
1.496 + __UHEAP_MARK;
1.497 +
1.498 + //reset the p&s variables before creating the schedule
1.499 + ResetVariablesL(0,0,0);
1.500 + TSchedulerItemRef ref1;
1.501 + _LIT(KName1, "toothpaste");
1.502 +
1.503 + TheTest.Printf(_L("Create a schedule with a P&S variables that doesnt exist\n"));
1.504 + {
1.505 + const TUid KNonexistentUid = TUid::Uid(0x01234566);
1.506 + res = CreateScheduleSingle1L(ref1, TheScheduler, KNonexistentUid, KTestKey1);
1.507 + TEST2(res, KErrNone);
1.508 + TheTest.Printf(_L("Schedule some tasks - error should be returned\n"));
1.509 +
1.510 + TTaskInfo taskInfo;
1.511 + taskInfo.iName = KName1;
1.512 + taskInfo.iPriority = 2;
1.513 + taskInfo.iRepeat = 0;
1.514 + HBufC* data = _L("the data").AllocLC();
1.515 + res = TheScheduler.ScheduleTask(taskInfo, *data, ref1.iHandle);
1.516 + // since we have created the schedule using a UID which doesn't exist
1.517 + //we should get an error
1.518 + TEST2(res, KErrArgument);
1.519 + CleanupStack::PopAndDestroy(); // data
1.520 +
1.521 + TheTest.Printf(_L("Deleting schedule with id %d\n"), ref1.iHandle);
1.522 + res = TheScheduler.DeleteSchedule(ref1.iHandle);
1.523 + TEST2(res, KErrNone);
1.524 + TInt scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
1.525 + TEST(scheduleCount == 0);
1.526 + }
1.527 +
1.528 + TheTest.Printf(_L("Create a schedule\n"));
1.529 + res = CreateScheduleSingle1L(ref1, TheScheduler, KUidSystemCategory, KTestKey1);
1.530 + TEST2(res, KErrNone);
1.531 + TheTest.Printf(_L("Schedule some tasks\n"));
1.532 + {
1.533 + TTaskInfo taskInfo;
1.534 + taskInfo.iName = KName1;
1.535 + taskInfo.iPriority = 2;
1.536 + taskInfo.iRepeat = 1;
1.537 + HBufC* data = _L("the data").AllocLC();
1.538 + User::LeaveIfError(TheScheduler.__DbgMarkHeap());
1.539 + res = TheScheduler.ScheduleTask(taskInfo, *data, ref1.iHandle);
1.540 + // since we have set repeat to something other than 0, we should get an error
1.541 + TEST2(res, KErrArgument);
1.542 + User::LeaveIfError(TheScheduler.__DbgMarkEnd(0));
1.543 + CleanupStack::PopAndDestroy(); // data
1.544 + }
1.545 +
1.546 + SchSvrHelpers::Pause(TheTest);
1.547 + __UHEAP_MARKEND;
1.548 + }
1.549 +
1.550 +/**
1.551 +@SYMTestCaseID SYSLIB-SCHSVR-CT-3245
1.552 +@SYMTestCaseDesc Persistent condition based schedule test
1.553 +@SYMTestPriority High
1.554 +@SYMTestActions Create a single persistent condition based schedule and then
1.555 + terminate the task scheduler.
1.556 + Set the condition and then launch the task scheduler with the
1.557 + condition satisfied. Check that the schedule is executed.
1.558 +@SYMTestExpectedResults Schedule must be executed and test must not panic or fail
1.559 +@SYMREQ REQ0000
1.560 +*/
1.561 +static void DoTest4L()
1.562 + {
1.563 + TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-3245 "));
1.564 + // create a persistent condition based schedule
1.565 + TInt res = KErrNone;
1.566 + TheTest.Next(_L("single condition based test"));
1.567 + __UHEAP_MARK;
1.568 +
1.569 + //reset the p&s variables before creating the schedule
1.570 + ResetVariablesL(0,0,0);
1.571 + TSchedulerItemRef ref1;
1.572 + TheTest.Printf(_L("Create a test schedule\n"));
1.573 + res = CreateScheduleSingle1L(ref1, TheScheduler, KUidSystemCategory, KTestKey1);
1.574 + TEST2(res, KErrNone);
1.575 +
1.576 + TInt task1 = 0;
1.577 + _LIT(KName1, "shutdown task 1");
1.578 + TheTest.Printf(_L("Schedule a persistant task\n"));
1.579 +
1.580 + res = SchedulePersistentTaskL(KName1, task1, ref1.iHandle, TheScheduler);
1.581 + TEST2(res, KErrNone);
1.582 +
1.583 + //Fault the server to force it to shut down
1.584 + TheScheduler.__FaultServer();
1.585 +
1.586 + //close the Scheduler handle
1.587 + TheScheduler.Close();
1.588 +
1.589 + SchSvrHelpers::Pause(TheTest);
1.590 +
1.591 + // set condition
1.592 + res = RProperty::Set(KUidSystemCategory, KTestKey1,10);
1.593 + TEST2(res, KErrNone);
1.594 +
1.595 + //Restart the scheduler with the condition for this persistant task
1.596 + //satisfied
1.597 + res = TheScheduler.Connect();
1.598 + TEST2(res, KErrNone);
1.599 +
1.600 + //wait for task to be executed
1.601 + TEST2(STaskSemaphore::WaitL(KDefaultTimeout), KErrNone);
1.602 + CleanupHelpers::KillProcess(KMinimalTaskHandler);
1.603 +
1.604 + SchSvrHelpers::Pause(TheTest);
1.605 +
1.606 + __UHEAP_MARKEND;
1.607 +
1.608 + }
1.609 +
1.610 +static TInt RunTestsL()
1.611 + {
1.612 + TheTest.Next(_L("Delete old files"));
1.613 + SchSvrHelpers::DeleteScheduleFilesL();
1.614 +
1.615 + TheTest.Next(_L("Create Task notification semaphore"));
1.616 + //initialise task notification semaphore
1.617 + STaskSemaphore sem;
1.618 + sem.CreateL();
1.619 +
1.620 + // Connect to the server
1.621 + TheTest.Next(_L("===== Connect to Scheduler ====="));
1.622 + TInt res = TheScheduler.Connect();
1.623 + TEST2(res, KErrNone);
1.624 + // Register a client with the server
1.625 + TheTest.Next(_L("===== Registering Client ====="));
1.626 + res = SchSvrHelpers::RegisterClientL(TheScheduler);
1.627 + TEST2(res, KErrNone);
1.628 +
1.629 + // Launch helper process to create P&S variables
1.630 + CreateTestVariables();
1.631 +
1.632 + CActiveScheduler* scheduler = new (ELeave) CActiveScheduler();
1.633 + CleanupStack::PushL(scheduler);
1.634 + CActiveScheduler::Install(scheduler);
1.635 +
1.636 + TheTest.Next(_L("Start tests"));
1.637 + DoTest1L();
1.638 + DoTest2L();
1.639 + DoTest3L();
1.640 + DoTest4L();
1.641 +
1.642 + TheTest.Next(_L("Tidying up"));
1.643 + CleanupStack::PopAndDestroy(scheduler);
1.644 + //close handle to semaphore
1.645 + sem.Close();
1.646 +
1.647 + //Tidying up so next test will be clear.
1.648 + TheTest.Next(_L("Delete all schedules"));
1.649 + SchSvrHelpers::DeleteAllSchedulesL(TheScheduler);
1.650 + SchSvrHelpers::Pause(TheTest, 2);
1.651 + TheTest.Next(_L("Delete old files\n"));
1.652 + SchSvrHelpers::DeleteScheduleFilesL();
1.653 +
1.654 + TheScheduler.Close();
1.655 + return KErrNone;
1.656 + }
1.657 +
1.658 +GLDEF_C TInt E32Main()
1.659 + {
1.660 + __UHEAP_MARK;
1.661 + TheTest.Start(_L("TC_TSCH_CONDITION_UTC"));
1.662 + TheTest.Title();
1.663 + TheCleanup = CTrapCleanup::New();
1.664 +
1.665 + //If the previous test fails, SCHSVR.exe may stay in memory.
1.666 + TRAPD(error,CleanupHelpers::TestCleanupL());
1.667 + TEST2(error, KErrNone);
1.668 + TheTest(TheFsSession.Connect() == KErrNone);;
1.669 + TRAP(error, RunTestsL());
1.670 + TEST2(error, KErrNone);
1.671 + TRAP(error,CleanupHelpers::TestCleanupL());
1.672 + TEST2(error, KErrNone);
1.673 + delete TheCleanup;
1.674 +
1.675 + TheFsSession.Close();
1.676 + TheTest.End();
1.677 + TheTest.Close();
1.678 + __UHEAP_MARKEND;
1.679 +
1.680 + return KErrNone;
1.681 + }