mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-21 22:05:59 +00:00
Merge origin/main into feat/malibridge-v25
This commit is contained in:
commit
a2a5f84711
132 files changed
+7212
-156
No files matched your search
@@ -0,0 +1,38 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
class BottomNotificationsTest {
|
||||
private val own = "com.droiddeck.launcher"
|
||||
|
||||
@Test fun messagesFromOtherAppsAreKept() {
|
||||
assertTrue(BottomNotifications.keep(own, "com.discord", ongoing = false, groupSummary = false, title = "Kurt", text = "ready?"))
|
||||
}
|
||||
|
||||
@Test fun ownOngoingSummaryAndEmptyNotificationsAreSkipped() {
|
||||
assertFalse(BottomNotifications.keep(own, own, ongoing = false, groupSummary = false, title = "Session", text = "running"))
|
||||
assertFalse(BottomNotifications.keep(own, "com.spotify", ongoing = true, groupSummary = false, title = "Song", text = "Artist"))
|
||||
assertFalse(BottomNotifications.keep(own, "com.discord", ongoing = false, groupSummary = true, title = "2 messages", text = ""))
|
||||
assertFalse(BottomNotifications.keep(own, "com.discord", ongoing = false, groupSummary = false, title = " ", text = ""))
|
||||
}
|
||||
|
||||
@Test fun anUpdatedNotificationMovesToTheTopOnce() {
|
||||
val list = mutableListOf(
|
||||
BottomNotification("a", "App", "one", "", 1L),
|
||||
BottomNotification("b", "App", "two", "", 2L),
|
||||
)
|
||||
BottomNotifications.add(list, BottomNotification("b", "App", "two again", "", 3L))
|
||||
assertEquals(listOf("b", "a"), list.map { it.key })
|
||||
assertEquals("two again", list.first().title)
|
||||
}
|
||||
|
||||
@Test fun theListKeepsTheNewestThirty() {
|
||||
val list = mutableListOf<BottomNotification>()
|
||||
repeat(35) { BottomNotifications.add(list, BottomNotification("k$it", "App", "t$it", "", it.toLong())) }
|
||||
assertEquals(30, list.size)
|
||||
assertEquals("k34", list.first().key)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.TemporaryFolder
|
||||
import java.io.File
|
||||
|
||||
class BottomScreenshotsTest {
|
||||
@get:Rule val tmp = TemporaryFolder()
|
||||
|
||||
@Test fun fileNamesSortByTime() {
|
||||
val name = BottomScreenshots.fileName(0L)
|
||||
assertTrue(name, name.startsWith("DroidDeck_") && name.endsWith(".jpg"))
|
||||
assertEquals(29, name.length)
|
||||
}
|
||||
|
||||
@Test fun steamScreenshotsAreFoundAndThumbnailsSkipped() {
|
||||
val root = tmp.root
|
||||
val shots = File(root, "root/.local/share/Steam/userdata/2932373/760/remote/220/screenshots")
|
||||
File(shots, "thumbnails").mkdirs()
|
||||
File(shots, "20261031010101_1.jpg").writeText("x")
|
||||
File(shots, "thumbnails/20261031010101_1.jpg").writeText("x")
|
||||
File(shots, "screenshots.vdf").writeText("x")
|
||||
val x64 = File(root, "root/.droiddeck-x64/.local/share/Steam/userdata/2932373/760/remote/440/screenshots")
|
||||
x64.mkdirs()
|
||||
File(x64, "20261031020202_1.jpg").writeText("x")
|
||||
val found = BottomScreenshots.steam(root).map { it.file!!.name }.sorted()
|
||||
assertEquals(listOf("20261031010101_1.jpg", "20261031020202_1.jpg"), found)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,226 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
import java.nio.ByteBuffer
|
||||
import java.nio.ByteOrder
|
||||
|
||||
class GameTelemetryTest {
|
||||
private fun packet(size: Int, fill: ByteBuffer.() -> Unit): ByteArray =
|
||||
ByteBuffer.allocate(size).order(ByteOrder.LITTLE_ENDIAN).apply(fill).array()
|
||||
|
||||
@Test fun codemastersFloatsBecomeADash() {
|
||||
val data = packet(264) {
|
||||
putFloat(7 * 4, 25f) // m/s
|
||||
putFloat(29 * 4, 0.8f)
|
||||
putFloat(31 * 4, 0.1f)
|
||||
putFloat(33 * 4, 3f)
|
||||
putFloat(36 * 4, 1f)
|
||||
putFloat(37 * 4, 650f) // rpm / 10
|
||||
putFloat(63 * 4, 800f)
|
||||
putFloat(45 * 4, 30f)
|
||||
putFloat(46 * 4, 60f)
|
||||
}
|
||||
val t = GameTelemetry.parse(GameTelemetry.CODEMASTERS_PORT, data, data.size)!!
|
||||
assertEquals(90f, t.speedKmh!!, 0.01f)
|
||||
assertEquals("3", t.gear)
|
||||
assertEquals(6500f, t.rpm!!, 0.01f)
|
||||
assertEquals(8000f, t.maxRpm!!, 0.01f)
|
||||
assertEquals(2, t.lap)
|
||||
assertEquals(0.5f, t.fuel!!, 0.001f)
|
||||
}
|
||||
|
||||
// Values from a DiRT Showdown packet recorded on a Retroid Pocket Duo (extradata 3 still sends 152 bytes there).
|
||||
@Test fun codemastersShortPacketFromDirtShowdown() {
|
||||
val data = packet(152) {
|
||||
putFloat(1 * 4, 80.085f)
|
||||
putFloat(7 * 4, 10.739f)
|
||||
putFloat(29 * 4, 0.816f)
|
||||
putFloat(33 * 4, 1f)
|
||||
putFloat(37 * 4, 827.531f)
|
||||
}
|
||||
val t = GameTelemetry.parse(GameTelemetry.CODEMASTERS_PORT, data, data.size)!!
|
||||
assertEquals(38.66f, t.speedKmh!!, 0.01f)
|
||||
assertEquals("1", t.gear)
|
||||
assertEquals(8275.31f, t.rpm!!, 0.01f)
|
||||
assertEquals(0.816f, t.throttle!!, 0.001f)
|
||||
assertEquals(1, t.lap)
|
||||
assertEquals(80.085f, t.currentLapS!!, 0.001f)
|
||||
assertNull(t.maxRpm)
|
||||
assertNull(t.laps)
|
||||
assertNull(t.position)
|
||||
assertNull(t.fuel)
|
||||
assertNull(t.lastLapS)
|
||||
}
|
||||
|
||||
@Test fun codemastersReverseAndNeutral() {
|
||||
fun gear(g: Float) = GameTelemetry.parse(GameTelemetry.CODEMASTERS_PORT, packet(264) { putFloat(33 * 4, g) }, 264)!!.gear
|
||||
assertEquals("N", gear(0f))
|
||||
assertEquals("R", gear(-1f))
|
||||
assertEquals("R", gear(10f))
|
||||
}
|
||||
|
||||
@Test fun forzaHorizonDashSitsTwelveBytesLater() {
|
||||
val dash = 232 + 12
|
||||
val data = packet(324) {
|
||||
putInt(0, 1)
|
||||
putFloat(8, 8000f)
|
||||
putFloat(16, 5000f)
|
||||
putFloat(dash + 12, 50f)
|
||||
put(dash + 71, 255.toByte())
|
||||
put(dash + 75, 4)
|
||||
putShort(dash + 68, 2)
|
||||
put(dash + 70, 5)
|
||||
}
|
||||
val t = GameTelemetry.parse(GameTelemetry.FORZA_PORT, data, data.size)!!
|
||||
assertEquals(180f, t.speedKmh!!, 0.01f)
|
||||
assertEquals("4", t.gear)
|
||||
assertEquals(1f, t.throttle!!, 0.001f)
|
||||
assertEquals(3, t.lap)
|
||||
assertEquals(5, t.position)
|
||||
}
|
||||
|
||||
@Test fun forzaMotorsportDashFollowsTheSled() {
|
||||
val data = packet(311) {
|
||||
putInt(0, 1)
|
||||
putFloat(232 + 12, 10f)
|
||||
put(232 + 75, 0)
|
||||
}
|
||||
val t = GameTelemetry.parse(GameTelemetry.FORZA_PORT, data, data.size)!!
|
||||
assertEquals(36f, t.speedKmh!!, 0.01f)
|
||||
assertEquals("R", t.gear)
|
||||
}
|
||||
|
||||
@Test fun forzaInMenusHasNoDash() {
|
||||
val t = GameTelemetry.parse(GameTelemetry.FORZA_PORT, packet(324) {}, 324)!!
|
||||
assertNull(t.speedKmh)
|
||||
}
|
||||
|
||||
@Test fun outGaugeGearsAreShiftedByOne() {
|
||||
val data = packet(96) {
|
||||
put(10, 3)
|
||||
putFloat(12, 20f)
|
||||
putFloat(16, 4000f)
|
||||
}
|
||||
val t = GameTelemetry.parse(GameTelemetry.OUTGAUGE_PORT, data, data.size)!!
|
||||
assertEquals("2", t.gear)
|
||||
assertEquals(72f, t.speedKmh!!, 0.01f)
|
||||
assertEquals(4000f, t.rpm!!, 0.01f)
|
||||
}
|
||||
|
||||
@Test fun listensOnIpv4Loopback() {
|
||||
assertTrue(GameTelemetry.LISTEN_ADDRESS is java.net.Inet4Address)
|
||||
assertEquals("127.0.0.1", GameTelemetry.LISTEN_ADDRESS.hostAddress)
|
||||
}
|
||||
|
||||
@Test fun shortPacketsAreIgnored() {
|
||||
assertNull(GameTelemetry.parse(GameTelemetry.CODEMASTERS_PORT, ByteArray(148), 148))
|
||||
assertNull(GameTelemetry.parse(GameTelemetry.OUTGAUGE_PORT, ByteArray(40), 40))
|
||||
assertNull(GameTelemetry.parse(1234, ByteArray(400), 400))
|
||||
}
|
||||
|
||||
// DiRT Showdown's 38 floats already carry steering and both G-forces.
|
||||
@Test fun codemastersGForceAndSteering() {
|
||||
val data = packet(152) {
|
||||
putFloat(30 * 4, -0.5f)
|
||||
putFloat(33 * 4, 2f)
|
||||
putFloat(34 * 4, 1.2f)
|
||||
putFloat(35 * 4, -0.8f)
|
||||
}
|
||||
val t = GameTelemetry.parse(GameTelemetry.CODEMASTERS_PORT, data, data.size)!!
|
||||
assertEquals(-0.5f, t.steer!!, 1e-4f)
|
||||
assertEquals(1.2f, t.gLat!!, 1e-4f)
|
||||
assertEquals(-0.8f, t.gLon!!, 1e-4f)
|
||||
}
|
||||
|
||||
@Test fun forzaReadsBestLapSteeringGForceAndTires() {
|
||||
val dash = 232
|
||||
val data = packet(311) {
|
||||
putInt(0, 1)
|
||||
putFloat(20, 9.81f)
|
||||
putFloat(28, -4.905f)
|
||||
putFloat(dash + 24, 212f)
|
||||
putFloat(dash + 28, 32f)
|
||||
putFloat(dash + 32, 194f)
|
||||
putFloat(dash + 36, 176f)
|
||||
putFloat(dash + 52, 81.5f)
|
||||
put(dash + 75, 3)
|
||||
put(dash + 76, (-127).toByte())
|
||||
}
|
||||
val t = GameTelemetry.parse(GameTelemetry.FORZA_PORT, data, data.size)!!
|
||||
assertEquals(1f, t.gLat!!, 1e-3f)
|
||||
assertEquals(-0.5f, t.gLon!!, 1e-3f)
|
||||
assertEquals(listOf(100f, 0f, 90f, 80f), t.tireTempsC!!.map { Math.round(it).toFloat() })
|
||||
assertEquals(81.5f, t.bestLapS!!, 1e-4f)
|
||||
assertEquals(-1f, t.steer!!, 1e-4f)
|
||||
}
|
||||
|
||||
@Test fun forzaWithoutTireDataLeavesThemOut() {
|
||||
val data = packet(311) { putInt(0, 1); put(232 + 75, 2) }
|
||||
assertNull(GameTelemetry.parse(GameTelemetry.FORZA_PORT, data, data.size)!!.tireTempsC)
|
||||
}
|
||||
|
||||
@Test fun outGaugeReadsTurboTemperaturesAndLights() {
|
||||
val data = packet(92) {
|
||||
put(10, 3)
|
||||
putFloat(20, 0.8f)
|
||||
putFloat(24, 92f)
|
||||
putFloat(36, 104f)
|
||||
putInt(40, GameTelemetry.DL_SHIFT or GameTelemetry.DL_ABS or GameTelemetry.DL_HANDBRAKE)
|
||||
putInt(44, GameTelemetry.DL_SHIFT or GameTelemetry.DL_ABS)
|
||||
}
|
||||
val t = GameTelemetry.parse(GameTelemetry.OUTGAUGE_PORT, data, data.size)!!
|
||||
assertEquals(0.8f, t.turboBar!!, 1e-4f)
|
||||
assertEquals(92f, t.engineTempC!!, 1e-4f)
|
||||
assertEquals(104f, t.oilTempC!!, 1e-4f)
|
||||
assertEquals(GameTelemetry.DL_SHIFT or GameTelemetry.DL_ABS, t.lights)
|
||||
}
|
||||
|
||||
// BeamNG leaves some OutGauge fields at zero; those stay hidden.
|
||||
@Test fun outGaugeZeroFieldsStayHidden() {
|
||||
val t = GameTelemetry.parse(GameTelemetry.OUTGAUGE_PORT, packet(92) { put(10, 2) }, 92)!!
|
||||
assertNull(t.turboBar)
|
||||
assertNull(t.engineTempC)
|
||||
assertNull(t.lights)
|
||||
}
|
||||
}
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [33])
|
||||
class GameStatusFilesTest {
|
||||
@Test fun warThunderShowsNumbersOnlyDuringAMatch() {
|
||||
assertEquals(emptyList<Pair<String, String>>(), GameStatusFiles.warThunder("""{"valid": false}"""))
|
||||
val rows = GameStatusFiles.warThunder("""{"valid": true, "H, m": 1520, "TAS, km/h": 512.4, "name": "x"}""")
|
||||
assertEquals(listOf("H, m" to "1520", "TAS, km/h" to "512.4"), rows)
|
||||
}
|
||||
|
||||
@Test fun warThunderKeepsEveryNumberForTheFlightLayout() {
|
||||
val json = buildString {
|
||||
append("{\"valid\": true")
|
||||
for (i in 0 until 20) append(", \"k$i\": $i")
|
||||
append(", \"IAS, km/h\": 512, \"throttle 1, %\": 110}")
|
||||
}
|
||||
val rows = GameStatusFiles.warThunder(json)
|
||||
assertEquals(22, rows.size)
|
||||
assertTrue(com.droiddeck.launcher.ui.FlightLabels.drawable(rows))
|
||||
assertEquals("110", rows.toMap()["throttle 1, %"])
|
||||
}
|
||||
|
||||
@Test fun eliteAtTheMenusShowsNothing() {
|
||||
assertNull(GameStatusFiles.elite("""{"timestamp": "2026-10-31T02:00:00Z", "event": "Status", "Flags": 0}"""))
|
||||
}
|
||||
|
||||
@Test fun eliteInFlight() {
|
||||
val e = GameStatusFiles.elite("""{"Flags": 16777240, "Pips": [4, 8, 0], "Fuel": {"FuelMain": 16.0, "FuelReservoir": 0.43},
|
||||
"Cargo": 2.0, "LegalState": "Clean", "Balance": 1234567}""")!!
|
||||
assertEquals(16.0, e.fuelMain!!, 0.001)
|
||||
assertEquals(listOf(4, 8, 0), e.pips)
|
||||
assertEquals("Clean", e.legal)
|
||||
assertEquals(1234567L, e.balance)
|
||||
}
|
||||
}
|
||||
@@ -88,6 +88,105 @@ class SessionSuspendControllerTest {
|
||||
assertTrue(disabled.pagedOut.isEmpty())
|
||||
}
|
||||
|
||||
@Test fun resumeReadsThePagedOutMemoryBack() {
|
||||
val fixture = fixture(17)
|
||||
fixture.control.writeText("0")
|
||||
fixture.controller.freeze(pageOut = true) { assertTrue(it) }
|
||||
val before = fixture.signals.size
|
||||
fixture.controller.resume { assertTrue(it) }
|
||||
val resumed = fixture.signals.drop(before)
|
||||
assertEquals(listOf(GAME), resumed.filter { it.signal == URG }.map { it.pid })
|
||||
assertTrue(resumed.indexOfLast { it.signal == CONT } < resumed.indexOfFirst { it.signal == URG })
|
||||
assertEquals("0", fixture.control.readText())
|
||||
assertEquals(listOf(Triple(1, 0L, 3_000_000L)), fixture.pagedIn)
|
||||
assertTrue(fixture.game.threads.all { it.state == 'S' })
|
||||
val again = fixture.signals.size
|
||||
fixture.controller.freeze { assertTrue(it) }
|
||||
fixture.controller.resume { assertTrue(it) }
|
||||
assertFalse(fixture.signals.drop(again).any { it.signal == URG })
|
||||
assertEquals(1, fixture.pagedIn.size)
|
||||
}
|
||||
|
||||
@Test fun noReadBackAfterAFreezeWithoutPageOut() {
|
||||
val fixture = fixture(17)
|
||||
fixture.control.writeText("0")
|
||||
fixture.controller.freeze { assertTrue(it) }
|
||||
fixture.controller.resume { assertTrue(it) }
|
||||
assertFalse(fixture.signals.any { it.signal == URG })
|
||||
assertTrue(fixture.pagedIn.isEmpty())
|
||||
}
|
||||
|
||||
@Test fun readBackIsSkippedWhenAvailableMemoryCannotTakeIt() {
|
||||
val fixture = fixture(17)
|
||||
fixture.control.writeText("0")
|
||||
fixture.availableKb = 3_500_000L
|
||||
fixture.controller.freeze(pageOut = true) { assertTrue(it) }
|
||||
val before = fixture.signals.size
|
||||
fixture.controller.resume { assertTrue(it) }
|
||||
assertFalse(fixture.signals.drop(before).any { it.signal == URG })
|
||||
assertEquals("1", fixture.control.readText())
|
||||
assertEquals(listOf(Triple(0, 3_000_000L, 3_000_000L)), fixture.pagedIn)
|
||||
}
|
||||
|
||||
@Test fun readBackNeedsTwiceTheSwapAvailable() {
|
||||
val fixture = fixture(17)
|
||||
fixture.control.writeText("0")
|
||||
fixture.availableKb = 5_500_000L
|
||||
fixture.controller.freeze(pageOut = true) { assertTrue(it) }
|
||||
val before = fixture.signals.size
|
||||
fixture.controller.resume { assertTrue(it) }
|
||||
assertFalse(fixture.signals.drop(before).any { it.signal == URG })
|
||||
assertEquals(listOf(Triple(0, 3_000_000L, 3_000_000L)), fixture.pagedIn)
|
||||
}
|
||||
|
||||
@Test fun readBackKeepsATenthOfMemTotalAvailable() {
|
||||
val fixture = fixture(17)
|
||||
fixture.control.writeText("0")
|
||||
fixture.totalKb = 40_000_000L
|
||||
fixture.availableKb = 6_500_000L
|
||||
fixture.controller.freeze(pageOut = true) { assertTrue(it) }
|
||||
val before = fixture.signals.size
|
||||
fixture.controller.resume { assertTrue(it) }
|
||||
assertFalse(fixture.signals.drop(before).any { it.signal == URG })
|
||||
assertEquals(listOf(Triple(0, 3_000_000L, 3_000_000L)), fixture.pagedIn)
|
||||
}
|
||||
|
||||
@Test fun noReadBackWithARamCap() {
|
||||
val fixture = fixture(17)
|
||||
fixture.control.writeText("0")
|
||||
fixture.readBackAllowed = false
|
||||
fixture.controller.freeze(pageOut = true) { assertTrue(it) }
|
||||
val before = fixture.signals.size
|
||||
fixture.controller.resume { assertTrue(it) }
|
||||
assertFalse(fixture.signals.drop(before).any { it.signal == URG })
|
||||
assertEquals("1", fixture.control.readText())
|
||||
assertEquals(listOf(Triple(0, 3_000_000L, 3_000_000L)), fixture.pagedIn)
|
||||
}
|
||||
|
||||
@Test fun cancelledFreezeReadsBackWhatThePageOutAlreadyMoved() {
|
||||
val fixture = fixture(17)
|
||||
fixture.control.writeText("0")
|
||||
fixture.afterSleep = { if (fixture.now >= 200 && fixture.signals.none { it.signal == STOP }) fixture.controller.cancelFreeze() }
|
||||
fixture.controller.freeze(pageOut = true) { assertFalse(it) }
|
||||
assertFalse(fixture.signals.any { it.signal == STOP })
|
||||
assertEquals(2, fixture.signals.count { it.signal == URG })
|
||||
assertEquals("0", fixture.control.readText())
|
||||
assertEquals(1, fixture.pagedIn.single().first)
|
||||
assertEquals(0L, fixture.pagedIn.single().second)
|
||||
assertTrue(fixture.pagedIn.single().third > 0L)
|
||||
}
|
||||
|
||||
@Test fun cancelledFreezeLeavesAPendingPageOutHandlerReadingBack() {
|
||||
val fixture = fixture(17)
|
||||
fixture.control.writeText("0")
|
||||
fixture.handlerStalls = true
|
||||
fixture.afterSleep = { if (fixture.now >= 500) fixture.controller.cancelFreeze() }
|
||||
fixture.controller.freeze(pageOut = true) { assertFalse(it) }
|
||||
assertEquals(2, fixture.signals.count { it.signal == URG })
|
||||
assertEquals("0", fixture.control.readText())
|
||||
assertEquals(Triple(1, 0L, 0L), fixture.pagedIn.single())
|
||||
}
|
||||
|
||||
@Test fun cpuMustBeStableAcrossTwoCompleteSnapshots() {
|
||||
val fixture = fixture(17)
|
||||
var changes = 0
|
||||
@@ -380,9 +479,14 @@ class SessionSuspendControllerTest {
|
||||
val clock = File(tmp, ".bl-clock")
|
||||
var clockAtContinue: Long? = null
|
||||
val pagedOut = mutableListOf<Triple<Int, Long, Long>>()
|
||||
val pagedIn = mutableListOf<Triple<Int, Long, Long>>()
|
||||
var availableKb = 8_000_000L
|
||||
var totalKb = 16_000_000L
|
||||
var readBackAllowed = true
|
||||
private var gameResidentKb = 4_000_000L
|
||||
private var gameSwapKb = 0L
|
||||
private var pagingOut = false
|
||||
private var pagingIn = false
|
||||
var unacknowledged = -1
|
||||
var handlerStalls = false
|
||||
var handlerReplaced = false
|
||||
@@ -397,6 +501,8 @@ class SessionSuspendControllerTest {
|
||||
pagedOut += Triple(processes, resident, swap)
|
||||
this.unacknowledged = unacknowledged
|
||||
},
|
||||
readBackAllowed = { readBackAllowed },
|
||||
pagedIn = { processes, swap, swapBefore, _, _ -> pagedIn += Triple(processes, swap, swapBefore) },
|
||||
)
|
||||
|
||||
init { sync() }
|
||||
@@ -411,7 +517,7 @@ class SessionSuspendControllerTest {
|
||||
it.state !in listOf('T', 't', 'Z', 'X') && !(neverStop && it == game.threads.last())
|
||||
}?.state = 't'
|
||||
} else if (signal == URG) {
|
||||
pagingOut = true
|
||||
if (control.readText() == "0") { pagingOut = false; pagingIn = true } else pagingOut = true
|
||||
} else if (signal == CONT) {
|
||||
if (clockAtContinue == null && clock.isFile) {
|
||||
clockAtContinue = ByteBuffer.wrap(clock.readBytes()).order(ByteOrder.LITTLE_ENDIAN).long
|
||||
@@ -445,6 +551,12 @@ class SessionSuspendControllerTest {
|
||||
pagingOut = false
|
||||
}
|
||||
}
|
||||
if (pagingIn) {
|
||||
val moved = minOf(gameSwapKb, 1_000_000L)
|
||||
gameSwapKb -= moved
|
||||
gameResidentKb += moved
|
||||
if (gameSwapKb == 0L) pagingIn = false
|
||||
}
|
||||
if (root.threads.first().state != 'T' && !continuing) game.threads.forEach {
|
||||
if (it.state != 'Z') { it.state = 'S'; it.cpu++ }
|
||||
}
|
||||
@@ -453,6 +565,7 @@ class SessionSuspendControllerTest {
|
||||
}
|
||||
|
||||
fun sync() {
|
||||
File(proc, "meminfo").writeText("MemTotal:\t$totalKb kB\nMemFree:\t1000 kB\nMemAvailable:\t$availableKb kB\n")
|
||||
for (group in groups) {
|
||||
val dir = File(proc, group.pid.toString())
|
||||
if (group == root && rootGone) { dir.deleteRecursively(); continue }
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
|
||||
class StatsLayoutTest {
|
||||
@Test fun unknownIdsFallBackToTheDefaults() {
|
||||
assertEquals(StatsStrip.PANEL, StatsStrip.from(null))
|
||||
assertEquals(StatsStrip.RINGS, StatsStrip.from("rings"))
|
||||
assertEquals(StatsDash.AUTO, StatsDash.from("gone"))
|
||||
assertEquals(StatsDash.TRACE, StatsDash.from("trace"))
|
||||
}
|
||||
|
||||
@Test fun tappingTheStripCyclesThroughEveryStyle() {
|
||||
assertEquals(StatsStrip.TILES, StatsStrip.PANEL.next())
|
||||
assertEquals(StatsStrip.RINGS, StatsStrip.TILES.next())
|
||||
assertEquals(StatsStrip.PANEL, StatsStrip.RINGS.next())
|
||||
}
|
||||
|
||||
@Test fun autoPicksTheDashByTheGamesFormat() {
|
||||
assertEquals(StatsDash.SPEEDOMETER, StatsDash.AUTO.resolve("Codemasters"))
|
||||
assertEquals(StatsDash.CIRCUIT, StatsDash.AUTO.resolve("Forza"))
|
||||
assertEquals(StatsDash.DIALS, StatsDash.AUTO.resolve("OutGauge"))
|
||||
assertEquals(StatsDash.TRACE, StatsDash.TRACE.resolve("Forza"))
|
||||
}
|
||||
|
||||
@Test fun tappingTheDashMovesOnFromTheOneOnScreen() {
|
||||
assertEquals(StatsDash.CIRCUIT, StatsDash.tapped(StatsDash.SPEEDOMETER))
|
||||
assertEquals(StatsDash.SPEEDOMETER, StatsDash.tapped(StatsDash.GLANCE))
|
||||
assertEquals(StatsDash.SPEEDOMETER, StatsDash.tapped(StatsDash.AUTO))
|
||||
}
|
||||
|
||||
@Test fun automaticSpeedUnitsFollowTheRegion() {
|
||||
assertEquals(SpeedUnit.MPH, SpeedUnit.AUTO.resolve("US"))
|
||||
assertEquals(SpeedUnit.MPH, SpeedUnit.AUTO.resolve("gb"))
|
||||
assertEquals(SpeedUnit.KMH, SpeedUnit.AUTO.resolve("DE"))
|
||||
assertEquals(SpeedUnit.KMH, SpeedUnit.AUTO.resolve(""))
|
||||
assertEquals(SpeedUnit.KMH, SpeedUnit.KMH.resolve("US"))
|
||||
assertEquals(SpeedUnit.MPH, SpeedUnit.MPH.resolve("DE"))
|
||||
}
|
||||
|
||||
@Test fun speedUnitsCycleAndConvert() {
|
||||
assertEquals(SpeedUnit.AUTO, SpeedUnit.from(null))
|
||||
assertEquals(SpeedUnit.MPH, SpeedUnit.from("mph"))
|
||||
assertEquals(SpeedUnit.KMH, SpeedUnit.AUTO.next())
|
||||
assertEquals(SpeedUnit.MPH, SpeedUnit.KMH.next())
|
||||
assertEquals(SpeedUnit.AUTO, SpeedUnit.MPH.next())
|
||||
assertEquals(62.1f, 100f * SpeedUnit.MPH.perKmh, 0.05f)
|
||||
assertEquals(100f, 100f * SpeedUnit.KMH.perKmh, 0f)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
class SteamDownloadsTest {
|
||||
private fun manifest(flags: Long, done: Long, total: Long) = """
|
||||
"AppState"
|
||||
{
|
||||
"appid" "220"
|
||||
"name" "Half-Life 2"
|
||||
"StateFlags" "$flags"
|
||||
"BytesToDownload" "$total"
|
||||
"BytesDownloaded" "$done"
|
||||
}
|
||||
""".trimIndent()
|
||||
|
||||
@Test fun anAppUnfinishedInBothSteamHomesIsListedOnce() {
|
||||
val arm = SteamDownload("220", "Half-Life 2", 10L, 100L)
|
||||
val x86 = SteamDownload("220", "Half-Life 2", 60L, 100L)
|
||||
val other = SteamDownload("440", "Team Fortress 2", 5L, 50L)
|
||||
assertEquals(listOf(x86, other), SteamDownloads.onePerApp(listOf(arm, x86, other)))
|
||||
}
|
||||
|
||||
@Test fun anInstalledGameIsNotADownload() {
|
||||
assertNull(SteamDownloads.fromManifest("220", "Half-Life 2", manifest(4, 100, 100)))
|
||||
}
|
||||
|
||||
@Test fun aRunningUpdateShowsItsBytes() {
|
||||
val d = SteamDownloads.fromManifest("220", "Half-Life 2", manifest(1026, 40, 100))!!
|
||||
assertEquals(40L, d.done)
|
||||
assertEquals(100L, d.total)
|
||||
}
|
||||
|
||||
@Test fun aPausedUpdateSaysSo() {
|
||||
assertTrue(SteamDownloads.fromManifest("220", "Half-Life 2", manifest(514, 40, 100))!!.paused)
|
||||
}
|
||||
|
||||
@Test fun anUpdateNotSizedYetIsStillListed() {
|
||||
assertEquals(0L, SteamDownloads.fromManifest("220", "Half-Life 2", manifest(6, 0, 0))!!.total)
|
||||
}
|
||||
|
||||
@Test fun onlyShaderUpdatesStillRunningCount() {
|
||||
val log = sequenceOf(
|
||||
"[2026-10-30 06:33:02] AppID 220 Shader update changed : Running Update,Downloading,",
|
||||
"[2026-10-30 06:33:02] AppID 440 Shader update changed : Running Update,",
|
||||
"[2026-10-30 06:33:03] AppID 440 Shader update changed : None",
|
||||
"[2026-10-30 06:33:03] AppID 570 App update changed : Running Update,",
|
||||
)
|
||||
assertEquals(listOf("220"), SteamDownloads.runningShaderUpdates(log))
|
||||
}
|
||||
|
||||
@Test fun aClientRestartForgetsOlderShaderUpdates() {
|
||||
val log = sequenceOf(
|
||||
"[2026-10-30 06:33:02] AppID 220 Shader update changed : Running Update,",
|
||||
"[2026-10-30 07:00:00] Client version: 1761000000",
|
||||
)
|
||||
assertEquals(emptyList<String>(), SteamDownloads.runningShaderUpdates(log))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Test
|
||||
|
||||
class SteamWebLoginTest {
|
||||
private fun hex(s: String) = ByteArray(s.length / 2) { s.substring(it * 2, it * 2 + 2).toInt(16).toByte() }
|
||||
|
||||
// Made with: openssl enc -aes-128-cbc -K <PBKDF2-SHA1("peanuts","saltysalt",1)> -iv <16 spaces>, prefixed "v10".
|
||||
@Test fun chromiumV10ValuesDecrypt() {
|
||||
val encrypted = hex("7631300b9cf0a6eee9cf1aaac601b85ca37cf9fe9e67078564f0e05835ae2aa3d9b0ab")
|
||||
assertEquals("0123456789abcdef01234567", SteamWebLogin.decrypt(encrypted, hostHashed = false))
|
||||
}
|
||||
|
||||
@Test fun newerStoresDropTheHostHash() {
|
||||
val encrypted = hex("7631304d4114329f1e692e807b8b044d67460f5e14d92ffb48b9f83be318ebd0d84c727674aea32f351b8a33c8aa42553dfeb5")
|
||||
assertEquals("hello", SteamWebLogin.decrypt(encrypted, hostHashed = true))
|
||||
}
|
||||
|
||||
@Test fun otherFormatsAreSkipped() {
|
||||
assertNull(SteamWebLogin.decrypt("v11garbage".toByteArray(), hostHashed = false))
|
||||
assertNull(SteamWebLogin.decrypt(ByteArray(2), hostHashed = false))
|
||||
}
|
||||
|
||||
@Test fun theSignInIsSentTheWaySteamPagesSendIt() {
|
||||
assertEquals("steamLoginSecure=76561190000000000%7C%7Ca.b.c; Path=/; Secure; HttpOnly",
|
||||
SteamWebLogin.header("steamLoginSecure", "76561190000000000||a.b.c", httpOnly = true))
|
||||
assertEquals("sessionid=0123; Path=/; Secure", SteamWebLogin.header("sessionid", "0123", httpOnly = false))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.TemporaryFolder
|
||||
import java.io.File
|
||||
|
||||
class TelemetryOutputTest {
|
||||
@get:Rule val tmp = TemporaryFolder()
|
||||
|
||||
// DiRT Showdown's own line, as found in its prefix on the Retroid Pocket Duo.
|
||||
private val showdown = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n<hardware_settings_config>\n" +
|
||||
"\t<audio mono=\"false\" />\n\t<motion enabled=\"true\" ip=\"dbox\" port=\"20777\" delay=\"1\" extradata=\"0\" />\n" +
|
||||
"</hardware_settings_config>\n"
|
||||
|
||||
@Test fun turningOnPointsTheMotionLineHereAndKeepsTheRest() {
|
||||
val on = TelemetryOutput.turnedOn(showdown)!!
|
||||
assertTrue(on.contains("<motion enabled=\"true\" ip=\"127.0.0.1\" port=\"20777\" delay=\"1\" extradata=\"3\" />"))
|
||||
assertEquals(showdown.replace("ip=\"dbox\"", "ip=\"127.0.0.1\"").replace("extradata=\"0\"", "extradata=\"3\""), on)
|
||||
assertTrue(TelemetryOutput.pointsHere(TelemetryOutput.element(on)!!.value))
|
||||
assertFalse(TelemetryOutput.pointsHere(TelemetryOutput.element(showdown)!!.value))
|
||||
}
|
||||
|
||||
@Test fun theUdpLineWinsOverTheMotionLineAndLongerTagsAreIgnored() {
|
||||
val xml = "<x><motion_platform><dbox enabled=\"true\" /></motion_platform>" +
|
||||
"<motion enabled=\"true\" ip=\"dbox\" port=\"20777\" />" +
|
||||
"<udp enabled=\"false\" extradata=\"0\" ip=\"127.0.0.1\" port=\"20777\" delay=\"1\" /></x>"
|
||||
assertTrue(TelemetryOutput.element(xml)!!.value.startsWith("<udp "))
|
||||
val on = TelemetryOutput.turnedOn(xml)!!
|
||||
assertTrue(on.contains("<udp enabled=\"true\" extradata=\"3\" ip=\"127.0.0.1\" port=\"20777\" delay=\"1\" />"))
|
||||
assertTrue(on.contains("<motion enabled=\"true\" ip=\"dbox\" port=\"20777\" />"))
|
||||
assertNull(TelemetryOutput.element("<x><motion_platform enabled=\"true\" /></x>"))
|
||||
}
|
||||
|
||||
@Test fun turningOffPutsTheOriginalLineBackOrSwitchesItOff() {
|
||||
val on = TelemetryOutput.turnedOn(showdown)!!
|
||||
assertEquals(showdown, TelemetryOutput.turnedOff(on, showdown))
|
||||
assertTrue(TelemetryOutput.turnedOff(on, null)!!.contains("<motion enabled=\"false\" ip=\"127.0.0.1\""))
|
||||
}
|
||||
|
||||
@Test fun missingAttributesAreAdded() {
|
||||
assertEquals("<udp enabled=\"true\" ip=\"127.0.0.1\" />", TelemetryOutput.withAttr("<udp enabled=\"true\" />", "ip", "127.0.0.1"))
|
||||
assertEquals("<udp a=\"1\" port=\"20777\">", TelemetryOutput.withAttr("<udp a=\"1\">", "port", "20777"))
|
||||
assertTrue(TelemetryOutput.pointsHere("<udp enabled=\"true\" ip=\"127.0.0.1\" port=\"20777\" />"))
|
||||
}
|
||||
|
||||
@Test fun scanFindsTheGameAndARoundTripRestoresTheFile() {
|
||||
val compatdata = tmp.newFolder("steamapps", "compatdata")
|
||||
val config = configFile(compatdata, "2848447563", "DiRT Showdown")
|
||||
config.writeText(showdown)
|
||||
configFile(compatdata, "12345", "Some Other Game").writeText("<hardware_settings_config />")
|
||||
|
||||
val games = TelemetryOutput.scan(listOf(compatdata))
|
||||
assertEquals(listOf("DiRT Showdown"), games.map { it.name })
|
||||
assertEquals("2848447563", games[0].prefixId)
|
||||
assertFalse(games[0].on)
|
||||
|
||||
assertTrue(TelemetryOutput.set(games[0], true))
|
||||
assertTrue(File(config.path + TelemetryOutput.ORIGINAL_SUFFIX).isFile)
|
||||
assertTrue(TelemetryOutput.scan(listOf(compatdata))[0].on)
|
||||
|
||||
assertTrue(TelemetryOutput.set(games[0], false))
|
||||
assertEquals(showdown, config.readText())
|
||||
assertFalse(File(config.path + TelemetryOutput.ORIGINAL_SUFFIX).exists())
|
||||
assertFalse(TelemetryOutput.scan(listOf(compatdata))[0].on)
|
||||
}
|
||||
|
||||
@Test fun theRunningGameIsMatchedByItsPrefixId() {
|
||||
assertTrue(TelemetryOutput.isRunning("2848447563", "2848447563"))
|
||||
assertTrue(TelemetryOutput.isRunning("-1446519733", "2848447563"))
|
||||
assertFalse(TelemetryOutput.isRunning("2848447563", "690790"))
|
||||
assertFalse(TelemetryOutput.isRunning("2848447563", null))
|
||||
assertTrue(TelemetryOutput.isRunning("2848447563", "program:/games/x.exe"))
|
||||
}
|
||||
|
||||
@Test fun automaticSkipsGamesThatAreOnSwitchedOffOrRunning() {
|
||||
val f = File("x")
|
||||
val dirt4 = TelemetryOutput.Game("DiRT 4", "421020", f, on = false)
|
||||
val rally = TelemetryOutput.Game("DiRT Rally 2.0", "690790", f, on = false)
|
||||
val grid = TelemetryOutput.Game("GRID", "703860", f, on = true)
|
||||
val games = listOf(dirt4, rally, grid)
|
||||
assertEquals(listOf(dirt4, rally), TelemetryOutput.automaticTargets(games, emptySet(), null))
|
||||
assertEquals(listOf(rally), TelemetryOutput.automaticTargets(games, setOf("421020/DiRT 4"), null))
|
||||
assertEquals(listOf(dirt4), TelemetryOutput.automaticTargets(games, emptySet(), "690790"))
|
||||
assertEquals("690790/DiRT Rally 2.0", TelemetryOutput.key(rally))
|
||||
}
|
||||
|
||||
@Test fun switchingAutomaticOffRestoresOnlyGamesDroidDeckChanged() {
|
||||
val compatdata = tmp.newFolder("steamapps", "compatdata")
|
||||
val changed = configFile(compatdata, "2848447563", "DiRT Showdown").apply { writeText(showdown) }
|
||||
val own = configFile(compatdata, "690790", "DiRT Rally 2.0")
|
||||
.apply { writeText("<x><udp enabled=\"true\" ip=\"127.0.0.1\" port=\"20777\" /></x>") }
|
||||
assertTrue(TelemetryOutput.set(TelemetryOutput.scan(listOf(compatdata)).first { it.name == "DiRT Showdown" }, true))
|
||||
val targets = TelemetryOutput.restoreTargets(TelemetryOutput.scan(listOf(compatdata)), null)
|
||||
assertEquals(listOf(changed), targets.map { it.file })
|
||||
assertTrue(own.isFile)
|
||||
assertTrue(TelemetryOutput.restoreTargets(TelemetryOutput.scan(listOf(compatdata)), "2848447563").isEmpty())
|
||||
}
|
||||
|
||||
@Test fun automaticTurnsOnDirt3AndShowdownLikeTheOtherGames() {
|
||||
val f = File("x")
|
||||
val showdownGame = TelemetryOutput.Game("DiRT Showdown", "2848447563", f, on = false)
|
||||
val dirt3 = TelemetryOutput.Game("DiRT3", "321040", f, on = false)
|
||||
val rally = TelemetryOutput.Game("DiRT Rally 2.0", "690790", f, on = false)
|
||||
assertEquals(listOf(showdownGame, dirt3, rally), TelemetryOutput.automaticTargets(listOf(showdownGame, dirt3, rally), emptySet(), null))
|
||||
assertEquals(listOf(rally), TelemetryOutput.automaticTargets(listOf(showdownGame, dirt3, rally), setOf("2848447563/DiRT Showdown", "321040/DiRT3"), null))
|
||||
}
|
||||
|
||||
private fun configFile(compatdata: File, id: String, game: String): File =
|
||||
File(compatdata, "$id/pfx/drive_c/users/steamuser/Documents/My Games/$game/hardwaresettings/hardware_settings_config.xml")
|
||||
.apply { parentFile!!.mkdirs() }
|
||||
}
|
||||
Reference in new issue
Block a user