summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/declarative_core/tst_geocoding.qml24
-rw-r--r--tests/auto/geotestplugin/qgeocodingmanagerengine_test.h53
-rw-r--r--tests/auto/qgeolocation/tst_qgeolocation.cpp32
-rw-r--r--tests/auto/qgeolocation/tst_qgeolocation.h2
-rw-r--r--tests/plugins/declarativetestplugin/locationtest.cpp3
5 files changed, 111 insertions, 3 deletions
diff --git a/tests/auto/declarative_core/tst_geocoding.qml b/tests/auto/declarative_core/tst_geocoding.qml
index 1eadf870..16843528 100644
--- a/tests/auto/declarative_core/tst_geocoding.qml
+++ b/tests/auto/declarative_core/tst_geocoding.qml
@@ -272,6 +272,14 @@ Item {
]
}
+ Plugin {
+ id: extendedPlugin;
+ name: "qmlgeo.test.plugin";
+ allowExperimental: true
+ PluginParameter { name: "finishRequestImmediately"; value: false}
+ PluginParameter { name: "includeExtendedData"; value: true }
+ }
+
GeocodeModel {id: testModel; plugin: testPlugin2}
SignalSpy {id: locationsSpy; target: testModel; signalName: "locationsChanged"}
SignalSpy {id: countSpy; target: testModel; signalName: "countChanged"}
@@ -297,6 +305,9 @@ Item {
GeocodeModel {id: automaticModel; plugin: autoPlugin; query: automaticAddress1; autoUpdate: true}
SignalSpy {id: automaticLocationsSpy; target: automaticModel; signalName: "locationsChanged"}
+ GeocodeModel {id: extendedModel; plugin: extendedPlugin; query: automaticAddress1; autoUpdate: true}
+ SignalSpy {id: extendedLocationsSpy; target: extendedModel; signalName: "locationsChanged"}
+
TestCase {
name: "GeocodeModelGeocoding"
function clear_slack_model() {
@@ -546,6 +557,19 @@ Item {
compare (automaticModel.count, 3)
}
+ function test_geocode_extended_attributes() {
+ compare (extendedModel.count, 6) // should be something already
+ compare (extendedLocationsSpy.count, 3)
+ compare(extendedModel.get(0).extendedAttributes
+ ["QGeoCodingManagerEngineTest_locationExtendedAttribute"], 42)
+ // change query and its contents and verify that autoupdate occurs
+ extendedModel.query = automaticCoordinate1
+ tryCompare(extendedLocationsSpy, "count", 4)
+ compare (extendedModel.count, 3)
+ compare(extendedModel.get(0).extendedAttributes
+ ["QGeoCodingManagerEngineTest_locationExtendedAttribute"], 42)
+ }
+
function test_delayed_geocode() {
// basic delayed response
slackModel.reset()
diff --git a/tests/auto/geotestplugin/qgeocodingmanagerengine_test.h b/tests/auto/geotestplugin/qgeocodingmanagerengine_test.h
index ecbb60d1..5a8ff451 100644
--- a/tests/auto/geotestplugin/qgeocodingmanagerengine_test.h
+++ b/tests/auto/geotestplugin/qgeocodingmanagerengine_test.h
@@ -35,20 +35,39 @@
#include <QtPositioning/qgeoaddress.h>
#include <QtPositioning/qgeolocation.h>
#include <qgeocodereply.h>
+#include <QtLocation/private/qgeocodereply_p.h>
#include <QtPositioning/QGeoShape>
#include <QTimer>
#include <QDebug>
#include <QTimerEvent>
+#include <QVariantMap>
QT_USE_NAMESPACE
+class GeocodeReplyTestPrivate : public QGeoCodeReplyPrivate
+{
+public:
+ GeocodeReplyTestPrivate()
+ {
+ }
+ ~GeocodeReplyTestPrivate()
+ {
+ }
+ QVariantMap extraData() const override
+ {
+ return m_extraData;
+ }
+
+ QVariantMap m_extraData;
+};
+
class GeocodeReplyTest :public QGeoCodeReply
{
Q_OBJECT
public:
- GeocodeReplyTest(QObject *parent = 0) : QGeoCodeReply (parent) {}
+ GeocodeReplyTest(QObject *parent = 0) : QGeoCodeReply (*new GeocodeReplyTestPrivate, parent) {}
void callAddLocation ( const QGeoLocation & location ) {addLocation(location);}
void callSetError ( Error error, const QString & errorString ) {setError(error, errorString);}
@@ -82,6 +101,11 @@ public:
finishRequestImmediately_ = qvariant_cast<bool>(parameters.value("finishRequestImmediately"));
if (parameters.contains("validateWellKnownValues"))
validateWellKnownValues_ = qvariant_cast<bool>(parameters.value("validateWellKnownValues"));
+ if (parameters.contains("includeExtendedData")) {
+ includeExtendedData_ = qvariant_cast<bool>(parameters.value("includeExtendedData"));
+ extendedLocationData_["QGeoCodingManagerEngineTest_locationExtendedAttribute"] = 42;
+ extendedReplyData_["QGeoCodingManagerEngineTest_extraData"] = 43;
+ }
setLocale(QLocale (QLocale::German, QLocale::Germany));
}
@@ -105,6 +129,8 @@ public:
if (errorCode_ == QGeoCodeReply::NoError)
setLocations(geocodeReply_, searchString, limit, offset);
+ if (includeExtendedData_)
+ injectExtra(geocodeReply_, extendedReplyData_);
if (finishRequestImmediately_) {
// check if we should finish with error
@@ -126,6 +152,8 @@ public:
geocodeReply_ = new GeocodeReplyTest();
connect(geocodeReply_, SIGNAL(aborted()), this, SLOT(requestAborted()));
geocodeReply_->callSetViewport(bounds);
+ if (includeExtendedData_)
+ injectExtra(geocodeReply_, extendedReplyData_);
if (address.street().startsWith("error")) {
errorString_ = address.street();
@@ -184,6 +212,8 @@ public:
address.setStreet(searchString);
address.setCounty(QString::number(offset));
location.setAddress(address);
+ if (includeExtendedData_)
+ injectExtra(location, extendedLocationData_);
reply->callAddLocation(location);
}
}
@@ -195,6 +225,8 @@ public:
for (int i = 0; i < count; ++i) {
QGeoLocation location;
location.setAddress(address);
+ if (includeExtendedData_)
+ injectExtra(location, extendedLocationData_);
reply->callAddLocation(location);
}
}
@@ -204,6 +236,8 @@ public:
for (int i = 0; i < coordinate.longitude(); ++i) {
QGeoLocation location;
location.setCoordinate(coordinate);
+ if (includeExtendedData_)
+ injectExtra(location, extendedLocationData_);
reply->callAddLocation(location);
}
}
@@ -215,6 +249,8 @@ public:
setLocations(geocodeReply_, coordinate);
geocodeReply_->callSetViewport(bounds);
+ if (includeExtendedData_)
+ injectExtra(geocodeReply_, extendedReplyData_);
if (coordinate.latitude() > 70) {
errorString_ = "error";
@@ -256,7 +292,20 @@ protected:
emit finished(geocodeReply_);
}
+ static void injectExtra(QGeoCodeReply *reply, const QVariantMap &extra)
+ {
+ GeocodeReplyTestPrivate *replyPrivate
+ = static_cast<GeocodeReplyTestPrivate *>(QGeoCodeReplyPrivate::get(*reply));
+ replyPrivate->m_extraData = extra;
+ }
+
+ static void injectExtra(QGeoLocation &location, const QVariantMap &extra)
+ {
+ location.setExtendedAttributes(extra);
+ }
+
private:
+ bool includeExtendedData_ = false;
bool validateWellKnownValues_;
bool finishRequestImmediately_;
bool supported_;
@@ -264,6 +313,8 @@ private:
int timerId_;
QGeoCodeReply::Error errorCode_;
QString errorString_;
+ QVariantMap extendedLocationData_;
+ QVariantMap extendedReplyData_;
};
#endif
diff --git a/tests/auto/qgeolocation/tst_qgeolocation.cpp b/tests/auto/qgeolocation/tst_qgeolocation.cpp
index 9e40b0b0..bb1f47f9 100644
--- a/tests/auto/qgeolocation/tst_qgeolocation.cpp
+++ b/tests/auto/qgeolocation/tst_qgeolocation.cpp
@@ -57,6 +57,7 @@ void tst_QGeoLocation::constructor()
QCOMPARE(m_location.address(), m_address);
QCOMPARE(m_location.coordinate(), m_coordinate);
QCOMPARE(m_location.boundingBox(), m_viewport);
+ QCOMPARE(m_location.extendedAttributes(), m_extendedAttributes);
}
void tst_QGeoLocation::copy_constructor()
@@ -123,6 +124,16 @@ void tst_QGeoLocation::viewport()
QVERIFY(m_location.boundingBox() != qgeoboundingboxcopy);
}
+void tst_QGeoLocation::extendedAttributes()
+{
+ m_extendedAttributes = QVariantMap({{ "foo" , 42 }});
+ m_location.setExtendedAttributes(m_extendedAttributes);
+ QCOMPARE(m_location.extendedAttributes(), m_extendedAttributes);
+
+ m_extendedAttributes["foo"] = 41;
+ QVERIFY(m_location.extendedAttributes() != m_extendedAttributes);
+}
+
void tst_QGeoLocation::operators()
{
QGeoAddress qgeoaddresscopy;
@@ -131,6 +142,7 @@ void tst_QGeoLocation::operators()
qgeoaddresscopy.setCountryCode("DEU");
QGeoCoordinate qgeocoordinatecopy (32.324 , 41.324 , 24.55);
+ QVariantMap extendedAttributesCopy {{ "foo" , 42 }};
m_address.setCity("Madrid");
m_address.setCountry("Spain");
@@ -140,8 +152,11 @@ void tst_QGeoLocation::operators()
m_coordinate.setLongitude(38.43443);
m_coordinate.setAltitude(634.21);
+ m_extendedAttributes["foo"] = 43;
+
m_location.setAddress(m_address);
m_location.setCoordinate(m_coordinate);
+ m_location.setExtendedAttributes(m_extendedAttributes);
//Create a copy and see that they are the same
QGeoLocation qgeolocationcopy(m_location);
@@ -152,9 +167,15 @@ void tst_QGeoLocation::operators()
qgeolocationcopy.setAddress(qgeoaddresscopy);
QVERIFY(!(m_location == qgeolocationcopy));
QVERIFY(m_location != qgeolocationcopy);
+ qgeolocationcopy.setAddress(m_address);
qgeolocationcopy.setCoordinate(qgeocoordinatecopy);
QVERIFY(!(m_location == qgeolocationcopy));
QVERIFY(m_location != qgeolocationcopy);
+ qgeolocationcopy.setCoordinate(m_coordinate);
+ qgeolocationcopy.setExtendedAttributes(extendedAttributesCopy);
+ QVERIFY(!(m_location == qgeolocationcopy));
+ QVERIFY(m_location != qgeolocationcopy);
+
//delete qgeolocationcopy;
//Asign and test that they are the same
@@ -195,6 +216,8 @@ void tst_QGeoLocation::comparison()
otherLocation.setCoordinate(QGeoCoordinate(12,13));
} else if (dataField == "viewport"){
otherLocation.setBoundingBox(QGeoRectangle(QGeoCoordinate(1,2), 0.5,0.5));
+ } else if (dataField == "extendedAttributes"){
+ otherLocation.setExtendedAttributes(QVariantMap({{"foo", 44}}));
} else {
qFatal("Unknown data field to test");
}
@@ -209,6 +232,7 @@ void tst_QGeoLocation::comparison_data()
QTest::newRow("no change") << "no change";
QTest::newRow("address") << "address";
QTest::newRow("coordinate") << "coordinate";
+ QTest::newRow("extendedAttributes") << "extendedAttributes";
}
void tst_QGeoLocation::isEmpty()
@@ -222,6 +246,8 @@ void tst_QGeoLocation::isEmpty()
boundingBox.setBottomRight(QGeoCoordinate(-1, 1));
QVERIFY(!boundingBox.isEmpty());
+ QVariantMap extendedAttributes({{"foo", 11}});
+
QGeoLocation location;
QVERIFY(location.isEmpty());
@@ -243,6 +269,12 @@ void tst_QGeoLocation::isEmpty()
QVERIFY(!location.isEmpty());
location.setBoundingBox(QGeoRectangle());
QVERIFY(location.isEmpty());
+
+ // extended attributes
+ location.setExtendedAttributes(extendedAttributes);
+ QVERIFY(!location.isEmpty());
+ location.setExtendedAttributes(QVariantMap());
+ 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 182cad27..a2bf6649 100644
--- a/tests/auto/qgeolocation/tst_qgeolocation.h
+++ b/tests/auto/qgeolocation/tst_qgeolocation.h
@@ -62,6 +62,7 @@ private Q_SLOTS:
void address();
void coordinate();
void viewport();
+ void extendedAttributes();
void operators();
void comparison();
void comparison_data();
@@ -74,6 +75,7 @@ private:
QGeoAddress m_address;
QGeoCoordinate m_coordinate;
QGeoRectangle m_viewport;
+ QVariantMap m_extendedAttributes;
};
Q_DECLARE_METATYPE( QGeoCoordinate::CoordinateFormat);
diff --git a/tests/plugins/declarativetestplugin/locationtest.cpp b/tests/plugins/declarativetestplugin/locationtest.cpp
index 44e74e86..f5efd423 100644
--- a/tests/plugins/declarativetestplugin/locationtest.cpp
+++ b/tests/plugins/declarativetestplugin/locationtest.cpp
@@ -62,7 +62,6 @@ public:
}
};
-#include "locationtest.moc"
-
QT_END_NAMESPACE
+#include "locationtest.moc"