Skip to content

Commit

Permalink
Allow for external mo2-cmake (#160)
Browse files Browse the repository at this point in the history
* Create standalone feature for mo2-cmake.
* Setup a QCoreApplication in tests main.
  • Loading branch information
Holt59 authored and mikael-capelle committed Oct 4, 2024
1 parent 4c93514 commit b8ef988
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 9 additions & 6 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
15 changes: 15 additions & 0 deletions tests/test_main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <gtest/gtest.h>

#include <QCoreApplication>
#include <QTranslator>

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();
}
9 changes: 9 additions & 0 deletions tests/test_strings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <gtest/gtest.h>
#pragma warning(pop)

#include <QCoreApplication>

#include <uibase/strings.h>

#include <format>
Expand Down Expand Up @@ -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"));
}
Binary file added tests/translations/tests_en.qm
Binary file not shown.
11 changes: 11 additions & 0 deletions tests/translations/tests_en.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="en_US">
<context>
<name>uibase-tests</name>
<message>
<source>Translate to French</source>
<translation>Translate to French</translation>
</message>
</context>
</TS>
Binary file added tests/translations/tests_fr.qm
Binary file not shown.
11 changes: 11 additions & 0 deletions tests/translations/tests_fr.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="fr_FR">
<context>
<name>uibase-tests</name>
<message>
<source>Translate to French</source>
<translation>Traduction en Français</translation>
</message>
</context>
</TS>
21 changes: 0 additions & 21 deletions vcpkg-configuration.json

This file was deleted.

21 changes: 20 additions & 1 deletion vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,34 @@
{
"dependencies": ["mo2-cmake", "spdlog"],
"dependencies": ["spdlog"],
"overrides": [
{
"name": "spdlog",
"version": "1.14.1"
}
],
"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"]
}
]
}
}

0 comments on commit b8ef988

Please sign in to comment.