|
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_CPosTp156.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\\LandmarksTP156Trace.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_LandmarksTP156Trace.txt"); |
|
43 |
|
44 _LIT(KKMZFile, "c:\\system\\test\\TestData\\Tp156KMZFile.kmz"); |
|
45 |
|
46 |
|
47 // Maxmimum size for each line in trace file |
|
48 const TInt KBufSize = 5000; |
|
49 |
|
50 // ================= MEMBER FUNCTIONS ======================= |
|
51 // --------------------------------------------------------- |
|
52 // CPosTp156::CloseTest |
|
53 // |
|
54 // (other items were commented in a header). |
|
55 // --------------------------------------------------------- |
|
56 // |
|
57 void CPosTp156::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 // CPosTp156::StartL |
|
83 // |
|
84 // (other items were commented in a header). |
|
85 // --------------------------------------------------------- |
|
86 // |
|
87 void CPosTp156::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 Tp156KMZFile.kmz")); |
|
99 PrintParsedDataFromEncoderL(KKMZFile, *emptyBuffer, -993, 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 TP156")); |
|
167 User::Leave(-1); |
|
168 } |
|
169 } |
|
170 |
|
171 // --------------------------------------------------------- |
|
172 // CPosTp156::DoCancelTestL |
|
173 // |
|
174 // (other items were commented in a header). |
|
175 // --------------------------------------------------------- |
|
176 // |
|
177 void CPosTp156::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 if(status == KErrNone) |
|
215 { |
|
216 nr = iLandmarkParser->NumOfParsedLandmarks(); |
|
217 if ((TInt)nr != 1) |
|
218 { |
|
219 iLog->Log(_L("One landmark should be found")); |
|
220 iErrorsFound++; |
|
221 } |
|
222 } |
|
223 |
|
224 // Change input |
|
225 iLandmarkParser->SetInputFileL(KKMZFile); |
|
226 |
|
227 nr = iLandmarkParser->NumOfParsedLandmarks(); |
|
228 if ((TInt)nr != 0) |
|
229 { |
|
230 iLog->Log(_L("No landmarks should be found")); |
|
231 User::Leave(KErrNone); |
|
232 } |
|
233 |
|
234 // No landmark should be found |
|
235 TRAP(err, iLandmarkParser->LandmarkLC()); |
|
236 if (err != KErrNotFound) |
|
237 { |
|
238 iLog->Log(_L("ERROR: No Landmark should be found")); |
|
239 iErrorsFound++; |
|
240 } |
|
241 |
|
242 delete iOperation; |
|
243 iOperation = NULL; |
|
244 delete iLandmarkParser; |
|
245 iLandmarkParser = NULL; |
|
246 iLog->Log(_L("DoCancelTestL Done")); |
|
247 } |
|
248 |
|
249 // --------------------------------------------------------- |
|
250 // CPosTp156::PrintParsedDataFromEncoderL |
|
251 // |
|
252 // (other items were commented in a header). |
|
253 // --------------------------------------------------------- |
|
254 // |
|
255 void CPosTp156::PrintParsedDataFromEncoderL( |
|
256 const TDesC& aFile, |
|
257 const TDesC8& aBuffer, |
|
258 TInt aExpectedStatusCode, |
|
259 const TDesC8& aMimeType) |
|
260 { |
|
261 iLog->Log(_L("===== PrintParsedDataFromEncoderL =======")); |
|
262 |
|
263 iLandmarkParser = CPosLandmarkParser::NewL(aMimeType); |
|
264 |
|
265 if (aFile != KNullDesC) |
|
266 { |
|
267 TFileName file( aFile ); |
|
268 iLog->Log(_L("FILE (%S)"), &file ); |
|
269 TraceL(_L("----->Using FILE<-------")); |
|
270 TraceL(file); |
|
271 iLandmarkParser->SetInputFileL(file); |
|
272 } |
|
273 else |
|
274 { |
|
275 iLog->Log(_L("BUFFER (size %d)"), aBuffer.Size() ); |
|
276 TraceL(_L("----->Using BUFFER<-------")); |
|
277 iLandmarkParser->SetInputBuffer(aBuffer); |
|
278 } |
|
279 |
|
280 iOperation = iLandmarkParser->ParseContentL(); |
|
281 TRequestStatus status = KPosLmOperationNotComplete; |
|
282 TReal32 progress; |
|
283 TInt number = 0; |
|
284 |
|
285 RArray<TPosLmItemId> array; |
|
286 CleanupClosePushL(array); |
|
287 |
|
288 while (status == KPosLmOperationNotComplete) |
|
289 { |
|
290 iLog->Log(_L("--- Parsing ---------------------------")); |
|
291 TraceL(_L("------------------------------")); |
|
292 iOperation->NextStep(status, progress); |
|
293 |
|
294 // Wait for NextStep to complete |
|
295 User::WaitForRequest(status); |
|
296 if (status != KPosLmOperationNotComplete && status != KErrNone) |
|
297 { |
|
298 iLog->Log(_L("Parsing Complete")); |
|
299 |
|
300 HBufC* buffer = HBufC::NewLC( 128); |
|
301 TPtr buf = buffer->Des(); |
|
302 |
|
303 buf.Format(_L("\tStatus %d"), status.Int()); |
|
304 iLog->Log(buf); |
|
305 TraceL(buf); |
|
306 |
|
307 CleanupStack::PopAndDestroy( buffer ); |
|
308 buffer = NULL; |
|
309 } |
|
310 else |
|
311 { |
|
312 iLog->Log(_L("Parsing element")); |
|
313 if ( iLandmarkParser->NumOfParsedLandmarks() ) |
|
314 { |
|
315 // Get last parsed landmark |
|
316 CPosLandmark* lm = iLandmarkParser->LandmarkLC(); |
|
317 TPtrC lmName; |
|
318 TPtrC catName; |
|
319 lm->GetLandmarkName(lmName); |
|
320 lm->GetCategoriesL(array); |
|
321 //iLog->Log(lmName); |
|
322 for (TInt i=0;i<array.Count();i++) |
|
323 { |
|
324 CPosLandmarkCategory* category = iLandmarkParser->LandmarkCategoryLC(array[i]); |
|
325 category->GetCategoryName( catName ); |
|
326 |
|
327 HBufC* buffer = HBufC::NewLC( 128 + catName.Length()); |
|
328 TPtr buf = buffer->Des(); |
|
329 |
|
330 if ( category->GlobalCategory()) |
|
331 { |
|
332 buf.Append(_L("\tGlobal category: ")); |
|
333 } |
|
334 else |
|
335 { |
|
336 buf.Append(_L("\tLocal category: ")); |
|
337 } |
|
338 |
|
339 buf.Append( catName ); |
|
340 iLog->Log( buf ); |
|
341 TraceL( buf ); |
|
342 |
|
343 CleanupStack::PopAndDestroy( buffer ); |
|
344 buffer = NULL; |
|
345 CleanupStack::PopAndDestroy(category); |
|
346 } |
|
347 |
|
348 PrintLandmarkFieldsWithDescriptionL(*lm, ETrue); |
|
349 |
|
350 |
|
351 number++; |
|
352 CleanupStack::PopAndDestroy(lm); |
|
353 } |
|
354 } |
|
355 } |
|
356 |
|
357 iLog->Log(_L("--- Parsing end ---------------------------")); |
|
358 TraceL(_L("------------------------------")); |
|
359 CleanupStack::PopAndDestroy(&array); |
|
360 |
|
361 if (status.Int() != aExpectedStatusCode) |
|
362 { |
|
363 HBufC* buffer = HBufC::NewLC( 128 ); |
|
364 TPtr buf = buffer->Des(); |
|
365 |
|
366 buf.Format(_L("\tERROR: Wrong status returned, was %d, should be %d"), status.Int(), aExpectedStatusCode); |
|
367 iLog->Log( buf ); |
|
368 iErrorsFound++; |
|
369 |
|
370 CleanupStack::PopAndDestroy( buffer ); |
|
371 buffer = NULL; |
|
372 } |
|
373 |
|
374 TUint32 nr = iLandmarkParser->NumOfParsedLandmarks(); |
|
375 HBufC* buffer = HBufC::NewLC( 256 ); |
|
376 TPtr buf = buffer->Des(); |
|
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 if (nr != (TUint32)number) |
|
384 { |
|
385 iLog->Log(_L("\tERROR: Wrong number of landmarks parsed returned!")); |
|
386 iErrorsFound++; |
|
387 } |
|
388 |
|
389 TPosLmCollectionDataId lmId = iLandmarkParser->FirstCollectionDataId(); |
|
390 |
|
391 iLog->Log(_L("--- CollectionData ---")); |
|
392 TraceL(_L("--- CollectionData ---")); |
|
393 |
|
394 if (lmId != EPosLmCollDataNone) |
|
395 { |
|
396 TPtrC first = iLandmarkParser->CollectionData(lmId); |
|
397 HBufC* buffer = HBufC::NewLC( first.Length() + 256 ); |
|
398 TPtr buf = buffer->Des(); |
|
399 buf.Zero(); |
|
400 buf.Format(_L("\t(1)Collection Id: %d CollectionData: "), lmId); |
|
401 buf.Append(first); |
|
402 iLog->Log(buf); |
|
403 TraceL(buf); |
|
404 CleanupStack::PopAndDestroy( buffer ); |
|
405 buffer = NULL; |
|
406 } |
|
407 else |
|
408 { |
|
409 iLog->Log(_L("\tNo collection data found 1")); |
|
410 } |
|
411 |
|
412 while (lmId != EPosLmCollDataNone) |
|
413 { |
|
414 lmId = iLandmarkParser->NextCollectionDataId(lmId); |
|
415 if (lmId != EPosLmCollDataNone) |
|
416 { |
|
417 TPtrC first = iLandmarkParser->CollectionData(lmId); |
|
418 |
|
419 HBufC* buffer = HBufC::NewLC( first.Length() + 256 ); |
|
420 TPtr buf = buffer->Des(); |
|
421 buf.Zero(); |
|
422 buf.Format(_L("\t(2)Collection Id: %d CollectionData: "), lmId); |
|
423 buf.Append(first); |
|
424 iLog->Log(buf); |
|
425 TraceL(buf); |
|
426 |
|
427 CleanupStack::PopAndDestroy( buffer ); |
|
428 buffer = NULL; |
|
429 } |
|
430 else |
|
431 { |
|
432 iLog->Log(_L("\tNo collection data found 2")); |
|
433 } |
|
434 } |
|
435 |
|
436 iLog->Log(_L("--- CollectionData ---")); |
|
437 TraceL(_L("--- CollectionData ---")); |
|
438 |
|
439 delete iOperation; |
|
440 iOperation = NULL; |
|
441 delete iLandmarkParser; |
|
442 iLandmarkParser = NULL; |
|
443 iLog->Log(_L("====== PrintParsedDataFromEncoderL Done ========\n")); |
|
444 } |
|
445 |
|
446 |
|
447 // --------------------------------------------------------- |
|
448 // CPosTp156::PrintLandmarkFieldsWithDescriptionL |
|
449 // |
|
450 // (other items were commented in a header). |
|
451 // --------------------------------------------------------- |
|
452 // |
|
453 void CPosTp156::PrintLandmarkFieldsWithDescriptionL(const CPosLandmark& aLandmark, TBool aTraceFlag) |
|
454 { |
|
455 iLog->Log(_L("Parsing Description ... \n")); |
|
456 TPositionFieldId sourceFieldId = aLandmark.FirstPositionFieldId(); |
|
457 TLocality loc; |
|
458 |
|
459 |
|
460 TInt err; |
|
461 TPtrC landmarkName; |
|
462 TPtrC landmarkDescription; |
|
463 err = aLandmark.GetLandmarkName(landmarkName); |
|
464 if (err == KErrNone) |
|
465 { |
|
466 HBufC* buffer = HBufC::NewLC( landmarkName.Length() + 256 ); |
|
467 TPtr buf = buffer->Des(); |
|
468 buf.Append(_L("\tLandmark Name: ")); |
|
469 buf.Append(landmarkName); |
|
470 iLog->Log(buf); |
|
471 if( aTraceFlag ) |
|
472 { |
|
473 TraceL( buf ); |
|
474 } |
|
475 |
|
476 CleanupStack::PopAndDestroy( buffer ); |
|
477 buffer = NULL; |
|
478 } |
|
479 |
|
480 err = aLandmark.GetPosition(loc); |
|
481 if (err == KErrNone) |
|
482 { |
|
483 HBufC* buffer = HBufC::NewLC( 1024 ); |
|
484 TPtr buf = buffer->Des(); |
|
485 TRealFormat format( 12, KRealFormatFixed ); |
|
486 format.iPoint = TChar('.'); |
|
487 format.iTriLen = KDoNotUseTriads; |
|
488 format.iPlaces = 6; |
|
489 |
|
490 TBuf<20> sLon, sLat, sVacc, sHacc, sAlt, sRad; |
|
491 sLon.Num( loc.Longitude(), format ); |
|
492 sLat.Num( loc.Latitude(), format ); |
|
493 sAlt.Num( loc.Altitude(), format ); |
|
494 sVacc.Num( loc.VerticalAccuracy(), format ); |
|
495 sHacc.Num( loc.HorizontalAccuracy(), format ); |
|
496 buf.Format( |
|
497 _L("\tLM: Long %S Lat %S vertAcc %S horAcc %S alt %S "), |
|
498 &sLon, &sLat, &sVacc, &sHacc, &sAlt); |
|
499 |
|
500 TReal32 sourceR; |
|
501 err = aLandmark.GetCoverageRadius(sourceR); |
|
502 if (err == KErrNone ) |
|
503 { |
|
504 sRad.Num( sourceR, format ); |
|
505 buf.AppendFormat(_L("srcRadius %S"), &sRad); |
|
506 } |
|
507 iLog->Log(buf); |
|
508 if (aTraceFlag) TraceL(buf); |
|
509 CleanupStack::PopAndDestroy( buffer ); |
|
510 buffer = NULL; |
|
511 } |
|
512 |
|
513 //Get landmark description |
|
514 err = aLandmark.GetLandmarkDescription(landmarkDescription); |
|
515 if (err == KErrNone) |
|
516 { |
|
517 HBufC* buffer = HBufC::NewLC( landmarkDescription.Length() + 256 ); |
|
518 TPtr buf = buffer->Des(); |
|
519 buf.Format(_L("\tLandmark Description: ")); |
|
520 buf.Append(landmarkDescription); |
|
521 iLog->Log(buf); |
|
522 if ( aTraceFlag ) |
|
523 { |
|
524 TraceL( buf ); |
|
525 } |
|
526 |
|
527 CleanupStack::PopAndDestroy( buffer ); |
|
528 buffer = NULL; |
|
529 } |
|
530 |
|
531 |
|
532 while (sourceFieldId != EPositionFieldNone) |
|
533 { |
|
534 TPtrC sourceValue; |
|
535 aLandmark.GetPositionField(sourceFieldId, sourceValue); |
|
536 HBufC* buffer = HBufC::NewLC( sourceValue.Length() + 256 ); |
|
537 TPtr buf = buffer->Des(); |
|
538 buf.Format(_L("\tIdField Id: %d Value:"), sourceFieldId); |
|
539 buf.Append(sourceValue); |
|
540 iLog->Log(buf); |
|
541 if ( aTraceFlag ) |
|
542 { |
|
543 TraceL( buf ); |
|
544 } |
|
545 sourceFieldId = aLandmark.NextPositionFieldId(sourceFieldId); |
|
546 |
|
547 CleanupStack::PopAndDestroy( buffer ); |
|
548 } |
|
549 } |
|
550 |
|
551 |
|
552 // --------------------------------------------------------- |
|
553 // CPosTp156::TraceL |
|
554 // |
|
555 // (other items were commented in a header). |
|
556 // --------------------------------------------------------- |
|
557 // |
|
558 void CPosTp156::TraceL(const TDesC& msg) |
|
559 { |
|
560 _LIT8( KEnd, "\r\n" ); |
|
561 |
|
562 RFile file; |
|
563 TInt err = file.Open(iFileSession, KFileTrace, EFileWrite); |
|
564 if (err == KErrNotFound) |
|
565 { |
|
566 file.Create(iFileSession, KFileTrace, EFileWrite); |
|
567 } |
|
568 |
|
569 HBufC8* line8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( msg ); |
|
570 |
|
571 TInt pos( 0 ); |
|
572 file.Seek( ESeekEnd, pos ); |
|
573 file.Write( *line8 ); |
|
574 file.Write( KEnd ); |
|
575 file.Close(); |
|
576 |
|
577 delete line8; |
|
578 } |
|
579 |
|
580 // End of File |