diff options
author | Aaron McCarthy <aaron.mccarthy@jollamobile.com> | 2013-12-18 15:15:58 +1000 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-02-11 01:02:51 +0100 |
commit | 334b9f3b0c4acb77db7254380c4a96cea6d589a8 (patch) | |
tree | eac101b47ec011783c050189ed8f3dbdef65d0e1 /tests | |
parent | 1e58cb04817a3ea6fbed45d5bbb9e6aea99b282d (diff) | |
download | qtlocation-334b9f3b0c4acb77db7254380c4a96cea6d589a8.tar.gz |
Fix declarative_ui tests.
Coordinates for map items located outside the view port cannot be
converted to and from screen coordinates. During tests pan the map so
that the items under tests are inside the view port.
Tests for panning the map and dragging map items were failing because
mapping between coordinates and screen position only works for visible
screen positions. The MouseAreas under test did not have
preventStealing set, which was causing the map to pan slightly prior to
item drag being detected.
Stop gesture detection for a touch point when the mouse is grabbed by a
child item.
Task-number: QTBUG-31797
Change-Id: I42a801d50c194c6fe9629f3b0de606b406ad8b8c
Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/declarative_ui/tst_map.qml | 10 | ||||
-rw-r--r-- | tests/auto/declarative_ui/tst_map_item.qml | 80 | ||||
-rw-r--r-- | tests/auto/declarative_ui/tst_map_item_details.qml | 19 | ||||
-rw-r--r-- | tests/auto/declarative_ui/tst_map_mouse.qml | 2 |
4 files changed, 83 insertions, 28 deletions
diff --git a/tests/auto/declarative_ui/tst_map.qml b/tests/auto/declarative_ui/tst_map.qml index 584b5a48..bf17a19f 100644 --- a/tests/auto/declarative_ui/tst_map.qml +++ b/tests/auto/declarative_ui/tst_map.qml @@ -67,6 +67,7 @@ Item { property variant coordinate2: QtPositioning.coordinate(12, 13) property variant coordinate3: QtPositioning.coordinate(50, 50, 0) property variant coordinate4: QtPositioning.coordinate(80, 80, 0) + property variant coordinate5: QtPositioning.coordinate(20, 180) property variant invalidCoordinate: QtPositioning.coordinate() property variant altitudelessCoordinate: QtPositioning.coordinate(50, 50) @@ -102,6 +103,15 @@ Item { map.center = coordinate2 compare(mapCenterSpy.count, 1) + // change center to dateline + mapCenterSpy.clear() + compare(mapCenterSpy.count, 0) + map.center = coordinate5 + compare(mapCenterSpy.count, 1) + compare(map.center, coordinate5) + + map.center = coordinate2 + verify(isNaN(map.center.altitude)); compare(map.center.longitude, 13) compare(map.center.latitude, 12) diff --git a/tests/auto/declarative_ui/tst_map_item.qml b/tests/auto/declarative_ui/tst_map_item.qml index 3afae572..80d5d132 100644 --- a/tests/auto/declarative_ui/tst_map_item.qml +++ b/tests/auto/declarative_ui/tst_map_item.qml @@ -99,7 +99,6 @@ Item { radius: 600000 MouseArea { anchors.fill: parent - onClicked: console.log('ext circle clicked') SignalSpy { id: extMapCircleClicked; target: parent; signalName: "clicked" } } } @@ -144,6 +143,7 @@ Item { id: preMapRectMa anchors.fill: parent drag.target: parent + preventStealing: true SignalSpy { id: preMapRectClicked; target: parent; signalName: "clicked" } SignalSpy { id: preMapRectActiveChanged; target: parent.drag; signalName: "activeChanged" } } @@ -159,11 +159,12 @@ Item { latitude: 10 longitude: 30 } - radius: 400000 + radius: 10000 MouseArea { id: preMapCircleMa anchors.fill: parent drag.target: parent + preventStealing: true SignalSpy { id: preMapCircleClicked; target: parent; signalName: "clicked" } SignalSpy { id: preMapCircleActiveChanged; target: parent.drag; signalName: "activeChanged" } } @@ -176,8 +177,10 @@ Item { MapQuickItem { id: preMapQuickItem MouseArea { + id: preMapQuickItemMa anchors.fill: parent drag.target: parent + preventStealing: true SignalSpy { id: preMapQuickItemClicked; target: parent; signalName: "clicked" } SignalSpy { id: preMapQuickItemActiveChanged; target: parent.drag; signalName: "activeChanged" } } @@ -258,30 +261,39 @@ Item { // precondition compare(preMapRectClicked.count, 0) compare(preMapCircleClicked.count, 0) + // click rect + map.center = preMapRect.topLeft var point = map.toScreenPosition(preMapRect.topLeft) mouseClick(map, point.x + 5, point.y + 5) compare(preMapRectClicked.count, 1) mouseClick(map, 1, 1) // no item hit compare(preMapRectClicked.count, 1) compare(preMapCircleClicked.count, 0) + // click circle, overlaps and is above rect - visualInspectionPoint() // marks good visual inspection point + map.center = preMapCircle.center point = map.toScreenPosition(preMapCircle.center) mouseClick(map, point.x - 5, point.y - 5) compare(preMapRectClicked.count, 1) compare(preMapCircleClicked.count, 1) + // click within circle bounding rect but not inside the circle geometry + map.center = preMapCircle.center.atDistanceAndAzimuth(preMapCircle.radius, -45) mouseClick(map, preMapCircle.x + 4, preMapCircle.y + 4) compare(preMapRectClicked.count, 2) compare(preMapCircleClicked.count, 1) + // click quick item compare(preMapQuickItemClicked.count, 0) + map.center = preMapQuickItem.coordinate point = map.toScreenPosition(preMapQuickItem.coordinate) mouseClick(map, point.x + 5, point.y + 5) compare(preMapQuickItemClicked.count, 1) + // click polygon compare (preMapPolygonClicked.count, 0) + map.center = preMapPolygon.path[1] point = map.toScreenPosition(preMapPolygon.path[1]) mouseClick(map, point.x - 5, point.y) compare(preMapPolygonClicked.count, 1) @@ -290,26 +302,31 @@ Item { map.clearMapItems() clear_data() compare (map.mapItems.length, 0) + map.center = preMapRect.topLeft point = map.toScreenPosition(preMapRect.topLeft) mouseClick(map, point.x + 5, point.y + 5) compare(preMapRectClicked.count, 0) visualInspectionPoint() + map.center = preMapCircle.center point = map.toScreenPosition(preMapCircle.center) mouseClick(map, point.x - 5, point.y - 5) compare(preMapRectClicked.count, 0) compare(preMapCircleClicked.count, 0) + map.center = preMapCircle.center.atDistanceAndAzimuth(preMapCircle.radius, -45) mouseClick(map, preMapCircle.x + 4, preMapCircle.y + 4) compare(preMapRectClicked.count, 0) compare(preMapCircleClicked.count, 0) compare(preMapQuickItemClicked.count, 0) + map.center = preMapQuickItem.coordinate point = map.toScreenPosition(preMapQuickItem.coordinate) mouseClick(map, point.x + 5, point.y + 5) compare(preMapQuickItemClicked.count, 0) + map.center = preMapPolygon.path[1] point = map.toScreenPosition(preMapPolygon.path[1]) mouseClick(map, point.x - 5, point.y) compare(preMapPolygonClicked.count, 0) - // re-add items and verify they are back (without needing to pan map etc.) + // re-add items and verify they are back // note: addition order is significant map.addMapItem(preMapRect) map.addMapItem(preMapCircle) @@ -319,20 +336,25 @@ Item { map.addMapItem(preMapRoute) compare (map.mapItems.length, 6) visualInspectionPoint() + map.center = preMapRect.topLeft point = map.toScreenPosition(preMapRect.topLeft) mouseClick(map, point.x + 5, point.y + 5) compare(preMapRectClicked.count, 1) + map.center = preMapCircle.center point = map.toScreenPosition(preMapCircle.center) mouseClick(map, point.x - 5, point.y - 5) compare(preMapRectClicked.count, 1) compare(preMapCircleClicked.count, 1) + map.center = preMapCircle.center.atDistanceAndAzimuth(preMapCircle.radius, -45) mouseClick(map, preMapCircle.x + 4, preMapCircle.y + 4) compare(preMapRectClicked.count, 2) compare(preMapCircleClicked.count, 1) compare(preMapQuickItemClicked.count, 0) + map.center = preMapQuickItem.coordinate point = map.toScreenPosition(preMapQuickItem.coordinate) mouseClick(map, point.x + 5, point.y + 5) compare(preMapQuickItemClicked.count, 1) + map.center = preMapPolygon.path[1] point = map.toScreenPosition(preMapPolygon.path[1]) mouseClick(map, point.x - 5, point.y) compare(preMapPolygonClicked.count, 1) @@ -340,41 +362,45 @@ Item { // item clips to map. not sure if this is sensible test map.addMapItem(extMapCircle) + map.center = extMapCircle.center visualInspectionPoint(); point = map.toScreenPosition(extMapCircle.center) mouseClick(map, point.x, point.y) compare(extMapCircleClicked.count, 1) mouseClick(map, point.x, -5) compare(extMapCircleClicked.count, 1) + map.removeMapItem(extMapCircle) map.addMapItem(extMapQuickItem) + map.center = extMapQuickItem.coordinate visualInspectionPoint(); point = map.toScreenPosition(extMapQuickItem.coordinate) mouseClick(map, point.x + 5, point.y + 5) compare(extMapQuickItemClicked.count, 1) mouseClick(map, map.width + 5, point.y + 5) compare(extMapQuickItemClicked.count, 1) + map.removeMapItem(extMapQuickItem) } function test_ab_drag() { clear_data() // basic drags, drag rectangle compare (preMapRectActiveChanged.count, 0) - var i = 0 + map.center = preMapRect.topLeft + var i var point = map.toScreenPosition(preMapRect.topLeft) + var targetCoordinate = map.toCoordinate(51, 51) mousePress(map, point.x + 5, point.y + 5) - for (i=0; i < 50; i += 5) { + for (i = 0; i < 50; i += 1) { wait(1) mouseMove(map, point.x + 5 - i, point.y + 5 - i) } mouseRelease(map, point.x + 5 - i, point.y + 5 - i) - visualInspectionPoint() compare (preMapRectActiveChanged.count, 2) - // coordinates update only (once) after drag has finished - compare (preMapRectTopLeftChanged.count, 1) - compare (preMapRectBottomRightChanged.count, 1) - verify(fuzzy_compare(preMapRect.topLeft.latitude, 27.2, 0.1)) - verify(fuzzy_compare(preMapRect.topLeft.longitude, 12.1, 0.1)) + verify(preMapRectTopLeftChanged.count > 1) + verify(preMapRectBottomRightChanged.count === preMapRectTopLeftChanged.count) + verify(fuzzy_compare(preMapRect.topLeft.latitude, targetCoordinate.latitude, 0.2)) + verify(fuzzy_compare(preMapRect.topLeft.longitude, targetCoordinate.longitude, 0.2)) var latH = preMapRect.bottomRight.latitude - preMapRect.topLeft.latitude var lonW = preMapRect.bottomRight.longitude - preMapRect.topLeft.longitude verify(fuzzy_compare(preMapRect.bottomRight.latitude, preMapRect.topLeft.latitude + latH, 0.1)) @@ -382,34 +408,38 @@ Item { // drag circle compare (preMapCircleActiveChanged.count, 0) + map.center = preMapCircle.center point = map.toScreenPosition(preMapCircle.center) + targetCoordinate = map.toCoordinate(51, 51) mousePress(map, point.x, point.y) - for (i=0; i < 50; i += 5) { + for (i = 0; i < 50; i += 1) { wait(1) mouseMove(map, point.x - i, point.y - i) } mouseRelease(map, point.x - i, point.y - i) visualInspectionPoint() - compare (preMapRectActiveChanged.count, 2) - compare (preMapCircleCenterChanged.count, 1) - verify(fuzzy_compare(preMapCircle.center.latitude, 17.7, 0.1)) - verify(fuzzy_compare(preMapCircle.center.longitude, 22.1, 0.1)) + compare(preMapRectActiveChanged.count, 2) + compare(preMapCircleActiveChanged.count, 2) + verify(preMapCircleCenterChanged.count > 1) + verify(fuzzy_compare(preMapCircle.center.latitude, targetCoordinate.latitude, 0.2)) + verify(fuzzy_compare(preMapCircle.center.longitude, targetCoordinate.longitude, 0.2)) // drag quick item compare (preMapQuickItemActiveChanged.count, 0) - i = 0 + map.center = preMapQuickItem.coordinate point = map.toScreenPosition(preMapQuickItem.coordinate) + targetCoordinate = map.toCoordinate(51, 51) mousePress(map, point.x + 5, point.y + 5) - for (i=0; i < 50; i += 5) { + for (i = 0; i < 50; i += 1) { wait(1) - mouseMove(map, point.x + i, point.y + i) + mouseMove(map, point.x - i, point.y - i) } - mouseRelease(map, point.x + i, point.y + i) + mouseRelease(map, point.x - i, point.y - i) visualInspectionPoint() - compare (preMapQuickItemActiveChanged.count, 2) - compare (preMapQuickItemCoordinateChanged.count, 1) - verify(fuzzy_compare(preMapQuickItem.coordinate.latitude, 29, 0.1)) - verify(fuzzy_compare(preMapQuickItem.coordinate.longitude, 10, 0.1)) + compare(preMapQuickItemActiveChanged.count, 2) + verify(preMapQuickItemCoordinateChanged.count > 1) + verify(fuzzy_compare(preMapQuickItem.coordinate.latitude, targetCoordinate.latitude, 0.2)) + verify(fuzzy_compare(preMapQuickItem.coordinate.longitude, targetCoordinate.longitude, 0.2)) } function test_ac_basic_properties() { diff --git a/tests/auto/declarative_ui/tst_map_item_details.qml b/tests/auto/declarative_ui/tst_map_item_details.qml index a15fc353..ca7ca8c2 100644 --- a/tests/auto/declarative_ui/tst_map_item_details.qml +++ b/tests/auto/declarative_ui/tst_map_item_details.qml @@ -112,6 +112,7 @@ Item { MouseArea { anchors.fill: parent drag.target: parent + preventStealing: true } } @@ -126,6 +127,7 @@ Item { MouseArea { anchors.fill: parent drag.target: parent + preventStealing: true } } @@ -134,6 +136,7 @@ Item { MouseArea { anchors.fill: parent drag.target: parent + preventStealing: true } coordinate { latitude: 20 @@ -158,6 +161,7 @@ Item { MouseArea { anchors.fill: parent drag.target: parent + preventStealing: true } } @@ -322,6 +326,7 @@ Item { clear_data() compare (extMapPolygon.border.width, 1.0) compare (extMapPolygonClicked.count, 0) + map.center = extMapPolygon.path[1] var point = map.toScreenPosition(extMapPolygon.path[1]) map.addMapItem(extMapPolygon) verify(extMapPolygon.path.length == 2) @@ -429,6 +434,7 @@ Item { extMapRectDateline.bottomRight.longitude = datelineCoordinateRight.longitude point = map.toScreenPosition(extMapRectDateline.bottomRight) verify(point.x > map.width / 2.0) + // move item edge onto dateline extMapRectDateline.topLeft.longitude = datelineCoordinate.longitude point = map.toScreenPosition(extMapRectDateline.topLeft) verify(point.x == map.width / 2.0) @@ -448,8 +454,9 @@ Item { // circle map.addMapItem(extMapCircleDateline) - verify(extMapCircleDateline.center.longitude == 180) - var point = map.toScreenPosition(extMapCircleDateline.center) + verify(extMapCircleDateline.center.longitude === 180) + map.center = datelineCoordinate + point = map.toScreenPosition(extMapCircleDateline.center) verify(point.x == map.width / 2.0) extMapCircleDateline.center.longitude = datelineCoordinateRight.longitude point = map.toScreenPosition(extMapCircleDateline.center) @@ -466,7 +473,8 @@ Item { // quickitem map.addMapItem(extMapQuickItemDateline) - verify(extMapQuickItemDateline.coordinate.longitude == 175) + map.center = datelineCoordinate + verify(extMapQuickItemDateline.coordinate.longitude === 175) point = map.toScreenPosition(extMapQuickItemDateline.coordinate) verify(point.x < map.width / 2.0) extMapQuickItemDateline.coordinate.longitude = datelineCoordinateRight.longitude @@ -484,6 +492,7 @@ Item { // polygon map.addMapItem(extMapPolygonDateline) + map.center = datelineCoordinate verify(extMapPolygonDateline.path[0].longitude == 175) verify(extMapPolygonDateline.path[1].longitude == -175) verify(extMapPolygonDateline.path[2].longitude == -175) @@ -530,6 +539,7 @@ Item { // polyline map.addMapItem(extMapPolylineDateline) + map.center = datelineCoordinate verify(extMapPolylineDateline.path[0].longitude == 175) verify(extMapPolylineDateline.path[1].longitude == -175) point = map.toScreenPosition(extMapPolylineDateline.path[0]) @@ -626,6 +636,7 @@ Item { // circle map.addMapItem(extMapCircleEdge) + map.center = datelineCoordinate verify(extMapCircleEdge.center.longitude == -15) var point = map.toScreenPosition(extMapCircleEdge.center) verify(point.x < map.width) @@ -647,6 +658,7 @@ Item { // quickitem map.addMapItem(extMapQuickItemEdge) + map.center = datelineCoordinate verify(extMapQuickItemEdge.coordinate.longitude == -15) point = map.toScreenPosition(extMapQuickItemEdge.coordinate) verify(point.x < map.width) @@ -666,6 +678,7 @@ Item { map.removeMapItem(extMapQuickItemEdge) // polygon + map.center = datelineCoordinate map.addMapItem(extMapPolygonEdge) verify(extMapPolygonEdge.path[0].longitude == -15) verify(extMapPolygonEdge.path[1].longitude == -5) diff --git a/tests/auto/declarative_ui/tst_map_mouse.qml b/tests/auto/declarative_ui/tst_map_mouse.qml index 189b7c7b..a8bff2e8 100644 --- a/tests/auto/declarative_ui/tst_map_mouse.qml +++ b/tests/auto/declarative_ui/tst_map_mouse.qml @@ -126,6 +126,8 @@ Item { property bool lastIsClick: false property bool lastAccepted: false; + preventStealing: true + // The following signal handlers use arguments[0] instead of mouse due to QTBUG-36560 onClicked: page.setMouseData(mouseUpper, arguments[0]) onDoubleClicked: page.setMouseData(mouseUpper, arguments[0]) |