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 "tst_qgeoroutingmanager.h" |
32 | |
33 | QT_USE_NAMESPACE |
34 | |
35 | |
36 | void tst_QGeoRoutingManager::initTestCase() |
37 | { |
38 | #if QT_CONFIG(library) |
39 | /* |
40 | * Set custom path since CI doesn't install test plugins |
41 | */ |
42 | #ifdef Q_OS_WIN |
43 | QCoreApplication::addLibraryPath(QCoreApplication::applicationDirPath() + |
44 | QStringLiteral("/../../../../plugins" )); |
45 | #else |
46 | QCoreApplication::addLibraryPath(QCoreApplication::applicationDirPath() |
47 | + QStringLiteral("/../../../plugins" )); |
48 | #endif |
49 | #endif |
50 | tst_QGeoRoutingManager::loadRoutingManager(); |
51 | } |
52 | |
53 | void tst_QGeoRoutingManager::cleanupTestCase() |
54 | { |
55 | //delete qgeoroutingmanager; |
56 | delete qgeoserviceprovider; |
57 | } |
58 | |
59 | void tst_QGeoRoutingManager::init() |
60 | { |
61 | } |
62 | |
63 | void tst_QGeoRoutingManager::cleanup() |
64 | { |
65 | } |
66 | |
67 | void tst_QGeoRoutingManager::loadRoutingManager() |
68 | { |
69 | QStringList providers = QGeoServiceProvider::availableServiceProviders(); |
70 | QVERIFY(providers.contains("georoute.test.plugin" )); |
71 | |
72 | qgeoserviceprovider = new QGeoServiceProvider("georoute.test.plugin" ); |
73 | QVERIFY(qgeoserviceprovider); |
74 | QCOMPARE(qgeoserviceprovider->error(), QGeoServiceProvider::NotSupportedError); |
75 | qgeoserviceprovider->setAllowExperimental(true); |
76 | |
77 | QCOMPARE(qgeoserviceprovider->routingFeatures(), |
78 | QGeoServiceProvider::OfflineRoutingFeature |
79 | | QGeoServiceProvider::AlternativeRoutesFeature |
80 | | QGeoServiceProvider::RouteUpdatesFeature |
81 | | QGeoServiceProvider::ExcludeAreasRoutingFeature); |
82 | QCOMPARE(qgeoserviceprovider->error(), QGeoServiceProvider::NoError); |
83 | |
84 | qgeoroutingmanager = qgeoserviceprovider->routingManager(); |
85 | QVERIFY(qgeoroutingmanager); |
86 | |
87 | } |
88 | |
89 | void tst_QGeoRoutingManager::supports() |
90 | { |
91 | QCOMPARE(qgeoroutingmanager->supportedTravelModes(),QGeoRouteRequest::PedestrianTravel); |
92 | QCOMPARE(qgeoroutingmanager->supportedFeatureTypes(),QGeoRouteRequest::TollFeature); |
93 | QCOMPARE(qgeoroutingmanager->supportedFeatureWeights(),QGeoRouteRequest::PreferFeatureWeight); |
94 | QCOMPARE(qgeoroutingmanager->supportedRouteOptimizations(),QGeoRouteRequest::FastestRoute); |
95 | QCOMPARE(qgeoroutingmanager->supportedSegmentDetails(),QGeoRouteRequest::BasicSegmentData); |
96 | QCOMPARE(qgeoroutingmanager->supportedManeuverDetails(),QGeoRouteRequest::BasicManeuvers); |
97 | } |
98 | |
99 | void tst_QGeoRoutingManager::locale() |
100 | { |
101 | QLocale german = QLocale(QLocale::German, QLocale::Germany); |
102 | QLocale english = QLocale(QLocale::C, QLocale::AnyCountry); |
103 | |
104 | qgeoroutingmanager->setLocale(german); |
105 | |
106 | QCOMPARE(qgeoroutingmanager->locale(), german); |
107 | |
108 | QVERIFY(qgeoroutingmanager->locale() != english); |
109 | |
110 | QLocale en_UK = QLocale(QLocale::English, QLocale::UnitedKingdom); |
111 | qgeoroutingmanager->setLocale(en_UK); |
112 | QCOMPARE(qgeoroutingmanager->measurementSystem(), en_UK.measurementSystem()); |
113 | qgeoroutingmanager->setMeasurementSystem(QLocale::MetricSystem); |
114 | QCOMPARE(qgeoroutingmanager->measurementSystem(), QLocale::MetricSystem); |
115 | QVERIFY(qgeoroutingmanager->locale().measurementSystem() != qgeoroutingmanager->measurementSystem()); |
116 | } |
117 | |
118 | void tst_QGeoRoutingManager::name() |
119 | { |
120 | QString name = "georoute.test.plugin" ; |
121 | QCOMPARE(qgeoroutingmanager->managerName(), name); |
122 | } |
123 | |
124 | void tst_QGeoRoutingManager::version() |
125 | { |
126 | QCOMPARE(qgeoroutingmanager->managerVersion(), 100); |
127 | } |
128 | |
129 | void tst_QGeoRoutingManager::calculate() |
130 | { |
131 | QString error = "no error" ; |
132 | origin = new QGeoCoordinate(12.12 , 23.23); |
133 | destination = new QGeoCoordinate(34.34 , 89.32); |
134 | request = new QGeoRouteRequest(*origin, *destination); |
135 | |
136 | reply = qgeoroutingmanager->calculateRoute(request: *request); |
137 | |
138 | QCOMPARE(reply->error(), QGeoRouteReply::NoError); |
139 | QCOMPARE(reply->errorString(), error); |
140 | |
141 | delete origin; |
142 | delete destination; |
143 | delete request; |
144 | delete reply; |
145 | } |
146 | |
147 | |
148 | void tst_QGeoRoutingManager::update() |
149 | { |
150 | QString error = "no error" ; |
151 | position = new QGeoCoordinate(34.34, 89.32); |
152 | route = new QGeoRoute(); |
153 | |
154 | reply = qgeoroutingmanager->updateRoute(route: *route, position: *position); |
155 | |
156 | QCOMPARE(reply->error(), QGeoRouteReply::CommunicationError); |
157 | QCOMPARE(reply->errorString(), error); |
158 | |
159 | delete position; |
160 | delete route; |
161 | delete reply; |
162 | } |
163 | |
164 | QTEST_MAIN(tst_QGeoRoutingManager) |
165 | |
166 | |