diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/allocator_test.c | 65 | ||||
-rw-r--r-- | test/btree_test.c | 14 | ||||
-rw-r--r-- | test/hash_test.c | 7 | ||||
-rw-r--r-- | test/ring_test.c | 2 | ||||
-rw-r--r-- | test/tree_test.c | 2 |
5 files changed, 78 insertions, 12 deletions
diff --git a/test/allocator_test.c b/test/allocator_test.c new file mode 100644 index 0000000..432b836 --- /dev/null +++ b/test/allocator_test.c @@ -0,0 +1,65 @@ +/* + Copyright 2014-2021 David Robillard <d@drobilla.net> + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#undef NDEBUG + +#include "zix/allocator.h" + +#include <assert.h> + +static void +test_allocator(void) +{ + // Just a basic smoke test to check that things seem to be working + + const ZixAllocator* const allocator = zix_default_allocator(); + + char* const malloced = (char*)zix_malloc(allocator, 4); + malloced[0] = 0; + malloced[3] = 3; + assert(malloced[0] == 0); + assert(malloced[3] == 3); + + char* const calloced = (char*)zix_calloc(allocator, 4, 1); + assert(calloced[0] == 0); + assert(calloced[1] == 0); + assert(calloced[2] == 0); + assert(calloced[3] == 0); + + char* const realloced = (char*)zix_realloc(allocator, calloced, 8); + assert(realloced[0] == 0); + assert(realloced[1] == 0); + assert(realloced[2] == 0); + assert(realloced[3] == 0); + realloced[4] = 4; + realloced[5] = 5; + realloced[6] = 6; + realloced[7] = 7; + assert(realloced[4] == 4); + assert(realloced[5] == 5); + assert(realloced[6] == 6); + assert(realloced[7] == 7); + + zix_free(allocator, realloced); + zix_free(allocator, malloced); +} + +int +main(void) +{ + test_allocator(); + return 0; +} diff --git a/test/btree_test.c b/test/btree_test.c index a890f0f..00a5790 100644 --- a/test/btree_test.c +++ b/test/btree_test.c @@ -136,7 +136,7 @@ no_destroy(void* const ptr, const void* const user_data) static void test_clear(void) { - ZixBTree* t = zix_btree_new(int_cmp, NULL); + ZixBTree* t = zix_btree_new(NULL, int_cmp, NULL); for (uintptr_t r = 0u; r < n_clear_insertions; ++r) { assert(!zix_btree_insert(t, (void*)(r + 1u))); @@ -151,7 +151,7 @@ test_clear(void) static void test_free(void) { - ZixBTree* t = zix_btree_new(int_cmp, NULL); + ZixBTree* t = zix_btree_new(NULL, int_cmp, NULL); for (uintptr_t r = 0u; r < n_clear_insertions; ++r) { assert(!zix_btree_insert(t, (void*)(r + 1u))); @@ -167,7 +167,7 @@ test_iter_comparison(void) { static const size_t n_elems = 4096u; - ZixBTree* const t = zix_btree_new(int_cmp, NULL); + ZixBTree* const t = zix_btree_new(NULL, int_cmp, NULL); // Store increasing numbers from 1 (jammed into the pointers themselves) for (uintptr_t r = 1u; r < n_elems; ++r) { @@ -211,7 +211,7 @@ test_insert_split_value(void) static const size_t n_insertions = 767u; // Number of insertions to split static const uintptr_t split_value = 512u; // Value that will be pulled up - ZixBTree* const t = zix_btree_new(int_cmp, NULL); + ZixBTree* const t = zix_btree_new(NULL, int_cmp, NULL); // Insert right up until it would cause a split for (uintptr_t r = 1u; r < n_insertions; ++r) { @@ -235,7 +235,7 @@ test_remove_cases(void) static const uintptr_t s2 = 255u; static const size_t n_insertions = s1 * s2 * 1000u; - ZixBTree* const t = zix_btree_new(int_cmp, NULL); + ZixBTree* const t = zix_btree_new(NULL, int_cmp, NULL); // Insert in s1-sized chunks for (uintptr_t phase = 0u; phase < s1; ++phase) { @@ -270,7 +270,7 @@ stress(const unsigned test_num, const size_t n_elems) } uintptr_t r = 0; - ZixBTree* t = zix_btree_new(int_cmp, NULL); + ZixBTree* t = zix_btree_new(NULL, int_cmp, NULL); ZixStatus st = ZIX_STATUS_SUCCESS; if (!t) { @@ -554,7 +554,7 @@ stress(const unsigned test_num, const size_t n_elems) // Test lower_bound with wildcard comparator TestContext ctx = {test_num, n_elems}; - if (!(t = zix_btree_new(wildcard_cmp, &ctx))) { + if (!(t = zix_btree_new(NULL, wildcard_cmp, &ctx))) { return test_fail(t, "Failed to allocate tree\n"); } diff --git a/test/hash_test.c b/test/hash_test.c index 834c391..62e2d18 100644 --- a/test/hash_test.c +++ b/test/hash_test.c @@ -132,7 +132,7 @@ string_equal(const char* const a, const char* const b) static int stress_with(const ZixHashFunc hash_func, const size_t n_elems) { - ZixHash* hash = zix_hash_new(identity, hash_func, string_equal); + ZixHash* hash = zix_hash_new(NULL, identity, hash_func, string_equal); if (!hash) { return test_fail("Failed to allocate hash\n"); } @@ -336,8 +336,9 @@ test_all_tombstones(void) "3 b", }; - ZixStatus st = ZIX_STATUS_SUCCESS; - ZixHash* hash = zix_hash_new(identity, identity_index_hash, string_equal); + ZixStatus st = ZIX_STATUS_SUCCESS; + ZixHash* hash = + zix_hash_new(NULL, identity, identity_index_hash, string_equal); // Insert each element then immediately remove it for (unsigned i = 0u; i < N_STRINGS; ++i) { diff --git a/test/ring_test.c b/test/ring_test.c index 61a6d1f..23c5adc 100644 --- a/test/ring_test.c +++ b/test/ring_test.c @@ -137,7 +137,7 @@ main(int argc, char** argv) MSG_SIZE, size); - ring = zix_ring_new(size); + ring = zix_ring_new(NULL, size); assert(ring); if (zix_ring_read_space(ring) != 0) { return failure("New ring is not empty\n"); diff --git a/test/tree_test.c b/test/tree_test.c index 76c247d..7d2b6af 100644 --- a/test/tree_test.c +++ b/test/tree_test.c @@ -63,7 +63,7 @@ stress(unsigned test_num, size_t n_elems) { uintptr_t r = 0u; ZixTreeIter* ti = NULL; - ZixTree* t = zix_tree_new(true, int_cmp, NULL, NULL, NULL); + ZixTree* t = zix_tree_new(NULL, true, int_cmp, NULL, NULL, NULL); // Insert n_elems elements for (size_t i = 0; i < n_elems; ++i) { |