aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@qt.io>2020-09-30 14:22:42 +0200
committerMitch Curtis <mitch.curtis@qt.io>2020-10-07 13:31:20 +0200
commit81e8cd67198768a08f5c65ec026e1553f78e1375 (patch)
treedccf23caaf08f06e3436e43993be8fa74093a1d0
parent8b534487044dfb3b464431ecb91ef4e0864af4ed (diff)
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 <qt_ci_bot@qt-project.org> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
-rw-r--r--src/quickcontrols2/qquickstyle.cpp5
-rw-r--r--src/quickcontrols2/qquickstyle_p.h1
-rw-r--r--src/quickcontrols2/qquickstyleplugin.cpp4
-rw-r--r--tests/auto/cursor/tst_cursor.cpp9
-rw-r--r--tests/auto/designer/tst_designer.cpp1
-rw-r--r--tests/auto/focus/tst_focus.cpp1
-rw-r--r--tests/auto/font/tst_font.cpp8
-rw-r--r--tests/auto/palette/tst_palette.cpp4
-rw-r--r--tests/auto/pressandhold/CMakeLists.txt1
-rw-r--r--tests/auto/pressandhold/pressandhold.pro2
-rw-r--r--tests/auto/pressandhold/tst_pressandhold.cpp9
-rw-r--r--tests/auto/qquickapplicationwindow/tst_qquickapplicationwindow.cpp7
-rw-r--r--tests/auto/qquickiconimage/tst_qquickiconimage.cpp1
-rw-r--r--tests/auto/qquickstyle/tst_qquickstyle.cpp2
-rw-r--r--tests/auto/revisions/CMakeLists.txt1
-rw-r--r--tests/auto/revisions/revisions.pro2
-rw-r--r--tests/auto/revisions/tst_revisions.cpp9
-rw-r--r--tests/auto/snippets/CMakeLists.txt13
-rw-r--r--tests/auto/snippets/qtquickcontrols2.conf3
-rw-r--r--tests/auto/snippets/snippets.pro3
-rw-r--r--tests/auto/translation/tst_translation.cpp9
21 files changed, 88 insertions, 7 deletions
diff --git a/src/quickcontrols2/qquickstyle.cpp b/src/quickcontrols2/qquickstyle.cpp
index 5b45a98a..7ad4a38d 100644
--- a/src/quickcontrols2/qquickstyle.cpp
+++ b/src/quickcontrols2/qquickstyle.cpp
@@ -260,6 +260,11 @@ struct QQuickStyleSpec
Q_GLOBAL_STATIC(QQuickStyleSpec, styleSpec)
+QString QQuickStylePrivate::style()
+{
+ return styleSpec()->style;
+}
+
QString QQuickStylePrivate::effectiveStyleName(const QString &styleName)
{
return !styleName.isEmpty() ? styleName : QLatin1String("Basic");
diff --git a/src/quickcontrols2/qquickstyle_p.h b/src/quickcontrols2/qquickstyle_p.h
index e2db35d7..8d0e5a8d 100644
--- a/src/quickcontrols2/qquickstyle_p.h
+++ b/src/quickcontrols2/qquickstyle_p.h
@@ -58,6 +58,7 @@ class QSettings;
class Q_QUICKCONTROLS2_EXPORT QQuickStylePrivate
{
public:
+ static QString style();
static QString effectiveStyleName(const QString &styleName);
static QString fallbackStyle();
static bool isCustomStyle();
diff --git a/src/quickcontrols2/qquickstyleplugin.cpp b/src/quickcontrols2/qquickstyleplugin.cpp
index 730a8423..27299b21 100644
--- a/src/quickcontrols2/qquickstyleplugin.cpp
+++ b/src/quickcontrols2/qquickstyleplugin.cpp
@@ -63,7 +63,9 @@ void QQuickStylePlugin::registerTypes(const char *uri)
qCDebug(lcStylePlugin).nospace() << "registerTypes called with uri " << uri << "; plugin name is " << name();
const QTypeRevision latestControlsRevision = QQmlMetaType::latestModuleVersion(QLatin1String("QtQuick.Controls"));
- QString styleName = QQuickStyle::name();
+ // Use the private function because we don't want to cause resolve() to be called,
+ // as the logic that assigns a default style if one wasn't set would interfere with compile-time style selection.
+ QString styleName = QQuickStylePrivate::style();
if (!latestControlsRevision.isValid() && styleName.isEmpty()) {
// The user hasn't imported QtQuick.Controls, nor set a style via the runtime methods.
qCDebug(lcStylePlugin).nospace() << uri << " imported before QtQuick.Controls; using compile-time style selection";
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 <QtQuickTemplates2/private/qquickpageindicator_p.h>
#include <QtQuickTemplates2/private/qquickscrollbar_p.h>
#include <QtQuickTemplates2/private/qquicktextarea_p.h>
+#include <QtQuickControls2/qquickstyle.h>
#if QT_CONFIG(cursor)
# include <QtGui/qscreen.h>
@@ -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<QFont>();
}
+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:<TRUE>:
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 <QtTest>
#include <QtQuick>
+#include <QtQuickControls2/qquickstyle.h>
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 <QtTest/qsignalspy.h>
#include <QtQml/qqmlengine.h>
#include <QtQml/qqmlcomponent.h>
+#include <QtQuickControls2/qquickstyle.h>
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<int>("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:<TRUE>:
# 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 <QtQuickTemplates2/private/qquickdialog_p.h>
#include <QtQuickTemplates2/private/qquickdialogbuttonbox_p.h>
#include <QtQuickTemplates2/private/qquicktextfield_p.h>
+#include <QtQuickControls2/qquickstyle.h>
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"));