File indexing completed on 2024-04-14 14:16:31

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2014 Levente Kurusa <levex@linux.com>
0004 //
0005 
0006 #include <QString>
0007 #include "TestUtils.h"
0008 #include "GeoUriParser.h"
0009 
0010 namespace Marble
0011 {
0012 
0013 class GeoUriParserTest : public QObject
0014 {
0015     Q_OBJECT
0016 
0017 private Q_SLOTS:
0018     void testGeoUri_data();
0019     void testGeoUri();
0020 };
0021 
0022 void GeoUriParserTest::testGeoUri_data()
0023 {
0024     QTest::addColumn<QString>( "uri" );
0025     QTest::addColumn<bool>( "valid" );
0026     QTest::addColumn<double>( "lat" );
0027     QTest::addColumn<double>( "lon" );
0028     QTest::addColumn<double>( "alt" );
0029 
0030     // geo: URI tests
0031     addRow() << "geo:-25.0064,153.359,250" << true << -25.0064 << 153.359 << 250.00;
0032     addRow() << "geo:-25.0064153.359250" << false << 0.00 << 0.00 << 0.00;
0033     addRow() << "geo-25.0064,153.359,250" << false << 0.00 << 0.00 << 0.00;
0034     addRow() << "geo:25.0064,-153.359,250" << true << 25.0064 << -153.359 << 250.00;
0035     addRow() << "25.0064,-153.359,250" << false << 0.00 << 0.00 << 0.00;
0036     addRow() << "geo:25.0064,-153.359" << true << 25.0064 << -153.359 << 00.00;
0037     addRow() << "geo:37.786971,-122.399677;u=35" << true << 37.786971 << -122.399677 << 0.00;
0038     addRow() << "geo:37.786971,-122.399677;crs=Moon-2011" << true << 37.786971 << -122.399677 << 0.00;
0039     addRow() << "geo:37.786971,-122.399677;crs=Moon-2011,u=25" << true <<  37.786971 << -122.399677 << 0.00;
0040 
0041     // worldwind: URI tests
0042     addRow() << "worldwind://goto/world=Earth&lat=-43.54642&lon=172.69&alt=25883&bank=242&tilt=1&dir=2&layer=Hello"
0043              << true << -43.54642 << 172.69 << 25883.0;
0044     addRow() << "worldwind://goto/world=Earth&lat=-43.54642&lon=172.69"
0045              << true << -43.54642 << 172.69 << 0.0;
0046     addRow() << "worldwind://lat=-43.54642&lon=172.69&alt=25883"
0047              << false << 0.0 << 0.0 << 0.0;
0048     addRow() << "worldwind://goto/world=Earth&alt=25883"
0049              << true << 0.0 << 0.0 << 25883.0;
0050     addRow() << "goto/world=Earth&lat=-43.54642&lon=172.69&alt=25883"
0051              << false << 0.0 << 0.0 << 0.0;
0052     addRow() << "world=Earth&lat=-43.54642&lon=172.69&alt=25883&bank=242&tilt=1&dir=2&layer=Hello"
0053              << false << 0.0 << 0.0 << 0.0;
0054 }
0055 
0056 void GeoUriParserTest::testGeoUri()
0057 {
0058     QFETCH( QString, uri );
0059     QFETCH( bool, valid );
0060     QFETCH( double, lat );
0061     QFETCH( double, lon );
0062     QFETCH( double, alt );
0063 
0064     GeoUriParser parser( uri );
0065     bool ret = parser.parse();
0066 
0067     GeoDataCoordinates coords = parser.coordinates();
0068 
0069     qreal cLat = 0.0, cLon = 0.0, cAlt = 0.0;
0070     coords.geoCoordinates(cLon, cLat, cAlt, GeoDataCoordinates::Degree);
0071 
0072     QCOMPARE(ret, valid);
0073     if ( ret == valid ) {
0074         QCOMPARE(cLat, lat );
0075         QCOMPARE(cLon, lon);
0076         QCOMPARE(cAlt, alt );
0077     }
0078 }
0079 
0080 
0081 }
0082 
0083 QTEST_MAIN( Marble::GeoUriParserTest )
0084 
0085 #include "GeoUriParserTest.moc"