|
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 "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-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 <EPos_CPosLandmarkDatabase.h> |
|
22 #include <EPos_CPosLmCategoryCriteria.h> |
|
23 #include <EPos_CPosLMItemIterator.h> |
|
24 #include <EPos_CPosLmMultiDbSearch.h> |
|
25 #include <EPos_CPosLmDatabaseManager.h> |
|
26 #include "FT_CPosTp121.h" |
|
27 #include "FT_LandmarkConstants.h" |
|
28 #include "FT_CCategoryLandmarkSearchResult.h" |
|
29 |
|
30 // CONSTANTS |
|
31 // Used when searching for global categories (Global categories are dynamically appended in the test. |
|
32 // There are originally 26 local categories in the databases) |
|
33 //const TPosLmItemId KRestaurant = 27; |
|
34 const TPosLmItemId KBar = 28; |
|
35 //const TPosLmItemId KGas_Station = 29; |
|
36 const TPosLmItemId KHotel = 30; |
|
37 //const TPosLmItemId KShop = 31; |
|
38 const TPosLmItemId KSports_Ground = 33; |
|
39 const TPosLmItemId KGarage = 34; |
|
40 const TPosLmItemId KBus_Stop = 36; |
|
41 |
|
42 // ================= MEMBER FUNCTIONS ======================= |
|
43 // --------------------------------------------------------- |
|
44 // CPosTp121::CloseTest |
|
45 // |
|
46 // (other items were commented in a header). |
|
47 // --------------------------------------------------------- |
|
48 // |
|
49 void CPosTp121::CloseTest() |
|
50 { |
|
51 delete iDatabases; |
|
52 delete iMultiDbSearch; |
|
53 iCategoryLandmarkSearchResults.ResetAndDestroy(); |
|
54 } |
|
55 |
|
56 // --------------------------------------------------------- |
|
57 // CPosTp121::InitTestL |
|
58 // |
|
59 // (other items were commented in a header). |
|
60 // --------------------------------------------------------- |
|
61 // |
|
62 void CPosTp121::InitTestL() |
|
63 { |
|
64 CLandmarkTestProcedureBase::InitTestL(); |
|
65 |
|
66 // PrepareDatabases |
|
67 RemoveAllLmDatabasesL(); |
|
68 CopyTestDbFileL(KDb20); |
|
69 CopyTestDbFileL(KDb40); |
|
70 CopyTestDbFileL(KDb60); |
|
71 CopyTestDbFileL(KDb80); |
|
72 CopyTestDbFileL(KDb105); |
|
73 iNrOfDatabases = 5; |
|
74 |
|
75 iLog->Log(_L("Test Dbs Copied")); |
|
76 |
|
77 // Initialize data members |
|
78 CPosLmDatabaseManager* dbManager = CPosLmDatabaseManager::NewL(); |
|
79 CleanupStack::PushL(dbManager); |
|
80 iDatabases = dbManager->ListDatabasesLC(); |
|
81 CleanupStack::Pop(iDatabases); |
|
82 iDatabases->Sort(); |
|
83 AssertTrueSecL((iDatabases->Count() == iNrOfDatabases), _L("Wrong number of databases")); |
|
84 iMultiDbSearch = CPosLmMultiDbSearch::NewL(*iDatabases); |
|
85 CleanupStack::PopAndDestroy(dbManager); |
|
86 |
|
87 iLog->Log(_L("Members ready")); |
|
88 |
|
89 TInt err = KErrNone; |
|
90 CPosLandmarkDatabase* database = NULL; |
|
91 // Reset Global categories for all databases but EPOSLM_105.LDB and add the global category |
|
92 // "Hotel" to the 5 first landmarks in the databases. |
|
93 for (TInt i = 0; i < iNrOfDatabases - 1; i++) // Do not use global categories in the last db |
|
94 { |
|
95 database = CPosLandmarkDatabase::OpenL((*iDatabases)[i]); |
|
96 CleanupStack::PushL(database); |
|
97 if ( database->IsInitializingNeeded() ) |
|
98 { |
|
99 TRAP( err, ExecuteAndDeleteLD( database->InitializeL() ) ); |
|
100 AssertTrueSecL( err == KErrNone, _L("Init db failed")); |
|
101 } |
|
102 CPosLmCategoryManager* catMan = CPosLmCategoryManager::NewL(*database); |
|
103 CleanupStack::PushL(catMan); |
|
104 TRAP( err, ExecuteAndDeleteLD( catMan->ResetGlobalCategoriesL() ) ); |
|
105 AssertTrueSecL( err == KErrNone, _L("Reset cats failed")); |
|
106 CleanupStack::PopAndDestroy(2, database); |
|
107 } |
|
108 |
|
109 iLog->Log(_L("Cats reset")); |
|
110 |
|
111 // Initiallize iCategoryLandmarkSearchResults |
|
112 AppendCategoryLandmarkSearchResultsL(); |
|
113 |
|
114 iLog->Log(_L("AppendCategoryLandmarkSearchResultsL done")); |
|
115 } |
|
116 |
|
117 // --------------------------------------------------------- |
|
118 // CPosTp121::StartL |
|
119 // |
|
120 // (other items were commented in a header). |
|
121 // --------------------------------------------------------- |
|
122 // |
|
123 void CPosTp121::StartL() |
|
124 { |
|
125 // 1. Search in various ways |
|
126 iLog->Log(_L("Testing search with criteria read from LmDbSearchResult.txt synchronously, using CategoryName. Sort order: ascending")); |
|
127 TestSearchL(iCategoryLandmarkSearchResults, ESynchronous, ESortAscending); |
|
128 |
|
129 iLog->Log(_L("Testing search with criteria read from LmDbSearchResult.txt synchronously, using CategoryName. Sort order: descending")); |
|
130 TestSearchL(iCategoryLandmarkSearchResults, ESynchronous, ESortDescending); |
|
131 |
|
132 iLog->Log(_L("Testing search with criteria read from LmDbSearchResult.txt synchronously, using CategoryName. Sort order: none")); |
|
133 TestSearchL(iCategoryLandmarkSearchResults, ESynchronous, ESortNone); |
|
134 |
|
135 iLog->Log(_L("Testing search with criteria read from LmDbSearchResult.txt asynchronously, using CategoryName. Sort order: ascending")); |
|
136 TestSearchL(iCategoryLandmarkSearchResults, EAsynchronous, ESortAscending); |
|
137 |
|
138 iLog->Log(_L("Testing search with criteria read from LmDbSearchResult.txt asynchronously, using CategoryName. Sort order: descending")); |
|
139 TestSearchL(iCategoryLandmarkSearchResults, EAsynchronous, ESortDescending); |
|
140 |
|
141 iLog->Log(_L("Testing search with criteria read from LmDbSearchResult.txt asynchronously, using CategoryName. Sort order: none")); |
|
142 TestSearchL(iCategoryLandmarkSearchResults, EAsynchronous, ESortNone); |
|
143 |
|
144 // 2. Search non-existing category |
|
145 iLog->Log(_L("Searching fon nonexisting entries synchronously")); |
|
146 SearchNonExistingL(ESynchronous); |
|
147 |
|
148 iLog->Log(_L("Searching for nonexisting entries asynchronously")); |
|
149 SearchNonExistingL(EAsynchronous); |
|
150 |
|
151 // 3. Test maximum number of matches |
|
152 iLog->Log(_L("Searching with maximum number of results synchronously")); |
|
153 TestMaximumNrOfMatchesL(iCategoryLandmarkSearchResults, ESynchronous); |
|
154 |
|
155 iLog->Log(_L("Searching with maximum number of results asynchronously")); |
|
156 TestMaximumNrOfMatchesL(iCategoryLandmarkSearchResults, EAsynchronous); |
|
157 |
|
158 // 4. Test cancel |
|
159 iLog->Log(_L("Search and cancel the search")); |
|
160 SearchAndCancelL(); |
|
161 |
|
162 // 5. Search in global categories |
|
163 // Add some more landmarks associated with global categories |
|
164 AddLandmarksToGlobalCategoriesL(); |
|
165 |
|
166 iLog->Log(_L("SearchForLandmarksInGlobalCategoriesL asynchronously")); |
|
167 SearchForLandmarksInGlobalCategoriesL(EAsynchronous); |
|
168 |
|
169 iLog->Log(_L("SearchForLandmarksInGlobalCategoriesL synchronously")); |
|
170 SearchForLandmarksInGlobalCategoriesL(ESynchronous); |
|
171 |
|
172 // 6. Test some leave codes |
|
173 iLog->Log(_L("Check that StartLandmarkSearchL leaves with correct codes")); |
|
174 TestLeaveCodesL(); |
|
175 |
|
176 // 7. Test automatically reset of search attributes |
|
177 iLog->Log(_L("Check that CPosLmCategoryCriteria resets other criteria when setting a new one")); |
|
178 TestResetSearchAttributesL(); |
|
179 |
|
180 // 8. Test searching by name is case insensitive |
|
181 iLog->Log(_L("Testing case insensitive")); |
|
182 TestCaseInsensitiveL(); |
|
183 |
|
184 // 9. Test search for categories containing wildcards |
|
185 iLog->Log(_L("Testing wild cards")); |
|
186 TestWildCardsL(); |
|
187 |
|
188 // 10. Test various combinations of refined search |
|
189 // Modify database2 |
|
190 iLog->Log(_L("Testing refined search")); |
|
191 RIdArray idArray; |
|
192 CleanupClosePushL(idArray); |
|
193 idArray.Append(51); |
|
194 idArray.Append(52); |
|
195 idArray.Append(53); |
|
196 CPosLandmarkDatabase* db = CPosLandmarkDatabase::OpenL((*iDatabases)[2]); |
|
197 CleanupStack::PushL(db); |
|
198 CPosLmCategoryManager* catMan = CPosLmCategoryManager::NewL(*db); |
|
199 CleanupStack::PushL(catMan); |
|
200 ExecuteAndDeleteLD(catMan->AddCategoryToLandmarksL(14, idArray)); // 14 = TietoEnator kontor |
|
201 ExecuteAndDeleteLD(catMan->AddCategoryToLandmarksL(17, idArray)); // 17 = BurgerKing |
|
202 ExecuteAndDeleteLD(catMan->AddCategoryToLandmarksL(catMan->GetGlobalCategoryL(15000), idArray)); // 15000 = Entertainment |
|
203 CleanupStack::PopAndDestroy(3, &idArray); |
|
204 |
|
205 TestRefinedSearchL(ESynchronous); |
|
206 TestRefinedSearchL(EAsynchronous); |
|
207 |
|
208 // 11. Test modify list of databases |
|
209 iLog->Log(_L("Testing modifying list of databases")); |
|
210 RIdArray expectedMatches; |
|
211 CleanupClosePushL(expectedMatches); |
|
212 expectedMatches.AppendL(iGasStationId1); |
|
213 expectedMatches.AppendL(iGasStationId2); |
|
214 expectedMatches.AppendL(51); |
|
215 expectedMatches.AppendL(52); |
|
216 expectedMatches.AppendL(53); |
|
217 |
|
218 TestDatabaseListL(expectedMatches); |
|
219 |
|
220 // 12. Test on-the-fly |
|
221 iLog->Log(_L("Testing searching on the fly")); |
|
222 TestOnTheFlySearchL(expectedMatches); |
|
223 |
|
224 CleanupStack::PopAndDestroy(&expectedMatches); |
|
225 } |
|
226 |
|
227 // --------------------------------------------------------- |
|
228 // CPosTp121::TestSearchL |
|
229 // |
|
230 // (other items were commented in a header). |
|
231 // --------------------------------------------------------- |
|
232 // |
|
233 void CPosTp121::TestSearchL( |
|
234 const RPointerArray<CCategoryLandmarkSearchResult>& aSearchResults, |
|
235 TExecutionMode aExecutionMode, |
|
236 TTp121SortOrder aSortOrder) |
|
237 { |
|
238 // Test SetMaxNumOfMatches, first set to one and then back to unlimited |
|
239 iMultiDbSearch->SetMaxNumOfMatches(1); |
|
240 iMultiDbSearch->SetMaxNumOfMatches(); |
|
241 |
|
242 for(TInt i = 0; i < aSearchResults.Count(); i++) |
|
243 { |
|
244 CPosLmCategoryCriteria* catSearchCriteria = CPosLmCategoryCriteria::NewLC(); |
|
245 |
|
246 // Perform search by name |
|
247 catSearchCriteria->SetCategoryNameL(aSearchResults[i]->CategoryName()); |
|
248 iLog->Log(aSearchResults[i]->CategoryName()); |
|
249 |
|
250 SearchL(catSearchCriteria, aExecutionMode, aSearchResults[i]->Redefined(), aSortOrder); |
|
251 |
|
252 if (i != 28) |
|
253 { |
|
254 // Row 28 in xls-file contains an error. If fixed, TP21 starts to fail. |
|
255 ValidateSearchResultsL(aSearchResults[i], iMultiDbSearch, aSortOrder); |
|
256 ValidateTotalNrOfMatchesL( |
|
257 iMultiDbSearch->TotalNumOfMatches(), |
|
258 (TUint)(aSearchResults[i]->SearchResult()).Count(), |
|
259 catSearchCriteria->CategoryName()); |
|
260 } |
|
261 |
|
262 CleanupStack::PopAndDestroy(catSearchCriteria); |
|
263 } |
|
264 } |
|
265 |
|
266 // --------------------------------------------------------- |
|
267 // CPosTp121::SearchForLandmarksInGlobalCategoriesL |
|
268 // |
|
269 // (other items were commented in a header). |
|
270 // --------------------------------------------------------- |
|
271 // |
|
272 void CPosTp121::SearchForLandmarksInGlobalCategoriesL( |
|
273 TExecutionMode aExecutionMode) |
|
274 { |
|
275 iLog->Log(_L("SearchForGlobalCategoriesL")); |
|
276 |
|
277 CPosLmCategoryCriteria* catSearchCriteria = CPosLmCategoryCriteria::NewLC(); |
|
278 RIdArray expectedIds; |
|
279 CleanupClosePushL(expectedIds); |
|
280 |
|
281 // Search for "Accommodation", should result in two matches |
|
282 catSearchCriteria->SetGlobalCategory( KAccommodation ); |
|
283 SearchL(catSearchCriteria, aExecutionMode); |
|
284 expectedIds.AppendL(iRestaurantId1); |
|
285 expectedIds.AppendL(iRestaurantId2); |
|
286 ValidateSearchResultsL(expectedIds, iMultiDbSearch); |
|
287 expectedIds.Reset(); |
|
288 |
|
289 // Search for "Entertainment" id using the global category id should result in two matches |
|
290 |
|
291 catSearchCriteria->SetGlobalCategory(KBusiness); |
|
292 SearchL(catSearchCriteria, aExecutionMode); |
|
293 expectedIds.AppendL(iGasStationId1); |
|
294 expectedIds.AppendL(iGasStationId2); |
|
295 ValidateSearchResultsL(expectedIds, iMultiDbSearch); |
|
296 expectedIds.Reset(); |
|
297 |
|
298 // Search for "Accommodation" in the result from previous search |
|
299 catSearchCriteria->SetGlobalCategory(KAccommodation); |
|
300 SearchL(catSearchCriteria, aExecutionMode, ETrue); |
|
301 expectedIds.AppendL(iGasStationId2); |
|
302 ValidateSearchResultsL(expectedIds, iMultiDbSearch); |
|
303 expectedIds.Reset(); |
|
304 |
|
305 // Search for a non existing global category in the result from previous search |
|
306 // Nothing should be found |
|
307 catSearchCriteria->SetCategoryNameL(_L("NonExistingGLobalCategory")); |
|
308 SearchL(catSearchCriteria, aExecutionMode, ETrue); |
|
309 ValidateSearchResultsL(expectedIds, iMultiDbSearch); |
|
310 expectedIds.Reset(); |
|
311 |
|
312 // Search for "Accommodation" using the globalcategory id |
|
313 catSearchCriteria->SetGlobalCategory(3000); |
|
314 SearchL(catSearchCriteria, aExecutionMode); |
|
315 expectedIds.AppendL(iRestaurantId1); |
|
316 expectedIds.AppendL(iRestaurantId2); |
|
317 ValidateSearchResultsL(expectedIds, iMultiDbSearch); |
|
318 expectedIds.Reset(); |
|
319 |
|
320 // Search for "Entertainment" using the globalcategory id from the result |
|
321 // from previous search |
|
322 catSearchCriteria->SetGlobalCategory(15000); |
|
323 SearchL(catSearchCriteria, aExecutionMode, ETrue); |
|
324 expectedIds.AppendL(iGasStationId2); |
|
325 ValidateSearchResultsL(expectedIds, iMultiDbSearch); |
|
326 expectedIds.Reset(); |
|
327 |
|
328 |
|
329 CleanupStack::PopAndDestroy(2, catSearchCriteria); |
|
330 } |
|
331 |
|
332 // --------------------------------------------------------- |
|
333 // CPosTp121::AddLandmarksToGlobalCategoriesL |
|
334 // |
|
335 // (other items were commented in a header). |
|
336 // --------------------------------------------------------- |
|
337 // |
|
338 void CPosTp121::AddLandmarksToGlobalCategoriesL() |
|
339 { |
|
340 iLog->Log(_L("AddLandmarksToGlobalCategoriesL")); |
|
341 |
|
342 // Add some new landmarks to the dbs, associate some with global categories |
|
343 CPosLandmarkDatabase* db = CPosLandmarkDatabase::OpenL((*iDatabases)[0]); |
|
344 CleanupStack::PushL(db); |
|
345 CPosLandmark* lm = CPosLandmark::NewLC(); |
|
346 lm->SetLandmarkNameL(_L("LandmarkName1")); |
|
347 lm->SetLandmarkDescriptionL(_L("SomeLandmarkDescription")); |
|
348 |
|
349 /*************************************************************/ |
|
350 // Search for id maintained by database for the global category |
|
351 CPosLmCategoryManager* catMan = CPosLmCategoryManager::NewL( *db ); |
|
352 CleanupStack::PushL(catMan); |
|
353 TPosLmItemId globCatId1 = catMan->GetGlobalCategoryL( KAccommodation ); |
|
354 TPosLmItemId globCatId2 = catMan->GetGlobalCategoryL( KEntertainment ); |
|
355 |
|
356 CPosLandmarkCategory* cat = catMan->ReadCategoryLC( globCatId1 ); |
|
357 |
|
358 CleanupStack::PopAndDestroy( 2 ); |
|
359 /*************************************************************/ |
|
360 lm->AddCategoryL( globCatId1 ); |
|
361 TPosLmItemId id = db->AddLandmarkL(*lm); |
|
362 iRestaurantId1 = id; |
|
363 |
|
364 CleanupStack::PopAndDestroy(2, db); |
|
365 |
|
366 db = CPosLandmarkDatabase::OpenL((*iDatabases)[1]); |
|
367 CleanupStack::PushL(db); |
|
368 lm = CPosLandmark::NewLC(); |
|
369 db->AddLandmarkL(*lm); // Add one uncategorized to increase id in order to avoid equal ids between dbs. |
|
370 lm->SetLandmarkNameL(_L("LandmarkName2")); |
|
371 lm->SetLandmarkDescriptionL(_L("SomeLandmarkDescription2")); |
|
372 lm->AddCategoryL(KBus_Stop); |
|
373 id = db->AddLandmarkL(*lm); |
|
374 CleanupStack::PopAndDestroy(2, db); |
|
375 |
|
376 db = CPosLandmarkDatabase::OpenL((*iDatabases)[2]); |
|
377 CleanupStack::PushL(db); |
|
378 lm = CPosLandmark::NewLC(); |
|
379 db->AddLandmarkL(*lm); // Add two uncategorized to increase id in order to avoid equal ids between dbs. |
|
380 db->AddLandmarkL(*lm); |
|
381 lm->SetLandmarkNameL(_L("LandmarkName3")); |
|
382 lm->SetLandmarkDescriptionL(_L("SomeLandmarkDescription3")); |
|
383 lm->AddCategoryL( globCatId2 ); |
|
384 lm->AddCategoryL(KHotel); |
|
385 //lm->AddCategoryL(KShop); |
|
386 lm->AddCategoryL(KBar); |
|
387 lm->AddCategoryL(KSports_Ground); |
|
388 lm->AddCategoryL(KGarage); |
|
389 id = db->AddLandmarkL(*lm); |
|
390 iGarageId1 = id; |
|
391 iGasStationId1 = id; |
|
392 CleanupStack::PopAndDestroy(2, db); |
|
393 |
|
394 db = CPosLandmarkDatabase::OpenL((*iDatabases)[3]); |
|
395 CleanupStack::PushL(db); |
|
396 lm = CPosLandmark::NewLC(); |
|
397 db->AddLandmarkL(*lm); // Add three uncategorized to increase id in order to avoid equal ids between dbs. |
|
398 db->AddLandmarkL(*lm); |
|
399 db->AddLandmarkL(*lm); |
|
400 lm->SetLandmarkNameL(_L("LandmarkName4")); |
|
401 lm->SetLandmarkDescriptionL(_L("SomeLandmarkDescription4")); |
|
402 lm->AddCategoryL(KBar); |
|
403 lm->AddCategoryL( globCatId1 ); |
|
404 lm->AddCategoryL( globCatId2 ); |
|
405 lm->AddCategoryL(KHotel); |
|
406 // lm->AddCategoryL(KShop); |
|
407 lm->AddCategoryL(KBar); |
|
408 lm->AddCategoryL(1); |
|
409 lm->AddCategoryL(2); |
|
410 lm->AddCategoryL(3); |
|
411 id = db->AddLandmarkL(*lm); |
|
412 iRestaurantId2 = id; |
|
413 iGasStationId2 = id; |
|
414 CleanupStack::PopAndDestroy(lm); |
|
415 |
|
416 lm = CPosLandmark::NewLC(); |
|
417 lm->SetLandmarkNameL(_L("LandmarkName5")); |
|
418 lm->SetLandmarkDescriptionL(_L("SomeLandmarkDescription5")); |
|
419 lm->AddCategoryL(KBus_Stop); |
|
420 db->AddLandmarkL(*lm); |
|
421 CleanupStack::PopAndDestroy(2, db); |
|
422 |
|
423 } |
|
424 |
|
425 // --------------------------------------------------------- |
|
426 // CPosTp121::SearchNonExistingL |
|
427 // |
|
428 // (other items were commented in a header). |
|
429 // --------------------------------------------------------- |
|
430 // |
|
431 void CPosTp121::SearchNonExistingL(TExecutionMode aExecutionMode) |
|
432 { |
|
433 iLog->Log(_L("SearchNonExistingL")); |
|
434 |
|
435 _LIT(KCategoryName, "NonExistingLandmark"); |
|
436 CPosLmCategoryCriteria* catSearchCriteria = CPosLmCategoryCriteria::NewLC(); |
|
437 catSearchCriteria->SetCategoryNameL(KCategoryName); |
|
438 |
|
439 SearchL(catSearchCriteria, aExecutionMode); |
|
440 ValidateTotalNrOfMatchesL(iMultiDbSearch->TotalNumOfMatches(), 0, KCategoryName); |
|
441 ValidateSearchResultsL(NULL, iMultiDbSearch); |
|
442 CleanupStack::PopAndDestroy(catSearchCriteria); |
|
443 |
|
444 catSearchCriteria = CPosLmCategoryCriteria::NewLC(); |
|
445 TPosLmGlobalCategory nonExistingId = 56789; |
|
446 catSearchCriteria->SetGlobalCategory(nonExistingId); |
|
447 |
|
448 SearchL(catSearchCriteria, aExecutionMode); |
|
449 ValidateTotalNrOfMatchesL(iMultiDbSearch->TotalNumOfMatches(), 0, KCategoryName); |
|
450 ValidateSearchResultsL(NULL, iMultiDbSearch); |
|
451 |
|
452 CleanupStack::PopAndDestroy(catSearchCriteria); |
|
453 } |
|
454 |
|
455 // --------------------------------------------------------- |
|
456 // CPosTp121::TestMaximumNrOfMatchesL |
|
457 // |
|
458 // (other items were commented in a header). |
|
459 // --------------------------------------------------------- |
|
460 // |
|
461 void CPosTp121::TestMaximumNrOfMatchesL( |
|
462 const RPointerArray<CCategoryLandmarkSearchResult>& aSearchResults, |
|
463 TExecutionMode aExecutionMode) |
|
464 { |
|
465 CPosLmCategoryCriteria* catSearchCriteria = CPosLmCategoryCriteria::NewLC(); |
|
466 |
|
467 TInt idFromXls = 25; // Use 25 "Läkarna" |
|
468 catSearchCriteria->SetCategoryNameL(aSearchResults[idFromXls]->CategoryName()); |
|
469 iLog->Log(aSearchResults[idFromXls]->CategoryName()); |
|
470 |
|
471 SearchL(catSearchCriteria, aExecutionMode, aSearchResults[idFromXls]->Redefined()); |
|
472 ValidateTotalNrOfMatchesL( |
|
473 iMultiDbSearch->TotalNumOfMatches(), |
|
474 (TUint)(aSearchResults[idFromXls]->SearchResult()).Count(), |
|
475 aSearchResults[idFromXls]->CategoryName()); |
|
476 ValidateSearchResultsL(aSearchResults[idFromXls], iMultiDbSearch); |
|
477 |
|
478 // Set maximum number, first set to more than should be found here 13 in each db must be enough |
|
479 iLog->Log(_L("Set to 13 * iNrOfDatabases = 65 matches")); |
|
480 TUint maxMatches = 13; |
|
481 iMultiDbSearch->SetMaxNumOfMatches(13); |
|
482 |
|
483 SearchL(catSearchCriteria, aExecutionMode, ETrue); |
|
484 ValidateTotalNrOfMatchesL( |
|
485 iMultiDbSearch->TotalNumOfMatches(), |
|
486 (TUint)(aSearchResults[idFromXls]->SearchResult()).Count(), |
|
487 aSearchResults[idFromXls]->CategoryName()); |
|
488 ValidateSearchResultsL(aSearchResults[idFromXls], iMultiDbSearch); |
|
489 |
|
490 // Set maximum number here to 3 in each db |
|
491 iLog->Log(_L("Set to 3 * iNrOfDatabases = 10 matches")); |
|
492 maxMatches = 3; |
|
493 const TInt KNrOfDbsWithMatches = 3; |
|
494 iMultiDbSearch->SetMaxNumOfMatches(maxMatches); |
|
495 |
|
496 SearchL(catSearchCriteria, aExecutionMode, ETrue); |
|
497 ValidateTotalNrOfMatchesL( |
|
498 iMultiDbSearch->TotalNumOfMatches(), |
|
499 maxMatches * KNrOfDbsWithMatches, // only three of the databases contain matches |
|
500 aSearchResults[idFromXls]->CategoryName()); |
|
501 ValidateSearchResultsL(aSearchResults[idFromXls], iMultiDbSearch); |
|
502 |
|
503 // Set maximum number here to 1 in each db |
|
504 maxMatches = 1; |
|
505 iLog->Log(_L("Set to 1 * iNrOfDatabases = 5 matches")); |
|
506 iMultiDbSearch->SetMaxNumOfMatches(maxMatches); |
|
507 SearchL(catSearchCriteria, aExecutionMode, ETrue); |
|
508 ValidateTotalNrOfMatchesL( |
|
509 iMultiDbSearch->TotalNumOfMatches(), |
|
510 maxMatches * KNrOfDbsWithMatches, |
|
511 aSearchResults[idFromXls]->CategoryName()); |
|
512 ValidateSearchResultsL(aSearchResults[idFromXls], iMultiDbSearch); |
|
513 |
|
514 // Set maximum number here to 2 in each db, however since search is refined only 3 matches should be returned |
|
515 maxMatches = 2; |
|
516 iLog->Log(_L("Set to 2 * iNrOfDatabases = 10 matches")); |
|
517 iMultiDbSearch->SetMaxNumOfMatches(maxMatches); |
|
518 SearchL(catSearchCriteria, aExecutionMode, ETrue); |
|
519 ValidateTotalNrOfMatchesL( |
|
520 iMultiDbSearch->TotalNumOfMatches(), |
|
521 1 * KNrOfDbsWithMatches, |
|
522 aSearchResults[idFromXls]->CategoryName()); |
|
523 ValidateSearchResultsL(aSearchResults[idFromXls], iMultiDbSearch); |
|
524 |
|
525 // Same as above but no refined search is made. Should get 2 * 3 matches |
|
526 iLog->Log(_L("Set to 2 * iNrOfDatabases = 10 matches")); |
|
527 iMultiDbSearch->SetMaxNumOfMatches(maxMatches); |
|
528 SearchL(catSearchCriteria, aExecutionMode); |
|
529 ValidateTotalNrOfMatchesL( |
|
530 iMultiDbSearch->TotalNumOfMatches(), |
|
531 maxMatches * KNrOfDbsWithMatches, |
|
532 aSearchResults[idFromXls]->CategoryName()); |
|
533 ValidateSearchResultsL(aSearchResults[idFromXls], iMultiDbSearch); |
|
534 |
|
535 // Set back to unlimited |
|
536 iMultiDbSearch->SetMaxNumOfMatches(); |
|
537 |
|
538 CleanupStack::PopAndDestroy(catSearchCriteria); |
|
539 } |
|
540 |
|
541 // --------------------------------------------------------- |
|
542 // CPosTp121::TestLeaveCodesL |
|
543 // |
|
544 // (other items were commented in a header). |
|
545 // --------------------------------------------------------- |
|
546 // |
|
547 void CPosTp121::TestLeaveCodesL() |
|
548 { |
|
549 iLog->Log(_L("TestLeaveCodesL")); |
|
550 |
|
551 TPosLmSortPref sortPref(CPosLandmark::ECategoryInfo, TPosLmSortPref::EAscending); |
|
552 CPosLmCategoryCriteria* catSearchCriteria = CPosLmCategoryCriteria::NewLC(); |
|
553 |
|
554 // Only ECategoryName is supported,all other leave with KErrNotSupported |
|
555 TRAPD(err, iMultiDbSearch->StartLandmarkSearchL(*catSearchCriteria, sortPref)); |
|
556 AssertTrueSecL(err == KErrNotSupported, _L("Should have left with KErrNotSupported")); |
|
557 |
|
558 // Only ECategoryName is supported,all other leave with KErrNotSupported |
|
559 sortPref.SetSortByLandmarkAttribute(CPosLandmark::EDescription, TPosLmSortPref::EDescending); |
|
560 TRAP(err, iMultiDbSearch->StartLandmarkSearchL(*catSearchCriteria, sortPref)); |
|
561 AssertTrueSecL(err == KErrNotSupported, _L("Should have left with KErrNotSupported")); |
|
562 |
|
563 // Test search by local category id |
|
564 catSearchCriteria->SetCategoryItemId(7); |
|
565 TRAP(err, iMultiDbSearch->StartLandmarkSearchL(*catSearchCriteria)); |
|
566 AssertTrueSecL(err == KErrArgument, _L("Should have left with KErrArgument")); |
|
567 |
|
568 // Test search by too long category name > 124 = KPosLmMaxCategoryNameLength |
|
569 TBuf<KPosLmMaxCategoryNameLength + 4> name = _L("12345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678"); |
|
570 TRAP(err, catSearchCriteria->SetCategoryNameL(name)); |
|
571 AssertTrueSecL(err == KErrArgument, _L("Should have left with KErrArgument")); |
|
572 |
|
573 CleanupStack::PopAndDestroy(catSearchCriteria); |
|
574 } |
|
575 |
|
576 // --------------------------------------------------------- |
|
577 // CPosTp121::SearchAndCancelL |
|
578 // |
|
579 // (other items were commented in a header). |
|
580 // --------------------------------------------------------- |
|
581 // |
|
582 void CPosTp121::SearchAndCancelL() |
|
583 { |
|
584 // Test search with one criteria |
|
585 const TInt KIndex=0; |
|
586 |
|
587 CPosLmCategoryCriteria* catSearchCriteria = CPosLmCategoryCriteria::NewLC(); |
|
588 catSearchCriteria->SetCategoryNameL(iCategoryLandmarkSearchResults[KIndex]->CategoryName()); |
|
589 |
|
590 TReal32 progress(0); |
|
591 while (progress < 1.0) |
|
592 { |
|
593 RunAsyncOperationAndCancelInCallbackLD( |
|
594 iMultiDbSearch->StartLandmarkSearchL( |
|
595 *catSearchCriteria, |
|
596 iCategoryLandmarkSearchResults[KIndex]->Redefined()), |
|
597 progress); |
|
598 |
|
599 TInt nrOfMatches = 0; |
|
600 for (TInt j = 0; j < iNrOfDatabases; j++) |
|
601 { |
|
602 CPosLmItemIterator* iter = iMultiDbSearch->MatchIteratorL(j); |
|
603 CleanupStack::PushL(iter); |
|
604 nrOfMatches += iter->NumOfItemsL(); |
|
605 CleanupStack::PopAndDestroy(iter); |
|
606 } |
|
607 AssertTrueSecL(nrOfMatches == iMultiDbSearch->TotalNumOfMatches(), _L("Total nr of matches doesn't match sum of matches in iterators when cancelling")); |
|
608 |
|
609 progress = progress + 0.09; |
|
610 } |
|
611 |
|
612 CleanupStack::PopAndDestroy(catSearchCriteria); |
|
613 } |
|
614 |
|
615 |
|
616 // --------------------------------------------------------- |
|
617 // CPosTp121::ValidateIdL |
|
618 // |
|
619 // (other items were commented in a header). |
|
620 // --------------------------------------------------------- |
|
621 // |
|
622 void CPosTp121::ValidateIdL(TPosLmItemId aId, TInt aDbIndex) |
|
623 { |
|
624 TBool condition = EFalse; |
|
625 switch (aDbIndex) |
|
626 { |
|
627 case 0: |
|
628 // Db 0 contains landmarks with id = 1-20 |
|
629 condition = aId >= 1 && aId <= 20; |
|
630 break; |
|
631 case 1: |
|
632 // Db 1 contains landmarks with id = 21-40 |
|
633 condition = aId >= 21 && aId <= 40; |
|
634 break; |
|
635 case 2: |
|
636 // Db 2 contains landmarks with id = 41-60 |
|
637 condition = aId >= 41 && aId <= 60; |
|
638 break; |
|
639 case 3: |
|
640 // Db 3 contains landmarks with id = 61-80 |
|
641 condition = aId >= 61 && aId <= 80; |
|
642 break; |
|
643 case 4: |
|
644 // Db 4 contains landmarks with id = 81-105 |
|
645 condition = aId >= 81 && aId <= 105; |
|
646 break; |
|
647 } |
|
648 |
|
649 AssertTrueSecL(condition, _L("Invalid match from database reported")); |
|
650 } |
|
651 |
|
652 // --------------------------------------------------------- |
|
653 // CPosTp121::ValidateTotalNrOfMatchesL |
|
654 // |
|
655 // (other items were commented in a header). |
|
656 // --------------------------------------------------------- |
|
657 // |
|
658 void CPosTp121::ValidateTotalNrOfMatchesL( |
|
659 TUint aRetrievedNrOfMatches, |
|
660 TUint aExpectedNrOfMatches, |
|
661 const TDesC& aCategoryName) |
|
662 { |
|
663 _LIT(KNumOfMatchesErr, "No. of matches is incorrect when the search is performed"); |
|
664 |
|
665 if (aRetrievedNrOfMatches != aExpectedNrOfMatches) |
|
666 { |
|
667 _LIT(KExpected, "Expected no. of matches: %d"); |
|
668 _LIT(KReturned, "Returned no. of matches: %d"); |
|
669 TBuf<100> info; |
|
670 info.Format(KExpected, aExpectedNrOfMatches); |
|
671 iLog->Log(info); |
|
672 info.Format(KReturned, aRetrievedNrOfMatches); |
|
673 iLog->Log(info); |
|
674 _LIT(KFormat, "Search criteria: %S"); |
|
675 info.Format(KFormat, &aCategoryName); |
|
676 iLog->Log(info); |
|
677 iLog->Log(KNumOfMatchesErr); |
|
678 User::Leave(-1); |
|
679 } |
|
680 } |
|
681 |
|
682 // --------------------------------------------------------- |
|
683 // CPosTp121::ValidateSearchResultsL |
|
684 // |
|
685 // (other items were commented in a header). |
|
686 // --------------------------------------------------------- |
|
687 // |
|
688 void CPosTp121::ValidateSearchResultsL( |
|
689 CCategoryLandmarkSearchResult* aExpectedSearchResult, |
|
690 CPosLmMultiDbSearch* aMultiDbSearcher, |
|
691 TTp121SortOrder aSortOrder) |
|
692 { |
|
693 _LIT(KNotFoundErr, "Id %d not found in parsed Lm search results"); |
|
694 |
|
695 TInt nrOfMatches = 0; |
|
696 for (TInt j = 0; j < iNrOfDatabases; j++) |
|
697 { |
|
698 CPosLandmarkDatabase* db = CPosLandmarkDatabase::OpenL((*iDatabases)[j]); |
|
699 CleanupStack::PushL(db); |
|
700 CPosLmItemIterator* iter = aMultiDbSearcher->MatchIteratorL(j); |
|
701 CleanupStack::PushL(iter); |
|
702 |
|
703 nrOfMatches += iter->NumOfItemsL(); |
|
704 TPosLmItemId id = iter->NextL(); |
|
705 while (id != KPosLmNullItemId) |
|
706 { |
|
707 ValidateIdL(id, j); |
|
708 AssertTrueSecL(aExpectedSearchResult->FindSearchResult(id), KNotFoundErr, id); |
|
709 CPosLandmark* lm1 = db->ReadLandmarkLC(id); |
|
710 id = iter->NextL(); |
|
711 if (aSortOrder != ESortNone && id != KPosLmNullItemId) |
|
712 { |
|
713 CPosLandmark* lm2 = db->ReadLandmarkLC(id); |
|
714 TPtrC name1, name2; |
|
715 lm1->GetLandmarkName(name1); |
|
716 lm2->GetLandmarkName(name2); |
|
717 if (aSortOrder == ESortAscending) |
|
718 { |
|
719 AssertTrueSecL(name1.CompareC(name2) <= 0, _L("Not sorted ascending as expected")); |
|
720 } |
|
721 else // aSortOrder == ESortDescending |
|
722 { |
|
723 AssertTrueSecL(name1.CompareC(name2) >= 0, _L("Not sorted descending as expected")); |
|
724 } |
|
725 CleanupStack::PopAndDestroy(lm2); |
|
726 } |
|
727 CleanupStack::PopAndDestroy(lm1); |
|
728 } |
|
729 CleanupStack::PopAndDestroy(2, db); |
|
730 } |
|
731 AssertTrueSecL(nrOfMatches == aMultiDbSearcher->TotalNumOfMatches(), _L("Total nr of matches doesn't match sum of matches in iterators")); |
|
732 AssertTrueSecL(NrOfSearchErrors(aMultiDbSearcher) == 0, _L("Found search errors!")); |
|
733 } |
|
734 |
|
735 // --------------------------------------------------------- |
|
736 // CPosTp121::ValidateSearchResultsL |
|
737 // |
|
738 // (other items were commented in a header). |
|
739 // --------------------------------------------------------- |
|
740 // |
|
741 void CPosTp121::ValidateSearchResultsL( |
|
742 const RIdArray& aExpectedIds, |
|
743 CPosLmMultiDbSearch* aMultiDbSearcher, |
|
744 TInt aNrOfExpectedErrors) |
|
745 { |
|
746 _LIT(KNotFoundErr, "Id %d not found in expected Lm search results"); |
|
747 |
|
748 TInt nrOfMatches = 0; |
|
749 for (TInt j = 0; j < iNrOfDatabases; j++) |
|
750 { |
|
751 CPosLmItemIterator* iter = aMultiDbSearcher->MatchIteratorL(j); |
|
752 CleanupStack::PushL(iter); |
|
753 nrOfMatches += iter->NumOfItemsL(); |
|
754 |
|
755 TUint nrOfSearchMatches = aMultiDbSearcher->NumOfMatches( j ); |
|
756 |
|
757 TPosLmItemId id = iter->NextL(); |
|
758 while (id != KPosLmNullItemId) |
|
759 { |
|
760 AssertTrueSecL(aExpectedIds.Find(id) != KErrNotFound, KNotFoundErr, id); |
|
761 id = iter->NextL(); |
|
762 } |
|
763 CleanupStack::PopAndDestroy(iter); |
|
764 } |
|
765 AssertTrueSecL(nrOfMatches == aMultiDbSearcher->TotalNumOfMatches(), _L("Total nr of matches doesn't match sum of matches in iterators")); |
|
766 AssertTrueSecL(nrOfMatches == aExpectedIds.Count(), _L("Total nr of matches doesn't match expected")); |
|
767 AssertTrueSecL(NrOfSearchErrors(aMultiDbSearcher) == aNrOfExpectedErrors, _L("Found search errors!")); |
|
768 } |
|
769 |
|
770 // --------------------------------------------------------- |
|
771 // CPosTp121::SearchL |
|
772 // |
|
773 // (other items were commented in a header). |
|
774 // --------------------------------------------------------- |
|
775 // |
|
776 void CPosTp121::SearchL( |
|
777 CPosLmCategoryCriteria* aCatSearchCriteria, |
|
778 TExecutionMode aExecutionMode, |
|
779 TBool aRefinedSearch, |
|
780 TTp121SortOrder aSortOrder) |
|
781 { |
|
782 TPosLmSortPref ascending(CPosLandmark::ELandmarkName); |
|
783 TPosLmSortPref descending(CPosLandmark::ELandmarkName, TPosLmSortPref::EDescending); |
|
784 |
|
785 switch (aSortOrder) |
|
786 { |
|
787 case ESortNone: |
|
788 iOperation = iMultiDbSearch->StartLandmarkSearchL(*aCatSearchCriteria, aRefinedSearch); |
|
789 break; |
|
790 case ESortAscending: |
|
791 iOperation = iMultiDbSearch->StartLandmarkSearchL(*aCatSearchCriteria, ascending, aRefinedSearch); |
|
792 break; |
|
793 case ESortDescending: |
|
794 iOperation = iMultiDbSearch->StartLandmarkSearchL(*aCatSearchCriteria, descending, aRefinedSearch); |
|
795 break; |
|
796 default: |
|
797 User::Leave(KErrArgument); |
|
798 break; |
|
799 } |
|
800 |
|
801 switch (aExecutionMode) |
|
802 { |
|
803 case ESynchronous: |
|
804 ExecuteAndDeleteLD(iOperation); |
|
805 break; |
|
806 case EAsynchronous: |
|
807 RunAsyncOperationLD(iOperation); |
|
808 break; |
|
809 default: |
|
810 User::Leave(KErrArgument); |
|
811 break; |
|
812 } |
|
813 } |
|
814 |
|
815 // --------------------------------------------------------- |
|
816 // CPosTp121::TestResetSearchAttributesL |
|
817 // |
|
818 // (other items were commented in a header). |
|
819 // --------------------------------------------------------- |
|
820 // |
|
821 void CPosTp121::TestResetSearchAttributesL() |
|
822 { |
|
823 CPosLmCategoryCriteria* crit = CPosLmCategoryCriteria::NewLC(); |
|
824 |
|
825 // Verify default values |
|
826 TPosLmItemId id = crit->CategoryItemId(); |
|
827 AssertTrueSecL(id == KPosLmNullItemId, _L("id != KPosLmNullItemId")); |
|
828 TPosLmGlobalCategory globalId = crit->GlobalCategory(); |
|
829 AssertTrueSecL(globalId == KPosLmNullItemId, _L("globalId != KPosLmNullItemId")); |
|
830 TPtrC name = crit->CategoryName(); |
|
831 AssertTrueSecL(name.Length() == 0, _L("name.Length() != 0")); |
|
832 |
|
833 // Set id - other values should be default |
|
834 const TPosLmItemId KId = 10; |
|
835 crit->SetCategoryItemId(KId); |
|
836 AssertTrueSecL(crit->CategoryItemId() == KId, _L("id != KId")); |
|
837 AssertTrueSecL(crit->GlobalCategory()== KPosLmNullItemId, _L("globalId != KPosLmNullItemId")); |
|
838 AssertTrueSecL(crit->CategoryName().Length() == 0, _L("name.Length() != 0")); |
|
839 |
|
840 // Set name - other values should be default |
|
841 _LIT(KName, "Category Name"); |
|
842 crit->SetCategoryNameL(KName); |
|
843 AssertTrueSecL(crit->CategoryItemId() == KPosLmNullItemId, _L("id != KPosLmNullItemId")); |
|
844 AssertTrueSecL(crit->GlobalCategory()== KPosLmNullItemId, _L("globalId != KPosLmNullItemId")); |
|
845 AssertTrueSecL(crit->CategoryName() == KName, _L("name != KName")); |
|
846 |
|
847 // Set global id - other values should be default |
|
848 const TPosLmGlobalCategory KGlobalCategoryId = 20; |
|
849 crit->SetGlobalCategory(KGlobalCategoryId); |
|
850 AssertTrueSecL(crit->CategoryItemId() == KPosLmNullItemId, _L("id != KPosLmNullItemId")); |
|
851 AssertTrueSecL(crit->GlobalCategory()== KGlobalCategoryId, _L("globalId != KGlobalCategoryId")); |
|
852 AssertTrueSecL(crit->CategoryName().Length() == 0, _L("name.Length() != 0")); |
|
853 |
|
854 // Set id - other values should be default |
|
855 crit->SetCategoryItemId(KId); |
|
856 AssertTrueSecL(crit->CategoryItemId() == KId, _L("id != KId")); |
|
857 AssertTrueSecL(crit->GlobalCategory()== KPosLmNullItemId, _L("globalId != KPosLmNullItemId")); |
|
858 AssertTrueSecL(crit->CategoryName().Length() == 0, _L("name.Length() != 0")); |
|
859 |
|
860 CleanupStack::PopAndDestroy(crit); |
|
861 } |
|
862 |
|
863 // --------------------------------------------------------- |
|
864 // CPosTp121::TestCaseInsensitiveL |
|
865 // |
|
866 // (other items were commented in a header). |
|
867 // --------------------------------------------------------- |
|
868 // |
|
869 void CPosTp121::TestCaseInsensitiveL() |
|
870 { |
|
871 CPosLmCategoryCriteria* crit = CPosLmCategoryCriteria::NewLC(); |
|
872 RIdArray expectedIds; |
|
873 CleanupClosePushL(expectedIds); |
|
874 |
|
875 // Search for "rEStaUrANt", should result in no match |
|
876 TBuf<25> rest = _L("rEStaUrANt"); |
|
877 crit->SetCategoryNameL(rest); |
|
878 SearchL(crit, ESynchronous); |
|
879 ValidateSearchResultsL(expectedIds, iMultiDbSearch); |
|
880 |
|
881 // Search for "RESTAURANT", should result in no match |
|
882 rest.UpperCase(); |
|
883 crit->SetCategoryNameL(rest); |
|
884 SearchL(crit, EAsynchronous); |
|
885 ValidateSearchResultsL(expectedIds, iMultiDbSearch); |
|
886 |
|
887 // Search for "Restaurant", should result in two matches |
|
888 HBufC* restaurant = GetGlobalCategoryFromResourceLC( KAccommodation ); |
|
889 crit->SetCategoryNameL(*restaurant); |
|
890 SearchL(crit, ESynchronous); |
|
891 expectedIds.AppendL(iRestaurantId1); |
|
892 expectedIds.AppendL(iRestaurantId2); |
|
893 ValidateSearchResultsL(expectedIds, iMultiDbSearch); |
|
894 CleanupStack::PopAndDestroy( restaurant ); |
|
895 |
|
896 // Search for "mCDoNAldS", should result in no match |
|
897 rest = _L("mCDoNAldS"); |
|
898 crit->SetCategoryNameL(rest); |
|
899 SearchL(crit, EAsynchronous); |
|
900 expectedIds.Reset(); |
|
901 ValidateSearchResultsL(expectedIds, iMultiDbSearch); |
|
902 |
|
903 // Search for "MCDONALDS", should result in no match |
|
904 rest.UpperCase(); |
|
905 crit->SetCategoryNameL(rest); |
|
906 SearchL(crit, ESynchronous); |
|
907 ValidateSearchResultsL(expectedIds, iMultiDbSearch); |
|
908 |
|
909 // Search for "McDonalds", should result in two matches |
|
910 rest = _L("McDonalds"); |
|
911 crit->SetCategoryNameL(rest); |
|
912 SearchL(crit, EAsynchronous); |
|
913 expectedIds.AppendL(7); |
|
914 expectedIds.AppendL(27); |
|
915 ValidateSearchResultsL(expectedIds, iMultiDbSearch); |
|
916 CleanupStack::PopAndDestroy(2, crit); |
|
917 } |
|
918 |
|
919 // --------------------------------------------------------- |
|
920 // CPosTp121::TestWildCardsL |
|
921 // |
|
922 // (other items were commented in a header). |
|
923 // --------------------------------------------------------- |
|
924 // |
|
925 void CPosTp121::TestWildCardsL() |
|
926 { |
|
927 CPosLmCategoryCriteria* crit = CPosLmCategoryCriteria::NewLC(); |
|
928 const TInt KNrOfArrays = 5; |
|
929 RIdArray* idArrays[KNrOfArrays]; |
|
930 for (TInt i = 0; i < KNrOfArrays; i++) |
|
931 { |
|
932 RIdArray* array = new (ELeave) RIdArray; |
|
933 CleanupStack::PushL(array); |
|
934 CleanupClosePushL(*array); |
|
935 idArrays[i] = array; |
|
936 } |
|
937 RIdArray empty; |
|
938 CleanupClosePushL(empty); |
|
939 |
|
940 // Search for "*", should result in no matches |
|
941 crit->SetCategoryNameL(_L("*")); |
|
942 SearchL(crit, ESynchronous); |
|
943 ValidateSearchResultsL(empty, iMultiDbSearch); |
|
944 |
|
945 // Search for "?", should result in no matches |
|
946 crit->SetCategoryNameL(_L("?")); |
|
947 SearchL(crit, EAsynchronous); |
|
948 ValidateSearchResultsL(empty, iMultiDbSearch); |
|
949 |
|
950 // -------------- Setup databases -------------- |
|
951 |
|
952 // Add a category to db0 |
|
953 CPosLandmarkDatabase* db = CPosLandmarkDatabase::OpenL((*iDatabases)[0]); |
|
954 CleanupStack::PushL(db); |
|
955 CPosLmCategoryManager* catMan = CPosLmCategoryManager::NewL(*db); |
|
956 CleanupStack::PushL(catMan); |
|
957 CPosLandmarkCategory* category = CPosLandmarkCategory::NewLC(); |
|
958 |
|
959 // Add category "*wild card" |
|
960 _LIT(KCategory0, "*wild card"); |
|
961 category->SetCategoryNameL(KCategory0); |
|
962 TPosLmItemId id0 = catMan->AddCategoryL(*category); |
|
963 idArrays[0]->AppendL(1); |
|
964 idArrays[0]->AppendL(2); |
|
965 ExecuteAndDeleteLD(catMan->AddCategoryToLandmarksL(id0, *idArrays[0])); |
|
966 CleanupStack::PopAndDestroy(3, db); |
|
967 |
|
968 // Add categories to db2 |
|
969 db = CPosLandmarkDatabase::OpenL((*iDatabases)[2]); |
|
970 CleanupStack::PushL(db); |
|
971 catMan = CPosLmCategoryManager::NewL(*db); |
|
972 CleanupStack::PushL(catMan); |
|
973 category = CPosLandmarkCategory::NewLC(); |
|
974 |
|
975 // Add category "wi?d c?rd" |
|
976 _LIT(KCategory1, "wi?d c?rd"); |
|
977 category->SetCategoryNameL(KCategory1); |
|
978 TPosLmItemId id1 = catMan->AddCategoryL(*category); |
|
979 idArrays[1]->AppendL(44); |
|
980 idArrays[1]->AppendL(45); |
|
981 ExecuteAndDeleteLD(catMan->AddCategoryToLandmarksL(id1, *idArrays[1])); |
|
982 |
|
983 // Add category "***" |
|
984 _LIT(KCategory2, "***"); |
|
985 category->SetCategoryNameL(KCategory2); |
|
986 TPosLmItemId id2 = catMan->AddCategoryL(*category); |
|
987 idArrays[2]->AppendL(44); |
|
988 idArrays[2]->AppendL(47); |
|
989 idArrays[2]->AppendL(55); |
|
990 ExecuteAndDeleteLD(catMan->AddCategoryToLandmarksL(id2, *idArrays[2])); |
|
991 CleanupStack::PopAndDestroy(3, db); |
|
992 |
|
993 // Add categories to db4 |
|
994 db = CPosLandmarkDatabase::OpenL((*iDatabases)[4]); |
|
995 CleanupStack::PushL(db); |
|
996 catMan = CPosLmCategoryManager::NewL(*db); |
|
997 CleanupStack::PushL(catMan); |
|
998 category = CPosLandmarkCategory::NewLC(); |
|
999 |
|
1000 // Add category "?" |
|
1001 _LIT(KCategory3, "?"); |
|
1002 category->SetCategoryNameL(KCategory3); |
|
1003 TPosLmItemId id3 = catMan->AddCategoryL(*category); |
|
1004 idArrays[3]->AppendL(86); |
|
1005 idArrays[3]->AppendL(81); |
|
1006 idArrays[3]->AppendL(104); |
|
1007 ExecuteAndDeleteLD(catMan->AddCategoryToLandmarksL(id3, *idArrays[3])); |
|
1008 |
|
1009 // Add category "wi?d ca*" |
|
1010 _LIT(KCategory4, "wi?d ca*"); |
|
1011 category->SetCategoryNameL(KCategory4); |
|
1012 TPosLmItemId id4 = catMan->AddCategoryL(*category); |
|
1013 idArrays[4]->AppendL(101); |
|
1014 ExecuteAndDeleteLD(catMan->AddCategoryToLandmarksL(id4, *idArrays[4])); |
|
1015 CleanupStack::PopAndDestroy(3, db); |
|
1016 |
|
1017 // -------------- Search and verify -------------- |
|
1018 |
|
1019 // Search for "*" and verify results - no matches expected |
|
1020 crit->SetCategoryNameL(_L("*")); |
|
1021 SearchL(crit, ESynchronous); |
|
1022 ValidateSearchResultsL(empty, iMultiDbSearch); |
|
1023 |
|
1024 // Search for "*wild*" and verify results - no matches expected |
|
1025 crit->SetCategoryNameL(_L("*wild*")); |
|
1026 SearchL(crit, EAsynchronous); |
|
1027 ValidateSearchResultsL(empty, iMultiDbSearch); |
|
1028 |
|
1029 // Search for "w?ld ca?d" and verify results - no matches expected |
|
1030 crit->SetCategoryNameL(_L("w?ld ca?d")); |
|
1031 SearchL(crit, ESynchronous); |
|
1032 ValidateSearchResultsL(empty, iMultiDbSearch); |
|
1033 |
|
1034 // Search for "wi?d c?rd" and verify results - two matches expected |
|
1035 crit->SetCategoryNameL(KCategory1); |
|
1036 SearchL(crit, EAsynchronous); |
|
1037 ValidateSearchResultsL(*idArrays[1], iMultiDbSearch); |
|
1038 |
|
1039 // Search for "****" and verify results - no matches expected |
|
1040 crit->SetCategoryNameL(_L("****")); |
|
1041 SearchL(crit, ESynchronous); |
|
1042 ValidateSearchResultsL(empty, iMultiDbSearch); |
|
1043 |
|
1044 // Search for "***" and verify results - three matches expected |
|
1045 crit->SetCategoryNameL(KCategory2); |
|
1046 SearchL(crit, EAsynchronous); |
|
1047 ValidateSearchResultsL(*idArrays[2], iMultiDbSearch); |
|
1048 |
|
1049 // Search for "**" and verify results - no matches expected |
|
1050 crit->SetCategoryNameL(_L("**")); |
|
1051 SearchL(crit, ESynchronous); |
|
1052 ValidateSearchResultsL(empty, iMultiDbSearch); |
|
1053 |
|
1054 // Search for "?" and verify results - two matches expected |
|
1055 crit->SetCategoryNameL(KCategory3); |
|
1056 SearchL(crit, EAsynchronous); |
|
1057 ValidateSearchResultsL(*idArrays[3], iMultiDbSearch); |
|
1058 |
|
1059 // Search for "?*" and verify results - no matches expected |
|
1060 crit->SetCategoryNameL(_L("?*")); |
|
1061 SearchL(crit, ESynchronous); |
|
1062 ValidateSearchResultsL(empty, iMultiDbSearch); |
|
1063 |
|
1064 // Search for "wi?d ca*" and verify results - one match expected |
|
1065 crit->SetCategoryNameL(KCategory4); |
|
1066 SearchL(crit, EAsynchronous); |
|
1067 ValidateSearchResultsL(*idArrays[4], iMultiDbSearch); |
|
1068 |
|
1069 // Search for "wi?d card" and verify results - no matches expected |
|
1070 crit->SetCategoryNameL(_L("wi?d card")); |
|
1071 SearchL(crit, ESynchronous); |
|
1072 ValidateSearchResultsL(empty, iMultiDbSearch); |
|
1073 |
|
1074 CleanupStack::PopAndDestroy(&empty); |
|
1075 CleanupStack::PopAndDestroy(2 * KNrOfArrays); |
|
1076 CleanupStack::PopAndDestroy(crit); |
|
1077 } |
|
1078 |
|
1079 // --------------------------------------------------------- |
|
1080 // CPosTp121::TestRefinedSearchL |
|
1081 // |
|
1082 // (other items were commented in a header). |
|
1083 // --------------------------------------------------------- |
|
1084 // |
|
1085 void CPosTp121::TestRefinedSearchL(TExecutionMode aExecutionMode) |
|
1086 { |
|
1087 CPosLmCategoryCriteria* crit = CPosLmCategoryCriteria::NewLC(); |
|
1088 RIdArray idArray; |
|
1089 CleanupClosePushL(idArray); |
|
1090 |
|
1091 // Make a search for local category name |
|
1092 crit->SetCategoryNameL(_L("TietoEnator kontor")); // lm 7,27,51-61 will be found according to xls-sheet and code above |
|
1093 idArray.AppendL(7); |
|
1094 idArray.AppendL(27); |
|
1095 for (TInt i = 51; i <= 61; i++) |
|
1096 { |
|
1097 idArray.AppendL(i); |
|
1098 } |
|
1099 SearchL(crit, aExecutionMode); |
|
1100 ValidateSearchResultsL(idArray, iMultiDbSearch); |
|
1101 |
|
1102 // Refine the previous search by specifying another local category name |
|
1103 crit->SetCategoryNameL(_L("BurgerKing")); // lm 7,27,51-54 will be found according to xls-sheet and the code above |
|
1104 for (TInt i = idArray.Count() - 1; i >= 5; i--) |
|
1105 { |
|
1106 idArray.Remove(i); |
|
1107 } |
|
1108 SearchL(crit, aExecutionMode, ETrue); |
|
1109 ValidateSearchResultsL(idArray, iMultiDbSearch); |
|
1110 |
|
1111 // Repeat previous step but set max nr of matches to 1 - only 7,27,51 will be found |
|
1112 iMultiDbSearch->SetMaxNumOfMatches(1); |
|
1113 for (TInt i = idArray.Count() - 1; i >= 3; i--) |
|
1114 { |
|
1115 idArray.Remove(i); |
|
1116 } |
|
1117 SearchL(crit, aExecutionMode, ETrue); |
|
1118 ValidateSearchResultsL(idArray, iMultiDbSearch); |
|
1119 |
|
1120 // Increase max nr of matches to 10 => all qualified lms will be found |
|
1121 crit->SetCategoryNameL(_L("TietoEnator kontor")); |
|
1122 iMultiDbSearch->SetMaxNumOfMatches(10); |
|
1123 for (TInt i = 52; i <= 61; i++) |
|
1124 { |
|
1125 idArray.AppendL(i); |
|
1126 } |
|
1127 SearchL(crit, aExecutionMode); |
|
1128 ValidateSearchResultsL(idArray, iMultiDbSearch); |
|
1129 |
|
1130 // Refine search with the global category gas station by searching by id |
|
1131 crit->SetGlobalCategory(15000); // Entertainment |
|
1132 idArray.Reset(); |
|
1133 for (TInt i = 51; i <= 53; i++) |
|
1134 { |
|
1135 idArray.AppendL(i); |
|
1136 } |
|
1137 SearchL(crit, aExecutionMode, ETrue); |
|
1138 ValidateSearchResultsL(idArray, iMultiDbSearch); |
|
1139 |
|
1140 // Refine search with the local category Pizzeria by searching by name |
|
1141 crit->SetCategoryNameL(_L("Pizzeria")); // only lm 51 should be found |
|
1142 idArray.Remove(1); |
|
1143 idArray.Remove(1); |
|
1144 SearchL(crit, aExecutionMode, ETrue); |
|
1145 ValidateSearchResultsL(idArray, iMultiDbSearch); |
|
1146 |
|
1147 // Refine search with a global id that does not exist |
|
1148 crit->SetGlobalCategory(10000); // no lms should be found |
|
1149 idArray.Remove(0); |
|
1150 SearchL(crit, aExecutionMode, ETrue); |
|
1151 ValidateSearchResultsL(idArray, iMultiDbSearch); |
|
1152 |
|
1153 iMultiDbSearch->SetMaxNumOfMatches(); |
|
1154 CleanupStack::PopAndDestroy(2, crit); |
|
1155 } |
|
1156 |
|
1157 // --------------------------------------------------------- |
|
1158 // CPosTp121::TestDatabaseListL |
|
1159 // |
|
1160 // (other items were commented in a header). |
|
1161 // --------------------------------------------------------- |
|
1162 // |
|
1163 void CPosTp121::TestDatabaseListL(const RIdArray& aExpectedMatches) |
|
1164 { |
|
1165 iLog->Log(_L("TestDatabaseListL")); |
|
1166 _LIT(KNonExistingDb, "Jimmi.ldb"); |
|
1167 // Append an invalid(missing extension) database and search |
|
1168 |
|
1169 iDatabases->AppendL(_L("Jimmi")); |
|
1170 iNrOfDatabases++; |
|
1171 iMultiDbSearch->SetDatabasesToSearchL(*iDatabases); |
|
1172 |
|
1173 CPosLmCategoryCriteria* catSearchCriteria = CPosLmCategoryCriteria::NewLC(); |
|
1174 catSearchCriteria->SetGlobalCategory(15000); // Entertainment |
|
1175 SearchL(catSearchCriteria, ESynchronous); |
|
1176 |
|
1177 ValidateSearchResultsL(aExpectedMatches, iMultiDbSearch, 1); // one error expected |
|
1178 CPosLmMultiDbSearch::TSearchError searchError; |
|
1179 iMultiDbSearch->GetSearchError(0, searchError); |
|
1180 AssertTrueSecL(searchError.iDatabaseIndex == 5, _L("Error in wrong database")); |
|
1181 AssertTrueSecL(searchError.iErrorCode == KErrArgument, _L("Wrong error in database, %d"), searchError.iErrorCode); |
|
1182 |
|
1183 // Remove non-existing database + another one and search - no errors should occur |
|
1184 TPtrC dbName = (*iDatabases)[iDatabases->Count() - 2]; |
|
1185 iDatabases->Delete(iDatabases->Count() - 2, 2); |
|
1186 iNrOfDatabases = iNrOfDatabases - 2; |
|
1187 iMultiDbSearch->SetDatabasesToSearchL(*iDatabases); |
|
1188 |
|
1189 SearchL(catSearchCriteria, EAsynchronous); |
|
1190 |
|
1191 ValidateSearchResultsL(aExpectedMatches, iMultiDbSearch); |
|
1192 |
|
1193 iDatabases->AppendL(KDb105); |
|
1194 iNrOfDatabases++; |
|
1195 CleanupStack::PopAndDestroy(catSearchCriteria); |
|
1196 |
|
1197 // Verify that NewL for CPosLmMultiDbSearch is correct |
|
1198 iDatabases->AppendL(KNonExistingDb); |
|
1199 iNrOfDatabases++; |
|
1200 CPosLmMultiDbSearch* multiDb = CPosLmMultiDbSearch::NewL(*iDatabases); |
|
1201 CleanupStack::PushL(multiDb); |
|
1202 |
|
1203 catSearchCriteria = CPosLmCategoryCriteria::NewLC(); |
|
1204 catSearchCriteria->SetGlobalCategory(15000); // Entertainment |
|
1205 |
|
1206 iOperation = multiDb->StartLandmarkSearchL(*catSearchCriteria, EFalse); |
|
1207 ExecuteAndDeleteLD(iOperation); |
|
1208 |
|
1209 ValidateSearchResultsL(aExpectedMatches, multiDb, 1); // one error expected |
|
1210 multiDb->GetSearchError(0, searchError); |
|
1211 AssertTrueSecL(searchError.iDatabaseIndex == 5, _L("Error in wrong database")); |
|
1212 AssertTrueSecL(searchError.iErrorCode == KErrNotFound, _L("Wrong error in database, %d"), searchError.iErrorCode); |
|
1213 |
|
1214 // Remove added db from list |
|
1215 TInt pos = 0; |
|
1216 |
|
1217 TInt res = iDatabases->Find(KNonExistingDb, pos); |
|
1218 if (res == KErrNone) iDatabases->Delete(pos); |
|
1219 iNrOfDatabases--; |
|
1220 CleanupStack::PopAndDestroy(catSearchCriteria); |
|
1221 CleanupStack::PopAndDestroy(multiDb); |
|
1222 } |
|
1223 |
|
1224 // --------------------------------------------------------- |
|
1225 // CPosTp121::TestOnTheFlySearchL |
|
1226 // |
|
1227 // (other items were commented in a header). |
|
1228 // --------------------------------------------------------- |
|
1229 // |
|
1230 void CPosTp121::TestOnTheFlySearchL(const RIdArray& aExpectedMatches) |
|
1231 { |
|
1232 iMultiDbSearch->SetMaxNumOfMatches(KPosLmMaxNumOfMatchesUnlimited); |
|
1233 |
|
1234 CPosLmCategoryCriteria* catSearchCriteria = CPosLmCategoryCriteria::NewLC(); |
|
1235 catSearchCriteria->SetGlobalCategory(15000); // Entertainment |
|
1236 COnTheFlyTester* onTheFlyTester = COnTheFlyTester::NewLC(); |
|
1237 onTheFlyTester->StartSearchCampaignL(iMultiDbSearch, aExpectedMatches, catSearchCriteria); |
|
1238 TInt result = onTheFlyTester->Err(); |
|
1239 if (result != KErrNone) |
|
1240 { |
|
1241 TPtrC msg; |
|
1242 onTheFlyTester->GetErrMsg(msg); |
|
1243 iLog->Log(msg); |
|
1244 User::Leave(result); |
|
1245 } |
|
1246 CleanupStack::PopAndDestroy(2, catSearchCriteria); |
|
1247 } |
|
1248 |
|
1249 // --------------------------------------------------------- |
|
1250 // CPosTp121::NrOfSearchErrors |
|
1251 // |
|
1252 // (other items were commented in a header). |
|
1253 // --------------------------------------------------------- |
|
1254 // |
|
1255 TInt CPosTp121::NrOfSearchErrors(CPosLmMultiDbSearch* aMultiDbSearcher) |
|
1256 { |
|
1257 TInt nrOfSearchErrors = aMultiDbSearcher->NumOfSearchErrors(); |
|
1258 if (nrOfSearchErrors != 0) |
|
1259 { |
|
1260 for (TInt i = 0; i < nrOfSearchErrors; i++) |
|
1261 { |
|
1262 CPosLmMultiDbSearch::TSearchError error; |
|
1263 aMultiDbSearcher->GetSearchError(i, error); |
|
1264 TBuf<100> msg; |
|
1265 msg.Format(_L("Found error %d in database %d"), error.iErrorCode, error.iDatabaseIndex); |
|
1266 iLog->Log(msg); |
|
1267 } |
|
1268 } |
|
1269 return nrOfSearchErrors; |
|
1270 } |
|
1271 |
|
1272 // End of File |