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_compare256_rle.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_compare256_rle.cc')
| -rw-r--r-- | neozip/test/test_compare256_rle.cc | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/neozip/test/test_compare256_rle.cc b/neozip/test/test_compare256_rle.cc new file mode 100644 index 0000000000..7a77fce59f --- /dev/null +++ b/neozip/test/test_compare256_rle.cc @@ -0,0 +1,54 @@ +/* test_compare256_rle.cc -- compare256_rle unit tests + * Copyright (C) 2022 Nathan Moinvaziri + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> + +extern "C" { +# include "zbuild.h" +# include "zutil.h" +# include "compare256_rle.h" +} + +#include <gtest/gtest.h> + +#define MAX_COMPARE_SIZE (256) + +/* Ensure that compare256_rle returns the correct match length */ +static inline void compare256_rle_match_check(compare256_rle_func compare256_rle) { + int32_t match_len, i; + uint8_t str1[] = {'a', 'a', 0}; + uint8_t *str2; + + str2 = (uint8_t *)PREFIX(zcalloc)(NULL, 1, MAX_COMPARE_SIZE); + ASSERT_TRUE(str2 != NULL); + memset(str2, 'a', MAX_COMPARE_SIZE); + + for (i = 0; i <= MAX_COMPARE_SIZE; i++) { + if (i < MAX_COMPARE_SIZE) + str2[i] = 0; + + match_len = compare256_rle(str1, str2); + EXPECT_EQ(match_len, i); + + if (i < MAX_COMPARE_SIZE) + str2[i] = 'a'; + } + + PREFIX(zcfree)(NULL, str2); +} + +#define TEST_COMPARE256_RLE(name, func, support_flag) \ + TEST(compare256_rle, name) { \ + if (!(support_flag)) { \ + GTEST_SKIP(); \ + return; \ + } \ + compare256_rle_match_check(func); \ + } + +TEST_COMPARE256_RLE(8, compare256_rle_8, 1) +TEST_COMPARE256_RLE(64, compare256_rle_64, 1) |
