summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAxel Spoerl <Axel.Spoerl@qt.io>2022-01-14 13:07:36 +0100
committerAxel Spoerl <Axel.Spoerl@qt.io>2022-03-17 19:29:48 +0100
commit6dd86d901f9eaf4cd4dac5b1d9e977eb2bed3feb (patch)
treea4aaf0857a3b3dc351ecff91ba9300106e64e919
parent447d8e465a3a1b7f89fa5e3ea2c730e99d26a623 (diff)
Add QTabBar test in tst_baseline_widgets
Task-number: QTBUG-99772 Change-Id: I501c8e5c8e3ee1a1d3ac2a36b12f51dab90c88c3 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> (cherry picked from commit 878aea36457a1c270586774e68e56acaef14950a) Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
-rw-r--r--tests/baseline/widgets/tst_baseline_widgets.cpp124
1 files changed, 124 insertions, 0 deletions
diff --git a/tests/baseline/widgets/tst_baseline_widgets.cpp b/tests/baseline/widgets/tst_baseline_widgets.cpp
index 31008b42f0..12ced99125 100644
--- a/tests/baseline/widgets/tst_baseline_widgets.cpp
+++ b/tests/baseline/widgets/tst_baseline_widgets.cpp
@@ -60,6 +60,12 @@ private slots:
void tst_QRadioButton_data();
void tst_QRadioButton();
+
+ void tst_QScrollBar_data();
+ void tst_QScrollBar();
+
+ void tst_QTabBar_data();
+ void tst_QTabBar();
};
void tst_Widgets::tst_QSlider_data()
@@ -424,6 +430,124 @@ void tst_Widgets::tst_QRadioButton()
QBASELINE_CHECK_DEFERRED(takeSnapshot(), "releaseChecked");
}
+void tst_Widgets::tst_QScrollBar_data()
+{
+ QTest::addColumn<Qt::Orientation>("orientation");
+
+ QTest::newRow("Horizontal") << Qt::Horizontal;
+ QTest::newRow("Vertical") << Qt::Vertical;
+}
+
+void tst_Widgets::tst_QScrollBar()
+{
+ QFETCH(Qt::Orientation, orientation);
+
+ QBoxLayout box((orientation == Qt::Vertical) ? QBoxLayout::LeftToRight
+ : QBoxLayout::TopToBottom);
+ QList<QScrollBar*> bars;
+ for (int i = 0; i < 4; ++i) {
+
+ QScrollBar *bar = new QScrollBar(testWindow());
+ (orientation == Qt::Vertical) ? bar->setFixedHeight(100)
+ : bar->setFixedWidth(100);
+
+ bar->setOrientation(orientation);
+ bar->setValue(i * 33);
+ box.addWidget(bar);
+ bars.append(bar);
+ }
+
+ testWindow()->setLayout(&box);
+ takeStandardSnapshots();
+
+ // press left/up of first bar
+ QScrollBar *bar = bars.at(0);
+ QStyleOptionSlider styleOption = qt_qscrollbarStyleOption(bar);
+ QPoint clickTarget = bar->style()->subControlRect(QStyle::CC_ScrollBar, &styleOption,
+ QStyle::SC_ScrollBarSubLine, bar).center();
+ QTest::mousePress(bar,Qt::MouseButton::LeftButton, Qt::KeyboardModifiers(), clickTarget,0);
+ QBASELINE_CHECK_DEFERRED(takeSnapshot(), "pressLeftUp");
+ QTest::mouseRelease(bar,Qt::MouseButton::LeftButton, Qt::KeyboardModifiers(), clickTarget,0);
+
+ // press slider of first bar
+ styleOption = qt_qscrollbarStyleOption(bar);
+ clickTarget = bar->style()->subControlRect(QStyle::CC_ScrollBar, &styleOption,
+ QStyle::SC_ScrollBarSlider, bar).center();
+ QTest::mousePress(bar,Qt::MouseButton::LeftButton, Qt::KeyboardModifiers(), clickTarget,0);
+ QVERIFY(bar->isSliderDown());
+ QBASELINE_CHECK_DEFERRED(takeSnapshot(), "pressSlider");
+ QTest::mouseRelease(bar,Qt::MouseButton::LeftButton, Qt::KeyboardModifiers(), clickTarget,0);
+
+ // Press AddPage up on first bar
+ clickTarget = bar->style()->subControlRect(QStyle::CC_ScrollBar, &styleOption,
+ QStyle::SC_ScrollBarAddPage, bar).center();
+ QTest::mousePress(bar,Qt::MouseButton::LeftButton, Qt::KeyboardModifiers(), clickTarget,0);
+ QBASELINE_CHECK_DEFERRED(takeSnapshot(), "pressAddPage");
+ QTest::mouseRelease(bar,Qt::MouseButton::LeftButton, Qt::KeyboardModifiers(), clickTarget,0);
+
+ // press SubPage of last bar
+ bar = bars.at(3);
+ styleOption = qt_qscrollbarStyleOption(bar);
+ clickTarget = bar->style()->subControlRect(QStyle::CC_ScrollBar, &styleOption,
+ QStyle::SC_ScrollBarAddLine, bar).center();
+ QTest::mousePress(bar,Qt::MouseButton::LeftButton, Qt::KeyboardModifiers(), clickTarget,0);
+ QBASELINE_CHECK_DEFERRED(takeSnapshot(), "pressRightDown");
+ QTest::mouseRelease(bar,Qt::MouseButton::LeftButton, Qt::KeyboardModifiers(), clickTarget,0);
+}
+
+void tst_Widgets::tst_QTabBar_data()
+{
+ QTest::addColumn<QTabBar::Shape>("shape");
+ QTest::addColumn<int>("numberTabs");
+ QTest::addColumn<int>("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