|
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_CPosTp122.h" |
|
27 #include "FT_LandmarkConstants.h" |
|
28 #include <EPos_CPosLmDisplayData.h> |
|
29 #include <EPos_CPosLmDisplayItem.h> |
|
30 |
|
31 #include <e32math.h> |
|
32 |
|
33 // CONSTANTS |
|
34 const TInt KMaxFieldLength = 80; |
|
35 const TInt KDistanceFieldLength = 24; |
|
36 const TInt KMaxNearestLineLength = 1024; |
|
37 |
|
38 //const TInt KNrOfDatabases = 5; |
|
39 |
|
40 _LIT(KLMDB1, "NEARESTLMDB_1.LDB"); |
|
41 _LIT(KLMDB2, "NEARESTLMDB_2.LDB"); |
|
42 _LIT(KLMDB3, "NEARESTLMDB_3.LDB"); |
|
43 _LIT(KLMDB4, "NEARESTLMDB_4.LDB"); |
|
44 _LIT(KLMDB5, "NEARESTLMDB_5.LDB"); |
|
45 |
|
46 _LIT(KNEARESTLMDB, "eposlmnearestsearch.ldb"); |
|
47 |
|
48 // ================= MEMBER FUNCTIONS ======================= |
|
49 |
|
50 // --------------------------------------------------------- |
|
51 // CPosTp122::CloseTest |
|
52 // |
|
53 // (other items were commented in a header). |
|
54 // --------------------------------------------------------- |
|
55 // |
|
56 void CPosTp122::CloseTest() |
|
57 { |
|
58 iLog->Log(_L("CloseTest")); |
|
59 |
|
60 delete iDatabases; |
|
61 |
|
62 if (iMultiDbSearch) iMultiDbSearch->UnsetDisplayData(); |
|
63 delete iDisplayData; |
|
64 iDisplayData = NULL; |
|
65 |
|
66 delete iMultiDbSearch; |
|
67 iNearestSearchResults.ResetAndDestroy(); |
|
68 |
|
69 TRAPD(err, RemoveAllLmDatabasesL()); |
|
70 if (err != KErrNone) iLog->Log(_L("Error when RemoveAllLmDatabasesL")); |
|
71 } |
|
72 |
|
73 // --------------------------------------------------------- |
|
74 // CPosTp122::InitTestL |
|
75 // |
|
76 // (other items were commented in a header). |
|
77 // --------------------------------------------------------- |
|
78 // |
|
79 void CPosTp122::InitTestL() |
|
80 { |
|
81 CLandmarkTestProcedureBase::InitTestL(); |
|
82 |
|
83 iLog->Log(_L("InitTestL")); |
|
84 RemoveAllLmDatabasesL(); |
|
85 |
|
86 // PrepareDatabases |
|
87 PrepareDatabasesL(); |
|
88 |
|
89 SetupLimits(); |
|
90 |
|
91 iNrOfDatabases = 5; |
|
92 |
|
93 CPosLmDatabaseManager* dbManager = CPosLmDatabaseManager::NewL(); |
|
94 CleanupStack::PushL(dbManager); |
|
95 iDatabases = dbManager->ListDatabasesLC(); |
|
96 CleanupStack::Pop(iDatabases); |
|
97 iDatabases->Sort(); // Not really necessary... |
|
98 AssertTrueSecL((iDatabases->Count() == iNrOfDatabases), _L("Wrong number of databases")); |
|
99 |
|
100 iLog->Log( _L("List sorted")); |
|
101 |
|
102 iMultiDbSearch = CPosLmMultiDbSearch::NewL(*iDatabases); |
|
103 CleanupStack::PopAndDestroy(dbManager); |
|
104 |
|
105 iLog->Log( _L("multi search")); |
|
106 |
|
107 // Copy db file, used by CNearestSearchResult |
|
108 CopyTestDbFileL(KNEARESTLMDB); |
|
109 |
|
110 iLog->Log( _L("copied")); |
|
111 |
|
112 // Initiallize iNearestSearchResults |
|
113 AppendNearestSearchResultsL(); |
|
114 } |
|
115 |
|
116 // --------------------------------------------------------- |
|
117 // CPosTp122::SetupLimits() |
|
118 // |
|
119 // (other items were commented in a header). |
|
120 // --------------------------------------------------------- |
|
121 void CPosTp122::SetupLimits() |
|
122 { |
|
123 iIdDb1Min = 1; |
|
124 iIdDb1Max = 50; |
|
125 |
|
126 iIdDb2Min = 51; |
|
127 iIdDb2Max = 100; |
|
128 |
|
129 iIdDb3Min = 101; |
|
130 iIdDb3Max = 150; |
|
131 |
|
132 iIdDb4Min = 151; |
|
133 iIdDb4Max = 200; |
|
134 |
|
135 iIdDb5Min = 201; |
|
136 iIdDb5Max = 254; |
|
137 } |
|
138 |
|
139 // --------------------------------------------------------- |
|
140 // CPosTp122::AppendNearestSearchResultsL() |
|
141 // |
|
142 // (other items were commented in a header). |
|
143 // --------------------------------------------------------- |
|
144 void CPosTp122::AppendNearestSearchResultsL() |
|
145 { |
|
146 iNearestSearchResults.ResetAndDestroy(); |
|
147 |
|
148 _LIT(KFileTestValues, "c:\\system\\test\\testdata\\lmDbNearestSearchResult.txt"); |
|
149 |
|
150 RFile file; |
|
151 CleanupClosePushL(file); |
|
152 User::LeaveIfError(file.Open(iFileSession, KFileTestValues, EFileRead)); |
|
153 |
|
154 TInt row=0; |
|
155 TBuf<KMaxNearestLineLength> line; |
|
156 while (ReadLn(file, line) != KErrEof) |
|
157 { |
|
158 TLex lex(line); |
|
159 if (lex.Peek() != '#' && lex.Peek() != '\t') |
|
160 { |
|
161 ++row; |
|
162 |
|
163 //iLog->Log(_L("Nearest search result in progress")); |
|
164 CNearestSearchResult* searchResult = CNearestSearchResult::NewL(line, row, iFileSession); |
|
165 CleanupStack::PushL(searchResult); |
|
166 |
|
167 User::LeaveIfError(iNearestSearchResults.Append(searchResult)); |
|
168 CleanupStack::Pop(searchResult); |
|
169 //iLog->Log(_L("Nearest search result added")); |
|
170 } |
|
171 } |
|
172 CleanupStack::PopAndDestroy(&file); |
|
173 } |
|
174 |
|
175 // --------------------------------------------------------- |
|
176 // CPosTp122::PrepareDatabasesL |
|
177 // |
|
178 // (other items were commented in a header). |
|
179 // --------------------------------------------------------- |
|
180 // |
|
181 void CPosTp122::PrepareDatabasesL() |
|
182 { |
|
183 iLog->Log(_L("PrepareDatabasesL")); |
|
184 // Copy eposlmnearestsearch.ldb into five dbs |
|
185 _LIT(KDbFile, "c:\\system\\test\\testdata\\eposlmnearestsearch.ldb"); |
|
186 |
|
187 CFileMan* fileMan = CFileMan::NewL(iFileSession); |
|
188 CleanupStack::PushL(fileMan); |
|
189 |
|
190 TBuf<100> path; |
|
191 path.Zero(); |
|
192 path.Append(KLmDbPath); |
|
193 path.Append(KLMDB1); |
|
194 User::LeaveIfError(fileMan->Copy(KDbFile, path, CFileMan::EOverWrite)); |
|
195 |
|
196 path.Zero(); |
|
197 path.Append(KLmDbPath); |
|
198 path.Append(KLMDB2); |
|
199 User::LeaveIfError(fileMan->Copy(KDbFile, path, CFileMan::EOverWrite)); |
|
200 |
|
201 path.Zero(); |
|
202 path.Append(KLmDbPath); |
|
203 path.Append(KLMDB3); |
|
204 User::LeaveIfError(fileMan->Copy(KDbFile, path, CFileMan::EOverWrite)); |
|
205 |
|
206 path.Zero(); |
|
207 path.Append(KLmDbPath); |
|
208 path.Append(KLMDB4); |
|
209 User::LeaveIfError(fileMan->Copy(KDbFile, path, CFileMan::EOverWrite)); |
|
210 |
|
211 path.Zero(); |
|
212 path.Append(KLmDbPath); |
|
213 path.Append(KLMDB5); |
|
214 User::LeaveIfError(fileMan->Copy(KDbFile, path, CFileMan::EOverWrite)); |
|
215 |
|
216 CleanupStack::PopAndDestroy(fileMan); |
|
217 |
|
218 // Now adjust dbs according to following: |
|
219 // First db-> Keep landmarks 1-50 |
|
220 // Second db-> Keep landmarks 51-100 |
|
221 // Third db-> Keep landmarks 101-150 |
|
222 // Fourth db-> Keep landmarks 151-200 |
|
223 // Fifth db-> Keep landmarks 201-254 |
|
224 |
|
225 RArray<TPosLmItemId> array; |
|
226 CleanupClosePushL(array); |
|
227 |
|
228 CPosLandmarkDatabase* lmd = CPosLandmarkDatabase::OpenL(KLMDB1); |
|
229 CleanupStack::PushL(lmd); |
|
230 |
|
231 TBool debug = EFalse; |
|
232 TInt index=0; |
|
233 TInt max=254; |
|
234 for (index=50;index<max;index++) array.Append(index+1); |
|
235 if (lmd->IsInitializingNeeded()) ExecuteAndDeleteLD(lmd->InitializeL()); |
|
236 ExecuteAndDeleteLD(lmd->RemoveLandmarksL(array)); |
|
237 array.Reset(); |
|
238 if (debug) PrintLm(lmd); |
|
239 CleanupStack::PopAndDestroy(lmd); |
|
240 |
|
241 lmd = CPosLandmarkDatabase::OpenL(KLMDB2); |
|
242 CleanupStack::PushL(lmd); |
|
243 |
|
244 for (index=0;index<50;index++) array.Append(index+1); |
|
245 for (index=100;index<max;index++) array.Append(index+1); |
|
246 if (lmd->IsInitializingNeeded()) ExecuteAndDeleteLD(lmd->InitializeL()); |
|
247 ExecuteAndDeleteLD(lmd->RemoveLandmarksL(array)); |
|
248 array.Reset(); |
|
249 if (debug) PrintLm(lmd); |
|
250 CleanupStack::PopAndDestroy(lmd); |
|
251 |
|
252 lmd = CPosLandmarkDatabase::OpenL(KLMDB3); |
|
253 CleanupStack::PushL(lmd); |
|
254 |
|
255 for (index=0;index<100;index++) array.Append(index+1); |
|
256 for (index=150;index<max;index++) array.Append(index+1); |
|
257 if (lmd->IsInitializingNeeded()) ExecuteAndDeleteLD(lmd->InitializeL()); |
|
258 ExecuteAndDeleteLD(lmd->RemoveLandmarksL(array)); |
|
259 array.Reset(); |
|
260 if (debug) PrintLm(lmd); |
|
261 CleanupStack::PopAndDestroy(lmd); |
|
262 |
|
263 lmd = CPosLandmarkDatabase::OpenL(KLMDB4); |
|
264 CleanupStack::PushL(lmd); |
|
265 |
|
266 for (index=0;index<150;index++) array.Append(index+1); |
|
267 for (index=200;index<max;index++) array.Append(index+1); |
|
268 if (lmd->IsInitializingNeeded()) ExecuteAndDeleteLD(lmd->InitializeL()); |
|
269 ExecuteAndDeleteLD(lmd->RemoveLandmarksL(array)); |
|
270 array.Reset(); |
|
271 if (debug) PrintLm(lmd); |
|
272 CleanupStack::PopAndDestroy(lmd); |
|
273 |
|
274 lmd = CPosLandmarkDatabase::OpenL(KLMDB5); |
|
275 CleanupStack::PushL(lmd); |
|
276 |
|
277 for (index=0;index<200;index++) array.Append(index+1); |
|
278 if (lmd->IsInitializingNeeded()) ExecuteAndDeleteLD(lmd->InitializeL()); |
|
279 ExecuteAndDeleteLD(lmd->RemoveLandmarksL(array)); |
|
280 array.Reset(); |
|
281 if (debug) PrintLm(lmd); |
|
282 |
|
283 CleanupStack::PopAndDestroy(lmd); |
|
284 |
|
285 CleanupStack::PopAndDestroy(&array); |
|
286 iLog->Log(_L("PrepareDatabasesL Done")); |
|
287 } |
|
288 |
|
289 // --------------------------------------------------------- |
|
290 // CPosTp122::PrintLm |
|
291 // |
|
292 // (other items were commented in a header). |
|
293 // --------------------------------------------------------- |
|
294 // |
|
295 void CPosTp122::PrintLm(CPosLandmarkDatabase* db) |
|
296 { |
|
297 CPosLmItemIterator* iter = db->LandmarkIteratorL(); |
|
298 CleanupStack::PushL(iter); |
|
299 iLog->Log(_L("PrintLm")); |
|
300 //for (TInt i=0;i< iter->Count();i++) |
|
301 TPosLmItemId id = iter->NextL(); |
|
302 TBuf<100> buf; |
|
303 |
|
304 while (id != KPosLmNullItemId) |
|
305 { |
|
306 CPosLandmark* lm = db->ReadLandmarkLC(id); |
|
307 TPtrC name; |
|
308 lm->GetLandmarkName(name); |
|
309 iLog->Log(_L("Found LM '%S' "), &name); |
|
310 TInt idde = lm->LandmarkId(); |
|
311 |
|
312 id = iter->NextL(); |
|
313 CleanupStack::PopAndDestroy(lm); |
|
314 } |
|
315 |
|
316 CleanupStack::PopAndDestroy(iter); |
|
317 iLog->Log(_L("PrintLm Done")); |
|
318 } |
|
319 |
|
320 // --------------------------------------------------------- |
|
321 // CPosTp122::StartL |
|
322 // |
|
323 // (other items were commented in a header). |
|
324 // --------------------------------------------------------- |
|
325 // |
|
326 void CPosTp122::StartL() |
|
327 { |
|
328 TInt KNrOfSearch = 0; |
|
329 iErrorsFound= KErrNone; |
|
330 |
|
331 iDisplayData = CPosLmDisplayData::NewL(); |
|
332 iMultiDbSearch->SetDisplayData(*iDisplayData); |
|
333 |
|
334 iLog->Log(_L(">>>>>Search Synchronous with ascending sort order")); |
|
335 StartSearchOperationL(iNearestSearchResults, ESynchronous, ESortAscending, KNrOfSearch); |
|
336 |
|
337 iLog->Log(_L(">>>>>Search Synchronous with descending sort order")); |
|
338 StartSearchOperationL(iNearestSearchResults, ESynchronous, ESortDescending, KNrOfSearch); |
|
339 |
|
340 iLog->Log(_L(">>>>>Search Asynchronous with ascending sort order")); |
|
341 StartSearchOperationL(iNearestSearchResults, EAsynchronous, ESortAscending, KNrOfSearch); |
|
342 |
|
343 iLog->Log(_L(">>>>>Search Asynchronous with descending sort order")); |
|
344 StartSearchOperationL(iNearestSearchResults, EAsynchronous, ESortDescending, KNrOfSearch); |
|
345 |
|
346 iLog->Log(_L(">>>>>Search Synchronous with no sort order (therefore sorted by distance)")); |
|
347 StartSearchOperationL(iNearestSearchResults, ESynchronous, ESortNone); |
|
348 |
|
349 iLog->Log(_L(">>>>>Search Asynchronous with no sort order (therefore sorted by distance)")); |
|
350 StartSearchOperationL(iNearestSearchResults, EAsynchronous, ESortNone); |
|
351 |
|
352 iLog->Log(_L(">>>>>Search Synchronous with no sort order, partial (therefore sorted by distance)")); |
|
353 iPartial = ETrue; |
|
354 StartSearchOperationL(iNearestSearchResults, ESynchronous, ESortNone); |
|
355 iPartial = EFalse; |
|
356 iDisplayData->UnsetPartialReadParameters(); |
|
357 |
|
358 iLog->Log(_L("Test with maximum searches")); |
|
359 TestMaximumNrOfMatchesL(iNearestSearchResults, EAsynchronous, ESortNone); |
|
360 TestMaximumNrOfMatchesL(iNearestSearchResults, ESynchronous, ESortNone); |
|
361 TestMaximumNrOfMatchesL(iNearestSearchResults, EAsynchronous, ESortDescending); |
|
362 TestMaximumNrOfMatchesL(iNearestSearchResults, EAsynchronous, ESortAscending); |
|
363 |
|
364 iLog->Log(_L("TestOnTheFlySearchL")); |
|
365 TestOnTheFlySearchL(iNearestSearchResults); |
|
366 |
|
367 // Since TestOnTheFlySearchL is changing displadata |
|
368 iMultiDbSearch->UnsetDisplayData(); |
|
369 delete iDisplayData; |
|
370 iDisplayData = NULL; |
|
371 iDisplayData = CPosLmDisplayData::NewL(); |
|
372 iMultiDbSearch->SetDisplayData(*iDisplayData); |
|
373 |
|
374 iLog->Log(_L("Test Leave codes for nearest search")); |
|
375 TestLeaveCodesL(); |
|
376 |
|
377 // TC Step 6 "A new array of databases is set to be searched" |
|
378 iLog->Log(_L("Test refined search, test different search dbs")); |
|
379 DoLastTestPartL(iNearestSearchResults); |
|
380 |
|
381 iLog->Log(_L("Testing cancel immediately")); |
|
382 CancelTestL(iNearestSearchResults, EFalse); |
|
383 |
|
384 // XXX Hangs client |
|
385 iLog->Log(_L("Testing cancel in callback")); |
|
386 CancelTestL(iNearestSearchResults, ETrue); |
|
387 |
|
388 if (iErrorsFound != KErrNone) |
|
389 { |
|
390 |
|
391 iLog->Log(_L("Errors found in TP122")); |
|
392 User::Leave(-1); |
|
393 } |
|
394 else iLog->Log(_L("TP122 successfully completed")); |
|
395 } |
|
396 |
|
397 // --------------------------------------------------------- |
|
398 // CPosTp122::StartSearchOperationL |
|
399 // |
|
400 // (other items were commented in a header). |
|
401 // --------------------------------------------------------- |
|
402 // |
|
403 void CPosTp122::StartSearchOperationL( |
|
404 const RPointerArray<CNearestSearchResult>& aSearchResults, |
|
405 TExecutionMode aExecutionMode, |
|
406 TTp122SortOrder aSortOrder, |
|
407 TInt aNrOfSearches) |
|
408 { |
|
409 |
|
410 // Test SetMaxNumOfMatches, first set to one and then back to unlimited |
|
411 iMultiDbSearch->SetMaxNumOfMatches(1); |
|
412 iMultiDbSearch->SetMaxNumOfMatches(); |
|
413 |
|
414 TBuf<100> buf; |
|
415 TInt maxSearches = 0; |
|
416 if (aNrOfSearches == 0) maxSearches = aSearchResults.Count(); |
|
417 else maxSearches = aNrOfSearches; |
|
418 |
|
419 for(TInt i=0; i<maxSearches; i++) |
|
420 { |
|
421 TCoordinate coord(aSearchResults[i]->iLatitude, aSearchResults[i]->iLongitude); |
|
422 CPosLmNearestCriteria* nearestCriteria = CPosLmNearestCriteria::NewLC(coord, aSearchResults[i]->iUseCoverageRadius); |
|
423 nearestCriteria->SetMaxDistance(aSearchResults[i]->iMaxDistance); |
|
424 buf.Format(_L("StartSearchOperationL: Searching for Lat %f Long %f"), aSearchResults[i]->iLatitude, aSearchResults[i]->iLongitude); |
|
425 //iLog->Log(buf); |
|
426 |
|
427 if (aSearchResults[i]->iMaxSearchResult > 0) |
|
428 { |
|
429 // Does not work anymore |
|
430 //iMultiDbSearch->SetMaxNumOfMatches(aSearchResults[i]->iMaxSearchResult); |
|
431 } |
|
432 else |
|
433 { |
|
434 iMultiDbSearch->SetMaxNumOfMatches(KPosLmMaxNumOfMatchesUnlimited); |
|
435 } |
|
436 |
|
437 if (iNearestSearchResults[i]->Redefined() && i > 0) |
|
438 { |
|
439 // Remove distances that are not present in the previous |
|
440 |
|
441 for (TInt j=0; j<iNearestSearchResults[i]->iDistances.Count(); j++) |
|
442 { |
|
443 TBool found = EFalse; |
|
444 TInt id = 0; |
|
445 TPosLmItemId idde; |
|
446 |
|
447 id = j; |
|
448 idde = iNearestSearchResults[i]->iDistances[j].Id(); |
|
449 |
|
450 TBuf<100> debug; |
|
451 debug.Format(_L("Looking for id %d or id: %d "), idde, id); |
|
452 //iLog->Log(debug); |
|
453 |
|
454 for (TInt p=0;p<iNearestSearchResults[i-1]->iDistances.Count();p++) |
|
455 { |
|
456 |
|
457 if (iNearestSearchResults[i]->iDistances[j].Id() == iNearestSearchResults[i-1]->iDistances[p].Id()) |
|
458 { |
|
459 found = ETrue; |
|
460 TBuf<100> buf; |
|
461 buf.Format(_L("Found id %d or id: %d "), idde, id); |
|
462 //iLog->Log(buf); |
|
463 } |
|
464 } |
|
465 if (!found) |
|
466 { |
|
467 // Remove since not found, only keep ids that was found in previous search |
|
468 TBuf<100> buf; |
|
469 buf.Format(_L("Removing lm Id %d from index %d"), idde, id); |
|
470 //iLog->Log(buf); |
|
471 iNearestSearchResults[i]->iDistances.Remove(id); |
|
472 //iLog->Log(_L("Removing Done")); |
|
473 j--; |
|
474 } |
|
475 //iLog->Log(_L("***********")); |
|
476 } |
|
477 } |
|
478 |
|
479 TTime iStart; |
|
480 TTime iStop; |
|
481 |
|
482 iStart.UniversalTime(); |
|
483 SearchL(nearestCriteria, aExecutionMode, aSearchResults[i]->Redefined(), aSortOrder); |
|
484 iStop.UniversalTime(); |
|
485 |
|
486 TInt64 msec = (iStop.Int64() - iStart.Int64())/1000; |
|
487 buf.Format(_L("Search op nr %d took %d msec"), i, msec); |
|
488 iLog->Log(buf); |
|
489 |
|
490 AssertTrueSecL(NrOfSearchErrors(iMultiDbSearch) == 0, _L("Found search errors!")); |
|
491 |
|
492 // Add check of result here |
|
493 CheckSearchResultL(*aSearchResults[i], aSortOrder); |
|
494 |
|
495 CleanupStack::PopAndDestroy(nearestCriteria); |
|
496 iDisplayData->Reset(); |
|
497 |
|
498 } |
|
499 } |
|
500 |
|
501 // --------------------------------------------------------- |
|
502 // CPosTp122::SearchL |
|
503 // |
|
504 // (other items were commented in a header). |
|
505 // --------------------------------------------------------- |
|
506 // |
|
507 void CPosTp122::SearchL( |
|
508 CPosLmNearestCriteria* aNearestSearchCriteria, |
|
509 TExecutionMode aExecutionMode, |
|
510 TBool aRefinedSearch, |
|
511 TTp122SortOrder aSortOrder) |
|
512 { |
|
513 if (iPartial) |
|
514 { |
|
515 RArray<TUint> reqFields; |
|
516 CleanupClosePushL(reqFields); |
|
517 reqFields.Append(EPositionFieldStreet); |
|
518 reqFields.Append(EPositionFieldBuildingFloor); |
|
519 CPosLmPartialReadParameters* partialParam = CPosLmPartialReadParameters::NewLC(); |
|
520 partialParam->SetRequestedPositionFields(reqFields); |
|
521 iDisplayData->SetPartialReadParametersL(*partialParam); |
|
522 CleanupStack::PopAndDestroy(2); |
|
523 } |
|
524 |
|
525 switch (aSortOrder) |
|
526 { |
|
527 case ESortNone: |
|
528 { |
|
529 iOperation = iMultiDbSearch->StartLandmarkSearchL(*aNearestSearchCriteria, aRefinedSearch); |
|
530 break; |
|
531 } |
|
532 case ESortAscending: |
|
533 { |
|
534 TPosLmSortPref ascending(CPosLandmark::ELandmarkName); |
|
535 iOperation = iMultiDbSearch->StartLandmarkSearchL(*aNearestSearchCriteria, ascending, aRefinedSearch); |
|
536 break; |
|
537 } |
|
538 case ESortDescending: |
|
539 { |
|
540 TPosLmSortPref descending(CPosLandmark::ELandmarkName, TPosLmSortPref::EDescending); |
|
541 iOperation = iMultiDbSearch->StartLandmarkSearchL(*aNearestSearchCriteria, descending, aRefinedSearch); |
|
542 break; |
|
543 } |
|
544 default: |
|
545 User::Leave(KErrArgument); |
|
546 break; |
|
547 } |
|
548 |
|
549 switch (aExecutionMode) |
|
550 { |
|
551 case ESynchronous: |
|
552 ExecuteAndDeleteLD(iOperation); |
|
553 break; |
|
554 case EAsynchronous: |
|
555 RunAsyncOperationLD(iOperation); |
|
556 break; |
|
557 default: |
|
558 User::Leave(KErrArgument); |
|
559 break; |
|
560 } |
|
561 } |
|
562 |
|
563 // --------------------------------------------------------- |
|
564 // CPosTp122::TestMaximumNrOfMatchesL |
|
565 // |
|
566 // (other items were commented in a header). |
|
567 // --------------------------------------------------------- |
|
568 // |
|
569 void CPosTp122::TestMaximumNrOfMatchesL( |
|
570 const RPointerArray<CNearestSearchResult>& aSearchResults, |
|
571 TExecutionMode aExecutionMode, TTp122SortOrder aSortOrder) |
|
572 { |
|
573 iLog->Log(_L("TestMaximumNrOfMatchesL")); |
|
574 for (TInt j=0;j<aSearchResults.Count();j++) |
|
575 { |
|
576 TInt KIndex = j; |
|
577 TCoordinate coord(aSearchResults[KIndex]->iLatitude, aSearchResults[KIndex]->iLongitude); |
|
578 CPosLmNearestCriteria* nearestCriteria = CPosLmNearestCriteria::NewLC(coord, aSearchResults[KIndex]->iUseCoverageRadius); |
|
579 nearestCriteria->SetMaxDistance(aSearchResults[KIndex]->iMaxDistance); |
|
580 |
|
581 for (TInt i=1;i<10;i++) |
|
582 { |
|
583 // Test with different maximum nr of matches |
|
584 iMultiDbSearch->SetMaxNumOfMatches(i*2); |
|
585 |
|
586 TBuf<100> buf; |
|
587 SearchL(nearestCriteria, aExecutionMode, aSearchResults[KIndex]->Redefined(), aSortOrder); |
|
588 |
|
589 |
|
590 TInt nrOfMatches = 0; |
|
591 for (TInt j = 0; j < iNrOfDatabases; j++) |
|
592 { |
|
593 CPosLmItemIterator* iter = iMultiDbSearch->MatchIteratorL(j); |
|
594 CleanupStack::PushL(iter); |
|
595 nrOfMatches += iter->NumOfItemsL(); |
|
596 CleanupStack::PopAndDestroy(iter); |
|
597 } |
|
598 |
|
599 AssertTrueSecL(nrOfMatches <= i*2 * iNrOfDatabases, _L("Total nr of matches are bigger than the set value of maximum nr of matches")); |
|
600 AssertTrueSecL(nrOfMatches == iMultiDbSearch->TotalNumOfMatches(), _L("Total nr of matches doesn't match sum of matches in iterators")); |
|
601 AssertTrueSecL(nrOfMatches == iDisplayData->Count(), _L("Total nr of matches doesn't match sum of matches in displaydata")); |
|
602 } |
|
603 |
|
604 CleanupStack::PopAndDestroy(nearestCriteria); |
|
605 } |
|
606 |
|
607 } |
|
608 |
|
609 // --------------------------------------------------------- |
|
610 // CPosTp122::TestLeaveCodesL |
|
611 // |
|
612 // (other items were commented in a header). |
|
613 // --------------------------------------------------------- |
|
614 // |
|
615 void CPosTp122::TestLeaveCodesL() |
|
616 { |
|
617 iLog->Log(_L("TestLeaveCodesL")); |
|
618 |
|
619 TPosLmSortPref sortPref(CPosLandmark::ECategoryInfo, TPosLmSortPref::EAscending); |
|
620 TCoordinate coord(25, 45); |
|
621 CPosLmNearestCriteria* nearestCriteria = CPosLmNearestCriteria::NewLC(coord); |
|
622 |
|
623 // Only ECategoryName is supported,all other leave with KErrNotSupported |
|
624 sortPref.SetSortByLandmarkAttribute(CPosLandmark::EDescription, TPosLmSortPref::EDescending); |
|
625 TRAPD(err, iMultiDbSearch->StartLandmarkSearchL(*nearestCriteria, sortPref)); |
|
626 AssertTrueSecL(err == KErrNotSupported, _L("Should have left with KErrNotSupported")); |
|
627 |
|
628 CleanupStack::PopAndDestroy(nearestCriteria); |
|
629 } |
|
630 |
|
631 // --------------------------------------------------------- |
|
632 // CPosTp122::CancelTestL |
|
633 // |
|
634 // (other items were commented in a header). |
|
635 // --------------------------------------------------------- |
|
636 // |
|
637 void CPosTp122::CancelTestL(const RPointerArray<CNearestSearchResult>& aSearchResults, TBool aCancelInCallback) |
|
638 { |
|
639 //Test search with one criteria |
|
640 const TInt KIndex=0; |
|
641 |
|
642 TCoordinate coord(aSearchResults[KIndex]->iLatitude, aSearchResults[KIndex]->iLongitude); |
|
643 CPosLmNearestCriteria* nearestCriteria = CPosLmNearestCriteria::NewLC(coord, aSearchResults[KIndex]->iUseCoverageRadius); |
|
644 nearestCriteria->SetMaxDistance(aSearchResults[KIndex]->iMaxDistance); |
|
645 |
|
646 // Cancel in callback, cancel in every progress step phase |
|
647 // when progress has increased with 0.09 |
|
648 if (aCancelInCallback) |
|
649 { |
|
650 TReal32 progress(0); |
|
651 while (progress < 1.0) |
|
652 { |
|
653 RunAsyncOperationAndCancelInCallbackLD( |
|
654 iMultiDbSearch->StartLandmarkSearchL( |
|
655 *nearestCriteria, |
|
656 aSearchResults[KIndex]->Redefined()), |
|
657 progress); |
|
658 |
|
659 TInt nrOfMatches = 0; |
|
660 for (TInt j = 0; j < iNrOfDatabases; j++) |
|
661 { |
|
662 CPosLmItemIterator* iter = iMultiDbSearch->MatchIteratorL(j); |
|
663 CleanupStack::PushL(iter); |
|
664 nrOfMatches += iter->NumOfItemsL(); |
|
665 CleanupStack::PopAndDestroy(iter); |
|
666 } |
|
667 AssertTrueSecL(nrOfMatches == iMultiDbSearch->TotalNumOfMatches(), _L("Total nr of matches doesn't match sum of matches in iterators when cancelling")); |
|
668 //AssertTrueSecL(iMultiDbSearch->TotalNumOfMatches() == iDisplayData->Count(),_L("Wrong number of matches after cancel")); |
|
669 |
|
670 progress = progress + 0.09; |
|
671 } |
|
672 } |
|
673 else |
|
674 { |
|
675 // Cancel immediately |
|
676 RunAsyncOperationAndCancelLD( |
|
677 iMultiDbSearch->StartLandmarkSearchL( |
|
678 *nearestCriteria, |
|
679 aSearchResults[KIndex]->Redefined())); |
|
680 |
|
681 AssertTrueSecL(iMultiDbSearch->TotalNumOfMatches() == iDisplayData->Count(),_L("Wrong number of matches after cancel")); |
|
682 } |
|
683 |
|
684 if (iMultiDbSearch->NumOfSearchErrors() != 0) iLog->Log(_L("Errors after search")); |
|
685 for (TInt i=0;i<iMultiDbSearch->NumOfSearchErrors(); i++) |
|
686 { |
|
687 CPosLmMultiDbSearch::TSearchError searchErr; |
|
688 iMultiDbSearch->GetSearchError(i, searchErr); |
|
689 TBuf<150> buf; |
|
690 buf.Format(_L("ErrorCode %d returned from db nr %d"),searchErr.iErrorCode, searchErr.iDatabaseIndex); |
|
691 iLog->Log(buf); |
|
692 } |
|
693 |
|
694 CleanupStack::PopAndDestroy(nearestCriteria); |
|
695 } |
|
696 |
|
697 // --------------------------------------------------------- |
|
698 // CPosTp122::DoLastTestPartL |
|
699 // |
|
700 // (other items were commented in a header). |
|
701 // --------------------------------------------------------- |
|
702 // |
|
703 void CPosTp122::DoLastTestPartL(const RPointerArray<CNearestSearchResult>& aSearchResults) |
|
704 { |
|
705 TInt KIndex = 0; |
|
706 TCoordinate coord(aSearchResults[KIndex]->iLatitude, aSearchResults[KIndex]->iLongitude); |
|
707 CPosLmNearestCriteria* nearestCriteria = CPosLmNearestCriteria::NewLC(coord, aSearchResults[KIndex]->iUseCoverageRadius); |
|
708 nearestCriteria->SetMaxDistance(aSearchResults[KIndex]->iMaxDistance); |
|
709 |
|
710 TBuf<100> buf; |
|
711 iLog->Log(_L("Search in all dbs")); |
|
712 SearchL(nearestCriteria, ESynchronous, aSearchResults[KIndex]->Redefined(), ESortNone); |
|
713 |
|
714 // Check displaydata/iterator here |
|
715 CheckDbL(); |
|
716 |
|
717 HBufC16* db4 = (*iDatabases)[4].AllocL(); |
|
718 HBufC16* db2 = (*iDatabases)[2].AllocL(); |
|
719 |
|
720 // Remove two dbs from uri list |
|
721 iDatabases->Delete(4); |
|
722 iDatabases->Delete(2); |
|
723 iNrOfDatabases-=2; |
|
724 |
|
725 iMultiDbSearch->SetDatabasesToSearchL(*iDatabases); |
|
726 |
|
727 iIdDb3Min = 151; |
|
728 iIdDb3Max = 200; |
|
729 |
|
730 iLog->Log(_L("Search in all dbs but db2 and db4")); |
|
731 SearchL(nearestCriteria, ESynchronous, aSearchResults[KIndex]->Redefined(), ESortNone); |
|
732 CheckDbL(); |
|
733 |
|
734 // Now search in all dbs but db nr 2 |
|
735 buf.Zero(); |
|
736 buf.Format(_L("%S"), db4); |
|
737 iDatabases->AppendL(buf); |
|
738 iNrOfDatabases++; |
|
739 iDatabases->Sort(); |
|
740 |
|
741 iMultiDbSearch->SetDatabasesToSearchL(*iDatabases); |
|
742 |
|
743 // Add a new landmark to db nr 4, nr 2 in the list |
|
744 buf.Zero(); |
|
745 buf.Format(_L("Open Database: %S"), db4); |
|
746 iLog->Log(buf); |
|
747 |
|
748 buf.Zero(); |
|
749 buf.Format(_L("%S"), db4); |
|
750 CPosLandmarkDatabase* db = CPosLandmarkDatabase::OpenL(buf); |
|
751 if (db->IsInitializingNeeded()) |
|
752 { |
|
753 ExecuteAndDeleteLD(db->InitializeL()); |
|
754 } |
|
755 |
|
756 CleanupStack::PushL(db); |
|
757 CPosLandmark* lm1 = CPosLandmark::NewLC(); |
|
758 lm1->SetLandmarkNameL(_L("TP122_Landmark")); |
|
759 lm1->SetLandmarkDescriptionL(_L("Some Description")); |
|
760 TCoordinate newCoord(aSearchResults[KIndex]->iLatitude-5, aSearchResults[KIndex]->iLongitude+1); |
|
761 |
|
762 TLocality loc(newCoord, 0.5); |
|
763 lm1->SetPositionL(loc); |
|
764 iLog->Log(_L("Add new Landmark to db nr 4")); |
|
765 TPosLmItemId newLmId = db->AddLandmarkL(*lm1); |
|
766 CleanupStack::PopAndDestroy(lm1); |
|
767 CleanupStack::PopAndDestroy(db); |
|
768 |
|
769 iLog->Log(_L("Search in all dbs but db2")); |
|
770 //Refine search. new landmark should not be included |
|
771 SearchL(nearestCriteria, ESynchronous, ETrue, ESortNone); |
|
772 |
|
773 SetupLimits(); |
|
774 iIdDb3Min = 151; |
|
775 iIdDb3Max = 200; |
|
776 iIdDb4Min = 201; |
|
777 iIdDb4Max = 254; |
|
778 |
|
779 CheckDbL(); |
|
780 |
|
781 TInt itemId = iDisplayData->NewItemIndex(); |
|
782 while (itemId != KPosLmNoNewItems) |
|
783 { |
|
784 |
|
785 CPosLmDisplayItem& item = iDisplayData->DisplayItem(itemId); |
|
786 TInt lmId = item.Landmark().LandmarkId(); |
|
787 TPtrC name; |
|
788 item.Landmark().GetLandmarkName(name); |
|
789 // Verify that the landmark is not found |
|
790 if (name.CompareC(_L("TP122_Landmark")) == 0) { |
|
791 iLog->Log(_L("Added landmarks should not be found in refined search")); |
|
792 User::Leave(-1); |
|
793 |
|
794 } |
|
795 itemId = iDisplayData->NewItemIndex(); |
|
796 } |
|
797 |
|
798 // Add all dbs to the search list |
|
799 SetupLimits(); |
|
800 |
|
801 // Add the last db to the search list |
|
802 buf.Zero(); |
|
803 buf.Format(_L("%S"), db2); |
|
804 iDatabases->AppendL(buf); |
|
805 iNrOfDatabases++; |
|
806 iDatabases->Sort(); |
|
807 |
|
808 iMultiDbSearch->SetDatabasesToSearchL(*iDatabases); |
|
809 iLog->Log(_L("Search in all dbs")); |
|
810 //Refine search. new landmark should not be included |
|
811 SearchL(nearestCriteria, ESynchronous, ETrue, ESortNone); |
|
812 CheckDbL(); |
|
813 itemId = iDisplayData->NewItemIndex(); |
|
814 while (itemId != KPosLmNoNewItems) |
|
815 { |
|
816 |
|
817 CPosLmDisplayItem& item = iDisplayData->DisplayItem(itemId); |
|
818 TInt lmId = item.Landmark().LandmarkId(); |
|
819 TPtrC name; |
|
820 item.Landmark().GetLandmarkName(name); |
|
821 // Verify that the landmark is not found |
|
822 if (name.CompareC(_L("TP122_Landmark")) == 0) { |
|
823 |
|
824 iLog->Log(_L("Added landmarks should not be found in refined search")); |
|
825 User::Leave(-1); |
|
826 |
|
827 } |
|
828 |
|
829 itemId = iDisplayData->NewItemIndex(); |
|
830 } |
|
831 |
|
832 CleanupStack::PopAndDestroy(nearestCriteria); |
|
833 |
|
834 // Correct limits if more testing after this part |
|
835 SetupLimits(); |
|
836 delete db4; |
|
837 delete db2; |
|
838 } |
|
839 |
|
840 // --------------------------------------------------------- |
|
841 // CPosTp122::CheckDbL |
|
842 // |
|
843 // (other items were commented in a header). |
|
844 // --------------------------------------------------------- |
|
845 // |
|
846 void CPosTp122::CheckDbL() |
|
847 { |
|
848 iLog->Log(_L("CheckDbL")); |
|
849 CDesCArray* dbToSearch = iMultiDbSearch->DatabasesToSearchL(); |
|
850 CleanupStack::PushL(dbToSearch); |
|
851 TBuf<100> buf; |
|
852 |
|
853 for (TInt i=0;i<dbToSearch->Count();i++) |
|
854 { |
|
855 buf.Zero(); |
|
856 buf.Format(_L("DB nr %d "), i); |
|
857 |
|
858 buf.Append((*dbToSearch)[i]); |
|
859 iLog->Log(buf); |
|
860 } |
|
861 |
|
862 if (iMultiDbSearch->NumOfDatabasesToSearch() != dbToSearch->Count()) iLog->Log(_L("Differ...")); |
|
863 |
|
864 CleanupStack::PopAndDestroy(dbToSearch); |
|
865 |
|
866 for (TInt j = 0; j <iMultiDbSearch->NumOfDatabasesToSearch(); j++) |
|
867 { |
|
868 CPosLmItemIterator* iter = iMultiDbSearch->MatchIteratorL(j); |
|
869 CleanupStack::PushL(iter); |
|
870 |
|
871 TPosLmItemId id = iter->NextL(); |
|
872 while (id != KPosLmNullItemId) |
|
873 { |
|
874 ValidateIdL(id, j); |
|
875 id = iter->NextL(); |
|
876 } |
|
877 //GetSearchError |
|
878 //NumOfSearchErrors |
|
879 CleanupStack::PopAndDestroy(iter); |
|
880 } |
|
881 iLog->Log(_L("CheckDbL Done")); |
|
882 } |
|
883 |
|
884 // --------------------------------------------------------- |
|
885 // CPosTp122::CheckSearchResultL |
|
886 // |
|
887 // (other items were commented in a header). |
|
888 // --------------------------------------------------------- |
|
889 // |
|
890 void CPosTp122::CheckSearchResultL(CNearestSearchResult& aSearchResult, TTp122SortOrder aSortOrder) |
|
891 { |
|
892 TBuf<150> buf; |
|
893 TUint expectedNoMatches = aSearchResult.iDistances.Count(); |
|
894 if (aSearchResult.iMaxSearchResult != 0 && aSearchResult.iMaxSearchResult < aSearchResult.iDistances.Count()) |
|
895 { |
|
896 |
|
897 } |
|
898 |
|
899 ValidateTotalNrOfMatchesL(expectedNoMatches, iMultiDbSearch->TotalNumOfMatches()); |
|
900 |
|
901 //iLog->Log(_L("Adding...")); |
|
902 |
|
903 // First check that result comes from correct db |
|
904 TInt nrOfMatches = 0; |
|
905 for (TInt j = 0; j < iNrOfDatabases; j++) |
|
906 { |
|
907 CPosLandmarkDatabase* db = CPosLandmarkDatabase::OpenL((*iDatabases)[j]); |
|
908 if (db->IsInitializingNeeded()) |
|
909 { |
|
910 ExecuteAndDeleteLD(db->InitializeL()); |
|
911 } |
|
912 |
|
913 CleanupStack::PushL(db); |
|
914 CPosLmItemIterator* iter = iMultiDbSearch->MatchIteratorL(j); |
|
915 CleanupStack::PushL(iter); |
|
916 |
|
917 nrOfMatches += iter->NumOfItemsL(); |
|
918 TPosLmItemId id = iter->NextL(); |
|
919 while (id != KPosLmNullItemId) |
|
920 { |
|
921 ValidateIdL(id, j); |
|
922 id = iter->NextL(); |
|
923 } |
|
924 TBuf<100> buf; |
|
925 buf.Format(_L("Found %d nr of matches from db nr %d"), iter->NumOfItemsL(), j); |
|
926 //iLog->Log(buf); |
|
927 |
|
928 CleanupStack::PopAndDestroy(iter); |
|
929 CleanupStack::PopAndDestroy(db); |
|
930 } |
|
931 |
|
932 //iLog->Log(_L("Done adding...")); |
|
933 |
|
934 if (nrOfMatches != iDisplayData->Count()) |
|
935 { |
|
936 iLog->Log(_L("Wrong number of items")); |
|
937 User::Leave(-1); |
|
938 |
|
939 } |
|
940 |
|
941 // Sorted on distance |
|
942 if (aSortOrder == ESortNone) |
|
943 { |
|
944 TInt index=0; |
|
945 TInt itemId = iDisplayData->NewItemIndex(); |
|
946 while (itemId != KPosLmNoNewItems) |
|
947 { |
|
948 |
|
949 CPosLmDisplayItem& item = iDisplayData->DisplayItem(itemId); |
|
950 TInt lmId = item.Landmark().LandmarkId(); |
|
951 |
|
952 TReal32 distance =0; |
|
953 TInt dist = item.GetDistance(distance); |
|
954 if(dist == KErrNone) |
|
955 { |
|
956 //iLog->Log(_L("CPosLmDisplayItem::GetDistanced returns KErrNone")); |
|
957 } |
|
958 |
|
959 else if(dist == KErrNotFound) |
|
960 { |
|
961 //iLog->Log(_L("CPosLmDisplayItem::GetDistanced returns KErrNotFound")); |
|
962 } |
|
963 |
|
964 // Validate lm from correct db |
|
965 TInt dbIndex = item.DatabaseIndex(); |
|
966 |
|
967 ValidateIdL(lmId, dbIndex); |
|
968 |
|
969 TBuf<100> buf; |
|
970 buf.Format(_L("Found exp id %d returned id %d"),aSearchResult.iDistances[index].iId, lmId); |
|
971 //iLog->Log(buf); |
|
972 |
|
973 if (aSearchResult.iDistances[index].iId != lmId) |
|
974 { |
|
975 // if the distance is equal to the distance to the landmark |
|
976 // before or after then no error. |
|
977 // This to be able to use a database with landmarks with the same position. |
|
978 |
|
979 TBool noError=EFalse; |
|
980 if (index > 0) |
|
981 { |
|
982 noError = (aSearchResult.iDistances[index-1].iDistance == aSearchResult.iDistances[index].iDistance); |
|
983 } |
|
984 if (index < aSearchResult.iDistances.Count() && !noError) |
|
985 { |
|
986 noError = (aSearchResult.iDistances[index+1].iDistance == aSearchResult.iDistances[index].iDistance); |
|
987 } |
|
988 if (!noError) |
|
989 { |
|
990 _LIT(KUnexpectedItemId, "ERROR: Unexpected item id"); |
|
991 |
|
992 iErrorsFound++; |
|
993 iLog->Log(KUnexpectedItemId); |
|
994 } |
|
995 } |
|
996 itemId = iDisplayData->NewItemIndex(); |
|
997 index++; |
|
998 } |
|
999 } |
|
1000 // Ascended and descended |
|
1001 else |
|
1002 { |
|
1003 /////////// |
|
1004 for (TInt i=0;i<iDisplayData->Count();i++) |
|
1005 { |
|
1006 // Check for all but first and last |
|
1007 if (i>0 && i<iDisplayData->Count()-1) |
|
1008 { |
|
1009 CPosLmDisplayItem& item = iDisplayData->DisplayItem(i); |
|
1010 TInt lmId = item.Landmark().LandmarkId(); |
|
1011 TReal32 distance =0; |
|
1012 TInt dist = item.GetDistance(distance); |
|
1013 if(dist == KErrNone) |
|
1014 { |
|
1015 //iLog->Log(_L("CPosLmDisplayItem::GetDistanced returns KErrNone")); |
|
1016 } |
|
1017 |
|
1018 else if(dist == KErrNotFound) |
|
1019 { |
|
1020 //iLog->Log(_L("CPosLmDisplayItem::GetDistanced returns KErrNotFound")); |
|
1021 } |
|
1022 |
|
1023 CPosLmDisplayItem& nextItem = iDisplayData->DisplayItem(i+1); |
|
1024 TInt nextLmId = nextItem.Landmark().LandmarkId(); |
|
1025 |
|
1026 TPtrC name, nextLmName; |
|
1027 item.Landmark().GetLandmarkName(name); |
|
1028 nextItem.Landmark().GetLandmarkName(nextLmName); |
|
1029 |
|
1030 // Validate lm from correct db |
|
1031 TInt dbIndex = item.DatabaseIndex(); |
|
1032 ValidateIdL(lmId, dbIndex); |
|
1033 TInt nextDbIndex = nextItem.DatabaseIndex(); |
|
1034 // Validate next lm from correct db |
|
1035 ValidateIdL(nextLmId, nextDbIndex); |
|
1036 |
|
1037 //debugging purposes |
|
1038 |
|
1039 |
|
1040 TInt order = nextLmName.CompareC(name); |
|
1041 if (aSortOrder == ESortAscending) |
|
1042 { // sorted ascended |
|
1043 if (order < 0) |
|
1044 { |
|
1045 iLog->Log(_L("ERROR: Wrong sortorder when ascended")); |
|
1046 iErrorsFound++; |
|
1047 } |
|
1048 } |
|
1049 else // sorted descended |
|
1050 { |
|
1051 if (order > 0) |
|
1052 { |
|
1053 iLog->Log(_L("ERROR: Wrong sortorder when descended")); |
|
1054 iErrorsFound++; |
|
1055 } |
|
1056 |
|
1057 } |
|
1058 } |
|
1059 } |
|
1060 |
|
1061 } |
|
1062 iLog->Log(_L("CheckSearchResultL Done")); |
|
1063 } |
|
1064 |
|
1065 // --------------------------------------------------------- |
|
1066 // CPosTp122::ValidateTotalNrOfMatchesL |
|
1067 // |
|
1068 // (other items were commented in a header). |
|
1069 // --------------------------------------------------------- |
|
1070 // |
|
1071 void CPosTp122::ValidateTotalNrOfMatchesL ( |
|
1072 TUint aRetrievedNrOfMatches, |
|
1073 TUint aExpectedNrOfMatches) |
|
1074 { |
|
1075 _LIT(KNumOfMatchesErr, "ERROR: No. of matches is incorrect when the search is performed"); |
|
1076 |
|
1077 if (aRetrievedNrOfMatches != aExpectedNrOfMatches) |
|
1078 { |
|
1079 _LIT(KExpected, "Expected no. of matches: %d"); |
|
1080 _LIT(KReturned, "Returned no. of matches: %d"); |
|
1081 TBuf<100> info; |
|
1082 info.Format(KExpected, aExpectedNrOfMatches); |
|
1083 iLog->Log(info); |
|
1084 info.Format(KReturned, aRetrievedNrOfMatches); |
|
1085 iLog->Log(info); |
|
1086 |
|
1087 iLog->Log(KNumOfMatchesErr); |
|
1088 iErrorsFound++; |
|
1089 } |
|
1090 } |
|
1091 |
|
1092 // --------------------------------------------------------- |
|
1093 // CPosTp122::ValidateIdL |
|
1094 // |
|
1095 // (other items were commented in a header). |
|
1096 // --------------------------------------------------------- |
|
1097 // |
|
1098 void CPosTp122::ValidateIdL(TPosLmItemId aId, TInt aDbIndex) |
|
1099 { |
|
1100 TBool condition = EFalse; |
|
1101 switch (aDbIndex) |
|
1102 { |
|
1103 case 0: |
|
1104 // Db 1 contains landmarks with id = 1-50 |
|
1105 condition = aId >= iIdDb1Min && aId <= iIdDb1Max; |
|
1106 break; |
|
1107 case 1: |
|
1108 // Db 2 contains landmarks with id = 51-100 |
|
1109 condition = aId >= iIdDb2Min && aId <= iIdDb2Max; |
|
1110 break; |
|
1111 case 2: |
|
1112 // Db 3 contains landmarks with id = 101-150 |
|
1113 condition = aId >= iIdDb3Min && aId <= iIdDb3Max; |
|
1114 break; |
|
1115 case 3: |
|
1116 // Db 4 contains landmarks with id = 151-200 |
|
1117 condition = aId >= iIdDb4Min && aId <= iIdDb4Max; |
|
1118 break; |
|
1119 case 4: |
|
1120 // Db 5 contains landmarks with id = 201-254 |
|
1121 condition = aId >= iIdDb5Min && aId <= iIdDb5Max; |
|
1122 break; |
|
1123 } |
|
1124 |
|
1125 if (!condition) |
|
1126 { |
|
1127 iErrorsFound++; |
|
1128 TBuf<150> buf; |
|
1129 buf.Format(_L("ERROR: Invalid match from database reported, index %d in db %d"), aId, aDbIndex); |
|
1130 iLog->Log(buf); |
|
1131 } |
|
1132 } |
|
1133 |
|
1134 // --------------------------------------------------------- |
|
1135 // CPosTp122::TestOnTheFlySearchL |
|
1136 // |
|
1137 // (other items were commented in a header). |
|
1138 // --------------------------------------------------------- |
|
1139 // |
|
1140 void CPosTp122::TestOnTheFlySearchL(const RPointerArray<CNearestSearchResult>& aSearchResults) |
|
1141 { |
|
1142 iMultiDbSearch->SetMaxNumOfMatches(KPosLmMaxNumOfMatchesUnlimited); |
|
1143 iMultiDbSearch->SetMaxNumOfMatches(); |
|
1144 |
|
1145 TInt KIndex = 0; |
|
1146 TCoordinate coord(aSearchResults[KIndex]->iLatitude, aSearchResults[KIndex]->iLongitude); |
|
1147 CPosLmNearestCriteria* nearestCriteria = CPosLmNearestCriteria::NewLC(coord, aSearchResults[KIndex]->iUseCoverageRadius); |
|
1148 nearestCriteria->SetMaxDistance(aSearchResults[KIndex]->iMaxDistance); |
|
1149 |
|
1150 RIdArray expectedMatches; |
|
1151 CleanupClosePushL(expectedMatches); |
|
1152 |
|
1153 TBuf<150> buf; |
|
1154 COnTheFlyTester* onTheFlyTester = COnTheFlyTester::NewLC(); |
|
1155 |
|
1156 // Remove lm with index 48,49,50, they have no location (see lmDbNearestSearch in landmarksdb.xls) |
|
1157 TInt pos = aSearchResults[KIndex]->iSearchResult.Find(48); |
|
1158 aSearchResults[KIndex]->iSearchResult.Remove(pos); |
|
1159 pos = aSearchResults[KIndex]->iSearchResult.Find(49); |
|
1160 aSearchResults[KIndex]->iSearchResult.Remove(pos); |
|
1161 pos = aSearchResults[KIndex]->iSearchResult.Find(50); |
|
1162 aSearchResults[KIndex]->iSearchResult.Remove(pos); |
|
1163 |
|
1164 onTheFlyTester->StartSearchCampaignL(iMultiDbSearch, aSearchResults[KIndex]->iSearchResult, nearestCriteria); |
|
1165 |
|
1166 TInt result = onTheFlyTester->Err(); |
|
1167 if (result != KErrNone) |
|
1168 { |
|
1169 TPtrC msg; |
|
1170 onTheFlyTester->GetErrMsg(msg); |
|
1171 |
|
1172 iLog->Log(msg); |
|
1173 User::Leave(result); |
|
1174 } |
|
1175 CleanupStack::PopAndDestroy(onTheFlyTester); |
|
1176 CleanupStack::PopAndDestroy(&expectedMatches); |
|
1177 CleanupStack::PopAndDestroy(nearestCriteria); |
|
1178 iLog->Log(_L("TestOnTheFlySearchL Done")); |
|
1179 } |
|
1180 |
|
1181 // --------------------------------------------------------- |
|
1182 // CPosTp122::NrOfSearchErrors |
|
1183 // |
|
1184 // (other items were commented in a header). |
|
1185 // --------------------------------------------------------- |
|
1186 // |
|
1187 TInt CPosTp122::NrOfSearchErrors(CPosLmMultiDbSearch* aMultiDbSearcher) |
|
1188 { |
|
1189 TInt nrOfSearchErrors = aMultiDbSearcher->NumOfSearchErrors(); |
|
1190 if (nrOfSearchErrors != 0) |
|
1191 { |
|
1192 for (TInt i = 0; i < nrOfSearchErrors; i++) |
|
1193 { |
|
1194 CPosLmMultiDbSearch::TSearchError error; |
|
1195 aMultiDbSearcher->GetSearchError(i, error); |
|
1196 TBuf<100> msg; |
|
1197 msg.Format(_L("Found error %d in database %d"), error.iErrorCode, error.iDatabaseIndex); |
|
1198 iLog->Log(msg); |
|
1199 } |
|
1200 } |
|
1201 return nrOfSearchErrors; |
|
1202 } |
|
1203 |
|
1204 |
|
1205 // --------------------------------------------------------- |
|
1206 // CNearestSearchResult::NewL() |
|
1207 // |
|
1208 // (other items were commented in a header). |
|
1209 // --------------------------------------------------------- |
|
1210 CNearestSearchResult* CNearestSearchResult::NewL( |
|
1211 const TDesC& aDes, |
|
1212 const TInt& aIndex, |
|
1213 RFs& aFileSession) |
|
1214 { |
|
1215 CNearestSearchResult* self = new(ELeave) CNearestSearchResult(aFileSession); |
|
1216 CleanupStack::PushL(self); |
|
1217 self->ConstructL(aDes, aIndex); |
|
1218 CleanupStack::Pop(); |
|
1219 return self; |
|
1220 } |
|
1221 |
|
1222 // C++ default constructor can NOT contain any code, that |
|
1223 // might leave. |
|
1224 // |
|
1225 CNearestSearchResult::CNearestSearchResult(RFs& aFileSession) |
|
1226 : iFileSession( aFileSession ) |
|
1227 { |
|
1228 TRealX nan; |
|
1229 nan.SetNaN(); |
|
1230 iMaxDistance = nan; |
|
1231 } |
|
1232 |
|
1233 // --------------------------------------------------------- |
|
1234 // CNearestSearchResult::CounstructL() |
|
1235 // |
|
1236 // (other items were commented in a header). |
|
1237 // --------------------------------------------------------- |
|
1238 void CNearestSearchResult::ConstructL(const TDesC& aDes, const TInt& aIndex) |
|
1239 { |
|
1240 // Use KNEARESTLMDB as correct template |
|
1241 iDatabase = CPosLandmarkDatabase::OpenL(KNEARESTLMDB); |
|
1242 |
|
1243 if ( iDatabase->IsInitializingNeeded() ) |
|
1244 { |
|
1245 TRAPD( err, ExecuteAndDeleteLD( iDatabase->InitializeL() ) ); |
|
1246 } |
|
1247 |
|
1248 TLex line(aDes); |
|
1249 line.Mark(); |
|
1250 TInt redefined=0, useCoverageRadius; |
|
1251 |
|
1252 if (line.Peek() != '#' && line.Peek() != '\t') |
|
1253 { |
|
1254 TInt index=0; |
|
1255 while (line.Peek() != '\n' && !(line.Peek()).Eos()) |
|
1256 { |
|
1257 line.Inc(); |
|
1258 if (line.Peek() == '\t') |
|
1259 { |
|
1260 TPtrC token = line.MarkedToken(); |
|
1261 TLex val(token); |
|
1262 switch(index) |
|
1263 { |
|
1264 case ELatitude: |
|
1265 val.Val(iLatitude, TChar(',')); |
|
1266 break; |
|
1267 case ELongitude: |
|
1268 val.Val(iLongitude, TChar(',')); |
|
1269 break; |
|
1270 case EUseCoverageRadius: |
|
1271 val.Val(useCoverageRadius); |
|
1272 if (useCoverageRadius == 1) |
|
1273 { |
|
1274 iUseCoverageRadius = ETrue; |
|
1275 } |
|
1276 break; |
|
1277 case EMaxDistance: |
|
1278 val.Val(iMaxDistance); |
|
1279 break; |
|
1280 case EErrorCode: |
|
1281 val.Val(iErrorCode); |
|
1282 break; |
|
1283 case ESearchResult: |
|
1284 ParseSearchResult(token); |
|
1285 break; |
|
1286 case ERedefined: |
|
1287 val.Val(redefined); |
|
1288 if (redefined == 1) |
|
1289 { |
|
1290 iRedefined = ETrue; |
|
1291 } |
|
1292 break; |
|
1293 case EMaxSearchResult: |
|
1294 val.Val(iMaxSearchResult); |
|
1295 break; |
|
1296 } |
|
1297 line.Inc(); |
|
1298 while (line.Peek() == '\t') // Empty value |
|
1299 { |
|
1300 line.Inc(); |
|
1301 ++index; |
|
1302 } |
|
1303 line.Mark(); |
|
1304 ++index; |
|
1305 } |
|
1306 } |
|
1307 AppendDistancesL(aIndex); |
|
1308 |
|
1309 } |
|
1310 } |
|
1311 |
|
1312 |
|
1313 // Destructor |
|
1314 CNearestSearchResult::~CNearestSearchResult() |
|
1315 { |
|
1316 iDistances.Close(); |
|
1317 delete iDatabase; |
|
1318 iDatabase = NULL; |
|
1319 } |
|
1320 |
|
1321 // --------------------------------------------------------- |
|
1322 // CNearestSearchResult::AppendDistancesL() |
|
1323 // |
|
1324 // (other items were commented in a header). |
|
1325 // --------------------------------------------------------- |
|
1326 void CNearestSearchResult::AppendDistancesL(const TInt& aIndex) |
|
1327 { |
|
1328 iDistances.Reset(); |
|
1329 |
|
1330 _LIT(KFileTestValues, "c:\\system\\test\\testdata\\lmDbNearestSearch.txt"); |
|
1331 |
|
1332 RFile file; |
|
1333 CleanupClosePushL(file); |
|
1334 User::LeaveIfError(file.Open(iFileSession, KFileTestValues, EFileRead)); |
|
1335 |
|
1336 TInt row=0; |
|
1337 TBuf<KMaxNearestLineLength> line; |
|
1338 while (CLandmarkTestProcedureBase::ReadLn(file, line) != KErrEof) |
|
1339 { |
|
1340 ParseDistanceL(line, aIndex, row); |
|
1341 ++row; |
|
1342 } |
|
1343 |
|
1344 SortDistances(); |
|
1345 |
|
1346 CleanupStack::PopAndDestroy(&file); |
|
1347 } |
|
1348 |
|
1349 // --------------------------------------------------------- |
|
1350 // CNearestSearchResult::ParseDistancesL() |
|
1351 // |
|
1352 // (other items were commented in a header). |
|
1353 // --------------------------------------------------------- |
|
1354 void CNearestSearchResult::ParseDistanceL(const TDesC& aDes, |
|
1355 const TInt& aIndex, |
|
1356 const TPosLmItemId& aId) |
|
1357 { |
|
1358 |
|
1359 const TInt KStartIndex = 5; |
|
1360 |
|
1361 TLex line(aDes); |
|
1362 line.Mark(); |
|
1363 TInt index = 0; |
|
1364 TReal64 dist=0; |
|
1365 |
|
1366 if (line.Peek() != '#' && line.Peek() != '\t') |
|
1367 { |
|
1368 while (line.Peek() != '\n' && !(line.Peek()).Eos()) |
|
1369 { |
|
1370 line.Inc(); |
|
1371 if (line.Peek() == '\t' || line.Peek() == '\n' || (line.Peek()).Eos()) |
|
1372 { |
|
1373 TPtrC token = line.MarkedToken(); |
|
1374 |
|
1375 if (index == (KStartIndex + aIndex)) |
|
1376 { |
|
1377 TLex val(token); |
|
1378 val.Val(dist, TChar(',')); |
|
1379 |
|
1380 if (iUseCoverageRadius) |
|
1381 { |
|
1382 CPosLandmark* lm = iDatabase->ReadLandmarkLC(aId); |
|
1383 |
|
1384 TReal32 aCoverageRadius; |
|
1385 if (lm->GetCoverageRadius(aCoverageRadius) == KErrNone) |
|
1386 { |
|
1387 dist -= aCoverageRadius; |
|
1388 if (dist < 0) |
|
1389 { |
|
1390 dist = 0; |
|
1391 } |
|
1392 } |
|
1393 CleanupStack::PopAndDestroy(lm); |
|
1394 } |
|
1395 |
|
1396 if (Math::IsNaN(iMaxDistance) || dist <= iMaxDistance) |
|
1397 { |
|
1398 if (dist != -1) |
|
1399 { |
|
1400 TSearchResult searchResult(aId, TReal32(dist)); |
|
1401 iDistances.Append(searchResult); |
|
1402 } |
|
1403 } |
|
1404 |
|
1405 break; |
|
1406 } |
|
1407 line.Inc(); |
|
1408 while (line.Peek() == '\t') // Empty value |
|
1409 { |
|
1410 line.Inc(); |
|
1411 ++index; |
|
1412 } |
|
1413 line.Mark(); |
|
1414 ++index; |
|
1415 } |
|
1416 } |
|
1417 } |
|
1418 } |
|
1419 // --------------------------------------------------------- |
|
1420 // CNearestSearchResult::Latitude |
|
1421 // |
|
1422 // (other items were commented in a header). |
|
1423 // --------------------------------------------------------- |
|
1424 // |
|
1425 TReal64 CNearestSearchResult::Latitude() const |
|
1426 { |
|
1427 return iLatitude; |
|
1428 } |
|
1429 |
|
1430 // --------------------------------------------------------- |
|
1431 // CNearestSearchResult::Latitude |
|
1432 // |
|
1433 // (other items were commented in a header). |
|
1434 // --------------------------------------------------------- |
|
1435 // |
|
1436 TReal64 CNearestSearchResult::Longitude() const |
|
1437 { |
|
1438 return iLongitude; |
|
1439 } |
|
1440 |
|
1441 // --------------------------------------------------------- |
|
1442 // CNearestSearchResult::UseCoverageRadius |
|
1443 // |
|
1444 // (other items were commented in a header). |
|
1445 // --------------------------------------------------------- |
|
1446 // |
|
1447 TBool CNearestSearchResult::UseCoverageRadius() const |
|
1448 { |
|
1449 return iUseCoverageRadius; |
|
1450 } |
|
1451 |
|
1452 // --------------------------------------------------------- |
|
1453 // CNearestSearchResult::MaxDistance |
|
1454 // |
|
1455 // (other items were commented in a header). |
|
1456 // --------------------------------------------------------- |
|
1457 // |
|
1458 TReal32 CNearestSearchResult::MaxDistance() const |
|
1459 { |
|
1460 return iMaxDistance; |
|
1461 } |
|
1462 |
|
1463 // --------------------------------------------------------- |
|
1464 // CNearestSearchResult::ErrorCode |
|
1465 // |
|
1466 // (other items were commented in a header). |
|
1467 // --------------------------------------------------------- |
|
1468 // |
|
1469 TInt CNearestSearchResult::ErrorCode() const |
|
1470 { |
|
1471 return iErrorCode; |
|
1472 } |
|
1473 |
|
1474 // --------------------------------------------------------- |
|
1475 // InternalLandmarksSortL |
|
1476 // |
|
1477 // (other items were commented in a header). |
|
1478 // --------------------------------------------------------- |
|
1479 // |
|
1480 TInt InternalSort(const TSearchResult& aSource, const TSearchResult& aTarget) |
|
1481 { |
|
1482 // zero, if the two objects are equal |
|
1483 // a negative value, if the first object is less than the second. |
|
1484 // a positive value, if the first object is greater than the second. |
|
1485 |
|
1486 if ( aSource.Distance() == aTarget.Distance()) |
|
1487 { |
|
1488 return 0; |
|
1489 } |
|
1490 else if (aSource.Distance() < aTarget.Distance()) |
|
1491 { |
|
1492 return -1; |
|
1493 } |
|
1494 |
|
1495 return 1; |
|
1496 } |
|
1497 |
|
1498 // --------------------------------------------------------- |
|
1499 // CNearestSearchResult::ErrorCode |
|
1500 // |
|
1501 // (other items were commented in a header). |
|
1502 // --------------------------------------------------------- |
|
1503 // |
|
1504 void CNearestSearchResult::SortDistances() |
|
1505 { |
|
1506 TLinearOrder<TSearchResult> order(InternalSort); |
|
1507 iDistances.Sort(order); |
|
1508 } |
|
1509 |
|
1510 // --------------------------------------------------------- |
|
1511 // CNearestSearchResult::Print |
|
1512 // |
|
1513 // (other items were commented in a header). |
|
1514 // --------------------------------------------------------- |
|
1515 // |
|
1516 void CNearestSearchResult::Print(TDes& aPrint) |
|
1517 { |
|
1518 _LIT(KPosInfo, "Latitude=%g, Longitude=%g"); |
|
1519 TChar del(','); |
|
1520 |
|
1521 TBuf<KMaxFieldLength> info; |
|
1522 info.Format(KPosInfo, iLatitude, iLongitude); |
|
1523 aPrint.Append(info); |
|
1524 aPrint.Append(del); |
|
1525 |
|
1526 _LIT(KUseCoverageRadius, "UseCoverageRadius=%d"); |
|
1527 info.Format(KUseCoverageRadius, iUseCoverageRadius); |
|
1528 aPrint.Append(info); |
|
1529 aPrint.Append(del); |
|
1530 |
|
1531 if (!Math::IsNaN(iMaxDistance)) |
|
1532 { |
|
1533 _LIT(KMaxDistance, "MaxDistance=%g"); |
|
1534 info.Format(KMaxDistance, iMaxDistance); |
|
1535 aPrint.Append(info); |
|
1536 aPrint.Append(del); |
|
1537 } |
|
1538 |
|
1539 _LIT(KErrorCode, "ErrorCode = %d"); |
|
1540 info.Format(KErrorCode, iErrorCode); |
|
1541 aPrint.Append(info); |
|
1542 aPrint.Append(del); |
|
1543 |
|
1544 _LIT(KRedefined, "Redefined=%d"); |
|
1545 info.Format(KRedefined, iRedefined); |
|
1546 aPrint.Append(info); |
|
1547 aPrint.Append(del); |
|
1548 |
|
1549 _LIT(KMaxSearchResult, "MaxSearchResult=%d"); |
|
1550 info.Format(KMaxSearchResult, iMaxSearchResult); |
|
1551 aPrint.Append(info); |
|
1552 aPrint.Append(del); |
|
1553 |
|
1554 |
|
1555 PrintDistances(aPrint); |
|
1556 } |
|
1557 |
|
1558 // --------------------------------------------------------- |
|
1559 // CNearestSearchResult::PrintDistances |
|
1560 // |
|
1561 // (other items were commented in a header). |
|
1562 // --------------------------------------------------------- |
|
1563 // |
|
1564 void CNearestSearchResult::PrintDistances(TDes& aPrint) |
|
1565 { |
|
1566 TBuf<KDistanceFieldLength> info2; |
|
1567 TChar del(':'); |
|
1568 aPrint.Append(_L("Distances: ")); |
|
1569 |
|
1570 for (TInt j=0; j<iDistances.Count(); j++) |
|
1571 { |
|
1572 _LIT(KDistance, "%g,%d"); |
|
1573 info2.Format(KDistance, iDistances[j].Distance(), iDistances[j].Id()); |
|
1574 aPrint.Append(info2); |
|
1575 aPrint.Append(del); |
|
1576 } |
|
1577 } |
|
1578 |
|
1579 // --------------------------------------------------------- |
|
1580 // TSearchResult::TSearchResult |
|
1581 // |
|
1582 // (other items were commented in a header). |
|
1583 // --------------------------------------------------------- |
|
1584 // |
|
1585 TSearchResult::TSearchResult() |
|
1586 { |
|
1587 TRealX nan; |
|
1588 nan.SetNaN(); |
|
1589 iDistance=nan; |
|
1590 iId=0; |
|
1591 } |
|
1592 |
|
1593 TSearchResult::TSearchResult(const TPosLmItemId& aId, const TReal32& aDistance) : |
|
1594 iDistance(aDistance), |
|
1595 iId(aId) |
|
1596 { |
|
1597 } |
|
1598 |
|
1599 // --------------------------------------------------------- |
|
1600 // TSearchResult::Distance |
|
1601 // |
|
1602 // (other items were commented in a header). |
|
1603 // --------------------------------------------------------- |
|
1604 // |
|
1605 TReal64 TSearchResult::Distance() const |
|
1606 { |
|
1607 return iDistance; |
|
1608 } |
|
1609 |
|
1610 // --------------------------------------------------------- |
|
1611 // TSearchResult::Id |
|
1612 // |
|
1613 // (other items were commented in a header). |
|
1614 // --------------------------------------------------------- |
|
1615 // |
|
1616 TPosLmItemId TSearchResult::Id() const |
|
1617 { |
|
1618 return iId; |
|
1619 } |
|
1620 // End of File |