diff --git a/CMakeLists.txt b/CMakeLists.txt index 0a04cd8..f60aa10 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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() + diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..7f11eac --- /dev/null +++ b/tests/CMakeLists.txt @@ -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) diff --git a/tests/test_AABB.c b/tests/test_AABB.c new file mode 100644 index 0000000..42f9b22 --- /dev/null +++ b/tests/test_AABB.c @@ -0,0 +1,25 @@ +#include "AABB.h" + +#include +#include +#include +#include +#include + +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); +}