sl@0
|
1 |
// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
#include <csch_cli.h>
|
sl@0
|
17 |
#include "Thelpers.h"
|
sl@0
|
18 |
|
sl@0
|
19 |
#include <e32base.h>
|
sl@0
|
20 |
#include <e32test.h>
|
sl@0
|
21 |
#include <f32file.h>
|
sl@0
|
22 |
#include <s32file.h>
|
sl@0
|
23 |
#include <e32property.h>
|
sl@0
|
24 |
#include <schinfointernal.h>
|
sl@0
|
25 |
#include "TestUtils.h"
|
sl@0
|
26 |
|
sl@0
|
27 |
_LIT(KTestName, "Task Scheduler Condition Scheduling Test - UTC");
|
sl@0
|
28 |
|
sl@0
|
29 |
RTest TheTest(KTestName);
|
sl@0
|
30 |
|
sl@0
|
31 |
typedef CArrayFixFlat<TTaskInfo> CTaskInfoArray;
|
sl@0
|
32 |
typedef CArrayFixFlat<TSchedulerItemRef> CSchItemRefArray;
|
sl@0
|
33 |
typedef CArrayFixFlat<TTaskSchedulerCondition> CSchConditionArray;
|
sl@0
|
34 |
|
sl@0
|
35 |
static RScheduler TheScheduler;
|
sl@0
|
36 |
static CTrapCleanup* TheCleanup;
|
sl@0
|
37 |
static RFs TheFsSession;
|
sl@0
|
38 |
|
sl@0
|
39 |
const TInt KTestKey1 = 1;
|
sl@0
|
40 |
const TInt KTestKey2 = 2;
|
sl@0
|
41 |
const TInt KTestKey3 = 3;
|
sl@0
|
42 |
|
sl@0
|
43 |
_LIT(KMinimalTaskHandler, "MinimalTaskHandler");
|
sl@0
|
44 |
_LIT(KSeparator, "|"); // Invalid filepath char used to separate filenames
|
sl@0
|
45 |
|
sl@0
|
46 |
// This function launches the TPropertyDefine process which
|
sl@0
|
47 |
// has WriteDeviceData Capabilities enabling it to create the P&S
|
sl@0
|
48 |
// variables used by this test.
|
sl@0
|
49 |
static void LaunchHelperL(TUid aCategory, TInt aKey, TInt aAttr)
|
sl@0
|
50 |
{
|
sl@0
|
51 |
_LIT(KConditionHelper, "TPropertyDefine");
|
sl@0
|
52 |
TRequestStatus stat;
|
sl@0
|
53 |
RProcess p;
|
sl@0
|
54 |
TBuf<32> args;
|
sl@0
|
55 |
args.AppendNum(aCategory.iUid);
|
sl@0
|
56 |
args.Append(KSeparator);
|
sl@0
|
57 |
args.AppendNum(aKey);
|
sl@0
|
58 |
args.Append(KSeparator);
|
sl@0
|
59 |
args.AppendNum(aAttr);
|
sl@0
|
60 |
User::LeaveIfError(p.Create(KConditionHelper, args,EOwnerProcess));
|
sl@0
|
61 |
|
sl@0
|
62 |
// Asynchronous logon: completes when process terminates with process exit code
|
sl@0
|
63 |
p.Logon(stat);
|
sl@0
|
64 |
p.Resume();
|
sl@0
|
65 |
|
sl@0
|
66 |
User::WaitForRequest(stat);
|
sl@0
|
67 |
TInt exitReason = p.ExitReason();
|
sl@0
|
68 |
p.Close();
|
sl@0
|
69 |
User::LeaveIfError(exitReason);
|
sl@0
|
70 |
}
|
sl@0
|
71 |
static void CreateTestVariables()
|
sl@0
|
72 |
{
|
sl@0
|
73 |
LaunchHelperL(KUidSystemCategory, KTestKey1,RProperty::EInt);
|
sl@0
|
74 |
LaunchHelperL(KUidSystemCategory, KTestKey2,RProperty::EInt);
|
sl@0
|
75 |
LaunchHelperL(KUidSystemCategory, KTestKey3,RProperty::EInt);
|
sl@0
|
76 |
}
|
sl@0
|
77 |
|
sl@0
|
78 |
static void ResetVariablesL(TInt aKey1Val,
|
sl@0
|
79 |
TInt aKey2Val,
|
sl@0
|
80 |
TInt aKey3Val)
|
sl@0
|
81 |
{
|
sl@0
|
82 |
User::LeaveIfError(RProperty::Set(KUidSystemCategory, KTestKey1,aKey1Val));
|
sl@0
|
83 |
User::LeaveIfError(RProperty::Set(KUidSystemCategory, KTestKey2,aKey2Val));
|
sl@0
|
84 |
User::LeaveIfError(RProperty::Set(KUidSystemCategory, KTestKey3,aKey3Val));
|
sl@0
|
85 |
}
|
sl@0
|
86 |
|
sl@0
|
87 |
static void GetTaskInfoL(CTaskInfoArray& aTaskInfoArray,
|
sl@0
|
88 |
TInt aScheduleId)
|
sl@0
|
89 |
// Extract schedule references from the schedule server based on a filter. If
|
sl@0
|
90 |
{
|
sl@0
|
91 |
aTaskInfoArray.Reset();
|
sl@0
|
92 |
TTsTime defaultTime;
|
sl@0
|
93 |
TScheduleState2 state;
|
sl@0
|
94 |
CSchConditionArray* conditionList
|
sl@0
|
95 |
= new (ELeave) CSchConditionArray(3);
|
sl@0
|
96 |
CleanupStack::PushL(conditionList);
|
sl@0
|
97 |
TInt res = TheScheduler.GetScheduleL(aScheduleId,
|
sl@0
|
98 |
state,
|
sl@0
|
99 |
*conditionList,
|
sl@0
|
100 |
defaultTime,
|
sl@0
|
101 |
aTaskInfoArray);
|
sl@0
|
102 |
TEST2(res, KErrNone);
|
sl@0
|
103 |
CleanupStack::PopAndDestroy(conditionList);
|
sl@0
|
104 |
}
|
sl@0
|
105 |
|
sl@0
|
106 |
static TInt CountTasksL(TInt aScheduleId)
|
sl@0
|
107 |
{
|
sl@0
|
108 |
CTaskInfoArray* tasks = new (ELeave) CTaskInfoArray(3);
|
sl@0
|
109 |
CleanupStack::PushL(tasks);
|
sl@0
|
110 |
GetTaskInfoL(*tasks, aScheduleId);
|
sl@0
|
111 |
TInt ret = tasks->Count();
|
sl@0
|
112 |
CleanupStack::PopAndDestroy(tasks);
|
sl@0
|
113 |
return ret;
|
sl@0
|
114 |
}
|
sl@0
|
115 |
|
sl@0
|
116 |
|
sl@0
|
117 |
static TInt CountScheduledItemsL(TScheduleFilter aFilter,
|
sl@0
|
118 |
RScheduler& aScheduler)
|
sl@0
|
119 |
// Extract schedule references from the schedule server based on a filter. If
|
sl@0
|
120 |
{
|
sl@0
|
121 |
CSchItemRefArray* refs = new (ELeave) CSchItemRefArray(3);
|
sl@0
|
122 |
CleanupStack::PushL(refs);
|
sl@0
|
123 |
|
sl@0
|
124 |
TInt res = aScheduler.GetScheduleRefsL(*refs, aFilter);
|
sl@0
|
125 |
TEST2(res, KErrNone);
|
sl@0
|
126 |
|
sl@0
|
127 |
TInt count = refs->Count();
|
sl@0
|
128 |
CleanupStack::PopAndDestroy(); // refs
|
sl@0
|
129 |
return count;
|
sl@0
|
130 |
}
|
sl@0
|
131 |
|
sl@0
|
132 |
static CSchConditionArray* CreateSingleConditionLC(const TUid& aConditionUID,
|
sl@0
|
133 |
TUint aConditionUInt)
|
sl@0
|
134 |
{
|
sl@0
|
135 |
CSchConditionArray* conditionList = new (ELeave) CSchConditionArray(3);
|
sl@0
|
136 |
CleanupStack::PushL(conditionList);
|
sl@0
|
137 |
|
sl@0
|
138 |
{
|
sl@0
|
139 |
TTaskSchedulerCondition condition1;
|
sl@0
|
140 |
condition1.iCategory = aConditionUID;
|
sl@0
|
141 |
condition1.iKey = aConditionUInt;
|
sl@0
|
142 |
condition1.iState = 10;
|
sl@0
|
143 |
condition1.iType = TTaskSchedulerCondition::EEquals;
|
sl@0
|
144 |
conditionList->AppendL(condition1);
|
sl@0
|
145 |
}
|
sl@0
|
146 |
return conditionList;
|
sl@0
|
147 |
}
|
sl@0
|
148 |
|
sl@0
|
149 |
static CSchConditionArray* CreateMultipleConditionsLC()
|
sl@0
|
150 |
{
|
sl@0
|
151 |
CSchConditionArray* conditionList = new (ELeave) CSchConditionArray(3);
|
sl@0
|
152 |
CleanupStack::PushL(conditionList);
|
sl@0
|
153 |
{
|
sl@0
|
154 |
TTaskSchedulerCondition condition1;
|
sl@0
|
155 |
condition1.iCategory = KUidSystemCategory;
|
sl@0
|
156 |
condition1.iKey = KTestKey1;
|
sl@0
|
157 |
condition1.iState = 10;
|
sl@0
|
158 |
condition1.iType = TTaskSchedulerCondition::EEquals;
|
sl@0
|
159 |
conditionList->AppendL(condition1);
|
sl@0
|
160 |
}
|
sl@0
|
161 |
{
|
sl@0
|
162 |
TTaskSchedulerCondition condition2;
|
sl@0
|
163 |
condition2.iCategory = KUidSystemCategory;
|
sl@0
|
164 |
condition2.iKey = KTestKey2;
|
sl@0
|
165 |
condition2.iState = 10;
|
sl@0
|
166 |
condition2.iType = TTaskSchedulerCondition::ENotEquals;
|
sl@0
|
167 |
conditionList->AppendL(condition2);
|
sl@0
|
168 |
}
|
sl@0
|
169 |
{
|
sl@0
|
170 |
TTaskSchedulerCondition condition3;
|
sl@0
|
171 |
condition3.iCategory = KUidSystemCategory;
|
sl@0
|
172 |
condition3.iKey = KTestKey3;
|
sl@0
|
173 |
condition3.iState = 10;
|
sl@0
|
174 |
condition3.iType = TTaskSchedulerCondition::ELessThan;
|
sl@0
|
175 |
conditionList->AppendL(condition3);
|
sl@0
|
176 |
}
|
sl@0
|
177 |
return conditionList;
|
sl@0
|
178 |
}
|
sl@0
|
179 |
|
sl@0
|
180 |
// single condition with default time set to 1 year in the future
|
sl@0
|
181 |
// As this is a valid time a CTimer object actually gets set unlike
|
sl@0
|
182 |
// if Time::TTimeMax() is used, hence we need to test for both cases.
|
sl@0
|
183 |
static TInt CreateScheduleSingle1L(TSchedulerItemRef& aRef,
|
sl@0
|
184 |
RScheduler& aScheduler,
|
sl@0
|
185 |
const TUid& aConditionUID,
|
sl@0
|
186 |
TUint aConditionUInt)
|
sl@0
|
187 |
{
|
sl@0
|
188 |
aRef.iName = _L("Schedule created using CreateScheduleSingle");
|
sl@0
|
189 |
|
sl@0
|
190 |
CSchConditionArray* conditionList
|
sl@0
|
191 |
= CreateSingleConditionLC(aConditionUID, aConditionUInt);
|
sl@0
|
192 |
|
sl@0
|
193 |
TTime ttime(SchSvrHelpers::UtcTimeBasedOnOffset(0, 0, 0, 0, 0, 1));
|
sl@0
|
194 |
TTsTime time(ttime, ETrue); //1 year in the future
|
sl@0
|
195 |
TInt res = aScheduler.CreatePersistentSchedule(aRef, *conditionList, time);
|
sl@0
|
196 |
CleanupStack::PopAndDestroy(); // conditionList
|
sl@0
|
197 |
return res;
|
sl@0
|
198 |
}
|
sl@0
|
199 |
|
sl@0
|
200 |
// single condition with default time set to Time::MaxTTime()
|
sl@0
|
201 |
static TInt CreateScheduleSingle2L(TSchedulerItemRef& aRef,
|
sl@0
|
202 |
RScheduler& aScheduler,
|
sl@0
|
203 |
const TUid& aConditionUID,
|
sl@0
|
204 |
TUint aConditionUInt)
|
sl@0
|
205 |
{
|
sl@0
|
206 |
aRef.iName = _L("Schedule created using CreateScheduleSingle");
|
sl@0
|
207 |
|
sl@0
|
208 |
CSchConditionArray* conditionList
|
sl@0
|
209 |
= CreateSingleConditionLC(aConditionUID, aConditionUInt);
|
sl@0
|
210 |
TTime ttime(Time::MaxTTime());
|
sl@0
|
211 |
TTsTime time(ttime, ETrue);
|
sl@0
|
212 |
TInt res = aScheduler.CreatePersistentSchedule(aRef, *conditionList, time);
|
sl@0
|
213 |
CleanupStack::PopAndDestroy(); // conditionList
|
sl@0
|
214 |
return res;
|
sl@0
|
215 |
}
|
sl@0
|
216 |
|
sl@0
|
217 |
// An empty schedule list.
|
sl@0
|
218 |
static TInt CreateScheduleEmpty3L(TSchedulerItemRef& aRef,
|
sl@0
|
219 |
RScheduler& aScheduler,
|
sl@0
|
220 |
const TUid&,
|
sl@0
|
221 |
TUint )
|
sl@0
|
222 |
{
|
sl@0
|
223 |
aRef.iName = _L("Empty Schedule list created");
|
sl@0
|
224 |
|
sl@0
|
225 |
CSchConditionArray* conditionList = new (ELeave) CSchConditionArray(3);
|
sl@0
|
226 |
CleanupStack::PushL(conditionList);
|
sl@0
|
227 |
TTime ttime(SchSvrHelpers::UtcTimeBasedOnOffset(0, 0, 0, 0, 0, 1));
|
sl@0
|
228 |
TTsTime time(ttime, ETrue); //1 year in the future
|
sl@0
|
229 |
TInt res = aScheduler.CreatePersistentSchedule(aRef, *conditionList, time);
|
sl@0
|
230 |
CleanupStack::PopAndDestroy(); // conditionList
|
sl@0
|
231 |
|
sl@0
|
232 |
return res;
|
sl@0
|
233 |
}
|
sl@0
|
234 |
|
sl@0
|
235 |
// A null schedule.
|
sl@0
|
236 |
static TInt CreateScheduleSingleNull4L(TSchedulerItemRef& aRef,
|
sl@0
|
237 |
RScheduler& aScheduler,
|
sl@0
|
238 |
const TUid&,
|
sl@0
|
239 |
TUint )
|
sl@0
|
240 |
{
|
sl@0
|
241 |
aRef.iName = _L("One schedule in the list with a NULL uid");
|
sl@0
|
242 |
|
sl@0
|
243 |
CSchConditionArray* conditionList
|
sl@0
|
244 |
= CreateSingleConditionLC(KNullUid, 0);
|
sl@0
|
245 |
TTime ttime(SchSvrHelpers::UtcTimeBasedOnOffset(0, 0, 0, 0, 0, 1));
|
sl@0
|
246 |
TTsTime time(ttime, ETrue); //1 year in the future
|
sl@0
|
247 |
TInt res = aScheduler.CreatePersistentSchedule(aRef, *conditionList, time);
|
sl@0
|
248 |
CleanupStack::PopAndDestroy(); // conditionList
|
sl@0
|
249 |
|
sl@0
|
250 |
return res;
|
sl@0
|
251 |
}
|
sl@0
|
252 |
|
sl@0
|
253 |
static TInt CreateScheduleMultipleL(TSchedulerItemRef& aRef, RScheduler& aScheduler)
|
sl@0
|
254 |
{
|
sl@0
|
255 |
aRef.iName = _L("Schedule created using CreateScheduleMultiple");
|
sl@0
|
256 |
|
sl@0
|
257 |
CSchConditionArray* conditionList = CreateMultipleConditionsLC();
|
sl@0
|
258 |
TTime ttime(SchSvrHelpers::UtcTimeBasedOnOffset(0, 0, 0, 0, 0, 1));
|
sl@0
|
259 |
TTsTime time(ttime, ETrue); //1 year in the future
|
sl@0
|
260 |
TInt res = aScheduler.CreatePersistentSchedule(aRef, *conditionList, time);
|
sl@0
|
261 |
CleanupStack::PopAndDestroy(); // conditionList
|
sl@0
|
262 |
return res;
|
sl@0
|
263 |
}
|
sl@0
|
264 |
|
sl@0
|
265 |
static TInt SchedulePersistentTaskL(const TDesC& aName,
|
sl@0
|
266 |
TInt& aNewId,
|
sl@0
|
267 |
TInt aScheduleId,
|
sl@0
|
268 |
RScheduler& aScheduler)
|
sl@0
|
269 |
{
|
sl@0
|
270 |
TTaskInfo taskInfo;
|
sl@0
|
271 |
taskInfo.iTaskId = aNewId;
|
sl@0
|
272 |
taskInfo.iName = aName;
|
sl@0
|
273 |
taskInfo.iPriority = 2;
|
sl@0
|
274 |
taskInfo.iRepeat = 0;
|
sl@0
|
275 |
HBufC* data = _L("the data").AllocLC();
|
sl@0
|
276 |
TInt res = aScheduler.ScheduleTask(taskInfo, *data, aScheduleId);
|
sl@0
|
277 |
aNewId = taskInfo.iTaskId;
|
sl@0
|
278 |
|
sl@0
|
279 |
CleanupStack::PopAndDestroy(); // data
|
sl@0
|
280 |
return res;
|
sl@0
|
281 |
}
|
sl@0
|
282 |
|
sl@0
|
283 |
/**
|
sl@0
|
284 |
@file
|
sl@0
|
285 |
@SYMTestCaseID SYSLIB-SCHSVR-CT-0244
|
sl@0
|
286 |
@SYMTestCaseDesc Single condition based test - UTC
|
sl@0
|
287 |
@SYMTestPriority High
|
sl@0
|
288 |
@SYMTestActions Create a condition based schedule & check schedule auto deletes
|
sl@0
|
289 |
@SYMTestExpectedResults The test must not fail.
|
sl@0
|
290 |
@SYMPREQ PREQ234
|
sl@0
|
291 |
*/
|
sl@0
|
292 |
static void DoTest1L()
|
sl@0
|
293 |
{
|
sl@0
|
294 |
TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0244 "));
|
sl@0
|
295 |
// create a simple condition based schedule, and see if it runs.
|
sl@0
|
296 |
TInt res = KErrNone;
|
sl@0
|
297 |
TheTest.Next(_L("single condition based test"));
|
sl@0
|
298 |
__UHEAP_MARK;
|
sl@0
|
299 |
|
sl@0
|
300 |
//reset the p&s variables before creating the schedule
|
sl@0
|
301 |
ResetVariablesL(0,0,0);
|
sl@0
|
302 |
TSchedulerItemRef ref1;
|
sl@0
|
303 |
TheTest.Printf(_L("Create a schedule\n"));
|
sl@0
|
304 |
res = CreateScheduleSingle1L(ref1, TheScheduler, KUidSystemCategory, KTestKey1);
|
sl@0
|
305 |
TEST2(res, KErrNone);
|
sl@0
|
306 |
|
sl@0
|
307 |
TInt task1 = 0;
|
sl@0
|
308 |
_LIT(KName1, "toothpaste");
|
sl@0
|
309 |
TheTest.Printf(_L("Schedule some tasks\n"));
|
sl@0
|
310 |
|
sl@0
|
311 |
res = SchedulePersistentTaskL(KName1, task1, ref1.iHandle, TheScheduler);
|
sl@0
|
312 |
TEST2(res, KErrNone);
|
sl@0
|
313 |
|
sl@0
|
314 |
res = TheScheduler.__DbgMarkHeap();
|
sl@0
|
315 |
User::LeaveIfError(res); //#1
|
sl@0
|
316 |
TInt scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
|
sl@0
|
317 |
TEST(scheduleCount == 1);
|
sl@0
|
318 |
|
sl@0
|
319 |
// Check that schedule is of condition type
|
sl@0
|
320 |
TScheduleType scheduleType;
|
sl@0
|
321 |
res = TheScheduler.GetScheduleTypeL(ref1.iHandle, scheduleType);
|
sl@0
|
322 |
TEST2(res, KErrNone);
|
sl@0
|
323 |
TEST(scheduleType == EConditionSchedule );
|
sl@0
|
324 |
|
sl@0
|
325 |
res = TheScheduler.__DbgMarkEnd(0);
|
sl@0
|
326 |
User::LeaveIfError(res); //#1
|
sl@0
|
327 |
|
sl@0
|
328 |
TheScheduler.Close();
|
sl@0
|
329 |
SchSvrHelpers::Pause(TheTest);
|
sl@0
|
330 |
|
sl@0
|
331 |
// wait for condition to be satisfied
|
sl@0
|
332 |
res = RProperty::Set(KUidSystemCategory, KTestKey1,10);
|
sl@0
|
333 |
User::LeaveIfError(res);
|
sl@0
|
334 |
TEST2(STaskSemaphore::WaitL(KDefaultTimeout), KErrNone);
|
sl@0
|
335 |
CleanupHelpers::KillProcess(KMinimalTaskHandler);
|
sl@0
|
336 |
|
sl@0
|
337 |
res = TheScheduler.Connect();
|
sl@0
|
338 |
TEST2(res, KErrNone);
|
sl@0
|
339 |
// Register a client with the server
|
sl@0
|
340 |
TheTest.Next(_L("===== Registering Client ====="));
|
sl@0
|
341 |
res = SchSvrHelpers::RegisterClientL(TheScheduler);
|
sl@0
|
342 |
TEST2(res, KErrNone);
|
sl@0
|
343 |
|
sl@0
|
344 |
// can't check scheduler to see if any tasks left because it's been
|
sl@0
|
345 |
// deleted as last task has completed
|
sl@0
|
346 |
|
sl@0
|
347 |
//Check that persistent schedule has auto-deleted
|
sl@0
|
348 |
|
sl@0
|
349 |
TheTest.Printf(_L("DEF46200 - Check schedule has auto deleted\n"));
|
sl@0
|
350 |
scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
|
sl@0
|
351 |
TEST(scheduleCount == 0);
|
sl@0
|
352 |
|
sl@0
|
353 |
// Attempt to delete auto-deleted schedule, should fail
|
sl@0
|
354 |
|
sl@0
|
355 |
TheTest.Printf(_L("DEF46200 - Attempting to delete schedule with id %d\n"), ref1.iHandle);
|
sl@0
|
356 |
res = TheScheduler.DeleteSchedule(ref1.iHandle);
|
sl@0
|
357 |
TEST2(res, KErrNotFound);
|
sl@0
|
358 |
|
sl@0
|
359 |
// now repeat process with singleschedule2
|
sl@0
|
360 |
ResetVariablesL(0,0,0);
|
sl@0
|
361 |
|
sl@0
|
362 |
TheTest.Printf(_L("Create another schedule\n"));
|
sl@0
|
363 |
res = CreateScheduleSingle2L(ref1, TheScheduler, KUidSystemCategory, KTestKey1);
|
sl@0
|
364 |
TEST2(res, KErrNone);
|
sl@0
|
365 |
|
sl@0
|
366 |
TheTest.Printf(_L("Create an empty schedule list\n"));
|
sl@0
|
367 |
res = CreateScheduleEmpty3L(ref1, TheScheduler, KUidSystemCategory, KTestKey1);
|
sl@0
|
368 |
TEST2(res, KErrArgument);
|
sl@0
|
369 |
|
sl@0
|
370 |
TheTest.Printf(_L("Create an empty schedule list\n"));
|
sl@0
|
371 |
res = CreateScheduleSingleNull4L(ref1, TheScheduler, KUidSystemCategory, KTestKey1);
|
sl@0
|
372 |
TEST2(res, KErrArgument);
|
sl@0
|
373 |
|
sl@0
|
374 |
res = SchedulePersistentTaskL(KName1, task1, ref1.iHandle, TheScheduler);
|
sl@0
|
375 |
TEST2(res, KErrNone);
|
sl@0
|
376 |
SchSvrHelpers::Pause(TheTest);
|
sl@0
|
377 |
|
sl@0
|
378 |
// we should have one outstanding task (without the check in
|
sl@0
|
379 |
// schtimer.cpp specifically for Time::MaxTTime() the timer would have
|
sl@0
|
380 |
// gone off immediately in the past.)
|
sl@0
|
381 |
TEST(CountTasksL(ref1.iHandle) == 1);
|
sl@0
|
382 |
|
sl@0
|
383 |
scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
|
sl@0
|
384 |
TEST(scheduleCount == 1);
|
sl@0
|
385 |
// wait for condition to be satisfied
|
sl@0
|
386 |
User::LeaveIfError(RProperty::Set(KUidSystemCategory, KTestKey1,10));
|
sl@0
|
387 |
TEST2(STaskSemaphore::WaitL(KDefaultTimeout), KErrNone);
|
sl@0
|
388 |
CleanupHelpers::KillProcess(KMinimalTaskHandler);
|
sl@0
|
389 |
|
sl@0
|
390 |
// can't check scheduler to see if any tasks left because it's been
|
sl@0
|
391 |
// deleted as last task has completed
|
sl@0
|
392 |
|
sl@0
|
393 |
TheTest.Printf(_L("DEF46200 - Check schedule has auto deleted\n"));
|
sl@0
|
394 |
scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
|
sl@0
|
395 |
TEST(scheduleCount == 0);
|
sl@0
|
396 |
|
sl@0
|
397 |
// Attempt to delete auto-deleted schedule, should fail
|
sl@0
|
398 |
|
sl@0
|
399 |
TheTest.Printf(_L("DEF46200 - Attempting to delete schedule with id %d\n"), ref1.iHandle);
|
sl@0
|
400 |
res = TheScheduler.DeleteSchedule(ref1.iHandle);
|
sl@0
|
401 |
TEST2(res, KErrNotFound);
|
sl@0
|
402 |
|
sl@0
|
403 |
SchSvrHelpers::Pause(TheTest);
|
sl@0
|
404 |
__UHEAP_MARKEND;
|
sl@0
|
405 |
}
|
sl@0
|
406 |
|
sl@0
|
407 |
/**
|
sl@0
|
408 |
@file
|
sl@0
|
409 |
@SYMTestCaseID SYSLIB-SCHSVR-CT-0245
|
sl@0
|
410 |
@SYMTestCaseDesc Multiple condition based test - UTC
|
sl@0
|
411 |
@SYMTestPriority High
|
sl@0
|
412 |
@SYMTestActions Create a condition based schedule with multiple entries, and see if it runs.
|
sl@0
|
413 |
Try auto deleting the last schedule and test for not found error.
|
sl@0
|
414 |
@SYMTestExpectedResults The test must not fail.
|
sl@0
|
415 |
@SYMPREQ PREQ234
|
sl@0
|
416 |
*/
|
sl@0
|
417 |
static void DoTest2L()
|
sl@0
|
418 |
{
|
sl@0
|
419 |
TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0245 "));
|
sl@0
|
420 |
// create a condition based schedule with multiple entries, and see if it runs.
|
sl@0
|
421 |
TInt res = KErrNone;
|
sl@0
|
422 |
TheTest.Next(_L("multiple condition based test"));
|
sl@0
|
423 |
__UHEAP_MARK;
|
sl@0
|
424 |
|
sl@0
|
425 |
//reset the p&s variables before creating the schedule
|
sl@0
|
426 |
ResetVariablesL(0,10,20);
|
sl@0
|
427 |
TSchedulerItemRef ref1;
|
sl@0
|
428 |
TheTest.Printf(_L("Create a schedule\n"));
|
sl@0
|
429 |
res = CreateScheduleMultipleL(ref1, TheScheduler);
|
sl@0
|
430 |
TEST2(res, KErrNone);
|
sl@0
|
431 |
|
sl@0
|
432 |
TInt task1 = 0;
|
sl@0
|
433 |
_LIT(KName1, "web subscription");
|
sl@0
|
434 |
TheTest.Printf(_L("Schedule some tasks\n"));
|
sl@0
|
435 |
res = SchedulePersistentTaskL(KName1, task1, ref1.iHandle, TheScheduler);
|
sl@0
|
436 |
TEST2(res, KErrNone);
|
sl@0
|
437 |
|
sl@0
|
438 |
TInt scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
|
sl@0
|
439 |
TEST(scheduleCount == 1);
|
sl@0
|
440 |
|
sl@0
|
441 |
// we should have one task scheduled to run
|
sl@0
|
442 |
CTaskInfoArray* tasks = new (ELeave) CTaskInfoArray(3);
|
sl@0
|
443 |
CleanupStack::PushL(tasks);
|
sl@0
|
444 |
GetTaskInfoL(*tasks, ref1.iHandle);
|
sl@0
|
445 |
TEST(tasks->Count() == 1);
|
sl@0
|
446 |
tasks->Reset();
|
sl@0
|
447 |
|
sl@0
|
448 |
// wait for conditions to be satisfied
|
sl@0
|
449 |
User::LeaveIfError(RProperty::Set(KUidSystemCategory, KTestKey1,10));//"=="
|
sl@0
|
450 |
User::LeaveIfError(RProperty::Set(KUidSystemCategory, KTestKey2,1234));//"!="
|
sl@0
|
451 |
User::LeaveIfError(RProperty::Set(KUidSystemCategory, KTestKey3,9));//"<"
|
sl@0
|
452 |
TEST2(STaskSemaphore::WaitL(KDefaultTimeout), KErrNone);
|
sl@0
|
453 |
CleanupHelpers::KillProcess(KMinimalTaskHandler);
|
sl@0
|
454 |
|
sl@0
|
455 |
// Can't check schedule for task info because it's gone
|
sl@0
|
456 |
|
sl@0
|
457 |
|
sl@0
|
458 |
// we should have no schedule, it has auto-deleted
|
sl@0
|
459 |
scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
|
sl@0
|
460 |
TEST(scheduleCount == 0);
|
sl@0
|
461 |
|
sl@0
|
462 |
// Reset variables
|
sl@0
|
463 |
TheTest.Printf(_L("Reseting variables"));
|
sl@0
|
464 |
ResetVariablesL(0,10,20);
|
sl@0
|
465 |
|
sl@0
|
466 |
TheTest.Printf(_L("DEF46200 - Attempting to delete schedule with id %d\n"), ref1.iHandle);
|
sl@0
|
467 |
res = TheScheduler.DeleteSchedule(ref1.iHandle);
|
sl@0
|
468 |
TEST2(res, KErrNotFound);
|
sl@0
|
469 |
scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
|
sl@0
|
470 |
TEST(scheduleCount == 0);
|
sl@0
|
471 |
|
sl@0
|
472 |
CleanupStack::PopAndDestroy(tasks);
|
sl@0
|
473 |
|
sl@0
|
474 |
SchSvrHelpers::Pause(TheTest);
|
sl@0
|
475 |
__UHEAP_MARKEND;
|
sl@0
|
476 |
}
|
sl@0
|
477 |
|
sl@0
|
478 |
/**
|
sl@0
|
479 |
@file
|
sl@0
|
480 |
@SYMTestCaseID SYSLIB-SCHSVR-CT-0246
|
sl@0
|
481 |
@SYMTestCaseDesc Error checking test - UTC
|
sl@0
|
482 |
@SYMTestPriority High
|
sl@0
|
483 |
@SYMTestActions Create a schedule with a P&S variables that doesnt exist & create a schedule with a P&S variable that isnt an integer.
|
sl@0
|
484 |
@SYMTestExpectedResults The test must not fail.
|
sl@0
|
485 |
@SYMPREQ PREQ234
|
sl@0
|
486 |
*/
|
sl@0
|
487 |
static void DoTest3L()
|
sl@0
|
488 |
{
|
sl@0
|
489 |
TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0246 "));
|
sl@0
|
490 |
// create a simple condition based schedule, and see if it runs.
|
sl@0
|
491 |
TInt res = KErrNone;
|
sl@0
|
492 |
TheTest.Next(_L("error checking test"));
|
sl@0
|
493 |
__UHEAP_MARK;
|
sl@0
|
494 |
|
sl@0
|
495 |
//reset the p&s variables before creating the schedule
|
sl@0
|
496 |
ResetVariablesL(0,0,0);
|
sl@0
|
497 |
TSchedulerItemRef ref1;
|
sl@0
|
498 |
_LIT(KName1, "toothpaste");
|
sl@0
|
499 |
|
sl@0
|
500 |
TheTest.Printf(_L("Create a schedule with a P&S variables that doesnt exist\n"));
|
sl@0
|
501 |
{
|
sl@0
|
502 |
const TUid KNonexistentUid = TUid::Uid(0x01234566);
|
sl@0
|
503 |
res = CreateScheduleSingle1L(ref1, TheScheduler, KNonexistentUid, KTestKey1);
|
sl@0
|
504 |
TEST2(res, KErrNone);
|
sl@0
|
505 |
TheTest.Printf(_L("Schedule some tasks - error should be returned\n"));
|
sl@0
|
506 |
|
sl@0
|
507 |
TTaskInfo taskInfo;
|
sl@0
|
508 |
taskInfo.iName = KName1;
|
sl@0
|
509 |
taskInfo.iPriority = 2;
|
sl@0
|
510 |
taskInfo.iRepeat = 0;
|
sl@0
|
511 |
HBufC* data = _L("the data").AllocLC();
|
sl@0
|
512 |
res = TheScheduler.ScheduleTask(taskInfo, *data, ref1.iHandle);
|
sl@0
|
513 |
// since we have created the schedule using a UID which doesn't exist
|
sl@0
|
514 |
//we should get an error
|
sl@0
|
515 |
TEST2(res, KErrArgument);
|
sl@0
|
516 |
CleanupStack::PopAndDestroy(); // data
|
sl@0
|
517 |
|
sl@0
|
518 |
TheTest.Printf(_L("Deleting schedule with id %d\n"), ref1.iHandle);
|
sl@0
|
519 |
res = TheScheduler.DeleteSchedule(ref1.iHandle);
|
sl@0
|
520 |
TEST2(res, KErrNone);
|
sl@0
|
521 |
TInt scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
|
sl@0
|
522 |
TEST(scheduleCount == 0);
|
sl@0
|
523 |
}
|
sl@0
|
524 |
|
sl@0
|
525 |
TheTest.Printf(_L("Create a schedule\n"));
|
sl@0
|
526 |
res = CreateScheduleSingle1L(ref1, TheScheduler, KUidSystemCategory, KTestKey1);
|
sl@0
|
527 |
TEST2(res, KErrNone);
|
sl@0
|
528 |
TheTest.Printf(_L("Schedule some tasks\n"));
|
sl@0
|
529 |
{
|
sl@0
|
530 |
TTaskInfo taskInfo;
|
sl@0
|
531 |
taskInfo.iName = KName1;
|
sl@0
|
532 |
taskInfo.iPriority = 2;
|
sl@0
|
533 |
taskInfo.iRepeat = 1;
|
sl@0
|
534 |
HBufC* data = _L("the data").AllocLC();
|
sl@0
|
535 |
User::LeaveIfError(TheScheduler.__DbgMarkHeap());
|
sl@0
|
536 |
res = TheScheduler.ScheduleTask(taskInfo, *data, ref1.iHandle);
|
sl@0
|
537 |
// since we have set repeat to something other than 0, we should get an error
|
sl@0
|
538 |
TEST2(res, KErrArgument);
|
sl@0
|
539 |
User::LeaveIfError(TheScheduler.__DbgMarkEnd(0));
|
sl@0
|
540 |
CleanupStack::PopAndDestroy(); // data
|
sl@0
|
541 |
}
|
sl@0
|
542 |
|
sl@0
|
543 |
SchSvrHelpers::Pause(TheTest);
|
sl@0
|
544 |
__UHEAP_MARKEND;
|
sl@0
|
545 |
}
|
sl@0
|
546 |
|
sl@0
|
547 |
/**
|
sl@0
|
548 |
@SYMTestCaseID SYSLIB-SCHSVR-CT-3245
|
sl@0
|
549 |
@SYMTestCaseDesc Persistent condition based schedule test
|
sl@0
|
550 |
@SYMTestPriority High
|
sl@0
|
551 |
@SYMTestActions Create a single persistent condition based schedule and then
|
sl@0
|
552 |
terminate the task scheduler.
|
sl@0
|
553 |
Set the condition and then launch the task scheduler with the
|
sl@0
|
554 |
condition satisfied. Check that the schedule is executed.
|
sl@0
|
555 |
@SYMTestExpectedResults Schedule must be executed and test must not panic or fail
|
sl@0
|
556 |
@SYMREQ REQ0000
|
sl@0
|
557 |
*/
|
sl@0
|
558 |
static void DoTest4L()
|
sl@0
|
559 |
{
|
sl@0
|
560 |
TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-3245 "));
|
sl@0
|
561 |
// create a persistent condition based schedule
|
sl@0
|
562 |
TInt res = KErrNone;
|
sl@0
|
563 |
TheTest.Next(_L("single condition based test"));
|
sl@0
|
564 |
__UHEAP_MARK;
|
sl@0
|
565 |
|
sl@0
|
566 |
//reset the p&s variables before creating the schedule
|
sl@0
|
567 |
ResetVariablesL(0,0,0);
|
sl@0
|
568 |
TSchedulerItemRef ref1;
|
sl@0
|
569 |
TheTest.Printf(_L("Create a test schedule\n"));
|
sl@0
|
570 |
res = CreateScheduleSingle1L(ref1, TheScheduler, KUidSystemCategory, KTestKey1);
|
sl@0
|
571 |
TEST2(res, KErrNone);
|
sl@0
|
572 |
|
sl@0
|
573 |
TInt task1 = 0;
|
sl@0
|
574 |
_LIT(KName1, "shutdown task 1");
|
sl@0
|
575 |
TheTest.Printf(_L("Schedule a persistant task\n"));
|
sl@0
|
576 |
|
sl@0
|
577 |
res = SchedulePersistentTaskL(KName1, task1, ref1.iHandle, TheScheduler);
|
sl@0
|
578 |
TEST2(res, KErrNone);
|
sl@0
|
579 |
|
sl@0
|
580 |
//Fault the server to force it to shut down
|
sl@0
|
581 |
TheScheduler.__FaultServer();
|
sl@0
|
582 |
|
sl@0
|
583 |
//close the Scheduler handle
|
sl@0
|
584 |
TheScheduler.Close();
|
sl@0
|
585 |
|
sl@0
|
586 |
SchSvrHelpers::Pause(TheTest);
|
sl@0
|
587 |
|
sl@0
|
588 |
// set condition
|
sl@0
|
589 |
res = RProperty::Set(KUidSystemCategory, KTestKey1,10);
|
sl@0
|
590 |
TEST2(res, KErrNone);
|
sl@0
|
591 |
|
sl@0
|
592 |
//Restart the scheduler with the condition for this persistant task
|
sl@0
|
593 |
//satisfied
|
sl@0
|
594 |
res = TheScheduler.Connect();
|
sl@0
|
595 |
TEST2(res, KErrNone);
|
sl@0
|
596 |
|
sl@0
|
597 |
//wait for task to be executed
|
sl@0
|
598 |
TEST2(STaskSemaphore::WaitL(KDefaultTimeout), KErrNone);
|
sl@0
|
599 |
CleanupHelpers::KillProcess(KMinimalTaskHandler);
|
sl@0
|
600 |
|
sl@0
|
601 |
SchSvrHelpers::Pause(TheTest);
|
sl@0
|
602 |
|
sl@0
|
603 |
__UHEAP_MARKEND;
|
sl@0
|
604 |
|
sl@0
|
605 |
}
|
sl@0
|
606 |
|
sl@0
|
607 |
static TInt RunTestsL()
|
sl@0
|
608 |
{
|
sl@0
|
609 |
TheTest.Next(_L("Delete old files"));
|
sl@0
|
610 |
SchSvrHelpers::DeleteScheduleFilesL();
|
sl@0
|
611 |
|
sl@0
|
612 |
TheTest.Next(_L("Create Task notification semaphore"));
|
sl@0
|
613 |
//initialise task notification semaphore
|
sl@0
|
614 |
STaskSemaphore sem;
|
sl@0
|
615 |
sem.CreateL();
|
sl@0
|
616 |
|
sl@0
|
617 |
// Connect to the server
|
sl@0
|
618 |
TheTest.Next(_L("===== Connect to Scheduler ====="));
|
sl@0
|
619 |
TInt res = TheScheduler.Connect();
|
sl@0
|
620 |
TEST2(res, KErrNone);
|
sl@0
|
621 |
// Register a client with the server
|
sl@0
|
622 |
TheTest.Next(_L("===== Registering Client ====="));
|
sl@0
|
623 |
res = SchSvrHelpers::RegisterClientL(TheScheduler);
|
sl@0
|
624 |
TEST2(res, KErrNone);
|
sl@0
|
625 |
|
sl@0
|
626 |
// Launch helper process to create P&S variables
|
sl@0
|
627 |
CreateTestVariables();
|
sl@0
|
628 |
|
sl@0
|
629 |
CActiveScheduler* scheduler = new (ELeave) CActiveScheduler();
|
sl@0
|
630 |
CleanupStack::PushL(scheduler);
|
sl@0
|
631 |
CActiveScheduler::Install(scheduler);
|
sl@0
|
632 |
|
sl@0
|
633 |
TheTest.Next(_L("Start tests"));
|
sl@0
|
634 |
DoTest1L();
|
sl@0
|
635 |
DoTest2L();
|
sl@0
|
636 |
DoTest3L();
|
sl@0
|
637 |
DoTest4L();
|
sl@0
|
638 |
|
sl@0
|
639 |
TheTest.Next(_L("Tidying up"));
|
sl@0
|
640 |
CleanupStack::PopAndDestroy(scheduler);
|
sl@0
|
641 |
//close handle to semaphore
|
sl@0
|
642 |
sem.Close();
|
sl@0
|
643 |
|
sl@0
|
644 |
//Tidying up so next test will be clear.
|
sl@0
|
645 |
TheTest.Next(_L("Delete all schedules"));
|
sl@0
|
646 |
SchSvrHelpers::DeleteAllSchedulesL(TheScheduler);
|
sl@0
|
647 |
SchSvrHelpers::Pause(TheTest, 2);
|
sl@0
|
648 |
TheTest.Next(_L("Delete old files\n"));
|
sl@0
|
649 |
SchSvrHelpers::DeleteScheduleFilesL();
|
sl@0
|
650 |
|
sl@0
|
651 |
TheScheduler.Close();
|
sl@0
|
652 |
return KErrNone;
|
sl@0
|
653 |
}
|
sl@0
|
654 |
|
sl@0
|
655 |
GLDEF_C TInt E32Main()
|
sl@0
|
656 |
{
|
sl@0
|
657 |
__UHEAP_MARK;
|
sl@0
|
658 |
TheTest.Start(_L("TC_TSCH_CONDITION_UTC"));
|
sl@0
|
659 |
TheTest.Title();
|
sl@0
|
660 |
TheCleanup = CTrapCleanup::New();
|
sl@0
|
661 |
|
sl@0
|
662 |
//If the previous test fails, SCHSVR.exe may stay in memory.
|
sl@0
|
663 |
TRAPD(error,CleanupHelpers::TestCleanupL());
|
sl@0
|
664 |
TEST2(error, KErrNone);
|
sl@0
|
665 |
TheTest(TheFsSession.Connect() == KErrNone);;
|
sl@0
|
666 |
TRAP(error, RunTestsL());
|
sl@0
|
667 |
TEST2(error, KErrNone);
|
sl@0
|
668 |
TRAP(error,CleanupHelpers::TestCleanupL());
|
sl@0
|
669 |
TEST2(error, KErrNone);
|
sl@0
|
670 |
delete TheCleanup;
|
sl@0
|
671 |
|
sl@0
|
672 |
TheFsSession.Close();
|
sl@0
|
673 |
TheTest.End();
|
sl@0
|
674 |
TheTest.Close();
|
sl@0
|
675 |
__UHEAP_MARKEND;
|
sl@0
|
676 |
|
sl@0
|
677 |
return KErrNone;
|
sl@0
|
678 |
}
|