Commit c008f748 authored by Volker Krause's avatar Volker Krause
Browse files

Split post-processing and validation tests

So we can eventually remove the legacy validation support in
post-processing.
parent b72c0fb8
......@@ -63,6 +63,52 @@ private Q_SLOTS:
v.setAcceptedTypes();
QVERIFY(v.isValidElement(input.at(0)));
}
void testFilter_data()
{
QTest::addColumn<QString>("preFile");
QTest::addColumn<QString>("postFile");
QDir dir(QStringLiteral(SOURCE_DIR "/validationdata"));
const auto lst = dir.entryList(QStringList(QStringLiteral("*.pre.json")), QDir::Files | QDir::Readable | QDir::NoSymLinks);
for (const auto &file : lst) {
const QString refFile = dir.path() + QLatin1Char('/') + file.left(file.size() - 8) + QStringLiteral("post.json");
if (!QFile::exists(refFile)) {
qDebug() << "reference file" << refFile << "does not exist, skipping test file" << file;
continue;
}
QTest::newRow(file.toLatin1().constData()) << QString(dir.path() + QLatin1Char('/') + file) << refFile;
}
}
void testFilter()
{
QFETCH(QString, preFile);
QFETCH(QString, postFile);
QFile f(preFile);
QVERIFY(f.open(QFile::ReadOnly));
const auto inArray = QJsonDocument::fromJson(f.readAll()).array();
QVERIFY(!inArray.isEmpty());
auto preData = JsonLdDocument::fromJson(inArray);
QCOMPARE(inArray.size(), preData.size());
ExtractorValidator validator;
preData.erase(std::remove_if(preData.begin(), preData.end(), [&validator](const auto &elem) {
return !validator.isValidElement(elem);
}), preData.end());
const auto outArray = JsonLdDocument::toJson(preData);
QFile ref(postFile);
QVERIFY(ref.open(QFile::ReadOnly));
const auto refArray = QJsonDocument::fromJson(ref.readAll()).array();
if (outArray != refArray) {
qDebug().noquote() << QJsonDocument(outArray).toJson();
}
QCOMPARE(refArray.size(), outArray.size());
QCOMPARE(outArray, refArray);
}
};
QTEST_GUILESS_MAIN(ExtractorValidatorTest)
......
......@@ -67,6 +67,7 @@ private Q_SLOTS:
QCOMPARE(inArray.size(), preData.size());
ExtractorPostprocessor postproc;
postproc.setValidationEnabled(false);
postproc.setContextDate({QDate(2018, 4, 2), QTime()});
postproc.process(preData);
const auto outArray = JsonLdDocument::toJson(postproc.result());
......
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