1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364
|
/****************************************************************************
**
** 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.5
import QtTest 1.0
import QtLocation 5.6
import QtPositioning 5.5
import QtLocation.Test 5.6
Item {
// General-purpose elements for the test:
id: page
width: 120
height: 120
Plugin { id: testPlugin; name: "qmlgeo.test.plugin"; allowExperimental: true }
property variant coordinate: QtPositioning.coordinate(10, 11)
MouseArea {
id: mouseAreaBottom
anchors.fill: parent
visible: false
}
Map {
id: map
plugin: testPlugin
center: coordinate;
zoomLevel: 9;
anchors.fill: page
x:0; y:0
property real flickStartedLatitude
property real flickStartedLongitude
property bool disableOnPanStartedWithNoGesture: false
property bool disableOnFlickStartedWithNoGesture: false
property bool disableOnPanStartedWithDisabled: false
property bool disableOnFlickStartedWithDisabled: false
gesture.onPanStarted: {
if (disableOnPanStartedWithNoGesture)
map.gesture.acceptedGestures = MapGestureArea.NoGesture
if (disableOnPanStartedWithDisabled)
map.gesture.enabled = false
}
gesture.onFlickStarted: {
flickStartedLatitude = map.center.latitude
flickStartedLatitude = map.center.longitude
if (disableOnFlickStartedWithNoGesture)
map.gesture.acceptedGestures = MapGestureArea.NoGesture
if (disableOnFlickStartedWithDisabled)
map.gesture.enabled = false
}
MouseArea {
id: mouseAreaTop
anchors.fill: parent
visible: false
}
}
SignalSpy {id: centerSpy; target: map; signalName: 'centerChanged'}
SignalSpy {id: panStartedSpy; target: map.gesture; signalName: 'panStarted'}
SignalSpy {id: panFinishedSpy; target: map.gesture; signalName: 'panFinished'}
SignalSpy {id: gestureEnabledSpy; target: map.gesture; signalName: 'enabledChanged'}
SignalSpy {id: flickDecelerationSpy; target: map.gesture; signalName: 'flickDecelerationChanged'}
SignalSpy {id: flickStartedSpy; target: map.gesture; signalName: 'flickStarted'}
SignalSpy {id: flickFinishedSpy; target: map.gesture; signalName: 'flickFinished'}
SignalSpy {id: mouseAreaTopSpy; target: mouseAreaTop; signalName: 'onPressed'}
SignalSpy {id: mouseAreaBottomSpy; target: mouseAreaBottom; signalName: 'onPressed'}
TestCase {
when: windowShown && map.mapReady
name: "MapFlick"
function init()
{
if (Qt.platform.os === "windows" && (LocationTestHelper.x86Bits() === 32))
skip("QTBUG-59503")
map.gesture.acceptedGestures = MapGestureArea.PanGesture | MapGestureArea.FlickGesture;
map.gesture.enabled = true
map.gesture.panEnabled = true
map.gesture.flickDeceleration = 500
map.zoomLevel = 9 // or flicking diagonally won't work
map.disableOnPanStartedWithNoGesture = false
map.disableOnFlickStartedWithNoGesture = false
map.disableOnPanStartedWithDisabled = false
map.disableOnFlickStartedWithDisabled = false
centerSpy.clear()
gestureEnabledSpy.clear()
flickDecelerationSpy.clear()
panStartedSpy.clear()
panFinishedSpy.clear()
flickStartedSpy.clear()
flickFinishedSpy.clear()
mouseAreaTopSpy.clear()
mouseAreaBottomSpy.clear()
mouseAreaBottom.visible = false
mouseAreaTop.visible = false
compare(map.gesture.pinchActive, false)
compare(map.gesture.panActive, false)
}
function initTestCase()
{
//check default values
compare(map.gesture.enabled, true)
map.gesture.enabled = false
compare(gestureEnabledSpy.count, 1)
compare(map.gesture.enabled, false)
map.gesture.enabled = false
compare(gestureEnabledSpy.count, 1)
compare(map.gesture.enabled, false)
map.gesture.enabled = true
compare(gestureEnabledSpy.count, 2)
compare(map.gesture.enabled, true)
compare(map.gesture.pinchActive, false)
compare(map.gesture.panActive, false)
verify(map.gesture.acceptedGestures & MapGestureArea.PinchGesture)
map.gesture.acceptedGestures = MapGestureArea.NoGesture
compare(map.gesture.acceptedGestures, MapGestureArea.NoGesture)
map.gesture.acceptedGestures = MapGestureArea.NoGesture
compare(map.gesture.acceptedGestures, MapGestureArea.NoGesture)
map.gesture.acceptedGestures = MapGestureArea.PinchGesture | MapGestureArea.PanGesture
compare(map.gesture.acceptedGestures, MapGestureArea.PinchGesture | MapGestureArea.PanGesture)
map.gesture.acceptedGestures = MapGestureArea.PanGesture
compare(map.gesture.acceptedGestures, MapGestureArea.PanGesture)
compare(map.gesture.flickDeceleration, 2500)
map.gesture.flickDeceleration = 2600
compare(flickDecelerationSpy.count, 1)
compare(map.gesture.flickDeceleration, 2600)
map.gesture.flickDeceleration = 2600
compare(flickDecelerationSpy.count, 1)
compare(map.gesture.flickDeceleration, 2600)
map.gesture.flickDeceleration = 400 // too small
compare(flickDecelerationSpy.count, 2)
compare(map.gesture.flickDeceleration, 500) // clipped to min
map.gesture.flickDeceleration = 11000 // too big
compare(flickDecelerationSpy.count, 3)
compare(map.gesture.flickDeceleration, 10000) // clipped to max
}
function flick_down()
{
map.center.latitude = 10
map.center.longitude = 11
mousePress(page, 0, 50)
for (var i = 0; i < 50; i += 5) {
wait(25)
mouseMove(page, 0, (50 + i), 0, Qt.LeftButton);
}
mouseRelease(page, 0, 100)
// order of signals is: flickStarted, either order: (flickEnded, movementEnded)
verify(map.center.latitude > 10) // latitude increases we are going 'up/north' (moving mouse down)
var moveLatitude = map.center.latitude // store lat and check that flick continues
tryCompare(flickStartedSpy, "count", 1)
tryCompare(panFinishedSpy, "count", 1)
tryCompare(flickFinishedSpy, "count", 1)
verify(map.center.latitude > moveLatitude)
compare(map.center.longitude, 11) // should remain the same
}
function test_flick_down()
{
flick_down()
}
function test_flick_down_with_filtering()
{
mouseAreaTop.visible = true
mouseAreaBottom.visible = true
flick_down()
tryCompare(mouseAreaTopSpy, "count", 1)
tryCompare(mouseAreaBottomSpy, "count",0)
}
function flick_up()
{
map.center.latitude = 70
map.center.longitude = 11
mousePress(page, 10, 95)
for (var i = 45; i > 0; i -= 5) {
wait(25)
mouseMove(page, 10, (50 + i), 0, Qt.LeftButton);
}
mouseRelease(page, 10, 50)
verify(map.center.latitude < 70)
var moveLatitude = map.center.latitude // store lat and check that flick continues
tryCompare(flickStartedSpy, "count", 1)
tryCompare(panFinishedSpy, "count", 1)
tryCompare(flickFinishedSpy, "count", 1)
verify(map.center.latitude < moveLatitude)
compare(map.center.longitude, 11) // should remain the same
}
function test_flick_up()
{
flick_up()
}
function test_flick_up_with_filtering()
{
mouseAreaTop.visible = true
mouseAreaBottom.visible = true
flick_up()
tryCompare(mouseAreaTopSpy, "count", 1)
tryCompare(mouseAreaBottomSpy, "count",0)
}
function test_flick_diagonal()
{
map.center.latitude = 50
map.center.longitude = 50
var pos = 5
mousePress(page, pos, pos)
for (var i = pos; i < 50; i += 5) {
pos = i
wait(25)
mouseMove(page, pos, pos, 0, Qt.LeftButton);
}
mouseRelease(page, pos, pos)
verify(map.center.latitude > 50)
verify(map.center.longitude < 50)
var moveLatitude = map.center.latitude
var moveLongitude = map.center.longitude
tryCompare(flickStartedSpy, "count", 1)
tryCompare(panFinishedSpy, "count", 1)
tryCompare(flickFinishedSpy, "count", 1)
verify(map.center.latitude > moveLatitude)
verify(map.center.longitude < moveLongitude)
}
function disabled_flicking()
{
map.center.latitude = 50
map.center.longitude = 50
mousePress(page, 0, 0)
for (var i = 0; i < 50; i += 5) {
wait(25)
mouseMove(page, i, i, 0, Qt.LeftButton);
}
mouseRelease(page, 50, 50)
compare(panStartedSpy.count, 0)
compare(panFinishedSpy.count, 0)
compare(flickStartedSpy.count, 0)
compare(flickFinishedSpy.count, 0)
}
function test_disabled_flicking_with_nogesture()
{
map.gesture.acceptedGestures = MapGestureArea.NoGesture
}
function test_disabled_flicking_with_disabled()
{
map.gesture.enabled = false
disabled_flicking()
}
function disable_onFlickStarted()
{
map.center.latitude = 50
map.center.longitude = 50
mousePress(page, 0, 0)
for (var i = 0; i < 50; i += 5) {
wait(25)
mouseMove(page, i, i, 0, Qt.LeftButton);
}
mouseRelease(page, 50, 50)
var latitude = map.center.latitude;
var longitude = map.center.longitude
tryCompare(panStartedSpy, "count", 1)
tryCompare(flickStartedSpy, "count", 1)
verify(map.center.latitude > 50)
tryCompare(panFinishedSpy, "count", 1)
tryCompare(flickFinishedSpy, "count", 1)
// compare that flick was interrupted (less movement than without interrupting)
compare(latitude, map.center.latitude)
compare(longitude, map.center.longitude)
}
function test_disable_onFlickStarted_with_disabled()
{
map.disableOnFlickStartedWithDisabled = true
disable_onFlickStarted()
}
function test_disable_onFlickStarted_with_nogesture()
{
map.disableOnFlickStartedWithNoGesture = true
disable_onFlickStarted()
}
function disable_onPanStarted()
{
map.center.latitude = 50
map.center.longitude = 50
mousePress(page, 0, 0)
for (var i = 0; i < 50; i += 5) {
wait(25)
mouseMove(page, i, i, 0, Qt.LeftButton);
}
mouseRelease(page, 50, 50)
compare(map.center.latitude,50)
compare(map.center.longitude,50)
tryCompare(panFinishedSpy, "count", 1)
// compare that flick was interrupted (less movement than without interrupting)
compare(map.center.latitude,50)
compare(map.center.longitude,50)
compare(map.gesture.panActive, false)
}
function test_disable_onPanStarted_with_disabled()
{
map.disableOnPanStartedWithDisabled = true
disable_onPanStarted()
}
function test_disable_onPanStarted_with_nogesture()
{
map.disableOnPanStartedWithNoGesture = true
disable_onPanStarted()
}
/*
Regression test for QTBUG-67580 where touching the map
(as opposing to clicking it with a mouse) would cause a crash.
So this test is merely about surviving a tap.
*/
function test_touch()
{
touchEvent(map).press(0).commit();
wait(25);
touchEvent(map).release(0).commit();
}
}
}
|