diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/bitset_test.c | 17 | ||||
-rw-r--r-- | test/btree_test.c | 39 | ||||
-rw-r--r-- | test/hash_test.c | 7 | ||||
-rw-r--r-- | test/strindex_test.c | 9 | ||||
-rw-r--r-- | test/tree_test.c | 17 |
5 files changed, 65 insertions, 24 deletions
diff --git a/test/bitset_test.c b/test/bitset_test.c index 95a6f60..3ed121c 100644 --- a/test/bitset_test.c +++ b/test/bitset_test.c @@ -17,6 +17,7 @@ #include "zix/bitset.h" #include "zix/common.h" +#include <inttypes.h> #include <stdarg.h> #include <stdio.h> @@ -52,18 +53,19 @@ main(void) zix_bitset_set(b, t, i); const size_t count = zix_bitset_count_up_to(b, t, N_BITS); if (count != i + 1) { - return test_fail("Count %zu != %zu\n", count, i + 1); + return test_fail("Count %" PRIuPTR " != %" PRIuPTR "\n", count, i + 1); } if (!zix_bitset_get(b, i)) { - return test_fail("Bit %zu is not set\n", i); + return test_fail("Bit %" PRIuPTR " is not set\n", i); } } for (size_t i = 0; i <= N_BITS; ++i) { const size_t count = zix_bitset_count_up_to(b, t, i); if (count != i) { - return test_fail("Count to %zu is %zu != %zu\n", i, count, i); + return test_fail( + "Count to %" PRIuPTR " is %" PRIuPTR " != %" PRIuPTR "\n", i, count, i); } } @@ -73,7 +75,8 @@ main(void) } const size_t count = zix_bitset_count_up_to(b, t, i); if (count != 0) { - return test_fail("Count to %zu is %zu != %d\n", i, count, 0); + return test_fail( + "Count to %" PRIuPTR " is %" PRIuPTR " != %d\n", i, count, 0); } } @@ -84,7 +87,11 @@ main(void) const size_t count = zix_bitset_count_up_to(b, t, i + 1); const size_t result = MIN(N_BITS / 2, i / 2 + 1); if (count != result) { - return test_fail("Count to %zu is %zu != %zu\n", i, count, result); + return test_fail("Count to %" PRIuPTR " is %" PRIuPTR " != %" PRIuPTR + "\n", + i, + count, + result); } } diff --git a/test/btree_test.c b/test/btree_test.c index 49cb443..4d875f3 100644 --- a/test/btree_test.c +++ b/test/btree_test.c @@ -183,7 +183,10 @@ stress(const unsigned test_num, const size_t n_elems) // Ensure tree size is correct if (zix_btree_size(t) != n_elems) { - return test_fail(t, "Tree size %zu != %zu\n", zix_btree_size(t), n_elems); + return test_fail(t, + "Tree size %" PRIuPTR " != %" PRIuPTR "\n", + zix_btree_size(t), + n_elems); } // Ensure begin no longer equals end @@ -206,7 +209,8 @@ stress(const unsigned test_num, const size_t n_elems) for (size_t i = 0; i < n_elems; ++i) { r = ith_elem(test_num, n_elems, i); if (zix_btree_find(t, (void*)r, &ti)) { - return test_fail(t, "Find %" PRIuPTR " @ %zu failed\n", (uintptr_t)r, i); + return test_fail( + t, "Find %" PRIuPTR " @ %" PRIuPTR " failed\n", (uintptr_t)r, i); } if ((uintptr_t)zix_btree_get(ti) != r) { @@ -228,12 +232,14 @@ stress(const unsigned test_num, const size_t n_elems) r = ith_elem(test_num, n_elems, i); if (zix_btree_lower_bound(t, (void*)r, &ti)) { return test_fail( - t, "Lower bound %" PRIuPTR " @ %zu failed\n", (uintptr_t)r, i); + t, "Lower bound %" PRIuPTR " @ %" PRIuPTR " failed\n", (uintptr_t)r, i); } if (zix_btree_iter_is_end(ti)) { - return test_fail( - t, "Lower bound %" PRIuPTR " @ %zu hit end\n", (uintptr_t)r, i); + return test_fail(t, + "Lower bound %" PRIuPTR " @ %" PRIuPTR " hit end\n", + (uintptr_t)r, + i); } if ((uintptr_t)zix_btree_get(ti) != r) { @@ -262,7 +268,8 @@ stress(const unsigned test_num, const size_t n_elems) const uintptr_t iter_data = (uintptr_t)zix_btree_get(ti); if (iter_data < last) { return test_fail(t, - "Iter @ %zu corrupt (%" PRIuPTR " < %" PRIuPTR ")\n", + "Iter @ %" PRIuPTR " corrupt (%" PRIuPTR " < %" PRIuPTR + ")\n", i, iter_data, last); @@ -271,7 +278,11 @@ stress(const unsigned test_num, const size_t n_elems) } zix_btree_iter_free(ti); if (i != n_elems) { - return test_fail(t, "Iteration stopped at %zu/%zu elements\n", i, n_elems); + return test_fail(t, + "Iteration stopped at %" PRIuPTR "/%" PRIuPTR + " elements\n", + i, + n_elems); } // Insert n_elems elements again, ensuring duplicates fail @@ -332,7 +343,7 @@ stress(const unsigned test_num, const size_t n_elems) // Ensure the tree is empty if (zix_btree_size(t) != 0) { - return test_fail(t, "Tree size %zu != 0\n", zix_btree_size(t)); + return test_fail(t, "Tree size %" PRIuPTR " != 0\n", zix_btree_size(t)); } // Insert n_elems elements again (to test non-empty destruction) @@ -357,7 +368,10 @@ stress(const unsigned test_num, const size_t n_elems) // Ensure tree size is still correct if (zix_btree_size(t) != n_elems) { - return test_fail(t, "Tree size %zu != %zu\n", zix_btree_size(t), n_elems); + return test_fail(t, + "Tree size %" PRIuPTR " != %" PRIuPTR "\n", + zix_btree_size(t), + n_elems); } // Delete some elements towards the end @@ -391,7 +405,10 @@ stress(const unsigned test_num, const size_t n_elems) // Check tree size if (zix_btree_size(t) != n_elems - (n_elems / 4)) { - return test_fail(t, "Tree size %zu != %zu\n", zix_btree_size(t), n_elems); + return test_fail(t, + "Tree size %" PRIuPTR " != %" PRIuPTR "\n", + zix_btree_size(t), + n_elems); } // Delete some elements in a random order @@ -526,7 +543,7 @@ main(int argc, char** argv) #ifdef ZIX_WITH_TEST_MALLOC const size_t total_n_allocs = test_malloc_get_n_allocs(); const size_t fail_n_elems = 1000; - printf("Testing 0 ... %zu failed allocations\n", total_n_allocs); + printf("Testing 0 ... %" PRIuPTR " failed allocations\n", total_n_allocs); expect_failure = true; for (size_t i = 0; i < total_n_allocs; ++i) { test_malloc_reset(i); diff --git a/test/hash_test.c b/test/hash_test.c index 46a8fd5..2b9bb51 100644 --- a/test/hash_test.c +++ b/test/hash_test.c @@ -20,6 +20,7 @@ #include "zix/digest.h" #include "zix/hash.h" +#include <inttypes.h> #include <stdarg.h> #include <stdbool.h> #include <stdint.h> @@ -113,7 +114,9 @@ stress(void) // Ensure hash size is correct if (zix_hash_size(hash) != n_strings) { - return test_fail("Hash size %zu != %zu\n", zix_hash_size(hash), n_strings); + return test_fail("Hash size %" PRIuPTR " != %" PRIuPTR "\n", + zix_hash_size(hash), + n_strings); } // zix_hash_print_dot(hash, stdout); @@ -210,7 +213,7 @@ main(void) #ifdef ZIX_WITH_TEST_MALLOC const size_t total_n_allocs = test_malloc_get_n_allocs(); - printf("Testing 0 ... %zu failed allocations\n", total_n_allocs); + printf("Testing 0 ... %" PRIuPTR " failed allocations\n", total_n_allocs); expect_failure = true; for (size_t i = 0; i < total_n_allocs; ++i) { test_malloc_reset(i); diff --git a/test/strindex_test.c b/test/strindex_test.c index 1c36811..42d3c66 100644 --- a/test/strindex_test.c +++ b/test/strindex_test.c @@ -17,6 +17,7 @@ #include "zix/common.h" #include "zix/strindex.h" +#include <inttypes.h> #include <stdarg.h> #include <stdio.h> #include <string.h> @@ -45,11 +46,15 @@ main(void) char* match = NULL; ZixStatus ret = zix_strindex_find(strindex, str + i, &match); if (ret) { - return test_fail("No match for substring at %zu length %zu\n", i, l); + return test_fail( + "No match for substring at %" PRIuPTR " length %" PRIuPTR "\n", i, l); } if (strncmp(str + i, match, l)) { - return test_fail("Bad match for substring at %zu length %zu\n", i, l); + return test_fail("Bad match for substring at %" PRIuPTR + " length %" PRIuPTR "\n", + i, + l); } } } diff --git a/test/tree_test.c b/test/tree_test.c index 0e75779..208080d 100644 --- a/test/tree_test.c +++ b/test/tree_test.c @@ -84,7 +84,10 @@ stress(unsigned test_num, size_t n_elems) // Ensure tree size is correct if (zix_tree_size(t) != n_elems) { - fprintf(stderr, "Tree size %zu != %zu\n", zix_tree_size(t), n_elems); + fprintf(stderr, + "Tree size %" PRIuPTR " != %" PRIuPTR "\n", + zix_tree_size(t), + n_elems); return test_fail(); } @@ -124,7 +127,10 @@ stress(unsigned test_num, size_t n_elems) last = iter_data; } if (i != n_elems) { - fprintf(stderr, "Iteration stopped at %zu/%zu elements\n", i, n_elems); + fprintf(stderr, + "Iteration stopped at %" PRIuPTR "/%" PRIuPTR " elements\n", + i, + n_elems); return test_fail(); } @@ -164,7 +170,7 @@ stress(unsigned test_num, size_t n_elems) // Ensure the tree is empty if (zix_tree_size(t) != 0) { - fprintf(stderr, "Tree size %zu != 0\n", zix_tree_size(t)); + fprintf(stderr, "Tree size %" PRIuPTR " != 0\n", zix_tree_size(t)); return test_fail(); } @@ -189,7 +195,10 @@ stress(unsigned test_num, size_t n_elems) // Ensure tree size is correct if (zix_tree_size(t) != n_elems) { - fprintf(stderr, "Tree size %zu != %zu\n", zix_tree_size(t), n_elems); + fprintf(stderr, + "Tree size %" PRIuPTR " != %" PRIuPTR "\n", + zix_tree_size(t), + n_elems); return test_fail(); } |