diff --git a/tests/unit/tests/unittests/designsystem/CMakeLists.txt b/tests/unit/tests/unittests/designsystem/CMakeLists.txt index 113381a5554..bf2fcf2da24 100644 --- a/tests/unit/tests/unittests/designsystem/CMakeLists.txt +++ b/tests/unit/tests/unittests/designsystem/CMakeLists.txt @@ -1,8 +1,18 @@ extend_qtc_test(unittest - DEPENDS - QmlDesignerUtils DesignSystem SOURCES dsthemegroup-test.cpp dsthememgr-test.cpp dsthemeqml-test.cpp ) + +extend_qtc_test(unittest + SOURCES_PREFIX "${QML_DESIGNER_DIRECTORY}/libs/designsystem" + INCLUDES "${QML_DESIGNER_DIRECTORY}/libs/designsystem" + DEFINES DESIGNSYSTEM_STATIC_LIBRARY + DEPENDS + Qt::Core Qt::Widgets QmlDesignerUtils TestDesignerCore + SOURCES + dsconstants.h + dsthemegroup.h dsthemegroup.cpp + dsthememanager.h dsthememanager.cpp +) diff --git a/tests/unit/tests/unittests/designsystem/dsthemegroup-test.cpp b/tests/unit/tests/unittests/designsystem/dsthemegroup-test.cpp index bf4c0f14788..8908ce38338 100644 --- a/tests/unit/tests/unittests/designsystem/dsthemegroup-test.cpp +++ b/tests/unit/tests/unittests/designsystem/dsthemegroup-test.cpp @@ -12,19 +12,28 @@ using QmlDesigner::DSThemeGroup; using QmlDesigner::ThemeProperty; namespace { -constexpr const char testPropertyNameFoo[] = "propFoo"; -constexpr const char testPropertyNameBar[] = "propBar"; +QByteArray testPropertyNameFoo = "propFoo"; +QByteArray testPropertyNameBar = "propBar"; constexpr QmlDesigner::ThemeId themeId1 = 0; constexpr QmlDesigner::ThemeId themeId2 = 1; -MATCHER_P3(HasPropertyCount, themeId, themePropCount, totalPropsCount, "") +MATCHER_P3(HasPropertyCount, + themeId, + themePropCount, + totalPropsCount, + std::string(negation ? "hasn't " : "has ") + "total property count " + + PrintToString(totalPropsCount) + " and theme property count " + + PrintToString(themePropCount)) { const DSThemeGroup &group = arg; return group.count() == totalPropsCount && group.count(themeId) == themePropCount; } -MATCHER_P2(HasThemeProperty, themeId, themeProp, "") +MATCHER_P2(HasThemeProperty, + themeId, + themeProp, + std::string(negation ? "hasn't " : "has ") + PrintToString(themeProp)) { const DSThemeGroup &group = arg; const std::optional prop = group.propertyValue(themeId, themeProp.name); diff --git a/tests/unit/tests/unittests/designsystem/dsthememgr-test.cpp b/tests/unit/tests/unittests/designsystem/dsthememgr-test.cpp index 02a2e56cabc..638e31b9853 100644 --- a/tests/unit/tests/unittests/designsystem/dsthememgr-test.cpp +++ b/tests/unit/tests/unittests/designsystem/dsthememgr-test.cpp @@ -11,8 +11,6 @@ #include -#include - using QmlDesigner::DSThemeManager; using QmlDesigner::GroupType; using QmlDesigner::Import; @@ -30,9 +28,7 @@ MATCHER_P3(HasProperty, themeId, group, themeProp, - std::format("Collection {} have a property {}", - (negation ? "Does't " : "Does "), - PrintToString(themeProp))) + std::string(negation ? "hasn't " : "has ") + PrintToString(themeProp)) { const DSThemeManager &mgr = arg; const std::optional prop = mgr.property(themeId, group, themeProp.name); diff --git a/tests/unit/tests/unittests/designsystem/dsthemeqml-test.cpp b/tests/unit/tests/unittests/designsystem/dsthemeqml-test.cpp index 602a1b356d8..5951ee830c0 100644 --- a/tests/unit/tests/unittests/designsystem/dsthemeqml-test.cpp +++ b/tests/unit/tests/unittests/designsystem/dsthemeqml-test.cpp @@ -13,8 +13,9 @@ #include #include -#include #include +#include +#include using QmlDesigner::DSThemeManager; using QmlDesigner::GroupType; @@ -22,40 +23,24 @@ using QmlDesigner::Import; using QmlDesigner::ModelNode; using QmlDesigner::ThemeProperty; -template<> -struct std::formatter : std::formatter -{ - template - auto format(const QByteArray &ba, FormatContext &ctx) const - { - return std::formatter::format(ba.toStdString(), ctx); - } -}; - namespace { - -static std::string formatedPropStr(const char tag[], const char name[], const QVariant &v) +std::string formatedPropStr(std::string tag, const QByteArray &name, const QVariant &value) { - return std::format("{}Property({}, {})", tag, name, v.toString().toStdString()); + return tag + "Property(" + name.toStdString() + ", " + value.toString().toStdString() + ")"; } -static auto bindingPropStr = std::bind(&formatedPropStr, - "Binding", - std::placeholders::_1, - std::placeholders::_2); -static auto variantPropStr = std::bind(&formatedPropStr, - "Variant", - std::placeholders::_1, - std::placeholders::_2); +auto bindingPropStr = std::bind_front(&formatedPropStr, "Binding"); +auto variantPropStr = std::bind_front(&formatedPropStr, "Variant"); -constexpr const char testPropertyName1[] = "prop1"; -constexpr const char darkThemeName[] = "dark"; +QByteArray testPropertyName1 = "prop1"; +QByteArray darkThemeName = "dark"; constexpr QmlDesigner::ThemeId testThemeId = 1; MATCHER_P2(HasNodeProperty, name, typeName, - std::format("{} have node {} with type {})", (negation ? "Does't " : "Does "), name, typeName)) + std::string(negation ? "hasn't node " : "has node ") + name.toStdString() + + std::string(" with type ") + typeName) { ModelNode n = arg; return n.hasNodeProperty(name) && n.nodeProperty(name).modelNode().isValid() @@ -65,7 +50,7 @@ MATCHER_P2(HasNodeProperty, MATCHER_P2(HasBindingProperty, name, value, - std::format("{} have {})", (negation ? "Does't " : "Does "), bindingPropStr(name, value))) + std::string(negation ? "hasn't " : "has ") + bindingPropStr(name, value)) { ModelNode n = arg; return n.hasBindingProperty(name) && n.bindingProperty(name).expression() == value; @@ -74,7 +59,7 @@ MATCHER_P2(HasBindingProperty, MATCHER_P2(HasVariantProperty, name, value, - std::format("{} have {})", (negation ? "Does't " : "Does "), variantPropStr(name, value))) + std::string(negation ? "hasn't " : "has ") + variantPropStr(name, value)) { ModelNode n = arg; return n.hasVariantProperty(name) && n.variantProperty(name).value() == value; @@ -83,10 +68,8 @@ MATCHER_P2(HasVariantProperty, MATCHER_P2(HasGroupVariantProperty, groupName, themeProp, - std::format("{} have node {} with {})", - (negation ? "Does't " : "Does "), - groupName.constData(), - PrintToString(themeProp))) + std::string(negation ? "hasn't node " : "has node ") + groupName.toStdString() + " with " + + PrintToString(themeProp)) { ModelNode n = arg; @@ -99,10 +82,8 @@ MATCHER_P2(HasGroupVariantProperty, MATCHER_P2(HasGroupBindingProperty, groupName, themeProp, - std::format("{} have node {} with {})", - (negation ? "Does't " : "Does "), - groupName.constData(), - PrintToString(themeProp))) + std::string(negation ? "hasn't node " : "has node ") + groupName.toStdString() + " with " + + PrintToString(themeProp)) { ModelNode n = arg;