mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 20:36:04 +00:00
feat: Better boot movies system; Added steamdeckrepo support (#1036)
This commit is contained in:
1 parent
b868863133
commit
e53232b301
52 files changed
+4040
-170
No files matched your search
@@ -0,0 +1,310 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
import android.content.Context
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.annotation.Config
|
||||
import java.io.File
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [33])
|
||||
class BootMovieLibraryTest {
|
||||
private val app get() = RuntimeEnvironment.getApplication()
|
||||
private val movies get() = BootMovieLibrary.moviesDir(app)
|
||||
|
||||
@Before fun clear() {
|
||||
app.getSharedPreferences("session", Context.MODE_PRIVATE).edit().clear().commit()
|
||||
File(app.filesDir, "boot-movie").deleteRecursively()
|
||||
movies.deleteRecursively()
|
||||
BootMovieLibrary.libraryDir(app).deleteRecursively()
|
||||
File(BootMovieLibrary.steamRoot(app), "steamui").deleteRecursively()
|
||||
File(BootMovieLibrary.steamRoot(app), "appcache").deleteRecursively()
|
||||
BootMovieLibrary.forgetScan()
|
||||
BootMovieLibrary.steamConfig(app).delete()
|
||||
}
|
||||
|
||||
private fun movie(name: String) = File(movies, name).also { it.parentFile!!.mkdirs(); it.writeText("movie") }
|
||||
|
||||
/** A movie DroidDeck itself imported: kept in the library, copied into Steam's folder and noted in the list. */
|
||||
private fun imported(title: String, source: String = BootMovieLibrary.SOURCE_IMPORT, repo: String? = null): String {
|
||||
val staged = File(BootMovieLibrary.libraryDir(app), ".t-${System.nanoTime()}-${Thread.currentThread().id}.staged").also { it.parentFile!!.mkdirs(); it.writeText("movie") }
|
||||
return BootMovieLibrary.commit(app, staged, title, source, repo)!!
|
||||
}
|
||||
|
||||
private fun steamPicksAt(path: String) {
|
||||
BootMovieLibrary.steamConfig(app).also { it.parentFile!!.mkdirs() }.writeText(
|
||||
"\"InstallConfigStore\"\n{\n\t\"StartupMovie\"\n\t{\n\t\t\"MovieID\"\t\t\"x\"\n\t\t\"LocalPath\"\t\t\"$path\"\n\t}\n}\n",
|
||||
)
|
||||
}
|
||||
|
||||
private fun steamPicks(name: String) = steamPicksAt("/uioverrides/movies/$name")
|
||||
|
||||
@Test fun theActiveX64ClientsOwnMoviesAreListedAndRemovedToo() {
|
||||
SessionPrefs.setSteamClientArch(app, "x86_64")
|
||||
val x64 = File(SessionPrefs.steamRoot(app, "x86_64"), "config/uioverrides/movies")
|
||||
try {
|
||||
File(x64, "Mine.webm").also { it.parentFile!!.mkdirs(); it.writeText("movie") }
|
||||
movie("Main.webm")
|
||||
val entries = BootMovieLibrary.list(app).filter { it.id.startsWith(BootMovieLibrary.PREFIX) }
|
||||
assertEquals(listOf("file:Main.webm", "file:Mine.webm"), entries.map { it.id })
|
||||
assertTrue(entries.all { it.removable })
|
||||
assertEquals("Mine.webm", BootMovieLibrary.file(app, "file:Mine.webm")?.name)
|
||||
assertEquals("Mine (2).webm", BootMovieLibrary.freeName(app, "Mine"))
|
||||
assertTrue(BootMovieLibrary.remove(app, "file:Mine.webm"))
|
||||
assertFalse(File(x64, "Mine.webm").exists())
|
||||
} finally {
|
||||
x64.deleteRecursively()
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun removingAMovieKeepsTheSameNamedOneInTheOtherSteamFolder() {
|
||||
SessionPrefs.setSteamClientArch(app, "x86_64")
|
||||
val x64 = File(SessionPrefs.steamRoot(app, "x86_64"), "config/uioverrides/movies")
|
||||
try {
|
||||
File(x64, "Intro.webm").also { it.parentFile!!.mkdirs(); it.writeText("movie") }
|
||||
movie("Intro.webm")
|
||||
assertTrue(BootMovieLibrary.remove(app, "file:Intro.webm"))
|
||||
assertFalse(File(movies, "Intro.webm").exists())
|
||||
assertTrue(File(x64, "Intro.webm").isFile)
|
||||
assertTrue(BootMovieLibrary.list(app).any { it.id == "file:Intro.webm" })
|
||||
assertTrue(BootMovieLibrary.remove(app, "file:Intro.webm"))
|
||||
assertFalse(File(x64, "Intro.webm").exists())
|
||||
} finally {
|
||||
x64.deleteRecursively()
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun aSavedChoiceKeepsMeaningTheSameFileWhicheverClientRuns() {
|
||||
val x64 = File(SessionPrefs.steamRoot(app, "x86_64"), "config/uioverrides/movies")
|
||||
try {
|
||||
File(x64, "Intro.webm").also { it.parentFile!!.mkdirs(); it.writeText("other") }
|
||||
val main = movie("Intro.webm")
|
||||
SessionPrefs.setSteamClientArch(app, "x86_64")
|
||||
assertEquals(main.path, BootMovieLibrary.file(app, "file:Intro.webm")?.path)
|
||||
SessionPrefs.setSteamClientArch(app, "arm64")
|
||||
assertEquals(main.path, BootMovieLibrary.file(app, "file:Intro.webm")?.path)
|
||||
} finally {
|
||||
x64.deleteRecursively()
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun listsTheDroidDeckMoviesAndEveryWebmButNotTheStagedCopies() {
|
||||
movie("Intro.webm")
|
||||
movie("bigpicture_startup.webm")
|
||||
movie("steam_os_startup.webm")
|
||||
movie("notes.txt")
|
||||
movie(".hidden.webm")
|
||||
val ids = BootMovieLibrary.list(app).map { it.id }
|
||||
assertEquals(listOf(BootMovie.DROIDDECK_30, BootMovie.DROIDDECK_60, "file:Intro.webm"), ids)
|
||||
}
|
||||
|
||||
@Test fun usesTheTitleItWasRegisteredWithAndFallsBackToTheFileName() {
|
||||
imported("Fancy", BootMovieLibrary.SOURCE_REPO, "id1"); movie("b.webm")
|
||||
val list = BootMovieLibrary.list(app).associateBy { it.id }
|
||||
assertEquals("Fancy", list["file:Fancy.webm"]!!.title)
|
||||
assertEquals(BootMovieLibrary.SOURCE_REPO, list["file:Fancy.webm"]!!.source)
|
||||
assertTrue(list["file:Fancy.webm"]!!.removable)
|
||||
assertTrue(list["file:b.webm"]!!.removable)
|
||||
assertEquals("b", list["file:b.webm"]!!.title)
|
||||
assertEquals(BootMovieLibrary.SOURCE_IMPORT, list["file:b.webm"]!!.source)
|
||||
assertEquals(setOf("id1"), BootMovieLibrary.installedRepoIds(app))
|
||||
assertEquals("Fancy.webm", BootMovieLibrary.nameForRepo(app, "id1"))
|
||||
}
|
||||
|
||||
@Test fun aChosenFileMovieIsKeptAndFallsBackOnceItIsGone() {
|
||||
val name = imported("Mine")
|
||||
BootMovie.select(app, "file:$name")
|
||||
assertEquals("file:$name", BootMovie.choice(app))
|
||||
assertTrue(BootMovieLibrary.remove(app, "file:$name"))
|
||||
assertEquals(BootMovie.DROIDDECK_30, BootMovie.choice(app))
|
||||
assertFalse(File(movies, name).exists())
|
||||
assertFalse(File(BootMovieLibrary.libraryDir(app), name).exists())
|
||||
}
|
||||
|
||||
@Test fun aMovieInSteamsCustomFolderCanBeRemovedEvenWithoutANote() {
|
||||
movie("by-hand.webm")
|
||||
assertTrue(BootMovieLibrary.list(app).first { it.id == "file:by-hand.webm" }.removable)
|
||||
assertTrue(BootMovieLibrary.remove(app, "file:by-hand.webm"))
|
||||
assertFalse(File(movies, "by-hand.webm").exists())
|
||||
}
|
||||
|
||||
@Test fun steamsOwnMoviesAreNeverDeleted() {
|
||||
val own = File(BootMovieLibrary.steamRoot(app), "steamui/movies/deck_startup.webm").also { it.parentFile!!.mkdirs(); it.writeText("movie") }
|
||||
val entry = BootMovieLibrary.list(app).first { it.id == "steam:/movies/deck_startup.webm" }
|
||||
assertFalse(entry.removable)
|
||||
assertFalse(BootMovieLibrary.remove(app, entry.id))
|
||||
assertTrue(own.exists())
|
||||
}
|
||||
|
||||
@Test fun anImportSurvivesTheRuntimeBeingReset() {
|
||||
val name = imported("Keep")
|
||||
movies.deleteRecursively()
|
||||
assertTrue(BootMovieLibrary.list(app).any { it.id == "file:$name" })
|
||||
assertTrue(File(movies, name).isFile)
|
||||
}
|
||||
|
||||
@Test fun importsAtTheSameTimeAllLandInTheList() {
|
||||
val names = java.util.Collections.synchronizedList(ArrayList<String>())
|
||||
(1..8).map { n -> Thread { names.add(imported("Movie")) } }.onEach { it.start() }.forEach { it.join() }
|
||||
assertEquals(8, names.toSet().size)
|
||||
assertEquals(8, BootMovieLibrary.list(app).count { it.source == BootMovieLibrary.SOURCE_IMPORT })
|
||||
}
|
||||
|
||||
@Test fun steamIsPointedBackAtItsDefaultWhenTheStagedMovieIsGone() {
|
||||
steamPicksAt(SessionFiles.BOOT_MOVIE_PATH)
|
||||
assertTrue(SessionFiles.resetMissingStartupMovie(BootMovieLibrary.steamConfig(app), false))
|
||||
assertNull(SessionFiles.startupMoviePath(BootMovieLibrary.steamConfig(app)))
|
||||
}
|
||||
|
||||
@Test fun aMissingConfigNeedsNoReset() {
|
||||
assertTrue(SessionFiles.resetMissingStartupMovie(BootMovieLibrary.steamConfig(app), true))
|
||||
}
|
||||
|
||||
@Test fun aStagedMovieThatIsThereIsLeftAlone() {
|
||||
movie("bigpicture_startup.webm")
|
||||
steamPicksAt(SessionFiles.BOOT_MOVIE_PATH)
|
||||
assertFalse(SessionFiles.resetMissingStartupMovie(BootMovieLibrary.steamConfig(app), false))
|
||||
assertEquals(SessionFiles.BOOT_MOVIE_PATH, SessionFiles.startupMoviePath(BootMovieLibrary.steamConfig(app)))
|
||||
}
|
||||
|
||||
@Test fun aPendingPickResetsASteamMovieThatWasRemoved() {
|
||||
steamPicksAt("/uioverrides/movies/gone.webm")
|
||||
assertFalse(SessionFiles.resetMissingStartupMovie(BootMovieLibrary.steamConfig(app), false))
|
||||
assertTrue(SessionFiles.resetMissingStartupMovie(BootMovieLibrary.steamConfig(app), true))
|
||||
assertNull(SessionFiles.startupMoviePath(BootMovieLibrary.steamConfig(app)))
|
||||
}
|
||||
|
||||
@Test fun onlyTheThreeStartupMoviesOfSteamAreListed() {
|
||||
listOf("deck_startup", "oled_startup", "startup_machine", "controller_generic_thumbstick_move").forEach {
|
||||
File(BootMovieLibrary.steamRoot(app), "steamui/movies/$it.webm").also { f -> f.parentFile!!.mkdirs(); f.writeText("movie") }
|
||||
}
|
||||
val ids = BootMovieLibrary.list(app).map { it.id }.filter { it.startsWith("steam:") }
|
||||
assertEquals(
|
||||
listOf("steam:/movies/deck_startup.webm", "steam:/movies/oled_startup.webm", "steam:/movies/startup_machine.webm"),
|
||||
ids.sorted(),
|
||||
)
|
||||
}
|
||||
|
||||
@Test fun aMovieBoughtInThePointsShopIsListedAndAdopted() {
|
||||
val file = File(BootMovieLibrary.steamRoot(app), "appcache/startupmovies/Bought.webm").also { it.parentFile!!.mkdirs(); it.writeText("movie") }
|
||||
val entry = BootMovieLibrary.list(app).first { it.id == "steam:/appcache/startupmovies/Bought.webm" }
|
||||
assertFalse(entry.removable)
|
||||
assertEquals(BootMovieLibrary.SOURCE_POINTSHOP, entry.source)
|
||||
steamPicksAt("/appcache/startupmovies/Bought.webm")
|
||||
assertTrue(BootMovie.syncFromSteam(app))
|
||||
assertEquals("steam:/appcache/startupmovies/Bought.webm", BootMovie.choice(app))
|
||||
assertEquals(file, BootMovie.currentFile(app))
|
||||
assertNull(BootMovieLibrary.file(app, "steam:/../x.webm"))
|
||||
}
|
||||
|
||||
@Test fun aBoughtMovieNamedByIdAndHashIsShownByItsId() {
|
||||
File(BootMovieLibrary.steamRoot(app), "appcache/startupmovies/39900045022_590371b7f10882d09ac59e5d3691b462c0091a6d.webm")
|
||||
.also { it.parentFile!!.mkdirs(); it.writeText("movie") }
|
||||
val entry = BootMovieLibrary.list(app).first { it.source == BootMovieLibrary.SOURCE_POINTSHOP }
|
||||
assertEquals("#39900045022", entry.title)
|
||||
}
|
||||
|
||||
@Test fun theReportNamesWhatStageDidAndWhereMoviesAre() {
|
||||
File(BootMovieLibrary.steamRoot(app), "appcache/startupmovies/1_ab.webm").also { it.parentFile!!.mkdirs(); it.writeText("movie") }
|
||||
BootMovieReport.note(app, "stage test")
|
||||
val report = BootMovieReport.build(app)
|
||||
assertTrue(report.contains("== DroidDeck state"))
|
||||
assertTrue(report.contains("startupmovies/1_ab.webm"))
|
||||
assertTrue(report.contains("stage test"))
|
||||
}
|
||||
|
||||
@Test fun pathTricksAreNotMovies() {
|
||||
movie("a.webm")
|
||||
assertNull(BootMovieLibrary.file(app, "file:../a.webm"))
|
||||
assertNull(BootMovieLibrary.file(app, "file:bigpicture_startup.webm"))
|
||||
assertFalse(BootMovieLibrary.remove(app, "file:../a.webm"))
|
||||
}
|
||||
|
||||
@Test fun freeNameNeverReusesAFileOrAStagedName() {
|
||||
movie("Intro.webm")
|
||||
assertEquals("Intro (2).webm", BootMovieLibrary.freeName(app, "Intro"))
|
||||
assertEquals("movie.webm", BootMovieLibrary.freeName(app, "///"))
|
||||
}
|
||||
|
||||
@Test fun aMovieChosenInsideSteamIsAdoptedOnce() {
|
||||
movie("a.webm"); movie("b.webm")
|
||||
BootMovie.select(app, "file:a.webm")
|
||||
steamPicks("b.webm")
|
||||
assertTrue(BootMovie.syncFromSteam(app))
|
||||
assertEquals("file:b.webm", BootMovie.choice(app))
|
||||
// Picking another one here is not undone by the same Steam setting.
|
||||
BootMovie.select(app, "file:a.webm")
|
||||
assertFalse(BootMovie.syncFromSteam(app))
|
||||
assertEquals("file:a.webm", BootMovie.choice(app))
|
||||
// A new pick inside Steam is adopted again.
|
||||
movie("c.webm")
|
||||
steamPicks("c.webm")
|
||||
assertTrue(BootMovie.syncFromSteam(app))
|
||||
assertEquals("file:c.webm", BootMovie.choice(app))
|
||||
}
|
||||
|
||||
@Test fun aSteamPickIsTakenOverWithoutBeingStagedOverSteamsOwnSetting() {
|
||||
movie("a.webm")
|
||||
BootMovie.select(app, "file:a.webm")
|
||||
SessionPrefs.setBootMovieApplyNext(app, false)
|
||||
steamPicks("a.webm")
|
||||
assertFalse(BootMovie.syncFromSteam(app))
|
||||
assertEquals("file:a.webm", BootMovie.choice(app))
|
||||
assertFalse(SessionPrefs.bootMovieApplyNext(app))
|
||||
}
|
||||
|
||||
@Test fun theStagedCopyNamedInSteamsConfigIsNotAPick() {
|
||||
movie("a.webm")
|
||||
BootMovie.select(app, "file:a.webm")
|
||||
steamPicksAt(SessionFiles.BOOT_MOVIE_PATH)
|
||||
assertFalse(BootMovie.syncFromSteam(app))
|
||||
assertEquals("file:a.webm", BootMovie.choice(app))
|
||||
}
|
||||
|
||||
@Test fun aBoughtMovieIsShownUnderItsPointsShopTitle() {
|
||||
File(BootMovieLibrary.steamRoot(app), "config/communityitemscache/startupmovies/39900045022_ab12.webm")
|
||||
.also { it.parentFile!!.mkdirs(); it.writeText("movie") }
|
||||
File(BootMovieLibrary.steamRoot(app), "userdata/1/config/localconfig.vdf").also { it.parentFile!!.mkdirs() }.writeText(
|
||||
"\"GetStartupMovies\"\t\t\"[{\\\"communityitemid\\\":\\\"39900045022\\\",\\\"image_small\\\":\\\"x.png\\\",\\\"name\\\":\\\"Turret Factory\\\",\\\"item_title\\\":\\\"Turret Factory\\\"}]\"\n",
|
||||
)
|
||||
val entry = BootMovieLibrary.list(app).first { it.source == BootMovieLibrary.SOURCE_POINTSHOP }
|
||||
assertEquals("Turret Factory", entry.title)
|
||||
}
|
||||
|
||||
@Test fun notesKeptInSteamsMoviesFolderByAnEarlierVersionAreTakenOver() {
|
||||
movie("Old.webm")
|
||||
File(movies, ".droiddeck-movies.json").writeText("{\"Old.webm\":{\"title\":\"Old one\",\"source\":\"repo\",\"repo\":\"r1\"}}")
|
||||
val entry = BootMovieLibrary.list(app).first { it.id == "file:Old.webm" }
|
||||
assertEquals("Old one", entry.title)
|
||||
assertEquals(BootMovieLibrary.SOURCE_REPO, entry.source)
|
||||
assertEquals(setOf("r1"), BootMovieLibrary.installedRepoIds(app))
|
||||
assertFalse(File(movies, ".droiddeck-movies.json").exists())
|
||||
}
|
||||
|
||||
@Test fun aPickMadeHereBeatsAnOlderSteamPickThatWasNeverSeen() {
|
||||
movie("a.webm"); movie("b.webm")
|
||||
steamPicks("b.webm")
|
||||
BootMovie.select(app, "file:a.webm")
|
||||
assertFalse(BootMovie.syncFromSteam(app))
|
||||
assertEquals("file:a.webm", BootMovie.choice(app))
|
||||
}
|
||||
|
||||
@Test fun steamPointingAtAMovieThatIsNotThereChangesNothing() {
|
||||
steamPicks("gone.webm")
|
||||
assertFalse(BootMovie.syncFromSteam(app))
|
||||
assertEquals(BootMovie.DROIDDECK_30, BootMovie.choice(app))
|
||||
}
|
||||
|
||||
@Test fun volumeAndLengthDefaultToTheWholeMovieAtFullVolume() {
|
||||
assertEquals(100, SessionPrefs.bootMovieVolume(app))
|
||||
assertEquals(0, SessionPrefs.bootMovieSeconds(app))
|
||||
SessionPrefs.setBootMovieVolume(app, 40)
|
||||
SessionPrefs.setBootMovieSeconds(app, 3)
|
||||
assertEquals(40, SessionPrefs.bootMovieVolume(app))
|
||||
assertEquals(3, SessionPrefs.bootMovieSeconds(app))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
import com.droiddeck.launcher.session.BootMovie.Step
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
class BootMoviePlanTest {
|
||||
@Test
|
||||
fun fullVolumeWithoutLimitPassesTheSourceThrough() {
|
||||
val plan = BootMovie.plan(100, 0)
|
||||
assertTrue(plan.passthrough)
|
||||
assertTrue(plan.steps.isEmpty())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun fullVolumeWithLimitKeepsSoundAndFallsBackToTheSource() {
|
||||
val plan = BootMovie.plan(100, 5)
|
||||
assertFalse(plan.passthrough)
|
||||
assertEquals(listOf(Step.REMUX_AUDIO, Step.TRANSCODE_AUDIO), plan.steps)
|
||||
assertTrue(plan.sourceOnFailure)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun silentGoesWithoutSoundAndNeverFallsBackToTheSource() {
|
||||
val plan = BootMovie.plan(0, 0)
|
||||
assertEquals(listOf(Step.REMUX_SILENT, Step.TRANSCODE_SILENT), plan.steps)
|
||||
assertFalse(plan.sourceOnFailure)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun partialVolumeDegradesToSilenceNotToFullVolume() {
|
||||
val plan = BootMovie.plan(40, 0)
|
||||
assertEquals(listOf(Step.REGAIN, Step.REMUX_SILENT, Step.TRANSCODE_AUDIO), plan.steps)
|
||||
assertFalse(plan.passthrough)
|
||||
assertFalse(plan.sourceOnFailure)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun framesBeyondFullHdAreOversizedInEitherOrientation() {
|
||||
assertTrue(BootMovie.oversized(3840, 2160))
|
||||
assertTrue(BootMovie.oversized(2160, 3840))
|
||||
assertFalse(BootMovie.oversized(1920, 1080))
|
||||
assertFalse(BootMovie.oversized(1280, 800))
|
||||
assertFalse(BootMovie.oversized(1080, 1920))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun anOversizedMovieIsAlwaysConvertedAndNeverFallsBackToTheSource() {
|
||||
for (volume in listOf(0, 40, 100)) {
|
||||
val plan = BootMovie.oversizedPlan(volume)
|
||||
assertFalse(plan.passthrough)
|
||||
assertFalse(plan.sourceOnFailure)
|
||||
}
|
||||
assertEquals(listOf(Step.TRANSCODE_SILENT), BootMovie.oversizedPlan(0).steps)
|
||||
assertEquals(listOf(Step.TRANSCODE_AUDIO), BootMovie.oversizedPlan(60).steps)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertSame
|
||||
import org.junit.Test
|
||||
|
||||
class BootMovieTranscoderTest {
|
||||
@Test fun scaleQuietsAndCutsTheSoundAtTheSameTime() {
|
||||
val pcm = ShortArray(48_000 * 2) { 1000 }
|
||||
assertSame(pcm, BootMovieTranscoder.scale(pcm, 2, 1f, Long.MAX_VALUE))
|
||||
val quieter = BootMovieTranscoder.scale(pcm, 2, 0.5f, Long.MAX_VALUE)
|
||||
assertEquals(pcm.size, quieter.size)
|
||||
assertEquals(500.toShort(), quieter[0])
|
||||
val cut = BootMovieTranscoder.scale(pcm, 2, 1f, 500_000L)
|
||||
assertEquals(24_000 * 2, cut.size)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.TemporaryFolder
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
import java.io.File
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [33])
|
||||
class StartupMovieConfigTest {
|
||||
@get:Rule val folder = TemporaryFolder()
|
||||
|
||||
private val older = "\t\t\t\t\"StartupMovie\"\n\t\t\t\t{\n\t\t\t\t\t\"MovieID\"\t\t\"0\"\n\t\t\t\t\t\"LocalPath\"\t\t\"%s\"\n\t\t\t\t}\n"
|
||||
private val customization = "\t\"Customization\"\n\t{\n\t\t\"StartupMovie\"\n\t\t{\n\t\t\t\"MovieID\"\t\t\"%s\"\n\t\t\t\"LocalPath\"\t\t\"%s\"\n\t\t}\n\t}\n"
|
||||
|
||||
private fun config(olderPath: String?, id: String?, path: String?): File {
|
||||
val text = StringBuilder("\"InstallConfigStore\"\n{\n\t\"Software\"\n\t{\n\t\t\"Valve\"\n\t\t{\n\t\t\t\"Steam\"\n\t\t\t{\n")
|
||||
if (olderPath != null) text.append(older.format(olderPath))
|
||||
text.append("\t\t\t}\n\t\t}\n\t}\n")
|
||||
if (id != null && path != null) text.append(customization.format(id, path))
|
||||
text.append("}\n")
|
||||
return folder.newFile().also { it.writeText(text.toString()) }
|
||||
}
|
||||
|
||||
@Test fun steamReadsTheMovieUnderCustomizationNotTheOlderOne() {
|
||||
val file = config(SessionFiles.BOOT_MOVIE_PATH, "39900045022", "/communityitemscache/startupmovies/39900045022_ab.webm")
|
||||
assertEquals("/communityitemscache/startupmovies/39900045022_ab.webm", SessionFiles.startupMoviePath(file))
|
||||
}
|
||||
|
||||
@Test fun aPickIsWrittenWhereSteamReadsItAndTheOlderPlaceIsKeptInStep() {
|
||||
val file = config("/uioverrides/movies/x.webm", "39900045022", "/communityitemscache/startupmovies/39900045022_ab.webm")
|
||||
assertTrue(SessionFiles.ensureStartupMovieDefault(file, force = true))
|
||||
val text = file.readText()
|
||||
assertEquals(SessionFiles.BOOT_MOVIE_PATH, SessionFiles.startupMoviePath(file))
|
||||
assertFalse(text.contains("39900045022"))
|
||||
assertEquals(2, Regex("\"LocalPath\"\\s+\"" + Regex.escape(SessionFiles.BOOT_MOVIE_PATH) + "\"").findAll(text).count())
|
||||
}
|
||||
|
||||
@Test fun aPickMadeInSteamIsLeftAloneWithoutAPendingPick() {
|
||||
val file = config(SessionFiles.BOOT_MOVIE_PATH, "0", "/uioverrides/movies/Undertale.webm")
|
||||
assertFalse(SessionFiles.ensureStartupMovieDefault(file, force = false))
|
||||
assertEquals("/uioverrides/movies/Undertale.webm", SessionFiles.startupMoviePath(file))
|
||||
}
|
||||
|
||||
@Test fun aConfigWithoutCustomizationGetsOne() {
|
||||
val file = config(null, null, null)
|
||||
assertTrue(SessionFiles.ensureStartupMovieDefault(file, force = false))
|
||||
val text = file.readText()
|
||||
assertTrue(text.contains("\"Customization\""))
|
||||
assertEquals(SessionFiles.BOOT_MOVIE_PATH, SessionFiles.startupMoviePath(file))
|
||||
assertEquals(2, Regex("\"StartupMovie\"").findAll(text).count())
|
||||
}
|
||||
|
||||
@Test fun aMissingStagedMovieResetsTheSectionSteamReads() {
|
||||
val file = config(SessionFiles.BOOT_MOVIE_PATH, "0", SessionFiles.BOOT_MOVIE_PATH)
|
||||
assertTrue(SessionFiles.resetMissingStartupMovie(file, false))
|
||||
assertNull(SessionFiles.startupMoviePath(file))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [33])
|
||||
class SteamDeckRepoTest {
|
||||
private val sample = """
|
||||
{"posts":[
|
||||
{"id":"p1","title":"Cool","content":"c","user":{"steam_name":"Ann"},"thumbnail":"https://x/t.png","video":"https://x/v.webm",
|
||||
"video_duration":7,"likes":3,"downloads":9,"devices":["steam_deck"],"url":"https://steamdeckrepo.com/post/p1"},
|
||||
{"id":"p2","title":"","video":"http://insecure/v.webm"},
|
||||
{"id":"","video":"https://x/v.webm"},
|
||||
{"id":"p3","video":"https://x/v3.webm","thumbnail":"ftp://bad"}
|
||||
],"currentSort":"trending"}
|
||||
""".trimIndent()
|
||||
|
||||
@Test fun parsesPostsAndSkipsBrokenOnes() {
|
||||
val posts = SteamDeckRepo.parse(sample)!!
|
||||
assertEquals(listOf("p1", "p3"), posts.map { it.id })
|
||||
val first = posts[0]
|
||||
assertEquals("Cool", first.title)
|
||||
assertEquals("Ann", first.author)
|
||||
assertEquals(7, first.seconds)
|
||||
assertEquals(listOf("steam_deck"), first.devices)
|
||||
assertEquals("p3", posts[1].title)
|
||||
assertEquals("", posts[1].thumbnail)
|
||||
}
|
||||
|
||||
@Test fun notJsonIsNotAPage() {
|
||||
assertNull(SteamDeckRepo.parse("<html>"))
|
||||
assertNull(SteamDeckRepo.parse("{}"))
|
||||
}
|
||||
|
||||
@Test fun buildsTheSameAddressesAsTheWebsite() {
|
||||
assertEquals("https://steamdeckrepo.com/api/posts?sort=trending", SteamDeckRepo.url(SteamDeckRepo.Sort.TRENDING, null, ""))
|
||||
assertEquals(
|
||||
"https://steamdeckrepo.com/api/posts?sort=downloads-desc&device=steam_machine&search=a%20b%26c&page=3",
|
||||
SteamDeckRepo.url(SteamDeckRepo.Sort.DOWNLOADS, "steam_machine", " a b&c ", 3),
|
||||
)
|
||||
}
|
||||
|
||||
@Test fun readsAreCutOffAtTheLimit() {
|
||||
assertEquals(10, SteamDeckRepo.readLimited(ByteArray(10).inputStream(), 10)!!.size)
|
||||
assertNull(SteamDeckRepo.readLimited(ByteArray(11).inputStream(), 10))
|
||||
}
|
||||
|
||||
@Test fun jsonNullsAreEmptyTextNotTheWordNull() {
|
||||
val posts = SteamDeckRepo.parse(
|
||||
"""{"posts":[{"id":"p9","title":null,"content":null,"user":{"steam_name":null},"thumbnail":null,"video":"https://x/v.webm","url":null}]}""",
|
||||
)!!
|
||||
val post = posts.single()
|
||||
assertEquals("p9", post.title)
|
||||
assertEquals("", post.content)
|
||||
assertEquals("", post.author)
|
||||
assertEquals("", post.thumbnail)
|
||||
assertEquals("", post.url)
|
||||
assertTrue(SteamDeckRepo.parse("""{"posts":[{"id":null,"video":"https://x/v.webm"}]}""")!!.isEmpty())
|
||||
}
|
||||
|
||||
@Test fun aPageHoldsTwelveMovies() {
|
||||
assertEquals(12, SteamDeckRepo.PAGE_SIZE)
|
||||
}
|
||||
|
||||
private fun lastPageOf(pages: Int, tail: Int = SteamDeckRepo.PAGE_SIZE) = SteamDeckRepo.lastPage(SteamDeckRepo.Sort.TRENDING, null, "") { p ->
|
||||
when {
|
||||
p < pages -> SteamDeckRepo.PAGE_SIZE
|
||||
p == pages -> tail
|
||||
else -> 0
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun theLastPageIsFoundByAskingForPages() {
|
||||
for (pages in listOf(2, 3, 7, 8, 9, 33, 100, 500)) assertEquals(pages, lastPageOf(pages))
|
||||
}
|
||||
|
||||
@Test fun aShortLastPageEndsTheSearchAtOnce() {
|
||||
assertEquals(1, lastPageOf(1, tail = 5))
|
||||
assertEquals(5, lastPageOf(5, tail = 3))
|
||||
assertEquals(37, lastPageOf(37, tail = 1))
|
||||
}
|
||||
|
||||
@Test fun aSearchWithNothingHasOnePageAndAnUnreachableSiteHasNone() {
|
||||
assertEquals(1, SteamDeckRepo.lastPage(SteamDeckRepo.Sort.TRENDING, null, "x") { 0 })
|
||||
assertNull(SteamDeckRepo.lastPage(SteamDeckRepo.Sort.TRENDING, null, "x") { null })
|
||||
assertNull(SteamDeckRepo.lastPage(SteamDeckRepo.Sort.TRENDING, null, "x") { p -> if (p < 4) SteamDeckRepo.PAGE_SIZE else null })
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user