From fae3cf5b42f9305eecb6dea0281cb1e372c6e98f Mon Sep 17 00:00:00 2001 From: Filip Leonarski Date: Wed, 19 Apr 2023 22:31:38 +0200 Subject: [PATCH] CBORTest: Check content of arrays with/without compression --- tests/CBORTest.cpp | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/tests/CBORTest.cpp b/tests/CBORTest.cpp index 3937338a..59dfa809 100644 --- a/tests/CBORTest.cpp +++ b/tests/CBORTest.cpp @@ -7,6 +7,7 @@ #include "../frame_serialize/JFJochFrameDeserializer.h" #include "../compression/JFJochCompressor.h" #include "stream2.h" +#include "../frame_serialize/CborUtil.h" TEST_CASE("CBORSerialize_Start", "[CBOR]") { JFJochFrameSerializer serializer(8*1024*1024); @@ -471,6 +472,15 @@ TEST_CASE("CBORSerialize_Start_stream2", "[CBOR]") { CHECK(msg2->frame_time == message.frame_time); CHECK(msg2->count_time == message.count_time); + CHECK(msg2->pixel_mask_enabled == message.pixel_mask_enabled); + CHECK(msg2->pixel_mask.len == 1); + CHECK(CmpString(msg2->pixel_mask.ptr[0].channel, "sc0")); + CHECK(msg2->pixel_mask.ptr[0].pixel_mask.dim[0] == 457); + CHECK(msg2->pixel_mask.ptr[0].pixel_mask.dim[1] == 456); + CHECK(msg2->pixel_mask.ptr[0].pixel_mask.array.data.len == 456 * 457 * sizeof(uint32_t)); + CHECK(memcmp(msg2->pixel_mask.ptr[0].pixel_mask.array.data.ptr, message.pixel_mask["sc0"].data(), + 456 * 457 * sizeof(uint32_t)) == 0); + CHECK(msg2->pixel_mask.ptr[0].pixel_mask.array.tag == TagUnsignedInt32BitLE); stream2_free_msg(msg); } @@ -516,10 +526,11 @@ TEST_CASE("CBORSerialize_Image_compressed_stream2", "[CBOR]") { JFJochBitShuffleCompressor compressor(CompressionAlgorithm::BSHUF_LZ4); - compressor.Compress(compressed_test.data(), test); + size_t compressed_size = compressor.Compress(compressed_test.data(), test); + CBORImage image { .data = compressed_test.data(), - .size = 1024 * 512, + .size = compressed_size, .xpixel = 1024, .ypixel = 512, .pixel_depth_bytes = 2, @@ -545,7 +556,15 @@ TEST_CASE("CBORSerialize_Image_compressed_stream2", "[CBOR]") { auto msg2 = (stream2_image_msg *) msg; CHECK(msg2->image_id == message.number); CHECK(msg2->data.len == 1); - + CHECK(CmpString(msg2->data.ptr[0].channel, "default")); + CHECK(msg2->data.ptr[0].data.dim[0] == 512); + CHECK(msg2->data.ptr[0].data.dim[1] == 1024); + CHECK(CmpString(msg2->data.ptr[0].data.array.data.compression.algorithm, "bslz4")); + CHECK(msg2->data.ptr[0].data.array.data.compression.elem_size == 2); + CHECK(msg2->data.ptr[0].data.array.data.compression.orig_size == 1024 * 512 * 2); + REQUIRE(msg2->data.ptr[0].data.array.data.len == compressed_size); + CHECK(memcmp(msg2->data.ptr[0].data.array.data.ptr, compressed_test.data(), compressed_size) == 0); + CHECK(msg2->data.ptr[0].data.array.tag == TagUnsignedInt16BitLE); CHECK(msg2->series_id == message.series_id); CHECK(CmpString(msg2->series_unique_id, message.series_unique_id)); stream2_free_msg(msg); @@ -588,7 +607,11 @@ TEST_CASE("CBORSerialize_Image_uncompressed_stream2", "[CBOR]") { auto msg2 = (stream2_image_msg *) msg; CHECK(msg2->image_id == message.number); CHECK(msg2->data.len == 1); - + CHECK(CmpString(msg2->data.ptr->channel, "default")); + CHECK(msg2->data.ptr[0].data.array.data.compression.algorithm == nullptr); + REQUIRE(msg2->data.ptr[0].data.array.data.len == 512*1024); + CHECK(memcmp(msg2->data.ptr[0].data.array.data.ptr, test.data(), 512*1024) == 0); + CHECK(msg2->data.ptr[0].data.array.tag == TagUnsignedInt8Bit); CHECK(msg2->series_id == message.series_id); CHECK(CmpString(msg2->series_unique_id, message.series_unique_id)); stream2_free_msg(msg);