aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/shared/visualtestutil.h
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/shared/visualtestutil.h')
-rw-r--r--tests/auto/shared/visualtestutil.h68
1 files changed, 60 insertions, 8 deletions
diff --git a/tests/auto/shared/visualtestutil.h b/tests/auto/shared/visualtestutil.h
index d5e651c5..726daa27 100644
--- a/tests/auto/shared/visualtestutil.h
+++ b/tests/auto/shared/visualtestutil.h
@@ -37,11 +37,12 @@
#ifndef QQUICKVISUALTESTUTIL_H
#define QQUICKVISUALTESTUTIL_H
+#include <functional>
+
#include <QtQuick/QQuickItem>
#include <QtQml/QQmlExpression>
-
#include <QtQuick/private/qquickitem_p.h>
-
+#include <QtQuickControls2/qquickstyle.h>
#include <QtQuickTemplates2/private/qquickapplicationwindow_p.h>
#include "util.h"
@@ -122,22 +123,73 @@ namespace QQuickVisualTestUtil
component.loadUrl(testCase->testFileUrl(testFilePath));
QObject *rootObject = component.create();
cleanup.reset(rootObject);
- QVERIFY2(rootObject, qPrintable(QString::fromLatin1("Failed to create window: %1").arg(component.errorString())));
+ if (!rootObject) {
+ errorMessage = QString::fromUtf8("Failed to create window: %1").arg(component.errorString()).toUtf8();
+ return;
+ }
window = qobject_cast<QQuickWindow*>(rootObject);
appWindow = qobject_cast<QQuickApplicationWindow*>(rootObject);
- QVERIFY(window);
- QVERIFY(!window->isVisible());
+ if (!window) {
+ errorMessage = QString::fromUtf8("Root object %1 must be a QQuickWindow subclass").arg(QDebug::toString(window)).toUtf8();
+ return;
+ }
+
+ if (window->isVisible()) {
+ errorMessage = QString::fromUtf8("Expected window not to be visible, but it is").toUtf8();
+ return;
+ }
+
+ ready = true;
+ }
+
+ // Return a C-style string instead of QString because that's what QTest uses for error messages,
+ // so it saves code at the calling site.
+ inline const char *failureMessage() const
+ {
+ return errorMessage.constData();
}
QQmlEngine engine;
QQmlComponent component;
QScopedPointer<QObject> cleanup;
- QQuickApplicationWindow *appWindow;
- QQuickWindow *window;
+ QQuickApplicationWindow *appWindow = nullptr;
+ QQuickWindow *window = nullptr;
+
+ bool ready = false;
+ // Store as a byte array so that we can return its raw data safely;
+ // using qPrintable() in failureMessage() will construct a throwaway QByteArray
+ // that is destroyed before the function returns.
+ QByteArray errorMessage;
};
- void addTestRowForEachControl(QQmlEngine *engine, const QString &sourcePath, const QString &targetPath, const QStringList &skiplist = QStringList());
+ struct QQuickStyleHelper
+ {
+ bool updateStyle(const QString &style)
+ {
+ // If it's not the first time a style has been set and the new style is not different, do nothing.
+ if (!currentStyle.isEmpty() && style == currentStyle)
+ return false;
+
+ engine.reset(new QQmlEngine);
+ currentStyle = style;
+ qmlClearTypeRegistrations();
+ QQuickStyle::setStyle(style);
+
+ QQmlComponent component(engine.data());
+ component.setData(QString("import QtQuick\nimport QtQuick.Controls\n Control { }").toUtf8(), QUrl());
+
+ return true;
+ }
+
+ QString currentStyle;
+ QScopedPointer<QQmlEngine> engine;
+ };
+
+ typedef std::function<void(const QString &/*relativePath*/, const QUrl &/*absoluteUrl*/)> ForEachCallback;
+
+ void forEachControl(QQmlEngine *engine, const QString &sourcePath, const QString &targetPath, const QStringList &skipList, ForEachCallback callback);
+ void addTestRowForEachControl(QQmlEngine *engine, const QString &sourcePath, const QString &targetPath, const QStringList &skipList = QStringList());
}
#define QQUICK_VERIFY_POLISH(item) \