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

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2012 Dennis Nienhüser <nienhueser@kde.org>
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 <GeoDataBalloonStyle.h>
0014 #include "TestUtils.h"
0015 
0016 using namespace Marble;
0017 
0018 
0019 class TestBalloonStyle : public QObject
0020 {
0021     Q_OBJECT
0022 private Q_SLOTS:
0023     void initTestCase();
0024     void simpleParseTest();
0025 };
0026 
0027 void TestBalloonStyle::initTestCase()
0028 {
0029     MarbleDebug::setEnabled( true );
0030 }
0031 
0032 void TestBalloonStyle::simpleParseTest()
0033 {
0034   QString const content (
0035         "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
0036         "<kml xmlns=\"http://www.opengis.net/kml/2.2\""
0037         " xmlns:gx=\"http://www.google.com/kml/ext/2.2\">"
0038         "<Document>"
0039         "  <name>The one and only BalloonStyle test case</name>"
0040         "  <Style id=\"my-balloon-style\">"
0041         "    <BalloonStyle>"
0042         "      <bgColor>aa112233</bgColor>"
0043         "      <textColor>bb445566</textColor>"
0044         "      <text>This is my balloon style. There are many like it, but this is mine.</text>"
0045         "      <displayMode>hide</displayMode>"
0046         "    </BalloonStyle>"
0047         "  </Style>"
0048         "  <Folder>"
0049         "  <Placemark>"
0050         "    <name>The first placemark</name>"
0051         "    <styleUrl>#my-balloon-style</styleUrl>"
0052         "    <Point><coordinates>80.0,30.0</coordinates></Point>"
0053         "  </Placemark>"
0054         "  </Folder>"
0055         "</Document>"
0056         "</kml>" );
0057 
0058     GeoDataDocument* dataDocument = parseKml( content  );
0059     QCOMPARE( dataDocument->folderList().size(), 1 );
0060     GeoDataFolder *folder = dataDocument->folderList().at( 0 );
0061     QCOMPARE( folder->size(), 1 );
0062     GeoDataPlacemark *placemark1 = dynamic_cast<GeoDataPlacemark*>( folder->child( 0 ) );
0063     QVERIFY( placemark1 != nullptr );
0064 
0065     QCOMPARE( placemark1->name(), QString( "The first placemark" ) );
0066     QCOMPARE( placemark1->style()->balloonStyle().backgroundColor().red(), 51 );
0067     QCOMPARE( placemark1->style()->balloonStyle().textColor().blue(), 68 );
0068     QCOMPARE( placemark1->style()->balloonStyle().displayMode(), GeoDataBalloonStyle::Hide );
0069     QString const text = "This is my balloon style. There are many like it, but this is mine.";
0070     QCOMPARE( placemark1->style()->balloonStyle().text(), text );
0071 
0072     delete dataDocument;
0073 }
0074 
0075 QTEST_MAIN( TestBalloonStyle )
0076 
0077 #include "TestBalloonStyle.moc"