mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-19 12:56:06 +00:00
feat: add persistent per-game compatibility profiles (#449)
* feat(profiles): add persistent per-game compatibility profiles * fix(profiles): show Windows component overrides Include per-game Windows component selections in the resolved profile summary so the session overlay marks those games as custom and shows the selected components. * fix(session): detect Proton games across runtime paths * fix(profiles): select the active Gamescope game * fix(profiles): improve per-game reset feedback * fix(profiles): align session components with game overrides * fix(session): prefer selected Steam game during refresh * fix(session): resume profile following when reopening games * chore: keep local dev testing outside the repository * test(session): remove local dev package path * fix(session): preserve profiles when refresh fails * fix(session): reject empty game profile reset scope * perf(session): cache drawer inventory by refresh revision * fix(profiles): align game presets and profile reset behavior * fix(profiles): preserve originals and normalize shortcut ids * fix(profiles): keep editor scope stable after rebase * fix(tests): host Compose tests in both build variants * fix(profiles): recover interrupted component selection saves --------- Co-authored-by: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com>
This commit is contained in:
1 parent
ef4807fbd0
commit
55c51f843e
46 files changed
+3501
-150
No files matched your search
@@ -0,0 +1,88 @@
|
||||
package com.droiddeck.launcher.agent
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Test
|
||||
|
||||
class AgentGuestSelectionTest {
|
||||
private val installedAppIds = setOf(646570L, 3180310L)
|
||||
|
||||
@Test fun focusedInstalledGameIsSelected() {
|
||||
assertEquals(3180310L, AgentGuest.focusedInstalledSteamAppId(3180310L, installedAppIds))
|
||||
}
|
||||
|
||||
@Test fun focusedInstalledGameIsActive() {
|
||||
assertEquals(
|
||||
3180310L,
|
||||
AgentGuest.activeInstalledSteamAppId(3180310L, listOf(769L, 3180310L), installedAppIds),
|
||||
)
|
||||
}
|
||||
|
||||
@Test fun selectedSteamGameWinsOverStaleActiveSteamGame() {
|
||||
assertEquals(
|
||||
646570L,
|
||||
AgentGuest.preferredInstalledSteamAppId(646570L, 3180310L, installedAppIds),
|
||||
)
|
||||
}
|
||||
|
||||
@Test fun validGamescopeGameFallsBackWhenSteamSelectionFails() {
|
||||
assertEquals(
|
||||
3180310L,
|
||||
AgentGuest.selectedOrActiveInstalledSteamAppId(
|
||||
Result.failure(IllegalStateException("agent unavailable")),
|
||||
3180310L,
|
||||
installedAppIds,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
@Test fun absentSelectionAndActiveGameRemainAValidNoSelection() {
|
||||
assertNull(AgentGuest.selectedOrActiveInstalledSteamAppId(Result.success(null), null, installedAppIds))
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException::class)
|
||||
fun selectionFailureWithoutGamescopeFallbackRemainsAnError() {
|
||||
AgentGuest.selectedOrActiveInstalledSteamAppId(
|
||||
Result.failure(IllegalStateException("agent unavailable")),
|
||||
null,
|
||||
installedAppIds,
|
||||
)
|
||||
}
|
||||
|
||||
@Test fun soleFocusableInstalledGameRemainsActiveUnderSteamOverlay() {
|
||||
assertEquals(
|
||||
3180310L,
|
||||
AgentGuest.activeInstalledSteamAppId(769L, listOf(3180310L), installedAppIds),
|
||||
)
|
||||
}
|
||||
|
||||
@Test fun ambiguousFocusableGamesAreIgnored() {
|
||||
assertNull(
|
||||
AgentGuest.activeInstalledSteamAppId(769L, listOf(646570L, 3180310L), installedAppIds),
|
||||
)
|
||||
}
|
||||
|
||||
@Test fun soleBaselayerGameResolvesAmbiguousSteamOverlayFocus() {
|
||||
assertEquals(
|
||||
646570L,
|
||||
AgentGuest.activeInstalledSteamAppId(
|
||||
focusedAppId = 769L,
|
||||
focusableAppIds = listOf(646570L, 3180310L),
|
||||
installedAppIds = installedAppIds,
|
||||
baselayerAppIds = listOf(769L, 646570L),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
@Test fun steamClientFocusIsIgnored() {
|
||||
assertNull(AgentGuest.focusedInstalledSteamAppId(769L, installedAppIds))
|
||||
}
|
||||
|
||||
@Test fun unknownGameFocusIsIgnored() {
|
||||
assertNull(AgentGuest.focusedInstalledSteamAppId(42L, installedAppIds))
|
||||
}
|
||||
|
||||
@Test fun missingFocusSnapshotIsIgnored() {
|
||||
assertNull(AgentGuest.focusedInstalledSteamAppId(null, installedAppIds))
|
||||
}
|
||||
}
|
||||
@@ -102,4 +102,24 @@ class GameEnvironmentTest {
|
||||
assertTrue(GameEnvironment.validScope("4294967295"))
|
||||
for (scope in listOf("0", "-1", "01", "+1", "4294967296", "../42")) assertFalse(GameEnvironment.validScope(scope))
|
||||
}
|
||||
|
||||
@Test fun gameFexPresetOverridesGeneralAndCanInheritAgain() {
|
||||
val performance = GameEnvironment.withGameFexPreset(GameEnvironment.Config(), "42", "PERFORMANCE")
|
||||
assertEquals("PERFORMANCE", GameEnvironment.gameFexPreset(performance, "42"))
|
||||
assertEquals("0", GameEnvironment.effective(performance, "STABILITY", "42")["FEX_TSOENABLED"])
|
||||
assertEquals("1", GameEnvironment.effective(performance, "STABILITY", "43")["FEX_TSOENABLED"])
|
||||
|
||||
val inherited = GameEnvironment.withGameFexPreset(performance, "42", null)
|
||||
assertNull(GameEnvironment.gameFexPreset(inherited, "42"))
|
||||
assertFalse(inherited.games.containsKey("42"))
|
||||
}
|
||||
|
||||
@Test fun gameFexPresetPreservesOtherOverridesAndRecognizesCustomValues() {
|
||||
val original = GameEnvironment.Config(games = mapOf("42" to mapOf("CUSTOM" to "value", "FEX_MULTIBLOCK" to "7")))
|
||||
assertEquals(GameEnvironment.CUSTOM_FEX_PRESET, GameEnvironment.gameFexPreset(original, "42"))
|
||||
|
||||
val compatibility = GameEnvironment.withGameFexPreset(original, "42", "COMPATIBILITY")
|
||||
assertEquals("value", compatibility.games.getValue("42")["CUSTOM"])
|
||||
assertEquals("COMPATIBILITY", GameEnvironment.gameFexPreset(compatibility, "42"))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
class ComponentsProcessTest {
|
||||
private val guestPath = "/root/.local/share/Steam/steamapps/common/Proton"
|
||||
private val hostPath = "/data/user/0/com.droiddeck.launcher/files/root/root/.local/share/Steam/steamapps/common/Proton"
|
||||
|
||||
@Test
|
||||
fun `running game is recognized through guest path`() {
|
||||
val command = "python3 $guestPath/proton waitforexitandrun game.exe"
|
||||
|
||||
assertTrue(ComponentsManager.processUsesProton(listOf(guestPath, hostPath), command, gameOnly = true))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `running game is recognized through Android host path`() {
|
||||
val command = "python3 $hostPath/proton waitforexitandrun game.exe"
|
||||
|
||||
assertTrue(ComponentsManager.processUsesProton(listOf(guestPath, hostPath), command, gameOnly = true))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Steam startup Proton process is not reported as a running game`() {
|
||||
val command = "python3 $hostPath/proton run wineboot.exe"
|
||||
|
||||
assertFalse(ComponentsManager.processUsesProton(listOf(guestPath, hostPath), command, gameOnly = true))
|
||||
assertTrue(ComponentsManager.processUsesProton(listOf(guestPath, hostPath), command, gameOnly = false))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `unrelated Proton process is ignored`() {
|
||||
val command = "python3 /other/Proton/proton waitforexitandrun game.exe"
|
||||
|
||||
assertFalse(ComponentsManager.processUsesProton(listOf(guestPath, hostPath), command, gameOnly = true))
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,10 @@ package com.droiddeck.launcher.session
|
||||
|
||||
import android.content.Context
|
||||
import com.droiddeck.launcher.gpu.GpuInfo
|
||||
import com.droiddeck.launcher.core.Hashes
|
||||
import com.droiddeck.launcher.runtime.LinuxRuntime
|
||||
import com.github.luben.zstd.ZstdOutputStream
|
||||
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONObject
|
||||
import org.junit.Assert.*
|
||||
@@ -89,6 +92,283 @@ class ForcedPackageTest {
|
||||
assertNull(install(gpu(650, GpuInfo.Family.A6XX)))
|
||||
}
|
||||
|
||||
@Test fun gameComponentProfilesReadOnlyKnownComponents() {
|
||||
val state = File(context.filesDir, "components/state.json")
|
||||
state.parentFile!!.mkdirs()
|
||||
state.writeText(JSONObject()
|
||||
.put("active", JSONObject())
|
||||
.put("queued", JSONObject())
|
||||
.put("profiles", JSONObject().put("42", JSONObject()
|
||||
.put("fex", "fex.wcp")
|
||||
.put("dxvk", "dxvk.wcp")
|
||||
.put("unknown", "ignored.wcp")))
|
||||
.toString())
|
||||
|
||||
assertEquals(mapOf("fex" to "fex.wcp", "dxvk" to "dxvk.wcp"), ComponentsManager.gameComponents(context, "42"))
|
||||
assertTrue(ComponentsManager.gameComponents(context, "43").isEmpty())
|
||||
}
|
||||
|
||||
@Test fun removingLastGameOverrideKeepsBundledComponentRestoreRow() {
|
||||
val protonName = "proton-exp"
|
||||
proton(protonName)
|
||||
writeGameProfile("42", "dxvk", "custom-dxvk.wcp")
|
||||
|
||||
ComponentsManager.clearGameComponents(context, "42")
|
||||
|
||||
assertFalse(ComponentsManager.gameComponents(context, "42").containsKey("dxvk"))
|
||||
assertDefaultDxvkRestoreRow(protonName)
|
||||
}
|
||||
|
||||
@Test fun usingDefaultForLastGameOverrideKeepsBundledComponentRestoreRow() {
|
||||
val protonName = "proton-exp"
|
||||
proton(protonName)
|
||||
writeGameProfile("42", "dxvk", "custom-dxvk.wcp")
|
||||
|
||||
ComponentsManager.setGameComponent(context, "42", "dxvk", null)
|
||||
|
||||
assertFalse(ComponentsManager.gameComponents(context, "42").containsKey("dxvk"))
|
||||
assertDefaultDxvkRestoreRow(protonName)
|
||||
}
|
||||
|
||||
@Test fun aNewProtonIsCapturedWhenTheLastOverrideIsReset() {
|
||||
proton("existing")
|
||||
writeGameProfile("42", "dxvk", "custom-dxvk.wcp")
|
||||
ComponentsManager.snapshotAll(context)
|
||||
proton("new-proton")
|
||||
|
||||
ComponentsManager.clearGameComponents(context, "42")
|
||||
|
||||
assertDefaultDxvkRestoreRow("existing")
|
||||
assertDefaultDxvkRestoreRow("new-proton")
|
||||
}
|
||||
|
||||
@Test fun anUpdatedBuildIsCapturedEvenAfterTheLastProfileWasRemoved() {
|
||||
proton("proton-exp")
|
||||
writeGameProfile("42", "dxvk", "custom-dxvk.wcp")
|
||||
ComponentsManager.clearGameComponents(context, "42")
|
||||
proton("proton-exp", "experimental-12")
|
||||
|
||||
ComponentsManager.setGameComponent(context, "43", "dxvk", null)
|
||||
|
||||
assertDefaultDxvkRestoreRow("proton-exp", "experimental-12")
|
||||
assertTrue(original("proton-exp", "experimental-11").isFile)
|
||||
assertTrue(original("proton-exp", "experimental-12").isFile)
|
||||
}
|
||||
|
||||
@Test fun aKnownEmptyComponentHasAnExplicitOriginalBundle() {
|
||||
proton("proton-exp", dxvk = false)
|
||||
writeGameProfile("42", "dxvk", "custom-dxvk.wcp")
|
||||
|
||||
ComponentsManager.clearGameComponents(context, "42")
|
||||
|
||||
assertTrue(original("proton-exp").isFile)
|
||||
val rows = launchState().readLines().map { it.split('\t') }
|
||||
assertEquals(14, rows.size)
|
||||
assertTrue(rows.all { it[3] == "dxvk" && it[5] == "-" && it[6] == "-" })
|
||||
}
|
||||
|
||||
@Test fun missingOriginalsCannotBeRecapturedFromPreviouslyProfiledFiles() {
|
||||
proton("proton-exp")
|
||||
writeGameProfile("42", "dxvk", "custom-dxvk.wcp")
|
||||
val saved = File(context.filesDir, "components/state.json").readText()
|
||||
val prior = "42\tproton-exp\texperimental-11\tdxvk\tfiles/lib/wine/dxvk/aarch64-windows/d3d11.dll\t-\t-\n"
|
||||
launchState().apply { parentFile!!.mkdirs(); writeText(prior) }
|
||||
|
||||
assertThrows(IllegalStateException::class.java) {
|
||||
ComponentsManager.setGameComponent(context, "42", "dxvk", null)
|
||||
}
|
||||
|
||||
assertEquals(saved, File(context.filesDir, "components/state.json").readText())
|
||||
assertEquals(prior, launchState().readText())
|
||||
assertFalse(original("proton-exp").isFile)
|
||||
}
|
||||
|
||||
@Test fun aBrokenOriginalDoesNotPublishDeletionRowsOrRemoveThePreviousStore() {
|
||||
proton("proton-exp")
|
||||
writeGameProfile("42", "dxvk", "custom-dxvk.wcp")
|
||||
val state = File(context.filesDir, "components/state.json")
|
||||
val saved = state.readText()
|
||||
val prior = "*\tother\tbuild\tdxvk\tfiles/old.dll\told-hash\t/old.dll\n"
|
||||
launchState().apply { parentFile!!.mkdirs(); writeText(prior) }
|
||||
val oldSource = File(launchState().parentFile, "store/old/files/old.dll")
|
||||
oldSource.apply { parentFile!!.mkdirs(); writeText("old component") }
|
||||
original("proton-exp").apply { parentFile!!.mkdirs(); writeText("not a bundle") }
|
||||
|
||||
assertThrows(java.io.IOException::class.java) {
|
||||
ComponentsManager.clearGameComponents(context, "42")
|
||||
}
|
||||
|
||||
assertEquals(saved, state.readText())
|
||||
assertEquals(prior, launchState().readText())
|
||||
assertEquals("old component", oldSource.readText())
|
||||
}
|
||||
|
||||
@Test fun anArchiveWithoutAProfileIsNotAKnownEmptyOriginal() {
|
||||
proton("proton-exp")
|
||||
writeGameProfile("42", "dxvk", "custom-dxvk.wcp")
|
||||
val bundle = original("proton-exp")
|
||||
bundle.parentFile!!.mkdirs()
|
||||
TarArchiveOutputStream(ZstdOutputStream(bundle.outputStream())).use { }
|
||||
|
||||
assertThrows(IllegalArgumentException::class.java) {
|
||||
ComponentsManager.clearGameComponents(context, "42")
|
||||
}
|
||||
|
||||
assertFalse(launchState().exists())
|
||||
assertEquals("custom-dxvk.wcp", ComponentsManager.gameComponents(context, "42")["dxvk"])
|
||||
}
|
||||
|
||||
@Test fun aFailedStateCommitIsRecoveredBeforeSelectionsCanBeRead() {
|
||||
proton("proton-exp")
|
||||
writeGameProfile("42", "dxvk", "custom-dxvk.wcp")
|
||||
val state = File(context.filesDir, "components/state.json")
|
||||
val saved = state.readText()
|
||||
val blocked = File(context.filesDir, "components/state.json.tmp")
|
||||
blocked.mkdir()
|
||||
val blocker = File(blocked, "blocker").apply { writeText("keep directory nonempty") }
|
||||
val oldSource = File(launchState().parentFile, "store/old/files/old.dll").apply {
|
||||
parentFile!!.mkdirs()
|
||||
writeText("old component")
|
||||
}
|
||||
|
||||
assertThrows(java.io.IOException::class.java) {
|
||||
ComponentsManager.clearGameComponents(context, "42")
|
||||
}
|
||||
|
||||
assertEquals(saved, state.readText())
|
||||
assertTrue(pendingState().isFile)
|
||||
assertTrue(launchState().isFile)
|
||||
assertEquals(Hashes.sha256(launchState()), JSONObject(pendingState().readText()).getString("launchSha256"))
|
||||
assertEquals("old component", oldSource.readText())
|
||||
assertThrows(java.io.IOException::class.java) {
|
||||
ComponentsManager.gameComponents(context, "42")
|
||||
}
|
||||
assertTrue(pendingState().isFile)
|
||||
|
||||
assertTrue(blocker.delete())
|
||||
assertTrue(blocked.delete())
|
||||
assertTrue(ComponentsManager.gameComponents(context, "42").isEmpty())
|
||||
assertFalse(pendingState().exists())
|
||||
assertDefaultDxvkRestoreRow("proton-exp")
|
||||
assertTrue(ComponentsManager.gameComponents(context, "42").isEmpty())
|
||||
ComponentsManager.snapshotAll(context)
|
||||
assertFalse(oldSource.exists())
|
||||
assertDefaultDxvkRestoreRow("proton-exp")
|
||||
}
|
||||
|
||||
@Test fun aFailedLaunchPublicationRetainsTheOldSelectionsAndStore() {
|
||||
proton("proton-exp")
|
||||
writeGameProfile("42", "dxvk", "custom-dxvk.wcp")
|
||||
val state = File(context.filesDir, "components/state.json")
|
||||
val saved = state.readText()
|
||||
launchState().mkdirs()
|
||||
val blocker = File(launchState(), "blocker").apply { writeText("block rename") }
|
||||
val oldSource = File(launchState().parentFile, "store/old/files/old.dll").apply {
|
||||
parentFile!!.mkdirs()
|
||||
writeText("old component")
|
||||
}
|
||||
|
||||
assertThrows(IllegalStateException::class.java) {
|
||||
ComponentsManager.clearGameComponents(context, "42")
|
||||
}
|
||||
|
||||
assertEquals(saved, state.readText())
|
||||
assertTrue(pendingState().isFile)
|
||||
assertEquals("custom-dxvk.wcp", ComponentsManager.gameComponents(context, "42")["dxvk"])
|
||||
assertFalse(pendingState().exists())
|
||||
assertEquals("old component", oldSource.readText())
|
||||
assertTrue(blocker.delete())
|
||||
assertTrue(launchState().delete())
|
||||
|
||||
ComponentsManager.clearGameComponents(context, "42")
|
||||
|
||||
assertTrue(ComponentsManager.gameComponents(context, "42").isEmpty())
|
||||
assertFalse(oldSource.exists())
|
||||
assertDefaultDxvkRestoreRow("proton-exp")
|
||||
}
|
||||
|
||||
@Test fun interruptionBeforePublicationDiscardsOnlyThePendingSelections() {
|
||||
writeGameProfile("42", "dxvk", "old-dxvk.wcp")
|
||||
val state = File(context.filesDir, "components/state.json")
|
||||
val saved = state.readText()
|
||||
val next = JSONObject(saved).apply {
|
||||
getJSONObject("profiles").getJSONObject("42").put("dxvk", "new-dxvk.wcp")
|
||||
}
|
||||
val staged = File(launchState().parentFile, "desired.tsv.tmp").apply {
|
||||
parentFile!!.mkdirs()
|
||||
writeText("new launch table")
|
||||
}
|
||||
launchState().writeText("old launch table")
|
||||
writePendingState(next, staged)
|
||||
|
||||
assertEquals("old-dxvk.wcp", ComponentsManager.gameComponents(context, "42")["dxvk"])
|
||||
assertEquals(saved, state.readText())
|
||||
assertEquals("old launch table", launchState().readText())
|
||||
assertFalse(pendingState().exists())
|
||||
assertFalse(staged.exists())
|
||||
}
|
||||
|
||||
@Test fun identicalLaunchTablesDoNotCommitUnpublishedSettings() {
|
||||
writeGameProfile("42", "dxvk", "old-dxvk.wcp")
|
||||
val state = File(context.filesDir, "components/state.json")
|
||||
val saved = state.readText()
|
||||
val next = JSONObject(saved).put("queued", JSONObject().put("proton-exp", JSONObject()))
|
||||
val staged = File(launchState().parentFile, "desired.tsv.tmp").apply {
|
||||
parentFile!!.mkdirs()
|
||||
writeText("unchanged launch table")
|
||||
}
|
||||
launchState().writeText(staged.readText())
|
||||
writePendingState(next, staged)
|
||||
|
||||
assertEquals("old-dxvk.wcp", ComponentsManager.gameComponents(context, "42")["dxvk"])
|
||||
assertEquals(saved, state.readText())
|
||||
assertFalse(pendingState().exists())
|
||||
assertFalse(staged.exists())
|
||||
}
|
||||
|
||||
@Test fun interruptionAfterPublicationRecoversAllSelectionsAndIsIdempotent() {
|
||||
writeGameProfile("42", "dxvk", "old-dxvk.wcp")
|
||||
val next = JSONObject()
|
||||
.put("active", JSONObject().put("proton-exp", JSONObject().put("dxvk", JSONObject().put("file", dxvk2))))
|
||||
.put("queued", JSONObject().put("proton-exp", JSONObject().put("fex", JSONObject().put("file", "fex.wcp"))))
|
||||
.put("profiles", JSONObject()
|
||||
.put("42", JSONObject().put("dxvk", "new-dxvk.wcp"))
|
||||
.put("43", JSONObject().put("fex", "fex.wcp")))
|
||||
.put("profiledComponents", JSONArray(listOf("dxvk", "fex")))
|
||||
launchState().apply { parentFile!!.mkdirs(); writeText("published launch table") }
|
||||
writePendingState(next, launchState())
|
||||
|
||||
assertEquals("new-dxvk.wcp", ComponentsManager.gameComponents(context, "42")["dxvk"])
|
||||
assertEquals("fex.wcp", ComponentsManager.gameComponents(context, "43")["fex"])
|
||||
assertEquals(next.toString(2), File(context.filesDir, "components/state.json").readText())
|
||||
assertFalse(pendingState().exists())
|
||||
assertEquals("published launch table", launchState().readText())
|
||||
assertEquals("new-dxvk.wcp", ComponentsManager.gameComponents(context, "42")["dxvk"])
|
||||
}
|
||||
|
||||
@Test fun aPendingTransactionAfterTheStateCommitCanBeRecoveredAgain() {
|
||||
writeGameProfile("42", "dxvk", "new-dxvk.wcp")
|
||||
val state = File(context.filesDir, "components/state.json")
|
||||
val next = JSONObject(state.readText())
|
||||
launchState().apply { parentFile!!.mkdirs(); writeText("published launch table") }
|
||||
writePendingState(next, launchState())
|
||||
|
||||
assertEquals("new-dxvk.wcp", ComponentsManager.gameComponents(context, "42")["dxvk"])
|
||||
assertEquals(next.toString(2), state.readText())
|
||||
assertFalse(pendingState().exists())
|
||||
}
|
||||
|
||||
@Test fun anUnreadableRecoveryRecordDoesNotSilentlyReturnStaleSelections() {
|
||||
writeGameProfile("42", "dxvk", "old-dxvk.wcp")
|
||||
pendingState().writeText("incomplete recovery record")
|
||||
|
||||
assertThrows(org.json.JSONException::class.java) {
|
||||
ComponentsManager.gameComponents(context, "42")
|
||||
}
|
||||
|
||||
assertTrue(pendingState().isFile)
|
||||
}
|
||||
|
||||
@Test fun theSamePackageOnThisProtonBuildIsNotFetchedAgain() {
|
||||
proton("proton-exp")
|
||||
writeState("proton-exp", dxvk2, "experimental-11")
|
||||
@@ -204,11 +484,57 @@ class ForcedPackageTest {
|
||||
|
||||
private fun refuseApply(protonId: String, file: String): String = error("apply $protonId $file")
|
||||
|
||||
private fun proton(name: String, version: String = "experimental-11") {
|
||||
private fun writeGameProfile(scope: String, comp: String, file: String) {
|
||||
val state = File(context.filesDir, "components/state.json")
|
||||
state.parentFile!!.mkdirs()
|
||||
state.writeText(
|
||||
JSONObject()
|
||||
.put("active", JSONObject())
|
||||
.put("queued", JSONObject())
|
||||
.put("profiles", JSONObject().put(scope, JSONObject().put(comp, file)))
|
||||
.toString(),
|
||||
)
|
||||
}
|
||||
|
||||
private fun launchState() = File(LinuxRuntime.rootDir(context), "root/.local/share/droiddeck-components/desired.tsv")
|
||||
|
||||
private fun pendingState() = File(context.filesDir, "components/state.pending.json")
|
||||
|
||||
private fun writePendingState(state: JSONObject, launch: File) {
|
||||
pendingState().writeText(JSONObject()
|
||||
.put("state", state)
|
||||
.put("launchSha256", Hashes.sha256(launch))
|
||||
.toString())
|
||||
}
|
||||
|
||||
private fun original(protonName: String, version: String = "experimental-11") =
|
||||
File(context.filesDir, "components/originals/$protonName/$version/dxvk.wcp")
|
||||
|
||||
private fun assertDefaultDxvkRestoreRow(protonName: String, version: String = "experimental-11") {
|
||||
val row = launchState().readLines().map { it.split('\t') }.single {
|
||||
it.size == 7 && it[0] == "*" && it[1] == protonName && it[2] == version &&
|
||||
it[3] == "dxvk" && it[4].endsWith("/aarch64-windows/d3d11.dll")
|
||||
}
|
||||
assertNotEquals("-", row[6])
|
||||
val source = File(LinuxRuntime.rootDir(context), row[6].removePrefix("/"))
|
||||
assertEquals("bundled DXVK $version", source.readText())
|
||||
assertEquals(Hashes.sha256(source), row[5])
|
||||
assertTrue(original(protonName, version).isFile)
|
||||
val state = JSONObject(File(context.filesDir, "components/state.json").readText())
|
||||
assertEquals(listOf("dxvk"), state.getJSONArray("profiledComponents").let { values ->
|
||||
(0 until values.length()).map(values::getString)
|
||||
})
|
||||
}
|
||||
|
||||
private fun proton(name: String, version: String = "experimental-11", dxvk: Boolean = true) {
|
||||
val dir = File(LinuxRuntime.rootDir(context), "root/.local/share/Steam/steamapps/common/$name")
|
||||
File(dir, "files/lib/wine").mkdirs()
|
||||
File(dir, "proton").writeText("#!/bin/sh\n")
|
||||
File(dir, "version").writeText("1 $version\n")
|
||||
if (dxvk) File(dir, "files/lib/wine/dxvk/aarch64-windows/d3d11.dll").apply {
|
||||
parentFile!!.mkdirs()
|
||||
writeText("bundled DXVK $version")
|
||||
}
|
||||
}
|
||||
|
||||
private fun writeState(protonId: String, file: String, protonVersion: String) {
|
||||
|
||||
@@ -69,6 +69,91 @@ class GameEnvironmentStoreTest {
|
||||
SessionState.upscaleRatio = 0f
|
||||
}
|
||||
|
||||
@Test fun changingGameFexPresetPreservesDefaultAndOtherGameSettings() {
|
||||
SessionPrefs.setFexPreset(context, "PERFORMANCE_TSO")
|
||||
val original = GameEnvironment.withGameFexPreset(
|
||||
GameEnvironment.Config(
|
||||
shared = mapOf("PROTON_LOG" to "1"),
|
||||
games = mapOf("42" to mapOf("DXVK_HUD" to "fps")),
|
||||
),
|
||||
"43",
|
||||
"COMPATIBILITY",
|
||||
)
|
||||
GameEnvironmentStore.save(context, original)
|
||||
|
||||
GameEnvironmentStore.setGameFexPreset(context, "42", "STABILITY")
|
||||
|
||||
val saved = GameEnvironmentStore.read(context)
|
||||
assertEquals("STABILITY", GameEnvironment.gameFexPreset(saved, "42"))
|
||||
assertEquals("fps", saved.entries("42")["DXVK_HUD"])
|
||||
assertEquals(original.shared, saved.shared)
|
||||
assertEquals(original.entries("43"), saved.entries("43"))
|
||||
assertEquals("PERFORMANCE_TSO", SessionPrefs.fexPreset(context))
|
||||
val published = GameEnvironmentStore.decode(JSONObject(guest.readText()))
|
||||
assertEquals(saved.games, published.games)
|
||||
assertEquals("0", published.shared["FEX_HALFBARRIERTSOENABLED"])
|
||||
assertEquals("1", published.entries("42")["FEX_HALFBARRIERTSOENABLED"])
|
||||
}
|
||||
|
||||
@Test fun gameFexDefaultsAndInheritanceRemainDistinct() {
|
||||
SessionPrefs.setFexPreset(context, "EXTREME")
|
||||
val original = GameEnvironment.Config(
|
||||
games = mapOf("42" to mapOf("DXVK_HUD" to "fps")),
|
||||
)
|
||||
GameEnvironmentStore.save(context, original)
|
||||
|
||||
GameEnvironmentStore.setGameFexPreset(context, "42", "")
|
||||
|
||||
val explicitDefaults = GameEnvironmentStore.read(context)
|
||||
assertEquals("", GameEnvironment.gameFexPreset(explicitDefaults, "42"))
|
||||
val published = GameEnvironmentStore.decode(JSONObject(guest.readText()))
|
||||
assertTrue(published.entries("42").containsKey("FEX_SMCCHECKS"))
|
||||
assertNull(published.entries("42")["FEX_SMCCHECKS"])
|
||||
|
||||
GameEnvironmentStore.setGameFexPreset(context, "42", null)
|
||||
|
||||
assertEquals(original, GameEnvironmentStore.read(context))
|
||||
val inherited = GameEnvironmentStore.decode(JSONObject(guest.readText()))
|
||||
assertFalse(inherited.entries("42").containsKey("FEX_SMCCHECKS"))
|
||||
assertEquals("none", inherited.shared["FEX_SMCCHECKS"])
|
||||
assertEquals("EXTREME", SessionPrefs.fexPreset(context))
|
||||
}
|
||||
|
||||
@Test fun invalidGamePresetEditsCannotChangeSavedOrPublishedSettings() {
|
||||
val original = GameEnvironment.Config(shared = mapOf("PROTON_LOG" to "1"))
|
||||
GameEnvironmentStore.save(context, original)
|
||||
val published = guest.readText()
|
||||
|
||||
assertThrows(IllegalArgumentException::class.java) {
|
||||
GameEnvironmentStore.setGameFexPreset(context, "", "STABILITY")
|
||||
}
|
||||
assertThrows(IllegalArgumentException::class.java) {
|
||||
GameEnvironmentStore.setGameFexPreset(context, "42", GameEnvironment.CUSTOM_FEX_PRESET)
|
||||
}
|
||||
|
||||
assertEquals(original, GameEnvironmentStore.read(context))
|
||||
assertEquals(published, guest.readText())
|
||||
}
|
||||
|
||||
@Test fun targetedFexUpdateDoesNotRestoreEnvironmentClearedByACompletedReset() {
|
||||
val original = GameEnvironment.withGameFexPreset(
|
||||
GameEnvironment.Config(games = mapOf("42" to mapOf("DXVK_HUD" to "fps"))),
|
||||
"42",
|
||||
"COMPATIBILITY",
|
||||
)
|
||||
GameEnvironmentStore.save(context, original)
|
||||
val staleEditorSnapshot = GameEnvironmentStore.read(context)
|
||||
val resetEnvironment = staleEditorSnapshot.withEntries("42", emptyMap())
|
||||
GameEnvironmentStore.save(context, resetEnvironment)
|
||||
|
||||
GameEnvironmentStore.setGameFexPreset(context, "43", "PERFORMANCE_TSO")
|
||||
|
||||
val saved = GameEnvironmentStore.read(context)
|
||||
assertTrue(saved.entries("42").isEmpty())
|
||||
assertEquals("PERFORMANCE_TSO", GameEnvironment.gameFexPreset(saved, "43"))
|
||||
assertFalse(saved.games.containsKey("42"))
|
||||
}
|
||||
|
||||
@Test fun unchosenFexPresetPublishesPerformanceTso() {
|
||||
GameEnvironmentStore.save(context, GameEnvironment.Config())
|
||||
val shared = JSONObject(guest.readText()).getJSONObject("shared")
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
class GameProfileFollowStateTest {
|
||||
@Test fun reopeningGamesPageResumesFollowingSteamAfterManualInspection() {
|
||||
val state = GameProfileFollowState()
|
||||
|
||||
state.selectManually()
|
||||
assertFalse(state.followsSteam)
|
||||
|
||||
state.resumeFollowingSteam()
|
||||
assertTrue(state.followsSteam)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Assert.assertThrows
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import java.util.concurrent.CountDownLatch
|
||||
import java.util.concurrent.Executors
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
class GameProfileInventoryCacheTest {
|
||||
@Test
|
||||
fun loadsOnlyOncePerRevision() {
|
||||
val cache = GameProfileInventoryCache<String>()
|
||||
var loads = 0
|
||||
|
||||
assertEquals(listOf("one"), cache.get(0) { loads++; listOf("one") })
|
||||
assertEquals(listOf("one"), cache.get(0) { loads++; listOf("two") })
|
||||
assertEquals(1, loads)
|
||||
|
||||
assertEquals(listOf("two"), cache.get(1) { loads++; listOf("two") })
|
||||
assertEquals(2, loads)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun failedLoadIsRetriedInsteadOfCached() {
|
||||
val cache = GameProfileInventoryCache<String>()
|
||||
var loads = 0
|
||||
|
||||
assertThrows(IllegalStateException::class.java) {
|
||||
cache.get(0) { loads++; error("inventory unavailable") }
|
||||
}
|
||||
|
||||
assertEquals(listOf("recovered"), cache.get(0) { loads++; listOf("recovered") })
|
||||
assertEquals(2, loads)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun failedNewRevisionDoesNotReuseThePreviousInventory() {
|
||||
val cache = GameProfileInventoryCache<String>()
|
||||
assertEquals(listOf("old"), cache.get(0) { listOf("old") })
|
||||
|
||||
assertThrows(IllegalStateException::class.java) {
|
||||
cache.get(1) { error("inventory unavailable") }
|
||||
}
|
||||
|
||||
assertEquals(listOf("new"), cache.get(1) { listOf("new") })
|
||||
assertEquals(listOf("new"), cache.get(1) { error("should use cached inventory") })
|
||||
}
|
||||
|
||||
@Test
|
||||
fun emptyInventoryIsCachedUntilTheRevisionChanges() {
|
||||
val cache = GameProfileInventoryCache<String>()
|
||||
|
||||
assertEquals(emptyList<String>(), cache.get(0) { emptyList() })
|
||||
assertEquals(emptyList<String>(), cache.get(0) { error("should use cached inventory") })
|
||||
assertEquals(listOf("installed"), cache.get(1) { listOf("installed") })
|
||||
}
|
||||
|
||||
@Test(timeout = 10_000)
|
||||
fun reopeningDuringAScanQueuesFreshInventoryWithoutWaitingAndRejectsOldResults() {
|
||||
data class Refresh(val appId: Long, val inventoryRevision: Long)
|
||||
|
||||
val cache = GameProfileInventoryCache<String>()
|
||||
val coordinator = LatestRequestCoordinator<Refresh>()
|
||||
val scanStarted = CountDownLatch(1)
|
||||
val finishScan = CountDownLatch(1)
|
||||
val worker = Executors.newSingleThreadExecutor()
|
||||
try {
|
||||
assertTrue(coordinator.submit(Refresh(42, 0)))
|
||||
val first = coordinator.takeLatest()!!
|
||||
val oldInventory = worker.submit<List<String>> {
|
||||
cache.get(first.value.inventoryRevision) {
|
||||
scanStarted.countDown()
|
||||
check(finishScan.await(5, TimeUnit.SECONDS))
|
||||
listOf("old")
|
||||
}
|
||||
}
|
||||
assertTrue(scanStarted.await(5, TimeUnit.SECONDS))
|
||||
|
||||
assertFalse(coordinator.submit(Refresh(42, 1)))
|
||||
assertFalse(oldInventory.isDone)
|
||||
assertFalse(coordinator.isLatest(first))
|
||||
|
||||
finishScan.countDown()
|
||||
assertEquals(listOf("old"), oldInventory.get(5, TimeUnit.SECONDS))
|
||||
assertFalse(coordinator.isLatest(first))
|
||||
val reopened = coordinator.takeLatest()!!
|
||||
val newInventory = worker.submit<List<String>> {
|
||||
cache.get(reopened.value.inventoryRevision) { listOf("new") }
|
||||
}
|
||||
assertEquals(listOf("new"), newInventory.get(5, TimeUnit.SECONDS))
|
||||
assertTrue(coordinator.isLatest(reopened))
|
||||
assertNull(coordinator.takeLatest())
|
||||
} finally {
|
||||
finishScan.countDown()
|
||||
worker.shutdownNow()
|
||||
assertTrue(worker.awaitTermination(5, TimeUnit.SECONDS))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
import android.content.Context
|
||||
import com.droiddeck.launcher.core.GameEnvironment
|
||||
import com.droiddeck.launcher.runtime.LinuxRuntime
|
||||
import org.json.JSONObject
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Assert.assertThrows
|
||||
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 = [28], manifest = Config.NONE)
|
||||
class GameProfileManagerTest {
|
||||
private lateinit var context: Context
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
context = RuntimeEnvironment.getApplication()
|
||||
context.getSharedPreferences("session", Context.MODE_PRIVATE).edit().clear().commit()
|
||||
File(context.filesDir, "game-environment.json").delete()
|
||||
File(context.filesDir, "wincomponents.json").delete()
|
||||
File(context.filesDir, "components").deleteRecursively()
|
||||
File(LinuxRuntime.rootDir(context), "root/.local/share/droiddeck-compat").deleteRecursively()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun resetClearsOnlyTheSelectedGameProfile() {
|
||||
val game = "42"
|
||||
val other = "43"
|
||||
GameEnvironmentStore.save(
|
||||
context,
|
||||
GameEnvironment.Config(
|
||||
games = mapOf(
|
||||
game to mapOf("DXVK_HUD" to "fps"),
|
||||
other to mapOf("DXVK_HUD" to "compiler"),
|
||||
),
|
||||
),
|
||||
)
|
||||
ProtonDefault.requestGame(context, game, proton("game"))
|
||||
ProtonDefault.requestGame(context, other, proton("other"))
|
||||
seedComponentProfiles(game, other)
|
||||
SessionPrefs.setGameTextureAnisotropy(context, game, 4)
|
||||
SessionPrefs.setGameTextureAnisotropy(context, other, 8)
|
||||
WinComponents.setPicks(context, game, listOf("vcrun2022"))
|
||||
WinComponents.setPicks(context, other, listOf("dotnet48"))
|
||||
|
||||
GameProfileManager.reset(context, game)
|
||||
|
||||
val environment = GameEnvironmentStore.read(context)
|
||||
assertFalse(environment.games.containsKey(game))
|
||||
assertEquals("compiler", environment.entries(other)["DXVK_HUD"])
|
||||
assertNull(ProtonDefault.gameChoice(context, game))
|
||||
assertEquals("other", ProtonDefault.gameChoice(context, other)?.dir)
|
||||
assertEquals(emptyMap<String, String>(), ComponentsManager.gameComponents(context, game))
|
||||
assertEquals("other.wcp", ComponentsManager.gameComponents(context, other)["dxvk"])
|
||||
assertEquals(SessionPrefs.GameTextureFiltering(), SessionPrefs.gameTextureFiltering(context, game))
|
||||
assertEquals(8, SessionPrefs.gameTextureFiltering(context, other).anisotropy)
|
||||
assertEquals(emptyList<String>(), WinComponents.picks(context, game))
|
||||
assertEquals(listOf("dotnet48"), WinComponents.picks(context, other))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun resetRejectsEmptyScopeWithoutChangingSharedSettings() {
|
||||
GameEnvironmentStore.save(
|
||||
context,
|
||||
GameEnvironment.Config(shared = mapOf("DXVK_HUD" to "fps")),
|
||||
)
|
||||
|
||||
assertThrows(IllegalArgumentException::class.java) {
|
||||
GameProfileManager.reset(context, "")
|
||||
}
|
||||
assertEquals("fps", GameEnvironmentStore.read(context).shared["DXVK_HUD"])
|
||||
}
|
||||
|
||||
private fun proton(name: String) = ComponentsManager.Proton(
|
||||
id = name,
|
||||
name = name,
|
||||
dir = File(context.filesDir, name),
|
||||
guestPath = "/proton/$name",
|
||||
version = "1",
|
||||
valve = false,
|
||||
)
|
||||
|
||||
private fun seedComponentProfiles(game: String, other: String) {
|
||||
val components = File(context.filesDir, "components").apply { mkdirs() }
|
||||
File(components, "state.json").writeText(
|
||||
JSONObject().put(
|
||||
"profiles",
|
||||
JSONObject()
|
||||
.put(game, JSONObject().put("dxvk", "game.wcp"))
|
||||
.put(other, JSONObject().put("dxvk", "other.wcp")),
|
||||
).toString(),
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
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 GameProfileRefreshStateTest {
|
||||
@Test
|
||||
fun firstFailureKeepsInitialStateWithoutCachedData() {
|
||||
val state = GameProfileRefreshState<String>().failed()
|
||||
|
||||
assertTrue(state.failed)
|
||||
assertFalse(state.loaded)
|
||||
assertNull(state.data)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun failureAfterSuccessPreservesCachedData() {
|
||||
val state = GameProfileRefreshState<String>().succeeded("cached profiles").failed()
|
||||
|
||||
assertTrue(state.failed)
|
||||
assertTrue(state.loaded)
|
||||
assertEquals("cached profiles", state.data)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun successAfterFailureReplacesCachedDataAndClearsWarning() {
|
||||
val state = GameProfileRefreshState<String>()
|
||||
.succeeded("old profiles")
|
||||
.failed()
|
||||
.succeeded("new profiles")
|
||||
|
||||
assertFalse(state.failed)
|
||||
assertTrue(state.loaded)
|
||||
assertEquals("new profiles", state.data)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun retryingClearsWarningWithoutDiscardingCachedData() {
|
||||
val state = GameProfileRefreshState<String>().succeeded("cached profiles").failed().retrying()
|
||||
|
||||
assertFalse(state.failed)
|
||||
assertTrue(state.loaded)
|
||||
assertEquals("cached profiles", state.data)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
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 LatestRequestCoordinatorTest {
|
||||
@Test fun coalescesPendingRequestsToTheLatestValue() {
|
||||
val coordinator = LatestRequestCoordinator<String>()
|
||||
|
||||
assertTrue(coordinator.submit("first"))
|
||||
val first = coordinator.takeLatest()!!
|
||||
assertFalse(coordinator.submit("second"))
|
||||
assertFalse(coordinator.submit("third"))
|
||||
|
||||
assertFalse(coordinator.isLatest(first))
|
||||
val latest = coordinator.takeLatest()!!
|
||||
assertEquals("third", latest.value)
|
||||
assertTrue(coordinator.isLatest(latest))
|
||||
assertNull(coordinator.takeLatest())
|
||||
}
|
||||
|
||||
@Test fun requestAfterWorkerBecomesIdleStartsAnotherWorker() {
|
||||
val coordinator = LatestRequestCoordinator<String>()
|
||||
|
||||
assertTrue(coordinator.submit("first"))
|
||||
coordinator.takeLatest()
|
||||
assertNull(coordinator.takeLatest())
|
||||
|
||||
assertTrue(coordinator.submit("second"))
|
||||
assertEquals("second", coordinator.takeLatest()!!.value)
|
||||
}
|
||||
|
||||
@Test fun newerRequestInvalidatesCompletedResultBeforeItIsApplied() {
|
||||
val coordinator = LatestRequestCoordinator<String>()
|
||||
|
||||
assertTrue(coordinator.submit("first"))
|
||||
val completed = coordinator.takeLatest()!!
|
||||
assertFalse(coordinator.submit("second"))
|
||||
|
||||
assertFalse(coordinator.isLatest(completed))
|
||||
assertEquals("second", coordinator.takeLatest()!!.value)
|
||||
}
|
||||
|
||||
@Test fun profileSwitchInvalidatesAnOlderFailedRefresh() {
|
||||
val coordinator = LatestRequestCoordinator<Long?>()
|
||||
|
||||
assertTrue(coordinator.submit(42L))
|
||||
val failedRefresh = coordinator.takeLatest()!!
|
||||
assertFalse(coordinator.submit(43L))
|
||||
|
||||
assertFalse(coordinator.isLatest(failedRefresh))
|
||||
assertEquals(43L, coordinator.takeLatest()!!.value)
|
||||
}
|
||||
|
||||
@Test fun repeatedPollDoesNotInvalidateEquivalentInFlightResult() {
|
||||
val coordinator = LatestRequestCoordinator<String>()
|
||||
|
||||
assertTrue(coordinator.submit("same"))
|
||||
val inFlight = coordinator.takeLatest()!!
|
||||
assertFalse(coordinator.submit("same"))
|
||||
|
||||
assertTrue(coordinator.isLatest(inFlight))
|
||||
assertEquals("same", coordinator.takeLatest()!!.value)
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
import com.droiddeck.launcher.runtime.LinuxRuntime
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertNull
|
||||
@@ -7,6 +8,7 @@ import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import java.io.File
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@@ -59,4 +61,46 @@ class ProtonDefaultTest {
|
||||
assertNull(ProtonDefault.chosen(ProtonDefault.parseState("{"), ProtonDefault.parseRequest("[]")))
|
||||
assertNull(ProtonDefault.parseRequest("""{"seq": 0, "dir": "x"}"""))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun perGameChoicesPreserveCustomizeAndInheritSemantics() {
|
||||
val games = ProtonDefault.parseGames(
|
||||
"""{"version":1,"games":{"42":{"valve":false,"dir":"GE-Proton11-7"},"43":null,"0":null,"bad":{},"44":{"valve":"false","dir":"GE-Proton9-1"}}}""",
|
||||
)
|
||||
assertEquals(ProtonDefault.GameChoice(false, "GE-Proton11-7"), games["42"])
|
||||
assertTrue(games.containsKey("43"))
|
||||
assertNull(games["43"])
|
||||
assertFalse(games.containsKey("0"))
|
||||
assertFalse(games.containsKey("bad"))
|
||||
assertFalse(games.containsKey("44"))
|
||||
assertTrue(ProtonDefault.parseGames("""{"version":2,"games":{"42":null}}""").isEmpty())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun perGameRequestsPersistCustomizeThenInherit() {
|
||||
val context = RuntimeEnvironment.getApplication()
|
||||
val file = File(LinuxRuntime.rootDir(context), "root/.local/share/droiddeck-compat/games.json")
|
||||
file.parentFile?.deleteRecursively()
|
||||
val selected = proton("GE-Proton11-7", false)
|
||||
|
||||
ProtonDefault.requestGame(context, "42", selected)
|
||||
assertEquals(ProtonDefault.GameChoice(false, "GE-Proton11-7"), ProtonDefault.parseGames(file.readText())["42"])
|
||||
|
||||
ProtonDefault.requestGame(context, "42", null)
|
||||
val inherited = ProtonDefault.parseGames(file.readText())
|
||||
assertTrue(inherited.containsKey("42"))
|
||||
assertNull(inherited["42"])
|
||||
}
|
||||
|
||||
@Test
|
||||
fun missingPerGameProtonIdentityRemainsStoredButUnresolved() {
|
||||
val context = RuntimeEnvironment.getApplication()
|
||||
val file = File(LinuxRuntime.rootDir(context), "root/.local/share/droiddeck-compat/games.json")
|
||||
file.parentFile?.deleteRecursively()
|
||||
ProtonDefault.requestGame(context, "42", proton("GE-Proton9-1", false))
|
||||
|
||||
assertEquals(ProtonDefault.GameChoice(false, "GE-Proton9-1"), ProtonDefault.gameChoice(context, "42"))
|
||||
assertNull(ProtonDefault.gameSelectedId(context, "42", listOf(proton("GE-Proton11-7", false))))
|
||||
assertEquals(ProtonDefault.GameChoice(false, "GE-Proton9-1"), ProtonDefault.parseGames(file.readText())["42"])
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
import com.droiddeck.launcher.core.GameEnvironment
|
||||
import com.droiddeck.launcher.frontend.Library
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import java.io.File
|
||||
|
||||
class SelectedGameProfileTest {
|
||||
private val proton = ComponentsManager.Proton("p1", "Proton 10", File("p1"), "/p1", "10", true)
|
||||
private val snapshot = ComponentsManager.Snapshot(
|
||||
protons = listOf(
|
||||
ComponentsManager.ProtonView(
|
||||
proton = proton,
|
||||
components = mapOf(
|
||||
"fex" to component("FEX General"),
|
||||
"dxvk" to component("DXVK General"),
|
||||
"vkd3d" to component("VKD3D General"),
|
||||
),
|
||||
originals = emptyList(),
|
||||
inUseByGame = false,
|
||||
),
|
||||
),
|
||||
packages = listOf(ComponentsManager.Package("dxvk.wcp", "dxvk", "DXVK Game", "", 1)),
|
||||
)
|
||||
private val game = Library.SteamGame(3180310, "Billies Wheelie", null, "internal")
|
||||
|
||||
@Test fun inheritedValuesUseGeneralProfile() {
|
||||
val profile = resolve()
|
||||
|
||||
assertEquals("Billies Wheelie", profile!!.name)
|
||||
assertEquals("PERFORMANCE_TSO", profile.fexPreset.value)
|
||||
assertTrue(profile.fexPreset.inherited)
|
||||
assertEquals("Proton 10", profile.proton.value)
|
||||
assertTrue(profile.proton.inherited)
|
||||
assertEquals("p1", profile.protonId)
|
||||
assertEquals("DXVK General", profile.components.getValue("dxvk").value)
|
||||
assertTrue(profile.components.getValue("dxvk").inherited)
|
||||
assertEquals(emptyMap<String, String>(), profile.componentFiles)
|
||||
assertEquals(0, profile.environmentOverrides)
|
||||
assertEquals(emptyList<String>(), profile.windowsComponentNames)
|
||||
assertFalse(profile.hasOverrides)
|
||||
}
|
||||
|
||||
@Test fun explicitValuesOverrideGeneralProfile() {
|
||||
val preset = GameEnvironment.withGameFexPreset(GameEnvironment.Config(), game.profileKey, "STABILITY")
|
||||
val environment = preset.withEntries(game.profileKey, preset.entries(game.profileKey) + ("PROTON_LOG" to "1"))
|
||||
val profile = resolve(
|
||||
environment = environment,
|
||||
gameChoice = ProtonDefault.GameChoice(true, "p1"),
|
||||
gameComponents = mapOf("dxvk" to "dxvk.wcp"),
|
||||
)
|
||||
|
||||
assertEquals("STABILITY", profile!!.fexPreset.value)
|
||||
assertFalse(profile.fexPreset.inherited)
|
||||
assertFalse(profile.proton.inherited)
|
||||
assertEquals("DXVK Game", profile.components.getValue("dxvk").value)
|
||||
assertFalse(profile.components.getValue("dxvk").inherited)
|
||||
assertEquals("dxvk.wcp", profile.componentFiles.getValue("dxvk"))
|
||||
assertEquals(1, profile.environmentOverrides)
|
||||
assertTrue(profile.hasOverrides)
|
||||
}
|
||||
|
||||
@Test fun windowsComponentsMakeProfileCustom() {
|
||||
val profile = resolve(gameWindowsComponents = listOf("oalinst_dll", "vcredist2010_dll"))
|
||||
|
||||
assertEquals(listOf("OpenAL", "Visual C++ 2010"), profile!!.windowsComponentNames)
|
||||
assertTrue(profile.hasOverrides)
|
||||
}
|
||||
|
||||
@Test fun unknownSelectedAppIsIgnored() {
|
||||
assertNull(resolve(selectedAppId = 42))
|
||||
}
|
||||
|
||||
@Test fun switchingProfilesResolvesEachGamesFexPresetWithoutChangingSettings() {
|
||||
val other = Library.SteamGame(42, "Other game", null, "internal")
|
||||
val games = listOf(game, other)
|
||||
val environment = GameEnvironment.withGameFexPreset(
|
||||
GameEnvironment.Config(), game.profileKey, "STABILITY",
|
||||
)
|
||||
|
||||
assertEquals(ProfileValue("STABILITY", false),
|
||||
resolve(games = games, environment = environment)!!.fexPreset)
|
||||
assertEquals(ProfileValue("PERFORMANCE_TSO", true),
|
||||
resolve(selectedAppId = 42, games = games, environment = environment)!!.fexPreset)
|
||||
assertEquals(ProfileValue("STABILITY", false),
|
||||
resolve(games = games, environment = environment)!!.fexPreset)
|
||||
assertNull(GameEnvironment.gameFexPreset(environment, other.profileKey))
|
||||
}
|
||||
|
||||
@Test fun customAndExplicitDefaultFexPresetsAreNotShownAsInherited() {
|
||||
val custom = GameEnvironment.Config(
|
||||
games = mapOf(game.profileKey to mapOf("FEX_TSOENABLED" to "0")),
|
||||
)
|
||||
assertEquals(ProfileValue(GameEnvironment.CUSTOM_FEX_PRESET, false),
|
||||
resolve(environment = custom)!!.fexPreset)
|
||||
val defaults = GameEnvironment.withGameFexPreset(custom, game.profileKey, "")
|
||||
assertEquals(ProfileValue("", false), resolve(environment = defaults)!!.fexPreset)
|
||||
val inherited = GameEnvironment.withGameFexPreset(defaults, game.profileKey, null)
|
||||
assertEquals(ProfileValue("PERFORMANCE_TSO", true), resolve(environment = inherited)!!.fexPreset)
|
||||
}
|
||||
|
||||
private fun resolve(
|
||||
selectedAppId: Long = 3180310,
|
||||
games: List<Library.SteamGame> = listOf(game),
|
||||
environment: GameEnvironment.Config = GameEnvironment.Config(),
|
||||
gameChoice: ProtonDefault.GameChoice? = null,
|
||||
gameComponents: Map<String, String> = emptyMap(),
|
||||
gameWindowsComponents: List<String> = emptyList(),
|
||||
) = SelectedGameProfile.resolve(
|
||||
selectedAppId = selectedAppId,
|
||||
games = games,
|
||||
generalFexPreset = "PERFORMANCE_TSO",
|
||||
environment = environment,
|
||||
snapshot = snapshot,
|
||||
generalProtonId = "p1",
|
||||
gameProtonChoice = gameChoice,
|
||||
gameProtonId = "p1",
|
||||
gameComponents = gameComponents,
|
||||
gameWindowsComponents = gameWindowsComponents,
|
||||
)
|
||||
|
||||
private fun component(label: String) =
|
||||
ComponentsManager.Component(label, "", "Changed outside Components", label, null, null)
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
import android.content.Context
|
||||
import com.droiddeck.launcher.core.TextureFiltering
|
||||
import com.droiddeck.launcher.runtime.LinuxRuntime
|
||||
import org.json.JSONObject
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Assert.assertTrue
|
||||
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 = [28], manifest = Config.NONE)
|
||||
class TextureFilteringPrefsTest {
|
||||
private lateinit var context: Context
|
||||
|
||||
@Before fun setUp() {
|
||||
context = RuntimeEnvironment.getApplication()
|
||||
context.getSharedPreferences("session", Context.MODE_PRIVATE).edit().clear().commit()
|
||||
File(context.filesDir, "game-environment.json").delete()
|
||||
File(LinuxRuntime.rootDir(context), "root/.config/droiddeck/game-environment.json").delete()
|
||||
}
|
||||
|
||||
@Test fun gameChoicesRemainSeparateFromDefaultAndCanInheritAgain() {
|
||||
SessionPrefs.setTextureAnisotropy(context, 16)
|
||||
SessionPrefs.setTextureLodBias(context, TextureFiltering.LOD_BIAS_AUTO)
|
||||
SessionPrefs.setGameTextureAnisotropy(context, "42", 4)
|
||||
SessionPrefs.setGameTextureLodBias(context, "42", "-0.5")
|
||||
|
||||
assertEquals(16, SessionPrefs.textureAnisotropy(context))
|
||||
assertEquals(TextureFiltering.LOD_BIAS_AUTO, SessionPrefs.textureLodBias(context))
|
||||
assertEquals(SessionPrefs.GameTextureFiltering(4, "-0.5"), SessionPrefs.gameTextureFiltering(context, "42"))
|
||||
assertEquals(SessionPrefs.GameTextureFiltering(), SessionPrefs.gameTextureFiltering(context, "43"))
|
||||
|
||||
SessionPrefs.setGameTextureAnisotropy(context, "42", null)
|
||||
SessionPrefs.setGameTextureLodBias(context, "42", null)
|
||||
|
||||
assertEquals(SessionPrefs.GameTextureFiltering(), SessionPrefs.gameTextureFiltering(context, "42"))
|
||||
assertFalse(SessionPrefs.gameTextureFiltering(context).containsKey("42"))
|
||||
}
|
||||
|
||||
@Test fun publishedDxvkOptionsUseGameOverridesWithoutChangingDefault() {
|
||||
SessionPrefs.setTextureAnisotropy(context, 16)
|
||||
SessionPrefs.setGameTextureAnisotropy(context, "42", 0)
|
||||
SessionPrefs.setGameTextureLodBias(context, "42", TextureFiltering.LOD_BIAS_OFF)
|
||||
|
||||
val published = JSONObject(
|
||||
File(LinuxRuntime.rootDir(context), "root/.config/droiddeck/game-environment.json").readText(),
|
||||
)
|
||||
assertTrue(published.getString(GameEnvironmentStore.DXVK_CONFIG).contains("samplerAnisotropy = 16"))
|
||||
assertEquals("", published.getJSONObject(GameEnvironmentStore.DXVK_CONFIG_GAMES).getString("42"))
|
||||
assertNull(SessionPrefs.gameTextureFiltering(context, "43").anisotropy)
|
||||
}
|
||||
|
||||
@Test fun clearingGameChoicesPreservesOtherProfiles() {
|
||||
SessionPrefs.setGameTextureAnisotropy(context, "42", 4)
|
||||
SessionPrefs.setGameTextureLodBias(context, "42", "-0.5")
|
||||
SessionPrefs.setGameTextureAnisotropy(context, "43", 8)
|
||||
|
||||
SessionPrefs.clearGameTextureFiltering(context, "42")
|
||||
|
||||
assertEquals(SessionPrefs.GameTextureFiltering(), SessionPrefs.gameTextureFiltering(context, "42"))
|
||||
assertEquals(8, SessionPrefs.gameTextureFiltering(context, "43").anisotropy)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import androidx.compose.ui.test.onNodeWithText
|
||||
import androidx.compose.ui.test.performClick
|
||||
import com.droiddeck.launcher.R
|
||||
import com.droiddeck.launcher.frontend.Library
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.annotation.Config
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [28])
|
||||
class ComponentsPageProfileTest {
|
||||
@get:Rule val compose = createRobolectricComposeRule()
|
||||
|
||||
@Test fun gameProfilesCoexistWithTheDefaultComponentStack() {
|
||||
val context = RuntimeEnvironment.getApplication()
|
||||
compose.setContent {
|
||||
DroidDeckTheme {
|
||||
ComponentsPage(
|
||||
snapshot = null,
|
||||
catalog = emptyList(),
|
||||
catalogAt = 0,
|
||||
protonId = null,
|
||||
comp = PROTON_TAB,
|
||||
checking = false,
|
||||
busy = null,
|
||||
downloads = emptyMap(),
|
||||
onProton = {},
|
||||
onComp = {},
|
||||
onSwap = {},
|
||||
onRestore = {},
|
||||
onCancelQueued = {},
|
||||
onDeletePackage = {},
|
||||
onDeleteOriginal = {},
|
||||
onDownload = {},
|
||||
onRefresh = {},
|
||||
onImport = {},
|
||||
onBack = {},
|
||||
games = listOf(Library.SteamGame(42, "Game A", null, "internal")),
|
||||
requestInitialFocus = false,
|
||||
)
|
||||
}
|
||||
}
|
||||
val stackHeading = context.getString(R.string.comp_this_proton).uppercase()
|
||||
compose.onNodeWithText(stackHeading).assertExists()
|
||||
compose.onNodeWithText(context.getString(R.string.comp_scope_general)).performClick()
|
||||
compose.onNodeWithText("Game A").performClick()
|
||||
compose.onNodeWithText(context.getString(R.string.comp_game_hint)).assertExists()
|
||||
compose.onNodeWithText(stackHeading).assertDoesNotExist()
|
||||
|
||||
compose.onNodeWithText("Game A").performClick()
|
||||
compose.onNodeWithText(context.getString(R.string.comp_scope_general)).performClick()
|
||||
compose.onNodeWithText(stackHeading).assertExists()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import android.content.Context
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.ui.test.hasText
|
||||
import androidx.compose.ui.test.onAllNodesWithText
|
||||
import androidx.compose.ui.test.onLast
|
||||
import androidx.compose.ui.test.onNodeWithText
|
||||
import androidx.compose.ui.test.performClick
|
||||
import androidx.compose.ui.test.performScrollTo
|
||||
import com.droiddeck.launcher.R
|
||||
import com.droiddeck.launcher.core.GameEnvironment
|
||||
import com.droiddeck.launcher.session.GameEnvironmentStore
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.annotation.Config
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [28])
|
||||
class GameEnvironmentEditorTest {
|
||||
@get:Rule val compose = createRobolectricComposeRule()
|
||||
|
||||
@Test fun backgroundSelectionCannotRetargetAnOpenVariableEdit() {
|
||||
val context: Context = RuntimeEnvironment.getApplication()
|
||||
val variable = "MESA_SHADER_CACHE_MAX_SIZE"
|
||||
GameEnvironmentStore.save(context, GameEnvironment.Config(games = mapOf(
|
||||
"42" to mapOf(variable to "512M"),
|
||||
"43" to mapOf(variable to "2G"),
|
||||
)))
|
||||
val selectedScope = mutableStateOf("42")
|
||||
compose.setContent {
|
||||
DroidDeckTheme { GameEnvironmentRow(initialScope = selectedScope.value) }
|
||||
}
|
||||
compose.onNodeWithText(context.getString(R.string.game_env_edit)).performClick()
|
||||
compose.waitUntil(5_000) {
|
||||
compose.onAllNodes(hasText("512M")).fetchSemanticsNodes().isNotEmpty()
|
||||
}
|
||||
compose.onNodeWithText("512M").performScrollTo().performClick()
|
||||
compose.onNodeWithText(context.getString(R.string.game_env_change)).performClick()
|
||||
compose.onAllNodesWithText("512M").onLast().performClick()
|
||||
compose.onNodeWithText("4G").performClick()
|
||||
|
||||
compose.runOnIdle { selectedScope.value = "43" }
|
||||
compose.onNodeWithText(context.getString(R.string.game_env_save)).performClick()
|
||||
compose.waitUntil(5_000) {
|
||||
GameEnvironmentStore.read(context).entries("42")[variable] == "4G"
|
||||
}
|
||||
assertEquals("2G", GameEnvironmentStore.read(context).entries("43")[variable])
|
||||
compose.onNodeWithText("4G").assertExists()
|
||||
|
||||
compose.onNodeWithText(context.getString(R.string.game_env_done)).performScrollTo().performClick()
|
||||
compose.waitForIdle()
|
||||
compose.onNodeWithText(context.getString(R.string.game_env_edit)).performClick()
|
||||
compose.waitUntil(5_000) {
|
||||
compose.onAllNodes(hasText("2G")).fetchSemanticsNodes().isNotEmpty()
|
||||
}
|
||||
compose.onNodeWithText("2G").assertExists()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import android.content.ComponentName
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.compose.ui.test.junit4.createComposeRule
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.Shadows.shadowOf
|
||||
|
||||
fun createRobolectricComposeRule() = createComposeRule().also {
|
||||
val context = RuntimeEnvironment.getApplication()
|
||||
// Register only in Robolectric, without adding a host activity to either APK variant.
|
||||
shadowOf(context.packageManager).addActivityIfNotPresent(
|
||||
ComponentName(context, ComponentActivity::class.java),
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user