File indexing completed on 2024-04-28 15:59:43
0001 /* 0002 SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "../src/lib/ifopt/ifoptutil.cpp" 0008 0009 #include <QJsonDocument> 0010 #include <QJsonObject> 0011 #include <QTest> 0012 0013 #define s(x) QStringLiteral(x) 0014 0015 using namespace KPublicTransport; 0016 0017 class IfoptTest: public QObject 0018 { 0019 Q_OBJECT 0020 private Q_SLOTS: 0021 void testIsValid_data() 0022 { 0023 QTest::addColumn<QString>("ifopt"); 0024 QTest::addColumn<bool>("valid"); 0025 0026 QTest::newRow("empty") << QString() << false; 0027 QTest::newRow("quay") << s("de:08115:4512:5:B") << true; 0028 QTest::newRow("prefix") << s("hbg:de:08115:4512:2:1") << false; 0029 QTest::newRow("level") << s("de:08115:4512:1") << true; 0030 QTest::newRow("stop_place") << s("de:05315:11201") << true; 0031 QTest::newRow("admin_area") << s("de:05111") << false; 0032 QTest::newRow("country") << s("de") << false; 0033 0034 QTest::newRow("colons") << s("::::") << false; 0035 QTest::newRow("missing element") << s("de:08115::5:B") << false; 0036 QTest::newRow("missing country") << s(":05111:18995:2:2") << false; 0037 QTest::newRow("trailing colon") << s("de:05315:11201:") << false; 0038 QTest::newRow("too many elements") << s("de:08115:4512:2:1:42") << false; 0039 } 0040 0041 void testIsValid() 0042 { 0043 QFETCH(QString, ifopt); 0044 QFETCH(bool, valid); 0045 QCOMPARE(IfoptUtil::isValid(ifopt), valid); 0046 } 0047 0048 void testStopPlace() 0049 { 0050 QCOMPARE(IfoptUtil::stopPlace(s("de:08115:4512:5:B")), s("de:08115:4512")); 0051 QCOMPARE(IfoptUtil::stopPlace(s("de:08115:4512:5")), s("de:08115:4512")); 0052 QCOMPARE(IfoptUtil::stopPlace(s("de:08115:4512")), s("de:08115:4512")); 0053 } 0054 0055 void testIsSameStopPlace() 0056 { 0057 QVERIFY(IfoptUtil::isSameStopPlace(s("de:08115:4512:5:B"), s("de:08115:4512"))); 0058 QVERIFY(IfoptUtil::isSameStopPlace(s("de:08115:4512:5:B"), s("de:08115:4512:2:1"))); 0059 QVERIFY(!IfoptUtil::isSameStopPlace(s("de:08115:4512:5:B"), s("de:08115:4513:2:1"))); 0060 } 0061 0062 void testCountry() 0063 { 0064 QCOMPARE(IfoptUtil::country(s("de:08115:4512:5:B")), s("de")); 0065 } 0066 0067 void testMerge() 0068 { 0069 QCOMPARE(IfoptUtil::merge(s("de:08115:4512:5:B"), s("de:08115:4512")), s("de:08115:4512")); 0070 QCOMPARE(IfoptUtil::merge(s("de:08115:4512:5:B"), s("de:08115:4512:5:A")), s("de:08115:4512:5")); 0071 QCOMPARE(IfoptUtil::merge(s("de:08115:4512:5:B"), s("de:08115:4512:5")), s("de:08115:4512:5")); 0072 QCOMPARE(IfoptUtil::merge(s("de:08115:4512:5:B"), s("de:08115:4512:1:2")), s("de:08115:4512")); 0073 QCOMPARE(IfoptUtil::merge(s("de:08115:4512:5:B"), s("de:08115:4512:5:B")), s("de:08115:4512:5:B")); 0074 QCOMPARE(IfoptUtil::merge(s("de:08115:4512"), s("de:08115:4512")), s("de:08115:4512")); 0075 0076 QCOMPARE(IfoptUtil::merge(QString(), s("de:08115:4512")), s("de:08115:4512")); 0077 QCOMPARE(IfoptUtil::merge(s("de:08115:4512"), QString()), s("de:08115:4512")); 0078 } 0079 }; 0080 0081 QTEST_APPLESS_MAIN(IfoptTest) 0082 0083 #include "ifopttest.moc"