|
1 // Copyright (c) 2005-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 "tcal_BadRRule.h" |
|
17 |
|
18 _LIT(KTestName,"tcal_BadRRule"); |
|
19 _LIT8(KGUID, "A_Global_UID"); |
|
20 _LIT8(KGUID1, "A_TODO_ENTRY"); |
|
21 |
|
22 static RTest test(KTestName); |
|
23 |
|
24 static void CleanupCCalEntryArray(TAny* aPointer) |
|
25 { |
|
26 RPointerArray<CCalEntry>* calEntryArray = static_cast<RPointerArray<CCalEntry>*>(aPointer); |
|
27 if (calEntryArray) |
|
28 { |
|
29 calEntryArray->ResetAndDestroy(); |
|
30 } |
|
31 } |
|
32 |
|
33 |
|
34 CBadRRule* CBadRRule::NewL(CCalTestLibrary* aTestLib) |
|
35 { |
|
36 CBadRRule* self = new (ELeave) CBadRRule(); |
|
37 CleanupStack::PushL(self); |
|
38 self->iTestLib = aTestLib ; |
|
39 self->ConstructL(); |
|
40 CleanupStack::Pop(self); |
|
41 return self; |
|
42 } |
|
43 |
|
44 |
|
45 void CBadRRule::ConstructL() |
|
46 { |
|
47 iTestLib->ReplaceFileL(KTestName); |
|
48 iTestLib->OpenFileL(KTestName); |
|
49 } |
|
50 |
|
51 |
|
52 CBadRRule::~CBadRRule() |
|
53 { |
|
54 test.Close(); |
|
55 } |
|
56 |
|
57 void CBadRRule::CreateToDoEntryL() |
|
58 { |
|
59 RPointerArray<CCalEntry> entryarr ; |
|
60 CleanupResetAndDestroyPushL(entryarr); |
|
61 |
|
62 |
|
63 TInt num ; |
|
64 |
|
65 HBufC8* guid = KGUID1().AllocLC(); // ownership of guid gets transferred |
|
66 CCalEntry *entry = CCalEntry::NewL(CCalEntry::ETodo, guid, CCalEntry::EMethodNone, 0) ; |
|
67 CleanupStack::Pop(guid); |
|
68 CleanupStack::PushL(entry) ; |
|
69 |
|
70 TCalTime startTime ; |
|
71 TCalTime endTime ; |
|
72 startTime.SetTimeUtcL(TTime(TDateTime(2006, EJanuary, 8, 10, 30, 0, 0))) ; |
|
73 endTime.SetTimeUtcL(startTime.TimeUtcL() + TTimeIntervalDays(1)) ; |
|
74 |
|
75 entry->SetStartAndEndTimeL(startTime, endTime) ; |
|
76 |
|
77 TCalTime endTime1 ; |
|
78 endTime1.SetTimeUtcL(TTime(TDateTime(2006, EJanuary, 23, 10, 5, 0, 0))) ; |
|
79 |
|
80 |
|
81 TCalRRule rrule(TCalRRule::EWeekly) ; |
|
82 |
|
83 rrule.SetDtStart(startTime); |
|
84 rrule.SetUntil(endTime1); |
|
85 rrule.SetInterval(1); |
|
86 |
|
87 RArray<TDay> days; |
|
88 CleanupClosePushL(days); |
|
89 days.AppendL(ETuesday); |
|
90 rrule.SetByDay(days); |
|
91 CleanupStack::PopAndDestroy(&days); |
|
92 |
|
93 entry->SetRRuleL(rrule) ; |
|
94 // both entry and rrule start time should be aligned to the first instance |
|
95 TCalRRule setRRule ; |
|
96 entry->GetRRuleL(setRRule) ; |
|
97 |
|
98 test(setRRule.DtStart().TimeUtcL() == rrule.DtStart().TimeUtcL()) ; |
|
99 entryarr.AppendL(entry) ; |
|
100 CleanupStack::Pop(entry); |
|
101 |
|
102 iCalEntryView->StoreL(entryarr, num) ; |
|
103 entryarr.ResetAndDestroy(); |
|
104 |
|
105 TCalTime recId; |
|
106 recId.SetTimeUtcL(TTime(TDateTime(2006, EJanuary, 9, 10, 30, 0, 0))); // creating recurrence id |
|
107 |
|
108 guid = KGUID1().AllocLC(); // ownership of guid gets transferred |
|
109 entry = CCalEntry::NewL(CCalEntry::ETodo, guid, CCalEntry::EMethodNone, 0, recId, CalCommon::EThisOnly); |
|
110 CleanupStack::Pop(guid); |
|
111 CleanupStack::PushL(entry) ; |
|
112 |
|
113 TCalTime startTime3 ; |
|
114 TCalTime endTime3 ; |
|
115 startTime3.SetTimeUtcL(TTime(TDateTime(2006, EJanuary, 7, 10, 2, 0, 0))) ; |
|
116 endTime3.SetTimeUtcL(startTime3.TimeUtcL() + TTimeIntervalHours(1)) ; |
|
117 entry->SetStartAndEndTimeL(startTime3, endTime3) ; |
|
118 |
|
119 entryarr.AppendL(entry) ; |
|
120 CleanupStack::Pop(entry) ; |
|
121 |
|
122 iCalEntryView->StoreL(entryarr, num) ; |
|
123 CleanupStack::PopAndDestroy(&entryarr); |
|
124 |
|
125 RArray<TTime> insTimes ; |
|
126 |
|
127 insTimes.Append(TTime(TDateTime(2006, EJanuary, 7, 11, 2, 0, 0))) ; |
|
128 insTimes.Append(TTime(TDateTime(2006, EJanuary, 16, 10, 30, 0, 0))) ; |
|
129 |
|
130 CleanupClosePushL(insTimes) ; |
|
131 CheckInstancesL(insTimes) ; |
|
132 CleanupStack::PopAndDestroy(&insTimes) ; |
|
133 // time portion of repeat's end eliminates the third instance |
|
134 |
|
135 } |
|
136 |
|
137 void CBadRRule::CreateParentL() |
|
138 { |
|
139 RPointerArray<CCalEntry> entryarr ; |
|
140 CleanupResetAndDestroyPushL(entryarr); |
|
141 |
|
142 TInt num ; |
|
143 |
|
144 HBufC8* guid = KGUID().AllocLC(); // ownership of guid gets transferred |
|
145 CCalEntry *entry = CCalEntry::NewL(CCalEntry::EEvent, guid, CCalEntry::EMethodNone, 0) ; |
|
146 CleanupStack::Pop(guid); |
|
147 CleanupStack::PushL(entry) ; |
|
148 |
|
149 TCalTime startTime ; |
|
150 TCalTime endTime ; |
|
151 startTime.SetTimeUtcL(TTime(TDateTime(2006, EJanuary, 7, 10, 1, 0, 0))) ; |
|
152 endTime.SetTimeUtcL(startTime.TimeUtcL() + TTimeIntervalHours(1)) ; |
|
153 |
|
154 entry->SetStartAndEndTimeL(startTime, endTime) ; |
|
155 |
|
156 TCalTime endTime1; |
|
157 endTime1.SetTimeUtcL(TTime(TDateTime(2006, EJanuary, 23, 10, 5, 0, 0))) ; |
|
158 |
|
159 |
|
160 TCalRRule rrule(TCalRRule::EWeekly) ; |
|
161 |
|
162 rrule.SetDtStart(startTime); |
|
163 rrule.SetUntil(endTime1); |
|
164 rrule.SetInterval(1); |
|
165 |
|
166 RArray<TDay> days; |
|
167 CleanupClosePushL(days); |
|
168 days.AppendL(ETuesday); |
|
169 rrule.SetByDay(days); |
|
170 CleanupStack::PopAndDestroy(&days); |
|
171 |
|
172 entry->SetRRuleL(rrule) ; |
|
173 TCalRRule setRRule ; |
|
174 entry->GetRRuleL(setRRule) ; |
|
175 |
|
176 test(setRRule.DtStart().TimeUtcL() == rrule.DtStart().TimeUtcL()) ; |
|
177 entryarr.AppendL(entry) ; |
|
178 CleanupStack::Pop(entry); |
|
179 |
|
180 iCalEntryView->StoreL(entryarr, num) ; |
|
181 entryarr.ResetAndDestroy() ; |
|
182 |
|
183 iCalEntryView->FetchL(KGUID(), entryarr); |
|
184 TCalRRule savedRRule ; |
|
185 entryarr[0]->GetRRuleL(savedRRule) ; |
|
186 |
|
187 TCalTime matchTime ; /* Jan 10, 2006 is the first Tuesday */ |
|
188 matchTime.SetTimeUtcL(TTime(TDateTime(2006, EJanuary, 9, 10, 1, 0, 0))) ; |
|
189 //When the entry is stored, the repeat start time is adjusted so that it fits the rule (10th January is Tuesday |
|
190 test(savedRRule.DtStart().TimeUtcL() == matchTime.TimeUtcL()) ; |
|
191 test(entryarr[0]->StartTimeL().TimeUtcL() == (matchTime.TimeUtcL())) ; |
|
192 |
|
193 |
|
194 CleanupStack::PopAndDestroy(&entryarr) ; |
|
195 |
|
196 RArray<TTime> insTimes ; |
|
197 insTimes.Append(TTime(TDateTime(2006, EJanuary, 9, 10, 1, 0, 0))) ; |
|
198 insTimes.Append(TTime(TDateTime(2006, EJanuary, 16, 10, 1, 0, 0))) ; |
|
199 insTimes.Append(TTime(TDateTime(2006, EJanuary, 23, 10, 1, 0, 0))) ; |
|
200 |
|
201 CleanupClosePushL(insTimes) ; |
|
202 CheckInstancesL(insTimes) ; |
|
203 CleanupStack::PopAndDestroy(&insTimes) ; |
|
204 } |
|
205 |
|
206 |
|
207 void CBadRRule::CreateChild1L() |
|
208 { |
|
209 TInt num ; |
|
210 |
|
211 TCalTime recId; |
|
212 |
|
213 recId.SetTimeUtcL(TTime(TDateTime(2006, EJanuary, 9, 10, 1, 0, 0))); // creating recurrence id |
|
214 |
|
215 HBufC8* guid1 = KGUID().AllocLC(); // ownership of guid1 gets transferred |
|
216 CCalEntry *entry1 = CCalEntry::NewL(CCalEntry::EEvent, guid1, CCalEntry::EMethodNone, 0, recId, CalCommon::EThisOnly); |
|
217 CleanupStack::Pop(guid1); |
|
218 CleanupStack::PushL(entry1) ; |
|
219 |
|
220 TCalTime startTime3 ; |
|
221 TCalTime endTime3 ; |
|
222 startTime3.SetTimeUtcL(TTime(TDateTime(2006, EJanuary, 7, 10, 2, 0, 0))) ; |
|
223 endTime3.SetTimeUtcL(startTime3.TimeUtcL() + TTimeIntervalHours(1)) ; |
|
224 entry1->SetStartAndEndTimeL(startTime3, endTime3) ; |
|
225 |
|
226 RPointerArray<CCalEntry> entryarr1 ; |
|
227 entryarr1.AppendL(entry1) ; |
|
228 iCalEntryView->StoreL(entryarr1, num) ; |
|
229 entryarr1.Close() ; |
|
230 |
|
231 CleanupStack::PopAndDestroy(entry1) ; |
|
232 |
|
233 } |
|
234 |
|
235 void CBadRRule::CreateChild2L() |
|
236 { |
|
237 TInt num ; |
|
238 |
|
239 TCalTime rec2 ; |
|
240 rec2.SetTimeUtcL(TTime(TDateTime(2006, EJanuary, 16, 10, 1, 0, 0))) ; //Jan 17 |
|
241 |
|
242 HBufC8* guid_c2 = KGUID().AllocLC(); // ownership of guid1 gets transferred |
|
243 CCalEntry *entry_c2 = CCalEntry::NewL(CCalEntry::EEvent, guid_c2, CCalEntry::EMethodNone, 0, rec2, CalCommon::EThisAndAll); |
|
244 CleanupStack::Pop(guid_c2); |
|
245 CleanupStack::PushL(entry_c2) ; |
|
246 |
|
247 TCalTime startTime_c2 ; |
|
248 TCalTime endTime_c2 ; |
|
249 startTime_c2.SetTimeUtcL(TTime(TDateTime(2006, EJanuary, 8, 11, 2, 0, 0))) ; |
|
250 endTime_c2.SetTimeUtcL(startTime_c2.TimeUtcL() + TTimeIntervalHours(1)) ; |
|
251 entry_c2->SetStartAndEndTimeL(startTime_c2, endTime_c2) ; |
|
252 |
|
253 RPointerArray<CCalEntry> entryarr_c2 ; |
|
254 entryarr_c2.AppendL(entry_c2) ; |
|
255 iCalEntryView->StoreL(entryarr_c2, num) ; |
|
256 entryarr_c2.Close() ; |
|
257 |
|
258 CleanupStack::PopAndDestroy(entry_c2) ; |
|
259 |
|
260 } |
|
261 |
|
262 |
|
263 void CBadRRule::ModifyEntriesL() |
|
264 { |
|
265 TInt num, err ; |
|
266 |
|
267 RPointerArray<CCalEntry> entryarr3 ; |
|
268 iCalEntryView->FetchL(KGUID(), entryarr3) ; |
|
269 test(entryarr3.Count() == 3) ; |
|
270 /* got 3 entries - EThisAndAll of second child do not have any special effect */ |
|
271 |
|
272 CleanupStack::PushL(TCleanupItem(CleanupCCalEntryArray, &entryarr3)); |
|
273 |
|
274 TCalTime startTime4 ; |
|
275 TCalTime endTime4 ; |
|
276 startTime4.SetTimeUtcL(TTime(TDateTime(2006, EJanuary, 1, 10, 1, 0, 0))) ; |
|
277 endTime4.SetTimeUtcL(startTime4.TimeUtcL() + TTimeIntervalHours(1)) ; |
|
278 |
|
279 entryarr3[0]->SetStartAndEndTimeL(startTime4, endTime4) ; |
|
280 |
|
281 //The repeating starting time will not be adjusted until the entry is stored |
|
282 test(entryarr3[0]->StartTimeL().TimeUtcL() == startTime4.TimeUtcL()) ; |
|
283 |
|
284 TCalRRule savedRRule ; |
|
285 entryarr3[0]->GetRRuleL(savedRRule) ; |
|
286 |
|
287 //The repeating starting time will not be adjusted until the entry is stored |
|
288 test(savedRRule.DtStart().TimeUtcL() == startTime4.TimeUtcL()) ; |
|
289 |
|
290 |
|
291 iCalEntryView->StoreL(entryarr3, num) ; |
|
292 // store succeeds, because children are still aligned to an instance |
|
293 |
|
294 CleanupStack::PopAndDestroy(&entryarr3) ; |
|
295 |
|
296 RArray<TTime> insTimes ; |
|
297 insTimes.Append(TTime(TDateTime(2006, EJanuary, 2, 10, 1, 0, 0))) ; |
|
298 insTimes.Append(TTime(TDateTime(2006, EJanuary, 7, 10, 2, 0, 0))) ; |
|
299 insTimes.Append(TTime(TDateTime(2006, EJanuary, 8, 11, 2, 0, 0))) ; |
|
300 insTimes.Append(TTime(TDateTime(2006, EJanuary, 23, 10, 1, 0, 0))) ; |
|
301 |
|
302 CleanupClosePushL(insTimes) ; |
|
303 CheckInstancesL(insTimes) ; |
|
304 CleanupStack::PopAndDestroy(&insTimes) ; |
|
305 |
|
306 // this is interesting - there could be 4 instance, but as the count value of the |
|
307 // repeat rule has been kept intact, we still get 3 instances, |
|
308 // but they are shifted . |
|
309 |
|
310 /* store is successful with modified time - now we shall change rrule */ |
|
311 |
|
312 RPointerArray<CCalEntry> entryarr4 ; |
|
313 iCalEntryView->FetchL(KGUID(), entryarr4) ; |
|
314 test(entryarr4.Count() == 3) ; |
|
315 |
|
316 CleanupStack::PushL(TCleanupItem(CleanupCCalEntryArray, &entryarr4)); |
|
317 |
|
318 CCalEntry *entry = entryarr4[0] ; |
|
319 |
|
320 |
|
321 TCalTime startTime1 ; |
|
322 TCalTime endTime1 ; |
|
323 TCalTime untilTime1 ; |
|
324 |
|
325 startTime1.SetTimeUtcL(TTime(TDateTime(2006, EJanuary, 16, 10, 1, 0, 0))) ; |
|
326 endTime1.SetTimeUtcL(TTime(TDateTime(2006, EJanuary, 16, 11, 1, 0, 0))) ; |
|
327 untilTime1.SetTimeUtcL(TTime(TDateTime(2006, EJanuary, 26, 10, 5, 0, 0))) ; |
|
328 |
|
329 |
|
330 TCalRRule rrule(TCalRRule::EWeekly) ; |
|
331 |
|
332 rrule.SetDtStart(startTime1); |
|
333 rrule.SetUntil(untilTime1); |
|
334 rrule.SetInterval(1); |
|
335 |
|
336 RArray<TDay> days; |
|
337 CleanupClosePushL(days); |
|
338 days.AppendL(ETuesday); |
|
339 rrule.SetByDay(days); |
|
340 CleanupStack::PopAndDestroy(&days); |
|
341 |
|
342 entry->SetStartAndEndTimeL(startTime1, endTime1); |
|
343 entry->SetRRuleL(rrule) ; |
|
344 |
|
345 TRAP(err, iCalEntryView->StoreL(entryarr4, num)) ; |
|
346 |
|
347 test(err == -1) ; // due to change in rrule store should fail |
|
348 test(num == 2) ; // only parent + child2 have been saved |
|
349 |
|
350 CleanupStack::PopAndDestroy(&entryarr4) ; |
|
351 } |
|
352 |
|
353 |
|
354 void CBadRRule::CheckInstancesL(RArray<TTime> &insTimes) |
|
355 { |
|
356 RPointerArray<CCalInstance> instanceArray ; |
|
357 |
|
358 TCalTime startTime ; |
|
359 TCalTime endTime ; |
|
360 startTime.SetTimeUtcL(TTime(TDateTime(2006, EJanuary, 1, 10, 1, 0, 0))) ; |
|
361 endTime.SetTimeUtcL(TTime(TDateTime(2006, EJanuary, 30, 10, 5, 0, 0))) ; |
|
362 |
|
363 CalCommon::TCalTimeRange timeRange(startTime, endTime); |
|
364 |
|
365 CCalInstanceView &insView = iTestLib->SynCGetInstanceViewL(); |
|
366 |
|
367 insView.FindInstanceL(instanceArray, CalCommon::EIncludeAll, timeRange); |
|
368 |
|
369 TInt count = instanceArray.Count() ; |
|
370 TInt count1 = insTimes.Count() ; |
|
371 |
|
372 test(count == count1) ; |
|
373 TInt i, j ; |
|
374 |
|
375 for(i = 0; i < count1; i++) |
|
376 { |
|
377 for(j = 0; j < count; j++) |
|
378 { |
|
379 if (instanceArray[j] == NULL) |
|
380 { |
|
381 continue ; |
|
382 } |
|
383 TTime t1 = instanceArray[j]->Time().TimeUtcL() ; |
|
384 TDateTime d1 = t1.DateTime() ; |
|
385 if (insTimes[i] == t1) |
|
386 { |
|
387 delete instanceArray[j] ; |
|
388 instanceArray[j] = NULL ; |
|
389 break ; |
|
390 } |
|
391 } |
|
392 test(j < count) ; |
|
393 } |
|
394 |
|
395 instanceArray.Close() ; |
|
396 } |
|
397 |
|
398 |
|
399 void CBadRRule::DeleteEntriesL() |
|
400 { |
|
401 |
|
402 RPointerArray<CCalEntry> entryarr5 ; |
|
403 iCalEntryView->FetchL(KGUID(), entryarr5) ; |
|
404 |
|
405 test(entryarr5.Count() == 2) ; |
|
406 // one bad child entry could not be saved before |
|
407 |
|
408 CleanupStack::PushL(TCleanupItem(CleanupCCalEntryArray, &entryarr5)); |
|
409 |
|
410 CCalEntry *entry2 = entryarr5[0] ; // get the parent |
|
411 |
|
412 iCalEntryView->DeleteL(*entry2) ; |
|
413 |
|
414 |
|
415 CleanupStack::PopAndDestroy(&entryarr5) ; |
|
416 |
|
417 /* now see if it has been deleted */ |
|
418 |
|
419 RPointerArray<CCalEntry> entryarr6 ; |
|
420 iCalEntryView->FetchL(KGUID(), entryarr6) ; |
|
421 |
|
422 test(entryarr6.Count() == 0) ; |
|
423 |
|
424 entryarr6.Close() ; |
|
425 } |
|
426 |
|
427 |
|
428 |
|
429 void CBadRRule::TestBadRRuleL() |
|
430 { |
|
431 |
|
432 test.Printf(_L("TestBadRRule start\n")); |
|
433 |
|
434 CCalEntryView& view = iTestLib->SynCGetEntryViewL() ; |
|
435 iCalEntryView = &view ; |
|
436 |
|
437 |
|
438 CreateParentL() ; |
|
439 |
|
440 |
|
441 CreateChild2L() ; // Create child entry with exception |
|
442 |
|
443 CreateChild1L() ; // Creating a another child |
|
444 |
|
445 |
|
446 RArray<TTime> insTimes ; |
|
447 |
|
448 insTimes.Append(TTime(TDateTime(2006, EJanuary, 7, 10, 2, 0, 0))) ; |
|
449 insTimes.Append(TTime(TDateTime(2006, EJanuary, 8, 11, 2, 0, 0))) ; |
|
450 insTimes.Append(TTime(TDateTime(2006, EJanuary, 23, 10, 1, 0, 0))) ; |
|
451 |
|
452 CleanupClosePushL(insTimes) ; |
|
453 CheckInstancesL(insTimes) ; |
|
454 CleanupStack::PopAndDestroy(&insTimes) ; |
|
455 |
|
456 ModifyEntriesL() ; // now modifying the parent again |
|
457 |
|
458 DeleteEntriesL() ; // now try deleting entry |
|
459 |
|
460 CreateToDoEntryL() ; |
|
461 |
|
462 |
|
463 /* if executed to this point test has actully passed */ |
|
464 |
|
465 test.Printf(_L("TestBadRRule successful\n")); |
|
466 } |
|
467 |