summaryrefslogtreecommitdiff
path: root/tests/ez_arena.c
diff options
context:
space:
mode:
authorsteven-na <noreply.github@stvnc.dev>2026-08-01 23:16:13 -0700
committersteven-na <noreply.github@stvnc.dev>2026-08-01 23:16:13 -0700
commitf7bda3da4fb6d6cd1fd449e865885a50618c78e4 (patch)
treeee9e363d4d0db2c71b620bbde1248068b1ca761d /tests/ez_arena.c
parent1ccc16dd584e95038b22264451315b44227bf321 (diff)
Added untested code
Diffstat (limited to 'tests/ez_arena.c')
-rw-r--r--tests/ez_arena.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/ez_arena.c b/tests/ez_arena.c
index d5bcced..8a8b959 100644
--- a/tests/ez_arena.c
+++ b/tests/ez_arena.c
@@ -107,3 +107,51 @@ Test(ez_arena, alloc_clear_dont_zero_arena) {
ez_arena_destroy(arena);
}
+
+Test(ez_arena, create_without_zeroing_is_usable) {
+ ez_arena_t *arena = ez_arena_create(sizeof(uint32_t), false);
+
+ uint32_t *i = ez_arena_alloc(arena, sizeof(uint32_t));
+ *i = UINT32_MAX;
+
+ cr_assert_eq(*i, UINT32_MAX);
+
+ ez_arena_destroy(arena);
+}
+
+Test(ez_arena, create_fails_when_malloc_cannot_satisfy_size) {
+ ez_arena_t *arena = ez_arena_create(UINT64_MAX - sizeof(ez_arena_t), true);
+
+ cr_expect_eq(arena, NULL);
+}
+
+Test(ez_arena, alloc_nz_arena) {
+ ez_arena_t *arena = ez_arena_create(sizeof(uint32_t), true);
+
+ uint32_t *i = ez_arena_alloc_nz(arena, sizeof(uint32_t));
+ *i = UINT32_MAX;
+
+ cr_assert_eq(*i, UINT32_MAX);
+
+ ez_arena_destroy(arena);
+}
+
+Test(ez_arena, alloc_exceeds_size_returns_null) {
+ ez_arena_t *arena = ez_arena_create(sizeof(uint32_t), true);
+
+ void *p = ez_arena_alloc(arena, KiB(1));
+
+ cr_expect_eq(p, NULL);
+
+ ez_arena_destroy(arena);
+}
+
+Test(ez_arena, alloc_nz_exceeds_size_returns_null) {
+ ez_arena_t *arena = ez_arena_create(sizeof(uint32_t), true);
+
+ void *p = ez_arena_alloc_nz(arena, KiB(1));
+
+ cr_expect_eq(p, NULL);
+
+ ez_arena_destroy(arena);
+}