mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-19 12:56:06 +00:00
Merge current main into PR #1042
This commit is contained in:
commit
287eafed0c
326 files changed
+22382
-2984
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)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,244 @@
|
||||
package com.droiddeck.launcher
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import androidx.compose.ui.geometry.Rect
|
||||
import com.droiddeck.launcher.frontend.AutoComponents
|
||||
import com.droiddeck.launcher.runtime.LinuxRuntime
|
||||
import com.droiddeck.launcher.session.ProtonExtras
|
||||
import com.droiddeck.launcher.session.SessionState
|
||||
import com.droiddeck.launcher.session.SessionPhase
|
||||
import com.droiddeck.launcher.session.LoadingState
|
||||
import com.droiddeck.launcher.ui.LaunchOrigin
|
||||
import com.droiddeck.launcher.ui.Motion
|
||||
import org.json.JSONObject
|
||||
import org.junit.After
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.Robolectric
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.Shadows.shadowOf
|
||||
import org.robolectric.annotation.Config
|
||||
import org.robolectric.util.ReflectionHelpers
|
||||
import java.io.File
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [28], manifest = Config.NONE)
|
||||
class ProtonMenuAutoTest {
|
||||
private val online = AutoComponents.online
|
||||
private val constrained = AutoComponents.unfavourable
|
||||
private lateinit var activity: Activity
|
||||
private lateinit var menu: ProtonMenu
|
||||
private lateinit var root: File
|
||||
private val attempts = mutableListOf<String>()
|
||||
private var idle = true
|
||||
|
||||
@Before fun setup() {
|
||||
activity = Robolectric.buildActivity(Activity::class.java).setup().get()
|
||||
root = LinuxRuntime.rootDir(activity)
|
||||
for (path in listOf("usr/bin/gamescope", "usr/local/bin/droiddeck-session", "opt/android-host/proot", "opt/android-host/loader")) {
|
||||
File(root, path).apply { parentFile!!.mkdirs(); writeText("") }
|
||||
}
|
||||
AutoComponents.online = { true }
|
||||
AutoComponents.unfavourable = { false }
|
||||
SessionState.running = false
|
||||
SessionState.phase = SessionPhase.IDLE
|
||||
SessionState.stopRequested = false
|
||||
LaunchOrigin.take()
|
||||
LaunchOrigin.flooding = null
|
||||
val latest = JSONObject()
|
||||
for (tool in ProtonExtras.tools) latest.put(tool.id, JSONObject()
|
||||
.put("tag", "${tool.prefix}-11-12").put("at", System.currentTimeMillis()))
|
||||
File(activity.filesDir, "proton-latest.json").writeText(latest.toString())
|
||||
menu = ProtonMenu(activity, Handler(Looper.getMainLooper())) { idle }
|
||||
menu.installer = { tool, progress ->
|
||||
progress("Installing ${tool.name}", 50)
|
||||
install("${tool.prefix}-11-12")
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
@After fun reset() {
|
||||
AutoComponents.online = online
|
||||
AutoComponents.unfavourable = constrained
|
||||
SessionState.running = false
|
||||
SessionState.phase = SessionPhase.IDLE
|
||||
SessionState.stopRequested = false
|
||||
LaunchOrigin.take()
|
||||
LaunchOrigin.flooding = null
|
||||
}
|
||||
|
||||
private fun install(name: String): File = File(root, "root/.local/share/Steam/compatibilitytools.d/$name").apply {
|
||||
mkdirs()
|
||||
File(this, "toolmanifest.vdf").writeText("manifest")
|
||||
}
|
||||
|
||||
private fun waitUntil(done: () -> Boolean) {
|
||||
val deadline = System.nanoTime() + 5_000_000_000L
|
||||
while (System.nanoTime() < deadline) {
|
||||
shadowOf(Looper.getMainLooper()).idle()
|
||||
if (done()) return
|
||||
Thread.sleep(10)
|
||||
}
|
||||
fail("Proton work did not finish")
|
||||
}
|
||||
|
||||
@Test fun aCachedCheckUpdatesOnlyInstalledFamiliesAndKeepsOlderBuildsAndSelections() {
|
||||
val older = install("DroidDeck-Proton-11-11.1")
|
||||
val request = File(root, "root/.local/share/droiddeck-compat/request.json").apply {
|
||||
parentFile!!.mkdirs()
|
||||
writeText("{\"seq\":1,\"dir\":\"DroidDeck-Proton-11-11.1\",\"valve\":false}")
|
||||
}
|
||||
val before = request.readText()
|
||||
assertFalse(ProtonExtras.checkLatest(activity))
|
||||
menu.checkUpdates()
|
||||
waitUntil { menu.protonRows.singleOrNull { it.id == "droiddeck" }?.installed == "DroidDeck-Proton-11-12" && menu.protonBusyId == null }
|
||||
assertTrue(older.isDirectory)
|
||||
assertEquals(before, request.readText())
|
||||
assertTrue(ProtonExtras.installedAll(activity, ProtonExtras.tools.first { it.id == "ge" }).isEmpty())
|
||||
assertTrue(ProtonExtras.installedAll(activity, ProtonExtras.tools.first { it.id == "cachyos" }).isEmpty())
|
||||
}
|
||||
|
||||
@Test fun downloadsWaitForTheSessionNetworkPowerAndOtherInstallWork() {
|
||||
install("DroidDeck-Proton-11-11.1")
|
||||
menu.installer = { tool, _ -> attempts.add(tool.id); "failed" }
|
||||
SessionState.running = true
|
||||
menu.ensureAutoUpdates()
|
||||
SessionState.running = false
|
||||
AutoComponents.online = { false }
|
||||
menu.ensureAutoUpdates()
|
||||
AutoComponents.online = { true }
|
||||
AutoComponents.unfavourable = { true }
|
||||
menu.ensureAutoUpdates()
|
||||
AutoComponents.unfavourable = { false }
|
||||
idle = false
|
||||
menu.ensureAutoUpdates()
|
||||
assertNull(menu.protonBusyId)
|
||||
assertTrue(attempts.isEmpty())
|
||||
idle = true
|
||||
menu.ensureAutoUpdates()
|
||||
waitUntil { menu.protonBusyId == null }
|
||||
assertEquals(listOf("droiddeck"), attempts)
|
||||
}
|
||||
|
||||
@Test fun aFailedUpdateDoesNotLoopOrBlockOtherInstalledFamilies() {
|
||||
val ge = install("GE-Proton11-11")
|
||||
val dd = install("DroidDeck-Proton-11-11.1")
|
||||
menu.installer = { tool, _ ->
|
||||
attempts.add(tool.id)
|
||||
if (tool.id == "ge") throw IllegalStateException("download failed")
|
||||
install("${tool.prefix}-11-12")
|
||||
null
|
||||
}
|
||||
menu.ensureAutoUpdates()
|
||||
waitUntil { menu.protonBusyId == null }
|
||||
menu.ensureAutoUpdates()
|
||||
shadowOf(Looper.getMainLooper()).idle()
|
||||
assertEquals(listOf("ge", "droiddeck"), attempts)
|
||||
assertTrue(ge.isDirectory)
|
||||
assertTrue(dd.isDirectory)
|
||||
assertNull(menu.protonStage)
|
||||
assertEquals(-1, menu.protonPercent)
|
||||
}
|
||||
|
||||
@Test fun anUninstalledRuntimeOrCurrentProtonDoesNotStartADownload() {
|
||||
install("DroidDeck-Proton-11-12")
|
||||
menu.installer = { tool, _ -> attempts.add(tool.id); null }
|
||||
menu.ensureAutoUpdates()
|
||||
assertTrue(attempts.isEmpty())
|
||||
install("GE-Proton11-11")
|
||||
File(root, "usr/bin/gamescope").delete()
|
||||
menu.ensureAutoUpdates()
|
||||
assertTrue(attempts.isEmpty())
|
||||
assertNull(menu.protonBusyId)
|
||||
}
|
||||
|
||||
@Test fun aFailedReleaseIsNotRetriedAfterRecreatingTheLauncher() {
|
||||
install("DroidDeck-Proton-11-11.1")
|
||||
menu.installer = { tool, _ -> attempts.add(tool.id); "failed" }
|
||||
menu.ensureAutoUpdates()
|
||||
waitUntil { menu.protonBusyId == null }
|
||||
val recreated = Robolectric.buildActivity(Activity::class.java).setup().get()
|
||||
val next = ProtonMenu(recreated, Handler(Looper.getMainLooper()))
|
||||
next.installer = { tool, _ -> attempts.add(tool.id); "failed" }
|
||||
next.ensureAutoUpdates()
|
||||
assertNull(next.protonBusyId)
|
||||
assertEquals(listOf("droiddeck"), attempts)
|
||||
}
|
||||
|
||||
@Test fun automaticUpdatesWaitForEveryNonEndedSessionPhaseEvenWhenRunningIsFalse() {
|
||||
install("DroidDeck-Proton-11-11.1")
|
||||
for (phase in SessionPhase.entries.filter { it != SessionPhase.IDLE && it != SessionPhase.FAILED }) {
|
||||
SessionState.phase = phase
|
||||
menu.ensureAutoUpdates()
|
||||
assertNull("Must wait during $phase", menu.protonBusyId)
|
||||
}
|
||||
SessionState.phase = SessionPhase.FAILED
|
||||
menu.ensureAutoUpdates()
|
||||
waitUntil { menu.protonBusyId == null }
|
||||
assertEquals("DroidDeck-Proton-11-12", ProtonExtras.installed(activity, ProtonExtras.tools.first { it.id == "droiddeck" }))
|
||||
}
|
||||
|
||||
@Test fun aPendingAnimatedLaunchPreventsAnAutomaticInstall() {
|
||||
install("DroidDeck-Proton-11-11.1")
|
||||
val launcher = Robolectric.buildActivity(FrontEndActivity::class.java).get()
|
||||
val protons = ReflectionHelpers.getField<ProtonMenu>(launcher, "protons")
|
||||
protons.installer = { tool, _ -> attempts.add(tool.id); "failed" }
|
||||
Motion.refresh(launcher)
|
||||
LaunchOrigin.mark(Rect(0f, 0f, 100f, 100f), "game")
|
||||
launcher.startActivity(Intent(launcher, SessionActivity::class.java))
|
||||
assertNotNull(ReflectionHelpers.callInstanceMethod<Any?>(launcher, "getFlood"))
|
||||
assertNull(shadowOf(launcher).nextStartedActivity)
|
||||
protons.ensureAutoUpdates()
|
||||
assertNull(protons.protonBusyId)
|
||||
assertTrue(attempts.isEmpty())
|
||||
}
|
||||
|
||||
@Test fun anAnimatedLaunchRechecksTheProtonInstallGuardBeforeStarting() {
|
||||
val launcher = Robolectric.buildActivity(FrontEndActivity::class.java).get()
|
||||
Motion.refresh(launcher)
|
||||
LaunchOrigin.mark(Rect(0f, 0f, 100f, 100f), "game")
|
||||
launcher.startActivity(Intent(launcher, SessionActivity::class.java))
|
||||
val pending = requireNotNull(ReflectionHelpers.callInstanceMethod<Any?>(launcher, "getFlood"))
|
||||
ReflectionHelpers.getField<ProtonMenu>(launcher, "protons").protonBusyId = "droiddeck"
|
||||
FrontEndActivity::class.java.getDeclaredMethod("launchFlooded", pending.javaClass)
|
||||
.apply { isAccessible = true }.invoke(launcher, pending)
|
||||
assertNull(shadowOf(launcher).nextStartedActivity)
|
||||
assertNull(ReflectionHelpers.callInstanceMethod<Any?>(launcher, "getFlood"))
|
||||
assertNull(LaunchOrigin.flooding)
|
||||
}
|
||||
|
||||
@Test fun aCancellationDuringTeardownCannotPublishIdleEarly() {
|
||||
val session = watchCancellation(SessionPhase.STOPPING)
|
||||
assertEquals(SessionPhase.STOPPING, SessionState.phase)
|
||||
assertTrue(SessionState.stopRequested)
|
||||
assertFalse(session.isFinishing)
|
||||
}
|
||||
|
||||
@Test fun cancellationBeforeSessionStartupStillFinishesTheActivity() {
|
||||
val session = watchCancellation(SessionPhase.PREPARING)
|
||||
assertEquals(SessionPhase.IDLE, SessionState.phase)
|
||||
assertFalse(SessionState.stopRequested)
|
||||
assertTrue(session.isFinishing)
|
||||
}
|
||||
|
||||
private fun watchCancellation(phase: SessionPhase): SessionActivity {
|
||||
val session = Robolectric.buildActivity(SessionActivity::class.java).get()
|
||||
ReflectionHelpers.setField(session, "loading", LoadingState(session).apply { visible = false })
|
||||
SessionState.phase = phase
|
||||
SessionState.stopRequested = true
|
||||
try {
|
||||
ReflectionHelpers.callInstanceMethod<Void>(session, "watchSession")
|
||||
shadowOf(Looper.getMainLooper()).idle()
|
||||
} finally {
|
||||
ReflectionHelpers.setField(session, "watching", false)
|
||||
shadowOf(Looper.getMainLooper()).idleFor(500, TimeUnit.MILLISECONDS)
|
||||
}
|
||||
return session
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
package com.droiddeck.launcher.audio
|
||||
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.junit.rules.TemporaryFolder
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
import org.robolectric.util.ReflectionHelpers
|
||||
import java.io.File
|
||||
import java.util.function.Consumer
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [28])
|
||||
class DirectAudioMicrophoneTest {
|
||||
@get:Rule val folder = TemporaryFolder()
|
||||
|
||||
@Test fun toggleOnlyChangesTheSessionCaptureControl() {
|
||||
val fifo = File(folder.root, "mic.fifo")
|
||||
val relay = DirectAudioRelayComponent(File(folder.root, "relay.sock"), fifo)
|
||||
val changes = mutableListOf<Boolean>()
|
||||
relay.onMicEnabled = Consumer { changes.add(it) }
|
||||
val control = File(folder.root, "mic-enabled")
|
||||
assertTrue(relay.setMicEnabled(false))
|
||||
assertEquals("0", control.readText())
|
||||
assertTrue(changes.isEmpty())
|
||||
log(relay, "DA-Relay: mic enabled=0")
|
||||
assertEquals(listOf(false), changes)
|
||||
assertTrue(relay.setMicEnabled(true))
|
||||
assertEquals("1", control.readText())
|
||||
log(relay, "DA-Relay: mic enabled=1")
|
||||
assertEquals(listOf(false, true), changes)
|
||||
assertFalse(fifo.exists())
|
||||
}
|
||||
|
||||
@Test fun sessionWithoutCaptureCannotEnableIt() {
|
||||
val relay = DirectAudioRelayComponent(File(folder.root, "relay.sock"), null)
|
||||
assertFalse(relay.setMicEnabled(true))
|
||||
assertFalse(File(folder.root, "mic-enabled").exists())
|
||||
}
|
||||
|
||||
@Test fun captureDemandDoesNotOverrideTheAcknowledgedToggle() {
|
||||
val relay = DirectAudioRelayComponent(File(folder.root, "relay.sock"), File(folder.root, "mic.fifo"))
|
||||
val changes = mutableListOf<Boolean>()
|
||||
relay.onMicEnabled = Consumer { changes.add(it) }
|
||||
log(relay, "DA-Relay: mic enabled=0")
|
||||
log(relay, "DA-Relay: mic start (game wants it, 1 consumer(s))")
|
||||
log(relay, "DA-Relay: mic stop (game)")
|
||||
assertEquals(listOf(false), changes)
|
||||
assertTrue(relay.awaitMicReleased(0))
|
||||
}
|
||||
|
||||
@Test fun controlWriteFailureStillStartsPlaybackWithCaptureDisabled() {
|
||||
val context = RuntimeEnvironment.getApplication()
|
||||
val info = context.applicationInfo
|
||||
val previous = info.nativeLibraryDir
|
||||
val nativeDir = folder.newFolder("native")
|
||||
val args = File(folder.root, "arguments")
|
||||
File(nativeDir, DirectAudioRelayComponent.BINARY).apply {
|
||||
writeText("#!/bin/sh\nprintf '%s\\n' \"\$@\" > '${args.path}.new'\nmv '${args.path}.new' '${args.path}'\n")
|
||||
setExecutable(true)
|
||||
}
|
||||
val fifo = folder.newFile("mic.fifo")
|
||||
File(folder.root, "mic-enabled.new").mkdir()
|
||||
val relay = DirectAudioRelayComponent(File(folder.root, "relay.sock"), fifo)
|
||||
relay.attach(context)
|
||||
try {
|
||||
info.nativeLibraryDir = nativeDir.path
|
||||
relay.start()
|
||||
val deadline = System.nanoTime() + 3_000_000_000L
|
||||
while (!args.isFile && System.nanoTime() < deadline) Thread.sleep(10)
|
||||
assertTrue("Playback helper did not start", args.isFile)
|
||||
val command = args.readLines()
|
||||
assertTrue(command.contains("--socket"))
|
||||
assertFalse(command.contains("--mic-fifo"))
|
||||
assertEquals(listOf("--mic-control", "/dev/null"), command.takeLast(2))
|
||||
} finally {
|
||||
info.nativeLibraryDir = previous
|
||||
}
|
||||
}
|
||||
|
||||
private fun log(relay: DirectAudioRelayComponent, line: String) =
|
||||
ReflectionHelpers.callInstanceMethod<Unit>(relay, "trackMic", ReflectionHelpers.ClassParameter.from(String::class.java, line))
|
||||
}
|
||||
@@ -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() {
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.droiddeck.launcher.frontend
|
||||
|
||||
import java.io.File
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.TemporaryFolder
|
||||
|
||||
class AddedGamesAccountTest {
|
||||
@get:Rule val tmp = TemporaryFolder()
|
||||
|
||||
private fun steamRoot(vararg blocks: Pair<Long, Map<String, String>>): File = tmp.newFolder("Steam").also { root ->
|
||||
File(root, "config").mkdirs()
|
||||
File(root, "userdata/123/config").mkdirs()
|
||||
File(root, "userdata/456/config").mkdirs()
|
||||
val body = blocks.joinToString("") { (account, keys) ->
|
||||
"\t\"${76561197960265728L + account}\"\n\t{\n" + keys.entries.joinToString("") { "\t\t\"${it.key}\"\t\t\"${it.value}\"\n" } + "\t}\n"
|
||||
}
|
||||
File(root, "config/loginusers.vdf").writeText("\"users\"\n{\n$body}\n")
|
||||
}
|
||||
|
||||
@Test fun theAccountMarkedMostRecentIsUsed() {
|
||||
val root = steamRoot(123L to mapOf("MostRecent" to "1", "AutoLogin" to "0", "timestamp" to "100"),
|
||||
456L to mapOf("MostRecent" to "0", "AutoLogin" to "1", "timestamp" to "200"))
|
||||
assertEquals(File(root, "userdata/123/config"), AddedGames.accountConfig(root))
|
||||
}
|
||||
|
||||
@Test fun withoutMostRecentTheAccountThatSignsInIsUsed() {
|
||||
val root = steamRoot(123L to mapOf("AutoLogin" to "1", "timestamp" to "100"), 456L to mapOf("AutoLogin" to "0", "timestamp" to "200"))
|
||||
assertEquals(File(root, "userdata/123/config"), AddedGames.accountConfig(root))
|
||||
}
|
||||
|
||||
@Test fun withoutEitherMarkTheAccountUsedLastIsUsed() {
|
||||
val root = steamRoot(456L to mapOf("AutoLogin" to "0", "timestamp" to "100"), 123L to mapOf("AutoLogin" to "0", "timestamp" to "200"))
|
||||
assertEquals(File(root, "userdata/123/config"), AddedGames.accountConfig(root))
|
||||
}
|
||||
|
||||
@Test fun twoAccountsWithoutAnyMarkGiveNoAccount() {
|
||||
val root = steamRoot(123L to mapOf("AccountName" to "a"), 456L to mapOf("AccountName" to "b"))
|
||||
assertNull(AddedGames.accountConfig(root))
|
||||
}
|
||||
}
|
||||
@@ -39,6 +39,28 @@ class GameLogoTest {
|
||||
assertNull(Library.steamCacheImage(cache, 730, Library.STEAM_LOGOS))
|
||||
}
|
||||
|
||||
@Test fun aSteamScanKeepsEveryArtworkSlotAndSeesNewHashDirectories() {
|
||||
val root = SessionPrefs.steamRoot(app, "arm64")
|
||||
File(root, "steamapps/appmanifest_620.acf").apply {
|
||||
parentFile!!.mkdirs()
|
||||
writeText("\"AppState\"\n{\n\"name\" \"Portal 2\"\n\"StateFlags\" \"4\"\n}\n")
|
||||
}
|
||||
val cache = File(root, "appcache/librarycache/620")
|
||||
fun cached(path: String) = File(cache, path).apply {
|
||||
parentFile!!.mkdirs()
|
||||
writeBytes(byteArrayOf(1))
|
||||
}
|
||||
val cover = cached("library_capsule.jpg")
|
||||
val hero = cached("hash/library_hero.jpg")
|
||||
val icon = cached("${"a".repeat(40)}.jpg")
|
||||
val game = Library.steamGames(app, arch = "arm64").single()
|
||||
assertEquals(listOf(cover, hero, icon, null), listOf(game.art, game.hero, game.icon, game.logo))
|
||||
|
||||
val logo = cached("new-hash/logo.png")
|
||||
val refreshed = Library.steamGames(app, arch = "arm64").single()
|
||||
assertEquals(listOf(cover, hero, icon, logo), listOf(refreshed.art, refreshed.hero, refreshed.icon, refreshed.logo))
|
||||
}
|
||||
|
||||
@Test fun aChosenLogoWinsOverSteamsAndKeepsTheRest() {
|
||||
val stock = image("logo.png")
|
||||
val game = Library.SteamGame(620, "Portal 2", null, "Steam library", logo = stock)
|
||||
|
||||
@@ -23,6 +23,20 @@ class LibraryArchTest {
|
||||
assertEquals(emptyList<String>(), Library.launchableGames(app, added = emptyList(), arch = "arm64").map { it.name })
|
||||
}
|
||||
|
||||
@Test fun aGameTheOtherClientSharesIsListedFromItsFiles() {
|
||||
SessionPrefs.setGameStorage(app, SessionPrefs.GAME_STORAGE_OFF, "")
|
||||
val apps = File(SessionPrefs.steamRoot(app, "x86_64"), "steamapps").apply { mkdirs() }
|
||||
File(apps, "common/Team Fortress 2").mkdirs()
|
||||
val manifest = "\"AppState\"\n{\n\t\"appid\"\t\t\"440\"\n\t\"name\"\t\t\"Team Fortress 2\"\n\t\"StateFlags\"\t\t\"4\"\n\t\"installdir\"\t\t\"Team Fortress 2\"\n}\n"
|
||||
File(apps, "appmanifest_440.acf").writeText(manifest)
|
||||
val view = File(com.droiddeck.launcher.runtime.LinuxRuntime.rootDir(app), "root/.droiddeck-x64/shared/x86-64/steamapps").apply { mkdirs() }
|
||||
File(view, "appmanifest_440.acf").writeText(manifest)
|
||||
val shared = Library.steamGames(app, arch = "arm64").single()
|
||||
assertEquals("Team Fortress 2", shared.name)
|
||||
assertEquals(File(apps, "common/Team Fortress 2"), shared.gameFiles)
|
||||
assertEquals(listOf("Team Fortress 2"), Library.steamGames(app, arch = "x86_64").map { it.name })
|
||||
}
|
||||
|
||||
@Test fun anAddedGameSteamAlreadyListsFromItsFolderIsShownOnce() {
|
||||
SessionPrefs.setGameStorage(app, SessionPrefs.GAME_STORAGE_OFF, "")
|
||||
val folder = File(app.filesDir, "games/Example").apply { mkdirs() }
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
package com.droiddeck.launcher.frontend
|
||||
|
||||
import android.os.Looper
|
||||
import com.droiddeck.launcher.FrontEndActivity
|
||||
import com.droiddeck.launcher.runtime.LinuxRuntime
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
import com.droiddeck.launcher.session.SessionService
|
||||
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 org.junit.runner.RunWith
|
||||
import org.robolectric.Robolectric
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.Shadows.shadowOf
|
||||
import org.robolectric.annotation.Config
|
||||
import org.robolectric.annotation.LooperMode
|
||||
import java.io.File
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [28])
|
||||
@LooperMode(LooperMode.Mode.PAUSED)
|
||||
class ModeSettingsLoadingTest {
|
||||
@Test fun steamPublishesItsShaderChoiceThroughTheMainQueue() {
|
||||
val activity = Robolectric.buildActivity(FrontEndActivity::class.java).get()
|
||||
SessionPrefs.setShaderPrecache(activity, false)
|
||||
load(activity, SessionService.MODE_STEAM)
|
||||
awaitRead()
|
||||
assertNull(value(activity))
|
||||
shadowOf(Looper.getMainLooper()).idle()
|
||||
assertEquals(false, value(activity))
|
||||
}
|
||||
|
||||
@Test fun desktopDoesNotConsumeSteamsAppliedShaderChoice() {
|
||||
val activity = Robolectric.buildActivity(FrontEndActivity::class.java).get()
|
||||
SessionPrefs.setShaderPrecache(activity, false)
|
||||
val applied = File(LinuxRuntime.rootDir(activity), "root/.bl-shader-precache-applied")
|
||||
applied.parentFile!!.mkdirs()
|
||||
applied.writeText("0")
|
||||
load(activity, SessionService.MODE_DESKTOP)
|
||||
awaitRead()
|
||||
shadowOf(Looper.getMainLooper()).idle()
|
||||
assertTrue(applied.isFile)
|
||||
assertNull(value(activity))
|
||||
}
|
||||
|
||||
@Test fun switchingToDesktopDiscardsAQueuedSteamResult() {
|
||||
val activity = Robolectric.buildActivity(FrontEndActivity::class.java).get()
|
||||
load(activity, SessionService.MODE_STEAM)
|
||||
awaitRead()
|
||||
load(activity, SessionService.MODE_DESKTOP)
|
||||
shadowOf(Looper.getMainLooper()).idle()
|
||||
assertNull(value(activity))
|
||||
}
|
||||
|
||||
private fun load(activity: FrontEndActivity, mode: String) {
|
||||
FrontEndActivity::class.java.getDeclaredMethod("loadShaderPrecache", String::class.java)
|
||||
.apply { isAccessible = true }.invoke(activity, mode)
|
||||
}
|
||||
|
||||
private fun value(activity: FrontEndActivity): Boolean? =
|
||||
FrontEndActivity::class.java.getDeclaredMethod("getShaderPrecache")
|
||||
.apply { isAccessible = true }.invoke(activity) as Boolean?
|
||||
|
||||
private fun awaitRead() {
|
||||
Thread.getAllStackTraces().keys.filter { it.name == "shader-precache" }.forEach {
|
||||
it.join(5_000)
|
||||
assertFalse("Shader settings read did not finish", it.isAlive)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
package com.droiddeck.launcher.frontend
|
||||
|
||||
import java.io.File
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.TemporaryFolder
|
||||
|
||||
class SteamCacheImagesTest {
|
||||
@get:Rule val tmp = TemporaryFolder()
|
||||
|
||||
private fun image(path: String, bytes: ByteArray = byteArrayOf(1)): File =
|
||||
File(tmp.root, path).apply { parentFile!!.mkdirs(); writeBytes(bytes) }
|
||||
|
||||
private class CountingDirectory(directory: File) : File(directory.path) {
|
||||
var listings = 0
|
||||
private set
|
||||
|
||||
override fun listFiles(): Array<File>? {
|
||||
listings++
|
||||
return super.listFiles()?.sortedByDescending { it.name }?.toTypedArray()
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun allArtworkAndTheHashIconShareOneDirectoryListing() {
|
||||
val cover = image("620/library_capsule.jpg")
|
||||
val hero = image("620/b/library_hero.jpg")
|
||||
val logo = image("620/a/logo.png")
|
||||
val icon = image("620/${"a".repeat(40)}.png")
|
||||
val directory = CountingDirectory(File(tmp.root, "620"))
|
||||
val images = Library.SteamCacheImages(directory)
|
||||
|
||||
assertEquals(cover, images.find(listOf("library_capsule.jpg", "library_600x900.jpg")))
|
||||
assertEquals(hero, images.find(listOf("library_hero.jpg")))
|
||||
assertEquals(logo, images.find(Library.STEAM_LOGOS))
|
||||
assertEquals(icon, images.icon())
|
||||
assertEquals(1, directory.listings)
|
||||
}
|
||||
|
||||
@Test fun preferredFilenamesWinEvenWhenOnlyTheAlternativeIsInTheRoot() {
|
||||
image("620/library_600x900.jpg")
|
||||
val preferred = image("620/hash/library_capsule.jpg")
|
||||
|
||||
assertEquals(preferred, Library.steamCacheImage(
|
||||
tmp.root, 620, listOf("library_capsule.jpg", "library_600x900.jpg"),
|
||||
))
|
||||
}
|
||||
|
||||
@Test fun theRootWinsOverHashDirectoriesForTheSameFilename() {
|
||||
image("620/hash/logo.png")
|
||||
val root = image("620/logo.png")
|
||||
|
||||
assertEquals(root, Library.steamCacheImage(tmp.root, 620, Library.STEAM_LOGOS))
|
||||
}
|
||||
|
||||
@Test fun hashDirectoriesAreSearchedByNameNotListingOrder() {
|
||||
image("620/z/logo.png")
|
||||
val first = image("620/a/logo.png")
|
||||
val directory = CountingDirectory(File(tmp.root, "620"))
|
||||
|
||||
assertEquals(first, Library.SteamCacheImages(directory).find(Library.STEAM_LOGOS))
|
||||
assertEquals(1, directory.listings)
|
||||
}
|
||||
|
||||
@Test fun emptyFilesAndDirectoriesAreNotArtwork() {
|
||||
image("620/logo.png", byteArrayOf())
|
||||
File(tmp.root, "620/a/logo.png").mkdirs()
|
||||
val valid = image("620/b/logo.png")
|
||||
|
||||
assertEquals(valid, Library.steamCacheImage(tmp.root, 620, Library.STEAM_LOGOS))
|
||||
}
|
||||
|
||||
@Test fun namedIconsKeepTheirFilenamePriorityOverHashIcons() {
|
||||
image("620/${"a".repeat(40)}.png")
|
||||
image("620/icon.png")
|
||||
val preferred = image("620/hash/icon.jpg")
|
||||
|
||||
assertEquals(preferred, Library.SteamCacheImages(File(tmp.root, "620")).icon())
|
||||
}
|
||||
|
||||
@Test fun hashIconsKeepTheOriginalRootListingOrderAndAllowEmptyFiles() {
|
||||
image("620/${"0".repeat(40)}.jpg")
|
||||
val first = image("620/${"F".repeat(40)}.png", byteArrayOf())
|
||||
File(tmp.root, "620/${"z".repeat(40)}.png").mkdirs()
|
||||
image("620/${"g".repeat(40)}.png")
|
||||
val directory = CountingDirectory(File(tmp.root, "620"))
|
||||
val images = Library.SteamCacheImages(directory)
|
||||
|
||||
assertEquals(first, images.icon())
|
||||
assertEquals(1, directory.listings)
|
||||
}
|
||||
|
||||
@Test fun hashIconsOutsideTheRootAndInvalidHashesAreIgnored() {
|
||||
image("620/hash/${"a".repeat(40)}.jpg")
|
||||
image("620/${"g".repeat(40)}.png")
|
||||
image("620/${"a".repeat(39)}.png")
|
||||
|
||||
assertNull(Library.SteamCacheImages(File(tmp.root, "620")).icon())
|
||||
}
|
||||
|
||||
@Test fun missingDirectoriesAreListedOnlyOnce() {
|
||||
val directory = CountingDirectory(File(tmp.root, "missing"))
|
||||
val images = Library.SteamCacheImages(directory)
|
||||
|
||||
assertNull(images.find(Library.STEAM_LOGOS))
|
||||
assertNull(images.icon())
|
||||
assertEquals(1, directory.listings)
|
||||
}
|
||||
|
||||
@Test fun aNewLookupSeesHashDirectoriesAddedAfterThePreviousScan() {
|
||||
image("620/unrelated.txt")
|
||||
assertNull(Library.steamCacheImage(tmp.root, 620, Library.STEAM_LOGOS))
|
||||
val added = image("620/new-hash/logo.png")
|
||||
|
||||
assertEquals(added, Library.steamCacheImage(tmp.root, 620, Library.STEAM_LOGOS))
|
||||
}
|
||||
}
|
||||
@@ -56,6 +56,17 @@ class WinCompSourcesTest {
|
||||
assertEquals(emptyList<String>(), WinCompSources.epic("Installers/LauncherHelper.exe", "Launcher Helper"))
|
||||
}
|
||||
|
||||
@Test fun xboxGamesAlwaysGetVisualCppAndTheirDeclaredRuntimes() {
|
||||
val folder = tmp.newFolder("xbox")
|
||||
val vc = listOf("vcredist2022" to "VC14", "vcredist2022_arm64" to "VC14")
|
||||
assertEquals(vc, WinCompSources.xbox(folder))
|
||||
File(folder, "MicrosoftGame.Config").writeText("""<Game><DesktopRegistration><DependencyList><KnownDependency Name="VC14"/></DependencyList></DesktopRegistration></Game>""")
|
||||
assertEquals(vc, WinCompSources.xbox(folder))
|
||||
sidecar(folder, Store.XBOX, emptyMap())
|
||||
assertEquals(listOf("vcredist2022" to WinCompSources.Origin.XBOX, "vcredist2022_arm64" to WinCompSources.Origin.XBOX),
|
||||
auto(WinCompSources.forGame(app, game(folder, Store.XBOX.id))).distinct())
|
||||
}
|
||||
|
||||
@Test fun steamworksSharedDepotsMapToComponents() {
|
||||
assertEquals(listOf("vcredist2015_dll" to "VC++ 2015", "d3dx9" to "DirectX (June 2010)"), WinCompSources.steamDepots(listOf("228986", "228990", "999")))
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
@@ -178,17 +178,39 @@ class BootMovieLibraryTest {
|
||||
assertNull(SessionFiles.startupMoviePath(BootMovieLibrary.steamConfig(app)))
|
||||
}
|
||||
|
||||
@Test fun onlyTheThreeStartupMoviesOfSteamAreListed() {
|
||||
listOf("deck_startup", "oled_startup", "startup_machine", "controller_generic_thumbstick_move").forEach {
|
||||
@Test fun onlyTheStartupMoviesOfSteamAreListed() {
|
||||
listOf("deck_startup", "oled_startup", "startup_machine", "steam_os_startup", "controller_generic_thumbstick_move").forEach {
|
||||
File(BootMovieLibrary.steamRoot(app), "steamui/movies/$it.webm").also { f -> f.parentFile!!.mkdirs(); f.writeText("movie") }
|
||||
}
|
||||
val ids = BootMovieLibrary.list(app).map { it.id }.filter { it.startsWith("steam:") }
|
||||
assertEquals(
|
||||
listOf("steam:/movies/deck_startup.webm", "steam:/movies/oled_startup.webm", "steam:/movies/startup_machine.webm"),
|
||||
listOf(
|
||||
"steam:/movies/deck_startup.webm", "steam:/movies/oled_startup.webm", "steam:/movies/startup_machine.webm",
|
||||
"steam:/movies/steam_os_startup.webm",
|
||||
),
|
||||
ids.sorted(),
|
||||
)
|
||||
}
|
||||
|
||||
@Test fun steamsDefaultPickIsTakenOverAsItsOwnStartupMovie() {
|
||||
val native = File(BootMovieLibrary.steamRoot(app), "steamui/movies/steam_os_startup.webm").also { it.parentFile!!.mkdirs(); it.writeText("movie") }
|
||||
movie("a.webm")
|
||||
steamPicksAt(SessionFiles.BOOT_MOVIE_PATH)
|
||||
BootMovie.select(app, "file:a.webm")
|
||||
steamPicksAt("")
|
||||
assertTrue(BootMovie.syncFromSteam(app))
|
||||
assertEquals("steam:/movies/steam_os_startup.webm", BootMovie.choice(app))
|
||||
assertEquals(native, BootMovie.currentFile(app))
|
||||
assertFalse(BootMovie.syncFromSteam(app))
|
||||
}
|
||||
|
||||
@Test fun anEmptySteamPickThatWasNeverSeenChangesNothing() {
|
||||
File(BootMovieLibrary.steamRoot(app), "steamui/movies/steam_os_startup.webm").also { it.parentFile!!.mkdirs(); it.writeText("movie") }
|
||||
steamPicksAt("")
|
||||
assertFalse(BootMovie.syncFromSteam(app))
|
||||
assertEquals(BootMovie.DROIDDECK_30, BootMovie.choice(app))
|
||||
}
|
||||
|
||||
@Test fun aMovieBoughtInThePointsShopIsListedAndAdopted() {
|
||||
val file = File(BootMovieLibrary.steamRoot(app), "appcache/startupmovies/Bought.webm").also { it.parentFile!!.mkdirs(); it.writeText("movie") }
|
||||
val entry = BootMovieLibrary.list(app).first { it.id == "steam:/appcache/startupmovies/Bought.webm" }
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Test
|
||||
|
||||
class LoadingStateTest {
|
||||
@Test fun clientDownloadCountsMegabytesWhenTheRuntimeSaysThem() {
|
||||
assertEquals(
|
||||
"45 / 360 MB" to 12,
|
||||
LoadingState.clientDownload("== STEP 17:38:20 downloading Steam: bins_linuxarm64_linuxarm64 (2/17), 45 of 360 MB"),
|
||||
)
|
||||
}
|
||||
|
||||
@Test fun aStalledDownloadStillShowsWhereItIs() {
|
||||
assertEquals(
|
||||
"45 / 360 MB" to 12,
|
||||
LoadingState.clientDownload(
|
||||
"== STEP 17:39:20 downloading Steam: bins_linuxarm64_linuxarm64 (2/17), 45 of 360 MB" +
|
||||
" - interrupted (curl exit 28), trying again in 5 s",
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
@Test fun anOlderRuntimeShowsThePartAndItsNumber() {
|
||||
assertEquals(
|
||||
"bins_linuxarm64_linuxarm64" to 11,
|
||||
LoadingState.clientDownload("== STEP 17:38:17 downloading Steam: bins_linuxarm64_linuxarm64 (2/17)"),
|
||||
)
|
||||
assertEquals("a_all" to 50, LoadingState.clientDownload("== STEP 00:00:00 downloading Steam: a_all (1/2), 0 of 0 MB"))
|
||||
}
|
||||
|
||||
@Test fun otherStepsAreNotClientDownloads() {
|
||||
assertNull(LoadingState.clientDownload("== STEP 17:38:14 checking the Steam client (a first run downloads it)"))
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
@@ -171,4 +171,31 @@ class ProtonExtrasTest {
|
||||
assertEquals(listOf("DroidDeck-Proton 11-7.10"), ProtonExtras.installedAll(context, tool("droiddeck")))
|
||||
assertEquals("DroidDeck-Proton 11-7.10", ProtonExtras.installed(context, tool("droiddeck")))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun removingABuildDropsItsStoredOriginalsAndSelections() {
|
||||
val context = RuntimeEnvironment.getApplication()
|
||||
val tools = File(LinuxRuntime.rootDir(context), "root/.local/share/Steam/compatibilitytools.d")
|
||||
File(LinuxRuntime.rootDir(context), "root/.local/share/droiddeck-components").mkdirs()
|
||||
installTool(tools, "GE-Proton11-7")
|
||||
val kept = installTool(tools, "GE-Proton11-8").apply {
|
||||
File(this, "files/lib/wine").mkdirs()
|
||||
File(this, "proton").writeText("")
|
||||
}
|
||||
val originals = File(context.filesDir, "components/originals")
|
||||
for (id in listOf("GE-Proton11-7", "GE-Proton11-8")) File(originals, "$id/$id/dxvk.wcp").apply { parentFile?.mkdirs(); writeText("x") }
|
||||
val pick = JSONObject().put("dxvk", JSONObject().put("file", "dxvk.wcp").put("protonVersion", "GE-Proton11-7"))
|
||||
File(context.filesDir, "components/state.json").writeText(JSONObject()
|
||||
.put("active", JSONObject().put("GE-Proton11-7", pick).put("GE-Proton11-8", pick))
|
||||
.put("queued", JSONObject().put("GE-Proton11-7", pick)).toString())
|
||||
ProtonExtras.remove(context, tool("ge"), "GE-Proton11-7")
|
||||
assertFalse(File(originals, "GE-Proton11-7").exists())
|
||||
assertTrue(File(originals, "GE-Proton11-8/GE-Proton11-8/dxvk.wcp").isFile)
|
||||
val state = JSONObject(File(context.filesDir, "components/state.json").readText())
|
||||
assertFalse(state.getJSONObject("active").has("GE-Proton11-7"))
|
||||
assertFalse(state.getJSONObject("queued").has("GE-Proton11-7"))
|
||||
assertTrue(state.getJSONObject("active").has("GE-Proton11-8"))
|
||||
ComponentsManager.forgetProton(context, kept.name)
|
||||
assertTrue(File(originals, "GE-Proton11-8/GE-Proton11-8/dxvk.wcp").isFile)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.TemporaryFolder
|
||||
import java.io.File
|
||||
|
||||
class SessionSteamLogsTest {
|
||||
@get:Rule val tmp = TemporaryFolder()
|
||||
|
||||
private fun names(files: List<File>) = files.map { it.name }.sorted()
|
||||
|
||||
@Test fun onlyWhatTheSessionWroteIsCollected() {
|
||||
val logs = tmp.newFolder("logs")
|
||||
val session = tmp.newFolder("session")
|
||||
val out = tmp.newFolder("out")
|
||||
File(logs, "console_log.txt").writeText("old line\n")
|
||||
File(logs, "cef_log.txt").writeText("old cef\n")
|
||||
File(logs, "cef_log.previous.txt").writeText("older cef\n")
|
||||
File(logs, "shrunk.txt").writeText("a long old line\n")
|
||||
File(logs, "untouched.txt").writeText("nothing new\n")
|
||||
SessionArtifacts.markSteamLogs(session, logs)
|
||||
|
||||
File(logs, "console_log.txt").appendText("new line\n")
|
||||
File(logs, "cef_log.previous.txt").delete()
|
||||
File(logs, "cef_log.txt").renameTo(File(logs, "cef_log.previous.txt"))
|
||||
File(logs, "cef_log.txt").writeText("this session's cef\n")
|
||||
File(logs, "shrunk.txt").writeText("short\n")
|
||||
File(logs, "content_log.txt").writeText("created this session\n")
|
||||
|
||||
val copied = SessionArtifacts.copySessionLogs(logs, session, out)
|
||||
assertEquals(listOf("cef_log.txt", "console_log.txt", "content_log.txt", "shrunk.txt"), names(copied))
|
||||
assertEquals("new line\n", File(out, "console_log.txt").readText())
|
||||
assertEquals("this session's cef\n", File(out, "cef_log.txt").readText())
|
||||
assertEquals("short\n", File(out, "shrunk.txt").readText())
|
||||
assertFalse(File(out, "cef_log.previous.txt").exists())
|
||||
assertFalse(File(out, "untouched.txt").exists())
|
||||
}
|
||||
|
||||
@Test fun aLineCutByTheMarkIsLeftOut() {
|
||||
val logs = tmp.newFolder("logs")
|
||||
val session = tmp.newFolder("session")
|
||||
val out = tmp.newFolder("out")
|
||||
File(logs, "web.txt").writeText("old\nGET /x?sessionid=")
|
||||
SessionArtifacts.markSteamLogs(session, logs)
|
||||
File(logs, "web.txt").appendText("abcdef123456 200\nnext line\n")
|
||||
SessionArtifacts.copySessionLogs(logs, session, out)
|
||||
assertEquals("next line\n", File(out, "web.txt").readText())
|
||||
}
|
||||
|
||||
@Test fun withoutMarksEveryLogUnderTheCapIsCollectedAndRedacted() {
|
||||
val logs = tmp.newFolder("logs")
|
||||
val out = tmp.newFolder("out")
|
||||
File(logs, "web.txt").writeText("GET /x?sessionid=abcdef123456 200\n")
|
||||
File(logs, "big.txt").outputStream().use { it.write(ByteArray(8 * 1024 * 1024)) }
|
||||
val copied = SessionArtifacts.copySessionLogs(logs, tmp.newFolder("session"), out)
|
||||
assertEquals(listOf("web.txt"), names(copied))
|
||||
assertFalse(File(out, "web.txt").readText().contains("abcdef123456"))
|
||||
}
|
||||
}
|
||||
@@ -101,6 +101,28 @@ class SteamDownloadMonitorTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun aLongLogIsFollowedFromWhereTheLastPollStopped() {
|
||||
val root = Files.createTempDirectory("droiddeck-steam-download-").toFile()
|
||||
try {
|
||||
val contentLog = File(root, "root/.local/share/Steam/logs/content_log.txt").apply {
|
||||
check(parentFile?.mkdirs() != false)
|
||||
writeText(buildString {
|
||||
repeat(5_000) { append("[2026-10-06 14:40:00] Detected write gap 64 MB in file \"data_$it.dat\"\r\n") }
|
||||
append("[2026-10-06 14:44:17] AppID 44 App update changed : Running Update,Downloading,\r\n")
|
||||
})
|
||||
}
|
||||
val monitor = SteamDownloadMonitor()
|
||||
|
||||
assertTrue(monitor.poll(root, now = 1_000L))
|
||||
contentLog.appendText("[2026-10-06 14:45:03] AppID 44 App update changed : None\r\n")
|
||||
assertFalse(monitor.poll(root, now = 2_000L))
|
||||
contentLog.appendText("[2026-10-06 14:46:00] AppID 45 App update changed : Running Update,Downloading,\r\n")
|
||||
assertTrue(monitor.poll(root, now = 3_000L))
|
||||
} finally {
|
||||
root.deleteRecursively()
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun theOtherClientsLogIsReadFromItsStart() {
|
||||
val root = Files.createTempDirectory("droiddeck-steam-download-").toFile()
|
||||
try {
|
||||
@@ -203,6 +225,38 @@ class SteamDownloadMonitorTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun theClientIsPendingUntilItIsInstalledAndStamped() {
|
||||
val root = Files.createTempDirectory("droiddeck-steam-client-").toFile()
|
||||
try {
|
||||
val steam = File(root, "root/.local/share/Steam")
|
||||
assertTrue(SteamDownloadMonitor.clientInstallPending(root))
|
||||
File(steam, "steamrtarm64").mkdirs()
|
||||
File(steam, "steamrtarm64/steam").writeText("client")
|
||||
assertTrue(SteamDownloadMonitor.clientInstallPending(root))
|
||||
File(steam, "package").mkdirs()
|
||||
File(steam, "package/droiddeck-installed").writeText("1791686101\n")
|
||||
assertFalse(SteamDownloadMonitor.clientInstallPending(root))
|
||||
} finally {
|
||||
root.deleteRecursively()
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun anOlderStampCountsAndARepairRequestIsPending() {
|
||||
val root = Files.createTempDirectory("droiddeck-steam-client-").toFile()
|
||||
try {
|
||||
val steam = File(root, "root/.local/share/Steam")
|
||||
File(steam, "steamrtarm64").mkdirs()
|
||||
File(steam, "steamrtarm64/steam").writeText("client")
|
||||
File(steam, "package").mkdirs()
|
||||
File(steam, "package/bannerlator-installed").writeText("1\n")
|
||||
assertFalse(SteamDownloadMonitor.clientInstallPending(root))
|
||||
File(root, "root/.bl-steam-repair").writeText("1\n")
|
||||
assertTrue(SteamDownloadMonitor.clientInstallPending(root))
|
||||
} finally {
|
||||
root.deleteRecursively()
|
||||
}
|
||||
}
|
||||
|
||||
private fun manifest(root: File, appId: String, downloaded: Long, total: Long, flags: Int): File {
|
||||
val file = File(root, "steamapps/appmanifest_$appId.acf")
|
||||
check(file.parentFile?.mkdirs() != false)
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
}
|
||||
@@ -31,6 +31,14 @@ class WinComponentsSupportTest {
|
||||
step("install_msi", "url" to "$base/ps-x86.msi"), step("install_msi", "url" to "$base/ps-x64.msi"))))
|
||||
}
|
||||
|
||||
@Test fun builtInArm64RuntimeIsRegistryOnlyInBothViews() {
|
||||
val c = WinComponents.builtInArm64Runtime()
|
||||
assertEquals(Support.READY, support(c))
|
||||
assertEquals(12, c.steps.count { it.action == "set_register_key" })
|
||||
assertEquals(setOf("HKLM\\Software\\Microsoft\\VisualStudio\\14.0\\VC\\Runtimes\\arm64",
|
||||
"HKLM\\Software\\Wow6432Node\\Microsoft\\VisualStudio\\14.0\\VC\\Runtimes\\arm64"), c.steps.map { it.str("key") }.toSet())
|
||||
}
|
||||
|
||||
@Test fun installerWrappersInstallHere() {
|
||||
assertEquals(Support.READY, support(component("vcredist2022",
|
||||
step("install_exe", "url" to "$base/vcredist2022__VC_redist.x86.exe", "file_name" to "VC_redist.x86.exe"),
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -7,6 +7,13 @@ class SortCatalogItemsTest {
|
||||
private fun item(id: String, title: String, size: Long = 0, releaseDate: String = "") =
|
||||
CatalogItem(Store.GOG, id, title, imageUrl = null, sizeBytes = size, releaseDate = releaseDate, owned = true)
|
||||
|
||||
private fun sortCatalogItems(
|
||||
items: List<CatalogItem>, sort: String,
|
||||
lastPlayed: (CatalogItem) -> Long = { 0L }, installedAt: (CatalogItem) -> Long = { 0L },
|
||||
) = sortGames(items, sort, { it.title }, { it.releaseDate }, lastPlayed, installedAt, { it.sizeBytes })
|
||||
|
||||
private fun retainCatalogOrder(items: List<CatalogItem>, previous: List<CatalogItem>) = retainOrder(items, previous) { it.key }
|
||||
|
||||
@Test fun titleOrderIsCaseInsensitiveAndDescendingIsItsMirror() {
|
||||
val items = listOf(item("1", "Zelda"), item("2", "alpha"), item("3", "Beta"))
|
||||
assertEquals(listOf("alpha", "Beta", "Zelda"), sortCatalogItems(items, "titleAsc").map { it.title })
|
||||
|
||||
@@ -201,4 +201,20 @@ class StoreAccountsCipherTest {
|
||||
assertFalse(StoreAccounts.isUnavailable(Store.AMAZON))
|
||||
assertFalse(file(Store.AMAZON).exists())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun teeEnvelopesUseTheCurrentKeyAndOlderOnesTheLegacyKey() {
|
||||
val legacy = SecretKeySpec(ByteArray(32) { 7 }, "AES")
|
||||
val keys = object : CredentialCipher.KeyProvider {
|
||||
override fun key(): SecretKey = key
|
||||
override fun legacy(): SecretKey = legacy
|
||||
override val version: Int get() = CredentialCipher.VERSION_TEE
|
||||
}
|
||||
val old = CredentialCipher.seal("old", CredentialCipher.KeyProvider { legacy })
|
||||
assertEquals(CredentialCipher.VERSION, old.getInt("v"))
|
||||
assertEquals("old", CredentialCipher.open(old, keys))
|
||||
val new = CredentialCipher.seal("new", keys)
|
||||
assertEquals(CredentialCipher.VERSION_TEE, new.getInt("v"))
|
||||
assertEquals("new", CredentialCipher.open(new, keys))
|
||||
}
|
||||
}
|
||||
@@ -38,6 +38,43 @@ class StoreInstallRootTest {
|
||||
assertEquals(1, StoreInstallRoot.targets(app).size)
|
||||
}
|
||||
|
||||
@Test fun externalStoreInstallPathsMapIntoTheirGuestMountWithoutPrefixCollisions() {
|
||||
val cardRoot = File(app.filesDir, "card/Games").apply { mkdirs() }
|
||||
val guestRoot = "/mnt/droiddeck-stores/card"
|
||||
val roots = listOf(cardRoot to guestRoot)
|
||||
|
||||
assertEquals("$guestRoot/Stores/Xbox/Doom", StoreInstallRoot.externalGuestPath(
|
||||
File(cardRoot, "Stores/Xbox/Doom"), roots))
|
||||
assertEquals(null, StoreInstallRoot.externalGuestPath(
|
||||
File(cardRoot.parentFile, "Games-old/Stores/Xbox/Doom"), roots))
|
||||
}
|
||||
|
||||
@Test fun xodusMapsTheSelectedSteamLibraryOnAnExternalVolume() {
|
||||
val library = File(app.filesDir, "card/steam").apply { mkdirs() }
|
||||
val storeRoot = File(library, "Games").apply { mkdirs() }
|
||||
SessionPrefs.setGameStorage(app, library.path, "Card")
|
||||
|
||||
val xodusRoot = StoreInstallRoot.externalRootsForXodus(app).single { it.first.absolutePath == storeRoot.absolutePath }
|
||||
val gameFolder = File(storeRoot, "Xbox/Doom")
|
||||
assertEquals("${xodusRoot.second}/Xbox/Doom", StoreInstallRoot.guestPathForXodus(app, gameFolder))
|
||||
|
||||
val bindSpecs = StoreInstallRoot.externalBindSpecsForXodus(app)
|
||||
assertTrue(bindSpecs.contains("${storeRoot.path}:${xodusRoot.second}"))
|
||||
assertTrue(File(LinuxRuntime.rootDir(app), xodusRoot.second.removePrefix("/")).isDirectory)
|
||||
}
|
||||
|
||||
@Test fun externalStoreBindsCreateGuestTargetsAndSkipUnavailableVolumes() {
|
||||
val host = File(app.filesDir, "card/Games").apply { mkdirs() }
|
||||
val guestRoot = "/mnt/droiddeck-stores/card"
|
||||
val guestFs = File(app.filesDir, "linuxfs").apply { mkdirs() }
|
||||
val missing = File(app.filesDir, "missing/Games")
|
||||
|
||||
assertEquals(listOf("${host.path}:$guestRoot"), StoreInstallRoot.externalBindSpecs(
|
||||
listOf(host to guestRoot, missing to "/mnt/droiddeck-stores/missing"), guestFs))
|
||||
assertTrue(File(guestFs, "mnt/droiddeck-stores/card").isDirectory)
|
||||
assertFalse(File(guestFs, "mnt/droiddeck-stores/missing").exists())
|
||||
}
|
||||
|
||||
@Test fun anExistingInstallWinsOverAFreshFolderUnderTheChosenRoot() {
|
||||
SessionPrefs.setGameStorage(app, SessionPrefs.GAME_STORAGE_OFF, "")
|
||||
val existing = File(StoreInstallRoot.storeDir(StoreInstallRoot.internalRoot(app), Store.GOG), "Old Name").apply { mkdirs() }
|
||||
|
||||
@@ -16,17 +16,6 @@ import java.security.MessageDigest
|
||||
class EpicClientTest {
|
||||
@get:Rule val tmp = TemporaryFolder()
|
||||
|
||||
private fun game(appId: Int, source: String) =
|
||||
com.droiddeck.launcher.frontend.Library.SteamGame(appId, "g$appId", null, "internal", source = source)
|
||||
|
||||
@Test fun theLauncherSitsRightAboveTheFirstEpicGame() {
|
||||
val launcher = game(EpicClient.LAUNCHER_APP_ID, "epic")
|
||||
val games = listOf(game(1, "steam"), game(2, "epic"), game(3, "steam"), game(4, "epic"))
|
||||
assertEquals(listOf(1, 0, 2, 3, 4), EpicClient.withLauncher(games, launcher).map { it.appId })
|
||||
assertEquals(listOf(1, 3, 0), EpicClient.withLauncher(listOf(games[0], games[2]), launcher).map { it.appId })
|
||||
assertEquals(listOf(1, 2), EpicClient.withLauncher(games.take(2), null).map { it.appId })
|
||||
}
|
||||
|
||||
private fun added(name: String, source: String, storeId: String?) =
|
||||
com.droiddeck.launcher.frontend.AddedGames.Game(File(tmp.root, name), name, File(tmp.root, "$name/$name.exe"),
|
||||
"/root/Games/$name/$name.exe", "/root/Games/$name", 3_000_000_000L, 0L, emptyList(), source = source, storeId = storeId)
|
||||
@@ -285,6 +274,28 @@ class EpicClientTest {
|
||||
assertTrue(EpicClient.loopback("http://localhost:5/launcher/authorized?code=1"))
|
||||
}
|
||||
|
||||
@Test fun theManifestLaunchCommandJoinsTheGameArguments() {
|
||||
val store = com.droiddeck.launcher.stores.Store.EPIC
|
||||
val epicArgs = listOf("-EpicPortal", "-epicapp=Fig", "-epicenv=Prod")
|
||||
val installed = com.droiddeck.launcher.stores.StoreGameSidecar(store, "Fig", "Fig Game", exe = "Fig.exe", args = epicArgs)
|
||||
val first = EpicClientLibrary.withLaunchArgs(installed, listOf("-PCStore=EGS"))
|
||||
assertEquals(epicArgs + "-PCStore=EGS", first.args)
|
||||
assertTrue(EpicClientLibrary.withLaunchArgs(first, listOf("-PCStore=EGS")) === first)
|
||||
val updated = EpicClientLibrary.withLaunchArgs(first, listOf("-PCStore=EGS", "-log=a b.txt"))
|
||||
assertEquals(epicArgs + listOf("-PCStore=EGS", "-log=a b.txt"), updated.args)
|
||||
val dropped = EpicClientLibrary.withLaunchArgs(updated, emptyList())
|
||||
assertEquals(epicArgs, dropped.args)
|
||||
assertFalse(dropped.extra.containsKey("launchArgs"))
|
||||
val reinstalled = first.copy(args = epicArgs)
|
||||
assertEquals(epicArgs + "-PCStore=EGS", EpicClientLibrary.withLaunchArgs(reinstalled, listOf("-PCStore=EGS")).args)
|
||||
assertTrue(EpicClientLibrary.withLaunchArgs(installed, emptyList()) === installed)
|
||||
val own = installed.copy(args = epicArgs + "-PCStore=EGS")
|
||||
assertTrue(EpicClientLibrary.withLaunchArgs(own, listOf("-PCStore=EGS")) === own)
|
||||
val ownUpdated = EpicClientLibrary.withLaunchArgs(own, listOf("-PCStore=EGS", "-log=a b.txt"))
|
||||
assertEquals(epicArgs + listOf("-PCStore=EGS", "-log=a b.txt"), ownUpdated.args)
|
||||
assertEquals(epicArgs + "-PCStore=EGS", EpicClientLibrary.withLaunchArgs(ownUpdated, emptyList()).args)
|
||||
}
|
||||
|
||||
@Test fun itemsDescribeTheInstallForTheLauncher() {
|
||||
val install = EpicClientLibrary.Install(
|
||||
"Fig", "ns1", "item1", "Fig Game", "1.0.5", "Binaries/Win64/Fig.exe", "/root/Games/Stores/Epic/Fig Game",
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
package com.droiddeck.launcher.stores.itch
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
class ItchBrowseTest {
|
||||
private fun path(sort: String = ItchBrowse.SORT_POPULAR, price: String = ItchBrowse.PRICE_ANY, platforms: Set<String> = emptySet(), tags: List<String> = emptyList()) =
|
||||
ItchBrowse.path(BrowseQuery(sort, price, platforms, tags))
|
||||
|
||||
@Test fun theDefaultQueryIsTheFrontPage() {
|
||||
assertTrue(BrowseQuery().isDefault)
|
||||
assertFalse(BrowseQuery(sort = ItchBrowse.SORT_NEWEST).isDefault)
|
||||
assertFalse(BrowseQuery(price = ItchBrowse.PRICE_FREE).isDefault)
|
||||
}
|
||||
|
||||
@Test fun sortsUseItchsOwnPaths() {
|
||||
assertEquals("https://itch.io/games", path())
|
||||
assertEquals("https://itch.io/games/new-and-popular", path(sort = ItchBrowse.SORT_NEW_POPULAR))
|
||||
assertEquals("https://itch.io/games/top-sellers", path(sort = ItchBrowse.SORT_TOP_SELLERS))
|
||||
assertEquals("https://itch.io/games/top-rated", path(sort = ItchBrowse.SORT_TOP_RATED))
|
||||
assertEquals("https://itch.io/games/newest", path(sort = ItchBrowse.SORT_NEWEST))
|
||||
}
|
||||
|
||||
@Test fun pricesUseItchsOwnPaths() {
|
||||
assertEquals("https://itch.io/games/free", path(price = ItchBrowse.PRICE_FREE))
|
||||
assertEquals("https://itch.io/games/on-sale", path(price = ItchBrowse.PRICE_SALE))
|
||||
assertEquals("https://itch.io/games/store", path(price = ItchBrowse.PRICE_PAID))
|
||||
assertEquals("https://itch.io/games/5-dollars-or-less", path(price = ItchBrowse.PRICE_UNDER_5))
|
||||
assertEquals("https://itch.io/games/15-dollars-or-less", path(price = ItchBrowse.PRICE_UNDER_15))
|
||||
}
|
||||
|
||||
@Test fun platformsUseItchsOwnNames() {
|
||||
val expected = mapOf(
|
||||
"windows" to "platform-windows", "osx" to "platform-osx", "linux" to "platform-linux", "android" to "platform-android",
|
||||
"ios" to "platform-ios", "web" to "platform-web", "mobile-web" to "platform-mobile-web",
|
||||
)
|
||||
assertEquals(expected.keys.toList(), ItchBrowse.platformNames)
|
||||
for ((name, segment) in expected) assertEquals("https://itch.io/games/$segment", path(platforms = setOf(name)))
|
||||
}
|
||||
|
||||
@Test fun aSortAPriceAndAPlatformCombineInThatOrder() {
|
||||
assertEquals(
|
||||
"https://itch.io/games/top-rated/free/platform-windows",
|
||||
path(ItchBrowse.SORT_TOP_RATED, ItchBrowse.PRICE_FREE, setOf("windows")),
|
||||
)
|
||||
}
|
||||
|
||||
@Test fun aTagIsItsLowercaseNameWithHyphens() {
|
||||
assertEquals("https://itch.io/games/tag-pixel-art", path(tags = listOf("Pixel Art")))
|
||||
assertEquals("pixel-art", ItchBrowse.tagSlug(" Pixel Art "))
|
||||
}
|
||||
|
||||
@Test fun aSortAPricePlatformAndTagCombineInThatOrder() {
|
||||
assertEquals(
|
||||
"https://itch.io/games/top-rated/free/platform-windows/tag-pixel-art.xml",
|
||||
ItchBrowse.url(BrowseQuery(ItchBrowse.SORT_TOP_RATED, ItchBrowse.PRICE_FREE, setOf("windows"), listOf("pixel-art")), 1),
|
||||
)
|
||||
}
|
||||
|
||||
@Test fun severalPlatformsAndTagsAreAllInTheAddress() {
|
||||
assertEquals(
|
||||
"https://itch.io/games/platform-windows/platform-linux/tag-pixel-art/tag-2d",
|
||||
path(platforms = setOf("linux", "windows"), tags = listOf("pixel-art", "2d")),
|
||||
)
|
||||
}
|
||||
|
||||
@Test fun aTypedTagBecomesItsSlug() {
|
||||
assertEquals("visual-novel", ItchBrowse.tagSlug("Visual Novel!"))
|
||||
assertEquals("", ItchBrowse.tagSlug(" !! "))
|
||||
}
|
||||
|
||||
@Test fun theSamePlatformsInAnyOrderGiveTheSameAddress() {
|
||||
assertEquals(path(platforms = setOf("web", "linux")), path(platforms = setOf("linux", "web")))
|
||||
}
|
||||
|
||||
@Test fun laterPagesAskForThePageNumberAndTheFirstDoesNot() {
|
||||
val query = BrowseQuery(sort = ItchBrowse.SORT_TOP_RATED)
|
||||
assertEquals("https://itch.io/games/top-rated.xml", ItchBrowse.url(query, 1))
|
||||
assertEquals("https://itch.io/games/top-rated.xml?page=2", ItchBrowse.url(query, 2))
|
||||
}
|
||||
}
|
||||
@@ -83,13 +83,14 @@ class XboxCatalogTest {
|
||||
assertEquals(mapOf(game to "gamepass", parent to "gamepass"), access(row(game, parent), row(parent, plan), row(plan)))
|
||||
}
|
||||
|
||||
@Test fun onlyPcPlansGrantSubscriptionAccess() {
|
||||
for (pc in listOf("CFQ7TTC0KGQ8", "CFQ7TTC0KHS0", "CFQ7TTC0P85B", "CFQ7TTC0K5DJ", "CFQ7TTC10QFD")) {
|
||||
assertEquals(mapOf(game to "gamepass"), access(row(game, pc), row(pc)))
|
||||
@Test fun everyActivePlanGrantsSubscriptionAccess() {
|
||||
for (plan in listOf("CFQ7TTC0KGQ8", "CFQ7TTC0KHS0", "CFQ7TTC0P85B", "CFQ7TTC0K5DJ", "CFQ7TTC10QFD", "CFQ7TTC0K6L8")) {
|
||||
assertEquals(mapOf(game to "gamepass"), access(row(game, plan), row(plan)))
|
||||
}
|
||||
val console = "CFQ7TTC0K6L8"
|
||||
assertTrue(access(row(game, console), row(console)).isEmpty())
|
||||
assertTrue(XboxCatalog.access(withMembership(envelope(row(game, console)), membership(console)),
|
||||
assertEquals(mapOf(game to "gamepass"), XboxCatalog.access(withMembership(envelope(row(game, console)), membership(console)),
|
||||
"test@example.test", "US", now))
|
||||
assertTrue(XboxCatalog.access(withMembership(envelope(row(game, console)), membership(console).put("status", "Expired")),
|
||||
"test@example.test", "US", now).isEmpty())
|
||||
}
|
||||
|
||||
@@ -165,4 +166,29 @@ class XboxCatalogTest {
|
||||
assertEquals(game, XboxCatalog.product(product("Windows.Desktop", "MSIXVC").put("ProductId", game.lowercase()), mapOf(game to "owned"))!!.id)
|
||||
assertTrue(pc.accessible); assertTrue(pc.subscription); assertFalse(pc.owned)
|
||||
}
|
||||
|
||||
private fun product(id: String, platform: String?) = JSONObject().put("ProductId", id).put("ProductType", "Game")
|
||||
.put("LocalizedProperties", JSONArray().put(JSONObject().put("ProductTitle", "A Game")))
|
||||
.put("DisplaySkuAvailabilities", JSONArray().put(JSONObject().put("Sku", JSONObject().put("Properties", JSONObject()
|
||||
.put("Packages", if (platform == null) JSONArray() else JSONArray().put(JSONObject().put("PackageFormat", "MSIXVC")
|
||||
.put("PlatformDependencies", JSONArray().put(JSONObject().put("PlatformName", platform)))))))))
|
||||
|
||||
@Test fun cloudListsKeepStreamOnlyGamesAndMarkStreamablePcGames() {
|
||||
val cloud = XboxCloudCatalog(gamePass = setOf(game), all = setOf(game, parent))
|
||||
val pc = XboxCatalog.product(product(game, "Windows.Desktop"), mapOf(game to "gamepass"), cloud)!!
|
||||
assertTrue(pc.xboxPc); assertTrue(pc.xboxCloud)
|
||||
val consoleOnly = XboxCatalog.product(product(parent, "Xbox.One"), mapOf(parent to "owned"), cloud)!!
|
||||
assertFalse(consoleOnly.xboxPc); assertTrue(consoleOnly.xboxCloud); assertEquals(0L, consoleOnly.sizeBytes)
|
||||
assertNull(XboxCatalog.product(product(parent, "Xbox.One"), mapOf(parent to "gamepass"), cloud))
|
||||
assertNull(XboxCatalog.product(product(parent, "Xbox.One"), mapOf(parent to "owned"), null))
|
||||
assertFalse(XboxCatalog.product(product(game, "Windows.Desktop"), mapOf(game to "gamepass"), null)!!.xboxCloud)
|
||||
}
|
||||
|
||||
@Test fun aCloudOnlyEditionFoldsIntoThePcCardWithTheSameTitle() {
|
||||
val cloud = XboxCloudCatalog(gamePass = setOf(parent), all = emptySet())
|
||||
val pc = XboxCatalog.product(product(game, "Windows.Desktop"), mapOf(game to "gamepass"), cloud)!!
|
||||
val console = XboxCatalog.product(product(parent, "Xbox.One"), mapOf(parent to "gamepass"), cloud)!!
|
||||
val merged = mergeEditions(listOf(pc, console)).single()
|
||||
assertEquals(game, merged.id); assertTrue(merged.xboxPc); assertTrue(merged.xboxCloud); assertEquals(parent, merged.xboxCloudId)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.droiddeck.launcher.stores.xbox
|
||||
|
||||
import com.droiddeck.launcher.stores.CatalogItem
|
||||
import com.droiddeck.launcher.stores.Store
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Test
|
||||
|
||||
@org.junit.runner.RunWith(org.robolectric.RobolectricTestRunner::class)
|
||||
@org.robolectric.annotation.Config(sdk = [33], application = android.app.Application::class)
|
||||
class XboxCloudTest {
|
||||
@Test fun settingsRoundTripAndOutOfRangeValuesAreClamped() {
|
||||
val settings = XboxCloudSettings(resolution = "720p", bitrateMbps = 20, volume = 200, sharpen = 4, fxaa = true, statsCorner = "left",
|
||||
playerEngine = "native", frameGen = "lsfg3", fpsLimit = 120, fpsCustomOn = true, fpsCustom = 90, smallBuffer = true, zeroCopy = true)
|
||||
assertEquals(settings, XboxCloudSettings.decode(settings.toJson()))
|
||||
val wild = XboxCloudSettings.decode("""{"resolution":"4k","codec":"x","bitrateMbps":900,"volume":5,"statsLevel":9,"gamma":40}""")
|
||||
assertEquals("1080p", wild.resolution); assertEquals("default", wild.codec); assertEquals(100, wild.bitrateMbps)
|
||||
assertEquals(100, wild.volume); assertEquals(4, wild.statsLevel); assertEquals(3f, wild.gamma)
|
||||
assertEquals("right", XboxCloudSettings.decode("""{"statsCorner":"middle"}""").statsCorner)
|
||||
assertEquals("ddfg", XboxCloudSettings.decode("""{"frameGen":"winfg"}""").frameGen)
|
||||
assertEquals(0, XboxCloudSettings.decode("""{"fpsLimit":77,"fpsCustom":500}""").fpsLimit)
|
||||
assertEquals(165, XboxCloudSettings.decode("""{"fpsCustomOn":true,"fpsCustom":500}""").fpsTarget)
|
||||
assertEquals(XboxCloudSettings(), XboxCloudSettings.decode("not json"))
|
||||
assertEquals("android", XboxCloudSettings(resolution = "720p").osName)
|
||||
assertEquals("tizen", XboxCloudSettings(resolution = "1080p_hq").osName)
|
||||
}
|
||||
|
||||
@Test fun addedCloudGamesKeepValidRowsOnly() {
|
||||
val list = listOf(XboxCloudGames.Entry("9AAAAAAAAAAA", "A game", "https://store-images.s-microsoft.com/p", null))
|
||||
val decoded = XboxCloudGames.decode(XboxCloudGames.encode(list))
|
||||
assertEquals(1, decoded.size); assertEquals("A game", decoded[0].title); assertNull(decoded[0].hero)
|
||||
assertTrue(XboxCloudGames.decode("""[{"id":"bad","title":"x"},{"id":"9BBBBBBBBBBB","title":""}]""").isEmpty())
|
||||
assertTrue(XboxCloudGames.decode("nope").isEmpty())
|
||||
assertTrue(XboxCloudGames.rowId("9AAAAAAAAAAA") < 0)
|
||||
}
|
||||
|
||||
@Test fun libraryFilterSplitsOwnedGamePassAndCloud() {
|
||||
fun item(owned: Boolean, pass: Boolean, cloud: Boolean) = CatalogItem(Store.XBOX, "9AAAAAAAAAAA", "A", null,
|
||||
owned = owned, subscription = pass, extra = mapOf("cloud" to if (cloud) "1" else "0"))
|
||||
val owned = item(true, false, false); val pass = item(false, true, true)
|
||||
assertTrue(XboxLibraryFilter.keeps(XboxLibraryFilter.ALL, owned))
|
||||
assertTrue(XboxLibraryFilter.keeps(XboxLibraryFilter.OWNED, owned)); assertFalse(XboxLibraryFilter.keeps(XboxLibraryFilter.OWNED, pass))
|
||||
assertTrue(XboxLibraryFilter.keeps(XboxLibraryFilter.GAME_PASS, pass)); assertFalse(XboxLibraryFilter.keeps(XboxLibraryFilter.GAME_PASS, owned))
|
||||
assertTrue(XboxLibraryFilter.keeps(XboxLibraryFilter.CLOUD, pass)); assertFalse(XboxLibraryFilter.keeps(XboxLibraryFilter.CLOUD, owned))
|
||||
}
|
||||
|
||||
@Test fun cloudLaunchUrlUsesTheStreamingEdition() {
|
||||
assertEquals("https://www.xbox.com/play/launch/ball-x-pit/9BBBBBBBBBBB", XboxCatalog.cloudUrl("9AAAAAAAAAAA", "BALL x PIT", "9BBBBBBBBBBB"))
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ class XboxLibraryCacheTest {
|
||||
private fun game(id: String, subscription: Boolean) = CatalogItem(Store.XBOX, id, "A game", "https://example.test/hero",
|
||||
tallImageUrl = "https://example.test/poster", description = "Description", developer = "Developer", publisher = "Publisher",
|
||||
sizeBytes = 12345, owned = !subscription, subscription = subscription, storeUrl = "https://www.xbox.com/games/store/$id",
|
||||
extra = mapOf("market" to "US", "access" to if (subscription) "gamepass" else "owned"))
|
||||
extra = mapOf("market" to "US", "access" to if (subscription) "gamepass" else "owned", "pc" to "1", "cloud" to "0", "cloudId" to ""))
|
||||
|
||||
@Test fun restartRestoresMetadataWithoutTurningSubscriptionsIntoPurchases() {
|
||||
val games = listOf(game("9AAAAAAAAAAA", false), game("9BBBBBBBBBBB", true))
|
||||
@@ -28,7 +28,7 @@ class XboxLibraryCacheTest {
|
||||
val text = XboxLibraryCache.encode(account, "US", listOf(game("9AAAAAAAAAAA", false)), now)
|
||||
assertNull(XboxLibraryCache.decode(text, "other@example.test", "US", now))
|
||||
assertNull(XboxLibraryCache.decode(text, account, "GB", now))
|
||||
assertNull(XboxLibraryCache.decode(text.replace("\"schema\":1", "\"schema\":2"), account, "US", now))
|
||||
assertNull(XboxLibraryCache.decode(text.replace("\"schema\":2", "\"schema\":1"), account, "US", now))
|
||||
assertNull(XboxLibraryCache.decode("invalid", account, "US", now))
|
||||
assertNull(XboxLibraryCache.decode(text, account, "US", now - 120_000))
|
||||
}
|
||||
@@ -50,4 +50,13 @@ class XboxLibraryCacheTest {
|
||||
XboxLibraryCache.clear(app)
|
||||
assertNull(XboxLibraryCache.read(app, account, "US"))
|
||||
}
|
||||
|
||||
@Test fun cloudFlagsAndTheStreamingEditionSurviveARestart() {
|
||||
val stream = game("9CCCCCCCCCCC", true).copy(extra = mapOf("market" to "US", "access" to "gamepass", "pc" to "0", "cloud" to "1", "cloudId" to ""))
|
||||
val folded = game("9AAAAAAAAAAA", true).copy(extra = mapOf("market" to "US", "access" to "gamepass", "pc" to "1", "cloud" to "1", "cloudId" to "9DDDDDDDDDDD"))
|
||||
val cached = XboxLibraryCache.decode(XboxLibraryCache.encode(account, "US", listOf(stream, folded), now), account, "US", now)!!
|
||||
assertEquals(listOf(stream, folded), cached.games)
|
||||
assertFalse(cached.games[0].xboxPc); assertTrue(cached.games[0].xboxCloud)
|
||||
assertEquals("9DDDDDDDDDDD", cached.games[1].xboxCloudId)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.droiddeck.launcher.stores.xbox
|
||||
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
class XodusDiagnosticsTest {
|
||||
private val rejected = Regex(Xodus.SIGN_IN_REJECTED)
|
||||
|
||||
@Test fun aContentLicenseRejectionIsRecognised() {
|
||||
assertTrue("Microsoft content licensing rejected sign-in (HTTP 401). Sign in again in Settings.".matches(rejected))
|
||||
}
|
||||
|
||||
@Test fun otherStderrTextIsNotTakenForARejection() {
|
||||
assertFalse("Microsoft content licensing rejected sign-in (HTTP 401). Sign in again in Settings. token=abc".matches(rejected))
|
||||
assertFalse("Microsoft content licensing rejected sign-in (HTTP 403). Sign in again in Settings.".matches(rejected))
|
||||
assertFalse("NEXUS_CONTENT_LICENSE_DIAGNOSTIC_V1 content-http 401".matches(rejected))
|
||||
}
|
||||
}
|
||||
@@ -48,7 +48,7 @@ class GamesClientTagTest {
|
||||
DroidDeckTheme {
|
||||
CompositionLocalProvider(LocalFrontFocus provides FrontFocus(), LocalNarrowPane provides narrow) {
|
||||
FocusGlideHost {
|
||||
GamesPage(FrontEndState(
|
||||
LibraryPage(FrontEndState(
|
||||
installed = "r9", ready = true, available = null, busy = false, stage = "", percent = -1,
|
||||
desktopInstalled = true, offlineAccount = null, offline = false, frameGenLabel = "",
|
||||
romsDir = null, logsEnabled = false, steamGames = games, steamGamesX64 = x64, emulators = emptyList(), running = null,
|
||||
@@ -60,7 +60,7 @@ class GamesClientTagTest {
|
||||
onRoms = {}, onFiles = {}, onLogs = {}, onOffline = {},
|
||||
onWirelessAdbPair = { _, _, _, _ -> }, onWirelessAdbApply = { _, _, _, _ -> },
|
||||
onSetPhantomProcessLimit = { _, _ -> },
|
||||
), selected = "app:440", onSelect = {}, modifier = Modifier.fillMaxSize())
|
||||
), selected = "games", onSelect = {}, modifier = Modifier.fillMaxSize())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import com.droiddeck.launcher.frontend.Library
|
||||
import com.droiddeck.launcher.stores.CatalogItem
|
||||
import com.droiddeck.launcher.stores.Store
|
||||
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 LibraryEntriesTest {
|
||||
private fun owned(store: Store, id: String, title: String = id) = CatalogItem(store, id, title, imageUrl = null, owned = true)
|
||||
|
||||
@Test fun anInstalledStoreGameClaimsItsOwnedProductSoItShowsOnce() {
|
||||
val games = listOf(
|
||||
Library.SteamGame(440, "Team Fortress 2", null, "Steam library"),
|
||||
Library.SteamGame(-5, "Cyberpunk", null, Library.ADDED, source = "gog", storeId = "1423049311"),
|
||||
)
|
||||
val library = mapOf(Store.GOG to listOf(owned(Store.GOG, "1423049311", "Cyberpunk 2077"), owned(Store.GOG, "1207658924", "Witcher")))
|
||||
val entries = libraryEntries(games, library, emptySet())
|
||||
assertEquals(listOf("app:440", "app:-5", "app:gog:1207658924"), entries.map { it.key })
|
||||
assertEquals("gog:1423049311", entries[1].item?.key)
|
||||
assertTrue(entries[1].installed)
|
||||
assertFalse(entries[2].installed)
|
||||
assertNull(entries[2].game)
|
||||
}
|
||||
|
||||
@Test fun theEpicLauncherIsNotAGame() {
|
||||
val launcher = Library.SteamGame(0, Library.EPIC_LAUNCHER_NAME, null, Library.EPIC_LAUNCHER)
|
||||
assertEquals(emptyList<String>(), libraryEntries(listOf(launcher), emptyMap(), emptySet()).map { it.key })
|
||||
}
|
||||
|
||||
@Test fun aStoreInstallTheLibraryHasNotScannedYetCountsAsInstalled() {
|
||||
val entries = libraryEntries(emptyList(), mapOf(Store.EPIC to listOf(owned(Store.EPIC, "fn"))), setOf("epic:fn"))
|
||||
assertTrue(entries.single().installed)
|
||||
}
|
||||
|
||||
@Test fun installedGamesComeFirstKeepingTheirSortedOrder() {
|
||||
val entries = listOf("a", "b", "c", "d").map { LibraryEntry(it, "steam", it, null, null, installed = it == "b" || it == "d") }
|
||||
assertEquals(listOf("b", "d", "a", "c"), installedFirst(entries).map { it.key })
|
||||
}
|
||||
|
||||
@Test fun gameKeysNameEitherAnAppOrAStoreProduct() {
|
||||
GameRef.parse("app:440").let { assertEquals(440, it.appId); assertNull(it.store) }
|
||||
GameRef.parse("app:-12").let { assertEquals(-12, it.appId) }
|
||||
GameRef.parse("app:gog:1207658924").let { assertEquals(Store.GOG, it.store); assertEquals("1207658924", it.storeId); assertNull(it.appId) }
|
||||
GameRef.parse("xbox:9NBLGGH4R315").let { assertEquals(Store.XBOX, it.store); assertEquals("9NBLGGH4R315", it.storeId) }
|
||||
GameRef.parse("app:nope:1").let { assertNull(it.store); assertNull(it.appId) }
|
||||
}
|
||||
}
|
||||
@@ -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 })
|
||||
|
||||
@@ -9,6 +9,7 @@ import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Button
|
||||
import androidx.compose.ui.test.*
|
||||
import androidx.compose.ui.semantics.SemanticsProperties.StateDescription
|
||||
import androidx.compose.runtime.MutableState
|
||||
import com.droiddeck.launcher.R
|
||||
import com.droiddeck.launcher.SessionActivity
|
||||
@@ -97,6 +98,42 @@ class SessionSecondScreenTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun sessionMicrophoneCanBeTurnedOff() {
|
||||
val changes = mutableListOf<Boolean>()
|
||||
compose.setContent {
|
||||
DroidDeckTheme {
|
||||
SessionDrawer(true, SessionDrawerPage.SESSION, false, {},
|
||||
actions(true, emptyList(), micAvailable = true, micEnabled = true, onMic = changes::add))
|
||||
}
|
||||
}
|
||||
compose.onNodeWithTag("setting-microphone").assertIsEnabled()
|
||||
.assert(SemanticsMatcher.expectValue(StateDescription, context.getString(R.string.widgets_on))).performClick()
|
||||
assertEquals(listOf(false), changes)
|
||||
}
|
||||
|
||||
@Test fun sessionMicrophoneCanBeTurnedBackOn() {
|
||||
val changes = mutableListOf<Boolean>()
|
||||
compose.setContent {
|
||||
DroidDeckTheme {
|
||||
SessionDrawer(true, SessionDrawerPage.SESSION, false, {},
|
||||
actions(true, emptyList(), micAvailable = true, onMic = changes::add))
|
||||
}
|
||||
}
|
||||
compose.onNodeWithTag("setting-microphone").assertIsEnabled()
|
||||
.assert(SemanticsMatcher.expectValue(StateDescription, context.getString(R.string.widgets_off))).performClick()
|
||||
assertEquals(listOf(true), changes)
|
||||
}
|
||||
|
||||
@Test fun sessionWithoutMicrophoneOmitsCaptureControl() {
|
||||
compose.setContent {
|
||||
DroidDeckTheme {
|
||||
SessionDrawer(true, SessionDrawerPage.SESSION, false, {}, actions(false, emptyList()))
|
||||
}
|
||||
}
|
||||
compose.onNodeWithTag("setting-microphone").assertDoesNotExist()
|
||||
compose.onNodeWithText(context.getString(R.string.mode_mic)).assertDoesNotExist()
|
||||
}
|
||||
|
||||
private fun checkModes(steam: Boolean) {
|
||||
SessionState.mode = if (steam) SessionService.MODE_STEAM else SessionService.MODE_DESKTOP
|
||||
val selected = mutableListOf<SecondScreenMode>()
|
||||
@@ -145,8 +182,11 @@ class SessionSecondScreenTest {
|
||||
if (view is ViewGroup) for (index in 0 until view.childCount) yieldAll(descendants(view.getChildAt(index)))
|
||||
}
|
||||
|
||||
private fun actions(steam: Boolean, displays: List<SecondScreenDisplay>, select: (SecondScreenMode) -> Unit = {}) =
|
||||
private fun actions(steam: Boolean, displays: List<SecondScreenDisplay>,
|
||||
micAvailable: Boolean = false, micEnabled: Boolean = false, onMic: (Boolean) -> Unit = {},
|
||||
select: (SecondScreenMode) -> Unit = {}) =
|
||||
DrawerActions(steam = steam, isHomeApp = false, androidApps = emptyList(), hudOn = false,
|
||||
micAvailable = micAvailable, micEnabled = micEnabled, onMicEnabled = onMic,
|
||||
frameGen = FrameGen.Mode.OFF, lossless = Lossless.State.NONE, oscMode = "never",
|
||||
onScreenButtonsVisible = false, suspendPolicy = "auto", backActionsInverted = false,
|
||||
touchMode = "auto", touchAuto = "trackpad", fexPreset = "default",
|
||||
|
||||
@@ -46,9 +46,4 @@ class StoreGridNavigationTest {
|
||||
assertEquals(10, storeGridNeighbor(6, 11, 4, 1, split = 6))
|
||||
assertNull(storeGridNeighbor(1, 11, 4, -1, split = 6))
|
||||
}
|
||||
|
||||
@Test fun installedGamesComeFirstKeepingTheirSortedOrder() {
|
||||
val items = listOf("a", "b", "c", "d").map { com.droiddeck.launcher.stores.CatalogItem(com.droiddeck.launcher.stores.Store.GOG, it, it, null) }
|
||||
assertEquals(listOf("b", "d", "a", "c"), installedFirst(items, setOf("d", "b")).map { it.id })
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import com.droiddeck.launcher.stores.Store
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
|
||||
class StoreTabsTest {
|
||||
@Test fun libraryAndStoreAmazonLibraryOnly() {
|
||||
assertEquals(listOf("library", "store"), tabsFor(Store.GOG))
|
||||
assertEquals(listOf("library", "store"), tabsFor(Store.ITCH))
|
||||
assertEquals(listOf("library"), tabsFor(Store.AMAZON))
|
||||
assertEquals("library", tabFor(Store.AMAZON, "store"))
|
||||
assertEquals("library", tabFor(Store.GOG, "all"))
|
||||
assertEquals("library", tabFor(Store.EPIC, "installed"))
|
||||
assertEquals("store", tabFor(Store.GOG, "store"))
|
||||
}
|
||||
}
|
||||
@@ -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