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>
|
refactor(all): Fixed alloc and moved growing logic to another function
OK, so evrything was a fucknig mess, it still kinda is, AI helped
me to clean my own mess, it really sucks but the fucking debugger
and address sanitizer were not working, also, there were small
small errors so no big deal but still, a bit sad, also changed a
the way i cast from uint8_t to double and int in the tests, may
change that i guess, verything else i might say is good :)
2026-04-03 12:44:01 -06:00
|
|
|
#include <string.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 "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);
|
refactor(all): Fixed alloc and moved growing logic to another function
OK, so evrything was a fucknig mess, it still kinda is, AI helped
me to clean my own mess, it really sucks but the fucking debugger
and address sanitizer were not working, also, there were small
small errors so no big deal but still, a bit sad, also changed a
the way i cast from uint8_t to double and int in the tests, may
change that i guess, verything else i might say is good :)
2026-04-03 12:44:01 -06:00
|
|
|
assert_int_equal(20, *(int*)result.address);
|
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
|
|
|
|
|
|
|
|
int_to_push = 30;
|
|
|
|
|
result = arena_push(&arena, &int_to_push, sizeof(int), alignof(int));
|
|
|
|
|
assert_true(result.is_valid);
|
refactor(all): Fixed alloc and moved growing logic to another function
OK, so evrything was a fucknig mess, it still kinda is, AI helped
me to clean my own mess, it really sucks but the fucking debugger
and address sanitizer were not working, also, there were small
small errors so no big deal but still, a bit sad, also changed a
the way i cast from uint8_t to double and int in the tests, may
change that i guess, verything else i might say is good :)
2026-04-03 12:44:01 -06:00
|
|
|
assert_int_equal(30, *(int*) result.address);
|
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
|
|
|
|
|
|
|
|
int_to_push = 40;
|
|
|
|
|
result = arena_push(&arena, &int_to_push, sizeof(int), alignof(int));
|
|
|
|
|
assert_true(result.is_valid);
|
refactor(all): Fixed alloc and moved growing logic to another function
OK, so evrything was a fucknig mess, it still kinda is, AI helped
me to clean my own mess, it really sucks but the fucking debugger
and address sanitizer were not working, also, there were small
small errors so no big deal but still, a bit sad, also changed a
the way i cast from uint8_t to double and int in the tests, may
change that i guess, verything else i might say is good :)
2026-04-03 12:44:01 -06:00
|
|
|
assert_int_equal(40, *(int*) result.address);
|
|
|
|
|
|
|
|
|
|
arena_destroy(&arena);
|
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
|
|
|
}
|
2026-03-29 10:40:09 -06:00
|
|
|
|
refactor(all): Fixed alloc and moved growing logic to another function
OK, so evrything was a fucknig mess, it still kinda is, AI helped
me to clean my own mess, it really sucks but the fucking debugger
and address sanitizer were not working, also, there were small
small errors so no big deal but still, a bit sad, also changed a
the way i cast from uint8_t to double and int in the tests, may
change that i guess, verything else i might say is good :)
2026-04-03 12:44:01 -06:00
|
|
|
static void test_push_3_ints_2_doubles(void **state) {
|
|
|
|
|
(void) state;
|
|
|
|
|
|
|
|
|
|
ArenaResult value = arena_init((sizeof(int) * 3) + (sizeof(double) * 2));
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
double double_to_push = 4.57;
|
|
|
|
|
result = arena_push(&arena, &double_to_push, sizeof(double), alignof(double));
|
|
|
|
|
assert_true(result.is_valid);
|
|
|
|
|
assert_double_equal(4.57, *(double*)result.address, 1e-6);
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
double_to_push = 267.33;
|
|
|
|
|
result = arena_push(&arena, &double_to_push, sizeof(double), alignof(double));
|
|
|
|
|
assert_true(result.is_valid);
|
|
|
|
|
assert_double_equal(267.33, *(double*) result.address, 1e-6);
|
|
|
|
|
|
|
|
|
|
arena_destroy(&arena);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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),
|
refactor(all): Fixed alloc and moved growing logic to another function
OK, so evrything was a fucknig mess, it still kinda is, AI helped
me to clean my own mess, it really sucks but the fucking debugger
and address sanitizer were not working, also, there were small
small errors so no big deal but still, a bit sad, also changed a
the way i cast from uint8_t to double and int in the tests, may
change that i guess, verything else i might say is good :)
2026-04-03 12:44:01 -06:00
|
|
|
cmocka_unit_test(test_push_3_ints_2_doubles),
|
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
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return cmocka_run_group_tests(tests, NULL, NULL);
|
2026-03-29 10:40:09 -06:00
|
|
|
}
|