diff options
| author | Mehmet Samet Duman <yongdohyun@projecttick.org> | 2026-04-02 19:56:09 +0300 |
|---|---|---|
| committer | Mehmet Samet Duman <yongdohyun@projecttick.org> | 2026-04-02 19:56:09 +0300 |
| commit | 7fb132859fda54aa96bc9dd46d302b343eeb5a02 (patch) | |
| tree | b43ae77d7451fb470a260c03349a1caf2846c5e5 /neozip/test/test_deflate_prime.cc | |
| parent | b1e34e861b5d732afe828d58aad2c638135061fd (diff) | |
| parent | c2712b8a345191f6ed79558c089777df94590087 (diff) | |
| download | Project-Tick-7fb132859fda54aa96bc9dd46d302b343eeb5a02.tar.gz Project-Tick-7fb132859fda54aa96bc9dd46d302b343eeb5a02.zip | |
Add 'neozip/' from commit 'c2712b8a345191f6ed79558c089777df94590087'
git-subtree-dir: neozip
git-subtree-mainline: b1e34e861b5d732afe828d58aad2c638135061fd
git-subtree-split: c2712b8a345191f6ed79558c089777df94590087
Diffstat (limited to 'neozip/test/test_deflate_prime.cc')
| -rw-r--r-- | neozip/test/test_deflate_prime.cc | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/neozip/test/test_deflate_prime.cc b/neozip/test/test_deflate_prime.cc new file mode 100644 index 0000000000..75dcf3177a --- /dev/null +++ b/neozip/test/test_deflate_prime.cc @@ -0,0 +1,91 @@ +/* test_deflate_prime.cc - Test deflatePrime() wrapping gzip around deflate stream */ + +#include "zbuild.h" +#ifdef ZLIB_COMPAT +# include "zlib.h" +#else +# include "zlib-ng.h" +#endif + +#include <stdio.h> +#include <stdint.h> +#include <stdlib.h> +#include <string.h> + +#include "test_shared_ng.h" + +#include <gtest/gtest.h> + +TEST(deflate, prime) { + PREFIX3(stream) c_stream, d_stream; + uint8_t compr[128], uncompr[128]; + z_size_t compr_len = sizeof(compr), uncompr_len = sizeof(uncompr); + uint32_t crc = 0; + int err; + + memset(&c_stream, 0, sizeof(c_stream)); + memset(&d_stream, 0, sizeof(d_stream)); + + /* Raw deflate windowBits is -15 */ + err = PREFIX(deflateInit2)(&c_stream, Z_DEFAULT_COMPRESSION, Z_DEFLATED, -MAX_WBITS, 8, Z_DEFAULT_STRATEGY); + EXPECT_EQ(err, Z_OK); + + /* Gzip magic number */ + err = PREFIX(deflatePrime)(&c_stream, 16, 0x8b1f); + EXPECT_EQ(err, Z_OK); + /* Gzip compression method (deflate) */ + err = PREFIX(deflatePrime)(&c_stream, 8, 0x08); + EXPECT_EQ(err, Z_OK); + /* Gzip flags (one byte, using two odd bit calls) */ + err = PREFIX(deflatePrime)(&c_stream, 3, 0x0); + EXPECT_EQ(err, Z_OK); + err = PREFIX(deflatePrime)(&c_stream, 5, 0x0); + EXPECT_EQ(err, Z_OK); + /* Gzip modified time */ + err = deflate_prime_32(&c_stream, 0x0); + EXPECT_EQ(err, Z_OK); + /* Gzip extra flags */ + err = PREFIX(deflatePrime)(&c_stream, 8, 0x0); + EXPECT_EQ(err, Z_OK); + /* Gzip operating system */ + err = PREFIX(deflatePrime)(&c_stream, 8, 255); + EXPECT_EQ(err, Z_OK); + + c_stream.next_in = (z_const unsigned char *)hello; + c_stream.avail_in = (uint32_t)hello_len; + c_stream.next_out = compr; + c_stream.avail_out = (uint32_t)compr_len; + + err = PREFIX(deflate)(&c_stream, Z_FINISH); + EXPECT_EQ(err, Z_STREAM_END); + + /* Gzip uncompressed data crc32 */ + crc = PREFIX(crc32)(0, (const uint8_t *)hello, (uint32_t)hello_len); + err = deflate_prime_32(&c_stream, crc); + EXPECT_EQ(err, Z_OK); + /* Gzip uncompressed data length */ + err = deflate_prime_32(&c_stream, (uint32_t)hello_len); + EXPECT_EQ(err, Z_OK); + + err = PREFIX(deflateEnd)(&c_stream); + EXPECT_EQ(err, Z_OK); + + d_stream.next_in = compr; + d_stream.avail_in = (uint32_t)c_stream.total_out; + d_stream.next_out = uncompr; + d_stream.avail_out = (uint32_t)uncompr_len; + d_stream.total_in = 0; + d_stream.total_out = 0; + + /* Inflate with gzip header */ + err = PREFIX(inflateInit2)(&d_stream, MAX_WBITS + 32); + EXPECT_EQ(err, Z_OK); + + err = PREFIX(inflate)(&d_stream, Z_FINISH); + EXPECT_EQ(err, Z_BUF_ERROR); + + err = PREFIX(inflateEnd)(&d_stream); + EXPECT_EQ(err, Z_OK); + + EXPECT_STREQ((char *)uncompr, hello); +} |
