|
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_CPosTp149.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\\LandmarksTP149Trace.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_LandmarksTP149Trace.txt"); |
|
42 |
|
43 _LIT(KKMZFile, "c:\\system\\test\\TestData\\Tp149KMZFile.kmz"); |
|
44 |
|
45 |
|
46 // Maxmimum size for each line in trace file |
|
47 const TInt KBufSize = 5000; |
|
48 |
|
49 // ================= MEMBER FUNCTIONS ======================= |
|
50 // --------------------------------------------------------- |
|
51 // CPosTp149::CloseTest |
|
52 // |
|
53 // (other items were commented in a header). |
|
54 // --------------------------------------------------------- |
|
55 // |
|
56 void CPosTp149::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 iLog->Log(_L("CloseTest Done")); |
|
78 } |
|
79 |
|
80 // --------------------------------------------------------- |
|
81 // CPosTp149::StartL |
|
82 // |
|
83 // (other items were commented in a header). |
|
84 // --------------------------------------------------------- |
|
85 // |
|
86 void CPosTp149::StartL() |
|
87 { |
|
88 BaflUtils::EnsurePathExistsL( iFileSession, KKMZFile ); |
|
89 |
|
90 |
|
91 // Delete the trace file |
|
92 DeleteFileL(KFileTrace); |
|
93 |
|
94 |
|
95 HBufC8* emptyBuffer=NULL; |
|
96 |
|
97 iLog->Log(_L("Test with Tp149KMZFile.kmz")); |
|
98 PrintParsedDataFromEncoderL(KKMZFile, *emptyBuffer, KErrNone, KKmzMimeType ); |
|
99 |
|
100 |
|
101 // Now compare tha trace file against the correct one |
|
102 RFile correctFile; |
|
103 RFile file; |
|
104 |
|
105 iLog->Log(_L(">>>>>>>Comparing files<<<<<")); |
|
106 |
|
107 TFileName filename; |
|
108 CreateCorrectXmlFileL( KCorrectFile, filename ); |
|
109 |
|
110 User::LeaveIfError(correctFile.Open(iFileSession, filename, EFileRead)); |
|
111 CleanupClosePushL(correctFile); |
|
112 User::LeaveIfError(file.Open(iFileSession, KFileTrace, EFileRead)); |
|
113 CleanupClosePushL(file); |
|
114 |
|
115 HBufC* correctLinebuffer = HBufC::NewLC( KBufSize ); |
|
116 TPtr correctLine = correctLinebuffer->Des(); |
|
117 HBufC* linebuffer = HBufC::NewLC( KBufSize ); |
|
118 TPtr line = linebuffer->Des(); |
|
119 |
|
120 TInt err = KErrNone; |
|
121 TBool done = EFalse; |
|
122 TInt lineNr = 0; |
|
123 |
|
124 while (ReadLn(correctFile, correctLine) != KErrEof && !done) |
|
125 { |
|
126 lineNr++; |
|
127 err = ReadLn(file, line); |
|
128 if ( err == KErrEof ) |
|
129 { |
|
130 done = ETrue; |
|
131 } |
|
132 correctLine.Trim(); |
|
133 line.Trim(); |
|
134 if (correctLine.Compare(line) != KErrNone) |
|
135 { |
|
136 HBufC* buf = HBufC::NewLC( 128 ); |
|
137 TPtr buffer = buf->Des(); |
|
138 |
|
139 buffer.Format(_L("ERROR in TraceFile on line %d: "), lineNr); |
|
140 |
|
141 iLog->Log( buffer ); |
|
142 iLog->Log( correctLine ); |
|
143 iLog->Log( line ); |
|
144 iErrorsFound++; |
|
145 CleanupStack::PopAndDestroy( buf ); |
|
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 TP149")); |
|
166 User::Leave(-1); |
|
167 } |
|
168 } |
|
169 |
|
170 // --------------------------------------------------------- |
|
171 // CPosTp149::DoCancelTestL |
|
172 // |
|
173 // (other items were commented in a header). |
|
174 // --------------------------------------------------------- |
|
175 // |
|
176 void CPosTp149::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 // CPosTp149::PrintParsedDataFromEncoderL |
|
247 // |
|
248 // (other items were commented in a header). |
|
249 // --------------------------------------------------------- |
|
250 // |
|
251 void CPosTp149::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 HBufC* buffer = HBufC::NewLC( 128); |
|
295 TPtr buf = buffer->Des(); |
|
296 buf.Format(_L("\tStatus %d"), status.Int()); |
|
297 iLog->Log(buf); |
|
298 TraceL(buf); |
|
299 CleanupStack::PopAndDestroy( buffer ); |
|
300 buffer = NULL; |
|
301 } |
|
302 else |
|
303 { |
|
304 iLog->Log(_L("Parsing element")); |
|
305 if ( iLandmarkParser->NumOfParsedLandmarks() ) |
|
306 { |
|
307 // Get last parsed landmark |
|
308 CPosLandmark* lm = iLandmarkParser->LandmarkLC(); |
|
309 TPtrC lmName; |
|
310 TPtrC catName; |
|
311 lm->GetLandmarkName(lmName); |
|
312 lm->GetCategoriesL(array); |
|
313 //iLog->Log(lmName); |
|
314 for (TInt i=0;i<array.Count();i++) |
|
315 { |
|
316 CPosLandmarkCategory* category = iLandmarkParser->LandmarkCategoryLC( array[i] ); |
|
317 category->GetCategoryName( catName ); |
|
318 |
|
319 HBufC* buffer = HBufC::NewLC( 128 + catName.Length()); |
|
320 TPtr buf = buffer->Des(); |
|
321 |
|
322 if ( category->GlobalCategory()) |
|
323 { |
|
324 buf.Append(_L("\tGlobal category: ")); |
|
325 } |
|
326 else |
|
327 { |
|
328 buf.Append(_L("\tLocal category: ")); |
|
329 } |
|
330 buf.Append(catName); |
|
331 iLog->Log(buf); |
|
332 TraceL(buf); |
|
333 CleanupStack::PopAndDestroy( buffer ); |
|
334 buffer = NULL; |
|
335 CleanupStack::PopAndDestroy(category); |
|
336 } |
|
337 |
|
338 PrintLandmarkFieldsWithDescriptionL(*lm, ETrue); |
|
339 |
|
340 |
|
341 |
|
342 |
|
343 number++; |
|
344 CleanupStack::PopAndDestroy(lm); |
|
345 } |
|
346 } |
|
347 } |
|
348 |
|
349 iLog->Log(_L("--- Parsing end ---------------------------")); |
|
350 TraceL(_L("------------------------------")); |
|
351 CleanupStack::PopAndDestroy(&array); |
|
352 |
|
353 if (status.Int() != aExpectedStatusCode) |
|
354 { |
|
355 HBufC* buffer = HBufC::NewLC( 128 ); |
|
356 TPtr buf = buffer->Des(); |
|
357 |
|
358 buf.Format(_L("\tERROR: Wrong status returned, was %d, should be %d"), status.Int(), aExpectedStatusCode); |
|
359 iLog->Log( buf ); |
|
360 iErrorsFound++; |
|
361 |
|
362 CleanupStack::PopAndDestroy( buffer ); |
|
363 buffer = NULL; |
|
364 } |
|
365 |
|
366 |
|
367 TUint32 nr = iLandmarkParser->NumOfParsedLandmarks(); |
|
368 HBufC* buffer = HBufC::NewLC( 256 ); |
|
369 TPtr buf = buffer->Des(); |
|
370 buf.Format(_L("\tNr of Parsed landmarks %d, should be %d"), nr, number); |
|
371 iLog->Log(buf); |
|
372 TraceL(buf); |
|
373 |
|
374 CleanupStack::PopAndDestroy( buffer ); |
|
375 buffer = NULL; |
|
376 |
|
377 if (nr != (TUint32)number) |
|
378 { |
|
379 iLog->Log(_L("\tERROR: Wrong number of landmarks parsed returned!")); |
|
380 iErrorsFound++; |
|
381 } |
|
382 |
|
383 TPosLmCollectionDataId lmId = iLandmarkParser->FirstCollectionDataId(); |
|
384 |
|
385 iLog->Log(_L("--- CollectionData ---")); |
|
386 TraceL(_L("--- CollectionData ---")); |
|
387 |
|
388 if (lmId != EPosLmCollDataNone) |
|
389 { |
|
390 TPtrC first = iLandmarkParser->CollectionData(lmId); |
|
391 HBufC* buffer = HBufC::NewLC( first.Length() + 256 ); |
|
392 TPtr buf = buffer->Des(); |
|
393 buf.Zero(); |
|
394 buf.Format(_L("\t(1)Collection Id: %d CollectionData: "), lmId); |
|
395 buf.Append(first); |
|
396 iLog->Log(buf); |
|
397 TraceL(buf); |
|
398 CleanupStack::PopAndDestroy( buffer ); |
|
399 buffer = NULL; |
|
400 } |
|
401 else |
|
402 { |
|
403 iLog->Log(_L("\tNo collection data found 1")); |
|
404 } |
|
405 |
|
406 while (lmId != EPosLmCollDataNone) |
|
407 { |
|
408 lmId = iLandmarkParser->NextCollectionDataId(lmId); |
|
409 if (lmId != EPosLmCollDataNone) |
|
410 { |
|
411 TPtrC first = iLandmarkParser->CollectionData(lmId); |
|
412 HBufC* buffer = HBufC::NewLC( first.Length() + 256 ); |
|
413 TPtr buf = buffer->Des(); |
|
414 buf.Zero(); |
|
415 buf.Format(_L("\t(2)Collection Id: %d CollectionData: "), lmId); |
|
416 buf.Append(first); |
|
417 iLog->Log(buf); |
|
418 TraceL(buf); |
|
419 CleanupStack::PopAndDestroy( buffer ); |
|
420 buffer = NULL; |
|
421 } |
|
422 else |
|
423 { |
|
424 iLog->Log(_L("\tNo collection data found 2")); |
|
425 } |
|
426 } |
|
427 |
|
428 iLog->Log(_L("--- CollectionData ---")); |
|
429 TraceL(_L("--- CollectionData ---")); |
|
430 |
|
431 delete iOperation; |
|
432 iOperation = NULL; |
|
433 delete iLandmarkParser; |
|
434 iLandmarkParser = NULL; |
|
435 iLog->Log(_L("====== PrintParsedDataFromEncoderL Done ========\n")); |
|
436 } |
|
437 |
|
438 |
|
439 // --------------------------------------------------------- |
|
440 // CPosTp149::PrintLandmarkFieldsWithDescriptionL |
|
441 // |
|
442 // (other items were commented in a header). |
|
443 // --------------------------------------------------------- |
|
444 // |
|
445 void CPosTp149::PrintLandmarkFieldsWithDescriptionL(const CPosLandmark& aLandmark, TBool aTraceFlag) |
|
446 { |
|
447 iLog->Log(_L("Parsing Description ... \n")); |
|
448 TPositionFieldId sourceFieldId = aLandmark.FirstPositionFieldId(); |
|
449 TLocality loc; |
|
450 |
|
451 TInt err; |
|
452 TPtrC landmarkName; |
|
453 TPtrC landmarkDescription; |
|
454 err = aLandmark.GetLandmarkName(landmarkName); |
|
455 if (err == KErrNone) |
|
456 { |
|
457 |
|
458 HBufC* buffer = HBufC::NewLC( landmarkName.Length() + 256 ); |
|
459 TPtr buf = buffer->Des(); |
|
460 buf.Append(_L("\tLandmark Name: ")); |
|
461 buf.Append(landmarkName); |
|
462 iLog->Log(buf); |
|
463 if( aTraceFlag ) |
|
464 { |
|
465 TraceL( buf ); |
|
466 } |
|
467 |
|
468 CleanupStack::PopAndDestroy( buffer ); |
|
469 buffer = NULL; |
|
470 } |
|
471 |
|
472 err = aLandmark.GetPosition(loc); |
|
473 if (err == KErrNone) |
|
474 { |
|
475 HBufC* buffer = HBufC::NewLC( 1024 ); |
|
476 TPtr buf = buffer->Des(); |
|
477 TRealFormat format( 12, KRealFormatFixed ); |
|
478 format.iPoint = TChar('.'); |
|
479 format.iTriLen = KDoNotUseTriads; |
|
480 format.iPlaces = 6; |
|
481 |
|
482 TBuf<20> sLon, sLat, sVacc, sHacc, sAlt, sRad; |
|
483 sLon.Num( loc.Longitude(), format ); |
|
484 sLat.Num( loc.Latitude(), format ); |
|
485 sAlt.Num( loc.Altitude(), format ); |
|
486 sVacc.Num( loc.VerticalAccuracy(), format ); |
|
487 sHacc.Num( loc.HorizontalAccuracy(), format ); |
|
488 buf.Format( |
|
489 _L("\tLM: Long %S Lat %S vertAcc %S horAcc %S alt %S "), |
|
490 &sLon, &sLat, &sVacc, &sHacc, &sAlt); |
|
491 |
|
492 TReal32 sourceR; |
|
493 err = aLandmark.GetCoverageRadius(sourceR); |
|
494 if (err == KErrNone ) |
|
495 { |
|
496 sRad.Num( sourceR, format ); |
|
497 buf.AppendFormat(_L("srcRadius %S"), &sRad); |
|
498 } |
|
499 iLog->Log(buf); |
|
500 if (aTraceFlag) TraceL(buf); |
|
501 CleanupStack::PopAndDestroy( buffer ); |
|
502 buffer = NULL; |
|
503 } |
|
504 |
|
505 //Get landmark description |
|
506 err = aLandmark.GetLandmarkDescription(landmarkDescription); |
|
507 if (err == KErrNone) |
|
508 { |
|
509 HBufC* buffer = HBufC::NewLC( landmarkDescription.Length() + 256 ); |
|
510 TPtr buf = buffer->Des(); |
|
511 buf.Format(_L("\tLandmark Description: ")); |
|
512 buf.Append(landmarkDescription); |
|
513 iLog->Log(buf); |
|
514 if ( aTraceFlag ) |
|
515 { |
|
516 TraceL( buf ); |
|
517 } |
|
518 |
|
519 CleanupStack::PopAndDestroy( buffer ); |
|
520 buffer = NULL; |
|
521 } |
|
522 |
|
523 |
|
524 while (sourceFieldId != EPositionFieldNone) |
|
525 { |
|
526 TPtrC sourceValue; |
|
527 aLandmark.GetPositionField(sourceFieldId, sourceValue); |
|
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 |
|
546 // --------------------------------------------------------- |
|
547 // CPosTp149::TraceL |
|
548 // |
|
549 // (other items were commented in a header). |
|
550 // --------------------------------------------------------- |
|
551 // |
|
552 void CPosTp149::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 |