This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[android] - instrumented unit tests, add map tests, refactor generate…
…d layer tests
- Loading branch information
Showing
13 changed files
with
2,081 additions
and
2,745 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/BaseLayerTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.mapbox.mapboxsdk.maps | ||
|
||
import android.support.test.InstrumentationRegistry | ||
import android.support.test.runner.AndroidJUnit4 | ||
import com.mapbox.mapboxsdk.style.layers.Layer | ||
import org.junit.runner.RunWith | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
abstract class BaseLayerTest { | ||
private lateinit var nativeMapView: NativeMapView | ||
|
||
companion object { | ||
const val WIDTH = 500 | ||
const val HEIGHT = WIDTH | ||
} | ||
|
||
fun before() { | ||
val context = InstrumentationRegistry.getContext() | ||
nativeMapView = NativeMapView(context, false, null, null, NativeMapViewTest.DummyRenderer(context)) | ||
nativeMapView.resizeView(WIDTH, HEIGHT) | ||
} | ||
|
||
fun setupLayer(layer: Layer) { | ||
nativeMapView.addLayer(layer) | ||
} | ||
} |
187 changes: 187 additions & 0 deletions
187
...oxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/NativeMapViewTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 | ||
} | ||
} | ||
} |
Oops, something went wrong.