add tests for project
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
#include <QCoreApplication>
|
||||
#include <QFileInfo>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonObject>
|
||||
#include <QPluginLoader>
|
||||
#include <QtTest>
|
||||
|
||||
#include "imetadataplugin.h"
|
||||
#include "iplugin.h"
|
||||
|
||||
struct PluginExpectation
|
||||
{
|
||||
QString path;
|
||||
QString id;
|
||||
};
|
||||
|
||||
class PluginMetadataTests : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit PluginMetadataTests(QList<PluginExpectation> plugins)
|
||||
: m_plugins(std::move(plugins))
|
||||
{
|
||||
}
|
||||
|
||||
private slots:
|
||||
void embeddedMetadataMatchesPluginContract()
|
||||
{
|
||||
for (const PluginExpectation &plugin : m_plugins) {
|
||||
QVERIFY2(QFileInfo::exists(plugin.path), qPrintable(plugin.path));
|
||||
|
||||
QPluginLoader loader(plugin.path);
|
||||
const QJsonObject metadata = loader.metaData();
|
||||
QVERIFY2(!metadata.isEmpty(), qPrintable(loader.errorString()));
|
||||
QCOMPARE(metadata.value(QStringLiteral("IID")).toString(), QString::fromLatin1(PluginInterface_iid));
|
||||
|
||||
const QJsonObject data = metadata.value(QStringLiteral("MetaData")).toObject();
|
||||
QVERIFY2(!data.isEmpty(), qPrintable(plugin.path));
|
||||
QCOMPARE(data.value(QStringLiteral("id")).toString(), plugin.id);
|
||||
QVERIFY(data.value(QStringLiteral("schemaVersion")).toInt() > 0);
|
||||
QVERIFY(data.value(QStringLiteral("sql")).isArray());
|
||||
QVERIFY(data.value(QStringLiteral("dependencies")).isArray());
|
||||
|
||||
const MetaDataPtr parsed = IMetaDataPlugin::loadBaseMetaData(metadata);
|
||||
QVERIFY(parsed);
|
||||
QCOMPARE(parsed->getId(), plugin.id);
|
||||
QCOMPARE(parsed->getSchemaVersion(), data.value(QStringLiteral("schemaVersion")).toInt());
|
||||
QCOMPARE(parsed->getSchemas().size(), data.value(QStringLiteral("sql")).toArray().size());
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
QList<PluginExpectation> m_plugins;
|
||||
};
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QCoreApplication app(argc, argv);
|
||||
if (argc < 3 || (argc - 1) % 2 != 0) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
QList<PluginExpectation> plugins;
|
||||
for (int index = 1; index < argc; index += 2) {
|
||||
plugins.append({QString::fromLocal8Bit(argv[index]), QString::fromLocal8Bit(argv[index + 1])});
|
||||
}
|
||||
|
||||
PluginMetadataTests tests(std::move(plugins));
|
||||
return QTest::qExec(&tests, 1, argv);
|
||||
}
|
||||
|
||||
#include "plugin_metadata_tests.moc"
|
||||
Reference in New Issue
Block a user