From: Friedemann Kleint Date: Fri, 23 Aug 2013 08:38:08 +0000 (+0200) Subject: Stabilize tst_qquickmousearea. X-Git-Tag: upstream/5.2.1~421^2^2~27 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cf3537e99c75d3bb92b9d4ed6f4d437e316dcf01;p=platform%2Fupstream%2Fqtdeclarative.git Stabilize tst_qquickmousearea. Replace createView() by initView(), instantiate windows on stack or use QScopedPointer. Center view in available geometry and make sure the mouse cursor is outside, since otherwise it can interfere with drag->active(). Remove insignification introduced by c1fbee270f50c44f47d4eb287765ad60f362c87a . Task-number: QTBUG-33006 Change-Id: I8fc661444bc42899dfa3d87887c594270483e508 Reviewed-by: Frederik Gladhorn --- diff --git a/tests/auto/quick/qquickmousearea/qquickmousearea.pro b/tests/auto/quick/qquickmousearea/qquickmousearea.pro index e9b06fd..dd7b434 100644 --- a/tests/auto/quick/qquickmousearea/qquickmousearea.pro +++ b/tests/auto/quick/qquickmousearea/qquickmousearea.pro @@ -10,7 +10,5 @@ include (../../shared/util.pri) TESTDATA = data/* -win32:CONFIG += insignificant_test # QTBUG-33006 - QT += core-private gui-private qml-private quick-private network testlib DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 diff --git a/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp b/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp index f92612e..5e7370f 100644 --- a/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp +++ b/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp @@ -49,6 +49,33 @@ #include #include "../../shared/util.h" #include +#include +#include + +// Initialize view, set Url, center in available geometry, move mouse away if desired +static bool initView(QQuickView &v, const QUrl &url, bool moveMouseOut, QByteArray *errorMessage) +{ + v.setBaseSize(QSize(240,320)); + v.setSource(url); + while (v.status() == QQuickView::Loading) + QTest::qWait(10); + if (v.status() != QQuickView::Ready) { + foreach (const QQmlError &e, v.errors()) + errorMessage->append(e.toString().toLocal8Bit() + '\n'); + return false; + } + const QRect screenGeometry = v.screen()->availableGeometry(); + const QSize size = v.size(); + const QPoint offset = QPoint(size.width() / 2, size.height() / 2); + v.setFramePosition(screenGeometry.center() - offset); +#ifndef QT_NO_CURSOR // Get the cursor out of the way. + if (moveMouseOut) + QCursor::setPos(v.geometry().topRight() + QPoint(100, 100)); +#else + Q_UNUSED(moveMouseOut) +#endif + return true; +} class tst_QQuickMouseArea: public QQmlDataTest { @@ -96,8 +123,6 @@ private slots: private: void acceptedButton_data(); void rejectedButton_data(); - - QQuickView *createView(); }; Q_DECLARE_METATYPE(Qt::MouseButton) @@ -129,23 +154,24 @@ void tst_QQuickMouseArea::rejectedButton_data() void tst_QQuickMouseArea::dragProperties() { - QQuickView *window = createView(); - window->setSource(testFileUrl("dragproperties.qml")); - window->show(); - QTest::qWaitForWindowExposed(window); - QVERIFY(window->rootObject() != 0); + QQuickView window; + QByteArray errorMessage; + QVERIFY2(initView(window, testFileUrl("dragproperties.qml"), true, &errorMessage), errorMessage.constData()); + window.show(); + QTest::qWaitForWindowExposed(&window); + QVERIFY(window.rootObject() != 0); - QQuickMouseArea *mouseRegion = window->rootObject()->findChild("mouseregion"); + QQuickMouseArea *mouseRegion = window.rootObject()->findChild("mouseregion"); QQuickDrag *drag = mouseRegion->drag(); QVERIFY(mouseRegion != 0); QVERIFY(drag != 0); // target - QQuickItem *blackRect = window->rootObject()->findChild("blackrect"); + QQuickItem *blackRect = window.rootObject()->findChild("blackrect"); QVERIFY(blackRect != 0); QVERIFY(blackRect == drag->target()); - QQuickItem *rootItem = qobject_cast(window->rootObject()); + QQuickItem *rootItem = qobject_cast(window.rootObject()); QVERIFY(rootItem != 0); QSignalSpy targetSpy(drag, SIGNAL(targetChanged())); drag->setTarget(rootItem); @@ -208,38 +234,34 @@ void tst_QQuickMouseArea::dragProperties() drag->setFilterChildren(true); QCOMPARE(filterChildrenSpy.count(), 1); - - delete window; } void tst_QQuickMouseArea::resetDrag() { - QQuickView *window = createView(); - - window->rootContext()->setContextProperty("haveTarget", QVariant(true)); - window->setSource(testFileUrl("dragreset.qml")); - window->show(); - QTest::qWaitForWindowExposed(window); - QVERIFY(window->rootObject() != 0); - - QQuickMouseArea *mouseRegion = window->rootObject()->findChild("mouseregion"); + QQuickView window; + QByteArray errorMessage; + window.rootContext()->setContextProperty("haveTarget", QVariant(true)); + QVERIFY2(initView(window, testFileUrl("dragreset.qml"), true, &errorMessage), errorMessage.constData()); + window.show(); + QTest::qWaitForWindowExposed(&window); + QVERIFY(window.rootObject() != 0); + + QQuickMouseArea *mouseRegion = window.rootObject()->findChild("mouseregion"); QQuickDrag *drag = mouseRegion->drag(); QVERIFY(mouseRegion != 0); QVERIFY(drag != 0); // target - QQuickItem *blackRect = window->rootObject()->findChild("blackrect"); + QQuickItem *blackRect = window.rootObject()->findChild("blackrect"); QVERIFY(blackRect != 0); QVERIFY(blackRect == drag->target()); - QQuickItem *rootItem = qobject_cast(window->rootObject()); + QQuickItem *rootItem = qobject_cast(window.rootObject()); QVERIFY(rootItem != 0); QSignalSpy targetSpy(drag, SIGNAL(targetChanged())); QVERIFY(drag->target() != 0); - window->rootContext()->setContextProperty("haveTarget", QVariant(false)); + window.rootContext()->setContextProperty("haveTarget", QVariant(false)); QCOMPARE(targetSpy.count(),1); QVERIFY(drag->target() == 0); - - delete window; } void tst_QQuickMouseArea::dragging() @@ -247,15 +269,15 @@ void tst_QQuickMouseArea::dragging() QFETCH(Qt::MouseButtons, acceptedButtons); QFETCH(Qt::MouseButton, button); - QQuickView *window = createView(); + QQuickView window; + QByteArray errorMessage; + QVERIFY2(initView(window, testFileUrl("dragging.qml"), true, &errorMessage), errorMessage.constData()); - window->setSource(testFileUrl("dragging.qml")); - window->show(); - QTest::qWaitForWindowExposed(window); - QVERIFY(QTest::qWaitForWindowExposed(window)); - QVERIFY(window->rootObject() != 0); + window.show(); + QVERIFY(QTest::qWaitForWindowExposed(&window)); + QVERIFY(window.rootObject() != 0); - QQuickMouseArea *mouseRegion = window->rootObject()->findChild("mouseregion"); + QQuickMouseArea *mouseRegion = window.rootObject()->findChild("mouseregion"); QQuickDrag *drag = mouseRegion->drag(); QVERIFY(mouseRegion != 0); QVERIFY(drag != 0); @@ -263,13 +285,13 @@ void tst_QQuickMouseArea::dragging() mouseRegion->setAcceptedButtons(acceptedButtons); // target - QQuickItem *blackRect = window->rootObject()->findChild("blackrect"); + QQuickItem *blackRect = window.rootObject()->findChild("blackrect"); QVERIFY(blackRect != 0); QVERIFY(blackRect == drag->target()); QVERIFY(!drag->active()); - QTest::mousePress(window, button, 0, QPoint(100,100)); + QTest::mousePress(&window, button, 0, QPoint(100,100)); QVERIFY(!drag->active()); QCOMPARE(blackRect->x(), 50.0); @@ -280,21 +302,19 @@ void tst_QQuickMouseArea::dragging() // The item is moved relative to the position of the mouse when the drag // was triggered, this prevents a sudden change in position when the drag // threshold is exceeded. - QTest::mouseMove(window, QPoint(111,111), 50); - QTest::mouseMove(window, QPoint(116,116), 50); - QTest::mouseMove(window, QPoint(122,122), 50); + QTest::mouseMove(&window, QPoint(111,111), 50); + QTest::mouseMove(&window, QPoint(116,116), 50); + QTest::mouseMove(&window, QPoint(122,122), 50); QTRY_VERIFY(drag->active()); QTRY_COMPARE(blackRect->x(), 61.0); QCOMPARE(blackRect->y(), 61.0); - QTest::mouseRelease(window, button, 0, QPoint(122,122)); + QTest::mouseRelease(&window, button, 0, QPoint(122,122)); QTRY_VERIFY(!drag->active()); QCOMPARE(blackRect->x(), 61.0); QCOMPARE(blackRect->y(), 61.0); - - delete window; } void tst_QQuickMouseArea::invalidDrag() @@ -302,14 +322,14 @@ void tst_QQuickMouseArea::invalidDrag() QFETCH(Qt::MouseButtons, acceptedButtons); QFETCH(Qt::MouseButton, button); - QQuickView *window = createView(); + QQuickView window; + QByteArray errorMessage; + QVERIFY2(initView(window, testFileUrl("dragging.qml"), true, &errorMessage), errorMessage.constData()); + window.show(); + QTest::qWaitForWindowExposed(&window); + QVERIFY(window.rootObject() != 0); - window->setSource(testFileUrl("dragging.qml")); - window->show(); - QTest::qWaitForWindowExposed(window); - QVERIFY(window->rootObject() != 0); - - QQuickMouseArea *mouseRegion = window->rootObject()->findChild("mouseregion"); + QQuickMouseArea *mouseRegion = window.rootObject()->findChild("mouseregion"); QQuickDrag *drag = mouseRegion->drag(); QVERIFY(mouseRegion != 0); QVERIFY(drag != 0); @@ -317,13 +337,13 @@ void tst_QQuickMouseArea::invalidDrag() mouseRegion->setAcceptedButtons(acceptedButtons); // target - QQuickItem *blackRect = window->rootObject()->findChild("blackrect"); + QQuickItem *blackRect = window.rootObject()->findChild("blackrect"); QVERIFY(blackRect != 0); QVERIFY(blackRect == drag->target()); QVERIFY(!drag->active()); - QTest::mousePress(window, button, 0, QPoint(100,100)); + QTest::mousePress(&window, button, 0, QPoint(100,100)); QVERIFY(!drag->active()); QCOMPARE(blackRect->x(), 50.0); @@ -332,42 +352,40 @@ void tst_QQuickMouseArea::invalidDrag() // First move event triggers drag, second is acted upon. // This is due to possibility of higher stacked area taking precedence. - QTest::mouseMove(window, QPoint(111,111)); + QTest::mouseMove(&window, QPoint(111,111)); QTest::qWait(50); - QTest::mouseMove(window, QPoint(122,122)); + QTest::mouseMove(&window, QPoint(122,122)); QTest::qWait(50); QVERIFY(!drag->active()); QCOMPARE(blackRect->x(), 50.0); QCOMPARE(blackRect->y(), 50.0); - QTest::mouseRelease(window, button, 0, QPoint(122,122)); + QTest::mouseRelease(&window, button, 0, QPoint(122,122)); QTest::qWait(50); QVERIFY(!drag->active()); QCOMPARE(blackRect->x(), 50.0); QCOMPARE(blackRect->y(), 50.0); - - delete window; } void tst_QQuickMouseArea::setDragOnPressed() { - QQuickView *window = createView(); - - window->setSource(testFileUrl("setDragOnPressed.qml")); - window->show(); - QTest::qWaitForWindowExposed(window); - QVERIFY(window->rootObject() != 0); - - QQuickMouseArea *mouseArea = qobject_cast(window->rootObject()); + QQuickView window; + QByteArray errorMessage; + QVERIFY2(initView(window, testFileUrl("setDragOnPressed.qml"), true, &errorMessage), errorMessage.constData()); + window.show(); + QTest::qWaitForWindowExposed(&window); + QVERIFY(window.rootObject() != 0); + + QQuickMouseArea *mouseArea = qobject_cast(window.rootObject()); QVERIFY(mouseArea); // target QQuickItem *target = mouseArea->findChild("target"); QVERIFY(target); - QTest::mousePress(window, Qt::LeftButton, 0, QPoint(100,100)); + QTest::mousePress(&window, Qt::LeftButton, 0, QPoint(100,100)); QQuickDrag *drag = mouseArea->drag(); QVERIFY(drag); @@ -379,81 +397,71 @@ void tst_QQuickMouseArea::setDragOnPressed() // First move event triggers drag, second is acted upon. // This is due to possibility of higher stacked area taking precedence. - QTest::mouseMove(window, QPoint(111,102)); + QTest::mouseMove(&window, QPoint(111,102)); QTest::qWait(50); - QTest::mouseMove(window, QPoint(122,122)); + QTest::mouseMove(&window, QPoint(122,122)); QTest::qWait(50); QVERIFY(drag->active()); QCOMPARE(target->x(), 61.0); QCOMPARE(target->y(), 50.0); - QTest::mouseRelease(window, Qt::LeftButton, 0, QPoint(122,122)); + QTest::mouseRelease(&window, Qt::LeftButton, 0, QPoint(122,122)); QTest::qWait(50); QVERIFY(!drag->active()); QCOMPARE(target->x(), 61.0); QCOMPARE(target->y(), 50.0); - - delete window; -} - -QQuickView *tst_QQuickMouseArea::createView() -{ - QQuickView *window = new QQuickView(0); - window->setBaseSize(QSize(240,320)); - - return window; } void tst_QQuickMouseArea::updateMouseAreaPosOnClick() { - QQuickView *window = createView(); - window->setSource(testFileUrl("updateMousePosOnClick.qml")); - window->show(); - QTest::qWaitForWindowExposed(window); - QVERIFY(window->rootObject() != 0); - - QQuickMouseArea *mouseRegion = window->rootObject()->findChild("mouseregion"); + QQuickView window; + QByteArray errorMessage; + QVERIFY2(initView(window, testFileUrl("updateMousePosOnClick.qml"), true, &errorMessage), errorMessage.constData()); + window.show(); + QVERIFY(QTest::qWaitForWindowExposed(&window)); + QVERIFY(window.rootObject() != 0); + + QQuickMouseArea *mouseRegion = window.rootObject()->findChild("mouseregion"); QVERIFY(mouseRegion != 0); - QQuickRectangle *rect = window->rootObject()->findChild("ball"); + QQuickRectangle *rect = window.rootObject()->findChild("ball"); QVERIFY(rect != 0); QCOMPARE(mouseRegion->mouseX(), rect->x()); QCOMPARE(mouseRegion->mouseY(), rect->y()); QMouseEvent event(QEvent::MouseButtonPress, QPoint(100, 100), Qt::LeftButton, Qt::LeftButton, 0); - QGuiApplication::sendEvent(window, &event); + QGuiApplication::sendEvent(&window, &event); QCOMPARE(mouseRegion->mouseX(), 100.0); QCOMPARE(mouseRegion->mouseY(), 100.0); QCOMPARE(mouseRegion->mouseX(), rect->x()); QCOMPARE(mouseRegion->mouseY(), rect->y()); - - delete window; } void tst_QQuickMouseArea::updateMouseAreaPosOnResize() { - QQuickView *window = createView(); - window->setSource(testFileUrl("updateMousePosOnResize.qml")); - window->show(); - QTest::qWaitForWindowExposed(window); - QVERIFY(window->rootObject() != 0); - - QQuickMouseArea *mouseRegion = window->rootObject()->findChild("mouseregion"); + QQuickView window; + QByteArray errorMessage; + QVERIFY2(initView(window, testFileUrl("updateMousePosOnResize.qml"), true, &errorMessage), errorMessage.constData()); + window.show(); + QVERIFY(QTest::qWaitForWindowExposed(&window)); + QVERIFY(window.rootObject() != 0); + + QQuickMouseArea *mouseRegion = window.rootObject()->findChild("mouseregion"); QVERIFY(mouseRegion != 0); - QQuickRectangle *rect = window->rootObject()->findChild("brother"); + QQuickRectangle *rect = window.rootObject()->findChild("brother"); QVERIFY(rect != 0); QCOMPARE(mouseRegion->mouseX(), 0.0); QCOMPARE(mouseRegion->mouseY(), 0.0); QMouseEvent event(QEvent::MouseButtonPress, rect->position().toPoint(), Qt::LeftButton, Qt::LeftButton, 0); - QGuiApplication::sendEvent(window, &event); + QGuiApplication::sendEvent(&window, &event); QVERIFY(!mouseRegion->property("emitPositionChanged").toBool()); QVERIFY(mouseRegion->property("mouseMatchesPos").toBool()); @@ -466,148 +474,142 @@ void tst_QQuickMouseArea::updateMouseAreaPosOnResize() QCOMPARE(mouseRegion->mouseX(), rect->x()); QCOMPARE(mouseRegion->mouseY(), rect->y()); - - delete window; } void tst_QQuickMouseArea::noOnClickedWithPressAndHold() { { // We handle onPressAndHold, therefore no onClicked - QQuickView *window = createView(); - window->setSource(testFileUrl("clickandhold.qml")); - window->show(); - QTest::qWaitForWindowExposed(window); - QVERIFY(window->rootObject() != 0); - QQuickMouseArea *mouseArea = qobject_cast(window->rootObject()->children().first()); + QQuickView window; + QByteArray errorMessage; + QVERIFY2(initView(window, testFileUrl("clickandhold.qml"), true, &errorMessage), errorMessage.constData()); + window.show(); + QVERIFY(QTest::qWaitForWindowExposed(&window)); + QVERIFY(window.rootObject() != 0); + QQuickMouseArea *mouseArea = qobject_cast(window.rootObject()->children().first()); QVERIFY(mouseArea); QMouseEvent pressEvent(QEvent::MouseButtonPress, QPoint(100, 100), Qt::LeftButton, Qt::LeftButton, 0); - QGuiApplication::sendEvent(window, &pressEvent); + QGuiApplication::sendEvent(&window, &pressEvent); QVERIFY(mouseArea->pressedButtons() == Qt::LeftButton); - QVERIFY(!window->rootObject()->property("clicked").toBool()); - QVERIFY(!window->rootObject()->property("held").toBool()); + QVERIFY(!window.rootObject()->property("clicked").toBool()); + QVERIFY(!window.rootObject()->property("held").toBool()); // timeout is 800 (in qquickmousearea.cpp) QTest::qWait(1000); QCoreApplication::processEvents(); - QVERIFY(!window->rootObject()->property("clicked").toBool()); - QVERIFY(window->rootObject()->property("held").toBool()); + QVERIFY(!window.rootObject()->property("clicked").toBool()); + QVERIFY(window.rootObject()->property("held").toBool()); QMouseEvent releaseEvent(QEvent::MouseButtonRelease, QPoint(100, 100), Qt::LeftButton, Qt::LeftButton, 0); - QGuiApplication::sendEvent(window, &releaseEvent); + QGuiApplication::sendEvent(&window, &releaseEvent); - QTRY_VERIFY(window->rootObject()->property("held").toBool()); - QVERIFY(!window->rootObject()->property("clicked").toBool()); - - delete window; + QTRY_VERIFY(window.rootObject()->property("held").toBool()); + QVERIFY(!window.rootObject()->property("clicked").toBool()); } { // We do not handle onPressAndHold, therefore we get onClicked - QQuickView *window = createView(); - window->setSource(testFileUrl("noclickandhold.qml")); - window->show(); - QTest::qWaitForWindowExposed(window); - QVERIFY(window->rootObject() != 0); + QQuickView window; + QByteArray errorMessage; + QVERIFY2(initView(window, testFileUrl("noclickandhold.qml"), true, &errorMessage), errorMessage.constData()); + window.show(); + QVERIFY(QTest::qWaitForWindowExposed(&window)); + QVERIFY(window.rootObject() != 0); QMouseEvent pressEvent(QEvent::MouseButtonPress, QPoint(100, 100), Qt::LeftButton, Qt::LeftButton, 0); - QGuiApplication::sendEvent(window, &pressEvent); + QGuiApplication::sendEvent(&window, &pressEvent); - QVERIFY(!window->rootObject()->property("clicked").toBool()); + QVERIFY(!window.rootObject()->property("clicked").toBool()); QTest::qWait(1000); QMouseEvent releaseEvent(QEvent::MouseButtonRelease, QPoint(100, 100), Qt::LeftButton, Qt::LeftButton, 0); - QGuiApplication::sendEvent(window, &releaseEvent); - - QVERIFY(window->rootObject()->property("clicked").toBool()); + QGuiApplication::sendEvent(&window, &releaseEvent); - delete window; + QVERIFY(window.rootObject()->property("clicked").toBool()); } } void tst_QQuickMouseArea::onMousePressRejected() { - QQuickView *window = createView(); - window->setSource(testFileUrl("rejectEvent.qml")); - window->show(); - QTest::qWaitForWindowExposed(window); - QVERIFY(window->rootObject() != 0); - QVERIFY(window->rootObject()->property("enabled").toBool()); - - QVERIFY(!window->rootObject()->property("mr1_pressed").toBool()); - QVERIFY(!window->rootObject()->property("mr1_released").toBool()); - QVERIFY(!window->rootObject()->property("mr1_canceled").toBool()); - QVERIFY(!window->rootObject()->property("mr2_pressed").toBool()); - QVERIFY(!window->rootObject()->property("mr2_released").toBool()); - QVERIFY(!window->rootObject()->property("mr2_canceled").toBool()); + QQuickView window; + QByteArray errorMessage; + QVERIFY2(initView(window, testFileUrl("rejectEvent.qml"), true, &errorMessage), errorMessage.constData()); + window.show(); + QVERIFY(QTest::qWaitForWindowExposed(&window)); + QVERIFY(window.rootObject() != 0); + QVERIFY(window.rootObject()->property("enabled").toBool()); + + QVERIFY(!window.rootObject()->property("mr1_pressed").toBool()); + QVERIFY(!window.rootObject()->property("mr1_released").toBool()); + QVERIFY(!window.rootObject()->property("mr1_canceled").toBool()); + QVERIFY(!window.rootObject()->property("mr2_pressed").toBool()); + QVERIFY(!window.rootObject()->property("mr2_released").toBool()); + QVERIFY(!window.rootObject()->property("mr2_canceled").toBool()); QMouseEvent pressEvent(QEvent::MouseButtonPress, QPoint(100, 100), Qt::LeftButton, Qt::LeftButton, 0); - QGuiApplication::sendEvent(window, &pressEvent); + QGuiApplication::sendEvent(&window, &pressEvent); - QVERIFY(window->rootObject()->property("mr1_pressed").toBool()); - QVERIFY(!window->rootObject()->property("mr1_released").toBool()); - QVERIFY(!window->rootObject()->property("mr1_canceled").toBool()); - QVERIFY(window->rootObject()->property("mr2_pressed").toBool()); - QVERIFY(!window->rootObject()->property("mr2_released").toBool()); - QVERIFY(window->rootObject()->property("mr2_canceled").toBool()); + QVERIFY(window.rootObject()->property("mr1_pressed").toBool()); + QVERIFY(!window.rootObject()->property("mr1_released").toBool()); + QVERIFY(!window.rootObject()->property("mr1_canceled").toBool()); + QVERIFY(window.rootObject()->property("mr2_pressed").toBool()); + QVERIFY(!window.rootObject()->property("mr2_released").toBool()); + QVERIFY(window.rootObject()->property("mr2_canceled").toBool()); QTest::qWait(200); QMouseEvent releaseEvent(QEvent::MouseButtonRelease, QPoint(100, 100), Qt::LeftButton, Qt::LeftButton, 0); - QGuiApplication::sendEvent(window, &releaseEvent); - - QVERIFY(window->rootObject()->property("mr1_released").toBool()); - QVERIFY(!window->rootObject()->property("mr1_canceled").toBool()); - QVERIFY(!window->rootObject()->property("mr2_released").toBool()); + QGuiApplication::sendEvent(&window, &releaseEvent); - delete window; + QVERIFY(window.rootObject()->property("mr1_released").toBool()); + QVERIFY(!window.rootObject()->property("mr1_canceled").toBool()); + QVERIFY(!window.rootObject()->property("mr2_released").toBool()); } void tst_QQuickMouseArea::pressedCanceledOnWindowDeactivate() { - QQuickView *window = createView(); - window->setSource(testFileUrl("pressedCanceled.qml")); - window->show(); - QTest::qWaitForWindowExposed(window); - QVERIFY(window->rootObject() != 0); - QVERIFY(!window->rootObject()->property("pressed").toBool()); - QVERIFY(!window->rootObject()->property("canceled").toBool()); - QVERIFY(!window->rootObject()->property("released").toBool()); + QQuickView window; + QByteArray errorMessage; + QVERIFY2(initView(window, testFileUrl("pressedCanceled.qml"), true, &errorMessage), errorMessage.constData()); + window.show(); + QVERIFY(QTest::qWaitForWindowExposed(&window)); + QVERIFY(window.rootObject() != 0); + QVERIFY(!window.rootObject()->property("pressed").toBool()); + QVERIFY(!window.rootObject()->property("canceled").toBool()); + QVERIFY(!window.rootObject()->property("released").toBool()); QMouseEvent pressEvent(QEvent::MouseButtonPress, QPoint(100, 100), Qt::LeftButton, Qt::LeftButton, 0); - QGuiApplication::sendEvent(window, &pressEvent); + QGuiApplication::sendEvent(&window, &pressEvent); - QVERIFY(window->rootObject()->property("pressed").toBool()); - QVERIFY(!window->rootObject()->property("canceled").toBool()); - QVERIFY(!window->rootObject()->property("released").toBool()); + QVERIFY(window.rootObject()->property("pressed").toBool()); + QVERIFY(!window.rootObject()->property("canceled").toBool()); + QVERIFY(!window.rootObject()->property("released").toBool()); - QWindow *secondWindow = qvariant_cast(window->rootObject()->property("secondWindow")); + QWindow *secondWindow = qvariant_cast(window.rootObject()->property("secondWindow")); secondWindow->setProperty("visible", true); QTest::qWaitForWindowExposed(secondWindow); - QVERIFY(!window->rootObject()->property("pressed").toBool()); - QVERIFY(window->rootObject()->property("canceled").toBool()); - QVERIFY(!window->rootObject()->property("released").toBool()); + QVERIFY(!window.rootObject()->property("pressed").toBool()); + QVERIFY(window.rootObject()->property("canceled").toBool()); + QVERIFY(!window.rootObject()->property("released").toBool()); //press again - QGuiApplication::sendEvent(window, &pressEvent); - QVERIFY(window->rootObject()->property("pressed").toBool()); - QVERIFY(!window->rootObject()->property("canceled").toBool()); - QVERIFY(!window->rootObject()->property("released").toBool()); + QGuiApplication::sendEvent(&window, &pressEvent); + QVERIFY(window.rootObject()->property("pressed").toBool()); + QVERIFY(!window.rootObject()->property("canceled").toBool()); + QVERIFY(!window.rootObject()->property("released").toBool()); QTest::qWait(200); //release QMouseEvent releaseEvent(QEvent::MouseButtonRelease, QPoint(100, 100), Qt::LeftButton, Qt::LeftButton, 0); - QGuiApplication::sendEvent(window, &releaseEvent); - QVERIFY(!window->rootObject()->property("pressed").toBool()); - QVERIFY(!window->rootObject()->property("canceled").toBool()); - QVERIFY(window->rootObject()->property("released").toBool()); - - delete window; + QGuiApplication::sendEvent(&window, &releaseEvent); + QVERIFY(!window.rootObject()->property("pressed").toBool()); + QVERIFY(!window.rootObject()->property("canceled").toBool()); + QVERIFY(window.rootObject()->property("released").toBool()); } void tst_QQuickMouseArea::doubleClick() @@ -615,36 +617,35 @@ void tst_QQuickMouseArea::doubleClick() QFETCH(Qt::MouseButtons, acceptedButtons); QFETCH(Qt::MouseButton, button); - QQuickView *window = createView(); - window->setSource(testFileUrl("doubleclick.qml")); - window->show(); - QTest::qWaitForWindowExposed(window); - QVERIFY(window->rootObject() != 0); + QQuickView window; + QByteArray errorMessage; + QVERIFY2(initView(window, testFileUrl("doubleclick.qml"), true, &errorMessage), errorMessage.constData()); + window.show(); + QVERIFY(QTest::qWaitForWindowExposed(&window)); + QVERIFY(window.rootObject() != 0); - QQuickMouseArea *mouseArea = window->rootObject()->findChild("mousearea"); + QQuickMouseArea *mouseArea = window.rootObject()->findChild("mousearea"); QVERIFY(mouseArea); mouseArea->setAcceptedButtons(acceptedButtons); // The sequence for a double click is: // press, release, (click), press, double click, release QMouseEvent pressEvent(QEvent::MouseButtonPress, QPoint(100, 100), button, button, 0); - QGuiApplication::sendEvent(window, &pressEvent); + QGuiApplication::sendEvent(&window, &pressEvent); QMouseEvent releaseEvent(QEvent::MouseButtonRelease, QPoint(100, 100), button, button, 0); - QGuiApplication::sendEvent(window, &releaseEvent); + QGuiApplication::sendEvent(&window, &releaseEvent); - QCOMPARE(window->rootObject()->property("released").toInt(), 1); + QCOMPARE(window.rootObject()->property("released").toInt(), 1); - QGuiApplication::sendEvent(window, &pressEvent); + QGuiApplication::sendEvent(&window, &pressEvent); pressEvent = QMouseEvent(QEvent::MouseButtonDblClick, QPoint(100, 100), button, button, 0); - QGuiApplication::sendEvent(window, &pressEvent); - QGuiApplication::sendEvent(window, &releaseEvent); + QGuiApplication::sendEvent(&window, &pressEvent); + QGuiApplication::sendEvent(&window, &releaseEvent); - QCOMPARE(window->rootObject()->property("clicked").toInt(), 1); - QCOMPARE(window->rootObject()->property("doubleClicked").toInt(), 1); - QCOMPARE(window->rootObject()->property("released").toInt(), 2); - - delete window; + QCOMPARE(window.rootObject()->property("clicked").toInt(), 1); + QCOMPARE(window.rootObject()->property("doubleClicked").toInt(), 1); + QCOMPARE(window.rootObject()->property("released").toInt(), 2); } // QTBUG-14832 @@ -653,36 +654,35 @@ void tst_QQuickMouseArea::clickTwice() QFETCH(Qt::MouseButtons, acceptedButtons); QFETCH(Qt::MouseButton, button); - QQuickView *window = createView(); - window->setSource(testFileUrl("clicktwice.qml")); - window->show(); - QTest::qWaitForWindowExposed(window); - QVERIFY(window->rootObject() != 0); + QQuickView window; + QByteArray errorMessage; + QVERIFY2(initView(window, testFileUrl("clicktwice.qml"), true, &errorMessage), errorMessage.constData()); + window.show(); + QVERIFY(QTest::qWaitForWindowExposed(&window)); + QVERIFY(window.rootObject() != 0); - QQuickMouseArea *mouseArea = window->rootObject()->findChild("mousearea"); + QQuickMouseArea *mouseArea = window.rootObject()->findChild("mousearea"); QVERIFY(mouseArea); mouseArea->setAcceptedButtons(acceptedButtons); QMouseEvent pressEvent(QEvent::MouseButtonPress, QPoint(100, 100), button, button, 0); - QGuiApplication::sendEvent(window, &pressEvent); + QGuiApplication::sendEvent(&window, &pressEvent); QMouseEvent releaseEvent(QEvent::MouseButtonRelease, QPoint(100, 100), button, button, 0); - QGuiApplication::sendEvent(window, &releaseEvent); + QGuiApplication::sendEvent(&window, &releaseEvent); - QCOMPARE(window->rootObject()->property("pressed").toInt(), 1); - QCOMPARE(window->rootObject()->property("released").toInt(), 1); - QCOMPARE(window->rootObject()->property("clicked").toInt(), 1); + QCOMPARE(window.rootObject()->property("pressed").toInt(), 1); + QCOMPARE(window.rootObject()->property("released").toInt(), 1); + QCOMPARE(window.rootObject()->property("clicked").toInt(), 1); - QGuiApplication::sendEvent(window, &pressEvent); + QGuiApplication::sendEvent(&window, &pressEvent); pressEvent = QMouseEvent(QEvent::MouseButtonDblClick, QPoint(100, 100), button, button, 0); - QGuiApplication::sendEvent(window, &pressEvent); - QGuiApplication::sendEvent(window, &releaseEvent); + QGuiApplication::sendEvent(&window, &pressEvent); + QGuiApplication::sendEvent(&window, &releaseEvent); - QCOMPARE(window->rootObject()->property("pressed").toInt(), 2); - QCOMPARE(window->rootObject()->property("released").toInt(), 2); - QCOMPARE(window->rootObject()->property("clicked").toInt(), 2); - - delete window; + QCOMPARE(window.rootObject()->property("pressed").toInt(), 2); + QCOMPARE(window.rootObject()->property("released").toInt(), 2); + QCOMPARE(window.rootObject()->property("clicked").toInt(), 2); } void tst_QQuickMouseArea::invalidClick() @@ -690,90 +690,88 @@ void tst_QQuickMouseArea::invalidClick() QFETCH(Qt::MouseButtons, acceptedButtons); QFETCH(Qt::MouseButton, button); - QQuickView *window = createView(); - window->setSource(testFileUrl("doubleclick.qml")); - window->show(); - QTest::qWaitForWindowExposed(window); - QVERIFY(window->rootObject() != 0); + QQuickView window; + QByteArray errorMessage; + QVERIFY2(initView(window, testFileUrl("doubleclick.qml"), true, &errorMessage), errorMessage.constData()); + window.show(); + QVERIFY(QTest::qWaitForWindowExposed(&window)); + QVERIFY(window.rootObject() != 0); - QQuickMouseArea *mouseArea = window->rootObject()->findChild("mousearea"); + QQuickMouseArea *mouseArea = window.rootObject()->findChild("mousearea"); QVERIFY(mouseArea); mouseArea->setAcceptedButtons(acceptedButtons); // The sequence for a double click is: // press, release, (click), press, double click, release QMouseEvent pressEvent(QEvent::MouseButtonPress, QPoint(100, 100), button, button, 0); - QGuiApplication::sendEvent(window, &pressEvent); + QGuiApplication::sendEvent(&window, &pressEvent); QMouseEvent releaseEvent(QEvent::MouseButtonRelease, QPoint(100, 100), button, button, 0); - QGuiApplication::sendEvent(window, &releaseEvent); + QGuiApplication::sendEvent(&window, &releaseEvent); - QCOMPARE(window->rootObject()->property("released").toInt(), 0); + QCOMPARE(window.rootObject()->property("released").toInt(), 0); - QGuiApplication::sendEvent(window, &pressEvent); + QGuiApplication::sendEvent(&window, &pressEvent); pressEvent = QMouseEvent(QEvent::MouseButtonDblClick, QPoint(100, 100), button, button, 0); - QGuiApplication::sendEvent(window, &pressEvent); - QGuiApplication::sendEvent(window, &releaseEvent); + QGuiApplication::sendEvent(&window, &pressEvent); + QGuiApplication::sendEvent(&window, &releaseEvent); - QCOMPARE(window->rootObject()->property("clicked").toInt(), 0); - QCOMPARE(window->rootObject()->property("doubleClicked").toInt(), 0); - QCOMPARE(window->rootObject()->property("released").toInt(), 0); - - delete window; + QCOMPARE(window.rootObject()->property("clicked").toInt(), 0); + QCOMPARE(window.rootObject()->property("doubleClicked").toInt(), 0); + QCOMPARE(window.rootObject()->property("released").toInt(), 0); } void tst_QQuickMouseArea::pressedOrdering() { - QQuickView *window = createView(); - window->setSource(testFileUrl("pressedOrdering.qml")); - window->show(); - QTest::qWaitForWindowExposed(window); - QVERIFY(window->rootObject() != 0); + QQuickView window; + QByteArray errorMessage; + QVERIFY2(initView(window, testFileUrl("pressedOrdering.qml"), true, &errorMessage), errorMessage.constData()); + window.show(); + QVERIFY(QTest::qWaitForWindowExposed(&window)); + QVERIFY(window.rootObject() != 0); - QCOMPARE(window->rootObject()->property("value").toString(), QLatin1String("base")); + QCOMPARE(window.rootObject()->property("value").toString(), QLatin1String("base")); QMouseEvent pressEvent(QEvent::MouseButtonPress, QPoint(100, 100), Qt::LeftButton, Qt::LeftButton, 0); - QGuiApplication::sendEvent(window, &pressEvent); + QGuiApplication::sendEvent(&window, &pressEvent); - QCOMPARE(window->rootObject()->property("value").toString(), QLatin1String("pressed")); + QCOMPARE(window.rootObject()->property("value").toString(), QLatin1String("pressed")); QMouseEvent releaseEvent(QEvent::MouseButtonRelease, QPoint(100, 100), Qt::LeftButton, Qt::LeftButton, 0); - QGuiApplication::sendEvent(window, &releaseEvent); + QGuiApplication::sendEvent(&window, &releaseEvent); - QCOMPARE(window->rootObject()->property("value").toString(), QLatin1String("toggled")); + QCOMPARE(window.rootObject()->property("value").toString(), QLatin1String("toggled")); - QGuiApplication::sendEvent(window, &pressEvent); + QGuiApplication::sendEvent(&window, &pressEvent); - QCOMPARE(window->rootObject()->property("value").toString(), QLatin1String("pressed")); - - delete window; + QCOMPARE(window.rootObject()->property("value").toString(), QLatin1String("pressed")); } void tst_QQuickMouseArea::preventStealing() { - QQuickView *window = createView(); - - window->setSource(testFileUrl("preventstealing.qml")); - window->show(); - QTest::qWaitForWindowExposed(window); - QVERIFY(window->rootObject() != 0); - - QQuickFlickable *flickable = qobject_cast(window->rootObject()); + QQuickView window; + QByteArray errorMessage; + QVERIFY2(initView(window, testFileUrl("preventstealing.qml"), true, &errorMessage), errorMessage.constData()); + window.show(); + QVERIFY(QTest::qWaitForWindowExposed(&window)); + QVERIFY(window.rootObject() != 0); + + QQuickFlickable *flickable = qobject_cast(window.rootObject()); QVERIFY(flickable != 0); - QQuickMouseArea *mouseArea = window->rootObject()->findChild("mousearea"); + QQuickMouseArea *mouseArea = window.rootObject()->findChild("mousearea"); QVERIFY(mouseArea != 0); QSignalSpy mousePositionSpy(mouseArea, SIGNAL(positionChanged(QQuickMouseEvent*))); - QTest::mousePress(window, Qt::LeftButton, 0, QPoint(80, 80)); + QTest::mousePress(&window, Qt::LeftButton, 0, QPoint(80, 80)); // Without preventStealing, mouse movement over MouseArea would // cause the Flickable to steal mouse and trigger content movement. - QTest::mouseMove(window,QPoint(69,69)); - QTest::mouseMove(window,QPoint(58,58)); - QTest::mouseMove(window,QPoint(47,47)); + QTest::mouseMove(&window,QPoint(69,69)); + QTest::mouseMove(&window,QPoint(58,58)); + QTest::mouseMove(&window,QPoint(47,47)); // We should have received all three move events QCOMPARE(mousePositionSpy.count(), 3); @@ -783,19 +781,19 @@ void tst_QQuickMouseArea::preventStealing() QCOMPARE(flickable->contentX(), 0.); QCOMPARE(flickable->contentY(), 0.); - QTest::mouseRelease(window, Qt::LeftButton, 0, QPoint(47, 47)); + QTest::mouseRelease(&window, Qt::LeftButton, 0, QPoint(47, 47)); // Now allow stealing and confirm Flickable does its thing. - window->rootObject()->setProperty("stealing", false); + window.rootObject()->setProperty("stealing", false); - QTest::mousePress(window, Qt::LeftButton, 0, QPoint(80, 80)); + QTest::mousePress(&window, Qt::LeftButton, 0, QPoint(80, 80)); // Without preventStealing, mouse movement over MouseArea would // cause the Flickable to steal mouse and trigger content movement. - QTest::mouseMove(window,QPoint(69,69)); - QTest::mouseMove(window,QPoint(58,58)); - QTest::mouseMove(window,QPoint(47,47)); + QTest::mouseMove(&window,QPoint(69,69)); + QTest::mouseMove(&window,QPoint(58,58)); + QTest::mouseMove(&window,QPoint(47,47)); // We should only have received the first move event QCOMPARE(mousePositionSpy.count(), 4); @@ -807,23 +805,22 @@ void tst_QQuickMouseArea::preventStealing() QCOMPARE(flickable->contentX(), 11.); QCOMPARE(flickable->contentY(), 11.); - QTest::mouseRelease(window, Qt::LeftButton, 0, QPoint(50, 50)); - - delete window; + QTest::mouseRelease(&window, Qt::LeftButton, 0, QPoint(50, 50)); } void tst_QQuickMouseArea::clickThrough() { QSKIP("QTBUG-23976 Unstable"); //With no handlers defined click, doubleClick and PressAndHold should propagate to those with handlers - QQuickView *window = createView(); - window->setSource(testFileUrl("clickThrough.qml")); + QScopedPointer window(new QQuickView); + QByteArray errorMessage; + QVERIFY2(initView(*window.data(), testFileUrl("clickThrough.qml"), true, &errorMessage), errorMessage.constData()); window->show(); - QTest::qWaitForWindowExposed(window); + QVERIFY(QTest::qWaitForWindowExposed(window.data())); QVERIFY(window->rootObject() != 0); - QTest::mousePress(window, Qt::LeftButton, 0, QPoint(100,100)); - QTest::mouseRelease(window, Qt::LeftButton, 0, QPoint(100,100)); + QTest::mousePress(window.data(), Qt::LeftButton, 0, QPoint(100,100)); + QTest::mouseRelease(window.data(), Qt::LeftButton, 0, QPoint(100,100)); QTRY_COMPARE(window->rootObject()->property("presses").toInt(), 0); QTRY_COMPARE(window->rootObject()->property("clicks").toInt(), 1); @@ -832,15 +829,15 @@ void tst_QQuickMouseArea::clickThrough() int doubleClickInterval = qApp->styleHints()->mouseDoubleClickInterval() + 10; QTest::qWait(doubleClickInterval); - QTest::mousePress(window, Qt::LeftButton, 0, QPoint(100,100)); + QTest::mousePress(window.data(), Qt::LeftButton, 0, QPoint(100,100)); QTest::qWait(1000); - QTest::mouseRelease(window, Qt::LeftButton, 0, QPoint(100,100)); + QTest::mouseRelease(window.data(), Qt::LeftButton, 0, QPoint(100,100)); QTRY_COMPARE(window->rootObject()->property("presses").toInt(), 0); QTRY_COMPARE(window->rootObject()->property("clicks").toInt(), 1); QTRY_COMPARE(window->rootObject()->property("pressAndHolds").toInt(), 1); - QTest::mouseDClick(window, Qt::LeftButton, 0, QPoint(100,100)); + QTest::mouseDClick(window.data(), Qt::LeftButton, 0, QPoint(100,100)); QTest::qWait(100); QCOMPARE(window->rootObject()->property("presses").toInt(), 0); @@ -848,33 +845,32 @@ void tst_QQuickMouseArea::clickThrough() QTRY_COMPARE(window->rootObject()->property("doubleClicks").toInt(), 1); QCOMPARE(window->rootObject()->property("pressAndHolds").toInt(), 1); - delete window; + window.reset(new QQuickView); //With handlers defined click, doubleClick and PressAndHold should propagate only when explicitly ignored - window = createView(); - window->setSource(testFileUrl("clickThrough2.qml")); + QVERIFY2(initView(*window.data(), testFileUrl("clickThrough2.qml"), true, &errorMessage), errorMessage.constData()); window->show(); - QTest::qWaitForWindowExposed(window); + QVERIFY(QTest::qWaitForWindowExposed(window.data())); QVERIFY(window->rootObject() != 0); - QTest::mousePress(window, Qt::LeftButton, 0, QPoint(100,100)); - QTest::mouseRelease(window, Qt::LeftButton, 0, QPoint(100,100)); + QTest::mousePress(window.data(), Qt::LeftButton, 0, QPoint(100,100)); + QTest::mouseRelease(window.data(), Qt::LeftButton, 0, QPoint(100,100)); QCOMPARE(window->rootObject()->property("presses").toInt(), 0); QCOMPARE(window->rootObject()->property("clicks").toInt(), 0); QTest::qWait(doubleClickInterval); // to avoid generating a double click. - QTest::mousePress(window, Qt::LeftButton, 0, QPoint(100,100)); + QTest::mousePress(window.data(), Qt::LeftButton, 0, QPoint(100,100)); QTest::qWait(1000); - QTest::mouseRelease(window, Qt::LeftButton, 0, QPoint(100,100)); + QTest::mouseRelease(window.data(), Qt::LeftButton, 0, QPoint(100,100)); QTest::qWait(100); QCOMPARE(window->rootObject()->property("presses").toInt(), 0); QCOMPARE(window->rootObject()->property("clicks").toInt(), 0); QCOMPARE(window->rootObject()->property("pressAndHolds").toInt(), 0); - QTest::mouseDClick(window, Qt::LeftButton, 0, QPoint(100,100)); + QTest::mouseDClick(window.data(), Qt::LeftButton, 0, QPoint(100,100)); QTest::qWait(100); QCOMPARE(window->rootObject()->property("presses").toInt(), 0); @@ -885,23 +881,23 @@ void tst_QQuickMouseArea::clickThrough() window->rootObject()->setProperty("letThrough", QVariant(true)); QTest::qWait(doubleClickInterval); // to avoid generating a double click. - QTest::mousePress(window, Qt::LeftButton, 0, QPoint(100,100)); - QTest::mouseRelease(window, Qt::LeftButton, 0, QPoint(100,100)); + QTest::mousePress(window.data(), Qt::LeftButton, 0, QPoint(100,100)); + QTest::mouseRelease(window.data(), Qt::LeftButton, 0, QPoint(100,100)); QCOMPARE(window->rootObject()->property("presses").toInt(), 0); QTRY_COMPARE(window->rootObject()->property("clicks").toInt(), 1); QTest::qWait(doubleClickInterval); // to avoid generating a double click. - QTest::mousePress(window, Qt::LeftButton, 0, QPoint(100,100)); + QTest::mousePress(window.data(), Qt::LeftButton, 0, QPoint(100,100)); QTest::qWait(1000); - QTest::mouseRelease(window, Qt::LeftButton, 0, QPoint(100,100)); + QTest::mouseRelease(window.data(), Qt::LeftButton, 0, QPoint(100,100)); QTest::qWait(100); QCOMPARE(window->rootObject()->property("presses").toInt(), 0); QCOMPARE(window->rootObject()->property("clicks").toInt(), 1); QCOMPARE(window->rootObject()->property("pressAndHolds").toInt(), 1); - QTest::mouseDClick(window, Qt::LeftButton, 0, QPoint(100,100)); + QTest::mouseDClick(window.data(), Qt::LeftButton, 0, QPoint(100,100)); QTest::qWait(100); QCOMPARE(window->rootObject()->property("presses").toInt(), 0); @@ -912,88 +908,82 @@ void tst_QQuickMouseArea::clickThrough() window->rootObject()->setProperty("noPropagation", QVariant(true)); QTest::qWait(doubleClickInterval); // to avoid generating a double click. - QTest::mousePress(window, Qt::LeftButton, 0, QPoint(100,100)); - QTest::mouseRelease(window, Qt::LeftButton, 0, QPoint(100,100)); + QTest::mousePress(window.data(), Qt::LeftButton, 0, QPoint(100,100)); + QTest::mouseRelease(window.data(), Qt::LeftButton, 0, QPoint(100,100)); QTest::qWait(doubleClickInterval); // to avoid generating a double click. - QTest::mousePress(window, Qt::LeftButton, 0, QPoint(100,100)); + QTest::mousePress(window.data(), Qt::LeftButton, 0, QPoint(100,100)); QTest::qWait(1000); - QTest::mouseRelease(window, Qt::LeftButton, 0, QPoint(100,100)); + QTest::mouseRelease(window.data(), Qt::LeftButton, 0, QPoint(100,100)); QTest::qWait(100); - QTest::mouseDClick(window, Qt::LeftButton, 0, QPoint(100,100)); + QTest::mouseDClick(window.data(), Qt::LeftButton, 0, QPoint(100,100)); QTest::qWait(100); QCOMPARE(window->rootObject()->property("presses").toInt(), 0); QTRY_COMPARE(window->rootObject()->property("clicks").toInt(), 2); QCOMPARE(window->rootObject()->property("doubleClicks").toInt(), 1); QCOMPARE(window->rootObject()->property("pressAndHolds").toInt(), 1); - - delete window; } void tst_QQuickMouseArea::hoverPosition() { - QQuickView *window = createView(); - window->setSource(testFileUrl("hoverPosition.qml")); - - QQuickItem *root = window->rootObject(); + QQuickView window; + QByteArray errorMessage; + QVERIFY2(initView(window, testFileUrl("hoverPosition.qml"), true, &errorMessage), errorMessage.constData()); + QQuickItem *root = window.rootObject(); QVERIFY(root != 0); QCOMPARE(root->property("mouseX").toReal(), qreal(0)); QCOMPARE(root->property("mouseY").toReal(), qreal(0)); - QTest::mouseMove(window,QPoint(10,32)); + QTest::mouseMove(&window,QPoint(10,32)); QCOMPARE(root->property("mouseX").toReal(), qreal(10)); QCOMPARE(root->property("mouseY").toReal(), qreal(32)); - - delete window; } void tst_QQuickMouseArea::hoverPropagation() { //QTBUG-18175, to behave like GV did. - QQuickView *window = createView(); - window->setSource(testFileUrl("hoverPropagation.qml")); - - QQuickItem *root = window->rootObject(); + QQuickView window; + QByteArray errorMessage; + QVERIFY2(initView(window, testFileUrl("hoverPropagation.qml"), true, &errorMessage), errorMessage.constData()); + QQuickItem *root = window.rootObject(); QVERIFY(root != 0); QCOMPARE(root->property("point1").toBool(), false); QCOMPARE(root->property("point2").toBool(), false); QMouseEvent moveEvent(QEvent::MouseMove, QPoint(32, 32), Qt::NoButton, Qt::NoButton, 0); - QGuiApplication::sendEvent(window, &moveEvent); + QGuiApplication::sendEvent(&window, &moveEvent); QCOMPARE(root->property("point1").toBool(), true); QCOMPARE(root->property("point2").toBool(), false); QMouseEvent moveEvent2(QEvent::MouseMove, QPoint(232, 32), Qt::NoButton, Qt::NoButton, 0); - QGuiApplication::sendEvent(window, &moveEvent2); + QGuiApplication::sendEvent(&window, &moveEvent2); QCOMPARE(root->property("point1").toBool(), false); QCOMPARE(root->property("point2").toBool(), true); - - delete window; } void tst_QQuickMouseArea::hoverVisible() { - QQuickView *window = createView(); - window->setSource(testFileUrl("hoverVisible.qml")); - - QQuickItem *root = window->rootObject(); + QQuickView window; + QByteArray errorMessage; + QVERIFY2(initView(window, testFileUrl("hoverVisible.qml"), true, &errorMessage), errorMessage.constData()); + QQuickItem *root = window.rootObject(); QVERIFY(root != 0); - QQuickMouseArea *mouseTracker = window->rootObject()->findChild("mousetracker"); + QQuickMouseArea *mouseTracker = window.rootObject()->findChild("mousetracker"); QVERIFY(mouseTracker != 0); QSignalSpy enteredSpy(mouseTracker, SIGNAL(entered())); // Note: We need to use a position that is different from the position in the last event // generated in the previous test case. Otherwise it is not interpreted as a move. - QTest::mouseMove(window,QPoint(11,33)); + QTest::mouseMove(&window,QPoint(11,33)); QCOMPARE(mouseTracker->hovered(), false); QCOMPARE(enteredSpy.count(), 0); @@ -1004,46 +994,44 @@ void tst_QQuickMouseArea::hoverVisible() QCOMPARE(enteredSpy.count(), 1); QCOMPARE(QPointF(mouseTracker->mouseX(), mouseTracker->mouseY()), QPointF(11,33)); - - delete window; } void tst_QQuickMouseArea::hoverAfterPress() { - QQuickView *window = createView(); - window->setSource(testFileUrl("hoverAfterPress.qml")); - - QQuickItem *root = window->rootObject(); + QQuickView window; + QByteArray errorMessage; + QVERIFY2(initView(window, testFileUrl("hoverAfterPress.qml"), true, &errorMessage), errorMessage.constData()); + QQuickItem *root = window.rootObject(); QVERIFY(root != 0); - QQuickMouseArea *mouseArea = window->rootObject()->findChild("mouseArea"); + QQuickMouseArea *mouseArea = window.rootObject()->findChild("mouseArea"); QVERIFY(mouseArea != 0); - QTest::mouseMove(window, QPoint(22,33)); + QTest::mouseMove(&window, QPoint(22,33)); QCOMPARE(mouseArea->hovered(), false); - QTest::mouseMove(window, QPoint(200,200)); + QTest::mouseMove(&window, QPoint(200,200)); QCOMPARE(mouseArea->hovered(), true); - QTest::mouseMove(window, QPoint(22,33)); + QTest::mouseMove(&window, QPoint(22,33)); QCOMPARE(mouseArea->hovered(), false); - QTest::mouseMove(window, QPoint(200,200)); + QTest::mouseMove(&window, QPoint(200,200)); QCOMPARE(mouseArea->hovered(), true); - QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, QPoint(200,200)); + QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, QPoint(200,200)); QCOMPARE(mouseArea->hovered(), true); - QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, QPoint(200,200)); + QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, QPoint(200,200)); QCOMPARE(mouseArea->hovered(), true); - QTest::mouseMove(window, QPoint(22,33)); + QTest::mouseMove(&window, QPoint(22,33)); QCOMPARE(mouseArea->hovered(), false); - delete window; } void tst_QQuickMouseArea::disableAfterPress() { - QQuickView *window = createView(); - window->setSource(testFileUrl("dragging.qml")); - window->show(); - QTest::qWaitForWindowExposed(window); - QVERIFY(window->rootObject() != 0); - - QQuickMouseArea *mouseArea = window->rootObject()->findChild("mouseregion"); + QQuickView window; + QByteArray errorMessage; + QVERIFY2(initView(window, testFileUrl("dragging.qml"), true, &errorMessage), errorMessage.constData()); + window.show(); + QVERIFY(QTest::qWaitForWindowExposed(&window)); + QVERIFY(window.rootObject() != 0); + + QQuickMouseArea *mouseArea = window.rootObject()->findChild("mouseregion"); QQuickDrag *drag = mouseArea->drag(); QVERIFY(mouseArea != 0); QVERIFY(drag != 0); @@ -1053,13 +1041,13 @@ void tst_QQuickMouseArea::disableAfterPress() QSignalSpy mouseReleaseSpy(mouseArea, SIGNAL(released(QQuickMouseEvent*))); // target - QQuickItem *blackRect = window->rootObject()->findChild("blackrect"); + QQuickItem *blackRect = window.rootObject()->findChild("blackrect"); QVERIFY(blackRect != 0); QVERIFY(blackRect == drag->target()); QVERIFY(!drag->active()); - QTest::mousePress(window, Qt::LeftButton, 0, QPoint(100,100)); + QTest::mousePress(&window, Qt::LeftButton, 0, QPoint(100,100)); QTRY_COMPARE(mousePressSpy.count(), 1); @@ -1070,9 +1058,9 @@ void tst_QQuickMouseArea::disableAfterPress() // First move event triggers drag, second is acted upon. // This is due to possibility of higher stacked area taking precedence. - QTest::mouseMove(window, QPoint(111,111)); + QTest::mouseMove(&window, QPoint(111,111)); QTest::qWait(50); - QTest::mouseMove(window, QPoint(122,122)); + QTest::mouseMove(&window, QPoint(122,122)); QTRY_COMPARE(mousePositionSpy.count(), 2); @@ -1083,9 +1071,9 @@ void tst_QQuickMouseArea::disableAfterPress() mouseArea->setEnabled(false); // move should still be acted upon - QTest::mouseMove(window, QPoint(133,133)); + QTest::mouseMove(&window, QPoint(133,133)); QTest::qWait(50); - QTest::mouseMove(window, QPoint(144,144)); + QTest::mouseMove(&window, QPoint(144,144)); QTRY_COMPARE(mousePositionSpy.count(), 4); @@ -1096,7 +1084,7 @@ void tst_QQuickMouseArea::disableAfterPress() QVERIFY(mouseArea->pressed()); QVERIFY(mouseArea->hovered()); - QTest::mouseRelease(window, Qt::LeftButton, 0, QPoint(144,144)); + QTest::mouseRelease(&window, Qt::LeftButton, 0, QPoint(144,144)); QTRY_COMPARE(mouseReleaseSpy.count(), 1); @@ -1115,13 +1103,13 @@ void tst_QQuickMouseArea::disableAfterPress() mousePositionSpy.clear(); mouseReleaseSpy.clear(); - QTest::mousePress(window, Qt::LeftButton, 0, QPoint(100,100)); + QTest::mousePress(&window, Qt::LeftButton, 0, QPoint(100,100)); QTest::qWait(50); QCOMPARE(mousePressSpy.count(), 0); - QTest::mouseMove(window, QPoint(111,111)); + QTest::mouseMove(&window, QPoint(111,111)); QTest::qWait(50); - QTest::mouseMove(window, QPoint(122,122)); + QTest::mouseMove(&window, QPoint(122,122)); QTest::qWait(50); QCOMPARE(mousePositionSpy.count(), 0); @@ -1130,32 +1118,28 @@ void tst_QQuickMouseArea::disableAfterPress() QCOMPARE(blackRect->x(), 50.0); QCOMPARE(blackRect->y(), 50.0); - QTest::mouseRelease(window, Qt::LeftButton, 0, QPoint(122,122)); + QTest::mouseRelease(&window, Qt::LeftButton, 0, QPoint(122,122)); QTest::qWait(50); QCOMPARE(mouseReleaseSpy.count(), 0); - - delete window; } void tst_QQuickMouseArea::onWheel() { - QQuickView *window = createView(); - window->setSource(testFileUrl("wheel.qml")); - - QQuickItem *root = window->rootObject(); + QQuickView window; + QByteArray errorMessage; + QVERIFY2(initView(window, testFileUrl("wheel.qml"), true, &errorMessage), errorMessage.constData()); + QQuickItem *root = window.rootObject(); QVERIFY(root != 0); QWheelEvent wheelEvent(QPoint(10, 32), QPoint(10, 32), QPoint(60, 20), QPoint(0, 120), 0, Qt::Vertical,Qt::NoButton, Qt::ControlModifier); - QGuiApplication::sendEvent(window, &wheelEvent); + QGuiApplication::sendEvent(&window, &wheelEvent); QCOMPARE(root->property("angleDeltaY").toInt(), 120); QCOMPARE(root->property("mouseX").toReal(), qreal(10)); QCOMPARE(root->property("mouseY").toReal(), qreal(32)); QCOMPARE(root->property("controlPressed").toBool(), true); - - delete window; } void tst_QQuickMouseArea::transformedMouseArea_data() @@ -1186,30 +1170,29 @@ void tst_QQuickMouseArea::transformedMouseArea() QFETCH(bool, insideTarget); QFETCH(QList, points); - QQuickView *window = createView(); - window->setSource(testFileUrl("transformedMouseArea.qml")); - window->show(); - QTest::qWaitForWindowExposed(window); - QVERIFY(window->rootObject() != 0); + QQuickView window; + QByteArray errorMessage; + QVERIFY2(initView(window, testFileUrl("transformedMouseArea.qml"), true, &errorMessage), errorMessage.constData()); + window.show(); + QVERIFY(QTest::qWaitForWindowExposed(&window)); + QVERIFY(window.rootObject() != 0); - QQuickMouseArea *mouseArea = window->rootObject()->findChild("mouseArea"); + QQuickMouseArea *mouseArea = window.rootObject()->findChild("mouseArea"); QVERIFY(mouseArea != 0); foreach (const QPoint &point, points) { // check hover - QTest::mouseMove(window, point); + QTest::mouseMove(&window, point); QTRY_COMPARE(mouseArea->property("containsMouse").toBool(), insideTarget); // check mouse press - QTest::mousePress(window, Qt::LeftButton, 0, point); + QTest::mousePress(&window, Qt::LeftButton, 0, point); QTRY_COMPARE(mouseArea->property("pressed").toBool(), insideTarget); // check mouse release - QTest::mouseRelease(window, Qt::LeftButton, 0, point); + QTest::mouseRelease(&window, Qt::LeftButton, 0, point); QTRY_COMPARE(mouseArea->property("pressed").toBool(), false); } - - delete window; } void tst_QQuickMouseArea::pressedMultipleButtons_data() @@ -1301,13 +1284,14 @@ void tst_QQuickMouseArea::pressedMultipleButtons() QFETCH(QList, pressedButtons); QFETCH(int, changeCount); - QQuickView *view = createView(); - view->setSource(testFileUrl("simple.qml")); - view->show(); - QTest::qWaitForWindowExposed(view); - QVERIFY(view->rootObject() != 0); + QQuickView view; + QByteArray errorMessage; + QVERIFY2(initView(view, testFileUrl("simple.qml"), true, &errorMessage), errorMessage.constData()); + view.show(); + QTest::qWaitForWindowExposed(&view); + QVERIFY(view.rootObject() != 0); - QQuickMouseArea *mouseArea = view->rootObject()->findChild("mousearea"); + QQuickMouseArea *mouseArea = view.rootObject()->findChild("mousearea"); QVERIFY(mouseArea != 0); QSignalSpy pressedSpy(mouseArea, SIGNAL(pressedChanged())); @@ -1320,31 +1304,29 @@ void tst_QQuickMouseArea::pressedMultipleButtons() int btns = buttons.at(i); // The windowsysteminterface takes care of sending releases - QTest::mousePress(view, (Qt::MouseButton)btns, 0, point); + QTest::mousePress(&view, (Qt::MouseButton)btns, 0, point); QCOMPARE(mouseArea->pressed(), pressed.at(i)); QCOMPARE(mouseArea->pressedButtons(), pressedButtons.at(i)); } - QTest::mousePress(view, Qt::NoButton, 0, point); + QTest::mousePress(&view, Qt::NoButton, 0, point); QCOMPARE(mouseArea->pressed(), false); QCOMPARE(pressedSpy.count(), 2); QCOMPARE(pressedButtonsSpy.count(), changeCount); - - delete view; } void tst_QQuickMouseArea::changeAxis() { - QQuickView *view = createView(); - - view->setSource(testFileUrl("changeAxis.qml")); - view->show(); - QTest::qWaitForWindowExposed(view); - QTRY_VERIFY(view->rootObject() != 0); + QQuickView view; + QByteArray errorMessage; + QVERIFY2(initView(view, testFileUrl("changeAxis.qml"), true, &errorMessage), errorMessage.constData()); + view.show(); + QVERIFY(QTest::qWaitForWindowExposed(&view)); + QTRY_VERIFY(view.rootObject() != 0); - QQuickMouseArea *mouseRegion = view->rootObject()->findChild("mouseregion"); + QQuickMouseArea *mouseRegion = view.rootObject()->findChild("mouseregion"); QQuickDrag *drag = mouseRegion->drag(); QVERIFY(mouseRegion != 0); QVERIFY(drag != 0); @@ -1352,22 +1334,22 @@ void tst_QQuickMouseArea::changeAxis() mouseRegion->setAcceptedButtons(Qt::LeftButton); // target - QQuickItem *blackRect = view->rootObject()->findChild("blackrect"); + QQuickItem *blackRect = view.rootObject()->findChild("blackrect"); QVERIFY(blackRect != 0); QVERIFY(blackRect == drag->target()); QVERIFY(!drag->active()); // Start a diagonal drag - QTest::mousePress(view, Qt::LeftButton, 0, QPoint(100, 100)); + QTest::mousePress(&view, Qt::LeftButton, 0, QPoint(100, 100)); QVERIFY(!drag->active()); QCOMPARE(blackRect->x(), 50.0); QCOMPARE(blackRect->y(), 50.0); - QTest::mouseMove(view, QPoint(111, 111)); + QTest::mouseMove(&view, QPoint(111, 111)); QTest::qWait(50); - QTest::mouseMove(view, QPoint(122, 122)); + QTest::mouseMove(&view, QPoint(122, 122)); QTRY_VERIFY(drag->active()); QCOMPARE(blackRect->x(), 61.0); @@ -1377,24 +1359,22 @@ void tst_QQuickMouseArea::changeAxis() /* When blackRect.x becomes bigger than 75, the drag axis is changed to * Drag.YAxis by the QML code. Verify that this happens, and that the drag * movement is effectively constrained to the Y axis. */ - QTest::mouseMove(view, QPoint(144, 144)); + QTest::mouseMove(&view, QPoint(144, 144)); QTRY_COMPARE(blackRect->x(), 83.0); QTRY_COMPARE(blackRect->y(), 83.0); QTRY_COMPARE(drag->axis(), QQuickDrag::YAxis); - QTest::mouseMove(view, QPoint(155, 155)); + QTest::mouseMove(&view, QPoint(155, 155)); QTRY_COMPARE(blackRect->y(), 94.0); QCOMPARE(blackRect->x(), 83.0); - QTest::mouseRelease(view, Qt::LeftButton, 0, QPoint(155, 155)); + QTest::mouseRelease(&view, Qt::LeftButton, 0, QPoint(155, 155)); QTRY_VERIFY(!drag->active()); QCOMPARE(blackRect->x(), 83.0); QCOMPARE(blackRect->y(), 94.0); - - delete view; } #ifndef QT_NO_CURSOR @@ -1429,25 +1409,22 @@ void tst_QQuickMouseArea::cursorShape() void tst_QQuickMouseArea::moveAndReleaseWithoutPress() { - QQuickView *window = createView(); + QQuickView window; + QByteArray errorMessage; + QVERIFY2(initView(window, testFileUrl("moveAndReleaseWithoutPress.qml"), true, &errorMessage), errorMessage.constData()); + window.show(); + QVERIFY(QTest::qWaitForWindowExposed(&window)); - window->setSource(testFileUrl("moveAndReleaseWithoutPress.qml")); - window->show(); - QTest::qWaitForWindowExposed(window); - QVERIFY(QTest::qWaitForWindowExposed(window)); - - QObject *root = window->rootObject(); + QObject *root = window.rootObject(); QVERIFY(root); - QTest::mousePress(window, Qt::LeftButton, 0, QPoint(100,100)); + QTest::mousePress(&window, Qt::LeftButton, 0, QPoint(100,100)); - QTest::mouseMove(window, QPoint(110,110), 50); + QTest::mouseMove(&window, QPoint(110,110), 50); QTRY_COMPARE(root->property("hadMove").toBool(), false); - QTest::mouseRelease(window, Qt::LeftButton, 0, QPoint(110,110)); + QTest::mouseRelease(&window, Qt::LeftButton, 0, QPoint(110,110)); QTRY_COMPARE(root->property("hadRelease").toBool(), false); - - delete window; } void tst_QQuickMouseArea::nestedStopAtBounds_data() @@ -1467,7 +1444,8 @@ void tst_QQuickMouseArea::nestedStopAtBounds() QFETCH(bool, invert); QQuickView view; - view.setSource(testFileUrl("nestedStopAtBounds.qml")); + QByteArray errorMessage; + QVERIFY2(initView(view, testFileUrl("nestedStopAtBounds.qml"), true, &errorMessage), errorMessage.constData()); view.show(); view.requestActivate(); QVERIFY(QTest::qWaitForWindowExposed(&view));