|
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 // Persistence Layer Test module |
|
15 // |
|
16 // |
|
17 |
|
18 |
|
19 #include <e32test.h> |
|
20 #include <coreappstest/testserver.h> |
|
21 #include "persistencelayer.h" |
|
22 #include "cnttestsynchroniser.h" |
|
23 |
|
24 _LIT(KTestName, "T_PersistenceLayer"); // Used by Testhelper |
|
25 |
|
26 #include "testhelpers.h" |
|
27 |
|
28 #include "NbCntTestLib/NbCntTestLib.h" |
|
29 |
|
30 #include "T_PersistenceLayer.h" |
|
31 #include "T_CntTestImplDefs.h" |
|
32 |
|
33 |
|
34 #define RUN_PL |
|
35 #define RUN_CNT |
|
36 |
|
37 #define KUidContactFieldCustom1Value 0x101FD209 |
|
38 #define KUidContactFieldCustom2Value 0x101FD20A |
|
39 const TUid KUidContactFieldCustom1={KUidContactFieldCustom1Value}; |
|
40 const TUid KUidContactFieldCustom2={KUidContactFieldCustom2Value}; |
|
41 _LIT(KCrudTestDbFile, "C:CRUD_TEST"); |
|
42 |
|
43 // |
|
44 // This test used to spit out a lot of html files which display |
|
45 // the contents of contact items. There are a lot of files |
|
46 // generated in the process which, as this is normally run on the |
|
47 // overnight build, are not read and just take up disk space. |
|
48 // Therefore, the call to the contact dumping method has been |
|
49 // configured out by #ifdefs and needs to be manually re-activated. |
|
50 // |
|
51 // So, uncomment the following line to turn on contact dumping. |
|
52 //#define __T_PERSISTENCELAYER_DUMP_CONTACT__ |
|
53 // |
|
54 |
|
55 |
|
56 void CPersistenceTests::AllTestsL() |
|
57 { |
|
58 FileCreationL(); |
|
59 |
|
60 IccL(); |
|
61 DuplicatedFieldUidsL(); |
|
62 |
|
63 BasicCRUDL(); |
|
64 ViewDefsInclL(); |
|
65 ViewDefsMaskL(); |
|
66 |
|
67 TDriveUnit drv(EDriveC); |
|
68 CDesCArray* arr = iCntTestImpl.ListDatabasesL(drv); |
|
69 delete arr; |
|
70 |
|
71 OomTestL(); |
|
72 AccessCountL(); |
|
73 TemplateAccessCountL(); |
|
74 GroupsL(); |
|
75 iCntTestImpl.CloseDatabase(); |
|
76 } |
|
77 |
|
78 |
|
79 void CPersistenceTests::IccL() |
|
80 { |
|
81 CContactSyncChecker::ResetL(); |
|
82 CContactItem* iccEntry = CContactICCEntry::NewL(iCntTestImpl.GetSysTemplate()); |
|
83 PUSH(iccEntry); |
|
84 |
|
85 TCnt theCnt(iccEntry); |
|
86 theCnt[KUidContactFieldGivenName] = _L("Name"); |
|
87 theCnt[KUidContactFieldFamilyName] = _L("Example"); |
|
88 |
|
89 iCntTestImpl.CreateL(*iccEntry); |
|
90 |
|
91 POPD(iccEntry); |
|
92 } |
|
93 |
|
94 |
|
95 void CPersistenceTests::OomTestL() |
|
96 { |
|
97 test.Next(_L("ReadLC OOM test")); |
|
98 CContactItem* cnt = iCntTestImpl.ReadLC(1, *iMatchAll); |
|
99 POPD(cnt); |
|
100 |
|
101 TInt ret = 0; |
|
102 for(TInt i=1; i < 2000; ++i) |
|
103 { |
|
104 __UHEAP_SETFAIL(RHeap::EDeterministic, i); |
|
105 __UHEAP_MARK; |
|
106 TRAP(ret, CContactItem* cnt = iCntTestImpl.ReadLC(1, *iMatchAll); POPD(cnt); ); |
|
107 __UHEAP_MARKEND; |
|
108 __UHEAP_RESET; |
|
109 |
|
110 if (ret == KErrNone) |
|
111 { |
|
112 break; |
|
113 } |
|
114 else if (ret != KErrNoMemory) |
|
115 { |
|
116 TESTVALUE(ret, KErrNoMemory); |
|
117 break; |
|
118 } |
|
119 if (!(i % 100)) |
|
120 { |
|
121 test.Printf(_L("."), i/100); |
|
122 } |
|
123 } |
|
124 test.Printf(_L("\r\n")); |
|
125 } |
|
126 |
|
127 |
|
128 |
|
129 void CPersistenceTests::TemplateAccessCountL() |
|
130 { |
|
131 test.Next(_L("Template Access Count test")); |
|
132 |
|
133 //Create a custom template |
|
134 CContactItem* templ = iCntTestImpl.CreateContactCardTemplateLC(_L("UserTemplate")); |
|
135 TContactItemId templId = templ->Id(); |
|
136 POPD(templ); templ = NULL; |
|
137 |
|
138 //Read the template from the database |
|
139 templ = iCntTestImpl.ReadLC(templId, *iMatchAll); |
|
140 TESTVALUE(templ->IsDeleted(), EFalse); |
|
141 |
|
142 |
|
143 //Create a contact based on the template |
|
144 CContactItem* card = CContactCard::NewLC(templ); |
|
145 TCnt theCnt(card); |
|
146 theCnt[KUidContactFieldGivenName] += _L("Contact"); |
|
147 theCnt[KUidContactFieldFamilyName] += _L("Based on"); |
|
148 theCnt[KUidContactFieldEMail] & KHome += _L("User Template"); |
|
149 iCntTestImpl.CreateL(*card); |
|
150 |
|
151 const TInt createdEntryId = card->Id(); |
|
152 POPD(card); card = NULL; |
|
153 POPD(templ); templ = NULL; |
|
154 |
|
155 //Try to delete the template (it should only be marked and deleted) |
|
156 TESTTRAP(iCntTestImpl.DeleteL(templId)); |
|
157 |
|
158 //Read the template from the database |
|
159 //It should work and the template must be marked as deleted |
|
160 templ = iCntTestImpl.ReadLC(templId, *iMatchAll); |
|
161 TESTTRUE(templ->IsDeleted()); |
|
162 POPD(templ); templ = NULL; |
|
163 |
|
164 //Delete the only contact, based on the user template |
|
165 TESTTRAP(iCntTestImpl.DeleteL(createdEntryId)); |
|
166 |
|
167 //Because the contact was the only thing dependant on the template |
|
168 //Template was deleted also |
|
169 TRAPD(err, iCntTestImpl.ReadLC(templId, *iMatchAll); POPD(templ);); |
|
170 TESTVALUE(err, KErrNotFound); |
|
171 } |
|
172 |
|
173 void CPersistenceTests::AccessCountL() |
|
174 { |
|
175 test.Next(_L("Access Count test")); |
|
176 static const TInt KAccessReps = 10; |
|
177 TInt i = 0; |
|
178 const CContactTemplate& goldenTemplate = iCntTestImpl.GetSysTemplate(); |
|
179 |
|
180 //Create a contact and set Acces Count to 10. |
|
181 CContactItem* card = CContactCard::NewLC(&goldenTemplate); |
|
182 TCnt theCnt(card); |
|
183 |
|
184 theCnt[KUidContactFieldGivenName] = _L("Sample"); |
|
185 theCnt[KUidContactFieldFamilyName] = _L("Test1"); |
|
186 theCnt[KUidContactFieldPhoneNumber] & KHome & KVoice & KCell = _L("mo1 7700900333"); |
|
187 theCnt[KUidContactFieldEMail] & KHome = _L("test@email"); |
|
188 theCnt[KUidContactFieldAddress] & KHome = _L("Home addresssssss"); |
|
189 // theCnt[KUidContactFieldLocality] & KHome = _L("Rome"); |
|
190 |
|
191 for(i = 0; i < KAccessReps; ++i ) |
|
192 { |
|
193 card->IncAccessCount(); |
|
194 } |
|
195 TESTTRUE(card->AccessCount() == KAccessReps);; |
|
196 iCntTestImpl.CreateL(*card); |
|
197 const TInt createdEntryId = card->Id(); |
|
198 POPD(card); |
|
199 |
|
200 //Check is Access cound was saved |
|
201 card = iCntTestImpl.ReadLC(createdEntryId, *iMatchAll); |
|
202 TESTTRUE(card->AccessCount() == KAccessReps);; |
|
203 POPD(card); |
|
204 |
|
205 //Try to delete entry 10 times |
|
206 for(i = 0; i < KAccessReps; ++i ) |
|
207 { |
|
208 iCntTestImpl.DeleteL(createdEntryId); |
|
209 } |
|
210 //Delete doesn't physically delete an entry, is simply marks is as deleted. |
|
211 |
|
212 //Check is Access count was saved, set it back to 0 and update |
|
213 card = iCntTestImpl.OpenLC(createdEntryId, *iMatchAll); |
|
214 TESTTRUE(card->IsDeleted()); |
|
215 TESTTRUE(card->AccessCount() == KAccessReps);; |
|
216 for(i = 0; i < KAccessReps; ++i ) |
|
217 { |
|
218 card->DecAccessCount(); |
|
219 } |
|
220 |
|
221 iCntTestImpl.UpdateL(*card); //The contact is actually deleted here |
|
222 POPD(card); //because the access count is now 0 |
|
223 |
|
224 //The contact should not be there anymore |
|
225 TRAPD(err, card = iCntTestImpl.ReadLC(createdEntryId, *iMatchAll)); |
|
226 TESTTRUE(err == KErrNotFound); |
|
227 } |
|
228 |
|
229 |
|
230 void CPersistenceTests::DuplicatedFieldUidsL() |
|
231 { |
|
232 CContactItem* cntItem = iCntTestImpl.OpenLC(1, *iMatchAll); |
|
233 TCnt theCnt(cntItem); |
|
234 #ifdef __T_PERSISTENCELAYER_DUMP_CONTACT__ |
|
235 TESTTRAP(iCntTestImpl.DumpContactL(*cntItem, _L("Before UID field"))); |
|
236 #endif |
|
237 |
|
238 theCnt[KUidContactFieldPhoneNumber] & KWork & KPager = _L("New work pager"); |
|
239 |
|
240 iCntTestImpl.UpdateL(*cntItem); |
|
241 |
|
242 #ifdef __T_PERSISTENCELAYER_DUMP_CONTACT__ |
|
243 TESTTRAP(iCntTestImpl.DumpContactL(*cntItem, _L("After UID field"))); |
|
244 #endif |
|
245 |
|
246 TPtrC phone = theCnt[KUidContactFieldPhoneNumber] & KWork & KPager; |
|
247 |
|
248 POPD(cntItem); |
|
249 } |
|
250 |
|
251 |
|
252 // Implementation of CPersistenceTests member functions |
|
253 |
|
254 void CPersistenceTests::FileCreationL() |
|
255 { |
|
256 test.Next(_L("File creation test")); |
|
257 |
|
258 #ifndef __SYMBIAN_CNTMODEL_USE_SQLITE__ |
|
259 TRAPD(err,iCntTestImpl.CreateDatabaseL(_L("JustAFilename.ext"), ETrue)); |
|
260 TESTVALUE(err, KErrBadName); //The filename MUST contain a drive name |
|
261 #endif |
|
262 |
|
263 iCntTestImpl.CreateDatabaseL(KCrudTestDbFile, ETrue); |
|
264 const CContactTemplate& goldenTemplate = iCntTestImpl.GetSysTemplate(); |
|
265 |
|
266 #ifdef __T_PERSISTENCELAYER_DUMP_CONTACT__ |
|
267 TESTTRAP(iCntTestImpl.DumpContactL(goldenTemplate, _L("Template"))); |
|
268 #endif |
|
269 |
|
270 CContactItem* card = CContactCard::NewLC(&goldenTemplate); |
|
271 TBuf<10> uidStr(_L("UidString")); |
|
272 card->SetUidStringL(uidStr); |
|
273 TCnt theCnt(card); |
|
274 |
|
275 theCnt[KUidContactFieldGivenName] = _L("Example1"); |
|
276 theCnt[KUidContactFieldFamilyName] = _L("NameL"); |
|
277 |
|
278 theCnt[KUidContactFieldPhoneNumber] & KHome & KVoice & KCell = _L("mo1 7700900333"); |
|
279 theCnt[KUidContactFieldPhoneNumber] & KHome & KVoice & KCell += _L("mo2 34530903495803948503984545"); |
|
280 |
|
281 theCnt[KUidContactFieldEMail] & KHome = _L("home@email"); |
|
282 theCnt[KUidContactFieldAddress] & KHome = _L("Home addresssssss"); |
|
283 theCnt[KUidContactFieldLocality] & KHome = _L("Glazgo"); |
|
284 theCnt[KUidContactFieldIMAddress] & KHome & KWv = _L("wireless@village"); |
|
285 |
|
286 //If the code fails on this line, you most likely haven't built the cnttutil |
|
287 //test library that create the test version of the system template cntmodel.rsc |
|
288 theCnt[KUidContactFieldSecondName] = _L("Second name"); |
|
289 |
|
290 theCnt[KUidContactFieldCompanyName] = _L("Test"); |
|
291 theCnt[KUidContactFieldJobTitle] = _L("Name1"); |
|
292 theCnt[KUidContactFieldPhoneNumber] & KWork & KVoice = _L("work Tel 12345"); |
|
293 |
|
294 theCnt[KUidContactFieldEMail] & KWork = _L("work@email"); |
|
295 theCnt[KUidContactFieldUrl] & KWork = _L("sdfsd"); |
|
296 theCnt[KUidContactFieldAddress] & KWork = _L("afas df asd"); |
|
297 theCnt[KUidContactFieldLocality] & KWork = _L("sdfsd"); |
|
298 |
|
299 theCnt[KUidContactFieldCustom1] = _L("Filterable 1"); |
|
300 theCnt[KUidContactFieldCustom2] = _L("Filterable 2"); |
|
301 |
|
302 theCnt[KUidContactFieldGivenNamePronunciation] = _L("first name re"); |
|
303 theCnt[KUidContactFieldFamilyNamePronunciation] = _L("Last name re"); |
|
304 |
|
305 theCnt[KUidContactFieldSIPID] & KPoc = _L("SIP POC"); |
|
306 theCnt[KUidContactFieldSIPID] & KSwis = _L("SIP SWIS"); |
|
307 theCnt[KUidContactFieldSIPID] & KVoip = _L("SIP VOIP"); |
|
308 |
|
309 #ifdef __T_PERSISTENCELAYER_DUMP_CONTACT__ |
|
310 TESTTRAP(iCntTestImpl.DumpContactL(*card, _L("Before Creation"))); |
|
311 #endif |
|
312 iCntTestImpl.CreateL(*card); |
|
313 POPD(card); |
|
314 |
|
315 card = CContactCard::NewLC(&goldenTemplate); |
|
316 theCnt[KUidContactFieldGivenName] = _L("Sample"); |
|
317 theCnt[KUidContactFieldFamilyName] = _L("Test"); |
|
318 theCnt[KUidContactFieldCompanyName] = _L("SYMBIANFOUNDATION"); |
|
319 theCnt[KUidContactFieldJobTitle] = _L("Test"); |
|
320 theCnt[KUidContactFieldPhoneNumber] & KHome & KVoice & KCell = _L("tel. 7700900333"); |
|
321 iCntTestImpl.CreateL(*card); |
|
322 POPD(card); |
|
323 |
|
324 //Create a group |
|
325 CContactGroup* group1 = iCntTestImpl.CreateGroupLC(_L("MyGroup1")); |
|
326 POPD(group1); |
|
327 } |
|
328 |
|
329 void CPersistenceTests::ViewDefsMaskL() |
|
330 { |
|
331 test.Next(_L("View Definition with Masks")); |
|
332 |
|
333 #ifdef __T_PERSISTENCELAYER_DUMP_CONTACT__ |
|
334 TESTTRAP(iCntTestImpl.PrintCntForViewL(_L("Full"), *iMatchAll)); |
|
335 #endif |
|
336 |
|
337 //ViewDefinition with masking of normal fields |
|
338 CContactItemViewDef* viewDef0 = CContactItemViewDef::NewLC( CContactItemViewDef::EMaskFields, |
|
339 CContactItemViewDef::EIncludeHiddenFields); |
|
340 |
|
341 #ifdef __T_PERSISTENCELAYER_DUMP_CONTACT__ |
|
342 TESTTRAP(iCntTestImpl.PrintCntForViewL(_L("MaskFields_nothing"), *viewDef0)); |
|
343 #endif |
|
344 |
|
345 viewDef0->AddL(KUidContactFieldGivenName); |
|
346 #ifdef __T_PERSISTENCELAYER_DUMP_CONTACT__ |
|
347 TESTTRAP(iCntTestImpl.PrintCntForViewL(_L("Mask_GivenName"), *viewDef0)); |
|
348 #endif |
|
349 |
|
350 viewDef0->AddL(KUidContactFieldPhoneNumber); |
|
351 #ifdef __T_PERSISTENCELAYER_DUMP_CONTACT__ |
|
352 TESTTRAP(iCntTestImpl.PrintCntForViewL(_L("Mask_GNameAndPhones"), *viewDef0)); |
|
353 #endif |
|
354 |
|
355 viewDef0->AddL(KUidContactFieldEMail); |
|
356 #ifdef __T_PERSISTENCELAYER_DUMP_CONTACT__ |
|
357 TESTTRAP(iCntTestImpl.PrintCntForViewL(_L("Mask_GNamePhonesAndEmails"), *viewDef0)); |
|
358 #endif |
|
359 |
|
360 viewDef0->Remove(2); |
|
361 viewDef0->Remove(1); |
|
362 viewDef0->Remove(0); |
|
363 |
|
364 viewDef0->AddL(KHome); |
|
365 #ifdef __T_PERSISTENCELAYER_DUMP_CONTACT__ |
|
366 TESTTRAP(iCntTestImpl.PrintCntForViewL(_L("Mask_Home"), *viewDef0)); |
|
367 #endif |
|
368 viewDef0->Remove(0); |
|
369 |
|
370 POPD(viewDef0); |
|
371 |
|
372 |
|
373 //ViewDefinition with masking of hidden fields |
|
374 CContactItemViewDef* viewDef1 = CContactItemViewDef::NewLC( CContactItemViewDef::EIncludeFields, |
|
375 CContactItemViewDef::EMaskHiddenFields); |
|
376 |
|
377 viewDef1->AddL(KUidContactFieldGivenName); |
|
378 #ifdef __T_PERSISTENCELAYER_DUMP_CONTACT__ |
|
379 TESTTRAP(iCntTestImpl.PrintCntForViewL(_L("OnlyGivenName_noH"), *viewDef1)); |
|
380 #endif |
|
381 viewDef1->Remove(0); |
|
382 |
|
383 viewDef1->AddL(KUidContactFieldPicture); |
|
384 #ifdef __T_PERSISTENCELAYER_DUMP_CONTACT__ |
|
385 TESTTRAP(iCntTestImpl.PrintCntForViewL(_L("noH_Photo"), *viewDef1)); |
|
386 #endif |
|
387 viewDef1->Remove(0); |
|
388 POPD(viewDef1); |
|
389 |
|
390 //todo: add more testing for hidden fields. |
|
391 } |
|
392 |
|
393 |
|
394 |
|
395 void CPersistenceTests::ViewDefsInclL() |
|
396 { |
|
397 test.Next(_L("View Definition with Inclusions")); |
|
398 |
|
399 CContactItem* cntItem = NULL; |
|
400 |
|
401 //ViewDefinition with inclusion |
|
402 CContactItemViewDef* viewDef1 = CContactItemViewDef::NewLC(CContactItemViewDef::EIncludeFields,CContactItemViewDef::EIncludeHiddenFields); |
|
403 |
|
404 cntItem = iCntTestImpl.ReadMinimalLC(1); |
|
405 |
|
406 #ifdef __T_PERSISTENCELAYER_DUMP_CONTACT__ |
|
407 TESTTRAP(iCntTestImpl.DumpContactL(*cntItem, _L("Minimal"))); |
|
408 #endif |
|
409 |
|
410 POPD(cntItem); |
|
411 |
|
412 #ifdef __T_PERSISTENCELAYER_DUMP_CONTACT__ |
|
413 TESTTRAP(iCntTestImpl.PrintCntForViewL(_L("Full"), *iMatchAll)); |
|
414 #endif |
|
415 |
|
416 viewDef1->AddL(KUidContactFieldPhoneNumber); |
|
417 #ifdef __T_PERSISTENCELAYER_DUMP_CONTACT__ |
|
418 TESTTRAP(iCntTestImpl.PrintCntForViewL(_L("OnlyPhones"), *viewDef1)); |
|
419 #endif |
|
420 viewDef1->Remove(0); |
|
421 |
|
422 viewDef1->AddL(KUidContactFieldAddress); |
|
423 #ifdef __T_PERSISTENCELAYER_DUMP_CONTACT__ |
|
424 TESTTRAP(iCntTestImpl.PrintCntForViewL(_L("OnlyAddress"), *viewDef1)); |
|
425 #endif |
|
426 viewDef1->Remove(0); |
|
427 |
|
428 viewDef1->AddL(KUidContactFieldGivenName); |
|
429 #ifdef __T_PERSISTENCELAYER_DUMP_CONTACT__ |
|
430 TESTTRAP(iCntTestImpl.PrintCntForViewL(_L("OnlyGivenName"), *viewDef1)); |
|
431 #endif |
|
432 viewDef1->Remove(0); |
|
433 |
|
434 viewDef1->AddL(KUidContactFieldEMail); |
|
435 #ifdef __T_PERSISTENCELAYER_DUMP_CONTACT__ |
|
436 TESTTRAP(iCntTestImpl.PrintCntForViewL(_L("OnlyEmails"), *viewDef1)); |
|
437 #endif |
|
438 viewDef1->AddL(KUidContactFieldPhoneNumber); |
|
439 #ifdef __T_PERSISTENCELAYER_DUMP_CONTACT__ |
|
440 TESTTRAP(iCntTestImpl.PrintCntForViewL(_L("Emails_and_Phones"), *viewDef1)); |
|
441 #endif |
|
442 viewDef1->AddL(KUidContactFieldFamilyName); |
|
443 #ifdef __T_PERSISTENCELAYER_DUMP_CONTACT__ |
|
444 TESTTRAP(iCntTestImpl.PrintCntForViewL(_L("EmailsPhonesAndFamilyName"), *viewDef1)); |
|
445 #endif |
|
446 viewDef1->Remove(2); |
|
447 viewDef1->Remove(1); |
|
448 viewDef1->Remove(0); |
|
449 |
|
450 viewDef1->AddL(KUidContactFieldBirthday); |
|
451 #ifdef __T_PERSISTENCELAYER_DUMP_CONTACT__ |
|
452 TESTTRAP(iCntTestImpl.PrintCntForViewL(_L("OnlyBirthday"), *viewDef1)); |
|
453 #endif |
|
454 viewDef1->Remove(0); |
|
455 |
|
456 viewDef1->AddL(KUidContactFieldPicture); |
|
457 #ifdef __T_PERSISTENCELAYER_DUMP_CONTACT__ |
|
458 TESTTRAP(iCntTestImpl.PrintCntForViewL(_L("OnlyPicture"), *viewDef1)); |
|
459 #endif |
|
460 viewDef1->Remove(0); |
|
461 |
|
462 |
|
463 POPD(viewDef1); |
|
464 } |
|
465 |
|
466 |
|
467 |
|
468 void CPersistenceTests::GroupsL() |
|
469 { |
|
470 test.Next(_L("Groups testing")); |
|
471 |
|
472 //Create a new group |
|
473 CContactGroup* group1 = iCntTestImpl.CreateGroupLC(_L("NewGroupLabel")); //>>> |
|
474 const TContactItemId newGroupID = group1->Id(); |
|
475 #ifdef __T_PERSISTENCELAYER_DUMP_CONTACT__ |
|
476 TESTTRAP(iCntTestImpl.DumpContactL(*group1, _L("NewGroup_created"))); |
|
477 #endif |
|
478 |
|
479 //Add existing contact to the group |
|
480 iCntTestImpl.GroupAddAndRemove(*group1, 1, -1); |
|
481 #ifdef __T_PERSISTENCELAYER_DUMP_CONTACT__ |
|
482 TESTTRAP(iCntTestImpl.DumpContactL(*group1, _L("GroupWithContAdded"))); |
|
483 #endif |
|
484 |
|
485 //Add another existing contact to the groups |
|
486 iCntTestImpl.GroupAddAndRemove(*group1, 2, -1); |
|
487 #ifdef __T_PERSISTENCELAYER_DUMP_CONTACT__ |
|
488 TESTTRAP(iCntTestImpl.DumpContactL(*group1, _L("GroupWithCont2Added"))); |
|
489 #endif |
|
490 |
|
491 //Add the created group to an existing group |
|
492 CContactGroup* group3 = static_cast<CContactGroup*>(iCntTestImpl.ReadLC(3, *iMatchAll)); //>>> |
|
493 #ifdef __T_PERSISTENCELAYER_DUMP_CONTACT__ |
|
494 TESTTRAP(iCntTestImpl.DumpContactL(*group3, _L("ExitstingGroup3"))); |
|
495 #endif |
|
496 iCntTestImpl.GroupAddAndRemove(*group3, group1->Id(), -1); |
|
497 POPD(group3); //<<< |
|
498 POPD(group1); //<<< |
|
499 |
|
500 //Print the existing group contents |
|
501 group3 = static_cast<CContactGroup*>(iCntTestImpl.ReadLC(3, *iMatchAll)); //>>> |
|
502 #ifdef __T_PERSISTENCELAYER_DUMP_CONTACT__ |
|
503 TESTTRAP(iCntTestImpl.DumpContactL(*group3, _L("Group3AddedGroup1"))); |
|
504 #endif |
|
505 POPD(group3); //<<< |
|
506 |
|
507 //Delete one of the contacts, belonging to the newly created group |
|
508 iCntTestImpl.DeleteL(2); |
|
509 group1 = static_cast<CContactGroup*>(iCntTestImpl.ReadLC(newGroupID, *iMatchAll)); //>>> |
|
510 #ifdef __T_PERSISTENCELAYER_DUMP_CONTACT__ |
|
511 TESTTRAP(iCntTestImpl.DumpContactL(*group1, _L("GroupWithContRemoved"))); |
|
512 #endif |
|
513 POPD(group1); //<<< |
|
514 |
|
515 //Delete new group |
|
516 iCntTestImpl.DeleteL(newGroupID); |
|
517 group3 = static_cast<CContactGroup*>(iCntTestImpl.ReadLC(3, *iMatchAll)); //>>> |
|
518 #ifdef __T_PERSISTENCELAYER_DUMP_CONTACT__ |
|
519 TESTTRAP(iCntTestImpl.DumpContactL(*group3, _L("Group3-Group1WasDeleted"))); |
|
520 #endif |
|
521 // |
|
522 |
|
523 TRAPD(err, iCntTestImpl.GroupAddAndRemove(*group3, 238, -1)); |
|
524 TESTVALUE(err, KErrNotFound); |
|
525 TRAP(err, iCntTestImpl.GroupAddAndRemove(*group3, -1, 1257)); |
|
526 TESTVALUE(err, KErrNotFound); |
|
527 |
|
528 POPD(group3); //<<< |
|
529 } |
|
530 |
|
531 |
|
532 void CPersistenceTests::BasicCRUDL() |
|
533 { |
|
534 test.Next(_L("Basic CRUD test")); |
|
535 |
|
536 |
|
537 test.Printf(_L("Reading Template\n")); |
|
538 CContactItem* cntItem = iCntTestImpl.ReadMinimalLC(0); |
|
539 #ifdef __T_PERSISTENCELAYER_DUMP_CONTACT__ |
|
540 TESTTRAP(iCntTestImpl.DumpContactL(*cntItem, _L("GoldenTempl"))); |
|
541 #endif |
|
542 POPD(cntItem); |
|
543 |
|
544 test.Printf(_L("Reading First contact\n")); |
|
545 cntItem = iCntTestImpl.ReadMinimalLC(1); |
|
546 #ifdef __T_PERSISTENCELAYER_DUMP_CONTACT__ |
|
547 TESTTRAP(iCntTestImpl.DumpContactL(*cntItem, _L("Contact_1"))); |
|
548 #endif |
|
549 |
|
550 TCnt theCnt2(cntItem); |
|
551 |
|
552 theCnt2[KUidContactFieldPhoneNumber] & KHome & KVoice & KCell = _L("456456456"); |
|
553 theCnt2[KUidContactFieldPhoneNumber] & KWork & KVoice = _L("456456456"); |
|
554 |
|
555 //Note that we are trying to create a contact, based on another conact which |
|
556 //was read using ReadMinimal API. This API doest read template information |
|
557 //So the newly created contact will not be bases on any template |
|
558 //(even not on Golden Template e.i. TemplateRefId() == 0) |
|
559 test.Printf(_L("Create new contact\n")); |
|
560 TContactItemId newItemId = 0; |
|
561 TESTTRAP(newItemId = iCntTestImpl.CreateL(*cntItem)); |
|
562 #ifdef __T_PERSISTENCELAYER_DUMP_CONTACT__ |
|
563 TESTTRAP(iCntTestImpl.DumpContactL(*cntItem, _L("InMemoryAfterCreation"))); |
|
564 #endif |
|
565 POPD(cntItem); |
|
566 |
|
567 test.Printf(_L("Reading Created contact\n")); |
|
568 cntItem = iCntTestImpl.OpenLC(newItemId, *iMatchAll); |
|
569 #ifdef __T_PERSISTENCELAYER_DUMP_CONTACT__ |
|
570 TESTTRAP(iCntTestImpl.DumpContactL(*cntItem, _L("Created_ReadFromDb"))); |
|
571 #endif |
|
572 |
|
573 TCnt theCnt3(cntItem); |
|
574 theCnt3[KUidContactFieldGivenName] = _L("new Given Name"); |
|
575 theCnt3[KUidContactFieldPhoneNumber] & KWork & KVoice = _L("123123123"); |
|
576 theCnt3[KUidContactFieldPhoneNumber] & KWork & KVoice & KCell += _L("123123123"); |
|
577 theCnt3[KUidContactFieldEMail] & KHome = _L("new@home"); |
|
578 theCnt3[KUidContactFieldAddress] & KHome = _L("new home address"); |
|
579 |
|
580 test.Printf(_L("Update contact\n")); |
|
581 #ifdef __T_PERSISTENCELAYER_DUMP_CONTACT__ |
|
582 TESTTRAP(iCntTestImpl.DumpContactL(*cntItem, _L("BeforeUpdate"))); |
|
583 #endif |
|
584 TESTTRAP(iCntTestImpl.UpdateL(*cntItem)); |
|
585 #ifdef __T_PERSISTENCELAYER_DUMP_CONTACT__ |
|
586 TESTTRAP(iCntTestImpl.DumpContactL(*cntItem, _L("AfterUpdate"))); |
|
587 #endif |
|
588 POPD(cntItem); |
|
589 |
|
590 test.Printf(_L("Reading Updated contact\n")); |
|
591 cntItem = iCntTestImpl.ReadMinimalLC(newItemId); |
|
592 #ifdef __T_PERSISTENCELAYER_DUMP_CONTACT__ |
|
593 TESTTRAP(iCntTestImpl.DumpContactL(*cntItem, _L("Updated_ReadFromDb"))); |
|
594 #endif |
|
595 |
|
596 iCntTestImpl.DeleteL(cntItem->Id()); |
|
597 |
|
598 POPD(cntItem); |
|
599 } |
|
600 |
|
601 |
|
602 //Persistence test construction and destruction |
|
603 CPersistenceTests* CPersistenceTests::NewLC (CCntTestImplementor& aCntTestImpl) |
|
604 { |
|
605 CPersistenceTests* self = new (ELeave) CPersistenceTests(aCntTestImpl); |
|
606 CleanupStack::PushL(self); |
|
607 |
|
608 self->ConstructL(); |
|
609 |
|
610 return self; |
|
611 } |
|
612 |
|
613 void CPersistenceTests::ConstructL() |
|
614 { |
|
615 iMatchAll = CContactItemViewDef::NewLC(CContactItemViewDef::EIncludeFields,CContactItemViewDef::EIncludeHiddenFields); |
|
616 iMatchAll->AddL(KUidContactFieldMatchAll); |
|
617 CleanupStack::Pop(iMatchAll); |
|
618 } |
|
619 |
|
620 CPersistenceTests::~CPersistenceTests() |
|
621 { |
|
622 delete iMatchAll; |
|
623 iMatchAll = NULL; |
|
624 } |
|
625 |
|
626 /** |
|
627 |
|
628 @SYMTestCaseID PIM-T-PERSISTENCELAYER-0001 |
|
629 |
|
630 */ |
|
631 |
|
632 LOCAL_C void DoTestsL() |
|
633 { |
|
634 CleanupClosePushL(test); |
|
635 CPersistenceTests* cntTester = NULL; |
|
636 test.Start(_L("@SYMTestCaseID:PIM-T-PERSISTENCELAYER-0001 Persistency tests")); |
|
637 |
|
638 RPIMTestServer serv; |
|
639 User::LeaveIfError(serv.Connect()); |
|
640 |
|
641 #ifdef RUN_PL |
|
642 |
|
643 test.Start(_L("Persistence Layer Tests")); |
|
644 __UHEAP_MARK; |
|
645 CPlTestImpl* plCntTestImpl = CPlTestImpl::NewLC(); |
|
646 cntTester = CPersistenceTests::NewLC(*plCntTestImpl); |
|
647 cntTester->AllTestsL(); |
|
648 test(__NB_failures == 0); |
|
649 |
|
650 POPD(cntTester); |
|
651 CleanupStack::PopAndDestroy(plCntTestImpl); |
|
652 plCntTestImpl = NULL; |
|
653 test.End(); |
|
654 __UHEAP_MARKEND; |
|
655 |
|
656 #endif |
|
657 |
|
658 #ifdef RUN_CNT |
|
659 |
|
660 test.Start(_L("Contact model tests")); |
|
661 __UHEAP_MARK; |
|
662 CCntTestImpl* oldCntTestImpl = CCntTestImpl::NewLC(); |
|
663 |
|
664 cntTester = CPersistenceTests::NewLC(*oldCntTestImpl); |
|
665 cntTester->AllTestsL(); |
|
666 POPD(cntTester); |
|
667 test(__NB_failures == 0); |
|
668 |
|
669 CleanupStack::PopAndDestroy(oldCntTestImpl); |
|
670 oldCntTestImpl = NULL; |
|
671 test.End(); |
|
672 __UHEAP_MARKEND; |
|
673 User::After(1500000); |
|
674 #endif |
|
675 |
|
676 serv.Close(); |
|
677 test.End(); |
|
678 CleanupStack::PopAndDestroy(1); // test.Close |
|
679 |
|
680 } |
|
681 |
|
682 |
|
683 |
|
684 |
|
685 GLDEF_C TInt E32Main() |
|
686 { |
|
687 // Init |
|
688 CTrapCleanup* cleanupStack = CTrapCleanup::New(); |
|
689 if (!cleanupStack) |
|
690 { |
|
691 return KErrNoMemory; |
|
692 } |
|
693 |
|
694 CActiveScheduler* activeScheduler = new CActiveScheduler; |
|
695 if (!activeScheduler) |
|
696 { |
|
697 return KErrNoMemory; |
|
698 } |
|
699 CActiveScheduler::Install(activeScheduler); |
|
700 |
|
701 // Run the tests |
|
702 __UHEAP_MARK; |
|
703 TRAPD(err, DoTestsL()); |
|
704 test(err == KErrNone); |
|
705 TRAP_IGNORE(CContactDatabase::DeleteDatabaseL(KCrudTestDbFile) ); |
|
706 __UHEAP_MARKEND; |
|
707 |
|
708 |
|
709 // Cleanup |
|
710 delete activeScheduler; |
|
711 delete cleanupStack; |
|
712 activeScheduler = NULL; |
|
713 cleanupStack = NULL; |
|
714 |
|
715 return err; |
|
716 } |
|
717 |
|
718 |