sl@0: // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: using namespace std; sl@0: sl@0: const unsigned int bufferSize = 1024; sl@0: const string filePath = "..\\..\\ezlib2_testdata\\"; sl@0: sl@0: /* sl@0: * deflateInflateTest() constants sl@0: */ sl@0: const int deflateInflateTestDataItems = 24; sl@0: const string deflateInflateTestFiles[deflateInflateTestDataItems] = {"GifImage.gif", "BigSize.txt", "BitmapImage.bmp", sl@0: "BigSize.txt", "JpegImage.jpg", "BigSize.txt", sl@0: "SmallSize.txt", "BigSize.txt", "HolyMoley.jar", sl@0: "BigSize.txt", "ExifHeadFile.png", "BigSize.txt", sl@0: "GifImage.gif", "BigSize.doc", "BitmapImage.bmp", sl@0: "BigSize.doc", "JpegImage.jpg", "BigSize.doc", sl@0: "SmallSize.txt", "BigSize.doc", "HolyMoley.jar", sl@0: "BigSize.doc", "ExifHeadFile.png", "BigSize.doc"}; sl@0: sl@0: const int deflateInflateTestLevel[deflateInflateTestDataItems] = {Z_DEFAULT_COMPRESSION, Z_NO_COMPRESSION, Z_BEST_COMPRESSION, sl@0: Z_DEFAULT_COMPRESSION, Z_NO_COMPRESSION, Z_BEST_COMPRESSION, sl@0: Z_BEST_COMPRESSION, Z_DEFAULT_COMPRESSION, Z_NO_COMPRESSION, sl@0: Z_BEST_COMPRESSION, Z_DEFAULT_COMPRESSION, Z_NO_COMPRESSION, sl@0: Z_NO_COMPRESSION, Z_BEST_COMPRESSION, Z_DEFAULT_COMPRESSION, sl@0: Z_NO_COMPRESSION, Z_BEST_COMPRESSION, Z_DEFAULT_COMPRESSION, sl@0: Z_BEST_SPEED, Z_BEST_SPEED, Z_BEST_SPEED, sl@0: Z_BEST_SPEED, Z_BEST_SPEED, Z_BEST_SPEED}; sl@0: sl@0: const int deflateInflateTestWindowBits[deflateInflateTestDataItems] = {8, MAX_WBITS, 8, sl@0: MAX_WBITS, 8, MAX_WBITS, sl@0: 8, 8, MAX_WBITS, sl@0: MAX_WBITS, MAX_WBITS, 8, sl@0: MAX_WBITS, 8, 8, sl@0: 8, MAX_WBITS, MAX_WBITS, sl@0: 8, MAX_WBITS, 8, sl@0: MAX_WBITS, MAX_WBITS, 8}; sl@0: sl@0: const int deflateInflateTestMemLevel[deflateInflateTestDataItems] = {1, 1, 1, sl@0: 1, 1, 1, sl@0: MAX_MEM_LEVEL, MAX_MEM_LEVEL, MAX_MEM_LEVEL, sl@0: MAX_MEM_LEVEL, MAX_MEM_LEVEL, MAX_MEM_LEVEL, sl@0: 8, 8, 8, sl@0: 8, 8, 8, sl@0: 1, MAX_MEM_LEVEL, 8, sl@0: 1, MAX_MEM_LEVEL, 8}; sl@0: sl@0: const int deflateInflateTestStrategy[deflateInflateTestDataItems] = {Z_DEFAULT_STRATEGY, Z_DEFAULT_STRATEGY, Z_FILTERED, sl@0: Z_FILTERED, Z_HUFFMAN_ONLY, Z_HUFFMAN_ONLY, sl@0: Z_DEFAULT_STRATEGY, Z_DEFAULT_STRATEGY, Z_FILTERED, sl@0: Z_FILTERED, Z_HUFFMAN_ONLY, Z_HUFFMAN_ONLY, sl@0: Z_DEFAULT_STRATEGY, Z_DEFAULT_STRATEGY, Z_FILTERED, sl@0: Z_FILTERED, Z_HUFFMAN_ONLY, Z_HUFFMAN_ONLY, sl@0: Z_DEFAULT_STRATEGY, Z_DEFAULT_STRATEGY, Z_FILTERED, sl@0: Z_FILTERED, Z_HUFFMAN_ONLY, Z_HUFFMAN_ONLY}; sl@0: sl@0: /* sl@0: * inflateOldZlibFilesTest() constants sl@0: */ sl@0: const int inflateOldZlibFilesTestDataItems = 24; sl@0: const string inflateOldZlibFilesTestFiles[inflateOldZlibFilesTestDataItems] = {"GifImage.gif", "BigSize.txt", "BitmapImage.bmp", sl@0: "BigSize.txt", "JpegImage.jpg", "BigSize.txt", sl@0: "SmallSize.txt", "BigSize.txt", "HolyMoley.jar", sl@0: "BigSize.txt", "ExifHeadFile.png", "BigSize.txt", sl@0: "GifImage.gif", "BigSize.doc", "BitmapImage.bmp", sl@0: "BigSize.doc", "JpegImage.jpg", "BigSize.doc", sl@0: "SmallSize.txt", "BigSize.doc", "HolyMoley.jar", sl@0: "BigSize.doc", "ExifHeadFile.png", "BigSize.doc"}; sl@0: sl@0: /* sl@0: * Global variables sl@0: */ sl@0: ofstream *outputFile = NULL; sl@0: int totalPassed = 0; sl@0: sl@0: /* sl@0: * HELPER FUNCTION DECLARATIONS sl@0: */ sl@0: void closeOutputFile(); sl@0: void deleteFile(const string fileLocation); sl@0: int deflateCompress(z_stream &aStream, ifstream &input, ofstream &output); sl@0: bool deflateFile(const string &aInputFileName, const string &aOutputFileName, int aLevel, int aMethod, int aWindowBits, int aMemLevel, int aStrategy); sl@0: bool doFilesMatch(const string &aFileName1, const string &aFileName2); sl@0: unsigned int getFileLength(ifstream &file); sl@0: int inflateDecompress(z_stream &aStream, ifstream &input, ofstream &output); sl@0: bool inflateFile(const string &aInputFileName, const string &aOutputFileName, int aWindowBits = 15); sl@0: bool openOutputFile(const string &aOutputFileName); sl@0: void printTestResults(); sl@0: sl@0: /* sl@0: * TEST FUNCTION DECLARATIONS sl@0: */ sl@0: bool deflateInflateTest(); sl@0: bool inflateOldZlibFilesTest(); sl@0: sl@0: sl@0: /* sl@0: * Closes the results output file and frees the memory. sl@0: */ sl@0: void closeOutputFile() sl@0: { sl@0: *outputFile << "\t" << endl; sl@0: *outputFile << "" << endl; sl@0: outputFile->close(); sl@0: sl@0: delete outputFile; sl@0: } sl@0: sl@0: void deleteFile(const string fileLocation) sl@0: { sl@0: int err = remove(fileLocation.c_str()); sl@0: if(err != 0) sl@0: { sl@0: *outputFile << "\t\t" << err << " - Error deleting file: " << fileLocation << "
" << endl; sl@0: cout << "Error deleting file: " << fileLocation << endl; sl@0: } sl@0: } sl@0: sl@0: /* sl@0: * Compresses data using the deflate function. sl@0: */ sl@0: int deflateCompress(z_stream &aStream, ifstream &input, ofstream &output) sl@0: { sl@0: int err = Z_OK; sl@0: int flush = Z_NO_FLUSH; sl@0: unsigned char in[bufferSize]; sl@0: unsigned char out[bufferSize]; sl@0: unsigned int fileSize = getFileLength(input); sl@0: sl@0: do sl@0: { sl@0: input.read(reinterpret_cast(in), bufferSize); sl@0: sl@0: aStream.avail_in = ((aStream.total_in + bufferSize) > fileSize) ? fileSize - aStream.total_in : bufferSize; sl@0: aStream.next_in = in; sl@0: sl@0: flush = input.eof() ? Z_FINISH : Z_NO_FLUSH; sl@0: sl@0: // Call deflate() on input until output buffer not full sl@0: // Finish compression if all of input buffer has been read in sl@0: do sl@0: { sl@0: aStream.avail_out = bufferSize; sl@0: aStream.next_out = out; sl@0: sl@0: err = deflate(&aStream, flush); sl@0: if(err != Z_OK && err != Z_STREAM_END) sl@0: { sl@0: return err; sl@0: } sl@0: output.write(reinterpret_cast(out), bufferSize - aStream.avail_out); sl@0: sl@0: } while(aStream.avail_out == 0 && err == Z_OK); sl@0: } while(err != Z_STREAM_END); sl@0: sl@0: return Z_OK; sl@0: } sl@0: sl@0: /* sl@0: * Reads in the data from the input file, compresses it and creates a new output file for the compressed data sl@0: */ sl@0: bool deflateFile(const string &aInputFileName, const string &aOutputFileName, int aLevel, int aMethod, int aWindowBits, int aMemLevel, int aStrategy) sl@0: { sl@0: int err = Z_OK; sl@0: sl@0: ifstream input(aInputFileName.c_str(), ios::in | ios::binary); sl@0: ofstream output(aOutputFileName.c_str(), ios::out | ios::trunc | ios::binary); sl@0: z_stream stream; sl@0: sl@0: if(input.is_open() && output.is_open()) sl@0: { sl@0: stream.zalloc = Z_NULL; sl@0: stream.zfree = Z_NULL; sl@0: stream.opaque = Z_NULL; sl@0: sl@0: deflateInit2(&stream, aLevel, aMethod, aWindowBits, aMemLevel, aStrategy); sl@0: err = deflateCompress(stream, input, output); sl@0: deflateEnd(&stream); sl@0: sl@0: if(err != Z_OK) sl@0: { sl@0: *outputFile << "\t\t" << err << " - Error deflating!
" << endl; sl@0: output.close(); sl@0: input.close(); sl@0: return false; sl@0: } sl@0: } sl@0: else sl@0: { sl@0: if(!input.is_open()) sl@0: { sl@0: *outputFile << "\t\tDeflate could not complete due to not being able to open the input file!
" << endl; sl@0: } sl@0: else sl@0: { sl@0: input.close(); sl@0: } sl@0: sl@0: if(!output.is_open()) sl@0: { sl@0: *outputFile << "\t\tDeflate could not complete due to not being able to open the output file!
" << endl; sl@0: } sl@0: else sl@0: { sl@0: output.close(); sl@0: } sl@0: sl@0: return false; sl@0: } sl@0: sl@0: input.close(); sl@0: output.close(); sl@0: sl@0: *outputFile << "\t\tDeflate complete!
" << endl; sl@0: return true; sl@0: } sl@0: sl@0: /* sl@0: * Checks that the two files are identical sl@0: */ sl@0: bool doFilesMatch(const string &aFileName1, const string &aFileName2) sl@0: { sl@0: ifstream file1(aFileName1.c_str(), ios::in | ios::binary); sl@0: ifstream file2(aFileName2.c_str(), ios::in | ios::binary); sl@0: sl@0: if(file1.is_open() && file2.is_open()) sl@0: { sl@0: int file1Size = getFileLength(file1); sl@0: int file2Size = getFileLength(file2); sl@0: sl@0: if(file1Size != file2Size) sl@0: { sl@0: *outputFile << "\t\t" << aFileName1 << " is not the same as " << aFileName2 << " because they have different file sizes!
" << endl; sl@0: return false; sl@0: } sl@0: else sl@0: { sl@0: char fileBuffer1[bufferSize]; sl@0: char fileBuffer2[bufferSize]; sl@0: sl@0: for(int totalSpaceProvided = bufferSize; !file1.eof(); totalSpaceProvided += bufferSize) sl@0: { sl@0: file1.read(fileBuffer1, bufferSize); sl@0: file2.read(fileBuffer2, bufferSize); sl@0: sl@0: int read = (totalSpaceProvided > file1Size) ? bufferSize - (totalSpaceProvided - file1Size) : bufferSize; sl@0: if(memcmp(fileBuffer1, fileBuffer2, read) != 0) sl@0: { sl@0: *outputFile << "\t\t" << aFileName1 << " is not the same as " << aFileName2 << "
" << endl; sl@0: return false; sl@0: } sl@0: } sl@0: } sl@0: } sl@0: else sl@0: { sl@0: if(!file1.is_open()) sl@0: { sl@0: *outputFile << "\t\tCould not check if files matched because " << aFileName1 << " could not be opened!
" << endl; sl@0: } sl@0: else sl@0: { sl@0: file1.close(); sl@0: } sl@0: sl@0: if(!file2.is_open()) sl@0: { sl@0: *outputFile << "\t\tCould not check if files matched because " << aFileName2 << " could not be opened!
" << endl; sl@0: } sl@0: else sl@0: { sl@0: file2.close(); sl@0: } sl@0: sl@0: return false; sl@0: } sl@0: sl@0: file1.close(); sl@0: file2.close(); sl@0: sl@0: return true; sl@0: } sl@0: sl@0: /* sl@0: * Returns a files size in bytes sl@0: */ sl@0: unsigned int getFileLength(ifstream &file) sl@0: { sl@0: file.seekg (0, ios::end); sl@0: unsigned int fileSize = file.tellg(); sl@0: file.seekg (0, ios::beg); sl@0: sl@0: return fileSize; sl@0: } sl@0: sl@0: /* sl@0: * Decompresses data using the inflate function. sl@0: */ sl@0: int inflateDecompress(z_stream &aStream, ifstream &input, ofstream &output) sl@0: { sl@0: int err = Z_OK; sl@0: unsigned char in[bufferSize]; sl@0: unsigned char out[bufferSize]; sl@0: unsigned int fileSize = getFileLength(input); sl@0: sl@0: // Keep providing input data and output space for deflate() sl@0: do sl@0: { sl@0: input.read(reinterpret_cast(in), bufferSize); sl@0: sl@0: aStream.avail_in = ((aStream.total_in + bufferSize) > fileSize) ? fileSize - aStream.total_in : bufferSize; sl@0: aStream.next_in = in; sl@0: sl@0: // Call inflate() on input until output buffer not full sl@0: // Finish compression if all of input buffer has been read in sl@0: do sl@0: { sl@0: aStream.avail_out = bufferSize; sl@0: aStream.next_out = out; sl@0: sl@0: err = inflate(&aStream, Z_NO_FLUSH); sl@0: if(err != Z_OK && err != Z_STREAM_END && err != Z_BUF_ERROR) sl@0: { sl@0: return err; sl@0: } sl@0: output.write(reinterpret_cast(out), bufferSize - aStream.avail_out); sl@0: sl@0: } while(aStream.avail_out == 0); sl@0: } while(err != Z_STREAM_END); sl@0: sl@0: return Z_OK; sl@0: } sl@0: sl@0: /* sl@0: * Reads in the data from the input file, decompresses it and creates a new output file for the decompressed data sl@0: * sl@0: * NOTE: Inflate fails when windowBits is set to 8. This is because deflateInit2() changes windowBits from 8 to 9 sl@0: * due to an error in zlib. However, inflateInit2() does not make the same change and this results in the sl@0: * inflate failing with a Z_DATA_ERROR. sl@0: */ sl@0: bool inflateFile(const string &aInputFileName, const string &aOutputFileName, int aWindowBits) sl@0: { sl@0: int err = Z_OK; sl@0: sl@0: ifstream input(aInputFileName.c_str(), ios::in | ios::binary); sl@0: ofstream output(aOutputFileName.c_str(), ios::out | ios::binary | ios::trunc); sl@0: z_stream stream; sl@0: sl@0: if(input.is_open() && output.is_open()) sl@0: { sl@0: stream.zalloc = Z_NULL; sl@0: stream.zfree = Z_NULL; sl@0: stream.opaque = Z_NULL; sl@0: sl@0: inflateInit2(&stream, aWindowBits); sl@0: err = inflateDecompress(stream, input, output); sl@0: inflateEnd(&stream); sl@0: sl@0: if(err != Z_OK) sl@0: { sl@0: *outputFile << "\t\t" << err << " - Error inflating!
" << endl; sl@0: output.close(); sl@0: input.close(); sl@0: return false; sl@0: } sl@0: } sl@0: else sl@0: { sl@0: if(!input.is_open()) sl@0: { sl@0: *outputFile << "\t\tInflate could not complete due to not being able to open the input file!
" << endl; sl@0: } sl@0: else sl@0: { sl@0: input.close(); sl@0: } sl@0: sl@0: if(!output.is_open()) sl@0: { sl@0: *outputFile << "\t\tInflate could not complete due to not being able to open the output file!
" << endl; sl@0: } sl@0: else sl@0: { sl@0: output.close(); sl@0: } sl@0: sl@0: return false; sl@0: } sl@0: sl@0: output.close(); sl@0: input.close(); sl@0: sl@0: *outputFile << "\t\tInflate complete!
" << endl; sl@0: return true; sl@0: } sl@0: sl@0: /* sl@0: * Creates and opens the results output file. sl@0: */ sl@0: bool openOutputFile(const string &aOutputFileName) sl@0: { sl@0: outputFile = new ofstream((aOutputFileName + ".html").c_str(), ios::out | ios::trunc); sl@0: sl@0: if(outputFile != NULL) sl@0: { sl@0: *outputFile << "" << endl; sl@0: *outputFile << "\t" << endl; sl@0: sl@0: return true; sl@0: } sl@0: sl@0: return false; sl@0: } sl@0: sl@0: /* sl@0: * Outputs the test results to the results output file. sl@0: */ sl@0: void printTestResults() sl@0: { sl@0: int totalFailed = deflateInflateTestDataItems + inflateOldZlibFilesTestDataItems - totalPassed; sl@0: sl@0: *outputFile << "\t\tTEST RESULTS:
" << endl; sl@0: *outputFile << "\t\tPassed = " << totalPassed << "
" << endl; sl@0: *outputFile << "\t\tFailed = " << totalFailed << "
" << endl; sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-EZLIB2-CT-4312 sl@0: @SYMTestCaseDesc Check files can be deflated and inflated. sl@0: @SYMTestPriority High sl@0: @SYMTestActions 1. Open the input file for reading and create a compressed output sl@0: file for writing. sl@0: 2. Create a deflate stream and initialise it using deflateInit2() sl@0: passing it the specified compression parameters. sl@0: 3. Deflate the input using deflate(), writing the deflated data sl@0: to the compressed output file. sl@0: 4. Cleanup the deflate stream and close the input and compressed sl@0: output files. sl@0: 5. Open the compressed file for reading and create a decompressed sl@0: output file for writing sl@0: 6. Create an inflate stream and initialise it using inflateInit2(). sl@0: 7. Inflate the input using inflate(), writing the inflated data to sl@0: the decompressed output file. sl@0: 8. Cleanup the inflate stream and close the compressed input and sl@0: decompressed output files. sl@0: 9. Open the original file (that was compressed) and the sl@0: decompressed file for reading. sl@0: 10. Compare the contents of each file using memcmp(). sl@0: 11. Close both the files. sl@0: 12. Cleanup any files created during the test. sl@0: sl@0: Note: The test should be repeated for different types of input sl@0: files as well as different size of input file e.g.: sl@0: • TXT sl@0: • PNG sl@0: • JAR sl@0: • JPG sl@0: • BMP sl@0: • DOC sl@0: • GIF sl@0: • Varying sizes of each input file should be tested starting sl@0: from a couple of kilobytes up to several megabytes. sl@0: sl@0: And with compression parameters as: sl@0: • Z_DEFAULT_COMPRESSION, Z_NO_COMPRESSION, Z_BEST_COMPRESSION sl@0: and Z_BEST_SPEED for level sl@0: • 8 and MAX_WBITS for windowBits sl@0: • 1, 8 (default memory level) and MAX_MEM_LEVEL for memLevel sl@0: • Z_DEFAULT_STRATEGY, Z_FILTERED and Z_HUFFMAN_ONLY for strategy sl@0: @SYMTestExpectedResults The input file used for deflating should be identical to the sl@0: inflated output file. sl@0: */ sl@0: bool deflateInflateTest() sl@0: { sl@0: bool passed = true; sl@0: sl@0: cout << endl << "Starting test case deflateInflateTest:" << endl; sl@0: for(int i = 0; i < deflateInflateTestDataItems ; i++) sl@0: { sl@0: stringstream ss; sl@0: string testNum; sl@0: ss << (i + 1); sl@0: ss >> testNum; sl@0: sl@0: cout << "Starting test " << testNum << " - File: " << deflateInflateTestFiles[i]; sl@0: sl@0: int extBegin = deflateInflateTestFiles[i].find_last_of(".", deflateInflateTestFiles[i].length()); sl@0: string fileName = deflateInflateTestFiles[i].substr(0, extBegin); sl@0: string fileExt = deflateInflateTestFiles[i].substr(extBegin + 1); sl@0: sl@0: string uncompressedFileName(filePath + deflateInflateTestFiles[i]); sl@0: string compressedFileName(filePath + fileName + testNum + ".zip"); sl@0: string decompressedFileName(filePath + "ezlib2_" + fileName + testNum + "_decompressed" + "." + fileExt); sl@0: sl@0: if(deflateFile(uncompressedFileName, compressedFileName, deflateInflateTestLevel[i], Z_DEFLATED, deflateInflateTestWindowBits[i], deflateInflateTestMemLevel[i], deflateInflateTestStrategy[i]) == false) sl@0: { sl@0: passed = false; sl@0: *outputFile << "\t\tFAILED for file: " << deflateInflateTestFiles[i] << "

