|
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 |
|
22 #include "FT_CPosTp35.h" |
|
23 #include <f32file.h> |
|
24 #include <e32math.h> |
|
25 #include <e32math.h> |
|
26 |
|
27 #include <EPos_CPosLandmarkDatabase.h> |
|
28 #include <EPos_CPosLandmarkSearch.h> |
|
29 #include <EPos_CPosLMItemIterator.h> |
|
30 #include <EPos_CPosLmDatabaseManager.h> |
|
31 #include "FT_LandmarkConstants.h" |
|
32 |
|
33 // CONSTANTS |
|
34 const TInt KMaxFieldLength = 80; |
|
35 const TInt KDistanceFieldLength = 24; |
|
36 const TInt KMaxNearestLineLength = 1024; |
|
37 |
|
38 // ================= MEMBER FUNCTIONS ======================= |
|
39 |
|
40 // --------------------------------------------------------- |
|
41 // CPosTp35::CloseTest |
|
42 // |
|
43 // (other items were commented in a header). |
|
44 // --------------------------------------------------------- |
|
45 // |
|
46 void CPosTp35::CloseTest() |
|
47 { |
|
48 iLog->Log(_L("CloseTest")); |
|
49 delete iDatabase; |
|
50 iDatabase = NULL; |
|
51 delete iLandmarkSearch; |
|
52 iLandmarkSearch = NULL; |
|
53 |
|
54 iNearestSearchResults.ResetAndDestroy(); |
|
55 } |
|
56 |
|
57 // --------------------------------------------------------- |
|
58 // CPosTp35::StartL |
|
59 // |
|
60 // (other items were commented in a header). |
|
61 // --------------------------------------------------------- |
|
62 // |
|
63 void CPosTp35::StartL() |
|
64 { |
|
65 RemoveDefaultDbL(); |
|
66 RemoveAllLmDatabasesL(); |
|
67 iDatabase = UseNearestSearchGeneratedDbFileL(); |
|
68 |
|
69 if (iDatabase->IsInitializingNeeded()) |
|
70 { |
|
71 ExecuteAndDeleteLD(iDatabase->InitializeL()); |
|
72 } |
|
73 |
|
74 AppendNearestSearchResultsL(); |
|
75 iLandmarkSearch = CPosLandmarkSearch::NewL(*iDatabase); |
|
76 |
|
77 iLog->Log(_L("Testing search with criterias read from LmDbNearestResult.txt syncronously")); |
|
78 SearchL(); |
|
79 |
|
80 iLog->Log(_L("Testing search with criterias read from LmDbNearestResult.txt asyncronously")); |
|
81 SearchL(ETrue); |
|
82 |
|
83 iLog->Log(_L("Testing search and cancel")); |
|
84 SearchAndCancelL(); |
|
85 |
|
86 iLog->Log(_L("Testing search and cancel in callback")); |
|
87 SearchAndCancelL(ETrue); |
|
88 |
|
89 iLog->Log(_L("Testing search with a sortorder")); |
|
90 SearchWithSortOrderL(); |
|
91 |
|
92 iLog->Log(_L("Testing error codes")); |
|
93 _LIT(KStartCatErr, "StartCategorySearch should leave with KErrArgument with nearest criteria"); |
|
94 _LIT(KNaNErr, "Max distance should be NaN by default"); |
|
95 |
|
96 TCoordinate coord(12, 13); |
|
97 CPosLmNearestCriteria* nearestCriteria = CPosLmNearestCriteria::NewLC(coord); |
|
98 AssertTrueSecL(Math::IsNaN(nearestCriteria->MaxDistance()), KNaNErr); |
|
99 |
|
100 TRAPD(err, iLandmarkSearch->StartCategorySearchL(*nearestCriteria, CPosLmCategoryManager::ECategorySortOrderNone)); |
|
101 AssertTrueSecL(err == KErrArgument, KStartCatErr); |
|
102 |
|
103 CleanupStack::PopAndDestroy(nearestCriteria); |
|
104 |
|
105 TCoordinate pos(55, 18); |
|
106 nearestCriteria = CPosLmNearestCriteria::NewLC(pos, ETrue); |
|
107 nearestCriteria->SetMaxDistance(1); |
|
108 RunAsyncOperationLD(iLandmarkSearch->StartLandmarkSearchL(*nearestCriteria, EFalse)); |
|
109 |
|
110 _LIT(KReturned, "Returned no. of matches: %d"); |
|
111 TBuf<100> info; |
|
112 info.Format(KReturned, iLandmarkSearch->NumOfMatches()); |
|
113 iLog->Log(info); |
|
114 |
|
115 CleanupStack::PopAndDestroy(nearestCriteria); |
|
116 |
|
117 nearestCriteria = CPosLmNearestCriteria::NewLC(pos, ETrue); |
|
118 nearestCriteria->SetMaxDistance(300); |
|
119 RunAsyncOperationLD(iLandmarkSearch->StartLandmarkSearchL(*nearestCriteria, EFalse)); |
|
120 |
|
121 info.Format(KReturned, iLandmarkSearch->NumOfMatches()); |
|
122 iLog->Log(info); |
|
123 CleanupStack::PopAndDestroy(nearestCriteria); |
|
124 |
|
125 } |
|
126 |
|
127 // --------------------------------------------------------- |
|
128 // CPosTp35::UseNearestSearchGeneratedDbFileL |
|
129 // |
|
130 // (other items were commented in a header). |
|
131 // --------------------------------------------------------- |
|
132 // |
|
133 CPosLandmarkDatabase* CPosTp35::UseNearestSearchGeneratedDbFileL() |
|
134 { |
|
135 _LIT(KDbFile, "eposlmnearestsearch.ldb"); |
|
136 CopyTestDbFileL(KDbFile); |
|
137 |
|
138 CPosLmDatabaseManager* manager = CPosLmDatabaseManager::NewL(); |
|
139 CleanupStack::PushL(manager); |
|
140 // This db must exist |
|
141 manager->SetDefaultDatabaseUriL(KDbFile); |
|
142 CleanupStack::PopAndDestroy(manager); |
|
143 |
|
144 return CPosLandmarkDatabase::OpenL(KDbFile); |
|
145 } |
|
146 |
|
147 // --------------------------------------------------------- |
|
148 // CPosTp35::SearchL |
|
149 // |
|
150 // (other items were commented in a header). |
|
151 // --------------------------------------------------------- |
|
152 // |
|
153 void CPosTp35::SearchL(const TBool& aSync) |
|
154 { |
|
155 |
|
156 for(TInt i=0; i<iNearestSearchResults.Count(); i++) |
|
157 { |
|
158 TCoordinate coord(iNearestSearchResults[i]->iLatitude, iNearestSearchResults[i]->iLongitude); |
|
159 iLog->Log(_L("SearchL")); |
|
160 CPosLmNearestCriteria* nearestCriteria = CPosLmNearestCriteria::NewLC(coord, iNearestSearchResults[i]->iUseCoverageRadius); |
|
161 nearestCriteria->SetMaxDistance(iNearestSearchResults[i]->iMaxDistance); |
|
162 |
|
163 TBuf<100> pelle; |
|
164 pelle.Format(_L("StartSearchOperationL: Searching for Lat %f Long %f"), iNearestSearchResults[i]->iLatitude, iNearestSearchResults[i]->iLongitude); |
|
165 iLog->Log(pelle); |
|
166 |
|
167 if (iNearestSearchResults[i]->iMaxSearchResult > 0) |
|
168 { |
|
169 iLandmarkSearch->SetMaxNumOfMatches(iNearestSearchResults[i]->iMaxSearchResult); |
|
170 } |
|
171 else |
|
172 { |
|
173 iLandmarkSearch->SetMaxNumOfMatches(KPosLmMaxNumOfMatchesUnlimited); |
|
174 } |
|
175 |
|
176 if (aSync) |
|
177 { |
|
178 RunAsyncOperationLD(iLandmarkSearch->StartLandmarkSearchL(*nearestCriteria, iNearestSearchResults[i]->Redefined())); |
|
179 } |
|
180 else |
|
181 { |
|
182 ExecuteAndDeleteLD(iLandmarkSearch->StartLandmarkSearchL(*nearestCriteria, iNearestSearchResults[i]->Redefined())); |
|
183 } |
|
184 |
|
185 if (iNearestSearchResults[i]->Redefined() && i > 0) |
|
186 { |
|
187 iLog->Log(_L("Redefined")); |
|
188 |
|
189 for (TInt j=0; j<iNearestSearchResults[i]->iDistances.Count(); j++) |
|
190 { |
|
191 TBool found = EFalse; |
|
192 TInt id = 0; |
|
193 TPosLmItemId idde; |
|
194 |
|
195 id = j; |
|
196 idde = iNearestSearchResults[i]->iDistances[j].Id(); |
|
197 |
|
198 TBuf<100> debug; |
|
199 debug.Format(_L("Looking for id %d or id: %d "), idde, id); |
|
200 //iLog->Log(debug); |
|
201 |
|
202 for (TInt p=0;p<iNearestSearchResults[i-1]->iDistances.Count();p++) |
|
203 { |
|
204 |
|
205 if (iNearestSearchResults[i]->iDistances[j].Id() == iNearestSearchResults[i-1]->iDistances[p].Id()) |
|
206 { |
|
207 found = ETrue; |
|
208 TBuf<100> buf; |
|
209 buf.Format(_L("Found id %d or id: %d "), idde, id); |
|
210 //iLog->Log(buf); |
|
211 } |
|
212 } |
|
213 if (!found) |
|
214 { |
|
215 // Remove since not found, only keep ids that was found in previous search |
|
216 TBuf<100> buf; |
|
217 buf.Format(_L("Removing lm Id %d from index %d"), idde, id); |
|
218 //iLog->Log(buf); |
|
219 iNearestSearchResults[i]->iDistances.Remove(id); |
|
220 //iLog->Log(_L("Removing Done")); |
|
221 j--; |
|
222 } |
|
223 //iLog->Log(_L("***********")); |
|
224 } |
|
225 |
|
226 |
|
227 } |
|
228 |
|
229 CheckSearchResultL(*iNearestSearchResults[i]); |
|
230 |
|
231 CleanupStack::PopAndDestroy(nearestCriteria); |
|
232 } |
|
233 } |
|
234 |
|
235 // --------------------------------------------------------- |
|
236 // CPosTp35::CheckSearchResultL |
|
237 // |
|
238 // (other items were commented in a header). |
|
239 // --------------------------------------------------------- |
|
240 // |
|
241 |
|
242 //void CPosTp35::CheckSearchResultL(CNearestSearchResult& aSearchResult) |
|
243 void CPosTp35::CheckSearchResultL(CNearestSearchResultTp35& aSearchResult) |
|
244 { |
|
245 _LIT(KNumOfMatchesErr, "No. of matches is incorrect when the search is performed"); |
|
246 |
|
247 TUint expectedNoMatches = aSearchResult.iDistances.Count(); |
|
248 if (aSearchResult.iMaxSearchResult != 0 && aSearchResult.iMaxSearchResult < aSearchResult.iDistances.Count()) |
|
249 { |
|
250 expectedNoMatches = aSearchResult.iMaxSearchResult; |
|
251 } |
|
252 |
|
253 if (expectedNoMatches != iLandmarkSearch->NumOfMatches()) |
|
254 { |
|
255 _LIT(KExpected, "Expected no. of matches: %d"); |
|
256 _LIT(KReturned, "Returned no. of matches: %d"); |
|
257 TBuf<100> info; |
|
258 info.Format(KExpected, expectedNoMatches); |
|
259 iLog->Log(info); |
|
260 info.Format(KReturned, iLandmarkSearch->NumOfMatches()); |
|
261 iLog->Log(info); |
|
262 |
|
263 |
|
264 iLog->Log(KNumOfMatchesErr); |
|
265 User::Leave(-1); |
|
266 } |
|
267 |
|
268 CPosLmItemIterator* iter = iLandmarkSearch->MatchIteratorL(); |
|
269 CleanupStack::PushL(iter); |
|
270 |
|
271 TInt index=0; |
|
272 TPosLmItemId id = iter->NextL(); |
|
273 while (id != KPosLmNullItemId) |
|
274 { |
|
275 if (aSearchResult.iDistances[index].iId != id) |
|
276 { |
|
277 // if the distance is equal to the distance to the landmark |
|
278 // before or after then no error. |
|
279 // This to be able to use a databse with landmarks with the same position. |
|
280 |
|
281 TBool noError=EFalse; |
|
282 if (index > 0) |
|
283 { |
|
284 noError = (aSearchResult.iDistances[index-1].iDistance == aSearchResult.iDistances[index].iDistance); |
|
285 } |
|
286 if (index < aSearchResult.iDistances.Count() && !noError) |
|
287 { |
|
288 noError = (aSearchResult.iDistances[index+1].iDistance == aSearchResult.iDistances[index].iDistance); |
|
289 } |
|
290 if (!noError) |
|
291 { |
|
292 _LIT(KUnexpectedItemId, "Unexpected item id"); |
|
293 _LIT(KExpected, "Expected item id: %d"); |
|
294 _LIT(KReturned, "Returned item id: %d"); |
|
295 TBuf<100> info; |
|
296 info.Format(KExpected, aSearchResult.iDistances[index].iId); |
|
297 iLog->Log(info); |
|
298 info.Format(KReturned, id); |
|
299 iLog->Log(info); |
|
300 |
|
301 TBuf<800> info2; |
|
302 aSearchResult.Print(info2); |
|
303 iLog->Log(info2); |
|
304 |
|
305 |
|
306 iLog->Log(KUnexpectedItemId); |
|
307 User::Leave(-1); |
|
308 |
|
309 } |
|
310 } |
|
311 _LIT(KReturned, "Returned id: %d or id: %d"); |
|
312 TBuf<100> info; |
|
313 info.Format(KReturned, aSearchResult.iDistances[index].iId, id); |
|
314 //iLog->Log(info); |
|
315 |
|
316 id = iter->NextL(); |
|
317 index++; |
|
318 } |
|
319 |
|
320 CleanupStack::PopAndDestroy(iter); |
|
321 |
|
322 } |
|
323 |
|
324 // --------------------------------------------------------- |
|
325 // CPosTp35::SearchAndCancelL |
|
326 // |
|
327 // (other items were commented in a header). |
|
328 // --------------------------------------------------------- |
|
329 // |
|
330 void CPosTp35::SearchAndCancelL(const TBool& aInCallback) |
|
331 { |
|
332 _LIT(KNumOfMatchesErr, "No. of matches is incorrect when the search is performed"); |
|
333 |
|
334 // Test search with one criteria |
|
335 const TInt KIndex=0; |
|
336 |
|
337 TCoordinate coord(iNearestSearchResults[KIndex]->iLatitude, iNearestSearchResults[KIndex]->iLongitude); |
|
338 |
|
339 CPosLmNearestCriteria* nearestCriteria = CPosLmNearestCriteria::NewLC(coord, iNearestSearchResults[KIndex]->iUseCoverageRadius); |
|
340 |
|
341 iLandmarkSearch->SetMaxNumOfMatches(KPosLmMaxNumOfMatchesUnlimited); |
|
342 if (aInCallback) |
|
343 { |
|
344 RunAsyncOperationAndCancelInCallbackLD(iLandmarkSearch->StartLandmarkSearchL( |
|
345 *nearestCriteria, |
|
346 iNearestSearchResults[KIndex]->Redefined())); |
|
347 } |
|
348 else |
|
349 { |
|
350 RunAsyncOperationAndCancelLD(iLandmarkSearch->StartLandmarkSearchL( |
|
351 *nearestCriteria, |
|
352 iNearestSearchResults[KIndex]->Redefined())); |
|
353 } |
|
354 |
|
355 CPosLmItemIterator* iter = iLandmarkSearch->MatchIteratorL(); |
|
356 CleanupStack::PushL(iter); |
|
357 |
|
358 if (aInCallback) |
|
359 { |
|
360 if (iter->NumOfItemsL() != iLandmarkSearch->NumOfMatches()) |
|
361 { |
|
362 iLog->Log(_L("Iterators no. of items is not equal to LandmarksSearch no. matches")); |
|
363 _LIT(KExpected, "Iter. of matches: %d"); |
|
364 _LIT(KReturned, "LandmarksSearch no. of matches: %d"); |
|
365 TBuf<100> info; |
|
366 info.Format(KExpected, iter->NumOfItemsL()); |
|
367 iLog->Log(info); |
|
368 info.Format(KReturned, iLandmarkSearch->NumOfMatches()); |
|
369 iLog->Log(info); |
|
370 |
|
371 iLog->Log(KNumOfMatchesErr); |
|
372 User::Leave(-1); |
|
373 |
|
374 } |
|
375 |
|
376 TBuf<100> info2; |
|
377 _LIT(KNof, "No. of matches found before cancelled the operation = %d"); |
|
378 info2.Format(KNof, iter->NumOfItemsL()); |
|
379 iLog->Log(info2); |
|
380 |
|
381 // FrBo: No longer sure that result is returned when cancelling |
|
382 //AssertTrueSecL(iter->NumOfItemsL() != 0, KCancelErr); |
|
383 } |
|
384 |
|
385 CleanupStack::PopAndDestroy(2, nearestCriteria); |
|
386 |
|
387 } |
|
388 |
|
389 // --------------------------------------------------------- |
|
390 // CPosTp35::SearchWithSortOrderL |
|
391 // |
|
392 // (other items were commented in a header). |
|
393 // --------------------------------------------------------- |
|
394 // |
|
395 void CPosTp35::SearchWithSortOrderL() |
|
396 { |
|
397 // Only verifies that search does not fail when only landmarks with no name in the db |
|
398 |
|
399 _LIT(KNumOfMatchesErr, "No. of matches is incorrect when the search is performed with a sortorder"); |
|
400 |
|
401 // Test search with one criteria which return all landmarks in db |
|
402 const TInt KIndex=0; |
|
403 |
|
404 TCoordinate coord(iNearestSearchResults[KIndex]->iLatitude, iNearestSearchResults[KIndex]->iLongitude); |
|
405 |
|
406 CPosLmNearestCriteria* nearestCriteria = CPosLmNearestCriteria::NewLC(coord, iNearestSearchResults[KIndex]->iUseCoverageRadius); |
|
407 TPosLmSortPref sortPref(CPosLandmark::ELandmarkName, TPosLmSortPref::EAscending); |
|
408 |
|
409 iLandmarkSearch->SetMaxNumOfMatches(KPosLmMaxNumOfMatchesUnlimited); |
|
410 |
|
411 for (TInt i=0; i<4; i++) |
|
412 { |
|
413 if(i==0) |
|
414 { |
|
415 ExecuteAndDeleteLD(iLandmarkSearch->StartLandmarkSearchL( |
|
416 *nearestCriteria, |
|
417 sortPref, |
|
418 iNearestSearchResults[KIndex]->Redefined())); |
|
419 } |
|
420 else if (i==1) |
|
421 { |
|
422 sortPref.SetSortByLandmarkAttribute(CPosLandmark::ELandmarkName, TPosLmSortPref::EDescending); |
|
423 ExecuteAndDeleteLD(iLandmarkSearch->StartLandmarkSearchL( |
|
424 *nearestCriteria, |
|
425 sortPref, |
|
426 iNearestSearchResults[KIndex]->Redefined())); |
|
427 } |
|
428 //**** async |
|
429 else if (i==2) |
|
430 { |
|
431 RunAsyncOperationLD(iLandmarkSearch->StartLandmarkSearchL( |
|
432 *nearestCriteria, |
|
433 sortPref, |
|
434 iNearestSearchResults[KIndex]->Redefined())); |
|
435 } |
|
436 else if (i==3) |
|
437 { |
|
438 sortPref.SetSortByLandmarkAttribute(CPosLandmark::ELandmarkName, TPosLmSortPref::EAscending); |
|
439 |
|
440 RunAsyncOperationLD(iLandmarkSearch->StartLandmarkSearchL( |
|
441 *nearestCriteria, |
|
442 sortPref, |
|
443 iNearestSearchResults[KIndex]->Redefined())); |
|
444 } |
|
445 AssertTrueSecL((TUint)iNearestSearchResults[KIndex]->iDistances.Count()== iLandmarkSearch->NumOfMatches(), KNumOfMatchesErr); |
|
446 } |
|
447 |
|
448 CleanupStack::PopAndDestroy(nearestCriteria); |
|
449 } |
|
450 |
|
451 // --------------------------------------------------------- |
|
452 // CPosTp35::AppendAreaSearchResultsL() |
|
453 // |
|
454 // (other items were commented in a header). |
|
455 // --------------------------------------------------------- |
|
456 void CPosTp35::AppendNearestSearchResultsL() |
|
457 { |
|
458 iNearestSearchResults.ResetAndDestroy(); |
|
459 |
|
460 _LIT(KFileTestValues, "c:\\system\\test\\testdata\\lmDbNearestSearchResult.txt"); |
|
461 |
|
462 RFile file; |
|
463 CleanupClosePushL(file); |
|
464 User::LeaveIfError(file.Open(iFileSession, KFileTestValues, EFileRead)); |
|
465 |
|
466 TInt row=0; |
|
467 TBuf<KMaxNearestLineLength> line; |
|
468 while (ReadLn(file, line) != KErrEof) |
|
469 { |
|
470 TLex lex(line); |
|
471 if (lex.Peek() != '#' && lex.Peek() != '\t') |
|
472 { |
|
473 ++row; |
|
474 //CNearestSearchResult* searchResult = CNearestSearchResult::NewL(line, row); |
|
475 CNearestSearchResultTp35* searchResult = CNearestSearchResultTp35::NewL(line, row, iFileSession); |
|
476 CleanupStack::PushL(searchResult); |
|
477 |
|
478 User::LeaveIfError(iNearestSearchResults.Append(searchResult)); |
|
479 CleanupStack::Pop(searchResult); |
|
480 |
|
481 } |
|
482 } |
|
483 CleanupStack::PopAndDestroy(&file); |
|
484 } |
|
485 |
|
486 // --------------------------------------------------------- |
|
487 // CNearestSearchResult::NewL() |
|
488 // |
|
489 // (other items were commented in a header). |
|
490 // --------------------------------------------------------- |
|
491 //CNearestSearchResult* CNearestSearchResult::NewL(const TDesC& aDes, const TInt& aIndex) |
|
492 CNearestSearchResultTp35* CNearestSearchResultTp35::NewL( |
|
493 const TDesC& aDes, |
|
494 const TInt& aIndex, |
|
495 RFs& aFileSession) |
|
496 { |
|
497 CNearestSearchResultTp35* self = new(ELeave) CNearestSearchResultTp35( aFileSession ); |
|
498 CleanupStack::PushL(self); |
|
499 self->ConstructL(aDes, aIndex); |
|
500 CleanupStack::Pop(); |
|
501 return self; |
|
502 } |
|
503 |
|
504 // C++ default constructor can NOT contain any code, that |
|
505 // might leave. |
|
506 // |
|
507 |
|
508 CNearestSearchResultTp35::CNearestSearchResultTp35(RFs& aFileSession) |
|
509 : iFileSession( aFileSession ) |
|
510 { |
|
511 TRealX nan; |
|
512 nan.SetNaN(); |
|
513 iMaxDistance = nan; |
|
514 } |
|
515 |
|
516 // --------------------------------------------------------- |
|
517 // CNearestSearchResult::CounstructL() |
|
518 // |
|
519 // (other items were commented in a header). |
|
520 // --------------------------------------------------------- |
|
521 void CNearestSearchResultTp35::ConstructL(const TDesC& aDes, const TInt& aIndex) |
|
522 { |
|
523 iDatabase = CPosLandmarkDatabase::OpenL(); |
|
524 |
|
525 TLex line(aDes); |
|
526 line.Mark(); |
|
527 TInt redefined=0, useCoverageRadius; |
|
528 |
|
529 if (line.Peek() != '#' && line.Peek() != '\t') |
|
530 { |
|
531 TInt index=0; |
|
532 while (line.Peek() != '\n' && !(line.Peek()).Eos()) |
|
533 { |
|
534 line.Inc(); |
|
535 if (line.Peek() == '\t') |
|
536 { |
|
537 TPtrC token = line.MarkedToken(); |
|
538 TLex val(token); |
|
539 switch(index) |
|
540 { |
|
541 case ELatitude: |
|
542 val.Val(iLatitude, TChar(',')); |
|
543 break; |
|
544 case ELongitude: |
|
545 val.Val(iLongitude, TChar(',')); |
|
546 break; |
|
547 case EUseCoverageRadius: |
|
548 val.Val(useCoverageRadius); |
|
549 if (useCoverageRadius == 1) |
|
550 { |
|
551 iUseCoverageRadius = ETrue; |
|
552 } |
|
553 break; |
|
554 case EMaxDistance: |
|
555 val.Val(iMaxDistance); |
|
556 break; |
|
557 case EErrorCode: |
|
558 val.Val(iErrorCode); |
|
559 break; |
|
560 case ESearchResult: |
|
561 ParseSearchResult(token); |
|
562 break; |
|
563 case ERedefined: |
|
564 val.Val(redefined); |
|
565 if (redefined == 1) |
|
566 { |
|
567 iRedefined = ETrue; |
|
568 } |
|
569 break; |
|
570 case EMaxSearchResult: |
|
571 val.Val(iMaxSearchResult); |
|
572 break; |
|
573 } |
|
574 line.Inc(); |
|
575 while (line.Peek() == '\t') // Empty value |
|
576 { |
|
577 line.Inc(); |
|
578 ++index; |
|
579 } |
|
580 line.Mark(); |
|
581 ++index; |
|
582 } |
|
583 } |
|
584 AppendDistancesL(aIndex); |
|
585 |
|
586 } |
|
587 } |
|
588 |
|
589 |
|
590 // Destructor |
|
591 |
|
592 CNearestSearchResultTp35::~CNearestSearchResultTp35() |
|
593 { |
|
594 iDistances.Close(); |
|
595 delete iDatabase; |
|
596 iDatabase = NULL; |
|
597 } |
|
598 |
|
599 // --------------------------------------------------------- |
|
600 // CNearestSearchResult::AppendDistancesL() |
|
601 // |
|
602 // (other items were commented in a header). |
|
603 // --------------------------------------------------------- |
|
604 void CNearestSearchResultTp35::AppendDistancesL(const TInt& aIndex) |
|
605 { |
|
606 iDistances.Reset(); |
|
607 |
|
608 _LIT(KFileTestValues, "c:\\system\\test\\testdata\\lmDbNearestSearch.txt"); |
|
609 |
|
610 RFile file; |
|
611 CleanupClosePushL(file); |
|
612 User::LeaveIfError(file.Open(iFileSession, KFileTestValues, EFileRead)); |
|
613 |
|
614 TInt row=0; |
|
615 TBuf<KMaxNearestLineLength> line; |
|
616 while (CLandmarkTestProcedureBase::ReadLn(file, line) != KErrEof) |
|
617 { |
|
618 ParseDistanceL(line, aIndex, row); |
|
619 ++row; |
|
620 } |
|
621 |
|
622 SortDistances(); |
|
623 |
|
624 CleanupStack::PopAndDestroy(&file); |
|
625 } |
|
626 |
|
627 // --------------------------------------------------------- |
|
628 // CNearestSearchResult::ParseDistancesL() |
|
629 // |
|
630 // (other items were commented in a header). |
|
631 // --------------------------------------------------------- |
|
632 void CNearestSearchResultTp35::ParseDistanceL(const TDesC& aDes, |
|
633 const TInt& aIndex, |
|
634 const TPosLmItemId& aId) |
|
635 { |
|
636 |
|
637 const TInt KStartIndex = 5; |
|
638 |
|
639 TLex line(aDes); |
|
640 line.Mark(); |
|
641 TInt index = 0; |
|
642 TReal64 dist=0; |
|
643 |
|
644 if (line.Peek() != '#' && line.Peek() != '\t') |
|
645 { |
|
646 while (line.Peek() != '\n' && !(line.Peek()).Eos()) |
|
647 { |
|
648 line.Inc(); |
|
649 if (line.Peek() == '\t' || line.Peek() == '\n' || (line.Peek()).Eos()) |
|
650 { |
|
651 TPtrC token = line.MarkedToken(); |
|
652 |
|
653 if (index == (KStartIndex + aIndex)) |
|
654 { |
|
655 TLex val(token); |
|
656 val.Val(dist, TChar(',')); |
|
657 |
|
658 if (iUseCoverageRadius) |
|
659 { |
|
660 CPosLandmark* lm = iDatabase->ReadLandmarkLC(aId); |
|
661 |
|
662 TReal32 aCoverageRadius; |
|
663 if (lm->GetCoverageRadius(aCoverageRadius) == KErrNone) |
|
664 { |
|
665 dist -= aCoverageRadius; |
|
666 if (dist < 0) |
|
667 { |
|
668 dist = 0; |
|
669 } |
|
670 } |
|
671 CleanupStack::PopAndDestroy(lm); |
|
672 } |
|
673 |
|
674 if (Math::IsNaN(iMaxDistance) || dist <= iMaxDistance) |
|
675 { |
|
676 if (dist != -1) |
|
677 { |
|
678 TSearchResultTp35 searchResult(aId, TReal32(dist)); |
|
679 iDistances.Append(searchResult); |
|
680 } |
|
681 } |
|
682 |
|
683 break; |
|
684 } |
|
685 line.Inc(); |
|
686 while (line.Peek() == '\t') // Empty value |
|
687 { |
|
688 line.Inc(); |
|
689 ++index; |
|
690 } |
|
691 line.Mark(); |
|
692 ++index; |
|
693 } |
|
694 } |
|
695 } |
|
696 } |
|
697 // --------------------------------------------------------- |
|
698 // CNearestSearchResult::Latitude |
|
699 // |
|
700 // (other items were commented in a header). |
|
701 // --------------------------------------------------------- |
|
702 // |
|
703 //TReal64 CNearestSearchResult::Latitude() const |
|
704 TReal64 CNearestSearchResultTp35::Latitude() const |
|
705 { |
|
706 return iLatitude; |
|
707 } |
|
708 |
|
709 // --------------------------------------------------------- |
|
710 // CNearestSearchResult::Latitude |
|
711 // |
|
712 // (other items were commented in a header). |
|
713 // --------------------------------------------------------- |
|
714 // |
|
715 //TReal64 CNearestSearchResult::Longitude() const |
|
716 TReal64 CNearestSearchResultTp35::Longitude() const |
|
717 { |
|
718 return iLongitude; |
|
719 } |
|
720 |
|
721 // --------------------------------------------------------- |
|
722 // CNearestSearchResult::UseCoverageRadius |
|
723 // |
|
724 // (other items were commented in a header). |
|
725 // --------------------------------------------------------- |
|
726 // |
|
727 //TBool CNearestSearchResult::UseCoverageRadius() const |
|
728 TBool CNearestSearchResultTp35::UseCoverageRadius() const |
|
729 { |
|
730 return iUseCoverageRadius; |
|
731 } |
|
732 |
|
733 // --------------------------------------------------------- |
|
734 // CNearestSearchResult::MaxDistance |
|
735 // |
|
736 // (other items were commented in a header). |
|
737 // --------------------------------------------------------- |
|
738 // |
|
739 |
|
740 TReal32 CNearestSearchResultTp35::MaxDistance() const |
|
741 { |
|
742 return iMaxDistance; |
|
743 } |
|
744 |
|
745 // --------------------------------------------------------- |
|
746 // CNearestSearchResult::ErrorCode |
|
747 // |
|
748 // (other items were commented in a header). |
|
749 // --------------------------------------------------------- |
|
750 // |
|
751 //TInt CNearestSearchResult::ErrorCode() const |
|
752 TInt CNearestSearchResultTp35::ErrorCode() const |
|
753 { |
|
754 return iErrorCode; |
|
755 } |
|
756 |
|
757 // --------------------------------------------------------- |
|
758 // InternalLandmarksSortL |
|
759 // |
|
760 // (other items were commented in a header). |
|
761 // --------------------------------------------------------- |
|
762 // |
|
763 TInt InternalSort(const TSearchResultTp35& aSource, const TSearchResultTp35& aTarget) |
|
764 { |
|
765 // zero, if the two objects are equal |
|
766 // a negative value, if the first object is less than the second. |
|
767 // a positive value, if the first object is greater than the second. |
|
768 |
|
769 if ( aSource.Distance() == aTarget.Distance()) |
|
770 { |
|
771 return 0; |
|
772 } |
|
773 else if (aSource.Distance() < aTarget.Distance()) |
|
774 { |
|
775 return -1; |
|
776 } |
|
777 |
|
778 return 1; |
|
779 } |
|
780 |
|
781 // --------------------------------------------------------- |
|
782 // CNearestSearchResult::ErrorCode |
|
783 // |
|
784 // (other items were commented in a header). |
|
785 // --------------------------------------------------------- |
|
786 // |
|
787 void CNearestSearchResultTp35::SortDistances() |
|
788 { |
|
789 TLinearOrder<TSearchResultTp35> order(InternalSort); |
|
790 iDistances.Sort(order); |
|
791 } |
|
792 |
|
793 // --------------------------------------------------------- |
|
794 // CNearestSearchResult::Print |
|
795 // |
|
796 // (other items were commented in a header). |
|
797 // --------------------------------------------------------- |
|
798 // |
|
799 void CNearestSearchResultTp35::Print(TDes& aPrint) |
|
800 { |
|
801 _LIT(KPosInfo, "Latitude=%g, Longitude=%g"); |
|
802 TChar del(','); |
|
803 |
|
804 TBuf<KMaxFieldLength> info; |
|
805 info.Format(KPosInfo, iLatitude, iLongitude); |
|
806 aPrint.Append(info); |
|
807 aPrint.Append(del); |
|
808 |
|
809 _LIT(KUseCoverageRadius, "UseCoverageRadius=%d"); |
|
810 info.Format(KUseCoverageRadius, iUseCoverageRadius); |
|
811 aPrint.Append(info); |
|
812 aPrint.Append(del); |
|
813 |
|
814 if (!Math::IsNaN(iMaxDistance)) |
|
815 { |
|
816 _LIT(KMaxDistance, "MaxDistance=%g"); |
|
817 info.Format(KMaxDistance, iMaxDistance); |
|
818 aPrint.Append(info); |
|
819 aPrint.Append(del); |
|
820 } |
|
821 |
|
822 _LIT(KErrorCode, "ErrorCode = %d"); |
|
823 info.Format(KErrorCode, iErrorCode); |
|
824 aPrint.Append(info); |
|
825 aPrint.Append(del); |
|
826 |
|
827 _LIT(KRedefined, "Redefined=%d"); |
|
828 info.Format(KRedefined, iRedefined); |
|
829 aPrint.Append(info); |
|
830 aPrint.Append(del); |
|
831 |
|
832 _LIT(KMaxSearchResult, "MaxSearchResult=%d"); |
|
833 info.Format(KMaxSearchResult, iMaxSearchResult); |
|
834 aPrint.Append(info); |
|
835 aPrint.Append(del); |
|
836 |
|
837 PrintDistances(aPrint); |
|
838 } |
|
839 |
|
840 // --------------------------------------------------------- |
|
841 // CNearestSearchResult::PrintDistances |
|
842 // |
|
843 // (other items were commented in a header). |
|
844 // --------------------------------------------------------- |
|
845 // |
|
846 void CNearestSearchResultTp35::PrintDistances(TDes& aPrint) |
|
847 { |
|
848 TBuf<KDistanceFieldLength> info2; |
|
849 TChar del(':'); |
|
850 aPrint.Append(_L("Distances: ")); |
|
851 |
|
852 for (TInt j=0; j<iDistances.Count(); j++) |
|
853 { |
|
854 _LIT(KDistance, "%g,%d"); |
|
855 info2.Format(KDistance, iDistances[j].Distance(), iDistances[j].Id()); |
|
856 aPrint.Append(info2); |
|
857 aPrint.Append(del); |
|
858 } |
|
859 } |
|
860 |
|
861 // --------------------------------------------------------- |
|
862 // TSearchResult::TSearchResult |
|
863 // |
|
864 // (other items were commented in a header). |
|
865 // --------------------------------------------------------- |
|
866 // |
|
867 TSearchResultTp35::TSearchResultTp35() |
|
868 { |
|
869 TRealX nan; |
|
870 nan.SetNaN(); |
|
871 iDistance=nan; |
|
872 iId=0; |
|
873 } |
|
874 |
|
875 TSearchResultTp35::TSearchResultTp35(const TPosLmItemId& aId, const TReal32& aDistance) : |
|
876 iDistance(aDistance), |
|
877 iId(aId) |
|
878 { |
|
879 } |
|
880 |
|
881 // --------------------------------------------------------- |
|
882 // TSearchResult::Distance |
|
883 // |
|
884 // (other items were commented in a header). |
|
885 // --------------------------------------------------------- |
|
886 // |
|
887 TReal64 TSearchResultTp35::Distance() const |
|
888 { |
|
889 return iDistance; |
|
890 } |
|
891 |
|
892 // --------------------------------------------------------- |
|
893 // TSearchResult::Id |
|
894 // |
|
895 // (other items were commented in a header). |
|
896 // --------------------------------------------------------- |
|
897 // |
|
898 TPosLmItemId TSearchResultTp35::Id() const |
|
899 { |
|
900 return iId; |
|
901 } |
|
902 |
|
903 // End of File |