diff options
Diffstat (limited to 'tests/auto/widgets/widgets/qtabbar/tst_qtabbar.cpp')
-rw-r--r-- | tests/auto/widgets/widgets/qtabbar/tst_qtabbar.cpp | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/tests/auto/widgets/widgets/qtabbar/tst_qtabbar.cpp b/tests/auto/widgets/widgets/qtabbar/tst_qtabbar.cpp index 11effcfa93..bc1496d0f6 100644 --- a/tests/auto/widgets/widgets/qtabbar/tst_qtabbar.cpp +++ b/tests/auto/widgets/widgets/qtabbar/tst_qtabbar.cpp @@ -60,6 +60,10 @@ private slots: void removeTab_data(); void removeTab(); + void hideTab_data(); + void hideTab(); + void hideAllTabs(); + void setElideMode_data(); void setElideMode(); void sizeHints(); @@ -244,6 +248,73 @@ void tst_QTabBar::removeTab() QTEST(tabbar.currentIndex(), "finalIndex"); } +void tst_QTabBar::hideTab_data() +{ + QTest::addColumn<int>("currentIndex"); + QTest::addColumn<int>("hideIndex"); + QTest::addColumn<int>("spyCount"); + QTest::addColumn<int>("finalIndex"); + + QTest::newRow("hideEnd") << 0 << 2 << 0 << 0; + QTest::newRow("hideEndWithIndexOnEnd") << 2 << 2 << 1 << 1; + QTest::newRow("hideMiddle") << 2 << 1 << 0 << 2; + QTest::newRow("hideMiddleOnMiddle") << 1 << 1 << 1 << 2; + QTest::newRow("hideFirst") << 2 << 0 << 0 << 2; + QTest::newRow("hideFirstOnFirst") << 0 << 0 << 1 << 1; +} + +void tst_QTabBar::hideTab() +{ + QTabBar tabbar; + + QFETCH(int, currentIndex); + QFETCH(int, hideIndex); + tabbar.addTab("foo"); + tabbar.addTab("bar"); + tabbar.addTab("baz"); + tabbar.setCurrentIndex(currentIndex); + QSignalSpy spy(&tabbar, &QTabBar::currentChanged); + tabbar.setTabVisible(hideIndex, false); + QTEST(spy.count(), "spyCount"); + QTEST(tabbar.currentIndex(), "finalIndex"); +} + +void tst_QTabBar::hideAllTabs() +{ + QTabBar tabbar; + + tabbar.addTab("foo"); + tabbar.addTab("bar"); + tabbar.addTab("baz"); + tabbar.setCurrentIndex(0); + + // Check we don't crash trying to hide an unexistant tab + QSize prevSizeHint = tabbar.sizeHint(); + tabbar.setTabVisible(3, false); + QCOMPARE(tabbar.currentIndex(), 0); + QSize sizeHint = tabbar.sizeHint(); + QVERIFY(sizeHint.width() == prevSizeHint.width()); + prevSizeHint = sizeHint; + + tabbar.setTabVisible(1, false); + QCOMPARE(tabbar.currentIndex(), 0); + sizeHint = tabbar.sizeHint(); + QVERIFY(sizeHint.width() < prevSizeHint.width()); + prevSizeHint = sizeHint; + + tabbar.setTabVisible(2, false); + QCOMPARE(tabbar.currentIndex(), 0); + sizeHint = tabbar.sizeHint(); + QVERIFY(sizeHint.width() < prevSizeHint.width()); + prevSizeHint = sizeHint; + + tabbar.setTabVisible(0, false); + // We cannot set currentIndex < 0 + QCOMPARE(tabbar.currentIndex(), 0); + sizeHint = tabbar.sizeHint(); + QVERIFY(sizeHint.width() < prevSizeHint.width()); +} + void tst_QTabBar::setElideMode_data() { QTest::addColumn<int>("tabElideMode"); |