From 878aea36457a1c270586774e68e56acaef14950a Mon Sep 17 00:00:00 2001 From: Axel Spoerl Date: Fri, 14 Jan 2022 13:07:36 +0100 Subject: Add QTabBar test in tst_baseline_widgets Task-number: QTBUG-99772 Pick-to: 6.3 Change-Id: I501c8e5c8e3ee1a1d3ac2a36b12f51dab90c88c3 Reviewed-by: Volker Hilsheimer --- tests/baseline/widgets/tst_baseline_widgets.cpp | 56 +++++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'tests/baseline') diff --git a/tests/baseline/widgets/tst_baseline_widgets.cpp b/tests/baseline/widgets/tst_baseline_widgets.cpp index 4522e42563..d49e9b494f 100644 --- a/tests/baseline/widgets/tst_baseline_widgets.cpp +++ b/tests/baseline/widgets/tst_baseline_widgets.cpp @@ -62,6 +62,9 @@ private slots: void tst_QScrollBar_data(); void tst_QScrollBar(); + + void tst_QTabBar_data(); + void tst_QTabBar(); }; void tst_Widgets::tst_QSlider_data() @@ -451,6 +454,59 @@ void tst_Widgets::tst_QScrollBar() QTest::mouseRelease(bar,Qt::MouseButton::LeftButton, Qt::KeyboardModifiers(), clickTarget,0); } +void tst_Widgets::tst_QTabBar_data() +{ + QTest::addColumn("shape"); + QTest::addColumn("numberTabs"); + QTest::addColumn("fixedWidth"); + + // fixedWidth <0 will be interpreted as variable width + QTest::newRow("RoundedNorth_3_variableWidth") << QTabBar::RoundedNorth << 3 << -1; + QTest::newRow("RoundedEast_3_variableWidth") << QTabBar::RoundedEast << 3 << -1; + QTest::newRow("RoundedWest_3_variableWidth") << QTabBar::RoundedWest << 3 << -1; + QTest::newRow("RoundedSouth_3_variableWidth") << QTabBar::RoundedSouth << 3 << -1; + QTest::newRow("RoundedNorth_20_fixedWidth") << QTabBar::RoundedNorth << 20 << 250; +} + +void tst_Widgets::tst_QTabBar() +{ + QFETCH(QTabBar::Shape, shape); + QFETCH(int, numberTabs); + QFETCH(int, fixedWidth); + + QTabBar bar (testWindow()); + bar.setShape(shape); + if (fixedWidth > 0) + bar.setFixedWidth(fixedWidth); + + for (int i = 0; i < numberTabs; ++i) { + bar.insertTab(i,"Tab_" + QString::number(i)); + } + + QBoxLayout box(QBoxLayout::LeftToRight, testWindow()); + box.addWidget(&bar); + testWindow()->setLayout(&box); + + takeStandardSnapshots(); + + // press/release first tab + bar.setCurrentIndex(0); + QPoint clickTarget = bar.tabRect(0).center(); + QTest::mousePress(&bar,Qt::MouseButton::LeftButton, Qt::KeyboardModifiers(), clickTarget,0); + QBASELINE_CHECK_DEFERRED(takeSnapshot(), "pressFirstTab"); + QTest::mouseRelease(&bar,Qt::MouseButton::LeftButton, Qt::KeyboardModifiers(), clickTarget,0); + QVERIFY(bar.currentIndex() == 0); + + // press/release second tab if it exists + if (bar.count() > 1) { + clickTarget = bar.tabRect(1).center(); + QTest::mousePress(&bar,Qt::MouseButton::LeftButton, Qt::KeyboardModifiers(), clickTarget,0); + QBASELINE_CHECK_DEFERRED(takeSnapshot(), "pressSecondTab"); + QTest::mouseRelease(&bar,Qt::MouseButton::LeftButton, Qt::KeyboardModifiers(), clickTarget,0); + QVERIFY(bar.currentIndex() == 1); + } +} + #define main _realmain QTEST_MAIN(tst_Widgets) #undef main -- cgit v1.2.3