File indexing completed on 2024-09-08 03:35:15
0001 // SPDX-License-Identifier: LGPL-2.1-or-later 0002 // 0003 // SPDX-FileCopyrightText: 2011 Thibaut Gridel <tgridel@free.fr> 0004 // SPDX-FileCopyrightText: 2012 Bernhard Beschow <bbeschow@cs.tu-berlin.de> 0005 // 0006 0007 #include "MarbleDebug.h" 0008 #include "MarbleDirs.h" 0009 #include "MarbleModel.h" 0010 #include "ParsingRunnerManager.h" 0011 #include "PluginManager.h" 0012 #include "ReverseGeocodingRunnerManager.h" 0013 #include "RoutingRunnerManager.h" 0014 #include "SearchRunnerManager.h" 0015 #include "GeoDataPlacemark.h" 0016 #include "routing/RouteRequest.h" 0017 #include "TestUtils.h" 0018 0019 #include <QSignalSpy> 0020 #include <QMetaType> 0021 #include <QThreadPool> 0022 0023 Q_DECLARE_METATYPE( QList<Marble::GeoDataCoordinates> ) 0024 0025 namespace Marble 0026 { 0027 0028 class MarbleRunnerManagerTest : public QObject 0029 { 0030 Q_OBJECT 0031 0032 private Q_SLOTS: 0033 void initTestCase();// will be called before the first testfunction is executed. 0034 void cleanupTestCase();// will be called after the last testfunction was executed. 0035 void init(){ qDebug() << "start: " << t.elapsed();}// will be called before each testfunction is executed. 0036 void cleanup(){ qDebug() << "end: " << t.elapsed();}// will be called after every testfunction. 0037 0038 void testSyncPlacemarks(); 0039 0040 void testAsyncPlacemarks_data(); 0041 void testAsyncPlacemarks(); 0042 0043 void testSyncReverse(); 0044 0045 void testAsyncReverse_data(); 0046 void testAsyncReverse(); 0047 0048 void testSyncRouting(); 0049 0050 void testAsyncRouting_data(); 0051 void testAsyncRouting(); 0052 0053 void testSyncParsing_data(); 0054 void testSyncParsing(); 0055 0056 void testAsyncParsing_data(); 0057 void testAsyncParsing(); 0058 0059 public: 0060 PluginManager m_pluginManager; 0061 int m_time; 0062 QString m_name; 0063 GeoDataCoordinates m_coords; 0064 GeoDataCoordinates m_coords2; 0065 RouteRequest m_request; 0066 QTime t; 0067 }; 0068 0069 void MarbleRunnerManagerTest::initTestCase() 0070 { 0071 MarbleDebug::setEnabled( true ); 0072 MarbleDirs::setMarbleDataPath( DATA_PATH ); 0073 MarbleDirs::setMarblePluginPath( PLUGIN_PATH ); 0074 m_time = 30000; 0075 m_name = "Berlin"; 0076 0077 qRegisterMetaType<QVector<GeoDataCoordinates> >( "QVector<GeoDataCoordinates>" ); 0078 0079 m_coords.setLatitude(52.50160, GeoDataCoordinates::Degree ); 0080 m_coords.setLongitude(13.40233, GeoDataCoordinates::Degree ); 0081 0082 m_coords2.setLatitude(52.52665, GeoDataCoordinates::Degree ); 0083 m_coords2.setLongitude(13.39032, GeoDataCoordinates::Degree ); 0084 0085 m_request.append( m_coords ); 0086 m_request.append( m_coords2 ); 0087 t.start(); 0088 } 0089 0090 void MarbleRunnerManagerTest::cleanupTestCase() 0091 { 0092 } 0093 0094 void MarbleRunnerManagerTest::testSyncPlacemarks() 0095 { 0096 MarbleModel model; 0097 SearchRunnerManager m_runnerManager(&model, this); 0098 0099 QSignalSpy finishSpy( &m_runnerManager, SIGNAL(placemarkSearchFinished()) ); 0100 QSignalSpy resultSpy( &m_runnerManager, SIGNAL(searchResultChanged(QVector<GeoDataPlacemark*>)) ); 0101 0102 QCOMPARE( finishSpy.count(), 0 ); 0103 QCOMPARE( resultSpy.count(), 0 ); 0104 0105 QTime timer; 0106 timer.start(); 0107 QVector<GeoDataPlacemark*> placemarks = m_runnerManager.searchPlacemarks(m_name); 0108 0109 QVERIFY( timer.elapsed() < m_time ); 0110 QCOMPARE( resultSpy.count(), 1 ); 0111 QVERIFY( placemarks.size() > 0 ); 0112 QCOMPARE( finishSpy.count(), 1 ); 0113 0114 // second search is optimised 0115 placemarks.clear(); 0116 finishSpy.clear(); 0117 resultSpy.clear(); 0118 timer.start(); 0119 placemarks = m_runnerManager.searchPlacemarks(m_name); 0120 0121 QVERIFY( timer.elapsed() < m_time ); 0122 QCOMPARE( resultSpy.count(), 1 ); 0123 QVERIFY( placemarks.size() > 0 ); 0124 QCOMPARE( finishSpy.count(), 1 ); 0125 } 0126 0127 void MarbleRunnerManagerTest::testAsyncPlacemarks_data() 0128 { 0129 QTest::addColumn<QString>( "name" ); 0130 0131 addRow() << QString( "Berlin" ); 0132 addRow() << QString( "www.heise.de" ); 0133 } 0134 0135 void MarbleRunnerManagerTest::testAsyncPlacemarks() 0136 { 0137 MarbleModel model; 0138 SearchRunnerManager m_runnerManager(&model, this); 0139 0140 QSignalSpy finishSpy( &m_runnerManager, SIGNAL(searchFinished(QString)) ); 0141 QSignalSpy resultSpy( &m_runnerManager, SIGNAL(searchResultChanged(QVector<GeoDataPlacemark*>)) ); 0142 0143 QEventLoop loop; 0144 connect( &m_runnerManager, SIGNAL(searchFinished(QString)), 0145 &loop, SLOT(quit()), Qt::QueuedConnection ); 0146 0147 QFETCH( QString, name ); 0148 m_runnerManager.findPlacemarks( name ); 0149 0150 loop.exec(); 0151 0152 QCOMPARE( resultSpy.count(), 1 ); 0153 QCOMPARE( finishSpy.count(), 1 ); 0154 0155 QThreadPool::globalInstance()->waitForDone(); 0156 } 0157 0158 void MarbleRunnerManagerTest::testSyncReverse() 0159 { 0160 MarbleModel model; 0161 ReverseGeocodingRunnerManager m_runnerManager(&model, this); 0162 0163 QSignalSpy finishSpy( &m_runnerManager, SIGNAL(reverseGeocodingFinished()) ); 0164 QSignalSpy resultSpy( &m_runnerManager, SIGNAL(reverseGeocodingFinished(GeoDataCoordinates,GeoDataPlacemark)) ); 0165 0166 QCOMPARE( finishSpy.count(), 0 ); 0167 QCOMPARE( resultSpy.count(), 0 ); 0168 0169 QTime timer; 0170 timer.start(); 0171 QString placemark = m_runnerManager.searchReverseGeocoding( m_coords ); 0172 0173 QVERIFY( timer.elapsed() < m_time ); 0174 QCOMPARE( resultSpy.count(), 1 ); 0175 QVERIFY( !placemark.isEmpty() ); 0176 QCOMPARE( finishSpy.count(), 1 ); 0177 0178 // second search is optimised 0179 finishSpy.clear(); 0180 resultSpy.clear(); 0181 timer.start(); 0182 placemark = m_runnerManager.searchReverseGeocoding( m_coords ); 0183 0184 QVERIFY( timer.elapsed() < m_time ); 0185 QCOMPARE( resultSpy.count(), 1 ); 0186 QVERIFY( !placemark.isEmpty() ); 0187 QCOMPARE( finishSpy.count(), 1 ); 0188 } 0189 0190 void MarbleRunnerManagerTest::testAsyncReverse_data() 0191 { 0192 QTest::addColumn<GeoDataCoordinates>( "coordinates" ); 0193 0194 addRow() << m_coords; 0195 } 0196 0197 void MarbleRunnerManagerTest::testAsyncReverse() 0198 { 0199 MarbleModel model; 0200 ReverseGeocodingRunnerManager m_runnerManager(&model, this); 0201 0202 QSignalSpy finishSpy( &m_runnerManager, SIGNAL(reverseGeocodingFinished()) ); 0203 QSignalSpy resultSpy( &m_runnerManager, SIGNAL(reverseGeocodingFinished(GeoDataCoordinates,GeoDataPlacemark)) ); 0204 0205 QEventLoop loop; 0206 connect( &m_runnerManager, SIGNAL(reverseGeocodingFinished()), 0207 &loop, SLOT(quit()), Qt::QueuedConnection ); 0208 0209 QFETCH( GeoDataCoordinates, coordinates ); 0210 m_runnerManager.reverseGeocoding( coordinates ); 0211 0212 loop.exec(); 0213 0214 QCOMPARE( resultSpy.count(), 1 ); 0215 QCOMPARE( finishSpy.count(), 1 ); 0216 0217 QThreadPool::globalInstance()->waitForDone(); 0218 } 0219 0220 void MarbleRunnerManagerTest::testSyncRouting() 0221 { 0222 MarbleModel model; 0223 RoutingRunnerManager m_runnerManager(&model, this); 0224 0225 QSignalSpy finishSpy( &m_runnerManager, SIGNAL(routingFinished()) ); 0226 QSignalSpy resultSpy( &m_runnerManager, SIGNAL(routeRetrieved(GeoDataDocument*)) ); 0227 0228 QCOMPARE( finishSpy.count(), 0 ); 0229 QCOMPARE( resultSpy.count(), 0 ); 0230 0231 QTime timer; 0232 timer.start(); 0233 QVector<GeoDataDocument*> routes = m_runnerManager.searchRoute( &m_request ); 0234 0235 QVERIFY( timer.elapsed() < m_time ); 0236 QVERIFY( resultSpy.count() > 0 ); 0237 QVERIFY( !routes.isEmpty() ); 0238 QCOMPARE( finishSpy.count(), 1 ); 0239 } 0240 0241 void MarbleRunnerManagerTest::testAsyncRouting_data() 0242 { 0243 QTest::addColumn<QVector<GeoDataCoordinates> >( "coordinatesList" ); 0244 0245 addRow() << ( QVector<GeoDataCoordinates>() << m_coords << m_coords2 ); 0246 } 0247 0248 void MarbleRunnerManagerTest::testAsyncRouting() 0249 { 0250 MarbleModel model; 0251 RoutingRunnerManager m_runnerManager(&model, this); 0252 0253 QSignalSpy finishSpy( &m_runnerManager, SIGNAL(routingFinished()) ); 0254 QSignalSpy resultSpy( &m_runnerManager, SIGNAL(routeRetrieved(GeoDataDocument*)) ); 0255 0256 QEventLoop loop; 0257 connect( &m_runnerManager, SIGNAL(routingFinished()), 0258 &loop, SLOT(quit()), Qt::QueuedConnection ); 0259 0260 QFETCH( QVector<GeoDataCoordinates>, coordinatesList ); 0261 RouteRequest request; 0262 foreach( const GeoDataCoordinates &coordinates, coordinatesList ) { 0263 request.append( coordinates ); 0264 } 0265 0266 m_runnerManager.retrieveRoute( &request ); 0267 0268 loop.exec(); 0269 0270 QVERIFY( resultSpy.count() > 0 ); 0271 QCOMPARE( finishSpy.count(), 1 ); 0272 0273 QThreadPool::globalInstance()->waitForDone(); 0274 } 0275 0276 void MarbleRunnerManagerTest::testSyncParsing_data() 0277 { 0278 QTest::addColumn<QString>( "fileName" ); 0279 QTest::addColumn<int>( "resultCount" ); 0280 0281 0282 addRow() << MarbleDirs::path( "mwdbii/DATELINE.PNT" ) << 1; 0283 addRow() << MarbleDirs::path( "mwdbii/PCOAST.PNT" ) << 1; 0284 addRow() << MarbleDirs::path( "mwdbii/PLAKEISLAND.PNT" ) << 1; 0285 addRow() << MarbleDirs::path( "mwdbii/PDIFFBORDER.PNT" ) << 1; 0286 addRow() << MarbleDirs::path( "mwdbii/PISLAND.PNT" ) << 1; 0287 addRow() << MarbleDirs::path( "mwdbii/PLAKE.PNT" ) << 1; 0288 addRow() << MarbleDirs::path( "mwdbii/PUSA48.DIFF.PNT" ) << 1; 0289 addRow() << MarbleDirs::path( "mwdbii/RIVER.PNT" ) << 1; 0290 0291 addNamedRow("cache") << QString( MARBLE_SRC_DIR ).append( "/data/placemarks/otherplacemarks.cache" ) << 1; 0292 addNamedRow("gpx") << QString( MARBLE_SRC_DIR ).append( "/examples/gpx/mjolby.gpx") << 1; 0293 addNamedRow("json") << QString( MARBLE_SRC_DIR ).append( "/examples/json/rfc7946-example.geojson") << 1; 0294 addNamedRow("kml") << QString( MARBLE_SRC_DIR ).append( "/examples/kml/NewYork.kml") << 1; 0295 //log 0296 addNamedRow("osm") << QString( MARBLE_SRC_DIR ).append( "/examples/osm/map.osm") << 1; 0297 addNamedRow("pn2") << QString( MARBLE_SRC_DIR ).append( "/data/naturalearth/ne_50m_lakes.pn2") << 1; 0298 addNamedRow("pnt") << QString( MARBLE_SRC_DIR ).append( "/data/mwdbii/PGLACIER.PNT" ) << 1; 0299 //shp 0300 0301 addNamedRow("svg") << MarbleDirs::path( "flags/flag_tv.svg" ) << 0; 0302 } 0303 0304 void MarbleRunnerManagerTest::testSyncParsing() 0305 { 0306 ParsingRunnerManager m_runnerManager(&m_pluginManager, this); 0307 0308 QSignalSpy finishSpy( &m_runnerManager, SIGNAL(parsingFinished()) ); 0309 QSignalSpy resultSpy( &m_runnerManager, SIGNAL(parsingFinished(GeoDataDocument*,QString)) ); 0310 0311 QFETCH( QString, fileName ); 0312 QFETCH( int, resultCount ); 0313 0314 GeoDataDocument* file = m_runnerManager.openFile( fileName ); 0315 0316 QCOMPARE( resultSpy.count(), resultCount ); 0317 QCOMPARE( file != nullptr, resultCount > 0 ); 0318 QCOMPARE( finishSpy.count(), 1 ); 0319 } 0320 0321 void MarbleRunnerManagerTest::testAsyncParsing_data() 0322 { 0323 QTest::addColumn<QString>( "fileName" ); 0324 QTest::addColumn<int>( "resultCount" ); 0325 0326 addRow() << MarbleDirs::path( "placemarks/otherplacemarks.cache" ) << 1; 0327 0328 addRow() << MarbleDirs::path( "mwdbii/DATELINE.PNT" ) << 1; 0329 addRow() << MarbleDirs::path( "mwdbii/PCOAST.PNT" ) << 1; 0330 addRow() << MarbleDirs::path( "mwdbii/PGLACIER.PNT" ) << 1; 0331 addRow() << MarbleDirs::path( "mwdbii/PLAKEISLAND.PNT" ) << 1; 0332 addRow() << MarbleDirs::path( "mwdbii/PDIFFBORDER.PNT" ) << 1; 0333 addRow() << MarbleDirs::path( "mwdbii/PISLAND.PNT" ) << 1; 0334 addRow() << MarbleDirs::path( "mwdbii/PLAKE.PNT" ) << 1; 0335 addRow() << MarbleDirs::path( "mwdbii/PUSA48.DIFF.PNT" ) << 1; 0336 addRow() << MarbleDirs::path( "mwdbii/RIVER.PNT" ) << 1; 0337 0338 addRow() << MarbleDirs::path( "flags/flag_tv.svg" ) << 0; 0339 } 0340 0341 void MarbleRunnerManagerTest::testAsyncParsing() 0342 { 0343 ParsingRunnerManager m_runnerManager(&m_pluginManager, this); 0344 0345 QSignalSpy finishSpy( &m_runnerManager, SIGNAL(parsingFinished()) ); 0346 QSignalSpy resultSpy( &m_runnerManager, SIGNAL(parsingFinished(GeoDataDocument*,QString)) ); 0347 0348 QEventLoop loop; 0349 connect( &m_runnerManager, SIGNAL(parsingFinished()), 0350 &loop, SLOT(quit()), Qt::QueuedConnection ); 0351 0352 QFETCH( QString, fileName ); 0353 QFETCH( int, resultCount ); 0354 0355 m_runnerManager.parseFile( fileName ); 0356 0357 loop.exec(); 0358 0359 0360 QCOMPARE( resultSpy.count(), resultCount ); 0361 QCOMPARE( finishSpy.count(), 1 ); 0362 0363 QThreadPool::globalInstance()->waitForDone(); 0364 } 0365 0366 } 0367 0368 QTEST_MAIN( Marble::MarbleRunnerManagerTest ) 0369 0370 #include "MarbleRunnerManagerTest.moc"