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_compress_bound.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_compress_bound.cc')
| -rw-r--r-- | neozip/test/test_compress_bound.cc | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/neozip/test/test_compress_bound.cc b/neozip/test/test_compress_bound.cc new file mode 100644 index 0000000000..1acda02fc5 --- /dev/null +++ b/neozip/test/test_compress_bound.cc @@ -0,0 +1,59 @@ +/* test_compress_bound.cc - Test compressBound() with small buffers */ + +#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 <gtest/gtest.h> + +#include "test_shared.h" + +#define MAX_LENGTH (32) + +class compress_bound_variant : public testing::TestWithParam<int32_t> { +public: + void estimate(int32_t level) { + z_size_t estimate_len = 0; + uint8_t *uncompressed = NULL; + uint8_t dest[128]; + int err; + + uncompressed = (uint8_t *)malloc(MAX_LENGTH); + ASSERT_TRUE(uncompressed != NULL); + + /* buffer with values for worst case compression */ + for (int32_t j = 0; j < MAX_LENGTH; j++) { + uncompressed[j] = (uint8_t)j; + } + + for (z_uintmax_t i = 0; i < MAX_LENGTH; i++) { + z_uintmax_t dest_len = sizeof(dest); + + /* calculate actual output length */ + estimate_len = PREFIX(compressBound)(i); + + err = PREFIX(compress2)(dest, &dest_len, uncompressed, i, level); + EXPECT_EQ(err, Z_OK); + EXPECT_GE(estimate_len, dest_len) << + "level: " << level << "\n" << + "length: " << i; + } + + free(uncompressed); + } +}; + +TEST_P(compress_bound_variant, estimate) { + estimate(GetParam()); +} + +INSTANTIATE_TEST_SUITE_P(compress_bound, compress_bound_variant, + testing::Values(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)); |
