|
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_CPosTp24.h" |
|
23 #include <EPos_CPosLandmarkDatabase.h> |
|
24 #include <EPos_CPosLandmark.h> |
|
25 #include <EPos_CPosLandmarkSearch.h> |
|
26 #include <EPos_CPosLmAreaCriteria.h> |
|
27 #include <EPos_CPosLMItemIterator.h> |
|
28 |
|
29 // ================= MEMBER FUNCTIONS ======================= |
|
30 |
|
31 |
|
32 // --------------------------------------------------------- |
|
33 // CPosTp24::CloseTest |
|
34 // |
|
35 // (other items were commented in a header). |
|
36 // --------------------------------------------------------- |
|
37 // |
|
38 void CPosTp24::CloseTest() |
|
39 { |
|
40 iLog->Log(_L("CloseTest")); |
|
41 delete iDatabase; |
|
42 iDatabase = NULL; |
|
43 delete iLandmarkSearch; |
|
44 iLandmarkSearch = NULL; |
|
45 iAreaSearchResults.ResetAndDestroy(); |
|
46 delete iOperation;iOperation=NULL; |
|
47 } |
|
48 |
|
49 // --------------------------------------------------------- |
|
50 // CPosTp24::StartL |
|
51 // |
|
52 // (other items were commented in a header). |
|
53 // --------------------------------------------------------- |
|
54 // |
|
55 void CPosTp24::StartL() |
|
56 { |
|
57 iDatabase = UseGeneratedDbFileL(); |
|
58 |
|
59 if (iDatabase->IsInitializingNeeded()) |
|
60 { |
|
61 ExecuteAndDeleteLD(iDatabase->InitializeL()); |
|
62 } |
|
63 iLandmarkSearch = CPosLandmarkSearch::NewL(*iDatabase); |
|
64 |
|
65 AppendAreaSearchResultsL(); |
|
66 |
|
67 // Invalid areas is tested (see LmDbAreaSearchResult.txt) |
|
68 iLog->Log(_L("Testing area search with criterias read from LmDbAreaSearchResult.txt syncronously")); |
|
69 SearchL(ESynchronous); |
|
70 |
|
71 iLog->Log(_L("Testing area search with criterias read from LmDbAreaSearchResult.txt asyncronously")); |
|
72 SearchL(EAsynchronous); |
|
73 |
|
74 iLog->Log(_L("Testing area search with criterias read from LmDbAreaSearchResult.txt asyncronously with User::WaitForRequest()")); |
|
75 SearchL(EWaitForRequest); |
|
76 |
|
77 iLog->Log(_L("Testing area search with a defined sortorder")); |
|
78 SearchWithSortOrderL(); |
|
79 |
|
80 iLog->Log(_L("Testing area search and cancel")); |
|
81 SearchAndCancelL(); |
|
82 iLog->Log(_L("Testing area search and cancel in callback")); |
|
83 SearchAndCancelL(ETrue); |
|
84 } |
|
85 |
|
86 // --------------------------------------------------------- |
|
87 // CPosTp24::SearchL |
|
88 // |
|
89 // (other items were commented in a header). |
|
90 // --------------------------------------------------------- |
|
91 // |
|
92 void CPosTp24::SearchL(TExecutionMode aExecutionMode) |
|
93 { |
|
94 TBuf<255> info; |
|
95 for (TInt i=0; i<iAreaSearchResults.Count(); i++) |
|
96 { |
|
97 CPosLmAreaCriteria* areaCriteria=NULL; |
|
98 TRAPD(err, areaCriteria = CPosTp24::NewLmAreaCriteriaL(iAreaSearchResults[i]->SouthLat(), |
|
99 iAreaSearchResults[i]->NorthLat(), |
|
100 iAreaSearchResults[i]->WestLong(), |
|
101 iAreaSearchResults[i]->EastLong() |
|
102 )); |
|
103 CleanupStack::PushL(areaCriteria); |
|
104 if (err != iAreaSearchResults[i]->ErrorCode()) |
|
105 { |
|
106 iLog->Log(_L("Unexpected error code returned")); |
|
107 iLog->Log(_L("Area Search result read from file:")); |
|
108 |
|
109 iAreaSearchResults[i]->Print(info); |
|
110 iLog->Log(info); |
|
111 |
|
112 _LIT(KReturned, "Search returned errorCode = %d"); |
|
113 info.Format(KReturned, err); |
|
114 iLog->Log(info); |
|
115 User::Leave(KErrGeneral); |
|
116 } |
|
117 |
|
118 if (!err) |
|
119 { |
|
120 iOperation = iLandmarkSearch->StartLandmarkSearchL( |
|
121 *areaCriteria, iAreaSearchResults[i]->Redefined()); |
|
122 switch (aExecutionMode) |
|
123 { |
|
124 case ESynchronous: |
|
125 ExecuteAndDeleteLD(iOperation); |
|
126 iOperation = NULL; |
|
127 break; |
|
128 case EAsynchronous: |
|
129 RunAsyncOperationLD(iOperation); |
|
130 iOperation = NULL; |
|
131 break; |
|
132 case EWaitForRequest: |
|
133 RunAsyncOperationByWaitForReqL(iOperation); |
|
134 delete iOperation;iOperation=NULL; |
|
135 break; |
|
136 } |
|
137 |
|
138 CPosLmItemIterator* iter = iLandmarkSearch->MatchIteratorL(); |
|
139 CleanupStack::PushL(iter); |
|
140 |
|
141 if ((TUint)(iAreaSearchResults[i]->SearchResult()).Count() != iLandmarkSearch->NumOfMatches()) |
|
142 { |
|
143 iLog->Log(_L("Unexpected no. of matches returned")); |
|
144 _LIT(KExpected, "Expected no. of matches: %d "); |
|
145 _LIT(KReturned, "Returned no. of matches: %d "); |
|
146 info.Format(KExpected, (iAreaSearchResults[i]->SearchResult()).Count()); |
|
147 iLog->Log(info); |
|
148 info.Format(KReturned, iLandmarkSearch->NumOfMatches()); |
|
149 iLog->Log(info); |
|
150 iLog->Log(_L("Area Search result read from file:")); |
|
151 info.Zero(); |
|
152 iAreaSearchResults[i]->Print(info); |
|
153 iLog->Log(info); |
|
154 |
|
155 iLog->Log(_L("Landmarks expected to find:")); |
|
156 for (TInt j=0; j<iAreaSearchResults[i]->SearchResult().Count(); j++) |
|
157 { |
|
158 RArray<TPosLmItemId>* searchResults = &iAreaSearchResults[i]->SearchResult(); |
|
159 CPosLandmark* lm = iDatabase->ReadLandmarkLC((*searchResults)[j]); |
|
160 info.Zero(); |
|
161 PrintLandmark(*lm, info); |
|
162 iLog->Log(info); |
|
163 CleanupStack::PopAndDestroy(lm); |
|
164 } |
|
165 |
|
166 iLog->Log(_L("Landmarks returned by Area search:")); |
|
167 TPosLmItemId id = iter->NextL(); |
|
168 while (id != KPosLmNullItemId) |
|
169 { |
|
170 CPosLandmark* lm2 = iDatabase->ReadLandmarkLC(id); |
|
171 info.Zero(); |
|
172 PrintLandmark(*lm2, info); |
|
173 iLog->Log(info); |
|
174 CleanupStack::PopAndDestroy(lm2); |
|
175 id = iter->NextL(); |
|
176 } |
|
177 |
|
178 User::Leave(KErrGeneral); |
|
179 } |
|
180 |
|
181 TPosLmItemId id = iter->NextL(); |
|
182 while (id != KPosLmNullItemId) |
|
183 { |
|
184 if (!iAreaSearchResults[i]->FindSearchResult(id)) |
|
185 { |
|
186 _LIT(KUnexpectedId, "Unexpected id, %d returned from search which is not in read area search result"); |
|
187 info.Format(KUnexpectedId, id); |
|
188 iLog->Log(_L("Area Search result read from file:")); |
|
189 iAreaSearchResults[i]->Print(info); |
|
190 iLog->Log(info); |
|
191 User::Leave(KErrGeneral); |
|
192 } |
|
193 id = iter->NextL(); |
|
194 } |
|
195 CleanupStack::PopAndDestroy(iter); |
|
196 } |
|
197 CleanupStack::PopAndDestroy(areaCriteria); |
|
198 } |
|
199 } |
|
200 |
|
201 // --------------------------------------------------------- |
|
202 // CPosTp24::SearchWithSortOrderL |
|
203 // |
|
204 // (other items were commented in a header). |
|
205 // --------------------------------------------------------- |
|
206 // |
|
207 void CPosTp24::SearchWithSortOrderL() |
|
208 { |
|
209 const TInt KSortOrderIndex=4; |
|
210 _LIT(KNumOfMatchesErr, "No. of matches is incorrect"); |
|
211 _LIT(KSortorderErr, "The sortorder is incorrect"); |
|
212 |
|
213 TPosLmSortPref sortPref(CPosLandmark::ELandmarkName, TPosLmSortPref::EAscending); |
|
214 |
|
215 CPosLmAreaCriteria* areaCriteria=CPosLmAreaCriteria::NewLC( |
|
216 iAreaSearchResults[KSortOrderIndex]->SouthLat(), |
|
217 iAreaSearchResults[KSortOrderIndex]->NorthLat(), |
|
218 iAreaSearchResults[KSortOrderIndex]->WestLong(), |
|
219 iAreaSearchResults[KSortOrderIndex]->EastLong() |
|
220 ); |
|
221 |
|
222 // Test SetSearchArea |
|
223 areaCriteria->SetSearchArea(iAreaSearchResults[KSortOrderIndex]->SouthLat(), |
|
224 iAreaSearchResults[KSortOrderIndex]->NorthLat(), |
|
225 iAreaSearchResults[KSortOrderIndex]->WestLong(), |
|
226 iAreaSearchResults[KSortOrderIndex]->EastLong()); |
|
227 |
|
228 |
|
229 TReal64 southLat; |
|
230 TReal64 northLat; |
|
231 TReal64 westLong; |
|
232 TReal64 eastLong; |
|
233 areaCriteria->GetSearchArea(southLat, northLat, westLong, eastLong); |
|
234 AssertTrueSecL(southLat == iAreaSearchResults[KSortOrderIndex]->SouthLat(), _L("SouthLat is wrong")); |
|
235 AssertTrueSecL(northLat == iAreaSearchResults[KSortOrderIndex]->NorthLat(), _L("NorthLat is wrong")); |
|
236 AssertTrueSecL(westLong == iAreaSearchResults[KSortOrderIndex]->WestLong(), _L("WestLong is wrong")); |
|
237 AssertTrueSecL(eastLong == iAreaSearchResults[KSortOrderIndex]->EastLong(), _L("EastLong is wrong")); |
|
238 |
|
239 |
|
240 for (TInt i=0; i<6; i++) |
|
241 { |
|
242 if(i==0) |
|
243 { |
|
244 iOperation = iLandmarkSearch->StartLandmarkSearchL(*areaCriteria, sortPref); |
|
245 ExecuteAndDeleteLD(iOperation); |
|
246 } |
|
247 else if (i==1) |
|
248 { |
|
249 sortPref.SetSortByLandmarkAttribute(CPosLandmark::ELandmarkName, TPosLmSortPref::EDescending); |
|
250 iOperation = iLandmarkSearch->StartLandmarkSearchL(*areaCriteria, sortPref); |
|
251 ExecuteAndDeleteLD(iOperation); |
|
252 } |
|
253 else if (i==2) |
|
254 { |
|
255 iOperation = iLandmarkSearch->StartLandmarkSearchL(*areaCriteria, sortPref); |
|
256 RunAsyncOperationLD(iOperation); |
|
257 } |
|
258 else if (i==3) |
|
259 { |
|
260 sortPref.SetSortByLandmarkAttribute(CPosLandmark::ELandmarkName, TPosLmSortPref::EAscending); |
|
261 iOperation = iLandmarkSearch->StartLandmarkSearchL(*areaCriteria, sortPref); |
|
262 RunAsyncOperationLD(iOperation); |
|
263 } |
|
264 else if (i==4) |
|
265 { |
|
266 iOperation = iLandmarkSearch->StartLandmarkSearchL(*areaCriteria, sortPref); |
|
267 RunAsyncOperationByWaitForReqL(iOperation); |
|
268 delete iOperation;iOperation=NULL; |
|
269 } |
|
270 else if (i==5) |
|
271 { |
|
272 sortPref.SetSortByLandmarkAttribute(CPosLandmark::ELandmarkName, TPosLmSortPref::EAscending); |
|
273 iOperation = iLandmarkSearch->StartLandmarkSearchL(*areaCriteria, sortPref); |
|
274 RunAsyncOperationByWaitForReqL(iOperation); |
|
275 delete iOperation;iOperation=NULL; |
|
276 } |
|
277 iOperation = NULL; |
|
278 CPosLmItemIterator* iter = iLandmarkSearch->MatchIteratorL(); |
|
279 CleanupStack::PushL(iter); |
|
280 |
|
281 RArray<TPosLmItemId>* searchResults = &iAreaSearchResults[KSortOrderIndex]->SearchResult(); |
|
282 AssertTrueSecL((TUint)searchResults->Count() == iLandmarkSearch->NumOfMatches(), KNumOfMatchesErr); |
|
283 |
|
284 LandmarksSortL(*searchResults, sortPref); |
|
285 |
|
286 TInt ii=0; |
|
287 TPosLmItemId id = iter->NextL(); |
|
288 while (id != KPosLmNullItemId) |
|
289 { |
|
290 AssertTrueSecL(id == (*searchResults)[ii], KSortorderErr, id); |
|
291 |
|
292 id = iter->NextL(); |
|
293 ++ii; |
|
294 } |
|
295 CleanupStack::PopAndDestroy(iter); |
|
296 } |
|
297 |
|
298 CleanupStack::PopAndDestroy(areaCriteria); |
|
299 } |
|
300 |
|
301 // --------------------------------------------------------- |
|
302 // CPosTp24::NewLmAreaCriteriaL |
|
303 // |
|
304 // (other items were commented in a header). |
|
305 // --------------------------------------------------------- |
|
306 // |
|
307 CPosLmAreaCriteria* CPosTp24::NewLmAreaCriteriaL(const TReal64 &aSouthLat, |
|
308 const TReal64 &aNorthLat, |
|
309 const TReal64 &aWestLong, |
|
310 const TReal64 &aEastLong) |
|
311 { |
|
312 CPosLmAreaCriteria* areaCriteria = CPosLmAreaCriteria::NewLC(aSouthLat, |
|
313 aNorthLat, |
|
314 aWestLong, |
|
315 aEastLong |
|
316 ); |
|
317 CleanupStack::Pop(); |
|
318 return areaCriteria; |
|
319 } |
|
320 |
|
321 // --------------------------------------------------------- |
|
322 // CPosTp24::SearchAndCancelL |
|
323 // |
|
324 // (other items were commented in a header). |
|
325 // --------------------------------------------------------- |
|
326 // |
|
327 void CPosTp24::SearchAndCancelL(const TBool& aInCallback) |
|
328 { |
|
329 _LIT(KNumOfMatchesErr, "No. of matches is incorrect when the search is performed"); |
|
330 _LIT(KCancelErr, "The search is canceled after progress has increased but no search result is found"); |
|
331 |
|
332 // Test search with one criteria |
|
333 const TInt KIndex=0; |
|
334 |
|
335 CPosLmAreaCriteria* areaCriteria=NULL; |
|
336 areaCriteria = CPosLmAreaCriteria::NewLC(iAreaSearchResults[KIndex]->SouthLat(), |
|
337 iAreaSearchResults[KIndex]->NorthLat(), |
|
338 iAreaSearchResults[KIndex]->WestLong(), |
|
339 iAreaSearchResults[KIndex]->EastLong() |
|
340 ); |
|
341 |
|
342 if (aInCallback) |
|
343 { |
|
344 RunAsyncOperationAndCancelInCallbackLD(iLandmarkSearch->StartLandmarkSearchL( |
|
345 *areaCriteria, iAreaSearchResults[KIndex]->Redefined())); |
|
346 } |
|
347 else |
|
348 { |
|
349 RunAsyncOperationAndCancelLD(iLandmarkSearch->StartLandmarkSearchL( |
|
350 *areaCriteria, iAreaSearchResults[KIndex]->Redefined())); |
|
351 } |
|
352 |
|
353 CPosLmItemIterator* iter = iLandmarkSearch->MatchIteratorL(); |
|
354 CleanupStack::PushL(iter); |
|
355 |
|
356 if (aInCallback) |
|
357 { |
|
358 if (iter->NumOfItemsL() != iLandmarkSearch->NumOfMatches()) |
|
359 { |
|
360 iLog->Log(_L("Iterators no. of items is not equal to LandmarksSearch no. matches")); |
|
361 _LIT(KExpected, "Iter. of matches: %d"); |
|
362 _LIT(KReturned, "LandmarksSearch no. of matches: %d"); |
|
363 TBuf<100> info; |
|
364 info.Format(KExpected, iter->NumOfItemsL()); |
|
365 iLog->Log(info); |
|
366 info.Format(KReturned, iLandmarkSearch->NumOfMatches()); |
|
367 iLog->Log(info); |
|
368 |
|
369 iLog->Log(KNumOfMatchesErr); |
|
370 User::Leave(-1); |
|
371 } |
|
372 TBuf<100> info2; |
|
373 _LIT(KNof, "No. of matches found before cancel = %d"); |
|
374 info2.Format(KNof, iter->NumOfItemsL()); |
|
375 iLog->Log(info2); |
|
376 |
|
377 AssertTrueSecL(iter->NumOfItemsL() != 0, KCancelErr); |
|
378 } |
|
379 |
|
380 CleanupStack::PopAndDestroy(2, areaCriteria); |
|
381 |
|
382 } |
|
383 |
|
384 // End of File |