From 32f7ffbe7307c02fce1493d43cdaf87bf0f1f1d7 Mon Sep 17 00:00:00 2001 From: Ivan Solovev Date: Wed, 27 Jan 2021 18:18:46 +0100 Subject: QtPositioning: refactor unit tests Some of the QtPositioning QML unit tests can be separated from the QtLocation tests, and run with QtPositioning and QtPositioningQuick only. This patch moves such unit tests into separate subdirectory. It also updated the tests to reflect the changes in Qt6: Since Qt6 the variant type behaves as var, so the tests that rely on the obsolete behavior need to be updated. The QGeoShape::center() method is no longer marked Q_INVOKABLE, because with updated Qt6 behavior it overrides the center properties of the child classes (like QGeoCircle or QGeoRectangle). It's marked as a read-only property instread, so that it could still be accessed from QML code. [ChangeLog][QtPositioning][QGeoShape] center is now a read-only property. The center() function is no longer a Q_INVOKABLE. Task-number: QTBUG-90491 Task-number: QTBUG-90836 Change-Id: I3c7993aa8abe1199e825d46ab19ccfb53902018f Reviewed-by: Alex Blasche --- tests/auto/CMakeLists.txt | 7 +- tests/auto/auto.pro | 8 +- tests/auto/declarative_core/BLACKLIST | 6 - tests/auto/declarative_core/declarative_core.pro | 14 - tests/auto/declarative_core/main.cpp | 48 - tests/auto/declarative_core/tst_address.qml | 88 -- tests/auto/declarative_core/tst_category.qml | 237 ----- tests/auto/declarative_core/tst_categorymodel.qml | 238 ----- tests/auto/declarative_core/tst_contactdetail.qml | 71 -- tests/auto/declarative_core/tst_coordinate.qml | 356 -------- tests/auto/declarative_core/tst_editorialmodel.qml | 186 ---- tests/auto/declarative_core/tst_geocoding.qml | 665 -------------- tests/auto/declarative_core/tst_imagemodel.qml | 186 ---- tests/auto/declarative_core/tst_place.qml | 627 ------------- tests/auto/declarative_core/tst_placeattribute.qml | 53 -- tests/auto/declarative_core/tst_placeicon.qml | 106 --- .../auto/declarative_core/tst_placesearchmodel.qml | 311 ------- .../tst_placesearchsuggestionmodel.qml | 153 ---- tests/auto/declarative_core/tst_plugin.qml | 150 ---- tests/auto/declarative_core/tst_plugin_error.qml | 61 -- tests/auto/declarative_core/tst_position.qml | 99 --- tests/auto/declarative_core/tst_positionsource.qml | 227 ----- tests/auto/declarative_core/tst_ratings.qml | 75 -- tests/auto/declarative_core/tst_reviewmodel.qml | 201 ----- tests/auto/declarative_core/tst_routing.qml | 971 --------------------- tests/auto/declarative_core/tst_supplier.qml | 100 --- tests/auto/declarative_core/tst_user.qml | 71 -- tests/auto/declarative_core/utils.js | 182 ---- .../declarative_geoshape/declarative_geoshape.pro | 11 - tests/auto/declarative_geoshape/main.cpp | 30 - .../declarative_geoshape/tst_locationsingleton.qml | 347 -------- .../declarative_location_core.pro | 14 + tests/auto/declarative_location_core/main.cpp | 48 + .../declarative_location_core/tst_category.qml | 237 +++++ .../tst_categorymodel.qml | 238 +++++ .../tst_contactdetail.qml | 71 ++ .../tst_editorialmodel.qml | 186 ++++ .../declarative_location_core/tst_geocoding.qml | 665 ++++++++++++++ .../declarative_location_core/tst_imagemodel.qml | 186 ++++ tests/auto/declarative_location_core/tst_place.qml | 627 +++++++++++++ .../tst_placeattribute.qml | 53 ++ .../declarative_location_core/tst_placeicon.qml | 106 +++ .../tst_placesearchmodel.qml | 311 +++++++ .../tst_placesearchsuggestionmodel.qml | 153 ++++ .../auto/declarative_location_core/tst_plugin.qml | 150 ++++ .../declarative_location_core/tst_plugin_error.qml | 61 ++ .../auto/declarative_location_core/tst_ratings.qml | 75 ++ .../declarative_location_core/tst_reviewmodel.qml | 201 +++++ .../auto/declarative_location_core/tst_routing.qml | 971 +++++++++++++++++++++ .../declarative_location_core/tst_supplier.qml | 100 +++ tests/auto/declarative_location_core/tst_user.qml | 71 ++ tests/auto/declarative_location_core/utils.js | 182 ++++ .../declarative_mappolyline.pro | 11 + tests/auto/declarative_mappolyline/main.cpp | 30 + .../tst_declarative_mappolyline.qml | 123 +++ tests/auto/declarative_positioning_core/BLACKLIST | 6 + .../declarative_positioning_core/CMakeLists.txt | 40 + .../declarative_positioning_core.pro | 14 + .../auto/declarative_positioning_core/factory.cpp | 50 ++ tests/auto/declarative_positioning_core/factory.h | 55 ++ tests/auto/declarative_positioning_core/main.cpp | 49 ++ .../declarative_positioning_core/tst_address.qml | 88 ++ .../tst_coordinate.qml | 365 ++++++++ .../declarative_positioning_core/tst_geoshape.qml | 300 +++++++ .../declarative_positioning_core/tst_position.qml | 99 +++ .../tst_positionsource.qml | 227 +++++ 66 files changed, 6174 insertions(+), 5874 deletions(-) delete mode 100644 tests/auto/declarative_core/BLACKLIST delete mode 100644 tests/auto/declarative_core/declarative_core.pro delete mode 100644 tests/auto/declarative_core/main.cpp delete mode 100644 tests/auto/declarative_core/tst_address.qml delete mode 100644 tests/auto/declarative_core/tst_category.qml delete mode 100644 tests/auto/declarative_core/tst_categorymodel.qml delete mode 100644 tests/auto/declarative_core/tst_contactdetail.qml delete mode 100644 tests/auto/declarative_core/tst_coordinate.qml delete mode 100644 tests/auto/declarative_core/tst_editorialmodel.qml delete mode 100644 tests/auto/declarative_core/tst_geocoding.qml delete mode 100644 tests/auto/declarative_core/tst_imagemodel.qml delete mode 100644 tests/auto/declarative_core/tst_place.qml delete mode 100644 tests/auto/declarative_core/tst_placeattribute.qml delete mode 100644 tests/auto/declarative_core/tst_placeicon.qml delete mode 100644 tests/auto/declarative_core/tst_placesearchmodel.qml delete mode 100644 tests/auto/declarative_core/tst_placesearchsuggestionmodel.qml delete mode 100644 tests/auto/declarative_core/tst_plugin.qml delete mode 100644 tests/auto/declarative_core/tst_plugin_error.qml delete mode 100644 tests/auto/declarative_core/tst_position.qml delete mode 100644 tests/auto/declarative_core/tst_positionsource.qml delete mode 100644 tests/auto/declarative_core/tst_ratings.qml delete mode 100644 tests/auto/declarative_core/tst_reviewmodel.qml delete mode 100644 tests/auto/declarative_core/tst_routing.qml delete mode 100644 tests/auto/declarative_core/tst_supplier.qml delete mode 100644 tests/auto/declarative_core/tst_user.qml delete mode 100644 tests/auto/declarative_core/utils.js delete mode 100644 tests/auto/declarative_geoshape/declarative_geoshape.pro delete mode 100644 tests/auto/declarative_geoshape/main.cpp delete mode 100644 tests/auto/declarative_geoshape/tst_locationsingleton.qml create mode 100644 tests/auto/declarative_location_core/declarative_location_core.pro create mode 100644 tests/auto/declarative_location_core/main.cpp create mode 100644 tests/auto/declarative_location_core/tst_category.qml create mode 100644 tests/auto/declarative_location_core/tst_categorymodel.qml create mode 100644 tests/auto/declarative_location_core/tst_contactdetail.qml create mode 100644 tests/auto/declarative_location_core/tst_editorialmodel.qml create mode 100644 tests/auto/declarative_location_core/tst_geocoding.qml create mode 100644 tests/auto/declarative_location_core/tst_imagemodel.qml create mode 100644 tests/auto/declarative_location_core/tst_place.qml create mode 100644 tests/auto/declarative_location_core/tst_placeattribute.qml create mode 100644 tests/auto/declarative_location_core/tst_placeicon.qml create mode 100644 tests/auto/declarative_location_core/tst_placesearchmodel.qml create mode 100644 tests/auto/declarative_location_core/tst_placesearchsuggestionmodel.qml create mode 100644 tests/auto/declarative_location_core/tst_plugin.qml create mode 100644 tests/auto/declarative_location_core/tst_plugin_error.qml create mode 100644 tests/auto/declarative_location_core/tst_ratings.qml create mode 100644 tests/auto/declarative_location_core/tst_reviewmodel.qml create mode 100644 tests/auto/declarative_location_core/tst_routing.qml create mode 100644 tests/auto/declarative_location_core/tst_supplier.qml create mode 100644 tests/auto/declarative_location_core/tst_user.qml create mode 100644 tests/auto/declarative_location_core/utils.js create mode 100644 tests/auto/declarative_mappolyline/declarative_mappolyline.pro create mode 100644 tests/auto/declarative_mappolyline/main.cpp create mode 100644 tests/auto/declarative_mappolyline/tst_declarative_mappolyline.qml create mode 100644 tests/auto/declarative_positioning_core/BLACKLIST create mode 100644 tests/auto/declarative_positioning_core/CMakeLists.txt create mode 100644 tests/auto/declarative_positioning_core/declarative_positioning_core.pro create mode 100644 tests/auto/declarative_positioning_core/factory.cpp create mode 100644 tests/auto/declarative_positioning_core/factory.h create mode 100644 tests/auto/declarative_positioning_core/main.cpp create mode 100644 tests/auto/declarative_positioning_core/tst_address.qml create mode 100644 tests/auto/declarative_positioning_core/tst_coordinate.qml create mode 100644 tests/auto/declarative_positioning_core/tst_geoshape.qml create mode 100644 tests/auto/declarative_positioning_core/tst_position.qml create mode 100644 tests/auto/declarative_positioning_core/tst_positionsource.qml (limited to 'tests') diff --git a/tests/auto/CMakeLists.txt b/tests/auto/CMakeLists.txt index 65412e06..88cbc5ac 100644 --- a/tests/auto/CMakeLists.txt +++ b/tests/auto/CMakeLists.txt @@ -66,12 +66,15 @@ add_subdirectory(qgeosatelliteinfo) # add_subdirectory(qgeotiledmap) # endif() # if(TARGET Qt::Location AND TARGET Qt::Quick AND NOT ANDROID) -# add_subdirectory(declarative_geoshape) -# add_subdirectory(declarative_core) +# add_subdirectory(declarative_mappolyline) +# add_subdirectory(declarative_location_core) # endif() # if(TARGET Qt::Location AND TARGET Qt::Quick AND NOT ANDROID AND NOT APPLE) # add_subdirectory(declarative_ui) # endif() +if(TARGET Qt::Quick AND NOT ANDROID) + add_subdirectory(declarative_positioning_core) +endif() if(NOT ANDROID) add_subdirectory(positionplugin) add_subdirectory(positionplugintest) diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index 912b6e42..c94ec618 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -70,8 +70,8 @@ qtHaveModule(location) { qgeotiledmap.depends = geotestplugin } qtHaveModule(quick):!android { - SUBDIRS += declarative_geoshape \ - declarative_core + SUBDIRS += declarative_mappolyline \ + declarative_location_core declarative_core.depends = geotestplugin !mac: { @@ -81,6 +81,10 @@ qtHaveModule(location) { } } +qtHaveModule(quick):!android { + SUBDIRS += declarative_positioning_core +} + SUBDIRS += \ doublevectors \ qgeoaddress \ diff --git a/tests/auto/declarative_core/BLACKLIST b/tests/auto/declarative_core/BLACKLIST deleted file mode 100644 index 99b4d786..00000000 --- a/tests/auto/declarative_core/BLACKLIST +++ /dev/null @@ -1,6 +0,0 @@ -# QTBUG-59074 flaky test -[CoordinateAnimation::test_west_direction_coordinate_animation] -osx -# QTBUG-59074 flaky test -[CoordinateAnimation::test_east_direction_coordinate_animation] -osx diff --git a/tests/auto/declarative_core/declarative_core.pro b/tests/auto/declarative_core/declarative_core.pro deleted file mode 100644 index 30c2b7f6..00000000 --- a/tests/auto/declarative_core/declarative_core.pro +++ /dev/null @@ -1,14 +0,0 @@ -# QML tests in this directory must not depend on an OpenGL context. -# QML tests that do require an OpenGL context must go in ../../declarative_ui. - -TEMPLATE = app -TARGET = tst_declarative_core -CONFIG += qmltestcase -SOURCES += main.cpp - -CONFIG -= app_bundle - -QT += location quick - -OTHER_FILES = *.qml *.js -TESTDATA = $$OTHER_FILES diff --git a/tests/auto/declarative_core/main.cpp b/tests/auto/declarative_core/main.cpp deleted file mode 100644 index b380a231..00000000 --- a/tests/auto/declarative_core/main.cpp +++ /dev/null @@ -1,48 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include - -static void initializeLibraryPath() -{ -#if QT_CONFIG(library) - // Set custom path since CI doesn't install test plugins -#ifdef Q_OS_WIN - QCoreApplication::addLibraryPath(QCoreApplication::applicationDirPath() + - QStringLiteral("/../../../../plugins")); -#else - QCoreApplication::addLibraryPath(QCoreApplication::applicationDirPath() + - QStringLiteral("/../../../plugins")); -#endif -#endif -} - -Q_COREAPP_STARTUP_FUNCTION(initializeLibraryPath) - -QUICK_TEST_MAIN(declarative_core) diff --git a/tests/auto/declarative_core/tst_address.qml b/tests/auto/declarative_core/tst_address.qml deleted file mode 100644 index 94f986c4..00000000 --- a/tests/auto/declarative_core/tst_address.qml +++ /dev/null @@ -1,88 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtTest 1.0 -import QtPositioning 5.2 - -TestCase { - id: testCase - - name: "Address" - - Address { - id: address - - street: "742 Evergreen Tce" - district: "Pressboard Estates" - city: "Springfield" - state: "Oregon" - postalCode: "8900" - country: "United States" - countryCode: "USA" - } - - function test_qmlAddressText() { - compare(address.isTextGenerated, true); - compare(address.text, "742 Evergreen Tce
Springfield, Oregon 8900
United States"); - var textChangedSpy = Qt.createQmlObject('import QtTest 1.0; SignalSpy {}', testCase, "SignalSpy"); - textChangedSpy.target = address; - textChangedSpy.signalName = "textChanged" - - var isTextGeneratedSpy = Qt.createQmlObject('import QtTest 1.0; SignalSpy {}', testCase, "SignalSpy"); - isTextGeneratedSpy.target = address - isTextGeneratedSpy.signalName = "isTextGeneratedChanged" - - address.countryCode = "FRA"; - compare(address.text, "742 Evergreen Tce
8900 Springfield
United States"); - compare(textChangedSpy.count, 1); - textChangedSpy.clear(); - compare(isTextGeneratedSpy.count, 0); - - address.text = "address label"; - compare(address.isTextGenerated, false); - compare(address.text, "address label"); - compare(textChangedSpy.count, 1); - textChangedSpy.clear(); - compare(isTextGeneratedSpy.count, 1); - isTextGeneratedSpy.clear(); - - address.countryCode = "USA"; - compare(address.text, "address label"); - compare(textChangedSpy.count, 0); - textChangedSpy.clear(); - compare(isTextGeneratedSpy.count, 0); - - address.text = ""; - compare(address.isTextGenerated, true); - compare(address.text, "742 Evergreen Tce
Springfield, Oregon 8900
United States"); - compare(textChangedSpy.count, 1); - textChangedSpy.clear(); - compare(isTextGeneratedSpy.count, 1); - isTextGeneratedSpy.clear(); - } -} diff --git a/tests/auto/declarative_core/tst_category.qml b/tests/auto/declarative_core/tst_category.qml deleted file mode 100644 index f0a14d6f..00000000 --- a/tests/auto/declarative_core/tst_category.qml +++ /dev/null @@ -1,237 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.0 -import QtQml.Models 2.14 -import QtTest 1.0 -import QtLocation 5.3 -import "utils.js" as Utils - -TestCase { - id: testCase - - name: "Category" - - Category { id: emptyCategory } - - function test_empty() { - compare(emptyCategory.categoryId, ""); - compare(emptyCategory.name, ""); - compare(emptyCategory.visibility, Category.UnspecifiedVisibility); - compare(emptyCategory.status, Category.Ready); - compare(emptyCategory.plugin, null); - verify(emptyCategory.icon); - } - - Category { - id: qmlCategory - - plugin: testPlugin - - categoryId: "test-category-id" - name: "Test Category" - visibility: Category.DeviceVisibility - - icon: Icon { - Component.onCompleted: { - parameters.singleUrl = "http://example.com/icons/test-category.png" - } - } - } - - function test_qmlConstructedCategory() { - compare(qmlCategory.categoryId, "test-category-id"); - compare(qmlCategory.name, "Test Category"); - compare(qmlCategory.visibility, Category.DeviceVisibility); - compare(qmlCategory.status, Category.Ready); - compare(qmlCategory.plugin, testPlugin); - verify(qmlCategory.icon); - compare(qmlCategory.icon.url(), "http://example.com/icons/test-category.png"); - compare(qmlCategory.icon.parameters.singleUrl, "http://example.com/icons/test-category.png"); - compare(qmlCategory.icon.plugin, qmlCategory.plugin); - } - - Category { - id: testCategory - } - - Plugin { - id: testPlugin - name: "qmlgeo.test.plugin" - allowExperimental: true - } - - Plugin { - id: invalidPlugin - } - - Icon { - id: testIcon - } - - Category { - id: saveCategory - - name: "Test Category" - visibility: Place.DeviceVisibility - } - - DelegateModel { - id: categoryModel - - model: CategoryModel { - plugin: testPlugin - } - delegate: Item { } - } - - function test_setAndGet_data() { - return [ - { tag: "name", property: "name", signal: "nameChanged", value: "Test Category", reset: "" }, - { tag: "categoryId", property: "categoryId", signal: "categoryIdChanged", value: "test-category-id-1", reset: "" }, - { tag: "visibility", property: "visibility", signal: "visibilityChanged", value: Place.PublicVisibility, reset: Place.UnspecifiedVisibility }, - { tag: "plugin", property: "plugin", signal: "pluginChanged", value: testPlugin }, - { tag: "icon", property: "icon", signal: "iconChanged", value: testIcon } - ]; - } - - function test_setAndGet(data) { - Utils.testObjectProperties(testCase, testCategory, data); - } - - function test_save() { - categoryModel.model.update(); - tryCompare(categoryModel.model, "status", CategoryModel.Ready); - compare(categoryModel.count, 0); - - saveCategory.plugin = testPlugin; - saveCategory.categoryId = "invalid-category-id"; - - saveCategory.save(); - - compare(saveCategory.status, Category.Saving); - verify(saveCategory.errorString().length === 0); - - tryCompare(saveCategory, "status", Category.Error); - verify(saveCategory.errorString().length > 0); - - // try again without an invalid categoryId - saveCategory.categoryId = ""; - saveCategory.save(); - - compare(saveCategory.status, Category.Saving); - - tryCompare(saveCategory, "status", Category.Ready); - verify(saveCategory.errorString().length === 0); - - verify(saveCategory.categoryId !== ""); - - - // Verify that the category was added to the model - categoryModel.model.update(); - compare(categoryModel.model.status, CategoryModel.Loading); - - tryCompare(categoryModel.model, "status", CategoryModel.Ready); - - compare(categoryModel.count, 1); - var modelCategory = categoryModel.model.data(categoryModel.modelIndex(0), - CategoryModel.CategoryRole); - compare(modelCategory.categoryId, saveCategory.categoryId); - compare(modelCategory.name, saveCategory.name); - - - // Remove a category - saveCategory.remove(); - - compare(saveCategory.status, Category.Removing); - - tryCompare(saveCategory, "status", Category.Ready); - verify(saveCategory.errorString().length === 0); - - - // Verify that the category was removed from the model - categoryModel.model.update(); - compare(categoryModel.model.status, CategoryModel.Loading); - - tryCompare(categoryModel.model, "status", CategoryModel.Ready); - - compare(categoryModel.count, 0); - - - // Try again, this time fail because category does not exist - saveCategory.remove(); - - compare(saveCategory.status, Category.Removing); - - tryCompare(saveCategory, "status", Category.Error); - - verify(saveCategory.errorString().length > 0); - } - - function test_saveWithoutPlugin() { - saveCategory.plugin = null; - saveCategory.categoryId = ""; - - saveCategory.save(); - - tryCompare(saveCategory, "status", Category.Error); - - verify(saveCategory.errorString().length > 0); - compare(saveCategory.categoryId, ""); - - saveCategory.plugin = invalidPlugin; - - saveCategory.save(); - - compare(saveCategory.status, Category.Error); - - verify(saveCategory.errorString().length > 0); - compare(saveCategory.categoryId, ""); - } - - function test_removeWithoutPlugin() { - saveCategory.plugin = null; - saveCategory.categoryId = "test-category-id"; - - saveCategory.remove(); - - compare(saveCategory.status, Category.Error); - - verify(saveCategory.errorString().length > 0); - compare(saveCategory.categoryId, "test-category-id"); - - saveCategory.plugin = invalidPlugin; - - saveCategory.remove(); - - compare(saveCategory.status, Category.Error); - - verify(saveCategory.errorString().length > 0); - compare(saveCategory.categoryId, "test-category-id"); - } -} diff --git a/tests/auto/declarative_core/tst_categorymodel.qml b/tests/auto/declarative_core/tst_categorymodel.qml deleted file mode 100644 index 59ec3e7c..00000000 --- a/tests/auto/declarative_core/tst_categorymodel.qml +++ /dev/null @@ -1,238 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.0 -import QtTest 1.0 -import QtLocation 5.3 -import "utils.js" as Utils - -TestCase { - id: testCase - - name: "CategoryModel" - - CategoryModel { - id: testModel - } - - Plugin { - id: testPlugin - name: "qmlgeo.test.plugin" - allowExperimental: true - parameters: [ - PluginParameter { - name: "initializePlaceData" - value: true - } - ] - } - - Plugin { - id: uninitializedPlugin - } - - Plugin { - id: nonExistantPlugin - name: "nonExistentName" - } - - function test_setAndGet_data() { - return [ - { tag: "plugin", property: "plugin", signal: "pluginChanged", value: testPlugin }, - { tag: "hierarchical", property: "hierarchical", signal: "hierarchicalChanged", value: false, reset: true }, - ]; - } - - function test_setAndGet(data) { - Utils.testObjectProperties(testCase, testModel, data); - } - - function test_hierarchicalModel() { - var modelSpy = Qt.createQmlObject('import QtTest 1.0; SignalSpy {}', testCase, "SignalSpy"); - var categoryModel = Qt.createQmlObject('import QtQuick 2.0; import QtQml.Models 2.14; import QtLocation 5.3;' - + 'DelegateModel { model: CategoryModel {} delegate: Item {} }', - testCase, "DelegateModel"); - - modelSpy.target = categoryModel.model; - modelSpy.signalName = "statusChanged"; - - compare(categoryModel.model.status, CategoryModel.Null); - compare(categoryModel.count, 0); - - - // set the plugin - categoryModel.model.plugin = testPlugin; - categoryModel.model.update(); - tryCompare(categoryModel.model, "status", CategoryModel.Loading); - compare(modelSpy.count, 1); - - tryCompare(categoryModel.model, "status", CategoryModel.Ready); - compare(modelSpy.count, 2); - compare(categoryModel.model.errorString(), ""); - - 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]); - - var parentCategory = categoryModel.model.data(categoryModel.modelIndex(i), - CategoryModel.ParentCategoryRole); - compare(parentCategory.name, "Accommodation"); - } - - 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; - categoryModel.model.update(); - - // check that the model is empty when an error is encountered - tryCompare(categoryModel, "count", 0); - compare(categoryModel.model.status, CategoryModel.Error); - } - - function test_flatModel() { - var modelSpy = Qt.createQmlObject('import QtTest 1.0; SignalSpy {}', testCase, "SignalSpy"); - var categoryModel = Qt.createQmlObject('import QtQuick 2.0; import QtQml.Models 2.14; import QtLocation 5.3;' - + 'DelegateModel { model: CategoryModel {} delegate: Item {} }', - testCase, "DelegateModel"); - - modelSpy.target = categoryModel.model; - modelSpy.signalName = "statusChanged"; - - compare(categoryModel.model.status, CategoryModel.Null); - compare(categoryModel.count, 0); - - - // set the plugin - categoryModel.model.hierarchical = false; - categoryModel.model.plugin = testPlugin; - - categoryModel.model.update(); - tryCompare(categoryModel.model, "status", CategoryModel.Loading); - compare(modelSpy.count, 1); - - tryCompare(categoryModel.model, "status", CategoryModel.Ready); - compare(modelSpy.count, 2); - - 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 the model is empty when an error is encountered - categoryModel.model.update(); - tryCompare(categoryModel, "count", 0); - compare(categoryModel.model.status, CategoryModel.Error); - } - - function test_error() { - var testModel = Qt.createQmlObject('import QtLocation 5.3; CategoryModel {}', testCase, "CategoryModel"); - - var statusChangedSpy = Qt.createQmlObject('import QtTest 1.0; SignalSpy {}', testCase, "SignalSpy"); - statusChangedSpy.target = testModel; - statusChangedSpy.signalName = "statusChanged"; - - //try updating without a plugin instance - testModel.update(); - tryCompare(statusChangedSpy, "count", 2); - compare(testModel.status, CategoryModel.Error); - statusChangedSpy.clear(); - //Aside: there is some difficulty in checking the transition to the Loading state - //since the model transitions from Loading to Error before the next event loop - //iteration. - - //try updating with an uninitialized plugin instance. - testModel.plugin = uninitializedPlugin; // uninitialized does not trigger update on setPlugin - testModel.update(); - tryCompare(statusChangedSpy, "count", 2); - compare(testModel.status, CategoryModel.Error); - statusChangedSpy.clear(); - - //try searching with plugin a instance - //that has been provided a non-existent name - tryCompare(statusChangedSpy, "count", 0); - testModel.plugin = nonExistantPlugin; -// testModel.update(); //QTBUG-70254 - tryCompare(statusChangedSpy, "count", 2); - compare(testModel.status, CategoryModel.Error); - } -} diff --git a/tests/auto/declarative_core/tst_contactdetail.qml b/tests/auto/declarative_core/tst_contactdetail.qml deleted file mode 100644 index a91c19fa..00000000 --- a/tests/auto/declarative_core/tst_contactdetail.qml +++ /dev/null @@ -1,71 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtTest 1.0 -import QtLocation 5.3 -import "utils.js" as Utils - -TestCase { - id: testCase - - name: "ContactDetail" - - ContactDetail { id: emptyContactDetail } - - function test_empty() { - compare(emptyContactDetail.label, ""); - compare(emptyContactDetail.value, ""); - } - - ContactDetail { - id: qmlContactDetail - - label: "Phone" - value: "12345" - } - - function test_qmlConstructedContactDetail() { - compare(qmlContactDetail.label, "Phone"); - compare(qmlContactDetail.value, "12345"); - } - - ContactDetail { - id: testContactDetail - } - - function test_setAndGet_data() { - return [ - { tag: "label", property: "label", signal: "labelChanged", value: "Phone", reset: "" }, - { tag: "value", property: "value", signal: "valueChanged", value: "12345", reset: "" }, - ]; - } - - function test_setAndGet(data) { - Utils.testObjectProperties(testCase, testContactDetail, data); - } -} diff --git a/tests/auto/declarative_core/tst_coordinate.qml b/tests/auto/declarative_core/tst_coordinate.qml deleted file mode 100644 index 9cb37195..00000000 --- a/tests/auto/declarative_core/tst_coordinate.qml +++ /dev/null @@ -1,356 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.0 -import QtTest 1.0 -import QtPositioning 5.5 - -Item { - id: item - - property variant empty: QtPositioning.coordinate() - property variant base: QtPositioning.coordinate(1.0, 1.0, 5.0) - property variant zero: QtPositioning.coordinate(0, 0) - property variant plusone: QtPositioning.coordinate(0, 1) - property variant minusone: QtPositioning.coordinate(0, -1) - property variant north: QtPositioning.coordinate(3, 0) - - SignalSpy { id: coordSpy; target: item; signalName: "baseChanged" } - - property variant inside: QtPositioning.coordinate(0.5, 0.5) - property variant outside: QtPositioning.coordinate(2, 2) - property variant tl: QtPositioning.coordinate(1, 0) - property variant br: QtPositioning.coordinate(0, 1) - property variant box: QtPositioning.rectangle(tl, br) - - - Address { - id: validTestAddress - street: "53 Brandl St" - city: "Eight Mile Plains" - country: "Australia" - countryCode: "AUS" - } - - Location { - id: testLocation - coordinate: inside - boundingBox: box - address: validTestAddress - } - - Location { - id: invalidLocation - } - - - Item { - id: coordinateItem - property variant coordinate - property int animationDuration: 100 - property var coordinateList: [] - property int coordinateCount: 0 - - CoordinateAnimation { - id: coordinateAnimation - target: coordinateItem - property: "coordinate" - duration: coordinateItem.animationDuration - } - onCoordinateChanged: { - if (!coordinateList) { - coordinateList = [] - } - coordinateList[coordinateCount] = QtPositioning.coordinate(coordinate.latitude,coordinate.longitude) - coordinateCount++ - } - - SignalSpy { id: coordinateAnimationStartSpy; target: coordinateAnimation; signalName: "started" } - SignalSpy { id: coordinateAnimationStopSpy; target: coordinateAnimation; signalName: "stopped" } - SignalSpy { id: coordinateAnimationDirectionSpy; target: coordinateAnimation; signalName: "directionChanged" } - } - - TestCase { - name: "GeoLocation" - - function test_Location_complete() - { - compare (testLocation.coordinate.longitude, inside.longitude) - compare (testLocation.coordinate.latitude, inside.latitude) - - compare (testLocation.boundingBox.contains(inside), true) - compare (testLocation.boundingBox.contains(outside), false) - compare (testLocation.boundingBox.bottomRight.longitude, br.longitude) - compare (testLocation.boundingBox.bottomRight.latitude, br.latitude) - compare (testLocation.boundingBox.topLeft.longitude, tl.longitude) - compare (testLocation.boundingBox.topLeft.latitude, tl.latitude) - - compare (testLocation.address.country, "Australia") - compare (testLocation.address.countryCode, "AUS") - compare (testLocation.address.city, "Eight Mile Plains") - compare (testLocation.address.street, "53 Brandl St") - } - - function test_Location_invalid() - { - compare(invalidLocation.coordinate.isValid, false) - compare(invalidLocation.boundingBox.isEmpty, true) - compare(invalidLocation.boundingBox.isValid, false) - compare(invalidLocation.address.city, "") - } - } - - TestCase { - name: "Coordinate" - - function test_validity() - { - compare(empty.isValid, false) - - empty.longitude = 0.0; - empty.latitude = 0.0; - - compare(empty.isValid, true) - } - - function test_accessors() - { - compare(base.longitude, 1.0) - compare(base.latitude, 1.0) - compare(base.altitude, 5.0) - - coordSpy.clear(); - - base.longitude = 2.0; - base.latitude = 3.0; - base.altitude = 6.0; - - compare(base.longitude, 2.0) - compare(base.latitude, 3.0) - compare(base.altitude, 6.0) - compare(coordSpy.count, 3) - } - - function test_comparison_data() - { - return [ - { tag: "empty", coord1: empty, coord2: QtPositioning.coordinate(), result: true }, - { tag: "zero", coord1: zero, coord2: QtPositioning.coordinate(0, 0), result: true }, - { tag: "plusone", coord1: plusone, coord2: QtPositioning.coordinate(0, 1), result: true }, - { tag: "minusone", coord1: minusone, coord2: QtPositioning.coordinate(0, -1), result: true }, - { tag: "north", coord1: north, coord2: QtPositioning.coordinate(3, 0), result: true }, - { tag: "lat,long.alt", coord1: QtPositioning.coordinate(1.1, 2.2, 3.3), coord2: QtPositioning.coordinate(1.1, 2.2, 3.3), result: true }, - { tag: "not equal1", coord1: plusone, coord2: minusone, result: false }, - { tag: "not equal2", coord1: plusone, coord2: north, result: false } - ] - } - - function test_comparison(data) - { - compare(data.coord1 === data.coord2, data.result) - compare(data.coord1 !== data.coord2, !data.result) - compare(data.coord1 == data.coord2, data.result) - compare(data.coord1 != data.coord2, !data.result) - } - - function test_distance() - { - compare(zero.distanceTo(plusone), zero.distanceTo(minusone)) - compare(2*plusone.distanceTo(zero), plusone.distanceTo(minusone)) - compare(zero.distanceTo(plusone) > 0, true) - } - - function test_azimuth() - { - compare(zero.azimuthTo(north), 0) - compare(zero.azimuthTo(plusone), 90) - compare(zero.azimuthTo(minusone), 270) - compare(minusone.azimuthTo(plusone), 360 - plusone.azimuthTo(minusone)) - } - - function test_atDistanceAndAzimuth() - { - // 112km is approximately one degree of arc - - var coord_0d = zero.atDistanceAndAzimuth(112000, 0) - compare(coord_0d.latitude > 0.95, true) - compare(coord_0d.latitude < 1.05, true) - compare(coord_0d.longitude < 0.05, true) - compare(coord_0d.longitude > -0.05, true) - compare(zero.distanceTo(coord_0d), 112000) - compare(zero.azimuthTo(coord_0d), 0) - - var coord_90d = zero.atDistanceAndAzimuth(112000, 90) - compare(coord_90d.longitude > 0.95, true) - compare(coord_90d.longitude < 1.05, true) - compare(coord_90d.latitude < 0.05, true) - compare(coord_90d.latitude > -0.05, true) - compare(zero.distanceTo(coord_90d), 112000) - compare(zero.azimuthTo(coord_90d), 90) - - var coord_30d = zero.atDistanceAndAzimuth(20000, 30) - compare(coord_30d.longitude > 0, true) - compare(coord_30d.latitude > 0, true) - compare(zero.distanceTo(coord_30d), 20000) - compare(zero.azimuthTo(coord_30d), 30) - - var coord_30d2 = coord_30d.atDistanceAndAzimuth(200, 30) - compare(zero.distanceTo(coord_30d2), 20200) - } - } - - TestCase { - name: "CoordinateAnimation" - - function init() - { - coordinateAnimation.stop() - coordinateAnimationStartSpy.clear() - coordinateAnimationStopSpy.clear() - coordinateAnimationDirectionSpy.clear() - coordinateAnimation.from = QtPositioning.coordinate(50,50) - coordinateAnimation.to = QtPositioning.coordinate(50,50) - coordinateAnimation.direction = CoordinateAnimation.Shortest - coordinateItem.coordinate = QtPositioning.coordinate(50,50) - coordinateItem.coordinateList = [] - coordinateItem.coordinateCount = 0 - } - - function initTestCase() - { - compare(coordinateAnimation.direction, CoordinateAnimation.Shortest) - compare(coordinateAnimationDirectionSpy.count,0) - coordinateAnimation.direction = CoordinateAnimation.Shortest - compare(coordinateAnimationDirectionSpy.count,0) - coordinateAnimation.direction = CoordinateAnimation.West - compare(coordinateAnimationDirectionSpy.count,1) - coordinateAnimation.direction = CoordinateAnimation.East - compare(coordinateAnimationDirectionSpy.count,2) - } - - function toMercator(coord) - { - var p = QtPositioning.coordToMercator(coord) - var lat = p.y - var lon = p.x - return {'latitude': lat, 'longitude': lon}; - } - - function coordinate_animation(from, to, movingEast) - { - var fromMerc = toMercator(from) - var toMerc = toMercator(to) - var delta = (toMerc.latitude - fromMerc.latitude) / (toMerc.longitude - fromMerc.longitude) - - compare(coordinateItem.coordinateList.length, 0); - coordinateAnimation.from = from - coordinateAnimation.to = to - coordinateAnimation.start() - tryCompare(coordinateAnimationStartSpy,"count",1) - tryCompare(coordinateAnimationStopSpy,"count",1) - - //check correct start position - verify(coordinateItem.coordinateList.length != 0) - compare(coordinateItem.coordinateList[0], from) - //check correct end position - compare(coordinateItem.coordinateList[coordinateItem.coordinateList.length - 1],to) - - var i - var lastLongitude - for (i in coordinateItem.coordinateList) { - var coordinate = coordinateItem.coordinateList[i] - var mercCoordinate = toMercator(coordinate) - - //check that coordinates from the animation is along a straight line between from and to - var estimatedLatitude = fromMerc.latitude + (mercCoordinate.longitude - fromMerc.longitude) * delta - verify(mercCoordinate.latitude - estimatedLatitude < 0.00000000001); - - //check that each step has moved in the right direction - - if (lastLongitude) { - var errorMessage = "movingEast: " + movingEast + "; From: " + from + "; To: " + to + "; i: " + i + "; crdList: " + coordinateItem.coordinateList - if (movingEast) { - if (coordinate.longitude > 0 && lastLongitude < 0) - verify(coordinate.longitude < lastLongitude + 360, errorMessage) - else - verify(coordinate.longitude < lastLongitude, errorMessage) - } else { - if (coordinate.longitude < 0 && lastLongitude > 0) - verify(coordinate.longitude + 360 > lastLongitude, errorMessage) - else - verify(coordinate.longitude > lastLongitude, errorMessage) - } - } - lastLongitude = coordinate.longitude - } - } - - function test_default_coordinate_animation() - { - //shortest - coordinate_animation(QtPositioning.coordinate(58.0,12.0), - QtPositioning.coordinate(62.0,24.0), - false) - } - - function test_east_direction_coordinate_animation(data) - { - coordinateAnimation.direction = CoordinateAnimation.East - coordinate_animation(data.from, - data.to, - true) - } - - function test_east_direction_coordinate_animation_data() - { - return [ - { from: QtPositioning.coordinate(58.0,24.0), to: QtPositioning.coordinate(58.0,12.0) }, - { from: QtPositioning.coordinate(58.0,12.0), to: QtPositioning.coordinate(58.0,24.0) }, - ] - } - - - function test_west_direction_coordinate_animation(data) - { - coordinateAnimation.direction = CoordinateAnimation.West - coordinate_animation(data.from, - data.to, - false) - } - - function test_west_direction_coordinate_animation_data() - { - return [ - { from: QtPositioning.coordinate(58.0,24.0),to: QtPositioning.coordinate(58.0,12.0) }, - { from: QtPositioning.coordinate(58.0,12.0),to: QtPositioning.coordinate(58.0,24.0) }, - ] - } - - - } -} diff --git a/tests/auto/declarative_core/tst_editorialmodel.qml b/tests/auto/declarative_core/tst_editorialmodel.qml deleted file mode 100644 index 4cb38e5e..00000000 --- a/tests/auto/declarative_core/tst_editorialmodel.qml +++ /dev/null @@ -1,186 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.0 -import QtTest 1.0 -import QtLocation 5.3 -import "utils.js" as Utils - -TestCase { - id: testCase - - name: "EditorialModel" - - Plugin { - id: testPlugin - name: "qmlgeo.test.plugin" - allowExperimental: true - parameters: [ - PluginParameter { - name: "initializePlaceData" - value: true - } - ] - } - - EditorialModel { - id: testModel - } - - Place { - id: testPlace - 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 }, - { tag: "batchSize", property: "batchSize", signal: "batchSizeChanged", value: 10, reset: 1 }, - ]; - } - - function test_setAndGet(data) { - Utils.testObjectProperties(testCase, testModel, data); - } - - function test_consecutive_fetch_data() { - return [ - { tag: "batchSize 1", batchSize: 1 }, - { tag: "batchSize 2", batchSize: 2 }, - { tag: "batchSize 5", batchSize: 5 }, - { tag: "batchSize 10", batchSize: 10 }, - ]; - } - - function test_consecutive_fetch(data) { - 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, data); - 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.3; EditorialModel {}', - testCase, "editorialModel"); - } -} diff --git a/tests/auto/declarative_core/tst_geocoding.qml b/tests/auto/declarative_core/tst_geocoding.qml deleted file mode 100644 index 16843528..00000000 --- a/tests/auto/declarative_core/tst_geocoding.qml +++ /dev/null @@ -1,665 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.0 -import QtTest 1.0 -import QtLocation 5.3 -import QtPositioning 5.2 - -Item { - Plugin { id: testPlugin1; name: "qmlgeo.test.plugin"; allowExperimental: true} - Plugin { id: errorPlugin; name: "qmlgeo.test.plugin"; allowExperimental: true - parameters: [ - PluginParameter { name: "error"; value: "1"}, - PluginParameter { name: "errorString"; value: "This error was expected. No worries !"} - ] - } - - - property variant coordinate1: QtPositioning.coordinate(51, 41) - property variant coordinate2: QtPositioning.coordinate(52, 42) - property variant coordinate3: QtPositioning.coordinate(53, 43) - property variant emptyCoordinate: QtPositioning.coordinate() - - property variant boundingBox1: QtPositioning.rectangle(coordinate1, coordinate2) - property variant boundingBox2: QtPositioning.rectangle(coordinate1, coordinate3) - property variant boundingCircle1: QtPositioning.circle(coordinate1, 100) - property variant boundingCircle2: QtPositioning.circle(coordinate2, 100) - - property variant emptyBox: QtPositioning.rectangle() - - GeocodeModel {id: emptyModel} - - Address {id: emptyAddress} - SignalSpy {id: querySpy; target: emptyModel; signalName: "queryChanged"} - SignalSpy {id: autoUpdateSpy; target: emptyModel; signalName: "autoUpdateChanged"} - SignalSpy {id: pluginSpy; target: emptyModel ; signalName: "pluginChanged"} - SignalSpy {id: boundsSpy; target: emptyModel; signalName: "boundsChanged"} - SignalSpy {id: limitSpy; target: emptyModel; signalName: "limitChanged"} - SignalSpy {id: offsetSpy; target: emptyModel; signalName: "offsetChanged"} - - TestCase { - id: testCase1 - name: "GeocodeModel" - function test_model_defaults_and_setters() { - // Query: address - compare (querySpy.count, 0) - emptyModel.query = address1 - compare (querySpy.count, 1) - compare (emptyModel.query.street, address1.street) - emptyModel.query = address1 - compare (querySpy.count, 1) - compare (emptyModel.query.street, address1.street) - // Query: coordinate - emptyModel.query = coordinate1 - compare (querySpy.count, 2) - compare (emptyModel.query.latitude, coordinate1.latitude) - emptyModel.query = coordinate1 - compare (querySpy.count, 2) - compare (emptyModel.query.latitude, coordinate1.latitude) - // Query: string - emptyModel.query = "Kuortane, Finland" - compare (querySpy.count, 3) - compare (emptyModel.query, "Kuortane, Finland") - emptyModel.query = "Kuortane, Finland" - compare (querySpy.count, 3) - compare (emptyModel.query, "Kuortane, Finland") - - // limit and offset - compare (limitSpy.count, 0) - compare (offsetSpy.count, 0) - compare(emptyModel.limit, -1) - compare(emptyModel.offset, 0) - emptyModel.limit = 2 - compare (limitSpy.count, 1) - emptyModel.limit = 2 - compare (limitSpy.count, 1) - emptyModel.offset = 10 - compare (offsetSpy.count, 1) - emptyModel.offset = 10 - compare (offsetSpy.count, 1) - - // bounding box - compare(boundsSpy.count, 0) - emptyModel.bounds = boundingBox1 - compare(boundsSpy.count, 1) - compare(emptyModel.bounds.topLeft.latitude, boundingBox1.topLeft.latitude) - compare(emptyModel.bounds.bottomRight.longitude, boundingBox1.bottomRight.longitude) - emptyModel.bounds = boundingBox1 - compare(boundsSpy.count, 1) - compare(emptyModel.bounds.topLeft.latitude, boundingBox1.topLeft.latitude) - compare(emptyModel.bounds.bottomRight.longitude, boundingBox1.bottomRight.longitude) - emptyModel.bounds = boundingBox2 - compare(boundsSpy.count, 2) - compare(emptyModel.bounds.topLeft.latitude, boundingBox2.topLeft.latitude) - compare(emptyModel.bounds.bottomRight.longitude, boundingBox2.bottomRight.longitude) - emptyModel.bounds = QtPositioning.rectangle(); - compare(boundsSpy.count, 3) - - - // bounding circle - boundsSpy.clear() - emptyModel.bounds = boundingCircle1 - compare(boundsSpy.count, 1) - compare(emptyModel.bounds.center.latitude, coordinate1.latitude) - emptyModel.bounds = boundingCircle1 - compare(boundsSpy.count, 1) - compare(emptyModel.bounds.center.latitude, coordinate1.latitude) - emptyModel.bounds = boundingCircle2 - compare(boundsSpy.count, 2) - compare(emptyModel.bounds.center.latitude, coordinate2.latitude) - var dynamicCircle = QtPositioning.circle(QtPositioning.coordinate(8, 9)); - emptyModel.bounds = dynamicCircle - compare(boundsSpy.count, 3) - compare(emptyModel.bounds.center.latitude, dynamicCircle.center.latitude) - - // status - compare (emptyModel.status, GeocodeModel.Null) - - // error - compare (emptyModel.errorString, "") - compare (emptyModel.error, GeocodeModel.NoError) - - // count - compare( emptyModel.count, 0) - - // auto update - compare (autoUpdateSpy.count, 0) - compare (emptyModel.autoUpdate, false) - emptyModel.autoUpdate = true - compare (emptyModel.autoUpdate, true) - compare (autoUpdateSpy.count, 1) - emptyModel.autoUpdate = true - compare (emptyModel.autoUpdate, true) - compare (autoUpdateSpy.count, 1) - - // mustn't crash even we don't have plugin - emptyModel.update() - - // Plugin - compare(pluginSpy.count, 0) - emptyModel.plugin = testPlugin1 - compare(pluginSpy.count, 1) - compare(emptyModel.plugin, testPlugin1) - emptyModel.plugin = testPlugin1 - compare(pluginSpy.count, 1) - emptyModel.plugin = errorPlugin - compare(pluginSpy.count, 2) - } - // Test that model acts gracefully when plugin is not set or is invalid - // (does not support geocoding) - GeocodeModel {id: errorModel; plugin: errorPlugin} - GeocodeModel {id: errorModelNoPlugin} - SignalSpy {id: countInvalidSpy; target: errorModel; signalName: "countChanged"} - SignalSpy {id: errorSpy; target: errorModel; signalName: "errorChanged"} - function test_error_plugin() { - // test plugin not set - compare(errorModelNoPlugin.error,GeocodeModel.NoError) - errorModelNoPlugin.update() - compare(errorModelNoPlugin.error,GeocodeModel.EngineNotSetError) - console.log(errorModelNoPlugin.errorString) - - //plugin set but otherwise not offering anything - compare(errorModel.error,GeocodeModel.EngineNotSetError) - compare(errorModel.errorString,"This error was expected. No worries !") - errorSpy.clear() - errorModel.update() - compare(errorModel.error,GeocodeModel.EngineNotSetError) - compare(errorModel.errorString,qsTr("Cannot geocode, geocode manager not set.")) - compare(errorSpy.count, 1) - errorSpy.clear() - errorModel.cancel() - compare(errorModel.error,GeocodeModel.NoError) - compare(errorModel.errorString,"") - compare(errorSpy.count, 1) - errorSpy.clear() - errorModel.reset() - compare(errorModel.error,GeocodeModel.NoError) - compare(errorModel.errorString,"") - compare(errorSpy.count, 0) - errorSpy.clear() - errorModel.update() - compare(errorModel.error,GeocodeModel.EngineNotSetError) - compare(errorModel.errorString,qsTr("Cannot geocode, geocode manager not set.")) - compare(errorSpy.count, 1) - errorSpy.clear() - var location = errorModel.get(-1) - compare(location, null) - } - - } - Address {id: address1; street: "wellknown street"; city: "expected city"; county: "2"} - Address {id: errorAddress1; street: "error"; county: "2"} // street is the error reason - - property variant rcoordinate1: QtPositioning.coordinate(51, 2) - property variant errorCoordinate1: QtPositioning.coordinate(73, 2) // (latiude mod 70) is the error code - property variant slackCoordinate1: QtPositioning.coordinate(60, 3) - Address {id: slackAddress1; street: "Slacker st"; city: "Lazy town"; county: "4"} - - property variant automaticCoordinate1: QtPositioning.coordinate(60, 3) - Address {id: automaticAddress1; street: "Auto st"; city: "Detroit"; county: "4"} - - Plugin { - id: testPlugin2; - name: "qmlgeo.test.plugin" - allowExperimental: true - parameters: [ - // Parms to guide the test plugin - PluginParameter { name: "supported"; value: true}, - PluginParameter { name: "finishRequestImmediately"; value: true}, - PluginParameter { name: "validateWellKnownValues"; value: true} - ] - } - - Plugin { - id: immediatePlugin; - name: "qmlgeo.test.plugin" - allowExperimental: true - parameters: [ - // Parms to guide the test plugin - PluginParameter { name: "supported"; value: true}, - PluginParameter { name: "finishRequestImmediately"; value: true}, - PluginParameter { name: "validateWellKnownValues"; value: false} - ] - } - - Plugin { - id: slackPlugin; - allowExperimental: true - name: "qmlgeo.test.plugin" - parameters: [ - // Parms to guide the test plugin - PluginParameter { name: "supported"; value: true}, - PluginParameter { name: "finishRequestImmediately"; value: false}, - PluginParameter { name: "validateWellKnownValues"; value: false} - ] - } - - Plugin { - id: autoPlugin; - allowExperimental: true - name: "qmlgeo.test.plugin" - parameters: [ - // Parms to guide the test plugin - PluginParameter { name: "supported"; value: true}, - PluginParameter { name: "finishRequestImmediately"; value: false}, - PluginParameter { name: "validateWellKnownValues"; value: false} - ] - } - - Plugin { - id: extendedPlugin; - name: "qmlgeo.test.plugin"; - allowExperimental: true - PluginParameter { name: "finishRequestImmediately"; value: false} - PluginParameter { name: "includeExtendedData"; value: true } - } - - GeocodeModel {id: testModel; plugin: testPlugin2} - SignalSpy {id: locationsSpy; target: testModel; signalName: "locationsChanged"} - SignalSpy {id: countSpy; target: testModel; signalName: "countChanged"} - SignalSpy {id: testQuerySpy; target: testModel; signalName: "queryChanged"} - SignalSpy {id: testStatusSpy; target: testModel; signalName: "statusChanged"} - - GeocodeModel {id: slackModel; plugin: slackPlugin; } - SignalSpy {id: locationsSlackSpy; target: slackModel; signalName: "locationsChanged"} - SignalSpy {id: countSlackSpy; target: slackModel; signalName: "countChanged"} - SignalSpy {id: querySlackSpy; target: slackModel; signalName: "queryChanged"} - SignalSpy {id: errorStringSlackSpy; target: slackModel; signalName: "errorChanged"} - SignalSpy {id: errorSlackSpy; target: slackModel; signalName: "errorChanged"} - SignalSpy {id: pluginSlackSpy; target: slackModel; signalName: "pluginChanged"} - - GeocodeModel {id: immediateModel; plugin: immediatePlugin} - SignalSpy {id: locationsImmediateSpy; target: immediateModel; signalName: "locationsChanged"} - SignalSpy {id: countImmediateSpy; target: immediateModel; signalName: "countChanged"} - SignalSpy {id: queryImmediateSpy; target: immediateModel; signalName: "queryChanged"} - SignalSpy {id: statusImmediateSpy; target: immediateModel; signalName: "statusChanged"} - SignalSpy {id: errorStringImmediateSpy; target: immediateModel; signalName: "errorChanged"} - SignalSpy {id: errorImmediateSpy; target: immediateModel; signalName: "errorChanged"} - - GeocodeModel {id: automaticModel; plugin: autoPlugin; query: automaticAddress1; autoUpdate: true} - SignalSpy {id: automaticLocationsSpy; target: automaticModel; signalName: "locationsChanged"} - - GeocodeModel {id: extendedModel; plugin: extendedPlugin; query: automaticAddress1; autoUpdate: true} - SignalSpy {id: extendedLocationsSpy; target: extendedModel; signalName: "locationsChanged"} - - TestCase { - name: "GeocodeModelGeocoding" - function clear_slack_model() { - slackModel.reset() - locationsSlackSpy.clear() - countSlackSpy.clear() - querySlackSpy.clear() - errorStringSlackSpy.clear() - errorSlackSpy.clear() - slackModel.limit = -1 - slackModel.offset = 0 - } - function clear_immediate_model() { - immediateModel.reset() - locationsImmediateSpy.clear() - countImmediateSpy.clear() - queryImmediateSpy.clear() - errorStringImmediateSpy.clear() - errorImmediateSpy.clear() - statusImmediateSpy.clear() - immediateModel.limit = -1 - immediateModel.offset = 0 - } - function test_reset() { - clear_immediate_model(); - immediateModel.query = errorAddress1 - immediateModel.update() - compare (immediateModel.errorString, errorAddress1.street) - compare (immediateModel.error, GeocodeModel.CommunicationError) - compare (immediateModel.count, 0) - compare (statusImmediateSpy.count, 2) - compare (immediateModel.status, GeocodeModel.Error) - immediateModel.reset() - compare (immediateModel.errorString, "") - compare (immediateModel.error, GeocodeModel.NoError) - compare (immediateModel.status, GeocodeModel.Null) - // Check that ongoing req is aborted - clear_slack_model() - slackModel.query = slackAddress1 - slackAddress1.county = "5" - slackModel.update() - tryCompare(countSlackSpy, "count", 0) - compare (locationsSlackSpy.count, 0) - compare (slackModel.count, 0) - slackModel.reset() - tryCompare(countSlackSpy, "count", 0) - compare (locationsSlackSpy.count, 0) - compare (slackModel.count, 0) - // Check that results are cleared - slackModel.update() - tryCompare(slackModel, "count", 5) - slackModel.reset() - compare (slackModel.count, 0) - // Check that changing plugin resets any ongoing requests - clear_slack_model() - slackModel.query = slackAddress1 - slackAddress1.county = "7" - compare (pluginSlackSpy.count, 0) - slackModel.update() - tryCompare(countSlackSpy, "count", 0) - slackModel.plugin = errorPlugin - tryCompare(countSlackSpy, "count", 0) - compare (pluginSlackSpy.count, 1) - // switch back and check that works - slackModel.plugin = slackPlugin - compare (pluginSlackSpy.count, 2) - slackModel.update() - tryCompare(countSlackSpy, "count", 0) - tryCompare(countSlackSpy, "count", 1) - } - function test_error_geocode() { - // basic immediate geocode error - clear_immediate_model() - immediateModel.query = errorAddress1 - immediateModel.update() - compare (errorStringImmediateSpy.count, 1) - compare (immediateModel.errorString, errorAddress1.street) - compare (immediateModel.error, GeocodeModel.CommunicationError) // county of the address (2) - compare (immediateModel.count, 0) - compare (statusImmediateSpy.count, 2) - compare (immediateModel.status, GeocodeModel.Error) - // basic delayed geocode error - clear_slack_model() - slackModel.query = errorAddress1 - errorAddress1.street = "error code 2" - slackModel.update() - compare (errorStringSlackSpy.count, 0) - compare (errorSlackSpy.count, 0) - tryCompare (errorStringSlackSpy, "count", 1) - tryCompare (errorSlackSpy, "count", 1) - compare (slackModel.errorString, errorAddress1.street) - compare (slackModel.error, GeocodeModel.CommunicationError) - compare (slackModel.count, 0) - // Check that we recover - slackModel.query = address1 - slackModel.update() - tryCompare(countSlackSpy, "count", 1) - compare (slackModel.count, 2) - compare (errorStringSlackSpy.count, 2) - compare (errorSlackSpy.count, 2) - compare (slackModel.errorString, "") - compare (slackModel.error, GeocodeModel.NoError) - } - - function test_error_reverse_geocode() { - // basic immediate geocode error - clear_immediate_model() - immediateModel.query = errorCoordinate1 - immediateModel.update() - if (immediateModel.errorString != "") - compare (errorStringImmediateSpy.count, 1) // the previous error is cleared upon update() - else - compare (errorImmediateSpy.count, 1) - compare (immediateModel.errorString, "error") - compare (immediateModel.error, GeocodeModel.ParseError) - compare (immediateModel.count, 0) - compare (statusImmediateSpy.count, 2) - compare (immediateModel.status, GeocodeModel.Error) - // basic delayed geocode error - clear_slack_model() - slackModel.query = errorCoordinate1 - slackModel.update() - compare (errorStringSlackSpy.count, 0) - compare (errorSlackSpy.count, 0) - if (slackModel.errorString != "") - tryCompare (errorStringSlackSpy, "count", 2) - else - tryCompare (errorStringSlackSpy, "count", 1) - compare (slackModel.errorString, "error") - compare (slackModel.error, GeocodeModel.ParseError) - compare (slackModel.count, 0) - // Check that we recover - slackModel.query = rcoordinate1 - slackModel.update() - tryCompare(countSlackSpy, "count", 1) - compare (slackModel.count, 2) - compare (errorStringSlackSpy.count, 2) - compare (errorSlackSpy.count, 2) - compare (slackModel.errorString, "") - compare (slackModel.error, GeocodeModel.NoError) - } - function test_address_geocode() { - testQuerySpy.clear() - locationsSpy.clear() - testStatusSpy.clear() - testModel.reset() - countSpy.clear() - compare (locationsSpy.count, 0) - compare (testModel.errorString, "") - compare (testModel.error, GeocodeModel.NoError) - compare (testModel.count, 0) - testModel.query = address1 - compare (testQuerySpy.count, 1) - testModel.update() - tryCompare (locationsSpy, "count", 1) // 5 sec - compare (testModel.errorString, "") - compare (testModel.error, GeocodeModel.NoError) - compare (testModel.count, 2) - compare (testQuerySpy.count, 1) - compare (testStatusSpy.count, 2) - compare (testModel.status, GeocodeModel.Ready) - compare (testModel.get(0).address.street, "wellknown street") - compare (testModel.get(0).address.city, "expected city") - } - - function test_freetext_geocode() { - testQuerySpy.clear() - locationsSpy.clear() - testStatusSpy.clear() - testModel.reset() - countSpy.clear() - compare (locationsSpy.count, 0) - compare (testModel.errorString, "") - compare (testModel.error, GeocodeModel.NoError) - compare (testModel.count, 0) - testModel.limit = 5 // number of places echoed back - testModel.offset = 10 // 'county' set in the places - // Test successful case - testModel.query = "Freetext geocode" - compare(testQuerySpy.count, 1) - testModel.update(); - tryCompare (locationsSpy, "count", 1) // 5 sec - tryCompare(countSpy, "count", 1) - tryCompare(testModel, "count", 5) - compare(testModel.get(0).address.county, "10") - // Test error case - testModel.query = "2" // tells plugin to echo error '2' - compare(testQuerySpy.count, 2) - testModel.update(); - tryCompare (locationsSpy, "count", 2) // 5 sec - tryCompare(countSpy, "count", 2) - tryCompare(testModel, "count", 0) - compare(testModel.errorString, "2") - compare (testModel.error, GeocodeModel.CommunicationError) - testModel.reset() - tryCompare(countSpy, "count", 2) - compare (testModel.count, 0) - } - - function test_delayed_freetext_geocode() { - clear_slack_model() - slackModel.limit = 5 // number of places echoed back - slackModel.offset = 10 // 'county' set in the places - // Basic successful case - slackModel.query = "freetext geocode" - compare (querySlackSpy.count, 1) - slackModel.update() - tryCompare(countSlackSpy, "count", 0) - compare (locationsSlackSpy.count, 0) - compare (slackModel.count, 0) - tryCompare(countSlackSpy, "count", 1); //waits up to 5s - compare (slackModel.count, 5) - compare (locationsSlackSpy.count, 1) - // Frequent updates, previous requests are aborted - slackModel.reset() - locationsSlackSpy.clear() - countSlackSpy.clear() - slackModel.update() - tryCompare(locationsSlackSpy, "count", 0) - compare(countSlackSpy.count, 0) - slackModel.update() - tryCompare(locationsSlackSpy, "count", 0) - compare(countSlackSpy.count, 0) - slackModel.update() - tryCompare(locationsSlackSpy, "count", 0) - compare(countSlackSpy.count, 0) - slackModel.update() - tryCompare(locationsSlackSpy, "count", 0) - compare(countSlackSpy.count, 0) - tryCompare(countSlackSpy, "count", 1); //waits up to 5s - compare (locationsSlackSpy.count, 1) - compare(slackModel.count, 5) // limit - } - - function test_geocode_auto_updates() { - compare (automaticModel.count, 4) // should be something already - compare (automaticLocationsSpy.count, 1) - // change query and its contents and verify that autoupdate occurs - automaticAddress1.county = 6 - tryCompare(automaticLocationsSpy, "count", 2) - compare (automaticModel.count, 6) - automaticAddress1.street = "The Avenue" - tryCompare(automaticLocationsSpy, "count", 3) - compare (automaticModel.count, 6) - automaticModel.query = automaticCoordinate1 - tryCompare(automaticLocationsSpy, "count", 4) - compare (automaticModel.count, 3) - } - - function test_geocode_extended_attributes() { - compare (extendedModel.count, 6) // should be something already - compare (extendedLocationsSpy.count, 3) - compare(extendedModel.get(0).extendedAttributes - ["QGeoCodingManagerEngineTest_locationExtendedAttribute"], 42) - // change query and its contents and verify that autoupdate occurs - extendedModel.query = automaticCoordinate1 - tryCompare(extendedLocationsSpy, "count", 4) - compare (extendedModel.count, 3) - compare(extendedModel.get(0).extendedAttributes - ["QGeoCodingManagerEngineTest_locationExtendedAttribute"], 42) - } - - function test_delayed_geocode() { - // basic delayed response - slackModel.reset() - querySlackSpy.clear() - countSlackSpy.clear() - locationsSlackSpy.clear() - slackModel.query = slackAddress1 - slackAddress1.county = "7" - compare (querySlackSpy.count, 1) - slackModel.update() - tryCompare(countSlackSpy, "count", 0) - compare (locationsSlackSpy.count, 0) - compare (slackModel.count, 0) - tryCompare(countSlackSpy, "count", 1); //waits up to 5s - compare (locationsSlackSpy.count, 1) - compare (slackModel.count, 7) // slackAddress1.county) - // Frequent updates, previous requests are aborted - slackModel.reset() - locationsSlackSpy.clear() - countSlackSpy.clear() - slackModel.update() - tryCompare(locationsSlackSpy, "count", 0) - compare(countSlackSpy.count, 0) - slackModel.update() - tryCompare(locationsSlackSpy, "count", 0) - compare(countSlackSpy.count, 0) - slackModel.update() - tryCompare(locationsSlackSpy, "count", 0) - compare(countSlackSpy.count, 0) - slackModel.update() - tryCompare(locationsSlackSpy, "count", 0) - compare(countSlackSpy.count, 0) - tryCompare(countSlackSpy, "count", 1); //waits up to 5s - compare (locationsSlackSpy.count, 1) - compare(slackModel.count, 7) // slackAddress1.county - } - function test_reverse_geocode() { - testModel.reset() - testQuerySpy.clear() - locationsSpy.clear() - testStatusSpy.clear() - countSpy.clear() - compare (testModel.errorString, "") - compare (testModel.error, GeocodeModel.NoError) - compare (testModel.count, 0) - compare (testQuerySpy.count, 0) - testModel.query = rcoordinate1 - compare (testQuerySpy.count, 1) - testModel.update() - tryCompare (locationsSpy, "count", 1) // 5 sec - tryCompare(countSpy, "count", 1) - compare (testModel.errorString, "") - compare (testModel.error, GeocodeModel.NoError) - compare (testModel.count, 2) - testModel.reset() - tryCompare(countSpy, "count", 2) - compare (testModel.count, 0) - } - function test_delayed_reverse_geocode() { - clear_slack_model() - slackModel.query = slackCoordinate1 - compare (querySlackSpy.count, 1) - slackModel.update() - tryCompare(countSlackSpy, "count", 0) - compare (locationsSlackSpy.count, 0) - compare (slackModel.count, 0) - - tryCompare(countSlackSpy, "count", 1); //waits up to 5s - compare (locationsSlackSpy.count, 1) - compare (slackModel.count, 3) // slackCoordinate1.longitude - // Frequent updates, previous requests are aborted - slackModel.reset() - locationsSlackSpy.clear() - countSlackSpy.clear() - slackModel.update() - tryCompare(locationsSlackSpy, "count", 0) - compare(countSlackSpy.count, 0) - slackModel.update() - tryCompare(locationsSlackSpy, "count", 0) - compare(countSlackSpy.count, 0) - slackModel.update() - tryCompare(locationsSlackSpy, "count", 0) - compare(countSlackSpy.count, 0) - slackModel.update() - tryCompare(locationsSlackSpy, "count", 0) - compare(countSlackSpy.count, 0) - - tryCompare(countSlackSpy, "count", 1); //waits up to 5s - compare(locationsSlackSpy.count, 1) - compare(slackModel.count, 3) // slackCoordinate1.longitude - } - } -} diff --git a/tests/auto/declarative_core/tst_imagemodel.qml b/tests/auto/declarative_core/tst_imagemodel.qml deleted file mode 100644 index 2fa5093c..00000000 --- a/tests/auto/declarative_core/tst_imagemodel.qml +++ /dev/null @@ -1,186 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.0 -import QtTest 1.0 -import QtLocation 5.3 -import "utils.js" as Utils - -TestCase { - id: testCase - - name: "ImageModel" - - Plugin { - id: testPlugin - name: "qmlgeo.test.plugin" - allowExperimental: true - parameters: [ - PluginParameter { - name: "initializePlaceData" - value: true - } - ] - } - - ImageModel { - id: testModel - } - - Place { - id: testPlace - 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 }, - { tag: "batchSize", property: "batchSize", signal: "batchSizeChanged", value: 10, reset: 1 }, - ]; - } - - function test_setAndGet(data) { - Utils.testObjectProperties(testCase, testModel, data); - } - - function test_consecutive_fetch_data() { - return [ - { tag: "batchSize 1", batchSize: 1 }, - { tag: "batchSize 2", batchSize: 2 }, - { tag: "batchSize 5", batchSize: 5 }, - { tag: "batchSize 10", batchSize: 10 }, - ]; - } - - function test_consecutive_fetch(data) { - 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, data); - 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.3; ImageModel {}', - testCase, "imageModel"); - } -} diff --git a/tests/auto/declarative_core/tst_place.qml b/tests/auto/declarative_core/tst_place.qml deleted file mode 100644 index bb789b42..00000000 --- a/tests/auto/declarative_core/tst_place.qml +++ /dev/null @@ -1,627 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.0 -import QtTest 1.0 -import QtLocation 5.3 -import QtPositioning 5.2 -import "utils.js" as Utils - -TestCase { - id: testCase - - name: "Place" - - Plugin { - id: testPlugin - name: "qmlgeo.test.plugin" - allowExperimental: true - } - - Place { - id: favoritePlace - name: "Favorite Place" - } - - Place { id: emptyPlace } - - Place { id: emptyPlace2 } - - Place { id: testPlace } - - Place { - id: savePlace - - name: "Test place" - - visibility: Place.DeviceVisibility - - location: Location { - address: Address { - country: "country" - countryCode: "cc" - state: "state" - county: "county" - city: "city" - district: "district" - street: "123 Fake Street" - postalCode: "1234" - } - - coordinate { - latitude: 10 - longitude: 10 - altitude: 100 - } - - boundingBox { - center: QtPositioning.coordinate(10, 10, 100) - width: 100 - height: 100 - } - } - - ratings: Ratings { - average: 3.5 - count: 10 - } - - supplier: Supplier { - name: "Supplier 1" - supplierId: "supplier-id-1" - url: "http://www.example.com/supplier-id-1/" - icon: Icon{ - plugin: testPlugin - Component.onCompleted: { - parameters.singleUrl = "http://www.example.com/supplier-id-1/icon" - } - } - } - - categories: [ - Category { - name: "Category 1" - categoryId: "category-id-1" - plugin: testPlugin - }, - Category { - name: "Category 2" - categoryId: "category-id-2" - plugin: testPlugin - } - ] - - icon: Icon { - Component.onCompleted: { - savePlace.icon.parameters.singleUrl = "http://example.com/test-place.png"; - } - } - } - - Place { - id: dummyPlace - placeId: "487" - name: "dummyPlace" - visibility: Place.PublicVisibility - } - - // compares two places property by property - function compare_place(place1, place2) { - // check simple properties - var simpleProperties = ["name", "placeId", "primaryPhone", "primaryFax", "primaryEmail", - "primaryWebsite", "visibility"]; - for (x in simpleProperties) { - if (place1[simpleProperties[x]] !== place2[simpleProperties[x]]) - return false; - } - - // check categories - if (place1.categories.length !== place2.categories.length) - return false; - for (var i = 0; i < place1.categories.length; ++i) { - // fixme, what if the order of the two lists are not the same - if (place1.categories[i].categoryId !== place2.categories[i].categoryId) - return false; - if (place1.categories[i].name !== place2.categories[i].name) - return false; - } - - // check supplier - if (place1.supplier === null && place2.supplier !== null) - return false; - if (place1.supplier !== null && place2.supplier === null) - return false; - if (place1.supplier !== null && place2.supplier !== null) { - if (place1.supplier.supplierId !== place2.supplier.supplierId) - return false; - if (place1.supplier.name !== place2.supplier.name) - return false; - if (place1.supplier.url !== place2.supplier.url) - return false; - - // check supplier icon - if (place1.supplier.icon === null && place2.supplier.icon !== null) - return false; - if (place1.supplier.icon !== null && place2.supplier.icon === null) - return false; - if (place1.supplier.icon !== null && place2.supplier.icon !== null) { - if (place1.supplier.icon.parameters.keys().length !== place2.supplier.icon.parameters.keys().length) { - return false; - } - - var keys = place1.supplier.icon.parameters.keys() + place2.supplier.icon.parameters.keys(); - for (var i = 0; i < keys.length; ++i) { - if (place1.supplier.icon.parameters[keys[i]] != place2.supplier.icon.parameters[keys[i]]) { - return false; - } - } - - if (place1.supplier.icon.plugin !== place2.supplier.icon.plugin) - return false; - } - } - - // check ratings - if (place1. ratings === null && place2.ratings !== null) - return false; - if (place1.ratings !== null && place2.ratings === null) - return false; - if (place1.ratings !== null && place2.ratings !== null) { - if (place1.ratings.average !== place2.ratings.average) - return false; - if (place1.ratings.count !== place2.ratings.count) - return false; - } - - // check location - if (place1.location === null && place2.location !== null) - return false; - if (place1.location !== null && place2.location === null) - return false; - if (place1.location !== null && place2.location !== null) { - if (place1.location.address.country !== place2.location.address.country) - return false; - if (place1.location.address.countryCode !== place2.location.address.countryCode) - return false; - if (place1.location.address.state !== place2.location.address.state) - return false; - if (place1.location.address.county !== place2.location.address.county) - return false; - if (place1.location.address.city !== place2.location.address.city) - return false; - if (place1.location.address.district !== place2.location.address.district) - return false; - if (place1.location.address.street !== place2.location.address.street) - return false; - if (place1.location.address.postalCode !== place2.location.address.postalCode) - return false; - - if (place1.location.coordinate !== place2.location.coordinate) - return false; - if (place1.location.boundingBox !== place2.location.boundingBox) - return false; - } - - // check icon - if (place1.icon === null && place2.icon !== null) { - return false; - } - if (place1.icon !== null && place2.icon === null) { - return false; - } - if (place1.icon !== null && place2.icon !== null) { - if (place1.icon.plugin !== place2.icon.plugin) { - console.log(place1.icon.plugin + " " + place2.icon.plugin); - return false; - } - - if (place1.icon.parameters.keys().length !== place2.icon.parameters.keys().length) { - return false; - } - - var keys = place1.icon.parameters.keys() + place2.icon.parameters.keys(); - for (var i = 0; i < keys.length; ++i) { - if (place1.icon.parameters[keys[i]] - != place2.icon.parameters[keys[i]]) { - return false; - } - } - } - - // check extended attributes - - return true; - } - - function test_emptyPlace() { - // basic properties - compare(emptyPlace.plugin, null); - compare(emptyPlace.categories.length, 0); - compare(emptyPlace.name, ""); - compare(emptyPlace.placeId, ""); - compare(emptyPlace.detailsFetched, false); - compare(emptyPlace.status, Place.Ready); - compare(emptyPlace.primaryPhone, ""); - compare(emptyPlace.primaryFax, ""); - compare(emptyPlace.primaryEmail, ""); - compare(emptyPlace.primaryWebsite, ""); - compare(emptyPlace.visibility, Place.UnspecifiedVisibility); - compare(emptyPlace.attribution, ""); - - // complex properties - compare(emptyPlace.ratings.average, 0); - compare(emptyPlace.location.address.street, ''); - compare(emptyPlace.location.address.district, ''); - compare(emptyPlace.location.address.city, ''); - compare(emptyPlace.location.address.county, ''); - compare(emptyPlace.location.address.state, ''); - compare(emptyPlace.location.address.country, ''); - - compare(emptyPlace.icon.plugin, null); - - compare(emptyPlace.supplier.name, ''); - compare(emptyPlace.supplier.supplierId, ''); - compare(emptyPlace.supplier.url, ''); - - compare(emptyPlace.supplier.icon.plugin, null); - - compare(emptyPlace.reviewModel.totalCount, -1); - compare(emptyPlace.imageModel.totalCount, -1); - compare(emptyPlace.editorialModel.totalCount, -1); - compare(emptyPlace.categories.length, 0); - - verify(compare_place(emptyPlace, emptyPlace)); - verify(compare_place(emptyPlace, emptyPlace2)); - } - - function test_setAndGet_data() { - return [ - { tag: "name", property: "name", signal: "nameChanged", value: "Test Place", reset: "" }, - { tag: "placeId", property: "placeId", signal: "placeIdChanged", value: "test-place-id-1", reset: "" }, - { tag: "visibility", property: "visibility", signal: "visibilityChanged", value: Place.PublicVisibility, reset: Place.UnspecifiedVisibility }, - { tag: "attribution", property: "attribution", signal: "attributionChanged", value: "Place data from...", reset: "" }, - { tag: "favorite", property: "favorite", signal: "favoriteChanged", value: favoritePlace } - ]; - } - - function test_setAndGet(data) { - Utils.testObjectProperties(testCase, testPlace, data); - } - - function test_categories() { - var categories = new Array(2); - categories[0] = Qt.createQmlObject('import QtLocation 5.3; Category { categoryId: "cat-id-1"; name: "Category 1" }', testCase, "Category1"); - categories[1] = Qt.createQmlObject('import QtLocation 5.3; Category { categoryId: "cat-id-2"; name: "Category 2" }', testCase, "Category2"); - - var signalSpy = Qt.createQmlObject('import QtTest 1.0; SignalSpy {}', testCase, "SignalSpy"); - signalSpy.target = testPlace; - signalSpy.signalName = "categoriesChanged"; - - // set categories to something new - testPlace.categories = categories; - compare(testPlace.categories.length, categories.length); - - for (var i = 0; i < categories.length; ++i) { - compare(testPlace.categories[i].categoryId, categories[i].categoryId); - compare(testPlace.categories[i].name, categories[i].name); - } - - compare(signalSpy.count, 2); - - // set categories to the same (signal spy should not increase?) - testPlace.categories = categories; - compare(testPlace.categories.length, categories.length); - - for (var i = 0; i < categories.length; ++i) { - compare(testPlace.categories[i].categoryId, categories[i].categoryId); - compare(testPlace.categories[i].name, categories[i].name); - } - - compare(signalSpy.count, 5); // clear + append + append - - // reset by assignment - testPlace.categories = new Array(0); - compare(testPlace.categories.length, 0); - compare(signalSpy.count, 6); - - signalSpy.destroy(); - } - - function test_supplier() { - var supplier = Qt.createQmlObject('import QtLocation 5.3; Supplier { supplierId: "sup-id-1"; name: "Category 1" }', testCase, "Supplier1"); - - var signalSpy = Qt.createQmlObject('import QtTest 1.0; SignalSpy {}', testCase, "SignalSpy"); - signalSpy.target = testPlace; - signalSpy.signalName = "supplierChanged"; - - // set supplier to something new - testPlace.supplier = supplier; - compare(testPlace.supplier, supplier); - - compare(testPlace.supplier.supplierId, supplier.supplierId); - compare(testPlace.supplier.name, supplier.name); - - compare(signalSpy.count, 1); - - // set supplier to the same - testPlace.supplier = supplier; - compare(testPlace.supplier, supplier); - - compare(testPlace.supplier.supplierId, supplier.supplierId); - compare(testPlace.supplier.name, supplier.name); - - compare(signalSpy.count, 1); - - // reset by assignment - testPlace.supplier = null; - compare(testPlace.supplier, null); - compare(signalSpy.count, 2); - - signalSpy.destroy(); - } - - function test_location() { - var location = Qt.createQmlObject('import QtPositioning 5.2; Location { coordinate: QtPositioning.coordinate(10.0, 20.0) }', testCase, "Location1"); - - var signalSpy = Qt.createQmlObject('import QtTest 1.0; SignalSpy {}', testCase, "SignalSpy"); - signalSpy.target = testPlace; - signalSpy.signalName = "locationChanged"; - - testPlace.location = location; - compare(testPlace.location.coordinate.latitude, 10.0); - compare(signalSpy.count, 1); - - testPlace.location = location; - compare(testPlace.location.coordinate.latitude, 10.0); - compare(signalSpy.count, 1); - - testPlace.location = null; - compare(testPlace.location, null); - compare(signalSpy.count, 2); - - location.destroy(); - signalSpy.destroy(); - } - - function test_ratings() { - var ratings = Qt.createQmlObject('import QtLocation 5.3; Ratings { average: 3; count: 100 }', testCase, "Rating1"); - - var signalSpy = Qt.createQmlObject('import QtTest 1.0; SignalSpy {}', testCase, "SignalSpy"); - signalSpy.target = testPlace; - signalSpy.signalName = "ratingsChanged"; - - testPlace.ratings = ratings; - compare(testPlace.ratings.average, 3); - compare(testPlace.ratings.count, 100); - compare(signalSpy.count, 1); - - testPlace.ratings = ratings; - compare(testPlace.ratings.average, 3); - compare(testPlace.ratings.count, 100); - compare(signalSpy.count, 1); - - testPlace.ratings = null; - compare(testPlace.ratings, null); - compare(signalSpy.count, 2); - - ratings.destroy(); - signalSpy.destroy(); - } - - function test_extendedAttributes() { - verify(testPlace.extendedAttributes); - - testPlace.extendedAttributes["foo"] = Qt.createQmlObject('import QtLocation 5.3; PlaceAttribute { text: "Foo"; label: "Foo label" }', testCase, 'PlaceAttribute'); - - verify(testPlace.extendedAttributes.foo); - compare(testPlace.extendedAttributes.foo.text, "Foo"); - compare(testPlace.extendedAttributes.foo.label, "Foo label"); - - testPlace.extendedAttributes["foo"] = null; - verify(!testPlace.extendedAttributes.foo); - } - - function test_contactDetailsProperty() { - verify(testPlace.contactDetails); - - testPlace.contactDetails["phone"] = Qt.createQmlObject('import QtLocation 5.3; ContactDetail { label: "Test Label"; value: "Detail Value" }', testCase, 'ContactDetail'); - - verify(testPlace.contactDetails.phone); - compare(testPlace.contactDetails.phone[0].label, "Test Label"); - compare(testPlace.contactDetails.phone[0].value, "Detail Value"); - - testPlace.contactDetails["phone"] = null; - verify(!testPlace.contactDetails.phone); - } - - function test_saveload() { - // Save a place - var signalSpy = Qt.createQmlObject('import QtTest 1.0; SignalSpy {}', testCase, "SignalSpy"); - signalSpy.target = savePlace; - signalSpy.signalName = "statusChanged"; - - savePlace.plugin = testPlugin; - savePlace.icon.plugin = testPlugin; - savePlace.placeId = "invalid-place-id"; - - savePlace.save(); - - compare(savePlace.status, Place.Saving); - - tryCompare(savePlace, "status", Place.Error); - - // try again without an invalid placeId - savePlace.placeId = ""; - savePlace.save(); - - compare(savePlace.status, Place.Saving); - - tryCompare(savePlace, "status", Place.Ready); - - verify(savePlace.placeId !== ""); - - signalSpy.destroy(); - - - // Read a place - var readPlace = Qt.createQmlObject('import QtLocation 5.3; Place { }', testCase, "test_saveload"); - - signalSpy = Qt.createQmlObject('import QtTest 1.0; SignalSpy {}', testCase, "SignalSpy"); - signalSpy.target = readPlace; - signalSpy.signalName = "statusChanged"; - - readPlace.plugin = testPlugin; - - readPlace.getDetails(); - - compare(readPlace.status, Place.Fetching); - tryCompare(readPlace, "status", Place.Error); - - readPlace.placeId = "invalid-id"; - - readPlace.getDetails(); - - compare(readPlace.status, Place.Fetching); - tryCompare(readPlace, "status", Place.Error); - - readPlace.placeId = savePlace.placeId; - - // verify that read place is not currently the same as what we saved - verify(!compare_place(readPlace, savePlace)); - - readPlace.getDetails(); - - compare(readPlace.status, Place.Fetching); - tryCompare(readPlace, "status", Place.Ready); - - // verify that read place is the same as what we saved - verify(compare_place(readPlace, savePlace)); - - signalSpy.destroy(); - - - // Remove a place - var removePlace = Qt.createQmlObject('import QtLocation 5.3; Place { }', testCase, "test_saveload"); - - signalSpy = Qt.createQmlObject('import QtTest 1.0; SignalSpy {}', testCase, "SignalSpy"); - signalSpy.target = removePlace; - signalSpy.signalName = "statusChanged"; - - removePlace.plugin = testPlugin; - - removePlace.remove(); - - compare(removePlace.status, Place.Removing); - tryCompare(removePlace, "status", Place.Error); - - removePlace.placeId = "invalid-id"; - - removePlace.remove(); - - compare(removePlace.status, Place.Removing); - tryCompare(removePlace, "status", Place.Error); - - removePlace.placeId = savePlace.placeId; - - removePlace.remove(); - - compare(removePlace.status, Place.Removing); - tryCompare(removePlace, "status", Place.Ready); - - removePlace.getDetails(); - - compare(removePlace.status, Place.Fetching); - tryCompare(removePlace, "status", Place.Error); - - signalSpy.destroy(); - } - - function test_copy() { - var place = Qt.createQmlObject('import QtLocation 5.3; Place { }', this); - place.plugin = testPlugin; - place.copyFrom(dummyPlace); - compare(place.placeId, ""); - compare(place.name, "dummyPlace"); - compare(place.visibility, Place.UnspecifiedVisibility); - } - - function test_contactDetails(data) { - var place = Qt.createQmlObject('import QtLocation 5.3; Place {}', this); - - var signalSpy = Qt.createQmlObject('import QtTest 1.0; SignalSpy {}', testCase, "SignalSpy"); - signalSpy.target = place; - signalSpy.signalName = data.signalName; - - var detail1 = Qt.createQmlObject('import QtLocation 5.3; ContactDetail {}', this); - detail1.label = "Detail1"; - detail1.value = "555-detail1"; - - place.contactDetails[data.contactType] = detail1; - compare(place.contactDetails[data.contactType].length, 1); - compare(place.contactDetails[data.contactType][0].label, "Detail1"); - compare(place.contactDetails[data.contactType][0].value, "555-detail1"); - - compare(place[data.primaryValue], "555-detail1"); - compare(signalSpy.count, 1); - signalSpy.clear(); - - var listView = Qt.createQmlObject('import QtQuick 2.0; ListView { delegate:Text{text:modelData.label + ":" + modelData.value } }', this); - listView.model = place.contactDetails[data.contactType]; - compare(listView.count, 1); - - var detail2 = Qt.createQmlObject('import QtLocation 5.3; ContactDetail {}', this); - detail2.label = "Detail2"; - detail2.value = "555-detail2"; - - var details = new Array(); - details.push(detail2); - details.push(detail1); - - place.contactDetails[data.contactType] = details; - compare(place.contactDetails[data.contactType].length, 2); - compare(place.contactDetails[data.contactType][0].label, "Detail2"); - compare(place.contactDetails[data.contactType][0].value, "555-detail2"); - compare(place.contactDetails[data.contactType][1].label, "Detail1"); - compare(place.contactDetails[data.contactType][1].value, "555-detail1"); - - compare(place[data.primaryValue], "555-detail2"); - compare(signalSpy.count, 1); - signalSpy.clear(); - listView.model = place.contactDetails[data.contactType]; - compare(listView.count, 2); - } - - function test_contactDetails_data() { - return [ - { tag: "phone", contactType: "phone", signalName: "primaryPhoneChanged", primaryValue: "primaryPhone"}, - { tag: "fax", contactType: "fax", signalName: "primaryFaxChanged", primaryValue: "primaryFax"}, - { tag: "email", contactType: "email", signalName: "primaryEmailChanged", primaryValue: "primaryEmail"}, - { tag: "website", contactType: "website", signalName: "primaryWebsiteChanged", primaryValue: "primaryWebsite"} - ]; - } -} diff --git a/tests/auto/declarative_core/tst_placeattribute.qml b/tests/auto/declarative_core/tst_placeattribute.qml deleted file mode 100644 index ae61aed4..00000000 --- a/tests/auto/declarative_core/tst_placeattribute.qml +++ /dev/null @@ -1,53 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.0 -import QtTest 1.0 -import QtLocation 5.3 -import "utils.js" as Utils - -TestCase { - id: testCase - - name: "PlaceAttribute" - - PlaceAttribute { - id: testAttribute - } - - function test_setAndGet_data() { - return [ - { tag: "label", property: "label", signal: "labelChanged", value: "Test Label", reset: "" }, - { tag: "text", property: "text", signal: "textChanged", value: "Test Text", reset: "" }, - ]; - } - - function test_setAndGet(data) { - Utils.testObjectProperties(testCase, testAttribute, data); - } -} diff --git a/tests/auto/declarative_core/tst_placeicon.qml b/tests/auto/declarative_core/tst_placeicon.qml deleted file mode 100644 index c0f099d7..00000000 --- a/tests/auto/declarative_core/tst_placeicon.qml +++ /dev/null @@ -1,106 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.0 -import QtTest 1.0 -import QtLocation 5.3 -import "utils.js" as Utils - -TestCase { - id: testCase - - name: "Icon" - - Icon { id: emptyIcon } - - function test_empty() { - compare(emptyIcon.plugin, null); - compare(emptyIcon.parameters.keys().length, 0) - } - - - Icon { - id: qmlIconSingleUrl - } - - function test_qmlSingleUrlIcon() { - qmlIconSingleUrl.parameters.singleUrl = "http://example.com/icon.png" - - var u = qmlIconSingleUrl.url(Qt.size(64, 64)); - compare(u, "http://example.com/icon.png"); - - u = qmlIconSingleUrl.url(Qt.size(20, 20)); - compare(u, "http://example.com/icon.png"); - - qmlIconSingleUrl.parameters.singleUrl = "/home/user/icon.png" - u = qmlIconSingleUrl.url(Qt.size(20, 20)); - compare(u, "file:///home/user/icon.png"); - } - - Plugin { - id: testPlugin - name: "qmlgeo.test.plugin" - allowExperimental: true - } - - Icon { - id: qmlIconParams - plugin: testPlugin - } - - function test_qmlIconParams() { - compare(qmlIconParams.plugin, testPlugin); - qmlIconParams.parameters.s = "http://example.com/icon_small.png" - qmlIconParams.parameters.m = "http://example.com/icon_medium.png" - qmlIconParams.parameters.l = "http://example.com/icon_large.png" - - compare(qmlIconParams.url(Qt.size(10, 10)), "http://example.com/icon_small.png"); - compare(qmlIconParams.url(Qt.size(20, 20)), "http://example.com/icon_small.png"); - compare(qmlIconParams.url(Qt.size(24, 24)), "http://example.com/icon_small.png"); - compare(qmlIconParams.url(Qt.size(25, 25)), "http://example.com/icon_medium.png"); - compare(qmlIconParams.url(Qt.size(30, 30)), "http://example.com/icon_medium.png"); - compare(qmlIconParams.url(Qt.size(39, 39)), "http://example.com/icon_medium.png"); - compare(qmlIconParams.url(Qt.size(40, 40)), "http://example.com/icon_large.png"); - compare(qmlIconParams.url(Qt.size(50, 50)), "http://example.com/icon_large.png"); - compare(qmlIconParams.url(Qt.size(60, 60)), "http://example.com/icon_large.png"); - } - - Icon { - id: testIcon - } - - function test_setAndGet_data() { - return [ - { tag: "plugin", property: "plugin", signal: "pluginChanged", value: testPlugin }, - ]; - } - - function test_setAndGet(data) { - Utils.testObjectProperties(testCase, testIcon, data); - } -} diff --git a/tests/auto/declarative_core/tst_placesearchmodel.qml b/tests/auto/declarative_core/tst_placesearchmodel.qml deleted file mode 100644 index 4c7897b5..00000000 --- a/tests/auto/declarative_core/tst_placesearchmodel.qml +++ /dev/null @@ -1,311 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.0 -import QtTest 1.0 -import QtLocation 5.3 -import QtPositioning 5.2 -import "utils.js" as Utils - -TestCase { - id: testCase - - name: "PlaceSearchModel" - - Plugin { - id: testPlugin - name: "qmlgeo.test.plugin" - allowExperimental: true - parameters: [ - PluginParameter { - name: "initializePlaceData" - value: true - } - ] - } - - Plugin { - id: favoritePlugin - name: "foo" - } - - Plugin { - id: uninitializedPlugin - } - - Category { - id: testCategory1 - categoryId: "da3606c1-3448-43b3-a4a3-ca24b12dd94a" - name: "Test Category 1" - } - - Category { - id: testCategory2 - categoryId: "bb8ead84-ec2a-48a9-9c8f-d4ffd3134b21" - name: "Test Category 2" - } - - function compareArray(a, b) { - if (a.length !== b.length) - return false; - - for (var i = 0; i < a.length; ++i) { - if (b.indexOf(a[i]) < 0) - return false; - } - - return true; - } - - function test_setAndGet_data() { - var testSearchArea = QtPositioning.circle(QtPositioning.coordinate(10, 20), 5000); - - return [ - { tag: "plugin", property: "plugin", signal: "pluginChanged", value: testPlugin }, - { tag: "searchArea", property: "searchArea", signal: "searchAreaChanged", value: testSearchArea, reset: QtPositioning.shape() }, - { tag: "limit", property: "limit", signal: "limitChanged", value: 10, reset: -1 }, - - { tag: "searchTerm", property: "searchTerm", signal: "searchTermChanged", value: "Test term", reset: "" }, - { tag: "recommendationId", property: "recommendationId", signal: "recommendationIdChanged", value: "Test-place-id", reset: "" }, - { tag: "relevanceHint", property: "relevanceHint", signal: "relevanceHintChanged", value: PlaceSearchModel.DistanceHint, reset: PlaceSearchModel.UnspecifiedHint }, - { tag: "visibilityScope", property: "visibilityScope", signal: "visibilityScopeChanged", value: Place.DeviceVisibility, reset: Place.UnspecifiedVisibility }, - { tag: "favoritesPlugin", property: "favoritesPlugin", signal: "favoritesPluginChanged", value: favoritePlugin }, - { tag: "category", property: "categories", signal: "categoriesChanged", value: testCategory1, expectedValue: [ testCategory1 ], reset: [], array: true }, - { tag: "categories", property: "categories", signal: "categoriesChanged", value: [ testCategory1, testCategory2 ], reset: [], array: true }, - ]; - } - - function test_setAndGet(data) { - var testModel = Qt.createQmlObject('import QtLocation 5.3; PlaceSearchModel {}', testCase, "PlaceSearchModel"); - Utils.testObjectProperties(testCase, testModel, data); - delete testModel; - } - - function test_search_data() { - var park = Qt.createQmlObject('import QtLocation 5.3; Category {name: "Park"; categoryId: "c2e1252c-b997-44fc-8165-e53dd00f66a7"}', testCase, "Category"); - return [ - { - tag: "searchTerm, multiple results", - property: "searchTerm", - value: "view", - reset: "", - places: [ - "4dcc74ce-fdeb-443e-827c-367438017cf1", - "8f72057a-54b2-4e95-a7bb-97b4d2b5721e" - ] - }, - { - tag: "searchTerm, single result", - property: "searchTerm", - value: "park", - reset: "", - places: [ - "4dcc74ce-fdeb-443e-827c-367438017cf1" - ] - }, - { - tag: "searchTerm, multiple results", - property: "searchTerm", - value: "sea", - reset: "", - alternate: true, - places: [ - "8f72057a-54b2-4e95-a7bb-97b4d2b5721e" - ] - }, - { - tag: "categories, single result", - property: "categories", - value: [ park ], - places: [ - "dacb2181-3f67-4e6a-bd4d-635e99ad5b03" - ] - }, - { - tag: "recommendations", - property: "recommendationId", - value: "4dcc74ce-fdeb-443e-827c-367438017cf1", - reset: "", - places: [ - "8f72057a-54b2-4e95-a7bb-97b4d2b5721e", - "dacb2181-3f67-4e6a-bd4d-635e99ad5b03" - ] - }, - { - tag: "no recommendations", - property: "recommendationId", - value: "8f72057a-54b2-4e95-a7bb-97b4d2b5721e", - reset: "", - places: [ ] - } - ]; - } - - function test_search(data) { - var testModel = Qt.createQmlObject('import QtLocation 5.3; PlaceSearchModel {}', testCase, "PlaceSearchModel"); - testModel.plugin = testPlugin; - - var statusChangedSpy = Qt.createQmlObject('import QtTest 1.0; SignalSpy {}', testCase, "SignalSpy"); - statusChangedSpy.target = testModel; - statusChangedSpy.signalName = "statusChanged"; - - var countChangedSpy = Qt.createQmlObject('import QtTest 1.0; SignalSpy {}', testCase, "SignalSpy"); - countChangedSpy.target = testModel; - countChangedSpy.signalName = "rowCountChanged"; - - compare(testModel.status, PlaceSearchModel.Null); - - testModel[data.property] = data.value; - testModel.update(); - - compare(testModel.status, PlaceSearchModel.Loading); - compare(statusChangedSpy.count, 1); - - tryCompare(testModel, "status", PlaceSearchModel.Ready); - compare(statusChangedSpy.count, 2); - - if (data.places.length > 0) - compare(countChangedSpy.count, 1); - else - compare(countChangedSpy.count, 0); - - for (var i = 0; i < testModel.count; ++i) { - compare(testModel.data(i, "type"), PlaceSearchModel.PlaceResult); - - var place = testModel.data(i, "place"); - - verify(data.places.indexOf(place.placeId) >= 0); - } - - // Test for alternate implementation - if (data.alternate !== undefined && data.alternate === true) { - for (var ii = 0; ii < testModel.count; ++ii) { - var p = testModel.data(ii, "place"); - compare(p.extendedAttributes["x_provider"].text, "QPlacePrivateDefaultAlt") - } - } - - testModel.reset(); - - compare(statusChangedSpy.count, 3); - compare(testModel.status, PlaceSearchModel.Null); - if (data.places.length > 0) - compare(countChangedSpy.count, 2); - else - compare(countChangedSpy.count, 0); - compare(testModel.count, 0); - - countChangedSpy.destroy(); - statusChangedSpy.destroy(); - - if (data.reset === undefined) { - testModel[data.property] = null; - } else { - testModel[data.property] = data.reset; - } - - delete testModel; - delete statusChangedSpy; - delete countChangedSpy; - } - - function test_cancel() { - var testModel = Qt.createQmlObject('import QtLocation 5.3; PlaceSearchModel {}', testCase, "PlaceSearchModel"); - testModel.plugin = testPlugin; - - var statusChangedSpy = Qt.createQmlObject('import QtTest 1.0; SignalSpy {}', testCase, "SignalSpy"); - statusChangedSpy.target = testModel; - statusChangedSpy.signalName = "statusChanged"; - - //try cancelling from an initially null state - compare(testModel.status, PlaceSearchModel.Null); - testModel.searchTerm = "view"; - testModel.update(); - tryCompare(testModel, "status", PlaceSearchModel.Loading); - testModel.cancel(); - tryCompare(testModel, "status", PlaceSearchModel.Ready); - compare(statusChangedSpy.count, 2); - - testModel.update(); - tryCompare(testModel, "status", PlaceSearchModel.Loading); - tryCompare(testModel, "status", PlaceSearchModel.Ready); - compare(statusChangedSpy.count, 4); - - var numResults = testModel.count; - verify(numResults > 0); - - //try cancelling from an initially ready state - testModel.update(); - tryCompare(testModel, "status", PlaceSearchModel.Loading); - testModel.cancel(); - tryCompare(testModel, "status", PlaceSearchModel.Ready); - compare(testModel.count, numResults); - compare(statusChangedSpy.count, 6); - - //chack that an encountering an error will cause the model - //to clear its data - testModel.plugin = null; - testModel.update(); - tryCompare(testModel, "count", 0); - compare(testModel.status, PlaceSearchModel.Error); - - delete testModel; - delete statusChangedSpy; - } - - function test_error() { - var testModel = Qt.createQmlObject('import QtLocation 5.3; PlaceSearchModel {}', testCase, "PlaceSearchModel"); - - var statusChangedSpy = Qt.createQmlObject('import QtTest 1.0; SignalSpy {}', testCase, "SignalSpy"); - statusChangedSpy.target = testModel; - statusChangedSpy.signalName = "statusChanged"; - - //try searching without a plugin instance - testModel.update(); - tryCompare(statusChangedSpy, "count", 2); - compare(testModel.status, PlaceSearchModel.Error); - statusChangedSpy.clear(); - //Aside: there is some difficulty in checking the transition to the Loading state - //since the model transitions from Loading to Error before the next event loop - //iteration. - - //try searching with an uninitialized plugin instance. - testModel.plugin = uninitializedPlugin; - testModel.update(); - tryCompare(statusChangedSpy, "count", 2); - compare(testModel.status, PlaceSearchModel.Error); - statusChangedSpy.clear(); - - //try searching with plugin a instance - //that has been provided a non-existent name - testModel.plugin = favoritePlugin; - testModel.update(); - tryCompare(statusChangedSpy, "count", 2); - compare(testModel.status, PlaceSearchModel.Error); - } -} diff --git a/tests/auto/declarative_core/tst_placesearchsuggestionmodel.qml b/tests/auto/declarative_core/tst_placesearchsuggestionmodel.qml deleted file mode 100644 index 13347565..00000000 --- a/tests/auto/declarative_core/tst_placesearchsuggestionmodel.qml +++ /dev/null @@ -1,153 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.0 -import QtTest 1.0 -import QtLocation 5.3 -import QtPositioning 5.2 -import "utils.js" as Utils - -TestCase { - id: testCase - - name: "PlaceSearchSuggestionModel" - - PlaceSearchSuggestionModel { - id: testModel - } - - PlaceSearchSuggestionModel { - id: testModelError - } - - Plugin { - id: testPlugin - name: "qmlgeo.test.plugin" - allowExperimental: true - } - - Plugin { - id: nonExistantPlugin - name: "nonExistantName" - } - - Plugin { - id: uninitializedPlugin - } - - function test_setAndGet_data() { - var testSearchArea = QtPositioning.circle(QtPositioning.coordinate(10, 20), 5000); - return [ - { tag: "plugin", property: "plugin", signal: "pluginChanged", value: testPlugin }, - { tag: "searchArea", property: "searchArea", signal: "searchAreaChanged", value: testSearchArea, reset: QtPositioning.shape() }, - { tag: "limit", property: "limit", signal: "limitChanged", value: 10, reset: -1 }, - - { tag: "searchTerm", property: "searchTerm", signal: "searchTermChanged", value: "Test term", reset: "" }, - ]; - } - - function test_setAndGet(data) { - Utils.testObjectProperties(testCase, testModel, data); - } - - SignalSpy { id: statusChangedSpy; target: testModel; signalName: "statusChanged" } - SignalSpy { id: suggestionsChangedSpy; target: testModel; signalName: "suggestionsChanged" } - - function test_suggestions() { - compare(statusChangedSpy.count, 0); - testModel.plugin = testPlugin; - - compare(testModel.status, PlaceSearchSuggestionModel.Null); - - testModel.searchTerm = "test"; - testModel.update(); - - compare(testModel.status, PlaceSearchSuggestionModel.Loading); - compare(statusChangedSpy.count, 1); - - tryCompare(testModel, "status", PlaceSearchSuggestionModel.Ready); - compare(statusChangedSpy.count, 2); - - var expectedSuggestions = [ "test1", "test2", "test3" ]; - - compare(suggestionsChangedSpy.count, 1); - compare(testModel.suggestions, expectedSuggestions); - - testModel.reset(); - - compare(statusChangedSpy.count, 3); - compare(testModel.status, PlaceSearchSuggestionModel.Null); - compare(suggestionsChangedSpy.count, 2); - compare(testModel.suggestions, []); - - testModel.update(); - - compare(statusChangedSpy.count, 4); - compare(testModel.status, PlaceSearchSuggestionModel.Loading); - - testModel.cancel(); - - compare(statusChangedSpy.count, 5); - compare(testModel.status, PlaceSearchSuggestionModel.Ready); - - //check that an encountering an error will cause the model - //to clear its data - testModel.plugin = null; - testModel.update(); - tryCompare(testModel.suggestions, "length", 0); - compare(testModel.status, PlaceSearchSuggestionModel.Error); - } - - SignalSpy { id: statusChangedSpyError; target: testModelError; signalName: "statusChanged" } - - function test_error() { - compare(statusChangedSpyError.count, 0); - //try searching without a plugin instance - testModelError.update(); - tryCompare(statusChangedSpyError, "count", 2); - compare(testModelError.status, PlaceSearchSuggestionModel.Error); - statusChangedSpyError.clear(); - //Aside: there is some difficulty in checking the transition to the Loading state - //since the model transitions from Loading to Error before the next event loop - //iteration. - - //try searching with an uninitialized plugin instance. - testModelError.plugin = uninitializedPlugin; - testModelError.update(); - tryCompare(statusChangedSpyError, "count", 2); - compare(testModelError.status, PlaceSearchSuggestionModel.Error); - statusChangedSpyError.clear(); - - //try searching with plugin a instance - //that has been provided a non-existent name - testModelError.plugin = nonExistantPlugin; - testModelError.update(); - tryCompare(statusChangedSpyError, "count", 2); - compare(testModelError.status, PlaceSearchSuggestionModel.Error); - } -} diff --git a/tests/auto/declarative_core/tst_plugin.qml b/tests/auto/declarative_core/tst_plugin.qml deleted file mode 100644 index 23c1ff9f..00000000 --- a/tests/auto/declarative_core/tst_plugin.qml +++ /dev/null @@ -1,150 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.0 -import QtTest 1.0 -import QtLocation 5.3 - -Item { - - Plugin { id: unattachedPlugin } - Plugin { id: herePlugin; name: "here"} - Plugin { id: invalidPlugin; name: "invalid"; allowExperimental: true } - Plugin { id: testPlugin; - name: "qmlgeo.test.plugin" - allowExperimental: true - parameters: [ - // Parms to guide the test plugin - PluginParameter { name: "supported"; value: true}, - PluginParameter { name: "finishRequestImmediately"; value: true}, - PluginParameter { name: "validateWellKnownValues"; value: true} - ] - } - SignalSpy {id: invalidAttachedSpy; target: invalidPlugin; signalName: "attached"} - - Plugin { - id: requiredPlugin - allowExperimental: true - required { - mapping: Plugin.OfflineMappingFeature; - geocoding: Plugin.OfflineGeocodingFeature; - places: Plugin.AnyPlacesFeatures; - navigation: Plugin.AnyNavigationFeatures; - } - } - - TestCase { - name: "Plugin properties" - function test_plugin() { - verify (invalidPlugin.availableServiceProviders.length > 0) - verify (invalidPlugin.availableServiceProviders.indexOf('qmlgeo.test.plugin') > -1) // at least test plugin must be present - - // invalid plugins should have no features - verify(invalidPlugin.isAttached) - verify(!(invalidPlugin.supportsMapping())) - verify(!(invalidPlugin.supportsGeocoding())) - verify(!(invalidPlugin.supportsRouting())) - verify(!(invalidPlugin.supportsPlaces())) - - if (invalidPlugin.availableServiceProviders.indexOf('qmlgeo.test.plugin') > -1) { - verify(testPlugin.isAttached) - verify(testPlugin.supportsMapping()) - verify(testPlugin.supportsGeocoding()) - verify(testPlugin.supportsPlaces()) - verify(testPlugin.supportsRouting()) - } - - if (invalidPlugin.availableServiceProviders.indexOf('here')) { - verify(herePlugin.isAttached) - verify(herePlugin.supportsMapping(Plugin.OnlineMappingFeature)) - verify(herePlugin.supportsGeocoding(Plugin.OnlineGeocodingFeature)) - verify(herePlugin.supportsRouting(Plugin.OnlineRoutingFeature)) - } - - verify(!unattachedPlugin.isAttached) - - // test changing name of plugin - invalidAttachedSpy.clear() - compare(invalidAttachedSpy.count, 0) - invalidPlugin.name = 'qmlgeo.test.plugin' - tryCompare(invalidAttachedSpy, 'count', 1) - verify(invalidPlugin.isAttached) - - verify(invalidPlugin.supportsMapping()) - verify(invalidPlugin.supportsGeocoding()) - verify(invalidPlugin.supportsRouting()) - verify(invalidPlugin.supportsPlaces()) - - invalidPlugin.name = 'here' - compare(invalidAttachedSpy.count, 2) - verify(invalidPlugin.supportsMapping(Plugin.OnlineMappingFeature)) - verify(invalidPlugin.supportsGeocoding(Plugin.OnlineGeocodingFeature)) - verify(invalidPlugin.supportsRouting(Plugin.OnlineRoutingFeature)) - - invalidPlugin.name = '' - compare(invalidAttachedSpy.count, 2) - verify(!invalidPlugin.supportsMapping()) - verify(!invalidPlugin.supportsGeocoding()) - verify(!invalidPlugin.supportsRouting()) - verify(!invalidPlugin.supportsPlaces()) - } - - function test_required() { - // the required plugin should either get here or qmlgeo.test.plugin - // either way the name will be non-empty and it'll meet the spec - verify(requiredPlugin.name !== "") - verify(requiredPlugin.supportsMapping(requiredPlugin.required.mapping)) - verify(requiredPlugin.supportsGeocoding(requiredPlugin.required.geocoding)) - verify(requiredPlugin.supportsPlaces(requiredPlugin.required.places)) - verify(requiredPlugin.supportsNavigation(requiredPlugin.required.navigation)) - } - - function test_placesFeatures() { - verify(testPlugin.supportsPlaces(Plugin.SavePlaceFeature)) - verify(testPlugin.supportsPlaces(Plugin.SaveCategoryFeature)) - verify(testPlugin.supportsPlaces(Plugin.SearchSuggestionsFeature)) - verify(!testPlugin.supportsPlaces(Plugin.RemovePlaceFeature)) - } - - function test_locale() { - compare(herePlugin.locales, [Qt.locale().name]); - - //try assignment of a single locale - herePlugin.locales = "fr_FR"; - compare(herePlugin.locales, ["fr_FR"]); - - //try assignment of multiple locales - herePlugin.locales = ["fr_FR","en_US"]; - compare(herePlugin.locales, ["fr_FR","en_US"]); - - //check that assignment of empty locale list defaults to system locale - herePlugin.locales = []; - compare(herePlugin.locales, [Qt.locale().name]); - } - } -} diff --git a/tests/auto/declarative_core/tst_plugin_error.qml b/tests/auto/declarative_core/tst_plugin_error.qml deleted file mode 100644 index 50b03590..00000000 --- a/tests/auto/declarative_core/tst_plugin_error.qml +++ /dev/null @@ -1,61 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.0 -import QtTest 1.0 -import QtLocation 5.3 - -Item { - - Plugin { id: testPlugin; - name: "qmlgeo.test.plugin" - allowExperimental: true - parameters: [ - // Parms to guide the test plugin - PluginParameter { name: "error"; value: "1"}, - PluginParameter { name: "errorString"; value: "This error was expected. No worries !"} - ] - } - - Map { - id: map - } - - SignalSpy {id: errorSpy; target: map; signalName: "errorChanged"} - - TestCase { - name: "MappingManagerError" - function test_error() { - verify (map.error === Map.NoError); - map.plugin = testPlugin; - verify (map.error === Map.NotSupportedError); - verify (map.errorString == "This error was expected. No worries !"); - compare(errorSpy.count, 1); - } - } -} diff --git a/tests/auto/declarative_core/tst_position.qml b/tests/auto/declarative_core/tst_position.qml deleted file mode 100644 index 1bde0879..00000000 --- a/tests/auto/declarative_core/tst_position.qml +++ /dev/null @@ -1,99 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.0 -import QtTest 1.0 -import QtPositioning 5.3 - -TestCase { - id: testCase - - name: "Position" - - Position { id: defaultPosition } - - SignalSpy { id: latitudeValidSpy; target: defaultPosition; signalName: "latitudeValidChanged" } - SignalSpy { id: longitudeValidSpy; target: defaultPosition; signalName: "longitudeValidChanged" } - SignalSpy { id: altitudeValidSpy; target: defaultPosition; signalName: "altitudeValidChanged" } - SignalSpy { id: timestampSpy; target: defaultPosition; signalName: "timestampChanged" } - SignalSpy { id: speedSpy; target: defaultPosition; signalName: "speedChanged" } - SignalSpy { id: speedValidSpy; target: defaultPosition; signalName: "speedValidChanged" } - SignalSpy { id: coordinateSpy; target: defaultPosition; signalName: "coordinateChanged" } - SignalSpy { id: horizontalAccuracySpy; target: defaultPosition; signalName: "horizontalAccuracyChanged" } - SignalSpy { id: horizontalAccuracyValidSpy; target: defaultPosition; signalName: "horizontalAccuracyValidChanged" } - SignalSpy { id: verticalAccuracySpy; target: defaultPosition; signalName: "verticalAccuracyChanged" } - SignalSpy { id: verticalAccuracyValidSpy; target: defaultPosition; signalName: "verticalAccuracyValidChanged" } - SignalSpy { id: directionSpy; target: defaultPosition; signalName: "directionChanged" } - SignalSpy { id: verticalSpeedSpy; target: defaultPosition; signalName: "verticalSpeedChanged" } - - function test_defaults() { - compare(defaultPosition.latitudeValid, false); - compare(defaultPosition.longitudeValid, false); - compare(defaultPosition.altitudeValid, false); - compare(defaultPosition.speedValid, false); - compare(defaultPosition.horizontalAccuracyValid, false); - compare(defaultPosition.verticalAccuracyValid, false); - verify(!defaultPosition.directionValid); - verify(isNaN(defaultPosition.direction)); - verify(!defaultPosition.verticalSpeedValid); - verify(isNaN(defaultPosition.verticalSpeed)); - } - - function test_modifiers() { - latitudeValidSpy.clear(); - longitudeValidSpy.clear(); - altitudeValidSpy.clear(); - timestampSpy.clear(); - speedSpy.clear(); - speedValidSpy.clear(); - coordinateSpy.clear(); - horizontalAccuracySpy.clear(); - horizontalAccuracyValidSpy.clear(); - verticalAccuracySpy.clear(); - verticalAccuracyValidSpy.clear(); - directionSpy.clear(); - verticalSpeedSpy.clear(); - - defaultPosition.horizontalAccuracy = 10; - compare(horizontalAccuracySpy.count, 1); - compare(horizontalAccuracyValidSpy.count, 1); - compare(defaultPosition.horizontalAccuracy, 10); - compare(defaultPosition.horizontalAccuracyValid, true); - - defaultPosition.verticalAccuracy = 10; - compare(verticalAccuracySpy.count, 1); - compare(verticalAccuracyValidSpy.count, 1); - compare(defaultPosition.verticalAccuracy, 10); - compare(defaultPosition.verticalAccuracyValid, true); - - // some extra precautions - compare(horizontalAccuracyValidSpy.count, 1); - compare(speedSpy.count, 0); - compare(speedValidSpy.count, 0); - } -} diff --git a/tests/auto/declarative_core/tst_positionsource.qml b/tests/auto/declarative_core/tst_positionsource.qml deleted file mode 100644 index 7b787a0c..00000000 --- a/tests/auto/declarative_core/tst_positionsource.qml +++ /dev/null @@ -1,227 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.0 -import QtTest 1.0 -import QtPositioning 5.14 - -TestCase { - id: testCase - - name: "PositionSource" - - PositionSource { id: defaultSource } - PositionSource - { - id: activeDefaultSource - active: true - } - - SignalSpy { id: defaultSourceSpy; target: defaultSource; signalName: "positionChanged" } - - function test_activeDefaultSource() { - wait(0); - verify(activeDefaultSource.name !== ""); - compare(activeDefaultSource.active, true); - } - - function test_invalidSource() { - activeDefaultSource.name = "invalid_positioning_source"; - verify(!activeDefaultSource.active); - verify(!activeDefaultSource.valid); - } - - function test_defaults() { - // at least the test.source plugin should be available - verify(defaultSource.name != ""); - compare(defaultSource.active, false); - } - - function test_inactive() { - defaultSourceSpy.clear(); - compare(defaultSourceSpy.count, 0); - wait(1000); - compare(defaultSourceSpy.count, 0); - } - - PositionSource { id: testSetSource; name: "nonexistent bogus plugin" } - SignalSpy { id: testingSourcePluginSpy; target: testSetSource; signalName: "nameChanged" } - - function test_setplugin() { - testingSourcePluginSpy.clear(); - - // On construction, if the provided source name is invalid, the default source will be - // used. Test that the source is valid as expected. - verify(testSetSource.name !== ""); - //we don't really know what the default source is named. - //It may not be "test.source" - var defaultSourceName = testSetSource.name; - verify(testSetSource.valid); - - // Test that setting name to "" will still use the default. - testSetSource.name = ""; - compare(testingSourcePluginSpy.count, 0); - compare(testSetSource.name, defaultSourceName); - verify(testSetSource.valid); - - testSetSource.name = "test.source"; - if (defaultSourceName === "test.source") - compare(testingSourcePluginSpy.count, 0); - compare(testSetSource.name, "test.source"); - verify(testSetSource.valid); - testingSourcePluginSpy.clear(); - - testSetSource.name = "bogus"; - compare(testingSourcePluginSpy.count, 1); - verify(!testSetSource.valid); - } - - PositionSource { id: testingSource; name: "test.source"; updateInterval: 1000 } - SignalSpy { id: updateSpy; target: testingSource; signalName: "positionChanged" } - SignalSpy { id: directionValidSpy; target: testingSource.position; signalName: "directionValidChanged" } - SignalSpy { id: directionSpy; target: testingSource.position; signalName: "directionChanged" } - - PositionSource { - id: testingSourceWParams - name: "test.source" - updateInterval: 1000 - PluginParameter { - id: altitudeParameter - name: "test.source.altitude" - value: 42.42 - } - } - - SignalSpy { id: updateSpyWParams; target: testingSourceWParams; signalName: "positionChanged" } - SignalSpy { id: directionValidSpyWParams; target: testingSourceWParams.position; signalName: "directionValidChanged" } - SignalSpy { id: directionSpyWParams; target: testingSourceWParams.position; signalName: "directionChanged" } - - PositionSource { id: testingSourceV1; name: "test.source.v1"; updateInterval: 1000 } - SignalSpy { id: updateSpyV1; target: testingSourceV1; signalName: "positionChanged" } - SignalSpy { id: directionValidSpyV1; target: testingSourceV1.position; signalName: "directionValidChanged" } - SignalSpy { id: directionSpyV1; target: testingSourceV1.position; signalName: "directionChanged" } - - function test_updateInterval() { - testingSource.updateInterval = 1000; - compare(testingSource.updateInterval, 1000); - testingSource.updateInterval = 1200; - compare(testingSource.updateInterval, 1200); - testingSource.updateInterval = 800; - compare(testingSource.updateInterval, 1000); - } - - function test_preferredPositioningMethods() { - testingSource.preferredPositioningMethods = PositionSource.AllPositioningMethods; - compare(testingSource.preferredPositioningMethods, PositionSource.AllPositioningMethods); - testingSource.preferredPositioningMethods = PositionSource.SatellitePositioningMethods; - compare(testingSource.preferredPositioningMethods, PositionSource.SatellitePositioningMethods); - testingSource.preferredPositioningMethods = PositionSource.NonSatellitePositioningMethods; - compare(testingSource.preferredPositioningMethods, PositionSource.NonSatellitePositioningMethods); - } - - function test_updates() { - updateSpyV1.clear(); - - compare(directionValidSpyV1.count, 0) - compare(directionSpyV1.count, 0) - - testingSourceV1.active = true; - - tryCompare(updateSpyV1, "count", 1, 1500); - compare(testingSourceV1.position.coordinate.longitude, 0.1); - compare(testingSourceV1.position.coordinate.latitude, 0.1); - compare(directionValidSpyV1.count, 1) - compare(directionSpyV1.count, 1) - fuzzyCompare(testingSourceV1.position.direction, 45, 0.1) - verify(!testingSourceV1.position.speedValid) - verify(isNaN(testingSourceV1.position.speed)) - - tryCompare(updateSpyV1, "count", 2, 1500); - compare(testingSourceV1.position.coordinate.longitude, 0.2); - compare(testingSourceV1.position.coordinate.latitude, 0.2); - compare(directionValidSpyV1.count, 1) - compare(directionSpyV1.count, 2) - fuzzyCompare(testingSourceV1.position.direction, 45, 0.1) - verify(testingSourceV1.position.speedValid) - verify(testingSourceV1.position.speed > 10000) - - testingSourceV1.active = false; - wait(2500); - compare(updateSpyV1.count, 2); - compare(testingSourceV1.position.coordinate.longitude, 0.2); - compare(testingSourceV1.position.coordinate.latitude, 0.2); - compare(directionValidSpyV1.count, 1) - compare(directionSpyV1.count, 2) - fuzzyCompare(testingSourceV1.position.direction, 45, 0.1) - verify(testingSourceV1.position.speedValid) - verify(testingSourceV1.position.speed > 10000) - } - - function test_updates_w_params() { - updateSpyWParams.clear(); - - compare(directionValidSpyWParams.count, 0) - compare(directionSpyWParams.count, 0) - compare(testingSourceWParams.backendProperty("altitude"), altitudeParameter.value) - testingSourceWParams.active = true; - - tryCompare(updateSpyWParams, "count", 1, 1500); - compare(testingSourceWParams.position.coordinate.longitude, 0.1); - compare(testingSourceWParams.position.coordinate.latitude, 0.1); - compare(testingSourceWParams.position.coordinate.altitude, altitudeParameter.value); - compare(directionValidSpyWParams.count, 1) - compare(directionSpyWParams.count, 1) - fuzzyCompare(testingSourceWParams.position.direction, 45, 0.1) - verify(!testingSourceWParams.position.speedValid) - verify(isNaN(testingSourceWParams.position.speed)) - testingSourceWParams.setBackendProperty("altitude", 24.24) - - tryCompare(updateSpyWParams, "count", 2, 1500); - compare(testingSourceWParams.position.coordinate.longitude, 0.2); - compare(testingSourceWParams.position.coordinate.latitude, 0.2); - compare(testingSourceWParams.position.coordinate.altitude, 24.24); - compare(directionValidSpyWParams.count, 1) - compare(directionSpyWParams.count, 2) - fuzzyCompare(testingSourceWParams.position.direction, 45, 0.1) - verify(testingSourceWParams.position.speedValid) - verify(testingSourceWParams.position.speed > 10000) - compare(testingSourceWParams.backendProperty("altitude"), 24.24) - - testingSourceWParams.active = false; - wait(2500); - compare(updateSpyWParams.count, 2); - compare(testingSourceWParams.position.coordinate.longitude, 0.2); - compare(testingSourceWParams.position.coordinate.latitude, 0.2); - compare(testingSourceWParams.position.coordinate.altitude, 24.24); - compare(directionValidSpyWParams.count, 1) - compare(directionSpyWParams.count, 2) - fuzzyCompare(testingSourceWParams.position.direction, 45, 0.1) - verify(testingSourceWParams.position.speedValid) - verify(testingSourceWParams.position.speed > 10000) - } -} diff --git a/tests/auto/declarative_core/tst_ratings.qml b/tests/auto/declarative_core/tst_ratings.qml deleted file mode 100644 index 5628432f..00000000 --- a/tests/auto/declarative_core/tst_ratings.qml +++ /dev/null @@ -1,75 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtTest 1.0 -import QtLocation 5.3 -import "utils.js" as Utils - -TestCase { - id: testCase - - name: "Ratings" - - Ratings { id: emptyRatings } - - function test_empty() { - compare(emptyRatings.average, 0.0); - compare(emptyRatings.maximum, 0.0); - compare(emptyRatings.count, 0); - } - - Ratings { - id: qmlRatings - - average: 3.5 - maximum: 5.0 - count: 7 - } - - function test_qmlConstructedRatings() { - compare(qmlRatings.average, 3.5); - compare(qmlRatings.maximum, 5.0); - compare(qmlRatings.count, 7); - } - - Ratings { - id: testRatings - } - - function test_setAndGet_data() { - return [ - { tag: "average", property: "average", signal: "averageChanged", value: 4.5, reset: 0.0 }, - { tag: "maximum", property: "maximum", signal: "maximumChanged", value: 5.0, reset: 0.0 }, - { tag: "count", property: "count", signal: "countChanged", value: 10, reset: 0 }, - ]; - } - - function test_setAndGet(data) { - Utils.testObjectProperties(testCase, testRatings, data); - } -} diff --git a/tests/auto/declarative_core/tst_reviewmodel.qml b/tests/auto/declarative_core/tst_reviewmodel.qml deleted file mode 100644 index 192026fd..00000000 --- a/tests/auto/declarative_core/tst_reviewmodel.qml +++ /dev/null @@ -1,201 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.0 -import QtTest 1.0 -import QtLocation 5.3 -import "utils.js" as Utils - -TestCase { - id: testCase - name: "ReviewModel" - - Plugin { - id: testPlugin - name: "qmlgeo.test.plugin" - allowExperimental: true - parameters: [ - PluginParameter { - name: "initializePlaceData" - value: true - } - ] - } - - ReviewModel { - id: testModel - } - - Place { - id: testPlace - 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 }, - { tag: "batchSize", property: "batchSize", signal: "batchSizeChanged", value: 10, reset: 1 }, - ]; - } - - function test_setAndGet(data) { - Utils.testObjectProperties(testCase, testModel, data); - } - - function test_consecutive_fetch_data() { - return [ - { tag: "batchSize 1", batchSize: 1 }, - { tag: "batchSize 2", batchSize: 2 }, - { tag: "batchSize 5", batchSize: 5 }, - { tag: "batchSize 10", batchSize: 10 }, - ]; - } - - function test_consecutive_fetch(data) { - //Note: in javascript the months go from 0(Jan) to 11(Dec) - var expectedReviews = [ - { - "title": "Park View Review 1", - "text": "Park View Review 1 Text", - "dateTime": new Date(2004, 8, 22, 13, 1), - "language": "en", - "rating": 3.5, - "reviewId": "0001" - }, - { - "title": "Park View Review 2", - "text": "Park View Review 2 Text", - "dateTime": new Date(2005, 8, 14, 4, 17), - "language": "en", - "rating": 1, - "reviewId": "0002" - }, - { - "title": "Park View Review 3", - "text": "Park View Review 3 Text", - "dateTime": new Date(2005, 9, 14, 4, 12), - "language": "en", - "rating": 5, - "reviewId": "0003" - }, - { - "title": "", - "text": "", - "dateTime": new Date(""), - "language": "", - "rating": 0, - "reviewId": "" - }, - { - "title": "Park View Review 5", - "text": "Park View Review 5 Text", - "dateTime": new Date(2005, 10, 20, 14, 53), - "language": "en", - "rating": 2.3, - "reviewId": "0005" - } - ] - - var model = createModel(); - Utils.testConsecutiveFetch(testCase, model, parkViewHotel, expectedReviews, data); - model.destroy(); - } - - function test_reset() { - var model = createModel(); - Utils.testReset(testCase, model, parkViewHotel); - model.destroy(); - } - - function test_fetch_data() { - return [ - { - tag: "fetch all reviews in a single batch", - model: createModel(), - batchSize: 10, - place: parkViewHotel, - expectedTotalCount: 5, - expectedCount: 5 - }, - { - tag: "fetch from a place with no reviews", - 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.3; ReviewModel {}', - testCase, "reviewModel"); - } -} diff --git a/tests/auto/declarative_core/tst_routing.qml b/tests/auto/declarative_core/tst_routing.qml deleted file mode 100644 index 1d7c1e37..00000000 --- a/tests/auto/declarative_core/tst_routing.qml +++ /dev/null @@ -1,971 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.0 -import QtTest 1.0 -import QtLocation 5.12 -import QtPositioning 5.12 - -Item { - id: root - function cloneArray(a) { - var i = a.length - var arr = new Array(i) - while (i--) arr[i] = a[i]; - return arr - } - Plugin { id: testPlugin; name: "qmlgeo.test.plugin"; allowExperimental: true } - Plugin { id: errorPlugin; name: "qmlgeo.test.plugin"; allowExperimental: true - parameters: [ - PluginParameter { name: "error"; value: "1"}, - PluginParameter { name: "errorString"; value: "This error was expected. No worries !"} - ] - } - - property variant coordinate1: QtPositioning.coordinate(51, 0) - property variant coordinate2: QtPositioning.coordinate(52, 0) - - property variant boundingBox1: QtPositioning.rectangle() - property variant boundingBox2: QtPositioning.rectangle() - - property variant circle1: QtPositioning.circle() - property variant circle2: QtPositioning.circle(tr, 4000) - - Component.onCompleted: { - boundingBox1.topLeft = bl - boundingBox1.bottomRight = bl - boundingBox1.width = 10 - - boundingBox2.topLeft = bl - boundingBox2.bottomRight = bl - boundingBox2.width = 20 - } - - property variant bl: QtPositioning.coordinate(0, 0) - property variant tl: QtPositioning.coordinate(1, 0) - property variant tr: QtPositioning.coordinate(1, 1) - property variant br: QtPositioning.coordinate(0, 1) - property variant ntr: QtPositioning.coordinate(3, 3) - - property variant unitBox: QtPositioning.rectangle(tl, br) - - Route {id: emptyRoute} - TestCase { - name: "RouteManeuver RouteSegment and MapRoute" - RouteSegment {id: emptySegment} - RouteManeuver {id: emptyManeuver} - - // TODO enable when we have map route - //MapRoute {id: emptyMapRoute} - - property variant emptyBox: QtPositioning.rectangle() - - property variant emptyCoordinate: QtPositioning.coordinate() - - // TODO enable when we have map route - /* - SignalSpy {id: mapRouteDetailLevelSpy; target: emptyMapRoute; signalName: "detailLevelChanged"} - SignalSpy {id: mapRouteColorSpy; target: emptyMapRoute.border; signalName: "colorChanged"} - SignalSpy {id: mapRouteWidthSpy; target: emptyMapRoute.border; signalName: "widthChanged"} - SignalSpy {id: mapRouteRouteSpy; target: emptyMapRoute; signalName: "routeChanged"} - function test_maproute_defaults() { - compare(mapRouteRouteSpy.count, 0) - compare(mapRouteColorSpy.count, 0) - compare(mapRouteDetailLevelSpy.count, 0) - compare (emptyMapRoute.detailLevel, 6) - emptyMapRoute.border.color = 'green' - emptyMapRoute.detailLevel = 3 - compare(mapRouteRouteSpy.count, 0) - compare(mapRouteColorSpy.count, 1) - compare(mapRouteDetailLevelSpy.count, 1) - emptyMapRoute.border.color = 'green' - emptyMapRoute.detailLevel = 3 - compare(mapRouteColorSpy.count, 1) - compare(mapRouteDetailLevelSpy.count, 1) - emptyMapRoute.route = emptyRoute - compare(mapRouteRouteSpy.count, 1) - compare(emptyMapRoute.route, emptyRoute) - // width - compare(mapRouteWidthSpy.count, 0) - emptyMapRoute.border.width = 123 - compare(mapRouteWidthSpy.count, 1) - compare(emptyMapRoute.border.width, 123) - emptyMapRoute.border.width = 123 - compare(mapRouteWidthSpy.count, 1) - emptyMapRoute.border.width = -1 - compare(mapRouteWidthSpy.count, 1) - compare(emptyMapRoute.border.width, 123) - emptyMapRoute.border.width = 0 - compare(mapRouteWidthSpy.count, 1) - compare(emptyMapRoute.border.width, 123) - } - */ - - function test_route_defaults() { - compare(emptyRoute.travelTime, 0) - compare(emptyRoute.distance,0) - compare(emptyRoute.path.length,0) - compare(emptyRoute.segments.length,0) - compare(emptyRoute.bounds.topLeft.latitude, emptyBox.topLeft.latitude) - compare(emptyRoute.bounds.bottomRight.longitude, emptyBox.bottomRight.longitude) - } - - function test_routesegment_defaults() { - compare(emptySegment.travelTime, 0) - compare(emptySegment.distance, 0) - compare(emptySegment.path.length, 0) - compare(emptySegment.maneuver.valid, emptyManeuver.valid) - compare(emptySegment.maneuver.instructionText, emptyManeuver.instructionText) - compare(emptySegment.maneuver.waypointValid, emptyManeuver.waypointValid) - } - function test_maneuver_defaults() { - compare(emptyManeuver.valid, false) - compare(emptyManeuver.instructionText, "") - compare(emptyManeuver.direction, RouteManeuver.NoDirection) - compare(emptyManeuver.timeToNextInstruction,0) - compare(emptyManeuver.distanceToNextInstruction,0) - compare(emptyManeuver.waypoint.latitude, emptyCoordinate.latitude) - compare(emptyManeuver.waypoint.longitude, emptyCoordinate.longitude) - compare(emptyManeuver.position.latitude, emptyCoordinate.latitude) - compare(emptyManeuver.position.longitude, emptyCoordinate.longitude) - } - } - - TestCase { - name: "MapRouteModel and MapRouteQuery" - RouteModel {id: emptyModel} - RouteQuery {id: emptyQuery} - - function test_model_default_properties() { - compare (emptyModel.autoUpdate, false, "Automatic update") - compare (emptyModel.status, RouteModel.Null, "Model status") - compare (emptyModel.errorString, "", "Model error") - compare (emptyModel.error, RouteModel.NoError) - compare (emptyModel.count, 0, "Model count") - emptyModel.get(192) // don't do stupid - - compare (emptyQuery.numberAlternativeRoutes, 0, "Number of alternative routes") - compare (emptyQuery.travelModes, RouteQuery.CarTravel, "Travel mode") - compare (emptyQuery.routeOptimizations, RouteQuery.FastestRoute, "Route optimization") - compare (emptyQuery.segmentDetail, RouteQuery.BasicSegmentData) - compare (emptyQuery.maneuverDetail, RouteQuery.BasicManeuvers) - compare (emptyQuery.waypoints.length, 0, "Waypoints") - compare (emptyQuery.excludedAreas.length, 0, "excluded areas") - compare (emptyQuery.featureTypes.length, 0, "Feature types") - } - - SignalSpy {id: autoUpdateSpy; target: emptyModel; signalName: "autoUpdateChanged"} - SignalSpy {id: pluginSpy; target: emptyModel ; signalName: "pluginChanged"} - - SignalSpy {id: travelModesSpy; target: emptyQuery; signalName: "travelModesChanged"} - SignalSpy {id: waypointsSpy; target: emptyQuery; signalName: "waypointsChanged"} - SignalSpy {id: exclusionSpy; target: emptyQuery; signalName: "excludedAreasChanged"} - SignalSpy {id: featureTypesSpy; target: emptyQuery; signalName: "featureTypesChanged"} - SignalSpy {id: segmentDetailSpy; target: emptyQuery; signalName: "segmentDetailChanged"} - SignalSpy {id: maneuverDetailSpy; target: emptyQuery; signalName: "maneuverDetailChanged"} - SignalSpy {id: numberAlterNativeRoutesSpy; target: emptyQuery; signalName: "numberAlternativeRoutesChanged"} - SignalSpy {id: routeOptimizationsSpy; target: emptyQuery; signalName: "routeOptimizationsChanged"} - SignalSpy {id: queryDetailsChangedSpy; target: emptyQuery; signalName: "queryDetailsChanged"} - function test_model_setters() { - // Autoupdate - compare(autoUpdateSpy.count, 0) - emptyModel.autoUpdate = true - compare(autoUpdateSpy.count, 1) - compare(emptyModel.autoUpdate, true) - emptyModel.autoUpdate = true // mustn't retrigger 'changed' -signal - compare(autoUpdateSpy.count, 1) - emptyModel.autoUpdate = false - compare(autoUpdateSpy.count, 2) - - // Travelmodes - compare(travelModesSpy.count, 0) - emptyQuery.travelModes = RouteQuery.BicycleTravel - compare(travelModesSpy.count, 1) - compare(emptyQuery.travelModes, RouteQuery.BicycleTravel) - emptyQuery.travelModes = RouteQuery.BicycleTravel | RouteQuery.PedestrianTravel - compare(emptyQuery.travelModes, RouteQuery.BicycleTravel | RouteQuery.PedestrianTravel) - compare(travelModesSpy.count, 2) - compare(queryDetailsChangedSpy.count, 2) - - // Basic adding and removing of waypoint - queryDetailsChangedSpy.clear() - compare(waypointsSpy.count, 0) - emptyQuery.addWaypoint(coordinate1) - compare(waypointsSpy.count, 1) - compare(queryDetailsChangedSpy.count, 1) - emptyQuery.addWaypoint(coordinate1) - compare(waypointsSpy.count, 2) - compare(queryDetailsChangedSpy.count, 2) - compare(emptyQuery.waypoints.length, 2) - emptyQuery.removeWaypoint(coordinate1) - compare(waypointsSpy.count, 3) - compare(queryDetailsChangedSpy.count, 3) - compare(emptyQuery.waypoints.length, 1) - emptyQuery.removeWaypoint(coordinate2) // coordinate2 isn't in the list, must not impact - compare(waypointsSpy.count, 3) - compare(queryDetailsChangedSpy.count, 3) - emptyQuery.removeWaypoint(coordinate1) - compare(waypointsSpy.count, 4) - emptyQuery.removeWaypoint(coordinate1) // doesn't exist anymore, must not impact - compare(waypointsSpy.count, 4) - compare(emptyQuery.waypoints.length, 0) - // Check correct ordering of waypoints - waypointsSpy.clear() - emptyQuery.addWaypoint(coordinate1) - emptyQuery.addWaypoint(coordinate2) - emptyQuery.addWaypoint(coordinate1) - emptyQuery.addWaypoint(coordinate2) - compare(waypointsSpy.count, 4) - compare(emptyQuery.waypoints[0], coordinate1) - compare(emptyQuery.waypoints[1], coordinate2) - compare(emptyQuery.waypoints[2], coordinate1) - compare(emptyQuery.waypoints[3], coordinate2) - emptyQuery.removeWaypoint(coordinate1) // remove one from the middle, check that one added last is removed - compare(emptyQuery.waypoints[0], coordinate1) - compare(emptyQuery.waypoints[1], coordinate2) - compare(emptyQuery.waypoints[2], coordinate2) - waypointsSpy.clear() - emptyQuery.clearWaypoints() - compare(emptyQuery.waypoints.length, 0) - compare(waypointsSpy.count, 1) - - // Altering the waypoint contents should trigger signal - emptyQuery.clearWaypoints() - queryDetailsChangedSpy.clear(); - emptyQuery.addWaypoint(coordinate1) - compare(queryDetailsChangedSpy.count, 1); - - // verify coordinate is disconnected - emptyQuery.removeWaypoint(coordinate1) - compare (queryDetailsChangedSpy.count, 2) - - // verify that the same coordinate can be added to the waypoints - emptyQuery.addWaypoint(coordinate1) - compare(queryDetailsChangedSpy.count, 3); - emptyQuery.addWaypoint(coordinate1) - compare(queryDetailsChangedSpy.count, 4); - compare (emptyQuery.waypoints.length, 2) - queryDetailsChangedSpy.clear() - - // verify that removing duplicate coordinate leaves remaining ones - emptyQuery.removeWaypoint(coordinate1) - compare (queryDetailsChangedSpy.count, 1) - compare (emptyQuery.waypoints.length, 1) - - // verify that clearing works - emptyQuery.clearWaypoints() - compare(queryDetailsChangedSpy.count, 2); - compare (emptyQuery.waypoints.length, 0) - - // Excluded areas - queryDetailsChangedSpy.clear() - compare(exclusionSpy.count, 0) - emptyQuery.addExcludedArea(boundingBox1) - compare(exclusionSpy.count, 1) - compare(queryDetailsChangedSpy.count, 1) - emptyQuery.addExcludedArea(boundingBox1) - // doesn't make sense to put same area twice - compare(exclusionSpy.count, 1) - compare(queryDetailsChangedSpy.count, 1) - compare(emptyQuery.excludedAreas.length, 1) - emptyQuery.removeExcludedArea(boundingBox1) - compare(exclusionSpy.count, 2) - compare(queryDetailsChangedSpy.count, 2) - compare(emptyQuery.excludedAreas.length, 0) - emptyQuery.removeExcludedArea(boundingBox2) // boundingBox2 isn't in the list, must not impact - compare(exclusionSpy.count, 2) - compare(queryDetailsChangedSpy.count, 2) - emptyQuery.removeExcludedArea(boundingBox1) // doesn't exist anymore, must not impact - compare(exclusionSpy.count, 2) - compare(queryDetailsChangedSpy.count, 2) - // Check correct ordering of exclusion - exclusionSpy.clear() - emptyQuery.addExcludedArea(boundingBox1) - emptyQuery.addExcludedArea(boundingBox2) - emptyQuery.addExcludedArea(boundingBox1) - emptyQuery.addExcludedArea(boundingBox2) - compare(exclusionSpy.count, 2) - compare(emptyQuery.excludedAreas[0], boundingBox1) - compare(emptyQuery.excludedAreas[1], boundingBox2) - emptyQuery.removeExcludedArea(boundingBox1) // remove first and check all geos ok - compare(emptyQuery.excludedAreas[0], boundingBox2) - exclusionSpy.clear() - emptyQuery.clearExcludedAreas() - compare(emptyQuery.excludedAreas.length, 0) - compare(exclusionSpy.count, 1) - - // verify that clearing works - emptyQuery.addExcludedArea(unitBox); - compare(emptyQuery.excludedAreas.length, 1); - queryDetailsChangedSpy.clear(); - emptyQuery.clearExcludedAreas(); - compare(queryDetailsChangedSpy.count, 1); - compare(emptyQuery.excludedAreas.length, 0) - - // Feature types and weights - queryDetailsChangedSpy.clear() - compare(emptyQuery.featureTypes.length, 0) - compare(featureTypesSpy.count, 0) - emptyQuery.setFeatureWeight(RouteQuery.TollFeature, RouteQuery.AvoidFeatureWeight); - compare(featureTypesSpy.count, 1) - compare(queryDetailsChangedSpy.count, 1) - emptyQuery.setFeatureWeight(RouteQuery.HighwayFeature, RouteQuery.PreferFeatureWeight); - compare(featureTypesSpy.count, 2) - compare(queryDetailsChangedSpy.count, 2) - compare(emptyQuery.featureTypes.length, 2) - compare(emptyQuery.featureTypes[0], RouteQuery.TollFeature) - compare(emptyQuery.featureTypes[1], RouteQuery.HighwayFeature) - // Verify feature weights are as set - compare(emptyQuery.featureWeight(RouteQuery.TollFeature), RouteQuery.AvoidFeatureWeight); - compare(emptyQuery.featureWeight(RouteQuery.HighwayFeature), RouteQuery.PreferFeatureWeight); - // Neutralize a weight, feature should disappear - emptyQuery.setFeatureWeight(RouteQuery.TollFeature, RouteQuery.NeutralFeatureWeight); - compare(featureTypesSpy.count, 3) - compare(queryDetailsChangedSpy.count, 3) - compare(emptyQuery.featureTypes.length, 1) - compare(emptyQuery.featureWeight(RouteQuery.TollFeature), RouteQuery.NeutralFeatureWeight); - compare(emptyQuery.featureWeight(RouteQuery.HighwayFeature), RouteQuery.PreferFeatureWeight); - compare(emptyQuery.featureTypes[0], RouteQuery.HighwayFeature) - compare(emptyQuery.featureWeight(emptyQuery.featureTypes[0]), RouteQuery.PreferFeatureWeight) - compare(featureTypesSpy.count, 3) - compare(queryDetailsChangedSpy.count, 3) - compare(emptyQuery.featureTypes.length, 1) - - // Put some feature weights and then reset them with NoFeature - emptyQuery.setFeatureWeight(RouteQuery.FerryFeature, RouteQuery.RequireFeatureWeight); - emptyQuery.setFeatureWeight(RouteQuery.MotorPoolLaneFeature, RouteQuery.DisallowFeatureWeight); - compare(featureTypesSpy.count, 5) - compare(queryDetailsChangedSpy.count, 5) - compare(emptyQuery.featureTypes.length, 3) - emptyQuery.setFeatureWeight(RouteQuery.NoFeature, RouteQuery.NeutralFeatureWeight) - compare(featureTypesSpy.count, 6) - compare(queryDetailsChangedSpy.count, 6) - compare(emptyQuery.featureTypes.length, 0) - - // Segment details - queryDetailsChangedSpy.clear() - compare(segmentDetailSpy.count, 0) - compare(emptyQuery.segmentDetail, RouteQuery.BasicSegmentData) - emptyQuery.segmentDetail = RouteQuery.NoSegmentData - compare(segmentDetailSpy.count, 1) - compare(queryDetailsChangedSpy.count, 1) - compare(emptyQuery.segmentDetail, RouteQuery.NoSegmentData) - emptyQuery.segmentDetail = RouteQuery.NoSegmentData - compare(segmentDetailSpy.count, 1) - compare(queryDetailsChangedSpy.count, 1) - compare(emptyQuery.segmentDetail, RouteQuery.NoSegmentData) - - // Maneuver details - queryDetailsChangedSpy.clear() - compare(maneuverDetailSpy.count, 0) - compare(emptyQuery.maneuverDetail, RouteQuery.BasicManeuvers) - emptyQuery.maneuverDetail = RouteQuery.NoManeuvers - compare(maneuverDetailSpy.count, 1) - compare(queryDetailsChangedSpy.count, 1) - compare(emptyQuery.maneuverDetail, RouteQuery.NoManeuvers) - emptyQuery.maneuverDetail = RouteQuery.NoManeuvers - compare(maneuverDetailSpy.count, 1) - compare(queryDetailsChangedSpy.count, 1) - compare(emptyQuery.maneuverDetail, RouteQuery.NoManeuvers) - - // NumberAlternativeRoutes - queryDetailsChangedSpy.clear() - compare(numberAlterNativeRoutesSpy.count, 0) - compare(emptyQuery.numberAlternativeRoutes, 0) - emptyQuery.numberAlternativeRoutes = 2 - compare(numberAlterNativeRoutesSpy.count, 1) - compare(queryDetailsChangedSpy.count, 1) - compare(emptyQuery.numberAlternativeRoutes, 2) - emptyQuery.numberAlternativeRoutes = 2 - compare(numberAlterNativeRoutesSpy.count, 1) - compare(queryDetailsChangedSpy.count, 1) - compare(emptyQuery.numberAlternativeRoutes, 2) - - // Route optimization - queryDetailsChangedSpy.clear() - compare(routeOptimizationsSpy.count, 0) - compare(emptyQuery.routeOptimizations, RouteQuery.FastestRoute) - emptyQuery.routeOptimizations = RouteQuery.ShortestRoute - compare(routeOptimizationsSpy.count, 1) - compare(queryDetailsChangedSpy.count, 1) - compare(emptyQuery.routeOptimizations, RouteQuery.ShortestRoute) - emptyQuery.routeOptimizations = RouteQuery.ShortestRoute | RouteQuery.MostScenicRoute - compare(routeOptimizationsSpy.count, 2) - compare(queryDetailsChangedSpy.count, 2) - compare(emptyQuery.routeOptimizations, RouteQuery.ShortestRoute | RouteQuery.MostScenicRoute) - - // Must act gracefully - emptyModel.reset() - emptyModel.update() - - // Plugin - compare(pluginSpy.count, 0) - emptyModel.plugin = testPlugin - compare(pluginSpy.count, 1) - compare(emptyModel.plugin, testPlugin) - emptyModel.plugin = testPlugin - compare(pluginSpy.count, 1) - emptyModel.plugin = errorPlugin - compare(pluginSpy.count, 2) - - // Must act gracefully - emptyModel.reset() - emptyModel.update() - } - // Test that model acts gracefully when plugin is not set or is invalid - // (does not support routing) - RouteModel {id: errorModel; plugin: errorPlugin} - RouteModel {id: errorModelNoPlugin} - SignalSpy {id: countInvalidSpy; target: errorModel; signalName: "countChanged"} - SignalSpy {id: errorSpy; target: errorModel; signalName: "errorChanged"} - function test_error_plugin() { - // test plugin not set - compare(errorModelNoPlugin.error,RouteModel.NoError) - errorModelNoPlugin.update() - compare(errorModelNoPlugin.error,RouteModel.EngineNotSetError) - console.log(errorModelNoPlugin.errorString) - - //plugin set but otherwise not offering anything - compare(errorModel.error,RouteModel.EngineNotSetError) - compare(errorModel.errorString,"This error was expected. No worries !") - errorSpy.clear() - errorModel.update() - compare(errorModel.error,RouteModel.EngineNotSetError) - compare(errorModel.errorString,qsTr("Cannot route, route manager not set.")) - compare(errorSpy.count, 1) - errorSpy.clear() - errorModel.cancel() - compare(errorModel.error,RouteModel.NoError) - compare(errorModel.errorString,"") - compare(errorSpy.count, 1) - errorSpy.clear() - errorModel.reset() - compare(errorModel.error,RouteModel.NoError) - compare(errorModel.errorString,"") - compare(errorSpy.count, 0) - errorSpy.clear() - errorModel.update() - compare(errorModel.error,RouteModel.EngineNotSetError) - compare(errorModel.errorString,qsTr("Cannot route, route manager not set.")) - compare(errorSpy.count, 1) - errorSpy.clear() - var data = errorModel.get(-1) - compare(data, null) - } - } - - Plugin { - id: testPlugin_immediate; - name: "qmlgeo.test.plugin" - allowExperimental: true - parameters: [ - // Parms to guide the test plugin - PluginParameter { name: "gc_supported"; value: true}, - PluginParameter { name: "gc_finishRequestImmediately"; value: true}, - PluginParameter { name: "gc_validateWellKnownValues"; value: true} - ] - } - - Plugin { - id: testPlugin_slacker; - name: "qmlgeo.test.plugin" - allowExperimental: true - parameters: [ - // Parms to guide the test plugin - PluginParameter { name: "gc_finishRequestImmediately"; value: false} - ] - } - - Plugin { - id: testPlugin_slacker_alt - name: "qmlgeo.test.plugin" - allowExperimental: true - PluginParameter { name: "gc_finishRequestImmediately"; value: false} - PluginParameter { name: "gc_alternateGeoRoute"; value: true} - } - - Plugin { - id: basicRoutingPlugin_slacker; - name: "qmlgeo.test.plugin" - allowExperimental: true - parameters: [ - // Parms to guide the test plugin - PluginParameter { name: "gc_finishRequestImmediately"; value: false} - ] - } - - property variant rcoordinate1: QtPositioning.coordinate(50, 50) - property variant rcoordinate2: QtPositioning.coordinate(51, 52) - property variant rcoordinate3: QtPositioning.coordinate(53, 54) - property variant rcoordinate4: QtPositioning.coordinate(55, 56) - property variant rcoordinate5: QtPositioning.coordinate(57, 58) - - property variant fcoordinate1: QtPositioning.coordinate(60, 60) - property variant fcoordinate2: QtPositioning.coordinate(61, 62) - property variant fcoordinate3: QtPositioning.coordinate(63, 64) - property variant fcoordinate4: QtPositioning.coordinate(65, 66) - property variant fcoordinate5: QtPositioning.coordinate(67, 68) - - property variant f2coordinate1: QtPositioning.coordinate(60, 60) - property variant f2coordinate2: QtPositioning.coordinate(61, 62) - property variant f2coordinate3: QtPositioning.coordinate(63, 64) - - Waypoint { - id: waypoint1 - coordinate: QtPositioning.coordinate(70, 70) - bearing: 42 - } - - Waypoint { - id: waypoint2 - coordinate: QtPositioning.coordinate(71, 71) - bearing: 43 - - MapParameter { - id: param1 - type: "user_distance" - property real distance: 10 - } - } - - RouteQuery {id: routeQuery} - property var routeQueryDefaultWaypoints: [ - { latitude: 60, longitude: 60 }, - { latitude: 61, longitude: 62 }, - { latitude: 63, longitude: 64 }, - { latitude: 65, longitude: 66 }, - { latitude: 67, longitude: 68 } - ] - property var routeQuery2DefaultWaypoints: [ - f2coordinate1, - f2coordinate2, - f2coordinate3 - ] - RouteQuery { - id: filledRouteQuery - numberAlternativeRoutes: 0 - waypoints: routeQueryDefaultWaypoints - } - RouteQuery { - id: filledRouteQuery2 - numberAlternativeRoutes: 0 - waypoints: routeQuery2DefaultWaypoints - } - RouteModel { - id: routeModelAutomatic; - plugin: testPlugin_slacker; - query: filledRouteQuery; - autoUpdate: true - } - RouteModel { - id: routeModelAutomaticAltImpl; - plugin: testPlugin_slacker_alt; - query: filledRouteQuery; - autoUpdate: true - } - - SignalSpy {id: automaticRoutesSpy; target: routeModelAutomatic; signalName: "routesChanged" } - SignalSpy {id: automaticRoutesSpyAlt; target: routeModelAutomaticAltImpl; signalName: "routesChanged" } - - RouteModel {id: routeModel; plugin: testPlugin_immediate; query: routeQuery } - SignalSpy {id: testRoutesSpy; target: routeModel; signalName: "routesChanged"} - SignalSpy {id: testCountSpy; target: routeModel; signalName: "countChanged" } - SignalSpy {id: testStatusSpy; target: routeModel; signalName: "statusChanged"} - SignalSpy {id: testErrorStringSpy; target: routeModel; signalName: "errorChanged"} - SignalSpy {id: testErrorSpy; target: routeModel; signalName: "errorChanged"} - SignalSpy {id: testWaypointsSpy; target: routeQuery; signalName: "waypointsChanged"} - - RouteModel {id: routeModelSlack; plugin: basicRoutingPlugin_slacker; query: routeQuery } - SignalSpy {id: testRoutesSlackSpy; target: routeModelSlack; signalName: "routesChanged"} - SignalSpy {id: testCountSlackSpy; target: routeModelSlack; signalName: "countChanged" } - SignalSpy {id: testStatusSlackSpy; target: routeModelSlack; signalName: "statusChanged"} - SignalSpy {id: testErrorStringSlackSpy; target: routeModelSlack; signalName: "errorChanged"} - SignalSpy {id: testErrorSlackSpy; target: routeModelSlack; signalName: "errorChanged"} - SignalSpy {id: testPluginSlackSpy; target: routeModelSlack; signalName: "pluginChanged"} - - RouteModel {id: routeModelEquals; plugin: testPlugin_immediate; query: routeQuery } - - TestCase { - name: "Routing" - function clear_immediate_model() { - routeModel.reset() - testRoutesSpy.clear() - testCountSpy.clear() - testStatusSpy.clear() - testErrorStringSpy.clear() - testErrorSpy.clear() - } - function clear_slacker_model() { - routeModelSlack.reset() - testRoutesSlackSpy.clear() - testCountSlackSpy.clear() - testStatusSlackSpy.clear() - testErrorStringSlackSpy.clear() - testErrorSlackSpy.clear() - } - - function test_reset() { - clear_immediate_model(); - routeQuery.numberAlternativeRoutes = 72 // 'altroutes - 70' is the echoed errorcode - routeModel.update() - verify (testErrorStringSpy.count > 0) - verify (testErrorSpy.count > 0) - compare (routeModel.errorString, "error") - compare (routeModel.error, RouteModel.CommunicationError) - compare (routeModel.count, 0) - compare (testStatusSpy.count, 2) - compare (routeModel.status, RouteModel.Error) - routeModel.reset() - compare (routeModel.status, RouteModel.Null) - compare (routeModel.errorString, "") - compare (routeModel.error, RouteModel.NoError) - // Check that ongoing req is aborted - clear_slacker_model() - routeQuery.numberAlternativeRoutes = 3 - routeModelSlack.update() - wait (100) - routeModelSlack.reset() - wait (200) - compare (routeModelSlack.count, 0) - // Check that results are cleared - routeModelSlack.update() - tryCompare(routeModelSlack, "count", 3) // numberALternativeRoutes - routeModelSlack.reset() - compare (routeModelSlack.count, 0) - // Check that changing plugin resets any ongoing requests - clear_slacker_model() - routeQuery.numberAlternativeRoutes = 3 - compare (testPluginSlackSpy.count, 0) - routeModelSlack.update() - wait (100) - routeModelSlack.plugin = testPlugin_immediate - wait (200) - compare (routeModelSlack.count, 0) // should be no updates - compare (testPluginSlackSpy.count, 1) - // test that works - routeModelSlack.update() - compare (routeModelSlack.count, 3) - // return back - routeModelSlack.plugin = testPlugin_slacker - } - - function test_error_routing() { - // Basic immediate error - clear_immediate_model(); - routeQuery.numberAlternativeRoutes = 72 // 'altroutes - 70' is the echoed errorcode - routeModel.update() - compare (testErrorStringSpy.count, 1) - compare (testErrorSpy.count, 1) - compare (routeModel.errorString, "error") - compare (routeModel.error, RouteModel.CommunicationError) - compare (routeModel.count, 0) - compare (testStatusSpy.count, 2) - compare (routeModel.status, RouteModel.Error) - // Basic delayed error - clear_slacker_model() - routeQuery.numberAlternativeRoutes = 72 - routeModelSlack.update() - compare (testErrorStringSlackSpy.count, 0) - compare (testErrorSlackSpy.count, 0) - if (routeModelSlack.errorString == "") - tryCompare(testErrorStringSlackSpy, "count", 1) - else - tryCompare(testErrorStringSlackSpy, "count", 2) - compare (routeModelSlack.errorString, "error") - compare (routeModelSlack.error, RouteModel.CommunicationError) - compare (routeModelSlack.count, 0) - // check that we recover - routeQuery.numberAlternativeRoutes = 1 - routeModelSlack.update() - tryCompare(routeModelSlack, "count", 1) - compare (testCountSlackSpy.count, 1) - compare (routeModelSlack.errorString, "") - compare (routeModelSlack.error, RouteModel.NoError) - } - function test_basic_routing() { - compare (testRoutesSpy.count, 0) - compare (routeModel.errorString, "") - compare (routeModel.error, RouteModel.NoError) - compare (testCountSpy.count, 0) - compare (routeModel.count, 0) - compare (routeQuery.waypoints.length, 0) - compare (testWaypointsSpy.count, 0) - routeQuery.addWaypoint(rcoordinate1) - routeQuery.addWaypoint(rcoordinate2) - routeQuery.addWaypoint(rcoordinate3) - routeQuery.addWaypoint(rcoordinate4) - routeQuery.addWaypoint(rcoordinate5) - compare (testWaypointsSpy.count, 5) - compare (routeQuery.waypoints.length, 5) - routeQuery.numberAlternativeRoutes = 1 // how many routes to get back, > 70 indicates error - routeModel.update() - routeModelEquals.update() - tryCompare (testRoutesSpy, "count", 1) // 5 sec - tryCompare (testCountSpy, "count", 1) - compare (routeModel.count, 1) - // the test plugin echoes waypoints back as the path of the route: - compare (routeQuery.waypoints.length, 5) - compare (routeModel.get(0).path.length, 5) - compare (routeModel.get(0).path[0].latitude, routeQuery.waypoints[0].latitude) - // test Route.equals - var route1 = routeModel.get(0) - var route2 = routeModelEquals.get(0) - verify(route1 !== route2) - verify(route1.equals(route2)) - // check reset() functionality - routeModel.reset() - tryCompare (testRoutesSpy, "count", 2) // 5 sec - tryCompare (testCountSpy, "count", 2) - compare (routeModel.count, 0) - - // delayed responses - compare (testRoutesSlackSpy.count, 0) - compare (routeModelSlack.errorString, "") - compare (routeModel.error, RouteModel.NoError) - compare (testCountSlackSpy.count, 0) - compare (routeModelSlack.count, 0) - routeModelSlack.update() - wait (100) - compare (testRoutesSlackSpy.count, 0) - compare (testCountSlackSpy.count, 0) - tryCompare(testRoutesSlackSpy, "count", 1) - compare (testCountSlackSpy.count, 1) - compare(routeModelSlack.count, 1) - compare (routeModelSlack.get(0).path.length, 5) - compare (routeModelSlack.get(0).path[0].latitude, routeQuery.waypoints[0].latitude) - - // Frequent updates, previous requests are aborted - routeModelSlack.reset() - testRoutesSlackSpy.clear() - testCountSlackSpy.clear() - routeModelSlack.update() - wait (100) - compare(testRoutesSlackSpy.count, 0) - compare(testCountSlackSpy.count, 0) - routeModelSlack.update() - wait (100) - compare(testRoutesSlackSpy.count, 0) - compare(testCountSlackSpy.count, 0) - routeModelSlack.update() - wait (100) - compare(testRoutesSlackSpy.count, 0) - compare(testCountSlackSpy.count, 0) - routeModelSlack.update() - wait (100) - compare(testRoutesSlackSpy.count, 0) - compare(testCountSlackSpy.count, 0) - tryCompare(testRoutesSlackSpy, "count", 1) - compare(testCountSlackSpy.count, 1) - compare(routeModelSlack.count, 1) - - test_basic_routing_automatic(routeModelAutomatic, automaticRoutesSpy, "routeModelAutomatic") - test_basic_routing_automatic(routeModelAutomaticAltImpl, automaticRoutesSpyAlt, "routeModelAutomaticAltImpl") - } - - function test_basic_routing_automatic(model, spy, label) { - if (label === undefined) - return - console.log("testing",label) - // Autoupdate - spy.clear(); - filledRouteQuery.numberAlternativeRoutes = 1 // 'altroutes - 70' is the echoed errorcode - tryCompare (spy, "count", 1) // 5 sec - compare(model.count, 1) // There should be a route already - compare (model.get(0).path.length, 5) - compare (model.get(0).path[0].latitude, filledRouteQuery.waypoints[0].latitude) - - if (label === "routeModelAutomaticAltImpl") // Test that it is an altImpl - compare(model.get(0).travelTime, 123456) - - // Remove a waypoint and check that autoupdate works - filledRouteQuery.removeWaypoint(fcoordinate2) - tryCompare (spy, "count", 2) - compare (model.get(0).path.length, 4) - compare (model.get(0).path[0].latitude, fcoordinate1.latitude) - - // Add a waypoint and check that autoupdate works - filledRouteQuery.addWaypoint(fcoordinate2); - tryCompare (spy, "count", 3) - compare(model.count, 1); - compare(model.get(0).path.length, 5); - compare(model.get(0).path[0].latitude, filledRouteQuery.waypoints[0].latitude); - - // Change contents of a coordinate and check that autoupdate works - filledRouteQuery.waypoints = [ - { latitude: fcoordinate1.latitude + 1, longitude: fcoordinate1.longitude }, - { latitude: 61, longitude: 62 }, - { latitude: 63, longitude: 64 }, - { latitude: 65, longitude: 66 }, - { latitude: 67, longitude: 68 } - ]; - tryCompare (spy, "count", 4) - compare(model.get(0).path[0].latitude, fcoordinate1.latitude + 1) // new value should be echoed - - // Extra parameter - var param = Qt.createQmlObject ('import QtLocation 5.9; MapParameter { type : "test-traveltime"; property var requestedTime : 42}', root) - var initialParams = cloneArray(filledRouteQuery.quickChildren) - var modifiedParams = cloneArray(initialParams) - modifiedParams.push(param) - - filledRouteQuery.quickChildren = modifiedParams - tryCompare (spy, "count", 5) - if (label === "routeModelAutomaticAltImpl") - compare(model.get(0).travelTime, 123456) - else - compare(model.get(0).travelTime, 42) - param.requestedTime = 43 - tryCompare (spy, "count", 6) - if (label === "routeModelAutomaticAltImpl") - compare(model.get(0).travelTime, 123456) - else - compare(model.get(0).travelTime, 43) - filledRouteQuery.quickChildren = initialParams - tryCompare (spy, "count", 7) - if (label === "routeModelAutomaticAltImpl") - compare(model.get(0).travelTime, 123456) - else - compare(model.get(0).travelTime, 0) - var secondParam = Qt.createQmlObject ('import QtLocation 5.9; MapParameter { type : "foo"; property var bar : 42}', root) - modifiedParams.push(secondParam) - param.requestedTime = 44 - filledRouteQuery.quickChildren = modifiedParams - tryCompare (spy, "count", 8) - if (label === "routeModelAutomaticAltImpl") - compare(model.get(0).travelTime, 123456) - else - compare(model.get(0).travelTime, 44) - filledRouteQuery.quickChildren = initialParams - tryCompare (spy, "count", 9) - if (label === "routeModelAutomaticAltImpl") - compare(model.get(0).travelTime, 123456) - else - compare(model.get(0).travelTime, 0) - - /* Test waypoints */ - // Verify that bearing is NaN for coordinates - verify(isNaN(filledRouteQuery.waypointObjects()[0].bearing)) - var numWaypoints = filledRouteQuery.waypoints.length - // Add a waypoint with bearing - filledRouteQuery.addWaypoint(waypoint1) - tryCompare (spy, "count", 10) - compare(filledRouteQuery.waypointObjects()[numWaypoints].bearing, 42) - // testing Waypoint to coordinate conversion - compare(filledRouteQuery.waypoints[numWaypoints], filledRouteQuery.waypointObjects()[numWaypoints].coordinate) - waypoint1.latitude += 0.1 - compare(model.get(0).distance, 0) - tryCompare (spy, "count", 11) - numWaypoints++; - filledRouteQuery.addWaypoint(waypoint2) // waypoint2 contains a MapParameter with user_distance - numWaypoints++; - tryCompare (spy, "count", 12) - compare(filledRouteQuery.waypointObjects()[numWaypoints-1].bearing, 43) - compare(model.get(0).distance, 10) - waypoint1.latitude += 0.1 - tryCompare (spy, "count", 13) - waypoint2.latitude += 0.1 - tryCompare (spy, "count", 14) - filledRouteQuery.removeWaypoint(waypoint1) - tryCompare (spy, "count", 15) - waypoint2.latitude += 0.1 - tryCompare (spy, "count", 16) - waypoint1.latitude += 0.1 - tryCompare (spy, "count", 16) // No effect, now disconnected - // test with other props - waypoint2.longitude += 0.1 - tryCompare (spy, "count", 17) - waypoint2.altitude = 42 - tryCompare (spy, "count", 18) - waypoint2.bearing += 1 - tryCompare (spy, "count", 19) - compare(waypoint2.longitude, 71.1) - compare(waypoint2.altitude, 42) - compare(waypoint2.bearing, 44) - // test with map parameters - param1.distance = 42 - tryCompare (spy, "count", 20) - compare(model.get(0).distance, 42) - - - // Change query - model.query = filledRouteQuery2 - filledRouteQuery2.numberAlternativeRoutes = 3 - tryCompare (spy, "count", 21) - compare (model.get(0).path.length, 3) - - // Verify that the old query is disconnected internally ie. does not trigger update - filledRouteQuery.waypoints = [ - { latitude: fcoordinate1.latitude + 2, longitude: fcoordinate1.longitude }, - { latitude: 61, longitude: 62 }, - { latitude: 63, longitude: 64 }, - { latitude: 65, longitude: 66 }, - { latitude: 67, longitude: 68 } - ]; - wait(800) // wait to hope no further updates comes through - compare (spy.count, 21) - compare(model.get(0).path.length, 3); - - // departure time - verify(!model.get(0).extendedAttributes["tst_departureTime"]) - var invalidDate = new Date("abc"); // to create an invalid date - var validDate = new Date("2011-02-07T11:05:00"); - - filledRouteQuery2.departureTime = validDate - tryCompare(spy, "count", 22) - compare(model.get(0).extendedAttributes["tst_departureTime"], validDate) - - filledRouteQuery2.departureTime = invalidDate - tryCompare (spy, "count", 23) - verify(!model.get(0).extendedAttributes["tst_departureTime"]) - - // ReSetting - filledRouteQuery.numberAlternativeRoutes = 0 - filledRouteQuery2.numberAlternativeRoutes = 0 - filledRouteQuery.waypoints = routeQueryDefaultWaypoints - filledRouteQuery2.waypoints = routeQuery2DefaultWaypoints - - waypoint1.coordinate = QtPositioning.coordinate(70, 70) - waypoint2.bearing = 42 - waypoint2.coordinate = QtPositioning.coordinate(71, 71) - waypoint2.bearing = 43 - param1.distance = 10 - } - - - - function test_route_query_handles_destroyed_qml_objects() { - var coordinate = QtPositioning.coordinate(11, 52); - routeQuery.addWaypoint(coordinate); - wait(300); - routeQuery.clearWaypoints(); - } - } -} - - - - diff --git a/tests/auto/declarative_core/tst_supplier.qml b/tests/auto/declarative_core/tst_supplier.qml deleted file mode 100644 index 3fcb0d1f..00000000 --- a/tests/auto/declarative_core/tst_supplier.qml +++ /dev/null @@ -1,100 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.0 -import QtTest 1.0 -import QtLocation 5.3 -import "utils.js" as Utils - -TestCase { - id: testCase - - name: "Supplier" - - Supplier { id: emptySupplier } - - function test_empty() { - compare(emptySupplier.supplierId, ""); - compare(emptySupplier.name, ""); - compare(emptySupplier.url, ""); - verify(emptySupplier.icon); - } - - Supplier { - id: qmlSupplier - - supplierId: "test-supplier-id" - name: "Test Supplier" - url: "http://example.com/test-supplier-id" - - icon: Icon { - Component.onCompleted: { - parameters.singleUrl = "http://example.com/icons/test-supplier.png" - } - } - } - - function test_qmlConstructedSupplier() { - compare(qmlSupplier.supplierId, "test-supplier-id"); - compare(qmlSupplier.name, "Test Supplier"); - compare(qmlSupplier.url, "http://example.com/test-supplier-id"); - verify(qmlSupplier.icon); - compare(qmlSupplier.icon.parameters.singleUrl, "http://example.com/icons/test-supplier.png"); - } - - Supplier { - id: testSupplier - } - - Plugin { - id: testPlugin - name: "qmlgeo.test.plugin" - allowExperimental: true - } - - Plugin { - id: invalidPlugin - } - - Icon { - id: testIcon - } - - function test_setAndGet_data() { - return [ - { tag: "name", property: "name", signal: "nameChanged", value: "Test Supplier", reset: "" }, - { tag: "supplierId", property: "supplierId", signal: "supplierIdChanged", value: "test-supplier-id-1", reset: "" }, - { tag: "url", property: "url", signal: "urlChanged", value: "http://example.com/test-supplier-id-1", reset: "" }, - { tag: "icon", property: "icon", signal: "iconChanged", value: testIcon } - ]; - } - - function test_setAndGet(data) { - Utils.testObjectProperties(testCase, testSupplier, data); - } -} diff --git a/tests/auto/declarative_core/tst_user.qml b/tests/auto/declarative_core/tst_user.qml deleted file mode 100644 index 1453c41a..00000000 --- a/tests/auto/declarative_core/tst_user.qml +++ /dev/null @@ -1,71 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtTest 1.0 -import QtLocation 5.3 -import "utils.js" as Utils - -TestCase { - id: testCase - - name: "User" - - User { id: emptyUser } - - function test_empty() { - compare(emptyUser.userId, ""); - compare(emptyUser.name, ""); - } - - User { - id: qmlUser - - userId: "testuser" - name: "Test User" - } - - function test_qmlConstructedUser() { - compare(qmlUser.userId, "testuser"); - compare(qmlUser.name, "Test User"); - } - - User { - id: testUser - } - - function test_setAndGet_data() { - return [ - { tag: "userId", property: "userId", signal: "userIdChanged", value: "testuser", reset: "" }, - { tag: "name", property: "name", signal: "nameChanged", value: "Test User", reset: "" }, - ]; - } - - function test_setAndGet(data) { - Utils.testObjectProperties(testCase, testUser, data); - } -} diff --git a/tests/auto/declarative_core/utils.js b/tests/auto/declarative_core/utils.js deleted file mode 100644 index 2b7dca32..00000000 --- a/tests/auto/declarative_core/utils.js +++ /dev/null @@ -1,182 +0,0 @@ -.pragma library - -function compareArray(a, b) { - if (a.length !== b.length) - return false; - - for (var i = 0; i < a.length; ++i) { - var aMatched = false; - var bMatched = false; - - for (var j = 0; j < b.length; ++j) { - if (a[i] === b[j]) - aMatched = true; - if (b[i] === a[j]) - bMatched = true; - if (aMatched && bMatched) - break; - } - - if (!aMatched || !bMatched) - return false; - } - - return true; -} - -function testObjectProperties(testCase, testObject, data) { - var signalSpy = Qt.createQmlObject('import QtTest 1.0; SignalSpy {}', testCase, "SignalSpy"); - signalSpy.target = testObject; - signalSpy.signalName = data.signal; - - // set property to something new - testObject[data.property] = data.value; - if (data.array) { - if (data.expectedValue) { - testCase.verify(compareArray(testObject[data.property], data.expectedValue)); - testCase.compare(signalSpy.count, 1 + data.expectedValue.length); - } else { - testCase.verify(compareArray(testObject[data.property], data.value)); - testCase.compare(signalSpy.count, 1 + data.value.length); - } - - } else { - testCase.compare(testObject[data.property], data.value); - testCase.compare(signalSpy.count, 1); - } - - signalSpy.clear(); - - // set property to same value - testObject[data.property] = data.value; - if (data.array) { - if (data.expectedValue) { - testCase.verify(compareArray(testObject[data.property], data.expectedValue)); - testCase.compare(signalSpy.count, 1 + data.expectedValue.length); - } else { - testCase.verify(compareArray(testObject[data.property], data.value)); - testCase.compare(signalSpy.count, 1 + data.value.length); - } - - } else { - testCase.compare(testObject[data.property], data.value); - testCase.compare(signalSpy.count, 0); - } - - signalSpy.clear(); - - // reset property - if (data.reset === undefined) { - testObject[data.property] = null; - testCase.compare(testObject[data.property], null); - } else { - testObject[data.property] = data.reset; - if (data.array) - testCase.verify(compareArray(testObject[data.property], data.reset)); - else - testCase.compare(testObject[data.property], data.reset); - } - testCase.compare(signalSpy.count, 1); - signalSpy.destroy(); -} - -function compareObj(testCase, obj1, obj2) { - for (var propertyName in obj2) { - if (obj1[propertyName] !== undefined) { - if (propertyName === "dateTime" && isNaN(obj2["dateTime"].getTime())) - testCase.verify(isNaN(obj1["dateTime"].getTime())); - else - testCase.compare(obj1[propertyName], obj2[propertyName]) - } - } -} - -function testConsecutiveFetch(testCase, model, place, expectedValues, data) -{ - 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; import QtQml.Models 2.14; ' - + 'DelegateModel{ 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.batchSize = data.batchSize - model.place = place; - testCase.tryCompare(signalSpy, "count", 1); - signalSpy.clear(); - - var totalCount = model.totalCount; - testCase.compare(totalCount, 5); - testCase.compare(visDataModel.items.count, Math.min(data.batchSize, totalCount)); - - compareObj(testCase, visDataModel.items.get(0).model, expectedValues[0]); - - //fetch remaining items, in batchSize batches - while (visDataModel.items.count < totalCount) { - var startIndex = visDataModel.items.count - - //'creating' the last item will trigger a fetch - visDataModel.items.create(visDataModel.items.count - 1); - - testCase.tryCompare(visDataModel.items, "count", Math.min(totalCount, startIndex + data.batchSize)); - testCase.compare(signalSpy.count, 0); - testCase.compare(model.totalCount, totalCount); - - for (var i = startIndex; i < Math.min(totalCount, startIndex + data.batchSize); ++i) - compareObj(testCase, visDataModel.items.get(i).model, expectedValues[i]); - } - - visDataModel.destroy(); - signalSpy.destroy(); -} - -function testReset(testCase, model, place) -{ - var dataModel = Qt.createQmlObject('import QtQuick 2.0; import QtQml.Models 2.14; ' - + 'DelegateModel{ 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.tryCompare(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; import QtQml.Models 2.14; ' - + 'DelegateModel{ 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.tryCompare(signalSpy, "count", 1); - signalSpy.clear(); - testCase.compare(model.totalCount, data.expectedTotalCount); - testCase.compare(visDataModel.items.count, data.expectedCount); - - visDataModel.destroy(); - signalSpy.destroy(); -} diff --git a/tests/auto/declarative_geoshape/declarative_geoshape.pro b/tests/auto/declarative_geoshape/declarative_geoshape.pro deleted file mode 100644 index aa6647f5..00000000 --- a/tests/auto/declarative_geoshape/declarative_geoshape.pro +++ /dev/null @@ -1,11 +0,0 @@ -# QML tests in this directory must not depend on an OpenGL context. - -TEMPLATE = app -TARGET = tst_declarative_geoshape -CONFIG += qmltestcase -SOURCES += main.cpp - -QT += positioning quick - -OTHER_FILES = *.qml -TESTDATA = $$OTHER_FILES diff --git a/tests/auto/declarative_geoshape/main.cpp b/tests/auto/declarative_geoshape/main.cpp deleted file mode 100644 index ffc94454..00000000 --- a/tests/auto/declarative_geoshape/main.cpp +++ /dev/null @@ -1,30 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -QUICK_TEST_MAIN(declarative_geoshape) diff --git a/tests/auto/declarative_geoshape/tst_locationsingleton.qml b/tests/auto/declarative_geoshape/tst_locationsingleton.qml deleted file mode 100644 index b58eedfd..00000000 --- a/tests/auto/declarative_geoshape/tst_locationsingleton.qml +++ /dev/null @@ -1,347 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.0 -import QtTest 1.0 -import QtPositioning 5.2 -import QtLocation 5.5 - -Item { - id: testCase - - property variant coordinate1: QtPositioning.coordinate(1, 1) - property variant coordinate2: QtPositioning.coordinate(2, 2) - property variant coordinate3: QtPositioning.coordinate(80, 80) - - property variant emptyCircle: QtPositioning.circle() - property variant circle1: QtPositioning.circle(coordinate1, 200000) - - SignalSpy { id: circleChangedSpy; target: testCase; signalName: "emptyCircleChanged" } - - TestCase { - name: "Bounding circle" - function test_circle_defaults_and_setters() { - circleChangedSpy.clear(); - compare (emptyCircle.radius, -1) - compare (circle1.radius, 200000) - - emptyCircle.radius = 200 - compare(circleChangedSpy.count, 1); - emptyCircle.radius = 200; - compare(circleChangedSpy.count, 1); - - emptyCircle.center = coordinate1; - compare(circleChangedSpy.count, 2); - emptyCircle.center = coordinate1 - compare(circleChangedSpy.count, 2); - emptyCircle.center = coordinate2 - compare(circleChangedSpy.count, 3); - - emptyCircle.center = coordinate1 - emptyCircle.radius = 200000 - - compare(emptyCircle.contains(coordinate1), true); - compare(emptyCircle.contains(coordinate2), true); - compare(emptyCircle.contains(coordinate3), false); - } - } - - property variant trace1 : [ QtPositioning.coordinate(43.773175, 11.255386), - QtPositioning.coordinate(43.773546 , 11.255372) ] - property variant trace2 : [ QtPositioning.coordinate(43.773175, 11.255386), - QtPositioning.coordinate(43.773546 , 11.255372), - QtPositioning.coordinate(43.77453 , 11.255734)] - - - // coordinate unit square - property variant bl: QtPositioning.coordinate(0, 0) - property variant tl: QtPositioning.coordinate(1, 0) - property variant tr: QtPositioning.coordinate(1, 1) - property variant br: QtPositioning.coordinate(0, 1) - property variant ntr: QtPositioning.coordinate(3, 3) - - property variant invalid: QtPositioning.coordinate(100, 190) - property variant inside: QtPositioning.coordinate(0.5, 0.5) - property variant outside: QtPositioning.coordinate(2, 2) - - property variant box: QtPositioning.rectangle(tl, br) - - property variant coordinates: [bl, tl, tr, br] - property variant coordinates2: [bl, tl, tr, br, ntr] - property variant coordinates3: [tr] - property variant coordinates4: [invalid] - property variant coordinates5: [] - - property variant listBox: QtPositioning.rectangle(coordinates) - property variant listBox2: QtPositioning.rectangle(coordinates2) - property variant listBox3: QtPositioning.rectangle(coordinates3) - property variant listBox4: QtPositioning.rectangle(coordinates4) - property variant listBox5: QtPositioning.rectangle(coordinates5) - - property variant widthBox: QtPositioning.rectangle(inside, 1, 1); - - // C++ auto test exists for basics of bounding box, testing here - // only added functionality - TestCase { - name: "Bounding box" - function test_box_defaults_and_setters() { - compare (box.bottomRight.longitude, br.longitude) // sanity - compare (box.contains(bl), true) - compare (box.contains(inside), true) - compare (box.contains(outside), false) - box.topRight = ntr - compare (box.contains(outside), true) - - compare (listBox.isValid, true) - compare (listBox.contains(outside), false) - compare (listBox2.contains(outside), true) - compare (listBox3.isValid, true) - compare (listBox3.isEmpty, true) - compare (listBox4.isValid, false) - compare (listBox5.isValid, false) - - compare (widthBox.contains(inside), true) - compare (widthBox.contains(outside), false) - } - } - - TestCase { - name: "Shape" - - function test_shape_comparison_data() { - return [ - { tag: "invalid shape", shape1: QtPositioning.shape(), shape2: QtPositioning.shape(), result: true }, - { tag: "box equal", shape1: box, shape2: QtPositioning.rectangle(tl, br), result: true }, - { tag: "box not equal", shape1: box, shape2: QtPositioning.rectangle([inside, outside]), result: false }, - { tag: "box invalid shape", rect1: box, shape2: QtPositioning.shape(), result: false }, - { tag: "invalid rectangle", shape1: QtPositioning.rectangle(), shape2: QtPositioning.rectangle(), result: true }, - { tag: "invalid rectangle2", shape1: QtPositioning.rectangle(), shape2: QtPositioning.shape(), result: false }, - { tag: "circle1 equal", shape1: circle1, shape2: QtPositioning.circle(coordinate1, 200000), result: true }, - { tag: "circle1 not equal", shape1: circle1, shape2: QtPositioning.circle(coordinate2, 2000), result: false }, - { tag: "circle1 invalid shape", shape1: circle1, shape2: QtPositioning.shape(), result: false }, - { tag: "invalid circle", shape1: QtPositioning.circle(), shape2: QtPositioning.circle(), result: true }, - { tag: "invalid circle2", shape1: QtPositioning.circle(), shape2: QtPositioning.shape(), result: false } - ] - } - - function test_shape_comparison(data) { - compare(data.shape1 === data.shape2, data.result) - compare(data.shape1 !== data.shape2, !data.result) - compare(data.shape1 == data.shape2, data.result) - compare(data.shape1 != data.shape2, !data.result) - } - } - - TestCase { - name: "Conversions" - - function test_shape_circle_conversions() { - var circle = QtPositioning.shapeToCircle(QtPositioning.shape()) - verify(!circle.isValid) - circle = QtPositioning.shapeToCircle(QtPositioning.circle()) - verify(!circle.isValid) - circle = QtPositioning.shapeToCircle(QtPositioning.circle(tl, 10000)) - verify(circle.isValid) - compare(circle.center, tl) - compare(circle.radius, 10000) - circle = QtPositioning.shapeToCircle(QtPositioning.rectangle()) - verify(!circle.isValid) - circle = QtPositioning.shapeToCircle(QtPositioning.rectangle(tl, br)) - verify(!circle.isValid) - circle = QtPositioning.shapeToCircle(listBox) - verify(!circle.isValid) - } - - function test_shape_rectangle_conversions() { - var rectangle = QtPositioning.shapeToRectangle(QtPositioning.shape()) - verify(!rectangle.isValid) - rectangle = QtPositioning.shapeToRectangle(QtPositioning.circle()) - verify(!rectangle.isValid) - rectangle = QtPositioning.shapeToRectangle(QtPositioning.circle(tl, 10000)) - verify(!rectangle.isValid) - rectangle = QtPositioning.shapeToRectangle(QtPositioning.rectangle()) - verify(!rectangle.isValid) - rectangle = QtPositioning.shapeToRectangle(QtPositioning.rectangle(tl, br)) - verify(rectangle.isValid) - compare(rectangle.topLeft, tl) - compare(rectangle.bottomRight, br) - rectangle = QtPositioning.shapeToRectangle(listBox) - verify(rectangle.isValid) - } - - function test_shape_path_conversions() { - var path = QtPositioning.shapeToPath(QtPositioning.shape()) - verify(!path.isValid) - path = QtPositioning.shapeToPath(QtPositioning.circle()) - verify(!path.isValid) - path = QtPositioning.shapeToPath(QtPositioning.circle(tl, 10000)) - verify(!path.isValid) - path = QtPositioning.shapeToPath(QtPositioning.rectangle()) - verify(!path.isValid) - path = QtPositioning.shapeToPath(QtPositioning.rectangle(tl, br)) - verify(!path.isValid) - - path = QtPositioning.shapeToPath(QtPositioning.path()) - verify(!path.isValid) - path = QtPositioning.shapeToPath(QtPositioning.path(trace1, 1)) - verify(path.isValid) - path = QtPositioning.shapeToPath(QtPositioning.path(trace2, 2)) - verify(path.isValid) - verify(path !== QtPositioning.shapeToPath(QtPositioning.path(trace1, 1))) - compare(path, QtPositioning.shapeToPath(QtPositioning.path(trace2, 2))) - } - - function test_shape_polygon_conversions() { - var polygon = QtPositioning.shapeToPolygon(QtPositioning.shape()) - verify(!polygon.isValid) - polygon = QtPositioning.shapeToPolygon(QtPositioning.circle()) - verify(!polygon.isValid) - polygon = QtPositioning.shapeToPolygon(QtPositioning.circle(tl, 10000)) - verify(polygon.isValid) // fixed, polygon copy constructor can now initialize from a circle. - polygon = QtPositioning.shapeToPolygon(QtPositioning.rectangle()) - verify(!polygon.isValid) - polygon = QtPositioning.shapeToPolygon(QtPositioning.rectangle(tl, br)) - verify(polygon.isValid) // fixed, polygon copy constructor can now initialize from a rectangle. - - polygon = QtPositioning.shapeToPolygon(QtPositioning.polygon()) - verify(!polygon.isValid) - polygon = QtPositioning.shapeToPolygon(QtPositioning.polygon(trace1)) - verify(!polygon.isValid) // polygon needs 3 coords at least - polygon = QtPositioning.shapeToPolygon(QtPositioning.polygon(trace2)) - verify(polygon.isValid) - verify(polygon !== QtPositioning.shapeToPolygon(QtPositioning.polygon(trace1))) - compare(polygon, QtPositioning.shapeToPolygon(QtPositioning.polygon(trace2))) - } - } - - - MapPolyline { - id: mapPolyline - path: [ - { latitude: -27, longitude: 153.0 }, - { latitude: -27, longitude: 154.1 }, - { latitude: -28, longitude: 153.5 }, - { latitude: -29, longitude: 153.5 } - ] - } - - MapPolyline { - id: mapPolylineGeopath - } - - TestCase { - name: "MapPolyline path" - function test_path_operations() { - compare(mapPolyline.path[1].latitude, -27) - compare(mapPolyline.path[1].longitude, 154.1) - compare(mapPolyline.coordinateAt(1), QtPositioning.coordinate(-27, 154.1)) - compare(mapPolyline.path.length, mapPolyline.pathLength()) - - mapPolyline.removeCoordinate(1); - compare(mapPolyline.path[1].latitude, -28) - compare(mapPolyline.path[1].longitude, 153.5) - compare(mapPolyline.coordinateAt(1), QtPositioning.coordinate(-28, 153.5)) - compare(mapPolyline.path.length, mapPolyline.pathLength()) - - mapPolyline.addCoordinate(QtPositioning.coordinate(30, 153.1)) - compare(mapPolyline.path[mapPolyline.path.length-1].latitude, 30) - compare(mapPolyline.path[mapPolyline.path.length-1].longitude, 153.1) - compare(mapPolyline.containsCoordinate(QtPositioning.coordinate(30, 153.1)), true) - compare(mapPolyline.path.length, mapPolyline.pathLength()) - - mapPolyline.removeCoordinate(QtPositioning.coordinate(30, 153.1)) - compare(mapPolyline.path[mapPolyline.path.length-1].latitude, -29) - compare(mapPolyline.path[mapPolyline.path.length-1].longitude, 153.5) - compare(mapPolyline.containsCoordinate(QtPositioning.coordinate(30, 153.1)), false) - compare(mapPolyline.path.length, mapPolyline.pathLength()) - - mapPolyline.insertCoordinate(2, QtPositioning.coordinate(35, 153.1)) - compare(mapPolyline.path[2].latitude, 35) - compare(mapPolyline.path[2].longitude, 153.1) - compare(mapPolyline.containsCoordinate(QtPositioning.coordinate(35, 153.1)), true) - compare(mapPolyline.path.length, mapPolyline.pathLength()) - - mapPolyline.replaceCoordinate(2, QtPositioning.coordinate(45, 150.1)) - compare(mapPolyline.path[2].latitude, 45) - compare(mapPolyline.path[2].longitude, 150.1) - compare(mapPolyline.containsCoordinate(QtPositioning.coordinate(35, 153.1)), false) - compare(mapPolyline.containsCoordinate(QtPositioning.coordinate(45, 150.1)), true) - compare(mapPolyline.path.length, mapPolyline.pathLength()) - - mapPolyline.insertCoordinate(2, QtPositioning.coordinate(35, 153.1)) - compare(mapPolyline.coordinateAt(2).latitude, 35) - compare(mapPolyline.coordinateAt(2).longitude, 153.1) - compare(mapPolyline.containsCoordinate(QtPositioning.coordinate(35, 153.1)), true) - compare(mapPolyline.path.length, mapPolyline.pathLength()) - } - } - - TestCase { - name: "GeoPath path" - function test_qgeopath_path_operations() { - var geopath = QtPositioning.path() - - geopath.path = trace2 - compare(geopath.path.length, trace2.length) - - geopath.path = mapPolyline.path - compare(geopath.path.length, mapPolyline.pathLength()) - compare(geopath.boundingGeoRectangle(), mapPolyline.geoShape.boundingGeoRectangle()) - - mapPolylineGeopath.geoShape = geopath - compare(mapPolylineGeopath.pathLength(), mapPolyline.pathLength()) - compare(mapPolylineGeopath.geoShape.boundingGeoRectangle(), mapPolyline.geoShape.boundingGeoRectangle()) - - geopath.path = trace2 - geopath.path[0].longitude = 11.0 - compare(geopath.path.length, trace2.length) - compare(geopath.coordinateAt(0).latitude, trace2[0].latitude) - expectFail("", "Longitude comparison fails") - compare(geopath.coordinateAt(0).longitude, 11) - } - } - - TestCase { - name: "GeoPolygon path" - function test_qgeopolygon_path_operations() { - var geopolygon = QtPositioning.polygon() - - geopolygon.perimeter = trace2 - compare(geopolygon.perimeter.length, trace2.length) - - geopolygon.perimeter = mapPolyline.path - compare(geopolygon.perimeter.length, mapPolyline.pathLength()) - compare(geopolygon.boundingGeoRectangle(), mapPolyline.geoShape.boundingGeoRectangle()) - - geopolygon.perimeter = trace2 - compare(geopolygon.perimeter.length, trace2.length) - compare(geopolygon.coordinateAt(0).latitude, trace2[0].latitude) - compare(geopolygon.coordinateAt(0).longitude, trace2[0].longitude) - } - } -} diff --git a/tests/auto/declarative_location_core/declarative_location_core.pro b/tests/auto/declarative_location_core/declarative_location_core.pro new file mode 100644 index 00000000..9e1372df --- /dev/null +++ b/tests/auto/declarative_location_core/declarative_location_core.pro @@ -0,0 +1,14 @@ +# QML tests in this directory must not depend on an OpenGL context. +# QML tests that do require an OpenGL context must go in ../../declarative_ui. + +TEMPLATE = app +TARGET = tst_declarative_location_core +CONFIG += qmltestcase +SOURCES += main.cpp + +CONFIG -= app_bundle + +QT += location quick + +OTHER_FILES = *.qml *.js +TESTDATA = $$OTHER_FILES diff --git a/tests/auto/declarative_location_core/main.cpp b/tests/auto/declarative_location_core/main.cpp new file mode 100644 index 00000000..80261f14 --- /dev/null +++ b/tests/auto/declarative_location_core/main.cpp @@ -0,0 +1,48 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +static void initializeLibraryPath() +{ +#if QT_CONFIG(library) + // Set custom path since CI doesn't install test plugins +#ifdef Q_OS_WIN + QCoreApplication::addLibraryPath(QCoreApplication::applicationDirPath() + + QStringLiteral("/../../../../plugins")); +#else + QCoreApplication::addLibraryPath(QCoreApplication::applicationDirPath() + + QStringLiteral("/../../../plugins")); +#endif +#endif +} + +Q_COREAPP_STARTUP_FUNCTION(initializeLibraryPath) + +QUICK_TEST_MAIN(declarative_location_core) diff --git a/tests/auto/declarative_location_core/tst_category.qml b/tests/auto/declarative_location_core/tst_category.qml new file mode 100644 index 00000000..f0a14d6f --- /dev/null +++ b/tests/auto/declarative_location_core/tst_category.qml @@ -0,0 +1,237 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtQml.Models 2.14 +import QtTest 1.0 +import QtLocation 5.3 +import "utils.js" as Utils + +TestCase { + id: testCase + + name: "Category" + + Category { id: emptyCategory } + + function test_empty() { + compare(emptyCategory.categoryId, ""); + compare(emptyCategory.name, ""); + compare(emptyCategory.visibility, Category.UnspecifiedVisibility); + compare(emptyCategory.status, Category.Ready); + compare(emptyCategory.plugin, null); + verify(emptyCategory.icon); + } + + Category { + id: qmlCategory + + plugin: testPlugin + + categoryId: "test-category-id" + name: "Test Category" + visibility: Category.DeviceVisibility + + icon: Icon { + Component.onCompleted: { + parameters.singleUrl = "http://example.com/icons/test-category.png" + } + } + } + + function test_qmlConstructedCategory() { + compare(qmlCategory.categoryId, "test-category-id"); + compare(qmlCategory.name, "Test Category"); + compare(qmlCategory.visibility, Category.DeviceVisibility); + compare(qmlCategory.status, Category.Ready); + compare(qmlCategory.plugin, testPlugin); + verify(qmlCategory.icon); + compare(qmlCategory.icon.url(), "http://example.com/icons/test-category.png"); + compare(qmlCategory.icon.parameters.singleUrl, "http://example.com/icons/test-category.png"); + compare(qmlCategory.icon.plugin, qmlCategory.plugin); + } + + Category { + id: testCategory + } + + Plugin { + id: testPlugin + name: "qmlgeo.test.plugin" + allowExperimental: true + } + + Plugin { + id: invalidPlugin + } + + Icon { + id: testIcon + } + + Category { + id: saveCategory + + name: "Test Category" + visibility: Place.DeviceVisibility + } + + DelegateModel { + id: categoryModel + + model: CategoryModel { + plugin: testPlugin + } + delegate: Item { } + } + + function test_setAndGet_data() { + return [ + { tag: "name", property: "name", signal: "nameChanged", value: "Test Category", reset: "" }, + { tag: "categoryId", property: "categoryId", signal: "categoryIdChanged", value: "test-category-id-1", reset: "" }, + { tag: "visibility", property: "visibility", signal: "visibilityChanged", value: Place.PublicVisibility, reset: Place.UnspecifiedVisibility }, + { tag: "plugin", property: "plugin", signal: "pluginChanged", value: testPlugin }, + { tag: "icon", property: "icon", signal: "iconChanged", value: testIcon } + ]; + } + + function test_setAndGet(data) { + Utils.testObjectProperties(testCase, testCategory, data); + } + + function test_save() { + categoryModel.model.update(); + tryCompare(categoryModel.model, "status", CategoryModel.Ready); + compare(categoryModel.count, 0); + + saveCategory.plugin = testPlugin; + saveCategory.categoryId = "invalid-category-id"; + + saveCategory.save(); + + compare(saveCategory.status, Category.Saving); + verify(saveCategory.errorString().length === 0); + + tryCompare(saveCategory, "status", Category.Error); + verify(saveCategory.errorString().length > 0); + + // try again without an invalid categoryId + saveCategory.categoryId = ""; + saveCategory.save(); + + compare(saveCategory.status, Category.Saving); + + tryCompare(saveCategory, "status", Category.Ready); + verify(saveCategory.errorString().length === 0); + + verify(saveCategory.categoryId !== ""); + + + // Verify that the category was added to the model + categoryModel.model.update(); + compare(categoryModel.model.status, CategoryModel.Loading); + + tryCompare(categoryModel.model, "status", CategoryModel.Ready); + + compare(categoryModel.count, 1); + var modelCategory = categoryModel.model.data(categoryModel.modelIndex(0), + CategoryModel.CategoryRole); + compare(modelCategory.categoryId, saveCategory.categoryId); + compare(modelCategory.name, saveCategory.name); + + + // Remove a category + saveCategory.remove(); + + compare(saveCategory.status, Category.Removing); + + tryCompare(saveCategory, "status", Category.Ready); + verify(saveCategory.errorString().length === 0); + + + // Verify that the category was removed from the model + categoryModel.model.update(); + compare(categoryModel.model.status, CategoryModel.Loading); + + tryCompare(categoryModel.model, "status", CategoryModel.Ready); + + compare(categoryModel.count, 0); + + + // Try again, this time fail because category does not exist + saveCategory.remove(); + + compare(saveCategory.status, Category.Removing); + + tryCompare(saveCategory, "status", Category.Error); + + verify(saveCategory.errorString().length > 0); + } + + function test_saveWithoutPlugin() { + saveCategory.plugin = null; + saveCategory.categoryId = ""; + + saveCategory.save(); + + tryCompare(saveCategory, "status", Category.Error); + + verify(saveCategory.errorString().length > 0); + compare(saveCategory.categoryId, ""); + + saveCategory.plugin = invalidPlugin; + + saveCategory.save(); + + compare(saveCategory.status, Category.Error); + + verify(saveCategory.errorString().length > 0); + compare(saveCategory.categoryId, ""); + } + + function test_removeWithoutPlugin() { + saveCategory.plugin = null; + saveCategory.categoryId = "test-category-id"; + + saveCategory.remove(); + + compare(saveCategory.status, Category.Error); + + verify(saveCategory.errorString().length > 0); + compare(saveCategory.categoryId, "test-category-id"); + + saveCategory.plugin = invalidPlugin; + + saveCategory.remove(); + + compare(saveCategory.status, Category.Error); + + verify(saveCategory.errorString().length > 0); + compare(saveCategory.categoryId, "test-category-id"); + } +} diff --git a/tests/auto/declarative_location_core/tst_categorymodel.qml b/tests/auto/declarative_location_core/tst_categorymodel.qml new file mode 100644 index 00000000..59ec3e7c --- /dev/null +++ b/tests/auto/declarative_location_core/tst_categorymodel.qml @@ -0,0 +1,238 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtTest 1.0 +import QtLocation 5.3 +import "utils.js" as Utils + +TestCase { + id: testCase + + name: "CategoryModel" + + CategoryModel { + id: testModel + } + + Plugin { + id: testPlugin + name: "qmlgeo.test.plugin" + allowExperimental: true + parameters: [ + PluginParameter { + name: "initializePlaceData" + value: true + } + ] + } + + Plugin { + id: uninitializedPlugin + } + + Plugin { + id: nonExistantPlugin + name: "nonExistentName" + } + + function test_setAndGet_data() { + return [ + { tag: "plugin", property: "plugin", signal: "pluginChanged", value: testPlugin }, + { tag: "hierarchical", property: "hierarchical", signal: "hierarchicalChanged", value: false, reset: true }, + ]; + } + + function test_setAndGet(data) { + Utils.testObjectProperties(testCase, testModel, data); + } + + function test_hierarchicalModel() { + var modelSpy = Qt.createQmlObject('import QtTest 1.0; SignalSpy {}', testCase, "SignalSpy"); + var categoryModel = Qt.createQmlObject('import QtQuick 2.0; import QtQml.Models 2.14; import QtLocation 5.3;' + + 'DelegateModel { model: CategoryModel {} delegate: Item {} }', + testCase, "DelegateModel"); + + modelSpy.target = categoryModel.model; + modelSpy.signalName = "statusChanged"; + + compare(categoryModel.model.status, CategoryModel.Null); + compare(categoryModel.count, 0); + + + // set the plugin + categoryModel.model.plugin = testPlugin; + categoryModel.model.update(); + tryCompare(categoryModel.model, "status", CategoryModel.Loading); + compare(modelSpy.count, 1); + + tryCompare(categoryModel.model, "status", CategoryModel.Ready); + compare(modelSpy.count, 2); + compare(categoryModel.model.errorString(), ""); + + 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]); + + var parentCategory = categoryModel.model.data(categoryModel.modelIndex(i), + CategoryModel.ParentCategoryRole); + compare(parentCategory.name, "Accommodation"); + } + + 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; + categoryModel.model.update(); + + // check that the model is empty when an error is encountered + tryCompare(categoryModel, "count", 0); + compare(categoryModel.model.status, CategoryModel.Error); + } + + function test_flatModel() { + var modelSpy = Qt.createQmlObject('import QtTest 1.0; SignalSpy {}', testCase, "SignalSpy"); + var categoryModel = Qt.createQmlObject('import QtQuick 2.0; import QtQml.Models 2.14; import QtLocation 5.3;' + + 'DelegateModel { model: CategoryModel {} delegate: Item {} }', + testCase, "DelegateModel"); + + modelSpy.target = categoryModel.model; + modelSpy.signalName = "statusChanged"; + + compare(categoryModel.model.status, CategoryModel.Null); + compare(categoryModel.count, 0); + + + // set the plugin + categoryModel.model.hierarchical = false; + categoryModel.model.plugin = testPlugin; + + categoryModel.model.update(); + tryCompare(categoryModel.model, "status", CategoryModel.Loading); + compare(modelSpy.count, 1); + + tryCompare(categoryModel.model, "status", CategoryModel.Ready); + compare(modelSpy.count, 2); + + 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 the model is empty when an error is encountered + categoryModel.model.update(); + tryCompare(categoryModel, "count", 0); + compare(categoryModel.model.status, CategoryModel.Error); + } + + function test_error() { + var testModel = Qt.createQmlObject('import QtLocation 5.3; CategoryModel {}', testCase, "CategoryModel"); + + var statusChangedSpy = Qt.createQmlObject('import QtTest 1.0; SignalSpy {}', testCase, "SignalSpy"); + statusChangedSpy.target = testModel; + statusChangedSpy.signalName = "statusChanged"; + + //try updating without a plugin instance + testModel.update(); + tryCompare(statusChangedSpy, "count", 2); + compare(testModel.status, CategoryModel.Error); + statusChangedSpy.clear(); + //Aside: there is some difficulty in checking the transition to the Loading state + //since the model transitions from Loading to Error before the next event loop + //iteration. + + //try updating with an uninitialized plugin instance. + testModel.plugin = uninitializedPlugin; // uninitialized does not trigger update on setPlugin + testModel.update(); + tryCompare(statusChangedSpy, "count", 2); + compare(testModel.status, CategoryModel.Error); + statusChangedSpy.clear(); + + //try searching with plugin a instance + //that has been provided a non-existent name + tryCompare(statusChangedSpy, "count", 0); + testModel.plugin = nonExistantPlugin; +// testModel.update(); //QTBUG-70254 + tryCompare(statusChangedSpy, "count", 2); + compare(testModel.status, CategoryModel.Error); + } +} diff --git a/tests/auto/declarative_location_core/tst_contactdetail.qml b/tests/auto/declarative_location_core/tst_contactdetail.qml new file mode 100644 index 00000000..a91c19fa --- /dev/null +++ b/tests/auto/declarative_location_core/tst_contactdetail.qml @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtTest 1.0 +import QtLocation 5.3 +import "utils.js" as Utils + +TestCase { + id: testCase + + name: "ContactDetail" + + ContactDetail { id: emptyContactDetail } + + function test_empty() { + compare(emptyContactDetail.label, ""); + compare(emptyContactDetail.value, ""); + } + + ContactDetail { + id: qmlContactDetail + + label: "Phone" + value: "12345" + } + + function test_qmlConstructedContactDetail() { + compare(qmlContactDetail.label, "Phone"); + compare(qmlContactDetail.value, "12345"); + } + + ContactDetail { + id: testContactDetail + } + + function test_setAndGet_data() { + return [ + { tag: "label", property: "label", signal: "labelChanged", value: "Phone", reset: "" }, + { tag: "value", property: "value", signal: "valueChanged", value: "12345", reset: "" }, + ]; + } + + function test_setAndGet(data) { + Utils.testObjectProperties(testCase, testContactDetail, data); + } +} diff --git a/tests/auto/declarative_location_core/tst_editorialmodel.qml b/tests/auto/declarative_location_core/tst_editorialmodel.qml new file mode 100644 index 00000000..4cb38e5e --- /dev/null +++ b/tests/auto/declarative_location_core/tst_editorialmodel.qml @@ -0,0 +1,186 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtTest 1.0 +import QtLocation 5.3 +import "utils.js" as Utils + +TestCase { + id: testCase + + name: "EditorialModel" + + Plugin { + id: testPlugin + name: "qmlgeo.test.plugin" + allowExperimental: true + parameters: [ + PluginParameter { + name: "initializePlaceData" + value: true + } + ] + } + + EditorialModel { + id: testModel + } + + Place { + id: testPlace + 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 }, + { tag: "batchSize", property: "batchSize", signal: "batchSizeChanged", value: 10, reset: 1 }, + ]; + } + + function test_setAndGet(data) { + Utils.testObjectProperties(testCase, testModel, data); + } + + function test_consecutive_fetch_data() { + return [ + { tag: "batchSize 1", batchSize: 1 }, + { tag: "batchSize 2", batchSize: 2 }, + { tag: "batchSize 5", batchSize: 5 }, + { tag: "batchSize 10", batchSize: 10 }, + ]; + } + + function test_consecutive_fetch(data) { + 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, data); + 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.3; EditorialModel {}', + testCase, "editorialModel"); + } +} diff --git a/tests/auto/declarative_location_core/tst_geocoding.qml b/tests/auto/declarative_location_core/tst_geocoding.qml new file mode 100644 index 00000000..16843528 --- /dev/null +++ b/tests/auto/declarative_location_core/tst_geocoding.qml @@ -0,0 +1,665 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtTest 1.0 +import QtLocation 5.3 +import QtPositioning 5.2 + +Item { + Plugin { id: testPlugin1; name: "qmlgeo.test.plugin"; allowExperimental: true} + Plugin { id: errorPlugin; name: "qmlgeo.test.plugin"; allowExperimental: true + parameters: [ + PluginParameter { name: "error"; value: "1"}, + PluginParameter { name: "errorString"; value: "This error was expected. No worries !"} + ] + } + + + property variant coordinate1: QtPositioning.coordinate(51, 41) + property variant coordinate2: QtPositioning.coordinate(52, 42) + property variant coordinate3: QtPositioning.coordinate(53, 43) + property variant emptyCoordinate: QtPositioning.coordinate() + + property variant boundingBox1: QtPositioning.rectangle(coordinate1, coordinate2) + property variant boundingBox2: QtPositioning.rectangle(coordinate1, coordinate3) + property variant boundingCircle1: QtPositioning.circle(coordinate1, 100) + property variant boundingCircle2: QtPositioning.circle(coordinate2, 100) + + property variant emptyBox: QtPositioning.rectangle() + + GeocodeModel {id: emptyModel} + + Address {id: emptyAddress} + SignalSpy {id: querySpy; target: emptyModel; signalName: "queryChanged"} + SignalSpy {id: autoUpdateSpy; target: emptyModel; signalName: "autoUpdateChanged"} + SignalSpy {id: pluginSpy; target: emptyModel ; signalName: "pluginChanged"} + SignalSpy {id: boundsSpy; target: emptyModel; signalName: "boundsChanged"} + SignalSpy {id: limitSpy; target: emptyModel; signalName: "limitChanged"} + SignalSpy {id: offsetSpy; target: emptyModel; signalName: "offsetChanged"} + + TestCase { + id: testCase1 + name: "GeocodeModel" + function test_model_defaults_and_setters() { + // Query: address + compare (querySpy.count, 0) + emptyModel.query = address1 + compare (querySpy.count, 1) + compare (emptyModel.query.street, address1.street) + emptyModel.query = address1 + compare (querySpy.count, 1) + compare (emptyModel.query.street, address1.street) + // Query: coordinate + emptyModel.query = coordinate1 + compare (querySpy.count, 2) + compare (emptyModel.query.latitude, coordinate1.latitude) + emptyModel.query = coordinate1 + compare (querySpy.count, 2) + compare (emptyModel.query.latitude, coordinate1.latitude) + // Query: string + emptyModel.query = "Kuortane, Finland" + compare (querySpy.count, 3) + compare (emptyModel.query, "Kuortane, Finland") + emptyModel.query = "Kuortane, Finland" + compare (querySpy.count, 3) + compare (emptyModel.query, "Kuortane, Finland") + + // limit and offset + compare (limitSpy.count, 0) + compare (offsetSpy.count, 0) + compare(emptyModel.limit, -1) + compare(emptyModel.offset, 0) + emptyModel.limit = 2 + compare (limitSpy.count, 1) + emptyModel.limit = 2 + compare (limitSpy.count, 1) + emptyModel.offset = 10 + compare (offsetSpy.count, 1) + emptyModel.offset = 10 + compare (offsetSpy.count, 1) + + // bounding box + compare(boundsSpy.count, 0) + emptyModel.bounds = boundingBox1 + compare(boundsSpy.count, 1) + compare(emptyModel.bounds.topLeft.latitude, boundingBox1.topLeft.latitude) + compare(emptyModel.bounds.bottomRight.longitude, boundingBox1.bottomRight.longitude) + emptyModel.bounds = boundingBox1 + compare(boundsSpy.count, 1) + compare(emptyModel.bounds.topLeft.latitude, boundingBox1.topLeft.latitude) + compare(emptyModel.bounds.bottomRight.longitude, boundingBox1.bottomRight.longitude) + emptyModel.bounds = boundingBox2 + compare(boundsSpy.count, 2) + compare(emptyModel.bounds.topLeft.latitude, boundingBox2.topLeft.latitude) + compare(emptyModel.bounds.bottomRight.longitude, boundingBox2.bottomRight.longitude) + emptyModel.bounds = QtPositioning.rectangle(); + compare(boundsSpy.count, 3) + + + // bounding circle + boundsSpy.clear() + emptyModel.bounds = boundingCircle1 + compare(boundsSpy.count, 1) + compare(emptyModel.bounds.center.latitude, coordinate1.latitude) + emptyModel.bounds = boundingCircle1 + compare(boundsSpy.count, 1) + compare(emptyModel.bounds.center.latitude, coordinate1.latitude) + emptyModel.bounds = boundingCircle2 + compare(boundsSpy.count, 2) + compare(emptyModel.bounds.center.latitude, coordinate2.latitude) + var dynamicCircle = QtPositioning.circle(QtPositioning.coordinate(8, 9)); + emptyModel.bounds = dynamicCircle + compare(boundsSpy.count, 3) + compare(emptyModel.bounds.center.latitude, dynamicCircle.center.latitude) + + // status + compare (emptyModel.status, GeocodeModel.Null) + + // error + compare (emptyModel.errorString, "") + compare (emptyModel.error, GeocodeModel.NoError) + + // count + compare( emptyModel.count, 0) + + // auto update + compare (autoUpdateSpy.count, 0) + compare (emptyModel.autoUpdate, false) + emptyModel.autoUpdate = true + compare (emptyModel.autoUpdate, true) + compare (autoUpdateSpy.count, 1) + emptyModel.autoUpdate = true + compare (emptyModel.autoUpdate, true) + compare (autoUpdateSpy.count, 1) + + // mustn't crash even we don't have plugin + emptyModel.update() + + // Plugin + compare(pluginSpy.count, 0) + emptyModel.plugin = testPlugin1 + compare(pluginSpy.count, 1) + compare(emptyModel.plugin, testPlugin1) + emptyModel.plugin = testPlugin1 + compare(pluginSpy.count, 1) + emptyModel.plugin = errorPlugin + compare(pluginSpy.count, 2) + } + // Test that model acts gracefully when plugin is not set or is invalid + // (does not support geocoding) + GeocodeModel {id: errorModel; plugin: errorPlugin} + GeocodeModel {id: errorModelNoPlugin} + SignalSpy {id: countInvalidSpy; target: errorModel; signalName: "countChanged"} + SignalSpy {id: errorSpy; target: errorModel; signalName: "errorChanged"} + function test_error_plugin() { + // test plugin not set + compare(errorModelNoPlugin.error,GeocodeModel.NoError) + errorModelNoPlugin.update() + compare(errorModelNoPlugin.error,GeocodeModel.EngineNotSetError) + console.log(errorModelNoPlugin.errorString) + + //plugin set but otherwise not offering anything + compare(errorModel.error,GeocodeModel.EngineNotSetError) + compare(errorModel.errorString,"This error was expected. No worries !") + errorSpy.clear() + errorModel.update() + compare(errorModel.error,GeocodeModel.EngineNotSetError) + compare(errorModel.errorString,qsTr("Cannot geocode, geocode manager not set.")) + compare(errorSpy.count, 1) + errorSpy.clear() + errorModel.cancel() + compare(errorModel.error,GeocodeModel.NoError) + compare(errorModel.errorString,"") + compare(errorSpy.count, 1) + errorSpy.clear() + errorModel.reset() + compare(errorModel.error,GeocodeModel.NoError) + compare(errorModel.errorString,"") + compare(errorSpy.count, 0) + errorSpy.clear() + errorModel.update() + compare(errorModel.error,GeocodeModel.EngineNotSetError) + compare(errorModel.errorString,qsTr("Cannot geocode, geocode manager not set.")) + compare(errorSpy.count, 1) + errorSpy.clear() + var location = errorModel.get(-1) + compare(location, null) + } + + } + Address {id: address1; street: "wellknown street"; city: "expected city"; county: "2"} + Address {id: errorAddress1; street: "error"; county: "2"} // street is the error reason + + property variant rcoordinate1: QtPositioning.coordinate(51, 2) + property variant errorCoordinate1: QtPositioning.coordinate(73, 2) // (latiude mod 70) is the error code + property variant slackCoordinate1: QtPositioning.coordinate(60, 3) + Address {id: slackAddress1; street: "Slacker st"; city: "Lazy town"; county: "4"} + + property variant automaticCoordinate1: QtPositioning.coordinate(60, 3) + Address {id: automaticAddress1; street: "Auto st"; city: "Detroit"; county: "4"} + + Plugin { + id: testPlugin2; + name: "qmlgeo.test.plugin" + allowExperimental: true + parameters: [ + // Parms to guide the test plugin + PluginParameter { name: "supported"; value: true}, + PluginParameter { name: "finishRequestImmediately"; value: true}, + PluginParameter { name: "validateWellKnownValues"; value: true} + ] + } + + Plugin { + id: immediatePlugin; + name: "qmlgeo.test.plugin" + allowExperimental: true + parameters: [ + // Parms to guide the test plugin + PluginParameter { name: "supported"; value: true}, + PluginParameter { name: "finishRequestImmediately"; value: true}, + PluginParameter { name: "validateWellKnownValues"; value: false} + ] + } + + Plugin { + id: slackPlugin; + allowExperimental: true + name: "qmlgeo.test.plugin" + parameters: [ + // Parms to guide the test plugin + PluginParameter { name: "supported"; value: true}, + PluginParameter { name: "finishRequestImmediately"; value: false}, + PluginParameter { name: "validateWellKnownValues"; value: false} + ] + } + + Plugin { + id: autoPlugin; + allowExperimental: true + name: "qmlgeo.test.plugin" + parameters: [ + // Parms to guide the test plugin + PluginParameter { name: "supported"; value: true}, + PluginParameter { name: "finishRequestImmediately"; value: false}, + PluginParameter { name: "validateWellKnownValues"; value: false} + ] + } + + Plugin { + id: extendedPlugin; + name: "qmlgeo.test.plugin"; + allowExperimental: true + PluginParameter { name: "finishRequestImmediately"; value: false} + PluginParameter { name: "includeExtendedData"; value: true } + } + + GeocodeModel {id: testModel; plugin: testPlugin2} + SignalSpy {id: locationsSpy; target: testModel; signalName: "locationsChanged"} + SignalSpy {id: countSpy; target: testModel; signalName: "countChanged"} + SignalSpy {id: testQuerySpy; target: testModel; signalName: "queryChanged"} + SignalSpy {id: testStatusSpy; target: testModel; signalName: "statusChanged"} + + GeocodeModel {id: slackModel; plugin: slackPlugin; } + SignalSpy {id: locationsSlackSpy; target: slackModel; signalName: "locationsChanged"} + SignalSpy {id: countSlackSpy; target: slackModel; signalName: "countChanged"} + SignalSpy {id: querySlackSpy; target: slackModel; signalName: "queryChanged"} + SignalSpy {id: errorStringSlackSpy; target: slackModel; signalName: "errorChanged"} + SignalSpy {id: errorSlackSpy; target: slackModel; signalName: "errorChanged"} + SignalSpy {id: pluginSlackSpy; target: slackModel; signalName: "pluginChanged"} + + GeocodeModel {id: immediateModel; plugin: immediatePlugin} + SignalSpy {id: locationsImmediateSpy; target: immediateModel; signalName: "locationsChanged"} + SignalSpy {id: countImmediateSpy; target: immediateModel; signalName: "countChanged"} + SignalSpy {id: queryImmediateSpy; target: immediateModel; signalName: "queryChanged"} + SignalSpy {id: statusImmediateSpy; target: immediateModel; signalName: "statusChanged"} + SignalSpy {id: errorStringImmediateSpy; target: immediateModel; signalName: "errorChanged"} + SignalSpy {id: errorImmediateSpy; target: immediateModel; signalName: "errorChanged"} + + GeocodeModel {id: automaticModel; plugin: autoPlugin; query: automaticAddress1; autoUpdate: true} + SignalSpy {id: automaticLocationsSpy; target: automaticModel; signalName: "locationsChanged"} + + GeocodeModel {id: extendedModel; plugin: extendedPlugin; query: automaticAddress1; autoUpdate: true} + SignalSpy {id: extendedLocationsSpy; target: extendedModel; signalName: "locationsChanged"} + + TestCase { + name: "GeocodeModelGeocoding" + function clear_slack_model() { + slackModel.reset() + locationsSlackSpy.clear() + countSlackSpy.clear() + querySlackSpy.clear() + errorStringSlackSpy.clear() + errorSlackSpy.clear() + slackModel.limit = -1 + slackModel.offset = 0 + } + function clear_immediate_model() { + immediateModel.reset() + locationsImmediateSpy.clear() + countImmediateSpy.clear() + queryImmediateSpy.clear() + errorStringImmediateSpy.clear() + errorImmediateSpy.clear() + statusImmediateSpy.clear() + immediateModel.limit = -1 + immediateModel.offset = 0 + } + function test_reset() { + clear_immediate_model(); + immediateModel.query = errorAddress1 + immediateModel.update() + compare (immediateModel.errorString, errorAddress1.street) + compare (immediateModel.error, GeocodeModel.CommunicationError) + compare (immediateModel.count, 0) + compare (statusImmediateSpy.count, 2) + compare (immediateModel.status, GeocodeModel.Error) + immediateModel.reset() + compare (immediateModel.errorString, "") + compare (immediateModel.error, GeocodeModel.NoError) + compare (immediateModel.status, GeocodeModel.Null) + // Check that ongoing req is aborted + clear_slack_model() + slackModel.query = slackAddress1 + slackAddress1.county = "5" + slackModel.update() + tryCompare(countSlackSpy, "count", 0) + compare (locationsSlackSpy.count, 0) + compare (slackModel.count, 0) + slackModel.reset() + tryCompare(countSlackSpy, "count", 0) + compare (locationsSlackSpy.count, 0) + compare (slackModel.count, 0) + // Check that results are cleared + slackModel.update() + tryCompare(slackModel, "count", 5) + slackModel.reset() + compare (slackModel.count, 0) + // Check that changing plugin resets any ongoing requests + clear_slack_model() + slackModel.query = slackAddress1 + slackAddress1.county = "7" + compare (pluginSlackSpy.count, 0) + slackModel.update() + tryCompare(countSlackSpy, "count", 0) + slackModel.plugin = errorPlugin + tryCompare(countSlackSpy, "count", 0) + compare (pluginSlackSpy.count, 1) + // switch back and check that works + slackModel.plugin = slackPlugin + compare (pluginSlackSpy.count, 2) + slackModel.update() + tryCompare(countSlackSpy, "count", 0) + tryCompare(countSlackSpy, "count", 1) + } + function test_error_geocode() { + // basic immediate geocode error + clear_immediate_model() + immediateModel.query = errorAddress1 + immediateModel.update() + compare (errorStringImmediateSpy.count, 1) + compare (immediateModel.errorString, errorAddress1.street) + compare (immediateModel.error, GeocodeModel.CommunicationError) // county of the address (2) + compare (immediateModel.count, 0) + compare (statusImmediateSpy.count, 2) + compare (immediateModel.status, GeocodeModel.Error) + // basic delayed geocode error + clear_slack_model() + slackModel.query = errorAddress1 + errorAddress1.street = "error code 2" + slackModel.update() + compare (errorStringSlackSpy.count, 0) + compare (errorSlackSpy.count, 0) + tryCompare (errorStringSlackSpy, "count", 1) + tryCompare (errorSlackSpy, "count", 1) + compare (slackModel.errorString, errorAddress1.street) + compare (slackModel.error, GeocodeModel.CommunicationError) + compare (slackModel.count, 0) + // Check that we recover + slackModel.query = address1 + slackModel.update() + tryCompare(countSlackSpy, "count", 1) + compare (slackModel.count, 2) + compare (errorStringSlackSpy.count, 2) + compare (errorSlackSpy.count, 2) + compare (slackModel.errorString, "") + compare (slackModel.error, GeocodeModel.NoError) + } + + function test_error_reverse_geocode() { + // basic immediate geocode error + clear_immediate_model() + immediateModel.query = errorCoordinate1 + immediateModel.update() + if (immediateModel.errorString != "") + compare (errorStringImmediateSpy.count, 1) // the previous error is cleared upon update() + else + compare (errorImmediateSpy.count, 1) + compare (immediateModel.errorString, "error") + compare (immediateModel.error, GeocodeModel.ParseError) + compare (immediateModel.count, 0) + compare (statusImmediateSpy.count, 2) + compare (immediateModel.status, GeocodeModel.Error) + // basic delayed geocode error + clear_slack_model() + slackModel.query = errorCoordinate1 + slackModel.update() + compare (errorStringSlackSpy.count, 0) + compare (errorSlackSpy.count, 0) + if (slackModel.errorString != "") + tryCompare (errorStringSlackSpy, "count", 2) + else + tryCompare (errorStringSlackSpy, "count", 1) + compare (slackModel.errorString, "error") + compare (slackModel.error, GeocodeModel.ParseError) + compare (slackModel.count, 0) + // Check that we recover + slackModel.query = rcoordinate1 + slackModel.update() + tryCompare(countSlackSpy, "count", 1) + compare (slackModel.count, 2) + compare (errorStringSlackSpy.count, 2) + compare (errorSlackSpy.count, 2) + compare (slackModel.errorString, "") + compare (slackModel.error, GeocodeModel.NoError) + } + function test_address_geocode() { + testQuerySpy.clear() + locationsSpy.clear() + testStatusSpy.clear() + testModel.reset() + countSpy.clear() + compare (locationsSpy.count, 0) + compare (testModel.errorString, "") + compare (testModel.error, GeocodeModel.NoError) + compare (testModel.count, 0) + testModel.query = address1 + compare (testQuerySpy.count, 1) + testModel.update() + tryCompare (locationsSpy, "count", 1) // 5 sec + compare (testModel.errorString, "") + compare (testModel.error, GeocodeModel.NoError) + compare (testModel.count, 2) + compare (testQuerySpy.count, 1) + compare (testStatusSpy.count, 2) + compare (testModel.status, GeocodeModel.Ready) + compare (testModel.get(0).address.street, "wellknown street") + compare (testModel.get(0).address.city, "expected city") + } + + function test_freetext_geocode() { + testQuerySpy.clear() + locationsSpy.clear() + testStatusSpy.clear() + testModel.reset() + countSpy.clear() + compare (locationsSpy.count, 0) + compare (testModel.errorString, "") + compare (testModel.error, GeocodeModel.NoError) + compare (testModel.count, 0) + testModel.limit = 5 // number of places echoed back + testModel.offset = 10 // 'county' set in the places + // Test successful case + testModel.query = "Freetext geocode" + compare(testQuerySpy.count, 1) + testModel.update(); + tryCompare (locationsSpy, "count", 1) // 5 sec + tryCompare(countSpy, "count", 1) + tryCompare(testModel, "count", 5) + compare(testModel.get(0).address.county, "10") + // Test error case + testModel.query = "2" // tells plugin to echo error '2' + compare(testQuerySpy.count, 2) + testModel.update(); + tryCompare (locationsSpy, "count", 2) // 5 sec + tryCompare(countSpy, "count", 2) + tryCompare(testModel, "count", 0) + compare(testModel.errorString, "2") + compare (testModel.error, GeocodeModel.CommunicationError) + testModel.reset() + tryCompare(countSpy, "count", 2) + compare (testModel.count, 0) + } + + function test_delayed_freetext_geocode() { + clear_slack_model() + slackModel.limit = 5 // number of places echoed back + slackModel.offset = 10 // 'county' set in the places + // Basic successful case + slackModel.query = "freetext geocode" + compare (querySlackSpy.count, 1) + slackModel.update() + tryCompare(countSlackSpy, "count", 0) + compare (locationsSlackSpy.count, 0) + compare (slackModel.count, 0) + tryCompare(countSlackSpy, "count", 1); //waits up to 5s + compare (slackModel.count, 5) + compare (locationsSlackSpy.count, 1) + // Frequent updates, previous requests are aborted + slackModel.reset() + locationsSlackSpy.clear() + countSlackSpy.clear() + slackModel.update() + tryCompare(locationsSlackSpy, "count", 0) + compare(countSlackSpy.count, 0) + slackModel.update() + tryCompare(locationsSlackSpy, "count", 0) + compare(countSlackSpy.count, 0) + slackModel.update() + tryCompare(locationsSlackSpy, "count", 0) + compare(countSlackSpy.count, 0) + slackModel.update() + tryCompare(locationsSlackSpy, "count", 0) + compare(countSlackSpy.count, 0) + tryCompare(countSlackSpy, "count", 1); //waits up to 5s + compare (locationsSlackSpy.count, 1) + compare(slackModel.count, 5) // limit + } + + function test_geocode_auto_updates() { + compare (automaticModel.count, 4) // should be something already + compare (automaticLocationsSpy.count, 1) + // change query and its contents and verify that autoupdate occurs + automaticAddress1.county = 6 + tryCompare(automaticLocationsSpy, "count", 2) + compare (automaticModel.count, 6) + automaticAddress1.street = "The Avenue" + tryCompare(automaticLocationsSpy, "count", 3) + compare (automaticModel.count, 6) + automaticModel.query = automaticCoordinate1 + tryCompare(automaticLocationsSpy, "count", 4) + compare (automaticModel.count, 3) + } + + function test_geocode_extended_attributes() { + compare (extendedModel.count, 6) // should be something already + compare (extendedLocationsSpy.count, 3) + compare(extendedModel.get(0).extendedAttributes + ["QGeoCodingManagerEngineTest_locationExtendedAttribute"], 42) + // change query and its contents and verify that autoupdate occurs + extendedModel.query = automaticCoordinate1 + tryCompare(extendedLocationsSpy, "count", 4) + compare (extendedModel.count, 3) + compare(extendedModel.get(0).extendedAttributes + ["QGeoCodingManagerEngineTest_locationExtendedAttribute"], 42) + } + + function test_delayed_geocode() { + // basic delayed response + slackModel.reset() + querySlackSpy.clear() + countSlackSpy.clear() + locationsSlackSpy.clear() + slackModel.query = slackAddress1 + slackAddress1.county = "7" + compare (querySlackSpy.count, 1) + slackModel.update() + tryCompare(countSlackSpy, "count", 0) + compare (locationsSlackSpy.count, 0) + compare (slackModel.count, 0) + tryCompare(countSlackSpy, "count", 1); //waits up to 5s + compare (locationsSlackSpy.count, 1) + compare (slackModel.count, 7) // slackAddress1.county) + // Frequent updates, previous requests are aborted + slackModel.reset() + locationsSlackSpy.clear() + countSlackSpy.clear() + slackModel.update() + tryCompare(locationsSlackSpy, "count", 0) + compare(countSlackSpy.count, 0) + slackModel.update() + tryCompare(locationsSlackSpy, "count", 0) + compare(countSlackSpy.count, 0) + slackModel.update() + tryCompare(locationsSlackSpy, "count", 0) + compare(countSlackSpy.count, 0) + slackModel.update() + tryCompare(locationsSlackSpy, "count", 0) + compare(countSlackSpy.count, 0) + tryCompare(countSlackSpy, "count", 1); //waits up to 5s + compare (locationsSlackSpy.count, 1) + compare(slackModel.count, 7) // slackAddress1.county + } + function test_reverse_geocode() { + testModel.reset() + testQuerySpy.clear() + locationsSpy.clear() + testStatusSpy.clear() + countSpy.clear() + compare (testModel.errorString, "") + compare (testModel.error, GeocodeModel.NoError) + compare (testModel.count, 0) + compare (testQuerySpy.count, 0) + testModel.query = rcoordinate1 + compare (testQuerySpy.count, 1) + testModel.update() + tryCompare (locationsSpy, "count", 1) // 5 sec + tryCompare(countSpy, "count", 1) + compare (testModel.errorString, "") + compare (testModel.error, GeocodeModel.NoError) + compare (testModel.count, 2) + testModel.reset() + tryCompare(countSpy, "count", 2) + compare (testModel.count, 0) + } + function test_delayed_reverse_geocode() { + clear_slack_model() + slackModel.query = slackCoordinate1 + compare (querySlackSpy.count, 1) + slackModel.update() + tryCompare(countSlackSpy, "count", 0) + compare (locationsSlackSpy.count, 0) + compare (slackModel.count, 0) + + tryCompare(countSlackSpy, "count", 1); //waits up to 5s + compare (locationsSlackSpy.count, 1) + compare (slackModel.count, 3) // slackCoordinate1.longitude + // Frequent updates, previous requests are aborted + slackModel.reset() + locationsSlackSpy.clear() + countSlackSpy.clear() + slackModel.update() + tryCompare(locationsSlackSpy, "count", 0) + compare(countSlackSpy.count, 0) + slackModel.update() + tryCompare(locationsSlackSpy, "count", 0) + compare(countSlackSpy.count, 0) + slackModel.update() + tryCompare(locationsSlackSpy, "count", 0) + compare(countSlackSpy.count, 0) + slackModel.update() + tryCompare(locationsSlackSpy, "count", 0) + compare(countSlackSpy.count, 0) + + tryCompare(countSlackSpy, "count", 1); //waits up to 5s + compare(locationsSlackSpy.count, 1) + compare(slackModel.count, 3) // slackCoordinate1.longitude + } + } +} diff --git a/tests/auto/declarative_location_core/tst_imagemodel.qml b/tests/auto/declarative_location_core/tst_imagemodel.qml new file mode 100644 index 00000000..2fa5093c --- /dev/null +++ b/tests/auto/declarative_location_core/tst_imagemodel.qml @@ -0,0 +1,186 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtTest 1.0 +import QtLocation 5.3 +import "utils.js" as Utils + +TestCase { + id: testCase + + name: "ImageModel" + + Plugin { + id: testPlugin + name: "qmlgeo.test.plugin" + allowExperimental: true + parameters: [ + PluginParameter { + name: "initializePlaceData" + value: true + } + ] + } + + ImageModel { + id: testModel + } + + Place { + id: testPlace + 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 }, + { tag: "batchSize", property: "batchSize", signal: "batchSizeChanged", value: 10, reset: 1 }, + ]; + } + + function test_setAndGet(data) { + Utils.testObjectProperties(testCase, testModel, data); + } + + function test_consecutive_fetch_data() { + return [ + { tag: "batchSize 1", batchSize: 1 }, + { tag: "batchSize 2", batchSize: 2 }, + { tag: "batchSize 5", batchSize: 5 }, + { tag: "batchSize 10", batchSize: 10 }, + ]; + } + + function test_consecutive_fetch(data) { + 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, data); + 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.3; ImageModel {}', + testCase, "imageModel"); + } +} diff --git a/tests/auto/declarative_location_core/tst_place.qml b/tests/auto/declarative_location_core/tst_place.qml new file mode 100644 index 00000000..bb789b42 --- /dev/null +++ b/tests/auto/declarative_location_core/tst_place.qml @@ -0,0 +1,627 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtTest 1.0 +import QtLocation 5.3 +import QtPositioning 5.2 +import "utils.js" as Utils + +TestCase { + id: testCase + + name: "Place" + + Plugin { + id: testPlugin + name: "qmlgeo.test.plugin" + allowExperimental: true + } + + Place { + id: favoritePlace + name: "Favorite Place" + } + + Place { id: emptyPlace } + + Place { id: emptyPlace2 } + + Place { id: testPlace } + + Place { + id: savePlace + + name: "Test place" + + visibility: Place.DeviceVisibility + + location: Location { + address: Address { + country: "country" + countryCode: "cc" + state: "state" + county: "county" + city: "city" + district: "district" + street: "123 Fake Street" + postalCode: "1234" + } + + coordinate { + latitude: 10 + longitude: 10 + altitude: 100 + } + + boundingBox { + center: QtPositioning.coordinate(10, 10, 100) + width: 100 + height: 100 + } + } + + ratings: Ratings { + average: 3.5 + count: 10 + } + + supplier: Supplier { + name: "Supplier 1" + supplierId: "supplier-id-1" + url: "http://www.example.com/supplier-id-1/" + icon: Icon{ + plugin: testPlugin + Component.onCompleted: { + parameters.singleUrl = "http://www.example.com/supplier-id-1/icon" + } + } + } + + categories: [ + Category { + name: "Category 1" + categoryId: "category-id-1" + plugin: testPlugin + }, + Category { + name: "Category 2" + categoryId: "category-id-2" + plugin: testPlugin + } + ] + + icon: Icon { + Component.onCompleted: { + savePlace.icon.parameters.singleUrl = "http://example.com/test-place.png"; + } + } + } + + Place { + id: dummyPlace + placeId: "487" + name: "dummyPlace" + visibility: Place.PublicVisibility + } + + // compares two places property by property + function compare_place(place1, place2) { + // check simple properties + var simpleProperties = ["name", "placeId", "primaryPhone", "primaryFax", "primaryEmail", + "primaryWebsite", "visibility"]; + for (x in simpleProperties) { + if (place1[simpleProperties[x]] !== place2[simpleProperties[x]]) + return false; + } + + // check categories + if (place1.categories.length !== place2.categories.length) + return false; + for (var i = 0; i < place1.categories.length; ++i) { + // fixme, what if the order of the two lists are not the same + if (place1.categories[i].categoryId !== place2.categories[i].categoryId) + return false; + if (place1.categories[i].name !== place2.categories[i].name) + return false; + } + + // check supplier + if (place1.supplier === null && place2.supplier !== null) + return false; + if (place1.supplier !== null && place2.supplier === null) + return false; + if (place1.supplier !== null && place2.supplier !== null) { + if (place1.supplier.supplierId !== place2.supplier.supplierId) + return false; + if (place1.supplier.name !== place2.supplier.name) + return false; + if (place1.supplier.url !== place2.supplier.url) + return false; + + // check supplier icon + if (place1.supplier.icon === null && place2.supplier.icon !== null) + return false; + if (place1.supplier.icon !== null && place2.supplier.icon === null) + return false; + if (place1.supplier.icon !== null && place2.supplier.icon !== null) { + if (place1.supplier.icon.parameters.keys().length !== place2.supplier.icon.parameters.keys().length) { + return false; + } + + var keys = place1.supplier.icon.parameters.keys() + place2.supplier.icon.parameters.keys(); + for (var i = 0; i < keys.length; ++i) { + if (place1.supplier.icon.parameters[keys[i]] != place2.supplier.icon.parameters[keys[i]]) { + return false; + } + } + + if (place1.supplier.icon.plugin !== place2.supplier.icon.plugin) + return false; + } + } + + // check ratings + if (place1. ratings === null && place2.ratings !== null) + return false; + if (place1.ratings !== null && place2.ratings === null) + return false; + if (place1.ratings !== null && place2.ratings !== null) { + if (place1.ratings.average !== place2.ratings.average) + return false; + if (place1.ratings.count !== place2.ratings.count) + return false; + } + + // check location + if (place1.location === null && place2.location !== null) + return false; + if (place1.location !== null && place2.location === null) + return false; + if (place1.location !== null && place2.location !== null) { + if (place1.location.address.country !== place2.location.address.country) + return false; + if (place1.location.address.countryCode !== place2.location.address.countryCode) + return false; + if (place1.location.address.state !== place2.location.address.state) + return false; + if (place1.location.address.county !== place2.location.address.county) + return false; + if (place1.location.address.city !== place2.location.address.city) + return false; + if (place1.location.address.district !== place2.location.address.district) + return false; + if (place1.location.address.street !== place2.location.address.street) + return false; + if (place1.location.address.postalCode !== place2.location.address.postalCode) + return false; + + if (place1.location.coordinate !== place2.location.coordinate) + return false; + if (place1.location.boundingBox !== place2.location.boundingBox) + return false; + } + + // check icon + if (place1.icon === null && place2.icon !== null) { + return false; + } + if (place1.icon !== null && place2.icon === null) { + return false; + } + if (place1.icon !== null && place2.icon !== null) { + if (place1.icon.plugin !== place2.icon.plugin) { + console.log(place1.icon.plugin + " " + place2.icon.plugin); + return false; + } + + if (place1.icon.parameters.keys().length !== place2.icon.parameters.keys().length) { + return false; + } + + var keys = place1.icon.parameters.keys() + place2.icon.parameters.keys(); + for (var i = 0; i < keys.length; ++i) { + if (place1.icon.parameters[keys[i]] + != place2.icon.parameters[keys[i]]) { + return false; + } + } + } + + // check extended attributes + + return true; + } + + function test_emptyPlace() { + // basic properties + compare(emptyPlace.plugin, null); + compare(emptyPlace.categories.length, 0); + compare(emptyPlace.name, ""); + compare(emptyPlace.placeId, ""); + compare(emptyPlace.detailsFetched, false); + compare(emptyPlace.status, Place.Ready); + compare(emptyPlace.primaryPhone, ""); + compare(emptyPlace.primaryFax, ""); + compare(emptyPlace.primaryEmail, ""); + compare(emptyPlace.primaryWebsite, ""); + compare(emptyPlace.visibility, Place.UnspecifiedVisibility); + compare(emptyPlace.attribution, ""); + + // complex properties + compare(emptyPlace.ratings.average, 0); + compare(emptyPlace.location.address.street, ''); + compare(emptyPlace.location.address.district, ''); + compare(emptyPlace.location.address.city, ''); + compare(emptyPlace.location.address.county, ''); + compare(emptyPlace.location.address.state, ''); + compare(emptyPlace.location.address.country, ''); + + compare(emptyPlace.icon.plugin, null); + + compare(emptyPlace.supplier.name, ''); + compare(emptyPlace.supplier.supplierId, ''); + compare(emptyPlace.supplier.url, ''); + + compare(emptyPlace.supplier.icon.plugin, null); + + compare(emptyPlace.reviewModel.totalCount, -1); + compare(emptyPlace.imageModel.totalCount, -1); + compare(emptyPlace.editorialModel.totalCount, -1); + compare(emptyPlace.categories.length, 0); + + verify(compare_place(emptyPlace, emptyPlace)); + verify(compare_place(emptyPlace, emptyPlace2)); + } + + function test_setAndGet_data() { + return [ + { tag: "name", property: "name", signal: "nameChanged", value: "Test Place", reset: "" }, + { tag: "placeId", property: "placeId", signal: "placeIdChanged", value: "test-place-id-1", reset: "" }, + { tag: "visibility", property: "visibility", signal: "visibilityChanged", value: Place.PublicVisibility, reset: Place.UnspecifiedVisibility }, + { tag: "attribution", property: "attribution", signal: "attributionChanged", value: "Place data from...", reset: "" }, + { tag: "favorite", property: "favorite", signal: "favoriteChanged", value: favoritePlace } + ]; + } + + function test_setAndGet(data) { + Utils.testObjectProperties(testCase, testPlace, data); + } + + function test_categories() { + var categories = new Array(2); + categories[0] = Qt.createQmlObject('import QtLocation 5.3; Category { categoryId: "cat-id-1"; name: "Category 1" }', testCase, "Category1"); + categories[1] = Qt.createQmlObject('import QtLocation 5.3; Category { categoryId: "cat-id-2"; name: "Category 2" }', testCase, "Category2"); + + var signalSpy = Qt.createQmlObject('import QtTest 1.0; SignalSpy {}', testCase, "SignalSpy"); + signalSpy.target = testPlace; + signalSpy.signalName = "categoriesChanged"; + + // set categories to something new + testPlace.categories = categories; + compare(testPlace.categories.length, categories.length); + + for (var i = 0; i < categories.length; ++i) { + compare(testPlace.categories[i].categoryId, categories[i].categoryId); + compare(testPlace.categories[i].name, categories[i].name); + } + + compare(signalSpy.count, 2); + + // set categories to the same (signal spy should not increase?) + testPlace.categories = categories; + compare(testPlace.categories.length, categories.length); + + for (var i = 0; i < categories.length; ++i) { + compare(testPlace.categories[i].categoryId, categories[i].categoryId); + compare(testPlace.categories[i].name, categories[i].name); + } + + compare(signalSpy.count, 5); // clear + append + append + + // reset by assignment + testPlace.categories = new Array(0); + compare(testPlace.categories.length, 0); + compare(signalSpy.count, 6); + + signalSpy.destroy(); + } + + function test_supplier() { + var supplier = Qt.createQmlObject('import QtLocation 5.3; Supplier { supplierId: "sup-id-1"; name: "Category 1" }', testCase, "Supplier1"); + + var signalSpy = Qt.createQmlObject('import QtTest 1.0; SignalSpy {}', testCase, "SignalSpy"); + signalSpy.target = testPlace; + signalSpy.signalName = "supplierChanged"; + + // set supplier to something new + testPlace.supplier = supplier; + compare(testPlace.supplier, supplier); + + compare(testPlace.supplier.supplierId, supplier.supplierId); + compare(testPlace.supplier.name, supplier.name); + + compare(signalSpy.count, 1); + + // set supplier to the same + testPlace.supplier = supplier; + compare(testPlace.supplier, supplier); + + compare(testPlace.supplier.supplierId, supplier.supplierId); + compare(testPlace.supplier.name, supplier.name); + + compare(signalSpy.count, 1); + + // reset by assignment + testPlace.supplier = null; + compare(testPlace.supplier, null); + compare(signalSpy.count, 2); + + signalSpy.destroy(); + } + + function test_location() { + var location = Qt.createQmlObject('import QtPositioning 5.2; Location { coordinate: QtPositioning.coordinate(10.0, 20.0) }', testCase, "Location1"); + + var signalSpy = Qt.createQmlObject('import QtTest 1.0; SignalSpy {}', testCase, "SignalSpy"); + signalSpy.target = testPlace; + signalSpy.signalName = "locationChanged"; + + testPlace.location = location; + compare(testPlace.location.coordinate.latitude, 10.0); + compare(signalSpy.count, 1); + + testPlace.location = location; + compare(testPlace.location.coordinate.latitude, 10.0); + compare(signalSpy.count, 1); + + testPlace.location = null; + compare(testPlace.location, null); + compare(signalSpy.count, 2); + + location.destroy(); + signalSpy.destroy(); + } + + function test_ratings() { + var ratings = Qt.createQmlObject('import QtLocation 5.3; Ratings { average: 3; count: 100 }', testCase, "Rating1"); + + var signalSpy = Qt.createQmlObject('import QtTest 1.0; SignalSpy {}', testCase, "SignalSpy"); + signalSpy.target = testPlace; + signalSpy.signalName = "ratingsChanged"; + + testPlace.ratings = ratings; + compare(testPlace.ratings.average, 3); + compare(testPlace.ratings.count, 100); + compare(signalSpy.count, 1); + + testPlace.ratings = ratings; + compare(testPlace.ratings.average, 3); + compare(testPlace.ratings.count, 100); + compare(signalSpy.count, 1); + + testPlace.ratings = null; + compare(testPlace.ratings, null); + compare(signalSpy.count, 2); + + ratings.destroy(); + signalSpy.destroy(); + } + + function test_extendedAttributes() { + verify(testPlace.extendedAttributes); + + testPlace.extendedAttributes["foo"] = Qt.createQmlObject('import QtLocation 5.3; PlaceAttribute { text: "Foo"; label: "Foo label" }', testCase, 'PlaceAttribute'); + + verify(testPlace.extendedAttributes.foo); + compare(testPlace.extendedAttributes.foo.text, "Foo"); + compare(testPlace.extendedAttributes.foo.label, "Foo label"); + + testPlace.extendedAttributes["foo"] = null; + verify(!testPlace.extendedAttributes.foo); + } + + function test_contactDetailsProperty() { + verify(testPlace.contactDetails); + + testPlace.contactDetails["phone"] = Qt.createQmlObject('import QtLocation 5.3; ContactDetail { label: "Test Label"; value: "Detail Value" }', testCase, 'ContactDetail'); + + verify(testPlace.contactDetails.phone); + compare(testPlace.contactDetails.phone[0].label, "Test Label"); + compare(testPlace.contactDetails.phone[0].value, "Detail Value"); + + testPlace.contactDetails["phone"] = null; + verify(!testPlace.contactDetails.phone); + } + + function test_saveload() { + // Save a place + var signalSpy = Qt.createQmlObject('import QtTest 1.0; SignalSpy {}', testCase, "SignalSpy"); + signalSpy.target = savePlace; + signalSpy.signalName = "statusChanged"; + + savePlace.plugin = testPlugin; + savePlace.icon.plugin = testPlugin; + savePlace.placeId = "invalid-place-id"; + + savePlace.save(); + + compare(savePlace.status, Place.Saving); + + tryCompare(savePlace, "status", Place.Error); + + // try again without an invalid placeId + savePlace.placeId = ""; + savePlace.save(); + + compare(savePlace.status, Place.Saving); + + tryCompare(savePlace, "status", Place.Ready); + + verify(savePlace.placeId !== ""); + + signalSpy.destroy(); + + + // Read a place + var readPlace = Qt.createQmlObject('import QtLocation 5.3; Place { }', testCase, "test_saveload"); + + signalSpy = Qt.createQmlObject('import QtTest 1.0; SignalSpy {}', testCase, "SignalSpy"); + signalSpy.target = readPlace; + signalSpy.signalName = "statusChanged"; + + readPlace.plugin = testPlugin; + + readPlace.getDetails(); + + compare(readPlace.status, Place.Fetching); + tryCompare(readPlace, "status", Place.Error); + + readPlace.placeId = "invalid-id"; + + readPlace.getDetails(); + + compare(readPlace.status, Place.Fetching); + tryCompare(readPlace, "status", Place.Error); + + readPlace.placeId = savePlace.placeId; + + // verify that read place is not currently the same as what we saved + verify(!compare_place(readPlace, savePlace)); + + readPlace.getDetails(); + + compare(readPlace.status, Place.Fetching); + tryCompare(readPlace, "status", Place.Ready); + + // verify that read place is the same as what we saved + verify(compare_place(readPlace, savePlace)); + + signalSpy.destroy(); + + + // Remove a place + var removePlace = Qt.createQmlObject('import QtLocation 5.3; Place { }', testCase, "test_saveload"); + + signalSpy = Qt.createQmlObject('import QtTest 1.0; SignalSpy {}', testCase, "SignalSpy"); + signalSpy.target = removePlace; + signalSpy.signalName = "statusChanged"; + + removePlace.plugin = testPlugin; + + removePlace.remove(); + + compare(removePlace.status, Place.Removing); + tryCompare(removePlace, "status", Place.Error); + + removePlace.placeId = "invalid-id"; + + removePlace.remove(); + + compare(removePlace.status, Place.Removing); + tryCompare(removePlace, "status", Place.Error); + + removePlace.placeId = savePlace.placeId; + + removePlace.remove(); + + compare(removePlace.status, Place.Removing); + tryCompare(removePlace, "status", Place.Ready); + + removePlace.getDetails(); + + compare(removePlace.status, Place.Fetching); + tryCompare(removePlace, "status", Place.Error); + + signalSpy.destroy(); + } + + function test_copy() { + var place = Qt.createQmlObject('import QtLocation 5.3; Place { }', this); + place.plugin = testPlugin; + place.copyFrom(dummyPlace); + compare(place.placeId, ""); + compare(place.name, "dummyPlace"); + compare(place.visibility, Place.UnspecifiedVisibility); + } + + function test_contactDetails(data) { + var place = Qt.createQmlObject('import QtLocation 5.3; Place {}', this); + + var signalSpy = Qt.createQmlObject('import QtTest 1.0; SignalSpy {}', testCase, "SignalSpy"); + signalSpy.target = place; + signalSpy.signalName = data.signalName; + + var detail1 = Qt.createQmlObject('import QtLocation 5.3; ContactDetail {}', this); + detail1.label = "Detail1"; + detail1.value = "555-detail1"; + + place.contactDetails[data.contactType] = detail1; + compare(place.contactDetails[data.contactType].length, 1); + compare(place.contactDetails[data.contactType][0].label, "Detail1"); + compare(place.contactDetails[data.contactType][0].value, "555-detail1"); + + compare(place[data.primaryValue], "555-detail1"); + compare(signalSpy.count, 1); + signalSpy.clear(); + + var listView = Qt.createQmlObject('import QtQuick 2.0; ListView { delegate:Text{text:modelData.label + ":" + modelData.value } }', this); + listView.model = place.contactDetails[data.contactType]; + compare(listView.count, 1); + + var detail2 = Qt.createQmlObject('import QtLocation 5.3; ContactDetail {}', this); + detail2.label = "Detail2"; + detail2.value = "555-detail2"; + + var details = new Array(); + details.push(detail2); + details.push(detail1); + + place.contactDetails[data.contactType] = details; + compare(place.contactDetails[data.contactType].length, 2); + compare(place.contactDetails[data.contactType][0].label, "Detail2"); + compare(place.contactDetails[data.contactType][0].value, "555-detail2"); + compare(place.contactDetails[data.contactType][1].label, "Detail1"); + compare(place.contactDetails[data.contactType][1].value, "555-detail1"); + + compare(place[data.primaryValue], "555-detail2"); + compare(signalSpy.count, 1); + signalSpy.clear(); + listView.model = place.contactDetails[data.contactType]; + compare(listView.count, 2); + } + + function test_contactDetails_data() { + return [ + { tag: "phone", contactType: "phone", signalName: "primaryPhoneChanged", primaryValue: "primaryPhone"}, + { tag: "fax", contactType: "fax", signalName: "primaryFaxChanged", primaryValue: "primaryFax"}, + { tag: "email", contactType: "email", signalName: "primaryEmailChanged", primaryValue: "primaryEmail"}, + { tag: "website", contactType: "website", signalName: "primaryWebsiteChanged", primaryValue: "primaryWebsite"} + ]; + } +} diff --git a/tests/auto/declarative_location_core/tst_placeattribute.qml b/tests/auto/declarative_location_core/tst_placeattribute.qml new file mode 100644 index 00000000..ae61aed4 --- /dev/null +++ b/tests/auto/declarative_location_core/tst_placeattribute.qml @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtTest 1.0 +import QtLocation 5.3 +import "utils.js" as Utils + +TestCase { + id: testCase + + name: "PlaceAttribute" + + PlaceAttribute { + id: testAttribute + } + + function test_setAndGet_data() { + return [ + { tag: "label", property: "label", signal: "labelChanged", value: "Test Label", reset: "" }, + { tag: "text", property: "text", signal: "textChanged", value: "Test Text", reset: "" }, + ]; + } + + function test_setAndGet(data) { + Utils.testObjectProperties(testCase, testAttribute, data); + } +} diff --git a/tests/auto/declarative_location_core/tst_placeicon.qml b/tests/auto/declarative_location_core/tst_placeicon.qml new file mode 100644 index 00000000..c0f099d7 --- /dev/null +++ b/tests/auto/declarative_location_core/tst_placeicon.qml @@ -0,0 +1,106 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtTest 1.0 +import QtLocation 5.3 +import "utils.js" as Utils + +TestCase { + id: testCase + + name: "Icon" + + Icon { id: emptyIcon } + + function test_empty() { + compare(emptyIcon.plugin, null); + compare(emptyIcon.parameters.keys().length, 0) + } + + + Icon { + id: qmlIconSingleUrl + } + + function test_qmlSingleUrlIcon() { + qmlIconSingleUrl.parameters.singleUrl = "http://example.com/icon.png" + + var u = qmlIconSingleUrl.url(Qt.size(64, 64)); + compare(u, "http://example.com/icon.png"); + + u = qmlIconSingleUrl.url(Qt.size(20, 20)); + compare(u, "http://example.com/icon.png"); + + qmlIconSingleUrl.parameters.singleUrl = "/home/user/icon.png" + u = qmlIconSingleUrl.url(Qt.size(20, 20)); + compare(u, "file:///home/user/icon.png"); + } + + Plugin { + id: testPlugin + name: "qmlgeo.test.plugin" + allowExperimental: true + } + + Icon { + id: qmlIconParams + plugin: testPlugin + } + + function test_qmlIconParams() { + compare(qmlIconParams.plugin, testPlugin); + qmlIconParams.parameters.s = "http://example.com/icon_small.png" + qmlIconParams.parameters.m = "http://example.com/icon_medium.png" + qmlIconParams.parameters.l = "http://example.com/icon_large.png" + + compare(qmlIconParams.url(Qt.size(10, 10)), "http://example.com/icon_small.png"); + compare(qmlIconParams.url(Qt.size(20, 20)), "http://example.com/icon_small.png"); + compare(qmlIconParams.url(Qt.size(24, 24)), "http://example.com/icon_small.png"); + compare(qmlIconParams.url(Qt.size(25, 25)), "http://example.com/icon_medium.png"); + compare(qmlIconParams.url(Qt.size(30, 30)), "http://example.com/icon_medium.png"); + compare(qmlIconParams.url(Qt.size(39, 39)), "http://example.com/icon_medium.png"); + compare(qmlIconParams.url(Qt.size(40, 40)), "http://example.com/icon_large.png"); + compare(qmlIconParams.url(Qt.size(50, 50)), "http://example.com/icon_large.png"); + compare(qmlIconParams.url(Qt.size(60, 60)), "http://example.com/icon_large.png"); + } + + Icon { + id: testIcon + } + + function test_setAndGet_data() { + return [ + { tag: "plugin", property: "plugin", signal: "pluginChanged", value: testPlugin }, + ]; + } + + function test_setAndGet(data) { + Utils.testObjectProperties(testCase, testIcon, data); + } +} diff --git a/tests/auto/declarative_location_core/tst_placesearchmodel.qml b/tests/auto/declarative_location_core/tst_placesearchmodel.qml new file mode 100644 index 00000000..4c7897b5 --- /dev/null +++ b/tests/auto/declarative_location_core/tst_placesearchmodel.qml @@ -0,0 +1,311 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtTest 1.0 +import QtLocation 5.3 +import QtPositioning 5.2 +import "utils.js" as Utils + +TestCase { + id: testCase + + name: "PlaceSearchModel" + + Plugin { + id: testPlugin + name: "qmlgeo.test.plugin" + allowExperimental: true + parameters: [ + PluginParameter { + name: "initializePlaceData" + value: true + } + ] + } + + Plugin { + id: favoritePlugin + name: "foo" + } + + Plugin { + id: uninitializedPlugin + } + + Category { + id: testCategory1 + categoryId: "da3606c1-3448-43b3-a4a3-ca24b12dd94a" + name: "Test Category 1" + } + + Category { + id: testCategory2 + categoryId: "bb8ead84-ec2a-48a9-9c8f-d4ffd3134b21" + name: "Test Category 2" + } + + function compareArray(a, b) { + if (a.length !== b.length) + return false; + + for (var i = 0; i < a.length; ++i) { + if (b.indexOf(a[i]) < 0) + return false; + } + + return true; + } + + function test_setAndGet_data() { + var testSearchArea = QtPositioning.circle(QtPositioning.coordinate(10, 20), 5000); + + return [ + { tag: "plugin", property: "plugin", signal: "pluginChanged", value: testPlugin }, + { tag: "searchArea", property: "searchArea", signal: "searchAreaChanged", value: testSearchArea, reset: QtPositioning.shape() }, + { tag: "limit", property: "limit", signal: "limitChanged", value: 10, reset: -1 }, + + { tag: "searchTerm", property: "searchTerm", signal: "searchTermChanged", value: "Test term", reset: "" }, + { tag: "recommendationId", property: "recommendationId", signal: "recommendationIdChanged", value: "Test-place-id", reset: "" }, + { tag: "relevanceHint", property: "relevanceHint", signal: "relevanceHintChanged", value: PlaceSearchModel.DistanceHint, reset: PlaceSearchModel.UnspecifiedHint }, + { tag: "visibilityScope", property: "visibilityScope", signal: "visibilityScopeChanged", value: Place.DeviceVisibility, reset: Place.UnspecifiedVisibility }, + { tag: "favoritesPlugin", property: "favoritesPlugin", signal: "favoritesPluginChanged", value: favoritePlugin }, + { tag: "category", property: "categories", signal: "categoriesChanged", value: testCategory1, expectedValue: [ testCategory1 ], reset: [], array: true }, + { tag: "categories", property: "categories", signal: "categoriesChanged", value: [ testCategory1, testCategory2 ], reset: [], array: true }, + ]; + } + + function test_setAndGet(data) { + var testModel = Qt.createQmlObject('import QtLocation 5.3; PlaceSearchModel {}', testCase, "PlaceSearchModel"); + Utils.testObjectProperties(testCase, testModel, data); + delete testModel; + } + + function test_search_data() { + var park = Qt.createQmlObject('import QtLocation 5.3; Category {name: "Park"; categoryId: "c2e1252c-b997-44fc-8165-e53dd00f66a7"}', testCase, "Category"); + return [ + { + tag: "searchTerm, multiple results", + property: "searchTerm", + value: "view", + reset: "", + places: [ + "4dcc74ce-fdeb-443e-827c-367438017cf1", + "8f72057a-54b2-4e95-a7bb-97b4d2b5721e" + ] + }, + { + tag: "searchTerm, single result", + property: "searchTerm", + value: "park", + reset: "", + places: [ + "4dcc74ce-fdeb-443e-827c-367438017cf1" + ] + }, + { + tag: "searchTerm, multiple results", + property: "searchTerm", + value: "sea", + reset: "", + alternate: true, + places: [ + "8f72057a-54b2-4e95-a7bb-97b4d2b5721e" + ] + }, + { + tag: "categories, single result", + property: "categories", + value: [ park ], + places: [ + "dacb2181-3f67-4e6a-bd4d-635e99ad5b03" + ] + }, + { + tag: "recommendations", + property: "recommendationId", + value: "4dcc74ce-fdeb-443e-827c-367438017cf1", + reset: "", + places: [ + "8f72057a-54b2-4e95-a7bb-97b4d2b5721e", + "dacb2181-3f67-4e6a-bd4d-635e99ad5b03" + ] + }, + { + tag: "no recommendations", + property: "recommendationId", + value: "8f72057a-54b2-4e95-a7bb-97b4d2b5721e", + reset: "", + places: [ ] + } + ]; + } + + function test_search(data) { + var testModel = Qt.createQmlObject('import QtLocation 5.3; PlaceSearchModel {}', testCase, "PlaceSearchModel"); + testModel.plugin = testPlugin; + + var statusChangedSpy = Qt.createQmlObject('import QtTest 1.0; SignalSpy {}', testCase, "SignalSpy"); + statusChangedSpy.target = testModel; + statusChangedSpy.signalName = "statusChanged"; + + var countChangedSpy = Qt.createQmlObject('import QtTest 1.0; SignalSpy {}', testCase, "SignalSpy"); + countChangedSpy.target = testModel; + countChangedSpy.signalName = "rowCountChanged"; + + compare(testModel.status, PlaceSearchModel.Null); + + testModel[data.property] = data.value; + testModel.update(); + + compare(testModel.status, PlaceSearchModel.Loading); + compare(statusChangedSpy.count, 1); + + tryCompare(testModel, "status", PlaceSearchModel.Ready); + compare(statusChangedSpy.count, 2); + + if (data.places.length > 0) + compare(countChangedSpy.count, 1); + else + compare(countChangedSpy.count, 0); + + for (var i = 0; i < testModel.count; ++i) { + compare(testModel.data(i, "type"), PlaceSearchModel.PlaceResult); + + var place = testModel.data(i, "place"); + + verify(data.places.indexOf(place.placeId) >= 0); + } + + // Test for alternate implementation + if (data.alternate !== undefined && data.alternate === true) { + for (var ii = 0; ii < testModel.count; ++ii) { + var p = testModel.data(ii, "place"); + compare(p.extendedAttributes["x_provider"].text, "QPlacePrivateDefaultAlt") + } + } + + testModel.reset(); + + compare(statusChangedSpy.count, 3); + compare(testModel.status, PlaceSearchModel.Null); + if (data.places.length > 0) + compare(countChangedSpy.count, 2); + else + compare(countChangedSpy.count, 0); + compare(testModel.count, 0); + + countChangedSpy.destroy(); + statusChangedSpy.destroy(); + + if (data.reset === undefined) { + testModel[data.property] = null; + } else { + testModel[data.property] = data.reset; + } + + delete testModel; + delete statusChangedSpy; + delete countChangedSpy; + } + + function test_cancel() { + var testModel = Qt.createQmlObject('import QtLocation 5.3; PlaceSearchModel {}', testCase, "PlaceSearchModel"); + testModel.plugin = testPlugin; + + var statusChangedSpy = Qt.createQmlObject('import QtTest 1.0; SignalSpy {}', testCase, "SignalSpy"); + statusChangedSpy.target = testModel; + statusChangedSpy.signalName = "statusChanged"; + + //try cancelling from an initially null state + compare(testModel.status, PlaceSearchModel.Null); + testModel.searchTerm = "view"; + testModel.update(); + tryCompare(testModel, "status", PlaceSearchModel.Loading); + testModel.cancel(); + tryCompare(testModel, "status", PlaceSearchModel.Ready); + compare(statusChangedSpy.count, 2); + + testModel.update(); + tryCompare(testModel, "status", PlaceSearchModel.Loading); + tryCompare(testModel, "status", PlaceSearchModel.Ready); + compare(statusChangedSpy.count, 4); + + var numResults = testModel.count; + verify(numResults > 0); + + //try cancelling from an initially ready state + testModel.update(); + tryCompare(testModel, "status", PlaceSearchModel.Loading); + testModel.cancel(); + tryCompare(testModel, "status", PlaceSearchModel.Ready); + compare(testModel.count, numResults); + compare(statusChangedSpy.count, 6); + + //chack that an encountering an error will cause the model + //to clear its data + testModel.plugin = null; + testModel.update(); + tryCompare(testModel, "count", 0); + compare(testModel.status, PlaceSearchModel.Error); + + delete testModel; + delete statusChangedSpy; + } + + function test_error() { + var testModel = Qt.createQmlObject('import QtLocation 5.3; PlaceSearchModel {}', testCase, "PlaceSearchModel"); + + var statusChangedSpy = Qt.createQmlObject('import QtTest 1.0; SignalSpy {}', testCase, "SignalSpy"); + statusChangedSpy.target = testModel; + statusChangedSpy.signalName = "statusChanged"; + + //try searching without a plugin instance + testModel.update(); + tryCompare(statusChangedSpy, "count", 2); + compare(testModel.status, PlaceSearchModel.Error); + statusChangedSpy.clear(); + //Aside: there is some difficulty in checking the transition to the Loading state + //since the model transitions from Loading to Error before the next event loop + //iteration. + + //try searching with an uninitialized plugin instance. + testModel.plugin = uninitializedPlugin; + testModel.update(); + tryCompare(statusChangedSpy, "count", 2); + compare(testModel.status, PlaceSearchModel.Error); + statusChangedSpy.clear(); + + //try searching with plugin a instance + //that has been provided a non-existent name + testModel.plugin = favoritePlugin; + testModel.update(); + tryCompare(statusChangedSpy, "count", 2); + compare(testModel.status, PlaceSearchModel.Error); + } +} diff --git a/tests/auto/declarative_location_core/tst_placesearchsuggestionmodel.qml b/tests/auto/declarative_location_core/tst_placesearchsuggestionmodel.qml new file mode 100644 index 00000000..13347565 --- /dev/null +++ b/tests/auto/declarative_location_core/tst_placesearchsuggestionmodel.qml @@ -0,0 +1,153 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtTest 1.0 +import QtLocation 5.3 +import QtPositioning 5.2 +import "utils.js" as Utils + +TestCase { + id: testCase + + name: "PlaceSearchSuggestionModel" + + PlaceSearchSuggestionModel { + id: testModel + } + + PlaceSearchSuggestionModel { + id: testModelError + } + + Plugin { + id: testPlugin + name: "qmlgeo.test.plugin" + allowExperimental: true + } + + Plugin { + id: nonExistantPlugin + name: "nonExistantName" + } + + Plugin { + id: uninitializedPlugin + } + + function test_setAndGet_data() { + var testSearchArea = QtPositioning.circle(QtPositioning.coordinate(10, 20), 5000); + return [ + { tag: "plugin", property: "plugin", signal: "pluginChanged", value: testPlugin }, + { tag: "searchArea", property: "searchArea", signal: "searchAreaChanged", value: testSearchArea, reset: QtPositioning.shape() }, + { tag: "limit", property: "limit", signal: "limitChanged", value: 10, reset: -1 }, + + { tag: "searchTerm", property: "searchTerm", signal: "searchTermChanged", value: "Test term", reset: "" }, + ]; + } + + function test_setAndGet(data) { + Utils.testObjectProperties(testCase, testModel, data); + } + + SignalSpy { id: statusChangedSpy; target: testModel; signalName: "statusChanged" } + SignalSpy { id: suggestionsChangedSpy; target: testModel; signalName: "suggestionsChanged" } + + function test_suggestions() { + compare(statusChangedSpy.count, 0); + testModel.plugin = testPlugin; + + compare(testModel.status, PlaceSearchSuggestionModel.Null); + + testModel.searchTerm = "test"; + testModel.update(); + + compare(testModel.status, PlaceSearchSuggestionModel.Loading); + compare(statusChangedSpy.count, 1); + + tryCompare(testModel, "status", PlaceSearchSuggestionModel.Ready); + compare(statusChangedSpy.count, 2); + + var expectedSuggestions = [ "test1", "test2", "test3" ]; + + compare(suggestionsChangedSpy.count, 1); + compare(testModel.suggestions, expectedSuggestions); + + testModel.reset(); + + compare(statusChangedSpy.count, 3); + compare(testModel.status, PlaceSearchSuggestionModel.Null); + compare(suggestionsChangedSpy.count, 2); + compare(testModel.suggestions, []); + + testModel.update(); + + compare(statusChangedSpy.count, 4); + compare(testModel.status, PlaceSearchSuggestionModel.Loading); + + testModel.cancel(); + + compare(statusChangedSpy.count, 5); + compare(testModel.status, PlaceSearchSuggestionModel.Ready); + + //check that an encountering an error will cause the model + //to clear its data + testModel.plugin = null; + testModel.update(); + tryCompare(testModel.suggestions, "length", 0); + compare(testModel.status, PlaceSearchSuggestionModel.Error); + } + + SignalSpy { id: statusChangedSpyError; target: testModelError; signalName: "statusChanged" } + + function test_error() { + compare(statusChangedSpyError.count, 0); + //try searching without a plugin instance + testModelError.update(); + tryCompare(statusChangedSpyError, "count", 2); + compare(testModelError.status, PlaceSearchSuggestionModel.Error); + statusChangedSpyError.clear(); + //Aside: there is some difficulty in checking the transition to the Loading state + //since the model transitions from Loading to Error before the next event loop + //iteration. + + //try searching with an uninitialized plugin instance. + testModelError.plugin = uninitializedPlugin; + testModelError.update(); + tryCompare(statusChangedSpyError, "count", 2); + compare(testModelError.status, PlaceSearchSuggestionModel.Error); + statusChangedSpyError.clear(); + + //try searching with plugin a instance + //that has been provided a non-existent name + testModelError.plugin = nonExistantPlugin; + testModelError.update(); + tryCompare(statusChangedSpyError, "count", 2); + compare(testModelError.status, PlaceSearchSuggestionModel.Error); + } +} diff --git a/tests/auto/declarative_location_core/tst_plugin.qml b/tests/auto/declarative_location_core/tst_plugin.qml new file mode 100644 index 00000000..23c1ff9f --- /dev/null +++ b/tests/auto/declarative_location_core/tst_plugin.qml @@ -0,0 +1,150 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtTest 1.0 +import QtLocation 5.3 + +Item { + + Plugin { id: unattachedPlugin } + Plugin { id: herePlugin; name: "here"} + Plugin { id: invalidPlugin; name: "invalid"; allowExperimental: true } + Plugin { id: testPlugin; + name: "qmlgeo.test.plugin" + allowExperimental: true + parameters: [ + // Parms to guide the test plugin + PluginParameter { name: "supported"; value: true}, + PluginParameter { name: "finishRequestImmediately"; value: true}, + PluginParameter { name: "validateWellKnownValues"; value: true} + ] + } + SignalSpy {id: invalidAttachedSpy; target: invalidPlugin; signalName: "attached"} + + Plugin { + id: requiredPlugin + allowExperimental: true + required { + mapping: Plugin.OfflineMappingFeature; + geocoding: Plugin.OfflineGeocodingFeature; + places: Plugin.AnyPlacesFeatures; + navigation: Plugin.AnyNavigationFeatures; + } + } + + TestCase { + name: "Plugin properties" + function test_plugin() { + verify (invalidPlugin.availableServiceProviders.length > 0) + verify (invalidPlugin.availableServiceProviders.indexOf('qmlgeo.test.plugin') > -1) // at least test plugin must be present + + // invalid plugins should have no features + verify(invalidPlugin.isAttached) + verify(!(invalidPlugin.supportsMapping())) + verify(!(invalidPlugin.supportsGeocoding())) + verify(!(invalidPlugin.supportsRouting())) + verify(!(invalidPlugin.supportsPlaces())) + + if (invalidPlugin.availableServiceProviders.indexOf('qmlgeo.test.plugin') > -1) { + verify(testPlugin.isAttached) + verify(testPlugin.supportsMapping()) + verify(testPlugin.supportsGeocoding()) + verify(testPlugin.supportsPlaces()) + verify(testPlugin.supportsRouting()) + } + + if (invalidPlugin.availableServiceProviders.indexOf('here')) { + verify(herePlugin.isAttached) + verify(herePlugin.supportsMapping(Plugin.OnlineMappingFeature)) + verify(herePlugin.supportsGeocoding(Plugin.OnlineGeocodingFeature)) + verify(herePlugin.supportsRouting(Plugin.OnlineRoutingFeature)) + } + + verify(!unattachedPlugin.isAttached) + + // test changing name of plugin + invalidAttachedSpy.clear() + compare(invalidAttachedSpy.count, 0) + invalidPlugin.name = 'qmlgeo.test.plugin' + tryCompare(invalidAttachedSpy, 'count', 1) + verify(invalidPlugin.isAttached) + + verify(invalidPlugin.supportsMapping()) + verify(invalidPlugin.supportsGeocoding()) + verify(invalidPlugin.supportsRouting()) + verify(invalidPlugin.supportsPlaces()) + + invalidPlugin.name = 'here' + compare(invalidAttachedSpy.count, 2) + verify(invalidPlugin.supportsMapping(Plugin.OnlineMappingFeature)) + verify(invalidPlugin.supportsGeocoding(Plugin.OnlineGeocodingFeature)) + verify(invalidPlugin.supportsRouting(Plugin.OnlineRoutingFeature)) + + invalidPlugin.name = '' + compare(invalidAttachedSpy.count, 2) + verify(!invalidPlugin.supportsMapping()) + verify(!invalidPlugin.supportsGeocoding()) + verify(!invalidPlugin.supportsRouting()) + verify(!invalidPlugin.supportsPlaces()) + } + + function test_required() { + // the required plugin should either get here or qmlgeo.test.plugin + // either way the name will be non-empty and it'll meet the spec + verify(requiredPlugin.name !== "") + verify(requiredPlugin.supportsMapping(requiredPlugin.required.mapping)) + verify(requiredPlugin.supportsGeocoding(requiredPlugin.required.geocoding)) + verify(requiredPlugin.supportsPlaces(requiredPlugin.required.places)) + verify(requiredPlugin.supportsNavigation(requiredPlugin.required.navigation)) + } + + function test_placesFeatures() { + verify(testPlugin.supportsPlaces(Plugin.SavePlaceFeature)) + verify(testPlugin.supportsPlaces(Plugin.SaveCategoryFeature)) + verify(testPlugin.supportsPlaces(Plugin.SearchSuggestionsFeature)) + verify(!testPlugin.supportsPlaces(Plugin.RemovePlaceFeature)) + } + + function test_locale() { + compare(herePlugin.locales, [Qt.locale().name]); + + //try assignment of a single locale + herePlugin.locales = "fr_FR"; + compare(herePlugin.locales, ["fr_FR"]); + + //try assignment of multiple locales + herePlugin.locales = ["fr_FR","en_US"]; + compare(herePlugin.locales, ["fr_FR","en_US"]); + + //check that assignment of empty locale list defaults to system locale + herePlugin.locales = []; + compare(herePlugin.locales, [Qt.locale().name]); + } + } +} diff --git a/tests/auto/declarative_location_core/tst_plugin_error.qml b/tests/auto/declarative_location_core/tst_plugin_error.qml new file mode 100644 index 00000000..50b03590 --- /dev/null +++ b/tests/auto/declarative_location_core/tst_plugin_error.qml @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtTest 1.0 +import QtLocation 5.3 + +Item { + + Plugin { id: testPlugin; + name: "qmlgeo.test.plugin" + allowExperimental: true + parameters: [ + // Parms to guide the test plugin + PluginParameter { name: "error"; value: "1"}, + PluginParameter { name: "errorString"; value: "This error was expected. No worries !"} + ] + } + + Map { + id: map + } + + SignalSpy {id: errorSpy; target: map; signalName: "errorChanged"} + + TestCase { + name: "MappingManagerError" + function test_error() { + verify (map.error === Map.NoError); + map.plugin = testPlugin; + verify (map.error === Map.NotSupportedError); + verify (map.errorString == "This error was expected. No worries !"); + compare(errorSpy.count, 1); + } + } +} diff --git a/tests/auto/declarative_location_core/tst_ratings.qml b/tests/auto/declarative_location_core/tst_ratings.qml new file mode 100644 index 00000000..5628432f --- /dev/null +++ b/tests/auto/declarative_location_core/tst_ratings.qml @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtTest 1.0 +import QtLocation 5.3 +import "utils.js" as Utils + +TestCase { + id: testCase + + name: "Ratings" + + Ratings { id: emptyRatings } + + function test_empty() { + compare(emptyRatings.average, 0.0); + compare(emptyRatings.maximum, 0.0); + compare(emptyRatings.count, 0); + } + + Ratings { + id: qmlRatings + + average: 3.5 + maximum: 5.0 + count: 7 + } + + function test_qmlConstructedRatings() { + compare(qmlRatings.average, 3.5); + compare(qmlRatings.maximum, 5.0); + compare(qmlRatings.count, 7); + } + + Ratings { + id: testRatings + } + + function test_setAndGet_data() { + return [ + { tag: "average", property: "average", signal: "averageChanged", value: 4.5, reset: 0.0 }, + { tag: "maximum", property: "maximum", signal: "maximumChanged", value: 5.0, reset: 0.0 }, + { tag: "count", property: "count", signal: "countChanged", value: 10, reset: 0 }, + ]; + } + + function test_setAndGet(data) { + Utils.testObjectProperties(testCase, testRatings, data); + } +} diff --git a/tests/auto/declarative_location_core/tst_reviewmodel.qml b/tests/auto/declarative_location_core/tst_reviewmodel.qml new file mode 100644 index 00000000..192026fd --- /dev/null +++ b/tests/auto/declarative_location_core/tst_reviewmodel.qml @@ -0,0 +1,201 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtTest 1.0 +import QtLocation 5.3 +import "utils.js" as Utils + +TestCase { + id: testCase + name: "ReviewModel" + + Plugin { + id: testPlugin + name: "qmlgeo.test.plugin" + allowExperimental: true + parameters: [ + PluginParameter { + name: "initializePlaceData" + value: true + } + ] + } + + ReviewModel { + id: testModel + } + + Place { + id: testPlace + 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 }, + { tag: "batchSize", property: "batchSize", signal: "batchSizeChanged", value: 10, reset: 1 }, + ]; + } + + function test_setAndGet(data) { + Utils.testObjectProperties(testCase, testModel, data); + } + + function test_consecutive_fetch_data() { + return [ + { tag: "batchSize 1", batchSize: 1 }, + { tag: "batchSize 2", batchSize: 2 }, + { tag: "batchSize 5", batchSize: 5 }, + { tag: "batchSize 10", batchSize: 10 }, + ]; + } + + function test_consecutive_fetch(data) { + //Note: in javascript the months go from 0(Jan) to 11(Dec) + var expectedReviews = [ + { + "title": "Park View Review 1", + "text": "Park View Review 1 Text", + "dateTime": new Date(2004, 8, 22, 13, 1), + "language": "en", + "rating": 3.5, + "reviewId": "0001" + }, + { + "title": "Park View Review 2", + "text": "Park View Review 2 Text", + "dateTime": new Date(2005, 8, 14, 4, 17), + "language": "en", + "rating": 1, + "reviewId": "0002" + }, + { + "title": "Park View Review 3", + "text": "Park View Review 3 Text", + "dateTime": new Date(2005, 9, 14, 4, 12), + "language": "en", + "rating": 5, + "reviewId": "0003" + }, + { + "title": "", + "text": "", + "dateTime": new Date(""), + "language": "", + "rating": 0, + "reviewId": "" + }, + { + "title": "Park View Review 5", + "text": "Park View Review 5 Text", + "dateTime": new Date(2005, 10, 20, 14, 53), + "language": "en", + "rating": 2.3, + "reviewId": "0005" + } + ] + + var model = createModel(); + Utils.testConsecutiveFetch(testCase, model, parkViewHotel, expectedReviews, data); + model.destroy(); + } + + function test_reset() { + var model = createModel(); + Utils.testReset(testCase, model, parkViewHotel); + model.destroy(); + } + + function test_fetch_data() { + return [ + { + tag: "fetch all reviews in a single batch", + model: createModel(), + batchSize: 10, + place: parkViewHotel, + expectedTotalCount: 5, + expectedCount: 5 + }, + { + tag: "fetch from a place with no reviews", + 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.3; ReviewModel {}', + testCase, "reviewModel"); + } +} diff --git a/tests/auto/declarative_location_core/tst_routing.qml b/tests/auto/declarative_location_core/tst_routing.qml new file mode 100644 index 00000000..1d7c1e37 --- /dev/null +++ b/tests/auto/declarative_location_core/tst_routing.qml @@ -0,0 +1,971 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtTest 1.0 +import QtLocation 5.12 +import QtPositioning 5.12 + +Item { + id: root + function cloneArray(a) { + var i = a.length + var arr = new Array(i) + while (i--) arr[i] = a[i]; + return arr + } + Plugin { id: testPlugin; name: "qmlgeo.test.plugin"; allowExperimental: true } + Plugin { id: errorPlugin; name: "qmlgeo.test.plugin"; allowExperimental: true + parameters: [ + PluginParameter { name: "error"; value: "1"}, + PluginParameter { name: "errorString"; value: "This error was expected. No worries !"} + ] + } + + property variant coordinate1: QtPositioning.coordinate(51, 0) + property variant coordinate2: QtPositioning.coordinate(52, 0) + + property variant boundingBox1: QtPositioning.rectangle() + property variant boundingBox2: QtPositioning.rectangle() + + property variant circle1: QtPositioning.circle() + property variant circle2: QtPositioning.circle(tr, 4000) + + Component.onCompleted: { + boundingBox1.topLeft = bl + boundingBox1.bottomRight = bl + boundingBox1.width = 10 + + boundingBox2.topLeft = bl + boundingBox2.bottomRight = bl + boundingBox2.width = 20 + } + + property variant bl: QtPositioning.coordinate(0, 0) + property variant tl: QtPositioning.coordinate(1, 0) + property variant tr: QtPositioning.coordinate(1, 1) + property variant br: QtPositioning.coordinate(0, 1) + property variant ntr: QtPositioning.coordinate(3, 3) + + property variant unitBox: QtPositioning.rectangle(tl, br) + + Route {id: emptyRoute} + TestCase { + name: "RouteManeuver RouteSegment and MapRoute" + RouteSegment {id: emptySegment} + RouteManeuver {id: emptyManeuver} + + // TODO enable when we have map route + //MapRoute {id: emptyMapRoute} + + property variant emptyBox: QtPositioning.rectangle() + + property variant emptyCoordinate: QtPositioning.coordinate() + + // TODO enable when we have map route + /* + SignalSpy {id: mapRouteDetailLevelSpy; target: emptyMapRoute; signalName: "detailLevelChanged"} + SignalSpy {id: mapRouteColorSpy; target: emptyMapRoute.border; signalName: "colorChanged"} + SignalSpy {id: mapRouteWidthSpy; target: emptyMapRoute.border; signalName: "widthChanged"} + SignalSpy {id: mapRouteRouteSpy; target: emptyMapRoute; signalName: "routeChanged"} + function test_maproute_defaults() { + compare(mapRouteRouteSpy.count, 0) + compare(mapRouteColorSpy.count, 0) + compare(mapRouteDetailLevelSpy.count, 0) + compare (emptyMapRoute.detailLevel, 6) + emptyMapRoute.border.color = 'green' + emptyMapRoute.detailLevel = 3 + compare(mapRouteRouteSpy.count, 0) + compare(mapRouteColorSpy.count, 1) + compare(mapRouteDetailLevelSpy.count, 1) + emptyMapRoute.border.color = 'green' + emptyMapRoute.detailLevel = 3 + compare(mapRouteColorSpy.count, 1) + compare(mapRouteDetailLevelSpy.count, 1) + emptyMapRoute.route = emptyRoute + compare(mapRouteRouteSpy.count, 1) + compare(emptyMapRoute.route, emptyRoute) + // width + compare(mapRouteWidthSpy.count, 0) + emptyMapRoute.border.width = 123 + compare(mapRouteWidthSpy.count, 1) + compare(emptyMapRoute.border.width, 123) + emptyMapRoute.border.width = 123 + compare(mapRouteWidthSpy.count, 1) + emptyMapRoute.border.width = -1 + compare(mapRouteWidthSpy.count, 1) + compare(emptyMapRoute.border.width, 123) + emptyMapRoute.border.width = 0 + compare(mapRouteWidthSpy.count, 1) + compare(emptyMapRoute.border.width, 123) + } + */ + + function test_route_defaults() { + compare(emptyRoute.travelTime, 0) + compare(emptyRoute.distance,0) + compare(emptyRoute.path.length,0) + compare(emptyRoute.segments.length,0) + compare(emptyRoute.bounds.topLeft.latitude, emptyBox.topLeft.latitude) + compare(emptyRoute.bounds.bottomRight.longitude, emptyBox.bottomRight.longitude) + } + + function test_routesegment_defaults() { + compare(emptySegment.travelTime, 0) + compare(emptySegment.distance, 0) + compare(emptySegment.path.length, 0) + compare(emptySegment.maneuver.valid, emptyManeuver.valid) + compare(emptySegment.maneuver.instructionText, emptyManeuver.instructionText) + compare(emptySegment.maneuver.waypointValid, emptyManeuver.waypointValid) + } + function test_maneuver_defaults() { + compare(emptyManeuver.valid, false) + compare(emptyManeuver.instructionText, "") + compare(emptyManeuver.direction, RouteManeuver.NoDirection) + compare(emptyManeuver.timeToNextInstruction,0) + compare(emptyManeuver.distanceToNextInstruction,0) + compare(emptyManeuver.waypoint.latitude, emptyCoordinate.latitude) + compare(emptyManeuver.waypoint.longitude, emptyCoordinate.longitude) + compare(emptyManeuver.position.latitude, emptyCoordinate.latitude) + compare(emptyManeuver.position.longitude, emptyCoordinate.longitude) + } + } + + TestCase { + name: "MapRouteModel and MapRouteQuery" + RouteModel {id: emptyModel} + RouteQuery {id: emptyQuery} + + function test_model_default_properties() { + compare (emptyModel.autoUpdate, false, "Automatic update") + compare (emptyModel.status, RouteModel.Null, "Model status") + compare (emptyModel.errorString, "", "Model error") + compare (emptyModel.error, RouteModel.NoError) + compare (emptyModel.count, 0, "Model count") + emptyModel.get(192) // don't do stupid + + compare (emptyQuery.numberAlternativeRoutes, 0, "Number of alternative routes") + compare (emptyQuery.travelModes, RouteQuery.CarTravel, "Travel mode") + compare (emptyQuery.routeOptimizations, RouteQuery.FastestRoute, "Route optimization") + compare (emptyQuery.segmentDetail, RouteQuery.BasicSegmentData) + compare (emptyQuery.maneuverDetail, RouteQuery.BasicManeuvers) + compare (emptyQuery.waypoints.length, 0, "Waypoints") + compare (emptyQuery.excludedAreas.length, 0, "excluded areas") + compare (emptyQuery.featureTypes.length, 0, "Feature types") + } + + SignalSpy {id: autoUpdateSpy; target: emptyModel; signalName: "autoUpdateChanged"} + SignalSpy {id: pluginSpy; target: emptyModel ; signalName: "pluginChanged"} + + SignalSpy {id: travelModesSpy; target: emptyQuery; signalName: "travelModesChanged"} + SignalSpy {id: waypointsSpy; target: emptyQuery; signalName: "waypointsChanged"} + SignalSpy {id: exclusionSpy; target: emptyQuery; signalName: "excludedAreasChanged"} + SignalSpy {id: featureTypesSpy; target: emptyQuery; signalName: "featureTypesChanged"} + SignalSpy {id: segmentDetailSpy; target: emptyQuery; signalName: "segmentDetailChanged"} + SignalSpy {id: maneuverDetailSpy; target: emptyQuery; signalName: "maneuverDetailChanged"} + SignalSpy {id: numberAlterNativeRoutesSpy; target: emptyQuery; signalName: "numberAlternativeRoutesChanged"} + SignalSpy {id: routeOptimizationsSpy; target: emptyQuery; signalName: "routeOptimizationsChanged"} + SignalSpy {id: queryDetailsChangedSpy; target: emptyQuery; signalName: "queryDetailsChanged"} + function test_model_setters() { + // Autoupdate + compare(autoUpdateSpy.count, 0) + emptyModel.autoUpdate = true + compare(autoUpdateSpy.count, 1) + compare(emptyModel.autoUpdate, true) + emptyModel.autoUpdate = true // mustn't retrigger 'changed' -signal + compare(autoUpdateSpy.count, 1) + emptyModel.autoUpdate = false + compare(autoUpdateSpy.count, 2) + + // Travelmodes + compare(travelModesSpy.count, 0) + emptyQuery.travelModes = RouteQuery.BicycleTravel + compare(travelModesSpy.count, 1) + compare(emptyQuery.travelModes, RouteQuery.BicycleTravel) + emptyQuery.travelModes = RouteQuery.BicycleTravel | RouteQuery.PedestrianTravel + compare(emptyQuery.travelModes, RouteQuery.BicycleTravel | RouteQuery.PedestrianTravel) + compare(travelModesSpy.count, 2) + compare(queryDetailsChangedSpy.count, 2) + + // Basic adding and removing of waypoint + queryDetailsChangedSpy.clear() + compare(waypointsSpy.count, 0) + emptyQuery.addWaypoint(coordinate1) + compare(waypointsSpy.count, 1) + compare(queryDetailsChangedSpy.count, 1) + emptyQuery.addWaypoint(coordinate1) + compare(waypointsSpy.count, 2) + compare(queryDetailsChangedSpy.count, 2) + compare(emptyQuery.waypoints.length, 2) + emptyQuery.removeWaypoint(coordinate1) + compare(waypointsSpy.count, 3) + compare(queryDetailsChangedSpy.count, 3) + compare(emptyQuery.waypoints.length, 1) + emptyQuery.removeWaypoint(coordinate2) // coordinate2 isn't in the list, must not impact + compare(waypointsSpy.count, 3) + compare(queryDetailsChangedSpy.count, 3) + emptyQuery.removeWaypoint(coordinate1) + compare(waypointsSpy.count, 4) + emptyQuery.removeWaypoint(coordinate1) // doesn't exist anymore, must not impact + compare(waypointsSpy.count, 4) + compare(emptyQuery.waypoints.length, 0) + // Check correct ordering of waypoints + waypointsSpy.clear() + emptyQuery.addWaypoint(coordinate1) + emptyQuery.addWaypoint(coordinate2) + emptyQuery.addWaypoint(coordinate1) + emptyQuery.addWaypoint(coordinate2) + compare(waypointsSpy.count, 4) + compare(emptyQuery.waypoints[0], coordinate1) + compare(emptyQuery.waypoints[1], coordinate2) + compare(emptyQuery.waypoints[2], coordinate1) + compare(emptyQuery.waypoints[3], coordinate2) + emptyQuery.removeWaypoint(coordinate1) // remove one from the middle, check that one added last is removed + compare(emptyQuery.waypoints[0], coordinate1) + compare(emptyQuery.waypoints[1], coordinate2) + compare(emptyQuery.waypoints[2], coordinate2) + waypointsSpy.clear() + emptyQuery.clearWaypoints() + compare(emptyQuery.waypoints.length, 0) + compare(waypointsSpy.count, 1) + + // Altering the waypoint contents should trigger signal + emptyQuery.clearWaypoints() + queryDetailsChangedSpy.clear(); + emptyQuery.addWaypoint(coordinate1) + compare(queryDetailsChangedSpy.count, 1); + + // verify coordinate is disconnected + emptyQuery.removeWaypoint(coordinate1) + compare (queryDetailsChangedSpy.count, 2) + + // verify that the same coordinate can be added to the waypoints + emptyQuery.addWaypoint(coordinate1) + compare(queryDetailsChangedSpy.count, 3); + emptyQuery.addWaypoint(coordinate1) + compare(queryDetailsChangedSpy.count, 4); + compare (emptyQuery.waypoints.length, 2) + queryDetailsChangedSpy.clear() + + // verify that removing duplicate coordinate leaves remaining ones + emptyQuery.removeWaypoint(coordinate1) + compare (queryDetailsChangedSpy.count, 1) + compare (emptyQuery.waypoints.length, 1) + + // verify that clearing works + emptyQuery.clearWaypoints() + compare(queryDetailsChangedSpy.count, 2); + compare (emptyQuery.waypoints.length, 0) + + // Excluded areas + queryDetailsChangedSpy.clear() + compare(exclusionSpy.count, 0) + emptyQuery.addExcludedArea(boundingBox1) + compare(exclusionSpy.count, 1) + compare(queryDetailsChangedSpy.count, 1) + emptyQuery.addExcludedArea(boundingBox1) + // doesn't make sense to put same area twice + compare(exclusionSpy.count, 1) + compare(queryDetailsChangedSpy.count, 1) + compare(emptyQuery.excludedAreas.length, 1) + emptyQuery.removeExcludedArea(boundingBox1) + compare(exclusionSpy.count, 2) + compare(queryDetailsChangedSpy.count, 2) + compare(emptyQuery.excludedAreas.length, 0) + emptyQuery.removeExcludedArea(boundingBox2) // boundingBox2 isn't in the list, must not impact + compare(exclusionSpy.count, 2) + compare(queryDetailsChangedSpy.count, 2) + emptyQuery.removeExcludedArea(boundingBox1) // doesn't exist anymore, must not impact + compare(exclusionSpy.count, 2) + compare(queryDetailsChangedSpy.count, 2) + // Check correct ordering of exclusion + exclusionSpy.clear() + emptyQuery.addExcludedArea(boundingBox1) + emptyQuery.addExcludedArea(boundingBox2) + emptyQuery.addExcludedArea(boundingBox1) + emptyQuery.addExcludedArea(boundingBox2) + compare(exclusionSpy.count, 2) + compare(emptyQuery.excludedAreas[0], boundingBox1) + compare(emptyQuery.excludedAreas[1], boundingBox2) + emptyQuery.removeExcludedArea(boundingBox1) // remove first and check all geos ok + compare(emptyQuery.excludedAreas[0], boundingBox2) + exclusionSpy.clear() + emptyQuery.clearExcludedAreas() + compare(emptyQuery.excludedAreas.length, 0) + compare(exclusionSpy.count, 1) + + // verify that clearing works + emptyQuery.addExcludedArea(unitBox); + compare(emptyQuery.excludedAreas.length, 1); + queryDetailsChangedSpy.clear(); + emptyQuery.clearExcludedAreas(); + compare(queryDetailsChangedSpy.count, 1); + compare(emptyQuery.excludedAreas.length, 0) + + // Feature types and weights + queryDetailsChangedSpy.clear() + compare(emptyQuery.featureTypes.length, 0) + compare(featureTypesSpy.count, 0) + emptyQuery.setFeatureWeight(RouteQuery.TollFeature, RouteQuery.AvoidFeatureWeight); + compare(featureTypesSpy.count, 1) + compare(queryDetailsChangedSpy.count, 1) + emptyQuery.setFeatureWeight(RouteQuery.HighwayFeature, RouteQuery.PreferFeatureWeight); + compare(featureTypesSpy.count, 2) + compare(queryDetailsChangedSpy.count, 2) + compare(emptyQuery.featureTypes.length, 2) + compare(emptyQuery.featureTypes[0], RouteQuery.TollFeature) + compare(emptyQuery.featureTypes[1], RouteQuery.HighwayFeature) + // Verify feature weights are as set + compare(emptyQuery.featureWeight(RouteQuery.TollFeature), RouteQuery.AvoidFeatureWeight); + compare(emptyQuery.featureWeight(RouteQuery.HighwayFeature), RouteQuery.PreferFeatureWeight); + // Neutralize a weight, feature should disappear + emptyQuery.setFeatureWeight(RouteQuery.TollFeature, RouteQuery.NeutralFeatureWeight); + compare(featureTypesSpy.count, 3) + compare(queryDetailsChangedSpy.count, 3) + compare(emptyQuery.featureTypes.length, 1) + compare(emptyQuery.featureWeight(RouteQuery.TollFeature), RouteQuery.NeutralFeatureWeight); + compare(emptyQuery.featureWeight(RouteQuery.HighwayFeature), RouteQuery.PreferFeatureWeight); + compare(emptyQuery.featureTypes[0], RouteQuery.HighwayFeature) + compare(emptyQuery.featureWeight(emptyQuery.featureTypes[0]), RouteQuery.PreferFeatureWeight) + compare(featureTypesSpy.count, 3) + compare(queryDetailsChangedSpy.count, 3) + compare(emptyQuery.featureTypes.length, 1) + + // Put some feature weights and then reset them with NoFeature + emptyQuery.setFeatureWeight(RouteQuery.FerryFeature, RouteQuery.RequireFeatureWeight); + emptyQuery.setFeatureWeight(RouteQuery.MotorPoolLaneFeature, RouteQuery.DisallowFeatureWeight); + compare(featureTypesSpy.count, 5) + compare(queryDetailsChangedSpy.count, 5) + compare(emptyQuery.featureTypes.length, 3) + emptyQuery.setFeatureWeight(RouteQuery.NoFeature, RouteQuery.NeutralFeatureWeight) + compare(featureTypesSpy.count, 6) + compare(queryDetailsChangedSpy.count, 6) + compare(emptyQuery.featureTypes.length, 0) + + // Segment details + queryDetailsChangedSpy.clear() + compare(segmentDetailSpy.count, 0) + compare(emptyQuery.segmentDetail, RouteQuery.BasicSegmentData) + emptyQuery.segmentDetail = RouteQuery.NoSegmentData + compare(segmentDetailSpy.count, 1) + compare(queryDetailsChangedSpy.count, 1) + compare(emptyQuery.segmentDetail, RouteQuery.NoSegmentData) + emptyQuery.segmentDetail = RouteQuery.NoSegmentData + compare(segmentDetailSpy.count, 1) + compare(queryDetailsChangedSpy.count, 1) + compare(emptyQuery.segmentDetail, RouteQuery.NoSegmentData) + + // Maneuver details + queryDetailsChangedSpy.clear() + compare(maneuverDetailSpy.count, 0) + compare(emptyQuery.maneuverDetail, RouteQuery.BasicManeuvers) + emptyQuery.maneuverDetail = RouteQuery.NoManeuvers + compare(maneuverDetailSpy.count, 1) + compare(queryDetailsChangedSpy.count, 1) + compare(emptyQuery.maneuverDetail, RouteQuery.NoManeuvers) + emptyQuery.maneuverDetail = RouteQuery.NoManeuvers + compare(maneuverDetailSpy.count, 1) + compare(queryDetailsChangedSpy.count, 1) + compare(emptyQuery.maneuverDetail, RouteQuery.NoManeuvers) + + // NumberAlternativeRoutes + queryDetailsChangedSpy.clear() + compare(numberAlterNativeRoutesSpy.count, 0) + compare(emptyQuery.numberAlternativeRoutes, 0) + emptyQuery.numberAlternativeRoutes = 2 + compare(numberAlterNativeRoutesSpy.count, 1) + compare(queryDetailsChangedSpy.count, 1) + compare(emptyQuery.numberAlternativeRoutes, 2) + emptyQuery.numberAlternativeRoutes = 2 + compare(numberAlterNativeRoutesSpy.count, 1) + compare(queryDetailsChangedSpy.count, 1) + compare(emptyQuery.numberAlternativeRoutes, 2) + + // Route optimization + queryDetailsChangedSpy.clear() + compare(routeOptimizationsSpy.count, 0) + compare(emptyQuery.routeOptimizations, RouteQuery.FastestRoute) + emptyQuery.routeOptimizations = RouteQuery.ShortestRoute + compare(routeOptimizationsSpy.count, 1) + compare(queryDetailsChangedSpy.count, 1) + compare(emptyQuery.routeOptimizations, RouteQuery.ShortestRoute) + emptyQuery.routeOptimizations = RouteQuery.ShortestRoute | RouteQuery.MostScenicRoute + compare(routeOptimizationsSpy.count, 2) + compare(queryDetailsChangedSpy.count, 2) + compare(emptyQuery.routeOptimizations, RouteQuery.ShortestRoute | RouteQuery.MostScenicRoute) + + // Must act gracefully + emptyModel.reset() + emptyModel.update() + + // Plugin + compare(pluginSpy.count, 0) + emptyModel.plugin = testPlugin + compare(pluginSpy.count, 1) + compare(emptyModel.plugin, testPlugin) + emptyModel.plugin = testPlugin + compare(pluginSpy.count, 1) + emptyModel.plugin = errorPlugin + compare(pluginSpy.count, 2) + + // Must act gracefully + emptyModel.reset() + emptyModel.update() + } + // Test that model acts gracefully when plugin is not set or is invalid + // (does not support routing) + RouteModel {id: errorModel; plugin: errorPlugin} + RouteModel {id: errorModelNoPlugin} + SignalSpy {id: countInvalidSpy; target: errorModel; signalName: "countChanged"} + SignalSpy {id: errorSpy; target: errorModel; signalName: "errorChanged"} + function test_error_plugin() { + // test plugin not set + compare(errorModelNoPlugin.error,RouteModel.NoError) + errorModelNoPlugin.update() + compare(errorModelNoPlugin.error,RouteModel.EngineNotSetError) + console.log(errorModelNoPlugin.errorString) + + //plugin set but otherwise not offering anything + compare(errorModel.error,RouteModel.EngineNotSetError) + compare(errorModel.errorString,"This error was expected. No worries !") + errorSpy.clear() + errorModel.update() + compare(errorModel.error,RouteModel.EngineNotSetError) + compare(errorModel.errorString,qsTr("Cannot route, route manager not set.")) + compare(errorSpy.count, 1) + errorSpy.clear() + errorModel.cancel() + compare(errorModel.error,RouteModel.NoError) + compare(errorModel.errorString,"") + compare(errorSpy.count, 1) + errorSpy.clear() + errorModel.reset() + compare(errorModel.error,RouteModel.NoError) + compare(errorModel.errorString,"") + compare(errorSpy.count, 0) + errorSpy.clear() + errorModel.update() + compare(errorModel.error,RouteModel.EngineNotSetError) + compare(errorModel.errorString,qsTr("Cannot route, route manager not set.")) + compare(errorSpy.count, 1) + errorSpy.clear() + var data = errorModel.get(-1) + compare(data, null) + } + } + + Plugin { + id: testPlugin_immediate; + name: "qmlgeo.test.plugin" + allowExperimental: true + parameters: [ + // Parms to guide the test plugin + PluginParameter { name: "gc_supported"; value: true}, + PluginParameter { name: "gc_finishRequestImmediately"; value: true}, + PluginParameter { name: "gc_validateWellKnownValues"; value: true} + ] + } + + Plugin { + id: testPlugin_slacker; + name: "qmlgeo.test.plugin" + allowExperimental: true + parameters: [ + // Parms to guide the test plugin + PluginParameter { name: "gc_finishRequestImmediately"; value: false} + ] + } + + Plugin { + id: testPlugin_slacker_alt + name: "qmlgeo.test.plugin" + allowExperimental: true + PluginParameter { name: "gc_finishRequestImmediately"; value: false} + PluginParameter { name: "gc_alternateGeoRoute"; value: true} + } + + Plugin { + id: basicRoutingPlugin_slacker; + name: "qmlgeo.test.plugin" + allowExperimental: true + parameters: [ + // Parms to guide the test plugin + PluginParameter { name: "gc_finishRequestImmediately"; value: false} + ] + } + + property variant rcoordinate1: QtPositioning.coordinate(50, 50) + property variant rcoordinate2: QtPositioning.coordinate(51, 52) + property variant rcoordinate3: QtPositioning.coordinate(53, 54) + property variant rcoordinate4: QtPositioning.coordinate(55, 56) + property variant rcoordinate5: QtPositioning.coordinate(57, 58) + + property variant fcoordinate1: QtPositioning.coordinate(60, 60) + property variant fcoordinate2: QtPositioning.coordinate(61, 62) + property variant fcoordinate3: QtPositioning.coordinate(63, 64) + property variant fcoordinate4: QtPositioning.coordinate(65, 66) + property variant fcoordinate5: QtPositioning.coordinate(67, 68) + + property variant f2coordinate1: QtPositioning.coordinate(60, 60) + property variant f2coordinate2: QtPositioning.coordinate(61, 62) + property variant f2coordinate3: QtPositioning.coordinate(63, 64) + + Waypoint { + id: waypoint1 + coordinate: QtPositioning.coordinate(70, 70) + bearing: 42 + } + + Waypoint { + id: waypoint2 + coordinate: QtPositioning.coordinate(71, 71) + bearing: 43 + + MapParameter { + id: param1 + type: "user_distance" + property real distance: 10 + } + } + + RouteQuery {id: routeQuery} + property var routeQueryDefaultWaypoints: [ + { latitude: 60, longitude: 60 }, + { latitude: 61, longitude: 62 }, + { latitude: 63, longitude: 64 }, + { latitude: 65, longitude: 66 }, + { latitude: 67, longitude: 68 } + ] + property var routeQuery2DefaultWaypoints: [ + f2coordinate1, + f2coordinate2, + f2coordinate3 + ] + RouteQuery { + id: filledRouteQuery + numberAlternativeRoutes: 0 + waypoints: routeQueryDefaultWaypoints + } + RouteQuery { + id: filledRouteQuery2 + numberAlternativeRoutes: 0 + waypoints: routeQuery2DefaultWaypoints + } + RouteModel { + id: routeModelAutomatic; + plugin: testPlugin_slacker; + query: filledRouteQuery; + autoUpdate: true + } + RouteModel { + id: routeModelAutomaticAltImpl; + plugin: testPlugin_slacker_alt; + query: filledRouteQuery; + autoUpdate: true + } + + SignalSpy {id: automaticRoutesSpy; target: routeModelAutomatic; signalName: "routesChanged" } + SignalSpy {id: automaticRoutesSpyAlt; target: routeModelAutomaticAltImpl; signalName: "routesChanged" } + + RouteModel {id: routeModel; plugin: testPlugin_immediate; query: routeQuery } + SignalSpy {id: testRoutesSpy; target: routeModel; signalName: "routesChanged"} + SignalSpy {id: testCountSpy; target: routeModel; signalName: "countChanged" } + SignalSpy {id: testStatusSpy; target: routeModel; signalName: "statusChanged"} + SignalSpy {id: testErrorStringSpy; target: routeModel; signalName: "errorChanged"} + SignalSpy {id: testErrorSpy; target: routeModel; signalName: "errorChanged"} + SignalSpy {id: testWaypointsSpy; target: routeQuery; signalName: "waypointsChanged"} + + RouteModel {id: routeModelSlack; plugin: basicRoutingPlugin_slacker; query: routeQuery } + SignalSpy {id: testRoutesSlackSpy; target: routeModelSlack; signalName: "routesChanged"} + SignalSpy {id: testCountSlackSpy; target: routeModelSlack; signalName: "countChanged" } + SignalSpy {id: testStatusSlackSpy; target: routeModelSlack; signalName: "statusChanged"} + SignalSpy {id: testErrorStringSlackSpy; target: routeModelSlack; signalName: "errorChanged"} + SignalSpy {id: testErrorSlackSpy; target: routeModelSlack; signalName: "errorChanged"} + SignalSpy {id: testPluginSlackSpy; target: routeModelSlack; signalName: "pluginChanged"} + + RouteModel {id: routeModelEquals; plugin: testPlugin_immediate; query: routeQuery } + + TestCase { + name: "Routing" + function clear_immediate_model() { + routeModel.reset() + testRoutesSpy.clear() + testCountSpy.clear() + testStatusSpy.clear() + testErrorStringSpy.clear() + testErrorSpy.clear() + } + function clear_slacker_model() { + routeModelSlack.reset() + testRoutesSlackSpy.clear() + testCountSlackSpy.clear() + testStatusSlackSpy.clear() + testErrorStringSlackSpy.clear() + testErrorSlackSpy.clear() + } + + function test_reset() { + clear_immediate_model(); + routeQuery.numberAlternativeRoutes = 72 // 'altroutes - 70' is the echoed errorcode + routeModel.update() + verify (testErrorStringSpy.count > 0) + verify (testErrorSpy.count > 0) + compare (routeModel.errorString, "error") + compare (routeModel.error, RouteModel.CommunicationError) + compare (routeModel.count, 0) + compare (testStatusSpy.count, 2) + compare (routeModel.status, RouteModel.Error) + routeModel.reset() + compare (routeModel.status, RouteModel.Null) + compare (routeModel.errorString, "") + compare (routeModel.error, RouteModel.NoError) + // Check that ongoing req is aborted + clear_slacker_model() + routeQuery.numberAlternativeRoutes = 3 + routeModelSlack.update() + wait (100) + routeModelSlack.reset() + wait (200) + compare (routeModelSlack.count, 0) + // Check that results are cleared + routeModelSlack.update() + tryCompare(routeModelSlack, "count", 3) // numberALternativeRoutes + routeModelSlack.reset() + compare (routeModelSlack.count, 0) + // Check that changing plugin resets any ongoing requests + clear_slacker_model() + routeQuery.numberAlternativeRoutes = 3 + compare (testPluginSlackSpy.count, 0) + routeModelSlack.update() + wait (100) + routeModelSlack.plugin = testPlugin_immediate + wait (200) + compare (routeModelSlack.count, 0) // should be no updates + compare (testPluginSlackSpy.count, 1) + // test that works + routeModelSlack.update() + compare (routeModelSlack.count, 3) + // return back + routeModelSlack.plugin = testPlugin_slacker + } + + function test_error_routing() { + // Basic immediate error + clear_immediate_model(); + routeQuery.numberAlternativeRoutes = 72 // 'altroutes - 70' is the echoed errorcode + routeModel.update() + compare (testErrorStringSpy.count, 1) + compare (testErrorSpy.count, 1) + compare (routeModel.errorString, "error") + compare (routeModel.error, RouteModel.CommunicationError) + compare (routeModel.count, 0) + compare (testStatusSpy.count, 2) + compare (routeModel.status, RouteModel.Error) + // Basic delayed error + clear_slacker_model() + routeQuery.numberAlternativeRoutes = 72 + routeModelSlack.update() + compare (testErrorStringSlackSpy.count, 0) + compare (testErrorSlackSpy.count, 0) + if (routeModelSlack.errorString == "") + tryCompare(testErrorStringSlackSpy, "count", 1) + else + tryCompare(testErrorStringSlackSpy, "count", 2) + compare (routeModelSlack.errorString, "error") + compare (routeModelSlack.error, RouteModel.CommunicationError) + compare (routeModelSlack.count, 0) + // check that we recover + routeQuery.numberAlternativeRoutes = 1 + routeModelSlack.update() + tryCompare(routeModelSlack, "count", 1) + compare (testCountSlackSpy.count, 1) + compare (routeModelSlack.errorString, "") + compare (routeModelSlack.error, RouteModel.NoError) + } + function test_basic_routing() { + compare (testRoutesSpy.count, 0) + compare (routeModel.errorString, "") + compare (routeModel.error, RouteModel.NoError) + compare (testCountSpy.count, 0) + compare (routeModel.count, 0) + compare (routeQuery.waypoints.length, 0) + compare (testWaypointsSpy.count, 0) + routeQuery.addWaypoint(rcoordinate1) + routeQuery.addWaypoint(rcoordinate2) + routeQuery.addWaypoint(rcoordinate3) + routeQuery.addWaypoint(rcoordinate4) + routeQuery.addWaypoint(rcoordinate5) + compare (testWaypointsSpy.count, 5) + compare (routeQuery.waypoints.length, 5) + routeQuery.numberAlternativeRoutes = 1 // how many routes to get back, > 70 indicates error + routeModel.update() + routeModelEquals.update() + tryCompare (testRoutesSpy, "count", 1) // 5 sec + tryCompare (testCountSpy, "count", 1) + compare (routeModel.count, 1) + // the test plugin echoes waypoints back as the path of the route: + compare (routeQuery.waypoints.length, 5) + compare (routeModel.get(0).path.length, 5) + compare (routeModel.get(0).path[0].latitude, routeQuery.waypoints[0].latitude) + // test Route.equals + var route1 = routeModel.get(0) + var route2 = routeModelEquals.get(0) + verify(route1 !== route2) + verify(route1.equals(route2)) + // check reset() functionality + routeModel.reset() + tryCompare (testRoutesSpy, "count", 2) // 5 sec + tryCompare (testCountSpy, "count", 2) + compare (routeModel.count, 0) + + // delayed responses + compare (testRoutesSlackSpy.count, 0) + compare (routeModelSlack.errorString, "") + compare (routeModel.error, RouteModel.NoError) + compare (testCountSlackSpy.count, 0) + compare (routeModelSlack.count, 0) + routeModelSlack.update() + wait (100) + compare (testRoutesSlackSpy.count, 0) + compare (testCountSlackSpy.count, 0) + tryCompare(testRoutesSlackSpy, "count", 1) + compare (testCountSlackSpy.count, 1) + compare(routeModelSlack.count, 1) + compare (routeModelSlack.get(0).path.length, 5) + compare (routeModelSlack.get(0).path[0].latitude, routeQuery.waypoints[0].latitude) + + // Frequent updates, previous requests are aborted + routeModelSlack.reset() + testRoutesSlackSpy.clear() + testCountSlackSpy.clear() + routeModelSlack.update() + wait (100) + compare(testRoutesSlackSpy.count, 0) + compare(testCountSlackSpy.count, 0) + routeModelSlack.update() + wait (100) + compare(testRoutesSlackSpy.count, 0) + compare(testCountSlackSpy.count, 0) + routeModelSlack.update() + wait (100) + compare(testRoutesSlackSpy.count, 0) + compare(testCountSlackSpy.count, 0) + routeModelSlack.update() + wait (100) + compare(testRoutesSlackSpy.count, 0) + compare(testCountSlackSpy.count, 0) + tryCompare(testRoutesSlackSpy, "count", 1) + compare(testCountSlackSpy.count, 1) + compare(routeModelSlack.count, 1) + + test_basic_routing_automatic(routeModelAutomatic, automaticRoutesSpy, "routeModelAutomatic") + test_basic_routing_automatic(routeModelAutomaticAltImpl, automaticRoutesSpyAlt, "routeModelAutomaticAltImpl") + } + + function test_basic_routing_automatic(model, spy, label) { + if (label === undefined) + return + console.log("testing",label) + // Autoupdate + spy.clear(); + filledRouteQuery.numberAlternativeRoutes = 1 // 'altroutes - 70' is the echoed errorcode + tryCompare (spy, "count", 1) // 5 sec + compare(model.count, 1) // There should be a route already + compare (model.get(0).path.length, 5) + compare (model.get(0).path[0].latitude, filledRouteQuery.waypoints[0].latitude) + + if (label === "routeModelAutomaticAltImpl") // Test that it is an altImpl + compare(model.get(0).travelTime, 123456) + + // Remove a waypoint and check that autoupdate works + filledRouteQuery.removeWaypoint(fcoordinate2) + tryCompare (spy, "count", 2) + compare (model.get(0).path.length, 4) + compare (model.get(0).path[0].latitude, fcoordinate1.latitude) + + // Add a waypoint and check that autoupdate works + filledRouteQuery.addWaypoint(fcoordinate2); + tryCompare (spy, "count", 3) + compare(model.count, 1); + compare(model.get(0).path.length, 5); + compare(model.get(0).path[0].latitude, filledRouteQuery.waypoints[0].latitude); + + // Change contents of a coordinate and check that autoupdate works + filledRouteQuery.waypoints = [ + { latitude: fcoordinate1.latitude + 1, longitude: fcoordinate1.longitude }, + { latitude: 61, longitude: 62 }, + { latitude: 63, longitude: 64 }, + { latitude: 65, longitude: 66 }, + { latitude: 67, longitude: 68 } + ]; + tryCompare (spy, "count", 4) + compare(model.get(0).path[0].latitude, fcoordinate1.latitude + 1) // new value should be echoed + + // Extra parameter + var param = Qt.createQmlObject ('import QtLocation 5.9; MapParameter { type : "test-traveltime"; property var requestedTime : 42}', root) + var initialParams = cloneArray(filledRouteQuery.quickChildren) + var modifiedParams = cloneArray(initialParams) + modifiedParams.push(param) + + filledRouteQuery.quickChildren = modifiedParams + tryCompare (spy, "count", 5) + if (label === "routeModelAutomaticAltImpl") + compare(model.get(0).travelTime, 123456) + else + compare(model.get(0).travelTime, 42) + param.requestedTime = 43 + tryCompare (spy, "count", 6) + if (label === "routeModelAutomaticAltImpl") + compare(model.get(0).travelTime, 123456) + else + compare(model.get(0).travelTime, 43) + filledRouteQuery.quickChildren = initialParams + tryCompare (spy, "count", 7) + if (label === "routeModelAutomaticAltImpl") + compare(model.get(0).travelTime, 123456) + else + compare(model.get(0).travelTime, 0) + var secondParam = Qt.createQmlObject ('import QtLocation 5.9; MapParameter { type : "foo"; property var bar : 42}', root) + modifiedParams.push(secondParam) + param.requestedTime = 44 + filledRouteQuery.quickChildren = modifiedParams + tryCompare (spy, "count", 8) + if (label === "routeModelAutomaticAltImpl") + compare(model.get(0).travelTime, 123456) + else + compare(model.get(0).travelTime, 44) + filledRouteQuery.quickChildren = initialParams + tryCompare (spy, "count", 9) + if (label === "routeModelAutomaticAltImpl") + compare(model.get(0).travelTime, 123456) + else + compare(model.get(0).travelTime, 0) + + /* Test waypoints */ + // Verify that bearing is NaN for coordinates + verify(isNaN(filledRouteQuery.waypointObjects()[0].bearing)) + var numWaypoints = filledRouteQuery.waypoints.length + // Add a waypoint with bearing + filledRouteQuery.addWaypoint(waypoint1) + tryCompare (spy, "count", 10) + compare(filledRouteQuery.waypointObjects()[numWaypoints].bearing, 42) + // testing Waypoint to coordinate conversion + compare(filledRouteQuery.waypoints[numWaypoints], filledRouteQuery.waypointObjects()[numWaypoints].coordinate) + waypoint1.latitude += 0.1 + compare(model.get(0).distance, 0) + tryCompare (spy, "count", 11) + numWaypoints++; + filledRouteQuery.addWaypoint(waypoint2) // waypoint2 contains a MapParameter with user_distance + numWaypoints++; + tryCompare (spy, "count", 12) + compare(filledRouteQuery.waypointObjects()[numWaypoints-1].bearing, 43) + compare(model.get(0).distance, 10) + waypoint1.latitude += 0.1 + tryCompare (spy, "count", 13) + waypoint2.latitude += 0.1 + tryCompare (spy, "count", 14) + filledRouteQuery.removeWaypoint(waypoint1) + tryCompare (spy, "count", 15) + waypoint2.latitude += 0.1 + tryCompare (spy, "count", 16) + waypoint1.latitude += 0.1 + tryCompare (spy, "count", 16) // No effect, now disconnected + // test with other props + waypoint2.longitude += 0.1 + tryCompare (spy, "count", 17) + waypoint2.altitude = 42 + tryCompare (spy, "count", 18) + waypoint2.bearing += 1 + tryCompare (spy, "count", 19) + compare(waypoint2.longitude, 71.1) + compare(waypoint2.altitude, 42) + compare(waypoint2.bearing, 44) + // test with map parameters + param1.distance = 42 + tryCompare (spy, "count", 20) + compare(model.get(0).distance, 42) + + + // Change query + model.query = filledRouteQuery2 + filledRouteQuery2.numberAlternativeRoutes = 3 + tryCompare (spy, "count", 21) + compare (model.get(0).path.length, 3) + + // Verify that the old query is disconnected internally ie. does not trigger update + filledRouteQuery.waypoints = [ + { latitude: fcoordinate1.latitude + 2, longitude: fcoordinate1.longitude }, + { latitude: 61, longitude: 62 }, + { latitude: 63, longitude: 64 }, + { latitude: 65, longitude: 66 }, + { latitude: 67, longitude: 68 } + ]; + wait(800) // wait to hope no further updates comes through + compare (spy.count, 21) + compare(model.get(0).path.length, 3); + + // departure time + verify(!model.get(0).extendedAttributes["tst_departureTime"]) + var invalidDate = new Date("abc"); // to create an invalid date + var validDate = new Date("2011-02-07T11:05:00"); + + filledRouteQuery2.departureTime = validDate + tryCompare(spy, "count", 22) + compare(model.get(0).extendedAttributes["tst_departureTime"], validDate) + + filledRouteQuery2.departureTime = invalidDate + tryCompare (spy, "count", 23) + verify(!model.get(0).extendedAttributes["tst_departureTime"]) + + // ReSetting + filledRouteQuery.numberAlternativeRoutes = 0 + filledRouteQuery2.numberAlternativeRoutes = 0 + filledRouteQuery.waypoints = routeQueryDefaultWaypoints + filledRouteQuery2.waypoints = routeQuery2DefaultWaypoints + + waypoint1.coordinate = QtPositioning.coordinate(70, 70) + waypoint2.bearing = 42 + waypoint2.coordinate = QtPositioning.coordinate(71, 71) + waypoint2.bearing = 43 + param1.distance = 10 + } + + + + function test_route_query_handles_destroyed_qml_objects() { + var coordinate = QtPositioning.coordinate(11, 52); + routeQuery.addWaypoint(coordinate); + wait(300); + routeQuery.clearWaypoints(); + } + } +} + + + + diff --git a/tests/auto/declarative_location_core/tst_supplier.qml b/tests/auto/declarative_location_core/tst_supplier.qml new file mode 100644 index 00000000..3fcb0d1f --- /dev/null +++ b/tests/auto/declarative_location_core/tst_supplier.qml @@ -0,0 +1,100 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtTest 1.0 +import QtLocation 5.3 +import "utils.js" as Utils + +TestCase { + id: testCase + + name: "Supplier" + + Supplier { id: emptySupplier } + + function test_empty() { + compare(emptySupplier.supplierId, ""); + compare(emptySupplier.name, ""); + compare(emptySupplier.url, ""); + verify(emptySupplier.icon); + } + + Supplier { + id: qmlSupplier + + supplierId: "test-supplier-id" + name: "Test Supplier" + url: "http://example.com/test-supplier-id" + + icon: Icon { + Component.onCompleted: { + parameters.singleUrl = "http://example.com/icons/test-supplier.png" + } + } + } + + function test_qmlConstructedSupplier() { + compare(qmlSupplier.supplierId, "test-supplier-id"); + compare(qmlSupplier.name, "Test Supplier"); + compare(qmlSupplier.url, "http://example.com/test-supplier-id"); + verify(qmlSupplier.icon); + compare(qmlSupplier.icon.parameters.singleUrl, "http://example.com/icons/test-supplier.png"); + } + + Supplier { + id: testSupplier + } + + Plugin { + id: testPlugin + name: "qmlgeo.test.plugin" + allowExperimental: true + } + + Plugin { + id: invalidPlugin + } + + Icon { + id: testIcon + } + + function test_setAndGet_data() { + return [ + { tag: "name", property: "name", signal: "nameChanged", value: "Test Supplier", reset: "" }, + { tag: "supplierId", property: "supplierId", signal: "supplierIdChanged", value: "test-supplier-id-1", reset: "" }, + { tag: "url", property: "url", signal: "urlChanged", value: "http://example.com/test-supplier-id-1", reset: "" }, + { tag: "icon", property: "icon", signal: "iconChanged", value: testIcon } + ]; + } + + function test_setAndGet(data) { + Utils.testObjectProperties(testCase, testSupplier, data); + } +} diff --git a/tests/auto/declarative_location_core/tst_user.qml b/tests/auto/declarative_location_core/tst_user.qml new file mode 100644 index 00000000..1453c41a --- /dev/null +++ b/tests/auto/declarative_location_core/tst_user.qml @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtTest 1.0 +import QtLocation 5.3 +import "utils.js" as Utils + +TestCase { + id: testCase + + name: "User" + + User { id: emptyUser } + + function test_empty() { + compare(emptyUser.userId, ""); + compare(emptyUser.name, ""); + } + + User { + id: qmlUser + + userId: "testuser" + name: "Test User" + } + + function test_qmlConstructedUser() { + compare(qmlUser.userId, "testuser"); + compare(qmlUser.name, "Test User"); + } + + User { + id: testUser + } + + function test_setAndGet_data() { + return [ + { tag: "userId", property: "userId", signal: "userIdChanged", value: "testuser", reset: "" }, + { tag: "name", property: "name", signal: "nameChanged", value: "Test User", reset: "" }, + ]; + } + + function test_setAndGet(data) { + Utils.testObjectProperties(testCase, testUser, data); + } +} diff --git a/tests/auto/declarative_location_core/utils.js b/tests/auto/declarative_location_core/utils.js new file mode 100644 index 00000000..2b7dca32 --- /dev/null +++ b/tests/auto/declarative_location_core/utils.js @@ -0,0 +1,182 @@ +.pragma library + +function compareArray(a, b) { + if (a.length !== b.length) + return false; + + for (var i = 0; i < a.length; ++i) { + var aMatched = false; + var bMatched = false; + + for (var j = 0; j < b.length; ++j) { + if (a[i] === b[j]) + aMatched = true; + if (b[i] === a[j]) + bMatched = true; + if (aMatched && bMatched) + break; + } + + if (!aMatched || !bMatched) + return false; + } + + return true; +} + +function testObjectProperties(testCase, testObject, data) { + var signalSpy = Qt.createQmlObject('import QtTest 1.0; SignalSpy {}', testCase, "SignalSpy"); + signalSpy.target = testObject; + signalSpy.signalName = data.signal; + + // set property to something new + testObject[data.property] = data.value; + if (data.array) { + if (data.expectedValue) { + testCase.verify(compareArray(testObject[data.property], data.expectedValue)); + testCase.compare(signalSpy.count, 1 + data.expectedValue.length); + } else { + testCase.verify(compareArray(testObject[data.property], data.value)); + testCase.compare(signalSpy.count, 1 + data.value.length); + } + + } else { + testCase.compare(testObject[data.property], data.value); + testCase.compare(signalSpy.count, 1); + } + + signalSpy.clear(); + + // set property to same value + testObject[data.property] = data.value; + if (data.array) { + if (data.expectedValue) { + testCase.verify(compareArray(testObject[data.property], data.expectedValue)); + testCase.compare(signalSpy.count, 1 + data.expectedValue.length); + } else { + testCase.verify(compareArray(testObject[data.property], data.value)); + testCase.compare(signalSpy.count, 1 + data.value.length); + } + + } else { + testCase.compare(testObject[data.property], data.value); + testCase.compare(signalSpy.count, 0); + } + + signalSpy.clear(); + + // reset property + if (data.reset === undefined) { + testObject[data.property] = null; + testCase.compare(testObject[data.property], null); + } else { + testObject[data.property] = data.reset; + if (data.array) + testCase.verify(compareArray(testObject[data.property], data.reset)); + else + testCase.compare(testObject[data.property], data.reset); + } + testCase.compare(signalSpy.count, 1); + signalSpy.destroy(); +} + +function compareObj(testCase, obj1, obj2) { + for (var propertyName in obj2) { + if (obj1[propertyName] !== undefined) { + if (propertyName === "dateTime" && isNaN(obj2["dateTime"].getTime())) + testCase.verify(isNaN(obj1["dateTime"].getTime())); + else + testCase.compare(obj1[propertyName], obj2[propertyName]) + } + } +} + +function testConsecutiveFetch(testCase, model, place, expectedValues, data) +{ + 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; import QtQml.Models 2.14; ' + + 'DelegateModel{ 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.batchSize = data.batchSize + model.place = place; + testCase.tryCompare(signalSpy, "count", 1); + signalSpy.clear(); + + var totalCount = model.totalCount; + testCase.compare(totalCount, 5); + testCase.compare(visDataModel.items.count, Math.min(data.batchSize, totalCount)); + + compareObj(testCase, visDataModel.items.get(0).model, expectedValues[0]); + + //fetch remaining items, in batchSize batches + while (visDataModel.items.count < totalCount) { + var startIndex = visDataModel.items.count + + //'creating' the last item will trigger a fetch + visDataModel.items.create(visDataModel.items.count - 1); + + testCase.tryCompare(visDataModel.items, "count", Math.min(totalCount, startIndex + data.batchSize)); + testCase.compare(signalSpy.count, 0); + testCase.compare(model.totalCount, totalCount); + + for (var i = startIndex; i < Math.min(totalCount, startIndex + data.batchSize); ++i) + compareObj(testCase, visDataModel.items.get(i).model, expectedValues[i]); + } + + visDataModel.destroy(); + signalSpy.destroy(); +} + +function testReset(testCase, model, place) +{ + var dataModel = Qt.createQmlObject('import QtQuick 2.0; import QtQml.Models 2.14; ' + + 'DelegateModel{ 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.tryCompare(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; import QtQml.Models 2.14; ' + + 'DelegateModel{ 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.tryCompare(signalSpy, "count", 1); + signalSpy.clear(); + testCase.compare(model.totalCount, data.expectedTotalCount); + testCase.compare(visDataModel.items.count, data.expectedCount); + + visDataModel.destroy(); + signalSpy.destroy(); +} diff --git a/tests/auto/declarative_mappolyline/declarative_mappolyline.pro b/tests/auto/declarative_mappolyline/declarative_mappolyline.pro new file mode 100644 index 00000000..342fcc42 --- /dev/null +++ b/tests/auto/declarative_mappolyline/declarative_mappolyline.pro @@ -0,0 +1,11 @@ +# QML tests in this directory must not depend on an OpenGL context. + +TEMPLATE = app +TARGET = tst_declarative_mappolyline +CONFIG += qmltestcase +SOURCES += main.cpp + +QT += positioning quick + +OTHER_FILES = *.qml +TESTDATA = $$OTHER_FILES diff --git a/tests/auto/declarative_mappolyline/main.cpp b/tests/auto/declarative_mappolyline/main.cpp new file mode 100644 index 00000000..dc8caaaf --- /dev/null +++ b/tests/auto/declarative_mappolyline/main.cpp @@ -0,0 +1,30 @@ +/**************************************************************************** +** +** Copyright (C) 2021 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +QUICK_TEST_MAIN(declarative_mappolyline) diff --git a/tests/auto/declarative_mappolyline/tst_declarative_mappolyline.qml b/tests/auto/declarative_mappolyline/tst_declarative_mappolyline.qml new file mode 100644 index 00000000..b7ce0c4a --- /dev/null +++ b/tests/auto/declarative_mappolyline/tst_declarative_mappolyline.qml @@ -0,0 +1,123 @@ +/**************************************************************************** +** +** Copyright (C) 2021 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtTest 1.0 +import QtPositioning 5.2 +import QtLocation 5.5 + +Item { + id: testCase + + MapPolyline { + id: mapPolyline + path: [ + { latitude: -27, longitude: 153.0 }, + { latitude: -27, longitude: 154.1 }, + { latitude: -28, longitude: 153.5 }, + { latitude: -29, longitude: 153.5 } + ] + } + + MapPolyline { + id: mapPolylineGeopath + } + + TestCase { + name: "MapPolyline path" + function test_path_operations() { + compare(mapPolyline.path[1].latitude, -27) + compare(mapPolyline.path[1].longitude, 154.1) + compare(mapPolyline.coordinateAt(1), QtPositioning.coordinate(-27, 154.1)) + compare(mapPolyline.path.length, mapPolyline.pathLength()) + + mapPolyline.removeCoordinate(1); + compare(mapPolyline.path[1].latitude, -28) + compare(mapPolyline.path[1].longitude, 153.5) + compare(mapPolyline.coordinateAt(1), QtPositioning.coordinate(-28, 153.5)) + compare(mapPolyline.path.length, mapPolyline.pathLength()) + + mapPolyline.addCoordinate(QtPositioning.coordinate(30, 153.1)) + compare(mapPolyline.path[mapPolyline.path.length-1].latitude, 30) + compare(mapPolyline.path[mapPolyline.path.length-1].longitude, 153.1) + compare(mapPolyline.containsCoordinate(QtPositioning.coordinate(30, 153.1)), true) + compare(mapPolyline.path.length, mapPolyline.pathLength()) + + mapPolyline.removeCoordinate(QtPositioning.coordinate(30, 153.1)) + compare(mapPolyline.path[mapPolyline.path.length-1].latitude, -29) + compare(mapPolyline.path[mapPolyline.path.length-1].longitude, 153.5) + compare(mapPolyline.containsCoordinate(QtPositioning.coordinate(30, 153.1)), false) + compare(mapPolyline.path.length, mapPolyline.pathLength()) + + mapPolyline.insertCoordinate(2, QtPositioning.coordinate(35, 153.1)) + compare(mapPolyline.path[2].latitude, 35) + compare(mapPolyline.path[2].longitude, 153.1) + compare(mapPolyline.containsCoordinate(QtPositioning.coordinate(35, 153.1)), true) + compare(mapPolyline.path.length, mapPolyline.pathLength()) + + mapPolyline.replaceCoordinate(2, QtPositioning.coordinate(45, 150.1)) + compare(mapPolyline.path[2].latitude, 45) + compare(mapPolyline.path[2].longitude, 150.1) + compare(mapPolyline.containsCoordinate(QtPositioning.coordinate(35, 153.1)), false) + compare(mapPolyline.containsCoordinate(QtPositioning.coordinate(45, 150.1)), true) + compare(mapPolyline.path.length, mapPolyline.pathLength()) + + mapPolyline.insertCoordinate(2, QtPositioning.coordinate(35, 153.1)) + compare(mapPolyline.coordinateAt(2).latitude, 35) + compare(mapPolyline.coordinateAt(2).longitude, 153.1) + compare(mapPolyline.containsCoordinate(QtPositioning.coordinate(35, 153.1)), true) + compare(mapPolyline.path.length, mapPolyline.pathLength()) + } + } + + TestCase { + name: "GeoPath path MapPolyLine" + function test_qgeopath_path_operations() { + var geopath = QtPositioning.path() + + geopath.path = mapPolyline.path + compare(geopath.path.length, mapPolyline.pathLength()) + compare(geopath.boundingGeoRectangle(), mapPolyline.geoShape.boundingGeoRectangle()) + + mapPolylineGeopath.geoShape = geopath + compare(mapPolylineGeopath.pathLength(), mapPolyline.pathLength()) + compare(mapPolylineGeopath.geoShape.boundingGeoRectangle(), mapPolyline.geoShape.boundingGeoRectangle()) + } + } + + TestCase { + name: "GeoPolygon path MapPolyLine" + function test_qgeopolygon_path_operations() { + var geopolygon = QtPositioning.polygon() + + geopolygon.perimeter = mapPolyline.path + compare(geopolygon.perimeter.length, mapPolyline.pathLength()) + compare(geopolygon.boundingGeoRectangle(), mapPolyline.geoShape.boundingGeoRectangle()) + } + } +} diff --git a/tests/auto/declarative_positioning_core/BLACKLIST b/tests/auto/declarative_positioning_core/BLACKLIST new file mode 100644 index 00000000..99b4d786 --- /dev/null +++ b/tests/auto/declarative_positioning_core/BLACKLIST @@ -0,0 +1,6 @@ +# QTBUG-59074 flaky test +[CoordinateAnimation::test_west_direction_coordinate_animation] +osx +# QTBUG-59074 flaky test +[CoordinateAnimation::test_east_direction_coordinate_animation] +osx diff --git a/tests/auto/declarative_positioning_core/CMakeLists.txt b/tests/auto/declarative_positioning_core/CMakeLists.txt new file mode 100644 index 00000000..673d2856 --- /dev/null +++ b/tests/auto/declarative_positioning_core/CMakeLists.txt @@ -0,0 +1,40 @@ +# Generated from declarative_positioning_core.pro. + +##################################################################### +## tst_declarative_positioning_core Test: +##################################################################### + +# Collect test data +file(GLOB_RECURSE test_data_glob + RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} + *.qml) +list(APPEND test_data ${test_data_glob}) + +qt_internal_add_test(tst_declarative_positioning_core + QMLTEST + SOURCES + main.cpp + factory.cpp + factory.h + PUBLIC_LIBRARIES + Qt::Positioning + Qt::Quick + TESTDATA ${test_data} +) + +# special case begin + +# These properties are required for the qt6_qml_type_registration() +# to work properly +set_target_properties(tst_declarative_positioning_core + PROPERTIES + QT_QML_MODULE_URI TestFactory + QT_QML_MODULE_VERSION 1.0 +) + +qt6_qml_type_registration(tst_declarative_positioning_core) + +# special case end + +#### Keys ignored in scope 1:.:.:declarative_positioning_core.pro:: +# TEMPLATE = "app" diff --git a/tests/auto/declarative_positioning_core/declarative_positioning_core.pro b/tests/auto/declarative_positioning_core/declarative_positioning_core.pro new file mode 100644 index 00000000..fbf82de0 --- /dev/null +++ b/tests/auto/declarative_positioning_core/declarative_positioning_core.pro @@ -0,0 +1,14 @@ +# QML tests in this directory must not depend on an OpenGL context. +# QML tests that do require an OpenGL context must go in ../../declarative_ui. + +TEMPLATE = app +TARGET = tst_declarative_positioning_core +CONFIG += qmltestcase +SOURCES += main.cpp + +CONFIG -= app_bundle + +QT += positioning quick + +OTHER_FILES = *.qml +TESTDATA = $$OTHER_FILES diff --git a/tests/auto/declarative_positioning_core/factory.cpp b/tests/auto/declarative_positioning_core/factory.cpp new file mode 100644 index 00000000..92a242c3 --- /dev/null +++ b/tests/auto/declarative_positioning_core/factory.cpp @@ -0,0 +1,50 @@ +/**************************************************************************** +** +** Copyright (C) 2021 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "factory.h" +#include +#include + +QT_BEGIN_NAMESPACE + +Factory::Factory(QObject *parent) : QObject(parent) +{ + +} + +QGeoShape Factory::createShape(const QGeoCoordinate &topLeft, const QGeoCoordinate &bottomRight) +{ + return QGeoRectangle(topLeft, bottomRight); +} + +QGeoShape Factory::createShape(const QGeoCoordinate ¢er, qreal radius) const +{ + return QGeoCircle(center, radius); +} + +QT_END_NAMESPACE diff --git a/tests/auto/declarative_positioning_core/factory.h b/tests/auto/declarative_positioning_core/factory.h new file mode 100644 index 00000000..9fcfef53 --- /dev/null +++ b/tests/auto/declarative_positioning_core/factory.h @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2021 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef FACTORY_H +#define FACTORY_H + +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class QGeoShape; +class QGeoCoordinate; + +class Factory : public QObject +{ + Q_OBJECT + QML_ELEMENT + +public: + explicit Factory(QObject *parent = nullptr); + + Q_INVOKABLE QGeoShape createShape(const QGeoCoordinate &topLeft, const QGeoCoordinate &bottomRight); + Q_INVOKABLE QGeoShape createShape(const QGeoCoordinate ¢er, qreal radius) const; +}; + +QT_END_NAMESPACE + +#endif // FACTORY_H diff --git a/tests/auto/declarative_positioning_core/main.cpp b/tests/auto/declarative_positioning_core/main.cpp new file mode 100644 index 00000000..d7cfb648 --- /dev/null +++ b/tests/auto/declarative_positioning_core/main.cpp @@ -0,0 +1,49 @@ +/**************************************************************************** +** +** Copyright (C) 2021 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include + +static void initializeLibraryPath() +{ +#if QT_CONFIG(library) + // Set custom path since CI doesn't install test plugins +#ifdef Q_OS_WIN + QCoreApplication::addLibraryPath(QCoreApplication::applicationDirPath() + + QStringLiteral("/../../../../plugins")); +#else + QCoreApplication::addLibraryPath(QCoreApplication::applicationDirPath() + + QStringLiteral("/../../../plugins")); +#endif +#endif +} + +Q_COREAPP_STARTUP_FUNCTION(initializeLibraryPath) + +QUICK_TEST_MAIN(declarative_positioning_core) diff --git a/tests/auto/declarative_positioning_core/tst_address.qml b/tests/auto/declarative_positioning_core/tst_address.qml new file mode 100644 index 00000000..94f986c4 --- /dev/null +++ b/tests/auto/declarative_positioning_core/tst_address.qml @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtTest 1.0 +import QtPositioning 5.2 + +TestCase { + id: testCase + + name: "Address" + + Address { + id: address + + street: "742 Evergreen Tce" + district: "Pressboard Estates" + city: "Springfield" + state: "Oregon" + postalCode: "8900" + country: "United States" + countryCode: "USA" + } + + function test_qmlAddressText() { + compare(address.isTextGenerated, true); + compare(address.text, "742 Evergreen Tce
Springfield, Oregon 8900
United States"); + var textChangedSpy = Qt.createQmlObject('import QtTest 1.0; SignalSpy {}', testCase, "SignalSpy"); + textChangedSpy.target = address; + textChangedSpy.signalName = "textChanged" + + var isTextGeneratedSpy = Qt.createQmlObject('import QtTest 1.0; SignalSpy {}', testCase, "SignalSpy"); + isTextGeneratedSpy.target = address + isTextGeneratedSpy.signalName = "isTextGeneratedChanged" + + address.countryCode = "FRA"; + compare(address.text, "742 Evergreen Tce
8900 Springfield
United States"); + compare(textChangedSpy.count, 1); + textChangedSpy.clear(); + compare(isTextGeneratedSpy.count, 0); + + address.text = "address label"; + compare(address.isTextGenerated, false); + compare(address.text, "address label"); + compare(textChangedSpy.count, 1); + textChangedSpy.clear(); + compare(isTextGeneratedSpy.count, 1); + isTextGeneratedSpy.clear(); + + address.countryCode = "USA"; + compare(address.text, "address label"); + compare(textChangedSpy.count, 0); + textChangedSpy.clear(); + compare(isTextGeneratedSpy.count, 0); + + address.text = ""; + compare(address.isTextGenerated, true); + compare(address.text, "742 Evergreen Tce
Springfield, Oregon 8900
United States"); + compare(textChangedSpy.count, 1); + textChangedSpy.clear(); + compare(isTextGeneratedSpy.count, 1); + isTextGeneratedSpy.clear(); + } +} diff --git a/tests/auto/declarative_positioning_core/tst_coordinate.qml b/tests/auto/declarative_positioning_core/tst_coordinate.qml new file mode 100644 index 00000000..00c8570b --- /dev/null +++ b/tests/auto/declarative_positioning_core/tst_coordinate.qml @@ -0,0 +1,365 @@ +/**************************************************************************** +** +** Copyright (C) 2021 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtTest 1.0 +import QtPositioning 5.5 + +Item { + id: item + + property var empty: QtPositioning.coordinate() + property var base: QtPositioning.coordinate(1.0, 1.0, 5.0) + property var zero: QtPositioning.coordinate(0, 0) + property var plusone: QtPositioning.coordinate(0, 1) + property var minusone: QtPositioning.coordinate(0, -1) + property var north: QtPositioning.coordinate(3, 0) + + SignalSpy { id: coordSpy; target: item; signalName: "baseChanged" } + + property var inside: QtPositioning.coordinate(0.5, 0.5) + property var outside: QtPositioning.coordinate(2, 2) + property var tl: QtPositioning.coordinate(1, 0) + property var br: QtPositioning.coordinate(0, 1) + property var box: QtPositioning.rectangle(tl, br) + + + Address { + id: validTestAddress + street: "53 Brandl St" + city: "Eight Mile Plains" + country: "Australia" + countryCode: "AUS" + } + + Location { + id: testLocation + coordinate: inside + boundingBox: box + address: validTestAddress + } + + Location { + id: invalidLocation + } + + + Item { + id: coordinateItem + property variant coordinate + property int animationDuration: 100 + property var coordinateList: [] + property int coordinateCount: 0 + + CoordinateAnimation { + id: coordinateAnimation + target: coordinateItem + property: "coordinate" + duration: coordinateItem.animationDuration + } + onCoordinateChanged: { + if (!coordinateList) { + coordinateList = [] + } + coordinateList[coordinateCount] = QtPositioning.coordinate(coordinate.latitude,coordinate.longitude) + coordinateCount++ + } + + SignalSpy { id: coordinateAnimationStartSpy; target: coordinateAnimation; signalName: "started" } + SignalSpy { id: coordinateAnimationStopSpy; target: coordinateAnimation; signalName: "stopped" } + SignalSpy { id: coordinateAnimationDirectionSpy; target: coordinateAnimation; signalName: "directionChanged" } + } + + TestCase { + name: "GeoLocation" + + function test_Location_complete() + { + compare (testLocation.coordinate.longitude, inside.longitude) + compare (testLocation.coordinate.latitude, inside.latitude) + + compare (testLocation.boundingBox.contains(inside), true) + compare (testLocation.boundingBox.contains(outside), false) + compare (testLocation.boundingBox.bottomRight.longitude, br.longitude) + compare (testLocation.boundingBox.bottomRight.latitude, br.latitude) + compare (testLocation.boundingBox.topLeft.longitude, tl.longitude) + compare (testLocation.boundingBox.topLeft.latitude, tl.latitude) + + compare (testLocation.address.country, "Australia") + compare (testLocation.address.countryCode, "AUS") + compare (testLocation.address.city, "Eight Mile Plains") + compare (testLocation.address.street, "53 Brandl St") + } + + function test_Location_invalid() + { + compare(invalidLocation.coordinate.isValid, false) + compare(invalidLocation.boundingBox.isEmpty, true) + compare(invalidLocation.boundingBox.isValid, false) + compare(invalidLocation.address.city, "") + } + } + + TestCase { + name: "Coordinate" + + function test_validity() + { + compare(empty.isValid, false) + + empty.longitude = 0.0; + empty.latitude = 0.0; + + compare(empty.isValid, true) + } + + function test_accessors() + { + compare(base.longitude, 1.0) + compare(base.latitude, 1.0) + compare(base.altitude, 5.0) + + coordSpy.clear() + + base.longitude = 2.0 + base.latitude = 3.0 + base.altitude = 6.0 + + compare(base.longitude, 2.0) + compare(base.latitude, 3.0) + compare(base.altitude, 6.0) + // changing individual properties does *not* trigger + // change notification + compare(coordSpy.count, 0) + + // updating the whole object *does* trigger change notification + base = QtPositioning.coordinate(3.0, 4.0, 5.0) + compare(base.latitude, 3.0) + compare(base.longitude, 4.0) + compare(base.altitude, 5.0) + compare(coordSpy.count, 1) + } + + function test_comparison_data() + { + return [ + { tag: "empty", coord1: empty, coord2: QtPositioning.coordinate(), result: true }, + { tag: "zero", coord1: zero, coord2: QtPositioning.coordinate(0, 0), result: true }, + { tag: "plusone", coord1: plusone, coord2: QtPositioning.coordinate(0, 1), result: true }, + { tag: "minusone", coord1: minusone, coord2: QtPositioning.coordinate(0, -1), result: true }, + { tag: "north", coord1: north, coord2: QtPositioning.coordinate(3, 0), result: true }, + { tag: "lat,long.alt", coord1: QtPositioning.coordinate(1.1, 2.2, 3.3), coord2: QtPositioning.coordinate(1.1, 2.2, 3.3), result: true }, + { tag: "not equal1", coord1: plusone, coord2: minusone, result: false }, + { tag: "not equal2", coord1: plusone, coord2: north, result: false } + ] + } + + function test_comparison(data) + { + compare(data.coord1 === data.coord2, data.result) + compare(data.coord1 !== data.coord2, !data.result) + compare(data.coord1 == data.coord2, data.result) + compare(data.coord1 != data.coord2, !data.result) + } + + function test_distance() + { + compare(zero.distanceTo(plusone), zero.distanceTo(minusone)) + compare(2*plusone.distanceTo(zero), plusone.distanceTo(minusone)) + compare(zero.distanceTo(plusone) > 0, true) + } + + function test_azimuth() + { + compare(zero.azimuthTo(north), 0) + compare(zero.azimuthTo(plusone), 90) + compare(zero.azimuthTo(minusone), 270) + compare(minusone.azimuthTo(plusone), 360 - plusone.azimuthTo(minusone)) + } + + function test_atDistanceAndAzimuth() + { + // 112km is approximately one degree of arc + + var coord_0d = zero.atDistanceAndAzimuth(112000, 0) + compare(coord_0d.latitude > 0.95, true) + compare(coord_0d.latitude < 1.05, true) + compare(coord_0d.longitude < 0.05, true) + compare(coord_0d.longitude > -0.05, true) + compare(zero.distanceTo(coord_0d), 112000) + compare(zero.azimuthTo(coord_0d), 0) + + var coord_90d = zero.atDistanceAndAzimuth(112000, 90) + compare(coord_90d.longitude > 0.95, true) + compare(coord_90d.longitude < 1.05, true) + compare(coord_90d.latitude < 0.05, true) + compare(coord_90d.latitude > -0.05, true) + compare(zero.distanceTo(coord_90d), 112000) + compare(zero.azimuthTo(coord_90d), 90) + + var coord_30d = zero.atDistanceAndAzimuth(20000, 30) + compare(coord_30d.longitude > 0, true) + compare(coord_30d.latitude > 0, true) + compare(zero.distanceTo(coord_30d), 20000) + compare(zero.azimuthTo(coord_30d), 30) + + var coord_30d2 = coord_30d.atDistanceAndAzimuth(200, 30) + compare(zero.distanceTo(coord_30d2), 20200) + } + } + + TestCase { + name: "CoordinateAnimation" + + function init() + { + coordinateAnimation.stop() + coordinateAnimationStartSpy.clear() + coordinateAnimationStopSpy.clear() + coordinateAnimationDirectionSpy.clear() + coordinateAnimation.from = QtPositioning.coordinate(50,50) + coordinateAnimation.to = QtPositioning.coordinate(50,50) + coordinateAnimation.direction = CoordinateAnimation.Shortest + coordinateItem.coordinate = QtPositioning.coordinate(50,50) + coordinateItem.coordinateList = [] + coordinateItem.coordinateCount = 0 + } + + function initTestCase() + { + compare(coordinateAnimation.direction, CoordinateAnimation.Shortest) + compare(coordinateAnimationDirectionSpy.count,0) + coordinateAnimation.direction = CoordinateAnimation.Shortest + compare(coordinateAnimationDirectionSpy.count,0) + coordinateAnimation.direction = CoordinateAnimation.West + compare(coordinateAnimationDirectionSpy.count,1) + coordinateAnimation.direction = CoordinateAnimation.East + compare(coordinateAnimationDirectionSpy.count,2) + } + + function toMercator(coord) + { + var p = QtPositioning.coordToMercator(coord) + var lat = p.y + var lon = p.x + return {'latitude': lat, 'longitude': lon}; + } + + function coordinate_animation(from, to, movingEast) + { + var fromMerc = toMercator(from) + var toMerc = toMercator(to) + var delta = (toMerc.latitude - fromMerc.latitude) / (toMerc.longitude - fromMerc.longitude) + + compare(coordinateItem.coordinateList.length, 0); + coordinateAnimation.from = from + coordinateAnimation.to = to + coordinateAnimation.start() + tryCompare(coordinateAnimationStartSpy,"count",1) + tryCompare(coordinateAnimationStopSpy,"count",1) + + //check correct start position + verify(coordinateItem.coordinateList.length != 0) + compare(coordinateItem.coordinateList[0], from) + //check correct end position + compare(coordinateItem.coordinateList[coordinateItem.coordinateList.length - 1],to) + + var i + var lastLongitude + for (i in coordinateItem.coordinateList) { + var coordinate = coordinateItem.coordinateList[i] + var mercCoordinate = toMercator(coordinate) + + //check that coordinates from the animation is along a straight line between from and to + var estimatedLatitude = fromMerc.latitude + (mercCoordinate.longitude - fromMerc.longitude) * delta + verify(mercCoordinate.latitude - estimatedLatitude < 0.00000000001); + + //check that each step has moved in the right direction + + if (lastLongitude) { + var errorMessage = "movingEast: " + movingEast + "; From: " + from + "; To: " + to + "; i: " + i + "; crdList: " + coordinateItem.coordinateList + if (movingEast) { + if (coordinate.longitude > 0 && lastLongitude < 0) + verify(coordinate.longitude < lastLongitude + 360, errorMessage) + else + verify(coordinate.longitude < lastLongitude, errorMessage) + } else { + if (coordinate.longitude < 0 && lastLongitude > 0) + verify(coordinate.longitude + 360 > lastLongitude, errorMessage) + else + verify(coordinate.longitude > lastLongitude, errorMessage) + } + } + lastLongitude = coordinate.longitude + } + } + + function test_default_coordinate_animation() + { + //shortest + coordinate_animation(QtPositioning.coordinate(58.0,12.0), + QtPositioning.coordinate(62.0,24.0), + false) + } + + function test_east_direction_coordinate_animation(data) + { + coordinateAnimation.direction = CoordinateAnimation.East + coordinate_animation(data.from, + data.to, + true) + } + + function test_east_direction_coordinate_animation_data() + { + return [ + { from: QtPositioning.coordinate(58.0,24.0), to: QtPositioning.coordinate(58.0,12.0) }, + { from: QtPositioning.coordinate(58.0,12.0), to: QtPositioning.coordinate(58.0,24.0) }, + ] + } + + + function test_west_direction_coordinate_animation(data) + { + coordinateAnimation.direction = CoordinateAnimation.West + coordinate_animation(data.from, + data.to, + false) + } + + function test_west_direction_coordinate_animation_data() + { + return [ + { from: QtPositioning.coordinate(58.0,24.0),to: QtPositioning.coordinate(58.0,12.0) }, + { from: QtPositioning.coordinate(58.0,12.0),to: QtPositioning.coordinate(58.0,24.0) }, + ] + } + + + } +} diff --git a/tests/auto/declarative_positioning_core/tst_geoshape.qml b/tests/auto/declarative_positioning_core/tst_geoshape.qml new file mode 100644 index 00000000..6429fb26 --- /dev/null +++ b/tests/auto/declarative_positioning_core/tst_geoshape.qml @@ -0,0 +1,300 @@ +/**************************************************************************** +** +** Copyright (C) 2021 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtTest 1.0 +import QtPositioning 5.2 +import TestFactory 1.0 + +Item { + id: testCase + + property var coordinate1: QtPositioning.coordinate(1, 1) + property var coordinate2: QtPositioning.coordinate(2, 2) + property var coordinate3: QtPositioning.coordinate(80, 80) + + property var emptyCircle: QtPositioning.circle() + property var circle1: QtPositioning.circle(coordinate1, 200000) + + SignalSpy { id: circleChangedSpy; target: testCase; signalName: "emptyCircleChanged" } + + TestCase { + name: "Bounding circle" + function test_circle_defaults_and_setters() { + circleChangedSpy.clear(); + compare (emptyCircle.radius, -1) + compare (circle1.radius, 200000) + + emptyCircle.radius = 200 + compare(emptyCircle.radius, 200) + + emptyCircle.center = coordinate1 + compare(emptyCircle.center, coordinate1) + + emptyCircle.center = coordinate2 + compare(emptyCircle.center, coordinate2) + + emptyCircle = QtPositioning.circle(coordinate1, 200000) + compare(emptyCircle.center, coordinate1) + compare(emptyCircle.radius, 200000) + // signal is triggered only when we update the whole object + compare(circleChangedSpy.count, 1) + + compare(emptyCircle.contains(coordinate1), true); + compare(emptyCircle.contains(coordinate2), true); + compare(emptyCircle.contains(coordinate3), false); + } + } + + property var trace1 : [ QtPositioning.coordinate(43.773175, 11.255386), + QtPositioning.coordinate(43.773546 , 11.255372) ] + property var trace2 : [ QtPositioning.coordinate(43.773175, 11.255386), + QtPositioning.coordinate(43.773546 , 11.255372), + QtPositioning.coordinate(43.77453 , 11.255734) ] + + + // coordinate unit square + property var bl: QtPositioning.coordinate(0, 0) + property var tl: QtPositioning.coordinate(1, 0) + property var tr: QtPositioning.coordinate(1, 1) + property var br: QtPositioning.coordinate(0, 1) + property var ntr: QtPositioning.coordinate(3, 3) + + property var invalid: QtPositioning.coordinate(100, 190) + property var inside: QtPositioning.coordinate(0.5, 0.5) + property var outside: QtPositioning.coordinate(2, 2) + + property var box: QtPositioning.rectangle(tl, br) + + property var coordinates: [bl, tl, tr, br] + property var coordinates2: [bl, tl, tr, br, ntr] + property var coordinates3: [tr] + property var coordinates4: [invalid] + property var coordinates5: [] + + property var listBox: QtPositioning.rectangle(coordinates) + property var listBox2: QtPositioning.rectangle(coordinates2) + property var listBox3: QtPositioning.rectangle(coordinates3) + property var listBox4: QtPositioning.rectangle(coordinates4) + property var listBox5: QtPositioning.rectangle(coordinates5) + + property var widthBox: QtPositioning.rectangle(inside, 1, 1); + + // C++ auto test exists for basics of bounding box, testing here + // only added functionality + TestCase { + name: "Bounding box" + function test_box_defaults_and_setters() { + compare (box.bottomRight.longitude, br.longitude) // sanity + compare (box.contains(bl), true) + compare (box.contains(inside), true) + compare (box.contains(outside), false) + box.topRight = ntr + compare (box.contains(outside), true) + + compare (listBox.isValid, true) + compare (listBox.contains(outside), false) + compare (listBox2.contains(outside), true) + compare (listBox3.isValid, true) + compare (listBox3.isEmpty, true) + compare (listBox4.isValid, false) + compare (listBox5.isValid, false) + + compare (widthBox.contains(inside), true) + compare (widthBox.contains(outside), false) + } + } + + TestCase { + name: "Shape" + + function test_shape_comparison_data() { + return [ + { tag: "invalid shape", shape1: QtPositioning.shape(), shape2: QtPositioning.shape(), result: true }, + { tag: "box equal", shape1: box, shape2: QtPositioning.rectangle(tl, br), result: true }, + { tag: "box not equal", shape1: box, shape2: QtPositioning.rectangle([inside, outside]), result: false }, + { tag: "box invalid shape", rect1: box, shape2: QtPositioning.shape(), result: false }, + { tag: "invalid rectangle", shape1: QtPositioning.rectangle(), shape2: QtPositioning.rectangle(), result: true }, + { tag: "invalid rectangle2", shape1: QtPositioning.rectangle(), shape2: QtPositioning.shape(), result: false }, + { tag: "circle1 equal", shape1: circle1, shape2: QtPositioning.circle(coordinate1, 200000), result: true }, + { tag: "circle1 not equal", shape1: circle1, shape2: QtPositioning.circle(coordinate2, 2000), result: false }, + { tag: "circle1 invalid shape", shape1: circle1, shape2: QtPositioning.shape(), result: false }, + { tag: "invalid circle", shape1: QtPositioning.circle(), shape2: QtPositioning.circle(), result: true }, + { tag: "invalid circle2", shape1: QtPositioning.circle(), shape2: QtPositioning.shape(), result: false } + ] + } + + function test_shape_comparison(data) { + compare(data.shape1 === data.shape2, data.result) + compare(data.shape1 !== data.shape2, !data.result) + compare(data.shape1 == data.shape2, data.result) + compare(data.shape1 != data.shape2, !data.result) + } + } + + TestCase { + name: "Conversions" + + function test_shape_circle_conversions() { + var circle = QtPositioning.shapeToCircle(QtPositioning.shape()) + verify(!circle.isValid) + circle = QtPositioning.shapeToCircle(QtPositioning.circle()) + verify(!circle.isValid) + circle = QtPositioning.shapeToCircle(QtPositioning.circle(tl, 10000)) + verify(circle.isValid) + compare(circle.center, tl) + compare(circle.radius, 10000) + circle = QtPositioning.shapeToCircle(QtPositioning.rectangle()) + verify(!circle.isValid) + circle = QtPositioning.shapeToCircle(QtPositioning.rectangle(tl, br)) + verify(!circle.isValid) + circle = QtPositioning.shapeToCircle(listBox) + verify(!circle.isValid) + } + + function test_shape_rectangle_conversions() { + var rectangle = QtPositioning.shapeToRectangle(QtPositioning.shape()) + verify(!rectangle.isValid) + rectangle = QtPositioning.shapeToRectangle(QtPositioning.circle()) + verify(!rectangle.isValid) + rectangle = QtPositioning.shapeToRectangle(QtPositioning.circle(tl, 10000)) + verify(!rectangle.isValid) + rectangle = QtPositioning.shapeToRectangle(QtPositioning.rectangle()) + verify(!rectangle.isValid) + rectangle = QtPositioning.shapeToRectangle(QtPositioning.rectangle(tl, br)) + verify(rectangle.isValid) + compare(rectangle.topLeft, tl) + compare(rectangle.bottomRight, br) + rectangle = QtPositioning.shapeToRectangle(listBox) + verify(rectangle.isValid) + } + + function test_shape_path_conversions() { + var path = QtPositioning.shapeToPath(QtPositioning.shape()) + verify(!path.isValid) + path = QtPositioning.shapeToPath(QtPositioning.circle()) + verify(!path.isValid) + path = QtPositioning.shapeToPath(QtPositioning.circle(tl, 10000)) + verify(!path.isValid) + path = QtPositioning.shapeToPath(QtPositioning.rectangle()) + verify(!path.isValid) + path = QtPositioning.shapeToPath(QtPositioning.rectangle(tl, br)) + verify(!path.isValid) + + path = QtPositioning.shapeToPath(QtPositioning.path()) + verify(!path.isValid) + path = QtPositioning.shapeToPath(QtPositioning.path(trace1, 1)) + verify(path.isValid) + path = QtPositioning.shapeToPath(QtPositioning.path(trace2, 2)) + verify(path.isValid) + verify(path !== QtPositioning.shapeToPath(QtPositioning.path(trace1, 1))) + compare(path, QtPositioning.shapeToPath(QtPositioning.path(trace2, 2))) + } + + function test_shape_polygon_conversions() { + var polygon = QtPositioning.shapeToPolygon(QtPositioning.shape()) + verify(!polygon.isValid) + polygon = QtPositioning.shapeToPolygon(QtPositioning.circle()) + verify(!polygon.isValid) + polygon = QtPositioning.shapeToPolygon(QtPositioning.circle(tl, 10000)) + verify(polygon.isValid) // fixed, polygon copy constructor can now initialize from a circle. + polygon = QtPositioning.shapeToPolygon(QtPositioning.rectangle()) + verify(!polygon.isValid) + polygon = QtPositioning.shapeToPolygon(QtPositioning.rectangle(tl, br)) + verify(polygon.isValid) // fixed, polygon copy constructor can now initialize from a rectangle. + + polygon = QtPositioning.shapeToPolygon(QtPositioning.polygon()) + verify(!polygon.isValid) + polygon = QtPositioning.shapeToPolygon(QtPositioning.polygon(trace1)) + verify(!polygon.isValid) // polygon needs 3 coords at least + polygon = QtPositioning.shapeToPolygon(QtPositioning.polygon(trace2)) + verify(polygon.isValid) + verify(polygon !== QtPositioning.shapeToPolygon(QtPositioning.polygon(trace1))) + compare(polygon, QtPositioning.shapeToPolygon(QtPositioning.polygon(trace2))) + } + } + + TestCase { + name: "GeoPath path" + function test_qgeopath_path_operations() { + var geopath = QtPositioning.path() + + geopath.path = trace2 + compare(geopath.path.length, trace2.length) + + geopath.path = trace2 + geopath.path[0].longitude = 11.0 + compare(geopath.path.length, trace2.length) + compare(geopath.coordinateAt(0).latitude, trace2[0].latitude) + expectFail("", "Longitude comparison fails") + compare(geopath.coordinateAt(0).longitude, 11) + } + } + + TestCase { + name: "GeoPolygon path" + function test_qgeopolygon_path_operations() { + var geopolygon = QtPositioning.polygon() + + geopolygon.perimeter = trace2 + compare(geopolygon.perimeter.length, trace2.length) + + geopolygon.perimeter = trace2 + compare(geopolygon.perimeter.length, trace2.length) + compare(geopolygon.coordinateAt(0).latitude, trace2[0].latitude) + compare(geopolygon.coordinateAt(0).longitude, trace2[0].longitude) + } + } + + Factory { + id: factory + } + + TestCase { + name: "GeoShape factory" + function test_geoshape_factory_construction() { + // Both createShape() methods return QGeoShape. We check that + // invokable methods and properties are called for correct + // objects + var c0 = QtPositioning.coordinate(1.0, 1.0) + var c1 = QtPositioning.coordinate(1.0001, 1.0001) + var c2 = QtPositioning.coordinate(0.5, 0.5) + var circle = factory.createShape(c0, 100.0) + verify(circle.contains(c1)) + verify(!circle.contains(c2)) + compare(circle.center, c0) + + var rectangle = factory.createShape(QtPositioning.coordinate(1.0, 0.0), QtPositioning.coordinate(0.0, 1.0)) + verify(rectangle.contains(c2)) + verify(!rectangle.contains(c1)) + compare(rectangle.center, c2) + + verify(rectangle.center !== circle.center) + } + } +} diff --git a/tests/auto/declarative_positioning_core/tst_position.qml b/tests/auto/declarative_positioning_core/tst_position.qml new file mode 100644 index 00000000..1bde0879 --- /dev/null +++ b/tests/auto/declarative_positioning_core/tst_position.qml @@ -0,0 +1,99 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtTest 1.0 +import QtPositioning 5.3 + +TestCase { + id: testCase + + name: "Position" + + Position { id: defaultPosition } + + SignalSpy { id: latitudeValidSpy; target: defaultPosition; signalName: "latitudeValidChanged" } + SignalSpy { id: longitudeValidSpy; target: defaultPosition; signalName: "longitudeValidChanged" } + SignalSpy { id: altitudeValidSpy; target: defaultPosition; signalName: "altitudeValidChanged" } + SignalSpy { id: timestampSpy; target: defaultPosition; signalName: "timestampChanged" } + SignalSpy { id: speedSpy; target: defaultPosition; signalName: "speedChanged" } + SignalSpy { id: speedValidSpy; target: defaultPosition; signalName: "speedValidChanged" } + SignalSpy { id: coordinateSpy; target: defaultPosition; signalName: "coordinateChanged" } + SignalSpy { id: horizontalAccuracySpy; target: defaultPosition; signalName: "horizontalAccuracyChanged" } + SignalSpy { id: horizontalAccuracyValidSpy; target: defaultPosition; signalName: "horizontalAccuracyValidChanged" } + SignalSpy { id: verticalAccuracySpy; target: defaultPosition; signalName: "verticalAccuracyChanged" } + SignalSpy { id: verticalAccuracyValidSpy; target: defaultPosition; signalName: "verticalAccuracyValidChanged" } + SignalSpy { id: directionSpy; target: defaultPosition; signalName: "directionChanged" } + SignalSpy { id: verticalSpeedSpy; target: defaultPosition; signalName: "verticalSpeedChanged" } + + function test_defaults() { + compare(defaultPosition.latitudeValid, false); + compare(defaultPosition.longitudeValid, false); + compare(defaultPosition.altitudeValid, false); + compare(defaultPosition.speedValid, false); + compare(defaultPosition.horizontalAccuracyValid, false); + compare(defaultPosition.verticalAccuracyValid, false); + verify(!defaultPosition.directionValid); + verify(isNaN(defaultPosition.direction)); + verify(!defaultPosition.verticalSpeedValid); + verify(isNaN(defaultPosition.verticalSpeed)); + } + + function test_modifiers() { + latitudeValidSpy.clear(); + longitudeValidSpy.clear(); + altitudeValidSpy.clear(); + timestampSpy.clear(); + speedSpy.clear(); + speedValidSpy.clear(); + coordinateSpy.clear(); + horizontalAccuracySpy.clear(); + horizontalAccuracyValidSpy.clear(); + verticalAccuracySpy.clear(); + verticalAccuracyValidSpy.clear(); + directionSpy.clear(); + verticalSpeedSpy.clear(); + + defaultPosition.horizontalAccuracy = 10; + compare(horizontalAccuracySpy.count, 1); + compare(horizontalAccuracyValidSpy.count, 1); + compare(defaultPosition.horizontalAccuracy, 10); + compare(defaultPosition.horizontalAccuracyValid, true); + + defaultPosition.verticalAccuracy = 10; + compare(verticalAccuracySpy.count, 1); + compare(verticalAccuracyValidSpy.count, 1); + compare(defaultPosition.verticalAccuracy, 10); + compare(defaultPosition.verticalAccuracyValid, true); + + // some extra precautions + compare(horizontalAccuracyValidSpy.count, 1); + compare(speedSpy.count, 0); + compare(speedValidSpy.count, 0); + } +} diff --git a/tests/auto/declarative_positioning_core/tst_positionsource.qml b/tests/auto/declarative_positioning_core/tst_positionsource.qml new file mode 100644 index 00000000..7b787a0c --- /dev/null +++ b/tests/auto/declarative_positioning_core/tst_positionsource.qml @@ -0,0 +1,227 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtTest 1.0 +import QtPositioning 5.14 + +TestCase { + id: testCase + + name: "PositionSource" + + PositionSource { id: defaultSource } + PositionSource + { + id: activeDefaultSource + active: true + } + + SignalSpy { id: defaultSourceSpy; target: defaultSource; signalName: "positionChanged" } + + function test_activeDefaultSource() { + wait(0); + verify(activeDefaultSource.name !== ""); + compare(activeDefaultSource.active, true); + } + + function test_invalidSource() { + activeDefaultSource.name = "invalid_positioning_source"; + verify(!activeDefaultSource.active); + verify(!activeDefaultSource.valid); + } + + function test_defaults() { + // at least the test.source plugin should be available + verify(defaultSource.name != ""); + compare(defaultSource.active, false); + } + + function test_inactive() { + defaultSourceSpy.clear(); + compare(defaultSourceSpy.count, 0); + wait(1000); + compare(defaultSourceSpy.count, 0); + } + + PositionSource { id: testSetSource; name: "nonexistent bogus plugin" } + SignalSpy { id: testingSourcePluginSpy; target: testSetSource; signalName: "nameChanged" } + + function test_setplugin() { + testingSourcePluginSpy.clear(); + + // On construction, if the provided source name is invalid, the default source will be + // used. Test that the source is valid as expected. + verify(testSetSource.name !== ""); + //we don't really know what the default source is named. + //It may not be "test.source" + var defaultSourceName = testSetSource.name; + verify(testSetSource.valid); + + // Test that setting name to "" will still use the default. + testSetSource.name = ""; + compare(testingSourcePluginSpy.count, 0); + compare(testSetSource.name, defaultSourceName); + verify(testSetSource.valid); + + testSetSource.name = "test.source"; + if (defaultSourceName === "test.source") + compare(testingSourcePluginSpy.count, 0); + compare(testSetSource.name, "test.source"); + verify(testSetSource.valid); + testingSourcePluginSpy.clear(); + + testSetSource.name = "bogus"; + compare(testingSourcePluginSpy.count, 1); + verify(!testSetSource.valid); + } + + PositionSource { id: testingSource; name: "test.source"; updateInterval: 1000 } + SignalSpy { id: updateSpy; target: testingSource; signalName: "positionChanged" } + SignalSpy { id: directionValidSpy; target: testingSource.position; signalName: "directionValidChanged" } + SignalSpy { id: directionSpy; target: testingSource.position; signalName: "directionChanged" } + + PositionSource { + id: testingSourceWParams + name: "test.source" + updateInterval: 1000 + PluginParameter { + id: altitudeParameter + name: "test.source.altitude" + value: 42.42 + } + } + + SignalSpy { id: updateSpyWParams; target: testingSourceWParams; signalName: "positionChanged" } + SignalSpy { id: directionValidSpyWParams; target: testingSourceWParams.position; signalName: "directionValidChanged" } + SignalSpy { id: directionSpyWParams; target: testingSourceWParams.position; signalName: "directionChanged" } + + PositionSource { id: testingSourceV1; name: "test.source.v1"; updateInterval: 1000 } + SignalSpy { id: updateSpyV1; target: testingSourceV1; signalName: "positionChanged" } + SignalSpy { id: directionValidSpyV1; target: testingSourceV1.position; signalName: "directionValidChanged" } + SignalSpy { id: directionSpyV1; target: testingSourceV1.position; signalName: "directionChanged" } + + function test_updateInterval() { + testingSource.updateInterval = 1000; + compare(testingSource.updateInterval, 1000); + testingSource.updateInterval = 1200; + compare(testingSource.updateInterval, 1200); + testingSource.updateInterval = 800; + compare(testingSource.updateInterval, 1000); + } + + function test_preferredPositioningMethods() { + testingSource.preferredPositioningMethods = PositionSource.AllPositioningMethods; + compare(testingSource.preferredPositioningMethods, PositionSource.AllPositioningMethods); + testingSource.preferredPositioningMethods = PositionSource.SatellitePositioningMethods; + compare(testingSource.preferredPositioningMethods, PositionSource.SatellitePositioningMethods); + testingSource.preferredPositioningMethods = PositionSource.NonSatellitePositioningMethods; + compare(testingSource.preferredPositioningMethods, PositionSource.NonSatellitePositioningMethods); + } + + function test_updates() { + updateSpyV1.clear(); + + compare(directionValidSpyV1.count, 0) + compare(directionSpyV1.count, 0) + + testingSourceV1.active = true; + + tryCompare(updateSpyV1, "count", 1, 1500); + compare(testingSourceV1.position.coordinate.longitude, 0.1); + compare(testingSourceV1.position.coordinate.latitude, 0.1); + compare(directionValidSpyV1.count, 1) + compare(directionSpyV1.count, 1) + fuzzyCompare(testingSourceV1.position.direction, 45, 0.1) + verify(!testingSourceV1.position.speedValid) + verify(isNaN(testingSourceV1.position.speed)) + + tryCompare(updateSpyV1, "count", 2, 1500); + compare(testingSourceV1.position.coordinate.longitude, 0.2); + compare(testingSourceV1.position.coordinate.latitude, 0.2); + compare(directionValidSpyV1.count, 1) + compare(directionSpyV1.count, 2) + fuzzyCompare(testingSourceV1.position.direction, 45, 0.1) + verify(testingSourceV1.position.speedValid) + verify(testingSourceV1.position.speed > 10000) + + testingSourceV1.active = false; + wait(2500); + compare(updateSpyV1.count, 2); + compare(testingSourceV1.position.coordinate.longitude, 0.2); + compare(testingSourceV1.position.coordinate.latitude, 0.2); + compare(directionValidSpyV1.count, 1) + compare(directionSpyV1.count, 2) + fuzzyCompare(testingSourceV1.position.direction, 45, 0.1) + verify(testingSourceV1.position.speedValid) + verify(testingSourceV1.position.speed > 10000) + } + + function test_updates_w_params() { + updateSpyWParams.clear(); + + compare(directionValidSpyWParams.count, 0) + compare(directionSpyWParams.count, 0) + compare(testingSourceWParams.backendProperty("altitude"), altitudeParameter.value) + testingSourceWParams.active = true; + + tryCompare(updateSpyWParams, "count", 1, 1500); + compare(testingSourceWParams.position.coordinate.longitude, 0.1); + compare(testingSourceWParams.position.coordinate.latitude, 0.1); + compare(testingSourceWParams.position.coordinate.altitude, altitudeParameter.value); + compare(directionValidSpyWParams.count, 1) + compare(directionSpyWParams.count, 1) + fuzzyCompare(testingSourceWParams.position.direction, 45, 0.1) + verify(!testingSourceWParams.position.speedValid) + verify(isNaN(testingSourceWParams.position.speed)) + testingSourceWParams.setBackendProperty("altitude", 24.24) + + tryCompare(updateSpyWParams, "count", 2, 1500); + compare(testingSourceWParams.position.coordinate.longitude, 0.2); + compare(testingSourceWParams.position.coordinate.latitude, 0.2); + compare(testingSourceWParams.position.coordinate.altitude, 24.24); + compare(directionValidSpyWParams.count, 1) + compare(directionSpyWParams.count, 2) + fuzzyCompare(testingSourceWParams.position.direction, 45, 0.1) + verify(testingSourceWParams.position.speedValid) + verify(testingSourceWParams.position.speed > 10000) + compare(testingSourceWParams.backendProperty("altitude"), 24.24) + + testingSourceWParams.active = false; + wait(2500); + compare(updateSpyWParams.count, 2); + compare(testingSourceWParams.position.coordinate.longitude, 0.2); + compare(testingSourceWParams.position.coordinate.latitude, 0.2); + compare(testingSourceWParams.position.coordinate.altitude, 24.24); + compare(directionValidSpyWParams.count, 1) + compare(directionSpyWParams.count, 2) + fuzzyCompare(testingSourceWParams.position.direction, 45, 0.1) + verify(testingSourceWParams.position.speedValid) + verify(testingSourceWParams.position.speed > 10000) + } +} -- cgit v1.2.1