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:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user