Cotton code
73 lines · 5.0 KB · KotlinRaw
package com.cottondb.cinemasimport org.junit.Assert.assertFalseimport org.junit.Assert.assertTrueimport org.junit.Testimport java.io.File/** * THE PLAYER COMES UP ON THE TAP (the owner, build 20: "the player doesn't come up immediately ... 4 to 8 seconds"): * a play stands the player at once with the title's picture and a spinner, and only then asks the core; and nothing * of ours announces the title over the picture as it starts (the owner: no title toast). */class PlayerStartTest {    private val root = generateSequence(File("").absoluteFile) { it.parentFile }.first { File(it, "apps/android").isDirectory }    private val cinemas = File(root, "apps/android/app/src/cinemas/kotlin/com/cottondb/cinemas")    private val playback = File(cinemas, "player/FilmPlayback.kt").readText()    private val parts = File(cinemas, "CinemasParts.kt").readText()    @Test    fun the_player_stands_before_the_core_is_asked() {        val play = playback.substring(playback.indexOf("fun play(table: String"))        val stands = play.indexOf("starting = Starting(")        val asks = play.indexOf("core.obj(\"shell.player\"")        assertTrue("play sets the starting player", stands >= 0)        assertTrue("…before it asks the core (stands at $stands, asks at $asks)", stands in 0 until asks)        // Its cover is drawn while it starts, until the film's first frame.        assertTrue(parts.contains("player-starting"))        assertTrue(playback.contains("override fun onRenderedFirstFrame()"))    }    @Test    fun a_title_page_prepares_its_film_and_the_next_episode_is_prepared_as_it_is_counted_in() {        val page = File(cinemas, "stream/TitlePage.kt").readText()        assertTrue(page.contains("state.playback?.prepare(item.table, item.id, hidden = state.inHidden)"))        assertTrue("prepared again when the player closes over the page", page.contains("LaunchedEffect(item.table, item.id, playerUp) { if (!playerUp)"))        // It names the network; the core holds to the cellular setting (RELAY 2), and fetches nothing without one.        assertTrue(playback.contains("player(\"prepare\") { put(\"table\", table); put(\"id\", id); put(\"network\", network);"))        assertTrue("a page closed lets go of what it prepared", page.contains("onDispose { state.playback?.unprepare() }"))        val close = playback.substring(playback.indexOf("fun close(clearing: Boolean")).substringBefore("\n    }\n")        assertTrue("the player closed releases the windows", close.contains("release()"))        val finished = playback.substring(playback.indexOf("private fun finished()")).substringBefore("\n    }\n")        assertTrue("the next episode is prepared before it is counted in", finished.indexOf("prepare(t, i)") in 0 until finished.indexOf("countNext("))    }    @Test    fun a_play_closed_while_it_starts_opens_nothing() {        val close = playback.substring(playback.indexOf("fun close(clearing: Boolean"))        assertTrue("close forgets a play still starting", close.substringBefore("\n    }\n").contains("starting = null"))        val asking = playback.substring(playback.indexOf("private fun asking(")).substringBefore("\n    }\n")        assertTrue("an answer to a play closed or overtaken is dropped", asking.contains("if (mine != playsAsked) return@launch"))        assertTrue("closing stops every try still to come", close.substringBefore("\n    }\n").contains("playsAsked++"))    }    @Test    fun no_title_toast_and_no_casting_line_over_the_picture() {        assertFalse(parts.contains("player-marquee"))        assertFalse(playback.contains("marquee"))        assertFalse(parts.contains("player-casting"))    }    @Test    fun a_slow_cotton_is_said_and_tried_again_until_it_plays() {        // SLOW (the owner's iPhone, 26 Nov 2026): said after 4 s with no frame or a stall, and tried again without end.        assertTrue(playback.contains("private const val SLOW_MS = 4_000L"))        val asking = playback.substring(playback.indexOf("private fun asking(")).substringBefore("\n    }\n")        assertTrue("a failed play is asked again unless it is final", asking.contains("if (final(failure))") && asking.contains("if (mine == playsAsked) asking(table, id, atStart, mine)"))        assertTrue("an unsigned stream is asked again", playback.contains("asked.str(\"refusal\") == null && film.str(\"bundle\") == null && film.str(\"file\") == null"))        assertTrue("a network failure prepares again", playback.contains("if (mine == playsAsked) exo?.prepare()"))        assertTrue("segments are fetched again without end", playback.contains("setLoadErrorHandlingPolicy(KeepTrying)") && playback.contains("getMinimumLoadableRetryCount(dataType: Int): Int = Int.MAX_VALUE"))        val parts = java.io.File(playback.let { "src/cinemas/kotlin/com/cottondb/cinemas/CinemasParts.kt" }).let { if (it.exists()) it else java.io.File("app/" + it.path) }.readText()        assertTrue("the player says it", parts.contains("if (playing.slow) SlowLine(shell)") && parts.contains("\"player.slow\""))    }}