File indexing completed on 2024-12-01 04:19:21
0001 /* 0002 SPDX-FileCopyrightText: 2020 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include <map/loader/levelparser_p.h> 0008 0009 #include <osm/element.h> 0010 0011 #include <QTest> 0012 0013 using namespace KOSMIndoorMap; 0014 0015 class LevelParserTest: public QObject 0016 { 0017 Q_OBJECT 0018 using LV = QVector<int>; 0019 private Q_SLOTS: 0020 void testLevelParse_data() 0021 { 0022 QTest::addColumn<QString>("input"); 0023 QTest::addColumn<LV>("levels"); 0024 0025 QTest::newRow("empty") << "" << LV{}; 0026 QTest::newRow("0") << "0" << LV{0}; 0027 QTest::newRow("1") << "1" << LV{10}; 0028 QTest::newRow("-1") << "-1" << LV{-10}; 0029 0030 QTest::newRow("-1;0") << "-1;0" << LV{-10,0}; 0031 QTest::newRow("0.5") << "0.5" << LV{5}; 0032 QTest::newRow("0.5;0.7") << "0.5;0.7" << LV{5,7}; 0033 QTest::newRow("0;-1") << "0;-1" << LV{0,-10}; 0034 0035 QTest::newRow("1-3") << "1-3" << LV{10,20,30}; 0036 QTest::newRow("-1-5") << "-1-5" << LV{-10,0,10,20,30,40,50}; 0037 QTest::newRow("-4--2") << "-4--2" << LV{-40,-30,-20}; 0038 QTest::newRow("0-6") << "0-6" << LV{0,10,20,30,40,50,60}; 0039 0040 QTest::newRow("0;2-3") << "0;2-3" << LV{0,20,30}; 0041 QTest::newRow("0;2-3;5") << "0;2-3;5" << LV{0,20,30,50}; 0042 0043 // invalid but we have workarounds for this 0044 QTest::newRow("1,5") << "1,5" << LV{15}; 0045 } 0046 0047 void testLevelParse() 0048 { 0049 QFETCH(QString, input); 0050 QFETCH(LV, levels); 0051 0052 OSM::Element e; 0053 LV result; 0054 LevelParser::parse(input.toUtf8(), e, [&result](int level, OSM::Element e) { 0055 Q_UNUSED(e); 0056 result.push_back(level); 0057 }); 0058 0059 if (result != levels) { 0060 qDebug() << result << levels; 0061 } 0062 QCOMPARE(result, levels); 0063 } 0064 }; 0065 0066 QTEST_GUILESS_MAIN(LevelParserTest) 0067 0068 #include "levelparsertest.moc"