[education/labplot] tests/backend/core: Added a test to check the loading of all example projecs to make sure we don't break anything in the serialization/deserialization
Alexander Semke <[email protected]>
| Newsgroups | gmane.comp.kde.cvs |
|---|---|
| Message-ID | <[email protected]> |
Git commit 4cb516b9eeec08a331ebfcc3e04f540d1f9c0cdb by Alexander Semke. Committed on 10/08/2026 at 20:55. Pushed by asemke into branch 'master'. Added a test to check the loading of all example projecs to make sure we don't break anything in the serialization/deserialization logic for all aspects available in our examples. M +30 -1 tests/backend/core/AbstractAspectTest.cpp M +2 -0 tests/backend/core/AbstractAspectTest.h M +1 -0 tests/backend/core/CMakeLists.txt https://invent.kde.org/education/labplot/-/commit/4cb516b9eeec08a331ebfcc3e04f540d1f9c0cdb diff --git a/tests/backend/core/AbstractAspectTest.cpp b/tests/backend/core/AbstractAspectTest.cpp index 751778c7ff..59ce7e7351 100644 --- a/tests/backend/core/AbstractAspectTest.cpp +++ b/tests/backend/core/AbstractAspectTest.cpp @@ -4,7 +4,7 @@ Description : Tests for AbstractAspect -------------------------------------------------------------------- SPDX-FileCopyrightText: 2023 Martin Marmsoler <[email protected]> - SPDX-FileCopyrightText: 2023-2025 Alexander Semke <[email protected]> + SPDX-FileCopyrightText: 2023-2026 Alexander Semke <[email protected]> SPDX-License-Identifier: GPL-2.0-or-later */ @@ -23,6 +23,8 @@ #include "backend/lib/UndoStack.h" +#include <QDir> + void AbstractAspectTest::name() { Project project; @@ -963,4 +965,31 @@ void AbstractAspectTest::reparentPreservesOrder() { QCOMPARE(treeModel.data(treeModel.index(0, 0, projectIdx)).toString(), QStringLiteral("Folder")); } +/*! +* \brief AbstractAspectTest::loadExampleProjects + * Load all example projects in the examples directory and verify that they can be loaded without errors. +*/ +void AbstractAspectTest::loadExampleProjects() { + const QDir examplesDir(QStringLiteral(LABPLOT_DATA_DIR "/examples")); + QVERIFY2(examplesDir.exists(), "examples directory not found"); + + // collect .lml files from all subdirectories + QFileInfoList files; + QDirIterator it(examplesDir.absolutePath(), {QStringLiteral("*.lml")}, QDir::Files, QDirIterator::Subdirectories); + while (it.hasNext()) + files << QFileInfo(it.next()); + + QVERIFY2(!files.isEmpty(), "no .lml example files found"); + + for (const auto& fi : files) { + // skip project that require python or Maxima runtimes that are not available in the CI environment + if (fi.fileName() == QLatin1String("Seasonal Decomposition with STL and MSTL.lml") || fi.fileName() == QLatin1String("Maxima Tutorial for Beginners.lml")) + continue; + + Project project; + const bool ok = project.load(fi.absoluteFilePath()); + QVERIFY2(ok, qPrintable(QStringLiteral("failed to load: ") + fi.fileName())); + } +} + QTEST_MAIN(AbstractAspectTest) diff --git a/tests/backend/core/AbstractAspectTest.h b/tests/backend/core/AbstractAspectTest.h index b19fde44e9..b1113408ce 100644 --- a/tests/backend/core/AbstractAspectTest.h +++ b/tests/backend/core/AbstractAspectTest.h @@ -44,6 +44,8 @@ private Q_SLOTS: void reparentToNestedFolder(); void reparentFolder(); void reparentPreservesOrder(); + + void loadExampleProjects(); }; #endif // ABSTRACTASPECTTEST_H diff --git a/tests/backend/core/CMakeLists.txt b/tests/backend/core/CMakeLists.txt index f9aa4e84b0..ea2032d0cc 100644 --- a/tests/backend/core/CMakeLists.txt +++ b/tests/backend/core/CMakeLists.txt @@ -4,6 +4,7 @@ if(ENABLE_TEST_BACKEND_CORE) add_executable (AbstractAspectTest AbstractAspectTest.cpp) target_link_libraries(AbstractAspectTest labplotbackendlib labplotlib labplottest) + target_compile_definitions(AbstractAspectTest PRIVATE LABPLOT_DATA_DIR="${CMAKE_SOURCE_DIR}/data") add_test(NAME AbstractAspectTest COMMAND AbstractAspectTest) endif()