From dfdb61e5b5773afc6342ef546fa992912fdbbc40 Mon Sep 17 00:00:00 2001 From: odweta Date: Tue, 6 Oct 2026 15:16:21 +0200 Subject: [PATCH 1/3] add munit as a submodule --- .gitmodules | 3 +++ third_party/munit | 1 + 2 files changed, 4 insertions(+) create mode 100644 .gitmodules create mode 160000 third_party/munit diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..4a38623 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "third_party/munit"] + path = third_party/munit + url = https://github.com/nemequ/munit.git diff --git a/third_party/munit b/third_party/munit new file mode 160000 index 0000000..fbbdf14 --- /dev/null +++ b/third_party/munit @@ -0,0 +1 @@ +Subproject commit fbbdf1467eb0d04a6ee465def2e529e4c87f2118 -- 2.54.0 From bcbd03269f8f4cc267b8f7202ad81533f6ecca25 Mon Sep 17 00:00:00 2001 From: odweta Date: Tue, 6 Oct 2026 15:18:43 +0200 Subject: [PATCH 2/3] pin munit version --- third_party/munit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/third_party/munit b/third_party/munit index fbbdf14..ad67a3a 160000 --- a/third_party/munit +++ b/third_party/munit @@ -1 +1 @@ -Subproject commit fbbdf1467eb0d04a6ee465def2e529e4c87f2118 +Subproject commit ad67a3a2ca6b0e106c9c8d515772359eadcefad6 -- 2.54.0 From ce8b44f4e9d5e7ac9760676270f2c5379d873d99 Mon Sep 17 00:00:00 2001 From: odweta Date: Tue, 6 Oct 2026 22:36:39 +0200 Subject: [PATCH 3/3] embed munit into the project --- CMakeLists.txt | 1 + tests/CMakeLists.txt | 40 ++++++++++++++++++++ tests/main.c | 26 +++++++++++++ tests/suites/sdl.c | 90 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 157 insertions(+) create mode 100644 tests/CMakeLists.txt create mode 100644 tests/main.c create mode 100644 tests/suites/sdl.c diff --git a/CMakeLists.txt b/CMakeLists.txt index d7fb178..d75f43f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,3 +10,4 @@ pkg_check_modules(SDL3 REQUIRED IMPORTED_TARGET sdl3) add_subdirectory(src/engine) add_subdirectory(src/examples) +add_subdirectory(tests) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..febbfb0 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,40 @@ +add_library(munit STATIC + "${PROJECT_SOURCE_DIR}/third_party/munit/munit.c" +) + +target_include_directories(munit + PUBLIC + ${PROJECT_SOURCE_DIR}/third_party +) + +file(GLOB TEST_SOURCES CONFIGURE_DEPENDS + "${CMAKE_CURRENT_SOURCE_DIR}/suites/*.c" +) + +add_library(dangerzone_tests STATIC + ${TEST_SOURCES} +) + +target_include_directories(dangerzone_tests + PUBLIC + ${PROJECT_SOURCE_DIR}/include + ${PROJECT_SOURCE_DIR}/src + ${PROJECT_SOURCE_DIR}/third_party +) + +add_executable(test_runner + main.c +) + +target_link_libraries(test_runner + PRIVATE + dangerzone_tests + munit + dangerzone_engine +) + +add_custom_target(test + COMMAND tests/test_runner + DEPENDS test_runner + WORKING_DIRECTORY ${PROJECT_BINARY_DIR} +) \ No newline at end of file diff --git a/tests/main.c b/tests/main.c new file mode 100644 index 0000000..f305e67 --- /dev/null +++ b/tests/main.c @@ -0,0 +1,26 @@ +#include "munit/munit.h" + +extern const MunitSuite sdl_suite; + +int main(int argc, char *argv[]) { + MunitSuite sub_suites[] = { + sdl_suite, + { // terminator + NULL, + NULL, + NULL, + 0, + MUNIT_SUITE_OPTION_NONE + } + }; + + MunitSuite master_suite = { + "", + NULL, + sub_suites, + 1, + MUNIT_SUITE_OPTION_NONE + }; + + return munit_suite_main(&master_suite, NULL, argc, argv); +} \ No newline at end of file diff --git a/tests/suites/sdl.c b/tests/suites/sdl.c new file mode 100644 index 0000000..ff365fc --- /dev/null +++ b/tests/suites/sdl.c @@ -0,0 +1,90 @@ +#include +#include "internal/engine_internal.h" + +#include "munit/munit.h" + +static void* +test_setup( + const MunitParameter params[], + void* data +) { + (void)params; + (void)data; + + internal_state = (engine_internal_state_t *) + malloc(sizeof(engine_internal_state_t)); + munit_assert_not_null(internal_state); + + internal_state->sdl_state = (engine_sdl_state_t *) + malloc(sizeof(engine_sdl_state_t)); + munit_assert_not_null(internal_state->sdl_state); + + internal_state->sdl_state->width = 500; + internal_state->sdl_state->height = 500; + strncpy( + internal_state->sdl_state->window_name, "Dangerzone", + WINDOW_NAME_MAX_LENGTH - 1 + ); + internal_state->sdl_state->window_name[WINDOW_NAME_MAX_LENGTH - 1] = '\0'; + + return internal_state; +} + +static void +test_teardown( + void *fixture +) { + engine_internal_state_t *state = fixture; + + if (state->sdl_state != NULL) { + free(state->sdl_state); + free(state); + } + + internal_state = NULL; +} + +static MunitResult +test_window_parameters( + const MunitParameter params[], + void* data +) { + (void)params; + + engine_internal_state_t *state = data; + + munit_assert_not_null(state); + munit_assert_not_null(state->sdl_state); + munit_assert_int(state->sdl_state->width, ==, 500); + munit_assert_int(state->sdl_state->height, ==, 500); + munit_assert_int(strcmp(state->sdl_state->window_name, "Dangerzone"), ==, 0); + + return MUNIT_OK; +} + +MunitTest tests[] = { + { + "/window-parameters", + test_window_parameters, + test_setup, + test_teardown, + MUNIT_TEST_OPTION_NONE, + NULL + }, + { // terminator + NULL, + NULL, + NULL, + NULL, + MUNIT_TEST_OPTION_NONE, + NULL + } +}; + +const MunitSuite sdl_suite = { + "/sdl", + tests, + NULL, + 1, + MUNIT_SUITE_OPTION_NONE +}; \ No newline at end of file -- 2.54.0