This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
af74d00
commit 98d3f42
Showing
5 changed files
with
186 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...SDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/storage/FileSourceMapTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
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.storage.FileSource | ||
import com.mapbox.mapboxsdk.testapp.activity.espresso.EspressoTestActivity | ||
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 | ||
import java.util.concurrent.CountDownLatch | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
open class FileSourceMapTest { | ||
|
||
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(rule.activity, 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() | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
...App/src/androidTest/java/com/mapbox/mapboxsdk/testapp/storage/FileSourceStandaloneTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package com.mapbox.mapboxsdk.testapp.storage | ||
|
||
import android.os.Handler | ||
import android.support.test.annotation.UiThreadTest | ||
import android.support.test.rule.ActivityTestRule | ||
import android.support.test.runner.AndroidJUnit4 | ||
import com.mapbox.mapboxsdk.storage.FileSource | ||
import com.mapbox.mapboxsdk.testapp.activity.FeatureOverviewActivity | ||
import org.junit.* | ||
import org.junit.rules.TestName | ||
import org.junit.runner.RunWith | ||
import java.util.concurrent.CountDownLatch | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
class FileSourceStandaloneTest { | ||
|
||
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)) | ||
|
||
// workaround for https://github.com/mapbox/mapbox-gl-native/issues/14334 | ||
val latch = CountDownLatch(1) | ||
rule.activity.runOnUiThread { | ||
fileSource.activate() | ||
Handler().postDelayed({ | ||
fileSource.deactivate() | ||
latch.countDown() | ||
}, 2000) | ||
} | ||
latch.await() | ||
|
||
fileSourceTestUtils.changePath(fileSourceTestUtils.originalPath) | ||
Assert.assertEquals(fileSourceTestUtils.originalPath, FileSource.getResourcesCachePath(rule.activity)) | ||
} | ||
|
||
@After | ||
fun cleanup() { | ||
fileSourceTestUtils.cleanup() | ||
} | ||
} |
40 changes: 0 additions & 40 deletions
40
...dSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/storage/FileSourceTest.java
This file was deleted.
Oops, something went wrong.
50 changes: 50 additions & 0 deletions
50
...KTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/storage/FileSourceTestUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.mapbox.mapboxsdk.testapp.storage | ||
|
||
import android.app.Activity | ||
import android.support.annotation.WorkerThread | ||
import com.mapbox.mapboxsdk.storage.FileSource | ||
import junit.framework.Assert | ||
import java.io.File | ||
import java.util.concurrent.CountDownLatch | ||
|
||
class FileSourceTestUtils(private val activity: Activity) { | ||
val originalPath = FileSource.getResourcesCachePath(activity) | ||
val testPath = "$originalPath/test" | ||
|
||
fun setup() { | ||
val testFile = File(testPath) | ||
testFile.mkdirs() | ||
} | ||
|
||
@WorkerThread | ||
fun cleanup() { | ||
val currentPath = FileSource.getResourcesCachePath(activity) | ||
if (currentPath != originalPath) { | ||
changePath(originalPath) | ||
} | ||
val testFile = File(testPath) | ||
if (testFile.exists()) { | ||
testFile.deleteRecursively() | ||
} | ||
} | ||
|
||
@WorkerThread | ||
fun changePath(path: String) { | ||
val latch = CountDownLatch(1) | ||
activity.runOnUiThread { | ||
FileSource.setResourcesCachePath( | ||
activity, | ||
path, | ||
object : FileSource.ResourcesCachePathChangeCallback { | ||
override fun onSuccess(path: String?) { | ||
latch.countDown() | ||
} | ||
|
||
override fun onError(message: String?) { | ||
Assert.fail("Resource path change failed - path: $path, message: $message") | ||
} | ||
}) | ||
} | ||
latch.await() | ||
} | ||
} |