diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2018-04-12 10:58:08 +0200 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2018-04-12 12:17:35 +0000 |
commit | c6e94e46077baf07793f95213bb53a8e56cf9b44 (patch) | |
tree | 5916d3f56997d466dd625d0fedea85a7439c377c | |
parent | ad343ad8ffc1016dd7d2d79603148ab2a07fe713 (diff) |
Tests: move duplicated addTestRows() to QQuickVisualTestUtil
Change-Id: I723f1fe2e5df1ea4a09bd7e567079cdbc7124e6e
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
-rw-r--r-- | tests/auto/sanity/sanity.pro | 2 | ||||
-rw-r--r-- | tests/auto/sanity/tst_sanity.cpp | 49 | ||||
-rw-r--r-- | tests/auto/shared/util.pri | 1 | ||||
-rw-r--r-- | tests/auto/shared/visualtestutil.cpp | 38 | ||||
-rw-r--r-- | tests/auto/shared/visualtestutil.h | 2 | ||||
-rw-r--r-- | tests/benchmarks/creationtime/creationtime.pro | 2 | ||||
-rw-r--r-- | tests/benchmarks/creationtime/tst_creationtime.cpp | 52 | ||||
-rw-r--r-- | tests/benchmarks/objectcount/objectcount.pro | 2 | ||||
-rw-r--r-- | tests/benchmarks/objectcount/tst_objectcount.cpp | 49 |
9 files changed, 70 insertions, 127 deletions
diff --git a/tests/auto/sanity/sanity.pro b/tests/auto/sanity/sanity.pro index 50030e80..c792c073 100644 --- a/tests/auto/sanity/sanity.pro +++ b/tests/auto/sanity/sanity.pro @@ -5,7 +5,7 @@ QT += qml testlib core-private qml-private CONFIG += testcase macos:CONFIG -= app_bundle -DEFINES += QQC2_IMPORT_PATH=\\\"$$QQC2_SOURCE_TREE/src/imports\\\" +include(../../auto/shared/util.pri) SOURCES += \ $$PWD/tst_sanity.cpp diff --git a/tests/auto/sanity/tst_sanity.cpp b/tests/auto/sanity/tst_sanity.cpp index df440ebd..69553d93 100644 --- a/tests/auto/sanity/tst_sanity.cpp +++ b/tests/auto/sanity/tst_sanity.cpp @@ -43,6 +43,9 @@ #include <QtQml/private/qqmljsast_p.h> #include <QtQml/private/qqmljsastvisitor_p.h> #include <QtQml/private/qqmlmetatype_p.h> +#include "../../auto/shared/visualtestutil.h" + +using namespace QQuickVisualTestUtil; Q_GLOBAL_STATIC(QObjectList, qt_qobjects) @@ -329,42 +332,6 @@ void tst_Sanity::ids_data() QTest::newRow(qPrintable(it.key())) << it.key() << it.value(); } -static void addTestRows(QQmlEngine *engine, const QString &sourcePath, const QString &targetPath, const QStringList &skiplist = QStringList()) -{ - // 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; - } - } - } - } - } -} - void tst_Sanity::attachedObjects() { QFETCH(QUrl, url); @@ -388,11 +355,11 @@ void tst_Sanity::attachedObjects() void tst_Sanity::attachedObjects_data() { QTest::addColumn<QUrl>("url"); - addTestRows(&engine, "calendar", "Qt/labs/calendar"); - addTestRows(&engine, "controls", "QtQuick/Controls.2"); - addTestRows(&engine, "controls/fusion", "QtQuick/Controls.2", QStringList() << "CheckIndicator" << "RadioIndicator" << "SliderGroove" << "SliderHandle" << "SwitchIndicator"); - addTestRows(&engine, "controls/material", "QtQuick/Controls.2/Material", QStringList() << "Ripple" << "SliderHandle" << "CheckIndicator" << "RadioIndicator" << "SwitchIndicator" << "BoxShadow" << "ElevationEffect" << "CursorDelegate"); - addTestRows(&engine, "controls/universal", "QtQuick/Controls.2/Universal", QStringList() << "CheckIndicator" << "RadioIndicator" << "SwitchIndicator"); + addTestRowForEachControl(&engine, "calendar", "Qt/labs/calendar"); + addTestRowForEachControl(&engine, "controls", "QtQuick/Controls.2"); + addTestRowForEachControl(&engine, "controls/fusion", "QtQuick/Controls.2", QStringList() << "CheckIndicator" << "RadioIndicator" << "SliderGroove" << "SliderHandle" << "SwitchIndicator"); + addTestRowForEachControl(&engine, "controls/material", "QtQuick/Controls.2/Material", QStringList() << "Ripple" << "SliderHandle" << "CheckIndicator" << "RadioIndicator" << "SwitchIndicator" << "BoxShadow" << "ElevationEffect" << "CursorDelegate"); + addTestRowForEachControl(&engine, "controls/universal", "QtQuick/Controls.2/Universal", QStringList() << "CheckIndicator" << "RadioIndicator" << "SwitchIndicator"); } QTEST_MAIN(tst_Sanity) 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) \ diff --git a/tests/benchmarks/creationtime/creationtime.pro b/tests/benchmarks/creationtime/creationtime.pro index 4c11c2e6..a594027e 100644 --- a/tests/benchmarks/creationtime/creationtime.pro +++ b/tests/benchmarks/creationtime/creationtime.pro @@ -5,7 +5,7 @@ QT += qml testlib CONFIG += testcase macos:CONFIG -= app_bundle -DEFINES += QQC2_IMPORT_PATH=\\\"$$QQC2_SOURCE_TREE/src/imports\\\" +include(../../auto/shared/util.pri) SOURCES += \ tst_creationtime.cpp diff --git a/tests/benchmarks/creationtime/tst_creationtime.cpp b/tests/benchmarks/creationtime/tst_creationtime.cpp index 1d300b1c..41d7224d 100644 --- a/tests/benchmarks/creationtime/tst_creationtime.cpp +++ b/tests/benchmarks/creationtime/tst_creationtime.cpp @@ -37,6 +37,10 @@ #include <QtQml> #include <QtTest> +#include "../../auto/shared/visualtestutil.h" + +using namespace QQuickVisualTestUtil; + class tst_CreationTime : public QObject { Q_OBJECT @@ -71,42 +75,6 @@ void tst_CreationTime::init() engine.clearComponentCache(); } -static void addTestRows(QQmlEngine *engine, const QString &sourcePath, const QString &targetPath, const QStringList &skiplist = QStringList()) -{ - // 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; - } - } - } - } - } -} - static void doBenchmark(QQmlEngine *engine, const QUrl &url) { QQmlComponent component(engine); @@ -131,7 +99,7 @@ void tst_CreationTime::controls() void tst_CreationTime::controls_data() { QTest::addColumn<QUrl>("url"); - addTestRows(&engine, "controls", "QtQuick/Controls.2", QStringList() << "ApplicationWindow"); + addTestRowForEachControl(&engine, "controls", "QtQuick/Controls.2", QStringList() << "ApplicationWindow"); } void tst_CreationTime::fusion() @@ -143,7 +111,7 @@ void tst_CreationTime::fusion() void tst_CreationTime::fusion_data() { QTest::addColumn<QUrl>("url"); - addTestRows(&engine, "controls/fusion", "QtQuick/Controls.2/Fusion", QStringList() << "ApplicationWindow" << "ButtonPanel" << "CheckIndicator" << "RadioIndicator" << "SliderGroove" << "SliderHandle" << "SwitchIndicator"); + addTestRowForEachControl(&engine, "controls/fusion", "QtQuick/Controls.2/Fusion", QStringList() << "ApplicationWindow" << "ButtonPanel" << "CheckIndicator" << "RadioIndicator" << "SliderGroove" << "SliderHandle" << "SwitchIndicator"); } void tst_CreationTime::imagine() @@ -155,7 +123,7 @@ void tst_CreationTime::imagine() void tst_CreationTime::imagine_data() { QTest::addColumn<QUrl>("url"); - addTestRows(&engine, "controls/imagine", "QtQuick/Controls.2/Imagine", QStringList() << "ApplicationWindow"); + addTestRowForEachControl(&engine, "controls/imagine", "QtQuick/Controls.2/Imagine", QStringList() << "ApplicationWindow"); } void tst_CreationTime::material() @@ -167,7 +135,7 @@ void tst_CreationTime::material() void tst_CreationTime::material_data() { QTest::addColumn<QUrl>("url"); - addTestRows(&engine, "controls/material", "QtQuick/Controls.2/Material", QStringList() << "ApplicationWindow" << "Ripple" << "SliderHandle" << "CheckIndicator" << "RadioIndicator" << "SwitchIndicator" << "BoxShadow" << "ElevationEffect" << "CursorDelegate"); + addTestRowForEachControl(&engine, "controls/material", "QtQuick/Controls.2/Material", QStringList() << "ApplicationWindow" << "Ripple" << "SliderHandle" << "CheckIndicator" << "RadioIndicator" << "SwitchIndicator" << "BoxShadow" << "ElevationEffect" << "CursorDelegate"); } void tst_CreationTime::universal() @@ -179,7 +147,7 @@ void tst_CreationTime::universal() void tst_CreationTime::universal_data() { QTest::addColumn<QUrl>("url"); - addTestRows(&engine, "controls/universal", "QtQuick/Controls.2/Universal", QStringList() << "ApplicationWindow" << "CheckIndicator" << "RadioIndicator" << "SwitchIndicator"); + addTestRowForEachControl(&engine, "controls/universal", "QtQuick/Controls.2/Universal", QStringList() << "ApplicationWindow" << "CheckIndicator" << "RadioIndicator" << "SwitchIndicator"); } void tst_CreationTime::calendar() @@ -191,7 +159,7 @@ void tst_CreationTime::calendar() void tst_CreationTime::calendar_data() { QTest::addColumn<QUrl>("url"); - addTestRows(&engine, "calendar", "Qt/labs/calendar"); + addTestRowForEachControl(&engine, "calendar", "Qt/labs/calendar"); } QTEST_MAIN(tst_CreationTime) diff --git a/tests/benchmarks/objectcount/objectcount.pro b/tests/benchmarks/objectcount/objectcount.pro index 3d7d411b..046bfc45 100644 --- a/tests/benchmarks/objectcount/objectcount.pro +++ b/tests/benchmarks/objectcount/objectcount.pro @@ -5,7 +5,7 @@ QT += quick testlib core-private CONFIG += testcase macos:CONFIG -= app_bundle -DEFINES += QQC2_IMPORT_PATH=\\\"$$QQC2_SOURCE_TREE/src/imports\\\" +include(../../auto/shared/util.pri) SOURCES += \ tst_objectcount.cpp diff --git a/tests/benchmarks/objectcount/tst_objectcount.cpp b/tests/benchmarks/objectcount/tst_objectcount.cpp index fcb6be5b..c37469c3 100644 --- a/tests/benchmarks/objectcount/tst_objectcount.cpp +++ b/tests/benchmarks/objectcount/tst_objectcount.cpp @@ -38,6 +38,9 @@ #include <QtQuick> #include <QtCore/private/qhooks_p.h> #include <iostream> +#include "../../auto/shared/visualtestutil.h" + +using namespace QQuickVisualTestUtil; static int qt_verbose = qgetenv("VERBOSE").toInt() != 0; @@ -88,49 +91,13 @@ void tst_ObjectCount::cleanup() qtHookData[QHooks::RemoveQObject] = 0; } -static void addTestRows(QQmlEngine *engine, const QString &sourcePath, const QString &targetPath, const QStringList &skiplist = QStringList()) -{ - // 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; - } - } - } - } - } -} - static void initTestRows(QQmlEngine *engine) { - addTestRows(engine, "controls", "QtQuick/Controls.2"); - addTestRows(engine, "controls/fusion", "QtQuick/Controls.2/Fusion", QStringList() << "ButtonPanel" << "CheckIndicator" << "RadioIndicator" << "SliderGroove" << "SliderHandle" << "SwitchIndicator"); - addTestRows(engine, "controls/imagine", "QtQuick/Controls.2/Imagine"); - addTestRows(engine, "controls/material", "QtQuick/Controls.2/Material", QStringList() << "Ripple" << "SliderHandle" << "CheckIndicator" << "RadioIndicator" << "SwitchIndicator" << "BoxShadow" << "ElevationEffect" << "CursorDelegate"); - addTestRows(engine, "controls/universal", "QtQuick/Controls.2/Universal", QStringList() << "CheckIndicator" << "RadioIndicator" << "SwitchIndicator"); + addTestRowForEachControl(engine, "controls", "QtQuick/Controls.2"); + addTestRowForEachControl(engine, "controls/fusion", "QtQuick/Controls.2/Fusion", QStringList() << "ButtonPanel" << "CheckIndicator" << "RadioIndicator" << "SliderGroove" << "SliderHandle" << "SwitchIndicator"); + addTestRowForEachControl(engine, "controls/imagine", "QtQuick/Controls.2/Imagine"); + addTestRowForEachControl(engine, "controls/material", "QtQuick/Controls.2/Material", QStringList() << "Ripple" << "SliderHandle" << "CheckIndicator" << "RadioIndicator" << "SwitchIndicator" << "BoxShadow" << "ElevationEffect" << "CursorDelegate"); + addTestRowForEachControl(engine, "controls/universal", "QtQuick/Controls.2/Universal", QStringList() << "CheckIndicator" << "RadioIndicator" << "SwitchIndicator"); } template <typename T> |