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_small_window.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_small_window.cc')
| -rw-r--r-- | neozip/test/test_small_window.cc | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/neozip/test/test_small_window.cc b/neozip/test/test_small_window.cc new file mode 100644 index 0000000000..e351efac0d --- /dev/null +++ b/neozip/test/test_small_window.cc @@ -0,0 +1,67 @@ +/* test_small_window.cc - Test deflate() and inflate() with a small window and a preset dictionary */ + +#include "zbuild.h" +#ifdef ZLIB_COMPAT +# include "zlib.h" +#else +# include "zlib-ng.h" +#endif + +#include <gtest/gtest.h> + +TEST(small_window, basic) { + PREFIX3(stream) stream; + int err; + unsigned char plain[128]; + unsigned char dictionary1[(1 << 9) - sizeof(plain) / 2]; + size_t i; + unsigned char compr[sizeof(plain)]; + unsigned int compr_len; + unsigned char plain_again[sizeof(plain)]; + + memset(&stream, 0, sizeof(stream)); + err = PREFIX(deflateInit2)(&stream, Z_BEST_COMPRESSION, Z_DEFLATED, -9, 8, Z_DEFAULT_STRATEGY); + EXPECT_EQ(err, Z_OK); + + /* Use a large dictionary that is loaded in two parts */ + memset(dictionary1, 'a', sizeof(dictionary1)); + err = PREFIX(deflateSetDictionary)(&stream, dictionary1, (unsigned int)sizeof(dictionary1)); + EXPECT_EQ(err, Z_OK); + for (i = 0; i < sizeof(plain); i++) + plain[i] = (unsigned char)i; + err = PREFIX(deflateSetDictionary)(&stream, plain, (unsigned int)sizeof(plain)); + EXPECT_EQ(err, Z_OK); + + stream.next_in = plain; + stream.avail_in = (uint32_t)sizeof(plain); + stream.next_out = compr; + stream.avail_out = (uint32_t)sizeof(compr); + err = PREFIX(deflate)(&stream, Z_FINISH); + EXPECT_EQ(err, Z_STREAM_END); + compr_len = sizeof(compr) - stream.avail_out; + + err = PREFIX(deflateEnd)(&stream); + EXPECT_EQ(err, Z_OK); + + memset(&stream, 0, sizeof(stream)); + err = PREFIX(inflateInit2)(&stream, -9); + EXPECT_EQ(err, Z_OK); + + err = PREFIX(inflateSetDictionary)(&stream, dictionary1, (unsigned int)sizeof(dictionary1)); + EXPECT_EQ(err, Z_OK); + err = PREFIX(inflateSetDictionary)(&stream, plain, (unsigned int)sizeof(plain)); + EXPECT_EQ(err, Z_OK); + + stream.next_in = compr; + stream.avail_in = compr_len; + stream.next_out = plain_again; + stream.avail_out = (unsigned int)sizeof(plain_again); + + err = PREFIX(inflate)(&stream, Z_NO_FLUSH); + EXPECT_EQ(err, Z_STREAM_END); + + err = PREFIX(inflateEnd)(&stream); + EXPECT_EQ(err, Z_OK); + + EXPECT_TRUE(memcmp(plain_again, plain, sizeof(plain)) == 0); +} |
