summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorjuhvu <qt-info@nokia.com>2011-10-20 11:24:34 +1000
committerQt by Nokia <qt-info@nokia.com>2011-10-20 07:08:21 +0200
commit0acb68f58dc276faea85c74311fee3920a99eac6 (patch)
tree43843899bad652d583eff61ec58438a4c6d5abfc /tests
parent8f765817b02e72356a0a4461b2889344fdc83dea (diff)
downloadqtlocation-0acb68f58dc276faea85c74311fee3920a99eac6.tar.gz
QML Map pinch and flick part 1/3
Autotest fw changes. First autotests and related fixes. Map initialization order changed to avoid blinking in hardcoded geocoordinate during app startup. Change-Id: Iaad879c135b6283957e0705b991474517f933485 Reviewed-by: David Laing <david.laing@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/declarative/tst_map.qml10
-rw-r--r--tests/auto/declarative/tst_map_mouse.qml1
-rw-r--r--tests/auto/declarative/tst_map_pinch_and_flick.qml438
-rw-r--r--tests/plugins/declarativetestplugin/qdeclarativepinchgenerator.cpp88
-rw-r--r--tests/plugins/declarativetestplugin/qdeclarativepinchgenerator_p.h22
5 files changed, 547 insertions, 12 deletions
diff --git a/tests/auto/declarative/tst_map.qml b/tests/auto/declarative/tst_map.qml
index 6625a255..68ee1e7b 100644
--- a/tests/auto/declarative/tst_map.qml
+++ b/tests/auto/declarative/tst_map.qml
@@ -63,6 +63,12 @@ Item {
function test_aa_map_properties_without_plugin() {
// TODO
+ compare(pluginlessMap.minimumZoomLevel, -1.0)
+ compare(pluginlessMap.maximumZoomLevel, -1.0)
+ // set the plugin and see that values change properly
+ pluginlessMap.plugin = nokiaPlugin;
+ compare(pluginlessMap.minimumZoomLevel, 0)
+ compare(pluginlessMap.maximumZoomLevel, 20)
}
function test_ab_map_properties_with_plugin() {
// TODO
@@ -73,8 +79,8 @@ Item {
compare(pluginlessMap.center.latitude, 10)
compare(pluginlessMap.center.longitude, 11)
// default coordinate (coordinate is not explicitly set)
- compare(map.center.latitude, -27.5)
- compare(map.center.longitude, 153)
+ compare(map.center.latitude, 0)
+ compare(map.center.longitude, 0)
map.center.latitude = 5
compare(centerSpy.count, 1)
map.center.longitude = 10
diff --git a/tests/auto/declarative/tst_map_mouse.qml b/tests/auto/declarative/tst_map_mouse.qml
index fa4a1cd7..62847940 100644
--- a/tests/auto/declarative/tst_map_mouse.qml
+++ b/tests/auto/declarative/tst_map_mouse.qml
@@ -288,6 +288,7 @@ Item {
function test_aaa_basic_properties() // _aaa_ to ensure execution first
{
clear_data()
+ wait(50)
// default values
compare(mouseUpper.containsMouse, false)
compare(mouseUpper.pressed, false)
diff --git a/tests/auto/declarative/tst_map_pinch_and_flick.qml b/tests/auto/declarative/tst_map_pinch_and_flick.qml
new file mode 100644
index 00000000..9b327fa2
--- /dev/null
+++ b/tests/auto/declarative/tst_map_pinch_and_flick.qml
@@ -0,0 +1,438 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.0
+import QtTest 1.0
+import QtLocation 5.0
+import QtLocation.test 5.0
+
+Item {
+ // General-purpose elements for the test:
+ id: page
+ width: 100
+ height: 100
+ //Plugin { id: testPlugin; name: "qmlgeo.test.plugin" }
+ Plugin { id: nokiaPlugin; name: "nokia"; PluginParameter {name: "mapping.host"; value: "for.nonexistent"} }
+ Coordinate{ id: coordinate1; latitude: 10; longitude: 11}
+ Coordinate{ id: coordinate2; latitude: 12; longitude: 13}
+ Map {
+ id: map
+ plugin: nokiaPlugin
+ center: coordinate1;
+ zoomLevel: 9;
+ anchors.fill: page
+ x:0; y:0
+ }
+
+ SignalSpy {id: centerSpy; target: map; signalName: 'centerChanged'}
+ SignalSpy {id: coordinate2LatitudeSpy; target: coordinate2; signalName: 'latitudeChanged'}
+ SignalSpy {id: coordinate2LongitudeSpy; target: coordinate2; signalName: 'longitudeChanged'}
+ SignalSpy {id: coordinate2AltitudeSpy; target: coordinate2; signalName: 'altitudeChanged'}
+ SignalSpy {id: pinchStartedSpy; target: map.pinch; signalName: 'pinchStarted'}
+ SignalSpy {id: pinchUpdatedSpy; target: map.pinch; signalName: 'pinchUpdated'}
+ SignalSpy {id: pinchFinishedSpy; target: map.pinch; signalName: 'pinchFinished'}
+ SignalSpy {id: pinchMaximumZoomLevelChangeSpy; target: map.pinch; signalName: 'maximumZoomLevelChangeChanged'}
+ SignalSpy {id: pinchMinimumZoomLevelSpy; target: map.pinch; signalName: 'minimumZoomLevelChanged'}
+ SignalSpy {id: pinchMaximumZoomLevelSpy; target: map.pinch; signalName: 'maximumZoomLevelChanged'}
+ SignalSpy {id: pinchMinimumRotationSpy; target: map.pinch; signalName: 'minimumRotationChanged'}
+ SignalSpy {id: pinchMaximumRotationSpy; target: map.pinch; signalName: 'maximumRotationChanged'}
+ SignalSpy {id: pinchRotationSpeedSpy; target: map.pinch; signalName: 'rotationSpeedChanged'}
+ SignalSpy {id: pinchEnabledSpy; target: map.pinch; signalName: 'enabledChanged'}
+ SignalSpy {id: pinchActiveSpy; target: map.pinch; signalName: 'activeChanged'}
+ SignalSpy {id: pinchActiveGesturesSpy; target: map.pinch; signalName: 'activeGesturesChanged'}
+
+ // From QtLocation.test plugin
+ PinchGenerator {
+ id: pinchGenerator
+ anchors.fill: parent
+ target: map
+ enabled: false
+ }
+
+ TestCase {
+ when: windowShown
+ name: "Map pinch"
+
+ function clear_data() {
+ centerSpy.clear()
+ coordinate2AltitudeSpy.clear()
+ coordinate2LatitudeSpy.clear()
+ coordinate2LongitudeSpy.clear()
+ pinchStartedSpy.clear()
+ pinchUpdatedSpy.clear()
+ pinchFinishedSpy.clear()
+ pinchMaximumZoomLevelChangeSpy.clear()
+ pinchMinimumZoomLevelSpy.clear()
+ pinchMaximumZoomLevelSpy.clear()
+ pinchMinimumRotationSpy.clear()
+ pinchMaximumRotationSpy.clear()
+ pinchRotationSpeedSpy.clear()
+ pinchEnabledSpy.clear()
+ pinchActiveSpy.clear()
+ pinchActiveGesturesSpy.clear()
+ }
+
+ function test_basic_properties() {
+ clear_data()
+
+ // pinch
+ compare(map.pinch.enabled, true)
+ map.pinch.enabled = false
+ compare(pinchEnabledSpy.count, 1)
+ compare(map.pinch.enabled, false)
+ map.pinch.enabled = false
+ compare(pinchEnabledSpy.count, 1)
+ compare(map.pinch.enabled, false)
+ map.pinch.enabled = true
+ compare(pinchEnabledSpy.count, 2)
+ compare(map.pinch.enabled, true)
+
+ compare(map.pinch.active, false)
+
+ verify(map.pinch.activeGestures & MapPinch.ZoomGesture)
+ verify(map.pinch.activeGestures & MapPinch.RotationGesture)
+ verify(!(map.pinch.activeGestures & MapPinch.TiltGesture))
+ map.pinch.activeGestures = MapPinch.NoGesture
+ compare(map.pinch.activeGestures, MapPinch.NoGesture)
+ compare(pinchActiveGesturesSpy.count, 1)
+ map.pinch.activeGestures = MapPinch.NoGesture
+ compare(map.pinch.activeGestures, MapPinch.NoGesture)
+ compare(pinchActiveGesturesSpy.count, 1)
+ map.pinch.activeGestures = MapPinch.ZoomGesture | MapPinch.RotationGesture
+ compare(map.pinch.activeGestures, MapPinch.ZoomGesture | MapPinch.RotationGesture)
+ compare(pinchActiveGesturesSpy.count, 2)
+ map.pinch.activeGestures = MapPinch.RotationGesture
+ compare(map.pinch.activeGestures, MapPinch.RotationGesture)
+ compare(pinchActiveGesturesSpy.count, 3)
+ map.pinch.activeGestures = MapPinch.ZoomGesture
+ compare(map.pinch.activeGestures, MapPinch.ZoomGesture)
+ compare(pinchActiveGesturesSpy.count, 4)
+
+ compare(map.pinch.minimumZoomLevel, map.minimumZoomLevel)
+ map.pinch.minimumZoomLevel = 5
+ compare(pinchMinimumZoomLevelSpy.count, 1)
+ compare(map.pinch.minimumZoomLevel, 5)
+ map.pinch.minimumZoomLevel = -1 // too small
+ map.pinch.minimumZoomLevel = 492 // too big
+ compare(pinchMinimumZoomLevelSpy.count, 1)
+ compare(map.pinch.minimumZoomLevel, 5)
+ map.pinch.minimumZoomLevel = map.minimumZoomLevel
+ compare(pinchMinimumZoomLevelSpy.count, 2)
+ compare(map.pinch.minimumZoomLevel, map.minimumZoomLevel)
+
+ compare(map.pinch.maximumZoomLevel, map.maximumZoomLevel)
+ map.pinch.maximumZoomLevel = 9
+ compare (pinchMaximumZoomLevelSpy.count, 1)
+ compare(map.pinch.maximumZoomLevel, 9)
+ map.pinch.maximumZoomLevel = -1 // too small
+ map.pinch.maximumZoomLevel = 3234 // too big
+ compare(pinchMaximumZoomLevelSpy.count, 1)
+ compare(map.pinch.maximumZoomLevel, 9)
+ map.pinch.maximumZoomLevel = map.maximumZoomLevel
+ compare(pinchMaximumZoomLevelSpy.count, 2)
+ compare(map.pinch.maximumZoomLevel, map.maximumZoomLevel)
+
+ clear_data()
+ map.pinch.minimumZoomLevel = 5 // ok
+ map.pinch.maximumZoomLevel = 9 // ok
+ map.pinch.minimumZoomLevel = 10 // bigger than max
+ map.pinch.maximumZoomLevel = 4 // smaller than min
+ compare (pinchMaximumZoomLevelSpy.count, 1)
+ compare (pinchMinimumZoomLevelSpy.count, 1)
+ compare(map.pinch.maximumZoomLevel, 9)
+ compare(map.pinch.minimumZoomLevel, 5)
+ map.pinch.minimumZoomLevel = map.minimumZoomLevel
+ map.pinch.maximumZoomLevel = map.maximumZoomLevel
+
+ compare(map.pinch.maximumZoomLevelChange, 2)
+ map.pinch.maximumZoomLevelChange = 4
+ compare(pinchMaximumZoomLevelChangeSpy.count, 1)
+ compare (map.pinch.maximumZoomLevelChange, 4)
+ map.pinch.maximumZoomLevelChange = 4
+ compare(pinchMaximumZoomLevelChangeSpy.count, 1)
+ compare (map.pinch.maximumZoomLevelChange, 4)
+ map.pinch.maximumZoomLevelChange = 11 // too big
+ map.pinch.maximumZoomLevelChange = 0.01 // too small
+ map.pinch.maximumZoomLevelChange = -1 // too small
+ compare(pinchMaximumZoomLevelChangeSpy.count, 1)
+ compare (map.pinch.maximumZoomLevelChange, 4)
+ map.pinch.maximumZoomLevelChange = 2
+ compare(pinchMaximumZoomLevelChangeSpy.count, 2)
+ compare (map.pinch.maximumZoomLevelChange, 2)
+
+ compare(map.pinch.minimumRotation, 0)
+ map.pinch.minimumRotation = 10
+ compare(pinchMinimumRotationSpy.count, 1)
+ compare(map.pinch.minimumRotation, 10)
+ map.pinch.minimumRotation = 10
+ compare(pinchMinimumRotationSpy.count, 1)
+ compare(map.pinch.minimumRotation, 10)
+ map.pinch.minimumRotation = -1 // too small
+ map.pinch.minimumRotation = 361 // too big
+ compare(pinchMinimumRotationSpy.count, 1)
+ compare(map.pinch.minimumRotation, 10)
+ map.pinch.minimumRotation = 0
+ compare(pinchMinimumRotationSpy.count, 2)
+ compare(map.pinch.minimumRotation, 0)
+
+ compare(map.pinch.maximumRotation, 45)
+ map.pinch.maximumRotation = 55
+ compare(pinchMaximumRotationSpy.count,1)
+ compare(map.pinch.maximumRotation, 55)
+ map.pinch.maximumRotation = 55
+ compare(pinchMaximumRotationSpy.count,1)
+ compare(map.pinch.maximumRotation, 55)
+ map.pinch.maximumRotation = -1 // too small
+ map.pinch.maximumRotation = 362 // too big
+ compare(pinchMaximumRotationSpy.count,1)
+ compare(map.pinch.maximumRotation, 55)
+ map.pinch.maximumRotation = 45
+ compare(pinchMaximumRotationSpy.count,2)
+ compare(map.pinch.maximumRotation, 45)
+
+ compare(map.pinch.rotationSpeed, 1)
+ map.pinch.rotationSpeed = 2
+ compare(pinchRotationSpeedSpy.count, 1)
+ compare(map.pinch.rotationSpeed, 2)
+ map.pinch.rotationSpeed = 2
+ compare(pinchRotationSpeedSpy.count, 1)
+ compare(map.pinch.rotationSpeed, 2)
+ map.pinch.rotationSpeed = -1 // too small
+ map.pinch.rotationSpeed = 11 // too big
+ compare(pinchRotationSpeedSpy.count, 1)
+ compare(map.pinch.rotationSpeed, 2)
+ map.pinch.rotationSpeed = 1
+ compare(pinchRotationSpeedSpy.count, 2)
+ compare(map.pinch.rotationSpeed, 1)
+
+ compare(map.pinch.maximumTilt, 90)
+ compare(map.pinch.minimumTilt, 0)
+ compare(map.pinch.maximumTiltChange, 20)
+
+ // flick
+
+
+ }
+
+ function test_pinch_rotation() {
+ map.pinch.activeGestures = MapPinch.RotationGesture
+ clear_data()
+ // todo
+
+ }
+
+
+ function test_pinch_zoom() {
+ map.pinch.activeGestures = MapPinch.ZoomGesture
+ clear_data()
+ // 1. typical zoom in
+ compare(map.zoomLevel, 9)
+ map.pinch.maximumZoomLevelChange = 2
+ compare(map.pinch.active, false)
+ pinchGenerator.pinch(
+ Qt.point(0,50), // point1From
+ Qt.point(50,50), // point1To
+ Qt.point(100,50), // point2From
+ Qt.point(50,50), // point2To
+ 20, // interval between touch events (swipe1), default 20ms
+ 20, // interval between touch events (swipe2), default 20ms
+ 10, // number of touchevents in point1from -> point1to, default 10
+ 10); // number of touchevents in point2from -> point2to, default 10
+ tryCompare(pinchStartedSpy, "count", 1);
+ wait(50);
+ compare(pinchActiveSpy.count,1) // check that pinch is active
+ compare(map.pinch.active, true)
+ wait(200);
+ verify(pinchUpdatedSpy.count >= 5); // verify 'sane' number of updates received
+ tryCompare(pinchFinishedSpy, "count", 1);
+ compare(pinchActiveSpy.count,2)
+ compare(map.pinch.active, false)
+ compare(map.zoomLevel, 8)
+ // 2. typical zoom out
+ clear_data();
+ map.pinch.maximumZoomLevelChange = 2
+ pinchGenerator.pinch(Qt.point(50,50), Qt.point(0,50),Qt.point(50,50), Qt.point(100,50));
+ tryCompare(pinchStartedSpy, "count", 1);
+ wait(250);
+ verify(pinchUpdatedSpy.count >= 5); // verify 'sane' number of updates received
+ tryCompare(pinchFinishedSpy, "count", 1);
+ compare(map.zoomLevel, 9)
+ // 3. zoom in and back out (direction change during same pinch)
+ clear_data();
+ pinchGenerator.pinch(Qt.point(0,50), Qt.point(100,50), Qt.point(100,50),Qt.point(0,50));
+ tryCompare(pinchStartedSpy, "count", 1);
+ wait(250);
+ verify(pinchUpdatedSpy.count >= 5); // verify 'sane' number of updates received
+ tryCompare(pinchFinishedSpy, "count", 1);
+ compare(map.zoomLevel, 9) // should remain the same
+ // 4. typical zoom in with different change level
+ clear_data();
+ map.pinch.maximumZoomLevelChange = 4
+ compare (map.pinch.maximumZoomLevelChange, 4)
+ pinchGenerator.pinch(Qt.point(0,50),Qt.point(50,50),Qt.point(100,50),Qt.point(50,50));
+ wait(250);
+ tryCompare(pinchFinishedSpy, "count", 1);
+ compare(map.zoomLevel, 7)
+ // 5. typical zoom out with different change level
+ clear_data();
+ map.pinch.maximumZoomLevelChange = 1
+ compare (map.pinch.maximumZoomLevelChange, 1)
+ pinchGenerator.pinch(Qt.point(50,50), Qt.point(0,50),Qt.point(50,50), Qt.point(100,50));
+ wait(250);
+ tryCompare(pinchFinishedSpy, "count", 1);
+ compare(map.zoomLevel, 7.5)
+
+ // 6. try to zoom in below minimum zoom level
+ clear_data()
+ map.pinch.maximumZoomLevelChange = 4
+ map.pinch.minimumZoomLevel = 7
+ pinchGenerator.pinch(Qt.point(0,50),Qt.point(50,50),Qt.point(100,50),Qt.point(50,50));
+ wait(250);
+ tryCompare(pinchFinishedSpy, "count", 1);
+ compare(map.zoomLevel, 7) // would go to 5.5
+
+ // 7. try to zoom out above maximum zoom level
+ clear_data()
+ map.pinch.maximumZoomLevelChange = 4
+ map.pinch.maximumZoomLevel = 8
+ pinchGenerator.pinch(Qt.point(50,50), Qt.point(0,50),Qt.point(50,50), Qt.point(100,50));
+ wait(250);
+ tryCompare(pinchFinishedSpy, "count", 1);
+ compare(map.zoomLevel, 8) // would go to 9
+
+ // 8. pinch when max and min are same
+ clear_data()
+ map.pinch.maximumZoomLevel = 8
+ map.pinch.minimumZoomLevel = 8
+ compare(map.pinch.maximumZoomLevel, 8)
+ compare(map.pinch.minimumZoomLevel, 8)
+ pinchGenerator.pinch(Qt.point(0,50),Qt.point(50,50),Qt.point(100,50),Qt.point(50,50));
+ wait(250);
+ tryCompare(pinchFinishedSpy, "count", 1);
+ compare(map.zoomLevel, 8)
+
+ // 9. pinch when max..min is not where map zoomLevel currently is
+ clear_data()
+ map.pinch.maximumZoomLevelChange = 4
+ map.pinch.minimumZoomLevel = 4
+ map.pinch.maximumZoomLevel = 6
+ // first when above the zoom range
+ map.zoomLevel = 10
+ pinchGenerator.pinch(Qt.point(50,50), Qt.point(0,50),Qt.point(50,50), Qt.point(100,50)); // zoom out
+ wait(250);
+ tryCompare(pinchFinishedSpy, "count", 1);
+ compare(map.zoomLevel, 6)
+ map.zoomLevel = 10
+ pinchGenerator.pinch(Qt.point(0,50),Qt.point(50,50),Qt.point(100,50),Qt.point(50,50)); // zoom in
+ wait(250);
+ tryCompare(pinchFinishedSpy, "count", 2);
+ compare(map.zoomLevel, 6)
+ console.log('the zoomLevel after pinching outside of range: ' + map.zoomLevel)
+ pinchGenerator.pinch(Qt.point(0,50),Qt.point(50,50),Qt.point(100,50),Qt.point(50,50)); // zoom in
+ wait(250);
+ tryCompare(pinchFinishedSpy, "count", 3);
+ compare(map.zoomLevel, 4)
+ // when below the zoom range
+ map.zoomLevel = 1
+ pinchGenerator.pinch(Qt.point(50,50), Qt.point(0,50),Qt.point(50,50), Qt.point(100,50)); // zoom out
+ wait(250);
+ tryCompare(pinchFinishedSpy, "count", 4);
+ compare(map.zoomLevel, 4)
+ map.zoomLevel = 1
+ pinchGenerator.pinch(Qt.point(0,50),Qt.point(50,50),Qt.point(100,50),Qt.point(50,50)); // zoom in
+ wait(250);
+ tryCompare(pinchFinishedSpy, "count", 5);
+ compare(map.zoomLevel, 4)
+ console.log('the zoomLevel after pinching outside of range: ' + map.zoomLevel)
+ pinchGenerator.pinch(Qt.point(50,50), Qt.point(0,50),Qt.point(50,50), Qt.point(100,50)); // zoom out
+ wait(250);
+ tryCompare(pinchFinishedSpy, "count", 6);
+ compare(map.zoomLevel, 6)
+ map.pinch.minimumZoomLevel = map.minimumZoomLevel
+ map.pinch.maximumZoomLevel = map.maximumZoomLevel
+
+ // 10. pinch while pinch area is disabled
+ clear_data()
+ map.pinch.enabled = false
+ map.pinch.maximumZoomLevelChange = 2
+ pinchGenerator.pinch(Qt.point(50,50), Qt.point(0,50),Qt.point(50,50), Qt.point(100,50));
+ wait(100);
+ compare(pinchActiveSpy.count, 0)
+ compare(map.pinch.active, false)
+ compare(pinchStartedSpy.count, 0)
+ compare(pinchUpdatedSpy.count, 0);
+ compare(pinchFinishedSpy.count, 0);
+ compare(map.zoomLevel, 6)
+ pinchGenerator.stop()
+ map.pinch.enabled = true
+
+ // 11. pinch disabling during pinching
+ clear_data()
+ pinchGenerator.pinch(Qt.point(50,50), Qt.point(0,50),Qt.point(50,50), Qt.point(100,50));
+ wait(250)
+ map.pinch.enabled = false
+ // check that pinch is active. then disable the pinch. pinch area should still process
+ // as long as it is active
+ compare(pinchActiveSpy.count,1)
+ compare(map.pinch.active, true)
+ compare(pinchStartedSpy.count, 1)
+ compare(pinchFinishedSpy.count, 0)
+ var pinchupdates = pinchUpdatedSpy.count
+ console.log('this many pinches there were ------ ' + pinchupdates)
+ verify(pinchupdates > 0)
+ tryCompare(pinchFinishedSpy, "count", 1)
+ compare(pinchActiveSpy.count,2)
+ compare(map.pinch.active, false)
+ map.pinch.enabled = true
+
+ // 12. check nuthin happens if no active gestures
+ clear_data()
+ map.pinch.activeGestures = MapPinch.NoGesture
+ pinchGenerator.pinch(Qt.point(50,50), Qt.point(0,50),Qt.point(50,50), Qt.point(100,50));
+ tryCompare(pinchStartedSpy, "count", 0);
+ wait(250);
+ compare(pinchUpdatedSpy.count, 0);
+ compare(pinchStartedSpy.count, 0);
+ compare(map.zoomLevel, 7)
+ map.pinch.activeGestures = MapPinch.ZoomGesture
+ }
+ }
+}
diff --git a/tests/plugins/declarativetestplugin/qdeclarativepinchgenerator.cpp b/tests/plugins/declarativetestplugin/qdeclarativepinchgenerator.cpp
index c32c77ef..05c24287 100644
--- a/tests/plugins/declarativetestplugin/qdeclarativepinchgenerator.cpp
+++ b/tests/plugins/declarativetestplugin/qdeclarativepinchgenerator.cpp
@@ -120,8 +120,13 @@ void QDeclarativePinchGenerator::setEnabled(bool enabled)
QTouchEvent::TouchPoint QDeclarativePinchGenerator::mouseEventToTouchPoint(QMouseEvent *event)
{
+ return createTouchPoint(event->type(), event->pos());
+}
+
+QTouchEvent::TouchPoint QDeclarativePinchGenerator::createTouchPoint(QEvent::Type type, QPoint pos)
+{
QTouchEvent::TouchPoint touchPoint;
- switch (event->type()) {
+ switch (type) {
//case QEvent::GraphicsSceneMousePress:
case QEvent::MouseButtonPress:
touchPoint.setState(Qt::TouchPointPressed);
@@ -140,10 +145,10 @@ QTouchEvent::TouchPoint QDeclarativePinchGenerator::mouseEventToTouchPoint(QMous
//touchPoint.setId(touchPointId_++); // running number
touchPoint.setId(0);
touchPoint.setPressure(0.75);
- touchPoint.setPos(event->pos());
- touchPoint.setLastPos(event->pos());
- touchPoint.setScenePos(target_->mapToScene(event->pos()));
- touchPoint.setLastScenePos(target_->mapToScene(event->pos()));
+ touchPoint.setPos(pos);
+ touchPoint.setLastPos(pos);
+ touchPoint.setScenePos(target_->mapToScene(pos));
+ touchPoint.setLastScenePos(target_->mapToScene(pos));
return touchPoint;
}
@@ -434,6 +439,79 @@ Q_INVOKABLE void QDeclarativePinchGenerator::replay()
setState(Replaying);
}
+void QDeclarativePinchGenerator::pinch(QPoint point1From,
+ QPoint point1To,
+ QPoint point2From,
+ QPoint point2To,
+ int interval1,
+ int interval2,
+ int samples1,
+ int samples2)
+{
+ //qDebug() << __FUNCTION__ << point1From << point1To << point2From << point2To << interval1 << interval2 << samples1 << samples2 << state_;
+ Q_ASSERT(state_ == Idle);
+ //Q_ASSERT(!point1From.isNull());
+ //Q_ASSERT(!point1To.isNull());
+ //Q_ASSERT(!point2From.isNull());
+ //Q_ASSERT(!point2To.isNull());
+ Q_ASSERT(interval1 > 10);
+ Q_ASSERT(interval2 > 10);
+ Q_ASSERT(samples1 >= 2); // we need press and release events at minimum
+ Q_ASSERT(samples2 >= 2);
+
+ // generate swipes based on the parameters
+ if (!swipes_.isEmpty()) {
+ qDeleteAll(swipes_);
+ swipes_.clear();
+ }
+ generateSwipe(point1From, point1To, interval1, samples1);
+ generateSwipe(point2From, point2To, interval2, samples2);
+ Q_ASSERT(swipes_.at(0));
+ Q_ASSERT(swipes_.at(1));
+
+ if (swipes_.at(0)->touchPoints.count() >= swipes_.at(1)->touchPoints.count())
+ masterSwipe_ = 0;
+ else
+ masterSwipe_ = 1;
+ replayTimer_ = startTimer(swipes_.at(masterSwipe_)->touchPointDurations.at(0) / replaySpeedFactor_);
+ replayBookmark_ = 0;
+ setState(Replaying);
+}
+
+void QDeclarativePinchGenerator::generateSwipe(QPoint from, QPoint to, int interval, int samples)
+{
+ //qDebug() << __FUNCTION__ << "generate swipe from, to, interval, samplecount: " << from << to << interval << samples;
+ int deltaX = (to.x() - from.x()) / samples;
+ int deltaY = (to.y() - from.y()) / samples;
+ //qDebug() << __FUNCTION__ << "deltaX, deltaY: " << deltaX << deltaY;
+ Q_ASSERT(qAbs(deltaX) > 0 || qAbs(deltaY) > 0);
+
+ activeSwipe_ = new Swipe;
+ // create press event
+ activeSwipe_->touchPointDurations.append(interval);
+ activeSwipe_->totalDuration += interval;
+ activeSwipe_->touchPoints.append(createTouchPoint(QEvent::MouseButtonPress, from));
+ //qDebug() << __FUNCTION__ << "press X, Y: " << from.x() << from.y();
+
+ // create move events
+ for (int i = 1; i < samples - 1; ++i) {
+ activeSwipe_->touchPointDurations.append(interval);
+ activeSwipe_->totalDuration += interval;
+ int nextX = from.x() + (i * deltaX);
+ int nextY = from.y() + (i * deltaY);
+ //qDebug() << __FUNCTION__ << "move X, Y: " << nextX << nextY;
+ activeSwipe_->touchPoints.append(createTouchPoint(QEvent::MouseMove, QPoint(nextX, nextY)));
+ }
+ // create release event
+ activeSwipe_->touchPointDurations.append(interval);
+ activeSwipe_->totalDuration += interval;
+ activeSwipe_->touchPoints.append(createTouchPoint(QEvent::MouseButtonRelease, to));
+ //qDebug() << __FUNCTION__ << "release X, Y: " << to.x() << to.y();
+
+ // append the swipe
+ swipes_.append(activeSwipe_);
+}
+
Q_INVOKABLE void QDeclarativePinchGenerator::clear()
{
stop();
diff --git a/tests/plugins/declarativetestplugin/qdeclarativepinchgenerator_p.h b/tests/plugins/declarativetestplugin/qdeclarativepinchgenerator_p.h
index 536d09f9..f3017903 100644
--- a/tests/plugins/declarativetestplugin/qdeclarativepinchgenerator_p.h
+++ b/tests/plugins/declarativetestplugin/qdeclarativepinchgenerator_p.h
@@ -43,12 +43,13 @@
#define QDECLARATIVEPINCHGENERATOR_H
#include <QtDeclarative/QSGItem>
-#include <QMouseEvent>
-#include <QElapsedTimer>
-#include <QTouchEvent>
#include <QSGCanvas>
-#include <QKeyEvent>
-#include <QList>
+#include <QtGui/QMouseEvent>
+#include <QtGui/QTouchEvent>
+#include <QtGui/QKeyEvent>
+#include <QtCore/QElapsedTimer>
+#include <QtCore/QList>
+#include <QtCore/QPoint>
#include <QDebug>
// how many concurrent "swipes" should we have
@@ -112,6 +113,15 @@ public:
Q_INVOKABLE void clear();
Q_INVOKABLE void stop();
+ // programmatic interface, useful for autotests
+ Q_INVOKABLE void pinch(QPoint point1From,
+ QPoint point1To,
+ QPoint point2From,
+ QPoint point2To,
+ int interval1 = 20,
+ int interval2 = 20,
+ int samples1 = 10,
+ int samples2 = 10);
signals:
void stateChanged();
void countChanged();
@@ -144,7 +154,9 @@ protected:
private:
void setState(GeneratorState state);
QTouchEvent::TouchPoint mouseEventToTouchPoint(QMouseEvent* event);
+ QTouchEvent::TouchPoint createTouchPoint(QEvent::Type type, QPoint pos);
QTouchEvent::TouchPoint convertToPrimary(QTouchEvent::TouchPoint original);
+ void generateSwipe(QPoint from, QPoint to, int duration, int samples);
private:
QSGItem* target_;