tests/auto/qgraphicseffect/tst_qgraphicseffect.cpp
branchRCL_3
changeset 13 c0432d11811c
parent 7 3f74d0d4af4c
--- a/tests/auto/qgraphicseffect/tst_qgraphicseffect.cpp	Wed Apr 21 12:15:23 2010 +0300
+++ b/tests/auto/qgraphicseffect/tst_qgraphicseffect.cpp	Wed Apr 21 20:15:53 2010 +0300
@@ -75,6 +75,7 @@
     void inheritOpacity();
     void dropShadowClipping();
     void childrenVisibilityShouldInvalidateCache();
+    void prepareGeometryChangeInvalidateCache();
 };
 
 void tst_QGraphicsEffect::initTestCase()
@@ -277,9 +278,8 @@
     // Make sure installing the effect triggers a repaint.
     CustomEffect *effect = new CustomEffect;
     item->setGraphicsEffect(effect);
-    QTest::qWait(50);
-    QCOMPARE(effect->numRepaints, 1);
-    QCOMPARE(item->numRepaints, 1);
+    QTRY_COMPARE(effect->numRepaints, 1);
+    QTRY_COMPARE(item->numRepaints, 1);
 
     // Make sure QPainter* and QStyleOptionGraphicsItem* stays persistent
     // during QGraphicsEffect::draw/QGraphicsItem::paint.
@@ -293,26 +293,23 @@
 
     // Make sure updating the source triggers a repaint.
     item->update();
-    QTest::qWait(50);
-    QCOMPARE(effect->numRepaints, 1);
-    QCOMPARE(item->numRepaints, 1);
+    QTRY_COMPARE(effect->numRepaints, 1);
+    QTRY_COMPARE(item->numRepaints, 1);
     QVERIFY(effect->m_sourceChangedFlags & QGraphicsEffect::SourceInvalidated);
     effect->reset();
     item->reset();
 
     // Make sure changing the effect's bounding rect triggers a repaint.
     effect->setMargin(20);
-    QTest::qWait(50);
-    QCOMPARE(effect->numRepaints, 1);
-    QCOMPARE(item->numRepaints, 1);
+    QTRY_COMPARE(effect->numRepaints, 1);
+    QTRY_COMPARE(item->numRepaints, 1);
     effect->reset();
     item->reset();
 
     // Make sure change the item's bounding rect triggers a repaint.
     item->setRect(0, 0, 50, 50);
-    QTest::qWait(50);
-    QCOMPARE(effect->numRepaints, 1);
-    QCOMPARE(item->numRepaints, 1);
+    QTRY_COMPARE(effect->numRepaints, 1);
+    QTRY_COMPARE(item->numRepaints, 1);
     QVERIFY(effect->m_sourceChangedFlags & QGraphicsEffect::SourceBoundingRectChanged);
     effect->reset();
     item->reset();
@@ -320,8 +317,7 @@
     // Make sure the effect is the one to issue a repaint of the item.
     effect->doNothingInDraw = true;
     item->update();
-    QTest::qWait(50);
-    QCOMPARE(effect->numRepaints, 1);
+    QTRY_COMPARE(effect->numRepaints, 1);
     QCOMPARE(item->numRepaints, 0);
     effect->doNothingInDraw = false;
     effect->reset();
@@ -336,9 +332,8 @@
     item->reset();
 
     effect->setEnabled(true);
-    QTest::qWait(50);
-    QCOMPARE(effect->numRepaints, 1);
-    QCOMPARE(item->numRepaints, 1);
+    QTRY_COMPARE(effect->numRepaints, 1);
+    QTRY_COMPARE(item->numRepaints, 1);
     effect->reset();
     item->reset();
 
@@ -352,8 +347,7 @@
     QPointer<CustomEffect> ptr = effect;
     item->setGraphicsEffect(0);
     QVERIFY(!ptr);
-    QTest::qWait(50);
-    QCOMPARE(item->numRepaints, 1);
+    QTRY_COMPARE(item->numRepaints, 1);
 }
 
 void tst_QGraphicsEffect::opacity()
@@ -515,7 +509,6 @@
     QTRY_VERIFY(effect->repaints >= 1);
 
     item->rotate(180);
-    QTest::qWait(50);
 
     QTRY_VERIFY(effect->repaints >= 2);
 }
@@ -560,9 +553,8 @@
     int numRepaints = item->numRepaints;
 
     item->translate(10, 0);
-    QTest::qWait(50);
 
-    QVERIFY(item->numRepaints == numRepaints);
+    QTRY_VERIFY(item->numRepaints == numRepaints);
 }
 
 void tst_QGraphicsEffect::inheritOpacity()
@@ -588,7 +580,6 @@
     int numRepaints = item->numRepaints;
 
     rectItem->setOpacity(1);
-    QTest::qWait(50);
 
     // item should have been rerendered due to opacity changing
     QTRY_VERIFY(item->numRepaints > numRepaints);
@@ -657,6 +648,33 @@
     QCOMPARE(parent.nbPaint, 3);
 }
 
+void tst_QGraphicsEffect::prepareGeometryChangeInvalidateCache()
+{
+    MyGraphicsItem *item = new MyGraphicsItem;
+    item->resize(200, 200);
+
+    QGraphicsScene scene;
+    scene.addItem(item);
+
+    QGraphicsView view(&scene);
+    view.show();
+    QTest::qWaitForWindowShown(&view);
+    QTRY_COMPARE(item->nbPaint, 1);
+
+    item->nbPaint = 0;
+    item->setGraphicsEffect(new QGraphicsDropShadowEffect);
+    QTRY_COMPARE(item->nbPaint, 1);
+
+    item->nbPaint = 0;
+    item->resize(300, 300);
+    QTRY_COMPARE(item->nbPaint, 1);
+
+    item->nbPaint = 0;
+    item->setPos(item->pos() + QPointF(10, 10));
+    QTest::qWait(50);
+    QCOMPARE(item->nbPaint, 0);
+}
+
 QTEST_MAIN(tst_QGraphicsEffect)
 #include "tst_qgraphicseffect.moc"