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 :)
83 lines
2.4 KiB
C
83 lines
2.4 KiB
C
#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 <string.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);
|
|
|
|
arena_destroy(&arena);
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
|
|
int main(void) {
|
|
const struct CMUnitTest tests[] = {
|
|
cmocka_unit_test(test_push_3_ints),
|
|
cmocka_unit_test(test_push_3_ints_2_doubles),
|
|
};
|
|
|
|
|
|
return cmocka_run_group_tests(tests, NULL, NULL);
|
|
}
|