mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-20 05:16:01 +00:00
Merge origin/main into feat/malibridge-v25
This commit is contained in:
commit
a2a5f84711
132 files changed
+7212
-156
No files matched your search
@@ -0,0 +1,22 @@
|
||||
package com.droiddeck.launcher
|
||||
|
||||
import com.droiddeck.launcher.HomeApp.RecentsStep
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
|
||||
class HomeRecentsTest {
|
||||
@Test fun theLauncherHidesAVisibleTaskAndTakesItOver() {
|
||||
assertEquals(RecentsStep.HIDE, HomeApp.recentsStep(hidden = true, owned = false, excluded = false))
|
||||
}
|
||||
|
||||
@Test fun aTaskSomeoneElseExcludedIsNeverClaimedOrShown() {
|
||||
assertEquals(RecentsStep.NONE, HomeApp.recentsStep(hidden = true, owned = false, excluded = true))
|
||||
assertEquals(RecentsStep.NONE, HomeApp.recentsStep(hidden = false, owned = false, excluded = true))
|
||||
}
|
||||
|
||||
@Test fun onlyATaskTheLauncherHidItselfIsShownAgain() {
|
||||
assertEquals(RecentsStep.SHOW, HomeApp.recentsStep(hidden = false, owned = true, excluded = true))
|
||||
assertEquals(RecentsStep.FORGET, HomeApp.recentsStep(hidden = false, owned = true, excluded = false))
|
||||
assertEquals(RecentsStep.NONE, HomeApp.recentsStep(hidden = true, owned = true, excluded = true))
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,9 @@ package com.droiddeck.launcher.core
|
||||
|
||||
import android.content.Context
|
||||
import androidx.test.core.app.ApplicationProvider
|
||||
import com.github.luben.zstd.ZstdOutputStream
|
||||
import org.apache.commons.compress.archivers.tar.TarArchiveEntry
|
||||
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream
|
||||
import java.io.File
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
@@ -54,4 +57,35 @@ class AddonPackTest {
|
||||
installed("b".repeat(64))
|
||||
assertFalse(AddonPack("sample", "", 0L, listOf("tool"), reuseDeviceCopy = false).installed(context))
|
||||
}
|
||||
|
||||
@Test fun localBuildInstallsTheBundledPackWithoutDownloading() {
|
||||
val archive = tarZst("tool" to "x")
|
||||
val pack = AddonPack("sample", Hashes.sha256(archive), archive.length(), listOf("tool"), bundle = { archive.inputStream() })
|
||||
|
||||
assertTrue(pack.await(context))
|
||||
assertEquals("x", pack.file(context, "tool").readText())
|
||||
}
|
||||
|
||||
@Test fun bundledPackWithTheWrongDigestIsRejected() {
|
||||
val archive = tarZst("tool" to "x")
|
||||
val pack = AddonPack("sample", "a".repeat(64), archive.length(), listOf("tool"),
|
||||
bundle = { archive.inputStream() })
|
||||
|
||||
val copy = File(context.cacheDir, "copy.tar.zst")
|
||||
|
||||
assertFalse(pack.bundled(context, copy))
|
||||
assertFalse(copy.exists())
|
||||
}
|
||||
|
||||
private fun tarZst(vararg files: Pair<String, String>): File =
|
||||
File(context.cacheDir, "sample-${System.nanoTime()}.tar.zst").apply {
|
||||
TarArchiveOutputStream(ZstdOutputStream(outputStream())).use { tar ->
|
||||
for ((path, text) in files) {
|
||||
val bytes = text.toByteArray()
|
||||
tar.putArchiveEntry(TarArchiveEntry(path).apply { size = bytes.size.toLong() })
|
||||
tar.write(bytes)
|
||||
tar.closeArchiveEntry()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -154,6 +154,98 @@ class AddedGameArtFillTest {
|
||||
assertFalse(File(AddedGameArt.cacheDir(app, second), AddedGameArt.EXTRAS_TRIED).exists())
|
||||
}
|
||||
|
||||
private fun steamFrom(asked: MutableList<String>, bytes: Byte, search: Int? = null, slotsAsked: MutableList<Set<Slot>> = ArrayList()) = AddedGameArt.Sources(
|
||||
storeLogo = { false },
|
||||
steamSearch = { if (search == null) fail("searched although the game names its appid"); search },
|
||||
steam = { id, cache, slots ->
|
||||
asked += id
|
||||
slotsAsked += slots
|
||||
slots.forEach { File(cache, steamNames.getValue(it)).writeBytes(byteArrayOf(bytes)) }
|
||||
slots.isNotEmpty()
|
||||
},
|
||||
sgdbGame = { _, _, _ -> null },
|
||||
sgdb = { _, _, _, _ -> false },
|
||||
)
|
||||
|
||||
@Test fun artOfTheAppTheFilesNamedBeforeIsFetchedAgain() {
|
||||
val g = game("Peak", 0x8100000AL, cover = false)
|
||||
File(g.folder, "steam_appid.txt").writeText("1029210")
|
||||
val asked = ArrayList<String>()
|
||||
assertTrue(AddedGameArt.fetchMissing(app, listOf(g), "", steamFrom(asked, 1)))
|
||||
File(g.folder, "steam_appid.txt").writeText("3527290")
|
||||
assertTrue(AddedGameArt.fetchMissing(app, listOf(g), "", steamFrom(asked, 2)))
|
||||
assertEquals(listOf("1029210", "3527290"), asked)
|
||||
assertArrayEquals(byteArrayOf(2), File(AddedGameArt.cacheDir(app, g), "p.jpg").readBytes())
|
||||
assertFalse(AddedGameArt.fetchMissing(app, listOf(g), "", steamFrom(asked, 3)))
|
||||
assertEquals(2, asked.size)
|
||||
}
|
||||
|
||||
@Test fun aPictureTheUserChoseOutlivesTheChange() {
|
||||
val g = game("Peak", 0x8100000BL, cover = false)
|
||||
File(g.folder, "steam_appid.txt").writeText("1029210")
|
||||
AddedGameArt.fetchMissing(app, listOf(g), "", steamFrom(ArrayList(), 1))
|
||||
val picked = File(tmp.root, "mine.jpg").apply { writeBytes(byteArrayOf(7)) }
|
||||
assertTrue(AddedGameArt.store(AddedGameArt.cacheDir(app, g), Slot.COVER, AddedGameArt.Option(AddedGameArt.FILE, picked.path, picked.path)))
|
||||
File(g.folder, "steam_appid.txt").writeText("3527290")
|
||||
val asked = ArrayList<String>()
|
||||
val slots = ArrayList<Set<Slot>>()
|
||||
AddedGameArt.fetchMissing(app, listOf(g), "", steamFrom(asked, 2, slotsAsked = slots))
|
||||
assertArrayEquals(byteArrayOf(7), AddedGameArt.resolve(app, g).portrait!!.readBytes())
|
||||
assertEquals(listOf("3527290"), asked)
|
||||
assertEquals(listOf(setOf(Slot.WIDE, Slot.BACKGROUND, Slot.LOGO)), slots)
|
||||
val cache = AddedGameArt.cacheDir(app, g)
|
||||
assertArrayEquals(byteArrayOf(2), File(cache, "header.jpg").readBytes())
|
||||
assertArrayEquals(byteArrayOf(2), File(cache, "hero.jpg").readBytes())
|
||||
assertFalse(File(cache, AddedGameArt.REFETCH).exists())
|
||||
}
|
||||
|
||||
private fun olderBuildsArt(g: AddedGames.Game, marker: String): File = AddedGameArt.cacheDir(app, g).apply {
|
||||
mkdirs()
|
||||
File(this, "steam-appid").writeText(marker)
|
||||
steamNames.values.forEach { File(this, it).writeBytes(byteArrayOf(1)) }
|
||||
}
|
||||
|
||||
@Test fun anOlderBuildsSpacewarMarkerGoesWithItsArt() {
|
||||
val g = game("Peak", 0x8100000DL, cover = false)
|
||||
File(g.folder, "steam_appid.txt").writeText("480")
|
||||
val cache = olderBuildsArt(g, "480")
|
||||
val asked = ArrayList<String>()
|
||||
assertTrue(AddedGameArt.fetchMissing(app, listOf(g), "", steamFrom(asked, 2, search = 3527290)))
|
||||
assertEquals(listOf("3527290"), asked)
|
||||
assertArrayEquals(byteArrayOf(2), File(cache, "p.jpg").readBytes())
|
||||
assertFalse(File(cache, "steam-appid").exists())
|
||||
}
|
||||
|
||||
@Test fun anOlderBuildsMatchStaysWhileTheFilesNameNoApp() {
|
||||
val g = game("Hades", 0x8100000EL, cover = false)
|
||||
File(g.folder, "steam_appid.txt").delete()
|
||||
val cache = olderBuildsArt(g, "1145360")
|
||||
assertFalse(AddedGameArt.fetchMissing(app, listOf(g), "", steamFrom(ArrayList(), 2)))
|
||||
assertEquals("1145360", File(cache, "steam-appid").readText())
|
||||
assertArrayEquals(byteArrayOf(1), File(cache, "p.jpg").readBytes())
|
||||
}
|
||||
|
||||
@Test fun anOlderBuildsMatchGivesWayToTheAppTheFilesName() {
|
||||
val g = game("Peak", 0x8100000FL, cover = false)
|
||||
File(g.folder, "steam_appid.txt").writeText("3527290")
|
||||
val cache = olderBuildsArt(g, "1029210")
|
||||
val asked = ArrayList<String>()
|
||||
assertTrue(AddedGameArt.fetchMissing(app, listOf(g), "", steamFrom(asked, 2)))
|
||||
assertEquals(listOf("3527290"), asked)
|
||||
assertArrayEquals(byteArrayOf(2), File(cache, "p.jpg").readBytes())
|
||||
assertFalse(File(cache, "steam-appid").exists())
|
||||
}
|
||||
|
||||
@Test fun filesThatStopNamingAnAppFallBackToTheGamesName() {
|
||||
val g = game("Peak", 0x8100000CL, cover = false)
|
||||
File(g.folder, "steam_appid.txt").writeText("1029210")
|
||||
val asked = ArrayList<String>()
|
||||
AddedGameArt.fetchMissing(app, listOf(g), "", steamFrom(asked, 1))
|
||||
File(g.folder, "steam_appid.txt").writeText("480")
|
||||
assertTrue(AddedGameArt.fetchMissing(app, listOf(g), "", steamFrom(asked, 2, search = 3527290)))
|
||||
assertEquals(listOf("1029210", "3527290"), asked)
|
||||
}
|
||||
|
||||
@Test fun nothingIsFetchedWhenArtIsOff() {
|
||||
SessionPrefs.setAddedGamesArt(app, false)
|
||||
val calls = Calls()
|
||||
|
||||
@@ -66,6 +66,29 @@ class AddedGameArtLookupTest {
|
||||
assertEquals(SteamMatch.Certainty.NAME, match.certainty)
|
||||
}
|
||||
|
||||
@Test fun anEarlierBuildsSpacewarLookupIsNotAMatch() {
|
||||
val dir = tmp.newFolder("Peak")
|
||||
val exe = File(dir, "PEAK.exe").apply { writeText("x") }
|
||||
val legacy = File(tmp.newFolder(), "steam-appid").apply { writeText("480") }
|
||||
assertEquals(3527290, SteamMatch.resolve(app, dir.path, exe, "PEAK", legacy = legacy) { 3527290 }.appId)
|
||||
}
|
||||
|
||||
@Test fun aSavedSpacewarMatchIsNotAMatch() {
|
||||
val dir = tmp.newFolder("Peak")
|
||||
val exe = File(dir, "PEAK.exe").apply { writeText("x") }
|
||||
SteamMatch.put(app, dir.path, SteamMatch.Match(480, SteamMatch.Certainty.NAME, "store search", System.currentTimeMillis()))
|
||||
assertNull(SteamMatch.resolve(app, dir.path, exe, "PEAK").appId)
|
||||
assertEquals(3527290, SteamMatch.resolve(app, dir.path, exe, "PEAK") { 3527290 }.appId)
|
||||
}
|
||||
|
||||
@Test fun aStoreSearchAnsweringSpacewarIsNoMatch() {
|
||||
val dir = tmp.newFolder("Spacewar Fan Remake")
|
||||
val exe = File(dir, "game.exe").apply { writeText("x") }
|
||||
val match = SteamMatch.resolve(app, dir.path, exe, "Spacewar Fan Remake") { 480 }
|
||||
assertNull(match.appId)
|
||||
assertEquals(SteamMatch.Certainty.NONE, match.certainty)
|
||||
}
|
||||
|
||||
@Test fun aStoreResultIsTakenOnlyWhenItsNameMatches() {
|
||||
assertNull(AddedGameArt.pickStoreResult("My Obscure Game", listOf("10" to "Totally Different", "11" to "Another One")))
|
||||
assertEquals("20", AddedGameArt.pickStoreResult("Hades", listOf("19" to "Hades II Soundtrack Bundle Extra", "20" to "Hades")))
|
||||
|
||||
@@ -31,8 +31,25 @@ class GameIdentifierTest {
|
||||
fun steamAppIdTxt_inSteamSettingsSubdir_isFound() {
|
||||
val dir = tmp.newFolder("Game")
|
||||
File(dir, "steam_settings").mkdirs()
|
||||
File(dir, "steam_settings/steam_appid.txt").writeText("480")
|
||||
assertEquals(480, GameIdentifier.identify(exeIn(dir)).appId)
|
||||
File(dir, "steam_settings/steam_appid.txt").writeText("3527290")
|
||||
assertEquals(3527290, GameIdentifier.identify(exeIn(dir)).appId)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun spacewarAppId_namesNoGame() {
|
||||
val dir = tmp.newFolder("PEAK")
|
||||
File(dir, "steam_appid.txt").writeText("480")
|
||||
File(dir, "steam_emu.ini").writeText("[Settings]\nAppId=480\n")
|
||||
assertNull(GameIdentifier.identify(exeIn(dir)).appId)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun spacewarAppId_fallsThroughToTheGamesOwnId() {
|
||||
val dir = tmp.newFolder("PEAK")
|
||||
File(dir, "steam_appid.txt").writeText("480")
|
||||
File(dir, "steam_settings").mkdirs()
|
||||
File(dir, "steam_settings/steam_appid.txt").writeText("3527290")
|
||||
assertEquals(3527290, GameIdentifier.identify(exeIn(dir)).appId)
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -44,6 +61,30 @@ class GameIdentifierTest {
|
||||
assertEquals(GameIdentifier.Source.STEAM_EMU_INI, id.source)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun spacewarManifest_namesNoGame() {
|
||||
val steamapps = tmp.newFolder("steamapps")
|
||||
File(steamapps, "appmanifest_480.acf").writeText(""""AppState" { "appid" "480" "name" "Spacewar" "installdir" "PEAK" }""")
|
||||
val game = File(steamapps, "common/PEAK").apply { mkdirs() }
|
||||
File(game, "steam_appid.txt").writeText("3527290")
|
||||
val id = GameIdentifier.identify(exeIn(game, "PEAK.exe"))
|
||||
assertEquals(3527290, id.appId)
|
||||
assertEquals(GameIdentifier.Source.STEAM_APPID_TXT, id.source)
|
||||
assertTrue(id.name != "Spacewar")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun spacewarManifest_leavesTheGamesOwnManifestForTheSameFolder() {
|
||||
val steamapps = tmp.newFolder("steamapps")
|
||||
File(steamapps, "appmanifest_480.acf").writeText(""""AppState" { "appid" "480" "name" "Spacewar" "installdir" "PEAK" }""")
|
||||
File(steamapps, "appmanifest_3527290.acf").writeText(""""AppState" { "appid" "3527290" "name" "PEAK" "installdir" "PEAK" }""")
|
||||
val game = File(steamapps, "common/PEAK").apply { mkdirs() }
|
||||
val id = GameIdentifier.identify(exeIn(game, "PEAK.exe"))
|
||||
assertEquals(3527290, id.appId)
|
||||
assertEquals("PEAK", id.name)
|
||||
assertEquals(GameIdentifier.Source.STEAM_MANIFEST_ACF, id.source)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun steamManifestAcf_matchedByInstalldir_givesAppIdAndName() {
|
||||
val steamapps = tmp.newFolder("steamapps")
|
||||
|
||||
@@ -0,0 +1,163 @@
|
||||
package com.droiddeck.launcher.frontend
|
||||
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
import com.droiddeck.launcher.session.SessionService
|
||||
import com.droiddeck.launcher.session.SessionState
|
||||
import java.io.File
|
||||
import org.junit.After
|
||||
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.RuntimeEnvironment
|
||||
import org.robolectric.annotation.Config
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [33])
|
||||
class SteamLaunchOptionsTest {
|
||||
@get:Rule val tmp = TemporaryFolder()
|
||||
|
||||
private fun config(apps: String) = listOf(
|
||||
"\"UserLocalConfigStore\"", "{", "\t\"Software\"", "\t{", "\t\t\"Valve\"", "\t\t{", "\t\t\t\"Steam\"", "\t\t\t{",
|
||||
apps, "\t\t\t}", "\t\t}", "\t}", "\t\"WebStorage\"", "\t{", "\t\t\"x\"\t\t\"1\"", "\t}", "}", "",
|
||||
).joinToString("\n")
|
||||
|
||||
private fun apps(vararg lines: String) = (listOf("\t\t\t\t\"apps\"", "\t\t\t\t{") + lines + "\t\t\t\t}").joinToString("\n")
|
||||
|
||||
private val sparking = arrayOf(
|
||||
"\t\t\t\t\t\"1790600\"", "\t\t\t\t\t{", "\t\t\t\t\t\t\"LastPlayed\"\t\t\"1761897600\"", "\t\t\t\t\t\t\"LaunchOptions\"\t\t\"-dx11\"", "\t\t\t\t\t}",
|
||||
)
|
||||
|
||||
@Test fun replacesTheOptionsSteamHas() {
|
||||
val text = config(apps(*sparking))
|
||||
val updated = SteamLaunchOptions.withLaunchOptions(text, 1790600, "-dx12")!!
|
||||
assertEquals(text.replace("\"-dx11\"", "\"-dx12\""), updated)
|
||||
assertEquals("-dx12", SteamLaunchOptions.launchOptions(updated, 1790600))
|
||||
}
|
||||
|
||||
@Test fun addsOptionsToAGameThatHasNone() {
|
||||
val text = config(apps("\t\t\t\t\t\"1790600\"", "\t\t\t\t\t{", "\t\t\t\t\t\t\"LastPlayed\"\t\t\"1761897600\"", "\t\t\t\t\t}"))
|
||||
assertEquals(config(apps(*sparking)).replace("-dx11", "-vulkan"), SteamLaunchOptions.withLaunchOptions(text, 1790600, "-vulkan"))
|
||||
}
|
||||
|
||||
@Test fun addsTheGameAndTheAppsSectionWhenSteamHasNeither() {
|
||||
val updated = SteamLaunchOptions.withLaunchOptions(config("\t\t\t\t\"language\"\t\t\"english\""), 1790600, "-dx11")!!
|
||||
assertEquals(
|
||||
config(
|
||||
"\t\t\t\t\"language\"\t\t\"english\"\n" +
|
||||
apps("\t\t\t\t\t\"1790600\"", "\t\t\t\t\t{", "\t\t\t\t\t\t\"LaunchOptions\"\t\t\"-dx11\"", "\t\t\t\t\t}"),
|
||||
),
|
||||
updated,
|
||||
)
|
||||
assertEquals("-dx11", SteamLaunchOptions.launchOptions(updated, 1790600))
|
||||
}
|
||||
|
||||
@Test fun quotesAndBackslashesAreEscapedAndReadBack() {
|
||||
val options = "PROTON_LOG=1 %command% -path \"C:\\Games\\DB\""
|
||||
val updated = SteamLaunchOptions.withLaunchOptions(config(apps(*sparking)), 1790600, options)!!
|
||||
assertEquals(true, updated.contains("\"PROTON_LOG=1 %command% -path \\\"C:\\\\Games\\\\DB\\\"\""))
|
||||
assertEquals(options, SteamLaunchOptions.launchOptions(updated, 1790600))
|
||||
}
|
||||
|
||||
@Test fun emptyOptionsClearSteams() {
|
||||
val updated = SteamLaunchOptions.withLaunchOptions(config(apps(*sparking)), 1790600, "")!!
|
||||
assertEquals("", SteamLaunchOptions.launchOptions(updated, 1790600))
|
||||
}
|
||||
|
||||
@Test fun windowsLineEndsAreKept() {
|
||||
val text = config("\t\t\t\t\"language\"\t\t\"english\"").replace("\n", "\r\n")
|
||||
val updated = SteamLaunchOptions.withLaunchOptions(text, 1790600, "-dx11")!!
|
||||
assertEquals(false, updated.replace("\r\n", "").contains('\n'))
|
||||
assertEquals("-dx11", SteamLaunchOptions.launchOptions(updated, 1790600))
|
||||
}
|
||||
|
||||
@Test fun onlyTheGamesOwnSectionChanges() {
|
||||
val other = arrayOf(
|
||||
"\t\t\t\t\t\"7\"", "\t\t\t\t\t{", "\t\t\t\t\t\t\"1790600\"", "\t\t\t\t\t\t{", "\t\t\t\t\t\t\t\"LaunchOptions\"\t\t\"keep\"", "\t\t\t\t\t\t}", "\t\t\t\t\t}",
|
||||
)
|
||||
val updated = SteamLaunchOptions.withLaunchOptions(config(apps(*other, *sparking)), 1790600, "-dx12")!!
|
||||
assertEquals(true, updated.contains("\"keep\""))
|
||||
assertEquals("-dx12", SteamLaunchOptions.launchOptions(updated, 1790600))
|
||||
assertNull(SteamLaunchOptions.launchOptions(config(apps(*other)), 1790600))
|
||||
}
|
||||
|
||||
@Test fun otherFilesAreLeftAlone() {
|
||||
assertNull(SteamLaunchOptions.withLaunchOptions("\"InstallConfigStore\"\n{\n}\n", 1790600, "-dx11"))
|
||||
assertNull(SteamLaunchOptions.withLaunchOptions("", 1790600, "-dx11"))
|
||||
assertNull(SteamLaunchOptions.launchOptions("", 1790600))
|
||||
}
|
||||
|
||||
private fun steamHome(home: File = tmp.newFolder("Steam")): File = home.also {
|
||||
File(home, "config").mkdirs()
|
||||
File(home, "config/loginusers.vdf").writeText(
|
||||
"\"users\"\n{\n\t\"76561198021239924\"\n\t{\n\t\t\"AccountName\"\t\t\"a\"\n\t\t\"MostRecent\"\t\t\"1\"\n\t}\n}\n")
|
||||
}
|
||||
|
||||
private fun localConfig(home: File, account: String) = File(home, "userdata/$account/config/localconfig.vdf").apply { parentFile!!.mkdirs() }
|
||||
|
||||
@Test fun aChangeGoesToTheSignedInAccountOnly() {
|
||||
val home = steamHome()
|
||||
val signedIn = localConfig(home, "60974196").apply { writeText(config(apps(*sparking))) }
|
||||
val other = localConfig(home, "123").apply { writeText(config("\t\t\t\t\"language\"\t\t\"english\"")) }
|
||||
val untouched = other.readText()
|
||||
assertTrue(SteamLaunchOptions.write(home, 1790600, "-dx12"))
|
||||
assertEquals("-dx12", SteamLaunchOptions.launchOptions(signedIn.readText(), 1790600))
|
||||
assertEquals(untouched, other.readText())
|
||||
assertFalse(File(signedIn.parentFile, "localconfig.vdf.staged").exists())
|
||||
}
|
||||
|
||||
@Test fun whatSteamWroteLastIsWhatTheGameHas() {
|
||||
val home = steamHome()
|
||||
val config = localConfig(home, "60974196").apply { writeText(config(apps(*sparking))) }
|
||||
assertTrue(SteamLaunchOptions.write(home, 1790600, "-dx12"))
|
||||
config.writeText(SteamLaunchOptions.withLaunchOptions(config.readText(), 1790600, "-vulkan")!!)
|
||||
assertEquals("-vulkan", SteamLaunchOptions.steam(home, 1790600))
|
||||
assertNull(SteamLaunchOptions.steam(home, 400))
|
||||
}
|
||||
|
||||
private val app get() = RuntimeEnvironment.getApplication()
|
||||
|
||||
private val written = ArrayList<File>()
|
||||
|
||||
private fun sessionConfig(): File {
|
||||
val home = steamHome(SessionPrefs.activeSteamRoot(app))
|
||||
return localConfig(home, "60974196").apply { writeText(config(apps(*sparking))) }
|
||||
.also { written += it; written += File(home, "config/loginusers.vdf") }
|
||||
}
|
||||
|
||||
@After fun noSession() {
|
||||
SessionState.running = false
|
||||
SessionState.mode = SessionService.MODE_STEAM
|
||||
written.forEach { it.delete() }
|
||||
}
|
||||
|
||||
@Test fun aValueChangedInSteamSinceItWasShownIsNotOverwritten() {
|
||||
val config = sessionConfig()
|
||||
assertEquals(SteamLaunchOptions.Saved.NO, SteamLaunchOptions.set(app, 1790600, "-dx12", shown = "-vulkan"))
|
||||
assertEquals("-dx11", SteamLaunchOptions.launchOptions(config.readText(), 1790600))
|
||||
assertEquals(SteamLaunchOptions.Saved.YES, SteamLaunchOptions.set(app, 1790600, "-dx12", shown = "-dx11"))
|
||||
assertEquals("-dx12", SteamLaunchOptions.launchOptions(config.readText(), 1790600))
|
||||
}
|
||||
|
||||
@Test fun aDesktopSessionLeavesTheFileToItsClient() {
|
||||
val config = sessionConfig()
|
||||
val before = config.readText()
|
||||
SessionState.running = true
|
||||
SessionState.mode = SessionService.MODE_DESKTOP
|
||||
assertEquals(SteamLaunchOptions.Saved.DESKTOP, SteamLaunchOptions.set(app, 1790600, "-dx12", shown = "-dx11"))
|
||||
assertEquals(before, config.readText())
|
||||
}
|
||||
|
||||
@Test fun nothingIsWrittenWithoutASignedInAccountsConfig() {
|
||||
assertFalse(SteamLaunchOptions.write(tmp.newFolder("NoSteam"), 1790600, "-dx11"))
|
||||
val home = steamHome()
|
||||
assertFalse(SteamLaunchOptions.write(home, 1790600, "-dx11"))
|
||||
localConfig(home, "60974196").writeText("\"InstallConfigStore\"\n{\n}\n")
|
||||
assertFalse(SteamLaunchOptions.write(home, 1790600, "-dx11"))
|
||||
}
|
||||
}
|
||||
@@ -45,6 +45,7 @@ class DroidDeckHudPanelTest {
|
||||
}
|
||||
val snapshot = SNAPSHOT
|
||||
for (size in DroidDeckHudSize.values()) {
|
||||
if (size == DroidDeckHudSize.STRIP) continue
|
||||
val view = DroidDeckHudView(RuntimeEnvironment.getApplication())
|
||||
view.applyConfig(DroidDeckHudConfig.encode(DroidDeckHudConfig.DEFAULTS + ("hudSize" to size.token)))
|
||||
view.setFrameStats(stats)
|
||||
@@ -70,6 +71,73 @@ class DroidDeckHudPanelTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun stripIsOneLineAcrossTheParentWithTheClockOnTheRight() {
|
||||
val app = RuntimeEnvironment.getApplication()
|
||||
val parent = FrameLayout(app)
|
||||
val view = DroidDeckHudView(app)
|
||||
parent.addView(view, FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT))
|
||||
parent.measure(View.MeasureSpec.makeMeasureSpec(2400, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(1080, View.MeasureSpec.EXACTLY))
|
||||
parent.layout(0, 0, 2400, 1080)
|
||||
view.applyConfig(DroidDeckHudConfig.encode(DroidDeckHudConfig.DEFAULTS + ("hudSize" to DroidDeckHudSize.STRIP.token) +
|
||||
("showBattery" to "1")))
|
||||
view.showForTest(SNAPSHOT, "DXVK", 0L)
|
||||
val unspecified = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)
|
||||
view.measure(unspecified, unspecified)
|
||||
|
||||
assertTrue(view.isStrip)
|
||||
assertEquals(2400, view.measuredWidth)
|
||||
val lines = view.linesForTest()
|
||||
assertEquals(lines.toString(), 1, lines.size)
|
||||
val line = lines.single()
|
||||
listOf("DXVK", "fps", "GPU", "CPU", "RAM", "BAT 79%").forEach { assertTrue(line, it in line) }
|
||||
assertTrue(line, line.indexOf("DXVK") < line.indexOf("GPU") && line.indexOf("GPU") < line.indexOf("BAT"))
|
||||
|
||||
val bitmap = Bitmap.createBitmap(view.measuredWidth, view.measuredHeight, Bitmap.Config.ARGB_8888)
|
||||
view.layout(0, 0, view.measuredWidth, view.measuredHeight)
|
||||
view.draw(Canvas(bitmap))
|
||||
val png = ByteArrayOutputStream().also { bitmap.compress(Bitmap.CompressFormat.PNG, 100, it) }
|
||||
println("DROIDDECKHUD-STRIP-PNG ${Base64.getEncoder().encodeToString(png.toByteArray())}")
|
||||
}
|
||||
|
||||
@Test fun stripLeavesOffWhatNoLongerFitsBeforeTheClock() {
|
||||
val app = RuntimeEnvironment.getApplication()
|
||||
val parent = FrameLayout(app)
|
||||
val view = DroidDeckHudView(app)
|
||||
parent.addView(view, FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT))
|
||||
parent.measure(View.MeasureSpec.makeMeasureSpec(700, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(400, View.MeasureSpec.EXACTLY))
|
||||
parent.layout(0, 0, 700, 400)
|
||||
view.applyConfig(DroidDeckHudConfig.encode(DroidDeckHudConfig.DEFAULTS + ("hudSize" to DroidDeckHudSize.STRIP.token)))
|
||||
view.showForTest(SNAPSHOT, "DXVK", 0L)
|
||||
val line = view.linesForTest().single()
|
||||
assertTrue(line, "fps" in line)
|
||||
assertFalse(line, "BAT" in line)
|
||||
}
|
||||
|
||||
@Test fun stripFollowsTheHudScaleInHeightAndKeepsTheFullWidth() {
|
||||
val app = RuntimeEnvironment.getApplication()
|
||||
val parent = FrameLayout(app)
|
||||
val view = DroidDeckHudView(app)
|
||||
parent.addView(view, FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT))
|
||||
parent.measure(View.MeasureSpec.makeMeasureSpec(2400, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(1080, View.MeasureSpec.EXACTLY))
|
||||
parent.layout(0, 0, 2400, 1080)
|
||||
fun at(scale: Int): Pair<Float, Float> {
|
||||
view.applyConfig(DroidDeckHudConfig.encode(DroidDeckHudConfig.DEFAULTS + ("hudSize" to DroidDeckHudSize.STRIP.token) +
|
||||
("hudScale" to scale.toString())))
|
||||
view.showForTest(SNAPSHOT, "DXVK", 0L)
|
||||
val unspecified = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)
|
||||
view.measure(unspecified, unspecified)
|
||||
view.layout(0, 0, view.measuredWidth, view.measuredHeight)
|
||||
val bitmap = Bitmap.createBitmap(view.measuredWidth, view.measuredHeight, Bitmap.Config.ARGB_8888)
|
||||
view.draw(Canvas(bitmap))
|
||||
val png = ByteArrayOutputStream().also { bitmap.compress(Bitmap.CompressFormat.PNG, 100, it) }
|
||||
println("DROIDDECKHUD-STRIP$scale-PNG ${Base64.getEncoder().encodeToString(png.toByteArray())}")
|
||||
return Pair(view.contentWidth, view.contentHeight)
|
||||
}
|
||||
val small = at(70); val big = at(150)
|
||||
assertEquals(2400f, small.first); assertEquals(2400f, big.first)
|
||||
assertEquals(big.second / small.second, 150f / 70f, 0.01f)
|
||||
}
|
||||
|
||||
@Test fun pillShowsEachBatteryPartOnItsOwnSwitch() {
|
||||
fun pill(vararg settings: Pair<String, String>): List<String> {
|
||||
val view = DroidDeckHudView(RuntimeEnvironment.getApplication())
|
||||
|
||||
@@ -4,23 +4,38 @@ import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
|
||||
class SecondScreenModeTest {
|
||||
@Test fun withNothingRememberedTheControllerPicksThePanel() {
|
||||
@Test fun withNothingRememberedTheDashboardOpens() {
|
||||
assertEquals(SecondScreenMode.DASHBOARD, SecondScreenMode.opening(null, deckPad = true, dashboard = true))
|
||||
assertEquals(SecondScreenMode.DASHBOARD, SecondScreenMode.opening(null, deckPad = false, dashboard = true))
|
||||
}
|
||||
|
||||
@Test fun withNothingRememberedAndNoDashboardTheControllerPicksThePanel() {
|
||||
assertEquals(SecondScreenMode.DECK_CONTROLS, SecondScreenMode.opening(null, deckPad = true))
|
||||
assertEquals(SecondScreenMode.KEYBOARD_TRACKPAD, SecondScreenMode.opening(null, deckPad = false))
|
||||
}
|
||||
|
||||
@Test fun thePanelTheUserPickedLastOpensAgain() {
|
||||
assertEquals(SecondScreenMode.KEYBOARD_TRACKPAD, SecondScreenMode.opening("keyboard-trackpad", deckPad = true, dashboard = true))
|
||||
assertEquals(SecondScreenMode.DECK_CONTROLS, SecondScreenMode.opening("deck-controls", deckPad = true, dashboard = true))
|
||||
assertEquals(SecondScreenMode.TERMINAL, SecondScreenMode.opening("terminal", deckPad = true, dashboard = true))
|
||||
assertEquals(SecondScreenMode.KEYBOARD_TRACKPAD, SecondScreenMode.opening("keyboard-trackpad", deckPad = true))
|
||||
assertEquals(SecondScreenMode.DECK_CONTROLS, SecondScreenMode.opening("deck-controls", deckPad = true))
|
||||
assertEquals(SecondScreenMode.TERMINAL, SecondScreenMode.opening("terminal", deckPad = true))
|
||||
}
|
||||
|
||||
@Test fun deckControlsNeedTheDeckPad() {
|
||||
assertEquals(SecondScreenMode.KEYBOARD_TRACKPAD, SecondScreenMode.opening("deck-controls", deckPad = false))
|
||||
assertEquals(SecondScreenMode.KEYBOARD_TRACKPAD, SecondScreenMode.opening("deck-controls", deckPad = false, dashboard = true))
|
||||
}
|
||||
|
||||
@Test fun anUnknownOrClosedChoiceFallsBackToTheDefault() {
|
||||
assertEquals(SecondScreenMode.DASHBOARD, SecondScreenMode.opening("none", deckPad = true, dashboard = true))
|
||||
assertEquals(SecondScreenMode.DASHBOARD, SecondScreenMode.opening("gone", deckPad = false, dashboard = true))
|
||||
assertEquals(SecondScreenMode.DECK_CONTROLS, SecondScreenMode.opening("none", deckPad = true))
|
||||
assertEquals(SecondScreenMode.KEYBOARD_TRACKPAD, SecondScreenMode.opening("gone", deckPad = false))
|
||||
}
|
||||
|
||||
@Test fun theDashboardOpensAgainOnlyWhileItHasPages() {
|
||||
assertEquals(SecondScreenMode.DASHBOARD, SecondScreenMode.opening("dashboard", deckPad = true, dashboard = true))
|
||||
assertEquals(SecondScreenMode.DECK_CONTROLS, SecondScreenMode.opening("dashboard", deckPad = true, dashboard = false))
|
||||
assertEquals(SecondScreenMode.KEYBOARD_TRACKPAD, SecondScreenMode.opening("dashboard", deckPad = false))
|
||||
}
|
||||
}
|
||||
@@ -33,7 +33,9 @@ class TouchpadGesturesTest {
|
||||
override fun onScroll(dx: Float, dy: Float) { events += "scroll" }
|
||||
override fun onScrollEnd() { events += "scroll end" }
|
||||
override fun onZoom(steps: Int) { events += "zoom $steps" }
|
||||
override fun onThreeFingerTap(): Boolean { events += "three tap"; return claimThreeTap }
|
||||
}
|
||||
private var claimThreeTap = false
|
||||
|
||||
@Before fun setUp() {
|
||||
touchpad = TouchpadGestures(SLOP, listener)
|
||||
@@ -50,7 +52,18 @@ class TouchpadGesturesTest {
|
||||
assertEquals(listOf("left down", "left up"), events)
|
||||
}
|
||||
|
||||
@Test fun threeFingerTapClicksTheMiddleButton() {
|
||||
@Test fun threeFingerTapClicksTheMiddleButtonWhenUnclaimed() {
|
||||
threeFingerTap()
|
||||
assertEquals(listOf("three tap", "middle down", "middle up"), events)
|
||||
}
|
||||
|
||||
@Test fun claimedThreeFingerTapSkipsTheMiddleButton() {
|
||||
claimThreeTap = true
|
||||
threeFingerTap()
|
||||
assertEquals(listOf("three tap"), events)
|
||||
}
|
||||
|
||||
private fun threeFingerTap() {
|
||||
touch(MotionEvent.ACTION_DOWN, 0, 1 to (400f to 300f))
|
||||
advance(10)
|
||||
touch(MotionEvent.ACTION_POINTER_DOWN, 1, 1 to (400f to 300f), 2 to (600f to 310f))
|
||||
@@ -61,7 +74,6 @@ class TouchpadGesturesTest {
|
||||
touch(MotionEvent.ACTION_POINTER_UP, 1, 1 to (400f to 300f), 2 to (600f to 310f))
|
||||
touch(MotionEvent.ACTION_UP, 0, 1 to (400f to 300f))
|
||||
advance(100)
|
||||
assertEquals(listOf("middle down", "middle up"), events)
|
||||
}
|
||||
|
||||
@Test fun desktopTwoFingerSlideScrollsSmoothlyAndStops() {
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
class BottomNotificationsTest {
|
||||
private val own = "com.droiddeck.launcher"
|
||||
|
||||
@Test fun messagesFromOtherAppsAreKept() {
|
||||
assertTrue(BottomNotifications.keep(own, "com.discord", ongoing = false, groupSummary = false, title = "Kurt", text = "ready?"))
|
||||
}
|
||||
|
||||
@Test fun ownOngoingSummaryAndEmptyNotificationsAreSkipped() {
|
||||
assertFalse(BottomNotifications.keep(own, own, ongoing = false, groupSummary = false, title = "Session", text = "running"))
|
||||
assertFalse(BottomNotifications.keep(own, "com.spotify", ongoing = true, groupSummary = false, title = "Song", text = "Artist"))
|
||||
assertFalse(BottomNotifications.keep(own, "com.discord", ongoing = false, groupSummary = true, title = "2 messages", text = ""))
|
||||
assertFalse(BottomNotifications.keep(own, "com.discord", ongoing = false, groupSummary = false, title = " ", text = ""))
|
||||
}
|
||||
|
||||
@Test fun anUpdatedNotificationMovesToTheTopOnce() {
|
||||
val list = mutableListOf(
|
||||
BottomNotification("a", "App", "one", "", 1L),
|
||||
BottomNotification("b", "App", "two", "", 2L),
|
||||
)
|
||||
BottomNotifications.add(list, BottomNotification("b", "App", "two again", "", 3L))
|
||||
assertEquals(listOf("b", "a"), list.map { it.key })
|
||||
assertEquals("two again", list.first().title)
|
||||
}
|
||||
|
||||
@Test fun theListKeepsTheNewestThirty() {
|
||||
val list = mutableListOf<BottomNotification>()
|
||||
repeat(35) { BottomNotifications.add(list, BottomNotification("k$it", "App", "t$it", "", it.toLong())) }
|
||||
assertEquals(30, list.size)
|
||||
assertEquals("k34", list.first().key)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.TemporaryFolder
|
||||
import java.io.File
|
||||
|
||||
class BottomScreenshotsTest {
|
||||
@get:Rule val tmp = TemporaryFolder()
|
||||
|
||||
@Test fun fileNamesSortByTime() {
|
||||
val name = BottomScreenshots.fileName(0L)
|
||||
assertTrue(name, name.startsWith("DroidDeck_") && name.endsWith(".jpg"))
|
||||
assertEquals(29, name.length)
|
||||
}
|
||||
|
||||
@Test fun steamScreenshotsAreFoundAndThumbnailsSkipped() {
|
||||
val root = tmp.root
|
||||
val shots = File(root, "root/.local/share/Steam/userdata/2932373/760/remote/220/screenshots")
|
||||
File(shots, "thumbnails").mkdirs()
|
||||
File(shots, "20261031010101_1.jpg").writeText("x")
|
||||
File(shots, "thumbnails/20261031010101_1.jpg").writeText("x")
|
||||
File(shots, "screenshots.vdf").writeText("x")
|
||||
val x64 = File(root, "root/.droiddeck-x64/.local/share/Steam/userdata/2932373/760/remote/440/screenshots")
|
||||
x64.mkdirs()
|
||||
File(x64, "20261031020202_1.jpg").writeText("x")
|
||||
val found = BottomScreenshots.steam(root).map { it.file!!.name }.sorted()
|
||||
assertEquals(listOf("20261031010101_1.jpg", "20261031020202_1.jpg"), found)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,226 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
import java.nio.ByteBuffer
|
||||
import java.nio.ByteOrder
|
||||
|
||||
class GameTelemetryTest {
|
||||
private fun packet(size: Int, fill: ByteBuffer.() -> Unit): ByteArray =
|
||||
ByteBuffer.allocate(size).order(ByteOrder.LITTLE_ENDIAN).apply(fill).array()
|
||||
|
||||
@Test fun codemastersFloatsBecomeADash() {
|
||||
val data = packet(264) {
|
||||
putFloat(7 * 4, 25f) // m/s
|
||||
putFloat(29 * 4, 0.8f)
|
||||
putFloat(31 * 4, 0.1f)
|
||||
putFloat(33 * 4, 3f)
|
||||
putFloat(36 * 4, 1f)
|
||||
putFloat(37 * 4, 650f) // rpm / 10
|
||||
putFloat(63 * 4, 800f)
|
||||
putFloat(45 * 4, 30f)
|
||||
putFloat(46 * 4, 60f)
|
||||
}
|
||||
val t = GameTelemetry.parse(GameTelemetry.CODEMASTERS_PORT, data, data.size)!!
|
||||
assertEquals(90f, t.speedKmh!!, 0.01f)
|
||||
assertEquals("3", t.gear)
|
||||
assertEquals(6500f, t.rpm!!, 0.01f)
|
||||
assertEquals(8000f, t.maxRpm!!, 0.01f)
|
||||
assertEquals(2, t.lap)
|
||||
assertEquals(0.5f, t.fuel!!, 0.001f)
|
||||
}
|
||||
|
||||
// Values from a DiRT Showdown packet recorded on a Retroid Pocket Duo (extradata 3 still sends 152 bytes there).
|
||||
@Test fun codemastersShortPacketFromDirtShowdown() {
|
||||
val data = packet(152) {
|
||||
putFloat(1 * 4, 80.085f)
|
||||
putFloat(7 * 4, 10.739f)
|
||||
putFloat(29 * 4, 0.816f)
|
||||
putFloat(33 * 4, 1f)
|
||||
putFloat(37 * 4, 827.531f)
|
||||
}
|
||||
val t = GameTelemetry.parse(GameTelemetry.CODEMASTERS_PORT, data, data.size)!!
|
||||
assertEquals(38.66f, t.speedKmh!!, 0.01f)
|
||||
assertEquals("1", t.gear)
|
||||
assertEquals(8275.31f, t.rpm!!, 0.01f)
|
||||
assertEquals(0.816f, t.throttle!!, 0.001f)
|
||||
assertEquals(1, t.lap)
|
||||
assertEquals(80.085f, t.currentLapS!!, 0.001f)
|
||||
assertNull(t.maxRpm)
|
||||
assertNull(t.laps)
|
||||
assertNull(t.position)
|
||||
assertNull(t.fuel)
|
||||
assertNull(t.lastLapS)
|
||||
}
|
||||
|
||||
@Test fun codemastersReverseAndNeutral() {
|
||||
fun gear(g: Float) = GameTelemetry.parse(GameTelemetry.CODEMASTERS_PORT, packet(264) { putFloat(33 * 4, g) }, 264)!!.gear
|
||||
assertEquals("N", gear(0f))
|
||||
assertEquals("R", gear(-1f))
|
||||
assertEquals("R", gear(10f))
|
||||
}
|
||||
|
||||
@Test fun forzaHorizonDashSitsTwelveBytesLater() {
|
||||
val dash = 232 + 12
|
||||
val data = packet(324) {
|
||||
putInt(0, 1)
|
||||
putFloat(8, 8000f)
|
||||
putFloat(16, 5000f)
|
||||
putFloat(dash + 12, 50f)
|
||||
put(dash + 71, 255.toByte())
|
||||
put(dash + 75, 4)
|
||||
putShort(dash + 68, 2)
|
||||
put(dash + 70, 5)
|
||||
}
|
||||
val t = GameTelemetry.parse(GameTelemetry.FORZA_PORT, data, data.size)!!
|
||||
assertEquals(180f, t.speedKmh!!, 0.01f)
|
||||
assertEquals("4", t.gear)
|
||||
assertEquals(1f, t.throttle!!, 0.001f)
|
||||
assertEquals(3, t.lap)
|
||||
assertEquals(5, t.position)
|
||||
}
|
||||
|
||||
@Test fun forzaMotorsportDashFollowsTheSled() {
|
||||
val data = packet(311) {
|
||||
putInt(0, 1)
|
||||
putFloat(232 + 12, 10f)
|
||||
put(232 + 75, 0)
|
||||
}
|
||||
val t = GameTelemetry.parse(GameTelemetry.FORZA_PORT, data, data.size)!!
|
||||
assertEquals(36f, t.speedKmh!!, 0.01f)
|
||||
assertEquals("R", t.gear)
|
||||
}
|
||||
|
||||
@Test fun forzaInMenusHasNoDash() {
|
||||
val t = GameTelemetry.parse(GameTelemetry.FORZA_PORT, packet(324) {}, 324)!!
|
||||
assertNull(t.speedKmh)
|
||||
}
|
||||
|
||||
@Test fun outGaugeGearsAreShiftedByOne() {
|
||||
val data = packet(96) {
|
||||
put(10, 3)
|
||||
putFloat(12, 20f)
|
||||
putFloat(16, 4000f)
|
||||
}
|
||||
val t = GameTelemetry.parse(GameTelemetry.OUTGAUGE_PORT, data, data.size)!!
|
||||
assertEquals("2", t.gear)
|
||||
assertEquals(72f, t.speedKmh!!, 0.01f)
|
||||
assertEquals(4000f, t.rpm!!, 0.01f)
|
||||
}
|
||||
|
||||
@Test fun listensOnIpv4Loopback() {
|
||||
assertTrue(GameTelemetry.LISTEN_ADDRESS is java.net.Inet4Address)
|
||||
assertEquals("127.0.0.1", GameTelemetry.LISTEN_ADDRESS.hostAddress)
|
||||
}
|
||||
|
||||
@Test fun shortPacketsAreIgnored() {
|
||||
assertNull(GameTelemetry.parse(GameTelemetry.CODEMASTERS_PORT, ByteArray(148), 148))
|
||||
assertNull(GameTelemetry.parse(GameTelemetry.OUTGAUGE_PORT, ByteArray(40), 40))
|
||||
assertNull(GameTelemetry.parse(1234, ByteArray(400), 400))
|
||||
}
|
||||
|
||||
// DiRT Showdown's 38 floats already carry steering and both G-forces.
|
||||
@Test fun codemastersGForceAndSteering() {
|
||||
val data = packet(152) {
|
||||
putFloat(30 * 4, -0.5f)
|
||||
putFloat(33 * 4, 2f)
|
||||
putFloat(34 * 4, 1.2f)
|
||||
putFloat(35 * 4, -0.8f)
|
||||
}
|
||||
val t = GameTelemetry.parse(GameTelemetry.CODEMASTERS_PORT, data, data.size)!!
|
||||
assertEquals(-0.5f, t.steer!!, 1e-4f)
|
||||
assertEquals(1.2f, t.gLat!!, 1e-4f)
|
||||
assertEquals(-0.8f, t.gLon!!, 1e-4f)
|
||||
}
|
||||
|
||||
@Test fun forzaReadsBestLapSteeringGForceAndTires() {
|
||||
val dash = 232
|
||||
val data = packet(311) {
|
||||
putInt(0, 1)
|
||||
putFloat(20, 9.81f)
|
||||
putFloat(28, -4.905f)
|
||||
putFloat(dash + 24, 212f)
|
||||
putFloat(dash + 28, 32f)
|
||||
putFloat(dash + 32, 194f)
|
||||
putFloat(dash + 36, 176f)
|
||||
putFloat(dash + 52, 81.5f)
|
||||
put(dash + 75, 3)
|
||||
put(dash + 76, (-127).toByte())
|
||||
}
|
||||
val t = GameTelemetry.parse(GameTelemetry.FORZA_PORT, data, data.size)!!
|
||||
assertEquals(1f, t.gLat!!, 1e-3f)
|
||||
assertEquals(-0.5f, t.gLon!!, 1e-3f)
|
||||
assertEquals(listOf(100f, 0f, 90f, 80f), t.tireTempsC!!.map { Math.round(it).toFloat() })
|
||||
assertEquals(81.5f, t.bestLapS!!, 1e-4f)
|
||||
assertEquals(-1f, t.steer!!, 1e-4f)
|
||||
}
|
||||
|
||||
@Test fun forzaWithoutTireDataLeavesThemOut() {
|
||||
val data = packet(311) { putInt(0, 1); put(232 + 75, 2) }
|
||||
assertNull(GameTelemetry.parse(GameTelemetry.FORZA_PORT, data, data.size)!!.tireTempsC)
|
||||
}
|
||||
|
||||
@Test fun outGaugeReadsTurboTemperaturesAndLights() {
|
||||
val data = packet(92) {
|
||||
put(10, 3)
|
||||
putFloat(20, 0.8f)
|
||||
putFloat(24, 92f)
|
||||
putFloat(36, 104f)
|
||||
putInt(40, GameTelemetry.DL_SHIFT or GameTelemetry.DL_ABS or GameTelemetry.DL_HANDBRAKE)
|
||||
putInt(44, GameTelemetry.DL_SHIFT or GameTelemetry.DL_ABS)
|
||||
}
|
||||
val t = GameTelemetry.parse(GameTelemetry.OUTGAUGE_PORT, data, data.size)!!
|
||||
assertEquals(0.8f, t.turboBar!!, 1e-4f)
|
||||
assertEquals(92f, t.engineTempC!!, 1e-4f)
|
||||
assertEquals(104f, t.oilTempC!!, 1e-4f)
|
||||
assertEquals(GameTelemetry.DL_SHIFT or GameTelemetry.DL_ABS, t.lights)
|
||||
}
|
||||
|
||||
// BeamNG leaves some OutGauge fields at zero; those stay hidden.
|
||||
@Test fun outGaugeZeroFieldsStayHidden() {
|
||||
val t = GameTelemetry.parse(GameTelemetry.OUTGAUGE_PORT, packet(92) { put(10, 2) }, 92)!!
|
||||
assertNull(t.turboBar)
|
||||
assertNull(t.engineTempC)
|
||||
assertNull(t.lights)
|
||||
}
|
||||
}
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [33])
|
||||
class GameStatusFilesTest {
|
||||
@Test fun warThunderShowsNumbersOnlyDuringAMatch() {
|
||||
assertEquals(emptyList<Pair<String, String>>(), GameStatusFiles.warThunder("""{"valid": false}"""))
|
||||
val rows = GameStatusFiles.warThunder("""{"valid": true, "H, m": 1520, "TAS, km/h": 512.4, "name": "x"}""")
|
||||
assertEquals(listOf("H, m" to "1520", "TAS, km/h" to "512.4"), rows)
|
||||
}
|
||||
|
||||
@Test fun warThunderKeepsEveryNumberForTheFlightLayout() {
|
||||
val json = buildString {
|
||||
append("{\"valid\": true")
|
||||
for (i in 0 until 20) append(", \"k$i\": $i")
|
||||
append(", \"IAS, km/h\": 512, \"throttle 1, %\": 110}")
|
||||
}
|
||||
val rows = GameStatusFiles.warThunder(json)
|
||||
assertEquals(22, rows.size)
|
||||
assertTrue(com.droiddeck.launcher.ui.FlightLabels.drawable(rows))
|
||||
assertEquals("110", rows.toMap()["throttle 1, %"])
|
||||
}
|
||||
|
||||
@Test fun eliteAtTheMenusShowsNothing() {
|
||||
assertNull(GameStatusFiles.elite("""{"timestamp": "2026-10-31T02:00:00Z", "event": "Status", "Flags": 0}"""))
|
||||
}
|
||||
|
||||
@Test fun eliteInFlight() {
|
||||
val e = GameStatusFiles.elite("""{"Flags": 16777240, "Pips": [4, 8, 0], "Fuel": {"FuelMain": 16.0, "FuelReservoir": 0.43},
|
||||
"Cargo": 2.0, "LegalState": "Clean", "Balance": 1234567}""")!!
|
||||
assertEquals(16.0, e.fuelMain!!, 0.001)
|
||||
assertEquals(listOf(4, 8, 0), e.pips)
|
||||
assertEquals("Clean", e.legal)
|
||||
assertEquals(1234567L, e.balance)
|
||||
}
|
||||
}
|
||||
@@ -88,6 +88,105 @@ class SessionSuspendControllerTest {
|
||||
assertTrue(disabled.pagedOut.isEmpty())
|
||||
}
|
||||
|
||||
@Test fun resumeReadsThePagedOutMemoryBack() {
|
||||
val fixture = fixture(17)
|
||||
fixture.control.writeText("0")
|
||||
fixture.controller.freeze(pageOut = true) { assertTrue(it) }
|
||||
val before = fixture.signals.size
|
||||
fixture.controller.resume { assertTrue(it) }
|
||||
val resumed = fixture.signals.drop(before)
|
||||
assertEquals(listOf(GAME), resumed.filter { it.signal == URG }.map { it.pid })
|
||||
assertTrue(resumed.indexOfLast { it.signal == CONT } < resumed.indexOfFirst { it.signal == URG })
|
||||
assertEquals("0", fixture.control.readText())
|
||||
assertEquals(listOf(Triple(1, 0L, 3_000_000L)), fixture.pagedIn)
|
||||
assertTrue(fixture.game.threads.all { it.state == 'S' })
|
||||
val again = fixture.signals.size
|
||||
fixture.controller.freeze { assertTrue(it) }
|
||||
fixture.controller.resume { assertTrue(it) }
|
||||
assertFalse(fixture.signals.drop(again).any { it.signal == URG })
|
||||
assertEquals(1, fixture.pagedIn.size)
|
||||
}
|
||||
|
||||
@Test fun noReadBackAfterAFreezeWithoutPageOut() {
|
||||
val fixture = fixture(17)
|
||||
fixture.control.writeText("0")
|
||||
fixture.controller.freeze { assertTrue(it) }
|
||||
fixture.controller.resume { assertTrue(it) }
|
||||
assertFalse(fixture.signals.any { it.signal == URG })
|
||||
assertTrue(fixture.pagedIn.isEmpty())
|
||||
}
|
||||
|
||||
@Test fun readBackIsSkippedWhenAvailableMemoryCannotTakeIt() {
|
||||
val fixture = fixture(17)
|
||||
fixture.control.writeText("0")
|
||||
fixture.availableKb = 3_500_000L
|
||||
fixture.controller.freeze(pageOut = true) { assertTrue(it) }
|
||||
val before = fixture.signals.size
|
||||
fixture.controller.resume { assertTrue(it) }
|
||||
assertFalse(fixture.signals.drop(before).any { it.signal == URG })
|
||||
assertEquals("1", fixture.control.readText())
|
||||
assertEquals(listOf(Triple(0, 3_000_000L, 3_000_000L)), fixture.pagedIn)
|
||||
}
|
||||
|
||||
@Test fun readBackNeedsTwiceTheSwapAvailable() {
|
||||
val fixture = fixture(17)
|
||||
fixture.control.writeText("0")
|
||||
fixture.availableKb = 5_500_000L
|
||||
fixture.controller.freeze(pageOut = true) { assertTrue(it) }
|
||||
val before = fixture.signals.size
|
||||
fixture.controller.resume { assertTrue(it) }
|
||||
assertFalse(fixture.signals.drop(before).any { it.signal == URG })
|
||||
assertEquals(listOf(Triple(0, 3_000_000L, 3_000_000L)), fixture.pagedIn)
|
||||
}
|
||||
|
||||
@Test fun readBackKeepsATenthOfMemTotalAvailable() {
|
||||
val fixture = fixture(17)
|
||||
fixture.control.writeText("0")
|
||||
fixture.totalKb = 40_000_000L
|
||||
fixture.availableKb = 6_500_000L
|
||||
fixture.controller.freeze(pageOut = true) { assertTrue(it) }
|
||||
val before = fixture.signals.size
|
||||
fixture.controller.resume { assertTrue(it) }
|
||||
assertFalse(fixture.signals.drop(before).any { it.signal == URG })
|
||||
assertEquals(listOf(Triple(0, 3_000_000L, 3_000_000L)), fixture.pagedIn)
|
||||
}
|
||||
|
||||
@Test fun noReadBackWithARamCap() {
|
||||
val fixture = fixture(17)
|
||||
fixture.control.writeText("0")
|
||||
fixture.readBackAllowed = false
|
||||
fixture.controller.freeze(pageOut = true) { assertTrue(it) }
|
||||
val before = fixture.signals.size
|
||||
fixture.controller.resume { assertTrue(it) }
|
||||
assertFalse(fixture.signals.drop(before).any { it.signal == URG })
|
||||
assertEquals("1", fixture.control.readText())
|
||||
assertEquals(listOf(Triple(0, 3_000_000L, 3_000_000L)), fixture.pagedIn)
|
||||
}
|
||||
|
||||
@Test fun cancelledFreezeReadsBackWhatThePageOutAlreadyMoved() {
|
||||
val fixture = fixture(17)
|
||||
fixture.control.writeText("0")
|
||||
fixture.afterSleep = { if (fixture.now >= 200 && fixture.signals.none { it.signal == STOP }) fixture.controller.cancelFreeze() }
|
||||
fixture.controller.freeze(pageOut = true) { assertFalse(it) }
|
||||
assertFalse(fixture.signals.any { it.signal == STOP })
|
||||
assertEquals(2, fixture.signals.count { it.signal == URG })
|
||||
assertEquals("0", fixture.control.readText())
|
||||
assertEquals(1, fixture.pagedIn.single().first)
|
||||
assertEquals(0L, fixture.pagedIn.single().second)
|
||||
assertTrue(fixture.pagedIn.single().third > 0L)
|
||||
}
|
||||
|
||||
@Test fun cancelledFreezeLeavesAPendingPageOutHandlerReadingBack() {
|
||||
val fixture = fixture(17)
|
||||
fixture.control.writeText("0")
|
||||
fixture.handlerStalls = true
|
||||
fixture.afterSleep = { if (fixture.now >= 500) fixture.controller.cancelFreeze() }
|
||||
fixture.controller.freeze(pageOut = true) { assertFalse(it) }
|
||||
assertEquals(2, fixture.signals.count { it.signal == URG })
|
||||
assertEquals("0", fixture.control.readText())
|
||||
assertEquals(Triple(1, 0L, 0L), fixture.pagedIn.single())
|
||||
}
|
||||
|
||||
@Test fun cpuMustBeStableAcrossTwoCompleteSnapshots() {
|
||||
val fixture = fixture(17)
|
||||
var changes = 0
|
||||
@@ -380,9 +479,14 @@ class SessionSuspendControllerTest {
|
||||
val clock = File(tmp, ".bl-clock")
|
||||
var clockAtContinue: Long? = null
|
||||
val pagedOut = mutableListOf<Triple<Int, Long, Long>>()
|
||||
val pagedIn = mutableListOf<Triple<Int, Long, Long>>()
|
||||
var availableKb = 8_000_000L
|
||||
var totalKb = 16_000_000L
|
||||
var readBackAllowed = true
|
||||
private var gameResidentKb = 4_000_000L
|
||||
private var gameSwapKb = 0L
|
||||
private var pagingOut = false
|
||||
private var pagingIn = false
|
||||
var unacknowledged = -1
|
||||
var handlerStalls = false
|
||||
var handlerReplaced = false
|
||||
@@ -397,6 +501,8 @@ class SessionSuspendControllerTest {
|
||||
pagedOut += Triple(processes, resident, swap)
|
||||
this.unacknowledged = unacknowledged
|
||||
},
|
||||
readBackAllowed = { readBackAllowed },
|
||||
pagedIn = { processes, swap, swapBefore, _, _ -> pagedIn += Triple(processes, swap, swapBefore) },
|
||||
)
|
||||
|
||||
init { sync() }
|
||||
@@ -411,7 +517,7 @@ class SessionSuspendControllerTest {
|
||||
it.state !in listOf('T', 't', 'Z', 'X') && !(neverStop && it == game.threads.last())
|
||||
}?.state = 't'
|
||||
} else if (signal == URG) {
|
||||
pagingOut = true
|
||||
if (control.readText() == "0") { pagingOut = false; pagingIn = true } else pagingOut = true
|
||||
} else if (signal == CONT) {
|
||||
if (clockAtContinue == null && clock.isFile) {
|
||||
clockAtContinue = ByteBuffer.wrap(clock.readBytes()).order(ByteOrder.LITTLE_ENDIAN).long
|
||||
@@ -445,6 +551,12 @@ class SessionSuspendControllerTest {
|
||||
pagingOut = false
|
||||
}
|
||||
}
|
||||
if (pagingIn) {
|
||||
val moved = minOf(gameSwapKb, 1_000_000L)
|
||||
gameSwapKb -= moved
|
||||
gameResidentKb += moved
|
||||
if (gameSwapKb == 0L) pagingIn = false
|
||||
}
|
||||
if (root.threads.first().state != 'T' && !continuing) game.threads.forEach {
|
||||
if (it.state != 'Z') { it.state = 'S'; it.cpu++ }
|
||||
}
|
||||
@@ -453,6 +565,7 @@ class SessionSuspendControllerTest {
|
||||
}
|
||||
|
||||
fun sync() {
|
||||
File(proc, "meminfo").writeText("MemTotal:\t$totalKb kB\nMemFree:\t1000 kB\nMemAvailable:\t$availableKb kB\n")
|
||||
for (group in groups) {
|
||||
val dir = File(proc, group.pid.toString())
|
||||
if (group == root && rootGone) { dir.deleteRecursively(); continue }
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
|
||||
class StatsLayoutTest {
|
||||
@Test fun unknownIdsFallBackToTheDefaults() {
|
||||
assertEquals(StatsStrip.PANEL, StatsStrip.from(null))
|
||||
assertEquals(StatsStrip.RINGS, StatsStrip.from("rings"))
|
||||
assertEquals(StatsDash.AUTO, StatsDash.from("gone"))
|
||||
assertEquals(StatsDash.TRACE, StatsDash.from("trace"))
|
||||
}
|
||||
|
||||
@Test fun tappingTheStripCyclesThroughEveryStyle() {
|
||||
assertEquals(StatsStrip.TILES, StatsStrip.PANEL.next())
|
||||
assertEquals(StatsStrip.RINGS, StatsStrip.TILES.next())
|
||||
assertEquals(StatsStrip.PANEL, StatsStrip.RINGS.next())
|
||||
}
|
||||
|
||||
@Test fun autoPicksTheDashByTheGamesFormat() {
|
||||
assertEquals(StatsDash.SPEEDOMETER, StatsDash.AUTO.resolve("Codemasters"))
|
||||
assertEquals(StatsDash.CIRCUIT, StatsDash.AUTO.resolve("Forza"))
|
||||
assertEquals(StatsDash.DIALS, StatsDash.AUTO.resolve("OutGauge"))
|
||||
assertEquals(StatsDash.TRACE, StatsDash.TRACE.resolve("Forza"))
|
||||
}
|
||||
|
||||
@Test fun tappingTheDashMovesOnFromTheOneOnScreen() {
|
||||
assertEquals(StatsDash.CIRCUIT, StatsDash.tapped(StatsDash.SPEEDOMETER))
|
||||
assertEquals(StatsDash.SPEEDOMETER, StatsDash.tapped(StatsDash.GLANCE))
|
||||
assertEquals(StatsDash.SPEEDOMETER, StatsDash.tapped(StatsDash.AUTO))
|
||||
}
|
||||
|
||||
@Test fun automaticSpeedUnitsFollowTheRegion() {
|
||||
assertEquals(SpeedUnit.MPH, SpeedUnit.AUTO.resolve("US"))
|
||||
assertEquals(SpeedUnit.MPH, SpeedUnit.AUTO.resolve("gb"))
|
||||
assertEquals(SpeedUnit.KMH, SpeedUnit.AUTO.resolve("DE"))
|
||||
assertEquals(SpeedUnit.KMH, SpeedUnit.AUTO.resolve(""))
|
||||
assertEquals(SpeedUnit.KMH, SpeedUnit.KMH.resolve("US"))
|
||||
assertEquals(SpeedUnit.MPH, SpeedUnit.MPH.resolve("DE"))
|
||||
}
|
||||
|
||||
@Test fun speedUnitsCycleAndConvert() {
|
||||
assertEquals(SpeedUnit.AUTO, SpeedUnit.from(null))
|
||||
assertEquals(SpeedUnit.MPH, SpeedUnit.from("mph"))
|
||||
assertEquals(SpeedUnit.KMH, SpeedUnit.AUTO.next())
|
||||
assertEquals(SpeedUnit.MPH, SpeedUnit.KMH.next())
|
||||
assertEquals(SpeedUnit.AUTO, SpeedUnit.MPH.next())
|
||||
assertEquals(62.1f, 100f * SpeedUnit.MPH.perKmh, 0.05f)
|
||||
assertEquals(100f, 100f * SpeedUnit.KMH.perKmh, 0f)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
class SteamDownloadsTest {
|
||||
private fun manifest(flags: Long, done: Long, total: Long) = """
|
||||
"AppState"
|
||||
{
|
||||
"appid" "220"
|
||||
"name" "Half-Life 2"
|
||||
"StateFlags" "$flags"
|
||||
"BytesToDownload" "$total"
|
||||
"BytesDownloaded" "$done"
|
||||
}
|
||||
""".trimIndent()
|
||||
|
||||
@Test fun anAppUnfinishedInBothSteamHomesIsListedOnce() {
|
||||
val arm = SteamDownload("220", "Half-Life 2", 10L, 100L)
|
||||
val x86 = SteamDownload("220", "Half-Life 2", 60L, 100L)
|
||||
val other = SteamDownload("440", "Team Fortress 2", 5L, 50L)
|
||||
assertEquals(listOf(x86, other), SteamDownloads.onePerApp(listOf(arm, x86, other)))
|
||||
}
|
||||
|
||||
@Test fun anInstalledGameIsNotADownload() {
|
||||
assertNull(SteamDownloads.fromManifest("220", "Half-Life 2", manifest(4, 100, 100)))
|
||||
}
|
||||
|
||||
@Test fun aRunningUpdateShowsItsBytes() {
|
||||
val d = SteamDownloads.fromManifest("220", "Half-Life 2", manifest(1026, 40, 100))!!
|
||||
assertEquals(40L, d.done)
|
||||
assertEquals(100L, d.total)
|
||||
}
|
||||
|
||||
@Test fun aPausedUpdateSaysSo() {
|
||||
assertTrue(SteamDownloads.fromManifest("220", "Half-Life 2", manifest(514, 40, 100))!!.paused)
|
||||
}
|
||||
|
||||
@Test fun anUpdateNotSizedYetIsStillListed() {
|
||||
assertEquals(0L, SteamDownloads.fromManifest("220", "Half-Life 2", manifest(6, 0, 0))!!.total)
|
||||
}
|
||||
|
||||
@Test fun onlyShaderUpdatesStillRunningCount() {
|
||||
val log = sequenceOf(
|
||||
"[2026-10-30 06:33:02] AppID 220 Shader update changed : Running Update,Downloading,",
|
||||
"[2026-10-30 06:33:02] AppID 440 Shader update changed : Running Update,",
|
||||
"[2026-10-30 06:33:03] AppID 440 Shader update changed : None",
|
||||
"[2026-10-30 06:33:03] AppID 570 App update changed : Running Update,",
|
||||
)
|
||||
assertEquals(listOf("220"), SteamDownloads.runningShaderUpdates(log))
|
||||
}
|
||||
|
||||
@Test fun aClientRestartForgetsOlderShaderUpdates() {
|
||||
val log = sequenceOf(
|
||||
"[2026-10-30 06:33:02] AppID 220 Shader update changed : Running Update,",
|
||||
"[2026-10-30 07:00:00] Client version: 1761000000",
|
||||
)
|
||||
assertEquals(emptyList<String>(), SteamDownloads.runningShaderUpdates(log))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Test
|
||||
|
||||
class SteamWebLoginTest {
|
||||
private fun hex(s: String) = ByteArray(s.length / 2) { s.substring(it * 2, it * 2 + 2).toInt(16).toByte() }
|
||||
|
||||
// Made with: openssl enc -aes-128-cbc -K <PBKDF2-SHA1("peanuts","saltysalt",1)> -iv <16 spaces>, prefixed "v10".
|
||||
@Test fun chromiumV10ValuesDecrypt() {
|
||||
val encrypted = hex("7631300b9cf0a6eee9cf1aaac601b85ca37cf9fe9e67078564f0e05835ae2aa3d9b0ab")
|
||||
assertEquals("0123456789abcdef01234567", SteamWebLogin.decrypt(encrypted, hostHashed = false))
|
||||
}
|
||||
|
||||
@Test fun newerStoresDropTheHostHash() {
|
||||
val encrypted = hex("7631304d4114329f1e692e807b8b044d67460f5e14d92ffb48b9f83be318ebd0d84c727674aea32f351b8a33c8aa42553dfeb5")
|
||||
assertEquals("hello", SteamWebLogin.decrypt(encrypted, hostHashed = true))
|
||||
}
|
||||
|
||||
@Test fun otherFormatsAreSkipped() {
|
||||
assertNull(SteamWebLogin.decrypt("v11garbage".toByteArray(), hostHashed = false))
|
||||
assertNull(SteamWebLogin.decrypt(ByteArray(2), hostHashed = false))
|
||||
}
|
||||
|
||||
@Test fun theSignInIsSentTheWaySteamPagesSendIt() {
|
||||
assertEquals("steamLoginSecure=76561190000000000%7C%7Ca.b.c; Path=/; Secure; HttpOnly",
|
||||
SteamWebLogin.header("steamLoginSecure", "76561190000000000||a.b.c", httpOnly = true))
|
||||
assertEquals("sessionid=0123; Path=/; Secure", SteamWebLogin.header("sessionid", "0123", httpOnly = false))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
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 java.io.File
|
||||
|
||||
class TelemetryOutputTest {
|
||||
@get:Rule val tmp = TemporaryFolder()
|
||||
|
||||
// DiRT Showdown's own line, as found in its prefix on the Retroid Pocket Duo.
|
||||
private val showdown = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n<hardware_settings_config>\n" +
|
||||
"\t<audio mono=\"false\" />\n\t<motion enabled=\"true\" ip=\"dbox\" port=\"20777\" delay=\"1\" extradata=\"0\" />\n" +
|
||||
"</hardware_settings_config>\n"
|
||||
|
||||
@Test fun turningOnPointsTheMotionLineHereAndKeepsTheRest() {
|
||||
val on = TelemetryOutput.turnedOn(showdown)!!
|
||||
assertTrue(on.contains("<motion enabled=\"true\" ip=\"127.0.0.1\" port=\"20777\" delay=\"1\" extradata=\"3\" />"))
|
||||
assertEquals(showdown.replace("ip=\"dbox\"", "ip=\"127.0.0.1\"").replace("extradata=\"0\"", "extradata=\"3\""), on)
|
||||
assertTrue(TelemetryOutput.pointsHere(TelemetryOutput.element(on)!!.value))
|
||||
assertFalse(TelemetryOutput.pointsHere(TelemetryOutput.element(showdown)!!.value))
|
||||
}
|
||||
|
||||
@Test fun theUdpLineWinsOverTheMotionLineAndLongerTagsAreIgnored() {
|
||||
val xml = "<x><motion_platform><dbox enabled=\"true\" /></motion_platform>" +
|
||||
"<motion enabled=\"true\" ip=\"dbox\" port=\"20777\" />" +
|
||||
"<udp enabled=\"false\" extradata=\"0\" ip=\"127.0.0.1\" port=\"20777\" delay=\"1\" /></x>"
|
||||
assertTrue(TelemetryOutput.element(xml)!!.value.startsWith("<udp "))
|
||||
val on = TelemetryOutput.turnedOn(xml)!!
|
||||
assertTrue(on.contains("<udp enabled=\"true\" extradata=\"3\" ip=\"127.0.0.1\" port=\"20777\" delay=\"1\" />"))
|
||||
assertTrue(on.contains("<motion enabled=\"true\" ip=\"dbox\" port=\"20777\" />"))
|
||||
assertNull(TelemetryOutput.element("<x><motion_platform enabled=\"true\" /></x>"))
|
||||
}
|
||||
|
||||
@Test fun turningOffPutsTheOriginalLineBackOrSwitchesItOff() {
|
||||
val on = TelemetryOutput.turnedOn(showdown)!!
|
||||
assertEquals(showdown, TelemetryOutput.turnedOff(on, showdown))
|
||||
assertTrue(TelemetryOutput.turnedOff(on, null)!!.contains("<motion enabled=\"false\" ip=\"127.0.0.1\""))
|
||||
}
|
||||
|
||||
@Test fun missingAttributesAreAdded() {
|
||||
assertEquals("<udp enabled=\"true\" ip=\"127.0.0.1\" />", TelemetryOutput.withAttr("<udp enabled=\"true\" />", "ip", "127.0.0.1"))
|
||||
assertEquals("<udp a=\"1\" port=\"20777\">", TelemetryOutput.withAttr("<udp a=\"1\">", "port", "20777"))
|
||||
assertTrue(TelemetryOutput.pointsHere("<udp enabled=\"true\" ip=\"127.0.0.1\" port=\"20777\" />"))
|
||||
}
|
||||
|
||||
@Test fun scanFindsTheGameAndARoundTripRestoresTheFile() {
|
||||
val compatdata = tmp.newFolder("steamapps", "compatdata")
|
||||
val config = configFile(compatdata, "2848447563", "DiRT Showdown")
|
||||
config.writeText(showdown)
|
||||
configFile(compatdata, "12345", "Some Other Game").writeText("<hardware_settings_config />")
|
||||
|
||||
val games = TelemetryOutput.scan(listOf(compatdata))
|
||||
assertEquals(listOf("DiRT Showdown"), games.map { it.name })
|
||||
assertEquals("2848447563", games[0].prefixId)
|
||||
assertFalse(games[0].on)
|
||||
|
||||
assertTrue(TelemetryOutput.set(games[0], true))
|
||||
assertTrue(File(config.path + TelemetryOutput.ORIGINAL_SUFFIX).isFile)
|
||||
assertTrue(TelemetryOutput.scan(listOf(compatdata))[0].on)
|
||||
|
||||
assertTrue(TelemetryOutput.set(games[0], false))
|
||||
assertEquals(showdown, config.readText())
|
||||
assertFalse(File(config.path + TelemetryOutput.ORIGINAL_SUFFIX).exists())
|
||||
assertFalse(TelemetryOutput.scan(listOf(compatdata))[0].on)
|
||||
}
|
||||
|
||||
@Test fun theRunningGameIsMatchedByItsPrefixId() {
|
||||
assertTrue(TelemetryOutput.isRunning("2848447563", "2848447563"))
|
||||
assertTrue(TelemetryOutput.isRunning("-1446519733", "2848447563"))
|
||||
assertFalse(TelemetryOutput.isRunning("2848447563", "690790"))
|
||||
assertFalse(TelemetryOutput.isRunning("2848447563", null))
|
||||
assertTrue(TelemetryOutput.isRunning("2848447563", "program:/games/x.exe"))
|
||||
}
|
||||
|
||||
@Test fun automaticSkipsGamesThatAreOnSwitchedOffOrRunning() {
|
||||
val f = File("x")
|
||||
val dirt4 = TelemetryOutput.Game("DiRT 4", "421020", f, on = false)
|
||||
val rally = TelemetryOutput.Game("DiRT Rally 2.0", "690790", f, on = false)
|
||||
val grid = TelemetryOutput.Game("GRID", "703860", f, on = true)
|
||||
val games = listOf(dirt4, rally, grid)
|
||||
assertEquals(listOf(dirt4, rally), TelemetryOutput.automaticTargets(games, emptySet(), null))
|
||||
assertEquals(listOf(rally), TelemetryOutput.automaticTargets(games, setOf("421020/DiRT 4"), null))
|
||||
assertEquals(listOf(dirt4), TelemetryOutput.automaticTargets(games, emptySet(), "690790"))
|
||||
assertEquals("690790/DiRT Rally 2.0", TelemetryOutput.key(rally))
|
||||
}
|
||||
|
||||
@Test fun switchingAutomaticOffRestoresOnlyGamesDroidDeckChanged() {
|
||||
val compatdata = tmp.newFolder("steamapps", "compatdata")
|
||||
val changed = configFile(compatdata, "2848447563", "DiRT Showdown").apply { writeText(showdown) }
|
||||
val own = configFile(compatdata, "690790", "DiRT Rally 2.0")
|
||||
.apply { writeText("<x><udp enabled=\"true\" ip=\"127.0.0.1\" port=\"20777\" /></x>") }
|
||||
assertTrue(TelemetryOutput.set(TelemetryOutput.scan(listOf(compatdata)).first { it.name == "DiRT Showdown" }, true))
|
||||
val targets = TelemetryOutput.restoreTargets(TelemetryOutput.scan(listOf(compatdata)), null)
|
||||
assertEquals(listOf(changed), targets.map { it.file })
|
||||
assertTrue(own.isFile)
|
||||
assertTrue(TelemetryOutput.restoreTargets(TelemetryOutput.scan(listOf(compatdata)), "2848447563").isEmpty())
|
||||
}
|
||||
|
||||
@Test fun automaticTurnsOnDirt3AndShowdownLikeTheOtherGames() {
|
||||
val f = File("x")
|
||||
val showdownGame = TelemetryOutput.Game("DiRT Showdown", "2848447563", f, on = false)
|
||||
val dirt3 = TelemetryOutput.Game("DiRT3", "321040", f, on = false)
|
||||
val rally = TelemetryOutput.Game("DiRT Rally 2.0", "690790", f, on = false)
|
||||
assertEquals(listOf(showdownGame, dirt3, rally), TelemetryOutput.automaticTargets(listOf(showdownGame, dirt3, rally), emptySet(), null))
|
||||
assertEquals(listOf(rally), TelemetryOutput.automaticTargets(listOf(showdownGame, dirt3, rally), setOf("2848447563/DiRT Showdown", "321040/DiRT3"), null))
|
||||
}
|
||||
|
||||
private fun configFile(compatdata: File, id: String, game: String): File =
|
||||
File(compatdata, "$id/pfx/drive_c/users/steamuser/Documents/My Games/$game/hardwaresettings/hardware_settings_config.xml")
|
||||
.apply { parentFile!!.mkdirs() }
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
class BottomChatPageTest {
|
||||
@Test fun steamSitesOpenOthersDoNot() {
|
||||
assertTrue(steamChatAllows("steamcommunity.com"))
|
||||
assertTrue(steamChatAllows("login.steampowered.com"))
|
||||
assertTrue(steamChatAllows("steam-chat.com"))
|
||||
assertTrue(steamChatAllows("community.cloudflare.steamstatic.com"))
|
||||
assertFalse(steamChatAllows("steamcommunity.com.example.net"))
|
||||
assertFalse(steamChatAllows("evilsteamcommunity.com"))
|
||||
assertFalse(steamChatAllows(null))
|
||||
}
|
||||
|
||||
@Test fun chatFitScriptUsesADotDecimalInEveryLocale() {
|
||||
val before = java.util.Locale.getDefault()
|
||||
try {
|
||||
java.util.Locale.setDefault(java.util.Locale.GERMANY)
|
||||
val js = steamChatFitScript(821, 0.75f)
|
||||
assertTrue(js.contains("m.content='width=821, initial-scale=0.75'"))
|
||||
assertTrue(js.contains("s.textContent='$STEAM_CHAT_FIT_CSS'"))
|
||||
assertFalse(STEAM_CHAT_FIT_CSS.contains('\''))
|
||||
} finally {
|
||||
java.util.Locale.setDefault(before)
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun theGroupChatListLeavesRoomForTheOnlineFriends() {
|
||||
assertTrue(STEAM_CHAT_FIT_CSS.contains(".ChatRoomList_Empty{display:none!important}"))
|
||||
assertTrue(STEAM_CHAT_FIT_CSS.contains(".chatRoomListContainer{height:auto!important;max-height:25vh!important}"))
|
||||
assertTrue(STEAM_CHAT_FIT_CSS.contains(".chat_main>:has(~.chat_main_flex){display:none!important}"))
|
||||
}
|
||||
|
||||
@Test fun desktopAgentKeepsTheWebViewChromeVersion() {
|
||||
val ua = desktopUserAgent("Mozilla/5.0 (Linux; Android 15; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/141.0.7390.122 Mobile Safari/537.36")
|
||||
assertEquals("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.7390.122 Safari/537.36", ua)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
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 BottomDashboardTest {
|
||||
@Test fun theRememberedPageOpensAgain() {
|
||||
assertEquals("shots", pickBottomPage("shots", listOf("downloads", "shots")))
|
||||
}
|
||||
|
||||
@Test fun aGoneOrMissingPageFallsBackToTheFirst() {
|
||||
assertEquals("downloads", pickBottomPage("gone", listOf("downloads", "shots")))
|
||||
assertEquals("downloads", pickBottomPage(null, listOf("downloads", "shots")))
|
||||
assertNull(pickBottomPage("shots", emptyList()))
|
||||
}
|
||||
|
||||
@Test fun withNothingPickedTheChatOpens() {
|
||||
val ids = listOf("telemetry", "downloads", "notifications", "screenshots", "chat")
|
||||
assertEquals("chat", pickBottomPage(null, ids))
|
||||
assertEquals("chat", pickBottomPage("gone", ids))
|
||||
assertEquals("telemetry", pickBottomPage("telemetry", ids))
|
||||
assertEquals("screenshots", pickBottomPage("screenshots", ids))
|
||||
}
|
||||
|
||||
@Test fun aGameStartShowsTheInGameStats() {
|
||||
assertEquals("telemetry", pageForGameStart(listOf("telemetry", "downloads", "chat")))
|
||||
assertNull(pageForGameStart(listOf("downloads", "chat")))
|
||||
}
|
||||
|
||||
@Test fun tabNamesShowOnlyWhileEveryTabFits() {
|
||||
// Retroid Pocket Duo bottom panel: 1280x960 at 320 dpi = 640 dp wide.
|
||||
assertTrue(bottomTabsWithLabels(640f, 4))
|
||||
assertFalse(bottomTabsWithLabels(640f, 5))
|
||||
assertFalse(bottomTabsWithLabels(360f, 3))
|
||||
}
|
||||
}
|
||||
|
||||
class BottomDownloadsRateTest {
|
||||
@Test fun rateIsBytesPerSecondBetweenReads() {
|
||||
assertEquals(1_000_000L, downloadRate(0L, 0L, 2_000_000L, 2_000L))
|
||||
}
|
||||
|
||||
@Test fun noMovementOrARestartIsZero() {
|
||||
assertEquals(0L, downloadRate(500L, 0L, 500L, 2_000L))
|
||||
assertEquals(0L, downloadRate(500L, 0L, 100L, 2_000L))
|
||||
assertEquals(0L, downloadRate(-1L, 0L, 100L, 2_000L))
|
||||
}
|
||||
}
|
||||
|
||||
class BottomTelemetryLapTimeTest {
|
||||
@Test fun lapTimesReadAsMinutesSecondsMillis() {
|
||||
assertEquals("1:23.456", lapTime(83.456f))
|
||||
assertEquals("0:05.000", lapTime(5f))
|
||||
}
|
||||
|
||||
@Test fun eachSessionStartsWithoutAPickedTab() {
|
||||
SessionBottomTab.pick("2026-11-01-01-steam", "screenshots")
|
||||
assertEquals("screenshots", SessionBottomTab.picked("2026-11-01-01-steam"))
|
||||
assertNull(SessionBottomTab.picked("2026-11-01-02-steam"))
|
||||
assertNull(SessionBottomTab.picked(null))
|
||||
assertEquals("chat", pickBottomPage(SessionBottomTab.picked("2026-11-01-02-steam"), listOf("telemetry", "chat", "screenshots")))
|
||||
}
|
||||
|
||||
@Test fun theStripNamesTheSteamClient() {
|
||||
assertEquals(com.droiddeck.launcher.R.string.stats_steam_client_x86, steamClientLabel("x86_64"))
|
||||
assertEquals(com.droiddeck.launcher.R.string.stats_steam_client_arm, steamClientLabel("arm64"))
|
||||
}
|
||||
}
|
||||
@@ -52,6 +52,22 @@ class DualScreenPanelOwnerTest {
|
||||
assertEquals(10, DualScreenPanel.focusTask(fromPanel = true))
|
||||
}
|
||||
|
||||
@Test fun aScreenFromAnotherAppKeepsTheTopScreenAfterABottomScreenTouch() {
|
||||
DualScreenPanel.show(app, 2, 10)
|
||||
assertTrue(DualScreenPanel.opensOutside("com.droiddeck.launcher", "com.android.packageinstaller"))
|
||||
DualScreenPanel.yieldTo(10, true)
|
||||
DualScreenPanel.ownerPaused(10, true)
|
||||
assertNull(DualScreenPanel.focusTask(fromPanel = true))
|
||||
DualScreenPanel.ownerPaused(10, false)
|
||||
DualScreenPanel.yieldTo(10, false)
|
||||
assertEquals(10, DualScreenPanel.focusTask(fromPanel = true))
|
||||
}
|
||||
|
||||
@Test fun droidDecksOwnScreensAndUnresolvedIntentsDoNotYield() {
|
||||
assertFalse(DualScreenPanel.opensOutside("com.droiddeck.launcher", "com.droiddeck.launcher"))
|
||||
assertFalse(DualScreenPanel.opensOutside("com.droiddeck.launcher", null))
|
||||
}
|
||||
|
||||
@Test fun anotherTasksPauseDoesNotStopThePanelReturningFocus() {
|
||||
DualScreenPanel.show(app, 2, 10)
|
||||
DualScreenPanel.ownerPaused(11, true)
|
||||
@@ -65,13 +81,4 @@ class DualScreenPanelOwnerTest {
|
||||
DualScreenPanel.show(app, 2, 10)
|
||||
assertEquals(10, DualScreenPanel.focusTask(fromPanel = false))
|
||||
}
|
||||
|
||||
@Test fun thePanelTookFocusWhenItJustOpenedOrWasJustTouched() {
|
||||
assertTrue(DualScreenPanel.tookFocus(fresh = true, touchedAt = Long.MIN_VALUE, now = 5_000L))
|
||||
assertTrue(DualScreenPanel.tookFocus(fresh = false, touchedAt = 4_700L, now = 5_000L))
|
||||
assertTrue(DualScreenPanel.tookFocus(fresh = false, touchedAt = 5_000L, now = 5_000L))
|
||||
assertFalse(DualScreenPanel.tookFocus(fresh = false, touchedAt = 3_500L, now = 5_000L))
|
||||
assertFalse(DualScreenPanel.tookFocus(fresh = false, touchedAt = Long.MIN_VALUE, now = 5_000L))
|
||||
assertFalse(DualScreenPanel.tookFocus(fresh = false, touchedAt = 6_000L, now = 5_000L))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user