[android] fixing ktlint issues

This commit is contained in:
Petr Pokorny
2020-12-21 11:35:43 +01:00
parent 68be84e32f
commit c5b645a02f
81 changed files with 9248 additions and 8961 deletions

View File

@@ -12,4 +12,4 @@ abstract class AppCenter {
open fun afterTest() {
reportHelper.label(javaClass.simpleName)
}
}
}

View File

@@ -3,8 +3,8 @@ package com.mapbox.mapboxsdk
import com.mapbox.mapboxsdk.testapp.MapboxApplication
class InstrumentationApplication : MapboxApplication() {
override fun initializeLeakCanary(): Boolean {
// do not initialize leak canary during instrumentation tests
return true
}
}
override fun initializeLeakCanary(): Boolean {
// do not initialize leak canary during instrumentation tests
return true
}
}

View File

@@ -5,7 +5,7 @@ import android.content.Context
import androidx.test.runner.AndroidJUnitRunner
class InstrumentationRunner : AndroidJUnitRunner() {
override fun newApplication(cl: ClassLoader?, className: String?, context: Context?): Application {
return super.newApplication(cl, InstrumentationApplication::class.java.name, context)
}
}
override fun newApplication(cl: ClassLoader?, className: String?, context: Context?): Application {
return super.newApplication(cl, InstrumentationApplication::class.java.name, context)
}
}

View File

@@ -16,171 +16,171 @@ import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class CameraUpdateFactoryTest : BaseTest() {
override fun getActivityClass(): Class<*> {
return DeviceIndependentTestActivity::class.java
}
override fun getActivityClass(): Class<*> {
return DeviceIndependentTestActivity::class.java
}
@Test
@UiThreadTest
fun testLatLngBoundsUntiltedUnrotated() {
mapboxMap.cameraPosition = CameraPosition.Builder()
.target(LatLng(60.0, 24.0))
.bearing(0.0)
.tilt(0.0)
.build()
@Test
@UiThreadTest
fun testLatLngBoundsUntiltedUnrotated() {
mapboxMap.cameraPosition = CameraPosition.Builder()
.target(LatLng(60.0, 24.0))
.bearing(0.0)
.tilt(0.0)
.build()
val bounds: LatLngBounds = LatLngBounds.Builder()
.include(LatLng(62.0, 26.0))
.include(LatLng(58.0, 22.0))
.build()
val bounds: LatLngBounds = LatLngBounds.Builder()
.include(LatLng(62.0, 26.0))
.include(LatLng(58.0, 22.0))
.build()
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 0))
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 0))
val cameraPosition = mapboxMap.cameraPosition
assertEquals("latitude should match:", 60.0, cameraPosition.target.latitude, 0.1)
assertEquals("longitude should match:", 24.0, cameraPosition.target.longitude, 0.1)
assertEquals("bearing should match:", 0.0, cameraPosition.bearing, 0.1)
assertEquals("zoom should match", 5.5, cameraPosition.zoom, 0.1)
assertEquals("tilt should match:", 0.0, cameraPosition.tilt, 0.1)
}
val cameraPosition = mapboxMap.cameraPosition
assertEquals("latitude should match:", 60.0, cameraPosition.target.latitude, 0.1)
assertEquals("longitude should match:", 24.0, cameraPosition.target.longitude, 0.1)
assertEquals("bearing should match:", 0.0, cameraPosition.bearing, 0.1)
assertEquals("zoom should match", 5.5, cameraPosition.zoom, 0.1)
assertEquals("tilt should match:", 0.0, cameraPosition.tilt, 0.1)
}
@Test
@UiThreadTest
fun testLatLngBoundsTilted() {
mapboxMap.cameraPosition = CameraPosition.Builder()
.target(LatLng(60.0, 24.0))
.bearing(0.0)
.tilt(45.0)
.build()
@Test
@UiThreadTest
fun testLatLngBoundsTilted() {
mapboxMap.cameraPosition = CameraPosition.Builder()
.target(LatLng(60.0, 24.0))
.bearing(0.0)
.tilt(45.0)
.build()
val bounds: LatLngBounds = LatLngBounds.Builder()
.include(LatLng(62.0, 26.0))
.include(LatLng(58.0, 22.0))
.build()
val bounds: LatLngBounds = LatLngBounds.Builder()
.include(LatLng(62.0, 26.0))
.include(LatLng(58.0, 22.0))
.build()
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 0))
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 0))
val cameraPosition = mapboxMap.cameraPosition
assertEquals("latitude should match:", 60.0, cameraPosition.target.latitude, 0.1)
assertEquals("longitude should match:", 24.0, cameraPosition.target.longitude, 0.1)
assertEquals("bearing should match:", 0.0, cameraPosition.bearing, 0.1)
assertEquals("zoom should match", 6.0, cameraPosition.zoom, 0.1)
assertEquals("tilt should match:", 45.0, cameraPosition.tilt, 0.1)
}
val cameraPosition = mapboxMap.cameraPosition
assertEquals("latitude should match:", 60.0, cameraPosition.target.latitude, 0.1)
assertEquals("longitude should match:", 24.0, cameraPosition.target.longitude, 0.1)
assertEquals("bearing should match:", 0.0, cameraPosition.bearing, 0.1)
assertEquals("zoom should match", 6.0, cameraPosition.zoom, 0.1)
assertEquals("tilt should match:", 45.0, cameraPosition.tilt, 0.1)
}
@Test
@UiThreadTest
fun testLatLngBoundsRotated() {
mapboxMap.cameraPosition = CameraPosition.Builder()
.target(LatLng(60.0, 24.0))
.bearing(30.0)
.tilt(0.0)
.build()
@Test
@UiThreadTest
fun testLatLngBoundsRotated() {
mapboxMap.cameraPosition = CameraPosition.Builder()
.target(LatLng(60.0, 24.0))
.bearing(30.0)
.tilt(0.0)
.build()
val bounds: LatLngBounds = LatLngBounds.Builder()
.include(LatLng(62.0, 26.0))
.include(LatLng(58.0, 22.0))
.build()
val bounds: LatLngBounds = LatLngBounds.Builder()
.include(LatLng(62.0, 26.0))
.include(LatLng(58.0, 22.0))
.build()
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 0))
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 0))
val cameraPosition = mapboxMap.cameraPosition
assertEquals("latitude should match:", 60.0, cameraPosition.target.latitude, 0.1)
assertEquals("longitude should match:", 24.0, cameraPosition.target.longitude, 0.1)
assertEquals("bearing should match:", 30.0, cameraPosition.bearing, 0.1)
assertEquals("zoom should match", 5.3, cameraPosition.zoom, 0.1)
assertEquals("tilt should match:", 0.0, cameraPosition.tilt, 0.1)
}
val cameraPosition = mapboxMap.cameraPosition
assertEquals("latitude should match:", 60.0, cameraPosition.target.latitude, 0.1)
assertEquals("longitude should match:", 24.0, cameraPosition.target.longitude, 0.1)
assertEquals("bearing should match:", 30.0, cameraPosition.bearing, 0.1)
assertEquals("zoom should match", 5.3, cameraPosition.zoom, 0.1)
assertEquals("tilt should match:", 0.0, cameraPosition.tilt, 0.1)
}
@Test
@UiThreadTest
fun testLatLngBoundsTiltedRotated() {
mapboxMap.cameraPosition = CameraPosition.Builder()
.target(LatLng(60.0, 24.0))
.bearing(30.0)
.tilt(45.0)
.build()
@Test
@UiThreadTest
fun testLatLngBoundsTiltedRotated() {
mapboxMap.cameraPosition = CameraPosition.Builder()
.target(LatLng(60.0, 24.0))
.bearing(30.0)
.tilt(45.0)
.build()
val bounds: LatLngBounds = LatLngBounds.Builder()
.include(LatLng(62.0, 26.0))
.include(LatLng(58.0, 22.0))
.build()
val bounds: LatLngBounds = LatLngBounds.Builder()
.include(LatLng(62.0, 26.0))
.include(LatLng(58.0, 22.0))
.build()
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 0))
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 0))
val cameraPosition = mapboxMap.cameraPosition
assertEquals("latitude should match:", 60.0, cameraPosition.target.latitude, 0.1)
assertEquals("longitude should match:", 24.0, cameraPosition.target.longitude, 0.1)
assertEquals("bearing should match:", 30.0, cameraPosition.bearing, 0.1)
assertEquals("zoom should match", 5.6, cameraPosition.zoom, 0.1)
assertEquals("tilt should match:", 45.0, cameraPosition.tilt, 0.1)
}
val cameraPosition = mapboxMap.cameraPosition
assertEquals("latitude should match:", 60.0, cameraPosition.target.latitude, 0.1)
assertEquals("longitude should match:", 24.0, cameraPosition.target.longitude, 0.1)
assertEquals("bearing should match:", 30.0, cameraPosition.bearing, 0.1)
assertEquals("zoom should match", 5.6, cameraPosition.zoom, 0.1)
assertEquals("tilt should match:", 45.0, cameraPosition.tilt, 0.1)
}
@Test
@UiThreadTest
fun testLatLngBoundsWithProvidedTiltAndRotation() {
mapboxMap.cameraPosition = CameraPosition.Builder()
.target(LatLng(60.0, 24.0))
.bearing(0.0)
.tilt(0.0)
.build()
@Test
@UiThreadTest
fun testLatLngBoundsWithProvidedTiltAndRotation() {
mapboxMap.cameraPosition = CameraPosition.Builder()
.target(LatLng(60.0, 24.0))
.bearing(0.0)
.tilt(0.0)
.build()
val bounds: LatLngBounds = LatLngBounds.Builder()
.include(LatLng(62.0, 26.0))
.include(LatLng(58.0, 22.0))
.build()
val bounds: LatLngBounds = LatLngBounds.Builder()
.include(LatLng(62.0, 26.0))
.include(LatLng(58.0, 22.0))
.build()
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 30.0, 40.0, 0))
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 30.0, 40.0, 0))
val cameraPosition = mapboxMap.cameraPosition
assertEquals("latitude should match:", 60.0, cameraPosition.target.latitude, 0.1)
assertEquals("longitude should match:", 24.0, cameraPosition.target.longitude, 0.1)
assertEquals("bearing should match:", 30.0, cameraPosition.bearing, 0.1)
assertEquals("zoom should match", 5.6, cameraPosition.zoom, 0.1)
assertEquals("tilt should match:", 40.0, cameraPosition.tilt, 0.1)
}
val cameraPosition = mapboxMap.cameraPosition
assertEquals("latitude should match:", 60.0, cameraPosition.target.latitude, 0.1)
assertEquals("longitude should match:", 24.0, cameraPosition.target.longitude, 0.1)
assertEquals("bearing should match:", 30.0, cameraPosition.bearing, 0.1)
assertEquals("zoom should match", 5.6, cameraPosition.zoom, 0.1)
assertEquals("tilt should match:", 40.0, cameraPosition.tilt, 0.1)
}
@Test
@UiThreadTest
fun withPadding_cameraInvalidated_paddingPersisting() {
val initialCameraPosition = mapboxMap.cameraPosition
val initialPoint = mapboxMap.projection.toScreenLocation(initialCameraPosition.target)
@Test
@UiThreadTest
fun withPadding_cameraInvalidated_paddingPersisting() {
val initialCameraPosition = mapboxMap.cameraPosition
val initialPoint = mapboxMap.projection.toScreenLocation(initialCameraPosition.target)
val bottomPadding = mapView.height / 4
val leftPadding = mapView.width / 4
val padding = doubleArrayOf(leftPadding.toDouble(), 0.0, 0.0, bottomPadding.toDouble())
mapboxMap.moveCamera(CameraUpdateFactory.paddingTo(leftPadding.toDouble(), 0.0, 0.0, bottomPadding.toDouble()))
val bottomPadding = mapView.height / 4
val leftPadding = mapView.width / 4
val padding = doubleArrayOf(leftPadding.toDouble(), 0.0, 0.0, bottomPadding.toDouble())
mapboxMap.moveCamera(CameraUpdateFactory.paddingTo(leftPadding.toDouble(), 0.0, 0.0, bottomPadding.toDouble()))
Assert.assertArrayEquals(intArrayOf(leftPadding, 0, 0, bottomPadding), mapboxMap.padding)
Assert.assertArrayEquals(intArrayOf(leftPadding, 0, 0, bottomPadding), mapboxMap.padding)
val resultingCameraPosition = mapboxMap.cameraPosition
assertEquals(initialCameraPosition.target, resultingCameraPosition.target)
assertEquals(
PointF(initialPoint.x + leftPadding / 2, initialPoint.y - bottomPadding / 2),
mapboxMap.projection.toScreenLocation(resultingCameraPosition.target)
)
Assert.assertArrayEquals(padding, resultingCameraPosition.padding, 0.0001)
}
val resultingCameraPosition = mapboxMap.cameraPosition
assertEquals(initialCameraPosition.target, resultingCameraPosition.target)
assertEquals(
PointF(initialPoint.x + leftPadding / 2, initialPoint.y - bottomPadding / 2),
mapboxMap.projection.toScreenLocation(resultingCameraPosition.target)
)
Assert.assertArrayEquals(padding, resultingCameraPosition.padding, 0.0001)
}
@Test
@UiThreadTest
fun withLatLngPadding_cameraInvalidated_paddingPersisting() {
val expectedTarget = LatLng(2.0, 2.0)
@Test
@UiThreadTest
fun withLatLngPadding_cameraInvalidated_paddingPersisting() {
val expectedTarget = LatLng(2.0, 2.0)
val topPadding = mapView.height / 4
val rightPadding = mapView.width / 4
val padding = doubleArrayOf(0.0, topPadding.toDouble(), rightPadding.toDouble(), 0.0)
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngPadding(expectedTarget, 0.0, topPadding.toDouble(), rightPadding.toDouble(), 0.0))
val topPadding = mapView.height / 4
val rightPadding = mapView.width / 4
val padding = doubleArrayOf(0.0, topPadding.toDouble(), rightPadding.toDouble(), 0.0)
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngPadding(expectedTarget, 0.0, topPadding.toDouble(), rightPadding.toDouble(), 0.0))
Assert.assertArrayEquals(intArrayOf(0, topPadding, rightPadding, 0), mapboxMap.padding)
Assert.assertArrayEquals(intArrayOf(0, topPadding, rightPadding, 0), mapboxMap.padding)
val resultingCameraPosition = mapboxMap.cameraPosition
assertEquals(expectedTarget.latitude, resultingCameraPosition.target.latitude, 0.1)
assertEquals(expectedTarget.longitude, resultingCameraPosition.target.longitude, 0.1)
val resultingCameraPosition = mapboxMap.cameraPosition
assertEquals(expectedTarget.latitude, resultingCameraPosition.target.latitude, 0.1)
assertEquals(expectedTarget.longitude, resultingCameraPosition.target.longitude, 0.1)
val centerLatLng = mapboxMap.projection.fromScreenLocation(PointF((mapView.width / 2).toFloat(), (mapView.height / 2).toFloat()))
assertTrue(centerLatLng.latitude > resultingCameraPosition.target.latitude)
assertTrue(centerLatLng.longitude > resultingCameraPosition.target.longitude)
Assert.assertArrayEquals(padding, resultingCameraPosition.padding, 0.0001)
}
}
val centerLatLng = mapboxMap.projection.fromScreenLocation(PointF((mapView.width / 2).toFloat(), (mapView.height / 2).toFloat()))
assertTrue(centerLatLng.latitude > resultingCameraPosition.target.latitude)
assertTrue(centerLatLng.longitude > resultingCameraPosition.target.longitude)
Assert.assertArrayEquals(padding, resultingCameraPosition.padding, 0.0001)
}
}

View File

@@ -12,12 +12,12 @@ const val TIMEOUT_UI_SEARCH_WAIT = 5000L
abstract class BaseIntegrationTest : AppCenter() {
protected lateinit var device: UiDevice
protected lateinit var device: UiDevice
@Before
open fun beforeTest() {
device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
}
@Before
open fun beforeTest() {
device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
}
}
/**
@@ -27,14 +27,14 @@ abstract class BaseIntegrationTest : AppCenter() {
* <p>
*/
fun UiDevice.launchActivity(context: Context, clazz: Class<*>) {
val applicationPackage = InstrumentationRegistry.getInstrumentation().targetContext.packageName
val intent = Intent(context, clazz)
intent.addFlags(FLAG_ACTIVITY_NEW_TASK)
InstrumentationRegistry.getInstrumentation().context.startActivity(intent)
wait(Until.hasObject(By.pkg(applicationPackage).depth(0)), TIMEOUT_UI_SEARCH_WAIT)
val applicationPackage = InstrumentationRegistry.getInstrumentation().targetContext.packageName
val intent = Intent(context, clazz)
intent.addFlags(FLAG_ACTIVITY_NEW_TASK)
InstrumentationRegistry.getInstrumentation().context.startActivity(intent)
wait(Until.hasObject(By.pkg(applicationPackage).depth(0)), TIMEOUT_UI_SEARCH_WAIT)
}
fun UiDevice.scrollRecyclerViewTo(recycleItem: String) {
val appView = UiScrollable(UiSelector().scrollable(true))
appView.scrollIntoView(UiSelector().text(recycleItem))
}
val appView = UiScrollable(UiSelector().scrollable(true))
appView.scrollIntoView(UiSelector().text(recycleItem))
}

View File

@@ -15,31 +15,31 @@ import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class FragmentBackStackTest : BaseIntegrationTest() {
@get:Rule
var activityRule: ActivityTestRule<FragmentBackStackActivity> = ActivityTestRule(FragmentBackStackActivity::class.java)
@get:Rule
var activityRule: ActivityTestRule<FragmentBackStackActivity> = ActivityTestRule(FragmentBackStackActivity::class.java)
@Test
@LargeTest
fun backPressedOnBackStackResumed() {
device.waitForIdle()
clickReplaceFragmentButton()
device.pressHome()
device.waitForIdle()
device.launchActivity(activityRule.activity.applicationContext, FragmentBackStackActivity::class.java)
backPressBackStack()
device.waitForIdle()
}
@Test
@LargeTest
fun backPressedOnBackStackResumed() {
device.waitForIdle()
clickReplaceFragmentButton()
device.pressHome()
device.waitForIdle()
device.launchActivity(activityRule.activity.applicationContext, FragmentBackStackActivity::class.java)
backPressBackStack()
device.waitForIdle()
}
private fun clickReplaceFragmentButton() {
device.findObject(UiSelector().description(textDescription)).click()
}
private fun clickReplaceFragmentButton() {
device.findObject(UiSelector().description(textDescription)).click()
}
private fun backPressBackStack() {
device.pressBack() // pops fragment, showing map
device.pressBack() // finish activity
}
private fun backPressBackStack() {
device.pressBack() // pops fragment, showing map
device.pressBack() // finish activity
}
private companion object {
const val textDescription = "btn_change_fragment"
}
}
private companion object {
const val textDescription = "btn_change_fragment"
}
}

View File

@@ -14,16 +14,16 @@ import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class GLSurfaceViewReopenTest : BaseIntegrationTest() {
@get:Rule
var activityRule: ActivityTestRule<SimpleMapActivity> = ActivityTestRule(SimpleMapActivity::class.java)
@get:Rule
var activityRule: ActivityTestRule<SimpleMapActivity> = ActivityTestRule(SimpleMapActivity::class.java)
@Test
@LargeTest
fun reopenSimpleMapActivity() {
device.waitForIdle()
device.pressHome()
device.waitForIdle()
device.launchActivity(activityRule.activity, SimpleMapActivity::class.java)
device.waitForIdle()
}
}
@Test
@LargeTest
fun reopenSimpleMapActivity() {
device.waitForIdle()
device.pressHome()
device.waitForIdle()
device.launchActivity(activityRule.activity, SimpleMapActivity::class.java)
device.waitForIdle()
}
}

View File

@@ -14,16 +14,16 @@ import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class GLSurfaceViewReuseTest : BaseIntegrationTest() {
@get:Rule
var activityRule: ActivityTestRule<GLSurfaceRecyclerViewActivity> = ActivityTestRule(GLSurfaceRecyclerViewActivity::class.java)
@get:Rule
var activityRule: ActivityTestRule<GLSurfaceRecyclerViewActivity> = ActivityTestRule(GLSurfaceRecyclerViewActivity::class.java)
@Test
@LargeTest
fun scrollRecyclerView() {
device.waitForIdle()
device.scrollRecyclerViewTo("Twenty-one")
device.waitForIdle()
device.scrollRecyclerViewTo("One")
device.waitForIdle()
}
}
@Test
@LargeTest
fun scrollRecyclerView() {
device.waitForIdle()
device.scrollRecyclerViewTo("Twenty-one")
device.waitForIdle()
device.scrollRecyclerViewTo("One")
device.waitForIdle()
}
}

View File

@@ -11,22 +11,22 @@ import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class OrientationChangeTest : BaseIntegrationTest() {
@get:Rule
var activityRule: ActivityTestRule<SimpleMapActivity> = ActivityTestRule(SimpleMapActivity::class.java)
@get:Rule
var activityRule: ActivityTestRule<SimpleMapActivity> = ActivityTestRule(SimpleMapActivity::class.java)
@Test
@LargeTest
fun rotateSimpleMap() {
device.setOrientationLeft()
device.waitForIdle()
device.setOrientationNatural()
device.waitForIdle()
device.setOrientationRight()
device.waitForIdle()
device.setOrientationNatural()
device.setOrientationLeft()
device.setOrientationNatural()
device.setOrientationRight()
device.setOrientationNatural()
}
}
@Test
@LargeTest
fun rotateSimpleMap() {
device.setOrientationLeft()
device.waitForIdle()
device.setOrientationNatural()
device.waitForIdle()
device.setOrientationRight()
device.waitForIdle()
device.setOrientationNatural()
device.setOrientationLeft()
device.setOrientationNatural()
device.setOrientationRight()
device.setOrientationNatural()
}
}

View File

