diff options
author | abcd <amos.choy@nokia.com> | 2012-07-04 16:46:34 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-07-12 04:48:28 +0200 |
commit | c7c6cbe48171534511306f72fd57ff5d62979e5e (patch) | |
tree | 1335b68bbe9eb17708824afd0bd0cff0526dc715 /tests/auto/declarative_core/utils.js | |
parent | 5fcd5bc9236ad21fe09f458889dbf6e3544ee134 (diff) | |
download | qtlocation-c7c6cbe48171534511306f72fd57ff5d62979e5e.tar.gz |
Expand unit tests for review model
Change-Id: I7915d8056828bc81e8c31c8e3c281cdf215f42a0
Reviewed-by: Aaron McCarthy <aaron.mccarthy@nokia.com>
Diffstat (limited to 'tests/auto/declarative_core/utils.js')
-rw-r--r-- | tests/auto/declarative_core/utils.js | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/tests/auto/declarative_core/utils.js b/tests/auto/declarative_core/utils.js index 57dcf6f3..1c8051b8 100644 --- a/tests/auto/declarative_core/utils.js +++ b/tests/auto/declarative_core/utils.js @@ -77,6 +77,116 @@ function testObjectProperties(testCase, testObject, data) { testCase.compare(testObject[data.property], data.reset); } testCase.compare(signalSpy.count, 1); + signalSpy.destroy(); +} + +function compareObj(testCase, obj1, obj2) { + for (var propertyName in obj1) { + if (obj1[propertyName] !== undefined) { + if (propertyName === "dateTime" && isNaN(obj1["dateTime"].getTime())) + testCase.verify(isNaN(obj2["dateTime"].getTime())); + else + testCase.compare(obj1[propertyName], obj2[propertyName]) + } + } +} + +function testConsecutiveFetch(testCase, model, place, expectedValues) +{ + var signalSpy = Qt.createQmlObject('import QtTest 1.0; SignalSpy {}', testCase, "SignalSpy"); + signalSpy.target = model; + signalSpy.signalName ="totalCountChanged"; + + var visDataModel = Qt.createQmlObject('import QtQuick 2.0; ' + + 'VisualDataModel{ delegate: Text{} }', + testCase, "dataModel"); + visDataModel.model = model; + + //check that initial values are as expected + testCase.compare(model.totalCount, -1); + testCase.compare(model.place, null); + testCase.compare(visDataModel.items.count, 0); + + //perform an initial fetch with the default batch size + model.place = place; + testCase.wait(1); + testCase.compare(signalSpy.count, 1); + signalSpy.clear(); + + var totalCount = model.totalCount; + testCase.compare(totalCount, 5); + testCase.compare(visDataModel.items.count, 1); + + compareObj(testCase, expectedValues[0], visDataModel.items.get(0).model); + + //set a non-default batch size and fetch the next batch + model.batchSize = 2; + visDataModel.items.create(0); //'creating' the last item will trigger a fetch + testCase.wait(1); + testCase.compare(signalSpy.count, 0); + testCase.compare(model.totalCount, totalCount); + testCase.compare(visDataModel.items.count, 3); + + compareObj(testCase, expectedValues[1], visDataModel.items.get(1).model); + compareObj(testCase, expectedValues[2], visDataModel.items.get(2).model); + + //set a batch size greater than the number of remaining items and fetch that batch + model.batchSize = 10; + visDataModel.items.create(2); + testCase.wait(1); + testCase.compare(signalSpy.count, 0); + testCase.compare(model.totalCount, totalCount); + testCase.compare(visDataModel.items.count, totalCount); + + compareObj(testCase, expectedValues[3], visDataModel.items.get(3).model); + compareObj(testCase, expectedValues[4], visDataModel.items.get(4).model); + + visDataModel.destroy(); + signalSpy.destroy(); +} + +function testReset(testCase, model, place) +{ + var dataModel = Qt.createQmlObject('import QtQuick 2.0; ' + + 'VisualDataModel{ delegate: Text{} }', + testCase, "dataModel"); + + dataModel.model = model; + model.place = place; + testCase.wait(1); + testCase.verify(model.totalCount > 0); + testCase.verify(dataModel.items.count > 0); + + model.place = null; + testCase.wait(1); + + testCase.compare(model.totalCount, -1); + testCase.compare(dataModel.items.count, 0); + + dataModel.destroy(); +} + +function testFetch(testCase, data) +{ + var model = data.model; + var visDataModel = Qt.createQmlObject('import QtQuick 2.0; ' + + 'VisualDataModel{ delegate: Text{} }', + testCase, "dataModel"); + visDataModel.model = model + + var signalSpy = Qt.createQmlObject('import QtTest 1.0; SignalSpy {}', + testCase, "SignalSpy"); + signalSpy.target = model; + signalSpy.signalName ="totalCountChanged"; + + model.batchSize = data.batchSize; + model.place = data.place; + testCase.wait(1); + testCase.compare(signalSpy.count, 1); + signalSpy.clear(); + testCase.compare(model.totalCount, data.expectedTotalCount); + testCase.compare(visDataModel.items.count, data.expectedCount); + visDataModel.destroy(); signalSpy.destroy(); } |