mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-20 21:35:59 +00:00
cleanup (#764)
This commit is contained in:
1 parent
5fd47421f9
commit
aecd2ebe1d
852 files changed
+4844
-46144
No files matched your search
@@ -13,7 +13,6 @@ import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.annotation.Config
|
||||
|
||||
/** The Games tab's +: one picked .exe becomes a game, once, wherever the session can see it. */
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [33])
|
||||
class AddedExesTest {
|
||||
@@ -54,7 +53,6 @@ class AddedExesTest {
|
||||
assertEquals(Library.ADDED, game.source)
|
||||
assertTrue(File(app.filesDir, "session/added-games.json").readText().contains("Celeste.exe"))
|
||||
|
||||
// The same exe again: the game it already is, no second entry.
|
||||
val again = AddedGames.addExe(app, pick)
|
||||
assertTrue(again is AddedGames.AddResult.Existing)
|
||||
assertEquals(game.appId, (again as AddedGames.AddResult.Existing).game.appId)
|
||||
@@ -83,7 +81,6 @@ class AddedExesTest {
|
||||
val result = AddedGames.addExe(app, deep)
|
||||
assertTrue(result is AddedGames.AddResult.Switched)
|
||||
assertEquals(deep.path, AddedGames.scan(app).single().exe.path)
|
||||
// The Games folder's game is an entry of its own (GamesFolderMigration); no second one.
|
||||
assertEquals(listOf(File(games, "Example").path), AddedExes.list(app).map { it.folder })
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@ import java.io.File
|
||||
import java.security.SecureRandom
|
||||
import javax.crypto.spec.SecretKeySpec
|
||||
|
||||
/** Where an added game's art comes from: its own Steam appid, a matching name, SteamGridDB's key. */
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [33])
|
||||
class AddedGameArtLookupTest {
|
||||
@@ -39,7 +38,6 @@ class AddedGameArtLookupTest {
|
||||
val match = SteamMatch.resolve(app, dir.path, exe, "Palworld") { fail("searched"); null }
|
||||
assertEquals(1623730, match.appId)
|
||||
assertEquals(SteamMatch.Certainty.FILES, match.certainty)
|
||||
// The same record for everyone who asks.
|
||||
assertEquals(1623730, SteamMatch.get(app, dir.path)!!.appId)
|
||||
}
|
||||
|
||||
@@ -68,7 +66,6 @@ class AddedGameArtLookupTest {
|
||||
}
|
||||
|
||||
@Test fun aStoreResultIsTakenOnlyWhenItsNameMatches() {
|
||||
// The first result is no longer taken for being first.
|
||||
assertNull(AddedGameArt.pickStoreResult("My Obscure Game", listOf("10" to "Totally Different", "11" to "Another One")))
|
||||
assertEquals("20", AddedGameArt.pickStoreResult("Hades", listOf("19" to "Hades II Soundtrack Bundle Extra", "20" to "Hades")))
|
||||
assertEquals("30", AddedGameArt.pickStoreResult("Skyrim Special Edition Complete Edition", listOf("1" to "Unrelated", "30" to "Skyrim Special Edition")))
|
||||
@@ -95,7 +92,6 @@ class AddedGameArtLookupTest {
|
||||
assertEquals("build", SteamGridDb.pick("", "build"))
|
||||
assertEquals("build", SteamGridDb.pick(" ", "build"))
|
||||
assertEquals("", SteamGridDb.pick("", ""))
|
||||
// This test build carries no key.
|
||||
assertEquals("", SteamGridDb.builtInKey())
|
||||
assertEquals("", SteamGridDb.key(app))
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.annotation.Config
|
||||
import java.io.File
|
||||
|
||||
/** "Add all games in this folder", the editor's writes to the shortcut listing, art choices. */
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [33])
|
||||
class AddedGameEditsTest {
|
||||
@@ -52,14 +51,11 @@ class AddedGameEditsTest {
|
||||
val alpha = result.added.first { it.name == "Alpha" }
|
||||
assertEquals("Alpha.exe", alpha.exe.name)
|
||||
assertFalse(alpha.exeUncertain)
|
||||
// Two lookalikes: the best guess, marked.
|
||||
assertTrue(result.added.first { it.name == "Beta" }.exeUncertain)
|
||||
// Entries, not a Games folder.
|
||||
assertEquals(emptyList<String>(), SessionPrefs.addedGamesDirs(app))
|
||||
assertEquals(3, AddedExes.list(app).size)
|
||||
assertTrue(listing().map { it.getString("name") }.containsAll(listOf("Alpha", "Beta", "Celeste")))
|
||||
|
||||
// Again: nothing new, all three there already.
|
||||
val again = AddedGames.addFolder(app, dir)
|
||||
assertEquals(emptyList<String>(), again.added.map { it.name })
|
||||
assertEquals(3, again.already)
|
||||
@@ -84,7 +80,6 @@ class AddedGameEditsTest {
|
||||
assertEquals(game.appId, entry.getLong("appid"))
|
||||
assertEquals(game.appId, AddedGameEdits.game(app, folder)!!.appId)
|
||||
|
||||
// Back to automatic.
|
||||
AddedGameEdits.setName(app, folder, "")
|
||||
assertTrue(AddedGameEdits.setStartIn(app, folder, ""))
|
||||
val auto = listing().single()
|
||||
@@ -109,8 +104,6 @@ class AddedGameEditsTest {
|
||||
assertEquals("/g/Game/data", SessionPrefs.addedGameStartIn(app, folder.path))
|
||||
assertEquals("-safe", SessionPrefs.addedGameLaunch(app, folder.path))
|
||||
|
||||
// The user renames it in the app before Steam's shortcut is written again: the same Steam
|
||||
// value is not taken a second time.
|
||||
SessionPrefs.setAddedGameName(app, folder.path, "Mine")
|
||||
AddedGames.adoptSteamEdits(app, folder, record)
|
||||
assertEquals("Mine", SessionPrefs.addedGameName(app, folder.path))
|
||||
|
||||
@@ -13,7 +13,6 @@ import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.annotation.Config
|
||||
|
||||
/** The .exe picker below a game folder (five levels, past installer folders, ranked) and the names it finds. */
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [33])
|
||||
class AddedGamesCandidatesTest {
|
||||
@@ -65,7 +64,6 @@ class AddedGamesCandidatesTest {
|
||||
val game = tmp.newFolder("Huge")
|
||||
for (i in 0 until GameExePicker.WALK_BUDGET + 50) File(game, "data/d%04d".format(i)).mkdirs()
|
||||
exe(game, "zzz/Late.exe")
|
||||
// data/ alone fills the budget before zzz/ is listed.
|
||||
assertEquals(emptyList<String>(), names(game))
|
||||
val small = tmp.newFolder("Small")
|
||||
exe(small, "x/y/Found.exe")
|
||||
@@ -136,7 +134,6 @@ class AddedGamesCandidatesTest {
|
||||
game.setLastModified(game.lastModified() + 10_000)
|
||||
val after = AddedGames.scan(app).single()
|
||||
assertEquals("The Witcher 3 - Wild Hunt", after.name)
|
||||
// Already added under the folder name: the shortcut keeps its id.
|
||||
assertEquals(before.appId, after.appId)
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@ import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.annotation.Config
|
||||
|
||||
/** Removing an added game stops listing it and keeps it off after a rescan, until it is added again; nothing on disk goes. */
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [33])
|
||||
class AddedGamesRemoveTest {
|
||||
@@ -47,7 +46,6 @@ class AddedGamesRemoveTest {
|
||||
|
||||
SessionPrefs.setAddedGameRemoved(app, File(games, "Beta").path, true)
|
||||
assertEquals(listOf("Alpha", "Gamma"), AddedGames.scan(app).map { it.name })
|
||||
// A rescan does not bring it back.
|
||||
assertEquals(listOf("Alpha", "Gamma"), AddedGames.scan(app).map { it.name })
|
||||
|
||||
SessionPrefs.setAddedGameRemoved(app, File(games, "Beta").path, false)
|
||||
@@ -66,7 +64,6 @@ class AddedGamesRemoveTest {
|
||||
assertTrue(!listing.contains("\"Beta\""))
|
||||
assertTrue(File(beta, "Beta.exe").isFile)
|
||||
|
||||
// Added again with the +: it comes back.
|
||||
assertTrue(AddedGames.addExe(app, File(beta, "Beta.exe")) is AddedGames.AddResult.Switched)
|
||||
assertEquals(emptyList<String>(), SessionPrefs.removedAddedGames(app))
|
||||
assertTrue(File(app.filesDir, "session/added-games.json").readText().contains("\"Beta\""))
|
||||
|
||||
@@ -13,7 +13,6 @@ import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.annotation.Config
|
||||
|
||||
/** A store install is one more folder the scan finds, named and aimed by its sidecar. */
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [33])
|
||||
class AddedGamesStoreScanTest {
|
||||
@@ -38,7 +37,6 @@ class AddedGamesStoreScanTest {
|
||||
assertEquals("HOMM3.exe", game.exe.name)
|
||||
assertEquals(Store.GOG.id, game.source)
|
||||
assertEquals("1207658924", game.storeId)
|
||||
// Inside the runtime's tree the folder needs no bind: its guest path is its path from the tree's root.
|
||||
assertEquals("/root/Games/Stores/GOG/Heroes of Might and Magic 3 Complete/HOMM3.exe", game.guestExe)
|
||||
assertEquals("/root/Games/Stores/GOG/Heroes of Might and Magic 3 Complete", game.guestDir)
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ class AddedGamesTest {
|
||||
"\"AppState\"\n{\n\t\"appid\"\t\t\"17410\"\n\t\"installdir\"\t\t\"Mirrors Edge\"\n}\n",
|
||||
)
|
||||
assertEquals(setOf("monster_hunter_stories_3_twisted_reflection", "mirrors edge"), AddedGames.steamInstallDirs(common))
|
||||
// Loose game folders at the library root are never Steam's.
|
||||
assertEquals(emptySet<String>(), AddedGames.steamInstallDirs(library))
|
||||
}
|
||||
}
|
||||
@@ -30,7 +30,6 @@ class GameFileSyncTest {
|
||||
assertEquals("8400", File(folder, "Geometry Wars.steam").readText())
|
||||
assertEquals(folder.path, GameFileSync.folder(context))
|
||||
assertEquals(1, folder.listFiles()!!.count { it.extension == GameFiles.EXTENSION })
|
||||
// An unavailable source must leave the existing export intact.
|
||||
val unavailable = File(steamapps.parentFile, "steamapps-unavailable")
|
||||
assertTrue(steamapps.renameTo(unavailable))
|
||||
assertThrows(IllegalStateException::class.java) { GameFileSync.syncConfigured(context) }
|
||||
@@ -38,11 +37,9 @@ class GameFileSyncTest {
|
||||
assertTrue(unavailable.renameTo(steamapps))
|
||||
GameFileSync.syncConfigured(context)
|
||||
assertTrue(File(folder, "Geometry Wars.steam").exists())
|
||||
// A genuine uninstall removes the owned export at the next tick.
|
||||
assertTrue(manifest.delete())
|
||||
GameFileSync.syncConfigured(context)
|
||||
assertEquals(0, folder.listFiles()!!.count { it.extension == GameFiles.EXTENSION })
|
||||
// Disabled sync does not write files for new installs.
|
||||
GameFileSync.disable(context)
|
||||
manifest.writeText("\"name\" \"Geometry Wars\"\n\"StateFlags\" \"4\"")
|
||||
GameFileSync.syncConfigured(context)
|
||||
|
||||
@@ -38,7 +38,6 @@ class GameFilesTest {
|
||||
val provider = LaunchFileProvider(file)
|
||||
provider.attachInfo(context, android.content.pm.ProviderInfo().apply { authority = "frontend" })
|
||||
ShadowContentResolver.registerProviderInternal("frontend", provider)
|
||||
// Providers often give opaque document IDs with no filename extension.
|
||||
val uri = Uri.parse("content://frontend/document/opaque%3A42")
|
||||
assertEquals("18446744073709551615", GameFiles.readIntent(context, Intent(Intent.ACTION_VIEW, uri)))
|
||||
}
|
||||
|
||||
@@ -9,18 +9,13 @@ import org.junit.Test
|
||||
import org.junit.rules.TemporaryFolder
|
||||
import java.io.File
|
||||
|
||||
/**
|
||||
* Signal-chain coverage for [GameIdentifier]. Pure JVM: builds
|
||||
* fake game layouts in a temp dir and asserts the right appId/name/source/confidence come back.
|
||||
* The PE version-resource path is exercised on-device (real .exe), not here.
|
||||
*/
|
||||
class GameIdentifierTest {
|
||||
|
||||
@get:Rule
|
||||
val tmp = TemporaryFolder()
|
||||
|
||||
private fun exeIn(dir: File, name: String = "game.exe"): File =
|
||||
File(dir, name).apply { parentFile?.mkdirs(); writeBytes(byteArrayOf(0x4D, 0x5A)) } // "MZ" — not a real PE
|
||||
File(dir, name).apply { parentFile?.mkdirs(); writeBytes(byteArrayOf(0x4D, 0x5A)) }
|
||||
|
||||
@Test
|
||||
fun steamAppIdTxt_besideExe_givesHighConfidenceAppId() {
|
||||
@@ -51,7 +46,6 @@ class GameIdentifierTest {
|
||||
|
||||
@Test
|
||||
fun steamManifestAcf_matchedByInstalldir_givesAppIdAndName() {
|
||||
// steamapps/common/Palworld/Pal/Binaries/Win64/Palworld-Win64-Shipping.exe
|
||||
val steamapps = tmp.newFolder("steamapps")
|
||||
File(steamapps, "appmanifest_1623730.acf").writeText(
|
||||
"""
|
||||
@@ -63,7 +57,6 @@ class GameIdentifierTest {
|
||||
}
|
||||
""".trimIndent()
|
||||
)
|
||||
// a decoy manifest that must NOT win
|
||||
File(steamapps, "appmanifest_570.acf").writeText(
|
||||
""""AppState" { "appid" "570" "name" "Dota 2" "installdir" "dota 2 beta" }"""
|
||||
)
|
||||
@@ -81,9 +74,6 @@ class GameIdentifierTest {
|
||||
"""{"gameId":"1207658691","name":"The Witcher 3: Wild Hunt","version":1}"""
|
||||
)
|
||||
val id = GameIdentifier.identify(exeIn(dir))
|
||||
// normalizeName() deliberately converts ":" to " - " (a colon is illegal in a Windows
|
||||
// filename), so the identified name never carries one. The test asserted the raw GOG
|
||||
// string and had never passed.
|
||||
assertEquals("The Witcher 3 - Wild Hunt", id.name)
|
||||
assertEquals("1207658691", id.gogId)
|
||||
assertNull(id.appId)
|
||||
@@ -103,7 +93,6 @@ class GameIdentifierTest {
|
||||
|
||||
@Test
|
||||
fun noMarkers_fallsBackToCleanedFolderName_forEngineBinary() {
|
||||
// UE shipping binary → the folder name is the real title, exe basename is noise.
|
||||
val dir = tmp.newFolder("Hades")
|
||||
val id = GameIdentifier.identify(exeIn(dir, "Hades-Win64-Shipping.exe"))
|
||||
assertEquals("Hades", id.name)
|
||||
@@ -115,18 +104,16 @@ class GameIdentifierTest {
|
||||
fun fallbackName_stripsRepackTagsAndVersionTokens() {
|
||||
val dir = tmp.newFolder("Stardew Valley [FitGirl Repack] v1.5.4")
|
||||
val id = GameIdentifier.identify(exeIn(dir, "Stardew.exe"))
|
||||
assertEquals("Stardew", id.name) // exe basename wins (not an engine binary); folder tags irrelevant here
|
||||
// and a repack-style exe basename is cleaned too:
|
||||
assertEquals("Stardew", id.name)
|
||||
val id2 = GameIdentifier.identify(exeIn(tmp.newFolder("g2"), "Game.CODEX.exe"))
|
||||
assertEquals(GameIdentifier.Source.FILENAME, id2.source)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun fltIni_gameSettingsAppId_isParsed() {
|
||||
// Real God of War (FLT release) layout: flt.ini holds the appid under [GameSettings].
|
||||
val dir = tmp.newFolder("GodOfWar")
|
||||
File(dir, "flt.ini").writeText("[GameSettings]\nAppId=1593500\nUserName=X\nBuildId=7969425\n")
|
||||
File(dir, "settings.ini").writeText("[Settings]\nVideoDevice=Wrapper\nMonitor=0\n") // no AppId -> ignored
|
||||
File(dir, "settings.ini").writeText("[Settings]\nVideoDevice=Wrapper\nMonitor=0\n")
|
||||
val id = GameIdentifier.identify(exeIn(dir, "GoW.exe"))
|
||||
assertEquals(1593500, id.appId)
|
||||
assertEquals(GameIdentifier.Confidence.HIGH, id.confidence)
|
||||
@@ -141,12 +128,10 @@ class GameIdentifierTest {
|
||||
|
||||
@Test
|
||||
fun bestName_prefersFileDescriptionWhenProductNameIsAbbreviation() {
|
||||
// God of War ships ProductName "GoW" but FileDescription "God of War".
|
||||
assertEquals(
|
||||
"God of War",
|
||||
PeVersionInfo.bestName(mapOf("ProductName" to "GoW", "FileDescription" to "God of War")),
|
||||
)
|
||||
// Normal case: ProductName is the full title -> keep it.
|
||||
assertEquals(
|
||||
"Cyberpunk 2077",
|
||||
PeVersionInfo.bestName(mapOf("ProductName" to "Cyberpunk 2077", "FileDescription" to "Cyberpunk 2077")),
|
||||
@@ -156,18 +141,15 @@ class GameIdentifierTest {
|
||||
|
||||
@Test
|
||||
fun name_isNormalizedToBeFilesystemSafeAndTidy() {
|
||||
// Colon → " - " (would otherwise be sanitized to '_' by the shortcut writer).
|
||||
val d1 = tmp.newFolder("ds")
|
||||
File(d1, "goggame-1.info").writeText("""{"name":"Dark Souls: Remastered"}""")
|
||||
assertEquals("Dark Souls - Remastered", GameIdentifier.identify(exeIn(d1)).name)
|
||||
// Trademark marks (symbol and text forms) stripped.
|
||||
val d2 = tmp.newFolder("gow2")
|
||||
File(d2, "goggame-2.info").writeText("""{"name":"God of War™"}""")
|
||||
assertEquals("God of War", GameIdentifier.identify(exeIn(d2)).name)
|
||||
val d3 = tmp.newFolder("ds3")
|
||||
File(d3, "goggame-3.info").writeText("""{"name":"DARK SOULS(TM): REMASTERED"}""")
|
||||
assertEquals("DARK SOULS - REMASTERED", GameIdentifier.identify(exeIn(d3)).name)
|
||||
// Trailing PE descriptors dropped (DiRT 3's FileDescription is "DiRT 3 Executable").
|
||||
val d4 = tmp.newFolder("dirt")
|
||||
File(d4, "goggame-4.info").writeText("""{"name":"DiRT 3 Executable"}""")
|
||||
assertEquals("DiRT 3", GameIdentifier.identify(exeIn(d4)).name)
|
||||
@@ -175,8 +157,6 @@ class GameIdentifierTest {
|
||||
|
||||
@Test
|
||||
fun launcherExe_prefersFolderName_overLauncher() {
|
||||
// GTA V Enhanced: user picks the Rockstar launcher PlayGTAV.exe (no Steam id, PE = junk on
|
||||
// a real exe). Fallback must use the folder title, not "PlayGTAV".
|
||||
val dir = tmp.newFolder("Grand Theft Auto V Enhanced")
|
||||
val id = GameIdentifier.identify(exeIn(dir, "PlayGTAV.exe"))
|
||||
assertEquals("Grand Theft Auto V Enhanced", id.name)
|
||||
@@ -187,12 +167,11 @@ class GameIdentifierTest {
|
||||
fun launcherExe_withSeparator_prefersFolder_andStripsSiteTag() {
|
||||
val dir = tmp.newFolder("Grand-Theft-Auto-IV-AnkerGames")
|
||||
val id = GameIdentifier.identify(exeIn(dir, "Play - GTA IV.exe"))
|
||||
assertEquals("Grand Theft Auto IV", id.name) // "AnkerGames" site tag stripped
|
||||
assertEquals("Grand Theft Auto IV", id.name)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun nonLauncherExe_startingWithPlay_keepsItsOwnName() {
|
||||
// "PlayerUnknown" must NOT be treated as a launcher (would wrongly use the folder name).
|
||||
val dir = tmp.newFolder("SomeInstallFolder")
|
||||
val id = GameIdentifier.identify(exeIn(dir, "PlayerUnknown.exe"))
|
||||
assertEquals("PlayerUnknown", id.name)
|
||||
@@ -211,8 +190,7 @@ class GameIdentifierTest {
|
||||
@Test
|
||||
fun emptyWhenNothingIdentifiable() {
|
||||
val dir = tmp.newFolder("x")
|
||||
val id = GameIdentifier.identify(exeIn(dir, "Game.exe")) // engine-ish base → folder "x"
|
||||
// "x" is a valid (if useless) fallback name; the point is it must not crash and appId is null.
|
||||
val id = GameIdentifier.identify(exeIn(dir, "Game.exe"))
|
||||
assertNull(id.appId)
|
||||
assertTrue(id.confidence == GameIdentifier.Confidence.LOW)
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@ import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.annotation.Config
|
||||
|
||||
/** Games folders from earlier builds become entries, every game keeping what it had. */
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [33])
|
||||
class GamesFolderMigrationTest {
|
||||
@@ -40,7 +39,6 @@ class GamesFolderMigrationTest {
|
||||
StoreGameSidecar.file(store).writeText("""{"store":"gog","id":"1","title":"Store Game","exe":"Store.exe"}""")
|
||||
File(pc, "Notes").mkdirs()
|
||||
SessionPrefs.setAddedGamesDirs(app, listOf(pc.path))
|
||||
// What earlier scans had kept, by folder.
|
||||
SessionPrefs.setAddedGameExe(app, beta.path, pick.path)
|
||||
SessionPrefs.addedGameAppId(app, alpha.path, 0x8123_4567L)
|
||||
SessionPrefs.addedGameAppId(app, beta.path, 0x8765_4321L)
|
||||
@@ -63,11 +61,9 @@ class GamesFolderMigrationTest {
|
||||
assertEquals(0x8765_4321L, games.getValue(beta.path).appId)
|
||||
assertEquals("Alpha GOTY", games.getValue(alpha.path).name)
|
||||
assertEquals(pick.path, games.getValue(beta.path).exe.path)
|
||||
// The same path inside the session as before: the shortcut keeps its target.
|
||||
assertEquals(AddedGames.GUEST_DIR + "/PC/Alpha/Alpha.exe", games.getValue(alpha.path).guestExe)
|
||||
assertEquals(AddedGames.GUEST_DIR + "/PC/Beta/bin/Beta64.exe", games.getValue(beta.path).guestExe)
|
||||
assertTrue(SessionPrefs.removedAddedGames(app).contains(gone.path))
|
||||
// Not a library any more.
|
||||
assertTrue(GameStorage.gamesFolderLibraries(app).isEmpty())
|
||||
}
|
||||
|
||||
|
||||
@@ -17,13 +17,11 @@ import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.annotation.Config
|
||||
|
||||
/** Steam's app info asked anonymously: the answer read, batched, kept, and asked only when needed. */
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [33])
|
||||
class SteamPicsTest {
|
||||
private val app get() = RuntimeEnvironment.getApplication()
|
||||
|
||||
/** Dragon's Dogma 2's app info as Steam's anonymous PICS answer carried it (recorded 2026-10-10). */
|
||||
private val recorded: String get() = javaClass.classLoader!!.getResource("steam-pics/app_2054970.vdf")!!.readText()
|
||||
|
||||
@After fun tearDown() { SteamAppInfo.pics = { SteamPics.lookup(it) } }
|
||||
@@ -32,7 +30,6 @@ class SteamPicsTest {
|
||||
val info = SteamPics.infoFromKeyValues(recorded)!!
|
||||
assertEquals("Dragon's Dogma 2", info.name)
|
||||
assertEquals(listOf("228988"), info.sharedDepots)
|
||||
// VC++ 2019 for the Windows components.
|
||||
assertEquals(listOf("vcredist2019_dll" to "VC++ 2019"), WinCompSources.steamDepots(info.sharedDepots))
|
||||
}
|
||||
|
||||
@@ -66,11 +63,9 @@ class SteamPicsTest {
|
||||
val calls = ArrayList<List<Int>>()
|
||||
SteamAppInfo.pics = { ids -> calls.add(ids); mapOf(2054970 to SteamPics.infoFromKeyValues(recorded), 7 to null) }
|
||||
assertTrue(SteamAppInfo.lookup(app, listOf(2054970, 7)))
|
||||
// One connection for both.
|
||||
assertEquals(listOf(listOf(2054970, 7)), calls)
|
||||
assertEquals(listOf("228988"), SteamAppInfo.info(app, 2054970)!!.sharedDepots)
|
||||
assertNull(SteamAppInfo.info(app, 7))
|
||||
// Kept: nothing asked again (the miss waits a week).
|
||||
assertFalse(SteamAppInfo.lookup(app, listOf(2054970, 7)))
|
||||
assertEquals(1, calls.size)
|
||||
assertEquals("hit", SteamAppInfo.state(app, 2054970))
|
||||
@@ -78,7 +73,6 @@ class SteamPicsTest {
|
||||
}
|
||||
|
||||
@Test fun noNetworkWhenTheClientsCacheHasTheApp() {
|
||||
// An appinfo.vdf with the app in it (built as in WinCompSourcesTest).
|
||||
val file = SteamAppInfo.appinfoFile(app)
|
||||
WinCompSourcesTest.writeAppinfo(file, 1145360)
|
||||
SteamAppInfo.pics = { fail("asked Steam"); null }
|
||||
|
||||
@@ -20,7 +20,6 @@ import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.annotation.Config
|
||||
|
||||
/** Each source's list of Windows components, how it maps to the catalog, and what turns on by itself. */
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [33])
|
||||
class WinCompSourcesTest {
|
||||
@@ -35,7 +34,6 @@ class WinCompSourcesTest {
|
||||
|
||||
private fun auto(findings: List<WinCompSources.Finding>) = findings.filter { it.auto }.map { it.component to it.origin }
|
||||
|
||||
// ---- mapping tables ----
|
||||
|
||||
@Test fun gogDependencyIdsMapToComponents() {
|
||||
assertEquals(listOf("vcredist2015"), WinCompSources.gog("MSVC2017_x64"))
|
||||
@@ -62,7 +60,6 @@ class WinCompSourcesTest {
|
||||
assertEquals(listOf("vcredist2015_dll" to "VC++ 2015", "d3dx9" to "DirectX (June 2010)"), WinCompSources.steamDepots(listOf("228986", "228990", "999")))
|
||||
}
|
||||
|
||||
// ---- per source ----
|
||||
|
||||
@Test fun steamTakesItsSharedDepotsAndTurnsThemOn() {
|
||||
val steamapps = tmp.newFolder("steamapps")
|
||||
@@ -80,7 +77,6 @@ class WinCompSourcesTest {
|
||||
sidecar(folder, Store.GOG, mapOf(WinCompSources.GOG_DEPENDENCIES to "MSVC2017_x64,DirectX,ISI"))
|
||||
val findings = WinCompSources.forGame(app, game(folder, "gog"))
|
||||
assertEquals(listOf("vcredist2015" to WinCompSources.Origin.GOG, "d3dx9" to WinCompSources.Origin.GOG), auto(findings))
|
||||
// ISI is none of ours: a suggestion under its own name.
|
||||
assertEquals(listOf("ISI"), findings.filter { it.component == null }.map { it.original })
|
||||
}
|
||||
|
||||
@@ -105,12 +101,10 @@ class WinCompSourcesTest {
|
||||
assertEquals(listOf("Activate.exe"), findings.filter { it.component == null }.map { it.original })
|
||||
}
|
||||
|
||||
// ---- Custom: certainty decides ----
|
||||
|
||||
private fun appinfo(file: File, appId: Int) = writeAppinfo(file, appId)
|
||||
|
||||
companion object {
|
||||
/** A version 29 appinfo.vdf with one app, whose depots point at two Steamworks Shared ones. */
|
||||
fun writeAppinfo(file: File, appId: Int) {
|
||||
val strings = listOf("appinfo", "common", "name", "depots", "228986", "depotfromapp", "228990", "1001", "maxsize")
|
||||
fun key(s: String) = ByteBuffer.allocate(4).order(ByteOrder.LITTLE_ENDIAN).putInt(strings.indexOf(s)).array()
|
||||
@@ -173,7 +167,6 @@ class WinCompSourcesTest {
|
||||
assertEquals(listOf("vcredist2013" to WinCompSources.Origin.FOLDER), findings.map { it.component to it.origin })
|
||||
}
|
||||
|
||||
// ---- what turns on, and the user's switches ----
|
||||
|
||||
private fun ready(name: String) = WinComponents.Component(name, "", "", "ready", emptyList(),
|
||||
listOf(WinComponents.Step("override_dll", JSONObject().put("dll", "x").put("type", "native"))))
|
||||
@@ -187,7 +180,6 @@ class WinCompSourcesTest {
|
||||
WinCompSources.Finding("d3dx9", "d3dx9_43.dll", WinCompSources.Origin.FOLDER, false),
|
||||
)
|
||||
val picks = AutoComponents.autoPicks(findings, catalog)
|
||||
// The detector's name installs as its DLL twin; physx cannot install; the folder scan only recommends.
|
||||
assertEquals(listOf("vcredist2015_dll"), picks.keys.toList())
|
||||
assertEquals("GOG", picks.getValue("vcredist2015_dll").kind)
|
||||
}
|
||||
@@ -199,11 +191,9 @@ class WinCompSourcesTest {
|
||||
WinComponents.setUser(app, key, "d3dx9", false)
|
||||
WinComponents.setUser(app, key, "oalinst_dll", true)
|
||||
assertEquals(listOf("xact", "oalinst_dll"), WinComponents.picks(app, key))
|
||||
// A new automatic list keeps the user's switches.
|
||||
WinComponents.setAuto(app, key, mapOf("d3dx9" to WinComponents.AutoReason("GOG", listOf("DirectX"))))
|
||||
assertEquals(listOf("oalinst_dll"), WinComponents.picks(app, key))
|
||||
assertEquals(mapOf("d3dx9" to false, "oalinst_dll" to true), WinComponents.selection(app, key).user)
|
||||
// What the launch reads stays version 1 with the effective list.
|
||||
val text = File(app.filesDir, "wincomponents.json").readText()
|
||||
assertEquals(1, JSONObject(text).getInt("version"))
|
||||
assertEquals("oalinst_dll", JSONObject(text).getJSONObject("games").getJSONArray(key).getString(0))
|
||||
@@ -219,10 +209,8 @@ class WinCompSourcesTest {
|
||||
val folder = tmp.newFolder("Shared")
|
||||
val exe = File(folder, "Shared.exe").apply { writeText("x") }
|
||||
val art = AddedGames.Game(folder, "Shared", exe, "/g/Shared.exe", "/g", 0x81234567L, 0L, emptyList())
|
||||
// The art fetch finds it by name ...
|
||||
val match = AddedGameArt.steamMatch(app, art) { 4242 }
|
||||
assertEquals(4242, match.appId)
|
||||
// ... and the components read the same record.
|
||||
assertEquals(4242, SteamMatch.get(app, folder.path)!!.appId)
|
||||
assertEquals(SteamMatch.Certainty.NAME, SteamMatch.get(app, folder.path)!!.certainty)
|
||||
assertFalse(WinCompSources.forGame(app, game(folder, Library.ADDED)).any { it.auto })
|
||||
@@ -268,7 +256,6 @@ class WinCompSourcesTest {
|
||||
@Test fun aSteamListedComponentNotYetDownloadedTurnsOnWhenItLands() = withFakeWorker {
|
||||
installedNow.add("d3dx9")
|
||||
val game = payback()
|
||||
// The user had switched one off: it is never downloaded for an automatic pick.
|
||||
WinComponents.setUser(app, "1262580", "vcredist2019_dll", false)
|
||||
AutoComponents.queueGame(app, game, asked = true)
|
||||
assertEquals(listOf("vcredist2013_dll"), downloaded)
|
||||
@@ -276,7 +263,6 @@ class WinCompSourcesTest {
|
||||
assertEquals(setOf("d3dx9", "vcredist2013_dll", "vcredist2019_dll"), sel.auto.keys)
|
||||
assertEquals(setOf("d3dx9", "vcredist2013_dll"), WinComponents.picks(app, "1262580").toSet())
|
||||
assertEquals("STEAM", sel.auto.getValue("vcredist2013_dll").kind)
|
||||
// The list is kept for the page.
|
||||
assertEquals(3, AutoComponents.cachedFindings(app, "1262580")!!.count { it.auto })
|
||||
}
|
||||
|
||||
@@ -297,7 +283,6 @@ class WinCompSourcesTest {
|
||||
AutoComponents.unfavourable = { true }
|
||||
AutoComponents.queueGame(app, game, asked = false)
|
||||
assertTrue(downloaded.isEmpty())
|
||||
// The user opens the page: asked for, it goes.
|
||||
AutoComponents.queueGame(app, game, asked = true)
|
||||
assertEquals(3, downloaded.size)
|
||||
}
|
||||
@@ -311,7 +296,6 @@ class WinCompSourcesTest {
|
||||
assertEquals(listOf("g:1262580"), AutoComponents.queued())
|
||||
session = false
|
||||
AutoComponents.drain(app)
|
||||
// Each component once, though two games could want it.
|
||||
assertEquals(downloaded.distinct(), downloaded)
|
||||
}
|
||||
|
||||
@@ -319,7 +303,6 @@ class WinCompSourcesTest {
|
||||
val game = payback()
|
||||
AutoComponents.online = { false }
|
||||
AutoComponents.queueGame(app, game, asked = true)
|
||||
// The list is worked out offline; the downloads wait.
|
||||
assertTrue(downloaded.isEmpty())
|
||||
assertTrue(AutoComponents.queued().all { it.startsWith("c:") })
|
||||
AutoComponents.online = { true }
|
||||
@@ -327,7 +310,6 @@ class WinCompSourcesTest {
|
||||
assertEquals(3, downloaded.size)
|
||||
}
|
||||
|
||||
// ---- older store installs: the list read once from the store ----
|
||||
|
||||
@Test fun anOlderGogInstallGetsItsListFromTheStoreOnce() {
|
||||
val folder = tmp.newFolder("DOOM I Enhanced")
|
||||
@@ -338,7 +320,6 @@ class WinCompSourcesTest {
|
||||
try {
|
||||
assertTrue(StoreListBackfill.fill(app, folder))
|
||||
assertEquals("MSVC2019_x64,DirectX", StoreGameSidecar.read(folder)!!.extra[WinCompSources.GOG_DEPENDENCIES])
|
||||
// Kept like a fresh install: not fetched again.
|
||||
assertFalse(StoreListBackfill.fill(app, folder))
|
||||
assertEquals(1, fetches)
|
||||
assertEquals(listOf("vcredist2019" to WinCompSources.Origin.GOG, "d3dx9" to WinCompSources.Origin.GOG), auto(WinCompSources.forGame(app, game(folder, "gog"))))
|
||||
@@ -377,7 +358,6 @@ class WinCompSourcesTest {
|
||||
AutoComponents.online = { true }
|
||||
assertFalse(StoreListBackfill.fill(app, folder))
|
||||
assertFalse(StoreListBackfill.fill(app, folder))
|
||||
// Signed out or the store refused: once, then a week's rest; the sidecar is untouched.
|
||||
assertEquals(1, fetches)
|
||||
assertTrue(StoreListBackfill.needs(StoreGameSidecar.read(folder)!!))
|
||||
} finally {
|
||||
@@ -386,16 +366,13 @@ class WinCompSourcesTest {
|
||||
}
|
||||
}
|
||||
|
||||
// ---- apps the client never saw ----
|
||||
|
||||
@Test fun anAppTheClientLearnsLaterIsReadOnceItsCacheIsWritten() {
|
||||
val file = SteamAppInfo.appinfoFile(app)
|
||||
appinfo(file, 1)
|
||||
file.setLastModified(1_000_000_000_000L)
|
||||
assertEquals(null, SteamAppInfo.info(app, 1145360))
|
||||
// Unchanged file: the miss stands (no re-read).
|
||||
assertEquals(null, SteamAppInfo.info(app, 1145360))
|
||||
// The client wrote its cache with the app in it: read at once, not a week later.
|
||||
appinfo(file, 1145360)
|
||||
file.setLastModified(1_000_000_100_000L)
|
||||
assertEquals(listOf("228986", "228990"), SteamAppInfo.info(app, 1145360)!!.sharedDepots)
|
||||
@@ -418,7 +395,6 @@ class WinCompSourcesTest {
|
||||
assertTrue(StoreListBackfill.needs(StoreGameSidecar.read(older)!!))
|
||||
}
|
||||
|
||||
// ---- a game installed during the session ----
|
||||
|
||||
private fun manifest(dir: File, appId: Int, state: Int, time: Long) =
|
||||
File(dir, "appmanifest_$appId.acf").apply {
|
||||
@@ -431,7 +407,6 @@ class WinCompSourcesTest {
|
||||
manifest(steamapps, 12900, 1026, 1_000_000L)
|
||||
manifest(steamapps, 570, 4, 1_000_000L)
|
||||
val watch = SessionInstalls.Watch { listOf(steamapps) }
|
||||
// What was there when the session started is not new.
|
||||
assertTrue(watch.poll().isEmpty())
|
||||
assertTrue(watch.poll().isEmpty())
|
||||
manifest(steamapps, 12900, 4, 2_000_000L)
|
||||
@@ -448,14 +423,12 @@ class WinCompSourcesTest {
|
||||
gameUp = true
|
||||
AutoComponents.queueInSession(app, installed)
|
||||
assertTrue(downloaded.isEmpty())
|
||||
// Other work stays paused in the session.
|
||||
val other = game(tmp.newFolder("Other"), Library.ADDED)
|
||||
AutoComponents.queueGame(app, other, asked = false)
|
||||
gameUp = false
|
||||
AutoComponents.drain(app)
|
||||
assertEquals(3, downloaded.size)
|
||||
assertEquals(setOf("d3dx9", "vcredist2013_dll", "vcredist2019_dll"), WinComponents.picks(app, "1262580").toSet())
|
||||
// Nothing left pending for the launch to wait on; the other game still waits for the session's end.
|
||||
assertEquals(0, AutoComponents.Pending.read(app).length())
|
||||
assertEquals(listOf("g:${AutoComponents.appKey(other)}"), AutoComponents.queued())
|
||||
session = false
|
||||
|
||||
Reference in new issue
Block a user