From 1f451da9d7ec33dd38b13ca4f98d8453cf7814de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Tue, 25 Jun 2019 10:01:00 +0200 Subject: Revert "Temporarily skip tst_QSslSocket::resume" This reverts commit 9a25d27b9d58316dee5d2305135d2d74ad5d51e7. The QSKIP is no longer needed as the imap server's certificate was updated Task-number: QTBUG-76610 Change-Id: I1007ce50d6f7f6258fdeb8894c66678a660b03ca Reviewed-by: Timur Pocheptsov --- tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'tests/auto') diff --git a/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp b/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp index 7420cd1296..307e3d82bd 100644 --- a/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp +++ b/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp @@ -2780,7 +2780,6 @@ void tst_QSslSocket::encryptWithoutConnecting() void tst_QSslSocket::resume_data() { - QSKIP("Temporary skip while updating certificates"); QTest::addColumn("ignoreErrorsAfterPause"); QTest::addColumn >("errorsToIgnore"); QTest::addColumn("expectSuccess"); -- cgit v1.2.3 From 307403f8b4f25f3fa711fb64102c755d50283c2b Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Fri, 5 Jul 2019 17:20:14 +0200 Subject: Stabilize QGraphicsItem::cursor and select_multi tests The tests send QEvent::MouseMove events to the view, but don't fully construct the event with both local and global position. Consequently, QMouseEvent will use QCursor::pos as the global position, which is unreliable, as QTest::mouseMove can not guarantee that the mouse really moves - when running the tests locally on e.g macOS, it never does. So instead construct the QMouseEvent with the trivially calculated global position. Change-Id: Ic4c914e3af7f15751545080d4743b06d3887cce8 Reviewed-by: Andreas Aardal Hanssen --- .../qgraphicsitem/tst_qgraphicsitem.cpp | 26 +++++++++++++--------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp index ae0d91dfe3..af4b6c9e4a 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp @@ -1811,7 +1811,8 @@ void tst_QGraphicsItem::selected_multi() { // Ctrl-move on item1 - QMouseEvent event(QEvent::MouseMove, view.mapFromScene(item1->scenePos()) + QPoint(1, 0), Qt::LeftButton, Qt::LeftButton, Qt::ControlModifier); + const QPoint item1Point = view.mapFromScene(item1->scenePos()) + QPoint(1, 0); + QMouseEvent event(QEvent::MouseMove, item1Point, view.viewport()->mapToGlobal(item1Point), Qt::LeftButton, Qt::LeftButton, Qt::ControlModifier); QApplication::sendEvent(view.viewport(), &event); QVERIFY(!item1->isSelected()); QVERIFY(!item2->isSelected()); @@ -1832,7 +1833,8 @@ void tst_QGraphicsItem::selected_multi() { // Ctrl-move on item1 - QMouseEvent event(QEvent::MouseMove, view.mapFromScene(item1->scenePos()) + QPoint(1, 0), Qt::LeftButton, Qt::LeftButton, Qt::ControlModifier); + const QPoint item1Point = view.mapFromScene(item1->scenePos()) + QPoint(1, 0); + QMouseEvent event(QEvent::MouseMove, item1Point, view.viewport()->mapToGlobal(item1Point), Qt::LeftButton, Qt::LeftButton, Qt::ControlModifier); QApplication::sendEvent(view.viewport(), &event); QVERIFY(item1->isSelected()); QVERIFY(!item2->isSelected()); @@ -4178,37 +4180,41 @@ void tst_QGraphicsItem::cursor() item1->setCursor(Qt::IBeamCursor); item2->setCursor(Qt::PointingHandCursor); - QTest::mouseMove(&view, view.rect().center()); + QPoint viewCenter = view.rect().center(); + QPoint item1Center = view.mapFromScene(item1->sceneBoundingRect().center()); + QPoint item2Center = view.mapFromScene(item2->sceneBoundingRect().center()); + + QTest::mouseMove(&view, viewCenter); const Qt::CursorShape viewportShape = view.viewport()->cursor().shape(); { QTest::mouseMove(view.viewport(), QPoint(100, 50)); - QMouseEvent event(QEvent::MouseMove, QPoint(100, 50), Qt::NoButton, 0, 0); + QMouseEvent event(QEvent::MouseMove, QPoint(100, 50), view.viewport()->mapToGlobal(QPoint(100, 50)), Qt::NoButton, 0, 0); QApplication::sendEvent(view.viewport(), &event); } QTRY_COMPARE(view.viewport()->cursor().shape(), viewportShape); { - QTest::mouseMove(view.viewport(), view.mapFromScene(item1->sceneBoundingRect().center())); - QMouseEvent event(QEvent::MouseMove, view.mapFromScene(item1->sceneBoundingRect().center()), Qt::NoButton, 0, 0); + QTest::mouseMove(view.viewport(), item1Center); + QMouseEvent event(QEvent::MouseMove, item1Center, view.viewport()->mapToGlobal(item1Center), Qt::NoButton, 0, 0); QApplication::sendEvent(view.viewport(), &event); } QTRY_COMPARE(view.viewport()->cursor().shape(), item1->cursor().shape()); { - QTest::mouseMove(view.viewport(), view.mapFromScene(item2->sceneBoundingRect().center())); - QMouseEvent event(QEvent::MouseMove, view.mapFromScene(item2->sceneBoundingRect().center()), Qt::NoButton, 0, 0); + QTest::mouseMove(view.viewport(), item2Center); + QMouseEvent event(QEvent::MouseMove, item2Center, view.viewport()->mapToGlobal(item2Center), Qt::NoButton, 0, 0); QApplication::sendEvent(view.viewport(), &event); } QTRY_COMPARE(view.viewport()->cursor().shape(), item2->cursor().shape()); { - QTest::mouseMove(view.viewport(), view.rect().center()); - QMouseEvent event(QEvent::MouseMove, QPoint(100, 25), Qt::NoButton, 0, 0); + QTest::mouseMove(view.viewport(), viewCenter); + QMouseEvent event(QEvent::MouseMove, QPoint(100, 25), view.viewport()->mapToGlobal(QPoint(100, 50)), Qt::NoButton, 0, 0); QApplication::sendEvent(view.viewport(), &event); } -- cgit v1.2.3 From d8688d44840dd3f2324769d10b927c442b42e2c0 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Fri, 5 Jul 2019 17:24:22 +0200 Subject: Don't set the mouse cursor for items that are disabled As with widgets, items that are disabled should not receive any input events. Similar to QGraphicsScene, which ignores disabled items when handling mouse presses, the view should also ignore them when handling mouse moves to update the cursor. Since QGraphicsView only adjusts the cursors on mouse moves, reenabling an item that is currently under the mouse will not change the cursor. This is consistent with other changes of item attributes that would position the item under the mouse (such as moving it). The overhead of hit-testing items for every such attribute change would be too large, and applications can generate a mouse move event if they really need to adjust the cursor in all situations. [ChangeLog][QtWidgets][QGraphicsView] Ignore disabled items when setting the mouse cursor. Fixes: QTBUG-76765 Change-Id: Ifcd31fc0581e8421e58eeb436a55b031909eed7e Reviewed-by: Shawn Rutledge --- .../widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp index af4b6c9e4a..3260e09943 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp @@ -4219,6 +4219,15 @@ void tst_QGraphicsItem::cursor() } QTRY_COMPARE(view.viewport()->cursor().shape(), viewportShape); + + item1->setEnabled(false); + { + QTest::mouseMove(view.viewport(), item1Center); + QMouseEvent event(QEvent::MouseMove, item1Center, view.viewport()->mapToGlobal(item1Center), Qt::NoButton, 0, 0); + QApplication::sendEvent(view.viewport(), &event); + } + + QTRY_COMPARE(view.viewport()->cursor().shape(), viewportShape); } #endif /* -- cgit v1.2.3 From 59b29d03b2fff8a138382d45077c81fe0d4b8ea8 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Tue, 9 Jul 2019 15:18:46 +0200 Subject: Further stabilization of QGraphicsItem::cursor test The QTest::mouseMove calls are not reliable, and seem to produce flakiness, at least on WinRT. Removing them, and only depending on handling of the synchronously delivered QMouseEVent for simulated mouse moves. Also, initialize the expected cursor shape from an empty scene; this avoids that showing the view with the cursor accidentially on an item results in the wrong default shape. Remove hard coded coordinates, just test what we know. Fixes: QTBUG-73545 Change-Id: I6f81d6b16bb613ec77aaa776d6a80aac739aeb58 Reviewed-by: Volker Hilsheimer --- .../qgraphicsitem/tst_qgraphicsitem.cpp | 25 ++++++++-------------- 1 file changed, 9 insertions(+), 16 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp index 3260e09943..e071edc332 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp @@ -4153,6 +4153,8 @@ void tst_QGraphicsItem::cursor() QGraphicsView view(&scene); view.showFullScreen(); QVERIFY(QTest::qWaitForWindowExposed(&view)); + const Qt::CursorShape viewportShape = view.viewport()->cursor().shape(); + QGraphicsRectItem *item1 = scene.addRect(QRectF(-100, 0, 50, 50)); QGraphicsRectItem *item2 = scene.addRect(QRectF(50, 0, 50, 50)); @@ -4184,50 +4186,41 @@ void tst_QGraphicsItem::cursor() QPoint item1Center = view.mapFromScene(item1->sceneBoundingRect().center()); QPoint item2Center = view.mapFromScene(item2->sceneBoundingRect().center()); - QTest::mouseMove(&view, viewCenter); - - const Qt::CursorShape viewportShape = view.viewport()->cursor().shape(); - { - QTest::mouseMove(view.viewport(), QPoint(100, 50)); - QMouseEvent event(QEvent::MouseMove, QPoint(100, 50), view.viewport()->mapToGlobal(QPoint(100, 50)), Qt::NoButton, 0, 0); + QMouseEvent event(QEvent::MouseMove, viewCenter, view.viewport()->mapToGlobal(viewCenter), Qt::NoButton, 0, 0); QApplication::sendEvent(view.viewport(), &event); } - QTRY_COMPARE(view.viewport()->cursor().shape(), viewportShape); + QCOMPARE(view.viewport()->cursor().shape(), viewportShape); { - QTest::mouseMove(view.viewport(), item1Center); QMouseEvent event(QEvent::MouseMove, item1Center, view.viewport()->mapToGlobal(item1Center), Qt::NoButton, 0, 0); QApplication::sendEvent(view.viewport(), &event); } - QTRY_COMPARE(view.viewport()->cursor().shape(), item1->cursor().shape()); + QCOMPARE(view.viewport()->cursor().shape(), item1->cursor().shape()); { - QTest::mouseMove(view.viewport(), item2Center); QMouseEvent event(QEvent::MouseMove, item2Center, view.viewport()->mapToGlobal(item2Center), Qt::NoButton, 0, 0); QApplication::sendEvent(view.viewport(), &event); } - QTRY_COMPARE(view.viewport()->cursor().shape(), item2->cursor().shape()); + QCOMPARE(view.viewport()->cursor().shape(), item2->cursor().shape()); { - QTest::mouseMove(view.viewport(), viewCenter); - QMouseEvent event(QEvent::MouseMove, QPoint(100, 25), view.viewport()->mapToGlobal(QPoint(100, 50)), Qt::NoButton, 0, 0); + QMouseEvent event(QEvent::MouseMove, viewCenter, view.viewport()->mapToGlobal(viewCenter), Qt::NoButton, 0, 0); QApplication::sendEvent(view.viewport(), &event); } - QTRY_COMPARE(view.viewport()->cursor().shape(), viewportShape); + QCOMPARE(view.viewport()->cursor().shape(), viewportShape); item1->setEnabled(false); { - QTest::mouseMove(view.viewport(), item1Center); QMouseEvent event(QEvent::MouseMove, item1Center, view.viewport()->mapToGlobal(item1Center), Qt::NoButton, 0, 0); QApplication::sendEvent(view.viewport(), &event); } - QTRY_COMPARE(view.viewport()->cursor().shape(), viewportShape); + QCOMPARE(view.viewport()->cursor().shape(), viewportShape); } #endif /* -- cgit v1.2.3 From b426cff1e0363b350f98bc64691b9b279bc6c757 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Wed, 3 Jul 2019 16:25:54 +0200 Subject: Make tst_QGraphicsItem painting tests most robust Counting absolute paint events is fragile, as there are no guarantees that a single call to QApp::processEvents only delivers a single paint event to a widget. As of QTBUG-76566, we see that the items occasionally receive three calls to paint, which can be simulated by activating other windows while the test is running and waiting for events to be processed. Instead, verify that we do receive any paint events as the first test, and then verify increments when we expect updates. This also reverts change 24b9424adcda1ab083fae4ae857007227ba5fee2. Change-Id: Ib51853e918f31acd3aea10d4109c95f34012a29f Fixes: QTBUG-76566 Reviewed-by: Dimitrios Apostolou Reviewed-by: Andreas Aardal Hanssen --- .../qgraphicsitem/tst_qgraphicsitem.cpp | 25 ++++++++++------------ 1 file changed, 11 insertions(+), 14 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp index e071edc332..872e0b62c5 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp @@ -5057,12 +5057,6 @@ public: void tst_QGraphicsItem::paint() { -#if defined(Q_OS_MACOS) - if (QSysInfo::productVersion() == QLatin1String("10.12")) { - QSKIP("Test is very flaky on MacOS_10_12, see QTBUG-76566"); - } -#endif - QGraphicsScene scene; PaintTester paintTester; @@ -5092,22 +5086,25 @@ void tst_QGraphicsItem::paint() PaintTester tester2; scene2.addItem(&tester2); - //First show one paint - QTRY_COMPARE(tester2.painted, 1); + //First show at least one paint + QCOMPARE(tester2.painted, 0); + QTRY_VERIFY(tester2.painted > 0); + int painted = tester2.painted; //nominal case, update call paint tester2.update(); - QTRY_COMPARE(tester2.painted, 2); + QTRY_COMPARE(tester2.painted, painted + 1); + painted = tester2.painted; //we remove the item from the scene, number of updates is still the same tester2.update(); scene2.removeItem(&tester2); - QTRY_COMPARE(tester2.painted, 2); + QTRY_COMPARE(tester2.painted, painted); //We re-add the item, the number of paint should increase scene2.addItem(&tester2); tester2.update(); - QTRY_COMPARE(tester2.painted, 3); + QTRY_COMPARE(tester2.painted, painted + 1); } class HarakiriItem : public QGraphicsRectItem @@ -11377,7 +11374,7 @@ void tst_QGraphicsItem::QTBUG_7714_fullUpdateDiscardingOpacityUpdate2() origView.reset(); childYellow->setOpacity(0.0); - QTRY_COMPARE(origView.repaints, 1); + QTRY_VERIFY(origView.repaints > 0); view.show(); qApp->setActiveWindow(&view); @@ -11392,8 +11389,8 @@ void tst_QGraphicsItem::QTBUG_7714_fullUpdateDiscardingOpacityUpdate2() QEXPECT_FAIL("", "Fails on WinRT. Figure out why - QTBUG-68297", Abort); #endif - QTRY_COMPARE(origView.repaints, 1); - QTRY_COMPARE(view.repaints, 1); + QTRY_VERIFY(origView.repaints > 0); + QTRY_VERIFY(view.repaints > 0); } void tst_QGraphicsItem::QT_2649_focusScope() -- cgit v1.2.3 From cc32226e647854a02ecd0775787bb08b85e2a014 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Tue, 2 Jul 2019 14:28:58 +0200 Subject: Windows: handle errors correctly when connecting to unreachable host MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The previous code handled only some error codes, in a very inefficient way, for some code paths. This change standardizes error handling using a helper function that maps winsock WSAE* codes to Qt error codes. The test for connecting to unreachable hosts or ports is now more generic, and enabled on Windows, where it passes in local tests, but dependency on network configuration still makes it fragile, so ignoring some failures without completely skipping the test. [ChangeLog][Network][Windows] Correctly emit errors when trying to reach unreachable hosts or services Change-Id: Icaca3e6fef88621d683f6d6fa3016212847de4ea Fixes: QTBUG-42567 Reviewed-by: MÃ¥rten Nordheim --- .../network/socket/qtcpsocket/tst_qtcpsocket.cpp | 39 ++++++++++++++++------ 1 file changed, 29 insertions(+), 10 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp b/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp index 2d64714f92..10b09629bc 100644 --- a/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp +++ b/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp @@ -164,9 +164,8 @@ private slots: void waitForReadyReadInASlot(); void remoteCloseError(); void nestedEventLoopInErrorSlot(); -#ifndef Q_OS_WIN - void connectToLocalHostNoService(); -#endif + void connectToHostError_data(); + void connectToHostError(); void waitForConnectedInHostLookupSlot(); void waitForConnectedInHostLookupSlot2(); void readyReadSignalsAfterWaitForReadyRead(); @@ -2040,18 +2039,38 @@ void tst_QTcpSocket::nestedEventLoopInErrorSlot() } //---------------------------------------------------------------------------------- -#ifndef Q_OS_WIN -void tst_QTcpSocket::connectToLocalHostNoService() + +void tst_QTcpSocket::connectToHostError_data() +{ + QTest::addColumn("host"); + QTest::addColumn("port"); + QTest::addColumn("expectedError"); + + QTest::newRow("localhost no service") << QStringLiteral("localhost") << 31415 << QAbstractSocket::ConnectionRefusedError; + QTest::newRow("unreachable") << QStringLiteral("0.0.0.1") << 65000 << QAbstractSocket::NetworkError; +} + + +void tst_QTcpSocket::connectToHostError() { - // This test was created after we received a report that claimed - // QTcpSocket would crash if trying to connect to "localhost" on a random - // port with no service listening. QTcpSocket *socket = newSocket(); - socket->connectToHost("localhost", 31415); // no service running here, one suspects + + QAbstractSocket::SocketError error = QAbstractSocket::UnknownSocketError; + + QFETCH(QString, host); + QFETCH(int, port); + QFETCH(QAbstractSocket::SocketError, expectedError); + + connect(socket, QOverload::of(&QAbstractSocket::error),[&](QAbstractSocket::SocketError socketError){ + error = socketError; + }); + socket->connectToHost(host, port); // no service running here, one suspects QTRY_COMPARE(socket->state(), QTcpSocket::UnconnectedState); + if (error != expectedError && error == QAbstractSocket::ConnectionRefusedError) + QEXPECT_FAIL("unreachable", "CI firewall interfers with this test", Continue); + QCOMPARE(error, expectedError); delete socket; } -#endif //---------------------------------------------------------------------------------- void tst_QTcpSocket::waitForConnectedInHostLookupSlot() -- cgit v1.2.3