diff options
Diffstat (limited to 'tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp')
-rw-r--r-- | tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp | 48 |
1 files changed, 17 insertions, 31 deletions
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); } |