summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorabcd <amos.choy@nokia.com>2012-07-11 11:56:29 +1000
committerQt by Nokia <qt-info@nokia.com>2012-07-24 02:42:30 +0200
commitf749179d7681216a7e51cae27ca61b0010737818 (patch)
tree098d8f55e164dc08d240fbd48cbe7b44fbe81397 /tests
parentc3b9d42c38f3c21fbcc01e3822127bf9d7d37d06 (diff)
downloadqtlocation-f749179d7681216a7e51cae27ca61b0010737818.tar.gz
Expand unit tests for EditorialModel
Change-Id: I4c62370193ae9c3ade7094fd4cd8e9841d627205 Reviewed-by: Aaron McCarthy <aaron.mccarthy@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/declarative_core/tst_editorialmodel.qml119
-rw-r--r--tests/auto/geotestplugin/place_data.json24
-rw-r--r--tests/auto/geotestplugin/qplacemanagerengine_test.h27
3 files changed, 169 insertions, 1 deletions
diff --git a/tests/auto/declarative_core/tst_editorialmodel.qml b/tests/auto/declarative_core/tst_editorialmodel.qml
index 3c34e860..1f68b42c 100644
--- a/tests/auto/declarative_core/tst_editorialmodel.qml
+++ b/tests/auto/declarative_core/tst_editorialmodel.qml
@@ -49,6 +49,18 @@ TestCase {
name: "EditorialModel"
+ Plugin {
+ id: testPlugin
+ name: "qmlgeo.test.plugin"
+ allowExperimental: true
+ parameters: [
+ PluginParameter {
+ name: "initializePlaceData"
+ value: true
+ }
+ ]
+ }
+
EditorialModel {
id: testModel
}
@@ -58,6 +70,18 @@ TestCase {
name: "Test Place"
}
+ Place {
+ id: parkViewHotel
+ placeId: "4dcc74ce-fdeb-443e-827c-367438017cf1"
+ plugin: testPlugin
+ }
+
+ Place {
+ id: seaViewHotel
+ placeId: "8f72057a-54b2-4e95-a7bb-97b4d2b5721e"
+ plugin: testPlugin
+ }
+
function test_setAndGet_data() {
return [
{ tag: "place", property: "place", signal: "placeChanged", value: testPlace },
@@ -68,4 +92,99 @@ TestCase {
function test_setAndGet(data) {
Utils.testObjectProperties(testCase, testModel, data);
}
+
+ function test_consecutive_fetch() {
+ var expectedEditorials = [
+ {
+ "title": "Editorial 1",
+ "text": "Editorial 1 Text",
+ "language": "en"
+ },
+ {
+ "title": "Editorial 2",
+ "text": "Editorial 2 Text",
+ "language": "en"
+ },
+ {
+ "title": "Editorial 3",
+ "text": "Editorial 3 Text",
+ "language": "en"
+ },
+ {
+ "title": "",
+ "text": "",
+ "language": "",
+ },
+ {
+ "title": "Editorial 5",
+ "text": "Editorial 5 Text",
+ "language": "en"
+ }
+ ]
+
+ var model = createModel();
+ Utils.testConsecutiveFetch(testCase, model, parkViewHotel, expectedEditorials);
+ model.destroy();
+ }
+
+ function test_reset() {
+ var model = createModel();
+ Utils.testReset(testCase, model, parkViewHotel);
+ model.destroy();
+ }
+
+ function test_fetch_data() {
+ return [
+ {
+ tag: "fetch all editorials in a single batch",
+ model: createModel(),
+ batchSize: 10,
+ place: parkViewHotel,
+ expectedTotalCount: 5,
+ expectedCount: 5
+ },
+ {
+ tag: "fetch from a place with no editorials",
+ model: createModel(),
+ batchSize: 1,
+ place: seaViewHotel,
+ expectedTotalCount: 0,
+ expectedCount: 0
+ },
+ {
+ tag: "fetch with batch size one less than the total",
+ model: createModel(),
+ batchSize: 4,
+ place: parkViewHotel,
+ expectedTotalCount: 5,
+ expectedCount: 4
+ },
+ {
+ tag: "fetch with batch size equal to the total",
+ model: createModel(),
+ batchSize: 5,
+ place: parkViewHotel,
+ expectedTotalCount: 5,
+ expectedCount: 5
+ },
+ {
+ tag: "fetch with batch size larger than the total",
+ model: createModel(),
+ batchSize: 6,
+ place: parkViewHotel,
+ expectedTotalCount: 5,
+ expectedCount: 5
+ }
+ ]
+ }
+
+ function test_fetch(data) {
+ Utils.testFetch(testCase, data);
+ data.model.destroy();
+ }
+
+ function createModel() {
+ return Qt.createQmlObject('import QtLocation 5.0; EditorialModel {}',
+ testCase, "editorialModel");
+ }
}
diff --git a/tests/auto/geotestplugin/place_data.json b/tests/auto/geotestplugin/place_data.json
index 82f97532..20062816 100644
--- a/tests/auto/geotestplugin/place_data.json
+++ b/tests/auto/geotestplugin/place_data.json
@@ -97,6 +97,30 @@
"imageId": "0005",
"mimeType": "image/png"
}
+ ],
+ "editorials": [
+ {
+ "title": "Editorial 1",
+ "text": "Editorial 1 Text",
+ "language": "en"
+ },
+ {
+ "title": "Editorial 2",
+ "text": "Editorial 2 Text",
+ "language": "en"
+ },
+ {
+ "title": "Editorial 3",
+ "text": "Editorial 3 Text",
+ "language": "en"
+ },
+ {
+ },
+ {
+ "title": "Editorial 5",
+ "text": "Editorial 5 Text",
+ "language": "en"
+ }
]
},
{
diff --git a/tests/auto/geotestplugin/qplacemanagerengine_test.h b/tests/auto/geotestplugin/qplacemanagerengine_test.h
index a683bb80..61fd7ae1 100644
--- a/tests/auto/geotestplugin/qplacemanagerengine_test.h
+++ b/tests/auto/geotestplugin/qplacemanagerengine_test.h
@@ -55,6 +55,7 @@
#include <QtLocation/QPlaceManagerEngine>
#include <QtLocation/QPlaceReply>
#include <QtLocation/QPlaceDetailsReply>
+#include <QtLocation/QPlaceEditorial>
#include <QtLocation/QPlaceIdReply>
#include <QtLocation/QPlaceImage>
#include <QtLocation/QPlaceSearchSuggestionReply>
@@ -320,6 +321,25 @@ public:
}
m_placeImages.insert(place.placeId(), images);
+
+ QJsonArray edArray = p.value(QStringLiteral("editorials")).toArray();
+ QList<QPlaceEditorial> editorials;
+ for (int j = 0; j < edArray.count(); ++j) {
+ QJsonObject edo = edArray.at(j).toObject();
+ QPlaceEditorial editorial;
+ if (edo.contains(QStringLiteral("title")))
+ editorial.setTitle(edo.value(QStringLiteral("title")).toString());
+
+ if (edo.contains(QStringLiteral("text")))
+ editorial.setText(edo.value(QStringLiteral("text")).toString());
+
+ if (edo.contains(QStringLiteral("language")))
+ editorial.setLanguage(edo.value(QStringLiteral("language")).toString());
+
+ editorials << editorial;
+ }
+
+ m_placeEditorials.insert(place.placeId(), editorials);
}
}
}
@@ -352,7 +372,7 @@ public:
} else {
QPlaceContent::Collection collection;
- int totalCount;
+ int totalCount = 0;
switch (query.contentType()) {
case QPlaceContent::ReviewType:
totalCount = m_placeReviews.value(placeId).count();
@@ -360,6 +380,8 @@ public:
case QPlaceContent::ImageType:
totalCount = m_placeImages.value(placeId).count();
break;
+ case QPlaceContent::EditorialType:
+ totalCount = m_placeEditorials.value(placeId).count();
default:
//do nothing
break;
@@ -376,6 +398,8 @@ public:
case QPlaceContent::ImageType:
collection.insert(i, m_placeImages.value(placeId).at(i));
break;
+ case QPlaceContent::EditorialType:
+ collection.insert(i, m_placeEditorials.value(placeId).at(i));
default:
//do nothing
break;
@@ -656,6 +680,7 @@ private:
QHash<QString, QStringList> m_placeRecommendations;
QHash<QString, QList<QPlaceReview> > m_placeReviews;
QHash<QString, QList<QPlaceImage> > m_placeImages;
+ QHash<QString, QList<QPlaceEditorial> > m_placeEditorials;
};
#endif