From 81e8cd67198768a08f5c65ec026e1553f78e1375 Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Wed, 30 Sep 2020 14:22:42 +0200 Subject: Make tests explicitly use Basic where necessary The previous commit changes the how the default style is set, and since the tests all assumed that Basic was the default, we now need to ensure it is explicitly set. If we want to, we can revert this patch (or file-by-file) later and ensure that these tests work with all styles. For now, just keep things working as they used to. Tests that use QTEST_QUICKCONTROLS_MAIN are not changed, as they already run with all built-in styles. Tests that don't use types that will cause issues, like tst_qquickcolor, do not need to be changed. tst_snippets can be run manually to produce screenshots, so we specify its style in a qtquickcontrols2.conf file to allow it to be overridden by e.g. application arguments (QQuickStyle::setStyle() takes precedence over all other approaches of setting a style). Change-Id: Ifae7e959f89a41a757c170272038fad139bba04f Reviewed-by: Qt CI Bot Reviewed-by: Volker Hilsheimer --- tests/auto/cursor/tst_cursor.cpp | 9 +++++++++ tests/auto/designer/tst_designer.cpp | 1 + tests/auto/focus/tst_focus.cpp | 1 + tests/auto/font/tst_font.cpp | 8 ++++++++ tests/auto/palette/tst_palette.cpp | 4 ++-- tests/auto/pressandhold/CMakeLists.txt | 1 + tests/auto/pressandhold/pressandhold.pro | 2 +- tests/auto/pressandhold/tst_pressandhold.cpp | 9 +++++++++ .../qquickapplicationwindow/tst_qquickapplicationwindow.cpp | 7 +++++++ tests/auto/qquickiconimage/tst_qquickiconimage.cpp | 1 + tests/auto/qquickstyle/tst_qquickstyle.cpp | 2 -- tests/auto/revisions/CMakeLists.txt | 1 + tests/auto/revisions/revisions.pro | 2 +- tests/auto/revisions/tst_revisions.cpp | 9 +++++++++ tests/auto/snippets/CMakeLists.txt | 13 +++++++++++++ tests/auto/snippets/qtquickcontrols2.conf | 3 +++ tests/auto/snippets/snippets.pro | 3 +++ tests/auto/translation/tst_translation.cpp | 9 +++++++++ 18 files changed, 79 insertions(+), 6 deletions(-) create mode 100644 tests/auto/snippets/qtquickcontrols2.conf (limited to 'tests') diff --git a/tests/auto/cursor/tst_cursor.cpp b/tests/auto/cursor/tst_cursor.cpp index ed5db5b1..37a9e0c1 100644 --- a/tests/auto/cursor/tst_cursor.cpp +++ b/tests/auto/cursor/tst_cursor.cpp @@ -43,6 +43,7 @@ #include #include #include +#include #if QT_CONFIG(cursor) # include @@ -55,6 +56,9 @@ class tst_cursor : public QQmlDataTest { Q_OBJECT +public: + tst_cursor(); + private slots: void init(); void controls_data(); @@ -64,6 +68,11 @@ private slots: void scrollBar(); }; +tst_cursor::tst_cursor() +{ + QQuickStyle::setStyle("Basic"); +} + void tst_cursor::init() { #if QT_CONFIG(cursor) diff --git a/tests/auto/designer/tst_designer.cpp b/tests/auto/designer/tst_designer.cpp index 64a27858..0f6598a6 100644 --- a/tests/auto/designer/tst_designer.cpp +++ b/tests/auto/designer/tst_designer.cpp @@ -57,6 +57,7 @@ private slots: void tst_Designer::initTestCase() { + QQuickStyle::setStyle("Basic"); } void doComponentCompleteRecursive(QObject *object) diff --git a/tests/auto/focus/tst_focus.cpp b/tests/auto/focus/tst_focus.cpp index 8117d90d..b3f7c9a1 100644 --- a/tests/auto/focus/tst_focus.cpp +++ b/tests/auto/focus/tst_focus.cpp @@ -74,6 +74,7 @@ private slots: void tst_focus::initTestCase() { + QQuickStyle::setStyle("Basic"); QQmlDataTest::initTestCase(); } diff --git a/tests/auto/font/tst_font.cpp b/tests/auto/font/tst_font.cpp index 0794e761..aeaa49f8 100644 --- a/tests/auto/font/tst_font.cpp +++ b/tests/auto/font/tst_font.cpp @@ -53,6 +53,9 @@ class tst_font : public QQmlDataTest { Q_OBJECT +public: + tst_font(); + private slots: void systemFont(); @@ -83,6 +86,11 @@ static QFont testFont() return var.value(); } +tst_font::tst_font() +{ + QQuickStyle::setStyle("Basic"); +} + void tst_font::systemFont() { QSKIP("QTBUG-70063: qmlClearTypeRegistrations() call causes crash"); diff --git a/tests/auto/palette/tst_palette.cpp b/tests/auto/palette/tst_palette.cpp index 6e41ca49..b69f03b4 100644 --- a/tests/auto/palette/tst_palette.cpp +++ b/tests/auto/palette/tst_palette.cpp @@ -84,10 +84,10 @@ private slots: void tst_palette::initTestCase() { - QQmlDataTest::initTestCase(); - QQuickStyle::setStyle("Basic"); + QQmlDataTest::initTestCase(); + // Import QtQuick.Controls to initialize styles and themes so that // QQuickControlPrivate::themePalette() returns a palette from the // style's theme instead of the platform's theme. diff --git a/tests/auto/pressandhold/CMakeLists.txt b/tests/auto/pressandhold/CMakeLists.txt index a5c1b845..32793510 100644 --- a/tests/auto/pressandhold/CMakeLists.txt +++ b/tests/auto/pressandhold/CMakeLists.txt @@ -10,6 +10,7 @@ qt_add_test(tst_pressandhold PUBLIC_LIBRARIES Qt::Gui Qt::Quick + Qt::QuickControls2 ) #### Keys ignored in scope 1:.:.:pressandhold.pro:: diff --git a/tests/auto/pressandhold/pressandhold.pro b/tests/auto/pressandhold/pressandhold.pro index db0d6288..57bc452e 100644 --- a/tests/auto/pressandhold/pressandhold.pro +++ b/tests/auto/pressandhold/pressandhold.pro @@ -1,7 +1,7 @@ TEMPLATE = app TARGET = tst_pressandhold -QT += quick testlib +QT += quick testlib quickcontrols2 CONFIG += testcase macos:CONFIG -= app_bundle diff --git a/tests/auto/pressandhold/tst_pressandhold.cpp b/tests/auto/pressandhold/tst_pressandhold.cpp index 1bfed129..f58bea03 100644 --- a/tests/auto/pressandhold/tst_pressandhold.cpp +++ b/tests/auto/pressandhold/tst_pressandhold.cpp @@ -36,11 +36,15 @@ #include #include +#include class tst_PressAndHold : public QObject { Q_OBJECT +public: + tst_PressAndHold(); + private slots: void initTestCase(); void cleanupTestCase(); @@ -52,6 +56,11 @@ private slots: void keepSelection(); }; +tst_PressAndHold::tst_PressAndHold() +{ + QQuickStyle::setStyle("Basic"); +} + void tst_PressAndHold::initTestCase() { QGuiApplication::styleHints()->setMousePressAndHoldInterval(100); diff --git a/tests/auto/qquickapplicationwindow/tst_qquickapplicationwindow.cpp b/tests/auto/qquickapplicationwindow/tst_qquickapplicationwindow.cpp index c57cf92e..b2535ccb 100644 --- a/tests/auto/qquickapplicationwindow/tst_qquickapplicationwindow.cpp +++ b/tests/auto/qquickapplicationwindow/tst_qquickapplicationwindow.cpp @@ -60,7 +60,9 @@ using namespace QQuickVisualTestUtil; class tst_QQuickApplicationWindow : public QQmlDataTest { Q_OBJECT + public: + tst_QQuickApplicationWindow(); private slots: void qmlCreation(); @@ -81,6 +83,11 @@ private slots: void opacity(); }; +tst_QQuickApplicationWindow::tst_QQuickApplicationWindow() +{ + QQuickStyle::setStyle("Basic"); +} + void tst_QQuickApplicationWindow::qmlCreation() { QQmlEngine engine; diff --git a/tests/auto/qquickiconimage/tst_qquickiconimage.cpp b/tests/auto/qquickiconimage/tst_qquickiconimage.cpp index 7dacda35..370d2ef4 100644 --- a/tests/auto/qquickiconimage/tst_qquickiconimage.cpp +++ b/tests/auto/qquickiconimage/tst_qquickiconimage.cpp @@ -95,6 +95,7 @@ tst_qquickiconimage::tst_qquickiconimage() : dpr(qGuiApp->devicePixelRatio()), integerDpr(qCeil(dpr)) { + QQuickStyle::setStyle("Basic"); } void tst_qquickiconimage::initTestCase() diff --git a/tests/auto/qquickstyle/tst_qquickstyle.cpp b/tests/auto/qquickstyle/tst_qquickstyle.cpp index 37915315..907dbd13 100644 --- a/tests/auto/qquickstyle/tst_qquickstyle.cpp +++ b/tests/auto/qquickstyle/tst_qquickstyle.cpp @@ -91,8 +91,6 @@ void tst_QQuickStyle::unloadControls() void tst_QQuickStyle::lookup() { - QCOMPARE(QQuickStyle::name(), QString()); - QQuickStyle::setStyle("Material"); QCOMPARE(QQuickStyle::name(), QString("Material")); diff --git a/tests/auto/revisions/CMakeLists.txt b/tests/auto/revisions/CMakeLists.txt index be0754fc..fbed2b6a 100644 --- a/tests/auto/revisions/CMakeLists.txt +++ b/tests/auto/revisions/CMakeLists.txt @@ -10,6 +10,7 @@ qt_add_test(tst_revisions PUBLIC_LIBRARIES Qt::Gui Qt::Qml + Qt::QuickControls2 ) ## Scopes: diff --git a/tests/auto/revisions/revisions.pro b/tests/auto/revisions/revisions.pro index b3c448da..67fb2977 100644 --- a/tests/auto/revisions/revisions.pro +++ b/tests/auto/revisions/revisions.pro @@ -4,4 +4,4 @@ SOURCES += tst_revisions.cpp macos:CONFIG -= app_bundle -QT += qml testlib +QT += qml testlib quickcontrols2 diff --git a/tests/auto/revisions/tst_revisions.cpp b/tests/auto/revisions/tst_revisions.cpp index 8eeec016..0d4518cc 100644 --- a/tests/auto/revisions/tst_revisions.cpp +++ b/tests/auto/revisions/tst_revisions.cpp @@ -38,11 +38,15 @@ #include #include #include +#include class tst_revisions : public QObject { Q_OBJECT +public: + tst_revisions(); + private slots: void revisions_data(); void revisions(); @@ -51,6 +55,11 @@ private slots: void window(); }; +tst_revisions::tst_revisions() +{ + QQuickStyle::setStyle("Basic"); +} + void tst_revisions::revisions_data() { QTest::addColumn("revision"); diff --git a/tests/auto/snippets/CMakeLists.txt b/tests/auto/snippets/CMakeLists.txt index 71bec579..6a9bbc5f 100644 --- a/tests/auto/snippets/CMakeLists.txt +++ b/tests/auto/snippets/CMakeLists.txt @@ -23,6 +23,19 @@ qt_add_test(tst_snippets TESTDATA ${test_data} ) +# Resources: +set(qmake_immediate_resource_files + "qtquickcontrols2.conf" +) + +qt_add_resource(tst_snippets "qmake_immediate" + PREFIX + "/" + FILES + ${qmake_immediate_resource_files} +) + + #### Keys ignored in scope 1:.:.:snippets.pro:: # OTHER_FILES = "$$PWD/data/*.qml" # TEMPLATE = "app" diff --git a/tests/auto/snippets/qtquickcontrols2.conf b/tests/auto/snippets/qtquickcontrols2.conf new file mode 100644 index 00000000..bd157776 --- /dev/null +++ b/tests/auto/snippets/qtquickcontrols2.conf @@ -0,0 +1,3 @@ +# Specify the style here so that it can be overridden by e.g. command line arguments. +[Controls] +Style=Basic diff --git a/tests/auto/snippets/snippets.pro b/tests/auto/snippets/snippets.pro index 9fa65055..0f12ae12 100644 --- a/tests/auto/snippets/snippets.pro +++ b/tests/auto/snippets/snippets.pro @@ -13,5 +13,8 @@ SOURCES += \ OTHER_FILES += \ $$PWD/data/*.qml +RESOURCES += \ + qtquickcontrols2.conf + TESTDATA += \ $$PWD/data/* diff --git a/tests/auto/translation/tst_translation.cpp b/tests/auto/translation/tst_translation.cpp index 81eb0b77..58ce86cc 100644 --- a/tests/auto/translation/tst_translation.cpp +++ b/tests/auto/translation/tst_translation.cpp @@ -46,6 +46,7 @@ #include #include #include +#include using namespace QQuickVisualTestUtil; @@ -53,12 +54,20 @@ class tst_translation : public QQmlDataTest { Q_OBJECT +public: + tst_translation(); + private slots: void dialogButtonBox(); void dialogButtonBoxWithCustomButtons(); void comboBox(); }; +tst_translation::tst_translation() +{ + QQuickStyle::setStyle("Basic"); +} + void tst_translation::dialogButtonBox() { QQuickView view(testFileUrl("dialogButtonBox.qml")); -- cgit v1.2.3