@@ -14,17 +14,17 @@ import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class QueryRenderedFeaturesBoxCountTest : BaseIntegrationTest() {
@get:Rule
var activityRule: ActivityTestRule<QueryRenderedFeaturesBoxCountActivity> =
ActivityTestRule(QueryRenderedFeaturesBoxCountActivity::class.java)
@get:Rule
var activityRule: ActivityTestRule<QueryRenderedFeaturesBoxCountActivity> =
ActivityTestRule(QueryRenderedFeaturesBoxCountActivity::class.java)
@Test
@LargeTest
fun reopenQueryRendererFeaturesActivity() {
device.waitForIdle()
device.pressHome()
device.waitForIdle()
device.launchActivity(activityRule.activity, QueryRenderedFeaturesBoxCountActivity::class.java)
device.waitForIdle()
}
}
@Test
@LargeTest
fun reopenQueryRendererFeaturesActivity() {
device.waitForIdle()
device.pressHome()
device.waitForIdle()
device.launchActivity(activityRule.activity, QueryRenderedFeaturesBoxCountActivity::class.java)
device.waitForIdle()
}
}

View File

@@ -14,16 +14,16 @@ import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class TextureViewReopenTest : BaseIntegrationTest() {
@get:Rule
var activityRule: ActivityTestRule<TextureViewDebugModeActivity> = ActivityTestRule(TextureViewDebugModeActivity::class.java)
@get:Rule
var activityRule: ActivityTestRule<TextureViewDebugModeActivity> = ActivityTestRule(TextureViewDebugModeActivity::class.java)
@Test
@LargeTest
fun reopenTextureViewDebugActivity() {
device.waitForIdle()
device.pressHome()
device.waitForIdle()
device.launchActivity(activityRule.activity, TextureViewDebugModeActivity::class.java)
device.waitForIdle()
}
}
@Test
@LargeTest
fun reopenTextureViewDebugActivity() {
device.waitForIdle()
device.pressHome()
device.waitForIdle()
device.launchActivity(activityRule.activity, TextureViewDebugModeActivity::class.java)
device.waitForIdle()
}
}

View File

@@ -14,16 +14,16 @@ import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class TextureViewReuseTest : BaseIntegrationTest() {
@get:Rule
var activityRule: ActivityTestRule<TextureRecyclerViewActivity> = ActivityTestRule(TextureRecyclerViewActivity::class.java)
@get:Rule
var activityRule: ActivityTestRule<TextureRecyclerViewActivity> = ActivityTestRule(TextureRecyclerViewActivity::class.java)
@Test
@LargeTest
fun scrollRecyclerView() {
device.waitForIdle()
device.scrollRecyclerViewTo("Twenty-one")
device.waitForIdle()
device.scrollRecyclerViewTo("One")
device.waitForIdle()
}
}
@Test
@LargeTest
fun scrollRecyclerView() {
device.waitForIdle()
device.scrollRecyclerViewTo("Twenty-one")
device.waitForIdle()
device.scrollRecyclerViewTo("One")
device.waitForIdle()
}
}

View File

@@ -15,22 +15,22 @@ import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class ViewPagerScrollTest : BaseIntegrationTest() {
@get:Rule
var activityRule: ActivityTestRule<ViewPagerActivity> = ActivityTestRule(ViewPagerActivity::class.java)
@get:Rule
var activityRule: ActivityTestRule<ViewPagerActivity> = ActivityTestRule(ViewPagerActivity::class.java)
@Test
@LargeTest
fun scrollViewPager() {
for (i in 1..4) {
clickTab(i)
@Test
@LargeTest
fun scrollViewPager() {
for (i in 1..4) {
clickTab(i)
}
for (i in 3 downTo 0) {
clickTab(i)
}
}
for (i in 3 downTo 0) {
clickTab(i)
private fun clickTab(index: Int) {
device.findObject(UiSelector().text("Page $index")).click()
}
}
private fun clickTab(index: Int) {
device.findObject(UiSelector().text("Page $index")).click()
}
}
}

View File

@@ -11,28 +11,29 @@ import com.mapbox.mapboxsdk.maps.Style
import org.hamcrest.Matcher
class LocationComponentAction(
private val mapboxMap: MapboxMap,
private val onPerformLocationComponentAction: OnPerformLocationComponentAction
private val mapboxMap: MapboxMap,
private val onPerformLocationComponentAction: OnPerformLocationComponentAction
) : ViewAction {
override fun getConstraints(): Matcher<View> {
return isDisplayed()
}
override fun getConstraints(): Matcher<View> {
return isDisplayed()
}
override fun getDescription(): String {
return javaClass.simpleName
}
override fun getDescription(): String {
return javaClass.simpleName
}
override fun perform(uiController: UiController, view: View) {
onPerformLocationComponentAction.onLocationComponentAction(
mapboxMap.locationComponent,
mapboxMap,
mapboxMap.style!!,
uiController,
view.context)
}
override fun perform(uiController: UiController, view: View) {
onPerformLocationComponentAction.onLocationComponentAction(
mapboxMap.locationComponent,
mapboxMap,
mapboxMap.style!!,
uiController,
view.context
)
}
interface OnPerformLocationComponentAction {
fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, style: Style, uiController: UiController, context: Context)
}
}
interface OnPerformLocationComponentAction {
fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, style: Style, uiController: UiController, context: Context)
}
}

View File

@@ -14,66 +14,69 @@ import com.mapbox.mapboxsdk.style.layers.Property
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource
fun MapboxMap.querySourceFeatures(sourceId: String): List<Feature> {
return this.style!!.getSourceAs<GeoJsonSource>(sourceId)?.querySourceFeatures(null) ?: emptyList()
return this.style!!.getSourceAs<GeoJsonSource>(sourceId)?.querySourceFeatures(null) ?: emptyList()
}
fun MapboxMap.queryRenderedFeatures(location: Location, layerId: String): List<Feature> {
val latLng = LatLng(location.latitude, location.longitude)
val point = this.projection.toScreenLocation(latLng)
return this.queryRenderedFeatures(point, layerId)
val latLng = LatLng(location.latitude, location.longitude)
val point = this.projection.toScreenLocation(latLng)
return this.queryRenderedFeatures(point, layerId)
}
fun MapboxMap.isLayerVisible(layerId: String): Boolean {
return this.style!!.getLayer(layerId)?.visibility?.value?.equals(Property.VISIBLE)!!
return this.style!!.getLayer(layerId)?.visibility?.value?.equals(Property.VISIBLE)!!
}
class MapboxTestingUtils {
companion object {
companion object {
/**
* Used to increase style load time for stress testing.
*/
const val MAPBOX_HEAVY_STYLE = "asset://heavy_style.json"
/**
* Used to increase style load time for stress testing.
*/
const val MAPBOX_HEAVY_STYLE = "asset://heavy_style.json"
private const val DATA_PUSH_INTERVAL = 1L
private const val DATA_PUSH_INTERVAL = 1L
/**
* Pushes data updates every [DATA_PUSH_INTERVAL] milliseconds until the style has been loaded,
* checked with [StyleChangeIdlingResource].
*/
fun pushSourceUpdates(styleChangeIdlingResource: StyleChangeIdlingResource, update: () -> Unit) {
val mainHandler = Handler(Looper.getMainLooper())
val runnable = object : Runnable {
override fun run() {
update.invoke()
if (!styleChangeIdlingResource.isIdleNow) {
mainHandler.postDelayed(this, DATA_PUSH_INTERVAL)
}
/**
* Pushes data updates every [DATA_PUSH_INTERVAL] milliseconds until the style has been loaded,
* checked with [StyleChangeIdlingResource].
*/
fun pushSourceUpdates(styleChangeIdlingResource: StyleChangeIdlingResource, update: () -> Unit) {
val mainHandler = Handler(Looper.getMainLooper())
val runnable = object : Runnable {
override fun run() {
update.invoke()
if (!styleChangeIdlingResource.isIdleNow) {
mainHandler.postDelayed(this, DATA_PUSH_INTERVAL)
}
}
}
if (!styleChangeIdlingResource.isIdleNow) {
if (Looper.myLooper() == Looper.getMainLooper()) {
runnable.run()
} else {
mainHandler.post(runnable)
}
}
}
}
if (!styleChangeIdlingResource.isIdleNow) {
if (Looper.myLooper() == Looper.getMainLooper()) {
runnable.run()
} else {
mainHandler.post(runnable)
}
}
}
}
}
fun MapboxMap.addImageFromDrawable(string: String, drawable: Drawable) {
val bitmapFromDrawable = getBitmapFromDrawable(drawable)
this.style!!.addImage(string, bitmapFromDrawable)
val bitmapFromDrawable = getBitmapFromDrawable(drawable)
this.style!!.addImage(string, bitmapFromDrawable)
}
private fun getBitmapFromDrawable(drawable: Drawable): Bitmap {
if (drawable is BitmapDrawable) return drawable.bitmap
val bitmap = Bitmap.createBitmap(drawable.intrinsicWidth,
drawable.intrinsicHeight, Bitmap.Config.ARGB_8888)
val canvas = Canvas(bitmap)
drawable.setBounds(0, 0, canvas.width, canvas.height)
drawable.draw(canvas)
return bitmap
}
if (drawable is BitmapDrawable) return drawable.bitmap
val bitmap = Bitmap.createBitmap(
drawable.intrinsicWidth,
drawable.intrinsicHeight,
Bitmap.Config.ARGB_8888
)
val canvas = Canvas(bitmap)
drawable.setBounds(0, 0, canvas.width, canvas.height)
drawable.draw(canvas)
return bitmap
}

View File

@@ -11,30 +11,30 @@ import com.mapbox.mapboxsdk.maps.Style
*/
class StyleChangeIdlingResource : IdlingResource {
private var callback: IdlingResource.ResourceCallback? = null
private var isIdle = true
private var callback: IdlingResource.ResourceCallback? = null
private var isIdle = true
override fun getName(): String {
return javaClass.simpleName
}
override fun isIdleNow(): Boolean {
return isIdle
}
override fun registerIdleTransitionCallback(callback: IdlingResource.ResourceCallback?) {
this.callback = callback
}
private fun setIdle() {
isIdle = true
callback?.onTransitionToIdle()
}
fun waitForStyle(mapboxMap: MapboxMap, styleUrl: String) {
isIdle = false
mapboxMap.setStyle(Style.Builder().fromUri(styleUrl)) {
setIdle()
override fun getName(): String {
return javaClass.simpleName
}
}
}
override fun isIdleNow(): Boolean {
return isIdle
}
override fun registerIdleTransitionCallback(callback: IdlingResource.ResourceCallback?) {
this.callback = callback
}
private fun setIdle() {
isIdle = true
callback?.onTransitionToIdle()
}
fun waitForStyle(mapboxMap: MapboxMap, styleUrl: String) {
isIdle = false
mapboxMap.setStyle(Style.Builder().fromUri(styleUrl)) {
setIdle()
}
}
}

View File

@@ -24,4 +24,4 @@ abstract class BaseLayerTest : AppCenter() {
fun setupLayer(layer: Layer) {
nativeMapView.addLayer(layer)
}
}
}

View File

