|
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_CPosTp144.h" |
|
23 #include <e32math.h> |
|
24 #include <LbsPosition.h> |
|
25 |
|
26 #include <EPos_CPosLandmark.h> |
|
27 #include <EPos_CPosLandmarkCategory.h> |
|
28 #include <EPos_PosLandmarkSerialization.h> |
|
29 #include <EPos_PosLmCategorySerialization.h> |
|
30 |
|
31 // ================= MEMBER FUNCTIONS ======================= |
|
32 |
|
33 |
|
34 // --------------------------------------------------------- |
|
35 // CPosTp144::StartL |
|
36 // |
|
37 // (other items were commented in a header). |
|
38 // --------------------------------------------------------- |
|
39 // |
|
40 void CPosTp144::StartL() |
|
41 { |
|
42 |
|
43 CheckLmSerializationL(); |
|
44 |
|
45 } |
|
46 |
|
47 // --------------------------------------------------------- |
|
48 // CPosTp144::DumpBuffer |
|
49 // |
|
50 // --------------------------------------------------------- |
|
51 |
|
52 void CPosTp144::DumpBuffer(const TDesC8& aBuffer) |
|
53 { |
|
54 DECLARE_ERROR_LOGGING; |
|
55 LOG("=== Buffer Dump ==="); |
|
56 message.Format(_L("Buffer size = %d units"), aBuffer.Length()); |
|
57 LOG_DES(message); |
|
58 for (TInt i = 0; i < aBuffer.Length(); i++) |
|
59 { |
|
60 _LIT(KByte, "Offset %4d = % 2d"); |
|
61 _LIT(KChar, "Offset %4d = % 2c"); |
|
62 TUint8 c = aBuffer[i]; |
|
63 if (TChar(c).IsAlphaDigit()) |
|
64 { |
|
65 message.Format(KChar, i, c); |
|
66 } |
|
67 else |
|
68 { |
|
69 message.Format(KByte, i, TInt(c)); |
|
70 } |
|
71 LOG_DES(message); |
|
72 } |
|
73 LOG("==================="); |
|
74 } |
|
75 // --------------------------------------------------------- |
|
76 // CPosTp144::CompareBuffers |
|
77 // |
|
78 // --------------------------------------------------------- |
|
79 |
|
80 void CPosTp144::CompareBuffers( |
|
81 const TDesC8& aBuf1, |
|
82 const TDesC8& aBuf2) |
|
83 { |
|
84 DECLARE_ERROR_LOGGING; |
|
85 |
|
86 CHECK_EQUAL(aBuf1.Length(), aBuf2.Length(), "Different buffer lengths"); |
|
87 for (TInt i = 0; i < Min(aBuf1.Length(), aBuf2.Length()); i++) |
|
88 { |
|
89 TInt c1 = aBuf1[i], c2 = aBuf2[i]; |
|
90 if (c1 != c2) |
|
91 { |
|
92 _LIT(KMessage, "Different at offset %d (actual = %d, expected %d)"); |
|
93 message.Format(KMessage, i, c1, c2); |
|
94 ERR_DES(message); |
|
95 } |
|
96 } |
|
97 } |
|
98 |
|
99 // --------------------------------------------------------- |
|
100 // CPosTp144::CreateDummyLandmarkLC |
|
101 // |
|
102 // --------------------------------------------------------- |
|
103 |
|
104 CPosLandmark* CPosTp144::CreateDummyLandmarkLC() |
|
105 { |
|
106 CPosLandmark* lm = CPosLandmark::NewLC(); |
|
107 |
|
108 _LIT(KName, "Name"); |
|
109 _LIT(KDesc, "Description"); |
|
110 _LIT(KIcon, "IconFile"); |
|
111 const TInt KIconIndex = 1, KIconMaskIndex = 2; |
|
112 |
|
113 const TPosLmItemId KCat[] = { 3, 4, 5 }; |
|
114 const TInt KCats = sizeof KCat / sizeof(TPosLmItemId); |
|
115 |
|
116 _LIT(KField1Val, "field1"); |
|
117 _LIT(KField2Val, "field11"); |
|
118 const TPositionFieldId KField[] = |
|
119 { |
|
120 EPositionFieldComment, |
|
121 EPositionFieldCountry |
|
122 }; |
|
123 const TInt KFields = sizeof KField / sizeof(TPositionFieldId); |
|
124 const TPtrC KFieldData[] = |
|
125 { |
|
126 KField1Val(), KField2Val() |
|
127 }; |
|
128 |
|
129 const TReal32 KRadius = 0.12; |
|
130 const TReal32 KHacc = 0.23, KVacc = 0.34; |
|
131 const TReal KLat = 12, KLon = -23, KAlt = 34; |
|
132 |
|
133 lm->SetLandmarkNameL(KName); |
|
134 lm->SetLandmarkDescriptionL(KDesc); |
|
135 lm->SetIconL(KIcon, KIconIndex, KIconMaskIndex); |
|
136 |
|
137 const TLocality KLoc(TCoordinate(KLat,KLon,KAlt), KHacc, KVacc); |
|
138 lm->SetPositionL(KLoc); |
|
139 lm->SetCoverageRadius(KRadius); |
|
140 |
|
141 for (TInt c = 0; c < KCats; c++) |
|
142 { |
|
143 lm->AddCategoryL(KCat[c]); |
|
144 } |
|
145 |
|
146 for (TInt f = 0; f < KFields; f++) |
|
147 { |
|
148 lm->SetPositionFieldL(KField[f], KFieldData[f]); |
|
149 } |
|
150 |
|
151 return lm; |
|
152 } |
|
153 |
|
154 // --------------------------------------------------------- |
|
155 // CPosTp144::CompareLandmarks |
|
156 // |
|
157 // --------------------------------------------------------- |
|
158 |
|
159 void CPosTp144::CompareLandmarks( |
|
160 CPosLandmark& aLm1, |
|
161 CPosLandmark& aLm2) |
|
162 { |
|
163 DECLARE_ERROR_LOGGING; |
|
164 |
|
165 TPtrC name1, name2; |
|
166 |
|
167 CHECK_EQUAL(aLm1.LandmarkId(), aLm2.LandmarkId(), "Diff id"); |
|
168 CHECK_EQUAL(aLm1.IsPartial(), aLm2.IsPartial(), "Diff partial state"); |
|
169 |
|
170 aLm1.GetLandmarkName(name1); |
|
171 aLm2.GetLandmarkName(name2); |
|
172 ERROR(name1 != name2, "Diff name"); |
|
173 |
|
174 aLm1.GetLandmarkDescription(name1); |
|
175 aLm2.GetLandmarkDescription(name2); |
|
176 ERROR(name1 != name2, "Diff description"); |
|
177 |
|
178 TInt iconIndex1 = 0, iconMaskIndex1 = 0; |
|
179 TInt iconIndex2 = 1, iconMaskIndex2 = 2; |
|
180 |
|
181 TInt found1 = aLm1.GetIcon(name1, iconIndex1, iconMaskIndex1); |
|
182 TInt found2 = aLm2.GetIcon(name2, iconIndex2, iconMaskIndex2); |
|
183 |
|
184 if (found1 == found2) |
|
185 { |
|
186 if (found1 != KErrNotFound) |
|
187 { |
|
188 ERROR(name1 != name2, "Diff icon name"); |
|
189 CHECK_EQUAL(iconIndex1, iconIndex2, "Diff icon index"); |
|
190 CHECK_EQUAL(iconMaskIndex1, iconMaskIndex2, "Diff icon mask index"); |
|
191 } |
|
192 } |
|
193 else |
|
194 { |
|
195 ERR("Diff icon") |
|
196 } |
|
197 |
|
198 // location |
|
199 TLocality loc1, loc2; |
|
200 found1 = aLm1.GetPosition(loc1); |
|
201 found2 = aLm2.GetPosition(loc2); |
|
202 |
|
203 if (found1 == found2) |
|
204 { |
|
205 if (found1 != KErrNotFound) |
|
206 { |
|
207 CHECK_EQUAL(loc1.Latitude(), loc2.Latitude(), "Diff latitude"); |
|
208 CHECK_EQUAL(loc1.Longitude(), loc2.Longitude(), "Diff longitude"); |
|
209 CHECK_EQUAL(loc1.Altitude(), loc2.Altitude(), "Diff altitude"); |
|
210 CHECK_EQUAL(loc1.HorizontalAccuracy(), loc2.HorizontalAccuracy(), "Diff hacc"); |
|
211 CHECK_EQUAL(loc1.VerticalAccuracy(), loc2.VerticalAccuracy(), "Diff vacc"); |
|
212 CHECK_EQUAL(loc1.Datum(), loc2.Datum(), "Diff datum"); |
|
213 } |
|
214 } |
|
215 else |
|
216 { |
|
217 ERR("Diff position"); |
|
218 } |
|
219 |
|
220 // categories |
|
221 RArray<TPosLmItemId> cats1, cats2; |
|
222 aLm1.GetCategoriesL(cats1); |
|
223 aLm2.GetCategoriesL(cats2); |
|
224 CHECK_EQUAL(cats1.Count(), cats2.Count(), "Diff amount of categories"); |
|
225 for (TInt c = 0; c < Min(cats1.Count(), cats2.Count()); c++) |
|
226 { |
|
227 CHECK_EQUAL(cats1[c], cats2[c], "Diff category"); |
|
228 } |
|
229 cats1.Close(); |
|
230 cats2.Close(); |
|
231 |
|
232 // fields |
|
233 TInt fields1 = aLm1.NumOfAvailablePositionFields(); |
|
234 TInt fields2 = aLm2.NumOfAvailablePositionFields(); |
|
235 CHECK_EQUAL(fields1, fields2, "Diff amount of fields"); |
|
236 |
|
237 TPositionFieldId fid1 = aLm1.FirstPositionFieldId(); |
|
238 TPositionFieldId fid2 = aLm2.FirstPositionFieldId(); |
|
239 for (TInt f = 0; |
|
240 f < Min(fields1, fields2) && |
|
241 (fid1 != EPositionFieldNone || fid2 != EPositionFieldNone); |
|
242 f++) |
|
243 { |
|
244 CHECK_EQUAL(fid1, fid2, "Diff field"); |
|
245 aLm1.GetPositionField(fid1, name1); |
|
246 aLm2.GetPositionField(fid2, name2); |
|
247 ERROR(name1 != name2, "Diff field data"); |
|
248 |
|
249 fid1 = aLm1.NextPositionFieldId(fid1); |
|
250 fid2 = aLm1.NextPositionFieldId(fid2); |
|
251 } |
|
252 } |
|
253 |
|
254 |
|
255 // --------------------------------------------------------- |
|
256 // CPosTp144::CheckLmSerialization_SubL |
|
257 // |
|
258 // --------------------------------------------------------- |
|
259 |
|
260 void CPosTp144::CheckLmSerialization_SubL(CPosLandmark* lm) |
|
261 { |
|
262 DECLARE_ERROR_LOGGING; |
|
263 |
|
264 CPosLandmark* lm1 = lm; |
|
265 CPosLandmark* lm2 = NULL; |
|
266 |
|
267 TInt err = KErrNone; |
|
268 HBufC8* buf1 = NULL; |
|
269 HBufC8* buf2 = NULL; |
|
270 |
|
271 TRAP(err, buf1 = PosLandmarkSerialization::PackL(*lm1)); |
|
272 IF_ERROR(err, "Packing failed"); |
|
273 User::LeaveIfError(err); |
|
274 CleanupStack::PushL(buf1); |
|
275 |
|
276 TRAP(err, lm2 = PosLandmarkSerialization::UnpackL(*buf1)); |
|
277 IF_ERROR(err, "Unpacking failed"); |
|
278 User::LeaveIfError(err); |
|
279 CleanupStack::PushL(lm2); |
|
280 |
|
281 // read and compare values |
|
282 CompareLandmarks(*lm1, *lm2); |
|
283 |
|
284 // compare by buffer |
|
285 TRAP(err, buf2 = PosLandmarkSerialization::PackL(*lm2)); |
|
286 CleanupStack::PushL(buf2); |
|
287 |
|
288 CompareBuffers(*buf1, *buf2); |
|
289 |
|
290 // cleanup |
|
291 CleanupStack::PopAndDestroy(buf2); |
|
292 CleanupStack::PopAndDestroy(lm2); |
|
293 CleanupStack::PopAndDestroy(buf1); |
|
294 |
|
295 } |
|
296 |
|
297 // --------------------------------------------------------- |
|
298 // CPosTp144::CheckLmSerializationL |
|
299 // |
|
300 // --------------------------------------------------------- |
|
301 |
|
302 void CPosTp144::CheckLmSerializationL() |
|
303 { |
|
304 DECLARE_ERROR_LOGGING; |
|
305 |
|
306 |
|
307 //LOG("1. Dummy landmark") |
|
308 CPosLandmark* lm = CreateDummyLandmarkLC(); |
|
309 CheckLmSerialization_SubL(lm); |
|
310 CleanupStack::PopAndDestroy(lm); |
|
311 |
|
312 //LOG("2. Empty landmark") |
|
313 lm = CPosLandmark::NewLC(); |
|
314 CheckLmSerialization_SubL(lm); |
|
315 CleanupStack::PopAndDestroy(lm); |
|
316 |
|
317 |
|
318 LEAVE_IF_ERRORS() |
|
319 } |
|
320 // End of File |