|
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 "FT_CPosTp38.h" |
|
22 #include <EPos_CPosLandmarkDatabase.h> |
|
23 #include <EPos_CPosLmCompositeCriteria.h> |
|
24 #include <EPos_CPosLmCategoryCriteria.h> |
|
25 #include <EPos_CPosLmCatNameCriteria.h> |
|
26 #include <EPos_CPosLmNearestCriteria.h> |
|
27 #include <EPos_CPosLmAreaCriteria.h> |
|
28 #include <EPos_CPosLmTextCriteria.h> |
|
29 #include <EPos_CPosLmIdListCriteria.h> |
|
30 #include "FT_LandmarkConstants.h" |
|
31 |
|
32 #include "FT_CCompositeSearchResult.h" |
|
33 |
|
34 // ================= MEMBER FUNCTIONS ======================= |
|
35 |
|
36 // --------------------------------------------------------- |
|
37 // CPosTp38::CloseTest |
|
38 // |
|
39 // (other items were commented in a header). |
|
40 // --------------------------------------------------------- |
|
41 // |
|
42 void CPosTp38::CloseTest() |
|
43 { |
|
44 iLog->Log(_L("CloseTest")); |
|
45 delete iDatabase; |
|
46 iDatabase=NULL; |
|
47 |
|
48 delete iLandmarkSearch; |
|
49 iLandmarkSearch = NULL; |
|
50 |
|
51 } |
|
52 |
|
53 // --------------------------------------------------------- |
|
54 // CPosTp38::StartL |
|
55 // |
|
56 // (other items were commented in a header). |
|
57 // --------------------------------------------------------- |
|
58 // |
|
59 void CPosTp38::StartL() |
|
60 { |
|
61 TTime startTime; |
|
62 TTime stopTime; |
|
63 startTime.UniversalTime(); |
|
64 |
|
65 iDatabase = UseCompositeLandmarksDbFileL(); |
|
66 |
|
67 if (iDatabase->IsInitializingNeeded()) |
|
68 { |
|
69 ExecuteAndDeleteLD(iDatabase->InitializeL()); |
|
70 } |
|
71 |
|
72 StartLandmarksCompositeTestL(); |
|
73 |
|
74 TestCompositeInCompositeL(); |
|
75 |
|
76 TestSeveralTextArgumentsL(); |
|
77 |
|
78 TestSeveralTextArgumentsWithORL(); |
|
79 |
|
80 TestSortOrderWithORL(); |
|
81 |
|
82 TestWithSortOrderLandmarksL(); |
|
83 |
|
84 TestWithSortOrderNearestL(); |
|
85 |
|
86 TestTwoLmCategoryCriteriaL(); |
|
87 |
|
88 TestAddAndRemoveL(); |
|
89 |
|
90 TInt err = KErrNone; |
|
91 TRAP(err, TestWithNoPreviousResultL(0)); |
|
92 if (err != KErrArgument) |
|
93 |
|
94 { |
|
95 iLog->Log(_L("Searching with no previous result should cause StartLandmarkL to leave with KErrArgument")); |
|
96 User::Leave(err); |
|
97 } |
|
98 delete iLandmarkSearch; |
|
99 iLandmarkSearch = NULL; |
|
100 |
|
101 SearchAndCancelL(EFalse); |
|
102 SearchAndCancelL(ETrue); |
|
103 |
|
104 // Since category and composite is no longer allowed, no need to test this |
|
105 //TestWithSortOrderCategoriesL(); |
|
106 //TestCategoryCompositeSearchL(); |
|
107 |
|
108 stopTime.UniversalTime(); |
|
109 TTimeIntervalMicroSeconds executionTime = |
|
110 stopTime.MicroSecondsFrom(startTime); |
|
111 |
|
112 TInt resse = executionTime.Int64()/1000000; |
|
113 TBuf<100> buf; |
|
114 buf.Format(_L("TP38 took %d seconds"), resse); |
|
115 iLog->Log(buf); |
|
116 } |
|
117 |
|
118 // --------------------------------------------------------- |
|
119 // CPosTp38::TestWithSortOrderCategoriesL |
|
120 // |
|
121 // (other items were commented in a header). |
|
122 // --------------------------------------------------------- |
|
123 // |
|
124 void CPosTp38::TestWithSortOrderCategoriesL() |
|
125 { |
|
126 iLog->Log(_L("TestWithSortOrderCategoriesL")); |
|
127 |
|
128 iLandmarkSearch = CPosLandmarkSearch::NewL(*iDatabase); |
|
129 CPosLmCompositeCriteria* composite = CPosLmCompositeCriteria::NewLC(CPosLmCompositeCriteria::ECompositionAND); |
|
130 |
|
131 CPosLmCatNameCriteria* nameCriteria = CPosLmCatNameCriteria::NewLC(); |
|
132 nameCriteria->SetSearchPatternL(_L("*")); |
|
133 TInt err = composite->AddArgument(nameCriteria); |
|
134 if (err != KErrNone) |
|
135 { |
|
136 iLog->Log(_L("Error from AddArgument(nameCriteria)")); |
|
137 User::Leave(err); |
|
138 } |
|
139 CleanupStack::Pop(nameCriteria); |
|
140 |
|
141 CPosLmCategoryManager::TCategorySortPref sortPref; |
|
142 sortPref = CPosLmCategoryManager::ECategorySortOrderNameAscending; |
|
143 TInt i=0; |
|
144 TInt j=0; |
|
145 for (j=0;j<2;j++) |
|
146 { |
|
147 if (j==0) |
|
148 { |
|
149 iLog->Log(_L("Sorting Ascending")); |
|
150 sortPref = CPosLmCategoryManager::ECategorySortOrderNameAscending; |
|
151 } |
|
152 else |
|
153 { |
|
154 iLog->Log(_L("Sorting Descending")); |
|
155 sortPref = CPosLmCategoryManager::ECategorySortOrderNameDescending; |
|
156 } |
|
157 |
|
158 iLog->Log(_L("iLandmarkSearch->StartCategorySearchL")); |
|
159 iOperation = iLandmarkSearch->StartCategorySearchL(*composite, sortPref); |
|
160 |
|
161 ExecuteAndDeleteLD(iOperation); |
|
162 |
|
163 CPosLmItemIterator* iter = iLandmarkSearch->MatchIteratorL(); |
|
164 CleanupStack::PushL(iter); |
|
165 |
|
166 // Create a sorted list out of the search result |
|
167 RArray<TPosLmItemId> searchResults; |
|
168 CleanupClosePushL(searchResults); |
|
169 |
|
170 for (i=1;i<27;i++) {searchResults.Append(i);} |
|
171 |
|
172 CategoriesSortL(searchResults, sortPref); |
|
173 |
|
174 TPosLmItemId id = iter->NextL(); |
|
175 TInt counter=0; |
|
176 while (id != KPosLmNullItemId) |
|
177 { |
|
178 // Check that sort order is correct |
|
179 AssertTrueSecL(searchResults[counter] == id, _L("Error in sorting")); |
|
180 id = iter->NextL(); |
|
181 counter++; |
|
182 } |
|
183 CleanupStack::PopAndDestroy(&searchResults); |
|
184 CleanupStack::PopAndDestroy(iter); |
|
185 } |
|
186 CleanupStack::PopAndDestroy(composite); |
|
187 |
|
188 delete iLandmarkSearch; |
|
189 iLandmarkSearch = NULL; |
|
190 |
|
191 iLog->Log(_L("Done")); |
|
192 } |
|
193 |
|
194 // --------------------------------------------------------- |
|
195 // CPosTp38::TestWithSortOrderNearestL |
|
196 // |
|
197 // (other items were commented in a header). |
|
198 // --------------------------------------------------------- |
|
199 // |
|
200 void CPosTp38::TestWithSortOrderNearestL() |
|
201 { |
|
202 |
|
203 iLog->Log(_L("TestWithSortOrderNearestL")); |
|
204 |
|
205 iLandmarkSearch = CPosLandmarkSearch::NewL(*iDatabase); |
|
206 CPosLmCompositeCriteria* composite = CPosLmCompositeCriteria::NewLC(CPosLmCompositeCriteria::ECompositionAND); |
|
207 |
|
208 // First create a textcriteria |
|
209 CPosLmTextCriteria* textCriteria = CPosLmTextCriteria::NewLC(); |
|
210 textCriteria->SetTextL(_L("*")); |
|
211 TInt err = composite->AddArgument(textCriteria); |
|
212 if (err != KErrNone) |
|
213 { |
|
214 iLog->Log(_L("Error when adding argument1")); |
|
215 User::Leave(err); |
|
216 } |
|
217 CleanupStack::Pop(textCriteria); |
|
218 |
|
219 // Then create a nearest criteria same coordinate as landmark itemid=3 God |
|
220 TCoordinate coord(45, 45); |
|
221 CPosLmNearestCriteria* nearestCriteria = CPosLmNearestCriteria::NewLC(coord, EFalse); |
|
222 err = composite->AddArgument(nearestCriteria); |
|
223 if (err != KErrNone) |
|
224 |
|
225 { |
|
226 iLog->Log(_L("Error when adding argument2")); |
|
227 User::Leave(err); |
|
228 |
|
229 } |
|
230 CleanupStack::Pop(nearestCriteria); |
|
231 |
|
232 // Then add an IdList |
|
233 CPosLmIdListCriteria* idList = CPosLmIdListCriteria::NewLC(); |
|
234 RArray<TPosLmItemId> list; |
|
235 CleanupClosePushL(list); |
|
236 |
|
237 // Use these four landmarks |
|
238 list.Append(6); |
|
239 list.Append(7); |
|
240 list.Append(3); |
|
241 list.Append(10); |
|
242 |
|
243 idList->SetLandmarkIdsL(list); |
|
244 err = composite->AddArgument(idList); |
|
245 if (err != KErrNone) |
|
246 |
|
247 { |
|
248 iLog->Log(_L("Error when adding argument3")); |
|
249 User::Leave(err); |
|
250 |
|
251 } |
|
252 CleanupStack::PopAndDestroy(&list); |
|
253 CleanupStack::Pop(idList); |
|
254 |
|
255 // Create search result |
|
256 RArray<TPosLmItemId> searchResults; |
|
257 CleanupClosePushL(searchResults); |
|
258 // This is the correct distance sorted array |
|
259 searchResults.Append(3); |
|
260 searchResults.Append(7); |
|
261 searchResults.Append(6); |
|
262 searchResults.Append(10); |
|
263 |
|
264 iOperation = iLandmarkSearch->StartLandmarkSearchL(*composite, EFalse); |
|
265 ExecuteAndDeleteLD(iOperation); |
|
266 |
|
267 CPosLmItemIterator* iter = iLandmarkSearch->MatchIteratorL(); |
|
268 CleanupStack::PushL(iter); |
|
269 |
|
270 |
|
271 TInt ii=0; |
|
272 TPosLmItemId id = iter->NextL(); |
|
273 |
|
274 while (id != KPosLmNullItemId) |
|
275 { |
|
276 if (id != (searchResults)[ii]) |
|
277 { |
|
278 // Check if same name then don't leave, there are three landmarks with same name, Mölndal |
|
279 CPosLandmark* source = iDatabase->ReadLandmarkLC(id); |
|
280 CPosLandmark* target = iDatabase->ReadLandmarkLC((searchResults)[ii]); |
|
281 TPtrC sourceName, targetName; |
|
282 source->GetLandmarkName(sourceName); |
|
283 TInt sourceId = source->LandmarkId(); |
|
284 target->GetLandmarkName(targetName); |
|
285 TInt targetId = target->LandmarkId(); |
|
286 |
|
287 |
|
288 AssertTrueSecL(sourceName.CompareC(targetName) == KErrNone,_L("Wrong sortorder"), id); |
|
289 CleanupStack::PopAndDestroy(2, source); |
|
290 } |
|
291 |
|
292 id = iter->NextL(); |
|
293 ++ii; |
|
294 } |
|
295 CleanupStack::PopAndDestroy(iter); |
|
296 CleanupStack::PopAndDestroy(&searchResults); |
|
297 CleanupStack::PopAndDestroy(composite); |
|
298 |
|
299 delete iLandmarkSearch; |
|
300 iLandmarkSearch = NULL; |
|
301 } |
|
302 |
|
303 // --------------------------------------------------------- |
|
304 // CPosTp38::TestTwoLmCategoryCriteriaL |
|
305 // |
|
306 // (other items were commented in a header). |
|
307 // --------------------------------------------------------- |
|
308 // |
|
309 void CPosTp38::TestTwoLmCategoryCriteriaL() |
|
310 { |
|
311 iLog->Log(_L("TestTwoLmCategoryCriteriaL")); |
|
312 |
|
313 iLandmarkSearch = CPosLandmarkSearch::NewL(*iDatabase); |
|
314 CPosLmCompositeCriteria* composite = CPosLmCompositeCriteria::NewLC(CPosLmCompositeCriteria::ECompositionAND); |
|
315 |
|
316 // First create a textcriteria |
|
317 CPosLmTextCriteria* textCriteria = CPosLmTextCriteria::NewLC(); |
|
318 textCriteria->SetTextL(_L("*")); |
|
319 TInt err = composite->AddArgument(textCriteria); |
|
320 if (err != KErrNone) |
|
321 { |
|
322 iLog->Log(_L("Error when adding argument1")); |
|
323 User::Leave(err); |
|
324 } |
|
325 CleanupStack::Pop(textCriteria); |
|
326 |
|
327 // Create a cat search criteria |
|
328 CPosLmCategoryCriteria* catSearchCriteria = CPosLmCategoryCriteria::NewLC(); |
|
329 iLog->Log(_L("SetCategoryItemId")); |
|
330 catSearchCriteria->SetCategoryItemId(14); |
|
331 composite->AddArgument(catSearchCriteria); |
|
332 CleanupStack::Pop(catSearchCriteria); |
|
333 |
|
334 // Create another cat search criteria |
|
335 CPosLmCategoryCriteria* catSearchCriteria2 = CPosLmCategoryCriteria::NewLC(); |
|
336 iLog->Log(_L("SetCategoryNameL")); |
|
337 catSearchCriteria2->SetCategoryNameL(_L("McDonalds")); |
|
338 composite->AddArgument(catSearchCriteria2); |
|
339 CleanupStack::Pop(catSearchCriteria2); |
|
340 |
|
341 // Should find id7=Billigt and id27=LOG9 |
|
342 iOperation = iLandmarkSearch->StartLandmarkSearchL(*composite, EFalse); |
|
343 ExecuteAndDeleteLD(iOperation); |
|
344 |
|
345 // Create search result |
|
346 RArray<TPosLmItemId> searchResults; |
|
347 CleanupClosePushL(searchResults); |
|
348 |
|
349 CPosLmItemIterator* iter = iLandmarkSearch->MatchIteratorL(); |
|
350 CleanupStack::PushL(iter); |
|
351 |
|
352 // This is the correct result list |
|
353 searchResults.Append(27); |
|
354 searchResults.Append(7); |
|
355 |
|
356 TInt size = iter->NumOfItemsL(); |
|
357 if (size != searchResults.Count()) |
|
358 |
|
359 { |
|
360 iLog->Log(_L("Wrong result returned from iterator")); |
|
361 User::Leave(-1); |
|
362 |
|
363 } |
|
364 |
|
365 TInt found = 0; |
|
366 TInt ii=0; |
|
367 TPosLmItemId id = iter->NextL(); |
|
368 |
|
369 while (id != KPosLmNullItemId) |
|
370 { |
|
371 for (ii=0;ii<size;ii++) |
|
372 { |
|
373 if (id == (searchResults)[ii]) |
|
374 { |
|
375 found++; |
|
376 } |
|
377 } |
|
378 id = iter->NextL(); |
|
379 } |
|
380 |
|
381 if (found != searchResults.Count()) |
|
382 |
|
383 { |
|
384 iLog->Log(_L("Wrong result returned from iterator1")); |
|
385 User::Leave(-1); |
|
386 |
|
387 } |
|
388 |
|
389 // Now refine search with another CPosLmCategoryCriteria |
|
390 // Create another cat search criteria |
|
391 CPosLmCategoryCriteria* catSearchCriteria3 = CPosLmCategoryCriteria::NewLC(); |
|
392 iLog->Log(_L("SetCategoryItemId")); |
|
393 catSearchCriteria3->SetCategoryItemId(11); |
|
394 composite->AddArgument(catSearchCriteria3); |
|
395 CleanupStack::Pop(catSearchCriteria3); |
|
396 |
|
397 // Should find id27=LOG9 |
|
398 iOperation = iLandmarkSearch->StartLandmarkSearchL(*composite, ETrue); |
|
399 ExecuteAndDeleteLD(iOperation); |
|
400 |
|
401 iter->Reset(); |
|
402 CleanupStack::PopAndDestroy(iter); |
|
403 iter = iLandmarkSearch->MatchIteratorL(); |
|
404 CleanupStack::PushL(iter); |
|
405 |
|
406 searchResults.Reset(); |
|
407 searchResults.Append(27); |
|
408 found=0; |
|
409 size = iter->NumOfItemsL(); |
|
410 id = iter->NextL(); |
|
411 if (size != searchResults.Count()) |
|
412 |
|
413 { |
|
414 iLog->Log(_L("Wrong result returned from iterator")); |
|
415 User::Leave(-1); |
|
416 |
|
417 } |
|
418 |
|
419 while (id != KPosLmNullItemId) |
|
420 { |
|
421 for (ii=0;ii<size;ii++) |
|
422 { |
|
423 if (id == (searchResults)[ii]) |
|
424 { |
|
425 found++; |
|
426 } |
|
427 } |
|
428 id = iter->NextL(); |
|
429 } |
|
430 |
|
431 if (found != searchResults.Count()) |
|
432 |
|
433 { |
|
434 iLog->Log(_L("Wrong items returned from iterator2")); |
|
435 User::Leave(-1); |
|
436 } |
|
437 |
|
438 CleanupStack::PopAndDestroy(iter); |
|
439 CleanupStack::PopAndDestroy(&searchResults); |
|
440 CleanupStack::PopAndDestroy(composite); |
|
441 |
|
442 delete iLandmarkSearch; |
|
443 iLandmarkSearch = NULL; |
|
444 } |
|
445 |
|
446 // --------------------------------------------------------- |
|
447 // CPosTp38::TestWithSortOrderLandmarksL |
|
448 // |
|
449 // (other items were commented in a header). |
|
450 // --------------------------------------------------------- |
|
451 // |
|
452 void CPosTp38::TestWithSortOrderLandmarksL() |
|
453 { |
|
454 iLog->Log(_L("TestWithSortOrderLandmarksL")); |
|
455 |
|
456 iLandmarkSearch = CPosLandmarkSearch::NewL(*iDatabase); |
|
457 CPosLmCompositeCriteria* composite = CPosLmCompositeCriteria::NewLC(CPosLmCompositeCriteria::ECompositionAND); |
|
458 TInt i=0; |
|
459 TInt j=0; |
|
460 |
|
461 TPosLmSortPref sortPref(CPosLandmark::ELandmarkName, TPosLmSortPref::EAscending); |
|
462 |
|
463 // First create a textcriteria |
|
464 CPosLmTextCriteria* textCriteria = CPosLmTextCriteria::NewLC(); |
|
465 textCriteria->SetTextL(_L("*")); |
|
466 TInt err = composite->AddArgument(textCriteria); |
|
467 if (err != KErrNone) |
|
468 { |
|
469 iLog->Log(_L("Error when adding argument1")); |
|
470 User::Leave(err); |
|
471 } |
|
472 CleanupStack::Pop(textCriteria); |
|
473 |
|
474 // Then create a nearest criteria |
|
475 TCoordinate coord(12.123, -20,123); |
|
476 CPosLmNearestCriteria* nearestCriteria = CPosLmNearestCriteria::NewLC(coord, EFalse); |
|
477 err = composite->AddArgument(nearestCriteria); |
|
478 if (err != KErrNone) |
|
479 { |
|
480 iLog->Log(_L("Error when adding argument2")); |
|
481 User::Leave(err); |
|
482 } |
|
483 CleanupStack::Pop(nearestCriteria); |
|
484 |
|
485 // Then add an IdList |
|
486 CPosLmIdListCriteria* idList = CPosLmIdListCriteria::NewLC(); |
|
487 RArray<TPosLmItemId> list; |
|
488 CleanupClosePushL(list); |
|
489 for (i=1;i<106;i++) {list.Append(i);} |
|
490 idList->SetLandmarkIdsL(list); |
|
491 err = composite->AddArgument(idList); |
|
492 if (err != KErrNone) |
|
493 { |
|
494 iLog->Log(_L("Error when adding argument3")); |
|
495 User::Leave(err); |
|
496 } |
|
497 CleanupStack::PopAndDestroy(&list); |
|
498 CleanupStack::Pop(idList); |
|
499 |
|
500 // Create search result of all landmark ids: 1-105 |
|
501 RArray<TPosLmItemId> searchResults; |
|
502 CleanupClosePushL(searchResults); |
|
503 for (i=1;i<106;i++) {searchResults.Append(i);} |
|
504 |
|
505 for (j=0;j<2;j++) |
|
506 { |
|
507 if (j==0) |
|
508 { |
|
509 iLog->Log(_L("Sorting Ascending")); |
|
510 sortPref.SetSortByLandmarkAttribute(CPosLandmark::ELandmarkName, TPosLmSortPref::EAscending); |
|
511 } |
|
512 else |
|
513 { |
|
514 iLog->Log(_L("Sorting Descending")); |
|
515 sortPref.SetSortByLandmarkAttribute(CPosLandmark::ELandmarkName, TPosLmSortPref::EDescending); |
|
516 } |
|
517 |
|
518 iOperation = iLandmarkSearch->StartLandmarkSearchL(*composite, sortPref, EFalse); |
|
519 ExecuteAndDeleteLD(iOperation); |
|
520 |
|
521 CPosLmItemIterator* iter = iLandmarkSearch->MatchIteratorL(); |
|
522 CleanupStack::PushL(iter); |
|
523 |
|
524 TInt size = iter->NumOfItemsL(); |
|
525 |
|
526 LandmarksSortL(searchResults, sortPref); |
|
527 |
|
528 TInt ii=0; |
|
529 TPosLmItemId id = iter->NextL(); |
|
530 |
|
531 while (id != KPosLmNullItemId) |
|
532 { |
|
533 if (id != (searchResults)[ii]) |
|
534 { |
|
535 // Check if same name then don't leave, there are three landmarks with same name, Mölndal |
|
536 |
|
537 CPosLandmark* source = iDatabase->ReadLandmarkLC(id); |
|
538 CPosLandmark* target = iDatabase->ReadLandmarkLC((searchResults)[ii]); |
|
539 TPtrC sourceName, targetName; |
|
540 source->GetLandmarkName(sourceName); |
|
541 TInt sourceId = source->LandmarkId(); |
|
542 target->GetLandmarkName(targetName); |
|
543 TInt targetId = target->LandmarkId(); |
|
544 |
|
545 AssertTrueSecL(sourceName.CompareC(targetName) == KErrNone,_L("Wrong sortorder"), id); |
|
546 |
|
547 CleanupStack::PopAndDestroy(2, source); |
|
548 } |
|
549 |
|
550 id = iter->NextL(); |
|
551 ++ii; |
|
552 } |
|
553 CleanupStack::PopAndDestroy(iter); |
|
554 } |
|
555 |
|
556 CleanupStack::PopAndDestroy(&searchResults); |
|
557 CleanupStack::PopAndDestroy(composite); |
|
558 |
|
559 delete iLandmarkSearch; |
|
560 iLandmarkSearch = NULL; |
|
561 } |
|
562 |
|
563 // --------------------------------------------------------- |
|
564 // CPosTp38::TestCompositeInCompositeL |
|
565 // |
|
566 // (other items were commented in a header). |
|
567 // --------------------------------------------------------- |
|
568 // |
|
569 void CPosTp38::TestCompositeInCompositeL() |
|
570 { |
|
571 iLog->Log(_L("TestCompositeInCompositeL")); |
|
572 iLandmarkSearch = CPosLandmarkSearch::NewL(*iDatabase); |
|
573 CPosLmCompositeCriteria* composite = CPosLmCompositeCriteria::NewLC(CPosLmCompositeCriteria::ECompositionAND); |
|
574 |
|
575 // First create a textcriteria |
|
576 CPosLmTextCriteria* textCriteria = CPosLmTextCriteria::NewLC(); |
|
577 |
|
578 textCriteria->SetTextL(_L("*")); |
|
579 |
|
580 TInt err = composite->AddArgument(textCriteria); |
|
581 if (err != KErrNone) |
|
582 { |
|
583 iLog->Log(_L("Error when adding argument1")); |
|
584 User::Leave(err); |
|
585 } |
|
586 CleanupStack::Pop(textCriteria); |
|
587 |
|
588 CPosLmAreaCriteria* areaCriteria = CPosLmAreaCriteria::NewLC(-48, 5, -5, 20); |
|
589 |
|
590 err = composite->AddArgument(areaCriteria); |
|
591 if (err != KErrNone) |
|
592 { |
|
593 iLog->Log(_L("Error when adding argument2")); |
|
594 User::Leave(err); |
|
595 } |
|
596 CleanupStack::Pop(areaCriteria); |
|
597 |
|
598 //Create composite object that should be used as argument to the first composite object |
|
599 CPosLmCompositeCriteria* composite2 = CPosLmCompositeCriteria::NewLC(CPosLmCompositeCriteria::ECompositionAND); |
|
600 |
|
601 CPosLmTextCriteria* textCriteria2 = CPosLmTextCriteria::NewLC(); |
|
602 |
|
603 textCriteria2->SetTextL(_L("TE,*")); |
|
604 |
|
605 err = composite2->AddArgument(textCriteria2); |
|
606 if (err != KErrNone) |
|
607 { |
|
608 iLog->Log(_L("Error when adding argument3")); |
|
609 User::Leave(err); |
|
610 } |
|
611 CleanupStack::Pop(textCriteria2); |
|
612 |
|
613 // Add a IdList |
|
614 RArray<TPosLmItemId> list; |
|
615 CleanupClosePushL(list); |
|
616 |
|
617 CPosLmIdListCriteria* idList = CPosLmIdListCriteria::NewLC(); |
|
618 |
|
619 for (TInt i=0;i<100;i++) |
|
620 { |
|
621 list.Append(i); |
|
622 } |
|
623 idList->SetLandmarkIdsL(list); |
|
624 |
|
625 err = composite2->AddArgument(idList); |
|
626 if (err != KErrNone) |
|
627 { |
|
628 iLog->Log(_L("Error when adding argument4")); |
|
629 User::Leave(err); |
|
630 } |
|
631 CleanupStack::Pop(idList); |
|
632 CleanupStack::PopAndDestroy(&list); |
|
633 |
|
634 // Nested composite is not allowed |
|
635 err = composite->AddArgument(composite2); |
|
636 if (err != KErrNotSupported) |
|
637 { |
|
638 iLog->Log(_L("Wrong error code when adding composite to a composite")); |
|
639 User::Leave(err); |
|
640 } |
|
641 CleanupStack::PopAndDestroy(composite2); |
|
642 |
|
643 CleanupStack::PopAndDestroy(composite); |
|
644 |
|
645 delete iLandmarkSearch; |
|
646 iLandmarkSearch = NULL; |
|
647 iLog->Log(_L("Done")); |
|
648 } |
|
649 |
|
650 // --------------------------------------------------------- |
|
651 // CPosTp38::StartLandmarksCompositeTestL |
|
652 // |
|
653 // (other items were commented in a header). |
|
654 // --------------------------------------------------------- |
|
655 // |
|
656 void CPosTp38::StartLandmarksCompositeTestL() |
|
657 { |
|
658 iLog->Log(_L("StartTestL")); |
|
659 iLandmarkSearch = CPosLandmarkSearch::NewL(*iDatabase); |
|
660 CPosLmCompositeCriteria* composite = CPosLmCompositeCriteria::NewLC(CPosLmCompositeCriteria::ECompositionAND); |
|
661 |
|
662 CCompositeSearchResult* res = CCompositeSearchResult::NewL(iLog); |
|
663 CleanupStack::PushL(res); |
|
664 |
|
665 TInt index=0; |
|
666 TInt errorsFound = KErrNone; |
|
667 |
|
668 TBuf<100> buf; |
|
669 buf.Format(_L(">>>>>>>Test round %d <<<<<<<"), index); |
|
670 |
|
671 while (!res->GetCompositeSearchResultsL(*composite)) |
|
672 { |
|
673 PrintCompositeInfo(composite); |
|
674 |
|
675 iLog->Log(_L("iLandmarkSearch->StartLandmarkSearchL")); |
|
676 iOperation = iLandmarkSearch->StartLandmarkSearchL(*composite, res->Redefined()); |
|
677 ExecuteAndDeleteLD(iOperation); |
|
678 |
|
679 CPosLmItemIterator* iter = iLandmarkSearch->MatchIteratorL(); |
|
680 CleanupStack::PushL(iter); |
|
681 TPosLmItemId id = iter->NextL(); |
|
682 |
|
683 TInt matches = iLandmarkSearch->NumOfMatches(); |
|
684 TInt expMatches = res->iResultIds.Count(); |
|
685 |
|
686 buf.Format(_L("nr of matches: %d nr of exp matches: %d"), matches, expMatches); |
|
687 iLog->Log(buf); |
|
688 |
|
689 while (id != KPosLmNullItemId) |
|
690 { |
|
691 buf.Format(_L("Result from iterator id: %d"), id); |
|
692 iLog->Log(buf); |
|
693 TInt idde = res->iResultIds.Find(id); |
|
694 if (idde == KErrNotFound) |
|
695 { |
|
696 iLog->Log(_L("MyError: Could not find id!!!")); |
|
697 errorsFound++; |
|
698 } |
|
699 else |
|
700 { |
|
701 // Remove so that we dont find the same id again |
|
702 res->iResultIds.Remove(idde); |
|
703 } |
|
704 id = iter->NextL(); |
|
705 } |
|
706 |
|
707 iter->Reset(); |
|
708 CleanupStack::PopAndDestroy(iter); |
|
709 |
|
710 if (expMatches != matches) |
|
711 { |
|
712 iLog->Log(_L("MyError: Wrong number of matches")); |
|
713 errorsFound++; |
|
714 } |
|
715 } |
|
716 |
|
717 if (errorsFound != KErrNone) |
|
718 { |
|
719 iLog->Log(_L("Errors found in TP38")); |
|
720 User::Leave(-1); |
|
721 |
|
722 } |
|
723 iLog->Log(_L("----Done---")); |
|
724 |
|
725 delete iLandmarkSearch; |
|
726 iLandmarkSearch = NULL; |
|
727 |
|
728 CleanupStack::PopAndDestroy(res); |
|
729 CleanupStack::PopAndDestroy(composite); |
|
730 } |
|
731 |
|
732 |
|
733 // --------------------------------------------------------- |
|
734 // CPosTp38::TestSeveralTextArgumentsL |
|
735 // |
|
736 // (other items were commented in a header). |
|
737 // --------------------------------------------------------- |
|
738 // |
|
739 void CPosTp38::TestSeveralTextArgumentsL() |
|
740 { |
|
741 iLog->Log(_L("TestSeveralTextArgumentsL")); |
|
742 |
|
743 iLandmarkSearch = CPosLandmarkSearch::NewL(*iDatabase); |
|
744 CPosLmCompositeCriteria* composite = CPosLmCompositeCriteria::NewLC(CPosLmCompositeCriteria::ECompositionAND); |
|
745 |
|
746 // First create a textcriteria |
|
747 CPosLmTextCriteria* textCriteria = CPosLmTextCriteria::NewLC(); |
|
748 textCriteria->SetTextL(_L("Nokia*")); |
|
749 TInt err = composite->AddArgument(textCriteria); |
|
750 if (err != KErrNone) |
|
751 { |
|
752 iLog->Log(_L("Error when adding argument1")); |
|
753 User::Leave(err); |
|
754 } |
|
755 CleanupStack::Pop(textCriteria); |
|
756 |
|
757 // First create a textcriteria |
|
758 CPosLmTextCriteria* textCriteria2 = CPosLmTextCriteria::NewLC(); |
|
759 textCriteria2->SetTextL(_L("*Stockholm")); |
|
760 err = composite->AddArgument(textCriteria2); |
|
761 if (err != KErrNone) |
|
762 { |
|
763 iLog->Log(_L("Error when adding argument2")); |
|
764 User::Leave(err); |
|
765 } |
|
766 CleanupStack::Pop(textCriteria2); |
|
767 |
|
768 // Should find landmark id: 63 name: "Nokia, Stockholm" |
|
769 iLog->Log(_L("iLandmarkSearch->StartLandmarkSearchL")); |
|
770 iOperation = iLandmarkSearch->StartLandmarkSearchL(*composite, EFalse); |
|
771 ExecuteAndDeleteLD(iOperation); |
|
772 |
|
773 CPosLmItemIterator* iter = iLandmarkSearch->MatchIteratorL(); |
|
774 CleanupStack::PushL(iter); |
|
775 TPosLmItemId id = iter->NextL(); |
|
776 |
|
777 TInt matches = iLandmarkSearch->NumOfMatches(); |
|
778 if (matches != 1) |
|
779 { |
|
780 iLog->Log(_L("Wrong number of matches")); |
|
781 User::Leave(-1); |
|
782 } |
|
783 |
|
784 if (id != 63) |
|
785 { |
|
786 |
|
787 iLog->Log(_L("Wrong landmark found, should find landmark with id 63")); |
|
788 User::Leave(-1); |
|
789 } |
|
790 |
|
791 iter->Reset(); |
|
792 CleanupStack::PopAndDestroy(iter); |
|
793 |
|
794 CleanupStack::PopAndDestroy(composite); |
|
795 |
|
796 delete iLandmarkSearch; |
|
797 iLandmarkSearch = NULL; |
|
798 } |
|
799 |
|
800 // --------------------------------------------------------- |
|
801 // CPosTp38::TestSeveralTextArgumentsWithORL |
|
802 // |
|
803 // (other items were commented in a header). |
|
804 // --------------------------------------------------------- |
|
805 // |
|
806 void CPosTp38::TestSeveralTextArgumentsWithORL() |
|
807 { |
|
808 iLog->Log(_L("TestSeveralTextArgumentsWithORL")); |
|
809 |
|
810 iLandmarkSearch = CPosLandmarkSearch::NewL(*iDatabase); |
|
811 CPosLmCompositeCriteria* composite = CPosLmCompositeCriteria::NewLC(CPosLmCompositeCriteria::ECompositionOR); |
|
812 |
|
813 // First create a textcriteria |
|
814 CPosLmTextCriteria* textCriteria = CPosLmTextCriteria::NewLC(); |
|
815 textCriteria->SetTextL(_L("Nokia*")); |
|
816 textCriteria->SetAttributesToSearch(CPosLandmark::ELandmarkName); |
|
817 TInt err = composite->AddArgument(textCriteria); |
|
818 if (err != KErrNone) |
|
819 { |
|
820 iLog->Log(_L("Error when adding argument1")); |
|
821 User::Leave(err); |
|
822 } |
|
823 CleanupStack::Pop(textCriteria); |
|
824 |
|
825 // First create a textcriteria |
|
826 CPosLmTextCriteria* textCriteria2 = CPosLmTextCriteria::NewLC(); |
|
827 textCriteria2->SetTextL(_L("*Eriksberg")); |
|
828 textCriteria2->SetAttributesToSearch(CPosLandmark::ELandmarkName); |
|
829 err = composite->AddArgument(textCriteria2); |
|
830 if (err != KErrNone) |
|
831 { |
|
832 iLog->Log(_L("Error when adding argument2")); |
|
833 User::Leave(err); |
|
834 } |
|
835 CleanupStack::Pop(textCriteria2); |
|
836 |
|
837 //Create nearest criteria instance and try adding it to composite criteria,should leave with KErrNotSupported since ORcomposition |
|
838 // is supported only for text criteria |
|
839 TCoordinate coord(45, 45); |
|
840 CPosLmNearestCriteria* nearestCriteria = CPosLmNearestCriteria::NewLC(coord, EFalse); |
|
841 err = composite->AddArgument(nearestCriteria); |
|
842 if (err != KErrNotSupported) |
|
843 |
|
844 { |
|
845 iLog->Log(_L("Error,should not support any other criteria except Text criteria")); |
|
846 User::Leave(err); |
|
847 |
|
848 } |
|
849 CleanupStack::Pop(nearestCriteria); |
|
850 |
|
851 |
|
852 |
|
853 |
|
854 |
|
855 // Should find landmark ids 48,55,62 & 63 with name:"Nokia","TE Eriksberg","Nokia Copenhagen" "Nokia, Stockholm" |
|
856 iLog->Log(_L("iLandmarkSearch->StartLandmarkSearchL")); |
|
857 iOperation = iLandmarkSearch->StartLandmarkSearchL(*composite, EFalse); |
|
858 ExecuteAndDeleteLD(iOperation); |
|
859 |
|
860 CPosLmItemIterator* iter = iLandmarkSearch->MatchIteratorL(); |
|
861 CleanupStack::PushL(iter); |
|
862 |
|
863 RArray<TPosLmItemId> idArray; |
|
864 iter->GetItemIdsL(idArray, 0, iter->NumOfItemsL()); |
|
865 |
|
866 |
|
867 TInt matches = iLandmarkSearch->NumOfMatches(); |
|
868 if (matches != 4) |
|
869 { |
|
870 iLog->Log(_L("Wrong number of matches")); |
|
871 User::Leave(-1); |
|
872 } |
|
873 |
|
874 for(int i=0; i<idArray.Count(); i++ ) |
|
875 { |
|
876 if(idArray[i] != 48 && idArray[i] != 55 && idArray[i] != 62 && idArray[i] != 63) |
|
877 { |
|
878 iLog->Log(_L("Wrong landmark found, should find landmark with id 48, 55, 62 & 63")); |
|
879 User::Leave(-1); |
|
880 } |
|
881 } |
|
882 |
|
883 iter->Reset(); |
|
884 CleanupStack::PopAndDestroy(iter); |
|
885 CleanupStack::PopAndDestroy(composite); |
|
886 delete iLandmarkSearch; |
|
887 iLandmarkSearch = NULL; |
|
888 } |
|
889 |
|
890 |
|
891 // --------------------------------------------------------- |
|
892 // CPosTp38::TestSortOrderWithORL |
|
893 // |
|
894 // (other items were commented in a header). |
|
895 // --------------------------------------------------------- |
|
896 // |
|
897 void CPosTp38::TestSortOrderWithORL() |
|
898 { |
|
899 |
|
900 |
|
901 |
|
902 iLog->Log(_L("TestSeveralTextArgumentsWithORL")); |
|
903 |
|
904 iLandmarkSearch = CPosLandmarkSearch::NewL(*iDatabase); |
|
905 CPosLmCompositeCriteria* composite = CPosLmCompositeCriteria::NewLC(CPosLmCompositeCriteria::ECompositionOR); |
|
906 |
|
907 TPosLmSortPref sortPref(CPosLandmark::ELandmarkName, TPosLmSortPref::EAscending); |
|
908 |
|
909 // First create a textcriteria |
|
910 CPosLmTextCriteria* textCriteria = CPosLmTextCriteria::NewLC(); |
|
911 textCriteria->SetTextL(_L("Nokia*")); |
|
912 textCriteria->SetAttributesToSearch(CPosLandmark::ELandmarkName); |
|
913 TInt err = composite->AddArgument(textCriteria); |
|
914 if (err != KErrNone) |
|
915 { |
|
916 iLog->Log(_L("Error when adding argument1")); |
|
917 User::Leave(err); |
|
918 } |
|
919 CleanupStack::Pop(textCriteria); |
|
920 |
|
921 // First create a textcriteria |
|
922 CPosLmTextCriteria* textCriteria2 = CPosLmTextCriteria::NewLC(); |
|
923 textCriteria2->SetTextL(_L("*Eriksberg")); |
|
924 textCriteria2->SetAttributesToSearch(CPosLandmark::ELandmarkName); |
|
925 err = composite->AddArgument(textCriteria2); |
|
926 if (err != KErrNone) |
|
927 { |
|
928 iLog->Log(_L("Error when adding argument2")); |
|
929 User::Leave(err); |
|
930 } |
|
931 CleanupStack::Pop(textCriteria2); |
|
932 |
|
933 // Should find landmark ids 48,55,62 & 63 with name:"Nokia","TE Eriksberg","Nokia Copenhagen" "Nokia, Stockholm" |
|
934 iLog->Log(_L("iLandmarkSearch->StartLandmarkSearchL")); |
|
935 iOperation = iLandmarkSearch->StartLandmarkSearchL(*composite,sortPref, EFalse); |
|
936 ExecuteAndDeleteLD(iOperation); |
|
937 |
|
938 CPosLmItemIterator* iter = iLandmarkSearch->MatchIteratorL(); |
|
939 CleanupStack::PushL(iter); |
|
940 |
|
941 RArray<TPosLmItemId> idArray; |
|
942 iter->GetItemIdsL(idArray, 0, iter->NumOfItemsL()); |
|
943 |
|
944 |
|
945 TInt matches = iLandmarkSearch->NumOfMatches(); |
|
946 if (matches != 4) |
|
947 { |
|
948 iLog->Log(_L("Wrong number of matches")); |
|
949 User::Leave(-1); |
|
950 } |
|
951 |
|
952 //Check if the landmarks are in ascending order i.e "Nokia","Nokia Copenhagen","Nokia Stockholm","TE Eriksberg" |
|
953 |
|
954 |
|
955 if(idArray[0] != 48 || idArray[1] != 62 || idArray[2] != 63 || idArray[3] != 55) |
|
956 { |
|
957 iLog->Log(_L("Wrong landmark found, should find landmark with id 48, 55, 62 & 63")); |
|
958 User::Leave(-1); |
|
959 } |
|
960 |
|
961 |
|
962 iter->Reset(); |
|
963 CleanupStack::PopAndDestroy(iter); |
|
964 CleanupStack::PopAndDestroy(composite); |
|
965 delete iLandmarkSearch; |
|
966 iLandmarkSearch = NULL; |
|
967 } |
|
968 |
|
969 // --------------------------------------------------------- |
|
970 // CPosTp38::TestCategoryCompositeSearchL |
|
971 // |
|
972 // (other items were commented in a header). |
|
973 // --------------------------------------------------------- |
|
974 // |
|
975 void CPosTp38::TestCategoryCompositeSearchL() |
|
976 { |
|
977 iLog->Log(_L("TestCategoryCompositeSearchL")); |
|
978 |
|
979 iLandmarkSearch = CPosLandmarkSearch::NewL(*iDatabase); |
|
980 CPosLmCompositeCriteria* composite = CPosLmCompositeCriteria::NewLC(CPosLmCompositeCriteria::ECompositionAND); |
|
981 |
|
982 // Use differen text pattern |
|
983 CPosLmCatNameCriteria* nameCriteria = CPosLmCatNameCriteria::NewLC(); |
|
984 nameCriteria->SetSearchPatternL(_L("*")); |
|
985 TInt err = composite->AddArgument(nameCriteria); |
|
986 if (err != KErrNone) |
|
987 { |
|
988 iLog->Log(_L("Error from AddArgument(nameCriteria);")); |
|
989 User::Leave(err); |
|
990 } |
|
991 CleanupStack::Pop(nameCriteria); |
|
992 |
|
993 CPosLmCatNameCriteria* nameCriteria2 = CPosLmCatNameCriteria::NewLC(); |
|
994 nameCriteria2->SetSearchPatternL(_L("*kontor")); |
|
995 err = composite->AddArgument(nameCriteria2); |
|
996 if (err != KErrNone) |
|
997 { |
|
998 iLog->Log(_L("Error from AddArgument(nameCriteria);")); |
|
999 User::Leave(err); |
|
1000 } |
|
1001 CleanupStack::Pop(nameCriteria2); |
|
1002 |
|
1003 // Should find category id: 13 name "Nokia Kontor" and id: 14 name: "TietoEnator kontor" |
|
1004 iLog->Log(_L("iLandmarkSearch->StartCategorySearchL")); |
|
1005 iOperation = iLandmarkSearch->StartCategorySearchL(*composite, CPosLmCategoryManager::ECategorySortOrderNone); |
|
1006 |
|
1007 ExecuteAndDeleteLD(iOperation); |
|
1008 |
|
1009 CPosLmItemIterator* iter = iLandmarkSearch->MatchIteratorL(); |
|
1010 CleanupStack::PushL(iter); |
|
1011 |
|
1012 TInt matches = iLandmarkSearch->NumOfMatches(); |
|
1013 if (matches != 2) |
|
1014 { |
|
1015 iLog->Log(_L("Wrong number of matches")); |
|
1016 User::Leave(-1); |
|
1017 } |
|
1018 else iLog->Log(_L("Found 2 nr of matches")); |
|
1019 |
|
1020 TPosLmItemId id1 = iter->NextL(); |
|
1021 TPosLmItemId id2 = iter->NextL(); |
|
1022 |
|
1023 if ((id1 == 13 && id2 != 14) || (id1 == 14 && id2 != 13) |
|
1024 || (id2 == 13 && id1 != 14) || (id2 == 14 && id1 != 13)) |
|
1025 { |
|
1026 iLog->Log(_L("Wrong landmark found")); |
|
1027 User::Leave(-1); |
|
1028 } |
|
1029 |
|
1030 iter->Reset(); |
|
1031 CleanupStack::PopAndDestroy(iter); |
|
1032 |
|
1033 // Use same text pattern |
|
1034 nameCriteria = CPosLmCatNameCriteria::NewLC(); |
|
1035 nameCriteria->SetSearchPatternL(_L("TietoEnator*")); |
|
1036 err = composite->AddArgument(nameCriteria); |
|
1037 if (err != KErrNone) |
|
1038 { |
|
1039 |
|
1040 iLog->Log(_L("Error from AddArgument(nameCriteria);")); |
|
1041 User::Leave(err); |
|
1042 } |
|
1043 CleanupStack::Pop(nameCriteria); |
|
1044 |
|
1045 nameCriteria2 = CPosLmCatNameCriteria::NewLC(); |
|
1046 nameCriteria2->SetSearchPatternL(_L("TietoEnator*")); |
|
1047 err = composite->AddArgument(nameCriteria2); |
|
1048 if (err != KErrNone) |
|
1049 { |
|
1050 iLog->Log(_L("Error from AddArgument(nameCriteria);")); |
|
1051 User::Leave(err); |
|
1052 |
|
1053 } |
|
1054 CleanupStack::Pop(nameCriteria2); |
|
1055 |
|
1056 // Should find category id: 14 name "TietoEnator Kontor" |
|
1057 iLog->Log(_L("iLandmarkSearch->StartCategorySearchL")); |
|
1058 iOperation = iLandmarkSearch->StartCategorySearchL(*composite, CPosLmCategoryManager::ECategorySortOrderNone); |
|
1059 |
|
1060 ExecuteAndDeleteLD(iOperation); |
|
1061 iter = iLandmarkSearch->MatchIteratorL(); |
|
1062 CleanupStack::PushL(iter); |
|
1063 |
|
1064 matches = iLandmarkSearch->NumOfMatches(); |
|
1065 if (matches != 1) |
|
1066 { |
|
1067 iLog->Log(_L("Wrong number of matches")); |
|
1068 User::Leave(-1); |
|
1069 |
|
1070 } |
|
1071 else iLog->Log(_L("Found 1 nr of matches")); |
|
1072 |
|
1073 id1 = iter->NextL(); |
|
1074 |
|
1075 if (id1 != 14) |
|
1076 { |
|
1077 iLog->Log(_L("Wrong landmark found")); |
|
1078 User::Leave(-1); |
|
1079 } |
|
1080 |
|
1081 iter->Reset(); |
|
1082 CleanupStack::PopAndDestroy(iter); |
|
1083 CleanupStack::PopAndDestroy(composite); |
|
1084 |
|
1085 delete iLandmarkSearch; |
|
1086 iLandmarkSearch = NULL; |
|
1087 |
|
1088 iLog->Log(_L("Done")); |
|
1089 } |
|
1090 |
|
1091 // --------------------------------------------------------- |
|
1092 // CPosTp38::TestAddAndRemoveL |
|
1093 // |
|
1094 // (other items were commented in a header). |
|
1095 // --------------------------------------------------------- |
|
1096 // |
|
1097 void CPosTp38::TestAddAndRemoveL() |
|
1098 { |
|
1099 iLog->Log(_L("TestAddAndRemoveL")); |
|
1100 |
|
1101 iLandmarkSearch = CPosLandmarkSearch::NewL(*iDatabase); |
|
1102 CPosLmCompositeCriteria* composite = CPosLmCompositeCriteria::NewLC(CPosLmCompositeCriteria::ECompositionAND); |
|
1103 |
|
1104 // 1) Add a text criteria |
|
1105 CPosLmTextCriteria* textCriteria = CPosLmTextCriteria::NewLC(); |
|
1106 textCriteria->SetTextL(_L("*")); |
|
1107 TInt err = composite->AddArgument(textCriteria); |
|
1108 if (err != KErrNone) |
|
1109 { |
|
1110 iLog->Log(_L("Error when adding argument1")); |
|
1111 User::Leave(err); |
|
1112 |
|
1113 } |
|
1114 CleanupStack::Pop(textCriteria); |
|
1115 |
|
1116 // 2) Add a text criteria |
|
1117 textCriteria = CPosLmTextCriteria::NewLC(); |
|
1118 textCriteria->SetTextL(_L("Natur*")); |
|
1119 err = composite->AddArgument(textCriteria); |
|
1120 if (err != KErrNone) |
|
1121 { |
|
1122 iLog->Log(_L("Error when adding argument2")); |
|
1123 User::Leave(err); |
|
1124 |
|
1125 } |
|
1126 CleanupStack::Pop(textCriteria); |
|
1127 |
|
1128 // 3) Add an area criteria |
|
1129 CPosLmAreaCriteria* areaCriteria = CPosLmAreaCriteria::NewLC(-12.23, 34.4, -2.05, 45.5); |
|
1130 err = composite->AddArgument(areaCriteria); |
|
1131 if (err != KErrNone) |
|
1132 { |
|
1133 iLog->Log(_L("Error when adding argument3")); |
|
1134 User::Leave(err); |
|
1135 |
|
1136 } |
|
1137 CleanupStack::Pop(areaCriteria); |
|
1138 |
|
1139 // 4) Add a category criteria |
|
1140 CPosLmCategoryCriteria* catCriteria = CPosLmCategoryCriteria::NewLC(); |
|
1141 catCriteria->SetCategoryNameL(_L("Museum")); |
|
1142 err = composite->AddArgument(catCriteria); |
|
1143 if (err != KErrNone) |
|
1144 { |
|
1145 iLog->Log(_L("Error when adding argument3")); |
|
1146 User::Leave(err); |
|
1147 |
|
1148 } |
|
1149 CleanupStack::Pop(catCriteria); |
|
1150 |
|
1151 // 5) Add a nearest criteria |
|
1152 TCoordinate cord(12.23, 12); |
|
1153 CPosLmNearestCriteria* nearestCriteria = CPosLmNearestCriteria::NewLC(cord, ETrue); |
|
1154 err = composite->AddArgument(nearestCriteria); |
|
1155 if (err != KErrNone) |
|
1156 { |
|
1157 iLog->Log(_L("Error when adding argument3")); |
|
1158 User::Leave(err); |
|
1159 |
|
1160 } |
|
1161 CleanupStack::Pop(nearestCriteria); |
|
1162 |
|
1163 if (composite->NumOfArguments() != 5) |
|
1164 { |
|
1165 iLog->Log(_L("Error when adding argument1")); |
|
1166 User::Leave(-1); |
|
1167 |
|
1168 } |
|
1169 |
|
1170 // Remove (3) area criteria |
|
1171 CPosLmSearchCriteria* obj1 = composite->RemoveArgument(2); |
|
1172 delete obj1; |
|
1173 obj1 = NULL; |
|
1174 |
|
1175 // Remove (5) nearest criteria (after 3 removed it has id 4) |
|
1176 CPosLmSearchCriteria* obj2 = composite->RemoveArgument(3); |
|
1177 delete obj2; |
|
1178 obj2 = NULL; |
|
1179 |
|
1180 // Should find landmark with id: 87 name: "Naturhistoriska" |
|
1181 iOperation = iLandmarkSearch->StartLandmarkSearchL(*composite); |
|
1182 ExecuteAndDeleteLD(iOperation); |
|
1183 |
|
1184 CPosLmItemIterator* iter = iLandmarkSearch->MatchIteratorL(); |
|
1185 CleanupStack::PushL(iter); |
|
1186 |
|
1187 TInt nr = iter->NumOfItemsL(); |
|
1188 TBuf<100> buf; |
|
1189 buf.Format(_L("Found %d nr of landmarks after removing two arguments "), nr); |
|
1190 iLog->Log(buf); |
|
1191 |
|
1192 TPosLmItemId id = iter->NextL(); |
|
1193 if (id != 87) |
|
1194 { |
|
1195 iLog->Log(_L("Wrong landmark found")); |
|
1196 User::Leave(-1); |
|
1197 |
|
1198 } |
|
1199 iter->Reset(); |
|
1200 |
|
1201 // Remove (1) first text criteria |
|
1202 CPosLmSearchCriteria* obj4 = composite->RemoveArgument(0); |
|
1203 delete obj4; |
|
1204 obj4 = NULL; |
|
1205 |
|
1206 // Remove (2) the second text criteria |
|
1207 CPosLmSearchCriteria* obj3 = composite->RemoveArgument(0); |
|
1208 delete obj3; |
|
1209 obj3 = NULL; |
|
1210 |
|
1211 CleanupStack::PopAndDestroy(iter); |
|
1212 |
|
1213 // Should find six landmarks belonging to category "museum", |
|
1214 iOperation = iLandmarkSearch->StartLandmarkSearchL(*composite); |
|
1215 ExecuteAndDeleteLD(iOperation); |
|
1216 |
|
1217 iter = iLandmarkSearch->MatchIteratorL(); |
|
1218 CleanupStack::PushL(iter); |
|
1219 |
|
1220 nr = iter->NumOfItemsL(); |
|
1221 if (nr != 6) |
|
1222 { |
|
1223 iLog->Log(_L("Wrong number of landmarks returned")); |
|
1224 User::Leave(-1); |
|
1225 } |
|
1226 buf.Format(_L("Found %d nr of landmarks after removing two more arguments"), nr); |
|
1227 iLog->Log(buf); |
|
1228 |
|
1229 iter->Reset(); |
|
1230 |
|
1231 CleanupStack::PopAndDestroy(iter); |
|
1232 CleanupStack::PopAndDestroy(composite); |
|
1233 |
|
1234 delete iLandmarkSearch; |
|
1235 iLandmarkSearch = NULL; |
|
1236 |
|
1237 iLog->Log(_L("Done")); |
|
1238 } |
|
1239 |
|
1240 // --------------------------------------------------------- |
|
1241 // CPosTp38::SearchAndCancelL |
|
1242 // |
|
1243 // (other items were commented in a header). |
|
1244 // --------------------------------------------------------- |
|
1245 // |
|
1246 void CPosTp38::SearchAndCancelL(const TBool& aInCallback) |
|
1247 { |
|
1248 iLog->Log(_L("SearchAndCancelL")); |
|
1249 |
|
1250 iLandmarkSearch = CPosLandmarkSearch::NewL(*iDatabase); |
|
1251 |
|
1252 CPosLmCompositeCriteria* composite = CPosLmCompositeCriteria::NewLC(CPosLmCompositeCriteria::ECompositionAND); |
|
1253 CPosLmTextCriteria* textCriteria = CPosLmTextCriteria::NewLC(); |
|
1254 textCriteria->SetTextL(_L("*")); |
|
1255 |
|
1256 TInt err = composite->AddArgument(textCriteria); |
|
1257 if (err != KErrNone) |
|
1258 { |
|
1259 iLog->Log(_L("Error when adding argument3")); |
|
1260 User::Leave(err); |
|
1261 } |
|
1262 CleanupStack::Pop(textCriteria); |
|
1263 |
|
1264 if (aInCallback) |
|
1265 { |
|
1266 RunAsyncOperationAndCancelInCallbackLD(iLandmarkSearch->StartLandmarkSearchL( |
|
1267 *composite, EFalse)); |
|
1268 } |
|
1269 else |
|
1270 { |
|
1271 RunAsyncOperationAndCancelLD(iLandmarkSearch->StartLandmarkSearchL( |
|
1272 *composite, EFalse)); |
|
1273 } |
|
1274 |
|
1275 CPosLmItemIterator* iter = iLandmarkSearch->MatchIteratorL(); |
|
1276 CleanupStack::PushL(iter); |
|
1277 |
|
1278 if (aInCallback) |
|
1279 { |
|
1280 _LIT(KExpected, "Iter. of matches: %d"); |
|
1281 _LIT(KReturned, "LandmarksSearch no. of matches: %d"); |
|
1282 TBuf<100> info; |
|
1283 info.Format(KExpected, iter->NumOfItemsL()); |
|
1284 iLog->Log(info); |
|
1285 info.Format(KReturned, iLandmarkSearch->NumOfMatches()); |
|
1286 iLog->Log(info); |
|
1287 |
|
1288 TBuf<100> info2; |
|
1289 _LIT(KNof, "No. of matches found before cancel = %d"); |
|
1290 info2.Format(KNof, iter->NumOfItemsL()); |
|
1291 iLog->Log(info2); |
|
1292 |
|
1293 |
|
1294 } |
|
1295 CleanupStack::PopAndDestroy(iter); |
|
1296 CleanupStack::PopAndDestroy(composite); |
|
1297 |
|
1298 delete iLandmarkSearch; |
|
1299 iLandmarkSearch = NULL; |
|
1300 } |
|
1301 |
|
1302 // --------------------------------------------------------- |
|
1303 // CPosTp38::TestWithNoPreviousResultL |
|
1304 // |
|
1305 // (other items were commented in a header). |
|
1306 // --------------------------------------------------------- |
|
1307 // |
|
1308 void CPosTp38::TestWithNoPreviousResultL(TInt aTestNr) |
|
1309 { |
|
1310 iLog->Log(_L("TestWithNoPreviousResultL")); |
|
1311 iLandmarkSearch = CPosLandmarkSearch::NewL(*iDatabase); |
|
1312 |
|
1313 CPosLmCompositeCriteria* composite = CPosLmCompositeCriteria::NewLC(CPosLmCompositeCriteria::ECompositionAND); |
|
1314 |
|
1315 if (aTestNr == 0) |
|
1316 { |
|
1317 CPosLmTextCriteria* textCriteria = CPosLmTextCriteria::NewLC(); |
|
1318 textCriteria->SetTextL(_L("*")); |
|
1319 |
|
1320 TInt err = composite->AddArgument(textCriteria); |
|
1321 if (err != KErrNone) |
|
1322 { |
|
1323 iLog->Log(_L("Error from AddArgument(textCriteria);")); |
|
1324 User::Leave(err); |
|
1325 } |
|
1326 CleanupStack::Pop(textCriteria); |
|
1327 |
|
1328 iOperation = iLandmarkSearch->StartLandmarkSearchL(*composite, ETrue); |
|
1329 ExecuteAndDeleteLD(iOperation); |
|
1330 iLog->Log(_L("ERROR: Should leave here")); |
|
1331 |
|
1332 iLog->Log(_L("Should never come here in the code")); |
|
1333 User::Leave(-1); |
|
1334 |
|
1335 } |
|
1336 else if (aTestNr == 1) |
|
1337 { |
|
1338 |
|
1339 CPosLmCatNameCriteria* nameCriteria = CPosLmCatNameCriteria::NewLC(); |
|
1340 nameCriteria->SetSearchPatternL(_L("*kontor")); |
|
1341 TInt err = composite->AddArgument(nameCriteria); |
|
1342 if (err != KErrNone) |
|
1343 { |
|
1344 iLog->Log(_L("Error from AddArgument(nameCriteria);")); |
|
1345 User::Leave(err); |
|
1346 } |
|
1347 CleanupStack::Pop(nameCriteria); |
|
1348 |
|
1349 iOperation = iLandmarkSearch->StartCategorySearchL(*composite, CPosLmCategoryManager::ECategorySortOrderNone, ETrue); |
|
1350 ExecuteAndDeleteLD(iOperation); |
|
1351 iLog->Log(_L("ERROR: Should leave here")); |
|
1352 |
|
1353 iLog->Log(_L("Should never come here in the code")); |
|
1354 User::Leave(-1); |
|
1355 |
|
1356 } |
|
1357 |
|
1358 delete iLandmarkSearch; |
|
1359 iLandmarkSearch = NULL; |
|
1360 |
|
1361 } |
|
1362 |
|
1363 // --------------------------------------------------------- |
|
1364 // CPosTp38::PrintCompositeInfo |
|
1365 // |
|
1366 // (other items were commented in a header). |
|
1367 // --------------------------------------------------------- |
|
1368 // |
|
1369 void CPosTp38::PrintCompositeInfo(CPosLmCompositeCriteria* aComposite) |
|
1370 { |
|
1371 TBuf<100> buf; |
|
1372 buf.Format(_L("PrintCompositeInfo() NrOfArg %d"), aComposite->NumOfArguments()); |
|
1373 iLog->Log(buf); |
|
1374 |
|
1375 for (TUint i=0;i<aComposite->NumOfArguments();i++) |
|
1376 { |
|
1377 |
|
1378 CPosLmSearchCriteria& comp = aComposite->Argument(i); |
|
1379 TInt type = comp.CriteriaType(); |
|
1380 |
|
1381 if (type == CPosLmSearchCriteria::ECriteriaArea) |
|
1382 { |
|
1383 iLog->Log(_L("Arg Area found")); |
|
1384 |
|
1385 CPosLmAreaCriteria& tt = static_cast<CPosLmAreaCriteria&>(comp); |
|
1386 |
|
1387 TReal64 southLat; |
|
1388 TReal64 northLat; |
|
1389 TReal64 westLong; |
|
1390 TReal64 eastLong; |
|
1391 |
|
1392 tt.GetSearchArea(southLat, northLat, westLong, eastLong); |
|
1393 |
|
1394 buf.Format(_L("SouthL %f NorthL: %f WestL :%f EastL: %f"), (TReal)southLat, (TReal)northLat, (TReal)westLong, (TReal)eastLong); |
|
1395 iLog->Log(buf); |
|
1396 |
|
1397 } |
|
1398 else if (type == CPosLmSearchCriteria::ECriteriaText) |
|
1399 { |
|
1400 iLog->Log(_L("Arg Text found:")); |
|
1401 CPosLmTextCriteria& tt = static_cast<CPosLmTextCriteria&>(comp); |
|
1402 iLog->Log(tt.Text()); |
|
1403 } |
|
1404 else if (type == CPosLmSearchCriteria::ECriteriaComposite) |
|
1405 { |
|
1406 iLog->Log(_L("Arg Composite found")); |
|
1407 } |
|
1408 else if (type == CPosLmSearchCriteria::ECriteriaCategory) |
|
1409 { |
|
1410 iLog->Log(_L("Arg Category found")); |
|
1411 |
|
1412 CPosLmCategoryCriteria& tt = static_cast<CPosLmCategoryCriteria&>(comp); |
|
1413 iLog->Log(tt.CategoryName()); |
|
1414 } |
|
1415 else if (type == CPosLmSearchCriteria::ECriteriaFindNearest) |
|
1416 { |
|
1417 CPosLmNearestCriteria& tt = static_cast<CPosLmNearestCriteria&>(comp); |
|
1418 TCoordinate cord; |
|
1419 tt.GetCoordinate(cord); |
|
1420 iLog->Log(_L("Arg Nearest found")); |
|
1421 buf.Format(_L("Latitude %f Longitude: %f MaxDist:%f"), (TReal)cord.Latitude(), (TReal)cord.Longitude(), (TReal)tt.MaxDistance()); |
|
1422 iLog->Log(buf); |
|
1423 } |
|
1424 else if (type == CPosLmSearchCriteria::ECriteriaIdList) |
|
1425 { |
|
1426 iLog->Log(_L("Arg Idlist found")); |
|
1427 CPosLmIdListCriteria& tt = static_cast<CPosLmIdListCriteria&>(comp); |
|
1428 |
|
1429 RArray<TPosLmItemId> result; |
|
1430 CleanupClosePushL(result); |
|
1431 tt.GetLandmarkIdsL(result); |
|
1432 |
|
1433 buf.Format(_L("Nr of Ids: %d"), result.Count()); |
|
1434 iLog->Log(buf); |
|
1435 |
|
1436 for (TInt i=0;i<result.Count();i++) |
|
1437 { |
|
1438 buf.Format(_L("ID%d: %d"), i, result[i]); |
|
1439 |
|
1440 } |
|
1441 CleanupStack::PopAndDestroy(&result); |
|
1442 |
|
1443 } |
|
1444 else if (type == CPosLmSearchCriteria::ECriteriaCategoryByName) |
|
1445 { |
|
1446 // Should never come here, ECriteriaCategoryByName not supported in composite objects |
|
1447 iLog->Log(_L("Arg Categorybyname found")); |
|
1448 } |
|
1449 } |
|
1450 } |
|
1451 |
|
1452 // End of File |