test: Add compression tests for SerializerBinary

This commit is contained in:
Joshua Scott 2018-12-11 20:33:58 +00:00
parent 7181c49bfb
commit 9e5ca2816f
4 changed files with 4 additions and 7 deletions

View File

@ -45,11 +45,12 @@ namespace serialization
// Make a copy of the uncompressed data // Make a copy of the uncompressed data
auto *uncompressed = new uint8_t[size_bytes] {0}; auto *uncompressed = new uint8_t[size_bytes] {0};
stream.seek(start_pos);
stream.read_copy(uncompressed, size_bits); stream.read_copy(uncompressed, size_bits);
// Setup compression // Setup compression
static const std::size_t bufsize = 1024; static const std::size_t bufsize = 1024;
auto *temp_buffer = new uint8_t[bufsize]{0}; uint8_t temp_buffer[bufsize] {0};
std::vector<uint8_t> compressed; std::vector<uint8_t> compressed;
z_stream z; z_stream z;
z.zalloc = nullptr; z.zalloc = nullptr;
@ -96,7 +97,6 @@ namespace serialization
// Cleanup temporary buffers // Cleanup temporary buffers
delete[] uncompressed; delete[] uncompressed;
delete[] temp_buffer;
// Write the compression header // Write the compression header
const auto use_compression = compressed.size() < size_bytes; const auto use_compression = compressed.size() < size_bytes;
@ -264,7 +264,7 @@ namespace serialization
{ {
// Create a buffer for the compressed data and read it in // Create a buffer for the compressed data and read it in
BitBuffer compressed(data_available_bytes); BitBuffer compressed(data_available_bytes);
segment_stream.read_copy(compressed.data(), data_available_bytes); segment_stream.read_copy(compressed.data(), data_available_bytes * 8);
// Uncompress the compressed buffer // Uncompress the compressed buffer
auto *uncompressed = new BitBuffer(uncompressed_size); auto *uncompressed = new BitBuffer(uncompressed_size);

Binary file not shown.

View File

@ -488,8 +488,6 @@ TEST_CASE("Serialization tests", "[serialization]")
); );
test_serializer(test_object, serializer, "_file"); test_serializer(test_object, serializer, "_file");
} }
/*
TODO: Test compression
SECTION("Regular format with compression") SECTION("Regular format with compression")
{ {
serialization::SerializerBinary serializer( serialization::SerializerBinary serializer(
@ -507,7 +505,6 @@ TEST_CASE("Serialization tests", "[serialization]")
); );
test_serializer(test_object, serializer, "_file_compressed"); test_serializer(test_object, serializer, "_file_compressed");
} }
*/
} }
// If one of the above sections leaves test_object set, then // If one of the above sections leaves test_object set, then