test and rework: Added push test and cahnged arena_push return

So added a little test that just adds 3 ints to an arena, nothing much
but the basics work, also changed arena_push because it only pushed and
didn't returned a ponter (wich is fucking useless) so also fixed that,
everything seems fine now, need more tests.

# Tipos:
# feat, fix, refactor, docs, style, test, chore
This commit is contained in:
2026-03-31 19:15:37 -06:00
parent 0401069a63
commit 39dfded924
3 changed files with 57 additions and 9 deletions

View File

@@ -1,6 +1,42 @@
#include "arena.h"
#include <stdalign.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <setjmp.h>
#include <cmocka.h>
#include "arena.h"
static void test_push_3_ints(void **state) {
(void) state;
ArenaResult value = arena_init(sizeof(int) * 3);
assert_true(value.is_valid);
Arena arena = value.arena;
int int_to_push = 20;
ArenaPointer result = arena_push(&arena, &int_to_push, sizeof(int), alignof(int));
assert_true(result.is_valid);
assert_int_equal(20, (int) *result.address);
int_to_push = 30;
result = arena_push(&arena, &int_to_push, sizeof(int), alignof(int));
assert_true(result.is_valid);
assert_int_equal(30, (int) *result.address);
int_to_push = 40;
result = arena_push(&arena, &int_to_push, sizeof(int), alignof(int));
assert_true(result.is_valid);
assert_int_equal(40, (int) *result.address);
}
int main(void) {
return EXIT_SUCCESS;
const struct CMUnitTest tests[] = {
cmocka_unit_test(test_push_3_ints),
};
return cmocka_run_group_tests(tests, NULL, NULL);
}