test: init tests
This commit is contained in:
@@ -4,8 +4,41 @@
|
|||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "lae_allocator.h"
|
||||||
#include "lae_strings.h"
|
#include "lae_strings.h"
|
||||||
|
|
||||||
int main(void) {
|
static void test_bstr_init_valid(void **state) {
|
||||||
return EXIT_SUCCESS;
|
(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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,6 +79,9 @@ if has_config("tests") then
|
|||||||
add_deps("lae_strings")
|
add_deps("lae_strings")
|
||||||
|
|
||||||
add_packages("cmocka")
|
add_packages("cmocka")
|
||||||
|
add_packages("lae_allocator")
|
||||||
|
|
||||||
|
add_tests("default")
|
||||||
|
|
||||||
if has_config("asan") then
|
if has_config("asan") then
|
||||||
add_cflags("-fsanitize=address", "-fno-omit-frame-pointer", { force = true })
|
add_cflags("-fsanitize=address", "-fno-omit-frame-pointer", { force = true })
|
||||||
|
|||||||
Reference in New Issue
Block a user