#pragma region CPL License /* Nuclex Native Framework Copyright (C) 2002-2021 Nuclex Development Labs This library is free software; you can redistribute it and/or modify it under the terms of the IBM Common Public License as published by the IBM Corporation; either version 1.0 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the IBM Common Public License for more details. You should have received a copy of the IBM Common Public License along with this library */ #pragma endregion // CPL License // If the library is compiled as a DLL, this ensures symbols are exported #define NUCLEX_STORAGE_SOURCE 1 #if defined(NUCLEX_STORAGE_HAVE_ZPAQ) #include "../../../Source/Compression/ZPaq/ZPaqDecompressor.h" #include namespace { // ------------------------------------------------------------------------------------------- // /// Compressed string used to test the ZPaq decompressor const std::uint8_t compressedString[] = { 0x7a, 0x50, 0x51, 0x01, 0x01, 0xc4, 0x00, 0x05, 0x09, 0x00, 0x00, 0x16, 0x01, 0xa0, 0x03, 0x05, 0x08, 0x0d, 0x01, 0x08, 0x10, 0x02, 0x08, 0x12, 0x03, 0x08, 0x13, 0x04, 0x08, 0x13, 0x05, 0x08, 0x14, 0x06, 0x04, 0x16, 0x18, 0x03, 0x11, 0x08, 0x13, 0x09, 0x03, 0x0d, 0x03, 0x0d, 0x03, 0x0d, 0x03, 0x0e, 0x07, 0x10, 0x00, 0x0f, 0x18, 0xff, 0x07, 0x08, 0x00, 0x10, 0x0a, 0xff, 0x06, 0x00, 0x0f, 0x10, 0x18, 0x00, 0x09, 0x08, 0x11, 0x20, 0xff, 0x06, 0x08, 0x11, 0x12, 0x10, 0xff, 0x09, 0x10, 0x13, 0x20, 0xff, 0x06, 0x00, 0x13, 0x14, 0x10, 0x00, 0x00, 0x11, 0x68, 0x4a, 0x04, 0x5f, 0x02, 0x3b, 0x70, 0x0a, 0x19, 0x3b, 0x70, 0x0a, 0x19, 0x3b, 0x70, 0x0a, 0x19, 0x3b, 0x70, 0x0a, 0x19, 0x3b, 0x70, 0x0a, 0x19, 0x3b, 0x0a, 0x3b, 0x70, 0x0a, 0x19, 0x3b, 0x70, 0x0a, 0x19, 0x45, 0xb7, 0x20, 0xef, 0x40, 0x2f, 0x0e, 0xe7, 0x5b, 0x2f, 0x0a, 0x19, 0x3c, 0x1a, 0x30, 0x86, 0x97, 0x14, 0x70, 0x3f, 0x09, 0x46, 0xdf, 0x00, 0x27, 0x03, 0x19, 0x70, 0x1a, 0x34, 0x19, 0x19, 0x4a, 0x0a, 0x04, 0x3b, 0x70, 0x19, 0x0a, 0x04, 0x3b, 0x70, 0x19, 0x0a, 0x04, 0x3b, 0x70, 0x19, 0x41, 0x8f, 0xd4, 0x48, 0x04, 0x3b, 0x70, 0x08, 0x8f, 0xd8, 0x08, 0x44, 0xaf, 0x3c, 0x3c, 0x19, 0x45, 0xcf, 0x09, 0x70, 0x19, 0x19, 0x19, 0x19, 0x19, 0x70, 0x38, 0x00, 0x01, 0x00, 0x00, 0x00, 0xff, 0xac, 0x38, 0xe3, 0x53, 0xeb, 0xff, 0x51, 0x17, 0x4f, 0x0e, 0x78, 0x5a, 0xab, 0x18, 0x86, 0x62, 0x13, 0x12, 0xc2, 0xca, 0x1b, 0x18, 0x7e, 0x40, 0x02, 0xa7, 0x4b, 0x24, 0xe9, 0x23, 0x20, 0x9c, 0x3b, 0x75, 0x02, 0xb0, 0xbf, 0x94, 0x91, 0x4b, 0x97, 0xcf, 0x86, 0x5f, 0x10, 0x30, 0x57, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xff }; // ------------------------------------------------------------------------------------------- // /// Text that should result went decompressing the test data const char uncompressedString[] = u8"Hello World, this is text that has been ZPaq-compressed"; // ------------------------------------------------------------------------------------------- // } namespace Nuclex { namespace Storage { namespace Compression { namespace ZPaq { // ------------------------------------------------------------------------------------------- // TEST(ZPaqDecompressorTest, CanBeCreatedAndDestroyed) { EXPECT_NO_THROW( ZPaqDecompressor decompressor; (void)decompressor; ); } // ------------------------------------------------------------------------------------------- // TEST(ZPaqDecompressorTest, MemoryChunkCanBeDecompressed) { // Message that will be compressed const std::uint8_t *input = compressedString; // Set up a buffer to hold the compressed data. We assume compression will not // make result in generated output that is more than twice the size of the input data :) std::vector outputBuffer; outputBuffer.resize(sizeof(uncompressedString) * 2); // Now compress the data with the deflate compressor { ZPaqDecompressor decompressor; std::size_t inputByteCount = sizeof(compressedString); std::size_t outputByteCount = outputBuffer.size(); StopReason stopReason = decompressor.Process( input, inputByteCount, &outputBuffer[0], outputByteCount ); EXPECT_EQ(stopReason, StopReason::InputBufferExhausted); std::size_t secondOutputByteCount = outputBuffer.size() - outputByteCount; stopReason = decompressor.Finish(&outputBuffer[outputByteCount], secondOutputByteCount); EXPECT_EQ(stopReason, StopReason::Finished); outputBuffer.resize(outputByteCount + secondOutputByteCount); } ASSERT_EQ(outputBuffer.size(), sizeof(uncompressedString)); for(std::size_t index = 0; index < sizeof(uncompressedString); ++index) { EXPECT_EQ(static_cast(outputBuffer[index]), uncompressedString[index]); } } // ------------------------------------------------------------------------------------------- // }}}} // namespace Nuclex::Storage::Compression::ZPaq #endif // defined(NUCLEX_STORAGE_HAVE_ZPAQ)