diff options
| author | Felix Morgner <felix.morgner@gmail.com> | 2018-12-07 22:12:12 +0100 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@gmail.com> | 2018-12-07 22:12:12 +0100 |
| commit | 32a24dfd5c5ca2cac3c303e82c9ebe7cc7ff28ab (patch) | |
| tree | 9a7a6ec731209ef365ab604b83855a09a4332e20 | |
| parent | 6a9d54e287526c1b3ee7656d94e71f933f685624 (diff) | |
| download | wanda-32a24dfd5c5ca2cac3c303e82c9ebe7cc7ff28ab.tar.xz wanda-32a24dfd5c5ca2cac3c303e82c9ebe7cc7ff28ab.zip | |
core: begin implementing tests
| -rw-r--r-- | CMakeLists.txt | 22 | ||||
| -rw-r--r-- | cmake/Modules/CUTE.cmake | 11 | ||||
| -rw-r--r-- | tests/core_driver.cpp | 18 | ||||
| -rw-r--r-- | tests/test_suite_xdg.cpp | 95 | ||||
| -rw-r--r-- | tests/test_suite_xdg.hpp | 16 |
5 files changed, 162 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 86de9c9..6d8a867 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,7 @@ list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/Modules") include("ConanDependencies") include("SystemDependencies") +include("CUTE") ##### Wanda CORE ##### @@ -51,6 +52,7 @@ set(WANDA_CORE_LIBRARIES add_library("wanda" ${WANDA_CORE_SOURCES} ${WANDA_CORE_HEADERS}) target_link_libraries("wanda" ${WANDA_CORE_LIBRARIES}) +target_include_directories("wanda" INTERFACE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>) set_target_properties("wanda" PROPERTIES PUBLIC_HEADER "${WANDA_CORE_HEADERS}") install(TARGETS "wanda" ARCHIVE DESTINATION "lib" PUBLIC_HEADER DESTINATION "include") @@ -100,3 +102,23 @@ set(WANDA_CONTROLLER_LIBRARIES add_executable("wandac" ${WANDA_CONTROLLER_SOURCES} ${WANDA_CONTROLLER_HEADERS}) target_link_libraries("wandac" ${WANDA_CONTROLLER_LIBRARIES}) install(TARGETS "wandac" RUNTIME DESTINATION "bin") + +##### Wanda Core Tests ##### +if(CUTE_FOUND) + set(WANDA_CORE_TESTS_SUITE_SOURCES + "tests/test_suite_xdg.cpp" + ) + + set(WANDA_CORE_TESTS_SUITE_HEADERS + "tests/test_suite_xdg.hpp" + ) + + set(WANDA_CORE_TESTS_LIBRARIES + "wanda" + "LIB::CUTE" + ) + + add_executable("wanda_core_tests" "tests/core_driver.cpp" ${WANDA_CORE_TESTS_SUITE_SOURCES} ${WANDA_CORE_TESTS_SUITE_HEADERS}) + target_link_libraries("wanda_core_tests" ${WANDA_CORE_TESTS_LIBRARIES}) + add_test(NAME "wanda_core_tests" COMMAND "wanda_core_tests") +endif()
\ No newline at end of file diff --git a/cmake/Modules/CUTE.cmake b/cmake/Modules/CUTE.cmake new file mode 100644 index 0000000..1f0e7df --- /dev/null +++ b/cmake/Modules/CUTE.cmake @@ -0,0 +1,11 @@ +if(NOT EXISTS "${PROJECT_SOURCE_DIR}/lib/cute/cute/cute.h") + message(STATUS "CUTE: Submodule 'lib/cute' not checked out. Disabling tests.") + set(CUTE_FOUND OFF) +else() + message(STATUS "CUTE: Found submodule 'lib/cute'. Enabling tests.") + include("CTest") + enable_testing() + add_library("LIB::CUTE" INTERFACE IMPORTED) + set_property(TARGET "LIB::CUTE" PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${PROJECT_SOURCE_DIR}/lib/cute") + set(CUTE_FOUND ON) +endif()
\ No newline at end of file diff --git a/tests/core_driver.cpp b/tests/core_driver.cpp new file mode 100644 index 0000000..3643da0 --- /dev/null +++ b/tests/core_driver.cpp @@ -0,0 +1,18 @@ +#include "test_suite_xdg.hpp" + +#include "cute/cute.h" +#include "cute/cute_runner.h" +#include "cute/tap_listener.h" + +#include <algorithm> +#include <iostream> +#include <iterator> +#include <vector> + +int main(int argc, char const *const *argv) +{ + auto listener = cute::tap_listener<>{std::cout}; + auto runner = cute::makeRunner(listener, argc, argv); + auto suites = std::vector<std::pair<cute::suite, std::string>>{wanda::test_suite_xdg()}; + return !all_of(cbegin(suites), cend(suites), [&](auto const &suite) { return runner(suite.first, suite.second.c_str()); }); +}
\ No newline at end of file diff --git a/tests/test_suite_xdg.cpp b/tests/test_suite_xdg.cpp new file mode 100644 index 0000000..48f3eaa --- /dev/null +++ b/tests/test_suite_xdg.cpp @@ -0,0 +1,95 @@ +#include "test_suite_xdg.hpp" +#include "xdg.hpp" + +#include "cute/cute.h" + +#include <unistd.h> + +#include <filesystem> + +namespace wanda +{ + +namespace +{ + char const * home_only_environment[2] = {"HOME=/home/cute"}; + char const * xdg_data_home_environment[2] = {"XDG_DATA_HOME=/home/cute/xdg_data_home"}; + char const * xdg_config_home_environment[2] = {"XDG_CONFIG_HOME=/home/cute/xdg_config_home"}; + char const * xdg_cache_home_environment[2] = {"XDG_CACHE_HOME=/home/cute/xdg_cache_home"}; + char const * xdg_runtime_dir_environment[2] = {"XDG_RUNTIME_DIR=/home/cute/xdg_runtime_dir"}; +} + +void test_xdg_variables() +{ + ASSERT_EQUAL("XDG_DATA_HOME", xdg_variable(xdg_directory::data_home)); + ASSERT_EQUAL("XDG_CONFIG_HOME", xdg_variable(xdg_directory::config_home)); + ASSERT_EQUAL("XDG_CACHE_HOME", xdg_variable(xdg_directory::cache_home)); + ASSERT_EQUAL("XDG_RUNTIME_DIR", xdg_variable(xdg_directory::runtime_dir)); +} + +void test_xdg_path_for_data_home_without_xdg_data_home_in_environment() +{ + auto env = environment{home_only_environment}; + ASSERT_EQUAL("/home/cute/.local/share", xdg_path_for(xdg_directory::data_home, env)); +} + +void test_xdg_path_for_data_home_with_xdg_data_home_in_environment() +{ + auto env = environment{xdg_data_home_environment}; + ASSERT_EQUAL("/home/cute/xdg_data_home", xdg_path_for(xdg_directory::data_home, env)); +} + +void test_xdg_path_for_config_home_without_xdg_config_home_in_environment() +{ + auto env = environment{home_only_environment}; + ASSERT_EQUAL("/home/cute/.config", xdg_path_for(xdg_directory::config_home, env)); +} + +void test_xdg_path_for_config_home_with_xdg_config_home_in_environment() +{ + auto env = environment{xdg_config_home_environment}; + ASSERT_EQUAL("/home/cute/xdg_config_home", xdg_path_for(xdg_directory::config_home, env)); +} + +void test_xdg_path_for_cache_home_without_xdg_cache_home_in_environment() +{ + auto env = environment{home_only_environment}; + ASSERT_EQUAL("/home/cute/.cache", xdg_path_for(xdg_directory::cache_home, env)); +} + +void test_xdg_path_for_cache_home_with_xdg_cache_home_in_environment() +{ + auto env = environment{xdg_cache_home_environment}; + ASSERT_EQUAL("/home/cute/xdg_cache_home", xdg_path_for(xdg_directory::cache_home, env)); +} + +void test_xdg_path_for_runtime_dir_without_xdg_runtime_dir_in_environment() +{ + auto env = environment{home_only_environment}; + auto expected = std::filesystem::path{"/run/user"} / std::to_string(::getuid()); + ASSERT_EQUAL(expected, xdg_path_for(xdg_directory::runtime_dir, env)); +} + +void test_xdg_path_for_runtime_dir_with_xdg_runtime_dir_in_environment() +{ + auto env = environment{xdg_runtime_dir_environment}; + ASSERT_EQUAL("/home/cute/xdg_runtime_dir", xdg_path_for(xdg_directory::runtime_dir, env)); +} + +std::pair<cute::suite, std::string> test_suite_xdg() +{ + return std::make_pair(cute::suite{ + CUTE(test_xdg_variables), + CUTE(test_xdg_path_for_data_home_without_xdg_data_home_in_environment), + CUTE(test_xdg_path_for_data_home_with_xdg_data_home_in_environment), + CUTE(test_xdg_path_for_config_home_without_xdg_config_home_in_environment), + CUTE(test_xdg_path_for_config_home_with_xdg_config_home_in_environment), + CUTE(test_xdg_path_for_cache_home_without_xdg_cache_home_in_environment), + CUTE(test_xdg_path_for_cache_home_with_xdg_cache_home_in_environment), + CUTE(test_xdg_path_for_runtime_dir_without_xdg_runtime_dir_in_environment), + CUTE(test_xdg_path_for_runtime_dir_with_xdg_runtime_dir_in_environment), + }, + "XDG Utilities"); +} + +} // namespace wanda
\ No newline at end of file diff --git a/tests/test_suite_xdg.hpp b/tests/test_suite_xdg.hpp new file mode 100644 index 0000000..698ad9a --- /dev/null +++ b/tests/test_suite_xdg.hpp @@ -0,0 +1,16 @@ +#ifndef WANDA_TEST_SUITE_XDG_HPP +#define WANDA_TEST_SUITE_XDG_HPP + +#include "cute/cute.h" + +#include <string> +#include <utility> + +namespace wanda +{ + +std::pair<cute::suite, std::string> test_suite_xdg(); + +} // namespace wanda + +#endif
\ No newline at end of file |
