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
|
package com.mapbox.mapboxsdk.maps
import android.content.Context
import android.graphics.PointF
import android.support.test.InstrumentationRegistry
import android.support.test.annotation.UiThreadTest
import android.support.test.runner.AndroidJUnit4
import com.mapbox.mapboxsdk.camera.CameraPosition
import com.mapbox.mapboxsdk.geometry.LatLng
import com.mapbox.mapboxsdk.maps.renderer.MapRenderer
import junit.framework.Assert.assertEquals
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class NativeMapViewTest {
private lateinit var nativeMapView: NativeMapView
companion object {
const val DELTA = 0.000001
const val DELTA_BIG = 1.0
const val BEARING_TEST = 60.0
const val PITCH_TEST = 40.0
const val ZOOM_TEST = 16.0
const val WIDTH = 500
const val HEIGHT = WIDTH
val LATLNG_TEST = LatLng(12.0, 34.0)
}
@Before
@UiThreadTest
fun before() {
val context = InstrumentationRegistry.getContext()
nativeMapView = NativeMapView(context, false, null, null, DummyRenderer(context))
nativeMapView.resizeView(WIDTH, HEIGHT)
}
@Test
@UiThreadTest
fun testBearing() {
val expected = BEARING_TEST
nativeMapView.bearing = expected
val actual = nativeMapView.bearing
assertEquals("Bearing should match", expected, actual, DELTA)
}
@Test
@UiThreadTest
fun testLatLng() {
val expected = LATLNG_TEST
nativeMapView.latLng = expected
val actual = nativeMapView.latLng
assertEquals("Latitude should match", expected.latitude, actual.latitude, DELTA)
assertEquals("Longitude should match", expected.longitude, actual.longitude, DELTA)
}
@Test
@UiThreadTest
fun testLatLngDefault() {
val expected = LatLng()
val actual = nativeMapView.latLng
assertEquals("Latitude should match", expected.latitude, actual.latitude, DELTA)
assertEquals("Longitude should match", expected.longitude, actual.longitude, DELTA)
}
@Test
@UiThreadTest
fun testBearingDefault() {
val expected = 0.0
val actual = nativeMapView.bearing
assertEquals("Bearing should match", expected, actual, DELTA)
}
@Test
@UiThreadTest
fun testPitch() {
val expected = PITCH_TEST
nativeMapView.pitch = expected
val actual = nativeMapView.pitch
assertEquals("Pitch should match", expected, actual, DELTA)
}
@Test
@UiThreadTest
fun testPitchDefault() {
val expected = 0.0
val actual = nativeMapView.pitch
assertEquals("Pitch should match", expected, actual, DELTA)
}
@Test
@UiThreadTest
fun testZoom() {
val expected = ZOOM_TEST
nativeMapView.setZoom(expected, PointF(0.0f, 0.0f), 0)
val actual = nativeMapView.zoom
assertEquals("Zoom should match", expected, actual, DELTA)
}
@Test
@UiThreadTest
fun testZoomDefault() {
val expected = 0.0
val actual = nativeMapView.zoom
assertEquals("Zoom should match", expected, actual, DELTA)
}
@Test
@UiThreadTest
fun testJumpTo() {
val expected = CameraPosition.Builder()
.bearing(BEARING_TEST)
.target(LATLNG_TEST)
.tilt(PITCH_TEST)
.zoom(ZOOM_TEST)
.build()
nativeMapView.jumpTo(BEARING_TEST, LATLNG_TEST, PITCH_TEST, ZOOM_TEST)
val actual = nativeMapView.cameraPosition
assertEquals("Latitude should match", expected.target.latitude, actual.target.latitude, DELTA)
assertEquals("Longitude should match", expected.target.longitude, actual.target.longitude, DELTA)
assertEquals("Bearing should match", expected.bearing, actual.bearing, DELTA)
assertEquals("Pitch should match", expected.tilt, actual.tilt, DELTA)
assertEquals("Zoom should match", expected.zoom, actual.zoom, DELTA)
}
@Test
@UiThreadTest
fun testLatLngForPixel() {
val expected = LATLNG_TEST
nativeMapView.latLng = LATLNG_TEST
val actual = nativeMapView.latLngForPixel(
PointF((WIDTH / 2).toFloat(), (HEIGHT / 2).toFloat())
)
assertEquals("Latitude should match", expected.latitude, actual.latitude, DELTA_BIG)
assertEquals("Longitude should match", expected.longitude, actual.longitude, DELTA_BIG)
}
@Test
@UiThreadTest
fun testPixelForLatLng() {
val expected = PointF((WIDTH / 2).toFloat(), (HEIGHT / 2).toFloat())
nativeMapView.latLng = LATLNG_TEST
val actual = nativeMapView.pixelForLatLng(LATLNG_TEST)
assertEquals("X should match", expected.x.toDouble(), actual.x.toDouble(), DELTA_BIG)
assertEquals("Y should match", expected.y.toDouble(), actual.y.toDouble(), DELTA_BIG)
}
@Test
@UiThreadTest
fun testPrefetchTilesTrue(){
val expected = true
nativeMapView.prefetchesTiles = true
val actual = nativeMapView.prefetchesTiles
assertEquals("Flag should match", expected, actual)
}
@Test
@UiThreadTest
fun testPrefetchTilesFalse(){
val expected = false
nativeMapView.prefetchesTiles = false
val actual = nativeMapView.prefetchesTiles
assertEquals("Flag should match", expected, actual)
}
@Test
@UiThreadTest
fun testPrefetchTilesDefault(){
val expected = true
val actual = nativeMapView.prefetchesTiles
assertEquals("Flag should match", expected, actual)
}
class DummyRenderer(context: Context) : MapRenderer(context, null) {
override fun requestRender() {
//no-op
}
override fun queueEvent(runnable: Runnable?) {
//no-op
}
}
}
|