mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 20:36:04 +00:00
Fix/variables (#60)
* Add editable per-game environment settings below FEX presets * Add typed preset variable pickers and default D3D12 capability levels --------- Co-authored-by: MaxsTechReview <6025299+maxjivi05@users.noreply.github.com>
This commit is contained in:
1 parent
1ffc23623d
commit
ae4f6727e0
18 files changed
+862
-40
No files matched your search
@@ -0,0 +1,75 @@
|
||||
package com.droiddeck.launcher.core
|
||||
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Test
|
||||
|
||||
class GameEnvironmentTest {
|
||||
@Test fun defaultsIncludeRequestedGraphicsLevelsAndKeepCaching() {
|
||||
val values = GameEnvironment.defaults("")
|
||||
assertEquals("false", values["MESA_SHADER_CACHE_DISABLE"])
|
||||
assertEquals("12_2", values["VKD3D_FEATURE_LEVEL"])
|
||||
assertEquals("6_9", values["VKD3D_SHADER_MODEL"])
|
||||
}
|
||||
|
||||
@Test fun gameOverridesSharedAndPresetWithoutLeakingToOtherGames() {
|
||||
val config = GameEnvironment.Config(
|
||||
shared = mapOf("FEX_MULTIBLOCK" to "0", "VKD3D_FEATURE_LEVEL" to "12_2"),
|
||||
games = mapOf("42" to mapOf("FEX_MULTIBLOCK" to "1", "VKD3D_FEATURE_LEVEL" to null)),
|
||||
)
|
||||
val game = GameEnvironment.effective(config, "COMPATIBILITY", "42")
|
||||
assertEquals("1", game["FEX_MULTIBLOCK"])
|
||||
assertTrue(game.containsKey("VKD3D_FEATURE_LEVEL"))
|
||||
assertNull(game["VKD3D_FEATURE_LEVEL"])
|
||||
val other = GameEnvironment.effective(config, "COMPATIBILITY", "43")
|
||||
assertEquals("0", other["FEX_MULTIBLOCK"])
|
||||
assertEquals("12_2", other["VKD3D_FEATURE_LEVEL"])
|
||||
}
|
||||
|
||||
@Test fun graphicsDefaultsRespectExistingEditsAndRemovals() {
|
||||
val config = GameEnvironment.Config(shared = mapOf("VKD3D_FEATURE_LEVEL" to "12_0"))
|
||||
.withEntries("42", mapOf("VKD3D_SHADER_MODEL" to null))
|
||||
val game = GameEnvironment.effective(config, "", "42")
|
||||
assertEquals("12_0", game["VKD3D_FEATURE_LEVEL"])
|
||||
assertTrue(game.containsKey("VKD3D_SHADER_MODEL"))
|
||||
assertNull(game["VKD3D_SHADER_MODEL"])
|
||||
val restored = GameEnvironment.effective(config.withEntries("42", emptyMap()), "", "42")
|
||||
assertEquals("6_9", restored["VKD3D_SHADER_MODEL"])
|
||||
}
|
||||
|
||||
@Test fun multiSelectionPreservesCustomTokensAndRemovesToggledValues() {
|
||||
assertEquals("fps,custom_token,frametimes", GameEnvironmentOptions.toggle("fps,custom_token", "frametimes"))
|
||||
assertEquals("custom_token", GameEnvironmentOptions.toggle("fps,custom_token", "fps"))
|
||||
assertEquals("", GameEnvironmentOptions.toggle("fps", "fps"))
|
||||
assertEquals("fps", GameEnvironmentOptions.toggle("", "fps"))
|
||||
}
|
||||
|
||||
@Test fun switchingPresetDropsOldPresetOnlyVariables() {
|
||||
val config = GameEnvironment.Config()
|
||||
assertEquals("none", GameEnvironment.effective(config, "EXTREME", "")["FEX_SMCCHECKS"])
|
||||
assertFalse(GameEnvironment.effective(config, "COMPATIBILITY", "").containsKey("FEX_SMCCHECKS"))
|
||||
assertFalse(GameEnvironment.effective(config, "", "").containsKey("FEX_MULTIBLOCK"))
|
||||
}
|
||||
|
||||
@Test fun resettingOneProfilePreservesOtherProfiles() {
|
||||
val config = GameEnvironment.Config(shared = mapOf("CUSTOM" to "shared"))
|
||||
.withEntries("42", mapOf("CUSTOM" to "game"))
|
||||
.withEntries("43", mapOf("CUSTOM" to "other"))
|
||||
.withEntries("42", emptyMap())
|
||||
assertEquals("shared", GameEnvironment.effective(config, "", "42")["CUSTOM"])
|
||||
assertEquals("other", GameEnvironment.effective(config, "", "43")["CUSTOM"])
|
||||
assertFalse(config.games.containsKey("42"))
|
||||
}
|
||||
|
||||
@Test fun validationPreservesLiteralValuesAndRejectsInvalidKeys() {
|
||||
assertTrue(GameEnvironment.validName("mesa_glthread"))
|
||||
assertFalse(GameEnvironment.validName("X=Y"))
|
||||
assertFalse(GameEnvironment.validName("1VAR"))
|
||||
assertFalse(GameEnvironment.validName("VAR\n"))
|
||||
assertTrue(GameEnvironment.validValue("a=b 'quote' $(touch file) ; $"))
|
||||
assertTrue(GameEnvironment.validValue(""))
|
||||
assertFalse(GameEnvironment.validValue("bad\u0000value"))
|
||||
assertFalse(GameEnvironment.validValue("x".repeat(8193)))
|
||||
assertTrue(GameEnvironment.validScope("4294967295"))
|
||||
for (scope in listOf("0", "-1", "01", "+1", "4294967296", "../42")) assertFalse(GameEnvironment.validScope(scope))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
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.*
|
||||
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 GameEnvironmentStoreTest {
|
||||
private lateinit var context: Context
|
||||
private lateinit var guest: File
|
||||
|
||||
@Before fun setUp() {
|
||||
context = RuntimeEnvironment.getApplication()
|
||||
guest = File(LinuxRuntime.rootDir(context), "root/.config/droiddeck/game-environment.json")
|
||||
File(context.filesDir, "game-environment.json").delete()
|
||||
}
|
||||
|
||||
@Test fun savedSettingsAndPublishedSettingsPreserveUnsetsAndLiteralValues() {
|
||||
val config = GameEnvironment.Config(
|
||||
shared = mapOf("LITERAL" to "a=b 'quoted' $(echo test)", "EMPTY" to ""),
|
||||
games = mapOf("42" to mapOf("LITERAL" to null, "VKD3D_SHADER_MODEL" to "6_9")),
|
||||
)
|
||||
GameEnvironmentStore.save(context, config)
|
||||
assertEquals(config, GameEnvironmentStore.read(context))
|
||||
val published = GameEnvironmentStore.decode(JSONObject(guest.readText()))
|
||||
assertEquals("false", published.shared["MESA_SHADER_CACHE_DISABLE"])
|
||||
assertEquals("12_2", published.shared["VKD3D_FEATURE_LEVEL"])
|
||||
assertEquals("6_9", published.shared["VKD3D_SHADER_MODEL"])
|
||||
assertEquals(config.games, published.games)
|
||||
assertEquals(config.shared["LITERAL"], published.shared["LITERAL"])
|
||||
assertEquals("", published.shared["EMPTY"])
|
||||
}
|
||||
|
||||
@Test fun changingFexPresetPublishesForNextGameLaunch() {
|
||||
GameEnvironmentStore.save(context, GameEnvironment.Config())
|
||||
SessionPrefs.setFexPreset(context, "EXTREME")
|
||||
assertEquals("none", JSONObject(guest.readText()).getJSONObject("shared").getString("FEX_SMCCHECKS"))
|
||||
SessionPrefs.setFexPreset(context, "")
|
||||
assertFalse(JSONObject(guest.readText()).getJSONObject("shared").has("FEX_SMCCHECKS"))
|
||||
}
|
||||
|
||||
@Test fun invalidDataCannotReplaceSavedConfiguration() {
|
||||
val original = GameEnvironment.Config(shared = mapOf("CUSTOM" to "ok"))
|
||||
GameEnvironmentStore.save(context, original)
|
||||
assertTrue(runCatching { GameEnvironmentStore.save(context, GameEnvironment.Config(shared = mapOf("BAD=NAME" to "x"))) }.isFailure)
|
||||
assertEquals(original, GameEnvironmentStore.read(context))
|
||||
}
|
||||
|
||||
@Test fun customComponentVariablesRemainEditable() {
|
||||
val config = GameEnvironment.Config(shared = mapOf("DXVK_ASYNC" to "1"))
|
||||
GameEnvironmentStore.save(context, config)
|
||||
assertEquals(config, GameEnvironmentStore.read(context))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user