package com.cottondb.albums import com.cottondb.albums.library.Bucket import com.cottondb.albums.library.ItemState import com.cottondb.albums.library.LibraryItem import com.cottondb.albums.source.AlbumKind import com.cottondb.albums.source.AlbumRow import com.cottondb.albums.source.AlbumView import com.cottondb.albums.source.AlbumsSource import com.cottondb.albums.source.Answer import com.cottondb.albums.source.BinView import com.cottondb.albums.source.CoreSource import com.cottondb.albums.source.HomeView import com.cottondb.albums.source.ListKind import com.cottondb.albums.source.ListView import com.cottondb.albums.source.PeopleView import com.cottondb.albums.source.PersonView import com.cottondb.albums.source.SetRow import com.cottondb.albums.source.Settled import com.cottondb.albums.source.TidyView import com.cottondb.albums.source.core.AlbumsCore import com.cottondb.albums.source.core.CoreWords import com.cottondb.albums.source.core.LibraryRead import com.cottondb.albums.source.core.LibraryReport import com.cottondb.albums.source.core.RequestIds import com.cottondb.shell.core.CoreException import kotlinx.coroutines.runBlocking import kotlinx.serialization.json.Json import kotlinx.serialization.json.JsonNull import kotlinx.serialization.json.JsonObject import kotlinx.serialization.json.int import kotlinx.serialization.json.jsonArray import kotlinx.serialization.json.jsonObject import kotlinx.serialization.json.jsonPrimitive import org.junit.Assert.assertEquals import org.junit.Assert.assertFalse import org.junit.Assert.assertNotEquals import org.junit.Assert.assertNull import org.junit.Assert.assertTrue import org.junit.Test import java.io.IOException import java.nio.file.Files /** * CORESOURCE ON A FAKE CORE answering ALBUMS CORE 1d's shapes: a request id on every act (one per tap, the same on a * retry and after a kill), the ids on screen and their count carried (rule B), `changed` as the redraw signal, * `albums.platform.done` asking only which ids to read (the next read settles them, never the shell), each file's * library state as the library layer holds it (trashed never folded into present, absent only after a finished * full-access read), and the screens' reads mapped from the core's answers. */ class CoreSourceTest { private val t0 = 1_700_000_000_000L private fun row(id: Long, trashed: Boolean = false, video: Boolean = false, taken: Long? = t0 + id * 1_000, name: String = "IMG_$id.jpg", path: String = "DCIM/Camera/", generation: Long = id) = LibraryItem(id, video, "external_primary", 1, "Camera", path, name, taken, t0 / 1000, t0 / 1000 + id, 1_000_000 + id, 4000, 3000, if (video) "video/mp4" else "image/jpeg", if (video) 6_000 else null, false, null, generation, false, trashed) /** A fake core: canned answers per method (a function of the body), every call recorded. */ private class FakeCore : AlbumsCore { val calls = ArrayList>() val answers = HashMap JsonObject>() /** Calls of a method that fail before any answer (a timeout, a kill), counted down. */ val lose = HashMap() override suspend fun ask(method: String, body: JsonObject): JsonObject { calls += method to body lose[method]?.let { n -> if (n > 0) { lose[method] = n - 1; throw IOException("no answer") } } return answers[method]?.invoke(body) ?: j("{}") } fun of(method: String) = calls.filter { it.first == method }.map { it.second } fun on(method: String, answer: String) { answers[method] = { j(answer) } } } /** What CoreSource leaves to the fixture (People, made albums, grids): nothing here. */ private object NoFallback : AlbumsSource { override suspend fun refresh(library: List, trashed: List, buckets: List) {} override fun tidy(passDone: Boolean) = TidyView(0, 0, 0, emptyList(), true) override fun sets() = emptyList() override fun set(id: String): SetRow? = null override fun list(kind: ListKind) = ListView(kind, emptyList()) override fun bin() = BinView(emptyList(), emptyList(), 0) override fun home() = HomeView(emptyList(), emptyList(), AlbumRow("all", "", AlbumKind.All, 0, null)) override fun album(id: String): AlbumView? = null override fun people() = PeopleView(emptyList(), emptyList(), false) override fun person(id: String): PersonView? = null override fun setKeep(set: String, members: List, count: Int, keep: List) = Answer.Done() override fun keep(ids: List, count: Int) = Answer.Done() override fun binMove(ids: List, count: Int, from: String) = Answer.Done() override fun bringBack(ids: List, count: Int) = Answer.Done() override fun undo(token: String) = Answer.Done() override fun free(ids: List, count: Int) = Answer.Done() override fun platformDone(act: String, actId: String, asked: List) = Answer.Done() override fun settled(actId: String): Settled? = null override fun makeAlbum(title: String, ids: List, count: Int) = Answer.Done() override fun addToAlbum(album: String, ids: List, count: Int) = Answer.Done() override fun namePerson(person: String, name: String, ids: List, count: Int) = Answer.Done() override fun forgetFaces() {} } private fun source(core: FakeCore, read: (() -> LibraryRead)? = null, ids: RequestIds = RequestIds()) = CoreSource(core, NoFallback, read, ids, now = { t0 }) private fun rid(body: JsonObject) = body["request_id"]!!.jsonPrimitive.content private fun strs(body: JsonObject, k: String) = body[k]!!.jsonArray.map { it.jsonPrimitive.content } // ── request ids (rule 6) ──────────────────────────────────────────── @Test fun coreSource_every_act_carries_a_request_id_and_each_tap_its_own() { val core = FakeCore().apply { on("albums.keep", """{"undo": {"label": "Undo", "token": "act-1"}, "job": null, "after": null}""") } val s = source(core) s.keep(listOf(1, 2), 2) s.keep(listOf(1, 2), 2) // the same ids tapped again after the first was answered: a new act s.keep(listOf(3), 1) val sent = core.of("albums.keep") assertEquals(3, sent.size) assertEquals(3, sent.map(::rid).toSet().size) assertTrue(sent.all { rid(it).isNotBlank() }) } @Test fun coreSource_a_retried_act_is_the_same_act_with_the_same_request_id() { val core = FakeCore().apply { on("albums.bin.move", """{"after": "Moved 2 to the Bin.", "undo": {"label": "Undo", "token": "act-9"}, "job": null, "skipped": null, "pairs": []}""") lose["albums.bin.move"] = 1 } val a = source(core).binMove(listOf(4, 5), 2, "screenshots") assertEquals(Answer.Done("Moved 2 to the Bin.", com.cottondb.albums.source.Undo("Undo", "act-9")), a) val sent = core.of("albums.bin.move") assertEquals(2, sent.size) assertEquals(rid(sent[0]), rid(sent[1])) } @Test fun coreSource_an_act_that_never_answered_keeps_its_id_for_the_next_tap_and_after_a_kill() { val file = Files.createTempDirectory("albums-rid").resolve("requests.json").toFile() val core = FakeCore().apply { on("albums.undo", """{"done": true, "job": null}"""); lose["albums.undo"] = CoreSource.TRIES } val first = source(core, ids = RequestIds(file)).undo("act-3") assertTrue(first is Answer.Changed) // the family's failure line, nothing assumed val lost = rid(core.of("albums.undo").first()) // The app is killed; a new source on the same file sends the same tap again: the same act. assertEquals(Answer.Done(), source(core, ids = RequestIds(file)).undo("act-3")) assertEquals(lost, rid(core.of("albums.undo").last())) // Answered now: the next tap is new. source(core, ids = RequestIds(file)).undo("act-3") assertNotEquals(lost, rid(core.of("albums.undo").last())) } @Test fun coreSource_request_ids_are_one_per_tap_until_answered() { var n = 0 val ids = RequestIds { "id-${++n}" } val (m, b) = CoreSource.Calls.keep(listOf(1), 1) assertEquals("id-1", ids.of(m, b)) assertEquals("id-1", ids.of(m, b)) // a double tap before the answer: one act ids.answered(m, b) assertEquals("id-2", ids.of(m, b)) assertEquals("id-3", ids.of(CoreSource.Calls.keep(listOf(2), 1).first, CoreSource.Calls.keep(listOf(2), 1).second)) } // ── rule B and changed ────────────────────────────────────────────── @Test fun coreSource_acts_carry_the_ids_on_screen_and_their_count() { val core = FakeCore().apply { on("albums.set.keep", """{"after": "Kept 1. Moved 2 to the Bin.", "undo": {"label": "Undo", "token": "act-2"}, "job": null, "pairs": []}""") } val s = source(core) s.setKeep("set-7", listOf(1, 2, 3), 3, listOf(2)) s.bringBack(listOf(8, 9), 2) val keep = core.of("albums.set.keep").single() assertEquals("set-7", keep["set"]!!.jsonPrimitive.content) assertEquals(listOf("1", "2", "3"), strs(keep, "members")) assertEquals(listOf("2"), strs(keep, "keep")) assertEquals(3, keep["count"]!!.jsonPrimitive.int) val back = core.of("albums.bin.bring_back").single() assertEquals(listOf("8", "9"), strs(back, "ids")) assertEquals(2, back["count"]!!.jsonPrimitive.int) } @Test fun coreSource_changed_answers_the_redraw_signal_with_the_cores_message_and_the_next_read_is_fresh() { val core = FakeCore().apply { on("albums.tidy", """{"bin": null, "lists": [], "empty": {"title": "Nothing to tidy right now."}}""") } val s = source(core) s.tidy(false); s.tidy(false) assertEquals(1, core.of("albums.tidy").size) // read once, kept until something changed core.answers["albums.keep"] = { throw CoreException("changed", "This changed while you were looking. Here it is again.", JsonNull) } assertEquals(Answer.Changed("This changed while you were looking. Here it is again."), s.keep(listOf(1), 1)) s.tidy(false) assertEquals(2, core.of("albums.tidy").size) core.answers["albums.keep"] = { throw CoreException("handed", "Some of these are being deleted.", JsonNull) } assertTrue(s.keep(listOf(1), 1) is Answer.Changed) core.answers["albums.keep"] = { throw CoreException("gone", "nothing", JsonNull) } assertEquals(Answer.Gone, s.keep(listOf(1), 1)) core.answers["albums.keep"] = { throw CoreException("bad_request", "count: how many", JsonNull) } assertEquals(Answer.Changed(CoreSource.FAILURE), s.keep(listOf(1), 1)) // never the code } // ── Delete, platform.done and the read that settles it ───────────── @Test fun coreSource_delete_answers_the_platform_list_and_platform_done_sends_only_the_read_request() { val core = FakeCore().apply { on("albums.bin", """{"title": "Bin", "head": "2 · 2.0 MB", "groups": [{"heading": "Today · chosen", "bring_back": "Bring back 2", "count": 2, "ids": ["1", "2"]}], "token": 41, "count": 2, "next_from": null, "act": {"label": "Delete 2"}}""") on("albums.bin.delete", """{"job": {"act_id": "act-5", "done": 0, "of": 2}}""") on("albums.work", """{"act_id": "act-5", "done": 2, "of": 2, "finished": true, "platform": {"act": "trash", "parts": [["1", "2", "12"]], "act_id": "act-5"}, "held_back": null}""") on("albums.platform.done", """{"read": ["1", "12", "2"], "act_id": "act-5"}""") } val s = source(core) runBlocking { s.refresh(listOf(row(1), row(2)), emptyList(), emptyList()) } val bin = s.bin() val platform = s.free(bin.ids, bin.count) as Answer.Platform assertEquals("trash", platform.act) assertEquals(listOf(1L, 2L, 12L), platform.ids) // exact file ids, the part included: never expanded here assertEquals(listOf(listOf(1L, 2L, 12L)), s.platformParts("act-5")) val delete = core.of("albums.bin.delete").single() assertEquals(41L, delete["token"]!!.jsonPrimitive.content.toLong()) assertEquals(true, delete["all"]!!.jsonPrimitive.content.toBoolean()) assertEquals(2, delete["count"]!!.jsonPrimitive.int) val before = core.calls.size assertEquals(Answer.Done(), s.platformDone("trash", "act-5", platform.ids)) val after = core.calls.drop(before) assertEquals(listOf("albums.platform.done"), after.map { it.first }) assertEquals(setOf("act_id", "request_id"), after.single().second.keys) // no states, no still_here, no done assertNull(s.settled("act-5")) // nothing is said until the library is read } @Test fun coreSource_the_next_read_settles_a_delete_from_each_files_state_trashed_never_present() { val core = FakeCore().apply { on("albums.bin", """{"groups": [{"heading": "Today · chosen", "count": 3, "ids": ["1", "2", "3"]}], "token": 7, "count": 3, "next_from": null}""") on("albums.bin.delete", """{"job": {"act_id": "act-6", "done": 0, "of": 3}}""") on("albums.work", """{"act_id": "act-6", "finished": true, "platform": {"act": "trash", "parts": [["1", "2", "3"]], "act_id": "act-6"}}""") on("albums.platform.done", """{"read": ["1", "2", "3", "4"], "act_id": "act-6"}""") answers["albums.library.take"] = { b -> if (b.containsKey("act_id")) j("""{"settled": {"freed": 2, "back": 1, "line": "Deleted 2 (2.0 MB). They stay in the phone's trash for 30 days.", "not_done": "1 weren't deleted and are still in the Bin.", "waiting": 0}, "waiting": 0}""") else j("""{"items": 3}""") } } var lr = LibraryRead.of(listOf(row(1), row(2), row(3)), emptyList()) val s = source(core, read = { lr }) runBlocking { s.refresh(listOf(row(1), row(2), row(3)), emptyList(), emptyList()) } val bin = s.bin() val p = s.free(bin.ids, bin.count) as Answer.Platform s.platformDone(p.act, p.actId, p.ids) // The phone trashed 1, left 2, and 3 went: the layer says so after a finished full-access read. lr = LibraryRead(listOf(row(1, trashed = true), row(2)), mapOf(1L to ItemState.Trashed, 2L to ItemState.Present, 3L to ItemState.Absent), complete = true, full = true, token = "v@g=9", whole = true) val before = core.calls.size runBlocking { s.refresh(listOf(row(2)), listOf(row(1, trashed = true)), emptyList()) } val takes = core.calls.drop(before).filter { it.first == "albums.library.take" }.map { it.second } val settle = takes.first() assertEquals("act-6", settle["act_id"]!!.jsonPrimitive.content) val states = settle["states"]!!.jsonArray.associate { it.jsonObject["id"]!!.jsonPrimitive.content to it.jsonObject["state"]!!.jsonPrimitive.content } assertEquals(mapOf("1" to "trashed", "2" to "present", "3" to "absent"), states) // 4: unknown to the layer, not guessed assertEquals(2, s.settled("act-6")!!.moved) assertTrue(s.settled("act-6")!!.after.startsWith("Deleted 2")) // The handed rows waited for the act's own read: sent only after it. val firstItems = takes.indexOfFirst { it.containsKey("items") } assertTrue(firstItems > 0) } @Test fun coreSource_waiting_deletes_from_before_a_kill_are_read_at_the_next_refresh() { val core = FakeCore().apply { on("albums.waiting", """{"count": 2, "acts": [{"act_id": "act-1", "read": ["5", "6"]}]}""") answers["albums.library.take"] = { b -> if (b.containsKey("act_id")) j("""{"settled": {"freed": 1, "back": 1, "line": "Deleted 1 (1.0 MB).", "not_done": null, "waiting": 0}, "waiting": 0}""") else j("{}") } } val s = source(core) runBlocking { s.refresh(listOf(row(6)), listOf(row(5, trashed = true)), emptyList()) } val settle = core.of("albums.library.take").first { it.containsKey("act_id") } val states = settle["states"]!!.jsonArray.associate { it.jsonObject["id"]!!.jsonPrimitive.content to it.jsonObject["state"]!!.jsonPrimitive.content } assertEquals(mapOf("5" to "trashed", "6" to "present"), states) assertEquals(1, s.settled("act-1")!!.moved) assertEquals(0, s.waitingCount) // what the core said after the read settled them } // ── the library read, per file ────────────────────────────────────── @Test fun coreSource_rows_go_per_file_with_trashed_as_its_own_flag_in_batches_of_1000() { val rows = (1L..2_500L).map { row(it, trashed = it % 2 == 0L) } val batches = LibraryReport.itemBatches(rows, emptyMap()) assertEquals(listOf(1_000, 1_000, 500), batches.map { it.size }) val body = LibraryReport.itemsBody(batches[0]) val items = body["items"]!!.jsonArray.map { it.jsonObject } val trashed = items.first { it["id"]!!.jsonPrimitive.content == "2" } val present = items.first { it["id"]!!.jsonPrimitive.content == "1" } assertTrue("trashed" in trashed["flags"]!!.jsonArray.map { it.jsonPrimitive.content }) assertFalse("trashed" in present["flags"]!!.jsonArray.map { it.jsonPrimitive.content }) // Sent once; again only when MediaStore changed the row. val sent = rows.associate { it.id to LibraryReport.fingerprint(it) } assertTrue(LibraryReport.itemBatches(rows, sent).isEmpty()) assertEquals(listOf(listOf(7L)), LibraryReport.itemBatches(rows.map { if (it.id == 7L) it.copy(trashed = true, generation = 99) else it }, sent).map { b -> b.map { it.id } }) } @Test fun coreSource_an_item_is_what_the_core_takes_a_time_always_no_null_duration_and_its_own_bytes() { val photo = LibraryReport.item(row(3, taken = null)) assertEquals((t0 / 1000 + 3) * 1000, photo["taken_at_ms"]!!.jsonPrimitive.content.toLong()) assertFalse(photo.containsKey("duration_ms")) assertEquals(1_000_003L, photo["bytes"]!!.jsonPrimitive.content.toLong()) val raw = row(4, name = "IMG_4.dng").let { it.copy(parts = emptyList()) } val grouped = row(5).copy(parts = listOf(raw)) assertEquals(1_000_005L, LibraryReport.item(grouped)["bytes"]!!.jsonPrimitive.content.toLong()) // never the parts' sum assertEquals(6_000L, LibraryReport.item(row(6, video = true))["duration_ms"]!!.jsonPrimitive.content.toLong()) assertEquals("DCIM/Camera/IMG_3.jpg", photo["path"]!!.jsonPrimitive.content) } @Test fun coreSource_trashed_is_never_folded_into_present_and_the_refresh_alone_never_says_absent() { val lr = LibraryRead.of(listOf(row(1).copy(parts = listOf(row(11, name = "IMG_1.dng")))), listOf(row(2, trashed = true))) assertEquals(mapOf(1L to ItemState.Present, 11L to ItemState.Present, 2L to ItemState.Trashed), lr.states) assertTrue(LibraryReport.absentBatches(lr, emptyMap()).isEmpty()) assertNull(LibraryReport.sweep(lr)) val settle = LibraryReport.settleBody("act-1", listOf("1", "2", "3"), lr.states)!! assertEquals(listOf("present", "trashed"), settle["states"]!!.jsonArray.map { it.jsonObject["state"]!!.jsonPrimitive.content }) assertNull(LibraryReport.settleBody("act-1", listOf("3"), lr.states)) } @Test fun coreSource_absent_only_after_a_finished_full_access_read_with_a_token_and_twice_at_most() { val states = mapOf(1L to ItemState.Present, 2L to ItemState.Absent, 3L to ItemState.Trashed) fun lr(complete: Boolean, full: Boolean, token: String?) = LibraryRead(emptyList(), states, complete, full, token, whole = true) assertTrue(LibraryReport.absentBatches(lr(false, true, "t1"), emptyMap()).isEmpty()) assertTrue(LibraryReport.absentBatches(lr(true, false, "t1"), emptyMap()).isEmpty()) assertTrue(LibraryReport.absentBatches(lr(true, true, null), emptyMap()).isEmpty()) val body = LibraryReport.absentBatches(lr(true, true, "t1"), emptyMap()).single() assertEquals("t1", body["token"]!!.jsonPrimitive.content) assertEquals(listOf("2"), body["states"]!!.jsonArray.map { it.jsonObject["id"]!!.jsonPrimitive.content }) assertTrue(LibraryReport.absentBatches(lr(true, true, "t1"), mapOf(2L to setOf("t1"))).isEmpty()) assertEquals(1, LibraryReport.absentBatches(lr(true, true, "t2"), mapOf(2L to setOf("t1"))).size) assertTrue(LibraryReport.absentBatches(lr(true, true, "t3"), mapOf(2L to setOf("t1", "t2"))).isEmpty()) // The sweep names every id still held, the trashed among them (trashed is not gone). val sweep = LibraryReport.sweep(lr(true, true, "t1"))!! assertEquals(listOf("1", "3"), sweep["all_ids"]!!.jsonArray.map { it.jsonPrimitive.content }) assertEquals(true, sweep["complete"]!!.jsonPrimitive.content.toBoolean()) assertNull(LibraryReport.sweep(lr(true, false, "t1"))) } @Test fun coreSource_refresh_tells_the_core_rows_absent_ids_and_the_sweep_in_that_order() { val core = FakeCore() val lr = LibraryRead(listOf(row(1), row(3, trashed = true)), mapOf(1L to ItemState.Present, 2L to ItemState.Absent, 3L to ItemState.Trashed), true, true, "v@g=4", whole = true) val s = source(core, read = { lr }) runBlocking { s.refresh(listOf(row(1)), listOf(row(3, trashed = true)), emptyList()) } val takes = core.of("albums.library.take") assertEquals(listOf("items", "states", "all_ids"), takes.map { b -> listOf("all_ids", "states", "items").first { b.containsKey(it) } }) assertEquals("waiting", core.calls.first().first.substringAfter("albums.")) // A second read changes nothing: nothing is sent again (the sweep waits a day; the absent id was told this token). runBlocking { s.refresh(listOf(row(1)), listOf(row(3, trashed = true)), emptyList()) } assertEquals(3, core.of("albums.library.take").size) } // ── the screens' reads ────────────────────────────────────────────── @Test fun coreSource_tidy_sets_lists_and_the_bin_map_from_the_cores_answers() { val core = FakeCore().apply { on("albums.tidy", """{"progress": {"head": "Looking through 3 photos", "detail": "1 done", "note": null, "cloud": null, "fraction": 0.33}, "bin": {"line": "In the Bin: 2,340 · 31.4 GB", "act": "Delete 2,340"}, "waiting": null, "could_free": "You could free about 1.5 GB more", "lists": [{"list": "screenshots", "name": "Screenshots", "count": "4,102", "size": "1.4 GB"}, {"list": "exact_copies", "name": "Exact copies", "count": "2", "size": "1 MB"}], "empty": null}""") on("albums.sets", """{"sets": [{"set": "s1", "line": "3 photos", "keep": "Keep 1", "frees": "2 MB", "strip": ["1", "2", "3"], "members": ["1", "2", "3"], "keepers": ["2"]}], "next_from": null}""") answers["albums.list"] = { b -> if (b["from"] == null) j("""{"groups": [{"heading": "Copies of photos you already have", "items": [{"id": "4", "original": "1"}]}, {"heading": "Other WhatsApp photos", "items": []}], "token": 12, "count": 2, "next_from": [1, "4"], "bin_all": {"label": "Bin all 1", "count": 1, "token": 12}}""") else j("""{"groups": [{"heading": "Copies of photos you already have", "items": []}, {"heading": "Other WhatsApp photos", "items": [{"id": "5"}]}], "token": 12, "count": 2, "next_from": null}""") } on("albums.bin", """{"groups": [{"heading": "Today · from a set", "bring_back": "Bring back 1", "count": 1, "ids": ["3"]}, {"heading": "No longer on this phone", "bring_back": null, "count": 2, "ids": ["8", "9"], "chosen": ["bin", "keep"]}], "token": 30, "count": 1, "next_from": null}""") on("albums.bin.move", """{"after": "Moved 1 to the Bin.", "undo": {"label": "Undo", "token": "act-4"}, "job": null}""") } val s = source(core) runBlocking { s.refresh((1L..5L).map { row(it) }, listOf(row(7, trashed = true)), emptyList()) } val tidy = s.tidy(false) assertEquals(2340, tidy.binCount) assertEquals(31_400_000_000L, tidy.binBytes) assertEquals(listOf(ListKind.Screenshots), tidy.lists.map { it.kind }) // a list Android has no kind for is left out assertEquals(4102, tidy.lists[0].count) assertEquals("Looking through 3 photos", s.passLines()!!.head) val set = s.sets().single() assertEquals(listOf(1L, 2L, 3L), set.members.map { it.id }) assertEquals(listOf(2L), set.keepers) val list = s.list(ListKind.WhatsappCopies) assertEquals(listOf(4L, 5L), list.items.map { it.id }) // every page followed assertEquals(1L, list.groups[0].originals[4L]!!.id) assertEquals(listOf(4L), list.binAllIds) // only the copies of his own photos s.binMove(list.binAllIds, 1, ListKind.WhatsappCopies.key) val all = core.of("albums.bin.move").single() assertEquals(true, all["all"]!!.jsonPrimitive.content.toBoolean()) assertEquals(12L, all["token"]!!.jsonPrimitive.content.toLong()) assertEquals("whatsapp_copies", all["list"]!!.jsonPrimitive.content) val bin = s.bin() assertEquals(listOf(3L), bin.ids) assertEquals(2, bin.gone) // shown, never counted or deleted assertEquals(listOf(7L), bin.inTrash.map { it.id }) // the phone's trash, never the Bin } @Test fun coreSource_core_words_carry_their_numbers() { assertEquals(2340, CoreWords.count("In the Bin: 2,340 · 31.4 GB")) assertEquals(31_400_000_000L, CoreWords.bytes("31.4 GB")) assertEquals(12_000_000L, CoreWords.bytes("about 12 MB")) assertEquals(0, CoreWords.count(null)) } companion object { fun j(s: String): JsonObject = Json.parseToJsonElement(s).jsonObject } }