diff --git a/CMakeLists.txt b/CMakeLists.txt index 9087f6c..32325bb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,8 +23,6 @@ project(${APP_NAME} LANGUAGES C ) -option(BUILD_TESTING "Build tests" OFF) - add_executable(${APP_NAME} ${SOURCE_DIR}/backend/output_utils.c ${SOURCE_DIR}/backend/x11/backend.c @@ -99,8 +97,3 @@ configure_file("${SOURCE_DIR}/app.h.in" ESCAPE_QUOTES @ONLY ) - -if(BUILD_TESTING) - enable_testing() - add_subdirectory(tests) -endif() diff --git a/Makefile b/Makefile index f6ef8b7..e96934a 100644 --- a/Makefile +++ b/Makefile @@ -39,18 +39,8 @@ build: prepare @cmake --build $(BUILD_DIR) @cp -lf $(BUILD_DIR)/$(TARGET_NAME) $(TARGET) -build-test: - cmake -S $(SRC_DIR) -B $(BUILD_DIR) -DBUILD_TESTING=ON - cmake --build $(BUILD_DIR) - -test: build-test - ctest --test-dir $(BUILD_DIR) - -test-detail: build-test - ctest --test-dir $(BUILD_DIR) --rerun-failed --output-on-failure - install-hooks: chmod +x $(MAKEFILE_DIR).githooks/pre-commit git -C $(MAKEFILE_DIR) config core.hooksPath $(MAKEFILE_DIR).githooks -.PHONY: clean run wm prepare build install uninstall reinstall test install-hooks +.PHONY: clean run wm prepare build install uninstall reinstall install-hooks diff --git a/build-utils/atoms-extern.sh b/build-utils/atoms-extern.sh deleted file mode 100755 index daf42c7..0000000 --- a/build-utils/atoms-extern.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -echo "/* This file is autogenerated by $0 - do not edit */" -echo -echo "#include " -echo - -while read atom -do - # 去掉首位空格 - atom_clean=$(echo "$atom" | sed 's/^[[:space:]]*//;s/[[:space:]]$//') - - # 跳过空行 - if [[ -n "$atom_clean" ]]; then - echo "extern xcb_atom_t ${atom_clean};" - fi -done < "$1" diff --git a/build-utils/atoms-intern.sh b/build-utils/atoms-intern.sh deleted file mode 100755 index 2b2811d..0000000 --- a/build-utils/atoms-intern.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/bin/bash - -echo "/* This file is autogenerated by $0 - do not edit */" -echo -echo "#include " -echo - -while read atom -do - # 去掉首位空格 - atom_clean=$(echo "$atom" | sed 's/^[[:space:]]*//;s/[[:space:]]$//') - - # 跳过空行 - if [[ -n "$atom_clean" ]]; then - echo "xcb_atom_t ${atom_clean};" - fi -done < "$1" - -echo -echo "typedef struct atom_item_t {" -echo " const char *name;" -echo " size_t len;" -echo " xcb_atom_t *atom;" -echo "} atom_item_t;" -echo -echo "static atom_item_t ATOM_LIST[] = {" - -while read atom -do - # 去掉首位空格 - atom_clean=$(echo "$atom" | sed 's/^[[:space:]]*//;s/[[:space:]]$//') - - # 跳过空行 - if [[ -n "$atom_clean" ]]; then - echo " {\"${atom_clean}\", sizeof(\"${atom_clean}\") - 1, &${atom_clean}}," - fi -done < "$1" - -echo "};" diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt deleted file mode 100644 index d897565..0000000 --- a/tests/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -add_subdirectory(backend) -add_subdirectory(config) -add_subdirectory(core) diff --git a/tests/backend/CMakeLists.txt b/tests/backend/CMakeLists.txt deleted file mode 100644 index d06f286..0000000 --- a/tests/backend/CMakeLists.txt +++ /dev/null @@ -1,23 +0,0 @@ -set(OUTPUT_UTILS_TEST_APP_NAME "zdwm-output-utils-tests") - -add_executable(${OUTPUT_UTILS_TEST_APP_NAME} - ${CMAKE_CURRENT_SOURCE_DIR}/output_utils_test.c - ${SOURCE_DIR}/backend/output_utils.c -) - -target_include_directories(${OUTPUT_UTILS_TEST_APP_NAME} SYSTEM - PRIVATE ${INCLUDE_DIR} -) - -target_include_directories(${OUTPUT_UTILS_TEST_APP_NAME} - PRIVATE ${SOURCE_DIR} - PRIVATE ${BUILD_DIR} -) - -target_link_libraries(${OUTPUT_UTILS_TEST_APP_NAME} - PRIVATE m -) - -add_test(NAME ${OUTPUT_UTILS_TEST_APP_NAME} - COMMAND $ -) diff --git a/tests/backend/output_utils_test.c b/tests/backend/output_utils_test.c deleted file mode 100644 index bd7f971..0000000 --- a/tests/backend/output_utils_test.c +++ /dev/null @@ -1,69 +0,0 @@ -#include "backend/output_utils.h" - -#include -#include - -#include "core/types.h" -#include "utils.h" - -static void assert_output_geometry( - const output_info_t *output, - int32_t x, - int32_t y, - int32_t width, - int32_t height -) { - assert(output); - assert(output->geometry.x == x); - assert(output->geometry.y == y); - assert(output->geometry.width == width); - assert(output->geometry.height == height); -} - -static void destroy_detect_result(backend_detect_t *detect) { - assert(detect); - for (size_t i = 0; i < detect->output_count; i++) { - p_delete(&detect->outputs[i].name); - } - p_delete(&detect->outputs); - free(detect); -} - -static void test_output_remove_duplication_invalid_input(void) { - output_info_t output = {0}; - - assert(output_remove_duplication(nullptr, 0) == nullptr); - assert(output_remove_duplication(&output, 0) == nullptr); -} - -static void test_output_remove_duplication_keeps_non_nested_outputs(void) { - output_info_t outputs[] = { - { - .geometry = {.x = 0, .y = 0, .width = 3840, .height = 1080}, - }, - { - .geometry = {.x = 0, .y = 0, .width = 1920, .height = 1080}, - }, - { - .geometry = {.x = 1920, .y = 0, .width = 1920, .height = 1080}, - }, - { - .geometry = {.x = 3840, .y = 0, .width = 1280, .height = 1024}, - }, - }; - - backend_detect_t *detect = - output_remove_duplication(outputs, countof(outputs)); - assert(detect); - assert(detect->output_count == 2); - assert_output_geometry(&detect->outputs[0], 0, 0, 3840, 1080); - assert_output_geometry(&detect->outputs[1], 3840, 0, 1280, 1024); - - destroy_detect_result(detect); -} - -int main(void) { - test_output_remove_duplication_invalid_input(); - test_output_remove_duplication_keeps_non_nested_outputs(); - return 0; -} diff --git a/tests/config/CMakeLists.txt b/tests/config/CMakeLists.txt deleted file mode 100644 index 4de20dd..0000000 --- a/tests/config/CMakeLists.txt +++ /dev/null @@ -1,90 +0,0 @@ -set(CONFIG_FIXTURE_TARGET "zdwm-config-fixture") -set(CONFIG_FIXTURE_NO_SETUP_TARGET "zdwm-config-fixture-no-setup") -set(CONFIG_LOADER_TEST_APP_NAME "zdwm-config-loader-tests") -set(RUNTIME_CONFIG_TEST_APP_NAME "zdwm-runtime-config-tests") - -add_library(${CONFIG_FIXTURE_TARGET} SHARED - ${CMAKE_CURRENT_SOURCE_DIR}/fixture_valid_config.c -) -target_include_directories(${CONFIG_FIXTURE_TARGET} - PRIVATE ${INCLUDE_DIR} -) - -add_library(${CONFIG_FIXTURE_NO_SETUP_TARGET} SHARED - ${CMAKE_CURRENT_SOURCE_DIR}/fixture_without_setup.c -) - -add_executable(${CONFIG_LOADER_TEST_APP_NAME} - ${CMAKE_CURRENT_SOURCE_DIR}/config_loader_test.c - ${SOURCE_DIR}/base/log.c - ${SOURCE_DIR}/config/loader.c -) -target_include_directories(${CONFIG_LOADER_TEST_APP_NAME} SYSTEM - PRIVATE ${INCLUDE_DIR} -) -target_include_directories(${CONFIG_LOADER_TEST_APP_NAME} - PRIVATE ${SOURCE_DIR} - PRIVATE ${BUILD_DIR} - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} -) -target_link_libraries(${CONFIG_LOADER_TEST_APP_NAME} - PRIVATE ${CMAKE_DL_LIBS} -) -add_dependencies(${CONFIG_LOADER_TEST_APP_NAME} - ${CONFIG_FIXTURE_TARGET} - ${CONFIG_FIXTURE_NO_SETUP_TARGET} -) - -add_executable(${RUNTIME_CONFIG_TEST_APP_NAME} - ${CMAKE_CURRENT_SOURCE_DIR}/runtime_config_test.c - ${SOURCE_DIR}/base/color.c - ${SOURCE_DIR}/base/log.c - ${SOURCE_DIR}/base/window_list.c - ${SOURCE_DIR}/config/defaults.c - ${SOURCE_DIR}/config/loader.c - ${SOURCE_DIR}/config/runtime_config.c - ${SOURCE_DIR}/core/action.c - ${SOURCE_DIR}/core/binding.c - ${SOURCE_DIR}/core/command_buffer.c - ${SOURCE_DIR}/core/event.c - ${SOURCE_DIR}/core/layer.c - ${SOURCE_DIR}/core/layout.c - ${SOURCE_DIR}/core/plan.c - ${SOURCE_DIR}/core/policy.c - ${SOURCE_DIR}/core/rules.c - ${SOURCE_DIR}/core/runtime.c - ${SOURCE_DIR}/core/state.c - ${SOURCE_DIR}/core/window.c - ${SOURCE_DIR}/layouts/fair.c - ${SOURCE_DIR}/layouts/fullscreen.c - ${SOURCE_DIR}/layouts/maximize.c -) -target_include_directories(${RUNTIME_CONFIG_TEST_APP_NAME} SYSTEM - PRIVATE ${INCLUDE_DIR} -) -target_include_directories(${RUNTIME_CONFIG_TEST_APP_NAME} - PRIVATE ${SOURCE_DIR} - PRIVATE ${BUILD_DIR} - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} -) -target_link_libraries(${RUNTIME_CONFIG_TEST_APP_NAME} - PRIVATE m - PRIVATE ${deps_xkbcommon_MODULE_NAME} - PRIVATE ${CMAKE_DL_LIBS} -) -add_dependencies(${RUNTIME_CONFIG_TEST_APP_NAME} - ${CONFIG_FIXTURE_TARGET} - ${CONFIG_FIXTURE_NO_SETUP_TARGET} -) - -add_test(NAME ${CONFIG_LOADER_TEST_APP_NAME} - COMMAND $ - $ - $ -) - -add_test(NAME ${RUNTIME_CONFIG_TEST_APP_NAME} - COMMAND $ - $ - $ -) diff --git a/tests/config/config_loader_test.c b/tests/config/config_loader_test.c deleted file mode 100644 index 417b074..0000000 --- a/tests/config/config_loader_test.c +++ /dev/null @@ -1,200 +0,0 @@ -#include -#include -#include -#include -#include - -#include "config/loader.h" -#include "helpers.h" - -static void test_config_loader_loads_explicit_override( - const char *fixture_path -) { - config_test_clear_env(); - - config_loader_t loader = {0}; - assert(config_loader_load(&loader, fixture_path)); - assert(loader.path); - assert(strcmp(loader.path, fixture_path) == 0); - assert(loader.handle); - assert(loader.setup); - - config_loader_cleanup(&loader); -} - -static void test_config_loader_override_has_priority_over_env( - const char *fixture_path -) { - config_test_clear_env(); - assert( - setenv("ZDWM_CONFIG_LIB", "/tmp/definitely-missing-config.so", 1) == 0 - ); - - config_loader_t loader = {0}; - assert(config_loader_load(&loader, fixture_path)); - assert(loader.path); - assert(strcmp(loader.path, fixture_path) == 0); - assert(loader.handle); - assert(loader.setup); - - config_loader_cleanup(&loader); -} - -static void test_config_loader_uses_zdwm_config_lib_env( - const char *fixture_path -) { - config_test_clear_env(); - assert(setenv("ZDWM_CONFIG_LIB", fixture_path, 1) == 0); - - config_loader_t loader = {0}; - assert(config_loader_load(&loader, nullptr)); - assert(loader.path); - assert(strcmp(loader.path, fixture_path) == 0); - assert(loader.handle); - assert(loader.setup); - - config_loader_cleanup(&loader); -} - -static void test_config_loader_uses_xdg_config_home(const char *fixture_path) { - config_test_clear_env(); - - char temp_root[PATH_MAX] = {0}; - char config_dir[PATH_MAX] = {0}; - char config_path[PATH_MAX] = {0}; - - config_test_make_temp_dir( - temp_root, - sizeof(temp_root), - "zdwm-config-loader-xdg" - ); - config_test_join_path(config_dir, sizeof(config_dir), temp_root, "zdwm"); - config_test_join_path( - config_path, - sizeof(config_path), - config_dir, - "config.so" - ); - config_test_mkdir(config_dir); - config_test_symlink(fixture_path, config_path); - assert(setenv("XDG_CONFIG_HOME", temp_root, 1) == 0); - - config_loader_t loader = {0}; - assert(config_loader_load(&loader, nullptr)); - assert(loader.path); - assert(strcmp(loader.path, config_path) == 0); - assert(loader.handle); - assert(loader.setup); - - config_loader_cleanup(&loader); - config_test_unlink(config_path); - config_test_rmdir(config_dir); - config_test_rmdir(temp_root); -} - -static void test_config_loader_uses_home_fallback(const char *fixture_path) { - config_test_clear_env(); - - char temp_root[PATH_MAX] = {0}; - char config_root[PATH_MAX] = {0}; - char zdwm_dir[PATH_MAX] = {0}; - char config_path[PATH_MAX] = {0}; - - config_test_make_temp_dir( - temp_root, - sizeof(temp_root), - "zdwm-config-loader-home" - ); - config_test_join_path(config_root, sizeof(config_root), temp_root, ".config"); - config_test_join_path(zdwm_dir, sizeof(zdwm_dir), config_root, "zdwm"); - config_test_join_path( - config_path, - sizeof(config_path), - zdwm_dir, - "config.so" - ); - config_test_mkdir(config_root); - config_test_mkdir(zdwm_dir); - config_test_symlink(fixture_path, config_path); - assert(setenv("HOME", temp_root, 1) == 0); - - config_loader_t loader = {0}; - assert(config_loader_load(&loader, nullptr)); - assert(loader.path); - assert(strcmp(loader.path, config_path) == 0); - assert(loader.handle); - assert(loader.setup); - - config_loader_cleanup(&loader); - config_test_unlink(config_path); - config_test_rmdir(zdwm_dir); - config_test_rmdir(config_root); - config_test_rmdir(temp_root); -} - -static void test_config_loader_allows_missing_implicit_library(void) { - config_test_clear_env(); - - char temp_root[PATH_MAX] = {0}; - char expected_path[PATH_MAX] = {0}; - - config_test_make_temp_dir( - temp_root, - sizeof(temp_root), - "zdwm-config-loader-missing" - ); - config_test_join_path( - expected_path, - sizeof(expected_path), - temp_root, - "zdwm/config.so" - ); - assert(setenv("XDG_CONFIG_HOME", temp_root, 1) == 0); - - config_loader_t loader = {0}; - assert(config_loader_load(&loader, nullptr)); - assert(loader.path); - assert(strcmp(loader.path, expected_path) == 0); - assert(loader.handle == nullptr); - assert(loader.setup == nullptr); - - config_loader_cleanup(&loader); - config_test_rmdir(temp_root); -} - -static void test_config_loader_rejects_missing_explicit_library(void) { - config_test_clear_env(); - - config_loader_t loader = {0}; - assert(!config_loader_load(&loader, "/tmp/definitely-missing-config.so")); - assert(loader.path == nullptr); - assert(loader.handle == nullptr); - assert(loader.setup == nullptr); -} - -static void test_config_loader_rejects_library_without_setup( - const char *fixture_path -) { - config_test_clear_env(); - - config_loader_t loader = {0}; - assert(!config_loader_load(&loader, fixture_path)); - assert(loader.path == nullptr); - assert(loader.handle == nullptr); - assert(loader.setup == nullptr); -} - -int main(int argc, char **argv) { - assert(argc == 3); - - test_config_loader_loads_explicit_override(argv[1]); - test_config_loader_override_has_priority_over_env(argv[1]); - test_config_loader_uses_zdwm_config_lib_env(argv[1]); - test_config_loader_uses_xdg_config_home(argv[1]); - test_config_loader_uses_home_fallback(argv[1]); - test_config_loader_allows_missing_implicit_library(); - test_config_loader_rejects_missing_explicit_library(); - test_config_loader_rejects_library_without_setup(argv[2]); - - return 0; -} diff --git a/tests/config/fixture_valid_config.c b/tests/config/fixture_valid_config.c deleted file mode 100644 index 4768839..0000000 --- a/tests/config/fixture_valid_config.c +++ /dev/null @@ -1,45 +0,0 @@ -#include - -static bool -fixture_layout(const zdwm_layout_ctx_t *ctx, zdwm_layout_result_t *out) { - if (!ctx || !out) return false; - - zdwm_layout_result_reset(out); - if (!ctx->window_ids || ctx->window_count == 0) return true; - - zdwm_layout_result_push( - out, - (zdwm_layout_item_t){ - .window_id = ctx->window_ids[0], - .rect = ctx->workarea, - } - ); - return true; -} - -bool setup( - const zdwm_api_t *api, - zdwm_config_builder_t *builder, - const zdwm_output_info_t *outputs, - size_t output_count -) { - if (!api || !builder || !outputs || output_count == 0) return false; - - zdwm_layout_id_t layout_id = api->register_layout( - builder, - "test-only", - "[T]", - "fixture layout", - fixture_layout - ); - if (layout_id == ZDWM_LAYOUT_ID_INVALID) return false; - - return api->define_workspace( - builder, - 0, - "from-so", - &layout_id, - 1, - layout_id - ) != ZDWM_WORKSPACE_ID_INVALID; -} diff --git a/tests/config/fixture_without_setup.c b/tests/config/fixture_without_setup.c deleted file mode 100644 index e355136..0000000 --- a/tests/config/fixture_without_setup.c +++ /dev/null @@ -1 +0,0 @@ -int zdwm_config_fixture_without_setup_symbol(void) { return 1; } diff --git a/tests/config/helpers.h b/tests/config/helpers.h deleted file mode 100644 index 171b6e4..0000000 --- a/tests/config/helpers.h +++ /dev/null @@ -1,51 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include - -static inline void config_test_clear_env(void) { - assert(unsetenv("ZDWM_CONFIG_LIB") == 0); - assert(unsetenv("XDG_CONFIG_HOME") == 0); - assert(unsetenv("HOME") == 0); -} - -static inline void -config_test_make_temp_dir(char *path, size_t path_size, const char *prefix) { - int len = snprintf(path, path_size, "/tmp/%s-XXXXXX", prefix); - assert(len > 0); - assert((size_t)len < path_size); - assert(mkdtemp(path) == path); -} - -static inline void config_test_join_path( - char *out, - size_t out_size, - const char *base, - const char *suffix -) { - int len = snprintf(out, out_size, "%s/%s", base, suffix); - assert(len > 0); - assert((size_t)len < out_size); -} - -static inline void config_test_mkdir(const char *path) { - assert(mkdir(path, 0700) == 0); -} - -static inline void config_test_symlink(const char *target, const char *path) { - assert(symlink(target, path) == 0); -} - -static inline void config_test_unlink(const char *path) { - assert(unlink(path) == 0); -} - -static inline void config_test_rmdir(const char *path) { - assert(rmdir(path) == 0); -} diff --git a/tests/config/runtime_config_test.c b/tests/config/runtime_config_test.c deleted file mode 100644 index 9f53c33..0000000 --- a/tests/config/runtime_config_test.c +++ /dev/null @@ -1,236 +0,0 @@ -#include "config/runtime_config.h" - -#include -#include -#include -#include -#include - -#include "core/layout.h" -#include "core/runtime.h" -#include "helpers.h" - -struct backend_t { - int unused; -}; - -void backend_destroy(backend_t *backend) { free(backend); } - -bool backend_next_event(backend_t *backend, event_t *event) { - (void)backend; - (void)event; - return false; -} - -bool backend_apply_effect( - backend_t *backend, - const effect_t *effects, - size_t effect_count -) { - return false; -} - -static backend_t *test_backend_create(void) { - return calloc(1, sizeof(backend_t)); -} - -static void assert_default_layouts(const runtime_init_desc_t *desc) { - assert(desc); - assert(layout_registry_count(&desc->layouts) == 4); - - const layout_slot_t *fair = layout_registry_at(&desc->layouts, 0); - const layout_slot_t *maximize = layout_registry_at(&desc->layouts, 1); - const layout_slot_t *fullscreen = layout_registry_at(&desc->layouts, 2); - const layout_slot_t *floating = layout_registry_at(&desc->layouts, 3); - - assert(fair); - assert(maximize); - assert(fullscreen); - assert(floating); - assert(strcmp(fair->name, "fair") == 0); - assert(strcmp(maximize->name, "maximize") == 0); - assert(strcmp(fullscreen->name, "fullscreen") == 0); - assert(strcmp(floating->name, "floating") == 0); -} - -static void test_runtime_config_loads_user_library(const char *fixture_path) { - config_test_clear_env(); - - output_info_t outputs[] = { - { - .name = "HDMI-A-1", - .geometry = {.x = 0, .y = 0, .width = 1920, .height = 1080}, - }, - }; - - runtime_init_desc_t desc = { - .outputs = outputs, - .output_count = 1, - }; - assert(runtime_config_load(fixture_path, &desc)); - assert(desc.config_module_handle != nullptr); - assert(layout_registry_count(&desc.layouts) == 1); - assert(desc.workspace_count == 1); - assert(strcmp(desc.workspaces[0].name, "from-so") == 0); - assert(desc.workspaces[0].output_index == 0); - assert(desc.workspaces[0].layout_count == 1); - assert(desc.workspaces[0].initial_layout_id == 0); - - const layout_slot_t *layout = layout_registry_at(&desc.layouts, 0); - assert(layout); - assert(strcmp(layout->name, "test-only") == 0); - assert(strcmp(layout->symbol, "[T]") == 0); - - runtime_config_cleanup(&desc); -} - -static void test_runtime_config_keeps_module_loaded_after_runtime_init( - const char *fixture_path -) { - config_test_clear_env(); - - output_info_t outputs[] = { - { - .name = "HDMI-A-1", - .geometry = {.x = 0, .y = 0, .width = 1920, .height = 1080}, - }, - }; - window_id_t window_ids[] = {42}; - - runtime_init_desc_t desc = { - .backend = test_backend_create(), - .outputs = outputs, - .output_count = 1, - }; - assert(desc.backend); - assert(runtime_config_load(fixture_path, &desc)); - - runtime_t runtime = {0}; - assert(runtime_init(&runtime, &desc)); - assert(desc.config_module_handle == nullptr); - runtime_init_desc_cleanup(&desc); - - assert(runtime.config_module_handle != nullptr); - - layout_fn layout = layout_get(&runtime.layouts, 0); - assert(layout != nullptr); - - layout_result_t result = {0}; - - layout_ctx_t ctx = { - .workspace_id = 0, - .focused_window_id = window_ids[0], - .workarea = {.x = 11, .y = 22, .width = 333, .height = 444}, - .window_ids = window_ids, - .window_count = 1, - }; - assert(layout(&ctx, &result)); - assert(result.item_count == 1); - assert(result.items[0].window_id == window_ids[0]); - assert(result.items[0].rect.x == ctx.workarea.x); - assert(result.items[0].rect.y == ctx.workarea.y); - assert(result.items[0].rect.width == ctx.workarea.width); - assert(result.items[0].rect.height == ctx.workarea.height); - - layout_result_cleanup(&result); - runtime_shutdown(&runtime); - assert(runtime.config_module_handle == nullptr); -} - -static void -test_runtime_config_falls_back_to_defaults_when_implicit_library_is_missing( - void -) { - config_test_clear_env(); - - output_info_t outputs[] = { - { - .name = "eDP-1", - .geometry = {.x = 0, .y = 0, .width = 1920, .height = 1080}, - }, - { - .name = "DP-1", - .geometry = {.x = 1920, .y = 0, .width = 2560, .height = 1440}, - }, - }; - - char temp_root[PATH_MAX] = {0}; - config_test_make_temp_dir( - temp_root, - sizeof(temp_root), - "zdwm-runtime-config-missing" - ); - assert(setenv("XDG_CONFIG_HOME", temp_root, 1) == 0); - - runtime_init_desc_t desc = { - .outputs = outputs, - .output_count = 2, - }; - assert(runtime_config_load(nullptr, &desc)); - assert(desc.config_module_handle == nullptr); - assert_default_layouts(&desc); - assert(desc.workspace_count == 2); - assert(strcmp(desc.workspaces[0].name, "main") == 0); - assert(strcmp(desc.workspaces[1].name, "main") == 0); - assert(desc.workspaces[0].output_index == 0); - assert(desc.workspaces[1].output_index == 1); - - runtime_config_cleanup(&desc); - config_test_rmdir(temp_root); -} - -static void test_runtime_config_rejects_missing_explicit_library(void) { - config_test_clear_env(); - - output_info_t outputs[] = { - { - .name = "HDMI-A-1", - .geometry = {.x = 0, .y = 0, .width = 1920, .height = 1080}, - }, - }; - - runtime_init_desc_t desc = { - .outputs = outputs, - .output_count = 1, - }; - assert(!runtime_config_load("/tmp/definitely-missing-config.so", &desc)); - assert(layout_registry_count(&desc.layouts) == 0); - assert(desc.workspace_count == 0); - assert(desc.workspaces == nullptr); - assert(desc.config_module_handle == nullptr); -} - -static void test_runtime_config_rejects_library_without_setup( - const char *fixture_path -) { - config_test_clear_env(); - - output_info_t outputs[] = { - { - .name = "HDMI-A-1", - .geometry = {.x = 0, .y = 0, .width = 1920, .height = 1080}, - }, - }; - - runtime_init_desc_t desc = { - .outputs = outputs, - .output_count = 1, - }; - assert(!runtime_config_load(fixture_path, &desc)); - assert(layout_registry_count(&desc.layouts) == 0); - assert(desc.workspace_count == 0); - assert(desc.workspaces == nullptr); - assert(desc.config_module_handle == nullptr); -} - -int main(int argc, char **argv) { - assert(argc == 3); - - test_runtime_config_loads_user_library(argv[1]); - test_runtime_config_keeps_module_loaded_after_runtime_init(argv[1]); - test_runtime_config_falls_back_to_defaults_when_implicit_library_is_missing(); - test_runtime_config_rejects_missing_explicit_library(); - test_runtime_config_rejects_library_without_setup(argv[2]); - - return 0; -} diff --git a/tests/core/CMakeLists.txt b/tests/core/CMakeLists.txt deleted file mode 100644 index 89a6cec..0000000 --- a/tests/core/CMakeLists.txt +++ /dev/null @@ -1,55 +0,0 @@ -set(TEST_APP_NAME "zdwm-tests") - -add_executable(${TEST_APP_NAME} - ${CMAKE_CURRENT_SOURCE_DIR}/main.c - ${SOURCE_DIR}/base/color.c - ${SOURCE_DIR}/base/log.c - ${SOURCE_DIR}/base/window_list.c - ${SOURCE_DIR}/backend/output_utils.c - ${SOURCE_DIR}/config/defaults.c - ${SOURCE_DIR}/config/loader.c - ${SOURCE_DIR}/config/runtime_config.c - ${SOURCE_DIR}/backend/x11/backend.c - ${SOURCE_DIR}/backend/x11/event.c - ${SOURCE_DIR}/backend/x11/window.c - ${SOURCE_DIR}/core/action.c - ${SOURCE_DIR}/core/binding.c - ${SOURCE_DIR}/core/command_buffer.c - ${SOURCE_DIR}/core/event.c - ${SOURCE_DIR}/core/layer.c - ${SOURCE_DIR}/core/layout.c - ${SOURCE_DIR}/core/plan.c - ${SOURCE_DIR}/core/policy.c - ${SOURCE_DIR}/core/rules.c - ${SOURCE_DIR}/core/runtime.c - ${SOURCE_DIR}/core/state.c - ${SOURCE_DIR}/core/window.c - ${SOURCE_DIR}/layouts/fair.c - ${SOURCE_DIR}/layouts/fullscreen.c - ${SOURCE_DIR}/layouts/maximize.c -) - -target_include_directories(${TEST_APP_NAME} SYSTEM - PRIVATE ${deps_INCLUDE_DIRS} - PRIVATE ${INCLUDE_DIR} -) -target_include_directories(${TEST_APP_NAME} - PRIVATE ${SOURCE_DIR} - PRIVATE ${BUILD_DIR} -) - -target_link_libraries(${TEST_APP_NAME} - PRIVATE m - PRIVATE ${CMAKE_DL_LIBS} - PRIVATE ${deps_LIBRARIES} -) - -if(HAS_EXECINFO AND LIB_EXECINFO) - target_link_libraries(${TEST_APP_NAME} PRIVATE ${LIB_EXECINFO}) -endif() - -add_test(NAME ${TEST_APP_NAME} COMMAND $) - -set_tests_properties(${TEST_APP_NAME} PROPERTIES - ENVIRONMENT "DISPLAY=:3" -) diff --git a/tests/core/main.c b/tests/core/main.c deleted file mode 100644 index d652f52..0000000 --- a/tests/core/main.c +++ /dev/null @@ -1,56 +0,0 @@ -#include -#include - -#include "base/log.h" -#include "config/runtime_config.h" -#include "core/backend.h" -#include "core/runtime.h" - -static void bootstrap(runtime_t *runtime) { - backend_t *backend = backend_create(nullptr); - backend_detect_t *detect = backend_detect(backend); - - if (!backend || !detect || detect->output_count == 0) { - fatal("backend detect failed"); - } - - runtime_init_desc_t desc = { - .backend = backend, - .outputs = detect->outputs, - .output_count = detect->output_count, - }; - if (!runtime_config_load(nullptr, &desc)) { - fatal("failed to build runtime inputs"); - } - - backend = nullptr; - - bool inited = runtime_init(runtime, &desc); - - runtime_init_desc_cleanup(&desc); - backend_detect_destroy(detect); - - if (!inited) { - fatal("zdwm runtime init failed"); - } -}; - -char **cmd_argv = nullptr; - -int main(int argc, char *argv[]) { - cmd_argv = argv; - - runtime_t runtime = {0}; - - bootstrap(&runtime); - runtime_setup(&runtime); - runtime_run(&runtime); - runtime_shutdown(&runtime); - - if (runtime.will_restart) { - execvp(cmd_argv[0], cmd_argv); - fatal("execv() failed: %s", strerror(errno)); - } - - return 0; -}