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_qgeocodingmanager.h"
32
33 QT_USE_NAMESPACE
34
35
initTestCase()36 void tst_QGeoCodingManager::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_QGeoCodingManager::loadGeocodingManager();
51 }
52
cleanupTestCase()53 void tst_QGeoCodingManager::cleanupTestCase()
54 {
55 delete qgeoserviceprovider;
56 }
57
init()58 void tst_QGeoCodingManager::init()
59 {
60 qRegisterMetaType<QGeoCodeReply::Error>();
61 qRegisterMetaType<QGeoCodeReply*>();
62
63 signalerror = new QSignalSpy(qgeocodingmanager, SIGNAL(error(QGeoCodeReply*,QGeoCodeReply::Error,QString)));
64 signalfinished = new QSignalSpy(qgeocodingmanager, SIGNAL(finished(QGeoCodeReply*)));
65 QVERIFY( signalerror->isValid() );
66 QVERIFY( signalfinished->isValid() );
67 }
68
cleanup()69 void tst_QGeoCodingManager::cleanup()
70 {
71 delete signalerror;
72 delete signalfinished;
73 }
74
loadGeocodingManager()75 void tst_QGeoCodingManager::loadGeocodingManager()
76 {
77 QStringList providers = QGeoServiceProvider::availableServiceProviders();
78 QVERIFY(providers.contains("geocode.test.plugin"));
79
80 qgeoserviceprovider = new QGeoServiceProvider("geocode.test.plugin");
81 QVERIFY(qgeoserviceprovider);
82 QCOMPARE(qgeoserviceprovider->error(), QGeoServiceProvider::NotSupportedError);
83
84 qgeoserviceprovider->setAllowExperimental(true);
85 QCOMPARE(qgeoserviceprovider->error(), QGeoServiceProvider::NoError);
86 QCOMPARE(qgeoserviceprovider->geocodingFeatures(),
87 QGeoServiceProvider::OfflineGeocodingFeature
88 | QGeoServiceProvider::ReverseGeocodingFeature);
89
90 qgeocodingmanager = qgeoserviceprovider->geocodingManager();
91 QVERIFY(qgeocodingmanager);
92 }
93
locale()94 void tst_QGeoCodingManager::locale()
95 {
96 QLocale *german = new QLocale (QLocale::German, QLocale::Germany);
97 QLocale *english = new QLocale (QLocale::C, QLocale::AnyCountry);
98
99 //Default Locale from the Search Engine
100 QCOMPARE(qgeocodingmanager->locale(),*german);
101
102 qgeocodingmanager->setLocale(*english);
103
104 QCOMPARE(qgeocodingmanager->locale(),*english);
105
106 QVERIFY(qgeocodingmanager->locale() != *german);
107
108 delete german;
109 delete english;
110 }
111
name()112 void tst_QGeoCodingManager::name()
113 {
114 QString name = "geocode.test.plugin";
115 QCOMPARE(qgeocodingmanager->managerName(),name);
116 }
117
version()118 void tst_QGeoCodingManager::version()
119 {
120 int version=100;
121 QCOMPARE(qgeocodingmanager->managerVersion(),version);
122
123 }
124
search()125 void tst_QGeoCodingManager::search()
126 {
127 QCOMPARE(signalerror->count(),0);
128 QCOMPARE(signalfinished->count(),0);
129
130 QString search = "Berlin. Invaliendenstrasse";
131 int limit = 10;
132 int offset = 2;
133
134 QGeoCodeReply * reply = qgeocodingmanager->geocode(search, limit,offset);
135
136 QCOMPARE(reply->errorString(),search);
137 QCOMPARE(signalfinished->count(),1);
138 QCOMPARE(signalerror->count(),0);
139
140 delete reply;
141 }
142
geocode()143 void tst_QGeoCodingManager::geocode()
144 {
145 QCOMPARE(signalerror->count(),0);
146 QCOMPARE(signalfinished->count(),0);
147
148 QGeoAddress *address = new QGeoAddress ();
149 QString city = "Berlin";
150 address->setCity(city);
151
152 QGeoCodeReply *reply = qgeocodingmanager->geocode(*address);
153
154 QCOMPARE(reply->errorString(),city);
155 QCOMPARE(signalfinished->count(),1);
156 QCOMPARE(signalerror->count(),0);
157
158 delete address;
159 delete reply;
160 }
161
reverseGeocode()162 void tst_QGeoCodingManager::reverseGeocode()
163 {
164 QCOMPARE(signalerror->count(), 0);
165 QCOMPARE(signalfinished->count(), 0);
166
167 QGeoCoordinate *coordinate = new QGeoCoordinate(34.34, 56.65);
168
169 QGeoCodeReply *reply = qgeocodingmanager->reverseGeocode(*coordinate);
170
171 QCOMPARE(reply->errorString(), coordinate->toString());
172 QCOMPARE(signalfinished->count(), 1);
173 QCOMPARE(signalerror->count(), 0);
174
175 delete coordinate;
176 delete reply;
177
178
179 }
180
181
182 QTEST_GUILESS_MAIN(tst_QGeoCodingManager)
183
184