[graphics/digikam] core/tests/widgets: Add ThemeManager unit test
Andreas Winther <[email protected]>
| Newsgroups | gmane.comp.kde.cvs |
|---|---|
| Message-ID | <[email protected]> |
Git commit ddb444176203c321542d87e867a184b468bca150 by Andreas Winther.
Committed on 18/07/2026 at 21:28.
Pushed by cgilles into branch 'master'.
Add ThemeManager unit test
Cover the public API contract that every method must be safe to call
before a theme menu has been registered with setThemeMenuAction().
Without the guard from the previous commit, updateThemeMenu() in that
state crashes with a null dereference of themeMenuActionGroup inside
updateCurrentDesktopDefaultThemePreview(), which this test catches as
a SIGSEGV. Also cover the default-theme fallback once a menu is
registered.
M +1 -0 core/tests/widgets/CMakeLists.txt
A +63 -0 core/tests/widgets/thememanager_utest.cpp [License: GPL(v2.0+)]
A +36 -0 core/tests/widgets/thememanager_utest.h [License: GPL(v2.0+)]
https://invent.kde.org/graphics/digikam/-/commit/ddb444176203c321542d87e867a184b468bca150
diff --git a/core/tests/widgets/CMakeLists.txt b/core/tests/widgets/CMakeLists.txt
index 249f9c97c4..a4f7a9a68f 100644
--- a/core/tests/widgets/CMakeLists.txt
+++ b/core/tests/widgets/CMakeLists.txt
@@ -13,6 +13,7 @@ include_directories(
##################################################################
ecm_add_tests(${CMAKE_CURRENT_SOURCE_DIR}/searchtextbar_utest.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/thememanager_utest.cpp
NAME_PREFIX
diff --git a/core/tests/widgets/thememanager_utest.cpp b/core/tests/widgets/thememanager_utest.cpp
new file mode 100644
index 0000000000..7741cf6950
--- /dev/null
+++ b/core/tests/widgets/thememanager_utest.cpp
@@ -0,0 +1,63 @@
+/* ============================================================
+ *
+ * This file is a part of digiKam project
+ * https://www.digikam.org
+ *
+ * Date : 2026-07-18
+ * Description : a test for the theme manager
+ *
+ * SPDX-FileCopyrightText: 2026 by Andreas Winther <git dot tumble747 at simplelogin dot com>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ *
+ * ============================================================ */
+
+#include "thememanager_utest.h"
+
+// Qt includes
+
+#include <QMenu>
+#include <QTest>
+
+// Local includes
+
+#include "thememanager.h"
+
+using namespace Digikam;
+
+QTEST_MAIN(ThemeManagerTest)
+
+ThemeManagerTest::ThemeManagerTest(QObject* const parent)
+ : QObject(parent)
+{
+}
+
+void ThemeManagerTest::testCallsBeforeMenuRegistration()
+{
+ ThemeManager* const tm = ThemeManager::instance();
+
+ // Every public method must be safe to call before a theme menu
+ // has been registered with setThemeMenuAction().
+
+ QCOMPARE(tm->currentThemeName(), tm->defaultThemeName());
+
+ tm->setCurrentTheme(QLatin1String("Does Not Exist"));
+ QCOMPARE(tm->currentThemeName(), tm->defaultThemeName());
+
+ tm->updateThemeMenu();
+ QCOMPARE(tm->currentThemeName(), tm->defaultThemeName());
+}
+
+void ThemeManagerTest::testAfterMenuRegistration()
+{
+ ThemeManager* const tm = ThemeManager::instance();
+ QMenu menu;
+
+ tm->setThemeMenuAction(&menu);
+
+ QCOMPARE(tm->currentThemeName(), tm->defaultThemeName());
+ QVERIFY(!menu.actions().isEmpty());
+
+ tm->updateThemeMenu();
+ QCOMPARE(tm->currentThemeName(), tm->defaultThemeName());
+}
diff --git a/core/tests/widgets/thememanager_utest.h b/core/tests/widgets/thememanager_utest.h
new file mode 100644
index 0000000000..8d75487b30
--- /dev/null
+++ b/core/tests/widgets/thememanager_utest.h
@@ -0,0 +1,36 @@
+/* ============================================================
+ *
+ * This file is a part of digiKam project
+ * https://www.digikam.org
+ *
+ * Date : 2026-07-18
+ * Description : a test for the theme manager
+ *
+ * SPDX-FileCopyrightText: 2026 by Andreas Winther <git dot tumble747 at simplelogin dot com>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ *
+ * ============================================================ */
+
+#ifndef DIGIKAM_THEME_MANAGER_UTEST_H
+#define DIGIKAM_THEME_MANAGER_UTEST_H
+
+// Qt includes
+
+#include <QObject>
+
+class ThemeManagerTest : public QObject
+{
+ Q_OBJECT
+
+public:
+
+ explicit ThemeManagerTest(QObject* const parent = nullptr);
+
+private Q_SLOTS:
+
+ void testCallsBeforeMenuRegistration();
+ void testAfterMenuRegistration();
+};
+
+#endif // DIGIKAM_THEME_MANAGER_UTEST_H