diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2017-05-03 21:19:09 +0200 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2017-05-03 21:19:09 +0200 |
commit | 87c1b763147f0dd15e7724fd2a41244dd856613c (patch) | |
tree | 2212e206ffc9085209776925c3145f1cff8d7493 /tests | |
parent | ea381fba363fcf9b9ef463f24eb90c5e5517fd01 (diff) | |
parent | 3af18224190d2c008a4ed6fe39b07e60db5dc683 (diff) |
Merge remote-tracking branch 'origin/5.9' into dev
Conflicts:
src/imports/controls/universal/CheckDelegate.qml
src/imports/controls/universal/RadioDelegate.qml
src/imports/controls/universal/Switch.qml
src/imports/controls/universal/SwitchDelegate.qml
Change-Id: I9bca4b8d9ce3f6c5c7589daa0ced7d0353f42efc
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/drawer/data/flickable.qml (renamed from tests/auto/drawer/data/flicking.qml) | 0 | ||||
-rw-r--r-- | tests/auto/drawer/data/reposition.qml | 8 | ||||
-rw-r--r-- | tests/auto/drawer/tst_drawer.cpp | 75 | ||||
-rw-r--r-- | tests/auto/popup/tst_popup.cpp | 13 | ||||
-rw-r--r-- | tests/auto/snippets/tst_snippets.cpp | 104 |
5 files changed, 119 insertions, 81 deletions
diff --git a/tests/auto/drawer/data/flicking.qml b/tests/auto/drawer/data/flickable.qml index 62256afd..62256afd 100644 --- a/tests/auto/drawer/data/flicking.qml +++ b/tests/auto/drawer/data/flickable.qml diff --git a/tests/auto/drawer/data/reposition.qml b/tests/auto/drawer/data/reposition.qml index 99cecd16..485da85c 100644 --- a/tests/auto/drawer/data/reposition.qml +++ b/tests/auto/drawer/data/reposition.qml @@ -52,10 +52,12 @@ import QtQuick 2.6 import QtQuick.Controls 2.0 ApplicationWindow { + id: window width: 400 height: 400 property alias drawer: drawer + property alias drawer2: drawer2 header: Item { implicitHeight: 50 } footer: Item { implicitHeight: 50 } @@ -65,4 +67,10 @@ ApplicationWindow { width: parent.width / 2 implicitHeight: parent.height } + + Drawer { + id: drawer2 + width: Math.min(window.width, window.height) / 3 * 2 + height: window.height + } } diff --git a/tests/auto/drawer/tst_drawer.cpp b/tests/auto/drawer/tst_drawer.cpp index eda00158..a7ebaa9e 100644 --- a/tests/auto/drawer/tst_drawer.cpp +++ b/tests/auto/drawer/tst_drawer.cpp @@ -91,7 +91,8 @@ private slots: void interactive_data(); void interactive(); - void flicking(); + void flickable_data(); + void flickable(); private: struct TouchDeviceDeleter @@ -422,6 +423,16 @@ void tst_Drawer::reposition() drawer->close(); QTRY_COMPARE(geometry(popupItem), QRectF(window->width(), 150, window->width() / 2, window->height() - 150)); + + QQuickDrawer *drawer2 = window->property("drawer2").value<QQuickDrawer *>(); + QVERIFY(drawer2); + QQuickItem *popupItem2 = drawer2->popupItem(); + QVERIFY(popupItem2); + + drawer2->open(); + QVERIFY(popupItem2->isVisible()); + QCOMPARE(popupItem2->x(), -drawer2->width()); + QTRY_COMPARE(popupItem2->x(), 0.0); } void tst_Drawer::header() @@ -879,9 +890,25 @@ void tst_Drawer::interactive() QCOMPARE(aboutToHideSpy.count(), 0); } -void tst_Drawer::flicking() +void tst_Drawer::flickable_data() +{ + QTest::addColumn<bool>("mouse"); + QTest::addColumn<QPoint>("from"); + QTest::addColumn<QPoint>("to"); + + QTest::newRow("mouse,straight") << true << QPoint(200, 200) << QPoint(200, 100); + QTest::newRow("mouse,diagonal") << true << QPoint(200, 200) << QPoint(250, 100); + QTest::newRow("touch,straight") << false << QPoint(200, 200) << QPoint(200, 100); + QTest::newRow("touch,diagonal") << false << QPoint(200, 200) << QPoint(250, 100); +} + +void tst_Drawer::flickable() { - QQuickApplicationHelper helper(this, QStringLiteral("flicking.qml")); + QFETCH(bool, mouse); + QFETCH(QPoint, from); + QFETCH(QPoint, to); + + QQuickApplicationHelper helper(this, QStringLiteral("flickable.qml")); QQuickWindow *window = helper.window; window->show(); QVERIFY(QTest::qWaitForWindowExposed(window)); @@ -898,23 +925,31 @@ void tst_Drawer::flicking() drawer->open(); QVERIFY(drawerOpenedSpy.wait()); - // mouse - QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, QPoint(200, 200)); - for (int y = 200; y > 100; y -= 10) - QTest::mouseMove(window, QPoint(200, y), 1); - QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, QPoint(200, 100)); - QVERIFY(flickable->isFlicking()); - - // reset - flickable->setContentY(0); - QVERIFY(!flickable->isFlicking()); - - // touch - QTest::touchEvent(window, touchDevice.data()).press(0, QPoint(200, 200)); - for (int y = 200; y > 100; y -= 10) - QTest::touchEvent(window, touchDevice.data()).move(0, QPoint(200, y)); - QTest::touchEvent(window, touchDevice.data()).release(0, QPoint(200, 100)); - QVERIFY(flickable->isFlicking()); + if (mouse) + QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, from); + else + QTest::touchEvent(window, touchDevice.data()).press(0, from); + + static const int steps = 10; + for (int i = 0; i < steps; ++i) { + int x = i * qAbs(from.x() - to.x()) / steps; + int y = i * qAbs(from.y() - to.y()) / steps; + + if (mouse) + QTest::mouseMove(window, QPoint(x, y)); + else + QTest::touchEvent(window, touchDevice.data()).move(0, QPoint(x, y)); + QTest::qWait(1); // avoid infinite velocity + } + + QVERIFY(flickable->isDragging()); + + if (mouse) + QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, to); + else + QTest::touchEvent(window, touchDevice.data()).release(0, to); + + QVERIFY(!flickable->isDragging()); } QTEST_MAIN(tst_Drawer) diff --git a/tests/auto/popup/tst_popup.cpp b/tests/auto/popup/tst_popup.cpp index 686a5923..9001c3ee 100644 --- a/tests/auto/popup/tst_popup.cpp +++ b/tests/auto/popup/tst_popup.cpp @@ -53,6 +53,7 @@ class tst_popup : public QQmlDataTest Q_OBJECT private slots: + void initTestCase(); void visible_data(); void visible(); void state(); @@ -77,6 +78,12 @@ private slots: void componentComplete(); }; +void tst_popup::initTestCase() +{ + QQmlDataTest::initTestCase(); + qputenv("QML_NO_TOUCH_COMPRESSION", "1"); +} + void tst_popup::visible_data() { QTest::addColumn<QString>("source"); @@ -434,6 +441,12 @@ void tst_popup::closePolicy() popup->open(); QVERIFY(popup->isVisible()); + // press inside and release outside + QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, QPoint(button->x() + popup->x(), button->y() + popup->y())); + QVERIFY(popup->isVisible()); + QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, QPoint(1, 1)); + QVERIFY(popup->isVisible()); + // escape QTest::keyClick(window, Qt::Key_Escape); if (closePolicy.testFlag(QQuickPopup::CloseOnEscape)) diff --git a/tests/auto/snippets/tst_snippets.cpp b/tests/auto/snippets/tst_snippets.cpp index ab3a94bc..97b10fe1 100644 --- a/tests/auto/snippets/tst_snippets.cpp +++ b/tests/auto/snippets/tst_snippets.cpp @@ -49,13 +49,11 @@ private slots: void verify(); void verify_data(); - void screenshots(); - void screenshots_data(); - private: - QQuickView view; + void loadSnippet(const QString &source); + + bool takeScreenshots; QMap<QString, QStringPair> snippetPaths; - QMap<QString, QStringPair> screenshotSnippetPaths; }; static QMap<QString, QStringPair> findSnippets(const QDir &inputDir, const QDir &outputDir = QDir()) @@ -77,86 +75,70 @@ void tst_Snippets::initTestCase() QDir snippetsDir(QQC2_SNIPPETS_PATH); QVERIFY(!snippetsDir.path().isEmpty()); - snippetPaths = findSnippets(snippetsDir); - QVERIFY(!snippetPaths.isEmpty()); + QDir screenshotsDir(QDir::current().filePath("screenshots")); - QDir screenshotOutputDir(QDir::current().filePath("screenshots")); - QVERIFY(screenshotOutputDir.exists() || QDir::current().mkpath("screenshots")); + takeScreenshots = qgetenv("SCREENSHOTS").toInt(); + if (takeScreenshots) + QVERIFY(screenshotsDir.exists() || QDir::current().mkpath("screenshots")); - QDir screenshotSnippetsDir(QQC2_SNIPPETS_PATH "/screenshots"); - QVERIFY(!screenshotSnippetsDir.path().isEmpty()); - - screenshotSnippetPaths = findSnippets(screenshotSnippetsDir, screenshotOutputDir); - QVERIFY(!screenshotSnippetPaths.isEmpty()); + snippetPaths = findSnippets(snippetsDir, screenshotsDir); + QVERIFY(!snippetPaths.isEmpty()); } Q_DECLARE_METATYPE(QList<QQmlError>) -static void loadSnippet(QQuickView *view, const QString &source) +void tst_Snippets::verify() { + QFETCH(QString, input); + QFETCH(QString, output); + + QQmlEngine engine; + QQmlComponent component(&engine); + qRegisterMetaType<QList<QQmlError> >(); - QSignalSpy warnings(view->engine(), SIGNAL(warnings(QList<QQmlError>))); + QSignalSpy warnings(&engine, SIGNAL(warnings(QList<QQmlError>))); QVERIFY(warnings.isValid()); - QUrl url = QUrl::fromLocalFile(source); - QQmlComponent *component = new QQmlComponent(view->engine(), view); - component->loadUrl(url); + QUrl url = QUrl::fromLocalFile(input); + component.loadUrl(url); - QObject *root = component->beginCreate(view->rootContext()); + QObject *root = component.create(); QVERIFY(root); - view->setContent(url, component, root); - component->completeCreate(); - QCOMPARE(view->status(), QQuickView::Ready); - QVERIFY(view->errors().isEmpty()); - QVERIFY(view->rootObject()); + QCOMPARE(component.status(), QQmlComponent::Ready); + QVERIFY(component.errors().isEmpty()); QVERIFY(warnings.isEmpty()); -} - -void tst_Snippets::verify() -{ - QFETCH(QString, input); - loadSnippet(&view, input); + if (takeScreenshots) { + QQuickWindow *window = qobject_cast<QQuickWindow *>(root); + if (!window) { + QQuickView *view = new QQuickView; + view->setContent(url, &component, root); + window = view; + } + + window->show(); + window->requestActivate(); + QVERIFY(QTest::qWaitForWindowActive(window)); + + QSharedPointer<QQuickItemGrabResult> result = window->contentItem()->grabToImage(); + QSignalSpy spy(result.data(), SIGNAL(ready())); + QVERIFY(spy.isValid()); + QVERIFY(spy.wait()); + QVERIFY(result->saveToFile(output)); + + window->close(); + } } void tst_Snippets::verify_data() { QTest::addColumn<QString>("input"); - - QMap<QString, QStringPair>::const_iterator it; - for (it = snippetPaths.constBegin(); it != snippetPaths.constEnd(); ++it) - QTest::newRow(qPrintable(it.key())) << it.value().first; -} - -void tst_Snippets::screenshots() -{ - QFETCH(QString, input); - QFETCH(QString, output); - - loadSnippet(&view, input); - - view.show(); - view.requestActivate(); - QVERIFY(QTest::qWaitForWindowActive(&view)); - - QSharedPointer<QQuickItemGrabResult> result = view.contentItem()->grabToImage(); - QSignalSpy spy(result.data(), SIGNAL(ready())); - QVERIFY(spy.isValid()); - QVERIFY(spy.wait()); - QVERIFY(result->saveToFile(output)); - - view.close(); -} - -void tst_Snippets::screenshots_data() -{ - QTest::addColumn<QString>("input"); QTest::addColumn<QString>("output"); QMap<QString, QStringPair>::const_iterator it; - for (it = screenshotSnippetPaths.constBegin(); it != screenshotSnippetPaths.constEnd(); ++it) + for (it = snippetPaths.constBegin(); it != snippetPaths.constEnd(); ++it) QTest::newRow(qPrintable(it.key())) << it.value().first << it.value().second; } |