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_qgeoroutereply.h"
30
31QT_USE_NAMESPACE
32
33void tst_QGeoRouteReply::initTestCase()
34{
35 qgeocoordinate1 = new QGeoCoordinate(43.5435 , 76.342);
36 qgeocoordinate2 = new QGeoCoordinate(-43.5435 , 176.342);
37 qgeocoordinate3 = new QGeoCoordinate(-13.5435 , +76.342);
38
39 waypoints.append(t: *qgeocoordinate1);
40 waypoints.append(t: *qgeocoordinate2);
41 waypoints.append(t: *qgeocoordinate3);
42
43 qgeorouterequest = new QGeoRouteRequest(waypoints);
44 reply = new SubRouteReply(*qgeorouterequest);
45}
46
47void tst_QGeoRouteReply::cleanupTestCase()
48{
49 delete qgeocoordinate1;
50 delete qgeocoordinate2;
51 delete qgeocoordinate3;
52 delete qgeorouterequest;
53 delete reply;
54}
55
56void tst_QGeoRouteReply::init()
57{
58 qRegisterMetaType<QGeoRouteReply::Error>();
59 signalerror = new QSignalSpy(reply, SIGNAL(error(QGeoRouteReply::Error,QString)));
60 signalfinished = new QSignalSpy(reply, SIGNAL(finished()));
61}
62
63void tst_QGeoRouteReply::cleanup()
64{
65 delete signalerror;
66 delete signalfinished;
67}
68
69void tst_QGeoRouteReply::constructor()
70{
71 QVERIFY(!reply->isFinished());
72 QCOMPARE(reply->error(), QGeoRouteReply::NoError);
73 QCOMPARE(reply->request(), *qgeorouterequest);
74
75 QVERIFY(signalerror->isValid());
76 QVERIFY(signalfinished->isValid());
77
78 QCOMPARE(signalerror->count(),0);
79 QCOMPARE(signalfinished->count(),0);
80}
81
82void tst_QGeoRouteReply::constructor_error()
83{
84 QFETCH(QGeoRouteReply::Error,error);
85 QFETCH(QString,msg);
86
87 QVERIFY(signalerror->isValid());
88 QVERIFY(signalfinished->isValid());
89
90 QGeoRouteReply *qgeoroutereplycopy = new QGeoRouteReply(error, msg, 0);
91
92 QCOMPARE(signalerror->count(), 0);
93 QCOMPARE(signalfinished->count(), 0);
94
95 QVERIFY(qgeoroutereplycopy->isFinished());
96 QCOMPARE(qgeoroutereplycopy->error(), error);
97 QCOMPARE(qgeoroutereplycopy->errorString(), msg);
98
99 delete qgeoroutereplycopy;
100}
101
102void tst_QGeoRouteReply::constructor_error_data()
103{
104 QTest::addColumn<QGeoRouteReply::Error>(name: "error");
105 QTest::addColumn<QString>(name: "msg");
106
107 QTest::newRow(dataTag: "error1") << QGeoRouteReply::NoError << "No error.";
108 QTest::newRow(dataTag: "error2") << QGeoRouteReply::EngineNotSetError << "Engine Not Set Error.";
109 QTest::newRow(dataTag: "error3") << QGeoRouteReply::CommunicationError << "Communication Error.";
110 QTest::newRow(dataTag: "error4") << QGeoRouteReply::ParseError << "Parse Error.";
111 QTest::newRow(dataTag: "error5") << QGeoRouteReply::UnsupportedOptionError << "Unsupported Option Error.";
112 QTest::newRow(dataTag: "error6") << QGeoRouteReply::UnknownError << "Unknown Error.";
113
114}
115
116void tst_QGeoRouteReply::destructor()
117{
118 QGeoRouteReply *qgeoroutereplycopy;
119
120 QFETCH(QGeoRouteReply::Error, error);
121 QFETCH(QString, msg);
122
123 qgeoroutereplycopy = new QGeoRouteReply(error, msg, 0);
124 delete qgeoroutereplycopy;
125
126}
127
128void tst_QGeoRouteReply::destructor_data()
129{
130 tst_QGeoRouteReply::constructor_error_data();
131}
132
133void tst_QGeoRouteReply::routes()
134{
135 QList<QGeoRoute> routes;
136 QGeoRoute *route1 = new QGeoRoute();
137 QGeoRoute *route2 = new QGeoRoute();
138
139 route1->setDistance(15.12);
140 route2->setDistance(20.12);
141
142 routes.append(t: *route1);
143 routes.append(t: *route2);
144
145 reply->callSetRoutes(routes);
146
147 QList<QGeoRoute> routescopy;
148 routescopy = reply->routes();
149 QCOMPARE(routescopy,routes);
150
151 QCOMPARE(routescopy.at(0).distance(),route1->distance());
152 QCOMPARE(routescopy.at(1).distance(),route2->distance());
153
154 delete route1;
155 delete route2;
156}
157
158void tst_QGeoRouteReply::finished()
159{
160 QVERIFY(signalerror->isValid());
161 QVERIFY(signalfinished->isValid());
162
163 QCOMPARE(signalerror->count(), 0);
164 QCOMPARE(signalfinished->count(), 0);
165
166 reply->callSetFinished(finished: true);
167
168 QCOMPARE(signalerror->count(), 0);
169 QCOMPARE(signalfinished->count(), 1);
170
171 reply->callSetFinished(finished: false);
172
173 QCOMPARE(signalerror->count(), 0);
174 QCOMPARE(signalfinished->count(), 1);
175
176 reply->callSetFinished(finished: true);
177
178 QCOMPARE(signalerror->count(), 0);
179 QCOMPARE(signalfinished->count(), 2);
180}
181
182void tst_QGeoRouteReply::abort()
183{
184 QVERIFY(signalerror->isValid());
185 QVERIFY(signalfinished->isValid());
186
187 QCOMPARE(signalerror->count(), 0);
188 QCOMPARE(signalfinished->count(), 0);
189
190 reply->abort();
191
192 QCOMPARE(signalerror->count(), 0);
193 QCOMPARE(signalfinished->count(), 0);
194
195 reply->abort();
196 reply->callSetFinished(finished: false);
197 reply->abort();
198
199 QCOMPARE(signalerror->count(), 0);
200 QCOMPARE(signalfinished->count(), 0);
201}
202
203void tst_QGeoRouteReply::error()
204{
205 QFETCH(QGeoRouteReply::Error, error);
206 QFETCH(QString, msg);
207
208 QVERIFY(signalerror->isValid());
209 QVERIFY(signalfinished->isValid());
210 QCOMPARE(signalerror->count(), 0);
211
212 reply->callSetError(error,msg);
213
214 QCOMPARE(signalerror->count(), 1);
215 QCOMPARE(signalfinished->count(), 1);
216 QCOMPARE(reply->errorString(), msg);
217 QCOMPARE(reply->error(), error);
218}
219
220void tst_QGeoRouteReply::error_data()
221{
222 QTest::addColumn<QGeoRouteReply::Error>(name: "error");
223 QTest::addColumn<QString>(name: "msg");
224
225 QTest::newRow(dataTag: "error1") << QGeoRouteReply::NoError << "No error.";
226 QTest::newRow(dataTag: "error2") << QGeoRouteReply::EngineNotSetError << "Engine Not Set Error.";
227 QTest::newRow(dataTag: "error3") << QGeoRouteReply::CommunicationError << "Communication Error.";
228 QTest::newRow(dataTag: "error4") << QGeoRouteReply::ParseError << "Parse Error.";
229 QTest::newRow(dataTag: "error5") << QGeoRouteReply::UnsupportedOptionError << "Unsupported Option Error.";
230 QTest::newRow(dataTag: "error6") << QGeoRouteReply::UnknownError << "Unknown Error.";
231}
232
233void tst_QGeoRouteReply::request()
234{
235 SubRouteReply *rr = new SubRouteReply(*qgeorouterequest);
236
237 QCOMPARE(rr->request(), *qgeorouterequest);
238
239 delete rr;
240}
241
242QTEST_APPLESS_MAIN(tst_QGeoRouteReply);
243

source code of qtlocation/tests/auto/qgeoroutereply/tst_qgeoroutereply.cpp