summaryrefslogtreecommitdiff
path: root/tests/auto/geotestplugin/qplacemanagerengine_test.h
diff options
context:
space:
mode:
authorAaron McCarthy <aaron.mccarthy@nokia.com>2011-12-14 14:14:04 +1000
committerQt by Nokia <qt-info@nokia.com>2011-12-16 04:07:25 +0100
commit84686e81c4b2a456826910ee618c8e462a81a0c1 (patch)
tree573373fca80b0d66cc66e93466a480e56743dcc3 /tests/auto/geotestplugin/qplacemanagerengine_test.h
parent54dcba08d14ab60566d00518dbb9d1feaf80901f (diff)
downloadqtlocation-84686e81c4b2a456826910ee618c8e462a81a0c1.tar.gz
Unit tests for Category element.
Change-Id: I3602b84490067287d840c784d40aa59cbf7e8d34 Reviewed-by: abcd <amos.choy@nokia.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.h115
1 files changed, 92 insertions, 23 deletions
diff --git a/tests/auto/geotestplugin/qplacemanagerengine_test.h b/tests/auto/geotestplugin/qplacemanagerengine_test.h
index c5993c76..3f6b9ec9 100644
--- a/tests/auto/geotestplugin/qplacemanagerengine_test.h
+++ b/tests/auto/geotestplugin/qplacemanagerengine_test.h
@@ -54,17 +54,21 @@
QT_USE_NAMESPACE
-class PlaceReplyTest : public QPlaceReply
+class PlaceReply : public QPlaceReply
{
Q_OBJECT
-public:
- PlaceReplyTest(QObject *parent = 0)
- : QPlaceReply(parent) {}
- void abort() { emit aborted(); }
+ friend class QPlaceManagerEngineTest;
+
+public:
+ PlaceReply(QObject *parent = 0)
+ : QPlaceReply(parent)
+ { }
-Q_SIGNALS:
- void aborted();
+ Q_INVOKABLE void emitFinished()
+ {
+ emit finished();
+ }
};
class DetailsReply : public QPlaceDetailsReply
@@ -209,44 +213,107 @@ public:
QPlaceIdReply *saveCategory(const QPlaceCategory &category, const QString &parentId)
{
- Q_UNUSED(category);
- Q_UNUSED(parentId);
+ IdReply *reply = new IdReply(QPlaceIdReply::SaveCategory, this);
- return 0;
+ if ((!category.categoryId().isEmpty() && !m_categories.contains(category.categoryId())) ||
+ (!parentId.isEmpty() && !m_categories.contains(parentId))) {
+ reply->setError(QPlaceReply::CategoryDoesNotExistError, tr("Category does not exist"));
+ QMetaObject::invokeMethod(reply, "emitError", Qt::QueuedConnection);
+ } else if (!category.categoryId().isEmpty()) {
+ m_categories.insert(category.categoryId(), category);
+ QStringList children = m_childCategories.value(parentId);
+
+ QMutableHashIterator<QString, QStringList> i(m_childCategories);
+ while (i.hasNext()) {
+ i.next();
+ i.value().removeAll(category.categoryId());
+ }
+
+ if (!children.contains(category.categoryId())) {
+ children.append(category.categoryId());
+ m_childCategories.insert(parentId, children);
+ }
+ reply->setId(category.categoryId());
+ } else {
+ QPlaceCategory c = category;
+ c.setCategoryId(QUuid::createUuid().toString());
+ m_categories.insert(c.categoryId(), c);
+ QStringList children = m_childCategories.value(parentId);
+ if (!children.contains(c.categoryId())) {
+ children.append(c.categoryId());
+ m_childCategories.insert(parentId, children);
+ }
+
+ reply->setId(c.categoryId());
+ }
+
+ QMetaObject::invokeMethod(reply, "emitFinished", Qt::QueuedConnection);
+
+ return reply;
}
QPlaceIdReply *removeCategory(const QString &categoryId)
{
- Q_UNUSED(categoryId);
+ IdReply *reply = new IdReply(QPlaceIdReply::RemoveCategory, this);
+ reply->setId(categoryId);
- return 0;
+ if (!m_categories.contains(categoryId)) {
+ reply->setError(QPlaceReply::CategoryDoesNotExistError, tr("Category does not exist"));
+ QMetaObject::invokeMethod(reply, "emitError", Qt::QueuedConnection);
+ } else {
+ m_categories.remove(categoryId);
+
+ QMutableHashIterator<QString, QStringList> i(m_childCategories);
+ while (i.hasNext()) {
+ i.next();
+ i.value().removeAll(categoryId);
+ }
+ }
+
+ QMetaObject::invokeMethod(reply, "emitFinished", Qt::QueuedConnection);
+
+ return reply;
}
QPlaceReply *initializeCategories()
{
- return 0;
+ QPlaceReply *reply = new PlaceReply(this);
+
+ QMetaObject::invokeMethod(reply, "emitFinished", Qt::QueuedConnection);
+
+ return reply;
}
QString parentCategoryId(const QString &categoryId) const
{
- Q_UNUSED(categoryId)
+ QHashIterator<QString, QStringList> i(m_childCategories);
+ while (i.hasNext()) {
+ i.next();
+ if (i.value().contains(categoryId))
+ return i.key();
+ }
+
return QString();
}
virtual QStringList childrenCategoryIds(const QString &categoryId) const
{
- Q_UNUSED(categoryId)
- return QStringList();
+ return m_childCategories.value(categoryId);
}
- virtual QPlaceCategory category(const QString &categoryId) const {
- Q_UNUSED(categoryId)
- return QPlaceCategory();
+ virtual QPlaceCategory category(const QString &categoryId) const
+ {
+ return m_categories.value(categoryId);
}
- QList<QPlaceCategory> childCategories(const QString &parentId) const {
- Q_UNUSED(parentId);
- return QList<QPlaceCategory>();
+ QList<QPlaceCategory> childCategories(const QString &parentId) const
+ {
+ QList<QPlaceCategory> categories;
+
+ foreach (const QString &id, m_childCategories.value(parentId))
+ categories.append(m_categories.value(id));
+
+ return categories;
}
QList<QLocale> locales() const
@@ -281,7 +348,9 @@ public:
private:
QList<QLocale> m_locales;
- QMap<QString, QPlace> m_places;
+ QHash<QString, QPlace> m_places;
+ QHash<QString, QPlaceCategory> m_categories;
+ QHash<QString, QStringList> m_childCategories;
};
#endif