|
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 // Packaging Test module |
|
15 // |
|
16 // |
|
17 |
|
18 |
|
19 #include <e32test.h> |
|
20 #include <coreappstest/testserver.h> |
|
21 |
|
22 _LIT(KTestName, "T_Packager"); // Used by Testhelper |
|
23 |
|
24 #include <cntfldst.h> |
|
25 #include "testhelpers.h" |
|
26 //#include "T_CntTest.h" |
|
27 |
|
28 #include "NbCntTestLib/NbCntTestLib.h" |
|
29 |
|
30 #include "T_Packager.h" |
|
31 #include "T_CntTestImplDefs.h" |
|
32 #include "CCntPackager.h" |
|
33 #include <cntfilt.h> |
|
34 |
|
35 |
|
36 |
|
37 //#define RUN_CNT |
|
38 #define RUN_PL |
|
39 |
|
40 // |
|
41 // This test used to spit out a lot of html files which display |
|
42 // the contents of contact items. There are a lot of files |
|
43 // generated in the process which, as this is normally run on the |
|
44 // overnight build, are not read and just take up disk space. |
|
45 // Therefore, the call to the contact dumping method has been |
|
46 // configured out by #ifdefs and needs to be manually re-activated. |
|
47 // |
|
48 // So, uncomment the following line to turn on contact dumping. |
|
49 //#define __T_PACKAGER_DUMP_CONTACT__ |
|
50 // |
|
51 |
|
52 |
|
53 #define KUidContactFieldCustom1Value 0x101FD209 |
|
54 #define KUidContactFieldCustom2Value 0x101FD20A |
|
55 const TUid KUidContactFieldCustom1={KUidContactFieldCustom1Value}; |
|
56 const TUid KUidContactFieldCustom2={KUidContactFieldCustom2Value}; |
|
57 |
|
58 _LIT(KCreatePlPerform, "C:PlPerform.cdb"); |
|
59 |
|
60 |
|
61 void CPackagerTests::AllTestsL() |
|
62 { |
|
63 ContactItemTestL(); |
|
64 // iCntTestImpl.CloseDatabase(); |
|
65 EmptyContactItemTestL(); |
|
66 // ContentTypeTestL(); |
|
67 CntItemViewDefTestL(); |
|
68 CntViewDefTestL(); |
|
69 DescArrayTestL(); |
|
70 // CContactIdArrayTestL(); |
|
71 CCntFilterTestL(); |
|
72 CntTextDefTestL(); |
|
73 // MessageBufferTestL(); |
|
74 |
|
75 iCntTestImpl.CloseDatabase(); |
|
76 } |
|
77 |
|
78 void CPackagerTests::ContactItemTestL() |
|
79 { |
|
80 CCntPackager* thePackage = CCntPackager::NewL(); |
|
81 CleanupStack::PushL(thePackage); |
|
82 |
|
83 test.Next(_L("ContactItemTestL")); |
|
84 |
|
85 |
|
86 iCntTestImpl.CreateDatabaseL(nsCntTestImpl::KSecureDBName, ETrue); |
|
87 |
|
88 const CContactTemplate& goldenTemplate = iCntTestImpl.GetSysTemplate(); |
|
89 //iTempl = iCntTestImpl.GetSysTemplate(); |
|
90 |
|
91 #ifdef __T_PACKAGER_DUMP_CONTACT__ |
|
92 TESTTRAP(iCntTestImpl.DumpContactL(goldenTemplate, _L("Template"))); |
|
93 #endif |
|
94 |
|
95 CContactItem* card = CContactCard::NewLC(&goldenTemplate); |
|
96 TCnt theCnt(card); |
|
97 |
|
98 theCnt[KUidContactFieldGivenName] = _L("AExample"); |
|
99 theCnt[KUidContactFieldFamilyName] = _L("BExample"); |
|
100 |
|
101 theCnt[KUidContactFieldPhoneNumber] & KHome & KVoice & KCell = _L("mo1 39849342"); |
|
102 theCnt[KUidContactFieldPhoneNumber] & KHome & KVoice & KCell += _L("mo2 34530903495803948503984545"); |
|
103 |
|
104 theCnt[KUidContactFieldEMail] & KHome = _L("home@email"); |
|
105 theCnt[KUidContactFieldAddress] & KHome = _L("Home addresssssss"); |
|
106 theCnt[KUidContactFieldLocality] & KHome = _L("Glazgo"); |
|
107 theCnt[KUidContactFieldIMAddress] & KHome & KWv = _L("wireless@village"); |
|
108 theCnt[KUidContactFieldSecondName] = _L("Second name"); |
|
109 |
|
110 theCnt[KUidContactFieldCompanyName] = _L("SymbianFoundation"); |
|
111 theCnt[KUidContactFieldJobTitle] = _L("Driver"); |
|
112 theCnt[KUidContactFieldPhoneNumber] & KWork & KVoice = _L("work Tel 2342"); |
|
113 |
|
114 theCnt[KUidContactFieldEMail] & KWork = _L("work@email"); |
|
115 theCnt[KUidContactFieldUrl] & KWork = _L("sdfsd"); |
|
116 theCnt[KUidContactFieldAddress] & KWork = _L("afas df asd"); |
|
117 theCnt[KUidContactFieldLocality] & KWork = _L("sdfsd"); |
|
118 |
|
119 theCnt[KUidContactFieldCustom1] = _L("Filterable 1"); |
|
120 theCnt[KUidContactFieldCustom2] = _L("Filterable 2"); |
|
121 |
|
122 theCnt[KUidContactFieldGivenNamePronunciation] = _L("first name re"); |
|
123 theCnt[KUidContactFieldFamilyNamePronunciation] = _L("Last name re"); |
|
124 |
|
125 theCnt[KUidContactFieldSIPID] & KPoc = _L("SIP POC"); |
|
126 theCnt[KUidContactFieldSIPID] & KSwis = _L("SIP SWIS"); |
|
127 theCnt[KUidContactFieldSIPID] & KVoip = _L("SIP VOIP"); |
|
128 |
|
129 #ifdef __T_PACKAGER_DUMP_CONTACT__ |
|
130 TESTTRAP(iCntTestImpl.DumpContactL(*card, _L("Before Creation"))); |
|
131 #endif |
|
132 |
|
133 iCntTestImpl.CreateL(*card); |
|
134 |
|
135 // For now, call this to allocate memory for buffer in packager. |
|
136 TPtrC8 theBuffer = thePackage->GetTransmittingBuffer(); |
|
137 |
|
138 TInt err = KErrNoMemory; |
|
139 while(err==KErrNoMemory) |
|
140 { |
|
141 |
|
142 TRAPD(error, (theBuffer.Set(thePackage->PackL(*card)))); |
|
143 err = error; |
|
144 if(error==KErrNoMemory) |
|
145 { |
|
146 thePackage->GetTransmittingBuffer(); |
|
147 |
|
148 } |
|
149 } |
|
150 |
|
151 CContactItem* cntItem = thePackage->UnpackCntItemLC(); |
|
152 // CleanupStack::PushL(cntItem); |
|
153 err = CompareContactItemTestL(cntItem, card); |
|
154 User::LeaveIfError(err); |
|
155 CleanupStack::PopAndDestroy(3, thePackage); |
|
156 // POPD(cntItem); |
|
157 // POPD(card); |
|
158 // POPD(thePackage); |
|
159 |
|
160 |
|
161 } |
|
162 |
|
163 void CPackagerTests::EmptyContactItemTestL() |
|
164 { |
|
165 CCntPackager* thePackage = CCntPackager::NewL(); |
|
166 CleanupStack::PushL(thePackage); |
|
167 |
|
168 test.Next(_L("EmptyContactItemTestL")); |
|
169 |
|
170 |
|
171 CPersistenceLayer* iPersistLayer = CPersistenceLayer::NewLC(iFs); |
|
172 CContactItemViewDef* cntItemVdef = CContactItemViewDef::NewLC(CContactItemViewDef::EIncludeFields, CContactItemViewDef::EMaskHiddenFields); |
|
173 cntItemVdef->AddL(KUidContactFieldMatchAll); |
|
174 |
|
175 MLplContactsFile& cntFile = iPersistLayer->ContactsFileL(); |
|
176 |
|
177 TRAPD(err, cntFile.CreateL(KCreatePlPerform, true ? MLplContactsFile::EPlOverwrite : MLplContactsFile::EPlLeaveIfExist)); |
|
178 User::LeaveIfError(err); |
|
179 TRAP(err, while(cntFile.OpenStepL(KCreatePlPerform)){}); |
|
180 User::LeaveIfError(err); |
|
181 |
|
182 CContactItem* card = NULL; |
|
183 card = iPersistLayer->PersistenceBroker().ReadLC(KGoldenTemplateId, *cntItemVdef, EPlAllInfo, 0); |
|
184 |
|
185 // For now, call this to allocate memory for buffer in packager. |
|
186 TPtrC8 theBuffer = thePackage->GetTransmittingBuffer(); |
|
187 |
|
188 err = KErrNoMemory; |
|
189 while(err==KErrNoMemory) |
|
190 { |
|
191 |
|
192 TRAPD(error, (theBuffer.Set(thePackage->PackL(*card)))); |
|
193 err = error; |
|
194 if(error==KErrNoMemory) |
|
195 { |
|
196 thePackage->GetTransmittingBuffer(); |
|
197 |
|
198 } |
|
199 } |
|
200 |
|
201 CContactItem* cntItem = thePackage->UnpackCntItemLC(); |
|
202 err = CompareContactItemTestL(cntItem, card); |
|
203 User::LeaveIfError(err); |
|
204 CleanupStack::PopAndDestroy(5, thePackage); |
|
205 |
|
206 } |
|
207 |
|
208 void CPackagerTests::ContentTypeTestL() |
|
209 { |
|
210 CCntPackager* thePackage = CCntPackager::NewL(); |
|
211 CleanupStack::PushL(thePackage); |
|
212 |
|
213 test.Next(_L("ContentTypeTestL")); |
|
214 |
|
215 |
|
216 iCntTestImpl.CreateDatabaseL(nsCntTestImpl::KSecureDBName, ETrue); |
|
217 |
|
218 const CContactTemplate& goldenTemplate = iCntTestImpl.GetSysTemplate(); |
|
219 //iTempl = iCntTestImpl.GetSysTemplate(); |
|
220 |
|
221 #ifdef __T_PACKAGER_DUMP_CONTACT__ |
|
222 TESTTRAP(iCntTestImpl.DumpContactL(goldenTemplate, _L("Template"))); |
|
223 #endif |
|
224 |
|
225 |
|
226 CContactItem* card = CContactCard::NewLC(&goldenTemplate); |
|
227 TCnt theCnt(card); |
|
228 |
|
229 theCnt[KUidContactFieldGivenName] = _L("AExample"); |
|
230 theCnt[KUidContactFieldFamilyName] = _L("BExample"); |
|
231 |
|
232 theCnt[KUidContactFieldPhoneNumber] & KHome & KVoice & KCell = _L("mo1 39849342"); |
|
233 theCnt[KUidContactFieldPhoneNumber] & KHome & KVoice & KCell += _L("mo2 34530903495803948503984545"); |
|
234 |
|
235 theCnt[KUidContactFieldEMail] & KHome = _L("home@email"); |
|
236 theCnt[KUidContactFieldAddress] & KHome = _L("Home addresssssss"); |
|
237 theCnt[KUidContactFieldLocality] & KHome = _L("Glazgo"); |
|
238 theCnt[KUidContactFieldIMAddress] & KHome & KWv = _L("wireless@village"); |
|
239 theCnt[KUidContactFieldSecondName] = _L("Second name"); |
|
240 |
|
241 theCnt[KUidContactFieldCompanyName] = _L("SymbianFoundation"); |
|
242 theCnt[KUidContactFieldJobTitle] = _L("Driver"); |
|
243 theCnt[KUidContactFieldPhoneNumber] & KWork & KVoice = _L("work Tel 2342"); |
|
244 |
|
245 theCnt[KUidContactFieldEMail] & KWork = _L("work@email"); |
|
246 theCnt[KUidContactFieldUrl] & KWork = _L("sdfsd"); |
|
247 theCnt[KUidContactFieldAddress] & KWork = _L("afas df asd"); |
|
248 theCnt[KUidContactFieldLocality] & KWork = _L("sdfsd"); |
|
249 |
|
250 theCnt[KUidContactFieldCustom1] = _L("Filterable 1"); |
|
251 theCnt[KUidContactFieldCustom2] = _L("Filterable 2"); |
|
252 |
|
253 theCnt[KUidContactFieldGivenNamePronunciation] = _L("first name re"); |
|
254 theCnt[KUidContactFieldFamilyNamePronunciation] = _L("Last name re"); |
|
255 |
|
256 theCnt[KUidContactFieldSIPID] & KPoc = _L("SIP POC"); |
|
257 theCnt[KUidContactFieldSIPID] & KSwis = _L("SIP SWIS"); |
|
258 theCnt[KUidContactFieldSIPID] & KVoip = _L("SIP VOIP"); |
|
259 |
|
260 #ifdef __T_PACKAGER_DUMP_CONTACT__ |
|
261 TESTTRAP(iCntTestImpl.DumpContactL(*card, _L("Before Creation"))); |
|
262 #endif |
|
263 |
|
264 // iCntTestImpl.CreateL(*card); |
|
265 |
|
266 // Get the Content Type from the contact item for testing. |
|
267 // Contact Item Field Set |
|
268 CContactItemFieldSet& item1Fieldset = card->CardFields(); |
|
269 //CContactItemField* item1Field = &(item1Fieldset)[0]; |
|
270 TInt item1Fieldset_Count = item1Fieldset.Count(); |
|
271 CContentType* cntType1 = CContentType::NewL(item1Fieldset[0].ContentType()); |
|
272 CleanupStack::PushL(cntType1); |
|
273 |
|
274 if(item1Fieldset_Count<=0) |
|
275 { |
|
276 return; |
|
277 } |
|
278 |
|
279 // For now, call this to allocate memory for buffer in packager. |
|
280 TPtrC8 theBuffer = thePackage->GetTransmittingBuffer(); |
|
281 |
|
282 TInt err = KErrNoMemory; |
|
283 while(err==KErrNoMemory) |
|
284 { |
|
285 |
|
286 TRAPD(error, (theBuffer.Set(thePackage->PackL(*cntType1)))); |
|
287 err = error; |
|
288 if(error==KErrNoMemory) |
|
289 { |
|
290 thePackage->GetTransmittingBuffer(); |
|
291 |
|
292 } |
|
293 } |
|
294 |
|
295 CContentType* cntType2 = thePackage->UnpackCntContentTypeLC(); |
|
296 err = CompareContentTypeTestL(*cntType1, *cntType2); |
|
297 User::LeaveIfError(err); |
|
298 CleanupStack::PopAndDestroy(4, thePackage); |
|
299 |
|
300 } |
|
301 |
|
302 |
|
303 void CPackagerTests::CntTextDefTestL() |
|
304 { |
|
305 CCntPackager* thePackage = CCntPackager::NewL(); |
|
306 CleanupStack::PushL(thePackage); |
|
307 test.Next(_L("CntTextDefTestL")); |
|
308 |
|
309 |
|
310 // To Do: Generate Test CContactTextDef object. |
|
311 CContactTextDef* textDef1 = CContactTextDef::NewLC(); |
|
312 |
|
313 //TContactViewPreferences preferences = static_cast<TContactViewPreferences> (EContactsOnly | EUnSortedAtEnd | ESingleWhiteSpaceIsEmptyField); |
|
314 |
|
315 textDef1->AppendL(TContactTextDefItem(KUidContactFieldFamilyName)); |
|
316 textDef1->AppendL(TContactTextDefItem(KUidContactFieldGivenName)); |
|
317 textDef1->AppendL(TContactTextDefItem(KUidContactFieldCompanyName)); |
|
318 textDef1->AppendL(TContactTextDefItem(KUidContactFieldAddress)); |
|
319 textDef1->AppendL(TContactTextDefItem(KUidContactFieldEMail)); |
|
320 textDef1->AppendL(TContactTextDefItem(KUidContactFieldAdditionalName)); |
|
321 |
|
322 // For now, call this to allocate memory for buffer in packager. |
|
323 TPtrC8 theBuffer = thePackage->GetTransmittingBuffer(); |
|
324 |
|
325 TInt err = KErrNoMemory; |
|
326 while(err==KErrNoMemory) |
|
327 { |
|
328 TRAPD(error, (theBuffer.Set(thePackage->PackL(*textDef1)))); |
|
329 err = error; |
|
330 if(error==KErrNoMemory) |
|
331 { |
|
332 thePackage->GetTransmittingBuffer(); |
|
333 |
|
334 } |
|
335 } |
|
336 |
|
337 CContactTextDef* textDef2 = thePackage->UnpackCntTextDefLC(); |
|
338 err = CompareCntTextDefL(textDef1, textDef2); |
|
339 User::LeaveIfError(err); |
|
340 CleanupStack::PopAndDestroy(3, thePackage); |
|
341 |
|
342 } |
|
343 |
|
344 TInt CPackagerTests::CompareContactItemTestL(CContactItem* item1, CContactItem* item2) |
|
345 { |
|
346 |
|
347 // Contact Item type |
|
348 if(item1->Type()!=item2->Type()) |
|
349 { |
|
350 return KErrNotFound; |
|
351 } |
|
352 |
|
353 // Contact Item Field Set |
|
354 CContactItemFieldSet& item1Fieldset = item1->CardFields(); |
|
355 CContactItemFieldSet& item2Fieldset = item2->CardFields(); |
|
356 TInt item1Fieldset_Count = item1Fieldset.Count(); |
|
357 TInt item2Fieldset_Count = item2Fieldset.Count(); |
|
358 if(item1Fieldset_Count!=item2Fieldset_Count) |
|
359 { |
|
360 return KErrNotFound; |
|
361 } |
|
362 |
|
363 else // Same count! |
|
364 { |
|
365 for(TInt i=0; i<item1Fieldset_Count; i++) |
|
366 { |
|
367 if(CompareContactItemFieldTestL(&(item1Fieldset)[i], &(item2Fieldset)[i])!=KErrNone) |
|
368 { |
|
369 return KErrNotFound; |
|
370 } |
|
371 |
|
372 } |
|
373 } |
|
374 |
|
375 // Contact item's iAttributes |
|
376 if(item1->iAttributes!=item2->iAttributes) |
|
377 { |
|
378 return KErrNotFound; |
|
379 } |
|
380 |
|
381 // Contact item's ID |
|
382 if(item1->Id()!=item2->Id()) |
|
383 { |
|
384 return KErrNotFound; |
|
385 } |
|
386 |
|
387 // Contact item's TemplateRefId |
|
388 if(item1->TemplateRefId()!=item2->TemplateRefId()) |
|
389 { |
|
390 return KErrNotFound; |
|
391 } |
|
392 |
|
393 // Contact item's LastModified |
|
394 if(item1->LastModified()!=item2->LastModified()) |
|
395 { |
|
396 return KErrNotFound; |
|
397 } |
|
398 |
|
399 // Contact item's iCreationDate |
|
400 if(item1->iCreationDate!=item2->iCreationDate) |
|
401 { |
|
402 return KErrNotFound; |
|
403 } |
|
404 |
|
405 // Contact item's iAccessCount |
|
406 if(item1->AccessCount()!=item2->AccessCount()) |
|
407 { |
|
408 return KErrNotFound; |
|
409 } |
|
410 |
|
411 // Contact item's iGuid |
|
412 if((item1->iGuid==NULL)||(item2->iGuid==NULL)) |
|
413 { |
|
414 if(!((item1->iGuid==NULL)&&(item2->iGuid==NULL))) |
|
415 { |
|
416 return KErrNotFound; |
|
417 } |
|
418 } |
|
419 else |
|
420 { |
|
421 if(item1->iGuid->Length()!=item2->iGuid->Length()) |
|
422 { |
|
423 return KErrNotFound; |
|
424 } |
|
425 |
|
426 else |
|
427 { |
|
428 if(item1->iGuid->Compare(item2->iGuid->Des())!=0) |
|
429 { |
|
430 return KErrNotFound; |
|
431 } |
|
432 } |
|
433 } |
|
434 |
|
435 // Contact item's group if applicable. |
|
436 // We already check type above. |
|
437 if((item1->Type()==KUidContactGroup)|| |
|
438 (item1->Type()==KUidContactICCEntry)|| |
|
439 (item1->Type()==KUidContactCard)|| |
|
440 (item1->Type()==KUidContactOwnCard)) |
|
441 { |
|
442 CContactCard* card1 = (CContactCard*) item1; |
|
443 CContactCard* card2 = (CContactCard*) item2; |
|
444 if((card1->GroupsJoined()==NULL)||(card2->GroupsJoined()==NULL)) |
|
445 { |
|
446 if(!((card1->GroupsJoined()==NULL)&&(card2->GroupsJoined()==NULL))) |
|
447 { |
|
448 return KErrNotFound; |
|
449 } |
|
450 |
|
451 } |
|
452 else |
|
453 { |
|
454 CContactIdArray* array1 = card1->GroupsJoinedLC(); |
|
455 CContactIdArray* array2 = card2->GroupsJoinedLC(); |
|
456 if(array1->Count()!=array2->Count()) |
|
457 { |
|
458 return KErrNotFound; |
|
459 } |
|
460 |
|
461 // Checked count above already. |
|
462 for(TInt i=0;i<array1->Count();i++) |
|
463 { |
|
464 if((*array1)[i]!=(*array2)[i]) |
|
465 { |
|
466 return KErrNotFound; |
|
467 } |
|
468 } |
|
469 CleanupStack::PopAndDestroy(2); |
|
470 } |
|
471 } |
|
472 |
|
473 // Contact item's items if applicable. |
|
474 if(item1->Type()==KUidContactGroup) |
|
475 { |
|
476 CContactGroup* group1 = (CContactGroup*) item1; |
|
477 CContactGroup* group2 = (CContactGroup*) item2; |
|
478 if((group1->GroupsJoined()==NULL)||(group2->GroupsJoined()==NULL)) |
|
479 { |
|
480 if(!((group1->GroupsJoined()==NULL)&&(group2->GroupsJoined()==NULL))) |
|
481 { |
|
482 return KErrNotFound; |
|
483 } |
|
484 } |
|
485 |
|
486 else |
|
487 { |
|
488 CContactIdArray* array1 = group1->GroupsJoinedLC(); |
|
489 CContactIdArray* array2 = group2->GroupsJoinedLC(); |
|
490 if(array1->Count()!=array2->Count()) |
|
491 { |
|
492 return KErrNotFound; |
|
493 } |
|
494 |
|
495 // Checked count above already. |
|
496 for(TInt i=0;i<array1->Count();i++) |
|
497 { |
|
498 if((*array1)[i]!=(*array2)[i]) |
|
499 { |
|
500 return KErrNotFound; |
|
501 } |
|
502 } |
|
503 CleanupStack::PopAndDestroy(2); |
|
504 } |
|
505 } |
|
506 |
|
507 |
|
508 return KErrNone; |
|
509 |
|
510 } |
|
511 |
|
512 TInt CPackagerTests::CompareContactItemFieldTestL(CContactItemField* itemField1, CContactItemField* itemField2) |
|
513 { |
|
514 // CContentType *iContentType; |
|
515 /*if(!(itemField1->ContentType()==itemField2->ContentType())) |
|
516 { |
|
517 return KErrNotFound; |
|
518 }*/ |
|
519 if(CompareContentTypeTestL(itemField1->ContentType(), itemField2->ContentType())!=KErrNone) |
|
520 { |
|
521 return KErrNotFound; |
|
522 } |
|
523 |
|
524 // TStorageType iStorageType; |
|
525 if(itemField1->StorageType()!=itemField2->StorageType()) |
|
526 { |
|
527 return KErrNotFound; |
|
528 } |
|
529 |
|
530 // HBufC* iLabel; |
|
531 if((itemField1->iLabel==NULL)||(itemField2->iLabel==NULL)) |
|
532 { |
|
533 if(!((itemField1->iLabel==NULL)&&(itemField2->iLabel==NULL))) |
|
534 { |
|
535 return KErrNotFound; |
|
536 } |
|
537 } |
|
538 else |
|
539 { |
|
540 if(itemField1->iLabel->Length()!=itemField2->iLabel->Length()) |
|
541 { |
|
542 return KErrNotFound; |
|
543 } |
|
544 else |
|
545 { |
|
546 if(itemField1->iLabel->Compare(itemField2->iLabel->Des())!=0) |
|
547 { |
|
548 return KErrNotFound; |
|
549 } |
|
550 } |
|
551 } |
|
552 |
|
553 // TInt iId; |
|
554 if(itemField1->iId!=itemField2->iId) |
|
555 { |
|
556 return KErrNotFound; |
|
557 } |
|
558 |
|
559 // TUint32 iAttributes; |
|
560 if(itemField1->iAttributes!=itemField2->iAttributes) |
|
561 { |
|
562 return KErrNotFound; |
|
563 } |
|
564 |
|
565 // TUint32 iExtendedAttributes; |
|
566 if(itemField1->iExtendedAttributes!=itemField2->iExtendedAttributes) |
|
567 { |
|
568 return KErrNotFound; |
|
569 } |
|
570 |
|
571 // CContactFieldStorage* iStorage; |
|
572 switch (itemField1->StorageType()) |
|
573 { |
|
574 case KStorageTypeText: |
|
575 if(itemField1->TextStorage()->Text()!=itemField2->TextStorage()->Text()) |
|
576 { |
|
577 return KErrNotFound; |
|
578 } |
|
579 break; |
|
580 |
|
581 case KStorageTypeStore: |
|
582 if(itemField1->StoreStorage()->Thing()!=itemField2->StoreStorage()->Thing()) |
|
583 { |
|
584 return KErrNotFound; |
|
585 } |
|
586 break; |
|
587 |
|
588 case KStorageTypeDateTime: |
|
589 if(itemField1->DateTimeStorage()->Time()!=itemField2->DateTimeStorage()->Time()) |
|
590 { |
|
591 return KErrNotFound; |
|
592 } |
|
593 break; |
|
594 |
|
595 case KStorageTypeContactItemId: |
|
596 if(itemField1->AgentStorage()->Value()!=itemField2->AgentStorage()->Value()) |
|
597 { |
|
598 return KErrNotFound; |
|
599 } |
|
600 break; |
|
601 |
|
602 default: |
|
603 User::Leave(KErrNotSupported); |
|
604 break; |
|
605 } |
|
606 |
|
607 // TInt iTemplateFieldId; |
|
608 if(itemField1->iTemplateFieldId!=itemField2->iTemplateFieldId) |
|
609 { |
|
610 return KErrNotFound; |
|
611 } |
|
612 |
|
613 return KErrNone; |
|
614 } |
|
615 |
|
616 TInt CPackagerTests::CompareContentTypeTestL(const CContentType& contentType1, const CContentType& contentType2) |
|
617 { |
|
618 // CContentType *iContentType; |
|
619 if(!(contentType1==contentType2)) |
|
620 { |
|
621 return KErrNotFound; |
|
622 } |
|
623 |
|
624 |
|
625 return KErrNone; |
|
626 } |
|
627 |
|
628 TInt CPackagerTests::CompareCntTextDefL(CContactTextDef* textDef1, CContactTextDef* textDef2) |
|
629 { |
|
630 // CContactTextDef* |
|
631 TInt textDef1_Count = textDef1->Count(); |
|
632 TInt textDef2_Count = textDef2->Count(); |
|
633 if(textDef1_Count!=textDef2_Count) |
|
634 { |
|
635 return KErrNotFound; |
|
636 } |
|
637 |
|
638 else // Same count! |
|
639 { |
|
640 for(TInt i=0; i<textDef1_Count; i++) |
|
641 { |
|
642 if((*textDef1)[i].iFieldType.iUid!=(*textDef2)[i].iFieldType.iUid) |
|
643 { |
|
644 return KErrNotFound; |
|
645 } |
|
646 |
|
647 if((*textDef1)[i].iSeperator!=(*textDef2)[i].iSeperator) |
|
648 { |
|
649 return KErrNotFound; |
|
650 } |
|
651 } |
|
652 } |
|
653 |
|
654 if(textDef1->FallbackField()!=textDef2->FallbackField()) |
|
655 { |
|
656 return KErrNotFound; |
|
657 } |
|
658 |
|
659 if(textDef1->ExactMatchOnly()!=textDef2->ExactMatchOnly()) |
|
660 { |
|
661 return KErrNotFound; |
|
662 } |
|
663 |
|
664 return KErrNone; |
|
665 } |
|
666 |
|
667 |
|
668 void CPackagerTests::DescArrayTestL() |
|
669 { |
|
670 test.Next(_L("DescArrayTestL")); |
|
671 |
|
672 CCntPackager* thePackage = CCntPackager::NewL(); |
|
673 CleanupStack::PushL(thePackage); |
|
674 |
|
675 // Create a Descriptor Array. |
|
676 CDesCArray* testArray1 = new(ELeave) CDesCArrayFlat(5); |
|
677 CleanupStack::PushL(testArray1); |
|
678 testArray1->AppendL(_L("Symbian")); |
|
679 testArray1->AppendL(_L("Software")); |
|
680 testArray1->AppendL(_L("Ltd.")); |
|
681 testArray1->AppendL(_L("United Kingdom")); |
|
682 testArray1->AppendL(_L("SE1")); |
|
683 |
|
684 // For now, call this to allocate memory for buffer in packager. |
|
685 TPtrC8 theBuffer = thePackage->GetTransmittingBuffer(); |
|
686 TInt err = KErrNoMemory; |
|
687 while(err==KErrNoMemory) |
|
688 { |
|
689 |
|
690 TRAPD(error, (theBuffer.Set(thePackage->PackL(*testArray1)))); |
|
691 err = error; |
|
692 if(error==KErrNoMemory) |
|
693 { |
|
694 thePackage->GetTransmittingBuffer(); |
|
695 |
|
696 } |
|
697 } |
|
698 |
|
699 CDesCArray* testArray2 = thePackage->UnpackDesCArrayLC(); |
|
700 // CleanupStack::PushL(testArray2); |
|
701 err = CompareDescArrayTestL(testArray2, testArray1); |
|
702 User::LeaveIfError(err); |
|
703 |
|
704 CleanupStack::PopAndDestroy(3, thePackage); |
|
705 |
|
706 } |
|
707 |
|
708 TInt CPackagerTests::CompareDescArrayTestL(CDesCArray* testArray1, CDesCArray* testArray2) |
|
709 { |
|
710 // CDesCArray |
|
711 if((testArray1==NULL)||(testArray2==NULL)) |
|
712 { |
|
713 if(!((testArray1==NULL)&&(testArray2==NULL))) |
|
714 { |
|
715 return KErrNotFound; |
|
716 } |
|
717 } |
|
718 |
|
719 else |
|
720 { |
|
721 if(testArray1->Count()!=testArray2->Count()) |
|
722 { |
|
723 return KErrNotFound; |
|
724 } |
|
725 else |
|
726 { |
|
727 for(TInt i=0; i<testArray1->Count(); i++) |
|
728 { |
|
729 if((*testArray1)[i]!=(*testArray2)[i]) |
|
730 { |
|
731 return KErrNotFound; |
|
732 } |
|
733 } |
|
734 } |
|
735 } |
|
736 |
|
737 |
|
738 return KErrNone; |
|
739 } |
|
740 |
|
741 |
|
742 void CPackagerTests::CntItemViewDefTestL() |
|
743 { |
|
744 test.Next(_L("CntItemViewDefL")); |
|
745 |
|
746 CCntPackager* thePackage = CCntPackager::NewL(); |
|
747 CleanupStack::PushL(thePackage); |
|
748 |
|
749 // Create a populated CContactItemViewDef object. |
|
750 CContactItemViewDef* viewDef1=CContactItemViewDef::NewLC(CContactItemViewDef::EIncludeFields,CContactItemViewDef::EMaskHiddenFields); |
|
751 viewDef1->AddL(KUidContactFieldGivenName); |
|
752 viewDef1->AddL(KUidContactFieldFamilyName); |
|
753 viewDef1->AddL(KUidContactFieldPhoneNumber); |
|
754 viewDef1->AddL(KUidContactFieldCompanyName); |
|
755 viewDef1->AddL(KUidContactFieldAddress); |
|
756 test(viewDef1->Count()==5); |
|
757 test((*viewDef1)[0]==KUidContactFieldGivenName); |
|
758 test((*viewDef1)[1]==KUidContactFieldFamilyName); |
|
759 test((*viewDef1)[2]==KUidContactFieldPhoneNumber); |
|
760 test((*viewDef1)[3]==KUidContactFieldCompanyName); |
|
761 test((*viewDef1)[4]==KUidContactFieldAddress); |
|
762 |
|
763 // For now, call this to allocate memory for buffer in packager. |
|
764 TPtrC8 theBuffer = thePackage->GetTransmittingBuffer(); |
|
765 TInt err = KErrNoMemory; |
|
766 while(err==KErrNoMemory) |
|
767 { |
|
768 |
|
769 TRAPD(error, (theBuffer.Set(thePackage->PackL(*viewDef1)))); |
|
770 err = error; |
|
771 if(error==KErrNoMemory) |
|
772 { |
|
773 thePackage->GetTransmittingBuffer(); |
|
774 |
|
775 } |
|
776 } |
|
777 |
|
778 CContactItemViewDef* viewDef2 = thePackage->UnpackCntItemViewDefLC(); |
|
779 err = CompareCntItemViewDefTestL(viewDef1, viewDef2); |
|
780 User::LeaveIfError(err); |
|
781 |
|
782 CleanupStack::PopAndDestroy(3, thePackage); |
|
783 |
|
784 } |
|
785 |
|
786 |
|
787 void CPackagerTests::CntViewDefTestL() |
|
788 { |
|
789 test.Next(_L("CntViewDefL")); |
|
790 |
|
791 CCntPackager* thePackage = CCntPackager::NewL(); |
|
792 CleanupStack::PushL(thePackage); |
|
793 |
|
794 // Create a populated CContactItemViewDef object. |
|
795 CContactItemViewDef* viewDef1=CContactItemViewDef::NewLC(CContactItemViewDef::EIncludeFields,CContactItemViewDef::EMaskHiddenFields); |
|
796 // CleanupStack::PushL(viewDef1); |
|
797 viewDef1->AddL(KUidContactFieldGivenName); |
|
798 viewDef1->AddL(KUidContactFieldFamilyName); |
|
799 viewDef1->AddL(KUidContactFieldPhoneNumber); |
|
800 viewDef1->AddL(KUidContactFieldCompanyName); |
|
801 viewDef1->AddL(KUidContactFieldAddress); |
|
802 test(viewDef1->Count()==5); |
|
803 test((*viewDef1)[0]==KUidContactFieldGivenName); |
|
804 test((*viewDef1)[1]==KUidContactFieldFamilyName); |
|
805 test((*viewDef1)[2]==KUidContactFieldPhoneNumber); |
|
806 test((*viewDef1)[3]==KUidContactFieldCompanyName); |
|
807 test((*viewDef1)[4]==KUidContactFieldAddress); |
|
808 |
|
809 // Create CContactViewDef |
|
810 CContactViewDef* def1=CContactViewDef::NewL(viewDef1); |
|
811 CleanupStack::Pop(viewDef1); // viewDef1 |
|
812 CleanupStack::PushL(def1); |
|
813 |
|
814 // For now, call this to allocate memory for buffer in packager. |
|
815 TPtrC8 theBuffer = thePackage->GetTransmittingBuffer(); |
|
816 TInt err = KErrNoMemory; |
|
817 while(err==KErrNoMemory) |
|
818 { |
|
819 |
|
820 TRAPD(error, (theBuffer.Set(thePackage->PackL(*def1)))); |
|
821 err = error; |
|
822 if(error==KErrNoMemory) |
|
823 { |
|
824 thePackage->GetTransmittingBuffer(); |
|
825 |
|
826 } |
|
827 } |
|
828 |
|
829 CContactViewDef* def2 = thePackage->UnpackCntViewDefLC(); |
|
830 |
|
831 err = CompareCntViewDefTestL(def1, def2); |
|
832 User::LeaveIfError(err); |
|
833 |
|
834 CleanupStack::PopAndDestroy(3, thePackage); |
|
835 |
|
836 } |
|
837 |
|
838 void CPackagerTests::MessageBufferTestL() |
|
839 { |
|
840 test.Next(_L("MessageBufferTestL")); |
|
841 |
|
842 CCntPackager* thePackage = CCntPackager::NewL(); |
|
843 CleanupStack::PushL(thePackage); |
|
844 |
|
845 // Create a Descriptor Array. |
|
846 CDesCArray* testArray1 = new(ELeave) CDesCArrayFlat(5); |
|
847 CleanupStack::PushL(testArray1); |
|
848 testArray1->AppendL(_L("Symbian")); |
|
849 testArray1->AppendL(_L("Software")); |
|
850 testArray1->AppendL(_L("Ltd.")); |
|
851 testArray1->AppendL(_L("United Kingdom")); |
|
852 testArray1->AppendL(_L("SE1")); |
|
853 |
|
854 // For now, call this to allocate memory for buffer in packager. |
|
855 TPtr8 theBuffer(NULL, NULL, NULL); |
|
856 TInt err = KErrNoMemory; |
|
857 while(err==KErrNoMemory) |
|
858 { |
|
859 |
|
860 TRAPD(error, (theBuffer.Set(thePackage->PackL(*testArray1)))); |
|
861 err = error; |
|
862 if(error==KErrNoMemory) |
|
863 { |
|
864 thePackage->GetTransmittingBuffer(); |
|
865 |
|
866 } |
|
867 } |
|
868 |
|
869 RMessage2 testMessage; |
|
870 // TDesC8& desBuf(theBuffer); |
|
871 TInt length = theBuffer.Length(); |
|
872 TInt size = theBuffer.Size(); |
|
873 |
|
874 // HBufC8* data = theBuffer.AllocLC();// HBufC8::NewLC(2000); |
|
875 |
|
876 // TPtr8 theBufferClone(data->Des()); |
|
877 // theBufferClone.Copy(theBuffer.Ptr()); |
|
878 length = theBuffer.Length(); |
|
879 size = theBuffer.Size(); |
|
880 testMessage.WriteL(0, theBuffer); |
|
881 testMessage.Complete(KErrNone); |
|
882 |
|
883 // Reset buffer and set buffer from the Message |
|
884 thePackage->Clear(); |
|
885 thePackage->SetBufferFromMessageL(testMessage); |
|
886 |
|
887 |
|
888 CDesCArray* testArray2 = thePackage->UnpackDesCArrayLC(); |
|
889 // CleanupStack::PushL(testArray2); |
|
890 err = CompareDescArrayTestL(testArray2, testArray1); |
|
891 User::LeaveIfError(err); |
|
892 |
|
893 CleanupStack::PopAndDestroy(3, thePackage); |
|
894 } |
|
895 |
|
896 |
|
897 void CPackagerTests::CContactIdArrayTestL() |
|
898 { |
|
899 test.Next(_L("CContactIdArrayTestL")); |
|
900 |
|
901 CCntPackager* thePackage = CCntPackager::NewL(); |
|
902 CleanupStack::PushL(thePackage); |
|
903 |
|
904 // Create a CContactIdArrayTestL Array from a contact item. |
|
905 iCntTestImpl.CreateDatabaseL(nsCntTestImpl::KSecureDBName, ETrue); |
|
906 |
|
907 const CContactTemplate& goldenTemplate = iCntTestImpl.GetSysTemplate(); |
|
908 |
|
909 #ifdef __T_PACKAGER_DUMP_CONTACT__ |
|
910 TESTTRAP(iCntTestImpl.DumpContactL(goldenTemplate, _L("Template"))); |
|
911 #endif |
|
912 |
|
913 CContactItem* card = CContactCard::NewLC(&goldenTemplate); |
|
914 TCnt theCnt(card); |
|
915 |
|
916 theCnt[KUidContactFieldGivenName] = _L("AExample"); |
|
917 theCnt[KUidContactFieldFamilyName] = _L("BExample"); |
|
918 |
|
919 theCnt[KUidContactFieldPhoneNumber] & KHome & KVoice & KCell = _L("mo1 39849342"); |
|
920 theCnt[KUidContactFieldPhoneNumber] & KHome & KVoice & KCell += _L("mo2 34530903495803948503984545"); |
|
921 |
|
922 theCnt[KUidContactFieldEMail] & KHome = _L("home@email"); |
|
923 theCnt[KUidContactFieldAddress] & KHome = _L("Home addresssssss"); |
|
924 theCnt[KUidContactFieldLocality] & KHome = _L("Glazgo"); |
|
925 theCnt[KUidContactFieldIMAddress] & KHome & KWv = _L("wireless@village"); |
|
926 theCnt[KUidContactFieldSecondName] = _L("Second name"); |
|
927 |
|
928 theCnt[KUidContactFieldCompanyName] = _L("SymbianFoundation"); |
|
929 theCnt[KUidContactFieldJobTitle] = _L("Driver"); |
|
930 theCnt[KUidContactFieldPhoneNumber] & KWork & KVoice = _L("work Tel 2342"); |
|
931 |
|
932 theCnt[KUidContactFieldEMail] & KWork = _L("work@email"); |
|
933 theCnt[KUidContactFieldUrl] & KWork = _L("sdfsd"); |
|
934 theCnt[KUidContactFieldAddress] & KWork = _L("afas df asd"); |
|
935 theCnt[KUidContactFieldLocality] & KWork = _L("sdfsd"); |
|
936 |
|
937 theCnt[KUidContactFieldCustom1] = _L("Filterable 1"); |
|
938 theCnt[KUidContactFieldCustom2] = _L("Filterable 2"); |
|
939 |
|
940 theCnt[KUidContactFieldGivenNamePronunciation] = _L("first name re"); |
|
941 theCnt[KUidContactFieldFamilyNamePronunciation] = _L("Last name re"); |
|
942 |
|
943 theCnt[KUidContactFieldSIPID] & KPoc = _L("SIP POC"); |
|
944 theCnt[KUidContactFieldSIPID] & KSwis = _L("SIP SWIS"); |
|
945 theCnt[KUidContactFieldSIPID] & KVoip = _L("SIP VOIP"); |
|
946 |
|
947 #ifdef __T_PACKAGER_DUMP_CONTACT__ |
|
948 TESTTRAP(iCntTestImpl.DumpContactL(*card, _L("Before Creation"))); |
|
949 #endif |
|
950 |
|
951 iCntTestImpl.CreateL(*card); |
|
952 |
|
953 // Create second contact item |
|
954 CPersistenceLayer* iPersistLayer = CPersistenceLayer::NewLC(iFs); |
|
955 CContactItemViewDef* cntItemVdef = CContactItemViewDef::NewLC(CContactItemViewDef::EIncludeFields, CContactItemViewDef::EMaskHiddenFields); |
|
956 cntItemVdef->AddL(KUidContactFieldMatchAll); |
|
957 |
|
958 MLplContactsFile& cntFile = iPersistLayer->ContactsFileL(); |
|
959 |
|
960 TRAPD(err, cntFile.CreateL(KCreatePlPerform, true ? MLplContactsFile::EPlOverwrite : MLplContactsFile::EPlLeaveIfExist)); |
|
961 User::LeaveIfError(err); |
|
962 TRAP(err, while(cntFile.OpenStepL(KCreatePlPerform)){}); |
|
963 User::LeaveIfError(err); |
|
964 |
|
965 CContactItem* card2 = NULL; |
|
966 card2 = iPersistLayer->PersistenceBroker().ReadLC(KGoldenTemplateId, *cntItemVdef, EPlAllInfo, 0); |
|
967 |
|
968 |
|
969 // Create CContactIdArray |
|
970 CContactIdArray* theIdArray1 = CContactIdArray::NewLC(); |
|
971 theIdArray1->AddL(card->Id()); |
|
972 theIdArray1->AddL(card->TemplateRefId()); |
|
973 theIdArray1->AddL(card2->Id()); |
|
974 theIdArray1->AddL(card2->TemplateRefId()); |
|
975 |
|
976 // For now, call this to allocate memory for buffer in packager. |
|
977 TPtrC8 theBuffer(NULL, NULL); |
|
978 TInt err2 = KErrNoMemory; |
|
979 while(err2==KErrNoMemory) |
|
980 { |
|
981 TRAPD(error, (theBuffer.Set(thePackage->PackL(*theIdArray1)))); |
|
982 err2= error; |
|
983 if(error==KErrNoMemory) |
|
984 { |
|
985 thePackage->GetTransmittingBuffer(); |
|
986 |
|
987 } |
|
988 } |
|
989 |
|
990 CContactIdArray* theIdArray2 = thePackage->UnpackCntIdArrayLC(); |
|
991 err2 = CompareCContactIdArrayTestL(theIdArray1, theIdArray2); |
|
992 User::LeaveIfError(err2); |
|
993 |
|
994 CleanupStack::PopAndDestroy(7, thePackage); |
|
995 } |
|
996 |
|
997 TInt CPackagerTests::CompareCContactIdArrayTestL(CContactIdArray* idArray1, CContactIdArray* idArray2) |
|
998 { |
|
999 // CContactIdArray |
|
1000 if((idArray1==NULL)||(idArray2==NULL)) |
|
1001 { |
|
1002 if(!((idArray1==NULL)&&(idArray2==NULL))) |
|
1003 { |
|
1004 return KErrNotFound; |
|
1005 } |
|
1006 } |
|
1007 |
|
1008 else |
|
1009 { |
|
1010 if(idArray1->Count()!=idArray2->Count()) |
|
1011 { |
|
1012 return KErrNotFound; |
|
1013 } |
|
1014 else |
|
1015 { |
|
1016 for(TInt i=0; i<idArray1->Count(); i++) |
|
1017 { |
|
1018 if((*idArray1)[i]!=(*idArray2)[i]) |
|
1019 { |
|
1020 return KErrNotFound; |
|
1021 } |
|
1022 } |
|
1023 } |
|
1024 } |
|
1025 |
|
1026 return KErrNone; |
|
1027 } |
|
1028 |
|
1029 TInt CPackagerTests::CompareCntItemViewDefTestL(CContactItemViewDef* viewDef1, CContactItemViewDef* viewDef2) |
|
1030 { |
|
1031 // CContactItemViewDef |
|
1032 |
|
1033 if(viewDef1->Mode()!=viewDef2->Mode()) |
|
1034 { |
|
1035 return KErrNotFound; |
|
1036 } |
|
1037 |
|
1038 if(viewDef1->Use()!=viewDef2->Use()) |
|
1039 { |
|
1040 return KErrNotFound; |
|
1041 } |
|
1042 |
|
1043 if(viewDef1->Count()!=viewDef2->Count()) |
|
1044 { |
|
1045 return KErrNotFound; |
|
1046 } |
|
1047 else |
|
1048 { |
|
1049 for(TInt i=0; i<viewDef1->Count(); i++) |
|
1050 { |
|
1051 if((*viewDef1)[i]!=(*viewDef2)[i]) |
|
1052 { |
|
1053 return KErrNotFound; |
|
1054 } |
|
1055 } |
|
1056 } |
|
1057 |
|
1058 return KErrNone; |
|
1059 } |
|
1060 |
|
1061 TInt CPackagerTests::CompareCntViewDefTestL(CContactViewDef* def1, CContactViewDef* def2) |
|
1062 { |
|
1063 // CContactViewDef |
|
1064 |
|
1065 return CompareCntItemViewDefTestL(&(def1->ItemDef()), &(def2->ItemDef())); |
|
1066 } |
|
1067 |
|
1068 |
|
1069 void CPackagerTests::CCntFilterTestL() |
|
1070 { |
|
1071 test.Next(_L("CContactIdArrayTestL")); |
|
1072 |
|
1073 CCntPackager* thePackage = CCntPackager::NewL(); |
|
1074 CleanupStack::PushL(thePackage); |
|
1075 |
|
1076 // Create a CCntFilter item. |
|
1077 CCntFilter* filter1 = CCntFilter::NewL(); |
|
1078 CleanupStack::PushL(filter1); |
|
1079 |
|
1080 filter1->SetContactFilterTypeCard(ETrue); |
|
1081 TTime time; |
|
1082 time.UniversalTime(); |
|
1083 time-=TTimeIntervalMinutes(20); // changes in the last 20 mins |
|
1084 filter1->SetFilterDateTime(time); |
|
1085 filter1->SetIncludeNewContacts(ETrue); |
|
1086 filter1->SetContactFilterTypeALL(ETrue); |
|
1087 |
|
1088 // For now, call this to allocate memory for buffer in packager. |
|
1089 TPtrC8 theBuffer(NULL, NULL); |
|
1090 TInt err = KErrNoMemory; |
|
1091 while(err==KErrNoMemory) |
|
1092 { |
|
1093 TRAPD(error, (theBuffer.Set(thePackage->PackL(*filter1)))); |
|
1094 err= error; |
|
1095 if(error==KErrNoMemory) |
|
1096 { |
|
1097 thePackage->GetTransmittingBuffer(); |
|
1098 |
|
1099 } |
|
1100 } |
|
1101 |
|
1102 CCntFilter* filter2 = thePackage->UnpackCntFilterLC(); |
|
1103 err = CompareCCntFilterTestL(filter1, filter2); |
|
1104 User::LeaveIfError(err); |
|
1105 |
|
1106 CleanupStack::PopAndDestroy(3, thePackage); |
|
1107 } |
|
1108 |
|
1109 TInt CPackagerTests::CompareCCntFilterTestL(CCntFilter* filter1, CCntFilter* filter2) |
|
1110 { |
|
1111 // CCntFilter |
|
1112 if(CompareCContactIdArrayTestL(filter1->iIds, filter2->iIds)!=KErrNone) |
|
1113 { |
|
1114 return KErrNotFound; |
|
1115 } |
|
1116 |
|
1117 if(filter1->GetFilterDateTime()!=filter2->GetFilterDateTime()) |
|
1118 { |
|
1119 return KErrNotFound; |
|
1120 } |
|
1121 |
|
1122 if(filter1->iInclude!=filter2->iInclude) |
|
1123 { |
|
1124 return KErrNotFound; |
|
1125 } |
|
1126 |
|
1127 if(filter1->iContactType!=filter2->iContactType) |
|
1128 { |
|
1129 return KErrNotFound; |
|
1130 } |
|
1131 |
|
1132 return KErrNone; |
|
1133 } |
|
1134 |
|
1135 //Persistence test construction and destruction |
|
1136 CPackagerTests* CPackagerTests::NewLC (CCntTestImplementor& aCntTestImpl) |
|
1137 { |
|
1138 CPackagerTests* self = new (ELeave) CPackagerTests(aCntTestImpl); |
|
1139 CleanupStack::PushL(self); |
|
1140 |
|
1141 self->ConstructL(); |
|
1142 |
|
1143 return self; |
|
1144 } |
|
1145 |
|
1146 void CPackagerTests::ConstructL() |
|
1147 { |
|
1148 User::LeaveIfError(iFs.Connect()); |
|
1149 iMatchAll = CContactItemViewDef::NewLC(CContactItemViewDef::EIncludeFields,CContactItemViewDef::EIncludeHiddenFields); |
|
1150 iMatchAll->AddL(KUidContactFieldMatchAll); |
|
1151 CleanupStack::Pop(iMatchAll); |
|
1152 } |
|
1153 |
|
1154 CPackagerTests::~CPackagerTests() |
|
1155 { |
|
1156 delete iMatchAll; |
|
1157 iFs.Close(); |
|
1158 } |
|
1159 |
|
1160 |
|
1161 /** |
|
1162 |
|
1163 @SYMTestCaseID PIM-T-PACKAGER-0001 |
|
1164 |
|
1165 */ |
|
1166 |
|
1167 |
|
1168 LOCAL_C void DoTestsL() |
|
1169 { |
|
1170 CleanupClosePushL(test); |
|
1171 CPackagerTests* cntTester = NULL; |
|
1172 test.Start(_L("@SYMTESTCaseID:PIM-T-PACKAGER-0001 Persistency tests")); |
|
1173 |
|
1174 |
|
1175 RPIMTestServer serv; |
|
1176 User::LeaveIfError(serv.Connect()); |
|
1177 |
|
1178 #ifdef RUN_CNT |
|
1179 |
|
1180 test.Start(_L("Contact model tests")); |
|
1181 |
|
1182 __UHEAP_MARK; |
|
1183 CCntTestImpl* oldCntTestImpl = CCntTestImpl::NewLC(); |
|
1184 |
|
1185 cntTester = CPackagerTests::NewLC(*oldCntTestImpl); |
|
1186 cntTester->AllTestsL(); |
|
1187 POPD(cntTester); |
|
1188 |
|
1189 CleanupStack::PopAndDestroy(oldCntTestImpl); |
|
1190 oldCntTestImpl = NULL; |
|
1191 test.End(); |
|
1192 __UHEAP_MARKEND; |
|
1193 #endif |
|
1194 |
|
1195 #ifdef RUN_PL |
|
1196 |
|
1197 test.Start(_L("Persistence Layer Tests")); |
|
1198 |
|
1199 __UHEAP_MARK; |
|
1200 CPlTestImpl* plCntTestImpl = CPlTestImpl::NewLC(); |
|
1201 cntTester = CPackagerTests::NewLC(*plCntTestImpl); |
|
1202 cntTester->AllTestsL(); |
|
1203 |
|
1204 POPD(cntTester); |
|
1205 CleanupStack::PopAndDestroy(plCntTestImpl); |
|
1206 plCntTestImpl = NULL; |
|
1207 test.End(); |
|
1208 __UHEAP_MARKEND; |
|
1209 |
|
1210 #endif |
|
1211 |
|
1212 |
|
1213 serv.Close(); |
|
1214 test.End(); |
|
1215 CleanupStack::PopAndDestroy(1); // test.Close |
|
1216 |
|
1217 } |
|
1218 |
|
1219 |
|
1220 |
|
1221 |
|
1222 GLDEF_C TInt E32Main() |
|
1223 { |
|
1224 // Init |
|
1225 CTrapCleanup* cleanupStack = CTrapCleanup::New(); |
|
1226 if (!cleanupStack) |
|
1227 { |
|
1228 return KErrNoMemory; |
|
1229 } |
|
1230 |
|
1231 CActiveScheduler* activeScheduler = new CActiveScheduler; |
|
1232 if (!activeScheduler) |
|
1233 { |
|
1234 return KErrNoMemory; |
|
1235 } |
|
1236 CActiveScheduler::Install(activeScheduler); |
|
1237 |
|
1238 // Run the tests |
|
1239 __UHEAP_MARK; |
|
1240 TRAPD(err, DoTestsL()); |
|
1241 __UHEAP_MARKEND; |
|
1242 |
|
1243 |
|
1244 test(__NB_failures == 0); |
|
1245 |
|
1246 // Cleanup |
|
1247 delete activeScheduler; |
|
1248 delete cleanupStack; |
|
1249 activeScheduler = NULL; |
|
1250 cleanupStack = NULL; |
|
1251 |
|
1252 return err; |
|
1253 } |
|
1254 |
|
1255 |