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