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_qgeolocation.h"
30 
31 QT_USE_NAMESPACE
32 
tst_QGeoLocation()33 tst_QGeoLocation::tst_QGeoLocation()
34 {
35 }
36 
initTestCase()37 void tst_QGeoLocation::initTestCase()
38 {
39 
40 }
41 
cleanupTestCase()42 void tst_QGeoLocation::cleanupTestCase()
43 {
44 
45 }
46 
init()47 void tst_QGeoLocation::init()
48 {
49 }
50 
cleanup()51 void tst_QGeoLocation::cleanup()
52 {
53 }
54 
constructor()55 void tst_QGeoLocation::constructor()
56 {
57     QCOMPARE(m_location.address(), m_address);
58     QCOMPARE(m_location.coordinate(), m_coordinate);
59     QCOMPARE(m_location.boundingBox(), m_viewport);
60     QCOMPARE(m_location.extendedAttributes(), m_extendedAttributes);
61 }
62 
copy_constructor()63 void tst_QGeoLocation::copy_constructor()
64 {
65     QGeoLocation *qgeolocationcopy = new QGeoLocation (m_location);
66     QCOMPARE(m_location, *qgeolocationcopy);
67     delete qgeolocationcopy;
68 }
69 
destructor()70 void tst_QGeoLocation::destructor()
71 {
72     QGeoLocation *qgeolocationcopy;
73 
74     qgeolocationcopy = new QGeoLocation();
75     delete qgeolocationcopy;
76 
77     qgeolocationcopy = new QGeoLocation(m_location);
78     delete qgeolocationcopy;
79 }
80 
address()81 void tst_QGeoLocation::address()
82 {
83     m_address.setCity("Berlin");
84     m_address.setCountry("Germany");
85     m_address.setCountryCode("DEU");
86     m_address.setDistrict("Mitte");
87     m_address.setPostalCode("10115");
88     m_address.setStreet("Invalidenstrasse");
89 
90     m_location.setAddress(m_address);
91 
92     QCOMPARE(m_location.address(),m_address);
93 
94     m_address.setPostalCode("10125");
95     QVERIFY(m_location.address() != m_address);
96 }
97 
coordinate()98 void tst_QGeoLocation::coordinate()
99 {
100     m_coordinate.setLatitude(13.3851);
101     m_coordinate.setLongitude(52.5312);
102     m_coordinate.setAltitude(134.23);
103 
104     m_location.setCoordinate(m_coordinate);
105 
106     QCOMPARE(m_location.coordinate(), m_coordinate);
107 
108     m_coordinate.setAltitude(0);
109     QVERIFY(m_location.coordinate() != m_coordinate);
110 }
111 
viewport()112 void tst_QGeoLocation::viewport()
113 {
114     m_coordinate.setLatitude(13.3851);
115     m_coordinate.setLongitude(52.5312);
116 
117     QGeoRectangle qgeoboundingboxcopy(m_coordinate, 0.4, 0.4);
118     m_location.setBoundingBox(qgeoboundingboxcopy);
119 
120     QCOMPARE(m_location.boundingBox(),qgeoboundingboxcopy);
121 
122     qgeoboundingboxcopy.setHeight(1);
123 
124     QVERIFY(m_location.boundingBox() != qgeoboundingboxcopy);
125 }
126 
extendedAttributes()127 void tst_QGeoLocation::extendedAttributes()
128 {
129     m_extendedAttributes = QVariantMap({{ "foo" , 42 }});
130     m_location.setExtendedAttributes(m_extendedAttributes);
131     QCOMPARE(m_location.extendedAttributes(), m_extendedAttributes);
132 
133     m_extendedAttributes["foo"] = 41;
134     QVERIFY(m_location.extendedAttributes() != m_extendedAttributes);
135 }
136 
operators()137 void tst_QGeoLocation::operators()
138 {
139     QGeoAddress qgeoaddresscopy;
140     qgeoaddresscopy.setCity("Berlin");
141     qgeoaddresscopy.setCountry("Germany");
142     qgeoaddresscopy.setCountryCode("DEU");
143 
144     QGeoCoordinate qgeocoordinatecopy (32.324 , 41.324 , 24.55);
145     QVariantMap extendedAttributesCopy {{ "foo" , 42 }};
146 
147     m_address.setCity("Madrid");
148     m_address.setCountry("Spain");
149     m_address.setCountryCode("SPA");
150 
151     m_coordinate.setLatitude(21.3434);
152     m_coordinate.setLongitude(38.43443);
153     m_coordinate.setAltitude(634.21);
154 
155     m_extendedAttributes["foo"] = 43;
156 
157     m_location.setAddress(m_address);
158     m_location.setCoordinate(m_coordinate);
159     m_location.setExtendedAttributes(m_extendedAttributes);
160 
161     //Create a copy and see that they are the same
162     QGeoLocation qgeolocationcopy(m_location);
163     QVERIFY(m_location == qgeolocationcopy);
164     QVERIFY(!(m_location != qgeolocationcopy));
165 
166     //Modify one and test if they are different
167    qgeolocationcopy.setAddress(qgeoaddresscopy);
168    QVERIFY(!(m_location == qgeolocationcopy));
169    QVERIFY(m_location != qgeolocationcopy);
170    qgeolocationcopy.setAddress(m_address);
171    qgeolocationcopy.setCoordinate(qgeocoordinatecopy);
172    QVERIFY(!(m_location == qgeolocationcopy));
173    QVERIFY(m_location != qgeolocationcopy);
174    qgeolocationcopy.setCoordinate(m_coordinate);
175    qgeolocationcopy.setExtendedAttributes(extendedAttributesCopy);
176    QVERIFY(!(m_location == qgeolocationcopy));
177    QVERIFY(m_location != qgeolocationcopy);
178 
179 
180     //delete qgeolocationcopy;
181     //Asign and test that they are the same
182     qgeolocationcopy = m_location;
183     QVERIFY(m_location ==qgeolocationcopy);
184     QVERIFY(!(m_location != qgeolocationcopy));
185 }
186 
comparison()187 void tst_QGeoLocation::comparison()
188 {
189     QFETCH(QString, dataField);
190 
191     QGeoLocation location;
192 
193     //set address
194     QGeoAddress address;
195     address.setStreet("21 jump st");
196     address.setCountry("USA");
197     location.setAddress(address);
198 
199     //set coordinate
200     location.setCoordinate(QGeoCoordinate(5,10));
201 
202     //set viewport
203     location.setBoundingBox(QGeoRectangle(QGeoCoordinate(5,5),0.4,0.4));
204 
205     QGeoLocation otherLocation(location);
206 
207     if (dataField == "no change") {
208         QCOMPARE(location, otherLocation);
209     } else {
210         if (dataField == "address") {
211             QGeoAddress otherAddress;
212             otherAddress.setStreet("42 evergreen tce");
213             otherAddress.setCountry("USA");
214             otherLocation.setAddress(otherAddress);
215         } else if (dataField == "coordinate") {
216             otherLocation.setCoordinate(QGeoCoordinate(12,13));
217         } else if (dataField == "viewport"){
218             otherLocation.setBoundingBox(QGeoRectangle(QGeoCoordinate(1,2), 0.5,0.5));
219         } else if (dataField == "extendedAttributes"){
220             otherLocation.setExtendedAttributes(QVariantMap({{"foo", 44}}));
221         } else {
222             qFatal("Unknown data field to test");
223         }
224 
225         QVERIFY(location != otherLocation);
226     }
227 }
228 
comparison_data()229 void tst_QGeoLocation::comparison_data()
230 {
231     QTest::addColumn<QString> ("dataField");
232     QTest::newRow("no change") << "no change";
233     QTest::newRow("address") << "address";
234     QTest::newRow("coordinate") << "coordinate";
235     QTest::newRow("extendedAttributes") << "extendedAttributes";
236 }
237 
isEmpty()238 void tst_QGeoLocation::isEmpty()
239 {
240     QGeoAddress address;
241     address.setCity(QStringLiteral("Braunschweig"));
242     QVERIFY(!address.isEmpty());
243 
244     QGeoRectangle boundingBox;
245     boundingBox.setTopLeft(QGeoCoordinate(1, -1));
246     boundingBox.setBottomRight(QGeoCoordinate(-1, 1));
247     QVERIFY(!boundingBox.isEmpty());
248 
249     QVariantMap extendedAttributes({{"foo", 11}});
250 
251     QGeoLocation location;
252 
253     QVERIFY(location.isEmpty());
254 
255     // address
256     location.setAddress(address);
257     QVERIFY(!location.isEmpty());
258     location.setAddress(QGeoAddress());
259     QVERIFY(location.isEmpty());
260 
261     // coordinate
262     location.setCoordinate(QGeoCoordinate(1, 2));
263     QVERIFY(!location.isEmpty());
264     location.setCoordinate(QGeoCoordinate());
265     QVERIFY(location.isEmpty());
266 
267     // bounding box
268     location.setBoundingBox(boundingBox);
269     QVERIFY(!location.isEmpty());
270     location.setBoundingBox(QGeoRectangle());
271     QVERIFY(location.isEmpty());
272 
273     // extended attributes
274     location.setExtendedAttributes(extendedAttributes);
275     QVERIFY(!location.isEmpty());
276     location.setExtendedAttributes(QVariantMap());
277     QVERIFY(location.isEmpty());
278 }
279 
280 QTEST_APPLESS_MAIN(tst_QGeoLocation);
281 
282