| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the test suite of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT |
| 21 | ** included in the packaging of this file. Please review the following |
| 22 | ** information to ensure the GNU General Public License requirements will |
| 23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
| 24 | ** |
| 25 | ** $QT_END_LICENSE$ |
| 26 | ** |
| 27 | ****************************************************************************/ |
| 28 | |
| 29 | //TESTED_COMPONENT=src/location |
| 30 | |
| 31 | #include "../utils/qlocationtestutils_p.h" |
| 32 | |
| 33 | #include <QtPositioning/qgeocoordinate.h> |
| 34 | #include <qtest.h> |
| 35 | |
| 36 | #include <QMetaType> |
| 37 | #include <QDebug> |
| 38 | |
| 39 | #include <float.h> |
| 40 | |
| 41 | QT_USE_NAMESPACE |
| 42 | |
| 43 | Q_DECLARE_METATYPE(QGeoCoordinate::CoordinateFormat) |
| 44 | Q_DECLARE_METATYPE(QGeoCoordinate::CoordinateType) |
| 45 | |
| 46 | static const QGeoCoordinate BRISBANE(-27.46758, 153.027892); |
| 47 | static const QGeoCoordinate MELBOURNE(-37.814251, 144.963169); |
| 48 | static const QGeoCoordinate LONDON(51.500152, -0.126236); |
| 49 | static const QGeoCoordinate NEW_YORK(40.71453, -74.00713); |
| 50 | static const QGeoCoordinate NORTH_POLE(90, 0); |
| 51 | static const QGeoCoordinate SOUTH_POLE(-90, 0); |
| 52 | |
| 53 | static const QChar DEGREES_SYMB(0x00B0); |
| 54 | |
| 55 | |
| 56 | QByteArray tst_qgeocoordinate_debug; |
| 57 | |
| 58 | void tst_qgeocoordinate_messageHandler(QtMsgType type, const QMessageLogContext &, const QString &msg) |
| 59 | { |
| 60 | switch (type) { |
| 61 | case QtDebugMsg : |
| 62 | tst_qgeocoordinate_debug = msg.toLocal8Bit(); |
| 63 | break; |
| 64 | default: |
| 65 | break; |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | |
| 70 | class tst_QGeoCoordinate : public QObject |
| 71 | { |
| 72 | Q_OBJECT |
| 73 | |
| 74 | private: |
| 75 | enum TestDataType { |
| 76 | Latitude, |
| 77 | Longitude, |
| 78 | Altitude |
| 79 | }; |
| 80 | |
| 81 | private slots: |
| 82 | void initTestcase() |
| 83 | { |
| 84 | qRegisterMetaType<QGeoCoordinate>(); |
| 85 | QMetaType::registerEqualsComparator<QGeoCoordinate>(); |
| 86 | } |
| 87 | |
| 88 | void constructor() |
| 89 | { |
| 90 | QGeoCoordinate c; |
| 91 | QVERIFY(!c.isValid()); |
| 92 | QCOMPARE(c, QGeoCoordinate()); |
| 93 | } |
| 94 | |
| 95 | void constructor_lat_long() |
| 96 | { |
| 97 | QFETCH(double, latitude); |
| 98 | QFETCH(double, longitude); |
| 99 | QFETCH(QGeoCoordinate::CoordinateType, type); |
| 100 | |
| 101 | QGeoCoordinate c(latitude, longitude); |
| 102 | QCOMPARE(c.type(), type); |
| 103 | if (type != QGeoCoordinate::InvalidCoordinate) { |
| 104 | QVERIFY(c.isValid()); |
| 105 | QCOMPARE(c.latitude(), latitude); |
| 106 | QCOMPARE(c.longitude(), longitude); |
| 107 | } else { |
| 108 | QVERIFY(!c.isValid()); |
| 109 | QVERIFY(c.latitude() != latitude); |
| 110 | QVERIFY(c.longitude() != longitude); |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | void constructor_lat_long_data() |
| 115 | { |
| 116 | QTest::addColumn<double>(name: "latitude" ); |
| 117 | QTest::addColumn<double>(name: "longitude" ); |
| 118 | QTest::addColumn<QGeoCoordinate::CoordinateType>(name: "type" ); |
| 119 | |
| 120 | QTest::newRow(dataTag: "both zero" ) << 0.0 << 0.0 << QGeoCoordinate::Coordinate2D; |
| 121 | QTest::newRow(dataTag: "both negative" ) << -1.0 << -1.0 << QGeoCoordinate::Coordinate2D; |
| 122 | QTest::newRow(dataTag: "both positive" ) << 1.0 << 1.0 << QGeoCoordinate::Coordinate2D; |
| 123 | QTest::newRow(dataTag: "latitude negative" ) << -1.0 << 1.0 << QGeoCoordinate::Coordinate2D; |
| 124 | QTest::newRow(dataTag: "longitude negative" ) << 1.0 << -1.0 << QGeoCoordinate::Coordinate2D; |
| 125 | |
| 126 | QTest::newRow(dataTag: "both too high" ) << 90.1 << 180.1 << QGeoCoordinate::InvalidCoordinate; |
| 127 | QTest::newRow(dataTag: "latitude too high" ) << 90.1 << 0.1 << QGeoCoordinate::InvalidCoordinate; |
| 128 | QTest::newRow(dataTag: "longitude too high" ) << 0.1 << 180.1 << QGeoCoordinate::InvalidCoordinate; |
| 129 | |
| 130 | QTest::newRow(dataTag: "both too low" ) << -90.1 << -180.1 << QGeoCoordinate::InvalidCoordinate; |
| 131 | QTest::newRow(dataTag: "latitude too low" ) << -90.1 << 0.1 << QGeoCoordinate::InvalidCoordinate; |
| 132 | QTest::newRow(dataTag: "longitude too low" ) << 0.1 << -180.1 << QGeoCoordinate::InvalidCoordinate; |
| 133 | |
| 134 | QTest::newRow(dataTag: "both not too high" ) << 90.0 << 180.0 << QGeoCoordinate::Coordinate2D; |
| 135 | QTest::newRow(dataTag: "both not too low" ) << -90.0 << -180.0 << QGeoCoordinate::Coordinate2D; |
| 136 | |
| 137 | QTest::newRow(dataTag: "latitude too high and longitude too low" ) << 90.1 << -180.1 << QGeoCoordinate::InvalidCoordinate; |
| 138 | QTest::newRow(dataTag: "latitude too low and longitude too high" ) << -90.1 << 180.1 << QGeoCoordinate::InvalidCoordinate; |
| 139 | } |
| 140 | |
| 141 | void constructor_lat_long_alt() |
| 142 | { |
| 143 | QFETCH(double, latitude); |
| 144 | QFETCH(double, longitude); |
| 145 | QFETCH(double, altitude); |
| 146 | QFETCH(QGeoCoordinate::CoordinateType, type); |
| 147 | |
| 148 | QGeoCoordinate c(latitude, longitude, altitude); |
| 149 | QCOMPARE(c.type(), type); |
| 150 | if (type != QGeoCoordinate::InvalidCoordinate) { |
| 151 | QCOMPARE(c.latitude(), latitude); |
| 152 | QCOMPARE(c.longitude(), longitude); |
| 153 | QCOMPARE(c.altitude(), altitude); |
| 154 | } else { |
| 155 | QVERIFY(!c.isValid()); |
| 156 | QVERIFY(c.latitude() != latitude); |
| 157 | QVERIFY(c.longitude() != longitude); |
| 158 | QVERIFY(c.altitude() != altitude); |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | void constructor_lat_long_alt_data() |
| 163 | { |
| 164 | QTest::addColumn<double>(name: "latitude" ); |
| 165 | QTest::addColumn<double>(name: "longitude" ); |
| 166 | QTest::addColumn<double>(name: "altitude" ); |
| 167 | QTest::addColumn<QGeoCoordinate::CoordinateType>(name: "type" ); |
| 168 | |
| 169 | QTest::newRow(dataTag: "all zero" ) << 0.0 << 0.0 << 0.0 << QGeoCoordinate::Coordinate3D; |
| 170 | QTest::newRow(dataTag: "all negative" ) << -1.0 << -1.0 << -2.0 << QGeoCoordinate::Coordinate3D; |
| 171 | QTest::newRow(dataTag: "all positive" ) << 1.0 << 1.0 << 4.0 << QGeoCoordinate::Coordinate3D; |
| 172 | |
| 173 | QTest::newRow(dataTag: "latitude negative" ) << -1.0 << 1.0 << 1.0 << QGeoCoordinate::Coordinate3D; |
| 174 | QTest::newRow(dataTag: "longitude negative" ) << 1.0 << -1.0 << 1.0 << QGeoCoordinate::Coordinate3D; |
| 175 | QTest::newRow(dataTag: "altitude negative" ) << 1.0 << 1.0 << -1.0 << QGeoCoordinate::Coordinate3D; |
| 176 | |
| 177 | QTest::newRow(dataTag: "altitude not too high" ) << 1.0 << 1.0 << DBL_MAX << QGeoCoordinate::Coordinate3D; |
| 178 | QTest::newRow(dataTag: "altitude not too low" ) << 1.0 << 1.0 << DBL_MIN << QGeoCoordinate::Coordinate3D; |
| 179 | |
| 180 | QTest::newRow(dataTag: "all not too high" ) << 90.0 << 180.0 << DBL_MAX << QGeoCoordinate::Coordinate3D; |
| 181 | QTest::newRow(dataTag: "all not too low" ) << -90.0 << -180.0 << DBL_MIN << QGeoCoordinate::Coordinate3D; |
| 182 | |
| 183 | QTest::newRow(dataTag: "all too high" ) << 90.1 << 180.1 << DBL_MAX << QGeoCoordinate::InvalidCoordinate; |
| 184 | QTest::newRow(dataTag: "all too low" ) << -90.1 << -180.1 << DBL_MIN << QGeoCoordinate::InvalidCoordinate; |
| 185 | } |
| 186 | |
| 187 | void copy_constructor() |
| 188 | { |
| 189 | QFETCH(QGeoCoordinate, c); |
| 190 | |
| 191 | QGeoCoordinate copy(c); |
| 192 | QCOMPARE(copy.type(), c.type()); |
| 193 | if (c.type() != QGeoCoordinate::InvalidCoordinate) { |
| 194 | QCOMPARE(copy.latitude(), c.latitude()); |
| 195 | QCOMPARE(copy.longitude(), c.longitude()); |
| 196 | if (c.type() == QGeoCoordinate::Coordinate3D) |
| 197 | QCOMPARE(copy.altitude(), c.altitude()); |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | void copy_constructor_data() |
| 202 | { |
| 203 | QTest::addColumn<QGeoCoordinate>(name: "c" ); |
| 204 | |
| 205 | QTest::newRow(dataTag: "no argument" ) << QGeoCoordinate(); |
| 206 | QTest::newRow(dataTag: "latitude, longitude arguments all zero" ) << QGeoCoordinate(0.0, 0.0); |
| 207 | |
| 208 | QTest::newRow(dataTag: "latitude, longitude arguments not too high" ) << QGeoCoordinate(90.0, 180.0); |
| 209 | QTest::newRow(dataTag: "latitude, longitude arguments not too low" ) << QGeoCoordinate(-90.0, -180.0); |
| 210 | QTest::newRow(dataTag: "latitude, longitude arguments too high" ) << QGeoCoordinate(90.1, 180.1); |
| 211 | QTest::newRow(dataTag: "latitude, longitude arguments too low" ) << QGeoCoordinate(-90.1, -180.1); |
| 212 | |
| 213 | QTest::newRow(dataTag: "latitude, longitude, altitude arguments all zero" ) << QGeoCoordinate(0.0, 0.0, 0.0); |
| 214 | QTest::newRow(dataTag: "latitude, longitude, altitude arguments not too high values" ) << QGeoCoordinate(90.0, 180.0, DBL_MAX); |
| 215 | QTest::newRow(dataTag: "latitude, longitude, altitude arguments not too low values" ) << QGeoCoordinate(-90.0, -180.0, DBL_MIN); |
| 216 | |
| 217 | QTest::newRow(dataTag: "latitude, longitude, altitude arguments too high latitude & longitude" ) << QGeoCoordinate(90.1, 180.1, DBL_MAX); |
| 218 | QTest::newRow(dataTag: "latitude, longitude, altitude arguments too low latitude & longitude" ) << QGeoCoordinate(-90.1, -180.1, DBL_MAX); |
| 219 | } |
| 220 | |
| 221 | void destructor() |
| 222 | { |
| 223 | QGeoCoordinate *coordinate; |
| 224 | |
| 225 | coordinate = new QGeoCoordinate(); |
| 226 | delete coordinate; |
| 227 | |
| 228 | coordinate = new QGeoCoordinate(0.0, 0.0); |
| 229 | delete coordinate; |
| 230 | |
| 231 | coordinate = new QGeoCoordinate(0.0, 0.0, 0.0); |
| 232 | delete coordinate; |
| 233 | |
| 234 | coordinate = new QGeoCoordinate(90.0, 180.0); |
| 235 | delete coordinate; |
| 236 | |
| 237 | coordinate = new QGeoCoordinate(-90.0, -180.0); |
| 238 | delete coordinate; |
| 239 | |
| 240 | coordinate = new QGeoCoordinate(90.1, 180.1); |
| 241 | delete coordinate; |
| 242 | |
| 243 | coordinate = new QGeoCoordinate(-90.1, -180.1); |
| 244 | delete coordinate; |
| 245 | } |
| 246 | |
| 247 | void destructor2() |
| 248 | { |
| 249 | QFETCH(QGeoCoordinate, c); |
| 250 | QGeoCoordinate *coordinate = new QGeoCoordinate(c); |
| 251 | delete coordinate; |
| 252 | } |
| 253 | |
| 254 | void destructor2_data() |
| 255 | { |
| 256 | copy_constructor_data(); |
| 257 | } |
| 258 | |
| 259 | void assign() |
| 260 | { |
| 261 | QFETCH(QGeoCoordinate, c); |
| 262 | |
| 263 | QGeoCoordinate c1 = c; |
| 264 | QCOMPARE(c.type(), c1.type()); |
| 265 | if (c.isValid()) { |
| 266 | QCOMPARE(c.latitude(), c.latitude()); |
| 267 | QCOMPARE(c.longitude(), c.longitude()); |
| 268 | if (c.type() == QGeoCoordinate::Coordinate3D) |
| 269 | QCOMPARE(c.altitude(), c.altitude()); |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | void assign_data() |
| 274 | { |
| 275 | copy_constructor_data(); |
| 276 | } |
| 277 | |
| 278 | void comparison() |
| 279 | { |
| 280 | QFETCH(QGeoCoordinate, c1); |
| 281 | QFETCH(QGeoCoordinate, c2); |
| 282 | QFETCH(bool, result); |
| 283 | |
| 284 | QCOMPARE(c1 == c2, result); |
| 285 | QVariant v1 = QVariant::fromValue(value: c1); |
| 286 | QVariant v2 = QVariant::fromValue(value: c2); |
| 287 | QCOMPARE(v2 == v1, result); |
| 288 | } |
| 289 | |
| 290 | void comparison_data() |
| 291 | { |
| 292 | QTest::addColumn<QGeoCoordinate>(name: "c1" ); |
| 293 | QTest::addColumn<QGeoCoordinate>(name: "c2" ); |
| 294 | QTest::addColumn<bool>(name: "result" ); |
| 295 | |
| 296 | QTest::newRow(dataTag: "Invalid != BRISBANE" ) |
| 297 | << QGeoCoordinate(-190,-1000) << BRISBANE << false; |
| 298 | QTest::newRow(dataTag: "BRISBANE != MELBOURNE" ) |
| 299 | << BRISBANE << MELBOURNE << false; |
| 300 | QTest::newRow(dataTag: "equal" ) |
| 301 | << BRISBANE << BRISBANE << true; |
| 302 | QTest::newRow(dataTag: "LONDON != uninitialized data" ) |
| 303 | << LONDON << QGeoCoordinate() << false; |
| 304 | QTest::newRow(dataTag: "uninitialized data == uninitialized data" ) |
| 305 | << QGeoCoordinate() << QGeoCoordinate() << true; |
| 306 | QTest::newRow(dataTag: "invalid == same invalid" ) |
| 307 | << QGeoCoordinate(-190,-1000) << QGeoCoordinate(-190,-1000) << true; |
| 308 | QTest::newRow(dataTag: "invalid == different invalid" ) |
| 309 | << QGeoCoordinate(-190,-1000) << QGeoCoordinate(190,1000) << true; |
| 310 | QTest::newRow(dataTag: "valid != another valid" ) |
| 311 | << QGeoCoordinate(-90,-180) << QGeoCoordinate(-45,+45) << false; |
| 312 | QTest::newRow(dataTag: "valid == same valid" ) |
| 313 | << QGeoCoordinate(-90,-180) << QGeoCoordinate(-90,-180) << true; |
| 314 | QTest::newRow(dataTag: "different longitudes at north pole are equal" ) |
| 315 | << QGeoCoordinate(90, 0) << QGeoCoordinate(90, 45) << true; |
| 316 | QTest::newRow(dataTag: "different longitudes at south pole are equal" ) |
| 317 | << QGeoCoordinate(-90, 0) << QGeoCoordinate(-90, 45) << true; |
| 318 | } |
| 319 | |
| 320 | void type() |
| 321 | { |
| 322 | QFETCH(QGeoCoordinate, c); |
| 323 | QFETCH(QGeoCoordinate::CoordinateType, type); |
| 324 | |
| 325 | QCOMPARE(c.type(), type); |
| 326 | } |
| 327 | |
| 328 | void type_data() |
| 329 | { |
| 330 | QTest::addColumn<QGeoCoordinate>(name: "c" ); |
| 331 | QTest::addColumn<QGeoCoordinate::CoordinateType>(name: "type" ); |
| 332 | |
| 333 | QGeoCoordinate c; |
| 334 | |
| 335 | QTest::newRow(dataTag: "no values set" ) << c << QGeoCoordinate::InvalidCoordinate; |
| 336 | |
| 337 | c.setAltitude(1.0); |
| 338 | QTest::newRow(dataTag: "only altitude is set" ) << c << QGeoCoordinate::InvalidCoordinate; |
| 339 | |
| 340 | c.setLongitude(1.0); |
| 341 | QTest::newRow(dataTag: "only latitude and altitude is set" ) << c << QGeoCoordinate::InvalidCoordinate; |
| 342 | |
| 343 | c.setLatitude(-1.0); |
| 344 | QTest::newRow(dataTag: "all valid: 3D Coordinate" ) << c << QGeoCoordinate::Coordinate3D; |
| 345 | |
| 346 | c.setLatitude(-90.1); |
| 347 | QTest::newRow(dataTag: "too low latitude and valid longitude" ) << c << QGeoCoordinate::InvalidCoordinate; |
| 348 | |
| 349 | c.setLongitude(-180.1); |
| 350 | c.setLatitude(90.0); |
| 351 | QTest::newRow(dataTag: "valid latitude and too low longitude" ) << c << QGeoCoordinate::InvalidCoordinate; |
| 352 | |
| 353 | c.setLatitude(90.1); |
| 354 | c.setLongitude(-180.0); |
| 355 | QTest::newRow(dataTag: "too high latitude and valid longitude" ) << c << QGeoCoordinate::InvalidCoordinate; |
| 356 | |
| 357 | c.setLatitude(-90.0); |
| 358 | c.setLongitude(180.1); |
| 359 | QTest::newRow(dataTag: "valid latitude and too high longitude" ) << c << QGeoCoordinate::InvalidCoordinate; |
| 360 | } |
| 361 | |
| 362 | void valid() |
| 363 | { |
| 364 | QFETCH(QGeoCoordinate, c); |
| 365 | QCOMPARE(c.isValid(), c.type() != QGeoCoordinate::InvalidCoordinate); |
| 366 | } |
| 367 | |
| 368 | void valid_data() |
| 369 | { |
| 370 | type_data(); |
| 371 | } |
| 372 | |
| 373 | void addDataValues(TestDataType type) |
| 374 | { |
| 375 | QTest::addColumn<double>(name: "value" ); |
| 376 | QTest::addColumn<bool>(name: "valid" ); |
| 377 | |
| 378 | QTest::newRow(dataTag: "negative" ) << -1.0 << true; |
| 379 | QTest::newRow(dataTag: "zero" ) << 0.0 << true; |
| 380 | QTest::newRow(dataTag: "positive" ) << 1.0 << true; |
| 381 | |
| 382 | switch (type) { |
| 383 | case Latitude: |
| 384 | QTest::newRow(dataTag: "too low" ) << -90.1 << false; |
| 385 | QTest::newRow(dataTag: "not too low" ) << -90.0 << true; |
| 386 | QTest::newRow(dataTag: "not too hight" ) << 90.0 << true; |
| 387 | QTest::newRow(dataTag: "too high" ) << 90.1; |
| 388 | break; |
| 389 | case Longitude: |
| 390 | QTest::newRow(dataTag: "too low" ) << -180.1 << false; |
| 391 | QTest::newRow(dataTag: "not too low" ) << -180.0 << true; |
| 392 | QTest::newRow(dataTag: "not too hight" ) << 180.0 << true; |
| 393 | QTest::newRow(dataTag: "too high" ) << 180.1; |
| 394 | break; |
| 395 | case Altitude: |
| 396 | break; |
| 397 | } |
| 398 | } |
| 399 | |
| 400 | void latitude() |
| 401 | { |
| 402 | QFETCH(double, value); |
| 403 | QGeoCoordinate c; |
| 404 | c.setLatitude(value); |
| 405 | QCOMPARE(c.latitude(), value); |
| 406 | |
| 407 | QGeoCoordinate c2 = c; |
| 408 | QCOMPARE(c.latitude(), value); |
| 409 | QCOMPARE(c2, c); |
| 410 | } |
| 411 | void latitude_data() { addDataValues(type: Latitude); } |
| 412 | |
| 413 | void longitude() |
| 414 | { |
| 415 | QFETCH(double, value); |
| 416 | QGeoCoordinate c; |
| 417 | c.setLongitude(value); |
| 418 | QCOMPARE(c.longitude(), value); |
| 419 | |
| 420 | QGeoCoordinate c2 = c; |
| 421 | QCOMPARE(c.longitude(), value); |
| 422 | QCOMPARE(c2, c); |
| 423 | } |
| 424 | void longitude_data() { addDataValues(type: Longitude); } |
| 425 | |
| 426 | void altitude() |
| 427 | { |
| 428 | QFETCH(double, value); |
| 429 | QGeoCoordinate c; |
| 430 | c.setAltitude(value); |
| 431 | QCOMPARE(c.altitude(), value); |
| 432 | |
| 433 | QGeoCoordinate c2 = c; |
| 434 | QCOMPARE(c.altitude(), value); |
| 435 | QCOMPARE(c2, c); |
| 436 | } |
| 437 | void altitude_data() { addDataValues(type: Altitude); } |
| 438 | |
| 439 | void distanceTo() |
| 440 | { |
| 441 | QFETCH(QGeoCoordinate, c1); |
| 442 | QFETCH(QGeoCoordinate, c2); |
| 443 | QFETCH(qreal, distance); |
| 444 | |
| 445 | QCOMPARE(QString::number(c1.distanceTo(c2)), QString::number(distance)); |
| 446 | } |
| 447 | |
| 448 | void distanceTo_data() |
| 449 | { |
| 450 | QTest::addColumn<QGeoCoordinate>(name: "c1" ); |
| 451 | QTest::addColumn<QGeoCoordinate>(name: "c2" ); |
| 452 | QTest::addColumn<qreal>(name: "distance" ); |
| 453 | |
| 454 | QTest::newRow(dataTag: "invalid coord 1" ) |
| 455 | << QGeoCoordinate() << BRISBANE << qreal(0.0); |
| 456 | QTest::newRow(dataTag: "invalid coord 2" ) |
| 457 | << BRISBANE << QGeoCoordinate() << qreal(0.0); |
| 458 | QTest::newRow(dataTag: "brisbane -> melbourne" ) |
| 459 | << BRISBANE << MELBOURNE << qreal(1374820.1618767744); |
| 460 | QTest::newRow(dataTag: "london -> new york" ) |
| 461 | << LONDON << NEW_YORK << qreal(5570538.4987236429); |
| 462 | QTest::newRow(dataTag: "north pole -> south pole" ) |
| 463 | << NORTH_POLE << SOUTH_POLE << qreal(20015109.4154876769); |
| 464 | } |
| 465 | |
| 466 | void azimuthTo() |
| 467 | { |
| 468 | QFETCH(QGeoCoordinate, c1); |
| 469 | QFETCH(QGeoCoordinate, c2); |
| 470 | QFETCH(qreal, azimuth); |
| 471 | |
| 472 | qreal result = c1.azimuthTo(other: c2); |
| 473 | QVERIFY(result >= 0.0); |
| 474 | QVERIFY(result < 360.0); |
| 475 | QCOMPARE(QString::number(result), QString::number(azimuth)); |
| 476 | } |
| 477 | |
| 478 | void azimuthTo_data() |
| 479 | { |
| 480 | QTest::addColumn<QGeoCoordinate>(name: "c1" ); |
| 481 | QTest::addColumn<QGeoCoordinate>(name: "c2" ); |
| 482 | QTest::addColumn<qreal>(name: "azimuth" ); |
| 483 | |
| 484 | QTest::newRow(dataTag: "invalid coord 1" ) |
| 485 | << QGeoCoordinate() << BRISBANE << qreal(0.0); |
| 486 | QTest::newRow(dataTag: "invalid coord 2" ) |
| 487 | << BRISBANE << QGeoCoordinate() << qreal(0.0); |
| 488 | QTest::newRow(dataTag: "brisbane -> melbourne" ) |
| 489 | << BRISBANE << MELBOURNE << qreal(211.1717286649); |
| 490 | QTest::newRow(dataTag: "london -> new york" ) |
| 491 | << LONDON << NEW_YORK << qreal(288.3388804508); |
| 492 | QTest::newRow(dataTag: "north pole -> south pole" ) |
| 493 | << NORTH_POLE << SOUTH_POLE << qreal(180.0); |
| 494 | QTest::newRow(dataTag: "Almost 360degrees bearing" ) |
| 495 | << QGeoCoordinate(0.5,45.0,0.0) << QGeoCoordinate(0.5,-134.9999651,0.0) << qreal(359.998); |
| 496 | } |
| 497 | |
| 498 | void atDistanceAndAzimuth() |
| 499 | { |
| 500 | QFETCH(QGeoCoordinate, origin); |
| 501 | QFETCH(qreal, distance); |
| 502 | QFETCH(qreal, azimuth); |
| 503 | QFETCH(QGeoCoordinate, result); |
| 504 | |
| 505 | QCOMPARE(result, origin.atDistanceAndAzimuth(distance, azimuth)); |
| 506 | } |
| 507 | |
| 508 | void atDistanceAndAzimuth_data() |
| 509 | { |
| 510 | QTest::addColumn<QGeoCoordinate>(name: "origin" ); |
| 511 | QTest::addColumn<qreal>(name: "distance" ); |
| 512 | QTest::addColumn<qreal>(name: "azimuth" ); |
| 513 | QTest::addColumn<QGeoCoordinate>(name: "result" ); |
| 514 | |
| 515 | QTest::newRow(dataTag: "invalid coord" ) |
| 516 | << QGeoCoordinate() |
| 517 | << qreal(1000.0) |
| 518 | << qreal(10.0) |
| 519 | << QGeoCoordinate(); |
| 520 | if (sizeof(qreal) == sizeof(double)) { |
| 521 | QTest::newRow(dataTag: "brisbane -> melbourne" ) |
| 522 | << BRISBANE |
| 523 | << qreal(1374820.1618767744) |
| 524 | << qreal(211.1717286649) |
| 525 | << MELBOURNE; |
| 526 | QTest::newRow(dataTag: "london -> new york" ) |
| 527 | << LONDON |
| 528 | << qreal(5570538.4987236429) |
| 529 | << qreal(288.3388804508) |
| 530 | << NEW_YORK; |
| 531 | QTest::newRow(dataTag: "north pole -> south pole" ) |
| 532 | << NORTH_POLE |
| 533 | << qreal(20015109.4154876769) |
| 534 | << qreal(180.0) |
| 535 | << SOUTH_POLE; |
| 536 | } else { |
| 537 | QTest::newRow(dataTag: "brisbane -> melbourne" ) |
| 538 | << BRISBANE |
| 539 | << qreal(1374820.1618767744) |
| 540 | << qreal(211.1717286649) |
| 541 | << QGeoCoordinate(-37.8142515084775, 144.963170622944); |
| 542 | QTest::newRow(dataTag: "london -> new york" ) |
| 543 | << LONDON |
| 544 | << qreal(5570538.4987236429) |
| 545 | << qreal(288.3388804508) |
| 546 | << QGeoCoordinate(40.7145220608416, -74.0071216045375); |
| 547 | QTest::newRow(dataTag: "north pole -> south pole" ) |
| 548 | << NORTH_POLE |
| 549 | << qreal(20015109.4154876769) |
| 550 | << qreal(180.0) |
| 551 | << QGeoCoordinate(-89.9999947369857, -90.0); |
| 552 | } |
| 553 | } |
| 554 | |
| 555 | void degreesToString() |
| 556 | { |
| 557 | QFETCH(QGeoCoordinate, coord); |
| 558 | QFETCH(QGeoCoordinate::CoordinateFormat, format); |
| 559 | QFETCH(QString, string); |
| 560 | |
| 561 | QCOMPARE(coord.toString(format), string); |
| 562 | } |
| 563 | |
| 564 | void degreesToString_data() |
| 565 | { |
| 566 | QTest::addColumn<QGeoCoordinate>(name: "coord" ); |
| 567 | QTest::addColumn<QGeoCoordinate::CoordinateFormat>(name: "format" ); |
| 568 | QTest::addColumn<QString>(name: "string" ); |
| 569 | |
| 570 | QGeoCoordinate northEast(27.46758, 153.027892); |
| 571 | QGeoCoordinate northEastWithAlt(27.46758, 153.027892, 28.23411); |
| 572 | QGeoCoordinate southEast(-27.46758, 153.027892); |
| 573 | QGeoCoordinate southEastWithAlt(-27.46758, 153.027892, 28.23411); |
| 574 | QGeoCoordinate northWest(27.46758, -153.027892); |
| 575 | QGeoCoordinate northWestWithAlt(27.46758, -153.027892, 28.23411); |
| 576 | QGeoCoordinate southWest(-27.46758, -153.027892); |
| 577 | QGeoCoordinate southWestWithAlt(-27.46758, -153.027892, 28.23411); |
| 578 | |
| 579 | QGeoCoordinate empty; |
| 580 | QGeoCoordinate toohigh(90.1, 180.1); |
| 581 | QGeoCoordinate toolow(-90.1, -180.1); |
| 582 | QGeoCoordinate zeroLatLong(0.0, 0.0); |
| 583 | QGeoCoordinate allZero(0.0, 0.0, 0.0); |
| 584 | |
| 585 | QTest::newRow(dataTag: "empty, dd, no hemisphere" ) |
| 586 | << empty << QGeoCoordinate::Degrees |
| 587 | << QString(); |
| 588 | QTest::newRow(dataTag: "empty, dd, hemisphere" ) |
| 589 | << empty << QGeoCoordinate::DegreesWithHemisphere |
| 590 | << QString(); |
| 591 | QTest::newRow(dataTag: "empty, dm, no hemisphere" ) |
| 592 | << empty << QGeoCoordinate::DegreesMinutes |
| 593 | << QString(); |
| 594 | QTest::newRow(dataTag: "empty, dm, hemisphere" ) |
| 595 | << empty << QGeoCoordinate::DegreesMinutesWithHemisphere |
| 596 | << QString(); |
| 597 | QTest::newRow(dataTag: "empty, dms, no hemisphere" ) |
| 598 | << empty << QGeoCoordinate::DegreesMinutesSeconds |
| 599 | << QString(); |
| 600 | QTest::newRow(dataTag: "empty, dms, hemisphere" ) |
| 601 | << empty << QGeoCoordinate::DegreesMinutesSecondsWithHemisphere |
| 602 | << QString(); |
| 603 | |
| 604 | QTest::newRow(dataTag: "too low, dd, no hemisphere" ) |
| 605 | << toolow << QGeoCoordinate::Degrees |
| 606 | << QString(); |
| 607 | QTest::newRow(dataTag: "too low, dd, hemisphere" ) |
| 608 | << toolow << QGeoCoordinate::DegreesWithHemisphere |
| 609 | << QString(); |
| 610 | QTest::newRow(dataTag: "too low, dm, no hemisphere" ) |
| 611 | << toolow << QGeoCoordinate::DegreesMinutes |
| 612 | << QString(); |
| 613 | QTest::newRow(dataTag: "too low, dm, hemisphere" ) |
| 614 | << toolow << QGeoCoordinate::DegreesMinutesWithHemisphere |
| 615 | << QString(); |
| 616 | QTest::newRow(dataTag: "too low, dms, no hemisphere" ) |
| 617 | << toolow << QGeoCoordinate::DegreesMinutesSeconds |
| 618 | << QString(); |
| 619 | QTest::newRow(dataTag: "too low, dms, hemisphere" ) |
| 620 | << toolow << QGeoCoordinate::DegreesMinutesSecondsWithHemisphere |
| 621 | << QString(); |
| 622 | |
| 623 | QTest::newRow(dataTag: "too high, dd, no hemisphere" ) |
| 624 | << toohigh << QGeoCoordinate::Degrees |
| 625 | << QString(); |
| 626 | QTest::newRow(dataTag: "too high, dd, hemisphere" ) |
| 627 | << toohigh << QGeoCoordinate::DegreesWithHemisphere |
| 628 | << QString(); |
| 629 | QTest::newRow(dataTag: "too high, dm, no hemisphere" ) |
| 630 | << toohigh << QGeoCoordinate::DegreesMinutes |
| 631 | << QString(); |
| 632 | QTest::newRow(dataTag: "too high, dm, hemisphere" ) |
| 633 | << toohigh << QGeoCoordinate::DegreesMinutesWithHemisphere |
| 634 | << QString(); |
| 635 | QTest::newRow(dataTag: "too high, dms, no hemisphere" ) |
| 636 | << toohigh << QGeoCoordinate::DegreesMinutesSeconds |
| 637 | << QString(); |
| 638 | QTest::newRow(dataTag: "too high, dms, hemisphere" ) |
| 639 | << toohigh << QGeoCoordinate::DegreesMinutesSecondsWithHemisphere |
| 640 | << QString(); |
| 641 | |
| 642 | QTest::newRow(dataTag: "zeroLatLong, dd, no hemisphere" ) |
| 643 | << zeroLatLong << QGeoCoordinate::Degrees |
| 644 | << QString("0.00000%1, 0.00000%1" ).arg(a: DEGREES_SYMB); |
| 645 | QTest::newRow(dataTag: "zeroLatLong, dd, hemisphere" ) |
| 646 | << zeroLatLong << QGeoCoordinate::DegreesWithHemisphere |
| 647 | << QString("0.00000%1, 0.00000%1" ).arg(a: DEGREES_SYMB); |
| 648 | QTest::newRow(dataTag: "zeroLatLong, dm, no hemisphere" ) |
| 649 | << zeroLatLong << QGeoCoordinate::DegreesMinutes |
| 650 | << QString("0%1 0.000', 0%1 0.000'" ).arg(a: DEGREES_SYMB); |
| 651 | QTest::newRow(dataTag: "zeroLatLong, dm, hemisphere" ) |
| 652 | << zeroLatLong << QGeoCoordinate::DegreesMinutesWithHemisphere |
| 653 | << QString("0%1 0.000', 0%1 0.000'" ).arg(a: DEGREES_SYMB); |
| 654 | QTest::newRow(dataTag: "zeroLatLong, dms, no hemisphere" ) |
| 655 | << zeroLatLong << QGeoCoordinate::DegreesMinutesSeconds |
| 656 | << QString("0%1 0' 0.0\", 0%1 0' 0.0\"" ).arg(a: DEGREES_SYMB); |
| 657 | QTest::newRow(dataTag: "zeroLatLong, dms, hemisphere" ) |
| 658 | << zeroLatLong << QGeoCoordinate::DegreesMinutesSecondsWithHemisphere |
| 659 | << QString("0%1 0' 0.0\", 0%1 0' 0.0\"" ).arg(a: DEGREES_SYMB); |
| 660 | |
| 661 | QTest::newRow(dataTag: "allZero, dd, no hemisphere" ) |
| 662 | << allZero << QGeoCoordinate::Degrees |
| 663 | << QString("0.00000%1, 0.00000%1, 0m" ).arg(a: DEGREES_SYMB); |
| 664 | QTest::newRow(dataTag: "allZero, dd, hemisphere" ) |
| 665 | << allZero << QGeoCoordinate::DegreesWithHemisphere |
| 666 | << QString("0.00000%1, 0.00000%1, 0m" ).arg(a: DEGREES_SYMB); |
| 667 | QTest::newRow(dataTag: "allZero, dm, no hemisphere" ) |
| 668 | << allZero << QGeoCoordinate::DegreesMinutes |
| 669 | << QString("0%1 0.000', 0%1 0.000', 0m" ).arg(a: DEGREES_SYMB); |
| 670 | QTest::newRow(dataTag: "allZero, dm, hemisphere" ) |
| 671 | << allZero << QGeoCoordinate::DegreesMinutesWithHemisphere |
| 672 | << QString("0%1 0.000', 0%1 0.000', 0m" ).arg(a: DEGREES_SYMB); |
| 673 | QTest::newRow(dataTag: "allZero, dms, no hemisphere" ) |
| 674 | << allZero << QGeoCoordinate::DegreesMinutesSeconds |
| 675 | << QString("0%1 0' 0.0\", 0%1 0' 0.0\", 0m" ).arg(a: DEGREES_SYMB); |
| 676 | QTest::newRow(dataTag: "allZero, dms, hemisphere" ) |
| 677 | << allZero << QGeoCoordinate::DegreesMinutesSecondsWithHemisphere |
| 678 | << QString("0%1 0' 0.0\", 0%1 0' 0.0\", 0m" ).arg(a: DEGREES_SYMB); |
| 679 | |
| 680 | QTest::newRow(dataTag: "NE, dd, no hemisphere" ) |
| 681 | << northEast << QGeoCoordinate::Degrees |
| 682 | << QString("27.46758%1, 153.02789%1" ).arg(a: DEGREES_SYMB); |
| 683 | QTest::newRow(dataTag: "NE, dd, hemisphere" ) |
| 684 | << northEast << QGeoCoordinate::DegreesWithHemisphere |
| 685 | << QString("27.46758%1 N, 153.02789%1 E" ).arg(a: DEGREES_SYMB); |
| 686 | QTest::newRow(dataTag: "NE, dm, no hemisphere" ) |
| 687 | << northEast << QGeoCoordinate::DegreesMinutes |
| 688 | << QString("27%1 28.055', 153%1 1.674'" ).arg(a: DEGREES_SYMB); |
| 689 | QTest::newRow(dataTag: "NE, dm, hemisphere" ) |
| 690 | << northEast << QGeoCoordinate::DegreesMinutesWithHemisphere |
| 691 | << QString("27%1 28.055' N, 153%1 1.674' E" ).arg(a: DEGREES_SYMB); |
| 692 | QTest::newRow(dataTag: "NE, dms, no hemisphere" ) |
| 693 | << northEast << QGeoCoordinate::DegreesMinutesSeconds |
| 694 | << QString("27%1 28' 3.3\", 153%1 1' 40.4\"" ).arg(a: DEGREES_SYMB); |
| 695 | QTest::newRow(dataTag: "NE, dms, hemisphere" ) |
| 696 | << northEast << QGeoCoordinate::DegreesMinutesSecondsWithHemisphere |
| 697 | << QString("27%1 28' 3.3\" N, 153%1 1' 40.4\" E" ).arg(a: DEGREES_SYMB); |
| 698 | |
| 699 | QTest::newRow(dataTag: "NE with alt, dd, no hemisphere" ) |
| 700 | << northEastWithAlt << QGeoCoordinate::Degrees |
| 701 | << QString("27.46758%1, 153.02789%1, 28.2341m" ).arg(a: DEGREES_SYMB); |
| 702 | QTest::newRow(dataTag: "NE with alt, dd, hemisphere" ) |
| 703 | << northEastWithAlt << QGeoCoordinate::DegreesWithHemisphere |
| 704 | << QString("27.46758%1 N, 153.02789%1 E, 28.2341m" ).arg(a: DEGREES_SYMB); |
| 705 | QTest::newRow(dataTag: "NE with alt, dm, no hemisphere" ) |
| 706 | << northEastWithAlt << QGeoCoordinate::DegreesMinutes |
| 707 | << QString("27%1 28.055', 153%1 1.674', 28.2341m" ).arg(a: DEGREES_SYMB); |
| 708 | QTest::newRow(dataTag: "NE with alt, dm, hemisphere" ) |
| 709 | << northEastWithAlt << QGeoCoordinate::DegreesMinutesWithHemisphere |
| 710 | << QString("27%1 28.055' N, 153%1 1.674' E, 28.2341m" ).arg(a: DEGREES_SYMB); |
| 711 | QTest::newRow(dataTag: "NE with alt, dms, no hemisphere" ) |
| 712 | << northEastWithAlt << QGeoCoordinate::DegreesMinutesSeconds |
| 713 | << QString("27%1 28' 3.3\", 153%1 1' 40.4\", 28.2341m" ).arg(a: DEGREES_SYMB); |
| 714 | QTest::newRow(dataTag: "NE with alt, dms, hemisphere" ) |
| 715 | << northEastWithAlt << QGeoCoordinate::DegreesMinutesSecondsWithHemisphere |
| 716 | << QString("27%1 28' 3.3\" N, 153%1 1' 40.4\" E, 28.2341m" ).arg(a: DEGREES_SYMB); |
| 717 | |
| 718 | QTest::newRow(dataTag: "SE, dd, no hemisphere" ) |
| 719 | << southEast << QGeoCoordinate::Degrees |
| 720 | << QString("-27.46758%1, 153.02789%1" ).arg(a: DEGREES_SYMB); |
| 721 | QTest::newRow(dataTag: "SE, dd, hemisphere" ) |
| 722 | << southEast << QGeoCoordinate::DegreesWithHemisphere |
| 723 | << QString("27.46758%1 S, 153.02789%1 E" ).arg(a: DEGREES_SYMB); |
| 724 | QTest::newRow(dataTag: "SE, dm, no hemisphere" ) |
| 725 | << southEast << QGeoCoordinate::DegreesMinutes |
| 726 | << QString("-27%1 28.055', 153%1 1.674'" ).arg(a: DEGREES_SYMB); |
| 727 | QTest::newRow(dataTag: "SE, dm, hemisphere" ) |
| 728 | << southEast << QGeoCoordinate::DegreesMinutesWithHemisphere |
| 729 | << QString("27%1 28.055' S, 153%1 1.674' E" ).arg(a: DEGREES_SYMB); |
| 730 | QTest::newRow(dataTag: "SE, dms, no hemisphere" ) |
| 731 | << southEast << QGeoCoordinate::DegreesMinutesSeconds |
| 732 | << QString("-27%1 28' 3.3\", 153%1 1' 40.4\"" ).arg(a: DEGREES_SYMB); |
| 733 | QTest::newRow(dataTag: "SE, dms, hemisphere" ) |
| 734 | << southEast << QGeoCoordinate::DegreesMinutesSecondsWithHemisphere |
| 735 | << QString("27%1 28' 3.3\" S, 153%1 1' 40.4\" E" ).arg(a: DEGREES_SYMB); |
| 736 | |
| 737 | QTest::newRow(dataTag: "SE with alt, dd, no hemisphere, 28.2341m" ) |
| 738 | << southEastWithAlt << QGeoCoordinate::Degrees |
| 739 | << QString("-27.46758%1, 153.02789%1, 28.2341m" ).arg(a: DEGREES_SYMB); |
| 740 | QTest::newRow(dataTag: "SE with alt, dd, hemisphere, 28.2341m" ) |
| 741 | << southEastWithAlt << QGeoCoordinate::DegreesWithHemisphere |
| 742 | << QString("27.46758%1 S, 153.02789%1 E, 28.2341m" ).arg(a: DEGREES_SYMB); |
| 743 | QTest::newRow(dataTag: "SE with alt, dm, no hemisphere, 28.2341m" ) |
| 744 | << southEastWithAlt << QGeoCoordinate::DegreesMinutes |
| 745 | << QString("-27%1 28.055', 153%1 1.674', 28.2341m" ).arg(a: DEGREES_SYMB); |
| 746 | QTest::newRow(dataTag: "SE with alt, dm, hemisphere, 28.2341m" ) |
| 747 | << southEastWithAlt << QGeoCoordinate::DegreesMinutesWithHemisphere |
| 748 | << QString("27%1 28.055' S, 153%1 1.674' E, 28.2341m" ).arg(a: DEGREES_SYMB); |
| 749 | QTest::newRow(dataTag: "SE with alt, dms, no hemisphere, 28.2341m" ) |
| 750 | << southEastWithAlt << QGeoCoordinate::DegreesMinutesSeconds |
| 751 | << QString("-27%1 28' 3.3\", 153%1 1' 40.4\", 28.2341m" ).arg(a: DEGREES_SYMB); |
| 752 | QTest::newRow(dataTag: "SE with alt, dms, hemisphere, 28.2341m" ) |
| 753 | << southEastWithAlt << QGeoCoordinate::DegreesMinutesSecondsWithHemisphere |
| 754 | << QString("27%1 28' 3.3\" S, 153%1 1' 40.4\" E, 28.2341m" ).arg(a: DEGREES_SYMB);; |
| 755 | |
| 756 | QTest::newRow(dataTag: "NW, dd, no hemisphere" ) |
| 757 | << northWest << QGeoCoordinate::Degrees |
| 758 | << QString("27.46758%1, -153.02789%1" ).arg(a: DEGREES_SYMB); |
| 759 | QTest::newRow(dataTag: "NW, dd, hemisphere" ) |
| 760 | << northWest << QGeoCoordinate::DegreesWithHemisphere |
| 761 | << QString("27.46758%1 N, 153.02789%1 W" ).arg(a: DEGREES_SYMB); |
| 762 | QTest::newRow(dataTag: "NW, dm, no hemisphere" ) |
| 763 | << northWest << QGeoCoordinate::DegreesMinutes |
| 764 | << QString("27%1 28.055', -153%1 1.674'" ).arg(a: DEGREES_SYMB); |
| 765 | QTest::newRow(dataTag: "NW, dm, hemisphere" ) |
| 766 | << northWest << QGeoCoordinate::DegreesMinutesWithHemisphere |
| 767 | << QString("27%1 28.055' N, 153%1 1.674' W" ).arg(a: DEGREES_SYMB); |
| 768 | QTest::newRow(dataTag: "NW, dms, no hemisphere" ) |
| 769 | << northWest << QGeoCoordinate::DegreesMinutesSeconds |
| 770 | << QString("27%1 28' 3.3\", -153%1 1' 40.4\"" ).arg(a: DEGREES_SYMB); |
| 771 | QTest::newRow(dataTag: "NW, dms, hemisphere" ) |
| 772 | << northWest << QGeoCoordinate::DegreesMinutesSecondsWithHemisphere |
| 773 | << QString("27%1 28' 3.3\" N, 153%1 1' 40.4\" W" ).arg(a: DEGREES_SYMB); |
| 774 | |
| 775 | QTest::newRow(dataTag: "NW with alt, dd, no hemisphere, 28.2341m" ) |
| 776 | << northWestWithAlt << QGeoCoordinate::Degrees |
| 777 | << QString("27.46758%1, -153.02789%1, 28.2341m" ).arg(a: DEGREES_SYMB); |
| 778 | QTest::newRow(dataTag: "NW with alt, dd, hemisphere, 28.2341m" ) |
| 779 | << northWestWithAlt << QGeoCoordinate::DegreesWithHemisphere |
| 780 | << QString("27.46758%1 N, 153.02789%1 W, 28.2341m" ).arg(a: DEGREES_SYMB); |
| 781 | QTest::newRow(dataTag: "NW with alt, dm, no hemisphere, 28.2341m" ) |
| 782 | << northWestWithAlt << QGeoCoordinate::DegreesMinutes |
| 783 | << QString("27%1 28.055', -153%1 1.674', 28.2341m" ).arg(a: DEGREES_SYMB); |
| 784 | QTest::newRow(dataTag: "NW with alt, dm, hemisphere, 28.2341m" ) |
| 785 | << northWestWithAlt << QGeoCoordinate::DegreesMinutesWithHemisphere |
| 786 | << QString("27%1 28.055' N, 153%1 1.674' W, 28.2341m" ).arg(a: DEGREES_SYMB); |
| 787 | QTest::newRow(dataTag: "NW with alt, dms, no hemisphere, 28.2341m" ) |
| 788 | << northWestWithAlt << QGeoCoordinate::DegreesMinutesSeconds |
| 789 | << QString("27%1 28' 3.3\", -153%1 1' 40.4\", 28.2341m" ).arg(a: DEGREES_SYMB); |
| 790 | QTest::newRow(dataTag: "NW with alt, dms, hemisphere, 28.2341m" ) |
| 791 | << northWestWithAlt << QGeoCoordinate::DegreesMinutesSecondsWithHemisphere |
| 792 | << QString("27%1 28' 3.3\" N, 153%1 1' 40.4\" W, 28.2341m" ).arg(a: DEGREES_SYMB); |
| 793 | |
| 794 | QTest::newRow(dataTag: "SW, dd, no hemisphere" ) |
| 795 | << southWest << QGeoCoordinate::Degrees |
| 796 | << QString("-27.46758%1, -153.02789%1" ).arg(a: DEGREES_SYMB); |
| 797 | QTest::newRow(dataTag: "SW, dd, hemisphere" ) |
| 798 | << southWest << QGeoCoordinate::DegreesWithHemisphere |
| 799 | << QString("27.46758%1 S, 153.02789%1 W" ).arg(a: DEGREES_SYMB); |
| 800 | QTest::newRow(dataTag: "SW, dm, no hemisphere" ) |
| 801 | << southWest << QGeoCoordinate::DegreesMinutes |
| 802 | << QString("-27%1 28.055', -153%1 1.674'" ).arg(a: DEGREES_SYMB); |
| 803 | QTest::newRow(dataTag: "SW, dm, hemisphere" ) |
| 804 | << southWest << QGeoCoordinate::DegreesMinutesWithHemisphere |
| 805 | << QString("27%1 28.055' S, 153%1 1.674' W" ).arg(a: DEGREES_SYMB); |
| 806 | QTest::newRow(dataTag: "SW, dms, no hemisphere" ) |
| 807 | << southWest << QGeoCoordinate::DegreesMinutesSeconds |
| 808 | << QString("-27%1 28' 3.3\", -153%1 1' 40.4\"" ).arg(a: DEGREES_SYMB); |
| 809 | QTest::newRow(dataTag: "SW, dms, hemisphere" ) |
| 810 | << southWest << QGeoCoordinate::DegreesMinutesSecondsWithHemisphere |
| 811 | << QString("27%1 28' 3.3\" S, 153%1 1' 40.4\" W" ).arg(a: DEGREES_SYMB); |
| 812 | |
| 813 | QTest::newRow(dataTag: "SW with alt, dd, no hemisphere, 28.2341m" ) |
| 814 | << southWestWithAlt << QGeoCoordinate::Degrees |
| 815 | << QString("-27.46758%1, -153.02789%1, 28.2341m" ).arg(a: DEGREES_SYMB); |
| 816 | QTest::newRow(dataTag: "SW with alt, dd, hemisphere, 28.2341m" ) |
| 817 | << southWestWithAlt << QGeoCoordinate::DegreesWithHemisphere |
| 818 | << QString("27.46758%1 S, 153.02789%1 W, 28.2341m" ).arg(a: DEGREES_SYMB); |
| 819 | QTest::newRow(dataTag: "SW with alt, dm, no hemisphere, 28.2341m" ) |
| 820 | << southWestWithAlt << QGeoCoordinate::DegreesMinutes |
| 821 | << QString("-27%1 28.055', -153%1 1.674', 28.2341m" ).arg(a: DEGREES_SYMB); |
| 822 | QTest::newRow(dataTag: "SW with alt, dm, hemisphere, 28.2341m" ) |
| 823 | << southWestWithAlt << QGeoCoordinate::DegreesMinutesWithHemisphere |
| 824 | << QString("27%1 28.055' S, 153%1 1.674' W, 28.2341m" ).arg(a: DEGREES_SYMB); |
| 825 | QTest::newRow(dataTag: "SW with alt, dms, no hemisphere, 28.2341m" ) |
| 826 | << southWestWithAlt << QGeoCoordinate::DegreesMinutesSeconds |
| 827 | << QString("-27%1 28' 3.3\", -153%1 1' 40.4\", 28.2341m" ).arg(a: DEGREES_SYMB); |
| 828 | QTest::newRow(dataTag: "SW with alt, dms, hemisphere, 28.2341m" ) |
| 829 | << southWestWithAlt << QGeoCoordinate::DegreesMinutesSecondsWithHemisphere |
| 830 | << QString("27%1 28' 3.3\" S, 153%1 1' 40.4\" W, 28.2341m" ).arg(a: DEGREES_SYMB); |
| 831 | |
| 832 | QTest::newRow(dataTag: "Wrap seconds to Minutes DMSH" ) |
| 833 | << QGeoCoordinate(1.1333333, 1.1333333) << QGeoCoordinate::DegreesMinutesSecondsWithHemisphere |
| 834 | << QString( "1%1 8' 0.0\" N, 1%1 8' 0.0\" E" ).arg(a: DEGREES_SYMB); |
| 835 | QTest::newRow(dataTag: "Wrap seconds to Minutes DMS" ) |
| 836 | << QGeoCoordinate(1.1333333, 1.1333333) << QGeoCoordinate::DegreesMinutesSeconds |
| 837 | << QString( "1%1 8' 0.0\", 1%1 8' 0.0\"" ).arg(a: DEGREES_SYMB); |
| 838 | QTest::newRow(dataTag: "Wrap minutes to Degrees DMH" ) |
| 839 | << QGeoCoordinate(1.999999, 1.999999) << QGeoCoordinate::DegreesMinutesWithHemisphere |
| 840 | << QString( "2%1 0.000' N, 2%1 0.000' E" ).arg(a: DEGREES_SYMB); |
| 841 | QTest::newRow(dataTag: "Wrap minutes to Degrees DM" ) |
| 842 | << QGeoCoordinate(1.999999, 1.999999) << QGeoCoordinate::DegreesMinutes |
| 843 | << QString( "2%1 0.000', 2%1 0.000'" ).arg(a: DEGREES_SYMB); |
| 844 | |
| 845 | QTest::newRow(dataTag: "Wrap seconds to minutes to Degrees DM -> above valid long/lat values" ) |
| 846 | << QGeoCoordinate(89.999999, 179.999999) << QGeoCoordinate::DegreesMinutesSeconds |
| 847 | << QString( "90%1 0' 0.0\", 180%1 0' 0.0\"" ).arg(a: DEGREES_SYMB); |
| 848 | |
| 849 | QTest::newRow(dataTag: "Seconds and minutes near valid long/lat values border" ) |
| 850 | << QGeoCoordinate(89.9999, 179.9999) << QGeoCoordinate::DegreesMinutesSeconds |
| 851 | << QString("89%1 59' 59.6\", 179%1 59' 59.6\"" ).arg(a: DEGREES_SYMB); |
| 852 | |
| 853 | QTest::newRow(dataTag: "Wrap minutes to Degrees DM ->above valid long/lat values" ) |
| 854 | << QGeoCoordinate(89.999999, 179.999999) << QGeoCoordinate::DegreesMinutes |
| 855 | << QString( "90%1 0.000', 180%1 0.000'" ).arg(a: DEGREES_SYMB); |
| 856 | |
| 857 | QTest::newRow(dataTag: "Minutes near valid long/lat values border" ) |
| 858 | << QGeoCoordinate(89.9999, 179.9999) << QGeoCoordinate::DegreesMinutes |
| 859 | << QString("89%1 59.994', 179%1 59.994'" ).arg(a: DEGREES_SYMB); |
| 860 | |
| 861 | QTest::newRow(dataTag: "Fix incorrect wrap minutes to degrees" ) |
| 862 | << QGeoCoordinate(0.995833, 0.995833) << QGeoCoordinate::DegreesMinutes |
| 863 | << QString("0%1 59.750', 0%1 59.750'" ).arg(a: DEGREES_SYMB); |
| 864 | |
| 865 | QTest::newRow(dataTag: "Fix incorrect wrap seconds to minutes" ) |
| 866 | << QGeoCoordinate(0.9832222, 0.9832222) << QGeoCoordinate::DegreesMinutesSeconds |
| 867 | << QString("0%1 58' 59.6\", 0%1 58' 59.6\"" ).arg(a: DEGREES_SYMB); |
| 868 | |
| 869 | } |
| 870 | |
| 871 | void datastream() |
| 872 | { |
| 873 | QFETCH(QGeoCoordinate, c); |
| 874 | |
| 875 | QByteArray ba; |
| 876 | QDataStream out(&ba, QIODevice::WriteOnly); |
| 877 | out << c; |
| 878 | |
| 879 | QDataStream in(&ba, QIODevice::ReadOnly); |
| 880 | QGeoCoordinate inCoord; |
| 881 | in >> inCoord; |
| 882 | QCOMPARE(inCoord, c); |
| 883 | } |
| 884 | |
| 885 | void datastream_data() |
| 886 | { |
| 887 | QTest::addColumn<QGeoCoordinate>(name: "c" ); |
| 888 | |
| 889 | QTest::newRow(dataTag: "invalid" ) << QGeoCoordinate(); |
| 890 | QTest::newRow(dataTag: "valid lat, long" ) << BRISBANE; |
| 891 | QTest::newRow(dataTag: "valid lat, long, alt" ) << QGeoCoordinate(-1, -1, -1); |
| 892 | QTest::newRow(dataTag: "valid lat, long, alt again" ) << QGeoCoordinate(1, 1, 1); |
| 893 | } |
| 894 | |
| 895 | void debug() |
| 896 | { |
| 897 | QFETCH(QGeoCoordinate, c); |
| 898 | QFETCH(int, nextValue); |
| 899 | QFETCH(QByteArray, debugString); |
| 900 | |
| 901 | qInstallMessageHandler(tst_qgeocoordinate_messageHandler); |
| 902 | qDebug() << c << nextValue; |
| 903 | qInstallMessageHandler(0); |
| 904 | QCOMPARE(tst_qgeocoordinate_debug, debugString); |
| 905 | } |
| 906 | |
| 907 | void debug_data() |
| 908 | { |
| 909 | QTest::addColumn<QGeoCoordinate>(name: "c" ); |
| 910 | QTest::addColumn<int>(name: "nextValue" ); |
| 911 | QTest::addColumn<QByteArray>(name: "debugString" ); |
| 912 | |
| 913 | QTest::newRow(dataTag: "uninitialized" ) << QGeoCoordinate() << 45 |
| 914 | << QByteArray("QGeoCoordinate(?, ?) 45" ); |
| 915 | QTest::newRow(dataTag: "initialized without altitude" ) << BRISBANE << 45 |
| 916 | << (QString("QGeoCoordinate(%1, %2) 45" ).arg(a: BRISBANE.latitude(), fieldWidth: 0, fmt: 'g', prec: 9) |
| 917 | .arg(a: BRISBANE.longitude(), fieldWidth: 0, fmt: 'g', prec: 9)).toLatin1(); |
| 918 | QTest::newRow(dataTag: "invalid initialization" ) << QGeoCoordinate(-100,-200) << 45 |
| 919 | << QByteArray("QGeoCoordinate(?, ?) 45" ); |
| 920 | QTest::newRow(dataTag: "initialized with altitude" ) << QGeoCoordinate(1,2,3) << 45 |
| 921 | << QByteArray("QGeoCoordinate(1, 2, 3) 45" ); |
| 922 | QTest::newRow(dataTag: "extra long coordinates" ) << QGeoCoordinate(89.123412341, 179.123412341) |
| 923 | << 45 << QByteArray("QGeoCoordinate(89.123412341, 179.12341234) 45" ); |
| 924 | } |
| 925 | |
| 926 | void hash() |
| 927 | { |
| 928 | uint s1 = qHash(coordinate: QGeoCoordinate(1, 1, 2)); |
| 929 | uint s2 = qHash(coordinate: QGeoCoordinate(2, 1, 1)); |
| 930 | uint s3 = qHash(coordinate: QGeoCoordinate(1, 2, 1)); |
| 931 | uint s10 = qHash(coordinate: QGeoCoordinate(0, 0, 2)); |
| 932 | uint s20 = qHash(coordinate: QGeoCoordinate(2, 0, 0)); |
| 933 | uint s30 = qHash(coordinate: QGeoCoordinate(0, 2, 0)); |
| 934 | uint s30NoAlt = qHash(coordinate: QGeoCoordinate(0, 2)); |
| 935 | uint s30WithSeed = qHash(coordinate: QGeoCoordinate(0, 2, 0), seed: 1); |
| 936 | uint nullCoordinate = qHash(coordinate: QGeoCoordinate()); |
| 937 | |
| 938 | uint north1 = qHash(coordinate: QGeoCoordinate(90.0, 34.7, 0)); |
| 939 | uint north2 = qHash(coordinate: QGeoCoordinate(90.0, 180, 0)); |
| 940 | |
| 941 | uint south1 = qHash(coordinate: QGeoCoordinate(90.0, 67.7, 34.0)); |
| 942 | uint south2 = qHash(coordinate: QGeoCoordinate(90.0, 111, 34.0)); |
| 943 | |
| 944 | QVERIFY(s1 != s2); |
| 945 | QVERIFY(s2 != s3); |
| 946 | QVERIFY(s1 != s3); |
| 947 | QVERIFY(s10 != s20); |
| 948 | QVERIFY(s20 != s30); |
| 949 | QVERIFY(s10 != s30); |
| 950 | QVERIFY(s30NoAlt != s30); |
| 951 | QVERIFY(s30WithSeed != s30); |
| 952 | |
| 953 | QVERIFY(nullCoordinate != s1); |
| 954 | QVERIFY(nullCoordinate != s2); |
| 955 | QVERIFY(nullCoordinate != s3); |
| 956 | QVERIFY(nullCoordinate != s10); |
| 957 | QVERIFY(nullCoordinate != s20); |
| 958 | QVERIFY(nullCoordinate != s30); |
| 959 | QVERIFY(nullCoordinate != s30NoAlt); |
| 960 | QVERIFY(nullCoordinate != s30WithSeed); |
| 961 | |
| 962 | QVERIFY(north1 == north2); |
| 963 | QVERIFY(south1 == south2); |
| 964 | } |
| 965 | }; |
| 966 | |
| 967 | QTEST_GUILESS_MAIN(tst_QGeoCoordinate) |
| 968 | #include "tst_qgeocoordinate.moc" |
| 969 | |