diff options
author | Aaron McCarthy <aaron.mccarthy@nokia.com> | 2012-01-10 11:25:41 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-01-10 05:45:57 +0100 |
commit | d203a303fb837229fab912730f899d5d24c6bc68 (patch) | |
tree | c1d3f7bafec546a640b7da28ef08f4117998fe8e /tests | |
parent | 20c1a963d5786c98a904c4c215073b74c9a112fc (diff) | |
download | qtlocation-d203a303fb837229fab912730f899d5d24c6bc68.tar.gz |
Improve unit tests for CategoryModel.
Tests fetching new categories and hierarchical property.
Change-Id: Ie9e2370dc49e65add83aa2154cd78a22ada548d9
Reviewed-by: abcd <amos.choy@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/declarative_core/tst_categorymodel.qml | 132 | ||||
-rw-r--r-- | tests/auto/geotestplugin/qplacemanagerengine_test.h | 32 |
2 files changed, 164 insertions, 0 deletions
diff --git a/tests/auto/declarative_core/tst_categorymodel.qml b/tests/auto/declarative_core/tst_categorymodel.qml index 14b3cb02..a98c5c7a 100644 --- a/tests/auto/declarative_core/tst_categorymodel.qml +++ b/tests/auto/declarative_core/tst_categorymodel.qml @@ -55,6 +55,12 @@ TestCase { Plugin { id: testPlugin name: "qmlgeo.test.plugin" + parameters: [ + PluginParameter { + name: "initializeCategories" + value: true + } + ] } function test_setAndGet_data() { @@ -91,4 +97,130 @@ TestCase { signalSpy.destroy(); } + + VisualDataModel { + id: categoryModel + + model: CategoryModel { } + delegate: Item { } + } + + function test_hierarchicalModel() { + var modelSpy = Qt.createQmlObject('import QtTest 1.0; SignalSpy {}', testCase, "SignalSpy"); + modelSpy.target = categoryModel.model; + modelSpy.signalName = "statusChanged"; + + compare(categoryModel.model.status, CategoryModel.Ready); + compare(categoryModel.count, 0); + + + // set the plugin + categoryModel.model.plugin = testPlugin; + + compare(modelSpy.count, 1); + compare(categoryModel.model.status, CategoryModel.Updating); + + wait(0); + + compare(modelSpy.count, 2); + compare(categoryModel.model.status, CategoryModel.Ready); + + var expectedNames = [ "Accommodation", "Park" ]; + + compare(categoryModel.count, expectedNames.length); + + for (var i = 0; i < expectedNames.length; ++i) { + var category = categoryModel.model.data(categoryModel.modelIndex(i), + CategoryModel.CategoryRole); + compare(category.name, expectedNames[i]); + } + + + // check that "Accommodation" has children + categoryModel.rootIndex = categoryModel.modelIndex(0); + + expectedNames = [ "Camping", "Hotel", "Motel" ]; + + compare(categoryModel.count, expectedNames.length); + + for (i = 0; i < expectedNames.length; ++i) { + category = categoryModel.model.data(categoryModel.modelIndex(i), + CategoryModel.CategoryRole); + compare(category.name, expectedNames[i]); + } + + categoryModel.rootIndex = categoryModel.parentModelIndex(); + + compare(categoryModel.count, 2); + + + // check that "Park" has no children + categoryModel.rootIndex = categoryModel.modelIndex(1); + + compare(categoryModel.count, 0); + + categoryModel.rootIndex = categoryModel.parentModelIndex(); + + + // clean up + categoryModel.model.plugin = null; + + + // check that model is empty + compare(categoryModel.count, 0); + } + + function test_flatModel() { + var modelSpy = Qt.createQmlObject('import QtTest 1.0; SignalSpy {}', testCase, "SignalSpy"); + modelSpy.target = categoryModel.model; + modelSpy.signalName = "statusChanged"; + + compare(categoryModel.model.status, CategoryModel.Ready); + compare(categoryModel.count, 0); + + + // set the plugin + categoryModel.model.hierarchical = false; + categoryModel.model.plugin = testPlugin; + + compare(modelSpy.count, 1); + compare(categoryModel.model.status, CategoryModel.Updating); + + wait(0); + + compare(modelSpy.count, 2); + compare(categoryModel.model.status, CategoryModel.Ready); + + var expectedNames = [ "Accommodation", "Camping", "Hotel", "Motel", "Park" ]; + + compare(categoryModel.count, expectedNames.length); + + for (var i = 0; i < expectedNames.length; ++i) { + var category = categoryModel.model.data(categoryModel.modelIndex(i), + CategoryModel.CategoryRole); + var name = categoryModel.model.data(categoryModel.modelIndex(i), 0); // DisplayRole + + compare(name, expectedNames[i]); + compare(category.name, expectedNames[i]); + } + + + // check that no category has children + for (i = 0; i < categoryModel.count; ++i) { + categoryModel.rootIndex = categoryModel.modelIndex(i); + + compare(categoryModel.count, 0); + + categoryModel.rootIndex = categoryModel.parentModelIndex(); + } + + + // clean up + categoryModel.model.hierarchical = true; + categoryModel.model.plugin = null; + + + // check that model is empty + compare(categoryModel.count, 0); + } } diff --git a/tests/auto/geotestplugin/qplacemanagerengine_test.h b/tests/auto/geotestplugin/qplacemanagerengine_test.h index da033231..b4e06bbb 100644 --- a/tests/auto/geotestplugin/qplacemanagerengine_test.h +++ b/tests/auto/geotestplugin/qplacemanagerengine_test.h @@ -123,6 +123,38 @@ public: : QPlaceManagerEngine(parameters) { m_locales << QLocale(); + + if (parameters.value(QLatin1String("initializeCategories"), false).toBool()) { + QPlaceCategory accommodation; + accommodation.setName(QLatin1String("Accommodation")); + accommodation.setCategoryId(QUuid::createUuid().toString()); + m_categories.insert(accommodation.categoryId(), accommodation); + m_childCategories[QString()].append(accommodation.categoryId()); + + QPlaceCategory hotel; + hotel.setName(QLatin1String("Hotel")); + hotel.setCategoryId(QUuid::createUuid().toString()); + m_categories.insert(hotel.categoryId(), hotel); + m_childCategories[accommodation.categoryId()].append(hotel.categoryId()); + + QPlaceCategory motel; + motel.setName(QLatin1String("Motel")); + motel.setCategoryId(QUuid::createUuid().toString()); + m_categories.insert(motel.categoryId(), motel); + m_childCategories[accommodation.categoryId()].append(motel.categoryId()); + + QPlaceCategory camping; + camping.setName(QLatin1String("Camping")); + camping.setCategoryId(QUuid::createUuid().toString()); + m_categories.insert(camping.categoryId(), camping); + m_childCategories[accommodation.categoryId()].append(camping.categoryId()); + + QPlaceCategory park; + park.setName(QLatin1String("Park")); + park.setCategoryId(QUuid::createUuid().toString()); + m_categories.insert(park.categoryId(), park); + m_childCategories[QString()].append(park.categoryId()); + } } QPlaceDetailsReply *getPlaceDetails(const QString &placeId) |