Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit a1efa7a7 authored by Volker Krause's avatar Volker Krause

Add unit test for merging reservation objects

parent 7bbf9b13
[{
"@context": "http://schema.org",
"@type": "Flight",
"airline": {
"@type": "Airline",
"name": "Lufthansa",
"iataCode": "LH"
}
}]
[{
"@context": "http://schema.org",
"@type": "Airline",
"@type": "Flight",
"airline": {
"@type": "Airline",
"name": "Lufthansa",
"iataCode": "LH"
}
}]
[{
"@context": "http://schema.org",
"@type": "Airline",
"@type": "Flight",
"airline": {
"@type": "Airline",
"name": "LH",
"iataCode": "LH"
}
}]
[{
"@context": "http://schema.org",
"@type": "Flight",
"arrivalTime": {
"@type": "QDateTime",
"@value": "2019-02-01T19:45:00+01:00",
"timezone": "Europe/Brussels"
}
}]
[{
"@context": "http://schema.org",
"@type": "Flight",
"arrivalTime": {
"@type": "QDateTime",
"@value": "2019-02-01T19:45:00+01:00",
"timezone": "Europe/Brussels"
}
}]
[{
"@context": "http://schema.org",
"@type": "Flight",
"arrivalTime": "2019-02-01T19:45+0200"
}]
......@@ -16,12 +16,17 @@
*/
#include <KItinerary/Flight>
#include <KItinerary/JsonLdDocument>
#include <KItinerary/MergeUtil>
#include <KItinerary/Organization>
#include <KItinerary/Person>
#include <KItinerary/Reservation>
#include <QDebug>
#include <QFile>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QObject>
#include <QTest>
......@@ -32,6 +37,14 @@ using namespace KItinerary;
class MergeUtilTest : public QObject
{
Q_OBJECT
private:
QByteArray readFile(const QString &fn) const
{
QFile f(fn);
f.open(QFile::ReadOnly);
return f.readAll();
}
private Q_SLOTS:
void testIsSameReservation()
{
......@@ -227,6 +240,35 @@ private Q_SLOTS:
res2.setReservationFor(hotel2);
QVERIFY(MergeUtil::isSame(res1, res2));
}
void testMerge_data()
{
QTest::addColumn<QString>("baseName");
QDir dir(QStringLiteral(SOURCE_DIR "/mergedata"));
const auto lst = dir.entryList(QStringList(QStringLiteral("*.merged.json")), QDir::Files | QDir::Readable | QDir::NoSymLinks);
for (const auto &file : lst) {
const auto base = file.left(file.size() - 12);
QTest::newRow(base.toLatin1().constData()) << (dir.path() + QLatin1Char('/') + base);
}
}
void testMerge()
{
QFETCH(QString, baseName);
const auto lhs = JsonLdDocument::fromJson(QJsonDocument::fromJson(readFile(baseName + QLatin1String(".lhs.json"))).array()).first();
const auto rhs = JsonLdDocument::fromJson(QJsonDocument::fromJson(readFile(baseName + QLatin1String(".rhs.json"))).array()).first();
const auto expected = QJsonDocument::fromJson(readFile(baseName + QLatin1String(".merged.json")));
const auto mergedL2R = MergeUtil::merge(lhs, rhs);
//qDebug().noquote() << QJsonDocument(JsonLdDocument::toJson({mergedL2R})).toJson();
QCOMPARE(QJsonDocument(JsonLdDocument::toJson({mergedL2R})), expected);
const auto mergedR2L = MergeUtil::merge(rhs, lhs);
//qDebug().noquote() << QJsonDocument(JsonLdDocument::toJson({mergedR2L})).toJson();
QCOMPARE(QJsonDocument(JsonLdDocument::toJson({mergedR2L})), expected);
}
};
QTEST_APPLESS_MAIN(MergeUtilTest)
......
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