From 16a1b8fa3543562f1bed104010d9c1f58783675e Mon Sep 17 00:00:00 2001 From: Abdelrahman Date: Sat, 14 Sep 2024 14:49:18 +0100 Subject: [PATCH] Reformat --- src/core/mem/arena/mem_arena_allocator.c | 16 +++----- tests/allocator/test_allocator.c | 22 +++++----- tests/arena/test_arena.c | 12 +++--- tests/shell_commander/test_shell_commander.c | 42 ++++++++------------ 4 files changed, 40 insertions(+), 52 deletions(-) diff --git a/src/core/mem/arena/mem_arena_allocator.c b/src/core/mem/arena/mem_arena_allocator.c index 2aee280..e7b63ee 100644 --- a/src/core/mem/arena/mem_arena_allocator.c +++ b/src/core/mem/arena/mem_arena_allocator.c @@ -19,19 +19,16 @@ internal inline void *mem_arena_realloc_aligned(void *ptr, u64 old_size, u64 new //////////////////////////////////////////////////////////////////////////////// /***************************************************************************/ // -Allocator wapp_mem_arena_allocator_init_custom(u64 base_capacity, - MemAllocFlags flags, - bool zero_buffer) { +Allocator wapp_mem_arena_allocator_init_custom(u64 base_capacity, MemAllocFlags flags, bool zero_buffer) { Allocator allocator = {0}; - bool initialised = wapp_mem_arena_init_custom( - (Arena **)(&allocator.obj), base_capacity, flags, zero_buffer); + bool initialised = wapp_mem_arena_init_custom((Arena **)(&allocator.obj), base_capacity, flags, zero_buffer); if (!initialised) { return allocator; } - allocator.alloc = mem_arena_alloc; - allocator.alloc_aligned = mem_arena_alloc_aligned; - allocator.realloc = mem_arena_realloc; + allocator.alloc = mem_arena_alloc; + allocator.alloc_aligned = mem_arena_alloc_aligned; + allocator.realloc = mem_arena_realloc; allocator.realloc_aligned = mem_arena_realloc_aligned; return allocator; @@ -57,8 +54,7 @@ internal inline void *mem_arena_alloc(u64 size, void *alloc_obj) { return wapp_mem_arena_alloc(arena, size); } -internal inline void *mem_arena_alloc_aligned(u64 size, u64 alignment, - void *alloc_obj) { +internal inline void *mem_arena_alloc_aligned(u64 size, u64 alignment, void *alloc_obj) { Arena *arena = (Arena *)alloc_obj; return wapp_mem_arena_alloc_aligned(arena, size, alignment); } diff --git a/tests/allocator/test_allocator.c b/tests/allocator/test_allocator.c index 7d15256..97852c9 100644 --- a/tests/allocator/test_allocator.c +++ b/tests/allocator/test_allocator.c @@ -8,11 +8,11 @@ TestFuncResult test_libc_allocator(void) { Allocator allocator = wapp_mem_libc_allocator(); - bool result = allocator.obj == NULL && allocator.alloc != NULL && - allocator.alloc_aligned != NULL && allocator.realloc != NULL && - allocator.realloc_aligned == NULL && allocator.free != NULL; - void *ptr = wapp_mem_allocator_alloc(&allocator, 20); - result = result && (ptr != NULL); + bool result = allocator.obj == NULL && allocator.alloc != NULL && + allocator.alloc_aligned != NULL && allocator.realloc != NULL && + allocator.realloc_aligned == NULL && allocator.free != NULL; + void *ptr = wapp_mem_allocator_alloc(&allocator, 20); + result = result && (ptr != NULL); if (ptr != NULL) { wapp_mem_allocator_free(&allocator, &ptr); @@ -24,12 +24,12 @@ TestFuncResult test_libc_allocator(void) { TestFuncResult test_arena_allocator(void) { Allocator allocator = wapp_mem_arena_allocator_init(4096); - bool result = allocator.obj != NULL && allocator.alloc != NULL && - allocator.alloc_aligned != NULL && - allocator.realloc == NULL & allocator.realloc_aligned == NULL && - allocator.free == NULL; - void *ptr = wapp_mem_allocator_alloc(&allocator, 20); - result = result && (ptr != NULL); + bool result = allocator.obj != NULL && allocator.alloc != NULL && + allocator.alloc_aligned != NULL && + allocator.realloc == NULL & allocator.realloc_aligned == NULL && + allocator.free == NULL; + void *ptr = wapp_mem_allocator_alloc(&allocator, 20); + result = result && (ptr != NULL); wapp_mem_arena_allocator_destroy(&allocator); diff --git a/tests/arena/test_arena.c b/tests/arena/test_arena.c index dd261da..9f74ed9 100644 --- a/tests/arena/test_arena.c +++ b/tests/arena/test_arena.c @@ -9,8 +9,8 @@ #define ARENA_CAPACITY 1024 internal Arena *arena = NULL; -internal i32 count = 20; -internal i32 *array = NULL; +internal i32 count = 20; +internal i32 *array = NULL; TestFuncResult test_arena_init(void) { bool result = wapp_mem_arena_init(&arena, ARENA_CAPACITY); @@ -20,8 +20,8 @@ TestFuncResult test_arena_init(void) { TestFuncResult test_arena_init_succeeds_when_reserving_very_large_size(void) { Arena *large_arena = NULL; - u64 capacity = GB(512); - bool result = wapp_mem_arena_init(&large_arena, capacity); + u64 capacity = GB(512); + bool result = wapp_mem_arena_init(&large_arena, capacity); if (result) { wapp_mem_arena_destroy(&large_arena); } @@ -30,7 +30,7 @@ TestFuncResult test_arena_init_succeeds_when_reserving_very_large_size(void) { } TestFuncResult test_arena_alloc_succeeds_when_within_capacity(void) { - array = wapp_mem_arena_alloc(arena, count * sizeof(i32)); + array = wapp_mem_arena_alloc(arena, count * sizeof(i32)); bool result = array != NULL; for (i32 i = 0; i < count; ++i) { @@ -41,7 +41,7 @@ TestFuncResult test_arena_alloc_succeeds_when_within_capacity(void) { } TestFuncResult test_arena_alloc_fails_when_over_capacity(void) { - u8 *bytes = wapp_mem_arena_alloc(arena, ARENA_CAPACITY * 2); + u8 *bytes = wapp_mem_arena_alloc(arena, ARENA_CAPACITY * 2); bool result = bytes == NULL; return wapp_tester_result(result); diff --git a/tests/shell_commander/test_shell_commander.c b/tests/shell_commander/test_shell_commander.c index 8ab5f9b..07dfea8 100644 --- a/tests/shell_commander/test_shell_commander.c +++ b/tests/shell_commander/test_shell_commander.c @@ -7,49 +7,41 @@ #include TestFuncResult test_commander_cmd_success(void) { - CMDResult result = wapp_shell_commander_execute(SHELL_OUTPUT_DISCARD, NULL, 0, - "echo", "hello world"); - - bool succeeded = result.exited && result.exit_code == EXIT_SUCCESS && - result.error == SHELL_ERR_NO_ERROR; + CMDResult result = wapp_shell_commander_execute(SHELL_OUTPUT_DISCARD, NULL, 0, "echo", "hello world"); + bool succeeded = result.exited && result.exit_code == EXIT_SUCCESS && + result.error == SHELL_ERR_NO_ERROR; return wapp_tester_result(succeeded); } TestFuncResult test_commander_cmd_failure(void) { - CMDResult result = - wapp_shell_commander_execute(SHELL_OUTPUT_DISCARD, NULL, 0, "grep"); - - bool failed = result.exited && result.exit_code != EXIT_SUCCESS && - result.error == SHELL_ERR_NO_ERROR; + CMDResult result = wapp_shell_commander_execute(SHELL_OUTPUT_DISCARD, NULL, 0, "grep"); + bool failed = result.exited && result.exit_code != EXIT_SUCCESS && + result.error == SHELL_ERR_NO_ERROR; return wapp_tester_result(failed); } TestFuncResult test_commander_cmd_out_buf_success(void) { - char buf[64] = {0}; + char buf[64] = {0}; char expected_output[64] = {0}; - const char *msg = "hello world"; + const char *msg = "hello world"; sprintf(expected_output, "%s\n", msg); - CMDResult result = - wapp_shell_commander_execute(SHELL_OUTPUT_CAPTURE, buf, 64, "echo", msg); - - bool succeeded = result.exited && result.exit_code == EXIT_SUCCESS && - result.error == SHELL_ERR_NO_ERROR && - strcmp(buf, expected_output) == 0; + CMDResult result = wapp_shell_commander_execute(SHELL_OUTPUT_CAPTURE, buf, 64, "echo", msg); + bool succeeded = result.exited && result.exit_code == EXIT_SUCCESS && + result.error == SHELL_ERR_NO_ERROR && + strcmp(buf, expected_output) == 0; return wapp_tester_result(succeeded); } TestFuncResult test_commander_cmd_out_buf_failure(void) { - char buf[4] = {0}; - const char *msg = "hello world"; - CMDResult result = - wapp_shell_commander_execute(SHELL_OUTPUT_CAPTURE, buf, 4, "echo", msg); - - bool failed = !result.exited && result.exit_code != EXIT_SUCCESS && - result.error == SHELL_ERR_OUT_BUF_FULL && strcmp(buf, msg) != 0; + char buf[4] = {0}; + const char *msg = "hello world"; + CMDResult result = wapp_shell_commander_execute(SHELL_OUTPUT_CAPTURE, buf, 4, "echo", msg); + bool failed = !result.exited && result.exit_code != EXIT_SUCCESS && + result.error == SHELL_ERR_OUT_BUF_FULL && strcmp(buf, msg) != 0; return wapp_tester_result(failed); }