File indexing completed on 2024-04-14 04:36:19

0001 /*
0002     SPDX-FileCopyrightText: 2023 Volker Krause <vkrause@kde.org>
0003     SPDX-License-Identifier: LGPL-2.0-or-later
0004 */
0005 
0006 #include <KPublicTransport/PlatformLayout>
0007 #include <KPublicTransport/Stopover>
0008 
0009 #include <QFile>
0010 #include <QJsonDocument>
0011 #include <QJsonObject>
0012 #include <QTest>
0013 
0014 #define s(x) QStringLiteral(x)
0015 
0016 using namespace KPublicTransport;
0017 
0018 class PlatformLayoutTest : public QObject
0019 {
0020     Q_OBJECT
0021 private Q_SLOTS:
0022     void testLayout()
0023     {
0024         QFile f(s(SOURCE_DIR "/data/deutschebahn/double-segment-ice-departure.json"));
0025         QVERIFY(f.open(QFile::ReadOnly));
0026         const auto stopover = Stopover::fromJson(QJsonDocument::fromJson(f.readAll()).object());
0027         QVERIFY(!stopover.platformLayout().sections().empty());
0028         QVERIFY(!stopover.vehicleLayout().sections().empty());
0029 
0030         PlatformLayout layout;
0031         QCOMPARE(layout.sectionsForVehicle(stopover), s("A-F"));
0032         QCOMPARE(layout.sectionsForClass(stopover, VehicleSection::SecondClass), s("A-F"));
0033         QCOMPARE(layout.sectionsForClass(stopover, VehicleSection::FirstClass), s("C-D,F"));
0034         QCOMPARE(layout.sectionsForVehicleSection(stopover, s("21")), s("A"));
0035         QCOMPARE(layout.sectionsForVehicleSection(stopover, s("32")), s("D-E"));
0036         QCOMPARE(layout.sectionsForVehicleSection(stopover, s("42")), QString());
0037     }
0038 };
0039 
0040 QTEST_GUILESS_MAIN(PlatformLayoutTest)
0041 
0042 #include "platformlayouttest.moc"