|
1 // Copyright (c) 2000-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 <e32std.h> |
|
17 #include <e32test.h> |
|
18 #include <cntdb.h> |
|
19 #include <cntitem.h> |
|
20 #include <cntfldst.h> |
|
21 #include "t_utils2.h" |
|
22 #include "t_filterview.h" |
|
23 #include "T_UTILS.H" |
|
24 |
|
25 // |
|
26 // Constants. |
|
27 // |
|
28 |
|
29 _LIT(KTestName,"t_filterview"); |
|
30 _LIT(KLogFileName,"t_filterview.log"); |
|
31 |
|
32 _LIT(KDbFileName,"c:t_filterview.cdb"); |
|
33 |
|
34 _LIT(KRemoteViewName,"RemoteView"); |
|
35 _LIT(KTextDefSeparator,""); |
|
36 |
|
37 LOCAL_D RTest test(KTestName); |
|
38 |
|
39 const TInt KNumSmsContacts = 111; |
|
40 const TInt KNumWorkEmailContacts = 121; |
|
41 const TInt KNumHomeEmailContacts = 131; |
|
42 const TInt KNumLandlineContacts = 141; |
|
43 const TInt KNumFaxContacts = 151; |
|
44 const TInt KNumRingTone = 161; |
|
45 const TInt KNumVoiceDial = 171; |
|
46 |
|
47 const TInt KNumIMProtocolWV = 53; |
|
48 const TInt KNumIMAddress= KNumIMProtocolWV; |
|
49 |
|
50 const TInt KNumPhonable = KNumSmsContacts + KNumLandlineContacts + KNumFaxContacts; |
|
51 const TInt KNumUnfiltered = KNumSmsContacts |
|
52 + KNumWorkEmailContacts |
|
53 + KNumHomeEmailContacts |
|
54 + KNumLandlineContacts |
|
55 + KNumFaxContacts |
|
56 + KNumRingTone |
|
57 + KNumVoiceDial |
|
58 + KNumIMAddress; |
|
59 |
|
60 |
|
61 // |
|
62 // CTestConductor. |
|
63 // |
|
64 |
|
65 CTestConductor* CTestConductor::NewL() |
|
66 { |
|
67 CTestConductor* self=new(ELeave) CTestConductor(); |
|
68 CleanupStack::PushL(self); |
|
69 self->ConstructL(); |
|
70 self->RunTestsL(); |
|
71 CleanupStack::Pop(); |
|
72 return self; |
|
73 } |
|
74 |
|
75 CTestConductor::~CTestConductor() |
|
76 { |
|
77 delete iLog; |
|
78 delete iDb; |
|
79 delete iRandomGenerator; |
|
80 TRAP_IGNORE(CContactDatabase::DeleteDatabaseL(KDbFileName)); |
|
81 |
|
82 iFs.Close(); |
|
83 CCntTest::ProfileReset(0,1); // ensure the profiling 'TLS' used in EKA2 is freed |
|
84 } |
|
85 |
|
86 CTestConductor::CTestConductor() {} |
|
87 |
|
88 void CTestConductor::ConstructL() |
|
89 { |
|
90 User::LeaveIfError(iFs.Connect()); |
|
91 iLog=CLog::NewL(test,KLogFileName); |
|
92 iDb=CContactDatabase::ReplaceL(KDbFileName); |
|
93 iRandomGenerator=CRandomContactGenerator::NewL(); |
|
94 iRandomGenerator->SetDbL(*iDb); |
|
95 AddContactsL(); |
|
96 } |
|
97 |
|
98 void CTestConductor::AddContactL(TInt aBitwiseFilterType) |
|
99 { |
|
100 test.Printf(_L("Adding Contact")); |
|
101 iRandomGenerator->AddTypicalContactForFilterL(aBitwiseFilterType); |
|
102 iTotalContacts++; |
|
103 } |
|
104 |
|
105 void CTestConductor::AddContactsThatMatchFilterL(TInt aNumberOfContacts, TInt aFilter) |
|
106 { |
|
107 test.Printf(_L("Adding %d contacts which match filter 0x%X : "), aNumberOfContacts, aFilter); |
|
108 TInt counter = 0; |
|
109 for (counter = 0; counter < aNumberOfContacts; counter++) |
|
110 { |
|
111 if(aFilter & CContactDatabase::EWirelessVillage) |
|
112 { |
|
113 iRandomGenerator->AddTypicalContactForFilterL(aFilter, KUidContactFieldVCardMapWV); |
|
114 } |
|
115 else |
|
116 { |
|
117 iRandomGenerator->AddTypicalContactForFilterL(aFilter); |
|
118 } |
|
119 iTotalContacts++; |
|
120 } |
|
121 test.Printf(_L("Done\n")); |
|
122 } |
|
123 |
|
124 void CTestConductor::AddContactsL() |
|
125 { |
|
126 iTotalContacts=0; |
|
127 test.Printf(_L("Adding \n")); |
|
128 |
|
129 AddContactsThatMatchFilterL(KNumSmsContacts, CContactDatabase::ESmsable); |
|
130 AddContactsThatMatchFilterL(KNumWorkEmailContacts, CContactDatabase::EMailable); |
|
131 AddContactsThatMatchFilterL(KNumHomeEmailContacts, CContactDatabase::EMailable | CContactDatabase::EHome); |
|
132 AddContactsThatMatchFilterL(KNumLandlineContacts, CContactDatabase::ELandLine); |
|
133 AddContactsThatMatchFilterL(KNumFaxContacts, CContactDatabase::EFaxable); |
|
134 AddContactsThatMatchFilterL(KNumRingTone, CContactDatabase::ERingTone); |
|
135 AddContactsThatMatchFilterL(KNumVoiceDial, CContactDatabase::EVoiceDial); |
|
136 AddContactsThatMatchFilterL(KNumIMProtocolWV, /*CContactDatabase::EIMAddress |*/ CContactDatabase::EWirelessVillage); |
|
137 } |
|
138 |
|
139 void CTestConductor::RunTestsL() |
|
140 { |
|
141 CViewTester* tester=CViewTester::NewL(*iLog,*iDb,this); |
|
142 CleanupStack::PushL(tester); |
|
143 CActiveScheduler::Start(); |
|
144 CleanupStack::Pop(tester); |
|
145 |
|
146 User::LeaveIfError(iTestError); |
|
147 } |
|
148 |
|
149 |
|
150 void CTestConductor::SetTestError(TInt aTestError) |
|
151 { |
|
152 iTestError = aTestError; |
|
153 } |
|
154 |
|
155 |
|
156 // |
|
157 // CViewTester. |
|
158 // |
|
159 |
|
160 CViewTester* CViewTester::NewL(CLog& aLog,CContactDatabase& aDb,CTestConductor* aTestConductor) |
|
161 { |
|
162 CViewTester* self=new(ELeave) CViewTester(aLog,aDb,aTestConductor); |
|
163 CleanupStack::PushL(self); |
|
164 self->ConstructL(); |
|
165 CleanupStack::Pop(); |
|
166 return self; |
|
167 } |
|
168 |
|
169 CViewTester::~CViewTester() |
|
170 { |
|
171 iVoiceDialView->Close(*this); |
|
172 iRingToneView->Close(*this); |
|
173 iLandlineFilterView->Close(*this); |
|
174 iLandlineFilterView2Fields->Close(*this); |
|
175 iSmsFilterView->Close(*this); |
|
176 iEmailFilterView->Close(*this); |
|
177 iFaxFilterView->Close(*this); |
|
178 iPhonableFilterView->Close(*this); |
|
179 iWorkFilterView->Close(*this); |
|
180 iHomeFilterView->Close(*this); |
|
181 iUnfilteredView->Close(*this); |
|
182 iWirelessVillageView->Close(*this); |
|
183 iIMAddressView->Close(*this); |
|
184 iOOMIMAddressView->Close(*this); |
|
185 iNamedRemoteView->Close(*this); |
|
186 iSortOrder_1.Close(); |
|
187 iSortOrder_2.Close(); |
|
188 delete iTextDef; |
|
189 } |
|
190 |
|
191 CViewTester::CViewTester(CLog& aLog,CContactDatabase& aDb,CTestConductor* aTestConductor) |
|
192 : CActive(EPriorityStandard),iLog(aLog),iDb(aDb),iCurrentTest(-1),iTestConductor(aTestConductor) |
|
193 { |
|
194 CActiveScheduler::Add(this); |
|
195 } |
|
196 |
|
197 void CViewTester::ConstructL() |
|
198 { |
|
199 iSortOrder_1.AppendL(KUidContactFieldGivenName); |
|
200 iSortOrder_1.AppendL(KUidContactFieldFamilyName); |
|
201 iSortOrder_1.AppendL(KUidContactFieldCompanyName); |
|
202 |
|
203 iTextDef=CContactTextDef::NewL(); |
|
204 iTextDef->AppendL(TContactTextDefItem(KUidContactFieldGivenName,KTextDefSeparator)); |
|
205 iTextDef->AppendL(TContactTextDefItem(KUidContactFieldFamilyName,KTextDefSeparator)); |
|
206 iTextDef->AppendL(TContactTextDefItem(KUidContactFieldCompanyName,KTextDefSeparator)); |
|
207 |
|
208 iSortOrder_2.AppendL(KUidContactFieldCompanyName); |
|
209 iSortOrder_2.AppendL(KUidContactFieldFamilyName); |
|
210 iSortOrder_2.AppendL(KUidContactFieldGivenName); |
|
211 |
|
212 NextTest(); |
|
213 } |
|
214 |
|
215 void CViewTester::PrintTimeTaken(TInt aTime) |
|
216 { |
|
217 iScratchBuf.Format(_L("** Test Took [%ds%dus] **\n"), aTime/1000000, aTime%1000000); |
|
218 iLog.LogLine(iScratchBuf); |
|
219 //TBuf<100> buffer; |
|
220 //buffer.Format(_L(" Test Took [%ds%dus]\n"), aProfile.iTime/1000000, aProfile.iTime%1000000); |
|
221 //iLog.LogLine(buffer); |
|
222 } |
|
223 |
|
224 |
|
225 void CViewTester::PrintTotalTimeTaken() |
|
226 { |
|
227 TInt counter; |
|
228 TInt totalTime = 0; |
|
229 |
|
230 for (counter = 0; counter < ENumTests; counter++) |
|
231 { |
|
232 totalTime += iTimeForTestsToComplete[counter]; |
|
233 } |
|
234 |
|
235 iScratchBuf.Format(_L("** Total amount of time taken [%ds%dus] **"), totalTime/1000000, totalTime%1000000); |
|
236 iLog.LogLine(iScratchBuf); |
|
237 |
|
238 } |
|
239 |
|
240 CContactFilteredView* CViewTester::CreateFilterViewL() |
|
241 { |
|
242 CCntTest::ProfileReset(0,1); |
|
243 CCntTest::ProfileStart(0); |
|
244 return CContactFilteredView::NewL(*this,iDb,*iNamedRemoteView, iFilter); |
|
245 } |
|
246 |
|
247 void CViewTester::RunL() |
|
248 { |
|
249 switch (iCurrentTest) |
|
250 { |
|
251 case ECreateLocalView: |
|
252 iLog.LogLine(_L("=== Create Name Remote local view")); |
|
253 CCntTest::ProfileReset(0,1); |
|
254 CCntTest::ProfileStart(0); |
|
255 iNamedRemoteView=CContactNamedRemoteView::NewL(*this,KRemoteViewName,iDb,iSortOrder_1,EContactsOnly); |
|
256 break; |
|
257 case EExerciseLocalView: |
|
258 iLog.LogLine(_L("=== Exercise local view")); |
|
259 ExceriseViewL(*iNamedRemoteView); |
|
260 NextTest(); |
|
261 break; |
|
262 case ECreateLandlineFilterView: |
|
263 { |
|
264 iLog.LogLine(_L("=== Create Land line Filter View {CContactFilteredView}")); |
|
265 iFilter = CContactDatabase::ELandLine; |
|
266 iLandlineFilterView = CreateFilterViewL(); |
|
267 } |
|
268 break; |
|
269 case ETestLandlineFilterView: |
|
270 { |
|
271 iLog.LogLine(_L("==== Exercise ETestLandlineFilterView")); |
|
272 test(iLandlineFilterView->CountL()==KNumLandlineContacts); |
|
273 TestViewIndiciesL(*iLandlineFilterView); |
|
274 NextTest(); |
|
275 } |
|
276 break; |
|
277 case ECreateSmsFilterView: |
|
278 { |
|
279 iLog.LogLine(_L("==== Create SMS Filter View")); |
|
280 iFilter=CContactDatabase::ESmsable; |
|
281 iSmsFilterView=CreateFilterViewL(); |
|
282 } |
|
283 break; |
|
284 case ETestSmsFilterView: |
|
285 { |
|
286 iLog.LogLine(_L("==== Exercise ETestSmsFilterView")); |
|
287 test(iSmsFilterView->CountL()==KNumSmsContacts); |
|
288 TestViewIndiciesL(*iSmsFilterView); |
|
289 NextTest(); |
|
290 } |
|
291 break; |
|
292 case ECreateEmailFilterView: |
|
293 { |
|
294 iLog.LogLine(_L("==== Create Email Filter View")); |
|
295 iFilter=CContactDatabase::EMailable; |
|
296 iEmailFilterView=CreateFilterViewL(); |
|
297 } |
|
298 break; |
|
299 case ETestEmailFilterView: |
|
300 { |
|
301 iLog.LogLine(_L("==== Exercise ETestEmailFilterView")); |
|
302 CCntTest::ProfileReset(0,1); |
|
303 CCntTest::ProfileStart(0); |
|
304 test(iEmailFilterView->CountL()==KNumWorkEmailContacts+KNumHomeEmailContacts); |
|
305 TestViewIndiciesL(*iEmailFilterView); |
|
306 NextTest(); |
|
307 } |
|
308 break; |
|
309 case ECreateFaxFilterView: |
|
310 { |
|
311 iLog.LogLine(_L("==== Create Fax Filter View")); |
|
312 iFilter=CContactDatabase::EFaxable; |
|
313 iFaxFilterView=CreateFilterViewL(); |
|
314 } |
|
315 break; |
|
316 case ETestFaxFilterView: |
|
317 { |
|
318 iLog.LogLine(_L("==== Exercise ETestFaxFilterView")); |
|
319 test(iFaxFilterView->CountL()==KNumFaxContacts); |
|
320 TestViewIndiciesL(*iFaxFilterView); |
|
321 NextTest(); |
|
322 } |
|
323 break; |
|
324 case ECreatePhonableFilterView: |
|
325 { |
|
326 iLog.LogLine(_L("==== Create Phonable Filter View")); |
|
327 iFilter=CContactDatabase::EPhonable; |
|
328 iPhonableFilterView=CreateFilterViewL(); |
|
329 } |
|
330 break; |
|
331 case ECreateWorkFilterView: |
|
332 { |
|
333 iLog.LogLine(_L("==== Create Work Filter View")); |
|
334 iFilter=CContactDatabase::EWork; |
|
335 iFilter|=CContactDatabase::EMailable; |
|
336 iWorkFilterView=CreateFilterViewL(); |
|
337 } |
|
338 break; |
|
339 case ECreateHomeFilterView: |
|
340 { |
|
341 iLog.LogLine(_L("==== Create Home Filter View")); |
|
342 iFilter=CContactDatabase::EHome; |
|
343 iFilter|=CContactDatabase::EMailable; |
|
344 iHomeFilterView=CreateFilterViewL(); |
|
345 } |
|
346 break; |
|
347 case ECreateUnfilteredView: |
|
348 { |
|
349 iLog.LogLine(_L("==== Create Unfiltered Filter View")); |
|
350 iFilter=0; |
|
351 iUnfilteredView=CreateFilterViewL(); |
|
352 } |
|
353 break; |
|
354 |
|
355 case ECreateRingToneView: |
|
356 iLog.LogLine(_L("==== Create Unfiltered Filter View")); |
|
357 iFilter = CContactDatabase::ERingTone; |
|
358 CCntTest::ProfileReset(0,1); |
|
359 CCntTest::ProfileStart(0); |
|
360 iRingToneView = CreateFilterViewL(); |
|
361 break; |
|
362 |
|
363 case ECreateVoiceDialView: |
|
364 iLog.LogLine(_L("==== Create Unfiltered Filter View")); |
|
365 iFilter = CContactDatabase::EVoiceDial; |
|
366 iVoiceDialView = CreateFilterViewL(); |
|
367 break; |
|
368 |
|
369 case ECreateWirelessVillageAddressView: |
|
370 { |
|
371 iLog.LogLine(_L("==== Create WirelessVillage address view")); |
|
372 iFilter = CContactDatabase::EWirelessVillage; |
|
373 iWirelessVillageView = CreateFilterViewL(); |
|
374 } |
|
375 break; |
|
376 |
|
377 case ECreateIMAddressView: |
|
378 { |
|
379 iLog.LogLine(_L("==== Create IM address view")); |
|
380 iFilter = CContactDatabase::EIMAddress; |
|
381 iIMAddressView = CreateFilterViewL(); |
|
382 } |
|
383 break; |
|
384 |
|
385 case ETestPhonableFilterView: |
|
386 { |
|
387 iLog.LogLine(_L("==== Exercise ETestPhonableFilterView")); |
|
388 test(iPhonableFilterView->CountL()==KNumPhonable); |
|
389 TestViewIndiciesL(*iPhonableFilterView); |
|
390 NextTest(); |
|
391 } |
|
392 break; |
|
393 case ETestWorkFilterView: |
|
394 { |
|
395 iLog.LogLine(_L("==== Exercise ETestWorkFilterView")); |
|
396 test(iWorkFilterView->CountL()==KNumWorkEmailContacts); |
|
397 TestViewIndiciesL(*iWorkFilterView); |
|
398 NextTest(); |
|
399 } |
|
400 break; |
|
401 case ETestHomeFilterView: |
|
402 { |
|
403 iLog.LogLine(_L("==== Exercise ETestHomeFilterView")); |
|
404 test(iHomeFilterView->CountL()==KNumHomeEmailContacts); |
|
405 TestViewIndiciesL(*iHomeFilterView); |
|
406 NextTest(); |
|
407 } |
|
408 break; |
|
409 case ETestUnfilteredView: |
|
410 { |
|
411 iLog.LogLine(_L("==== Exercise EUnfilteredView")); |
|
412 test(iUnfilteredView->CountL()==KNumUnfiltered); |
|
413 TestViewIndiciesL(*iUnfilteredView); |
|
414 NextTest(); |
|
415 } |
|
416 break; |
|
417 |
|
418 case ETestRingToneView: |
|
419 iLog.LogLine(_L("==== Exercise ETestRingToneView")); |
|
420 test(iRingToneView->CountL()==KNumRingTone); |
|
421 TestViewIndiciesL(*iRingToneView); |
|
422 NextTest(); |
|
423 |
|
424 break; |
|
425 |
|
426 case ETestVoiceDialView: |
|
427 iLog.LogLine(_L("==== Exercise ETestVoiceDialView")); |
|
428 test( iVoiceDialView->CountL() == KNumVoiceDial ); |
|
429 TestViewIndiciesL(*iVoiceDialView); |
|
430 NextTest(); |
|
431 |
|
432 break; |
|
433 |
|
434 case ETestWirelessVillageAddressView: |
|
435 // this should also test the different protocols assigned to the IMAddress for each contact |
|
436 { |
|
437 iLog.LogLine(_L("==== Exercise WirelessVillageAddressView")); |
|
438 TInt numberContacts = iWirelessVillageView->CountL(); |
|
439 test(numberContacts == KNumIMAddress); |
|
440 |
|
441 TInt numberWV = 0; |
|
442 |
|
443 for(TInt a = 0; a < numberContacts; a++) |
|
444 { |
|
445 TContactItemId contactID = iWirelessVillageView->AtL(a); |
|
446 CContactItem* contact = iDb.ReadContactLC(contactID); // PUSH |
|
447 CContactItemFieldSet& fieldSet = contact->CardFields(); |
|
448 CContactItemField& field = fieldSet[contact->CardFields().Find(KUidContactFieldIMAddress)]; |
|
449 TFieldType imProtocol = field.ContentType().FieldType(1); |
|
450 |
|
451 if(imProtocol == KUidContactFieldVCardMapWV) |
|
452 numberWV++; |
|
453 CleanupStack::PopAndDestroy(); // contact |
|
454 } |
|
455 test(numberWV == KNumIMProtocolWV); |
|
456 |
|
457 TestViewIndiciesL(*iWirelessVillageView); |
|
458 NextTest(); |
|
459 } |
|
460 break; |
|
461 |
|
462 case ETestIMAddressView: |
|
463 { |
|
464 iLog.LogLine(_L("==== Exercise IMAddressView")); |
|
465 test(iIMAddressView->CountL()==KNumIMAddress); |
|
466 TestViewIndiciesL(*iIMAddressView); |
|
467 NextTest(); |
|
468 } |
|
469 break; |
|
470 |
|
471 case ETestRemoveContacts: |
|
472 { |
|
473 iLog.LogLine(_L("==== Remove Some Contacts")); |
|
474 TContactItemId deletedId = iPhonableFilterView->AtL(10); |
|
475 iDb.DeleteContactL(deletedId); |
|
476 RDebug::Print(_L("DELETED ID : %d"),deletedId); |
|
477 deletedId = iEmailFilterView->AtL(3); |
|
478 iDb.DeleteContactL(deletedId); |
|
479 RDebug::Print(_L("DELETED ID : %d"),deletedId); |
|
480 deletedId = iFaxFilterView->AtL(6); |
|
481 iDb.DeleteContactL(deletedId); |
|
482 RDebug::Print(_L("DELETED ID : %d"),deletedId); |
|
483 iItemEventsExpected=3; |
|
484 iItemsEventsRecieved=0; |
|
485 } |
|
486 break; |
|
487 case ETestViewIndiciesAfterRemoval: |
|
488 { |
|
489 iLog.LogLine(_L("==== Exercise ETestPhonableFilterView after removal")); |
|
490 TestViewIndiciesL(*iPhonableFilterView); |
|
491 TestViewIndiciesL(*iLandlineFilterView); |
|
492 TestViewIndiciesL(*iSmsFilterView); |
|
493 TestViewIndiciesL(*iFaxFilterView); |
|
494 TestViewIndiciesL(*iEmailFilterView); |
|
495 NextTest(); |
|
496 } |
|
497 break; |
|
498 case ETestAddContacts: |
|
499 { |
|
500 iLog.LogLine(_L("==== Add some Contacts")); |
|
501 iTestConductor->AddContactL(CContactDatabase::ELandLine); |
|
502 iTestConductor->AddContactL(CContactDatabase::EMailable); |
|
503 iTestConductor->AddContactL(CContactDatabase::ESmsable); |
|
504 iTestConductor->AddContactL(CContactDatabase::EFaxable); |
|
505 iItemEventsExpected=4; |
|
506 iItemsEventsRecieved=0; |
|
507 // NextTest(); //wait until notitifications has gone through the system |
|
508 } |
|
509 break; |
|
510 case ETestViewIndiciesAfterAddition: |
|
511 { |
|
512 iLog.LogLine(_L("==== Exercise ETestPhonableFilterView after addition")); |
|
513 TestViewIndiciesL(*iPhonableFilterView); |
|
514 TestViewIndiciesL(*iLandlineFilterView); |
|
515 TestViewIndiciesL(*iSmsFilterView); |
|
516 TestViewIndiciesL(*iFaxFilterView); |
|
517 TestViewIndiciesL(*iEmailFilterView); |
|
518 NextTest(); |
|
519 } |
|
520 break; |
|
521 case EAllViewsOutOfBoundsAccess: |
|
522 { |
|
523 //Views depend on their underlying views being in a good state, however |
|
524 //as some base views are potentially in other processes they must be resistant |
|
525 //to out of date views accessesing out of bound members, views, should not |
|
526 //panic but should leave with KErrNotFound; |
|
527 //local view |
|
528 TInt err=0; |
|
529 iLog.LogLine(_L("=== Test views for out of bounds access")); |
|
530 TInt outCount = iPhonableFilterView->CountL(); |
|
531 TRAP(err,iPhonableFilterView->AtL(outCount)); |
|
532 test(err==KErrNotFound); |
|
533 TRAP(err,iPhonableFilterView->ContactAtL(outCount)); |
|
534 test(err==KErrNotFound); |
|
535 NextTest(); |
|
536 } |
|
537 break; |
|
538 case EOOMIMAddressView: |
|
539 { |
|
540 ++iOOMCounter += iOOMCounter/25; //Increasing step as we go further |
|
541 iFilter = CContactDatabase::EIMAddress; |
|
542 |
|
543 __UHEAP_SETFAIL(RHeap::EDeterministic,iOOMCounter); |
|
544 TRAPD(ret, iOOMIMAddressView = CContactFilteredView::NewL(*this,iDb,*iNamedRemoteView, iFilter)); |
|
545 |
|
546 if (ret==KErrNone) |
|
547 { |
|
548 break; //Wait for asynchronous notification in HandleContactViewEvent |
|
549 } |
|
550 |
|
551 if (ret != KErrNoMemory) |
|
552 { |
|
553 _LIT(KOMMFail, "OOM Test failed: Leave reason is not KErrNoMemory: %d"); |
|
554 test.Printf(KOMMFail, ret); |
|
555 User::Leave(KErrAbort); |
|
556 } |
|
557 __UHEAP_RESET; |
|
558 |
|
559 test.Printf(_L("KErrNoMemory at step %5d"), iOOMCounter); |
|
560 TRequestStatus *pS=&iStatus; |
|
561 User::RequestComplete(pS,KErrNone); |
|
562 SetActive(); |
|
563 } |
|
564 break; |
|
565 |
|
566 case EOOMDeleteIMAddressView: |
|
567 { |
|
568 iOOMIMAddressView->Close(*this); |
|
569 iCurrentTest = EOOMIMAddressView; //Back to OOM |
|
570 TRequestStatus *pS=&iStatus; |
|
571 User::RequestComplete(pS,KErrNone); |
|
572 SetActive(); |
|
573 } |
|
574 break; |
|
575 |
|
576 case ECreateLandLineFilterView2Fields: |
|
577 { |
|
578 // For DEF077467. Propagated from DEF074316. |
|
579 // Ensure hint field is set to landline when there's < 3 fields but one of them is voice |
|
580 // One contact should appear in the filtered view |
|
581 // Clear the database first |
|
582 while(iDb.CountL() !=0) |
|
583 { |
|
584 iDb.DeleteContactL((*iDb.SortedItemsL())[0]); |
|
585 } |
|
586 iFilterViewSavedId = KErrNotFound; |
|
587 // Loop adds 2 contacts with 2 fields, Hint field should be set with ELandLine |
|
588 // first time through loop and hence should appear in the filtered view |
|
589 // Second time through the loop still 2 fields but not voice and hence will not |
|
590 // appear in the filtered view |
|
591 // Verify the correct one is in the view with the contact id |
|
592 for(TInt i=0;i<2;++i) |
|
593 { |
|
594 CContactCard* card=CContactCard::NewLC(); |
|
595 CContactItemField* field=CContactItemField::NewLC(KStorageTypeText); |
|
596 field->AddFieldTypeL(KUidContactFieldPhoneNumber); |
|
597 if(i==0) |
|
598 { |
|
599 field->AddFieldTypeL(KUidContactFieldVCardMapVOICE); |
|
600 } |
|
601 else |
|
602 { |
|
603 field->AddFieldTypeL(KUidContactFieldVCardMapPAGER); |
|
604 } |
|
605 field->TextStorage()->SetTextL(_L("02071541222")); |
|
606 card->AddFieldL(*field); |
|
607 CleanupStack::Pop(field); |
|
608 if(i==0) |
|
609 { |
|
610 iFilterViewSavedId = iDb.AddNewContactL(*card); |
|
611 } |
|
612 else |
|
613 { |
|
614 (void)iDb.AddNewContactL(*card); |
|
615 } |
|
616 CleanupStack::PopAndDestroy(card); // card |
|
617 } |
|
618 // Create the filtered view |
|
619 iFilter = CContactDatabase::ESmsable|CContactDatabase::ELandLine; |
|
620 iLandlineFilterView2Fields = CreateFilterViewL(); |
|
621 // Event handler kicks to next state where we check result |
|
622 } |
|
623 break; |
|
624 |
|
625 case ETestLandLineFilterView2Fields: |
|
626 { |
|
627 // Should only be one contact in the view even though there's 2 in the database |
|
628 test(iLandlineFilterView2Fields->CountL()==1); |
|
629 TContactItemId id = iLandlineFilterView2Fields->AtL(0); |
|
630 // Make sure it's the one we're expecting |
|
631 test(iFilterViewSavedId == id && iFilterViewSavedId != KErrNotFound); |
|
632 NextTest(); |
|
633 } |
|
634 break; |
|
635 |
|
636 case ENumTests: |
|
637 iLog.LogLine(_L("==== Filter View Finished")); |
|
638 PrintTotalTimeTaken(); |
|
639 CActiveScheduler::Stop(); |
|
640 delete this; |
|
641 break; |
|
642 default: |
|
643 ASSERT(EFalse); |
|
644 break; |
|
645 } |
|
646 } |
|
647 |
|
648 |
|
649 TInt CViewTester::RunError(TInt aError) |
|
650 { |
|
651 iTestConductor->SetTestError(aError); |
|
652 |
|
653 switch (iCurrentTest) |
|
654 { |
|
655 case ECreateLocalView: test.Printf(_L("Test failed at step CreateLocalView (%i) with error %i"), iCurrentTest, aError); break; |
|
656 case EExerciseLocalView: test.Printf(_L("Test failed at step ExerciseLocalView (%i) with error %i"), iCurrentTest, aError); break; |
|
657 case ECreateLandlineFilterView: test.Printf(_L("Test failed at step CreateLandlineFilterView (%i) with error %i"), iCurrentTest, aError); break; |
|
658 case ETestLandlineFilterView: test.Printf(_L("Test failed at step TestLandlineFilterView (%i) with error %i"), iCurrentTest, aError); break; |
|
659 case ECreateSmsFilterView: test.Printf(_L("Test failed at step CreateSmsFilterView (%i) with error %i"), iCurrentTest, aError); break; |
|
660 case ETestSmsFilterView: test.Printf(_L("Test failed at step TestSmsFilterView (%i) with error %i"), iCurrentTest, aError); break; |
|
661 case ECreateEmailFilterView: test.Printf(_L("Test failed at step CreateEmailFilterView (%i) with error %i"), iCurrentTest, aError); break; |
|
662 case ETestEmailFilterView: test.Printf(_L("Test failed at step TestEmailFilterView (%i) with error %i"), iCurrentTest, aError); break; |
|
663 case ECreateFaxFilterView: test.Printf(_L("Test failed at step CreateFaxFilterView (%i) with error %i"), iCurrentTest, aError); break; |
|
664 case ETestFaxFilterView: test.Printf(_L("Test failed at step TestFaxFilterView (%i) with error %i"), iCurrentTest, aError); break; |
|
665 case ECreatePhonableFilterView: test.Printf(_L("Test failed at step CreatePhonableFilterView (%i) with error %i"), iCurrentTest, aError); break; |
|
666 case ECreateWorkFilterView: test.Printf(_L("Test failed at step CreateWorkFilterView (%i) with error %i"), iCurrentTest, aError); break; |
|
667 case ECreateHomeFilterView: test.Printf(_L("Test failed at step CreateHomeFilterView (%i) with error %i"), iCurrentTest, aError); break; |
|
668 case ECreateUnfilteredView: test.Printf(_L("Test failed at step CreateUnfilteredView (%i) with error %i"), iCurrentTest, aError); break; |
|
669 case ECreateRingToneView: test.Printf(_L("Test failed at step CreateRingToneView (%i) with error %i"), iCurrentTest, aError); break; |
|
670 case ECreateVoiceDialView: test.Printf(_L("Test failed at step CreateVoiceDialView (%i) with error %i"), iCurrentTest, aError); break; |
|
671 case ECreateWirelessVillageAddressView: test.Printf(_L("Test failed at step CreateWirelessVillageAddressView (%i) with error %i"), iCurrentTest, aError); break; |
|
672 case ECreateIMAddressView: test.Printf(_L("Test failed at step CreateIMAddressView (%i) with error %i"), iCurrentTest, aError); break; |
|
673 case ETestPhonableFilterView: test.Printf(_L("Test failed at step TestPhonableFilterView (%i) with error %i"), iCurrentTest, aError); break; |
|
674 case ETestWorkFilterView: test.Printf(_L("Test failed at step TestWorkFilterView (%i) with error %i"), iCurrentTest, aError); break; |
|
675 case ETestHomeFilterView: test.Printf(_L("Test failed at step TestHomeFilterView (%i) with error %i"), iCurrentTest, aError); break; |
|
676 case ETestUnfilteredView: test.Printf(_L("Test failed at step TestUnfilteredView (%i) with error %i"), iCurrentTest, aError); break; |
|
677 case ETestRingToneView: test.Printf(_L("Test failed at step TestRingToneView (%i) with error %i"), iCurrentTest, aError); break; |
|
678 case ETestVoiceDialView: test.Printf(_L("Test failed at step TestVoiceDialView (%i) with error %i"), iCurrentTest, aError); break; |
|
679 case ETestWirelessVillageAddressView: test.Printf(_L("Test failed at step TestWirelessVillageAddressView (%i) with error %i"), iCurrentTest, aError); break; |
|
680 case ETestIMAddressView: test.Printf(_L("Test failed at step TestIMAddressView (%i) with error %i"), iCurrentTest, aError); break; |
|
681 case ETestRemoveContacts: test.Printf(_L("Test failed at step TestRemoveContacts (%i) with error %i"), iCurrentTest, aError); break; |
|
682 case ETestViewIndiciesAfterRemoval: test.Printf(_L("Test failed at step TestViewIndiciesAfterRemoval (%i) with error %i"), iCurrentTest, aError); break; |
|
683 case ETestAddContacts: test.Printf(_L("Test failed at step TestAddContacts (%i) with error %i"), iCurrentTest, aError); break; |
|
684 case ETestViewIndiciesAfterAddition: test.Printf(_L("Test failed at step TestViewIndiciesAfterAddition (%i) with error %i"), iCurrentTest, aError); break; |
|
685 case EAllViewsOutOfBoundsAccess: test.Printf(_L("Test failed at step AllViewsOutOfBoundsAccess (%i) with error %i"), iCurrentTest, aError); break; |
|
686 case EOOMIMAddressView: test.Printf(_L("Test failed at step OOMIMAddressView (%i) with error %i"), iCurrentTest, aError); break; |
|
687 case EOOMDeleteIMAddressView: test.Printf(_L("Test failed at step OOMDeleteIMAddressView (%i) with error %i"), iCurrentTest, aError); break; |
|
688 case ECreateLandLineFilterView2Fields: test.Printf(_L("Test failed at step CreateLandlineFilterView (%i) with error %i"), iCurrentTest, aError); break; |
|
689 case ETestLandLineFilterView2Fields: test.Printf(_L("Test failed at step TestLandlineFilterView (%i) with error %i"), iCurrentTest, aError); break; |
|
690 |
|
691 case ENumTests: test.Printf(_L("Test failed at step NumTests (%i) with error %i"), iCurrentTest, aError); break; |
|
692 |
|
693 default: test.Printf(_L("Test failed at step %i with error %i"), iCurrentTest, aError); break; |
|
694 } |
|
695 |
|
696 CActiveScheduler::Stop(); |
|
697 return KErrNone; |
|
698 } |
|
699 |
|
700 |
|
701 // Should always return true for a correct implementation of |
|
702 // CContactViewBase |
|
703 TBool CViewTester::ContactIdsEqualL(const CContactViewBase& aView, TInt aIndex) |
|
704 { |
|
705 TContactItemId viewId = aView.AtL(aIndex); |
|
706 //RDebug::Print(_L("UnderLyingView viewId : %d"),viewId); |
|
707 TContactItemId contactId = aView.ContactAtL(aIndex).Id(); |
|
708 //RDebug::Print(_L("Sub View Id contactId : %d"),contactId); |
|
709 return (contactId == viewId); |
|
710 } |
|
711 |
|
712 void CViewTester::TestViewIndiciesL(const CContactViewBase& aView) |
|
713 { |
|
714 for (TInt i=0; i < aView.CountL(); ++i) |
|
715 { |
|
716 test(ContactIdsEqualL(aView,i)!=EFalse); |
|
717 } |
|
718 } |
|
719 /* |
|
720 CContactFilteredView* filteredView = ...; |
|
721 for (TInt i=0; i < filteredView->CountL(); ++i) |
|
722 { |
|
723 ASSERT(ContactIdsEqual(*filteredView, i); |
|
724 }*/ |
|
725 |
|
726 void CViewTester::HandleViewCreation(const CContactViewBase& aView, const TContactViewEvent& aEvent, CContactViewBase* aPtrView) |
|
727 { |
|
728 test(aPtrView==&aView); |
|
729 test(aEvent.iEventType==TContactViewEvent::EReady); |
|
730 CCntTest::ProfileEnd(0); |
|
731 CCntTest::ProfileResult(&iProfile,0,1); |
|
732 iTimeForTestsToComplete[iCurrentTest] = iProfile.iTime; |
|
733 PrintTimeTaken(iProfile.iTime); |
|
734 } |
|
735 |
|
736 |
|
737 void CViewTester::HandleContactViewEvent(const CContactViewBase& aView,const TContactViewEvent& aEvent) |
|
738 { |
|
739 switch (iCurrentTest) |
|
740 { |
|
741 case ECreateLocalView: |
|
742 HandleViewCreation( aView, aEvent, iNamedRemoteView ); |
|
743 break; |
|
744 case EExerciseLocalView: |
|
745 test(ETrue); |
|
746 break; |
|
747 case ECreateLandlineFilterView: |
|
748 HandleViewCreation( aView, aEvent, iLandlineFilterView ); |
|
749 break; |
|
750 case ETestLandlineFilterView: |
|
751 test(EFalse); |
|
752 break; |
|
753 case ECreateSmsFilterView: |
|
754 HandleViewCreation( aView, aEvent, iSmsFilterView ); |
|
755 break; |
|
756 case ETestSmsFilterView: |
|
757 test(EFalse); |
|
758 break; |
|
759 case ECreateEmailFilterView: |
|
760 HandleViewCreation( aView, aEvent, iEmailFilterView ); |
|
761 break; |
|
762 case ETestEmailFilterView: |
|
763 test(EFalse); |
|
764 break; |
|
765 case ECreateFaxFilterView: |
|
766 HandleViewCreation( aView, aEvent, iFaxFilterView ); |
|
767 break; |
|
768 case ETestFaxFilterView: |
|
769 test(EFalse); |
|
770 break; |
|
771 case ECreatePhonableFilterView: |
|
772 HandleViewCreation( aView, aEvent, iPhonableFilterView ); |
|
773 break; |
|
774 case ECreateWorkFilterView: |
|
775 HandleViewCreation( aView, aEvent, iWorkFilterView ); |
|
776 break; |
|
777 case ECreateHomeFilterView: |
|
778 HandleViewCreation( aView, aEvent, iHomeFilterView ); |
|
779 break; |
|
780 case ECreateUnfilteredView: |
|
781 HandleViewCreation( aView, aEvent, iUnfilteredView ); |
|
782 break; |
|
783 |
|
784 case ECreateRingToneView: |
|
785 HandleViewCreation( aView, aEvent, iRingToneView ); |
|
786 break; |
|
787 |
|
788 case ECreateVoiceDialView: |
|
789 HandleViewCreation( aView, aEvent, iVoiceDialView ); |
|
790 break; |
|
791 |
|
792 case ECreateWirelessVillageAddressView: |
|
793 HandleViewCreation( aView, aEvent, iWirelessVillageView ); |
|
794 break; |
|
795 |
|
796 case ECreateIMAddressView: |
|
797 HandleViewCreation( aView, aEvent, iIMAddressView ); |
|
798 break; |
|
799 |
|
800 case ETestPhonableFilterView: |
|
801 test(EFalse); |
|
802 break; |
|
803 case ETestRemoveContacts: |
|
804 { |
|
805 if(aEvent.iEventType==TContactViewEvent::EItemRemoved) |
|
806 { |
|
807 iItemsEventsRecieved++; |
|
808 if(iItemEventsExpected==iItemsEventsRecieved) |
|
809 { |
|
810 NextTest(); |
|
811 } |
|
812 } |
|
813 return; |
|
814 } |
|
815 case ETestViewIndiciesAfterRemoval: |
|
816 test(aEvent.iEventType==TContactViewEvent::EItemRemoved); |
|
817 return; |
|
818 case ETestAddContacts: |
|
819 { |
|
820 if(aEvent.iEventType==TContactViewEvent::EItemAdded) |
|
821 { |
|
822 iItemsEventsRecieved++; |
|
823 if(iItemEventsExpected==iItemsEventsRecieved) |
|
824 { |
|
825 NextTest(); |
|
826 } |
|
827 } |
|
828 return; |
|
829 } |
|
830 case ETestViewIndiciesAfterAddition: |
|
831 test(aEvent.iEventType==TContactViewEvent::EItemAdded); |
|
832 return; |
|
833 case EAllViewsOutOfBoundsAccess: |
|
834 { |
|
835 test(EFalse); |
|
836 break; |
|
837 } |
|
838 case EOOMIMAddressView: |
|
839 { |
|
840 __UHEAP_RESET; |
|
841 test(iOOMIMAddressView==&aView); |
|
842 switch (aEvent.iEventType) |
|
843 { |
|
844 case TContactViewEvent::EReady: |
|
845 test.Printf(_L("OOM: EReady at step %5d\n"), iOOMCounter); |
|
846 ++iCurrentTest; //Exit OOM loop - goto next test |
|
847 break; |
|
848 case TContactViewEvent::ESortError: |
|
849 test.Printf(_L("OOM: ESortError at step %5d\n"), iOOMCounter); |
|
850 break; //Go to EOOMDeleteIMAddressView - we cannot delete view in its callback. |
|
851 default: |
|
852 test.Printf(_L("OOM: Unexpected notification at step %5d\n"), iOOMCounter); |
|
853 test(EFalse); //Unsupported event - fail |
|
854 } |
|
855 } |
|
856 break; |
|
857 |
|
858 case ECreateLandLineFilterView2Fields: |
|
859 { |
|
860 HandleViewCreation( aView, aEvent, iLandlineFilterView2Fields); |
|
861 } |
|
862 break; |
|
863 |
|
864 case EOOMDeleteIMAddressView: //there should not be any call backs after deletion |
|
865 case ENumTests: |
|
866 default: |
|
867 test(EFalse); |
|
868 break; |
|
869 } |
|
870 if (--iNumNotificationExpected<=0) |
|
871 { |
|
872 NextTest(); |
|
873 iNumNotificationExpected=0; |
|
874 } |
|
875 } |
|
876 |
|
877 void CViewTester::TestViewNotificationsL(CContactViewBase& /*aView*/) |
|
878 { |
|
879 //Test just add some contacts for now... |
|
880 /* CRandomContactGenerator* generator=CRandomContactGenerator::NewL(); |
|
881 CleanupStack::PushL(generator); |
|
882 generator->SetDbL(iDb); |
|
883 for (TInt ii=0;ii<KInitialNumContacts;++ii) |
|
884 { |
|
885 generator->AddTypicalRandomContactL(); |
|
886 } |
|
887 CleanupStack::PopAndDestroy(); // generator. |
|
888 */ } |
|
889 |
|
890 void CViewTester::NextTest() |
|
891 { |
|
892 ++iCurrentTest; |
|
893 TRequestStatus *pS=&iStatus; |
|
894 User::RequestComplete(pS,KErrNone); |
|
895 SetActive(); |
|
896 } |
|
897 |
|
898 void CViewTester::ExceriseViewL(CContactViewBase& aView) |
|
899 { |
|
900 TContactItemId lastId=0; |
|
901 const TInt numItems=aView.CountL(); |
|
902 for (TInt ii=0;ii<numItems;++ii) |
|
903 { |
|
904 if (ii==numItems-1) |
|
905 { |
|
906 lastId=aView.AtL(ii); |
|
907 } |
|
908 iDb.ReadContactTextDefL(aView.AtL(ii),iScratchBuf,iTextDef); |
|
909 iLog.LogLineNoEcho(iScratchBuf); |
|
910 iScratchBuf.SetLength(0); |
|
911 } |
|
912 |
|
913 test(aView.FindL(lastId)==numItems-1); |
|
914 } |
|
915 |
|
916 void CViewTester::DoCancel() |
|
917 { |
|
918 } |
|
919 |
|
920 void doMainL() |
|
921 { |
|
922 __UHEAP_MARK; |
|
923 CTestConductor* testConductor = NULL; |
|
924 testConductor = CTestConductor::NewL(); |
|
925 CleanupStack::PushL( testConductor ); |
|
926 CleanupStack::PopAndDestroy( testConductor ); |
|
927 __UHEAP_MARKEND; |
|
928 } |
|
929 // |
|
930 // Main. |
|
931 // |
|
932 |
|
933 |
|
934 /** |
|
935 |
|
936 @SYMTestCaseID PIM-T-FILTERVIEW-0001 |
|
937 |
|
938 */ |
|
939 |
|
940 GLDEF_C TInt E32Main() |
|
941 { |
|
942 __UHEAP_MARK; |
|
943 test.Start(_L("@SYMTESTCaseID:PIM-T-FILTERVIEW-0001 ")); |
|
944 |
|
945 CActiveScheduler* scheduler=new CActiveScheduler; |
|
946 if (scheduler) |
|
947 { |
|
948 CActiveScheduler::Install(scheduler); |
|
949 CTrapCleanup* cleanup=CTrapCleanup::New(); |
|
950 if (cleanup) |
|
951 { |
|
952 TRAPD(err,doMainL()); |
|
953 test(err == KErrNone); |
|
954 delete cleanup; |
|
955 } |
|
956 delete scheduler; |
|
957 } |
|
958 test.End(); |
|
959 test.Close(); |
|
960 __UHEAP_MARKEND; |
|
961 return KErrNone; |
|
962 } |