|
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 /** |
|
17 @file |
|
18 @publishedAll |
|
19 @released |
|
20 */ |
|
21 |
|
22 #include <e32panic.h> |
|
23 #include <test/testexecutelog.h> |
|
24 #include <cntfldst.h> |
|
25 #include "CustomLabelUid.h" |
|
26 #include "ClientServer.h" |
|
27 |
|
28 _LIT(KRun1,"Uids"); |
|
29 _LIT(KRun2,"Labels"); |
|
30 _LIT(KRun3,"LabelsUids"); |
|
31 _LIT(KRun4,"LabelsUidsPlus"); |
|
32 _LIT(KRun5,"DuplicateUids"); |
|
33 _LIT(KRun6,"DuplicateExistingUids"); |
|
34 _LIT(KRun7,"UniqueExistingUids"); |
|
35 |
|
36 _LIT(KTest1,"Testing custom uids..."); |
|
37 _LIT(KTest2,"Testing custom labels..."); |
|
38 _LIT(KTest3,"Testing custom labels and uids..."); |
|
39 _LIT(KTest4,"Testing custom labels and uids plus new fields..."); |
|
40 _LIT(KTest5,"Testing Duplicate custom and exisiting Uids"); |
|
41 _LIT(KTest6,"Testing Duplicate exisiting Uids"); |
|
42 _LIT(KTest7,"Testing Unique exisiting Uids"); |
|
43 |
|
44 _LIT(KEnter,"In Test Step"); |
|
45 |
|
46 |
|
47 CCustomLabelUid::CCustomLabelUid() : |
|
48 CCntBaseStep( 1 )//Number of contacts to be used by this step |
|
49 { |
|
50 // Call base class method to set up the human readable name for logging |
|
51 SetTestStepName(SharedConstants::KCustomLabelUid); |
|
52 } |
|
53 |
|
54 TVerdict CCustomLabelUid::doTestStepL() |
|
55 { |
|
56 |
|
57 __UHEAP_MARK; |
|
58 |
|
59 INFO_PRINTF1(KEnter); |
|
60 InitializeL(); |
|
61 iIterate->Reset(); |
|
62 |
|
63 const TDesC &run = ConfigSection(); |
|
64 |
|
65 if( run == KRun1 ) |
|
66 { |
|
67 INFO_PRINTF1(KTest1); |
|
68 TestCustomUidsL(iIterate->NextL() ); |
|
69 } |
|
70 else if( run == KRun2 ) |
|
71 { |
|
72 INFO_PRINTF1(KTest2); |
|
73 TestCustomLabelsL( iIterate->NextL() ); |
|
74 } |
|
75 else if( run == KRun3 ) |
|
76 { |
|
77 INFO_PRINTF1(KTest3); |
|
78 TestCustomUidLabelsL(iIterate->NextL(), EFalse); |
|
79 } |
|
80 else if( run == KRun4 ) |
|
81 { |
|
82 INFO_PRINTF1(KTest4); |
|
83 TestCustomUidLabelsL(iIterate->NextL(), ETrue); |
|
84 } |
|
85 else if( run == KRun5 ) |
|
86 { |
|
87 INFO_PRINTF1(KTest5); |
|
88 DuplicateUidsTestL( iIterate->NextL() ); |
|
89 } |
|
90 else if( run == KRun6 ) |
|
91 { |
|
92 INFO_PRINTF1(KTest6); |
|
93 ExistingUidsTestL( EDuplicateUids ); |
|
94 } |
|
95 else if( run == KRun7 ) |
|
96 { |
|
97 INFO_PRINTF1(KTest7); |
|
98 ExistingUidsTestL( EUniqueUids ); |
|
99 } |
|
100 else |
|
101 { |
|
102 MissngTestPanic(); |
|
103 } |
|
104 Cleanup(); |
|
105 __UHEAP_MARKEND; |
|
106 |
|
107 return TestStepResult(); |
|
108 } |
|
109 |
|
110 /** |
|
111 Test: opens contact item, and adds a custom uid to each field, |
|
112 then checks if uid was stored correctly |
|
113 */ |
|
114 void CCustomLabelUid::TestCustomUidsL( const TContactItemId aCid ) |
|
115 { |
|
116 //open contact |
|
117 CContactItem *contactItem = NULL; |
|
118 contactItem = iContactsDatabase->OpenContactLX(aCid,*iViewAll); |
|
119 CleanupStack::PushL(contactItem); |
|
120 CContactItemFieldSet *ContactFields = &(contactItem->CardFields()); |
|
121 |
|
122 //add an extra (custom) uid to each fieldtype of this contact |
|
123 AddUIDsL(*ContactFields,TestConstants::KInitialUID); |
|
124 |
|
125 //populate contact fields |
|
126 SetContactFieldsL(*contactItem); |
|
127 //update contact |
|
128 iContactsDatabase->CommitContactL(*contactItem); |
|
129 |
|
130 CleanupStack::PopAndDestroy(contactItem); |
|
131 CleanupStack::Pop();//lock |
|
132 contactItem = NULL; |
|
133 |
|
134 //read contact item |
|
135 contactItem = iContactsDatabase->ReadContactLC(aCid,*iViewAll); |
|
136 ContactFields = &(contactItem->CardFields()); |
|
137 //check that contact field uids updated correctly |
|
138 SINGLECOMPARE( CheckUIDsL(*ContactFields,TestConstants::KInitialUID), 0 ,0 ); |
|
139 //check that contact fields updated correctly |
|
140 SINGLECOMPARE( CheckContactFieldsL(*contactItem), 0, 0 ); |
|
141 |
|
142 CleanupStack::PopAndDestroy(contactItem); |
|
143 } |
|
144 |
|
145 |
|
146 /** |
|
147 Test: opens contact item, add two identical uids to each field, |
|
148 alternating between custom and existing uids, |
|
149 then checks if uids were stored correctly |
|
150 */ |
|
151 void CCustomLabelUid::DuplicateUidsTestL( const TContactItemId aCid ) |
|
152 { |
|
153 //open contact |
|
154 CContactItem *contactItem = NULL; |
|
155 contactItem = iContactsDatabase->OpenContactLX(aCid,*iViewAll); |
|
156 CleanupStack::PushL(contactItem); |
|
157 CContactItemFieldSet *contactFields = &(contactItem->CardFields()); |
|
158 |
|
159 //add two identical uids to each field, alternating between custom and existing uids |
|
160 const TInt KFieldsCount = contactFields->Count(); |
|
161 TInt error = KErrNone; |
|
162 |
|
163 |
|
164 //add duplicate custom uids |
|
165 CContactItemField *contactField1 = CContactItemField::NewL(KStorageTypeText); |
|
166 CleanupStack::PushL(contactField1); |
|
167 contactField1->SetTemplateField(EFalse); |
|
168 TRAP( error, contactField1->AddFieldTypeL( TFieldType::Uid(TestConstants::KInitialUID) )); |
|
169 INTCOMPARE( KErrNone, ==, error, 0, 0 ); |
|
170 TRAP( error, contactField1->AddFieldTypeL( TFieldType::Uid(TestConstants::KInitialUID) )); |
|
171 INTCOMPARE( KErrNone, ==, error, 0, 0 ); |
|
172 contactItem->AddFieldL(*contactField1); |
|
173 CleanupStack::Pop(contactField1); |
|
174 |
|
175 //add duplicate existing uids |
|
176 CContactItemField *contactField2 = CContactItemField::NewL(KStorageTypeText); |
|
177 CleanupStack::PushL(contactField2); |
|
178 contactField2->SetTemplateField(EFalse); |
|
179 TRAP( error, contactField2->AddFieldTypeL(KUidContactFieldAdditionalName)); |
|
180 INTCOMPARE( KErrNone, ==, error, 1, 0 ); |
|
181 TRAP( error, contactField2->AddFieldTypeL(KUidContactFieldAdditionalName)); |
|
182 INTCOMPARE( KErrNone, ==, error, 1, 0 ); |
|
183 contactItem->AddFieldL(*contactField2); |
|
184 CleanupStack::Pop(contactField2); |
|
185 |
|
186 |
|
187 //populate contact fields |
|
188 SetContactFieldsL(*contactItem); |
|
189 //update contact |
|
190 iContactsDatabase->CommitContactL(*contactItem); |
|
191 |
|
192 |
|
193 CleanupStack::PopAndDestroy(contactItem); |
|
194 CleanupStack::Pop();//lock |
|
195 contactItem = NULL; |
|
196 |
|
197 //read contact item |
|
198 contactItem = iContactsDatabase->ReadContactLC(aCid,*iViewAll); |
|
199 contactFields = &(contactItem->CardFields()); |
|
200 //check that contact field uids updated correctly |
|
201 |
|
202 const TInt KReadFieldsCount = contactFields->Count(); |
|
203 const CContentType *KContentType = NULL; |
|
204 INTCOMPARE( KReadFieldsCount, >, 0, 0, 0 ); |
|
205 |
|
206 KContentType = &(*contactFields)[KFieldsCount].ContentType(); |
|
207 SINGLECOMPARE( KContentType->ContainsFieldType( TFieldType::Uid(TestConstants::KInitialUID) ), KFieldsCount,0 ); |
|
208 |
|
209 KContentType = &(*contactFields)[KFieldsCount+1].ContentType(); |
|
210 SINGLECOMPARE( KContentType->ContainsFieldType(KUidContactFieldAdditionalName), KFieldsCount+1,0 ); |
|
211 |
|
212 //check that contact fields updated correctly |
|
213 SINGLECOMPARE( CheckContactFieldsL(*contactItem), 0, 0 ); |
|
214 |
|
215 CleanupStack::PopAndDestroy(contactItem); |
|
216 } |
|
217 |
|
218 /** |
|
219 Add new contact |
|
220 Add new uid to each field that doesnt already contain that uid (EUniqueUids) |
|
221 Add new uid to each field that already contains that uid (EDuplicateUids) |
|
222 populate contact |
|
223 set custom labels |
|
224 check that all fields contain the additional uid (EUniqueUids) |
|
225 check that contact was populated correctly |
|
226 check that field lables were updated correctly |
|
227 */ |
|
228 void CCustomLabelUid::ExistingUidsTestL( const TUidTypeTest aTestType ) |
|
229 { |
|
230 /* Limitations (exceptions) to Test |
|
231 It is not possible to add Uids to all fields and expect to store and re-read them. |
|
232 This is because: |
|
233 i) Template matching (CContactItemFieldSet::MatchTemplateField) means that if a field matches a |
|
234 template field, the additional Uids are lost |
|
235 ii) Fast access fields must be text fields |
|
236 iii) Other curious combinations of Uids seem to never have been supported (e.g. Unused Name and Additional Name) |
|
237 */ |
|
238 const TUid KFastAccessFieldUids[] = |
|
239 { |
|
240 KUidContactFieldGivenNameValue, |
|
241 KUidContactFieldFamilyNameValue, |
|
242 KUidContactFieldCompanyNameValue, |
|
243 KUidContactFieldGivenNamePronunciationValue, |
|
244 KUidContactFieldFamilyNamePronunciationValue, |
|
245 KUidContactFieldCompanyNamePronunciationValue |
|
246 }; |
|
247 |
|
248 const TInt KUidsCount = iExistingUidsArray->Count(); |
|
249 CContactCard* contact = CContactCard::NewLC(iTemplate); |
|
250 |
|
251 for(TInt i = 0; i < KUidsCount; ++i ) |
|
252 { |
|
253 const TFieldType KFieldType = TFieldType::Uid( (*iExistingUidsArray)[i] ); |
|
254 |
|
255 TBool found = EFalse; |
|
256 for (TInt nameFieldNum = 0; nameFieldNum < sizeof(KFastAccessFieldUids) / sizeof(TInt); ++nameFieldNum) |
|
257 { |
|
258 if (KFieldType == (KFastAccessFieldUids[nameFieldNum])) |
|
259 { |
|
260 found = ETrue; |
|
261 } |
|
262 } |
|
263 |
|
264 found = found || KFieldType == KUidContactFieldVCardMapSIPID; |
|
265 found = found || KFieldType == KUidContactFieldTemplateLabel; |
|
266 found = found || KFieldType == KUidContactFieldVCardMapUnusedN; |
|
267 found = found || KFieldType == KUidContactFieldVCardMapTEL; |
|
268 |
|
269 if (found) |
|
270 { |
|
271 continue; |
|
272 } |
|
273 |
|
274 TContactItemId contactId = KNullContactId; |
|
275 contactId = iContactsDatabase->AddNewContactL( *contact ); |
|
276 |
|
277 //open contact |
|
278 CContactItem *contactItem = NULL; |
|
279 contactItem = iContactsDatabase->OpenContactLX(contactId,*iViewAll); |
|
280 CleanupStack::PushL(contactItem); |
|
281 CContactItemFieldSet &contactFields = contactItem->CardFields(); |
|
282 |
|
283 const TInt KFieldsCount = contactFields.Count(); |
|
284 |
|
285 for( TInt j = 0; j < KFieldsCount; ++j ) |
|
286 { |
|
287 const CContentType &KContentType = contactFields[j].ContentType(); |
|
288 |
|
289 // don't add phone/email/SIP UIDs to non-text fields |
|
290 if ((KFieldType == KUidContactFieldEMail || |
|
291 KFieldType == KUidContactFieldPhoneNumber || |
|
292 KFieldType == KUidContactFieldFax || |
|
293 KFieldType == KUidContactFieldSms) && contactFields[j].StorageType() != KStorageTypeText) |
|
294 { |
|
295 continue; |
|
296 } |
|
297 |
|
298 //if testing duplicate uids and uid is present in contact field add uid |
|
299 // if testing unique uids and uid is not presnt in contact field add uid |
|
300 if( (aTestType == EDuplicateUids) && KContentType.ContainsFieldType( KFieldType ) ) |
|
301 { |
|
302 contactFields[j].AddFieldTypeL( KFieldType ); |
|
303 } |
|
304 else if( (aTestType == EUniqueUids) && !KContentType.ContainsFieldType( KFieldType ) ) |
|
305 { |
|
306 contactFields[j].AddFieldTypeL( KFieldType ); |
|
307 } |
|
308 |
|
309 } |
|
310 |
|
311 //populate contact fields |
|
312 SetContactFieldsL(*contactItem); |
|
313 //setlabels of contact field to custom values |
|
314 SetContactLabelsL(*contactItem); |
|
315 |
|
316 iContactsDatabase->CommitContactL(*contactItem); |
|
317 CleanupStack::PopAndDestroy(contactItem); |
|
318 CleanupStack::Pop();//lock |
|
319 |
|
320 //read contact item |
|
321 contactItem = iContactsDatabase->ReadContactLC(contactId,*iViewAll); |
|
322 CContactItemFieldSet &readContactFields = contactItem->CardFields(); |
|
323 |
|
324 //check that contact field uids updated correctly |
|
325 const TInt KReadFieldsCount = readContactFields.Count(); |
|
326 INTCOMPARE( KReadFieldsCount, >, 0, i, 0 ); |
|
327 |
|
328 if( (aTestType == EUniqueUids) ) |
|
329 { |
|
330 //check that each fields contains at least one instance of the existing uid |
|
331 // (except the fast access fields) |
|
332 for( TInt k = 0; k < KReadFieldsCount; ++k ) |
|
333 { |
|
334 TBool found = EFalse; |
|
335 const CContentType &KContentType = readContactFields[k].ContentType(); |
|
336 |
|
337 for (TInt nameFieldNum = 0; nameFieldNum < sizeof(KFastAccessFieldUids) / sizeof(TInt); ++nameFieldNum) |
|
338 { |
|
339 if (KContentType.ContainsFieldType(KFastAccessFieldUids[nameFieldNum])) |
|
340 { |
|
341 found = ETrue; |
|
342 } |
|
343 } |
|
344 |
|
345 if (found) |
|
346 { |
|
347 continue; |
|
348 } |
|
349 |
|
350 // The behaviour of CContactItemFieldSet::MatchTemplateField has changed |
|
351 // add an extra UID in this case to avoid a template match (and loss of the added UID) |
|
352 if (KContentType.ContainsFieldType(KUidContactFieldVCardMapSIPID)) |
|
353 { |
|
354 continue; |
|
355 } |
|
356 |
|
357 if (KContentType.ContainsFieldType(KUidContactFieldVCardMapTEL)) |
|
358 { |
|
359 continue; |
|
360 } |
|
361 |
|
362 // some combinations of UID to Field Type are not supported |
|
363 if (KContentType.ContainsFieldType(KUidContactFieldVCardMapUnusedN) |
|
364 && (KFieldType == KUidContactFieldAdditionalName || |
|
365 KFieldType == KUidContactFieldSuffixName || |
|
366 KFieldType == KUidContactFieldPrefixName)) |
|
367 { |
|
368 continue; |
|
369 } |
|
370 |
|
371 // don't check phone/email/SIP UIDs to non-text fields |
|
372 if ((KFieldType == KUidContactFieldEMail || |
|
373 KFieldType == KUidContactFieldPhoneNumber || |
|
374 KFieldType == KUidContactFieldFax || |
|
375 KFieldType == KUidContactFieldSms) && contactFields[k].StorageType() != KStorageTypeText) |
|
376 { |
|
377 continue; |
|
378 } |
|
379 SINGLECOMPARE( KContentType.ContainsFieldType( KFieldType ), i, k ); |
|
380 } |
|
381 } |
|
382 |
|
383 //check that contact fields updated correctly |
|
384 SINGLECOMPARE( CheckContactFieldsL(*contactItem),i,0 ); |
|
385 |
|
386 //check that contact field labels were updated correctly |
|
387 SINGLECOMPARE( CheckContactLabelsL(*contactItem),i,0 ); |
|
388 |
|
389 CleanupStack::PopAndDestroy(contactItem); |
|
390 iContactsDatabase->DeleteContactL( contactId ); |
|
391 } |
|
392 CleanupStack::PopAndDestroy( contact ); |
|
393 } |
|
394 |
|
395 |
|
396 /** |
|
397 opens contact item, and changes the label of each field to a custom label, then checks |
|
398 if label was stored correctly |
|
399 */ |
|
400 void CCustomLabelUid::TestCustomLabelsL( const TContactItemId aCid ) |
|
401 { |
|
402 //open contact item |
|
403 CContactItem *contactItem = NULL; |
|
404 contactItem = iContactsDatabase->OpenContactLX(aCid,*iViewAll); |
|
405 CleanupStack::PushL(contactItem); |
|
406 |
|
407 //setlabels of contact field to custom values |
|
408 SetContactLabelsL(*contactItem); |
|
409 //populate cotnact fields and update |
|
410 SetContactFieldsL(*contactItem); |
|
411 iContactsDatabase->CommitContactL(*contactItem); |
|
412 |
|
413 CleanupStack::PopAndDestroy(contactItem); |
|
414 CleanupStack::Pop();//lock record |
|
415 |
|
416 //read contact |
|
417 contactItem = NULL; |
|
418 contactItem = iContactsDatabase->ReadContactLC(aCid,*iViewAll); |
|
419 |
|
420 //check that contact field labels were updated correctly |
|
421 SINGLECOMPARE( CheckContactLabelsL(*contactItem),0,0 ); |
|
422 |
|
423 //check that fields updated correctly |
|
424 SINGLECOMPARE( CheckContactFieldsL(*contactItem),0,0 ); |
|
425 |
|
426 CleanupStack::PopAndDestroy(contactItem); |
|
427 } |
|
428 |
|
429 /** |
|
430 this function encompasses two tests |
|
431 Test1(!aNewFields) opens contact item, and adds a custom uid to each field, changes lable to custom label |
|
432 then checks if uid and label were stored correctly |
|
433 Test2(aNewFields) opens contact item and adds ten new fields, and adds a custom uid to |
|
434 each field(new and old), changes lable to custom label then checks if uid and |
|
435 label were stored correctly. also checks both uids of new fields |
|
436 */ |
|
437 void CCustomLabelUid::TestCustomUidLabelsL( const TContactItemId aCid, const TBool aNewFields ) |
|
438 { |
|
439 CContactItem *contactItem = NULL; |
|
440 //open contact |
|
441 contactItem = iContactsDatabase->OpenContactLX(aCid,*iViewAll); |
|
442 CleanupStack::PushL(contactItem); |
|
443 CContactItemFieldSet *ContactFields = &(contactItem->CardFields()); |
|
444 |
|
445 if(aNewFields) |
|
446 { |
|
447 TInt length = 10;//add 10 new custom fields |
|
448 for(TInt i = 0, uids = TestConstants::KAltUID; i < length; i++, uids++) |
|
449 { |
|
450 AddNewFieldL( *ContactFields, TestConstants::KShortString, TFieldType::Uid(uids) ); |
|
451 } |
|
452 } |
|
453 //set custom labels for contact fields |
|
454 SetContactLabelsL(*contactItem); |
|
455 //set custom uids for contact fields |
|
456 AddUIDsL(*ContactFields,TestConstants::KInitialUID); |
|
457 //populate contact fields and update |
|
458 SetContactFieldsL(*contactItem); |
|
459 iContactsDatabase->CommitContactL(*contactItem); |
|
460 |
|
461 CleanupStack::PopAndDestroy(contactItem); |
|
462 CleanupStack::Pop();//lock |
|
463 |
|
464 //read contact |
|
465 contactItem = NULL; |
|
466 contactItem = iContactsDatabase->ReadContactLC(aCid,*iViewAll); |
|
467 ContactFields = &(contactItem->CardFields()); |
|
468 |
|
469 //check uids were update correctly |
|
470 SINGLECOMPARE( CheckUIDsL(*ContactFields,TestConstants::KInitialUID),0,0 ); |
|
471 //check labels were update correctly |
|
472 SINGLECOMPARE( CheckContactLabelsL(*contactItem),0,0 ); |
|
473 //check fields were populated correctly |
|
474 SINGLECOMPARE( CheckContactFieldsL(*contactItem),0,0 ); |
|
475 |
|
476 if(aNewFields) |
|
477 { |
|
478 //check that new fields contain the correct uids(2), initial and updated custom values |
|
479 TInt length = ContactFields->Count(); |
|
480 TInt i = ContactFields->Find( TFieldType::Uid(TestConstants::KAltUID) ); |
|
481 for(TInt uids = TestConstants::KAltUID; i < length; i++, uids++) |
|
482 { |
|
483 SINGLECOMPARE( CheckNewFieldL( *ContactFields, i, TFieldType::Uid(uids) ), i, 0); |
|
484 } |
|
485 } |
|
486 CleanupStack::PopAndDestroy(contactItem); |
|
487 } |
|
488 |
|
489 |