|
1 // Copyright (c) 2006-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 #include "caltestlib.h" |
|
17 #include <calentryview.h> |
|
18 #include <calinstance.h> |
|
19 #include <calinstanceview.h> |
|
20 #include <calrrule.h> |
|
21 #include <e32test.h> |
|
22 #include <s32file.h> |
|
23 #include <vtzrules.h> |
|
24 |
|
25 static RTest test(_L("tcal_tz_instance")); |
|
26 |
|
27 // Device time zone |
|
28 _LIT8(KAmericaChicago, "America/Chicago"); |
|
29 |
|
30 class CCalTzInstanceTest : public CBase |
|
31 { |
|
32 public: |
|
33 static CCalTzInstanceTest* NewLC(); |
|
34 void DoTestL(); |
|
35 void DoCountYearlyByDayTestL(); |
|
36 void DoUntilAfterDSTChangeTestL(); |
|
37 void DoCountTestL(); |
|
38 ~CCalTzInstanceTest(); |
|
39 |
|
40 void DoOOMTestTzClientCacheClearingL(); |
|
41 void SupportCodeTestTzClientCacheClearingL(); |
|
42 private: |
|
43 void ConstructL(); |
|
44 |
|
45 private: |
|
46 CCalTestLibrary* iTestLib; |
|
47 }; |
|
48 |
|
49 _LIT(KCalName, "TestCalendarFile"); |
|
50 |
|
51 void CCalTzInstanceTest::DoCountYearlyByDayTestL() |
|
52 { |
|
53 iTestLib->CleanDatabaseL(); |
|
54 |
|
55 TCalRRule rule(TCalRRule::EYearly); |
|
56 |
|
57 // create entry repeating on the second Tuesday on August for four instances, setting the Count |
|
58 TCalTime dtStart; |
|
59 dtStart.SetTimeLocalL(TDateTime(2006, EAugust, 0, 7, 0, 0, 0)); |
|
60 rule.SetDtStart(dtStart); |
|
61 |
|
62 RArray<TMonth> months; |
|
63 CleanupClosePushL(months); |
|
64 months.AppendL(EAugust); |
|
65 rule.SetByMonth(months); |
|
66 CleanupStack::PopAndDestroy(&months); |
|
67 |
|
68 RArray<TCalRRule::TDayOfMonth> dayofmonths; |
|
69 CleanupClosePushL(dayofmonths); |
|
70 dayofmonths.AppendL(TCalRRule::TDayOfMonth(ETuesday, 2)); |
|
71 rule.SetByDay(dayofmonths); |
|
72 CleanupStack::PopAndDestroy(&dayofmonths); |
|
73 |
|
74 rule.SetCount(4); |
|
75 |
|
76 HBufC8* guid = _L8("guid").AllocLC(); |
|
77 CCalEntry* dummy = CCalEntry::NewL(CCalEntry::EAppt, guid, CCalEntry::EMethodNone, 0); |
|
78 CleanupStack::Pop(guid); |
|
79 CleanupStack::PushL(dummy); |
|
80 |
|
81 dummy->SetStartAndEndTimeL(dtStart, dtStart); |
|
82 dummy->SetRRuleL(rule); |
|
83 |
|
84 TCalRRule rule2; |
|
85 dummy->GetRRuleL(rule2); |
|
86 |
|
87 TDateTime endDate = rule2.Until().TimeLocalL().DateTime(); |
|
88 |
|
89 RPointerArray<CCalEntry> entryArray; |
|
90 CleanupClosePushL(entryArray); |
|
91 entryArray.AppendL(dummy); |
|
92 TInt success = 0; |
|
93 iTestLib->SynCGetEntryViewL().StoreL(entryArray, success); |
|
94 CleanupStack::PopAndDestroy(&entryArray); |
|
95 |
|
96 CleanupStack::PopAndDestroy(dummy); |
|
97 |
|
98 // Define the time range to find the instances |
|
99 TCalTime startTime; |
|
100 TCalTime endTime; |
|
101 startTime.SetTimeUtcL(TCalTime::MinTime()); |
|
102 endTime.SetTimeUtcL(TCalTime::MaxTime()); |
|
103 |
|
104 CalCommon::TCalTimeRange timeRange(startTime, endTime); |
|
105 |
|
106 RPointerArray<CCalInstance> instanceList; |
|
107 |
|
108 // Find all the instances within the specified time range |
|
109 iTestLib->SynCGetInstanceViewL().FindInstanceL(instanceList, CalCommon::EIncludeAll, timeRange); |
|
110 |
|
111 // Display all the instances found |
|
112 for (TInt instanceCounter = 0; instanceCounter < instanceList.Count(); ++instanceCounter) |
|
113 { |
|
114 TDateTime instanceDateTime = instanceList[instanceCounter]->StartTimeL().TimeUtcL().DateTime(); |
|
115 RDebug::Print(_L("Found instance at %d:%d on %d/%d/%d"), |
|
116 instanceDateTime.Hour(), instanceDateTime.Minute(), instanceDateTime.Day()+1, instanceDateTime.Month()+1, instanceDateTime.Year()); |
|
117 } |
|
118 |
|
119 // Verify the number of instances found |
|
120 test(instanceList.Count() == 4); |
|
121 |
|
122 instanceList.ResetAndDestroy(); |
|
123 } |
|
124 |
|
125 void CCalTzInstanceTest::DoUntilAfterDSTChangeTestL() |
|
126 { |
|
127 iTestLib->CleanDatabaseL(); |
|
128 |
|
129 RPointerArray<CCalEntry> entries; |
|
130 |
|
131 CCalEntry* entry; |
|
132 HBufC8* uid; |
|
133 TCalTime startTime; |
|
134 TCalTime endTime; |
|
135 TCalTime untilTime; |
|
136 TCalRRule rrule; |
|
137 CTzRules* tzRules; |
|
138 |
|
139 // Allocate a UID. |
|
140 uid = HBufC8::NewL(50); |
|
141 uid->Des().Copy(_L8("{70706C03-015C-4550-BFAF-1B7067BF0141}")); |
|
142 |
|
143 // Symbian's day of month values are 0-based. |
|
144 startTime.SetTimeUtcL(TTime(TDateTime(2005, EMarch, 19, 19, 00, 0, 0))); |
|
145 endTime.SetTimeUtcL(TTime(TDateTime(2005, EMarch, 19, 19, 30, 0, 0))); |
|
146 untilTime.SetTimeUtcL(TTime(TDateTime(2005, EApril, 9, 19, 00, 0, 0))); |
|
147 |
|
148 // Create the recurrence rule |
|
149 rrule.SetDtStart( startTime ); |
|
150 rrule.SetInterval( 1 ); |
|
151 rrule.SetUntil( untilTime ); |
|
152 rrule.SetType( TCalRRule::EDaily ); |
|
153 |
|
154 // Create time zone rules |
|
155 tzRules = CTzRules::NewL(); |
|
156 tzRules->SetInitialStdTimeOffset( +420 ); |
|
157 tzRules->SetStartYear( 0 ); |
|
158 tzRules->SetEndYear( 9999 ); |
|
159 // Arizona does not observe daylight savings time, so do not add any additional rules. |
|
160 |
|
161 // Setting current device Time Zone to USA/Chicago (Observers DST) |
|
162 // |
|
163 // USA, Chicago - UTC-6hrs Winter Time and UTC-5hrs Summer Time |
|
164 // DST starts on Sunday, 2 April 2005, 02:00 local standard time |
|
165 // DST ends on Sunday, 29 October 2005, 02:00 local daylight time |
|
166 |
|
167 // Device Time Zone |
|
168 iTestLib->SetTimeZoneL(KAmericaChicago); |
|
169 |
|
170 // Create the entry. |
|
171 entry = CCalEntry::NewL( CCalEntry::EAppt, uid, CCalEntry::EMethodNone, 0 ); |
|
172 |
|
173 entry->SetStartAndEndTimeL( startTime, endTime ); |
|
174 |
|
175 entry->SetSummaryL( _L("Daily 3/20/2005 thru 4/10/2005 at 12:00pm") ); |
|
176 |
|
177 // Set entry's repeat rule |
|
178 entry->SetRRuleL( rrule ); |
|
179 |
|
180 // Set entry's repeat rule's time zone (different from the device time zone) |
|
181 entry->SetTzRulesL( *tzRules ); |
|
182 |
|
183 delete tzRules; |
|
184 |
|
185 entries.Append( entry ); |
|
186 |
|
187 // Store the recurring entry |
|
188 TInt successCount; |
|
189 TRAPD( err, iTestLib->SynCGetEntryViewL().StoreL( entries, successCount ) ); |
|
190 |
|
191 // CHECKPOINT 1: Check that all the entries were successfully added (one entry) |
|
192 test(err == KErrNone && successCount == entries.Count()); |
|
193 |
|
194 entries.ResetAndDestroy(); |
|
195 |
|
196 // Define the time range to find the instances |
|
197 startTime.SetTimeUtcL(TCalTime::MinTime()); |
|
198 endTime.SetTimeUtcL(TCalTime::MaxTime()); |
|
199 |
|
200 CalCommon::TCalTimeRange timeRange(startTime, endTime); |
|
201 |
|
202 RPointerArray<CCalInstance> instanceList; |
|
203 |
|
204 // Find all the instances |
|
205 iTestLib->SynCGetInstanceViewL().FindInstanceL( instanceList, CalCommon::EIncludeAll, timeRange ); |
|
206 |
|
207 // Display all the instances found |
|
208 for (TInt instanceCounter = 0; instanceCounter < instanceList.Count(); ++instanceCounter) |
|
209 { |
|
210 TDateTime instanceDateTime = instanceList[instanceCounter]->StartTimeL().TimeUtcL().DateTime(); |
|
211 RDebug::Print(_L("Found instance at %d:%d on %d/%d/%d"), |
|
212 instanceDateTime.Hour(), instanceDateTime.Minute(), instanceDateTime.Day()+1, instanceDateTime.Month()+1, instanceDateTime.Year()); |
|
213 } |
|
214 |
|
215 // Retrieve the last instance / last day for testing purposes |
|
216 CCalInstance* lastInstance = instanceList[instanceList.Count() - 1]; |
|
217 |
|
218 TInt lastDay = lastInstance->StartTimeL().TimeUtcL().DateTime().Day(); |
|
219 |
|
220 // CHECKPOINT 2: Check that the last day is valid |
|
221 test(lastDay == untilTime.TimeUtcL().DateTime().Day()); |
|
222 |
|
223 instanceList.ResetAndDestroy(); |
|
224 } |
|
225 |
|
226 void CCalTzInstanceTest::DoCountTestL() |
|
227 { |
|
228 iTestLib->CleanDatabaseL(); |
|
229 |
|
230 RPointerArray<CCalEntry> entries; |
|
231 |
|
232 // create entry with repeat rule set by the Count, then change the time zone and check end date is correct |
|
233 CCalEntry* entry; |
|
234 HBufC8* uid; |
|
235 TCalTime startTime; |
|
236 TCalTime endTime; |
|
237 TCalTime untilTime; |
|
238 TCalRRule rrule; |
|
239 CTzRules* tzRules; |
|
240 |
|
241 // Allocate a UID. |
|
242 uid = HBufC8::NewL(50); |
|
243 uid->Des().Copy(_L8("{70706C03-015C-4550-BFAF-1B7067BF0141}")); |
|
244 |
|
245 // Symbian's day of month values are 0-based. |
|
246 startTime.SetTimeUtcL(TTime(TDateTime(2005, EMarch, 19, 19, 00, 0, 0))); |
|
247 endTime.SetTimeUtcL(TTime(TDateTime(2005, EMarch, 19, 19, 30, 0, 0))); |
|
248 |
|
249 // Create the recurrence rule |
|
250 rrule.SetDtStart( startTime ); |
|
251 rrule.SetInterval( 1 ); |
|
252 rrule.SetCount( 22 ); |
|
253 rrule.SetType( TCalRRule::EDaily ); |
|
254 |
|
255 // Create time zone rules |
|
256 tzRules = CTzRules::NewL(); |
|
257 tzRules->SetInitialStdTimeOffset( -420 ); |
|
258 tzRules->SetStartYear( 0 ); |
|
259 tzRules->SetEndYear( 9999 ); |
|
260 |
|
261 // Create the entry. |
|
262 entry = CCalEntry::NewL( CCalEntry::EAppt, uid, CCalEntry::EMethodNone, 0 ); |
|
263 |
|
264 entry->SetStartAndEndTimeL( startTime, endTime ); |
|
265 |
|
266 entry->SetSummaryL( _L("Daily 3/20/2005 thru 4/10/2005 at 12:00pm") ); |
|
267 |
|
268 // Set entry's repeat rule |
|
269 entry->SetRRuleL( rrule ); |
|
270 |
|
271 // Set entry's repeat rule's time zone (different from the device time zone) |
|
272 entry->SetTzRulesL( *tzRules ); |
|
273 |
|
274 delete tzRules; |
|
275 |
|
276 entries.Append( entry ); |
|
277 |
|
278 // Store the recurring entry |
|
279 TInt successCount; |
|
280 TRAPD( err, iTestLib->SynCGetEntryViewL().StoreL( entries, successCount ) ); |
|
281 |
|
282 // CHECKPOINT 1: Check that all the entries were successfully added |
|
283 test(err == KErrNone && successCount == entries.Count()); |
|
284 |
|
285 entries.ResetAndDestroy(); |
|
286 |
|
287 // Define the time range to find the instances |
|
288 startTime.SetTimeUtcL(TCalTime::MinTime()); |
|
289 endTime.SetTimeUtcL(TCalTime::MaxTime()); |
|
290 |
|
291 CalCommon::TCalTimeRange timeRange(startTime, endTime); |
|
292 |
|
293 RPointerArray<CCalInstance> instanceList; |
|
294 |
|
295 // Find all the instances |
|
296 iTestLib->SynCGetInstanceViewL().FindInstanceL( instanceList, CalCommon::EIncludeAll, timeRange ); |
|
297 |
|
298 // CHECKPOINT 2: Check all the instances are found |
|
299 test(instanceList.Count() == 22); |
|
300 |
|
301 instanceList.ResetAndDestroy(); |
|
302 } |
|
303 |
|
304 CCalTzInstanceTest* CCalTzInstanceTest::NewLC() |
|
305 { |
|
306 CCalTzInstanceTest* self = new (ELeave) CCalTzInstanceTest(); |
|
307 |
|
308 CleanupStack::PushL(self); |
|
309 self->ConstructL(); |
|
310 |
|
311 return (self); |
|
312 } |
|
313 |
|
314 void CCalTzInstanceTest::ConstructL() |
|
315 { |
|
316 iTestLib = CCalTestLibrary::NewL(); |
|
317 |
|
318 iTestLib->ReplaceFileL(KCalName()); |
|
319 iTestLib->OpenFileL(KCalName()); |
|
320 } |
|
321 |
|
322 CCalTzInstanceTest::~CCalTzInstanceTest() |
|
323 { |
|
324 delete iTestLib; |
|
325 } |
|
326 |
|
327 |
|
328 /** |
|
329 @SYMTestCaseID PIM-TCAL-TZ-INSTANCE-0002 |
|
330 @SYMDEF DEF113539 |
|
331 @SYMTestType UT |
|
332 @SYMTestPriority NORMAL |
|
333 @SYMDEF DEF113539 |
|
334 @SYMTestCaseDesc Check if cache at Tz Client is cleared using the API ClearTzClientCacheL(). |
|
335 |
|
336 @SYMTestActions |
|
337 1) Clean Tz Clientside cache before starting OOM test. |
|
338 2) Run OOM test. |
|
339 3) Clean Tz Clientside cache allocated inside OOM loop. |
|
340 4) Test if any memory allocated inside OOM loop has not been released. |
|
341 5) Clean Tz Clientside cache and RESTART caching. |
|
342 |
|
343 @SYMTestExpectedResults There should not be any memory leaks. |
|
344 */ |
|
345 |
|
346 void CCalTzInstanceTest::DoOOMTestTzClientCacheClearingL() |
|
347 { |
|
348 test.Next(_L("@SYMTESTCaseID:PIM-TCAL-TZ-INSTANCE-0002 Testing Functionality for cleaning up Tz client cache.")); |
|
349 |
|
350 |
|
351 TInt tryCount = 1; |
|
352 TInt err = 0; |
|
353 TBool cleanCache = EFalse; |
|
354 |
|
355 // OOM LOOP BEGINS |
|
356 for ( ;; ) |
|
357 { |
|
358 iTestLib->__dbgClearTzClientCacheL(cleanCache); |
|
359 |
|
360 __UHEAP_SETFAIL(RHeap::EFailNext, tryCount); |
|
361 __UHEAP_MARK; |
|
362 TRAP(err, SupportCodeTestTzClientCacheClearingL()); |
|
363 |
|
364 iTestLib->__dbgClearTzClientCacheL(cleanCache); |
|
365 |
|
366 if ( err==KErrNone ) |
|
367 { |
|
368 __UHEAP_RESET; |
|
369 RDebug::Printf("OOM test for checking cleaning of Tz client cache compelete"); |
|
370 break; |
|
371 } |
|
372 test(err == KErrNoMemory); |
|
373 __UHEAP_MARKEND; |
|
374 __UHEAP_SETFAIL(RHeap::ENone, 0); |
|
375 ++tryCount; |
|
376 } |
|
377 // OOM LOOP ENDS |
|
378 cleanCache = ETrue; |
|
379 iTestLib->__dbgClearTzClientCacheL(cleanCache); //RESTARTING CACHING |
|
380 } |
|
381 |
|
382 /** |
|
383 Support function for OOM test function DoOOMTestTzClientCacheClearingL. |
|
384 Code attempts to convert different times so that Tz client cache keep variying. |
|
385 */ |
|
386 void CCalTzInstanceTest::SupportCodeTestTzClientCacheClearingL() |
|
387 { |
|
388 |
|
389 TTime gettime; |
|
390 TCalTime calStartTime; |
|
391 |
|
392 TTime recentTime(TDateTime(2005, EMay, 12, 9, 0, 0, 0)); |
|
393 calStartTime.SetTimeUtcL(recentTime); |
|
394 |
|
395 TTime eighties(TDateTime(1985, EAugust, 12, 9, 0, 0, 0)); |
|
396 calStartTime.SetTimeLocalL(eighties); |
|
397 gettime = calStartTime.TimeUtcL(); |
|
398 |
|
399 TTime seventies(TDateTime(1975, EAugust, 12, 9, 0, 0, 0)); |
|
400 calStartTime.SetTimeLocalL(seventies); |
|
401 gettime = calStartTime.TimeUtcL(); |
|
402 |
|
403 TTime sixties(TDateTime(1965, EAugust, 12, 9, 0, 0, 0)); |
|
404 calStartTime.SetTimeUtcL(sixties); |
|
405 gettime = calStartTime.TimeLocalL(); |
|
406 |
|
407 } |
|
408 |
|
409 |
|
410 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
|
411 * DoTestL() |
|
412 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |
|
413 |
|
414 static void DoTestL() |
|
415 { |
|
416 CCalTzInstanceTest* testManager = CCalTzInstanceTest::NewLC(); |
|
417 |
|
418 |
|
419 TPerformanceTimer timer(test); |
|
420 timer.Start(); |
|
421 |
|
422 |
|
423 // Run the test suite |
|
424 |
|
425 testManager->DoCountYearlyByDayTestL(); |
|
426 testManager->DoUntilAfterDSTChangeTestL(); |
|
427 testManager->DoCountTestL(); |
|
428 testManager->DoOOMTestTzClientCacheClearingL(); |
|
429 |
|
430 |
|
431 timer.Stop(); |
|
432 test.Printf(_L("Done\n")); |
|
433 // printout performance time |
|
434 timer.PrintOut(); |
|
435 |
|
436 |
|
437 CleanupStack::PopAndDestroy(testManager); |
|
438 } |
|
439 |
|
440 |
|
441 /** |
|
442 |
|
443 @SYMTestCaseID PIM-TCAL-TZ-INSTANCE-0001 |
|
444 |
|
445 */ |
|
446 |
|
447 TInt E32Main() |
|
448 { |
|
449 __UHEAP_MARK; |
|
450 |
|
451 test.Start(_L("@SYMTESTCaseID:PIM-TCAL-TZ-INSTANCE-0001 Calendar Interim API Time Zone and Instance test suite")); |
|
452 |
|
453 test.Title(); |
|
454 |
|
455 CTrapCleanup* trapCleanup = CTrapCleanup::New(); |
|
456 CActiveScheduler* scheduler = new (ELeave) CActiveScheduler; |
|
457 |
|
458 CActiveScheduler::Install(scheduler); |
|
459 |
|
460 TRAPD(ret, DoTestL()); |
|
461 test(ret == KErrNone); |
|
462 |
|
463 delete scheduler; |
|
464 delete trapCleanup; |
|
465 |
|
466 test.End(); |
|
467 test.Close(); |
|
468 |
|
469 __UHEAP_MARKEND; |
|
470 |
|
471 return (KErrNone); |
|
472 } |