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
|
/****************************************************************************
**
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/
**
** 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
Item {
width:100
height:100
// General-purpose elements for the test:
Plugin { id: testPlugin; name: "qmlgeo.test.plugin"; allowExperimental: true }
Plugin { id: testPlugin2; name: "gmlgeo.test.plugin"; allowExperimental: true }
Plugin { id: nokiaPlugin; name: "nokia";
parameters: [
PluginParameter {
name: "app_id"
value: "stub"
},
PluginParameter {
name: "token"
value: "stub"
}
]
}
property variant coordinate1: QtLocation.coordinate(10, 11)
property variant coordinate2: QtLocation.coordinate(12, 13)
property variant coordinate3: QtLocation.coordinate(50, 50, 0)
property variant coordinate4: QtLocation.coordinate(80, 80, 0)
property variant invalidCoordinate: QtLocation.coordinate()
property variant altitudelessCoordinate: QtLocation.coordinate(50, 50)
Map {id: map; plugin: testPlugin; center: coordinate1; width: 100; height: 100}
Map {id: coordinateMap; plugin: nokiaPlugin; center: coordinate3; width: 1000; height: 1000; zoomLevel: 15}
SignalSpy {id: mapCenterSpy; target: map; signalName: 'centerChanged'}
TestCase {
when: windowShown
name: "Basic Map properties"
function fuzzy_compare(val, ref) {
var tolerance = 0.01;
if ((val > ref - tolerance) && (val < ref + tolerance))
return true;
console.log('map fuzzy cmp returns false for value, ref: ' + val + ', ' + ref)
return false;
}
function test_map_center() {
mapCenterSpy.clear();
// coordinate is set at map element declaration
compare(map.center.latitude, 10)
compare(map.center.longitude, 11)
// change center and its values
mapCenterSpy.clear();
compare(mapCenterSpy.count, 0)
map.center = coordinate2
compare(mapCenterSpy.count, 1)
map.center = coordinate2
compare(mapCenterSpy.count, 1)
verify(isNaN(map.center.altitude));
compare(map.center.longitude, 13)
compare(map.center.latitude, 12)
}
function test_pan() {
map.center.latitude = 30
map.center.longitude = 60
map.zoomLevel = 4
mapCenterSpy.clear();
// up left
tryCompare(mapCenterSpy, "count", 0)
map.pan(-20,-20)
tryCompare(mapCenterSpy, "count", 1)
verify(map.center.latitude > 30)
verify(map.center.longitude < 60)
map.center.latitude = 30
map.center.longitude = 60
mapCenterSpy.clear()
// up
map.pan(0,-20)
tryCompare(mapCenterSpy, "count", 1)
verify(map.center.latitude > 30)
compare(map.center.longitude, 60)
map.center.latitude = 30
map.center.longitude = 60
mapCenterSpy.clear()
// up right
tryCompare(mapCenterSpy, "count", 0)
map.pan(20,-20)
tryCompare(mapCenterSpy, "count", 1)
verify(map.center.latitude > 30)
verify(map.center.longitude > 60)
map.center.latitude = 30
map.center.longitude = 60
mapCenterSpy.clear()
// left
map.pan(-20,0)
tryCompare(mapCenterSpy, "count", 1)
verify (fuzzy_compare(map.center.latitude, 30))
verify(map.center.longitude < 60)
map.center.latitude = 30
map.center.longitude = 60
mapCenterSpy.clear()
// center
map.pan(0,0)
tryCompare(mapCenterSpy, "count", 0)
compare(map.center.latitude, 30)
compare(map.center.longitude, 60)
map.center.latitude = 30
map.center.longitude = 60
mapCenterSpy.clear()
// right
map.pan(20,0)
tryCompare(mapCenterSpy, "count", 1)
verify (fuzzy_compare(map.center.latitude, 30))
verify(map.center.longitude > 60)
map.center.latitude = 30
map.center.longitude = 60
mapCenterSpy.clear()
// down left
map.pan(-20,20)
tryCompare(mapCenterSpy, "count", 1)
verify (map.center.latitude < 30 )
verify (map.center.longitude < 60 )
map.center.latitude = 30
map.center.longitude = 60
mapCenterSpy.clear()
// down
map.pan(0,20)
tryCompare(mapCenterSpy, "count", 1)
verify (map.center.latitude < 30 )
verify (fuzzy_compare(map.center.longitude, 60))
map.center.latitude = 30
map.center.longitude = 60
mapCenterSpy.clear()
// down right
map.pan(20,20)
tryCompare(mapCenterSpy, "count", 1)
verify (map.center.latitude < 30 )
verify (map.center.longitude > 60 )
map.center.latitude = 30
map.center.longitude = 60
mapCenterSpy.clear()
}
function test_coordinate_conversion() {
wait(1000)
mapCenterSpy.clear();
compare(coordinateMap.center.latitude, 50)
compare(coordinateMap.center.longitude, 50)
// valid to screen position
var point = coordinateMap.toScreenPosition(coordinateMap.center)
verify (point.x > 495 && point.x < 505)
verify (point.y > 495 && point.y < 505)
// valid coordinate without altitude
point = coordinateMap.toScreenPosition(altitudelessCoordinate)
verify (point.x > 495 && point.x < 505)
verify (point.y > 495 && point.y < 505)
// out of map area
point = coordinateMap.toScreenPosition(coordinate4)
verify(isNaN(point.x))
verify(isNaN(point.y))
// invalid coordinates
point = coordinateMap.toScreenPosition(invalidCoordinate)
verify(isNaN(point.x))
verify(isNaN(point.y))
point = coordinateMap.toScreenPosition(null)
verify(isNaN(point.x))
verify(isNaN(point.y))
// valid point to coordinate
var coord = coordinateMap.toCoordinate(Qt.point(500,500))
verify(coord.latitude > 49 && coord.latitude < 51)
verify(coord.longitude > 49 && coord.longitude < 51)
// beyond
coord = coordinateMap.toCoordinate(Qt.point(2000, 2000))
verify(isNaN(coord.latitude))
verify(isNaN(coord.longitde))
// invalid
coord = coordinateMap.toCoordinate(Qt.point(-5, -6))
verify(isNaN(coord.latitude))
verify(isNaN(coord.longitde))
}
}
}
|