|
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_CPosTp161.h" |
|
23 #include <EPos_CPosLandmarkDatabase.h> |
|
24 #include <EPos_CPosLmDatabaseManager.h> |
|
25 #include <EPos_CPosLandmarkParser.h> |
|
26 |
|
27 // ================= CONSTANTS ======================= |
|
28 |
|
29 _LIT(KTp161DbFile, "TP161Test.ldb"); |
|
30 _LIT(KKMLFile, "c:\\system\\test\\testdata\\Tp161KML.kml"); |
|
31 |
|
32 |
|
33 _LIT(KEmpty, ""); |
|
34 |
|
35 _LIT(K1, "Category nr1 added in TP48"); |
|
36 |
|
37 _LIT(K2, "Läkare"); |
|
38 _LIT(K3, "Sjukhus"); |
|
39 _LIT(K4, "Restaurant"); |
|
40 _LIT(K5, "Shop"); |
|
41 |
|
42 _LIT(K6, "Frisör"); |
|
43 |
|
44 _LIT(K7, "Dagis"); |
|
45 _LIT(K8, "BurgerKing"); |
|
46 _LIT(K9, "Hotel"); |
|
47 _LIT(K10, "Car park"); |
|
48 |
|
49 _LIT(K11, "Garage"); |
|
50 _LIT(K12, "Bus stop"); |
|
51 _LIT(K13, "BurgerKing"); |
|
52 |
|
53 _LIT(K14, "Category nr2 added in TP48"); |
|
54 _LIT(K15_1, "OutSight"); |
|
55 const TInt KNrOfLandmarks = 8; |
|
56 |
|
57 // ================= MEMBER FUNCTIONS ======================= |
|
58 |
|
59 // --------------------------------------------------------- |
|
60 // CPosTp161::CloseTest |
|
61 // |
|
62 // (other items were commented in a header). |
|
63 // --------------------------------------------------------- |
|
64 // |
|
65 void CPosTp161::CloseTest() |
|
66 { |
|
67 delete iLandmarkParser; |
|
68 iLandmarkParser = NULL; |
|
69 |
|
70 delete iDatabase; |
|
71 iDatabase = NULL; |
|
72 // Release ECOM stuff |
|
73 ReleaseLandmarkResources(); |
|
74 |
|
75 delete iOperation;iOperation=NULL; |
|
76 } |
|
77 |
|
78 // --------------------------------------------------------- |
|
79 // CPosTp161::StartL |
|
80 // |
|
81 // (other items were commented in a header). |
|
82 // --------------------------------------------------------- |
|
83 // |
|
84 void CPosTp161::StartL() |
|
85 { |
|
86 iErrorsFound = 0; |
|
87 |
|
88 |
|
89 // KML |
|
90 TestParseL(KKMLFile, KKmlMimeType); |
|
91 TestImportL(KKMLFile, KKmlMimeType); |
|
92 |
|
93 if (iErrorsFound != KErrNone) |
|
94 { |
|
95 iLog->Log(_L("Errors found in TP161")); |
|
96 User::Leave(-1); |
|
97 } |
|
98 } |
|
99 |
|
100 // --------------------------------------------------------- |
|
101 // CPosTp161::TestParseL |
|
102 // |
|
103 // (other items were commented in a header). |
|
104 // --------------------------------------------------------- |
|
105 // |
|
106 void CPosTp161::TestParseL(const TDesC& aFile, const TDesC8& aMime) |
|
107 { |
|
108 iLog->Log(_L("----- TestParseL -----")); |
|
109 iLog->Log(_L("FILE: %S"), &aFile); |
|
110 |
|
111 RemoveAllLmDatabasesL(); |
|
112 |
|
113 const TDesC* categoryNames[KNrOfLandmarks][4] = {{&KEmpty, &KEmpty, &KEmpty, &KEmpty}, |
|
114 {&K1, &KEmpty, &KEmpty, &KEmpty}, |
|
115 {&K2, &K3, &K4, &K5}, |
|
116 {&KEmpty, &KEmpty, &KEmpty, &KEmpty}, |
|
117 {&K6, &KEmpty, &KEmpty, &KEmpty}, |
|
118 {&K7, &K8, &K9, &K10}, |
|
119 {&K11, &K12, &K13, &KEmpty}, |
|
120 {&K14, &K15_1, &KEmpty, &KEmpty}}; |
|
121 |
|
122 CPosLandmarkParser* parser = CPosLandmarkParser::NewL(aMime); |
|
123 CleanupStack::PushL(parser); |
|
124 |
|
125 RFile file; |
|
126 TInt err = file.Open(iFileSession, aFile, EFileRead); |
|
127 if (err != KErrNone) |
|
128 { |
|
129 iLog->Log(_L("Error when opening file")); |
|
130 User::Leave(err); |
|
131 } |
|
132 CleanupClosePushL(file); |
|
133 parser->SetInputFileHandleL(file); |
|
134 iOperation = parser->ParseContentL(); |
|
135 TRequestStatus status = KPosLmOperationNotComplete; |
|
136 TReal32 progress=0; |
|
137 |
|
138 CDesCArrayFlat* landmarkNames = new (ELeave) CDesCArrayFlat(KNrOfLandmarks); |
|
139 landmarkNames->AppendL(_L("Billigt")); |
|
140 landmarkNames->AppendL(_L("LOG9")); |
|
141 landmarkNames->AppendL(_L("Kalles Hundgård")); |
|
142 landmarkNames->AppendL(_L("MLFW")); |
|
143 landmarkNames->AppendL(_L("TE, Lund")); |
|
144 landmarkNames->AppendL(_L("asdf")); |
|
145 landmarkNames->AppendL(_L("TP48LandmarkWithAllXMLFields")); |
|
146 landmarkNames->AppendL(_L("TP48Landmark With Empty XML Fields")); |
|
147 |
|
148 TInt counter=0; |
|
149 while (progress != 1) |
|
150 { |
|
151 iOperation->NextStep(status, progress); |
|
152 // Wait for NextStep to complete |
|
153 User::WaitForRequest(status); |
|
154 CPosLandmark* lm = parser->LandmarkLC(); |
|
155 TPtrC name; |
|
156 lm->GetLandmarkName(name); |
|
157 TPtrC expName(landmarkNames->MdcaPoint(counter)); |
|
158 iLog->Log(_L("Landmark %d, Actual name '%S', Expected '%S'"), counter, &name, &expName); |
|
159 if (expName.CompareC(name) != KErrNone) |
|
160 { |
|
161 iLog->Log(_L("ERROR: Wrong Landmark Name")); |
|
162 iErrorsFound++; |
|
163 } |
|
164 |
|
165 RArray<TPosLmItemId> arr; |
|
166 CleanupClosePushL(arr); |
|
167 |
|
168 lm->GetCategoriesL(arr); |
|
169 for (TInt i=0;i<arr.Count();i++) |
|
170 { |
|
171 CPosLandmarkCategory* cat = parser->LandmarkCategoryLC(arr[i]); |
|
172 TPtrC catName; |
|
173 cat->GetCategoryName(catName); |
|
174 iLog->Log(_L("Category %d, Actual '%S', Expected '%S'"), i, &catName, categoryNames[counter][i]); |
|
175 if (catName.CompareC(*categoryNames[counter][i]) != KErrNone) |
|
176 { |
|
177 iLog->Log(_L("ERROR: Wrong Category Name when comparing")); |
|
178 iErrorsFound++; |
|
179 } |
|
180 CleanupStack::PopAndDestroy(cat); |
|
181 } |
|
182 |
|
183 CleanupStack::PopAndDestroy(&arr); |
|
184 CleanupStack::PopAndDestroy(lm); |
|
185 counter++; |
|
186 } |
|
187 |
|
188 TUint32 nr = parser->NumOfParsedLandmarks(); |
|
189 if (nr != KNrOfLandmarks) |
|
190 { |
|
191 iLog->Log(_L("ERROR: Wrong number of landmarks parsed")); |
|
192 iErrorsFound++; |
|
193 } |
|
194 |
|
195 iLog->Log(_L("-------------------\n")); |
|
196 delete iOperation;iOperation=NULL; |
|
197 |
|
198 CleanupStack::PopAndDestroy(&file); |
|
199 |
|
200 landmarkNames->Reset(); |
|
201 delete landmarkNames; |
|
202 landmarkNames = NULL; |
|
203 CleanupStack::PopAndDestroy(parser); |
|
204 } |
|
205 |
|
206 |
|
207 // --------------------------------------------------------- |
|
208 // CPosTp161::TestImport1L |
|
209 // |
|
210 // (other items were commented in a header). |
|
211 // --------------------------------------------------------- |
|
212 // |
|
213 void CPosTp161::TestImportL(const TDesC& aFile, const TDesC8& aMime) |
|
214 { |
|
215 iLog->Log(_L("----- TestImport1L ------")); |
|
216 iLog->Log(_L("FILE: %S"), &aFile); |
|
217 RemoveAllLmDatabasesL(); |
|
218 CopyTestDbFileL(KTp161DbFile); |
|
219 iLandmarkParser = CPosLandmarkParser::NewL(aMime); |
|
220 iLandmarkParser->SetInputFileL(aFile); |
|
221 |
|
222 TRAPD( err,iDatabase = CPosLandmarkDatabase::OpenL(KTp161DbFile)); |
|
223 iLog->Log(_L("Error after CPosLandmarkDatabase::OpenL = %d"),err); |
|
224 |
|
225 if (iDatabase->IsInitializingNeeded()) |
|
226 { |
|
227 ExecuteAndDeleteLD(iDatabase->InitializeL()); |
|
228 } |
|
229 |
|
230 CPosLmCategoryManager* categoryManager = CPosLmCategoryManager::NewL(*iDatabase); |
|
231 CleanupStack::PushL(categoryManager); |
|
232 // Create two local categories, "Dagis" and "BurgerKing" belongs to landmark "asdf" |
|
233 CPosLandmarkCategory* category1 = CPosLandmarkCategory::NewLC(); |
|
234 category1->SetCategoryNameL(_L("Dagis")); |
|
235 TPosLmItemId id1 = categoryManager->AddCategoryL(*category1); |
|
236 CleanupStack::PopAndDestroy(category1); |
|
237 |
|
238 CPosLandmarkCategory* category2 = CPosLandmarkCategory::NewLC(); |
|
239 category2->SetCategoryNameL(_L("BurgerKing")); |
|
240 TPosLmItemId id2 = categoryManager->AddCategoryL(*category2); |
|
241 CleanupStack::PopAndDestroy(category2); |
|
242 |
|
243 // Create "Frisör" belongs to landmark "TE, Lund" |
|
244 CPosLandmarkCategory* category3 = CPosLandmarkCategory::NewLC(); |
|
245 category3->SetCategoryNameL(_L("Frisör")); |
|
246 TPosLmItemId id3 = categoryManager->AddCategoryL(*category3); |
|
247 CleanupStack::PopAndDestroy(category3); |
|
248 |
|
249 // Remove global category with global id 1 |
|
250 // Belongs to "Kalles Hundgård" |
|
251 TPosLmItemId globalId = categoryManager->GetGlobalCategoryL(3000); |
|
252 ExecuteAndDeleteLD(categoryManager->RemoveCategoryL(globalId)); |
|
253 |
|
254 CPosLmItemIterator* catIter = categoryManager->CategoryIteratorL(); |
|
255 CleanupStack::PushL(catIter); |
|
256 TInt nrOfcategoriesBefore = catIter->NumOfItemsL(); |
|
257 CleanupStack::PopAndDestroy(catIter); |
|
258 |
|
259 iLog->Log(_L("iDatabase->ImportLandmarksL")); |
|
260 |
|
261 ExecuteAndDeleteLD(iDatabase->ImportLandmarksL(*iLandmarkParser, CPosLandmarkDatabase::EIncludeGlobalCategoryNames | CPosLandmarkDatabase::ESupressCategoryCreation| CPosLandmarkDatabase::EIncludeCategories)); |
|
262 |
|
263 |
|
264 catIter = categoryManager->CategoryIteratorL(); |
|
265 CleanupStack::PushL(catIter); |
|
266 TInt nrOfcategoriesAfter = catIter->NumOfItemsL(); |
|
267 CleanupStack::PopAndDestroy(catIter); |
|
268 if (nrOfcategoriesAfter != nrOfcategoriesBefore) |
|
269 { |
|
270 iLog->Log(_L("ERROR: Three categories should have been added")); |
|
271 iErrorsFound++; |
|
272 } |
|
273 |
|
274 // Check that landmark "TE, Lund" has "Frisör" and |
|
275 // landmark "asdf" has "Dagis" and "BurgerKing" (and also already existing global categories |
|
276 |
|
277 TBuf<100> buf; |
|
278 |
|
279 RArray<TPosLmItemId> categories; |
|
280 CleanupClosePushL(categories); |
|
281 |
|
282 TPosLmItemId idde1; |
|
283 |
|
284 // Check id=5 Te, Lund |
|
285 idde1 = categoryManager->GetCategoryL(_L("Frisör")); |
|
286 categories.Append(idde1); |
|
287 CheckLandmarkL(5, categories); |
|
288 categories.Reset(); |
|
289 |
|
290 // Check id=6 asdf |
|
291 idde1 = categoryManager->GetCategoryL(_L("Dagis")); |
|
292 |
|
293 categories.Append(idde1); |
|
294 |
|
295 CheckLandmarkL(6, categories); |
|
296 categories.Reset(); |
|
297 |
|
298 CleanupStack::PopAndDestroy(&categories); |
|
299 CleanupStack::PopAndDestroy(categoryManager); |
|
300 |
|
301 delete iLandmarkParser; |
|
302 iLandmarkParser = NULL; |
|
303 |
|
304 delete iDatabase; |
|
305 iDatabase = NULL; |
|
306 iLog->Log(_L("-------------------\n")); |
|
307 } |
|
308 |
|
309 // --------------------------------------------------------- |
|
310 // CPosTp161::CheckLandmarkL |
|
311 // |
|
312 // (other items were commented in a header). |
|
313 // --------------------------------------------------------- |
|
314 // |
|
315 void CPosTp161::CheckLandmarkL(TPosLmItemId aLandmarkId, RArray<TPosLmItemId> aCategoriesList) |
|
316 { |
|
317 iLog->Log(_L("CheckLandmarkL")); |
|
318 |
|
319 // Get landmark |
|
320 CPosLandmark* lm1 = iDatabase->ReadLandmarkLC(aLandmarkId); |
|
321 TPtrC name1; |
|
322 lm1->GetLandmarkName(name1); |
|
323 iLog->Log(name1); |
|
324 |
|
325 RArray<TPosLmItemId> categories; |
|
326 CleanupClosePushL(categories); |
|
327 // Get all categories attached to this landmark |
|
328 lm1->GetCategoriesL(categories); |
|
329 |
|
330 CPosLmCategoryManager* categoryManager = CPosLmCategoryManager::NewL(*iDatabase); |
|
331 CleanupStack::PushL(categoryManager); |
|
332 |
|
333 if ( aCategoriesList.Count() != categories.Count() ) |
|
334 { |
|
335 iLog->Log(_L("ERROR: Wrong number of categories, actual %d, expected %d"), |
|
336 categories.Count(), aCategoriesList.Count() ); |
|
337 iErrorsFound++; |
|
338 } |
|
339 |
|
340 for (TInt i=0;i<categories.Count();i++) |
|
341 { |
|
342 if (aCategoriesList.Find(categories[i]) != KErrNotFound) |
|
343 { |
|
344 iLog->Log(_L("Found")); |
|
345 } |
|
346 else |
|
347 { |
|
348 iLog->Log(_L("ERROR: Category '%S' was not found")); |
|
349 iErrorsFound++; |
|
350 } |
|
351 } |
|
352 |
|
353 CleanupStack::PopAndDestroy(categoryManager); |
|
354 |
|
355 CleanupStack::PopAndDestroy(&categories); |
|
356 CleanupStack::PopAndDestroy(lm1); |
|
357 } |
|
358 |
|
359 |
|
360 // End of File |