From d9d76d0f56b0e2b0ce09abf39c710a1e666fa09f Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Tue, 13 Oct 2009 13:55:44 +0200 Subject: Fix graphicsview test on Cocoa. Cocoa doesn't support regions update and always update the bounding rect (see comment in QWidgetPrivate::update_sys in qwidget_mac.cpp) Change tests that checked that we get the exact regions. Reviewed-by: MortenS --- tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp | 20 ++++++++++++++------ tests/auto/qgraphicsview/tst_qgraphicsview.cpp | 6 +++++- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp index 49b76ac..0a6f60e 100644 --- a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp @@ -82,6 +82,14 @@ Q_DECLARE_METATYPE(QRectF) #define Q_CHECK_PAINTEVENTS #endif +#if defined(Q_WS_MAC) && defined(QT_MAC_USE_COCOA) +// On mac (cocoa) we always get full update. +// So check that the expected region is contained inside the actual +#define COMPARE_REGIONS(ACTUAL, EXPECTED) QVERIFY((EXPECTED).subtracted(ACTUAL).isEmpty()) +#else +#define COMPARE_REGIONS QTRY_COMPARE +#endif + static void sendMousePress(QGraphicsScene *scene, const QPointF &point, Qt::MouseButton button = Qt::LeftButton) { QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMousePress); @@ -6290,7 +6298,7 @@ void tst_QGraphicsItem::opacityZeroUpdates() QRegion expectedRegion = parentDeviceBoundingRect.adjusted(-2, -2, 2, 2); expectedRegion += childDeviceBoundingRect.adjusted(-2, -2, 2, 2); - QTRY_COMPARE(view.paintedRegion, expectedRegion); + COMPARE_REGIONS(view.paintedRegion, expectedRegion); } class StacksBehindParentHelper : public QGraphicsRectItem @@ -7117,7 +7125,7 @@ void tst_QGraphicsItem::update() qApp->processEvents(); QCOMPARE(item->repaints, 1); QCOMPARE(view.repaints, 1); - QCOMPARE(view.paintedRegion, expectedRegion + expectedRegion.translated(50, 50)); + COMPARE_REGIONS(view.paintedRegion, expectedRegion + expectedRegion.translated(50, 50)); // Make sure moving a parent item triggers an update on the children // (even though the parent itself is outside the viewport). @@ -7392,7 +7400,7 @@ void tst_QGraphicsItem::moveItem() QRegion expectedParentRegion = parentDeviceBoundingRect; // old position parentDeviceBoundingRect.translate(20, 20); expectedParentRegion += parentDeviceBoundingRect; // new position - QCOMPARE(view.paintedRegion, expectedParentRegion); + COMPARE_REGIONS(view.paintedRegion, expectedParentRegion); RESET_COUNTERS @@ -7402,7 +7410,7 @@ void tst_QGraphicsItem::moveItem() QCOMPARE(child->repaints, 1); QCOMPARE(view.repaints, 1); const QRegion expectedChildRegion = expectedParentRegion.translated(20, 20); - QCOMPARE(view.paintedRegion, expectedChildRegion); + COMPARE_REGIONS(view.paintedRegion, expectedChildRegion); RESET_COUNTERS @@ -7413,7 +7421,7 @@ void tst_QGraphicsItem::moveItem() QCOMPARE(grandChild->repaints, 1); QCOMPARE(view.repaints, 1); const QRegion expectedGrandChildRegion = expectedParentRegion.translated(40, 40); - QCOMPARE(view.paintedRegion, expectedGrandChildRegion); + COMPARE_REGIONS(view.paintedRegion, expectedGrandChildRegion); RESET_COUNTERS @@ -7426,7 +7434,7 @@ void tst_QGraphicsItem::moveItem() expectedParentRegion.translate(20, 20); expectedParentRegion += expectedChildRegion.translated(20, 20); expectedParentRegion += expectedGrandChildRegion.translated(20, 20); - QCOMPARE(view.paintedRegion, expectedParentRegion); + COMPARE_REGIONS(view.paintedRegion, expectedParentRegion); } void tst_QGraphicsItem::sorting_data() diff --git a/tests/auto/qgraphicsview/tst_qgraphicsview.cpp b/tests/auto/qgraphicsview/tst_qgraphicsview.cpp index 8acaa72..389200b 100644 --- a/tests/auto/qgraphicsview/tst_qgraphicsview.cpp +++ b/tests/auto/qgraphicsview/tst_qgraphicsview.cpp @@ -2210,9 +2210,11 @@ void tst_QGraphicsView::viewportUpdateMode() // The view gets two updates for the update scene updates. QTRY_VERIFY(!view.lastUpdateRegions.isEmpty()); +#ifndef QT_MAC_USE_COCOA //cocoa doesn't support drawing regions QCOMPARE(view.lastUpdateRegions.last().rects().size(), 2); QCOMPARE(view.lastUpdateRegions.last().rects().at(0).size(), QSize(15, 15)); QCOMPARE(view.lastUpdateRegions.last().rects().at(1).size(), QSize(15, 15)); +#endif // Set full update mode. view.setViewportUpdateMode(QGraphicsView::FullViewportUpdate); @@ -3431,10 +3433,12 @@ void tst_QGraphicsView::exposeRegion() // Make sure it triggers correct repaint on the view. QTRY_COMPARE(view.lastUpdateRegions.size(), 1); - QTRY_COMPARE(view.lastUpdateRegions.at(0), expectedExposeRegion); + COMPARE_REGIONS(view.lastUpdateRegions.at(0), expectedExposeRegion); // Make sure the item didn't get any repaints. +#ifndef QT_MAC_USE_COCOA QCOMPARE(item->paints, 0); +#endif } void tst_QGraphicsView::update_data() -- cgit v0.12