mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-19 04:46:08 +00:00
Merge main into Steam client download PR
This commit is contained in:
commit
c8cc17bf3a
491 files changed
+34864
-2441
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,73 @@
|
||||
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.Test
|
||||
|
||||
class ComponentsNightlyCatalogTest {
|
||||
@Test
|
||||
fun nightlyFilesGoToTheirComponentList() {
|
||||
val n = ComponentsManager.DD_NIGHTLY
|
||||
assertEquals("dxvk", ComponentsManager.assetComp(n, "DD-dxvk-3.1.1+153-nightly.wcp"))
|
||||
assertEquals("dxvk", ComponentsManager.assetComp(n, "DD-dxvk-arm64ec-3.1.1+153-nightly.wcp"))
|
||||
assertEquals("dxvk", ComponentsManager.assetComp(n, "DD-dxvk-gplasync-3.1.1+153-nightly.wcp"))
|
||||
assertEquals("vkd3d", ComponentsManager.assetComp(n, "DD-vkd3d-proton-arm64ec-3.0.1+455-nightly.wcp"))
|
||||
assertEquals("fex", ComponentsManager.assetComp(n, "DD-FEXCore-2610+58-nightly.wcp"))
|
||||
assertNull(ComponentsManager.assetComp(n, "state.json"))
|
||||
assertNull(ComponentsManager.assetComp(n, "something-else.wcp"))
|
||||
assertEquals("dxvk", ComponentsManager.assetComp("Dxvk-gplasync-Linux", "dxvk-gplasync-3.1.1-1-linux.wcp"))
|
||||
assertNull(ComponentsManager.assetComp("Unknown-Release", "dxvk-3.1.1-linux.wcp"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun nightliesListBelowTheStablePackages() {
|
||||
fun item(file: String, release: String) = ComponentsManager.CatalogItem(file, "dxvk", release, "", 0, "")
|
||||
val sorted = listOf(
|
||||
item("DD-dxvk-3.1.1+153-nightly.wcp", ComponentsManager.DD_NIGHTLY),
|
||||
item("dxvk-2.7.1-linux.wcp", "Dxvk-Linux"),
|
||||
item("dxvk-3.1.1-linux.wcp", "Dxvk-Linux"),
|
||||
).sortedWith(ComponentsManager.CATALOG_ORDER).map { it.file }
|
||||
assertEquals(listOf("dxvk-3.1.1-linux.wcp", "dxvk-2.7.1-linux.wcp", "DD-dxvk-3.1.1+153-nightly.wcp"), sorted)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun nightliesPairWithTheStableOfTheSameFlavorAndVersion() {
|
||||
val n = ComponentsManager.DD_NIGHTLY
|
||||
fun item(file: String, comp: String, release: String) = ComponentsManager.CatalogItem(file, comp, release, "", 0, "")
|
||||
val dxvk = item("dxvk-3.1.1-linux.wcp", "dxvk", "Dxvk-Linux")
|
||||
val ec = item("dxvk-arm64ec-3.1.1-linux.wcp", "dxvk", "Dxvk-arm64ec-Linux")
|
||||
val gpl = item("dxvk-gplasync-3.1.1-1-linux.wcp", "dxvk", "Dxvk-gplasync-Linux")
|
||||
val fex = item("FEXCore-2610-linux.wcp", "fex", "FexCore-Linux")
|
||||
val vk = item("vkd3d-proton-3.0.1-linux.wcp", "vkd3d", "Vkd3d-proton-Linux")
|
||||
val others = listOf(
|
||||
item("dxvk-low-latency-3.1.1-2-linux.wcp", "dxvk", "Dxvk-Linux"),
|
||||
item("dxvk-3.1-linux.wcp", "dxvk", "Dxvk-Linux"),
|
||||
item("dxvk-gplasync-3.1-1-linux.wcp", "dxvk", "Dxvk-gplasync-Linux"),
|
||||
item("FEXCore-2610-d2rfix28-linux.wcp", "fex", "FexCore-Linux"),
|
||||
)
|
||||
val nDxvk = item("DD-dxvk-3.1.1+153-nightly.wcp", "dxvk", n)
|
||||
val nEc = item("DD-dxvk-arm64ec-3.1.1+153-nightly.wcp", "dxvk", n)
|
||||
val nGpl = item("DD-dxvk-gplasync-3.1.1+153-nightly.wcp", "dxvk", n)
|
||||
val nFex = item("DD-FEXCore-2610+58-nightly.wcp", "fex", n)
|
||||
val nVk = item("DD-vkd3d-proton-3.0.1+455-nightly.wcp", "vkd3d", n)
|
||||
val nVkEc = item("DD-vkd3d-proton-arm64ec-3.0.1+455-nightly.wcp", "vkd3d", n)
|
||||
val pairs = ComponentsManager.nightlyPairs(listOf(dxvk, ec, gpl, fex, vk) + others + listOf(nDxvk, nEc, nGpl, nFex, nVk, nVkEc))
|
||||
assertEquals(mapOf(dxvk to nDxvk, ec to nEc, gpl to nGpl, fex to nFex, vk to nVk), pairs)
|
||||
// Two nightlies for one stable build: the newer one wins.
|
||||
val nDxvkNewer = item("DD-dxvk-3.1.1+154-nightly.wcp", "dxvk", n)
|
||||
assertEquals(mapOf(dxvk to nDxvkNewer), ComponentsManager.nightlyPairs(listOf(dxvk, nDxvkNewer, nDxvk)))
|
||||
assertEquals(mapOf(dxvk to nDxvkNewer), ComponentsManager.nightlyPairs(listOf(dxvk, nDxvk, nDxvkNewer)))
|
||||
// A nightly of a version with no stable build pairs with nothing.
|
||||
assertEquals(emptyMap<Any, Any>(), ComponentsManager.nightlyPairs(listOf(item("dxvk-3.1-linux.wcp", "dxvk", "Dxvk-Linux"), nDxvk)))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun downloadsOnlyFromTheTwoRepositories() {
|
||||
assertTrue(ComponentsManager.allowedDownload("https://github.com/The412Banner/Nightlies/releases/download/Dxvk-Linux/dxvk-3.1.1-linux.wcp"))
|
||||
assertTrue(ComponentsManager.allowedDownload("https://github.com/Droid-Deck/DroidDeck-Components/releases/download/linux-nightly/DD-FEXCore-2610+58-nightly.wcp"))
|
||||
assertFalse(ComponentsManager.allowedDownload("https://github.com/someone/else/releases/download/x/y.wcp"))
|
||||
assertFalse(ComponentsManager.allowedDownload("https://github.com/Droid-Deck/DroidDeck-Components-evil/releases/download/x/y.wcp"))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
import com.droiddeck.launcher.input.FakeInputWriter
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
class InputSysfsComponentTest {
|
||||
@Test fun steamInputsVirtualPadKeepsItsIdentity() {
|
||||
val pad = InputSysfsComponent.virtualPad("PRODUCT=3/28de/11ff/1\nNAME=\"Microsoft X-Box 360 pad 0\"\nPHYS=\"\"\n")!!
|
||||
assertEquals(listOf(3, 0x28de, 0x11ff, 1), listOf(pad.bus, pad.vendor, pad.product, pad.version))
|
||||
assertEquals("Microsoft X-Box 360 pad 0", pad.name)
|
||||
assertEquals("", pad.phys)
|
||||
assertTrue(pad.uevent().startsWith("PRODUCT=3/28de/11ff/1\nNAME=\"Microsoft X-Box 360 pad 0\"\n"))
|
||||
}
|
||||
|
||||
@Test fun anUnreadableDescriptionIsNotListed() {
|
||||
assertNull(InputSysfsComponent.virtualPad(""))
|
||||
assertNull(InputSysfsComponent.virtualPad("PRODUCT=3/28de\nNAME=\"pad\"\n"))
|
||||
assertNull(InputSysfsComponent.virtualPad("PRODUCT=3/28de/11ff/1\n"))
|
||||
}
|
||||
|
||||
@Test fun ringPadsMatchWhatTheirIoctlsAnswer() {
|
||||
val xbox = InputSysfsComponent.ringPad(1, steamVirtual = false)
|
||||
assertEquals("Xbox 360 Controller (1)", xbox.name)
|
||||
assertEquals(listOf(0x045e, 0x028e, 0x110), listOf(xbox.vendor, xbox.product, xbox.version))
|
||||
val steam = InputSysfsComponent.ringPad(0, steamVirtual = true)
|
||||
assertEquals("Microsoft X-Box 360 pad 0", steam.name)
|
||||
assertEquals(listOf(0x28de, 0x11ff), listOf(steam.vendor, steam.product))
|
||||
}
|
||||
|
||||
@Test fun ringPadsAreHiddenWhereGamesCannotOpenThem() {
|
||||
assertFalse(InputSysfsComponent.ringWithdrawn(deckPad = false, type = FakeInputWriter.PAD_TYPE_DECK))
|
||||
assertFalse(InputSysfsComponent.ringWithdrawn(deckPad = true, type = FakeInputWriter.PAD_TYPE_XBOX))
|
||||
assertTrue(InputSysfsComponent.ringWithdrawn(deckPad = true, type = FakeInputWriter.PAD_TYPE_DECK))
|
||||
assertTrue(InputSysfsComponent.ringWithdrawn(deckPad = true, type = -1))
|
||||
}
|
||||
|
||||
@Test fun onlyThePadsOwnUdevRecordsAreCleared() {
|
||||
assertTrue(InputSysfsComponent.isPadRecord("c13:64"))
|
||||
assertTrue(InputSysfsComponent.isPadRecord("c13:80"))
|
||||
assertTrue(InputSysfsComponent.isPadRecord("+input:input16"))
|
||||
assertFalse(InputSysfsComponent.isPadRecord("c13:63"))
|
||||
assertFalse(InputSysfsComponent.isPadRecord("c13:128"))
|
||||
assertFalse(InputSysfsComponent.isPadRecord("c240:16"))
|
||||
assertFalse(InputSysfsComponent.isPadRecord("+input:input64"))
|
||||
}
|
||||
|
||||
@Test fun theUdevRecordMarksAnInitializedJoystick() {
|
||||
val record = InputSysfsComponent.udevRecord(42).lines()
|
||||
assertEquals("I:42", record.first())
|
||||
assertTrue("E:ID_INPUT_JOYSTICK=1" in record)
|
||||
assertTrue("E:ID_INPUT=1" in record)
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,7 @@ class OrientationTest {
|
||||
}
|
||||
|
||||
@Test fun landscapeChoicesPersistGloballyAndCanRestoreAutomaticRotation() {
|
||||
assertEquals(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE, SessionPrefs.orientation(context))
|
||||
assertEquals(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE, SessionPrefs.orientation(context))
|
||||
for (value in listOf(
|
||||
ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
|
||||
ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE,
|
||||
@@ -34,7 +34,7 @@ class OrientationTest {
|
||||
@Test fun invalidStoredOrientationFallsBackAndInvalidChoicePreservesTheSavedValue() {
|
||||
val prefs = context.getSharedPreferences("session", Context.MODE_PRIVATE)
|
||||
prefs.edit().putInt("orientation", ActivityInfo.SCREEN_ORIENTATION_PORTRAIT).commit()
|
||||
assertEquals(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE, SessionPrefs.orientation(context))
|
||||
assertEquals(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE, SessionPrefs.orientation(context))
|
||||
SessionPrefs.setOrientation(context, ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE)
|
||||
assertThrows(IllegalArgumentException::class.java) {
|
||||
SessionPrefs.setOrientation(context, ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)
|
||||
|
||||
@@ -32,6 +32,35 @@ class SessionLogShareTest {
|
||||
"rules $rules\n" + files.joinToString("") { val f = File(folder, it); "${f.length()}\t${f.lastModified()}\t$it\n" })
|
||||
}
|
||||
|
||||
@Test fun aLogPastTheInMemoryCapIsStillScrubbedIntoTheZip() {
|
||||
val folder = tmp.newFolder("2026-10-18-01-steam")
|
||||
val line = ("x".repeat(1023) + "\n").toByteArray()
|
||||
File(folder, "session.log").outputStream().buffered().use { out ->
|
||||
out.write("$secret\n".toByteArray())
|
||||
repeat(65 * 1024) { out.write(line) }
|
||||
}
|
||||
assertTrue(File(folder, "session.log").length() >= LogRedactor.IN_MEMORY_SCRUB_MAX)
|
||||
val out = zip(folder)
|
||||
assertTrue(out.containsKey("session.log"))
|
||||
assertFalse(out.getValue("session.log").contains(leaked))
|
||||
}
|
||||
|
||||
@Test fun aLogWithANulByteIsScrubbedNotCopiedRaw() {
|
||||
val folder = tmp.newFolder("2026-10-18-02-steam")
|
||||
File(folder, "crash.log").writeBytes(byteArrayOf(0) + "$secret\n".toByteArray())
|
||||
val out = zip(folder)
|
||||
assertTrue(out.containsKey("crash.log"))
|
||||
assertFalse(out.getValue("crash.log").contains(leaked))
|
||||
}
|
||||
|
||||
@Test fun utf16SecretsDoNotEscapeInTheSharedZip() {
|
||||
val folder = tmp.newFolder("2026-10-18-03-steam")
|
||||
File(folder, "crash.log").writeBytes("sessionid=$leaked".toByteArray(Charsets.UTF_16LE))
|
||||
val output = zip(folder).getValue("crash.log")
|
||||
assertFalse(output.replace("\u0000", "").contains(leaked))
|
||||
assertTrue(output.contains("withheld"))
|
||||
}
|
||||
|
||||
@Test fun aRecordedUnchangedFileIsScrubbedAgainOnTheWayIntoTheZip() {
|
||||
val folder = tmp.newFolder("2026-10-06-01-steam")
|
||||
File(folder, "session.log").writeText("$secret\n")
|
||||
|
||||
@@ -40,6 +40,19 @@ class SessionScalingPrefsTest {
|
||||
assertEquals("800x600", SessionPrefs.resolutionChoice(context, "lxqt", 1440 to 1080))
|
||||
}
|
||||
|
||||
@Test fun userAppsTakeTheDesktopResolutionOnceItIsChosen() {
|
||||
val context = RuntimeEnvironment.getApplication()
|
||||
val script = com.droiddeck.launcher.runtime.UserApps.SCRIPT_LAUNCHER
|
||||
assertEquals("steam", SessionPrefs.displayMode(context, "run", script))
|
||||
SessionPrefs.setResolutionChoice(context, "lxqt", SessionDisplay.MATCH_SCREEN)
|
||||
assertEquals("lxqt", SessionPrefs.displayMode(context, "run", script))
|
||||
assertEquals("lxqt", SessionPrefs.displayMode(context, "run", com.droiddeck.launcher.runtime.AppImageManager.LAUNCHER))
|
||||
val choice = SessionPrefs.resolutionChoice(context, SessionPrefs.displayMode(context, "run", script), 1240 to 1080)
|
||||
assertEquals(1240 to 1080, SessionDisplay.resolveChoice(1240 to 1080, choice))
|
||||
assertEquals("steam", SessionPrefs.displayMode(context, "run", "/usr/bin/retroarch"))
|
||||
assertEquals("steam", SessionPrefs.displayMode(context, "steam", script))
|
||||
}
|
||||
|
||||
@Test fun freshSettingsUseTheConcreteDefaultAndCustomSizesAreNormalized() {
|
||||
val context = RuntimeEnvironment.getApplication()
|
||||
assertEquals(SessionDisplay.DEFAULT_RESOLUTION, SessionPrefs.resolutionChoice(context, "steam", 2400 to 1080))
|
||||
|
||||
@@ -0,0 +1,379 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
import java.io.File
|
||||
import java.util.concurrent.AbstractExecutorService
|
||||
import java.util.concurrent.RejectedExecutionException
|
||||
import java.util.concurrent.TimeUnit
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.TemporaryFolder
|
||||
|
||||
class SessionSuspendControllerTest {
|
||||
@get:Rule val temporary = TemporaryFolder()
|
||||
|
||||
@Test fun everyWorkerThreadIsStoppedAfterTheRoot() {
|
||||
for (count in listOf(17, 68)) {
|
||||
val fixture = fixture(count)
|
||||
fixture.controller.freeze { assertTrue(it) }
|
||||
assertTrue(fixture.game.threads.all { it.state == 't' })
|
||||
assertTrue(fixture.signals.count { it.pid == GAME && it.signal == STOP } >= count)
|
||||
assertEquals(ROOT, fixture.signals.first { it.signal == STOP }.pid)
|
||||
assertTrue(fixture.now < 1000)
|
||||
assertEquals(1, fixture.audioSuspends)
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun cpuMustBeStableAcrossTwoCompleteSnapshots() {
|
||||
val fixture = fixture(17)
|
||||
var changes = 0
|
||||
fixture.afterSleep = {
|
||||
if (fixture.game.threads.all { it.state == 't' } && changes < 3) {
|
||||
fixture.game.threads.last().cpu++
|
||||
changes++
|
||||
}
|
||||
}
|
||||
fixture.controller.freeze { assertTrue(it) }
|
||||
assertEquals(3, changes)
|
||||
assertTrue(fixture.signals.count { it.pid == GAME && it.signal == STOP } >= 17)
|
||||
}
|
||||
|
||||
@Test fun reusedTidAndNewThreadMustJoinTheStableInventory() {
|
||||
val fixture = fixture(17)
|
||||
var changed = false
|
||||
fixture.afterSleep = {
|
||||
if (!changed && fixture.game.threads.all { it.state == 't' }) {
|
||||
changed = true
|
||||
fixture.game.threads.last().apply { started++; state = 'S'; cpu = 0 }
|
||||
fixture.game.threads += Task(500, 9000, 'S')
|
||||
}
|
||||
}
|
||||
fixture.controller.freeze { assertTrue(it) }
|
||||
assertTrue(changed)
|
||||
assertTrue(fixture.game.threads.all { it.state == 't' })
|
||||
assertTrue(fixture.signals.count { it.pid == GAME && it.signal == STOP } >= 19)
|
||||
}
|
||||
|
||||
@Test fun zombieLeaderDoesNotHideRunningWorkers() {
|
||||
val fixture = fixture(17)
|
||||
fixture.game.threads.first().state = 'Z'
|
||||
fixture.sync()
|
||||
fixture.controller.freeze { assertTrue(it) }
|
||||
assertEquals('Z', fixture.game.threads.first().state)
|
||||
assertTrue(fixture.game.threads.drop(1).all { it.state == 't' })
|
||||
assertTrue(fixture.signals.count { it.pid == GAME && it.signal == STOP } >= 16)
|
||||
}
|
||||
|
||||
@Test fun lateReparentedTraceeIsDiscoveredAndResumed() {
|
||||
val fixture = fixture(17)
|
||||
val late = Group(600, 1, ROOT, mutableListOf(Task(600, 6000, 'S')))
|
||||
fixture.afterSleep = {
|
||||
if (fixture.root.threads.first().state == 'T' && late !in fixture.groups) fixture.groups += late
|
||||
}
|
||||
fixture.controller.freeze { assertTrue(it) }
|
||||
assertEquals('t', late.threads.first().state)
|
||||
fixture.controller.resume { assertTrue(it) }
|
||||
assertEquals('S', late.threads.first().state)
|
||||
}
|
||||
|
||||
@Test fun descendantHelperKeepsRootStopAndResumeOrdering() {
|
||||
val fixture = fixture(17)
|
||||
val helper = Group(700, ROOT, 0, mutableListOf(Task(700, 7000, 'S')))
|
||||
fixture.groups += helper
|
||||
fixture.helpers += helper.pid
|
||||
fixture.sync()
|
||||
fixture.controller.freeze { assertTrue(it) }
|
||||
val stops = fixture.signals.filter { it.signal == STOP }
|
||||
assertTrue(stops.indexOfFirst { it.pid == ROOT } < stops.indexOfFirst { it.pid == helper.pid })
|
||||
val before = fixture.signals.size
|
||||
fixture.controller.resume { assertTrue(it) }
|
||||
assertEquals(listOf(ROOT, helper.pid, GAME), fixture.signals.drop(before).take(3).map { it.pid })
|
||||
}
|
||||
|
||||
@Test fun retainedHelperDoesNotAdoptAReusedPidOnRefreeze() {
|
||||
val fixture = fixture(17)
|
||||
val helper = Group(700, 9000, 0, mutableListOf(Task(700, 7000, 'S')))
|
||||
fixture.groups += helper
|
||||
fixture.helpers += helper.pid
|
||||
fixture.sync()
|
||||
fixture.controller.freeze { assertTrue(it) }
|
||||
fixture.blockGameContinue = true
|
||||
fixture.controller.resume { assertFalse(it) }
|
||||
helper.threads.first().apply { started++; state = 'S' }
|
||||
fixture.sync()
|
||||
val before = fixture.signals.size
|
||||
fixture.controller.freeze { assertTrue(it) }
|
||||
assertFalse(fixture.signals.drop(before).any { it.pid == helper.pid })
|
||||
}
|
||||
|
||||
@Test fun timeoutRollsBackAllKnownProcessesAndAudio() {
|
||||
val fixture = fixture(17)
|
||||
fixture.neverStop = true
|
||||
fixture.controller.freeze { assertFalse(it) }
|
||||
assertTrue(fixture.now <= 8100)
|
||||
assertEquals(ROOT, fixture.signals.first { it.signal == CONT }.pid)
|
||||
assertTrue(fixture.game.threads.all { it.state == 'S' })
|
||||
assertEquals(1, fixture.audioResumes)
|
||||
}
|
||||
|
||||
@Test fun missingKnownStatCannotBeMistakenForAnExitedProcess() {
|
||||
val fixture = fixture(17)
|
||||
fixture.afterSleep = {
|
||||
if (fixture.root.threads.first().state == 'T') fixture.missingGameStat = true
|
||||
}
|
||||
fixture.controller.freeze { assertFalse(it) }
|
||||
assertEquals(1, fixture.audioResumes)
|
||||
fixture.missingGameStat = false
|
||||
fixture.sync()
|
||||
fixture.controller.resume { assertTrue(it) }
|
||||
assertTrue(fixture.game.threads.all { it.state == 'S' })
|
||||
}
|
||||
|
||||
@Test fun unavailableOrEmptyThreadInventoryCannotReportSuccess() {
|
||||
for (empty in listOf(false, true)) {
|
||||
val fixture = fixture(17)
|
||||
fixture.emptyGameTasks = empty
|
||||
fixture.missingGameTasks = !empty
|
||||
fixture.sync()
|
||||
fixture.controller.freeze { assertFalse(it) }
|
||||
assertEquals(1, fixture.audioResumes)
|
||||
assertTrue(fixture.game.threads.all { it.state == 'S' })
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun disappearingRootFailsAndStillResumesKnownChildren() {
|
||||
val fixture = fixture(17)
|
||||
fixture.afterSleep = {
|
||||
if (fixture.root.threads.first().state == 'T') fixture.rootGone = true
|
||||
}
|
||||
fixture.controller.freeze { assertFalse(it) }
|
||||
assertTrue(fixture.game.threads.all { it.state == 'S' })
|
||||
assertEquals(1, fixture.audioResumes)
|
||||
}
|
||||
|
||||
@Test fun replacementRootIsNeverStoppedOrContinued() {
|
||||
val fixture = fixture(17)
|
||||
var atReplacement = -1
|
||||
fixture.afterSleep = {
|
||||
if (atReplacement < 0 && fixture.root.threads.first().state == 'T') {
|
||||
atReplacement = fixture.signals.size
|
||||
fixture.root.threads.first().apply { started++; state = 'S' }
|
||||
}
|
||||
}
|
||||
fixture.controller.freeze { assertFalse(it) }
|
||||
assertTrue(atReplacement > 0)
|
||||
assertFalse(fixture.signals.drop(atReplacement).any { it.pid == ROOT })
|
||||
assertTrue(fixture.game.threads.all { it.state == 'S' })
|
||||
}
|
||||
|
||||
@Test fun reusedChildPidIsNotContinuedDuringResume() {
|
||||
val fixture = fixture(17)
|
||||
fixture.controller.freeze { assertTrue(it) }
|
||||
fixture.game.threads.first().apply { started++; state = 'S' }
|
||||
fixture.game.parent = 1
|
||||
fixture.game.tracer = 0
|
||||
fixture.sync()
|
||||
val before = fixture.signals.size
|
||||
fixture.controller.resume { assertTrue(it) }
|
||||
assertFalse(fixture.signals.drop(before).any { it.pid == GAME })
|
||||
}
|
||||
|
||||
@Test fun closeCancelsFreezeAndRestoresSavedRootAfterServiceClearsIt() {
|
||||
val executor = QueueExecutor()
|
||||
val fixture = fixture(68, executor)
|
||||
var closed = false
|
||||
var requested = false
|
||||
fixture.afterSleep = {
|
||||
if (!requested && fixture.root.threads.first().state == 'T') {
|
||||
requested = true
|
||||
fixture.rootPid = -1
|
||||
fixture.controller.closeAndResume { closed = true }
|
||||
}
|
||||
}
|
||||
fixture.controller.freeze { assertFalse(it) }
|
||||
executor.drain()
|
||||
assertTrue(closed)
|
||||
assertTrue(executor.isShutdown)
|
||||
assertTrue(fixture.game.threads.all { it.state == 'S' })
|
||||
assertEquals(1, fixture.audioResumes)
|
||||
}
|
||||
|
||||
@Test fun successfulFreezeIsRecheckedAndAudioIsReassertedAfterFailedResume() {
|
||||
val fixture = fixture(17)
|
||||
fixture.controller.freeze { assertTrue(it) }
|
||||
fixture.blockGameContinue = true
|
||||
fixture.controller.resume { assertFalse(it) }
|
||||
assertEquals(1, fixture.audioResumes)
|
||||
fixture.blockGameContinue = false
|
||||
fixture.game.threads.last().state = 'S'
|
||||
fixture.sync()
|
||||
fixture.controller.freeze { assertTrue(it) }
|
||||
assertTrue(fixture.game.threads.all { it.state == 't' })
|
||||
assertEquals(2, fixture.audioSuspends)
|
||||
}
|
||||
|
||||
@Test fun failedRollbackCanBeRefrozenAndAudioIsSuspendedAgain() {
|
||||
val fixture = fixture(17)
|
||||
fixture.neverStop = true
|
||||
fixture.blockGameContinue = true
|
||||
fixture.controller.freeze { assertFalse(it) }
|
||||
fixture.neverStop = false
|
||||
fixture.blockGameContinue = false
|
||||
fixture.controller.freeze { assertTrue(it) }
|
||||
assertTrue(fixture.game.threads.all { it.state == 't' })
|
||||
assertEquals(2, fixture.audioSuspends)
|
||||
assertEquals(1, fixture.audioResumes)
|
||||
}
|
||||
|
||||
@Test fun repeatedFreezeResumeKeepsOriginalRootFirstOrdering() {
|
||||
val fixture = fixture(17)
|
||||
repeat(2) {
|
||||
fixture.controller.freeze { assertTrue(it) }
|
||||
val before = fixture.signals.size
|
||||
fixture.controller.resume { assertTrue(it) }
|
||||
assertEquals(ROOT, fixture.signals.drop(before).first().pid)
|
||||
assertTrue(fixture.game.threads.all { it.state == 'S' })
|
||||
}
|
||||
fixture.controller.freeze { assertTrue(it) }
|
||||
fixture.rootPid = -1
|
||||
var closed = false
|
||||
fixture.controller.closeAndResume { closed = true }
|
||||
assertTrue(closed)
|
||||
assertTrue(fixture.game.threads.all { it.state == 'S' })
|
||||
}
|
||||
|
||||
@Test fun rejectedExecutorDoesNotFreezeOnTheCallingThread() {
|
||||
val executor = QueueExecutor().apply { shutdown() }
|
||||
val fixture = fixture(17, executor)
|
||||
fixture.controller.freeze { assertFalse(it) }
|
||||
assertTrue(fixture.signals.isEmpty())
|
||||
assertEquals(0, fixture.audioSuspends)
|
||||
}
|
||||
|
||||
private fun fixture(count: Int, executor: QueueExecutor = InlineExecutor()) =
|
||||
Fixture(temporary.newFolder(), count, executor)
|
||||
|
||||
private data class Task(val tid: Int, var started: Long, var state: Char, var cpu: Long = 0)
|
||||
private data class Group(val pid: Int, var parent: Int, var tracer: Int, val threads: MutableList<Task>)
|
||||
private data class SentSignal(val pid: Int, val signal: Int)
|
||||
|
||||
private class Fixture(val proc: File, count: Int, executor: QueueExecutor) {
|
||||
val root = Group(ROOT, 9000, 0, mutableListOf(Task(ROOT, 1000, 'S')))
|
||||
val game = Group(GAME, ROOT, ROOT, MutableList(count) { Task(GAME + it, 2000L + it, 'S') })
|
||||
val groups = mutableListOf(root, game)
|
||||
val helpers = mutableListOf<Int>()
|
||||
val signals = mutableListOf<SentSignal>()
|
||||
var rootPid = ROOT
|
||||
var now = 0L
|
||||
var audioSuspends = 0
|
||||
var audioResumes = 0
|
||||
var neverStop = false
|
||||
var blockGameContinue = false
|
||||
var missingGameStat = false
|
||||
var missingGameTasks = false
|
||||
var emptyGameTasks = false
|
||||
var rootGone = false
|
||||
var afterSleep: (() -> Unit)? = null
|
||||
private var continuing = false
|
||||
val controller = SessionSuspendController(
|
||||
{ rootPid }, { helpers }, { audioSuspends++ }, { audioResumes++ },
|
||||
proc, ::signal, ::threadSignal, ::sleep, { now }, executor,
|
||||
)
|
||||
|
||||
init { sync() }
|
||||
|
||||
private fun signal(pid: Int, signal: Int) {
|
||||
signals += SentSignal(pid, signal)
|
||||
val group = groups.first { it.pid == pid }
|
||||
if (signal == STOP) {
|
||||
continuing = false
|
||||
if (pid == ROOT) group.threads.forEach { it.state = 'T' }
|
||||
else group.threads.firstOrNull {
|
||||
it.state !in listOf('T', 't', 'Z', 'X') && !(neverStop && it == game.threads.last())
|
||||
}?.state = 't'
|
||||
} else if (signal == CONT) {
|
||||
continuing = true
|
||||
if (!(pid == GAME && blockGameContinue)) group.threads.forEach { if (it.state != 'Z') it.state = 'S' }
|
||||
}
|
||||
sync()
|
||||
}
|
||||
|
||||
private fun threadSignal(pid: Int, tid: Int, signal: Int) {
|
||||
signals += SentSignal(pid, signal)
|
||||
val task = groups.first { it.pid == pid }.threads.first { it.tid == tid }
|
||||
if (signal == STOP && task.state !in listOf('T', 't', 'Z', 'X') && !(neverStop && task == game.threads.last())) {
|
||||
task.state = 't'
|
||||
}
|
||||
sync()
|
||||
}
|
||||
|
||||
private fun sleep(millis: Long) {
|
||||
now += millis
|
||||
if (root.threads.first().state != 'T' && !continuing) game.threads.forEach {
|
||||
if (it.state != 'Z') { it.state = 'S'; it.cpu++ }
|
||||
}
|
||||
afterSleep?.invoke()
|
||||
sync()
|
||||
}
|
||||
|
||||
fun sync() {
|
||||
for (group in groups) {
|
||||
val dir = File(proc, group.pid.toString())
|
||||
if (group == root && rootGone) { dir.deleteRecursively(); continue }
|
||||
dir.mkdirs()
|
||||
val stat = File(dir, "stat")
|
||||
if (group == game && missingGameStat) stat.delete()
|
||||
else stat.writeText(stat(group, group.threads.first()))
|
||||
File(dir, "status").writeText("TracerPid: ${group.tracer}\n")
|
||||
val taskDir = File(dir, "task")
|
||||
if (group == game && missingGameTasks) { taskDir.deleteRecursively(); continue }
|
||||
taskDir.mkdirs()
|
||||
if (group == game && emptyGameTasks) { taskDir.listFiles().orEmpty().forEach { it.deleteRecursively() }; continue }
|
||||
for (task in group.threads) {
|
||||
val entry = File(taskDir, task.tid.toString()).apply { mkdirs() }
|
||||
File(entry, "stat").writeText(stat(group, task))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun stat(group: Group, task: Task): String {
|
||||
val fields = MutableList(20) { "0" }
|
||||
fields[0] = task.state.toString()
|
||||
fields[1] = group.parent.toString()
|
||||
fields[11] = task.cpu.toString()
|
||||
fields[19] = task.started.toString()
|
||||
return "${task.tid} (fixture (worker)) ${fields.joinToString(" ")}"
|
||||
}
|
||||
}
|
||||
|
||||
private open class QueueExecutor : AbstractExecutorService() {
|
||||
private val queue = ArrayDeque<Runnable>()
|
||||
private var stopped = false
|
||||
override fun execute(command: Runnable) {
|
||||
if (stopped) throw RejectedExecutionException()
|
||||
queue.add(command)
|
||||
}
|
||||
fun drain() { while (queue.isNotEmpty()) queue.removeFirst().run() }
|
||||
override fun shutdown() { stopped = true }
|
||||
override fun shutdownNow(): MutableList<Runnable> {
|
||||
stopped = true
|
||||
return queue.toMutableList().also { queue.clear() }
|
||||
}
|
||||
override fun isShutdown() = stopped
|
||||
override fun isTerminated() = stopped && queue.isEmpty()
|
||||
override fun awaitTermination(timeout: Long, unit: TimeUnit) = isTerminated
|
||||
}
|
||||
|
||||
private class InlineExecutor : QueueExecutor() {
|
||||
override fun execute(command: Runnable) { super.execute(command); drain() }
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val ROOT = 100
|
||||
const val GAME = 200
|
||||
const val STOP = 19
|
||||
const val CONT = 18
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
import android.view.Display
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
@@ -20,6 +21,34 @@ class SessionVisibilityTest {
|
||||
assertFalse(sessionHasVisibleSurface(false, false, false))
|
||||
}
|
||||
|
||||
@Test fun phoneDisplayFollowsTheInteractiveState() {
|
||||
assertTrue(sessionScreenOn(true, true, null))
|
||||
assertFalse(sessionScreenOn(true, false, null))
|
||||
assertFalse(sessionScreenOn(true, false, Display.STATE_ON))
|
||||
}
|
||||
|
||||
@Test fun externalDisplayKeepsTheSessionAwakeWhileThePhoneScreenIsOff() {
|
||||
assertTrue(sessionScreenOn(false, false, Display.STATE_ON))
|
||||
assertTrue(sessionScreenOn(false, false, Display.STATE_ON_SUSPEND))
|
||||
assertTrue(sessionScreenOn(false, false, Display.STATE_VR))
|
||||
}
|
||||
|
||||
@Test fun externalDisplayTurnedOffSuspendsEvenWithThePhoneScreenOn() {
|
||||
assertFalse(sessionScreenOn(false, true, Display.STATE_OFF))
|
||||
assertFalse(sessionScreenOn(false, true, Display.STATE_DOZE))
|
||||
assertFalse(sessionScreenOn(false, true, Display.STATE_DOZE_SUSPEND))
|
||||
}
|
||||
|
||||
@Test fun missingExternalDisplayFallsBackToThePhone() {
|
||||
assertTrue(sessionScreenOn(false, true, null))
|
||||
assertFalse(sessionScreenOn(false, false, null))
|
||||
}
|
||||
|
||||
@Test fun unknownExternalDisplayStateFallsBackToThePhone() {
|
||||
assertTrue(sessionScreenOn(false, true, Display.STATE_UNKNOWN))
|
||||
assertFalse(sessionScreenOn(false, false, Display.STATE_UNKNOWN))
|
||||
}
|
||||
|
||||
@Test fun losingXrVisibilityReturnsToNormalSuspendRules() {
|
||||
assertTrue(sessionHasVisibleSurface(false, false, true))
|
||||
assertFalse(sessionHasVisibleSurface(false, false, false))
|
||||
|
||||
@@ -32,9 +32,14 @@ class SettingsResetTest {
|
||||
SessionPrefs.setHdr(app, SessionService.MODE_DESKTOP, true)
|
||||
SessionPrefs.setResolutionChoice(app, SessionService.MODE_STEAM, "1280x800")
|
||||
SessionPrefs.setGuestHostname(app, "MyDeck")
|
||||
SessionPrefs.setHudShowFps(app, false)
|
||||
SessionPrefs.setHudShowBattery(app, false)
|
||||
SessionPrefs.setHudShowGraph(app, false)
|
||||
SessionPrefs.setHudColor(app, "amber")
|
||||
SessionPrefs.setHudOpacity(app, 40)
|
||||
ControllerPrefs.setOpacity(app, 40)
|
||||
AppUiPrefs.setScale(app, 150)
|
||||
FrameGen.set(app, FrameGen.Mode(FrameGen.ENGINE_WINFG, 3))
|
||||
FrameGen.set(app, FrameGen.Mode(FrameGen.ENGINE_DDFG, 3))
|
||||
prefs("steam_touch").edit().putBoolean("gyro", false).commit()
|
||||
|
||||
assertTrue(SettingsReset.resetAll(app, gameProfiles = false))
|
||||
@@ -45,6 +50,13 @@ class SettingsResetTest {
|
||||
assertFalse(SessionPrefs.hdr(app, SessionService.MODE_DESKTOP))
|
||||
assertFalse(SessionPrefs.resolutionChosen(app, SessionService.MODE_STEAM))
|
||||
assertEquals(SessionPrefs.DEFAULT_GUEST_HOSTNAME, SessionPrefs.guestHostname(app))
|
||||
assertTrue(SessionPrefs.hudShowFps(app))
|
||||
assertTrue(SessionPrefs.hudShowBattery(app))
|
||||
assertTrue(SessionPrefs.hudShowGraph(app))
|
||||
assertEquals(SessionPrefs.HUD_COLOR_MINT, SessionPrefs.hudColor(app))
|
||||
assertEquals(SessionPrefs.HUD_OPACITY_DEFAULT, SessionPrefs.hudOpacity(app))
|
||||
assertEquals("32.4°C", PerfHud.batteryCelsius(324))
|
||||
assertNull(PerfHud.batteryCelsius(0))
|
||||
assertEquals(100, ControllerPrefs.read(app).opacity)
|
||||
assertEquals(AppUiPrefs.DEFAULT_SCALE, AppUiPrefs.scale(app))
|
||||
assertEquals(FrameGen.Mode.OFF.engine, FrameGen.engine(app))
|
||||
|
||||
@@ -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,72 @@
|
||||
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.Test
|
||||
|
||||
class SteamClientSetupFailureTest {
|
||||
private fun find(vararg lines: String) = SteamClientSetupFailure.find(lines.asSequence())
|
||||
|
||||
@Test fun aBlockedDownloadCarriesTheLastCurlError() {
|
||||
val failure = find(
|
||||
"== STEP 12:35:22 checking the Steam client (first run downloads it, ~1-2 min with nothing on screen)",
|
||||
"curl: (7) Failed to connect to client-update.steamstatic.com:443 after 3 ms: Could not connect to server",
|
||||
"curl: (35) Recv failure: Connection reset by peer",
|
||||
"droiddeck-steam-install: no Steam client CDN answered for steam_client_steamdeck_publicbeta_linuxarm64",
|
||||
"== steam: the Steam client could not be set up (status 1)",
|
||||
"[gamescope] [Info] launch: Primary child shut down!",
|
||||
)!!
|
||||
assertTrue(failure.download)
|
||||
assertEquals("curl: (35) Recv failure: Connection reset by peer", failure.curlError)
|
||||
}
|
||||
|
||||
@Test fun aFailureWithoutCurlErrorIsNotCalledADownloadProblem() {
|
||||
val failure = find(
|
||||
"== STEP 12:35:22 checking the Steam client (a first run downloads it)",
|
||||
"== STEP 12:35:30 downloading Steam: bins_linuxarm64_linuxarm64 (2/17)",
|
||||
"error: cannot create /root/.local/share/Steam/ubuntu12_32/steam-runtime.tar.xz",
|
||||
"== steam: the Steam client could not be set up (status 50)",
|
||||
)!!
|
||||
assertFalse(failure.download)
|
||||
assertNull(failure.curlError)
|
||||
}
|
||||
|
||||
@Test fun aReadyClientIsNoFailure() {
|
||||
assertNull(find(
|
||||
"== STEP 12:35:22 checking the Steam client (first run downloads it, ~1-2 min with nothing on screen)",
|
||||
"curl: (35) Recv failure: Connection reset by peer",
|
||||
"== STEP 12:35:40 Steam client ready",
|
||||
))
|
||||
}
|
||||
|
||||
@Test fun onlyTheLatestCheckCounts() {
|
||||
assertNull(find(
|
||||
"== STEP 10:00:00 checking the Steam client (first run downloads it, ~1-2 min with nothing on screen)",
|
||||
"curl: (6) Could not resolve host: client-update.steamstatic.com",
|
||||
"== steam: the Steam client could not be set up (status 1)",
|
||||
"== STEP 10:05:00 checking the Steam client (first run downloads it, ~1-2 min with nothing on screen)",
|
||||
"== STEP 10:06:00 Steam client ready",
|
||||
))
|
||||
val failure = find(
|
||||
"== STEP 10:00:00 checking the Steam client (first run downloads it, ~1-2 min with nothing on screen)",
|
||||
"curl: (6) Could not resolve host: client-update.steamstatic.com",
|
||||
"== steam: the Steam client could not be set up (status 1)",
|
||||
"== STEP 10:05:00 checking the Steam client (first run downloads it, ~1-2 min with nothing on screen)",
|
||||
"== steam: the Steam client could not be set up (status 9)",
|
||||
)!!
|
||||
assertNull(failure.curlError)
|
||||
}
|
||||
|
||||
@Test fun anArm64SyncErrorIsNotBlamedForTheX64Client() {
|
||||
val failure = find(
|
||||
"== STEP 10:00:00 checking the Steam client's arm64 parts (first run downloads them, ~1-2 min)",
|
||||
"curl: (6) Could not resolve host: client-update.steamstatic.com",
|
||||
"== STEP 10:00:05 could not update the arm64 client's parts; the x86-64 client keeps its own web helper",
|
||||
"== STEP 10:00:05 checking the x86-64 Steam client (FEX, experimental; the first run downloads ~2 GB)",
|
||||
"== steam: the Steam client could not be set up (status 3)",
|
||||
)!!
|
||||
assertNull(failure.curlError)
|
||||
}
|
||||
}
|
||||
@@ -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 })
|
||||
}
|
||||
}
|
||||
@@ -57,6 +57,25 @@ class SteamDownloadMonitorTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun readsBoundCardLibrariesFromTheirHostPath() {
|
||||
val root = Files.createTempDirectory("droiddeck-steam-download-").toFile()
|
||||
try {
|
||||
val card = File(root, "card").apply { mkdirs() }
|
||||
File(root, "root/.local/share/Steam/steamapps").apply { mkdirs() }
|
||||
.resolve("libraryfolders.vdf")
|
||||
.writeText("\"libraryfolders\" { \"1\" { \"path\" \"/mnt/droiddeck-sd\" } }")
|
||||
val manifest = manifest(card, "44", downloaded = 10, total = 100, flags = 6)
|
||||
val monitor = SteamDownloadMonitor()
|
||||
val mounts = mapOf("/mnt/droiddeck-sd" to card)
|
||||
|
||||
assertFalse(monitor.poll(root, now = 1_000L, mounts = mounts))
|
||||
manifest.writeText(appManifest(downloaded = 20, total = 100, flags = 6))
|
||||
assertTrue(monitor.poll(root, now = 3_000L, mounts = mounts))
|
||||
} finally {
|
||||
root.deleteRecursively()
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun followsSteamContentActivityWhenManifestProgressIsNotFlushed() {
|
||||
val root = Files.createTempDirectory("droiddeck-steam-download-").toFile()
|
||||
try {
|
||||
|
||||
Reference in new issue
Block a user