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 <QtTest/QtTest> |
30 | #include <QtQml/QQmlEngine> |
31 | #include <QtQml/QQmlComponent> |
32 | #include <QtQml/QQmlListReference> |
33 | #include <QtPositioning/QGeoCoordinate> |
34 | #include <QtPositioning/QGeoAddress> |
35 | #include <QtPositioning/QGeoRectangle> |
36 | #include <QtPositioning/QGeoCircle> |
37 | #include <QtPositioning/QGeoLocation> |
38 | #include <QtLocation/QPlaceCategory> |
39 | #include <QtLocation/QPlace> |
40 | #include <QtLocation/QPlaceIcon> |
41 | #include <QtLocation/QPlaceRatings> |
42 | #include <QtLocation/QPlaceSupplier> |
43 | #include <QtLocation/QPlaceUser> |
44 | #include <QtLocation/QPlaceAttribute> |
45 | #include <QtLocation/QPlaceContactDetail> |
46 | |
47 | class tst_qmlinterface : public QObject |
48 | { |
49 | Q_OBJECT |
50 | |
51 | public: |
52 | tst_qmlinterface(); |
53 | |
54 | private Q_SLOTS: |
55 | void testAddress(); |
56 | void testLocation(); |
57 | void testCategory(); |
58 | void testIcon(); |
59 | void testRatings(); |
60 | void testSupplier(); |
61 | void testUser(); |
62 | void testPlaceAttribute(); |
63 | void testContactDetail(); |
64 | void testPlace(); |
65 | |
66 | private: |
67 | QGeoCoordinate m_coordinate; |
68 | QGeoAddress m_address; |
69 | QGeoRectangle m_rectangle; |
70 | QGeoLocation m_location; |
71 | QPlaceCategory m_category; |
72 | QPlaceIcon m_icon; |
73 | QPlaceRatings m_ratings; |
74 | QPlaceSupplier m_supplier; |
75 | QPlaceUser m_user; |
76 | QPlaceAttribute m_placeAttribute; |
77 | QPlaceContactDetail m_contactDetail; |
78 | QList<QPlaceCategory> m_categories; |
79 | QPlace m_place; |
80 | }; |
81 | |
82 | tst_qmlinterface::tst_qmlinterface() |
83 | { |
84 | m_coordinate.setLongitude(10.0); |
85 | m_coordinate.setLatitude(20.0); |
86 | m_coordinate.setAltitude(30.0); |
87 | |
88 | m_address.setCity(QStringLiteral("Brisbane" )); |
89 | m_address.setCountry(QStringLiteral("Australia" )); |
90 | m_address.setCountryCode(QStringLiteral("AU" )); |
91 | m_address.setPostalCode(QStringLiteral("4000" )); |
92 | m_address.setState(QStringLiteral("Queensland" )); |
93 | m_address.setStreet(QStringLiteral("123 Fake Street" )); |
94 | |
95 | m_rectangle.setCenter(m_coordinate); |
96 | m_rectangle.setHeight(30.0); |
97 | m_rectangle.setWidth(40.0); |
98 | |
99 | m_location.setAddress(m_address); |
100 | m_location.setBoundingBox(m_rectangle); |
101 | m_location.setCoordinate(m_coordinate); |
102 | |
103 | m_category.setName(QStringLiteral("Test category" )); |
104 | m_category.setCategoryId(QStringLiteral("test-category-id" )); |
105 | |
106 | QVariantMap iconParams; |
107 | iconParams.insert(akey: QPlaceIcon::SingleUrl, avalue: QUrl(QStringLiteral("http://www.example.com/test-icon.png" ))); |
108 | m_icon.setParameters(iconParams); |
109 | |
110 | m_ratings.setAverage(3.5); |
111 | m_ratings.setMaximum(5.0); |
112 | m_ratings.setCount(10); |
113 | |
114 | m_supplier.setName(QStringLiteral("Test supplier" )); |
115 | m_supplier.setUrl(QUrl(QStringLiteral("http://www.example.com/test-supplier" ))); |
116 | m_supplier.setSupplierId(QStringLiteral("test-supplier-id" )); |
117 | m_supplier.setIcon(m_icon); |
118 | |
119 | m_user.setName(QStringLiteral("Test User" )); |
120 | m_user.setUserId(QStringLiteral("test-user-id" )); |
121 | |
122 | m_placeAttribute.setLabel(QStringLiteral("Test Attribute" )); |
123 | m_placeAttribute.setText(QStringLiteral("Test attribute text" )); |
124 | |
125 | m_contactDetail.setLabel(QStringLiteral("Test Contact Detail" )); |
126 | m_contactDetail.setValue(QStringLiteral("Test contact detail value" )); |
127 | |
128 | QPlaceCategory category; |
129 | category.setName(QStringLiteral("Test category 1" )); |
130 | category.setCategoryId(QStringLiteral("test-category-id-1" )); |
131 | m_categories.append(t: category); |
132 | category.setName(QStringLiteral("Test category 2" )); |
133 | category.setCategoryId(QStringLiteral("test-category-id-2" )); |
134 | m_categories.append(t: category); |
135 | |
136 | m_place.setName(QStringLiteral("Test Place" )); |
137 | m_place.setPlaceId(QStringLiteral("test-place-id" )); |
138 | m_place.setAttribution(QStringLiteral("Place data by Foo" )); |
139 | m_place.setCategories(m_categories); |
140 | m_place.setLocation(m_location); |
141 | m_place.setRatings(m_ratings); |
142 | m_place.setIcon(m_icon); |
143 | m_place.setSupplier(m_supplier); |
144 | m_place.setVisibility(QLocation::PrivateVisibility); |
145 | } |
146 | |
147 | void tst_qmlinterface::testAddress() |
148 | { |
149 | QQmlEngine engine; |
150 | QQmlComponent component(&engine, SRCDIR "data/TestAddress.qml" ); |
151 | QVERIFY2(component.isReady(), qPrintable(component.errorString())); |
152 | QObject *qmlObject = component.create(); |
153 | |
154 | QGeoAddress address = qmlObject->property(name: "address" ).value<QGeoAddress>(); |
155 | |
156 | QCOMPARE(address, m_address); |
157 | |
158 | qmlObject->setProperty(name: "address" , value: QVariant::fromValue(value: QGeoAddress())); |
159 | |
160 | QVERIFY(qmlObject->property("city" ).toString().isEmpty()); |
161 | QVERIFY(qmlObject->property("country" ).toString().isEmpty()); |
162 | QVERIFY(qmlObject->property("countryCode" ).toString().isEmpty()); |
163 | QVERIFY(qmlObject->property("postalCode" ).toString().isEmpty()); |
164 | QVERIFY(qmlObject->property("state" ).toString().isEmpty()); |
165 | QVERIFY(qmlObject->property("street" ).toString().isEmpty()); |
166 | |
167 | delete qmlObject; |
168 | } |
169 | |
170 | void tst_qmlinterface::testLocation() |
171 | { |
172 | QQmlEngine engine; |
173 | QQmlComponent component(&engine, SRCDIR "data/TestLocation.qml" ); |
174 | QVERIFY2(component.isReady(), qPrintable(component.errorString())); |
175 | QObject *qmlObject = component.create(); |
176 | |
177 | QGeoLocation location = qmlObject->property(name: "location" ).value<QGeoLocation>(); |
178 | |
179 | QCOMPARE(location, m_location); |
180 | |
181 | qmlObject->setProperty(name: "location" , value: QVariant::fromValue(value: QGeoLocation())); |
182 | |
183 | QCOMPARE(qmlObject->property("address" ).value<QGeoAddress>(), QGeoAddress()); |
184 | QCOMPARE(qmlObject->property("boundingBox" ).value<QGeoRectangle>(), QGeoRectangle()); |
185 | QCOMPARE(qmlObject->property("coordinate" ).value<QGeoCoordinate>(), QGeoCoordinate()); |
186 | |
187 | delete qmlObject; |
188 | } |
189 | |
190 | void tst_qmlinterface::testCategory() |
191 | { |
192 | QQmlEngine engine; |
193 | QQmlComponent component(&engine, SRCDIR "data/TestCategory.qml" ); |
194 | QVERIFY2(component.isReady(), qPrintable(component.errorString())); |
195 | QObject *qmlObject = component.create(); |
196 | |
197 | QPlaceCategory category = qmlObject->property(name: "category" ).value<QPlaceCategory>(); |
198 | |
199 | QCOMPARE(category, m_category); |
200 | |
201 | qmlObject->setProperty(name: "category" , value: QVariant::fromValue(value: QPlaceCategory())); |
202 | |
203 | QVERIFY(qmlObject->property("name" ).toString().isEmpty()); |
204 | QVERIFY(qmlObject->property("categoryId" ).toString().isEmpty()); |
205 | |
206 | delete qmlObject; |
207 | } |
208 | |
209 | void tst_qmlinterface::testIcon() |
210 | { |
211 | QQmlEngine engine; |
212 | QQmlComponent component(&engine, SRCDIR "data/TestIcon.qml" ); |
213 | QVERIFY2(component.isReady(), qPrintable(component.errorString())); |
214 | QObject *qmlObject = component.create(); |
215 | |
216 | QPlaceIcon icon = qmlObject->property(name: "icon" ).value<QPlaceIcon>(); |
217 | |
218 | QCOMPARE(icon, m_icon); |
219 | |
220 | qmlObject->setProperty(name: "icon" , value: QVariant::fromValue(value: QPlaceIcon())); |
221 | |
222 | QVERIFY(!qmlObject->property("fullUrl" ).toUrl().isValid()); |
223 | |
224 | delete qmlObject; |
225 | } |
226 | |
227 | void tst_qmlinterface::testRatings() |
228 | { |
229 | QQmlEngine engine; |
230 | QQmlComponent component(&engine, SRCDIR "data/TestRatings.qml" ); |
231 | QVERIFY2(component.isReady(), qPrintable(component.errorString())); |
232 | QObject *qmlObject = component.create(); |
233 | |
234 | QPlaceRatings ratings = qmlObject->property(name: "ratings" ).value<QPlaceRatings>(); |
235 | |
236 | QCOMPARE(ratings, m_ratings); |
237 | |
238 | qmlObject->setProperty(name: "ratings" , value: QVariant::fromValue(value: QPlaceRatings())); |
239 | |
240 | QCOMPARE(qmlObject->property("average" ).value<qreal>(), 0.0); |
241 | QCOMPARE(qmlObject->property("maximum" ).value<qreal>(), 0.0); |
242 | QCOMPARE(qmlObject->property("average" ).toInt(), 0); |
243 | |
244 | delete qmlObject; |
245 | } |
246 | |
247 | void tst_qmlinterface::testSupplier() |
248 | { |
249 | QQmlEngine engine; |
250 | QQmlComponent component(&engine, SRCDIR "data/TestSupplier.qml" ); |
251 | QVERIFY2(component.isReady(), qPrintable(component.errorString())); |
252 | QObject *qmlObject = component.create(); |
253 | |
254 | QPlaceSupplier supplier = qmlObject->property(name: "supplier" ).value<QPlaceSupplier>(); |
255 | |
256 | QCOMPARE(supplier, m_supplier); |
257 | |
258 | qmlObject->setProperty(name: "supplier" , value: QVariant::fromValue(value: QPlaceSupplier())); |
259 | |
260 | QVERIFY(qmlObject->property("name" ).toString().isEmpty()); |
261 | QVERIFY(!qmlObject->property("url" ).toUrl().isValid()); |
262 | QVERIFY(qmlObject->property("supplierId" ).toString().isEmpty()); |
263 | QCOMPARE(qmlObject->property("icon" ).value<QPlaceIcon>(), QPlaceIcon()); |
264 | |
265 | delete qmlObject; |
266 | } |
267 | |
268 | void tst_qmlinterface::testUser() |
269 | { |
270 | QQmlEngine engine; |
271 | QQmlComponent component(&engine, SRCDIR "data/TestUser.qml" ); |
272 | QVERIFY2(component.isReady(), qPrintable(component.errorString())); |
273 | QObject *qmlObject = component.create(); |
274 | |
275 | QPlaceUser user = qmlObject->property(name: "user" ).value<QPlaceUser>(); |
276 | |
277 | QCOMPARE(user, m_user); |
278 | |
279 | qmlObject->setProperty(name: "user" , value: QVariant::fromValue(value: QPlaceUser())); |
280 | |
281 | QVERIFY(qmlObject->property("name" ).toString().isEmpty()); |
282 | QVERIFY(qmlObject->property("userId" ).toString().isEmpty()); |
283 | |
284 | delete qmlObject; |
285 | } |
286 | |
287 | void tst_qmlinterface::testPlaceAttribute() |
288 | { |
289 | QQmlEngine engine; |
290 | QQmlComponent component(&engine, SRCDIR "data/TestPlaceAttribute.qml" ); |
291 | QVERIFY2(component.isReady(), qPrintable(component.errorString())); |
292 | QObject *qmlObject = component.create(); |
293 | |
294 | QPlaceAttribute placeAttribute = qmlObject->property(name: "attribute" ).value<QPlaceAttribute>(); |
295 | |
296 | QCOMPARE(placeAttribute, m_placeAttribute); |
297 | |
298 | qmlObject->setProperty(name: "attribute" , value: QVariant::fromValue(value: QPlaceAttribute())); |
299 | |
300 | QVERIFY(qmlObject->property("label" ).toString().isEmpty()); |
301 | QVERIFY(qmlObject->property("text" ).toString().isEmpty()); |
302 | |
303 | delete qmlObject; |
304 | } |
305 | |
306 | void tst_qmlinterface::testContactDetail() |
307 | { |
308 | QQmlEngine engine; |
309 | QQmlComponent component(&engine, SRCDIR "data/TestContactDetail.qml" ); |
310 | QVERIFY2(component.isReady(), qPrintable(component.errorString())); |
311 | QObject *qmlObject = component.create(); |
312 | |
313 | QPlaceContactDetail contactDetail = qmlObject->property(name: "contactDetail" ).value<QPlaceContactDetail>(); |
314 | |
315 | QCOMPARE(contactDetail, m_contactDetail); |
316 | |
317 | qmlObject->setProperty(name: "contactDetail" , value: QVariant::fromValue(value: QPlaceContactDetail())); |
318 | |
319 | QVERIFY(qmlObject->property("label" ).toString().isEmpty()); |
320 | QVERIFY(qmlObject->property("value" ).toString().isEmpty()); |
321 | |
322 | delete qmlObject; |
323 | } |
324 | |
325 | void tst_qmlinterface::testPlace() |
326 | { |
327 | QQmlEngine engine; |
328 | QQmlComponent component(&engine, SRCDIR "data/TestPlace.qml" ); |
329 | QVERIFY2(component.isReady(), qPrintable(component.errorString())); |
330 | QObject *qmlObject = component.create(); |
331 | |
332 | QPlace place = qmlObject->property(name: "place" ).value<QPlace>(); |
333 | |
334 | QCOMPARE(place, m_place); |
335 | |
336 | qmlObject->setProperty(name: "place" , value: QVariant::fromValue(value: QPlace())); |
337 | |
338 | QVERIFY(qmlObject->property("name" ).toString().isEmpty()); |
339 | QVERIFY(qmlObject->property("placeId" ).toString().isEmpty()); |
340 | QVERIFY(qmlObject->property("attribution" ).toString().isEmpty()); |
341 | QQmlListReference categories(qmlObject, "categories" , &engine); |
342 | QCOMPARE(categories.count(), 0); |
343 | QCOMPARE(qmlObject->property("location" ).value<QGeoLocation>(), QGeoLocation()); |
344 | QCOMPARE(qmlObject->property("ratings" ).value<QPlaceRatings>(), QPlaceRatings()); |
345 | QCOMPARE(qmlObject->property("icon" ).value<QPlaceIcon>(), QPlaceIcon()); |
346 | QCOMPARE(qmlObject->property("supplier" ).value<QPlaceSupplier>(), QPlaceSupplier()); |
347 | |
348 | delete qmlObject; |
349 | } |
350 | |
351 | QTEST_MAIN(tst_qmlinterface) |
352 | |
353 | #include "tst_qmlinterface.moc" |
354 | |