Skip to content

Commit 643f77e

Browse files
committed
Allow for external mo2-cmake (#160)
* Create standalone feature for mo2-cmake. * Setup a QCoreApplication in tests main.
1 parent 7810e03 commit 643f77e

11 files changed

Lines changed: 78 additions & 30 deletions

File tree

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
- name: Configure UI Base build
3737
shell: pwsh
3838
run: |
39-
cmake --preset vs2022-windows `
39+
cmake --preset vs2022-windows-standalone `
4040
"-DCMAKE_PREFIX_PATH=${env:QT_ROOT_DIR}\msvc2019_64" `
4141
"-DCMAKE_INSTALL_PREFIX=install" -DUIBASE_TESTING=ON
4242

CMakePresets.json

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,16 @@
5050
"inherits": ["cmake-dev", "vcpkg-dev"],
5151
"name": "vs2022-windows",
5252
"toolset": "v143"
53-
}
54-
],
55-
"buildPresets": [
53+
},
5654
{
57-
"name": "vs2022-windows",
58-
"resolvePackageReferences": "on",
59-
"configurePreset": "vs2022-windows"
55+
"cacheVariables": {
56+
"VCPKG_MANIFEST_FEATURES": {
57+
"type": "STRING",
58+
"value": "standalone;testing"
59+
}
60+
},
61+
"inherits": "vs2022-windows",
62+
"name": "vs2022-windows-standalone"
6063
}
6164
],
6265
"version": 4

tests/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ cmake_minimum_required(VERSION 3.16)
33
add_executable(uibase-tests EXCLUDE_FROM_ALL)
44
target_sources(uibase-tests
55
PRIVATE
6+
test_main.cpp
67
test_formatters.cpp
78
test_ifiletree.cpp
89
test_strings.cpp
910
test_versioning.cpp
1011
)
11-
mo2_configure_tests(uibase-tests NO_SOURCES WARNINGS 4)
12+
mo2_configure_tests(uibase-tests NO_SOURCES NO_MAIN NO_MOCK WARNINGS 4)
1213
target_link_libraries(uibase-tests PRIVATE uibase)

tests/test_main.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include <gtest/gtest.h>
2+
3+
#include <QCoreApplication>
4+
#include <QTranslator>
5+
6+
int main(int argc, char** argv)
7+
{
8+
QCoreApplication app(argc, argv);
9+
QTranslator translator;
10+
if (translator.load("tests_fr", "tests/translations")) {
11+
app.installTranslator(&translator);
12+
}
13+
testing::InitGoogleTest(&argc, argv);
14+
return RUN_ALL_TESTS();
15+
}

tests/test_strings.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#include <gtest/gtest.h>
44
#pragma warning(pop)
55

6+
#include <QCoreApplication>
7+
68
#include <uibase/strings.h>
79

810
#include <format>
@@ -31,3 +33,10 @@ TEST(StringsTest, IReplaceAll)
3133
ireplace_all("replace some stuff with some stuff som", "some", "a"));
3234
ASSERT_EQ("1YYY3YYY2", ireplace_all("1aBc3AbC2", "abC", "YYY"));
3335
}
36+
37+
// this is more a tests of the tests
38+
TEST(StringsTest, Translation)
39+
{
40+
ASSERT_EQ("Traduction en Français",
41+
QCoreApplication::translate("uibase-tests", "Translate to French"));
42+
}

tests/translations/tests_en.qm

141 Bytes
Binary file not shown.

tests/translations/tests_en.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!DOCTYPE TS>
3+
<TS version="2.1" language="en_US">
4+
<context>
5+
<name>uibase-tests</name>
6+
<message>
7+
<source>Translate to French</source>
8+
<translation>Translate to French</translation>
9+
</message>
10+
</context>
11+
</TS>

tests/translations/tests_fr.qm

147 Bytes
Binary file not shown.

tests/translations/tests_fr.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!DOCTYPE TS>
3+
<TS version="2.1" language="fr_FR">
4+
<context>
5+
<name>uibase-tests</name>
6+
<message>
7+
<source>Translate to French</source>
8+
<translation>Traduction en Français</translation>
9+
</message>
10+
</context>
11+
</TS>

vcpkg-configuration.json

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)