aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_world.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2023-09-10 15:06:42 -0400
committerDavid Robillard <d@drobilla.net>2023-12-02 18:49:08 -0500
commit248a874d7425749d29cf900a1c3783c624ea8d8c (patch)
treeaed59f5a484a815cd254506866e98a947858904d /test/test_world.c
parent0bd10132c6707353dba80bd89cf0102ee7ca4e34 (diff)
downloadserd-248a874d7425749d29cf900a1c3783c624ea8d8c.tar.gz
serd-248a874d7425749d29cf900a1c3783c624ea8d8c.tar.bz2
serd-248a874d7425749d29cf900a1c3783c624ea8d8c.zip
Add support for custom allocators
This makes it explicit in the API where memory is allocated, and allows the user to provide a custom allocator to avoid the use of the default system allocator for whatever reason.
Diffstat (limited to 'test/test_world.c')
-rw-r--r--test/test_world.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/test/test_world.c b/test/test_world.c
index 3f7f6ea6..7ff20143 100644
--- a/test/test_world.c
+++ b/test/test_world.c
@@ -3,6 +3,8 @@
#undef NDEBUG
+#include "failing_allocator.h"
+
#include "serd/node.h"
#include "serd/world.h"
@@ -11,9 +13,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) {
@@ -29,6 +50,7 @@ test_get_blank(void)
int
main(void)
{
+ test_new_failed_alloc();
test_get_blank();
return 0;