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 "qgeocameradata_p.h" |
33 | |
34 | QT_USE_NAMESPACE |
35 | |
36 | class tst_QGeoCameraData : public QObject |
37 | { |
38 | Q_OBJECT |
39 | |
40 | public: |
41 | tst_QGeoCameraData(); |
42 | |
43 | private: |
44 | void populateCameraData(); |
45 | |
46 | private Q_SLOTS: |
47 | void constructorTest_data(); |
48 | void constructorTest(); |
49 | void centerTest(); |
50 | void bearingTest(); |
51 | void tiltTest(); |
52 | void rollTest(); |
53 | void zoomLevelTest(); |
54 | void operatorsTest_data(); |
55 | void operatorsTest(); |
56 | }; |
57 | |
58 | tst_QGeoCameraData::tst_QGeoCameraData() |
59 | { |
60 | } |
61 | |
62 | |
63 | void tst_QGeoCameraData::populateCameraData() |
64 | { |
65 | QTest::addColumn<QGeoCoordinate>(name: "center" ); |
66 | QTest::addColumn<double>(name: "bearing" ); |
67 | QTest::addColumn<double>(name: "tilt" ); |
68 | QTest::addColumn<double>(name: "roll" ); |
69 | QTest::addColumn<double>(name: "zoomLevel" ); |
70 | QTest::newRow(dataTag: "zeros" ) << QGeoCoordinate() << 0.0 << 0.0 << 0.0 << 0.0; |
71 | QTest::newRow(dataTag: "valid" ) << QGeoCoordinate(10.0,20.5,30.8) << 0.1 << 0.2 << 0.3 << 2.0; |
72 | QTest::newRow(dataTag: "negative values" ) << QGeoCoordinate(-50,-20,100) << -0.1 << -0.2 << -0.3 << 1.0; |
73 | } |
74 | |
75 | void tst_QGeoCameraData::constructorTest_data(){ |
76 | populateCameraData(); |
77 | } |
78 | |
79 | void tst_QGeoCameraData::constructorTest() |
80 | { |
81 | QFETCH(QGeoCoordinate, center); |
82 | QFETCH(double, bearing); |
83 | QFETCH(double, tilt); |
84 | QFETCH(double, roll); |
85 | QFETCH(double, zoomLevel); |
86 | |
87 | // constructor test with default values |
88 | QGeoCameraData cameraData; |
89 | QGeoCameraData cameraData2(cameraData); |
90 | QCOMPARE(cameraData.center(), cameraData2.center()); |
91 | QCOMPARE(cameraData.bearing(), cameraData2.bearing()); |
92 | QCOMPARE(cameraData.tilt(), cameraData2.tilt()); |
93 | QCOMPARE(cameraData.roll(), cameraData2.roll()); |
94 | QCOMPARE(cameraData.zoomLevel(), cameraData2.zoomLevel()); |
95 | |
96 | // constructor test after setting values |
97 | cameraData.setCenter(center); |
98 | cameraData.setBearing(bearing); |
99 | cameraData.setTilt(tilt); |
100 | cameraData.setRoll(roll); |
101 | cameraData.setZoomLevel(zoomLevel); |
102 | QGeoCameraData cameraData3(cameraData); |
103 | // test the correctness of the constructor copy |
104 | QCOMPARE(cameraData3.center(), center); |
105 | QCOMPARE(cameraData3.bearing(), bearing); |
106 | QCOMPARE(cameraData3.tilt(), tilt); |
107 | QCOMPARE(cameraData3.roll(), roll); |
108 | QCOMPARE(cameraData3.zoomLevel(), zoomLevel); |
109 | // verify that values have not changed after a constructor copy |
110 | QCOMPARE(cameraData.center(), cameraData3.center()); |
111 | QCOMPARE(cameraData.bearing(), cameraData3.bearing()); |
112 | QCOMPARE(cameraData.tilt(), cameraData3.tilt()); |
113 | QCOMPARE(cameraData.roll(), cameraData3.roll()); |
114 | QCOMPARE(cameraData.zoomLevel(), cameraData3.zoomLevel()); |
115 | } |
116 | |
117 | |
118 | void tst_QGeoCameraData::centerTest() |
119 | { |
120 | QGeoCameraData cameraData; //center currently default to (-27.5, 153) |
121 | cameraData.setCenter(QGeoCoordinate(10.0,20.4,30.8)); |
122 | QCOMPARE(cameraData.center(),QGeoCoordinate(10.0,20.4,30.8)); |
123 | } |
124 | |
125 | void tst_QGeoCameraData::bearingTest(){ |
126 | QGeoCameraData cameraData; |
127 | QCOMPARE(cameraData.bearing(),0.0); |
128 | cameraData.setBearing(0.1); |
129 | QCOMPARE(cameraData.bearing(),0.1); |
130 | |
131 | QGeoCameraData cameraData2 = cameraData; |
132 | QCOMPARE(cameraData2.bearing(),0.1); |
133 | cameraData.setBearing(0.2); |
134 | QCOMPARE(cameraData2.bearing(),0.1); |
135 | } |
136 | |
137 | void tst_QGeoCameraData::tiltTest(){ |
138 | QGeoCameraData cameraData; |
139 | QCOMPARE(cameraData.tilt(),0.0); |
140 | cameraData.setTilt(0.4); |
141 | QCOMPARE(cameraData.tilt(),0.4); |
142 | |
143 | QGeoCameraData cameraData2 = cameraData; |
144 | QCOMPARE(cameraData2.tilt(),0.4); |
145 | cameraData.setTilt(0.5); |
146 | QCOMPARE(cameraData2.tilt(),0.4); |
147 | } |
148 | |
149 | void tst_QGeoCameraData::rollTest(){ |
150 | QGeoCameraData cameraData; |
151 | QCOMPARE(cameraData.roll(),0.0); |
152 | cameraData.setRoll(0.5); |
153 | QCOMPARE(cameraData.roll(),0.5); |
154 | |
155 | QGeoCameraData cameraData2 = cameraData; |
156 | QCOMPARE(cameraData2.roll(),0.5); |
157 | cameraData.setRoll(0.6); |
158 | QCOMPARE(cameraData2.roll(),0.5); |
159 | } |
160 | |
161 | void tst_QGeoCameraData::zoomLevelTest(){ |
162 | QGeoCameraData cameraData; //zoom level currently defaults to 9.0 |
163 | cameraData.setZoomLevel(8.0); |
164 | QCOMPARE(cameraData.zoomLevel(),8.0); |
165 | |
166 | QGeoCameraData cameraData2 = cameraData; |
167 | QCOMPARE(cameraData2.zoomLevel(),8.0); |
168 | cameraData.setZoomLevel(9.0); |
169 | QCOMPARE(cameraData2.zoomLevel(),8.0); |
170 | } |
171 | |
172 | void tst_QGeoCameraData::operatorsTest_data(){ |
173 | populateCameraData(); |
174 | } |
175 | |
176 | void tst_QGeoCameraData::operatorsTest(){ |
177 | QGeoCameraData cameraData; |
178 | QGeoCameraData cameraData2; |
179 | QVERIFY2(cameraData == cameraData2, "Camera data with default values are not copied correctly" ); |
180 | |
181 | QFETCH(QGeoCoordinate, center); |
182 | QFETCH(double, bearing); |
183 | QFETCH(double, tilt); |
184 | QFETCH(double, roll); |
185 | QFETCH(double, zoomLevel); |
186 | cameraData.setCenter(center); |
187 | cameraData.setBearing(bearing); |
188 | cameraData.setTilt(tilt); |
189 | cameraData.setRoll(roll); |
190 | cameraData.setZoomLevel(zoomLevel); |
191 | |
192 | QGeoCameraData cameraData3; |
193 | cameraData3 = cameraData; |
194 | QVERIFY2(cameraData == cameraData3, "Camera data not copied correctly" ); |
195 | |
196 | // test QGeoCameraData pairs where they differ in one field |
197 | QGeoCameraData cameraData4; |
198 | cameraData4 = cameraData; |
199 | cameraData4.setCenter(QGeoCoordinate(10.0,20.0,30.0)); |
200 | QVERIFY2(cameraData != cameraData4, "Camera data should be different" ); |
201 | QGeoCameraData cameraData5; |
202 | cameraData5 = cameraData; |
203 | cameraData5.setBearing(bearing+1.0); |
204 | QVERIFY2(cameraData != cameraData5, "Camera data should be different" ); |
205 | QGeoCameraData cameraData6; |
206 | cameraData6 = cameraData; |
207 | cameraData6.setTilt(tilt+0.1); |
208 | QVERIFY2(cameraData != cameraData6, "Camera data should be different" ); |
209 | QGeoCameraData cameraData7; |
210 | cameraData7 = cameraData; |
211 | cameraData7.setRoll(roll+0.1); |
212 | QVERIFY2(cameraData != cameraData7, "Camera data should be different" ); |
213 | QGeoCameraData cameraData8; |
214 | cameraData8 = cameraData; |
215 | cameraData8.setZoomLevel(zoomLevel+1.0); |
216 | QVERIFY2(cameraData != cameraData8, "Camera data should be different" ); |
217 | } |
218 | |
219 | QTEST_APPLESS_MAIN(tst_QGeoCameraData) |
220 | |
221 | #include "tst_qgeocameradata.moc" |
222 | |