summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/widgets')
-rw-r--r--tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp26
-rw-r--r--tests/auto/widgets/widgets/qtabbar/tst_qtabbar.cpp71
-rw-r--r--tests/auto/widgets/widgets/qtabwidget/tst_qtabwidget.cpp25
3 files changed, 110 insertions, 12 deletions
diff --git a/tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp b/tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp
index dcb932de66..67d8764b61 100644
--- a/tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp
+++ b/tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp
@@ -177,8 +177,9 @@ void tst_QListWidget::moveRowsInvalid_data()
result->addItems({"A", "B", "C", "D", "E", "F"});
return result;
};
+ constexpr int rowCount = 6;
- QTest::addRow("destination_equal_source") << createWidget() << QModelIndex() << 0 << 1 << QModelIndex() << 1;
+ QTest::addRow("destination_equal_source") << createWidget() << QModelIndex() << 0 << 1 << QModelIndex() << 0;
QTest::addRow("count_equal_0") << createWidget() << QModelIndex() << 0 << 0 << QModelIndex() << 2;
QListWidget* tempWidget = createWidget();
QTest::addRow("move_child") << tempWidget << tempWidget->model()->index(0, 0) << 0 << 1 << QModelIndex() << 2;
@@ -187,10 +188,11 @@ void tst_QListWidget::moveRowsInvalid_data()
QTest::addRow("negative_count") << createWidget() << QModelIndex() << 0 << -1 << QModelIndex() << 2;
QTest::addRow("negative_source_row") << createWidget() << QModelIndex() << -1 << 1 << QModelIndex() << 2;
QTest::addRow("negative_destination_row") << createWidget() << QModelIndex() << 0 << 1 << QModelIndex() << -1;
- QTest::addRow("source_row_equal_rowCount") << createWidget() << QModelIndex() << 6 << 1 << QModelIndex() << 1;
- QTest::addRow("destination_row_greater_rowCount") << createWidget() << QModelIndex() << 0 << 1 << QModelIndex() << 6 + 1;
+ QTest::addRow("source_row_equal_rowCount") << createWidget() << QModelIndex() << rowCount << 1 << QModelIndex() << 1;
+ QTest::addRow("source_row_equal_destination_row") << createWidget() << QModelIndex() << 2 << 1 << QModelIndex() << 2;
+ QTest::addRow("source_row_equal_destination_row_plus1") << createWidget() << QModelIndex() << 2 << 1 << QModelIndex() << 3;
+ QTest::addRow("destination_row_greater_rowCount") << createWidget() << QModelIndex() << 0 << 1 << QModelIndex() << rowCount + 1;
QTest::addRow("move_row_within_source_range") << createWidget() << QModelIndex() << 0 << 3 << QModelIndex() << 2;
- QTest::addRow("destination_row_before_0") << createWidget() << QModelIndex() << 1 << 1 << QModelIndex() << 0;
}
void tst_QListWidget::moveRowsInvalid()
@@ -221,20 +223,20 @@ void tst_QListWidget::moveRows_data()
QTest::newRow("1_Item_from_top_to_middle") << 0 << 1 << 3 << QStringList{"B", "C", "A", "D", "E", "F"};
QTest::newRow("1_Item_from_top_to_bottom") << 0 << 1 << 6 << QStringList{"B", "C", "D", "E", "F", "A"};
- QTest::newRow("1_Item_from_middle_to_top") << 2 << 1 << 1 << QStringList{"C", "A", "B", "D", "E", "F"};
- QTest::newRow("1_Item_from_bottom_to_middle") << 5 << 1 << 3 << QStringList{"A", "B", "F", "C", "D", "E"};
- QTest::newRow("1_Item_from_bottom to_top") << 5 << 1 << 1 << QStringList{"F", "A", "B", "C", "D", "E"};
+ QTest::newRow("1_Item_from_middle_to_top") << 2 << 1 << 0 << QStringList{"C", "A", "B", "D", "E", "F"};
+ QTest::newRow("1_Item_from_bottom_to_middle") << 5 << 1 << 2 << QStringList{"A", "B", "F", "C", "D", "E"};
+ QTest::newRow("1_Item_from_bottom to_top") << 5 << 1 << 0 << QStringList{"F", "A", "B", "C", "D", "E"};
QTest::newRow("1_Item_from_middle_to_bottom") << 2 << 1 << 6 << QStringList{"A", "B", "D", "E", "F", "C"};
- QTest::newRow("1_Item_from_middle_to_middle_before") << 2 << 1 << 1 << QStringList{"C", "A", "B", "D", "E", "F"};
+ QTest::newRow("1_Item_from_middle_to_middle_before") << 2 << 1 << 1 << QStringList{"A", "C", "B", "D", "E", "F"};
QTest::newRow("1_Item_from_middle_to_middle_after") << 2 << 1 << 4 << QStringList{"A", "B", "D", "C", "E", "F"};
QTest::newRow("2_Items_from_top_to_middle") << 0 << 2 << 3 << QStringList{"C", "A", "B", "D", "E", "F"};
QTest::newRow("2_Items_from_top_to_bottom") << 0 << 2 << 6 << QStringList{"C", "D", "E", "F", "A", "B"};
- QTest::newRow("2_Items_from_middle_to_top") << 2 << 2 << 1 << QStringList{"C", "D", "A", "B", "E", "F"};
- QTest::newRow("2_Items_from_bottom_to_middle") << 4 << 2 << 3 << QStringList{"A", "B", "E", "F", "C", "D"};
- QTest::newRow("2_Items_from_bottom_to_top") << 4 << 2 << 1 << QStringList{"E", "F", "A", "B", "C", "D"};
+ QTest::newRow("2_Items_from_middle_to_top") << 2 << 2 << 0 << QStringList{"C", "D", "A", "B", "E", "F"};
+ QTest::newRow("2_Items_from_bottom_to_middle") << 4 << 2 << 2 << QStringList{"A", "B", "E", "F", "C", "D"};
+ QTest::newRow("2_Items_from_bottom_to_top") << 4 << 2 << 0 << QStringList{"E", "F", "A", "B", "C", "D"};
QTest::newRow("2_Items_from_middle_to_bottom") << 2 << 2 << 6 << QStringList{"A", "B", "E", "F", "C", "D"};
- QTest::newRow("2_Items_from_middle_to_middle_before") << 3 << 2 << 2 << QStringList{"A", "D", "E", "B", "C", "F"};
+ QTest::newRow("2_Items_from_middle_to_middle_before") << 3 << 2 << 1 << QStringList{"A", "D", "E", "B", "C", "F"};
QTest::newRow("2_Items_from_middle_to_middle_after") << 1 << 2 << 5 << QStringList{"A", "D", "E", "B", "C", "F"};
}
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");
diff --git a/tests/auto/widgets/widgets/qtabwidget/tst_qtabwidget.cpp b/tests/auto/widgets/widgets/qtabwidget/tst_qtabwidget.cpp
index ec550b445c..28b8bfc6b3 100644
--- a/tests/auto/widgets/widgets/qtabwidget/tst_qtabwidget.cpp
+++ b/tests/auto/widgets/widgets/qtabwidget/tst_qtabwidget.cpp
@@ -81,6 +81,7 @@ private slots:
void addRemoveTab();
void tabPosition();
void tabEnabled();
+ void tabHidden();
void tabText();
void tabShape();
void tabTooltip();
@@ -246,6 +247,30 @@ void tst_QTabWidget::tabEnabled()
removePage(index);
}
+void tst_QTabWidget::tabHidden()
+{
+ // Test bad arguments
+ QVERIFY(!tw->isTabVisible(-1));
+ tw->setTabVisible(-1, false);
+ QVERIFY(!tw->isTabVisible(tw->count()));
+ tw->setTabVisible(tw->count(), false);
+
+ const int index = addPage();
+
+ tw->setTabVisible(index, true);
+ QVERIFY(tw->isTabVisible(index));
+ tw->setTabVisible(index, false);
+ QVERIFY(!tw->isTabVisible(index));
+ tw->setTabVisible(index, true);
+ QVERIFY(tw->isTabVisible(index));
+
+ removePage(index);
+
+ for (int i = 0; i < tw->count(); ++i) {
+ QVERIFY(tw->isTabVisible(i));
+ }
+}
+
void tst_QTabWidget::tabText()
{
// Test bad arguments