|
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_CPosTp159.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\\LandmarksTP159Trace.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_LandmarksTP159Trace.txt"); |
|
43 |
|
44 _LIT(KKMZFile, "c:\\system\\test\\TestData\\Tp159KMZFile.kmz"); |
|
45 |
|
46 |
|
47 // Maxmimum size for each line in trace file |
|
48 const TInt KBufSize = 5000; |
|
49 |
|
50 // ================= MEMBER FUNCTIONS ======================= |
|
51 // --------------------------------------------------------- |
|
52 // CPosTp159::CloseTest |
|
53 // |
|
54 // (other items were commented in a header). |
|
55 // --------------------------------------------------------- |
|
56 // |
|
57 void CPosTp159::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 // CPosTp159::StartL |
|
83 // |
|
84 // (other items were commented in a header). |
|
85 // --------------------------------------------------------- |
|
86 // |
|
87 void CPosTp159::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 Tp159KMZFile.kmz")); |
|
99 PrintParsedDataFromEncoderL(KKMZFile, *emptyBuffer, KErrPosLmUnknownFormat, 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 |
|
163 |
|
164 if (iErrorsFound != KErrNone) |
|
165 { |
|
166 iLog->Log(_L("Errors found in TP159")); |
|
167 User::Leave(-1); |
|
168 } |
|
169 } |
|
170 |
|
171 |
|
172 |
|
173 // --------------------------------------------------------- |
|
174 // CPosTp159::PrintParsedDataFromEncoderL |
|
175 // |
|
176 // (other items were commented in a header). |
|
177 // --------------------------------------------------------- |
|
178 // |
|
179 void CPosTp159::PrintParsedDataFromEncoderL( |
|
180 const TDesC& aFile, |
|
181 const TDesC8& aBuffer, |
|
182 TInt aExpectedStatusCode, |
|
183 const TDesC8& aMimeType) |
|
184 { |
|
185 iLog->Log(_L("===== PrintParsedDataFromEncoderL =======")); |
|
186 |
|
187 iLandmarkParser = CPosLandmarkParser::NewL(aMimeType); |
|
188 |
|
189 |
|
190 TFileName file( aFile ); |
|
191 iLog->Log(_L("FILE (%S)"), &file ); |
|
192 TraceL(_L("----->Using FILE<-------")); |
|
193 TraceL(file); |
|
194 TRAPD(err,iLandmarkParser->SetInputFileL(file)); |
|
195 if(err != KErrPosLmUnknownFormat) |
|
196 { |
|
197 iErrorsFound++; |
|
198 TBuf<100> buffe; |
|
199 buffe.Format(_L("\tERROR: SetInputFile should leave with error code KErrPosLmUnknownFormat (-30352)")); |
|
200 iLog->Log(buffe); |
|
201 |
|
202 } |
|
203 else |
|
204 { |
|
205 |
|
206 TBuf<100> buffe; |
|
207 buffe.Format(_L("\tSetInputFile leaves with error code KErrPosLmUnknownFormat")); |
|
208 iLog->Log(buffe); |
|
209 |
|
210 } |
|
211 |
|
212 |
|
213 delete iLandmarkParser; |
|
214 iLandmarkParser = NULL; |
|
215 iLog->Log(_L("====== PrintParsedDataFromEncoderL Done ========\n")); |
|
216 } |
|
217 |
|
218 |
|
219 |
|
220 |
|
221 // --------------------------------------------------------- |
|
222 // CPosTp159::TraceL |
|
223 // |
|
224 // (other items were commented in a header). |
|
225 // --------------------------------------------------------- |
|
226 // |
|
227 void CPosTp159::TraceL(const TDesC& msg) |
|
228 { |
|
229 _LIT8( KEnd, "\r\n" ); |
|
230 |
|
231 RFile file; |
|
232 TInt err = file.Open(iFileSession, KFileTrace, EFileWrite); |
|
233 if (err == KErrNotFound) |
|
234 { |
|
235 file.Create(iFileSession, KFileTrace, EFileWrite); |
|
236 } |
|
237 |
|
238 HBufC8* line8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( msg ); |
|
239 |
|
240 TInt pos( 0 ); |
|
241 file.Seek( ESeekEnd, pos ); |
|
242 file.Write( *line8 ); |
|
243 file.Write( KEnd ); |
|
244 file.Close(); |
|
245 |
|
246 delete line8; |
|
247 } |
|
248 |
|
249 // End of File |