diff options
author | Aaron McCarthy <aaron.mccarthy@nokia.com> | 2011-09-21 15:49:40 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-09-27 07:08:30 +0200 |
commit | 0aa6b39d6a3c67c573408cb329ed5ebc8ce7b150 (patch) | |
tree | 490b6e430a00b7733e774c92daea6d2158dd66ce /tests/auto/geotestplugin/qplacemanagerengine_test.h | |
parent | 246e55aa9e64add8a23fe6b44f19d3fa3817ad20 (diff) | |
download | qtlocation-0aa6b39d6a3c67c573408cb329ed5ebc8ce7b150.tar.gz |
Place element unit tests.
Change-Id: Ife7b98f33e83e41619b7ec81edb9b9cce715a0d6
Reviewed-on: http://codereview.qt-project.org/5283
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: abcd <qt_abcd1@ovi.com>
Reviewed-by: Aaron McCarthy <aaron.mccarthy@nokia.com>
Diffstat (limited to 'tests/auto/geotestplugin/qplacemanagerengine_test.h')
-rw-r--r-- | tests/auto/geotestplugin/qplacemanagerengine_test.h | 97 |
1 files changed, 91 insertions, 6 deletions
diff --git a/tests/auto/geotestplugin/qplacemanagerengine_test.h b/tests/auto/geotestplugin/qplacemanagerengine_test.h index 62d7852a..87a9f6b3 100644 --- a/tests/auto/geotestplugin/qplacemanagerengine_test.h +++ b/tests/auto/geotestplugin/qplacemanagerengine_test.h @@ -42,10 +42,14 @@ #ifndef QPLACEMANAGERENGINE_TEST_H #define QPLACEMANAGERENGINE_TEST_H +#include <QtCore/QUuid> + #include <qplacemanager.h> #include <qplacemanagerengine.h> #include <qplacereply.h> +#include <QtCore/QDebug> + QT_USE_NAMESPACE class PlaceReplyTest : public QPlaceReply @@ -61,6 +65,50 @@ Q_SIGNALS: void aborted(); }; +class DetailsReply : public QPlaceDetailsReply +{ + Q_OBJECT + + friend class QPlaceManagerEngineTest; + +public: + DetailsReply(QObject *parent = 0) + : QPlaceDetailsReply(parent) + { } + + Q_INVOKABLE void emitError() + { + emit error(error(), errorString()); + } + + Q_INVOKABLE void emitFinished() + { + emit finished(); + } +}; + +class IdReply : public QPlaceIdReply +{ + Q_OBJECT + + friend class QPlaceManagerEngineTest; + +public: + IdReply(QPlaceIdReply::OperationType type, QObject *parent = 0) + : QPlaceIdReply(type, parent) + { } + + Q_INVOKABLE void emitError() + { + emit error(error(), errorString()); + } + + Q_INVOKABLE void emitFinished() + { + emit finished(); + } +}; + class QPlaceManagerEngineTest : public QPlaceManagerEngine { Q_OBJECT @@ -72,9 +120,18 @@ public: QPlaceDetailsReply *getPlaceDetails(const QString &placeId) { - Q_UNUSED(placeId) + DetailsReply *reply = new DetailsReply(this); - return 0; + if (placeId.isEmpty() || !m_places.contains(placeId)) { + reply->setError(QPlaceReply::PlaceDoesNotExistError, tr("Place does not exist")); + QMetaObject::invokeMethod(reply, "emitError", Qt::QueuedConnection); + } else { + reply->setResult(m_places.value(placeId)); + } + + QMetaObject::invokeMethod(reply, "emitFinished", Qt::QueuedConnection); + + return reply; } QPlaceContentReply *getContent(const QPlace &place, const QPlaceContentRequest &query) @@ -117,10 +174,27 @@ public: QPlaceIdReply *savePlace(const QPlace &place, QPlaceManager::VisibilityScope scope) { - Q_UNUSED(place) Q_UNUSED(scope) - return 0; + IdReply *reply = new IdReply(QPlaceIdReply::SavePlace, this); + + if (!place.placeId().isEmpty() && !m_places.contains(place.placeId())) { + reply->setError(QPlaceReply::PlaceDoesNotExistError, tr("Place does not exist")); + QMetaObject::invokeMethod(reply, "emitError", Qt::QueuedConnection); + } else if (!place.placeId().isEmpty()) { + m_places.insert(place.placeId(), place); + reply->setId(place.placeId()); + } else { + QPlace p = place; + p.setPlaceId(QUuid::createUuid().toString()); + m_places.insert(p.placeId(), p); + + reply->setId(p.placeId()); + } + + QMetaObject::invokeMethod(reply, "emitFinished", Qt::QueuedConnection); + + return reply; } QPlaceManager::VisibilityScopes supportedSaveVisibilityScopes() const @@ -130,9 +204,19 @@ public: QPlaceIdReply *removePlace(const QPlace &place) { - Q_UNUSED(place) + IdReply *reply = new IdReply(QPlaceIdReply::RemovePlace, this); + reply->setId(place.placeId()); - return 0; + if (!m_places.contains(place.placeId())) { + reply->setError(QPlaceReply::PlaceDoesNotExistError, tr("Place does not exist")); + QMetaObject::invokeMethod(reply, "emitError", Qt::QueuedConnection); + } else { + m_places.remove(place.placeId()); + } + + QMetaObject::invokeMethod(reply, "emitFinished", Qt::QueuedConnection); + + return reply; } QPlaceReply *initializeCategories() @@ -159,6 +243,7 @@ public: private: QLocale m_locale; + QMap<QString, QPlace> m_places; }; #endif |