[plasma/union] /: autotests: Add a test that tests StylePackage loading
Arjen Hiemstra <[email protected]> Wed, 5 Aug 2026 10:33:24 +0000 (UTC)
| Newsgroups | gmane.comp.kde.cvs |
|---|---|
| Message-ID | <[email protected]> |
Git commit 4094cf0a6ee650535240223a25ec33359a03abe8 by Arjen Hiemstra. Committed on 05/08/2026 at 10:24. Pushed by ahiemstra into branch 'master'. autotests: Add a test that tests StylePackage loading It verifies that a correct package loads properly and also various error conditions that may occur. M +2 -0 .kde-ci.yml M +10 -0 REUSE.toml M +1 -0 autotests/CMakeLists.txt A +97 -0 autotests/TestStylePackage.cpp [License: LGPL(3+eV) LGPL(v3.0) LGPL(v2.1)] A +1 -0 autotests/TestStylePackageData/EmptyMetaDataStyle/contents/.gitkeep A +1 -0 autotests/TestStylePackageData/EmptyMetaDataStyle/metadata.json A +1 -0 autotests/TestStylePackageData/EmptyStyle/.gitkeep A +5 -0 autotests/TestStylePackageData/NoContentsStyle/metadata.json A +1 -0 autotests/TestStylePackageData/UnknownInputStyle/contents/.gitkeep A +3 -0 autotests/TestStylePackageData/UnknownInputStyle/metadata.json A +16 -0 autotests/TestStylePackageData/ValidTestStyle/contents/test/style.json A +11 -0 autotests/TestStylePackageData/ValidTestStyle/metadata.json https://invent.kde.org/plasma/union/-/commit/4094cf0a6ee650535240223a25ec33359a03abe8 diff --git a/.kde-ci.yml b/.kde-ci.yml index 9a4c12a7..0ebe31b7 100644 --- a/.kde-ci.yml +++ b/.kde-ci.yml @@ -17,3 +17,5 @@ Options: # Explicitly enable QtWidgets output to make sure we verify it builds cmake-options: "-DBUILD_OUTPUT_QTWIDGETS=ON" run-qmllint: true + json-validate-ignore: + - autotests/TestStylePackageData/EmptyMetaDataStyle/metadata.json diff --git a/REUSE.toml b/REUSE.toml index 525ae808..22e28657 100644 --- a/REUSE.toml +++ b/REUSE.toml @@ -32,3 +32,13 @@ SPDX-FileCopyrightText = "2026 Arjen Hiemstra <[email protected]>" path = "src/output/qtwidgets/Union.json" SPDX-License-Identifier = "BSD-2-Clause" SPDX-FileCopyrightText = "2025 Joshua Goins <[email protected]>" + +[[annotations]] +path = "**/.gitkeep" +SPDX-License-Identifier = "CC0-1.0" +SPDX-FileCopyrightText = "None" + +[[annotations]] +path = "autotests/TestStylePackageData/ValidTestStyle/contents/test/style.json" +SPDX-License-Identifier = "BSD-2-Clause" +SPDX-FileCopyrightText = "2026 Arjen Hiemstra <[email protected]>" diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt index ef385592..4f7f970d 100644 --- a/autotests/CMakeLists.txt +++ b/autotests/CMakeLists.txt @@ -9,6 +9,7 @@ ecm_add_tests( TestStyle.cpp TestStyleRegistry.cpp TestColor.cpp + TestStylePackage.cpp LINK_LIBRARIES Qt6::Test Union::Union ) diff --git a/autotests/TestStylePackage.cpp b/autotests/TestStylePackage.cpp new file mode 100644 index 00000000..f53e3471 --- /dev/null +++ b/autotests/TestStylePackage.cpp @@ -0,0 +1,97 @@ +// SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +// SPDX-FileCopyrightText: 2026 Arjen Hiemstra <[email protected]> + +#include <QtTest> + +#include <InputPlugin.h> +#include <Style.h> +#include <StyleLoader.h> +#include <StylePackage.h> + +#include "TestInputPlugin.h" + +using namespace Union; +using namespace Qt::StringLiterals; + +namespace fs = std::filesystem; + +class TestStylePackage : public QObject +{ + Q_OBJECT + + StylePackage makePackage(QStringView relativePath) + { + QString findPath = u"TestStylePackageData/"_s + relativePath; + return StylePackage{FINDTESTPATH(findPath)}; + } + +private Q_SLOTS: + void initTestCase() + { + InputPlugin::addInputType(u"test"_s, std::make_shared<TestInputPlugin>()); + } + + void testIsValid() + { + auto package = std::make_unique<StylePackage>(fs::path()); + QVERIFY(!package->isValid()); + QCOMPARE(package->error(), StylePackage::Error::NotFound); + + auto testPackage = [this](QStringView style, StylePackage::Error expectedError) { + auto package = makePackage(style); + if (expectedError == StylePackage::Error::None) { + QVERIFY(package.isValid()); + } else { + QVERIFY(!package.isValid()); + } + QCOMPARE(package.error(), expectedError); + }; + + testPackage(u"EmptyStyle", StylePackage::Error::MissingFiles); + testPackage(u"NoContentsStyle", StylePackage::Error::MissingFiles); + testPackage(u"EmptyMetaDataStyle", StylePackage::Error::InvalidMetaData); + testPackage(u"UnknownInputStyle", StylePackage::Error::UnknownInputType); + testPackage(u"ValidTestStyle", StylePackage::Error::None); + } + + void testMetaData() + { + auto package = makePackage(u"ValidTestStyle"); + + QVERIFY(package.isValid()); + + QCOMPARE(package.id(), u"ValidTestStyle"_s); + QCOMPARE(package.inputType(), u"test"_s); + QCOMPARE(package.name(), u"Valid Test Style"_s); + QCOMPARE(package.description(), u"A style used for testing that is completely valid."_s); + QCOMPARE(package.version(), u"1.0"_s); + QCOMPARE(package.license(), u"BSD-2-Clause"_s); + QCOMPARE(package.authors(), (QStringList{u"Test Author 1"_s, u"Test Author 2"_s})); + } + + void testLoad() + { + auto package = makePackage(u"ValidTestStyle"); + + auto style = package.load(); + QVERIFY(style); + QCOMPARE(style->path(), package.path()); + + package = makePackage(u"UnknownInputStyle"); + + style = package.load(); + QVERIFY(!style); + } + + void benchmarkValidate() + { + QBENCHMARK { + auto package = makePackage(u"ValidTestStyle"); + QVERIFY(package.isValid()); + } + } +}; + +QTEST_MAIN(TestStylePackage) + +#include "TestStylePackage.moc" diff --git a/autotests/TestStylePackageData/EmptyMetaDataStyle/contents/.gitkeep b/autotests/TestStylePackageData/EmptyMetaDataStyle/contents/.gitkeep new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/autotests/TestStylePackageData/EmptyMetaDataStyle/contents/.gitkeep @@ -0,0 +1 @@ + diff --git a/autotests/TestStylePackageData/EmptyMetaDataStyle/metadata.json b/autotests/TestStylePackageData/EmptyMetaDataStyle/metadata.json new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/autotests/TestStylePackageData/EmptyMetaDataStyle/metadata.json @@ -0,0 +1 @@ + diff --git a/autotests/TestStylePackageData/EmptyStyle/.gitkeep b/autotests/TestStylePackageData/EmptyStyle/.gitkeep new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/autotests/TestStylePackageData/EmptyStyle/.gitkeep @@ -0,0 +1 @@ + diff --git a/autotests/TestStylePackageData/NoContentsStyle/metadata.json b/autotests/TestStylePackageData/NoContentsStyle/metadata.json new file mode 100644 index 00000000..18b28543 --- /dev/null +++ b/autotests/TestStylePackageData/NoContentsStyle/metadata.json @@ -0,0 +1,5 @@ +{ + "input-type": "test", + "name": "Test Style Without Contents" +} + diff --git a/autotests/TestStylePackageData/UnknownInputStyle/contents/.gitkeep b/autotests/TestStylePackageData/UnknownInputStyle/contents/.gitkeep new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/autotests/TestStylePackageData/UnknownInputStyle/contents/.gitkeep @@ -0,0 +1 @@ + diff --git a/autotests/TestStylePackageData/UnknownInputStyle/metadata.json b/autotests/TestStylePackageData/UnknownInputStyle/metadata.json new file mode 100644 index 00000000..309b5771 --- /dev/null +++ b/autotests/TestStylePackageData/UnknownInputStyle/metadata.json @@ -0,0 +1,3 @@ +{ + "input-type": "unknown" +} diff --git a/autotests/TestStylePackageData/ValidTestStyle/contents/test/style.json b/autotests/TestStylePackageData/ValidTestStyle/contents/test/style.json new file mode 100644 index 00000000..84628dee --- /dev/null +++ b/autotests/TestStylePackageData/ValidTestStyle/contents/test/style.json @@ -0,0 +1,16 @@ +{ + "rules": [ + { + "selectors": [ + { "type": "test" } + ], + "background-color": "red" + }, + { + "selectors": [ + { "id": "test" } + ], + "background-color": "blue" + } + ] +} diff --git a/autotests/TestStylePackageData/ValidTestStyle/metadata.json b/autotests/TestStylePackageData/ValidTestStyle/metadata.json new file mode 100644 index 00000000..2b6dddf0 --- /dev/null +++ b/autotests/TestStylePackageData/ValidTestStyle/metadata.json @@ -0,0 +1,11 @@ +{ + "input-type": "test", + "name": "Valid Test Style", + "description": "A style used for testing that is completely valid.", + "version": "1.0", + "license": "BSD-2-Clause", + "authors": [ + "Test Author 1", + "Test Author 2" + ] +}