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
2026-03-31 19:15:37 -06:00
|
|
|
#include <stdalign.h>
|
2026-03-29 10:40:09 -06:00
|
|
|
#include <stdlib.h>
|
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
2026-03-31 19:15:37 -06:00
|
|
|
#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);
|
|
|
|
|
}
|
2026-03-29 10:40:09 -06:00
|
|
|
|
|
|
|
|
int main(void) {
|
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
2026-03-31 19:15:37 -06:00
|
|
|
const struct CMUnitTest tests[] = {
|
|
|
|
|
cmocka_unit_test(test_push_3_ints),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return cmocka_run_group_tests(tests, NULL, NULL);
|
2026-03-29 10:40:09 -06:00
|
|
|
}
|