summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/widgets/qtabwidget/tst_qtabwidget.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/widgets/widgets/qtabwidget/tst_qtabwidget.cpp')
-rw-r--r--tests/auto/widgets/widgets/qtabwidget/tst_qtabwidget.cpp123
1 files changed, 81 insertions, 42 deletions
diff --git a/tests/auto/widgets/widgets/qtabwidget/tst_qtabwidget.cpp b/tests/auto/widgets/widgets/qtabwidget/tst_qtabwidget.cpp
index 0e7012482d..d7bfdfaad2 100644
--- a/tests/auto/widgets/widgets/qtabwidget/tst_qtabwidget.cpp
+++ b/tests/auto/widgets/widgets/qtabwidget/tst_qtabwidget.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
@@ -85,6 +60,7 @@ private slots:
void tabPosition();
void tabEnabled();
void tabHidden();
+ void checkHiddenTab();
void tabText();
void tabShape();
void tabTooltip();
@@ -104,6 +80,9 @@ private slots:
void moveCurrentTab();
void autoHide();
+ void setCurrentBeforeShow_data();
+ void setCurrentBeforeShow();
+
private:
int addPage();
void removePage(int index);
@@ -274,6 +253,32 @@ void tst_QTabWidget::tabHidden()
}
}
+void tst_QTabWidget::checkHiddenTab()
+{
+ tw->addTab(new QWidget(), "foo");
+ tw->addTab(new QWidget(), "bar");
+ tw->addTab(new QWidget(), "baz");
+ QCOMPARE(tw->count(), 3);
+ tw->setCurrentIndex(0);
+ tw->setTabVisible(1, false);
+
+ QKeyEvent keyTab(QKeyEvent::KeyPress, Qt::Key_Tab, Qt::ControlModifier);
+ QVERIFY(QApplication::sendEvent(tw, &keyTab));
+ QCOMPARE(tw->currentIndex(), 2);
+ QVERIFY(QApplication::sendEvent(tw, &keyTab));
+ QCOMPARE(tw->currentIndex(), 0);
+ QVERIFY(QApplication::sendEvent(tw, &keyTab));
+ QCOMPARE(tw->currentIndex(), 2);
+
+ QKeyEvent keyBacktab(QKeyEvent::KeyPress, Qt::Key_Backtab, Qt::ControlModifier);
+ QVERIFY(QApplication::sendEvent(tw, &keyBacktab));
+ QCOMPARE(tw->currentIndex(), 0);
+ QVERIFY(QApplication::sendEvent(tw, &keyBacktab));
+ QCOMPARE(tw->currentIndex(), 2);
+ QVERIFY(QApplication::sendEvent(tw, &keyBacktab));
+ QCOMPARE(tw->currentIndex(), 0);
+}
+
void tst_QTabWidget::tabText()
{
// Test bad arguments
@@ -383,12 +388,12 @@ void tst_QTabWidget::currentIndex()
QCOMPARE(tw->currentIndex(), -1);
tw->setCurrentIndex(-1);
QCOMPARE(tw->currentIndex(), -1);
- QCOMPARE(spy.count(), 0);
+ QCOMPARE(spy.size(), 0);
int firstIndex = addPage();
tw->setCurrentIndex(firstIndex);
QCOMPARE(tw->currentIndex(), firstIndex);
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
QList<QVariant> arguments = spy.takeFirst();
QCOMPARE(arguments.at(0).toInt(), firstIndex);
@@ -396,19 +401,19 @@ void tst_QTabWidget::currentIndex()
QCOMPARE(tw->currentIndex(), firstIndex);
tw->setCurrentIndex(index);
QCOMPARE(tw->currentIndex(), index);
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
arguments = spy.takeFirst();
QCOMPARE(arguments.at(0).toInt(), index);
removePage(index);
QCOMPARE(tw->currentIndex(), firstIndex);
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
arguments = spy.takeFirst();
QCOMPARE(arguments.at(0).toInt(), firstIndex);
removePage(firstIndex);
QCOMPARE(tw->currentIndex(), -1);
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
arguments = spy.takeFirst();
QCOMPARE(arguments.at(0).toInt(), -1);
}
@@ -689,8 +694,8 @@ void tst_QTabWidget::tabBarClicked()
QSignalSpy clickSpy(&tabWidget, SIGNAL(tabBarClicked(int)));
QSignalSpy doubleClickSpy(&tabWidget, SIGNAL(tabBarDoubleClicked(int)));
- QCOMPARE(clickSpy.count(), 0);
- QCOMPARE(doubleClickSpy.count(), 0);
+ QCOMPARE(clickSpy.size(), 0);
+ QCOMPARE(doubleClickSpy.size(), 0);
QTabBar &tabBar = *tabWidget.tabBar();
Qt::MouseButton button = Qt::LeftButton;
@@ -698,27 +703,27 @@ void tst_QTabWidget::tabBarClicked()
const QPoint tabPos = tabBar.tabRect(0).center();
QTest::mouseClick(&tabBar, button, {}, tabPos);
- QCOMPARE(clickSpy.count(), 1);
+ QCOMPARE(clickSpy.size(), 1);
QCOMPARE(clickSpy.takeFirst().takeFirst().toInt(), 0);
- QCOMPARE(doubleClickSpy.count(), 0);
+ QCOMPARE(doubleClickSpy.size(), 0);
QTest::mouseDClick(&tabBar, button, {}, tabPos);
- QCOMPARE(clickSpy.count(), 1);
+ QCOMPARE(clickSpy.size(), 1);
QCOMPARE(clickSpy.takeFirst().takeFirst().toInt(), 0);
- QCOMPARE(doubleClickSpy.count(), 1);
+ QCOMPARE(doubleClickSpy.size(), 1);
QCOMPARE(doubleClickSpy.takeFirst().takeFirst().toInt(), 0);
const QPoint barPos(tabBar.tabRect(0).right() + 5, tabBar.tabRect(0).center().y());
QTest::mouseClick(&tabBar, button, {}, barPos);
- QCOMPARE(clickSpy.count(), 1);
+ QCOMPARE(clickSpy.size(), 1);
QCOMPARE(clickSpy.takeFirst().takeFirst().toInt(), -1);
- QCOMPARE(doubleClickSpy.count(), 0);
+ QCOMPARE(doubleClickSpy.size(), 0);
QTest::mouseDClick(&tabBar, button, {}, barPos);
- QCOMPARE(clickSpy.count(), 1);
+ QCOMPARE(clickSpy.size(), 1);
QCOMPARE(clickSpy.takeFirst().takeFirst().toInt(), -1);
- QCOMPARE(doubleClickSpy.count(), 1);
+ QCOMPARE(doubleClickSpy.size(), 1);
QCOMPARE(doubleClickSpy.takeFirst().takeFirst().toInt(), -1);
button = Qt::MouseButton(button << 1);
@@ -775,5 +780,39 @@ void tst_QTabWidget::autoHide()
QVERIFY(heightForWidth1 > tabWidget.heightForWidth(20));
}
+void tst_QTabWidget::setCurrentBeforeShow_data()
+{
+ QTest::addColumn<QTabWidget::TabPosition>("tabPosition");
+ QTest::newRow("West") << QTabWidget::West;
+ QTest::newRow("North") << QTabWidget::North;
+ QTest::newRow("East") << QTabWidget::East;
+ QTest::newRow("South") << QTabWidget::South;
+}
+
+void tst_QTabWidget::setCurrentBeforeShow()
+{
+ QFETCH(QTabWidget::TabPosition, tabPosition);
+
+ QTabWidget tabWidget;
+ tabWidget.setTabPosition(tabPosition);
+
+ QPixmap pm(50, 50);
+ pm.fill(Qt::red);
+ const QIcon icon(pm);
+ for (int i = 0; i < 4; ++i)
+ tabWidget.addTab(new QWidget, icon, QString("Tab %1").arg(i));
+
+ // the tab widget has space for the entire tab bar
+ tabWidget.resize(tabWidget.tabBar()->sizeHint() + QSize(50, 50));
+ tabWidget.setCurrentIndex(2);
+ tabWidget.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&tabWidget));
+
+ QCOMPARE_GE(tabWidget.tabBar()->tabRect(0).x(), 0);
+ QCOMPARE_GE(tabWidget.tabBar()->tabRect(0).y(), 0);
+
+ QTest::qWait(2000);
+}
+
QTEST_MAIN(tst_QTabWidget)
#include "tst_qtabwidget.moc"