From 1da0221459ed09e65ed637c58ee6a32b33fca8b2 Mon Sep 17 00:00:00 2001 From: laentropia Date: Sun, 31 May 2026 21:25:56 -0600 Subject: [PATCH] test: init tests --- test/test_string.c | 37 +++++++++++++++++++++++++++++++++++-- xmake.lua | 3 +++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/test/test_string.c b/test/test_string.c index 6e550ee..fb5ab5c 100644 --- a/test/test_string.c +++ b/test/test_string.c @@ -4,8 +4,41 @@ #include #include +#include "lae_allocator.h" #include "lae_strings.h" -int main(void) { - return EXIT_SUCCESS; +static void test_bstr_init_valid(void **state) { + (void)state; + + ByteStr *bstr; + bstr_init(&bstr, allocator_default(), 64); + assert_non_null(bstr); + + bstr_destroy(&bstr); + assert_null(bstr); +} + +static void test_bstr_init_null_arg(void **state) { + (void)state; + + assert_uint_equal(bstr_init(NULL, allocator_default(), 64), STR_NULL_ARG); +} + +static void test_bstr_init_zero_cap(void **state) { + (void)state; + + ByteStr *bstr; + assert_uint_equal( + bstr_init(&bstr, allocator_default(), 0), + STR_INVALID_CAPACITY); +} + +int main(void) { + const struct CMUnitTest tests[] = { + cmocka_unit_test(test_bstr_init_valid), + cmocka_unit_test(test_bstr_init_null_arg), + cmocka_unit_test(test_bstr_init_zero_cap), + }; + + return cmocka_run_group_tests(tests, NULL, NULL); } diff --git a/xmake.lua b/xmake.lua index 178250a..a3786d1 100644 --- a/xmake.lua +++ b/xmake.lua @@ -79,6 +79,9 @@ if has_config("tests") then add_deps("lae_strings") add_packages("cmocka") + add_packages("lae_allocator") + + add_tests("default") if has_config("asan") then add_cflags("-fsanitize=address", "-fno-omit-frame-pointer", { force = true })