File indexing completed on 2024-12-01 09:46:14

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2013 Mayank Madan <maddiemadan@gmail.com>
0004 //
0005 
0006 #include <QObject>
0007 
0008 #include "TestUtils.h"
0009 #include <GeoDataDocument.h>
0010 #include <GeoDataFolder.h>
0011 #include <MarbleDebug.h>
0012 #include <GeoDataNetworkLink.h>
0013 #include <GeoDataLink.h>
0014 
0015 using namespace Marble;
0016 
0017 
0018 class TestNetworkLink : public QObject
0019 {
0020     Q_OBJECT
0021 private Q_SLOTS:
0022     void initTestCase();
0023     void simpleParseTest();
0024 };
0025 
0026 void TestNetworkLink::initTestCase()
0027 {
0028     MarbleDebug::setEnabled( true );
0029 }
0030 
0031 void TestNetworkLink::simpleParseTest()
0032 {
0033     QString const centerContent (
0034     "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
0035     "<kml xmlns=\"http://www.opengis.net/kml/2.2\""
0036     " xmlns:gx=\"http://www.google.com/kml/ext/2.2\">"
0037     "<Folder>"
0038     " <NetworkLink>"
0039     "  <refreshVisibility>1</refreshVisibility> <!-- boolean -->"
0040     "  <flyToView>1</flyToView>                 <!-- boolean -->"
0041     "  <Link>"
0042     "   <href>http://files.kde.org/marble/examples/kml/</href>"
0043     "   <refreshMode>onChange</refreshMode>"
0044     "   <refreshInterval>2.1</refreshInterval>"
0045     "   <viewRefreshMode>never</viewRefreshMode>"
0046     "   <viewRefreshTime>4.2</viewRefreshTime>"
0047     "   <viewBoundScale>1.5</viewBoundScale>"
0048     "   <viewFormat>BBOX=[bboxWest],[bboxSouth],[bboxEast],[bboxNorth]</viewFormat>"
0049     "   <httpQuery>SiteType=sw,gw,sp&amp;SiteCode=all&amp;Format=ge</httpQuery>"
0050     "  </Link>"
0051     " </NetworkLink>"
0052     "</Folder>"
0053     "</kml>");
0054 
0055     GeoDataDocument* dataDocument = parseKml( centerContent  );
0056     QCOMPARE( dataDocument->folderList().size(), 1 );
0057     GeoDataFolder *folder = dataDocument->folderList().at( 0 );
0058     QCOMPARE( folder->size(), 1 );
0059     GeoDataNetworkLink *networkLink = dynamic_cast<GeoDataNetworkLink*>( folder->child( 0 ) );
0060     QVERIFY( networkLink != nullptr );
0061 
0062     QCOMPARE( networkLink->refreshVisibility(), true );
0063     QCOMPARE( networkLink->flyToView(), true );
0064     QCOMPARE( networkLink->link().href(), QString("http://files.kde.org/marble/examples/kml/") );
0065     QCOMPARE( networkLink->link().refreshMode(), GeoDataLink::OnChange );
0066     QFUZZYCOMPARE( networkLink->link().refreshInterval(), 2.1, 0.0001 );
0067     QCOMPARE( networkLink->link().viewRefreshMode(), GeoDataLink::Never);
0068     QFUZZYCOMPARE( networkLink->link().viewRefreshTime(), 4.2, 0.0001 );
0069     QFUZZYCOMPARE( networkLink->link().viewBoundScale(), 1.5, 0.0001 );
0070     QCOMPARE( networkLink->link().viewFormat(), QString("BBOX=[bboxWest],[bboxSouth],[bboxEast],[bboxNorth]") );
0071     QCOMPARE( networkLink->link().httpQuery(), QString("SiteType=sw,gw,sp&SiteCode=all&Format=ge"));
0072 
0073 }
0074 
0075 QTEST_MAIN( TestNetworkLink )
0076 
0077 #include "TestNetworkLink.moc"
0078