|
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 <collate.h> |
|
19 #include <cntdb.h> |
|
20 #include <cntitem.h> |
|
21 #include <cntfldst.h> |
|
22 #include "t_utils2.h" |
|
23 #include "t_apac.h" |
|
24 #include <badesca.h> |
|
25 |
|
26 // |
|
27 // Constants. |
|
28 // |
|
29 |
|
30 _LIT(KTestName,"t_apac"); |
|
31 _LIT(KLogFileName,"t_apac.log"); |
|
32 |
|
33 _LIT(KDbFileName,"c:t_apac.cdb"); |
|
34 |
|
35 _LIT8(KUnicodeLineEnd,"\x0D\x00\x0a\x00"); |
|
36 const TInt KNumberOfUnsortableContacts=10; |
|
37 //Sample uid for the TestPlugin. |
|
38 const TUid KFindTestUid = {0x101F8012}; |
|
39 |
|
40 |
|
41 LOCAL_D RTest test(KTestName); |
|
42 |
|
43 |
|
44 LOCAL_C void CleanupContactArray(TAny* aArray) |
|
45 { |
|
46 RPointerArray<CViewContact>* array=REINTERPRET_CAST(RPointerArray<CViewContact>*,aArray); |
|
47 if (array) |
|
48 array->ResetAndDestroy(); |
|
49 array->Close(); |
|
50 } |
|
51 |
|
52 // |
|
53 // CTestConductor. |
|
54 // |
|
55 |
|
56 CTestConductor* CTestConductor::NewL() |
|
57 { |
|
58 CTestConductor* self=new(ELeave) CTestConductor(); |
|
59 CleanupStack::PushL(self); |
|
60 self->ConstructL(); |
|
61 CleanupStack::Pop(); |
|
62 return self; |
|
63 } |
|
64 |
|
65 CTestConductor::~CTestConductor() |
|
66 { |
|
67 if (iLocalView != NULL) |
|
68 { |
|
69 iLocalView->Close(*this); |
|
70 } |
|
71 if (iLocalViewWithPlugin != NULL) |
|
72 { |
|
73 iLocalViewWithPlugin->Close(*this); |
|
74 } |
|
75 if (iRemoteView != NULL) |
|
76 { |
|
77 iRemoteView->Close(*this); |
|
78 } |
|
79 if (iRemoteViewWithPlugin) |
|
80 { |
|
81 iRemoteViewWithPlugin->Close(*this); |
|
82 } |
|
83 |
|
84 if(iFindDesArray) |
|
85 { |
|
86 iFindDesArray->Reset(); |
|
87 delete iFindDesArray; |
|
88 } |
|
89 |
|
90 iSortOrder.Close(); |
|
91 delete iContactOpenOperation; |
|
92 delete iRandomGenerator; |
|
93 delete iSortChecker; |
|
94 delete iViewCreator; |
|
95 delete iContactAdder; |
|
96 delete iContactRemover; |
|
97 delete iLog; |
|
98 delete iDb; |
|
99 iTestIds.Reset(); |
|
100 iTestIds.Close(); |
|
101 |
|
102 TRAP_IGNORE(CContactDatabase::DeleteDatabaseL(KDbFileName)); |
|
103 |
|
104 iFs.Close(); |
|
105 } |
|
106 |
|
107 CTestConductor::CTestConductor() : CActive(EPriorityStandard),iCurrentTestNumber(-1) |
|
108 { |
|
109 CActiveScheduler::Add(this); |
|
110 } |
|
111 |
|
112 void CTestConductor::ConstructL() |
|
113 { |
|
114 iSortOrder.AppendL(KUidContactFieldGivenName); |
|
115 iSortOrder.AppendL(KUidContactFieldFamilyName); |
|
116 iSortOrder.AppendL(KUidContactFieldCompanyName); |
|
117 |
|
118 User::LeaveIfError(iFs.Connect()); |
|
119 // ensure database exists |
|
120 iDb=CContactDatabase::ReplaceL(KDbFileName); |
|
121 // close it |
|
122 delete iDb; |
|
123 iDb = NULL; |
|
124 |
|
125 iRandomGenerator=CRandomContactGenerator::NewL(); |
|
126 |
|
127 iLog=CLog::NewL(test,KLogFileName); |
|
128 |
|
129 NextTest(); |
|
130 CActiveScheduler::Start(); |
|
131 // error from active object? |
|
132 User::LeaveIfError(iTestError); |
|
133 test.Printf(_L("\n")); |
|
134 } |
|
135 |
|
136 void CTestConductor::NextTest() |
|
137 { |
|
138 ++iCurrentTestNumber; |
|
139 TRequestStatus *pS=&iStatus; |
|
140 User::RequestComplete(pS,KErrNone); |
|
141 SetActive(); |
|
142 } |
|
143 |
|
144 void CTestConductor::RunL() |
|
145 { |
|
146 switch (iCurrentTestNumber) |
|
147 { |
|
148 case EAsyncOpen: |
|
149 iLog->LogLine(_L("=== Async Open")); |
|
150 SetActive(); |
|
151 iContactOpenOperation = CContactDatabase::Open(KDbFileName,iStatus); |
|
152 ++iCurrentTestNumber; |
|
153 break; |
|
154 case EAsyncOpened: |
|
155 // Open failed |
|
156 if (iStatus.Int() != KErrNone) |
|
157 { |
|
158 iLog->LogLine(_L(" * Asynchronous open failed")); |
|
159 User::Leave(iStatus.Int()); |
|
160 } |
|
161 iLog->LogLine(_L("=== Opened Async")); |
|
162 iDb = iContactOpenOperation->TakeDatabase(); |
|
163 iRandomGenerator->SetDbL(*iDb); |
|
164 iSortChecker=CSortChecker::NewL(*this); |
|
165 iViewCreator=CViewCreator::NewL(*this); |
|
166 iContactAdder=CContactAdder::NewL(*this); |
|
167 iContactRemover=CContactRemover::NewL(*this); |
|
168 NextTest(); |
|
169 break; |
|
170 |
|
171 case ECreateLocalView: |
|
172 iLog->LogLine(_L("=== Create local view")); |
|
173 iCurrentTestObject=iViewCreator; |
|
174 iLocalView=iViewCreator->CreateLocalViewL(iSortOrder); |
|
175 break; |
|
176 case EAddInitialContacts: |
|
177 iLog->LogLine(_L("=== Add initial contacts")); |
|
178 iCurrentTestObject=iContactAdder; |
|
179 iContactAdder->AddContactsL(_L("z:\\t_apac\\t_apac_initial_contacts.txt"),1); |
|
180 break; |
|
181 |
|
182 case ECreateLocalViewWithPlugin: |
|
183 iLog->LogLine(_L("=== Create local view with my find plugin")); |
|
184 iCurrentTestObject=iViewCreator; |
|
185 iLocalViewWithPlugin=iViewCreator->CreateLocalViewL(iSortOrder); |
|
186 iLocalViewWithPlugin->SetViewFindConfigPlugin(KFindTestUid); |
|
187 break; |
|
188 case ECreateRemoteView: |
|
189 iLog->LogLine(_L("=== Create remote view")); |
|
190 iCurrentTestObject=iViewCreator; |
|
191 iRemoteView=iViewCreator->CreateRemoteViewL(iSortOrder); |
|
192 break; |
|
193 case ECreateRemoteViewWithPlugin: |
|
194 iLog->LogLine(_L("=== Create remote view with my find plugin")); |
|
195 iCurrentTestObject=iViewCreator; |
|
196 iRemoteViewWithPlugin=iViewCreator->CreateRemoteViewL(iSortOrder); |
|
197 iRemoteViewWithPlugin->SetViewFindConfigPlugin(KFindTestUid); |
|
198 break; |
|
199 case ECriteriaSearchForStringInLocal: |
|
200 { |
|
201 iLog->LogLine(_L("=== Criteria Search for string in Local View")); |
|
202 _LIT(KFindString1,"Mar"); |
|
203 CPtrCArray* array =new(ELeave)CPtrC16Array(1); |
|
204 CleanupStack::PushL(array); |
|
205 array->AppendL(KFindString1()); |
|
206 RPointerArray<CViewContact> contactArray; |
|
207 CleanupStack::PushL(TCleanupItem(CleanupContactArray,&contactArray)); |
|
208 iLocalView->ContactsMatchingCriteriaL(*array, contactArray); |
|
209 if(contactArray.Count() > 0) |
|
210 { |
|
211 iLog->LogLine(_L("=== Matches found!!Criteria Search Local View!")); |
|
212 } |
|
213 CleanupStack::PopAndDestroy(2, array); |
|
214 NextTest(); |
|
215 } |
|
216 break; |
|
217 case ECriteriaSearchForStringInLocalWithPlugin: |
|
218 { |
|
219 iLog->LogLine(_L("=== Criteria Search for string in Local View with my plugin")); |
|
220 _LIT(KFindString1,"Mar"); |
|
221 CPtrCArray* array =new(ELeave)CPtrC16Array(1); |
|
222 CleanupStack::PushL(array); |
|
223 array->AppendL(KFindString1()); |
|
224 RPointerArray<CViewContact> contactArray; |
|
225 CleanupStack::PushL(TCleanupItem(CleanupContactArray,&contactArray)); |
|
226 iLocalViewWithPlugin->ContactsMatchingCriteriaL(*array, contactArray); |
|
227 if(contactArray.Count() > 0) |
|
228 { |
|
229 iLog->LogLine(_L("=== Matches found!!Criteria Search Local View with plugin")); |
|
230 } |
|
231 CleanupStack::PopAndDestroy(2, array); |
|
232 NextTest(); |
|
233 } |
|
234 break; |
|
235 case ECriteriaSearchForStringInRemote: |
|
236 { |
|
237 iLog->LogLine(_L("=== Criteria Search for string in Remote View")); |
|
238 _LIT(KFindString1,"Mar"); |
|
239 CPtrCArray* array =new(ELeave)CPtrC16Array(1); |
|
240 CleanupStack::PushL(array); |
|
241 array->AppendL(KFindString1()); |
|
242 RPointerArray<CViewContact> contactArray; |
|
243 CleanupStack::PushL(TCleanupItem(CleanupContactArray,&contactArray)); |
|
244 iRemoteView->ContactsMatchingCriteriaL(*array, contactArray); |
|
245 if(contactArray.Count() > 0) |
|
246 { |
|
247 iLog->LogLine(_L("=== Matches found!!Criteria Search Remote View ")); |
|
248 } |
|
249 CleanupStack::PopAndDestroy(2, array); |
|
250 NextTest(); |
|
251 } |
|
252 break; |
|
253 case ECriteriaSearchForStringInRemoteWithPlugin: |
|
254 { |
|
255 iLog->LogLine(_L("=== Criteria Search for string in Remote View with plugin")); |
|
256 _LIT(KFindString1,"Mar"); |
|
257 CPtrCArray* array =new(ELeave)CPtrC16Array(1); |
|
258 CleanupStack::PushL(array); |
|
259 array->AppendL(KFindString1()); |
|
260 RPointerArray<CViewContact> contactArray; |
|
261 CleanupStack::PushL(TCleanupItem(CleanupContactArray,&contactArray)); |
|
262 iRemoteViewWithPlugin->ContactsMatchingCriteriaL(*array, contactArray); |
|
263 if(contactArray.Count() > 0) |
|
264 { |
|
265 iLog->LogLine(_L("=== Matches found!!Criteria Search Remote View with plugin")); |
|
266 } |
|
267 CleanupStack::PopAndDestroy(2, array); |
|
268 NextTest(); |
|
269 } |
|
270 break; |
|
271 case EPrefixSearchForStringInLocal: |
|
272 { |
|
273 iLog->LogLine(_L("=== Prefix Search for string in Local View")); |
|
274 _LIT(KFindString1,"Mar"); |
|
275 CPtrCArray* array =new(ELeave)CPtrC16Array(1); |
|
276 CleanupStack::PushL(array); |
|
277 array->AppendL(KFindString1()); |
|
278 RPointerArray<CViewContact> contactArray; |
|
279 CleanupStack::PushL(TCleanupItem(CleanupContactArray,&contactArray)); |
|
280 iLocalView->ContactsMatchingCriteriaL(*array, contactArray); |
|
281 if(contactArray.Count() > 0) |
|
282 { |
|
283 iLog->LogLine(_L("=== Matches were indeed found!!Prefix Search Local View!")); |
|
284 } |
|
285 CleanupStack::PopAndDestroy(2, array); |
|
286 NextTest(); |
|
287 } |
|
288 break; |
|
289 case EPrefixSearchForStringInLocalWithPlugin: |
|
290 { |
|
291 iLog->LogLine(_L("=== Prefix Search for string in Local View with my plugin")); |
|
292 _LIT(KFindString1,"Mar"); |
|
293 CPtrCArray* array =new(ELeave)CPtrC16Array(1); |
|
294 CleanupStack::PushL(array); |
|
295 array->AppendL(KFindString1()); |
|
296 RPointerArray<CViewContact> contactArray; |
|
297 CleanupStack::PushL(TCleanupItem(CleanupContactArray,&contactArray)); |
|
298 iLocalViewWithPlugin->ContactsMatchingPrefixL(*array, contactArray); |
|
299 if(contactArray.Count() > 0) |
|
300 { |
|
301 iLog->LogLine(_L("=== Matches were found!!Prefix Search Local View with plugin")); |
|
302 } |
|
303 CleanupStack::PopAndDestroy(2, array); |
|
304 NextTest(); |
|
305 } |
|
306 break; |
|
307 case EPrefixSearchForStringInRemote: |
|
308 { |
|
309 iLog->LogLine(_L("=== Prefix Search for string in Remote View")); |
|
310 _LIT(KFindString1,"Mar"); |
|
311 CPtrCArray* array =new(ELeave)CPtrC16Array(1); |
|
312 CleanupStack::PushL(array); |
|
313 array->AppendL(KFindString1()); |
|
314 RPointerArray<CViewContact> contactArray; |
|
315 CleanupStack::PushL(TCleanupItem(CleanupContactArray,&contactArray)); |
|
316 iRemoteView->ContactsMatchingPrefixL(*array, contactArray); |
|
317 if(contactArray.Count() > 0) |
|
318 { |
|
319 iLog->LogLine(_L("=== Matches were found!!Prefix Search Remote View ")); |
|
320 } |
|
321 CleanupStack::PopAndDestroy(2, array); |
|
322 NextTest(); |
|
323 } |
|
324 break; |
|
325 case EPrefixSearchForStringInRemoteWithPlugin: |
|
326 { |
|
327 iLog->LogLine(_L("=== Prefix Search for string in Remote View with plugin")); |
|
328 _LIT(KFindString1,"Mar"); |
|
329 CPtrCArray* array =new(ELeave)CPtrC16Array(1); |
|
330 CleanupStack::PushL(array); |
|
331 array->AppendL(KFindString1()); |
|
332 RPointerArray<CViewContact> contactArray; |
|
333 CleanupStack::PushL(TCleanupItem(CleanupContactArray,&contactArray)); |
|
334 iRemoteViewWithPlugin->ContactsMatchingPrefixL(*array, contactArray); |
|
335 if(contactArray.Count() > 0) |
|
336 { |
|
337 iLog->LogLine(_L("=== Matches were found!!Prefix Search Remote View with plugin")); |
|
338 } |
|
339 CleanupStack::PopAndDestroy(2, array); |
|
340 NextTest(); |
|
341 } |
|
342 break; |
|
343 |
|
344 case ENumTests: |
|
345 { |
|
346 RThread thread; |
|
347 test(thread.RequestCount()==0); |
|
348 CActiveScheduler::Stop(); |
|
349 } |
|
350 break; |
|
351 default: |
|
352 ASSERT(EFalse); |
|
353 break; |
|
354 } |
|
355 } |
|
356 |
|
357 TInt CTestConductor::RunError(TInt aError) |
|
358 { |
|
359 // propagate error |
|
360 iTestError = aError; |
|
361 |
|
362 switch (iCurrentTestNumber) |
|
363 { |
|
364 case EAsyncOpen: test.Printf(_L("test failed at step AsyncOpen (%i) with error %i"), iCurrentTestNumber, aError); break; |
|
365 case EAsyncOpened: test.Printf(_L("test failed at step AsyncOpened (%i) with error %i"), iCurrentTestNumber, aError); break; |
|
366 case ECreateLocalView: test.Printf(_L("test failed at step CreateLocalView (%i) with error %i"), iCurrentTestNumber, aError); break; |
|
367 case EAddInitialContacts: test.Printf(_L("test failed at step AddInitialContacts (%i) with error %i"), iCurrentTestNumber, aError); break; |
|
368 case ECreateLocalViewWithPlugin: test.Printf(_L("test failed at step CreateLocalViewWithPlugin (%i) with error %i"), iCurrentTestNumber, aError); break; |
|
369 case ECreateRemoteView: test.Printf(_L("test failed at step CreateRemoteView (%i) with error %i"), iCurrentTestNumber, aError); break; |
|
370 case ECreateRemoteViewWithPlugin: test.Printf(_L("test failed at step CreateRemoteViewWithPlugin (%i) with error %i"), iCurrentTestNumber, aError); break; |
|
371 case ECriteriaSearchForStringInLocal: test.Printf(_L("test failed at step CriteriaSearchForStringInLocal (%i) with error %i"), iCurrentTestNumber, aError); break; |
|
372 case ECriteriaSearchForStringInLocalWithPlugin: test.Printf(_L("test failed at step CriteriaSearchForStringInLocalWithPlugin (%i) with error %i"), iCurrentTestNumber, aError); break; |
|
373 case ECriteriaSearchForStringInRemote: test.Printf(_L("test failed at step CriteriaSearchForStringInRemote (%i) with error %i"), iCurrentTestNumber, aError); break; |
|
374 case ECriteriaSearchForStringInRemoteWithPlugin: test.Printf(_L("test failed at step CriteriaSearchForStringInRemoteWithPlugin (%i) with error %i"), iCurrentTestNumber, aError); break; |
|
375 case EPrefixSearchForStringInLocal: test.Printf(_L("test failed at step PrefixSearchForStringInLocal (%i) with error %i"), iCurrentTestNumber, aError); break; |
|
376 case EPrefixSearchForStringInLocalWithPlugin: test.Printf(_L("test failed at step PrefixSearchForStringInLocalWithPlugin (%i) with error %i"), iCurrentTestNumber, aError); break; |
|
377 case EPrefixSearchForStringInRemote: test.Printf(_L("test failed at step PrefixSearchForStringInRemote (%i) with error %i"), iCurrentTestNumber, aError); break; |
|
378 case EPrefixSearchForStringInRemoteWithPlugin: test.Printf(_L("test failed at step PrefixSearchForStringInRemoteWithPlugin (%i) with error %i"), iCurrentTestNumber, aError); break; |
|
379 |
|
380 case ENumTests: test.Printf(_L("test failed at step NumTests (%i) with error %i"), iCurrentTestNumber, aError); break; |
|
381 |
|
382 default: test.Printf(_L("test failed at step %i with error %i"), iCurrentTestNumber, aError); break; |
|
383 } |
|
384 |
|
385 CActiveScheduler::Stop(); |
|
386 return KErrNone; |
|
387 } |
|
388 |
|
389 |
|
390 void CTestConductor::HandleContactViewEvent(const CContactViewBase& aView,const TContactViewEvent& aEvent) |
|
391 { |
|
392 TRAPD(err, iCurrentTestObject->HandleNotificationL(aView,aEvent) ); |
|
393 test(err == KErrNone); |
|
394 } |
|
395 |
|
396 void CTestConductor::DoCancel() |
|
397 { |
|
398 } |
|
399 |
|
400 void CTestConductor::ExerciseViewPreferencesL(const CContactViewBase* aViewToTest,TContactViewPreferences aPrefsToTest) |
|
401 { |
|
402 //test the viewpreferences of a view. All views with EunsortedatBegining for example should place, any contact |
|
403 //without the field specified in a sort to the begining of the main sorted list of contact |
|
404 TInt normalContacts = aViewToTest->CountL()-iTestIds.Count(); |
|
405 test(normalContacts>0); |
|
406 TContactItemId id=KErrNotFound; |
|
407 TInt index =KErrNotFound; |
|
408 for(TInt ii=0;ii<iTestIds.Count();ii++) |
|
409 { |
|
410 index = aViewToTest->FindL(iTestIds[ii]); |
|
411 test(index>=0);//no error code |
|
412 if(aPrefsToTest&EUnSortedAtBeginning) |
|
413 { |
|
414 //shpould be before 'normal contacts |
|
415 test(index<iTestIds.Count());//in the right place |
|
416 } |
|
417 else if(aPrefsToTest&EUnSortedAtEnd) |
|
418 { |
|
419 //should be after the last index of the 'normal' contacts |
|
420 test(index>=normalContacts);//in the right place |
|
421 } |
|
422 //Integrity check |
|
423 id=aViewToTest->AtL(index); |
|
424 const CViewContact& contact=aViewToTest->ContactAtL(index); |
|
425 test(contact.Id()==id); |
|
426 if(aPrefsToTest&ESingleWhiteSpaceIsEmptyField) |
|
427 { |
|
428 //Contact Fields Should not have any white space as a field, _L(" ") |
|
429 for(TInt zz=0;zz<contact.FieldCount();zz++) |
|
430 { |
|
431 test((contact.Field(zz).CompareC(_L(" ")))!=0); |
|
432 } |
|
433 } |
|
434 } |
|
435 } |
|
436 |
|
437 // |
|
438 // CSortChecker. |
|
439 // |
|
440 |
|
441 CSortChecker* CSortChecker::NewL(CTestConductor& aConductor) |
|
442 { |
|
443 CSortChecker* self=new(ELeave) CSortChecker(aConductor); |
|
444 CleanupStack::PushL(self); |
|
445 self->ConstructL(); |
|
446 CleanupStack::Pop(); // self. |
|
447 return self; |
|
448 } |
|
449 |
|
450 CSortChecker::CSortChecker(CTestConductor& aConductor) : iConductor(aConductor) |
|
451 { |
|
452 } |
|
453 |
|
454 void CSortChecker::ConstructL() |
|
455 { |
|
456 iCollateMethod=new(ELeave) TCollationMethod; |
|
457 *iCollateMethod=*Mem::CollationMethodByIndex(0); |
|
458 iCollateMethod->iFlags|=TCollationMethod::EIgnoreNone; |
|
459 } |
|
460 |
|
461 CSortChecker::~CSortChecker() |
|
462 { |
|
463 iSortedFirstLast.ResetAndDestroy(); |
|
464 iSortedLastFirst.ResetAndDestroy(); |
|
465 delete iCollateMethod; |
|
466 } |
|
467 |
|
468 void CSortChecker::AddContactL(const TDesC& aFirstName,const TDesC& aLastName) |
|
469 { |
|
470 HBufC* buf=HBufC::NewLC(aFirstName.Length()+aLastName.Length()+1); |
|
471 TPtr bufPtr(buf->Des()); |
|
472 bufPtr.Append(aFirstName); |
|
473 if (aFirstName.Length()) |
|
474 bufPtr.Append(_L(" ")); |
|
475 bufPtr.Append(aLastName); |
|
476 User::LeaveIfError(iSortedFirstLast.Append(buf)); |
|
477 CleanupStack::Pop(); // buf. |
|
478 |
|
479 buf=HBufC::NewLC(aFirstName.Length()+aLastName.Length()+1); |
|
480 TPtr bufPtr2(buf->Des()); |
|
481 bufPtr2.Append(aLastName); |
|
482 if (aLastName.Length()) |
|
483 bufPtr2.Append(_L(" ")); |
|
484 bufPtr2.Append(aFirstName); |
|
485 User::LeaveIfError(iSortedLastFirst.Append(buf)); |
|
486 CleanupStack::Pop(); // buf. |
|
487 } |
|
488 |
|
489 void CSortChecker::RemoveContactL(const TDesC& aFirstName,const TDesC& aLastName) |
|
490 { |
|
491 HBufC* buf=HBufC::NewLC(aFirstName.Length()+aLastName.Length()+1); |
|
492 TPtr bufPtr(buf->Des()); |
|
493 bufPtr.Append(aFirstName); |
|
494 if (aFirstName.Length()) |
|
495 bufPtr.Append(_L(" ")); |
|
496 bufPtr.Append(aLastName); |
|
497 TInt index=iSortedFirstLast.Find(buf,TIdentityRelation<HBufC>(Match)); |
|
498 ASSERT(index!=KErrNotFound); |
|
499 delete iSortedFirstLast[index]; |
|
500 iSortedFirstLast.Remove(index); |
|
501 CleanupStack::PopAndDestroy(); // buf. |
|
502 |
|
503 buf=HBufC::NewLC(aFirstName.Length()+aLastName.Length()+1); |
|
504 TPtr bufPtr2(buf->Des()); |
|
505 bufPtr2.Append(aLastName); |
|
506 if (aLastName.Length()) |
|
507 bufPtr2.Append(_L(" ")); |
|
508 bufPtr2.Append(aFirstName); |
|
509 index=iSortedLastFirst.Find(buf,TIdentityRelation<HBufC>(Match)); |
|
510 ASSERT(index!=KErrNotFound); |
|
511 delete iSortedLastFirst[index]; |
|
512 iSortedLastFirst.Remove(index); |
|
513 CleanupStack::PopAndDestroy(); // buf. |
|
514 } |
|
515 |
|
516 TBool CSortChecker::Match(const HBufC& aFirst,const HBufC& aSecond) |
|
517 { |
|
518 if (aFirst.Compare(aSecond)==0) |
|
519 { |
|
520 return ETrue; |
|
521 } |
|
522 return EFalse; |
|
523 } |
|
524 |
|
525 TPtrC CSortChecker::ContactAt(TSortOrder aOrder,TInt aIndex) const |
|
526 { |
|
527 const RPointerArray<HBufC>& sortedList=(aOrder==ELastNameFirstName) ? iSortedLastFirst : iSortedFirstLast; |
|
528 return TPtrC(*sortedList[aIndex]); |
|
529 } |
|
530 |
|
531 TInt CSortChecker::Count() const |
|
532 { |
|
533 return iSortedFirstLast.Count(); |
|
534 } |
|
535 |
|
536 TInt CSortChecker::Count(TSortOrder aOrder,const TDesC& aLowBoundary,const TDesC& aHighBoundary) const |
|
537 { |
|
538 const TInt low=FindIndex(aOrder,aLowBoundary,CSortChecker::EGreaterThanOrEqualTo); |
|
539 const TInt high=FindIndex(aOrder,aHighBoundary,CSortChecker::EGreaterThanOrEqualTo); |
|
540 if (low==KErrNotFound) |
|
541 { |
|
542 test(high==KErrNotFound); |
|
543 return 0; |
|
544 } |
|
545 return high-low; |
|
546 } |
|
547 |
|
548 TInt CSortChecker::CountLow(TSortOrder aOrder,const TDesC& aHighBoundary) const |
|
549 { |
|
550 const TInt high=FindIndex(aOrder,aHighBoundary,CSortChecker::EGreaterThanOrEqualTo); |
|
551 if (high==KErrNotFound) |
|
552 { |
|
553 return 0; |
|
554 } |
|
555 return high; |
|
556 } |
|
557 |
|
558 TInt CSortChecker::CountHigh(TSortOrder aOrder,const TDesC& aLowBoundary) const |
|
559 { |
|
560 const TInt low=FindIndex(aOrder,aLowBoundary,CSortChecker::EGreaterThanOrEqualTo); |
|
561 if (low==KErrNotFound) |
|
562 { |
|
563 return 0; |
|
564 } |
|
565 return Count()-low; |
|
566 } |
|
567 |
|
568 void CSortChecker::Sort() |
|
569 { |
|
570 iSortedFirstLast.Sort(TLinearOrder<HBufC>(CompareWithoutIgnoringSpacesL)); |
|
571 iSortedLastFirst.Sort(TLinearOrder<HBufC>(CompareWithoutIgnoringSpacesL)); |
|
572 |
|
573 const TInt numContacts=iSortedFirstLast.Count(); |
|
574 __ASSERT_ALWAYS(numContacts==iSortedLastFirst.Count(),User::Invariant()); |
|
575 } |
|
576 |
|
577 void CSortChecker::CheckSort(TSortOrder aOrder,const TDesC& aName,TInt aIndex) const |
|
578 { |
|
579 const RPointerArray<HBufC>& sortedList=(aOrder==ELastNameFirstName) ? iSortedLastFirst : iSortedFirstLast; |
|
580 iConductor.iLog->LogLineNoEcho(_L("Checking - %S against %S"),&aName,sortedList[aIndex]); |
|
581 test(sortedList[aIndex]->Compare(aName)==0); |
|
582 } |
|
583 |
|
584 void CSortChecker::CheckSortLowSubView(TSortOrder aOrder,const TDesC& aName,TInt aIndex,const TDesC& aHighBoundary) const |
|
585 { |
|
586 const RPointerArray<HBufC>& sortedList=(aOrder==ELastNameFirstName) ? iSortedLastFirst : iSortedFirstLast; |
|
587 const HBufC* name=sortedList[aIndex]; |
|
588 iConductor.iLog->LogLineNoEcho(_L("Checking - %S against %S"),&aName,name); |
|
589 test(name->CompareC(aHighBoundary,3,iCollateMethod)<0); |
|
590 test(name->Compare(aName)==0); |
|
591 } |
|
592 |
|
593 void CSortChecker::CheckSortHighSubView(TSortOrder aOrder,const TDesC& aName,TInt aIndex,const TDesC& aLowBoundary) const |
|
594 { |
|
595 const RPointerArray<HBufC>& sortedList=(aOrder==ELastNameFirstName) ? iSortedLastFirst : iSortedFirstLast; |
|
596 const TInt lowIndex=FindIndex(aOrder,aLowBoundary,CSortChecker::EGreaterThanOrEqualTo); |
|
597 if (lowIndex!=KErrNotFound) |
|
598 { |
|
599 iConductor.iLog->LogLineNoEcho(_L("Checking - %S against %S"),&aName,sortedList[lowIndex+aIndex]); |
|
600 test(sortedList[lowIndex+aIndex]->Compare(aName)==0); |
|
601 } |
|
602 } |
|
603 |
|
604 void CSortChecker::CheckSortSubView(TSortOrder aOrder,const TDesC& aName,TInt aIndex,const TDesC& aLowBoundary,const TDesC& aHighBoundary) const |
|
605 { |
|
606 const RPointerArray<HBufC>& sortedList=(aOrder==ELastNameFirstName) ? iSortedLastFirst : iSortedFirstLast; |
|
607 const TInt lowIndex=FindIndex(aOrder,aLowBoundary,CSortChecker::EGreaterThanOrEqualTo); |
|
608 if (lowIndex!=KErrNotFound) |
|
609 { |
|
610 const HBufC* name=sortedList[lowIndex+aIndex]; |
|
611 iConductor.iLog->LogLineNoEcho(_L("Checking - %S against %S"),&aName,name); |
|
612 test(name->CompareC(aHighBoundary,3,iCollateMethod)<0); |
|
613 test(name->Compare(aName)==0); |
|
614 } |
|
615 } |
|
616 |
|
617 TInt CSortChecker::FindIndex(TSortOrder aOrder,const TDesC& aBoundary,TCriteria aCriteria) const |
|
618 { |
|
619 const RPointerArray<HBufC>& sortedList=(aOrder==ELastNameFirstName) ? iSortedLastFirst : iSortedFirstLast; |
|
620 const TInt numContacts=sortedList.Count(); |
|
621 for (TInt ii=0;ii<numContacts;++ii) |
|
622 { |
|
623 switch (aCriteria) |
|
624 { |
|
625 case ELessThan: |
|
626 if (sortedList[ii]->CompareC(aBoundary,3,iCollateMethod)<0) |
|
627 { |
|
628 return ii; |
|
629 } |
|
630 break; |
|
631 case ELessThanOrEqualTo: |
|
632 if (sortedList[ii]->CompareC(aBoundary,3,iCollateMethod)<=0) |
|
633 { |
|
634 return ii; |
|
635 } |
|
636 break; |
|
637 case EGreaterThan: |
|
638 if (sortedList[ii]->CompareC(aBoundary,3,iCollateMethod)>0) |
|
639 { |
|
640 return ii; |
|
641 } |
|
642 break; |
|
643 case EGreaterThanOrEqualTo: |
|
644 if (sortedList[ii]->CompareC(aBoundary,3,iCollateMethod)>=0) |
|
645 { |
|
646 return ii; |
|
647 } |
|
648 break; |
|
649 default: |
|
650 ASSERT(EFalse); |
|
651 } |
|
652 } |
|
653 return KErrNotFound; |
|
654 } |
|
655 |
|
656 TInt CSortChecker::Compare(const HBufC& aFirst, const HBufC& aSecond) |
|
657 { |
|
658 return aFirst.CompareC(aSecond); |
|
659 } |
|
660 |
|
661 TInt CSortChecker::CompareWithoutIgnoringSpacesL(const HBufC& aFirst, const HBufC& aSecond) |
|
662 { |
|
663 // In order to sort correctly, we need to recognise spaces, but ignore other punctuation |
|
664 HBufC* temp1=HBufC::NewLC(aFirst.Length()); |
|
665 TPtr first(temp1->Des()); |
|
666 first.Copy(aFirst); |
|
667 HBufC* temp2=HBufC::NewLC(aSecond.Length()); |
|
668 TPtr second(temp2->Des()); |
|
669 second.Copy(aSecond); |
|
670 TChar leftParenthesis('('); |
|
671 TChar rightParenthesis(')'); |
|
672 RemoveCharacterFromDescriptor(leftParenthesis, first); |
|
673 RemoveCharacterFromDescriptor(rightParenthesis, first); |
|
674 RemoveCharacterFromDescriptor(leftParenthesis, second); |
|
675 RemoveCharacterFromDescriptor(rightParenthesis, second); |
|
676 |
|
677 |
|
678 TCollationMethod collateMethod; |
|
679 collateMethod = *Mem::CollationMethodByIndex(0); |
|
680 collateMethod.iFlags|=TCollationMethod::EIgnoreNone; |
|
681 TInt compare=0; |
|
682 TInt collationLevel=0; |
|
683 |
|
684 while (!compare && collationLevel<4) |
|
685 { |
|
686 compare=first.CompareC(second,collationLevel,&collateMethod); |
|
687 ++collationLevel; |
|
688 } |
|
689 |
|
690 CleanupStack::PopAndDestroy(2); |
|
691 return compare; |
|
692 } |
|
693 |
|
694 void CSortChecker::RemoveCharacterFromDescriptor(const TChar aChar, TDes& aDes) |
|
695 { |
|
696 TInt location=aDes.Locate(aChar); |
|
697 while (location!=KErrNotFound) |
|
698 { |
|
699 aDes.Delete(location,1); |
|
700 location=aDes.Locate(aChar); |
|
701 } |
|
702 } |
|
703 |
|
704 // |
|
705 // CTestBase. |
|
706 // |
|
707 |
|
708 CTestBase::CTestBase(CTestConductor& aConductor) : iConductor(aConductor) |
|
709 { |
|
710 } |
|
711 |
|
712 |
|
713 // |
|
714 // CViewCreator. |
|
715 // |
|
716 |
|
717 CViewCreator* CViewCreator::NewL(CTestConductor& aConductor) |
|
718 { |
|
719 CViewCreator* self=new(ELeave) CViewCreator(aConductor); |
|
720 return self; |
|
721 } |
|
722 |
|
723 CContactLocalView* CViewCreator::CreateLocalViewL(const RContactViewSortOrder& aSortOrder,TContactViewPreferences aViewPrefs) |
|
724 { |
|
725 iView=CContactLocalView::NewL(iConductor,*iConductor.iDb,aSortOrder,aViewPrefs); |
|
726 return STATIC_CAST(CContactLocalView*,iView); |
|
727 } |
|
728 |
|
729 CContactLocalView* CViewCreator::CreateLocalViewL(const RContactViewSortOrder& aSortOrder) |
|
730 { |
|
731 TInt32 viewPrefs=0; |
|
732 viewPrefs|=EUnSortedAtBeginning; |
|
733 iView=CContactLocalView::NewL(iConductor,*iConductor.iDb,aSortOrder,TContactViewPreferences(viewPrefs)); |
|
734 return STATIC_CAST(CContactLocalView*,iView); |
|
735 } |
|
736 CContactNamedLocalView* CViewCreator::CreateNamedLocalViewL(const TDesC& aName,const RContactViewSortOrder& aSortOrder) |
|
737 { |
|
738 TInt32 viewPrefs=0; |
|
739 viewPrefs|=EUnSortedAtBeginning; |
|
740 iView=CContactNamedLocalView::NewL(iConductor,aName,*iConductor.iDb,aSortOrder,TContactViewPreferences(viewPrefs)); |
|
741 return STATIC_CAST(CContactNamedLocalView*,iView); |
|
742 } |
|
743 |
|
744 CContactRemoteView* CViewCreator::CreateRemoteViewL(const RContactViewSortOrder& aSortOrder) |
|
745 { |
|
746 TInt32 viewPrefs=0; |
|
747 viewPrefs|=EUnSortedAtBeginning; |
|
748 iView=CContactRemoteView::NewL(iConductor,*iConductor.iDb,aSortOrder,TContactViewPreferences(viewPrefs)); |
|
749 return STATIC_CAST(CContactRemoteView*,iView); |
|
750 } |
|
751 |
|
752 CContactNamedRemoteView* CViewCreator::CreateNamedRemoteViewL(const TDesC& aName,const RContactViewSortOrder& aSortOrder) |
|
753 { |
|
754 TInt32 viewPrefs=0; |
|
755 viewPrefs|=EUnSortedAtBeginning; |
|
756 iView=CContactNamedRemoteView::NewL(iConductor,aName,*iConductor.iDb,aSortOrder,TContactViewPreferences(viewPrefs)); |
|
757 return STATIC_CAST(CContactNamedRemoteView*,iView); |
|
758 } |
|
759 |
|
760 void CViewCreator::HandleNotificationL(const CContactViewBase& aView,const TContactViewEvent& aEvent) |
|
761 { |
|
762 test(&aView==iView); |
|
763 test(aEvent.iEventType==TContactViewEvent::EReady); |
|
764 iConductor.NextTest(); |
|
765 } |
|
766 |
|
767 CViewCreator::CViewCreator(CTestConductor& aConductor) : CTestBase(aConductor) |
|
768 { |
|
769 } |
|
770 |
|
771 |
|
772 // |
|
773 // CContactAdder. |
|
774 // |
|
775 |
|
776 CContactAdder* CContactAdder::NewL(CTestConductor& aConductor) |
|
777 { |
|
778 CContactAdder* self=new(ELeave) CContactAdder(aConductor); |
|
779 CleanupStack::PushL(self); |
|
780 self->ConstructL(); |
|
781 CleanupStack::Pop(); // self. |
|
782 return self; |
|
783 } |
|
784 |
|
785 CContactAdder::~CContactAdder() |
|
786 { |
|
787 delete iTemplate; |
|
788 iFile.Close(); |
|
789 iFs.Close(); |
|
790 } |
|
791 |
|
792 void CContactAdder::AddContactsL(const TDesC& aFileName,TInt aNumViews) |
|
793 { |
|
794 User::LeaveIfError(iFile.Open(iFs,aFileName,EFileShareAny|EFileStreamText)); |
|
795 iNumViews=aNumViews; |
|
796 TInt pos=2; |
|
797 iFile.Seek(ESeekStart,pos); // Ignore Unicode header. |
|
798 test.Printf(_L("Adding contact ")); |
|
799 AddOneContactL(); |
|
800 } |
|
801 |
|
802 void CContactAdder::HandleNotificationL(const CContactViewBase&,const TContactViewEvent& aEvent) |
|
803 { |
|
804 if (++iNumNotifications == iNumViews) |
|
805 { |
|
806 if (iFinished) |
|
807 { |
|
808 iConductor.NextTest(); |
|
809 } |
|
810 else |
|
811 { |
|
812 AddOneContactL(); |
|
813 } |
|
814 } |
|
815 else |
|
816 { |
|
817 test(aEvent.iEventType == TContactViewEvent::EItemAdded); |
|
818 } |
|
819 } |
|
820 |
|
821 CContactAdder::CContactAdder(CTestConductor& aConductor) : CTestBase(aConductor) |
|
822 { |
|
823 } |
|
824 |
|
825 void CContactAdder::ConstructL() |
|
826 { |
|
827 User::LeaveIfError(iFs.Connect()); |
|
828 iTemplate=STATIC_CAST(CContactTemplate*,iConductor.iDb->ReadContactL(iConductor.iDb->TemplateId())); |
|
829 } |
|
830 |
|
831 void CContactAdder::AddOneContactL() |
|
832 { |
|
833 iNumNotifications=0; |
|
834 TBuf<64> firstName; |
|
835 TBuf<64> lastName; |
|
836 iConductor.iLog->IncVisualCounter(); |
|
837 iFinished=!ReadNamePairL(iFile,firstName,lastName); |
|
838 iConductor.iLog->LogLineNoEcho(_L("Adding %S %S"),&firstName,&lastName); |
|
839 CTestContact* contact=CTestContact::NewLC(*iTemplate); |
|
840 contact->SetFirstNameL(firstName); |
|
841 contact->SetLastNameL(lastName); |
|
842 iConductor.iDb->AddNewContactL(contact->ContactItem()); |
|
843 CleanupStack::PopAndDestroy(); // contact. |
|
844 iConductor.iDb->CompactL(); |
|
845 iConductor.iSortChecker->AddContactL(firstName,lastName); |
|
846 if (iFinished) |
|
847 { |
|
848 iConductor.iLog->EndVisualCounter(); |
|
849 iConductor.iSortChecker->Sort(); |
|
850 } |
|
851 } |
|
852 |
|
853 TBool CContactAdder::ReadNamePairL(RFile aFile,TDes& aFirstName,TDes& aLastName) |
|
854 { |
|
855 TBuf8<2> character=_L8(" "); |
|
856 TBuf8<4> lineEndTestBuf=_L8(" "); |
|
857 |
|
858 aFirstName.SetLength(0); |
|
859 aLastName.SetLength(0); |
|
860 TBool readingLastName=ETrue; |
|
861 while (lineEndTestBuf!=KUnicodeLineEnd) |
|
862 { |
|
863 User::LeaveIfError(aFile.Read(character,2)); |
|
864 if (character.Length()>0) |
|
865 { |
|
866 lineEndTestBuf[0]=lineEndTestBuf[2]; |
|
867 lineEndTestBuf[1]=lineEndTestBuf[3]; |
|
868 lineEndTestBuf[2]=character[0]; |
|
869 lineEndTestBuf[3]=character[1]; |
|
870 |
|
871 const TPtrC16 widePtr((TUint16*)character.Ptr(),1); |
|
872 if (widePtr[0]==';') |
|
873 { |
|
874 readingLastName=EFalse; |
|
875 } |
|
876 else if (readingLastName) |
|
877 { |
|
878 aLastName.Append(widePtr); |
|
879 } |
|
880 else |
|
881 { |
|
882 aFirstName.Append(widePtr); |
|
883 } |
|
884 } |
|
885 else |
|
886 { |
|
887 return EFalse; |
|
888 } |
|
889 } |
|
890 |
|
891 aFirstName.Delete(aFirstName.Length()-2,2); // Strip off \n\r. |
|
892 return ETrue; |
|
893 } |
|
894 |
|
895 |
|
896 // |
|
897 // CContactRemover. |
|
898 // |
|
899 |
|
900 CContactRemover* CContactRemover::NewL(CTestConductor& aConductor) |
|
901 { |
|
902 CContactRemover* self=new(ELeave) CContactRemover(aConductor); |
|
903 CleanupStack::PushL(self); |
|
904 self->ConstructL(); |
|
905 CleanupStack::Pop(); // self. |
|
906 return self; |
|
907 } |
|
908 |
|
909 CContactRemover::~CContactRemover() |
|
910 { |
|
911 iFile.Close(); |
|
912 iFs.Close(); |
|
913 } |
|
914 |
|
915 void CContactRemover::RemoveContactsL(const TDesC& aFileName,TInt aNumViews) |
|
916 { |
|
917 User::LeaveIfError(iFile.Open(iFs,aFileName,EFileShareAny|EFileStreamText)); |
|
918 iNumViews=aNumViews; |
|
919 TInt pos=2; |
|
920 iFile.Seek(ESeekStart,pos); // Ignore Unicode header. |
|
921 test.Printf(_L("Removing contact ")); |
|
922 RemoveOneContactL(); |
|
923 } |
|
924 |
|
925 void CContactRemover::HandleNotificationL(const CContactViewBase&,const TContactViewEvent& aEvent) |
|
926 { |
|
927 if (++iNumNotifications==iNumViews) |
|
928 { |
|
929 if (iFinished) |
|
930 { |
|
931 iConductor.NextTest(); |
|
932 } |
|
933 else |
|
934 { |
|
935 TRAPD(err, RemoveOneContactL() ); |
|
936 test(err == KErrNone); |
|
937 } |
|
938 } |
|
939 else |
|
940 { |
|
941 test(aEvent.iEventType==TContactViewEvent::EItemRemoved); |
|
942 } |
|
943 } |
|
944 |
|
945 CContactRemover::CContactRemover(CTestConductor& aConductor) : CTestBase(aConductor) |
|
946 { |
|
947 } |
|
948 |
|
949 void CContactRemover::ConstructL() |
|
950 { |
|
951 User::LeaveIfError(iFs.Connect()); |
|
952 } |
|
953 |
|
954 void CContactRemover::RemoveOneContactL() |
|
955 { |
|
956 iNumNotifications=0; |
|
957 TBuf<64> firstName; |
|
958 TBuf<64> lastName; |
|
959 iConductor.iLog->IncVisualCounter(); |
|
960 iFinished=!CContactAdder::ReadNamePairL(iFile,firstName,lastName); |
|
961 iConductor.iLog->LogLineNoEcho(_L("Removing %S %S"),&firstName,&lastName); |
|
962 CContactItemFieldDef* def=new(ELeave) CContactItemFieldDef(); |
|
963 CleanupStack::PushL(def); |
|
964 def->AppendL(KUidContactFieldGivenName); |
|
965 def->AppendL(KUidContactFieldFamilyName); |
|
966 CContactIdArray* matchList1=iConductor.iDb->FindLC(lastName,def); |
|
967 CContactIdArray* matchList2=iConductor.iDb->FindLC(firstName,def); |
|
968 |
|
969 for (TInt ii=matchList1->Count()-1;ii>=0;--ii) |
|
970 { |
|
971 TContactItemId thisId=(*matchList1)[ii]; |
|
972 for (TInt jj=matchList2->Count()-1;jj>=0;--jj) |
|
973 { |
|
974 if (thisId==(*matchList2)[jj]) |
|
975 { |
|
976 iConductor.iDb->DeleteContactL(thisId); |
|
977 goto carry_on; |
|
978 } |
|
979 } |
|
980 } |
|
981 ASSERT(EFalse); |
|
982 |
|
983 carry_on: |
|
984 CleanupStack::PopAndDestroy(3); // matchList2, matchList1, def. |
|
985 iConductor.iDb->CompactL(); |
|
986 iConductor.iSortChecker->RemoveContactL(firstName,lastName); |
|
987 if (iFinished) |
|
988 { |
|
989 iConductor.iLog->EndVisualCounter(); |
|
990 iConductor.iSortChecker->Sort(); |
|
991 } |
|
992 } |
|
993 |
|
994 |
|
995 // |
|
996 // CSortOrderChanger. |
|
997 // |
|
998 |
|
999 CSortOrderChanger* CSortOrderChanger::NewL(CTestConductor& aConductor) |
|
1000 { |
|
1001 CSortOrderChanger* self=new(ELeave) CSortOrderChanger(aConductor); |
|
1002 return self; |
|
1003 } |
|
1004 |
|
1005 void CSortOrderChanger::ChangeSortOrderL(RContactViewSortOrder& aSortOrder,CContactNamedLocalView& aView,TInt aNumViews) |
|
1006 { |
|
1007 aView.ChangeSortOrderL(aSortOrder); |
|
1008 iNumViews=aNumViews; |
|
1009 iNumNotifications=0; |
|
1010 } |
|
1011 |
|
1012 void CSortOrderChanger::ChangeSortOrderL(RContactViewSortOrder& aSortOrder,CContactNamedRemoteView& aView,TInt aNumViews) |
|
1013 { |
|
1014 aView.ChangeSortOrderL(aSortOrder); |
|
1015 iNumViews=aNumViews; |
|
1016 iNumNotifications=0; |
|
1017 } |
|
1018 |
|
1019 CSortOrderChanger::~CSortOrderChanger() |
|
1020 { |
|
1021 } |
|
1022 |
|
1023 void CSortOrderChanger::HandleNotificationL(const CContactViewBase&,const TContactViewEvent& aEvent) |
|
1024 { |
|
1025 test(aEvent.iEventType==TContactViewEvent::EUnavailable || aEvent.iEventType==TContactViewEvent::ESortOrderChanged || aEvent.iEventType==TContactViewEvent::EReady); |
|
1026 // if (++iNumNotifications==iNumViews*3) // 3 because there will be EUnavailable, ESortOrderChanged, and EReady notifications for each view. |
|
1027 if (++iNumNotifications==iNumViews*2) // 3 because there will be EUnavailable, ESortOrderChanged, and EReady notifications for each view. |
|
1028 { |
|
1029 iConductor.NextTest(); |
|
1030 } |
|
1031 } |
|
1032 |
|
1033 CSortOrderChanger::CSortOrderChanger(CTestConductor& aConductor) : CTestBase(aConductor) |
|
1034 { |
|
1035 } |
|
1036 |
|
1037 |
|
1038 // |
|
1039 // CUnsortableContactAdder. |
|
1040 // |
|
1041 |
|
1042 CUnsortableContactAdder::CUnsortableContactAdder(CTestConductor& aConductor,const CContactViewBase& aView) |
|
1043 :CTestBase(aConductor),iView(&aView) |
|
1044 {} |
|
1045 |
|
1046 CUnsortableContactAdder* CUnsortableContactAdder::NewL(CTestConductor& aConductor,const CContactViewBase& aView) |
|
1047 { |
|
1048 CUnsortableContactAdder* self=new(ELeave) CUnsortableContactAdder(aConductor,aView); |
|
1049 return self; |
|
1050 } |
|
1051 |
|
1052 CUnsortableContactAdder::~CUnsortableContactAdder() |
|
1053 { |
|
1054 } |
|
1055 |
|
1056 void CUnsortableContactAdder::AddContactsL(TInt aNumberOfContact,TContactViewPreferences aContactTypes) |
|
1057 { |
|
1058 iNumContacts = aNumberOfContact; |
|
1059 iNumNotifications=0; |
|
1060 for(TInt ii=0;ii<KNumberOfUnsortableContacts;ii++) |
|
1061 { |
|
1062 TContactItemId id = iConductor.iRandomGenerator->AddTypicalContactForLocalViewPreferencesL(TContactViewPreferences(aContactTypes)); |
|
1063 iConductor.iTestIds.Append(id); |
|
1064 } |
|
1065 |
|
1066 |
|
1067 } |
|
1068 void CUnsortableContactAdder::HandleNotificationL(const CContactViewBase& aView,const TContactViewEvent& aEvent) |
|
1069 { |
|
1070 if(aEvent.iEventType==TContactViewEvent::EItemAdded && &aView == iView ) |
|
1071 { |
|
1072 //only start the next test when all the contact have been added to our view. |
|
1073 if (++iNumNotifications==iNumContacts) |
|
1074 { |
|
1075 iConductor.NextTest(); |
|
1076 } |
|
1077 } |
|
1078 } |
|
1079 |
|
1080 |
|
1081 // |
|
1082 // Main. |
|
1083 // |
|
1084 |
|
1085 /** |
|
1086 |
|
1087 @SYMTestCaseID PIM-T-APAC-0001 |
|
1088 |
|
1089 */ |
|
1090 |
|
1091 GLDEF_C TInt E32Main() |
|
1092 { |
|
1093 __UHEAP_MARK; |
|
1094 // UserHal::SetAutoSwitchOffBehavior(ESwitchOffDisabled); |
|
1095 test.Start(_L("@SYMTESTCaseID:PIM-T-APAC-0001 t_apac")); |
|
1096 |
|
1097 CActiveScheduler* scheduler=new CActiveScheduler; |
|
1098 if (scheduler) |
|
1099 { |
|
1100 CActiveScheduler::Install(scheduler); |
|
1101 CTrapCleanup* cleanup=CTrapCleanup::New(); |
|
1102 if (cleanup) |
|
1103 { |
|
1104 CTestConductor* tester=NULL; |
|
1105 TRAPD(err,tester=CTestConductor::NewL()); |
|
1106 test(err == KErrNone); |
|
1107 delete tester; |
|
1108 delete cleanup; |
|
1109 } |
|
1110 delete scheduler; |
|
1111 } |
|
1112 test.End(); |
|
1113 test.Close(); |
|
1114 __UHEAP_MARKEND; |
|
1115 return KErrNone; |
|
1116 } |