summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@theqtcompany.com>2015-03-03 09:14:37 +0100
committerAlex Blasche <alexander.blasche@theqtcompany.com>2015-03-24 14:30:07 +0000
commitf738357f041291eb42c8f6a6d5ca9aa1dd4ebfb1 (patch)
tree5d68f0906650b50b268b97d87cc004787b7ff3e9
parent4468f565e34a29e5241312528734cd57fc1e10ad (diff)
Adds a QGeoServiceProvider unit tests
Change-Id: I1f9ba929f28ef261eaab9d7ac0a96f6ca88c8767 Reviewed-by: Michal Klocek <michal.klocek@theqtcompany.com> Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
-rw-r--r--tests/auto/auto.pro1
-rw-r--r--tests/auto/qgeoserviceprovider/qgeoserviceprovider.pro7
-rw-r--r--tests/auto/qgeoserviceprovider/tst_qgeoserviceprovider.cpp203
3 files changed, 211 insertions, 0 deletions
diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro
index ffbd9b84..dd95998e 100644
--- a/tests/auto/auto.pro
+++ b/tests/auto/auto.pro
@@ -49,6 +49,7 @@ qtHaveModule(location) {
qgeoroutesegment \
qgeoroutingmanager \
qgeoroutingmanagerplugins \
+ qgeoserviceprovider \
qgeotilespec \
qgeoroutexmlparser \
qgeomapcontroller \
diff --git a/tests/auto/qgeoserviceprovider/qgeoserviceprovider.pro b/tests/auto/qgeoserviceprovider/qgeoserviceprovider.pro
new file mode 100644
index 00000000..793d7ac5
--- /dev/null
+++ b/tests/auto/qgeoserviceprovider/qgeoserviceprovider.pro
@@ -0,0 +1,7 @@
+TEMPLATE = app
+CONFIG+=testcase
+TARGET=tst_qgeoserviceprovider
+
+SOURCES += tst_qgeoserviceprovider.cpp
+
+QT += testlib location
diff --git a/tests/auto/qgeoserviceprovider/tst_qgeoserviceprovider.cpp b/tests/auto/qgeoserviceprovider/tst_qgeoserviceprovider.cpp
new file mode 100644
index 00000000..99ab7148
--- /dev/null
+++ b/tests/auto/qgeoserviceprovider/tst_qgeoserviceprovider.cpp
@@ -0,0 +1,203 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL21$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** As a special exception, The Qt Company gives you certain additional
+** rights. These rights are described in The Qt Company LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QObject>
+#include <QDebug>
+#include <QTest>
+#include <QtLocation/QGeoServiceProvider>
+
+QT_USE_NAMESPACE
+
+class tst_QGeoServiceProvider : public QObject
+{
+ Q_OBJECT
+
+private slots:
+ void initTestCase();
+ void tst_availableServiceProvider();
+ void tst_features_data();
+ void tst_features();
+ void tst_misc();
+};
+
+void tst_QGeoServiceProvider::initTestCase()
+{
+ /*
+ * Set custom path since CI doesn't install test plugins
+ */
+ QCoreApplication::addLibraryPath(QCoreApplication::applicationDirPath()
+ + QStringLiteral("/../../../plugins"));
+}
+
+void tst_QGeoServiceProvider::tst_availableServiceProvider()
+{
+ const QStringList provider = QGeoServiceProvider::availableServiceProviders();
+
+ // Currently provided plugins
+ if (provider.count() != 7)
+ qWarning() << provider;
+ QCOMPARE(provider.count(), 7);
+ // these providers are deployed
+ QVERIFY(provider.contains(QStringLiteral("mapbox")));
+ QVERIFY(provider.contains(QStringLiteral("nokia")));
+ QVERIFY(provider.contains(QStringLiteral("osm")));
+ // these providers exist for unit tests only
+ QVERIFY(provider.contains(QStringLiteral("geocode.test.plugin")));
+ QVERIFY(provider.contains(QStringLiteral("georoute.test.plugin")));
+ QVERIFY(provider.contains(QStringLiteral("qmlgeo.test.plugin")));
+ QVERIFY(provider.contains(QStringLiteral("test.places.unsupported")));
+
+}
+
+Q_DECLARE_METATYPE(QGeoServiceProvider::MappingFeatures)
+Q_DECLARE_METATYPE(QGeoServiceProvider::GeocodingFeatures)
+Q_DECLARE_METATYPE(QGeoServiceProvider::RoutingFeatures)
+Q_DECLARE_METATYPE(QGeoServiceProvider::PlacesFeatures)
+
+void tst_QGeoServiceProvider::tst_features_data()
+{
+ QTest::addColumn<QString>("providerName");
+ QTest::addColumn<QGeoServiceProvider::MappingFeatures>("mappingFeatures");
+ QTest::addColumn<QGeoServiceProvider::GeocodingFeatures>("codingFeatures");
+ QTest::addColumn<QGeoServiceProvider::RoutingFeatures>("routingFeatures");
+ QTest::addColumn<QGeoServiceProvider::PlacesFeatures>("placeFeatures");
+
+ QTest::newRow("invalid") << QString("non-existing-provider-name")
+ << QGeoServiceProvider::MappingFeatures(QGeoServiceProvider::NoMappingFeatures)
+ << QGeoServiceProvider::GeocodingFeatures(QGeoServiceProvider::NoGeocodingFeatures)
+ << QGeoServiceProvider::RoutingFeatures(QGeoServiceProvider::NoRoutingFeatures)
+ << QGeoServiceProvider::PlacesFeatures(QGeoServiceProvider::NoPlacesFeatures);
+
+ QTest::newRow("mapbox") << QString("mapbox")
+ << QGeoServiceProvider::MappingFeatures(QGeoServiceProvider::OnlineMappingFeature)
+ << QGeoServiceProvider::GeocodingFeatures(QGeoServiceProvider::NoGeocodingFeatures)
+ << QGeoServiceProvider::RoutingFeatures(QGeoServiceProvider::NoRoutingFeatures)
+ << QGeoServiceProvider::PlacesFeatures(QGeoServiceProvider::NoPlacesFeatures);
+
+ QTest::newRow("nokia") << QString("nokia")
+ << QGeoServiceProvider::MappingFeatures(QGeoServiceProvider::OnlineMappingFeature)
+ << QGeoServiceProvider::GeocodingFeatures(QGeoServiceProvider::OnlineGeocodingFeature
+ | QGeoServiceProvider::ReverseGeocodingFeature)
+ << QGeoServiceProvider::RoutingFeatures(QGeoServiceProvider::OnlineRoutingFeature
+ | QGeoServiceProvider::RouteUpdatesFeature
+ | QGeoServiceProvider::AlternativeRoutesFeature
+ | QGeoServiceProvider::ExcludeAreasRoutingFeature)
+ << QGeoServiceProvider::PlacesFeatures(QGeoServiceProvider::OnlinePlacesFeature
+ | QGeoServiceProvider::PlaceRecommendationsFeature
+ | QGeoServiceProvider::SearchSuggestionsFeature
+ | QGeoServiceProvider::LocalizedPlacesFeature);
+
+ QTest::newRow("osm") << QString("osm")
+ << QGeoServiceProvider::MappingFeatures(QGeoServiceProvider::OnlineMappingFeature)
+ << QGeoServiceProvider::GeocodingFeatures(QGeoServiceProvider::OnlineGeocodingFeature
+ | QGeoServiceProvider::ReverseGeocodingFeature)
+ << QGeoServiceProvider::RoutingFeatures(QGeoServiceProvider::OnlineRoutingFeature)
+ << QGeoServiceProvider::PlacesFeatures(QGeoServiceProvider::OnlinePlacesFeature);
+}
+
+void tst_QGeoServiceProvider::tst_features()
+{
+ QFETCH(QString, providerName);
+ QFETCH(QGeoServiceProvider::MappingFeatures, mappingFeatures);
+ QFETCH(QGeoServiceProvider::GeocodingFeatures, codingFeatures);
+ QFETCH(QGeoServiceProvider::RoutingFeatures, routingFeatures);
+ QFETCH(QGeoServiceProvider::PlacesFeatures, placeFeatures);
+
+ QGeoServiceProvider provider(providerName);
+ QCOMPARE(provider.mappingFeatures(), mappingFeatures);
+ QCOMPARE(provider.geocodingFeatures(), codingFeatures);
+ QCOMPARE(provider.routingFeatures(), routingFeatures);
+ QCOMPARE(provider.placesFeatures(), placeFeatures);
+
+ if (provider.mappingFeatures() == QGeoServiceProvider::NoMappingFeatures) {
+ QVERIFY(provider.mappingManager() == Q_NULLPTR);
+ } else {
+ // some plugins require token/access parameter
+ // they return 0 but set QGeoServiceProvider::MissingRequiredParameterError
+ if (provider.mappingManager() != Q_NULLPTR)
+ QCOMPARE(provider.error(), QGeoServiceProvider::NoError);
+ else
+ QCOMPARE(provider.error(), QGeoServiceProvider::MissingRequiredParameterError);
+ }
+
+ if (provider.geocodingFeatures() == QGeoServiceProvider::NoGeocodingFeatures) {
+ QVERIFY(provider.geocodingManager() == Q_NULLPTR);
+ } else {
+ if (provider.geocodingManager() != Q_NULLPTR)
+ QVERIFY(provider.geocodingManager() != Q_NULLPTR); //pointless but we want a VERIFY here
+ else
+ QCOMPARE(provider.error(), QGeoServiceProvider::MissingRequiredParameterError);
+ }
+
+ if (provider.routingFeatures() == QGeoServiceProvider::NoRoutingFeatures) {
+ QVERIFY(provider.routingManager() == Q_NULLPTR);
+ } else {
+ if (provider.routingManager() != Q_NULLPTR)
+ QCOMPARE(provider.error(), QGeoServiceProvider::NoError);
+ else
+ QCOMPARE(provider.error(), QGeoServiceProvider::MissingRequiredParameterError);
+ }
+
+ if (provider.placesFeatures() == QGeoServiceProvider::NoPlacesFeatures) {
+ QVERIFY(provider.placeManager() == Q_NULLPTR);
+ } else {
+ if (provider.placeManager() != Q_NULLPTR)
+ QCOMPARE(provider.error(), QGeoServiceProvider::NoError);
+ else
+ QCOMPARE(provider.error(), QGeoServiceProvider::MissingRequiredParameterError);
+ }
+}
+
+void tst_QGeoServiceProvider::tst_misc()
+{
+ const QStringList provider = QGeoServiceProvider::availableServiceProviders();
+ QVERIFY(provider.contains(QStringLiteral("osm")));
+ QVERIFY(provider.contains(QStringLiteral("geocode.test.plugin")));
+
+ QGeoServiceProvider test_experimental(
+ QStringLiteral("geocode.test.plugin"), QVariantMap(), true);
+ QGeoServiceProvider test_noexperimental(
+ QStringLiteral("geocode.test.plugin"), QVariantMap(), false);
+ QCOMPARE(test_experimental.error(), QGeoServiceProvider::NoError);
+ QCOMPARE(test_noexperimental.error(), QGeoServiceProvider::NotSupportedError);
+
+ QGeoServiceProvider osm_experimental(
+ QStringLiteral("osm"), QVariantMap(), true);
+ QGeoServiceProvider osm_noexperimental(
+ QStringLiteral("osm"), QVariantMap(), false);
+ QCOMPARE(osm_experimental.error(), QGeoServiceProvider::NoError);
+ QCOMPARE(osm_noexperimental.error(), QGeoServiceProvider::NoError);
+}
+
+QTEST_GUILESS_MAIN(tst_QGeoServiceProvider)
+#include "tst_qgeoserviceprovider.moc"