|
1 // Copyright (c) 1997-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 // Run as part T_DBASE2, tests find |
|
15 // |
|
16 // |
|
17 |
|
18 #include <e32test.h> |
|
19 #include <f32file.h> |
|
20 #include <s32file.h> |
|
21 #include <s32mem.h> |
|
22 #include <cntdb.h> |
|
23 #include <cntitem.h> |
|
24 #include <cntfield.h> |
|
25 #include <cntfldst.h> |
|
26 #include "T_UTILS.H" |
|
27 #include "T_DBASE2.H" |
|
28 |
|
29 class CAsyncFinder : public CBase, public MIdleFindObserver |
|
30 { |
|
31 public: |
|
32 ~CAsyncFinder(); |
|
33 void ConstructL(CContactDatabase *aContactDatabase, const TDesC& aText,const CContactItemFieldDef *aFieldDef); |
|
34 void ConstructL(CContactDatabase *aContactDatabase, const CDesCArray& aFindWords,const CContactTextDef *aTextDef,const TCallBack &aCallBack); |
|
35 inline CContactIdArray *TakeContactIds() {return(iFinder->TakeContactIds());}; |
|
36 inline TInt Error() const {return(iFinder->Error());}; |
|
37 protected: |
|
38 // from MIdleFindObserver |
|
39 void IdleFindCallback(); |
|
40 private: |
|
41 CIdleFinder *iFinder; |
|
42 }; |
|
43 |
|
44 CAsyncFinder::~CAsyncFinder() |
|
45 { |
|
46 delete iFinder; |
|
47 } |
|
48 |
|
49 void CAsyncFinder::ConstructL(CContactDatabase *aContactDatabase, const TDesC& aText,const CContactItemFieldDef *aFieldDef) |
|
50 { |
|
51 iFinder=aContactDatabase->FindAsyncL(aText, aFieldDef, this); |
|
52 } |
|
53 |
|
54 void CAsyncFinder::ConstructL(CContactDatabase *aContactDatabase, const CDesCArray& aFindWords,const CContactTextDef *aTextDef,const TCallBack &aCallBack) |
|
55 { |
|
56 if (aTextDef) |
|
57 iFinder=aContactDatabase->FindInTextDefAsyncL(aFindWords, aTextDef, this, aCallBack); |
|
58 else |
|
59 iFinder=aContactDatabase->FindInTextDefAsyncL(aFindWords, this, aCallBack); |
|
60 } |
|
61 |
|
62 void CAsyncFinder::IdleFindCallback() |
|
63 { |
|
64 if (iFinder->IsComplete()) |
|
65 CActiveScheduler::Stop(); |
|
66 } |
|
67 |
|
68 GLDEF_C TBool CompareIdArrays(CContactIdArray* aIds1,CContactIdArray* aIds2) |
|
69 { |
|
70 if (aIds1->Count()!=aIds2->Count()) |
|
71 return(EFalse); |
|
72 for(TInt loop=0;loop<aIds1->Count();loop++) |
|
73 { |
|
74 if ((*aIds1)[loop]!=(*aIds2)[loop]) |
|
75 return(EFalse); |
|
76 } |
|
77 return(ETrue); |
|
78 } |
|
79 |
|
80 GLDEF_C CContactIdArray* CreateIdArrayLC(TContactItemId *aId1, TContactItemId *aId2=NULL, TContactItemId *aId3=NULL, TContactItemId *aId4=NULL, TContactItemId *aId5=NULL) |
|
81 { |
|
82 CContactIdArray* ids=CContactIdArray::NewLC(); |
|
83 if (aId1) |
|
84 ids->AddL(*aId1); |
|
85 if (aId2) |
|
86 ids->AddL(*aId2); |
|
87 if (aId3) |
|
88 ids->AddL(*aId3); |
|
89 if (aId4) |
|
90 ids->AddL(*aId4); |
|
91 if (aId5) |
|
92 ids->AddL(*aId5); |
|
93 return(ids); |
|
94 } |
|
95 |
|
96 LOCAL_C CDesCArray *CreateFindWordsL(const TDesC &aFind1,const TDesC &aFind2,const TDesC &aFind3) |
|
97 { |
|
98 CDesCArray *desCA=new(ELeave) CDesCArrayFlat(5); |
|
99 CleanupStack::PushL(desCA); |
|
100 if (aFind1.Length()>0) |
|
101 desCA->AppendL(aFind1); |
|
102 if (aFind2.Length()>0) |
|
103 desCA->AppendL(aFind2); |
|
104 if (aFind3.Length()>0) |
|
105 desCA->AppendL(aFind3); |
|
106 CleanupStack::Pop(); // desCA |
|
107 return(desCA); |
|
108 } |
|
109 |
|
110 LOCAL_C void CheckResult(CContactIdArray* aIds,CContactIdArray* aResultIds) |
|
111 { |
|
112 if (aResultIds) |
|
113 test(CompareIdArrays(aIds,aResultIds)); |
|
114 else |
|
115 test(aIds->Count()==0); |
|
116 } |
|
117 |
|
118 LOCAL_C void runAsyncFindL(CAsyncFinder *aFinder, CContactIdArray* aResultIds) |
|
119 { |
|
120 CActiveScheduler::Start(); |
|
121 CContactIdArray* ids=aFinder->TakeContactIds(); |
|
122 CheckResult(ids,aResultIds); |
|
123 delete ids; |
|
124 } |
|
125 |
|
126 LOCAL_C TInt findWordSplitterL(TAny *aParams) |
|
127 { |
|
128 SFindInTextDefWordParser *parser=(SFindInTextDefWordParser *)aParams; |
|
129 const TText *ptr=parser->iSearchString->Ptr(); |
|
130 const TText *end=ptr+parser->iSearchString->Length(); |
|
131 const TText *startOfWord=NULL; |
|
132 FOREVER |
|
133 { |
|
134 if (ptr==end || !TChar(*ptr).IsAlphaDigit()) |
|
135 { |
|
136 if (startOfWord) |
|
137 { |
|
138 TPtrC addWord(startOfWord,ptr-startOfWord); |
|
139 parser->iWordArray->AppendL(addWord); |
|
140 startOfWord=NULL; |
|
141 } |
|
142 if (ptr==end) |
|
143 break; |
|
144 } |
|
145 else if (!startOfWord) |
|
146 startOfWord=ptr; |
|
147 ptr++; |
|
148 } |
|
149 return(KErrNone); |
|
150 } |
|
151 |
|
152 GLDEF_C void doDoFindInTextDefTestL(CDesCArray *aFindWords, CContactTextDef *aTextDef, CContactIdArray* aResultIds) |
|
153 { |
|
154 TCallBack callBack(findWordSplitterL); |
|
155 CAsyncFinder *finder=new(ELeave) CAsyncFinder; |
|
156 CleanupStack::PushL(finder); |
|
157 finder->ConstructL(CntTest->Db(),*aFindWords,aTextDef,callBack); |
|
158 runAsyncFindL(finder, aResultIds); |
|
159 CleanupStack::PopAndDestroy(); // finder |
|
160 // |
|
161 CContactIdArray* ids=NULL; |
|
162 if (aTextDef) |
|
163 ids=CntTest->Db()->FindInTextDefLC(*aFindWords,aTextDef,callBack); |
|
164 else |
|
165 ids=CntTest->Db()->FindInTextDefLC(*aFindWords,callBack); |
|
166 CheckResult(ids,aResultIds); |
|
167 CleanupStack::PopAndDestroy(); // ids |
|
168 } |
|
169 |
|
170 GLDEF_C void DoFindInTextDefTestL(CDesCArray *aFindWords, CContactTextDef *aTextDef, CContactIdArray* aResultIds) |
|
171 { |
|
172 CleanupStack::PushL(aFindWords); |
|
173 doDoFindInTextDefTestL(aFindWords, aTextDef, aResultIds); |
|
174 CContactTextDef* textDef=CContactTextDef::NewLC(); |
|
175 if (aTextDef) |
|
176 { |
|
177 for(TInt loop=0;loop<aTextDef->Count();loop++) |
|
178 textDef->AppendL((*aTextDef)[loop]); |
|
179 textDef->SetFallbackField(aTextDef->FallbackField()); |
|
180 } |
|
181 CntTest->Db()->SetTextDefinitionL(textDef); |
|
182 CleanupStack::Pop(); // textDef |
|
183 doDoFindInTextDefTestL(aFindWords, NULL, aResultIds); |
|
184 CntTest->Db()->SetTextDefinitionL(NULL); |
|
185 CleanupStack::Pop(); // aFindWords |
|
186 } |
|
187 |
|
188 GLDEF_C void DoFindInTextDefTestLD(CDesCArray *aFindWords, CContactTextDef *aTextDef, CContactIdArray* aResultIds) |
|
189 { |
|
190 DoFindInTextDefTestL(aFindWords, aTextDef, aResultIds); |
|
191 if (aFindWords->Count()>0) |
|
192 { |
|
193 CDesCArray *reverseArray=new(ELeave) CDesCArrayFlat(10); |
|
194 CleanupStack::PushL(reverseArray); |
|
195 for(TInt loop=aFindWords->Count()-1;loop>=0;loop--) |
|
196 reverseArray->AppendL((*aFindWords)[loop]); |
|
197 DoFindInTextDefTestL(reverseArray, aTextDef, aResultIds); |
|
198 CleanupStack::PopAndDestroy(); |
|
199 } |
|
200 delete aFindWords; |
|
201 } |
|
202 |
|
203 GLDEF_C void DoAsyncFindL(const TDesC &aText, CContactItemFieldDef *aFieldDef,CContactIdArray* aResultIds) |
|
204 { |
|
205 CAsyncFinder *finder=new(ELeave) CAsyncFinder; |
|
206 CleanupStack::PushL(finder); |
|
207 finder->ConstructL(CntTest->Db(),aText,aFieldDef); |
|
208 runAsyncFindL(finder, aResultIds); |
|
209 CleanupStack::PopAndDestroy(); // finder |
|
210 } |
|
211 |
|
212 GLDEF_C void DoAsyncFindL(const TDesC &aText, CContactItemFieldDef *aFieldDef, TInt aCount) |
|
213 { |
|
214 CAsyncFinder *finder=new(ELeave) CAsyncFinder; |
|
215 CleanupStack::PushL(finder); |
|
216 finder->ConstructL(CntTest->Db(),aText,aFieldDef); |
|
217 CActiveScheduler::Start(); |
|
218 CContactIdArray* ids=finder->TakeContactIds(); |
|
219 test(ids->Count()==aCount); |
|
220 delete ids; |
|
221 CleanupStack::PopAndDestroy(); // finder |
|
222 } |
|
223 |
|
224 /** |
|
225 |
|
226 @SYMTestCaseID PIM-T-FIND-0001 |
|
227 |
|
228 */ |
|
229 |
|
230 GLDEF_C void FindAsyncL() |
|
231 { |
|
232 test.Next(_L("@SYMTestCaseID:PIM-T-FIND-0001 Async search 1")); |
|
233 // |
|
234 TBuf<32> name; |
|
235 name.Format(KTestName,7); |
|
236 DoAsyncFindL(name,NULL,1); |
|
237 // |
|
238 test.Next(_L("Async search 2")); |
|
239 CContactItemFieldDef *fieldDef=new(ELeave) CContactItemFieldDef; |
|
240 CleanupStack::PushL(fieldDef); |
|
241 fieldDef->AppendL(KUidContactFieldFamilyName); |
|
242 DoAsyncFindL(_L("Test Name No"),fieldDef,CntTest->Db()->CountL()-3); // ..empty groups & own card |
|
243 CleanupStack::PopAndDestroy(); // fieldDef |
|
244 // |
|
245 test.Next(_L("Async search 3")); |
|
246 CContactItemFieldDef *fieldDef2=new(ELeave) CContactItemFieldDef; |
|
247 CleanupStack::PushL(fieldDef2); |
|
248 fieldDef2->AppendL(KUidContactFieldAddress); |
|
249 DoAsyncFindL(_L("Test Name No"),fieldDef2,0); |
|
250 CleanupStack::PopAndDestroy(); // fieldDef2 |
|
251 // |
|
252 #if defined(_DEBUG) |
|
253 CAsyncFinder *finder=new(ELeave) CAsyncFinder; |
|
254 CleanupStack::PushL(finder); |
|
255 TBuf<32> name2; |
|
256 name2.Format(KTestName,7); |
|
257 finder->ConstructL(CntTest->Db(),name2,NULL); |
|
258 __UHEAP_SETFAIL(RHeap::EDeterministic,10); |
|
259 CActiveScheduler::Start(); |
|
260 __UHEAP_RESET; |
|
261 // |
|
262 CContactIdArray* ids=finder->TakeContactIds(); |
|
263 test(finder->Error()==KErrNoMemory || finder->Error()==KErrNone); |
|
264 delete ids; |
|
265 CleanupStack::PopAndDestroy(); // finder |
|
266 #endif |
|
267 // |
|
268 CAsyncFinder *asyncFinder=new(ELeave) CAsyncFinder; |
|
269 asyncFinder->ConstructL(CntTest->Db(), _L("a"), NULL); |
|
270 delete asyncFinder; // Checks ids get deleted if not claimed with TakeContactIds() |
|
271 } |
|
272 |
|
273 LOCAL_C TContactItemId AddFindRecordL(const TDesC &aFirstName, const TDesC &aLastName, const TDesC &aCompanyName, const TDesC &aAddress) |
|
274 { |
|
275 CContactItem *item=CContactCard::NewLC(); |
|
276 if (aFirstName.Length()>0) |
|
277 SetNameL(*item,KUidContactFieldGivenName,KUidContactFieldVCardMapUnusedN,aFirstName,ETrue); |
|
278 if (aLastName.Length()>0) |
|
279 SetNameL(*item,KUidContactFieldFamilyName,KUidContactFieldVCardMapUnusedN,aLastName,ETrue); |
|
280 if (aCompanyName.Length()>0) |
|
281 SetNameL(*item,KUidContactFieldCompanyName,KUidContactFieldVCardMapORG,aCompanyName,ETrue); |
|
282 if (aAddress.Length()>0) |
|
283 SetNameL(*item,KUidContactFieldAddress,KUidContactFieldVCardMapADR,aAddress,ETrue); |
|
284 TContactItemId id=CntTest->Db()->AddNewContactL(*item); |
|
285 CleanupStack::PopAndDestroy(); // item |
|
286 return(id); |
|
287 } |
|
288 |
|
289 GLDEF_C void FindAsyncInTextDefL() |
|
290 { |
|
291 CContactTextDef* textDef1=CContactTextDef::NewLC(); |
|
292 textDef1->AppendL(TContactTextDefItem(KUidContactFieldGivenName)); |
|
293 textDef1->AppendL(TContactTextDefItem(KUidContactFieldFamilyName)); |
|
294 textDef1->SetFallbackField(KUidContactFieldCompanyName); |
|
295 CContactTextDef* textDef2=CContactTextDef::NewLC(); |
|
296 textDef2->AppendL(TContactTextDefItem(KUidContactFieldGivenName)); |
|
297 textDef2->AppendL(TContactTextDefItem(KUidContactFieldFamilyName)); |
|
298 textDef2->AppendL(TContactTextDefItem(KUidContactFieldCompanyName)); |
|
299 textDef2->SetFallbackField(KUidContactFieldAddress); |
|
300 // |
|
301 TContactItemId wally=AddFindRecordL(_L("Wally"),_L("Example"),_L("Example Comp Inc"),_L("")); |
|
302 TContactItemId vincent=AddFindRecordL(_L("Vincent"),_L("Jones"),_L(""),_L("")); |
|
303 TContactItemId wilbert=AddFindRecordL(_L("Wilbert"),_L("Example"),_L("Sample Test Name"),_L("")); |
|
304 TContactItemId vincent2=AddFindRecordL(_L("Vincent"),_L("Vincent"),_L(""),_L("")); |
|
305 TContactItemId death=AddFindRecordL(_L("Black"),_L("De'ath"),_L("Hell"),_L("Sample of ExampleH")); |
|
306 // |
|
307 CContactIdArray* wallyResults=CreateIdArrayLC(&wally); |
|
308 CContactIdArray* wombatResults=CreateIdArrayLC(&wally,&wilbert); |
|
309 CContactIdArray* vjResults=CreateIdArrayLC(&vincent); |
|
310 CContactIdArray* v2Results=CreateIdArrayLC(&vincent2); |
|
311 CContactIdArray* vjv2Results=CreateIdArrayLC(&vincent,&vincent2); |
|
312 CContactIdArray* deathResults=CreateIdArrayLC(&death); |
|
313 // |
|
314 CDesCArray *findWords=CreateFindWordsL(_L("Wally"),_L(""),_L("")); |
|
315 //chrisd: the behaviour of the new code has changed because if you pass a null |
|
316 //chrisd: textdef to ER5/ER6 or 6.1 it doesn't find anything |
|
317 DoFindInTextDefTestL(findWords, NULL, NULL); // No text def defined |
|
318 // |
|
319 DoFindInTextDefTestLD(findWords, textDef1, wallyResults); |
|
320 findWords=CreateFindWordsL(_L("Wally"),_L("NotFound"),_L("")); |
|
321 DoFindInTextDefTestLD(findWords, textDef1, NULL); |
|
322 findWords=CreateFindWordsL(_L("Wally"),_L("Example"),_L("")); |
|
323 DoFindInTextDefTestLD(findWords, textDef1, wallyResults); |
|
324 findWords=CreateFindWordsL(_L("Wally"),_L("Example"),_L("xxx")); |
|
325 DoFindInTextDefTestLD(findWords, textDef1, NULL); |
|
326 findWords=CreateFindWordsL(_L("W"),_L("Example"),_L("")); |
|
327 DoFindInTextDefTestLD(findWords, textDef1, wombatResults); |
|
328 findWords=CreateFindWordsL(_L("Wally"),_L("Wally"),_L("")); |
|
329 DoFindInTextDefTestLD(findWords, textDef1, NULL); |
|
330 findWords=CreateFindWordsL(_L("Example"),_L("Example"),_L("")); |
|
331 DoFindInTextDefTestLD(findWords, textDef1, wallyResults); |
|
332 findWords=CreateFindWordsL(_L("Example"),_L("Example"),_L("Example")); |
|
333 DoFindInTextDefTestLD(findWords, textDef1, NULL); |
|
334 findWords=CreateFindWordsL(_L("Example"),_L("Comp"),_L("Inc")); |
|
335 //chrisd: new code doesn't find anything here and should have - this is |
|
336 //chrisd: all words are contained in the company field |
|
337 DoFindInTextDefTestLD(findWords, textDef1, wallyResults); |
|
338 // |
|
339 findWords=CreateFindWordsL(_L("ample"),_L("omp"),_L("lly")); |
|
340 DoFindInTextDefTestLD(findWords, textDef1, NULL); |
|
341 findWords=CreateFindWordsL(_L("Example"),_L("Comp"),_L("Inc")); |
|
342 //chrisd: new code doesn't find anything here and should have - this is |
|
343 //chrisd: all words are contained in the company field |
|
344 DoFindInTextDefTestLD(findWords, textDef1, wallyResults); |
|
345 // |
|
346 findWords=CreateFindWordsL(_L("Vincent"),_L("J"),_L("")); |
|
347 DoFindInTextDefTestLD(findWords, textDef1, vjResults); |
|
348 findWords=CreateFindWordsL(_L("Vincent"),_L("V"),_L("")); |
|
349 DoFindInTextDefTestLD(findWords, textDef1, v2Results); |
|
350 findWords=CreateFindWordsL(_L("Vincent"),_L(""),_L("")); |
|
351 DoFindInTextDefTestLD(findWords, textDef1, vjv2Results); |
|
352 |
|
353 findWords=CreateFindWordsL(_L("De"),_L("Ath"),_L("")); |
|
354 //chrisd: new code fails here |
|
355 //chrisd: last name contains both first & last names (PC PIM syncs both to one field) |
|
356 DoFindInTextDefTestLD(findWords, textDef1, deathResults); |
|
357 findWords=CreateFindWordsL(_L("De"),_L("Ath"),_L("ExampleH")); |
|
358 DoFindInTextDefTestLD(findWords, textDef1, NULL); |
|
359 //chrisd: new code fails here |
|
360 //chrisd: last name contains first and last |
|
361 findWords=CreateFindWordsL(_L("De"),_L("Ath"),_L("ExampleH")); |
|
362 DoFindInTextDefTestLD(findWords, textDef2, deathResults); |
|
363 findWords=CreateFindWordsL(_L("ExampleH"),_L(""),_L("")); |
|
364 //chrisd:one word at the end - partial match - so doesn't need to match |
|
365 DoFindInTextDefTestLD(findWords, textDef1, NULL); |
|
366 findWords=CreateFindWordsL(_L("ExampleH"),_L(""),_L("")); |
|
367 //chrisd:one word at the end - partial match - so doesn't need to match |
|
368 DoFindInTextDefTestLD(findWords, textDef2, deathResults); |
|
369 findWords=CreateFindWordsL(_L("of"),_L("Sample"),_L("ExampleH")); |
|
370 //chrisd:all words are in one field - this doesn't need to match |
|
371 DoFindInTextDefTestLD(findWords, textDef2, deathResults); |
|
372 // |
|
373 CntTest->DeleteContact(wally); |
|
374 CntTest->DeleteContact(vincent); |
|
375 CntTest->DeleteContact(wilbert); |
|
376 CntTest->DeleteContact(vincent2); |
|
377 CntTest->DeleteContact(death); |
|
378 CleanupStack::PopAndDestroy(6); // wallyResults,wombatResults,vjResults,v2Results,deathResults |
|
379 CleanupStack::PopAndDestroy(2); // textDef1,textDef2 |
|
380 } |
|
381 |
|
382 GLDEF_C void FindL() |
|
383 { |
|
384 CContactItemFieldDef* fieldDef=new(ELeave) CContactItemFieldDef; |
|
385 CleanupStack::PushL(fieldDef); |
|
386 fieldDef->AppendL(KUidContactFieldAddress); |
|
387 fieldDef->AppendL(KUidContactFieldFamilyName); |
|
388 fieldDef->AppendL(KUidContactFieldGivenName); |
|
389 fieldDef->AppendL(KUidContactFieldCompanyName); |
|
390 fieldDef->AppendL(KUidContactFieldBirthday); |
|
391 fieldDef->AppendL(KUidContactFieldTemplateLabel); |
|
392 // |
|
393 test.Next(_L("Search for full given name")); |
|
394 TBuf<16> name; |
|
395 name.Format(KTestName,7); |
|
396 CContactIdArray* ids=CntTest->Db()->FindLC(name,fieldDef); |
|
397 test(ids->Count()==1); |
|
398 CleanupStack::PopAndDestroy(); // ids |
|
399 |
|
400 test.Next(_L("Search for full given name in only contact groups")); |
|
401 // same test but only looking in groups so shouldn't find anything |
|
402 name.Format(KTestName,7); |
|
403 CntTest->Db()->SetDbViewContactType(KUidContactGroup); |
|
404 ids=CntTest->Db()->FindLC(name,fieldDef); |
|
405 test(ids->Count()==0); // nothing found. |
|
406 CleanupStack::PopAndDestroy(); // ids |
|
407 |
|
408 CntTest->Db()->SetDbViewContactType(KUidContactItem); //reset view |
|
409 test.Next(_L("Search for partial name")); |
|
410 TBuf<8> shortName(name.Left(8)); |
|
411 ids=CntTest->Db()->FindLC(shortName,fieldDef); |
|
412 test(ids->Count()==KTotalNumRecords); |
|
413 CleanupStack::PopAndDestroy(); // ids |
|
414 |
|
415 shortName=name.Right(8); |
|
416 ids=CntTest->Db()->FindLC(shortName,fieldDef); |
|
417 test(ids->Count()==1); |
|
418 CleanupStack::PopAndDestroy(); // ids |
|
419 shortName=name.Mid(3,8); |
|
420 ids=CntTest->Db()->FindLC(shortName,fieldDef); |
|
421 test(ids->Count()>1); |
|
422 CleanupStack::PopAndDestroy(); // ids |
|
423 |
|
424 test.Next(_L("Search for full address")); |
|
425 TBuf<16> address; |
|
426 address.Format(KTestAddress,11); |
|
427 ids=CntTest->Db()->FindLC(address,fieldDef); |
|
428 test(ids->Count()==1); |
|
429 CleanupStack::PopAndDestroy(); // ids |
|
430 |
|
431 test.Next(_L("NULL search string")); |
|
432 ids=CntTest->Db()->FindLC(_L(""),fieldDef); |
|
433 test(ids->Count()==KTotalNumRecords + 3); // 2 groups + 1 owncard |
|
434 CleanupStack::PopAndDestroy(); // ids |
|
435 |
|
436 // look in just the groups |
|
437 test.Next(_L("NULL search string in GROUPS")); |
|
438 TInt groupCount = CntTest->Db()->GroupCount(); |
|
439 CntTest->Db()->SetDbViewContactType(KUidContactGroup); |
|
440 ids=CntTest->Db()->FindLC(_L(""),fieldDef); |
|
441 test(ids->Count()==groupCount); |
|
442 CleanupStack::PopAndDestroy(); // ids |
|
443 // |
|
444 ids=CntTest->Db()->FindLC(_L("New Group"),fieldDef); |
|
445 test(ids->Count()==groupCount); |
|
446 CleanupStack::PopAndDestroy(); // ids |
|
447 // |
|
448 CntTest->Db()->SetDbViewContactType(KUidContactItem); |
|
449 |
|
450 // look in just the OWN CARD |
|
451 test.Next(_L("NULL search string in OWN CARD")); |
|
452 CntTest->Db()->SetDbViewContactType(KUidContactOwnCard); |
|
453 ids=CntTest->Db()->FindLC(_L(""),fieldDef); |
|
454 test(ids->Count()==1); |
|
455 CleanupStack::PopAndDestroy(); // ids |
|
456 // |
|
457 CntTest->Db()->SetDbViewContactType(KUidContactItem); |
|
458 |
|
459 test.Next(_L("Search for partial address")); |
|
460 TBuf<8> shortAddress(address.Left(6)); |
|
461 ids=CntTest->Db()->FindLC(shortAddress,fieldDef); |
|
462 test(ids->Count()==KTotalNumRecords/2); |
|
463 CleanupStack::PopAndDestroy(); // ids |
|
464 shortAddress=address.Right(6); |
|
465 ids=CntTest->Db()->FindLC(shortAddress,fieldDef); |
|
466 test(ids->Count()==1); |
|
467 CleanupStack::PopAndDestroy(); // ids |
|
468 shortAddress=address.Mid(3,6); |
|
469 ids=CntTest->Db()->FindLC(shortAddress,fieldDef); |
|
470 test(ids->Count()>1); |
|
471 TContactItemId deleteItem=(*ids)[0]; |
|
472 CleanupStack::PopAndDestroy(); // ids |
|
473 // |
|
474 CntTest->AdjustContactAccessCountL(deleteItem,1); |
|
475 CntTest->Db()->DeleteContactL(deleteItem); |
|
476 // |
|
477 ids=CntTest->Db()->FindLC(shortAddress,NULL); |
|
478 test(ids->Count()>1); |
|
479 CleanupStack::PopAndDestroy(); // ids |
|
480 // |
|
481 CntTest->AdjustContactAccessCountL(deleteItem,-1); |
|
482 ids=CntTest->Db()->FindLC(shortAddress,NULL); |
|
483 test(ids->Count()>1); |
|
484 CleanupStack::PopAndDestroy(); // ids |
|
485 // |
|
486 ids=CntTest->Db()->FindLC(_L("*"),NULL); |
|
487 test(ids->Count()==0); // literal matching now and no asterisks in this file! |
|
488 CleanupStack::PopAndDestroy(); // ids |
|
489 // |
|
490 ids=CntTest->Db()->FindLC(shortAddress,fieldDef); |
|
491 test(ids->Count()>1); |
|
492 CleanupStack::PopAndDestroy(); // ids |
|
493 // |
|
494 CleanupStack::PopAndDestroy(); // fieldDef |
|
495 } |
|
496 |
|
497 GLDEF_C TContactItemId AddContactForFindL(const TDesC& aName) |
|
498 { |
|
499 CContactItem* item=CContactCard::NewLC(); |
|
500 SetNameL(*item,KUidContactFieldGivenName,KUidContactFieldVCardMapUnusedN,aName,ETrue); |
|
501 item->SetTemplateRefId(KGoldenTemplateId); |
|
502 TContactItemId id=CntTest->Db()->AddNewContactL(*item); |
|
503 CleanupStack::PopAndDestroy(item); |
|
504 return id; |
|
505 } |
|
506 |
|
507 GLDEF_C TContactItemId AddContactWithAddressL(const TDesC& aName, const TDesC& anAddress) |
|
508 { |
|
509 CContactItem* item=CContactCard::NewLC(); |
|
510 item->SetTemplateRefId(KGoldenTemplateId); |
|
511 SetNameL(*item,KUidContactFieldGivenName,KUidContactFieldVCardMapUnusedN,aName,ETrue); |
|
512 SetNameL(*item,KUidContactFieldAddress, KUidContactFieldVCardMapUnusedN,anAddress,ETrue); |
|
513 TContactItemId id=CntTest->Db()->AddNewContactL(*item); |
|
514 CleanupStack::PopAndDestroy(item); |
|
515 return id; |
|
516 } |
|
517 |
|
518 // |
|
519 // Testcode for find defect |
|
520 // EDNAPIN-4L4EN9 "Wildcards should be treated as normal charactersin search" |
|
521 // |
|
522 // Test case: |
|
523 // a contacts database containing contacts with names |
|
524 // *,?,chris,c?ris,c*s,??,???? |
|
525 // |
|
526 // '*' matches contacts with fields containing '*' |
|
527 // '?' matches contacts with fields containing '?' |
|
528 // 'chris' matches contacts with fields containing 'chris' but not 'c*s' or 'c?ris' |
|
529 // 'c?ris' matches contacts with fields containing 'c?ris' but not 'c*s' or 'chris' |
|
530 // 'c*' matches contacts with fields containing 'c*' but not 'chris' or 'c?ris' |
|
531 // '??' matches contacts with fields containing '??' but not '?', 'chris', 'c*s' etc. |
|
532 // |
|
533 GLDEF_C void FindDefectL() |
|
534 { |
|
535 test.Next(_L("Find defect")); |
|
536 CntTest->CreateDatabaseL(); |
|
537 _LIT(KAsterisk,"*"); |
|
538 _LIT(KQuestionMark,"?"); |
|
539 _LIT(KChris,"chris"); |
|
540 _LIT(KChrisQuestion,"c?ris"); |
|
541 _LIT(KChrisAsterisk,"c*s"); |
|
542 _LIT(KTwoQuestionMarks,"??"); |
|
543 _LIT(KFourQuestionMarks,"????"); |
|
544 TContactItemId asterisk = AddContactForFindL(KAsterisk()); |
|
545 AddContactForFindL(KQuestionMark()); |
|
546 TContactItemId chris = AddContactForFindL(KChris()); |
|
547 TContactItemId chrisquestion = AddContactForFindL(KChrisQuestion()); |
|
548 TContactItemId chrisasterisk = AddContactForFindL(KChrisAsterisk()); |
|
549 AddContactForFindL(KTwoQuestionMarks()); |
|
550 AddContactForFindL(KFourQuestionMarks()); |
|
551 |
|
552 |
|
553 CContactItemFieldDef* fieldDef=new(ELeave) CContactItemFieldDef; |
|
554 CleanupStack::PushL(fieldDef); |
|
555 fieldDef->AppendL(KUidContactFieldGivenName); |
|
556 |
|
557 // * |
|
558 CContactIdArray* ids=CntTest->Db()->FindLC(KAsterisk,fieldDef); |
|
559 test(ids->Count()==2); |
|
560 test((*ids)[0]==asterisk); |
|
561 CleanupStack::PopAndDestroy(); // ids |
|
562 |
|
563 // ? |
|
564 ids=CntTest->Db()->FindLC(KQuestionMark,fieldDef); |
|
565 test(ids->Count()==4); // should be 4 |
|
566 CleanupStack::PopAndDestroy(); // ids |
|
567 |
|
568 // chris |
|
569 ids=CntTest->Db()->FindLC(KChris,fieldDef); |
|
570 test(ids->Count()==1); // should be 1 |
|
571 test((*ids)[0]==chris); |
|
572 CleanupStack::PopAndDestroy(); // ids |
|
573 |
|
574 // c?ris |
|
575 ids=CntTest->Db()->FindLC(KChrisQuestion,fieldDef); |
|
576 test(ids->Count()==1); // should be 1 |
|
577 test((*ids)[0]==chrisquestion); |
|
578 CleanupStack::PopAndDestroy(); // ids |
|
579 |
|
580 // c* |
|
581 ids=CntTest->Db()->FindLC(KChrisAsterisk,fieldDef); |
|
582 test(ids->Count()==1); // should be 1 |
|
583 test((*ids)[0]==chrisasterisk); |
|
584 CleanupStack::PopAndDestroy(); // ids |
|
585 |
|
586 // ?? |
|
587 ids=CntTest->Db()->FindLC(KTwoQuestionMarks,fieldDef); |
|
588 test(ids->Count()==2); // should be 2 |
|
589 CleanupStack::PopAndDestroy(); // ids |
|
590 |
|
591 CleanupStack::PopAndDestroy(fieldDef); |
|
592 CntTest->CloseDatabase(); |
|
593 CntTest->DeleteDatabaseL(); |
|
594 }; |
|
595 |
|
596 GLDEF_C void FindAndCheckL(const TDesC& aStr, const TInt aNum, const CContactItemFieldDef* const aFieldDef) |
|
597 { |
|
598 CContactIdArray* const ids = CntTest->Db()->FindLC(aStr,aFieldDef); |
|
599 test(aNum == ids->Count()); |
|
600 CleanupStack::PopAndDestroy(ids); |
|
601 } |
|
602 |
|
603 GLDEF_C void FindScandinavianLettersL() |
|
604 { |
|
605 test.Next(_L("Scandinavian Letters defect")); |
|
606 CntTest->CreateDatabaseL(); |
|
607 |
|
608 //Scandinavian words with their conterparts without accents. |
|
609 _LIT(KMalmoS,"Malm\xF6"); //Malmö |
|
610 _LIT(KMalmo,"Malmo"); |
|
611 _LIT(KAraS,"\xC5ra"); //Åra |
|
612 _LIT(KAra,"Ara"); |
|
613 _LIT(KAtaS,"\xC4ta"); //Äta |
|
614 _LIT(KAta,"Ata"); |
|
615 |
|
616 //Adding some contacts with Scandinavian letter in them. |
|
617 //Note that Name is stored in separate field while address is in the BLOB |
|
618 AddContactWithAddressL(KAraS, KMalmoS); |
|
619 AddContactWithAddressL(KAtaS, KAtaS); |
|
620 AddContactWithAddressL(KAtaS, KAraS); |
|
621 AddContactWithAddressL(KMalmoS, KMalmoS); |
|
622 |
|
623 //Search only by name column |
|
624 CContactItemFieldDef* fieldDef=new(ELeave) CContactItemFieldDef; |
|
625 CleanupStack::PushL(fieldDef); |
|
626 fieldDef->AppendL(KUidContactFieldGivenName); |
|
627 |
|
628 FindAndCheckL(KAta, 2, fieldDef); |
|
629 FindAndCheckL(KAra, 1, fieldDef); |
|
630 FindAndCheckL(KMalmo,1, fieldDef); |
|
631 |
|
632 //Search only by address column |
|
633 fieldDef->Delete(0); |
|
634 fieldDef->AppendL(KUidContactFieldAddress); |
|
635 test(fieldDef->Count() == 1); |
|
636 |
|
637 // Uncomment when DBMS collation problem will be sorted out. |
|
638 FindAndCheckL(KMalmo,2, fieldDef); |
|
639 FindAndCheckL(KAra, 1, fieldDef); |
|
640 FindAndCheckL(KAta,1, fieldDef); |
|
641 |
|
642 CleanupStack::PopAndDestroy(fieldDef); |
|
643 CntTest->CloseDatabase(); |
|
644 CntTest->DeleteDatabaseL(); |
|
645 } |
|
646 |
|
647 GLDEF_C void DoFindL(const TDesC &aTextToFind, CContactItemFieldDef *aFieldDef, TInt aCount) |
|
648 { |
|
649 CContactIdArray* matchList=CntTest->Db()->FindLC(aTextToFind,aFieldDef); |
|
650 |
|
651 const TInt numIds=matchList->Count(); |
|
652 RDebug::Print(_L("Matched %d contact(s) of %d expected"),numIds,aCount); |
|
653 if(numIds!=aCount) |
|
654 { |
|
655 RDebug::Print(_L("FAILED!")); |
|
656 } |
|
657 test(numIds==aCount); |
|
658 CleanupStack::PopAndDestroy(); // matchList. |
|
659 } |
|
660 |
|
661 GLDEF_C void FindNameInFirstNameFieldL(const TDesC& aTextToFind, const TInt aNumExpectedFinds,TBool aAsync=EFalse) |
|
662 { |
|
663 RDebug::Print(_L("Find %S in Given name field"),&aTextToFind); |
|
664 CContactItemFieldDef* def=new(ELeave) CContactItemFieldDef(); |
|
665 CleanupStack::PushL(def); |
|
666 def->AppendL(KUidContactFieldGivenName); |
|
667 if(!aAsync) |
|
668 { |
|
669 DoFindL(aTextToFind,def,aNumExpectedFinds); |
|
670 } |
|
671 else |
|
672 { |
|
673 DoAsyncFindL(aTextToFind,def,aNumExpectedFinds); |
|
674 } |
|
675 CleanupStack::PopAndDestroy(); // def. |
|
676 } |
|
677 |
|
678 GLDEF_C void FindNameInLastNameFieldL(const TDesC& aTextToFind, const TInt aNumExpectedFinds,TBool aAsync=EFalse) |
|
679 { |
|
680 RDebug::Print(_L("Find %S in Family name field"),&aTextToFind); |
|
681 CContactItemFieldDef* def=new(ELeave) CContactItemFieldDef(); |
|
682 CleanupStack::PushL(def); |
|
683 def->AppendL(KUidContactFieldFamilyName); |
|
684 if(!aAsync) |
|
685 { |
|
686 DoFindL(aTextToFind,def,aNumExpectedFinds); |
|
687 } |
|
688 else |
|
689 { |
|
690 DoAsyncFindL(aTextToFind,def,aNumExpectedFinds); |
|
691 } |
|
692 CleanupStack::PopAndDestroy(); // def. |
|
693 } |
|
694 |
|
695 GLDEF_C void FindInAllFieldsL(const TDesC& aTextToFind, const TInt aNumExpectedFinds,TBool aAsync=EFalse) |
|
696 { |
|
697 RDebug::Print(_L("Find %S in All fields"),&aTextToFind); |
|
698 CContactItemFieldDef* def=new(ELeave) CContactItemFieldDef(); |
|
699 CleanupStack::PushL(def); |
|
700 def->AppendL(KUidContactFieldMatchAll); |
|
701 if(!aAsync) |
|
702 { |
|
703 DoFindL(aTextToFind,def,aNumExpectedFinds); |
|
704 } |
|
705 else |
|
706 { |
|
707 DoAsyncFindL(aTextToFind,def,aNumExpectedFinds); |
|
708 } |
|
709 CleanupStack::PopAndDestroy(); // def. |
|
710 } |
|
711 |
|
712 GLDEF_C void FindInCompanyFieldL(const TDesC& aTextToFind, const TInt aNumExpectedFinds,TBool aAsync=EFalse) |
|
713 { |
|
714 RDebug::Print(_L("Find %S in Company name field"),&aTextToFind); |
|
715 CContactItemFieldDef* def=new(ELeave) CContactItemFieldDef(); |
|
716 CleanupStack::PushL(def); |
|
717 def->AppendL(KUidContactFieldCompanyName); |
|
718 if(!aAsync) |
|
719 { |
|
720 DoFindL(aTextToFind,def,aNumExpectedFinds); |
|
721 } |
|
722 else |
|
723 { |
|
724 DoAsyncFindL(aTextToFind,def,aNumExpectedFinds); |
|
725 } |
|
726 CleanupStack::PopAndDestroy(); // def. |
|
727 } |
|
728 |
|
729 /** |
|
730 @SYMTestCaseID PIM-T-FIND-INC049017-0001 |
|
731 @SYMTestType CT |
|
732 @SYMTestPriority High |
|
733 @SYMDEF INC049017 |
|
734 @SYMTestCaseDependencies cnttutil |
|
735 @SYMTestCaseDesc Tests that Identity fields are searched when FindAsyncL and FindLC are used with KUidContactFieldMatchAll. |
|
736 @SYMTestActions Create a contact database and add four contacts. |
|
737 Search the database by using identity fields: GivenName, FamilyName and CompanyName. |
|
738 Search for contacts by providing a name and using KUidContactFieldMatchAll. |
|
739 Perform the search synchronously and asynchronously. |
|
740 @SYMTestExpectedResults Contacts are found by given name, family name or company name when using KUidContactFieldMatchAll. |
|
741 */ |
|
742 |
|
743 GLDEF_C void FindUsingKUidContactFieldMatchAllL() |
|
744 { |
|
745 //create the database |
|
746 CntTest->CreateDatabaseL(); |
|
747 |
|
748 //add the contacts |
|
749 //AddFindRecordL(const TDesC &aFirstName, const TDesC &aLastName, const TDesC &aCompanyName, const TDesC &aAddress) |
|
750 AddFindRecordL(_L("NameR"),_L("NameJ"),_L("Symbian Foundation"),_L(" ")); |
|
751 AddFindRecordL(_L("NameAm"),_L("NameJ"),_L("Symbian Foundation"),_L(" ")); |
|
752 AddFindRecordL(_L("NameB"),_L("NameT"),_L("Test NameH"),_L(" ")); |
|
753 AddFindRecordL(_L("NameC"),_L("NameAn"),_L("Test Soft Kicks"),_L(" ")); |
|
754 |
|
755 //start of tests for defect where identity fields were not searched when using KUidMatchInAllFields |
|
756 test.Next(_L("@SYMTestCaseID:PIM-T-FIND-INC049017-0001 FINDING CONTACTS BY NAME FROM GIVEN NAME FIELD.")); |
|
757 { |
|
758 FindNameInFirstNameFieldL(_L("NameC"),1); |
|
759 FindNameInFirstNameFieldL(_L("NameT"),0); |
|
760 FindNameInFirstNameFieldL(_L("e"),4); |
|
761 } |
|
762 |
|
763 test.Next(_L("FINDING CONTACTS BY NAME FROM FAMILY NAME FIELD")); |
|
764 { |
|
765 FindNameInLastNameFieldL(_L("NameT"),1); |
|
766 FindNameInLastNameFieldL(_L("NameJ"),2); |
|
767 FindNameInLastNameFieldL(_L("N"),4); |
|
768 FindNameInLastNameFieldL(_L("NameC"),0); |
|
769 } |
|
770 |
|
771 test.Next(_L("FINDING CONTACTS BY NAME FROM ALL FIELDS")); |
|
772 { |
|
773 FindInAllFieldsL(_L("NameB"),1); |
|
774 FindInAllFieldsL(_L("NameJ"),2); |
|
775 FindInAllFieldsL(_L("r"),1); |
|
776 FindInAllFieldsL(_L("xxxxxxxxx"),0); |
|
777 } |
|
778 |
|
779 test.Next(_L("FINDING CONTACTS BY COMPANY FROM COMPANY NAME FIELD")); |
|
780 { |
|
781 FindInCompanyFieldL(_L("NameB"),0); |
|
782 FindInCompanyFieldL(_L("Test NameH"),1); |
|
783 FindInCompanyFieldL(_L("Symbian Foundation"),2); |
|
784 FindInCompanyFieldL(_L("s"),4); |
|
785 } |
|
786 |
|
787 test.Next(_L("FINDING CONTACTS BY COMPANY FROM ALL FIELDS")); |
|
788 { |
|
789 FindInAllFieldsL(_L("Kick"),1); |
|
790 FindInAllFieldsL(_L("Test NameH"),1); |
|
791 FindInAllFieldsL(_L("Symbian Foundation"),2); |
|
792 FindInAllFieldsL(_L("s"),4); |
|
793 } |
|
794 //end of tests for defect where identity fields were not searched when using KUidMatchInAllFields |
|
795 |
|
796 //start of Async tests for defect where identity fields were not searched when using KUidMatchInAllFields |
|
797 test.Next(_L("FINDING CONTACTS BY NAME FROM GIVEN NAME FIELD ASYNCHRONOUSLY")); |
|
798 { |
|
799 FindNameInFirstNameFieldL(_L("NameC"),1,ETrue); |
|
800 FindNameInFirstNameFieldL(_L("NameT"),0,ETrue); |
|
801 FindNameInFirstNameFieldL(_L("e"),4,ETrue); |
|
802 } |
|
803 |
|
804 test.Next(_L("FINDING CONTACTS BY NAME FROM FAMILY NAME FIELD ASYNCHRONOUSLY")); |
|
805 { |
|
806 FindNameInLastNameFieldL(_L("NameT"),1,ETrue); |
|
807 FindNameInLastNameFieldL(_L("NameJ"),2,ETrue); |
|
808 FindNameInLastNameFieldL(_L("m"),4,ETrue); |
|
809 FindNameInLastNameFieldL(_L("NameC"),0,ETrue); |
|
810 } |
|
811 |
|
812 test.Next(_L("FINDING CONTACTS BY NAME FROM ALL FIELDS ASYNCHRONOUSLY")); |
|
813 { |
|
814 FindInAllFieldsL(_L("NameB"),1,ETrue); |
|
815 FindInAllFieldsL(_L("NameJ"),2,ETrue); |
|
816 FindInAllFieldsL(_L("r"),1,ETrue); |
|
817 FindInAllFieldsL(_L("xxxxxxxxx"),0,ETrue); |
|
818 } |
|
819 |
|
820 test.Next(_L("FINDING CONTACTS BY COMPANY FROM COMPANY NAME FIELD ASYNCHRONOUSLY")); |
|
821 { |
|
822 FindInCompanyFieldL(_L("NameB"),0,ETrue); |
|
823 FindInCompanyFieldL(_L("Test NameH"),1,ETrue); |
|
824 FindInCompanyFieldL(_L("Symbian Foundation"),2,ETrue); |
|
825 FindInCompanyFieldL(_L("s"),4,ETrue); |
|
826 } |
|
827 |
|
828 test.Next(_L("FINDING CONTACTS BY COMPANY FROM ALL FIELDS ASYNCHRONOUSLY")); |
|
829 { |
|
830 FindInAllFieldsL(_L("Kick"),1,ETrue); |
|
831 FindInAllFieldsL(_L("Test NameH"),1,ETrue); |
|
832 FindInAllFieldsL(_L("Symbian Foundation"),2,ETrue); |
|
833 FindInAllFieldsL(_L("s"),4,ETrue); |
|
834 } |
|
835 //end of Async tests for defect where identity fields were not searched when using KUidMatchInAllFields |
|
836 |
|
837 CntTest->CloseDatabase(); |
|
838 CntTest->DeleteDatabaseL(); |
|
839 } |