summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/location/LocationComponentTest.kt
diff options
context:
space:
mode:
authorŁukasz Paczos <lukas.paczos@gmail.com>2018-12-13 12:40:40 +0100
committerŁukasz Paczos <lukasz.paczos@mapbox.com>2018-12-13 17:44:54 +0100
commit1d410c94fc6bd6d9f4880f22193328403302a847 (patch)
treec71117d40f0e2f3722d64e019f06d0b23e425c1f /platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/location/LocationComponentTest.kt
parent3fbd9578c7bc016b0599d1df5d12125f325b9cda (diff)
downloadqtlocation-mapboxgl-1d410c94fc6bd6d9f4880f22193328403302a847.tar.gz
[android] register compass sensor listener only if provided data is consumed by the location layer or location camera
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/location/LocationComponentTest.kt')
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/location/LocationComponentTest.kt161
1 files changed, 161 insertions, 0 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/location/LocationComponentTest.kt b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/location/LocationComponentTest.kt
index 2fa340fbb8..cf513068ac 100644
--- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/location/LocationComponentTest.kt
+++ b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/location/LocationComponentTest.kt
@@ -9,6 +9,7 @@ import com.mapbox.android.core.location.LocationEngineRequest
import com.mapbox.mapboxsdk.R
import com.mapbox.mapboxsdk.camera.CameraPosition
import com.mapbox.mapboxsdk.location.modes.CameraMode
+import com.mapbox.mapboxsdk.location.modes.RenderMode
import com.mapbox.mapboxsdk.maps.MapboxMap
import com.mapbox.mapboxsdk.maps.Style
import io.mockk.mockk
@@ -183,4 +184,164 @@ class LocationComponentTest {
verify(listener).onLocationCameraTransitionCanceled(CameraMode.TRACKING)
verify(locationAnimatorCoordinator).resetAllCameraAnimations(CameraPosition.DEFAULT, false)
}
+
+ @Test
+ fun compass_listenWhenConsumedByNoneCamera() {
+ locationComponent.activateLocationComponent(context, mockk(), locationEngine, locationEngineRequest, locationComponentOptions)
+ locationComponent.onStart()
+ locationComponent.isLocationComponentEnabled = true
+ `when`(mapboxMap.cameraPosition).thenReturn(CameraPosition.DEFAULT)
+
+ `when`(locationCameraController.isConsumingCompass).thenReturn(true)
+ locationComponent.cameraMode = CameraMode.NONE_COMPASS
+ verify(compassEngine).addCompassListener(any(CompassListener::class.java))
+ }
+
+ @Test
+ fun compass_listenWhenConsumedByTrackingCamera() {
+ locationComponent.activateLocationComponent(context, mockk(), locationEngine, locationEngineRequest, locationComponentOptions)
+ locationComponent.onStart()
+ locationComponent.isLocationComponentEnabled = true
+ `when`(mapboxMap.cameraPosition).thenReturn(CameraPosition.DEFAULT)
+
+ `when`(locationCameraController.isConsumingCompass).thenReturn(true)
+ locationComponent.cameraMode = CameraMode.TRACKING_COMPASS
+ verify(compassEngine).addCompassListener(any(CompassListener::class.java))
+ }
+
+ @Test
+ fun compass_listenWhenConsumedByLayer() {
+ locationComponent.activateLocationComponent(context, mockk(), locationEngine, locationEngineRequest, locationComponentOptions)
+ locationComponent.onStart()
+ locationComponent.isLocationComponentEnabled = true
+ `when`(mapboxMap.cameraPosition).thenReturn(CameraPosition.DEFAULT)
+
+ `when`(locationLayerController.isConsumingCompass).thenReturn(true)
+ locationComponent.renderMode = RenderMode.COMPASS
+ verify(compassEngine).addCompassListener(any(CompassListener::class.java))
+ }
+
+ @Test
+ fun compass_notListenWhenNotConsumed() {
+ locationComponent.activateLocationComponent(context, mockk(), locationEngine, locationEngineRequest, locationComponentOptions)
+ locationComponent.onStart()
+ locationComponent.isLocationComponentEnabled = true
+ `when`(mapboxMap.cameraPosition).thenReturn(CameraPosition.DEFAULT)
+
+ `when`(locationLayerController.isConsumingCompass).thenReturn(false)
+ `when`(locationCameraController.isConsumingCompass).thenReturn(false)
+ locationComponent.renderMode = RenderMode.GPS
+ locationComponent.renderMode = RenderMode.NORMAL
+ locationComponent.cameraMode = CameraMode.TRACKING
+ locationComponent.cameraMode = CameraMode.NONE
+ locationComponent.cameraMode = CameraMode.NONE_GPS
+ locationComponent.cameraMode = CameraMode.TRACKING_GPS
+ locationComponent.cameraMode = CameraMode.TRACKING_GPS_NORTH
+ verify(compassEngine, never()).addCompassListener(any(CompassListener::class.java))
+ }
+
+ @Test
+ fun compass_removeListenerOnChange() {
+ locationComponent.activateLocationComponent(context, mockk(), locationEngine, locationEngineRequest, locationComponentOptions)
+ locationComponent.onStart()
+ locationComponent.isLocationComponentEnabled = true
+ `when`(mapboxMap.cameraPosition).thenReturn(CameraPosition.DEFAULT)
+
+ `when`(locationLayerController.isConsumingCompass).thenReturn(true)
+ locationComponent.renderMode = RenderMode.COMPASS
+ `when`(locationLayerController.isConsumingCompass).thenReturn(false)
+ locationComponent.renderMode = RenderMode.NORMAL
+ verify(compassEngine).removeCompassListener(any(CompassListener::class.java))
+ }
+
+ @Test
+ fun compass_removeListenerOnStop() {
+ locationComponent.activateLocationComponent(context, mockk(), locationEngine, locationEngineRequest, locationComponentOptions)
+ locationComponent.onStart()
+ locationComponent.isLocationComponentEnabled = true
+ `when`(mapboxMap.cameraPosition).thenReturn(CameraPosition.DEFAULT)
+
+ `when`(locationLayerController.isConsumingCompass).thenReturn(true)
+ locationComponent.renderMode = RenderMode.COMPASS
+ locationComponent.onStop()
+ verify(compassEngine).removeCompassListener(any(CompassListener::class.java))
+ }
+
+ @Test
+ fun compass_reAddListenerOnStart() {
+ locationComponent.activateLocationComponent(context, mockk(), locationEngine, locationEngineRequest, locationComponentOptions)
+ locationComponent.onStart()
+ locationComponent.isLocationComponentEnabled = true
+ `when`(mapboxMap.cameraPosition).thenReturn(CameraPosition.DEFAULT)
+
+ `when`(locationLayerController.isConsumingCompass).thenReturn(true)
+ locationComponent.renderMode = RenderMode.COMPASS
+ locationComponent.onStop()
+ locationComponent.onStart()
+ verify(compassEngine, times(2)).addCompassListener(any(CompassListener::class.java))
+ }
+
+ @Test
+ fun compass_removeListenerOnStyleStartLoad() {
+ locationComponent.activateLocationComponent(context, mockk(), locationEngine, locationEngineRequest, locationComponentOptions)
+ locationComponent.onStart()
+ locationComponent.isLocationComponentEnabled = true
+ `when`(mapboxMap.cameraPosition).thenReturn(CameraPosition.DEFAULT)
+
+ `when`(locationLayerController.isConsumingCompass).thenReturn(true)
+ locationComponent.renderMode = RenderMode.COMPASS
+ locationComponent.onStartLoadingMap()
+ verify(compassEngine).removeCompassListener(any(CompassListener::class.java))
+ }
+
+ @Test
+ fun compass_reAddListenerOnStyleLoadFinished() {
+ locationComponent.activateLocationComponent(context, mockk(), locationEngine, locationEngineRequest, locationComponentOptions)
+ locationComponent.onStart()
+ locationComponent.isLocationComponentEnabled = true
+ `when`(mapboxMap.cameraPosition).thenReturn(CameraPosition.DEFAULT)
+
+ `when`(locationLayerController.isConsumingCompass).thenReturn(true)
+ locationComponent.renderMode = RenderMode.COMPASS
+ locationComponent.onStartLoadingMap()
+ locationComponent.onFinishLoadingStyle()
+ verify(compassEngine, times(2)).addCompassListener(any(CompassListener::class.java))
+ }
+
+ @Test
+ fun compass_reAddListenerOnlyWhenEnabled() {
+ locationComponent.activateLocationComponent(context, mockk(), locationEngine, locationEngineRequest, locationComponentOptions)
+ locationComponent.onStart()
+ locationComponent.isLocationComponentEnabled = true
+ `when`(mapboxMap.cameraPosition).thenReturn(CameraPosition.DEFAULT)
+
+ `when`(locationLayerController.isConsumingCompass).thenReturn(true)
+ locationComponent.renderMode = RenderMode.COMPASS
+ locationComponent.isLocationComponentEnabled = false
+ locationComponent.onStartLoadingMap()
+ locationComponent.onFinishLoadingStyle()
+ verify(compassEngine).addCompassListener(any(CompassListener::class.java))
+ }
+
+ @Test
+ fun compass_notAdListenerWhenDisabled() {
+ locationComponent.activateLocationComponent(context, mockk(), locationEngine, locationEngineRequest, locationComponentOptions)
+ locationComponent.onStart()
+ `when`(mapboxMap.cameraPosition).thenReturn(CameraPosition.DEFAULT)
+
+ `when`(locationLayerController.isConsumingCompass).thenReturn(true)
+ locationComponent.renderMode = RenderMode.COMPASS
+ verify(compassEngine, never()).addCompassListener(any(CompassListener::class.java))
+ }
+
+ @Test
+ fun compass_notAdListenerWhenStopped() {
+ locationComponent.activateLocationComponent(context, mockk(), locationEngine, locationEngineRequest, locationComponentOptions)
+ locationComponent.isLocationComponentEnabled = true
+ `when`(mapboxMap.cameraPosition).thenReturn(CameraPosition.DEFAULT)
+
+ `when`(locationLayerController.isConsumingCompass).thenReturn(true)
+ locationComponent.renderMode = RenderMode.COMPASS
+ verify(compassEngine, never()).addCompassListener(any(CompassListener::class.java))
+ }
} \ No newline at end of file