diff options
author | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2020-01-15 01:00:59 +0100 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2020-01-15 10:14:05 +0100 |
commit | d14fd32d403bd8d120fbe92dae06e9cb187c01c8 (patch) | |
tree | fbcae21f765b48e0359f9fb303554172caa5a83c /tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp | |
parent | 96dea48c154e5971593582f92917db3b3f17c7fa (diff) | |
parent | 2cbc5f6f7ae8ba580126a7cafc1898377c2a2407 (diff) |
Merge remote-tracking branch 'origin/5.15' into dev
Conflicts:
tests/benchmarks/network/access/qnetworkreply/tst_qnetworkreply.cpp
tests/auto/network/access/spdy/tst_spdy.cpp
Change-Id: I3196c5f7b34f2ffc9ef1e690d02d5b9bb3270a74
Diffstat (limited to 'tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp')
-rw-r--r-- | tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp | 51 |
1 files changed, 46 insertions, 5 deletions
diff --git a/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp b/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp index 5ee25677bf..a7881b6983 100644 --- a/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp +++ b/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp @@ -506,29 +506,67 @@ void tst_QGuiApplication::keyboardModifiers() window->close(); } +/* + Compare actual against expected but ignore unset roles. + + Comparing palettes via operator== will compare all roles. +*/ +static bool palettesMatch(const QPalette &actual, const QPalette &expected) +{ + if (actual.resolve() != expected.resolve()) + return false; + + for (int i = 0; i < QPalette::NColorGroups; i++) { + for (int j = 0; j < QPalette::NColorRoles; j++) { + const auto g = QPalette::ColorGroup(i); + const auto r = QPalette::ColorRole(j); + if (expected.isBrushSet(g, r)) { + if (actual.brush(g, r) != expected.brush(g, r)) + return false; + } + } + } + return true; +} + void tst_QGuiApplication::palette() { + // Getting the palette before application construction should work + QPalette paletteBeforeAppConstruction = QGuiApplication::palette(); + // And should be reflected in the default constructed palette + QCOMPARE(paletteBeforeAppConstruction, QPalette()); + int argc = 1; char *argv[] = { const_cast<char*>("tst_qguiapplication") }; QGuiApplication app(argc, argv); + + // The same should be true after application construction + QCOMPARE(QGuiApplication::palette(), QPalette()); + + // The default application palette is not resolved + QVERIFY(!QGuiApplication::palette().resolve()); + QSignalSpy signalSpy(&app, SIGNAL(paletteChanged(QPalette))); QPalette oldPalette = QGuiApplication::palette(); QPalette newPalette = QPalette(Qt::red); QGuiApplication::setPalette(newPalette); - QCOMPARE(QGuiApplication::palette(), newPalette); + QVERIFY(palettesMatch(QGuiApplication::palette(), newPalette)); QCOMPARE(signalSpy.count(), 1); - QCOMPARE(signalSpy.at(0).at(0), QVariant(newPalette)); + QVERIFY(palettesMatch(signalSpy.at(0).at(0).value<QPalette>(), newPalette)); + QCOMPARE(QGuiApplication::palette(), QPalette()); QGuiApplication::setPalette(oldPalette); - QCOMPARE(QGuiApplication::palette(), oldPalette); + QVERIFY(palettesMatch(QGuiApplication::palette(), oldPalette)); QCOMPARE(signalSpy.count(), 2); - QCOMPARE(signalSpy.at(1).at(0), QVariant(oldPalette)); + QVERIFY(palettesMatch(signalSpy.at(1).at(0).value<QPalette>(), oldPalette)); + QCOMPARE(QGuiApplication::palette(), QPalette()); QGuiApplication::setPalette(oldPalette); - QCOMPARE(QGuiApplication::palette(), oldPalette); + QVERIFY(palettesMatch(QGuiApplication::palette(), oldPalette)); QCOMPARE(signalSpy.count(), 2); + QCOMPARE(QGuiApplication::palette(), QPalette()); } void tst_QGuiApplication::font() @@ -1073,6 +1111,9 @@ void tst_QGuiApplication::testSetPaletteAttribute() QGuiApplication::setPalette(palette); QVERIFY(QCoreApplication::testAttribute(Qt::AA_SetPalette)); + + QGuiApplication::setPalette(QPalette()); + QVERIFY(!QCoreApplication::testAttribute(Qt::AA_SetPalette)); } // Test that static functions do not crash if there is no application instance. |