mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 20:36:04 +00:00
Merge branch 'main' into fix/steam-client-download
# Conflicts: # tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-install # tools/tests/test_steam_install.py
This commit is contained in:
commit
2d9d4dbeb0
155 files changed
+6161
-993
No files matched your search
@@ -6,9 +6,11 @@ import android.os.Handler
|
||||
import android.os.Looper
|
||||
import com.droiddeck.launcher.session.QuestExperimental
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
import com.droiddeck.launcher.gpu.TpUbwcHint
|
||||
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
|
||||
@@ -17,11 +19,15 @@ import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.annotation.Config
|
||||
import org.robolectric.shadows.ShadowBuild
|
||||
import org.robolectric.util.ReflectionHelpers
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [28], manifest = Config.NONE)
|
||||
class DriverMenusAutoTest {
|
||||
@Before fun reset() {
|
||||
ReflectionHelpers.setStaticField(TpUbwcHint::class.java, "resolved", false)
|
||||
ReflectionHelpers.setStaticField(TpUbwcHint::class.java, "cached", null)
|
||||
ReflectionHelpers.setStaticField(TpUbwcHint::class.java, "activeMode", null)
|
||||
RuntimeEnvironment.getApplication().getSharedPreferences("session", Context.MODE_PRIVATE)
|
||||
.edit().clear().commit()
|
||||
ShadowBuild.setModel("Quest 3")
|
||||
@@ -53,4 +59,36 @@ class DriverMenusAutoTest {
|
||||
assertEquals("chosen-display", SessionPrefs.androidDriver(activity))
|
||||
assertEquals("chosen-linux", SessionPrefs.linuxDriver(activity))
|
||||
}
|
||||
|
||||
@Test fun driverMenusCanBeConstructedBeforeActivityContextIsAttached() {
|
||||
val menus = DriverMenus(Activity(), Handler(Looper.getMainLooper()))
|
||||
assertEquals(SessionPrefs.TP_UBWC_AUTO, menus.tpUbwcMode)
|
||||
}
|
||||
|
||||
@Test fun refreshingDriversLoadsTheSavedUbwcModeAfterContextAttachment() {
|
||||
val activity = Robolectric.buildActivity(Activity::class.java).setup().get()
|
||||
SessionPrefs.setTpUbwcMode(activity, SessionPrefs.TP_UBWC_ON)
|
||||
val menus = DriverMenus(activity, Handler(Looper.getMainLooper()))
|
||||
menus.refreshDrivers()
|
||||
assertEquals(SessionPrefs.TP_UBWC_ON, menus.tpUbwcMode)
|
||||
assertFalse(menus.state().tpUbwcRestartRequired)
|
||||
}
|
||||
|
||||
@Test fun changingUbwcBeforeTheFirstSessionDoesNotRequireRestart() {
|
||||
val activity = Robolectric.buildActivity(Activity::class.java).setup().get()
|
||||
val menus = DriverMenus(activity, Handler(Looper.getMainLooper()))
|
||||
menus.refreshDrivers()
|
||||
SessionPrefs.setTpUbwcMode(activity, SessionPrefs.TP_UBWC_ON)
|
||||
menus.refreshDrivers()
|
||||
assertFalse(menus.state().tpUbwcRestartRequired)
|
||||
}
|
||||
|
||||
@Test fun recreatingTheMenuKeepsTheActiveHintRestartWarning() {
|
||||
val activity = Robolectric.buildActivity(Activity::class.java).setup().get()
|
||||
TpUbwcHint.forThisDevice(activity)
|
||||
SessionPrefs.setTpUbwcMode(activity, SessionPrefs.TP_UBWC_ON)
|
||||
val menus = DriverMenus(activity, Handler(Looper.getMainLooper()))
|
||||
menus.refreshDrivers()
|
||||
assertTrue(menus.state().tpUbwcRestartRequired)
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
package com.droiddeck.launcher.core
|
||||
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Test
|
||||
|
||||
class CpuAllocationDefaultsTest {
|
||||
private val thor = (0..7).associateWith { when (it) { in 0..2 -> 2.016; in 3..6 -> 2.8032; else -> 3.1872 } }
|
||||
|
||||
@Test fun gen2UsesTheFourMiddleCoresAndOnePrime() {
|
||||
for (model in listOf("SM8550", "QCS8550", "sm8550-ac")) {
|
||||
assertEquals(CpuAllocationDefaults.Allocation("7", "3,4,5,6"), CpuAllocationDefaults.forDevice(model, "", thor))
|
||||
}
|
||||
assertEquals(CpuAllocationDefaults.Allocation("7", "3,4,5,6"), CpuAllocationDefaults.forDevice("", "kalama", thor))
|
||||
}
|
||||
|
||||
@Test fun coreNumbersAndClockVariantsAreDetectedInsteadOfHardcoded() {
|
||||
val reordered = mapOf(0 to 3.36, 1 to 2.0, 2 to 2.0, 3 to 2.0, 4 to 2.8, 5 to 2.8, 6 to 2.8, 7 to 2.8)
|
||||
assertEquals(CpuAllocationDefaults.Allocation("0", "4,5,6,7"), CpuAllocationDefaults.forDevice("SM8550-AC", "kalama", reordered))
|
||||
}
|
||||
|
||||
@Test fun anotherOrUnknownChipDoesNotAcquireThisDefault() {
|
||||
assertNull(CpuAllocationDefaults.forDevice("SM8650", "pineapple", thor))
|
||||
assertNull(CpuAllocationDefaults.forDevice("SM8650", "kalama", thor))
|
||||
assertNull(CpuAllocationDefaults.forDevice("", "", thor))
|
||||
}
|
||||
|
||||
@Test fun missingOrUnexpectedTopologyKeepsTheSchedulerDefault() {
|
||||
assertNull(CpuAllocationDefaults.forDevice("SM8550", "kalama", thor - 7))
|
||||
assertNull(CpuAllocationDefaults.forDevice("SM8550", "kalama", thor + (7 to null)))
|
||||
assertNull(CpuAllocationDefaults.forDevice("SM8550", "kalama", thor + (7 to 0.0)))
|
||||
assertNull(CpuAllocationDefaults.forDevice("SM8550", "kalama", thor + (7 to Double.NaN)))
|
||||
assertNull(CpuAllocationDefaults.forDevice("SM8550", "kalama", (0..7).associateWith { 2.8 }))
|
||||
}
|
||||
|
||||
@Test fun allCoreGamesUndoTheClientsInheritedRestriction() {
|
||||
val all = CpuCores.listOrAll("")
|
||||
assertEquals(all, CpuCores.gameLaunchList("", clientPinned = true))
|
||||
assertEquals(all, CpuCores.gameLaunchList(all, clientPinned = true))
|
||||
assertEquals("", CpuCores.gameLaunchList("", clientPinned = false))
|
||||
assertEquals("0", CpuCores.gameLaunchList("0", clientPinned = true))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.droiddeck.launcher.files
|
||||
|
||||
import java.io.File
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.TemporaryFolder
|
||||
|
||||
class FileManagerNavigationTest {
|
||||
@get:Rule val tmp = TemporaryFolder()
|
||||
|
||||
@Test fun backCannotNavigateAboveTheCurrentDriveRoot() {
|
||||
val drive = tmp.newFolder("drive")
|
||||
val child = File(drive, "folder").apply { mkdir() }
|
||||
|
||||
assertTrue(canNavigateUp(child, drive))
|
||||
assertFalse(canNavigateUp(drive, drive))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
package com.droiddeck.launcher.files
|
||||
|
||||
import java.io.File
|
||||
import java.util.concurrent.CancellationException
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertThrows
|
||||
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
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
class FileOpsCancellationTest {
|
||||
@get:Rule val tmp = TemporaryFolder()
|
||||
|
||||
@Test fun cancellingCopyRemovesAnIncompleteNewFile() {
|
||||
val source = tmp.newFile("source").apply { writeBytes(ByteArray(5 * 1024 * 1024)) }
|
||||
val destination = File(tmp.root, "destination")
|
||||
var cancelled = false
|
||||
|
||||
assertThrows(CancellationException::class.java) {
|
||||
FileOps.copyWithProgress(source, destination, { _, _ -> cancelled = true }) { cancelled }
|
||||
}
|
||||
|
||||
assertTrue(source.exists())
|
||||
assertFalse(destination.exists())
|
||||
}
|
||||
|
||||
@Test fun cancellingMoveFallbackPreservesTheSourceAndExistingDestination() {
|
||||
val source = tmp.newFile("source").apply { writeText("replacement") }
|
||||
val destination = tmp.newFile("destination").apply { writeText("original") }
|
||||
var cancelled = false
|
||||
|
||||
assertThrows(CancellationException::class.java) {
|
||||
FileOps.moveWithProgress(source, destination, { _, _ -> cancelled = true }) { cancelled }
|
||||
}
|
||||
|
||||
assertEquals("replacement", source.readText())
|
||||
assertEquals("original", destination.readText())
|
||||
}
|
||||
|
||||
@Test fun aCommittedMoveFinishesRemovingTheSourceDespiteCancellation() {
|
||||
val source = tmp.newFile("source").apply { writeText("replacement") }
|
||||
val destination = tmp.newFile("destination").apply { writeText("original") }
|
||||
val isCancelled = { destination.readText() == "replacement" }
|
||||
|
||||
assertTrue(FileOps.moveWithProgress(source, destination, null, isCancelled))
|
||||
|
||||
assertTrue(isCancelled())
|
||||
assertEquals("replacement", destination.readText())
|
||||
assertFalse(source.exists())
|
||||
assertEquals(setOf("destination"), tmp.root.list()!!.toSet())
|
||||
}
|
||||
|
||||
@Test fun cancellingTheSizeScanStopsBeforeCreatingTheDestination() {
|
||||
val source = tmp.newFolder("source")
|
||||
repeat(3) { File(source, "file-$it").writeText("content") }
|
||||
val destination = File(tmp.root, "destination")
|
||||
var checks = 0
|
||||
|
||||
assertThrows(CancellationException::class.java) {
|
||||
FileOps.copyWithProgress(source, destination, null) {
|
||||
assertFalse(destination.exists())
|
||||
++checks > 2
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals(3, checks)
|
||||
assertFalse(destination.exists())
|
||||
assertEquals(3, source.listFiles()?.size)
|
||||
}
|
||||
|
||||
@Test fun cancellingCopyRemovesANewDestinationDirectory() {
|
||||
val source = tmp.newFolder("source")
|
||||
val payload = File(source, "nested/payload").apply {
|
||||
parentFile!!.mkdirs()
|
||||
writeText("content")
|
||||
}
|
||||
val destination = File(tmp.root, "destination")
|
||||
|
||||
assertThrows(CancellationException::class.java) {
|
||||
FileOps.copyWithProgress(source, destination, { _, _ -> throw CancellationException("cancel") })
|
||||
}
|
||||
|
||||
assertEquals("content", payload.readText())
|
||||
assertFalse(destination.exists())
|
||||
}
|
||||
|
||||
@Test fun cancellingCopyPreservesAnExistingDestinationDirectory() {
|
||||
val source = tmp.newFolder("source")
|
||||
File(source, "nested/payload").apply {
|
||||
parentFile!!.mkdirs()
|
||||
writeText("replacement")
|
||||
}
|
||||
val destination = tmp.newFolder("destination")
|
||||
val existing = File(destination, "keep").apply { writeText("original") }
|
||||
|
||||
assertThrows(CancellationException::class.java) {
|
||||
FileOps.copyWithProgress(source, destination, { _, _ -> throw CancellationException("cancel") })
|
||||
}
|
||||
|
||||
assertEquals("original", existing.readText())
|
||||
assertEquals(setOf("keep"), destination.list()!!.toSet())
|
||||
}
|
||||
|
||||
@Test fun cancellingRecursiveDeleteStopsBeforeTheNextFile() {
|
||||
val directory = tmp.newFolder("directory")
|
||||
repeat(3) { File(directory, "file-$it").writeText("content") }
|
||||
var checks = 0
|
||||
|
||||
assertThrows(CancellationException::class.java) {
|
||||
FileOps.delete(directory) { ++checks > 3 }
|
||||
}
|
||||
|
||||
assertTrue(directory.exists())
|
||||
assertEquals(2, directory.listFiles()?.size)
|
||||
}
|
||||
}
|
||||
@@ -53,27 +53,25 @@ class FileOpsCopyTest {
|
||||
assertEquals("replacement", src.readText())
|
||||
}
|
||||
|
||||
@Test fun cancellingStopsATreeOfEmptyFiles() {
|
||||
@Test fun cancellingRemovesANewTreeOfEmptyFiles() {
|
||||
val src = tmp.newFolder("source")
|
||||
for (name in listOf("a", "b", "c")) File(src, name).createNewFile()
|
||||
val dst = File(tmp.root, "dest")
|
||||
var checks = 0
|
||||
assertThrows(CancellationException::class.java) {
|
||||
FileOps.copyWithProgress(src, dst, null) { checks++ > 1 }
|
||||
FileOps.copyWithProgress(src, dst, null) { dst.list()?.isNotEmpty() == true }
|
||||
}
|
||||
assertEquals(1, dst.list()!!.size)
|
||||
assertFalse(dst.exists())
|
||||
assertEquals(3, src.list()!!.size)
|
||||
}
|
||||
|
||||
@Test fun cancellingStopsATreeOfEmptyFolders() {
|
||||
@Test fun cancellingRemovesANewTreeOfEmptyFolders() {
|
||||
val src = tmp.newFolder("source")
|
||||
for (name in listOf("a", "b", "c")) File(src, name).mkdir()
|
||||
val dst = File(tmp.root, "dest")
|
||||
var checks = 0
|
||||
assertThrows(CancellationException::class.java) {
|
||||
FileOps.copyWithProgress(src, dst, null) { checks++ > 1 }
|
||||
FileOps.copyWithProgress(src, dst, null) { dst.list()?.isNotEmpty() == true }
|
||||
}
|
||||
assertEquals(1, dst.list()!!.size)
|
||||
assertFalse(dst.exists())
|
||||
}
|
||||
|
||||
@Test fun aCompletedCopyReplacesTheDestination() {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.droiddeck.launcher.frontend
|
||||
|
||||
import com.droiddeck.launcher.BuildConfig
|
||||
import com.droiddeck.launcher.stores.CredentialCipher
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONObject
|
||||
@@ -92,8 +93,9 @@ class AddedGameArtLookupTest {
|
||||
assertEquals("build", SteamGridDb.pick("", "build"))
|
||||
assertEquals("build", SteamGridDb.pick(" ", "build"))
|
||||
assertEquals("", SteamGridDb.pick("", ""))
|
||||
assertEquals("", SteamGridDb.builtInKey())
|
||||
assertEquals("", SteamGridDb.key(app))
|
||||
val builtIn = SteamGridDb.builtInKey()
|
||||
assertTrue(builtIn == BuildConfig.SGDB_API_KEY)
|
||||
assertTrue(SteamGridDb.key(app) == builtIn.trim())
|
||||
}
|
||||
|
||||
@Test fun theUsersKeyIsSealedOnDiskAndClears() {
|
||||
@@ -106,7 +108,7 @@ class AddedGameArtLookupTest {
|
||||
assertEquals("abcdef0123456789secretkey", SteamGridDb.key(app))
|
||||
SteamGridDb.setUserKey(app, "")
|
||||
assertFalse(file.exists())
|
||||
assertEquals("", SteamGridDb.key(app))
|
||||
assertTrue(SteamGridDb.key(app) == SteamGridDb.builtInKey().trim())
|
||||
}
|
||||
|
||||
@Test fun aFailedLookupIsNotRememberedAsNoMatch() {
|
||||
|
||||
@@ -3,13 +3,23 @@ package com.droiddeck.launcher.gpu
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Test
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
|
||||
class TpUbwcHintTest {
|
||||
@Test fun a740OnABlobV6xxTurnsTheHintOff() {
|
||||
assertEquals("enable_tp_ubwc_flag_hint=0", TpUbwcHint.features(740, "512.676.53"))
|
||||
assertEquals("enable_tp_ubwc_flag_hint=0", TpUbwcHint.features(740, "512.676.75"))
|
||||
assertEquals("enable_tp_ubwc_flag_hint=0", TpUbwcHint.features(740, "512.676"))
|
||||
assertEquals("enable_tp_ubwc_flag_hint=0", TpUbwcHint.features(740, "512.699.10"))
|
||||
}
|
||||
|
||||
@Test fun a740OnThePocoBlobTurnsTheHintOn() {
|
||||
assertEquals("enable_tp_ubwc_flag_hint=1", TpUbwcHint.features(740, "512.676.76"))
|
||||
assertEquals("enable_tp_ubwc_flag_hint=1", TpUbwcHint.features(740, "512.676.80"))
|
||||
}
|
||||
|
||||
@Test fun a740OnANewerBlobTurnsTheHintOn() {
|
||||
assertEquals("enable_tp_ubwc_flag_hint=1", TpUbwcHint.features(740, "512.700.0"))
|
||||
assertEquals("enable_tp_ubwc_flag_hint=1", TpUbwcHint.features(740, "512.762.10"))
|
||||
}
|
||||
|
||||
@@ -18,6 +28,24 @@ class TpUbwcHintTest {
|
||||
assertEquals("enable_tp_ubwc_flag_hint=1", TpUbwcHint.features(740, null, samsung = true))
|
||||
}
|
||||
|
||||
@Test fun onOverridesThePocoRuleEvenWhenTheVersionIsUnreadable() {
|
||||
for (version in listOf("512.676.1", "512.676.53", "garbage", null)) {
|
||||
assertEquals("enable_tp_ubwc_flag_hint=1", TpUbwcHint.features(740, version, mode = SessionPrefs.TP_UBWC_ON))
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun offOverridesSamsungAndNewerBlobs() {
|
||||
assertEquals("enable_tp_ubwc_flag_hint=0", TpUbwcHint.features(740, "512.762.10", mode = SessionPrefs.TP_UBWC_OFF))
|
||||
assertEquals("enable_tp_ubwc_flag_hint=0", TpUbwcHint.features(740, null, samsung = true, mode = SessionPrefs.TP_UBWC_OFF))
|
||||
}
|
||||
|
||||
@Test fun overridesDoNotApplyToOtherGpus() {
|
||||
for (mode in listOf(SessionPrefs.TP_UBWC_ON, SessionPrefs.TP_UBWC_OFF)) {
|
||||
assertNull(TpUbwcHint.features(750, "512.762.10", mode = mode))
|
||||
assertNull(TpUbwcHint.features(0, null, mode = mode))
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun otherGpusKeepTheirDriverDefault() {
|
||||
assertNull(TpUbwcHint.features(750, "512.762.10"))
|
||||
assertNull(TpUbwcHint.features(830, "512.676.53"))
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.droiddeck.launcher.runtime
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNotEquals
|
||||
import org.junit.Test
|
||||
|
||||
class SeededMacTest {
|
||||
@Test
|
||||
fun theAndroidIdSeedsAStableLocalMac() {
|
||||
val mac = LinuxNetworkLinkComponent.seededMac { "0123456789abcdef" }
|
||||
assertEquals(mac, LinuxNetworkLinkComponent.seededMac { "0123456789abcdef" })
|
||||
assertNotEquals(mac, LinuxNetworkLinkComponent.seededMac { null })
|
||||
assertEquals(0x02, mac.substringBefore(':').toInt(16) and 0x03)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aRomThatThrowsOnTheAndroidIdReadFallsBackToTheDefaultSeed() {
|
||||
val mac = LinuxNetworkLinkComponent.seededMac { throw IllegalArgumentException("Illegal char: - at offset 8") }
|
||||
assertEquals(LinuxNetworkLinkComponent.seededMac { null }, mac)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
import org.json.JSONObject
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import java.io.File
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
class ComponentsSelectionTest {
|
||||
private val proton = ComponentsManager.Proton("DroidDeck-Proton_11-11.1", "DroidDeck-Proton 11-11.1", File("/p"), "/p", "DroidDeck-Proton-11-11.1", false)
|
||||
private val entry = JSONObject().put("file", "dxvk-low-latency-arm64ec-3.1.1-2-linux.wcp").put("protonVersion", "DroidDeck-Proton-11-11.1")
|
||||
|
||||
@Test
|
||||
fun `a package swapped into an installed Proton is in use`() {
|
||||
assertTrue(ComponentsManager.liveSelection("active", entry, proton))
|
||||
assertTrue(ComponentsManager.liveSelection("queued", JSONObject().put("file", "x.wcp"), proton))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a package left on a removed Proton is not in use`() {
|
||||
assertFalse(ComponentsManager.liveSelection("active", entry, null))
|
||||
assertFalse(ComponentsManager.liveSelection("queued", entry, null))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a package from before a Proton update is not in use`() {
|
||||
assertFalse(ComponentsManager.liveSelection("active", JSONObject(entry.toString()).put("protonVersion", "DroidDeck-Proton-11-9.1"), proton))
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
import android.content.Context
|
||||
import com.droiddeck.launcher.core.CpuAllocationDefaults
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
@@ -14,36 +13,22 @@ import org.robolectric.annotation.Config
|
||||
@Config(sdk = [33])
|
||||
class CoreAllocationPrefsTest {
|
||||
private val app get() = RuntimeEnvironment.getApplication()
|
||||
private val defaults = CpuAllocationDefaults.Allocation("7", "3,4,5,6")
|
||||
private val saved get() = app.getSharedPreferences("session", Context.MODE_PRIVATE)
|
||||
|
||||
@Before fun clear() { saved.edit().clear().commit() }
|
||||
|
||||
@Test fun absentPreferencesUseTheDeviceDefaultWithoutWritingIt() {
|
||||
assertEquals(SessionPrefs.CoreAllocation(true, "7", "3,4,5,6"), SessionPrefs.coreAllocation(app, defaults))
|
||||
assertTrue(saved.all.isEmpty())
|
||||
assertEquals(SessionPrefs.CoreAllocation(false, "", ""), SessionPrefs.coreAllocation(app, null))
|
||||
@Test fun absentPreferencesLeaveEveryCoreToTheScheduler() {
|
||||
assertFalse(SessionPrefs.clientCpusOverride(app))
|
||||
assertEquals("", SessionPrefs.clientCpus(app))
|
||||
assertEquals("", SessionPrefs.gameCpus(app))
|
||||
}
|
||||
|
||||
@Test fun explicitDisableAndAllCoreChoicesSurviveAnUpdate() {
|
||||
saved.edit().putBoolean("clientCpusOverride", false).putString("clientCpus", "").putString("gameCpus", "").commit()
|
||||
assertEquals(SessionPrefs.CoreAllocation(false, "", ""), SessionPrefs.coreAllocation(app, defaults))
|
||||
}
|
||||
|
||||
@Test fun existingCustomMasksArePreserved() {
|
||||
saved.edit().putBoolean("clientCpusOverride", true).putString("clientCpus", "0,1").putString("gameCpus", "2,7").commit()
|
||||
assertEquals(SessionPrefs.CoreAllocation(true, "0,1", "2,7"), SessionPrefs.coreAllocation(app, defaults))
|
||||
}
|
||||
|
||||
@Test fun anOldClientMaskIsNotEnabledWithoutAnOverrideChoice() {
|
||||
saved.edit().putString("clientCpus", "0,1").commit()
|
||||
assertEquals(SessionPrefs.CoreAllocation(false, "0,1", "3,4,5,6"), SessionPrefs.coreAllocation(app, defaults))
|
||||
}
|
||||
|
||||
@Test fun changingOneChoiceDoesNotReplaceTheOtherDefaults() {
|
||||
SessionPrefs.setGameCpus(app, "0,1,2,3,4,5,6,7")
|
||||
assertEquals(SessionPrefs.CoreAllocation(true, "7", "0,1,2,3,4,5,6,7"), SessionPrefs.coreAllocation(app, defaults))
|
||||
SessionPrefs.setClientCpusOverride(app, false)
|
||||
assertEquals(SessionPrefs.CoreAllocation(false, "7", "0,1,2,3,4,5,6,7"), SessionPrefs.coreAllocation(app, defaults))
|
||||
@Test fun savedChoicesAreKept() {
|
||||
SessionPrefs.setClientCpusOverride(app, true)
|
||||
SessionPrefs.setClientCpus(app, "7")
|
||||
SessionPrefs.setGameCpus(app, "3,4,5,6")
|
||||
assertTrue(SessionPrefs.clientCpusOverride(app))
|
||||
assertEquals("7", SessionPrefs.clientCpus(app))
|
||||
assertEquals("3,4,5,6", SessionPrefs.gameCpus(app))
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,7 @@ class OrientationTest {
|
||||
}
|
||||
|
||||
@Test fun landscapeChoicesPersistGloballyAndCanRestoreAutomaticRotation() {
|
||||
assertEquals(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE, SessionPrefs.orientation(context))
|
||||
assertEquals(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE, SessionPrefs.orientation(context))
|
||||
for (value in listOf(
|
||||
ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
|
||||
ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE,
|
||||
@@ -34,7 +34,7 @@ class OrientationTest {
|
||||
@Test fun invalidStoredOrientationFallsBackAndInvalidChoicePreservesTheSavedValue() {
|
||||
val prefs = context.getSharedPreferences("session", Context.MODE_PRIVATE)
|
||||
prefs.edit().putInt("orientation", ActivityInfo.SCREEN_ORIENTATION_PORTRAIT).commit()
|
||||
assertEquals(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE, SessionPrefs.orientation(context))
|
||||
assertEquals(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE, SessionPrefs.orientation(context))
|
||||
SessionPrefs.setOrientation(context, ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE)
|
||||
assertThrows(IllegalArgumentException::class.java) {
|
||||
SessionPrefs.setOrientation(context, ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)
|
||||
|
||||
@@ -13,9 +13,33 @@ class SyncBackendTest {
|
||||
private val context: Context = RuntimeEnvironment.getApplication()
|
||||
|
||||
@Test
|
||||
fun aFreshInstallStartsOnEsync() {
|
||||
assertEquals(SessionPrefs.SYNC_ESYNC, SessionPrefs.syncBackend(context))
|
||||
fun aFreshInstallStartsOnNtsync() {
|
||||
assertEquals(SessionPrefs.SYNC_NTSYNC, SessionPrefs.syncBackend(context))
|
||||
assertEquals(false, SessionPrefs.fsyncFirst(context))
|
||||
SessionPrefs.applyNtsyncDefault(context)
|
||||
assertEquals(SessionPrefs.SYNC_NTSYNC, SessionPrefs.syncBackend(context))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun anEarlierChoiceMovesToNtsyncOnce() {
|
||||
for (earlier in listOf(SessionPrefs.SYNC_ESYNC, SessionPrefs.SYNC_FSYNC, SessionPrefs.SYNC_WINESERVER)) {
|
||||
context.getSharedPreferences("session", Context.MODE_PRIVATE).edit().clear().commit()
|
||||
SessionPrefs.setSyncBackend(context, earlier)
|
||||
SessionPrefs.applyNtsyncDefault(context)
|
||||
assertEquals(SessionPrefs.SYNC_NTSYNC, SessionPrefs.syncBackend(context))
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aChoiceMadeAfterTheMoveIsKept() {
|
||||
SessionPrefs.setSyncBackend(context, SessionPrefs.SYNC_ESYNC)
|
||||
SessionPrefs.applyNtsyncDefault(context)
|
||||
SessionPrefs.setSyncBackend(context, SessionPrefs.SYNC_ESYNC)
|
||||
SessionPrefs.applyNtsyncDefault(context)
|
||||
assertEquals(SessionPrefs.SYNC_ESYNC, SessionPrefs.syncBackend(context))
|
||||
SessionPrefs.setSyncBackend(context, SessionPrefs.SYNC_WINESERVER)
|
||||
SessionPrefs.applyNtsyncDefault(context)
|
||||
assertEquals(SessionPrefs.SYNC_WINESERVER, SessionPrefs.syncBackend(context))
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -34,6 +58,7 @@ class SyncBackendTest {
|
||||
|
||||
@Test
|
||||
fun pickingATabTurnsSyncBackOn() {
|
||||
SessionPrefs.setFastSync(context, false)
|
||||
SessionPrefs.setSyncFallback(context, false)
|
||||
SessionPrefs.setFsyncFirst(context, false)
|
||||
assertEquals(SessionPrefs.SYNC_WINESERVER, SessionPrefs.syncBackend(context))
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
import android.content.Context
|
||||
import com.droiddeck.launcher.gpu.TpUbwcHint
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
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 org.robolectric.util.ReflectionHelpers
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [28], manifest = Config.NONE)
|
||||
class TpUbwcPrefsTest {
|
||||
private val context: Context get() = RuntimeEnvironment.getApplication()
|
||||
|
||||
@Before fun reset() {
|
||||
ReflectionHelpers.setStaticField(TpUbwcHint::class.java, "resolved", false)
|
||||
ReflectionHelpers.setStaticField(TpUbwcHint::class.java, "cached", null)
|
||||
ReflectionHelpers.setStaticField(TpUbwcHint::class.java, "activeMode", null)
|
||||
context.getSharedPreferences("session", Context.MODE_PRIVATE).edit().clear().commit()
|
||||
}
|
||||
|
||||
@Test fun missingOrInvalidChoiceUsesAuto() {
|
||||
assertEquals(SessionPrefs.TP_UBWC_AUTO, SessionPrefs.tpUbwcMode(context))
|
||||
context.getSharedPreferences("session", Context.MODE_PRIVATE).edit().putString("tpUbwcMode", "invalid").commit()
|
||||
assertEquals(SessionPrefs.TP_UBWC_AUTO, SessionPrefs.tpUbwcMode(context))
|
||||
}
|
||||
|
||||
@Test fun overrideIsStoredWithoutChangingDriverChoices() {
|
||||
SessionPrefs.setAndroidDriver(context, "display")
|
||||
SessionPrefs.setLinuxDriver(context, "runtime")
|
||||
for (mode in listOf(SessionPrefs.TP_UBWC_ON, SessionPrefs.TP_UBWC_OFF, SessionPrefs.TP_UBWC_AUTO)) {
|
||||
SessionPrefs.setTpUbwcMode(context, mode)
|
||||
assertEquals(mode, SessionPrefs.tpUbwcMode(context))
|
||||
assertEquals("display", SessionPrefs.androidDriver(context))
|
||||
assertEquals("runtime", SessionPrefs.linuxDriver(context))
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun changingTheSavedChoiceKeepsTheProcessChoiceUntilRestart() {
|
||||
SessionPrefs.setTpUbwcMode(context, SessionPrefs.TP_UBWC_ON)
|
||||
val initial = TpUbwcHint.forThisDevice(context)
|
||||
SessionPrefs.setTpUbwcMode(context, SessionPrefs.TP_UBWC_OFF)
|
||||
assertTrue(TpUbwcHint.restartRequired(context))
|
||||
assertEquals(SessionPrefs.TP_UBWC_ON, TpUbwcHint.activeMode)
|
||||
assertEquals(initial, TpUbwcHint.forThisDevice(context))
|
||||
SessionPrefs.setTpUbwcMode(context, SessionPrefs.TP_UBWC_ON)
|
||||
assertFalse(TpUbwcHint.restartRequired(context))
|
||||
}
|
||||
}
|
||||
@@ -92,6 +92,30 @@ class SteamStorageTest {
|
||||
assertEquals(emptyMap<String, String>(), SteamStorage.compatMappings("\"x\" {}"))
|
||||
}
|
||||
|
||||
@Test fun readsShaderPrecacheFromConfig() {
|
||||
val vdf = """
|
||||
"InstallConfigStore"
|
||||
{
|
||||
"Software" { "Valve" { "Steam" { "ShaderCacheManager"
|
||||
{
|
||||
"HasCurrentBucket" "1"
|
||||
"DisableShaderCache" "1"
|
||||
} } } }
|
||||
}
|
||||
""".trimIndent()
|
||||
assertEquals(false, SteamStorage.shaderPrecache(vdf))
|
||||
assertEquals(true, SteamStorage.shaderPrecache(vdf.replace("\"DisableShaderCache\"\t\t\"1\"", "\"DisableShaderCache\"\t\t\"0\"")))
|
||||
assertEquals(true, SteamStorage.shaderPrecache("\"InstallConfigStore\" {}"))
|
||||
assertEquals(true, SteamStorage.shaderPrecache("""
|
||||
"InstallConfigStore"
|
||||
{
|
||||
// "DisableShaderCache" "1"
|
||||
"Other" { "DisableShaderCache" "1" }
|
||||
"Software" { "Valve" { "Steam" { "ShaderCacheManager" { "DisableShaderCache" "0" } } } }
|
||||
}
|
||||
""".trimIndent()))
|
||||
}
|
||||
|
||||
@Test fun readsCustomToolName() {
|
||||
val vdf = "\"compatibilitytools\"\n{\n \"compat_tools\"\n {\n \"GE-Proton11-9-aarch64\"\n {\n \"install_path\" \".\"\n }\n }\n}"
|
||||
assertEquals("GE-Proton11-9-aarch64", SteamStorage.compatToolName(vdf))
|
||||
|
||||
@@ -29,6 +29,17 @@ class PickListingTest {
|
||||
assertEquals(listOf("alarms", "Android", "DCIM", "Documents", "Download", "Games", "Winlator"), listing.folders.map { it.dir.name })
|
||||
}
|
||||
|
||||
@Test fun hiddenDirectoriesAndExecutablesCanBeShownOnRequest() {
|
||||
val root = storage()
|
||||
val hidden = File(root, ".Games").apply { mkdirs() }
|
||||
File(hidden, "Game.exe").writeText("game")
|
||||
assertFalse(pickListing(root, PickKind.EXE).folders.any { it.dir.name == ".Games" })
|
||||
val listing = pickListing(root, PickKind.EXE, showHidden = true)
|
||||
assertTrue(listing.folders.any { it.dir.name == ".Games" })
|
||||
assertTrue(listing.files.any { it.name == ".hidden.exe" })
|
||||
assertEquals(listOf("Game.exe"), pickListing(hidden, PickKind.EXE).files.map { it.name })
|
||||
}
|
||||
|
||||
@Test fun onlyExesForAGameOnlyImagesForArt() {
|
||||
val root = storage()
|
||||
assertEquals(listOf("game.EXE", "Setup.exe"), pickListing(root, PickKind.EXE).files.map { it.name })
|
||||
|
||||
@@ -132,4 +132,40 @@ class ThemeColorsTest {
|
||||
assertTrue(Themes.all.any { it.id == Themes.GRADIENT })
|
||||
assertEquals(Themes.GRAPHITE, Themes.byId("nonsense").id)
|
||||
}
|
||||
|
||||
@Test fun innerGamerSitsJustAboveGradientInTheThemeList() {
|
||||
val ids = Themes.all.map { it.id }
|
||||
assertEquals(ids.indexOf(Themes.GRADIENT) - 1, ids.indexOf(Themes.INNER_GAMER))
|
||||
}
|
||||
|
||||
@Test fun innerGamerButtonTextIsReadableAlongTheGradientAtEveryHue() {
|
||||
var hue = 0f
|
||||
while (hue < 360f) {
|
||||
val p = Themes.innerGamer(hue)
|
||||
assertEquals(Themes.INNER_GAMER, p.id)
|
||||
for (i in 0..100) {
|
||||
val f = i / 100f
|
||||
val blend = Color(
|
||||
p.primary.red + (p.primary2.red - p.primary.red) * f,
|
||||
p.primary.green + (p.primary2.green - p.primary.green) * f,
|
||||
p.primary.blue + (p.primary2.blue - p.primary.blue) * f,
|
||||
)
|
||||
assertTrue("hue $hue at $f", contrast(p.onPrimary, blend) >= 4.49f)
|
||||
}
|
||||
hue += Themes.RGB_HUE_STEP
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun innerGamerFollowsTheHueAndTheSpeedIsSavedAndKeptInRange() {
|
||||
Themes.moveRgbHue(120f)
|
||||
assertEquals(Themes.innerGamer(120f).primary, Themes.byId(Themes.INNER_GAMER).primary)
|
||||
Themes.setRgbSpeed(app, 7)
|
||||
assertEquals(7, SessionPrefs.rgbSpeed(app))
|
||||
Themes.setRgbSpeed(app, 99)
|
||||
assertEquals(Themes.RGB_SPEEDS, Themes.rgbSpeed)
|
||||
Themes.setRgbSpeed(app, 0)
|
||||
assertEquals(1, SessionPrefs.rgbSpeed(app))
|
||||
Themes.setRgbSpeed(app, 1)
|
||||
assertTrue(Themes.rgbCycleMillis(1) > Themes.rgbCycleMillis(10))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user