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/geotestplugin | |
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/geotestplugin')
-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 |
6 files changed, 203 insertions, 51 deletions
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) |