diff options
Diffstat (limited to 'tests/auto/widgets/kernel/qwidgetrepaintmanager/tst_qwidgetrepaintmanager.cpp')
-rw-r--r-- | tests/auto/widgets/kernel/qwidgetrepaintmanager/tst_qwidgetrepaintmanager.cpp | 65 |
1 files changed, 59 insertions, 6 deletions
diff --git a/tests/auto/widgets/kernel/qwidgetrepaintmanager/tst_qwidgetrepaintmanager.cpp b/tests/auto/widgets/kernel/qwidgetrepaintmanager/tst_qwidgetrepaintmanager.cpp index fb959821bc..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() @@ -51,6 +70,14 @@ public: } QRegion paintedRegions; + bool event(QEvent *event) override + { + const auto type = event->type(); + if (type == QEvent::WindowActivate || type == QEvent::WindowDeactivate) + return true; + return QWidget::event(event); + } + protected: void paintEvent(QPaintEvent *event) override { @@ -71,6 +98,14 @@ public: setAttribute(Qt::WA_OpaquePaintEvent); } + bool event(QEvent *event) override + { + const auto type = event->type(); + if (type == QEvent::WindowActivate || type == QEvent::WindowDeactivate) + return true; + return QWidget::event(event); + } + protected: void paintEvent(QPaintEvent *e) override { @@ -186,6 +221,14 @@ public: QSize sizeHint() const override { return QSize(400, 400); } + bool event(QEvent *event) override + { + const auto type = event->type(); + if (type == QEvent::WindowActivate || type == QEvent::WindowDeactivate) + return true; + return QWidget::event(event); + } + protected: void resizeEvent(QResizeEvent *) override { @@ -226,13 +269,14 @@ protected: */ bool compareWidget(QWidget *w) { + QBackingStore *backingStore = w->window()->backingStore(); + Q_ASSERT(backingStore && backingStore->handle()); + QPlatformBackingStore *platformBackingStore = backingStore->handle(); + if (!waitForFlush(w)) { qWarning() << "Widget" << w << "failed to flush"; return false; } - QBackingStore *backingStore = w->window()->backingStore(); - Q_ASSERT(backingStore && backingStore->handle()); - QPlatformBackingStore *platformBackingStore = backingStore->handle(); QImage backingstoreContent = platformBackingStore->toImage(); if (!w->isWindow()) { @@ -259,7 +303,14 @@ protected: } bool waitForFlush(QWidget *widget) const { + if (!widget) + return true; + auto *repaintManager = QWidgetPrivate::get(widget->window())->maybeRepaintManager(); + + if (!repaintManager) + return true; + return QTest::qWaitFor([repaintManager]{ return !repaintManager->isDirty(); } ); }; #endif // QT_BUILD_INTERNAL @@ -282,7 +333,7 @@ void tst_QWidgetRepaintManager::initTestCase() QVERIFY(QTest::qWaitForWindowExposed(&widget)); m_implementsScroll = widget.backingStore()->handle()->scroll(QRegion(widget.rect()), 1, 1); - qDebug() << QGuiApplication::platformName() << "QPA backend implements scroll:" << m_implementsScroll; + qInfo() << QGuiApplication::platformName() << "QPA backend implements scroll:" << m_implementsScroll; } void tst_QWidgetRepaintManager::cleanup() @@ -321,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())); @@ -594,6 +646,7 @@ void tst_QWidgetRepaintManager::fastMove() QCOMPARE(dirtyRegion(scene.yellowChild), QRect(0, 0, 100, 100)); } QCOMPARE(dirtyRegion(&scene), QRect(0, 0, 25, 100)); + QTRY_VERIFY(dirtyRegion(&scene).isEmpty()); QVERIFY(compareWidget(&scene)); } |