#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/ZPaqHelper.h" #include namespace Nuclex { namespace Storage { namespace Compression { namespace ZPaq { // ------------------------------------------------------------------------------------------- // TEST(ZPaqHelperTest, WriterCanBeCreatedAndDestroyed) { EXPECT_NO_THROW( SplitBufferWriter writer; (void)writer; ); } // ------------------------------------------------------------------------------------------- // TEST(ZPaqHelperTest, WriterCanTargetBuffer) { std::uint8_t buffer[16]; SplitBufferWriter writer; std::size_t storedByteCount = writer.TargetNewOutputBuffer(buffer, 16); EXPECT_EQ(storedByteCount, 0U); } // ------------------------------------------------------------------------------------------- // TEST(ZPaqHelperTest, WriterFillsTargetBufferFirst) { std::uint8_t buffer[16]; SplitBufferWriter writer; writer.TargetNewOutputBuffer(buffer, 16); char filler[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; writer.write(filler, 12); for(std::size_t index = 0; index < 12; ++index) { EXPECT_EQ(buffer[index], static_cast(filler[index])); } } // ------------------------------------------------------------------------------------------- // TEST(ZPaqHelperTest, WriterAppendsToTargetBuffer) { std::uint8_t buffer[16]; SplitBufferWriter writer; writer.TargetNewOutputBuffer(buffer, 16); char filler[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; writer.write(filler, 5); writer.write(filler, 10); for(std::size_t index = 0; index < 5; ++index) { EXPECT_EQ(buffer[index], static_cast(filler[index])); } for(std::size_t index = 0; index < 10; ++index) { EXPECT_EQ(buffer[index + 5], static_cast(filler[index])); } } // ------------------------------------------------------------------------------------------- // TEST(ZPaqHelperTest, WriterKeepsExcessData) { std::uint8_t buffer[16]; SplitBufferWriter writer; writer.TargetNewOutputBuffer(buffer, 16); char filler[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24 }; writer.write(filler, 22); for(std::size_t index = 0; index < 16; ++index) { EXPECT_EQ(buffer[index], static_cast(filler[index])); } std::size_t storedByteCount = writer.TargetNewOutputBuffer(buffer, 16); EXPECT_EQ(storedByteCount, 6U); for(std::size_t index = 0; index < 6; ++index) { EXPECT_EQ(buffer[index], static_cast(filler[index + 16])); } } // ------------------------------------------------------------------------------------------- // TEST(ZPaqHelperTest, WriterKeepsLotsOfExcessData) { std::uint8_t buffer[16]; SplitBufferWriter writer; writer.TargetNewOutputBuffer(buffer, 16); char filler[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24 }; writer.write(filler, 24); writer.write(filler, 24); for(std::size_t index = 0; index < 16; ++index) { EXPECT_EQ(buffer[index], static_cast(filler[index])); } // First set std::size_t storedByteCount = writer.TargetNewOutputBuffer(buffer, 16); EXPECT_EQ(storedByteCount, 16U); for(std::size_t index = 0; index < 8; ++index) { EXPECT_EQ(buffer[index], static_cast(filler[index + 16])); } for(std::size_t index = 0; index < 8; ++index) { EXPECT_EQ(buffer[index + 8], static_cast(filler[index])); } // Second set storedByteCount = writer.TargetNewOutputBuffer(buffer, 16); EXPECT_EQ(storedByteCount, 16U); for(std::size_t index = 0; index < 16; ++index) { EXPECT_EQ(buffer[index], static_cast(filler[index + 8])); } } // ------------------------------------------------------------------------------------------- // TEST(ZPaqHelperTest, WriterCanSplitOffExcessData) { std::uint8_t buffer[16]; SplitBufferWriter writer; writer.TargetNewOutputBuffer(buffer, 16); char filler[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24 }; writer.write(filler, 8); writer.write(filler, 22); for(std::size_t index = 0; index < 8; ++index) { EXPECT_EQ(buffer[index], static_cast(filler[index])); } for(std::size_t index = 0; index < 8; ++index) { EXPECT_EQ(buffer[index + 8], static_cast(filler[index])); } std::size_t storedByteCount = writer.TargetNewOutputBuffer(buffer, 16); EXPECT_EQ(storedByteCount, 14U); for(std::size_t index = 0; index < 14; ++index) { EXPECT_EQ(buffer[index], static_cast(filler[index + 8])); } } // ------------------------------------------------------------------------------------------- // }}}} // namespace Nuclex::Storage::Compression::ZPaq #endif // defined(NUCLEX_STORAGE_HAVE_ZPAQ)