From c42890667593eb6fdc20a4d5cd29416405180a15 Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Mon, 19 Sep 2022 10:34:22 +0300 Subject: [PATCH] add bzip2 test --- test/bzip2.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 test/bzip2.cpp diff --git a/test/bzip2.cpp b/test/bzip2.cpp new file mode 100644 index 00000000..9bf74d9d --- /dev/null +++ b/test/bzip2.cpp @@ -0,0 +1,44 @@ +#include +#include + +int main() +{ + constexpr size_t BUFFER_SIZE = 1024; + char reference[BUFFER_SIZE]; + + for (size_t i = 0; i < BUFFER_SIZE; ++i) + { + reference[i] = static_cast(i % 47); + } + + bz_stream stream = {}; + AEDI_EXPECT(BZ2_bzCompressInit(&stream, 1, 0, 0) == BZ_OK); + + char compressed[BUFFER_SIZE] = {}; + + stream.next_in = reference; + stream.avail_in = BUFFER_SIZE; + stream.next_out = compressed; + stream.avail_out = BUFFER_SIZE; + + AEDI_EXPECT(BZ2_bzCompress(&stream, BZ_FINISH) == BZ_STREAM_END); + AEDI_EXPECT(BZ2_bzCompressEnd(&stream) == BZ_OK); + + stream = {}; + + AEDI_EXPECT(BZ2_bzDecompressInit(&stream, 0, 0) == BZ_OK); + + char decompressed[BUFFER_SIZE] = {}; + + stream.next_in = compressed; + stream.avail_in = BUFFER_SIZE; + stream.next_out = decompressed; + stream.avail_out = BUFFER_SIZE; + + AEDI_EXPECT(BZ2_bzDecompress(&stream) == BZ_STREAM_END); + AEDI_EXPECT(BZ2_bzDecompressEnd(&stream) == BZ_OK); + + AEDI_EXPECT(memcmp(reference, decompressed, BUFFER_SIZE) == 0); + + return 0; +}