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_qgeoroutesegment.h"
30
31 QT_USE_NAMESPACE
32
tst_QGeoRouteSegment()33 tst_QGeoRouteSegment::tst_QGeoRouteSegment()
34 {
35 }
36
initTestCase()37 void tst_QGeoRouteSegment::initTestCase()
38 {
39 }
40
cleanupTestCase()41 void tst_QGeoRouteSegment::cleanupTestCase()
42 {
43 }
44
init()45 void tst_QGeoRouteSegment::init()
46 {
47 qgeocoordinate = new QGeoCoordinate();
48 qgeoroutesegment = new QGeoRouteSegment();
49 qgeomaneuver = new QGeoManeuver();
50 }
51
cleanup()52 void tst_QGeoRouteSegment::cleanup()
53 {
54 delete qgeocoordinate;
55 delete qgeoroutesegment;
56 }
57
constructor()58 void tst_QGeoRouteSegment::constructor()
59 {
60 QVERIFY(!qgeoroutesegment->isValid());
61 QCOMPARE(qgeoroutesegment->distance(), qreal(0.0));
62 QCOMPARE(qgeoroutesegment->maneuver(),*qgeomaneuver);
63 QCOMPARE(qgeoroutesegment->travelTime(),0);
64 }
65
copy_constructor()66 void tst_QGeoRouteSegment::copy_constructor()
67 {
68 QGeoRouteSegment *qgeoroutesegmentcopy = new QGeoRouteSegment(*qgeoroutesegment);
69
70 QCOMPARE(*qgeoroutesegment, *qgeoroutesegmentcopy);
71
72 QVERIFY(!qgeoroutesegmentcopy->isValid());
73 QCOMPARE(qgeoroutesegmentcopy->distance(), qreal(0.0));
74 QCOMPARE(qgeoroutesegmentcopy->maneuver(), *qgeomaneuver);
75 QCOMPARE(qgeoroutesegmentcopy->travelTime(), 0);
76
77 delete qgeoroutesegmentcopy;
78 }
79
destructor()80 void tst_QGeoRouteSegment::destructor()
81 {
82 QGeoRouteSegment *qgeoroutesegmentcopy;
83
84 qgeoroutesegmentcopy = new QGeoRouteSegment();
85 delete qgeoroutesegmentcopy;
86
87 qgeoroutesegmentcopy = new QGeoRouteSegment(*qgeoroutesegment);
88 delete qgeoroutesegmentcopy;
89 }
90
91
travelTime()92 void tst_QGeoRouteSegment::travelTime()
93 {
94 QFETCH(int, traveltime);
95
96 QGeoRouteSegment sgmt;
97 QVERIFY(!sgmt.isValid());
98
99 sgmt.setTravelTime(traveltime);
100
101 QVERIFY(sgmt.isValid());
102 QCOMPARE(sgmt.travelTime(), traveltime);
103 }
104
travelTime_data()105 void tst_QGeoRouteSegment::travelTime_data()
106 {
107 QTest::addColumn<int>("traveltime");
108
109 QTest::newRow("travel1") << 0;
110 QTest::newRow("travel2") << -50;
111 QTest::newRow("travel3") << 324556;
112 }
113
distance()114 void tst_QGeoRouteSegment::distance()
115 {
116 QFETCH(qreal, distance);
117
118 QGeoRouteSegment sgmt;
119 QVERIFY(!sgmt.isValid());
120
121 sgmt.setDistance(distance);
122
123 QVERIFY(sgmt.isValid());
124 QCOMPARE(sgmt.distance(), distance);
125 }
126
distance_data()127 void tst_QGeoRouteSegment::distance_data()
128 {
129 QTest::addColumn<qreal>("distance");
130
131 QTest::newRow("distance1") << qreal(0.0) ;
132 QTest::newRow("distance2") << qreal(-50.3435) ;
133 QTest::newRow("distance3") << qreal(324556.543534) ;
134 }
135
136
path()137 void tst_QGeoRouteSegment::path()
138 {
139 QFETCH(QList<double>, coordinates);
140
141 QGeoRouteSegment sgmt;
142 QVERIFY(!sgmt.isValid());
143
144 QList<QGeoCoordinate> path;
145
146 for (int i = 0; i < coordinates.size(); i += 2) {
147 path.append(QGeoCoordinate(coordinates.at(i), coordinates.at(i+1)));
148 }
149
150 sgmt.setPath(path);
151 QVERIFY(sgmt.isValid());
152
153 QList<QGeoCoordinate> pathretrieved = sgmt.path();
154 QCOMPARE(pathretrieved, path);
155
156 for (int i = 0; i < pathretrieved.size(); i++) {
157 QCOMPARE(pathretrieved.at(i), path.at(i));
158 }
159 }
160
path_data()161 void tst_QGeoRouteSegment::path_data()
162 {
163 QTest::addColumn<QList<double> >("coordinates");
164
165 QList<double> coordinates;
166
167 coordinates << 0.0 << 0.0;
168 QTest::newRow("path1") << coordinates;
169
170 coordinates << -23.23 << 54.45345;
171 QTest::newRow("path2") << coordinates;
172
173 coordinates << -85.4324 << -121.343;
174 QTest::newRow("path3") << coordinates;
175
176 coordinates << 1.323 << 12.323;
177 QTest::newRow("path4") << coordinates;
178
179 coordinates << 1324.323 << 143242.323;
180 QTest::newRow("path5") << coordinates;
181 }
182
nextroutesegment()183 void tst_QGeoRouteSegment::nextroutesegment()
184 {
185 QGeoRouteSegment sgmt;
186 QVERIFY(!sgmt.isValid());
187
188 QGeoRouteSegment *qgeoroutesegmentcopy = new QGeoRouteSegment();
189 qgeoroutesegmentcopy->setDistance(45.34);
190
191 sgmt.setNextRouteSegment(*qgeoroutesegmentcopy);
192
193 QVERIFY(sgmt.isValid());
194 QCOMPARE(sgmt.nextRouteSegment(), *qgeoroutesegmentcopy);
195
196 QCOMPARE((sgmt.nextRouteSegment()).distance(),
197 qgeoroutesegmentcopy->distance());
198 delete qgeoroutesegmentcopy;
199
200 }
201
maneuver()202 void tst_QGeoRouteSegment::maneuver()
203 {
204 QGeoRouteSegment sgmt;
205 QVERIFY(!sgmt.isValid());
206
207 sgmt.setManeuver(*qgeomaneuver);
208 QCOMPARE(sgmt.maneuver(), *qgeomaneuver);
209 QVERIFY(sgmt.isValid());
210 }
211
operators()212 void tst_QGeoRouteSegment::operators()
213 {
214 //Create a copy and see that they are the same
215 QGeoRouteSegment *qgeoroutesegmentcopy = new QGeoRouteSegment(*qgeoroutesegment);
216 QGeoRouteSegment *trueSgmtCopy = new QGeoRouteSegment();
217
218 QVERIFY(qgeoroutesegment->operator ==(*qgeoroutesegmentcopy));
219 QVERIFY(!qgeoroutesegment->operator !=(*qgeoroutesegmentcopy));
220 QVERIFY(!qgeoroutesegment->isValid());
221 QVERIFY(!qgeoroutesegmentcopy->isValid());
222
223 //Same segment ? content is the same but pointer different
224 QVERIFY(qgeoroutesegment->operator ==(*trueSgmtCopy));
225 QVERIFY(!qgeoroutesegment->operator !=(*trueSgmtCopy));
226 QVERIFY(!trueSgmtCopy->isValid());
227
228 QFETCH(double, distance);
229 QFETCH(int, traveltime);
230 QFETCH(QList<double>, coordinates);
231
232 QList<QGeoCoordinate> path;
233
234 for (int i = 0; i < coordinates.size(); i += 2) {
235 path.append(QGeoCoordinate(coordinates.at(i), coordinates.at(i+1)));
236 }
237
238 qgeoroutesegment->setDistance(distance);
239 qgeoroutesegment->setTravelTime(traveltime);
240 qgeoroutesegment->setPath(path);
241
242 trueSgmtCopy->setDistance(distance);
243 trueSgmtCopy->setTravelTime(traveltime);
244 trueSgmtCopy->setPath(path);
245
246 QCOMPARE(qgeoroutesegment->distance(), distance);
247 QCOMPARE(qgeoroutesegment->travelTime(), traveltime);
248 QCOMPARE(qgeoroutesegment->path(), path);
249
250 QCOMPARE(qgeoroutesegmentcopy->distance(), distance);
251 QCOMPARE(qgeoroutesegmentcopy->travelTime(), traveltime);
252 QCOMPARE(qgeoroutesegmentcopy->path(), path);
253
254 QCOMPARE(trueSgmtCopy->distance(), distance);
255 QCOMPARE(trueSgmtCopy->travelTime(), traveltime);
256 QCOMPARE(trueSgmtCopy->path(), path);
257
258 //Same as based off copy constructor (d-pointer shared)
259 QVERIFY(qgeoroutesegment->operator==(*qgeoroutesegmentcopy));
260 QVERIFY(!qgeoroutesegment->operator!=(*qgeoroutesegmentcopy));
261
262 //Same as based off same content although different d-pointer
263 QVERIFY(qgeoroutesegment->operator==(*trueSgmtCopy));
264 QVERIFY(!qgeoroutesegment->operator!=(*trueSgmtCopy));
265
266 const int newTravelTime = 111;
267 trueSgmtCopy->setTravelTime(newTravelTime);
268 QCOMPARE(trueSgmtCopy->travelTime(), newTravelTime);
269
270 //different d-pointer and different content
271 QVERIFY(!qgeoroutesegment->operator==(*trueSgmtCopy));
272 QVERIFY(qgeoroutesegment->operator!=(*trueSgmtCopy));
273
274 //Assign one segment to the other and test that they are the same again
275 *qgeoroutesegmentcopy = qgeoroutesegmentcopy->operator =(*qgeoroutesegment);
276 QVERIFY(qgeoroutesegment->operator==(*qgeoroutesegmentcopy));
277 QVERIFY(!qgeoroutesegment->operator!=(*qgeoroutesegmentcopy));
278
279 *qgeoroutesegmentcopy = qgeoroutesegmentcopy->operator =(*trueSgmtCopy);
280 QVERIFY(trueSgmtCopy->operator==(*qgeoroutesegmentcopy));
281 QVERIFY(!trueSgmtCopy->operator!=(*qgeoroutesegmentcopy));
282
283 delete trueSgmtCopy;
284 delete qgeoroutesegmentcopy;
285 }
286
operators_data()287 void tst_QGeoRouteSegment::operators_data()
288 {
289 QTest::addColumn<double>("distance");
290 QTest::addColumn<int>("traveltime");
291 QTest::addColumn<QList<double> >("coordinates");
292
293 QList<double> coordinates;
294
295 coordinates << 0.0 << 0.0 << 23.234 << -121.767 << 8.43534 << 32.789;
296 QTest::newRow("set1") << 143545.43 << 45665 << coordinates;
297
298 coordinates << 42.343 << -38.657;
299 QTest::newRow("set2") << 745654.43 << 786585 << coordinates;
300 }
301
302 QTEST_APPLESS_MAIN(tst_QGeoRouteSegment);
303