Integrate CMocka to do unit testing

scene_man
En Yi 2023-06-16 11:51:22 +08:00
parent 6005d3f490
commit ca621bf798
3 changed files with 39 additions and 0 deletions

View File

@ -97,3 +97,8 @@ target_link_libraries(assets_test
${GAME_LIBS}
)
if (UNIT_TESTING)
find_package(cmocka 1.1.0 REQUIRED)
add_subdirectory(tests)
endif()

View File

@ -0,0 +1,9 @@
add_executable(AABBTest test_AABB.c)
target_compile_features(AABBTest PRIVATE c_std_99)
target_link_libraries(AABBTest PRIVATE
cmocka
lib_scenes
)
enable_testing()
add_test(NAME AABBTest COMMAND AABBTest)

25
tests/test_AABB.c 100644
View File

@ -0,0 +1,25 @@
#include "AABB.h"
#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
#include <setjmp.h>
#include <cmocka.h>
static void test_no_overlap(void **state)
{
(void) state;
Vector2 a = {0, 5};
Vector2 b = {6, 9};
float overlap = 0;
assert_int_equal(find_1D_overlap(a, b, &overlap), 0);
}
int main(void)
{
const struct CMUnitTest tests[] = {
cmocka_unit_test(test_no_overlap),
};
return cmocka_run_group_tests(tests, NULL, NULL);
}