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 <qplace.h>
33#include <qplaceimage.h>
34#include <qplaceattribute.h>
35#include <QtLocation/QPlaceEditorial>
36
37QT_USE_NAMESPACE
38
39class tst_Place : public QObject
40{
41 Q_OBJECT
42
43public:
44 tst_Place();
45
46private Q_SLOTS:
47 void constructorTest();
48 void categoriesTest();
49 void detailsFetchedTest();
50 void locationTest();
51 void ratingTest();
52 void supplierTest();
53 void imageContentTest();
54 void reviewContentTest();
55 void editorialContentTest();
56 void totalContentCountTest();
57 void totalContentCountTest_data();
58 void nameTest();
59 void placeIdTest();
60 void attributionTest();
61 void contactDetailsTest();
62 void primaryPhoneTest();
63 void primaryFaxTest();
64 void primaryEmailTest();
65 void primaryWebsiteTest();
66 void operatorsTest();
67 void extendedAttributeTest();
68 void visibilityTest();
69 void isEmptyTest();
70};
71
72tst_Place::tst_Place()
73{
74}
75
76void tst_Place::constructorTest()
77{
78 QPlace testObj;
79 testObj.setPlaceId("testId");
80 QPlaceAttribute paymentMethods;
81 paymentMethods.setLabel("Payment methods");
82 paymentMethods.setText("Visa");
83 testObj.setExtendedAttribute(QStringLiteral("paymentMethods"), attribute: paymentMethods);
84 QGeoLocation loc;
85 loc.setCoordinate(QGeoCoordinate(10,20));
86 testObj.setLocation(loc);
87 QPlace *testObjPtr = new QPlace(testObj);
88
89 QVERIFY2(testObjPtr != NULL, "Copy constructor - null");
90 QVERIFY2(*testObjPtr == testObj, "Copy constructor - compare");
91
92 delete testObjPtr;
93}
94
95void tst_Place::nameTest()
96{
97 QPlace testObj;
98 QVERIFY2(testObj.name() == QString(), "Wrong default value");
99 testObj.setName("testText");
100 QVERIFY2(testObj.name() == "testText", "Wrong value returned");
101}
102
103void tst_Place::placeIdTest()
104{
105 QPlace testObj;
106 QVERIFY2(testObj.placeId() == QString(), "Wrong default value");
107 testObj.setPlaceId("testText");
108 QVERIFY2(testObj.placeId() == "testText", "Wrong value returned");
109}
110
111void tst_Place::totalContentCountTest()
112{
113 QFETCH(QPlaceContent::Type, contentType);
114 QPlace testObj;
115 QVERIFY2(testObj.totalContentCount(contentType) == 0, "Wrong default value");
116 testObj.setTotalContentCount(type: contentType, total: 50);
117 QVERIFY2(testObj.totalContentCount(contentType) == 50, "Wrong value returned");
118
119 testObj.setTotalContentCount(type: contentType,total: 0);
120 QVERIFY2(testObj.totalContentCount(contentType) == 0, "Wrong value returned");
121}
122
123void tst_Place::totalContentCountTest_data()
124{
125 QTest::addColumn<QPlaceContent::Type>(name: "contentType");
126 QTest::newRow(dataTag: "Image content") << QPlaceContent::ImageType;
127 QTest::newRow(dataTag: "Editoral content") << QPlaceContent::EditorialType;
128 QTest::newRow(dataTag: "Review content") << QPlaceContent::ReviewType;
129}
130
131void tst_Place::ratingTest()
132{
133 QPlace testObj;
134 QVERIFY2(testObj.ratings() == QPlaceRatings(), "Wrong default value");
135 QPlaceRatings obj;
136 obj.setCount(10);
137 testObj.setRatings(obj);
138 QVERIFY2(testObj.ratings() == obj, "Wrong value returned");
139}
140
141void tst_Place::locationTest()
142{
143 QPlace testObj;
144 QVERIFY2(testObj.location() == QGeoLocation(), "Wrong default value");
145 QGeoLocation obj;
146 obj.setCoordinate(QGeoCoordinate(10,20));
147 testObj.setLocation(obj);
148 QVERIFY2(testObj.location() == obj, "Wrong value returned");
149}
150
151void tst_Place::detailsFetchedTest()
152{
153 QPlace testPlace;
154 QVERIFY2(testPlace.detailsFetched() == false, "Wrong default value");
155 testPlace.setDetailsFetched(true);
156 QVERIFY2(testPlace.detailsFetched() == true, "Wrong value returned");
157 testPlace.setDetailsFetched(false);
158 QVERIFY2(testPlace.detailsFetched() == false, "Wrong value returned");
159}
160
161void tst_Place::imageContentTest()
162{
163 QPlace place;
164 QVERIFY2(place.content(QPlaceContent::ImageType).count() ==0,"Wrong default value");
165
166 QPlaceImage dummyImage;
167 dummyImage.setUrl(QUrl("www.dummy.one"));
168
169 QPlaceImage dummyImage2;
170 dummyImage2.setUrl(QUrl("www.dummy.two"));
171
172 QPlaceImage dummyImage3;
173 dummyImage3.setUrl(QUrl("www.dummy.three"));
174
175 QPlaceContent::Collection imageCollection;
176 imageCollection.insert(akey: 0,avalue: dummyImage);
177 imageCollection.insert(akey: 1, avalue: dummyImage2);
178 imageCollection.insert(akey: 2, avalue: dummyImage3);
179
180 place.setContent(type: QPlaceContent::ImageType, content: imageCollection);
181 QPlaceContent::Collection retrievedCollection = place.content(type: QPlaceContent::ImageType);
182
183 QCOMPARE(retrievedCollection.count(), 3);
184 QCOMPARE(QPlaceImage(retrievedCollection.value(0)), dummyImage);
185 QCOMPARE(QPlaceImage(retrievedCollection.value(1)), dummyImage2);
186 QCOMPARE(QPlaceImage(retrievedCollection.value(2)), dummyImage3);
187
188 //replace the second and insert a sixth image
189 //indexes 4 and 5 are "missing"
190 QPlaceImage dummyImage2New;
191 dummyImage2.setUrl(QUrl("www.dummy.two.new"));
192
193 QPlaceImage dummyImage6;
194 dummyImage6.setUrl(QUrl("www.dummy.six"));
195
196 imageCollection.clear();
197 imageCollection.insert(akey: 1, avalue: dummyImage2New);
198 imageCollection.insert(akey: 5, avalue: dummyImage6);
199 place.insertContent(type: QPlaceContent::ImageType, content: imageCollection);
200
201 retrievedCollection = place.content(type: QPlaceContent::ImageType);
202 QCOMPARE(retrievedCollection.count(), 4);
203 QCOMPARE(QPlaceImage(retrievedCollection.value(0)), dummyImage);
204 QCOMPARE(QPlaceImage(retrievedCollection.value(1)), dummyImage2New);
205 QCOMPARE(QPlaceImage(retrievedCollection.value(2)), dummyImage3);
206 QCOMPARE(QPlaceImage(retrievedCollection.value(3)), QPlaceImage());
207 QCOMPARE(QPlaceImage(retrievedCollection.value(4)), QPlaceImage());
208 QCOMPARE(QPlaceImage(retrievedCollection.value(5)), dummyImage6);
209}
210
211void tst_Place::reviewContentTest()
212{
213 QPlace place;
214 QVERIFY2(place.content(QPlaceContent::ReviewType).count() ==0,"Wrong default value");
215
216 QPlaceReview dummyReview;
217 dummyReview.setTitle(QStringLiteral("Review 1"));
218
219 QPlaceReview dummyReview2;
220 dummyReview2.setTitle(QStringLiteral("Review 2"));
221
222 QPlaceReview dummyReview3;
223 dummyReview3.setTitle(QStringLiteral("Review 3"));
224
225 QPlaceContent::Collection reviewCollection;
226 reviewCollection.insert(akey: 0,avalue: dummyReview);
227 reviewCollection.insert(akey: 1, avalue: dummyReview2);
228 reviewCollection.insert(akey: 2, avalue: dummyReview3);
229
230 place.setContent(type: QPlaceContent::ReviewType, content: reviewCollection);
231 QPlaceContent::Collection retrievedCollection = place.content(type: QPlaceContent::ReviewType);
232
233 QCOMPARE(retrievedCollection.count(), 3);
234 QCOMPARE(QPlaceReview(retrievedCollection.value(0)), dummyReview);
235 QCOMPARE(QPlaceReview(retrievedCollection.value(1)), dummyReview2);
236 QCOMPARE(QPlaceReview(retrievedCollection.value(2)), dummyReview3);
237
238 //replace the second and insert a sixth review
239 //indexes 4 and 5 are "missing"
240 QPlaceReview dummyReview2New;
241 dummyReview2.setTitle(QStringLiteral("Review 2 new"));
242
243 QPlaceReview dummyReview6;
244 dummyReview6.setTitle(QStringLiteral("Review 6"));
245
246 reviewCollection.clear();
247 reviewCollection.insert(akey: 1, avalue: dummyReview2New);
248 reviewCollection.insert(akey: 5, avalue: dummyReview6);
249 place.insertContent(type: QPlaceContent::ReviewType, content: reviewCollection);
250
251 retrievedCollection = place.content(type: QPlaceContent::ReviewType);
252 QCOMPARE(retrievedCollection.count(), 4);
253 QCOMPARE(QPlaceReview(retrievedCollection.value(0)), dummyReview);
254 QCOMPARE(QPlaceReview(retrievedCollection.value(1)), dummyReview2New);
255 QCOMPARE(QPlaceReview(retrievedCollection.value(2)), dummyReview3);
256 QCOMPARE(QPlaceReview(retrievedCollection.value(3)), QPlaceReview());
257 QCOMPARE(QPlaceReview(retrievedCollection.value(4)), QPlaceReview());
258 QCOMPARE(QPlaceReview(retrievedCollection.value(5)), dummyReview6);
259}
260
261void tst_Place::editorialContentTest()
262{
263 QPlace place;
264 QVERIFY2(place.content(QPlaceContent::EditorialType).count() == 0, "Wrong default value");
265
266 QPlaceEditorial dummyEditorial;
267 dummyEditorial.setTitle(QStringLiteral("Editorial 1"));
268
269 QPlaceEditorial dummyEditorial2;
270 dummyEditorial2.setTitle(QStringLiteral("Editorial 2"));
271
272 QPlaceEditorial dummyEditorial3;
273 dummyEditorial3.setTitle(QStringLiteral("Editorial 3"));
274
275 QPlaceContent::Collection editorialCollection;
276 editorialCollection.insert(akey: 0,avalue: dummyEditorial);
277 editorialCollection.insert(akey: 1, avalue: dummyEditorial2);
278 editorialCollection.insert(akey: 2, avalue: dummyEditorial3);
279
280 place.setContent(type: QPlaceContent::EditorialType, content: editorialCollection);
281 QPlaceContent::Collection retrievedCollection = place.content(type: QPlaceContent::EditorialType);
282
283 QCOMPARE(retrievedCollection.count(), 3);
284 QCOMPARE(QPlaceEditorial(retrievedCollection.value(0)), dummyEditorial);
285 QCOMPARE(QPlaceEditorial(retrievedCollection.value(1)), dummyEditorial2);
286 QCOMPARE(QPlaceEditorial(retrievedCollection.value(2)), dummyEditorial3);
287
288 //replace the second and insert a sixth editorial
289 //indexes 4 and 5 are "missing"
290 QPlaceEditorial dummyEditorial2New;
291 dummyEditorial2.setTitle(QStringLiteral("Editorial 2 new"));
292
293 QPlaceEditorial dummyEditorial6;
294 dummyEditorial6.setTitle(QStringLiteral("Editorial 6"));
295
296 editorialCollection.clear();
297 editorialCollection.insert(akey: 1, avalue: dummyEditorial2New);
298 editorialCollection.insert(akey: 5, avalue: dummyEditorial6);
299 place.insertContent(type: QPlaceContent::EditorialType, content: editorialCollection);
300
301 retrievedCollection = place.content(type: QPlaceContent::EditorialType);
302 QCOMPARE(retrievedCollection.count(), 4);
303 QCOMPARE(QPlaceEditorial(retrievedCollection.value(0)), dummyEditorial);
304 QCOMPARE(QPlaceEditorial(retrievedCollection.value(1)), dummyEditorial2New);
305 QCOMPARE(QPlaceEditorial(retrievedCollection.value(2)), dummyEditorial3);
306 QCOMPARE(QPlaceEditorial(retrievedCollection.value(3)), QPlaceEditorial());
307 QCOMPARE(QPlaceEditorial(retrievedCollection.value(4)), QPlaceEditorial());
308 QCOMPARE(QPlaceEditorial(retrievedCollection.value(5)), dummyEditorial6);
309}
310
311void tst_Place::categoriesTest()
312{
313 QPlace place;
314 QVERIFY(place.categories().isEmpty());
315
316 //set a single category
317 QPlaceCategory cat1;
318 cat1.setName("cat1");
319
320 place.setCategory(cat1);
321 QCOMPARE(place.categories().count(), 1);
322 QCOMPARE(place.categories().at(0), cat1);
323
324 //set multiple categories
325 QPlaceCategory cat2;
326 cat2.setName("cat2");
327
328 QPlaceCategory cat3;
329 cat3.setName("cat3");
330
331 QList<QPlaceCategory> categories;
332 categories << cat2 << cat3;
333
334 place.setCategories(categories);
335 QCOMPARE(place.categories().count(), 2);
336 QVERIFY(place.categories().contains(cat2));
337 QVERIFY(place.categories().contains(cat3));
338
339 //set a single category again while there are multiple categories already assigned.
340 place.setCategory(cat1);
341 QCOMPARE(place.categories().count(), 1);
342 QCOMPARE(place.categories().at(0), cat1);
343
344 //set an empty list of categories
345 place.setCategories(QList<QPlaceCategory>());
346 QVERIFY(place.categories().isEmpty());
347}
348
349void tst_Place::supplierTest()
350{
351 QPlace testObj;
352 QCOMPARE(testObj.supplier(), QPlaceSupplier());
353
354 QPlaceSupplier sup;
355 sup.setName("testName1");
356 sup.setSupplierId("testId");
357
358 testObj.setSupplier(sup);
359
360 QCOMPARE(testObj.supplier(), sup);
361}
362
363void tst_Place::attributionTest()
364{
365 QPlace testPlace;
366 QVERIFY(testPlace.attribution().isEmpty());
367 testPlace.setAttribution(QStringLiteral("attribution"));
368 QCOMPARE(testPlace.attribution(), QStringLiteral("attribution"));
369 testPlace.setAttribution(QString());
370 QVERIFY(testPlace.attribution().isEmpty());
371}
372
373void tst_Place::contactDetailsTest()
374{
375 QPlaceContactDetail phone1;
376 phone1.setLabel("Phone1");
377 phone1.setValue("555-5555");
378
379 QPlaceContactDetail phone2;
380 phone2.setLabel("Phone2");
381 phone2.setValue("555-5556");
382
383 QList<QPlaceContactDetail> phones;
384 phones << phone1 << phone2;
385
386
387 QPlaceContactDetail email;
388 email.setLabel("Email");
389 email.setValue("email@email.com");
390
391 QPlace place;
392 place.setContactDetails(contactType: QPlaceContactDetail::Phone,details: phones);
393 QCOMPARE(place.contactTypes().count(), 1);
394 QVERIFY(place.contactTypes().contains(QPlaceContactDetail::Phone));
395 QCOMPARE(place.contactDetails(QPlaceContactDetail::Phone), phones);
396
397 place.appendContactDetail(contactType: QPlaceContactDetail::Email, detail: email);
398 QCOMPARE(place.contactTypes().count(), 2);
399 QVERIFY(place.contactTypes().contains(QPlaceContactDetail::Phone));
400 QVERIFY(place.contactTypes().contains(QPlaceContactDetail::Email));
401 QCOMPARE(place.contactDetails(QPlaceContactDetail::Phone), phones);
402 QCOMPARE(place.contactDetails(QPlaceContactDetail::Email).count(), 1);
403 QCOMPARE(place.contactDetails(QPlaceContactDetail::Email).at(0), email);
404
405 place.removeContactDetails(contactType: QPlaceContactDetail::Phone);
406 QCOMPARE(place.contactTypes().count(), 1);
407 QVERIFY(!place.contactTypes().contains(QPlaceContactDetail::Phone));
408 QVERIFY(place.contactDetails(QPlaceContactDetail::Phone).isEmpty());
409 QVERIFY(place.contactTypes().contains(QPlaceContactDetail::Email));
410 QCOMPARE(place.contactDetails(QPlaceContactDetail::Email).count(), 1);
411 QCOMPARE(place.contactDetails(QPlaceContactDetail::Email).at(0), email);
412
413 place.removeContactDetails(contactType: QPlaceContactDetail::Email);
414 QVERIFY(place.contactTypes().isEmpty());
415 QVERIFY(place.contactDetails(QPlaceContactDetail::Email).isEmpty());
416}
417
418void tst_Place::primaryPhoneTest()
419{
420 QPlace place;
421 QVERIFY2(place.primaryPhone().isEmpty(), "Wrong default value");
422
423 QPlaceContactDetail contactDetail;
424 contactDetail.setLabel(QStringLiteral("Phone"));
425 contactDetail.setValue(QStringLiteral("555-5555"));
426 place.appendContactDetail(contactType: QPlaceContactDetail::Phone, detail: contactDetail);
427
428 QCOMPARE(place.primaryPhone(), QString("555-5555"));
429
430 //try clearing the primary phone number
431 place.setContactDetails(contactType: QPlaceContactDetail::Phone, details: QList<QPlaceContactDetail>());
432 QCOMPARE(place.primaryPhone(), QString());
433}
434
435void tst_Place::primaryEmailTest()
436{
437 QPlace place;
438 QVERIFY2(place.primaryEmail().isEmpty(), "Wrong default value");
439
440 QPlaceContactDetail contactDetail;
441 contactDetail.setLabel(QStringLiteral("Email"));
442 contactDetail.setValue(QStringLiteral("test@test.com"));
443 place.appendContactDetail(contactType: QPlaceContactDetail::Email, detail: contactDetail);
444
445 QCOMPARE(place.primaryEmail(), QStringLiteral("test@test.com"));
446
447 //try clearing the primary email address
448 place.setContactDetails(contactType: QPlaceContactDetail::Email, details: QList<QPlaceContactDetail>());
449 QCOMPARE(place.primaryEmail(), QString());
450}
451
452void tst_Place::primaryFaxTest()
453{
454 QPlace place;
455 QVERIFY2(place.primaryFax().isEmpty(), "Wrong default value");
456
457 QPlaceContactDetail contactDetail;
458 contactDetail.setLabel(QStringLiteral("Fax"));
459 contactDetail.setValue(QStringLiteral("555-5555"));
460 place.appendContactDetail(contactType: QPlaceContactDetail::Fax, detail: contactDetail);
461
462 QCOMPARE(place.primaryFax(), QStringLiteral("555-5555"));
463
464 //try clearing the primary fax number
465 place.setContactDetails(contactType: QPlaceContactDetail::Fax, details: QList<QPlaceContactDetail>());
466 QCOMPARE(place.primaryFax(), QString());
467}
468
469void tst_Place::primaryWebsiteTest()
470{
471 QPlace place;
472 QVERIFY2(place.primaryWebsite().isEmpty(), "Wrong default value");
473
474 QPlaceContactDetail contactDetail;
475 contactDetail.setLabel(QStringLiteral("Website"));
476 contactDetail.setValue(QStringLiteral("www.example.com"));
477 place.appendContactDetail(contactType: QPlaceContactDetail::Website, detail: contactDetail);
478
479 QCOMPARE(place.primaryWebsite(), QUrl("www.example.com"));
480
481 //try clearing the primary website number
482 place.setContactDetails(contactType: QPlaceContactDetail::Website, details: QList<QPlaceContactDetail>());
483 QCOMPARE(place.primaryWebsite(), QUrl());
484}
485
486void tst_Place::operatorsTest()
487{
488 QPlace testObj;
489 testObj.setPlaceId("testId");
490 QPlaceAttribute paymentMethods;
491 paymentMethods.setLabel("Payment methods");
492 paymentMethods.setText("Visa");
493 testObj.setExtendedAttribute(QStringLiteral("paymentMethods"), attribute: paymentMethods);
494 QGeoLocation loc;
495 loc.setCoordinate(QGeoCoordinate(10,20));
496 testObj.setLocation(loc);
497
498 QPlace testObj2;
499 testObj2 = testObj;
500 QVERIFY2(testObj == testObj2, "Not copied correctly");
501 testObj2.setPlaceId("342-456");
502 QVERIFY2(testObj != testObj2, "Object should be different");
503}
504
505void tst_Place::extendedAttributeTest()
506{
507 QPlace place;
508 QVERIFY(place.extendedAttributeTypes().isEmpty());
509 QPlaceAttribute smoking;
510 smoking.setLabel(QStringLiteral("Public Smoking"));
511 smoking.setText(QStringLiteral("No"));
512
513 //test setting of an attribue
514 place.setExtendedAttribute(QStringLiteral("smoking"), attribute: smoking);
515
516 QVERIFY(place.extendedAttributeTypes().contains(QStringLiteral("smoking")));
517 QCOMPARE(place.extendedAttributeTypes().count(), 1);
518
519 QCOMPARE(place.extendedAttribute(QStringLiteral("smoking")).label(), QStringLiteral("Public Smoking"));
520 QCOMPARE(place.extendedAttribute(QStringLiteral("smoking")).text(), QStringLiteral("No"));
521
522 QPlaceAttribute shelter;
523 shelter.setLabel(QStringLiteral("Outdoor shelter"));
524 shelter.setText(QStringLiteral("Yes"));
525
526 //test setting another new attribute
527 place.setExtendedAttribute(attributeType: "shelter", attribute: shelter);
528 QVERIFY(place.extendedAttributeTypes().contains(QStringLiteral("shelter")));
529 QVERIFY(place.extendedAttributeTypes().contains(QStringLiteral("smoking")));
530 QCOMPARE(place.extendedAttributeTypes().count(), 2);
531 QCOMPARE(place.extendedAttribute(QStringLiteral("shelter")).label(), QStringLiteral("Outdoor shelter"));
532 QCOMPARE(place.extendedAttribute(QStringLiteral("shelter")).text(), QStringLiteral("Yes"));
533
534 //test overwriting an attribute
535 shelter.setText(QStringLiteral("No"));
536 place.setExtendedAttribute(QStringLiteral("shelter"), attribute: shelter);
537
538 QVERIFY(place.extendedAttributeTypes().contains(QStringLiteral("shelter")));
539 QVERIFY(place.extendedAttributeTypes().contains(QStringLiteral("smoking")));
540 QCOMPARE(place.extendedAttributeTypes().count(), 2);
541 QCOMPARE(place.extendedAttribute(QStringLiteral("shelter")).text(), QStringLiteral("No"));
542
543 //test clearing of attributes by setting them to the default attribute
544 foreach (const QString &attributeType, place.extendedAttributeTypes())
545 place.setExtendedAttribute(attributeType, attribute: QPlaceAttribute());
546
547 QCOMPARE(place.extendedAttributeTypes().count(), 0);
548
549 //test removing of attributes
550 place.setExtendedAttribute(QStringLiteral("smoking"), attribute: smoking);
551 QVERIFY(!place.extendedAttributeTypes().isEmpty());
552 place.removeExtendedAttribute(QStringLiteral("smoking"));
553 QVERIFY(place.extendedAttributeTypes().isEmpty());
554}
555void tst_Place::visibilityTest()
556{
557 QPlace place;
558
559 QCOMPARE(place.visibility(), QLocation::UnspecifiedVisibility);
560
561 place.setVisibility(QLocation::DeviceVisibility);
562
563 QCOMPARE(place.visibility(), QLocation::DeviceVisibility);
564}
565
566void tst_Place::isEmptyTest()
567{
568 QGeoLocation location;
569 location.setCoordinate(QGeoCoordinate(6.788697, 51.224679));
570 QVERIFY(!location.isEmpty());
571
572 QPlaceCategory category;
573
574 QPlaceRatings ratings;
575 ratings.setCount(1);
576 QVERIFY(!ratings.isEmpty());
577
578 QPlaceSupplier supplier;
579 supplier.setName(QStringLiteral("Foo & Bar Imports"));
580 QVERIFY(!supplier.isEmpty());
581
582 QPlaceIcon icon;
583 QVariantMap iconParametersMap;
584 iconParametersMap.insert(QStringLiteral("Para"), QStringLiteral("meter"));
585 icon.setParameters(iconParametersMap);
586 QVERIFY(!icon.isEmpty());
587
588 QPlaceContent content;
589 QPlaceContent::Collection contentCollection;
590 contentCollection.insert(akey: 42, avalue: content);
591
592 QPlaceAttribute attribute;
593 attribute.setLabel(QStringLiteral("noodle"));
594
595 QPlaceContactDetail contactDetail;
596
597
598 QPlace place;
599
600 // default constructed
601 QVERIFY(place.isEmpty());
602
603 // categories
604 place.setCategory(category);
605 QVERIFY(!place.isEmpty());
606 place.categories().clear();
607 place = QPlace();
608
609 // location
610 place.setLocation(location);
611 QVERIFY(!place.isEmpty());
612 place.setLocation(QGeoLocation());
613 QVERIFY(place.isEmpty());
614
615 // ratings
616 place.setRatings(ratings);
617 QVERIFY(!place.isEmpty());
618 place.setRatings(QPlaceRatings());
619 QVERIFY(place.isEmpty());
620
621 // supplier
622 place.setSupplier(supplier);
623 QVERIFY(!place.isEmpty());
624 place.setSupplier(QPlaceSupplier());
625 QVERIFY(place.isEmpty());
626
627 // attribution
628 place.setAttribution(QStringLiteral("attr"));
629 QVERIFY(!place.isEmpty());
630 place.setAttribution(QString());
631 QVERIFY(place.isEmpty());
632
633 // icon
634 place.setIcon(icon);
635 QVERIFY(!place.isEmpty());
636 place.setIcon(QPlaceIcon());
637 QVERIFY(place.isEmpty());
638
639 // content
640 place.insertContent(type: QPlaceContent::EditorialType, content: contentCollection);
641 QVERIFY(!place.isEmpty());
642 place = QPlace();
643
644 // name
645 place.setName(QStringLiteral("Naniwa"));
646 QVERIFY(!place.isEmpty());
647 place.setName(QString());
648 QVERIFY(place.isEmpty());
649
650 // placeId
651 place.setPlaceId(QStringLiteral("naniwa"));
652 QVERIFY(!place.isEmpty());
653 place.setPlaceId(QString());
654 QVERIFY(place.isEmpty());
655
656 // extendedAttributes
657 place.setExtendedAttribute(QStringLiteral("part"), attribute);
658 QVERIFY(!place.isEmpty());
659 place.removeExtendedAttribute(QStringLiteral("part"));
660 QVERIFY(place.isEmpty());
661
662 // extendedAttributes
663 place.setDetailsFetched(true);
664 QVERIFY(place.isEmpty());
665
666 // contact detail
667 place.appendContactDetail(QStringLiteral("phone"), detail: contactDetail);
668 QVERIFY(!place.isEmpty());
669 place.removeContactDetails(QStringLiteral("phone"));
670 QVERIFY(place.isEmpty());
671
672 // visibility
673 place.setVisibility(QLocation::DeviceVisibility);
674 QVERIFY(!place.isEmpty());
675 place.setVisibility(QLocation::UnspecifiedVisibility);
676 QVERIFY(place.isEmpty());
677}
678
679QTEST_APPLESS_MAIN(tst_Place)
680
681#include "tst_qplace.moc"
682

source code of qtlocation/tests/auto/qplace/tst_qplace.cpp