diff options
author | David Robillard <d@drobilla.net> | 2021-10-27 14:15:31 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2022-01-28 21:57:24 -0500 |
commit | 30487c277ac5d4be5786733ca7b98adb4c810ae9 (patch) | |
tree | f1b00a7725d74a594fcd91de2aea924485356528 /test/test_world.c | |
parent | 56cceb103dc633d6af957472945e792187a5dd4e (diff) | |
download | serd-30487c277ac5d4be5786733ca7b98adb4c810ae9.tar.gz serd-30487c277ac5d4be5786733ca7b98adb4c810ae9.tar.bz2 serd-30487c277ac5d4be5786733ca7b98adb4c810ae9.zip |
Add custom allocator support
Diffstat (limited to 'test/test_world.c')
-rw-r--r-- | test/test_world.c | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/test/test_world.c b/test/test_world.c index 8045d1bf..23958b19 100644 --- a/test/test_world.c +++ b/test/test_world.c @@ -16,6 +16,8 @@ #undef NDEBUG +#include "failing_allocator.h" + #include "serd/serd.h" #include <assert.h> @@ -23,9 +25,28 @@ #include <string.h> static void +test_new_failed_alloc(void) +{ + SerdFailingAllocator allocator = serd_failing_allocator(); + + // Successfully allocate a world to count the number of allocations + SerdWorld* const world = serd_world_new(&allocator.base); + assert(world); + + // Test that each allocation failing is handled gracefully + const size_t n_new_allocs = allocator.n_allocations; + for (size_t i = 0; i < n_new_allocs; ++i) { + allocator.n_remaining = i; + assert(!serd_world_new(&allocator.base)); + } + + serd_world_free(world); +} + +static void test_get_blank(void) { - SerdWorld* world = serd_world_new(); + SerdWorld* world = serd_world_new(NULL); char expected[12]; for (unsigned i = 0; i < 32; ++i) { @@ -41,7 +62,7 @@ test_get_blank(void) static void test_nodes(void) { - SerdWorld* const world = serd_world_new(); + SerdWorld* const world = serd_world_new(NULL); SerdNodes* const nodes = serd_world_nodes(world); assert(serd_nodes_size(nodes) > 0u); @@ -52,6 +73,7 @@ test_nodes(void) int main(void) { + test_new_failed_alloc(); test_get_blank(); test_nodes(); |