From 274e973dbe696f89d56d5a78d73208e27c638a77 Mon Sep 17 00:00:00 2001 From: Alex Trotsenko Date: Tue, 31 Mar 2020 16:43:54 +0300 Subject: [PATCH 1/7] Fix flakiness in tst_QApplication::testDeleteLater DeleteLaterWidget is a main application window of the test. So, its show() function should be called explicitly before starting the main event loop. Otherwise, it remains hidden for the whole time, which causes an incorrect emission of QApplication::lastWindowClosed signal when a dialog window is closed in the middle of the test. Also, fix synchronization between deferred deletion and timer event. Change-Id: Id3ce5adbcd9e5e22508825c52025eeea70202354 Reviewed-by: Thiago Macieira --- .../auto/widgets/kernel/qapplication/tst_qapplication.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp b/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp index 3debfd4231..28bf851d37 100644 --- a/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp +++ b/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp @@ -1229,6 +1229,11 @@ void DeleteLaterWidget::runTest() QCoreApplication::processEvents(); + // At this point, the event queue is empty. As we want a deferred + // deletion to occur before the timer event, we should provoke the + // event dispatcher for the next spin. + QCoreApplication::eventDispatcher()->interrupt(); + QVERIFY(!stillAlive); // verify at the end to make test terminate } @@ -1258,8 +1263,10 @@ void tst_QApplication::testDeleteLater() QObject *stillAlive = wgt->findChild("deleteLater"); QVERIFY(stillAlive); + wgt->show(); QCoreApplication::exec(); + QVERIFY(wgt->isHidden()); delete wgt; } From 9834536cfaa903048c8ae510387606cd055658e6 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 2 Apr 2020 12:02:55 -0300 Subject: [PATCH 2/7] QLibrary/Android: Correct improper merging I had originally developed ae6f73e8566fa76470937aca737141183929a5ec in 5.13, where this code for Android didn't exist. I didn't notice the use of pHnd there when I merged up for the push. Change-Id: Ibdc95e9af7bd456a94ecfffd160208dfaa596d95 Reviewed-by: BogDan Vatra --- src/corelib/plugin/qlibrary_unix.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/corelib/plugin/qlibrary_unix.cpp b/src/corelib/plugin/qlibrary_unix.cpp index 29813e5863..017aa97b66 100644 --- a/src/corelib/plugin/qlibrary_unix.cpp +++ b/src/corelib/plugin/qlibrary_unix.cpp @@ -235,15 +235,15 @@ bool QLibraryPrivate::load_sys() hnd = dlopen(QFile::encodeName(attempt), dlFlags); #ifdef Q_OS_ANDROID - if (!pHnd) { + if (!hnd) { auto attemptFromBundle = attempt; - pHnd = dlopen(QFile::encodeName(attemptFromBundle.replace(QLatin1Char('/'), QLatin1Char('_'))), dlFlags); + hnd = dlopen(QFile::encodeName(attemptFromBundle.replace(QLatin1Char('/'), QLatin1Char('_'))), dlFlags); } - if (pHnd) { + if (hnd) { using JniOnLoadPtr = jint (*)(JavaVM *vm, void *reserved); JniOnLoadPtr jniOnLoad = reinterpret_cast(dlsym(pHnd, "JNI_OnLoad")); if (jniOnLoad && jniOnLoad(QtAndroidPrivate::javaVM(), nullptr) == JNI_ERR) { - dlclose(pHnd); + dlclose(hnd); pHnd = nullptr; } } From e0d80167c18b5a71acf4dac59f3e6f37292fa397 Mon Sep 17 00:00:00 2001 From: Alex Trotsenko Date: Wed, 18 Mar 2020 20:04:47 +0200 Subject: [PATCH 3/7] QEventDispatcherWin32: fix posted events delivering To avoid livelocks, posted events should be delivered when all pending messages have been processed, and the thread's message queue becomes empty. Although the logic of the previous patch is correct, it turned out that determining the moment when the message queue is really empty is not so simple. It is worth noting that the GetQueueStatus function sometimes reports unexpected results due to internal filtering and processing. Indeed, Windows docs say that "the return value from GetQueueStatus should be considered only a hint as to whether GetMessage or PeekMessage should be called". Thus, we cannot rely on GetQueueStatus in unambiguous logic inside the qt_GetMessageHook. To solve the problem, this patch introduces a guard timer which guarantees low priority processing for posted events in foreign loop. The wakeUps flag reset logic has also been changed to provide clearer synchronization of the Qt internal loop. Fixes: QTBUG-82701 Fixes: QTBUG-83151 Change-Id: I33d5001a40d2a4879ef4eb878c09bc1c0616e289 Reviewed-by: Volker Hilsheimer --- src/corelib/kernel/qeventdispatcher_win.cpp | 80 ++++++++++++--------- src/corelib/kernel/qeventdispatcher_win_p.h | 1 + 2 files changed, 49 insertions(+), 32 deletions(-) diff --git a/src/corelib/kernel/qeventdispatcher_win.cpp b/src/corelib/kernel/qeventdispatcher_win.cpp index 87623f304a..56b60e67e0 100644 --- a/src/corelib/kernel/qeventdispatcher_win.cpp +++ b/src/corelib/kernel/qeventdispatcher_win.cpp @@ -84,10 +84,8 @@ enum { WM_QT_ACTIVATENOTIFIERS = WM_USER + 2 }; -// WM_QT_SENDPOSTEDEVENTS message parameter enum { - WMWP_QT_TOFOREIGNLOOP = 0, - WMWP_QT_FROMWAKEUP + SendPostedEventsTimerId = ~1u }; class QEventDispatcherWin32Private; @@ -100,8 +98,8 @@ LRESULT QT_WIN_CALLBACK qt_internal_proc(HWND hwnd, UINT message, WPARAM wp, LPA QEventDispatcherWin32Private::QEventDispatcherWin32Private() : threadId(GetCurrentThreadId()), interrupt(false), internalHwnd(0), - getMessageHook(0), wakeUps(0), activateNotifiersPosted(false), - winEventNotifierActivatedEvent(NULL) + getMessageHook(0), sendPostedEventsTimerId(0), wakeUps(0), + activateNotifiersPosted(false), winEventNotifierActivatedEvent(NULL) { } @@ -129,6 +127,18 @@ void WINAPI QT_WIN_CALLBACK qt_fast_timer_proc(uint timerId, uint /*reserved*/, QCoreApplication::postEvent(t->dispatcher, new QTimerEvent(t->timerId)); } +static inline UINT inputQueueMask() +{ + UINT result = QS_ALLEVENTS; + // QTBUG 28513, QTBUG-29097, QTBUG-29435: QS_TOUCH, QS_POINTER became part of + // QS_INPUT in Windows Kit 8. They should not be used when running on pre-Windows 8. +#if WINVER > 0x0601 + if (QOperatingSystemVersion::current() < QOperatingSystemVersion::Windows8) + result &= ~(QS_TOUCH | QS_POINTER); +#endif // WINVER > 0x0601 + return result; +} + LRESULT QT_WIN_CALLBACK qt_internal_proc(HWND hwnd, UINT message, WPARAM wp, LPARAM lp) { if (message == WM_NCCREATE) @@ -240,47 +250,39 @@ LRESULT QT_WIN_CALLBACK qt_internal_proc(HWND hwnd, UINT message, WPARAM wp, LPA case WM_TIMER: Q_ASSERT(d != 0); - d->sendTimerEvent(wp); + if (wp == d->sendPostedEventsTimerId) + q->sendPostedEvents(); + else + d->sendTimerEvent(wp); return 0; case WM_QT_SENDPOSTEDEVENTS: Q_ASSERT(d != 0); // We send posted events manually, if the window procedure was invoked // by the foreign event loop (e.g. from the native modal dialog). - q->sendPostedEvents(); + // Skip sending, if the message queue is not empty. + // sendPostedEventsTimer will deliver posted events later. + static const UINT mask = inputQueueMask(); + if (HIWORD(GetQueueStatus(mask)) == 0) + q->sendPostedEvents(); return 0; } // switch (message) return DefWindowProc(hwnd, message, wp, lp); } -static inline UINT inputQueueMask() -{ - UINT result = QS_ALLEVENTS; - // QTBUG 28513, QTBUG-29097, QTBUG-29435: QS_TOUCH, QS_POINTER became part of - // QS_INPUT in Windows Kit 8. They should not be used when running on pre-Windows 8. -#if WINVER > 0x0601 - if (QOperatingSystemVersion::current() < QOperatingSystemVersion::Windows8) - result &= ~(QS_TOUCH | QS_POINTER); -#endif // WINVER > 0x0601 - return result; -} - LRESULT QT_WIN_CALLBACK qt_GetMessageHook(int code, WPARAM wp, LPARAM lp) { QEventDispatcherWin32 *q = qobject_cast(QAbstractEventDispatcher::instance()); Q_ASSERT(q != 0); QEventDispatcherWin32Private *d = q->d_func(); MSG *msg = reinterpret_cast(lp); - static const UINT mask = inputQueueMask(); - if (HIWORD(GetQueueStatus(mask)) == 0 && wp == PM_REMOVE) { - // Allow posting WM_QT_SENDPOSTEDEVENTS message. - d->wakeUps.storeRelaxed(0); - if (!(msg->hwnd == d->internalHwnd && msg->message == WM_QT_SENDPOSTEDEVENTS)) { - PostMessage(d->internalHwnd, WM_QT_SENDPOSTEDEVENTS, - WMWP_QT_TOFOREIGNLOOP, 0); - } + if (msg->hwnd == d->internalHwnd && msg->message == WM_QT_SENDPOSTEDEVENTS + && wp == PM_REMOVE && d->sendPostedEventsTimerId == 0) { + // Start a timer to deliver posted events when the message queue is emptied. + d->sendPostedEventsTimerId = SetTimer(d->internalHwnd, SendPostedEventsTimerId, + USER_TIMER_MINIMUM, NULL); } return d->getMessageHook ? CallNextHookEx(0, code, wp, lp) : 0; } @@ -571,12 +573,15 @@ bool QEventDispatcherWin32::processEvents(QEventLoop::ProcessEventsFlags flags) } if (haveMessage) { if (d->internalHwnd == msg.hwnd && msg.message == WM_QT_SENDPOSTEDEVENTS) { - // Set result to 'true', if the message was sent by wakeUp(). - if (msg.wParam == WMWP_QT_FROMWAKEUP) - retVal = true; + // Set result to 'true' because the message was sent by wakeUp(). + retVal = true; continue; } if (msg.message == WM_TIMER) { + // Skip timer event intended for use inside foreign loop. + if (d->internalHwnd == msg.hwnd && msg.wParam == d->sendPostedEventsTimerId) + continue; + // avoid live-lock by keeping track of the timers we've already sent bool found = false; for (int i = 0; !found && i < processedTimers.count(); ++i) { @@ -964,8 +969,7 @@ void QEventDispatcherWin32::wakeUp() Q_D(QEventDispatcherWin32); if (d->internalHwnd && d->wakeUps.testAndSetAcquire(0, 1)) { // post a WM_QT_SENDPOSTEDEVENTS to this thread if there isn't one already pending - if (!PostMessage(d->internalHwnd, WM_QT_SENDPOSTEDEVENTS, - WMWP_QT_FROMWAKEUP, 0)) + if (!PostMessage(d->internalHwnd, WM_QT_SENDPOSTEDEVENTS, 0, 0)) qErrnoWarning("QEventDispatcherWin32::wakeUp: Failed to post a message"); } } @@ -1007,6 +1011,10 @@ void QEventDispatcherWin32::closingDown() if (d->getMessageHook) UnhookWindowsHookEx(d->getMessageHook); d->getMessageHook = 0; + + if (d->sendPostedEventsTimerId != 0) + KillTimer(d->internalHwnd, d->sendPostedEventsTimerId); + d->sendPostedEventsTimerId = 0; } bool QEventDispatcherWin32::event(QEvent *e) @@ -1048,6 +1056,14 @@ bool QEventDispatcherWin32::event(QEvent *e) void QEventDispatcherWin32::sendPostedEvents() { Q_D(QEventDispatcherWin32); + + if (d->sendPostedEventsTimerId != 0) + KillTimer(d->internalHwnd, d->sendPostedEventsTimerId); + d->sendPostedEventsTimerId = 0; + + // Allow posting WM_QT_SENDPOSTEDEVENTS message. + d->wakeUps.storeRelaxed(0); + QCoreApplicationPrivate::sendPostedEvents(0, 0, d->threadData); } diff --git a/src/corelib/kernel/qeventdispatcher_win_p.h b/src/corelib/kernel/qeventdispatcher_win_p.h index e6620178d8..8f6f05e0a7 100644 --- a/src/corelib/kernel/qeventdispatcher_win_p.h +++ b/src/corelib/kernel/qeventdispatcher_win_p.h @@ -170,6 +170,7 @@ public: HHOOK getMessageHook; // for controlling when to send posted events + UINT_PTR sendPostedEventsTimerId; QAtomicInt wakeUps; // timers From 3f783bfad93b77583de915dc35bc40b0500b9275 Mon Sep 17 00:00:00 2001 From: Topi Reinio Date: Wed, 1 Apr 2020 10:39:26 +0200 Subject: [PATCH 4/7] Doc: Clarify equivalence of two QDate instances Fixes: QTBUG-83212 Change-Id: I627716522a962a4c90c5833446dd62f6a18d7d86 Reviewed-by: Edward Welbourne --- src/corelib/time/qdatetime.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/corelib/time/qdatetime.cpp b/src/corelib/time/qdatetime.cpp index a5761055ed..3a564d1b9a 100644 --- a/src/corelib/time/qdatetime.cpp +++ b/src/corelib/time/qdatetime.cpp @@ -277,10 +277,11 @@ static int fromOffsetString(QStringView offsetString, bool *valid) noexcept \reentrant \brief The QDate class provides date functions. - - A QDate object represents a particular date. This can be expressed as a - calendar date, i.e. year, month, and day numbers, in the proleptic Gregorian - calendar. + A QDate object represents a particular day, regardless of calendar, + locale or other settings used when creating it or supplied by the system. + It can report the year, month and day of the month that represent the + day with respect to the proleptic Gregorian calendar or any calendar supplied + as a QCalendar object. A QDate object is typically created by giving the year, month, and day numbers explicitly. Note that QDate interprets year numbers less than 100 as @@ -1572,9 +1573,8 @@ qint64 QDate::daysTo(const QDate &d) const /*! \fn bool QDate::operator==(const QDate &d) const - Returns \c true if this date is equal to \a d; otherwise returns - false. - + Returns \c true if this date and \a d represent the same day, otherwise + \c false. */ /*! @@ -1582,6 +1582,8 @@ qint64 QDate::daysTo(const QDate &d) const Returns \c true if this date is different from \a d; otherwise returns \c false. + + \sa operator==() */ /*! From ff36ed8c41b203ec11e23c6f7b7d8e4b048ca737 Mon Sep 17 00:00:00 2001 From: Leena Miettinen Date: Tue, 31 Mar 2020 17:09:31 +0200 Subject: [PATCH 5/7] Doc: Fix QLineF::IntersectionType enum name Fixes: QTBUG-82727 Change-Id: Iaffa3b0f61debf27a9fe55775362a3f016612217 Reviewed-by: Christian Ehrlicher --- src/corelib/tools/qline.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/corelib/tools/qline.cpp b/src/corelib/tools/qline.cpp index dde66ed093..3afd23d76b 100644 --- a/src/corelib/tools/qline.cpp +++ b/src/corelib/tools/qline.cpp @@ -374,7 +374,7 @@ QDataStream &operator>>(QDataStream &stream, QLine &line) */ /*! - \enum QLineF::IntersectType + \enum QLineF::IntersectionType Describes the intersection between two lines. From 8ed14a3c481c3fc59f10cd084ea203cb45e89309 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Wed, 1 Apr 2020 17:51:59 +0200 Subject: [PATCH 6/7] Stabilize QScroller test Show and activate the widget, otherwise we can't rely on geometry and gesture event delivery. Use QTRY_ macros in a few more places. As a drive-by, fix coding style. Change-Id: If3a13732ae6b07a137fec89e78b7e6b39e066bed Fixes: QTBUG-82947 Reviewed-by: Shawn Rutledge --- .../widgets/util/qscroller/tst_qscroller.cpp | 149 +++++++++--------- 1 file changed, 78 insertions(+), 71 deletions(-) diff --git a/tests/auto/widgets/util/qscroller/tst_qscroller.cpp b/tests/auto/widgets/util/qscroller/tst_qscroller.cpp index 8bdd4b4783..5e71c1888d 100644 --- a/tests/auto/widgets/util/qscroller/tst_qscroller.cpp +++ b/tests/auto/widgets/util/qscroller/tst_qscroller.cpp @@ -82,8 +82,8 @@ public: currentPos = se->contentPos(); overshoot = se->overshootDistance(); - if (!qFuzzyCompare( overshoot.x() + 1.0, 1.0 ) || - !qFuzzyCompare( overshoot.y() + 1.0, 1.0 )) + if (!qFuzzyCompare(overshoot.x() + 1.0, 1.0) || + !qFuzzyCompare(overshoot.y() + 1.0, 1.0)) receivedOvershoot = true; return true; } @@ -116,8 +116,8 @@ public: ~tst_QScroller() { } private: - void kineticScroll( tst_QScrollerWidget *sw, QPointF from, QPoint touchStart, QPoint touchUpdate, QPoint touchEnd); - void kineticScrollNoTest( tst_QScrollerWidget *sw, QPointF from, QPoint touchStart, QPoint touchUpdate, QPoint touchEnd); + void kineticScroll(tst_QScrollerWidget *sw, QPointF from, QPoint touchStart, QPoint touchUpdate, QPoint touchEnd); + void kineticScrollNoTest(tst_QScrollerWidget *sw, QPointF from, QPoint touchStart, QPoint touchUpdate, QPoint touchEnd); private slots: void staticScrollers(); @@ -135,13 +135,13 @@ private: Generates touchBegin, touchUpdate and touchEnd events to trigger scrolling. Tests some in between states but does not wait until scrolling is finished. */ -void tst_QScroller::kineticScroll( tst_QScrollerWidget *sw, QPointF from, QPoint touchStart, QPoint touchUpdate, QPoint touchEnd) +void tst_QScroller::kineticScroll(tst_QScrollerWidget *sw, QPointF from, QPoint touchStart, QPoint touchUpdate, QPoint touchEnd) { sw->scrollPosition = from; sw->currentPos= from; QScroller *s1 = QScroller::scroller(sw); - QCOMPARE( s1->state(), QScroller::Inactive ); + QCOMPARE(s1->state(), QScroller::Inactive); QScrollerProperties sp1 = QScroller::scroller(sw)->scrollerProperties(); @@ -161,7 +161,7 @@ void tst_QScroller::kineticScroll( tst_QScrollerWidget *sw, QPointF from, QPoint (QList() << touchPoint)); QApplication::sendEvent(sw, &touchEvent1); - QCOMPARE( s1->state(), QScroller::Pressed ); + QCOMPARE(s1->state(), QScroller::Pressed); // send the touch update far enough to trigger a scroll QTest::qWait(200); // we need to wait a little or else the speed would be infinite. now we have around 500 pixel per second. @@ -175,13 +175,13 @@ void tst_QScroller::kineticScroll( tst_QScrollerWidget *sw, QPointF from, QPoint (QList() << touchPoint)); QApplication::sendEvent(sw, &touchEvent2); - QCOMPARE( s1->state(), QScroller::Dragging ); - QCOMPARE( sw->receivedPrepare, true ); + QCOMPARE(s1->state(), QScroller::Dragging); + QCOMPARE(sw->receivedPrepare, true); - QTRY_COMPARE( sw->receivedFirst, true ); - QCOMPARE( sw->receivedScroll, true ); - QCOMPARE( sw->receivedOvershoot, false ); + QTRY_COMPARE(sw->receivedFirst, true); + QCOMPARE(sw->receivedScroll, true); + QCOMPARE(sw->receivedOvershoot, false); // note that the scrolling goes in a different direction than the mouse move QPoint calculatedPos = from.toPoint() - touchUpdate - touchStart; @@ -204,13 +204,13 @@ void tst_QScroller::kineticScroll( tst_QScrollerWidget *sw, QPointF from, QPoint Generates touchBegin, touchUpdate and touchEnd events to trigger scrolling. This function does not have any in between tests, it does not expect the scroller to actually scroll. */ -void tst_QScroller::kineticScrollNoTest( tst_QScrollerWidget *sw, QPointF from, QPoint touchStart, QPoint touchUpdate, QPoint touchEnd) +void tst_QScroller::kineticScrollNoTest(tst_QScrollerWidget *sw, QPointF from, QPoint touchStart, QPoint touchUpdate, QPoint touchEnd) { sw->scrollPosition = from; sw->currentPos = from; QScroller *s1 = QScroller::scroller(sw); - QCOMPARE( s1->state(), QScroller::Inactive ); + QCOMPARE(s1->state(), QScroller::Inactive); QScrollerProperties sp1 = s1->scrollerProperties(); int fps = 60; @@ -348,52 +348,57 @@ void tst_QScroller::scrollerProperties() void tst_QScroller::scrollTo() { - { - tst_QScrollerWidget *sw = new tst_QScrollerWidget(); - sw->scrollArea = QRectF( 0, 0, 1000, 1000 ); - sw->scrollPosition = QPointF( 500, 500 ); + QScopedPointer sw(new tst_QScrollerWidget); + sw->show(); + QApplication::setActiveWindow(sw.data()); + if (!QTest::qWaitForWindowExposed(sw.data()) || !QTest::qWaitForWindowActive(sw.data())) + QSKIP("Failed to show and activate window"); - QScroller *s1 = QScroller::scroller(sw); - QCOMPARE( s1->state(), QScroller::Inactive ); + sw->scrollArea = QRectF(0, 0, 1000, 1000); + sw->scrollPosition = QPointF(500, 500); - // a normal scroll - s1->scrollTo(QPointF(100,100), 100); - QTest::qWait(200); + QScroller *s1 = QScroller::scroller(sw.data()); + QCOMPARE(s1->state(), QScroller::Inactive); - QCOMPARE( sw->receivedPrepare, true ); - QCOMPARE( sw->receivedScroll, true ); - QCOMPARE( sw->receivedFirst, true ); - QCOMPARE( sw->receivedLast, true ); - QCOMPARE( sw->receivedOvershoot, false ); - QVERIFY(qFuzzyCompare( sw->currentPos.x(), 100 )); - QVERIFY(qFuzzyCompare( sw->currentPos.y(), 100 )); + // a normal scroll + s1->scrollTo(QPointF(100,100), 100); + QTest::qWait(200); - delete sw; - } + QTRY_COMPARE(sw->receivedPrepare, true); + QCOMPARE(sw->receivedScroll, true); + QCOMPARE(sw->receivedFirst, true); + QCOMPARE(sw->receivedLast, true); + QCOMPARE(sw->receivedOvershoot, false); + QTRY_VERIFY(qFuzzyCompare(sw->currentPos.x(), 100)); + QVERIFY(qFuzzyCompare(sw->currentPos.y(), 100)); } void tst_QScroller::scroll() { #if QT_CONFIG(gestures) && QT_CONFIG(scroller) // -- good case. normal scroll - tst_QScrollerWidget *sw = new tst_QScrollerWidget(); + QScopedPointer sw(new tst_QScrollerWidget()); sw->scrollArea = QRectF(0, 0, 1000, 1000); - QScroller::grabGesture(sw, QScroller::TouchGesture); + QScroller::grabGesture(sw.data(), QScroller::TouchGesture); sw->setGeometry(100, 100, 400, 300); + sw->show(); + QApplication::setActiveWindow(sw.data()); + if (!QTest::qWaitForWindowExposed(sw.data()) || !QTest::qWaitForWindowActive(sw.data())) + QSKIP("Failed to show and activate window"); - QScroller *s1 = QScroller::scroller(sw); - kineticScroll(sw, QPointF(500, 500), QPoint(0, 0), QPoint(100, 100), QPoint(200, 200)); + QScroller *s1 = QScroller::scroller(sw.data()); + kineticScroll(sw.data(), QPointF(500, 500), QPoint(0, 0), QPoint(100, 100), QPoint(200, 200)); // now we should be scrolling - QTRY_COMPARE( s1->state(), QScroller::Scrolling ); + QTRY_COMPARE(s1->state(), QScroller::Scrolling); // wait until finished, check that no further first scroll is sent sw->receivedFirst = false; sw->receivedScroll = false; QTRY_VERIFY(s1->state() != QScroller::Scrolling); - QCOMPARE( sw->receivedFirst, false ); - QCOMPARE( sw->receivedScroll, true ); - QCOMPARE( sw->receivedLast, true ); + QCOMPARE(sw->receivedFirst, false); + QCOMPARE(sw->receivedScroll, true); + QCOMPARE(sw->receivedLast, true); QVERIFY(sw->currentPos.x() < 400); QVERIFY(sw->currentPos.y() < 400); @@ -401,26 +406,28 @@ void tst_QScroller::scroll() sw->reset(); sw->scrollArea = QRectF(0, 0, 0, 1000); - kineticScrollNoTest(sw, QPointF(0, 500), QPoint(0, 0), QPoint(100, 0), QPoint(200, 0)); + kineticScrollNoTest(sw.data(), QPointF(0, 500), QPoint(0, 0), QPoint(100, 0), QPoint(200, 0)); QTRY_COMPARE(s1->state(), QScroller::Inactive); QCOMPARE(sw->currentPos.x(), 0.0); QCOMPARE(sw->currentPos.y(), 500.0); - - delete sw; #endif } void tst_QScroller::overshoot() { #if QT_CONFIG(gestures) && QT_CONFIG(scroller) - tst_QScrollerWidget *sw = new tst_QScrollerWidget(); + QScopedPointer sw(new tst_QScrollerWidget); sw->scrollArea = QRectF(0, 0, 1000, 1000); - QScroller::grabGesture(sw, QScroller::TouchGesture); + QScroller::grabGesture(sw.data(), QScroller::TouchGesture); sw->setGeometry(100, 100, 400, 300); + sw->show(); + QApplication::setActiveWindow(sw.data()); + if (!QTest::qWaitForWindowExposed(sw.data()) || !QTest::qWaitForWindowActive(sw.data())) + QSKIP("Failed to show and activate window"); - QScroller *s1 = QScroller::scroller(sw); + QScroller *s1 = QScroller::scroller(sw.data()); QScrollerProperties sp1 = s1->scrollerProperties(); sp1.setScrollMetric(QScrollerProperties::OvershootDragResistanceFactor, 0.5); @@ -431,14 +438,14 @@ void tst_QScroller::overshoot() sp1.setScrollMetric(QScrollerProperties::HorizontalOvershootPolicy, QVariant::fromValue(QScrollerProperties::OvershootWhenScrollable)); s1->setScrollerProperties(sp1); - kineticScrollNoTest(sw, QPointF(500, 500), QPoint(0, 0), QPoint(400, 0), QPoint(490, 0)); + kineticScrollNoTest(sw.data(), QPointF(500, 500), QPoint(0, 0), QPoint(400, 0), QPoint(490, 0)); QTRY_COMPARE(s1->state(), QScroller::Inactive); //qDebug() << "Overshoot fuzzy: "<currentPos; - QVERIFY(qFuzzyCompare( sw->currentPos.x(), 0 )); - QVERIFY(qFuzzyCompare( sw->currentPos.y(), 500 )); - QCOMPARE( sw->receivedOvershoot, true ); + QVERIFY(qFuzzyCompare(sw->currentPos.x(), 0)); + QVERIFY(qFuzzyCompare(sw->currentPos.y(), 500)); + QCOMPARE(sw->receivedOvershoot, true); // -- try to scroll with overshoot (when scrollable bad case) sw->reset(); @@ -446,14 +453,14 @@ void tst_QScroller::overshoot() sp1.setScrollMetric(QScrollerProperties::HorizontalOvershootPolicy, QVariant::fromValue(QScrollerProperties::OvershootWhenScrollable)); s1->setScrollerProperties(sp1); - kineticScrollNoTest(sw, QPointF(0, 500), QPoint(0, 0), QPoint(400, 0), QPoint(490, 0)); + kineticScrollNoTest(sw.data(), QPointF(0, 500), QPoint(0, 0), QPoint(400, 0), QPoint(490, 0)); QTRY_COMPARE(s1->state(), QScroller::Inactive); //qDebug() << "Overshoot fuzzy: "<currentPos; - QVERIFY(qFuzzyCompare( sw->currentPos.x(), 0 )); - QVERIFY(qFuzzyCompare( sw->currentPos.y(), 500 )); - QCOMPARE( sw->receivedOvershoot, false ); + QVERIFY(qFuzzyCompare(sw->currentPos.x(), 0)); + QVERIFY(qFuzzyCompare(sw->currentPos.y(), 500)); + QCOMPARE(sw->receivedOvershoot, false); // -- try to scroll with overshoot (always on) sw->reset(); @@ -461,15 +468,15 @@ void tst_QScroller::overshoot() sp1.setScrollMetric(QScrollerProperties::HorizontalOvershootPolicy, QVariant::fromValue(QScrollerProperties::OvershootAlwaysOn)); s1->setScrollerProperties(sp1); - kineticScrollNoTest(sw, QPointF(0, 500), QPoint(0, 0), QPoint(400, 0), QPoint(490, 0)); + kineticScrollNoTest(sw.data(), QPointF(0, 500), QPoint(0, 0), QPoint(400, 0), QPoint(490, 0)); QTRY_COMPARE(s1->state(), QScroller::Inactive); //qDebug() << "Overshoot fuzzy: "<currentPos; - QVERIFY(qFuzzyCompare( sw->currentPos.x(), 0 )); - QVERIFY(qFuzzyCompare( sw->currentPos.y(), 500 )); - QCOMPARE( sw->receivedOvershoot, true ); + QVERIFY(qFuzzyCompare(sw->currentPos.x(), 0)); + QVERIFY(qFuzzyCompare(sw->currentPos.y(), 500)); + QCOMPARE(sw->receivedOvershoot, true); // -- try to scroll with overshoot (always off) sw->reset(); @@ -477,13 +484,13 @@ void tst_QScroller::overshoot() sp1.setScrollMetric(QScrollerProperties::HorizontalOvershootPolicy, QVariant::fromValue(QScrollerProperties::OvershootAlwaysOff)); s1->setScrollerProperties(sp1); - kineticScrollNoTest(sw, QPointF(500, 500), QPoint(0, 0), QPoint(400, 0), QPoint(490, 0)); + kineticScrollNoTest(sw.data(), QPointF(500, 500), QPoint(0, 0), QPoint(400, 0), QPoint(490, 0)); QTRY_COMPARE(s1->state(), QScroller::Inactive); - QVERIFY(qFuzzyCompare( sw->currentPos.x(), 0 )); - QVERIFY(qFuzzyCompare( sw->currentPos.y(), 500 )); - QCOMPARE( sw->receivedOvershoot, false ); + QVERIFY(qFuzzyCompare(sw->currentPos.x(), 0)); + QVERIFY(qFuzzyCompare(sw->currentPos.y(), 500)); + QCOMPARE(sw->receivedOvershoot, false); // -- try to scroll with overshoot (always on but max overshoot = 0) sp1.setScrollMetric(QScrollerProperties::OvershootDragDistanceFactor, 0.0); @@ -493,39 +500,39 @@ void tst_QScroller::overshoot() sp1.setScrollMetric(QScrollerProperties::HorizontalOvershootPolicy, QVariant::fromValue(QScrollerProperties::OvershootAlwaysOn)); s1->setScrollerProperties(sp1); - kineticScrollNoTest(sw, QPointF(500, 500), QPoint(0, 0), QPoint(400, 0), QPoint(490, 0)); + kineticScrollNoTest(sw.data(), QPointF(500, 500), QPoint(0, 0), QPoint(400, 0), QPoint(490, 0)); QTRY_COMPARE(s1->state(), QScroller::Inactive); - QVERIFY(qFuzzyCompare( sw->currentPos.x(), 0 )); - QVERIFY(qFuzzyCompare( sw->currentPos.y(), 500 )); - QCOMPARE( sw->receivedOvershoot, false ); - - delete sw; + QVERIFY(qFuzzyCompare(sw->currentPos.x(), 0)); + QVERIFY(qFuzzyCompare(sw->currentPos.y(), 500)); + QCOMPARE(sw->receivedOvershoot, false); #endif } void tst_QScroller::multipleWindows() { #if QT_CONFIG(gestures) && QT_CONFIG(scroller) - QScopedPointer sw1(new tst_QScrollerWidget()); + QScopedPointer sw1(new tst_QScrollerWidget); sw1->scrollArea = QRectF(0, 0, 1000, 1000); QScroller::grabGesture(sw1.data(), QScroller::TouchGesture); sw1->setGeometry(100, 100, 400, 300); + QScroller *s1 = QScroller::scroller(sw1.data()); kineticScroll(sw1.data(), QPointF(500, 500), QPoint(0, 0), QPoint(100, 100), QPoint(200, 200)); // now we should be scrolling - QTRY_COMPARE( s1->state(), QScroller::Scrolling ); + QTRY_COMPARE(s1->state(), QScroller::Scrolling); // That was fun! Do it again! QScopedPointer sw2(new tst_QScrollerWidget()); sw2->scrollArea = QRectF(0, 0, 1000, 1000); QScroller::grabGesture(sw2.data(), QScroller::TouchGesture); sw2->setGeometry(100, 100, 400, 300); + QScroller *s2 = QScroller::scroller(sw2.data()); kineticScroll(sw2.data(), QPointF(500, 500), QPoint(0, 0), QPoint(100, 100), QPoint(200, 200)); // now we should be scrolling - QTRY_COMPARE( s2->state(), QScroller::Scrolling ); + QTRY_COMPARE(s2->state(), QScroller::Scrolling); // wait for both to stop QTRY_VERIFY(s1->state() != QScroller::Scrolling); From 4ee7adf59d13ada5bfaa4f0382e0bb70b66b8814 Mon Sep 17 00:00:00 2001 From: Sona Kurazyan Date: Tue, 10 Mar 2020 11:47:12 +0100 Subject: [PATCH 7/7] Try to stabilize flaky test cases of tst_qsequentialanimationgroup Use QTRY_COMPARE in the flaky tests instead of waiting. Change-Id: Ic18fc5fde3fa47f3b3ef21e6acd876bd6990981d Reviewed-by: Friedemann Kleint (cherry picked from commit 0ae6803d3956cf59801bbcc52143b95de9fc96d1) --- .../tst_qsequentialanimationgroup.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/auto/corelib/animation/qsequentialanimationgroup/tst_qsequentialanimationgroup.cpp b/tests/auto/corelib/animation/qsequentialanimationgroup/tst_qsequentialanimationgroup.cpp index 06e9fe7a66..d6607dc813 100644 --- a/tests/auto/corelib/animation/qsequentialanimationgroup/tst_qsequentialanimationgroup.cpp +++ b/tests/auto/corelib/animation/qsequentialanimationgroup/tst_qsequentialanimationgroup.cpp @@ -1295,10 +1295,9 @@ void tst_QSequentialAnimationGroup::startGroupWithRunningChild() QCOMPARE(anim1->state(), QAnimationGroup::Running); QCOMPARE(anim2->state(), QAnimationGroup::Paused); - QTest::qWait(300); - + // Wait until anim1 finishes (anim2 should be still running) + QTRY_COMPARE(anim1->state(), QAnimationGroup::Stopped); QCOMPARE(group.state(), QAnimationGroup::Running); - QCOMPARE(anim1->state(), QAnimationGroup::Stopped); QCOMPARE(anim2->state(), QAnimationGroup::Running); QCOMPARE(stateChangedSpy2.count(), 4); @@ -1615,7 +1614,7 @@ void tst_QSequentialAnimationGroup::clear() group.start(); QTest::qWait(anim1->duration() + 100); QTRY_COMPARE(group.state(), QAbstractAnimation::Running); - QVERIFY(anim1 == 0); //anim1 should have been deleted + QTRY_COMPARE(anim1, nullptr); // anim1 should have been deleted } void tst_QSequentialAnimationGroup::pauseResume()