diff options
Diffstat (limited to 'test/test_btree.c')
-rw-r--r-- | test/test_btree.c | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/test/test_btree.c b/test/test_btree.c index e918799..a87e26e 100644 --- a/test/test_btree.c +++ b/test/test_btree.c @@ -3,16 +3,15 @@ #undef NDEBUG -#include "zix/btree.h" - #include "ensure.h" #include "failing_allocator.h" #include "test_args.h" #include "test_data.h" -#include "zix/allocator.h" -#include "zix/attributes.h" -#include "zix/status.h" +#include <zix/allocator.h> +#include <zix/attributes.h> +#include <zix/btree.h> +#include <zix/status.h> #include <assert.h> #include <inttypes.h> @@ -20,8 +19,7 @@ #include <stdio.h> #include <stdlib.h> -ZIX_PURE_FUNC -static int +ZIX_PURE_FUNC static int int_cmp(const void* a, const void* b, const void* ZIX_UNUSED(user_data)) { const uintptr_t ia = (uintptr_t)a; @@ -103,6 +101,23 @@ destroy(void* const ptr, const void* const user_data) } static void +test_empty(void) +{ + ZixBTree* const t = zix_btree_new(NULL, int_cmp, NULL); + assert(t); + + // Check that reading functions work properly with an empty (rootless) tree + const int e = 42; + ZixBTreeIter ti = zix_btree_end(t); + zix_btree_clear(t, NULL, NULL); + assert(!zix_btree_size(t)); + assert(zix_btree_find(t, &e, &ti) == ZIX_STATUS_NOT_FOUND); + assert(!zix_btree_lower_bound(t, int_cmp, NULL, &e, &ti)); + + zix_btree_free(t, destroy, NULL); +} + +static void test_clear(void) { ZixBTree* t = zix_btree_new(NULL, int_cmp, NULL); @@ -419,7 +434,7 @@ stress(ZixAllocator* const allocator, uintptr_t removed = 0; ENSUREV(t, zix_btree_remove(t, (void*)r, (void**)&removed, &next), - "Removal of non-existant %" PRIuPTR " succeeded\n", + "Removal of non-existent %" PRIuPTR " succeeded\n", r); } @@ -563,9 +578,9 @@ test_failed_alloc(void) assert(!stress(&allocator.base, 0, 4096)); // Test that each allocation failing is handled gracefully - const size_t n_new_allocs = allocator.n_allocations; + const size_t n_new_allocs = zix_failing_allocator_reset(&allocator, 0); for (size_t i = 0U; i < n_new_allocs; ++i) { - allocator.n_remaining = i; + zix_failing_allocator_reset(&allocator, i); assert(stress(&allocator.base, 0, 4096)); } } @@ -578,6 +593,7 @@ main(int argc, char** argv) return EXIT_FAILURE; } + test_empty(); test_clear(); test_free(); test_iter_comparison(); |