summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKari Oikarinen <kari.oikarinen@qt.io>2018-04-09 13:37:33 +0300
committerKari Oikarinen <kari.oikarinen@qt.io>2018-05-09 05:52:22 +0000
commite110ab6c282790f6f035d52747b8589c448a362b (patch)
tree26a4e897665c749037e4f9b33abfd9fd9bede6bf
parenta2df0ef57add82ccfb3bc3bcfaccc7510d709d98 (diff)
tests/auto/widgets/itemviews: Avoid unconditional qWait()s
Task-number: QTBUG-63992 Change-Id: Id4fcb0c2e4f83edd9508565468e16f57e100c780 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Frederik Gladhorn <frederik.gladhorn@qt.io>
-rw-r--r--tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp10
-rw-r--r--tests/auto/widgets/itemviews/qcolumnview/tst_qcolumnview.cpp4
-rw-r--r--tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp48
-rw-r--r--tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp43
-rw-r--r--tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp53
-rw-r--r--tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp2
-rw-r--r--tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp40
-rw-r--r--tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp41
-rw-r--r--tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp19
9 files changed, 90 insertions, 170 deletions
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 08597d5eb1..fd83228c8b 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();
protected:
@@ -2268,22 +2268,21 @@ void tst_QHeaderView::QTBUG6058_reset()
QHeaderView view(Qt::Vertical);
view.setModel(&proxy);
view.show();
- QTest::qWait(20);
+ 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()
@@ -3269,28 +3268,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);
-static void waitFor(const std::function<bool()> &func)
-{
- for (int i = 0; i < 100; i++)
- {
- if (func())
- return;
- QTest::qWait(10);
- }
-}
-
-void tst_QHeaderView::testMinMaxSectionSize(bool stretchLastSection)
-{
QStandardItemModel m(5, 5);
QTableView tv;
tv.setModel(&m);
@@ -3326,8 +3314,7 @@ void tst_QHeaderView::testMinMaxSectionSize(bool stretchLastSection)
header.resizeSection(0, sectionSizeMax);
QCOMPARE(header.sectionSize(0), sectionSizeMax);
header.setMaximumSectionSize(defaultSectionSize);
- waitFor([&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);
@@ -3335,8 +3322,7 @@ void tst_QHeaderView::testMinMaxSectionSize(bool stretchLastSection)
header.resizeSection(0, sectionSizeMin);
QCOMPARE(header.sectionSize(0), sectionSizeMin);
header.setMinimumSectionSize(defaultSectionSize);
- waitFor([&header, defaultSectionSize]() { return header.sectionSize(0) == defaultSectionSize; });
- QCOMPARE(header.sectionSize(0), defaultSectionSize);
+ QTRY_COMPARE(header.sectionSize(0), defaultSectionSize);
}
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 347d2a81e6..4c637573d0 100644
--- a/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp
+++ b/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp
@@ -3464,6 +3464,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)
@@ -3487,12 +3488,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;
}
@@ -3515,11 +3519,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);
}
@@ -3553,11 +3555,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)));
}
@@ -3575,15 +3576,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;
@@ -3741,11 +3741,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);
@@ -3810,7 +3809,6 @@ void tst_QTreeView::task246536_scrollbarsNotWorking()
QTest::qWait(100);
o.count = 0;
tree.verticalScrollBar()->setValue(50);
- QTest::qWait(100);
QTRY_VERIFY(o.count > 0);
}
@@ -3826,7 +3824,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());
}
@@ -3863,7 +3861,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()));
@@ -3976,7 +3973,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);
@@ -4041,7 +4037,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);
}
@@ -4249,7 +4244,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());
}
@@ -4269,8 +4263,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 d0e6407283..321e4bcd0e 100644
--- a/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp
+++ b/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp
@@ -2026,7 +2026,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));
@@ -2981,7 +2980,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);
@@ -2991,7 +2990,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);
@@ -3088,7 +3086,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
@@ -3097,9 +3095,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()
@@ -3306,16 +3302,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);
}
@@ -3356,34 +3351,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);
}