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 <QObject>
30 #include <QDebug>
31 #include <QTest>
32 #include <QtLocation/QGeoServiceProvider>
33
34 QT_USE_NAMESPACE
35
36 class tst_QGeoServiceProvider : public QObject
37 {
38 Q_OBJECT
39
40 private slots:
41 void initTestCase();
42 void tst_availableServiceProvider();
43 void tst_features_data();
44 void tst_features();
45 void tst_misc();
46 void tst_nokiaRename();
47 };
48
initTestCase()49 void tst_QGeoServiceProvider::initTestCase()
50 {
51 #if QT_CONFIG(library)
52 /*
53 * Set custom path since CI doesn't install test plugins
54 */
55 #ifdef Q_OS_WIN
56 QCoreApplication::addLibraryPath(QCoreApplication::applicationDirPath() +
57 QStringLiteral("/../../../../plugins"));
58 #else
59 QCoreApplication::addLibraryPath(QCoreApplication::applicationDirPath()
60 + QStringLiteral("/../../../plugins"));
61 #endif
62 #endif
63 }
64
tst_availableServiceProvider()65 void tst_QGeoServiceProvider::tst_availableServiceProvider()
66 {
67 const QStringList provider = QGeoServiceProvider::availableServiceProviders();
68
69 // Currently provided plugins
70 if (provider.count() != 8)
71 qWarning() << provider;
72 QVERIFY(provider.count() >= 8);
73 // these providers are deployed
74 QVERIFY(provider.contains(QStringLiteral("mapbox")));
75 QVERIFY(provider.contains(QStringLiteral("here")));
76 QVERIFY(provider.contains(QStringLiteral("osm")));
77 QVERIFY(provider.contains(QStringLiteral("esri")));
78 // these providers exist for unit tests only
79 QVERIFY(provider.contains(QStringLiteral("geocode.test.plugin")));
80 QVERIFY(provider.contains(QStringLiteral("georoute.test.plugin")));
81 QVERIFY(provider.contains(QStringLiteral("qmlgeo.test.plugin")));
82 QVERIFY(provider.contains(QStringLiteral("test.places.unsupported")));
83
84 }
85
86 Q_DECLARE_METATYPE(QGeoServiceProvider::MappingFeatures)
Q_DECLARE_METATYPE(QGeoServiceProvider::GeocodingFeatures)87 Q_DECLARE_METATYPE(QGeoServiceProvider::GeocodingFeatures)
88 Q_DECLARE_METATYPE(QGeoServiceProvider::RoutingFeatures)
89 Q_DECLARE_METATYPE(QGeoServiceProvider::PlacesFeatures)
90
91 void tst_QGeoServiceProvider::tst_features_data()
92 {
93 QTest::addColumn<QString>("providerName");
94 QTest::addColumn<QGeoServiceProvider::MappingFeatures>("mappingFeatures");
95 QTest::addColumn<QGeoServiceProvider::GeocodingFeatures>("codingFeatures");
96 QTest::addColumn<QGeoServiceProvider::RoutingFeatures>("routingFeatures");
97 QTest::addColumn<QGeoServiceProvider::PlacesFeatures>("placeFeatures");
98
99 QTest::newRow("invalid") << QString("non-existing-provider-name")
100 << QGeoServiceProvider::MappingFeatures(QGeoServiceProvider::NoMappingFeatures)
101 << QGeoServiceProvider::GeocodingFeatures(QGeoServiceProvider::NoGeocodingFeatures)
102 << QGeoServiceProvider::RoutingFeatures(QGeoServiceProvider::NoRoutingFeatures)
103 << QGeoServiceProvider::PlacesFeatures(QGeoServiceProvider::NoPlacesFeatures);
104
105 QTest::newRow("mapbox") << QString("mapbox")
106 << QGeoServiceProvider::MappingFeatures(QGeoServiceProvider::OnlineMappingFeature)
107 << QGeoServiceProvider::GeocodingFeatures(QGeoServiceProvider::OnlineGeocodingFeature
108 | QGeoServiceProvider::ReverseGeocodingFeature
109 | QGeoServiceProvider::LocalizedGeocodingFeature)
110 << QGeoServiceProvider::RoutingFeatures(QGeoServiceProvider::OnlineRoutingFeature)
111 << QGeoServiceProvider::PlacesFeatures(QGeoServiceProvider::OnlinePlacesFeature
112 | QGeoServiceProvider::PlaceRecommendationsFeature
113 | QGeoServiceProvider::SearchSuggestionsFeature
114 | QGeoServiceProvider::LocalizedPlacesFeature);
115
116 QTest::newRow("here") << QString("here")
117 << QGeoServiceProvider::MappingFeatures(QGeoServiceProvider::OnlineMappingFeature)
118 << QGeoServiceProvider::GeocodingFeatures(QGeoServiceProvider::OnlineGeocodingFeature
119 | QGeoServiceProvider::ReverseGeocodingFeature)
120 << QGeoServiceProvider::RoutingFeatures(QGeoServiceProvider::OnlineRoutingFeature
121 | QGeoServiceProvider::RouteUpdatesFeature
122 | QGeoServiceProvider::AlternativeRoutesFeature
123 | QGeoServiceProvider::ExcludeAreasRoutingFeature)
124 << QGeoServiceProvider::PlacesFeatures(QGeoServiceProvider::OnlinePlacesFeature
125 | QGeoServiceProvider::PlaceRecommendationsFeature
126 | QGeoServiceProvider::SearchSuggestionsFeature
127 | QGeoServiceProvider::LocalizedPlacesFeature);
128
129 QTest::newRow("osm") << QString("osm")
130 << QGeoServiceProvider::MappingFeatures(QGeoServiceProvider::OnlineMappingFeature)
131 << QGeoServiceProvider::GeocodingFeatures(QGeoServiceProvider::OnlineGeocodingFeature
132 | QGeoServiceProvider::ReverseGeocodingFeature)
133 << QGeoServiceProvider::RoutingFeatures(QGeoServiceProvider::OnlineRoutingFeature)
134 << QGeoServiceProvider::PlacesFeatures(QGeoServiceProvider::OnlinePlacesFeature);
135
136 QTest::newRow("esri") << QString("esri")
137 << QGeoServiceProvider::MappingFeatures(QGeoServiceProvider::OnlineMappingFeature)
138 << QGeoServiceProvider::GeocodingFeatures(QGeoServiceProvider::OnlineGeocodingFeature
139 | QGeoServiceProvider::ReverseGeocodingFeature)
140 << QGeoServiceProvider::RoutingFeatures(QGeoServiceProvider::OnlineRoutingFeature)
141 << QGeoServiceProvider::PlacesFeatures(QGeoServiceProvider::OnlinePlacesFeature);
142 }
143
tst_features()144 void tst_QGeoServiceProvider::tst_features()
145 {
146 QFETCH(QString, providerName);
147 QFETCH(QGeoServiceProvider::MappingFeatures, mappingFeatures);
148 QFETCH(QGeoServiceProvider::GeocodingFeatures, codingFeatures);
149 QFETCH(QGeoServiceProvider::RoutingFeatures, routingFeatures);
150 QFETCH(QGeoServiceProvider::PlacesFeatures, placeFeatures);
151
152 QGeoServiceProvider provider(providerName);
153 QCOMPARE(provider.mappingFeatures(), mappingFeatures);
154 QCOMPARE(provider.geocodingFeatures(), codingFeatures);
155 QCOMPARE(provider.routingFeatures(), routingFeatures);
156 QCOMPARE(provider.placesFeatures(), placeFeatures);
157
158 if (provider.mappingFeatures() == QGeoServiceProvider::NoMappingFeatures) {
159 QVERIFY(provider.mappingManager() == nullptr);
160 } else {
161 // some plugins require token/access parameter
162 // they return 0 but set QGeoServiceProvider::MissingRequiredParameterError
163 if (provider.mappingManager() != nullptr)
164 QCOMPARE(provider.error(), QGeoServiceProvider::NoError);
165 else
166 QCOMPARE(provider.error(), QGeoServiceProvider::MissingRequiredParameterError);
167 }
168
169 if (provider.geocodingFeatures() == QGeoServiceProvider::NoGeocodingFeatures) {
170 QVERIFY(provider.geocodingManager() == nullptr);
171 } else {
172 if (provider.geocodingManager() != nullptr)
173 QVERIFY(provider.geocodingManager() != nullptr); //pointless but we want a VERIFY here
174 else
175 QCOMPARE(provider.error(), QGeoServiceProvider::MissingRequiredParameterError);
176 }
177
178 if (provider.routingFeatures() == QGeoServiceProvider::NoRoutingFeatures) {
179 QVERIFY(provider.routingManager() == nullptr);
180 } else {
181 if (provider.routingManager() != nullptr)
182 QCOMPARE(provider.error(), QGeoServiceProvider::NoError);
183 else
184 QCOMPARE(provider.error(), QGeoServiceProvider::MissingRequiredParameterError);
185 }
186
187 if (provider.placesFeatures() == QGeoServiceProvider::NoPlacesFeatures) {
188 QVERIFY(provider.placeManager() == nullptr);
189 } else {
190 if (provider.placeManager() != nullptr)
191 QCOMPARE(provider.error(), QGeoServiceProvider::NoError);
192 else
193 QCOMPARE(provider.error(), QGeoServiceProvider::MissingRequiredParameterError);
194 }
195 }
196
tst_misc()197 void tst_QGeoServiceProvider::tst_misc()
198 {
199 const QStringList provider = QGeoServiceProvider::availableServiceProviders();
200 QVERIFY(provider.contains(QStringLiteral("osm")));
201 QVERIFY(provider.contains(QStringLiteral("geocode.test.plugin")));
202
203 QGeoServiceProvider test_experimental(
204 QStringLiteral("geocode.test.plugin"), QVariantMap(), true);
205 QGeoServiceProvider test_noexperimental(
206 QStringLiteral("geocode.test.plugin"), QVariantMap(), false);
207 QCOMPARE(test_experimental.error(), QGeoServiceProvider::NoError);
208 QCOMPARE(test_noexperimental.error(), QGeoServiceProvider::NotSupportedError);
209
210 QGeoServiceProvider osm_experimental(
211 QStringLiteral("osm"), QVariantMap(), true);
212 QGeoServiceProvider osm_noexperimental(
213 QStringLiteral("osm"), QVariantMap(), false);
214 QCOMPARE(osm_experimental.error(), QGeoServiceProvider::NoError);
215 QCOMPARE(osm_noexperimental.error(), QGeoServiceProvider::NoError);
216 }
217
tst_nokiaRename()218 void tst_QGeoServiceProvider::tst_nokiaRename()
219 {
220 // The "nokia" plugin was renamed to "here".
221 // It remains available under the name "nokia" for now
222 // but is not advertised via QGeoServiceProvider::availableServiceProviders()
223
224 QVERIFY(!QGeoServiceProvider::availableServiceProviders().contains("nokia"));
225 QGeoServiceProvider provider(QStringLiteral("nokia"));
226 QCOMPARE(provider.error(), QGeoServiceProvider::NoError);
227
228 }
229
230 QTEST_GUILESS_MAIN(tst_QGeoServiceProvider)
231
232 #include "tst_qgeoserviceprovider.moc"
233