From 9e5ca2816f9bc33b61588015cc8c9aa36f589765 Mon Sep 17 00:00:00 2001 From: Joshua Scott Date: Tue, 11 Dec 2018 20:33:58 +0000 Subject: [PATCH] test: Add compression tests for SerializerBinary --- src/serialization/SerializerBinary.cpp | 8 ++++---- .../serialization_binary_file_compressed.bin | Bin 0 -> 547 bytes .../serialization_binary_regular_compressed.bin | Bin 0 -> 316 bytes test/src/unit-serialization.cpp | 3 --- 4 files changed, 4 insertions(+), 7 deletions(-) create mode 100644 test/samples/serialization_binary_file_compressed.bin create mode 100644 test/samples/serialization_binary_regular_compressed.bin diff --git a/src/serialization/SerializerBinary.cpp b/src/serialization/SerializerBinary.cpp index 5162a50..a01181d 100644 --- a/src/serialization/SerializerBinary.cpp +++ b/src/serialization/SerializerBinary.cpp @@ -44,12 +44,13 @@ namespace serialization const auto size_bytes = (end_pos - start_pos).as_bytes(); // 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); // Setup compression static const std::size_t bufsize = 1024; - auto *temp_buffer = new uint8_t[bufsize]{0}; + uint8_t temp_buffer[bufsize] {0}; std::vector compressed; z_stream z; z.zalloc = nullptr; @@ -96,7 +97,6 @@ namespace serialization // Cleanup temporary buffers delete[] uncompressed; - delete[] temp_buffer; // Write the compression header 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 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 auto *uncompressed = new BitBuffer(uncompressed_size); diff --git a/test/samples/serialization_binary_file_compressed.bin b/test/samples/serialization_binary_file_compressed.bin new file mode 100644 index 0000000000000000000000000000000000000000..2280edc3ae02894c23696a7ad2c202eb2c7bad12 GIT binary patch literal 547 zcmV+;0^I!x00001$pioZc%1Fi-Ahw(7{KvoZ@Q`TY&vV1=`njTYxZuIy==Bt+N-(B zYG!kely(tpM~Fs5P;^s>hIADM609T2Y&+qh9c3){+B@z~q*PrfXJMALRZcjP84she~*mTx%jG*L}x5{SiA^JL* z(~2DS^MqHQJkm;B&f;stMUFRGh1a8%yUR*dX3ToM<#*;>$OsiO^)^E{GjCcvfrZTP z4}7Bwne&Vv)_yR25*-{$>l|@ClT2sy;dshOj#xzU^K(RrJJ#z)=#H$WLOXb5CBWg~qeeSyNx0vy}hL!x zXu?{oLjcWKj}6#}P1p=om#t{QHnd_pcAyPAu?xGg2SHF=X~$kEY_ffbU_aDO=|CqA z;t&qwi0Td02I|6bbR&urIEhnG+v+sV;4EV3#X0nueTkzV39~nEo9-t5_vYX0jcP>B l_H$hIBX3VcX64T}W;NsHnu)CHNB&jfuWwNG?-$|Xhml2=6bJwS literal 0 HcmV?d00001 diff --git a/test/samples/serialization_binary_regular_compressed.bin b/test/samples/serialization_binary_regular_compressed.bin new file mode 100644 index 0000000000000000000000000000000000000000..b2d8ba9c550c6d0e438917631168986f28a89e35 GIT binary patch literal 316 zcmV-C0mJ?Q*#iIoc%1FgM^ZvT5P;z(=ZuQ^VNRHHL_`#`f{GXsDWPP?gN=9c0IXbi z3y>`Oh?Bf83IKnYbaEddekj6PKaET1Aki|7_aEm+K;{iE5BLCl$KiQK;AL_<@La)`l O{*g~K`tl8Q*F{)8NtBiV literal 0 HcmV?d00001 diff --git a/test/src/unit-serialization.cpp b/test/src/unit-serialization.cpp index 24c4995..738a409 100644 --- a/test/src/unit-serialization.cpp +++ b/test/src/unit-serialization.cpp @@ -488,8 +488,6 @@ TEST_CASE("Serialization tests", "[serialization]") ); test_serializer(test_object, serializer, "_file"); } - /* - TODO: Test compression SECTION("Regular format with compression") { serialization::SerializerBinary serializer( @@ -507,7 +505,6 @@ TEST_CASE("Serialization tests", "[serialization]") ); test_serializer(test_object, serializer, "_file_compressed"); } - */ } // If one of the above sections leaves test_object set, then