summaryrefslogtreecommitdiff
path: root/test/allocator.c
diff options
context:
space:
mode:
authorAlbert Cervin <albert@acervin.com>2023-01-29 22:22:54 +0100
committerAlbert Cervin <albert@acervin.com>2023-01-29 22:22:54 +0100
commitf90d5e1f07fdc9dea7c24b11107049b613a5be7a (patch)
treed4e3ba84f198738fd68f225b2d03f34b2653acb1 /test/allocator.c
parent94278ec39b08b4085fa920f870261eb7639baa6b (diff)
downloaddged-f90d5e1f07fdc9dea7c24b11107049b613a5be7a.tar.gz
dged-f90d5e1f07fdc9dea7c24b11107049b613a5be7a.tar.xz
dged-f90d5e1f07fdc9dea7c24b11107049b613a5be7a.zip
More tests and documentation
Also improve find file and switch buffer a bit. Implement word backward/forward.
Diffstat (limited to 'test/allocator.c')
-rw-r--r--test/allocator.c31
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); }