// SPDX-FileCopyrightText: 2026 Matvey Shcherbinin // SPDX-License-Identifier: BSD-2-Clause // // The three appearance selectors that are not colours: the font, the icon theme // and the controls style. Each one is a thin layer over a setting, and the // point of checking them is where the layer is not thin - the font arithmetic // that has to go back to the desktop's font when a setting is cleared, and the // two defaults (the desktop controls style and "the desktop's own" for the rest) // that a blank setting has to mean. Nothing here opens a window: QGuiApplication // is as far as it goes. #include "core/theme/FontSelector.h" #include "core/theme/IconThemeSelector.h" #include "core/theme/StyleSelector.h" #include "koutnetsettings.h" #include #include #include #include using namespace koutnet; class AppearanceSelectorsTest : public QObject { Q_OBJECT private Q_SLOTS: void initTestCase() { // A settings file of this test's own rather than the user's, so a run // here never reads or writes what KOutNet keeps in ~/.config. QCoreApplication::setOrganizationName(QStringLiteral("koutnet.test")); QCoreApplication::setApplicationName(QStringLiteral("appearanceselectors")); QStandardPaths::setTestModeEnabled(true); } // A blank family and a zero size both mean "leave it alone", so the font // resolved from a base is the base itself and not a font with an empty // family. This is the whole of the reset path: clearing the settings has to // resolve back to the desktop's font rather than to a nameless one. void aBlankSettingLeavesTheBaseFontAlone() { QFont base(QStringLiteral("KOutNet Base"), 10); QCOMPARE(FontSelector::resolvedFont(base, QString(), 0), base); } // What is set is what is laid over the base: the family changes the family, // the size changes the size, and everything neither touches - the style, the // weight, the stretch - is the base's and is not lost. void whatIsSetIsLaidOverTheBase() { QFont base(QStringLiteral("KOutNet Base"), 10); base.setBold(true); const QFont familyOnly = FontSelector::resolvedFont(base, QStringLiteral("Serif"), 0); QCOMPARE(familyOnly.family(), QStringLiteral("Serif")); QCOMPARE(familyOnly.pointSize(), 10); QVERIFY(familyOnly.bold()); const QFont sizeOnly = FontSelector::resolvedFont(base, QString(), 14); QCOMPARE(sizeOnly.family(), QStringLiteral("KOutNet Base")); QCOMPARE(sizeOnly.pointSize(), 14); QVERIFY(sizeOnly.bold()); const QFont both = FontSelector::resolvedFont(base, QStringLiteral("Monospace"), 12); QCOMPARE(both.family(), QStringLiteral("Monospace")); QCOMPARE(both.pointSize(), 12); } // A fresh settings file is not customised, and clearing what was set goes // back to not being customised. That flag is what the reset row is shown // against, so it has to flip on the way in and back on the way out. void theFontGoesBackToTheDesktopWhenItIsCleared() { KOutNetSettings settings; FontSelector selector(&settings); QCOMPARE(selector.family(), QString()); QCOMPARE(selector.pointSize(), 0); QVERIFY(!selector.customised()); selector.setFamily(QStringLiteral("Serif")); QCOMPARE(selector.family(), QStringLiteral("Serif")); QVERIFY(selector.customised()); selector.setPointSize(13); QCOMPARE(selector.pointSize(), 13); selector.resetToSystem(); QCOMPARE(selector.family(), QString()); QCOMPARE(selector.pointSize(), 0); QVERIFY(!selector.customised()); } // apply() puts the resolved font on the application, which is the one thing // it is for. Checked through the application font rather than a window, // because there is no window. void applyPutsTheFontOnTheApplication() { KOutNetSettings settings; FontSelector selector(&settings); selector.setFamily(QStringLiteral("Serif")); QCOMPARE(QGuiApplication::font().family(), QStringLiteral("Serif")); selector.resetToSystem(); QVERIFY(QGuiApplication::font().family() != QStringLiteral("Serif")); } // The icon theme is the desktop's own until one is picked, and picking one // only writes it down: the list of names is read off the machine, so what it // holds depends on the machine and the test checks the shape rather than the // contents. void anIconThemeIsTheDesktopsUntilOneIsPicked() { KOutNetSettings settings; IconThemeSelector selector(&settings); QCOMPARE(selector.theme(), QString()); QVERIFY(!selector.customised()); selector.setTheme(QStringLiteral("breeze-dark")); QCOMPARE(selector.theme(), QStringLiteral("breeze-dark")); QVERIFY(selector.customised()); selector.resetToSystem(); QCOMPARE(selector.theme(), QString()); QVERIFY(!selector.customised()); // Sorted and free of repeats, whatever is installed: two equal names in // the list would be two rows in the settings page saying the same thing. const QStringList themes = selector.availableThemes(); QStringList sorted = themes; sorted.sort(Qt::CaseInsensitive); QCOMPARE(themes, sorted); QCOMPARE(themes.size(), QSet(themes.begin(), themes.end()).size()); } // The controls style defaults to the desktop one and, unlike the font, is // not applied by the selector: it is written down and read back by main.cpp // before the module loads, so setting it here only changes what is stored. void theControlsStyleDefaultsToTheDesktopOne() { KOutNetSettings settings; StyleSelector selector(&settings); QCOMPARE(selector.style(), QStringLiteral("org.kde.desktop")); selector.setStyle(QStringLiteral("Fusion")); QCOMPARE(selector.style(), QStringLiteral("Fusion")); // The desktop style is always on offer, whatever Qt has installed. QVERIFY(selector.availableStyles().contains(QStringLiteral("org.kde.desktop"))); // And the style the window is actually built out of is a real name, not // an empty string a page would draw a blank row for. QVERIFY(!selector.runningStyle().isEmpty()); } }; QTEST_MAIN(AppearanceSelectorsTest) #include "AppearanceSelectorsTest.moc"