From eb500f9cd9756f035b3d74b3a58a1a78e229988d Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Wed, 9 Dec 2015 15:37:01 +0100 Subject: Move ApplicationHelper to visualtestutil.h and rename it This class is useful for other auto tests, like Popup's. Change-Id: Ie193c07e5b53b67493fceba9a1c32798db2f4e34 Reviewed-by: J-P Nurmi --- tests/auto/menu/tst_menu.cpp | 30 ++++-------------------------- tests/auto/shared/util.pri | 2 +- tests/auto/shared/visualtestutil.h | 26 ++++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 27 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/menu/tst_menu.cpp b/tests/auto/menu/tst_menu.cpp index 5823767a..7b2b8ea6 100644 --- a/tests/auto/menu/tst_menu.cpp +++ b/tests/auto/menu/tst_menu.cpp @@ -52,28 +52,6 @@ using namespace QQuickVisualTestUtil; -class ApplicationHelper -{ -public: - ApplicationHelper(QQmlDataTest *testCase, const QString &testFilePath = QLatin1String("applicationwindow.qml")) : - component(&engine) - { - component.loadUrl(testCase->testFileUrl(testFilePath)); - QObject *rootObject = component.create(); - cleanup.reset(rootObject); - QVERIFY2(rootObject, qPrintable(QString::fromLatin1("Failed to create ApplicationWindow: %1").arg(component.errorString()))); - - window = qobject_cast(rootObject); - QVERIFY(window); - QVERIFY(!window->isVisible()); - } - - QQmlEngine engine; - QQmlComponent component; - QScopedPointer cleanup; - QQuickApplicationWindow *window; -}; - class tst_menu : public QQmlDataTest { Q_OBJECT @@ -89,7 +67,7 @@ private slots: void tst_menu::defaults() { - ApplicationHelper helper(this); + QQuickApplicationHelper helper(this, QLatin1String("applicationwindow.qml")); QQuickMenu *emptyMenu = helper.window->property("emptyMenu").value(); QCOMPARE(emptyMenu->isVisible(), false); @@ -98,7 +76,7 @@ void tst_menu::defaults() void tst_menu::mouse() { - ApplicationHelper helper(this); + QQuickApplicationHelper helper(this, QLatin1String("applicationwindow.qml")); QQuickApplicationWindow *window = helper.window; window->show(); @@ -170,7 +148,7 @@ void tst_menu::contextMenuKeyboard() if (QGuiApplication::styleHints()->tabFocusBehavior() != Qt::TabFocusAllControls) QSKIP("This platform only allows tab focus for text controls"); - ApplicationHelper helper(this); + QQuickApplicationHelper helper(this, QLatin1String("applicationwindow.qml")); QQuickApplicationWindow *window = helper.window; window->show(); @@ -248,7 +226,7 @@ void tst_menu::menuButton() if (QGuiApplication::styleHints()->tabFocusBehavior() != Qt::TabFocusAllControls) QSKIP("This platform only allows tab focus for text controls"); - ApplicationHelper helper(this); + QQuickApplicationHelper helper(this, QLatin1String("applicationwindow.qml")); QQuickApplicationWindow *window = helper.window; window->show(); diff --git a/tests/auto/shared/util.pri b/tests/auto/shared/util.pri index 747bdf64..5e6b06b6 100644 --- a/tests/auto/shared/util.pri +++ b/tests/auto/shared/util.pri @@ -1,4 +1,4 @@ -QT += core-private gui-private qml-private quick-private +QT += core-private gui-private qml-private quick-private labstemplates-private HEADERS += $$PWD/visualtestutil.h \ $$PWD/util.h diff --git a/tests/auto/shared/visualtestutil.h b/tests/auto/shared/visualtestutil.h index 7a35ac76..b3fecf8e 100644 --- a/tests/auto/shared/visualtestutil.h +++ b/tests/auto/shared/visualtestutil.h @@ -42,6 +42,10 @@ #include +#include + +#include "util.h" + namespace QQuickVisualTestUtil { QQuickItem *findVisibleChild(QQuickItem *parent, const QString &objectName); @@ -104,6 +108,28 @@ namespace QQuickVisualTestUtil items << qobject_cast(findItem(parent, objectName, indexes[i])); return items; } + + class QQuickApplicationHelper + { + public: + QQuickApplicationHelper(QQmlDataTest *testCase, const QString &testFilePath) : + component(&engine) + { + component.loadUrl(testCase->testFileUrl(testFilePath)); + QObject *rootObject = component.create(); + cleanup.reset(rootObject); + QVERIFY2(rootObject, qPrintable(QString::fromLatin1("Failed to create ApplicationWindow: %1").arg(component.errorString()))); + + window = qobject_cast(rootObject); + QVERIFY(window); + QVERIFY(!window->isVisible()); + } + + QQmlEngine engine; + QQmlComponent component; + QScopedPointer cleanup; + QQuickApplicationWindow *window; + }; } #define QQUICK_VERIFY_POLISH(item) \ -- cgit v1.2.3