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>
This commit is contained in:
Eike Ziller
2023-03-09 11:30:31 +01:00
parent 3859b70375
commit 87b5176fd2
7 changed files with 198 additions and 9 deletions

View File

@@ -229,10 +229,18 @@ expected_str<QList<ExampleItem *>> parseExamples(const FilePath &manifest,
if (!contents)
return make_unexpected(contents.error());
const FilePath path = manifest.parentDir();
return parseExamples(*contents, manifest, examplesInstallPath, demosInstallPath, examples);
}
expected_str<QList<ExampleItem *>> parseExamples(const QByteArray &manifestData,
const Utils::FilePath &manifestPath,
const FilePath &examplesInstallPath,
const FilePath &demosInstallPath,
const bool examples)
{
const FilePath path = manifestPath.parentDir();
QList<ExampleItem *> items;
QXmlStreamReader reader(*contents);
QXmlStreamReader reader(manifestData);
while (!reader.atEnd()) {
switch (reader.readNext()) {
case QXmlStreamReader::StartElement:
@@ -251,7 +259,7 @@ expected_str<QList<ExampleItem *>> parseExamples(const FilePath &manifest,
if (reader.hasError()) {
qDeleteAll(items);
return make_unexpected(QString("Could not parse file \"%1\" as XML document: %2:%3: %4")
.arg(manifest.toUserOutput())
.arg(manifestPath.toUserOutput())
.arg(reader.lineNumber())
.arg(reader.columnNumber())
.arg(reader.errorString()));

View File

@@ -3,6 +3,8 @@
#pragma once
#include "qtsupport_global.h"
#include <coreplugin/welcomepagehelper.h>
#include <utils/expected.h>
#include <utils/filepath.h>
@@ -11,7 +13,7 @@ namespace QtSupport::Internal {
enum InstructionalType { Example = 0, Demo, Tutorial };
class ExampleItem : public Core::ListItem
class QTSUPPORT_EXPORT ExampleItem : public Core::ListItem
{
public:
Utils::FilePath projectPath;
@@ -20,7 +22,6 @@ public:
Utils::FilePath mainFile; /* file to be visible after opening filesToOpen */
Utils::FilePaths dependencies;
InstructionalType type;
int difficulty = 0;
bool hasSourceCode = false;
bool isVideo = false;
bool isHighlighted = false;
@@ -29,10 +30,18 @@ public:
QStringList platforms;
};
Utils::expected_str<QList<ExampleItem *>> parseExamples(const Utils::FilePath &manifest,
const Utils::FilePath &examplesInstallPath,
const Utils::FilePath &demosInstallPath,
bool examples);
QTSUPPORT_EXPORT Utils::expected_str<QList<ExampleItem *>> parseExamples(
const Utils::FilePath &manifest,
const Utils::FilePath &examplesInstallPath,
const Utils::FilePath &demosInstallPath,
bool examples);
QTSUPPORT_EXPORT Utils::expected_str<QList<ExampleItem *>> parseExamples(
const QByteArray &manifestData,
const Utils::FilePath &manifestPath,
const Utils::FilePath &examplesInstallPath,
const Utils::FilePath &demosInstallPath,
bool examples);
} // namespace QtSupport::Internal