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