|
1 // Copyright (c) 1997-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 <e32test.h> |
|
17 #include <f32file.h> |
|
18 #include <s32file.h> |
|
19 #include <cntdb.h> |
|
20 #include <cntitem.h> |
|
21 #include <cntfield.h> |
|
22 #include <cntfldst.h> |
|
23 #include <bautils.h> |
|
24 #include <barsc.h> |
|
25 #include <barsread.h> |
|
26 #include <cntmodel.rsg> |
|
27 #include "T_UTILS.H" |
|
28 |
|
29 CCntTest* CntTest=NULL; |
|
30 LOCAL_D RTest test(_L("T_CARDTM")); |
|
31 |
|
32 const TPtrC KDatabaseFileName=_L("C:T_CARDTM"); |
|
33 const TPtrC KTestName=_L("Test Name No%d"); |
|
34 const TPtrC KTestAddress=_L("Address %d"); |
|
35 const TPtrC KTestLabel = _L("Test label No %d"); |
|
36 const TPtrC KTestEmail = _L("Test@Email.com No %d"); |
|
37 const TPtrC KTestCountry = _L("Test Country No %d"); |
|
38 const TPtrC KTestCompany = _L("Test Company No %d"); |
|
39 const TPtrC KTestFamilyName=_L("Test Family Name No %d"); |
|
40 const TInt KTotalNumRecords=50; |
|
41 |
|
42 |
|
43 #define KCardGivenName _L("Given Name #%d") |
|
44 #define KCardFamilyName _L("Family Name #%d") |
|
45 #define KCardFieldText _L("Card id %d, text field #%d") |
|
46 #define KCardFieldEditedText _L("UPDATED Card id %d, text field #%d") |
|
47 #define KTestData _L("test data") |
|
48 |
|
49 |
|
50 |
|
51 /** |
|
52 * Added to understand what support Contacts provides for user-defined templates... |
|
53 */ |
|
54 /* |
|
55 void TestCardTemplateCreationL(CContactDatabase& aDb) |
|
56 { |
|
57 _LIT(KCardTemplateName,"CContactCardTemplate"); |
|
58 CContactItem* temp = aDb.CreateContactCardTemplateLC(KCardTemplateName); |
|
59 TContactItemId templateId = temp->Id(); |
|
60 TContactItemId templateRefId = temp->TemplateRefId(); |
|
61 __ASSERT_ALWAYS(templateRefId==KNullContactId, User::Invariant()); //templates must not reference other cards |
|
62 __ASSERT_ALWAYS(temp->Type()==KUidContactCardTemplate, User::Invariant()); //correct type? |
|
63 CContactItemFieldSet& fieldSet = temp->CardFields(); |
|
64 TInt fieldSetCount = fieldSet.Count(); |
|
65 TInt labelPosition = fieldSet.Find(KUidContactFieldTemplateLabel); |
|
66 __ASSERT_ALWAYS(labelPosition!=KErrNotFound, User::Invariant()); |
|
67 CContactItemField& labelField = fieldSet[labelPosition]; |
|
68 __ASSERT_ALWAYS(labelField.TextStorage()->Text()==KCardTemplateName, User::Invariant()); |
|
69 |
|
70 |
|
71 //Create a card based on the template |
|
72 CContactItem* card = CContactCard::NewLC(temp); |
|
73 TContactItemId cardTemplateRefId = card->TemplateRefId(); |
|
74 __ASSERT_ALWAYS(cardTemplateRefId==templateId, User::Invariant()); |
|
75 __ASSERT_ALWAYS(card->Type()==KUidContactCard, User::Invariant()); |
|
76 CContactItemFieldSet& cardFieldSet = card->CardFields(); |
|
77 TInt cardFieldSetCount = cardFieldSet.Count(); |
|
78 TInt cardLabelPosition = cardFieldSet.Find(KUidContactFieldTemplateLabel); |
|
79 __ASSERT_ALWAYS(cardLabelPosition==KErrNotFound, User::Invariant()); |
|
80 |
|
81 TContactItemId cardId = aDb.AddNewContactL(*card); |
|
82 CleanupStack::PopAndDestroy(card); |
|
83 |
|
84 CleanupStack::PopAndDestroy(temp); |
|
85 |
|
86 |
|
87 //Modify the template - does the card get the changes? |
|
88 CContactItem* modifiedTemp = aDb.OpenContactLX(templateId); |
|
89 CleanupStack::PushL(modifiedTemp); |
|
90 const TInt fieldCount = modifiedTemp->CardFields().Count(); |
|
91 for(TInt i=fieldCount-1;i>=0;i--) |
|
92 temp->RemoveField(i); |
|
93 |
|
94 CContactItemField* name = CContactItemField::NewLC(KStorageTypeText,KUidContactFieldGivenName); |
|
95 name->SetMapping(KUidContactFieldVCardMapUnusedN); |
|
96 modifiedTemp->AddFieldL(*name); |
|
97 CleanupStack::Pop(name); |
|
98 |
|
99 CContactItemField* number = CContactItemField::NewLC(KStorageTypeText,KUidContactFieldPhoneNumber); |
|
100 number->SetMapping(KUidContactFieldVCardMapTEL); |
|
101 modifiedTemp->AddFieldL(*number); |
|
102 CleanupStack::Pop(number); |
|
103 |
|
104 CContactItemField* slotnum = CContactItemField::NewLC(KStorageTypeText,KUidContactFieldICCSlot); |
|
105 modifiedTemp->AddFieldL(*slotnum); |
|
106 CleanupStack::Pop(slotnum); |
|
107 |
|
108 aDb.CommitContactL(*modifiedTemp); |
|
109 CleanupStack::PopAndDestroy(2); // temp, close template |
|
110 |
|
111 CContactItem* fetchedCard = aDb.ReadContactLC(cardId); |
|
112 TInt cardFieldsCount = fetchedCard->CardFields().Count(); |
|
113 CleanupStack::PopAndDestroy(fetchedCard); |
|
114 |
|
115 |
|
116 //Add a new contact with the modified template |
|
117 CContactItem* fetchedTemplate = aDb.ReadContactLC(templateId); |
|
118 CContactItem* newCard = CContactCard::NewLC(fetchedTemplate); |
|
119 TInt newCardFieldsCount = newCard->CardFields().Count(); |
|
120 |
|
121 TInt pos = newCard->CardFields().Find(KUidContactFieldGivenName,KUidContactFieldVCardMapUnusedN); |
|
122 if (pos!=KErrNotFound) |
|
123 { |
|
124 CContactItemField& field=fieldSet[pos]; |
|
125 field.TextStorage()->SetTextL(_L("Chris")); |
|
126 } |
|
127 TContactItemId id = aDb.AddNewContactL(*newCard); |
|
128 CleanupStack::PopAndDestroy(newCard); |
|
129 |
|
130 CContactItem* it = aDb.ReadContactLC(id); |
|
131 TInt fit = it->CardFields().Count(); |
|
132 CleanupStack::PopAndDestroy(it); |
|
133 |
|
134 |
|
135 |
|
136 //ICC contacts then.. |
|
137 CContactItem* iccCard = CContactICCEntry::NewL(*fetchedTemplate); |
|
138 CleanupStack::PushL(iccCard); |
|
139 TInt iccFieldsCount = iccCard->CardFields().Count(); |
|
140 |
|
141 TInt p = iccCard->CardFields().Find(KUidContactFieldGivenName,KUidContactFieldVCardMapUnusedN); |
|
142 if (p!=KErrNotFound) |
|
143 { |
|
144 CContactItemField& field=fieldSet[p]; |
|
145 field.TextStorage()->SetTextL(_L("Chris")); |
|
146 } |
|
147 TContactItemId iccId = aDb.AddNewContactL(*iccCard); |
|
148 CleanupStack::PopAndDestroy(iccCard); |
|
149 |
|
150 CContactItem* fetchedIcc = aDb.ReadContactLC(iccId); |
|
151 TInt fetchedIccCount = fetchedIcc->CardFields().Count(); |
|
152 CleanupStack::PopAndDestroy(fetchedIcc); |
|
153 |
|
154 |
|
155 |
|
156 |
|
157 CleanupStack::PopAndDestroy(fetchedTemplate); |
|
158 } |
|
159 */ |
|
160 |
|
161 |
|
162 |
|
163 |
|
164 |
|
165 |
|
166 |
|
167 // |
|
168 // |
|
169 // SUPPORT MODULES |
|
170 // |
|
171 // |
|
172 |
|
173 LOCAL_C void SetNameL(CContactItem& aItem,TUid aType,const TDesC& aName) |
|
174 // |
|
175 // Set the contents of a text field, creating the field if required |
|
176 // |
|
177 { |
|
178 CContactItemFieldSet& fieldSet=aItem.CardFields(); |
|
179 const TInt pos=fieldSet.Find(aType); |
|
180 if (pos!=KErrNotFound) |
|
181 fieldSet[pos].TextStorage()->SetTextL(aName); |
|
182 } |
|
183 |
|
184 |
|
185 LOCAL_C void CompareFieldSetsL(CContactItem* aContact, CContactItem* aTemplate) |
|
186 // |
|
187 // check new card fields are the same as the templates |
|
188 // |
|
189 { |
|
190 CContactItemFieldSet& contactFields = aContact->CardFields(); |
|
191 CContactItemFieldSet& templateFields = aTemplate->CardFields(); |
|
192 test(contactFields.Count() == (templateFields.Count() - 1)); |
|
193 //-1 label field |
|
194 for (TInt jj=1;jj < (contactFields.Count()-1);jj++) |
|
195 // need to start at 1 since label field wont exist in contact card |
|
196 { |
|
197 CContactItemField& tempField = (templateFields)[jj]; |
|
198 TBool exists = EFalse; |
|
199 for (TInt counter=0;counter<contactFields.Count();counter++) |
|
200 { |
|
201 CContactItemField& contField = (contactFields)[counter]; |
|
202 if (contField.ContentType()==tempField.ContentType()) |
|
203 { |
|
204 exists=ETrue; |
|
205 break; |
|
206 } |
|
207 } |
|
208 test(exists); |
|
209 } |
|
210 } |
|
211 |
|
212 LOCAL_C void CompareFieldSetsWithTextL(CContactItem* aContact, CContactItem* aTemplate) |
|
213 // |
|
214 // check new card fields are the same as the templates |
|
215 // |
|
216 { |
|
217 CContactItemFieldSet& contactFields = aContact->CardFields(); |
|
218 CContactItemFieldSet& templateFields = aTemplate->CardFields(); |
|
219 test(contactFields.Count() == (templateFields.Count()-1)); |
|
220 //-1 label field |
|
221 for (TInt jj=1;jj < (contactFields.Count()-1);jj++) |
|
222 { |
|
223 CContactItemField& tempField = (templateFields)[jj]; |
|
224 TBool exists = EFalse; |
|
225 for (TInt counter=0;counter<contactFields.Count();counter++) |
|
226 { |
|
227 CContactItemField& contField = (contactFields)[counter]; |
|
228 if (contField.ContentType()==tempField.ContentType()) |
|
229 { |
|
230 exists=ETrue; |
|
231 if (contField.StorageType()==KStorageTypeText) |
|
232 { |
|
233 exists=ETrue; |
|
234 break; |
|
235 } |
|
236 } |
|
237 } |
|
238 test(exists); |
|
239 } |
|
240 } |
|
241 |
|
242 LOCAL_C void PopulateDatabaseL(CContactItem& aTemplate, TInt aNumberToPopulate, TBool aPhoneNumbers, TBool aWithTime) |
|
243 // |
|
244 // Create and populate the database |
|
245 // |
|
246 { |
|
247 TTime before=TTime(); |
|
248 if (aWithTime) |
|
249 before.UniversalTime(); |
|
250 for (TInt counter=0;counter<aNumberToPopulate;counter++) |
|
251 { |
|
252 CContactItem* item=CContactCard::NewLC(&aTemplate); |
|
253 TBuf<16> name; |
|
254 name.Format(KTestName,counter); |
|
255 SetNameL(*item,KUidContactFieldGivenName,name); |
|
256 if (aPhoneNumbers) |
|
257 { |
|
258 TBuf<20> number; |
|
259 switch(counter%3) |
|
260 { |
|
261 case 0: |
|
262 number.Format(_L("0171-%03d %04d"),(counter*9)%1000,((counter+11)*23)%10000); |
|
263 break; |
|
264 case 1: |
|
265 number.Format(_L("%04d:%04d:%04d:%04d"),(counter*123)%10000,(counter*666)%10000,(counter*234)%10000); |
|
266 break; |
|
267 case 2: |
|
268 number.Format(_L("+00%d-%03d %04d"),(counter*123)%100,(counter*13)%1000,((counter+13)*17)%10000); |
|
269 break; |
|
270 } |
|
271 SetNameL(*item,KUidContactFieldPhoneNumber,number); |
|
272 if (!(counter%2)) |
|
273 { |
|
274 number.Format(_L("0181-%03d %04d"),(counter*8)%1000,((counter+11)*22)%10000); |
|
275 SetNameL(*item,KUidContactFieldPhoneNumber,number); |
|
276 number.Format(_L("01734-%06d"),(counter*123456)%1000000); |
|
277 SetNameL(*item,KUidContactFieldPhoneNumber,number); |
|
278 } |
|
279 } |
|
280 TBuf<32> address; |
|
281 address.Format(KTestAddress,counter); |
|
282 SetNameL(*item,KUidContactFieldAddress,address); |
|
283 // |
|
284 TBuf<32> familyName; |
|
285 familyName.Format(KTestFamilyName,counter); |
|
286 SetNameL(*item,KUidContactFieldFamilyName,familyName); |
|
287 // |
|
288 TBuf<32> email; |
|
289 email.Format(KTestEmail,counter); |
|
290 SetNameL(*item,KUidContactFieldEMail,email); |
|
291 // |
|
292 TBuf<32> country; |
|
293 country.Format(KTestCountry,counter); |
|
294 SetNameL(*item,KUidContactFieldCountry,country); |
|
295 // |
|
296 TBuf<32> company; |
|
297 company.Format(KTestCompany,counter); |
|
298 SetNameL(*item,KUidContactFieldCompanyName,company); |
|
299 // |
|
300 CContactItemFieldSet& itemFields = item->CardFields(); |
|
301 for (TInt counter2=0;counter2<itemFields.Count();counter2++) |
|
302 { |
|
303 if (!itemFields[counter2].Storage()->IsFull() && itemFields[counter2].StorageType()==KStorageTypeText) |
|
304 itemFields[counter2].TextStorage()->SetTextL(KTestData); |
|
305 } |
|
306 CntTest->Db()->AddNewContactL(*item); //templ |
|
307 CleanupStack::PopAndDestroy(); // item |
|
308 // |
|
309 if (counter%100==0 && aWithTime) |
|
310 test.Printf(_L(".")); // Just to show some life |
|
311 |
|
312 } |
|
313 CntTest->Db()->SetDateFormatTextL(_L("%E%D%X%N%Y %1 %2 %3")); |
|
314 CntTest->Db()->CompactL(); |
|
315 if (aWithTime) |
|
316 { |
|
317 TTime after; |
|
318 after.UniversalTime(); |
|
319 TTimeIntervalSeconds secondsTaken; |
|
320 after.SecondsFrom(before,secondsTaken); |
|
321 test.Printf(_L(" TIME: %d Secs"),secondsTaken.Int()); |
|
322 test.Printf(_L("\n")); |
|
323 } |
|
324 } |
|
325 |
|
326 // |
|
327 // |
|
328 // TEST MODULES |
|
329 // |
|
330 // |
|
331 |
|
332 |
|
333 LOCAL_C void CreateCardTemplateL() |
|
334 { |
|
335 test.Next(_L("Create Card Template")); |
|
336 |
|
337 //copy 'golden' template |
|
338 CContactItem* tempTemplate = CntTest->Db()->CreateContactCardTemplateL(_L("label1")); |
|
339 CleanupStack::PushL(tempTemplate); |
|
340 |
|
341 // create template with more fields than the golden template |
|
342 CContactItemField* field1=CContactItemField::NewLC(KStorageTypeText,TUid::Uid(1)); |
|
343 field1->SetMapping(KUidContactFieldVCardMapUnusedN); |
|
344 tempTemplate->AddFieldL(*field1); |
|
345 CContactItemField* field2=CContactItemField::NewLC(KStorageTypeText,TUid::Uid(2)); |
|
346 field2->SetMapping(KUidContactFieldVCardMapUnusedN); |
|
347 tempTemplate->AddFieldL(*field2); |
|
348 CleanupStack::Pop(2); // field1,2 |
|
349 CContactItem* secondTempTemplate = CntTest->Db()->CreateContactCardTemplateL(tempTemplate,_L("TEMPLATE2")); |
|
350 CleanupStack::PushL(secondTempTemplate); |
|
351 |
|
352 // create template with less fields than the golden template |
|
353 CContactItemFieldSet& tempFields = tempTemplate->CardFields(); |
|
354 TInt fieldCount=tempFields.Count(); |
|
355 TInt index = fieldCount-1; |
|
356 TInt counter = 0; |
|
357 |
|
358 while(counter < 12) |
|
359 { |
|
360 if(!tempFields[index].IsHidden()) |
|
361 { |
|
362 //delete visible fields only as the tests only test againest the visible fields. |
|
363 tempTemplate->RemoveField(index); |
|
364 ++counter; |
|
365 } |
|
366 --index; |
|
367 } |
|
368 |
|
369 CContactItem* thirdTempTemplate = CntTest->Db()->CreateContactCardTemplateL(tempTemplate,_L("TEMPLATE3")); |
|
370 CleanupStack::PushL(thirdTempTemplate); |
|
371 |
|
372 // create template with just the label field |
|
373 tempFields.Reset(); |
|
374 CContactItem* fourthTempTemplate = CntTest->Db()->CreateContactCardTemplateL(tempTemplate,_L("TEMPLATE4")); |
|
375 |
|
376 CleanupStack::PopAndDestroy(3); // thirdTempTemplate secondTempTemplate tempTemplate |
|
377 delete fourthTempTemplate; |
|
378 } |
|
379 |
|
380 |
|
381 LOCAL_C void CheckCardTemplateListPersistL() |
|
382 { |
|
383 test.Next(_L("Check Card Template LIST Persistance")); |
|
384 |
|
385 |
|
386 // get golden template |
|
387 TContactItemId goldenTemplateId = CntTest->Db()->TemplateId(); |
|
388 CContactItem* goldenTemplate = CntTest->Db()->ReadContactLC(goldenTemplateId); |
|
389 CContactItemFieldSet& goldenTemplateFields = goldenTemplate->CardFields(); |
|
390 TInt originalCount = goldenTemplateFields.Count(); |
|
391 CleanupStack::PopAndDestroy(goldenTemplate); |
|
392 |
|
393 CContactIdArray* tempIdList = CntTest->Db()->GetCardTemplateIdListL(); |
|
394 CleanupStack::PushL(tempIdList); |
|
395 TInt templateCount = tempIdList->Count(); |
|
396 test(templateCount == 4); |
|
397 |
|
398 // Check Template definitions created by CreateCardTemplateL() |
|
399 { |
|
400 CContactItem* goldCopyTemp = CntTest->Db()->ReadContactLC((*tempIdList)[0]); |
|
401 CContactItemFieldSet& goldenCopyFields = goldCopyTemp->CardFields(); |
|
402 // original + 1 (+ template label field) |
|
403 test(goldenCopyFields.Count() == originalCount + 1); |
|
404 CleanupStack::PopAndDestroy(goldCopyTemp); |
|
405 } |
|
406 |
|
407 { |
|
408 CContactItem* largeCopyTemp = CntTest->Db()->ReadContactLC((*tempIdList)[1]); |
|
409 CContactItemFieldSet& largeCopyFields = largeCopyTemp->CardFields(); |
|
410 // original + 3 (+ template label field +2 UIDs) |
|
411 test(largeCopyFields.Count() == originalCount + 3); |
|
412 CleanupStack::PopAndDestroy(largeCopyTemp); |
|
413 } |
|
414 |
|
415 { |
|
416 CContactItem* smallCopyTemp = CntTest->Db()->ReadContactLC((*tempIdList)[2]); |
|
417 CContactItemFieldSet& smallCopyFields = smallCopyTemp->CardFields(); |
|
418 // (original + template label field + 2 UIDs - 12 fields from end of template) == originalCount - 9 |
|
419 test(smallCopyFields.Count() == originalCount - 9); |
|
420 CleanupStack::PopAndDestroy(smallCopyTemp); |
|
421 } |
|
422 |
|
423 { |
|
424 CContactItem* singleFieldCopyTemp = CntTest->Db()->ReadContactLC((*tempIdList)[3]); |
|
425 CContactItemFieldSet& singleCopyFields = singleFieldCopyTemp->CardFields(); |
|
426 // template just has template label |
|
427 test(singleCopyFields.Count() == 1); |
|
428 CleanupStack::PopAndDestroy(singleFieldCopyTemp); |
|
429 } |
|
430 |
|
431 CleanupStack::PopAndDestroy(tempIdList); |
|
432 } |
|
433 |
|
434 LOCAL_C void CreateEmptyContactsFromTemplateL() |
|
435 // |
|
436 // create empty contact cards using all templates |
|
437 // |
|
438 { |
|
439 test.Next(_L("Create Empty Contacts using Templates")); |
|
440 |
|
441 // |
|
442 CContactIdArray* tempIdList = CntTest->Db()->GetCardTemplateIdListL(); |
|
443 CleanupStack::PushL(tempIdList); |
|
444 TInt templateCount = tempIdList->Count(); |
|
445 for (TInt counter=0; counter<templateCount; counter++) |
|
446 { |
|
447 TContactItemId templateId = (*tempIdList)[counter]; |
|
448 CContactItem* tempTemplate = CntTest->Db()->OpenContactL(templateId); |
|
449 // |
|
450 CleanupStack::PushL(tempTemplate); |
|
451 for(TInt jj=0; jj<5; jj++) |
|
452 { |
|
453 CContactItem* newContact = CContactCard::NewL(tempTemplate); |
|
454 CleanupStack::PushL(newContact); |
|
455 CntTest->Db()->AddNewContactL(*newContact); |
|
456 CleanupStack::PopAndDestroy(); // newContact |
|
457 } |
|
458 CleanupStack::PopAndDestroy(); // tempTemplate |
|
459 CntTest->Db()->CloseContactL(templateId); |
|
460 } |
|
461 CleanupStack::PopAndDestroy(); // tempIdList |
|
462 } |
|
463 |
|
464 |
|
465 LOCAL_C void CheckEmptyContactsFromTemplatePersistL() |
|
466 // |
|
467 // check empty card template matching persist |
|
468 // |
|
469 { |
|
470 test.Next(_L("Check Empty Contacts Match Templates & Persist")); |
|
471 |
|
472 |
|
473 CContactIdArray* tempIdList = CntTest->Db()->GetCardTemplateIdListL(); |
|
474 CleanupStack::PushL(tempIdList); |
|
475 TInt templateCount = tempIdList->Count(); |
|
476 TInt jj=5; |
|
477 for (TInt counter=0; counter<templateCount; counter++) |
|
478 { |
|
479 TContactItemId templateId = (*tempIdList)[counter]; |
|
480 CContactItem* tempTemplate = CntTest->Db()->OpenContactL(templateId); |
|
481 CleanupStack::PushL(tempTemplate); |
|
482 |
|
483 CContactItem* newContact = CntTest->Db()->OpenContactL(jj); |
|
484 CleanupStack::PushL(newContact); |
|
485 CompareFieldSetsL(newContact, tempTemplate); |
|
486 CntTest->Db()->CloseContactL(tempTemplate->Id()); |
|
487 CntTest->Db()->CloseContactL(newContact->Id()); |
|
488 CleanupStack::PopAndDestroy(2); // newContact tempTemplate |
|
489 jj+=5; |
|
490 } |
|
491 CleanupStack::PopAndDestroy(); // tempIdList |
|
492 } |
|
493 |
|
494 LOCAL_C void CreateFullContactsFromTemplateL() |
|
495 // |
|
496 // create FULL contact cards using all templates |
|
497 // |
|
498 { |
|
499 test.Next(_L("Create FULL Contacts using Templates")); |
|
500 // |
|
501 CContactIdArray* tempIdList = CntTest->Db()->GetCardTemplateIdListL(); |
|
502 CleanupStack::PushL(tempIdList); |
|
503 TInt templateCount = tempIdList->Count(); |
|
504 for (TInt counter=0; counter<templateCount; counter++) |
|
505 { |
|
506 TContactItemId templateId = (*tempIdList)[counter]; |
|
507 CContactItem* tempTemplate = CntTest->Db()->ReadContactL(templateId); |
|
508 // |
|
509 CleanupStack::PushL(tempTemplate); |
|
510 PopulateDatabaseL(*tempTemplate, 5, ETrue, EFalse); |
|
511 CleanupStack::PopAndDestroy(); // tempTemplate |
|
512 } |
|
513 CleanupStack::PopAndDestroy(); // tempIdList |
|
514 } |
|
515 |
|
516 |
|
517 LOCAL_C void CheckFullContactsFromTemplatePersistL() |
|
518 // |
|
519 // check FULL card template matching persist |
|
520 // |
|
521 { |
|
522 test.Next(_L("Check FULL Contacts Match Templates & Persist")); |
|
523 |
|
524 |
|
525 CContactIdArray* tempIdList = CntTest->Db()->GetCardTemplateIdListL(); |
|
526 CleanupStack::PushL(tempIdList); |
|
527 TInt templateCount = tempIdList->Count(); |
|
528 TInt jj=25; |
|
529 for (TInt counter=0; counter<templateCount; counter++) |
|
530 { |
|
531 TContactItemId templateId = (*tempIdList)[counter]; |
|
532 CContactItem* tempTemplate = CntTest->Db()->ReadContactL(templateId); |
|
533 CleanupStack::PushL(tempTemplate); |
|
534 CContactItem* newContact = CntTest->Db()->ReadContactL(jj); |
|
535 CleanupStack::PushL(newContact); |
|
536 |
|
537 CompareFieldSetsWithTextL(newContact, tempTemplate); |
|
538 CleanupStack::PopAndDestroy(2); // newContact tempTemplate |
|
539 jj+=5; |
|
540 } |
|
541 CleanupStack::PopAndDestroy(); // tempIdList |
|
542 } |
|
543 |
|
544 |
|
545 LOCAL_C void ModifyAddTemplateL() |
|
546 // |
|
547 // modify / add fields to templates |
|
548 // |
|
549 { |
|
550 test.Next(_L("Modify / add fields to templates")); |
|
551 // |
|
552 CContactIdArray* tempIdList = CntTest->Db()->GetCardTemplateIdListL(); |
|
553 CleanupStack::PushL(tempIdList); |
|
554 TInt templateCount = tempIdList->Count(); |
|
555 for (TInt counter=0; counter<templateCount; counter++) |
|
556 { |
|
557 TContactItemId templateId = (*tempIdList)[counter]; |
|
558 CContactItem* tempTemplate = CntTest->Db()->OpenContactL(templateId); |
|
559 CleanupStack::PushL(tempTemplate); |
|
560 // |
|
561 for(TInt jj=0; jj<3; jj++) |
|
562 { |
|
563 CContactItemField* field=CContactItemField::NewLC(KStorageTypeText,KUidContactFieldPrefixName); |
|
564 field->SetMapping(KUidContactFieldVCardMapUnusedN); |
|
565 tempTemplate->AddFieldL(*field); |
|
566 CleanupStack::Pop(); // field |
|
567 } |
|
568 CntTest->Db()->CommitContactL(*tempTemplate); |
|
569 CntTest->Db()->CloseContactL(templateId); |
|
570 // |
|
571 CleanupStack::PopAndDestroy(); // tempTemplate |
|
572 } |
|
573 CleanupStack::PopAndDestroy(); // tempIdList |
|
574 } |
|
575 |
|
576 |
|
577 LOCAL_C void CheckModifyAddContactsFromTemplatePersistL() |
|
578 // |
|
579 // check modified card template match cards persist |
|
580 // |
|
581 { |
|
582 test.Next(_L("Check contacts Match modified Templates & Persist")); |
|
583 // |
|
584 CContactIdArray* tempIdList = CntTest->Db()->GetCardTemplateIdListL(); |
|
585 CleanupStack::PushL(tempIdList); |
|
586 TInt templateCount = tempIdList->Count(); |
|
587 TInt jj=25; |
|
588 for (TInt counter=0; counter<templateCount; counter++) |
|
589 { |
|
590 TContactItemId templateId = (*tempIdList)[counter]; |
|
591 CContactItem* tempTemplate = CntTest->Db()->ReadContactL(templateId); |
|
592 CleanupStack::PushL(tempTemplate); |
|
593 |
|
594 CContactItem* newContact = CntTest->Db()->ReadContactL(jj); |
|
595 CleanupStack::PushL(newContact); |
|
596 CompareFieldSetsL(newContact, tempTemplate); |
|
597 CleanupStack::PopAndDestroy(2); // newContact tempTemplate |
|
598 jj+=5; |
|
599 } |
|
600 CleanupStack::PopAndDestroy(); // tempIdList |
|
601 } |
|
602 |
|
603 |
|
604 LOCAL_C void ModifyRemoveTemplateL() |
|
605 // |
|
606 // modify / remove fields to templates |
|
607 // |
|
608 { |
|
609 test.Next(_L("Modify / REMOVE fields to templates")); |
|
610 // |
|
611 CContactIdArray* tempIdList = CntTest->Db()->GetCardTemplateIdListL(); |
|
612 CleanupStack::PushL(tempIdList); |
|
613 TInt templateCount = tempIdList->Count(); |
|
614 for (TInt counter=0; counter<templateCount-1; counter++) |
|
615 { |
|
616 TContactItemId templateId = (*tempIdList)[counter]; |
|
617 CContactItem* tempTemplate = CntTest->Db()->OpenContactL(templateId); |
|
618 CContactItemFieldSet& tempFieldSet = tempTemplate->CardFields(); |
|
619 TInt fieldCount = tempFieldSet.Count(); |
|
620 CleanupStack::PushL(tempTemplate); |
|
621 // |
|
622 for(TInt jj=1; jj<15; jj++) |
|
623 { |
|
624 tempTemplate->RemoveField(fieldCount-jj); |
|
625 } |
|
626 CntTest->Db()->CommitContactL(*tempTemplate); |
|
627 CntTest->Db()->CloseContactL(templateId); |
|
628 // |
|
629 CleanupStack::PopAndDestroy(); // tempTemplate |
|
630 } |
|
631 CleanupStack::PopAndDestroy(); // tempIdList |
|
632 } |
|
633 |
|
634 LOCAL_C void CheckModifyRemoveContactsFromTemplatePersistL() |
|
635 // |
|
636 // check modified REMOVE card template match cards persist |
|
637 // |
|
638 { |
|
639 test.Next(_L("Check contacts Match modified Templates & Persist")); |
|
640 // |
|
641 CContactIdArray* tempIdList = CntTest->Db()->GetCardTemplateIdListL(); |
|
642 CleanupStack::PushL(tempIdList); |
|
643 TInt templateCount = tempIdList->Count(); |
|
644 TInt jj=5; |
|
645 // CHECK EMPTY CONTACTS FIRST |
|
646 for (TInt counter=0; counter<templateCount-1; counter++) |
|
647 { |
|
648 TContactItemId templateId = (*tempIdList)[counter]; |
|
649 CContactItem* tempTemplate = CntTest->Db()->ReadContactL(templateId); |
|
650 CleanupStack::PushL(tempTemplate); |
|
651 |
|
652 CContactItem* newContact = CntTest->Db()->ReadContactL(jj); |
|
653 CleanupStack::PushL(newContact); |
|
654 CompareFieldSetsL(newContact, tempTemplate); |
|
655 CleanupStack::PopAndDestroy(2); // newContact tempTemplate |
|
656 jj+=5; |
|
657 } |
|
658 jj=25; |
|
659 // check full contacts fields persists |
|
660 for (TInt counter2=0; counter2<templateCount-1; counter2++) |
|
661 { |
|
662 TContactItemId templateId = (*tempIdList)[counter2]; |
|
663 CContactItem* tempTemplate = CntTest->Db()->ReadContactL(templateId); |
|
664 CleanupStack::PushL(tempTemplate); |
|
665 |
|
666 CContactItem* newContact = CntTest->Db()->ReadContactL(jj); |
|
667 CleanupStack::PushL(newContact); |
|
668 // |
|
669 CContactItemFieldSet& templ = tempTemplate->CardFields(); |
|
670 CContactItemFieldSet& item = newContact->CardFields(); |
|
671 test(item.Count()>templ.Count()); |
|
672 CleanupStack::PopAndDestroy(2); // newContact tempTemplate |
|
673 jj+=5; |
|
674 } |
|
675 CleanupStack::PopAndDestroy(); // tempIdList |
|
676 } |
|
677 |
|
678 |
|
679 LOCAL_C void SetTemplateLabelL() |
|
680 // |
|
681 // Set template fields label |
|
682 // |
|
683 { |
|
684 test.Next(_L("Modify field labels in templates")); |
|
685 // |
|
686 CContactIdArray* tempIdList = CntTest->Db()->GetCardTemplateIdListL(); |
|
687 CleanupStack::PushL(tempIdList); |
|
688 TInt templateCount = tempIdList->Count(); |
|
689 for (TInt counter=0; counter<templateCount; counter++) |
|
690 { |
|
691 TContactItemId templateId = (*tempIdList)[counter]; |
|
692 CContactItem* tempTemplate = CntTest->Db()->OpenContactL(templateId); |
|
693 CContactItemFieldSet& tempFieldSet = tempTemplate->CardFields(); |
|
694 TInt fieldCount = tempFieldSet.Count(); |
|
695 CleanupStack::PushL(tempTemplate); |
|
696 // |
|
697 for(TInt jj=0; jj<fieldCount; jj++) |
|
698 { |
|
699 (tempFieldSet)[jj].SetLabelL(KTestLabel); |
|
700 } |
|
701 CntTest->Db()->CommitContactL(*tempTemplate); |
|
702 CntTest->Db()->CloseContactL(templateId); |
|
703 // |
|
704 CleanupStack::PopAndDestroy(); // tempTemplate |
|
705 } |
|
706 CleanupStack::PopAndDestroy(); // tempIdList |
|
707 } |
|
708 |
|
709 |
|
710 LOCAL_C void CheckFieldLabelsPersistL() |
|
711 // |
|
712 // check modified field labels persist |
|
713 // |
|
714 { |
|
715 test.Next(_L("Check modified field labels Persist")); |
|
716 // |
|
717 CContactIdArray* tempIdList = CntTest->Db()->GetCardTemplateIdListL(); |
|
718 CleanupStack::PushL(tempIdList); |
|
719 TInt templateCount = tempIdList->Count(); |
|
720 for (TInt counter=0; counter<templateCount; counter++) |
|
721 { |
|
722 TContactItemId templateId = (*tempIdList)[counter]; |
|
723 CContactItem* tempTemplate = CntTest->Db()->OpenContactL(templateId); |
|
724 CleanupStack::PushL(tempTemplate); |
|
725 CContactItemFieldSet& tempFieldSet = tempTemplate->CardFields(); |
|
726 TInt fieldCount = tempFieldSet.Count(); |
|
727 // |
|
728 for(TInt jj=0; jj<fieldCount; jj++) |
|
729 { |
|
730 test((tempFieldSet)[jj].Label() == KTestLabel); |
|
731 } |
|
732 CleanupStack::PopAndDestroy(); // tempTemplate |
|
733 CntTest->Db()->CloseContactL(templateId); |
|
734 } |
|
735 CleanupStack::PopAndDestroy(); // tempIdList |
|
736 // !!!!!!! ADD CHECKING FOR CONTACT AS WELL. |
|
737 } |
|
738 |
|
739 |
|
740 LOCAL_C void DeleteCardTemplateL() |
|
741 // |
|
742 // Delete Card Template |
|
743 // |
|
744 { |
|
745 test.Next(_L("Delete Card Template")); |
|
746 // |
|
747 CContactIdArray* tempIdList = CntTest->Db()->GetCardTemplateIdListL(); |
|
748 CleanupStack::PushL(tempIdList); |
|
749 test(tempIdList->Count() > 0); |
|
750 TContactItemId templateId = (*tempIdList)[1]; |
|
751 |
|
752 CntTest->Db()->DeleteContactL(templateId); |
|
753 CleanupStack::PopAndDestroy(); // tempIdList |
|
754 } |
|
755 |
|
756 |
|
757 LOCAL_C void CheckDeleteCardTemplateL() |
|
758 // |
|
759 // Check Delete Card Template |
|
760 // |
|
761 { |
|
762 test.Next(_L("Check Delete Card Template")); |
|
763 // |
|
764 CContactIdArray* tempIdList = CntTest->Db()->GetCardTemplateIdListL(); |
|
765 CleanupStack::PushL(tempIdList); |
|
766 TInt templateCount = tempIdList->Count(); |
|
767 test(templateCount==3); |
|
768 // |
|
769 CContactItem* tempTemplate = CntTest->Db()->ReadContactL(11); |
|
770 CleanupStack::PushL(tempTemplate); |
|
771 // |
|
772 CleanupStack::PopAndDestroy(2); // tempTemplate tempIdList |
|
773 } |
|
774 |
|
775 |
|
776 LOCAL_C void CheckLargePopulatedTemplate() |
|
777 // |
|
778 // create MANY FULL contact cards using all templates |
|
779 // |
|
780 { |
|
781 test.Next(_L("Create MANY FULL Contacts using Templates")); |
|
782 // |
|
783 CContactIdArray* tempIdList = CntTest->Db()->GetCardTemplateIdListL(); |
|
784 CleanupStack::PushL(tempIdList); |
|
785 TInt templateCount = tempIdList->Count(); |
|
786 for (TInt counter=0; counter<templateCount; counter++) |
|
787 { |
|
788 TContactItemId templateId = (*tempIdList)[counter]; |
|
789 CContactItem* tempTemplate = CntTest->Db()->ReadContactL(templateId); |
|
790 CleanupStack::PushL(tempTemplate); |
|
791 // |
|
792 PopulateDatabaseL(*tempTemplate, KTotalNumRecords, ETrue, ETrue); |
|
793 //PopulateDatabaseL(*tempTemplate, 1000, ETrue, ETrue); |
|
794 CleanupStack::PopAndDestroy(); // tempTemplate |
|
795 } |
|
796 CleanupStack::PopAndDestroy(); // tempIdList |
|
797 } |
|
798 |
|
799 LOCAL_C void ModifyCardBasedOnTemplate() |
|
800 // |
|
801 // modify FULL contact cards based on template and check persist |
|
802 // |
|
803 { |
|
804 test.Next(_L("modify Contact Card & check persist")); |
|
805 |
|
806 |
|
807 CContactItemViewDef* itemDef=CContactItemViewDef::NewLC(CContactItemViewDef::EIncludeFields,CContactItemViewDef::EIncludeHiddenFields); |
|
808 itemDef->AddL(KUidContactFieldMatchAll); |
|
809 |
|
810 CContactIdArray* tempIdList = CntTest->Db()->GetCardTemplateIdListL(); |
|
811 CleanupStack::PushL(tempIdList); |
|
812 TContactItemId templateId = (*tempIdList)[0]; // first in the list |
|
813 CContactItem* tempTemplate = CntTest->Db()->ReadContactLC(templateId,*itemDef); |
|
814 |
|
815 CContactItem* newContactItem = CContactCard::NewLC(tempTemplate); |
|
816 CContactItemFieldSet& fieldSet = newContactItem->CardFields(); |
|
817 // |
|
818 // fill up the contact |
|
819 TInt counter=0; |
|
820 for (;counter<fieldSet.Count();counter++) |
|
821 { |
|
822 if (!fieldSet[counter].Storage()->IsFull() && fieldSet[counter].StorageType()==KStorageTypeText) |
|
823 fieldSet[counter].TextStorage()->SetTextL(KTestData); |
|
824 } |
|
825 |
|
826 // add the new contact to the db |
|
827 TContactItemId newItemID = CntTest->Db()->AddNewContactL(*newContactItem); |
|
828 // |
|
829 CntTest->CloseDatabase(); |
|
830 CntTest->OpenDatabaseL(); |
|
831 // |
|
832 CContactItem* newContactItem2 = CntTest->Db()->OpenContactLX(newItemID,*itemDef); // gets the new contact from the db |
|
833 CleanupStack::PushL(newContactItem2); |
|
834 CContactItemFieldSet& fieldSet2 = newContactItem2->CardFields(); |
|
835 // |
|
836 // check the same |
|
837 for (counter=0;counter<fieldSet2.Count();counter++) |
|
838 { |
|
839 if (fieldSet2[counter].StorageType()==KStorageTypeText) |
|
840 { |
|
841 TPtrC fieldText = fieldSet[counter].TextStorage()->Text(); |
|
842 TPtrC fieldText2 = fieldSet2[counter].TextStorage()->Text(); |
|
843 test.Printf(_L("\n Field %d = %S ... %S "),counter,&fieldText,&fieldText2); // Show what text is in field 3 |
|
844 User::After(20000); |
|
845 //test.Getch(); |
|
846 } |
|
847 } |
|
848 |
|
849 test.Printf(_L("\n")); |
|
850 test.Next(_L("Remove Field Data and Check Persist")); |
|
851 |
|
852 |
|
853 fieldSet2[4].TextStorage()->SetStandardTextL(_L("")); |
|
854 CntTest->Db()->CommitContactL(*newContactItem2); // commit the changes |
|
855 |
|
856 CContactItem* newContactItem3 = CntTest->Db()->OpenContactLX(newItemID,*itemDef); // gets the new contact from the db |
|
857 CleanupStack::PushL(newContactItem3); |
|
858 CContactItemFieldSet& fieldSet3 = newContactItem3->CardFields(); |
|
859 // |
|
860 // check the same |
|
861 for (counter=0;counter<fieldSet3.Count();counter++) |
|
862 { |
|
863 if (fieldSet3[counter].StorageType()==KStorageTypeText) |
|
864 { |
|
865 TPtrC fieldText = fieldSet[counter].TextStorage()->Text(); |
|
866 TPtrC fieldText2 = fieldSet2[counter].TextStorage()->Text(); |
|
867 TPtrC fieldText3 = fieldSet3[counter].TextStorage()->Text(); |
|
868 test.Printf(_L("\n Field %d = %S ... %S ... %S "),counter,&fieldText,&fieldText2,&fieldText3); // Show what text is in field 3 |
|
869 User::After(20000); |
|
870 //test.Getch(); |
|
871 } |
|
872 } |
|
873 fieldSet3[5].TextStorage()->SetStandardTextL(_L("")); |
|
874 CntTest->Db()->CommitContactL(*newContactItem3); // commit the changes |
|
875 |
|
876 CContactItem* newContactItem4 = CntTest->Db()->OpenContactLX(newItemID,*itemDef); // gets the new contact from the db |
|
877 CleanupStack::PushL(newContactItem4); |
|
878 CContactItemFieldSet& fieldSet4 = newContactItem4->CardFields(); |
|
879 // |
|
880 // check the same |
|
881 for (counter=0;counter<fieldSet4.Count();counter++) |
|
882 { |
|
883 if (fieldSet4[counter].StorageType()==KStorageTypeText) |
|
884 { |
|
885 TPtrC fieldText = fieldSet[counter].TextStorage()->Text(); |
|
886 TPtrC fieldText2 = fieldSet2[counter].TextStorage()->Text(); |
|
887 TPtrC fieldText3 = fieldSet3[counter].TextStorage()->Text(); |
|
888 TPtrC fieldText4 = fieldSet4[counter].TextStorage()->Text(); |
|
889 test.Printf(_L("\n Field %d = %S ... %S ... %S ... %S "),counter,&fieldText,&fieldText2,&fieldText3,&fieldText4); // Show what text is in field 3 |
|
890 User::After(20000); |
|
891 //st.Getch(); |
|
892 } |
|
893 } |
|
894 // |
|
895 CntTest->Db()->CloseContactL(newContactItem4->Id()); // commit the changes |
|
896 CleanupStack::PopAndDestroy(10); // tempIdList tempTemplate openlx newContactItem2, itemDef |
|
897 } |
|
898 |
|
899 |
|
900 LOCAL_C void DeleteTemplateCheckPersist() |
|
901 { |
|
902 test.Next(_L("Delete Template Check Persist")); |
|
903 // |
|
904 CContactIdArray* tempIdList = CntTest->Db()->GetCardTemplateIdListL(); |
|
905 CleanupStack::PushL(tempIdList); |
|
906 TInt templateCount = tempIdList->Count(); |
|
907 for (TInt counter=0; counter<templateCount; counter++) |
|
908 { |
|
909 CntTest->Db()->DeleteContactL((*tempIdList)[counter]); |
|
910 } |
|
911 // |
|
912 for (TInt counter2=KTotalNumRecords-10; counter2<(KTotalNumRecords*templateCount); counter2+=KTotalNumRecords) |
|
913 { |
|
914 CContactItem* contact = CntTest->Db()->ReadContactL(counter2); |
|
915 delete contact; |
|
916 } |
|
917 |
|
918 CContactIdArray* tempIdList2 = CntTest->Db()->GetCardTemplateIdListL(); |
|
919 TInt templateCount2 = tempIdList2->Count(); |
|
920 test(templateCount2==0); |
|
921 delete tempIdList2; |
|
922 CleanupStack::PopAndDestroy(); // tempIdList |
|
923 } |
|
924 |
|
925 |
|
926 LOCAL_C void CheckManyTemplates() |
|
927 // |
|
928 // create MANY templates |
|
929 // |
|
930 { |
|
931 test.Next(_L("Create MANY Templates")); |
|
932 |
|
933 // |
|
934 CntTest->CloseDatabase(); |
|
935 CntTest->DeleteDatabaseL(); |
|
936 CntTest->CreateDatabaseL(); |
|
937 |
|
938 TTime before; |
|
939 before.UniversalTime(); |
|
940 for (TInt counter=0; counter<KTotalNumRecords; counter++) |
|
941 { |
|
942 CContactItem* tempTemplate = CntTest->Db()->CreateContactCardTemplateL(_L("TEMPLATE")); |
|
943 delete tempTemplate; |
|
944 if (counter%100==0) |
|
945 test.Printf(_L(".")); // Just to show some life |
|
946 } |
|
947 test(CntTest->Db()->TemplateCount()==KTotalNumRecords); |
|
948 TTime after; |
|
949 after.UniversalTime(); |
|
950 TTimeIntervalSeconds secondsTaken; |
|
951 after.SecondsFrom(before,secondsTaken); |
|
952 test.Printf(_L(" TIME: %d Secs"),secondsTaken.Int()); |
|
953 test.Printf(_L("\n")); |
|
954 } |
|
955 |
|
956 |
|
957 LOCAL_C void TestModifyCardAttribs() |
|
958 // |
|
959 // set attribs and check persist |
|
960 // |
|
961 { |
|
962 test.Next(_L("set attribs check persist")); |
|
963 // |
|
964 // multiple template created card |
|
965 CContactIdArray* tempIdList = CntTest->Db()->GetCardTemplateIdListL(); |
|
966 TContactItemId templateId = (*tempIdList)[0]; // first in the list |
|
967 delete tempIdList; |
|
968 CContactItem* tempTemplate = CntTest->Db()->OpenContactLX(templateId); |
|
969 // |
|
970 // golden template created card |
|
971 |
|
972 // CContactItem* tempTemplate = CntTest->Db()->OpenContactLX(0); |
|
973 // |
|
974 CleanupStack::PushL(tempTemplate); |
|
975 CContactItem* newContactItem = CContactCard::NewLC(tempTemplate); |
|
976 CntTest->Db()->CloseContactL(tempTemplate->Id()); |
|
977 CContactItemFieldSet& fieldSet = newContactItem->CardFields(); |
|
978 // |
|
979 // fill up the contact |
|
980 TInt counter=0; |
|
981 for (;counter<fieldSet.Count();counter++) |
|
982 { |
|
983 if (!fieldSet[counter].Storage()->IsFull() && fieldSet[counter].StorageType()==KStorageTypeText) |
|
984 fieldSet[counter].TextStorage()->SetTextL(KTestData); |
|
985 } |
|
986 // add the new contact to the db |
|
987 TContactItemId newItemID = CntTest->Db()->AddNewContactL(*newContactItem); |
|
988 // |
|
989 CntTest->CloseDatabase(); |
|
990 CntTest->OpenDatabaseL(); |
|
991 |
|
992 CContactItem* newContactItem2 = CntTest->Db()->OpenContactLX(newItemID); |
|
993 CleanupStack::PushL(newContactItem2); |
|
994 CContactItemFieldSet& fieldSet2 = newContactItem2->CardFields(); |
|
995 // |
|
996 for (counter=0;counter<fieldSet2.Count();counter++) |
|
997 { |
|
998 fieldSet2[counter].SetPrivate(ETrue); |
|
999 if (counter%2) |
|
1000 { |
|
1001 fieldSet2[counter].SetHidden(ETrue); |
|
1002 test.Printf(_L("\n Field %d is SetHidden"),counter); |
|
1003 User::After(20000); |
|
1004 } |
|
1005 else |
|
1006 { |
|
1007 fieldSet2[counter].SetReadOnly(ETrue); |
|
1008 test.Printf(_L("\n Field %d is ReadOnly"),counter); |
|
1009 User::After(20000); |
|
1010 } |
|
1011 } |
|
1012 CntTest->Db()->CommitContactL(*newContactItem2); // commit the changes |
|
1013 CleanupStack::PopAndDestroy(2); // newContactItem2 openlx |
|
1014 |
|
1015 CntTest->CloseDatabase(); |
|
1016 CntTest->OpenDatabaseL(); |
|
1017 |
|
1018 test.Printf(_L("\n")); |
|
1019 // |
|
1020 test.Next(_L("Check hidden Persists")); |
|
1021 |
|
1022 CContactItem* newContactItem3 = CntTest->Db()->OpenContactL(newItemID); |
|
1023 CleanupStack::PushL(newContactItem3); |
|
1024 CContactItemFieldSet& fieldSet3 = newContactItem3->CardFields(); |
|
1025 // check the same |
|
1026 for (counter=0;counter<fieldSet3.Count();counter++) |
|
1027 { |
|
1028 if (fieldSet3[counter].IsHidden()) |
|
1029 { |
|
1030 if (fieldSet3[counter].IsPrivate()) |
|
1031 { |
|
1032 test.Printf(_L("\n Field %d is Hidden & PRIVATE"),counter); |
|
1033 User::After(20000); |
|
1034 } |
|
1035 else |
|
1036 { |
|
1037 test.Printf(_L("\n Field %d is Hidden"),counter); |
|
1038 User::After(20000); |
|
1039 } |
|
1040 } |
|
1041 if (fieldSet3[counter].IsReadOnly()) |
|
1042 { |
|
1043 if (fieldSet3[counter].IsPrivate()) |
|
1044 { |
|
1045 test.Printf(_L("\n Field %d is READ ONLY & PRIVATE"),counter); |
|
1046 User::After(20000); |
|
1047 } |
|
1048 else |
|
1049 { |
|
1050 test.Printf(_L("\n Field %d is READ ONLY "),counter); |
|
1051 User::After(20000); |
|
1052 } |
|
1053 } |
|
1054 } |
|
1055 CntTest->Db()->CloseContactL(newContactItem3->Id()); |
|
1056 CleanupStack::PopAndDestroy(4); // newContactItem2 openlx |
|
1057 } |
|
1058 |
|
1059 |
|
1060 LOCAL_C void PopulateUsingManyTemplates() |
|
1061 // |
|
1062 // create MANY templates |
|
1063 // |
|
1064 { |
|
1065 test.Next(_L("Create Contacts from MANY Templates")); |
|
1066 |
|
1067 // |
|
1068 CContactIdArray* tempIdList = CntTest->Db()->GetCardTemplateIdListL(); |
|
1069 CleanupStack::PushL(tempIdList); |
|
1070 TInt templateCount = tempIdList->Count(); |
|
1071 test(templateCount == KTotalNumRecords); |
|
1072 // |
|
1073 TTime before; |
|
1074 before.UniversalTime(); |
|
1075 for (TInt counter=0; counter<KTotalNumRecords; counter++) |
|
1076 { |
|
1077 CContactItem* tempTemplate = CntTest->Db()->ReadContactL((*tempIdList)[counter]); |
|
1078 CleanupStack::PushL(tempTemplate); |
|
1079 PopulateDatabaseL(*tempTemplate, 1, ETrue, EFalse); |
|
1080 if (counter%100==0) |
|
1081 test.Printf(_L(".")); // Just to show some life |
|
1082 CleanupStack::PopAndDestroy(); // tempTemplate |
|
1083 } |
|
1084 TTime after; |
|
1085 after.UniversalTime(); |
|
1086 TTimeIntervalSeconds secondsTaken; |
|
1087 after.SecondsFrom(before,secondsTaken); |
|
1088 test.Printf(_L(" TIME: %d Secs"),secondsTaken.Int()); |
|
1089 test.Printf(_L("\n")); |
|
1090 CleanupStack::PopAndDestroy(); // tempIdList |
|
1091 } |
|
1092 |
|
1093 |
|
1094 LOCAL_C void DeleteManyTemplates() |
|
1095 // |
|
1096 // Delete MANY templates |
|
1097 // |
|
1098 { |
|
1099 test.Next(_L("Delete MANY Templates")); |
|
1100 |
|
1101 // |
|
1102 CContactIdArray* tempIdList = CntTest->Db()->GetCardTemplateIdListL(); |
|
1103 CleanupStack::PushL(tempIdList); |
|
1104 TInt templateCount = tempIdList->Count(); |
|
1105 |
|
1106 // -1 because of DeletePreferredTemplate() |
|
1107 test(templateCount == KTotalNumRecords - 1); |
|
1108 // |
|
1109 TTime before; |
|
1110 before.UniversalTime(); |
|
1111 |
|
1112 // -1 because of DeletePreferredTemplate() |
|
1113 for (TInt counter=0; counter<KTotalNumRecords-1; counter++) |
|
1114 { |
|
1115 CntTest->Db()->DeleteContactL((*tempIdList)[counter]); |
|
1116 if (counter%100==0) |
|
1117 test.Printf(_L(".")); // Just to show some life |
|
1118 } |
|
1119 TTime after; |
|
1120 after.UniversalTime(); |
|
1121 TTimeIntervalSeconds secondsTaken; |
|
1122 after.SecondsFrom(before,secondsTaken); |
|
1123 test.Printf(_L(" TIME: %d Secs"),secondsTaken.Int()); |
|
1124 test.Printf(_L("\n")); |
|
1125 CContactIdArray* tempIdList2 = CntTest->Db()->GetCardTemplateIdListL(); |
|
1126 test(tempIdList2->Count()==0); |
|
1127 delete tempIdList2; |
|
1128 CleanupStack::PopAndDestroy(); // tempIdList |
|
1129 } |
|
1130 |
|
1131 LOCAL_C void SetTemplateName() |
|
1132 { |
|
1133 // |
|
1134 test.Next(_L("Set Template Label")); |
|
1135 |
|
1136 CContactIdArray* templateIds = CntTest->Db()->GetCardTemplateIdListL(); |
|
1137 CleanupStack::PushL(templateIds); |
|
1138 CContactItem* tempTemplate = CntTest->Db()->OpenContactL((*templateIds)[1]); |
|
1139 TContactItemId id = tempTemplate->Id(); |
|
1140 CleanupStack::PushL(tempTemplate); |
|
1141 TBuf<32> label; |
|
1142 label.Format(KTestLabel,99); |
|
1143 STATIC_CAST(CContactCardTemplate*,tempTemplate)->SetTemplateLabelL(label); |
|
1144 |
|
1145 CntTest->Db()->CommitContactL(*tempTemplate); |
|
1146 CntTest->Db()->CloseContactL(id); |
|
1147 CntTest->CloseDatabase(); |
|
1148 CntTest->OpenDatabaseL(); |
|
1149 |
|
1150 CContactItem* tempTemplate2 = CntTest->Db()->OpenContactL(id); |
|
1151 TPtrC tempLabel = STATIC_CAST(CContactCardTemplate*,tempTemplate2)->GetTemplateLabelL(); |
|
1152 CntTest->Db()->CloseContactL(id); |
|
1153 test(tempLabel==label); |
|
1154 delete tempTemplate2; |
|
1155 CleanupStack::PopAndDestroy(2); // tempTemplate templateIds |
|
1156 } |
|
1157 |
|
1158 |
|
1159 LOCAL_C void SetPreferredTemplate() |
|
1160 { |
|
1161 test.Next(_L("Set & Test Preferred Template")); |
|
1162 |
|
1163 CContactIdArray* templateIds = CntTest->Db()->GetCardTemplateIdListL(); |
|
1164 CleanupStack::PushL(templateIds); |
|
1165 // |
|
1166 TInt templateCount = templateIds->Count(); |
|
1167 test(templateCount == KTotalNumRecords); |
|
1168 // |
|
1169 TContactItemId prefTemplateId = CntTest->Db()->PrefTemplateId(); |
|
1170 test(prefTemplateId == KNullContactId); |
|
1171 |
|
1172 // set the preferred template |
|
1173 CContactItem* firstTemplate = CntTest->Db()->ReadContactLC((*templateIds)[0]); |
|
1174 CntTest->Db()->SetPrefTemplateL(*firstTemplate); |
|
1175 |
|
1176 CntTest->CloseDatabase(); |
|
1177 CntTest->OpenDatabaseL(); |
|
1178 |
|
1179 prefTemplateId = CntTest->Db()->PrefTemplateId(); |
|
1180 test(prefTemplateId == firstTemplate->Id()); |
|
1181 // |
|
1182 CleanupStack::PopAndDestroy(2, templateIds); // firstTemplate; |
|
1183 } |
|
1184 |
|
1185 |
|
1186 LOCAL_C void SetBadPreferredTemplate() |
|
1187 { |
|
1188 // this function is TRAPD |
|
1189 test.Next(_L("Set BAD pref Template")); |
|
1190 CContactItem* item=CContactCard::NewLC(); |
|
1191 TBuf<16> name; |
|
1192 name.Format(KTestName,1); |
|
1193 SetNameL(*item,KUidContactFieldGivenName,name); |
|
1194 CntTest->Db()->AddNewContactL(*item); |
|
1195 CntTest->Db()->SetPrefTemplateL(*item); |
|
1196 // should leave with KErrNotSupported |
|
1197 } |
|
1198 |
|
1199 LOCAL_C void DeletePreferredTemplate() |
|
1200 { |
|
1201 // this function is TRAPD |
|
1202 test.Next(_L("Delete pref Template")); |
|
1203 |
|
1204 |
|
1205 // get the template id |
|
1206 TContactItemId prefTemplateId = CntTest->Db()->PrefTemplateId(); |
|
1207 test(prefTemplateId != KNullContactId); |
|
1208 |
|
1209 // delete the preferred template |
|
1210 CntTest->Db()->DeleteContactL(prefTemplateId); |
|
1211 |
|
1212 |
|
1213 // retest the preftempId |
|
1214 prefTemplateId = CntTest->Db()->PrefTemplateId(); |
|
1215 // and ensure it has been reset to null. |
|
1216 test(prefTemplateId == KNullContactId); |
|
1217 |
|
1218 CntTest->CloseDatabase(); |
|
1219 CntTest->OpenDatabaseL(); |
|
1220 |
|
1221 prefTemplateId = CntTest->Db()->PrefTemplateId(); |
|
1222 test(prefTemplateId == KNullContactId); |
|
1223 } |
|
1224 |
|
1225 |
|
1226 LOCAL_C void DeleteAll() |
|
1227 { |
|
1228 // creates a new database - adds loads of contacts based on the golden template |
|
1229 // then deletes everything, then creates loads of contacts based on a cardtemplate |
|
1230 // then deletes everything. |
|
1231 |
|
1232 CntTest->CloseDatabase(); |
|
1233 CntTest->DeleteDatabaseL(); |
|
1234 CntTest->CreateDatabaseL(); |
|
1235 test.Next(_L("Delete All based on Golden")); |
|
1236 |
|
1237 // get the golden template |
|
1238 CContactItem* goldenTemplate = CntTest->Db()->OpenContactLX(0); |
|
1239 CleanupStack::PushL(goldenTemplate); // 2 things on the stack |
|
1240 |
|
1241 TInt i=0; |
|
1242 for (; i<KTotalNumRecords; i++) |
|
1243 { |
|
1244 CContactItem* newItem = CContactCard::NewLC(goldenTemplate); |
|
1245 CntTest->Db()->AddNewContactL(*newItem); |
|
1246 CleanupStack::PopAndDestroy(); //newItem |
|
1247 } |
|
1248 CntTest->Db()->CloseContactL(0); |
|
1249 const CContactIdArray* sortedItems = CntTest->Db()->SortedItemsL(); |
|
1250 |
|
1251 // delete the all entries in the db. |
|
1252 TInt dbCount = sortedItems->Count(); |
|
1253 |
|
1254 for (i=dbCount-1; i > -1; i--) |
|
1255 { |
|
1256 CntTest->Db()->DeleteContactL((*sortedItems)[i]); |
|
1257 } |
|
1258 |
|
1259 dbCount = CntTest->Db()->CountL(); |
|
1260 |
|
1261 // now wit multi template |
|
1262 CContactItem* tempTemplate = CntTest->Db()->CreateContactCardTemplateL(_L("label1")); |
|
1263 CleanupStack::PushL(tempTemplate); |
|
1264 |
|
1265 for (i=0; i<KTotalNumRecords; i++) |
|
1266 { |
|
1267 CContactItem* newItem = CContactCard::NewLC(tempTemplate); |
|
1268 CntTest->Db()->AddNewContactL(*newItem); |
|
1269 CleanupStack::PopAndDestroy(); //newItem |
|
1270 } |
|
1271 CntTest->Db()->CloseContactL(0); |
|
1272 const CContactIdArray* sortedItems2 = CntTest->Db()->SortedItemsL(); |
|
1273 |
|
1274 // delete the all entries in the db. |
|
1275 dbCount = sortedItems2->Count(); |
|
1276 |
|
1277 for (i=dbCount-1; i > -1; i--) |
|
1278 { |
|
1279 CntTest->Db()->DeleteContactL((*sortedItems2)[i]); |
|
1280 } |
|
1281 |
|
1282 dbCount = CntTest->Db()->CountL(); |
|
1283 |
|
1284 CleanupStack::PopAndDestroy(3); // goldenTemplate close() tempTemplate |
|
1285 } |
|
1286 |
|
1287 |
|
1288 LOCAL_C void TestTemplateCachingL() |
|
1289 // |
|
1290 // create MANY templates |
|
1291 // |
|
1292 { |
|
1293 const TInt KNumTestTemplates=32; |
|
1294 test.Next(_L("Template caching")); |
|
1295 // |
|
1296 CntTest->CloseDatabase(); |
|
1297 CntTest->DeleteDatabaseL(); |
|
1298 CntTest->CreateDatabaseL(); |
|
1299 |
|
1300 CContactIdArray* cntIdArray=CContactIdArray::NewLC(); |
|
1301 for (TInt loop=0; loop<KNumTestTemplates; loop++) |
|
1302 { |
|
1303 TBuf<32> buf; |
|
1304 buf.Format(_L("Template Cache %2d"),loop); |
|
1305 CContactItem* tempTemplate = CntTest->Db()->CreateContactCardTemplateLC(buf); |
|
1306 TContactItemId templateId=tempTemplate->Id(); |
|
1307 CleanupStack::PopAndDestroy(); // tempTemplate |
|
1308 // |
|
1309 tempTemplate=(CContactCardTemplate*)CntTest->Db()->OpenContactLX(templateId); |
|
1310 CleanupStack::PushL(tempTemplate); // |
|
1311 for(TInt delLoop=tempTemplate->CardFields().Count()-1;delLoop>=0;delLoop--) |
|
1312 tempTemplate->RemoveField(delLoop); |
|
1313 CContactItemField* field=CContactItemField::NewLC(KStorageTypeText,KUidContactFieldGivenName); |
|
1314 buf.Format(_L("Label %2d"),loop); |
|
1315 field->SetLabelL(buf); |
|
1316 tempTemplate->AddFieldL(*field); |
|
1317 CleanupStack::Pop(); // field |
|
1318 CntTest->Db()->CommitContactL(*tempTemplate); |
|
1319 CleanupStack::PopAndDestroy(2); // tempTemplate, close template |
|
1320 // |
|
1321 tempTemplate=(CContactCardTemplate*)CntTest->Db()->ReadContactLC(templateId); |
|
1322 CContactCard *card=CContactCard::NewLC(tempTemplate); |
|
1323 cntIdArray->AddL(CntTest->Db()->AddNewContactL(*card)); |
|
1324 CleanupStack::PopAndDestroy(2); // tempTemplate,card |
|
1325 } |
|
1326 test(CntTest->Db()->TemplateCount()==KNumTestTemplates); |
|
1327 CContactIdArray *ids=CntTest->Db()->GetCardTemplateIdListL(); |
|
1328 CleanupStack::PushL(ids); |
|
1329 test(ids->Count()==KNumTestTemplates); |
|
1330 for (TInt loop2=0; loop2<KNumTestTemplates; loop2++) |
|
1331 { |
|
1332 TBuf<32> name; |
|
1333 name.Format(_L("Template Cache %2d"),loop2); |
|
1334 TBuf<32> label; |
|
1335 label.Format(_L("Label %2d"),loop2); |
|
1336 for (TInt mode=0; mode<3; mode++) |
|
1337 { |
|
1338 if (mode==1) |
|
1339 { |
|
1340 CContactCardTemplate* editTemplate=(CContactCardTemplate*)CntTest->Db()->OpenContactLX((*ids)[loop2]); |
|
1341 CleanupStack::PushL(editTemplate); |
|
1342 name.Format(_L("Template Cache B%2d"),loop2); |
|
1343 label.Format(_L("Label B%2d"),loop2); |
|
1344 editTemplate->SetTemplateLabelL(name); |
|
1345 editTemplate->CardFields()[1].SetLabelL(label); |
|
1346 CntTest->Db()->CommitContactL(*editTemplate); |
|
1347 CleanupStack::PopAndDestroy(2); // tempTemplate2,close template |
|
1348 } |
|
1349 else |
|
1350 { |
|
1351 CContactItem* card=CntTest->Db()->ReadContactLC((*cntIdArray)[loop2]); |
|
1352 CContactCardTemplate* tempTemplate2=(CContactCardTemplate*)CntTest->Db()->ReadContactLC((*ids)[loop2]); |
|
1353 test(tempTemplate2->GetTemplateLabelL()==name); |
|
1354 TBuf<32> tl1(card->CardFields()[0].Label()); |
|
1355 TBuf<32> tl2(tempTemplate2->CardFields()[1].Label()); |
|
1356 test(tl1==label); |
|
1357 test(tl2==label); |
|
1358 CleanupStack::PopAndDestroy(2); // card,tempTemplate2 |
|
1359 } |
|
1360 } |
|
1361 } |
|
1362 CleanupStack::PopAndDestroy(2); // ids,cntIdArray |
|
1363 } |
|
1364 |
|
1365 // |
|
1366 // |
|
1367 // Main dispatching module |
|
1368 // |
|
1369 // |
|
1370 /** |
|
1371 |
|
1372 @SYMTestCaseID PIM-T-CARDTM-0001 |
|
1373 |
|
1374 */ |
|
1375 |
|
1376 void DoTestsL() |
|
1377 { |
|
1378 // UserHal::SetAutoSwitchOffBehavior(ESwitchOffDisabled); |
|
1379 test.Start(_L("@SYMTESTCaseID:PIM-T-CARDTM-0001 Create new database")); |
|
1380 |
|
1381 TRAPD(err,CntTest->CreateDatabaseL()); |
|
1382 test(err==KErrNone); |
|
1383 |
|
1384 TRAP(err,CreateCardTemplateL()); |
|
1385 test(err==KErrNone); |
|
1386 CntTest->CloseDatabase(); |
|
1387 CntTest->OpenDatabaseL(); |
|
1388 TRAP(err,CheckCardTemplateListPersistL()); |
|
1389 test(err==KErrNone); |
|
1390 CntTest->CloseDatabase(); |
|
1391 CntTest->OpenDatabaseL(); |
|
1392 TRAP(err,CreateEmptyContactsFromTemplateL()); |
|
1393 test(err==KErrNone); |
|
1394 CntTest->CloseDatabase(); |
|
1395 CntTest->OpenDatabaseL(); |
|
1396 TRAP(err,CheckEmptyContactsFromTemplatePersistL()); |
|
1397 test(err==KErrNone); |
|
1398 CntTest->CloseDatabase(); |
|
1399 CntTest->OpenDatabaseL(); |
|
1400 TRAP(err,CreateFullContactsFromTemplateL()); |
|
1401 test(err==KErrNone); |
|
1402 CntTest->CloseDatabase(); |
|
1403 CntTest->OpenDatabaseL(); |
|
1404 TRAP(err,CheckFullContactsFromTemplatePersistL()); |
|
1405 test(err==KErrNone); |
|
1406 CntTest->CloseDatabase(); |
|
1407 CntTest->OpenDatabaseL(); |
|
1408 TRAP(err,ModifyAddTemplateL()); |
|
1409 test(err==KErrNone); |
|
1410 CntTest->CloseDatabase(); |
|
1411 CntTest->OpenDatabaseL(); |
|
1412 TRAP(err,CheckModifyAddContactsFromTemplatePersistL()); |
|
1413 test(err==KErrNone); |
|
1414 CntTest->CloseDatabase(); |
|
1415 CntTest->OpenDatabaseL(); |
|
1416 TRAP(err,ModifyRemoveTemplateL()); |
|
1417 test(err==KErrNone); |
|
1418 CntTest->CloseDatabase(); |
|
1419 CntTest->OpenDatabaseL(); |
|
1420 TRAP(err,CheckModifyRemoveContactsFromTemplatePersistL()); |
|
1421 test(err==KErrNone); |
|
1422 CntTest->CloseDatabase(); |
|
1423 CntTest->OpenDatabaseL(); |
|
1424 TRAP(err,SetTemplateLabelL()); |
|
1425 test(err==KErrNone); |
|
1426 CntTest->CloseDatabase(); |
|
1427 CntTest->OpenDatabaseL(); |
|
1428 TRAP(err,CheckFieldLabelsPersistL()); |
|
1429 test(err==KErrNone); |
|
1430 TRAP(err,DeleteCardTemplateL()); |
|
1431 test(err==KErrNone); |
|
1432 TRAP(err,CheckDeleteCardTemplateL()); |
|
1433 test(err==KErrNone); |
|
1434 TRAP(err,CheckLargePopulatedTemplate()); |
|
1435 test(err==KErrNone); |
|
1436 TRAP(err,ModifyCardBasedOnTemplate()); |
|
1437 test(err==KErrNone); |
|
1438 TRAP(err,DeleteTemplateCheckPersist()); |
|
1439 test(err==KErrNone); |
|
1440 TRAP(err,CheckManyTemplates()); |
|
1441 test(err==KErrNone); |
|
1442 TRAP(err,TestModifyCardAttribs()); |
|
1443 test(err==KErrNone); |
|
1444 TRAP(err,PopulateUsingManyTemplates()); |
|
1445 test(err==KErrNone); |
|
1446 TRAP(err,SetTemplateName()); |
|
1447 test(err==KErrNone); |
|
1448 TRAP(err,SetPreferredTemplate()); |
|
1449 test(err==KErrNone); |
|
1450 TRAP(err,SetBadPreferredTemplate()); |
|
1451 test(err==KErrNotSupported); |
|
1452 TRAP(err,DeletePreferredTemplate()); |
|
1453 test(err==KErrNone); |
|
1454 TRAP(err,DeleteManyTemplates()); |
|
1455 test(err==KErrNone); |
|
1456 TRAP(err,TestTemplateCachingL()); |
|
1457 test(err==KErrNone); |
|
1458 TRAP(err,DeleteAll()); |
|
1459 test(err==KErrNone); |
|
1460 // TestCardTemplateCreationL(*(CntTest->Db())); |
|
1461 CntTest->CloseDatabase(); |
|
1462 |
|
1463 test.Next(_L("Delete database")); |
|
1464 |
|
1465 TRAP(err,CntTest->DeleteDatabaseL()); |
|
1466 test(err==KErrNone); |
|
1467 } |
|
1468 |
|
1469 GLDEF_C TInt E32Main() |
|
1470 { |
|
1471 __UHEAP_MARK; |
|
1472 CntTest=new(ELeave) CCntTest; |
|
1473 CntTest->ConstructL(test,KDatabaseFileName); |
|
1474 TRAPD(err,DoTestsL()); |
|
1475 CntTest->EndTestLib(err); |
|
1476 __UHEAP_MARKEND; |
|
1477 return KErrNone; |
|
1478 } |