|
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_CPosTp9.h" |
|
23 #include <EPos_CPosLandmarkDatabase.h> |
|
24 #include <EPos_CPosLMItemIterator.h> |
|
25 #include <EPos_CPosLandmark.h> |
|
26 #include <EPos_TPosLMSortPref.h> |
|
27 #include <e32svr.h> // RDebug |
|
28 |
|
29 // CONSTANTS |
|
30 const TInt KNoLandmarks = 50; |
|
31 _LIT(KIteratorNumOfItemsErr, "The iterator returns incorrect number of items"); |
|
32 _LIT(KIteratorIdErr, "A landmarks id not in the database returned from the iterator"); |
|
33 |
|
34 // ================= MEMBER FUNCTIONS ======================= |
|
35 |
|
36 // --------------------------------------------------------- |
|
37 // CPosTp9::StartL |
|
38 // |
|
39 // (other items were commented in a header). |
|
40 // --------------------------------------------------------- |
|
41 // |
|
42 void CPosTp9::StartL() |
|
43 { |
|
44 |
|
45 RemoveDefaultDbL(); |
|
46 RemoveAllLmDatabasesL(); |
|
47 |
|
48 iDatabase = CPosLandmarkDatabase::OpenL(); |
|
49 if (iDatabase->IsInitializingNeeded()) |
|
50 { |
|
51 ExecuteAndDeleteLD(iDatabase->InitializeL()); |
|
52 } |
|
53 ExecuteAndDeleteLD(iDatabase->CompactL()); |
|
54 AddLandmarksL(); |
|
55 IterateLandmarksL(); |
|
56 IterateSetOfLandmarksL(); |
|
57 IterateSortedLandmarksL(); |
|
58 } |
|
59 |
|
60 // --------------------------------------------------------- |
|
61 // CPosTp9::CloseTestL |
|
62 // |
|
63 // (other items were commented in a header). |
|
64 // --------------------------------------------------------- |
|
65 // |
|
66 void CPosTp9::CloseTest() |
|
67 { |
|
68 iLandmarks.ResetAndDestroy(); |
|
69 iLandmarks.Close(); |
|
70 delete iDatabase; |
|
71 iDatabase = NULL; |
|
72 } |
|
73 |
|
74 // --------------------------------------------------------- |
|
75 // CPosTp9::AddLandmarksL |
|
76 // |
|
77 // (other items were commented in a header). |
|
78 // --------------------------------------------------------- |
|
79 // |
|
80 void CPosTp9::AddLandmarksL() |
|
81 { |
|
82 iLog->Log(_L("AddLandmarksL")); |
|
83 _LIT(KLmName, "LmTP9 - %d"); |
|
84 _LIT(KLmDescription, "LmTP9Description - %d"); |
|
85 |
|
86 for (TInt i=0; i<(KNoLandmarks); i++) |
|
87 { |
|
88 TBuf<100> lmName; |
|
89 lmName.Format(KLmName,i); |
|
90 TBuf<100> lmDesc; |
|
91 lmDesc.Format(KLmDescription,i); |
|
92 |
|
93 CPosLandmark* landmark = CPosLandmark::NewLC(); |
|
94 landmark->SetLandmarkNameL(lmName); |
|
95 landmark->SetLandmarkDescriptionL(lmDesc); |
|
96 TInt err = KErrLocked; |
|
97 while (err == KErrLocked) |
|
98 { |
|
99 TRAP(err, iDatabase->AddLandmarkL(*landmark)); |
|
100 } |
|
101 |
|
102 iLandmarks.Append(landmark); |
|
103 |
|
104 CleanupStack::Pop(landmark); |
|
105 } |
|
106 } |
|
107 |
|
108 // --------------------------------------------------------- |
|
109 // CPosTp9::IterateLandmarksL |
|
110 // |
|
111 // (other items were commented in a header). |
|
112 // --------------------------------------------------------- |
|
113 // |
|
114 void CPosTp9::IterateLandmarksL() |
|
115 { |
|
116 iLog->Log(_L("IterateLandmarksL")); |
|
117 CPosLmItemIterator* iter = iDatabase->LandmarkIteratorL(); |
|
118 CleanupStack::PushL(iter); |
|
119 |
|
120 TPosLmItemId id = iter->NextL(); |
|
121 while (id != KPosLmNullItemId) |
|
122 { |
|
123 CPosLandmark* source = InternalGet(id); |
|
124 AssertTrueSecL(source != NULL, KIteratorIdErr); |
|
125 |
|
126 CPosLandmark* target = iDatabase->ReadLandmarkLC(id); |
|
127 CompareLandmarksL(*source, *target); |
|
128 CleanupStack::PopAndDestroy(); // target |
|
129 |
|
130 id = iter->NextL(); |
|
131 } |
|
132 |
|
133 AssertTrueSecL(iter->NumOfItemsL() == (TUint)iLandmarks.Count(), KIteratorNumOfItemsErr); |
|
134 |
|
135 iter->Reset(); |
|
136 id = iter->NextL(); |
|
137 while (id != KPosLmNullItemId) |
|
138 { |
|
139 CPosLandmark* source = InternalGet(id); |
|
140 AssertTrueSecL(source != NULL, KIteratorIdErr); |
|
141 |
|
142 CPosLandmark* target = iDatabase->ReadLandmarkLC(id); |
|
143 CompareLandmarksL(*source, *target); |
|
144 CleanupStack::PopAndDestroy(); // target |
|
145 |
|
146 id = iter->NextL(); |
|
147 } |
|
148 |
|
149 AssertTrueSecL(iter->NumOfItemsL() == (TUint)iLandmarks.Count(), KIteratorNumOfItemsErr); |
|
150 |
|
151 CleanupStack::PopAndDestroy(iter); |
|
152 } |
|
153 |
|
154 // --------------------------------------------------------- |
|
155 // CPosTp9::IterateSetOfLandmarksL |
|
156 // |
|
157 // (other items were commented in a header). |
|
158 // --------------------------------------------------------- |
|
159 // |
|
160 void CPosTp9::IterateSetOfLandmarksL() |
|
161 { |
|
162 iLog->Log(_L("IterateSetOfLandmarksL")); |
|
163 CPosLmItemIterator* iter = iDatabase->LandmarkIteratorL(); |
|
164 CleanupStack::PushL(iter); |
|
165 |
|
166 const TInt startIndex=5; |
|
167 const TInt numOfItems=20; |
|
168 |
|
169 RArray<TPosLmItemId> ids; |
|
170 CleanupClosePushL(ids); |
|
171 |
|
172 iter->GetItemIdsL(ids, startIndex, numOfItems); |
|
173 |
|
174 AssertTrueSecL(ids.Count() == numOfItems, KIteratorNumOfItemsErr); |
|
175 |
|
176 for (TInt i=0; i<numOfItems; i++) |
|
177 { |
|
178 CPosLandmark* source = InternalGet(ids[i]); |
|
179 AssertTrueSecL(source != NULL, KIteratorIdErr); |
|
180 |
|
181 CPosLandmark* target = iDatabase->ReadLandmarkLC(ids[i]); |
|
182 CompareLandmarksL(*source, *target); |
|
183 CleanupStack::PopAndDestroy(); // target |
|
184 } |
|
185 |
|
186 CleanupStack::PopAndDestroy(2, iter); |
|
187 } |
|
188 |
|
189 // --------------------------------------------------------- |
|
190 // CPosTp9::InternalSort |
|
191 // |
|
192 // (other items were commented in a header). |
|
193 // --------------------------------------------------------- |
|
194 // |
|
195 TInt InternalSortL(const CPosLandmark& aSource, const CPosLandmark& aTarget) |
|
196 { |
|
197 TPtrC sourceName, targetName; |
|
198 |
|
199 User::LeaveIfError(aSource.GetLandmarkName(sourceName)); |
|
200 User::LeaveIfError(aTarget.GetLandmarkName(targetName)); |
|
201 |
|
202 return sourceName.Compare(targetName); |
|
203 } |
|
204 |
|
205 // --------------------------------------------------------- |
|
206 // CPosTp9::IterateLandmarksL |
|
207 // |
|
208 // (other items were commented in a header). |
|
209 // --------------------------------------------------------- |
|
210 // |
|
211 void CPosTp9::IterateSortedLandmarksL() |
|
212 { |
|
213 iLog->Log(_L("IterateSortedLandmarksL")); |
|
214 CheckIteratorArgL(CPosLandmark::EPosition); |
|
215 CheckIteratorArgL(CPosLandmark::ECoverageRadius); |
|
216 CheckIteratorArgL(CPosLandmark::ECategoryInfo); |
|
217 CheckIteratorArgL(CPosLandmark::EIcon); |
|
218 CheckIteratorArgL(CPosLandmark::EDescription); |
|
219 |
|
220 TLinearOrder<CPosLandmark> order(InternalSortL); |
|
221 iLandmarks.Sort(order); |
|
222 |
|
223 TPosLmSortPref sortDesc(CPosLandmark::ELandmarkName, TPosLmSortPref::EDescending); |
|
224 CPosLmItemIterator* iter = iDatabase->LandmarkIteratorL(sortDesc); |
|
225 CleanupStack::PushL(iter); |
|
226 |
|
227 AssertTrueSecL(iter->NumOfItemsL() == (TUint)iLandmarks.Count(), KIteratorNumOfItemsErr); |
|
228 |
|
229 TInt lastIndex=iLandmarks.Count()-1; |
|
230 for (TInt i=lastIndex; i>=0; i--) |
|
231 { |
|
232 CPosLandmark* target = iDatabase->ReadLandmarkLC(iter->NextL()); |
|
233 |
|
234 CompareLandmarksL(*iLandmarks[i], *target); |
|
235 CleanupStack::PopAndDestroy(); // target |
|
236 } |
|
237 CleanupStack::PopAndDestroy(iter); |
|
238 |
|
239 TPosLmSortPref sortAsc(CPosLandmark::ELandmarkName, TPosLmSortPref::EAscending); |
|
240 iter = iDatabase->LandmarkIteratorL(sortAsc); |
|
241 CleanupStack::PushL(iter); |
|
242 |
|
243 for (TInt j=0; j < iLandmarks.Count(); j++) |
|
244 { |
|
245 CPosLandmark* target = iDatabase->ReadLandmarkLC(iter->NextL()); |
|
246 |
|
247 CompareLandmarksL(*iLandmarks[j], *target); |
|
248 CleanupStack::PopAndDestroy(); // target |
|
249 } |
|
250 |
|
251 CleanupStack::PopAndDestroy(iter); |
|
252 iLog->Log(_L("IterateSortedLandmarksL completed")); |
|
253 } |
|
254 |
|
255 // --------------------------------------------------------- |
|
256 // CPosTp9:: |
|
257 // |
|
258 // (other items were commented in a header). |
|
259 // --------------------------------------------------------- |
|
260 // |
|
261 void CPosTp9::CheckIteratorArgL(const CPosLandmark::TAttributes& aAttr) |
|
262 { |
|
263 _LIT(KSortByNameErr, "Only sorting by landmark name should be supported"); |
|
264 iLog->Log(_L("CheckIteratorArgL")); |
|
265 TPosLmSortPref sortPref(aAttr); |
|
266 CPosLmItemIterator* iter = NULL; |
|
267 TRAPD(err, iter = iDatabase->LandmarkIteratorL(sortPref)); |
|
268 delete iter; |
|
269 AssertTrueSecL(err==KErrNotSupported, KSortByNameErr); |
|
270 } |
|
271 |
|
272 // --------------------------------------------------------- |
|
273 // CPosTp9::InternalGet |
|
274 // |
|
275 // (other items were commented in a header). |
|
276 // --------------------------------------------------------- |
|
277 // |
|
278 CPosLandmark* CPosTp9::InternalGet(TPosLmItemId id) |
|
279 { |
|
280 for (TInt i=0; i<iLandmarks.Count(); i++) |
|
281 { |
|
282 if (iLandmarks[i]->LandmarkId() == id) |
|
283 { |
|
284 return iLandmarks[i]; |
|
285 } |
|
286 } |
|
287 |
|
288 return NULL; |
|
289 } |
|
290 |
|
291 // End of File |