From cb4b29cc2a7b42bcb2dc2fb2cb4dbcb6867f2d48 Mon Sep 17 00:00:00 2001 From: Axel Spoerl Date: Mon, 31 Jan 2022 14:18:55 +0100 Subject: [PATCH] Extend baseline test for QTabWidget tabsClosable and documentMode added, merge conflict fixed Task-number: QTBUG-99773 Pick-to: 6.3 Change-Id: I8eb51b9f434bc97e6e7e55377801c6ee8aec52b0 Reviewed-by: Volker Hilsheimer --- .../baseline/widgets/tst_baseline_widgets.cpp | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/tests/baseline/widgets/tst_baseline_widgets.cpp b/tests/baseline/widgets/tst_baseline_widgets.cpp index 5ab4d484bd8..6760e9c03b5 100644 --- a/tests/baseline/widgets/tst_baseline_widgets.cpp +++ b/tests/baseline/widgets/tst_baseline_widgets.cpp @@ -65,6 +65,9 @@ private slots: void tst_QTabBar_data(); void tst_QTabBar(); + + void tst_QTabWidget_data(); + void tst_QTabWidget(); }; void tst_Widgets::tst_QSlider_data() @@ -531,6 +534,88 @@ void tst_Widgets::tst_QTabBar() } } +void tst_Widgets::tst_QTabWidget_data() +{ + QTest::addColumn("tabPosition"); + QTest::addColumn("numberTabs"); + QTest::addColumn("tabText"); + QTest::addColumn("fixedWidth"); + QTest::addColumn("isClosable"); + QTest::addColumn("isDocumentMode"); + + // fixedWidth <0 will be interpreted as variable width + QTest::newRow("North_3_variableWidthDocMode") << QTabWidget::North << 3 << "This is a tab text" << -1 << false << true; + QTest::newRow("East_3_variableWidth") << QTabWidget::East << 3 << "This is a tab text" << -1 << false << false; + QTest::newRow("West_3_variableWidthDocMode") << QTabWidget::West << 3 << "This is a tab text" << -1 << false << true; + QTest::newRow("South_3_variableWidth") << QTabWidget::South << 3 << "This is a tab text" << -1 << true << false; + QTest::newRow("North_20_fixedWidthDocMode") << QTabWidget::North << 20 + << "This is a very long text to actually force wrapping!" << 100 << true << true; + QTest::newRow("South_20_variableWidth") << QTabWidget::South << 20 + << "This is a very long text to actually force wrapping!" << -1 << false << false; +} + +void tst_Widgets::tst_QTabWidget() +{ + QFETCH(QTabWidget::TabPosition, tabPosition); + QFETCH(int, numberTabs); + QFETCH(QString, tabText); + QFETCH(int, fixedWidth); + QFETCH(bool, isClosable); + QFETCH(bool, isDocumentMode); + + QTabWidget tabWidget (testWindow()); + if (fixedWidth > 0) + tabWidget.setFixedWidth(fixedWidth); + tabWidget.setTabPosition(tabPosition); + tabWidget.setTabsClosable(isClosable); + tabWidget.setDocumentMode(isDocumentMode); + + for (int i = 0; i < numberTabs; ++i) { + QLabel *tabLabel = new QLabel("Tab number " + QString::number(i) + "\n" + tabText, &tabWidget); + QBoxLayout *tabBox = new QBoxLayout(QBoxLayout::TopToBottom,&tabWidget); + tabBox->addWidget(tabLabel); + tabWidget.insertTab(i,tabLabel,"Tab_" + QString::number(i)); + tabWidget.setCurrentIndex(i); + tabWidget.currentWidget()->setLayout(tabBox); + } + + tabWidget.setCurrentIndex(0); + QBoxLayout box(QBoxLayout::LeftToRight, testWindow()); + box.addWidget(&tabWidget); + testWindow()->setLayout(&box); + takeStandardSnapshots(); + + // press/release on second tab if it exists + if (numberTabs > 1) { + const QPoint clickTarget = tabWidget.tabBar()->tabRect(1).center(); + QTest::mousePress(tabWidget.tabBar(),Qt::MouseButton::LeftButton,Qt::KeyboardModifiers(), clickTarget,0); + QBASELINE_CHECK_DEFERRED(takeSnapshot(), "pressSecondTab"); + QTest::mouseRelease(tabWidget.tabBar(),Qt::MouseButton::LeftButton, Qt::KeyboardModifiers(), clickTarget,0); + QVERIFY(tabWidget.currentIndex() == 1); + } + + // test press/release on close button + if (isClosable) { + + // CloseButton is either left or right + QWidget *leftButton = tabWidget.tabBar()->tabButton(tabWidget.currentIndex(),QTabBar::ButtonPosition::LeftSide); + QWidget *rightButton = tabWidget.tabBar()->tabButton(tabWidget.currentIndex(),QTabBar::ButtonPosition::RightSide); + QAbstractButton *button = qobject_cast(leftButton); + if (button == nullptr) + button = qobject_cast(rightButton); + + if (button != nullptr) { + const QPoint clickTarget = button->rect().center(); + QTest::mousePress(button,Qt::MouseButton::LeftButton, + Qt::KeyboardModifiers(), clickTarget,0); + QBASELINE_CHECK_DEFERRED(takeSnapshot(), "pressCloseTab"); + QTest::mouseRelease(button,Qt::MouseButton::LeftButton, + Qt::KeyboardModifiers(), clickTarget,0); + QBASELINE_CHECK_DEFERRED(takeSnapshot(), "releaseCloseTab"); + } + } +} + #define main _realmain QTEST_MAIN(tst_Widgets) #undef main