summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPaolo Angelelli <paolo.angelelli@qt.io>2017-08-29 16:48:51 +0200
committerPaolo Angelelli <paolo.angelelli@qt.io>2018-01-27 09:56:21 +0000
commita6ff21e1e5ae264b7de264b47e08d334739fa4c6 (patch)
tree0da24ba1c0a9b5b0190d1f8a8c844ac3a9e4ea64 /tests
parentd8a7da2c00d9b292e56f28cf2df4f191e6edce2c (diff)
downloadqtlocation-a6ff21e1e5ae264b7de264b47e08d334739fa4c6.tar.gz
Make QPlace extensible
This change makes it possible to subclass QPlace with custom private implementations. Change-Id: I363c0e8b7db41d9a8400ce6dbddf5405c619eeef Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/declarative_core/tst_placesearchmodel.qml18
-rw-r--r--tests/auto/geotestplugin/place_data.json3
-rw-r--r--tests/auto/geotestplugin/qplacemanagerengine_test.h39
3 files changed, 59 insertions, 1 deletions
diff --git a/tests/auto/declarative_core/tst_placesearchmodel.qml b/tests/auto/declarative_core/tst_placesearchmodel.qml
index 2d3c599c..4c7897b5 100644
--- a/tests/auto/declarative_core/tst_placesearchmodel.qml
+++ b/tests/auto/declarative_core/tst_placesearchmodel.qml
@@ -129,6 +129,16 @@ TestCase {
]
},
{
+ tag: "searchTerm, multiple results",
+ property: "searchTerm",
+ value: "sea",
+ reset: "",
+ alternate: true,
+ places: [
+ "8f72057a-54b2-4e95-a7bb-97b4d2b5721e"
+ ]
+ },
+ {
tag: "categories, single result",
property: "categories",
value: [ park ],
@@ -192,6 +202,14 @@ TestCase {
verify(data.places.indexOf(place.placeId) >= 0);
}
+ // Test for alternate implementation
+ if (data.alternate !== undefined && data.alternate === true) {
+ for (var ii = 0; ii < testModel.count; ++ii) {
+ var p = testModel.data(ii, "place");
+ compare(p.extendedAttributes["x_provider"].text, "QPlacePrivateDefaultAlt")
+ }
+ }
+
testModel.reset();
compare(statusChangedSpy.count, 3);
diff --git a/tests/auto/geotestplugin/place_data.json b/tests/auto/geotestplugin/place_data.json
index 20062816..3aafcbec 100644
--- a/tests/auto/geotestplugin/place_data.json
+++ b/tests/auto/geotestplugin/place_data.json
@@ -130,7 +130,8 @@
"location": {
"latitude": 0.1002,
"longitude": 0.1002
- }
+ },
+ "alternateImplementation": true
},
{
"name": "Country Gardens",
diff --git a/tests/auto/geotestplugin/qplacemanagerengine_test.h b/tests/auto/geotestplugin/qplacemanagerengine_test.h
index f8af1edc..30e5422e 100644
--- a/tests/auto/geotestplugin/qplacemanagerengine_test.h
+++ b/tests/auto/geotestplugin/qplacemanagerengine_test.h
@@ -51,6 +51,7 @@
#include <QtLocation/QPlaceCategory>
#include <QtLocation/QPlace>
#include <QtLocation/QPlaceReview>
+#include <QtLocation/private/qplace_p.h>
#include <QtTest/QTest>
QT_BEGIN_NAMESPACE
@@ -64,6 +65,37 @@ QT_END_NAMESPACE
QT_USE_NAMESPACE
+class QPlacePrivateDefaultAlt : public QPlacePrivateDefault
+{
+public:
+ QPlacePrivateDefaultAlt() {}
+ QPlacePrivateDefaultAlt(const QPlacePrivateDefaultAlt &other)
+ : QPlacePrivateDefault(other)
+ {
+ }
+ ~QPlacePrivateDefaultAlt() {}
+
+ QPlaceAttribute extendedAttribute(const QString &attributeType) const override
+ {
+ if (attributeType == QStringLiteral("x_provider")) {
+ QPlaceAttribute a;
+ a.setLabel(QStringLiteral("x_provider"));
+ a.setText(QStringLiteral("QPlacePrivateDefaultAlt"));
+ return a;
+ } else {
+ return QPlacePrivateDefault::extendedAttribute(attributeType);
+ }
+ }
+};
+
+class QPlaceAlt : public QPlace
+{
+public:
+ QPlaceAlt() : QPlace(QSharedDataPointer<QPlacePrivate>(new QPlacePrivateDefaultAlt()))
+ {
+ }
+};
+
class PlaceReply : public QPlaceReply
{
Q_OBJECT
@@ -233,6 +265,13 @@ public:
QJsonObject p = places.at(i).toObject();
QPlace place;
+ if (p.value(QStringLiteral("alternateImplementation")).toBool(false)) {
+ place = QPlaceAlt();
+ QPlaceAttribute att;
+ att.setLabel(QStringLiteral("x_provider"));
+ att.setText(QStringLiteral("42")); // Doesn't matter, wont be used.
+ place.setExtendedAttribute(QStringLiteral("x_provider"), att);
+ }
place.setName(p.value(QStringLiteral("name")).toString());
place.setPlaceId(p.value(QStringLiteral("id")).toString());