2026-05-26 22:28:06 -06:00
|
|
|
#include <cmocka.h>
|
|
|
|
|
#include <setjmp.h>
|
|
|
|
|
#include <stdarg.h> /* required by cmocka */
|
|
|
|
|
#include <stddef.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
2026-05-31 21:25:56 -06:00
|
|
|
#include "lae_allocator.h"
|
2026-05-26 22:28:06 -06:00
|
|
|
#include "lae_strings.h"
|
|
|
|
|
|
2026-05-31 21:25:56 -06:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-26 22:28:06 -06:00
|
|
|
int main(void) {
|
2026-05-31 21:25:56 -06:00
|
|
|
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);
|
2026-05-26 22:28:06 -06:00
|
|
|
}
|