diff options
author | Allan Wang <me@allanwang.ca> | 2018-01-18 23:23:56 -0500 |
---|---|---|
committer | Allan Wang <me@allanwang.ca> | 2018-01-20 16:42:37 -0500 |
commit | d766100c297bc094491de150f24c04719ffa8f4e (patch) | |
tree | b69863dace2fcb45d5fd25c276ca450e07305c44 /app/src/test | |
parent | 78b3cc41e4c9f8d141ad46ee75e476fa2d177f19 (diff) | |
download | frost-d766100c297bc094491de150f24c04719ffa8f4e.tar.gz frost-d766100c297bc094491de150f24c04719ffa8f4e.tar.bz2 frost-d766100c297bc094491de150f24c04719ffa8f4e.zip |
Enhancement/speed up (#650)
* Revert back to m.facebook
* Add initial speedup
* Update theme
* Fix link press for event status
* Move web states to fb const
* Fix images and email
* Fix up flyweight for requests
* Ensure frost request is synchronous
* Prepare diff utils
* Improve speed and fix blank overlay
* Update comments
* Add debugger and fix searchview
* Theme discover pages. Resolves #654
* Fix duplicate reload
* Fix image loading
* Update changelog
* Update tests
* Rename test
Update dependencies
Update gitignore
Diffstat (limited to 'app/src/test')
4 files changed, 80 insertions, 32 deletions
diff --git a/app/src/test/kotlin/com/pitchedapps/frost/facebook/FbUrlTest.kt b/app/src/test/kotlin/com/pitchedapps/frost/facebook/FbUrlTest.kt index 79d5ea64..e508c3fe 100644 --- a/app/src/test/kotlin/com/pitchedapps/frost/facebook/FbUrlTest.kt +++ b/app/src/test/kotlin/com/pitchedapps/frost/facebook/FbUrlTest.kt @@ -20,7 +20,7 @@ class FbUrlTest { @Test fun base() { - val url = "https://touch.facebook.com/relative/?asdf=1234&hjkl=7890" + val url = "${FB_URL_BASE}relative/?asdf=1234&hjkl=7890" assertFbFormat(url, url) } @@ -62,11 +62,11 @@ class FbUrlTest { @Test - fun imageRegex() { + fun image() { arrayOf( - "https://scontent-yyz1-1.xx.fbcdn.net/v/t1.0-9/fr/cp0/e15/q65/229_546131_836546862_n.jpg?efg=e343J9&oh=d4245b1&oe=5453", - "/photo/view_full_size/?fbid=1523&ref_component=mbasic_photo_permalink&ref_page=%2Fwap%2Fphoto.php&refid=153&_ft_=...", - "#!/photo/view_full_size/?fbid=1523&ref_component=mbasic_photo_permalink&ref_page=%2Fwap%2Fphoto.php&refid=153&_ft_=..." + "https://scontent-yyz1-1.xx.fbcdn.net/v/t1.0-9/fr/cp0/e15/q65/229_546131_836546862_n.jpg?efg=e343J9&oh=d4245b1&oe=5453" +// "/photo/view_full_size/?fbid=1523&ref_component=mbasic_photo_permalink&ref_page=%2Fwap%2Fphoto.php&refid=153&_ft_=...", +// "#!/photo/view_full_size/?fbid=1523&ref_component=mbasic_photo_permalink&ref_page=%2Fwap%2Fphoto.php&refid=153&_ft_=..." ).forEach { assertTrue(it.isImageUrl, "Failed to match image for $it") } @@ -84,4 +84,10 @@ class FbUrlTest { } + @Test + fun viewFullImage() { + val url = "https://scontent-yyz1-1.xx.fbcdn.net/v/t1.0-9/fr/cp0/e15/q65/asdf_n.jpg?efg=asdf&oh=asdf&oe=asdf" + assertFbFormat(url, "#!$url") + } + }
\ No newline at end of file diff --git a/app/src/test/kotlin/com/pitchedapps/frost/internal/Internal.kt b/app/src/test/kotlin/com/pitchedapps/frost/internal/Internal.kt index fb2b2a45..2af98eda 100644 --- a/app/src/test/kotlin/com/pitchedapps/frost/internal/Internal.kt +++ b/app/src/test/kotlin/com/pitchedapps/frost/internal/Internal.kt @@ -1,13 +1,18 @@ package com.pitchedapps.frost.internal -import com.pitchedapps.frost.facebook.* +import com.pitchedapps.frost.facebook.FB_USER_MATCHER +import com.pitchedapps.frost.facebook.FbItem +import com.pitchedapps.frost.facebook.get import com.pitchedapps.frost.facebook.requests.RequestAuth import com.pitchedapps.frost.facebook.requests.getAuth import com.pitchedapps.frost.utils.frostJsoup +import io.reactivex.Completable import org.junit.Assume +import org.junit.Test import java.io.File import java.io.FileInputStream import java.util.* +import java.util.concurrent.TimeUnit import kotlin.reflect.full.starProjectedType import kotlin.test.assertEquals import kotlin.test.assertTrue @@ -74,4 +79,35 @@ fun Any.assertComponentsNotEmpty() { fun <T : Comparable<T>> List<T>.assertDescending(tag: String) { assertEquals(sortedDescending(), this, "$tag not sorted in descending order") +} + +interface CompletableCallback { + fun onComplete() + fun onError(message: String) +} + +inline fun concurrentTest(crossinline caller: (callback: CompletableCallback) -> Unit) { + val result = Completable.create { emitter -> + caller(object : CompletableCallback { + override fun onComplete() = emitter.onComplete() + override fun onError(message: String) = emitter.onError(Throwable(message)) + }) + }.blockingGet(5, TimeUnit.SECONDS) + if (result != null) + throw RuntimeException("Concurrent fail: ${result.message}") +} + +class InternalTest { + @Test + fun concurrentTest() = try { + concurrentTest { result -> + Thread().run { + Thread.sleep(100) + result.onError("Intentional fail") + } + } + fail("Did not throw exception") + } catch (e: Exception) { + // pass + } }
\ No newline at end of file diff --git a/app/src/test/kotlin/com/pitchedapps/frost/rx/ResettableFlyweightTest.kt b/app/src/test/kotlin/com/pitchedapps/frost/rx/ResettableFlyweightTest.kt index ec92b059..a520e9e3 100644 --- a/app/src/test/kotlin/com/pitchedapps/frost/rx/ResettableFlyweightTest.kt +++ b/app/src/test/kotlin/com/pitchedapps/frost/rx/ResettableFlyweightTest.kt @@ -1,10 +1,8 @@ package com.pitchedapps.frost.rx +import com.pitchedapps.frost.internal.concurrentTest import org.junit.Before import org.junit.Test -import java.util.concurrent.CountDownLatch -import kotlin.test.assertEquals -import kotlin.test.assertNotEquals /** * Created by Allan Wang on 07/01/18. @@ -27,34 +25,34 @@ class ResettableFlyweightTest { } private lateinit var flyweight: IntFlyweight - private lateinit var latch: CountDownLatch @Before fun init() { flyweight = IntFlyweight() - latch = CountDownLatch(1) } @Test - fun testCache() { - flyweight(1).subscribe { i -> - flyweight(1).subscribe { j -> - assertEquals(i, j, "Did not use cache during calls") - latch.countDown() + fun testCache() = concurrentTest { result -> + flyweight(1).subscribe { i, _ -> + flyweight(1).subscribe { j, _ -> + if (i != null && i == j) + result.onComplete() + else + result.onError("Did not use cache during calls") } } - latch.await() } @Test - fun testNoCache() { - flyweight(1).subscribe { i -> - flyweight(2).subscribe { j -> - assertNotEquals(i, j, "Should not use cache for calls with different keys") - latch.countDown() + fun testNoCache() = concurrentTest { result -> + flyweight(1).subscribe { i, _ -> + flyweight(2).subscribe { j, _ -> + if (i != null && i != j) + result.onComplete() + else + result.onError("Should not use cache for calls with different keys") } } - latch.await() } diff --git a/app/src/test/kotlin/com/pitchedapps/frost/utils/UrlTests.kt b/app/src/test/kotlin/com/pitchedapps/frost/utils/UrlTests.kt index 5dbcad65..109387a0 100644 --- a/app/src/test/kotlin/com/pitchedapps/frost/utils/UrlTests.kt +++ b/app/src/test/kotlin/com/pitchedapps/frost/utils/UrlTests.kt @@ -2,6 +2,7 @@ package com.pitchedapps.frost.utils import com.pitchedapps.frost.facebook.FACEBOOK_COM import org.junit.Test +import kotlin.test.assertEquals import kotlin.test.assertFalse import kotlin.test.assertTrue @@ -14,15 +15,22 @@ class UrlTests { @Test fun independence() { - assertTrue(GOOGLE.isIndependent, "google") - assertTrue(FACEBOOK_COM.isIndependent, "facebook") - assertFalse("#!/photos/viewer/?photoset_token=pcb.1234".isIndependent, "photo") - assertFalse("#test-id".isIndependent, "id") - assertFalse("#".isIndependent, "#") - assertFalse("#!".isIndependent, "#!") - assertFalse("#!/".isIndependent, "#!/") - assertTrue("/this/is/valid".isIndependent, "url segments") - assertTrue("#!/facebook/segment".isIndependent, "facebook segments") + + mapOf( + GOOGLE to true, + FACEBOOK_COM to true, + "#!/photos/viewer/?photoset_token=pcb.1234" to false, + "#test-id" to false, + "#" to false, + "#!" to false, + "#!/" to false, + "#!/events/permalink/going/?event_id=" to false, + "/this/is/valid" to true, + "#!/facebook/segment" to true + ).forEach { (url, valid) -> + assertEquals(valid, url.isIndependent, + "Independence test failed for $url; should be $valid") + } } @Test |