48
|
1 |
/*
|
|
2 |
* Copyright (c) 2008 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 the License "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 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
// INCLUDE FILES
|
|
20 |
|
|
21 |
#include <zipfile.h>
|
|
22 |
|
|
23 |
#include "CIptvTestVerifyData.h"
|
|
24 |
#include "VCXTestLog.h"
|
|
25 |
|
|
26 |
// EXTERNAL DATA STRUCTURES
|
|
27 |
|
|
28 |
// EXTERNAL FUNCTION PROTOTYPES
|
|
29 |
|
|
30 |
// CONSTANTS
|
|
31 |
|
|
32 |
// MACROS
|
|
33 |
|
|
34 |
// LOCAL CONSTANTS AND MACROS
|
|
35 |
|
|
36 |
// MODULE DATA STRUCTURES
|
|
37 |
|
|
38 |
// LOCAL FUNCTION PROTOTYPES
|
|
39 |
|
|
40 |
// FORWARD DECLARATIONS
|
|
41 |
|
|
42 |
// ============================= LOCAL FUNCTIONS ===============================
|
|
43 |
|
|
44 |
// ============================ MEMBER FUNCTIONS ===============================
|
|
45 |
|
|
46 |
_LIT(KDriveC, "C:\\");
|
|
47 |
_LIT(KLineBreak, "\r\n");
|
|
48 |
|
|
49 |
_LIT(KPathVerifyWrite, "testing\\data\\verifynew\\");
|
|
50 |
_LIT(KVerifyExtension, ".txt");
|
|
51 |
|
|
52 |
// -----------------------------------------------------------------------------
|
|
53 |
// CVerifyFile::NewL
|
|
54 |
// -----------------------------------------------------------------------------
|
|
55 |
//
|
|
56 |
CVerifyFile* CVerifyFile::NewL()
|
|
57 |
{
|
|
58 |
CVerifyFile* self = new (ELeave) CVerifyFile();
|
|
59 |
CleanupStack::PushL(self);
|
|
60 |
self->ConstructL();
|
|
61 |
CleanupStack::Pop(self);
|
|
62 |
return self;
|
|
63 |
}
|
|
64 |
|
|
65 |
// -----------------------------------------------------------------------------
|
|
66 |
// CVerifyFile::ConstructL
|
|
67 |
// -----------------------------------------------------------------------------
|
|
68 |
//
|
|
69 |
void CVerifyFile::ConstructL()
|
|
70 |
{
|
|
71 |
iFs.Connect();
|
|
72 |
iId.Zero();
|
|
73 |
}
|
|
74 |
|
|
75 |
// -----------------------------------------------------------------------------
|
|
76 |
// CVerifyFile::CVerifyFile
|
|
77 |
// -----------------------------------------------------------------------------
|
|
78 |
//
|
|
79 |
CVerifyFile::CVerifyFile()
|
|
80 |
{
|
|
81 |
|
|
82 |
}
|
|
83 |
|
|
84 |
// -----------------------------------------------------------------------------
|
|
85 |
// CVerifyFile::~CVerifyFile
|
|
86 |
// -----------------------------------------------------------------------------
|
|
87 |
//
|
|
88 |
CVerifyFile::~CVerifyFile()
|
|
89 |
{
|
|
90 |
delete iFileName;
|
|
91 |
iFileName = NULL;
|
|
92 |
CloseFileHandles();
|
|
93 |
iFs.Close();
|
|
94 |
}
|
|
95 |
|
|
96 |
// -----------------------------------------------------------------------------
|
|
97 |
// CVerifyFile::CloseFileHandles
|
|
98 |
// -----------------------------------------------------------------------------
|
|
99 |
//
|
|
100 |
void CVerifyFile::CloseFileHandles()
|
|
101 |
{
|
|
102 |
VCXLOGLO1(">>>CVerifyFile::CloseFileHandles");
|
|
103 |
if(iFileOpen)
|
|
104 |
{
|
|
105 |
iFile.Close();
|
|
106 |
iFileStream.Close();
|
|
107 |
}
|
|
108 |
iFileOpen = EFalse;
|
|
109 |
VCXLOGLO1("<<<CVerifyFile::CloseFileHandles");
|
|
110 |
}
|
|
111 |
|
|
112 |
// -----------------------------------------------------------------------------
|
|
113 |
// CVerifyFile::ResolveFileName
|
|
114 |
// -----------------------------------------------------------------------------
|
|
115 |
//
|
|
116 |
void CVerifyFile::ResolveFileName()
|
|
117 |
{
|
|
118 |
if(iFileName == NULL)
|
|
119 |
{
|
|
120 |
iFileName = HBufC::NewL(256);
|
|
121 |
}
|
|
122 |
else
|
|
123 |
{
|
|
124 |
return;
|
|
125 |
}
|
|
126 |
|
|
127 |
VCXLOGLO1(">>>CVerifyFile::ResolveFileName");
|
|
128 |
|
|
129 |
iFileName->Des().Zero();
|
|
130 |
|
|
131 |
iFileName->Des().Append(KDriveC);
|
|
132 |
|
|
133 |
iFileName->Des().Append(KPathVerifyWrite);
|
|
134 |
|
|
135 |
BaflUtils::EnsurePathExistsL(iFs, iFileName->Des());
|
|
136 |
|
|
137 |
iFileName->Des().Append(iId);
|
|
138 |
iFileName->Des().Append(KVerifyExtension);
|
|
139 |
|
|
140 |
VCXLOGLO1("<<CVerifyFile::ResolveFileName");
|
|
141 |
}
|
|
142 |
|
|
143 |
// -----------------------------------------------------------------------------
|
|
144 |
// CVerifyFile::OpenStream
|
|
145 |
// -----------------------------------------------------------------------------
|
|
146 |
//
|
|
147 |
void CVerifyFile::OpenStream()
|
|
148 |
{
|
|
149 |
if(iFileOpen)
|
|
150 |
{
|
|
151 |
return;
|
|
152 |
}
|
|
153 |
|
|
154 |
VCXLOGLO1(">>>CVerifyFile::OpenStream");
|
|
155 |
|
|
156 |
ResolveFileName();
|
|
157 |
|
|
158 |
// create the stream
|
|
159 |
|
|
160 |
TInt filePos = 0;
|
|
161 |
if(BaflUtils::FileExists(iFs, iFileName->Des()))
|
|
162 |
{
|
|
163 |
TInt result = iFile.Open(iFs, iFileName->Des(), EFileShareAny | EFileWrite | EFileStreamText);
|
|
164 |
if(result != KErrNone)
|
|
165 |
{
|
|
166 |
TPtrC fileName = iFileName->Des();
|
|
167 |
VCXLOGLO2("Could not open file: %S", &fileName);
|
|
168 |
VCXLOGLO1("<<<CIptvTestVerifyData::WriteVerifyData");
|
|
169 |
iFile.Close();
|
|
170 |
User::Leave(result);
|
|
171 |
}
|
|
172 |
iFile.Seek(ESeekEnd, filePos);
|
|
173 |
|
|
174 |
iFileStream.Attach(iFile, filePos);
|
|
175 |
}
|
|
176 |
else
|
|
177 |
{
|
|
178 |
User::Leave(KErrCorrupt);
|
|
179 |
}
|
|
180 |
|
|
181 |
iFileOpen = ETrue;
|
|
182 |
VCXLOGLO1("<<<CVerifyFile::OpenStream");
|
|
183 |
}
|
|
184 |
|
|
185 |
// -----------------------------------------------------------------------------
|
|
186 |
// CVerifyFile::CreateNewFile
|
|
187 |
// -----------------------------------------------------------------------------
|
|
188 |
//
|
|
189 |
void CVerifyFile::CreateNewFile()
|
|
190 |
{
|
|
191 |
ResolveFileName();
|
|
192 |
|
|
193 |
VCXLOGLO1(">>>CVerifyFile::CreateNewFile");
|
|
194 |
|
|
195 |
if(BaflUtils::FileExists(iFs, iFileName->Des() ))
|
|
196 |
{
|
|
197 |
iFs.Delete(iFileName->Des());
|
|
198 |
}
|
|
199 |
|
|
200 |
if(KErrNone == iFile.Create(iFs, iFileName->Des(), EFileShareAny | EFileWrite | EFileStreamText))
|
|
201 |
{
|
|
202 |
iFile.Close();
|
|
203 |
}
|
|
204 |
|
|
205 |
VCXLOGLO1("<<<CVerifyFile::CreateNewFile");
|
|
206 |
}
|
|
207 |
|
|
208 |
// -----------------------------------------------------------------------------
|
|
209 |
// CVerifyFile::WriteData
|
|
210 |
// -----------------------------------------------------------------------------
|
|
211 |
//
|
|
212 |
void CVerifyFile::WriteData(TDesC& aData)
|
|
213 |
{
|
|
214 |
OpenStream();
|
|
215 |
|
|
216 |
iFileStream.WriteL(aData);
|
|
217 |
}
|
|
218 |
|
|
219 |
// -----------------------------------------------------------------------------
|
|
220 |
// CVerifyFile::GetFileToWrite
|
|
221 |
// -----------------------------------------------------------------------------
|
|
222 |
//
|
|
223 |
void CVerifyFile::GetFileToWrite(TDes& aFileName)
|
|
224 |
{
|
|
225 |
ResolveFileName();
|
|
226 |
|
|
227 |
if(iFileName->Des().Length() > 0)
|
|
228 |
{
|
|
229 |
aFileName = iFileName->Des();
|
|
230 |
}
|
|
231 |
}
|
|
232 |
|
|
233 |
// -----------------------------------------------------------------------------
|
|
234 |
// CIptvTestVerifyData::
|
|
235 |
// C++ default constructor can NOT contain any code, that
|
|
236 |
// might leave.
|
|
237 |
// -----------------------------------------------------------------------------
|
|
238 |
//
|
|
239 |
EXPORT_C CIptvTestVerifyData* CIptvTestVerifyData::NewL()
|
|
240 |
{
|
|
241 |
VCXLOGLO1(">>>CIptvTestVerifyData::NewL");
|
|
242 |
CIptvTestVerifyData* self = new (ELeave) CIptvTestVerifyData( );
|
|
243 |
CleanupStack::PushL(self);
|
|
244 |
self->ConstructL();
|
|
245 |
CleanupStack::Pop();
|
|
246 |
VCXLOGLO1("<<<CIptvTestVerifyData::NewL");
|
|
247 |
return self;
|
|
248 |
}
|
|
249 |
|
|
250 |
// -----------------------------------------------------------------------------
|
|
251 |
// CIptvTestVerifyData::~CIptvTestVerifyData
|
|
252 |
// destructor
|
|
253 |
// -----------------------------------------------------------------------------
|
|
254 |
//
|
|
255 |
EXPORT_C CIptvTestVerifyData::~CIptvTestVerifyData()
|
|
256 |
{
|
|
257 |
VCXLOGLO1(">>>CIptvTestVerifyData::~CIptvTestVerifyData");
|
|
258 |
|
|
259 |
delete iZipFile;
|
|
260 |
iZipFile = NULL;
|
|
261 |
|
|
262 |
iFs.Close();
|
|
263 |
|
|
264 |
iVerifyFiles.ResetAndDestroy();
|
|
265 |
|
|
266 |
delete iBuffer;
|
|
267 |
iBuffer = NULL;
|
|
268 |
|
|
269 |
VCXLOGLO1("<<<CIptvTestVerifyData::~CIptvTestVerifyData");
|
|
270 |
}
|
|
271 |
|
|
272 |
// -----------------------------------------------------------------------------
|
|
273 |
// CIptvTestVerifyData::GetVerifyFileIndex
|
|
274 |
// -----------------------------------------------------------------------------
|
|
275 |
//
|
|
276 |
TInt CIptvTestVerifyData::GetVerifyFileIndex(TInt& aIndex, TDesC& aVerifyId)
|
|
277 |
{
|
|
278 |
aIndex = -1;
|
|
279 |
|
|
280 |
TInt i;
|
|
281 |
|
|
282 |
for(i=0; i<iVerifyFiles.Count(); i++)
|
|
283 |
{
|
|
284 |
if(iVerifyFiles[i]->iId == aVerifyId)
|
|
285 |
{
|
|
286 |
aIndex = i;
|
|
287 |
}
|
|
288 |
}
|
|
289 |
|
|
290 |
if(aIndex == -1)
|
|
291 |
{
|
|
292 |
return KErrNotFound;
|
|
293 |
}
|
|
294 |
|
|
295 |
return KErrNone;
|
|
296 |
}
|
|
297 |
|
|
298 |
// -----------------------------------------------------------------------------
|
|
299 |
// CIptvTestVerifyData::CreateVerifyData
|
|
300 |
// -----------------------------------------------------------------------------
|
|
301 |
//
|
|
302 |
EXPORT_C TInt CIptvTestVerifyData::CreateVerifyDataL(TDesC& aVerifyId, TBool aAppend)
|
|
303 |
{
|
|
304 |
VCXLOGLO1(">>>CIptvTestVerifyData::CreateVerifyData");
|
|
305 |
|
|
306 |
if(aVerifyId.Length() <= 0)
|
|
307 |
{
|
|
308 |
VCXLOGLO1("No verify Id");
|
|
309 |
VCXLOGLO1("<<<CIptvTestVerifyData::CreateVerifyData");
|
|
310 |
return KErrNone;
|
|
311 |
}
|
|
312 |
|
|
313 |
//BAFL::EnsurePathExistsL
|
|
314 |
|
|
315 |
TInt result = KErrNone;
|
|
316 |
|
|
317 |
TInt index;
|
|
318 |
|
|
319 |
if(KErrNone != GetVerifyFileIndex(index, aVerifyId))
|
|
320 |
{
|
|
321 |
CVerifyFile *vf = CVerifyFile::NewL();
|
|
322 |
vf->iId = aVerifyId;
|
|
323 |
iVerifyFiles.Append(vf);
|
|
324 |
if(KErrNone != GetVerifyFileIndex(index, aVerifyId))
|
|
325 |
{
|
|
326 |
VCXLOGLO1("CIptvTestVerifyData:: Verify file not found even after creating one.");
|
|
327 |
VCXLOGLO1("<<<CIptvTestVerifyData::CreateVerifyData");
|
|
328 |
return KErrGeneral;
|
|
329 |
}
|
|
330 |
}
|
|
331 |
|
|
332 |
TBuf<256> fileName;
|
|
333 |
|
|
334 |
if(!aAppend)
|
|
335 |
{
|
|
336 |
iVerifyFiles[index]->CreateNewFile();
|
|
337 |
}
|
|
338 |
|
|
339 |
iVerifyFiles[index]->GetFileToWrite(fileName);
|
|
340 |
|
|
341 |
VCXLOGLO2("CIptvTestVerifyData:: writePath %S", &fileName);
|
|
342 |
|
|
343 |
VCXLOGLO1("<<<CIptvTestVerifyData::CreateVerifyData");
|
|
344 |
return result;
|
|
345 |
}
|
|
346 |
|
|
347 |
|
|
348 |
// -----------------------------------------------------------------------------
|
|
349 |
// CIptvTestVerifyData::WriteVerifyData
|
|
350 |
// -----------------------------------------------------------------------------
|
|
351 |
//
|
|
352 |
EXPORT_C TInt CIptvTestVerifyData::WriteVerifyDataL(TDesC& aVerifyId, TDesC& aVerifyData)
|
|
353 |
{
|
|
354 |
TInt index;
|
|
355 |
|
|
356 |
if(KErrNone != GetVerifyFileIndex(index, aVerifyId))
|
|
357 |
{
|
|
358 |
//VCXLOGLO1("Call to WriteVerifyData before CreateVerifyData is called.");
|
|
359 |
//VCXLOGLO1("<<<CIptvTestVerifyData::WriteVerifyData");
|
|
360 |
return KErrNone;
|
|
361 |
}
|
|
362 |
|
|
363 |
// VCXLOGLO1(">>>CIptvTestVerifyData::WriteVerifyData");
|
|
364 |
|
|
365 |
iBuffer->Des().Zero();
|
|
366 |
|
|
367 |
if( iUseTimestamps )
|
|
368 |
{
|
|
369 |
_LIT(KDateTimeString,"%D%M%Y%/0%1%/1%2%/2%3%/3 %-B%:0%H%:1%T%:2%S%.%*C2%:3%-B");
|
|
370 |
TBuf<128> timeString;
|
|
371 |
TTime time;
|
|
372 |
time.HomeTime();
|
|
373 |
TBuf<128> buff;
|
|
374 |
time.FormatL( buff, KDateTimeString );
|
|
375 |
iBuffer->Des().Append( buff );
|
|
376 |
iBuffer->Des().Append( _L(" ") );
|
|
377 |
}
|
|
378 |
|
|
379 |
iBuffer->Des().Append( aVerifyData );
|
|
380 |
|
|
381 |
TInt result = KErrNone;
|
|
382 |
iVerifyFiles[index]->WriteData( *iBuffer );
|
|
383 |
TBuf<12> lineChange(KLineBreak);
|
|
384 |
iVerifyFiles[index]->WriteData( lineChange );
|
|
385 |
|
|
386 |
// VCXLOGLO1("<<<CIptvTestVerifyData::WriteVerifyData");
|
|
387 |
return result;
|
|
388 |
}
|
|
389 |
|
|
390 |
// -----------------------------------------------------------------------------
|
|
391 |
// CIptvTestVerifyData::VerifyData
|
|
392 |
// ----------------------------------------------------------------------------
|
|
393 |
//
|
|
394 |
EXPORT_C TInt CIptvTestVerifyData::VerifyDataL(TDesC& aVerifyId, TVerifyResult& aVerifyResult)
|
|
395 |
{
|
|
396 |
// Get index for the verified file info
|
|
397 |
// If not found then exit w/o error
|
|
398 |
TInt index;
|
|
399 |
|
|
400 |
if(KErrNone != GetVerifyFileIndex(index, aVerifyId))
|
|
401 |
{
|
|
402 |
VCXLOGLO1("CIptvTestVerifyData::VerifyDataL - Data verifying is not enabled.");
|
|
403 |
aVerifyResult = EVerifiedFileNotFound;
|
|
404 |
return KErrNone;
|
|
405 |
}
|
|
406 |
|
|
407 |
VCXLOGLO1(">>>CIptvTestVerifyData::VerifyData");
|
|
408 |
|
|
409 |
TInt result = KErrNone;
|
|
410 |
aVerifyResult = EVerifyOk;
|
|
411 |
|
|
412 |
// Connect to file system
|
|
413 |
TBuf<256> fileNameRead( _L("c:\\testing\\data\\iptvtempverify.txt") ); // File which is extracted from verify.zip
|
|
414 |
TBuf<256> fileNameWrite; // File which is written during the test
|
|
415 |
|
|
416 |
TRAPD( err, ExtractVerifyFileL( aVerifyId, fileNameRead ) );
|
|
417 |
if( err != KErrNone )
|
|
418 |
{
|
|
419 |
VCXLOGLO2("CIptvTestVerifyData:: verify file extract failed: %d", err);
|
|
420 |
VCXLOGLO1("<<<CIptvTestVerifyData::VerifyDataL");
|
|
421 |
aVerifyResult = EVerifiedFileNotFound;
|
|
422 |
return KErrNone;
|
|
423 |
}
|
|
424 |
|
|
425 |
iVerifyFiles[index]->GetFileToWrite(fileNameWrite);
|
|
426 |
iVerifyFiles[index]->CloseFileHandles();
|
|
427 |
|
|
428 |
// Check that the files exist
|
|
429 |
|
|
430 |
if(!BaflUtils::FileExists(iFs, fileNameRead))
|
|
431 |
{
|
|
432 |
VCXLOGLO2("File used to verify data not found. %S must be verified by hand and added to the verify.zip.", &fileNameWrite);
|
|
433 |
VCXLOGLO1("<<<CIptvTestVerifyData::VerifyDataL");
|
|
434 |
aVerifyResult = EVerifiedFileNotFound;
|
|
435 |
return KErrNone;
|
|
436 |
}
|
|
437 |
|
|
438 |
if(!BaflUtils::FileExists(iFs, fileNameWrite))
|
|
439 |
{
|
|
440 |
VCXLOGLO2("File %S not found. This should not happen.", &fileNameWrite);
|
|
441 |
VCXLOGLO1("<<<CIptvTestVerifyData::VerifyDataL");
|
|
442 |
aVerifyResult = EVerifiedFileNotFound;
|
|
443 |
return KErrNone;
|
|
444 |
}
|
|
445 |
|
|
446 |
// Open files and do comparison line by line
|
|
447 |
|
|
448 |
// Verified file from installation
|
|
449 |
RFile fileFromInst;
|
|
450 |
TFileText fromInst;
|
|
451 |
HBufC* lineFromInstBuff = HBufC::NewL( 1024 * 4 );
|
|
452 |
CleanupStack::PushL( lineFromInstBuff );
|
|
453 |
TPtr lineFromInst( lineFromInstBuff->Des() );
|
|
454 |
|
|
455 |
// File from test case
|
|
456 |
RFile fileFromTest;
|
|
457 |
TFileText fromTest;
|
|
458 |
HBufC* lineFromTestBuff = HBufC::NewL( 1024 * 4 );
|
|
459 |
CleanupStack::PushL( lineFromTestBuff );
|
|
460 |
TPtr lineFromTest( lineFromTestBuff->Des() );
|
|
461 |
|
|
462 |
result = fileFromInst.Open(iFs, fileNameRead, EFileRead | EFileStreamText);
|
|
463 |
if(result != KErrNone)
|
|
464 |
{
|
|
465 |
VCXLOGLO2("Could not open file 1: %S", &fileNameRead);
|
|
466 |
CleanupStack::PopAndDestroy( lineFromTestBuff );
|
|
467 |
CleanupStack::PopAndDestroy( lineFromInstBuff );
|
|
468 |
VCXLOGLO1("<<<CIptvTestVerifyData::VerifyDataL");
|
|
469 |
aVerifyResult = ESystemError;
|
|
470 |
return result;
|
|
471 |
}
|
|
472 |
CleanupClosePushL(fileFromInst);
|
|
473 |
|
|
474 |
result = fileFromTest.Open(iFs, fileNameWrite, EFileRead | EFileStreamText);
|
|
475 |
if(result != KErrNone)
|
|
476 |
{
|
|
477 |
VCXLOGLO2("Could not open file 2: %S", &fileNameRead);
|
|
478 |
VCXLOGLO1("<<<CIptvTestVerifyData::VerifyDataL");
|
|
479 |
aVerifyResult = ESystemError;
|
|
480 |
CleanupStack::PopAndDestroy(&fileFromInst);
|
|
481 |
CleanupStack::PopAndDestroy( lineFromTestBuff );
|
|
482 |
CleanupStack::PopAndDestroy( lineFromInstBuff );
|
|
483 |
return result;
|
|
484 |
}
|
|
485 |
CleanupClosePushL(fileFromTest);
|
|
486 |
|
|
487 |
TInt lineNumber(0);
|
|
488 |
TInt totalResult(0);
|
|
489 |
TInt32 totalLength(0);
|
|
490 |
|
|
491 |
fromInst.Set(fileFromInst);
|
|
492 |
fromTest.Set(fileFromTest);
|
|
493 |
|
|
494 |
while(result == KErrNone)
|
|
495 |
{
|
|
496 |
TInt result2(KErrNone);
|
|
497 |
|
|
498 |
result = fromInst.Read(lineFromInst);
|
|
499 |
result2 = fromTest.Read(lineFromTest);
|
|
500 |
|
|
501 |
// End of file reached for both files. No differences.
|
|
502 |
if(result == KErrEof && result2 == KErrEof)
|
|
503 |
{
|
|
504 |
result = KErrNone;
|
|
505 |
break;
|
|
506 |
}
|
|
507 |
|
|
508 |
// Eof reached only for one file. Verify failed.
|
|
509 |
if( result == KErrEof )
|
|
510 |
{
|
|
511 |
aVerifyResult = EVerifyFailed;
|
|
512 |
VCXLOGLO1("End of file reached for installed verify file!");
|
|
513 |
break;
|
|
514 |
}
|
|
515 |
else if( result2 == KErrEof )
|
|
516 |
{
|
|
517 |
aVerifyResult = EVerifyFailed;
|
|
518 |
VCXLOGLO1("End of file reached for test verify file!");
|
|
519 |
break;
|
|
520 |
}
|
|
521 |
|
|
522 |
// Error reading the files.
|
|
523 |
if(result != KErrNone && result != KErrTooBig)
|
|
524 |
{
|
|
525 |
VCXLOGLO3("CIptvTestVerifyData:: reading file (test) failed at line: %d, result: %d", lineNumber, result);
|
|
526 |
break;
|
|
527 |
}
|
|
528 |
|
|
529 |
if(result2 != KErrNone && result2 != KErrTooBig)
|
|
530 |
{
|
|
531 |
VCXLOGLO3("CIptvTestVerifyData:: reading file (test) failed at line: %d, result: %d", lineNumber, result);
|
|
532 |
result = result2;
|
|
533 |
break;
|
|
534 |
}
|
|
535 |
|
|
536 |
totalLength += lineFromInst.Length();
|
|
537 |
|
|
538 |
// Don't compare if line is for path because it can have service id which varies
|
|
539 |
if( KErrNotFound != lineFromTest.Match(_L("*\\Data\\videocenter\\*")) && KErrNotFound != lineFromTest.Match(_L("*\\data\\videocenter\\*")) )
|
|
540 |
{
|
|
541 |
TInt res = lineFromInst.Compare(lineFromTest);
|
|
542 |
if(res < 0)
|
|
543 |
{
|
|
544 |
totalResult += (res *- 1);
|
|
545 |
}
|
|
546 |
else
|
|
547 |
{
|
|
548 |
totalResult += res;
|
|
549 |
}
|
|
550 |
|
|
551 |
if(res != KErrNone)
|
|
552 |
{
|
|
553 |
VCXLOGLO3("CIptvTestVerifyData:: Lines at line %d are different. Res: %d", lineNumber, res);
|
|
554 |
VCXLOGLO2("CIptvTestVerifyData:: %S", &lineFromInst);
|
|
555 |
VCXLOGLO2("CIptvTestVerifyData:: %S", &lineFromTest);
|
|
556 |
aVerifyResult = EVerifyFailed;
|
|
557 |
break; // No more verifying
|
|
558 |
}
|
|
559 |
}
|
|
560 |
|
|
561 |
lineNumber++;
|
|
562 |
}
|
|
563 |
|
|
564 |
VCXLOGLO2("CIptvTestVerifyData:: %d lines verified.", lineNumber);
|
|
565 |
VCXLOGLO2("CIptvTestVerifyData:: %d total length of file.", totalLength);
|
|
566 |
VCXLOGLO2("CIptvTestVerifyData:: %d total difference.", totalResult);
|
|
567 |
|
|
568 |
CleanupStack::PopAndDestroy(&fileFromTest);
|
|
569 |
CleanupStack::PopAndDestroy(&fileFromInst);
|
|
570 |
CleanupStack::PopAndDestroy( lineFromTestBuff );
|
|
571 |
CleanupStack::PopAndDestroy( lineFromInstBuff );
|
|
572 |
|
|
573 |
VCXLOGLO1("<<<CIptvTestVerifyData::VerifyData");
|
|
574 |
return result;
|
|
575 |
}
|
|
576 |
|
|
577 |
// -----------------------------------------------------------------------------
|
|
578 |
// CIptvTestVerifyData::VerifyData
|
|
579 |
// ----------------------------------------------------------------------------
|
|
580 |
//
|
|
581 |
EXPORT_C void CIptvTestVerifyData::EnableTimestamps( TBool aUseTimestamps )
|
|
582 |
{
|
|
583 |
iUseTimestamps = aUseTimestamps;
|
|
584 |
}
|
|
585 |
// -----------------------------------------------------------------------------
|
|
586 |
// CIptvTestVerifyData::CIptvTestVerifyData
|
|
587 |
// -----------------------------------------------------------------------------
|
|
588 |
//
|
|
589 |
CIptvTestVerifyData::CIptvTestVerifyData()
|
|
590 |
{
|
|
591 |
VCXLOGLO1(">>>CIptvTestVerifyData::CIptvTestVerifyData");
|
|
592 |
|
|
593 |
VCXLOGLO1("<<<CIptvTestVerifyData::CIptvTestVerifyData");
|
|
594 |
}
|
|
595 |
|
|
596 |
// -----------------------------------------------------------------------------
|
|
597 |
// CIptvTestVerifyData::ConstructL()
|
|
598 |
// -----------------------------------------------------------------------------
|
|
599 |
//
|
|
600 |
void CIptvTestVerifyData::ConstructL()
|
|
601 |
{
|
|
602 |
VCXLOGLO1(">>>CIptvTestVerifyData::ConstructL");
|
|
603 |
iVerifyFiles.ResetAndDestroy();
|
|
604 |
User::LeaveIfError( iFs.Connect() );
|
|
605 |
TRAPD(err, iZipFile = CZipFile::NewL( iFs, KIptvVerifyZipFile ) );
|
|
606 |
if( err == KErrNoMemory )
|
|
607 |
{
|
|
608 |
User::Leave( err );
|
|
609 |
}
|
|
610 |
if( err != KErrNone )
|
|
611 |
{
|
|
612 |
VCXLOGLO2("CIptvTestVerifyData:: CZipFile::NewL err: %d", err);
|
|
613 |
delete iZipFile;
|
|
614 |
iZipFile = NULL;
|
|
615 |
}
|
|
616 |
|
|
617 |
iBuffer = HBufC::NewL( 1024 * 5 );
|
|
618 |
|
|
619 |
VCXLOGLO1("<<<CIptvTestVerifyData::ConstructL");
|
|
620 |
}
|
|
621 |
|
|
622 |
// -----------------------------------------------------------------------------
|
|
623 |
// CIptvTestVerifyData::ReadFile()
|
|
624 |
// -----------------------------------------------------------------------------
|
|
625 |
//
|
|
626 |
TInt CIptvTestVerifyData::ReadFileL(RFs& aFs, TDes& aFileName, HBufC8** aBuff, TVerifyResult& aVerifyResult)
|
|
627 |
{
|
|
628 |
VCXLOGLO2(">>>CIptvTestVerifyData::ReadFile: %S", &aFileName);
|
|
629 |
|
|
630 |
TInt result = KErrNone;
|
|
631 |
RFile file;
|
|
632 |
TInt fileSize;
|
|
633 |
|
|
634 |
result = file.Open(aFs, aFileName, EFileRead | EFileStreamText);
|
|
635 |
if(result != KErrNone)
|
|
636 |
{
|
|
637 |
VCXLOGLO2("Could not open file 1: %S", &aFileName);
|
|
638 |
VCXLOGLO1("<<<CIptvTestVerifyData::VerifyDataL");
|
|
639 |
aVerifyResult = ESystemError;
|
|
640 |
return result;
|
|
641 |
}
|
|
642 |
CleanupClosePushL(file);
|
|
643 |
|
|
644 |
file.Size(fileSize);
|
|
645 |
|
|
646 |
TInt filePos = 0;
|
|
647 |
file.Seek(ESeekStart, filePos);
|
|
648 |
|
|
649 |
HBufC8* buff = HBufC8::NewL( fileSize);
|
|
650 |
|
|
651 |
TPtr8 ptr( buff->Des() );
|
|
652 |
file.Read(ptr);
|
|
653 |
|
|
654 |
*aBuff = buff;
|
|
655 |
|
|
656 |
CleanupStack::PopAndDestroy(&file);
|
|
657 |
|
|
658 |
VCXLOGLO1("<<<CIptvTestVerifyData::ReadFile");
|
|
659 |
return KErrNone;
|
|
660 |
}
|
|
661 |
|
|
662 |
// -----------------------------------------------------------------------------
|
|
663 |
// CIptvTestVerifyData::ExtractVerifyFile()
|
|
664 |
// -----------------------------------------------------------------------------
|
|
665 |
//
|
|
666 |
void CIptvTestVerifyData::ExtractVerifyFileL( TDesC& aVerifyId, const TDesC& aDestFile )
|
|
667 |
{
|
|
668 |
VCXLOGLO1(">>>CIptvTestVerifyData::ExtractVerifyFile");
|
|
669 |
|
|
670 |
iFs.Delete( aDestFile );
|
|
671 |
|
|
672 |
if( !iZipFile )
|
|
673 |
{
|
|
674 |
VCXLOGLO1("CIptvTestVerifyData:: iZipFile == NULL! Leaving..");
|
|
675 |
User::Leave( KErrNotReady );
|
|
676 |
}
|
|
677 |
|
|
678 |
TBuf<256> verifyFileName( aVerifyId );
|
|
679 |
verifyFileName.Append( KVerifyExtension );
|
|
680 |
VCXLOGLO2("CIptvTestVerifyData:: verifyFileName: %S", &verifyFileName);
|
|
681 |
VCXLOGLO2("CIptvTestVerifyData:: aDestFile: %S", &aDestFile);
|
|
682 |
|
|
683 |
if( !FileExistsInZip( iZipFile, verifyFileName ) )
|
|
684 |
{
|
|
685 |
VCXLOGLO1("CIptvTestVerifyData:: No such file in zip! Leaving..");
|
|
686 |
User::Leave( CIptvTestVerifyData::EVerifiedFileNotFound );
|
|
687 |
}
|
|
688 |
|
|
689 |
// Get zip file member from the archive
|
|
690 |
VCXLOGLO1("CIptvTestVerifyData:: Get zip file member from the archive");
|
|
691 |
CZipFileMember* member = iZipFile->CaseInsensitiveMemberL( verifyFileName );
|
|
692 |
if( member == NULL )
|
|
693 |
{
|
|
694 |
VCXLOGLO1("CIptvTestVerifyData:: zip member is null. Leaving..");
|
|
695 |
User::Leave(KErrGeneral);
|
|
696 |
}
|
|
697 |
CleanupStack::PushL( member );
|
|
698 |
|
|
699 |
// Get read stream for the file
|
|
700 |
VCXLOGLO1("CIptvTestVerifyData:: Get read stream for the file");
|
|
701 |
RZipFileMemberReaderStream* stream;
|
|
702 |
iZipFile->GetInputStreamL( member, stream );
|
|
703 |
CleanupStack::PushL( stream );
|
|
704 |
|
|
705 |
// Alloc buffer and read the archived file
|
|
706 |
VCXLOGLO1("CIptvTestVerifyData:: Alloc buffer and read the archived file");
|
|
707 |
HBufC8* buffer = HBufC8::NewLC( member->UncompressedSize() );
|
|
708 |
TPtr8 bufferPtr( buffer->Des() );
|
|
709 |
User::LeaveIfError( stream->Read( bufferPtr, member->UncompressedSize() ) );
|
|
710 |
|
|
711 |
// Write the file to the filesystem
|
|
712 |
VCXLOGLO1("CIptvTestVerifyData:: Write the file to the filesystem");
|
|
713 |
RFile file;
|
|
714 |
User::LeaveIfError( file.Replace( iFs, aDestFile, EFileWrite ) );
|
|
715 |
CleanupClosePushL( file );
|
|
716 |
User::LeaveIfError( file.Write(*buffer) );
|
|
717 |
|
|
718 |
CleanupStack::PopAndDestroy( &file );
|
|
719 |
CleanupStack::PopAndDestroy( buffer );
|
|
720 |
CleanupStack::PopAndDestroy( stream );
|
|
721 |
CleanupStack::PopAndDestroy( member );
|
|
722 |
|
|
723 |
VCXLOGLO1("<<<CIptvTestVerifyData::ExtractVerifyFile");
|
|
724 |
}
|
|
725 |
|
|
726 |
// -----------------------------------------------------------------------------
|
|
727 |
// CIptvTestVerifyData::FileExistsInZip()
|
|
728 |
// -----------------------------------------------------------------------------
|
|
729 |
//
|
|
730 |
TBool CIptvTestVerifyData::FileExistsInZip( CZipFile* aZipFile, const TDesC& aFileName )
|
|
731 |
{
|
|
732 |
VCXLOGLO1(">>>CIptvTestVerifyData::FileExistsInZip");
|
|
733 |
|
|
734 |
CZipFileMember* member = NULL;
|
|
735 |
|
|
736 |
VCXLOGLO1("CIptvTestVerifyData:: list of members");
|
|
737 |
CZipFileMemberIterator* members = aZipFile->GetMembersL();
|
|
738 |
|
|
739 |
VCXLOGLO1("CIptvTestVerifyData:: loop all members");
|
|
740 |
|
|
741 |
while ((member = members->NextL()) != 0)
|
|
742 |
{
|
|
743 |
VCXLOGLO3("CIptvTestVerifyData:: member %S, size: %d", &(*member->Name()), member->CompressedSize());
|
|
744 |
|
|
745 |
if( aFileName == (*member->Name()) )
|
|
746 |
{
|
|
747 |
delete member;
|
|
748 |
delete members;
|
|
749 |
VCXLOGLO1("<<<CIptvTestVerifyData::FileExistsInZip");
|
|
750 |
return ETrue;
|
|
751 |
}
|
|
752 |
|
|
753 |
delete member;
|
|
754 |
}
|
|
755 |
|
|
756 |
delete members;
|
|
757 |
VCXLOGLO1("<<<CIptvTestVerifyData::FileExistsInZip");
|
|
758 |
return EFalse;
|
|
759 |
}
|
|
760 |
|
|
761 |
// ---------------------------------
|
|
762 |
// End of File
|