" << endl << endl; sl@0: cout << " - FAILED" << endl; sl@0: continue; sl@0: } sl@0: sl@0: if(inflateFile(compressedFileName, decompressedFileName, deflateInflateTestWindowBits[i]) == false) sl@0: { sl@0: passed = false; sl@0: *outputFile << "\t\tFAILED for file: " << uncompressedFileName << "

" << endl << endl; sl@0: cout << " - FAILED" << endl; sl@0: sl@0: deleteFile(compressedFileName); sl@0: deleteFile(decompressedFileName); sl@0: continue; sl@0: } sl@0: sl@0: if(doFilesMatch(uncompressedFileName, decompressedFileName) == false) sl@0: { sl@0: passed = false; sl@0: *outputFile << "\t\tFAILED for file: " << uncompressedFileName << "

" << endl << endl; sl@0: cout << " - FAILED" << endl; sl@0: sl@0: deleteFile(compressedFileName); sl@0: deleteFile(decompressedFileName); sl@0: continue; sl@0: } sl@0: sl@0: totalPassed++; sl@0: *outputFile << "\t\tPASSED for file: " << uncompressedFileName << "

" << endl << endl; sl@0: cout << " - PASSED" << endl; sl@0: sl@0: deleteFile(compressedFileName); sl@0: deleteFile(decompressedFileName); sl@0: } sl@0: cout << "Finished test case case deflateInflateTest." << endl; sl@0: sl@0: return passed; sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-EZLIB2-CT-4313 sl@0: @SYMTestCaseDesc Check files deflated with EZlib can be inflated using EZlib2. sl@0: @SYMTestPriority High sl@0: @SYMTestActions 1. Open the compressed input file, which was compressed using EZlib, sl@0: for reading and create a decompressed output file for writing sl@0: 2. Create an inflate stream and initialise it using inflateInit2(). sl@0: 3. Inflate the input using inflate(), writing the inflated data sl@0: to the decompressed output file. sl@0: 4. Cleanup the inflate stream and close the compressed input and sl@0: decompressed output files. sl@0: 5. Open the compressed input file and the decompressed output sl@0: file for reading. sl@0: 6. Compare the contents of each file using memcmp(). sl@0: 7. Close both the files. sl@0: 8. Cleanup any files created during the test. sl@0: sl@0: Note: The test should be repeated for different types of files as sl@0: well as different size of file e.g.: sl@0: • TXT sl@0: • PNG sl@0: • JAR sl@0: • JPG sl@0: • BMP sl@0: • DOC sl@0: • GIF sl@0: • Varying sizes of each input file should be tested starting sl@0: from a couple of kilobytes up to several megabytes. sl@0: sl@0: @SYMTestExpectedResults The input file used for deflating should be identical to the sl@0: inflated output file. sl@0: */ sl@0: bool inflateOldZlibFilesTest() sl@0: { sl@0: bool passed = true; sl@0: sl@0: cout << endl << "Starting test case inflateOldZlibFilesTest:" << endl; sl@0: for(int i = 0; i < inflateOldZlibFilesTestDataItems ; i++) sl@0: { sl@0: stringstream ss; sl@0: string testNum; sl@0: ss << (i + 1); sl@0: ss >> testNum; sl@0: sl@0: cout << "Starting test " << testNum << " - File: " << inflateOldZlibFilesTestFiles[i]; sl@0: sl@0: int extBegin = inflateOldZlibFilesTestFiles[i].find_last_of(".", inflateOldZlibFilesTestFiles[i].length()); sl@0: string fileName = inflateOldZlibFilesTestFiles[i].substr(0, extBegin); sl@0: string fileExt = inflateOldZlibFilesTestFiles[i].substr(extBegin + 1); sl@0: sl@0: string uncompressedFileName(filePath + inflateOldZlibFilesTestFiles[i]); sl@0: string compressedFileName(filePath + "ezlib_" + fileName + testNum + ".zip"); sl@0: string decompressedFileName(filePath + "ezlib_" + fileName + testNum + "_decompressed" + "." + fileExt); sl@0: sl@0: if(inflateFile(compressedFileName, decompressedFileName, 15) == false) sl@0: { sl@0: passed = false; sl@0: *outputFile << "\t\tFAILED for file: " << compressedFileName << "

