File indexing completed on 2022-10-04 14:00:26

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2012 Mohammed Nafees <nafees.technocool@gmail.com>
0004 //
0005 
0006 #include <QObject>
0007 
0008 #include <GeoDataDocument.h>
0009 #include <MarbleDebug.h>
0010 #include <GeoDataFolder.h>
0011 #include <GeoDataGroundOverlay.h>
0012 #include "TestUtils.h"
0013 
0014 using namespace Marble;
0015 
0016 class TestGroundOverlay : public QObject
0017 {
0018     Q_OBJECT
0019 private Q_SLOTS:
0020     void initTestCase();
0021     void simpleParseTest();
0022 };
0023 
0024 void TestGroundOverlay::initTestCase()
0025 {
0026     MarbleDebug::setEnabled( true );
0027 }
0028 
0029 void TestGroundOverlay::simpleParseTest()
0030 {
0031   QString const centerContent (
0032         "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
0033         "<kml xmlns=\"http://www.opengis.net/kml/2.2\""
0034         " xmlns:gx=\"http://www.google.com/kml/ext/2.2\">"
0035         "<Folder>"
0036             "<GroundOverlay>"
0037                 "<altitude>0</altitude>"
0038                 "<altitudeMode>absolute</altitudeMode>"
0039                 "<LatLonBox>"
0040                     "<north>37.91904192681665</north>"
0041                     "<south>37.46543388598137</south>"
0042                     "<east>15.35832653742206</east>"
0043                     "<west>14.60128369746704</west>"
0044                     "<rotation>-0.1556640799496235</rotation>"
0045                  "</LatLonBox>"
0046              "</GroundOverlay>"
0047               "<GroundOverlay>"
0048                   "<altitude>233</altitude>"
0049                   "<drawOrder>2</drawOrder>"
0050                   "<LatLonBox>"
0051                       "<north>23.3765376</north>"
0052                       "<south>1.5743867869</south>"
0053                       "<east>33.78365874</east>"
0054                       "<west>94.352435642</west>"
0055                       "<rotation>6.346364378</rotation>"
0056                    "</LatLonBox>"
0057                "</GroundOverlay>"
0058         "</Folder>"
0059         "</kml>" );
0060 
0061     GeoDataDocument* dataDocument = parseKml( centerContent  );
0062     QCOMPARE( dataDocument->folderList().size(), 1 );
0063     GeoDataFolder *folder = dataDocument->folderList().at( 0 );
0064     QCOMPARE( folder->size(), 2 );
0065     GeoDataGroundOverlay *overlayFirst = dynamic_cast<GeoDataGroundOverlay*>( folder->child( 0 ) );
0066     GeoDataGroundOverlay *overlaySecond = dynamic_cast<GeoDataGroundOverlay*>( folder->child( 1 ) );
0067     QVERIFY( overlayFirst != nullptr );
0068     QVERIFY( overlaySecond != nullptr );
0069 
0070     QFUZZYCOMPARE( overlayFirst->altitude(), 0.0, 0.0001 );
0071 
0072     QFUZZYCOMPARE( overlayFirst->altitudeMode(), Absolute, 0.0001 );
0073     QCOMPARE( overlayFirst->drawOrder(), 0 );
0074 
0075     QFUZZYCOMPARE( overlayFirst->latLonBox().north(), 37.91904192681665 * DEG2RAD, 0.0001 );
0076     QFUZZYCOMPARE( overlayFirst->latLonBox().south(), 37.46543388598137 * DEG2RAD, 0.0001 );
0077     QFUZZYCOMPARE( overlayFirst->latLonBox().east(), 15.35832653742206 * DEG2RAD, 0.0001 );
0078     QFUZZYCOMPARE( overlayFirst->latLonBox().west(), 14.60128369746704 * DEG2RAD, 0.0001 );
0079     QFUZZYCOMPARE( overlayFirst->latLonBox().rotation(), -0.1556640799496235 * DEG2RAD, 0.0001 );
0080 
0081     QFUZZYCOMPARE( overlaySecond->altitude(), 233.0, 0.0001 );
0082 
0083     QCOMPARE( overlaySecond->altitudeMode(), ClampToGround );
0084     QCOMPARE( overlaySecond->drawOrder(), 2 );
0085 
0086     QFUZZYCOMPARE( overlaySecond->latLonBox().north(), 23.3765376 * DEG2RAD, 0.0001 );
0087     QFUZZYCOMPARE( overlaySecond->latLonBox().south(), 1.5743867869 * DEG2RAD, 0.0001 );
0088     QFUZZYCOMPARE( overlaySecond->latLonBox().east(), 33.78365874 * DEG2RAD, 0.0001 );
0089     QFUZZYCOMPARE( overlaySecond->latLonBox().west(), 94.352435642 * DEG2RAD, 0.0001 );
0090     QFUZZYCOMPARE( overlaySecond->latLonBox().rotation(), 6.346364378 * DEG2RAD, 0.0001 );
0091 
0092     delete dataDocument;
0093 }
0094 
0095 QTEST_MAIN( TestGroundOverlay )
0096 
0097 #include "TestGroundOverlay.moc"