diff options
author | Axel Spoerl <axel.spoerl@qt.io> | 2022-11-22 12:57:28 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2022-12-01 06:59:15 +0000 |
commit | e5f94b3b1ff01e44b9d53bdd0822b37b9778aa2d (patch) | |
tree | fc376b68fd7120020fbd7ec5c8767f5a1300adb2 | |
parent | 268652173e744acacd6bbcfa57169d13121c0290 (diff) | |
download | qtbase-e5f94b3b1ff01e44b9d53bdd0822b37b9778aa2d.tar.gz |
Handle multiple paint events in tst_QWidgetRepaintManager
The helper function TestWidget::waitForPainted returned after the test
widget had consumed the first paint event. In case of multiple paint
events, QRegion paintedRegions did not match the entire region that
was supposed to be painted. The test function children() failed/flaked
due to that.
This patch extends the helper function. After consumption of the first
paint event, it processes events until the painted regions no longer
change.
Fixes: QTBUG-108764
Change-Id: I54e14bb07725dd1f602cc93085da13836e3b7494
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
(cherry picked from commit f7089e691e2f154f5ce6b50c5fee3d52e693c0ff)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | tests/auto/widgets/kernel/qwidgetrepaintmanager/tst_qwidgetrepaintmanager.cpp | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/tests/auto/widgets/kernel/qwidgetrepaintmanager/tst_qwidgetrepaintmanager.cpp b/tests/auto/widgets/kernel/qwidgetrepaintmanager/tst_qwidgetrepaintmanager.cpp index 5b839cbde5..f53d5aeb05 100644 --- a/tests/auto/widgets/kernel/qwidgetrepaintmanager/tst_qwidgetrepaintmanager.cpp +++ b/tests/auto/widgets/kernel/qwidgetrepaintmanager/tst_qwidgetrepaintmanager.cpp @@ -33,14 +33,33 @@ public: void initialShow() { show(); - if (isWindow()) + if (isWindow()) { QVERIFY(QTest::qWaitForWindowExposed(this)); + QVERIFY(waitForPainted()); + } paintedRegions = {}; } bool waitForPainted(int timeout = 5000) { - return QTest::qWaitFor([this]{ return !paintedRegions.isEmpty(); }, timeout); + int remaining = timeout; + QDeadlineTimer deadline(remaining, Qt::PreciseTimer); + if (!QTest::qWaitFor([this]{ return !paintedRegions.isEmpty(); }, timeout)) + return false; + + // In case of multiple paint events: + // Process events and wait until all have been consumed, + // i.e. paintedRegions no longer changes. + QRegion reg; + while (remaining > 0 && reg != paintedRegions) { + reg = paintedRegions; + QCoreApplication::processEvents(QEventLoop::AllEvents, remaining); + if (reg == paintedRegions) + return true; + + remaining = int(deadline.remainingTime()); + } + return false; } QRegion takePaintedRegions() @@ -353,6 +372,7 @@ void tst_QWidgetRepaintManager::children() TestWidget *child1 = new TestWidget(&widget); child1->move(20, 20); child1->show(); + QVERIFY(QTest::qWaitForWindowExposed(child1)); QVERIFY(child1->waitForPainted()); QCOMPARE(widget.takePaintedRegions(), QRegion(child1->geometry())); QCOMPARE(child1->takePaintedRegions(), QRegion(child1->rect())); |