Skip to content

Commit d2fe9a8

Browse files
committed
fix qml test import error
1 parent 9a9e371 commit d2fe9a8

3 files changed

Lines changed: 58 additions & 39 deletions

File tree

include/SimpleMapView.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ class SimpleMapView : public SimpleMapViewBase
7070
Resource
7171
};
7272

73+
#ifdef SIMPLE_MAP_VIEW_USE_QML
74+
Q_ENUM(TileServerSource);
75+
#endif
76+
7377
explicit SimpleMapView(SimpleMapViewBase* parent = nullptr);
7478
~SimpleMapView() = default;
7579

tests/CMakeLists.txt

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,16 @@ if(SIMPLE_MAP_VIEW_BUILD_QML)
99
../Resources.qrc
1010
SimpleMapViewQmlTest.cpp
1111
)
12-
target_compile_definitions(SimpleMapViewTests PRIVATE QUICK_TEST_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}")
13-
target_link_libraries(SimpleMapViewTests PRIVATE Qt::QuickTest)
12+
target_compile_definitions(
13+
SimpleMapViewTests PRIVATE
14+
QUICK_TEST_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}"
15+
QML2_IMPORT_PATH="${CMAKE_BINARY_DIR}"
16+
)
17+
target_link_libraries(
18+
SimpleMapViewTests PRIVATE
19+
SimpleMapViewplugin
20+
Qt::QuickTest
21+
)
1422

1523
else()
1624

@@ -20,11 +28,13 @@ else()
2028
../Resources.qrc
2129
SimpleMapViewWidgetTest.cpp
2230
)
23-
target_link_libraries(SimpleMapViewTests PRIVATE Qt::Test)
31+
target_link_libraries(
32+
SimpleMapViewTests PRIVATE
33+
SimpleMapView
34+
Qt::Test
35+
)
2436

2537
endif()
2638

27-
target_link_libraries(SimpleMapViewTests PRIVATE SimpleMapView)
28-
2939
include(CTest)
3040
add_test(NAME SimpleMapViewTests COMMAND SimpleMapViewTests)

