File indexing completed on 2024-10-06 12:18:39
0001 /* 0002 SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org> 0003 SPDX-License-Identifier: LGPL-2.0-or-later 0004 */ 0005 0006 #include "../src/geo-scheme-handler/kgeourihandler.cpp" 0007 0008 #include <QTest> 0009 0010 class KGeoUriHandlerTest : public QObject 0011 { 0012 Q_OBJECT 0013 private Q_SLOTS: 0014 void testHandler_data() 0015 { 0016 QTest::addColumn<QString>("input"); 0017 QTest::addColumn<QString>("output"); 0018 0019 QTest::newRow("empty") << QString() << QStringLiteral("https://openstreetmap.org"); 0020 QTest::newRow("incomplete-1") << QStringLiteral("geo:") << QStringLiteral("https://openstreetmap.org"); 0021 QTest::newRow("incomplete-2") << QStringLiteral("geo:46.1") << QStringLiteral("https://openstreetmap.org"); 0022 QTest::newRow("broken-1") << QStringLiteral("geo:a,b") << QStringLiteral("https://openstreetmap.org"); 0023 QTest::newRow("broken-2") << QStringLiteral("geo:46.1;7.783") << QStringLiteral("https://openstreetmap.org"); 0024 QTest::newRow("lat-out-of-range-1") << QStringLiteral("geo:91.0;-1.0") << QStringLiteral("https://openstreetmap.org"); 0025 QTest::newRow("lat-out-of-range-2") << QStringLiteral("geo:-91.0;1.0") << QStringLiteral("https://openstreetmap.org"); 0026 QTest::newRow("lon-out-of-range-1") << QStringLiteral("geo:1.0;181.0") << QStringLiteral("https://openstreetmap.org"); 0027 QTest::newRow("lon-out-of-range-2") << QStringLiteral("geo:-1.0;-181.0") << QStringLiteral("https://openstreetmap.org"); 0028 0029 QTest::newRow("2d-coord-only") << QStringLiteral("geo:46.1,7.783") << QStringLiteral("https://www.openstreetmap.org/#map=18/46.1/7.783"); 0030 QTest::newRow("3d-coord") << QStringLiteral("geo:46.1,7.783,1600") << QStringLiteral("https://www.openstreetmap.org/#map=18/46.1/7.783"); 0031 QTest::newRow("2d-coord-with-uncertainty") << QStringLiteral("geo:46.1,7.783;u=100") 0032 << QStringLiteral("https://www.openstreetmap.org/#map=18/46.1/7.783"); 0033 QTest::newRow("2d-coord-with-z") << QStringLiteral("geo:46.1,7.783?z=19") << QStringLiteral("https://www.openstreetmap.org/#map=19/46.1/7.783"); 0034 QTest::newRow("negative-coord") << QStringLiteral("geo:-34.59,-58.375") << QStringLiteral("https://www.openstreetmap.org/#map=18/-34.59/-58.375"); 0035 0036 QTest::newRow("query") << QStringLiteral("geo:0,0?q=Randa") << QStringLiteral("https://www.openstreetmap.org/search?query=Randa"); 0037 QTest::newRow("query-with-coord") << QStringLiteral("geo:46.1,7.783?q=Randa") << QStringLiteral("https://www.openstreetmap.org/search?query=Randa"); 0038 0039 // explicit coordinate reference systems 0040 QTest::newRow("WGS84") << QStringLiteral("geo:37.78,-122.4;u=35;crs=wgs84") << QStringLiteral("https://www.openstreetmap.org/#map=18/37.78/-122.4"); 0041 QTest::newRow("EPSG:32618") << QStringLiteral("geo:323482,4306480;crs=EPSG:32618;u=20") << QStringLiteral("https://openstreetmap.org"); 0042 QTest::newRow("moon") << QStringLiteral("geo:37.786971,-122.399677;crs=Moon-2011;u=35") << QStringLiteral("https://openstreetmap.org"); 0043 } 0044 0045 void testHandler() 0046 { 0047 QFETCH(QString, input); 0048 QFETCH(QString, output); 0049 0050 KGeoUriHandler handler; 0051 handler.setCoordinateTemplate(QStringLiteral("https://www.openstreetmap.org/#map=<Z>/<LAT>/<LON>")); 0052 handler.setQueryTemplate(QStringLiteral("https://www.openstreetmap.org/search?query=<Q>")); 0053 handler.setFallbackUrl(QStringLiteral("https://openstreetmap.org")); 0054 QCOMPARE(handler.handleUri(QUrl(input)), output); 0055 } 0056 }; 0057 0058 QTEST_APPLESS_MAIN(KGeoUriHandlerTest) 0059 0060 #include "kgeourihandlertest.moc"