1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356
|
// SPDX-License-Identifier: LGPL-2.1-or-later
//
// SPDX-FileCopyrightText: 2011 Niko Sams <niko.sams@gmail.com>
//
#include <QObject>
#include "GeoDataLinearRing.h"
#include "GeoDataPoint.h"
#include "TestUtils.h"
#include <GeoDataDocument.h>
#include <GeoDataExtendedData.h>
#include <GeoDataFolder.h>
#include <GeoDataPlacemark.h>
#include <GeoDataSimpleArrayData.h>
#include <GeoDataTrack.h>
#include <MarbleDebug.h>
#include <QDateTime>
using namespace Marble;
class TestGeoDataTrack : public QObject
{
Q_OBJECT
private Q_SLOTS:
void initTestCase();
void defaultConstructor();
void interpolate();
void simpleParseTest();
void removeBeforeTest();
void removeAfterTest();
void extendedDataParseTest();
void withoutTimeTest();
};
void TestGeoDataTrack::initTestCase()
{
MarbleDebug::setEnabled(true);
}
void TestGeoDataTrack::defaultConstructor()
{
const GeoDataTrack track;
QCOMPARE(track.size(), 0);
QCOMPARE(track.interpolate(), false);
QCOMPARE(track.coordinatesList().size(), 0);
QCOMPARE(track.whenList().size(), 0);
QCOMPARE(track.lineString()->size(), 0);
QCOMPARE(track.latLonAltBox(), GeoDataLatLonAltBox());
QCOMPARE(track.coordinatesAt(QDateTime(QDate(2014, 8, 16), QTime(8, 0, 0))), GeoDataCoordinates());
}
void TestGeoDataTrack::interpolate()
{
GeoDataTrack track;
track.setInterpolate(true);
const QDateTime date1(QDate(2014, 8, 16), QTime(4, 57, 26));
const QDateTime date2(QDate(2014, 8, 16), QTime(12, 47, 16));
const GeoDataCoordinates coordinates1(13.592294, 52.675926, 71, GeoDataCoordinates::Degree);
const GeoDataCoordinates coordinates2(13.572776, 53.517952, 97, GeoDataCoordinates::Degree);
track.addPoint(date1, coordinates1);
track.addPoint(date2, coordinates2);
const GeoDataCoordinates interpolated = track.coordinatesAt(QDateTime(QDate(2014, 8, 16), QTime(8, 0, 0)));
QCOMPARE(interpolated.longitude(GeoDataCoordinates::Degree), 13.5848002666755789391572761815);
QCOMPARE(interpolated.latitude(GeoDataCoordinates::Degree), 53.0031187444621139093214878812);
const GeoDataCoordinates beforeStart = track.coordinatesAt(QDateTime(QDate(2014, 8, 16), QTime(0, 0, 0)));
QCOMPARE(beforeStart, GeoDataCoordinates());
const GeoDataCoordinates afterEnd = track.coordinatesAt(QDateTime(QDate(2014, 8, 16), QTime(23, 0, 0)));
QCOMPARE(afterEnd, GeoDataCoordinates());
}
//"Simple Example" from kmlreference
QString simpleExampleContent(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
"<kml xmlns=\"http://www.opengis.net/kml/2.2\""
" xmlns:gx=\"http://www.google.com/kml/ext/2.2\">"
"<Folder>"
" <Placemark>"
" <gx:Track>"
" <when>2010-05-28T02:02:09Z</when>"
" <when>2010-05-28T02:02:35Z</when>"
" <when>2010-05-28T02:02:44Z</when>"
" <when>2010-05-28T02:02:53Z</when>"
" <when>2010-05-28T02:02:54Z</when>"
" <when>2010-05-28T02:02:55Z</when>"
" <when>2010-05-28T02:02:56Z</when>"
" <gx:coord>-122.207881 37.371915 156.000000</gx:coord>"
" <gx:coord>-122.205712 37.373288 152.000000</gx:coord>"
" <gx:coord>-122.204678 37.373939 147.000000</gx:coord>"
" <gx:coord>-122.203572 37.374630 142.199997</gx:coord>"
" <gx:coord>-122.203451 37.374706 141.800003</gx:coord>"
" <gx:coord>-122.203329 37.374780 141.199997</gx:coord>"
" <gx:coord>-122.203207 37.374857 140.199997</gx:coord>"
" </gx:Track>"
" </Placemark>"
"</Folder>"
"</kml>");
void TestGeoDataTrack::simpleParseTest()
{
GeoDataDocument *dataDocument = parseKml(simpleExampleContent);
GeoDataFolder *folder = dataDocument->folderList().at(0);
QCOMPARE(folder->placemarkList().size(), 1);
GeoDataPlacemark *placemark = folder->placemarkList().at(0);
QCOMPARE(placemark->geometry()->geometryId(), GeoDataTrackId);
auto track = static_cast<GeoDataTrack *>(placemark->geometry());
QCOMPARE(track->size(), 7);
{
QDateTime when = track->whenList().at(0);
QCOMPARE(when, QDateTime(QDate(2010, 5, 28), QTime(2, 2, 9), Qt::UTC));
}
{
GeoDataCoordinates coord = track->coordinatesList().at(0);
QCOMPARE(coord.longitude(GeoDataCoordinates::Degree), -122.207881);
QCOMPARE(coord.latitude(GeoDataCoordinates::Degree), 37.371915);
QCOMPARE(coord.altitude(), 156.000000);
}
{
GeoDataCoordinates coord = track->coordinatesAt(QDateTime(QDate(2010, 5, 28), QTime(2, 2, 9), Qt::UTC));
QCOMPARE(coord.longitude(GeoDataCoordinates::Degree), -122.207881);
QCOMPARE(coord.latitude(GeoDataCoordinates::Degree), 37.371915);
QCOMPARE(coord.altitude(), 156.000000);
}
delete dataDocument;
}
void TestGeoDataTrack::removeBeforeTest()
{
GeoDataDocument *dataDocument = parseKml(simpleExampleContent);
GeoDataFolder *folder = dataDocument->folderList().at(0);
QCOMPARE(folder->placemarkList().size(), 1);
GeoDataPlacemark *placemark = folder->placemarkList().at(0);
QCOMPARE(placemark->geometry()->geometryId(), GeoDataTrackId);
auto track = static_cast<GeoDataTrack *>(placemark->geometry());
QCOMPARE(track->size(), 7);
track->removeBefore(QDateTime(QDate(2010, 5, 28), QTime(2, 2, 54), Qt::UTC));
QCOMPARE(track->size(), 3);
{
QDateTime when = track->whenList().at(0);
QCOMPARE(when, QDateTime(QDate(2010, 5, 28), QTime(2, 2, 54), Qt::UTC));
}
{
QDateTime when = track->whenList().at(2);
QCOMPARE(when, QDateTime(QDate(2010, 5, 28), QTime(2, 2, 56), Qt::UTC));
}
{
GeoDataCoordinates coord = track->coordinatesList().at(0);
QCOMPARE(coord.longitude(GeoDataCoordinates::Degree), -122.203451);
QCOMPARE(coord.latitude(GeoDataCoordinates::Degree), 37.374706);
QCOMPARE(coord.altitude(), 141.800003);
}
delete dataDocument;
}
void TestGeoDataTrack::removeAfterTest()
{
GeoDataDocument *dataDocument = parseKml(simpleExampleContent);
GeoDataFolder *folder = dataDocument->folderList().at(0);
QCOMPARE(folder->placemarkList().size(), 1);
GeoDataPlacemark *placemark = folder->placemarkList().at(0);
QCOMPARE(placemark->geometry()->geometryId(), GeoDataTrackId);
auto track = static_cast<GeoDataTrack *>(placemark->geometry());
QCOMPARE(track->size(), 7);
track->removeAfter(QDateTime(QDate(2010, 5, 28), QTime(2, 2, 54), Qt::UTC));
QCOMPARE(track->size(), 5);
{
QDateTime when = track->whenList().at(0);
QCOMPARE(when, QDateTime(QDate(2010, 5, 28), QTime(2, 2, 9), Qt::UTC));
}
{
QDateTime when = track->whenList().at(4);
QCOMPARE(when, QDateTime(QDate(2010, 5, 28), QTime(2, 2, 54), Qt::UTC));
}
{
GeoDataCoordinates coord = track->coordinatesList().at(0);
QCOMPARE(coord.longitude(GeoDataCoordinates::Degree), -122.207881);
QCOMPARE(coord.latitude(GeoDataCoordinates::Degree), 37.371915);
QCOMPARE(coord.altitude(), 156.000000);
}
delete dataDocument;
}
void TestGeoDataTrack::extendedDataParseTest()
{
//"Example of Track with Extended Data" from kmlreference
QString content(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
"<kml xmlns=\"http://www.opengis.net/kml/2.2\" xmlns:gx=\"http://www.google.com/kml/ext/2.2\">"
" <Document>"
" <name>GPS device</name>"
" <Snippet>Created Wed Jun 2 15:33:39 2010</Snippet>"
" <Schema id=\"schema\">"
" <gx:SimpleArrayField name=\"heartrate\" type=\"int\">"
" <displayName>Heart Rate</displayName>"
" </gx:SimpleArrayField>"
" <gx:SimpleArrayField name=\"cadence\" type=\"int\">"
" <displayName>Cadence</displayName>"
" </gx:SimpleArrayField>"
" <gx:SimpleArrayField name=\"power\" type=\"float\">"
" <displayName>Power</displayName>"
" </gx:SimpleArrayField>"
" </Schema>"
" <Folder>"
" <name>Tracks</name>"
" <Placemark>"
" <name>2010-05-28T01:16:35.000Z</name>"
" <styleUrl>#multiTrack</styleUrl>"
" <gx:Track>"
" <when>2010-05-28T02:02:09Z</when>"
" <when>2010-05-28T02:02:35Z</when>"
" <when>2010-05-28T02:02:44Z</when>"
" <when>2010-05-28T02:02:53Z</when>"
" <when>2010-05-28T02:02:54Z</when>"
" <when>2010-05-28T02:02:55Z</when>"
" <when>2010-05-28T02:02:56Z</when>"
" <gx:coord>-122.207881 37.371915 156.000000</gx:coord>"
" <gx:coord>-122.205712 37.373288 152.000000</gx:coord>"
" <gx:coord>-122.204678 37.373939 147.000000</gx:coord>"
" <gx:coord>-122.203572 37.374630 142.199997</gx:coord>"
" <gx:coord>-122.203451 37.374706 141.800003</gx:coord>"
" <gx:coord>-122.203329 37.374780 141.199997</gx:coord>"
" <gx:coord>-122.203207 37.374857 140.199997</gx:coord>"
" <ExtendedData>"
" <SchemaData schemaUrl=\"#schema\">"
" <gx:SimpleArrayData name=\"cadence\">"
" <gx:value>86</gx:value>"
" <gx:value>103</gx:value>"
" <gx:value>108</gx:value>"
" <gx:value>113</gx:value>"
" <gx:value>113</gx:value>"
" <gx:value>113</gx:value>"
" <gx:value>113</gx:value>"
" </gx:SimpleArrayData>"
" <gx:SimpleArrayData name=\"heartrate\">"
" <gx:value>181</gx:value>"
" <gx:value>177</gx:value>"
" <gx:value>175</gx:value>"
" <gx:value>173</gx:value>"
" <gx:value>173</gx:value>"
" <gx:value>173</gx:value>"
" <gx:value>173</gx:value>"
" </gx:SimpleArrayData>"
" <gx:SimpleArrayData name=\"power\">"
" <gx:value>327.0</gx:value>"
" <gx:value>177.0</gx:value>"
" <gx:value>179.0</gx:value>"
" <gx:value>162.0</gx:value>"
" <gx:value>166.0</gx:value>"
" <gx:value>177.0</gx:value>"
" <gx:value>183.0</gx:value>"
" </gx:SimpleArrayData>"
" </SchemaData>"
" </ExtendedData>"
" </gx:Track>"
" </Placemark>"
" </Folder>"
" </Document>"
"</kml>");
GeoDataDocument *dataDocument = parseKml(content);
GeoDataFolder *folder = dataDocument->folderList().at(0);
QCOMPARE(folder->placemarkList().size(), 1);
GeoDataPlacemark *placemark = folder->placemarkList().at(0);
QCOMPARE(placemark->geometry()->geometryId(), GeoDataTrackId);
auto track = static_cast<GeoDataTrack *>(placemark->geometry());
QCOMPARE(track->size(), 7);
{
GeoDataSimpleArrayData *cadence = track->extendedData().simpleArrayData("cadence");
QCOMPARE(cadence->size(), 7);
QCOMPARE(cadence->valueAt(0), QVariant("86"));
QCOMPARE(cadence->valueAt(6), QVariant("113"));
}
{
GeoDataSimpleArrayData *hr = track->extendedData().simpleArrayData("heartrate");
QCOMPARE(hr->size(), 7);
QCOMPARE(hr->valueAt(0), QVariant("181"));
QCOMPARE(hr->valueAt(6), QVariant("173"));
}
{
GeoDataSimpleArrayData *power = track->extendedData().simpleArrayData("power");
QCOMPARE(power->size(), 7);
QCOMPARE(power->valueAt(0), QVariant("327.0"));
QCOMPARE(power->valueAt(6), QVariant("183.0"));
}
delete dataDocument;
}
void TestGeoDataTrack::withoutTimeTest()
{
//"Simple Example" from kmlreference; when elements emptied
QString content(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
"<kml xmlns=\"http://www.opengis.net/kml/2.2\""
" xmlns:gx=\"http://www.google.com/kml/ext/2.2\">"
"<Folder>"
" <Placemark>"
" <gx:Track>"
" <when></when>"
" <when></when>"
" <when></when>"
" <when></when>"
" <when></when>"
" <when></when>"
" <when></when>"
" <gx:coord>-122.207881 37.371915 156.000000</gx:coord>"
" <gx:coord>-122.205712 37.373288 152.000000</gx:coord>"
" <gx:coord>-122.204678 37.373939 147.000000</gx:coord>"
" <gx:coord>-122.203572 37.374630 142.199997</gx:coord>"
" <gx:coord>-122.203451 37.374706 141.800003</gx:coord>"
" <gx:coord>-122.203329 37.374780 141.199997</gx:coord>"
" <gx:coord>-122.203207 37.374857 140.199997</gx:coord>"
" </gx:Track>"
" </Placemark>"
"</Folder>"
"</kml>");
GeoDataDocument *dataDocument = parseKml(content);
GeoDataFolder *folder = dataDocument->folderList().at(0);
QCOMPARE(folder->placemarkList().size(), 1);
GeoDataPlacemark *placemark = folder->placemarkList().at(0);
QCOMPARE(placemark->geometry()->geometryId(), GeoDataTrackId);
auto track = static_cast<GeoDataTrack *>(placemark->geometry());
QCOMPARE(track->size(), 7);
{
GeoDataCoordinates coord = track->coordinatesList().at(0);
QCOMPARE(coord.longitude(GeoDataCoordinates::Degree), -122.207881);
QCOMPARE(coord.latitude(GeoDataCoordinates::Degree), 37.371915);
QCOMPARE(coord.altitude(), 156.000000);
}
{
const GeoDataLineString *lineString = track->lineString();
QCOMPARE(lineString->size(), 7);
GeoDataCoordinates coord = lineString->at(0);
QCOMPARE(coord.longitude(GeoDataCoordinates::Degree), -122.207881);
QCOMPARE(coord.latitude(GeoDataCoordinates::Degree), 37.371915);
QCOMPARE(coord.altitude(), 156.000000);
}
delete dataDocument;
}
QTEST_MAIN(TestGeoDataTrack)
#include "TestGeoDataTrack.moc"
|