|
1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 |
|
17 #include <e32test.h> |
|
18 #include <tz.h> |
|
19 #include <vtzrules.h> |
|
20 #include <e32math.h> |
|
21 #include <tzconverter.h> |
|
22 #include "testserver.h" |
|
23 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
24 #include <tzusernames.h> |
|
25 #include <tzuserdefineddata.h> |
|
26 #endif |
|
27 #include <tzlocalizedcityrecord.h> |
|
28 #include <tzlocalizedtimezonerecord.h> |
|
29 #include "tzidinternal.h" |
|
30 |
|
31 |
|
32 _LIT(KTzUserDataDb, "c:\\private\\1020383e\\SQLite__tzuserdata.db"); |
|
33 |
|
34 const TInt KPrintFreq=500; |
|
35 |
|
36 static RPIMTestServer Serv; |
|
37 // Forward class references. |
|
38 class CTzUserDataTest; |
|
39 |
|
40 |
|
41 _LIT(KTestName,"User-Defined TZ Data Test Suite"); |
|
42 RTest test(KTestName); |
|
43 |
|
44 |
|
45 _LIT8(KTzLondon, "Europe/London"); |
|
46 |
|
47 |
|
48 typedef void (CTzUserDataTest::*OOMTestFunction)(); |
|
49 |
|
50 |
|
51 class CTzUserDataTest : public CBase |
|
52 { |
|
53 public: |
|
54 enum TOOMTest |
|
55 { |
|
56 EClientOOM, |
|
57 EServerOOM |
|
58 }; |
|
59 |
|
60 enum TTest |
|
61 { |
|
62 ETimeConversion, |
|
63 EDayLightSave, |
|
64 EDeleteCurrentUserRule, |
|
65 EUpdateCachedTz, |
|
66 EDeleteCachedTz, |
|
67 EPersistence |
|
68 }; |
|
69 |
|
70 static CTzUserDataTest* NewLC(); |
|
71 ~CTzUserDataTest(); |
|
72 |
|
73 // Basic test - client operations on user-defined time zones. |
|
74 void TestBasicUserDataL(); |
|
75 void TestOutOfMemoryBehaviourL(TOOMTest aOOMTest); |
|
76 void TestTimeZoneRulesL(TTest aWhatToTest); |
|
77 void TestServerResponseToChangesL(); |
|
78 void TestReadIdsL(RTz& aRTz); |
|
79 void TestIdsL(RTz& aRTz); |
|
80 void TestTimeConversionL(); |
|
81 void TestDaylightSaveL(); |
|
82 void TestDeleteCurrentTimeZoneL(RTz& aTz); |
|
83 void TestCurrentTimeZonePersistenceL(RTz& aTz); |
|
84 void TestUpdateCachedUserTimeZoneL(RTz& aTz); |
|
85 void TestDeletedCachedUserTimeZoneL(RTz& aTz); |
|
86 void BoundaryTestL(); |
|
87 void TestTzIdReusabilityL(); |
|
88 void NullTestL(); |
|
89 void TestShortTzId(RTz& aRTz); |
|
90 |
|
91 private: |
|
92 CTzUserDataTest(); |
|
93 |
|
94 // Basic operations. |
|
95 void TestCreateUserDefinedTzL(); |
|
96 void TestUpdateUserDefinedTzL(); |
|
97 void TestDeleteUserDefinedTzL(); |
|
98 void ReadIdsAndTestL(RTz& aRTz, TBool aCheckId); |
|
99 |
|
100 // Create user-defined time zone. |
|
101 void CreateTzAndCheckL(TInt aOldOffset, TInt aNewOffset, RTz& aRTz, TTest aWhatToTest); |
|
102 CTzId* CreateUserDefinedTzL(TInt16 aStandardOffset,TInt16 aDSTOffset, TBool aCheck); |
|
103 void CreateUserTzBasedOnLondonRuleL(RTz& aRTz, TTest aWhatToTest); |
|
104 void CreateUserTzBasedOnShanghaiRuleL(RTz& aRTz, TTest aWhatToTest); |
|
105 CTzUserNames* CreateUserDefinedTzNamesLC(); |
|
106 CTzRules* CreateUserDefinedTzLC(TInt16 aStandardOffset,TInt16 aDSTOffset); |
|
107 |
|
108 // OOM tests. |
|
109 void CreateOOML(); |
|
110 void ReadOOML(); |
|
111 void GetIdsOOML(); |
|
112 void UpdateOOML(); |
|
113 void DeleteOOML(); |
|
114 void OOMTestL(OOMTestFunction aFunction, TOOMTest aOOMTest); |
|
115 |
|
116 // TZ Server response to changes. |
|
117 void DeleteCurrentTzL(RTz& aTz); |
|
118 void UpdateCurrentTzL(RTz& aTz,TInt aOldOffSet, TInt aNewOffSet); |
|
119 void DeleteCurrentUserTzL(RTz& aTz, TTest aWhatToTest); |
|
120 void UpdateCurrentUserTzL(RTz& aTz); |
|
121 void CreateUserTzAndSetCurrentTimeToL(RTz& aTz, TInt aStandardOffSet, TInt aDSTOffset); |
|
122 void CachedUserTimeZoneL(RTz& aRTz, TTest aWhatToTest); |
|
123 |
|
124 // Utility methods. |
|
125 void CreateString(TDes& aString); |
|
126 TBool CompareArray(const RPointerArray<CTzId>& aIds1, const RPointerArray<CTzId>& aIds2); |
|
127 TBool CompareNames(const CTzUserNames& aName1, const CTzUserNames& aNames); |
|
128 void TestDaylightSavingStateL(CTzId& aTzId, const RArray<TTime>& times, TBool aIsOn, RTz& aRTz); |
|
129 void TestUtcOffsetL(CTzId& aTzId,const CTzRules& rules, const RArray<TTime>& times, TInt aOffset, RTz& aRTz); |
|
130 void CheckTimeZoneL(const CTzId& aId, const CTzRules& aRules, const CTzUserNames& aNames); |
|
131 |
|
132 void ResetTzUserDataL(); |
|
133 |
|
134 private: |
|
135 RPointerArray<CTzId> iTzIds; //Used for transfering time zone IDs in delete and update test. |
|
136 CTzUserData* iUserData; |
|
137 TInt64 iSeed; |
|
138 }; |
|
139 |
|
140 |
|
141 CTzUserDataTest* CTzUserDataTest::NewLC() |
|
142 { |
|
143 CTzUserDataTest* self = new (ELeave) CTzUserDataTest(); |
|
144 CleanupStack::PushL(self); |
|
145 return (self); |
|
146 } |
|
147 |
|
148 |
|
149 CTzUserDataTest::CTzUserDataTest() |
|
150 :iSeed(100) |
|
151 { |
|
152 } |
|
153 |
|
154 |
|
155 CTzUserDataTest::~CTzUserDataTest() |
|
156 { |
|
157 TRAP_IGNORE(ResetTzUserDataL()); |
|
158 delete iUserData; |
|
159 } |
|
160 |
|
161 |
|
162 LOCAL_D void ResetTimeZoneToLondonL() |
|
163 { |
|
164 RTz tz; |
|
165 User::LeaveIfError(tz.Connect()); |
|
166 CleanupClosePushL(tz); |
|
167 |
|
168 CTzId* id = CTzId::NewL(KTzLondon); |
|
169 CleanupStack::PushL(id); |
|
170 tz.SetTimeZoneL(*id); |
|
171 CleanupStack::PopAndDestroy(2, &tz); |
|
172 } |
|
173 |
|
174 |
|
175 LOCAL_D void ResetAndDestroyTzIdArray(TAny* aPtr) |
|
176 { |
|
177 RPointerArray<CTzId>* ids = static_cast<RPointerArray<CTzId>*>(aPtr); |
|
178 if (ids) |
|
179 { |
|
180 ids->ResetAndDestroy(); |
|
181 } |
|
182 } |
|
183 |
|
184 |
|
185 void CTzUserDataTest::CreateString(TDes& aString) |
|
186 { |
|
187 for (TInt i(0) ; i < 10 ; ++i) |
|
188 { |
|
189 // Add random upper and lower case letters |
|
190 aString.Append( 'A' + (Math::Rand(iSeed) % 26) ); |
|
191 } |
|
192 } |
|
193 |
|
194 |
|
195 TBool CTzUserDataTest::CompareArray(const RPointerArray<CTzId>& aIds1, const RPointerArray<CTzId>& aIds2) |
|
196 { |
|
197 TInt count1 = aIds1.Count(); |
|
198 TInt count2 = aIds2.Count(); |
|
199 test(count1 == count2); |
|
200 |
|
201 TBool isEqual = ETrue; |
|
202 TInt ii=0; |
|
203 |
|
204 while(ii<count1 && isEqual) |
|
205 { |
|
206 isEqual = EFalse; |
|
207 for (TInt jj=0; jj<count2; ++jj) |
|
208 { |
|
209 if(aIds1[ii]==aIds2[jj]) |
|
210 { |
|
211 isEqual = ETrue; |
|
212 break; |
|
213 } |
|
214 } |
|
215 ++ii; |
|
216 } |
|
217 return isEqual; |
|
218 } |
|
219 |
|
220 |
|
221 TBool CTzUserDataTest::CompareNames(const CTzUserNames& aNames1, const CTzUserNames& aNames2) |
|
222 { |
|
223 if (aNames1.StandardName() != aNames2.StandardName()) |
|
224 return EFalse; |
|
225 if (aNames1.ShortStandardName() != aNames2.ShortStandardName()) |
|
226 return EFalse; |
|
227 if (aNames1.DaylightSaveName() != aNames2.DaylightSaveName()) |
|
228 return EFalse; |
|
229 if (aNames1.ShortDaylightSaveName() != aNames2.ShortDaylightSaveName()) |
|
230 return EFalse; |
|
231 if (aNames1.CityName() != aNames2.CityName()) |
|
232 return EFalse; |
|
233 if (aNames1.RegionName() != aNames2.RegionName()) |
|
234 return EFalse; |
|
235 |
|
236 return ETrue; |
|
237 } |
|
238 |
|
239 |
|
240 void CTzUserDataTest::TestUtcOffsetL(CTzId& aTzId, const CTzRules& rules, const RArray<TTime>& times, TInt aOffset, RTz& aRTz ) |
|
241 { |
|
242 aRTz.SetTimeZoneL(aTzId); |
|
243 |
|
244 TInt count = times.Count(); |
|
245 |
|
246 for(TInt ii=0; ii<count; ++ii) |
|
247 { |
|
248 test (aOffset == rules.GetOffsetL(times[ii], ETzUtcTimeReference)); |
|
249 TTime utc = times[ii]; |
|
250 aRTz.ConvertToUniversalTime(utc); |
|
251 TTimeIntervalMinutes minutes; |
|
252 times[ii].MinutesFrom(utc, minutes); |
|
253 test (minutes == TTimeIntervalMinutes(aOffset)); |
|
254 } |
|
255 } |
|
256 |
|
257 |
|
258 void CTzUserDataTest::TestDaylightSavingStateL(CTzId& aTzId, const RArray<TTime>& times, TBool aIsOn, RTz& aRTz) |
|
259 { |
|
260 aRTz.SetTimeZoneL(aTzId); |
|
261 TInt count = times.Count(); |
|
262 for(TInt ii=0; ii<count; ++ii) |
|
263 { |
|
264 test (aIsOn == aRTz.IsDaylightSavingOnL(aTzId, times[ii])); |
|
265 } |
|
266 } |
|
267 |
|
268 |
|
269 void CTzUserDataTest::ResetTzUserDataL() |
|
270 { |
|
271 RTz tz; |
|
272 User::LeaveIfError(tz.Connect()); |
|
273 CleanupClosePushL(tz); |
|
274 CTzUserData* userdata = CTzUserData::NewL(tz); |
|
275 CleanupStack::PushL(userdata); |
|
276 userdata->GetTzIdsL(iTzIds); |
|
277 TInt count = iTzIds.Count(); |
|
278 for (TInt ii=0; ii<count; ++ii) |
|
279 { |
|
280 if(ii%KPrintFreq == 0) |
|
281 { |
|
282 test.Printf(_L("Deleted %d time zones in the database\n"), ii); |
|
283 } |
|
284 |
|
285 userdata->DeleteL(*iTzIds[ii]); |
|
286 } |
|
287 CleanupStack::PopAndDestroy(2, &tz); |
|
288 |
|
289 iTzIds.ResetAndDestroy(); |
|
290 } |
|
291 |
|
292 |
|
293 CTzId* CTzUserDataTest::CreateUserDefinedTzL(TInt16 aStandardOffset,TInt16 aDSTOffset, TBool aCheck) |
|
294 { |
|
295 CTzRules* rules = CreateUserDefinedTzLC(aStandardOffset, aDSTOffset); |
|
296 CTzUserNames* names = CreateUserDefinedTzNamesLC(); |
|
297 CTzId* id = iUserData->CreateL(*rules, *names); |
|
298 CleanupStack::PushL(id); |
|
299 if(aCheck) |
|
300 { |
|
301 CheckTimeZoneL(*id, *rules, *names); |
|
302 } |
|
303 CleanupStack::Pop(id); |
|
304 CleanupStack::PopAndDestroy(2, rules); |
|
305 return id; |
|
306 } |
|
307 |
|
308 |
|
309 void CTzUserDataTest::CheckTimeZoneL(const CTzId& aId, const CTzRules& aRules, const CTzUserNames& aNames) |
|
310 { |
|
311 CTzRules* rulesGet = iUserData->ReadRulesL(aId); |
|
312 CleanupStack::PushL(rulesGet); |
|
313 test(aRules.IsEqualTo(*rulesGet)); |
|
314 CleanupStack::PopAndDestroy(rulesGet); |
|
315 |
|
316 CTzUserNames* namesGet = iUserData->ReadNamesL(aId); |
|
317 CleanupStack::PushL(namesGet); |
|
318 test (CompareNames(aNames, *namesGet)); |
|
319 CleanupStack::PopAndDestroy(namesGet); |
|
320 } |
|
321 |
|
322 |
|
323 void CTzUserDataTest::CreateUserTzBasedOnLondonRuleL(RTz& aRTz, TTest aWhatToTest) |
|
324 { |
|
325 test.Next(_L("Test Creation user-defined time zone based on London rules")); |
|
326 //create a new rule which doesn't have DST saving. |
|
327 TTime start (TDateTime(2010, ESeptember, 0, 0, 0, 0, 0)); |
|
328 TInt year = start.DateTime().Year(); |
|
329 TMonth month = start.DateTime().Month(); |
|
330 TInt day = start.DateTime().Day(); |
|
331 TTzRule newrule(year, 9999, 0, 0, month, ETzFixedDate, day, 0, ETzWallTimeReference, 120); |
|
332 |
|
333 //Get the existing london rule |
|
334 _LIT8(KTimeNone, "Europe/London"); |
|
335 |
|
336 CTzId* londonId = CTzId::NewL(KTimeNone()); |
|
337 CleanupStack::PushL(londonId); |
|
338 CTzRules* userrule = aRTz.GetTimeZoneRulesL(*londonId, 0, 9999, ETzUtcTimeReference); |
|
339 CleanupStack::PopAndDestroy(londonId); |
|
340 |
|
341 //Use London rule to create a new user-defined rule |
|
342 TInt count = userrule->Count(); |
|
343 |
|
344 //Since the last two rules (TTzRule objects one for summer rule one for winter rule) in existing database covers the years in which a new rule starts. |
|
345 //The client has to amend the ending years of those two rules before adding a new rule. |
|
346 //We set the ending year for last two rules to 2009 since the new rule starts on 2010 |
|
347 |
|
348 TTzRule lastRule = (*userrule)[count-1]; |
|
349 TDateTime dateTimeLast = lastRule.iTo.iTime.DateTime(); |
|
350 dateTimeLast.SetYear(2009); |
|
351 lastRule.iTo.iTime = dateTimeLast; |
|
352 |
|
353 TTzRule lastSecondRule = (*userrule)[count-2]; |
|
354 TDateTime dateTimeLastSecond = lastSecondRule.iTo.iTime.DateTime(); |
|
355 dateTimeLastSecond.SetYear(2009); |
|
356 lastSecondRule.iTo.iTime = dateTimeLastSecond; |
|
357 |
|
358 CleanupStack::PushL(userrule); |
|
359 //Remove last two existing rules |
|
360 userrule->RemoveRule(count-1); |
|
361 userrule->RemoveRule(count-2); |
|
362 |
|
363 //Add two rules whoes ending years have been amended |
|
364 userrule->AddRuleL(lastRule); |
|
365 userrule->AddRuleL(lastSecondRule); |
|
366 |
|
367 //Add the new rule |
|
368 userrule->AddRuleL(newrule); |
|
369 //userrule->AddRuleL(newrule);//add the new rule which doesn't have DST |
|
370 |
|
371 CTzUserNames* newRuleNames = CreateUserDefinedTzNamesLC(); |
|
372 CTzId* id = iUserData->CreateL(*userrule, *newRuleNames); |
|
373 CleanupStack::PushL(id); |
|
374 iTzIds.AppendL(id); |
|
375 CleanupStack::Pop(id); |
|
376 CheckTimeZoneL(*id, *userrule, *newRuleNames); |
|
377 CleanupStack::PopAndDestroy(newRuleNames); |
|
378 |
|
379 RArray<TTime> timesOn; |
|
380 CleanupClosePushL(timesOn); |
|
381 RArray<TTime> timesOff; |
|
382 CleanupClosePushL(timesOff); |
|
383 |
|
384 // Check UTC offset and DST. |
|
385 TTime check = TDateTime(1998, ESeptember, 0, 0, 0, 0, 0); |
|
386 timesOn.AppendL(check); |
|
387 check = TDateTime(2005, ESeptember, 0, 0, 0, 0, 0); |
|
388 timesOn.AppendL(check); |
|
389 check = TDateTime(2009, ESeptember, 0, 0, 0, 0, 0); |
|
390 timesOn.AppendL(check); |
|
391 |
|
392 check = TDateTime(2010, ESeptember, 0, 3, 0, 0, 0); |
|
393 timesOff.AppendL(check); |
|
394 check = TDateTime(2015, ESeptember, 0, 3, 0, 0, 0); |
|
395 timesOff.AppendL(check); |
|
396 check = TDateTime(2020, ESeptember, 0, 3, 0, 0, 0); |
|
397 timesOff.AppendL(check); |
|
398 |
|
399 if(aWhatToTest==ETimeConversion) |
|
400 { |
|
401 TestUtcOffsetL(*id,*userrule, timesOn, 60, aRTz); |
|
402 TestUtcOffsetL(*id,*userrule, timesOff, 0, aRTz); |
|
403 } |
|
404 else if(aWhatToTest==EDayLightSave) |
|
405 { |
|
406 TestDaylightSavingStateL(*id, timesOn, ETrue, aRTz); |
|
407 TestDaylightSavingStateL(*id, timesOff, EFalse, aRTz); |
|
408 } |
|
409 |
|
410 CleanupStack::PopAndDestroy(3, userrule); |
|
411 } |
|
412 |
|
413 |
|
414 void CTzUserDataTest::CreateUserTzBasedOnShanghaiRuleL(RTz& aRTz, TTest aWhatToTest) |
|
415 { |
|
416 _LIT8(KTimeNone, "Asia/Shanghai"); |
|
417 |
|
418 CTzId* shanghaiId = CTzId::NewL(KTimeNone()); |
|
419 CleanupStack::PushL(shanghaiId); |
|
420 |
|
421 CTzRules* shanghaiRule = aRTz.GetTimeZoneRulesL(*shanghaiId, 0, 9999, ETzUtcTimeReference); |
|
422 CleanupStack::PopAndDestroy(shanghaiId); |
|
423 |
|
424 // Last rule: 00:00:000 Date:1/01/1987 Time: 23:59:59:000 Date:31/12/1991 Old=480 New=540 Ch=0 |
|
425 TTime dston (TDateTime(2010, EMarch, 0, 0, 0, 0, 0)); |
|
426 TTime dstoff (TDateTime(2010, ESeptember, 0, 0, 0, 0, 0)); |
|
427 TMonth monthOn = dston.DateTime().Month(); |
|
428 TInt dayOn = dston.DateTime().Day(); |
|
429 TMonth monthOff = dstoff.DateTime().Month(); |
|
430 TInt dayOff = dstoff.DateTime().Day(); |
|
431 |
|
432 test.Next(_L("Test Creation user-defined time zone based on Shanghai rules")); |
|
433 |
|
434 TTzRule dstOn(2010, 9999, 480, 540, monthOn, ETzFixedDate, dayOn, 0, ETzWallTimeReference, 120); |
|
435 TTzRule dstOff (2010, 9999, 540, 480, monthOff, ETzFixedDate, dayOff, 0, ETzWallTimeReference, 120); |
|
436 |
|
437 CleanupStack::PushL(shanghaiRule); |
|
438 shanghaiRule->AddRuleL(dstOff);//add the new rule which have DST |
|
439 shanghaiRule->AddRuleL(dstOn); |
|
440 CTzUserNames* newRuleNames = CreateUserDefinedTzNamesLC(); |
|
441 |
|
442 CTzId* id = iUserData->CreateL(*shanghaiRule, *newRuleNames); |
|
443 CleanupStack::PushL(id); |
|
444 iTzIds.AppendL(id); |
|
445 CleanupStack::Pop(id); |
|
446 |
|
447 CheckTimeZoneL(*id, *shanghaiRule, *newRuleNames); |
|
448 |
|
449 // Check UTC offset and DST. |
|
450 RArray<TTime> timesOn; |
|
451 CleanupClosePushL(timesOn); |
|
452 RArray<TTime> timesOff; |
|
453 CleanupClosePushL(timesOff); |
|
454 |
|
455 TTime check = TDateTime(1998, ESeptember, 0, 3, 0, 0, 0); |
|
456 timesOff.AppendL(check); |
|
457 check = TDateTime(2005, ESeptember, 0, 3, 0, 0, 0); |
|
458 timesOff.AppendL(check); |
|
459 check = TDateTime(2020, ESeptember, 0, 3, 0, 0, 0); |
|
460 timesOff.AppendL(check); |
|
461 |
|
462 check = TDateTime(2011, EAugust, 0, 0, 0, 0, 0); |
|
463 timesOn.AppendL(check); |
|
464 check = TDateTime(2015, EAugust, 0, 0, 0, 0, 0); |
|
465 timesOn.AppendL(check); |
|
466 check = TDateTime(2020, EAugust, 0, 0, 0, 0, 0); |
|
467 timesOn.AppendL(check); |
|
468 |
|
469 if(aWhatToTest==ETimeConversion) |
|
470 { |
|
471 TestUtcOffsetL(*id,*shanghaiRule, timesOn, 540, aRTz); |
|
472 TestUtcOffsetL(*id,*shanghaiRule, timesOff, 480, aRTz); |
|
473 } |
|
474 else if(aWhatToTest==EDayLightSave) |
|
475 { |
|
476 TestDaylightSavingStateL(*id, timesOn, ETrue, aRTz); |
|
477 TestDaylightSavingStateL(*id, timesOff, EFalse, aRTz); |
|
478 } |
|
479 |
|
480 CleanupStack::PopAndDestroy(4, shanghaiRule); |
|
481 } |
|
482 |
|
483 |
|
484 CTzRules* CTzUserDataTest::CreateUserDefinedTzLC(TInt16 aStandardOffset,TInt16 aDSTOffset) |
|
485 { |
|
486 TTime dston (TDateTime(2005, EMarch, 0, 0, 0, 0, 0)); |
|
487 TTime dstoff (TDateTime(2005, ESeptember, 0, 0, 0, 0, 0)); |
|
488 TMonth monthOn = dston.DateTime().Month(); |
|
489 TInt dayOn = dston.DateTime().Day(); |
|
490 TMonth monthOff = dstoff.DateTime().Month(); |
|
491 TInt dayOff = dstoff.DateTime().Day(); |
|
492 |
|
493 TTzRule dstOff(0, 9999, aStandardOffset, aDSTOffset, monthOn, ETzFixedDate, dayOn, 0, ETzWallTimeReference, 120); |
|
494 TTzRule dstOn (0, 9999, aDSTOffset, aStandardOffset, monthOff, ETzFixedDate, dayOff, 0, ETzWallTimeReference, 120); |
|
495 |
|
496 CTzRules* rules = CTzRules::NewL(0, 9999); |
|
497 CleanupStack::PushL(rules); |
|
498 rules->AddRuleL(dstOff); |
|
499 rules->AddRuleL(dstOn); |
|
500 return rules; |
|
501 } |
|
502 |
|
503 |
|
504 CTzUserNames* CTzUserDataTest::CreateUserDefinedTzNamesLC() |
|
505 { |
|
506 TBuf<10> standardName; |
|
507 CreateString(standardName); |
|
508 |
|
509 TBuf<10> shortStandardName; |
|
510 CreateString(shortStandardName); |
|
511 |
|
512 TBuf<10> dayLightSaveName; |
|
513 CreateString(dayLightSaveName); |
|
514 |
|
515 TBuf<10> shortDayLightSaveName; |
|
516 CreateString(shortDayLightSaveName); |
|
517 |
|
518 TBuf<10> cityName; |
|
519 CreateString(cityName); |
|
520 |
|
521 TBuf<10> regionName; |
|
522 CreateString(regionName); |
|
523 |
|
524 return CTzUserNames::NewLC(standardName, shortStandardName, dayLightSaveName, shortDayLightSaveName, cityName, regionName); |
|
525 } |
|
526 |
|
527 |
|
528 void CTzUserDataTest::CreateTzAndCheckL(TInt aOldOffset, TInt aNewOffset, RTz& aRTz, TTest aWhatToTest) |
|
529 { |
|
530 /* On the day: |
|
531 |
|
532 TTime dston (TDateTime(2005, EMarch, 0, 0, 0, 0, 0)); |
|
533 TTime dstoff (TDateTime(2005, ESeptember, 0, 0, 0, 0, 0)); |
|
534 |
|
535 After two hours DST changes which should be repeated every year |
|
536 */ |
|
537 RArray<TTime> timesOn; |
|
538 CleanupClosePushL(timesOn); |
|
539 RArray<TTime> timesOff; |
|
540 CleanupClosePushL(timesOff); |
|
541 |
|
542 TTime check = TDateTime(1920, EMarch, 0, 0, 0, 0, 0); |
|
543 timesOff.AppendL(check); |
|
544 check = TDateTime(2005, EMarch, 0, 0, 0, 0, 0); |
|
545 timesOff.AppendL(check); |
|
546 check = TDateTime(2020, EMarch, 0, 0, 0, 0, 0); |
|
547 timesOff.AppendL(check); |
|
548 |
|
549 check = TDateTime(1920, EMarch, 0, 3, 0, 0, 0); |
|
550 timesOn.AppendL(check); |
|
551 check = TDateTime(2005, EMarch, 0, 3, 0, 0, 0); |
|
552 timesOn.AppendL(check); |
|
553 check = TDateTime(2020, EMarch, 0, 3, 0, 0, 0); |
|
554 timesOn.AppendL(check); |
|
555 |
|
556 CTzId* id = CreateUserDefinedTzL(aOldOffset, aNewOffset, ETrue); |
|
557 CleanupStack::PushL(id); |
|
558 CTzRules* rules = iUserData->ReadRulesL(*id); |
|
559 CleanupStack::PushL(rules); |
|
560 |
|
561 if (aWhatToTest==ETimeConversion) |
|
562 { |
|
563 TestUtcOffsetL(*id,*rules, timesOn, aNewOffset, aRTz); |
|
564 TestUtcOffsetL(*id,*rules, timesOff, aOldOffset, aRTz); |
|
565 } |
|
566 else if (aWhatToTest==EDayLightSave) |
|
567 { |
|
568 TBool isDSTon = aOldOffset != aNewOffset; |
|
569 TestDaylightSavingStateL(*id, timesOn, isDSTon, aRTz); |
|
570 TestDaylightSavingStateL(*id, timesOff, EFalse, aRTz); |
|
571 } |
|
572 |
|
573 CleanupStack::PopAndDestroy(4, ×On); |
|
574 } |
|
575 |
|
576 |
|
577 void CTzUserDataTest::CreateOOML() |
|
578 { |
|
579 CTzId* id = CreateUserDefinedTzL(60, 60, EFalse); |
|
580 delete id; |
|
581 } |
|
582 |
|
583 |
|
584 void CTzUserDataTest::ReadOOML() |
|
585 { |
|
586 CTzRules* rule = iUserData->ReadRulesL(*iTzIds[0]); |
|
587 CleanupStack::PushL(rule); |
|
588 CTzUserNames* newNames = iUserData->ReadNamesL(*iTzIds[0]); |
|
589 CleanupStack::PopAndDestroy(rule); |
|
590 delete newNames; |
|
591 } |
|
592 |
|
593 |
|
594 void CTzUserDataTest::GetIdsOOML() |
|
595 { |
|
596 RPointerArray<CTzId> ids; |
|
597 CleanupStack::PushL(TCleanupItem(ResetAndDestroyTzIdArray, &ids)); |
|
598 iUserData->GetTzIdsL(ids); |
|
599 CleanupStack::PopAndDestroy(&ids); |
|
600 } |
|
601 |
|
602 |
|
603 void CTzUserDataTest::UpdateOOML() |
|
604 { |
|
605 CTzRules* rules = CreateUserDefinedTzLC(0, 0); |
|
606 CTzUserNames* newNames = CreateUserDefinedTzNamesLC(); |
|
607 iUserData->UpdateL(*(iTzIds[0]), *rules, *newNames); |
|
608 CleanupStack::PopAndDestroy(2, rules); |
|
609 } |
|
610 |
|
611 |
|
612 void CTzUserDataTest::DeleteOOML() |
|
613 { |
|
614 for(TInt ii=iTzIds.Count()-1; ii>=0; --ii) |
|
615 { |
|
616 //Delete the user-defined time zone as the last element in the array. |
|
617 iUserData->DeleteL(*(iTzIds[ii])); |
|
618 } |
|
619 } |
|
620 |
|
621 |
|
622 void CTzUserDataTest::OOMTestL(OOMTestFunction aFunction, TOOMTest aOOMTest) |
|
623 { |
|
624 TInt tryCount = 1; |
|
625 |
|
626 RTz tz; |
|
627 User::LeaveIfError(tz.Connect()); |
|
628 CleanupClosePushL(tz); |
|
629 iUserData = CTzUserData::NewL(tz); |
|
630 |
|
631 TInt cellsBefore = 0; |
|
632 |
|
633 for (;;) |
|
634 { |
|
635 test.Printf(_L("Heap memory allocation set to fail at allocation #%d.\n"), |
|
636 tryCount); |
|
637 |
|
638 if(aOOMTest == EClientOOM) |
|
639 { |
|
640 __UHEAP_SETFAIL(RAllocator::EDeterministic, tryCount); |
|
641 __UHEAP_MARK; |
|
642 } |
|
643 else |
|
644 { |
|
645 TInt heapSize = 0; |
|
646 tz.__dbgSetHeapFailL(RAllocator::EDeterministic, tryCount); |
|
647 cellsBefore = tz.__dbgRequestAllocatedCellsL(heapSize); |
|
648 } |
|
649 |
|
650 TRAPD(err, (this->*aFunction)()); |
|
651 |
|
652 if(err == KErrNone) |
|
653 { |
|
654 test.Printf(_L("OOM test complete.\n")); |
|
655 break; |
|
656 } |
|
657 |
|
658 test(err == KErrNoMemory); |
|
659 |
|
660 if(aOOMTest == EClientOOM) |
|
661 { |
|
662 __UHEAP_MARKEND; |
|
663 } |
|
664 else |
|
665 { |
|
666 tz.__dbgResetHeapL(); |
|
667 TInt heapSize = 0; |
|
668 TInt cellsAfter = tz.__dbgRequestAllocatedCellsL(heapSize); |
|
669 if(cellsBefore != cellsAfter) |
|
670 { |
|
671 test.Printf(_L("ERROR: Memory leak. Heap cells: %d before, %d after.\n"), |
|
672 cellsBefore, cellsAfter); |
|
673 test(EFalse); |
|
674 } |
|
675 } |
|
676 |
|
677 tryCount++; |
|
678 } |
|
679 |
|
680 __UHEAP_RESET; |
|
681 tz.__dbgResetHeapL(); |
|
682 |
|
683 delete iUserData; |
|
684 iUserData = NULL; |
|
685 |
|
686 CleanupStack::PopAndDestroy(&tz); |
|
687 } |
|
688 |
|
689 |
|
690 /** |
|
691 Create and read user-defined time zones. |
|
692 |
|
693 @SYMTestCaseID PIM-APPSERV-TZS-CO-0001 |
|
694 |
|
695 @SYMTestCaseDesc |
|
696 The purpose of this test is to verify that user-defined time zone rules and |
|
697 names can be created and read back. |
|
698 |
|
699 @SYMTestActions |
|
700 1. Create a few user-defined time zone with different offset. |
|
701 2. Read the rules and names for the user-defined time zone created in action |
|
702 1. |
|
703 |
|
704 @SYMTestExpectedResults |
|
705 The following information is the same as the information used to created |
|
706 the user-defined time zone in action 1: |
|
707 |
|
708 - Time zone rules |
|
709 - Standard time name |
|
710 - Daylight saving time name |
|
711 - Short standard time name |
|
712 - Short daylight saving time name |
|
713 - City name |
|
714 - Region name |
|
715 |
|
716 @SYMTestType |
|
717 CT |
|
718 |
|
719 @SYMTestPriority |
|
720 1 |
|
721 */ |
|
722 |
|
723 |
|
724 void CTzUserDataTest::TestCreateUserDefinedTzL() |
|
725 { |
|
726 test.Next(_L("@SYMTestCaseID PIM-APPSERV-TZS-CO-0001 Create user-defined Time Zone")); |
|
727 |
|
728 // Offset 60 There is no DST |
|
729 test.Printf(_L("Offset 60 There is no DST\n")); |
|
730 |
|
731 CTzId* id = CreateUserDefinedTzL(60, 60, ETrue); |
|
732 CleanupStack::PushL(id); |
|
733 iTzIds.AppendL(id); |
|
734 CleanupStack::Pop(id); |
|
735 |
|
736 // Offset - 60 There is no DST |
|
737 test.Printf(_L("Offset -60 There is no DST\n")); |
|
738 id = CreateUserDefinedTzL(-60, -60, ETrue); |
|
739 CleanupStack::PushL(id); |
|
740 iTzIds.AppendL(id); |
|
741 CleanupStack::Pop(id); |
|
742 |
|
743 // Offset 60 There is DST of 60 |
|
744 id = CreateUserDefinedTzL(60, 120, ETrue); |
|
745 CleanupStack::PushL(id); |
|
746 iTzIds.AppendL(id); |
|
747 CleanupStack::Pop(id); |
|
748 |
|
749 // Offset - 60 There is DST of 60 |
|
750 test.Printf(_L("Offset - 60 There is DST of 60\n")); |
|
751 id = CreateUserDefinedTzL(-60, 0, ETrue); |
|
752 CleanupStack::PushL(id); |
|
753 iTzIds.AppendL(id); |
|
754 CleanupStack::Pop(id); |
|
755 } |
|
756 |
|
757 |
|
758 /** |
|
759 Update user-defined time zone. |
|
760 |
|
761 @SYMTestCaseID PIM-APPSERV-TZS-CO-0002 |
|
762 |
|
763 @SYMTestCaseDesc |
|
764 The purpose of this test is to verify that user-defined time zone time rules |
|
765 and names can be updated. |
|
766 |
|
767 @SYMTestActions |
|
768 1. Create a user-defined time zone (rules and names). |
|
769 2. Get all existing user-defined time zones and update them with the rules |
|
770 and names created in action 1. |
|
771 3. Read the new user-defined time zone rules and names updated in action 2. |
|
772 |
|
773 @SYMTestExpectedResults |
|
774 The following information is the same as the information used to update the |
|
775 user-defined time zone in action 3: |
|
776 |
|
777 - Time zone rules |
|
778 - Standard time name |
|
779 - Daylight saving time name |
|
780 - Short standard time name |
|
781 - Short daylight saving time name |
|
782 - City name |
|
783 - Region name |
|
784 |
|
785 @SYMTestType |
|
786 CT |
|
787 |
|
788 @SYMTestPriority |
|
789 1 |
|
790 */ |
|
791 void CTzUserDataTest::TestUpdateUserDefinedTzL() |
|
792 { |
|
793 test.Next(_L("@SYMTestCaseID PIM-APPSERV-TZS-CO-0002 ")); |
|
794 CTzRules* newRule = CreateUserDefinedTzLC(0,0); |
|
795 CTzUserNames* newNames = CreateUserDefinedTzNamesLC(); |
|
796 |
|
797 for(TInt ii=0; ii<iTzIds.Count(); ++ii) |
|
798 { |
|
799 iUserData->UpdateL(*(iTzIds[ii]), *newRule, *newNames); |
|
800 |
|
801 //Get and Compare |
|
802 CTzRules* userRuleGet = iUserData->ReadRulesL(*(iTzIds[ii])); |
|
803 test (userRuleGet->IsEqualTo(*newRule)); |
|
804 delete userRuleGet; |
|
805 |
|
806 CTzUserNames* userNamesGet = iUserData->ReadNamesL(*(iTzIds[ii])); |
|
807 test(CompareNames(*userNamesGet, *newNames)); |
|
808 delete userNamesGet; |
|
809 } |
|
810 |
|
811 CleanupStack::PopAndDestroy(2, newRule); |
|
812 } |
|
813 |
|
814 |
|
815 /** |
|
816 Delete user-defined time zones. |
|
817 |
|
818 @SYMTestCaseID PIM-APPSERV-TZS-CO-0003 |
|
819 |
|
820 @SYMTestCaseDesc |
|
821 The purpose of this test is to verify that user-defined time zones can be |
|
822 deleted. |
|
823 |
|
824 @SYMTestActions |
|
825 1. Get all existing user-defined time zones. |
|
826 2. Delete the user-defined time zone as the last element in the array one |
|
827 by one. |
|
828 3. Try to read the user-defined time zone deleted in action 2. |
|
829 |
|
830 @SYMTestExpectedResults |
|
831 The user-defined time zone does not exist. |
|
832 |
|
833 @SYMTestType |
|
834 CT |
|
835 |
|
836 @SYMTestPriority |
|
837 1 |
|
838 */ |
|
839 void CTzUserDataTest::TestDeleteUserDefinedTzL() |
|
840 { |
|
841 test.Next(_L("@SYMTestCaseID PIM-APPSERV-TZS-CO-0003")); |
|
842 RPointerArray<CTzId> ids; |
|
843 CleanupStack::PushL(TCleanupItem(ResetAndDestroyTzIdArray, &ids)); |
|
844 |
|
845 for(TInt ii=iTzIds.Count()-1; ii>=0; --ii) |
|
846 { |
|
847 iUserData->GetTzIdsL(ids); |
|
848 |
|
849 // The array obtained should be same as expected who elements is deleted |
|
850 // one by one in each loop. |
|
851 CompareArray(ids,iTzIds); |
|
852 ids.ResetAndDestroy(); |
|
853 |
|
854 // Delete the user-defined time zone as the last element in the array. |
|
855 iUserData->DeleteL(*(iTzIds[ii])); |
|
856 |
|
857 // The rule and names of the last element in the array should not be |
|
858 // found since it has been deleted. |
|
859 TRAPD(err, iUserData->ReadRulesL(*(iTzIds[ii]))); |
|
860 test(err == KErrNotFound); |
|
861 TRAP(err, iUserData->ReadNamesL(*(iTzIds[ii]))); |
|
862 test(err == KErrNotFound); |
|
863 |
|
864 delete iTzIds[ii]; |
|
865 iTzIds.Remove(ii); |
|
866 } |
|
867 |
|
868 CleanupStack::PopAndDestroy(&ids); |
|
869 } |
|
870 |
|
871 |
|
872 /** |
|
873 All user-defined time zone identifiers. |
|
874 |
|
875 @SYMTestCaseID PIM-APPSERV-TZS-CO-0004 |
|
876 |
|
877 @SYMTestCaseDesc |
|
878 The purpose of this test is to verify that time zone identifiers for user- |
|
879 defined time zones can be queried. |
|
880 |
|
881 @SYMTestActions |
|
882 1. Get all existing user-defined time zones. |
|
883 |
|
884 @SYMTestExpectedResults |
|
885 The time zone identifiers obtained should be same as those existing ones. |
|
886 |
|
887 @SYMTestType |
|
888 CT |
|
889 |
|
890 @SYMTestPriority |
|
891 1 |
|
892 */ |
|
893 |
|
894 |
|
895 void CTzUserDataTest::TestReadIdsL(RTz& aRTz) |
|
896 { |
|
897 test.Next(_L("@SYMTestCaseID PIM-APPSERV-TZS-CO-0004 Read time zone IDs")); |
|
898 ReadIdsAndTestL(aRTz, EFalse); |
|
899 } |
|
900 |
|
901 |
|
902 /** |
|
903 Check time zone identifier is a user-defined time zone identifier. |
|
904 |
|
905 @SYMTestCaseID PIM-APPSERV-TZS-CO-0005 |
|
906 |
|
907 @SYMTestCaseDesc |
|
908 The purpose of this test is to verify that a time zone identifier is or is |
|
909 not a user-defined time zone identifier. |
|
910 |
|
911 @SYMTestActions |
|
912 1. Get all existing user-defined time zones. |
|
913 2. Obtain a time zone identifier for a non-user-defined time zone |
|
914 |
|
915 @SYMTestExpectedResults |
|
916 - Check that the time zone identifier is a user-defined time zone |
|
917 identifier. |
|
918 - Check that the time zone identifier is not a user-defined time zone |
|
919 |
|
920 @SYMTestType |
|
921 CT |
|
922 |
|
923 @SYMTestPriority |
|
924 1 |
|
925 */ |
|
926 |
|
927 |
|
928 void CTzUserDataTest::TestIdsL(RTz& aRTz) |
|
929 { |
|
930 test.Next(_L("@SYMTestCaseID PIM-APPSERV-TZS-CO-0005 Check time zone IDs")); |
|
931 ReadIdsAndTestL(aRTz, ETrue); |
|
932 } |
|
933 |
|
934 |
|
935 void CTzUserDataTest::TestShortTzId(RTz& aRTz) |
|
936 { |
|
937 test.Next(_L("test short TzId behaviour")); |
|
938 TInt KGreaterThanExpectedVal = 65536; //a value greater than 0xffff i.e. 16 bits |
|
939 TUint8 groupId = 8; //make up some random value |
|
940 TUint resourceId = 123; //make up some random value |
|
941 TRAPD(err, aRTz.LocalizationWriteCityL(_L("myCity"), KGreaterThanExpectedVal, groupId, resourceId)); |
|
942 test(err == KErrArgument); |
|
943 TRAPD(err1, aRTz.LocalizationDeleteCityL(_L("myCity"), KGreaterThanExpectedVal)); |
|
944 test(err1 == KErrArgument); |
|
945 |
|
946 TRAPD(err2, aRTz.LocalizationDeleteCityL(_L("myCity"), KGreaterThanExpectedVal - 1)); |
|
947 test(err2 == KErrNotFound); |
|
948 |
|
949 TRAPD(err3, CTzLocalizedTimeZoneRecord::NewLC(KGreaterThanExpectedVal, _L("standardName"), _L("daylightName"), _L("shortStandardName"), _L("shortDaylighName"), 0)); |
|
950 test(err3 == KErrArgument); |
|
951 |
|
952 TRAPD(err4, CTzLocalizedCityRecord::NewLC(_L("aCity"), 0, 0, KGreaterThanExpectedVal, 0)); |
|
953 test(err4 == KErrArgument); |
|
954 } |
|
955 |
|
956 |
|
957 |
|
958 void CTzUserDataTest::ReadIdsAndTestL(RTz& aRTz, TBool aCheckId) |
|
959 { |
|
960 test.Next(_L("Read time zone IDs")); |
|
961 RPointerArray<CTzId> ids; |
|
962 CleanupStack::PushL(TCleanupItem(ResetAndDestroyTzIdArray, &ids)); |
|
963 iUserData->GetTzIdsL(ids); |
|
964 test(iTzIds.Count() == ids.Count()); |
|
965 if(aCheckId) |
|
966 { |
|
967 TInt count = ids.Count(); |
|
968 for(TInt ii = 0; ii<count; ++ii) |
|
969 { |
|
970 test(ids[ii]->IsUserTzId()); |
|
971 } |
|
972 //Current time zone is default time zone Europe/London which is not the user-defined time zone. |
|
973 CTzId* currentId = aRTz.GetTimeZoneIdL(); |
|
974 test (!currentId->IsUserTzId()); |
|
975 delete currentId; |
|
976 } |
|
977 |
|
978 CleanupStack::PopAndDestroy(&ids); |
|
979 } |
|
980 |
|
981 |
|
982 void CTzUserDataTest::TestBasicUserDataL() |
|
983 { |
|
984 ResetTzUserDataL(); |
|
985 RTz tz; |
|
986 User::LeaveIfError(tz.Connect()); |
|
987 CleanupClosePushL(tz); |
|
988 iUserData = CTzUserData::NewL(tz); |
|
989 TestCreateUserDefinedTzL(); |
|
990 TestReadIdsL(tz); |
|
991 TestIdsL(tz); |
|
992 TestUpdateUserDefinedTzL(); |
|
993 TestDeleteUserDefinedTzL(); |
|
994 TestShortTzId(tz); |
|
995 delete iUserData; |
|
996 iUserData = NULL; |
|
997 CleanupStack::PopAndDestroy(&tz); |
|
998 } |
|
999 |
|
1000 |
|
1001 /** |
|
1002 Out of memory behaviour. |
|
1003 |
|
1004 @SYMTestCaseID PIM-APPSERV-TZS-CO-0006 |
|
1005 |
|
1006 @SYMTestCaseDesc |
|
1007 The purpose of this test is to verify that user-defined time zone operations |
|
1008 are robust and result in no memory leaks under OOM conditions. |
|
1009 |
|
1010 @SYMTestActions |
|
1011 Create, Read, Update and Delete a user-defined time zone rule under OOM |
|
1012 conditions. |
|
1013 |
|
1014 @SYMTestExpectedResults |
|
1015 Each operation leaves with KErrNoMemory until eventually the operation |
|
1016 completes successfully. Once the operation completes successfully the |
|
1017 client process (for client-side OOM testing) or TZ Server process (for |
|
1018 server-side OOM testing) is terminated and does not report a memory leak. |
|
1019 |
|
1020 @SYMTestType |
|
1021 CT |
|
1022 |
|
1023 @SYMTestPriority |
|
1024 1 |
|
1025 */ |
|
1026 void CTzUserDataTest::TestOutOfMemoryBehaviourL(TOOMTest aOOMTest) |
|
1027 { |
|
1028 ResetTzUserDataL(); |
|
1029 |
|
1030 |
|
1031 test.Start(_L("@SYMTestCaseID PIM-APPSERV-TZS-CO-0006 Test Create User-Defined Time Zone OOM")); |
|
1032 OOMTestL(&CreateOOML,aOOMTest); |
|
1033 |
|
1034 // Ensure that a tz ID is saved in iTzIds which is used to fetch a time zone |
|
1035 // in ReadOOML(). |
|
1036 RTz tz; |
|
1037 User::LeaveIfError(tz.Connect()); |
|
1038 CleanupClosePushL(tz); |
|
1039 iUserData = CTzUserData::NewL(tz); |
|
1040 iUserData->GetTzIdsL(iTzIds); |
|
1041 delete iUserData; |
|
1042 iUserData = NULL; |
|
1043 CleanupStack::PopAndDestroy(&tz); |
|
1044 |
|
1045 test.Next(_L("Test Read User-Defined Time Zone OOM")); |
|
1046 OOMTestL(&ReadOOML,aOOMTest); |
|
1047 |
|
1048 test.Next(_L("Test Get User-Defined Time Zone IDs OOM")); |
|
1049 OOMTestL(&GetIdsOOML,aOOMTest); |
|
1050 |
|
1051 test.Next(_L("Test Update User-Defined Time Zone OOM")); |
|
1052 OOMTestL(&UpdateOOML,aOOMTest); |
|
1053 |
|
1054 test.Next(_L("Test Delete User-Defined Time Zone OOM")); |
|
1055 OOMTestL(&DeleteOOML,aOOMTest); |
|
1056 |
|
1057 test.End(); |
|
1058 |
|
1059 ResetTzUserDataL(); |
|
1060 } |
|
1061 |
|
1062 |
|
1063 /** |
|
1064 Boundary tests. |
|
1065 |
|
1066 @SYMTestCaseID PIM-APPSERV-TZUSERDATA-0013 |
|
1067 |
|
1068 @SYMTestCaseDesc |
|
1069 The purpose of this test is to test behaviour under various boundary |
|
1070 conditions. |
|
1071 |
|
1072 @SYMTestActions |
|
1073 1. Get TZ Ids of user-defined time zone when the database is empty. |
|
1074 2. Get the user-defined rule for a valid TZ Id when the database is empty. |
|
1075 3. Get the user-defined rule names when the database is empty. |
|
1076 4. Create a user time zone with all named KNullDesC |
|
1077 5. Get rules, names and try to update and delete using a non-user-defined |
|
1078 TZID. |
|
1079 |
|
1080 @SYMTestExpectedResults |
|
1081 Array obtained in action 1 has 0 count. Leaving code KErrNotFound is |
|
1082 expected in action 2 and 3. A user time zone with all named KNullDesC |
|
1083 should be allowed. |
|
1084 |
|
1085 @SYMTestType |
|
1086 CT |
|
1087 |
|
1088 @SYMTestPriority |
|
1089 1 |
|
1090 */ |
|
1091 |
|
1092 void CTzUserDataTest::BoundaryTestL() |
|
1093 { |
|
1094 test.Next(_L("@SYMTestCaseID PIM-APPSERV-TZUSERDATA-0013 Boundary Test")); |
|
1095 ResetTzUserDataL(); |
|
1096 |
|
1097 RTz tz; |
|
1098 User::LeaveIfError(tz.Connect()); |
|
1099 CleanupClosePushL(tz); |
|
1100 iUserData = CTzUserData::NewL(tz); |
|
1101 |
|
1102 // Empty user time zone database. |
|
1103 iUserData->GetTzIdsL(iTzIds); |
|
1104 test (iTzIds.Count() == 0); |
|
1105 |
|
1106 CTzId * id = CTzId::NewL(KUserTzIdMin); |
|
1107 CleanupStack::PushL(id); |
|
1108 CTzRules* rulesGet = NULL; |
|
1109 TRAPD(err, rulesGet = iUserData->ReadRulesL(*id)); |
|
1110 test (!rulesGet); |
|
1111 test (err==KErrNotFound); |
|
1112 |
|
1113 CTzUserNames* namesGet = NULL; |
|
1114 TRAP(err, namesGet = iUserData->ReadNamesL(*id)); |
|
1115 test (!namesGet); |
|
1116 test (err==KErrNotFound); |
|
1117 iUserData->DeleteL(*id); |
|
1118 CleanupStack::PopAndDestroy(id); |
|
1119 |
|
1120 // Create a user time zone with all named KNullDesC. |
|
1121 CTzRules* rules = CreateUserDefinedTzLC(0, 0); |
|
1122 CTzUserNames* names = CTzUserNames::NewLC(KNullDesC , KNullDesC, KNullDesC, KNullDesC, KNullDesC, KNullDesC); |
|
1123 id = iUserData->CreateL(*rules, *names); |
|
1124 CleanupStack::PushL(id); |
|
1125 CheckTimeZoneL(*id, *rules, *names); |
|
1126 |
|
1127 // Create a non-user-defined TZID object and reuse it in the following |
|
1128 // tests. |
|
1129 CTzId* nonUserDefinedTzId = CTzId::NewL(KUserTzIdMin - 1); |
|
1130 CleanupStack::PushL(nonUserDefinedTzId); |
|
1131 |
|
1132 // Attempt to update user-defined TZ data using a TZID which is not a user- |
|
1133 // defined TZID. |
|
1134 TRAP(err, iUserData->UpdateL(*nonUserDefinedTzId, *rules, *names)); |
|
1135 test(err == KErrArgument); |
|
1136 |
|
1137 // Attempt to read rules from user-defined TZ data using a TZID which is |
|
1138 // not a user-defined TZID. |
|
1139 TRAP(err, rulesGet = iUserData->ReadRulesL(*nonUserDefinedTzId)); |
|
1140 test(err == KErrArgument); |
|
1141 |
|
1142 // Attempt to read names from user-defined TZ data using a TZID which is |
|
1143 // not a user-defined TZID. |
|
1144 TRAP(err, namesGet = iUserData->ReadNamesL(*nonUserDefinedTzId)); |
|
1145 test(err == KErrArgument); |
|
1146 |
|
1147 // Attempt to delete from user-defined TZ data using a TZID which is not |
|
1148 // a user-defined TZID. |
|
1149 TRAP(err, iUserData->DeleteL(*nonUserDefinedTzId)); |
|
1150 test(err == KErrArgument); |
|
1151 |
|
1152 CleanupStack::PopAndDestroy(4, rules); |
|
1153 |
|
1154 delete iUserData; |
|
1155 CleanupStack::PopAndDestroy(&tz); |
|
1156 ResetTzUserDataL(); |
|
1157 } |
|
1158 |
|
1159 |
|
1160 /** |
|
1161 Convert time using user-defined time zone. |
|
1162 |
|
1163 @SYMTestCaseID PIM-APPSERV-TZS-TZR-0001 |
|
1164 |
|
1165 @SYMTestCaseDesc |
|
1166 The purpose of this test is to verify the behaviour of time conversion using |
|
1167 a user-defined time zone. |
|
1168 |
|
1169 @SYMTestActions |
|
1170 1. Create a few user-defined time zone with different UTC offsets and store |
|
1171 them in the database. |
|
1172 2. Get the UTC offset of each time zone created. |
|
1173 3. Set the current time zone to each user-defined time zone created in |
|
1174 action 1. |
|
1175 4. Convert the system time from UTC to local. |
|
1176 5. Verify the UTC offset for each user-defined time zone. |
|
1177 |
|
1178 @SYMTestExpectedResults |
|
1179 The UTC offset for the given time zone created is correct. |
|
1180 |
|
1181 @SYMTestType |
|
1182 CT |
|
1183 |
|
1184 @SYMTestPriority |
|
1185 1 |
|
1186 */ |
|
1187 void CTzUserDataTest::TestTimeConversionL() |
|
1188 { |
|
1189 TestTimeZoneRulesL(ETimeConversion); |
|
1190 } |
|
1191 |
|
1192 |
|
1193 /** |
|
1194 Daylight saving observation using user-defined time zone. |
|
1195 |
|
1196 @SYMTestCaseID PIM-APPSERV-TZS-TZR-0002 |
|
1197 |
|
1198 @SYMTestCaseDesc |
|
1199 The purpose of this test is to verify the behaviour of daylight saving time |
|
1200 zone rules for a user-defined time zone. |
|
1201 |
|
1202 @SYMTestActions |
|
1203 1. Create a user-defined time zone. |
|
1204 2. Set the current time zone to the user-defined time zone created in |
|
1205 action 1. |
|
1206 3. Check if the daylight saving is on to a time that is inside the time |
|
1207 interval during which DST is observed. [1] |
|
1208 4. Check if the daylight saving is on to a time that is outside the time |
|
1209 interval during which DST is not observed. [2] |
|
1210 |
|
1211 @SYMTestExpectedResults |
|
1212 [1] The system indicates that DST is currently being observed. |
|
1213 [2] The system indicates that DST is not currently being observed. |
|
1214 |
|
1215 @SYMTestType |
|
1216 CT |
|
1217 |
|
1218 @SYMTestPriority |
|
1219 1 |
|
1220 */ |
|
1221 void CTzUserDataTest::TestDaylightSaveL() |
|
1222 { |
|
1223 TestTimeZoneRulesL(EDayLightSave); |
|
1224 } |
|
1225 |
|
1226 |
|
1227 /** |
|
1228 Check that CTzUserData can work with creating a CTzUserData with KUserTzIdMin |
|
1229 id and with a KNullDesC8 name as expected. |
|
1230 */ |
|
1231 void CTzUserDataTest::NullTestL() |
|
1232 { |
|
1233 CTzId* minId = CTzId::NewL(KUserTzIdMin); |
|
1234 test (minId->IsUserTzId()); |
|
1235 delete minId; |
|
1236 |
|
1237 CTzId* nullId = CTzId::NewL(KNullDesC8()); |
|
1238 test (nullId->IsUserTzId() == EFalse); |
|
1239 delete nullId; |
|
1240 } |
|
1241 |
|
1242 void CTzUserDataTest::TestTimeZoneRulesL(TTest aWhatToTest) |
|
1243 { |
|
1244 ResetTzUserDataL(); |
|
1245 |
|
1246 test.Next(_L("Time Zone Rules")); |
|
1247 RTz tz; |
|
1248 User::LeaveIfError(tz.Connect()); |
|
1249 CleanupClosePushL(tz); |
|
1250 tz.SetAutoUpdateBehaviorL(RTz::ETZAutoDSTUpdateOn); |
|
1251 iUserData = CTzUserData::NewL(tz); |
|
1252 |
|
1253 test.Next(_L("Create user-defined Time Zone")); |
|
1254 |
|
1255 // Offset 60 There is no DST |
|
1256 test.Printf(_L("Offset 60 There is no DST\n")); |
|
1257 CreateTzAndCheckL(60, 60, tz, aWhatToTest); |
|
1258 |
|
1259 // Offset - 60 There is no DST |
|
1260 test.Printf(_L("Offset -60 There is no DST\n")); |
|
1261 CreateTzAndCheckL(-60, -60, tz, aWhatToTest); |
|
1262 |
|
1263 // Offset 60 There is DST of 60 |
|
1264 CreateTzAndCheckL(60, 120, tz, aWhatToTest); |
|
1265 |
|
1266 // Offset - 60 There is DST of 60 |
|
1267 test.Printf(_L("Offset - 60 There is DST of 60\n")); |
|
1268 CreateTzAndCheckL(-60, 0, tz, aWhatToTest); |
|
1269 |
|
1270 // Create user time zone based on London TZ rules |
|
1271 test.Printf(_L("Create User Tz Based On London Rule\n")); |
|
1272 CreateUserTzBasedOnLondonRuleL(tz, aWhatToTest); |
|
1273 |
|
1274 // Create user time zone based on Shanghai TZ rules |
|
1275 test.Printf(_L("Create User Tz Based On Shanghai Rule\n")); |
|
1276 CreateUserTzBasedOnShanghaiRuleL(tz, aWhatToTest); |
|
1277 |
|
1278 delete iUserData; |
|
1279 iUserData= NULL; |
|
1280 CleanupStack::PopAndDestroy(&tz); |
|
1281 ResetTzUserDataL(); |
|
1282 } |
|
1283 |
|
1284 |
|
1285 void CTzUserDataTest::UpdateCurrentTzL(RTz& aTz,TInt aOldOffSet, TInt aNewOffSet ) |
|
1286 { |
|
1287 CTzRules* newrules = CreateUserDefinedTzLC(aOldOffSet, aNewOffSet); |
|
1288 CTzUserNames* newnames = CreateUserDefinedTzNamesLC(); |
|
1289 CTzId* currentTzid = aTz.GetTimeZoneIdL(); |
|
1290 CleanupStack::PushL(currentTzid); |
|
1291 iUserData->UpdateL(*currentTzid,*newrules, *newnames); |
|
1292 CleanupStack::PopAndDestroy(currentTzid); |
|
1293 CTzRules* currentRules = aTz.GetTimeZoneRulesL(0, 9999,ETzUtcTimeReference ); |
|
1294 CleanupStack::PushL(currentRules); |
|
1295 test(newrules->IsEqualTo(*currentRules)); |
|
1296 CleanupStack::PopAndDestroy(3, newrules); |
|
1297 } |
|
1298 |
|
1299 |
|
1300 void CTzUserDataTest::DeleteCurrentTzL(RTz& aTz) |
|
1301 { |
|
1302 CTzId* currentTzid = aTz.GetTimeZoneIdL(); |
|
1303 CleanupStack::PushL(currentTzid); |
|
1304 iUserData->DeleteL(*currentTzid); |
|
1305 CleanupStack::PopAndDestroy(currentTzid); |
|
1306 CTzId* tzGot = aTz.GetTimeZoneIdL(); |
|
1307 test(KTzLondon()==tzGot->TimeZoneNameID()); |
|
1308 delete tzGot; |
|
1309 } |
|
1310 |
|
1311 |
|
1312 /** |
|
1313 User-defined time zone is current time zone. |
|
1314 |
|
1315 @SYMTestCaseID PIM-APPSERV-TZS-RC-0001 |
|
1316 |
|
1317 @SYMTestCaseDesc |
|
1318 The purpose of this test is to verify that the current time zone can be set |
|
1319 to a user-defined time zone. |
|
1320 |
|
1321 @SYMTestActions |
|
1322 1. Create a user-defined time zone and store the returned time zone |
|
1323 identifier. |
|
1324 2. Set the current time zone using the time zone identifier stored in |
|
1325 action 1. |
|
1326 3. Get the time zone identifier for the current time zone. |
|
1327 |
|
1328 @SYMTestExpectedResults |
|
1329 The time zone identifier obtained in action 1 is the same as the time zone |
|
1330 identifier obtained in action 3. |
|
1331 |
|
1332 @SYMTestType |
|
1333 CT |
|
1334 |
|
1335 @SYMTestPriority |
|
1336 1 |
|
1337 */ |
|
1338 |
|
1339 |
|
1340 void CTzUserDataTest::CreateUserTzAndSetCurrentTimeToL(RTz& aTz, TInt aStandardOffSet, TInt aDSTOffset) |
|
1341 { |
|
1342 test.Next(_L("@SYMTestCaseID PIM-APPSERV-TZS-RC-0001 Test user-defined time zone is current time zone")); |
|
1343 CTzId* usertzid = CreateUserDefinedTzL(aStandardOffSet, aDSTOffset, ETrue); |
|
1344 CleanupStack::PushL(usertzid); |
|
1345 aTz.SetTimeZoneL(*usertzid); |
|
1346 CTzId* tzGot = aTz.GetTimeZoneIdL(); |
|
1347 test (*tzGot == *usertzid); |
|
1348 delete tzGot; |
|
1349 CleanupStack::PopAndDestroy(usertzid); |
|
1350 } |
|
1351 |
|
1352 |
|
1353 /** |
|
1354 Update user-defined time zone whose rules are being cached by TZ Server in the |
|
1355 current time zone rules cache. |
|
1356 |
|
1357 @SYMTestCaseID PIM-APPSERV-TZS-RC-0002 |
|
1358 |
|
1359 @SYMTestCaseDesc |
|
1360 The purpose of this test is to verify that expected behaviour when a time |
|
1361 zone rule for a user-defined time zone, which is also the current time zone, |
|
1362 is updated. |
|
1363 |
|
1364 @SYMTestActions |
|
1365 1. Create a user-defined time zone. |
|
1366 2. Set the current time zone to the user-defined time zone created in |
|
1367 action 1. |
|
1368 3. Update the first time zone rule for the user-defined zone created in |
|
1369 action 1. |
|
1370 4. Get the first time zone rule for the current time zone. |
|
1371 |
|
1372 @SYMTestExpectedResults |
|
1373 The rule used to update the user-defined time zone in action 2 is the same |
|
1374 as the rule obtained in action 4, implying that the current time zone rules |
|
1375 cache in the TZ Server has been updated. |
|
1376 |
|
1377 @SYMTestType |
|
1378 CT |
|
1379 |
|
1380 @SYMTestPriority |
|
1381 1 |
|
1382 */ |
|
1383 |
|
1384 |
|
1385 void CTzUserDataTest::UpdateCurrentUserTzL(RTz& aTz) |
|
1386 { |
|
1387 test.Next(_L("@SYMTestCaseID PIM-APPSERV-TZS-RC-0002 Update Current TZ rules - Server Response to Changes")); |
|
1388 TInt standardOffset = 60; |
|
1389 TInt dstOffset = 60; |
|
1390 CreateUserTzAndSetCurrentTimeToL(aTz,standardOffset,dstOffset); |
|
1391 standardOffset = 120; |
|
1392 dstOffset = 120; |
|
1393 UpdateCurrentTzL(aTz,standardOffset, dstOffset); |
|
1394 } |
|
1395 |
|
1396 |
|
1397 /** |
|
1398 Delete user-defined time zone whose rules are being cached by TZ Server in the |
|
1399 current time zone rules cache. |
|
1400 |
|
1401 @SYMTestCaseID PIM-APPSERV-TZS-RC-0003 |
|
1402 |
|
1403 @SYMTestCaseDesc |
|
1404 The purpose of this test is to verify the expected behaviour when a user- |
|
1405 defined time zone, which is also the current time zone, is deleted. |
|
1406 |
|
1407 @SYMTestActions |
|
1408 1. Set the current time zone to the default time zone for the system TZ |
|
1409 database. |
|
1410 2. Get the time zone identifier for the current time zone. |
|
1411 3. Create a user-defined time zone. |
|
1412 4. Set the current time zone to the user-defined time zone created in |
|
1413 action 3. |
|
1414 5. Delete the user-defined time zone created in action 3. |
|
1415 6. Get the time zone identifier for the current time zone. |
|
1416 |
|
1417 @SYMTestExpectedResults |
|
1418 The time zone identifier obtained in action 2 is the same as the time zone |
|
1419 identifier obtained in action 6, implying that the current time zone has |
|
1420 reverted to the default time zone for the system TZ database. |
|
1421 |
|
1422 @SYMTestType |
|
1423 CT |
|
1424 |
|
1425 @SYMTestPriority |
|
1426 1 |
|
1427 */ |
|
1428 void CTzUserDataTest::TestDeleteCurrentTimeZoneL(RTz& aTz) |
|
1429 { |
|
1430 DeleteCurrentUserTzL(aTz, EDeleteCurrentUserRule); |
|
1431 } |
|
1432 |
|
1433 |
|
1434 void CTzUserDataTest::DeleteCurrentUserTzL(RTz& aTz, TTest aWhatToTest) |
|
1435 { |
|
1436 test.Next(_L("Delete Current TZ rules - Server Response to Changes")); |
|
1437 |
|
1438 // Set system to default time zone |
|
1439 ResetTimeZoneToLondonL(); |
|
1440 CTzId* defaulteTzid = aTz.GetTimeZoneIdL(); |
|
1441 test(KTzLondon()==defaulteTzid->TimeZoneNameID()); |
|
1442 delete defaulteTzid; |
|
1443 |
|
1444 // Set system to a newly created user time zone |
|
1445 const TInt KStandardOffset = 60; |
|
1446 const TInt KDSTOffset = 120; |
|
1447 CreateUserTzAndSetCurrentTimeToL(aTz,KStandardOffset,KDSTOffset); |
|
1448 |
|
1449 //Delete the user time zone |
|
1450 DeleteCurrentTzL(aTz); |
|
1451 |
|
1452 if(aWhatToTest == EPersistence) |
|
1453 { |
|
1454 aTz.Close(); |
|
1455 User::After(1000000); |
|
1456 User::LeaveIfError(aTz.Connect()); |
|
1457 } |
|
1458 CTzId* tzGot = aTz.GetTimeZoneIdL(); |
|
1459 test(KTzLondon()==tzGot->TimeZoneNameID()); |
|
1460 delete tzGot; |
|
1461 } |
|
1462 |
|
1463 |
|
1464 /** |
|
1465 Current time zone persistence. |
|
1466 |
|
1467 @SYMTestCaseID PIM-APPSERV-TZS-RC-0006 |
|
1468 |
|
1469 @SYMTestCaseDesc |
|
1470 The purpose of this test is to ensure the home time zone identifier in the |
|
1471 Central Repository is not defined when it is deleted. |
|
1472 |
|
1473 @SYMTestActions |
|
1474 1. Set the current time zone to the default time zone for the system TZ |
|
1475 database. |
|
1476 2. Get the time zone identifier for the current time zone. |
|
1477 3. Create a user-defined time zone. |
|
1478 4. Set the current time zone to the user-defined time zone created in |
|
1479 action 3. |
|
1480 5. Delete the user-defined time zone created in action 3. |
|
1481 6. Get the time zone identifier for the current time zone. |
|
1482 7. Close session with TZ Server so that TZ Server process is terminated. |
|
1483 8. Get the time zone identifier for the current time zone. |
|
1484 9. The expected result is same as 8. |
|
1485 |
|
1486 @SYMTestExpectedResults |
|
1487 The time zone identifier obtained in action 2 is the same as the time zone |
|
1488 identifier obtained in action 8, implying that the current time zone has |
|
1489 been established by the TZ Server when the server is started using the |
|
1490 current time zone value persisted to the Central Repository. |
|
1491 |
|
1492 @SYMTestType |
|
1493 CT |
|
1494 |
|
1495 @SYMTestPriority |
|
1496 1 |
|
1497 */ |
|
1498 void CTzUserDataTest::TestCurrentTimeZonePersistenceL(RTz& aTz) |
|
1499 { |
|
1500 DeleteCurrentUserTzL(aTz, EPersistence); |
|
1501 } |
|
1502 |
|
1503 |
|
1504 /** |
|
1505 Update user-defined time zone whose rules are being cached by TZ Server in the |
|
1506 foreign time zone rules cache. |
|
1507 |
|
1508 @SYMTestCaseID PIM-APPSERV-TZS-RC-0004 |
|
1509 |
|
1510 @SYMTestCaseDesc |
|
1511 The purpose of this test is to verify that time conversion to/from a foreign |
|
1512 (i.e. not current) time zone behaves correctly when the time zone rules |
|
1513 cached by the TZ Server for the foreign time zone are time zone rules from a |
|
1514 user-defined time zone that is subsequently updated. |
|
1515 |
|
1516 @SYMTestActions |
|
1517 1. Create a user-defined time zone. |
|
1518 2. Convert a given time from UTC to local time using the user-defined time |
|
1519 zone. |
|
1520 3. Update the user-defined time zone created in action 1. |
|
1521 4. Convert a given time from UTC to local time using an existing time zone. |
|
1522 |
|
1523 @SYMTestExpectedResults |
|
1524 The local time is correctly converted, implying that the foreign time zone |
|
1525 rules cache in the TZ Server is invalidated and recreated. |
|
1526 |
|
1527 @SYMTestType |
|
1528 CT |
|
1529 |
|
1530 @SYMTestPriority |
|
1531 1 |
|
1532 */ |
|
1533 void CTzUserDataTest::TestUpdateCachedUserTimeZoneL(RTz& aRTz) |
|
1534 { |
|
1535 CachedUserTimeZoneL(aRTz, EUpdateCachedTz); |
|
1536 } |
|
1537 |
|
1538 |
|
1539 /** |
|
1540 Delete user-defined time zone whose rules are being cached by TZ Server in the |
|
1541 foreign time zone rules cache. |
|
1542 |
|
1543 @SYMTestCaseID PIM-APPSERV-TZS-RC-0005 |
|
1544 |
|
1545 @SYMTestCaseDesc |
|
1546 The purpose of this test is to verify that time conversion to/from a foreign |
|
1547 (i.e. not current) time zone behaves correctly when the time zone rules |
|
1548 cached by the TZ Server for the foreign time zone are time zone rules from a |
|
1549 user-defined time zone that is subsequently deleted. |
|
1550 |
|
1551 @SYMTestActions |
|
1552 1. Create a user-defined time zone. |
|
1553 2. Convert a given time from UTC to local time using the user-defined time |
|
1554 zone. |
|
1555 3. Delete the user-defined time zone created in action 1. |
|
1556 4. Convert a given time from UTC to local time using an existing time zone. |
|
1557 |
|
1558 @SYMTestExpectedResults |
|
1559 The local time is correctly converted, implying that the foreign time zone |
|
1560 rules cache in the TZ Server is invalidated and recreated. |
|
1561 |
|
1562 @SYMTestType |
|
1563 CT |
|
1564 |
|
1565 @SYMTestPriority |
|
1566 1 |
|
1567 */ |
|
1568 void CTzUserDataTest::TestDeletedCachedUserTimeZoneL(RTz& aRTz) |
|
1569 { |
|
1570 CachedUserTimeZoneL(aRTz, EDeleteCachedTz); |
|
1571 } |
|
1572 |
|
1573 |
|
1574 void CTzUserDataTest::CachedUserTimeZoneL(RTz& aRTz, TTest aWhatToTest) |
|
1575 { |
|
1576 test.Next(_L("Conver times - Server Response to Changes")); |
|
1577 TInt offset = 60; |
|
1578 TTime utctime (TDateTime(2000, EMay, 0, 0, 0, 0, 0)); |
|
1579 |
|
1580 //Convert a given time from UTC to local time using the user-defined time zone |
|
1581 TTime localtime = utctime ; |
|
1582 CreateUserTzAndSetCurrentTimeToL(aRTz, offset, offset); |
|
1583 aRTz.ConvertToLocalTime(localtime); |
|
1584 TTimeIntervalMinutes minutes; |
|
1585 localtime.MinutesFrom(utctime, minutes); |
|
1586 test (minutes == TTimeIntervalMinutes(offset)); |
|
1587 |
|
1588 localtime = utctime; |
|
1589 |
|
1590 //Convert a given time from UTC to local time when the corrent tz rule is updated |
|
1591 if(aWhatToTest==EUpdateCachedTz) |
|
1592 { |
|
1593 offset = 120; |
|
1594 UpdateCurrentTzL(aRTz, offset, offset); |
|
1595 } |
|
1596 else if(aWhatToTest==EDeleteCachedTz) |
|
1597 { |
|
1598 //Delete the current tz rule which result in system time reverting to the default time zone. |
|
1599 DeleteCurrentTzL(aRTz); |
|
1600 //Convert a given time from UTC to local time using an existing time zone which is the defaut time zone. |
|
1601 CTzRules* currentRules = aRTz.GetTimeZoneRulesL(0, 9999,ETzUtcTimeReference ); |
|
1602 CleanupStack::PushL(currentRules); |
|
1603 offset = currentRules->GetOffsetL(utctime, ETzUtcTimeReference); |
|
1604 CleanupStack::PopAndDestroy(currentRules); |
|
1605 } |
|
1606 |
|
1607 aRTz.ConvertToLocalTime(localtime); |
|
1608 localtime.MinutesFrom(utctime, minutes); |
|
1609 test (minutes == TTimeIntervalMinutes(offset)); |
|
1610 } |
|
1611 |
|
1612 |
|
1613 /** |
|
1614 The purpose of the following test cases is to verify the behaviour of the TZ |
|
1615 Server component’s response to changes in user-defined time zones, specifically |
|
1616 the rules associated with user-defined time zones. |
|
1617 |
|
1618 The TZ Server maintains a cache of certain time zone rules data and persists the |
|
1619 time zone identifier for the current time zone. |
|
1620 |
|
1621 If either this cache or the persisted setting relates to user-defined time zones |
|
1622 and those time zones are modified then the TZ Server must respond to the change |
|
1623 appropriately. |
|
1624 */ |
|
1625 |
|
1626 // @SYMTestCaseID PIM-APPSERV-TZS-RC-0003-TO-0006 |
|
1627 |
|
1628 void CTzUserDataTest::TestServerResponseToChangesL() |
|
1629 { |
|
1630 ResetTzUserDataL(); |
|
1631 |
|
1632 test.Next(_L("@SYMTestCaseID PIM-APPSERV-TZS-RC-0003-TO-0006 Server Response To Changes")); |
|
1633 |
|
1634 RTz tz; |
|
1635 User::LeaveIfError(tz.Connect()); |
|
1636 CleanupClosePushL(tz); |
|
1637 |
|
1638 iUserData = CTzUserData::NewL(tz); |
|
1639 |
|
1640 const TInt KStandardOffset = 60; |
|
1641 const TInt KDSTOffset = 60; |
|
1642 CreateUserTzAndSetCurrentTimeToL(tz,KStandardOffset,KDSTOffset); |
|
1643 |
|
1644 UpdateCurrentUserTzL(tz); |
|
1645 |
|
1646 TestUpdateCachedUserTimeZoneL(tz); |
|
1647 TestDeletedCachedUserTimeZoneL(tz); |
|
1648 TestDeleteCurrentTimeZoneL(tz); |
|
1649 TestCurrentTimeZonePersistenceL(tz); |
|
1650 |
|
1651 delete iUserData; |
|
1652 iUserData= NULL; |
|
1653 |
|
1654 CleanupStack::PopAndDestroy(&tz); |
|
1655 } |
|
1656 |
|
1657 |
|
1658 /** |
|
1659 The purpose of the follwing test case is to verify the behaviour of |
|
1660 reuse of Tz Ids in case all the 4095 ids have been used. |
|
1661 */ |
|
1662 void CTzUserDataTest::TestTzIdReusabilityL() |
|
1663 { |
|
1664 ResetTzUserDataL(); |
|
1665 RTz tz; |
|
1666 CleanupClosePushL(tz); |
|
1667 User::LeaveIfError(tz.Connect()); |
|
1668 iUserData = CTzUserData::NewL(tz); |
|
1669 const TInt maxTzIds = 4095; |
|
1670 for(TInt i=0; i<= maxTzIds; i++) |
|
1671 { |
|
1672 CTzId* tzid = NULL; |
|
1673 TRAPD(err, tzid = CreateUserDefinedTzL(0,0, EFalse)); |
|
1674 if(i%KPrintFreq == 0 || i == maxTzIds) |
|
1675 { |
|
1676 test.Printf(_L("Added %d rules to the database\n"), i); |
|
1677 } |
|
1678 |
|
1679 if(err != KErrNone) |
|
1680 { |
|
1681 test.Printf(_L("Error while creating rules. Error is %d\n"), err); |
|
1682 } |
|
1683 delete tzid; |
|
1684 } |
|
1685 const TUint KFirstReusedTzId = 16400; |
|
1686 CTzId* tzId = CTzId::NewL(KFirstReusedTzId); |
|
1687 CleanupStack::PushL(tzId); |
|
1688 iUserData->DeleteL(*tzId); |
|
1689 CleanupStack::PopAndDestroy(tzId); |
|
1690 |
|
1691 const TUint KSecondReusedTzId = 16500; |
|
1692 CTzId* tzId1 = CTzId::NewL(KSecondReusedTzId); |
|
1693 CleanupStack::PushL(tzId1); |
|
1694 iUserData->DeleteL(*tzId1); |
|
1695 CleanupStack::PopAndDestroy(tzId1); |
|
1696 |
|
1697 CTzId* reusedId = CreateUserDefinedTzL(0, 0, EFalse); |
|
1698 test(reusedId->TimeZoneNumericID() == KFirstReusedTzId); |
|
1699 test.Printf(_L("The first re-used id is %d\n"), reusedId->TimeZoneNumericID()); |
|
1700 delete reusedId; |
|
1701 |
|
1702 CTzId* secondReusedId = CreateUserDefinedTzL(0, 0, EFalse); |
|
1703 test(secondReusedId->TimeZoneNumericID() == KSecondReusedTzId); |
|
1704 test.Printf(_L("The second re-used id is %d\n"), secondReusedId->TimeZoneNumericID()); |
|
1705 delete secondReusedId; |
|
1706 |
|
1707 TRAPD(err, CreateUserDefinedTzL(0, 0, EFalse)); |
|
1708 test(err == KErrOverflow); |
|
1709 |
|
1710 delete iUserData; |
|
1711 iUserData = NULL; |
|
1712 CleanupStack::PopAndDestroy(&tz); |
|
1713 } |
|
1714 |
|
1715 static void DoTestsL() |
|
1716 { |
|
1717 User::LeaveIfError(Serv.Connect()); |
|
1718 |
|
1719 test.Title(); |
|
1720 |
|
1721 ResetTimeZoneToLondonL(); |
|
1722 |
|
1723 CTzUserDataTest* userDataTest = CTzUserDataTest::NewLC(); |
|
1724 |
|
1725 test.Start(_L("Test Basic User Data")); |
|
1726 userDataTest->TestBasicUserDataL(); |
|
1727 |
|
1728 test.Next(_L("Test Out Of Memory Behaviour (Client)")); |
|
1729 userDataTest->TestOutOfMemoryBehaviourL(CTzUserDataTest::EClientOOM); |
|
1730 |
|
1731 test.Next(_L("Test Out Of Memory Behaviour (Server)")); |
|
1732 userDataTest->TestOutOfMemoryBehaviourL(CTzUserDataTest::EServerOOM ); |
|
1733 |
|
1734 test.Next(_L("@SYMTestCaseID PIM-APPSERV-TZS-TZR-0001 Test Time Conversion")); |
|
1735 userDataTest->TestTimeConversionL(); |
|
1736 |
|
1737 test.Next(_L("@SYMTestCaseID PIM-APPSERV-TZS-TZR-0002 Test Daylight Save")); |
|
1738 userDataTest->TestDaylightSaveL(); |
|
1739 |
|
1740 test.Next(_L("Test Boundary Test")); |
|
1741 userDataTest->BoundaryTestL(); |
|
1742 |
|
1743 test.Next(_L("Test Server Response To Changes")); |
|
1744 userDataTest->TestServerResponseToChangesL(); |
|
1745 |
|
1746 // Delete the user-defined TZ database before the next test case. |
|
1747 Serv.CloseTzSession(); |
|
1748 Serv.DeleteFileL(KTzUserDataDb); |
|
1749 |
|
1750 test.Next(_L("Test Reusability Of TZ IDs")); |
|
1751 userDataTest->TestTzIdReusabilityL(); |
|
1752 |
|
1753 // Delete the user defined TZ database. |
|
1754 Serv.CloseTzSession(); |
|
1755 Serv.DeleteFileL(KTzUserDataDb); |
|
1756 |
|
1757 test.Next(_L("Null Test")); |
|
1758 userDataTest->NullTestL(); |
|
1759 |
|
1760 ResetTimeZoneToLondonL(); |
|
1761 |
|
1762 CleanupStack::PopAndDestroy(userDataTest); |
|
1763 |
|
1764 test.End(); |
|
1765 |
|
1766 Serv.Close(); |
|
1767 } |
|
1768 |
|
1769 |
|
1770 TInt E32Main() |
|
1771 { |
|
1772 __UHEAP_MARK; |
|
1773 |
|
1774 CTrapCleanup* trapCleanup = CTrapCleanup::New(); |
|
1775 if(!trapCleanup) |
|
1776 { |
|
1777 return KErrNoMemory; |
|
1778 } |
|
1779 |
|
1780 CActiveScheduler* scheduler = new CActiveScheduler; |
|
1781 if(!scheduler) |
|
1782 { |
|
1783 return KErrNoMemory; |
|
1784 } |
|
1785 CActiveScheduler::Install(scheduler); |
|
1786 |
|
1787 TRAPD(ret, DoTestsL()); |
|
1788 test.Printf(_L("Trapped return value from DoTestsL(): %d\n"), ret); |
|
1789 test(ret == KErrNone); |
|
1790 |
|
1791 test.Close(); |
|
1792 |
|
1793 delete scheduler; |
|
1794 delete trapCleanup; |
|
1795 |
|
1796 __UHEAP_MARKEND; |
|
1797 |
|
1798 return (KErrNone); |
|
1799 } |