@@ -13,143 +13,143 @@ import org.hamcrest.Matcher
object GesturesUiTestUtils {
private const val DEFAULT_GESTURE_DURATION = 500L
private const val DEFAULT_GESTURE_DURATION = 500L
fun pinch(
startSpan: Float,
endSpan: Float,
center: PointF? = null,
duration: Long = DEFAULT_GESTURE_DURATION
): ViewAction {
return object : ViewAction {
override fun getConstraints(): Matcher<View> {
return ViewMatchers.isEnabled()
}
fun pinch(
startSpan: Float,
endSpan: Float,
center: PointF? = null,
duration: Long = DEFAULT_GESTURE_DURATION
): ViewAction {
return object : ViewAction {
override fun getConstraints(): Matcher<View> {
return ViewMatchers.isEnabled()
}
override fun getDescription(): String = "Pinch $startSpan -> $endSpan"
override fun getDescription(): String = "Pinch $startSpan -> $endSpan"
override fun perform(uiController: UiController, view: View) {
var middlePosition = center
if (middlePosition == null) {
middlePosition = getCenterPointF(view)
override fun perform(uiController: UiController, view: View) {
var middlePosition = center
if (middlePosition == null) {
middlePosition = getCenterPointF(view)
}
val startPoint1 = PointF(middlePosition.x - startSpan / 2f, middlePosition.y)
val startPoint2 = PointF(middlePosition.x + startSpan / 2f, middlePosition.y)
val endPoint1 = PointF(middlePosition.x - endSpan / 2f, middlePosition.y)
val endPoint2 = PointF(middlePosition.x + endSpan / 2f, middlePosition.y)
performPinch(uiController, startPoint1, startPoint2, endPoint1, endPoint2, duration)
}
}
val startPoint1 = PointF(middlePosition.x - startSpan / 2f, middlePosition.y)
val startPoint2 = PointF(middlePosition.x + startSpan / 2f, middlePosition.y)
val endPoint1 = PointF(middlePosition.x - endSpan / 2f, middlePosition.y)
val endPoint2 = PointF(middlePosition.x + endSpan / 2f, middlePosition.y)
performPinch(uiController, startPoint1, startPoint2, endPoint1, endPoint2, duration)
}
}
}
fun quickScale(
deltaY: Float,
startPoint: PointF? = null,
withVelocity: Boolean = true,
duration: Long = DEFAULT_GESTURE_DURATION,
interrupt: Boolean = false
): ViewAction {
return object : ViewAction {
override fun getConstraints(): Matcher<View> = ViewMatchers.isEnabled()
fun quickScale(
deltaY: Float,
startPoint: PointF? = null,
withVelocity: Boolean = true,
duration: Long = DEFAULT_GESTURE_DURATION,
interrupt: Boolean = false
): ViewAction {
return object : ViewAction {
override fun getConstraints(): Matcher<View> = ViewMatchers.isEnabled()
override fun getDescription(): String = "quick scale ${deltaY}Y"
override fun getDescription(): String = "quick scale ${deltaY}Y"
override fun perform(uiController: UiController, view: View) {
var middlePosition = startPoint
if (middlePosition == null) {
middlePosition = getCenterPointF(view)
override fun perform(uiController: UiController, view: View) {
var middlePosition = startPoint
if (middlePosition == null) {
middlePosition = getCenterPointF(view)
}
val endPoint = PointF(middlePosition.x, middlePosition.y + deltaY)
performQuickScale(uiController, middlePosition, endPoint, withVelocity, duration, interrupt)
}
}
val endPoint = PointF(middlePosition.x, middlePosition.y + deltaY)
performQuickScale(uiController, middlePosition, endPoint, withVelocity, duration, interrupt)
}
}
}
fun move(
deltaX: Float,
deltaY: Float,
startPoint: PointF? = null,
withVelocity: Boolean = true,
duration: Long = DEFAULT_GESTURE_DURATION
): ViewAction {
return object : ViewAction {
override fun getConstraints(): Matcher<View> = ViewMatchers.isEnabled()
fun move(
deltaX: Float,
deltaY: Float,
startPoint: PointF? = null,
withVelocity: Boolean = true,
duration: Long = DEFAULT_GESTURE_DURATION
): ViewAction {
return object : ViewAction {
override fun getConstraints(): Matcher<View> = ViewMatchers.isEnabled()
override fun getDescription(): String = "move ${deltaX}X, ${deltaY}Y"
override fun getDescription(): String = "move ${deltaX}X, ${deltaY}Y"
override fun perform(uiController: UiController, view: View) {
var middlePosition = startPoint
if (middlePosition == null) {
middlePosition = getCenterPointF(view)
override fun perform(uiController: UiController, view: View) {
var middlePosition = startPoint
if (middlePosition == null) {
middlePosition = getCenterPointF(view)
}
val endPoint = PointF(middlePosition.x + deltaX, middlePosition.y + deltaY)
performMove(uiController, middlePosition, endPoint, withVelocity, duration)
}
}
val endPoint = PointF(middlePosition.x + deltaX, middlePosition.y + deltaY)
performMove(uiController, middlePosition, endPoint, withVelocity, duration)
}
}
}
private fun getCenterPointF(view: View): PointF {
val locationOnScreen = IntArray(2)
view.getLocationOnScreen(locationOnScreen)
val viewHeight = view.height * view.scaleY
val viewWidth = view.width * view.scaleX
return PointF(
(locationOnScreen[0] + viewWidth / 2).toInt().toFloat(),
(locationOnScreen[1] + viewHeight / 2).toInt().toFloat()
)
}
private fun getCenterPointF(view: View): PointF {
val locationOnScreen = IntArray(2)
view.getLocationOnScreen(locationOnScreen)
val viewHeight = view.height * view.scaleY
val viewWidth = view.width * view.scaleX
return PointF(
(locationOnScreen[0] + viewWidth / 2).toInt().toFloat(),
(locationOnScreen[1] + viewHeight / 2).toInt().toFloat()
)
}
// https://stackoverflow.com/a/46443628/9126211
private fun performPinch(
uiController: UiController,
startPoint1: PointF,
startPoint2: PointF,
endPoint1: PointF,
endPoint2: PointF,
duration: Long
) {
val eventMinInterval: Long = 10
val startTime = SystemClock.uptimeMillis()
var eventTime = startTime
var event: MotionEvent
var eventX1: Float = startPoint1.x
var eventY1: Float = startPoint1.y
var eventX2: Float = startPoint2.x
var eventY2: Float = startPoint2.y
// https://stackoverflow.com/a/46443628/9126211
private fun performPinch(
uiController: UiController,
startPoint1: PointF,
startPoint2: PointF,
endPoint1: PointF,
endPoint2: PointF,
duration: Long
) {
val eventMinInterval: Long = 10
val startTime = SystemClock.uptimeMillis()
var eventTime = startTime
var event: MotionEvent
var eventX1: Float = startPoint1.x
var eventY1: Float = startPoint1.y
var eventX2: Float = startPoint2.x
var eventY2: Float = startPoint2.y
// Specify the property for the two touch points
val properties = arrayOfNulls<MotionEvent.PointerProperties>(2)
val pp1 = MotionEvent.PointerProperties()
pp1.id = 0
pp1.toolType = MotionEvent.TOOL_TYPE_FINGER
val pp2 = MotionEvent.PointerProperties()
pp2.id = 1
pp2.toolType = MotionEvent.TOOL_TYPE_FINGER
// Specify the property for the two touch points
val properties = arrayOfNulls<MotionEvent.PointerProperties>(2)
val pp1 = MotionEvent.PointerProperties()
pp1.id = 0
pp1.toolType = MotionEvent.TOOL_TYPE_FINGER
val pp2 = MotionEvent.PointerProperties()
pp2.id = 1
pp2.toolType = MotionEvent.TOOL_TYPE_FINGER
properties[0] = pp1
properties[1] = pp2
properties[0] = pp1
properties[1] = pp2
// Specify the coordinations of the two touch points
// NOTE: you MUST set the pressure and size value, or it doesn't work
val pointerCoords = arrayOfNulls<MotionEvent.PointerCoords>(2)
val pc1 = MotionEvent.PointerCoords()
pc1.x = eventX1
pc1.y = eventY1
pc1.pressure = 1f
pc1.size = 1f
val pc2 = MotionEvent.PointerCoords()
pc2.x = eventX2
pc2.y = eventY2
pc2.pressure = 1f
pc2.size = 1f
pointerCoords[0] = pc1
pointerCoords[1] = pc2
// Specify the coordinations of the two touch points
// NOTE: you MUST set the pressure and size value, or it doesn't work
val pointerCoords = arrayOfNulls<MotionEvent.PointerCoords>(2)
val pc1 = MotionEvent.PointerCoords()
pc1.x = eventX1
pc1.y = eventY1
pc1.pressure = 1f
pc1.size = 1f
val pc2 = MotionEvent.PointerCoords()
pc2.x = eventX2
pc2.y = eventY2
pc2.pressure = 1f
pc2.size = 1f
pointerCoords[0] = pc1
pointerCoords[1] = pc2
/*
* Events sequence of zoom gesture:
@@ -162,118 +162,119 @@ object GesturesUiTestUtils {
* 6. Send ACTION_UP of one end point
*/
try {
// Step 1
event = MotionEvent.obtain(
startTime, eventTime,
MotionEvent.ACTION_DOWN, 1, properties,
pointerCoords, 0, 0, 1f, 1f, 0, 0, 0, 0
)
injectMotionEventToUiController(uiController, event)
try {
// Step 1
event = MotionEvent.obtain(
startTime, eventTime,
MotionEvent.ACTION_DOWN, 1, properties,
pointerCoords, 0, 0, 1f, 1f, 0, 0, 0, 0
)
injectMotionEventToUiController(uiController, event)
// Step 2
event = MotionEvent.obtain(
startTime, eventTime,
MotionEvent.ACTION_POINTER_DOWN + (pp2.id shl MotionEvent.ACTION_POINTER_INDEX_SHIFT), 2,
properties, pointerCoords, 0, 0, 1f, 1f, 0, 0, 0, 0
)
injectMotionEventToUiController(uiController, event)
// Step 2
event = MotionEvent.obtain(
startTime, eventTime,
MotionEvent.ACTION_POINTER_DOWN + (pp2.id shl MotionEvent.ACTION_POINTER_INDEX_SHIFT), 2,
properties, pointerCoords, 0, 0, 1f, 1f, 0, 0, 0, 0
)
injectMotionEventToUiController(uiController, event)
// Step 3, 4
val moveEventNumber = duration / eventMinInterval
// Step 3, 4
val moveEventNumber = duration / eventMinInterval
val stepX1: Float
val stepY1: Float
val stepX2: Float
val stepY2: Float
val stepX1: Float
val stepY1: Float
val stepX2: Float
val stepY2: Float
stepX1 = (endPoint1.x - startPoint1.x) / moveEventNumber
stepY1 = (endPoint1.y - startPoint1.y) / moveEventNumber
stepX2 = (endPoint2.x - startPoint2.x) / moveEventNumber
stepY2 = (endPoint2.y - startPoint2.y) / moveEventNumber
stepX1 = (endPoint1.x - startPoint1.x) / moveEventNumber
stepY1 = (endPoint1.y - startPoint1.y) / moveEventNumber
stepX2 = (endPoint2.x - startPoint2.x) / moveEventNumber
stepY2 = (endPoint2.y - startPoint2.y) / moveEventNumber
for (i in 0 until moveEventNumber) {
// Update the move events
eventTime += eventMinInterval
eventX1 += stepX1
eventY1 += stepY1
eventX2 += stepX2
eventY2 += stepY2
for (i in 0 until moveEventNumber) {
// Update the move events
eventTime += eventMinInterval
eventX1 += stepX1
eventY1 += stepY1
eventX2 += stepX2
eventY2 += stepY2
pc1.x = eventX1
pc1.y = eventY1
pc2.x = eventX2
pc2.y = eventY2
pointerCoords[0] = pc1
pointerCoords[1] = pc2
event = MotionEvent.obtain(
startTime, eventTime,
MotionEvent.ACTION_MOVE, 2, properties,
pointerCoords, 0, 0, 1f, 1f, 0, 0, 0, 0
)
injectMotionEventToUiController(uiController, event)
}
// Step 5
pc1.x = endPoint1.x
pc1.y = endPoint1.y
pc2.x = endPoint2.x
pc2.y = endPoint2.y
pointerCoords[0] = pc1
pointerCoords[1] = pc2
eventTime += eventMinInterval
event = MotionEvent.obtain(
startTime, eventTime,
MotionEvent.ACTION_POINTER_UP + (pp2.id shl MotionEvent.ACTION_POINTER_INDEX_SHIFT), 2, properties,
pointerCoords, 0, 0, 1f, 1f, 0, 0, 0, 0
)
injectMotionEventToUiController(uiController, event)
// Step 6
eventTime += eventMinInterval
event = MotionEvent.obtain(
startTime, eventTime,
MotionEvent.ACTION_UP, 1, properties,
pointerCoords, 0, 0, 1f, 1f, 0, 0, 0, 0
)
injectMotionEventToUiController(uiController, event)
} catch (ex: InjectEventSecurityException) {
throw RuntimeException("Could not perform pinch", ex)
}
}
private fun performQuickScale(
uiController: UiController,
startPoint: PointF,
endPoint: PointF,
withVelocity: Boolean,
duration: Long,
interrupt: Boolean
) {
val eventMinInterval: Long = 10
val tapDownMinInterval: Long = 40 // ViewConfiguration#DOUBLE_TAP_MIN_TIME = 40
val startTime = SystemClock.uptimeMillis()
var eventTime = startTime
var event: MotionEvent
var eventX1: Float = startPoint.x
var eventY1: Float = startPoint.y
var properties = arrayOfNulls<MotionEvent.PointerProperties>(1)
val pp1 = MotionEvent.PointerProperties()
pp1.id = 0
pp1.toolType = MotionEvent.TOOL_TYPE_FINGER
properties[0] = pp1
var pointerCoords = arrayOfNulls<MotionEvent.PointerCoords>(1)
val pc1 = MotionEvent.PointerCoords()
pc1.x = eventX1
pc1.y = eventY1
pc2.x = eventX2
pc2.y = eventY2
pc1.pressure = 1f
pc1.size = 1f
pointerCoords[0] = pc1
pointerCoords[1] = pc2
event = MotionEvent.obtain(
startTime, eventTime,
MotionEvent.ACTION_MOVE, 2, properties,
pointerCoords, 0, 0, 1f, 1f, 0, 0, 0, 0
)
injectMotionEventToUiController(uiController, event)
}
// Step 5
pc1.x = endPoint1.x
pc1.y = endPoint1.y
pc2.x = endPoint2.x
pc2.y = endPoint2.y
pointerCoords[0] = pc1
pointerCoords[1] = pc2
eventTime += eventMinInterval
event = MotionEvent.obtain(
startTime, eventTime,
MotionEvent.ACTION_POINTER_UP + (pp2.id shl MotionEvent.ACTION_POINTER_INDEX_SHIFT), 2, properties,
pointerCoords, 0, 0, 1f, 1f, 0, 0, 0, 0
)
injectMotionEventToUiController(uiController, event)
// Step 6
eventTime += eventMinInterval
event = MotionEvent.obtain(
startTime, eventTime,
MotionEvent.ACTION_UP, 1, properties,
pointerCoords, 0, 0, 1f, 1f, 0, 0, 0, 0
)
injectMotionEventToUiController(uiController, event)
} catch (ex: InjectEventSecurityException) {
throw RuntimeException("Could not perform pinch", ex)
}
}
private fun performQuickScale(
uiController: UiController,
startPoint: PointF,
endPoint: PointF,
withVelocity: Boolean,
duration: Long,
interrupt: Boolean
) {
val eventMinInterval: Long = 10
val tapDownMinInterval: Long = 40 // ViewConfiguration#DOUBLE_TAP_MIN_TIME = 40
val startTime = SystemClock.uptimeMillis()
var eventTime = startTime
var event: MotionEvent
var eventX1: Float = startPoint.x
var eventY1: Float = startPoint.y
var properties = arrayOfNulls<MotionEvent.PointerProperties>(1)
val pp1 = MotionEvent.PointerProperties()
pp1.id = 0
pp1.toolType = MotionEvent.TOOL_TYPE_FINGER
properties[0] = pp1
var pointerCoords = arrayOfNulls<MotionEvent.PointerCoords>(1)
val pc1 = MotionEvent.PointerCoords()
pc1.x = eventX1
pc1.y = eventY1
pc1.pressure = 1f
pc1.size = 1f
pointerCoords[0] = pc1
/*
* Events sequence of quick scale gesture:
@@ -284,145 +285,145 @@ object GesturesUiTestUtils {
* 4. Send ACTION_MOVE with updated middle points (x,y), until reach the end points
* 5. Send ACTION_UP of one end point
*/
try {
// Step 1
event = MotionEvent.obtain(
startTime, eventTime,
MotionEvent.ACTION_DOWN, 1, properties,
pointerCoords, 0, 0, 1f, 1f, 0, 0, 0, 0
)
injectMotionEventToUiController(uiController, event)
try {
// Step 1
event = MotionEvent.obtain(
startTime, eventTime,
MotionEvent.ACTION_DOWN, 1, properties,
pointerCoords, 0, 0, 1f, 1f, 0, 0, 0, 0
)
injectMotionEventToUiController(uiController, event)
// Step 2
eventTime += eventMinInterval
event = MotionEvent.obtain(
startTime, eventTime,
MotionEvent.ACTION_UP, 1, properties,
pointerCoords, 0, 0, 1f, 1f, 0, 0, 0, 0
)
injectMotionEventToUiController(uiController, event)
// Step 2
eventTime += eventMinInterval
event = MotionEvent.obtain(
startTime, eventTime,
MotionEvent.ACTION_UP, 1, properties,
pointerCoords, 0, 0, 1f, 1f, 0, 0, 0, 0
)
injectMotionEventToUiController(uiController, event)
// Step 3
eventTime += tapDownMinInterval
event = MotionEvent.obtain(
startTime, eventTime,
MotionEvent.ACTION_DOWN, 1, properties,
pointerCoords, 0, 0, 1f, 1f, 0, 0, 0, 0
)
injectMotionEventToUiController(uiController, event)
// Step 3
eventTime += tapDownMinInterval
event = MotionEvent.obtain(
startTime, eventTime,
MotionEvent.ACTION_DOWN, 1, properties,
pointerCoords, 0, 0, 1f, 1f, 0, 0, 0, 0
)
injectMotionEventToUiController(uiController, event)
// Step 4
val moveEventNumber = duration / eventMinInterval
// Step 4
val moveEventNumber = duration / eventMinInterval
val stepX1: Float
val stepY1: Float
val stepX1: Float
val stepY1: Float
stepX1 = (endPoint.x - startPoint.x) / moveEventNumber
stepY1 = (endPoint.y - startPoint.y) / moveEventNumber
stepX1 = (endPoint.x - startPoint.x) / moveEventNumber
stepY1 = (endPoint.y - startPoint.y) / moveEventNumber
var interrupted = false
var interrupted = false
for (i in 0 until moveEventNumber) {
// Update the move events
eventTime += eventMinInterval
eventX1 += stepX1
eventY1 += stepY1
for (i in 0 until moveEventNumber) {
// Update the move events
eventTime += eventMinInterval
eventX1 += stepX1
eventY1 += stepY1
pc1.x = eventX1
pc1.y = eventY1
pointerCoords[0] = pc1
event = MotionEvent.obtain(
startTime, eventTime,
MotionEvent.ACTION_MOVE, if (interrupted) 2 else 1, properties,
pointerCoords, 0, 0, 1f, 1f, 0, 0, 0, 0
)
injectMotionEventToUiController(uiController, event)
if (interrupt && i == moveEventNumber / 2) {
// Specify the property for the two touch points
properties = arrayOfNulls<MotionEvent.PointerProperties>(2)
val pp2 = MotionEvent.PointerProperties()
pp2.id = 1
pp2.toolType = MotionEvent.TOOL_TYPE_FINGER
properties[0] = pp1
properties[1] = pp2
// Specify the coordinations of the two touch points
// NOTE: you MUST set the pressure and size value, or it doesn't work
pointerCoords = arrayOfNulls<MotionEvent.PointerCoords>(2)
val pc2 = MotionEvent.PointerCoords()
pc2.x = startPoint.x
pc2.y = startPoint.y
pc2.pressure = 1f
pc2.size = 1f
pointerCoords[0] = pc1
pointerCoords[1] = pc2
eventTime += eventMinInterval
event = MotionEvent.obtain(
startTime, eventTime,
MotionEvent.ACTION_POINTER_DOWN + (pp2.id shl MotionEvent.ACTION_POINTER_INDEX_SHIFT), 2,
properties, pointerCoords, 0, 0, 1f, 1f, 0, 0, 0, 0
)
injectMotionEventToUiController(uiController, event)
interrupted = true
}
}
if (!withVelocity) {
eventTime += eventMinInterval
event = MotionEvent.obtain(
startTime, eventTime,
MotionEvent.ACTION_MOVE, 1, properties,
pointerCoords, 0, 0, 1f, 1f, 0, 0, 0, 0
)
injectMotionEventToUiController(uiController, event)
}
// Step 5
eventTime += eventMinInterval
event = MotionEvent.obtain(
startTime, eventTime,
MotionEvent.ACTION_UP, 1, properties,
pointerCoords, 0, 0, 1f, 1f, 0, 0, 0, 0
)
injectMotionEventToUiController(uiController, event)
} catch (ex: InjectEventSecurityException) {
throw RuntimeException("Could not perform quick scale", ex)
}
}
private fun performMove(
uiController: UiController,
startPoint: PointF,
endPoint: PointF,
withVelocity: Boolean,
duration: Long
) {
val eventMinInterval: Long = 10
val startTime = SystemClock.uptimeMillis()
var eventTime = startTime
var event: MotionEvent
var eventX1: Float = startPoint.x
var eventY1: Float = startPoint.y
val properties = arrayOfNulls<MotionEvent.PointerProperties>(1)
val pp1 = MotionEvent.PointerProperties()
pp1.id = 0
pp1.toolType = MotionEvent.TOOL_TYPE_FINGER
properties[0] = pp1
val pointerCoords = arrayOfNulls<MotionEvent.PointerCoords>(1)
val pc1 = MotionEvent.PointerCoords()
pc1.x = eventX1
pc1.y = eventY1
pc1.pressure = 1f
pc1.size = 1f
pointerCoords[0] = pc1
event = MotionEvent.obtain(
startTime, eventTime,
MotionEvent.ACTION_MOVE, if (interrupted) 2 else 1, properties,
pointerCoords, 0, 0, 1f, 1f, 0, 0, 0, 0
)
injectMotionEventToUiController(uiController, event)
if (interrupt && i == moveEventNumber / 2) {
// Specify the property for the two touch points
properties = arrayOfNulls<MotionEvent.PointerProperties>(2)
val pp2 = MotionEvent.PointerProperties()
pp2.id = 1
pp2.toolType = MotionEvent.TOOL_TYPE_FINGER
properties[0] = pp1
properties[1] = pp2
// Specify the coordinations of the two touch points
// NOTE: you MUST set the pressure and size value, or it doesn't work
pointerCoords = arrayOfNulls<MotionEvent.PointerCoords>(2)
val pc2 = MotionEvent.PointerCoords()
pc2.x = startPoint.x
pc2.y = startPoint.y
pc2.pressure = 1f
pc2.size = 1f
pointerCoords[0] = pc1
pointerCoords[1] = pc2
eventTime += eventMinInterval
event = MotionEvent.obtain(
startTime, eventTime,
MotionEvent.ACTION_POINTER_DOWN + (pp2.id shl MotionEvent.ACTION_POINTER_INDEX_SHIFT), 2,
properties, pointerCoords, 0, 0, 1f, 1f, 0, 0, 0, 0
)
injectMotionEventToUiController(uiController, event)
interrupted = true
}
}
if (!withVelocity) {
eventTime += eventMinInterval
event = MotionEvent.obtain(
startTime, eventTime,
MotionEvent.ACTION_MOVE, 1, properties,
pointerCoords, 0, 0, 1f, 1f, 0, 0, 0, 0
)
injectMotionEventToUiController(uiController, event)
}
// Step 5
eventTime += eventMinInterval
event = MotionEvent.obtain(
startTime, eventTime,
MotionEvent.ACTION_UP, 1, properties,
pointerCoords, 0, 0, 1f, 1f, 0, 0, 0, 0
)
injectMotionEventToUiController(uiController, event)
} catch (ex: InjectEventSecurityException) {
throw RuntimeException("Could not perform quick scale", ex)
}
}
private fun performMove(
uiController: UiController,
startPoint: PointF,
endPoint: PointF,
withVelocity: Boolean,
duration: Long
) {
val eventMinInterval: Long = 10
val startTime = SystemClock.uptimeMillis()
var eventTime = startTime
var event: MotionEvent
var eventX1: Float = startPoint.x
var eventY1: Float = startPoint.y
val properties = arrayOfNulls<MotionEvent.PointerProperties>(1)
val pp1 = MotionEvent.PointerProperties()
pp1.id = 0
pp1.toolType = MotionEvent.TOOL_TYPE_FINGER
properties[0] = pp1
val pointerCoords = arrayOfNulls<MotionEvent.PointerCoords>(1)
val pc1 = MotionEvent.PointerCoords()
pc1.x = eventX1
pc1.y = eventY1
pc1.pressure = 1f
pc1.size = 1f
pointerCoords[0] = pc1
/*
* Events sequence of move gesture:
*
@@ -430,87 +431,87 @@ object GesturesUiTestUtils {
* 2. Send ACTION_MOVE with updated middle points (x,y), until reach the end points
* 3. Send ACTION_UP
*/
try {
// Step 1
event = MotionEvent.obtain(
startTime, eventTime,
MotionEvent.ACTION_DOWN, 1, properties,
pointerCoords, 0, 0, 1f, 1f, 0, 0, 0, 0
)
injectMotionEventToUiController(uiController, event)
try {
// Step 1
event = MotionEvent.obtain(
startTime, eventTime,
MotionEvent.ACTION_DOWN, 1, properties,
pointerCoords, 0, 0, 1f, 1f, 0, 0, 0, 0
)
injectMotionEventToUiController(uiController, event)
// Step 2
val moveEventNumber = duration / eventMinInterval
// Step 2
val moveEventNumber = duration / eventMinInterval
val stepX1: Float
val stepY1: Float
val stepX1: Float
val stepY1: Float
stepX1 = (endPoint.x - startPoint.x) / moveEventNumber
stepY1 = (endPoint.y - startPoint.y) / moveEventNumber
stepX1 = (endPoint.x - startPoint.x) / moveEventNumber
stepY1 = (endPoint.y - startPoint.y) / moveEventNumber
for (i in 0 until moveEventNumber) {
// Update the move events
eventTime += eventMinInterval
eventX1 += stepX1
eventY1 += stepY1
for (i in 0 until moveEventNumber) {
// Update the move events
eventTime += eventMinInterval
eventX1 += stepX1
eventY1 += stepY1
pc1.x = eventX1
pc1.y = eventY1
pc1.x = eventX1
pc1.y = eventY1
pointerCoords[0] = pc1
pointerCoords[0] = pc1
event = MotionEvent.obtain(
startTime, eventTime,
MotionEvent.ACTION_MOVE, 1, properties,
pointerCoords, 0, 0, 1f, 1f, 0, 0, 0, 0
)
injectMotionEventToUiController(uiController, event)
}
event = MotionEvent.obtain(
startTime, eventTime,
MotionEvent.ACTION_MOVE, 1, properties,
pointerCoords, 0, 0, 1f, 1f, 0, 0, 0, 0
)
injectMotionEventToUiController(uiController, event)
}
if (!withVelocity) {
eventTime += eventMinInterval
event = MotionEvent.obtain(
startTime, eventTime,
MotionEvent.ACTION_MOVE, 1, properties,
pointerCoords, 0, 0, 1f, 1f, 0, 0, 0, 0
)
injectMotionEventToUiController(uiController, event)
}
if (!withVelocity) {
eventTime += eventMinInterval
event = MotionEvent.obtain(
startTime, eventTime,
MotionEvent.ACTION_MOVE, 1, properties,
pointerCoords, 0, 0, 1f, 1f, 0, 0, 0, 0
)
injectMotionEventToUiController(uiController, event)
}
// Step 3
eventTime += eventMinInterval
event = MotionEvent.obtain(
startTime, eventTime,
MotionEvent.ACTION_UP, 1, properties,
pointerCoords, 0, 0, 1f, 1f, 0, 0, 0, 0
)
injectMotionEventToUiController(uiController, event)
} catch (ex: InjectEventSecurityException) {
throw RuntimeException("Could not perform quick scale", ex)
// Step 3
eventTime += eventMinInterval
event = MotionEvent.obtain(
startTime, eventTime,
MotionEvent.ACTION_UP, 1, properties,
pointerCoords, 0, 0, 1f, 1f, 0, 0, 0, 0
)
injectMotionEventToUiController(uiController, event)
} catch (ex: InjectEventSecurityException) {
throw RuntimeException("Could not perform quick scale", ex)
}
}
}
/**
* Safely call uiController.injectMotionEvent(event): Detect any error and "convert" it to an
* IllegalStateException
*/
@Throws(InjectEventSecurityException::class)
private fun injectMotionEventToUiController(uiController: UiController, event: MotionEvent) {
val injectEventSucceeded = uiController.injectMotionEvent(event)
if (!injectEventSucceeded) {
throw IllegalStateException("Error performing event $event")
/**
* Safely call uiController.injectMotionEvent(event): Detect any error and "convert" it to an
* IllegalStateException
*/
@Throws(InjectEventSecurityException::class)
private fun injectMotionEventToUiController(uiController: UiController, event: MotionEvent) {
val injectEventSucceeded = uiController.injectMotionEvent(event)
if (!injectEventSucceeded) {
throw IllegalStateException("Error performing event $event")
}
}
}
}
fun Int.loopFor(millis: Long) {
Espresso.onView(ViewMatchers.withId(this)).perform(object : ViewAction {
override fun getDescription(): String = "waiting for $millis"
Espresso.onView(ViewMatchers.withId(this)).perform(object : ViewAction {
override fun getDescription(): String = "waiting for $millis"
override fun getConstraints(): Matcher<View> = ViewMatchers.isEnabled()
override fun getConstraints(): Matcher<View> = ViewMatchers.isEnabled()
override fun perform(uiController: UiController?, view: View?) {
uiController?.loopMainThreadForAtLeast(millis)
}
})
}
override fun perform(uiController: UiController?, view: View?) {
uiController?.loopMainThreadForAtLeast(millis)
}
})
}

View File

@@ -16,178 +16,178 @@ import org.junit.Before
import org.junit.Test
class MapGestureDetectorTest : BaseTest() {
override fun getActivityClass() = SimpleMapActivity::class.java
override fun getActivityClass() = SimpleMapActivity::class.java
private var maxWidth: Int = 0
private var maxHeight: Int = 0
private var maxWidth: Int = 0
private var maxHeight: Int = 0
@Before
fun setup() {
maxWidth = mapView.width
maxHeight = mapView.height
}
@Test
fun sanity_quickZoom() {
validateTestSetup()
var initialZoom: Double? = null
rule.runOnUiThread {
initialZoom = mapboxMap.cameraPosition.zoom
}
onView(withId(R.id.mapView)).perform(quickScale(maxHeight / 2f, withVelocity = false))
rule.runOnUiThread {
Assert.assertTrue(mapboxMap.cameraPosition.zoom > initialZoom!!)
}
}
@Test
fun quickZoomDisabled_phantomQuickZoom_moveStillEnabled_15091() {
// regression test for https://github.com/mapbox/mapbox-gl-native/issues/15091
validateTestSetup()
var initialCameraPosition: CameraPosition? = null
rule.runOnUiThread {
// zoom in so we can move vertically
mapboxMap.moveCamera(CameraUpdateFactory.zoomTo(4.0))
initialCameraPosition = mapboxMap.cameraPosition
mapboxMap.uiSettings.isQuickZoomGesturesEnabled = false
@Before
fun setup() {
maxWidth = mapView.width
maxHeight = mapView.height
}
onView(withId(R.id.mapView)).perform(quickScale(maxHeight / 2f))
rule.runOnUiThread {
// camera did not move
Assert.assertEquals(initialCameraPosition!!, mapboxMap.cameraPosition)
@Test
fun sanity_quickZoom() {
validateTestSetup()
var initialZoom: Double? = null
rule.runOnUiThread {
initialZoom = mapboxMap.cameraPosition.zoom
}
onView(withId(R.id.mapView)).perform(quickScale(maxHeight / 2f, withVelocity = false))
rule.runOnUiThread {
Assert.assertTrue(mapboxMap.cameraPosition.zoom > initialZoom!!)
}
}
// move to expected target
onView(withId(R.id.mapView)).perform(move(-maxWidth / 2f, -maxHeight / 2f, withVelocity = false))
rule.runOnUiThread {
Assert.assertNotEquals(initialCameraPosition!!.target.latitude, mapboxMap.cameraPosition.target.latitude, 1.0)
Assert.assertNotEquals(initialCameraPosition!!.target.longitude, mapboxMap.cameraPosition.target.longitude, 1.0)
}
}
@Test
fun quickZoomDisabled_phantomQuickZoom_moveStillEnabled_15091() {
// regression test for https://github.com/mapbox/mapbox-gl-native/issues/15091
validateTestSetup()
var initialCameraPosition: CameraPosition? = null
rule.runOnUiThread {
// zoom in so we can move vertically
mapboxMap.moveCamera(CameraUpdateFactory.zoomTo(4.0))
initialCameraPosition = mapboxMap.cameraPosition
mapboxMap.uiSettings.isQuickZoomGesturesEnabled = false
}
@Test
fun quickZoom_doNotMove_14227() {
// test for https://github.com/mapbox/mapbox-gl-native/issues/14227
validateTestSetup()
var initialTarget: LatLng? = null
rule.runOnUiThread {
initialTarget = mapboxMap.cameraPosition.target
onView(withId(R.id.mapView)).perform(quickScale(maxHeight / 2f))
rule.runOnUiThread {
// camera did not move
Assert.assertEquals(initialCameraPosition!!, mapboxMap.cameraPosition)
}
// move to expected target
onView(withId(R.id.mapView)).perform(move(-maxWidth / 2f, -maxHeight / 2f, withVelocity = false))
rule.runOnUiThread {
Assert.assertNotEquals(initialCameraPosition!!.target.latitude, mapboxMap.cameraPosition.target.latitude, 1.0)
Assert.assertNotEquals(initialCameraPosition!!.target.longitude, mapboxMap.cameraPosition.target.longitude, 1.0)
}
}
onView(withId(R.id.mapView)).perform(quickScale(maxHeight / 2f))
rule.runOnUiThread {
// camera did not move
Assert.assertEquals(initialTarget!!.latitude, mapboxMap.cameraPosition.target.latitude, 1.0)
Assert.assertEquals(initialTarget!!.longitude, mapboxMap.cameraPosition.target.longitude, 1.0)
}
}
@Test
fun quickZoom_doNotMove_14227() {
// test for https://github.com/mapbox/mapbox-gl-native/issues/14227
validateTestSetup()
var initialTarget: LatLng? = null
rule.runOnUiThread {
initialTarget = mapboxMap.cameraPosition.target
}
@Test
fun quickZoom_interrupted_moveStillEnabled_14598() {
// test for https://github.com/mapbox/mapbox-gl-native/issues/14598
validateTestSetup()
onView(withId(R.id.mapView)).perform(quickScale(maxHeight / 2f, interrupt = true))
var initialCameraPosition: CameraPosition? = null
rule.runOnUiThread {
// zoom in so we can move vertically
mapboxMap.moveCamera(CameraUpdateFactory.zoomTo(4.0))
initialCameraPosition = mapboxMap.cameraPosition
mapboxMap.uiSettings.isQuickZoomGesturesEnabled = false
onView(withId(R.id.mapView)).perform(quickScale(maxHeight / 2f))
rule.runOnUiThread {
// camera did not move
Assert.assertEquals(initialTarget!!.latitude, mapboxMap.cameraPosition.target.latitude, 1.0)
Assert.assertEquals(initialTarget!!.longitude, mapboxMap.cameraPosition.target.longitude, 1.0)
}
}
// move to expected target
onView(withId(R.id.mapView)).perform(move(-maxWidth / 2f, -maxHeight / 2f, withVelocity = false))
rule.runOnUiThread {
Assert.assertNotEquals(initialCameraPosition!!.target.latitude, mapboxMap.cameraPosition.target.latitude, 1.0)
Assert.assertNotEquals(initialCameraPosition!!.target.longitude, mapboxMap.cameraPosition.target.longitude, 1.0)
}
}
@Test
fun quickZoom_interrupted_moveStillEnabled_14598() {
// test for https://github.com/mapbox/mapbox-gl-native/issues/14598
validateTestSetup()
onView(withId(R.id.mapView)).perform(quickScale(maxHeight / 2f, interrupt = true))
@Test
fun quickZoom_ignoreDoubleTap() {
// test for https://github.com/mapbox/mapbox-gl-native/issues/14013
validateTestSetup()
var initialZoom: Double? = null
rule.runOnUiThread {
mapboxMap.moveCamera(CameraUpdateFactory.zoomTo(2.0))
initialZoom = mapboxMap.cameraPosition.zoom
}
onView(withId(R.id.mapView)).perform(quickScale(-(mapboxMap.gesturesManager.standardScaleGestureDetector.spanSinceStartThreshold * 2), withVelocity = false, duration = 1000L))
R.id.mapView.loopFor(MapboxConstants.ANIMATION_DURATION.toLong())
rule.runOnUiThread {
Assert.assertTrue(mapboxMap.cameraPosition.zoom < initialZoom!!)
}
}
var initialCameraPosition: CameraPosition? = null
rule.runOnUiThread {
// zoom in so we can move vertically
mapboxMap.moveCamera(CameraUpdateFactory.zoomTo(4.0))
initialCameraPosition = mapboxMap.cameraPosition
mapboxMap.uiSettings.isQuickZoomGesturesEnabled = false
}
@Test
fun doubleTap_minimalMovement() {
validateTestSetup()
var initialZoom: Double? = null
rule.runOnUiThread {
initialZoom = mapboxMap.cameraPosition.zoom
}
onView(withId(R.id.mapView)).perform(quickScale(mapboxMap.gesturesManager.standardScaleGestureDetector.spanSinceStartThreshold / 2, withVelocity = false, duration = 50L))
R.id.mapView.loopFor(MapboxConstants.ANIMATION_DURATION.toLong())
rule.runOnUiThread {
Assert.assertEquals(initialZoom!! + 1, mapboxMap.cameraPosition.zoom, 0.1)
}
}
@Test
fun doubleTap_overMaxThreshold_ignore_14013() {
// test for https://github.com/mapbox/mapbox-gl-native/issues/14013
validateTestSetup()
var initialZoom: Double? = null
rule.runOnUiThread {
initialZoom = mapboxMap.cameraPosition.zoom
mapboxMap.uiSettings.isQuickZoomGesturesEnabled = false
}
onView(withId(R.id.mapView)).perform(quickScale(mapboxMap.gesturesManager.standardScaleGestureDetector.spanSinceStartThreshold * 2, withVelocity = false, duration = 50L))
R.id.mapView.loopFor(MapboxConstants.ANIMATION_DURATION.toLong())
rule.runOnUiThread {
Assert.assertEquals(initialZoom!!, mapboxMap.cameraPosition.zoom, 0.01)
}
}
@Test
fun doubleTap_interrupted_moveStillEnabled() {
validateTestSetup()
rule.runOnUiThread {
mapboxMap.moveCamera(CameraUpdateFactory.zoomTo(4.0))
// move to expected target
onView(withId(R.id.mapView)).perform(move(-maxWidth / 2f, -maxHeight / 2f, withVelocity = false))
rule.runOnUiThread {
Assert.assertNotEquals(initialCameraPosition!!.target.latitude, mapboxMap.cameraPosition.target.latitude, 1.0)
Assert.assertNotEquals(initialCameraPosition!!.target.longitude, mapboxMap.cameraPosition.target.longitude, 1.0)
}
}
onView(withId(R.id.mapView)).perform(quickScale(mapboxMap.gesturesManager.standardScaleGestureDetector.spanSinceStartThreshold / 2, withVelocity = false, duration = 50L, interrupt = true))
var initialCameraPosition: CameraPosition? = null
rule.runOnUiThread {
// zoom in so we can move vertically
mapboxMap.moveCamera(CameraUpdateFactory.zoomTo(4.0))
initialCameraPosition = mapboxMap.cameraPosition
mapboxMap.uiSettings.isQuickZoomGesturesEnabled = false
@Test
fun quickZoom_ignoreDoubleTap() {
// test for https://github.com/mapbox/mapbox-gl-native/issues/14013
validateTestSetup()
var initialZoom: Double? = null
rule.runOnUiThread {
mapboxMap.moveCamera(CameraUpdateFactory.zoomTo(2.0))
initialZoom = mapboxMap.cameraPosition.zoom
}
onView(withId(R.id.mapView)).perform(quickScale(-(mapboxMap.gesturesManager.standardScaleGestureDetector.spanSinceStartThreshold * 2), withVelocity = false, duration = 1000L))
R.id.mapView.loopFor(MapboxConstants.ANIMATION_DURATION.toLong())
rule.runOnUiThread {
Assert.assertTrue(mapboxMap.cameraPosition.zoom < initialZoom!!)
}
}
// move to expected target
onView(withId(R.id.mapView)).perform(move(-maxWidth / 2f, -maxHeight / 2f, withVelocity = false))
rule.runOnUiThread {
Assert.assertNotEquals(initialCameraPosition!!.target.latitude, mapboxMap.cameraPosition.target.latitude, 1.0)
Assert.assertNotEquals(initialCameraPosition!!.target.longitude, mapboxMap.cameraPosition.target.longitude, 1.0)
@Test
fun doubleTap_minimalMovement() {
validateTestSetup()
var initialZoom: Double? = null
rule.runOnUiThread {
initialZoom = mapboxMap.cameraPosition.zoom
}
onView(withId(R.id.mapView)).perform(quickScale(mapboxMap.gesturesManager.standardScaleGestureDetector.spanSinceStartThreshold / 2, withVelocity = false, duration = 50L))
R.id.mapView.loopFor(MapboxConstants.ANIMATION_DURATION.toLong())
rule.runOnUiThread {
Assert.assertEquals(initialZoom!! + 1, mapboxMap.cameraPosition.zoom, 0.1)
}
}
}
@Test
fun quickZoom_roundTripping() {
validateTestSetup()
rule.runOnUiThread {
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(LatLng(51.0, 16.0), 3.0))
@Test
fun doubleTap_overMaxThreshold_ignore_14013() {
// test for https://github.com/mapbox/mapbox-gl-native/issues/14013
validateTestSetup()
var initialZoom: Double? = null
rule.runOnUiThread {
initialZoom = mapboxMap.cameraPosition.zoom
mapboxMap.uiSettings.isQuickZoomGesturesEnabled = false
}
onView(withId(R.id.mapView)).perform(quickScale(mapboxMap.gesturesManager.standardScaleGestureDetector.spanSinceStartThreshold * 2, withVelocity = false, duration = 50L))
R.id.mapView.loopFor(MapboxConstants.ANIMATION_DURATION.toLong())
rule.runOnUiThread {
Assert.assertEquals(initialZoom!!, mapboxMap.cameraPosition.zoom, 0.01)
}
}
onView(withId(R.id.mapView)).perform(quickScale(300f, withVelocity = false, duration = 750L))
onView(withId(R.id.mapView)).perform(quickScale(-300f, withVelocity = false, duration = 750L))
rule.runOnUiThread {
Assert.assertEquals(3.0, mapboxMap.cameraPosition.zoom, 0.0001)
@Test
fun doubleTap_interrupted_moveStillEnabled() {
validateTestSetup()
rule.runOnUiThread {
mapboxMap.moveCamera(CameraUpdateFactory.zoomTo(4.0))
}
onView(withId(R.id.mapView)).perform(quickScale(mapboxMap.gesturesManager.standardScaleGestureDetector.spanSinceStartThreshold / 2, withVelocity = false, duration = 50L, interrupt = true))
var initialCameraPosition: CameraPosition? = null
rule.runOnUiThread {
// zoom in so we can move vertically
mapboxMap.moveCamera(CameraUpdateFactory.zoomTo(4.0))
initialCameraPosition = mapboxMap.cameraPosition
mapboxMap.uiSettings.isQuickZoomGesturesEnabled = false
}
// move to expected target
onView(withId(R.id.mapView)).perform(move(-maxWidth / 2f, -maxHeight / 2f, withVelocity = false))
rule.runOnUiThread {
Assert.assertNotEquals(initialCameraPosition!!.target.latitude, mapboxMap.cameraPosition.target.latitude, 1.0)
Assert.assertNotEquals(initialCameraPosition!!.target.longitude, mapboxMap.cameraPosition.target.longitude, 1.0)
}
}
}
}
@Test
fun quickZoom_roundTripping() {
validateTestSetup()
rule.runOnUiThread {
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(LatLng(51.0, 16.0), 3.0))
}
onView(withId(R.id.mapView)).perform(quickScale(300f, withVelocity = false, duration = 750L))
onView(withId(R.id.mapView)).perform(quickScale(-300f, withVelocity = false, duration = 750L))
rule.runOnUiThread {
Assert.assertEquals(3.0, mapboxMap.cameraPosition.zoom, 0.0001)
}
}
}

View File

@@ -155,12 +155,12 @@ class NativeMapViewTest : AppCenter() {
@UiThreadTest
fun testJumpTo() {
val expected = CameraPosition.Builder()
.bearing(BEARING_TEST)
.target(LATLNG_TEST)
.tilt(PITCH_TEST)
.zoom(ZOOM_TEST)
.padding(PADDING_TEST)
.build()
.bearing(BEARING_TEST)
.target(LATLNG_TEST)
.tilt(PITCH_TEST)
.zoom(ZOOM_TEST)
.padding(PADDING_TEST)
.build()
// verify that the lazily set padding is ignored when a value is provided with the camera
nativeMapView.contentPadding = doubleArrayOf(1.0, 2.0, 3.0, 4.0)
nativeMapView.jumpTo(LATLNG_TEST, ZOOM_TEST, PITCH_TEST, BEARING_TEST, PADDING_TEST)
@@ -179,7 +179,7 @@ class NativeMapViewTest : AppCenter() {
val expected = LATLNG_TEST
nativeMapView.setLatLng(LATLNG_TEST, 0)
val actual = nativeMapView.latLngForPixel(
PointF((WIDTH / 2).toFloat(), (HEIGHT / 2).toFloat())
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)
@@ -224,18 +224,18 @@ class NativeMapViewTest : AppCenter() {
@Test
@UiThreadTest
fun testPrefetchZoomDelta() {
val expected = 2
nativeMapView.prefetchZoomDelta = 2
val actual = nativeMapView.prefetchZoomDelta
assertEquals("Prefetch zoom delta should match", expected, actual)
val expected = 2
nativeMapView.prefetchZoomDelta = 2
val actual = nativeMapView.prefetchZoomDelta
assertEquals("Prefetch zoom delta should match", expected, actual)
}
@Test
@UiThreadTest
fun testPrefetchZoomDeltaDefault() {
val expected = 4
val actual = nativeMapView.prefetchZoomDelta
assertEquals("Prefetch zoom delta should match", expected, actual)
val expected = 4
val actual = nativeMapView.prefetchZoomDelta
assertEquals("Prefetch zoom delta should match", expected, actual)
}
@Test
@@ -268,23 +268,23 @@ class NativeMapViewTest : AppCenter() {
assertEquals("Max zoom should match", expected, actual)
}
@Test
@UiThreadTest
fun testSetMinPitch() {
val expected = 60.0
nativeMapView.minPitch = expected
val actual = nativeMapView.minPitch
assertEquals("Min Pitch should match", expected, actual, 0.01)
}
@Test
@UiThreadTest
fun testSetMinPitch() {
val expected = 60.0
nativeMapView.minPitch = expected
val actual = nativeMapView.minPitch
assertEquals("Min Pitch should match", expected, actual, 0.01)
}
@Test
@UiThreadTest
fun testSetMaxPitch() {
val expected = 60.0
nativeMapView.maxPitch = expected
val actual = nativeMapView.maxPitch
assertEquals("Max Pitch should match", expected, actual, 0.01)
}
@Test
@UiThreadTest
fun testSetMaxPitch() {
val expected = 60.0
nativeMapView.maxPitch = expected
val actual = nativeMapView.maxPitch
assertEquals("Max Pitch should match", expected, actual, 0.01)
}
@Test
@UiThreadTest
@@ -307,12 +307,12 @@ class NativeMapViewTest : AppCenter() {
@UiThreadTest
fun testFlyTo() {
val expected = CameraPosition.Builder()
.zoom(12.0)
.tilt(30.0)
.target(LatLng(12.0, 14.0))
.bearing(20.0)
.padding(PADDING_TEST)
.build()
.zoom(12.0)
.tilt(30.0)
.target(LatLng(12.0, 14.0))
.bearing(20.0)
.padding(PADDING_TEST)
.build()
// verify that the lazily set padding is ignored when a value is provided with the camera
nativeMapView.contentPadding = doubleArrayOf(1.0, 2.0, 3.0, 4.0)
nativeMapView.flyTo(expected.target, expected.zoom, expected.bearing, expected.tilt, PADDING_TEST, 0)
@@ -329,12 +329,12 @@ class NativeMapViewTest : AppCenter() {
@UiThreadTest
fun testEaseTo() {
val expected = CameraPosition.Builder()
.zoom(12.0)
.tilt(30.0)
.target(LatLng(12.0, 14.0))
.bearing(20.0)
.padding(PADDING_TEST)
.build()
.zoom(12.0)
.tilt(30.0)
.target(LatLng(12.0, 14.0))
.bearing(20.0)
.padding(PADDING_TEST)
.build()
// verify that the lazily set padding is ignored when a value is provided with the camera
nativeMapView.contentPadding = doubleArrayOf(1.0, 2.0, 3.0, 4.0)
nativeMapView.easeTo(expected.target, expected.zoom, expected.bearing, expected.tilt, PADDING_TEST, 0, false)
@@ -351,12 +351,12 @@ class NativeMapViewTest : AppCenter() {
@UiThreadTest
fun testResetPosition() {
val expected = CameraPosition.Builder()
.zoom(0.0)
.tilt(0.0)
.target(LatLng(0.0, 0.0))
.bearing(0.0)
.padding(PADDING_TEST)
.build()
.zoom(0.0)
.tilt(0.0)
.target(LatLng(0.0, 0.0))
.bearing(0.0)
.padding(PADDING_TEST)
.build()
nativeMapView.jumpTo(LatLng(1.0, 2.0), 12.0, 23.0, 1.0, PADDING_TEST)
nativeMapView.resetPosition()
val actual = nativeMapView.cameraPosition
@@ -372,16 +372,16 @@ class NativeMapViewTest : AppCenter() {
@UiThreadTest
fun testGetCameraForLatLngBounds() {
val expected = CameraPosition.Builder()
.zoom(3.5258764777024005)
.tilt(0.0)
.target(LatLng(23.182767623652808, 13.999999999994088))
.bearing(0.0)
.build()
.zoom(3.5258764777024005)
.tilt(0.0)
.target(LatLng(23.182767623652808, 13.999999999994088))
.bearing(0.0)
.build()
val actual = nativeMapView.getCameraForLatLngBounds(
LatLngBounds.from(30.0, 16.0, 16.0, 12.0),
intArrayOf(0, 0, 0, 0),
0.0,
0.0
LatLngBounds.from(30.0, 16.0, 16.0, 12.0),
intArrayOf(0, 0, 0, 0),
0.0,
0.0
)
assertEquals("Bearing should match", expected.bearing, actual.bearing, TestConstants.BEARING_DELTA)
assertEquals("Latitude should match", expected.target.latitude, actual.target.latitude, TestConstants.LAT_LNG_DELTA)
@@ -394,11 +394,11 @@ class NativeMapViewTest : AppCenter() {
@UiThreadTest
fun testMoveBy() {
val expected = CameraPosition.Builder()
.zoom(0.0)
.tilt(0.0)
.target(LatLng(4.21494310024160, -4.218749958739409))
.bearing(0.0)
.build()
.zoom(0.0)
.tilt(0.0)
.target(LatLng(4.21494310024160, -4.218749958739409))
.bearing(0.0)
.build()
nativeMapView.moveBy(12.0, 12.0, 0)
val actual = nativeMapView.cameraPosition
assertEquals("Bearing should match", expected.bearing, actual.bearing, TestConstants.BEARING_DELTA)
@@ -436,4 +436,4 @@ class NativeMapViewTest : AppCenter() {
// no-op
}
}
}
}

View File

@@ -30,4 +30,4 @@ class TransformTest : EspressoTest() {
assertEquals("Camera position should match", expectedCameraPosition, actualCameraPosition)
}
}
}
}

View File

@@ -14,505 +14,507 @@ import org.junit.Test
class VisibleRegionTest : BaseTest() {
override fun getActivityClass(): Class<*> {
return PixelTestActivity::class.java
}
override
fun beforeTest() {
super.beforeTest()
mapView = (rule.activity as PixelTestActivity).mapView
}
@Test
fun visibleRegionTest() {
validateTestSetup()
invoke(mapboxMap) { _: UiController, mapboxMap: MapboxMap ->
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(LatLng(0.0, 0.0), 8.0))
val latLngs = listOf(
mapboxMap.getLatLngFromScreenCoords(0f, 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), mapView.height / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(0f, mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(0f, mapView.height / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height / 2f)
)
val visibleRegion = mapboxMap.projection.visibleRegion
assertTrue(latLngs.all { visibleRegion.latLngBounds.contains(it) })
override fun getActivityClass(): Class<*> {
return PixelTestActivity::class.java
}
}
@Test
fun paddedVisibleRegionTest() {
validateTestSetup()
invoke(mapboxMap) { _: UiController, mapboxMap: MapboxMap ->
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(LatLng(0.0, 0.0), 8.0))
val latLngs = listOf(
mapboxMap.getLatLngFromScreenCoords(0f, 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), mapView.height / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(0f, mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(0f, mapView.height / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height / 2f)
)
mapboxMap.setPadding(
mapView.width / 4,
mapView.height / 4,
mapView.width / 4,
mapView.height / 4)
val visibleRegion = mapboxMap.projection.getVisibleRegion(false)
val filtered = latLngs.filter { visibleRegion.latLngBounds.contains(it) }
assertTrue(filtered.size == 1)
assertTrue(filtered.contains(mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height / 2f)))
override
fun beforeTest() {
super.beforeTest()
mapView = (rule.activity as PixelTestActivity).mapView
}
}
@Test
fun paddedLeftVisibleRegionTest() {
validateTestSetup()
invoke(mapboxMap) { _: UiController, mapboxMap: MapboxMap ->
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(LatLng(0.0, 0.0), 8.0))
val latLngs = listOf(
mapboxMap.getLatLngFromScreenCoords(0f, 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), mapView.height / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(0f, mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(0f, mapView.height / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height / 2f)
)
mapboxMap.setPadding(mapView.width / 4, 0, 0, 0)
val visibleRegion = mapboxMap.projection.getVisibleRegion(false)
val filtered = latLngs.filter { visibleRegion.latLngBounds.contains(it) }
assertTrue(filtered.size == 6)
assertFalse(filtered.contains(mapboxMap.getLatLngFromScreenCoords(0f, mapView.height / 2f)))
@Test
fun visibleRegionTest() {
validateTestSetup()
invoke(mapboxMap) { _: UiController, mapboxMap: MapboxMap ->
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(LatLng(0.0, 0.0), 8.0))
val latLngs = listOf(
mapboxMap.getLatLngFromScreenCoords(0f, 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), mapView.height / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(0f, mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(0f, mapView.height / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height / 2f)
)
val visibleRegion = mapboxMap.projection.visibleRegion
assertTrue(latLngs.all { visibleRegion.latLngBounds.contains(it) })
}
}
}
@Test
fun paddedTopVisibleRegionTest() {
validateTestSetup()
invoke(mapboxMap) { _: UiController, mapboxMap: MapboxMap ->
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(LatLng(0.0, 0.0), 8.0))
val latLngs = listOf(
mapboxMap.getLatLngFromScreenCoords(0f, 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), mapView.height / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(0f, mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(0f, mapView.height / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height / 2f)
)
@Test
fun paddedVisibleRegionTest() {
validateTestSetup()
invoke(mapboxMap) { _: UiController, mapboxMap: MapboxMap ->
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(LatLng(0.0, 0.0), 8.0))
val latLngs = listOf(
mapboxMap.getLatLngFromScreenCoords(0f, 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), mapView.height / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(0f, mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(0f, mapView.height / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height / 2f)
)
mapboxMap.setPadding(0, mapView.height / 4, 0, 0)
mapboxMap.setPadding(
mapView.width / 4,
mapView.height / 4,
mapView.width / 4,
mapView.height / 4
)
val visibleRegion = mapboxMap.projection.getVisibleRegion(false)
val filtered = latLngs.filter { visibleRegion.latLngBounds.contains(it) }
assertTrue(filtered.size == 6)
assertFalse(filtered.contains(mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, 0f)))
val visibleRegion = mapboxMap.projection.getVisibleRegion(false)
val filtered = latLngs.filter { visibleRegion.latLngBounds.contains(it) }
assertTrue(filtered.size == 1)
assertTrue(filtered.contains(mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height / 2f)))
}
}
}
@Test
fun paddedRightVisibleRegionTest() {
validateTestSetup()
invoke(mapboxMap) { _: UiController, mapboxMap: MapboxMap ->
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(LatLng(0.0, 0.0), 8.0))
val latLngs = listOf(
mapboxMap.getLatLngFromScreenCoords(0f, 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), mapView.height / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(0f, mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(0f, mapView.height / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height / 2f)
)
@Test
fun paddedLeftVisibleRegionTest() {
validateTestSetup()
invoke(mapboxMap) { _: UiController, mapboxMap: MapboxMap ->
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(LatLng(0.0, 0.0), 8.0))
val latLngs = listOf(
mapboxMap.getLatLngFromScreenCoords(0f, 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), mapView.height / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(0f, mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(0f, mapView.height / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height / 2f)
)
mapboxMap.setPadding(0, 0, mapView.width / 4, 0)
mapboxMap.setPadding(mapView.width / 4, 0, 0, 0)
val visibleRegion = mapboxMap.projection.getVisibleRegion(false)
val filtered = latLngs.filter { visibleRegion.latLngBounds.contains(it) }
assertTrue(filtered.size == 6)
assertFalse(filtered.contains(mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), mapView.height / 2f)))
val visibleRegion = mapboxMap.projection.getVisibleRegion(false)
val filtered = latLngs.filter { visibleRegion.latLngBounds.contains(it) }
assertTrue(filtered.size == 6)
assertFalse(filtered.contains(mapboxMap.getLatLngFromScreenCoords(0f, mapView.height / 2f)))
}
}
}
@Test
fun paddedBottomVisibleRegionTest() {
validateTestSetup()
invoke(mapboxMap) { _: UiController, mapboxMap: MapboxMap ->
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(LatLng(0.0, 0.0), 8.0))
val latLngs = listOf(
mapboxMap.getLatLngFromScreenCoords(0f, 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), mapView.height / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(0f, mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(0f, mapView.height / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height / 2f)
)
@Test
fun paddedTopVisibleRegionTest() {
validateTestSetup()
invoke(mapboxMap) { _: UiController, mapboxMap: MapboxMap ->
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(LatLng(0.0, 0.0), 8.0))
val latLngs = listOf(
mapboxMap.getLatLngFromScreenCoords(0f, 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), mapView.height / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(0f, mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(0f, mapView.height / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height / 2f)
)
mapboxMap.setPadding(0, 0, 0, mapView.height / 4)
mapboxMap.setPadding(0, mapView.height / 4, 0, 0)
val visibleRegion = mapboxMap.projection.getVisibleRegion(false)
val filtered = latLngs.filter { visibleRegion.latLngBounds.contains(it) }
assertTrue(filtered.size == 6)
assertFalse(filtered.contains(mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height.toFloat())))
val visibleRegion = mapboxMap.projection.getVisibleRegion(false)
val filtered = latLngs.filter { visibleRegion.latLngBounds.contains(it) }
assertTrue(filtered.size == 6)
assertFalse(filtered.contains(mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, 0f)))
}
}
}
@Test
fun visibleRegionOverDatelineTest() {
validateTestSetup()
invoke(mapboxMap) { _: UiController, mapboxMap: MapboxMap ->
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(LatLng(0.0, 180.0), 8.0))
val latLngs = listOf(
mapboxMap.getLatLngFromScreenCoords(0f, 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), 0f)
.also { it.longitude += 360 },
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), mapView.height / 2f)
.also { it.longitude += 360 },
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), mapView.height.toFloat())
.also { it.longitude += 360 },
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(0f, mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(0f, mapView.height / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height / 2f)
)
val visibleRegion = mapboxMap.projection.visibleRegion
assertTrue(latLngs.all { visibleRegion.latLngBounds.contains(it) })
@Test
fun paddedRightVisibleRegionTest() {
validateTestSetup()
invoke(mapboxMap) { _: UiController, mapboxMap: MapboxMap ->
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(LatLng(0.0, 0.0), 8.0))
val latLngs = listOf(
mapboxMap.getLatLngFromScreenCoords(0f, 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), mapView.height / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(0f, mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(0f, mapView.height / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height / 2f)
)
mapboxMap.setPadding(0, 0, mapView.width / 4, 0)
val visibleRegion = mapboxMap.projection.getVisibleRegion(false)
val filtered = latLngs.filter { visibleRegion.latLngBounds.contains(it) }
assertTrue(filtered.size == 6)
assertFalse(filtered.contains(mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), mapView.height / 2f)))
}
}
}
@Test
fun paddedVisibleRegionOverDatelineTest() {
validateTestSetup()
invoke(mapboxMap) { _: UiController, mapboxMap: MapboxMap ->
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(LatLng(0.0, 180.0), 8.0))
val latLngs = listOf(
mapboxMap.getLatLngFromScreenCoords(0f, 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), mapView.height / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(0f, mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(0f, mapView.height / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height / 2f)
)
@Test
fun paddedBottomVisibleRegionTest() {
validateTestSetup()
invoke(mapboxMap) { _: UiController, mapboxMap: MapboxMap ->
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(LatLng(0.0, 0.0), 8.0))
val latLngs = listOf(
mapboxMap.getLatLngFromScreenCoords(0f, 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), mapView.height / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(0f, mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(0f, mapView.height / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height / 2f)
)
mapboxMap.setPadding(
mapView.width / 4,
mapView.height / 4,
mapView.width / 4,
mapView.height / 4)
mapboxMap.setPadding(0, 0, 0, mapView.height / 4)
val visibleRegion = mapboxMap.projection.getVisibleRegion(false)
val filtered = latLngs.filter { visibleRegion.latLngBounds.contains(it) }
assertTrue(filtered.size == 1)
assertTrue(filtered.contains(mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height / 2f)))
val visibleRegion = mapboxMap.projection.getVisibleRegion(false)
val filtered = latLngs.filter { visibleRegion.latLngBounds.contains(it) }
assertTrue(filtered.size == 6)
assertFalse(filtered.contains(mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height.toFloat())))
}
}
}
@Test
fun paddedLeftVisibleRegionOverDatelineTest() {
validateTestSetup()
invoke(mapboxMap) { _: UiController, mapboxMap: MapboxMap ->
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(LatLng(0.0, 180.0), 8.0))
val latLngs = listOf(
mapboxMap.getLatLngFromScreenCoords(0f, 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), 0f)
.also { it.longitude += 360 },
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), mapView.height / 2f)
.also { it.longitude += 360 },
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), mapView.height.toFloat())
.also { it.longitude += 360 },
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(0f, mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(0f, mapView.height / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height / 2f)
)
mapboxMap.setPadding(mapView.width / 4, 0, 0, 0)
val visibleRegion = mapboxMap.projection.getVisibleRegion(false)
val filtered = latLngs.filter { visibleRegion.latLngBounds.contains(it) }
assertTrue(filtered.size == 6)
assertFalse(filtered.contains(mapboxMap.getLatLngFromScreenCoords(0f, mapView.height / 2f)))
@Test
fun visibleRegionOverDatelineTest() {
validateTestSetup()
invoke(mapboxMap) { _: UiController, mapboxMap: MapboxMap ->
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(LatLng(0.0, 180.0), 8.0))
val latLngs = listOf(
mapboxMap.getLatLngFromScreenCoords(0f, 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), 0f)
.also { it.longitude += 360 },
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), mapView.height / 2f)
.also { it.longitude += 360 },
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), mapView.height.toFloat())
.also { it.longitude += 360 },
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(0f, mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(0f, mapView.height / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height / 2f)
)
val visibleRegion = mapboxMap.projection.visibleRegion
assertTrue(latLngs.all { visibleRegion.latLngBounds.contains(it) })
}
}
}
@Test
fun paddedTopVisibleRegionOverDatelineTest() {
validateTestSetup()
invoke(mapboxMap) { ui: UiController, mapboxMap: MapboxMap ->
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(LatLng(0.0, 180.0), 8.0))
ui.loopMainThreadForAtLeast(5000)
val latLngs = listOf(
mapboxMap.getLatLngFromScreenCoords(0f, 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), 0f)
.also { it.longitude += 360 },
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), mapView.height / 2f)
.also { it.longitude += 360 },
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), mapView.height.toFloat())
.also { it.longitude += 360 },
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(0f, mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(0f, mapView.height / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height / 2f)
)
@Test
fun paddedVisibleRegionOverDatelineTest() {
validateTestSetup()
invoke(mapboxMap) { _: UiController, mapboxMap: MapboxMap ->
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(LatLng(0.0, 180.0), 8.0))
val latLngs = listOf(
mapboxMap.getLatLngFromScreenCoords(0f, 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), mapView.height / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(0f, mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(0f, mapView.height / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height / 2f)
)
mapboxMap.setPadding(0, mapView.height / 4, 0, 0)
mapboxMap.setPadding(
mapView.width / 4,
mapView.height / 4,
mapView.width / 4,
mapView.height / 4
)
val visibleRegion = mapboxMap.projection.getVisibleRegion(false)
val filtered = latLngs.filter { visibleRegion.latLngBounds.contains(it) }
assertTrue(filtered.size == 6)
assertFalse(filtered.contains(mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, 0f)))
val visibleRegion = mapboxMap.projection.getVisibleRegion(false)
val filtered = latLngs.filter { visibleRegion.latLngBounds.contains(it) }
assertTrue(filtered.size == 1)
assertTrue(filtered.contains(mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height / 2f)))
}
}
}
@Test
fun paddedRightVisibleRegionOverDatelineTest() {
validateTestSetup()
invoke(mapboxMap) { _: UiController, mapboxMap: MapboxMap ->
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(LatLng(0.0, 180.0), 8.0))
val latLngs = listOf(
mapboxMap.getLatLngFromScreenCoords(0f, 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), 0f)
.also { it.longitude += 360 },
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), mapView.height / 2f)
.also { it.longitude += 360 },
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), mapView.height.toFloat())
.also { it.longitude += 360 },
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(0f, mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(0f, mapView.height / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height / 2f)
)
@Test
fun paddedLeftVisibleRegionOverDatelineTest() {
validateTestSetup()
invoke(mapboxMap) { _: UiController, mapboxMap: MapboxMap ->
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(LatLng(0.0, 180.0), 8.0))
val latLngs = listOf(
mapboxMap.getLatLngFromScreenCoords(0f, 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), 0f)
.also { it.longitude += 360 },
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), mapView.height / 2f)
.also { it.longitude += 360 },
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), mapView.height.toFloat())
.also { it.longitude += 360 },
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(0f, mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(0f, mapView.height / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height / 2f)
)
mapboxMap.setPadding(0, 0, mapView.width / 4, 0)
mapboxMap.setPadding(mapView.width / 4, 0, 0, 0)
val visibleRegion = mapboxMap.projection.getVisibleRegion(false)
val filtered = latLngs.filter { visibleRegion.latLngBounds.contains(it) }
assertTrue(filtered.size == 6)
assertFalse(filtered.contains(mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), mapView.height / 2f)))
val visibleRegion = mapboxMap.projection.getVisibleRegion(false)
val filtered = latLngs.filter { visibleRegion.latLngBounds.contains(it) }
assertTrue(filtered.size == 6)
assertFalse(filtered.contains(mapboxMap.getLatLngFromScreenCoords(0f, mapView.height / 2f)))
}
}
}
@Test
fun paddedBottomVisibleRegionOverDatelineTest() {
validateTestSetup()
invoke(mapboxMap) { _: UiController, mapboxMap: MapboxMap ->
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(LatLng(0.0, 180.0), 8.0))
val latLngs = listOf(
mapboxMap.getLatLngFromScreenCoords(0f, 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), 0f)
.also { it.longitude += 360 },
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), mapView.height / 2f)
.also { it.longitude += 360 },
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), mapView.height.toFloat())
.also { it.longitude += 360 },
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(0f, mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(0f, mapView.height / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height / 2f)
)
@Test
fun paddedTopVisibleRegionOverDatelineTest() {
validateTestSetup()
invoke(mapboxMap) { ui: UiController, mapboxMap: MapboxMap ->
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(LatLng(0.0, 180.0), 8.0))
ui.loopMainThreadForAtLeast(5000)
val latLngs = listOf(
mapboxMap.getLatLngFromScreenCoords(0f, 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), 0f)
.also { it.longitude += 360 },
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), mapView.height / 2f)
.also { it.longitude += 360 },
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), mapView.height.toFloat())
.also { it.longitude += 360 },
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(0f, mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(0f, mapView.height / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height / 2f)
)
mapboxMap.setPadding(0, 0, 0, mapView.height / 4)
mapboxMap.setPadding(0, mapView.height / 4, 0, 0)
val visibleRegion = mapboxMap.projection.getVisibleRegion(false)
val filtered = latLngs.filter { visibleRegion.latLngBounds.contains(it) }
assertTrue(filtered.size == 6)
assertFalse(filtered.contains(mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height.toFloat())))
val visibleRegion = mapboxMap.projection.getVisibleRegion(false)
val filtered = latLngs.filter { visibleRegion.latLngBounds.contains(it) }
assertTrue(filtered.size == 6)
assertFalse(filtered.contains(mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, 0f)))
}
}
}
@Test
fun visibleRotatedRegionTest() {
validateTestSetup()
invoke(mapboxMap) { _: UiController, mapboxMap: MapboxMap ->
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(LatLng(0.0, 0.0), 8.0))
val d = Math.min(mapboxMap.width, mapboxMap.height) / 4
val latLngs = listOf(
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f - d / 2f, mapView.height / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f + d / 2f, mapView.height / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height / 2f - d / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height / 2f + d / 2f)
)
@Test
fun paddedRightVisibleRegionOverDatelineTest() {
validateTestSetup()
invoke(mapboxMap) { _: UiController, mapboxMap: MapboxMap ->
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(LatLng(0.0, 180.0), 8.0))
val latLngs = listOf(
mapboxMap.getLatLngFromScreenCoords(0f, 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), 0f)
.also { it.longitude += 360 },
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), mapView.height / 2f)
.also { it.longitude += 360 },
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), mapView.height.toFloat())
.also { it.longitude += 360 },
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(0f, mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(0f, mapView.height / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height / 2f)
)
for (bearing in 45 until 360 step 45) {
mapboxMap.moveCamera(CameraUpdateFactory.bearingTo(bearing.toDouble()))
val visibleRegion = mapboxMap.projection.visibleRegion
assertTrue(latLngs.all { visibleRegion.latLngBounds.contains(it) })
}
mapboxMap.setPadding(0, 0, mapView.width / 4, 0)
val visibleRegion = mapboxMap.projection.getVisibleRegion(false)
val filtered = latLngs.filter { visibleRegion.latLngBounds.contains(it) }
assertTrue(filtered.size == 6)
assertFalse(filtered.contains(mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), mapView.height / 2f)))
}
}
}
@Test
fun visibleRotatedRegionOverDatelineTest() {
validateTestSetup()
invoke(mapboxMap) { _: UiController, mapboxMap: MapboxMap ->
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(LatLng(0.0, 180.0), 8.0))
val d = Math.min(mapboxMap.width, mapboxMap.height) / 4
val latLngs = listOf(
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f - d / 2f, mapView.height / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f + d / 2f, mapView.height / 2f)
.also { it.longitude += 360 },
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height / 2f - d / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height / 2f + d / 2f)
)
@Test
fun paddedBottomVisibleRegionOverDatelineTest() {
validateTestSetup()
invoke(mapboxMap) { _: UiController, mapboxMap: MapboxMap ->
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(LatLng(0.0, 180.0), 8.0))
val latLngs = listOf(
mapboxMap.getLatLngFromScreenCoords(0f, 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), 0f)
.also { it.longitude += 360 },
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), mapView.height / 2f)
.also { it.longitude += 360 },
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), mapView.height.toFloat())
.also { it.longitude += 360 },
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(0f, mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(0f, mapView.height / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height / 2f)
)
for (bearing in 45 until 360 step 45) {
mapboxMap.moveCamera(CameraUpdateFactory.bearingTo(bearing.toDouble()))
val visibleRegion = mapboxMap.projection.visibleRegion
assertTrue(latLngs.all { visibleRegion.latLngBounds.contains(it) })
}
mapboxMap.setPadding(0, 0, 0, mapView.height / 4)
val visibleRegion = mapboxMap.projection.getVisibleRegion(false)
val filtered = latLngs.filter { visibleRegion.latLngBounds.contains(it) }
assertTrue(filtered.size == 6)
assertFalse(filtered.contains(mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height.toFloat())))
}
}
}
@Test
fun visibleRegionWithBoundsEqualTest() {
validateTestSetup()
invoke(mapboxMap) { _: UiController, mapboxMap: MapboxMap ->
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(LatLng(0.0, 0.0), 8.0))
val latLngs = listOf(
mapboxMap.getLatLngFromScreenCoords(0f, 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), mapView.height / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(0f, mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(0f, mapView.height / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height / 2f)
)
val bounds = doubleArrayOf(0.0, 0.0, 0.0, 0.0)
mapboxMap.projection.getVisibleCoordinateBounds(bounds)
val latLngBounds = LatLngBounds.from(bounds[0], bounds[1], bounds[2], bounds[3])
val visibleRegion = mapboxMap.projection.visibleRegion
assertTrue(latLngBounds == visibleRegion.latLngBounds)
assertTrue(latLngs.all { latLngBounds.contains(it) })
@Test
fun visibleRotatedRegionTest() {
validateTestSetup()
invoke(mapboxMap) { _: UiController, mapboxMap: MapboxMap ->
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(LatLng(0.0, 0.0), 8.0))
val d = Math.min(mapboxMap.width, mapboxMap.height) / 4
val latLngs = listOf(
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f - d / 2f, mapView.height / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f + d / 2f, mapView.height / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height / 2f - d / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height / 2f + d / 2f)
)
for (bearing in 45 until 360 step 45) {
mapboxMap.moveCamera(CameraUpdateFactory.bearingTo(bearing.toDouble()))
val visibleRegion = mapboxMap.projection.visibleRegion
assertTrue(latLngs.all { visibleRegion.latLngBounds.contains(it) })
}
}
}
}
@Test
fun visibleRegionBoundsOverDatelineTest() {
validateTestSetup()
invoke(mapboxMap) { _: UiController, mapboxMap: MapboxMap ->
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(LatLng(0.0, 180.0), 8.0))
val latLngs = listOf(
mapboxMap.getLatLngFromScreenCoords(0f, 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), 0f)
.also { it.longitude += 360 },
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), mapView.height / 2f)
.also { it.longitude += 360 },
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), mapView.height.toFloat())
.also { it.longitude += 360 },
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(0f, mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(0f, mapView.height / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height / 2f)
)
val bounds = doubleArrayOf(0.0, 0.0, 0.0, 0.0)
mapboxMap.projection.getVisibleCoordinateBounds(bounds)
val latLngBounds = LatLngBounds.from(bounds[0], bounds[1], bounds[2], bounds[3])
assertTrue(latLngs.all { latLngBounds.contains(it) })
@Test
fun visibleRotatedRegionOverDatelineTest() {
validateTestSetup()
invoke(mapboxMap) { _: UiController, mapboxMap: MapboxMap ->
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(LatLng(0.0, 180.0), 8.0))
val d = Math.min(mapboxMap.width, mapboxMap.height) / 4
val latLngs = listOf(
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f - d / 2f, mapView.height / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f + d / 2f, mapView.height / 2f)
.also { it.longitude += 360 },
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height / 2f - d / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height / 2f + d / 2f)
)
for (bearing in 45 until 360 step 45) {
mapboxMap.moveCamera(CameraUpdateFactory.bearingTo(bearing.toDouble()))
val visibleRegion = mapboxMap.projection.visibleRegion
assertTrue(latLngs.all { visibleRegion.latLngBounds.contains(it) })
}
}
}
}
@Test
fun visibleRegionBoundsOverDatelineLatitudeZeroTest() {
validateTestSetup()
invoke(mapboxMap) { _: UiController, mapboxMap: MapboxMap ->
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(LatLng(0.0, 180.0), 8.0))
val shift = mapboxMap.getLatLngFromScreenCoords(0f, 0f)
mapboxMap.moveCamera(CameraUpdateFactory.newLatLng(LatLng(0.0, 180.0 - shift.longitude)))
val bounds = doubleArrayOf(0.0, 0.0, 0.0, 0.0)
mapboxMap.projection.getVisibleCoordinateBounds(bounds)
val latLngBounds = LatLngBounds.from(bounds[0], bounds[1], bounds[2], bounds[3])
val visibleRegion = mapboxMap.projection.visibleRegion
assertTrue(latLngBounds == visibleRegion.latLngBounds)
@Test
fun visibleRegionWithBoundsEqualTest() {
validateTestSetup()
invoke(mapboxMap) { _: UiController, mapboxMap: MapboxMap ->
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(LatLng(0.0, 0.0), 8.0))
val latLngs = listOf(
mapboxMap.getLatLngFromScreenCoords(0f, 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), mapView.height / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(0f, mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(0f, mapView.height / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height / 2f)
)
val bounds = doubleArrayOf(0.0, 0.0, 0.0, 0.0)
mapboxMap.projection.getVisibleCoordinateBounds(bounds)
val latLngBounds = LatLngBounds.from(bounds[0], bounds[1], bounds[2], bounds[3])
val visibleRegion = mapboxMap.projection.visibleRegion
assertTrue(latLngBounds == visibleRegion.latLngBounds)
assertTrue(latLngs.all { latLngBounds.contains(it) })
}
}
}
@Test
fun visibleRotatedRegionBoundEqualTest() {
validateTestSetup()
invoke(mapboxMap) { _: UiController, mapboxMap: MapboxMap ->
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(LatLng(0.0, 0.0), 8.0))
val d = Math.min(mapboxMap.width, mapboxMap.height) / 4
val latLngs = listOf(
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f - d / 2f, mapView.height / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f + d / 2f, mapView.height / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height / 2f - d / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height / 2f + d / 2f)
)
for (bearing in 45 until 360 step 45) {
mapboxMap.moveCamera(CameraUpdateFactory.bearingTo(bearing.toDouble()))
val bounds = doubleArrayOf(0.0, 0.0, 0.0, 0.0)
mapboxMap.projection.getVisibleCoordinateBounds(bounds)
val latLngBounds = LatLngBounds.from(bounds[0], bounds[1], bounds[2], bounds[3])
val visibleRegion = mapboxMap.projection.visibleRegion
assertTrue(latLngBounds == visibleRegion.latLngBounds)
assertTrue(latLngs.all { latLngBounds.contains(it) })
}
@Test
fun visibleRegionBoundsOverDatelineTest() {
validateTestSetup()
invoke(mapboxMap) { _: UiController, mapboxMap: MapboxMap ->
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(LatLng(0.0, 180.0), 8.0))
val latLngs = listOf(
mapboxMap.getLatLngFromScreenCoords(0f, 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, 0f),
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), 0f)
.also { it.longitude += 360 },
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), mapView.height / 2f)
.also { it.longitude += 360 },
mapboxMap.getLatLngFromScreenCoords(mapView.width.toFloat(), mapView.height.toFloat())
.also { it.longitude += 360 },
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(0f, mapView.height.toFloat()),
mapboxMap.getLatLngFromScreenCoords(0f, mapView.height / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height / 2f)
)
val bounds = doubleArrayOf(0.0, 0.0, 0.0, 0.0)
mapboxMap.projection.getVisibleCoordinateBounds(bounds)
val latLngBounds = LatLngBounds.from(bounds[0], bounds[1], bounds[2], bounds[3])
assertTrue(latLngs.all { latLngBounds.contains(it) })
}
}
}
@Test
fun visibleRotatedRegionBoundsOverDatelineTest() {
validateTestSetup()
invoke(mapboxMap) { _: UiController, mapboxMap: MapboxMap ->
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(LatLng(0.0, 179.0), 8.0))
val d = Math.min(mapboxMap.width, mapboxMap.height) / 4
val latLngs = listOf(
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f - d / 2f, mapView.height / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f + d / 2f, mapView.height / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height / 2f - d / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height / 2f + d / 2f)
)
@Test
fun visibleRegionBoundsOverDatelineLatitudeZeroTest() {
validateTestSetup()
invoke(mapboxMap) { _: UiController, mapboxMap: MapboxMap ->
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(LatLng(0.0, 180.0), 8.0))
val shift = mapboxMap.getLatLngFromScreenCoords(0f, 0f)
mapboxMap.moveCamera(CameraUpdateFactory.newLatLng(LatLng(0.0, 180.0 - shift.longitude)))
for (bearing in 45 until 360 step 45) {
mapboxMap.moveCamera(CameraUpdateFactory.bearingTo(bearing.toDouble()))
val bounds = doubleArrayOf(0.0, 0.0, 0.0, 0.0)
mapboxMap.projection.getVisibleCoordinateBounds(bounds)
val latLngBounds = LatLngBounds.from(bounds[0], bounds[1], bounds[2], bounds[3])
assertTrue(latLngs.all { latLngBounds.contains(it) })
}
val bounds = doubleArrayOf(0.0, 0.0, 0.0, 0.0)
mapboxMap.projection.getVisibleCoordinateBounds(bounds)
val latLngBounds = LatLngBounds.from(bounds[0], bounds[1], bounds[2], bounds[3])
val visibleRegion = mapboxMap.projection.visibleRegion
assertTrue(latLngBounds == visibleRegion.latLngBounds)
}
}
}
private fun MapboxMap.getLatLngFromScreenCoords(x: Float, y: Float): LatLng {
return this.projection.fromScreenLocation(PointF(x, y))
}
}
@Test
fun visibleRotatedRegionBoundEqualTest() {
validateTestSetup()
invoke(mapboxMap) { _: UiController, mapboxMap: MapboxMap ->
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(LatLng(0.0, 0.0), 8.0))
val d = Math.min(mapboxMap.width, mapboxMap.height) / 4
val latLngs = listOf(
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f - d / 2f, mapView.height / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f + d / 2f, mapView.height / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height / 2f - d / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height / 2f + d / 2f)
)
for (bearing in 45 until 360 step 45) {
mapboxMap.moveCamera(CameraUpdateFactory.bearingTo(bearing.toDouble()))
val bounds = doubleArrayOf(0.0, 0.0, 0.0, 0.0)
mapboxMap.projection.getVisibleCoordinateBounds(bounds)
val latLngBounds = LatLngBounds.from(bounds[0], bounds[1], bounds[2], bounds[3])
val visibleRegion = mapboxMap.projection.visibleRegion
assertTrue(latLngBounds == visibleRegion.latLngBounds)
assertTrue(latLngs.all { latLngBounds.contains(it) })
}
}
}
@Test
fun visibleRotatedRegionBoundsOverDatelineTest() {
validateTestSetup()
invoke(mapboxMap) { _: UiController, mapboxMap: MapboxMap ->
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(LatLng(0.0, 179.0), 8.0))
val d = Math.min(mapboxMap.width, mapboxMap.height) / 4
val latLngs = listOf(
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f - d / 2f, mapView.height / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f + d / 2f, mapView.height / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height / 2f - d / 2f),
mapboxMap.getLatLngFromScreenCoords(mapView.width / 2f, mapView.height / 2f + d / 2f)
)
for (bearing in 45 until 360 step 45) {
mapboxMap.moveCamera(CameraUpdateFactory.bearingTo(bearing.toDouble()))
val bounds = doubleArrayOf(0.0, 0.0, 0.0, 0.0)
mapboxMap.projection.getVisibleCoordinateBounds(bounds)
val latLngBounds = LatLngBounds.from(bounds[0], bounds[1], bounds[2], bounds[3])
assertTrue(latLngs.all { latLngBounds.contains(it) })
}
}
}
private fun MapboxMap.getLatLngFromScreenCoords(x: Float, y: Float): LatLng {
return this.projection.fromScreenLocation(PointF(x, y))
}
}

