diff options
-rw-r--r-- | src/location/places/qplace.cpp | 28 | ||||
-rw-r--r-- | src/location/places/qplace.h | 2 | ||||
-rw-r--r-- | src/location/places/qplace_p.h | 2 | ||||
-rw-r--r-- | src/location/places/qplaceratings.cpp | 13 | ||||
-rw-r--r-- | src/location/places/qplaceratings.h | 2 | ||||
-rw-r--r-- | src/location/places/qplaceratings_p.h | 2 | ||||
-rw-r--r-- | src/location/places/qplacesupplier.cpp | 17 | ||||
-rw-r--r-- | src/location/places/qplacesupplier.h | 2 | ||||
-rw-r--r-- | src/location/places/qplacesupplier_p.h | 2 | ||||
-rw-r--r-- | src/location/qgeolocation.cpp | 16 | ||||
-rw-r--r-- | src/location/qgeolocation.h | 2 | ||||
-rw-r--r-- | src/location/qgeolocation_p.h | 2 | ||||
-rw-r--r-- | tests/auto/qgeolocation/tst_qgeolocation.cpp | 34 | ||||
-rw-r--r-- | tests/auto/qgeolocation/tst_qgeolocation.h | 1 | ||||
-rw-r--r-- | tests/auto/qplace/tst_qplace.cpp | 114 | ||||
-rw-r--r-- | tests/auto/qplaceratings/tst_qplaceratings.cpp | 23 | ||||
-rw-r--r-- | tests/auto/qplacesupplier/tst_qplacesupplier.cpp | 38 |
17 files changed, 300 insertions, 0 deletions
diff --git a/src/location/places/qplace.cpp b/src/location/places/qplace.cpp index b82eb685..27fa1781 100644 --- a/src/location/places/qplace.cpp +++ b/src/location/places/qplace.cpp @@ -603,6 +603,15 @@ QtLocation::Visibility QPlace::visibility() const return d->visibility; } +/*! + Returns a boolean indicating whether the all the fields of the place are empty or not. +*/ +bool QPlace::isEmpty() const +{ + Q_D(const QPlace); + return d->isEmpty(); +} + /******************************************************************************* *******************************************************************************/ @@ -686,4 +695,23 @@ bool QPlacePrivate::operator== (const QPlacePrivate &other) const ); } + +bool QPlacePrivate::isEmpty() const +{ + return (categories.isEmpty() + && location.isEmpty() + && ratings.isEmpty() + && supplier.isEmpty() + && contentCollections.isEmpty() + && contentCounts.isEmpty() + && name.isEmpty() + && placeId.isEmpty() + && attribution.isEmpty() + && contacts.isEmpty() + && extendedAttributes.isEmpty() + && QtLocation::UnspecifiedVisibility == visibility + && icon.isEmpty() + ); +} + QT_END_NAMESPACE diff --git a/src/location/places/qplace.h b/src/location/places/qplace.h index 041ed38c..2de45693 100644 --- a/src/location/places/qplace.h +++ b/src/location/places/qplace.h @@ -128,6 +128,8 @@ public: QtLocation::Visibility visibility() const; void setVisibility(QtLocation::Visibility visibility); + bool isEmpty() const; + private: QSharedDataPointer<QPlacePrivate> d_ptr; diff --git a/src/location/places/qplace_p.h b/src/location/places/qplace_p.h index 0d60dd95..4e50552a 100644 --- a/src/location/places/qplace_p.h +++ b/src/location/places/qplace_p.h @@ -76,6 +76,8 @@ public: bool operator==(const QPlacePrivate &other) const; + bool isEmpty() const; + QList<QPlaceCategory> categories; QGeoLocation location; QPlaceRatings ratings; diff --git a/src/location/places/qplaceratings.cpp b/src/location/places/qplaceratings.cpp index 30311370..9fc791ac 100644 --- a/src/location/places/qplaceratings.cpp +++ b/src/location/places/qplaceratings.cpp @@ -63,6 +63,11 @@ bool QPlaceRatingsPrivate::operator==(const QPlaceRatingsPrivate &other) const return average == other.average && maximum == other.maximum && count == other.count; } +bool QPlaceRatingsPrivate::isEmpty() const +{ + return count == 0 && average == 0 && maximum == 0; +} + /*! \class QPlaceRatings \inmodule QtLocation @@ -176,3 +181,11 @@ void QPlaceRatings::setCount(int count) { d->count = count; } + +/*! + Returns true if all fields of the place ratings are 0; otherwise returns false. +*/ +bool QPlaceRatings::isEmpty() const +{ + return d->isEmpty(); +} diff --git a/src/location/places/qplaceratings.h b/src/location/places/qplaceratings.h index 6aa5ce2c..0c94a615 100644 --- a/src/location/places/qplaceratings.h +++ b/src/location/places/qplaceratings.h @@ -76,6 +76,8 @@ public: qreal maximum() const; void setMaximum(qreal max); + bool isEmpty() const; + private: QSharedDataPointer<QPlaceRatingsPrivate> d; }; diff --git a/src/location/places/qplaceratings_p.h b/src/location/places/qplaceratings_p.h index 49a7edb2..ea469902 100644 --- a/src/location/places/qplaceratings_p.h +++ b/src/location/places/qplaceratings_p.h @@ -56,6 +56,8 @@ public: bool operator==(const QPlaceRatingsPrivate &other) const; + bool isEmpty() const; + qreal average; qreal maximum; int count; diff --git a/src/location/places/qplacesupplier.cpp b/src/location/places/qplacesupplier.cpp index f4867322..cc56d830 100644 --- a/src/location/places/qplacesupplier.cpp +++ b/src/location/places/qplacesupplier.cpp @@ -71,6 +71,15 @@ bool QPlaceSupplierPrivate::operator==(const QPlaceSupplierPrivate &other) const ); } +bool QPlaceSupplierPrivate::isEmpty() const +{ + return (name.isEmpty() + && supplierId.isEmpty() + && url.isEmpty() + && icon.isEmpty() + ); +} + /*! \class QPlaceSupplier \inmodule QtLocation @@ -199,3 +208,11 @@ void QPlaceSupplier::setIcon(const QPlaceIcon &icon) { d->icon = icon; } + +/*! + Returns true if all fields of the place supplier are 0; otherwise returns false. +*/ +bool QPlaceSupplier::isEmpty() const +{ + return d->isEmpty(); +} diff --git a/src/location/places/qplacesupplier.h b/src/location/places/qplacesupplier.h index b7f15ed6..bffed1b0 100644 --- a/src/location/places/qplacesupplier.h +++ b/src/location/places/qplacesupplier.h @@ -79,6 +79,8 @@ public: QPlaceIcon icon() const; void setIcon(const QPlaceIcon &icon); + bool isEmpty() const; + private: QSharedDataPointer<QPlaceSupplierPrivate> d; }; diff --git a/src/location/places/qplacesupplier_p.h b/src/location/places/qplacesupplier_p.h index 1cadfdfe..bc3b2962 100644 --- a/src/location/places/qplacesupplier_p.h +++ b/src/location/places/qplacesupplier_p.h @@ -60,6 +60,8 @@ public: bool operator==(const QPlaceSupplierPrivate &other) const; + bool isEmpty() const; + QString name; QString supplierId; QUrl url; diff --git a/src/location/qgeolocation.cpp b/src/location/qgeolocation.cpp index f430f8ed..d0689c71 100644 --- a/src/location/qgeolocation.cpp +++ b/src/location/qgeolocation.cpp @@ -69,6 +69,14 @@ bool QGeoLocationPrivate::operator==(const QGeoLocationPrivate &other) const } +bool QGeoLocationPrivate::isEmpty() const +{ + return (address.isEmpty() + && !coordinate.isValid() + && viewport.isEmpty() + ); +} + /*! \class QGeoLocation \inmodule QtLocation @@ -177,3 +185,11 @@ void QGeoLocation::setBoundingBox(const QGeoBoundingBox &boundingBox) { d->viewport = boundingBox; } + +/*! + Returns true if all fields of the location are 0; otherwise returns false. +*/ +bool QGeoLocation::isEmpty() const +{ + return d->isEmpty(); +} diff --git a/src/location/qgeolocation.h b/src/location/qgeolocation.h index e8945f97..78224b5f 100644 --- a/src/location/qgeolocation.h +++ b/src/location/qgeolocation.h @@ -80,6 +80,8 @@ public: QGeoBoundingBox boundingBox() const; void setBoundingBox(const QGeoBoundingBox &box); + bool isEmpty() const; + private: QSharedDataPointer<QGeoLocationPrivate> d; }; diff --git a/src/location/qgeolocation_p.h b/src/location/qgeolocation_p.h index f32906a9..7a2a002d 100644 --- a/src/location/qgeolocation_p.h +++ b/src/location/qgeolocation_p.h @@ -56,6 +56,8 @@ public: bool operator==(const QGeoLocationPrivate &other) const; + bool isEmpty() const; + QGeoAddress address; QGeoCoordinate coordinate; QGeoBoundingBox viewport; diff --git a/tests/auto/qgeolocation/tst_qgeolocation.cpp b/tests/auto/qgeolocation/tst_qgeolocation.cpp index 28a15196..0936412e 100644 --- a/tests/auto/qgeolocation/tst_qgeolocation.cpp +++ b/tests/auto/qgeolocation/tst_qgeolocation.cpp @@ -224,5 +224,39 @@ void tst_QGeoLocation::comparison_data() QTest::newRow("coordinate") << "coordinate"; } +void tst_QGeoLocation::isEmpty() +{ + QGeoAddress address; + address.setCity(QLatin1String("Braunschweig")); + QVERIFY(!address.isEmpty()); + + QGeoBoundingBox boundingBox; + boundingBox.setTopLeft(QGeoCoordinate(1, -1)); + boundingBox.setBottomRight(QGeoCoordinate(-1, 1)); + QVERIFY(!boundingBox.isEmpty()); + + QGeoLocation location; + + QVERIFY(location.isEmpty()); + + // address + location.setAddress(address); + QVERIFY(!location.isEmpty()); + location.setAddress(QGeoAddress()); + QVERIFY(location.isEmpty()); + + // coordinate + location.setCoordinate(QGeoCoordinate(1, 2)); + QVERIFY(!location.isEmpty()); + location.setCoordinate(QGeoCoordinate()); + QVERIFY(location.isEmpty()); + + // bounding box + location.setBoundingBox(boundingBox); + QVERIFY(!location.isEmpty()); + location.setBoundingBox(QGeoBoundingBox()); + QVERIFY(location.isEmpty()); +} + QTEST_APPLESS_MAIN(tst_QGeoLocation); diff --git a/tests/auto/qgeolocation/tst_qgeolocation.h b/tests/auto/qgeolocation/tst_qgeolocation.h index 05072f85..49bde170 100644 --- a/tests/auto/qgeolocation/tst_qgeolocation.h +++ b/tests/auto/qgeolocation/tst_qgeolocation.h @@ -78,6 +78,7 @@ private Q_SLOTS: void operators(); void comparison(); void comparison_data(); + void isEmpty(); //End Unit Tests for qgeolocation.h private: diff --git a/tests/auto/qplace/tst_qplace.cpp b/tests/auto/qplace/tst_qplace.cpp index ec9979f3..c4df5462 100644 --- a/tests/auto/qplace/tst_qplace.cpp +++ b/tests/auto/qplace/tst_qplace.cpp @@ -78,6 +78,7 @@ private Q_SLOTS: void operatorsTest(); void extendedAttributeTest(); void visibilityTest(); + void isEmptyTest(); }; tst_Place::tst_Place() @@ -565,6 +566,119 @@ void tst_Place::visibilityTest() QCOMPARE(place.visibility(), QtLocation::DeviceVisibility); } +void tst_Place::isEmptyTest() +{ + QGeoLocation location; + location.setCoordinate(QGeoCoordinate(6.788697, 51.224679)); + QVERIFY(!location.isEmpty()); + + QPlaceCategory category; + + QPlaceRatings ratings; + ratings.setCount(1); + QVERIFY(!ratings.isEmpty()); + + QPlaceSupplier supplier; + supplier.setName(QLatin1String("Foo & Bar Imports")); + QVERIFY(!supplier.isEmpty()); + + QPlaceIcon icon; + QVariantMap iconParametersMap; + iconParametersMap.insert(QLatin1String("Para"), QLatin1String("meter")); + icon.setParameters(iconParametersMap); + QVERIFY(!icon.isEmpty()); + + QPlaceContent content; + QPlaceContent::Collection contentCollection; + contentCollection.insert(42, content); + + QPlaceAttribute attribute; + attribute.setLabel(QLatin1String("noodle")); + + QPlaceContactDetail contactDetail; + + + QPlace place; + + // default constructed + QVERIFY(place.isEmpty()); + + // categories + place.setCategory(category); + QVERIFY(!place.isEmpty()); + place.categories().clear(); + place = QPlace(); + + // location + place.setLocation(location); + QVERIFY(!place.isEmpty()); + place.setLocation(QGeoLocation()); + QVERIFY(place.isEmpty()); + + // ratings + place.setRatings(ratings); + QVERIFY(!place.isEmpty()); + place.setRatings(QPlaceRatings()); + QVERIFY(place.isEmpty()); + + // supplier + place.setSupplier(supplier); + QVERIFY(!place.isEmpty()); + place.setSupplier(QPlaceSupplier()); + QVERIFY(place.isEmpty()); + + // attribution + place.setAttribution(QLatin1String("attr")); + QVERIFY(!place.isEmpty()); + place.setAttribution(QString()); + QVERIFY(place.isEmpty()); + + // icon + place.setIcon(icon); + QVERIFY(!place.isEmpty()); + place.setIcon(QPlaceIcon()); + QVERIFY(place.isEmpty()); + + // content + place.insertContent(QPlaceContent::EditorialType, contentCollection); + QVERIFY(!place.isEmpty()); + place = QPlace(); + + // name + place.setName(QLatin1String("Naniwa")); + QVERIFY(!place.isEmpty()); + place.setName(QString()); + QVERIFY(place.isEmpty()); + + // placeId + place.setPlaceId(QLatin1String("naniwa")); + QVERIFY(!place.isEmpty()); + place.setPlaceId(QString()); + QVERIFY(place.isEmpty()); + + // extendedAttributes + place.setExtendedAttribute(QLatin1String("part"), attribute); + QVERIFY(!place.isEmpty()); + place.removeExtendedAttribute(QLatin1String("part")); + QVERIFY(place.isEmpty()); + + // extendedAttributes + place.setDetailsFetched(true); + QVERIFY(place.isEmpty()); + + // contact detail + place.appendContactDetail(QLatin1String("phone"), contactDetail); + QVERIFY(!place.isEmpty()); + place.removeContactDetails(QLatin1String("phone")); + QVERIFY(place.isEmpty()); + + // visiblity + place.setVisibility(QtLocation::DeviceVisibility); + QVERIFY(!place.isEmpty()); + place.setVisibility(QtLocation::UnspecifiedVisibility); + QVERIFY(place.isEmpty()); +} + QTEST_APPLESS_MAIN(tst_Place) #include "tst_qplace.moc" diff --git a/tests/auto/qplaceratings/tst_qplaceratings.cpp b/tests/auto/qplaceratings/tst_qplaceratings.cpp index 4b07ca58..f99fb2ba 100644 --- a/tests/auto/qplaceratings/tst_qplaceratings.cpp +++ b/tests/auto/qplaceratings/tst_qplaceratings.cpp @@ -58,6 +58,7 @@ private Q_SLOTS: void averageTest(); void countTest(); void operatorsTest(); + void isEmptyTest(); }; tst_QPlaceRatings::tst_QPlaceRatings() @@ -104,6 +105,28 @@ void tst_QPlaceRatings::operatorsTest() QVERIFY2(testObj != testObj2, "Object should be different"); } +void tst_QPlaceRatings::isEmptyTest() +{ + QPlaceRatings ratings; + + QVERIFY(ratings.isEmpty()); + + ratings.setCount(1); + QVERIFY(!ratings.isEmpty()); + ratings.setCount(0); + QVERIFY(ratings.isEmpty()); + + ratings.setMaximum(1); + QVERIFY(!ratings.isEmpty()); + ratings.setMaximum(0); + QVERIFY(ratings.isEmpty()); + + ratings.setAverage(1); + QVERIFY(!ratings.isEmpty()); + ratings.setAverage(0); + QVERIFY(ratings.isEmpty()); +} + QTEST_APPLESS_MAIN(tst_QPlaceRatings); #include "tst_qplaceratings.moc" diff --git a/tests/auto/qplacesupplier/tst_qplacesupplier.cpp b/tests/auto/qplacesupplier/tst_qplacesupplier.cpp index 692f52e6..2ed05079 100644 --- a/tests/auto/qplacesupplier/tst_qplacesupplier.cpp +++ b/tests/auto/qplacesupplier/tst_qplacesupplier.cpp @@ -60,6 +60,7 @@ private Q_SLOTS: void urlTest(); void iconTest(); void operatorsTest(); + void isEmptyTest(); }; tst_QPlaceSupplier::tst_QPlaceSupplier() @@ -137,6 +138,43 @@ void tst_QPlaceSupplier::operatorsTest() QVERIFY2(testObj != testObj2, "Object should be different"); } +void tst_QPlaceSupplier::isEmptyTest() +{ + QPlaceIcon icon; + QVariantMap iconParametersMap; + iconParametersMap.insert(QLatin1String("Para"), QLatin1String("meter")); + icon.setParameters(iconParametersMap); + QVERIFY(!icon.isEmpty()); + + QPlaceSupplier supplier; + + QVERIFY(supplier.isEmpty()); + + // name + supplier.setName(QLatin1String("Name")); + QVERIFY(!supplier.isEmpty()); + supplier.setName(QString()); + QVERIFY(supplier.isEmpty()); + + // supplierId + supplier.setSupplierId(QLatin1String("1")); + QVERIFY(!supplier.isEmpty()); + supplier.setSupplierId(QString()); + QVERIFY(supplier.isEmpty()); + + // url + supplier.setUrl(QUrl(QLatin1String("www.example.com"))); + QVERIFY(!supplier.isEmpty()); + supplier.setUrl(QUrl()); + QVERIFY(supplier.isEmpty()); + + // icon + supplier.setIcon(icon); + QVERIFY(!supplier.isEmpty()); + supplier.setIcon(QPlaceIcon()); + QVERIFY(supplier.isEmpty()); +} + QTEST_APPLESS_MAIN(tst_QPlaceSupplier); #include "tst_qplacesupplier.moc" |