tests/tst_SimpleMapView.qml

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,13 @@ TestCase {
2222
function test_instantiation() {
2323
verify(map !== null, "SimpleMapView widget failed to instantiate.")
2424

25-
compare(map.tileServer, SimpleMapView.OSM, "Default `tileServer` should be OSM.")
26-
compare(map.tileServerSource, SimpleMapView.Remote, "Default source should be Remote.")
25+
compare(map.tileServer, TileServers.OSM, "Default `tileServer` should be OSM.")
26+
compare(map.tileServerSource(), SimpleMapView.Remote, "Default source should be Remote.")
2727

28-
verify(!map.isZoomLocked, "Default `isZoomLocked` should be false")
29-
verify(!map.isGeolocationLocked, "Default `isGeolocationLocked` should be false")
30-
verify(!map.isMouseWheelZoomDisabled, "Default `isMouseWheelZoomDisabled` should be false")
31-
verify(!map.isMouseMoveMapDisabled, "Default `isMouseMoveMapDisabled` should be false")
32-
33-
verify(map.markerIcon !== "", "Default marker icon should not be empty")
34-
verify(map.markerIcon.toString().indexOf("marker.svg") >= 0, "Default marker icon path mismatch.")
28+
verify(!map.isZoomLocked(), "Default `isZoomLocked` should be false")
29+
verify(!map.isGeolocationLocked(), "Default `isGeolocationLocked` should be false")
30+
verify(!map.isMouseWheelZoomDisabled(), "Default `isMouseWheelZoomDisabled` should be false")
31+
verify(!map.isMouseMoveMapDisabled(), "Default `isMouseMoveMapDisabled` should be false")
3532
}
3633

3734
function test_zoomLevel() {
@@ -66,25 +63,25 @@ TestCase {
6663
map.zoomLevel = 5
6764
zoomSpy.clear()
6865

69-
map.lockZoom()
66+
map.lockZoom = true
7067
map.zoomLevel = 12
7168
compare(map.zoomLevel, 5, "Failed to lock zoom.")
7269
compare(zoomSpy.count, 0)
7370

74-
map.unlockZoom()
71+
map.lockZoom = false
7572
map.zoomLevel = 12
7673
compare(map.zoomLevel, 12, "Failed to unlock zoom.")
7774
compare(zoomSpy.count, 1)
7875

79-
map.disableMouseWheelZoom()
80-
verify(map.isMouseWheelZoomDisabled, "Failed to disable mouse wheel zoom.")
76+
map.disableMouseWheelZoom = true
77+
verify(map.isMouseWheelZoomDisabled(), "Failed to disable mouse wheel zoom.")
8178

8279
preZoom = map.zoomLevel
8380
mouseWheel(map, map.width/2, map.height/2, 120, 120)
8481
compare(map.zoomLevel, preZoom, "Mouse wheel should be ignored when disabled.")
8582

86-
map.enableMouseWheelZoom()
87-
verify(!map.isMouseWheelZoomDisabled, "Failed to enable mouse wheel zoom.")
83+
map.disableMouseWheelZoom = false
84+
verify(!map.isMouseWheelZoomDisabled(), "Failed to enable mouse wheel zoom.")
8885
}
8986

9087
function test_positioning() {
@@ -107,35 +104,49 @@ TestCase {
107104

108105
var startX = map.width / 2
109106
var startY = map.height / 2
110-
111107
var initialLon = map.longitude
112108
var initialLat = map.latitude
113109

114-
mouseDrag(map, startX, startY, startX - 100, startY)
110+
mousePress(map, startX, startY, Qt.LeftButton)
111+
mouseMove(map, startX - 100, startY, 0, Qt.LeftButton)
112+
mouseRelease(map, startX - 100, startY, Qt.LeftButton)
113+
115114
verify(map.longitude > initialLon, "Failed to move map (Longitude) via mouse.")
116-
verify(Math.abs(map.latitude - initialLat) < 0.0001, "Latitude should remain constant on horizontal drag.")
115+
verify(map.latitude === initialLat, "Latitude should remain constant on horizontal drag.")
116+
117+
map.longitude = initialLon
118+
map.latitude = initialLat
119+
120+
mousePress(map, startX, startY, Qt.LeftButton)
121+
mouseMove(map, startX, startY + 100, 0, Qt.LeftButton)
122+
mouseRelease(map, startX, startY + 100, Qt.LeftButton)
123+
124+
verify(map.longitude === initialLon, "Failed to move map (Longitude) via mouse.")
125+
verify(map.latitude > initialLat, "Latitude should remain constant on horizontal drag.")
117126

118127
map.latitude = 10.0
119128
centerSpy.clear()
120129

121-
map.lockGeolocation()
130+
map.lockGeolocation = true
122131
map.latitude = 20.0
123132
compare(map.latitude, 10.0, "Failed to lock geolocation.")
124133
compare(centerSpy.count, 0)
125134

126-
map.unlockGeolocation()
135+
map.lockGeolocation = false
127136
map.latitude = 20.0
128137
compare(map.latitude, 20.0, "Failed to unlock geolocation.")
129138

130-
map.disableMouseMoveMap()
131-
verify(map.isMouseMoveMapDisabled, "Failed to flag mouse move disabled.")
139+
map.disableMouseMoveMap = true
140+
verify(map.isMouseMoveMapDisabled(), "Failed to flag mouse move disabled.")
132141

133142
var frozenCenter = map.center
134-
mouseDrag(map, startX, startY, startX - 100, startY)
143+
mousePress(map, startX, startY, Qt.LeftButton)
144+
mouseMove(map, startX - 100, startY + 100, 0, Qt.LeftButton)
145+
mouseRelease(map, startX - 100, startY + 100, Qt.LeftButton)
135146
compare(map.center, frozenCenter, "Map should not move when mouse move is disabled.")
136147

137-
map.enableMouseMoveMap()
138-
verify(!map.isMouseMoveMapDisabled, "Failed to flag mouse move enabled.")
148+
map.disableMouseMoveMap = false
149+
verify(!map.isMouseMoveMapDisabled(), "Failed to flag mouse move enabled.")
139150
}
140151

141152
function test_tileServers() {
@@ -146,20 +157,14 @@ TestCase {
146157
map.setTileServer(invalidUrl)
147158
wait(5000)
148159

149-
compare(map.tileServer, SimpleMapView.OSM, "Should default to OSM on invalid server.")
160+
compare(map.tileServer, TileServers.OSM, "Should default to OSM on invalid server.")
150161

151-
map.setTileServer(SimpleMapView.GOOGLE_MAP)
152-
compare(map.tileServer, SimpleMapView.GOOGLE_MAP, "Failed to change tile server.")
162+
map.setTileServer(TileServers.GOOGLE_MAP)
163+
compare(map.tileServer, TileServers.GOOGLE_MAP, "Failed to change tile server.")
153164
}
154165

155166
function test_markers() {
156167
var marker = map.addMarker(map.latitude, map.longitude)
157168
verify(marker !== null, "Failed to add marker.")
158-
159-
map.setMarkerIcon("qrc:/SimpleMapView/marker_alt.svg")
160-
var marker2 = map.addMarker(map.center)
161-
verify(marker2 !== null, "Failed to add second marker.")
162-
163-
verify(map.markerIcon.toString().indexOf("marker_alt.svg") >= 0, "Global marker icon failed to update.")
164169
}
165170
}

0 commit comments

Comments
 (0)