From c316712fb8792d651f8d4216e2de1b735867b95f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Lefebvre?= Date: Fri, 6 Dec 2024 13:19:03 +0100 Subject: [PATCH] Split auto test palettePropagation2() palettePropagation was a fairly long test function and was testing more than one thing at once. Split palettePropagation2() in two, creating the new auto test palettePropagation3() that verify if the text color propagation is correctly being ignored when setting a new palette for buttons. This was previously tested in palettePropagation2(). palettePropagation2() now only tests if colors are propagated correctly. Both function are now shorter, easier to understand and maintain. Change-Id: Icdad272d4cdc437595c0a31ab231d134cb3b5d86 Reviewed-by: Richard Moe Gustavsen --- .../widgets/kernel/qwidget/tst_qwidget.cpp | 41 ++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp index 2ba860c22ee..251dd9c26c0 100644 --- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp +++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp @@ -163,6 +163,7 @@ private slots: void fontPropagationDynamic(); void palettePropagation(); void palettePropagation2(); + void palettePropagation3(); void palettePropagationDynamic(); void enabledPropagation(); void ignoreKeyEventsWhenDisabled_QTBUG27417(); @@ -1142,7 +1143,6 @@ void tst_QWidget::palettePropagation2() static constexpr QColor sysPalToolTipBase(12, 13, 14); static constexpr QColor overridePalText(42, 43, 44); static constexpr QColor overridePalToolTipBase(45, 46, 47); - static constexpr QColor sysPalButton(99, 98, 97); // Check that only the application fonts apply. const QPalette &appPal = QApplication::palette(); @@ -1179,6 +1179,37 @@ void tst_QWidget::palettePropagation2() else if (i <= 5) QCOMPARE(children.at(i)->palette().color(QPalette::ToolTipBase), overridePalToolTipBase); } +} + +void tst_QWidget::palettePropagation3() { + if (QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive)) + QSKIP("Wayland: This fails. Figure out why."); + + QWidget root; + root.setObjectName(QTest::currentTestFunction()); + root.setWindowTitle(root.objectName()); + root.resize(200, 200); + + QWidget *parent = &root; + static constexpr int propagationIndex = 2; + QWidgetList children; + for (int i = 0; i < 6; ++i) { + QWidget *w = (propagationIndex == i) ? new QPropagationTestWidget(parent) : new QWidget(parent); + w->setObjectName(QString("Widget-%1").arg(i)); + children << w; + parent = w; + } + + root.show(); + QVERIFY(QTest::qWaitForWindowExposed(&root)); + + // These colors are unlikely to be imposed on the default palette of + // QWidget ;-). + static constexpr QColor overridePalText(42, 43, 44); + static constexpr QColor overridePalToolTipBase(45, 46, 47); + static constexpr QColor sysPalButton(99, 98, 97); + + const QPalette &appPal = QApplication::palette(); // Replace the app palette for child2. Button should propagate but Text // should still be ignored. The previous ToolTipBase setting is gone. @@ -1190,6 +1221,14 @@ void tst_QWidget::palettePropagation2() waitForPolished(children); QCOMPARE(root.palette(), appPal); + // Set children.at(0)'s Text, and set ToolTipBase on children.at(4). + QPalette textPalette; + textPalette.setColor(QPalette::Text, overridePalText); + children.at(0)->setPalette(textPalette); + QPalette toolTipPalette; + toolTipPalette.setColor(QPalette::ToolTipBase, overridePalToolTipBase); + children.at(4)->setPalette(toolTipPalette); + for (int i = 0; i < children.count(); i++) { QCOMPARE(children.at(i)->palette().color(QPalette::Text), overridePalText); if (i <= 1)