diff options
Diffstat (limited to 'test/allocator.c')
| -rw-r--r-- | test/allocator.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/test/allocator.c b/test/allocator.c new file mode 100644 index 0000000..ca1a7a0 --- /dev/null +++ b/test/allocator.c @@ -0,0 +1,31 @@ +#include "assert.h" +#include "test.h" + +#include "allocator.h" + +void test_frame_allocator() { + struct frame_allocator fa = frame_allocator_create(128); + + ASSERT(fa.capacity == 128, + "Expected frame allocator to be created with specified capacity"); + + void *bytes = frame_allocator_alloc(&fa, 128); + ASSERT( + bytes != NULL, + "Expected to be able to allocate <capacity> bytes from frame allocator"); + + void *bytes_again = frame_allocator_alloc(&fa, 128); + ASSERT(bytes_again == NULL, + "Expected to not be able to allocate <capacity> bytes " + "from frame allocator a second time"); + + frame_allocator_clear(&fa); + void *bytes_after_clear = frame_allocator_alloc(&fa, 128); + ASSERT(bytes_after_clear != NULL, + "Expected to be able to allocate <capacity> bytes from frame " + "allocator again after clearing it"); + + frame_allocator_destroy(&fa); +} + +void run_allocator_tests() { run_test(test_frame_allocator); } |
