From 76b58be4b8495f488607639f012de227dc047102 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Wed, 6 Dec 2023 11:01:43 +0100 Subject: [PATCH] QIcon: don't rely on getting a null-icon in test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If a QPA-provided engine provides an "edit-cut" icon, then it won't be null. We cannot reliably test that the icon came from the fallback theme as the cacheKey of the icon doesn't change (the proxying to a different theme is handled internally by the QThemeIconEngine). That the cacheKey of a QIcon doesn't change even if the pixmaps we get from it change is not a problem in practice; QIcon is a named container for transient graphical assets that might change for reasons outside of Qt's control (such as color scheme, or display resolution). Change-Id: I695e8ad0c8f0aec7f17a2c242e64b615178b78b5 Reviewed-by: Tor Arne Vestbø --- tests/auto/gui/image/qicon/tst_qicon.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/auto/gui/image/qicon/tst_qicon.cpp b/tests/auto/gui/image/qicon/tst_qicon.cpp index d7fcd58a03e..f479a33625d 100644 --- a/tests/auto/gui/image/qicon/tst_qicon.cpp +++ b/tests/auto/gui/image/qicon/tst_qicon.cpp @@ -722,10 +722,16 @@ void tst_QIcon::fromTheme() QCOMPARE(i.availableSizes(), abIcon.availableSizes()); } - // Check that setting a fallback theme invalidates earlier lookups - QVERIFY(QIcon::fromTheme("edit-cut").isNull()); - QIcon::setFallbackThemeName("fallbacktheme"); - QVERIFY(!QIcon::fromTheme("edit-cut").isNull()); + // Setting or changing the fallback theme should invalidate earlier lookups. + // We can only test this if the system doesn't provide an icon, because once + // we got a valid icon, it will be cached, and even if we proxy to a different + // engine when a fallback theme is set, the cacheKey of the icon will be the + // same. + const QIcon editCut = QIcon::fromTheme("edit-cut"); + if (editCut.isNull()) { + QIcon::setFallbackThemeName("fallbacktheme"); + QVERIFY(!QIcon::fromTheme("edit-cut").isNull()); + } // Make sure setting the theme name clears the state QIcon::setThemeName("");