Skip to content

Commit

Permalink
Split auto test palettePropagation2()
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Frédéric Lefebvre committed Dec 16, 2024
1 parent 54d47f8 commit c316712
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ private slots:
void fontPropagationDynamic();
void palettePropagation();
void palettePropagation2();
void palettePropagation3();
void palettePropagationDynamic();
void enabledPropagation();
void ignoreKeyEventsWhenDisabled_QTBUG27417();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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.
Expand All @@ -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)
Expand Down

0 comments on commit c316712

Please sign in to comment.