|
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 // INCLUDES |
|
20 #include "FT_CPosTp152.h" |
|
21 #include <EPos_CPosLandmarkDatabase.h> |
|
22 #include <EPos_CPosLandmarkParser.h> |
|
23 #include <EPos_CPosLandmarkEncoder.h> |
|
24 #include <LbsPosition.h> |
|
25 #include <e32math.h> |
|
26 #include <bautils.h> |
|
27 #include <utf.h> |
|
28 #include <xml/xmlparsererrors.h> |
|
29 |
|
30 // CONSTANTS |
|
31 |
|
32 _LIT(KFileTrace, "c:\\documents\\LandmarksTP152Trace.txt"); |
|
33 |
|
34 // See \epoc32\include\xml\XmlParserErrors.h for error codes |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 // See \epoc32\include\xml\XmlParserErrors.h for error codes |
|
40 |
|
41 |
|
42 _LIT(KCorrectFile, "c:\\system\\test\\TestData\\CorrectFileFor_LandmarksTP152Trace.txt"); |
|
43 |
|
44 _LIT(KKMZFile, "c:\\system\\test\\TestData\\Tp152KMZFile.kmz"); |
|
45 |
|
46 |
|
47 // Maxmimum size for each line in trace file |
|
48 const TInt KBufSize = 5000; |
|
49 |
|
50 // ================= MEMBER FUNCTIONS ======================= |
|
51 // --------------------------------------------------------- |
|
52 // CPosTp152::CloseTest |
|
53 // |
|
54 // (other items were commented in a header). |
|
55 // --------------------------------------------------------- |
|
56 // |
|
57 void CPosTp152::CloseTest() |
|
58 { |
|
59 iLog->Log(_L("CloseTest")); |
|
60 |
|
61 delete iEncoderBuffer; |
|
62 iEncoderBuffer = NULL; |
|
63 |
|
64 iLandmarks.ResetAndDestroy(); |
|
65 iLandmarks.Close(); |
|
66 |
|
67 |
|
68 delete iLandmarkEncoder; |
|
69 iLandmarkEncoder = NULL; |
|
70 |
|
71 delete iLandmarkParser; |
|
72 iLandmarkParser = NULL; |
|
73 |
|
74 delete iOperation; |
|
75 iOperation = NULL; |
|
76 |
|
77 |
|
78 iLog->Log(_L("CloseTest Done")); |
|
79 } |
|
80 |
|
81 // --------------------------------------------------------- |
|
82 // CPosTp152::StartL |
|
83 // |
|
84 // (other items were commented in a header). |
|
85 // --------------------------------------------------------- |
|
86 // |
|
87 void CPosTp152::StartL() |
|
88 { |
|
89 BaflUtils::EnsurePathExistsL( iFileSession, KKMZFile ); |
|
90 |
|
91 |
|
92 // Delete the trace file |
|
93 DeleteFileL(KFileTrace); |
|
94 |
|
95 |
|
96 HBufC8* emptyBuffer=NULL; |
|
97 |
|
98 iLog->Log(_L("Test with Tp152KMZFile.kmz")); |
|
99 PrintParsedDataFromEncoderL(KKMZFile, *emptyBuffer, KErrNone, KKmzMimeType ); |
|
100 |
|
101 |
|
102 // Now compare tha trace file against the correct one |
|
103 RFile correctFile; |
|
104 RFile file; |
|
105 |
|
106 iLog->Log(_L(">>>>>>>Comparing files<<<<<")); |
|
107 |
|
108 TFileName filename; |
|
109 CreateCorrectXmlFileL( KCorrectFile, filename ); |
|
110 |
|
111 User::LeaveIfError(correctFile.Open(iFileSession, filename, EFileRead)); |
|
112 CleanupClosePushL(correctFile); |
|
113 User::LeaveIfError(file.Open(iFileSession, KFileTrace, EFileRead)); |
|
114 CleanupClosePushL(file); |
|
115 |
|
116 HBufC* correctLinebuffer = HBufC::NewLC( KBufSize ); |
|
117 TPtr correctLine = correctLinebuffer->Des(); |
|
118 HBufC* linebuffer = HBufC::NewLC( KBufSize ); |
|
119 TPtr line = linebuffer->Des(); |
|
120 |
|
121 TInt err = KErrNone; |
|
122 TBool done = EFalse; |
|
123 TInt lineNr = 0; |
|
124 |
|
125 while (ReadLn(correctFile, correctLine) != KErrEof && !done) |
|
126 { |
|
127 lineNr++; |
|
128 err = ReadLn(file, line); |
|
129 if ( err == KErrEof ) |
|
130 { |
|
131 done = ETrue; |
|
132 } |
|
133 correctLine.Trim(); |
|
134 line.Trim(); |
|
135 if (correctLine.Compare(line) != KErrNone) |
|
136 { |
|
137 HBufC* buf = HBufC::NewLC( 128 ); |
|
138 TPtr buffer = buf->Des(); |
|
139 |
|
140 buffer.Format(_L("ERROR in TraceFile on line %d: "), lineNr); |
|
141 |
|
142 iLog->Log( buffer ); |
|
143 iLog->Log( correctLine ); |
|
144 iLog->Log( line ); |
|
145 iErrorsFound++; |
|
146 CleanupStack::PopAndDestroy( buf ); |
|
147 } |
|
148 } |
|
149 |
|
150 CleanupStack::PopAndDestroy(linebuffer); |
|
151 CleanupStack::PopAndDestroy(correctLinebuffer); |
|
152 CleanupStack::PopAndDestroy(&file); |
|
153 CleanupStack::PopAndDestroy(&correctFile); |
|
154 |
|
155 // EOF for trace file was reach before EOF in the correct file |
|
156 if (done) |
|
157 { |
|
158 iLog->Log(_L("ERROR: EOF for Trace file was reached to early")); |
|
159 iErrorsFound++; |
|
160 } |
|
161 |
|
162 |
|
163 DoCancelTestL(); |
|
164 |
|
165 if (iErrorsFound != KErrNone) |
|
166 { |
|
167 iLog->Log(_L("Errors found in TP152")); |
|
168 User::Leave(-1); |
|
169 } |
|
170 } |
|
171 |
|
172 // --------------------------------------------------------- |
|
173 // CPosTp152::DoCancelTestL |
|
174 // |
|
175 // (other items were commented in a header). |
|
176 // --------------------------------------------------------- |
|
177 // |
|
178 void CPosTp152::DoCancelTestL() |
|
179 { |
|
180 iLog->Log(_L("DoCancelTestL")); |
|
181 iLandmarkParser = CPosLandmarkParser::NewL(KKmzMimeType); |
|
182 iLandmarkParser->SetInputFileL(KKMZFile); |
|
183 |
|
184 iOperation = iLandmarkParser->ParseContentL(); |
|
185 |
|
186 TRequestStatus status = KPosLmOperationNotComplete; |
|
187 TReal32 progress; |
|
188 |
|
189 // 1 ) Cancel parse function by deleting iOperation |
|
190 delete iOperation; |
|
191 iOperation = NULL; |
|
192 |
|
193 TUint32 nr = iLandmarkParser->NumOfParsedLandmarks(); |
|
194 if ((TInt)nr != 0) |
|
195 { |
|
196 iLog->Log(_L("No landmarks should be found")); |
|
197 User::Leave(KErrNone); |
|
198 } |
|
199 |
|
200 // No landmark should be found |
|
201 TRAPD(err, iLandmarkParser->LandmarkLC()); |
|
202 if (err != KErrNotFound) |
|
203 { |
|
204 iLog->Log(_L("ERROR: No Landmark should be found")); |
|
205 iErrorsFound++; |
|
206 } |
|
207 |
|
208 // 1 ) Cancel parse function by changing input |
|
209 iOperation = iLandmarkParser->ParseContentL(); |
|
210 |
|
211 // Get the first landmark |
|
212 iOperation->NextStep(status, progress); |
|
213 // Wait for NextStep to complete |
|
214 User::WaitForRequest(status); |
|
215 nr = iLandmarkParser->NumOfParsedLandmarks(); |
|
216 if ((TInt)nr != 1) |
|
217 { |
|
218 iLog->Log(_L("One landmark should be found")); |
|
219 User::Leave(KErrNone); |
|
220 } |
|
221 |
|
222 // Change input |
|
223 iLandmarkParser->SetInputFileL(KKMZFile); |
|
224 |
|
225 nr = iLandmarkParser->NumOfParsedLandmarks(); |
|
226 if ((TInt)nr != 0) |
|
227 { |
|
228 iLog->Log(_L("No landmarks should be found")); |
|
229 User::Leave(KErrNone); |
|
230 } |
|
231 |
|
232 // No landmark should be found |
|
233 TRAP(err, iLandmarkParser->LandmarkLC()); |
|
234 if (err != KErrNotFound) |
|
235 { |
|
236 iLog->Log(_L("ERROR: No Landmark should be found")); |
|
237 iErrorsFound++; |
|
238 } |
|
239 |
|
240 delete iOperation; |
|
241 iOperation = NULL; |
|
242 delete iLandmarkParser; |
|
243 iLandmarkParser = NULL; |
|
244 iLog->Log(_L("DoCancelTestL Done")); |
|
245 } |
|
246 |
|
247 // --------------------------------------------------------- |
|
248 // CPosTp152::PrintParsedDataFromEncoderL |
|
249 // |
|
250 // (other items were commented in a header). |
|
251 // --------------------------------------------------------- |
|
252 // |
|
253 void CPosTp152::PrintParsedDataFromEncoderL( |
|
254 const TDesC& aFile, |
|
255 const TDesC8& aBuffer, |
|
256 TInt aExpectedStatusCode, |
|
257 const TDesC8& aMimeType) |
|
258 { |
|
259 iLog->Log(_L("===== PrintParsedDataFromEncoderL =======")); |
|
260 |
|
261 iLandmarkParser = CPosLandmarkParser::NewL(aMimeType); |
|
262 |
|
263 if (aFile != KNullDesC) |
|
264 { |
|
265 TFileName file( aFile ); |
|
266 iLog->Log(_L("FILE (%S)"), &file ); |
|
267 TraceL(_L("----->Using FILE<-------")); |
|
268 TraceL(file); |
|
269 iLandmarkParser->SetInputFileL(file); |
|
270 } |
|
271 else |
|
272 { |
|
273 iLog->Log(_L("BUFFER (size %d)"), aBuffer.Size() ); |
|
274 TraceL(_L("----->Using BUFFER<-------")); |
|
275 iLandmarkParser->SetInputBuffer(aBuffer); |
|
276 } |
|
277 |
|
278 iOperation = iLandmarkParser->ParseContentL(); |
|
279 TRequestStatus status = KPosLmOperationNotComplete; |
|
280 TReal32 progress; |
|
281 TInt number = 0; |
|
282 |
|
283 RArray<TPosLmItemId> array; |
|
284 CleanupClosePushL(array); |
|
285 |
|
286 while (status == KPosLmOperationNotComplete) |
|
287 { |
|
288 iLog->Log(_L("--- Parsing ---------------------------")); |
|
289 TraceL(_L("------------------------------")); |
|
290 iOperation->NextStep(status, progress); |
|
291 |
|
292 // Wait for NextStep to complete |
|
293 User::WaitForRequest(status); |
|
294 if (status != KPosLmOperationNotComplete && status != KErrNone) |
|
295 { |
|
296 iLog->Log(_L("Parsing Complete")); |
|
297 |
|
298 HBufC* buffer = HBufC::NewLC( 128); |
|
299 TPtr buf = buffer->Des(); |
|
300 buf.Format(_L("\tStatus %d"), status.Int()); |
|
301 iLog->Log(buf); |
|
302 TraceL(buf); |
|
303 |
|
304 CleanupStack::PopAndDestroy( buffer ); |
|
305 buffer = NULL; |
|
306 } |
|
307 else |
|
308 { |
|
309 iLog->Log(_L("Parsing element")); |
|
310 if ( iLandmarkParser->NumOfParsedLandmarks() ) |
|
311 { |
|
312 // Get last parsed landmark |
|
313 CPosLandmark* lm = iLandmarkParser->LandmarkLC(); |
|
314 TPtrC lmName; |
|
315 TPtrC catName; |
|
316 lm->GetLandmarkName(lmName); |
|
317 lm->GetCategoriesL(array); |
|
318 //iLog->Log(lmName); |
|
319 for (TInt i=0;i<array.Count();i++) |
|
320 { |
|
321 CPosLandmarkCategory* category = iLandmarkParser->LandmarkCategoryLC( array[i] ); |
|
322 category->GetCategoryName( catName ); |
|
323 |
|
324 HBufC* buffer = HBufC::NewLC( 128 + catName.Length()); |
|
325 TPtr buf = buffer->Des(); |
|
326 |
|
327 if ( category->GlobalCategory()) |
|
328 { |
|
329 buf.Append(_L("\tGlobal category: ")); |
|
330 } |
|
331 else |
|
332 { |
|
333 buf.Append(_L("\tLocal category: ")); |
|
334 } |
|
335 buf.Append(catName); |
|
336 iLog->Log(buf); |
|
337 TraceL(buf); |
|
338 CleanupStack::PopAndDestroy(buffer); |
|
339 buffer = NULL; |
|
340 CleanupStack::PopAndDestroy(category); |
|
341 } |
|
342 |
|
343 PrintLandmarkFieldsWithDescriptionL(*lm, ETrue); |
|
344 |
|
345 |
|
346 number++; |
|
347 CleanupStack::PopAndDestroy(lm); |
|
348 } |
|
349 } |
|
350 } |
|
351 |
|
352 iLog->Log(_L("--- Parsing end ---------------------------")); |
|
353 TraceL(_L("------------------------------")); |
|
354 CleanupStack::PopAndDestroy(&array); |
|
355 |
|
356 if (status.Int() != aExpectedStatusCode) |
|
357 { |
|
358 HBufC* buffer = HBufC::NewLC( 128 ); |
|
359 TPtr buf = buffer->Des(); |
|
360 |
|
361 buf.Format(_L("\tERROR: Wrong status returned, was %d, should be %d"), status.Int(), aExpectedStatusCode); |
|
362 iLog->Log( buf ); |
|
363 iErrorsFound++; |
|
364 |
|
365 CleanupStack::PopAndDestroy( buffer ); |
|
366 buffer = NULL; |
|
367 } |
|
368 |
|
369 TUint32 nr = iLandmarkParser->NumOfParsedLandmarks(); |
|
370 HBufC* buffer = HBufC::NewLC( 256 ); |
|
371 TPtr buf = buffer->Des(); |
|
372 buf.Format(_L("\tNr of Parsed landmarks %d, should be %d"), nr, number); |
|
373 iLog->Log(buf); |
|
374 TraceL(buf); |
|
375 |
|
376 CleanupStack::PopAndDestroy( buffer ); |
|
377 buffer = NULL; |
|
378 if (nr != (TUint32)number) |
|
379 { |
|
380 iLog->Log(_L("\tERROR: Wrong number of landmarks parsed returned!")); |
|
381 iErrorsFound++; |
|
382 } |
|
383 |
|
384 TPosLmCollectionDataId lmId = iLandmarkParser->FirstCollectionDataId(); |
|
385 |
|
386 iLog->Log(_L("--- CollectionData ---")); |
|
387 TraceL(_L("--- CollectionData ---")); |
|
388 |
|
389 if (lmId != EPosLmCollDataNone) |
|
390 { |
|
391 TPtrC first = iLandmarkParser->CollectionData(lmId); |
|
392 HBufC* buffer = HBufC::NewLC( first.Length() + 256 ); |
|
393 TPtr buf = buffer->Des(); |
|
394 buf.Zero(); |
|
395 buf.Format(_L("\t(1)Collection Id: %d CollectionData: "), lmId); |
|
396 buf.Append(first); |
|
397 iLog->Log(buf); |
|
398 TraceL(buf); |
|
399 CleanupStack::PopAndDestroy( buffer ); |
|
400 buffer = NULL; |
|
401 } |
|
402 else |
|
403 { |
|
404 iLog->Log(_L("\tNo collection data found 1")); |
|
405 } |
|
406 |
|
407 while (lmId != EPosLmCollDataNone) |
|
408 { |
|
409 lmId = iLandmarkParser->NextCollectionDataId(lmId); |
|
410 if (lmId != EPosLmCollDataNone) |
|
411 { |
|
412 TPtrC first = iLandmarkParser->CollectionData(lmId); |
|
413 |
|
414 HBufC* buffer = HBufC::NewLC( first.Length() + 256 ); |
|
415 TPtr buf = buffer->Des(); |
|
416 buf.Zero(); |
|
417 buf.Format(_L("\t(2)Collection Id: %d CollectionData: "), lmId); |
|
418 buf.Append(first); |
|
419 iLog->Log(buf); |
|
420 TraceL(buf); |
|
421 |
|
422 CleanupStack::PopAndDestroy( buffer ); |
|
423 buffer = NULL; |
|
424 } |
|
425 else |
|
426 { |
|
427 iLog->Log(_L("\tNo collection data found 2")); |
|
428 } |
|
429 } |
|
430 |
|
431 iLog->Log(_L("--- CollectionData ---")); |
|
432 TraceL(_L("--- CollectionData ---")); |
|
433 |
|
434 delete iOperation; |
|
435 iOperation = NULL; |
|
436 delete iLandmarkParser; |
|
437 iLandmarkParser = NULL; |
|
438 iLog->Log(_L("====== PrintParsedDataFromEncoderL Done ========\n")); |
|
439 } |
|
440 |
|
441 |
|
442 // --------------------------------------------------------- |
|
443 // CPosTp152::PrintLandmarkFieldsWithDescriptionL |
|
444 // |
|
445 // (other items were commented in a header). |
|
446 // --------------------------------------------------------- |
|
447 // |
|
448 void CPosTp152::PrintLandmarkFieldsWithDescriptionL(const CPosLandmark& aLandmark, TBool aTraceFlag) |
|
449 { |
|
450 iLog->Log(_L("Parsing Description ... \n")); |
|
451 TPositionFieldId sourceFieldId = aLandmark.FirstPositionFieldId(); |
|
452 TLocality loc; |
|
453 |
|
454 TInt err; |
|
455 TPtrC landmarkName; |
|
456 TPtrC landmarkDescription; |
|
457 err = aLandmark.GetLandmarkName(landmarkName); |
|
458 if (err == KErrNone) |
|
459 { |
|
460 HBufC* buffer = HBufC::NewLC( landmarkName.Length() + 256 ); |
|
461 TPtr buf = buffer->Des(); |
|
462 buf.Append(_L("\tLandmark Name: ")); |
|
463 buf.Append(landmarkName); |
|
464 iLog->Log(buf); |
|
465 if( aTraceFlag ) |
|
466 { |
|
467 TraceL( buf ); |
|
468 } |
|
469 |
|
470 CleanupStack::PopAndDestroy( buffer ); |
|
471 buffer = NULL; |
|
472 } |
|
473 |
|
474 err = aLandmark.GetPosition(loc); |
|
475 if (err == KErrNone) |
|
476 { |
|
477 HBufC* buffer = HBufC::NewLC( 1024 ); |
|
478 TPtr buf = buffer->Des(); |
|
479 TRealFormat format( 12, KRealFormatFixed ); |
|
480 format.iPoint = TChar('.'); |
|
481 format.iTriLen = KDoNotUseTriads; |
|
482 format.iPlaces = 6; |
|
483 |
|
484 TBuf<20> sLon, sLat, sVacc, sHacc, sAlt, sRad; |
|
485 sLon.Num( loc.Longitude(), format ); |
|
486 sLat.Num( loc.Latitude(), format ); |
|
487 sAlt.Num( loc.Altitude(), format ); |
|
488 sVacc.Num( loc.VerticalAccuracy(), format ); |
|
489 sHacc.Num( loc.HorizontalAccuracy(), format ); |
|
490 buf.Format( |
|
491 _L("\tLM: Long %S Lat %S vertAcc %S horAcc %S alt %S "), |
|
492 &sLon, &sLat, &sVacc, &sHacc, &sAlt); |
|
493 |
|
494 TReal32 sourceR; |
|
495 err = aLandmark.GetCoverageRadius(sourceR); |
|
496 if (err == KErrNone ) |
|
497 { |
|
498 sRad.Num( sourceR, format ); |
|
499 buf.AppendFormat(_L("srcRadius %S"), &sRad); |
|
500 } |
|
501 iLog->Log(buf); |
|
502 if (aTraceFlag) TraceL(buf); |
|
503 CleanupStack::PopAndDestroy( buffer ); |
|
504 buffer = NULL; |
|
505 } |
|
506 |
|
507 //Get landmark description |
|
508 err = aLandmark.GetLandmarkDescription(landmarkDescription); |
|
509 if (err == KErrNone) |
|
510 { |
|
511 HBufC* buffer = HBufC::NewLC( landmarkDescription.Length() + 256 ); |
|
512 TPtr buf = buffer->Des(); |
|
513 buf.Format(_L("\tLandmark Description: ")); |
|
514 buf.Append(landmarkDescription); |
|
515 iLog->Log(buf); |
|
516 if ( aTraceFlag ) |
|
517 { |
|
518 TraceL( buf ); |
|
519 } |
|
520 |
|
521 CleanupStack::PopAndDestroy( buffer ); |
|
522 buffer = NULL; |
|
523 } |
|
524 |
|
525 |
|
526 while (sourceFieldId != EPositionFieldNone) |
|
527 { |
|
528 TPtrC sourceValue; |
|
529 aLandmark.GetPositionField(sourceFieldId, sourceValue); |
|
530 |
|
531 HBufC* buffer = HBufC::NewLC( sourceValue.Length() + 256 ); |
|
532 TPtr buf = buffer->Des(); |
|
533 buf.Format(_L("\tIdField Id: %d Value:"), sourceFieldId); |
|
534 buf.Append(sourceValue); |
|
535 iLog->Log(buf); |
|
536 if ( aTraceFlag ) |
|
537 { |
|
538 TraceL( buf ); |
|
539 } |
|
540 sourceFieldId = aLandmark.NextPositionFieldId(sourceFieldId); |
|
541 CleanupStack::PopAndDestroy( buffer ); |
|
542 } |
|
543 } |
|
544 |
|
545 |
|
546 // --------------------------------------------------------- |
|
547 // CPosTp152::TraceL |
|
548 // |
|
549 // (other items were commented in a header). |
|
550 // --------------------------------------------------------- |
|
551 // |
|
552 void CPosTp152::TraceL(const TDesC& msg) |
|
553 { |
|
554 _LIT8( KEnd, "\r\n" ); |
|
555 |
|
556 RFile file; |
|
557 TInt err = file.Open(iFileSession, KFileTrace, EFileWrite); |
|
558 if (err == KErrNotFound) |
|
559 { |
|
560 file.Create(iFileSession, KFileTrace, EFileWrite); |
|
561 } |
|
562 |
|
563 HBufC8* line8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( msg ); |
|
564 |
|
565 TInt pos( 0 ); |
|
566 file.Seek( ESeekEnd, pos ); |
|
567 file.Write( *line8 ); |
|
568 file.Write( KEnd ); |
|
569 file.Close(); |
|
570 |
|
571 delete line8; |
|
572 } |
|
573 |
|
574 // End of File |