|
1 /* |
|
2 * Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Symbian Foundation License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * ?description_line |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDES |
|
21 #include "FT_CPosTp130.h" |
|
22 #include "FT_LandmarkConstants.h" |
|
23 #include <EPos_CPosLmMultiDbSearch.h> |
|
24 #include <EPos_CPosLmTextCriteria.h> |
|
25 #include <EPos_CPosLmDatabaseManager.h> |
|
26 #include <EPos_CPosLmItemIterator.h> |
|
27 #include <EPos_TPosLmSortPref.h> |
|
28 #include <EPos_CPosLmCatNameCriteria.h> |
|
29 #include "badesca.h" |
|
30 |
|
31 // CONSTANTS |
|
32 const TInt KNrOfDatabases = 5; |
|
33 _LIT(KSearchPattern, "*e*"); |
|
34 |
|
35 class CNamedLmItem : public CBase |
|
36 { |
|
37 public: |
|
38 ~CNamedLmItem() { delete iName; }; |
|
39 TPosLmItemId iId; |
|
40 HBufC* iName; |
|
41 |
|
42 static TInt CompareByName( const CNamedLmItem& aLeft, const CNamedLmItem& aRight ) |
|
43 { |
|
44 return aLeft.iName->CompareC( *aRight.iName ); |
|
45 }; |
|
46 }; |
|
47 |
|
48 // ================= LOCAL FUNCTIONS ======================= |
|
49 |
|
50 void ResetAndDestroy(TAny* aAny) |
|
51 { |
|
52 RPointerArray<CPosLmItemIterator>* pointerArray = |
|
53 reinterpret_cast <RPointerArray<CPosLmItemIterator>*> (aAny); |
|
54 pointerArray->ResetAndDestroy(); |
|
55 } |
|
56 |
|
57 void ResetAndDestroyNamedLmItem(TAny* aAny) |
|
58 { |
|
59 RPointerArray<CNamedLmItem>* pointerArray = |
|
60 reinterpret_cast <RPointerArray<CNamedLmItem>*> (aAny); |
|
61 pointerArray->ResetAndDestroy(); |
|
62 } |
|
63 |
|
64 // ================= MEMBER FUNCTIONS ======================= |
|
65 // --------------------------------------------------------- |
|
66 // CPosTp130::InitTestL |
|
67 // |
|
68 // (other items were commented in a header). |
|
69 // --------------------------------------------------------- |
|
70 // |
|
71 void CPosTp130::InitTestL() |
|
72 { |
|
73 CLandmarkTestProcedureBase::InitTestL(); |
|
74 |
|
75 // PrepareDatabases |
|
76 const TInt KNrOfDatabases = 5; |
|
77 RemoveAllLmDatabasesL(); |
|
78 CopyTestDbFileL(KDb20); |
|
79 CopyTestDbFileL(KDb40); |
|
80 CopyTestDbFileL(KDb60); |
|
81 CopyTestDbFileL(KDb80); |
|
82 CopyTestDbFileL(KDb105); |
|
83 |
|
84 // List databases |
|
85 CPosLmDatabaseManager* dbMan = CPosLmDatabaseManager::NewL(); |
|
86 CleanupStack::PushL(dbMan); |
|
87 iDbUris = dbMan->ListDatabasesLC(); |
|
88 CleanupStack::Pop(iDbUris); |
|
89 AssertTrueSecL(iDbUris->Count() == KNrOfDatabases, _L("Wrong number of test databases!")); |
|
90 CleanupStack::PopAndDestroy(dbMan); |
|
91 |
|
92 iDbSearcher = CPosLmMultiDbSearch::NewL(*iDbUris); |
|
93 |
|
94 // Initialize expected landmark search result |
|
95 |
|
96 for ( TInt i = 0; i < iDbUris->Count(); i++ ) |
|
97 { |
|
98 RIdArray* lmArray = new (ELeave) RIdArray; |
|
99 InitExpectedResultsL( (*iDbUris)[i], *lmArray, ETrue ); |
|
100 iExpectedLmResult.AppendL( lmArray ); |
|
101 |
|
102 RIdArray* catArray = new (ELeave) RIdArray; |
|
103 InitExpectedResultsL( (*iDbUris)[i], *catArray, EFalse ); |
|
104 iExpectedCatResult.AppendL( catArray ); |
|
105 } |
|
106 |
|
107 } |
|
108 |
|
109 // --------------------------------------------------------- |
|
110 // CPosTp130::CloseTest |
|
111 // |
|
112 // (other items were commented in a header). |
|
113 // --------------------------------------------------------- |
|
114 // |
|
115 void CPosTp130::CloseTest() |
|
116 { |
|
117 delete iDbUris; |
|
118 delete iDbSearcher; |
|
119 for (TInt i = 0; i < iExpectedLmResult.Count(); i++) |
|
120 { |
|
121 iExpectedLmResult[i]->Close(); |
|
122 iExpectedCatResult[i]->Close(); |
|
123 } |
|
124 iExpectedLmResult.ResetAndDestroy(); |
|
125 iExpectedCatResult.ResetAndDestroy(); |
|
126 } |
|
127 |
|
128 // --------------------------------------------------------- |
|
129 // CPosTp130::StartL |
|
130 // |
|
131 // (other items were commented in a header). |
|
132 // --------------------------------------------------------- |
|
133 // |
|
134 void CPosTp130::StartL() |
|
135 { |
|
136 // nrOfExpectedMatches contains the number of matches for each db when search pattern is *e* |
|
137 RArray<TInt> nrOfExpectedMatches; |
|
138 CleanupClosePushL(nrOfExpectedMatches); |
|
139 for (TInt i = 0; i < KNrOfDatabases; i++) |
|
140 { |
|
141 nrOfExpectedMatches.AppendL((*iExpectedLmResult[i]).Count()); |
|
142 } |
|
143 |
|
144 // 1. Search for landmarks |
|
145 iLog->Log(_L("1")); |
|
146 SearchForLandmarksL(); |
|
147 |
|
148 // 2-9. Verify result |
|
149 iLog->Log(_L("2-9")); |
|
150 VerifyIteratorsL(nrOfExpectedMatches, ETrue); |
|
151 |
|
152 iLog->Log(_L("10.true")); |
|
153 // 10. Test iterators dynamically |
|
154 TestMatchIteratorL(ETrue); |
|
155 iLog->Log(_L("10.false")); |
|
156 TestMatchIteratorL(EFalse); |
|
157 |
|
158 iLog->Log(_L("11")); |
|
159 // 11. Test error codes |
|
160 TestErrorCodesL(); |
|
161 |
|
162 iLog->Log(_L("12")); |
|
163 // 12. Check iterators from matching categories |
|
164 nrOfExpectedMatches.Reset(); |
|
165 for (TInt i = 0; i < KNrOfDatabases; i++) |
|
166 { |
|
167 nrOfExpectedMatches.AppendL((*iExpectedCatResult[i]).Count()); |
|
168 } |
|
169 SearchForCategoriesL(); |
|
170 VerifyIteratorsL(nrOfExpectedMatches, EFalse); |
|
171 CleanupStack::PopAndDestroy(&nrOfExpectedMatches); |
|
172 } |
|
173 |
|
174 // --------------------------------------------------------- |
|
175 // CPosTp130::SearchForLandmarksL |
|
176 // |
|
177 // (other items were commented in a header). |
|
178 // --------------------------------------------------------- |
|
179 // |
|
180 void CPosTp130::SearchForLandmarksL() |
|
181 { |
|
182 // Search for landmarks containing a specific string in name |
|
183 CPosLmTextCriteria* criteria = CPosLmTextCriteria::NewLC(); |
|
184 criteria->SetTextL(KSearchPattern); |
|
185 criteria->SetAttributesToSearch(CPosLandmark::ELandmarkName); |
|
186 |
|
187 // Do the search |
|
188 ExecuteAndDeleteLD(iDbSearcher->StartLandmarkSearchL(*criteria)); |
|
189 |
|
190 // Check errors |
|
191 TUint nrOfSearchErrors = iDbSearcher->NumOfSearchErrors(); |
|
192 AssertTrueSecL(nrOfSearchErrors == 0, _L("Found errors during search")); |
|
193 |
|
194 CleanupStack::PopAndDestroy(criteria); |
|
195 } |
|
196 |
|
197 // --------------------------------------------------------- |
|
198 // CPosTp130::SearchForCategoriesL |
|
199 // |
|
200 // (other items were commented in a header). |
|
201 // --------------------------------------------------------- |
|
202 // |
|
203 void CPosTp130::SearchForCategoriesL() |
|
204 { |
|
205 // Search for categories containing a specific string in name |
|
206 CPosLmCatNameCriteria* criteria = CPosLmCatNameCriteria::NewLC(); |
|
207 criteria->SetSearchPatternL(KSearchPattern); |
|
208 |
|
209 // Do the search |
|
210 ExecuteAndDeleteLD(iDbSearcher->StartCategorySearchL(*criteria, CPosLmCategoryManager::ECategorySortOrderNone)); |
|
211 |
|
212 // Check errors |
|
213 TUint nrOfSearchErrors = iDbSearcher->NumOfSearchErrors(); |
|
214 AssertTrueSecL(nrOfSearchErrors == 0, _L("Found errors during search")); |
|
215 |
|
216 CleanupStack::PopAndDestroy(criteria); |
|
217 } |
|
218 |
|
219 // --------------------------------------------------------- |
|
220 // CPosTp130::VerifyIteratorsL |
|
221 // |
|
222 // (other items were commented in a header). |
|
223 // --------------------------------------------------------- |
|
224 // |
|
225 void CPosTp130::VerifyIteratorsL(RArray<TInt>& aNrOfExpectedItems, TBool aLm) |
|
226 { |
|
227 RPointerArray<CPosLmItemIterator> iterators; |
|
228 CleanupClosePushL(iterators); |
|
229 CleanupStack::PushL(TCleanupItem(ResetAndDestroy, &iterators)); |
|
230 |
|
231 TInt totalNrOfMatches(0), totalNrOfExpectedMatches(0); |
|
232 for (TInt i = 0; i < KNrOfDatabases; i++) |
|
233 { |
|
234 // 2. Ask for the iterator for each database |
|
235 iterators.AppendL(iDbSearcher->MatchIteratorL(i)); |
|
236 |
|
237 // 3. Verify that the number of each iterator equals to the expected result |
|
238 AssertTrueSecL(aNrOfExpectedItems[i] == iterators[i]->NumOfItemsL(), _L("aNrOfExpectedItems[i] != iterators[i]->NumOfItemsL()")); |
|
239 AssertTrueSecL(aNrOfExpectedItems[i] == iDbSearcher->NumOfMatches(i), _L("aNrOfExpectedItems[i] != iDbSearcher->NumOfMatches(i)")); |
|
240 |
|
241 totalNrOfExpectedMatches += aNrOfExpectedItems[i]; |
|
242 totalNrOfMatches += iterators[i]->NumOfItemsL(); |
|
243 } |
|
244 |
|
245 // 4. Verify that the total number of matches equals the sum of expected |
|
246 AssertTrueSecL(totalNrOfMatches == totalNrOfExpectedMatches, _L("totalNrOfMatches != totalNrOfExpectedMatches")); |
|
247 AssertTrueSecL(totalNrOfMatches == iDbSearcher->TotalNumOfMatches(), _L("totalNrOfMatches != iDbSearcher->TotalNumOfMatches()")); |
|
248 |
|
249 for (TInt dbIndex = 0; dbIndex < KNrOfDatabases; dbIndex++) |
|
250 { |
|
251 // 5. Ask for the first item in each iterator |
|
252 TPosLmItemId id1 = iterators[dbIndex]->NextL(); |
|
253 |
|
254 // 6. Perform an operation on the first item, e.g. read it from db |
|
255 CPosLandmarkDatabase* db = CPosLandmarkDatabase::OpenL((*iDbUris)[dbIndex]); |
|
256 CleanupStack::PushL(db); |
|
257 if (aLm) |
|
258 { |
|
259 CPosLandmark* lm = db->ReadLandmarkLC(id1); |
|
260 TPtrC name; |
|
261 lm->GetLandmarkName(name); |
|
262 AssertTrueSecL(name.MatchC(KSearchPattern) != KErrNotFound, _L("First lm in iterator does not contain \"e\"")); |
|
263 CleanupStack::PopAndDestroy(lm); |
|
264 } |
|
265 else |
|
266 { |
|
267 CPosLmCategoryManager* catMan = CPosLmCategoryManager::NewL(*db); |
|
268 CleanupStack::PushL(catMan); |
|
269 CPosLandmarkCategory* cat = catMan->ReadCategoryLC(id1); |
|
270 TPtrC name; |
|
271 cat->GetCategoryName(name); |
|
272 AssertTrueSecL(name.MatchC(KSearchPattern) != KErrNotFound, _L("First category in iterator does not contain \"e\"")); |
|
273 CleanupStack::PopAndDestroy(2, catMan); |
|
274 } |
|
275 CleanupStack::PopAndDestroy(db); |
|
276 |
|
277 RIdArray allIds; |
|
278 CleanupClosePushL(allIds); |
|
279 |
|
280 // 7. Reset iterator and ask for next item |
|
281 iterators[dbIndex]->Reset(); |
|
282 TPosLmItemId id2 = iterators[dbIndex]->NextL(); |
|
283 AssertTrueSecL(id1 == id2, _L("id1 != id2")); |
|
284 allIds.AppendL(id2); |
|
285 |
|
286 // 8. Iterate until there are no more items to iterate |
|
287 while (id2 != KPosLmNullItemId) |
|
288 { |
|
289 id2 = iterators[dbIndex]->NextL(); |
|
290 allIds.AppendL(id2); |
|
291 } |
|
292 AssertTrueSecL(id2 == KPosLmNullItemId, _L("id2 != KPosLmNullItemId")); |
|
293 |
|
294 // 9. Ask for sequences of iterator |
|
295 RIdArray idArray; |
|
296 CleanupClosePushL(idArray); |
|
297 TInt nrOfItems = iterators[dbIndex]->NumOfItemsL(); |
|
298 for (TInt iterIndex = 0; iterIndex < nrOfItems; iterIndex++) |
|
299 { |
|
300 // Get sequence of the tail of the iterator |
|
301 iterators[dbIndex]->GetItemIdsL(idArray, iterIndex, nrOfItems - iterIndex); |
|
302 AssertTrueSecL(idArray.Count() == nrOfItems - iterIndex, _L("A: Wrong number of items in id array")); |
|
303 for (TInt i = iterIndex; i < nrOfItems - iterIndex; i++) |
|
304 { |
|
305 id1 = idArray[i - iterIndex]; |
|
306 id2 = allIds[i]; |
|
307 AssertTrueSecL(id1 == id2, _L("A: Unexpected id in part of all ids array")); |
|
308 } |
|
309 |
|
310 // Get sequence of the nose of the iterator |
|
311 iterators[dbIndex]->GetItemIdsL(idArray, 0, iterIndex); |
|
312 AssertTrueSecL(idArray.Count() == iterIndex, _L("B: Wrong number of items in id array")); |
|
313 for (TInt j = 0; j < iterIndex; j++) |
|
314 { |
|
315 id1 = idArray[j]; |
|
316 id2 = allIds[j]; |
|
317 AssertTrueSecL(id1 == id2, _L("B: Unexpected id in part of all ids array")); |
|
318 } |
|
319 } |
|
320 CleanupStack::PopAndDestroy(2, &allIds); |
|
321 } |
|
322 |
|
323 CleanupStack::PopAndDestroy(2, &iterators); |
|
324 } |
|
325 |
|
326 // --------------------------------------------------------- |
|
327 // CPosTp130::TestErrorCodesL |
|
328 // |
|
329 // (other items were commented in a header). |
|
330 // --------------------------------------------------------- |
|
331 // |
|
332 void CPosTp130::TestErrorCodesL() |
|
333 { |
|
334 // No error codes to test |
|
335 } |
|
336 |
|
337 // --------------------------------------------------------- |
|
338 // CPosTp130::TestMatchIteratorL |
|
339 // |
|
340 // (other items were commented in a header). |
|
341 // --------------------------------------------------------- |
|
342 // |
|
343 void CPosTp130::TestMatchIteratorL(TBool aSearchLm) |
|
344 { |
|
345 CMatchIteratorTester* matchIterTester = CMatchIteratorTester::NewLC(iDbUris, iLog); |
|
346 CPosLmOperation* operation = NULL; |
|
347 |
|
348 if (aSearchLm) |
|
349 { |
|
350 CPosLmTextCriteria* textCriteria = CPosLmTextCriteria::NewLC(); |
|
351 textCriteria->SetTextL(KSearchPattern); |
|
352 textCriteria->SetAttributesToSearch(CPosLandmark::ELandmarkName); |
|
353 TPosLmSortPref sortPref(CPosLandmark::ELandmarkName, TPosLmSortPref::EAscending); |
|
354 operation = iDbSearcher->StartLandmarkSearchL(*textCriteria, sortPref); |
|
355 CleanupStack::PopAndDestroy(textCriteria); |
|
356 |
|
357 CleanupStack::PushL(operation); |
|
358 matchIterTester->RunTestL(iDbSearcher, operation, iExpectedLmResult); |
|
359 CleanupStack::Pop(operation); // ownership transferred |
|
360 } |
|
361 else |
|
362 { |
|
363 CPosLmCatNameCriteria* criteria = CPosLmCatNameCriteria::NewLC(); |
|
364 criteria->SetSearchPatternL(KSearchPattern); |
|
365 operation = iDbSearcher->StartCategorySearchL(*criteria, CPosLmCategoryManager::ECategorySortOrderNameAscending); |
|
366 CleanupStack::PopAndDestroy(criteria); |
|
367 |
|
368 CleanupStack::PushL(operation); |
|
369 matchIterTester->RunTestL(iDbSearcher, operation, iExpectedCatResult); |
|
370 CleanupStack::Pop(operation); // ownership transferred |
|
371 } |
|
372 |
|
373 TInt error = matchIterTester->Result(); |
|
374 if (error != KErrNone) |
|
375 { |
|
376 TPtrC msg; |
|
377 matchIterTester->GetErrorMsg(msg); |
|
378 |
|
379 iLog->Log(msg); |
|
380 User::Leave(error); |
|
381 } |
|
382 |
|
383 CleanupStack::PopAndDestroy(matchIterTester); |
|
384 } |
|
385 |
|
386 // --------------------------------------------------------- |
|
387 // --------------------------------------------------------- |
|
388 // |
|
389 void CPosTp130::InitExpectedResultsL( const TDesC& aDbName, RIdArray& aArray, TBool aSearchLm ) |
|
390 { |
|
391 iLog->Log( aDbName ); |
|
392 CPosLandmarkDatabase* db = CPosLandmarkDatabase::OpenL( aDbName ); |
|
393 CleanupStack::PushL( db ); |
|
394 |
|
395 if ( db->IsInitializingNeeded() ) |
|
396 { |
|
397 ExecuteAndDeleteLD( db->InitializeL() ); |
|
398 } |
|
399 |
|
400 CPosLmCategoryManager* catman = CPosLmCategoryManager::NewL( *db ); |
|
401 CleanupStack::PushL( catman ); |
|
402 |
|
403 RPointerArray<CNamedLmItem> items; |
|
404 CleanupStack::PushL( TCleanupItem( ResetAndDestroyNamedLmItem, &items ) ); |
|
405 |
|
406 CPosLmItemIterator* iter = NULL; |
|
407 if ( aSearchLm ) |
|
408 { |
|
409 iter = db->LandmarkIteratorL(); |
|
410 } |
|
411 else |
|
412 { |
|
413 iter = catman->CategoryIteratorL(); |
|
414 } |
|
415 CleanupStack::PushL( iter ); |
|
416 |
|
417 TPosLmItemId id = iter->NextL(); |
|
418 while ( id != KPosLmNullItemId ) |
|
419 { |
|
420 CNamedLmItem* item = new (ELeave) CNamedLmItem; |
|
421 CleanupStack::PushL( item ); |
|
422 |
|
423 item->iId = id; |
|
424 |
|
425 TPtrC name; |
|
426 if ( aSearchLm ) |
|
427 { |
|
428 CPosLandmark* lm = db->ReadLandmarkLC( id ); |
|
429 lm->GetLandmarkName( name ); |
|
430 item->iName = name.AllocL(); |
|
431 CleanupStack::PopAndDestroy( lm ); |
|
432 } |
|
433 else |
|
434 { |
|
435 CPosLandmarkCategory* cat = catman->ReadCategoryLC( id ); |
|
436 cat->GetCategoryName( name ); |
|
437 item->iName = name.AllocL(); |
|
438 CleanupStack::PopAndDestroy( cat ); |
|
439 } |
|
440 |
|
441 if ( item->iName->MatchC( KSearchPattern ) != KErrNotFound ) |
|
442 { |
|
443 items.AppendL( item ); |
|
444 CleanupStack::Pop( item ); |
|
445 } |
|
446 else |
|
447 { |
|
448 CleanupStack::PopAndDestroy( item ); |
|
449 } |
|
450 id = iter->NextL(); |
|
451 } |
|
452 CleanupStack::PopAndDestroy( iter ); |
|
453 |
|
454 TLinearOrder<CNamedLmItem> order( CNamedLmItem::CompareByName ); |
|
455 items.Sort( order ); |
|
456 |
|
457 aArray.Reset(); |
|
458 for( TInt i = 0; i < items.Count(); i++ ) |
|
459 { |
|
460 aArray.AppendL( items[i]->iId ); |
|
461 iLog->Log( _L("id: %d, name = '%S'"), items[i]->iId, items[i]->iName ); |
|
462 } |
|
463 |
|
464 CleanupStack::PopAndDestroy(); // items |
|
465 CleanupStack::PopAndDestroy( catman ); |
|
466 CleanupStack::PopAndDestroy( db ); |
|
467 } |
|
468 |
|
469 // ================= CMatchIteratorTester MEMBER FUNCTIONS ======================= |
|
470 |
|
471 // Constructor |
|
472 CMatchIteratorTester::CMatchIteratorTester( |
|
473 CDesCArray* aDbUris, CStifLogger* aLog ) |
|
474 : CActive(CActive::EPriorityStandard), |
|
475 iDbUris(aDbUris), iLog( aLog ) |
|
476 { |
|
477 CActiveScheduler::Add(this); |
|
478 } |
|
479 |
|
480 // Destructor |
|
481 CMatchIteratorTester::~CMatchIteratorTester() |
|
482 { |
|
483 Cancel(); |
|
484 delete iErrorMsg; |
|
485 delete iOperation; |
|
486 iIterators.ResetAndDestroy(); |
|
487 } |
|
488 |
|
489 // --------------------------------------------------------- |
|
490 // CMatchIteratorTester::NewLC |
|
491 // |
|
492 // (other items were commented in a header). |
|
493 // --------------------------------------------------------- |
|
494 // |
|
495 CMatchIteratorTester* CMatchIteratorTester::NewLC( |
|
496 CDesCArray* aDbUris, CStifLogger* aLog) |
|
497 { |
|
498 CMatchIteratorTester* self = |
|
499 new (ELeave) CMatchIteratorTester(aDbUris, aLog); |
|
500 CleanupStack::PushL(self); |
|
501 return self; |
|
502 } |
|
503 |
|
504 // --------------------------------------------------------- |
|
505 // CMatchIteratorTester::RunL |
|
506 // |
|
507 // (other items were commented in a header). |
|
508 // --------------------------------------------------------- |
|
509 // |
|
510 void CMatchIteratorTester::RunL() |
|
511 { |
|
512 iResult = iStatus.Int(); |
|
513 VerifyIteratorsL(iResult); |
|
514 |
|
515 if (iStatus.Int() == KPosLmOperationNotComplete) |
|
516 { |
|
517 iOperation->NextStep(iStatus, iProgress); |
|
518 SetActive(); |
|
519 } |
|
520 else |
|
521 { |
|
522 CActiveScheduler::Stop(); |
|
523 } |
|
524 } |
|
525 |
|
526 // --------------------------------------------------------- |
|
527 // CMatchIteratorTester::DoCancel |
|
528 // |
|
529 // (other items were commented in a header). |
|
530 // --------------------------------------------------------- |
|
531 // |
|
532 void CMatchIteratorTester::DoCancel() |
|
533 { |
|
534 delete iOperation; |
|
535 iOperation = NULL; |
|
536 } |
|
537 |
|
538 // --------------------------------------------------------- |
|
539 // CMatchIteratorTester::RunError |
|
540 // |
|
541 // (other items were commented in a header). |
|
542 // --------------------------------------------------------- |
|
543 // |
|
544 TInt CMatchIteratorTester::RunError(TInt aError) |
|
545 { |
|
546 iResult = aError; |
|
547 CActiveScheduler::Stop(); |
|
548 return KErrNone; |
|
549 } |
|
550 |
|
551 // --------------------------------------------------------- |
|
552 // CMatchIteratorTester::RunTestL |
|
553 // |
|
554 // (other items were commented in a header). |
|
555 // --------------------------------------------------------- |
|
556 // |
|
557 void CMatchIteratorTester::RunTestL( |
|
558 CPosLmMultiDbSearch* aMultiSearcher, |
|
559 CPosLmOperation* aSearchOperation, |
|
560 RPointerArray<RIdArray>& aExpectedResult) |
|
561 { |
|
562 iMultiSearcher = aMultiSearcher; |
|
563 iExpectedResult = &aExpectedResult; |
|
564 iOperation = aSearchOperation; |
|
565 |
|
566 // Initialize iIterators |
|
567 for (TInt i = 0; i < iMultiSearcher->NumOfDatabasesToSearch(); i++) |
|
568 { |
|
569 CPosLmItemIterator* iterator = iMultiSearcher->MatchIteratorL(i); |
|
570 CleanupStack::PushL(iterator); |
|
571 User::LeaveIfError(iIterators.Append(iterator)); |
|
572 CleanupStack::Pop(iterator); |
|
573 } |
|
574 |
|
575 iOperation->NextStep(iStatus, iProgress); |
|
576 SetActive(); |
|
577 CActiveScheduler::Start(); |
|
578 } |
|
579 |
|
580 // --------------------------------------------------------- |
|
581 // CMatchIteratorTester::Result |
|
582 // |
|
583 // (other items were commented in a header). |
|
584 // --------------------------------------------------------- |
|
585 // |
|
586 TInt CMatchIteratorTester::Result() const |
|
587 { |
|
588 return iResult; |
|
589 } |
|
590 |
|
591 // --------------------------------------------------------- |
|
592 // CMatchIteratorTester::GetErrorMsg |
|
593 // |
|
594 // (other items were commented in a header). |
|
595 // --------------------------------------------------------- |
|
596 // |
|
597 void CMatchIteratorTester::GetErrorMsg(TPtrC& aMsg) const |
|
598 { |
|
599 aMsg.Set(*iErrorMsg); |
|
600 } |
|
601 |
|
602 // --------------------------------------------------------- |
|
603 // CMatchIteratorTester::VerifyIteratorsL |
|
604 // |
|
605 // (other items were commented in a header). |
|
606 // --------------------------------------------------------- |
|
607 // |
|
608 void CMatchIteratorTester::VerifyIteratorsL(TInt aResult) |
|
609 { |
|
610 for (TInt dbIndex = 0; dbIndex < iMultiSearcher->NumOfDatabasesToSearch(); dbIndex++) |
|
611 { |
|
612 CPosLmItemIterator* iterator = iMultiSearcher->MatchIteratorL(dbIndex); |
|
613 CleanupStack::PushL(iterator); |
|
614 CompareIteratorsL(*iterator, *iIterators[dbIndex]); |
|
615 delete iIterators[dbIndex]; |
|
616 iIterators[dbIndex] = iterator; |
|
617 CleanupStack::Pop(iterator); |
|
618 |
|
619 // Verify matches are correct |
|
620 TBuf<50> buf; |
|
621 iterator->Reset(); |
|
622 TPosLmItemId id = iterator->NextL(); |
|
623 while (id != KPosLmNullItemId) |
|
624 { |
|
625 if ((*(*iExpectedResult)[dbIndex]).Find(id) == KErrNotFound) |
|
626 { |
|
627 buf.Format(_L("Cannot find match %d in expected result"), id ); |
|
628 SetErrorAndLeaveL(buf); |
|
629 } |
|
630 id = iterator->NextL(); |
|
631 } |
|
632 |
|
633 if (aResult == KErrNone) // Search is completed - result should be sorted ascending |
|
634 { |
|
635 RIdArray idArray; |
|
636 CleanupClosePushL(idArray); |
|
637 TInt nrOfItems = iterator->NumOfItemsL(); |
|
638 iterator->GetItemIdsL(idArray, 0, nrOfItems); |
|
639 for (TInt i = 0; i < nrOfItems; i++) |
|
640 { |
|
641 TPosLmItemId id1 = idArray[i]; |
|
642 TPosLmItemId id2 = (*(*iExpectedResult)[dbIndex])[i]; |
|
643 if (id1 != id2) |
|
644 { |
|
645 buf.Format(_L("Sorted result differs, %d != %d"), id1, id2); |
|
646 SetErrorAndLeaveL(buf); |
|
647 } |
|
648 } |
|
649 |
|
650 TInt expectedLength = (*(*iExpectedResult)[dbIndex]).Count(); |
|
651 if (nrOfItems != expectedLength) |
|
652 { |
|
653 buf.Format(_L("Length of arrays doesnät match, %d != %d"), nrOfItems, expectedLength); |
|
654 SetErrorAndLeaveL(buf); |
|
655 } |
|
656 CleanupStack::PopAndDestroy(&idArray); |
|
657 } |
|
658 } |
|
659 } |
|
660 |
|
661 // --------------------------------------------------------- |
|
662 // CMatchIteratorTester::CompareIteratorsL |
|
663 // |
|
664 // (other items were commented in a header). |
|
665 // --------------------------------------------------------- |
|
666 // |
|
667 void CMatchIteratorTester::CompareIteratorsL( |
|
668 CPosLmItemIterator& aNewIter, |
|
669 CPosLmItemIterator& aOldIter) |
|
670 { |
|
671 TInt oldIterLength = aOldIter.NumOfItemsL(); |
|
672 TInt newIterLength = aNewIter.NumOfItemsL(); |
|
673 |
|
674 if (newIterLength < oldIterLength) |
|
675 { |
|
676 SetErrorAndLeaveL(_L("aNewIter is shorter than aOldIter")); |
|
677 } |
|
678 |
|
679 // Verify that all the items in the old iterator can be found in the new one |
|
680 if (newIterLength > 0) |
|
681 { |
|
682 RArray<TPosLmItemId> newItemIds; |
|
683 CleanupClosePushL(newItemIds); |
|
684 aNewIter.GetItemIdsL(newItemIds, 0, newIterLength); |
|
685 |
|
686 aOldIter.Reset(); |
|
687 TPosLmItemId id = aOldIter.NextL(); |
|
688 while (id != KPosLmNullItemId) |
|
689 { |
|
690 TInt err = newItemIds.Find(id); |
|
691 if (err == KErrNotFound) |
|
692 { |
|
693 SetErrorAndLeaveL(_L("aNewIter doesn't match aOldIter")); |
|
694 } |
|
695 id = aOldIter.NextL(); |
|
696 } |
|
697 |
|
698 CleanupStack::PopAndDestroy(&newItemIds); |
|
699 } |
|
700 } |
|
701 |
|
702 // --------------------------------------------------------- |
|
703 // CMatchIteratorTester::SetErrorAndLeaveL |
|
704 // |
|
705 // (other items were commented in a header). |
|
706 // --------------------------------------------------------- |
|
707 // |
|
708 void CMatchIteratorTester::SetErrorAndLeaveL(const TDesC& aErrMsg) |
|
709 { |
|
710 delete iErrorMsg; |
|
711 iErrorMsg = NULL; |
|
712 iErrorMsg = aErrMsg.AllocL(); |
|
713 User::Leave(KErrGeneral); |
|
714 } |
|
715 |
|
716 // End of File |