|
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_CPosTp155.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\\LandmarksTP155Trace.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_LandmarksTP155Trace.txt"); |
|
43 |
|
44 _LIT(KKMZFile, "c:\\system\\test\\TestData\\Tp155KMZFile.kmz"); |
|
45 |
|
46 |
|
47 // Maxmimum size for each line in trace file |
|
48 const TInt KBufSize = 5000; |
|
49 |
|
50 // ================= MEMBER FUNCTIONS ======================= |
|
51 // --------------------------------------------------------- |
|
52 // CPosTp155::CloseTest |
|
53 // |
|
54 // (other items were commented in a header). |
|
55 // --------------------------------------------------------- |
|
56 // |
|
57 void CPosTp155::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 // CPosTp155::StartL |
|
83 // |
|
84 // (other items were commented in a header). |
|
85 // --------------------------------------------------------- |
|
86 // |
|
87 void CPosTp155::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 Tp155KMZFile.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 CleanupStack::PopAndDestroy(linebuffer); |
|
150 CleanupStack::PopAndDestroy(correctLinebuffer); |
|
151 CleanupStack::PopAndDestroy(&file); |
|
152 CleanupStack::PopAndDestroy(&correctFile); |
|
153 |
|
154 // EOF for trace file was reach before EOF in the correct file |
|
155 if (done) |
|
156 { |
|
157 iLog->Log(_L("ERROR: EOF for Trace file was reached to early")); |
|
158 iErrorsFound++; |
|
159 } |
|
160 |
|
161 |
|
162 DoCancelTestL(); |
|
163 |
|
164 if (iErrorsFound != KErrNone) |
|
165 { |
|
166 iLog->Log(_L("Errors found in TP155")); |
|
167 User::Leave(-1); |
|
168 } |
|
169 } |
|
170 |
|
171 // --------------------------------------------------------- |
|
172 // CPosTp155::DoCancelTestL |
|
173 // |
|
174 // (other items were commented in a header). |
|
175 // --------------------------------------------------------- |
|
176 // |
|
177 void CPosTp155::DoCancelTestL() |
|
178 { |
|
179 iLog->Log(_L("DoCancelTestL")); |
|
180 iLandmarkParser = CPosLandmarkParser::NewL(KKmzMimeType); |
|
181 iLandmarkParser->SetInputFileL(KKMZFile); |
|
182 |
|
183 iOperation = iLandmarkParser->ParseContentL(); |
|
184 |
|
185 TRequestStatus status = KPosLmOperationNotComplete; |
|
186 TReal32 progress; |
|
187 |
|
188 // 1 ) Cancel parse function by deleting iOperation |
|
189 delete iOperation; |
|
190 iOperation = NULL; |
|
191 |
|
192 TUint32 nr = iLandmarkParser->NumOfParsedLandmarks(); |
|
193 if ((TInt)nr != 0) |
|
194 { |
|
195 iLog->Log(_L("No landmarks should be found")); |
|
196 User::Leave(KErrNone); |
|
197 } |
|
198 |
|
199 // No landmark should be found |
|
200 TRAPD(err, iLandmarkParser->LandmarkLC()); |
|
201 if (err != KErrNotFound) |
|
202 { |
|
203 iLog->Log(_L("ERROR: No Landmark should be found")); |
|
204 iErrorsFound++; |
|
205 } |
|
206 |
|
207 // 1 ) Cancel parse function by changing input |
|
208 iOperation = iLandmarkParser->ParseContentL(); |
|
209 |
|
210 // Get the first landmark |
|
211 iOperation->NextStep(status, progress); |
|
212 // Wait for NextStep to complete |
|
213 User::WaitForRequest(status); |
|
214 nr = iLandmarkParser->NumOfParsedLandmarks(); |
|
215 if ((TInt)nr != 1) |
|
216 { |
|
217 iLog->Log(_L("One landmark should be found")); |
|
218 User::Leave(KErrNone); |
|
219 } |
|
220 |
|
221 // Change input |
|
222 iLandmarkParser->SetInputFileL(KKMZFile); |
|
223 |
|
224 nr = iLandmarkParser->NumOfParsedLandmarks(); |
|
225 if ((TInt)nr != 0) |
|
226 { |
|
227 iLog->Log(_L("No landmarks should be found")); |
|
228 User::Leave(KErrNone); |
|
229 } |
|
230 |
|
231 // No landmark should be found |
|
232 TRAP(err, iLandmarkParser->LandmarkLC()); |
|
233 if (err != KErrNotFound) |
|
234 { |
|
235 iLog->Log(_L("ERROR: No Landmark should be found")); |
|
236 iErrorsFound++; |
|
237 } |
|
238 |
|
239 delete iOperation; |
|
240 iOperation = NULL; |
|
241 delete iLandmarkParser; |
|
242 iLandmarkParser = NULL; |
|
243 iLog->Log(_L("DoCancelTestL Done")); |
|
244 } |
|
245 |
|
246 // --------------------------------------------------------- |
|
247 // CPosTp155::PrintParsedDataFromEncoderL |
|
248 // |
|
249 // (other items were commented in a header). |
|
250 // --------------------------------------------------------- |
|
251 // |
|
252 void CPosTp155::PrintParsedDataFromEncoderL( |
|
253 const TDesC& aFile, |
|
254 const TDesC8& aBuffer, |
|
255 TInt aExpectedStatusCode, |
|
256 const TDesC8& aMimeType) |
|
257 { |
|
258 iLog->Log(_L("===== PrintParsedDataFromEncoderL =======")); |
|
259 |
|
260 iLandmarkParser = CPosLandmarkParser::NewL(aMimeType); |
|
261 |
|
262 if (aFile != KNullDesC) |
|
263 { |
|
264 TFileName file( aFile ); |
|
265 iLog->Log(_L("FILE (%S)"), &file ); |
|
266 TraceL(_L("----->Using FILE<-------")); |
|
267 TraceL(file); |
|
268 iLandmarkParser->SetInputFileL(file); |
|
269 } |
|
270 else |
|
271 { |
|
272 iLog->Log(_L("BUFFER (size %d)"), aBuffer.Size() ); |
|
273 TraceL(_L("----->Using BUFFER<-------")); |
|
274 iLandmarkParser->SetInputBuffer(aBuffer); |
|
275 } |
|
276 |
|
277 iOperation = iLandmarkParser->ParseContentL(); |
|
278 TRequestStatus status = KPosLmOperationNotComplete; |
|
279 TReal32 progress; |
|
280 TInt number = 0; |
|
281 |
|
282 RArray<TPosLmItemId> array; |
|
283 CleanupClosePushL(array); |
|
284 |
|
285 while (status == KPosLmOperationNotComplete) |
|
286 { |
|
287 iLog->Log(_L("--- Parsing ---------------------------")); |
|
288 TraceL(_L("------------------------------")); |
|
289 iOperation->NextStep(status, progress); |
|
290 |
|
291 // Wait for NextStep to complete |
|
292 User::WaitForRequest(status); |
|
293 if (status != KPosLmOperationNotComplete && status != KErrNone) |
|
294 { |
|
295 iLog->Log(_L("Parsing Complete")); |
|
296 |
|
297 HBufC* buffer = HBufC::NewLC( 128); |
|
298 TPtr buf = buffer->Des(); |
|
299 buf.Format(_L("\tStatus %d"), status.Int()); |
|
300 iLog->Log(buf); |
|
301 TraceL(buf); |
|
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 buf.Append(catName); |
|
334 iLog->Log(buf); |
|
335 TraceL(buf); |
|
336 CleanupStack::PopAndDestroy(category); |
|
337 } |
|
338 |
|
339 PrintLandmarkFieldsWithDescriptionL(*lm, ETrue); |
|
340 |
|
341 |
|
342 number++; |
|
343 CleanupStack::PopAndDestroy(lm); |
|
344 } |
|
345 } |
|
346 } |
|
347 |
|
348 iLog->Log(_L("--- Parsing end ---------------------------")); |
|
349 TraceL(_L("------------------------------")); |
|
350 CleanupStack::PopAndDestroy(&array); |
|
351 |
|
352 if (status.Int() != aExpectedStatusCode) |
|
353 { |
|
354 HBufC* buffer = HBufC::NewLC( 128 ); |
|
355 TPtr buf = buffer->Des(); |
|
356 |
|
357 buf.Format(_L("\tERROR: Wrong status returned, was %d, should be %d"), status.Int(), aExpectedStatusCode); |
|
358 iLog->Log( buf ); |
|
359 iErrorsFound++; |
|
360 |
|
361 CleanupStack::PopAndDestroy( buffer ); |
|
362 buffer = NULL; |
|
363 } |
|
364 |
|
365 TUint32 nr = iLandmarkParser->NumOfParsedLandmarks(); |
|
366 HBufC* buffer = HBufC::NewLC( 256 ); |
|
367 TPtr buf = buffer->Des(); |
|
368 buf.Format(_L("\tNr of Parsed landmarks %d, should be %d"), nr, number); |
|
369 iLog->Log(buf); |
|
370 TraceL(buf); |
|
371 |
|
372 CleanupStack::PopAndDestroy( buffer ); |
|
373 buffer = NULL; |
|
374 if (nr != (TUint32)number) |
|
375 { |
|
376 iLog->Log(_L("\tERROR: Wrong number of landmarks parsed returned!")); |
|
377 iErrorsFound++; |
|
378 } |
|
379 |
|
380 TPosLmCollectionDataId lmId = iLandmarkParser->FirstCollectionDataId(); |
|
381 |
|
382 iLog->Log(_L("--- CollectionData ---")); |
|
383 TraceL(_L("--- CollectionData ---")); |
|
384 |
|
385 if (lmId != EPosLmCollDataNone) |
|
386 { |
|
387 TPtrC first = iLandmarkParser->CollectionData(lmId); |
|
388 HBufC* buffer = HBufC::NewLC( first.Length() + 256 ); |
|
389 TPtr buf = buffer->Des(); |
|
390 buf.Zero(); |
|
391 buf.Format(_L("\t(1)Collection Id: %d CollectionData: "), lmId); |
|
392 buf.Append(first); |
|
393 iLog->Log(buf); |
|
394 TraceL(buf); |
|
395 CleanupStack::PopAndDestroy( buffer ); |
|
396 buffer = NULL; |
|
397 } |
|
398 else |
|
399 { |
|
400 iLog->Log(_L("\tNo collection data found 1")); |
|
401 } |
|
402 |
|
403 while (lmId != EPosLmCollDataNone) |
|
404 { |
|
405 lmId = iLandmarkParser->NextCollectionDataId(lmId); |
|
406 if (lmId != EPosLmCollDataNone) |
|
407 { |
|
408 TPtrC first = iLandmarkParser->CollectionData(lmId); |
|
409 |
|
410 HBufC* buffer = HBufC::NewLC( first.Length() + 256 ); |
|
411 TPtr buf = buffer->Des(); |
|
412 buf.Zero(); |
|
413 buf.Format(_L("\t(2)Collection Id: %d CollectionData: "), lmId); |
|
414 buf.Append(first); |
|
415 iLog->Log(buf); |
|
416 TraceL(buf); |
|
417 |
|
418 CleanupStack::PopAndDestroy( buffer ); |
|
419 buffer = NULL; |
|
420 } |
|
421 else |
|
422 { |
|
423 iLog->Log(_L("\tNo collection data found 2")); |
|
424 } |
|
425 } |
|
426 |
|
427 iLog->Log(_L("--- CollectionData ---")); |
|
428 TraceL(_L("--- CollectionData ---")); |
|
429 |
|
430 delete iOperation; |
|
431 iOperation = NULL; |
|
432 delete iLandmarkParser; |
|
433 iLandmarkParser = NULL; |
|
434 iLog->Log(_L("====== PrintParsedDataFromEncoderL Done ========\n")); |
|
435 } |
|
436 |
|
437 |
|
438 // --------------------------------------------------------- |
|
439 // CPosTp155::PrintLandmarkFieldsWithDescriptionL |
|
440 // |
|
441 // (other items were commented in a header). |
|
442 // --------------------------------------------------------- |
|
443 // |
|
444 void CPosTp155::PrintLandmarkFieldsWithDescriptionL(const CPosLandmark& aLandmark, TBool aTraceFlag) |
|
445 { |
|
446 iLog->Log(_L("Parsing Description ... \n")); |
|
447 TPositionFieldId sourceFieldId = aLandmark.FirstPositionFieldId(); |
|
448 TLocality loc; |
|
449 |
|
450 |
|
451 TInt err; |
|
452 TPtrC landmarkName; |
|
453 TPtrC landmarkDescription; |
|
454 err = aLandmark.GetLandmarkName(landmarkName); |
|
455 if (err == KErrNone) |
|
456 { |
|
457 HBufC* buffer = HBufC::NewLC( landmarkName.Length() + 256 ); |
|
458 TPtr buf = buffer->Des(); |
|
459 buf.Append(_L("\tLandmark Name: ")); |
|
460 buf.Append(landmarkName); |
|
461 iLog->Log(buf); |
|
462 if( aTraceFlag ) |
|
463 { |
|
464 TraceL( buf ); |
|
465 } |
|
466 |
|
467 CleanupStack::PopAndDestroy( buffer ); |
|
468 buffer = NULL; |
|
469 } |
|
470 |
|
471 err = aLandmark.GetPosition(loc); |
|
472 if (err == KErrNone) |
|
473 { |
|
474 HBufC* buffer = HBufC::NewLC( 1024 ); |
|
475 TPtr buf = buffer->Des(); |
|
476 TRealFormat format( 12, KRealFormatFixed ); |
|
477 format.iPoint = TChar('.'); |
|
478 format.iTriLen = KDoNotUseTriads; |
|
479 format.iPlaces = 6; |
|
480 |
|
481 TBuf<20> sLon, sLat, sVacc, sHacc, sAlt, sRad; |
|
482 sLon.Num( loc.Longitude(), format ); |
|
483 sLat.Num( loc.Latitude(), format ); |
|
484 sAlt.Num( loc.Altitude(), format ); |
|
485 sVacc.Num( loc.VerticalAccuracy(), format ); |
|
486 sHacc.Num( loc.HorizontalAccuracy(), format ); |
|
487 buf.Format( |
|
488 _L("\tLM: Long %S Lat %S vertAcc %S horAcc %S alt %S "), |
|
489 &sLon, &sLat, &sVacc, &sHacc, &sAlt); |
|
490 |
|
491 TReal32 sourceR; |
|
492 err = aLandmark.GetCoverageRadius(sourceR); |
|
493 if (err == KErrNone ) |
|
494 { |
|
495 sRad.Num( sourceR, format ); |
|
496 buf.AppendFormat(_L("srcRadius %S"), &sRad); |
|
497 } |
|
498 iLog->Log(buf); |
|
499 if (aTraceFlag) TraceL(buf); |
|
500 CleanupStack::PopAndDestroy( buffer ); |
|
501 buffer = NULL; |
|
502 } |
|
503 |
|
504 //Get landmark description |
|
505 err = aLandmark.GetLandmarkDescription(landmarkDescription); |
|
506 if (err == KErrNone) |
|
507 { |
|
508 HBufC* buffer = HBufC::NewLC( landmarkDescription.Length() + 256 ); |
|
509 TPtr buf = buffer->Des(); |
|
510 buf.Format(_L("\tLandmark Description: ")); |
|
511 buf.Append(landmarkDescription); |
|
512 iLog->Log(buf); |
|
513 if ( aTraceFlag ) |
|
514 { |
|
515 TraceL( buf ); |
|
516 } |
|
517 |
|
518 CleanupStack::PopAndDestroy( buffer ); |
|
519 buffer = NULL; |
|
520 } |
|
521 |
|
522 |
|
523 while (sourceFieldId != EPositionFieldNone) |
|
524 { |
|
525 TPtrC sourceValue; |
|
526 aLandmark.GetPositionField(sourceFieldId, sourceValue); |
|
527 |
|
528 HBufC* buffer = HBufC::NewLC( sourceValue.Length() + 256 ); |
|
529 TPtr buf = buffer->Des(); |
|
530 buf.Format(_L("\tIdField Id: %d Value:"), sourceFieldId); |
|
531 buf.Append(sourceValue); |
|
532 iLog->Log(buf); |
|
533 if ( aTraceFlag ) |
|
534 { |
|
535 TraceL( buf ); |
|
536 } |
|
537 sourceFieldId = aLandmark.NextPositionFieldId(sourceFieldId); |
|
538 |
|
539 CleanupStack::PopAndDestroy( buffer ); |
|
540 } |
|
541 } |
|
542 |
|
543 |
|
544 // --------------------------------------------------------- |
|
545 // CPosTp155::TraceL |
|
546 // |
|
547 // (other items were commented in a header). |
|
548 // --------------------------------------------------------- |
|
549 // |
|
550 void CPosTp155::TraceL(const TDesC& msg) |
|
551 { |
|
552 _LIT8( KEnd, "\r\n" ); |
|
553 |
|
554 RFile file; |
|
555 TInt err = file.Open(iFileSession, KFileTrace, EFileWrite); |
|
556 if (err == KErrNotFound) |
|
557 { |
|
558 file.Create(iFileSession, KFileTrace, EFileWrite); |
|
559 } |
|
560 |
|
561 HBufC8* line8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( msg ); |
|
562 |
|
563 TInt pos( 0 ); |
|
564 file.Seek( ESeekEnd, pos ); |
|
565 file.Write( *line8 ); |
|
566 file.Write( KEnd ); |
|
567 file.Close(); |
|
568 |
|
569 delete line8; |
|
570 } |
|
571 |
|
572 // End of File |