summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/storage
diff options
context:
space:
mode:
authortobrun <tobrun.van.nuland@gmail.com>2019-11-01 10:13:22 +0100
committertobrun <tobrun.van.nuland@gmail.com>2019-11-01 10:13:22 +0100
commit5825afac23d5cfbab3127cf5bdd09f2e815de5f4 (patch)
tree314ca31ef9a4278e0798b3de9115db2892bd8dac /platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/storage
parentc94184c04742e935853a2e6b26d7fe1aa94c3250 (diff)
downloadqtlocation-mapboxgl-upstream/tvn-test-ci.tar.gz
Diffstat (limited to 'platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/storage')
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/storage/FileSourceMapTest.kt59
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/storage/FileSourceStandaloneTest.kt116
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/storage/FileSourceTestUtils.kt59
3 files changed, 234 insertions, 0 deletions
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/storage/FileSourceMapTest.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/storage/FileSourceMapTest.kt
new file mode 100644
index 0000000000..d08507470e
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/storage/FileSourceMapTest.kt
@@ -0,0 +1,59 @@
+package com.mapbox.mapboxsdk.testapp.storage
+
+import android.support.test.annotation.UiThreadTest
+import android.support.test.rule.ActivityTestRule
+import android.support.test.runner.AndroidJUnit4
+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
+import org.junit.Rule
+import org.junit.Test
+import org.junit.rules.TestName
+import org.junit.runner.RunWith
+
+@RunWith(AndroidJUnit4::class)
+open class FileSourceMapTest : AppCenter() {
+
+ private lateinit var fileSourceTestUtils: FileSourceTestUtils
+
+ @get:Rule
+ val rule = ActivityTestRule(EspressoTestActivity::class.java)
+
+ @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) {
+ Assert.fail("Requested resources change while the map is running should fail")
+ }
+
+ override fun onError(message: String) {
+ Assert.assertEquals("Cannot set path, file source is activated." +
+ " Make sure that the map or a resources download is not running.", message)
+ latch.countDown()
+ }
+ })
+ }
+ latch.await()
+ }
+
+ @After
+ fun cleanup() {
+ fileSourceTestUtils.cleanup()
+ }
+} \ No newline at end of file
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/storage/FileSourceStandaloneTest.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/storage/FileSourceStandaloneTest.kt
new file mode 100644
index 0000000000..59f0d04237
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/storage/FileSourceStandaloneTest.kt
@@ -0,0 +1,116 @@
+package com.mapbox.mapboxsdk.testapp.storage
+
+import android.support.test.annotation.UiThreadTest
+import android.support.test.rule.ActivityTestRule
+import android.support.test.runner.AndroidJUnit4
+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
+
+@RunWith(AndroidJUnit4::class)
+class FileSourceStandaloneTest : AppCenter() {
+
+ private lateinit var fileSourceTestUtils: FileSourceTestUtils
+ private lateinit var fileSource: FileSource
+
+ @get:Rule
+ val rule = ActivityTestRule(FeatureOverviewActivity::class.java)
+
+ @get:Rule
+ val testName = TestName()
+
+ @Before
+ @UiThreadTest
+ fun setup() {
+ fileSource = FileSource.getInstance(rule.activity)
+ fileSourceTestUtils = FileSourceTestUtils(rule.activity)
+ fileSourceTestUtils.setup()
+ }
+
+ @Test
+ @UiThreadTest
+ fun testDefault() {
+ Assert.assertFalse("FileSource should not be active", fileSource.isActivated)
+ }
+
+ @Test
+ @UiThreadTest
+ fun testActivateDeactivate() {
+ Assert.assertFalse("1) FileSource should not be active", fileSource.isActivated)
+ fileSource.activate()
+ Assert.assertTrue("2) FileSource should be active", fileSource.isActivated)
+ fileSource.deactivate()
+ Assert.assertFalse("3) FileSource should not be active", fileSource.isActivated)
+ }
+
+ @Test
+ fun pathChangeTest() {
+ Assert.assertFalse("FileSource should not be active", fileSource.isActivated)
+ Assert.assertEquals(fileSourceTestUtils.originalPath, FileSource.getResourcesCachePath(rule.activity))
+
+ fileSourceTestUtils.changePath(fileSourceTestUtils.testPath)
+ Assert.assertEquals(fileSourceTestUtils.testPath, FileSource.getResourcesCachePath(rule.activity))
+
+ fileSourceTestUtils.changePath(fileSourceTestUtils.originalPath)
+ Assert.assertEquals(fileSourceTestUtils.originalPath, FileSource.getResourcesCachePath(rule.activity))
+ }
+
+ @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) {
+ 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)) {
+ rule.runOnUiThread {
+ // if we fail to call a callback, the file source is not going to be deactivated
+ fileSource.deactivate()
+ }
+ Assert.fail("Second attempt should fail.")
+ }
+
+ if (!firstLatch.await(5, TimeUnit.SECONDS)) {
+ rule.runOnUiThread {
+ // if we fail to call a callback, the file source is not going to be deactivated
+ fileSource.deactivate()
+ }
+ Assert.fail("First attempt should succeed.")
+ }
+ }
+
+ @After
+ fun cleanup() {
+ fileSourceTestUtils.cleanup()
+ }
+} \ No newline at end of file
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/storage/FileSourceTestUtils.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/storage/FileSourceTestUtils.kt
new file mode 100644
index 0000000000..6bd97056a6
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/storage/FileSourceTestUtils.kt
@@ -0,0 +1,59 @@
+package com.mapbox.mapboxsdk.testapp.storage
+
+import android.app.Activity
+import android.support.annotation.WorkerThread
+import com.mapbox.mapboxsdk.AppCenter
+import com.mapbox.mapboxsdk.storage.FileSource
+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"
+
+ 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)
+ }
+
+ for (path in paths) {
+ val testFile = File(path)
+ if (testFile.exists()) {
+ testFile.deleteRecursively()
+ }
+ }
+ }
+
+ @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()
+ }
+} \ No newline at end of file