diff options
Diffstat (limited to 'tests')
29 files changed, 1188 insertions, 152 deletions
diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index e3236deb..ba7dc523 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -74,6 +74,7 @@ SUBDIRS += \ qgeoshape \ qgeorectangle \ qgeocircle \ + qgeopath \ qgeocoordinate \ qgeolocation \ qgeopositioninfo \ diff --git a/tests/auto/declarative_ui/ItemGroup.qml b/tests/auto/declarative_ui/ItemGroup.qml new file mode 100644 index 00000000..57108ec7 --- /dev/null +++ b/tests/auto/declarative_ui/ItemGroup.qml @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** 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.4 +import QtPositioning 5.6 +import QtLocation 5.9 +import QtLocation.Test 5.6 + +MapItemGroup { + id: itemGroup + property double latitude : (mainRectangle.topLeft.latitude + mainRectangle.bottomRight.latitude) / 2.0 + property double longitude: (mainRectangle.topLeft.longitude + mainRectangle.bottomRight.longitude) / 2.0 + property double radius: 100 * 1000 + + MapRectangle { + id: mainRectangle + topLeft: QtPositioning.coordinate(43, -3) + bottomRight: QtPositioning.coordinate(37, 3) + opacity: 0.05 + visible: true + color: 'blue' + } + + MapCircle { + id: groupCircle + center: QtPositioning.coordinate(parent.latitude, parent.longitude) + radius: parent.radius + color: 'crimson' + } + + MapRectangle { + id: groupRectangle + topLeft: QtPositioning.coordinate(parent.latitude + 5, parent.longitude - 5) + bottomRight: QtPositioning.coordinate(parent.latitude, parent.longitude ) + color: 'yellow' + } +} diff --git a/tests/auto/declarative_ui/declarative_ui.pro b/tests/auto/declarative_ui/declarative_ui.pro index d3a2f08e..6734b1f9 100644 --- a/tests/auto/declarative_ui/declarative_ui.pro +++ b/tests/auto/declarative_ui/declarative_ui.pro @@ -16,3 +16,6 @@ TESTDATA = $$OTHER_FILES # Import path used by 'make check' since CI doesn't install test imports IMPORTPATH = $$OUT_PWD/../../../qml + +DISTFILES += \ + ItemGroup.qml diff --git a/tests/auto/declarative_ui/tst_map.qml b/tests/auto/declarative_ui/tst_map.qml index 5f02962d..6691580e 100644 --- a/tests/auto/declarative_ui/tst_map.qml +++ b/tests/auto/declarative_ui/tst_map.qml @@ -28,8 +28,8 @@ import QtQuick 2.0 import QtTest 1.0 -import QtLocation 5.6 import QtPositioning 5.5 +import QtLocation 5.9 Item { width:100 @@ -79,10 +79,22 @@ Item { Map {id: map; plugin: testPlugin; center: coordinate1; width: 100; height: 100} SignalSpy {id: mapCenterSpy; target: map; signalName: 'centerChanged'} + Map {id: mapPar; plugin: testPlugin; center: coordinate1; width: 512; height: 512} + Map {id: coordinateMap; plugin: herePlugin; center: coordinate3; width: 1000; height: 1000; zoomLevel: 15 } + Map {id: mapTiltBearing; plugin: testPlugin; center: coordinate1; + width: 1000; height: 1000; zoomLevel: 4; bearing: 45.0; tilt: 25.0 } + + Map {id: mapTiltBearingHere; plugin: herePlugin; center: coordinate1; + width: 1000; height: 1000; zoomLevel: 4; bearing: 45.0; tilt: 25.0 } + MapParameter { + id: testParameter + type: "cameraCenter_test" + property var center: QtPositioning.coordinate(-33.0, -47.0) + } TestCase { @@ -128,6 +140,51 @@ Item { compare(map.center.latitude, 12) } + function test_map_parameters() + { + // coordinate is set at map element declaration + var center = mapPar.toCoordinate(Qt.point((mapPar.width - 1) / 2.0, (mapPar.height - 1) / 2.0)) + fuzzyCompare(center.latitude, 10, 0.1) + fuzzyCompare(center.longitude, 11, 0.1) + + compare(mapPar.mapParameters.length, 0) + + mapPar.addMapParameter(testParameter) + + compare(mapPar.mapParameters.length, 1) + + center = mapPar.toCoordinate(Qt.point((mapPar.width - 1) / 2.0, (mapPar.height - 1) / 2.0)) + fuzzyCompare(center.latitude, -33, 0.1) + fuzzyCompare(center.longitude, -47, 0.1) + + mapPar.addMapParameter(testParameter) + compare(mapPar.mapParameters.length, 1) + + mapPar.removeMapParameter(testParameter) + compare(mapPar.mapParameters.length, 0) + + center = mapPar.toCoordinate(Qt.point((mapPar.width - 1) / 2.0, (mapPar.height - 1) / 2.0)) + fuzzyCompare(center.latitude, -33, 0.1) + fuzzyCompare(center.longitude, -47, 0.1) + + testParameter.center = mapPar.center // map.center has not been affected as it lives in the Declarative Map + mapPar.addMapParameter(testParameter) + compare(mapPar.mapParameters.length, 1) + + center = mapPar.toCoordinate(Qt.point((mapPar.width - 1) / 2.0, (mapPar.height - 1) / 2.0)) + fuzzyCompare(center.latitude, 10, 0.1) + fuzzyCompare(center.longitude, 11, 0.1) + + testParameter.center = QtPositioning.coordinate(-33.0, -47.0) + + center = mapPar.toCoordinate(Qt.point((mapPar.width - 1) / 2.0, (mapPar.height - 1) / 2.0)) + fuzzyCompare(center.latitude, -33, 0.1) + fuzzyCompare(center.longitude, -47, 0.1) + + mapPar.removeMapParameter(testParameter) + compare(mapPar.mapParameters.length, 0) + } + function test_map_clamp() { //valid @@ -203,6 +260,105 @@ Item { compare(map.maximumZoomLevel, 20) } + function test_tilt_limits() + { + map.tilt = 0 + + //initial plugin values + compare(map.minimumTilt, 0) + compare(map.maximumTilt, 60) + + //Higher min level than curr tilt, should change curr tilt + map.minimumTilt = 5 + map.maximumTilt = 18 + compare(map.tilt, 5) + compare(map.minimumTilt, 5) + compare(map.maximumTilt, 18) + + //Trying to set higher than max, max should be set. + map.maximumTilt = 61 + compare(map.minimumTilt, 5) + compare(map.maximumTilt, 60) + + //Negative values should be ignored + map.minimumTilt = -1 + map.maximumTilt = -2 + compare(map.minimumTilt, 5) + compare(map.maximumTilt, 60) + + //Max limit lower than curr zoom, should change curr zoom + map.tilt = 18 + map.maximumTilt = 16 + compare(map.tilt, 16) + + //resetting default + map.minimumTilt = 0 + map.maximumTilt = 60 + map.tilt = 0 + compare(map.minimumTilt, 0) + compare(map.maximumTilt, 60) + compare(map.tilt, 0) + } + + function test_fov_limits() + { + map.fieldOfView = 45 + + //initial plugin values + compare(map.minimumFieldOfView, 45) + compare(map.maximumFieldOfView, 45) + + map.minimumFieldOfView = 5 + map.maximumFieldOfView = 18 + map.fieldOfView = 4 + compare(map.fieldOfView, 45) + compare(map.minimumFieldOfView, 45) + compare(map.maximumFieldOfView, 45) + + map.activeMapType = map.supportedMapTypes[3] + // camera caps are [1-179], user previously asked for [5-18] + compare(map.minimumFieldOfView, 5) + compare(map.maximumFieldOfView, 18) + + map.fieldOfView = 4 + compare(map.fieldOfView, 5) + + //Higher min level than curr fieldOfView, should change curr fieldOfView + map.minimumFieldOfView = 6 + compare(map.fieldOfView, 6) + compare(map.minimumFieldOfView, 6) + compare(map.maximumFieldOfView, 18) + + //Trying to set higher than max, max should be set. + map.maximumFieldOfView = 179.5 + compare(map.minimumFieldOfView, 6) + compare(map.maximumFieldOfView, 179) + + //Negative values should be ignored + map.minimumFieldOfView = -1 + map.maximumFieldOfView = -2 + compare(map.minimumFieldOfView, 6) + compare(map.maximumFieldOfView, 179) + + //Max limit lower than curr zoom, should change curr zoom + map.fieldOfView = 18 + compare(map.fieldOfView, 18) + map.maximumFieldOfView = 16 + compare(map.maximumFieldOfView, 16) + compare(map.fieldOfView, 16) + + //resetting default + map.minimumFieldOfView = 1 + map.maximumFieldOfView = 179 + compare(map.minimumFieldOfView, 1) + compare(map.maximumFieldOfView, 179) + + map.activeMapType = map.supportedMapTypes[0] + compare(map.minimumFieldOfView, 45) + compare(map.maximumFieldOfView, 45) + compare(map.fieldOfView, 45) + } + function test_zoom() { wait(1000) @@ -298,6 +454,44 @@ Item { mapCenterSpy.clear() } + function test_map_tilt_bearing() + { + compare(map.bearing, 0.0) + compare(map.tilt, 0.0) + compare(mapTiltBearing.bearing, 45.0) + compare(mapTiltBearing.tilt, 25.0) + compare(mapTiltBearingHere.bearing, 45.0) + compare(mapTiltBearingHere.tilt, 25.0) + + mapTiltBearing.bearing = 0.0 + mapTiltBearing.tilt = 0.0 + compare(mapTiltBearing.bearing, 0.0) + compare(mapTiltBearing.tilt, 0.0) + + mapTiltBearing.bearing = 480.0 + mapTiltBearing.tilt = 140.0 + compare(mapTiltBearing.bearing, 120.0) + compare(mapTiltBearing.tilt, 60.0) + + mapTiltBearing.tilt = -140.0 + compare(mapTiltBearing.tilt, 0.0) + + mapTiltBearingHere.bearing = 45.0 + mapTiltBearingHere.tilt = 25.0 + compare(mapTiltBearingHere.bearing, 45.0) + compare(mapTiltBearingHere.tilt, 25.0) + mapTiltBearingHere.bearing = 0.0 + mapTiltBearingHere.tilt = 0.0 + compare(mapTiltBearingHere.bearing, 0.0) + compare(mapTiltBearingHere.tilt, 0.0) + + mapTiltBearing.bearing = 45.0 + mapTiltBearing.tilt = 25.0 + mapTiltBearing.zoomLevel = 8.0 + compare(mapTiltBearing.bearing, 45.0) + compare(mapTiltBearing.tilt, 25.0) + } + function test_coordinate_conversion() { wait(1000) diff --git a/tests/auto/declarative_ui/tst_map_error.qml b/tests/auto/declarative_ui/tst_map_error.qml index c978e0cf..35613f63 100644 --- a/tests/auto/declarative_ui/tst_map_error.qml +++ b/tests/auto/declarative_ui/tst_map_error.qml @@ -192,10 +192,16 @@ Item { { map_no_plugin.visibleRegion = QtPositioning.circle(coordinate,1000) verify(map_no_plugin.center != coordinate) - verify(map_no_plugin.visibleRegion == QtPositioning.circle(coordinate,1000)) + verify(map_no_plugin.visibleRegion.contains(coordinate.atDistanceAndAzimuth(1000,0)) == true) + verify(map_no_plugin.visibleRegion.contains(coordinate.atDistanceAndAzimuth(1000,90)) == true) + verify(map_no_plugin.visibleRegion.contains(coordinate.atDistanceAndAzimuth(1000,180)) == true) + verify(map_no_plugin.visibleRegion.contains(coordinate.atDistanceAndAzimuth(1000,270)) == true) map_error_plugin.visibleRegion = QtPositioning.circle(coordinate,1000) verify(map_error_plugin.center != coordinate) - verify(map_no_plugin.visibleRegion == QtPositioning.circle(coordinate,1000)) + verify(map_error_plugin.visibleRegion.contains(coordinate.atDistanceAndAzimuth(1000,0)) == true) + verify(map_error_plugin.visibleRegion.contains(coordinate.atDistanceAndAzimuth(1000,90)) == true) + verify(map_error_plugin.visibleRegion.contains(coordinate.atDistanceAndAzimuth(1000,180)) == true) + verify(map_error_plugin.visibleRegion.contains(coordinate.atDistanceAndAzimuth(1000,270)) == true) } function test_map_activeMapType() diff --git a/tests/auto/declarative_ui/tst_map_item.qml b/tests/auto/declarative_ui/tst_map_item.qml index 8ede357f..b75daf38 100644 --- a/tests/auto/declarative_ui/tst_map_item.qml +++ b/tests/auto/declarative_ui/tst_map_item.qml @@ -28,7 +28,7 @@ import QtQuick 2.0 import QtTest 1.0 -import QtLocation 5.6 +import QtLocation 5.9 import QtPositioning 5.5 import QtLocation.Test 5.6 @@ -75,6 +75,10 @@ Item { } Item { id: someItem } + ItemGroup { + id: itemGroup1 + } + MapCircle { id: extMapCircle center { @@ -403,6 +407,10 @@ Item { mouseClick(map, map.width + 5, point.y + 5) tryCompare(extMapQuickItemClicked, "count", 1) map.removeMapItem(extMapQuickItem) + + var numItemsOnMap = map.mapItems.length + map.addMapItemGroup( itemGroup1 ) + compare(map.mapItems.length, numItemsOnMap + 3) } function test_drag() diff --git a/tests/auto/declarative_ui/tst_map_item_details.qml b/tests/auto/declarative_ui/tst_map_item_details.qml index ebaf1ea7..0c5f5c0b 100644 --- a/tests/auto/declarative_ui/tst_map_item_details.qml +++ b/tests/auto/declarative_ui/tst_map_item_details.qml @@ -439,7 +439,7 @@ Item { // move item edge onto dateline extMapRectDateline.topLeft.longitude = datelineCoordinate.longitude point = map.fromCoordinate(extMapRectDateline.topLeft) - verify(point.x == map.width / 2.0) + compare(point.x, map.width / 2.0) // drag item back onto dateline verify(LocationTestHelper.waitForPolished(map)) visualInspectionPoint(inspectionTime) @@ -463,7 +463,7 @@ Item { verify(extMapCircleDateline.center.longitude === 180) map.center = datelineCoordinate point = map.fromCoordinate(extMapCircleDateline.center) - verify(point.x == map.width / 2.0) // center of the screen + compare(point.x, map.width / 2.0) // center of the screen visualInspectionPoint() extMapCircleDateline.center.longitude = datelineCoordinateRight.longitude // -170, moving the circle to the right point = map.fromCoordinate(extMapCircleDateline.center) @@ -533,12 +533,12 @@ Item { path[0].longitude = datelineCoordinate.longitude; extMapPolygonDateline.path = path; point = map.fromCoordinate(extMapPolygonDateline.path[0]) - verify(point.x == map.width / 2.0) + compare(point.x, map.width / 2.0) path = extMapPolygonDateline.path; path[3].longitude = datelineCoordinate.longitude; extMapPolygonDateline.path = path; point = map.fromCoordinate(extMapPolygonDateline.path[3]) - verify(point.x == map.width / 2.0) + compare(point.x, map.width / 2.0) verify(LocationTestHelper.waitForPolished(map)) visualInspectionPoint(inspectionTime) mousePress(map, point.x + 5, point.y - 5) @@ -575,7 +575,7 @@ Item { path[0].longitude = datelineCoordinate.longitude; extMapPolylineDateline.path = path; point = map.fromCoordinate(extMapPolylineDateline.path[0]) - verify(point.x == map.width / 2.0) + compare(point.x, map.width / 2.0) map.removeMapItem(extMapPolylineDateline) // map route diff --git a/tests/auto/declarative_ui/tst_map_maptype.qml b/tests/auto/declarative_ui/tst_map_maptype.qml index fa056c44..1de30439 100644 --- a/tests/auto/declarative_ui/tst_map_maptype.qml +++ b/tests/auto/declarative_ui/tst_map_maptype.qml @@ -40,6 +40,12 @@ Item{ Map { id: map; anchors.fill: parent } SignalSpy { id: supportedMapTypesSpy; target: map; signalName: "supportedMapTypesChanged" } SignalSpy { id: activeMapTypeChangedSpy; target: map; signalName: "activeMapTypeChanged" } + SignalSpy { id: minimumZoomLevelChangedSpy; target: map; signalName: "minimumZoomLevelChanged" } + SignalSpy { id: maximumZoomLevelChangedSpy; target: map; signalName: "maximumZoomLevelChanged" } + SignalSpy { id: minimumTiltChangedSpy; target: map; signalName: "minimumTiltChanged" } + SignalSpy { id: maximumTiltChangedSpy; target: map; signalName: "maximumTiltChanged" } + SignalSpy { id: minimumFieldOfViewChangedSpy; target: map; signalName: "minimumFieldOfViewChanged" } + SignalSpy { id: maximumFieldOfViewChangedSpy; target: map; signalName: "maximumFieldOfViewChanged" } TestCase { id: testCase @@ -52,7 +58,7 @@ Item{ compare(map.activeMapType.style, MapType.NoMap) map.plugin = testPlugin tryCompare(supportedMapTypesSpy, "count", 1) - compare(map.supportedMapTypes.length,3) + compare(map.supportedMapTypes.length, 4) compare(map.supportedMapTypes[0].style, MapType.StreetMap) compare(map.supportedMapTypes[0].name, "StreetMap") compare(map.supportedMapTypes[0].description, "StreetMap") @@ -62,19 +68,30 @@ Item{ compare(map.supportedMapTypes[2].style, MapType.CycleMap) compare(map.supportedMapTypes[2].name, "CycleMap") compare(map.supportedMapTypes[2].description, "CycleMap") + compare(map.supportedMapTypes[3].style, MapType.CustomMap) + compare(map.supportedMapTypes[3].name, "AlternateCameraCapabilities") + compare(map.supportedMapTypes[3].description, "AlternateCameraCapabilities") //default compare(map.activeMapType.style, MapType.StreetMap) } function init() { + map.activeMapType = map.supportedMapTypes[0] + supportedMapTypesSpy.clear() activeMapTypeChangedSpy.clear() - map.activeMapType = map.supportedMapTypes[0] + minimumZoomLevelChangedSpy.clear(); + maximumZoomLevelChangedSpy.clear(); + minimumTiltChangedSpy.clear(); + maximumTiltChangedSpy.clear(); + minimumFieldOfViewChangedSpy.clear(); + maximumFieldOfViewChangedSpy.clear(); } function test_setting_types() { + // resetting it first map.activeMapType = map.supportedMapTypes[0] tryCompare(activeMapTypeChangedSpy, "count", 0) @@ -87,6 +104,82 @@ Item{ tryCompare(activeMapTypeChangedSpy, "count", 2) compare(map.supportedMapTypes[2].name, map.activeMapType.name) compare(map.supportedMapTypes[2].style, map.activeMapType.style) + + map.activeMapType = map.supportedMapTypes[3] + tryCompare(activeMapTypeChangedSpy, "count", 3) + compare(map.supportedMapTypes[3].name, map.activeMapType.name) + compare(map.supportedMapTypes[3].style, map.activeMapType.style) + } + + function test_maptype_capabilities() + { + map.activeMapType = map.supportedMapTypes[0] + + compare(map.minimumZoomLevel, 0) + compare(map.maximumZoomLevel, 20) + compare(map.minimumTilt, 0) + compare(map.maximumTilt, 60) + compare(map.minimumFieldOfView, 45) + compare(map.maximumFieldOfView, 45) + + tryCompare(minimumZoomLevelChangedSpy, "count", 0) + tryCompare(maximumZoomLevelChangedSpy, "count", 0) + tryCompare(minimumTiltChangedSpy, "count", 0) + tryCompare(maximumTiltChangedSpy, "count", 0) + tryCompare(minimumFieldOfViewChangedSpy, "count", 0) + tryCompare(maximumFieldOfViewChangedSpy, "count", 0) + + + map.activeMapType = map.supportedMapTypes[1] + + compare(map.minimumZoomLevel, 0) + compare(map.maximumZoomLevel, 20) + compare(map.minimumTilt, 0) + compare(map.maximumTilt, 60) + compare(map.minimumFieldOfView, 45) + compare(map.maximumFieldOfView, 45) + + tryCompare(minimumZoomLevelChangedSpy, "count", 0) + tryCompare(maximumZoomLevelChangedSpy, "count", 0) + tryCompare(minimumTiltChangedSpy, "count", 0) + tryCompare(maximumTiltChangedSpy, "count", 0) + tryCompare(minimumFieldOfViewChangedSpy, "count", 0) + tryCompare(maximumFieldOfViewChangedSpy, "count", 0) + + + map.activeMapType = map.supportedMapTypes[3] + + compare(map.minimumZoomLevel, 0) + compare(map.maximumZoomLevel, 19) + compare(map.minimumTilt, 0) + compare(map.maximumTilt, 80) + compare(map.minimumFieldOfView, 1) + compare(map.maximumFieldOfView, 179) + + tryCompare(minimumZoomLevelChangedSpy, "count", 0) + tryCompare(maximumZoomLevelChangedSpy, "count", 1) + tryCompare(minimumTiltChangedSpy, "count", 0) + tryCompare(maximumTiltChangedSpy, "count", 1) + tryCompare(minimumFieldOfViewChangedSpy, "count", 1) + tryCompare(maximumFieldOfViewChangedSpy, "count", 1) + + + map.activeMapType = map.supportedMapTypes[0] + + compare(map.minimumZoomLevel, 0) + compare(map.maximumZoomLevel, 20) + compare(map.minimumTilt, 0) + compare(map.maximumTilt, 60) + compare(map.minimumFieldOfView, 45) + compare(map.maximumFieldOfView, 45) + + tryCompare(minimumZoomLevelChangedSpy, "count", 0) + tryCompare(maximumZoomLevelChangedSpy, "count", 2) + tryCompare(minimumTiltChangedSpy, "count", 0) + tryCompare(maximumTiltChangedSpy, "count", 2) + tryCompare(minimumFieldOfViewChangedSpy, "count", 2) + tryCompare(maximumFieldOfViewChangedSpy, "count", 2) + } } } diff --git a/tests/auto/geotestplugin/geotestplugin.pro b/tests/auto/geotestplugin/geotestplugin.pro index fb3f1b39..f4fe25b3 100644 --- a/tests/auto/geotestplugin/geotestplugin.pro +++ b/tests/auto/geotestplugin/geotestplugin.pro @@ -14,7 +14,8 @@ HEADERS += qgeocodingmanagerengine_test.h \ qgeotiledmap_test.h \ qgeotilefetcher_test.h -SOURCES += qgeoserviceproviderplugin_test.cpp +SOURCES += qgeoserviceproviderplugin_test.cpp \ + qgeotiledmap_test.cpp OTHER_FILES += \ geotestplugin.json \ diff --git a/tests/auto/geotestplugin/qgeocodingmanagerengine_test.h b/tests/auto/geotestplugin/qgeocodingmanagerengine_test.h index 1d9f0792..ecbb60d1 100644 --- a/tests/auto/geotestplugin/qgeocodingmanagerengine_test.h +++ b/tests/auto/geotestplugin/qgeocodingmanagerengine_test.h @@ -57,11 +57,6 @@ public: void callSetOffset ( int offset ) {setOffset(offset);} void callSetLocations ( const QList<QGeoLocation> & locations ) {setLocations(locations);} void callSetViewport ( const QGeoShape &viewport ) {setViewport(viewport);} - void abort() { - emit aborted(); - } -Q_SIGNALS: - void aborted(); }; class QGeoCodingManagerEngineTest: public QGeoCodingManagerEngine diff --git a/tests/auto/geotestplugin/qgeoroutingmanagerengine_test.h b/tests/auto/geotestplugin/qgeoroutingmanagerengine_test.h index 8ae58042..0a1e7ce6 100644 --- a/tests/auto/geotestplugin/qgeoroutingmanagerengine_test.h +++ b/tests/auto/geotestplugin/qgeoroutingmanagerengine_test.h @@ -52,12 +52,6 @@ public: void callSetError ( Error error, const QString & errorString ) {setError(error, errorString);} void callSetFinished ( bool finished ) {setFinished(finished);} void callSetRoutes(const QList<QGeoRoute> &routes) {setRoutes(routes);} - - void abort() { - emit aborted(); - } -Q_SIGNALS: - void aborted(); }; class QGeoRoutingManagerEngineTest: public QGeoRoutingManagerEngine diff --git a/tests/auto/geotestplugin/qgeotiledmap_test.cpp b/tests/auto/geotestplugin/qgeotiledmap_test.cpp new file mode 100644 index 00000000..ef2af7db --- /dev/null +++ b/tests/auto/geotestplugin/qgeotiledmap_test.cpp @@ -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$ +** +****************************************************************************/ + +#include "qgeotiledmap_test.h" +#include <QtLocation/private/qgeotiledmap_p_p.h> +#include <QtLocation/private/qgeomapparameter_p.h> + +QT_USE_NAMESPACE + +class QGeoTiledMapTestPrivate: public QGeoTiledMapPrivate +{ + Q_DECLARE_PUBLIC(QGeoTiledMapTest) +public: + QGeoTiledMapTestPrivate(QGeoTiledMappingManagerEngine *engine) + : QGeoTiledMapPrivate(engine) + { + + } + + ~QGeoTiledMapTestPrivate() + { + + } + + void addParameter(QGeoMapParameter *param) override + { + Q_Q(QGeoTiledMapTest); + if (param->type() == QStringLiteral("cameraCenter_test")) { + // We assume that cameraCenter_test parameters have a QGeoCoordinate property named "center" + // Handle the parameter + QGeoCameraData cameraData = m_cameraData; + QGeoCoordinate newCenter = param->property("center").value<QGeoCoordinate>(); + cameraData.setCenter(newCenter); + q->setCameraData(cameraData); + // Connect for further changes handling + q->connect(param, SIGNAL(propertyUpdated(QGeoMapParameter *, const char *)), + q, SLOT(onCameraCenter_testChanged(QGeoMapParameter*, const char*))); + + } + } + void removeParameter(QGeoMapParameter *param) override + { + Q_Q(QGeoTiledMapTest); + param->disconnect(q); + } +}; + +QGeoTiledMapTest::QGeoTiledMapTest(QGeoTiledMappingManagerEngine *engine, QObject *parent) +: QGeoTiledMap(*new QGeoTiledMapTestPrivate(engine), engine, parent), m_engine(engine) +{ +} + +void QGeoTiledMapTest::onCameraCenter_testChanged(QGeoMapParameter *param, const char *propertyName) +{ + Q_D(QGeoTiledMapTest); + if (strcmp(propertyName, "center") == 0) { + QGeoCameraData cameraData = d->m_cameraData; + // Not testing for propertyName as this param has only one allowed property + QGeoCoordinate newCenter = param->property(propertyName).value<QGeoCoordinate>(); + cameraData.setCenter(newCenter); + setCameraData(cameraData); + } +} diff --git a/tests/auto/geotestplugin/qgeotiledmap_test.h b/tests/auto/geotestplugin/qgeotiledmap_test.h index 27ff7164..19c7620e 100644 --- a/tests/auto/geotestplugin/qgeotiledmap_test.h +++ b/tests/auto/geotestplugin/qgeotiledmap_test.h @@ -33,17 +33,25 @@ #include <QtLocation/private/qgeotiledmap_p.h> QT_USE_NAMESPACE + class QGeoTiledMappingManagerEngineTest; +class QGeoTiledMapTestPrivate; + class QGeoTiledMapTest: public QGeoTiledMap { Q_OBJECT + Q_DECLARE_PRIVATE(QGeoTiledMapTest) public: - QGeoTiledMapTest(QGeoTiledMappingManagerEngine *engine, QObject *parent = 0): - QGeoTiledMap(engine, parent), - m_engine(engine){} + QGeoTiledMapTest(QGeoTiledMappingManagerEngine *engine, QObject *parent = 0); + +protected slots: + void onCameraCenter_testChanged(QGeoMapParameter *param, const char *propertyName); + public: using QGeoTiledMap::setCameraData; QGeoTiledMappingManagerEngine *m_engine; }; #endif + + diff --git a/tests/auto/geotestplugin/qgeotiledmappingmanagerengine_test.h b/tests/auto/geotestplugin/qgeotiledmappingmanagerengine_test.h index 2765c268..df729392 100644 --- a/tests/auto/geotestplugin/qgeotiledmappingmanagerengine_test.h +++ b/tests/auto/geotestplugin/qgeotiledmappingmanagerengine_test.h @@ -57,12 +57,16 @@ public: capabilities.setMinimumZoomLevel(0.0); capabilities.setMaximumZoomLevel(20.0); capabilities.setSupportsBearing(true); + capabilities.setSupportsTilting(true); + capabilities.setMinimumTilt(0); + capabilities.setMaximumTilt(60); setTileSize(QSize(256, 256)); QList<QGeoMapType> mapTypes; mapTypes << QGeoMapType(QGeoMapType::StreetMap, tr("StreetMap"), tr("StreetMap"), false, false, 1); mapTypes << QGeoMapType(QGeoMapType::SatelliteMapDay, tr("SatelliteMapDay"), tr("SatelliteMapDay"), false, false, 2); mapTypes << QGeoMapType(QGeoMapType::CycleMap, tr("CycleMap"), tr("CycleMap"), false, false, 3); + mapTypes << QGeoMapType(QGeoMapType::CustomMap, tr("AlternateCameraCapabilities"), tr("AlternateCameraCapabilities"), false, false, 4); setSupportedMapTypes(mapTypes); QGeoTileFetcherTest *fetcher = new QGeoTileFetcherTest(this); @@ -87,6 +91,27 @@ public: return new QGeoTiledMapTest(this); } + QGeoCameraCapabilities cameraCapabilities(const QGeoMapType &mapType) const Q_DECL_OVERRIDE + { + switch (mapType.mapId()) { + case 4: + { + QGeoCameraCapabilities capabilities; + capabilities.setMinimumZoomLevel(0.0); + capabilities.setMaximumZoomLevel(19.0); + capabilities.setSupportsBearing(true); + capabilities.setSupportsTilting(true); + capabilities.setMinimumTilt(0); + capabilities.setMaximumTilt(80); + capabilities.setMinimumFieldOfView(1); + capabilities.setMaximumFieldOfView(179); + return capabilities; + } + default: + return QGeoMappingManagerEngine::cameraCapabilities(mapType); + } + } + }; #endif diff --git a/tests/auto/qgeocameracapabilities/tst_qgeocameracapabilities.cpp b/tests/auto/qgeocameracapabilities/tst_qgeocameracapabilities.cpp index 54755421..06d85e1e 100644 --- a/tests/auto/qgeocameracapabilities/tst_qgeocameracapabilities.cpp +++ b/tests/auto/qgeocameracapabilities/tst_qgeocameracapabilities.cpp @@ -29,8 +29,8 @@ #include <QtCore/QString> #include <QtTest/QtTest> -#include "qgeocameracapabilities_p.h" -#include "qgeotiledmap_p.h" +#include <QtLocation/private/qgeocameracapabilities_p.h> +#include <QtLocation/private/qgeotiledmap_p.h> QT_USE_NAMESPACE @@ -54,6 +54,8 @@ private Q_SLOTS: void supportsTiltingTest(); void minimumTiltTest(); void maximumTiltTest(); + void minimumFieldOfViewTest(); + void maximumFieldOfViewTest(); void operatorsTest_data(); void operatorsTest(); void isValidTest(); @@ -68,12 +70,14 @@ void tst_QGeoCameraCapabilities::populateGeoCameraCapabilitiesData(){ QTest::addColumn<double>("maximumZoomLevel"); QTest::addColumn<double>("minimumTilt"); QTest::addColumn<double>("maximumTilt"); + QTest::addColumn<double>("minimumFieldOfView"); + QTest::addColumn<double>("maximumFieldOfView"); QTest::addColumn<bool>("bearingSupport"); QTest::addColumn<bool>("rollingSupport"); QTest::addColumn<bool>("tiltingSupport"); - QTest::newRow("zeros") << 0.0 << 0.0 << 0.0 << 0.0 << false << false << false; - QTest::newRow("valid") << 1.0 << 2.0 << 0.5 << 1.5 << true << true << true; - QTest::newRow("negative values") << 0.0 << 0.5 << -0.5 << -0.1 << true << true << true; + QTest::newRow("zeros") << 0.0 << 0.0 << 0.0 << 0.0 << 0.0 << 0.0 << false << false << false; + QTest::newRow("valid") << 1.0 << 2.0 << 0.5 << 1.5 << 1.0 << 179.0 << true << true << true; + QTest::newRow("negative values") << 0.0 << 0.5 << -0.5 << -0.1 << -20.0 << -30.0 << true << true << true; } void tst_QGeoCameraCapabilities::constructorTest_data(){ @@ -86,10 +90,15 @@ void tst_QGeoCameraCapabilities::constructorTest() QFETCH(double, maximumZoomLevel); QFETCH(double, minimumTilt); QFETCH(double, maximumTilt); + QFETCH(double, minimumFieldOfView); + QFETCH(double, maximumFieldOfView); QFETCH(bool, bearingSupport); QFETCH(bool, rollingSupport); QFETCH(bool, tiltingSupport); + minimumFieldOfView = qBound(1.0, minimumFieldOfView, 179.0); + maximumFieldOfView = qBound(1.0, maximumFieldOfView, 179.0); + // contructor test with default values QGeoCameraCapabilities cameraCapabilities; QGeoCameraCapabilities cameraCapabilities2(cameraCapabilities); @@ -100,12 +109,16 @@ void tst_QGeoCameraCapabilities::constructorTest() QVERIFY2(cameraCapabilities.supportsTilting() == cameraCapabilities2.supportsTilting(), "Copy constructor failed for tilting support"); QCOMPARE(cameraCapabilities.minimumTilt(), cameraCapabilities2.minimumTilt()); QCOMPARE(cameraCapabilities.maximumTilt(), cameraCapabilities2.maximumTilt()); + QCOMPARE(cameraCapabilities.minimumFieldOfView(), cameraCapabilities2.minimumFieldOfView()); + QCOMPARE(cameraCapabilities.maximumFieldOfView(), cameraCapabilities2.maximumFieldOfView()); // constructor test after setting values cameraCapabilities.setMinimumZoomLevel(minimumZoomLevel); cameraCapabilities.setMaximumZoomLevel(maximumZoomLevel); cameraCapabilities.setMinimumTilt(minimumTilt); cameraCapabilities.setMaximumTilt(maximumTilt); + cameraCapabilities.setMinimumFieldOfView(minimumFieldOfView); + cameraCapabilities.setMaximumFieldOfView(maximumFieldOfView); cameraCapabilities.setSupportsBearing(bearingSupport); cameraCapabilities.setSupportsRolling(rollingSupport); cameraCapabilities.setSupportsTilting(tiltingSupport); @@ -116,6 +129,8 @@ void tst_QGeoCameraCapabilities::constructorTest() QCOMPARE(cameraCapabilities3.maximumZoomLevel(), maximumZoomLevel); QCOMPARE(cameraCapabilities3.minimumTilt(), minimumTilt); QCOMPARE(cameraCapabilities3.maximumTilt(), maximumTilt); + QCOMPARE(cameraCapabilities3.minimumFieldOfView(), minimumFieldOfView); + QCOMPARE(cameraCapabilities3.maximumFieldOfView(), maximumFieldOfView); QVERIFY2(cameraCapabilities3.supportsBearing() == bearingSupport, "Copy constructor failed for bearing support"); QVERIFY2(cameraCapabilities3.supportsRolling() == rollingSupport, "Copy constructor failed for rolling support "); QVERIFY2(cameraCapabilities3.supportsTilting() == tiltingSupport, "Copy constructor failed for tilting support"); @@ -127,6 +142,8 @@ void tst_QGeoCameraCapabilities::constructorTest() QVERIFY2(cameraCapabilities.supportsTilting() == cameraCapabilities3.supportsTilting(), "Copy constructor failed for tilting support"); QCOMPARE(cameraCapabilities.minimumTilt(), cameraCapabilities3.minimumTilt()); QCOMPARE(cameraCapabilities.maximumTilt(), cameraCapabilities3.maximumTilt()); + QCOMPARE(cameraCapabilities.minimumFieldOfView(), cameraCapabilities3.minimumFieldOfView()); + QCOMPARE(cameraCapabilities.maximumFieldOfView(), cameraCapabilities3.maximumFieldOfView()); } void tst_QGeoCameraCapabilities::minimumZoomLevelTest() @@ -213,6 +230,40 @@ void tst_QGeoCameraCapabilities::maximumTiltTest(){ QCOMPARE(cameraCapabilities2.maximumTilt(), 1.5); } +void tst_QGeoCameraCapabilities::minimumFieldOfViewTest() +{ + QGeoCameraCapabilities cameraCapabilities; + QCOMPARE(cameraCapabilities.minimumFieldOfView(), 45.0); // min/max default to 45 + cameraCapabilities.setMinimumFieldOfView(1.5); + QCOMPARE(cameraCapabilities.minimumFieldOfView(), 1.5); + cameraCapabilities.setMinimumFieldOfView(-1.5); + QCOMPARE(cameraCapabilities.minimumFieldOfView(), 1.0); + cameraCapabilities.setMinimumFieldOfView(245.5); + QCOMPARE(cameraCapabilities.minimumFieldOfView(), 179.0); + + QGeoCameraCapabilities cameraCapabilities2 = cameraCapabilities; + QCOMPARE(cameraCapabilities2.minimumFieldOfView(), 179.0); + cameraCapabilities.setMinimumFieldOfView(2.5); + QCOMPARE(cameraCapabilities2.minimumFieldOfView(), 179.0); +} + +void tst_QGeoCameraCapabilities::maximumFieldOfViewTest() +{ + QGeoCameraCapabilities cameraCapabilities; + QCOMPARE(cameraCapabilities.maximumFieldOfView(), 45.0); // min/max default to 45 + cameraCapabilities.setMaximumFieldOfView(1.5); + QCOMPARE(cameraCapabilities.maximumFieldOfView(), 1.5); + cameraCapabilities.setMaximumFieldOfView(-1.5); + QCOMPARE(cameraCapabilities.maximumFieldOfView(), 1.0); + cameraCapabilities.setMaximumFieldOfView(245.5); + QCOMPARE(cameraCapabilities.maximumFieldOfView(), 179.0); + + QGeoCameraCapabilities cameraCapabilities2 = cameraCapabilities; + QCOMPARE(cameraCapabilities2.maximumFieldOfView(), 179.0); + cameraCapabilities.setMaximumFieldOfView(2.5); + QCOMPARE(cameraCapabilities2.maximumFieldOfView(), 179.0); +} + void tst_QGeoCameraCapabilities::operatorsTest_data(){ populateGeoCameraCapabilitiesData(); } @@ -223,15 +274,22 @@ void tst_QGeoCameraCapabilities::operatorsTest(){ QFETCH(double, maximumZoomLevel); QFETCH(double, minimumTilt); QFETCH(double, maximumTilt); + QFETCH(double, minimumFieldOfView); + QFETCH(double, maximumFieldOfView); QFETCH(bool, bearingSupport); QFETCH(bool, rollingSupport); QFETCH(bool, tiltingSupport); + minimumFieldOfView = qBound(1.0, minimumFieldOfView, 179.0); + maximumFieldOfView = qBound(1.0, maximumFieldOfView, 179.0); + QGeoCameraCapabilities cameraCapabilities; cameraCapabilities.setMinimumZoomLevel(minimumZoomLevel); cameraCapabilities.setMaximumZoomLevel(maximumZoomLevel); cameraCapabilities.setMinimumTilt(minimumTilt); cameraCapabilities.setMaximumTilt(maximumTilt); + cameraCapabilities.setMinimumFieldOfView(minimumFieldOfView); + cameraCapabilities.setMaximumFieldOfView(maximumFieldOfView); cameraCapabilities.setSupportsBearing(bearingSupport); cameraCapabilities.setSupportsRolling(rollingSupport); cameraCapabilities.setSupportsTilting(tiltingSupport); @@ -242,17 +300,21 @@ void tst_QGeoCameraCapabilities::operatorsTest(){ QCOMPARE(cameraCapabilities2.maximumZoomLevel(), maximumZoomLevel); QCOMPARE(cameraCapabilities2.minimumTilt(), minimumTilt); QCOMPARE(cameraCapabilities2.maximumTilt(), maximumTilt); - QVERIFY2(cameraCapabilities2.supportsBearing() == bearingSupport, "Copy constructor failed for bearing support"); - QVERIFY2(cameraCapabilities2.supportsRolling() == rollingSupport, "Copy constructor failed for rolling support "); - QVERIFY2(cameraCapabilities2.supportsTilting() == tiltingSupport, "Copy constructor failed for tilting support"); + QVERIFY2(cameraCapabilities2.supportsBearing() == bearingSupport, "Assignment operator failed for bearing support"); + QVERIFY2(cameraCapabilities2.supportsRolling() == rollingSupport, "Assignment operator failed for rolling support "); + QVERIFY2(cameraCapabilities2.supportsTilting() == tiltingSupport, "Assignment operator failed for tilting support"); + QCOMPARE(cameraCapabilities2.minimumFieldOfView(), minimumFieldOfView); + QCOMPARE(cameraCapabilities2.maximumFieldOfView(), maximumFieldOfView); // verify that values have not changed after a constructor copy QCOMPARE(cameraCapabilities.minimumZoomLevel(), cameraCapabilities2.minimumZoomLevel()); QCOMPARE(cameraCapabilities.maximumZoomLevel(), cameraCapabilities2.maximumZoomLevel()); - QVERIFY2(cameraCapabilities.supportsBearing() == cameraCapabilities2.supportsBearing(), "Copy constructor failed for bearing support"); - QVERIFY2(cameraCapabilities.supportsRolling() == cameraCapabilities2.supportsRolling(), "Copy constructor failed for rolling support "); - QVERIFY2(cameraCapabilities.supportsTilting() == cameraCapabilities2.supportsTilting(), "Copy constructor failed for tilting support"); + QVERIFY2(cameraCapabilities.supportsBearing() == cameraCapabilities2.supportsBearing(), "Assignment operator failed for bearing support"); + QVERIFY2(cameraCapabilities.supportsRolling() == cameraCapabilities2.supportsRolling(), "Assignment operator failed for rolling support "); + QVERIFY2(cameraCapabilities.supportsTilting() == cameraCapabilities2.supportsTilting(), "Assignment operator failed for tilting support"); QCOMPARE(cameraCapabilities.minimumTilt(), cameraCapabilities2.minimumTilt()); QCOMPARE(cameraCapabilities.maximumTilt(), cameraCapabilities2.maximumTilt()); + QCOMPARE(cameraCapabilities.minimumFieldOfView(), cameraCapabilities2.minimumFieldOfView()); + QCOMPARE(cameraCapabilities.maximumFieldOfView(), cameraCapabilities2.maximumFieldOfView()); } void tst_QGeoCameraCapabilities::isValidTest(){ diff --git a/tests/auto/qgeocameradata/qgeocameradata.pro b/tests/auto/qgeocameradata/qgeocameradata.pro index f2d6d5d8..80069ea1 100644 --- a/tests/auto/qgeocameradata/qgeocameradata.pro +++ b/tests/auto/qgeocameradata/qgeocameradata.pro @@ -6,4 +6,4 @@ INCLUDEPATH += ../../../src/location/maps SOURCES += tst_qgeocameradata.cpp -QT += location positioning-private testlib +QT += location-private positioning-private testlib diff --git a/tests/auto/qgeocameratiles/qgeocameratiles.pro b/tests/auto/qgeocameratiles/qgeocameratiles.pro index 816e4240..63ab2771 100644 --- a/tests/auto/qgeocameratiles/qgeocameratiles.pro +++ b/tests/auto/qgeocameratiles/qgeocameratiles.pro @@ -5,4 +5,4 @@ INCLUDEPATH += ../../../src/location/maps SOURCES += tst_qgeocameratiles.cpp -QT += location positioning-private testlib +QT += location-private positioning-private testlib diff --git a/tests/auto/qgeocameratiles/tst_qgeocameratiles.cpp b/tests/auto/qgeocameratiles/tst_qgeocameratiles.cpp index 8d9cec3a..1ac0abfa 100644 --- a/tests/auto/qgeocameratiles/tst_qgeocameratiles.cpp +++ b/tests/auto/qgeocameratiles/tst_qgeocameratiles.cpp @@ -28,12 +28,12 @@ //TESTED_COMPONENT=src/location/maps -#include "qgeotilespec_p.h" -#include "qgeocameratiles_p.h" -#include "qgeocameradata_p.h" -#include "qgeomaptype_p.h" +#include <QtLocation/private/qgeotilespec_p.h> +#include <QtLocation/private/qgeocameratiles_p.h> +#include <QtLocation/private/qgeocameradata_p.h> +#include <QtLocation/private/qgeomaptype_p.h> -#include <QtPositioning/private/qgeoprojection_p.h> +#include <QtPositioning/private/qwebmercator_p.h> #include <QtPositioning/private/qdoublevector2d_p.h> #include <QtTest/QtTest> #include <QtCore/QList> @@ -69,6 +69,7 @@ private slots: void tilesMapType(); void tilesPositions(); void tilesPositions_data(); + void test_tilted_frustum(); }; void tst_QGeoCameraTiles::row(const PositionTestInfo &pti, int xOffset, int yOffset, int tileX, int tileY, int tileW, int tileH) @@ -116,6 +117,29 @@ void tst_QGeoCameraTiles::test_group(const PositionTestInfo &pti, QList<int> &xV } } +void tst_QGeoCameraTiles::test_tilted_frustum() +{ + // ctFull : Full map in the view, all 16 zl2 tiles visible. Using this as control. + QGeoCameraData cameraFull; + cameraFull.setZoomLevel(2); + cameraFull.setCenter(QGeoCoordinate(0,0)); + QGeoCameraTiles ctFull; + ctFull.setTileSize(64); + ctFull.setCameraData(cameraFull); + ctFull.setScreenSize(QSize(256, 256)); + + QGeoCameraData camera; + camera.setZoomLevel(2.322); + camera.setTilt(30); + camera.setCenter(QWebMercator::mercatorToCoord(QDoubleVector2D(0.75, 0.5))); + QGeoCameraTiles ct; + ct.setTileSize(64); + ct.setScreenSize(QSize(320, 180)); + ct.setCameraData(camera); + + QCOMPARE(ct.createTiles(), ctFull.createTiles()); +} + void tst_QGeoCameraTiles::tilesPlugin() { QGeoCameraData camera; @@ -226,7 +250,7 @@ void tst_QGeoCameraTiles::tilesPositions() QGeoCameraData camera; camera.setZoomLevel(zoom); - camera.setCenter(QGeoProjection::mercatorToCoord(QDoubleVector2D(mercatorX, mercatorY))); + camera.setCenter(QWebMercator::mercatorToCoord(QDoubleVector2D(mercatorX, mercatorY))); QGeoCameraTiles ct; ct.setTileSize(16); diff --git a/tests/auto/qgeocircle/tst_qgeocircle.cpp b/tests/auto/qgeocircle/tst_qgeocircle.cpp index 01fbed6b..8777e7d9 100644 --- a/tests/auto/qgeocircle/tst_qgeocircle.cpp +++ b/tests/auto/qgeocircle/tst_qgeocircle.cpp @@ -60,8 +60,11 @@ private slots: void contains_data(); void contains(); - void extendShape(); - void extendShape_data(); + void boundingGeoRectangle_data(); + void boundingGeoRectangle(); + + void extendCircle(); + void extendCircle_data(); void areaComparison(); void areaComparison_data(); @@ -243,7 +246,7 @@ void tst_QGeoCircle::valid() QCOMPARE(c.isValid(), valid); QGeoShape area = c; - QCOMPARE(c.isValid(), valid); + QCOMPARE(area.isValid(), valid); } void tst_QGeoCircle::empty_data() @@ -281,7 +284,7 @@ void tst_QGeoCircle::contains_data() QTest::addColumn<QGeoCoordinate>("probe"); QTest::addColumn<bool>("result"); - QTest::newRow("own centre") << QGeoCoordinate(1,1) << qreal(100.0) << + QTest::newRow("own center") << QGeoCoordinate(1,1) << qreal(100.0) << QGeoCoordinate(1,1) << true; QTest::newRow("over the hills") << QGeoCoordinate(1,1) << qreal(100.0) << QGeoCoordinate(30, 40) << false; @@ -291,6 +294,7 @@ void tst_QGeoCircle::contains_data() QGeoCoordinate(1.00077538, 0.99955527) << true; QTest::newRow("at 1.01*radius") << QGeoCoordinate(1,1) << qreal(100.0) << QGeoCoordinate(1.00071413, 0.99943423) << false; + // TODO: add tests for edge circle cases: cross 1 pole, cross both poles } void tst_QGeoCircle::contains() @@ -307,7 +311,39 @@ void tst_QGeoCircle::contains() QCOMPARE(area.contains(probe), result); } -void tst_QGeoCircle::extendShape() +void tst_QGeoCircle::boundingGeoRectangle_data() +{ + QTest::addColumn<QGeoCoordinate>("center"); + QTest::addColumn<qreal>("radius"); + QTest::addColumn<QGeoCoordinate>("probe"); + QTest::addColumn<bool>("result"); + + QTest::newRow("own center") << QGeoCoordinate(1,1) << qreal(100.0) << + QGeoCoordinate(1,1) << true; + QTest::newRow("over the hills") << QGeoCoordinate(1,1) << qreal(100.0) << + QGeoCoordinate(30, 40) << false; + QTest::newRow("at 0.5*radius") << QGeoCoordinate(1,1) << qreal(100.0) << + QGeoCoordinate(1.00015374,1.00015274) << true; + QTest::newRow("at 0.99*radius") << QGeoCoordinate(1,1) << qreal(100.0) << + QGeoCoordinate(1.00077538, 0.99955527) << true; + QTest::newRow("Outside the box") << QGeoCoordinate(1,1) << qreal(100.0) << + QGeoCoordinate(1.00071413, 0.99903423) << false; + // TODO: add tests for edge circle cases: cross 1 pole, cross both poles +} + +void tst_QGeoCircle::boundingGeoRectangle() +{ + QFETCH(QGeoCoordinate, center); + QFETCH(qreal, radius); + QFETCH(QGeoCoordinate, probe); + QFETCH(bool, result); + + QGeoCircle c(center, radius); + QGeoRectangle box = c.boundingGeoRectangle(); + QCOMPARE(box.contains(probe), result); +} + +void tst_QGeoCircle::extendCircle() { QFETCH(QGeoCircle, circle); QFETCH(QGeoCoordinate, coord); @@ -315,12 +351,12 @@ void tst_QGeoCircle::extendShape() QFETCH(bool, containsExtended); QCOMPARE(circle.contains(coord), containsFirst); - circle.extendShape(coord); + circle.extendCircle(coord); QCOMPARE(circle.contains(coord), containsExtended); } -void tst_QGeoCircle::extendShape_data() +void tst_QGeoCircle::extendCircle_data() { QTest::addColumn<QGeoCircle>("circle"); QTest::addColumn<QGeoCoordinate>("coord"); diff --git a/tests/auto/qgeocoordinate/tst_qgeocoordinate.cpp b/tests/auto/qgeocoordinate/tst_qgeocoordinate.cpp index fa9fd5c5..1b30f647 100644 --- a/tests/auto/qgeocoordinate/tst_qgeocoordinate.cpp +++ b/tests/auto/qgeocoordinate/tst_qgeocoordinate.cpp @@ -894,16 +894,17 @@ private slots: QTest::addColumn<int>("nextValue"); QTest::addColumn<QByteArray>("debugString"); - QTest::newRow("uninitialized") << QGeoCoordinate() << 45 << QByteArray("QGeoCoordinate(?, ?) 45"); QTest::newRow("initialized without altitude") << BRISBANE << 45 - << (QString("QGeoCoordinate(%1, %2) 45").arg(BRISBANE.latitude()) - .arg(BRISBANE.longitude())).toLatin1(); + << (QString("QGeoCoordinate(%1, %2) 45").arg(BRISBANE.latitude(), 0, 'g', 9) + .arg(BRISBANE.longitude(), 0, 'g', 9)).toLatin1(); QTest::newRow("invalid initialization") << QGeoCoordinate(-100,-200) << 45 << QByteArray("QGeoCoordinate(?, ?) 45"); QTest::newRow("initialized with altitude") << QGeoCoordinate(1,2,3) << 45 << QByteArray("QGeoCoordinate(1, 2, 3) 45"); + QTest::newRow("extra long coordinates") << QGeoCoordinate(89.123412341, 179.123412341) + << 45 << QByteArray("QGeoCoordinate(89.123412341, 179.12341234) 45"); } void hash() diff --git a/tests/auto/qgeopath/qgeopath.pro b/tests/auto/qgeopath/qgeopath.pro new file mode 100644 index 00000000..eec05974 --- /dev/null +++ b/tests/auto/qgeopath/qgeopath.pro @@ -0,0 +1,8 @@ +TEMPLATE = app +CONFIG += testcase +TARGET = tst_qgeopath + +SOURCES += \ + tst_qgeopath.cpp + +QT += positioning testlib diff --git a/tests/auto/qgeopath/tst_qgeopath.cpp b/tests/auto/qgeopath/tst_qgeopath.cpp new file mode 100644 index 00000000..8c4ac767 --- /dev/null +++ b/tests/auto/qgeopath/tst_qgeopath.cpp @@ -0,0 +1,385 @@ +/**************************************************************************** +** +** 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 <QtTest/QtTest> +#include <QtPositioning/QGeoCoordinate> +#include <QtPositioning/QGeoRectangle> +#include <QtPositioning/QGeoPath> + +QT_USE_NAMESPACE + +class tst_QGeoPath : public QObject +{ + Q_OBJECT + +private slots: + void defaultConstructor(); + void listConstructor(); + void assignment(); + + void comparison(); + void type(); + + void path(); + void width(); + + void translate_data(); + void translate(); + + void valid_data(); + void valid(); + + void contains_data(); + void contains(); + + void boundingGeoRectangle_data(); + void boundingGeoRectangle(); + + void extendShape(); + void extendShape_data(); +}; + +void tst_QGeoPath::defaultConstructor() +{ + QGeoPath p; + QVERIFY(!p.path().size()); + QCOMPARE(p.width(), qreal(0.0)); +} + +void tst_QGeoPath::listConstructor() +{ + QList<QGeoCoordinate> coords; + coords.append(QGeoCoordinate(1,1)); + coords.append(QGeoCoordinate(2,2)); + coords.append(QGeoCoordinate(3,0)); + + QGeoPath p(coords, 1.0); + QCOMPARE(p.width(), qreal(1.0)); + QCOMPARE(p.path().size(), 3); + + for (const QGeoCoordinate &c : coords) { + QCOMPARE(p.path().contains(c), true); + } +} + +void tst_QGeoPath::assignment() +{ + QGeoPath p1; + QList<QGeoCoordinate> coords; + coords.append(QGeoCoordinate(1,1)); + coords.append(QGeoCoordinate(2,2)); + coords.append(QGeoCoordinate(3,0)); + QGeoPath p2(coords, 1.0); + + QVERIFY(p1 != p2); + + p1 = p2; + QCOMPARE(p1.path(), coords); + QCOMPARE(p1.width(), 1.0); + QCOMPARE(p1, p2); + + // Assign c1 to an area + QGeoShape area = p1; + QCOMPARE(area.type(), p1.type()); + QVERIFY(area == p1); + + // Assign the area back to a bounding circle + QGeoPath p3 = area; + QCOMPARE(p3.path(), coords); + QCOMPARE(p3.width(), 1.0); + + // Check that the copy is not modified when modifying the original. + p1.setWidth(2.0); + QVERIFY(p3.width() != p1.width()); + QVERIFY(p3 != p1); +} + +void tst_QGeoPath::comparison() +{ + QList<QGeoCoordinate> coords; + coords.append(QGeoCoordinate(1,1)); + coords.append(QGeoCoordinate(2,2)); + coords.append(QGeoCoordinate(3,0)); + QList<QGeoCoordinate> coords2; + coords2.append(QGeoCoordinate(3,1)); + coords2.append(QGeoCoordinate(4,2)); + coords2.append(QGeoCoordinate(3,0)); + QGeoPath c1(coords, qreal(50.0)); + QGeoPath c2(coords, qreal(50.0)); + QGeoPath c3(coords, qreal(35.0)); + QGeoPath c4(coords2, qreal(50.0)); + + QVERIFY(c1 == c2); + QVERIFY(!(c1 != c2)); + + QVERIFY(!(c1 == c3)); + QVERIFY(c1 != c3); + + QVERIFY(!(c1 == c4)); + QVERIFY(c1 != c4); + + QVERIFY(!(c2 == c3)); + QVERIFY(c2 != c3); + + QGeoRectangle b1(QGeoCoordinate(20,20),QGeoCoordinate(10,30)); + QVERIFY(!(c1 == b1)); + QVERIFY(c1 != b1); + + QGeoShape *c2Ptr = &c2; + QVERIFY(c1 == *c2Ptr); + QVERIFY(!(c1 != *c2Ptr)); + + QGeoShape *c3Ptr = &c3; + QVERIFY(!(c1 == *c3Ptr)); + QVERIFY(c1 != *c3Ptr); +} + +void tst_QGeoPath::type() +{ + QGeoPath c; + QCOMPARE(c.type(), QGeoShape::PathType); +} + +void tst_QGeoPath::path() +{ + QList<QGeoCoordinate> coords; + coords.append(QGeoCoordinate(1,1)); + coords.append(QGeoCoordinate(2,2)); + coords.append(QGeoCoordinate(3,0)); + + QGeoPath p; + p.setPath(coords); + QCOMPARE(p.path().size(), 3); + + for (const QGeoCoordinate &c : coords) { + QCOMPARE(p.path().contains(c), true); + } +} + +void tst_QGeoPath::width() +{ + QGeoPath p; + p.setWidth(10.0); + QCOMPARE(p.width(), qreal(10.0)); +} + +void tst_QGeoPath::translate_data() +{ + QTest::addColumn<QGeoCoordinate>("c1"); + QTest::addColumn<QGeoCoordinate>("c2"); + QTest::addColumn<QGeoCoordinate>("c3"); + QTest::addColumn<double>("lat"); + QTest::addColumn<double>("lon"); + + QTest::newRow("Simple") << QGeoCoordinate(1,1) << QGeoCoordinate(2,2) << + QGeoCoordinate(3,0) << 5.0 << 4.0; + QTest::newRow("Backward") << QGeoCoordinate(1,1) << QGeoCoordinate(2,2) << + QGeoCoordinate(3,0) << -5.0 << -4.0; +} + +void tst_QGeoPath::translate() +{ + QFETCH(QGeoCoordinate, c1); + QFETCH(QGeoCoordinate, c2); + QFETCH(QGeoCoordinate, c3); + QFETCH(double, lat); + QFETCH(double, lon); + + QList<QGeoCoordinate> coords; + coords.append(c1); + coords.append(c2); + coords.append(c3); + QGeoPath p(coords); + + p.translate(lat, lon); + + for (int i = 0; i < p.path().size(); i++) { + QCOMPARE(coords[i].latitude(), p.path()[i].latitude() - lat ); + QCOMPARE(coords[i].longitude(), p.path()[i].longitude() - lon ); + } +} + +void tst_QGeoPath::valid_data() +{ + QTest::addColumn<QGeoCoordinate>("c1"); + QTest::addColumn<QGeoCoordinate>("c2"); + QTest::addColumn<QGeoCoordinate>("c3"); + QTest::addColumn<qreal>("width"); + QTest::addColumn<bool>("valid"); + + QTest::newRow("empty coords") << QGeoCoordinate() << QGeoCoordinate() << QGeoCoordinate() << qreal(5.0) << false; + QTest::newRow("invalid coord") << QGeoCoordinate(50, 50) << QGeoCoordinate(60, 60) << QGeoCoordinate(700, 700) << qreal(5.0) << false; + QTest::newRow("bad width") << QGeoCoordinate(10, 10) << QGeoCoordinate(11, 11) << QGeoCoordinate(10, 12) << qreal(-5.0) << true; + QTest::newRow("NaN width") << QGeoCoordinate(10, 10) << QGeoCoordinate(11, 11) << QGeoCoordinate(10, 12) << qreal(qQNaN()) << true; + QTest::newRow("zero width") << QGeoCoordinate(10, 10) << QGeoCoordinate(11, 11) << QGeoCoordinate(10, 12) << qreal(0) << true; + QTest::newRow("good") << QGeoCoordinate(10, 10) << QGeoCoordinate(11, 11) << QGeoCoordinate(10, 12) << qreal(5) << true; +} + +void tst_QGeoPath::valid() +{ + QFETCH(QGeoCoordinate, c1); + QFETCH(QGeoCoordinate, c2); + QFETCH(QGeoCoordinate, c3); + QFETCH(qreal, width); + QFETCH(bool, valid); + + QList<QGeoCoordinate> coords; + coords.append(c1); + coords.append(c2); + coords.append(c3); + QGeoPath p(coords, width); + + QCOMPARE(p.isValid(), valid); + + QGeoShape area = p; + QCOMPARE(area.isValid(), valid); +} + +void tst_QGeoPath::contains_data() +{ + QTest::addColumn<QGeoCoordinate>("c1"); + QTest::addColumn<QGeoCoordinate>("c2"); + QTest::addColumn<QGeoCoordinate>("c3"); + QTest::addColumn<qreal>("width"); + QTest::addColumn<QGeoCoordinate>("probe"); + QTest::addColumn<bool>("result"); + + QList<QGeoCoordinate> c; + c.append(QGeoCoordinate(1,1)); + c.append(QGeoCoordinate(2,2)); + c.append(QGeoCoordinate(3,0)); + + QTest::newRow("One of the points") << c[0] << c[1] << c[2] << 0.0 << QGeoCoordinate(2, 2) << true; + QTest::newRow("Not so far away") << c[0] << c[1] << c[2] << 0.0 << QGeoCoordinate(0, 0) << false; + QTest::newRow("Not so far away and large line") << c[0] << c[1] << c[2] << 100000.0 << QGeoCoordinate(0, 0) << true; +} + +void tst_QGeoPath::contains() +{ + QFETCH(QGeoCoordinate, c1); + QFETCH(QGeoCoordinate, c2); + QFETCH(QGeoCoordinate, c3); + QFETCH(qreal, width); + QFETCH(QGeoCoordinate, probe); + QFETCH(bool, result); + + QList<QGeoCoordinate> coords; + coords.append(c1); + coords.append(c2); + coords.append(c3); + QGeoPath p(coords, width); + + QCOMPARE(p.contains(probe), result); + + QGeoShape area = p; + QCOMPARE(area.contains(probe), result); +} + +void tst_QGeoPath::boundingGeoRectangle_data() +{ + QTest::addColumn<QGeoCoordinate>("c1"); + QTest::addColumn<QGeoCoordinate>("c2"); + QTest::addColumn<QGeoCoordinate>("c3"); + QTest::addColumn<qreal>("width"); + QTest::addColumn<QGeoCoordinate>("probe"); + QTest::addColumn<bool>("result"); + + QList<QGeoCoordinate> c; + c.append(QGeoCoordinate(1,1)); + c.append(QGeoCoordinate(2,2)); + c.append(QGeoCoordinate(3,0)); + + QTest::newRow("One of the points") << c[0] << c[1] << c[2] << 0.0 << QGeoCoordinate(2, 2) << true; + QTest::newRow("Not so far away") << c[0] << c[1] << c[2] << 0.0 << QGeoCoordinate(0, 0) << false; + QTest::newRow("Inside the bounds") << c[0] << c[1] << c[2] << 100.0 << QGeoCoordinate(1, 0) << true; + QTest::newRow("Inside the bounds") << c[0] << c[1] << c[2] << 100.0 << QGeoCoordinate(1.1, 0.1) << true; +} + +void tst_QGeoPath::boundingGeoRectangle() +{ + QFETCH(QGeoCoordinate, c1); + QFETCH(QGeoCoordinate, c2); + QFETCH(QGeoCoordinate, c3); + QFETCH(qreal, width); + QFETCH(QGeoCoordinate, probe); + QFETCH(bool, result); + + QList<QGeoCoordinate> coords; + coords.append(c1); + coords.append(c2); + coords.append(c3); + QGeoPath p(coords, width); + + QGeoRectangle box = p.boundingGeoRectangle(); + QCOMPARE(box.contains(probe), result); +} + +void tst_QGeoPath::extendShape() +{ + QFETCH(QGeoCoordinate, c1); + QFETCH(QGeoCoordinate, c2); + QFETCH(QGeoCoordinate, c3); + QFETCH(qreal, width); + QFETCH(QGeoCoordinate, probe); + QFETCH(bool, before); + QFETCH(bool, after); + + QList<QGeoCoordinate> coords; + coords.append(c1); + coords.append(c2); + coords.append(c3); + QGeoPath p(coords, width); + + + QCOMPARE(p.contains(probe), before); + p.extendShape(probe); + QCOMPARE(p.contains(probe), after); +} + +void tst_QGeoPath::extendShape_data() +{ + QTest::addColumn<QGeoCoordinate>("c1"); + QTest::addColumn<QGeoCoordinate>("c2"); + QTest::addColumn<QGeoCoordinate>("c3"); + QTest::addColumn<qreal>("width"); + QTest::addColumn<QGeoCoordinate>("probe"); + QTest::addColumn<bool>("before"); + QTest::addColumn<bool>("after"); + + QList<QGeoCoordinate> c; + c.append(QGeoCoordinate(1,1)); + c.append(QGeoCoordinate(2,2)); + c.append(QGeoCoordinate(3,0)); + + QTest::newRow("One of the points") << c[0] << c[1] << c[2] << 0.0 << QGeoCoordinate(2, 2) << true << true; + QTest::newRow("Not so far away") << c[0] << c[1] << c[2] << 0.0 << QGeoCoordinate(0, 0) << false << true; + QTest::newRow("Not so far away and large line") << c[0] << c[1] << c[2] << 100000.0 << QGeoCoordinate(0, 0) << true << true; +} + +QTEST_MAIN(tst_QGeoPath) +#include "tst_qgeopath.moc" diff --git a/tests/auto/qgeorectangle/tst_qgeorectangle.cpp b/tests/auto/qgeorectangle/tst_qgeorectangle.cpp index 71a3765a..01f0104b 100644 --- a/tests/auto/qgeorectangle/tst_qgeorectangle.cpp +++ b/tests/auto/qgeorectangle/tst_qgeorectangle.cpp @@ -71,6 +71,9 @@ private slots: void center(); void center_data(); + void boundingGeoRectangle(); + void boundingGeoRectangle_data(); + void containsCoord(); void containsCoord_data(); @@ -83,8 +86,8 @@ private slots: void unite(); void unite_data(); - void extendShape(); - void extendShape_data(); + void extendRectangle(); + void extendRectangle_data(); void areaComparison(); void areaComparison_data(); @@ -957,6 +960,28 @@ void tst_QGeoRectangle::center_data() QGeoCoordinate(-90.0, -170.0)); } +void tst_QGeoRectangle::boundingGeoRectangle_data() +{ + QTest::addColumn<QGeoRectangle>("rectangle"); + + QGeoRectangle b1(QGeoCoordinate(70, 30), QGeoCoordinate(30, 70)); + QGeoRectangle b2(QGeoCoordinate(70, 150), QGeoCoordinate(30, -170)); + QGeoRectangle b3(QGeoCoordinate(90, 30), QGeoCoordinate(50, 70)); + QGeoRectangle b4(QGeoCoordinate(-50, 30), QGeoCoordinate(-90, 70)); + + QTest::newRow("Box 1") << b1; + QTest::newRow("Box 2") << b2; + QTest::newRow("Box 3") << b3; + QTest::newRow("Box 4") << b4; +} + +void tst_QGeoRectangle::boundingGeoRectangle() +{ + QFETCH(QGeoRectangle, rectangle); + + QGeoRectangle box = rectangle.boundingGeoRectangle(); + QCOMPARE(box, rectangle); +} void tst_QGeoRectangle::containsCoord() { @@ -1769,14 +1794,14 @@ void tst_QGeoRectangle::translate_data() << 20.0 << 20.0 << QGeoRectangle(QGeoCoordinate(90.0, -10.0), - QGeoCoordinate(40.0, 50.0)); + QGeoCoordinate(30.0, 50.0)); QTest::newRow("non wrapping -> south clip") << QGeoRectangle(QGeoCoordinate(-20.0, -30.0), QGeoCoordinate(-80.0, 30.0)) << -20.0 << 20.0 - << QGeoRectangle(QGeoCoordinate(-40.0, -10.0), + << QGeoRectangle(QGeoCoordinate(-30.0, -10.0), QGeoCoordinate(-90.0, 50.0)); QTest::newRow("wrapping -> non wrapping") @@ -1801,14 +1826,14 @@ void tst_QGeoRectangle::translate_data() << 20.0 << 20.0 << QGeoRectangle(QGeoCoordinate(90.0, 150.0), - QGeoCoordinate(40.0, -150.0)); + QGeoCoordinate(30.0, -150.0)); QTest::newRow("wrapping -> south clip") << QGeoRectangle(QGeoCoordinate(-20.0, 130.0), QGeoCoordinate(-80.0, -170.0)) << -20.0 << 20.0 - << QGeoRectangle(QGeoCoordinate(-40.0, 150.0), + << QGeoRectangle(QGeoCoordinate(-30.0, 150.0), QGeoCoordinate(-90.0, -150.0)); } @@ -2201,17 +2226,17 @@ void tst_QGeoRectangle::unite_data() } -void tst_QGeoRectangle::extendShape() +void tst_QGeoRectangle::extendRectangle() { QFETCH(QGeoRectangle, box); QFETCH(QGeoCoordinate, coord); QFETCH(QGeoRectangle, out); - box.extendShape(coord); + box.extendRectangle(coord); QCOMPARE(box, out); } -void tst_QGeoRectangle::extendShape_data() +void tst_QGeoRectangle::extendRectangle_data() { QTest::addColumn<QGeoRectangle>("box"); QTest::addColumn<QGeoCoordinate>("coord"); diff --git a/tests/auto/qgeoroutereply/tst_qgeoroutereply.cpp b/tests/auto/qgeoroutereply/tst_qgeoroutereply.cpp index 447181f2..de406b40 100644 --- a/tests/auto/qgeoroutereply/tst_qgeoroutereply.cpp +++ b/tests/auto/qgeoroutereply/tst_qgeoroutereply.cpp @@ -197,7 +197,7 @@ void tst_QGeoRouteReply::abort() reply->abort(); QCOMPARE(signalerror->count(), 0); - QCOMPARE(signalfinished->count(), 1); + QCOMPARE(signalfinished->count(), 0); } void tst_QGeoRouteReply::error() diff --git a/tests/auto/qgeoserviceprovider/tst_qgeoserviceprovider.cpp b/tests/auto/qgeoserviceprovider/tst_qgeoserviceprovider.cpp index 7303e431..6efa2f92 100644 --- a/tests/auto/qgeoserviceprovider/tst_qgeoserviceprovider.cpp +++ b/tests/auto/qgeoserviceprovider/tst_qgeoserviceprovider.cpp @@ -69,7 +69,7 @@ void tst_QGeoServiceProvider::tst_availableServiceProvider() // Currently provided plugins if (provider.count() != 8) qWarning() << provider; - QCOMPARE(provider.count(), 8); + QVERIFY(provider.count() >= 8); // these providers are deployed QVERIFY(provider.contains(QStringLiteral("mapbox"))); QVERIFY(provider.contains(QStringLiteral("here"))); diff --git a/tests/auto/qgeotiledmap/tst_qgeotiledmap.cpp b/tests/auto/qgeotiledmap/tst_qgeotiledmap.cpp index 480e7d60..ae0083ba 100644 --- a/tests/auto/qgeotiledmap/tst_qgeotiledmap.cpp +++ b/tests/auto/qgeotiledmap/tst_qgeotiledmap.cpp @@ -37,6 +37,7 @@ #include <QtCore/QString> #include <QtTest/QtTest> #include <QtTest/QSignalSpy> +#include <QtPositioning/private/qwebmercator_p.h> #include <QtLocation/QGeoServiceProvider> #include <QtLocation/private/qgeotiledmap_p.h> #include <QtLocation/private/qgeomappingmanager_p.h> @@ -102,7 +103,7 @@ void tst_QGeoTiledMap::initTestCase() #endif #endif QVariantMap parameters; - parameters["tileSize"] = 16; + parameters["tileSize"] = 256; parameters["maxZoomLevel"] = 8; parameters["finishRequestImmediately"] = true; QGeoServiceProvider *provider = new QGeoServiceProvider("qmlgeo.test.plugin",parameters); @@ -111,7 +112,7 @@ void tst_QGeoTiledMap::initTestCase() QVERIFY2(provider->error() == QGeoServiceProvider::NoError, "Could not load plugin: " + provider->errorString().toLatin1()); m_map.reset(static_cast<QGeoTiledMapTest*>(mappingManager->createMap(this))); QVERIFY(m_map); - m_map->setViewportSize(QSize(16, 16)); + m_map->setViewportSize(QSize(256, 256)); m_fetcher = static_cast<QGeoTileFetcherTest*>(m_map->m_engine->tileFetcher()); m_tilesCounter.reset(new FetchTileCounter()); connect(m_fetcher, SIGNAL(tileFetched(const QGeoTileSpec&)), m_tilesCounter.data(), SLOT(tileFetched(const QGeoTileSpec&))); @@ -128,7 +129,7 @@ void tst_QGeoTiledMap::fetchTiles() m_map->setPrefetchStyle(style); QGeoCameraData camera; - camera.setCenter(QGeoProjection::mercatorToCoord(QDoubleVector2D( 0.5 , 0.5 ))); + camera.setCenter(QWebMercator::mercatorToCoord(QDoubleVector2D( 0.5 , 0.5 ))); //prev_visible camera.setZoomLevel(zoomLevel-1); diff --git a/tests/auto/qgeotiledmapscene/qgeotiledmapscene.pro b/tests/auto/qgeotiledmapscene/qgeotiledmapscene.pro index c3ec6e91..0db4b544 100644 --- a/tests/auto/qgeotiledmapscene/qgeotiledmapscene.pro +++ b/tests/auto/qgeotiledmapscene/qgeotiledmapscene.pro @@ -5,4 +5,4 @@ INCLUDEPATH += ../../../src/location/maps SOURCES += tst_qgeotiledmapscene.cpp -QT += location positioning-private testlib +QT += location-private positioning-private testlib diff --git a/tests/auto/qgeotiledmapscene/tst_qgeotiledmapscene.cpp b/tests/auto/qgeotiledmapscene/tst_qgeotiledmapscene.cpp index 3d43ebd8..6b3dc1f6 100644 --- a/tests/auto/qgeotiledmapscene/tst_qgeotiledmapscene.cpp +++ b/tests/auto/qgeotiledmapscene/tst_qgeotiledmapscene.cpp @@ -33,8 +33,8 @@ #include "qgeocameratiles_p.h" #include "qgeocameradata_p.h" #include "qabstractgeotilecache_p.h" - -#include <QtPositioning/private/qgeoprojection_p.h> +#include <QtLocation/private/qgeoprojection_p.h> +#include <QtPositioning/private/qwebmercator_p.h> #include <QtPositioning/private/qdoublevector2d_p.h> #include <qtest.h> @@ -52,7 +52,7 @@ class tst_QGeoTiledMapScene : public QObject Q_OBJECT private: - void row(QString name, double screenX, double screenY, double cameraCenterX, double cameraCenterY, + void row(QString name, double screenX, double screenX2, double screenY, double cameraCenterX, double cameraCenterY, double zoom, int tileSize, int screenWidth, int screenHeight, double mercatorX, double mercatorY){ // expected behaviour of wrapping @@ -62,7 +62,7 @@ class tst_QGeoTiledMapScene : public QObject mercatorX -= 1.0; QTest::newRow(qPrintable(name)) - << screenX << screenY + << screenX << screenX2 << screenY << cameraCenterX << cameraCenterY << zoom << tileSize << screenWidth << screenHeight @@ -74,6 +74,7 @@ class tst_QGeoTiledMapScene : public QObject int tileSize, int screenWidth, int screenHeight) { double screenX; + double screenX2; double screenY; double mercatorX; double mercatorY; @@ -84,76 +85,92 @@ class tst_QGeoTiledMapScene : public QObject double scaledHalfLengthX = halfLength * scaleX; double scaledHalfLengthY = halfLength * scaleY; - // top left - screenX = 0.0; + bool matchingMapEnds = false; + if (screenWidth == std::pow(2.0, zoom) * tileSize) + matchingMapEnds = true; + + // bottom left + screenX = screenX2 = 0.0; + if (matchingMapEnds) + screenX2 = qAbs(screenX - 1.0) * screenWidth; screenY = 1.0 * screenHeight; mercatorX = cameraCenterX - scaledHalfLengthX; mercatorY = cameraCenterY + scaledHalfLengthY; - row (name + QString("_topLeftScreen"), screenX, screenY, cameraCenterX, cameraCenterY, + row (name + QString("_bottomLeftScreen"), screenX, screenX2, screenY, cameraCenterX, cameraCenterY, zoom, tileSize, screenWidth, screenHeight, mercatorX, mercatorY); - // top - screenX = 0.5 * screenWidth; + // bottom + screenX = screenX2 = 0.5 * screenWidth; screenY = 1.0 * screenHeight; mercatorX = cameraCenterX; mercatorY = cameraCenterY + scaledHalfLengthY; - row (name + QString("_topScreen"), screenX, screenY, cameraCenterX, cameraCenterY, + row (name + QString("_bottomScreen"), screenX, screenX2, screenY, cameraCenterX, cameraCenterY, zoom, tileSize, screenWidth, screenHeight, mercatorX, mercatorY); - // top right - screenX = 1.0 * screenWidth; + // bottom right + screenX = screenX2 = 1.0 * screenWidth; + if (matchingMapEnds) + screenX2 = qAbs(screenX - 1.0) * screenWidth; screenY = 1.0 * screenHeight; mercatorX = cameraCenterX + scaledHalfLengthX; mercatorY = cameraCenterY + scaledHalfLengthY; - row (name + QString("_topRightScreen"), screenX, screenY, cameraCenterX, cameraCenterY, + row (name + QString("_bottomRightScreen"), screenX, screenX2, screenY, cameraCenterX, cameraCenterY, zoom, tileSize, screenWidth, screenHeight, mercatorX, mercatorY); // left - screenX = 0.0 * screenWidth; + screenX = screenX2 = 0.0 * screenWidth; + if (matchingMapEnds) + screenX2 = qAbs(screenX - 1.0) * screenWidth; screenY = 0.5 * screenHeight; mercatorX = cameraCenterX - scaledHalfLengthX; mercatorY = cameraCenterY; - row (name + QString("_leftScreen"), screenX, screenY, cameraCenterX, cameraCenterY, + row (name + QString("_leftScreen"), screenX, screenX2, screenY, cameraCenterX, cameraCenterY, zoom, tileSize, screenWidth, screenHeight, mercatorX, mercatorY); // center - screenX = 0.5 * screenWidth; + screenX = screenX2 = 0.5 * screenWidth; screenY = 0.5 * screenHeight; mercatorX = cameraCenterX; mercatorY = cameraCenterY; - row (name + QString("_centerScreen"), screenX, screenY, cameraCenterX, cameraCenterY, + row (name + QString("_centerScreen"), screenX, screenX2, screenY, cameraCenterX, cameraCenterY, zoom, tileSize, screenWidth, screenHeight, mercatorX, mercatorY); // right - screenX = 1.0 * screenWidth; + screenX = screenX2 = 1.0 * screenWidth; + if (matchingMapEnds) + screenX2 = qAbs(screenX - 1.0) * screenWidth; screenY = 0.5 * screenHeight; mercatorX = cameraCenterX + scaledHalfLengthX; mercatorY = cameraCenterY; - row (name + QString("_rightScreen"), screenX, screenY, cameraCenterX, cameraCenterY, + row (name + QString("_rightScreen"), screenX, screenX2, screenY, cameraCenterX, cameraCenterY, zoom, tileSize, screenWidth, screenHeight, mercatorX, mercatorY); - // bottom left - screenX = 0.0; + // top left + screenX = screenX2 = 0.0; + if (matchingMapEnds) + screenX2 = qAbs(screenX - 1.0) * screenWidth; screenY = 0.0; mercatorX = cameraCenterX - scaledHalfLengthX; mercatorY = cameraCenterY - scaledHalfLengthY; - row (name + QString("_bottomLeftrScreen"), screenX, screenY, cameraCenterX, cameraCenterY, + row (name + QString("_topLeftScreen"), screenX, screenX2, screenY, cameraCenterX, cameraCenterY, zoom, tileSize, screenWidth, screenHeight, mercatorX, mercatorY); - // bottom - screenX = 0.5 * screenWidth; + // top + screenX = screenX2 = 0.5 * screenWidth; screenY = 0.0; mercatorX = cameraCenterX; mercatorY = cameraCenterY - scaledHalfLengthY; - row (name + QString("_bottomScreen"), screenX, screenY, cameraCenterX, cameraCenterY, + row (name + QString("_topScreen"), screenX, screenX2, screenY, cameraCenterX, cameraCenterY, zoom, tileSize, screenWidth, screenHeight, mercatorX, mercatorY); - // bottom right - screenX = 1.0 * screenWidth; + // top right + screenX = screenX2 = 1.0 * screenWidth; + if (matchingMapEnds) + screenX2 = qAbs(screenX - 1.0) * screenWidth; screenY = 0.0; mercatorX = cameraCenterX + scaledHalfLengthX; mercatorY = cameraCenterY - scaledHalfLengthY; - row (name + QString("_bottomRightScreen"), screenX, screenY, cameraCenterX, cameraCenterY, + row (name + QString("_topRightScreen"), screenX, screenX2, screenY, cameraCenterX, cameraCenterY, zoom, tileSize, screenWidth, screenHeight, mercatorX, mercatorY); } @@ -164,21 +181,21 @@ class tst_QGeoTiledMapScene : public QObject double cameraCenterX; double cameraCenterY; - // top left + // bottom left cameraCenterX = 0; cameraCenterY = 1.0; - screenPositions(name + QString("_topLeftCamera"), cameraCenterX, cameraCenterY, + screenPositions(name + QString("_bottomLeftCamera"), cameraCenterX, cameraCenterY, zoom, tileSize, screenWidth, screenHeight); - // top + // bottom cameraCenterX = 0.5; cameraCenterY = 1.0; - screenPositions(name + QString("_topCamera"), cameraCenterX, cameraCenterY, + screenPositions(name + QString("_bottomCamera"), cameraCenterX, cameraCenterY, zoom, tileSize, screenWidth, screenHeight); - // top right + // bottom right cameraCenterX = 1.0; cameraCenterY = 1.0; - screenPositions(name + QString("_topRightCamera"), cameraCenterX, cameraCenterY, + screenPositions(name + QString("_bottomRightCamera"), cameraCenterX, cameraCenterY, zoom, tileSize, screenWidth, screenHeight); // left cameraCenterX = 0.0; @@ -195,25 +212,26 @@ class tst_QGeoTiledMapScene : public QObject cameraCenterY = 0.5; screenPositions(name + QString("_rightCamera"), cameraCenterX, cameraCenterY, zoom, tileSize, screenWidth, screenHeight); - // bottom left + // top left cameraCenterX = 0.0; cameraCenterY = 0.0; - screenPositions(name + QString("_bottomLeftCamera"), cameraCenterX, cameraCenterY, + screenPositions(name + QString("_topLeftCamera"), cameraCenterX, cameraCenterY, zoom, tileSize, screenWidth, screenHeight); - // bottom + // top cameraCenterX = 0.5; cameraCenterY = 0.0; - screenPositions(name + QString("_bottomCamera"), cameraCenterX, cameraCenterY, + screenPositions(name + QString("_topCamera"), cameraCenterX, cameraCenterY, zoom, tileSize, screenWidth, screenHeight); - // bottom right + // top right cameraCenterX = 1.0; cameraCenterY = 0.0; - screenPositions(name + QString("_bottomRightCamera"), cameraCenterX, cameraCenterY, + screenPositions(name + QString("_topRightCamera"), cameraCenterX, cameraCenterY, zoom, tileSize, screenWidth, screenHeight); } void populateScreenMercatorData(){ QTest::addColumn<double>("screenX"); + QTest::addColumn<double>("screenX2"); QTest::addColumn<double>("screenY"); QTest::addColumn<double>("cameraCenterX"); QTest::addColumn<double>("cameraCenterY"); @@ -229,8 +247,8 @@ class tst_QGeoTiledMapScene : public QObject int screenWidth; int screenHeight; QString name; - tileSize = 16; - zoom = 4.0; + tileSize = 256; + zoom = 1.0; // 4 tiles in the map. map size = 2*tileSize x 2*tileSize /* ScreenWidth = t @@ -259,6 +277,7 @@ class tst_QGeoTiledMapScene : public QObject name = QString("_(2t x t)"); screenCameraPositions(name, zoom, tileSize, screenWidth, screenHeight); + /* Screen Width = t * 2 Screen Height = t * 2 @@ -269,38 +288,13 @@ class tst_QGeoTiledMapScene : public QObject screenCameraPositions(name, zoom, tileSize, screenWidth, screenHeight); } - private slots: - - void useVerticalLock(){ - QGeoCameraData camera; - camera.setZoomLevel(4.0); - camera.setCenter(QGeoProjection::mercatorToCoord(QDoubleVector2D(0.0, 0.0))); - - QGeoCameraTiles ct; - ct.setTileSize(16); - ct.setCameraData(camera); - ct.setScreenSize(QSize(16,16)); - - QGeoTiledMapScene mapScene; - mapScene.setTileSize(16); - mapScene.setScreenSize(QSize(16,16*32)); - mapScene.setCameraData(camera); - QVERIFY(!mapScene.verticalLock()); - mapScene.setUseVerticalLock(true); - mapScene.setVisibleTiles(ct.createTiles()); - QVERIFY(mapScene.verticalLock()); - - // Test the case when setting vertical lock has no effect - QGeoTiledMapScene mapScene2; - mapScene2.setTileSize(16); - mapScene2.setScreenSize(QSize(16,16)); - mapScene2.setCameraData(camera); - QVERIFY(!mapScene2.verticalLock()); - mapScene2.setUseVerticalLock(true); - mapScene2.setVisibleTiles(ct.createTiles()); - QVERIFY(!mapScene2.verticalLock()); - } + // Calculates the distance in mercator space of 2 x coordinates, assuming that 1 == 0 + double wrappedMercatorDistance(double x1, double x2) + { + return qMin(qMin(qAbs(x1 - 1.0 - x2), qAbs(x1 - x2)), qAbs(x1 + 1.0 - x2)); + } + private slots: void screenToMercatorPositions(){ QFETCH(double, screenX); QFETCH(double, screenY); @@ -315,7 +309,8 @@ class tst_QGeoTiledMapScene : public QObject QGeoCameraData camera; camera.setZoomLevel(zoom); - camera.setCenter(QGeoProjection::mercatorToCoord(QDoubleVector2D(cameraCenterX, cameraCenterY))); + QGeoCoordinate centerCoordinate = QWebMercator::mercatorToCoord(QDoubleVector2D(cameraCenterX, cameraCenterY)); + camera.setCenter(centerCoordinate); QGeoCameraTiles ct; ct.setTileSize(tileSize); @@ -328,11 +323,22 @@ class tst_QGeoTiledMapScene : public QObject mapGeometry.setCameraData(camera); mapGeometry.setVisibleTiles(ct.createTiles()); - QDoubleVector2D point(screenX,screenY); - QDoubleVector2D mecartorPos = mapGeometry.itemPositionToMercator(point); + QGeoProjectionWebMercator projection; + projection.setViewportSize(QSize(screenWidth,screenHeight)); + projection.setCameraData(camera); - QCOMPARE(mecartorPos.x(),mercatorX); - QCOMPARE(mecartorPos.y(),mercatorY); + QDoubleVector2D point(screenX,screenY); + QDoubleVector2D mercartorPos = projection.unwrapMapProjection(projection.itemPositionToWrappedMapProjection(point)); + + const double tolerance = 0.00000000001; // FuzzyCompare is too strict here + QVERIFY2(wrappedMercatorDistance(mercartorPos.x(), mercatorX) < tolerance, + qPrintable(QString("Accepted: %1 , Actual: %2") + .arg(QString::number(mercatorX)) + .arg(QString::number(mercartorPos.x())))); + QVERIFY2(qAbs(mercartorPos.y() - mercatorY) < tolerance, + qPrintable(QString("Accepted: %1 , Actual: %2") + .arg(QString::number(mercatorY)) + .arg(QString::number(mercartorPos.y())))); } void screenToMercatorPositions_data() @@ -342,6 +348,7 @@ class tst_QGeoTiledMapScene : public QObject void mercatorToScreenPositions(){ QFETCH(double, screenX); + QFETCH(double, screenX2); QFETCH(double, screenY); QFETCH(double, cameraCenterX); QFETCH(double, cameraCenterY); @@ -354,7 +361,8 @@ class tst_QGeoTiledMapScene : public QObject QGeoCameraData camera; camera.setZoomLevel(zoom); - camera.setCenter(QGeoProjection::mercatorToCoord(QDoubleVector2D(cameraCenterX, cameraCenterY))); + QGeoCoordinate coord = QWebMercator::mercatorToCoord(QDoubleVector2D(cameraCenterX, cameraCenterY)); + camera.setCenter(coord); QGeoCameraTiles ct; ct.setTileSize(tileSize); @@ -367,10 +375,18 @@ class tst_QGeoTiledMapScene : public QObject mapGeometry.setCameraData(camera); mapGeometry.setVisibleTiles(ct.createTiles()); + QGeoProjectionWebMercator projection; + projection.setViewportSize(QSize(screenWidth,screenHeight)); + projection.setCameraData(camera); + QDoubleVector2D mercatorPos(mercatorX, mercatorY); - QPointF point = mapGeometry.mercatorToItemPosition(mercatorPos).toPointF(); + QPointF point = projection.wrappedMapProjectionToItemPosition(projection.wrapMapProjection(mercatorPos)).toPointF(); - QCOMPARE(point.x(), screenX); + QVERIFY2((point.x() == screenX) || (point.x() == screenX2), + qPrintable(QString("Accepted: { %1 , %2 } Actual: %3") + .arg(QString::number(screenX)) + .arg(QString::number(screenX2)) + .arg(QString::number(point.x())))); QCOMPARE(point.y(), screenY); } diff --git a/tests/auto/qgeotilespec/qgeotilespec.pro b/tests/auto/qgeotilespec/qgeotilespec.pro index eb48aea6..87cec150 100644 --- a/tests/auto/qgeotilespec/qgeotilespec.pro +++ b/tests/auto/qgeotilespec/qgeotilespec.pro @@ -6,4 +6,4 @@ INCLUDEPATH += ../../../src/location/maps SOURCES += tst_qgeotilespec.cpp -QT += location testlib +QT += location-private testlib |