View File

@@ -6,12 +6,12 @@ import com.mapbox.geojson.Point
import com.mapbox.mapboxsdk.log.Logger
import com.mapbox.mapboxsdk.maps.Style
import com.mapbox.mapboxsdk.testapp.activity.FeatureOverviewActivity
import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit
import java.util.concurrent.TimeoutException
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit
import java.util.concurrent.TimeoutException
/**
* Integration test that validates downloading an offline region from a point geometry at zoomlevel 17
@@ -19,67 +19,68 @@ import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class OfflineDownloadTest : OfflineRegion.OfflineRegionObserver {
@Rule
@JvmField
var rule = ActivityTestRule(FeatureOverviewActivity::class.java)
@Rule
@JvmField
var rule = ActivityTestRule(FeatureOverviewActivity::class.java)
private val countDownLatch = CountDownLatch(1)
private lateinit var offlineRegion: OfflineRegion
private val countDownLatch = CountDownLatch(1)
private lateinit var offlineRegion: OfflineRegion
@Test(timeout = 60000)
fun offlineDownload() {
rule.runOnUiThreadActivity {
OfflineManager.getInstance(rule.activity).createOfflineRegion(
createTestRegionDefinition(),
ByteArray(0),
object : OfflineManager.CreateOfflineRegionCallback {
override fun onCreate(region: OfflineRegion) {
offlineRegion = region
offlineRegion.setDownloadState(OfflineRegion.STATE_ACTIVE)
offlineRegion.setObserver(this@OfflineDownloadTest)
}
@Test(timeout = 60000)
fun offlineDownload() {
rule.runOnUiThreadActivity {
OfflineManager.getInstance(rule.activity).createOfflineRegion(
createTestRegionDefinition(),
ByteArray(0),
object : OfflineManager.CreateOfflineRegionCallback {
override fun onCreate(region: OfflineRegion) {
offlineRegion = region
offlineRegion.setDownloadState(OfflineRegion.STATE_ACTIVE)
offlineRegion.setObserver(this@OfflineDownloadTest)
}
override fun onError(error: String) {
Logger.e(TAG, "Error while creating offline region: $error")
}
})
override fun onError(error: String) {
Logger.e(TAG, "Error while creating offline region: $error")
}
}
)
}
if (!countDownLatch.await(60, TimeUnit.SECONDS)) {
throw TimeoutException()
}
}
if (!countDownLatch.await(60, TimeUnit.SECONDS)) {
throw TimeoutException()
override fun onStatusChanged(status: OfflineRegionStatus) {
Logger.i(TAG, "Download percentage ${100.0 * status.completedResourceCount / status.requiredResourceCount}")
if (status.isComplete) {
offlineRegion.setDownloadState(OfflineRegion.STATE_INACTIVE)
countDownLatch.countDown()
}
}
}
override fun onStatusChanged(status: OfflineRegionStatus) {
Logger.i(TAG, "Download percentage ${100.0 * status.completedResourceCount / status.requiredResourceCount}")
if (status.isComplete) {
offlineRegion.setDownloadState(OfflineRegion.STATE_INACTIVE)
countDownLatch.countDown()
override fun onError(error: OfflineRegionError) {
Logger.e(TAG, "Error while downloading offline region: $error")
}
}
override fun onError(error: OfflineRegionError) {
Logger.e(TAG, "Error while downloading offline region: $error")
}
override fun mapboxTileCountLimitExceeded(limit: Long) {
Logger.e(TAG, "Tile count limited exceeded: $limit")
}
override fun mapboxTileCountLimitExceeded(limit: Long) {
Logger.e(TAG, "Tile count limited exceeded: $limit")
}
private fun createTestRegionDefinition(): OfflineRegionDefinition {
return OfflineGeometryRegionDefinition(
Style.MAPBOX_STREETS,
Point.fromLngLat(50.847857, 4.360137),
17.0,
17.0,
1.0f,
false
)
}
private fun createTestRegionDefinition(): OfflineRegionDefinition {
return OfflineGeometryRegionDefinition(
Style.MAPBOX_STREETS,
Point.fromLngLat(50.847857, 4.360137),
17.0,
17.0,
1.0f,
false
)
}
companion object {
const val TAG = "OfflineDownloadTest"
}
companion object {
const val TAG = "OfflineDownloadTest"
}
}
fun ActivityTestRule<*>.runOnUiThreadActivity(runnable: () -> Unit) = activity.runOnUiThread(runnable)
fun ActivityTestRule<*>.runOnUiThreadActivity(runnable: () -> Unit) = activity.runOnUiThread(runnable)

View File

@@ -8,14 +8,14 @@ import com.mapbox.mapboxsdk.maps.Style
import com.mapbox.mapboxsdk.style.layers.BackgroundLayer
import com.mapbox.mapboxsdk.style.layers.PropertyFactory
import com.mapbox.mapboxsdk.testapp.activity.FeatureOverviewActivity
import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit
import java.util.concurrent.TimeoutException
import junit.framework.Assert.assertNotNull
import org.junit.Assert
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit
import java.util.concurrent.TimeoutException
/**
* Integration test that validates if a snapshotter creation
@@ -23,39 +23,44 @@ import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class MapSnapshotterTest {
@Rule
@JvmField
var rule = ActivityTestRule(FeatureOverviewActivity::class.java)
@Rule
@JvmField
var rule = ActivityTestRule(FeatureOverviewActivity::class.java)
private val countDownLatch = CountDownLatch(1)
private val countDownLatch = CountDownLatch(1)
@Test
fun mapSnapshotter() {
var mapSnapshotter: MapSnapshotter?
rule.activity.runOnUiThread {
val bg = BackgroundLayer("rand_tint")
bg.setProperties(PropertyFactory.backgroundColor("rgba(255,128,0,0.7)"))
val options = MapSnapshotter.Options(512, 512)
.withPixelRatio(1.0f)
.withStyleBuilder(Style.Builder().fromUri(Style.SATELLITE_STREETS)
.withLayerAbove(bg, "country-label"))
.withCameraPosition(
CameraPosition.Builder()
.zoom(12.0)
.target(LatLng(51.145495, 5.742234))
.build()
)
mapSnapshotter = MapSnapshotter(rule.activity, options)
mapSnapshotter!!.start({
assertNotNull(it)
assertNotNull(it.bitmap)
countDownLatch.countDown()
}, {
Assert.fail(it)
})
@Test
fun mapSnapshotter() {
var mapSnapshotter: MapSnapshotter?
rule.activity.runOnUiThread {
val bg = BackgroundLayer("rand_tint")
bg.setProperties(PropertyFactory.backgroundColor("rgba(255,128,0,0.7)"))
val options = MapSnapshotter.Options(512, 512)
.withPixelRatio(1.0f)
.withStyleBuilder(
Style.Builder().fromUri(Style.SATELLITE_STREETS)
.withLayerAbove(bg, "country-label")
)
.withCameraPosition(
CameraPosition.Builder()
.zoom(12.0)
.target(LatLng(51.145495, 5.742234))
.build()
)
mapSnapshotter = MapSnapshotter(rule.activity, options)
mapSnapshotter!!.start(
{
assertNotNull(it)
assertNotNull(it.bitmap)
countDownLatch.countDown()
},
{
Assert.fail(it)
}
)
}
if (!countDownLatch.await(30, TimeUnit.SECONDS)) {
throw TimeoutException()
}
}
if (!countDownLatch.await(30, TimeUnit.SECONDS)) {
throw TimeoutException()
}
}
}
}

View File

@@ -32,4 +32,4 @@ class MapDialogFragmentTest : AppCenter() {
Thread.sleep(2500)
Espresso.pressBack()
}
}
}

View File

@@ -7,66 +7,67 @@ import com.mapbox.mapboxsdk.maps.MapView
import com.mapbox.mapboxsdk.maps.Style
import com.mapbox.mapboxsdk.testapp.R
import com.mapbox.mapboxsdk.testapp.activity.espresso.EspressoTestActivity
import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit
import java.util.concurrent.TimeoutException
import junit.framework.Assert.assertEquals
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit
import java.util.concurrent.TimeoutException
@RunWith(AndroidJUnit4::class)
class ImageMissingTest : AppCenter() {
@Rule
@JvmField
var rule = ActivityTestRule(EspressoTestActivity::class.java)
@Rule
@JvmField
var rule = ActivityTestRule(EspressoTestActivity::class.java)
private lateinit var mapView: MapView
private lateinit var latch: CountDownLatch
private lateinit var mapView: MapView
private lateinit var latch: CountDownLatch
@Before
fun setup() {
latch = CountDownLatch(1)
}
@Test
fun testMissingImage() {
rule.runOnUiThread {
initMap(styleJson).addOnStyleImageMissingListener {
assertEquals("missing-icon", it)
latch.countDown()
}
@Before
fun setup() {
latch = CountDownLatch(1)
}
if (!latch.await(10, TimeUnit.SECONDS)) {
throw TimeoutException()
}
}
@Test
fun testMissingImage() {
rule.runOnUiThread {
initMap(styleJson).addOnStyleImageMissingListener {
assertEquals("missing-icon", it)
latch.countDown()
}
}
@Test
fun testMissingImage_invalidSprite() {
rule.runOnUiThread {
initMap(styleJsonInvalidSprite).addOnStyleImageMissingListener {
assertEquals("missing-icon", it)
latch.countDown()
}
if (!latch.await(10, TimeUnit.SECONDS)) {
throw TimeoutException()
}
}
if (!latch.await(10, TimeUnit.SECONDS)) {
throw TimeoutException()
@Test
fun testMissingImage_invalidSprite() {
rule.runOnUiThread {
initMap(styleJsonInvalidSprite).addOnStyleImageMissingListener {
assertEquals("missing-icon", it)
latch.countDown()
}
}
if (!latch.await(10, TimeUnit.SECONDS)) {
throw TimeoutException()
}
}
}
private fun initMap(style: String): MapView {
mapView = rule.activity.findViewById(R.id.mapView)
mapView.getMapAsync { it.setStyle(Style.Builder().fromJson(style)) }
return mapView
}
private fun initMap(style: String): MapView {
mapView = rule.activity.findViewById(R.id.mapView)
mapView.getMapAsync { it.setStyle(Style.Builder().fromJson(style)) }
return mapView
}
companion object {
private const val styleJson = """
companion object {
private const val styleJson =
"""
{
"version": 8,
"name": "Mapbox Streets",
@@ -109,7 +110,8 @@ class ImageMissingTest : AppCenter() {
}
"""
private const val styleJsonInvalidSprite = """
private const val styleJsonInvalidSprite =
"""
{
"version": 8,
"name": "Mapbox Streets",
@@ -151,5 +153,5 @@ class ImageMissingTest : AppCenter() {
}]
}
"""
}
}
}
}

View File

@@ -11,99 +11,100 @@ import com.mapbox.mapboxsdk.maps.MapboxMap
import com.mapbox.mapboxsdk.maps.Style
import com.mapbox.mapboxsdk.testapp.R
import com.mapbox.mapboxsdk.testapp.activity.espresso.EspressoTestActivity
import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit
import java.util.concurrent.TimeoutException
import org.junit.Assert.*
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit
import java.util.concurrent.TimeoutException
@RunWith(AndroidJUnit4::class)
class RemoveUnusedImagesTest : AppCenter() {
@Rule
@JvmField
var rule = ActivityTestRule(EspressoTestActivity::class.java)
@Rule
@JvmField
var rule = ActivityTestRule(EspressoTestActivity::class.java)
private lateinit var mapView: MapView
private lateinit var mapboxMap: MapboxMap
private val latch = CountDownLatch(1)
private lateinit var mapView: MapView
private lateinit var mapboxMap: MapboxMap
private val latch = CountDownLatch(1)
@Before
fun setup() {
rule.runOnUiThread {
mapView = rule.activity.findViewById(R.id.mapView)
mapView.getMapAsync {
mapboxMap = it
mapboxMap.setStyle(Style.Builder().fromJson(styleJson))
}
}
}
@Test
fun testRemoveUnusedImagesUserProvidedListener() {
var callbackLatch = CountDownLatch(2)
rule.runOnUiThread {
mapView.addOnStyleImageMissingListener {
mapboxMap.style!!.addImage(it, Bitmap.createBitmap(512, 512, Bitmap.Config.ARGB_8888))
}
// Remove layer and source, so that rendered tiles are no longer used, therefore, map must
// notify client about unused images.
mapView.addOnDidBecomeIdleListener {
mapboxMap.style!!.removeLayer("icon")
mapboxMap.style!!.removeSource("geojson")
}
mapView.addOnCanRemoveUnusedStyleImageListener {
callbackLatch.countDown()
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(LatLng(0.0, 120.0), 8.0))
mapView.addOnDidFinishRenderingFrameListener {
assertNotNull(mapboxMap.style!!.getImage("small"))
assertNotNull(mapboxMap.style!!.getImage("large"))
latch.countDown()
@Before
fun setup() {
rule.runOnUiThread {
mapView = rule.activity.findViewById(R.id.mapView)
mapView.getMapAsync {
mapboxMap = it
mapboxMap.setStyle(Style.Builder().fromJson(styleJson))
}
}
return@addOnCanRemoveUnusedStyleImageListener false
}
}
if (!latch.await(5, TimeUnit.SECONDS) && !callbackLatch.await(5, TimeUnit.SECONDS)) {
throw TimeoutException()
}
}
@Test
fun testRemoveUnusedImagesUserProvidedListener() {
var callbackLatch = CountDownLatch(2)
rule.runOnUiThread {
mapView.addOnStyleImageMissingListener {
mapboxMap.style!!.addImage(it, Bitmap.createBitmap(512, 512, Bitmap.Config.ARGB_8888))
}
@Test
fun testRemoveUnusedImagesDefaultListener() {
rule.runOnUiThread {
mapView.addOnStyleImageMissingListener {
mapboxMap.style!!.addImage(it, Bitmap.createBitmap(512, 512, Bitmap.Config.ARGB_8888))
}
// Remove layer and source, so that rendered tiles are no longer used, therefore, map must
// notify client about unused images.
mapView.addOnDidBecomeIdleListener {
mapboxMap.style!!.removeLayer("icon")
mapboxMap.style!!.removeSource("geojson")
}
// Remove layer and source, so that rendered tiles are no longer used, thus
// map must request removal of unused images.
mapView.addOnDidBecomeIdleListener {
mapboxMap.style!!.removeLayer("icon")
mapboxMap.style!!.removeSource("geojson")
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(LatLng(0.0, 120.0), 8.0))
// Wait for the next frame and check that images were removed from the style.
mapView.addOnDidFinishRenderingFrameListener {
if (mapboxMap.style!!.getImage("small") == null && mapboxMap.style!!.getImage("large") == null) {
latch.countDown()
}
mapView.addOnCanRemoveUnusedStyleImageListener {
callbackLatch.countDown()
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(LatLng(0.0, 120.0), 8.0))
mapView.addOnDidFinishRenderingFrameListener {
assertNotNull(mapboxMap.style!!.getImage("small"))
assertNotNull(mapboxMap.style!!.getImage("large"))
latch.countDown()
}
return@addOnCanRemoveUnusedStyleImageListener false
}
}
if (!latch.await(5, TimeUnit.SECONDS) && !callbackLatch.await(5, TimeUnit.SECONDS)) {
throw TimeoutException()
}
}
}
if (!latch.await(5, TimeUnit.SECONDS)) {
throw TimeoutException()
}
}
@Test
fun testRemoveUnusedImagesDefaultListener() {
rule.runOnUiThread {
mapView.addOnStyleImageMissingListener {
mapboxMap.style!!.addImage(it, Bitmap.createBitmap(512, 512, Bitmap.Config.ARGB_8888))
}
companion object {
private const val styleJson = """
// Remove layer and source, so that rendered tiles are no longer used, thus
// map must request removal of unused images.
mapView.addOnDidBecomeIdleListener {
mapboxMap.style!!.removeLayer("icon")
mapboxMap.style!!.removeSource("geojson")
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(LatLng(0.0, 120.0), 8.0))
// Wait for the next frame and check that images were removed from the style.
mapView.addOnDidFinishRenderingFrameListener {
if (mapboxMap.style!!.getImage("small") == null && mapboxMap.style!!.getImage("large") == null) {
latch.countDown()
}
}
}
}
if (!latch.await(5, TimeUnit.SECONDS)) {
throw TimeoutException()
}
}
companion object {
private const val styleJson =
"""
{
"version": 8,
"name": "Mapbox Streets",
@@ -159,5 +160,5 @@ class RemoveUnusedImagesTest : AppCenter() {
}]
}
"""
}
}
}
}

View File

@@ -10,42 +10,43 @@ import com.mapbox.mapboxsdk.maps.MapView
import com.mapbox.mapboxsdk.maps.MapboxMapOptions
import com.mapbox.mapboxsdk.maps.renderer.glsurfaceview.MapboxGLSurfaceView
import com.mapbox.mapboxsdk.testapp.activity.FeatureOverviewActivity
import java.util.concurrent.CountDownLatch
import junit.framework.Assert.assertNotNull
import junit.framework.Assert.assertTrue
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import java.util.concurrent.CountDownLatch
@RunWith(AndroidJUnit4::class)
class RenderViewGetterTest : AppCenter() {
@Rule
@JvmField
var rule = ActivityTestRule(FeatureOverviewActivity::class.java)
@Rule
@JvmField
var rule = ActivityTestRule(FeatureOverviewActivity::class.java)
private lateinit var rootView: ViewGroup
private lateinit var mapView: MapView
private val latch: CountDownLatch = CountDownLatch(1)
private lateinit var rootView: ViewGroup
private lateinit var mapView: MapView
private val latch: CountDownLatch = CountDownLatch(1)
@Test
@UiThreadTest
fun testGLSurfaceView() {
rootView = rule.activity.findViewById(android.R.id.content)
mapView = MapView(rule.activity)
assertNotNull(mapView.renderView)
assertTrue(mapView.renderView is MapboxGLSurfaceView)
}
@Test
@UiThreadTest
fun testGLSurfaceView() {
rootView = rule.activity.findViewById(android.R.id.content)
mapView = MapView(rule.activity)
assertNotNull(mapView.renderView)
assertTrue(mapView.renderView is MapboxGLSurfaceView)
}
@Test
@UiThreadTest
fun testTextureView() {
rootView = rule.activity.findViewById(android.R.id.content)
mapView = MapView(rule.activity,
MapboxMapOptions.createFromAttributes(rule.activity, null)
.textureMode(true)
)
assertNotNull(mapView.renderView)
assertTrue(mapView.renderView is TextureView)
}
}
@Test
@UiThreadTest
fun testTextureView() {
rootView = rule.activity.findViewById(android.R.id.content)
mapView = MapView(
rule.activity,
MapboxMapOptions.createFromAttributes(rule.activity, null)
.textureMode(true)
)
assertNotNull(mapView.renderView)
assertTrue(mapView.renderView is TextureView)
}
}

View File

@@ -8,105 +8,121 @@ import com.mapbox.mapboxsdk.geometry.LatLng
import com.mapbox.mapboxsdk.maps.MapView
import com.mapbox.mapboxsdk.testapp.R
import com.mapbox.mapboxsdk.testapp.activity.espresso.DeviceIndependentTestActivity
import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit
@RunWith(AndroidJUnit4::class)
class ScreenCoordinateConversion : AppCenter() {
@Rule
@JvmField
var rule = ActivityTestRule(DeviceIndependentTestActivity::class.java)
@Rule
@JvmField
var rule = ActivityTestRule(DeviceIndependentTestActivity::class.java)
private lateinit var mapView: MapView
private lateinit var latch: CountDownLatch
private lateinit var mapView: MapView
private lateinit var latch: CountDownLatch
@Before
fun setup() {
latch = CountDownLatch(1)
}
@Test
fun testToScreenCoordinates() {
rule.runOnUiThread {
mapView = rule.activity.findViewById(R.id.mapView)
val expected = doubleArrayOf(261.6888889445351, 253.15541110551123, 267.37777788907033, 247.4627648056528)
val actual = doubleArrayOf(0.0, 0.0, 0.0, 0.0)
mapView.getMapAsync {
val projection = it.projection
projection.toScreenLocations(doubleArrayOf(1.0, 2.0, 3.0, 4.0), actual)
// check all values
assertTrue(expected.contentEquals(actual))
// check first coordinate value
val pointFirst = PointF(expected[0].toFloat(), expected[1].toFloat())
val convertedFirst = projection.toScreenLocation(LatLng(1.0, 2.0))
assertEquals(
pointFirst.x, convertedFirst.x, DELTA_FLOAT
)
assertEquals(
pointFirst.y, convertedFirst.y, DELTA_FLOAT
)
// check second latlng value
val pointSecond = PointF(expected[2].toFloat(), expected[3].toFloat())
val convertedSecond = projection.toScreenLocation(LatLng(3.0, 4.0))
assertEquals(
pointSecond.x, convertedSecond.x, DELTA_FLOAT
)
assertEquals(
pointSecond.y, convertedSecond.y, DELTA_FLOAT
)
latch.countDown()
}
@Before
fun setup() {
latch = CountDownLatch(1)
}
latch.await(10, TimeUnit.SECONDS)
}
@Test
fun testFromScreenCoordinates() {
rule.runOnUiThread {
mapView = rule.activity.findViewById(R.id.mapView)
val expected = doubleArrayOf(66.2314571265913, -89.64843662311537, 65.94647142295494, -88.94531162999371)
val actual = doubleArrayOf(0.0, 0.0, 0.0, 0.0)
mapView.getMapAsync {
val projection = it.projection
projection.fromScreenLocations(doubleArrayOf(1.0, 2.0, 3.0, 4.0), actual)
// check all values at once
assertTrue(expected.contentEquals(actual))
@Test
fun testToScreenCoordinates() {
rule.runOnUiThread {
mapView = rule.activity.findViewById(R.id.mapView)
val expected = doubleArrayOf(261.6888889445351, 253.15541110551123, 267.37777788907033, 247.4627648056528)
val actual = doubleArrayOf(0.0, 0.0, 0.0, 0.0)
mapView.getMapAsync {
val projection = it.projection
projection.toScreenLocations(doubleArrayOf(1.0, 2.0, 3.0, 4.0), actual)
// check all values
assertTrue(expected.contentEquals(actual))
// check first coordinate value
val pointFirst = PointF(expected[0].toFloat(), expected[1].toFloat())
val convertedFirst = projection.toScreenLocation(LatLng(1.0, 2.0))
assertEquals(
pointFirst.x,
convertedFirst.x,
DELTA_FLOAT
)
assertEquals(
pointFirst.y,
convertedFirst.y,
DELTA_FLOAT
)
// check first latlng value
val latLngFirst = LatLng(expected[0], expected[1])
val convertedFirst = projection.fromScreenLocation(PointF(1.0f, 2.0f))
assertEquals(
latLngFirst.latitude, convertedFirst.latitude, DELTA_DOUBLE
)
assertEquals(
latLngFirst.longitude, convertedFirst.longitude, DELTA_DOUBLE
)
// check second latlng value
val latLngSecond = LatLng(expected[2], expected[3])
val convertedSecond = projection.fromScreenLocation(PointF(3.0f, 4.0f))
assertEquals(
latLngSecond.latitude, convertedSecond.latitude, DELTA_DOUBLE
)
assertEquals(
latLngSecond.longitude, convertedSecond.longitude, DELTA_DOUBLE
)
latch.countDown()
}
// check second latlng value
val pointSecond = PointF(expected[2].toFloat(), expected[3].toFloat())
val convertedSecond = projection.toScreenLocation(LatLng(3.0, 4.0))
assertEquals(
pointSecond.x,
convertedSecond.x,
DELTA_FLOAT
)
assertEquals(
pointSecond.y,
convertedSecond.y,
DELTA_FLOAT
)
latch.countDown()
}
}
latch.await(10, TimeUnit.SECONDS)
}
latch.await(10, TimeUnit.SECONDS)
}
companion object {
const val DELTA_DOUBLE = 0.000001
const val DELTA_FLOAT = 0.000001f
}
}
@Test
fun testFromScreenCoordinates() {
rule.runOnUiThread {
mapView = rule.activity.findViewById(R.id.mapView)
val expected = doubleArrayOf(66.2314571265913, -89.64843662311537, 65.94647142295494, -88.94531162999371)
val actual = doubleArrayOf(0.0, 0.0, 0.0, 0.0)
mapView.getMapAsync {
val projection = it.projection
projection.fromScreenLocations(doubleArrayOf(1.0, 2.0, 3.0, 4.0), actual)
// check all values at once
assertTrue(expected.contentEquals(actual))
// check first latlng value
val latLngFirst = LatLng(expected[0], expected[1])
val convertedFirst = projection.fromScreenLocation(PointF(1.0f, 2.0f))
assertEquals(
latLngFirst.latitude,
convertedFirst.latitude,
DELTA_DOUBLE
)
assertEquals(
latLngFirst.longitude,
convertedFirst.longitude,
DELTA_DOUBLE
)
// check second latlng value
val latLngSecond = LatLng(expected[2], expected[3])
val convertedSecond = projection.fromScreenLocation(PointF(3.0f, 4.0f))
assertEquals(
latLngSecond.latitude,
convertedSecond.latitude,
DELTA_DOUBLE
)
assertEquals(
latLngSecond.longitude,
convertedSecond.longitude,
DELTA_DOUBLE
)
latch.countDown()
}
}
latch.await(10, TimeUnit.SECONDS)
}
companion object {
const val DELTA_DOUBLE = 0.000001
const val DELTA_FLOAT = 0.000001f
}
}

View File

@@ -28,4 +28,4 @@ class StyleLoadTest : EspressoTest() {
source.setGeoJson("{}")
}
}
}
}

View File

@@ -5,100 +5,103 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.rule.ActivityTestRule
import com.mapbox.mapboxsdk.offline.OfflineManager
import com.mapbox.mapboxsdk.testapp.activity.FeatureOverviewActivity
import java.util.concurrent.CountDownLatch
import org.junit.Assert
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import java.util.concurrent.CountDownLatch
@RunWith(AndroidJUnit4::class)
class CacheTest {
@Rule
@JvmField
var rule = ActivityTestRule(FeatureOverviewActivity::class.java)
@Rule
@JvmField
var rule = ActivityTestRule(FeatureOverviewActivity::class.java)
private val context: Context by lazy { rule.activity }
private val context: Context by lazy { rule.activity }
private val countDownLatch = CountDownLatch(1)
private val countDownLatch = CountDownLatch(1)
@Test
fun testSetMaximumAmbientCacheSize() {
rule.activity.runOnUiThread {
OfflineManager.getInstance(context).setMaximumAmbientCacheSize(10000000, object : OfflineManager.FileSourceCallback {
override fun onSuccess() {
countDownLatch.countDown()
@Test
fun testSetMaximumAmbientCacheSize() {
rule.activity.runOnUiThread {
OfflineManager.getInstance(context).setMaximumAmbientCacheSize(
10000000,
object : OfflineManager.FileSourceCallback {
override fun onSuccess() {
countDownLatch.countDown()
}
override fun onError(message: String) {
Assert.assertNull("onError should not be called", message)
}
}
)
}
override fun onError(message: String) {
Assert.assertNull("onError should not be called", message)
}
})
countDownLatch.await()
}
countDownLatch.await()
}
@Test
fun testSetClearAmbientCache() {
rule.activity.runOnUiThread {
OfflineManager.getInstance(context).clearAmbientCache(object : OfflineManager.FileSourceCallback {
override fun onSuccess() {
countDownLatch.countDown()
}
@Test
fun testSetClearAmbientCache() {
rule.activity.runOnUiThread {
OfflineManager.getInstance(context).clearAmbientCache(object : OfflineManager.FileSourceCallback {
override fun onSuccess() {
countDownLatch.countDown()
}
override fun onError(message: String) {
Assert.assertNull("onError should not be called", message)
override fun onError(message: String) {
Assert.assertNull("onError should not be called", message)
}
})
}
})
countDownLatch.await()
}
countDownLatch.await()
}
@Test
fun testSetInvalidateAmbientCache() {
rule.activity.runOnUiThread {
OfflineManager.getInstance(context).invalidateAmbientCache(object : OfflineManager.FileSourceCallback {
override fun onSuccess() {
countDownLatch.countDown()
}
@Test
fun testSetInvalidateAmbientCache() {
rule.activity.runOnUiThread {
OfflineManager.getInstance(context).invalidateAmbientCache(object : OfflineManager.FileSourceCallback {
override fun onSuccess() {
countDownLatch.countDown()
}
override fun onError(message: String) {
Assert.assertNull("onError should not be called", message)
override fun onError(message: String) {
Assert.assertNull("onError should not be called", message)
}
})
}
})
countDownLatch.await()
}
countDownLatch.await()
}
@Test
fun testSetResetDatabase() {
rule.activity.runOnUiThread {
OfflineManager.getInstance(context).resetDatabase(object : OfflineManager.FileSourceCallback {
override fun onSuccess() {
countDownLatch.countDown()
}
@Test
fun testSetResetDatabase() {
rule.activity.runOnUiThread {
OfflineManager.getInstance(context).resetDatabase(object : OfflineManager.FileSourceCallback {
override fun onSuccess() {
countDownLatch.countDown()
}
override fun onError(message: String) {
Assert.assertNull("onError should not be called", message)
override fun onError(message: String) {
Assert.assertNull("onError should not be called", message)
}
})
}
})
countDownLatch.await()
}
countDownLatch.await()
}
@Test
fun testSetPackDatabase() {
rule.activity.runOnUiThread {
OfflineManager.getInstance(context).packDatabase(object : OfflineManager.FileSourceCallback {
override fun onSuccess() {
countDownLatch.countDown()
}
@Test
fun testSetPackDatabase() {
rule.activity.runOnUiThread {
OfflineManager.getInstance(context).packDatabase(object : OfflineManager.FileSourceCallback {
override fun onSuccess() {
countDownLatch.countDown()
}
override fun onError(message: String) {
Assert.assertNull("onError should not be called", message)
override fun onError(message: String) {
Assert.assertNull("onError should not be called", message)
}
})
}
})
countDownLatch.await()
}
countDownLatch.await()
}
}
}

View File

@@ -9,116 +9,120 @@ import com.mapbox.mapboxsdk.offline.OfflineRegion
import com.mapbox.mapboxsdk.storage.FileSource
import com.mapbox.mapboxsdk.testapp.activity.FeatureOverviewActivity
import com.mapbox.mapboxsdk.testapp.utils.FileUtils
import java.io.IOException
import java.util.concurrent.CountDownLatch
import org.junit.FixMethodOrder
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.MethodSorters
import java.io.IOException
import java.util.concurrent.CountDownLatch
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@RunWith(AndroidJUnit4::class)
class OfflineManagerTest : AppCenter() {
companion object {
private const val TEST_DB_FILE_NAME = "offline_test.db"
private lateinit var mergedRegion: OfflineRegion
}
@Rule
@JvmField
var rule = ActivityTestRule(FeatureOverviewActivity::class.java)
private val context: Context by lazy { rule.activity }
@Test(timeout = 30_000)
fun a_copyFileFromAssets() {
val latch = CountDownLatch(1)
rule.activity.runOnUiThread {
FileUtils.CopyFileFromAssetsTask(rule.activity, object : FileUtils.OnFileCopiedFromAssetsListener {
override fun onFileCopiedFromAssets() {
latch.countDown()
}
override fun onError() {
throw IOException("Unable to copy DB file.")
}
}).execute(TEST_DB_FILE_NAME, FileSource.getResourcesCachePath(rule.activity))
companion object {
private const val TEST_DB_FILE_NAME = "offline_test.db"
private lateinit var mergedRegion: OfflineRegion
}
latch.await()
}
@Test(timeout = 30_000)
fun b_mergeRegion() {
val latch = CountDownLatch(1)
rule.activity.runOnUiThread {
OfflineManager.getInstance(context).mergeOfflineRegions(
FileSource.getResourcesCachePath(rule.activity) + "/" + TEST_DB_FILE_NAME,
object : OfflineManager.MergeOfflineRegionsCallback {
override fun onMerge(offlineRegions: Array<out OfflineRegion>?) {
assert(offlineRegions?.size == 1)
latch.countDown()
}
@Rule
@JvmField
var rule = ActivityTestRule(FeatureOverviewActivity::class.java)
override fun onError(error: String?) {
throw RuntimeException("Unable to merge external offline database. $error")
}
})
private val context: Context by lazy { rule.activity }
@Test(timeout = 30_000)
fun a_copyFileFromAssets() {
val latch = CountDownLatch(1)
rule.activity.runOnUiThread {
FileUtils.CopyFileFromAssetsTask(
rule.activity,
object : FileUtils.OnFileCopiedFromAssetsListener {
override fun onFileCopiedFromAssets() {
latch.countDown()
}
override fun onError() {
throw IOException("Unable to copy DB file.")
}
}
).execute(TEST_DB_FILE_NAME, FileSource.getResourcesCachePath(rule.activity))
}
latch.await()
}
latch.await()
}
@Test(timeout = 30_000)
fun c_listRegion() {
val latch = CountDownLatch(1)
rule.activity.runOnUiThread {
OfflineManager.getInstance(context).listOfflineRegions(object : OfflineManager.ListOfflineRegionsCallback {
override fun onList(offlineRegions: Array<out OfflineRegion>?) {
assert(offlineRegions?.size == 1)
mergedRegion = offlineRegions!![0]
latch.countDown()
}
@Test(timeout = 30_000)
fun b_mergeRegion() {
val latch = CountDownLatch(1)
rule.activity.runOnUiThread {
OfflineManager.getInstance(context).mergeOfflineRegions(
FileSource.getResourcesCachePath(rule.activity) + "/" + TEST_DB_FILE_NAME,
object : OfflineManager.MergeOfflineRegionsCallback {
override fun onMerge(offlineRegions: Array<out OfflineRegion>?) {
assert(offlineRegions?.size == 1)
latch.countDown()
}
override fun onError(error: String?) {
throw RuntimeException("Unable to merge external offline database. $error")
override fun onError(error: String?) {
throw RuntimeException("Unable to merge external offline database. $error")
}
}
)
}
})
latch.await()
}
latch.await()
}
@Test(timeout = 30_000)
fun d_invalidateRegion() {
val latch = CountDownLatch(1)
rule.activity.runOnUiThread {
mergedRegion.invalidate(object : OfflineRegion.OfflineRegionInvalidateCallback {
override fun onInvalidate() {
latch.countDown()
}
@Test(timeout = 30_000)
fun c_listRegion() {
val latch = CountDownLatch(1)
rule.activity.runOnUiThread {
OfflineManager.getInstance(context).listOfflineRegions(object : OfflineManager.ListOfflineRegionsCallback {
override fun onList(offlineRegions: Array<out OfflineRegion>?) {
assert(offlineRegions?.size == 1)
mergedRegion = offlineRegions!![0]
latch.countDown()
}
override fun onError(error: String?) {
throw RuntimeException("Unable to delete region")
override fun onError(error: String?) {
throw RuntimeException("Unable to merge external offline database. $error")
}
})
}
})
latch.await()
}
latch.await()
}
@Test(timeout = 30_000)
fun e_deleteRegion() {
val latch = CountDownLatch(1)
rule.activity.runOnUiThread {
mergedRegion.delete(object : OfflineRegion.OfflineRegionDeleteCallback {
override fun onDelete() {
latch.countDown()
}
@Test(timeout = 30_000)
fun d_invalidateRegion() {
val latch = CountDownLatch(1)
rule.activity.runOnUiThread {
mergedRegion.invalidate(object : OfflineRegion.OfflineRegionInvalidateCallback {
override fun onInvalidate() {
latch.countDown()
}
override fun onError(error: String?) {
throw RuntimeException("Unable to delete region")
override fun onError(error: String?) {
throw RuntimeException("Unable to delete region")
}
})
}
})
latch.await()
}
latch.await()
}
}
@Test(timeout = 30_000)
fun e_deleteRegion() {
val latch = CountDownLatch(1)
rule.activity.runOnUiThread {
mergedRegion.delete(object : OfflineRegion.OfflineRegionDeleteCallback {
override fun onDelete() {
latch.countDown()
}
override fun onError(error: String?) {
throw RuntimeException("Unable to delete region")
}
})
}
latch.await()
}
}

View File

@@ -6,7 +6,6 @@ import androidx.test.rule.ActivityTestRule
import com.mapbox.mapboxsdk.AppCenter
import com.mapbox.mapboxsdk.storage.FileSource
import com.mapbox.mapboxsdk.testapp.activity.espresso.EspressoTestActivity
import java.util.concurrent.CountDownLatch
import junit.framework.Assert
import org.junit.After
import org.junit.Before
@@ -14,45 +13,49 @@ import org.junit.Rule
import org.junit.Test
import org.junit.rules.TestName
import org.junit.runner.RunWith
import java.util.concurrent.CountDownLatch
@RunWith(AndroidJUnit4::class)
open class FileSourceMapTest : AppCenter() {
private lateinit var fileSourceTestUtils: FileSourceTestUtils
private lateinit var fileSourceTestUtils: FileSourceTestUtils
@get:Rule
val rule = ActivityTestRule(EspressoTestActivity::class.java)
@get:Rule
val rule = ActivityTestRule(EspressoTestActivity::class.java)
@get:Rule
val testName = TestName()
@get:Rule
val testName = TestName()
@Before
@UiThreadTest
fun setup() {
fileSourceTestUtils = FileSourceTestUtils(rule.activity)
fileSourceTestUtils.setup()
}
@Test
fun changeResourcesPathWhileMapVisible() {
val latch = CountDownLatch(1)
rule.activity.runOnUiThread {
FileSource.setResourcesCachePath(fileSourceTestUtils.testPath, object : FileSource.ResourcesCachePathChangeCallback {
override fun onSuccess(path: String) {
latch.countDown()
Assert.assertEquals(fileSourceTestUtils.testPath, path)
}
override fun onError(message: String) {
Assert.fail("Resources path can be changed while the map is running")
}
})
@Before
@UiThreadTest
fun setup() {
fileSourceTestUtils = FileSourceTestUtils(rule.activity)
fileSourceTestUtils.setup()
}
latch.await()
}
@After
fun cleanup() {
fileSourceTestUtils.cleanup()
}
}
@Test
fun changeResourcesPathWhileMapVisible() {
val latch = CountDownLatch(1)
rule.activity.runOnUiThread {
FileSource.setResourcesCachePath(
fileSourceTestUtils.testPath,
object : FileSource.ResourcesCachePathChangeCallback {
override fun onSuccess(path: String) {
latch.countDown()
Assert.assertEquals(fileSourceTestUtils.testPath, path)
}
override fun onError(message: String) {
Assert.fail("Resources path can be changed while the map is running")
}
}
)
}
latch.await()
}
@After
fun cleanup() {
fileSourceTestUtils.cleanup()
}
}

View File

@@ -6,105 +6,107 @@ import androidx.test.rule.ActivityTestRule
import com.mapbox.mapboxsdk.AppCenter
import com.mapbox.mapboxsdk.storage.FileSource
import com.mapbox.mapboxsdk.testapp.activity.FeatureOverviewActivity
import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit
import org.junit.*
import org.junit.rules.TestName
import org.junit.runner.RunWith
import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit
@RunWith(AndroidJUnit4::class)
class FileSourceStandaloneTest : AppCenter() {
private lateinit var fileSourceTestUtils: FileSourceTestUtils
private lateinit var fileSource: FileSource
private lateinit var fileSourceTestUtils: FileSourceTestUtils
private lateinit var fileSource: FileSource
@get:Rule
val rule = ActivityTestRule(FeatureOverviewActivity::class.java)
@get:Rule
val rule = ActivityTestRule(FeatureOverviewActivity::class.java)
@get:Rule
val testName = TestName()
@get:Rule
val testName = TestName()
@Before
@UiThreadTest
fun setup() {
fileSource = FileSource.getInstance(rule.activity)
fileSourceTestUtils = FileSourceTestUtils(rule.activity)
fileSourceTestUtils.setup()
}
@Before
@UiThreadTest
fun setup() {
fileSource = FileSource.getInstance(rule.activity)
fileSourceTestUtils = FileSourceTestUtils(rule.activity)
fileSourceTestUtils.setup()
}
@Test
@UiThreadTest
fun testDefault() {
Assert.assertTrue("FileSource should be active", fileSource.isActivated)
}
@Test
@UiThreadTest
fun testDefault() {
Assert.assertTrue("FileSource should be active", fileSource.isActivated)
}
@Test
@UiThreadTest
fun testActivateDeactivate() {
Assert.assertTrue("1) FileSource should be active", fileSource.isActivated)
fileSource.deactivate()
Assert.assertFalse("2) FileSource should not be active", fileSource.isActivated)
fileSource.activate()
Assert.assertTrue("3) FileSource should be active", fileSource.isActivated)
}
@Test
@UiThreadTest
fun testActivateDeactivate() {
Assert.assertTrue("1) FileSource should be active", fileSource.isActivated)
fileSource.deactivate()
Assert.assertFalse("2) FileSource should not be active", fileSource.isActivated)
fileSource.activate()
Assert.assertTrue("3) FileSource should be active", fileSource.isActivated)
}
@Test
fun pathChangeTest() {
Assert.assertTrue("FileSource should be active", fileSource.isActivated)
Assert.assertEquals(fileSourceTestUtils.originalPath, FileSource.getResourcesCachePath(rule.activity))
@Test
fun pathChangeTest() {
Assert.assertTrue("FileSource should be active", fileSource.isActivated)
Assert.assertEquals(fileSourceTestUtils.originalPath, FileSource.getResourcesCachePath(rule.activity))
fileSourceTestUtils.changePath(fileSourceTestUtils.testPath)
Assert.assertEquals(fileSourceTestUtils.testPath, FileSource.getResourcesCachePath(rule.activity))
Assert.assertTrue("FileSource should be active", fileSource.isActivated)
fileSourceTestUtils.changePath(fileSourceTestUtils.testPath)
Assert.assertEquals(fileSourceTestUtils.testPath, FileSource.getResourcesCachePath(rule.activity))
Assert.assertTrue("FileSource should be active", fileSource.isActivated)
fileSourceTestUtils.changePath(fileSourceTestUtils.originalPath)
Assert.assertEquals(fileSourceTestUtils.originalPath, FileSource.getResourcesCachePath(rule.activity))
Assert.assertTrue("FileSource should be active", fileSource.isActivated)
}
fileSourceTestUtils.changePath(fileSourceTestUtils.originalPath)
Assert.assertEquals(fileSourceTestUtils.originalPath, FileSource.getResourcesCachePath(rule.activity))
Assert.assertTrue("FileSource should be active", fileSource.isActivated)
}
@Test
fun overridePathChangeCallTest() {
val firstLatch = CountDownLatch(1)
val secondLatch = CountDownLatch(1)
rule.activity.runOnUiThread {
FileSource.setResourcesCachePath(
fileSourceTestUtils.testPath,
object : FileSource.ResourcesCachePathChangeCallback {
override fun onSuccess(path: String) {
Assert.assertEquals(fileSourceTestUtils.testPath, path)
firstLatch.countDown()
}
@Test
fun overridePathChangeCallTest() {
val firstLatch = CountDownLatch(1)
val secondLatch = CountDownLatch(1)
rule.activity.runOnUiThread {
FileSource.setResourcesCachePath(
fileSourceTestUtils.testPath,
object : FileSource.ResourcesCachePathChangeCallback {
override fun onSuccess(path: String) {
Assert.assertEquals(fileSourceTestUtils.testPath, path)
firstLatch.countDown()
}
override fun onError(message: String) {
override fun onError(message: String) {
Assert.fail("First attempt should succeed.")
}
}
)
FileSource.setResourcesCachePath(
fileSourceTestUtils.testPath2,
object : FileSource.ResourcesCachePathChangeCallback {
override fun onSuccess(path: String) {
Assert.fail("Second attempt should fail because first one is in progress.")
}
override fun onError(message: String) {
Assert.assertEquals("Another resources cache path change is in progress", message)
secondLatch.countDown()
}
}
)
}
if (!secondLatch.await(5, TimeUnit.SECONDS)) {
Assert.fail("Second attempt should fail.")
}
if (!firstLatch.await(5, TimeUnit.SECONDS)) {
Assert.fail("First attempt should succeed.")
}
})
FileSource.setResourcesCachePath(
fileSourceTestUtils.testPath2,
object : FileSource.ResourcesCachePathChangeCallback {
override fun onSuccess(path: String) {
Assert.fail("Second attempt should fail because first one is in progress.")
}
override fun onError(message: String) {
Assert.assertEquals("Another resources cache path change is in progress", message)
secondLatch.countDown()
}
})
}
}
if (!secondLatch.await(5, TimeUnit.SECONDS)) {
Assert.fail("Second attempt should fail.")
@After
fun cleanup() {
fileSourceTestUtils.cleanup()
}
if (!firstLatch.await(5, TimeUnit.SECONDS)) {
Assert.fail("First attempt should succeed.")
}
}
@After
fun cleanup() {
fileSourceTestUtils.cleanup()
}
}
}

View File

@@ -4,56 +4,57 @@ import android.app.Activity
import androidx.annotation.WorkerThread
import com.mapbox.mapboxsdk.AppCenter
import com.mapbox.mapboxsdk.storage.FileSource
import junit.framework.Assert
import java.io.File
import java.util.concurrent.CountDownLatch
import junit.framework.Assert
class FileSourceTestUtils(private val activity: Activity) : AppCenter() {
val originalPath = FileSource.getResourcesCachePath(activity)
val testPath = "$originalPath/test"
val testPath2 = "$originalPath/test2"
val originalPath = FileSource.getResourcesCachePath(activity)
val testPath = "$originalPath/test"
val testPath2 = "$originalPath/test2"
private val paths = listOf(testPath, testPath2)
private val paths = listOf(testPath, testPath2)
fun setup() {
for (path in paths) {
val testFile = File(path)
testFile.mkdirs()
}
}
@WorkerThread
fun cleanup() {
val currentPath = FileSource.getResourcesCachePath(activity)
if (currentPath != originalPath) {
changePath(originalPath)
fun setup() {
for (path in paths) {
val testFile = File(path)
testFile.mkdirs()
}
}
for (path in paths) {
val testFile = File(path)
if (testFile.exists()) {
testFile.deleteRecursively()
}
}
}
@WorkerThread
fun cleanup() {
val currentPath = FileSource.getResourcesCachePath(activity)
if (currentPath != originalPath) {
changePath(originalPath)
}
@WorkerThread
fun changePath(requestedPath: String) {
val latch = CountDownLatch(1)
activity.runOnUiThread {
FileSource.setResourcesCachePath(
requestedPath,
object : FileSource.ResourcesCachePathChangeCallback {
override fun onSuccess(path: String) {
Assert.assertEquals(requestedPath, path)
latch.countDown()
}
override fun onError(message: String) {
Assert.fail("Resource path change failed - path: $requestedPath, message: $message")
}
})
for (path in paths) {
val testFile = File(path)
if (testFile.exists()) {
testFile.deleteRecursively()
}
}
}
latch.await()
}
}
@WorkerThread
fun changePath(requestedPath: String) {
val latch = CountDownLatch(1)
activity.runOnUiThread {
FileSource.setResourcesCachePath(
requestedPath,
object : FileSource.ResourcesCachePathChangeCallback {
override fun onSuccess(path: String) {
Assert.assertEquals(requestedPath, path)
latch.countDown()
}
override fun onError(message: String) {
Assert.fail("Resource path change failed - path: $requestedPath, message: $message")
}
}
)
}
latch.await()
}
}

View File

@@ -19,92 +19,98 @@ import org.junit.Test
class CustomGeometrySourceTest : BaseTest() {
override fun getActivityClass(): Class<*> = GridSourceActivity::class.java
override fun getActivityClass(): Class<*> = GridSourceActivity::class.java
@Test
fun sourceNotLeakingThreadsTest() {
validateTestSetup()
WaitAction.invoke(4000)
onView(isRoot()).perform(orientationLandscape())
WaitAction.invoke(2000)
onView(isRoot()).perform(orientationPortrait())
WaitAction.invoke(2000)
Assert.assertFalse("Threads should be shutdown when the source is destroyed.",
Thread.getAllStackTraces().keys.filter {
it.name.startsWith(THREAD_PREFIX)
}.count() > THREAD_POOL_LIMIT)
}
@Test
fun threadsShutdownWhenSourceRemovedTest() {
validateTestSetup()
invoke(mapboxMap) { uiController, mapboxMap ->
mapboxMap.style!!.removeLayer(ID_GRID_LAYER)
TestingAsyncUtils.waitForLayer(uiController, mapView)
mapboxMap.style!!.removeSource(ID_GRID_SOURCE)
TestingAsyncUtils.waitForLayer(uiController, mapView)
Assert.assertTrue("There should be no threads running when the source is removed.",
Thread.getAllStackTraces().keys.filter {
it.name.startsWith(THREAD_PREFIX)
}.count() == 0)
@Test
fun sourceNotLeakingThreadsTest() {
validateTestSetup()
WaitAction.invoke(4000)
onView(isRoot()).perform(orientationLandscape())
WaitAction.invoke(2000)
onView(isRoot()).perform(orientationPortrait())
WaitAction.invoke(2000)
Assert.assertFalse(
"Threads should be shutdown when the source is destroyed.",
Thread.getAllStackTraces().keys.filter {
it.name.startsWith(THREAD_PREFIX)
}.count() > THREAD_POOL_LIMIT
)
}
}
@Test
fun threadsRestartedWhenSourceReAddedTest() {
validateTestSetup()
invoke(mapboxMap) { uiController, mapboxMap ->
mapboxMap.style!!.removeLayer((rule.activity as GridSourceActivity).layer)
TestingAsyncUtils.waitForLayer(uiController, mapView)
mapboxMap.style!!.removeSource(ID_GRID_SOURCE)
TestingAsyncUtils.waitForLayer(uiController, mapView)
mapboxMap.style!!.addSource((rule.activity as GridSourceActivity).source)
mapboxMap.style!!.addLayer((rule.activity as GridSourceActivity).layer)
TestingAsyncUtils.waitForLayer(uiController, mapView)
Assert.assertTrue("Threads should be restarted when the source is re-added to the map.",
Thread.getAllStackTraces().keys.filter {
it.name.startsWith(THREAD_PREFIX)
}.count() == THREAD_POOL_LIMIT)
@Test
fun threadsShutdownWhenSourceRemovedTest() {
validateTestSetup()
invoke(mapboxMap) { uiController, mapboxMap ->
mapboxMap.style!!.removeLayer(ID_GRID_LAYER)
TestingAsyncUtils.waitForLayer(uiController, mapView)
mapboxMap.style!!.removeSource(ID_GRID_SOURCE)
TestingAsyncUtils.waitForLayer(uiController, mapView)
Assert.assertTrue(
"There should be no threads running when the source is removed.",
Thread.getAllStackTraces().keys.filter {
it.name.startsWith(THREAD_PREFIX)
}.count() == 0
)
}
}
}
@Test
fun sourceZoomDeltaTest() {
validateTestSetup()
invoke(mapboxMap) { uiController, mapboxMap ->
mapboxMap.prefetchZoomDelta = 3
mapboxMap.style!!.getSource(ID_GRID_SOURCE)!!.let {
assertNull(it.prefetchZoomDelta)
it.prefetchZoomDelta = 5
assertNotNull(it.prefetchZoomDelta)
assertEquals(5, it.prefetchZoomDelta!!)
it.prefetchZoomDelta = null
assertNull(it.prefetchZoomDelta)
}
@Test
fun threadsRestartedWhenSourceReAddedTest() {
validateTestSetup()
invoke(mapboxMap) { uiController, mapboxMap ->
mapboxMap.style!!.removeLayer((rule.activity as GridSourceActivity).layer)
TestingAsyncUtils.waitForLayer(uiController, mapView)
mapboxMap.style!!.removeSource(ID_GRID_SOURCE)
TestingAsyncUtils.waitForLayer(uiController, mapView)
mapboxMap.style!!.addSource((rule.activity as GridSourceActivity).source)
mapboxMap.style!!.addLayer((rule.activity as GridSourceActivity).layer)
TestingAsyncUtils.waitForLayer(uiController, mapView)
Assert.assertTrue(
"Threads should be restarted when the source is re-added to the map.",
Thread.getAllStackTraces().keys.filter {
it.name.startsWith(THREAD_PREFIX)
}.count() == THREAD_POOL_LIMIT
)
}
}
}
@Test
fun isVolatileTest() {
validateTestSetup()
invoke(mapboxMap) { uiController, mapboxMap ->
mapboxMap.style!!.getSource(ID_GRID_SOURCE)!!.let {
assertFalse(it.isVolatile)
it.isVolatile = true
assertTrue(it.isVolatile)
}
@Test
fun sourceZoomDeltaTest() {
validateTestSetup()
invoke(mapboxMap) { uiController, mapboxMap ->
mapboxMap.prefetchZoomDelta = 3
mapboxMap.style!!.getSource(ID_GRID_SOURCE)!!.let {
assertNull(it.prefetchZoomDelta)
it.prefetchZoomDelta = 5
assertNotNull(it.prefetchZoomDelta)
assertEquals(5, it.prefetchZoomDelta!!)
it.prefetchZoomDelta = null
assertNull(it.prefetchZoomDelta)
}
}
}
}
@Test
fun minimumTileUpdateIntervalTest() {
validateTestSetup()
invoke(mapboxMap) { uiController, mapboxMap ->
mapboxMap.style!!.getSource(ID_GRID_SOURCE)!!.let {
assertEquals(0, it.minimumTileUpdateInterval)
it.minimumTileUpdateInterval = 1000
assertEquals(1000, it.minimumTileUpdateInterval)
}
@Test
fun isVolatileTest() {
validateTestSetup()
invoke(mapboxMap) { uiController, mapboxMap ->
mapboxMap.style!!.getSource(ID_GRID_SOURCE)!!.let {
assertFalse(it.isVolatile)
it.isVolatile = true
assertTrue(it.isVolatile)
}
}
}
}
}
@Test
fun minimumTileUpdateIntervalTest() {
validateTestSetup()
invoke(mapboxMap) { uiController, mapboxMap ->
mapboxMap.style!!.getSource(ID_GRID_SOURCE)!!.let {
assertEquals(0, it.minimumTileUpdateInterval)
it.minimumTileUpdateInterval = 1000
assertEquals(1000, it.minimumTileUpdateInterval)
}
}
}
}

View File

@@ -6,11 +6,11 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import com.mapbox.mapboxsdk.testapp.R
import com.mapbox.mapboxsdk.testapp.action.MapboxMapAction
import com.mapbox.mapboxsdk.testapp.activity.EspressoTest
import java.util.*
import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import java.util.*
/**
* CRUD tests around Image
@@ -18,58 +18,58 @@ import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class ImageTest : EspressoTest() {
companion object {
private const val IMAGE_ID = "test.image"
}
@Test
fun testAddGetImage() {
validateTestSetup()
MapboxMapAction.invoke(mapboxMap) { uiController, mapboxMap ->
val drawable = rule.activity.resources.getDrawable(R.drawable.ic_launcher_round)
assertTrue(drawable is BitmapDrawable)
val bitmapSet = (drawable as BitmapDrawable).bitmap
mapboxMap.style!!.addImage(IMAGE_ID, bitmapSet)
// adding an image requires converting the image with an asynctask
uiController.loopMainThreadForAtLeast(200)
val bitmapGet = mapboxMap.style!!.getImage(IMAGE_ID)
assertTrue(bitmapGet!!.similarTo(bitmapSet))
mapboxMap.style!!.removeImage(IMAGE_ID)
assertNull(mapboxMap.style!!.getImage(IMAGE_ID))
companion object {
private const val IMAGE_ID = "test.image"
}
@Test
fun testAddGetImage() {
validateTestSetup()
MapboxMapAction.invoke(mapboxMap) { uiController, mapboxMap ->
val drawable = rule.activity.resources.getDrawable(R.drawable.ic_launcher_round)
assertTrue(drawable is BitmapDrawable)
val bitmapSet = (drawable as BitmapDrawable).bitmap
mapboxMap.style!!.addImage(IMAGE_ID, bitmapSet)
// adding an image requires converting the image with an asynctask
uiController.loopMainThreadForAtLeast(200)
val bitmapGet = mapboxMap.style!!.getImage(IMAGE_ID)
assertTrue(bitmapGet!!.similarTo(bitmapSet))
mapboxMap.style!!.removeImage(IMAGE_ID)
assertNull(mapboxMap.style!!.getImage(IMAGE_ID))
}
}
}
}
/**
* Alternative implementation of Bitmap.sameAs #14060
*/
fun Bitmap.similarTo(other: Bitmap): Boolean {
if (invalidConfig(other)) {
return false
}
// Allocate arrays
val argb = IntArray(width * height)
val argbOther = IntArray(other.width * other.height)
getPixels(argb, 0, width, 0, 0, width, height)
other.getPixels(argbOther, 0, width, 0, 0, width, height)
// Alpha channel special check
if (config == Bitmap.Config.ALPHA_8) {
// in this case we have to manually compare the alpha channel as the rest is garbage.
val length = width * height
for (i in 0 until length) {
if (argb[i] and -0x1000000 != argbOther[i] and -0x1000000) {
if (invalidConfig(other)) {
return false
}
}
return true
}
return Arrays.equals(argb, argbOther)
// Allocate arrays
val argb = IntArray(width * height)
val argbOther = IntArray(other.width * other.height)
getPixels(argb, 0, width, 0, 0, width, height)
other.getPixels(argbOther, 0, width, 0, 0, width, height)
// Alpha channel special check
if (config == Bitmap.Config.ALPHA_8) {
// in this case we have to manually compare the alpha channel as the rest is garbage.
val length = width * height
for (i in 0 until length) {
if (argb[i] and -0x1000000 != argbOther[i] and -0x1000000) {
return false
}
}
return true
}
return Arrays.equals(argb, argbOther)
}
fun Bitmap.invalidConfig(other: Bitmap): Boolean = this.config != other.config || this.width != other.width || this.height != other.height
fun Bitmap.invalidConfig(other: Bitmap): Boolean = this.config != other.config || this.width != other.width || this.height != other.height

View File

@@ -4,15 +4,15 @@ import androidx.test.espresso.UiController
import com.mapbox.mapboxsdk.maps.MapView
object TestingAsyncUtils {
private const val DEFAULT_TIMEOUT = 15_000L
private const val DEFAULT_TIMEOUT = 15_000L
fun waitForLayer(uiController: UiController, mapView: MapView) {
val start = System.nanoTime() / 1E6
var isIdle = false
mapView.addOnDidBecomeIdleListener { isIdle = true }
fun waitForLayer(uiController: UiController, mapView: MapView) {
val start = System.nanoTime() / 1E6
var isIdle = false
mapView.addOnDidBecomeIdleListener { isIdle = true }
while (!isIdle && System.nanoTime() / 1E6 - start < DEFAULT_TIMEOUT) {
uiController.loopMainThreadForAtLeast(100)
while (!isIdle && System.nanoTime() / 1E6 - start < DEFAULT_TIMEOUT) {
uiController.loopMainThreadForAtLeast(100)
}
}
}
}
}