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 <GeoDataPlacemark.h>
0012 #include <GeoDataStyle.h>
0013 #include <GeoDataListStyle.h>
0014 #include <GeoDataItemIcon.h>
0015 #include "TestUtils.h"
0016 
0017 using namespace Marble;
0018 
0019 
0020 class TestListStyle : public QObject
0021 {
0022     Q_OBJECT
0023 private Q_SLOTS:
0024     void initTestCase();
0025     void simpleParseTest();
0026 };
0027 
0028 void TestListStyle::initTestCase()
0029 {
0030     MarbleDebug::setEnabled( true );
0031 }
0032 
0033 void TestListStyle::simpleParseTest()
0034 {
0035   QString const content (
0036         "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
0037         "<kml xmlns=\"http://www.opengis.net/kml/2.2\""
0038         " xmlns:gx=\"http://www.google.com/kml/ext/2.2\">"
0039         "<Document>"
0040         "  <name>The one and only BalloonStyle test case</name>"
0041         "  <Style id=\"my-list-style\">"
0042         "    <ListStyle>"
0043         "      <listItemType>checkOffOnly</listItemType>"
0044         "      <bgColor>aa112233</bgColor>"
0045         "      <ItemIcon>"
0046         "        <state>open error</state>"
0047         "        <href>https://developers.google.com/kml/documentation/images/itemicons.jpg</href>"
0048         "      </ItemIcon>"
0049         "      <ItemIcon>"
0050         "        <state>closed</state>"
0051         "        <href>https://developers.google.com/kml/documentation/images/itemicons1.jpg</href>"
0052         "      </ItemIcon>"
0053         "    </ListStyle>"
0054         "  </Style>"
0055         "  <Folder>"
0056         "  <Placemark>"
0057         "    <name>The first placemark</name>"
0058         "    <styleUrl>#my-list-style</styleUrl>"
0059         "    <Point><coordinates>80.0,30.0</coordinates></Point>"
0060         "  </Placemark>"
0061         "  </Folder>"
0062         "</Document>"
0063         "</kml>" );
0064 
0065     GeoDataDocument* dataDocument = parseKml( content  );
0066     QCOMPARE( dataDocument->folderList().size(), 1 );
0067     GeoDataFolder *folder = dataDocument->folderList().at( 0 );
0068     QCOMPARE( folder->size(), 1 );
0069     GeoDataPlacemark *placemark1 = dynamic_cast<GeoDataPlacemark*>( folder->child( 0 ) );
0070     QVERIFY( placemark1 != nullptr );
0071 
0072     QCOMPARE( placemark1->name(), QString( "The first placemark" ) );
0073     QCOMPARE( placemark1->style()->listStyle().listItemType(), GeoDataListStyle::CheckOffOnly );
0074     QCOMPARE( placemark1->style()->listStyle().backgroundColor().red(), 51 );
0075     QCOMPARE( placemark1->style()->listStyle().itemIconList().at(0)->state(), GeoDataItemIcon::Open | GeoDataItemIcon::Error );
0076     QCOMPARE( placemark1->style()->listStyle().itemIconList().at(0)->iconPath(), QString( "https://developers.google.com/kml/documentation/images/itemicons.jpg" ) );
0077     QCOMPARE( placemark1->style()->listStyle().itemIconList().at(1)->state(), GeoDataItemIcon::Closed );
0078     QCOMPARE( placemark1->style()->listStyle().itemIconList().at(1)->iconPath(), QString( "https://developers.google.com/kml/documentation/images/itemicons1.jpg" ) );
0079 
0080     delete dataDocument;
0081 }
0082 
0083 QTEST_MAIN( TestListStyle )
0084 
0085 #include "TestListStyle.moc"
0086