summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorabcd <amos.choy@nokia.com>2012-07-10 18:29:22 +1000
committerQt by Nokia <qt-info@nokia.com>2012-07-24 02:42:23 +0200
commitc3b9d42c38f3c21fbcc01e3822127bf9d7d37d06 (patch)
tree3a408f431168dfea525c40d3e56cff0d1b088f00 /tests
parent6075e23f5137f2c54eab99a86f8dabd8b782fb22 (diff)
downloadqtlocation-c3b9d42c38f3c21fbcc01e3822127bf9d7d37d06.tar.gz
Expand unit tests for image model
Change-Id: I1039b63a2d0dfb487515697eec5b54565f1e4882 Reviewed-by: Aaron McCarthy <aaron.mccarthy@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/declarative_core/tst_imagemodel.qml119
-rw-r--r--tests/auto/geotestplugin/place_data.json24
-rw-r--r--tests/auto/geotestplugin/qplacemanagerengine_test.h52
3 files changed, 190 insertions, 5 deletions
diff --git a/tests/auto/declarative_core/tst_imagemodel.qml b/tests/auto/declarative_core/tst_imagemodel.qml
index 1072e57c..aa29d773 100644
--- a/tests/auto/declarative_core/tst_imagemodel.qml
+++ b/tests/auto/declarative_core/tst_imagemodel.qml
@@ -49,6 +49,18 @@ TestCase {
name: "ImageModel"
+ Plugin {
+ id: testPlugin
+ name: "qmlgeo.test.plugin"
+ allowExperimental: true
+ parameters: [
+ PluginParameter {
+ name: "initializePlaceData"
+ value: true
+ }
+ ]
+ }
+
ImageModel {
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 expectedImages = [
+ {
+ "url": "http://somewhere.com/image1.png",
+ "imageId": "0001",
+ "mimeType": "image/png"
+ },
+ {
+ "url": "http://somewhere.com/image2.png",
+ "imageId": "0002",
+ "mimeType": "image/png"
+ },
+ {
+ "url": "http://somewhere.com/image3.png",
+ "imageId": "0003",
+ "mimeType": "image/png"
+ },
+ {
+ "url": "",
+ "imageId": "",
+ "mimeType": ""
+ },
+ {
+ "url": "http://somewhere.com/image5.png",
+ "imageId": "0005",
+ "mimeType": "image/png"
+ }
+ ]
+
+ var model = createModel();
+ Utils.testConsecutiveFetch(testCase, model, parkViewHotel, expectedImages);
+ model.destroy();
+ }
+
+ function test_reset() {
+ var model = createModel();
+ Utils.testReset(testCase, model, parkViewHotel);
+ model.destroy();
+ }
+
+ function test_fetch_data() {
+ return [
+ {
+ tag: "fetch all images in a single batch",
+ model: createModel(),
+ batchSize: 10,
+ place: parkViewHotel,
+ expectedTotalCount: 5,
+ expectedCount: 5
+ },
+ {
+ tag: "fetch from a place with no images",
+ 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; ImageModel {}',
+ testCase, "imageModel");
+ }
}
diff --git a/tests/auto/geotestplugin/place_data.json b/tests/auto/geotestplugin/place_data.json
index 1da1d19b..82f97532 100644
--- a/tests/auto/geotestplugin/place_data.json
+++ b/tests/auto/geotestplugin/place_data.json
@@ -73,6 +73,30 @@
"rating": 2.3,
"reviewId": "0005"
}
+ ],
+ "images": [
+ {
+ "url": "http://somewhere.com/image1.png",
+ "imageId": "0001",
+ "mimeType": "image/png"
+ },
+ {
+ "url": "http://somewhere.com/image2.png",
+ "imageId": "0002",
+ "mimeType": "image/png"
+ },
+ {
+ "url": "http://somewhere.com/image3.png",
+ "imageId": "0003",
+ "mimeType": "image/png"
+ },
+ {
+ },
+ {
+ "url": "http://somewhere.com/image5.png",
+ "imageId": "0005",
+ "mimeType": "image/png"
+ }
]
},
{
diff --git a/tests/auto/geotestplugin/qplacemanagerengine_test.h b/tests/auto/geotestplugin/qplacemanagerengine_test.h
index 5b36c432..a683bb80 100644
--- a/tests/auto/geotestplugin/qplacemanagerengine_test.h
+++ b/tests/auto/geotestplugin/qplacemanagerengine_test.h
@@ -56,6 +56,7 @@
#include <QtLocation/QPlaceReply>
#include <QtLocation/QPlaceDetailsReply>
#include <QtLocation/QPlaceIdReply>
+#include <QtLocation/QPlaceImage>
#include <QtLocation/QPlaceSearchSuggestionReply>
#include <QtLocation/QPlaceSearchReply>
#include <QtLocation/QPlaceResult>
@@ -300,6 +301,25 @@ public:
reviews << review;
}
m_placeReviews.insert(place.placeId(), reviews);
+
+ QJsonArray imgArray = p.value(QStringLiteral("images")).toArray();
+ QList<QPlaceImage> images;
+ for (int j = 0; j < imgArray.count(); ++j) {
+ QJsonObject imgo = imgArray.at(j).toObject();
+ QPlaceImage image;
+ if (imgo.contains(QStringLiteral("url")))
+ image.setUrl(imgo.value(QStringLiteral("url")).toString());
+
+ if (imgo.contains("imageId"))
+ image.setImageId(imgo.value(QStringLiteral("imageId")).toString());
+
+ if (imgo.contains("mimeType"))
+ image.setMimeType(imgo.value(QStringLiteral("mimeType")).toString());
+
+ images << image;
+ }
+
+ m_placeImages.insert(place.placeId(), images);
}
}
}
@@ -331,18 +351,39 @@ public:
QMetaObject::invokeMethod(reply, "emitError", Qt::QueuedConnection);
} else {
- if (query.contentType() == QPlaceContent::ReviewType) {
QPlaceContent::Collection collection;
- int totalCount = m_placeReviews.value(placeId).count();
+ int totalCount;
+ switch (query.contentType()) {
+ case QPlaceContent::ReviewType:
+ totalCount = m_placeReviews.value(placeId).count();
+ break;
+ case QPlaceContent::ImageType:
+ totalCount = m_placeImages.value(placeId).count();
+ break;
+ default:
+ //do nothing
+ break;
+ }
+
int offset = qMax(query.offset(), 0);
int max = (query.limit() == -1) ? totalCount
: qMin(offset + query.limit(), totalCount);
- for (int i = offset; i < max; ++i)
- collection.insert(i, m_placeReviews.value(placeId).at(i));
+ for (int i = offset; i < max; ++i) {
+ switch (query.contentType()) {
+ case QPlaceContent::ReviewType:
+ collection.insert(i, m_placeReviews.value(placeId).at(i));
+ break;
+ case QPlaceContent::ImageType:
+ collection.insert(i, m_placeImages.value(placeId).at(i));
+ break;
+ default:
+ //do nothing
+ break;
+ }
+ }
reply->setContent(collection);
reply->setTotalCount(totalCount);
- }
}
QMetaObject::invokeMethod(reply, "emitFinished", Qt::QueuedConnection);
@@ -614,6 +655,7 @@ private:
QHash<QString, QStringList> m_childCategories;
QHash<QString, QStringList> m_placeRecommendations;
QHash<QString, QList<QPlaceReview> > m_placeReviews;
+ QHash<QString, QList<QPlaceImage> > m_placeImages;
};
#endif