diff options
author | Liang Qi <liang.qi@qt.io> | 2018-05-14 18:34:32 +0000 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2018-05-14 21:17:03 +0000 |
commit | 4f421c274bb8f7d9bc6fb968f4d8275d1cd3cf06 (patch) | |
tree | 733b8d0bd9b5d4369588da03390afd207843eeff /tests/auto | |
parent | 71a1df5456ebe7070533b469434a964e7de5a5c7 (diff) | |
parent | 7e1b504f31dcdad0b055c1532209e44f81033bc9 (diff) |
Merge "Merge remote-tracking branch 'origin/5.11' into dev" into refs/staging/dev
Diffstat (limited to 'tests/auto')
18 files changed, 177 insertions, 355 deletions
diff --git a/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp b/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp index de759ae051..e32fa7c724 100644 --- a/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp +++ b/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp @@ -2838,11 +2838,19 @@ void tst_QSslSocket::qtbug18498_peek() client->setObjectName("client"); client->ignoreSslErrors(); - connect(client, SIGNAL(encrypted()), this, SLOT(exitLoop())); + int encryptedCounter = 2; + connect(client, &QSslSocket::encrypted, this, [&encryptedCounter, this](){ + if (!--encryptedCounter) + exitLoop(); + }); + WebSocket *serversocket = server.socket; + connect(serversocket, &QSslSocket::encrypted, this, [&encryptedCounter, this](){ + if (!--encryptedCounter) + exitLoop(); + }); connect(client, SIGNAL(disconnected()), this, SLOT(exitLoop())); client->startClientEncryption(); - WebSocket *serversocket = server.socket; QVERIFY(serversocket); serversocket->setObjectName("server"); diff --git a/tests/auto/widgets/graphicsview/qgraphicsanchorlayout1/tst_qgraphicsanchorlayout1.cpp b/tests/auto/widgets/graphicsview/qgraphicsanchorlayout1/tst_qgraphicsanchorlayout1.cpp index 9124ff0070..65480bf665 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsanchorlayout1/tst_qgraphicsanchorlayout1.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsanchorlayout1/tst_qgraphicsanchorlayout1.cpp @@ -3066,8 +3066,6 @@ void tst_QGraphicsAnchorLayout1::testComplexCases() widget->resize(size); QCOMPARE(widget->size(), size); -// QTest::qWait(500); // layouting is asynchronous.. - // Validate for (int i = 0; i < result.count(); ++i) { const BasicLayoutTestResult item = result[i]; diff --git a/tests/auto/widgets/graphicsview/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp b/tests/auto/widgets/graphicsview/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp index 6924b78397..34646a9074 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp @@ -1826,7 +1826,7 @@ void tst_QGraphicsGridLayout::removeLayout() QGraphicsView view(&scene); view.show(); - QTest::qWait(20); + QVERIFY(QTest::qWaitForWindowActive(&view)); QRectF r1 = textEdit->geometry(); QRectF r2 = pushButton->geometry(); diff --git a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp index 92225f60a2..6ff95c0304 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp @@ -1691,7 +1691,6 @@ void tst_QGraphicsItem::selected_textItem() QGraphicsView view(&scene); view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); - QTest::qWait(20); QTRY_VERIFY(!text->isSelected()); QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, @@ -1725,107 +1724,88 @@ void tst_QGraphicsItem::selected_multi() QGraphicsView view(&scene); view.show(); view.fitInView(scene.sceneRect()); - qApp->processEvents(); + QVERIFY(QTest::qWaitForWindowActive(&view)); QVERIFY(!item1->isSelected()); QVERIFY(!item2->isSelected()); - // Start clicking - QTest::qWait(200); - // Click on item1 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(item1->scenePos())); - QTest::qWait(20); QVERIFY(item1->isSelected()); QVERIFY(!item2->isSelected()); // Click on item2 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(item2->scenePos())); - QTest::qWait(20); QVERIFY(item2->isSelected()); QVERIFY(!item1->isSelected()); // Ctrl-click on item1 QTest::mouseClick(view.viewport(), Qt::LeftButton, Qt::ControlModifier, view.mapFromScene(item1->scenePos())); - QTest::qWait(20); QVERIFY(item2->isSelected()); QVERIFY(item1->isSelected()); // Ctrl-click on item1 again QTest::mouseClick(view.viewport(), Qt::LeftButton, Qt::ControlModifier, view.mapFromScene(item1->scenePos())); - QTest::qWait(20); QVERIFY(item2->isSelected()); QVERIFY(!item1->isSelected()); // Ctrl-click on item2 QTest::mouseClick(view.viewport(), Qt::LeftButton, Qt::ControlModifier, view.mapFromScene(item2->scenePos())); - QTest::qWait(20); QVERIFY(!item2->isSelected()); QVERIFY(!item1->isSelected()); // Click on item1 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(item1->scenePos())); - QTest::qWait(20); QVERIFY(item1->isSelected()); QVERIFY(!item2->isSelected()); // Click on scene QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(0, 0)); - QTest::qWait(20); QVERIFY(!item1->isSelected()); QVERIFY(!item2->isSelected()); // Click on item1 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(item1->scenePos())); - QTest::qWait(20); QVERIFY(item1->isSelected()); QVERIFY(!item2->isSelected()); // Ctrl-click on scene QTest::mouseClick(view.viewport(), Qt::LeftButton, Qt::ControlModifier, view.mapFromScene(0, 0)); - QTest::qWait(20); QVERIFY(item1->isSelected()); QVERIFY(!item2->isSelected()); // Click on scene QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(0, 0)); - QTest::qWait(20); QVERIFY(!item1->isSelected()); QVERIFY(!item2->isSelected()); // Click on item1 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(item1->scenePos())); - QTest::qWait(20); QVERIFY(item1->isSelected()); QVERIFY(!item2->isSelected()); // Press on item2 QTest::mousePress(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(item2->scenePos())); - QTest::qWait(20); QVERIFY(!item1->isSelected()); QVERIFY(item2->isSelected()); // Release on item2 QTest::mouseRelease(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(item2->scenePos())); - QTest::qWait(20); QVERIFY(!item1->isSelected()); QVERIFY(item2->isSelected()); // Click on item1 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(item1->scenePos())); - QTest::qWait(20); QVERIFY(item1->isSelected()); QVERIFY(!item2->isSelected()); // Ctrl-click on item1 QTest::mouseClick(view.viewport(), Qt::LeftButton, Qt::ControlModifier, view.mapFromScene(item1->scenePos())); - QTest::qWait(20); QVERIFY(!item1->isSelected()); QVERIFY(!item2->isSelected()); // Ctrl-press on item1 QTest::mousePress(view.viewport(), Qt::LeftButton, Qt::ControlModifier, view.mapFromScene(item1->scenePos())); - QTest::qWait(20); QVERIFY(!item1->isSelected()); QVERIFY(!item2->isSelected()); @@ -1833,14 +1813,12 @@ void tst_QGraphicsItem::selected_multi() // Ctrl-move on item1 QMouseEvent event(QEvent::MouseMove, view.mapFromScene(item1->scenePos()) + QPoint(1, 0), Qt::LeftButton, Qt::LeftButton, Qt::ControlModifier); QApplication::sendEvent(view.viewport(), &event); - QTest::qWait(20); QVERIFY(!item1->isSelected()); QVERIFY(!item2->isSelected()); } // Release on item1 QTest::mouseRelease(view.viewport(), Qt::LeftButton, Qt::ControlModifier, view.mapFromScene(item1->scenePos())); - QTest::qWait(20); QVERIFY(item1->isSelected()); QVERIFY(!item2->isSelected()); @@ -1849,7 +1827,6 @@ void tst_QGraphicsItem::selected_multi() // Ctrl-press on item1 QTest::mousePress(view.viewport(), Qt::LeftButton, Qt::ControlModifier, view.mapFromScene(item1->scenePos())); - QTest::qWait(20); QVERIFY(!item1->isSelected()); QVERIFY(!item2->isSelected()); @@ -1857,14 +1834,12 @@ void tst_QGraphicsItem::selected_multi() // Ctrl-move on item1 QMouseEvent event(QEvent::MouseMove, view.mapFromScene(item1->scenePos()) + QPoint(1, 0), Qt::LeftButton, Qt::LeftButton, Qt::ControlModifier); QApplication::sendEvent(view.viewport(), &event); - QTest::qWait(20); QVERIFY(item1->isSelected()); QVERIFY(!item2->isSelected()); } // Release on item1 QTest::mouseRelease(view.viewport(), Qt::LeftButton, Qt::ControlModifier, view.mapFromScene(item1->scenePos())); - QTest::qWait(20); QVERIFY(item1->isSelected()); QVERIFY(!item2->isSelected()); } @@ -3386,9 +3361,8 @@ void tst_QGraphicsItem::childrenBoundingRect() view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); - QTest::qWait(30); - QCOMPARE(parent->childrenBoundingRect(), QRectF(-500, -100, 600, 800)); + QTRY_COMPARE(parent->childrenBoundingRect(), QRectF(-500, -100, 600, 800)); } void tst_QGraphicsItem::childrenBoundingRectTransformed() @@ -3579,7 +3553,6 @@ void tst_QGraphicsItem::group() QCOMPARE(scene.items().size(), 4); QCOMPARE(scene.items(group->sceneBoundingRect()).size(), 3); - QTest::qWait(25); QRectF parent2SceneBoundingRect = parent2->sceneBoundingRect(); group->addToGroup(parent2); @@ -3591,8 +3564,6 @@ void tst_QGraphicsItem::group() QCOMPARE(scene.items().size(), 4); QCOMPARE(scene.items(group->sceneBoundingRect()).size(), 4); - QTest::qWait(25); - QList<QGraphicsItem *> newItems; for (int i = 0; i < 100; ++i) { QGraphicsItem *item = scene.addRect(QRectF(-25, -25, 50, 50), QPen(Qt::black, 0), @@ -3606,12 +3577,9 @@ void tst_QGraphicsItem::group() view.fitInView(scene.itemsBoundingRect()); - int n = 0; foreach (QGraphicsItem *item, newItems) { group->addToGroup(item); QCOMPARE(item->group(), group); - if ((n++ % 100) == 0) - QTest::qWait(10); } } @@ -3801,7 +3769,6 @@ void tst_QGraphicsItem::handlesChildEvents() QGraphicsView view(&scene); view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); - QTest::qWait(20); // Pull out the items, closest item first QList<QGraphicsItem *> items = scene.items(scene.itemsBoundingRect()); @@ -4014,7 +3981,6 @@ void tst_QGraphicsItem::filtersChildEvents() QGraphicsView view(&scene); view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); - QTest::qWait(20); QGraphicsSceneMouseEvent pressEvent(QEvent::GraphicsSceneMousePress); QGraphicsSceneMouseEvent releaseEvent(QEvent::GraphicsSceneMouseRelease); @@ -4140,7 +4106,6 @@ void tst_QGraphicsItem::ensureVisible() } item->ensureVisible(-100, -100, 25, 25); - QTest::qWait(25); for (int x = -100; x < 100; x += 25) { for (int y = -100; y < 100; y += 25) { @@ -4220,8 +4185,6 @@ void tst_QGraphicsItem::cursor() QTest::mouseMove(&view, view.rect().center()); - QTest::qWait(25); - const Qt::CursorShape viewportShape = view.viewport()->cursor().shape(); { @@ -5043,7 +5006,6 @@ void tst_QGraphicsItem::sceneEventFilter() gv.setScene(anotherScene); gv.show(); QVERIFY(QTest::qWaitForWindowExposed(&gv)); - QTest::qWait(25); ti->installSceneEventFilter(ti2); ti3->installSceneEventFilter(ti); delete ti2; @@ -5116,30 +5078,25 @@ void tst_QGraphicsItem::paint() QGraphicsView view2(&scene2); view2.show(); QVERIFY(QTest::qWaitForWindowExposed(&view2)); - QTest::qWait(25); PaintTester tester2; scene2.addItem(&tester2); - qApp->processEvents(); //First show one paint QTRY_COMPARE(tester2.painted, 1); //nominal case, update call paint tester2.update(); - qApp->processEvents(); QTRY_COMPARE(tester2.painted, 2); //we remove the item from the scene, number of updates is still the same tester2.update(); scene2.removeItem(&tester2); - qApp->processEvents(); QTRY_COMPARE(tester2.painted, 2); //We re-add the item, the number of paint should increase scene2.addItem(&tester2); tester2.update(); - qApp->processEvents(); QTRY_COMPARE(tester2.painted, 3); } @@ -6263,7 +6220,6 @@ void tst_QGraphicsItem::untransformable() view.rotate(13); view.shear(qreal(0.01), qreal(0.01)); view.translate(10, 10); - QTest::qWait(25); } } @@ -6302,7 +6258,6 @@ void tst_QGraphicsItem::contextMenuEventPropagation() view.show(); view.resize(200, 200); QVERIFY(QTest::qWaitForWindowExposed(&view)); - QTest::qWait(20); QContextMenuEvent event(QContextMenuEvent::Mouse, QPoint(10, 10), view.viewport()->mapToGlobal(QPoint(10, 10))); @@ -6580,15 +6535,12 @@ void tst_QGraphicsItem::ensureUpdateOnTextItem() QGraphicsView view(&scene); view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); - QTest::qWait(25); TextItem *text1 = new TextItem(QLatin1String("123")); scene.addItem(text1); - qApp->processEvents(); QTRY_COMPARE(text1->updates,1); //same bouding rect but we have to update text1->setText(QLatin1String("321")); - qApp->processEvents(); QTRY_COMPARE(text1->updates,2); } @@ -6867,7 +6819,6 @@ void tst_QGraphicsItem::opacity2() RESET_REPAINT_COUNTERS child->setOpacity(0.0); - QTest::qWait(10); QTRY_COMPARE(view.repaints, 1); QCOMPARE(parent->repaints, 1); QCOMPARE(child->repaints, 0); @@ -6876,7 +6827,6 @@ void tst_QGraphicsItem::opacity2() RESET_REPAINT_COUNTERS child->setOpacity(1.0); - QTest::qWait(10); QTRY_COMPARE(view.repaints, 1); QCOMPARE(parent->repaints, 1); QCOMPARE(child->repaints, 1); @@ -6885,7 +6835,6 @@ void tst_QGraphicsItem::opacity2() RESET_REPAINT_COUNTERS parent->setOpacity(0.0); - QTest::qWait(10); QTRY_COMPARE(view.repaints, 1); QCOMPARE(parent->repaints, 0); QCOMPARE(child->repaints, 0); @@ -6894,7 +6843,6 @@ void tst_QGraphicsItem::opacity2() RESET_REPAINT_COUNTERS parent->setOpacity(1.0); - QTest::qWait(10); QTRY_COMPARE(view.repaints, 1); QCOMPARE(parent->repaints, 1); QCOMPARE(child->repaints, 1); @@ -6904,7 +6852,6 @@ void tst_QGraphicsItem::opacity2() RESET_REPAINT_COUNTERS child->setOpacity(0.0); - QTest::qWait(10); QTRY_COMPARE(view.repaints, 1); QCOMPARE(parent->repaints, 1); QCOMPARE(child->repaints, 0); @@ -6914,7 +6861,7 @@ void tst_QGraphicsItem::opacity2() child->setOpacity(0.0); // Already 0.0; no change. QTest::qWait(10); - QTRY_COMPARE(view.repaints, 0); + QCOMPARE(view.repaints, 0); QCOMPARE(parent->repaints, 0); QCOMPARE(child->repaints, 0); QCOMPARE(grandChild->repaints, 0); @@ -6939,7 +6886,7 @@ void tst_QGraphicsItem::opacityZeroUpdates() view.reset(); parent->setOpacity(0.0); - QTest::qWait(20); + QTRY_COMPARE(view.repaints, 1); // transforming items bounding rect to view coordinates const QRect childDeviceBoundingRect = child->deviceTransform(view.viewportTransform()) @@ -7008,7 +6955,6 @@ void tst_QGraphicsItem::itemStacksBehindParent() view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); QTRY_VERIFY(!paintedItems.isEmpty()); - QTest::qWait(100); paintedItems.clear(); view.viewport()->update(); QApplication::processEvents(); @@ -7027,34 +6973,32 @@ void tst_QGraphicsItem::itemStacksBehindParent() child11->setFlag(QGraphicsItem::ItemStacksBehindParent); scene.update(); paintedItems.clear(); - QApplication::processEvents(); QTRY_COMPARE(scene.items(rect), (QList<QGraphicsItem *>() << grandChild121 << child12 << parent1 << grandChild111 << child11 << grandChild211 << child21 << grandChild221 << child22 << parent2)); - QCOMPARE(paintedItems, QList<QGraphicsItem *>() - << parent2 << child22 << grandChild221 - << child21 << grandChild211 - << child11 << grandChild111 - << parent1 << child12 << grandChild121); + QTRY_COMPARE(paintedItems, QList<QGraphicsItem *>() + << parent2 << child22 << grandChild221 + << child21 << grandChild211 + << child11 << grandChild111 + << parent1 << child12 << grandChild121); child12->setFlag(QGraphicsItem::ItemStacksBehindParent); paintedItems.clear(); scene.update(); - QApplication::processEvents(); QTRY_COMPARE(scene.items(rect), (QList<QGraphicsItem *>() << parent1 << grandChild111 << child11 << grandChild121 << child12 << grandChild211 << child21 << grandChild221 << child22 << parent2)); - QCOMPARE(paintedItems, QList<QGraphicsItem *>() - << parent2 << child22 << grandChild221 - << child21 << grandChild211 - << child12 << grandChild121 - << child11 << grandChild111 << parent1); + QTRY_COMPARE(paintedItems, QList<QGraphicsItem *>() + << parent2 << child22 << grandChild221 + << child21 << grandChild211 + << child12 << grandChild121 + << child11 << grandChild111 << parent1); } class ClippingAndTransformsScene : public QGraphicsScene @@ -7106,7 +7050,6 @@ void tst_QGraphicsItem::nestedClipping() view.setOptimizationFlag(QGraphicsView::IndirectPainting); view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); - QTest::qWait(25); QList<QGraphicsItem *> expected; expected << root << l1 << l2 << l3; @@ -7299,16 +7242,13 @@ void tst_QGraphicsItem::tabChangesFocus() QTRY_VERIFY(scene.isActive()); dial1->setFocus(); - QTest::qWait(15); QTRY_VERIFY(dial1->hasFocus()); QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab); - QTest::qWait(15); QTRY_VERIFY(view->hasFocus()); QTRY_VERIFY(item->hasFocus()); QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab); - QTest::qWait(15); if (tabChangesFocus) { QTRY_VERIFY(!view->hasFocus()); @@ -7331,10 +7271,6 @@ void tst_QGraphicsItem::cacheMode() QVERIFY(QTest::qWaitForWindowExposed(&view)); QVERIFY(QTest::qWaitForWindowActive(&view)); - // Increase the probability of window activation - // not causing another repaint of test items. - QTest::qWait(50); - EventTester *tester = new EventTester; EventTester *testerChild = new EventTester; testerChild->setParentItem(tester); @@ -7343,7 +7279,6 @@ void tst_QGraphicsItem::cacheMode() testerChild2->setFlag(QGraphicsItem::ItemIgnoresTransformations); scene.addItem(tester); - QTest::qWait(10); for (int i = 0; i < 2; ++i) { // No visual change. @@ -7368,7 +7303,6 @@ void tst_QGraphicsItem::cacheMode() tester->setPos(10, 10); testerChild->setPos(10, 10); testerChild2->setPos(10, 10); - QTest::qWait(25); QTRY_COMPARE(tester->repaints, 2); QCOMPARE(testerChild->repaints, 2); QCOMPARE(testerChild2->repaints, 2); @@ -7385,13 +7319,12 @@ void tst_QGraphicsItem::cacheMode() // Translating does not result in a repaint. tester->setTransform(QTransform::fromTranslate(10, 10), true); QTest::qWait(25); - QTRY_COMPARE(tester->repaints, 2); + QCOMPARE(tester->repaints, 2); QCOMPARE(testerChild->repaints, 2); QCOMPARE(testerChild2->repaints, 2); // Rotating results in a repaint. tester->setTransform(QTransform().rotate(45), true); - QTest::qWait(25); QTRY_COMPARE(tester->repaints, 3); QCOMPARE(testerChild->repaints, 3); QCOMPARE(testerChild2->repaints, 2); @@ -7400,7 +7333,6 @@ void tst_QGraphicsItem::cacheMode() tester->setCacheMode(QGraphicsItem::ItemCoordinateCache); // autosize testerChild->setCacheMode(QGraphicsItem::ItemCoordinateCache); // autosize testerChild2->setCacheMode(QGraphicsItem::ItemCoordinateCache); // autosize - QTest::qWait(25); QTRY_COMPARE(tester->repaints, 4); QCOMPARE(testerChild->repaints, 4); QCOMPARE(testerChild2->repaints, 3); @@ -7410,16 +7342,15 @@ void tst_QGraphicsItem::cacheMode() testerChild->setTransform(QTransform().rotate(22), true); testerChild2->setTransform(QTransform().rotate(22), true); QTest::qWait(25); - QTRY_COMPARE(tester->repaints, 4); - QTRY_COMPARE(testerChild->repaints, 4); - QTRY_COMPARE(testerChild2->repaints, 3); + QCOMPARE(tester->repaints, 4); + QCOMPARE(testerChild->repaints, 4); + QCOMPARE(testerChild2->repaints, 3); tester->resetTransform(); testerChild->resetTransform(); testerChild2->resetTransform(); // Explicit update causes a repaint. tester->update(0, 0, 5, 5); - QTest::qWait(25); QTRY_COMPARE(tester->repaints, 5); QCOMPARE(testerChild->repaints, 4); QCOMPARE(testerChild2->repaints, 3); @@ -7427,14 +7358,13 @@ void tst_QGraphicsItem::cacheMode() // Updating outside the item's bounds does not cause a repaint. tester->update(10, 10, 5, 5); QTest::qWait(25); - QTRY_COMPARE(tester->repaints, 5); + QCOMPARE(tester->repaints, 5); QCOMPARE(testerChild->repaints, 4); QCOMPARE(testerChild2->repaints, 3); // Resizing an item should cause a repaint of that item. (because of // autosize). tester->setGeometry(QRectF(-15, -15, 30, 30)); - QTest::qWait(25); QTRY_COMPARE(tester->repaints, 6); QCOMPARE(testerChild->repaints, 4); QCOMPARE(testerChild2->repaints, 3); @@ -7443,22 +7373,20 @@ void tst_QGraphicsItem::cacheMode() tester->setCacheMode(QGraphicsItem::ItemCoordinateCache, QSize(30, 30)); testerChild->setCacheMode(QGraphicsItem::ItemCoordinateCache, QSize(30, 30)); testerChild2->setCacheMode(QGraphicsItem::ItemCoordinateCache, QSize(30, 30)); - QTest::qWait(20); QTRY_COMPARE(tester->repaints, 7); QCOMPARE(testerChild->repaints, 5); QCOMPARE(testerChild2->repaints, 4); // Resizing the item should cause a repaint. testerChild->setGeometry(QRectF(-15, -15, 30, 30)); - QTest::qWait(25); - QTRY_COMPARE(tester->repaints, 7); - QCOMPARE(testerChild->repaints, 6); + QTRY_COMPARE(testerChild->repaints, 6); + QCOMPARE(tester->repaints, 7); QCOMPARE(testerChild2->repaints, 4); // Scaling the view does not cause a repaint. view.scale(0.7, 0.7); QTest::qWait(25); - QTRY_COMPARE(tester->repaints, 7); + QCOMPARE(tester->repaints, 7); QCOMPARE(testerChild->repaints, 6); QCOMPARE(testerChild2->repaints, 4); @@ -7466,46 +7394,42 @@ void tst_QGraphicsItem::cacheMode() tester->setCacheMode(QGraphicsItem::DeviceCoordinateCache); testerChild->setCacheMode(QGraphicsItem::DeviceCoordinateCache); testerChild2->setCacheMode(QGraphicsItem::DeviceCoordinateCache); - QTest::qWait(25); QTRY_COMPARE(tester->repaints, 8); QCOMPARE(testerChild->repaints, 7); QCOMPARE(testerChild2->repaints, 5); // Scaling the view back should cause repaints for two of the items. view.setTransform(QTransform()); - QTest::qWait(25); QTRY_COMPARE(tester->repaints, 9); QCOMPARE(testerChild->repaints, 8); QCOMPARE(testerChild2->repaints, 5); // Rotating the base item (perspective) should repaint two items. tester->setTransform(QTransform().rotate(10, Qt::XAxis)); - QTest::qWait(25); QTRY_COMPARE(tester->repaints, 10); QCOMPARE(testerChild->repaints, 9); QCOMPARE(testerChild2->repaints, 5); - // Moving the middle item should case a repaint even if it's a move, + // Moving the middle item should cause a repaint even if it's a move, // because the parent is rotated with a perspective. testerChild->setPos(1, 1); - QTest::qWait(25); QTRY_COMPARE(tester->repaints, 11); QTRY_COMPARE(testerChild->repaints, 10); - QTRY_COMPARE(testerChild2->repaints, 5); + QCOMPARE(testerChild2->repaints, 5); tester->resetTransform(); // Make a huge item tester->setGeometry(QRectF(-4000, -4000, 8000, 8000)); QTRY_COMPARE(tester->repaints, 12); QTRY_COMPARE(testerChild->repaints, 11); - QTRY_COMPARE(testerChild2->repaints, 5); + QCOMPARE(testerChild2->repaints, 5); // Move the large item - will cause a repaint as the // cache is clipped. tester->setPos(5, 0); QTRY_COMPARE(tester->repaints, 13); QTRY_COMPARE(testerChild->repaints, 11); - QTRY_COMPARE(testerChild2->repaints, 5); + QCOMPARE(testerChild2->repaints, 5); // Hiding and showing should invalidate the cache tester->hide(); @@ -7526,66 +7450,56 @@ void tst_QGraphicsItem::cacheMode2() QVERIFY(QTest::qWaitForWindowExposed(&view)); QVERIFY(QTest::qWaitForWindowActive(&view)); - // Increase the probability of window activation - // not causing another repaint of test items. - QTest::qWait(50); - EventTester *tester = new EventTester; scene.addItem(tester); - QTest::qWait(10); QTRY_COMPARE(tester->repaints, 1); // Switching from NoCache to NoCache (no repaint) tester->setCacheMode(QGraphicsItem::NoCache); QTest::qWait(50); - QTRY_COMPARE(tester->repaints, 1); + QCOMPARE(tester->repaints, 1); // Switching from NoCache to DeviceCoordinateCache (no repaint) tester->setCacheMode(QGraphicsItem::DeviceCoordinateCache); QTest::qWait(50); - QTRY_COMPARE(tester->repaints, 1); + QCOMPARE(tester->repaints, 1); // Switching from DeviceCoordinateCache to DeviceCoordinateCache (no repaint) tester->setCacheMode(QGraphicsItem::DeviceCoordinateCache); QTest::qWait(50); - QTRY_COMPARE(tester->repaints, 1); + QCOMPARE(tester->repaints, 1); // Switching from DeviceCoordinateCache to NoCache (no repaint) tester->setCacheMode(QGraphicsItem::NoCache); QTest::qWait(50); - QTRY_COMPARE(tester->repaints, 1); + QCOMPARE(tester->repaints, 1); // Switching from NoCache to ItemCoordinateCache (repaint) tester->setCacheMode(QGraphicsItem::ItemCoordinateCache); - QTest::qWait(50); QTRY_COMPARE(tester->repaints, 2); // Switching from ItemCoordinateCache to ItemCoordinateCache (no repaint) tester->setCacheMode(QGraphicsItem::ItemCoordinateCache); QTest::qWait(50); - QTRY_COMPARE(tester->repaints, 2); + QCOMPARE(tester->repaints, 2); // Switching from ItemCoordinateCache to ItemCoordinateCache with different size (repaint) tester->setCacheMode(QGraphicsItem::ItemCoordinateCache, QSize(100, 100)); - QTest::qWait(50); QTRY_COMPARE(tester->repaints, 3); // Switching from ItemCoordinateCache to NoCache (repaint) tester->setCacheMode(QGraphicsItem::NoCache); - QTest::qWait(50); QTRY_COMPARE(tester->repaints, 4); // Switching from DeviceCoordinateCache to ItemCoordinateCache (repaint) tester->setCacheMode(QGraphicsItem::DeviceCoordinateCache); QTest::qWait(50); - QTRY_COMPARE(tester->repaints, 4); + QCOMPARE(tester->repaints, 4); tester->setCacheMode(QGraphicsItem::ItemCoordinateCache); - QTest::qWait(50); QTRY_COMPARE(tester->repaints, 5); // Switching from ItemCoordinateCache to DeviceCoordinateCache (repaint) tester->setCacheMode(QGraphicsItem::DeviceCoordinateCache); - QTest::qWait(50); QTRY_COMPARE(tester->repaints, 6); } @@ -7603,7 +7517,6 @@ void tst_QGraphicsItem::updateCachedItemAfterMove() view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); - QTest::qWait(12); QTRY_VERIFY(tester->repaints > 0); tester->repaints = 0; @@ -7615,8 +7528,7 @@ void tst_QGraphicsItem::updateCachedItemAfterMove() // Move then update, should cause one repaint tester->setPos(20, 0); tester->update(); - QTest::qWait(12); - QCOMPARE(tester->repaints, 1); + QTRY_COMPARE(tester->repaints, 1); // Hiding the item doesn't cause a repaint tester->hide(); @@ -7753,28 +7665,25 @@ void tst_QGraphicsItem::update() EventTester *item = new EventTester; scene.addItem(item); - QTest::qWait(100); // Make sure all pending updates are processed. + QTRY_VERIFY(item->repaints > 0); // Wait for painting item->repaints = 0; item->update(); // Item marked as dirty scene.update(); // Entire scene marked as dirty - qApp->processEvents(); - QCOMPARE(item->repaints, 1); + QTRY_COMPARE(item->repaints, 1); // Make sure the dirty state from the previous update is reset so that // the item don't think it is already dirty and discards this update. item->update(); - qApp->processEvents(); - QCOMPARE(item->repaints, 2); + QTRY_COMPARE(item->repaints, 2); // Make sure a partial update doesn't cause a full update to be discarded. view.reset(); item->repaints = 0; item->update(QRectF(0, 0, 5, 5)); item->update(); - qApp->processEvents(); - QCOMPARE(item->repaints, 1); - QCOMPARE(view.repaints, 1); + QTRY_COMPARE(item->repaints, 1); + QTRY_COMPARE(view.repaints, 1); QRect itemDeviceBoundingRect = item->deviceTransform(view.viewportTransform()) .mapRect(item->boundingRect()).toAlignedRect(); QRegion expectedRegion = itemDeviceBoundingRect.adjusted(-2, -2, 2, 2); @@ -7836,13 +7745,11 @@ void tst_QGraphicsItem::update() item->setPos(originalPos + QPoint(50, 50)); viewPrivate->updateAll(); QVERIFY(viewPrivate->fullUpdatePending); - QTest::qWait(50); + QTRY_VERIFY(view.repaints > 1 && item->repaints > 1); item->repaints = 0; view.reset(); item->setPos(originalPos); - QTest::qWait(50); - qApp->processEvents(); - QCOMPARE(item->repaints, 1); + QTRY_COMPARE(item->repaints, 1); QCOMPARE(view.repaints, 1); COMPARE_REGIONS(view.paintedRegion, expectedRegion + expectedRegion.translated(50, 50)); @@ -7853,7 +7760,6 @@ void tst_QGraphicsItem::update() item->setParentItem(parent); item->setPos(400, 0); scene.addItem(parent); - QTest::qWait(50); itemDeviceBoundingRect = item->deviceTransform(view.viewportTransform()) .mapRect(item->boundingRect()).toAlignedRect(); expectedRegion = itemDeviceBoundingRect.adjusted(-2, -2, 2, 2); @@ -7995,6 +7901,7 @@ public: void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) { + ++repaints; if (startTrack) { //Doesn't use the extended style option so the exposed rect is the boundingRect if (!(flags() & QGraphicsItem::ItemUsesExtendedStyleOption)) { @@ -8009,6 +7916,7 @@ public: QGraphicsRectItem::paint(painter, option, widget); } bool startTrack; + int repaints = 0; }; void tst_QGraphicsItem::itemUsesExtendedStyleOption() @@ -8031,17 +7939,21 @@ void tst_QGraphicsItem::itemUsesExtendedStyleOption() rect->startTrack = false; topLevel.show(); QVERIFY(QTest::qWaitForWindowExposed(&topLevel)); - QTest::qWait(60); + QTRY_VERIFY(rect->repaints > 0); + rect->repaints = 0; rect->startTrack = true; rect->update(10, 10, 10, 10); - QTest::qWait(60); + QTRY_COMPARE(rect->repaints, 1); + rect->repaints = 0; rect->startTrack = false; rect->setFlag(QGraphicsItem::ItemUsesExtendedStyleOption, true); QVERIFY((rect->flags() & QGraphicsItem::ItemUsesExtendedStyleOption)); - QTest::qWait(60); + QTRY_COMPARE(rect->repaints, 1); + rect->repaints = 0; rect->startTrack = true; rect->update(10, 10, 10, 10); QTest::qWait(60); + // MyStyleOptionTester does not receive a paint event. Why not? } void tst_QGraphicsItem::itemSendsGeometryChanges() @@ -8124,8 +8036,9 @@ void tst_QGraphicsItem::moveItem() grandChild->repaints = 0; \ view.reset(); + RESET_COUNTERS scene.addItem(parent); - QTest::qWait(100); + QTRY_COMPARE(view.repaints, 1); RESET_COUNTERS @@ -8204,15 +8117,13 @@ void tst_QGraphicsItem::moveLineItem() // Make sure the calculated region is correct. item->update(); - QTest::qWait(10); QTRY_COMPARE(view.paintedRegion, expectedRegion); view.reset(); // Old position: (50, 50) item->setPos(50, 100); expectedRegion += expectedRegion.translated(0, 50); - QTest::qWait(10); - QCOMPARE(view.paintedRegion, expectedRegion); + QTRY_COMPARE(view.paintedRegion, expectedRegion); } void tst_QGraphicsItem::sorting_data() @@ -8261,7 +8172,7 @@ void tst_QGraphicsItem::sorting() qApp->setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowExposed(&view)); QVERIFY(QTest::qWaitForWindowActive(&view)); - QTest::qWait(100); + QTRY_VERIFY(_paintedItems.count() > 0); _paintedItems.clear(); @@ -8345,7 +8256,6 @@ void tst_QGraphicsItem::hitTestUntransformableItem() item3->setPos(80, 80); scene.addItem(item1); - QTest::qWait(100); QList<QGraphicsItem *> items = scene.items(QPointF(80, 80)); QCOMPARE(items.size(), 1); @@ -8402,7 +8312,8 @@ void tst_QGraphicsItem::hitTestGraphicsEffectItem() item3->brush = Qt::blue; scene.addItem(item1); - QTest::qWait(100); + QTRY_COMPARE(item2->repaints, 1); + QCOMPARE(item3->repaints, 1); item1->repaints = 0; item2->repaints = 0; @@ -8412,10 +8323,9 @@ void tst_QGraphicsItem::hitTestGraphicsEffectItem() QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect; shadow->setOffset(-20, -20); item1->setGraphicsEffect(shadow); - QTest::qWait(50); // Make sure all visible items are repainted. - QCOMPARE(item1->repaints, 1); + QTRY_COMPARE(item1->repaints, 1); QCOMPARE(item2->repaints, 1); QCOMPARE(item3->repaints, 1); diff --git a/tests/auto/widgets/graphicsview/qgraphicslinearlayout/tst_qgraphicslinearlayout.cpp b/tests/auto/widgets/graphicsview/qgraphicslinearlayout/tst_qgraphicslinearlayout.cpp index 97f3eb4a60..f9b6fe3ebd 100644 --- a/tests/auto/widgets/graphicsview/qgraphicslinearlayout/tst_qgraphicslinearlayout.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicslinearlayout/tst_qgraphicslinearlayout.cpp @@ -612,7 +612,6 @@ void tst_QGraphicsLinearLayout::insertStretch() } } - //QTest::qWait(1000); delete widget; } @@ -639,7 +638,6 @@ void tst_QGraphicsLinearLayout::invalidate() layout.setContentsMargins(0, 0, 0, 0); view.show(); widget->show(); - //QTest::qWait(1000); QVERIFY(QTest::qWaitForWindowExposed(&view)); qApp->processEvents(); layout.layoutRequest = 0; @@ -1218,7 +1216,6 @@ void tst_QGraphicsLinearLayout::testStretch() //view->setSceneRect(-50, -50, 800, 800); //view->show(); //QVERIFY(QTest::qWaitForWindowExposed(view)); - //QTest::qWait(5000); QCOMPARE(form->geometry().size(), QSizeF(600,600)); QCOMPARE(w1->geometry(), QRectF(0, 0, 100, 100)); QCOMPARE(w2->geometry(), QRectF(400, 0, 200, 200)); @@ -1521,7 +1518,7 @@ void tst_QGraphicsLinearLayout::removeLayout() QGraphicsView view(&scene); view.show(); - QTest::qWait(20); + QVERIFY(QTest::qWaitForWindowActive(&view)); QRectF r1 = textEdit->geometry(); QRectF r2 = pushButton->geometry(); diff --git a/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp b/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp index 3b340d06ab..0071c39f49 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp @@ -3108,7 +3108,6 @@ void tst_QGraphicsScene::tabFocus_sceneWithFocusableItems() // Check that everyone loses focus when the widget is hidden. widget.hide(); - QTest::qWait(15); QTRY_VERIFY(!view->hasFocus()); QVERIFY(!view->viewport()->hasFocus()); QVERIFY(!scene.hasFocus()); @@ -4056,7 +4055,6 @@ void tst_QGraphicsScene::isActive() QVERIFY(!scene2.hasFocus()); toplevel1.hide(); - QTest::qWait(50); QTRY_VERIFY(!scene1.isActive()); QTRY_VERIFY(!scene2.isActive()); QVERIFY(!scene1.hasFocus()); @@ -4381,7 +4379,6 @@ void tst_QGraphicsScene::taskQT657_paintIntoCacheWithTransparentParts() QVERIFY(QTest::qWaitForWindowExposed(view)); view->repaints = 0; proxy->update(10, 10, 10, 10); - QTest::qWait(50); QTRY_VERIFY(view->repaints > 0); QPixmap pix; @@ -4427,7 +4424,6 @@ void tst_QGraphicsScene::taskQTBUG_7863_paintIntoCacheWithTransparentParts() QVERIFY(QTest::qWaitForWindowExposed(view)); view->repaints = 0; rectItem->update(10, 10, 10, 10); - QTest::qWait(50); QTRY_VERIFY(view->repaints > 0); QPixmap pix; @@ -4469,7 +4465,6 @@ void tst_QGraphicsScene::taskQTBUG_7863_paintIntoCacheWithTransparentParts() QVERIFY(QTest::qWaitForWindowExposed(view)); view->repaints = 0; rectItem->update(10, 10, 10, 10); - QTest::qWait(50); QTRY_VERIFY(view->repaints > 0); QPixmap pix; @@ -4510,7 +4505,6 @@ void tst_QGraphicsScene::taskQTBUG_7863_paintIntoCacheWithTransparentParts() QVERIFY(QTest::qWaitForWindowExposed(view)); view->repaints = 0; rectItem->update(10, 10, 10, 10); - QTest::qWait(50); QTRY_VERIFY(view->repaints > 0); QPixmap pix; diff --git a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp index 582c0e36a0..87a05d02d9 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp @@ -508,10 +508,8 @@ void tst_QGraphicsView::setScene() view.setScene(0); - QTest::qWait(25); - - QVERIFY(!view.horizontalScrollBar()->isVisible()); - QVERIFY(!view.verticalScrollBar()->isVisible()); + QTRY_VERIFY(!view.horizontalScrollBar()->isVisible()); + QTRY_VERIFY(!view.verticalScrollBar()->isVisible()); QVERIFY(!view.horizontalScrollBar()->isHidden()); QVERIFY(!view.verticalScrollBar()->isHidden()); @@ -573,13 +571,12 @@ void tst_QGraphicsView::sceneRect_growing() QGraphicsView view(&scene, &toplevel); view.setFixedSize(200, 200); toplevel.show(); + QVERIFY(QTest::qWaitForWindowActive(&toplevel)); int size = 200; scene.setSceneRect(-size, -size, size * 2, size * 2); QCOMPARE(view.sceneRect(), scene.sceneRect()); - QTest::qWait(25); - QPointF topLeft = view.mapToScene(0, 0); for (int i = 0; i < 5; ++i) { @@ -642,14 +639,14 @@ void tst_QGraphicsView::viewport() QVERIFY(view.viewport() != 0); view.show(); - QTest::qWait(25); + QVERIFY(QTest::qWaitForWindowExposed(&view)); QPointer<QWidget> widget = new QWidget; view.setViewport(widget); QCOMPARE(view.viewport(), (QWidget *)widget); view.show(); - QTest::qWait(25); + QVERIFY(QTest::qWaitForWindowExposed(&view)); view.setViewport(0); QVERIFY(widget.isNull()); @@ -657,7 +654,7 @@ void tst_QGraphicsView::viewport() QVERIFY(view.viewport() != widget); view.show(); - QTest::qWait(25); + QVERIFY(QTest::qWaitForWindowExposed(&view)); } #ifndef QT_NO_OPENGL @@ -889,8 +886,6 @@ void tst_QGraphicsView::dragMode_rubberBand() // We don't use QRubberBand as of 4.3; the band is drawn internally. QVERIFY(!view.findChild<QRubberBand *>()); - QTest::qWait(25); - { // Move QMouseEvent event(QEvent::MouseMove, @@ -903,8 +898,6 @@ void tst_QGraphicsView::dragMode_rubberBand() QCOMPARE(view.horizontalScrollBar()->value(), horizontalScrollBarValue); QCOMPARE(view.verticalScrollBar()->value(), verticalScrollBarValue); - QTest::qWait(25); - { // Release QMouseEvent event(QEvent::MouseButtonRelease, @@ -920,8 +913,6 @@ void tst_QGraphicsView::dragMode_rubberBand() QCOMPARE(view.viewport()->cursor().shape(), cursorShape); #endif - QTest::qWait(25); - if (view.scene()) QCOMPARE(scene.selectedItems().size(), 1); @@ -1075,7 +1066,7 @@ void tst_QGraphicsView::backgroundBrush() QCOMPARE(scene.backgroundBrush(), QBrush(Qt::blue)); view.show(); - QTest::qWait(25); + QVERIFY(QTest::qWaitForWindowExposed(&view)); scene.setBackgroundBrush(QBrush()); QCOMPARE(scene.backgroundBrush(), QBrush()); @@ -1097,7 +1088,7 @@ void tst_QGraphicsView::foregroundBrush() QCOMPARE(scene.foregroundBrush(), QBrush(Qt::blue)); view.show(); - QTest::qWait(25); + QVERIFY(QTest::qWaitForWindowExposed(&view)); scene.setForegroundBrush(QBrush()); QCOMPARE(scene.foregroundBrush(), QBrush()); @@ -2054,7 +2045,7 @@ void tst_QGraphicsView::mapFromSceneRect() view.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); view.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); topLevel.show(); - QTest::qWait(25); + QVERIFY(QTest::qWaitForWindowActive(&view)); QPolygon polygon; polygon << QPoint(98, 98); @@ -2464,7 +2455,6 @@ void tst_QGraphicsView::viewportUpdateMode() // Issue two scene updates. scene.update(QRectF(0, 0, 10, 10)); scene.update(QRectF(20, 0, 10, 10)); - QTest::qWait(50); // The view gets two updates for the update scene updates. QTRY_VERIFY(!view.lastUpdateRegions.isEmpty()); @@ -2571,8 +2561,7 @@ void tst_QGraphicsView::viewportUpdateMode2() view.lastUpdateRegions.clear(); viewPrivate->processPendingUpdates(); - QTest::qWait(50); - QCOMPARE(view.lastUpdateRegions.size(), 1); + QTRY_COMPARE(view.lastUpdateRegions.size(), 1); // Note that we adjust by 2 for antialiasing. QCOMPARE(view.lastUpdateRegions.at(0), QRegion(boundingRect.adjusted(-2, -2, 2, 2) & viewportRect)); #endif @@ -2769,8 +2758,7 @@ void tst_QGraphicsView::optimizationFlags_dontSavePainterState2() // Make sure the view is repainted; otherwise the tests below will fail. view.viewport()->repaint(); - QTest::qWait(200); - QVERIFY(view.painted); + QTRY_VERIFY(view.painted); // Make sure the painter's world transform is preserved after drawItems. QTransform expectedTransform = view.viewportTransform(); @@ -3683,7 +3671,6 @@ void tst_QGraphicsView::centerOnDirtyItem() toplevel.show(); QVERIFY(QTest::qWaitForWindowExposed(&toplevel)); - QTest::qWait(50); QImage before(view.viewport()->size(), QImage::Format_ARGB32); view.viewport()->render(&before); @@ -3691,8 +3678,6 @@ void tst_QGraphicsView::centerOnDirtyItem() item->setPos(20, 0); view.centerOn(item); - QTest::qWait(50); - QImage after(view.viewport()->size(), QImage::Format_ARGB32); view.viewport()->render(&after); @@ -4290,8 +4275,6 @@ void tst_QGraphicsView::update_ancestorClipsChildrenToShape2() QCOMPARE(view.lastUpdateRegions.at(0), QRegion(expected.toAlignedRect())); #endif - QTest::qWait(50); - view.lastUpdateRegions.clear(); view.painted = false; @@ -4491,7 +4474,7 @@ void tst_QGraphicsView::indirectPainting() view.setOptimizationFlag(QGraphicsView::IndirectPainting); view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); - QTest::qWait(100); + QTRY_VERIFY(scene.drawCount > 0); scene.drawCount = 0; item->setPos(20, 20); diff --git a/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp b/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp index da52a7ea27..231474c71c 100644 --- a/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp +++ b/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp @@ -1168,8 +1168,7 @@ void tst_QAbstractItemView::task221955_selectedEditor() //We set the focus to the button, the index need to be selected button->setFocus(); - QTest::qWait(100); - QVERIFY(tree.selectionModel()->selectedIndexes().contains(tree.model()->index(3,0))); + QTRY_VERIFY(tree.selectionModel()->selectedIndexes().contains(tree.model()->index(3,0))); tree.setCurrentIndex(tree.model()->index(1,0)); QVERIFY(! tree.selectionModel()->selectedIndexes().contains(tree.model()->index(3,0))); @@ -1179,7 +1178,6 @@ void tst_QAbstractItemView::task221955_selectedEditor() tree.setSelectionMode(QAbstractItemView::NoSelection); tree.clearSelection(); QVERIFY(tree.selectionModel()->selectedIndexes().isEmpty()); - QTest::qWait(10); button->setFocus(); QTest::qWait(50); QVERIFY(tree.selectionModel()->selectedIndexes().isEmpty()); @@ -1267,15 +1265,11 @@ void tst_QAbstractItemView::task257481_emptyEditor() QCOMPARE(lineEditors.count(), 1); QVERIFY(!lineEditors.first()->size().isEmpty()); - QTest::qWait(30); - treeView.edit(model.index(1,0)); lineEditors = treeView.viewport()->findChildren<QLineEdit *>(); QCOMPARE(lineEditors.count(), 1); QVERIFY(!lineEditors.first()->size().isEmpty()); - QTest::qWait(30); - treeView.edit(model.index(2,0)); lineEditors = treeView.viewport()->findChildren<QLineEdit *>(); QCOMPARE(lineEditors.count(), 1); @@ -1462,7 +1456,6 @@ void tst_QAbstractItemView::QTBUG6407_extendedSelection() QCOMPARE(static_cast<QWidget *>(&view), QApplication::activeWindow()); view.verticalScrollBar()->setValue(view.verticalScrollBar()->maximum()); - QTest::qWait(20); QModelIndex index49 = view.model()->index(49,0); QPoint p = view.visualRect(index49).center(); @@ -1506,7 +1499,6 @@ void tst_QAbstractItemView::QTBUG6753_selectOnSelection() QRect itemRect = table.visualRect(item); QTest::mouseMove(table.viewport(), itemRect.center()); QTest::mouseClick(table.viewport(), Qt::LeftButton, Qt::NoModifier, itemRect.center()); - QTest::qWait(20); QCOMPARE(table.selectedItems().count(), 1); QCOMPARE(table.selectedItems().first(), table.item(item.row(), item.column())); diff --git a/tests/auto/widgets/itemviews/qcolumnview/tst_qcolumnview.cpp b/tests/auto/widgets/itemviews/qcolumnview/tst_qcolumnview.cpp index 38e6d95ba4..58b34e8aea 100644 --- a/tests/auto/widgets/itemviews/qcolumnview/tst_qcolumnview.cpp +++ b/tests/auto/widgets/itemviews/qcolumnview/tst_qcolumnview.cpp @@ -703,7 +703,7 @@ void tst_QColumnView::moveGrip() view.setCurrentIndex(home); view.resize(640, 200); topLevel.show(); - QTest::qWait(ANIMATION_DELAY); + QVERIFY(QTest::qWaitForWindowActive(&topLevel)); int columnNum = view.createdColumns.count() - 2; QVERIFY(columnNum >= 0); @@ -934,7 +934,6 @@ void tst_QColumnView::parentCurrentIndex() QVERIFY(second.isValid()); QVERIFY(third.isValid()); view.setCurrentIndex(third); - QTest::qWait(ANIMATION_DELAY); QTRY_COMPARE(view.createdColumns[0]->currentIndex(), first); QTRY_COMPARE(view.createdColumns[1]->currentIndex(), second); QTRY_COMPARE(view.createdColumns[2]->currentIndex(), third); @@ -946,7 +945,6 @@ void tst_QColumnView::parentCurrentIndex() QVERIFY(second.isValid()); QVERIFY(third.isValid()); view.setCurrentIndex(third); - QTest::qWait(ANIMATION_DELAY); QTRY_COMPARE(view.createdColumns[0]->currentIndex(), first); QTRY_COMPARE(view.createdColumns[1]->currentIndex(), second); diff --git a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp index a15c1aafe7..57dbb98049 100644 --- a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp +++ b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp @@ -240,8 +240,8 @@ private slots: void testStreamWithHide(); void testStylePosition(); void stretchAndRestoreLastSection(); - void testMinMaxSectionSizeStretched(); - void testMinMaxSectionSizeNotStretched(); + void testMinMaxSectionSize_data(); + void testMinMaxSectionSize(); void sizeHintCrash(); void testResetCachedSizeHint(); @@ -2284,21 +2284,21 @@ void tst_QHeaderView::QTBUG6058_reset() view.setModel(&proxy); view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); + QVERIFY(QTest::qWaitForWindowActive(&view)); proxy.setSourceModel(&model1); - QApplication::processEvents(); view.swapSections(0,2); view.swapSections(1,4); - QApplication::processEvents(); - QCOMPARE(checkHeaderViewOrder(&view, QVector<int>() << 2 << 4 << 0 << 3 << 1 << 5) , 0); + QVector<int> expectedOrder{2, 4, 0, 3, 1, 5}; + QTRY_COMPARE(checkHeaderViewOrder(&view, expectedOrder) , 0); proxy.setSourceModel(&model2); - QApplication::processEvents(); - QCOMPARE(checkHeaderViewOrder(&view, QVector<int>() << 2 << 0 << 1 ) , 0); + expectedOrder = {2, 0, 1}; + QTRY_COMPARE(checkHeaderViewOrder(&view, expectedOrder) , 0); proxy.setSourceModel(&model1); - QApplication::processEvents(); - QCOMPARE(checkHeaderViewOrder(&view, QVector<int>() << 2 << 0 << 1 << 3 << 4 << 5 ) , 0); + expectedOrder = {2, 0, 1, 3, 4, 5}; + QTRY_COMPARE(checkHeaderViewOrder(&view, expectedOrder) , 0); } void tst_QHeaderView::QTBUG7833_sectionClicked() @@ -3284,18 +3284,17 @@ void tst_QHeaderView::stretchAndRestoreLastSection() QCOMPARE(header.sectionSize(9), someOtherSectionSize); } -void tst_QHeaderView::testMinMaxSectionSizeStretched() +void tst_QHeaderView::testMinMaxSectionSize_data() { - testMinMaxSectionSize(true); + QTest::addColumn<bool>("stretchLastSection"); + QTest::addRow("stretched") << true; + QTest::addRow("not stretched") << false; } -void tst_QHeaderView::testMinMaxSectionSizeNotStretched() +void tst_QHeaderView::testMinMaxSectionSize() { - testMinMaxSectionSize(false); -} + QFETCH(bool, stretchLastSection); -void tst_QHeaderView::testMinMaxSectionSize(bool stretchLastSection) -{ QStandardItemModel m(5, 5); QTableView tv; tv.setModel(&m); @@ -3331,8 +3330,7 @@ void tst_QHeaderView::testMinMaxSectionSize(bool stretchLastSection) header.resizeSection(0, sectionSizeMax); QCOMPARE(header.sectionSize(0), sectionSizeMax); header.setMaximumSectionSize(defaultSectionSize); - QVERIFY(QTest::qWaitFor([&header, defaultSectionSize]() { return header.sectionSize(0) == defaultSectionSize; })); - QCOMPARE(header.sectionSize(0), defaultSectionSize); + QTRY_COMPARE(header.sectionSize(0), defaultSectionSize); // change section size on min change header.setMinimumSectionSize(sectionSizeMin); @@ -3340,8 +3338,7 @@ void tst_QHeaderView::testMinMaxSectionSize(bool stretchLastSection) header.resizeSection(0, sectionSizeMin); QCOMPARE(header.sectionSize(0), sectionSizeMin); header.setMinimumSectionSize(defaultSectionSize); - QVERIFY(QTest::qWaitFor([&header, defaultSectionSize]() { return header.sectionSize(0) == defaultSectionSize; })); - QCOMPARE(header.sectionSize(0), defaultSectionSize); + QTRY_COMPARE(header.sectionSize(0), defaultSectionSize); } void tst_QHeaderView::testResetCachedSizeHint() diff --git a/tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp b/tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp index 802a04b4bf..a8f6906056 100644 --- a/tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp +++ b/tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp @@ -1276,7 +1276,7 @@ void tst_QItemDelegate::enterKey() view.show(); QApplication::setActiveWindow(&view); view.setFocus(); - QTest::qWait(30); + QVERIFY(QTest::qWaitForWindowActive(&view)); struct TestDelegate : public QItemDelegate { @@ -1306,7 +1306,6 @@ void tst_QItemDelegate::enterKey() QModelIndex index = model.index(0, 0); view.setCurrentIndex(index); // the editor will only selectAll on the current index view.edit(index); - QTest::qWait(30); QList<QWidget*> lineEditors = view.viewport()->findChildren<QWidget *>(QString::fromLatin1("TheEditor")); QCOMPARE(lineEditors.count(), 1); @@ -1315,7 +1314,6 @@ void tst_QItemDelegate::enterKey() QCOMPARE(editor->hasFocus(), true); QTest::keyClick(editor, Qt::Key(key)); - QApplication::processEvents(); if (expectedFocus) { QVERIFY(!editor.isNull()); @@ -1335,11 +1333,10 @@ void tst_QItemDelegate::task257859_finalizeEdit() view.show(); QApplication::setActiveWindow(&view); view.setFocus(); - QTest::qWait(30); + QVERIFY(QTest::qWaitForWindowActive(&view)); QModelIndex index = model.index(0, 0); view.edit(index); - QTest::qWait(30); QList<QLineEdit *> lineEditors = view.viewport()->findChildren<QLineEdit *>(); QCOMPARE(lineEditors.count(), 1); @@ -1454,28 +1451,26 @@ void tst_QItemDelegate::testLineEditValidation() QApplication::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowActive(&view)); - QList<QLineEdit *> lineEditors; QPointer<QLineEdit> editor; QPersistentModelIndex index = model.indexFromItem(item); view.setCurrentIndex(index); view.edit(index); - QTest::qWait(30); - lineEditors = view.findChildren<QLineEdit *>(QStringLiteral("TheEditor")); - QCOMPARE(lineEditors.count(), 1); - editor = lineEditors.at(0); + const auto findEditors = [&]() { + return view.findChildren<QLineEdit *>(QStringLiteral("TheEditor")); + }; + QCOMPARE(findEditors().count(), 1); + editor = findEditors().at(0); editor->clear(); // first try to set a valid text QTest::keyClicks(editor, QStringLiteral("foo,bar")); - QTest::qWait(30); // close the editor QTest::keyClick(editor, Qt::Key(key)); - QTest::qWait(30); - QVERIFY(editor.isNull()); + QTRY_VERIFY(editor.isNull()); if (key != Qt::Key_Escape) QCOMPARE(item->data(Qt::DisplayRole).toString(), QStringLiteral("foo,bar")); else @@ -1484,20 +1479,16 @@ void tst_QItemDelegate::testLineEditValidation() // now an invalid (but partially matching) text view.setCurrentIndex(index); view.edit(index); - QTest::qWait(30); - lineEditors = view.findChildren<QLineEdit *>(QStringLiteral("TheEditor")); - QCOMPARE(lineEditors.count(), 1); - editor = lineEditors.at(0); + QTRY_COMPARE(findEditors().count(), 1); + editor = findEditors().at(0); editor->clear(); // edit QTest::keyClicks(editor, QStringLiteral("foobar")); - QTest::qWait(30); // try to close the editor QTest::keyClick(editor, Qt::Key(key)); - QTest::qWait(30); if (key != Qt::Key_Escape) { QVERIFY(!editor.isNull()); @@ -1505,33 +1496,29 @@ void tst_QItemDelegate::testLineEditValidation() QCOMPARE(editor->text(), QStringLiteral("foobar")); QCOMPARE(item->data(Qt::DisplayRole).toString(), QStringLiteral("foo,bar")); } else { - QVERIFY(editor.isNull()); + QTRY_VERIFY(editor.isNull()); QCOMPARE(item->data(Qt::DisplayRole).toString(), QStringLiteral("abc,def")); } // reset the view to forcibly close the editor view.reset(); - QTest::qWait(30); + QTRY_COMPARE(findEditors().count(), 0); // set a valid text again view.setCurrentIndex(index); view.edit(index); - QTest::qWait(30); - lineEditors = view.findChildren<QLineEdit *>(QStringLiteral("TheEditor")); - QCOMPARE(lineEditors.count(), 1); - editor = lineEditors.at(0); + QTRY_COMPARE(findEditors().count(), 1); + editor = findEditors().at(0); editor->clear(); // set a valid text QTest::keyClicks(editor, QStringLiteral("gender,bender")); - QTest::qWait(30); // close the editor QTest::keyClick(editor, Qt::Key(key)); - QTest::qWait(30); - QVERIFY(editor.isNull()); + QTRY_VERIFY(editor.isNull()); if (key != Qt::Key_Escape) QCOMPARE(item->data(Qt::DisplayRole).toString(), QStringLiteral("gender,bender")); else diff --git a/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp b/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp index 1d8286b3cf..d0c9dae313 100644 --- a/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp +++ b/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp @@ -293,7 +293,7 @@ public: void tst_QListView::cleanup() { - QVERIFY(QApplication::topLevelWidgets().isEmpty()); + QTRY_VERIFY(QApplication::topLevelWidgets().isEmpty()); } void tst_QListView::noDelegate() @@ -779,7 +779,6 @@ void tst_QListView::hideFirstRow() view.setRowHidden(0,true); view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); - QTest::qWait(10); } static int modelIndexCount(const QAbstractItemView *view) @@ -857,7 +856,6 @@ void tst_QListView::setCurrentIndex() QCOMPARE(sb->value(), offset + 1); ++offset; } - //QTest::qWait(50); } --i; // item 20 does not exist @@ -870,7 +868,6 @@ void tst_QListView::setCurrentIndex() QCOMPARE(sb->value(), offset - 1); --offset; } - //QTest::qWait(50); } } } @@ -1397,21 +1394,17 @@ void tst_QListView::scrollBarAsNeeded() lv.setModel(&model); lv.resize(size); topLevel.show(); + QVERIFY(QTest::qWaitForWindowActive(&topLevel)); for (uint r = 0; r < sizeof(rowCounts)/sizeof(int); ++r) { QStringList list; - int i; - for (i = 0; i < rowCounts[r]; ++i) + for (int i = 0; i < rowCounts[r]; ++i) list << QLatin1String("Item ") + QString::number(i); model.setStringList(list); - QApplication::processEvents(); - QTest::qWait(50); model.setStringList(generateList(QLatin1String("Item "), itemCount)); - QApplication::processEvents(); - QTRY_COMPARE(lv.horizontalScrollBar()->isVisible(), horizontalScrollBarVisible); QTRY_COMPARE(lv.verticalScrollBar()->isVisible(), verticalScrollBarVisible); } @@ -1577,14 +1570,14 @@ void tst_QListView::task228566_infiniteRelayout() view.setFixedHeight(itemHeight * 12); view.show(); + QVERIFY(QTest::qWaitForWindowActive(&view)); QTest::qWait(100); //make sure the layout is done once QSignalSpy spy(view.horizontalScrollBar(), SIGNAL(rangeChanged(int,int))); - QTest::qWait(200); //the layout should already have been done //so there should be no change made to the scrollbar - QCOMPARE(spy.count(), 0); + QVERIFY(!spy.wait(200)); } void tst_QListView::task248430_crashWith0SizedItem() @@ -1619,7 +1612,7 @@ void tst_QListView::task250446_scrollChanged() QTRY_COMPARE(view.currentIndex(), index); view.showNormal(); - QTest::qWait(50); + QVERIFY(QTest::qWaitForWindowExposed(&view)); QTRY_COMPARE(view.verticalScrollBar()->value(), scrollValue); QTRY_COMPARE(view.currentIndex(), index); } @@ -1709,19 +1702,14 @@ void tst_QListView::keyboardSearch() qApp->setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowActive(&view)); -// QCOMPARE(view.currentIndex() , model.index(0,0)); - QTest::keyClick(&view, Qt::Key_K); - QTest::qWait(10); - QCOMPARE(view.currentIndex() , model.index(5,0)); //KAFEINE + QTRY_COMPARE(view.currentIndex() , model.index(5,0)); //KAFEINE QTest::keyClick(&view, Qt::Key_O); - QTest::qWait(10); - QCOMPARE(view.currentIndex() , model.index(6,0)); //KONQUEROR + QTRY_COMPARE(view.currentIndex() , model.index(6,0)); //KONQUEROR QTest::keyClick(&view, Qt::Key_N); - QTest::qWait(10); - QCOMPARE(view.currentIndex() , model.index(6,0)); //KONQUEROR + QTRY_COMPARE(view.currentIndex() , model.index(6,0)); //KONQUEROR } void tst_QListView::shiftSelectionWithNonUniformItemSizes() @@ -1751,8 +1739,7 @@ void tst_QListView::shiftSelectionWithNonUniformItemSizes() QCOMPARE(view.currentIndex(), index); QTest::keyClick(&view, Qt::Key_Up, Qt::ShiftModifier); - QTest::qWait(10); - QCOMPARE(view.currentIndex(), model.index(1, 0)); + QTRY_COMPARE(view.currentIndex(), model.index(1, 0)); QModelIndexList selected = view.selectionModel()->selectedIndexes(); QCOMPARE(selected.count(), 3); @@ -1781,8 +1768,7 @@ void tst_QListView::shiftSelectionWithNonUniformItemSizes() QCOMPARE(view.currentIndex(), index); QTest::keyClick(&view, Qt::Key_Left, Qt::ShiftModifier); - QTest::qWait(10); - QCOMPARE(view.currentIndex(), model.index(1, 0)); + QTRY_COMPARE(view.currentIndex(), model.index(1, 0)); QModelIndexList selected = view.selectionModel()->selectedIndexes(); QCOMPARE(selected.count(), 3); @@ -1833,10 +1819,8 @@ void tst_QListView::task262152_setModelColumnNavigate() QVERIFY(QTest::qWaitForWindowActive(&view)); QCOMPARE(static_cast<QWidget *>(&view), QApplication::activeWindow()); QTest::keyClick(&view, Qt::Key_Down); - QTest::qWait(30); QTRY_COMPARE(view.currentIndex(), model.index(1,1)); QTest::keyClick(&view, Qt::Key_Down); - QTest::qWait(30); QTRY_COMPARE(view.currentIndex(), model.index(2,1)); } @@ -1888,14 +1872,11 @@ void tst_QListView::taskQTBUG_2233_scrollHiddenItems() int nbVisibleItem = rowCount / 2 - bar->maximum(); bar->setValue(bar->maximum()); - QApplication::processEvents(); for (int i = rowCount; i > rowCount / 2; i--) { view.setRowHidden(i, true); } - QApplication::processEvents(); - QTest::qWait(50); + QTRY_COMPARE(bar->maximum(), rowCount/4 - nbVisibleItem); QCOMPARE(bar->value(), bar->maximum()); - QCOMPARE(bar->maximum(), rowCount/4 - nbVisibleItem); } void tst_QListView::taskQTBUG_633_changeModelData() @@ -1911,10 +1892,12 @@ void tst_QListView::taskQTBUG_633_changeModelData() view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); model.setData( model.index(1, 0), QLatin1String("long long text")); - QTest::qWait(100); //leave time for relayouting the items - QRect rectLongText = view.visualRect(model.index(1,0)); - QRect rect2 = view.visualRect(model.index(2,0)); - QVERIFY( ! rectLongText.intersects(rect2) ); + const auto longTextDoesNotIntersectNextItem = [&]() { + QRect rectLongText = view.visualRect(model.index(1,0)); + QRect rect2 = view.visualRect(model.index(2,0)); + return !rectLongText.intersects(rect2); + }; + QTRY_VERIFY(longTextDoesNotIntersectNextItem()); } void tst_QListView::taskQTBUG_435_deselectOnViewportClick() diff --git a/tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp b/tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp index f7332a15f5..98b44fe8aa 100644 --- a/tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp +++ b/tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp @@ -1565,7 +1565,7 @@ void tst_QListWidget::task217070_scrollbarsAdjusted() v.setResizeMode(QListView::Adjust); v.setUniformItemSizes(true); v.resize(160,100); - QTest::qWait(50); + QVERIFY(QTest::qWaitForWindowActive(&v)); QScrollBar *hbar = v.horizontalScrollBar(); QScrollBar *vbar = v.verticalScrollBar(); QVERIFY(hbar && vbar); diff --git a/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp b/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp index 06c80bf8d2..8427b04be7 100644 --- a/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp +++ b/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp @@ -2781,15 +2781,14 @@ void tst_QTableView::scrollTo() for (int c = 0; c < columnCount; ++c) view.setColumnWidth(c, columnWidth); - QTest::qWait(150); // ### needed to pass the test view.horizontalScrollBar()->setValue(horizontalScroll); view.verticalScrollBar()->setValue(verticalScroll); QModelIndex index = model.index(row, column); QVERIFY(index.isValid()); view.scrollTo(index, (QAbstractItemView::ScrollHint)scrollHint); - QCOMPARE(view.verticalScrollBar()->value(), expectedVerticalScroll); - QCOMPARE(view.horizontalScrollBar()->value(), expectedHorizontalScroll); + QTRY_COMPARE(view.verticalScrollBar()->value(), expectedVerticalScroll); + QTRY_COMPARE(view.horizontalScrollBar()->value(), expectedHorizontalScroll); } void tst_QTableView::indexAt_data() @@ -2936,14 +2935,12 @@ void tst_QTableView::indexAt() for (int c = 0; c < columnCount; ++c) view.setColumnWidth(c, columnWidth); - QTest::qWait(20); view.horizontalScrollBar()->setValue(horizontalScroll); view.verticalScrollBar()->setValue(verticalScroll); - QTest::qWait(20); QModelIndex index = view.indexAt(QPoint(x, y)); - QCOMPARE(index.row(), expectedRow); - QCOMPARE(index.column(), expectedColumn); + QTRY_COMPARE(index.row(), expectedRow); + QTRY_COMPARE(index.column(), expectedColumn); } void tst_QTableView::span_data() @@ -3261,7 +3258,7 @@ void tst_QTableView::spansAfterRowInsertion() view.setModel(&model); view.setSpan(3, 3, 3, 3); view.show(); - QTest::qWait(50); + QVERIFY(QTest::qWaitForWindowActive(&view)); // Insertion before the span only shifts the span. view.model()->insertRows(0, 2); @@ -3297,7 +3294,7 @@ void tst_QTableView::spansAfterColumnInsertion() view.setModel(&model); view.setSpan(3, 3, 3, 3); view.show(); - QTest::qWait(50); + QVERIFY(QTest::qWaitForWindowActive(&view)); // Insertion before the span only shifts the span. view.model()->insertColumns(0, 2); @@ -3345,7 +3342,7 @@ void tst_QTableView::spansAfterRowRemoval() view.setSpan(span.top(), span.left(), span.height(), span.width()); view.show(); - QTest::qWait(100); + QVERIFY(QTest::qWaitForWindowActive(&view)); view.model()->removeRows(3, 3); QList<QRect> expectedSpans; @@ -3385,7 +3382,7 @@ void tst_QTableView::spansAfterColumnRemoval() view.setSpan(span.left(), span.top(), span.width(), span.height()); view.show(); - QTest::qWait(100); + QVERIFY(QTest::qWaitForWindowActive(&view)); view.model()->removeColumns(3, 3); QList<QRect> expectedSpans; @@ -4083,7 +4080,6 @@ void tst_QTableView::task259308_scrollVerticalHeaderSwappedSections() QTRY_COMPARE(tv.currentIndex().row(), newRow); tv.setCurrentIndex(model.index(0, 0)); - QTest::qWait(60); QTest::keyClick(&tv, Qt::Key_PageDown); // PageDown won't scroll when at the bottom QTRY_COMPARE(tv.rowAt(tv.viewport()->height() - 1), tv.verticalHeader()->logicalIndex(model.rowCount() - 1)); } @@ -4104,7 +4100,7 @@ void tst_QTableView::task191545_dragSelectRows() table.setSelectionMode(QAbstractItemView::ExtendedSelection); table.setMinimumSize(1000, 400); table.show(); - QTest::qWait(200); + QVERIFY(QTest::qWaitForWindowActive(&table)); ValueSaver<Qt::KeyboardModifiers> saver(QApplicationPrivate::modifier_buttons); QApplicationPrivate::modifier_buttons = Qt::ControlModifier; @@ -4214,27 +4210,22 @@ void tst_QTableView::task234926_setHeaderSorting() QTableView view; view.setModel(&model); // view.show(); - QTest::qWait(20); - QCOMPARE(model.stringList(), data); + QTRY_COMPARE(model.stringList(), data); view.setSortingEnabled(true); view.sortByColumn(0, Qt::AscendingOrder); - QApplication::processEvents(); - QCOMPARE(model.stringList() , sortedDataA); + QTRY_COMPARE(model.stringList() , sortedDataA); view.horizontalHeader()->setSortIndicator(0, Qt::DescendingOrder); - QApplication::processEvents(); - QCOMPARE(model.stringList() , sortedDataD); + QTRY_COMPARE(model.stringList() , sortedDataD); QHeaderView *h = new QHeaderView(Qt::Horizontal); h->setModel(&model); view.setHorizontalHeader(h); h->setSortIndicator(0, Qt::AscendingOrder); - QApplication::processEvents(); - QCOMPARE(model.stringList() , sortedDataA); + QTRY_COMPARE(model.stringList() , sortedDataA); h->setSortIndicator(0, Qt::DescendingOrder); - QApplication::processEvents(); - QCOMPARE(model.stringList() , sortedDataD); + QTRY_COMPARE(model.stringList() , sortedDataD); } void tst_QTableView::taskQTBUG_5062_spansInconsistency() @@ -4288,9 +4279,8 @@ void tst_QTableView::changeHeaderData() QVERIFY(view.verticalHeader()->width() < textWidth); model.setHeaderData(2, Qt::Vertical, text); - QTest::qWait(100); //leave time for layout - QVERIFY(view.verticalHeader()->width() > textWidth); + QTRY_VERIFY(view.verticalHeader()->width() > textWidth); } #if QT_CONFIG(wheelevent) diff --git a/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp b/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp index 37402d8a58..a58202e636 100644 --- a/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp +++ b/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp @@ -3466,6 +3466,7 @@ void tst_QTreeView::addRowsWhileSectionsAreHidden() QStandardItemModel *model = new QStandardItemModel(6, pass, &view); view.setModel(model); view.show(); + QVERIFY(QTest::qWaitForWindowActive(&view)); int i; for (i = 0; i < 3; ++i) @@ -3489,12 +3490,15 @@ void tst_QTreeView::addRowsWhileSectionsAreHidden() } for (col = 0; col < pass; ++col) view.setColumnHidden(col, false); - QTest::qWait(250); - for (i = 0; i < 6; ++i) { - QRect rect = view.visualRect(model->index(i, 0)); - QCOMPARE(rect.isValid(), true); - } + auto allVisualRectsValid = [](QTreeView *view, QStandardItemModel *model) { + for (int i = 0; i < 6; ++i) { + if (!view->visualRect(model->index(i, 0)).isValid()) + return false; + } + return true; + }; + QTRY_VERIFY(allVisualRectsValid(&view, model)); delete model; } @@ -3517,11 +3521,9 @@ void tst_QTreeView::task216717_updateChildren() tree.refreshed = false; QTreeWidgetItem *parent = new QTreeWidgetItem(QStringList() << "parent"); tree.addTopLevelItem(parent); - QTest::qWait(10); QTRY_VERIFY(tree.refreshed); tree.refreshed = false; parent->addChild(new QTreeWidgetItem(QStringList() << "child")); - QTest::qWait(10); QTRY_VERIFY(tree.refreshed); } @@ -3555,11 +3557,10 @@ void tst_QTreeView::task220298_selectColumns() Model model; view.setModel(&model); view.show(); - QTest::qWait(50); + QVERIFY(QTest::qWaitForWindowActive(&view)); QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.visualRect(view.model()->index(1, 1)).center()); - QTest::qWait(50); - QVERIFY(view.selectedIndexes().contains(view.model()->index(1, 2))); + QTRY_VERIFY(view.selectedIndexes().contains(view.model()->index(1, 2))); QVERIFY(view.selectedIndexes().contains(view.model()->index(1, 1))); QVERIFY(view.selectedIndexes().contains(view.model()->index(1, 0))); } @@ -3577,15 +3578,14 @@ void tst_QTreeView::task224091_appendColumns() qApp->setActiveWindow(topLevel); QVERIFY(QTest::qWaitForWindowActive(topLevel)); + QVERIFY(!treeView->verticalScrollBar()->isVisible()); + QList<QStandardItem *> projlist; for (int k = 0; k < 10; ++k) projlist.append(new QStandardItem(QLatin1String("Top Level ") + QString::number(k))); model->appendColumn(projlist); model->invisibleRootItem()->appendRow(new QStandardItem("end")); - QTest::qWait(50); - qApp->processEvents(); - QTRY_VERIFY(treeView->verticalScrollBar()->isVisible()); delete topLevel; @@ -3743,11 +3743,10 @@ void tst_QTreeView::task238873_avoidAutoReopening() view.setModel(&model); view.show(); view.expandAll(); - QTest::qWait(100); + QVERIFY(QTest::qWaitForWindowActive(&view)); QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.visualRect(child.index()).center()); - QTest::qWait(20); - QCOMPARE(view.currentIndex(), child.index()); + QTRY_COMPARE(view.currentIndex(), child.index()); view.setExpanded(item1.index(), false); @@ -3812,7 +3811,6 @@ void tst_QTreeView::task246536_scrollbarsNotWorking() QTest::qWait(100); o.count = 0; tree.verticalScrollBar()->setValue(50); - QTest::qWait(100); QTRY_VERIFY(o.count > 0); } @@ -3828,7 +3826,7 @@ void tst_QTreeView::task250683_wrongSectionSize() treeView.setColumnHidden(3, true); treeView.show(); - QTest::qWait(100); + QVERIFY(QTest::qWaitForWindowActive(&treeView)); QCOMPARE(treeView.header()->sectionSize(0) + treeView.header()->sectionSize(1), treeView.viewport()->width()); } @@ -3865,7 +3863,6 @@ void tst_QTreeView::task239271_addRowsWithFirstColumnHidden() QStandardItem sub1("sub1"), sub11("sub11"); root0.appendRow(QList<QStandardItem*>() << &sub1 << &sub11); - QTest::qWait(20); //items in the 2nd column should have been painted QTRY_VERIFY(!delegate.paintedIndexes.isEmpty()); QVERIFY(delegate.paintedIndexes.contains(sub00.index())); @@ -3978,7 +3975,6 @@ void tst_QTreeView::doubleClickedWithSpans() //end the previous edition QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, p); - QTest::qWait(150); QTest::mousePress(view.viewport(), Qt::LeftButton, 0, p); QTest::mouseDClick(view.viewport(), Qt::LeftButton, 0, p); QTest::mouseRelease(view.viewport(), Qt::LeftButton, 0, p); @@ -4043,7 +4039,6 @@ void tst_QTreeView::taskQTBUG_9216_setSizeAndUniformRowHeightsWrongRepaint() view.painted = 0; view.doCompare = true; model.setData(model.index(0, 0), QVariant(QSize(50, 50)), Qt::SizeHintRole); - QTest::qWait(100); QTRY_VERIFY(view.painted > 0); } @@ -4251,7 +4246,6 @@ void tst_QTreeView::taskQTBUG_11466_keyboardNavigationRegression() QVERIFY(QTest::qWaitForWindowExposed(&treeView)); QTest::keyPress(treeView.viewport(), Qt::Key_Down); - QTest::qWait(10); QTRY_COMPARE(treeView.currentIndex(), treeView.selectionModel()->selection().indexes().first()); } @@ -4271,8 +4265,7 @@ void tst_QTreeView::taskQTBUG_13567_removeLastItemRegression() view.setCurrentIndex(model.index(199, 0)); model.removeLastRow(); - QTest::qWait(10); - QCOMPARE(view.currentIndex(), model.index(198, 0)); + QTRY_COMPARE(view.currentIndex(), model.index(198, 0)); CHECK_VISIBLE(198, 0); } diff --git a/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp b/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp index 6ac0e5e18e..1f438f59eb 100644 --- a/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp +++ b/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp @@ -2041,7 +2041,6 @@ void tst_QTreeWidget::setHeaderItem() headerItem->setText(0, "0"); headerItem->setText(1, "1"); testWidget->setHeaderItem(headerItem); - QTest::qWait(100); QCOMPARE(testWidget->headerItem(), headerItem); QCOMPARE(headerItem->treeWidget(), static_cast<QTreeWidget *>(testWidget)); @@ -2996,7 +2995,7 @@ void tst_QTreeWidget::task191552_rtl() item->setCheckState(0, Qt::Checked); QCOMPARE(item->checkState(0), Qt::Checked); tw.show(); - QTest::qWait(50); + QVERIFY(QTest::qWaitForWindowActive(&tw)); QStyleOptionViewItem opt; opt.initFrom(&tw); opt.rect = tw.visualItemRect(item); @@ -3006,7 +3005,6 @@ void tst_QTreeWidget::task191552_rtl() opt.widget = &tw; const QRect checkRect = tw.style()->subElementRect(QStyle::SE_ViewItemCheckIndicator, &opt, &tw); QTest::mouseClick(tw.viewport(), Qt::LeftButton, Qt::NoModifier, checkRect.center()); - QTest::qWait(200); QCOMPARE(item->checkState(0), Qt::Unchecked); qApp->setLayoutDirection(oldDir); @@ -3103,7 +3101,7 @@ void tst_QTreeWidget::task253109_itemHeight() QTreeWidget treeWidget; treeWidget.setColumnCount(1); treeWidget.show(); - QTest::qWait(200); + QVERIFY(QTest::qWaitForWindowActive(&treeWidget)); QTreeWidgetItem item(&treeWidget); class MyWidget : public QWidget @@ -3112,9 +3110,7 @@ void tst_QTreeWidget::task253109_itemHeight() } w; treeWidget.setItemWidget(&item, 0, &w); - QTest::qWait(200); - QCOMPARE(w.geometry(), treeWidget.visualItemRect(&item)); - + QTRY_COMPARE(w.geometry(), treeWidget.visualItemRect(&item)); } void tst_QTreeWidget::task206367_duplication() @@ -3321,16 +3317,15 @@ void tst_QTreeWidget::setTextUpdate() treeWidget.setItemDelegate(&delegate); treeWidget.show(); + QVERIFY(QTest::qWaitForWindowExposed(&treeWidget)); QStringList strList; strList << "variable1" << "0"; QTreeWidgetItem *item = new QTreeWidgetItem(strList); treeWidget.insertTopLevelItem(0, item); - QTest::qWait(50); QTRY_VERIFY(delegate.numPaints > 0); delegate.numPaints = 0; item->setText(1, "42"); - QApplication::processEvents(); QTRY_VERIFY(delegate.numPaints > 0); } @@ -3371,34 +3366,30 @@ void tst_QTreeWidget::setChildIndicatorPolicy() treeWidget.setItemDelegate(&delegate); treeWidget.show(); + QVERIFY(QTest::qWaitForWindowExposed(&treeWidget)); QTreeWidgetItem *item = new QTreeWidgetItem(QStringList("Hello")); treeWidget.insertTopLevelItem(0, item); - QTest::qWait(50); QTRY_VERIFY(delegate.numPaints > 0); delegate.numPaints = 0; delegate.expectChildren = true; item->setChildIndicatorPolicy(QTreeWidgetItem::ShowIndicator); - QApplication::processEvents(); QTRY_COMPARE(delegate.numPaints, 1); delegate.numPaints = 0; delegate.expectChildren = false; item->setChildIndicatorPolicy(QTreeWidgetItem::DontShowIndicatorWhenChildless); - QApplication::processEvents(); QTRY_COMPARE(delegate.numPaints, 1); delegate.numPaints = 0; delegate.expectChildren = true; new QTreeWidgetItem(item); - QApplication::processEvents(); QTRY_COMPARE(delegate.numPaints, 1); delegate.numPaints = 0; delegate.expectChildren = false; item->setChildIndicatorPolicy(QTreeWidgetItem::DontShowIndicator); - QApplication::processEvents(); QTRY_COMPARE(delegate.numPaints, 1); } diff --git a/tests/auto/widgets/kernel/qwidget/BLACKLIST b/tests/auto/widgets/kernel/qwidget/BLACKLIST index dc9adb74f7..ae2534a8c1 100644 --- a/tests/auto/widgets/kernel/qwidget/BLACKLIST +++ b/tests/auto/widgets/kernel/qwidget/BLACKLIST @@ -15,6 +15,9 @@ rhel-7.4 osx [focusProxyAndInputMethods] linux +[raise] +# QTBUG-68175 +opensuse [setWindowGeometry] osx [windowMoveResize] diff --git a/tests/auto/widgets/widgets/qmdiarea/tst_qmdiarea.cpp b/tests/auto/widgets/widgets/qmdiarea/tst_qmdiarea.cpp index c8a92f3751..ecad7267dd 100644 --- a/tests/auto/widgets/widgets/qmdiarea/tst_qmdiarea.cpp +++ b/tests/auto/widgets/widgets/qmdiarea/tst_qmdiarea.cpp @@ -1400,6 +1400,7 @@ void tst_QMdiArea::subWindowList() QMdiArea workspace; workspace.show(); qApp->setActiveWindow(&workspace); + QVERIFY(QTest::qWaitForWindowActive(&workspace)); QList<QMdiSubWindow *> activationOrder; QVector<QMdiSubWindow *> windows; @@ -1418,8 +1419,7 @@ void tst_QMdiArea::subWindowList() windows[staysOnTop1]->setWindowFlags(windows[staysOnTop1]->windowFlags() | Qt::WindowStaysOnTopHint); workspace.setActiveSubWindow(windows[activeSubWindow]); - qApp->processEvents(); - QCOMPARE(workspace.activeSubWindow(), windows[activeSubWindow]); + QTRY_COMPARE(workspace.activeSubWindow(), windows[activeSubWindow]); activationOrder.move(activationOrder.indexOf(windows[activeSubWindow]), windowCount - 1); QList<QMdiSubWindow *> subWindows = workspace.subWindowList(windowOrder); @@ -1441,13 +1441,11 @@ void tst_QMdiArea::subWindowList() windows[staysOnTop2]->setWindowFlags(windows[staysOnTop2]->windowFlags() | Qt::WindowStaysOnTopHint); workspace.setActiveSubWindow(windows[staysOnTop2]); - qApp->processEvents(); - QCOMPARE(workspace.activeSubWindow(), windows[staysOnTop2]); + QTRY_COMPARE(workspace.activeSubWindow(), windows[staysOnTop2]); activationOrder.move(activationOrder.indexOf(windows[staysOnTop2]), windowCount - 1); workspace.setActiveSubWindow(windows[activeSubWindow]); - qApp->processEvents(); - QCOMPARE(workspace.activeSubWindow(), windows[activeSubWindow]); + QTRY_COMPARE(workspace.activeSubWindow(), windows[activeSubWindow]); activationOrder.move(activationOrder.indexOf(windows[activeSubWindow]), windowCount - 1); QList<QMdiSubWindow *> widgets = workspace.subWindowList(windowOrder); |