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_qgeocodereply.h"
30 
31 QT_USE_NAMESPACE
32 
initTestCase()33 void tst_QGeoCodeReply::initTestCase()
34 {
35 
36     reply = new SubGeocodeReply();
37 }
38 
cleanupTestCase()39 void tst_QGeoCodeReply::cleanupTestCase()
40 {
41 
42     delete reply;
43     delete qgeolocation;
44 }
45 
init()46 void tst_QGeoCodeReply::init()
47 {
48     qRegisterMetaType<QGeoCodeReply::Error>();
49     signalerror = new QSignalSpy(reply, SIGNAL(error(QGeoCodeReply::Error,QString)));
50     signalfinished = new QSignalSpy(reply, SIGNAL(finished()));
51 }
52 
cleanup()53 void tst_QGeoCodeReply::cleanup()
54 {
55     delete signalerror;
56     delete signalfinished;
57 }
58 
constructor()59 void tst_QGeoCodeReply::constructor()
60 {
61     QVERIFY(!reply->isFinished());
62 
63     QCOMPARE(reply->limit(),-1);
64     QCOMPARE(reply->offset(),0);
65     QCOMPARE(reply->error(),QGeoCodeReply::NoError);
66 
67     QVERIFY( signalerror->isValid() );
68     QVERIFY( signalfinished->isValid() );
69 
70     QCOMPARE(signalerror->count(),0);
71     QCOMPARE(signalfinished->count(),0);
72 }
73 
constructor_error()74 void tst_QGeoCodeReply::constructor_error()
75 {
76     QFETCH(QGeoCodeReply::Error,error);
77     QFETCH(QString,msg);
78 
79     QVERIFY( signalerror->isValid() );
80     QVERIFY( signalfinished->isValid() );
81 
82     QGeoCodeReply *qgeocodereplycopy = new QGeoCodeReply (error,msg,0);
83 
84     QCOMPARE(signalerror->count(),0);
85     QCOMPARE(signalfinished->count(),0);
86 
87     QCOMPARE (qgeocodereplycopy->error(),error);
88     QCOMPARE (qgeocodereplycopy->errorString(),msg);
89 
90     delete qgeocodereplycopy;
91 }
92 
constructor_error_data()93 void tst_QGeoCodeReply::constructor_error_data()
94 {
95     QTest::addColumn<QGeoCodeReply::Error>("error");
96     QTest::addColumn<QString>("msg");
97 
98     QTest::newRow("error1") << QGeoCodeReply::NoError << "No error.";
99     QTest::newRow("error2") << QGeoCodeReply::EngineNotSetError << "Engine Not Set Error.";
100     QTest::newRow("error3") << QGeoCodeReply::CommunicationError << "Communication Error.";
101     QTest::newRow("error4") << QGeoCodeReply::ParseError << "Parse Error.";
102     QTest::newRow("error5") << QGeoCodeReply::UnsupportedOptionError << "Unsupported Option Error.";
103     QTest::newRow("error6") << QGeoCodeReply::UnknownError << "Unknown Error.";
104 
105 }
106 
destructor()107 void tst_QGeoCodeReply::destructor()
108 {
109     QGeoCodeReply *qgeocodereplycopy;
110     QFETCH(QGeoCodeReply::Error,error);
111     QFETCH(QString,msg);
112 
113     qgeocodereplycopy = new QGeoCodeReply (error,msg,0);
114     delete qgeocodereplycopy;
115 }
116 
destructor_data()117 void tst_QGeoCodeReply::destructor_data()
118 {
119     tst_QGeoCodeReply::constructor_error_data();
120 }
121 
abort()122 void tst_QGeoCodeReply::abort()
123 {
124     QVERIFY( signalerror->isValid() );
125     QVERIFY( signalfinished->isValid() );
126 
127     QCOMPARE(signalerror->count(),0);
128     QCOMPARE (signalfinished->count(),0);
129 
130     reply->callSetFinished(true);
131     reply->abort();
132 
133     QCOMPARE(signalerror->count(),0);
134     QCOMPARE (signalfinished->count(),1);
135 
136     reply->abort();
137     reply->callSetFinished(false);
138     reply->abort();
139 
140     QCOMPARE(signalerror->count(),0);
141     QCOMPARE (signalfinished->count(),2);
142 }
143 
error()144 void tst_QGeoCodeReply::error()
145 {
146     QFETCH(QGeoCodeReply::Error,error);
147     QFETCH(QString,msg);
148 
149     QVERIFY( signalerror->isValid() );
150     QVERIFY( signalfinished->isValid() );
151     QCOMPARE(signalerror->count(),0);
152 
153     reply->callSetError(error,msg);
154 
155    QCOMPARE(signalerror->count(),1);
156    QCOMPARE(signalfinished->count(),1);
157    QCOMPARE(reply->errorString(),msg);
158    QCOMPARE(reply->error(),error);
159 
160 
161 }
162 
error_data()163 void tst_QGeoCodeReply::error_data()
164 {
165     QTest::addColumn<QGeoCodeReply::Error>("error");
166     QTest::addColumn<QString>("msg");
167 
168     QTest::newRow("error1") << QGeoCodeReply::NoError << "No error.";
169     QTest::newRow("error2") << QGeoCodeReply::EngineNotSetError << "Engine Not Set Error.";
170     QTest::newRow("error3") << QGeoCodeReply::CommunicationError << "Communication Error.";
171     QTest::newRow("error4") << QGeoCodeReply::ParseError << "Parse Error.";
172     QTest::newRow("error5") << QGeoCodeReply::UnsupportedOptionError << "Unsupported Option Error.";
173     QTest::newRow("error6") << QGeoCodeReply::UnknownError << "Unknown Error.";
174 }
175 
finished()176 void tst_QGeoCodeReply::finished()
177 {
178     QVERIFY( signalerror->isValid() );
179     QVERIFY( signalfinished->isValid() );
180 
181     QCOMPARE(signalerror->count(),0);
182     QCOMPARE (signalfinished->count(),0);
183 
184     reply->callSetFinished(true);
185     QVERIFY(reply->isFinished());
186     QCOMPARE(signalerror->count(),0);
187     QCOMPARE (signalfinished->count(),1);
188 
189     reply->callSetFinished(false);
190 
191     QVERIFY(!reply->isFinished());
192     QCOMPARE(signalerror->count(),0);
193     QCOMPARE (signalfinished->count(),1);
194 
195     reply->callSetFinished(true);
196 
197     QVERIFY(reply->isFinished());
198     QCOMPARE(signalerror->count(),0);
199     QCOMPARE (signalfinished->count(),2);
200 }
201 
202 
203 
limit()204 void tst_QGeoCodeReply::limit()
205 {
206     int limit =30;
207     reply->callSetLimit(limit);
208     QCOMPARE(reply->limit(),limit);
209 }
210 
offset()211 void tst_QGeoCodeReply::offset()
212 {
213     int offset = 2;
214     reply->callSetOffset(offset);
215     QCOMPARE(reply->offset(),offset);
216 }
217 
locations()218 void tst_QGeoCodeReply::locations()
219 {
220     QList <QGeoLocation> geolocations;
221     geolocations = reply->locations();
222 
223     QCOMPARE(geolocations.size(),0);
224 
225     QGeoAddress *qgeoaddress = new QGeoAddress ();
226     qgeoaddress->setCity("Berlin");
227 
228     QGeoCoordinate *qgeocoordinate = new QGeoCoordinate (12.12 , 54.43);
229 
230     qgeolocation = new QGeoLocation ();
231     qgeolocation->setAddress(*qgeoaddress);
232     qgeolocation->setCoordinate(*qgeocoordinate);
233 
234     reply->callAddLocation(*qgeolocation);
235 
236     geolocations = reply->locations();
237     QCOMPARE(geolocations.size(),1);
238     QCOMPARE(geolocations.at(0),*qgeolocation);
239 
240     QGeoLocation *qgeolocationcopy = new QGeoLocation (*qgeolocation);
241 
242     QList <QGeoLocation> qgeolocations;
243     qgeolocations.append(*qgeolocation);
244     qgeolocations.append(*qgeolocationcopy);
245 
246     reply->callSetLocations(qgeolocations);
247 
248     geolocations = reply->locations();
249 
250     QCOMPARE(geolocations.size(),qgeolocations.size());
251     for (int i = 0 ; i < geolocations.size(); i++)
252     {
253         QCOMPARE(geolocations.at(i),qgeolocations.at(i));
254     }
255 
256     delete qgeoaddress;
257     delete qgeocoordinate;
258     delete qgeolocationcopy;
259 }
260 
viewport()261 void tst_QGeoCodeReply::viewport()
262 {
263     QGeoCoordinate *qgeocoordinate = new QGeoCoordinate (12.12 , 54.43);
264 
265     qgeoboundingbox = new QGeoRectangle (*qgeocoordinate, 0.5 , 0.5);
266 
267     reply->callSetViewport(*qgeoboundingbox);
268 
269     QCOMPARE (reply->viewport(), static_cast<const QGeoShape &>(*qgeoboundingbox));
270 
271     delete qgeocoordinate;
272     delete qgeoboundingbox;
273 }
274 
275 QTEST_MAIN(tst_QGeoCodeReply);
276