|
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 // Contains implementation of CTestCreateCalEntriesStep class |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file |
|
20 @internalTechnology |
|
21 */ |
|
22 |
|
23 // User Include |
|
24 #include "TestCreateCalEntriesStep.h" |
|
25 #include "ProgressCallBack.h" |
|
26 |
|
27 // System Includes |
|
28 #include <calalarm.h> |
|
29 #include <calcontent.h> |
|
30 |
|
31 /** |
|
32 Constructor. Sets the test step name. Testserver reference passed to make use |
|
33 of TEF's method of sharing data between test steps |
|
34 @internalTechnology |
|
35 @test |
|
36 */ |
|
37 CTestCreateCalEntriesStep::CTestCreateCalEntriesStep(CTestMultipleAlarmsServer& aTestServer) |
|
38 : CTestBaseStep(aTestServer) |
|
39 { |
|
40 //Call base class method to set human readable name for test step |
|
41 SetTestStepName(KTestCreateCalEntriesStep); |
|
42 } |
|
43 |
|
44 /** |
|
45 Call back to destroy the pointer array |
|
46 @param aPtr Pointer to the pointer array |
|
47 @internalTechnology |
|
48 @test |
|
49 */ |
|
50 LOCAL_C void DestroyPointerArray(TAny* aPtr) |
|
51 { |
|
52 RPointerArray<CCalEntry>* pointerArray = static_cast<RPointerArray<CCalEntry>*> (aPtr); |
|
53 pointerArray->ResetAndDestroy(); |
|
54 pointerArray->Close(); |
|
55 } |
|
56 |
|
57 /** |
|
58 Base class pure virtual. |
|
59 @return EPass or EFail indicating the result of the test step. |
|
60 @internalTechnology |
|
61 @test |
|
62 */ |
|
63 TVerdict CTestCreateCalEntriesStep::doTestStepL() |
|
64 { |
|
65 CActiveScheduler* sched = new(ELeave) CActiveScheduler; |
|
66 CActiveScheduler::Install(sched); |
|
67 |
|
68 TRAPD(error, CreateCalEntriesL()); |
|
69 PrintIfError(KCreateEntriesError(), error); |
|
70 |
|
71 delete sched; |
|
72 return TestStepResult(); |
|
73 } |
|
74 |
|
75 /** |
|
76 Creates the calendar entries |
|
77 @internalTechnology |
|
78 @test |
|
79 */ |
|
80 void CTestCreateCalEntriesStep::CreateCalEntriesL() |
|
81 { |
|
82 TInt numOfEntries = 0; |
|
83 TPtrC subsections; |
|
84 |
|
85 CCalSession* calSession = CreateAndInitializeCalSessionL(ETrue); |
|
86 CleanupStack::PushL(calSession); |
|
87 CCalEntryView* calEntryView = CreateEntryViewL(calSession); |
|
88 CleanupStack::PushL(calEntryView); |
|
89 |
|
90 ReadIntsFromConfig(ConfigSection(), &KIniNumOfEntries(), &numOfEntries, NULL); |
|
91 ReadStringsFromConfig(ConfigSection(), &KIniSubsections(), &subsections, NULL); |
|
92 if(numOfEntries <= 0) |
|
93 { |
|
94 IniProblem(); |
|
95 } |
|
96 else |
|
97 { |
|
98 RPointerArray<CCalEntry> entryArray; |
|
99 CleanupStack::PushL(TCleanupItem(DestroyPointerArray, &entryArray)); |
|
100 |
|
101 // Fill the array with entries |
|
102 if(subsections.Compare(KYes) == KErrNone) |
|
103 { |
|
104 FillCalEntriesFromSubSectionsL(entryArray, numOfEntries); |
|
105 } |
|
106 else |
|
107 { |
|
108 FillCalEntriesAtWillL(entryArray, numOfEntries); |
|
109 } |
|
110 |
|
111 // Store the entries |
|
112 TInt actualNumOfEntries; |
|
113 calEntryView->StoreL(entryArray, actualNumOfEntries); |
|
114 // Check result |
|
115 CompareAndPrintResult(numOfEntries, actualNumOfEntries); |
|
116 CleanupStack::PopAndDestroy(&entryArray); |
|
117 } |
|
118 CleanupStack::PopAndDestroy(2, calSession); // calEntryView and calSession |
|
119 } |
|
120 |
|
121 /** |
|
122 Constructs the sub-section name |
|
123 @param aSubSectionName The descriptor which is to hold the sub-sec name |
|
124 @param aSubSectionNo The sub section number |
|
125 @internalTechnology |
|
126 @test |
|
127 */ |
|
128 void CTestCreateCalEntriesStep::GetSubSectionName(HBufC*& aSubSectionName, const TInt& aSubSectionNo) |
|
129 { |
|
130 aSubSectionName->Des().Copy(ConfigSection()); |
|
131 aSubSectionName->Des().Append(KDot); |
|
132 aSubSectionName->Des().Append(KEntry); |
|
133 aSubSectionName->Des().AppendNum(aSubSectionNo); |
|
134 } |
|
135 |
|
136 |
|
137 /** |
|
138 Reads the ini sub-sections, initializes the calendar entries and fills the pointer |
|
139 array passed as parameter |
|
140 @param aEntryArray Pointer array to be filled with the entries |
|
141 @param aNumOfEntries No. of entries to be created, so as to loop through the |
|
142 ini sub-sections |
|
143 @internalTechnology |
|
144 @test |
|
145 */ |
|
146 void CTestCreateCalEntriesStep::FillCalEntriesFromSubSectionsL(RPointerArray<CCalEntry>& aEntryArray, const TInt& aNumOfEntries) |
|
147 { |
|
148 TPtrC typeOfEntry; |
|
149 TPtrC gUId; |
|
150 TPtrC alarmMessage; |
|
151 TInt alarmMinsFromNow = 0; |
|
152 |
|
153 TTime now; |
|
154 now.HomeTime(); |
|
155 |
|
156 // Create a HBufC enough to hold the 'sub-section' name |
|
157 // which looks like "<section-name>.entry<#>" |
|
158 HBufC* sectionName = HBufC::NewLC(ConfigSection().Length() + KEntry().Length() + 4); |
|
159 for(TInt sub = 1; sub <= aNumOfEntries; ++sub) |
|
160 { |
|
161 GetSubSectionName(sectionName, sub); |
|
162 if(GetCalEntryDetails(*sectionName, typeOfEntry, gUId, alarmMessage, alarmMinsFromNow)) |
|
163 { |
|
164 CCalEntry* entry = CreateCalEntryL(GetEntryTypeL(typeOfEntry), gUId, alarmMessage); |
|
165 CleanupStack::PushL(entry); |
|
166 if(entry != NULL) |
|
167 { |
|
168 aEntryArray.AppendL(entry); |
|
169 } |
|
170 // The memory pointed to by entry will be destroyed when this |
|
171 // array is destroyed, which is already in the CleanupStack |
|
172 CleanupStack::Pop(entry); |
|
173 |
|
174 // Set alarm |
|
175 SetCalTimesL(entry, now, alarmMinsFromNow); |
|
176 CCalAlarm* calAlarm = CreateCalAlarmL(*sectionName, alarmMinsFromNow); |
|
177 CleanupStack::PushL(calAlarm); |
|
178 |
|
179 entry->SetAlarmL(calAlarm); |
|
180 |
|
181 CleanupStack::PopAndDestroy(calAlarm); |
|
182 } |
|
183 else |
|
184 { |
|
185 IniProblem(); |
|
186 // We still dont return as other sub-sections might be proper. |
|
187 // The test step result will be EFail though |
|
188 } |
|
189 } |
|
190 CleanupStack::PopAndDestroy(sectionName); |
|
191 } |
|
192 |
|
193 /** |
|
194 Creates a set of test entries. Can be used to create a large no. of |
|
195 entries arbitrarily without having to take the pain of mentioning the |
|
196 details of all the entries in the ini file. |
|
197 @param aEntryArray Pointer array to be filled with the entries |
|
198 @param aNumOfEntries No. of entries to be created, so as to loop through the |
|
199 ini sub-sections |
|
200 @internalTechnology |
|
201 @test |
|
202 */ |
|
203 void CTestCreateCalEntriesStep::FillCalEntriesAtWillL(RPointerArray<CCalEntry>& aEntryArray, const TInt& aNumOfEntries) |
|
204 { |
|
205 _LIT(KTestGUId, "testguid%D@test.com"); |
|
206 _LIT(KTestMessage, "testentry%D"); |
|
207 |
|
208 CCalEntry::TType typeOfEntry; |
|
209 TBuf<30> gUId; |
|
210 TBuf<15> alarmMessage; |
|
211 TInt alarmMinsFromNow = 1; |
|
212 |
|
213 // In this case, same calalarm will be used by all the entries |
|
214 CCalAlarm* calAlarm = CreateCalAlarmL(ConfigSection(), alarmMinsFromNow); |
|
215 CleanupStack::PushL(calAlarm); |
|
216 |
|
217 TTime now; |
|
218 now.HomeTime(); |
|
219 |
|
220 for(TInt num = 1; num <= aNumOfEntries; ++num) |
|
221 { |
|
222 // typeofentry will alternate between the 5 types of entries |
|
223 typeOfEntry = static_cast<CCalEntry::TType>(num % CCalEntry::EAnniv); |
|
224 |
|
225 gUId.Format(KTestGUId, num); |
|
226 alarmMessage.Format(KTestMessage, num); |
|
227 |
|
228 CCalEntry* entry = CreateCalEntryL(typeOfEntry, gUId, alarmMessage); |
|
229 CleanupStack::PushL(entry); |
|
230 aEntryArray.AppendL(entry); |
|
231 |
|
232 // The memory pointed to by entry will be destroyed when the |
|
233 // array is destroyed, which is already in the CleanupStack |
|
234 CleanupStack::Pop(entry); |
|
235 |
|
236 SetCalTimesL(entry, now, alarmMinsFromNow); |
|
237 |
|
238 entry->SetAlarmL(calAlarm); |
|
239 |
|
240 } |
|
241 CleanupStack::PopAndDestroy(calAlarm); |
|
242 } |
|
243 |
|
244 /** |
|
245 Reads the specified values from ini |
|
246 @param aSectionName The section name to read from |
|
247 @param aTypeOfEntry Will hold the type of entry (appt/entry/todo/event) |
|
248 @param aGUId Will hold the GUID of the entry |
|
249 @param aAlarmMessage Will hold the message associated with the alarm |
|
250 @param aAlarmMinsFromNow Will hold the minutes from now, when the alarm has to |
|
251 expire |
|
252 @internalTechnology |
|
253 @test |
|
254 */ |
|
255 TBool CTestCreateCalEntriesStep::GetCalEntryDetails(const TDesC& aSectionName, TPtrC& aTypeOfEntry, TPtrC& aGUId, TPtrC& aAlarmMessage, TInt& aAlarmMinsFromNow) |
|
256 { |
|
257 if(ReadStringsFromConfig(aSectionName, &KIniTypeOfEntry(), &aTypeOfEntry, |
|
258 &KIniGUId(), &aGUId, |
|
259 &KIniAlarmMessage(), &aAlarmMessage, NULL) |
|
260 && ReadIntsFromConfig(aSectionName, &KIniAlarmMinsFromNow(), &aAlarmMinsFromNow, NULL)) |
|
261 { |
|
262 return ETrue; |
|
263 } |
|
264 return EFalse; |
|
265 } |
|
266 |
|
267 /** |
|
268 Creates a calendar entry |
|
269 @param aTypeOfEntry The type of entry |
|
270 @param aGUId The GUID of the entry |
|
271 @param aAlarmMessage The Summary of the entry |
|
272 @internalTechnology |
|
273 @test |
|
274 */ |
|
275 CCalEntry* CTestCreateCalEntriesStep::CreateCalEntryL(const CCalEntry::TType& aTypeOfEntry, const TDesC& aGUId, const TDesC& aAlarmMessage) |
|
276 { |
|
277 HBufC8* gUID8 = HBufC8::NewLC(aGUId.Length()); |
|
278 gUID8->Des().Copy(aGUId); |
|
279 CCalEntry* entry = CCalEntry::NewL(aTypeOfEntry, gUID8, CCalEntry::EMethodNone, 0); |
|
280 CleanupStack::Pop(gUID8); |
|
281 CleanupStack::PushL(entry); |
|
282 |
|
283 // The summary will be displayed when alarm is playing. |
|
284 // This summary is considered as the one that uniquely identifies the |
|
285 // entry/alarm for the purpose of this testing. Hence the message of |
|
286 // each entry in the ini file must be unique. |
|
287 entry->SetSummaryL(aAlarmMessage); |
|
288 |
|
289 CleanupStack::Pop(entry); |
|
290 return entry; |
|
291 } |
|
292 |
|
293 /** |
|
294 Sets the start and end time of the entry and the alarm, all relative to the |
|
295 current time, so that the alarms are imminent ones |
|
296 @param aEntry Reference to a pointer to the entry |
|
297 @param aNow The time value, on which the calculation is to be based upon |
|
298 @param aAlarmMinsFromNow The number of minutes after which we desire the alarm |
|
299 to expire. For example if aAlarmMinsFromNow = 1, then start time of the entry will |
|
300 be calculated as 2 minutes from NOW and alarm offset will be 1 minute before |
|
301 the start time |
|
302 @internalTechnology |
|
303 @test |
|
304 */ |
|
305 void CTestCreateCalEntriesStep::SetCalTimesL(CCalEntry*& aEntry, const TTime aNow, const TInt& aAlarmMinsFromNow) |
|
306 { |
|
307 iCalStartTime.SetTimeLocalL(aNow + TTimeIntervalMinutes(2 * aAlarmMinsFromNow)); |
|
308 if(aEntry->EntryTypeL() == CCalEntry::ETodo) |
|
309 { |
|
310 iCalEndTime = iCalStartTime; |
|
311 } |
|
312 else |
|
313 { |
|
314 iCalEndTime.SetTimeLocalL(iCalStartTime.TimeLocalL() + TTimeIntervalHours(1)); |
|
315 } |
|
316 |
|
317 aEntry->SetStartAndEndTimeL(iCalStartTime, iCalEndTime); |
|
318 } |
|
319 |
|
320 /** |
|
321 Creates the cal-alarm |
|
322 @param aSectionName Section name in the ini |
|
323 @param aAlarmMinsFromNow The number of minutes after which we desire the alarm |
|
324 to expire. |
|
325 @return Pointer to the cal-alarm |
|
326 @internalTechnology |
|
327 @test |
|
328 */ |
|
329 CCalAlarm* CTestCreateCalEntriesStep::CreateCalAlarmL(const TDesC& aSectionName, const TInt& aAlarmMinsFromNow) |
|
330 { |
|
331 TPtrC aAlarmSoundName; |
|
332 CCalAlarm* calAlarm = CCalAlarm::NewL(); |
|
333 CleanupStack::PushL(calAlarm); |
|
334 calAlarm->SetTimeOffset(aAlarmMinsFromNow); |
|
335 |
|
336 if(ReadStringsFromConfig(aSectionName, &KIniAlarmSoundName(), &aAlarmSoundName, NULL)) |
|
337 { |
|
338 calAlarm->SetAlarmSoundNameL(aAlarmSoundName); |
|
339 } |
|
340 |
|
341 SetAlarmContentL(aSectionName, calAlarm); |
|
342 |
|
343 CleanupStack::Pop(calAlarm); |
|
344 return calAlarm; |
|
345 } |
|
346 |
|
347 /** |
|
348 Attaches the associated data for the alarm if require ini field exists, |
|
349 else simply returns |
|
350 @param aSectionName Section name in the ini |
|
351 @param aCalAlarm Reference to a pointer to the CalAlarm |
|
352 @internalTechnology |
|
353 @test |
|
354 */ |
|
355 void CTestCreateCalEntriesStep::SetAlarmContentL(const TDesC& aSectionName, CCalAlarm*& aCalAlarm) |
|
356 { |
|
357 TPtrC typeOfAD; |
|
358 if(!ReadStringsFromConfig(aSectionName, &KIniTypeOfAD(), &typeOfAD, NULL)) |
|
359 {// No associated data to be attached |
|
360 return; |
|
361 } |
|
362 else |
|
363 { |
|
364 INFO_PRINTF1(_L("Attaching associated data...")); |
|
365 DoSetAlarmContentL(typeOfAD, aSectionName, aCalAlarm); |
|
366 } |
|
367 } |
|
368 |
|
369 /** |
|
370 Attaches the associated data for the alarm |
|
371 If the type of AD is URL, it attaches the URL value passed from the ini |
|
372 If it is MIME, then it expects a filename from the ini file, from which data will |
|
373 be read into a descriptor and attached with the alarm |
|
374 @param aTypeOfAD Type of associated data, can be either url or mime |
|
375 @param aSectionName Section name in the ini |
|
376 @param aCalAlarm Reference to a pointer to the CalAlarm |
|
377 @internalTechnology |
|
378 @test |
|
379 */ |
|
380 void CTestCreateCalEntriesStep::DoSetAlarmContentL(const TPtrC& aTypeOfAD, const TDesC& aSectionName, CCalAlarm*& aCalAlarm) |
|
381 { |
|
382 TPtrC mimeType; |
|
383 if(!ReadStringsFromConfig(aSectionName, &KIniContentType(), &mimeType, NULL)) |
|
384 { |
|
385 IniProblem(); |
|
386 return; |
|
387 }; |
|
388 // Convert read MIME type from unicode to 8-bit data. |
|
389 HBufC8* mimeType8 = HBufC8::NewL(mimeType.Length()); |
|
390 mimeType8->Des().Copy(mimeType); |
|
391 CleanupStack::PushL(mimeType8); |
|
392 |
|
393 HBufC8* content8 = NULL; |
|
394 CCalContent::TDisposition disposition = CCalContent::EDispositionUnknown; |
|
395 if(aTypeOfAD.Compare(KIniUrl) == 0) |
|
396 { |
|
397 TPtrC url; |
|
398 if(!ReadStringsFromConfig(aSectionName, &KIniUrl(), &url, NULL)) |
|
399 { |
|
400 CleanupStack::PopAndDestroy(mimeType8); |
|
401 IniProblem(); |
|
402 return; |
|
403 }; |
|
404 // Convert read url from unicode to 8-bit data. |
|
405 content8 = HBufC8::NewL(url.Length()); |
|
406 content8->Des().Copy(url); |
|
407 disposition = CCalContent::EDispositionUrl; |
|
408 } |
|
409 else if(aTypeOfAD.Compare(KIniMime) == KErrNone) |
|
410 { |
|
411 TPtrC fileName; |
|
412 if(!ReadStringsFromConfig(aSectionName, &KIniFileName(), &fileName, NULL)) |
|
413 { |
|
414 CleanupStack::PopAndDestroy(mimeType8); |
|
415 IniProblem(); |
|
416 return; |
|
417 }; |
|
418 GetAlarmContentFromFileL(fileName, content8); |
|
419 disposition = CCalContent::EDispositionInline; |
|
420 } |
|
421 CleanupStack::PushL(content8); |
|
422 |
|
423 CCalContent* alarmAction = CCalContent::NewL(); |
|
424 CleanupStack::PushL(alarmAction); |
|
425 alarmAction->SetContentL(content8, mimeType8, disposition); //Takes ownership of content8 & mimeType8 |
|
426 CleanupStack::Pop(alarmAction); |
|
427 CleanupStack::Pop(content8); |
|
428 CleanupStack::Pop(mimeType8); |
|
429 |
|
430 aCalAlarm->SetAlarmAction(alarmAction); // Takes ownership of alarmAction |
|
431 } |
|
432 |
|
433 /** |
|
434 Returns the appropriate enumeration based on the entry type string passed |
|
435 @param aTypeString The entry type string |
|
436 @return The appropriate enumeration |
|
437 @internalTechnology |
|
438 @test |
|
439 */ |
|
440 CCalEntry::TType CTestCreateCalEntriesStep::GetEntryTypeL(const TDesC& aTypeString) |
|
441 { |
|
442 CCalEntry::TType entryType = CCalEntry::EAppt; |
|
443 HBufC* typeBuf = aTypeString.AllocL(); |
|
444 typeBuf->Des().LowerCase(); |
|
445 if(typeBuf->Des().Compare(KTodo) == KErrNone) |
|
446 { |
|
447 entryType = CCalEntry::ETodo; |
|
448 } |
|
449 else if(typeBuf->Des().Compare(KEvent) == KErrNone) |
|
450 { |
|
451 entryType = CCalEntry::EEvent; |
|
452 } |
|
453 else if(typeBuf->Des().Compare(KReminder) == KErrNone) |
|
454 { |
|
455 entryType = CCalEntry::EReminder; |
|
456 } |
|
457 else if(typeBuf->Des().Compare(KAnniversary) == KErrNone) |
|
458 { |
|
459 entryType = CCalEntry::EAnniv; |
|
460 } |
|
461 delete typeBuf; |
|
462 return entryType; |
|
463 } |
|
464 |
|
465 /** |
|
466 Compares the no. of entries we tried to create with that of the actual |
|
467 entries created and prints the result |
|
468 @param aTriedNum The no. of entries we tried to create |
|
469 @param aActualNum The no. of successful entries actually created |
|
470 @internalTechnology |
|
471 @test |
|
472 */ |
|
473 void CTestCreateCalEntriesStep::CompareAndPrintResult(const TInt& aTriedNum, const TInt& aActualNum) |
|
474 { |
|
475 INFO_PRINTF3(_L("Num of entries tried to create = %D, actually created = %D"), aTriedNum, aActualNum); |
|
476 if(aTriedNum != aActualNum) |
|
477 { |
|
478 INFO_PRINTF1(_L("Could not create one or more entries...Failing the test")); |
|
479 SetTestStepResult(EFail); |
|
480 } |
|
481 } |