1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the test suite of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 as published by the Free Software
20** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21** included in the packaging of this file. Please review the following
22** information to ensure the GNU General Public License requirements will
23** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24**
25** $QT_END_LICENSE$
26**
27****************************************************************************/
28
29import QtQuick 2.0
30import QtTest 1.0
31import QtPositioning 5.5
32import QtLocation 5.10
33import QtLocation.Test 5.6
34
35Item {
36    width:100
37    height:100
38    // General-purpose elements for the test:
39    Plugin { id: testPlugin; name: "qmlgeo.test.plugin"; allowExperimental: true }
40    Plugin { id: testPlugin2; name: "gmlgeo.test.plugin"; allowExperimental: true }
41    Plugin {
42        id: testPluginLazyParameter;
43        name: "qmlgeo.test.plugin"
44        allowExperimental: true
45        property string extraTypeName : undefined
46        PluginParameter { name: "supported"; value: true}
47        PluginParameter { name: "finishRequestImmediately"; value: true}
48        PluginParameter { name: "validateWellKnownValues"; value: true}
49        PluginParameter { name: "extraMapTypeName"; value: testPluginLazyParameter.extraTypeName}
50
51        Component.onCompleted: {
52            extraTypeName = "SomeString"
53        }
54    }
55    Plugin {
56        id: testPluginNoVisibleArea;
57        name: "qmlgeo.test.plugin";
58        allowExperimental: true
59        PluginParameter { name: "supportVisibleArea"; value: false}
60    }
61    Plugin { id: itemsOverlay; name: "itemsoverlay"; }
62
63    property variant coordinate1: QtPositioning.coordinate(10, 11)
64    property variant coordinate2: QtPositioning.coordinate(12, 13)
65    property variant coordinate3: QtPositioning.coordinate(50, 50, 0)
66    property variant coordinate4: QtPositioning.coordinate(80, 80, 0)
67    property variant coordinate5: QtPositioning.coordinate(20, 180)
68    property variant coordinateCenterVisibleRegion: QtPositioning.coordinate(27, 77)
69    property variant coordinateVisible1: QtPositioning.coordinate(28, 77)
70    property variant coordinateVisible2: QtPositioning.coordinate(33, 79.1)
71    property variant coordinateVisible3: QtPositioning.coordinate(27, 80.5)
72    property variant invalidCoordinate: QtPositioning.coordinate()
73    property variant altitudelessCoordinate: QtPositioning.coordinate(50, 50)
74    property bool allMapsReady: mapZoomOnCompleted.mapReady
75                                && mapZoomDefault.mapReady
76                                && mapZoomUserInit.mapReady
77                                && map.mapReady
78                                && mapPar.mapReady
79                                && coordinateMap.mapReady
80                                && mapTiltBearing.mapReady
81                                && mapTiltBearingHere.mapReady
82                                && mapTestProjection.mapReady
83
84    Map { id: mapZoomOnCompleted; width: 200; height: 200;
85        zoomLevel: 3; center: coordinate1; plugin: testPlugin;
86        Component.onCompleted: {
87            zoomLevel = 7
88        }
89    }
90    SignalSpy {id: mapZoomSpy; target: mapZoomOnCompleted; signalName: 'zoomLevelChanged'}
91
92    Map { id: mapZoomDefault; width: 200; height: 200;
93        center: coordinate1; plugin: testPlugin; }
94
95    Map { id: mapZoomUserInit; width: 210; height: 210;
96        zoomLevel: 4; center: coordinate1; plugin: testPlugin;
97        Component.onCompleted: {
98            console.log("mapZoomUserInit completed")
99        }
100    }
101
102    Map { id: mapVisibleRegion; width: 800; height: 600;
103        center: coordinateCenterVisibleRegion; plugin: testPlugin; zoomLevel: 1.0 }
104
105    Map {id: map; plugin: testPlugin; center: coordinate1; width: 100; height: 100}
106    SignalSpy {id: mapCenterSpy; target: map; signalName: 'centerChanged'}
107
108    Map {id: mapPar; plugin: testPlugin; center: coordinate1; width: 512; height: 512}
109
110    Map {id: coordinateMap; plugin: testPlugin; center: coordinate3;
111        width: 1000; height: 1000; zoomLevel: 15 }
112
113    Map {id: mapTiltBearing; plugin: testPlugin; center: coordinate1;
114        width: 1000; height: 1000; zoomLevel: 4; bearing: 45.0; tilt: 25.0 }
115
116    Map {id: mapTiltBearingHere; plugin: testPlugin; center: coordinate1;
117        width: 1000; height: 1000; zoomLevel: 4; bearing: 45.0; tilt: 25.0 }
118
119    Map {
120        id: mapWithLazyPlugin
121        plugin: testPluginLazyParameter
122    }
123
124    Map {
125        id: mapTestProjection
126        plugin: testPlugin
127        width: 200
128        height: 200
129    }
130
131    MapParameter {
132        id: testParameter
133        type: "cameraCenter_test"
134        property var center: QtPositioning.coordinate(-33.0, -47.0)
135    }
136
137    Map {
138        id: mapVisibleArea
139        width: 256; height: 256;
140    }
141    Map {
142        id: mapVisibleAreaUnsupported
143        width: 256; height: 256;
144    }
145    SignalSpy { id: visibleAreaSpy; target: mapVisibleArea; signalName: 'visibleAreaChanged'}
146    SignalSpy { id: visibleAreaUnsupportedSpy; target: mapVisibleAreaUnsupported; signalName: 'visibleAreaChanged'}
147
148    TestCase {
149        when: windowShown && allMapsReady
150        name: "MapProperties"
151
152        function fuzzy_compare(val, ref) {
153            var tolerance = 0.01;
154            if ((val > ref - tolerance) && (val < ref + tolerance))
155                return true;
156            console.log('map fuzzy cmp returns false for value, ref: ' + val + ', ' + ref)
157            return false;
158        }
159
160        function init() {
161            mapCenterSpy.clear();
162        }
163
164        function test_lazy_parameter() {
165            compare(mapWithLazyPlugin.supportedMapTypes.length, 5)
166            compare(mapWithLazyPlugin.supportedMapTypes[4].name, "SomeString")
167        }
168
169        function test_map_center() {
170            // coordinate is set at map element declaration
171            compare(map.center.latitude, 10)
172            compare(map.center.longitude, 11)
173
174            // change center and its values
175            mapCenterSpy.clear();
176            compare(mapCenterSpy.count, 0)
177            map.center = coordinate2
178            compare(mapCenterSpy.count, 1)
179            map.center = coordinate2
180            compare(mapCenterSpy.count, 1)
181
182            // change center to dateline
183            mapCenterSpy.clear()
184            compare(mapCenterSpy.count, 0)
185            map.center = coordinate5
186            compare(mapCenterSpy.count, 1)
187            compare(map.center, coordinate5)
188
189            map.center = coordinate2
190
191            verify(isNaN(map.center.altitude));
192            compare(map.center.longitude, 13)
193            compare(map.center.latitude, 12)
194        }
195
196        function test_map_visible_region()
197        {
198            mapVisibleRegion.zoomLevel = 1.0
199            wait(50)
200            verify(mapVisibleRegion.visibleRegion.contains(coordinateVisible1))
201            verify(mapVisibleRegion.visibleRegion.contains(coordinateVisible2))
202            verify(mapVisibleRegion.visibleRegion.contains(coordinateVisible3))
203
204            mapVisibleRegion.zoomLevel = 1.88
205            verify(LocationTestHelper.waitForPolished(mapVisibleRegion))
206            verify(mapVisibleRegion.visibleRegion.contains(coordinateVisible1))
207            verify(mapVisibleRegion.visibleRegion.contains(coordinateVisible2))
208            verify(mapVisibleRegion.visibleRegion.contains(coordinateVisible3))
209
210            mapVisibleRegion.zoomLevel = 2.12
211            verify(LocationTestHelper.waitForPolished(mapVisibleRegion))
212            verify(mapVisibleRegion.visibleRegion.contains(coordinateVisible1))
213            verify(mapVisibleRegion.visibleRegion.contains(coordinateVisible2))
214            verify(mapVisibleRegion.visibleRegion.contains(coordinateVisible3))
215
216            mapVisibleRegion.zoomLevel = 2.5
217            verify(LocationTestHelper.waitForPolished(mapVisibleRegion))
218            verify(mapVisibleRegion.visibleRegion.contains(coordinateVisible1))
219            verify(mapVisibleRegion.visibleRegion.contains(coordinateVisible2))
220            verify(mapVisibleRegion.visibleRegion.contains(coordinateVisible3))
221
222            mapVisibleRegion.zoomLevel = 2.7
223            verify(LocationTestHelper.waitForPolished(mapVisibleRegion))
224            verify(mapVisibleRegion.visibleRegion.contains(coordinateVisible1))
225            verify(mapVisibleRegion.visibleRegion.contains(coordinateVisible2))
226            verify(mapVisibleRegion.visibleRegion.contains(coordinateVisible3))
227        }
228
229        function test_map_parameters()
230        {
231            // coordinate is set at map element declaration
232            var center = mapPar.toCoordinate(Qt.point((mapPar.width - 1) / 2.0, (mapPar.height - 1) / 2.0))
233            fuzzyCompare(center.latitude, 10, 0.1)
234            fuzzyCompare(center.longitude, 11, 0.1)
235
236            compare(mapPar.mapParameters.length, 0)
237
238            mapPar.addMapParameter(testParameter)
239
240            compare(mapPar.mapParameters.length, 1)
241
242            // Using toCoordinate, below, to verify the actual value of the center, and not what is in the map.center property
243            center = mapPar.toCoordinate(Qt.point((mapPar.width - 1) / 2.0, (mapPar.height - 1) / 2.0))
244            fuzzyCompare(center.latitude, -33, 0.1)
245            fuzzyCompare(center.longitude, -47, 0.1)
246
247            mapPar.addMapParameter(testParameter)
248            compare(mapPar.mapParameters.length, 1)
249
250            mapPar.removeMapParameter(testParameter)
251            compare(mapPar.mapParameters.length, 0)
252
253            center = mapPar.toCoordinate(Qt.point((mapPar.width - 1) / 2.0, (mapPar.height - 1) / 2.0))
254            fuzzyCompare(center.latitude, -33, 0.1)
255            fuzzyCompare(center.longitude, -47, 0.1)
256
257            testParameter.center = mapPar.center  // map.center has been affected as the Declarative Map has received the QGeoMap::cameraDataChanged signal
258            mapPar.addMapParameter(testParameter)
259            compare(mapPar.mapParameters.length, 1)
260
261            center = mapPar.toCoordinate(Qt.point((mapPar.width - 1) / 2.0, (mapPar.height - 1) / 2.0))
262            fuzzyCompare(center.latitude, -33, 0.1)
263            fuzzyCompare(center.longitude, -47, 0.1)
264
265            testParameter.center = QtPositioning.coordinate(-30.0, -40.0)
266
267            center = mapPar.toCoordinate(Qt.point((mapPar.width - 1) / 2.0, (mapPar.height - 1) / 2.0))
268            fuzzyCompare(center.latitude, -30, 0.1)
269            fuzzyCompare(center.longitude, -40, 0.1)
270            fuzzyCompare(mapPar.center.latitude, -30, 0.1)
271            fuzzyCompare(mapPar.center.longitude, -40, 0.1)
272
273            mapPar.removeMapParameter(testParameter)
274            compare(mapPar.mapParameters.length, 0)
275        }
276
277        function test_map_clamp()
278        {
279            //valid
280            map.center = QtPositioning.coordinate(10.0, 20.5, 30.8)
281            map.zoomLevel = 2.0
282
283            compare(map.center.latitude, 10)
284            compare(map.center.longitude, 20.5)
285            compare(map.center.altitude, 30.8)
286
287            //negative values
288            map.center = QtPositioning.coordinate(-50, -20, 100)
289            map.zoomLevel = 1.0
290
291            compare(map.center.latitude, -50)
292            compare(map.center.longitude, -20)
293            compare(map.center.altitude, 100)
294
295            //clamped center negative
296            map.center = QtPositioning.coordinate(-89, -45, 0)
297            map.zoomLevel = 1.0
298
299            fuzzyCompare(map.center.latitude, -80.8728, 0.001)
300            compare(map.center.longitude, -45)
301            compare(map.center.altitude, 0)
302
303            //clamped center positive
304            map.center = QtPositioning.coordinate(86, 38, 0)
305            map.zoomLevel = 1.0
306
307            fuzzyCompare(map.center.latitude, 80.8728, 0.001)
308            compare(map.center.longitude, 38)
309            compare(map.center.altitude, 0)
310        }
311
312        function test_zoom_limits()
313        {
314            map.center.latitude = 30
315            map.center.longitude = 60
316            map.zoomLevel = 4
317
318            //initial plugin values
319            compare(map.minimumZoomLevel, 0)
320            compare(map.maximumZoomLevel, 20)
321            compare(map.activeMapType.cameraCapabilities.minimumZoomLevel, 0)
322            compare(map.activeMapType.cameraCapabilities.maximumZoomLevel, 20)
323
324            //Higher min level than curr zoom, should change curr zoom
325            map.minimumZoomLevel = 5
326            map.maximumZoomLevel = 18
327            compare(map.zoomLevel, 5)
328            compare(map.minimumZoomLevel, 5)
329            compare(map.maximumZoomLevel, 18)
330
331            //Trying to set higher than max, max should be set.
332            map.maximumZoomLevel = 21
333            compare(map.minimumZoomLevel, 5)
334            compare(map.maximumZoomLevel, 20)
335
336            //Negative values should be ignored
337            map.minimumZoomLevel = -1
338            map.maximumZoomLevel = -2
339            compare(map.minimumZoomLevel, 5)
340            compare(map.maximumZoomLevel, 20)
341
342            //Max limit lower than curr zoom, should change curr zoom
343            map.zoomLevel = 18
344            map.maximumZoomLevel = 16
345            compare(map.zoomLevel, 16)
346            compare(map.activeMapType.cameraCapabilities.minimumZoomLevel, 0)
347            compare(map.activeMapType.cameraCapabilities.maximumZoomLevel, 20)
348
349            //reseting default
350            map.minimumZoomLevel = 0
351            map.maximumZoomLevel = 20
352            compare(map.minimumZoomLevel, 0)
353            compare(map.maximumZoomLevel, 20)
354        }
355
356        function test_tilt_limits()
357        {
358            map.tilt = 0
359
360            //initial plugin values
361            compare(map.minimumTilt, 0)
362            compare(map.maximumTilt, 60)
363            compare(map.activeMapType.cameraCapabilities.minimumTilt, 0)
364            compare(map.activeMapType.cameraCapabilities.maximumTilt, 60)
365
366            //Higher min level than curr tilt, should change curr tilt
367            map.minimumTilt = 5
368            map.maximumTilt = 18
369            compare(map.tilt, 5)
370            compare(map.minimumTilt, 5)
371            compare(map.maximumTilt, 18)
372            // Capabilities remain the same
373            compare(map.activeMapType.cameraCapabilities.minimumTilt, 0)
374            compare(map.activeMapType.cameraCapabilities.maximumTilt, 60)
375
376            //Trying to set higher than max, max should be set.
377            map.maximumTilt = 61
378            compare(map.minimumTilt, 5)
379            compare(map.maximumTilt, 60)
380
381            //Negative values should be ignored
382            map.minimumTilt = -1
383            map.maximumTilt = -2
384            compare(map.minimumTilt, 5)
385            compare(map.maximumTilt, 60)
386
387            //Max limit lower than curr zoom, should change curr zoom
388            map.tilt = 18
389            map.maximumTilt = 16
390            compare(map.tilt, 16)
391
392            //resetting default
393            map.minimumTilt = 0
394            map.maximumTilt = 60
395            map.tilt = 0
396            compare(map.minimumTilt, 0)
397            compare(map.maximumTilt, 60)
398            compare(map.tilt, 0)
399        }
400
401        function test_fov_limits()
402        {
403            map.fieldOfView = 45
404
405            //initial plugin values
406            compare(map.minimumFieldOfView, 45)
407            compare(map.maximumFieldOfView, 45)
408            compare(map.activeMapType.cameraCapabilities.minimumFieldOfView, 45)
409            compare(map.activeMapType.cameraCapabilities.maximumFieldOfView, 45)
410
411            map.minimumFieldOfView = 5
412            map.maximumFieldOfView = 18
413            map.fieldOfView = 4
414            compare(map.fieldOfView, 45)
415            compare(map.minimumFieldOfView, 45)
416            compare(map.maximumFieldOfView, 45)
417
418            map.activeMapType = map.supportedMapTypes[3]
419            // camera caps are [1-179], user previously asked for [5-18]
420            compare(map.minimumFieldOfView, 5)
421            compare(map.maximumFieldOfView, 18)
422            compare(map.activeMapType.cameraCapabilities.minimumFieldOfView, 1)
423            compare(map.activeMapType.cameraCapabilities.maximumFieldOfView, 179)
424
425            map.fieldOfView = 4
426            compare(map.fieldOfView, 5)
427
428            //Higher min level than curr fieldOfView, should change curr fieldOfView
429            map.minimumFieldOfView = 6
430            compare(map.fieldOfView, 6)
431            compare(map.minimumFieldOfView, 6)
432            compare(map.maximumFieldOfView, 18)
433
434            //Trying to set higher than max, max should be set.
435            map.maximumFieldOfView = 179.5
436            compare(map.minimumFieldOfView, 6)
437            compare(map.maximumFieldOfView, 179)
438
439            //Negative values should be ignored
440            map.minimumFieldOfView = -1
441            map.maximumFieldOfView = -2
442            compare(map.minimumFieldOfView, 6)
443            compare(map.maximumFieldOfView, 179)
444
445            //Max limit lower than curr zoom, should change curr zoom
446            map.fieldOfView = 18
447            compare(map.fieldOfView, 18)
448            map.maximumFieldOfView = 16
449            compare(map.maximumFieldOfView, 16)
450            compare(map.fieldOfView, 16)
451
452            //resetting default
453            map.minimumFieldOfView = 1
454            map.maximumFieldOfView = 179
455            compare(map.minimumFieldOfView, 1)
456            compare(map.maximumFieldOfView, 179)
457
458            map.activeMapType = map.supportedMapTypes[0]
459            compare(map.minimumFieldOfView, 45)
460            compare(map.maximumFieldOfView, 45)
461            compare(map.fieldOfView, 45)
462            compare(map.activeMapType.cameraCapabilities.minimumFieldOfView, 45)
463            compare(map.activeMapType.cameraCapabilities.maximumFieldOfView, 45)
464        }
465
466        function test_zoom()
467        {
468            wait(1000)
469            compare(mapZoomOnCompleted.zoomLevel, 7)
470            compare(mapZoomDefault.zoomLevel, 8)
471            compare(mapZoomUserInit.zoomLevel, 4)
472
473            mapZoomSpy.clear()
474            mapZoomOnCompleted.zoomLevel = 6
475            tryCompare(mapZoomSpy, "count", 1)
476        }
477
478        function test_pan()
479        {
480            map.center.latitude = 30
481            map.center.longitude = 60
482            map.zoomLevel = 4
483            mapCenterSpy.clear();
484
485            // up left
486            tryCompare(mapCenterSpy, "count", 0)
487            map.pan(-20,-20)
488            tryCompare(mapCenterSpy, "count", 1)
489            verify(map.center.latitude > 30)
490            verify(map.center.longitude < 60)
491            map.center.latitude = 30
492            map.center.longitude = 60
493            mapCenterSpy.clear()
494            // up
495            map.pan(0,-20)
496            tryCompare(mapCenterSpy, "count", 1)
497            verify(map.center.latitude > 30)
498            compare(map.center.longitude, 60)
499            map.center.latitude = 30
500            map.center.longitude = 60
501            mapCenterSpy.clear()
502            // up right
503            tryCompare(mapCenterSpy, "count", 0)
504            map.pan(20,-20)
505            tryCompare(mapCenterSpy, "count", 1)
506            verify(map.center.latitude > 30)
507            verify(map.center.longitude > 60)
508            map.center.latitude = 30
509            map.center.longitude = 60
510            mapCenterSpy.clear()
511            // left
512            map.pan(-20,0)
513            tryCompare(mapCenterSpy, "count", 1)
514            verify (fuzzy_compare(map.center.latitude, 30))
515            verify(map.center.longitude < 60)
516            map.center.latitude = 30
517            map.center.longitude = 60
518            mapCenterSpy.clear()
519            // center
520            map.pan(0,0)
521            tryCompare(mapCenterSpy, "count", 0)
522            compare(map.center.latitude, 30)
523            compare(map.center.longitude, 60)
524            map.center.latitude = 30
525            map.center.longitude = 60
526            mapCenterSpy.clear()
527            // right
528            map.pan(20,0)
529            tryCompare(mapCenterSpy, "count", 1)
530            verify (fuzzy_compare(map.center.latitude, 30))
531            verify(map.center.longitude > 60)
532            map.center.latitude = 30
533            map.center.longitude = 60
534            mapCenterSpy.clear()
535            // down left
536            map.pan(-20,20)
537            tryCompare(mapCenterSpy, "count", 1)
538            verify (map.center.latitude < 30 )
539            verify (map.center.longitude < 60 )
540            map.center.latitude = 30
541            map.center.longitude = 60
542            mapCenterSpy.clear()
543            // down
544            map.pan(0,20)
545            tryCompare(mapCenterSpy, "count", 1)
546            verify (map.center.latitude < 30 )
547            verify (fuzzy_compare(map.center.longitude, 60))
548            map.center.latitude = 30
549            map.center.longitude = 60
550            mapCenterSpy.clear()
551            // down right
552            map.pan(20,20)
553            tryCompare(mapCenterSpy, "count", 1)
554            verify (map.center.latitude < 30 )
555            verify (map.center.longitude > 60 )
556            map.center.latitude = 30
557            map.center.longitude = 60
558            mapCenterSpy.clear()
559        }
560
561        function test_map_tilt_bearing()
562        {
563            compare(map.bearing, 0.0)
564            compare(map.tilt, 0.0)
565            compare(mapTiltBearing.bearing, 45.0)
566            compare(mapTiltBearing.tilt, 25.0)
567            compare(mapTiltBearingHere.bearing, 45.0)
568            compare(mapTiltBearingHere.tilt, 25.0)
569
570            mapTiltBearing.bearing = 0.0
571            mapTiltBearing.tilt = 0.0
572            compare(mapTiltBearing.bearing, 0.0)
573            compare(mapTiltBearing.tilt, 0.0)
574
575            mapTiltBearing.bearing = 480.0
576            mapTiltBearing.tilt = 140.0
577            compare(mapTiltBearing.bearing, 120.0)
578            compare(mapTiltBearing.tilt, 60.0)
579
580            mapTiltBearing.tilt = -140.0
581            compare(mapTiltBearing.tilt, 0.0)
582
583            mapTiltBearingHere.bearing = 45.0
584            mapTiltBearingHere.tilt = 25.0
585            compare(mapTiltBearingHere.bearing, 45.0)
586            compare(mapTiltBearingHere.tilt, 25.0)
587            mapTiltBearingHere.bearing = 0.0
588            mapTiltBearingHere.tilt = 0.0
589            compare(mapTiltBearingHere.bearing, 0.0)
590            compare(mapTiltBearingHere.tilt, 0.0)
591
592            mapTiltBearing.bearing = 45.0
593            mapTiltBearing.tilt = 25.0
594            mapTiltBearing.zoomLevel = 8.0
595            compare(mapTiltBearing.bearing, 45.0)
596            compare(mapTiltBearing.tilt, 25.0)
597        }
598
599        function test_map_setbearing()
600        {
601            var zeroCoord = QtPositioning.coordinate(0,0)
602            mapTiltBearing.bearing = 0.0
603            mapTiltBearing.tilt = 0.0
604            mapTiltBearing.zoomLevel = 3
605            mapTiltBearing.center = zeroCoord
606            compare(mapTiltBearing.bearing, 0.0)
607            compare(mapTiltBearing.tilt, 0.0)
608            compare(mapTiltBearing.zoomLevel, 3)
609            compare(mapTiltBearing.center, zeroCoord)
610
611            var fulcrum = QtPositioning.coordinate(20,-20)
612            var fulcrumPos = mapTiltBearing.fromCoordinate(fulcrum)
613            var bearing = 90.0
614            mapTiltBearing.setBearing(bearing, fulcrum)
615            var fulcrumPosAfter = mapTiltBearing.fromCoordinate(fulcrum)
616            compare(mapTiltBearing.bearing, bearing)
617            compare(fulcrumPos, fulcrumPosAfter)
618
619            // resetting
620            mapTiltBearing.center = coordinate1
621            mapTiltBearing.zoomLevel = 4
622            mapTiltBearing.bearing = 45.0
623            mapTiltBearing.tilt = 25.0
624        }
625
626        function test_map_align_coordinate_to_point()
627        {
628            var zeroCoord = QtPositioning.coordinate(0,0)
629            mapTiltBearing.bearing = 0.0
630            mapTiltBearing.tilt = 0.0
631            mapTiltBearing.zoomLevel = 3
632            mapTiltBearing.center = zeroCoord
633            compare(mapTiltBearing.bearing, 0.0)
634            compare(mapTiltBearing.tilt, 0.0)
635            compare(mapTiltBearing.zoomLevel, 3)
636            compare(mapTiltBearing.center, zeroCoord)
637
638            var coord = QtPositioning.coordinate(20,-20)
639            var point = Qt.point(400, 400)
640            mapTiltBearing.alignCoordinateToPoint(coord, point)
641            var coordAfter = mapTiltBearing.toCoordinate(point)
642            compare(coord.latitude, coordAfter.latitude)
643            compare(coord.longitude, coordAfter.longitude)
644
645            // resetting
646            mapTiltBearing.center = coordinate1
647            mapTiltBearing.zoomLevel = 4
648            mapTiltBearing.bearing = 45.0
649            mapTiltBearing.tilt = 25.0
650        }
651
652        function test_coordinate_conversion()
653        {
654            wait(1000)
655            mapCenterSpy.clear();
656            compare(coordinateMap.center.latitude, 50)
657            compare(coordinateMap.center.longitude, 50)
658            // valid to screen position
659            var point = coordinateMap.fromCoordinate(coordinateMap.center)
660            verify (point.x > 495 && point.x < 505)
661            verify (point.y > 495 && point.y < 505)
662            // valid coordinate without altitude
663            point = coordinateMap.fromCoordinate(altitudelessCoordinate)
664            verify (point.x > 495 && point.x < 505)
665            verify (point.y > 495 && point.y < 505)
666            // out of map area in view
667            //var oldZoomLevel = coordinateMap.zoomLevel
668            //coordinateMap.zoomLevel = 8
669            point = coordinateMap.fromCoordinate(coordinate4)
670            verify(isNaN(point.x))
671            verify(isNaN(point.y))
672            //coordinateMap.zoomLevel = oldZoomLevel
673            // invalid coordinates
674            point = coordinateMap.fromCoordinate(invalidCoordinate)
675            verify(isNaN(point.x))
676            verify(isNaN(point.y))
677            point = coordinateMap.fromCoordinate(null)
678            verify(isNaN(point.x))
679            verify(isNaN(point.y))
680            // valid point to coordinate
681            var coord = coordinateMap.toCoordinate(Qt.point(500,500))
682            verify(coord.latitude > 49 && coord.latitude < 51)
683            verify(coord.longitude > 49 && coord.longitude < 51)
684            // beyond
685            coord = coordinateMap.toCoordinate(Qt.point(2000, 2000))
686            verify(isNaN(coord.latitude))
687            verify(isNaN(coord.longitde))
688            // invalid
689            coord = coordinateMap.toCoordinate(Qt.point(-5, -6))
690            verify(isNaN(coord.latitude))
691            verify(isNaN(coord.longitde))
692
693            // test with tilting
694            coord = QtPositioning.coordinate(45.6, 17.67)
695            var pos = mapTestProjection.fromCoordinate(coord, false)
696            compare(Math.floor(pos.x), 3339)
697            compare(Math.floor(pos.y), 1727)
698            mapTestProjection.tilt = 6
699            pos = mapTestProjection.fromCoordinate(coord, false)
700            compare(Math.floor(pos.x), 11066)
701            compare(Math.floor(pos.y), 5577)
702            mapTestProjection.tilt = 12
703            pos = mapTestProjection.fromCoordinate(coord, false)
704            verify(isNaN(pos.latitude))
705            verify(isNaN(pos.longitde))
706        }
707
708        function test_visible_area()
709        {
710            wait(1000)
711            visibleAreaSpy.clear();
712            visibleAreaUnsupportedSpy.clear();
713            var defaultRect = Qt.rect(0,0,0,0)
714
715            verify(mapVisibleAreaUnsupported.visibleArea, defaultRect)
716            mapVisibleAreaUnsupported.visibleArea = Qt.rect(0,0,256,256)
717            compare(visibleAreaUnsupportedSpy.count, 1)
718            verify(mapVisibleAreaUnsupported.visibleArea, Qt.rect(0,0,256,256))
719            mapVisibleAreaUnsupported.plugin = testPluginNoVisibleArea
720            tryCompare(visibleAreaUnsupportedSpy, "count", 2)
721            verify(mapVisibleAreaUnsupported.visibleArea, defaultRect)
722
723            verify(mapVisibleArea.visibleArea, defaultRect)
724            mapVisibleArea.visibleArea = Qt.rect(0,0,256,256)
725            compare(visibleAreaSpy.count, 1)
726            verify(mapVisibleArea.visibleArea, Qt.rect(0,0,256,256))
727            mapVisibleArea.plugin = testPlugin
728            tryCompare(visibleAreaSpy, "count", 1)
729            verify(mapVisibleAreaUnsupported.visibleArea, Qt.rect(0,0,256,256))
730        }
731    }
732}
733