From b8ef9883c892f8135baa2da245955feae978da7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mika=C3=ABl=20Capelle?= Date: Fri, 9 Aug 2024 12:47:13 +0200 Subject: [PATCH] Allow for external mo2-cmake (#160) * Create standalone feature for mo2-cmake. * Setup a QCoreApplication in tests main. --- .github/workflows/build.yml | 2 +- CMakePresets.json | 15 +++++++++------ tests/CMakeLists.txt | 3 ++- tests/test_main.cpp | 15 +++++++++++++++ tests/test_strings.cpp | 9 +++++++++ tests/translations/tests_en.qm | Bin 0 -> 141 bytes tests/translations/tests_en.ts | 11 +++++++++++ tests/translations/tests_fr.qm | Bin 0 -> 147 bytes tests/translations/tests_fr.ts | 11 +++++++++++ vcpkg-configuration.json | 21 --------------------- vcpkg.json | 21 ++++++++++++++++++++- 11 files changed, 78 insertions(+), 30 deletions(-) create mode 100644 tests/test_main.cpp create mode 100644 tests/translations/tests_en.qm create mode 100644 tests/translations/tests_en.ts create mode 100644 tests/translations/tests_fr.qm create mode 100644 tests/translations/tests_fr.ts delete mode 100644 vcpkg-configuration.json diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f685a376..e5ceb1be 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -36,7 +36,7 @@ jobs: - name: Configure UI Base build shell: pwsh run: | - cmake --preset vs2022-windows ` + cmake --preset vs2022-windows-standalone ` "-DCMAKE_PREFIX_PATH=${env:QT_ROOT_DIR}\msvc2019_64" ` "-DCMAKE_INSTALL_PREFIX=install" -DUIBASE_TESTING=ON diff --git a/CMakePresets.json b/CMakePresets.json index 0c06d1a3..f0e338e3 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -50,13 +50,16 @@ "inherits": ["cmake-dev", "vcpkg-dev"], "name": "vs2022-windows", "toolset": "v143" - } - ], - "buildPresets": [ + }, { - "name": "vs2022-windows", - "resolvePackageReferences": "on", - "configurePreset": "vs2022-windows" + "cacheVariables": { + "VCPKG_MANIFEST_FEATURES": { + "type": "STRING", + "value": "standalone;testing" + } + }, + "inherits": "vs2022-windows", + "name": "vs2022-windows-standalone" } ], "version": 4 diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index ac17234a..7ff9e192 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -3,10 +3,11 @@ cmake_minimum_required(VERSION 3.16) add_executable(uibase-tests EXCLUDE_FROM_ALL) target_sources(uibase-tests PRIVATE + test_main.cpp test_formatters.cpp test_ifiletree.cpp test_strings.cpp test_versioning.cpp ) -mo2_configure_tests(uibase-tests NO_SOURCES WARNINGS 4) +mo2_configure_tests(uibase-tests NO_SOURCES NO_MAIN NO_MOCK WARNINGS 4) target_link_libraries(uibase-tests PRIVATE uibase) diff --git a/tests/test_main.cpp b/tests/test_main.cpp new file mode 100644 index 00000000..0399b433 --- /dev/null +++ b/tests/test_main.cpp @@ -0,0 +1,15 @@ +#include + +#include +#include + +int main(int argc, char** argv) +{ + QCoreApplication app(argc, argv); + QTranslator translator; + if (translator.load("tests_fr", "tests/translations")) { + app.installTranslator(&translator); + } + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/tests/test_strings.cpp b/tests/test_strings.cpp index 69dadbbf..56e75c9b 100644 --- a/tests/test_strings.cpp +++ b/tests/test_strings.cpp @@ -3,6 +3,8 @@ #include #pragma warning(pop) +#include + #include #include @@ -31,3 +33,10 @@ TEST(StringsTest, IReplaceAll) ireplace_all("replace some stuff with some stuff som", "some", "a")); ASSERT_EQ("1YYY3YYY2", ireplace_all("1aBc3AbC2", "abC", "YYY")); } + +// this is more a tests of the tests +TEST(StringsTest, Translation) +{ + ASSERT_EQ("Traduction en Français", + QCoreApplication::translate("uibase-tests", "Translate to French")); +} diff --git a/tests/translations/tests_en.qm b/tests/translations/tests_en.qm new file mode 100644 index 0000000000000000000000000000000000000000..d5ca50195d8899565e374e2405b25297d85c8ced GIT binary patch literal 141 zcmcE7ks@*G{hX<16=n7(EZlo{IRgU&YieG6Xs{EI#lil4=?@^ykO{<5%s@hoA%vlb zA(0`Ep_m~DNS83AGAIDad?4utlt~53Br{}ifHbiIv2aLHVqS4hVo9n(Nxp(xQEFat c20Kukr!+Guu{c$?B(=Dtn6U#W!o + + + + uibase-tests + + Translate to French + Translate to French + + + diff --git a/tests/translations/tests_fr.qm b/tests/translations/tests_fr.qm new file mode 100644 index 0000000000000000000000000000000000000000..80958d6e11a850ede8d6266c2a39254a0abce8ba GIT binary patch literal 147 zcmcE7ks@*G{hX<16=n7(EZlo{IRgU&Yg$pfTaXiw#lil4=?@^ykO{;I%s@hiA%vlb zA(0`4p_Cz+p#&(A&ydHUz>o?i-N15r49|foG8u|FKw8;=SU998F|Rl$u_RTYBwxX; gC^auRgB>W&Q<|BSSe&X`l3H9+%-8`GVPa+k0Fgu_wEzGB literal 0 HcmV?d00001 diff --git a/tests/translations/tests_fr.ts b/tests/translations/tests_fr.ts new file mode 100644 index 00000000..eed02a06 --- /dev/null +++ b/tests/translations/tests_fr.ts @@ -0,0 +1,11 @@ + + + + + uibase-tests + + Translate to French + Traduction en Français + + + diff --git a/vcpkg-configuration.json b/vcpkg-configuration.json deleted file mode 100644 index 2e5c2a90..00000000 --- a/vcpkg-configuration.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "default-registry": { - "kind": "git", - "repository": "https://github.com/Microsoft/vcpkg", - "baseline": "f61a294e765b257926ae9e9d85f96468a0af74e7" - }, - "registries": [ - { - "kind": "git", - "repository": "https://github.com/Microsoft/vcpkg", - "baseline": "f61a294e765b257926ae9e9d85f96468a0af74e7", - "packages": ["boost*", "boost-*"] - }, - { - "kind": "git", - "repository": "https://github.com/ModOrganizer2/vcpkg-registry", - "baseline": "6e9492a38a7d5bfeeeaf80723fa821b42f3a26a8", - "packages": ["mo2-cmake", "spdlog"] - } - ] -} diff --git a/vcpkg.json b/vcpkg.json index 563f4f91..6c1e8c9d 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -1,5 +1,5 @@ { - "dependencies": ["mo2-cmake", "spdlog"], + "dependencies": ["spdlog"], "overrides": [ { "name": "spdlog", @@ -7,9 +7,28 @@ } ], "features": { + "standalone": { + "description": "Build Standalone.", + "dependencies": ["mo2-cmake"] + }, "testing": { "description": "Build UI Base tests.", "dependencies": ["gtest"] } + }, + "vcpkg-configuration": { + "default-registry": { + "kind": "git", + "repository": "https://github.com/Microsoft/vcpkg", + "baseline": "8ae59b5b1329a51875abc71d528da93d9c3e8972" + }, + "registries": [ + { + "kind": "git", + "repository": "https://github.com/ModOrganizer2/vcpkg-registry", + "baseline": "84ff92223433d101738a3c6cef96fa6ae6a6f302", + "packages": ["mo2-cmake", "spdlog"] + } + ] } }