aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/shared
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@qt.io>2018-04-12 10:58:08 +0200
committerJ-P Nurmi <jpnurmi@qt.io>2018-04-12 12:17:35 +0000
commitc6e94e46077baf07793f95213bb53a8e56cf9b44 (patch)
tree5916d3f56997d466dd625d0fedea85a7439c377c /tests/auto/shared
parentad343ad8ffc1016dd7d2d79603148ab2a07fe713 (diff)
Tests: move duplicated addTestRows() to QQuickVisualTestUtil
Change-Id: I723f1fe2e5df1ea4a09bd7e567079cdbc7124e6e Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'tests/auto/shared')
-rw-r--r--tests/auto/shared/util.pri1
-rw-r--r--tests/auto/shared/visualtestutil.cpp38
-rw-r--r--tests/auto/shared/visualtestutil.h2
3 files changed, 41 insertions, 0 deletions
diff --git a/tests/auto/shared/util.pri b/tests/auto/shared/util.pri
index 77c2cc59..16f37f8a 100644
--- a/tests/auto/shared/util.pri
+++ b/tests/auto/shared/util.pri
@@ -7,3 +7,4 @@ SOURCES += $$PWD/visualtestutil.cpp \
$$PWD/util.cpp
DEFINES += QT_QMLTEST_DATADIR=\\\"$${_PRO_FILE_PWD_}/data\\\"
+DEFINES += QQC2_IMPORT_PATH=\\\"$$QQC2_SOURCE_TREE/src/imports\\\"
diff --git a/tests/auto/shared/visualtestutil.cpp b/tests/auto/shared/visualtestutil.cpp
index c5e69812..44ca6d77 100644
--- a/tests/auto/shared/visualtestutil.cpp
+++ b/tests/auto/shared/visualtestutil.cpp
@@ -40,6 +40,8 @@
#include <QtCore/QDebug>
#include <QtGui/QCursor>
#include <QtCore/QCoreApplication>
+#include <QtQml/QQmlFile>
+#include <QtTest/QTest>
bool QQuickVisualTestUtil::delegateVisible(QQuickItem *item)
{
@@ -92,3 +94,39 @@ void QQuickVisualTestUtil::centerOnScreen(QQuickWindow *window)
const QPoint offset = QPoint(window->width() / 2, window->height() / 2);
window->setFramePosition(screenGeometry.center() - offset);
}
+
+void QQuickVisualTestUtil::addTestRowForEachControl(QQmlEngine *engine, const QString &sourcePath, const QString &targetPath, const QStringList &skiplist)
+{
+ // We cannot use QQmlComponent to load QML files directly from the source tree.
+ // For styles that use internal QML types (eg. material/Ripple.qml), the source
+ // dir would be added as an "implicit" import path overriding the actual import
+ // path (qtbase/qml/QtQuick/Controls.2/Material). => The QML engine fails to load
+ // the style C++ plugin from the implicit import path (the source dir).
+ //
+ // Therefore we only use the source tree for finding out the set of QML files that
+ // a particular style implements, and then we locate the respective QML files in
+ // the engine's import path. This way we can use QQmlComponent to load each QML file
+ // for benchmarking.
+
+ const QFileInfoList entries = QDir(QQC2_IMPORT_PATH "/" + sourcePath).entryInfoList(QStringList("*.qml"), QDir::Files);
+ for (const QFileInfo &entry : entries) {
+ QString name = entry.baseName();
+ if (!skiplist.contains(name)) {
+ const auto importPathList = engine->importPathList();
+ for (const QString &importPath : importPathList) {
+ QString name = entry.dir().dirName() + "/" + entry.fileName();
+ QString filePath = importPath + "/" + targetPath + "/" + entry.fileName();
+ if (QFile::exists(filePath)) {
+ QTest::newRow(qPrintable(name)) << QUrl::fromLocalFile(filePath);
+ break;
+ } else {
+ filePath = QQmlFile::urlToLocalFileOrQrc(filePath);
+ if (!filePath.isEmpty() && QFile::exists(filePath)) {
+ QTest::newRow(qPrintable(name)) << QUrl(filePath);
+ break;
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/tests/auto/shared/visualtestutil.h b/tests/auto/shared/visualtestutil.h
index a6b52fef..d5e651c5 100644
--- a/tests/auto/shared/visualtestutil.h
+++ b/tests/auto/shared/visualtestutil.h
@@ -136,6 +136,8 @@ namespace QQuickVisualTestUtil
QQuickApplicationWindow *appWindow;
QQuickWindow *window;
};
+
+ void addTestRowForEachControl(QQmlEngine *engine, const QString &sourcePath, const QString &targetPath, const QStringList &skiplist = QStringList());
}
#define QQUICK_VERIFY_POLISH(item) \