|
1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include <iostream> |
|
17 #include <cstdio> |
|
18 #include <fstream> |
|
19 #include <sstream> |
|
20 #include <string> |
|
21 #include <zlib.h> |
|
22 |
|
23 using namespace std; |
|
24 |
|
25 const unsigned int bufferSize = 1024; |
|
26 const string filePath = "..\\..\\ezlib2_testdata\\"; |
|
27 |
|
28 /* |
|
29 * deflateInflateTest() constants |
|
30 */ |
|
31 const int deflateInflateTestDataItems = 24; |
|
32 const string deflateInflateTestFiles[deflateInflateTestDataItems] = {"GifImage.gif", "BigSize.txt", "BitmapImage.bmp", |
|
33 "BigSize.txt", "JpegImage.jpg", "BigSize.txt", |
|
34 "SmallSize.txt", "BigSize.txt", "HolyMoley.jar", |
|
35 "BigSize.txt", "ExifHeadFile.png", "BigSize.txt", |
|
36 "GifImage.gif", "BigSize.doc", "BitmapImage.bmp", |
|
37 "BigSize.doc", "JpegImage.jpg", "BigSize.doc", |
|
38 "SmallSize.txt", "BigSize.doc", "HolyMoley.jar", |
|
39 "BigSize.doc", "ExifHeadFile.png", "BigSize.doc"}; |
|
40 |
|
41 const int deflateInflateTestLevel[deflateInflateTestDataItems] = {Z_DEFAULT_COMPRESSION, Z_NO_COMPRESSION, Z_BEST_COMPRESSION, |
|
42 Z_DEFAULT_COMPRESSION, Z_NO_COMPRESSION, Z_BEST_COMPRESSION, |
|
43 Z_BEST_COMPRESSION, Z_DEFAULT_COMPRESSION, Z_NO_COMPRESSION, |
|
44 Z_BEST_COMPRESSION, Z_DEFAULT_COMPRESSION, Z_NO_COMPRESSION, |
|
45 Z_NO_COMPRESSION, Z_BEST_COMPRESSION, Z_DEFAULT_COMPRESSION, |
|
46 Z_NO_COMPRESSION, Z_BEST_COMPRESSION, Z_DEFAULT_COMPRESSION, |
|
47 Z_BEST_SPEED, Z_BEST_SPEED, Z_BEST_SPEED, |
|
48 Z_BEST_SPEED, Z_BEST_SPEED, Z_BEST_SPEED}; |
|
49 |
|
50 const int deflateInflateTestWindowBits[deflateInflateTestDataItems] = {8, MAX_WBITS, 8, |
|
51 MAX_WBITS, 8, MAX_WBITS, |
|
52 8, 8, MAX_WBITS, |
|
53 MAX_WBITS, MAX_WBITS, 8, |
|
54 MAX_WBITS, 8, 8, |
|
55 8, MAX_WBITS, MAX_WBITS, |
|
56 8, MAX_WBITS, 8, |
|
57 MAX_WBITS, MAX_WBITS, 8}; |
|
58 |
|
59 const int deflateInflateTestMemLevel[deflateInflateTestDataItems] = {1, 1, 1, |
|
60 1, 1, 1, |
|
61 MAX_MEM_LEVEL, MAX_MEM_LEVEL, MAX_MEM_LEVEL, |
|
62 MAX_MEM_LEVEL, MAX_MEM_LEVEL, MAX_MEM_LEVEL, |
|
63 8, 8, 8, |
|
64 8, 8, 8, |
|
65 1, MAX_MEM_LEVEL, 8, |
|
66 1, MAX_MEM_LEVEL, 8}; |
|
67 |
|
68 const int deflateInflateTestStrategy[deflateInflateTestDataItems] = {Z_DEFAULT_STRATEGY, Z_DEFAULT_STRATEGY, Z_FILTERED, |
|
69 Z_FILTERED, Z_HUFFMAN_ONLY, Z_HUFFMAN_ONLY, |
|
70 Z_DEFAULT_STRATEGY, Z_DEFAULT_STRATEGY, Z_FILTERED, |
|
71 Z_FILTERED, Z_HUFFMAN_ONLY, Z_HUFFMAN_ONLY, |
|
72 Z_DEFAULT_STRATEGY, Z_DEFAULT_STRATEGY, Z_FILTERED, |
|
73 Z_FILTERED, Z_HUFFMAN_ONLY, Z_HUFFMAN_ONLY, |
|
74 Z_DEFAULT_STRATEGY, Z_DEFAULT_STRATEGY, Z_FILTERED, |
|
75 Z_FILTERED, Z_HUFFMAN_ONLY, Z_HUFFMAN_ONLY}; |
|
76 |
|
77 /* |
|
78 * inflateOldZlibFilesTest() constants |
|
79 */ |
|
80 const int inflateOldZlibFilesTestDataItems = 24; |
|
81 const string inflateOldZlibFilesTestFiles[inflateOldZlibFilesTestDataItems] = {"GifImage.gif", "BigSize.txt", "BitmapImage.bmp", |
|
82 "BigSize.txt", "JpegImage.jpg", "BigSize.txt", |
|
83 "SmallSize.txt", "BigSize.txt", "HolyMoley.jar", |
|
84 "BigSize.txt", "ExifHeadFile.png", "BigSize.txt", |
|
85 "GifImage.gif", "BigSize.doc", "BitmapImage.bmp", |
|
86 "BigSize.doc", "JpegImage.jpg", "BigSize.doc", |
|
87 "SmallSize.txt", "BigSize.doc", "HolyMoley.jar", |
|
88 "BigSize.doc", "ExifHeadFile.png", "BigSize.doc"}; |
|
89 |
|
90 /* |
|
91 * Global variables |
|
92 */ |
|
93 ofstream *outputFile = NULL; |
|
94 int totalPassed = 0; |
|
95 |
|
96 /* |
|
97 * HELPER FUNCTION DECLARATIONS |
|
98 */ |
|
99 void closeOutputFile(); |
|
100 void deleteFile(const string fileLocation); |
|
101 int deflateCompress(z_stream &aStream, ifstream &input, ofstream &output); |
|
102 bool deflateFile(const string &aInputFileName, const string &aOutputFileName, int aLevel, int aMethod, int aWindowBits, int aMemLevel, int aStrategy); |
|
103 bool doFilesMatch(const string &aFileName1, const string &aFileName2); |
|
104 unsigned int getFileLength(ifstream &file); |
|
105 int inflateDecompress(z_stream &aStream, ifstream &input, ofstream &output); |
|
106 bool inflateFile(const string &aInputFileName, const string &aOutputFileName, int aWindowBits = 15); |
|
107 bool openOutputFile(const string &aOutputFileName); |
|
108 void printTestResults(); |
|
109 |
|
110 /* |
|
111 * TEST FUNCTION DECLARATIONS |
|
112 */ |
|
113 bool deflateInflateTest(); |
|
114 bool inflateOldZlibFilesTest(); |
|
115 |
|
116 |
|
117 /* |
|
118 * Closes the results output file and frees the memory. |
|
119 */ |
|
120 void closeOutputFile() |
|
121 { |
|
122 *outputFile << "\t</body>" << endl; |
|
123 *outputFile << "</html>" << endl; |
|
124 outputFile->close(); |
|
125 |
|
126 delete outputFile; |
|
127 } |
|
128 |
|
129 void deleteFile(const string fileLocation) |
|
130 { |
|
131 int err = remove(fileLocation.c_str()); |
|
132 if(err != 0) |
|
133 { |
|
134 *outputFile << "\t\t" << err << " - Error deleting file: " << fileLocation << "<br />" << endl; |
|
135 cout << "Error deleting file: " << fileLocation << endl; |
|
136 } |
|
137 } |
|
138 |
|
139 /* |
|
140 * Compresses data using the deflate function. |
|
141 */ |
|
142 int deflateCompress(z_stream &aStream, ifstream &input, ofstream &output) |
|
143 { |
|
144 int err = Z_OK; |
|
145 int flush = Z_NO_FLUSH; |
|
146 unsigned char in[bufferSize]; |
|
147 unsigned char out[bufferSize]; |
|
148 unsigned int fileSize = getFileLength(input); |
|
149 |
|
150 do |
|
151 { |
|
152 input.read(reinterpret_cast<char *>(in), bufferSize); |
|
153 |
|
154 aStream.avail_in = ((aStream.total_in + bufferSize) > fileSize) ? fileSize - aStream.total_in : bufferSize; |
|
155 aStream.next_in = in; |
|
156 |
|
157 flush = input.eof() ? Z_FINISH : Z_NO_FLUSH; |
|
158 |
|
159 // Call deflate() on input until output buffer not full |
|
160 // Finish compression if all of input buffer has been read in |
|
161 do |
|
162 { |
|
163 aStream.avail_out = bufferSize; |
|
164 aStream.next_out = out; |
|
165 |
|
166 err = deflate(&aStream, flush); |
|
167 if(err != Z_OK && err != Z_STREAM_END) |
|
168 { |
|
169 return err; |
|
170 } |
|
171 output.write(reinterpret_cast<char *>(out), bufferSize - aStream.avail_out); |
|
172 |
|
173 } while(aStream.avail_out == 0 && err == Z_OK); |
|
174 } while(err != Z_STREAM_END); |
|
175 |
|
176 return Z_OK; |
|
177 } |
|
178 |
|
179 /* |
|
180 * Reads in the data from the input file, compresses it and creates a new output file for the compressed data |
|
181 */ |
|
182 bool deflateFile(const string &aInputFileName, const string &aOutputFileName, int aLevel, int aMethod, int aWindowBits, int aMemLevel, int aStrategy) |
|
183 { |
|
184 int err = Z_OK; |
|
185 |
|
186 ifstream input(aInputFileName.c_str(), ios::in | ios::binary); |
|
187 ofstream output(aOutputFileName.c_str(), ios::out | ios::trunc | ios::binary); |
|
188 z_stream stream; |
|
189 |
|
190 if(input.is_open() && output.is_open()) |
|
191 { |
|
192 stream.zalloc = Z_NULL; |
|
193 stream.zfree = Z_NULL; |
|
194 stream.opaque = Z_NULL; |
|
195 |
|
196 deflateInit2(&stream, aLevel, aMethod, aWindowBits, aMemLevel, aStrategy); |
|
197 err = deflateCompress(stream, input, output); |
|
198 deflateEnd(&stream); |
|
199 |
|
200 if(err != Z_OK) |
|
201 { |
|
202 *outputFile << "\t\t" << err << " - Error deflating!<br />" << endl; |
|
203 output.close(); |
|
204 input.close(); |
|
205 return false; |
|
206 } |
|
207 } |
|
208 else |
|
209 { |
|
210 if(!input.is_open()) |
|
211 { |
|
212 *outputFile << "\t\tDeflate could not complete due to not being able to open the input file!<br />" << endl; |
|
213 } |
|
214 else |
|
215 { |
|
216 input.close(); |
|
217 } |
|
218 |
|
219 if(!output.is_open()) |
|
220 { |
|
221 *outputFile << "\t\tDeflate could not complete due to not being able to open the output file!<br />" << endl; |
|
222 } |
|
223 else |
|
224 { |
|
225 output.close(); |
|
226 } |
|
227 |
|
228 return false; |
|
229 } |
|
230 |
|
231 input.close(); |
|
232 output.close(); |
|
233 |
|
234 *outputFile << "\t\tDeflate complete!<br />" << endl; |
|
235 return true; |
|
236 } |
|
237 |
|
238 /* |
|
239 * Checks that the two files are identical |
|
240 */ |
|
241 bool doFilesMatch(const string &aFileName1, const string &aFileName2) |
|
242 { |
|
243 ifstream file1(aFileName1.c_str(), ios::in | ios::binary); |
|
244 ifstream file2(aFileName2.c_str(), ios::in | ios::binary); |
|
245 |
|
246 if(file1.is_open() && file2.is_open()) |
|
247 { |
|
248 int file1Size = getFileLength(file1); |
|
249 int file2Size = getFileLength(file2); |
|
250 |
|
251 if(file1Size != file2Size) |
|
252 { |
|
253 *outputFile << "\t\t" << aFileName1 << " is not the same as " << aFileName2 << " because they have different file sizes!<br />" << endl; |
|
254 return false; |
|
255 } |
|
256 else |
|
257 { |
|
258 char fileBuffer1[bufferSize]; |
|
259 char fileBuffer2[bufferSize]; |
|
260 |
|
261 for(int totalSpaceProvided = bufferSize; !file1.eof(); totalSpaceProvided += bufferSize) |
|
262 { |
|
263 file1.read(fileBuffer1, bufferSize); |
|
264 file2.read(fileBuffer2, bufferSize); |
|
265 |
|
266 int read = (totalSpaceProvided > file1Size) ? bufferSize - (totalSpaceProvided - file1Size) : bufferSize; |
|
267 if(memcmp(fileBuffer1, fileBuffer2, read) != 0) |
|
268 { |
|
269 *outputFile << "\t\t" << aFileName1 << " is not the same as " << aFileName2 << "<br />" << endl; |
|
270 return false; |
|
271 } |
|
272 } |
|
273 } |
|
274 } |
|
275 else |
|
276 { |
|
277 if(!file1.is_open()) |
|
278 { |
|
279 *outputFile << "\t\tCould not check if files matched because " << aFileName1 << " could not be opened!<br />" << endl; |
|
280 } |
|
281 else |
|
282 { |
|
283 file1.close(); |
|
284 } |
|
285 |
|
286 if(!file2.is_open()) |
|
287 { |
|
288 *outputFile << "\t\tCould not check if files matched because " << aFileName2 << " could not be opened!<br />" << endl; |
|
289 } |
|
290 else |
|
291 { |
|
292 file2.close(); |
|
293 } |
|
294 |
|
295 return false; |
|
296 } |
|
297 |
|
298 file1.close(); |
|
299 file2.close(); |
|
300 |
|
301 return true; |
|
302 } |
|
303 |
|
304 /* |
|
305 * Returns a files size in bytes |
|
306 */ |
|
307 unsigned int getFileLength(ifstream &file) |
|
308 { |
|
309 file.seekg (0, ios::end); |
|
310 unsigned int fileSize = file.tellg(); |
|
311 file.seekg (0, ios::beg); |
|
312 |
|
313 return fileSize; |
|
314 } |
|
315 |
|
316 /* |
|
317 * Decompresses data using the inflate function. |
|
318 */ |
|
319 int inflateDecompress(z_stream &aStream, ifstream &input, ofstream &output) |
|
320 { |
|
321 int err = Z_OK; |
|
322 unsigned char in[bufferSize]; |
|
323 unsigned char out[bufferSize]; |
|
324 unsigned int fileSize = getFileLength(input); |
|
325 |
|
326 // Keep providing input data and output space for deflate() |
|
327 do |
|
328 { |
|
329 input.read(reinterpret_cast<char *>(in), bufferSize); |
|
330 |
|
331 aStream.avail_in = ((aStream.total_in + bufferSize) > fileSize) ? fileSize - aStream.total_in : bufferSize; |
|
332 aStream.next_in = in; |
|
333 |
|
334 // Call inflate() on input until output buffer not full |
|
335 // Finish compression if all of input buffer has been read in |
|
336 do |
|
337 { |
|
338 aStream.avail_out = bufferSize; |
|
339 aStream.next_out = out; |
|
340 |
|
341 err = inflate(&aStream, Z_NO_FLUSH); |
|
342 if(err != Z_OK && err != Z_STREAM_END && err != Z_BUF_ERROR) |
|
343 { |
|
344 return err; |
|
345 } |
|
346 output.write(reinterpret_cast<char *>(out), bufferSize - aStream.avail_out); |
|
347 |
|
348 } while(aStream.avail_out == 0); |
|
349 } while(err != Z_STREAM_END); |
|
350 |
|
351 return Z_OK; |
|
352 } |
|
353 |
|
354 /* |
|
355 * Reads in the data from the input file, decompresses it and creates a new output file for the decompressed data |
|
356 * |
|
357 * NOTE: Inflate fails when windowBits is set to 8. This is because deflateInit2() changes windowBits from 8 to 9 |
|
358 * due to an error in zlib. However, inflateInit2() does not make the same change and this results in the |
|
359 * inflate failing with a Z_DATA_ERROR. |
|
360 */ |
|
361 bool inflateFile(const string &aInputFileName, const string &aOutputFileName, int aWindowBits) |
|
362 { |
|
363 int err = Z_OK; |
|
364 |
|
365 ifstream input(aInputFileName.c_str(), ios::in | ios::binary); |
|
366 ofstream output(aOutputFileName.c_str(), ios::out | ios::binary | ios::trunc); |
|
367 z_stream stream; |
|
368 |
|
369 if(input.is_open() && output.is_open()) |
|
370 { |
|
371 stream.zalloc = Z_NULL; |
|
372 stream.zfree = Z_NULL; |
|
373 stream.opaque = Z_NULL; |
|
374 |
|
375 inflateInit2(&stream, aWindowBits); |
|
376 err = inflateDecompress(stream, input, output); |
|
377 inflateEnd(&stream); |
|
378 |
|
379 if(err != Z_OK) |
|
380 { |
|
381 *outputFile << "\t\t" << err << " - Error inflating!<br />" << endl; |
|
382 output.close(); |
|
383 input.close(); |
|
384 return false; |
|
385 } |
|
386 } |
|
387 else |
|
388 { |
|
389 if(!input.is_open()) |
|
390 { |
|
391 *outputFile << "\t\tInflate could not complete due to not being able to open the input file!<br />" << endl; |
|
392 } |
|
393 else |
|
394 { |
|
395 input.close(); |
|
396 } |
|
397 |
|
398 if(!output.is_open()) |
|
399 { |
|
400 *outputFile << "\t\tInflate could not complete due to not being able to open the output file!<br />" << endl; |
|
401 } |
|
402 else |
|
403 { |
|
404 output.close(); |
|
405 } |
|
406 |
|
407 return false; |
|
408 } |
|
409 |
|
410 output.close(); |
|
411 input.close(); |
|
412 |
|
413 *outputFile << "\t\tInflate complete!<br />" << endl; |
|
414 return true; |
|
415 } |
|
416 |
|
417 /* |
|
418 * Creates and opens the results output file. |
|
419 */ |
|
420 bool openOutputFile(const string &aOutputFileName) |
|
421 { |
|
422 outputFile = new ofstream((aOutputFileName + ".html").c_str(), ios::out | ios::trunc); |
|
423 |
|
424 if(outputFile != NULL) |
|
425 { |
|
426 *outputFile << "<html>" << endl; |
|
427 *outputFile << "\t<body>" << endl; |
|
428 |
|
429 return true; |
|
430 } |
|
431 |
|
432 return false; |
|
433 } |
|
434 |
|
435 /* |
|
436 * Outputs the test results to the results output file. |
|
437 */ |
|
438 void printTestResults() |
|
439 { |
|
440 int totalFailed = deflateInflateTestDataItems + inflateOldZlibFilesTestDataItems - totalPassed; |
|
441 |
|
442 *outputFile << "\t\tTEST RESULTS:<br />" << endl; |
|
443 *outputFile << "\t\t<font color=00AF00>Passed = " << totalPassed << "</font><br />" << endl; |
|
444 *outputFile << "\t\t<font color=FF0000>Failed = " << totalFailed << "</font><br />" << endl; |
|
445 } |
|
446 |
|
447 /** |
|
448 @SYMTestCaseID SYSLIB-EZLIB2-CT-4312 |
|
449 @SYMTestCaseDesc Check files can be deflated and inflated. |
|
450 @SYMTestPriority High |
|
451 @SYMTestActions 1. Open the input file for reading and create a compressed output |
|
452 file for writing. |
|
453 2. Create a deflate stream and initialise it using deflateInit2() |
|
454 passing it the specified compression parameters. |
|
455 3. Deflate the input using deflate(), writing the deflated data |
|
456 to the compressed output file. |
|
457 4. Cleanup the deflate stream and close the input and compressed |
|
458 output files. |
|
459 5. Open the compressed file for reading and create a decompressed |
|
460 output file for writing |
|
461 6. Create an inflate stream and initialise it using inflateInit2(). |
|
462 7. Inflate the input using inflate(), writing the inflated data to |
|
463 the decompressed output file. |
|
464 8. Cleanup the inflate stream and close the compressed input and |
|
465 decompressed output files. |
|
466 9. Open the original file (that was compressed) and the |
|
467 decompressed file for reading. |
|
468 10. Compare the contents of each file using memcmp(). |
|
469 11. Close both the files. |
|
470 12. Cleanup any files created during the test. |
|
471 |
|
472 Note: The test should be repeated for different types of input |
|
473 files as well as different size of input file e.g.: |
|
474 • TXT |
|
475 • PNG |
|
476 • JAR |
|
477 • JPG |
|
478 • BMP |
|
479 • DOC |
|
480 • GIF |
|
481 • Varying sizes of each input file should be tested starting |
|
482 from a couple of kilobytes up to several megabytes. |
|
483 |
|
484 And with compression parameters as: |
|
485 • Z_DEFAULT_COMPRESSION, Z_NO_COMPRESSION, Z_BEST_COMPRESSION |
|
486 and Z_BEST_SPEED for level |
|
487 • 8 and MAX_WBITS for windowBits |
|
488 • 1, 8 (default memory level) and MAX_MEM_LEVEL for memLevel |
|
489 • Z_DEFAULT_STRATEGY, Z_FILTERED and Z_HUFFMAN_ONLY for strategy |
|
490 @SYMTestExpectedResults The input file used for deflating should be identical to the |
|
491 inflated output file. |
|
492 */ |
|
493 bool deflateInflateTest() |
|
494 { |
|
495 bool passed = true; |
|
496 |
|
497 cout << endl << "Starting test case deflateInflateTest:" << endl; |
|
498 for(int i = 0; i < deflateInflateTestDataItems ; i++) |
|
499 { |
|
500 stringstream ss; |
|
501 string testNum; |
|
502 ss << (i + 1); |
|
503 ss >> testNum; |
|
504 |
|
505 cout << "Starting test " << testNum << " - File: " << deflateInflateTestFiles[i]; |
|
506 |
|
507 int extBegin = deflateInflateTestFiles[i].find_last_of(".", deflateInflateTestFiles[i].length()); |
|
508 string fileName = deflateInflateTestFiles[i].substr(0, extBegin); |
|
509 string fileExt = deflateInflateTestFiles[i].substr(extBegin + 1); |
|
510 |
|
511 string uncompressedFileName(filePath + deflateInflateTestFiles[i]); |
|
512 string compressedFileName(filePath + fileName + testNum + ".zip"); |
|
513 string decompressedFileName(filePath + "ezlib2_" + fileName + testNum + "_decompressed" + "." + fileExt); |
|
514 |
|
515 if(deflateFile(uncompressedFileName, compressedFileName, deflateInflateTestLevel[i], Z_DEFLATED, deflateInflateTestWindowBits[i], deflateInflateTestMemLevel[i], deflateInflateTestStrategy[i]) == false) |
|
516 { |
|
517 passed = false; |
|
518 *outputFile << "\t\t<font color=FF0000>FAILED for file: " << deflateInflateTestFiles[i] << "</font><p />" << endl << endl; |
|
519 cout << " - FAILED" << endl; |
|
520 continue; |
|
521 } |
|
522 |
|
523 if(inflateFile(compressedFileName, decompressedFileName, deflateInflateTestWindowBits[i]) == false) |
|
524 { |
|
525 passed = false; |
|
526 *outputFile << "\t\t<font color=FF0000>FAILED for file: " << uncompressedFileName << "</font><p />" << endl << endl; |
|
527 cout << " - FAILED" << endl; |
|
528 |
|
529 deleteFile(compressedFileName); |
|
530 deleteFile(decompressedFileName); |
|
531 continue; |
|
532 } |
|
533 |
|
534 if(doFilesMatch(uncompressedFileName, decompressedFileName) == false) |
|
535 { |
|
536 passed = false; |
|
537 *outputFile << "\t\t<font color=FF0000>FAILED for file: " << uncompressedFileName << "</font><p />" << endl << endl; |
|
538 cout << " - FAILED" << endl; |
|
539 |
|
540 deleteFile(compressedFileName); |
|
541 deleteFile(decompressedFileName); |
|
542 continue; |
|
543 } |
|
544 |
|
545 totalPassed++; |
|
546 *outputFile << "\t\t<font color=00AF00>PASSED for file: " << uncompressedFileName << "</font><p />" << endl << endl; |
|
547 cout << " - PASSED" << endl; |
|
548 |
|
549 deleteFile(compressedFileName); |
|
550 deleteFile(decompressedFileName); |
|
551 } |
|
552 cout << "Finished test case case deflateInflateTest." << endl; |
|
553 |
|
554 return passed; |
|
555 } |
|
556 |
|
557 /** |
|
558 @SYMTestCaseID SYSLIB-EZLIB2-CT-4313 |
|
559 @SYMTestCaseDesc Check files deflated with EZlib can be inflated using EZlib2. |
|
560 @SYMTestPriority High |
|
561 @SYMTestActions 1. Open the compressed input file, which was compressed using EZlib, |
|
562 for reading and create a decompressed output file for writing |
|
563 2. Create an inflate stream and initialise it using inflateInit2(). |
|
564 3. Inflate the input using inflate(), writing the inflated data |
|
565 to the decompressed output file. |
|
566 4. Cleanup the inflate stream and close the compressed input and |
|
567 decompressed output files. |
|
568 5. Open the compressed input file and the decompressed output |
|
569 file for reading. |
|
570 6. Compare the contents of each file using memcmp(). |
|
571 7. Close both the files. |
|
572 8. Cleanup any files created during the test. |
|
573 |
|
574 Note: The test should be repeated for different types of files as |
|
575 well as different size of file e.g.: |
|
576 • TXT |
|
577 • PNG |
|
578 • JAR |
|
579 • JPG |
|
580 • BMP |
|
581 • DOC |
|
582 • GIF |
|
583 • Varying sizes of each input file should be tested starting |
|
584 from a couple of kilobytes up to several megabytes. |
|
585 |
|
586 @SYMTestExpectedResults The input file used for deflating should be identical to the |
|
587 inflated output file. |
|
588 */ |
|
589 bool inflateOldZlibFilesTest() |
|
590 { |
|
591 bool passed = true; |
|
592 |
|
593 cout << endl << "Starting test case inflateOldZlibFilesTest:" << endl; |
|
594 for(int i = 0; i < inflateOldZlibFilesTestDataItems ; i++) |
|
595 { |
|
596 stringstream ss; |
|
597 string testNum; |
|
598 ss << (i + 1); |
|
599 ss >> testNum; |
|
600 |
|
601 cout << "Starting test " << testNum << " - File: " << inflateOldZlibFilesTestFiles[i]; |
|
602 |
|
603 int extBegin = inflateOldZlibFilesTestFiles[i].find_last_of(".", inflateOldZlibFilesTestFiles[i].length()); |
|
604 string fileName = inflateOldZlibFilesTestFiles[i].substr(0, extBegin); |
|
605 string fileExt = inflateOldZlibFilesTestFiles[i].substr(extBegin + 1); |
|
606 |
|
607 string uncompressedFileName(filePath + inflateOldZlibFilesTestFiles[i]); |
|
608 string compressedFileName(filePath + "ezlib_" + fileName + testNum + ".zip"); |
|
609 string decompressedFileName(filePath + "ezlib_" + fileName + testNum + "_decompressed" + "." + fileExt); |
|
610 |
|
611 if(inflateFile(compressedFileName, decompressedFileName, 15) == false) |
|
612 { |
|
613 passed = false; |
|
614 *outputFile << "\t\t<font color=FF0000>FAILED for file: " << compressedFileName << "</font><p />" << endl << endl; |
|
615 cout << " - FAILED" << endl; |
|
616 |
|
617 deleteFile(decompressedFileName); |
|
618 continue; |
|
619 } |
|
620 |
|
621 if(doFilesMatch(uncompressedFileName, decompressedFileName) == false) |
|
622 { |
|
623 passed = false; |
|
624 *outputFile << "\t\t<font color=FF0000>FAILED for file: " << compressedFileName << "</font><p />" << endl << endl; |
|
625 cout << " - FAILED" << endl; |
|
626 |
|
627 deleteFile(decompressedFileName); |
|
628 continue; |
|
629 } |
|
630 |
|
631 totalPassed++; |
|
632 *outputFile << "\t\t<font color=00AF00>PASSED for file: " << compressedFileName << "</font><p />" << endl << endl; |
|
633 cout << " - PASSED" << endl; |
|
634 |
|
635 deleteFile(decompressedFileName); |
|
636 } |
|
637 cout << "Finished test case inflateOldZlibFilesTest." << endl; |
|
638 |
|
639 return passed; |
|
640 } |
|
641 |
|
642 int main() |
|
643 { |
|
644 if(openOutputFile("basicfunctest")) |
|
645 { |
|
646 *outputFile << "\t\t<b>START TEST deflateInflateTest()</b><br />" << endl; |
|
647 if(deflateInflateTest() == false) |
|
648 { |
|
649 *outputFile << "\t\t<font color=FF0000>deflateInflateTest() FAILED!</font><br />" << endl; |
|
650 } |
|
651 else |
|
652 { |
|
653 *outputFile << "\t\t<font color=00AF00>deflateInflateTest() PASSED!</font><br />" << endl; |
|
654 } |
|
655 *outputFile << "\t\t<b>END TEST deflateInflateTest()</b><p />" << endl << endl;; |
|
656 |
|
657 *outputFile << "\t\t<b>START TEST inflateOldZlibFilesTest()</b><br />" << endl; |
|
658 if(inflateOldZlibFilesTest() == false) |
|
659 { |
|
660 *outputFile << "\t\t<font color=FF0000>inflateOldZlibFilesTest() FAILED!</font><br />" << endl; |
|
661 } |
|
662 else |
|
663 { |
|
664 *outputFile << "\t\t<font color=00AF00>inflateOldZlibFilesTest() PASSED!</font><br />" << endl; |
|
665 } |
|
666 *outputFile << "\t\t<b>END TEST inflateOldZlibFilesTest()</b><p />" << endl << endl; |
|
667 |
|
668 printTestResults(); |
|
669 |
|
670 closeOutputFile(); |
|
671 } |
|
672 |
|
673 return 0; |
|
674 } |