" << endl << endl; sl@0: cout << " - FAILED" << endl; sl@0: sl@0: deleteFile(decompressedFileName); sl@0: continue; sl@0: } sl@0: sl@0: if(doFilesMatch(uncompressedFileName, decompressedFileName) == false) sl@0: { sl@0: passed = false; sl@0: *outputFile << "\t\tFAILED for file: " << compressedFileName << "

" << endl << endl; sl@0: cout << " - FAILED" << endl; sl@0: sl@0: deleteFile(decompressedFileName); sl@0: continue; sl@0: } sl@0: sl@0: totalPassed++; sl@0: *outputFile << "\t\tPASSED for file: " << compressedFileName << "

" << endl << endl; sl@0: cout << " - PASSED" << endl; sl@0: sl@0: deleteFile(decompressedFileName); sl@0: } sl@0: cout << "Finished test case inflateOldZlibFilesTest." << endl; sl@0: sl@0: return passed; sl@0: } sl@0: sl@0: int main() sl@0: { sl@0: if(openOutputFile("basicfunctest")) sl@0: { sl@0: *outputFile << "\t\tSTART TEST deflateInflateTest()
" << endl; sl@0: if(deflateInflateTest() == false) sl@0: { sl@0: *outputFile << "\t\tdeflateInflateTest() FAILED!
" << endl; sl@0: } sl@0: else sl@0: { sl@0: *outputFile << "\t\tdeflateInflateTest() PASSED!
" << endl; sl@0: } sl@0: *outputFile << "\t\tEND TEST deflateInflateTest()

" << endl << endl;; sl@0: sl@0: *outputFile << "\t\tSTART TEST inflateOldZlibFilesTest()
" << endl; sl@0: if(inflateOldZlibFilesTest() == false) sl@0: { sl@0: *outputFile << "\t\tinflateOldZlibFilesTest() FAILED!
" << endl; sl@0: } sl@0: else sl@0: { sl@0: *outputFile << "\t\tinflateOldZlibFilesTest() PASSED!
" << endl; sl@0: } sl@0: *outputFile << "\t\tEND TEST inflateOldZlibFilesTest()

" << endl << endl; sl@0: sl@0: printTestResults(); sl@0: sl@0: closeOutputFile(); sl@0: } sl@0: sl@0: return 0; sl@0: }