Commit ba6939fa authored by Nikolai Kosjar's avatar Nikolai Kosjar

Unit tests: Fix ProjectInfoGenerator.* tests

...by adapting to recent mime type changes:

    commit e8e46ab5
    Plugins: Fix that mimetype definition was not valid JSON

Change-Id: Iac416ab481814e4488fac4d818c51c647c1ec349
Reviewed-by: Eike Ziller's avatarEike Ziller <eike.ziller@qt.io>
parent c78ea5a7
......@@ -32,6 +32,7 @@
#include <utils/algorithm.h>
#include <utils/qtcassert.h>
#include <utils/stringutils.h>
#include <QCoreApplication>
#include <QDebug>
......@@ -631,26 +632,6 @@ static inline QString msgInvalidFormat(const char *key, const QString &content)
.arg(QLatin1String(key), content);
}
bool PluginSpec::readMultiLineString(const QJsonValue &value, QString *out)
{
QTC_ASSERT(out, return false);
if (value.isString()) {
*out = value.toString();
} else if (value.isArray()) {
QJsonArray array = value.toArray();
QStringList lines;
foreach (const QJsonValue &v, array) {
if (!v.isString())
return false;
lines.append(v.toString());
}
*out = lines.join(QLatin1Char('\n'));
} else {
return false;
}
return true;
}
/*!
\internal
*/
......@@ -735,7 +716,7 @@ bool PluginSpecPrivate::readMetaData(const QJsonObject &pluginMetaData)
copyright = value.toString();
value = metaData.value(QLatin1String(DESCRIPTION));
if (!value.isUndefined() && !PluginSpec::readMultiLineString(value, &description))
if (!value.isUndefined() && !Utils::readMultiLineString(value, &description))
return reportError(msgValueIsNotAString(DESCRIPTION));
value = metaData.value(QLatin1String(URL));
......@@ -749,7 +730,7 @@ bool PluginSpecPrivate::readMetaData(const QJsonObject &pluginMetaData)
category = value.toString();
value = metaData.value(QLatin1String(LICENSE));
if (!value.isUndefined() && !PluginSpec::readMultiLineString(value, &license))
if (!value.isUndefined() && !Utils::readMultiLineString(value, &license))
return reportError(msgValueIsNotAMultilineString(LICENSE));
value = metaData.value(QLatin1String(PLATFORM));
......
......@@ -131,8 +131,6 @@ public:
bool hasError() const;
QString errorString() const;
static bool readMultiLineString(const QJsonValue &value, QString *out);
private:
PluginSpec();
......
......@@ -28,8 +28,11 @@
#include "hostosinfo.h"
#include <utils/algorithm.h>
#include <utils/qtcassert.h>
#include <QDir>
#include <QJsonArray>
#include <QJsonValue>
#include <QRegularExpression>
#include <QSet>
......@@ -246,4 +249,24 @@ QTCREATOR_UTILS_EXPORT QString stripAccelerator(const QString &text)
return res;
}
QTCREATOR_UTILS_EXPORT bool readMultiLineString(const QJsonValue &value, QString *out)
{
QTC_ASSERT(out, return false);
if (value.isString()) {
*out = value.toString();
} else if (value.isArray()) {
QJsonArray array = value.toArray();
QStringList lines;
foreach (const QJsonValue &v, array) {
if (!v.isString())
return false;
lines.append(v.toString());
}
*out = lines.join(QLatin1Char('\n'));
} else {
return false;
}
return true;
}
} // namespace Utils
......@@ -28,6 +28,7 @@
#include "utils_global.h"
QT_BEGIN_NAMESPACE
class QJsonValue;
class QStringList;
QT_END_NAMESPACE
......@@ -53,6 +54,8 @@ QTCREATOR_UTILS_EXPORT QString withTildeHomePath(const QString &path);
// Removes first unescaped ampersand in text
QTCREATOR_UTILS_EXPORT QString stripAccelerator(const QString &text);
QTCREATOR_UTILS_EXPORT bool readMultiLineString(const QJsonValue &value, QString *out);
class QTCREATOR_UTILS_EXPORT AbstractMacroExpander
{
public:
......
......@@ -132,7 +132,7 @@ bool CorePlugin::initialize(const QStringList &arguments, QString *errorMessage)
const QJsonObject metaData = plugin->metaData();
const QJsonValue mimetypes = metaData.value("Mimetypes");
QString mimetypeString;
if (ExtensionSystem::PluginSpec::readMultiLineString(mimetypes, &mimetypeString))
if (Utils::readMultiLineString(mimetypes, &mimetypeString))
Utils::addMimeTypes(plugin->name() + ".mimetypes", mimetypeString.trimmed().toUtf8());
}
......
......@@ -32,6 +32,7 @@
#include <QString>
#include <utils/mimetypes/mimedatabase.h>
#include <utils/stringutils.h>
namespace MimeDataBaseUtilities
{
......@@ -47,9 +48,11 @@ bool addCppToolsMimeTypes()
if (file.open(QIODevice::ReadOnly)) {
auto doc = QJsonDocument::fromJson(file.readAll());
QJsonValue mimetypes = doc.object().value("Mimetypes");
if (!mimetypes.isString())
QString mimetypeString;
if (!Utils::readMultiLineString(mimetypes, &mimetypeString))
return false;
Utils::addMimeTypes(filePath, mimetypes.toString().trimmed().toUtf8());
Utils::addMimeTypes(filePath, mimetypeString.trimmed().toUtf8());
alreadyAdded = true;
return true;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment