diff options
| author | Joel Klinghed <the_jk@spawned.biz> | 2024-09-10 23:46:21 +0200 |
|---|---|---|
| committer | Joel Klinghed <the_jk@spawned.biz> | 2024-09-10 23:50:27 +0200 |
| commit | 994672608db65a68b3ba3db8fa37bb613de89c20 (patch) | |
| tree | 4873d7177a7949f7e1501e9494e2897e2da35d03 /libs/test-utils/src/main/java/org | |
| parent | 3e1b734cd804dbdb8bff8bbdc944a0fd141bed75 (diff) | |
Add libs:documents
Reads the abomination that is SAF, or Androids best effort to make
files and directories completely and utterly unusable on Android.
The androidTest was (and is) a pain, only known to work on a
Pixel3 API 34 emulator but it showed a lot of things that the
fake content provider in the unit tests failed to show.
Diffstat (limited to 'libs/test-utils/src/main/java/org')
| -rw-r--r-- | libs/test-utils/src/main/java/org/the_jk/cleversync/TreeAbstractTest.kt | 60 |
1 files changed, 42 insertions, 18 deletions
diff --git a/libs/test-utils/src/main/java/org/the_jk/cleversync/TreeAbstractTest.kt b/libs/test-utils/src/main/java/org/the_jk/cleversync/TreeAbstractTest.kt index 302e809..ba65108 100644 --- a/libs/test-utils/src/main/java/org/the_jk/cleversync/TreeAbstractTest.kt +++ b/libs/test-utils/src/main/java/org/the_jk/cleversync/TreeAbstractTest.kt @@ -22,10 +22,13 @@ abstract class TreeAbstractTest { @Test open fun emptyLive() { - val content = tree.liveList().safeValue() - assertThat(content?.directories).isEmpty() - assertThat(content?.files).isEmpty() - assertThat(content?.links).isEmpty() + val liveContent = tree.liveList() + onMain { + val content = liveContent.safeValue() + assertThat(content?.directories).isEmpty() + assertThat(content?.files).isEmpty() + assertThat(content?.links).isEmpty() + } } @Test @@ -45,15 +48,20 @@ abstract class TreeAbstractTest { @Test(timeout = 10000) open fun observeCreateDirectory() { val content = tree.liveList() + // Only accessed on main thread var dir: Directory? = null - content.observeForever { - if (it.directories.size == 1) dir = it.directories[0] + onMain { + content.observeForever { + if (it.directories.size == 1) dir = it.directories[0] + } } tree.createDirectory("foo") - while (dir == null) { - idle() + onMain { + while (dir == null) { + idle() + } + assertThat(dir?.name).isEqualTo("foo") } - assertThat(dir?.name).isEqualTo("foo") } @Test @@ -100,13 +108,18 @@ abstract class TreeAbstractTest { open fun removeDirLive() { tree.createDirectory("foo") val content = tree.liveList() + // Only accessed on main var done = false - content.observeForever { - if (it.directories.isEmpty()) done = true + onMain { + content.observeForever { + if (it.directories.isEmpty()) done = true + } } assertThat(tree.removeDirectory("foo")).isTrue() - while (!done) { - idle() + onMain { + while (!done) { + idle() + } } } @@ -166,16 +179,23 @@ abstract class TreeAbstractTest { Assume.assumeTrue(supportSymlinks()) val content = tree.liveList() + // Only accessed on main var link: Link? = null - content.observeForever { - if (it.links.size == 1) link = it.links[0] + onMain { + content.observeForever { + if (it.links.size == 1) link = it.links[0] + } } val dir = tree.createDirectory("dir") tree.createLink("link", "dir") - while (link == null) { - idle() + onMain { + while (link == null) { + idle() + } + assertThat((link?.resolve() as Link.DirectoryTarget).directory).isEqualTo( + dir + ) } - assertThat((link?.resolve() as Link.DirectoryTarget).directory).isEqualTo(dir) } @Test @@ -336,4 +356,8 @@ abstract class TreeAbstractTest { protected abstract fun supportSymlinks(): Boolean protected abstract fun idle() + + protected open fun onMain(block: () -> Unit) { + block.invoke() + } } |
