diff options
author | Eike Ziller <eike.ziller@qt.io> | 2023-03-09 11:30:31 +0100 |
---|---|---|
committer | Eike Ziller <eike.ziller@qt.io> | 2023-04-13 07:14:05 +0000 |
commit | 9144ab75f41d54b907e323586dbc303400dc0327 (patch) | |
tree | c17f211a32bf82337faffab6757c2a0d9893cf09 /tests | |
parent | ac17e0e2ad47f16c80eb233725c4a603f6053acb (diff) |
Add test for examples parsing
Change-Id: Id2ec8afcdbdff97e12b32b836c955552589081c4
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
(cherry picked from commit 87b5176fd23b749d13fef81e65db09939b446e4f)
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/auto/auto.qbs | 1 | ||||
-rw-r--r-- | tests/auto/examples/CMakeLists.txt | 5 | ||||
-rw-r--r-- | tests/auto/examples/examples.qbs | 9 | ||||
-rw-r--r-- | tests/auto/examples/tst_examples.cpp | 156 |
5 files changed, 172 insertions, 0 deletions
diff --git a/tests/auto/CMakeLists.txt b/tests/auto/CMakeLists.txt index c71cbafdb2d..98ee3458965 100644 --- a/tests/auto/CMakeLists.txt +++ b/tests/auto/CMakeLists.txt @@ -6,6 +6,7 @@ add_subdirectory(cplusplus) add_subdirectory(debugger) add_subdirectory(diff) add_subdirectory(environment) +add_subdirectory(examples) add_subdirectory(extensionsystem) add_subdirectory(externaltool) add_subdirectory(filesearch) diff --git a/tests/auto/auto.qbs b/tests/auto/auto.qbs index af173fa9f09..2ff98d14097 100644 --- a/tests/auto/auto.qbs +++ b/tests/auto/auto.qbs @@ -12,6 +12,7 @@ Project { "debugger/debugger.qbs", "diff/diff.qbs", "environment/environment.qbs", + "examples/examples.qbs", "extensionsystem/extensionsystem.qbs", "externaltool/externaltool.qbs", "filesearch/filesearch.qbs", diff --git a/tests/auto/examples/CMakeLists.txt b/tests/auto/examples/CMakeLists.txt new file mode 100644 index 00000000000..cf8d1e4191e --- /dev/null +++ b/tests/auto/examples/CMakeLists.txt @@ -0,0 +1,5 @@ +add_qtc_test(tst_examples + DEPENDS Utils Core QtSupport + SOURCES tst_examples.cpp +) + diff --git a/tests/auto/examples/examples.qbs b/tests/auto/examples/examples.qbs new file mode 100644 index 00000000000..39cacc395fa --- /dev/null +++ b/tests/auto/examples/examples.qbs @@ -0,0 +1,9 @@ +import qbs + +QtcAutotest { + name: "Examples autotest" + Depends { name: "Core" } + Depends { name: "QtSupport" } + Depends { name: "Utils" } + files: "tst_examples.cpp" +} diff --git a/tests/auto/examples/tst_examples.cpp b/tests/auto/examples/tst_examples.cpp new file mode 100644 index 00000000000..22236ed4c5d --- /dev/null +++ b/tests/auto/examples/tst_examples.cpp @@ -0,0 +1,156 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +#include <utils/filepath.h> +#include <qtsupport/examplesparser.h> + +#include <QtTest> + +using namespace Utils; +using namespace QtSupport::Internal; + +class tst_Examples : public QObject +{ + Q_OBJECT + +public: + tst_Examples(); + ~tst_Examples(); + +private slots: + void parsing_data(); + void parsing(); +}; + +tst_Examples::tst_Examples() = default; +tst_Examples::~tst_Examples() = default; + +static ExampleItem fetchItem() +{ + QFETCH(QString, name); + QFETCH(QString, description); + QFETCH(QString, imageUrl); + QFETCH(QStringList, tags); + QFETCH(FilePath, projectPath); + QFETCH(QString, docUrl); + QFETCH(FilePaths, filesToOpen); + QFETCH(FilePath, mainFile); + QFETCH(FilePaths, dependencies); + QFETCH(InstructionalType, type); + QFETCH(bool, hasSourceCode); + QFETCH(bool, isVideo); + QFETCH(bool, isHighlighted); + QFETCH(QString, videoUrl); + QFETCH(QString, videoLength); + QFETCH(QStringList, platforms); + ExampleItem item; + item.name = name; + item.description = description; + item.imageUrl = imageUrl; + item.tags = tags; + item.projectPath = projectPath; + item.docUrl = docUrl; + item.filesToOpen = filesToOpen; + item.mainFile = mainFile; + item.dependencies = dependencies; + item.type = type; + item.hasSourceCode = hasSourceCode; + item.isVideo = isVideo; + item.isHighlighted = isHighlighted; + item.videoUrl = videoUrl; + item.videoLength = videoLength; + item.platforms = platforms; + return item; +} + +void tst_Examples::parsing_data() +{ + QTest::addColumn<QByteArray>("data"); + QTest::addColumn<bool>("isExamples"); + QTest::addColumn<QString>("name"); + QTest::addColumn<QString>("description"); + QTest::addColumn<QString>("imageUrl"); + QTest::addColumn<QStringList>("tags"); + QTest::addColumn<FilePath>("projectPath"); + QTest::addColumn<QString>("docUrl"); + QTest::addColumn<FilePaths>("filesToOpen"); + QTest::addColumn<FilePath>("mainFile"); + QTest::addColumn<FilePaths>("dependencies"); + QTest::addColumn<InstructionalType>("type"); + QTest::addColumn<bool>("hasSourceCode"); + QTest::addColumn<bool>("isVideo"); + QTest::addColumn<bool>("isHighlighted"); + QTest::addColumn<QString>("videoUrl"); + QTest::addColumn<QString>("videoLength"); + QTest::addColumn<QStringList>("platforms"); + + QTest::addRow("example") + << QByteArray(R"raw( + <examples> + <example docUrl="qthelp://org.qt-project.qtwidgets.660/qtwidgets/qtwidgets-widgets-analogclock-example.html" + imageUrl="qthelp://org.qt-project.qtwidgets.660/qtwidgets/images/analogclock-example.png" + name="Analog Clock" projectPath="widgets/widgets/analogclock/CMakeLists.txt"> + <description><![CDATA[The Analog Clock example shows how to draw the contents of a custom widget.]]></description> + <tags>ios,widgets</tags> + <fileToOpen>widgets/widgets/analogclock/main.cpp</fileToOpen> + <fileToOpen>widgets/widgets/analogclock/analogclock.h</fileToOpen> + <fileToOpen mainFile="true">widgets/widgets/analogclock/analogclock.cpp</fileToOpen> + <meta> + <entry name="category">Graphics</entry> + <entry name="tags">widgets</entry> + </meta> + </example> + </examples> + )raw") << /*isExamples=*/true + << "Analog Clock" + << "The Analog Clock example shows how to draw the contents of a custom widget." + << "qthelp://org.qt-project.qtwidgets.660/qtwidgets/images/analogclock-example.png" + << QStringList{"ios", "widgets"} + << FilePath::fromUserInput("manifest/widgets/widgets/analogclock/CMakeLists.txt") + << "qthelp://org.qt-project.qtwidgets.660/qtwidgets/" + "qtwidgets-widgets-analogclock-example.html" + << FilePaths{FilePath::fromUserInput("manifest/widgets/widgets/analogclock/main.cpp"), + FilePath::fromUserInput("manifest/widgets/widgets/analogclock/analogclock.h"), + FilePath::fromUserInput( + "manifest/widgets/widgets/analogclock/analogclock.cpp")} + << FilePath::fromUserInput("manifest/widgets/widgets/analogclock/analogclock.cpp") + << FilePaths() << Example << true << false << false << "" + << "" << QStringList(); +} + +void tst_Examples::parsing() +{ + QFETCH(QByteArray, data); + QFETCH(bool, isExamples); + const ExampleItem expected = fetchItem(); + const expected_str<QList<ExampleItem *>> result + = parseExamples(data, + FilePath("manifest/examples-manifest.xml"), + FilePath("examples"), + FilePath("demos"), + isExamples); + QVERIFY(result); + QCOMPARE(result->size(), 1); + const ExampleItem item = *result->at(0); + QCOMPARE(item.name, expected.name); + QCOMPARE(item.description, expected.description); + QCOMPARE(item.imageUrl, expected.imageUrl); + QCOMPARE(item.tags, expected.tags); + QCOMPARE(item.projectPath, expected.projectPath); + QCOMPARE(item.docUrl, expected.docUrl); + QCOMPARE(item.filesToOpen, expected.filesToOpen); + QCOMPARE(item.mainFile, expected.mainFile); + QCOMPARE(item.dependencies, expected.dependencies); + QCOMPARE(item.type, expected.type); + QCOMPARE(item.hasSourceCode, expected.hasSourceCode); + QCOMPARE(item.isVideo, expected.isVideo); + QCOMPARE(item.isHighlighted, expected.isHighlighted); + QCOMPARE(item.videoUrl, expected.videoUrl); + QCOMPARE(item.videoLength, expected.videoLength); + QCOMPARE(item.platforms, expected.platforms); + qDeleteAll(*result); +} + +QTEST_APPLESS_MAIN(tst_Examples) + +#include "tst_examples.moc" |