sl@0
|
1 |
// Copyright (c) 2005-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 <e32test.h>
|
sl@0
|
17 |
#include <f32file.h>
|
sl@0
|
18 |
#include <tz.h>
|
sl@0
|
19 |
#include <schinfo.h>
|
sl@0
|
20 |
#include <schinfointernal.h>
|
sl@0
|
21 |
#include <schtask.h>
|
sl@0
|
22 |
#include "Thelpers.h"
|
sl@0
|
23 |
|
sl@0
|
24 |
_LIT(KHBufTest, "This is a CScheduledTask test");
|
sl@0
|
25 |
_LIT(KTestName, "Scheduled Task");
|
sl@0
|
26 |
RTest TheTest(KTestName);
|
sl@0
|
27 |
|
sl@0
|
28 |
// persistent file for externalize and internalize test
|
sl@0
|
29 |
_LIT(KFileName,"_:\\CSheduledTask.dat");
|
sl@0
|
30 |
static TBuf<32> fileName;
|
sl@0
|
31 |
|
sl@0
|
32 |
LOCAL_D RFs TheFsSession;
|
sl@0
|
33 |
|
sl@0
|
34 |
//Test macroses and functions
|
sl@0
|
35 |
static void Check(TInt aValue, TInt aLine)
|
sl@0
|
36 |
{
|
sl@0
|
37 |
if(!aValue)
|
sl@0
|
38 |
{
|
sl@0
|
39 |
(void)TheFsSession.Delete(fileName);
|
sl@0
|
40 |
TheTest(EFalse, aLine);
|
sl@0
|
41 |
}
|
sl@0
|
42 |
}
|
sl@0
|
43 |
static void Check(TInt aValue, TInt aExpected, TInt aLine)
|
sl@0
|
44 |
{
|
sl@0
|
45 |
if(aValue != aExpected)
|
sl@0
|
46 |
{
|
sl@0
|
47 |
RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
|
sl@0
|
48 |
(void)TheFsSession.Delete(fileName);
|
sl@0
|
49 |
TheTest(EFalse, aLine);
|
sl@0
|
50 |
}
|
sl@0
|
51 |
}
|
sl@0
|
52 |
#define TEST(arg) ::Check((arg), __LINE__)
|
sl@0
|
53 |
#define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
|
sl@0
|
54 |
|
sl@0
|
55 |
|
sl@0
|
56 |
|
sl@0
|
57 |
/**
|
sl@0
|
58 |
@file
|
sl@0
|
59 |
@SYMTestCaseID SYSLIB-SCHSVR-CT-0202
|
sl@0
|
60 |
@SYMTestCaseDesc Check that externalize executes correctly for tasks with local based times
|
sl@0
|
61 |
@SYMTestPriority low
|
sl@0
|
62 |
@SYMTestActions Create a local time based instance of CSheduledTask and externalize
|
sl@0
|
63 |
@SYMTestExpectedResults The test must not fail.
|
sl@0
|
64 |
@SYMPREQ PREQ234
|
sl@0
|
65 |
*/
|
sl@0
|
66 |
LOCAL_D void doLocalTimeExternalizeTestL()
|
sl@0
|
67 |
{
|
sl@0
|
68 |
TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0202 CScheduledTask Externalize Test (local time) "));
|
sl@0
|
69 |
|
sl@0
|
70 |
TheTest.Printf(_L("Tests with timezone set to Europe, London"));
|
sl@0
|
71 |
RTz tz;
|
sl@0
|
72 |
tz.Connect();
|
sl@0
|
73 |
CTzId* tzId = CTzId::NewL(2592); //set the timezone to Europe/London
|
sl@0
|
74 |
CleanupStack::PushL(tzId);
|
sl@0
|
75 |
tz.SetTimeZoneL(*tzId);
|
sl@0
|
76 |
|
sl@0
|
77 |
TheTest.Printf(_L("Tests with DST on"));
|
sl@0
|
78 |
//set the current utc time to 8.55am, 15 May 2005 -Daylight savings apply on this date
|
sl@0
|
79 |
TDateTime date(2005, EMay, 15, 8, 55, 0, 0);
|
sl@0
|
80 |
TTime time(date);
|
sl@0
|
81 |
TInt err = SchSvrHelpers::SetUTCTimeL(time);
|
sl@0
|
82 |
TEST(err == 0);
|
sl@0
|
83 |
User::After(KOneSecond * 3);
|
sl@0
|
84 |
// set data for CScheduledTask construction
|
sl@0
|
85 |
TTaskInfo taskInfo;
|
sl@0
|
86 |
|
sl@0
|
87 |
HBufC* taskdata = HBufC::NewLC(KHBufTest().Length());
|
sl@0
|
88 |
TPtr pData(taskdata->Des());
|
sl@0
|
89 |
pData.Append(KHBufTest);
|
sl@0
|
90 |
|
sl@0
|
91 |
TSecurityInfo securityInfo;
|
sl@0
|
92 |
|
sl@0
|
93 |
CScheduledTask* extTask = new(ELeave) CScheduledTask(taskInfo,
|
sl@0
|
94 |
taskdata,
|
sl@0
|
95 |
ETimeSchedule,
|
sl@0
|
96 |
securityInfo);
|
sl@0
|
97 |
CleanupStack::Pop(taskdata); //taskdata now owned by newTask
|
sl@0
|
98 |
CleanupStack::PushL(extTask);
|
sl@0
|
99 |
|
sl@0
|
100 |
// set due time, 63284489700000000 microseconds since 1st Jan 0 AD
|
sl@0
|
101 |
// This is local time
|
sl@0
|
102 |
TDateTime extDate(2005, EMay, 15, 8, 55, 0, 0);
|
sl@0
|
103 |
TTime extTime(extDate);
|
sl@0
|
104 |
TTime extDueTime(extTime);
|
sl@0
|
105 |
extTask->OnDue(TTsTime(extDueTime,EFalse));
|
sl@0
|
106 |
|
sl@0
|
107 |
// externalize
|
sl@0
|
108 |
RFile extFile;
|
sl@0
|
109 |
TFileName extFileName(fileName);
|
sl@0
|
110 |
TEST2(extFile.Replace(TheFsSession,extFileName,EFileWrite), KErrNone);
|
sl@0
|
111 |
RFileBuf extBuf;
|
sl@0
|
112 |
CleanupClosePushL(extBuf);
|
sl@0
|
113 |
extBuf.Attach(extFile);
|
sl@0
|
114 |
RWriteStream extStream(&extBuf);
|
sl@0
|
115 |
|
sl@0
|
116 |
TRAP(err, extTask->ExternalizeL(extStream));
|
sl@0
|
117 |
TEST(err == KErrNone);
|
sl@0
|
118 |
|
sl@0
|
119 |
CleanupStack::PopAndDestroy(3, tzId);
|
sl@0
|
120 |
}
|
sl@0
|
121 |
|
sl@0
|
122 |
/**
|
sl@0
|
123 |
@file
|
sl@0
|
124 |
@SYMTestCaseID SYSLIB-SCHSVR-CT-0203
|
sl@0
|
125 |
@SYMTestCaseDesc Check that internalize executes correctly for tasks with local based times
|
sl@0
|
126 |
@SYMTestPriority low
|
sl@0
|
127 |
@SYMTestActions Create a local time based instance of CSheduledTask which does an internalize
|
sl@0
|
128 |
@SYMTestExpectedResults The test must not fail.
|
sl@0
|
129 |
@SYMPREQ PREQ234
|
sl@0
|
130 |
*/
|
sl@0
|
131 |
LOCAL_D void doLocalTimeInternalizeTestL()
|
sl@0
|
132 |
{
|
sl@0
|
133 |
TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0203 CScheduledTask Internalize Test (local time) "));
|
sl@0
|
134 |
|
sl@0
|
135 |
// internalize
|
sl@0
|
136 |
RFile intFile;
|
sl@0
|
137 |
TFileName intFileName(fileName);
|
sl@0
|
138 |
TEST2(intFile.Open(TheFsSession,intFileName,EFileRead), KErrNone);
|
sl@0
|
139 |
RFileBuf intBuf;
|
sl@0
|
140 |
CleanupClosePushL(intBuf);
|
sl@0
|
141 |
intBuf.Attach(intFile);
|
sl@0
|
142 |
RReadStream intStream(&intBuf);
|
sl@0
|
143 |
|
sl@0
|
144 |
CScheduledTask* intTask = CScheduledTask::NewLC(intStream);
|
sl@0
|
145 |
|
sl@0
|
146 |
// due date/time is 8.55am, 15 May 2005 -Daylight savings apply on this date
|
sl@0
|
147 |
TTsTime ttime = intTask->ValidUntil();
|
sl@0
|
148 |
TTime time = ttime.GetLocalTime();
|
sl@0
|
149 |
TDateTime dtime = time.DateTime();
|
sl@0
|
150 |
|
sl@0
|
151 |
TEST(dtime.Year() == 2005);
|
sl@0
|
152 |
TEST(dtime.Month() == EMay);
|
sl@0
|
153 |
TEST(dtime.Day() == 15);
|
sl@0
|
154 |
TEST(dtime.Hour() == 8);
|
sl@0
|
155 |
TEST(dtime.Minute() == 55);
|
sl@0
|
156 |
TEST(dtime.Second() == 0);
|
sl@0
|
157 |
TEST(dtime.MicroSecond() == 0);
|
sl@0
|
158 |
|
sl@0
|
159 |
// test offset - 3600 seconds (1 hour) because time of device is in BST
|
sl@0
|
160 |
TTimeIntervalSeconds offset(3600);
|
sl@0
|
161 |
TEST(ttime.GetOffset() == offset);
|
sl@0
|
162 |
|
sl@0
|
163 |
// test difference between returned values
|
sl@0
|
164 |
TTime utcTime = intTask->ValidUntil().GetUtcTime();
|
sl@0
|
165 |
TTime localTime = intTask->ValidUntil().GetLocalTime();
|
sl@0
|
166 |
Int64 t = localTime.Int64() - utcTime.Int64();
|
sl@0
|
167 |
TTimeIntervalSeconds diff((localTime.Int64() - utcTime.Int64())/1000000);
|
sl@0
|
168 |
TEST(diff == offset);
|
sl@0
|
169 |
|
sl@0
|
170 |
// test that this instance is home time and not UTC
|
sl@0
|
171 |
TEST(ttime.IsUtc() == EFalse);
|
sl@0
|
172 |
|
sl@0
|
173 |
// test data
|
sl@0
|
174 |
HBufC* data = const_cast<HBufC*>(&(intTask->Data()));
|
sl@0
|
175 |
TEST(data->Compare(KHBufTest) == 0);
|
sl@0
|
176 |
|
sl@0
|
177 |
CleanupStack::PopAndDestroy(2, &intBuf);
|
sl@0
|
178 |
}
|
sl@0
|
179 |
|
sl@0
|
180 |
/**
|
sl@0
|
181 |
@file
|
sl@0
|
182 |
@SYMTestCaseID SYSLIB-SCHSVR-CT-0239
|
sl@0
|
183 |
@SYMTestCaseDesc Check that externalize executes correctly for tasks with UTC based times
|
sl@0
|
184 |
@SYMTestPriority low
|
sl@0
|
185 |
@SYMTestActions Create a UTC time based instance of CSheduledTask and externalize
|
sl@0
|
186 |
@SYMTestExpectedResults The test must not fail.
|
sl@0
|
187 |
@SYMPREQ PREQ234
|
sl@0
|
188 |
*/
|
sl@0
|
189 |
LOCAL_D void doUtcExternalizeTestL()
|
sl@0
|
190 |
{
|
sl@0
|
191 |
TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0239 CScheduledTask Externalize Test (UTC) "));
|
sl@0
|
192 |
|
sl@0
|
193 |
TheTest.Printf(_L("Tests with timezone set to Europe, London"));
|
sl@0
|
194 |
RTz tz;
|
sl@0
|
195 |
tz.Connect();
|
sl@0
|
196 |
CTzId* tzId = CTzId::NewL(2592); //set the timezone to Europe/London
|
sl@0
|
197 |
CleanupStack::PushL(tzId);
|
sl@0
|
198 |
tz.SetTimeZoneL(*tzId);
|
sl@0
|
199 |
|
sl@0
|
200 |
TheTest.Printf(_L("Tests with DST on"));
|
sl@0
|
201 |
//set the current utc time to 8.55am, 15 May 2005 -Daylight savings apply on this date
|
sl@0
|
202 |
TDateTime date(2005, EMay, 15, 8, 55, 0, 0);
|
sl@0
|
203 |
TTime time(date);
|
sl@0
|
204 |
TInt err = SchSvrHelpers::SetUTCTimeL(time);
|
sl@0
|
205 |
TEST(err == 0);
|
sl@0
|
206 |
User::After(KOneSecond * 3);
|
sl@0
|
207 |
// set data for CScheduledTask construction
|
sl@0
|
208 |
TTaskInfo taskInfo;
|
sl@0
|
209 |
|
sl@0
|
210 |
HBufC* taskdata = HBufC::NewLC(KHBufTest().Length());
|
sl@0
|
211 |
TPtr pData(taskdata->Des());
|
sl@0
|
212 |
pData.Append(KHBufTest);
|
sl@0
|
213 |
|
sl@0
|
214 |
TSecurityInfo securityInfo;
|
sl@0
|
215 |
|
sl@0
|
216 |
CScheduledTask* extTask = new(ELeave) CScheduledTask(taskInfo,
|
sl@0
|
217 |
taskdata,
|
sl@0
|
218 |
ETimeSchedule,
|
sl@0
|
219 |
securityInfo);
|
sl@0
|
220 |
CleanupStack::Pop(taskdata); //taskdata now owned by newTask
|
sl@0
|
221 |
CleanupStack::PushL(extTask);
|
sl@0
|
222 |
|
sl@0
|
223 |
// set due time, 63284489700000000 microseconds since 1st Jan 0 AD
|
sl@0
|
224 |
// This is UTC time
|
sl@0
|
225 |
TDateTime extDate(2005, EMay, 15, 8, 55, 0, 0);
|
sl@0
|
226 |
TTime extTime(extDate);
|
sl@0
|
227 |
TTime extDueTime(extTime);
|
sl@0
|
228 |
extTask->OnDue(TTsTime(extDueTime,ETrue));
|
sl@0
|
229 |
|
sl@0
|
230 |
// externalize
|
sl@0
|
231 |
RFile extFile;
|
sl@0
|
232 |
TFileName extFileName(fileName);
|
sl@0
|
233 |
TEST2(extFile.Replace(TheFsSession,extFileName,EFileWrite), KErrNone);
|
sl@0
|
234 |
RFileBuf extBuf;
|
sl@0
|
235 |
CleanupClosePushL(extBuf);
|
sl@0
|
236 |
extBuf.Attach(extFile);
|
sl@0
|
237 |
RWriteStream extStream(&extBuf);
|
sl@0
|
238 |
|
sl@0
|
239 |
TRAP(err, extTask->ExternalizeL(extStream));
|
sl@0
|
240 |
TEST(err == KErrNone);
|
sl@0
|
241 |
|
sl@0
|
242 |
CleanupStack::PopAndDestroy(3, tzId);
|
sl@0
|
243 |
}
|
sl@0
|
244 |
|
sl@0
|
245 |
/**
|
sl@0
|
246 |
@file
|
sl@0
|
247 |
@SYMTestCaseID SYSLIB-SCHSVR-CT-0240
|
sl@0
|
248 |
@SYMTestCaseDesc Check that internalize executes correctly for tasks with UTC times
|
sl@0
|
249 |
@SYMTestPriority low
|
sl@0
|
250 |
@SYMTestActions Create a UTC based instance of CSheduledTask which does an internalize
|
sl@0
|
251 |
@SYMTestExpectedResults The test must not fail.
|
sl@0
|
252 |
@SYMPREQ PREQ234
|
sl@0
|
253 |
*/
|
sl@0
|
254 |
LOCAL_D void doUtcInternalizeTestL()
|
sl@0
|
255 |
{
|
sl@0
|
256 |
TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0240 CScheduledTask Internalize Test (UTC) "));
|
sl@0
|
257 |
|
sl@0
|
258 |
// internalize
|
sl@0
|
259 |
RFile intFile;
|
sl@0
|
260 |
TFileName intFileName(fileName);
|
sl@0
|
261 |
TEST2(intFile.Open(TheFsSession,intFileName,EFileRead), KErrNone);
|
sl@0
|
262 |
RFileBuf intBuf;
|
sl@0
|
263 |
CleanupClosePushL(intBuf);
|
sl@0
|
264 |
intBuf.Attach(intFile);
|
sl@0
|
265 |
RReadStream intStream(&intBuf);
|
sl@0
|
266 |
|
sl@0
|
267 |
CScheduledTask* intTask = CScheduledTask::NewLC(intStream);
|
sl@0
|
268 |
|
sl@0
|
269 |
// due date/time is 8.55am, 15 May 2005 -Daylight savings apply on this date
|
sl@0
|
270 |
TTsTime ttime = intTask->ValidUntil();
|
sl@0
|
271 |
TTime time = ttime.GetUtcTime();
|
sl@0
|
272 |
TDateTime dtime = time.DateTime();
|
sl@0
|
273 |
|
sl@0
|
274 |
TEST(dtime.Year() == 2005);
|
sl@0
|
275 |
TEST(dtime.Month() == EMay);
|
sl@0
|
276 |
TEST(dtime.Day() == 15);
|
sl@0
|
277 |
TEST(dtime.Hour() == 8);
|
sl@0
|
278 |
TEST(dtime.Minute() == 55);
|
sl@0
|
279 |
TEST(dtime.Second() == 0);
|
sl@0
|
280 |
TEST(dtime.MicroSecond() == 0);
|
sl@0
|
281 |
|
sl@0
|
282 |
// test offset - should be zero because the object is UTC based
|
sl@0
|
283 |
TTimeIntervalSeconds offset(0);
|
sl@0
|
284 |
TEST(ttime.GetOffset() == offset);
|
sl@0
|
285 |
|
sl@0
|
286 |
// test difference between returned values
|
sl@0
|
287 |
TTime utcTime = intTask->ValidUntil().GetUtcTime();
|
sl@0
|
288 |
TTime localTime = intTask->ValidUntil().GetLocalTime();
|
sl@0
|
289 |
Int64 t = localTime.Int64() - utcTime.Int64();
|
sl@0
|
290 |
TTimeIntervalSeconds diff((localTime.Int64() - utcTime.Int64())/1000000);
|
sl@0
|
291 |
// difference should be the kernel offset from UTC
|
sl@0
|
292 |
offset = User::UTCOffset();
|
sl@0
|
293 |
TEST(diff == offset);
|
sl@0
|
294 |
|
sl@0
|
295 |
// test that this instance is UTC and not local time based
|
sl@0
|
296 |
TEST(ttime.IsUtc());
|
sl@0
|
297 |
|
sl@0
|
298 |
// test data
|
sl@0
|
299 |
HBufC* data = const_cast<HBufC*>(&(intTask->Data()));
|
sl@0
|
300 |
TEST(data->Compare(KHBufTest) == 0);
|
sl@0
|
301 |
|
sl@0
|
302 |
CleanupStack::PopAndDestroy(2, &intBuf);
|
sl@0
|
303 |
}
|
sl@0
|
304 |
|
sl@0
|
305 |
|
sl@0
|
306 |
static void RunTestsL()
|
sl@0
|
307 |
{
|
sl@0
|
308 |
doLocalTimeExternalizeTestL();
|
sl@0
|
309 |
doLocalTimeInternalizeTestL();
|
sl@0
|
310 |
doUtcExternalizeTestL();
|
sl@0
|
311 |
doUtcInternalizeTestL();
|
sl@0
|
312 |
}
|
sl@0
|
313 |
|
sl@0
|
314 |
//***********************************************************************************
|
sl@0
|
315 |
GLDEF_C TInt E32Main()
|
sl@0
|
316 |
{
|
sl@0
|
317 |
CTrapCleanup* tc = CTrapCleanup::New();
|
sl@0
|
318 |
TEST(tc != NULL);
|
sl@0
|
319 |
|
sl@0
|
320 |
__UHEAP_MARK;
|
sl@0
|
321 |
|
sl@0
|
322 |
fileName.Copy(KFileName);
|
sl@0
|
323 |
fileName[0] = RFs::GetSystemDriveChar();
|
sl@0
|
324 |
|
sl@0
|
325 |
TInt err = TheFsSession.Connect();
|
sl@0
|
326 |
TEST(err == KErrNone);
|
sl@0
|
327 |
|
sl@0
|
328 |
TheTest.Title();
|
sl@0
|
329 |
TheTest.Start(_L("Unit tests for CScheduledTask"));
|
sl@0
|
330 |
TRAP(err, ::RunTestsL())
|
sl@0
|
331 |
TEST(err == KErrNone);
|
sl@0
|
332 |
|
sl@0
|
333 |
(void)TheFsSession.Delete(fileName);
|
sl@0
|
334 |
TheFsSession.Close();
|
sl@0
|
335 |
TheTest.End();
|
sl@0
|
336 |
TheTest.Close();
|
sl@0
|
337 |
|
sl@0
|
338 |
__UHEAP_MARKEND;
|
sl@0
|
339 |
|
sl@0
|
340 |
delete tc;
|
sl@0
|
341 |
|
sl@0
|
342 |
return(KErrNone);
|
sl@0
|
343 |
}
|