diff options
| -rw-r--r-- | CMakeLists.txt | 1 | ||||
| -rw-r--r-- | lang/CMakeLists.txt | 16 | ||||
| -rw-r--r-- | lang/tests/translations.cpp | 29 | ||||
| -rw-r--r-- | test_support/CMakeLists.txt | 23 | ||||
| -rw-r--r-- | test_support/src/intl_main.cpp | 13 |
5 files changed, 81 insertions, 1 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 1ee538f..a554edc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,6 +15,7 @@ include("GlibCompileResources") include("GNUInstallDirs") find_package("Gettext" REQUIRED) +find_package("Intl" REQUIRED) find_package("PkgConfig" REQUIRED) check_ipo_supported(RESULT CAN_DO_IPO LANGUAGES CXX) diff --git a/lang/CMakeLists.txt b/lang/CMakeLists.txt index 4bc985c..9ba960b 100644 --- a/lang/CMakeLists.txt +++ b/lang/CMakeLists.txt @@ -35,4 +35,18 @@ target_compile_definitions("lang" INTERFACE "LOCALEDIR=\"${CMAKE_INSTALL_FULL_LOCALEDIR}\"" ) -add_dependencies("lang" "mofiles")
\ No newline at end of file +add_dependencies("lang" "mofiles") + +# Tests + +add_executable("lang-tests" + "tests/translations.cpp" +) + +target_link_libraries("lang-tests" PRIVATE + "Catch2::Catch2" + + "turns::intl-test-main" +) + +catch_discover_tests("lang-tests")
\ No newline at end of file diff --git a/lang/tests/translations.cpp b/lang/tests/translations.cpp new file mode 100644 index 0000000..1bb78a5 --- /dev/null +++ b/lang/tests/translations.cpp @@ -0,0 +1,29 @@ +#include <catch2/catch_test_macros.hpp> +#include <catch2/generators/catch_generators.hpp> + +#include <libintl.h> + +#include <format> +#include <string> + +TEST_CASE("All supported languages have translations") +{ + auto message = GENERATE( + "Turns", + "Add a participant", + "No active turn-order", + "_Quit" + ); + + auto locale = GENERATE( + "de_CH.UTF-8", + "de_DE.UTF-8", + "de_AT.UTF-8" + ); + + SECTION(std::format("'{}' has a translation in '{}'", message, locale)) + { + setlocale(LC_ALL, locale); + REQUIRE(std::string{gettext(message)} != message); + } +} diff --git a/test_support/CMakeLists.txt b/test_support/CMakeLists.txt index fe30782..bb2ae4f 100644 --- a/test_support/CMakeLists.txt +++ b/test_support/CMakeLists.txt @@ -1,5 +1,7 @@ get_target_property(TRANSLATIONS_BINARY_DIR "lang" BINARY_DIR) +# GTK test support + add_library("test_support-gtk" OBJECT "src/gtk_main.cpp" ) @@ -20,3 +22,24 @@ target_link_libraries("test_support-gtk" PUBLIC "PkgConfig::adwaita" "PkgConfig::gtkmm" ) + +# Intl test support + +add_library("test_support-intl" OBJECT + "src/intl_main.cpp" +) + +add_library("turns::intl-test-main" ALIAS "test_support-intl") + +target_compile_features("test_support-intl" PRIVATE + "cxx_std_23" +) + +target_compile_definitions("test_support-intl" PUBLIC + "TESTLOCALEDIR=\"${TRANSLATIONS_BINARY_DIR}\"" +) + +target_link_libraries("test_support-intl" PUBLIC + "Intl::Intl" + "turns::lang" +) diff --git a/test_support/src/intl_main.cpp b/test_support/src/intl_main.cpp new file mode 100644 index 0000000..4a74ac5 --- /dev/null +++ b/test_support/src/intl_main.cpp @@ -0,0 +1,13 @@ +#include <catch2/catch_session.hpp> + +#include <libintl.h> + +auto main(int argc, char * argv[]) -> int +{ + setlocale(LC_ALL, ""); + bindtextdomain("turns", TESTLOCALEDIR); + bind_textdomain_codeset("turns", "UTF-8"); + textdomain("turns"); + + return Catch::Session().run(argc, argv); +}
\ No newline at end of file |
