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

Add basic unit test for vehicle position interpolation

parent 2902d6c0
Pipeline #52984 passed with stage
in 25 seconds
......@@ -21,6 +21,7 @@ ecm_add_test(notestest.cpp LINK_LIBRARIES Qt5::Test KPublicTransport)
ecm_add_test(backendtest.cpp LINK_LIBRARIES Qt5::Test KPublicTransport)
ecm_add_test(linemetadatatest.cpp LINK_LIBRARIES Qt5::Test KPublicTransport)
ecm_add_test(networkconfigtest.cpp LINK_LIBRARIES Qt5::Test)
ecm_add_test(vehiclelayoutquerymodeltest.cpp LINK_LIBRARIES Qt5::Test KPublicTransport)
ecm_add_test(navitiaparsertest.cpp LINK_LIBRARIES Qt5::Test KPublicTransport)
ecm_add_test(hafasmgateparsertest.cpp LINK_LIBRARIES Qt5::Test KPublicTransport)
......
/*
SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include <KPublicTransport/Manager>
#include <KPublicTransport/Stopover>
#include <KPublicTransport/VehicleLayoutQueryModel>
#include <QAbstractItemModelTester>
#include <QFile>
#include <QJsonDocument>
#include <QJsonObject>
#include <QSignalSpy>
#include <QTest>
using namespace KPublicTransport;
class VehicleLayoutQueryModelTest : public QObject
{
Q_OBJECT
private:
QByteArray readFile(const QString &fn)
{
QFile f(fn);
f.open(QFile::ReadOnly);
return f.readAll();
}
private Q_SLOTS:
void testCoachPositionInterpolation()
{
Manager ptMgr;
VehicleLayoutQueryModel model;
QAbstractItemModelTester modelTest(&model);
model.setManager(&ptMgr);
QSignalSpy resetSpy(&model, &QAbstractItemModel::modelReset);
const auto inVec = Vehicle::fromJson(QJsonDocument::fromJson(readFile(QStringLiteral(SOURCE_DIR "/data/hafas/rem-I-JF-sbb-ic-train-formation-bern-vehicle.json"))).object());
QCOMPARE(inVec.sections().size(), 10);
QVERIFY(!inVec.hasPlatformPositions());
QVERIFY(inVec.hasPlatformSectionNames());
const auto inPlat = Platform::fromJson(QJsonDocument::fromJson(readFile(QStringLiteral(SOURCE_DIR "/data/hafas/rem-I-XP-sbb-platform-bern.json"))).object());
QVERIFY(!inPlat.sections().empty());
Stopover s;
s.setVehicleLayout(inVec);
s.setPlatformLayout(inPlat);
s.setScheduledDepartureTime(QDateTime::currentDateTime());
Line line;
line.setName(QStringLiteral("IC 8"));
Route route;
route.setLine(line);
s.setRoute(route);
VehicleLayoutRequest req(s);
QVERIFY(req.isValid());
model.setRequest(req);
QVERIFY(resetSpy.wait(10)); // query is started, initial requested data is set
QCOMPARE(model.rowCount(), 10);
resetSpy.clear();
QVERIFY(resetSpy.wait(10)); // query finished, interpolation is triggered
QCOMPARE(model.rowCount(), 10);
for (int i = 0; i < model.rowCount(); ++i) {
const auto idx = model.index(i, 0);
const auto sec = idx.data(VehicleLayoutQueryModel::VehicleSectionRole).value<VehicleSection>();
QVERIFY(sec.hasPlatformPosition());
}
}
};
QTEST_GUILESS_MAIN(VehicleLayoutQueryModelTest)
#include "vehiclelayoutquerymodeltest.moc"
......@@ -51,7 +51,7 @@ public:
};
Q_ENUM(Roles)
int rowCount(const QModelIndex &parent) const override;
int rowCount(const QModelIndex &parent = {}) const override;
QVariant data(const QModelIndex &index, int role) const override;
QHash<int, QByteArray> roleNames() const override;
Q_SIGNALS:
......
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