diff options
author | Aaron McCarthy <aaron.mccarthy@nokia.com> | 2012-06-27 10:13:42 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-07-03 02:39:42 +0200 |
commit | 51268e1351c08d4e4f595b177fd247881762c0be (patch) | |
tree | c6fc4bb32a724373c87ed7affc5e4cd4a3b31037 /tests/auto | |
parent | 15f27a542e83a0e61fd2aedd7ef55ecf384fc8b2 (diff) | |
download | qtlocation-51268e1351c08d4e4f595b177fd247881762c0be.tar.gz |
Expand the PlaceSearchModel auto tests.
Add new settable properties to the PlaceSearchModel set/get test.
Add new search (searchTerm and category) test.
Change-Id: I9c78b34c26905e7c716e90b505bd35ae27e44616
Reviewed-by: abcd <amos.choy@nokia.com>
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/declarative_core/tst_categorymodel.qml | 2 | ||||
-rw-r--r-- | tests/auto/declarative_core/tst_placesearchmodel.qml | 109 | ||||
-rw-r--r-- | tests/auto/geotestplugin/geotestplugin.pro | 7 | ||||
-rw-r--r-- | tests/auto/geotestplugin/place_data.json | 57 | ||||
-rw-r--r-- | tests/auto/geotestplugin/qgeotiledmapdata_test.h | 2 | ||||
-rw-r--r-- | tests/auto/geotestplugin/qgeotiledmappingmanagerengine_test.h | 16 | ||||
-rw-r--r-- | tests/auto/geotestplugin/qgeotilefetcher_test.h | 6 | ||||
-rw-r--r-- | tests/auto/geotestplugin/qplacemanagerengine_test.h | 166 | ||||
-rw-r--r-- | tests/auto/qgeomapcontroller/qgeomapcontroller.pro | 3 | ||||
-rw-r--r-- | tests/auto/qgeomapcontroller/tst_qgeomapcontroller.cpp | 4 |
10 files changed, 315 insertions, 57 deletions
diff --git a/tests/auto/declarative_core/tst_categorymodel.qml b/tests/auto/declarative_core/tst_categorymodel.qml index cf85fd0b..2c80e322 100644 --- a/tests/auto/declarative_core/tst_categorymodel.qml +++ b/tests/auto/declarative_core/tst_categorymodel.qml @@ -58,7 +58,7 @@ TestCase { allowExperimental: true parameters: [ PluginParameter { - name: "initializeCategories" + name: "initializePlaceData" value: true } ] diff --git a/tests/auto/declarative_core/tst_placesearchmodel.qml b/tests/auto/declarative_core/tst_placesearchmodel.qml index b626307b..ed7b588f 100644 --- a/tests/auto/declarative_core/tst_placesearchmodel.qml +++ b/tests/auto/declarative_core/tst_placesearchmodel.qml @@ -55,6 +55,18 @@ TestCase { Plugin { id: testPlugin name: "qmlgeo.test.plugin" + allowExperimental: true + parameters: [ + PluginParameter { + name: "initializePlaceData" + value: true + } + ] + } + + Plugin { + id: favoritePlugin + name: "foo" } GeoCircle { @@ -67,7 +79,6 @@ TestCase { } function test_setAndGet_data() { - var myNull = null; return [ { tag: "plugin", property: "plugin", signal: "pluginChanged", value: testPlugin }, { tag: "searchArea", property: "searchArea", signal: "searchAreaChanged", value: testSearchArea }, @@ -75,8 +86,10 @@ TestCase { { tag: "limit", property: "limit", signal: "limitChanged", value: 10, reset: -1 }, { tag: "searchTerm", property: "searchTerm", signal: "searchTermChanged", value: "Test term", reset: "" }, + { tag: "recommendationId", property: "recommendationId", signal: "recommendationIdChanged", value: "Test-place-id", reset: "" }, { tag: "relevanceHint", property: "relevanceHint", signal: "relevanceHintChanged", value: PlaceSearchModel.DistanceHint, reset: PlaceSearchModel.UnspecifiedHint }, { tag: "visibilityScope", property: "visibilityScope", signal: "visibilityScopeChanged", value: Place.DeviceVisibility, reset: Place.UnspecifiedVisibility }, + { tag: "favoritesPlugin", property: "favoritesPlugin", signal: "favoritesPluginChanged", value: favoritePlugin }, ]; } @@ -107,4 +120,98 @@ TestCase { signalSpy.destroy(); } + + function test_search_data() { + var park = Qt.createQmlObject('import QtLocation 5.0; Category {name: "Park"; categoryId: "c2e1252c-b997-44fc-8165-e53dd00f66a7"}', testCase, "Category"); + return [ + { + tag: "searchTerm, multiple results", + property: "searchTerm", + value: "view", + reset: "", + places: [ + "4dcc74ce-fdeb-443e-827c-367438017cf1", + "8f72057a-54b2-4e95-a7bb-97b4d2b5721e" + ] + }, + { + tag: "searchTerm, single result", + property: "searchTerm", + value: "park", + reset: "", + places: [ + "4dcc74ce-fdeb-443e-827c-367438017cf1" + ] + }, + { + tag: "categories, single result", + property: "categories", + value: [ park ], + places: [ + "dacb2181-3f67-4e6a-bd4d-635e99ad5b03" + ] + }, + ]; + } + + function test_search(data) { + testModel.plugin = testPlugin; + + var statusChangedSpy = Qt.createQmlObject('import QtTest 1.0; SignalSpy {}', testCase, "SignalSpy"); + statusChangedSpy.target = testModel; + statusChangedSpy.signalName = "statusChanged"; + + var countChangedSpy = Qt.createQmlObject('import QtTest 1.0; SignalSpy {}', testCase, "SignalSpy"); + countChangedSpy.target = testModel; + countChangedSpy.signalName = "rowCountChanged"; + + compare(testModel.status, PlaceSearchModel.Null); + + testModel[data.property] = data.value; + testModel.update(); + + compare(testModel.status, PlaceSearchModel.Loading); + compare(statusChangedSpy.count, 1); + + tryCompare(testModel, "status", PlaceSearchModel.Ready); + compare(statusChangedSpy.count, 2); + + compare(countChangedSpy.count, 1); + + for (var i = 0; i < testModel.count; ++i) { + compare(testModel.data(i, "type"), PlaceSearchModel.PlaceResult); + + var place = testModel.data(i, "place"); + + verify(data.places.indexOf(place.placeId) >= 0); + } + + testModel.reset(); + + compare(statusChangedSpy.count, 3); + compare(testModel.status, PlaceSearchModel.Null); + compare(countChangedSpy.count, 2); + compare(testModel.count, 0); + + testModel.update(); + + compare(testModel.status, PlaceSearchModel.Loading); + compare(statusChangedSpy.count, 4); + + testModel.cancel(); + + compare(statusChangedSpy.count, 5); + compare(testModel.status, PlaceSearchModel.Null); + + countChangedSpy.destroy(); + statusChangedSpy.destroy(); + + if (data.reset === undefined) { + testModel[data.property] = null; + } else { + testModel[data.property] = data.reset; + } + + testModel.plugin = null; + } } diff --git a/tests/auto/geotestplugin/geotestplugin.pro b/tests/auto/geotestplugin/geotestplugin.pro index 352b1bce..3dcd9e27 100644 --- a/tests/auto/geotestplugin/geotestplugin.pro +++ b/tests/auto/geotestplugin/geotestplugin.pro @@ -1,9 +1,7 @@ load(qt_plugin) TARGET = qtgeoservices_qmltestplugin -QT += location - -INCLUDEPATH += ../../../src/location/maps +QT += location-private testlib DESTDIR = $$QT.location.plugins/geoservices @@ -21,4 +19,5 @@ target.path += $$[QT_INSTALL_PLUGINS]/geoservices INSTALLS += target OTHER_FILES += \ - geotestplugin.json + geotestplugin.json \ + place_data.json diff --git a/tests/auto/geotestplugin/place_data.json b/tests/auto/geotestplugin/place_data.json new file mode 100644 index 00000000..bea3177d --- /dev/null +++ b/tests/auto/geotestplugin/place_data.json @@ -0,0 +1,57 @@ +{ + "categories": [ + { + "name": "Accommodation", + "id": "4b79794f-e146-4adc-9bdf-68c06e7209fd" + }, + { + "name": "Hotel", + "id": "70ab5807-26d2-46be-a860-dc48f17133f0", + "parentId": "4b79794f-e146-4adc-9bdf-68c06e7209fd" + }, + { + "name": "Motel", + "id": "e0478f8a-fe8f-4bf9-8392-c1910e49223f", + "parentId": "4b79794f-e146-4adc-9bdf-68c06e7209fd" + }, + { + "name": "Camping", + "id": "b0434495-9429-4c9f-96e5-75f52f0b8dc8", + "parentId": "4b79794f-e146-4adc-9bdf-68c06e7209fd" + }, + { + "name": "Park", + "id": "c2e1252c-b997-44fc-8165-e53dd00f66a7" + } + ], + + "places": [ + { + "name": "Park View Hotel", + "id": "4dcc74ce-fdeb-443e-827c-367438017cf1", + "categories": [ "70ab5807-26d2-46be-a860-dc48f17133f0" ], + "location": { + "latitude": 0.1001, + "longitude": 0.1001 + } + }, + { + "name": "Sea View Hotel", + "id": "8f72057a-54b2-4e95-a7bb-97b4d2b5721e", + "categories": [ "70ab5807-26d2-46be-a860-dc48f17133f0" ], + "location": { + "latitude": 0.1002, + "longitude": 0.1002 + } + }, + { + "name": "Country Gardens", + "id": "dacb2181-3f67-4e6a-bd4d-635e99ad5b03", + "categories": [ "c2e1252c-b997-44fc-8165-e53dd00f66a7" ], + "location": { + "latitude": 0.1001, + "longitude": 0.1002 + } + } + ] +} diff --git a/tests/auto/geotestplugin/qgeotiledmapdata_test.h b/tests/auto/geotestplugin/qgeotiledmapdata_test.h index 94c018c8..ae892bc9 100644 --- a/tests/auto/geotestplugin/qgeotiledmapdata_test.h +++ b/tests/auto/geotestplugin/qgeotiledmapdata_test.h @@ -42,7 +42,7 @@ #ifndef QGEOTILEDMAPDATA_TEST_H #define QGEOTILEDMAPDATA_TEST_H -#include <qgeotiledmapdata_p.h> +#include <QtLocation/private/qgeotiledmapdata_p.h> QT_USE_NAMESPACE diff --git a/tests/auto/geotestplugin/qgeotiledmappingmanagerengine_test.h b/tests/auto/geotestplugin/qgeotiledmappingmanagerengine_test.h index 36280a2e..7a518276 100644 --- a/tests/auto/geotestplugin/qgeotiledmappingmanagerengine_test.h +++ b/tests/auto/geotestplugin/qgeotiledmappingmanagerengine_test.h @@ -42,20 +42,16 @@ #ifndef QGEOTILEDMAPPINGMANAGERENGINE_TEST_H #define QGEOTILEDMAPPINGMANAGERENGINE_TEST_H -#include <qgeoserviceprovider.h> -#include "qgeotiledmappingmanagerengine_p.h" -#include <QLocale> -#include "qgeotiledmapreply_p.h" -#include "qgeomaptype_p.h" -#include "qgeocameracapabilities_p.h" +#include <QtCore/QLocale> +#include <QtLocation/QGeoServiceProvider> +#include <QtLocation/private/qgeotiledmappingmanagerengine_p.h> +#include <QtLocation/private/qgeotiledmapreply_p.h> +#include <QtLocation/private/qgeomaptype_p.h> +#include <QtLocation/private/qgeocameracapabilities_p.h> #include "qgeotiledmapdata_test.h" #include "qgeotilefetcher_test.h" -#include <QTimer> -#include <QDebug> -#include <QTimerEvent> - QT_USE_NAMESPACE class QGeoTiledMappingManagerEngineTest: public QGeoTiledMappingManagerEngine diff --git a/tests/auto/geotestplugin/qgeotilefetcher_test.h b/tests/auto/geotestplugin/qgeotilefetcher_test.h index 92fa56d0..e6663939 100644 --- a/tests/auto/geotestplugin/qgeotilefetcher_test.h +++ b/tests/auto/geotestplugin/qgeotilefetcher_test.h @@ -42,9 +42,9 @@ #ifndef QGEOTILEFETCHER_TEST_H #define QGEOTILEFETCHER_TEST_H -#include "qgeotiledmapreply_p.h" -#include "qgeotilefetcher_p.h" -#include "qgeotilespec_p.h" +#include <QtLocation/private/qgeotiledmapreply_p.h> +#include <QtLocation/private/qgeotilefetcher_p.h> +#include <QtLocation/private/qgeotilespec_p.h> #include <QLocale> #include <QPainter> diff --git a/tests/auto/geotestplugin/qplacemanagerengine_test.h b/tests/auto/geotestplugin/qplacemanagerengine_test.h index eb660bb9..f0793306 100644 --- a/tests/auto/geotestplugin/qplacemanagerengine_test.h +++ b/tests/auto/geotestplugin/qplacemanagerengine_test.h @@ -42,15 +42,33 @@ #ifndef QPLACEMANAGERENGINE_TEST_H #define QPLACEMANAGERENGINE_TEST_H +#include <QtCore/QFile> +#include <QtCore/QJsonDocument> +#include <QtCore/QJsonObject> +#include <QtCore/QJsonArray> #include <QtCore/QUuid> +#include <QtLocation/QGeoCoordinate> +#include <QtLocation/QGeoLocation> #include <QtLocation/QPlaceManager> #include <QtLocation/QPlaceManagerEngine> #include <QtLocation/QPlaceReply> #include <QtLocation/QPlaceDetailsReply> #include <QtLocation/QPlaceIdReply> #include <QtLocation/QPlaceSearchSuggestionReply> +#include <QtLocation/QPlaceSearchReply> +#include <QtLocation/QPlaceResult> +#include <QtLocation/QPlaceCategory> +#include <QtLocation/QPlace> +#include <QtTest/QTest> -#include <QtCore/QDebug> +QT_BEGIN_NAMESPACE + +inline uint qHash(const QPlaceCategory &category) +{ + return qHash(QUuid(category.categoryId().toLatin1())); +} + +QT_END_NAMESPACE QT_USE_NAMESPACE @@ -115,6 +133,28 @@ public: } }; +class PlaceSearchReply : public QPlaceSearchReply +{ + Q_OBJECT + +public: + PlaceSearchReply(const QList<QPlaceSearchResult> &results, QObject *parent = 0) + : QPlaceSearchReply(parent) + { + setResults(results); + } + + Q_INVOKABLE void emitError() + { + emit error(error(), errorString()); + } + + Q_INVOKABLE void emitFinished() + { + emit finished(); + } +}; + class SuggestionReply : public QPlaceSearchSuggestionReply { Q_OBJECT @@ -146,36 +186,67 @@ public: { m_locales << QLocale(); - if (parameters.value(QLatin1String("initializeCategories"), false).toBool()) { - QPlaceCategory accommodation; - accommodation.setName(QLatin1String("Accommodation")); - accommodation.setCategoryId(QUuid::createUuid().toString()); - m_categories.insert(accommodation.categoryId(), accommodation); - m_childCategories[QString()].append(accommodation.categoryId()); - - QPlaceCategory hotel; - hotel.setName(QLatin1String("Hotel")); - hotel.setCategoryId(QUuid::createUuid().toString()); - m_categories.insert(hotel.categoryId(), hotel); - m_childCategories[accommodation.categoryId()].append(hotel.categoryId()); - - QPlaceCategory motel; - motel.setName(QLatin1String("Motel")); - motel.setCategoryId(QUuid::createUuid().toString()); - m_categories.insert(motel.categoryId(), motel); - m_childCategories[accommodation.categoryId()].append(motel.categoryId()); - - QPlaceCategory camping; - camping.setName(QLatin1String("Camping")); - camping.setCategoryId(QUuid::createUuid().toString()); - m_categories.insert(camping.categoryId(), camping); - m_childCategories[accommodation.categoryId()].append(camping.categoryId()); - - QPlaceCategory park; - park.setName(QLatin1String("Park")); - park.setCategoryId(QUuid::createUuid().toString()); - m_categories.insert(park.categoryId(), park); - m_childCategories[QString()].append(park.categoryId()); + if (parameters.value(QStringLiteral("initializePlaceData"), false).toBool()) { + QFile placeData(QFINDTESTDATA("place_data.json")); + if (placeData.open(QIODevice::ReadOnly)) { + QJsonDocument document = QJsonDocument::fromJson(placeData.readAll()); + + if (document.isObject()) { + QJsonObject o = document.object(); + + if (o.contains(QStringLiteral("categories"))) { + QJsonArray categories = o.value(QStringLiteral("categories")).toArray(); + + for (int i = 0; i < categories.count(); ++i) { + QJsonObject c = categories.at(i).toObject(); + + QPlaceCategory category; + + category.setName(c.value(QStringLiteral("name")).toString()); + category.setCategoryId(c.value(QStringLiteral("id")).toString()); + + m_categories.insert(category.categoryId(), category); + + const QString parentId = c.value(QStringLiteral("parentId")).toString(); + m_childCategories[parentId].append(category.categoryId()); + } + } + + if (o.contains(QStringLiteral("places"))) { + QJsonArray places = o.value(QStringLiteral("places")).toArray(); + + for (int i = 0; i < places.count(); ++i) { + QJsonObject p = places.at(i).toObject(); + + QPlace place; + + place.setName(p.value(QStringLiteral("name")).toString()); + place.setPlaceId(p.value(QStringLiteral("id")).toString()); + + QList<QPlaceCategory> categories; + QJsonArray ca = p.value(QStringLiteral("categories")).toArray(); + for (int j = 0; j < ca.count(); ++j) { + QPlaceCategory c = m_categories.value(ca.at(j).toString()); + if (!c.isEmpty()) + categories.append(c); + } + place.setCategories(categories); + + QGeoCoordinate coordinate; + QJsonObject lo = p.value(QStringLiteral("location")).toObject(); + coordinate.setLatitude(lo.value(QStringLiteral("latitude")).toDouble()); + coordinate.setLongitude(lo.value(QStringLiteral("longitude")).toDouble()); + + QGeoLocation location; + location.setCoordinate(coordinate); + + place.setLocation(location); + + m_places.insert(place.placeId(), place); + } + } + } + } } } @@ -205,9 +276,38 @@ public: QPlaceSearchReply *search(const QPlaceSearchRequest &query) { - Q_UNUSED(query) + QList<QPlaceSearchResult> results; - return 0; + if (!query.searchTerm().isEmpty()) { + foreach (const QPlace &place, m_places) { + if (!place.name().contains(query.searchTerm(), Qt::CaseInsensitive)) + continue; + + QPlaceResult r; + r.setPlace(place); + r.setTitle(place.name()); + + results.append(r); + } + } else if (!query.categories().isEmpty()) { + QSet<QPlaceCategory> categories = query.categories().toSet(); + foreach (const QPlace &place, m_places) { + if (place.categories().toSet().intersect(categories).isEmpty()) + continue; + + QPlaceResult r; + r.setPlace(place); + r.setTitle(place.name()); + + results.append(r); + } + } + + PlaceSearchReply *reply = new PlaceSearchReply(results, this); + + QMetaObject::invokeMethod(reply, "emitFinished", Qt::QueuedConnection); + + return reply; } QPlaceSearchSuggestionReply *searchSuggestions(const QPlaceSearchRequest &query) diff --git a/tests/auto/qgeomapcontroller/qgeomapcontroller.pro b/tests/auto/qgeomapcontroller/qgeomapcontroller.pro index 38ec87e6..8bb40c67 100644 --- a/tests/auto/qgeomapcontroller/qgeomapcontroller.pro +++ b/tests/auto/qgeomapcontroller/qgeomapcontroller.pro @@ -2,7 +2,6 @@ TEMPLATE = app CONFIG += testcase TARGET = tst_qgeomapcontroller -INCLUDEPATH += ../../../src/location/maps HEADERS += ../geotestplugin/qgeoserviceproviderplugin_test.h \ ../geotestplugin/qgeotiledmapdata_test.h \ ../geotestplugin/qgeotiledmappingmanagerengine_test.h \ @@ -14,4 +13,4 @@ HEADERS += ../geotestplugin/qgeoserviceproviderplugin_test.h \ SOURCES += tst_qgeomapcontroller.cpp SOURCES += ../geotestplugin/qgeoserviceproviderplugin_test.cpp -QT += location testlib +QT += location-private testlib diff --git a/tests/auto/qgeomapcontroller/tst_qgeomapcontroller.cpp b/tests/auto/qgeomapcontroller/tst_qgeomapcontroller.cpp index 995b8c69..3b4758a5 100644 --- a/tests/auto/qgeomapcontroller/tst_qgeomapcontroller.cpp +++ b/tests/auto/qgeomapcontroller/tst_qgeomapcontroller.cpp @@ -43,8 +43,8 @@ #include <QtTest/QtTest> #include <QSignalSpy> -#include "qgeomapdata_p.h" -#include "qgeomapcontroller_p.h" +#include <QtLocation/private/qgeomapdata_p.h> +#include <QtLocation/private/qgeomapcontroller_p.h> // cross-reference test plugin, where concrete subclasses are needed // in order to create a concrete mapcontroller |