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 |
// tschsvrsclient1.cpp
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
#include <e32base.h>
|
sl@0
|
19 |
#include <e32debug.h>
|
sl@0
|
20 |
|
sl@0
|
21 |
#include <csch_cli.h>
|
sl@0
|
22 |
#include <schinfointernal.h>
|
sl@0
|
23 |
#include "Thelpers.h"
|
sl@0
|
24 |
#include "TestUtils.h"
|
sl@0
|
25 |
|
sl@0
|
26 |
_LIT(KTestName, "Client with different UID test");
|
sl@0
|
27 |
RTest TheTest(KTestName);
|
sl@0
|
28 |
static RScheduler TheScheduler;
|
sl@0
|
29 |
|
sl@0
|
30 |
|
sl@0
|
31 |
typedef CArrayFixFlat<TScheduleEntryInfo> CSchEntryInfoArray;
|
sl@0
|
32 |
typedef CArrayFixFlat<TTaskInfo> CTaskInfoArray;
|
sl@0
|
33 |
typedef CArrayFixFlat<TSchedulerItemRef> CSchItemRefArray;
|
sl@0
|
34 |
typedef CArrayFixFlat<TTaskSchedulerCondition> CSchConditionArray;
|
sl@0
|
35 |
|
sl@0
|
36 |
|
sl@0
|
37 |
static CSchEntryInfoArray* CreateScheduleArrayLC()
|
sl@0
|
38 |
{
|
sl@0
|
39 |
CSchEntryInfoArray* entryList = new (ELeave) CSchEntryInfoArray(3);
|
sl@0
|
40 |
CleanupStack::PushL(entryList);
|
sl@0
|
41 |
|
sl@0
|
42 |
TScheduleEntryInfo entry1;
|
sl@0
|
43 |
entry1.iStartTime = SchSvrHelpers::TimeBasedOnOffset(0, 20); // 20m from "now"
|
sl@0
|
44 |
entry1.iInterval = 1;
|
sl@0
|
45 |
entry1.iIntervalType = EDaily;
|
sl@0
|
46 |
entry1.iValidityPeriod = 20;
|
sl@0
|
47 |
entryList->AppendL(entry1);
|
sl@0
|
48 |
|
sl@0
|
49 |
return entryList;
|
sl@0
|
50 |
}
|
sl@0
|
51 |
|
sl@0
|
52 |
static CSchConditionArray* CreateSingleConditionLC()
|
sl@0
|
53 |
{
|
sl@0
|
54 |
CSchConditionArray* conditionList = new (ELeave) CSchConditionArray(3);
|
sl@0
|
55 |
CleanupStack::PushL(conditionList);
|
sl@0
|
56 |
|
sl@0
|
57 |
const TUid KTestUid = TUid::Uid(0x12345678);
|
sl@0
|
58 |
|
sl@0
|
59 |
TTaskSchedulerCondition condition1;
|
sl@0
|
60 |
condition1.iCategory = KTestUid;
|
sl@0
|
61 |
condition1.iKey = 1;
|
sl@0
|
62 |
condition1.iState = 10;
|
sl@0
|
63 |
condition1.iType = TTaskSchedulerCondition::EEquals;
|
sl@0
|
64 |
conditionList->AppendL(condition1);
|
sl@0
|
65 |
|
sl@0
|
66 |
return conditionList;
|
sl@0
|
67 |
}
|
sl@0
|
68 |
/**
|
sl@0
|
69 |
@SYMTestCaseID SYSLIB-SCHSVR-CT-1343
|
sl@0
|
70 |
@SYMTestCaseDesc Client with different UID test
|
sl@0
|
71 |
@SYMTestPriority High
|
sl@0
|
72 |
@SYMTestActions Connect to Scheduler,
|
sl@0
|
73 |
Tests RScheduler::EditSchedule(),RScheduler::DisableSchedule(),RScheduler::EnableSchedule()
|
sl@0
|
74 |
RScheduler::ScheduleTask(),RScheduler::GetScheduleRefsL(),RScheduler::GetScheduleL(),
|
sl@0
|
75 |
RScheduler::GetTaskRefsL(),RScheduler::GetTaskDataSize(),RScheduler::GetTaskInfoL(),
|
sl@0
|
76 |
RScheduler::GetScheduleTypeL(),RScheduler::DeleteTask(),RScheduler::DeleteSchedule() functions
|
sl@0
|
77 |
@SYMTestExpectedResults Test must not fail
|
sl@0
|
78 |
@SYMREQ REQ0000
|
sl@0
|
79 |
*/
|
sl@0
|
80 |
void DoExecuteL(TInt aScheduleHandle,
|
sl@0
|
81 |
TInt aTaskHandle,
|
sl@0
|
82 |
TInt aExpectedError,
|
sl@0
|
83 |
TInt aExpectedScheduleCount,
|
sl@0
|
84 |
TInt aExpectedTaskCount)
|
sl@0
|
85 |
{
|
sl@0
|
86 |
|
sl@0
|
87 |
TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-1343 Connect to Scheduler "));
|
sl@0
|
88 |
TInt res = TheScheduler.Connect();
|
sl@0
|
89 |
TEST2(res, KErrNone);
|
sl@0
|
90 |
TheTest.Next(_L("Registering Client"));
|
sl@0
|
91 |
TEST2(SchSvrHelpers::RegisterClientL(TheScheduler), KErrNone);
|
sl@0
|
92 |
|
sl@0
|
93 |
//Edit Schedule
|
sl@0
|
94 |
TheTest.Next(_L("Testing EditSchedule"));
|
sl@0
|
95 |
CSchEntryInfoArray* scheduleArray = CreateScheduleArrayLC();
|
sl@0
|
96 |
res = TheScheduler.EditSchedule(aScheduleHandle, *scheduleArray);
|
sl@0
|
97 |
CleanupStack::PopAndDestroy(); //scheduleArray
|
sl@0
|
98 |
TEST2(res, aExpectedError);
|
sl@0
|
99 |
//condition API - only check if we are expecting an error
|
sl@0
|
100 |
if(aExpectedError != KErrNone)
|
sl@0
|
101 |
{
|
sl@0
|
102 |
CSchConditionArray* conditionList = CreateSingleConditionLC();
|
sl@0
|
103 |
TTime time = SchSvrHelpers::TimeBasedOnOffset(0, 0, 0, 0, 0, 1); //1 year in the future
|
sl@0
|
104 |
res = TheScheduler.EditSchedule(aScheduleHandle, *conditionList, time);
|
sl@0
|
105 |
CleanupStack::PopAndDestroy(); // conditionList
|
sl@0
|
106 |
TEST2(res, aExpectedError);
|
sl@0
|
107 |
}
|
sl@0
|
108 |
//Disable/Enable Schedule
|
sl@0
|
109 |
TheTest.Next(_L("Testing DisableSchedule and EnableSchedule"));
|
sl@0
|
110 |
res = TheScheduler.DisableSchedule(aScheduleHandle);
|
sl@0
|
111 |
TEST2(res, aExpectedError);
|
sl@0
|
112 |
res = TheScheduler.EnableSchedule(aScheduleHandle);
|
sl@0
|
113 |
TEST2(res, aExpectedError);
|
sl@0
|
114 |
|
sl@0
|
115 |
//ScheduleTask
|
sl@0
|
116 |
TheTest.Next(_L("Testing ScheduleTask"));
|
sl@0
|
117 |
TTaskInfo taskInfo;
|
sl@0
|
118 |
taskInfo.iName = _L("MyTask");
|
sl@0
|
119 |
taskInfo.iPriority = 2;
|
sl@0
|
120 |
taskInfo.iTaskId = 0;
|
sl@0
|
121 |
taskInfo.iRepeat = 1;
|
sl@0
|
122 |
HBufC* data = _L("Task Data I cant schedule").AllocLC();
|
sl@0
|
123 |
res = TheScheduler.ScheduleTask(taskInfo, *data, aScheduleHandle);
|
sl@0
|
124 |
TEST2(res, aExpectedError);
|
sl@0
|
125 |
CleanupStack::PopAndDestroy(); // data
|
sl@0
|
126 |
|
sl@0
|
127 |
if(res == KErrNone)
|
sl@0
|
128 |
{
|
sl@0
|
129 |
res = TheScheduler.DeleteTask(taskInfo.iTaskId);
|
sl@0
|
130 |
TEST2(res, KErrNone);
|
sl@0
|
131 |
}
|
sl@0
|
132 |
|
sl@0
|
133 |
//GetScheduleRefs
|
sl@0
|
134 |
TheTest.Next(_L("Testing GetScheduleRefsL"));
|
sl@0
|
135 |
CSchItemRefArray* refs = new (ELeave) CSchItemRefArray(3);
|
sl@0
|
136 |
CleanupStack::PushL(refs);
|
sl@0
|
137 |
res = TheScheduler.GetScheduleRefsL(*refs, EAllSchedules);
|
sl@0
|
138 |
TEST2(res, KErrNone);
|
sl@0
|
139 |
TInt count = refs->Count();
|
sl@0
|
140 |
TEST2(count, aExpectedScheduleCount);
|
sl@0
|
141 |
|
sl@0
|
142 |
//GetSchedule
|
sl@0
|
143 |
TheTest.Next(_L("Testing GetScheduleL"));
|
sl@0
|
144 |
CSchEntryInfoArray* entries = new (ELeave) CSchEntryInfoArray(3);
|
sl@0
|
145 |
CleanupStack::PushL(entries);
|
sl@0
|
146 |
CTaskInfoArray* tasks = new (ELeave) CTaskInfoArray(3);
|
sl@0
|
147 |
CleanupStack::PushL(tasks);
|
sl@0
|
148 |
|
sl@0
|
149 |
TTime nextTimeScheduleIsDue;
|
sl@0
|
150 |
TScheduleState state;
|
sl@0
|
151 |
res = TheScheduler.GetScheduleL(aScheduleHandle,
|
sl@0
|
152 |
state,
|
sl@0
|
153 |
*entries,
|
sl@0
|
154 |
*tasks,
|
sl@0
|
155 |
nextTimeScheduleIsDue);
|
sl@0
|
156 |
TEST2(res, aExpectedError);
|
sl@0
|
157 |
//condition API - only check if we are expecting an error
|
sl@0
|
158 |
if(aExpectedError != KErrNone)
|
sl@0
|
159 |
{
|
sl@0
|
160 |
CSchConditionArray* conditions = new (ELeave) CSchConditionArray(3);
|
sl@0
|
161 |
CleanupStack::PushL(conditions);
|
sl@0
|
162 |
res = TheScheduler.GetScheduleL(aScheduleHandle,
|
sl@0
|
163 |
state,
|
sl@0
|
164 |
*conditions,
|
sl@0
|
165 |
nextTimeScheduleIsDue,
|
sl@0
|
166 |
*tasks);
|
sl@0
|
167 |
CleanupStack::PopAndDestroy(conditions);
|
sl@0
|
168 |
TEST2(res, aExpectedError);
|
sl@0
|
169 |
}
|
sl@0
|
170 |
|
sl@0
|
171 |
//GetTaskRefs
|
sl@0
|
172 |
TheTest.Next(_L("Testing GetScheduleL"));
|
sl@0
|
173 |
res = TheScheduler.GetTaskRefsL(*refs, EAllSchedules, EAllTasks);
|
sl@0
|
174 |
TEST2(res, KErrNone);
|
sl@0
|
175 |
count = refs->Count();
|
sl@0
|
176 |
TEST2(count, aExpectedTaskCount);
|
sl@0
|
177 |
|
sl@0
|
178 |
// TaskDataSize
|
sl@0
|
179 |
TheTest.Next(_L("Testing GetTaskDataSize"));
|
sl@0
|
180 |
TInt taskSize = 0;
|
sl@0
|
181 |
res = TheScheduler.GetTaskDataSize(aTaskHandle, taskSize);
|
sl@0
|
182 |
TEST2(res, aExpectedError);
|
sl@0
|
183 |
|
sl@0
|
184 |
// GetTaskInfo
|
sl@0
|
185 |
TheTest.Next(_L("Testing GetTaskInfoL"));
|
sl@0
|
186 |
if(aExpectedError != KErrNone)
|
sl@0
|
187 |
//use dummy size for task as we actually didnt get it from above
|
sl@0
|
188 |
// if we were expected as error
|
sl@0
|
189 |
taskSize = 10;
|
sl@0
|
190 |
HBufC* taskData = HBufC::NewLC(taskSize);
|
sl@0
|
191 |
TPtr pTaskData = taskData->Des();
|
sl@0
|
192 |
|
sl@0
|
193 |
TTime scheduleNextDueTime;
|
sl@0
|
194 |
TTaskInfo taskFromServer;
|
sl@0
|
195 |
TSchedulerItemRef scheduleReference;
|
sl@0
|
196 |
|
sl@0
|
197 |
res = TheScheduler.GetTaskInfoL(aTaskHandle,
|
sl@0
|
198 |
taskFromServer,
|
sl@0
|
199 |
pTaskData,
|
sl@0
|
200 |
scheduleReference,
|
sl@0
|
201 |
scheduleNextDueTime);
|
sl@0
|
202 |
CleanupStack::PopAndDestroy(taskData);
|
sl@0
|
203 |
TEST2(res, aExpectedError);
|
sl@0
|
204 |
|
sl@0
|
205 |
TScheduleType scheduleType;
|
sl@0
|
206 |
res = TheScheduler.GetScheduleTypeL(aScheduleHandle, scheduleType);
|
sl@0
|
207 |
TEST2(res, aExpectedError);
|
sl@0
|
208 |
|
sl@0
|
209 |
//DeleteTask
|
sl@0
|
210 |
TheTest.Next(_L("Testing TaskSchedule"));
|
sl@0
|
211 |
res = TheScheduler.DeleteTask(aTaskHandle);
|
sl@0
|
212 |
TEST2(res, aExpectedError);
|
sl@0
|
213 |
|
sl@0
|
214 |
//Delete Schedule
|
sl@0
|
215 |
TheTest.Next(_L("Testing DeleteSchedule"));
|
sl@0
|
216 |
res = TheScheduler.DeleteSchedule(aScheduleHandle);
|
sl@0
|
217 |
TEST2(res, aExpectedError);
|
sl@0
|
218 |
|
sl@0
|
219 |
CleanupStack::PopAndDestroy(tasks);
|
sl@0
|
220 |
CleanupStack::PopAndDestroy(entries);
|
sl@0
|
221 |
CleanupStack::PopAndDestroy(refs);
|
sl@0
|
222 |
|
sl@0
|
223 |
TheScheduler.Close();
|
sl@0
|
224 |
|
sl@0
|
225 |
}
|
sl@0
|
226 |
|
sl@0
|
227 |
LOCAL_D TInt Execute(TInt aScheduleHandle,
|
sl@0
|
228 |
TInt aTaskHandle,
|
sl@0
|
229 |
TInt aExpectedError,
|
sl@0
|
230 |
TInt aExpectedScheduleCount,
|
sl@0
|
231 |
TInt aExpectedTaskCount)
|
sl@0
|
232 |
{
|
sl@0
|
233 |
TInt err = KErrNoMemory;
|
sl@0
|
234 |
CTrapCleanup* cleanup=CTrapCleanup::New(); //can fail
|
sl@0
|
235 |
if (cleanup)
|
sl@0
|
236 |
{
|
sl@0
|
237 |
|
sl@0
|
238 |
TheTest.Start(_L("TSchSvrClient"));
|
sl@0
|
239 |
TheTest.Title();
|
sl@0
|
240 |
err = KErrNone;
|
sl@0
|
241 |
TRAP(err, DoExecuteL(aScheduleHandle,
|
sl@0
|
242 |
aTaskHandle,
|
sl@0
|
243 |
aExpectedError,
|
sl@0
|
244 |
aExpectedScheduleCount,
|
sl@0
|
245 |
aExpectedTaskCount))
|
sl@0
|
246 |
delete cleanup;
|
sl@0
|
247 |
|
sl@0
|
248 |
TheTest.End();
|
sl@0
|
249 |
TheTest.Close();
|
sl@0
|
250 |
|
sl@0
|
251 |
}
|
sl@0
|
252 |
return err;
|
sl@0
|
253 |
}
|
sl@0
|
254 |
|
sl@0
|
255 |
|
sl@0
|
256 |
//***********************************************************************************
|
sl@0
|
257 |
static TInt Str2Int(const TDesC& aStr)
|
sl@0
|
258 |
{
|
sl@0
|
259 |
TLex16 lex(aStr);
|
sl@0
|
260 |
TInt val = 0;
|
sl@0
|
261 |
lex.Val(val);
|
sl@0
|
262 |
return val;
|
sl@0
|
263 |
}
|
sl@0
|
264 |
|
sl@0
|
265 |
static TBuf<20> ExtractInt(const TDesC& aBuf, TInt& aExtractedInt)
|
sl@0
|
266 |
{
|
sl@0
|
267 |
TBuf<20> buf = aBuf.Right(aBuf.Length() - aBuf.Locate(':')-1);
|
sl@0
|
268 |
TBuf<5> handle;
|
sl@0
|
269 |
handle.FillZ();
|
sl@0
|
270 |
handle = buf.Left(buf.Locate(':'));
|
sl@0
|
271 |
aExtractedInt = Str2Int(handle);
|
sl@0
|
272 |
return buf;
|
sl@0
|
273 |
}
|
sl@0
|
274 |
|
sl@0
|
275 |
GLDEF_C TInt E32Main()
|
sl@0
|
276 |
{
|
sl@0
|
277 |
TBuf<30> cmd;
|
sl@0
|
278 |
User::CommandLine(cmd);
|
sl@0
|
279 |
// schedule Handle is first
|
sl@0
|
280 |
TInt scheduleHandle=0, taskHandle=0, errCode=0, schCount=0, taskCount=0;
|
sl@0
|
281 |
cmd = ExtractInt(cmd, scheduleHandle);
|
sl@0
|
282 |
// task Handle is second
|
sl@0
|
283 |
cmd = ExtractInt(cmd, taskHandle);
|
sl@0
|
284 |
// expected error code is third
|
sl@0
|
285 |
cmd = ExtractInt(cmd, errCode);
|
sl@0
|
286 |
// expected schedule count (based on this exe UID/Capability is fourth
|
sl@0
|
287 |
cmd = ExtractInt(cmd, schCount);
|
sl@0
|
288 |
// expected task count (based on this exe UID/Capability is fourth
|
sl@0
|
289 |
cmd = ExtractInt(cmd, taskCount);
|
sl@0
|
290 |
|
sl@0
|
291 |
return Execute(scheduleHandle, taskHandle, errCode, schCount, taskCount);
|
sl@0
|
292 |
}
|
sl@0
|
293 |
|
sl@0
|
294 |
|