| 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 | #include "tst_qgeorouterequest.h" |
| 30 | |
| 31 | #include <QtPositioning/QGeoRectangle> |
| 32 | |
| 33 | QT_USE_NAMESPACE |
| 34 | |
| 35 | tst_QGeoRouteRequest::tst_QGeoRouteRequest() |
| 36 | { |
| 37 | } |
| 38 | |
| 39 | void tst_QGeoRouteRequest::initTestCase() |
| 40 | { |
| 41 | } |
| 42 | |
| 43 | void tst_QGeoRouteRequest::cleanupTestCase() |
| 44 | { |
| 45 | } |
| 46 | |
| 47 | void tst_QGeoRouteRequest::init() |
| 48 | { |
| 49 | qgeocoordinate = new QGeoCoordinate(); |
| 50 | qgeoboundingbox = new QGeoRectangle(); |
| 51 | qgeorouterequest = new QGeoRouteRequest(); |
| 52 | } |
| 53 | |
| 54 | void tst_QGeoRouteRequest::cleanup() |
| 55 | { |
| 56 | delete qgeocoordinate; |
| 57 | delete qgeoboundingbox; |
| 58 | delete qgeorouterequest; |
| 59 | } |
| 60 | |
| 61 | void tst_QGeoRouteRequest::constructor_waypoints() |
| 62 | { |
| 63 | QGeoCoordinate *qgeocoord1 = new QGeoCoordinate(43.5435, 76.342); |
| 64 | QGeoCoordinate *qgeocoord2 = new QGeoCoordinate(-43.5435, 176.342); |
| 65 | QGeoCoordinate *qgeocoord3 = new QGeoCoordinate(-13.5435, +76.342); |
| 66 | |
| 67 | QList<QGeoCoordinate> waypoints; |
| 68 | waypoints.append(t: *qgeocoord1); |
| 69 | waypoints.append(t: *qgeocoord2); |
| 70 | waypoints.append(t: *qgeocoord3); |
| 71 | |
| 72 | QGeoRouteRequest *copy = new QGeoRouteRequest(waypoints); |
| 73 | |
| 74 | QCOMPARE(copy->waypoints(), waypoints); |
| 75 | QCOMPARE(copy->numberAlternativeRoutes(), 0); |
| 76 | QCOMPARE(copy->routeOptimization(), QGeoRouteRequest::FastestRoute); |
| 77 | QCOMPARE(copy->segmentDetail(), QGeoRouteRequest::BasicSegmentData); |
| 78 | QCOMPARE(copy->travelModes(), QGeoRouteRequest::CarTravel); |
| 79 | QCOMPARE(copy->maneuverDetail(), QGeoRouteRequest::BasicManeuvers); |
| 80 | |
| 81 | delete qgeocoord1; |
| 82 | delete qgeocoord2; |
| 83 | delete qgeocoord3; |
| 84 | delete copy; |
| 85 | } |
| 86 | |
| 87 | void tst_QGeoRouteRequest::constructor_orig_dest() |
| 88 | { |
| 89 | QGeoCoordinate *qgeocoord1 = new QGeoCoordinate(43.5435, 76.342); |
| 90 | QGeoCoordinate *qgeocoord2 = new QGeoCoordinate(-43.5435, 176.342); |
| 91 | |
| 92 | QGeoRouteRequest *copy = new QGeoRouteRequest(*qgeocoord1, *qgeocoord2); |
| 93 | |
| 94 | QList<QGeoCoordinate> waypoints; |
| 95 | waypoints.append(t: *qgeocoord1); |
| 96 | waypoints.append(t: *qgeocoord2); |
| 97 | |
| 98 | QCOMPARE(copy->waypoints(), waypoints); |
| 99 | QCOMPARE(copy->numberAlternativeRoutes(), 0); |
| 100 | QCOMPARE(copy->routeOptimization(), QGeoRouteRequest::FastestRoute); |
| 101 | QCOMPARE(copy->segmentDetail(), QGeoRouteRequest::BasicSegmentData); |
| 102 | QCOMPARE(copy->travelModes(), QGeoRouteRequest::CarTravel); |
| 103 | QCOMPARE(copy->maneuverDetail(), QGeoRouteRequest::BasicManeuvers); |
| 104 | |
| 105 | delete qgeocoord1; |
| 106 | delete qgeocoord2; |
| 107 | delete copy; |
| 108 | } |
| 109 | |
| 110 | void tst_QGeoRouteRequest::copy_constructor() |
| 111 | { |
| 112 | QGeoRouteRequest *qgeorouterequestcopy = new QGeoRouteRequest(*qgeorouterequest); |
| 113 | QCOMPARE(*qgeorouterequest, *qgeorouterequestcopy); |
| 114 | delete qgeorouterequestcopy; |
| 115 | } |
| 116 | |
| 117 | void tst_QGeoRouteRequest::destructor() |
| 118 | { |
| 119 | QGeoRouteRequest *qgeorouterequestcopy; |
| 120 | |
| 121 | qgeorouterequestcopy = new QGeoRouteRequest(); |
| 122 | delete qgeorouterequestcopy; |
| 123 | |
| 124 | qgeorouterequestcopy = new QGeoRouteRequest(*qgeorouterequest); |
| 125 | delete qgeorouterequestcopy; |
| 126 | } |
| 127 | |
| 128 | void tst_QGeoRouteRequest::excludeAreas() |
| 129 | { |
| 130 | qgeocoordinate->setLatitude(13.3851); |
| 131 | qgeocoordinate->setLongitude(52.5312); |
| 132 | |
| 133 | QGeoCoordinate *qgeocoordinatecopy = new QGeoCoordinate(34.324 , -110.32); |
| 134 | |
| 135 | QGeoRectangle *qgeoboundingboxcopy = new QGeoRectangle(*qgeocoordinate, 0.4, 0.4); |
| 136 | QGeoRectangle *qgeoboundingboxcopy2 = new QGeoRectangle(*qgeocoordinatecopy, 1.2, 0.9); |
| 137 | QList<QGeoRectangle> areas; |
| 138 | areas.append(t: *qgeoboundingboxcopy); |
| 139 | areas.append(t: *qgeoboundingboxcopy2); |
| 140 | |
| 141 | qgeorouterequest->setExcludeAreas(areas); |
| 142 | |
| 143 | QCOMPARE(qgeorouterequest->excludeAreas(), areas); |
| 144 | |
| 145 | delete qgeoboundingboxcopy; |
| 146 | delete qgeoboundingboxcopy2; |
| 147 | delete qgeocoordinatecopy; |
| 148 | } |
| 149 | |
| 150 | void tst_QGeoRouteRequest::numberAlternativeRoutes() |
| 151 | { |
| 152 | qgeorouterequest->setNumberAlternativeRoutes(0); |
| 153 | QCOMPARE(qgeorouterequest->numberAlternativeRoutes(), 0); |
| 154 | |
| 155 | qgeorouterequest->setNumberAlternativeRoutes(24); |
| 156 | QCOMPARE(qgeorouterequest->numberAlternativeRoutes(), 24); |
| 157 | |
| 158 | qgeorouterequest->setNumberAlternativeRoutes(-12); |
| 159 | |
| 160 | QCOMPARE(qgeorouterequest->numberAlternativeRoutes(), 0); |
| 161 | } |
| 162 | |
| 163 | void tst_QGeoRouteRequest::routeOptimization() |
| 164 | { |
| 165 | QFETCH(QGeoRouteRequest::RouteOptimization, optimization); |
| 166 | |
| 167 | QCOMPARE(qgeorouterequest->routeOptimization(),QGeoRouteRequest::FastestRoute); |
| 168 | |
| 169 | qgeorouterequest->setRouteOptimization(optimization); |
| 170 | QCOMPARE(qgeorouterequest->routeOptimization(), optimization); |
| 171 | } |
| 172 | |
| 173 | void tst_QGeoRouteRequest::routeOptimization_data() |
| 174 | { |
| 175 | QTest::addColumn<QGeoRouteRequest::RouteOptimization>(name: "optimization" ); |
| 176 | |
| 177 | QTest::newRow(dataTag: "optimization1" ) << QGeoRouteRequest::FastestRoute; |
| 178 | QTest::newRow(dataTag: "optimization2" ) << QGeoRouteRequest::ShortestRoute; |
| 179 | QTest::newRow(dataTag: "optimization3" ) << QGeoRouteRequest::MostEconomicRoute; |
| 180 | QTest::newRow(dataTag: "optimization4" ) << QGeoRouteRequest::MostScenicRoute; |
| 181 | |
| 182 | } |
| 183 | |
| 184 | void tst_QGeoRouteRequest::segmentDetail() |
| 185 | { |
| 186 | QFETCH(QGeoRouteRequest::SegmentDetail, detail); |
| 187 | |
| 188 | QCOMPARE(qgeorouterequest->segmentDetail(), QGeoRouteRequest::BasicSegmentData); |
| 189 | |
| 190 | qgeorouterequest->setSegmentDetail(detail); |
| 191 | QCOMPARE(qgeorouterequest->segmentDetail(), detail); |
| 192 | } |
| 193 | |
| 194 | void tst_QGeoRouteRequest::segmentDetail_data() |
| 195 | { |
| 196 | QTest::addColumn<QGeoRouteRequest::SegmentDetail>(name: "detail" ); |
| 197 | |
| 198 | QTest::newRow(dataTag: "detail1" ) << QGeoRouteRequest::NoSegmentData; |
| 199 | QTest::newRow(dataTag: "detail2" ) << QGeoRouteRequest::BasicSegmentData; |
| 200 | } |
| 201 | |
| 202 | void tst_QGeoRouteRequest::travelModes() |
| 203 | { |
| 204 | QFETCH(QGeoRouteRequest::TravelMode,mode); |
| 205 | |
| 206 | QCOMPARE(qgeorouterequest->travelModes(), QGeoRouteRequest::CarTravel); |
| 207 | |
| 208 | qgeorouterequest->setTravelModes(mode); |
| 209 | QCOMPARE(qgeorouterequest->travelModes(), mode); |
| 210 | } |
| 211 | |
| 212 | void tst_QGeoRouteRequest::travelModes_data() |
| 213 | { |
| 214 | QTest::addColumn<QGeoRouteRequest::TravelMode>(name: "mode" ); |
| 215 | |
| 216 | QTest::newRow(dataTag: "mode1" ) << QGeoRouteRequest::CarTravel; |
| 217 | QTest::newRow(dataTag: "mode2" ) << QGeoRouteRequest::PedestrianTravel; |
| 218 | QTest::newRow(dataTag: "mode3" ) << QGeoRouteRequest::BicycleTravel; |
| 219 | QTest::newRow(dataTag: "mode4" ) << QGeoRouteRequest::PublicTransitTravel; |
| 220 | QTest::newRow(dataTag: "mode5" ) << QGeoRouteRequest::TruckTravel; |
| 221 | } |
| 222 | |
| 223 | void tst_QGeoRouteRequest::waypoints() |
| 224 | { |
| 225 | QFETCH(QList<double>, coordinates); |
| 226 | |
| 227 | QList<QGeoCoordinate> waypoints; |
| 228 | |
| 229 | for (int i = 0; i < coordinates.size(); i += 2) { |
| 230 | waypoints.append(t: QGeoCoordinate(coordinates.at(i), coordinates.at(i: i+1))); |
| 231 | } |
| 232 | |
| 233 | qgeorouterequest->setWaypoints(waypoints); |
| 234 | |
| 235 | QList<QGeoCoordinate> waypointsRetrieved = qgeorouterequest->waypoints(); |
| 236 | QCOMPARE(waypointsRetrieved, waypoints); |
| 237 | |
| 238 | for (int i=0; i < waypointsRetrieved.size(); i++) { |
| 239 | QCOMPARE(waypointsRetrieved.at(i), waypoints.at(i)); |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | void tst_QGeoRouteRequest::waypoints_data() |
| 244 | { |
| 245 | QTest::addColumn<QList<double> >(name: "coordinates" ); |
| 246 | |
| 247 | QList<double> coordinates; |
| 248 | |
| 249 | coordinates << 0.0 << 0.0; |
| 250 | QTest::newRow(dataTag: "path1" ) << coordinates ; |
| 251 | |
| 252 | coordinates << -23.23 << 54.45345; |
| 253 | QTest::newRow(dataTag: "path2" ) << coordinates ; |
| 254 | |
| 255 | coordinates << -85.4324 << -121.343; |
| 256 | QTest::newRow(dataTag: "path3" ) << coordinates ; |
| 257 | |
| 258 | coordinates << 1.323 << 12.323; |
| 259 | QTest::newRow(dataTag: "path4" ) << coordinates ; |
| 260 | |
| 261 | coordinates << 1324.323 << 143242.323; |
| 262 | QTest::newRow(dataTag: "path5" ) << coordinates ; |
| 263 | } |
| 264 | |
| 265 | void tst_QGeoRouteRequest::maneuverDetail() |
| 266 | { |
| 267 | QFETCH(QGeoRouteRequest::ManeuverDetail,maneuver); |
| 268 | |
| 269 | QCOMPARE(qgeorouterequest->maneuverDetail(), QGeoRouteRequest::BasicManeuvers); |
| 270 | |
| 271 | qgeorouterequest->setManeuverDetail(maneuver); |
| 272 | QCOMPARE(qgeorouterequest->maneuverDetail(), maneuver); |
| 273 | } |
| 274 | |
| 275 | void tst_QGeoRouteRequest::maneuverDetail_data() |
| 276 | { |
| 277 | QTest::addColumn<QGeoRouteRequest::ManeuverDetail>(name: "maneuver" ); |
| 278 | |
| 279 | QTest::newRow(dataTag: "maneuver1" ) << QGeoRouteRequest::NoManeuvers; |
| 280 | QTest::newRow(dataTag: "maneuver2" ) << QGeoRouteRequest::BasicManeuvers; |
| 281 | |
| 282 | } |
| 283 | |
| 284 | void tst_QGeoRouteRequest::featureWeight_data() |
| 285 | { |
| 286 | QTest::addColumn<QGeoRouteRequest::FeatureType>(name: "type" ); |
| 287 | QTest::addColumn<bool>(name: "checkTypes" ); |
| 288 | QTest::addColumn<QGeoRouteRequest::FeatureWeight>(name: "initialWeight" ); |
| 289 | QTest::addColumn<QGeoRouteRequest::FeatureWeight>(name: "newWeight" ); |
| 290 | QTest::addColumn<QGeoRouteRequest::FeatureWeight>(name: "expectWeight" ); |
| 291 | |
| 292 | QTest::newRow(dataTag: "NoFeature" ) << QGeoRouteRequest::NoFeature << false |
| 293 | << QGeoRouteRequest::NeutralFeatureWeight |
| 294 | << QGeoRouteRequest::PreferFeatureWeight |
| 295 | << QGeoRouteRequest::NeutralFeatureWeight; |
| 296 | QTest::newRow(dataTag: "TollFeature" ) << QGeoRouteRequest::TollFeature << true |
| 297 | << QGeoRouteRequest::NeutralFeatureWeight |
| 298 | << QGeoRouteRequest::PreferFeatureWeight |
| 299 | << QGeoRouteRequest::PreferFeatureWeight; |
| 300 | QTest::newRow(dataTag: "HighwayFeature" ) << QGeoRouteRequest::HighwayFeature << true |
| 301 | << QGeoRouteRequest::NeutralFeatureWeight |
| 302 | << QGeoRouteRequest::RequireFeatureWeight |
| 303 | << QGeoRouteRequest::RequireFeatureWeight; |
| 304 | } |
| 305 | |
| 306 | void tst_QGeoRouteRequest::featureWeight() |
| 307 | { |
| 308 | QFETCH(QGeoRouteRequest::FeatureType, type); |
| 309 | QFETCH(bool, checkTypes); |
| 310 | QFETCH(QGeoRouteRequest::FeatureWeight, initialWeight); |
| 311 | QFETCH(QGeoRouteRequest::FeatureWeight, newWeight); |
| 312 | QFETCH(QGeoRouteRequest::FeatureWeight, expectWeight); |
| 313 | |
| 314 | QCOMPARE(qgeorouterequest->featureWeight(type), initialWeight); |
| 315 | qgeorouterequest->setFeatureWeight(featureType: type, featureWeight: newWeight); |
| 316 | QCOMPARE(qgeorouterequest->featureWeight(type), expectWeight); |
| 317 | |
| 318 | if (checkTypes) |
| 319 | QVERIFY(qgeorouterequest->featureTypes().contains(type)); |
| 320 | } |
| 321 | |
| 322 | void tst_QGeoRouteRequest::() |
| 323 | { |
| 324 | QTest::addColumn<QVariantMap>(name: "extraParameters" ); |
| 325 | |
| 326 | QVariantMap params; |
| 327 | QTest::newRow(dataTag: "Empty" ) << params; |
| 328 | |
| 329 | const QVariantMap param1 = {{"property1" , QVariant(42)} , {"property2" , QVariant("42" )} , {"property3" , QVariant("42.0" )}}; |
| 330 | params["param1" ] = param1; |
| 331 | |
| 332 | QTest::newRow(dataTag: "One param" ) << params; |
| 333 | |
| 334 | const QVariantMap param2 = {{"property1" , QVariant(43)} , {"property2" , QVariant("43" )} , {"property3" , QVariant("43.0" )}}; |
| 335 | params["param2" ] = param2; |
| 336 | |
| 337 | QTest::newRow(dataTag: "Two params" ) << params; |
| 338 | } |
| 339 | |
| 340 | void tst_QGeoRouteRequest::() |
| 341 | { |
| 342 | typedef QVariantMap ParameterType; |
| 343 | QFETCH(ParameterType , ); |
| 344 | QVariantMap emptyParams; |
| 345 | qgeorouterequest->setExtraParameters(extraParameters); |
| 346 | QCOMPARE(qgeorouterequest->extraParameters(), extraParameters); |
| 347 | qgeorouterequest->setExtraParameters(emptyParams); |
| 348 | QCOMPARE(qgeorouterequest->extraParameters(), emptyParams); |
| 349 | } |
| 350 | |
| 351 | void tst_QGeoRouteRequest::departureTime_data() |
| 352 | { |
| 353 | QTest::addColumn<QDateTime>(name: "departureTime" ); |
| 354 | |
| 355 | QTest::newRow(dataTag: "Invalid" ) << QDateTime(); |
| 356 | QTest::newRow(dataTag: "date1" ) << QDateTime(QDate(2012, 7, 6), QTime(23, 55, 0)); |
| 357 | QTest::newRow(dataTag: "date2" ) << QDateTime(QDate(2012, 7, 7), QTime(0, 5, 0)); |
| 358 | } |
| 359 | |
| 360 | void tst_QGeoRouteRequest::departureTime() |
| 361 | { |
| 362 | QFETCH(QDateTime , departureTime); |
| 363 | qgeorouterequest->setDepartureTime(departureTime); |
| 364 | QCOMPARE(qgeorouterequest->departureTime(), departureTime); |
| 365 | } |
| 366 | |
| 367 | QTEST_APPLESS_MAIN(tst_QGeoRouteRequest); |
| 368 | |