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.

Pick-to: 6.4
Fixes: QTBUG-108764
Change-Id: I54e14bb07725dd1f602cc93085da13836e3b7494
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
bb10
Axel Spoerl 2022-11-22 12:57:28 +01:00
parent 4a6ce541c5
commit f7089e691e
1 changed files with 22 additions and 2 deletions

View File

@ -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()
@ -321,6 +340,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()));