|
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 |
|
21 // INCLUDES |
|
22 #include "FT_CLandmarkTestProcedureBase.h" |
|
23 |
|
24 #include <EPos_CPosLandmarkDatabase.h> |
|
25 #include <EPos_CPosLandmark.h> |
|
26 #include <EPos_CPosLMCategoryManager.h> |
|
27 #include <EPos_CPosLandmarkCategory.h> |
|
28 #include <EPos_CPosLmDatabaseManager.h> |
|
29 #include <EPos_CPosLMOperation.h> |
|
30 #include <EPos_TPosLMSortPref.h> |
|
31 #include <EPos_CPosLmDisplayData.h> |
|
32 #include <EPos_CPosLmMultiDbSearch.h> |
|
33 #include <EPos_CPosLmDisplayItem.h> |
|
34 #include <LbsPosition.h> |
|
35 #include <lbs.h> |
|
36 #include <bautils.h> |
|
37 #include <s32file.h> |
|
38 #include "FT_LandmarkConstants.h" |
|
39 #include <e32def.h> |
|
40 #include <BaRsc2.H> |
|
41 #include <BaRsRead2.H> |
|
42 #include <BAUTILS.H> |
|
43 #include <utf.h> |
|
44 |
|
45 // CONSTANTS |
|
46 const TInt KBufSize=100; |
|
47 const TInt KMaxFieldLength = 80; |
|
48 |
|
49 const TInt KFirstNextStepLogLimit = 100000; //µs |
|
50 |
|
51 // CONSTANTS |
|
52 _LIT(KLt, "<"); |
|
53 _LIT(KGt, ">"); |
|
54 _LIT(KAmp, "&"); |
|
55 _LIT(KApos, "'"); |
|
56 _LIT(KQuot, "\""); |
|
57 |
|
58 _LIT(KLtXmlStr, "<"); |
|
59 _LIT(KGtXmlStr, ">"); |
|
60 _LIT(KAmpXmlStr, "&"); |
|
61 _LIT(KAposXmlStr, "'"); |
|
62 _LIT(KQuotXmlStr, """); |
|
63 |
|
64 // ================= MEMBER FUNCTIONS ======================= |
|
65 |
|
66 |
|
67 // ----------------------------------------------------------------------------- |
|
68 // CLandMarksTestModule::ConstructL |
|
69 // Symbian 2nd phase constructor can leave. |
|
70 // ----------------------------------------------------------------------------- |
|
71 // |
|
72 |
|
73 |
|
74 |
|
75 // C++ default constructor can NOT contain any code, that |
|
76 // might leave. |
|
77 // |
|
78 CLandmarkTestProcedureBase::CLandmarkTestProcedureBase( |
|
79 TInt aModuleId, CStifLogger* aLog) |
|
80 : iModuleId(aModuleId), |
|
81 KFirstDelayTime(5000), |
|
82 KIntervalTime(5000), |
|
83 iLog(aLog) |
|
84 { |
|
85 iUseLogFromThreadIsDisabled = EFalse; |
|
86 iFileSession.Connect(); |
|
87 } |
|
88 |
|
89 |
|
90 |
|
91 // Destructor |
|
92 CLandmarkTestProcedureBase::~CLandmarkTestProcedureBase() |
|
93 { |
|
94 iSearchResults.ResetAndDestroy(); |
|
95 iAreaSearchResults.ResetAndDestroy(); |
|
96 |
|
97 iCategorySearchResults.ResetAndDestroy(); |
|
98 iCategoryLandmarkSearchResults.ResetAndDestroy(); |
|
99 iFileSession.Close(); |
|
100 ReleaseLandmarkResources(); |
|
101 } |
|
102 |
|
103 // --------------------------------------------------------- |
|
104 // --------------------------------------------------------- |
|
105 // |
|
106 void CLandmarkTestProcedureBase::InitTestL() |
|
107 { |
|
108 } |
|
109 |
|
110 // --------------------------------------------------------- |
|
111 // --------------------------------------------------------- |
|
112 // |
|
113 void CLandmarkTestProcedureBase::StartL() |
|
114 { |
|
115 iLog->Log(_L("StartL not overridden")); |
|
116 } |
|
117 |
|
118 // --------------------------------------------------------- |
|
119 // --------------------------------------------------------- |
|
120 // |
|
121 void CLandmarkTestProcedureBase::CloseTest() |
|
122 { |
|
123 } |
|
124 |
|
125 // --------------------------------------------------------- |
|
126 // CLandmarkTestProcedureBase::RemoveAllLmDatabasesL |
|
127 // |
|
128 // (other items were commented in a header). |
|
129 // --------------------------------------------------------- |
|
130 // |
|
131 void CLandmarkTestProcedureBase::RemoveAllLmDatabasesL() |
|
132 { |
|
133 CPosLmDatabaseManager* dbManager = CPosLmDatabaseManager::NewL(); |
|
134 CleanupStack::PushL(dbManager); |
|
135 |
|
136 CDesCArray* dbArray = dbManager->ListDatabasesLC(); |
|
137 TInt count = dbArray->Count(); |
|
138 |
|
139 for (TInt i=0;i<count;i++) |
|
140 { |
|
141 iLog->Log((*dbArray)[i]); |
|
142 TRAPD(error,dbManager->DeleteDatabaseL((*dbArray)[i])); |
|
143 if (error != KErrNone) |
|
144 { |
|
145 if( error == KErrInUse ) |
|
146 { |
|
147 iLog->Log(_L("Cannot delete database since it is in use")); |
|
148 } |
|
149 else |
|
150 { |
|
151 iLog->Log(_L("Delete database leaves with error = %d"),error); |
|
152 User::Leave( error); |
|
153 } |
|
154 |
|
155 } |
|
156 } |
|
157 |
|
158 CleanupStack::PopAndDestroy(dbArray); |
|
159 CleanupStack::PopAndDestroy(dbManager); |
|
160 iLog->Log(_L("DeleteAllDatabasesL Done")); |
|
161 } |
|
162 |
|
163 // --------------------------------------------------------- |
|
164 // CLandmarkTestProcedureBase::RemoveDefaultDb |
|
165 // |
|
166 // (other items were commented in a header). |
|
167 // --------------------------------------------------------- |
|
168 // |
|
169 void CLandmarkTestProcedureBase::RemoveDefaultDbL() |
|
170 { |
|
171 |
|
172 |
|
173 |
|
174 iLog->Log(_L("In CLandmarkTestProcedureBase::RemoveDefaultDbL() ")); |
|
175 |
|
176 |
|
177 // Retrieve default db from db manager and then delete |
|
178 |
|
179 CPosLmDatabaseManager* manager = CPosLmDatabaseManager::NewL(); |
|
180 |
|
181 CleanupStack::PushL(manager); |
|
182 |
|
183 HBufC* defaultDbUri; |
|
184 defaultDbUri = manager->DefaultDatabaseUriLC(); |
|
185 |
|
186 TRAPD(err, manager->DeleteDatabaseL(*defaultDbUri)); |
|
187 if (err != KErrNone && err != KErrNotFound) |
|
188 { |
|
189 if( err == KErrInUse) |
|
190 { |
|
191 iLog->Log(_L("Cannot delete database since it is in use")); |
|
192 } |
|
193 else |
|
194 { |
|
195 iLog->Log(_L("Delete of the default landmarks database failed with %d"),err); |
|
196 User::Leave(err); |
|
197 } |
|
198 } |
|
199 |
|
200 CleanupStack::PopAndDestroy(defaultDbUri); |
|
201 CleanupStack::PopAndDestroy(manager); |
|
202 |
|
203 |
|
204 } |
|
205 |
|
206 // --------------------------------------------------------- |
|
207 // CLandmarkTestProcedureBase::CreateCategoryLC |
|
208 // |
|
209 // (other items were commented in a header). |
|
210 // --------------------------------------------------------- |
|
211 // |
|
212 CPosLandmarkCategory* CLandmarkTestProcedureBase::CreateCategoryLC(const TDesC& aName) |
|
213 { |
|
214 _LIT(KGetCategoryNameErr, "GetCategory name returns incorrect error code"); |
|
215 |
|
216 CPosLandmarkCategory* category = CPosLandmarkCategory::NewLC(); |
|
217 |
|
218 TInt err=0; |
|
219 TPtrC name; |
|
220 err=category->GetCategoryName(name); |
|
221 AssertTrueSecL(err == KErrNotFound, KGetCategoryNameErr); |
|
222 |
|
223 category->SetCategoryNameL(aName); |
|
224 |
|
225 category->SetIconL(KMbmFileName, KIconIndex, KIconMaskIndex); |
|
226 |
|
227 return category; |
|
228 } |
|
229 |
|
230 // --------------------------------------------------------- |
|
231 // CLandmarkTestProcedureBase::CreateLandmarkLC |
|
232 // |
|
233 // (other items were commented in a header). |
|
234 // --------------------------------------------------------- |
|
235 // |
|
236 CPosLandmark* CLandmarkTestProcedureBase::CreateLandmarkLC(const TDesC& aName) |
|
237 { |
|
238 _LIT(KGetNameErr, "GetLandmarks name returns incorrect error code"); |
|
239 _LIT(KFirstPositionFieldIdErr, "FirstPositionFieldId returns incorrect id"); |
|
240 |
|
241 |
|
242 CPosLandmark* landmark = CPosLandmark::NewLC(); |
|
243 TInt err=0; |
|
244 TPtrC name; |
|
245 err=landmark->GetLandmarkName(name); |
|
246 AssertTrueSecL(err == KErrNotFound, KGetNameErr); |
|
247 |
|
248 landmark->SetLandmarkNameL(aName); |
|
249 |
|
250 TCoordinate coord(KLatitude, KLongitude, KAltitude); |
|
251 TLocality loc(coord, KHorizontalAcc, KVerticalAcc); |
|
252 TTime time; |
|
253 time.UniversalTime(); |
|
254 TPosition pos(loc, time); |
|
255 landmark->SetPositionL(pos); |
|
256 |
|
257 landmark->SetIconL(KMbmFileName, KIconIndex, KIconMaskIndex); |
|
258 landmark->SetLandmarkDescriptionL(KDescription); |
|
259 landmark->SetCoverageRadius(KCoverageRadius); |
|
260 |
|
261 AssertTrueSecL(landmark->FirstPositionFieldId()==EPositionFieldNone, KFirstPositionFieldIdErr); |
|
262 |
|
263 AddFieldsL(landmark); |
|
264 |
|
265 _LIT(KCategoryName, "%S Category %d"); |
|
266 for(TInt i=0; i<KNoCategories; i++) |
|
267 { |
|
268 TBuf<100> name; |
|
269 HBufC* tmp = aName.Alloc(); |
|
270 name.Format(KCategoryName,tmp,i); |
|
271 delete tmp; |
|
272 landmark->AddCategoryL(CreateCategoryL(name)); |
|
273 } |
|
274 return landmark; |
|
275 |
|
276 } |
|
277 |
|
278 // --------------------------------------------------------- |
|
279 // CLandmarkTestProcedureBase::AddFieldsL |
|
280 // |
|
281 // (other items were commented in a header). |
|
282 // --------------------------------------------------------- |
|
283 // |
|
284 void CLandmarkTestProcedureBase::AddFieldsL(CPosLandmark* aLandmark) |
|
285 { |
|
286 _LIT(KPositionFieldNoneErr, "SetPositionFieldL should return KErrArgumnet with EPositionFieldNone"); |
|
287 |
|
288 aLandmark->SetPositionFieldL(EPositionFieldCountry, KCountry); |
|
289 aLandmark->SetPositionFieldL(EPositionFieldHorizontalSpeed, KHorizontalSpeed); |
|
290 // Removed from LBSFieldsIds.h |
|
291 |
|
292 aLandmark->SetPositionFieldL(EPositionFieldMediaLinks, KMediaLinks); |
|
293 aLandmark->SetPositionFieldL(EPositionFieldMediaLinksStart, KMediaLink1); |
|
294 |
|
295 TUint16 tmp = (TUint16)EPositionFieldMediaLinksStart; |
|
296 aLandmark->SetPositionFieldL(++tmp, KMediaLink2); |
|
297 aLandmark->SetPositionFieldL(++tmp, KMediaLink3); |
|
298 |
|
299 aLandmark->SetPositionFieldL(EPositionFieldIdLast, KOrientation); |
|
300 |
|
301 TRAPD(err, aLandmark->SetPositionFieldL(EPositionFieldNone, KMediaLink3)); |
|
302 AssertTrueSecL(err == KErrArgument, KPositionFieldNoneErr); |
|
303 |
|
304 } |
|
305 |
|
306 // --------------------------------------------------------- |
|
307 // CLandmarkTestProcedureBase::AddFields2L |
|
308 // |
|
309 // (other items were commented in a header). |
|
310 // --------------------------------------------------------- |
|
311 // |
|
312 void CLandmarkTestProcedureBase::AddFields2L(CPosLandmark* aLandmark) |
|
313 { |
|
314 aLandmark->SetPositionFieldL(EPositionFieldCountry, KCountry2); |
|
315 aLandmark->SetPositionFieldL(EPositionFieldHorizontalSpeed, KHorizontalSpeed2); |
|
316 // Removed from LBSFieldsIds.h |
|
317 |
|
318 aLandmark->SetPositionFieldL(EPositionFieldMediaLinksStart, KMediaLinks2); |
|
319 aLandmark->SetPositionFieldL(EPositionFieldMediaLinksStart+1, KMediaLink4); |
|
320 |
|
321 TUint16 tmp = (TUint16)EPositionFieldMediaLinksStart; |
|
322 aLandmark->SetPositionFieldL(++tmp, KMediaLink5); |
|
323 } |
|
324 |
|
325 // --------------------------------------------------------- |
|
326 // CLandmarkTestProcedureBase::AddFields3L |
|
327 // |
|
328 // (other items were commented in a header). |
|
329 // --------------------------------------------------------- |
|
330 // |
|
331 void CLandmarkTestProcedureBase::AddFields3L(CPosLandmark* aLandmark) |
|
332 { |
|
333 aLandmark->SetPositionFieldL(EPositionFieldCountryCode, KCountryCode); |
|
334 aLandmark->SetPositionFieldL(EPositionFieldState, KState); |
|
335 aLandmark->SetPositionFieldL(EPositionFieldCity, KCity); |
|
336 aLandmark->SetPositionFieldL(EPositionFieldDistrict, KDistrict); |
|
337 aLandmark->SetPositionFieldL(EPositionFieldStreet, KStreet); |
|
338 aLandmark->SetPositionFieldL(EPositionFieldStreetExtension, KStreetExtension); |
|
339 aLandmark->SetPositionFieldL(EPositionFieldLocationName, KLocationName); |
|
340 aLandmark->SetPositionFieldL(EPositionFieldPostalCode, KPostalCode); |
|
341 aLandmark->SetPositionFieldL(EPositionFieldLocality, KLocality); |
|
342 aLandmark->SetPositionFieldL(EPositionFieldCrossing1, KCrossing1); |
|
343 aLandmark->SetPositionFieldL(EPositionFieldCrossing2, KCrossing2); |
|
344 aLandmark->SetPositionFieldL(EPositionFieldBuildingName, KBuildingName); |
|
345 aLandmark->SetPositionFieldL(EPositionFieldBuildingFloor, KBuildingFloor); |
|
346 aLandmark->SetPositionFieldL(EPositionFieldBuildingRoom, KBuildingRoom); |
|
347 aLandmark->SetPositionFieldL(EPositionFieldBuildingZone, KBuildingZone); |
|
348 aLandmark->SetPositionFieldL(EPositionFieldBuildingTelephone, KBuildingTelephone); |
|
349 } |
|
350 |
|
351 |
|
352 // --------------------------------------------------------- |
|
353 // CLandmarkTestProcedureBase::CreateXMLLandmarkLC |
|
354 // |
|
355 // (other items were commented in a header). |
|
356 // --------------------------------------------------------- |
|
357 // |
|
358 CPosLandmark* CLandmarkTestProcedureBase::CreateXMLLandmarkLC(const TDesC& aName) |
|
359 { |
|
360 _LIT(KGetNameErr, "GetLandmarks name returns incorrect error code"); |
|
361 _LIT(KFirstPositionFieldIdErr, "FirstPositionFieldId returns incorrect id"); |
|
362 |
|
363 CPosLandmark* landmark = CPosLandmark::NewLC(); |
|
364 |
|
365 TInt err=0; |
|
366 TPtrC name; |
|
367 err=landmark->GetLandmarkName(name); |
|
368 AssertTrueSecL(err == KErrNotFound, KGetNameErr); |
|
369 |
|
370 landmark->SetLandmarkNameL(aName); |
|
371 |
|
372 TCoordinate coord(KLatitude, KLongitude, KAltitude); |
|
373 TLocality loc(coord, KHorizontalAcc, KVerticalAcc); |
|
374 TTime time; |
|
375 time.UniversalTime(); |
|
376 TPosition pos(loc, time); |
|
377 landmark->SetPositionL(pos); |
|
378 |
|
379 landmark->SetIconL(KMbmFileName, KIconIndex, KPosLmIconMaskNotUsed); |
|
380 |
|
381 landmark->SetLandmarkDescriptionL(KDescription); |
|
382 |
|
383 landmark->SetCoverageRadius(KCoverageRadius); |
|
384 |
|
385 AssertTrueSecL(landmark->FirstPositionFieldId()==EPositionFieldNone, KFirstPositionFieldIdErr); |
|
386 |
|
387 return landmark; |
|
388 } |
|
389 |
|
390 |
|
391 // --------------------------------------------------------- |
|
392 // CLandmarkTestProcedureBase::AddAllXMLFieldsL |
|
393 // |
|
394 // (other items were commented in a header). |
|
395 // --------------------------------------------------------- |
|
396 // |
|
397 void CLandmarkTestProcedureBase::AddAllXMLFieldsL(CPosLandmark* aLandmark) |
|
398 { |
|
399 aLandmark->SetPositionFieldL(EPositionFieldCountry, KCountry2); |
|
400 aLandmark->SetPositionFieldL(EPositionFieldCountryCode, KCountryCode); |
|
401 aLandmark->SetPositionFieldL(EPositionFieldState, KState); |
|
402 aLandmark->SetPositionFieldL(EPositionFieldCounty, KCounty); |
|
403 aLandmark->SetPositionFieldL(EPositionFieldCity, KCity); |
|
404 aLandmark->SetPositionFieldL(EPositionFieldDistrict, KDistrict); |
|
405 aLandmark->SetPositionFieldL(EPositionFieldPostalCode, KPostalCode); |
|
406 |
|
407 aLandmark->SetPositionFieldL(EPositionFieldCrossing1, KCrossing1); |
|
408 aLandmark->SetPositionFieldL(EPositionFieldCrossing2, KCrossing2); |
|
409 aLandmark->SetPositionFieldL(EPositionFieldStreet, KStreet); |
|
410 |
|
411 aLandmark->SetPositionFieldL(EPositionFieldBuildingName, KBuildingName); |
|
412 aLandmark->SetPositionFieldL(EPositionFieldBuildingFloor, KBuildingFloor); |
|
413 aLandmark->SetPositionFieldL(EPositionFieldBuildingRoom, KBuildingRoom); |
|
414 aLandmark->SetPositionFieldL(EPositionFieldBuildingZone, KBuildingZone); |
|
415 |
|
416 aLandmark->SetPositionFieldL(EPositionFieldStreetExtension, KStreetExtension); |
|
417 aLandmark->SetPositionFieldL(EPositionFieldBuildingTelephone, KBuildingTelephone); |
|
418 |
|
419 // Set number of medialink fields |
|
420 aLandmark->SetPositionFieldL(EPositionFieldMediaLinks, _L("13")); |
|
421 aLandmark->SetPositionFieldL(EPositionFieldMediaLinksStart, KXMLMediaLink1); |
|
422 aLandmark->SetPositionFieldL(EPositionFieldMediaLinksStart+1, KXMLMediaLink2); |
|
423 aLandmark->SetPositionFieldL(EPositionFieldMediaLinksStart+2, KXMLMediaLink3); |
|
424 aLandmark->SetPositionFieldL(EPositionFieldMediaLinksStart+3, KXMLMediaLink4); |
|
425 aLandmark->SetPositionFieldL(EPositionFieldMediaLinksStart+4, KXMLMediaLink5); |
|
426 aLandmark->SetPositionFieldL(EPositionFieldMediaLinksStart+5, KXMLMediaLink6); |
|
427 aLandmark->SetPositionFieldL(EPositionFieldMediaLinksStart+6, KXMLMediaLink7); |
|
428 aLandmark->SetPositionFieldL(EPositionFieldMediaLinksStart+7, KXMLMediaLink8); |
|
429 aLandmark->SetPositionFieldL(EPositionFieldMediaLinksStart+8, KXMLMediaLink9); |
|
430 aLandmark->SetPositionFieldL(EPositionFieldMediaLinksStart+9, KXMLMediaLink10); |
|
431 aLandmark->SetPositionFieldL(EPositionFieldMediaLinksStart+10, KXMLMediaLink11); |
|
432 aLandmark->SetPositionFieldL(EPositionFieldMediaLinksStart+11, KXMLMediaLink12); |
|
433 aLandmark->SetPositionFieldL(EPositionFieldMediaLinksStart+12, KXMLMediaLink13); |
|
434 |
|
435 |
|
436 } |
|
437 |
|
438 // --------------------------------------------------------- |
|
439 // CLandmarkTestProcedureBase::AddAllXMLFieldsL |
|
440 // |
|
441 // (other items were commented in a header). |
|
442 // --------------------------------------------------------- |
|
443 // |
|
444 void CLandmarkTestProcedureBase::AddAllEmptyXMLFieldsL(CPosLandmark* aLandmark) |
|
445 { |
|
446 aLandmark->SetPositionFieldL(EPositionFieldCountry, _L("")); |
|
447 aLandmark->SetPositionFieldL(EPositionFieldCountryCode, _L("")); |
|
448 aLandmark->SetPositionFieldL(EPositionFieldState, _L("")); |
|
449 aLandmark->SetPositionFieldL(EPositionFieldCounty, _L("")); |
|
450 aLandmark->SetPositionFieldL(EPositionFieldCity, _L("")); |
|
451 aLandmark->SetPositionFieldL(EPositionFieldDistrict, _L("")); |
|
452 aLandmark->SetPositionFieldL(EPositionFieldPostalCode, _L("")); |
|
453 |
|
454 aLandmark->SetPositionFieldL(EPositionFieldCrossing1, _L("")); |
|
455 aLandmark->SetPositionFieldL(EPositionFieldCrossing2, _L("")); |
|
456 aLandmark->SetPositionFieldL(EPositionFieldStreet, _L("")); |
|
457 |
|
458 aLandmark->SetPositionFieldL(EPositionFieldBuildingName, _L("")); |
|
459 aLandmark->SetPositionFieldL(EPositionFieldBuildingFloor, _L("")); |
|
460 aLandmark->SetPositionFieldL(EPositionFieldBuildingRoom, _L("")); |
|
461 aLandmark->SetPositionFieldL(EPositionFieldBuildingZone, _L("")); |
|
462 |
|
463 aLandmark->SetPositionFieldL(EPositionFieldStreetExtension, _L("")); |
|
464 aLandmark->SetPositionFieldL(EPositionFieldBuildingTelephone, _L("")); |
|
465 |
|
466 aLandmark->SetPositionFieldL(EPositionFieldMediaLinks, _L("0")); |
|
467 |
|
468 |
|
469 aLandmark->SetLandmarkDescriptionL(_L("")); |
|
470 |
|
471 |
|
472 } |
|
473 |
|
474 //--------------------------------------------------------- |
|
475 // CLandmarkTestProcedureBase::WriteBufferToFileL |
|
476 // |
|
477 // (other items were commented in a header). |
|
478 // --------------------------------------------------------- |
|
479 void CLandmarkTestProcedureBase::WriteBufferToFileL(const CBufBase* aBuffer, const TDesC& aFile) |
|
480 { |
|
481 iFileSession.Delete(aFile); |
|
482 |
|
483 RFile file; |
|
484 file.Create(iFileSession, aFile, EFileWrite); |
|
485 CleanupClosePushL(file); |
|
486 |
|
487 RFileWriteStream stream(file); |
|
488 CleanupClosePushL(stream); |
|
489 |
|
490 TInt pos=0; |
|
491 TInt size = aBuffer->Size(); |
|
492 TInt length; |
|
493 if (size < 255 ) |
|
494 { |
|
495 length = size; |
|
496 } |
|
497 else |
|
498 { |
|
499 length = 255; |
|
500 } |
|
501 |
|
502 while (pos < size) |
|
503 { |
|
504 TBuf8<255> xml; |
|
505 |
|
506 aBuffer->Read(pos, xml, length); |
|
507 |
|
508 stream.WriteL(xml); |
|
509 |
|
510 pos += 255; |
|
511 |
|
512 if (pos + 255 > size ) |
|
513 { |
|
514 length = size - pos; |
|
515 } |
|
516 } |
|
517 |
|
518 CleanupStack::PopAndDestroy(2, &file); |
|
519 } |
|
520 |
|
521 //--------------------------------------------------------- |
|
522 // CLandmarkTestProcedureBase::CreateCategoryL |
|
523 // |
|
524 // (other items were commented in a header). |
|
525 // --------------------------------------------------------- |
|
526 // |
|
527 TPosLmItemId CLandmarkTestProcedureBase::CreateCategoryL(const TDesC& aName) |
|
528 { |
|
529 _LIT(KCategoryIdErr, "Category id is incorrect"); |
|
530 |
|
531 CPosLandmarkDatabase* lmd = OpenDatabaseLC(); |
|
532 |
|
533 CPosLmCategoryManager* cm = CPosLmCategoryManager::NewL(*lmd); |
|
534 CleanupStack::PushL(cm); |
|
535 |
|
536 TPosLmItemId id=0; |
|
537 |
|
538 |
|
539 |
|
540 CPosLandmarkCategory* lmc = CPosLandmarkCategory::NewLC(); |
|
541 lmc->SetCategoryNameL(aName); |
|
542 |
|
543 id = cm->AddCategoryL(*lmc); |
|
544 |
|
545 AssertTrueSecL(id == lmc->CategoryId(), KCategoryIdErr); |
|
546 CleanupStack::PopAndDestroy(lmc); |
|
547 |
|
548 |
|
549 CleanupStack::PopAndDestroy(2, lmd); |
|
550 |
|
551 return id; |
|
552 } |
|
553 |
|
554 // --------------------------------------------------------- |
|
555 // CLandmarkTestProcedureBase::OpenLandmarkDatabaseLC |
|
556 // |
|
557 // (other items were commented in a header). |
|
558 // --------------------------------------------------------- |
|
559 // |
|
560 CPosLandmarkDatabase* CLandmarkTestProcedureBase::OpenDatabaseLC() |
|
561 { |
|
562 CPosLandmarkDatabase* lmd = CPosLandmarkDatabase::OpenL(); |
|
563 CleanupStack::PushL(lmd); |
|
564 |
|
565 if (lmd->IsInitializingNeeded()) |
|
566 { |
|
567 CPosLmOperation* op = lmd->InitializeL(); // Synchronous since no argument |
|
568 op->ExecuteL(); |
|
569 delete op; |
|
570 } |
|
571 return lmd; |
|
572 } |
|
573 |
|
574 // --------------------------------------------------------- |
|
575 // CLandmarkTestProcedureBase::CompareLandmarksL |
|
576 // |
|
577 // (other items were commented in a header). |
|
578 // --------------------------------------------------------- |
|
579 // |
|
580 void CLandmarkTestProcedureBase::CompareLandmarksL(const CPosLandmark& aSource, const CPosLandmark& aTarget) |
|
581 { |
|
582 _LIT(KCompareIdErr, "Landmark id's are not equal"); |
|
583 _LIT(KComparePositionErr, "Landmark positions are not equal"); |
|
584 _LIT(KComparePositionErr1, "Landmark longitude are not equal"); |
|
585 _LIT(KComparePositionErr2, "Landmark latitude are not equal"); |
|
586 _LIT(KComparePositionErr3, "Landmark horizontal accuracy are not equal"); |
|
587 _LIT(KComparePositionErr4, "Landmark vertical accuracy are not equal"); |
|
588 _LIT(KComparePositionErr5, "Landmark altitude are not equal"); |
|
589 _LIT(KCompareNameErr, "Landmark names are not equal"); |
|
590 _LIT(KCompareCoverageRadiusErr, "Landmark coverage radiuses are not equal"); |
|
591 _LIT(KCompareIconErr, "Landmark icons are not equal"); |
|
592 _LIT(KCompareDescErr, "Landmark descriptions are not equal"); |
|
593 _LIT(KCompareNoPositionFieldsErr, "Landmark no positioning fields are not equal"); |
|
594 _LIT(KComparePositionFieldIdErr, "Position field id's are not equal"); |
|
595 _LIT(KComparePositionFieldErr, "Position fields are not equal"); |
|
596 _LIT(KCompareNumOfCategoriesErr, "Number of categories is not equal"); |
|
597 _LIT(KCompareSetOfCategoriesErr, "Set of categories is not equal"); |
|
598 |
|
599 TInt sourceErr, targetErr; |
|
600 TPtrC sourceName; |
|
601 sourceErr=aSource.GetLandmarkName(sourceName); |
|
602 |
|
603 TPtrC targetName; |
|
604 targetErr=aTarget.GetLandmarkName(targetName); |
|
605 |
|
606 AssertTrueSecL(targetErr == sourceErr, KCompareNameErr); |
|
607 if (!sourceErr) |
|
608 { |
|
609 AssertTrueSecL(sourceName.Compare(targetName) == KErrNone, KCompareNameErr); |
|
610 AssertTrueSecL(aSource.LandmarkId() == aTarget.LandmarkId(), KCompareIdErr); |
|
611 } |
|
612 |
|
613 TLocality sourceLoc, targetLoc; |
|
614 sourceErr = aSource.GetPosition(sourceLoc); |
|
615 targetErr = aTarget.GetPosition(targetLoc); |
|
616 AssertTrueSecL(sourceErr == targetErr, KComparePositionErr); |
|
617 if (!sourceErr) |
|
618 { |
|
619 // Difference between WINS and WINSCW/TARGET |
|
620 // For WINS comparing TReal NaN == NaN evaluates to true |
|
621 // but for TARGET and WINSCW it evaluates to false |
|
622 TRealX vertAcc(sourceLoc.VerticalAccuracy()); |
|
623 TRealX targetVertAcc(targetLoc.VerticalAccuracy()); |
|
624 TRealX horAcc(sourceLoc.HorizontalAccuracy()); |
|
625 TRealX targetHorAcc(targetLoc.HorizontalAccuracy()); |
|
626 TRealX horAlt(sourceLoc.Altitude()); |
|
627 TRealX targetHorAlt(targetLoc.Altitude()); |
|
628 |
|
629 AssertTrueSecL(sourceLoc.Longitude() == targetLoc.Longitude(),KComparePositionErr1); |
|
630 AssertTrueSecL(sourceLoc.Latitude() == targetLoc.Latitude(), KComparePositionErr2); |
|
631 |
|
632 AssertTrueSecL((horAcc.IsNaN() && targetHorAcc.IsNaN()) || horAcc == targetHorAcc, KComparePositionErr3); |
|
633 AssertTrueSecL((vertAcc.IsNaN() && targetVertAcc.IsNaN()) || vertAcc == targetVertAcc, KComparePositionErr4); |
|
634 AssertTrueSecL((targetHorAlt.IsNaN() && horAlt.IsNaN()) || horAlt == targetHorAlt , KComparePositionErr5); |
|
635 } |
|
636 |
|
637 TReal32 sourceR, targetR; |
|
638 sourceErr = aSource.GetCoverageRadius(sourceR); |
|
639 targetErr = aTarget.GetCoverageRadius(targetR); |
|
640 AssertTrueSecL(sourceErr == targetErr, KCompareCoverageRadiusErr); |
|
641 if (!sourceErr) |
|
642 { |
|
643 AssertTrueSecL(sourceR == targetR, KCompareCoverageRadiusErr); |
|
644 } |
|
645 |
|
646 TPtrC sourceMbmFileName, targetMbmFileName; |
|
647 TInt sourceIndex, targetIndex; |
|
648 TInt sourceMaskIndex, targetMaskIndex; |
|
649 |
|
650 sourceErr = aSource.GetIcon(sourceMbmFileName, sourceIndex, sourceMaskIndex); |
|
651 targetErr = aTarget.GetIcon(targetMbmFileName, targetIndex, targetMaskIndex); |
|
652 |
|
653 AssertTrueSecL(sourceErr == targetErr, KCompareIconErr); |
|
654 if (!sourceErr) |
|
655 { |
|
656 AssertTrueSecL(sourceMbmFileName.Compare(targetMbmFileName) == KErrNone, KCompareIconErr); |
|
657 AssertTrueSecL(sourceIndex == targetIndex, KCompareIconErr); |
|
658 } |
|
659 |
|
660 TPtrC sourceDesc, targetDesc; |
|
661 sourceErr = aSource.GetLandmarkDescription(sourceDesc); |
|
662 targetErr = aTarget.GetLandmarkDescription(targetDesc); |
|
663 AssertTrueSecL(sourceErr == targetErr, KCompareDescErr); |
|
664 if (!sourceErr) |
|
665 { |
|
666 AssertTrueSecL(sourceDesc.Compare(targetDesc) == KErrNone, KCompareDescErr); |
|
667 } |
|
668 |
|
669 AssertTrueSecL(aSource.NumOfAvailablePositionFields() == aTarget.NumOfAvailablePositionFields(), KCompareNoPositionFieldsErr); |
|
670 |
|
671 TPositionFieldId sourceFieldId = aSource.FirstPositionFieldId(); |
|
672 TPositionFieldId targetFieldId = aTarget.FirstPositionFieldId(); |
|
673 AssertTrueSecL(sourceFieldId == targetFieldId, KComparePositionFieldIdErr); |
|
674 |
|
675 while (sourceFieldId != EPositionFieldNone) |
|
676 { |
|
677 TPtrC sourceValue, targetValue; |
|
678 |
|
679 aSource.GetPositionField(sourceFieldId, sourceValue); |
|
680 aTarget.GetPositionField(targetFieldId, targetValue); |
|
681 |
|
682 AssertTrueSecL(sourceValue.Compare(targetValue) == KErrNone, KComparePositionFieldErr); |
|
683 |
|
684 sourceFieldId = aSource.NextPositionFieldId(sourceFieldId); |
|
685 targetFieldId = aTarget.NextPositionFieldId(targetFieldId); |
|
686 |
|
687 AssertTrueSecL(sourceFieldId == targetFieldId, KComparePositionFieldIdErr); |
|
688 } |
|
689 |
|
690 RArray<TPosLmItemId> sourceCategories; |
|
691 CleanupClosePushL(sourceCategories); |
|
692 RArray<TPosLmItemId> targetCategories; |
|
693 CleanupClosePushL(targetCategories); |
|
694 |
|
695 aSource.GetCategoriesL(sourceCategories); |
|
696 aTarget.GetCategoriesL(targetCategories); |
|
697 |
|
698 AssertTrueSecL(sourceCategories.Count() == targetCategories.Count(), KCompareNumOfCategoriesErr); |
|
699 |
|
700 for(TInt i=0; i<sourceCategories.Count(); i++) |
|
701 { |
|
702 TInt targetPos = targetCategories.Find( sourceCategories[i] ); |
|
703 AssertTrueSecL( targetPos >= 0, KCompareSetOfCategoriesErr ); |
|
704 } |
|
705 CleanupStack::PopAndDestroy(2, &sourceCategories); |
|
706 } |
|
707 |
|
708 // --------------------------------------------------------- |
|
709 // CPSYTesterTestProcedureBase::CompareCategoriesL |
|
710 // |
|
711 // (other items were commented in a header). |
|
712 // --------------------------------------------------------- |
|
713 // |
|
714 void CLandmarkTestProcedureBase::CompareCategoriesL( |
|
715 const TPosLmItemId& aSourceId, |
|
716 const TPosLmItemId& aTargetId) |
|
717 { |
|
718 |
|
719 CPosLmCategoryManager* cm = CPosLmCategoryManager::NewL(*iDatabase); |
|
720 CleanupStack::PushL(cm); |
|
721 |
|
722 CPosLandmarkCategory* source = cm->ReadCategoryLC(aSourceId); |
|
723 CPosLandmarkCategory* target = cm->ReadCategoryLC(aTargetId); |
|
724 |
|
725 CompareCategoriesL(*source, *target); |
|
726 |
|
727 |
|
728 CleanupStack::PopAndDestroy(3); |
|
729 } |
|
730 |
|
731 // --------------------------------------------------------- |
|
732 // CPSYTesterTestProcedureBase::CompareCategoriesL |
|
733 // |
|
734 // (other items were commented in a header). |
|
735 // --------------------------------------------------------- |
|
736 // |
|
737 void CLandmarkTestProcedureBase::CompareCategoriesL( |
|
738 const CPosLandmarkCategory& aSource, |
|
739 const CPosLandmarkCategory& aTarget) |
|
740 { |
|
741 _LIT(KCompareCategoryNameErr, "Category names are not equal"); |
|
742 _LIT(KCompareCategoryIdErr, "Category id's are not equal"); |
|
743 _LIT(KCompareGlobalCategoryIdErr, "Category global id's are not equal"); |
|
744 _LIT(KCompareCategoryIconErr, "Category icons are not equal"); |
|
745 |
|
746 TInt sourceErr, targetErr; |
|
747 TPtrC sourceName, targetName; |
|
748 sourceErr = aSource.GetCategoryName(sourceName); |
|
749 targetErr = aTarget.GetCategoryName(targetName); |
|
750 |
|
751 AssertTrueSecL(sourceErr == targetErr, KCompareCategoryNameErr); |
|
752 AssertTrueSecL(sourceName.Compare(targetName) == KErrNone, KCompareCategoryNameErr); |
|
753 |
|
754 AssertTrueSecL(aSource.CategoryId() == aTarget.CategoryId(), KCompareCategoryIdErr); |
|
755 AssertTrueSecL(aSource.GlobalCategory() == aTarget.GlobalCategory(), KCompareGlobalCategoryIdErr); |
|
756 |
|
757 TPtrC sourceMbmFileName, targetMbmFileName; |
|
758 TInt sourceIndex, targetIndex; |
|
759 TInt sourceMaskIndex, targetMaskIndex; |
|
760 |
|
761 sourceErr = aSource.GetIcon(sourceMbmFileName, sourceIndex, sourceMaskIndex); |
|
762 targetErr = aTarget.GetIcon(targetMbmFileName, targetIndex, targetMaskIndex); |
|
763 |
|
764 AssertTrueSecL(sourceErr == targetErr, KCompareCategoryIconErr); |
|
765 if (!sourceErr) |
|
766 { |
|
767 AssertTrueSecL(sourceMbmFileName.Compare(targetMbmFileName) == KErrNone, KCompareCategoryIconErr); |
|
768 AssertTrueSecL(sourceIndex == targetIndex, KCompareCategoryIconErr); |
|
769 } |
|
770 } |
|
771 |
|
772 // --------------------------------------------------------- |
|
773 // CLandmarkTestProcedureBase::CompareXMLLandmarksL |
|
774 // |
|
775 // (other items were commented in a header). |
|
776 // --------------------------------------------------------- |
|
777 // |
|
778 TInt CLandmarkTestProcedureBase::CompareXMLLandmarksL(const CPosLandmark& aSource, const CPosLandmark& aTarget, TBool aDebug) |
|
779 { |
|
780 _LIT(KComparePositionErr, "Landmark positions are not equal"); |
|
781 _LIT(KComparePositionErr1, "Landmark longitude are not equal"); |
|
782 _LIT(KComparePositionErr2, "Landmark latitude are not equal"); |
|
783 _LIT(KComparePositionErr3, "Landmark horizontal accuracy are not equal"); |
|
784 _LIT(KComparePositionErr4, "Landmark vertical accuracy are not equal"); |
|
785 _LIT(KComparePositionErr5, "Landmark altitude are not equal"); |
|
786 _LIT(KCompareNameErr, "Landmark names are not equal, src %S, trg %S"); |
|
787 _LIT(KCompareCoverageRadiusErr, "Landmark coverage radiuses are not equal"); |
|
788 _LIT(KCompareDescErr, "Landmark descriptions are not equal"); |
|
789 _LIT(KCompareNoPositionFieldsErr, "ERROR: Landmark nr of positioning fields are not equal"); |
|
790 _LIT(KComparePositionFieldIdErr, "ERROR: Position field id's are not equal, src '%d', trg '%d'"); |
|
791 _LIT(KComparePositionFieldErr, "ERROR: Position fields are not equal, src '%S', trg '%S'"); |
|
792 |
|
793 if (aDebug) iLog->Log(_L("CompareXMLLandmarksL")); |
|
794 |
|
795 TInt errorsFound = KErrNone; |
|
796 |
|
797 TInt sourceErr, targetErr; |
|
798 TPtrC sourceName; |
|
799 sourceErr=aSource.GetLandmarkName(sourceName); |
|
800 //iLog->Log(sourceName); |
|
801 |
|
802 TPtrC targetName; |
|
803 targetErr=aTarget.GetLandmarkName(targetName); |
|
804 //iLog->Log(targetName); |
|
805 |
|
806 AssertTrueSecL(targetErr == sourceErr, KCompareNameErr); |
|
807 if (!sourceErr) |
|
808 { |
|
809 if (sourceName.Compare(targetName) != KErrNone) |
|
810 { |
|
811 iLog->Log(KCompareNameErr, &sourceName, &targetName); |
|
812 } |
|
813 } |
|
814 |
|
815 TLocality sourceLoc, targetLoc; |
|
816 sourceErr = aSource.GetPosition(sourceLoc); |
|
817 targetErr = aTarget.GetPosition(targetLoc); |
|
818 AssertTrueSecL(sourceErr == targetErr, KComparePositionErr); |
|
819 if (!sourceErr) |
|
820 { |
|
821 // Difference between WINS and WINSCW/TARGET |
|
822 // For WINS comparing TReal NaN == NaN evaluates to true |
|
823 // but for TARGET and WINSCW it evaluates to false |
|
824 TRealX vertAcc(sourceLoc.VerticalAccuracy()); |
|
825 TRealX targetVertAcc(targetLoc.VerticalAccuracy()); |
|
826 TRealX horAcc(sourceLoc.HorizontalAccuracy()); |
|
827 TRealX targetHorAcc(targetLoc.HorizontalAccuracy()); |
|
828 TRealX horAlt(sourceLoc.Altitude()); |
|
829 TRealX targetHorAlt(targetLoc.Altitude()); |
|
830 |
|
831 AssertTrueSecL(sourceLoc.Longitude() == targetLoc.Longitude(),KComparePositionErr1); |
|
832 AssertTrueSecL(sourceLoc.Latitude() == targetLoc.Latitude(), KComparePositionErr2); |
|
833 |
|
834 AssertTrueSecL((horAcc.IsNaN() && targetHorAcc.IsNaN()) || horAcc == targetHorAcc, KComparePositionErr3); |
|
835 AssertTrueSecL((vertAcc.IsNaN() && targetVertAcc.IsNaN()) || vertAcc == targetVertAcc, KComparePositionErr4); |
|
836 AssertTrueSecL((targetHorAlt.IsNaN() && horAlt.IsNaN()) || horAlt == targetHorAlt , KComparePositionErr5); |
|
837 } |
|
838 |
|
839 TReal32 sourceR, targetR; |
|
840 sourceErr = aSource.GetCoverageRadius(sourceR); |
|
841 targetErr = aTarget.GetCoverageRadius(targetR); |
|
842 AssertTrueSecL(sourceErr == targetErr, KCompareCoverageRadiusErr); |
|
843 if (!sourceErr) |
|
844 { |
|
845 AssertTrueSecL(sourceR == targetR, KCompareCoverageRadiusErr); |
|
846 } |
|
847 TPtrC sourceDesc, targetDesc; |
|
848 sourceErr = aSource.GetLandmarkDescription(sourceDesc); |
|
849 targetErr = aTarget.GetLandmarkDescription(targetDesc); |
|
850 AssertTrueSecL(sourceErr == targetErr, KCompareDescErr); |
|
851 if (!sourceErr) |
|
852 { |
|
853 AssertTrueSecL(sourceDesc.Compare(targetDesc) == KErrNone, KCompareDescErr); |
|
854 } |
|
855 |
|
856 if (aSource.NumOfAvailablePositionFields() != aTarget.NumOfAvailablePositionFields()) |
|
857 { |
|
858 iLog->Log(KCompareNoPositionFieldsErr); |
|
859 errorsFound++; |
|
860 //PrintLandmarkFieldsL(aSource); |
|
861 //PrintLandmarkFieldsL(aTarget); |
|
862 } |
|
863 |
|
864 TPositionFieldId sourceFieldId = aSource.FirstPositionFieldId(); |
|
865 TPositionFieldId targetFieldId = aTarget.FirstPositionFieldId(); |
|
866 |
|
867 if (sourceFieldId != targetFieldId) |
|
868 { |
|
869 iLog->Log(KComparePositionFieldIdErr); |
|
870 errorsFound++; |
|
871 } |
|
872 |
|
873 while (sourceFieldId != EPositionFieldNone) |
|
874 { |
|
875 TPtrC sourceValue, targetValue; |
|
876 |
|
877 HBufC* buf1 = NULL; |
|
878 HBufC* buf2 = NULL; |
|
879 |
|
880 aSource.GetPositionField(sourceFieldId, sourceValue); |
|
881 aTarget.GetPositionField(sourceFieldId, targetValue); |
|
882 |
|
883 // Remove // from string starting with // |
|
884 // The encoder adds "//" to medialinks with unknown mimetype |
|
885 if (sourceValue.Find(_L("//")) == 0) |
|
886 { |
|
887 TPtrC sourceValue2 = sourceValue.Mid(2); |
|
888 buf1 = sourceValue2.Alloc(); |
|
889 } |
|
890 else buf1 = sourceValue.Alloc(); |
|
891 CleanupStack::PushL(buf1); |
|
892 |
|
893 // Remove // from string starting with // |
|
894 // The encoder adds "//" to medialinks with unknown mimetype |
|
895 if (targetValue.Find(_L("//")) == 0) |
|
896 { |
|
897 TPtrC targetValue2 = targetValue.Mid(2); |
|
898 buf2 = targetValue2.Alloc(); |
|
899 } |
|
900 else buf2 = targetValue.Alloc(); |
|
901 CleanupStack::PushL(buf2); |
|
902 |
|
903 // Check if strings are equal |
|
904 if (buf1->Des().Compare(buf2->Des())) |
|
905 { |
|
906 iLog->Log(KComparePositionFieldErr, sourceFieldId, &sourceValue, &targetValue); |
|
907 errorsFound++; |
|
908 } |
|
909 |
|
910 CleanupStack::PopAndDestroy(buf2); |
|
911 CleanupStack::PopAndDestroy(buf1); |
|
912 |
|
913 sourceFieldId = aSource.NextPositionFieldId(sourceFieldId); |
|
914 } |
|
915 |
|
916 return errorsFound; |
|
917 } |
|
918 |
|
919 // --------------------------------------------------------- |
|
920 // CLandmarkTestProcedureBase::CompareXMLCategoriesL |
|
921 // |
|
922 // (other items were commented in a header). |
|
923 // --------------------------------------------------------- |
|
924 // |
|
925 TInt CLandmarkTestProcedureBase::CompareXMLCategoriesL( |
|
926 const CPosLandmarkCategory& aSource, |
|
927 const CPosLandmarkCategory& aTarget, TBool /*aDebug*/) |
|
928 { |
|
929 _LIT(KCompareCategoryNameErr1, "ERROR: Category names not correct found"); |
|
930 _LIT(KCompareCategoryNameErr2, "ERROR: Category names are not equal"); |
|
931 TInt errorsFound = KErrNone; |
|
932 iLog->Log(_L("CompareXMLCategoriesL")); |
|
933 |
|
934 TInt sourceErr, targetErr; |
|
935 TPtrC sourceName, targetName; |
|
936 sourceErr = aSource.GetCategoryName(sourceName); |
|
937 targetErr = aTarget.GetCategoryName(targetName); |
|
938 |
|
939 AssertTrueSecL(sourceErr == targetErr, KCompareCategoryNameErr1); |
|
940 iLog->Log(_L("Source %S, target %S"), &sourceName, &targetName); |
|
941 |
|
942 if (sourceName.Compare(targetName) != KErrNone) |
|
943 { |
|
944 iLog->Log(KCompareCategoryNameErr2); |
|
945 errorsFound++; |
|
946 } |
|
947 |
|
948 if (aSource.GlobalCategory() != aTarget.GlobalCategory()) |
|
949 { |
|
950 iLog->Log(KCompareCategoryNameErr2); |
|
951 errorsFound++; |
|
952 } |
|
953 |
|
954 iLog->Log(_L("CompareXMLCategoriesL Done")); |
|
955 return errorsFound; |
|
956 } |
|
957 |
|
958 |
|
959 // --------------------------------------------------------- |
|
960 // CLandmarkTestProcedureBase::AssertTrueSecL |
|
961 // |
|
962 // (other items were commented in a header). |
|
963 // --------------------------------------------------------- |
|
964 // |
|
965 void CLandmarkTestProcedureBase::AssertTrueSecL(TBool aCondition, const TDesC& aErrorMsg, TInt aErrorCode) |
|
966 { |
|
967 if (!aCondition) |
|
968 { |
|
969 TBuf<KBufSize> buf; |
|
970 buf.Format(aErrorMsg, aErrorCode); |
|
971 // Necessary to separate the case when aErrorCode==KErrNone |
|
972 |
|
973 if (aErrorCode == KErrNone) |
|
974 { |
|
975 iLog->Log(buf); |
|
976 User::Leave(KErrNone); |
|
977 |
|
978 } |
|
979 else |
|
980 { |
|
981 iLog->Log(buf); |
|
982 User::Leave(aErrorCode); |
|
983 } |
|
984 } |
|
985 } |
|
986 |
|
987 // --------------------------------------------------------- |
|
988 // CLandmarkTestProcedureBase::CheckDefaultDbExitsL |
|
989 // |
|
990 // (other items were commented in a header). |
|
991 // --------------------------------------------------------- |
|
992 // |
|
993 void CLandmarkTestProcedureBase::CheckDefaultDbExistL() |
|
994 { |
|
995 _LIT(KDefaultDbMissingErr, "Default landmarks db is missing, open returns %d"); |
|
996 |
|
997 RFile file; |
|
998 TInt err = file.Open(iFileSession, KDefaultDb, EFileRead); |
|
999 file.Close(); |
|
1000 AssertTrueSecL(err==KErrNone, KDefaultDbMissingErr, err); |
|
1001 } |
|
1002 |
|
1003 // --------------------------------------------------------- |
|
1004 // CLandmarkTestProcedureBase::BackupDbFileL() |
|
1005 // |
|
1006 // (other items were commented in a header). |
|
1007 // --------------------------------------------------------- |
|
1008 // |
|
1009 CPosLandmarkDatabase* CLandmarkTestProcedureBase::BackupDbFileL() |
|
1010 { |
|
1011 |
|
1012 CPosLmDatabaseManager* manager = CPosLmDatabaseManager::NewL(); |
|
1013 CleanupStack::PushL(manager); |
|
1014 |
|
1015 HBufC* defaultDbUri = manager->DefaultDatabaseUriLC(); |
|
1016 TBuf<255> buf; |
|
1017 // Extract URI except characters ".ldb" |
|
1018 buf.Append(defaultDbUri->Left(defaultDbUri->Length()-4)); |
|
1019 buf.Append(_L("COPY.LDB")); |
|
1020 // Delete in case it already exist |
|
1021 TRAPD(err, manager->DeleteDatabaseL(buf)); |
|
1022 if (err != KErrNone && err != KErrNotFound) iLog->Log(_L("Could not delete file")); |
|
1023 manager->CopyDatabaseL(*defaultDbUri, buf); |
|
1024 |
|
1025 CleanupStack::PopAndDestroy(defaultDbUri); |
|
1026 CleanupStack::PopAndDestroy(manager); |
|
1027 return CPosLandmarkDatabase::OpenL(); |
|
1028 } |
|
1029 |
|
1030 // --------------------------------------------------------- |
|
1031 // CLandmarkTestProcedureBase::RestoreDbFileL() |
|
1032 // |
|
1033 // (other items were commented in a header). |
|
1034 // --------------------------------------------------------- |
|
1035 // |
|
1036 CPosLandmarkDatabase* CLandmarkTestProcedureBase::RestoreDbFileL() |
|
1037 { |
|
1038 |
|
1039 |
|
1040 CPosLmDatabaseManager* manager = CPosLmDatabaseManager::NewL(); |
|
1041 CleanupStack::PushL(manager); |
|
1042 |
|
1043 HBufC* defaultDbUri = manager->DefaultDatabaseUriLC(); |
|
1044 TBuf<255> buf; |
|
1045 // Extract URI except characters ".ldb" |
|
1046 buf.Append(defaultDbUri->Left(defaultDbUri->Length()-4)); |
|
1047 buf.Append(_L("COPY.LDB")); |
|
1048 // Delete in case it already exist |
|
1049 TRAPD(err, manager->DeleteDatabaseL(*defaultDbUri)); |
|
1050 if (err != KErrNone && err != KErrNotFound) iLog->Log(_L("Could not delete file")); |
|
1051 manager->CopyDatabaseL(buf, *defaultDbUri); |
|
1052 |
|
1053 CleanupStack::PopAndDestroy(defaultDbUri); |
|
1054 CleanupStack::PopAndDestroy(manager); |
|
1055 return CPosLandmarkDatabase::OpenL(); |
|
1056 } |
|
1057 |
|
1058 // --------------------------------------------------------- |
|
1059 // CLandmarkTestProcedureBase::CopyDbFileL |
|
1060 // |
|
1061 // (other items were commented in a header). |
|
1062 // --------------------------------------------------------- |
|
1063 // |
|
1064 |
|
1065 |
|
1066 void CLandmarkTestProcedureBase::CopyDbFileL(const TDesC& aFileName) |
|
1067 { |
|
1068 _LIT(KTestPath, "c:\\system\\test\\testdata\\"); |
|
1069 |
|
1070 CFileMan* fileMan = CFileMan::NewL(iFileSession); |
|
1071 CleanupStack::PushL(fileMan); |
|
1072 |
|
1073 TBuf<150> srcPath; |
|
1074 |
|
1075 srcPath.Append(KTestPath); |
|
1076 srcPath.Append(aFileName); |
|
1077 |
|
1078 |
|
1079 TInt err = fileMan->Copy(srcPath, KLmFullDefaultDbPath, CFileMan::EOverWrite); |
|
1080 if (err != KErrNone) |
|
1081 iLog->Log(_L("Error when copying file")); |
|
1082 |
|
1083 CleanupStack::PopAndDestroy(fileMan); |
|
1084 } |
|
1085 |
|
1086 // --------------------------------------------------------- |
|
1087 // CLandmarkTestProcedureBase::CopyTestDbFileL |
|
1088 // |
|
1089 // (other items were commented in a header). |
|
1090 // --------------------------------------------------------- |
|
1091 // |
|
1092 void CLandmarkTestProcedureBase::CopyTestDbFileL(const TDesC& aFileName) |
|
1093 { |
|
1094 CFileMan* fileMan = CFileMan::NewL(iFileSession); |
|
1095 CleanupStack::PushL(fileMan); |
|
1096 |
|
1097 TBuf<150> srcPath; |
|
1098 TBuf<150> destPath; |
|
1099 |
|
1100 srcPath.Append(KTestPath); |
|
1101 srcPath.Append(aFileName); |
|
1102 |
|
1103 destPath.Append(KLmDbPath); |
|
1104 destPath.Append(aFileName); |
|
1105 |
|
1106 TInt err = fileMan->Copy(srcPath, destPath, CFileMan::EOverWrite); |
|
1107 if (err != KErrNone) iLog->Log(_L("Error when copying file")); |
|
1108 |
|
1109 CleanupStack::PopAndDestroy(fileMan); |
|
1110 } |
|
1111 |
|
1112 // --------------------------------------------------------- |
|
1113 // CLandmarkTestProcedureBase::UseGeneratedDbFile |
|
1114 // |
|
1115 // (other items were commented in a header). |
|
1116 // --------------------------------------------------------- |
|
1117 // |
|
1118 CPosLandmarkDatabase* CLandmarkTestProcedureBase::UseGeneratedDbFileL() |
|
1119 { |
|
1120 CopyDbFileL(KDefaultDb); |
|
1121 |
|
1122 CPosLmDatabaseManager* manager = CPosLmDatabaseManager::NewL(); |
|
1123 CleanupStack::PushL(manager); |
|
1124 |
|
1125 // This db must exist |
|
1126 manager->SetDefaultDatabaseUriL(KDefaultDb); |
|
1127 CleanupStack::PopAndDestroy(manager); |
|
1128 |
|
1129 CPosLandmarkDatabase* db = CPosLandmarkDatabase::OpenL(KDefaultDb); |
|
1130 if ( db->IsInitializingNeeded() ) |
|
1131 { |
|
1132 TRAPD( err, ExecuteAndDeleteLD( db->InitializeL() ) ); |
|
1133 AssertTrueSecL( err == KErrNone, _L("Init db failed")); |
|
1134 } |
|
1135 |
|
1136 return db; |
|
1137 } |
|
1138 |
|
1139 // --------------------------------------------------------- |
|
1140 // CLandmarkTestProcedureBase::UseCompositeLandmarksDbFileL |
|
1141 // |
|
1142 // (other items were commented in a header). |
|
1143 // --------------------------------------------------------- |
|
1144 // |
|
1145 CPosLandmarkDatabase* CLandmarkTestProcedureBase::UseCompositeLandmarksDbFileL() |
|
1146 { |
|
1147 iLog->Log(_L("UseCompositeLandmarksDbFileL")); |
|
1148 |
|
1149 |
|
1150 _LIT(KDbFile, "compositeeposlm.ldb"); |
|
1151 CopyTestDbFileL(KDbFile); |
|
1152 |
|
1153 CPosLmDatabaseManager* manager = CPosLmDatabaseManager::NewL(); |
|
1154 CleanupStack::PushL(manager); |
|
1155 // This db must exist |
|
1156 manager->SetDefaultDatabaseUriL(KDbFile); |
|
1157 CleanupStack::PopAndDestroy(manager); |
|
1158 return CPosLandmarkDatabase::OpenL(KDbFile); |
|
1159 } |
|
1160 |
|
1161 // --------------------------------------------------------- |
|
1162 // CLandmarkTestProcedureBase::UseEmptyDbFileL |
|
1163 // |
|
1164 // (other items were commented in a header). |
|
1165 // --------------------------------------------------------- |
|
1166 // |
|
1167 CPosLandmarkDatabase* CLandmarkTestProcedureBase::UseEmptyDbFileL() |
|
1168 { |
|
1169 |
|
1170 CopyTestDbFileL(KLandmarksEmptyDb); |
|
1171 |
|
1172 CPosLmDatabaseManager* manager = CPosLmDatabaseManager::NewL(); |
|
1173 CleanupStack::PushL(manager); |
|
1174 // This db must exist |
|
1175 manager->SetDefaultDatabaseUriL(KLandmarksEmptyDb); |
|
1176 CleanupStack::PopAndDestroy(manager); |
|
1177 |
|
1178 return CPosLandmarkDatabase::OpenL(KLandmarksEmptyDb); |
|
1179 |
|
1180 } |
|
1181 |
|
1182 |
|
1183 // --------------------------------------------------------- |
|
1184 // CPosLandmarkDatabase::UseGlobalCategoriesL |
|
1185 // |
|
1186 // (other items were commented in a header). |
|
1187 // --------------------------------------------------------- |
|
1188 // |
|
1189 CPosLandmarkDatabase* CLandmarkTestProcedureBase::UseGlobalCategoriesL() |
|
1190 { |
|
1191 _LIT(KGlobalCategoryResFile, "c:\\system\\test\\testdata\\EPOSLMGLOBALCATEGORIES.R01"); |
|
1192 |
|
1193 _LIT(KGlobalCategoryResPath, "c:\\resource\\"); |
|
1194 |
|
1195 iLog->Log(_L("UseGlobalCategoriesL")); |
|
1196 |
|
1197 CFileMan* fileMan = CFileMan::NewL(iFileSession); |
|
1198 CleanupStack::PushL(fileMan); |
|
1199 TInt err = KErrNone; |
|
1200 //check if landmark is flashed |
|
1201 TInt Value=BaflUtils::FileExists(iFileSession, KGlobalCategoryResFileROM); |
|
1202 // if (!BaflUtils::FileExists(fs, KGlobalCategoryResFileROM)) |
|
1203 if(!Value) |
|
1204 { |
|
1205 iLog->Log(_L("Landmark is NOT flashed, rename global categories")); |
|
1206 //Landmark is not flashed rename the file before copy a own defiend file. |
|
1207 //since landmark is not flashed the file should exist hence leaving if it is not found! |
|
1208 |
|
1209 err = fileMan->Rename(KGlobalCategoryResFileWINS, KGlobalCategoryResFileCOPY, CFileMan::EOverWrite); |
|
1210 if (err != KErrNone) |
|
1211 { |
|
1212 TBuf<100> buf; |
|
1213 buf.Format(_L("ErrCode: from fileMan->Rename %d"),err); |
|
1214 iLog->Log(buf); |
|
1215 } |
|
1216 |
|
1217 } |
|
1218 else |
|
1219 { |
|
1220 iLog->Log(_L("Landmark is flashed, copy global categories")); |
|
1221 } |
|
1222 |
|
1223 // Recurse copy -> Create directory if it does not exist and overwrite file if it exists |
|
1224 err = fileMan->Copy(KGlobalCategoryResFile, KGlobalCategoryResPath, CFileMan::EOverWrite); |
|
1225 if (err != KErrNone) |
|
1226 { |
|
1227 TBuf<100> buf; |
|
1228 buf.Format(_L("ErrCode: from fileMan->Copy %d"),err); |
|
1229 iLog->Log(buf); |
|
1230 } |
|
1231 |
|
1232 CleanupStack::PopAndDestroy(fileMan); |
|
1233 |
|
1234 return CPosLandmarkDatabase::OpenL(); |
|
1235 } |
|
1236 |
|
1237 // --------------------------------------------------------- |
|
1238 // CLandmarkTestProcedureBase::RemoveGlobalCategoriesL |
|
1239 // |
|
1240 // (other items were commented in a header). |
|
1241 // --------------------------------------------------------- |
|
1242 // |
|
1243 void CLandmarkTestProcedureBase::RemoveGlobalCategoriesL() |
|
1244 { |
|
1245 |
|
1246 _LIT(KGlobalCategoryResFile, "c:\\resource\\EPOSLMGLOBALCATEGORIES.R01"); |
|
1247 |
|
1248 iLog->Log(_L("RemoveGlobalCategoriesL")); |
|
1249 |
|
1250 CFileMan* fileMan = CFileMan::NewL(iFileSession); |
|
1251 CleanupStack::PushL(fileMan); |
|
1252 TInt err = KErrNone; |
|
1253 |
|
1254 //check if the global category file exist in rom |
|
1255 //if landmarks is flushed it is just okej to remove |
|
1256 //any global gategory files in on the c drive. |
|
1257 if (BaflUtils::FileExists(iFileSession, KGlobalCategoryResFileROM)) |
|
1258 { |
|
1259 iLog->Log(_L("Landmark is flashed, delete global categories")); |
|
1260 //in this case it is same just to remove it form c if it exists: |
|
1261 if (BaflUtils::FileExists(iFileSession, KGlobalCategoryResFile)) |
|
1262 { |
|
1263 err = fileMan->Delete(KGlobalCategoryResFile); |
|
1264 if (err != KErrNone) |
|
1265 { |
|
1266 TBuf<100> buf; |
|
1267 buf.Format(_L("ErrCode: from fileMan->Delete %d"),err); |
|
1268 iLog->Log(buf); |
|
1269 } |
|
1270 } |
|
1271 } |
|
1272 else |
|
1273 { |
|
1274 iLog->Log(_L("Landmark is NOT flashed, delete global categories and rename the old file")); |
|
1275 //If a copy exist this should be used, but if it does not |
|
1276 //exist the file is not removed since it is hard to know |
|
1277 //if anything has gone wrong. |
|
1278 if(BaflUtils::FileExists(iFileSession, KGlobalCategoryResFileCOPY)) |
|
1279 { |
|
1280 //first delete the used file, if it exist |
|
1281 if (BaflUtils::FileExists(iFileSession, KGlobalCategoryResFile)) |
|
1282 { |
|
1283 |
|
1284 err = fileMan->Delete(KGlobalCategoryResFile); |
|
1285 if (err != KErrNone) |
|
1286 { |
|
1287 TBuf<100> buf; |
|
1288 buf.Format(_L("ErrCode: from fileMan->Delete %d"),err); |
|
1289 iLog->Log(buf); |
|
1290 } |
|
1291 } |
|
1292 //Rename the copy file |
|
1293 |
|
1294 err = fileMan->Rename(KGlobalCategoryResFileCOPY, KGlobalCategoryResFile, CFileMan::EOverWrite); |
|
1295 if (err != KErrNone) |
|
1296 { |
|
1297 TBuf<100> buf; |
|
1298 buf.Format(_L("ErrCode: from fileMan->Rename %d"),err); |
|
1299 iLog->Log(buf); |
|
1300 } |
|
1301 } |
|
1302 } |
|
1303 iLog->Log(_L("RemoveGlobalCategoriesL Done in CLandmarkTestProcedureBase")); |
|
1304 CleanupStack::PopAndDestroy(fileMan); |
|
1305 } |
|
1306 |
|
1307 // --------------------------------------------------------- |
|
1308 // CLandmarkTestProcedureBase::Trace |
|
1309 // |
|
1310 // (other items were commented in a header). |
|
1311 // --------------------------------------------------------- |
|
1312 // |
|
1313 void CLandmarkTestProcedureBase::Trace(TBuf8<KMsgBufSize> aMsg) |
|
1314 { |
|
1315 _LIT(KFileTrace, "c:\\LandmarksTestsTrace.txt"); |
|
1316 _LIT8(KEnd,"\r\n"); |
|
1317 |
|
1318 RFs fs; |
|
1319 fs.Connect(); |
|
1320 |
|
1321 RFile file; |
|
1322 TInt err = file.Open(fs, KFileTrace, EFileWrite); |
|
1323 |
|
1324 if ( err ) |
|
1325 { |
|
1326 err = file.Create(fs, KFileTrace, EFileWrite); |
|
1327 } |
|
1328 |
|
1329 if ( !err ) |
|
1330 { |
|
1331 TInt pos = 0; |
|
1332 file.Seek( ESeekEnd, pos ); |
|
1333 file.Write( aMsg ); |
|
1334 file.Write( KEnd() ); |
|
1335 } |
|
1336 |
|
1337 file.Close(); |
|
1338 fs.Close(); |
|
1339 } |
|
1340 |
|
1341 // --------------------------------------------------------- |
|
1342 // CLandmarkTestProcedureBase::AppendSearchResultsL() |
|
1343 // |
|
1344 // (other items were commented in a header). |
|
1345 // --------------------------------------------------------- |
|
1346 void CLandmarkTestProcedureBase::AppendSearchResultsL() |
|
1347 { |
|
1348 if (iSearchResults.Count() == 0 ) |
|
1349 { |
|
1350 _LIT(KFileTestValues, "c:\\system\\test\\testdata\\LmDbSearchResult.txt"); |
|
1351 |
|
1352 RFile file; |
|
1353 User::LeaveIfError(file.Open(iFileSession, KFileTestValues, EFileRead)); |
|
1354 CleanupClosePushL(file); |
|
1355 |
|
1356 TBuf<KMaxLineLength> line; |
|
1357 while (ReadLn(file, line) != KErrEof) |
|
1358 { |
|
1359 TLex lex(line); |
|
1360 if (lex.Peek() != '#' && lex.Peek() != '\t') |
|
1361 { |
|
1362 CSearchResult* searchResult = CSearchResult::NewL(line); |
|
1363 CleanupStack::PushL(searchResult); |
|
1364 |
|
1365 User::LeaveIfError(iSearchResults.Append(searchResult)); |
|
1366 CleanupStack::Pop(searchResult); |
|
1367 } |
|
1368 } |
|
1369 CleanupStack::PopAndDestroy(&file); |
|
1370 } |
|
1371 } |
|
1372 |
|
1373 // --------------------------------------------------------- |
|
1374 // CLandmarkTestProcedureBase::AppendAreaSearchResultsL() |
|
1375 // |
|
1376 // (other items were commented in a header). |
|
1377 // --------------------------------------------------------- |
|
1378 void CLandmarkTestProcedureBase::AppendAreaSearchResultsL() |
|
1379 { |
|
1380 if (iSearchResults.Count() == 0) |
|
1381 { |
|
1382 _LIT(KFileTestValues, "c:\\system\\test\\testdata\\lmDbAreaSearchResult.txt"); |
|
1383 |
|
1384 RFile file; |
|
1385 User::LeaveIfError(file.Open(iFileSession, KFileTestValues, EFileRead)); |
|
1386 CleanupClosePushL(file); |
|
1387 |
|
1388 TBuf<KMaxLineLength> line; |
|
1389 while (ReadLn(file, line) != KErrEof) |
|
1390 { |
|
1391 TLex lex(line); |
|
1392 if (lex.Peek() != '#' && lex.Peek() != '\t') |
|
1393 { |
|
1394 CAreaSearchResult* searchResult = CAreaSearchResult::NewL(line); |
|
1395 CleanupStack::PushL(searchResult); |
|
1396 |
|
1397 User::LeaveIfError(iAreaSearchResults.Append(searchResult)); |
|
1398 CleanupStack::Pop(searchResult); |
|
1399 } |
|
1400 } |
|
1401 CleanupStack::PopAndDestroy(&file); |
|
1402 } |
|
1403 } |
|
1404 |
|
1405 // --------------------------------------------------------- |
|
1406 // CLandmarkTestProcedureBase::AppendCategoryLandmarkSearchResultsL |
|
1407 // |
|
1408 // (other items were commented in a header). |
|
1409 // --------------------------------------------------------- |
|
1410 void CLandmarkTestProcedureBase::AppendCategoryLandmarkSearchResultsL() |
|
1411 { |
|
1412 if (iCategoryLandmarkSearchResults.Count() == 0 ) |
|
1413 { |
|
1414 _LIT(KFileTestValues, "c:\\system\\test\\testdata\\LmDbCatLandmarkSearchResult.txt"); |
|
1415 |
|
1416 RFile file; |
|
1417 TInt err = file.Open(iFileSession, KFileTestValues, EFileRead); |
|
1418 AssertTrueSecL( err == KErrNone, _L("AppendCategoryLandmarkSearchResultsL file error")); |
|
1419 CleanupClosePushL(file); |
|
1420 |
|
1421 TBuf<KMaxLineLength> line; |
|
1422 while (ReadLn(file, line) != KErrEof) |
|
1423 { |
|
1424 TLex lex(line); |
|
1425 if (lex.Peek() != '#' && lex.Peek() != '\t') |
|
1426 { |
|
1427 CCategoryLandmarkSearchResult* oneLineResult = CCategoryLandmarkSearchResult::NewL(line); |
|
1428 CleanupStack::PushL(oneLineResult); |
|
1429 |
|
1430 User::LeaveIfError(iCategoryLandmarkSearchResults.Append(oneLineResult)); |
|
1431 CleanupStack::Pop(oneLineResult); |
|
1432 |
|
1433 } |
|
1434 } |
|
1435 |
|
1436 CleanupStack::PopAndDestroy(&file); |
|
1437 } |
|
1438 } |
|
1439 |
|
1440 // --------------------------------------------------------- |
|
1441 // CLandmarkTestProcedureBase::AppendCategorySearchResultsL |
|
1442 // |
|
1443 // (other items were commented in a header). |
|
1444 // --------------------------------------------------------- |
|
1445 void CLandmarkTestProcedureBase::AppendCategorySearchResultsL() |
|
1446 { |
|
1447 if (iCategorySearchResults.Count() == 0 ) |
|
1448 { |
|
1449 _LIT(KFileTestValues, "c:\\system\\test\\testdata\\LmDbCategorySearchResult.txt"); |
|
1450 |
|
1451 RFile file; |
|
1452 User::LeaveIfError(file.Open(iFileSession, KFileTestValues, EFileRead)); |
|
1453 CleanupClosePushL(file); |
|
1454 |
|
1455 |
|
1456 TBuf<KMaxLineLength> line; |
|
1457 while (ReadLn(file, line) != KErrEof) |
|
1458 { |
|
1459 TLex lex(line); |
|
1460 if (lex.Peek() != '#' && lex.Peek() != '\t') |
|
1461 { |
|
1462 CCategorySearchResult* oneLineResult = CCategorySearchResult::NewL(line); |
|
1463 CleanupStack::PushL(oneLineResult); |
|
1464 |
|
1465 User::LeaveIfError(iCategorySearchResults.Append(oneLineResult)); |
|
1466 CleanupStack::Pop(oneLineResult); |
|
1467 //iLog->Log(line); |
|
1468 } |
|
1469 } |
|
1470 |
|
1471 CleanupStack::PopAndDestroy(&file); |
|
1472 } |
|
1473 } |
|
1474 |
|
1475 // --------------------------------------------------------- |
|
1476 // CLandmarkTestProcedureBase::SeachResults |
|
1477 // |
|
1478 // (other items were commented in a header). |
|
1479 // --------------------------------------------------------- |
|
1480 // |
|
1481 const RPointerArray<CSearchResult>& CLandmarkTestProcedureBase::SearchResults() |
|
1482 { |
|
1483 return iSearchResults; |
|
1484 } |
|
1485 |
|
1486 // --------------------------------------------------------- |
|
1487 // CLandmarkTestProcedureBase::AreaSeachResults |
|
1488 // |
|
1489 // (other items were commented in a header). |
|
1490 // --------------------------------------------------------- |
|
1491 // |
|
1492 const RPointerArray<CAreaSearchResult>& CLandmarkTestProcedureBase::AreaSearchResults() |
|
1493 { |
|
1494 return iAreaSearchResults; |
|
1495 } |
|
1496 |
|
1497 // --------------------------------------------------------- |
|
1498 // CLandmarkTestProcedureBase::ReadLn |
|
1499 // |
|
1500 // (other items were commented in a header). |
|
1501 // --------------------------------------------------------- |
|
1502 // |
|
1503 TInt CLandmarkTestProcedureBase::ReadLn(RFile& aFile, TDes& aDes) |
|
1504 { |
|
1505 aDes = KNullDesC; |
|
1506 TBuf8<KMaxLineLength> line; |
|
1507 |
|
1508 TInt err = aFile.Read(line); |
|
1509 if (line.Length() == 0) |
|
1510 { |
|
1511 return KErrEof; |
|
1512 } |
|
1513 if (err) |
|
1514 { |
|
1515 return err; |
|
1516 } |
|
1517 |
|
1518 // Find line feed |
|
1519 TInt i = 0; |
|
1520 TLex8 fileData; |
|
1521 fileData.Assign(line); |
|
1522 while (fileData.Peek() != '\n' && !(fileData.Peek()).Eos()) |
|
1523 { |
|
1524 fileData.Inc(); |
|
1525 if (++i == KMaxLineLength) |
|
1526 { |
|
1527 // In case no carriage return or end of string characters are present. |
|
1528 break; |
|
1529 } |
|
1530 } |
|
1531 |
|
1532 // Update file position |
|
1533 TInt diff = -(line.Length() - i - 1); |
|
1534 aFile.Seek(ESeekCurrent, diff); |
|
1535 |
|
1536 // Convert to 16-bit |
|
1537 line.SetLength(i); |
|
1538 aDes.Copy(line); |
|
1539 |
|
1540 return KErrNone; |
|
1541 } |
|
1542 |
|
1543 // --------------------------------------------------------- |
|
1544 // CLandmarkTestProcedureBase::CompareL |
|
1545 // |
|
1546 // (other items were commented in a header). |
|
1547 // --------------------------------------------------------- |
|
1548 // |
|
1549 TInt CLandmarkTestProcedureBase::CompareL( |
|
1550 const TDesC& aSourceFileName, |
|
1551 const TDesC& aTargetFileName) |
|
1552 { |
|
1553 _LIT(KCompareErr, "Compared file %S is not equal to %S"); |
|
1554 _LIT(KLineErr, "Line %S is different to line %S"); |
|
1555 |
|
1556 iLog->Log(_L("CompareL: source file '%S' with target file '%S'"), &aSourceFileName, &aTargetFileName ); |
|
1557 |
|
1558 RFile targetFile, sourceFile; |
|
1559 |
|
1560 TInt err = KErrNone; |
|
1561 err = sourceFile.Open(iFileSession, aSourceFileName, EFileRead); |
|
1562 if ( err ) |
|
1563 { |
|
1564 iLog->Log(_L("Failed to open source file '%S', err % d"), &aSourceFileName, err ); |
|
1565 User::Leave( err ); |
|
1566 } |
|
1567 CleanupClosePushL(sourceFile); |
|
1568 |
|
1569 err = targetFile.Open(iFileSession, aTargetFileName, EFileRead); |
|
1570 if ( err ) |
|
1571 { |
|
1572 iLog->Log(_L("Failed to open target file '%S', err % d"), &aTargetFileName, err ); |
|
1573 User::Leave( err ); |
|
1574 } |
|
1575 CleanupClosePushL(targetFile); |
|
1576 |
|
1577 TBuf<255> sourceLine; |
|
1578 TBuf<255> targetLine; |
|
1579 |
|
1580 while (ReadLn(sourceFile, sourceLine) != KErrEof) |
|
1581 { |
|
1582 ReadLn(targetFile, targetLine); |
|
1583 |
|
1584 if (sourceLine.Compare(targetLine) != 0) |
|
1585 { |
|
1586 TBuf<255> info; |
|
1587 info.Format(KCompareErr, &aSourceFileName, &aTargetFileName); |
|
1588 iLog->Log(info); |
|
1589 |
|
1590 info.Format(KLineErr, &targetLine, &sourceLine); |
|
1591 iLog->Log(info); |
|
1592 |
|
1593 err = KErrGeneral; |
|
1594 break; |
|
1595 } |
|
1596 } |
|
1597 |
|
1598 CleanupStack::PopAndDestroy(&targetFile); |
|
1599 CleanupStack::PopAndDestroy(&sourceFile); |
|
1600 return err; |
|
1601 } |
|
1602 |
|
1603 // --------------------------------------------------------- |
|
1604 // CLandmarkTestProcedureBase::CompareL |
|
1605 // |
|
1606 // (other items were commented in a header). |
|
1607 // --------------------------------------------------------- |
|
1608 // |
|
1609 TInt CLandmarkTestProcedureBase::CompareL(const TDesC& aFileName) |
|
1610 { |
|
1611 _LIT(KTargetPath, "c:\\"); |
|
1612 |
|
1613 _LIT(KSourcePath, "c:\\system\\test\\testdata\\"); |
|
1614 |
|
1615 TBuf<100> target; |
|
1616 target.Append(KTargetPath); |
|
1617 target.Append(aFileName); |
|
1618 |
|
1619 TBuf<100> source; |
|
1620 source.Append(KSourcePath); |
|
1621 source.Append(aFileName); |
|
1622 |
|
1623 return CompareL(source, target); |
|
1624 } |
|
1625 |
|
1626 // --------------------------------------------------------- |
|
1627 // CLandmarkTestProcedureBase::PrintLandmark |
|
1628 // |
|
1629 // (other items were commented in a header). |
|
1630 // --------------------------------------------------------- |
|
1631 // |
|
1632 void CLandmarkTestProcedureBase::PrintLandmark(const CPosLandmark& aLandmark, TDes& aPrint) |
|
1633 { |
|
1634 |
|
1635 |
|
1636 TChar del(','); |
|
1637 |
|
1638 _LIT(KIntInfo, "%d"); |
|
1639 TBuf<KMaxFieldLength> info; |
|
1640 TPosLmItemId id = aLandmark.LandmarkId(); |
|
1641 if (id != 0) |
|
1642 { |
|
1643 info.Format(KIntInfo, id); |
|
1644 aPrint.Append(info); |
|
1645 } |
|
1646 aPrint.Append(del); |
|
1647 |
|
1648 RArray<TPosLmItemId> lmcats; |
|
1649 // How to do this in test code, with non leaving function? // fran |
|
1650 CleanupClosePushL(lmcats); |
|
1651 TRAPD(error, aLandmark.GetCategoriesL(lmcats)); |
|
1652 |
|
1653 if (error == KErrNone) |
|
1654 { |
|
1655 _LIT(KStart, "{"); |
|
1656 _LIT(KStop, "}"); |
|
1657 aPrint.Append(KStart); |
|
1658 for (TInt i=0; i<lmcats.Count(); i++) |
|
1659 { |
|
1660 info.Format(KIntInfo, lmcats[i]); |
|
1661 aPrint.Append(info); |
|
1662 aPrint.Append(del); |
|
1663 } |
|
1664 aPrint.Append(KStop); |
|
1665 } |
|
1666 CleanupStack::PopAndDestroy(&lmcats); |
|
1667 |
|
1668 TPtrC name; |
|
1669 aLandmark.GetLandmarkName(name); |
|
1670 aPrint.Append(name); |
|
1671 aPrint.Append(del); |
|
1672 |
|
1673 TInt err; |
|
1674 _LIT(KRealInfo, "%f"); |
|
1675 TReal32 coverageR; |
|
1676 |
|
1677 err = aLandmark.GetCoverageRadius(coverageR); |
|
1678 if (!err) |
|
1679 { |
|
1680 info.Format(KRealInfo, coverageR); |
|
1681 aPrint.Append(info); |
|
1682 } |
|
1683 |
|
1684 aPrint.Append(del); |
|
1685 TPtrC desc; |
|
1686 err = aLandmark.GetLandmarkDescription(desc); |
|
1687 if (!err) |
|
1688 { |
|
1689 aPrint.Append(desc); |
|
1690 } |
|
1691 |
|
1692 aPrint.Append(del); |
|
1693 |
|
1694 TPtrC iconName; |
|
1695 TInt iconIndex; |
|
1696 TInt iconMaskIndex; |
|
1697 err = aLandmark.GetIcon(iconName, iconIndex, iconMaskIndex); |
|
1698 if (!err) |
|
1699 { |
|
1700 aPrint.Append(iconName); |
|
1701 aPrint.Append(del); |
|
1702 info.Format(KIntInfo, iconIndex); |
|
1703 aPrint.Append(info); |
|
1704 } |
|
1705 |
|
1706 aPrint.Append(del); |
|
1707 TPtrC street; |
|
1708 err = aLandmark.GetPositionField(EPositionFieldStreet, street); |
|
1709 if (!err) |
|
1710 { |
|
1711 aPrint.Append(street); |
|
1712 } |
|
1713 |
|
1714 aPrint.Append(del); |
|
1715 TPtrC postalCode; |
|
1716 err = aLandmark.GetPositionField(EPositionFieldPostalCode, postalCode); |
|
1717 if (!err) |
|
1718 { |
|
1719 aPrint.Append(postalCode); |
|
1720 } |
|
1721 |
|
1722 aPrint.Append(del); |
|
1723 TPtrC city; |
|
1724 err = aLandmark.GetPositionField(EPositionFieldCity, city); |
|
1725 if (!err) |
|
1726 { |
|
1727 aPrint.Append(city); |
|
1728 } |
|
1729 |
|
1730 aPrint.Append(del); |
|
1731 TPtrC locationName; |
|
1732 err = aLandmark.GetPositionField(EPositionFieldLocationName, locationName); |
|
1733 if (!err) |
|
1734 { |
|
1735 aPrint.Append(locationName); |
|
1736 } |
|
1737 |
|
1738 aPrint.Append(del); |
|
1739 TPtrC country; |
|
1740 err = aLandmark.GetPositionField(EPositionFieldCountry, country); |
|
1741 if (!err) |
|
1742 { |
|
1743 aPrint.Append(country); |
|
1744 } |
|
1745 |
|
1746 aPrint.Append(del); |
|
1747 TPtrC mediaLink; |
|
1748 err = aLandmark.GetPositionField(EPositionFieldMediaLinksStart, mediaLink); |
|
1749 if (!err) |
|
1750 { |
|
1751 aPrint.Append(mediaLink); |
|
1752 } |
|
1753 |
|
1754 aPrint.Append(del); |
|
1755 TUint16 tmp = (TUint16)EPositionFieldMediaLinksStart; |
|
1756 TPtrC mediaLink2; |
|
1757 err = aLandmark.GetPositionField(++tmp, mediaLink2); |
|
1758 if (!err) |
|
1759 { |
|
1760 aPrint.Append(mediaLink2); |
|
1761 } |
|
1762 |
|
1763 aPrint.Append(del); |
|
1764 TLocality loc; |
|
1765 err = aLandmark.GetPosition(loc); |
|
1766 if (!err) |
|
1767 { |
|
1768 info.Format(KRealInfo, loc.Latitude()); |
|
1769 aPrint.Append(info); |
|
1770 aPrint.Append(del); |
|
1771 info.Format(KRealInfo, loc.Longitude()); |
|
1772 aPrint.Append(info); |
|
1773 aPrint.Append(del); |
|
1774 if (!Math::IsNaN(loc.HorizontalAccuracy())) |
|
1775 { |
|
1776 info.Format(KRealInfo, loc.HorizontalAccuracy()); |
|
1777 aPrint.Append(info); |
|
1778 aPrint.Append(del); |
|
1779 } |
|
1780 if (!Math::IsNaN(loc.VerticalAccuracy())) |
|
1781 { |
|
1782 info.Format(KRealInfo, loc.VerticalAccuracy()); |
|
1783 aPrint.Append(info); |
|
1784 aPrint.Append(del); |
|
1785 } |
|
1786 if (!Math::IsNaN(loc.Altitude())) |
|
1787 { |
|
1788 info.Format(KRealInfo, loc.Altitude()); |
|
1789 aPrint.Append(info); |
|
1790 aPrint.Append(del); |
|
1791 } |
|
1792 } |
|
1793 |
|
1794 |
|
1795 } |
|
1796 |
|
1797 TInt InternalLandmarksSortL(const CPosLandmark& aSource, const CPosLandmark& aTarget) |
|
1798 { |
|
1799 TPtrC sourceName, targetName; |
|
1800 |
|
1801 User::LeaveIfError(aSource.GetLandmarkName(sourceName)); |
|
1802 User::LeaveIfError(aTarget.GetLandmarkName(targetName)); |
|
1803 |
|
1804 return sourceName.CompareC(targetName); |
|
1805 } |
|
1806 |
|
1807 // --------------------------------------------------------- |
|
1808 // CLandmarkTestProcedureBase::LandmarksSortL |
|
1809 // |
|
1810 // (other items were commented in a header). |
|
1811 // --------------------------------------------------------- |
|
1812 // |
|
1813 void CLandmarkTestProcedureBase::LandmarksSortL(RArray<TPosLmItemId>& aArray, |
|
1814 const TPosLmSortPref& aSortPref) |
|
1815 { |
|
1816 RPointerArray<CPosLandmark> landmarks; |
|
1817 CleanupClosePushL(landmarks); |
|
1818 |
|
1819 for (TInt i=0; i<aArray.Count(); i++) |
|
1820 { |
|
1821 CPosLandmark* lm = iDatabase->ReadLandmarkLC(aArray[i]); |
|
1822 landmarks.Append(lm); |
|
1823 CleanupStack::Pop(lm); |
|
1824 } |
|
1825 |
|
1826 TLinearOrder<CPosLandmark> order(InternalLandmarksSortL); |
|
1827 landmarks.Sort(order); |
|
1828 |
|
1829 aArray.Reset(); |
|
1830 |
|
1831 if (aSortPref.SortOrder() == TPosLmSortPref::EAscending) |
|
1832 { |
|
1833 for (TInt j=0; j<landmarks.Count(); j++) |
|
1834 { |
|
1835 aArray.Append(landmarks[j]->LandmarkId()); |
|
1836 } |
|
1837 } |
|
1838 else |
|
1839 { |
|
1840 for (TInt k=landmarks.Count()-1; k>=0; k--) |
|
1841 { |
|
1842 aArray.Append(landmarks[k]->LandmarkId()); |
|
1843 } |
|
1844 } |
|
1845 landmarks.ResetAndDestroy(); |
|
1846 CleanupStack::PopAndDestroy(&landmarks); |
|
1847 } |
|
1848 |
|
1849 |
|
1850 // --------------------------------------------------------- |
|
1851 // InternalCategorySortL |
|
1852 // |
|
1853 // (other items were commented in a header). |
|
1854 // --------------------------------------------------------- |
|
1855 // |
|
1856 TInt InternalCategorySortL(const CPosLandmarkCategory& aSource, const CPosLandmarkCategory& aTarget) |
|
1857 { |
|
1858 TPtrC sourceName, targetName; |
|
1859 |
|
1860 User::LeaveIfError(aSource.GetCategoryName(sourceName)); |
|
1861 User::LeaveIfError(aTarget.GetCategoryName(targetName)); |
|
1862 |
|
1863 return sourceName.CompareC(targetName); |
|
1864 } |
|
1865 |
|
1866 // --------------------------------------------------------- |
|
1867 // CLandmarkTestProcedureBase::CategoriesSortL |
|
1868 // |
|
1869 // (other items were commented in a header). |
|
1870 // --------------------------------------------------------- |
|
1871 // |
|
1872 void CLandmarkTestProcedureBase::CategoriesSortL(RArray<TPosLmItemId>& aArray, |
|
1873 CPosLmCategoryManager::TCategorySortPref aSortPref) |
|
1874 { |
|
1875 RPointerArray<CPosLandmarkCategory> categories; |
|
1876 CleanupClosePushL(categories); |
|
1877 |
|
1878 CPosLmCategoryManager* categoryManager = CPosLmCategoryManager::NewL(*iDatabase); |
|
1879 CleanupStack::PushL(categoryManager); |
|
1880 |
|
1881 for (TInt i=0; i<aArray.Count(); i++) |
|
1882 { |
|
1883 CPosLandmarkCategory* cat = categoryManager->ReadCategoryLC(aArray[i]); |
|
1884 categories.Append(cat); |
|
1885 CleanupStack::Pop(cat); |
|
1886 } |
|
1887 |
|
1888 TLinearOrder<CPosLandmarkCategory> order(InternalCategorySortL); |
|
1889 categories.Sort(order); |
|
1890 |
|
1891 aArray.Reset(); |
|
1892 |
|
1893 if (aSortPref == CPosLmCategoryManager::ECategorySortOrderNameAscending) |
|
1894 { |
|
1895 for (TInt j=0; j<categories.Count(); j++) |
|
1896 { |
|
1897 aArray.Append(categories[j]->CategoryId()); |
|
1898 } |
|
1899 } |
|
1900 else |
|
1901 { |
|
1902 for (TInt k=categories.Count()-1; k>=0; k--) |
|
1903 { |
|
1904 aArray.Append(categories[k]->CategoryId()); |
|
1905 } |
|
1906 } |
|
1907 categories.ResetAndDestroy(); |
|
1908 CleanupStack::PopAndDestroy(categoryManager); |
|
1909 CleanupStack::PopAndDestroy(&categories); |
|
1910 } |
|
1911 |
|
1912 // --------------------------------------------------------- |
|
1913 // CLandmarkTestProcedureBase::LogToFileL |
|
1914 // |
|
1915 // (other items were commented in a header). |
|
1916 // --------------------------------------------------------- |
|
1917 // |
|
1918 void CLandmarkTestProcedureBase::LogToFileL(const TDesC& aFileName, TBuf8<KMsgBufSize> aMsg) |
|
1919 { |
|
1920 _LIT8(KEnd,"\r\n"); |
|
1921 |
|
1922 BaflUtils::EnsurePathExistsL( iFileSession, aFileName ); |
|
1923 |
|
1924 RFile file; |
|
1925 TInt err = file.Open(iFileSession, aFileName, EFileWrite); |
|
1926 if ( err ) |
|
1927 { |
|
1928 err = file.Create(iFileSession, aFileName, EFileWrite); |
|
1929 } |
|
1930 |
|
1931 if ( !err ) |
|
1932 { |
|
1933 TInt pos = 0; |
|
1934 file.Seek( ESeekEnd, pos ); |
|
1935 file.Write( aMsg ); |
|
1936 file.Write( KEnd ); |
|
1937 } |
|
1938 |
|
1939 file.Close(); |
|
1940 } |
|
1941 |
|
1942 // --------------------------------------------------------- |
|
1943 // CLandmarkTestProcedureBase::RunAsyncOperationLD |
|
1944 // |
|
1945 // (other items were commented in a header). |
|
1946 // --------------------------------------------------------- |
|
1947 // |
|
1948 void CLandmarkTestProcedureBase::RunAsyncOperationLD(CPosLmOperation* aOperation) |
|
1949 { |
|
1950 CActiveLmOperation* activeLmOperation = new(ELeave) CActiveLmOperation(iLog, iUseLogFromThreadIsDisabled); |
|
1951 CleanupStack::PushL(activeLmOperation); |
|
1952 |
|
1953 activeLmOperation->Start(aOperation); |
|
1954 |
|
1955 CActiveScheduler::Start(); |
|
1956 |
|
1957 activeLmOperation->CheckOperationL(); |
|
1958 activeLmOperation->DeleteOperationD(); |
|
1959 |
|
1960 CleanupStack::PopAndDestroy(activeLmOperation); |
|
1961 } |
|
1962 |
|
1963 // --------------------------------------------------------- |
|
1964 // CLandmarkTestProcedureBase::RunAsyncOperationLD |
|
1965 // |
|
1966 // (other items were commented in a header). |
|
1967 // --------------------------------------------------------- |
|
1968 // |
|
1969 void CLandmarkTestProcedureBase::RunAsyncOperationL( |
|
1970 CPosLmOperation* aOperation) |
|
1971 { |
|
1972 CActiveLmOperation* activeLmOperation = new(ELeave) CActiveLmOperation(iLog, iUseLogFromThreadIsDisabled); |
|
1973 CleanupStack::PushL(activeLmOperation); |
|
1974 |
|
1975 activeLmOperation->Start(aOperation); |
|
1976 |
|
1977 CActiveScheduler::Start(); |
|
1978 |
|
1979 activeLmOperation->CheckOperationL(); |
|
1980 |
|
1981 CleanupStack::PopAndDestroy(activeLmOperation); |
|
1982 } |
|
1983 |
|
1984 // --------------------------------------------------------- |
|
1985 // CLandmarkTestProcedureBase::RunAsyncOperationByWaitForReqL |
|
1986 // |
|
1987 // (other items were commented in a header). |
|
1988 // --------------------------------------------------------- |
|
1989 // |
|
1990 void CLandmarkTestProcedureBase::RunAsyncOperationByWaitForReqL( |
|
1991 CPosLmOperation* aOperation) |
|
1992 { |
|
1993 TRequestStatus status = KPosLmOperationNotComplete; |
|
1994 TReal32 progress = 0; |
|
1995 |
|
1996 while (status == KPosLmOperationNotComplete) |
|
1997 { |
|
1998 aOperation->NextStep(status, progress); |
|
1999 User::WaitForRequest(status); |
|
2000 } |
|
2001 |
|
2002 _LIT(KStatusError, "Executing CPosLmOperation by using User::WaitForRequest() failed with %d"); |
|
2003 AssertTrueSecL(status.Int() == KErrNone, KStatusError, status.Int()); |
|
2004 |
|
2005 _LIT(KProgError, "Progress not 1.0 but %d when executing CPosLmOperation with User::WaitForRequest()"); |
|
2006 AssertTrueSecL(progress == 1.0, KProgError, (TInt) (progress * 100)); |
|
2007 } |
|
2008 |
|
2009 // --------------------------------------------------------- |
|
2010 // CLandmarkTestProcedureBase::RunAsyncOperationAndCancelLD |
|
2011 // |
|
2012 // (other items were commented in a header). |
|
2013 // --------------------------------------------------------- |
|
2014 // |
|
2015 void CLandmarkTestProcedureBase::RunAsyncOperationAndCancelLD(CPosLmOperation* aOperation) |
|
2016 { |
|
2017 CActiveLmOperation* activeLmOperation = new(ELeave) CActiveLmOperation(iLog, iUseLogFromThreadIsDisabled); |
|
2018 CleanupStack::PushL(activeLmOperation); |
|
2019 |
|
2020 activeLmOperation->Start(aOperation); |
|
2021 |
|
2022 activeLmOperation->DeleteOperationD(); |
|
2023 |
|
2024 CActiveScheduler::Start(); |
|
2025 |
|
2026 CleanupStack::PopAndDestroy(activeLmOperation); |
|
2027 } |
|
2028 |
|
2029 // --------------------------------------------------------- |
|
2030 // CLandmarkTestProcedureBase::RunAsyncOperationAndCancelInCallbackLD |
|
2031 // |
|
2032 // (other items were commented in a header). |
|
2033 // --------------------------------------------------------- |
|
2034 // |
|
2035 void CLandmarkTestProcedureBase::RunAsyncOperationAndCancelInCallbackLD( |
|
2036 CPosLmOperation* aOperation, |
|
2037 TReal32 aThreshold) |
|
2038 { |
|
2039 if (aThreshold > 0) |
|
2040 { |
|
2041 CActiveLmOperation* activeLmOperation = new(ELeave) CActiveLmOperation( |
|
2042 iLog, iUseLogFromThreadIsDisabled, aThreshold); |
|
2043 CleanupStack::PushL(activeLmOperation); |
|
2044 |
|
2045 TCallBack callback(CancelTest, activeLmOperation); |
|
2046 |
|
2047 CPeriodic* periodicTimer = CPeriodic::NewL(CActive::EPriorityHigh); |
|
2048 CleanupStack::PushL(periodicTimer); |
|
2049 |
|
2050 periodicTimer->Start(1, 1, callback); |
|
2051 |
|
2052 activeLmOperation->SetCancelTest(); |
|
2053 activeLmOperation->Start(aOperation); |
|
2054 |
|
2055 CActiveScheduler::Start(); |
|
2056 |
|
2057 periodicTimer->Cancel(); |
|
2058 |
|
2059 if (activeLmOperation->Operation()) |
|
2060 { |
|
2061 // In case of no cancel |
|
2062 activeLmOperation->DeleteOperationD(); |
|
2063 if (activeLmOperation->DeltaProgress() < 1 - aThreshold) |
|
2064 { |
|
2065 iLog->Log(_L("Test was never cancelled!")); |
|
2066 } |
|
2067 } |
|
2068 |
|
2069 CleanupStack::PopAndDestroy(2, activeLmOperation); |
|
2070 } |
|
2071 else |
|
2072 { |
|
2073 // Cancel immediately |
|
2074 RunAsyncOperationAndCancelLD(aOperation); |
|
2075 } |
|
2076 } |
|
2077 |
|
2078 // --------------------------------------------------------- |
|
2079 // CLandmarkTestProcedureBase::CancelTest |
|
2080 // |
|
2081 // (other items were commented in a header). |
|
2082 // --------------------------------------------------------- |
|
2083 // |
|
2084 TInt CLandmarkTestProcedureBase::CancelTest(TAny* aSelf) |
|
2085 { |
|
2086 CActiveLmOperation* activeLmOperation = static_cast<CActiveLmOperation*>(aSelf); |
|
2087 |
|
2088 if (activeLmOperation->Progress() >= activeLmOperation->Threshold()) |
|
2089 { |
|
2090 activeLmOperation->DeleteOperationD(); |
|
2091 } |
|
2092 |
|
2093 return 0; |
|
2094 } |
|
2095 |
|
2096 // --------------------------------------------------------- |
|
2097 // CLandmarkTestProcedureBase::DeleteFileL |
|
2098 // |
|
2099 // (other items were commented in a header). |
|
2100 // --------------------------------------------------------- |
|
2101 // |
|
2102 void CLandmarkTestProcedureBase::DeleteFileL(const TDesC& aFile) |
|
2103 { |
|
2104 TInt err = iFileSession.Delete(aFile); |
|
2105 |
|
2106 TBuf<512> buf; |
|
2107 |
|
2108 if (err == KErrNone) |
|
2109 { |
|
2110 _LIT(KDebugText, "DeleteFileL: Specified file '%S' has been deleted"); |
|
2111 buf.Format(KDebugText, &aFile, err); |
|
2112 iLog->Log(buf); |
|
2113 } |
|
2114 else |
|
2115 { |
|
2116 _LIT(KErrText, "DeleteFileL: Specified file '%S' could not be deleted, error %d"); |
|
2117 buf.Format(KErrText, &aFile, err); |
|
2118 iLog->Log(buf); |
|
2119 switch ( err ) |
|
2120 { |
|
2121 case KErrNotFound: |
|
2122 case KErrPathNotFound: |
|
2123 break; |
|
2124 default: |
|
2125 User::Leave(err); |
|
2126 break; |
|
2127 } |
|
2128 } |
|
2129 } |
|
2130 |
|
2131 // --------------------------------------------------------- |
|
2132 // CLandmarkTestProcedureBase::ServerAliveL |
|
2133 // |
|
2134 // (other items were commented in a header). |
|
2135 // --------------------------------------------------------- |
|
2136 // |
|
2137 void CLandmarkTestProcedureBase::MakeSurePanicDebugFileExistsL() |
|
2138 { |
|
2139 _LIT(KFileName, "c:\\system\\bootdata\\ErrRd"); |
|
2140 _LIT(KFilePath, "c:\\system\\bootdata\\"); |
|
2141 |
|
2142 TInt res = iFileSession.MkDirAll(KFilePath); |
|
2143 if (res != KErrAlreadyExists && res != KErrNone) |
|
2144 { |
|
2145 iLog->Log(_L("Problem creating directory c:\\system\\bootdata\\")); |
|
2146 User::Leave(res); |
|
2147 } |
|
2148 |
|
2149 RFile panicDebugFile; |
|
2150 res = panicDebugFile.Create(iFileSession, KFileName, EFileRead); |
|
2151 CleanupClosePushL(panicDebugFile); |
|
2152 |
|
2153 if (res != KErrAlreadyExists && res != KErrNone) |
|
2154 { |
|
2155 iLog->Log(_L("Problem creating file c:\\system\\bootdata\\ErrRd")); |
|
2156 User::Leave(res); |
|
2157 } |
|
2158 |
|
2159 CleanupStack::PopAndDestroy(&panicDebugFile); |
|
2160 } |
|
2161 |
|
2162 // --------------------------------------------------------- |
|
2163 // CLandmarkTestProcedureBase::ServerAliveL |
|
2164 // |
|
2165 // (other items were commented in a header). |
|
2166 // --------------------------------------------------------- |
|
2167 // |
|
2168 TBool CLandmarkTestProcedureBase::ServerAlive(const TDesC& aServerName) |
|
2169 { |
|
2170 TFindServer find(aServerName); |
|
2171 TFullName name; |
|
2172 if (find.Next(name) == KErrNone) // server found |
|
2173 { |
|
2174 TBuf<100> buf; |
|
2175 buf.Append(_L("Found server: ")); |
|
2176 buf.Append(name); |
|
2177 iLog->Log(buf); |
|
2178 return ETrue; |
|
2179 } |
|
2180 else |
|
2181 { |
|
2182 return EFalse; |
|
2183 } |
|
2184 } |
|
2185 |
|
2186 // --------------------------------------------------------- |
|
2187 // CLandmarkTestProcedureBase::ListLandmarkDbsL |
|
2188 // |
|
2189 // (other items were commented in a header). |
|
2190 // --------------------------------------------------------- |
|
2191 // |
|
2192 CDesCArray* CLandmarkTestProcedureBase::ListLandmarkDbsL() |
|
2193 { |
|
2194 CPosLmDatabaseManager* dbman = CPosLmDatabaseManager::NewL(); |
|
2195 CleanupStack::PushL(dbman); |
|
2196 CDesCArray* dbs = dbman->ListDatabasesLC(); |
|
2197 CleanupStack::Pop(dbs); |
|
2198 CleanupStack::PopAndDestroy(dbman); |
|
2199 return dbs; |
|
2200 } |
|
2201 |
|
2202 // ----------------------------------------------------------------------------- |
|
2203 // CActiveLmOperation::CActiveLmOperation |
|
2204 // C++ default constructor can NOT contain any code, that |
|
2205 // might leave. |
|
2206 // ----------------------------------------------------------------------------- |
|
2207 // |
|
2208 CActiveLmOperation::CActiveLmOperation( |
|
2209 CStifLogger* aLog, |
|
2210 TBool aUseLogFromThreadIsDisabled, |
|
2211 TReal32 aThreshold) |
|
2212 : CActive(EPriorityNormal), |
|
2213 iThreshold(aThreshold), |
|
2214 iUseLogFromThreadIsDisabled(aUseLogFromThreadIsDisabled), |
|
2215 iLog(aLog) |
|
2216 { |
|
2217 CActiveScheduler::Add(this); |
|
2218 } |
|
2219 |
|
2220 |
|
2221 // Destructor |
|
2222 CActiveLmOperation::~CActiveLmOperation() |
|
2223 { |
|
2224 Cancel(); |
|
2225 |
|
2226 } |
|
2227 |
|
2228 // --------------------------------------------------------- |
|
2229 // CActiveLmOperation::StartL |
|
2230 // |
|
2231 // (other items were commented in a header). |
|
2232 // --------------------------------------------------------- |
|
2233 // |
|
2234 void CActiveLmOperation::Start( |
|
2235 CPosLmOperation* aOperation, |
|
2236 MProgressObserver* aObserver) |
|
2237 { |
|
2238 iOperation = aOperation; |
|
2239 iObserver = aObserver; |
|
2240 |
|
2241 TTime start, stop; |
|
2242 start.UniversalTime(); |
|
2243 iOperation->NextStep(iStatus, iPassedProgress); |
|
2244 stop.UniversalTime(); |
|
2245 |
|
2246 TInt64 usec = (stop.Int64() - start.Int64()); |
|
2247 |
|
2248 TBuf8<KMsgBufSize> msg; |
|
2249 _LIT8(KTrace, "First next step took %d µs"); |
|
2250 msg.Format(KTrace, usec); |
|
2251 // Dont log if used from different threads |
|
2252 // ex TP30,TP31 |
|
2253 // Log if step took more than 0.1 seconds |
|
2254 if (!iUseLogFromThreadIsDisabled && usec > KFirstNextStepLogLimit) |
|
2255 { |
|
2256 iLog->Log(msg); |
|
2257 } |
|
2258 |
|
2259 SetActive(); |
|
2260 } |
|
2261 |
|
2262 // --------------------------------------------------------- |
|
2263 // CActiveLmOperation::RunL |
|
2264 // |
|
2265 // (other items were commented in a header). |
|
2266 // --------------------------------------------------------- |
|
2267 // |
|
2268 void CActiveLmOperation::RunL() |
|
2269 { |
|
2270 if (iPassedProgress < iLastProgress) |
|
2271 { |
|
2272 iAsyncProgressErr = ETrue; |
|
2273 } |
|
2274 |
|
2275 iDeltaProgress = iPassedProgress - iLastProgress; |
|
2276 iLastProgress = iPassedProgress; |
|
2277 if (iObserver) |
|
2278 { |
|
2279 iObserver->NotifyProgress(iPassedProgress); |
|
2280 } |
|
2281 |
|
2282 if (iStatus == KPosLmOperationNotComplete && iOperation) |
|
2283 { |
|
2284 if (iLastProgress == 1.0) |
|
2285 { |
|
2286 iPassedProgressErr = ETrue; |
|
2287 } |
|
2288 |
|
2289 iOperation->NextStep(iStatus, iPassedProgress); |
|
2290 |
|
2291 if (iCancelTest) |
|
2292 { |
|
2293 User::After(1); |
|
2294 } |
|
2295 |
|
2296 SetActive(); |
|
2297 } |
|
2298 else |
|
2299 { |
|
2300 if (iStatus == KErrNone && iPassedProgress != 1.0) |
|
2301 { |
|
2302 iPassedProgressErr = ETrue; |
|
2303 } |
|
2304 |
|
2305 iLastProgress = 0; |
|
2306 CActiveScheduler::Stop(); |
|
2307 } |
|
2308 |
|
2309 |
|
2310 } |
|
2311 |
|
2312 // --------------------------------------------------------- |
|
2313 // CActiveLmOperation::DoCancel |
|
2314 // |
|
2315 // (other items were commented in a header). |
|
2316 // --------------------------------------------------------- |
|
2317 // |
|
2318 void CActiveLmOperation::DoCancel() |
|
2319 { |
|
2320 |
|
2321 } |
|
2322 |
|
2323 // --------------------------------------------------------- |
|
2324 // CActiveLmOperation::CheckOperationL |
|
2325 // |
|
2326 // (other items were commented in a header). |
|
2327 // --------------------------------------------------------- |
|
2328 // |
|
2329 void CActiveLmOperation::CheckOperationL() |
|
2330 { |
|
2331 _LIT(KAsyncStatusErr, "Status incorrect in RunL = %d"); |
|
2332 _LIT(KAsyncProgressErr, "Progress not updated in RunL"); |
|
2333 _LIT(KPassedProgressErr, "Passed Progress is not updated correctly in RunL"); |
|
2334 |
|
2335 if (iAsyncProgressErr) |
|
2336 { |
|
2337 iLog->Log(KAsyncProgressErr); |
|
2338 User::Leave(KErrGeneral); |
|
2339 } |
|
2340 |
|
2341 if (iPassedProgressErr) |
|
2342 { |
|
2343 iLog->Log(KPassedProgressErr); |
|
2344 User::Leave(KErrGeneral); |
|
2345 } |
|
2346 |
|
2347 if (iStatus != KErrNone) |
|
2348 { |
|
2349 if (!iUseLogFromThreadIsDisabled) |
|
2350 { |
|
2351 TBuf<100> info; |
|
2352 info.Format(KAsyncStatusErr, iStatus.Int()); |
|
2353 iLog->Log(info); |
|
2354 } |
|
2355 User::Leave(iStatus.Int()); |
|
2356 } |
|
2357 |
|
2358 iAsyncProgressErr = iPassedProgressErr = EFalse; |
|
2359 |
|
2360 } |
|
2361 |
|
2362 // --------------------------------------------------------- |
|
2363 // CActiveLmOperation::DeleteOperationD |
|
2364 // |
|
2365 // (other items were commented in a header). |
|
2366 // --------------------------------------------------------- |
|
2367 void CActiveLmOperation::DeleteOperationD() |
|
2368 { |
|
2369 delete iOperation; |
|
2370 iOperation = NULL; |
|
2371 } |
|
2372 |
|
2373 // --------------------------------------------------------- |
|
2374 // CActiveLmOperation::Status |
|
2375 // |
|
2376 // (other items were commented in a header). |
|
2377 // --------------------------------------------------------- |
|
2378 // |
|
2379 TInt CActiveLmOperation::Status() const |
|
2380 { |
|
2381 return iStatus.Int(); |
|
2382 } |
|
2383 |
|
2384 // --------------------------------------------------------- |
|
2385 // CActiveLmOperation::Progress |
|
2386 // |
|
2387 // (other items were commented in a header). |
|
2388 // --------------------------------------------------------- |
|
2389 // |
|
2390 TReal CActiveLmOperation::Progress() const |
|
2391 { |
|
2392 return iLastProgress; |
|
2393 } |
|
2394 |
|
2395 // --------------------------------------------------------- |
|
2396 // CActiveLmOperation::Operation |
|
2397 // |
|
2398 // (other items were commented in a header). |
|
2399 // --------------------------------------------------------- |
|
2400 CPosLmOperation* CActiveLmOperation::Operation() |
|
2401 { |
|
2402 return iOperation; |
|
2403 } |
|
2404 |
|
2405 //--------------------------------------------------------- |
|
2406 // CActiveLmOperation::SetCancelTest |
|
2407 // |
|
2408 // (other items were commented in a header). |
|
2409 // --------------------------------------------------------- |
|
2410 // |
|
2411 void CActiveLmOperation::SetCancelTest() |
|
2412 { |
|
2413 iCancelTest = ETrue; |
|
2414 } |
|
2415 |
|
2416 //--------------------------------------------------------- |
|
2417 // CActiveLmOperation::Threshold |
|
2418 // |
|
2419 // (other items were commented in a header). |
|
2420 // --------------------------------------------------------- |
|
2421 // |
|
2422 TReal32 CActiveLmOperation::Threshold() |
|
2423 { |
|
2424 return iThreshold; |
|
2425 } |
|
2426 |
|
2427 //--------------------------------------------------------- |
|
2428 // CActiveLmOperation::DeltaProgress |
|
2429 // |
|
2430 // (other items were commented in a header). |
|
2431 // --------------------------------------------------------- |
|
2432 // |
|
2433 TReal32 CActiveLmOperation::DeltaProgress() |
|
2434 { |
|
2435 return iDeltaProgress; |
|
2436 } |
|
2437 |
|
2438 // <---------------- inner class COnTheFlyTester (utility class for testing multiDbSearch) ----------------> |
|
2439 |
|
2440 // Constructor |
|
2441 CLandmarkTestProcedureBase::COnTheFlyTester::COnTheFlyTester() : CActive(CActive::EPriorityStandard) |
|
2442 { |
|
2443 CActiveScheduler::Add(this); |
|
2444 } |
|
2445 |
|
2446 // Desctructor |
|
2447 CLandmarkTestProcedureBase::COnTheFlyTester::~COnTheFlyTester() |
|
2448 { |
|
2449 delete iDisplayData; |
|
2450 delete iOperation; |
|
2451 Cancel(); |
|
2452 } |
|
2453 |
|
2454 // --------------------------------------------------------- |
|
2455 // CLandmarkTestProcedureBase::COnTheFlyTester::NewLC |
|
2456 // |
|
2457 // (other items were commented in a header). |
|
2458 // --------------------------------------------------------- |
|
2459 // |
|
2460 CLandmarkTestProcedureBase::COnTheFlyTester* CLandmarkTestProcedureBase::COnTheFlyTester::NewLC() |
|
2461 { |
|
2462 CLandmarkTestProcedureBase::COnTheFlyTester* self = new (ELeave) CLandmarkTestProcedureBase::COnTheFlyTester; |
|
2463 CleanupStack::PushL(self); |
|
2464 return self; |
|
2465 } |
|
2466 |
|
2467 // --------------------------------------------------------- |
|
2468 // CLandmarkTestProcedureBase::COnTheFlyTester::StartSearchCampaignL |
|
2469 // |
|
2470 // (other items were commented in a header). |
|
2471 // --------------------------------------------------------- |
|
2472 // |
|
2473 void CLandmarkTestProcedureBase::COnTheFlyTester::StartSearchCampaignL( |
|
2474 CPosLmMultiDbSearch* aSearcher, |
|
2475 const RIdArray& aExpectedMatches, |
|
2476 CPosLmSearchCriteria* aSearchCriteria) |
|
2477 { |
|
2478 iSearcher = aSearcher; |
|
2479 iExpectedMatches = &aExpectedMatches; |
|
2480 |
|
2481 // Set DisplayData |
|
2482 delete iDisplayData; |
|
2483 iDisplayData = NULL; |
|
2484 iDisplayData = CPosLmDisplayData::NewL(); |
|
2485 CPosLmPartialReadParameters* partialReadParams = CPosLmPartialReadParameters::NewLC(); |
|
2486 partialReadParams->SetRequestedAttributes(CPosLandmark::ELandmarkName); |
|
2487 iDisplayData->SetPartialReadParametersL(*partialReadParams); |
|
2488 iSearcher->SetDisplayData(*iDisplayData); |
|
2489 CleanupStack::PopAndDestroy(partialReadParams); |
|
2490 |
|
2491 // Start search |
|
2492 TPosLmSortPref sortPref(CPosLandmark::ELandmarkName, TPosLmSortPref::EAscending); |
|
2493 delete iOperation; |
|
2494 iOperation = NULL; |
|
2495 iOperation = iSearcher->StartLandmarkSearchL(*aSearchCriteria, sortPref); |
|
2496 iOperation->NextStep(iStatus, iProgress); |
|
2497 SetActive(); |
|
2498 |
|
2499 CActiveScheduler::Start(); |
|
2500 } |
|
2501 |
|
2502 // --------------------------------------------------------- |
|
2503 // CLandmarkTestProcedureBase::COnTheFlyTester::RunL |
|
2504 // |
|
2505 // (other items were commented in a header). |
|
2506 // --------------------------------------------------------- |
|
2507 // |
|
2508 void CLandmarkTestProcedureBase::COnTheFlyTester::RunL() |
|
2509 { |
|
2510 iErr = iStatus.Int(); |
|
2511 switch (iErr) |
|
2512 { |
|
2513 case KPosLmOperationNotComplete: |
|
2514 VerifyOnTheFlyDataL(); |
|
2515 iOperation->NextStep(iStatus, iProgress); |
|
2516 SetActive(); |
|
2517 break; |
|
2518 |
|
2519 case KErrNone: |
|
2520 VerifyOnTheFlyDataL(ETrue); |
|
2521 CActiveScheduler::Stop(); |
|
2522 break; |
|
2523 |
|
2524 default: |
|
2525 User::Leave(iErr); |
|
2526 } |
|
2527 } |
|
2528 |
|
2529 // --------------------------------------------------------- |
|
2530 // CLandmarkTestProcedureBase::COnTheFlyTester::DoCancel |
|
2531 // |
|
2532 // (other items were commented in a header). |
|
2533 // --------------------------------------------------------- |
|
2534 // |
|
2535 void CLandmarkTestProcedureBase::COnTheFlyTester::DoCancel() |
|
2536 { |
|
2537 delete iOperation; |
|
2538 iOperation = NULL; |
|
2539 CActiveScheduler::Stop(); |
|
2540 } |
|
2541 |
|
2542 // --------------------------------------------------------- |
|
2543 // CLandmarkTestProcedureBase::COnTheFlyTester::RunError |
|
2544 // |
|
2545 // (other items were commented in a header). |
|
2546 // --------------------------------------------------------- |
|
2547 // |
|
2548 TInt CLandmarkTestProcedureBase::COnTheFlyTester::RunError(TInt aError) |
|
2549 { |
|
2550 iErr = aError; |
|
2551 CActiveScheduler::Stop(); |
|
2552 return KErrNone; |
|
2553 } |
|
2554 |
|
2555 // --------------------------------------------------------- |
|
2556 // CLandmarkTestProcedureBase::COnTheFlyTester::VerifyOnTheFlyDataL |
|
2557 // |
|
2558 // (other items were commented in a header). |
|
2559 // --------------------------------------------------------- |
|
2560 // |
|
2561 void CLandmarkTestProcedureBase::COnTheFlyTester::VerifyOnTheFlyDataL(TBool aIsFinished) |
|
2562 { |
|
2563 // No errors should have occurred |
|
2564 if (iSearcher->NumOfSearchErrors() != 0) |
|
2565 { |
|
2566 iBuf = _L("iSearcher->NumOfSearchErrors() != 0"); |
|
2567 User::Leave(KErrGeneral); |
|
2568 } |
|
2569 |
|
2570 // Verify that number of found matches does not decrease |
|
2571 TInt nrOfItems = iDisplayData->Count(); |
|
2572 if (nrOfItems < iNrOfOldItems) |
|
2573 { |
|
2574 iBuf = _L("nrOfItems < iNrOfOldItems"); |
|
2575 User::Leave(KErrGeneral); |
|
2576 } |
|
2577 iNrOfOldItems = nrOfItems; |
|
2578 |
|
2579 // Verify sort order |
|
2580 for (TInt i = 0; i < nrOfItems; i++) |
|
2581 { |
|
2582 CPosLmDisplayItem& displayItem = iDisplayData->DisplayItem(i); |
|
2583 if (displayItem.DisplayItemType() != CPosLmDisplayItem::ELandmarkItem) |
|
2584 { |
|
2585 iBuf = _L("Wrong displayItemType"); |
|
2586 User::Leave(KErrGeneral); |
|
2587 } |
|
2588 if (i < nrOfItems - 1) |
|
2589 { |
|
2590 TPtrC name1, name2; |
|
2591 displayItem.Landmark().GetLandmarkName(name1); |
|
2592 iDisplayData->DisplayItem(i + 1).Landmark().GetLandmarkName(name2); |
|
2593 if (name1.CompareC(name2) > 0) |
|
2594 { |
|
2595 iBuf.Format(_L("%S is greater than %S"), &name1, &name2); |
|
2596 User::Leave(KErrGeneral); |
|
2597 } |
|
2598 } |
|
2599 } |
|
2600 |
|
2601 // When completed, the expected number of matches should have been found |
|
2602 if (aIsFinished) |
|
2603 { |
|
2604 TInt totNrOfMatches = iSearcher->TotalNumOfMatches(); |
|
2605 TInt expectedNrOfHits = iExpectedMatches->Count(); |
|
2606 if (totNrOfMatches != expectedNrOfHits) |
|
2607 { |
|
2608 iBuf.Format(_L("Wrong number of landmarks returned when searching for landmarks, found: %d expected %d"), totNrOfMatches, expectedNrOfHits); |
|
2609 User::Leave(KErrGeneral); |
|
2610 } |
|
2611 for (TInt i = 0; i < expectedNrOfHits; i++) |
|
2612 { |
|
2613 TInt found = iExpectedMatches->Find(iDisplayData->DisplayItem(i).Landmark().LandmarkId()); |
|
2614 if (found == KErrNotFound) |
|
2615 { |
|
2616 iBuf.Format(_L("Non-qualified landmark was found")); |
|
2617 User::Leave(KErrNotFound); |
|
2618 } |
|
2619 TPtrC name; |
|
2620 iDisplayData->DisplayItem(i).Landmark().GetLandmarkName(name); |
|
2621 } |
|
2622 } |
|
2623 } |
|
2624 |
|
2625 // --------------------------------------------------------- |
|
2626 // --------------------------------------------------------- |
|
2627 // |
|
2628 void CLandmarkTestProcedureBase::ReadGlobalCategoriesFromResourceL( |
|
2629 RArray<TUint>& aCatIds, |
|
2630 RPointerArray<HBufC>& aCatNames, |
|
2631 TInt aMaxNum ) |
|
2632 { |
|
2633 _LIT(KGlobalCategoryResourceFile, "z:\\Resource\\eposlmglobalcategories.rsc"); |
|
2634 const TInt KPosLmGlCatResourceOffset = 1; |
|
2635 |
|
2636 TFileName filename(KGlobalCategoryResourceFile); |
|
2637 BaflUtils::NearestLanguageFile( iFileSession, filename ); |
|
2638 |
|
2639 CResourceFile* resFile = CResourceFile::NewLC( iFileSession, filename, 0, 0 ); |
|
2640 |
|
2641 RResourceReader reader; |
|
2642 reader.OpenLC( resFile, KPosLmGlCatResourceOffset ); |
|
2643 |
|
2644 // Read the size of the icon path array. |
|
2645 TInt size = reader.ReadInt8L(); |
|
2646 |
|
2647 // read icon paths |
|
2648 for (TInt i = 0; i < size; i++) |
|
2649 { |
|
2650 HBufC* path = reader.ReadHBufCL(); |
|
2651 delete path; |
|
2652 } |
|
2653 |
|
2654 // read category data |
|
2655 size = reader.ReadInt16L(); |
|
2656 if ( aMaxNum > 0 ) |
|
2657 { |
|
2658 size = Min( size, aMaxNum ); |
|
2659 } |
|
2660 |
|
2661 for (TInt i = 0; i < size; i++) |
|
2662 { |
|
2663 TInt id = reader.ReadUint32L(); |
|
2664 aCatIds.Append( id ); |
|
2665 HBufC* name = reader.ReadHBufCL(); |
|
2666 aCatNames.Append( name ); |
|
2667 |
|
2668 //iLog->Log(_L("Localized category: id: %d, name: '%S'"), id, name); |
|
2669 |
|
2670 reader.ReadInt32L(); |
|
2671 reader.ReadInt32L(); |
|
2672 reader.ReadInt8L(); |
|
2673 } |
|
2674 CleanupStack::PopAndDestroy( &reader ); |
|
2675 CleanupStack::PopAndDestroy( resFile ); |
|
2676 } |
|
2677 |
|
2678 |
|
2679 // --------------------------------------------------------- |
|
2680 // --------------------------------------------------------- |
|
2681 // |
|
2682 void CLandmarkTestProcedureBase::ResetAndDestroyHBufCArray( TAny* aPointer ) |
|
2683 { |
|
2684 RPointerArray<HBufC>* array = ( RPointerArray<HBufC>* ) aPointer; |
|
2685 array->ResetAndDestroy(); |
|
2686 } |
|
2687 |
|
2688 // --------------------------------------------------------- |
|
2689 // --------------------------------------------------------- |
|
2690 // |
|
2691 void CLandmarkTestProcedureBase::CreateCorrectXmlFileL( const TDesC& aSampleFile, TFileName& aFileName ) |
|
2692 { |
|
2693 _LIT( KTargetFolder, "c:\\documents\\" ); |
|
2694 _LIT( KNewFileSuffix, ".localized" ); |
|
2695 |
|
2696 iLog->Log(_L("Making localized XML file out of '%S'"), &aSampleFile ); |
|
2697 |
|
2698 RFileReadStream source; |
|
2699 TInt err = source.Open( iFileSession, aSampleFile, EFileRead ); |
|
2700 if ( err ) |
|
2701 { |
|
2702 iLog->Log(_L("Failed to open source file '%S', err %d"), &aSampleFile, err ); |
|
2703 User::Leave( err ); |
|
2704 } |
|
2705 CleanupClosePushL( source ); |
|
2706 |
|
2707 TParse parse; |
|
2708 parse.Set( aSampleFile, 0, 0 ); |
|
2709 aFileName = KTargetFolder; |
|
2710 aFileName.Append( parse.Name() ); |
|
2711 aFileName.Append( KNewFileSuffix ); |
|
2712 aFileName.Append( parse.Ext() ); |
|
2713 |
|
2714 RFile target; |
|
2715 err = target.Replace( iFileSession, aFileName, EFileRead ); |
|
2716 if ( err ) |
|
2717 { |
|
2718 iLog->Log(_L("Failed to create target file '%S', err %d"), &aFileName, err ); |
|
2719 User::Leave( err ); |
|
2720 } |
|
2721 CleanupClosePushL( target ); |
|
2722 |
|
2723 // Replace Global Category macros with correct strings |
|
2724 |
|
2725 RArray<TUint> globalIds; |
|
2726 RPointerArray<HBufC> names; |
|
2727 CleanupStack::PushL( TCleanupItem( CLandmarkTestProcedureBase::ResetAndDestroyHBufCArray, &names ) ); |
|
2728 ReadGlobalCategoriesFromResourceL( globalIds, names ); |
|
2729 |
|
2730 const TChar KIdStart = '{'; |
|
2731 const TChar KIdEnd = '}'; |
|
2732 //category name length should be <= 124 |
|
2733 _LIT( KGlobalCategoryMacro, "__GLOBAL_CAT_{" ); |
|
2734 |
|
2735 TBuf8<1024> line8; |
|
2736 while ( !err ) |
|
2737 { |
|
2738 TRAP( err, source.ReadL( line8, TChar('\n') ) ); |
|
2739 if ( !err ) |
|
2740 { |
|
2741 HBufC* line16 = CnvUtfConverter::ConvertToUnicodeFromUtf8L( line8 ); |
|
2742 CleanupStack::PushL( line16 ); |
|
2743 TPtr line( line16->Des() ); |
|
2744 |
|
2745 TInt macroStart = line.Find( KGlobalCategoryMacro ); |
|
2746 if ( macroStart != KErrNotFound ) |
|
2747 { |
|
2748 // find global categoryid in the macro |
|
2749 TInt idStart = line.Locate( KIdStart ); |
|
2750 TInt idEnd = line.Locate( KIdEnd ); |
|
2751 |
|
2752 TLex idStr( line.Mid( idStart + 1, idEnd - idStart - 1 ) ); |
|
2753 |
|
2754 TUint globalId = 0; |
|
2755 idStr.Val( globalId ); |
|
2756 |
|
2757 // find localized string for the category |
|
2758 TInt idIndex = globalIds.Find( globalId ); |
|
2759 |
|
2760 // put it to the file instead of macro |
|
2761 if ( idIndex >= 0 ) |
|
2762 { |
|
2763 HBufC* des = EscapeStringToXmlLC(*(names[idIndex])); |
|
2764 |
|
2765 |
|
2766 if(des->Length() > (idEnd - macroStart + 1)) |
|
2767 { |
|
2768 TInt diffrence = des->Length() - (idEnd - macroStart + 1); |
|
2769 HBufC* diffStr = HBufC::NewLC(diffrence * 2); |
|
2770 TPtr ptr(diffStr->Des()); |
|
2771 TInt i=0; |
|
2772 for(i=0; i<diffrence; i++) |
|
2773 { |
|
2774 ptr.Append(' '); |
|
2775 } |
|
2776 line16->ReAllocL(line.MaxLength() + i); |
|
2777 TPtr newPtr(line16->Des()); |
|
2778 newPtr.Insert(idEnd, ptr); |
|
2779 newPtr.Replace( macroStart, (idEnd + i) - macroStart + 1, des->Des() ); |
|
2780 HBufC8* newLine8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( newPtr ); |
|
2781 target.Write( *newLine8 ); |
|
2782 delete newLine8; |
|
2783 CleanupStack::PopAndDestroy( diffStr ); |
|
2784 } |
|
2785 else |
|
2786 { |
|
2787 line.Replace( macroStart, idEnd - macroStart + 1, des->Des() ); |
|
2788 HBufC8* newLine8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( line ); |
|
2789 target.Write( *newLine8 ); |
|
2790 delete newLine8; |
|
2791 } |
|
2792 CleanupStack::PopAndDestroy(des); |
|
2793 } |
|
2794 |
|
2795 |
|
2796 } |
|
2797 else |
|
2798 { |
|
2799 target.Write( line8 ); |
|
2800 } |
|
2801 |
|
2802 CleanupStack::PopAndDestroy( line16 ); |
|
2803 } |
|
2804 else |
|
2805 { |
|
2806 iLog->Log(_L("Stopped reading from '%S' with code %d"), &aSampleFile, err ); |
|
2807 } |
|
2808 } |
|
2809 |
|
2810 target.Flush(); |
|
2811 CleanupStack::PopAndDestroy(); // names |
|
2812 CleanupStack::PopAndDestroy( &target ); |
|
2813 CleanupStack::PopAndDestroy( &source ); |
|
2814 } |
|
2815 |
|
2816 // --------------------------------------------------------- |
|
2817 // --------------------------------------------------------- |
|
2818 // |
|
2819 HBufC* CLandmarkTestProcedureBase::GetGlobalCategoryFromResourceLC( TPosLmGlobalCategory aGlobalId ) |
|
2820 { |
|
2821 HBufC* name = NULL; |
|
2822 RArray<TUint> catIds; |
|
2823 RPointerArray<HBufC> catNames; |
|
2824 |
|
2825 CleanupClosePushL( catIds ); |
|
2826 CleanupStack::PushL( TCleanupItem( ResetAndDestroyHBufCArray, &catNames )); |
|
2827 |
|
2828 ReadGlobalCategoriesFromResourceL( catIds, catNames ); |
|
2829 TInt idIndex = catIds.Find( aGlobalId ); |
|
2830 if ( idIndex >= 0 ) |
|
2831 { |
|
2832 name = catNames[idIndex]; |
|
2833 catNames.Remove( idIndex ); |
|
2834 } |
|
2835 else |
|
2836 { |
|
2837 iLog->Log(_L("Global category %d not found"), aGlobalId ); |
|
2838 User::Leave( KErrNotFound ); |
|
2839 } |
|
2840 CleanupStack::PopAndDestroy(); //catNames |
|
2841 CleanupStack::PopAndDestroy( &catIds ); |
|
2842 |
|
2843 CleanupStack::PushL( name ); |
|
2844 return name; |
|
2845 } |
|
2846 |
|
2847 // --------------------------------------------------------- |
|
2848 // --------------------------------------------------------- |
|
2849 // |
|
2850 HBufC* CLandmarkTestProcedureBase::ReadDefaultDatabaseNameFromResourceLC() |
|
2851 { |
|
2852 _LIT(KDatabaseNameResourceFile, "z:\\resource\\eposlmdefaultdbname.rsc"); |
|
2853 const TInt KNameResourceOffset = 2; |
|
2854 |
|
2855 TFileName filename( KDatabaseNameResourceFile ); |
|
2856 BaflUtils::NearestLanguageFile( iFileSession, filename ); |
|
2857 |
|
2858 CResourceFile* resFile = CResourceFile::NewLC( iFileSession, filename, 0, 0 ); |
|
2859 |
|
2860 RResourceReader reader; |
|
2861 reader.OpenLC( resFile, KNameResourceOffset ); |
|
2862 |
|
2863 HBufC* name = reader.ReadHBufCL(); |
|
2864 |
|
2865 CleanupStack::PopAndDestroy( &reader ); |
|
2866 CleanupStack::PopAndDestroy( resFile ); |
|
2867 |
|
2868 CleanupStack::PushL( name ); |
|
2869 return name; |
|
2870 } |
|
2871 |
|
2872 // ----------------------------------------------------------------------------- |
|
2873 // PosLmConverterUtils::EscapeStringToXmlLC |
|
2874 // |
|
2875 // (other items were commented in a header). |
|
2876 // ----------------------------------------------------------------------------- |
|
2877 // |
|
2878 HBufC* CLandmarkTestProcedureBase::EscapeStringToXmlLC( |
|
2879 const TDesC& aStrToEscape) |
|
2880 { |
|
2881 HBufC* string = HBufC::NewLC(CalculateEscapedStringSize(aStrToEscape)); |
|
2882 string->Des().Copy(aStrToEscape); |
|
2883 |
|
2884 // Must start with &, because when escaping other characters & will be |
|
2885 // added to the string. |
|
2886 TPtr ptr = string->Des(); |
|
2887 EscapeString(ptr, KAmp, KAmpXmlStr); |
|
2888 EscapeString(ptr, KLt, KLtXmlStr); |
|
2889 EscapeString(ptr, KGt, KGtXmlStr); |
|
2890 EscapeString(ptr, KApos, KAposXmlStr); |
|
2891 EscapeString(ptr, KQuot, KQuotXmlStr); |
|
2892 |
|
2893 return string; |
|
2894 } |
|
2895 |
|
2896 // ----------------------------------------------------------------------------- |
|
2897 // PosLmConverterUtils::EscapeString |
|
2898 // |
|
2899 // (other items were commented in a header). |
|
2900 // ----------------------------------------------------------------------------- |
|
2901 // |
|
2902 void CLandmarkTestProcedureBase::EscapeString( |
|
2903 TDes& aStrToEscape, |
|
2904 const TDesC& aFromStr, |
|
2905 const TDesC& aToStr) |
|
2906 { |
|
2907 TPtrC ptr(aStrToEscape); |
|
2908 TInt lastPos = 0; |
|
2909 |
|
2910 // Find first occurence of the escape string. |
|
2911 TInt pos = ptr.Find(aFromStr); |
|
2912 |
|
2913 while (pos != KErrNotFound) |
|
2914 { |
|
2915 aStrToEscape.Replace(pos+lastPos, aFromStr.Length(), aToStr); |
|
2916 |
|
2917 // Move ptr forward past the inserted aToStr in aStrToEscape |
|
2918 pos += aToStr.Length(); |
|
2919 lastPos += pos; |
|
2920 ptr.Set(aStrToEscape.Right(aStrToEscape.Length() - lastPos)); |
|
2921 |
|
2922 // Find next occurence of the escape string. |
|
2923 pos = ptr.Find(aFromStr); |
|
2924 } |
|
2925 } |
|
2926 |
|
2927 // ----------------------------------------------------------------------------- |
|
2928 // PosLmConverterUtils::CalculateEscapedStringSize |
|
2929 // |
|
2930 // (other items were commented in a header). |
|
2931 // ----------------------------------------------------------------------------- |
|
2932 // |
|
2933 TInt CLandmarkTestProcedureBase::CalculateEscapedStringSize( |
|
2934 const TDesC& aStrToEscape) |
|
2935 { |
|
2936 return aStrToEscape.Length() + |
|
2937 CalculateIncrease(aStrToEscape, KAmp, KAmpXmlStr) + |
|
2938 CalculateIncrease(aStrToEscape, KLt, KLtXmlStr) + |
|
2939 CalculateIncrease(aStrToEscape, KGt, KGtXmlStr) + |
|
2940 CalculateIncrease(aStrToEscape, KApos, KAposXmlStr) + |
|
2941 CalculateIncrease(aStrToEscape, KQuot, KQuotXmlStr); |
|
2942 } |
|
2943 |
|
2944 // ----------------------------------------------------------------------------- |
|
2945 // PosLmConverterUtils::CalculateIncrease |
|
2946 // |
|
2947 // (other items were commented in a header). |
|
2948 // ----------------------------------------------------------------------------- |
|
2949 // |
|
2950 TInt CLandmarkTestProcedureBase::CalculateIncrease( |
|
2951 const TDesC& aStrToEscape, |
|
2952 const TDesC& aFromStr, |
|
2953 const TDesC& aToStr) |
|
2954 { |
|
2955 TPtrC ptr(aStrToEscape); |
|
2956 TInt occurrences = 0; |
|
2957 |
|
2958 // Find first occurence of the escape string. |
|
2959 TInt pos = ptr.Find(aFromStr); |
|
2960 |
|
2961 while (pos != KErrNotFound) |
|
2962 { |
|
2963 ++occurrences; |
|
2964 |
|
2965 // Move ptr forward past the found occurence. |
|
2966 ptr.Set(ptr.Right(ptr.Length() - (pos + aFromStr.Length()))); |
|
2967 |
|
2968 // Find next occurence of the escaped string. |
|
2969 pos = ptr.Find(aFromStr); |
|
2970 } |
|
2971 |
|
2972 // Return the increased (or decreased) size impact on the string to escape. |
|
2973 return occurrences*(aToStr.Length() - aFromStr.Length()); |
|
2974 } |