|
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_CPosTp136.h" |
|
23 #include <EPos_CPosLandmarkDatabase.h> |
|
24 #include <EPos_CPosLmDatabaseManager.h> |
|
25 #include <EPos_CPosLandmarkParser.h> |
|
26 |
|
27 // ================= CONSTANTS ======================= |
|
28 |
|
29 _LIT(KLMXFile, "c:\\system\\test\\testdata\\Tp136.xml"); |
|
30 _LIT(KGPXFile, "c:\\system\\test\\testdata\\Tp136.gpx"); |
|
31 |
|
32 _LIT(KEmpty, ""); |
|
33 |
|
34 _LIT(K1, "Category nr1 added in TP48"); |
|
35 |
|
36 _LIT(K2, "Läkare"); |
|
37 _LIT(K3, "Sjukhus"); |
|
38 _LIT(K4, "Restaurant"); |
|
39 _LIT(K5, "Shop"); |
|
40 |
|
41 _LIT(K6, "Frisör"); |
|
42 |
|
43 _LIT(K7, "Dagis"); |
|
44 _LIT(K8, "BurgerKing"); |
|
45 _LIT(K9, "Hotel"); |
|
46 _LIT(K10, "Car park"); |
|
47 |
|
48 _LIT(K11, "Garage"); |
|
49 _LIT(K12, "Bus stop"); |
|
50 _LIT(K13, "BurgerKing"); |
|
51 |
|
52 _LIT(K14, "Category nr2 added in TP48"); |
|
53 _LIT(K15_1, "OutSight"); |
|
54 const TInt KNrOfLandmarks = 8; |
|
55 |
|
56 // ================= MEMBER FUNCTIONS ======================= |
|
57 |
|
58 // --------------------------------------------------------- |
|
59 // CPosTp136::CloseTest |
|
60 // |
|
61 // (other items were commented in a header). |
|
62 // --------------------------------------------------------- |
|
63 // |
|
64 void CPosTp136::CloseTest() |
|
65 { |
|
66 // Release ECOM stuff |
|
67 ReleaseLandmarkResources(); |
|
68 |
|
69 delete iOperation;iOperation=NULL; |
|
70 } |
|
71 |
|
72 // --------------------------------------------------------- |
|
73 // CPosTp136::StartL |
|
74 // |
|
75 // (other items were commented in a header). |
|
76 // --------------------------------------------------------- |
|
77 // |
|
78 void CPosTp136::StartL() |
|
79 { |
|
80 iErrorsFound = 0; |
|
81 |
|
82 // LMX |
|
83 TestParseL(KLMXFile, KLmxMimeType); |
|
84 TestImportL(KLMXFile, KLmxMimeType); |
|
85 |
|
86 // GPX |
|
87 TestParseL(KGPXFile, KGpxMimeType); |
|
88 TestImportL(KGPXFile, KGpxMimeType); |
|
89 |
|
90 if (iErrorsFound != KErrNone) |
|
91 { |
|
92 iLog->Log(_L("Errors found in TP136")); |
|
93 User::Leave(-1); |
|
94 } |
|
95 } |
|
96 |
|
97 // --------------------------------------------------------- |
|
98 // CPosTp136::TestParseL |
|
99 // |
|
100 // (other items were commented in a header). |
|
101 // --------------------------------------------------------- |
|
102 // |
|
103 void CPosTp136::TestParseL(const TDesC& aFile, const TDesC8& aMime) |
|
104 { |
|
105 iLog->Log(_L("----- TestParseL -----")); |
|
106 iLog->Log(_L("FILE: %S"), &aFile); |
|
107 |
|
108 RemoveAllLmDatabasesL(); |
|
109 |
|
110 const TDesC* categoryNames[KNrOfLandmarks][4] = {{&KEmpty, &KEmpty, &KEmpty, &KEmpty}, |
|
111 {&K1, &KEmpty, &KEmpty, &KEmpty}, |
|
112 {&K2, &K3, &K4, &K5}, |
|
113 {&KEmpty, &KEmpty, &KEmpty, &KEmpty}, |
|
114 {&K6, &KEmpty, &KEmpty, &KEmpty}, |
|
115 {&K7, &K8, &K9, &K10}, |
|
116 {&K11, &K12, &K13, &KEmpty}, |
|
117 {&K14, &K15_1, &KEmpty, &KEmpty}}; |
|
118 |
|
119 CPosLandmarkParser* parser = CPosLandmarkParser::NewL(aMime); |
|
120 CleanupStack::PushL(parser); |
|
121 |
|
122 RFile file; |
|
123 TInt err = file.Open(iFileSession, aFile, EFileRead); |
|
124 if (err != KErrNone) |
|
125 { |
|
126 iLog->Log(_L("Error when opening file")); |
|
127 User::Leave(err); |
|
128 } |
|
129 CleanupClosePushL(file); |
|
130 parser->SetInputFileHandleL(file); |
|
131 iOperation = parser->ParseContentL(); |
|
132 TRequestStatus status = KPosLmOperationNotComplete; |
|
133 TReal32 progress=0; |
|
134 |
|
135 CDesCArrayFlat* landmarkNames = new (ELeave) CDesCArrayFlat(KNrOfLandmarks); |
|
136 landmarkNames->AppendL(_L("Billigt")); |
|
137 landmarkNames->AppendL(_L("LOG9")); |
|
138 landmarkNames->AppendL(_L("Kalles Hundgård")); |
|
139 landmarkNames->AppendL(_L("MLFW")); |
|
140 landmarkNames->AppendL(_L("TE, Lund")); |
|
141 landmarkNames->AppendL(_L("asdf")); |
|
142 landmarkNames->AppendL(_L("TP48LandmarkWithAllXMLFields")); |
|
143 landmarkNames->AppendL(_L("TP48Landmark With Empty XML Fields")); |
|
144 |
|
145 TInt counter=0; |
|
146 while (progress != 1) |
|
147 { |
|
148 iOperation->NextStep(status, progress); |
|
149 // Wait for NextStep to complete |
|
150 User::WaitForRequest(status); |
|
151 CPosLandmark* lm = parser->LandmarkLC(); |
|
152 TPtrC name; |
|
153 lm->GetLandmarkName(name); |
|
154 TPtrC expName(landmarkNames->MdcaPoint(counter)); |
|
155 iLog->Log(_L("Landmark %d, Actual name '%S', Expected '%S'"), counter, &name, &expName); |
|
156 if (expName.CompareC(name) != KErrNone) |
|
157 { |
|
158 iLog->Log(_L("ERROR: Wrong Landmark Name")); |
|
159 iErrorsFound++; |
|
160 } |
|
161 |
|
162 RArray<TPosLmItemId> arr; |
|
163 CleanupClosePushL(arr); |
|
164 |
|
165 lm->GetCategoriesL(arr); |
|
166 for (TInt i=0;i<arr.Count();i++) |
|
167 { |
|
168 CPosLandmarkCategory* cat = parser->LandmarkCategoryLC(arr[i]); |
|
169 TPtrC catName; |
|
170 cat->GetCategoryName(catName); |
|
171 iLog->Log(_L("Category %d, Actual '%S', Expected '%S'"), i, &catName, categoryNames[counter][i]); |
|
172 if (catName.CompareC(*categoryNames[counter][i]) != KErrNone) |
|
173 { |
|
174 iLog->Log(_L("ERROR: Wrong Category Name when comparing")); |
|
175 iErrorsFound++; |
|
176 } |
|
177 CleanupStack::PopAndDestroy(cat); |
|
178 } |
|
179 |
|
180 CleanupStack::PopAndDestroy(&arr); |
|
181 CleanupStack::PopAndDestroy(lm); |
|
182 counter++; |
|
183 } |
|
184 |
|
185 TUint32 nr = parser->NumOfParsedLandmarks(); |
|
186 if (nr != KNrOfLandmarks) |
|
187 { |
|
188 iLog->Log(_L("ERROR: Wrong number of landmarks parsed")); |
|
189 iErrorsFound++; |
|
190 } |
|
191 |
|
192 iLog->Log(_L("-------------------\n")); |
|
193 delete iOperation;iOperation=NULL; |
|
194 |
|
195 CleanupStack::PopAndDestroy(&file); |
|
196 |
|
197 landmarkNames->Reset(); |
|
198 delete landmarkNames; |
|
199 landmarkNames = NULL; |
|
200 CleanupStack::PopAndDestroy(parser); |
|
201 } |
|
202 |
|
203 // --------------------------------------------------------- |
|
204 // CPosTp136::TestImportL |
|
205 // |
|
206 // (other items were commented in a header). |
|
207 // --------------------------------------------------------- |
|
208 // |
|
209 void CPosTp136::TestImportL(const TDesC& aFile, const TDesC8& aMime) |
|
210 { |
|
211 iLog->Log(_L("----- TestImportL -----")); |
|
212 iLog->Log(_L("FILE: %S"), &aFile); |
|
213 |
|
214 RemoveAllLmDatabasesL(); |
|
215 |
|
216 const TDesC* categoryNames[KNrOfLandmarks][4] = {{&KEmpty, &KEmpty, &KEmpty, &KEmpty}, |
|
217 {&K1, &KEmpty, &KEmpty, &KEmpty}, |
|
218 {&K2, &K3, &K4, &K5}, |
|
219 {&KEmpty, &KEmpty, &KEmpty, &KEmpty}, |
|
220 {&K6, &KEmpty, &KEmpty, &KEmpty}, |
|
221 {&K7, &K8, &K9, &K10}, |
|
222 {&K11, &K12, &K13, &KEmpty}, |
|
223 {&K14, &K15_1, &KEmpty, &KEmpty}}; |
|
224 |
|
225 CPosLandmarkDatabase* database = OpenDatabaseLC(); |
|
226 |
|
227 CPosLandmarkParser* parser = CPosLandmarkParser::NewL(aMime); |
|
228 CleanupStack::PushL(parser); |
|
229 |
|
230 CPosLmCategoryManager* categoryManager = CPosLmCategoryManager::NewL(*database); |
|
231 CleanupStack::PushL(categoryManager); |
|
232 |
|
233 RFile file; |
|
234 TInt err = file.Open(iFileSession, aFile, EFileRead); |
|
235 if (err != KErrNone) |
|
236 { |
|
237 iLog->Log(_L("Error when opening file")); |
|
238 User::Leave(err); |
|
239 } |
|
240 CleanupClosePushL(file); |
|
241 |
|
242 parser->SetInputFileHandleL(file); |
|
243 iOperation = database->ImportLandmarksL(*parser, CPosLandmarkDatabase::EIncludeCategories); |
|
244 |
|
245 ExecuteAndDeleteLD(iOperation); |
|
246 iOperation=NULL; |
|
247 |
|
248 CPosLmItemIterator* iter = database->LandmarkIteratorL(); |
|
249 CleanupStack::PushL(iter); |
|
250 |
|
251 CDesCArrayFlat* landmarkNames = new (ELeave) CDesCArrayFlat(KNrOfLandmarks); |
|
252 landmarkNames->AppendL(_L("Billigt")); |
|
253 landmarkNames->AppendL(_L("LOG9")); |
|
254 landmarkNames->AppendL(_L("Kalles Hundgård")); |
|
255 landmarkNames->AppendL(_L("MLFW")); |
|
256 landmarkNames->AppendL(_L("TE, Lund")); |
|
257 landmarkNames->AppendL(_L("asdf")); |
|
258 landmarkNames->AppendL(_L("TP48LandmarkWithAllXMLFields")); |
|
259 landmarkNames->AppendL(_L("TP48Landmark With Empty XML Fields")); |
|
260 |
|
261 TPosLmItemId id = iter->NextL(); |
|
262 TInt counter = 0; |
|
263 while (id != KPosLmNullItemId) |
|
264 { |
|
265 CPosLandmark* lm = database->ReadLandmarkLC(id); |
|
266 RArray<TPosLmItemId> arr; |
|
267 CleanupClosePushL(arr); |
|
268 |
|
269 TPtrC name; |
|
270 lm->GetLandmarkName(name); |
|
271 TPtrC expName(landmarkNames->MdcaPoint(counter)); |
|
272 iLog->Log(_L("Landmark %d, Actual name '%S', Expected '%S'"), counter, &name, &expName); |
|
273 if (expName.CompareC(name) != KErrNone) |
|
274 { |
|
275 iLog->Log(_L("ERROR: Wrong Landmark Name")); |
|
276 iErrorsFound++; |
|
277 } |
|
278 |
|
279 lm->GetCategoriesL(arr); |
|
280 if (arr.Count() == 0) iLog->Log(_L("NOLL")); |
|
281 else |
|
282 { |
|
283 TBuf<100> buf; |
|
284 buf.Format(_L("nr of categories %d"), arr.Count()); |
|
285 iLog->Log(buf); |
|
286 } |
|
287 |
|
288 for (TInt i=0;i<arr.Count();i++) |
|
289 { |
|
290 CPosLandmarkCategory* cat = categoryManager->ReadCategoryLC(arr[i]); |
|
291 TPtrC catName; |
|
292 cat->GetCategoryName(catName); |
|
293 iLog->Log(_L("Category %d, Actual '%S', Expected '%S'"), i, &catName, categoryNames[counter][i]); |
|
294 if (catName.CompareC(*categoryNames[counter][i]) != KErrNone) |
|
295 { |
|
296 iLog->Log(_L("ERROR: Wrong Category Name")); |
|
297 iErrorsFound++; |
|
298 } |
|
299 CleanupStack::PopAndDestroy(cat); |
|
300 } |
|
301 |
|
302 CleanupStack::PopAndDestroy(&arr); |
|
303 CleanupStack::PopAndDestroy(lm); |
|
304 id = iter->NextL(); |
|
305 counter++; |
|
306 } |
|
307 TUint32 nr = parser->NumOfParsedLandmarks(); |
|
308 if (nr != KNrOfLandmarks) |
|
309 { |
|
310 iLog->Log(_L("ERROR: Wrong number of landmarks parsed")); |
|
311 iErrorsFound++; |
|
312 } |
|
313 |
|
314 CleanupStack::PopAndDestroy(iter); |
|
315 landmarkNames->Reset(); |
|
316 delete landmarkNames; |
|
317 landmarkNames = NULL; |
|
318 |
|
319 iLog->Log(_L("-------------------\n")); |
|
320 |
|
321 CleanupStack::PopAndDestroy(&file); |
|
322 CleanupStack::PopAndDestroy(categoryManager); |
|
323 CleanupStack::PopAndDestroy(parser); |
|
324 CleanupStack::PopAndDestroy(database); |
|
325 } |
|
326 |
|
327 // End of File |