File indexing completed on 2025-04-20 03:36:21
0001 // SPDX-License-Identifier: LGPL-2.1-or-later 0002 // 0003 // SPDX-FileCopyrightText: 2013 Illya Kovalevskyy <illya.kovalevskyy@gmail.com> 0004 // 0005 0006 #include <GeoDataParser.h> 0007 #include <GeoDataDocument.h> 0008 #include <GeoDataUpdate.h> 0009 #include <GeoDataTour.h> 0010 #include <GeoDataPlaylist.h> 0011 #include <GeoDataTourControl.h> 0012 #include <MarbleDebug.h> 0013 #include <GeoDataFolder.h> 0014 #include <GeoDataAnimatedUpdate.h> 0015 0016 #include <QObject> 0017 #include <QBuffer> 0018 #include <QTest> 0019 0020 using namespace Marble; 0021 0022 class TestTour : public QObject 0023 { 0024 Q_OBJECT 0025 private Q_SLOTS: 0026 void initTestCase(); 0027 void simpleParseTest(); 0028 }; 0029 0030 void TestTour::initTestCase() 0031 { 0032 MarbleDebug::setEnabled( true ); 0033 } 0034 0035 GeoDataDocument *parseKml(const QString &content) 0036 { 0037 GeoDataParser parser( GeoData_KML ); 0038 0039 QByteArray array( content.toUtf8() ); 0040 QBuffer buffer( &array ); 0041 buffer.open( QIODevice::ReadOnly ); 0042 //qDebug() << "Buffer content:" << endl << buffer.buffer(); 0043 if ( !parser.read( &buffer ) ) { 0044 qFatal( "Could not parse data!" ); 0045 } 0046 GeoDocument* document = parser.releaseDocument(); 0047 Q_ASSERT( document ); 0048 return static_cast<GeoDataDocument*>( document ); 0049 } 0050 0051 void TestTour::simpleParseTest() 0052 { 0053 QString const centerContent ( 0054 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" 0055 "<kml xmlns=\"http://www.opengis.net/kml/2.2\"" 0056 " xmlns:gx=\"http://www.google.com/kml/ext/2.2\">" 0057 "<Folder>" 0058 " <gx:Tour>" 0059 " <name>My Tour</name>" 0060 " <description>This is my tour.</description>" 0061 " </gx:Tour>" 0062 " <gx:Tour id=\"tourId\">" 0063 " <gx:Playlist>" 0064 " <gx:TourControl id=\"space\">" 0065 " <gx:playMode>pause</gx:playMode>" 0066 " </gx:TourControl>" 0067 " </gx:Playlist>" 0068 " </gx:Tour>" 0069 " <gx:Tour id=\"animUpd\">" 0070 " <name>TourAnim</name>" 0071 " <description>Tour with AnimatedUpdate</description>" 0072 " <gx:Playlist>" 0073 " <gx:AnimatedUpdate>" 0074 " <gx:duration>5.0</gx:duration>" 0075 " <Update>" 0076 " <targetHref>Whatever.jpg</targetHref>" 0077 " </Update>" 0078 " </gx:AnimatedUpdate>" 0079 " </gx:Playlist>" 0080 " </gx:Tour>" 0081 "</Folder>" 0082 "</kml>" ); 0083 0084 GeoDataDocument* dataDocument = parseKml( centerContent ); 0085 QCOMPARE( dataDocument->folderList().size(), 1 ); 0086 GeoDataFolder *folder = dataDocument->folderList().at( 0 ); 0087 0088 0089 GeoDataTour *tour_1 = dynamic_cast<GeoDataTour*>(folder->child(0)); 0090 GeoDataTour *tour_2 = dynamic_cast<GeoDataTour*>(folder->child(1)); 0091 GeoDataTour *tour_3 = dynamic_cast<GeoDataTour*>(folder->child(2)); 0092 0093 QVERIFY(tour_1 != nullptr); 0094 QVERIFY(tour_2 != nullptr); 0095 QVERIFY(tour_3 != nullptr); 0096 0097 QCOMPARE(tour_1->id(), QString("")); 0098 QCOMPARE(tour_1->name(), QString("My Tour")); 0099 QCOMPARE(tour_1->description(), QString("This is my tour.")); 0100 0101 QCOMPARE(tour_2->id(), QString("tourId")); 0102 QCOMPARE(tour_2->name(), QString()); 0103 QCOMPARE(tour_2->description(), QString()); 0104 0105 QCOMPARE(tour_3->id(), QString("animUpd")); 0106 QCOMPARE(tour_3->name(), QString("TourAnim")); 0107 QCOMPARE(tour_3->description(), QString("Tour with AnimatedUpdate")); 0108 0109 GeoDataPlaylist *playlist = tour_2->playlist(); 0110 QVERIFY(playlist != nullptr); 0111 0112 GeoDataTourControl *control = dynamic_cast<GeoDataTourControl*>( 0113 playlist->primitive(0)); 0114 QVERIFY(control != nullptr); 0115 QCOMPARE(control->id(), QString("space")); 0116 QCOMPARE(control->playMode(), GeoDataTourControl::Pause); 0117 0118 GeoDataPlaylist *playlist2 = tour_3->playlist(); 0119 QVERIFY(playlist2 != nullptr); 0120 0121 GeoDataAnimatedUpdate *update = dynamic_cast<GeoDataAnimatedUpdate*>(playlist2->primitive(0)); 0122 QVERIFY(update != nullptr); 0123 QCOMPARE(update->duration(),5.0); 0124 QCOMPARE(update->update()->targetHref(),QString("Whatever.jpg")); 0125 0126 delete dataDocument; 0127 } 0128 0129 QTEST_MAIN( TestTour ) 0130 0131 #include "TestTour.moc" 0132