File indexing completed on 2024-05-19 03:53:09
0001 // SPDX-License-Identifier: LGPL-2.1-or-later 0002 // 0003 // SPDX-FileCopyrightText: 2011 Niko Sams <niko.sams@gmail.com> 0004 // 0005 0006 #include <QObject> 0007 #include <QtTest> 0008 0009 #include "GeoDataPoint.h" 0010 #include "GeoDataLinearRing.h" 0011 #include "GeoDataMultiGeometry.h" 0012 #include <GeoDataParser.h> 0013 #include <GeoDataDocument.h> 0014 #include <GeoDataPlacemark.h> 0015 #include <MarbleDebug.h> 0016 #include <GeoDataTrack.h> 0017 #include <GeoDataExtendedData.h> 0018 #include <GeoDataSimpleArrayData.h> 0019 #include "GpxParser.h" 0020 0021 using namespace Marble; 0022 0023 0024 class TestTrack : public QObject 0025 { 0026 Q_OBJECT 0027 private Q_SLOTS: 0028 void initTestCase(); 0029 void simpleParseTest(); 0030 void withoutTimeTest(); 0031 void partialTimeTest(); 0032 void extendedDataHeartRateTest(); 0033 0034 }; 0035 0036 void TestTrack::initTestCase() 0037 { 0038 MarbleDebug::setEnabled( true ); 0039 } 0040 0041 void TestTrack::simpleParseTest() 0042 { 0043 //example track recorded using a Garmin Vista HCx and downloaded using gpsbabel 0044 QString content( 0045 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" 0046 "<gpx" 0047 " version=\"1.0\"" 0048 " creator=\"GPSBabel - http://www.gpsbabel.org\"" 0049 " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" 0050 " xmlns=\"http://www.topografix.com/GPX/1/0\"" 0051 " xsi:schemaLocation=\"http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd\">" 0052 "<time>2011-07-03T14:19:57Z</time>" 0053 "<bounds minlat=\"47.231073193\" minlon=\"12.549449634\" maxlat=\"48.502999926\" maxlon=\"14.302069964\"/>" 0054 "<trk>" 0055 " <name>test track</name>" 0056 "<number>1</number>" 0057 "<trkseg>" 0058 "<trkpt lat=\"47.231477033\" lon=\"12.560534449\">" 0059 " <ele>1130.647705</ele>" 0060 " <time>2011-06-24T10:33:40Z</time>" 0061 "</trkpt>" 0062 "<trkpt lat=\"47.231486840\" lon=\"12.560604354\">" 0063 " <ele>1127.763672</ele>" 0064 " <time>2011-06-24T10:33:55Z</time>" 0065 "</trkpt>" 0066 "<trkpt lat=\"47.231497569\" lon=\"12.560612401\">" 0067 " <ele>1121.995850</ele>" 0068 " <time>2011-06-24T10:34:00Z</time>" 0069 "</trkpt>" 0070 "</trkseg>" 0071 "</trk>" 0072 "</gpx>" 0073 ); 0074 0075 GpxParser parser; 0076 0077 QByteArray array( content.toUtf8() ); 0078 QBuffer buffer( &array ); 0079 buffer.open( QIODevice::ReadOnly ); 0080 qDebug() << "Buffer content:" << endl << buffer.buffer(); 0081 if ( !parser.read( &buffer ) ) { 0082 QFAIL( "Could not parse data!" ); 0083 return; 0084 } 0085 GeoDocument* document = parser.releaseDocument(); 0086 QVERIFY( document ); 0087 GeoDataDocument *dataDocument = static_cast<GeoDataDocument*>( document ); 0088 GeoDataPlacemark* placemark = dataDocument->placemarkList().at( 0 ); 0089 QCOMPARE( placemark->geometry()->geometryId(), GeoDataMultiGeometryId ); 0090 GeoDataMultiGeometry* multiGeo = static_cast<GeoDataMultiGeometry*>( placemark->geometry() ); 0091 GeoDataTrack* track = static_cast<GeoDataTrack*>( &multiGeo->at( 0 ) ); 0092 QCOMPARE( track->size(), 3 ); 0093 { 0094 QDateTime when = track->whenList().at( 0 ); 0095 QCOMPARE( when, QDateTime( QDate( 2011, 6, 24 ), QTime( 10, 33, 40 ), Qt::UTC ) ); 0096 } 0097 { 0098 GeoDataCoordinates coord = track->coordinatesAt( 0 ); 0099 QCOMPARE( coord.longitude( GeoDataCoordinates::Degree ), 12.560534449 ); 0100 QCOMPARE( coord.latitude( GeoDataCoordinates::Degree ), 47.231477033 ); 0101 QCOMPARE( coord.altitude(), 1130.647705 ); 0102 } 0103 { 0104 GeoDataCoordinates coord = track->coordinatesAt( QDateTime( QDate( 2011, 6, 24 ), QTime( 10, 33, 40 ), Qt::UTC ) ); 0105 QCOMPARE( coord.longitude( GeoDataCoordinates::Degree ), 12.560534449 ); 0106 QCOMPARE( coord.latitude( GeoDataCoordinates::Degree ), 47.231477033 ); 0107 QCOMPARE( coord.altitude(), 1130.647705 ); 0108 } 0109 { 0110 const GeoDataLineString* lineString = track->lineString(); 0111 QCOMPARE( lineString->size(), 3 ); 0112 GeoDataCoordinates coord = lineString->at( 0 ); 0113 QCOMPARE( coord.longitude( GeoDataCoordinates::Degree ), 12.560534449 ); 0114 QCOMPARE( coord.latitude( GeoDataCoordinates::Degree ), 47.231477033 ); 0115 QCOMPARE( coord.altitude(), 1130.647705 ); 0116 } 0117 0118 delete document; 0119 } 0120 0121 void TestTrack::withoutTimeTest() 0122 { 0123 //example track recorded using a Garmin Vista HCx and downloaded using gpsbabel; time removed 0124 QString content( 0125 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" 0126 "<gpx" 0127 " version=\"1.0\"" 0128 " creator=\"GPSBabel - http://www.gpsbabel.org\"" 0129 " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" 0130 " xmlns=\"http://www.topografix.com/GPX/1/0\"" 0131 " xsi:schemaLocation=\"http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd\">" 0132 "<time>2011-07-03T14:19:57Z</time>" 0133 "<bounds minlat=\"47.231073193\" minlon=\"12.549449634\" maxlat=\"48.502999926\" maxlon=\"14.302069964\"/>" 0134 "<trk>" 0135 " <name>test track</name>" 0136 "<number>1</number>" 0137 "<trkseg>" 0138 "<trkpt lat=\"47.231477033\" lon=\"12.560534449\">" 0139 " <ele>1130.647705</ele>" 0140 "</trkpt>" 0141 "<trkpt lat=\"47.231486840\" lon=\"12.560604354\">" 0142 " <ele>1127.763672</ele>" 0143 "</trkpt>" 0144 "<trkpt lat=\"47.231497569\" lon=\"12.560612401\">" 0145 " <ele>1121.995850</ele>" 0146 "</trkpt>" 0147 "</trkseg>" 0148 "</trk>" 0149 "</gpx>" 0150 ); 0151 0152 GpxParser parser; 0153 0154 QByteArray array( content.toUtf8() ); 0155 QBuffer buffer( &array ); 0156 buffer.open( QIODevice::ReadOnly ); 0157 qDebug() << "Buffer content:" << endl << buffer.buffer(); 0158 if ( !parser.read( &buffer ) ) { 0159 QFAIL( "Could not parse data!" ); 0160 return; 0161 } 0162 GeoDocument* document = parser.releaseDocument(); 0163 QVERIFY( document ); 0164 GeoDataDocument *dataDocument = static_cast<GeoDataDocument*>( document ); 0165 GeoDataPlacemark* placemark = dataDocument->placemarkList().at( 0 ); 0166 QCOMPARE( placemark->geometry()->geometryId(), GeoDataMultiGeometryId ); 0167 GeoDataMultiGeometry* multiGeo = static_cast<GeoDataMultiGeometry*>( placemark->geometry() ); 0168 GeoDataTrack* track = static_cast<GeoDataTrack*>( &multiGeo->at( 0 ) ); 0169 QCOMPARE( track->size(), 3 ); 0170 { 0171 GeoDataCoordinates coord = track->coordinatesAt( 0 ); 0172 QCOMPARE( coord.longitude( GeoDataCoordinates::Degree ), 12.560534449 ); 0173 QCOMPARE( coord.latitude( GeoDataCoordinates::Degree ), 47.231477033 ); 0174 QCOMPARE( coord.altitude(), 1130.647705 ); 0175 } 0176 { 0177 const GeoDataLineString* lineString = track->lineString(); 0178 QCOMPARE( lineString->size(), 3 ); 0179 GeoDataCoordinates coord = lineString->at( 0 ); 0180 QCOMPARE( coord.longitude( GeoDataCoordinates::Degree ), 12.560534449 ); 0181 QCOMPARE( coord.latitude( GeoDataCoordinates::Degree ), 47.231477033 ); 0182 QCOMPARE( coord.altitude(), 1130.647705 ); 0183 } 0184 0185 0186 delete document; 0187 } 0188 0189 void TestTrack::partialTimeTest() 0190 { 0191 //example track recorded using a Garmin Vista HCx and downloaded using gpsbabel 0192 //one time information removed 0193 QString content( 0194 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" 0195 "<gpx" 0196 " version=\"1.0\"" 0197 " creator=\"GPSBabel - http://www.gpsbabel.org\"" 0198 " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" 0199 " xmlns=\"http://www.topografix.com/GPX/1/0\"" 0200 " xsi:schemaLocation=\"http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd\">" 0201 "<time>2011-07-03T14:19:57Z</time>" 0202 "<bounds minlat=\"47.231073193\" minlon=\"12.549449634\" maxlat=\"48.502999926\" maxlon=\"14.302069964\"/>" 0203 "<trk>" 0204 " <name>test track</name>" 0205 "<number>1</number>" 0206 "<trkseg>" 0207 "<trkpt lat=\"47.231477033\" lon=\"12.560534449\">" 0208 " <ele>1130.647705</ele>" 0209 " <time>2011-06-24T10:33:40Z</time>" 0210 "</trkpt>" 0211 "<trkpt lat=\"47.231486840\" lon=\"12.560604354\">" 0212 " <ele>1127.763672</ele>" 0213 "</trkpt>" 0214 "<trkpt lat=\"47.231497569\" lon=\"12.560612401\">" 0215 " <ele>1121.995850</ele>" 0216 " <time>2011-06-24T10:34:00Z</time>" 0217 "</trkpt>" 0218 "</trkseg>" 0219 "</trk>" 0220 "</gpx>" 0221 ); 0222 0223 GpxParser parser; 0224 0225 QByteArray array( content.toUtf8() ); 0226 QBuffer buffer( &array ); 0227 buffer.open( QIODevice::ReadOnly ); 0228 qDebug() << "Buffer content:" << endl << buffer.buffer(); 0229 if ( !parser.read( &buffer ) ) { 0230 QFAIL( "Could not parse data!" ); 0231 return; 0232 } 0233 GeoDocument* document = parser.releaseDocument(); 0234 QVERIFY( document ); 0235 GeoDataDocument *dataDocument = static_cast<GeoDataDocument*>( document ); 0236 GeoDataPlacemark* placemark = dataDocument->placemarkList().at( 0 ); 0237 QCOMPARE( placemark->geometry()->geometryId(), GeoDataMultiGeometryId ); 0238 GeoDataMultiGeometry* multiGeo = static_cast<GeoDataMultiGeometry*>( placemark->geometry() ); 0239 GeoDataTrack* track = static_cast<GeoDataTrack*>( &multiGeo->at( 0 ) ); 0240 QCOMPARE( track->whenList().size(), 3 ); 0241 { 0242 QDateTime when = track->whenList().at( 0 ); 0243 QCOMPARE( when, QDateTime( QDate( 2011, 6, 24 ), QTime( 10, 33, 40 ), Qt::UTC ) ); 0244 } 0245 { 0246 QDateTime when = track->whenList().at( 1 ); 0247 QCOMPARE( when, QDateTime() ); 0248 } 0249 { 0250 QDateTime when = track->whenList().at( 2 ); 0251 QCOMPARE( when, QDateTime( QDate( 2011, 6, 24 ), QTime( 10, 34, 00 ), Qt::UTC ) ); 0252 } 0253 QCOMPARE( track->size(), 3 ); 0254 { 0255 GeoDataCoordinates coord = track->coordinatesAt( 0 ); 0256 QCOMPARE( coord.longitude( GeoDataCoordinates::Degree ), 12.560534449 ); 0257 QCOMPARE( coord.latitude( GeoDataCoordinates::Degree ), 47.231477033 ); 0258 QCOMPARE( coord.altitude(), 1130.647705 ); 0259 } 0260 { 0261 GeoDataCoordinates coord = track->coordinatesAt( QDateTime( QDate( 2011, 6, 24 ), QTime( 10, 33, 40 ), Qt::UTC ) ); 0262 QCOMPARE( coord.longitude( GeoDataCoordinates::Degree ), 12.560534449 ); 0263 QCOMPARE( coord.latitude( GeoDataCoordinates::Degree ), 47.231477033 ); 0264 QCOMPARE( coord.altitude(), 1130.647705 ); 0265 } 0266 { 0267 GeoDataCoordinates coord = track->coordinatesAt( QDateTime( QDate( 2011, 6, 24 ), QTime( 10, 34, 00 ), Qt::UTC ) ); 0268 QCOMPARE( coord.longitude( GeoDataCoordinates::Degree ), 12.560612401 ); 0269 QCOMPARE( coord.latitude( GeoDataCoordinates::Degree ), 47.231497569 ); 0270 QCOMPARE( coord.altitude(), 1121.995850 ); 0271 } 0272 { 0273 const GeoDataLineString* lineString = track->lineString(); 0274 QCOMPARE( lineString->size(), 3 ); 0275 GeoDataCoordinates coord = lineString->at( 0 ); 0276 QCOMPARE( coord.longitude( GeoDataCoordinates::Degree ), 12.560534449 ); 0277 QCOMPARE( coord.latitude( GeoDataCoordinates::Degree ), 47.231477033 ); 0278 QCOMPARE( coord.altitude(), 1130.647705 ); 0279 } 0280 0281 delete document; 0282 } 0283 0284 void TestTrack::extendedDataHeartRateTest() 0285 { 0286 //example track recorded using a Garmin Oregon 450 and downloading using it's USB mass storare mode 0287 QString content( 0288 "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" 0289 "<gpx xmlns=\"http://www.topografix.com/GPX/1/1\" " 0290 " xmlns:gpxx=\"http://www.garmin.com/xmlschemas/WaypointExtension/v1\" " 0291 " xmlns:gpxtrx=\"http://www.garmin.com/xmlschemas/GpxExtensions/v3\" " 0292 " xmlns:gpxtpx=\"http://www.garmin.com/xmlschemas/TrackPointExtension/v1\" " 0293 " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " 0294 " creator=\"Oregon 450\" " 0295 " version=\"1.1\" " 0296 " xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 " 0297 "http://www.topografix.com/GPX/1/1/gpx.xsd " 0298 "http://www.garmin.com/xmlschemas/WaypointExtension/v1 " 0299 "http://www8.garmin.com/xmlschemas/WaypointExtensionv1.xsd " 0300 "http://www.garmin.com/xmlschemas/TrackPointExtension/v1 " 0301 "http://www.garmin.com/xmlschemas/TrackPointExtensionv1.xsd\" " 0302 " >" 0303 " <metadata>" 0304 " <link href=\"http://www.garmin.com\">" 0305 " <text>Garmin International</text>" 0306 " </link>" 0307 " <time>2011-10-29T15:29:19Z</time>" 0308 " </metadata>" 0309 " <trk>" 0310 " <name>29-OKT-11 17:29:17</name>" 0311 " <extensions>" 0312 " <gpxtrx:TrackExtension>" 0313 " <gpxtrx:DisplayColor>Black</gpxtrx:DisplayColor>" 0314 " </gpxtrx:TrackExtension>" 0315 " </extensions>" 0316 " <trkseg>" 0317 " <trkpt lat=\"47.951347\" lon=\"13.228035\">" 0318 " <ele>571.16</ele>" 0319 " <time>2011-10-29T08:35:31Z</time>" 0320 " <extensions>" 0321 " <gpxtpx:TrackPointExtension>" 0322 " <gpxtpx:hr>108</gpxtpx:hr>" 0323 " </gpxtpx:TrackPointExtension>" 0324 " </extensions>" 0325 " </trkpt>" 0326 " <trkpt lat=\"47.951348\" lon=\"13.228035\">" 0327 " <ele>573.56</ele>" 0328 " <time>2011-10-29T08:35:37Z</time>" 0329 " <extensions>" 0330 " <gpxtpx:TrackPointExtension>" 0331 " <gpxtpx:hr>109</gpxtpx:hr>" 0332 " </gpxtpx:TrackPointExtension>" 0333 " </extensions>" 0334 " </trkpt>" 0335 " <trkpt lat=\"47.951349\" lon=\"13.228036\">" 0336 " <ele>572.12</ele>" 0337 " <time>2011-10-29T08:35:43Z</time>" 0338 " <extensions>" 0339 " <gpxtpx:TrackPointExtension>" 0340 " <gpxtpx:hr>110</gpxtpx:hr>" 0341 " </gpxtpx:TrackPointExtension>" 0342 " </extensions>" 0343 " </trkpt>" 0344 " </trkseg>" 0345 " </trk>" 0346 "</gpx>" 0347 ); 0348 0349 GpxParser parser; 0350 0351 QByteArray array( content.toUtf8() ); 0352 QBuffer buffer( &array ); 0353 buffer.open( QIODevice::ReadOnly ); 0354 qDebug() << "Buffer content:" << endl << buffer.buffer(); 0355 if ( !parser.read( &buffer ) ) { 0356 QFAIL( "Could not parse data!" ); 0357 return; 0358 } 0359 GeoDocument* document = parser.releaseDocument(); 0360 QVERIFY( document ); 0361 GeoDataDocument *dataDocument = static_cast<GeoDataDocument*>( document ); 0362 GeoDataPlacemark* placemark = dataDocument->placemarkList().at( 0 ); 0363 QCOMPARE( placemark->geometry()->geometryId(), GeoDataMultiGeometryId ); 0364 GeoDataMultiGeometry* multiGeo = static_cast<GeoDataMultiGeometry*>( placemark->geometry() ); 0365 GeoDataTrack* track = static_cast<GeoDataTrack*>( &multiGeo->at( 0 ) ); 0366 QCOMPARE( track->size(), 3 ); 0367 0368 { 0369 GeoDataSimpleArrayData* hr = track->extendedData().simpleArrayData( "heartrate" ); 0370 QCOMPARE( hr->size(), 3 ); 0371 QCOMPARE( hr->valueAt( 0 ), QVariant( "108" ) ); 0372 QCOMPARE( hr->valueAt( 2 ), QVariant( "110" ) ); 0373 } 0374 0375 delete document; 0376 } 0377 0378 QTEST_MAIN( TestTrack ) 0379 0380 #include "TestTrack.moc" 0381