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 <QtCore/QString> |
30 | #include <QtTest/QtTest> |
31 | |
32 | #include <QtLocation/private/qgeocameracapabilities_p.h> |
33 | #include <QtLocation/private/qgeotiledmap_p.h> |
34 | |
35 | QT_USE_NAMESPACE |
36 | |
37 | class tst_QGeoCameraCapabilities : public QObject |
38 | { |
39 | Q_OBJECT |
40 | |
41 | public: |
42 | tst_QGeoCameraCapabilities(); |
43 | |
44 | private: |
45 | void populateGeoCameraCapabilitiesData(); |
46 | |
47 | private Q_SLOTS: |
48 | void constructorTest_data(); |
49 | void constructorTest(); |
50 | void minimumZoomLevelTest(); |
51 | void maximumZoomLevelTest(); |
52 | void supportsBearingTest(); |
53 | void supportsRollingTest(); |
54 | void supportsTiltingTest(); |
55 | void minimumTiltTest(); |
56 | void maximumTiltTest(); |
57 | void minimumFieldOfViewTest(); |
58 | void maximumFieldOfViewTest(); |
59 | void operatorsTest_data(); |
60 | void operatorsTest(); |
61 | void isValidTest(); |
62 | }; |
63 | |
64 | tst_QGeoCameraCapabilities::tst_QGeoCameraCapabilities() |
65 | { |
66 | } |
67 | |
68 | void tst_QGeoCameraCapabilities::populateGeoCameraCapabilitiesData(){ |
69 | QTest::addColumn<double>(name: "minimumZoomLevel" ); |
70 | QTest::addColumn<double>(name: "maximumZoomLevel" ); |
71 | QTest::addColumn<double>(name: "minimumTilt" ); |
72 | QTest::addColumn<double>(name: "maximumTilt" ); |
73 | QTest::addColumn<double>(name: "minimumFieldOfView" ); |
74 | QTest::addColumn<double>(name: "maximumFieldOfView" ); |
75 | QTest::addColumn<bool>(name: "bearingSupport" ); |
76 | QTest::addColumn<bool>(name: "rollingSupport" ); |
77 | QTest::addColumn<bool>(name: "tiltingSupport" ); |
78 | QTest::newRow(dataTag: "zeros" ) << 0.0 << 0.0 << 0.0 << 0.0 << 0.0 << 0.0 << false << false << false; |
79 | QTest::newRow(dataTag: "valid" ) << 1.0 << 2.0 << 0.5 << 1.5 << 1.0 << 179.0 << true << true << true; |
80 | QTest::newRow(dataTag: "negative values" ) << 0.0 << 0.5 << -0.5 << -0.1 << -20.0 << -30.0 << true << true << true; |
81 | } |
82 | |
83 | void tst_QGeoCameraCapabilities::constructorTest_data(){ |
84 | populateGeoCameraCapabilitiesData(); |
85 | } |
86 | |
87 | void tst_QGeoCameraCapabilities::constructorTest() |
88 | { |
89 | QFETCH(double, minimumZoomLevel); |
90 | QFETCH(double, maximumZoomLevel); |
91 | QFETCH(double, minimumTilt); |
92 | QFETCH(double, maximumTilt); |
93 | QFETCH(double, minimumFieldOfView); |
94 | QFETCH(double, maximumFieldOfView); |
95 | QFETCH(bool, bearingSupport); |
96 | QFETCH(bool, rollingSupport); |
97 | QFETCH(bool, tiltingSupport); |
98 | |
99 | minimumFieldOfView = qBound(min: 1.0, val: minimumFieldOfView, max: 179.0); |
100 | maximumFieldOfView = qBound(min: 1.0, val: maximumFieldOfView, max: 179.0); |
101 | |
102 | // contructor test with default values |
103 | QGeoCameraCapabilities cameraCapabilities; |
104 | QGeoCameraCapabilities cameraCapabilities2(cameraCapabilities); |
105 | QCOMPARE(cameraCapabilities.minimumZoomLevel(), cameraCapabilities2.minimumZoomLevel()); |
106 | QCOMPARE(cameraCapabilities.maximumZoomLevel(), cameraCapabilities2.maximumZoomLevel()); |
107 | QVERIFY2(cameraCapabilities.supportsBearing() == cameraCapabilities2.supportsBearing(), "Copy constructor failed for bearing support" ); |
108 | QVERIFY2(cameraCapabilities.supportsRolling() == cameraCapabilities2.supportsRolling(), "Copy constructor failed for rolling support " ); |
109 | QVERIFY2(cameraCapabilities.supportsTilting() == cameraCapabilities2.supportsTilting(), "Copy constructor failed for tilting support" ); |
110 | QCOMPARE(cameraCapabilities.minimumTilt(), cameraCapabilities2.minimumTilt()); |
111 | QCOMPARE(cameraCapabilities.maximumTilt(), cameraCapabilities2.maximumTilt()); |
112 | QCOMPARE(cameraCapabilities.minimumFieldOfView(), cameraCapabilities2.minimumFieldOfView()); |
113 | QCOMPARE(cameraCapabilities.maximumFieldOfView(), cameraCapabilities2.maximumFieldOfView()); |
114 | |
115 | // constructor test after setting values |
116 | cameraCapabilities.setMinimumZoomLevel(minimumZoomLevel); |
117 | cameraCapabilities.setMaximumZoomLevel(maximumZoomLevel); |
118 | cameraCapabilities.setMinimumTilt(minimumTilt); |
119 | cameraCapabilities.setMaximumTilt(maximumTilt); |
120 | cameraCapabilities.setMinimumFieldOfView(minimumFieldOfView); |
121 | cameraCapabilities.setMaximumFieldOfView(maximumFieldOfView); |
122 | cameraCapabilities.setSupportsBearing(bearingSupport); |
123 | cameraCapabilities.setSupportsRolling(rollingSupport); |
124 | cameraCapabilities.setSupportsTilting(tiltingSupport); |
125 | |
126 | QGeoCameraCapabilities cameraCapabilities3(cameraCapabilities); |
127 | // test the correctness of the constructor copy |
128 | QCOMPARE(cameraCapabilities3.minimumZoomLevel(), minimumZoomLevel); |
129 | QCOMPARE(cameraCapabilities3.maximumZoomLevel(), maximumZoomLevel); |
130 | QCOMPARE(cameraCapabilities3.minimumTilt(), minimumTilt); |
131 | QCOMPARE(cameraCapabilities3.maximumTilt(), maximumTilt); |
132 | QCOMPARE(cameraCapabilities3.minimumFieldOfView(), minimumFieldOfView); |
133 | QCOMPARE(cameraCapabilities3.maximumFieldOfView(), maximumFieldOfView); |
134 | QVERIFY2(cameraCapabilities3.supportsBearing() == bearingSupport, "Copy constructor failed for bearing support" ); |
135 | QVERIFY2(cameraCapabilities3.supportsRolling() == rollingSupport, "Copy constructor failed for rolling support " ); |
136 | QVERIFY2(cameraCapabilities3.supportsTilting() == tiltingSupport, "Copy constructor failed for tilting support" ); |
137 | // verify that values have not changed after a constructor copy |
138 | QCOMPARE(cameraCapabilities.minimumZoomLevel(), cameraCapabilities3.minimumZoomLevel()); |
139 | QCOMPARE(cameraCapabilities.maximumZoomLevel(), cameraCapabilities3.maximumZoomLevel()); |
140 | QVERIFY2(cameraCapabilities.supportsBearing() == cameraCapabilities3.supportsBearing(), "Copy constructor failed for bearing support" ); |
141 | QVERIFY2(cameraCapabilities.supportsRolling() == cameraCapabilities3.supportsRolling(), "Copy constructor failed for rolling support " ); |
142 | QVERIFY2(cameraCapabilities.supportsTilting() == cameraCapabilities3.supportsTilting(), "Copy constructor failed for tilting support" ); |
143 | QCOMPARE(cameraCapabilities.minimumTilt(), cameraCapabilities3.minimumTilt()); |
144 | QCOMPARE(cameraCapabilities.maximumTilt(), cameraCapabilities3.maximumTilt()); |
145 | QCOMPARE(cameraCapabilities.minimumFieldOfView(), cameraCapabilities3.minimumFieldOfView()); |
146 | QCOMPARE(cameraCapabilities.maximumFieldOfView(), cameraCapabilities3.maximumFieldOfView()); |
147 | } |
148 | |
149 | void tst_QGeoCameraCapabilities::minimumZoomLevelTest() |
150 | { |
151 | QGeoCameraCapabilities cameraCapabilities; |
152 | cameraCapabilities.setMinimumZoomLevel(1.5); |
153 | QCOMPARE(cameraCapabilities.minimumZoomLevel(), 1.5); |
154 | |
155 | QGeoCameraCapabilities cameraCapabilities2 = cameraCapabilities; |
156 | QCOMPARE(cameraCapabilities2.minimumZoomLevel(), 1.5); |
157 | cameraCapabilities.setMinimumZoomLevel(2.5); |
158 | QCOMPARE(cameraCapabilities2.minimumZoomLevel(), 1.5); |
159 | } |
160 | |
161 | void tst_QGeoCameraCapabilities::maximumZoomLevelTest() |
162 | { |
163 | QGeoCameraCapabilities cameraCapabilities; |
164 | cameraCapabilities.setMaximumZoomLevel(3.5); |
165 | QCOMPARE(cameraCapabilities.maximumZoomLevel(), 3.5); |
166 | |
167 | QGeoCameraCapabilities cameraCapabilities2 = cameraCapabilities; |
168 | QCOMPARE(cameraCapabilities2.maximumZoomLevel(), 3.5); |
169 | cameraCapabilities.setMaximumZoomLevel(4.5); |
170 | QCOMPARE(cameraCapabilities2.maximumZoomLevel(), 3.5); |
171 | } |
172 | |
173 | void tst_QGeoCameraCapabilities::supportsBearingTest(){ |
174 | QGeoCameraCapabilities cameraCapabilities; |
175 | QVERIFY(!cameraCapabilities.supportsBearing()); |
176 | cameraCapabilities.setSupportsBearing(true); |
177 | QVERIFY2(cameraCapabilities.supportsBearing(), "Camera capabilities should support bearing" ); |
178 | |
179 | QGeoCameraCapabilities cameraCapabilities2 = cameraCapabilities; |
180 | QVERIFY(cameraCapabilities2.supportsBearing()); |
181 | cameraCapabilities.setSupportsBearing(false); |
182 | QVERIFY2(cameraCapabilities2.supportsBearing(), "Camera capabilities should support bearing" ); |
183 | } |
184 | |
185 | void tst_QGeoCameraCapabilities::supportsRollingTest(){ |
186 | QGeoCameraCapabilities cameraCapabilities; |
187 | QVERIFY(!cameraCapabilities.supportsRolling()); |
188 | cameraCapabilities.setSupportsRolling(true); |
189 | QVERIFY2(cameraCapabilities.supportsRolling(), "Camera capabilities should support rolling" ); |
190 | |
191 | QGeoCameraCapabilities cameraCapabilities2 = cameraCapabilities; |
192 | QVERIFY(cameraCapabilities2.supportsRolling()); |
193 | cameraCapabilities.setSupportsRolling(false); |
194 | QVERIFY2(cameraCapabilities2.supportsRolling(), "Camera capabilities should support rolling" ); |
195 | } |
196 | |
197 | void tst_QGeoCameraCapabilities::supportsTiltingTest(){ |
198 | QGeoCameraCapabilities cameraCapabilities; |
199 | QVERIFY(!cameraCapabilities.supportsTilting()); |
200 | cameraCapabilities.setSupportsTilting(true); |
201 | QVERIFY2(cameraCapabilities.supportsTilting(), "Camera capabilities should support tilting" ); |
202 | |
203 | QGeoCameraCapabilities cameraCapabilities2 = cameraCapabilities; |
204 | QVERIFY(cameraCapabilities2.supportsTilting()); |
205 | cameraCapabilities.setSupportsTilting(false); |
206 | QVERIFY2(cameraCapabilities2.supportsTilting(), "Camera capabilities should support tilting" ); |
207 | } |
208 | |
209 | void tst_QGeoCameraCapabilities::minimumTiltTest(){ |
210 | QGeoCameraCapabilities cameraCapabilities; |
211 | QCOMPARE(cameraCapabilities.minimumTilt(),0.0); |
212 | cameraCapabilities.setMinimumTilt(0.5); |
213 | QCOMPARE(cameraCapabilities.minimumTilt(),0.5); |
214 | |
215 | QGeoCameraCapabilities cameraCapabilities2 = cameraCapabilities; |
216 | QCOMPARE(cameraCapabilities2.minimumTilt(), 0.5); |
217 | cameraCapabilities.setMinimumTilt(1.5); |
218 | QCOMPARE(cameraCapabilities2.minimumTilt(), 0.5); |
219 | } |
220 | |
221 | void tst_QGeoCameraCapabilities::maximumTiltTest(){ |
222 | QGeoCameraCapabilities cameraCapabilities; |
223 | QCOMPARE(cameraCapabilities.maximumTilt(),0.0); |
224 | cameraCapabilities.setMaximumTilt(1.5); |
225 | QCOMPARE(cameraCapabilities.maximumTilt(),1.5); |
226 | |
227 | QGeoCameraCapabilities cameraCapabilities2 = cameraCapabilities; |
228 | QCOMPARE(cameraCapabilities2.maximumTilt(), 1.5); |
229 | cameraCapabilities.setMaximumTilt(2.5); |
230 | QCOMPARE(cameraCapabilities2.maximumTilt(), 1.5); |
231 | } |
232 | |
233 | void tst_QGeoCameraCapabilities::minimumFieldOfViewTest() |
234 | { |
235 | QGeoCameraCapabilities cameraCapabilities; |
236 | QCOMPARE(cameraCapabilities.minimumFieldOfView(), 45.0); // min/max default to 45 |
237 | cameraCapabilities.setMinimumFieldOfView(1.5); |
238 | QCOMPARE(cameraCapabilities.minimumFieldOfView(), 1.5); |
239 | cameraCapabilities.setMinimumFieldOfView(-1.5); |
240 | QCOMPARE(cameraCapabilities.minimumFieldOfView(), 1.0); |
241 | cameraCapabilities.setMinimumFieldOfView(245.5); |
242 | QCOMPARE(cameraCapabilities.minimumFieldOfView(), 179.0); |
243 | |
244 | QGeoCameraCapabilities cameraCapabilities2 = cameraCapabilities; |
245 | QCOMPARE(cameraCapabilities2.minimumFieldOfView(), 179.0); |
246 | cameraCapabilities.setMinimumFieldOfView(2.5); |
247 | QCOMPARE(cameraCapabilities2.minimumFieldOfView(), 179.0); |
248 | } |
249 | |
250 | void tst_QGeoCameraCapabilities::maximumFieldOfViewTest() |
251 | { |
252 | QGeoCameraCapabilities cameraCapabilities; |
253 | QCOMPARE(cameraCapabilities.maximumFieldOfView(), 45.0); // min/max default to 45 |
254 | cameraCapabilities.setMaximumFieldOfView(1.5); |
255 | QCOMPARE(cameraCapabilities.maximumFieldOfView(), 1.5); |
256 | cameraCapabilities.setMaximumFieldOfView(-1.5); |
257 | QCOMPARE(cameraCapabilities.maximumFieldOfView(), 1.0); |
258 | cameraCapabilities.setMaximumFieldOfView(245.5); |
259 | QCOMPARE(cameraCapabilities.maximumFieldOfView(), 179.0); |
260 | |
261 | QGeoCameraCapabilities cameraCapabilities2 = cameraCapabilities; |
262 | QCOMPARE(cameraCapabilities2.maximumFieldOfView(), 179.0); |
263 | cameraCapabilities.setMaximumFieldOfView(2.5); |
264 | QCOMPARE(cameraCapabilities2.maximumFieldOfView(), 179.0); |
265 | } |
266 | |
267 | void tst_QGeoCameraCapabilities::operatorsTest_data(){ |
268 | populateGeoCameraCapabilitiesData(); |
269 | } |
270 | |
271 | void tst_QGeoCameraCapabilities::operatorsTest(){ |
272 | |
273 | QFETCH(double, minimumZoomLevel); |
274 | QFETCH(double, maximumZoomLevel); |
275 | QFETCH(double, minimumTilt); |
276 | QFETCH(double, maximumTilt); |
277 | QFETCH(double, minimumFieldOfView); |
278 | QFETCH(double, maximumFieldOfView); |
279 | QFETCH(bool, bearingSupport); |
280 | QFETCH(bool, rollingSupport); |
281 | QFETCH(bool, tiltingSupport); |
282 | |
283 | minimumFieldOfView = qBound(min: 1.0, val: minimumFieldOfView, max: 179.0); |
284 | maximumFieldOfView = qBound(min: 1.0, val: maximumFieldOfView, max: 179.0); |
285 | |
286 | QGeoCameraCapabilities cameraCapabilities; |
287 | cameraCapabilities.setMinimumZoomLevel(minimumZoomLevel); |
288 | cameraCapabilities.setMaximumZoomLevel(maximumZoomLevel); |
289 | cameraCapabilities.setMinimumTilt(minimumTilt); |
290 | cameraCapabilities.setMaximumTilt(maximumTilt); |
291 | cameraCapabilities.setMinimumFieldOfView(minimumFieldOfView); |
292 | cameraCapabilities.setMaximumFieldOfView(maximumFieldOfView); |
293 | cameraCapabilities.setSupportsBearing(bearingSupport); |
294 | cameraCapabilities.setSupportsRolling(rollingSupport); |
295 | cameraCapabilities.setSupportsTilting(tiltingSupport); |
296 | QGeoCameraCapabilities cameraCapabilities2; |
297 | cameraCapabilities2 = cameraCapabilities; |
298 | // test the correctness of the assignment |
299 | QCOMPARE(cameraCapabilities2.minimumZoomLevel(), minimumZoomLevel); |
300 | QCOMPARE(cameraCapabilities2.maximumZoomLevel(), maximumZoomLevel); |
301 | QCOMPARE(cameraCapabilities2.minimumTilt(), minimumTilt); |
302 | QCOMPARE(cameraCapabilities2.maximumTilt(), maximumTilt); |
303 | QVERIFY2(cameraCapabilities2.supportsBearing() == bearingSupport, "Assignment operator failed for bearing support" ); |
304 | QVERIFY2(cameraCapabilities2.supportsRolling() == rollingSupport, "Assignment operator failed for rolling support " ); |
305 | QVERIFY2(cameraCapabilities2.supportsTilting() == tiltingSupport, "Assignment operator failed for tilting support" ); |
306 | QCOMPARE(cameraCapabilities2.minimumFieldOfView(), minimumFieldOfView); |
307 | QCOMPARE(cameraCapabilities2.maximumFieldOfView(), maximumFieldOfView); |
308 | // verify that values have not changed after a constructor copy |
309 | QCOMPARE(cameraCapabilities.minimumZoomLevel(), cameraCapabilities2.minimumZoomLevel()); |
310 | QCOMPARE(cameraCapabilities.maximumZoomLevel(), cameraCapabilities2.maximumZoomLevel()); |
311 | QVERIFY2(cameraCapabilities.supportsBearing() == cameraCapabilities2.supportsBearing(), "Assignment operator failed for bearing support" ); |
312 | QVERIFY2(cameraCapabilities.supportsRolling() == cameraCapabilities2.supportsRolling(), "Assignment operator failed for rolling support " ); |
313 | QVERIFY2(cameraCapabilities.supportsTilting() == cameraCapabilities2.supportsTilting(), "Assignment operator failed for tilting support" ); |
314 | QCOMPARE(cameraCapabilities.minimumTilt(), cameraCapabilities2.minimumTilt()); |
315 | QCOMPARE(cameraCapabilities.maximumTilt(), cameraCapabilities2.maximumTilt()); |
316 | QCOMPARE(cameraCapabilities.minimumFieldOfView(), cameraCapabilities2.minimumFieldOfView()); |
317 | QCOMPARE(cameraCapabilities.maximumFieldOfView(), cameraCapabilities2.maximumFieldOfView()); |
318 | } |
319 | |
320 | void tst_QGeoCameraCapabilities::isValidTest(){ |
321 | QGeoCameraCapabilities cameraCapabilities; |
322 | QVERIFY2(!cameraCapabilities.isValid(), "Camera capabilities should default to invalid" ); |
323 | cameraCapabilities.setSupportsBearing(true); |
324 | QVERIFY2(cameraCapabilities.isValid(), "Camera capabilities should be valid" ); |
325 | |
326 | QGeoCameraCapabilities cameraCapabilities2; |
327 | QVERIFY2(!cameraCapabilities2.isValid(), "Camera capabilities should default to invalid" ); |
328 | cameraCapabilities2.setSupportsRolling(true); |
329 | QVERIFY2(cameraCapabilities2.isValid(), "Camera capabilities should be valid" ); |
330 | |
331 | QGeoCameraCapabilities cameraCapabilities3; |
332 | QVERIFY2(!cameraCapabilities3.isValid(), "Camera capabilities should default to invalid" ); |
333 | cameraCapabilities3.setSupportsTilting(true); |
334 | QVERIFY2(cameraCapabilities3.isValid(), "Camera capabilities should be valid" ); |
335 | |
336 | QGeoCameraCapabilities cameraCapabilities4; |
337 | QVERIFY2(!cameraCapabilities4.isValid(), "Camera capabilities should default to invalid" ); |
338 | cameraCapabilities4.setMinimumZoomLevel(1.0); |
339 | QVERIFY2(cameraCapabilities4.isValid(), "Camera capabilities should be valid" ); |
340 | |
341 | QGeoCameraCapabilities cameraCapabilities5; |
342 | QVERIFY2(!cameraCapabilities5.isValid(), "Camera capabilities should default to invalid" ); |
343 | cameraCapabilities5.setMaximumZoomLevel(1.5); |
344 | QVERIFY2(cameraCapabilities5.isValid(), "Camera capabilities should be valid" ); |
345 | |
346 | QGeoCameraCapabilities cameraCapabilities6; |
347 | QVERIFY2(!cameraCapabilities6.isValid(), "Camera capabilities should default to invalid" ); |
348 | cameraCapabilities6.setMinimumTilt(0.2); |
349 | QVERIFY2(cameraCapabilities6.isValid(), "Camera capabilities should be valid" ); |
350 | |
351 | QGeoCameraCapabilities cameraCapabilities7; |
352 | QVERIFY2(!cameraCapabilities7.isValid(), "Camera capabilities should default to invalid" ); |
353 | cameraCapabilities7.setMaximumTilt(0.8); |
354 | QVERIFY2(cameraCapabilities7.isValid(), "Camera capabilities should be valid" ); |
355 | } |
356 | |
357 | QTEST_APPLESS_MAIN(tst_QGeoCameraCapabilities) |
358 | |
359 | #include "tst_qgeocameracapabilities.moc" |
360 | |