mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 20:36:04 +00:00
Merge branch 'main' into fix/steam-client-download
This commit is contained in:
123 files changed
+2637
-331
No files matched your search
@@ -14,20 +14,6 @@ class ZramSupportTest {
|
||||
assertFalse(ZramSupport.kernelAtLeast("", 5, 4))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun underTwelveGbFromAdvertisedOrTotalMemory() {
|
||||
val gb = 1_000_000_000L
|
||||
val gib = 1L shl 30
|
||||
assertTrue(ZramSupport.belowTwelveGb(8 * gb, 0))
|
||||
assertTrue(ZramSupport.belowTwelveGb(8 * gib, 0))
|
||||
assertFalse(ZramSupport.belowTwelveGb(12 * gb, 0))
|
||||
assertFalse(ZramSupport.belowTwelveGb(12 * gib, 0))
|
||||
assertTrue(ZramSupport.belowTwelveGb(0, 7_400_000L * 1024))
|
||||
assertTrue(ZramSupport.belowTwelveGb(0, 9_300_000L * 1024))
|
||||
assertFalse(ZramSupport.belowTwelveGb(0, 11_100_000L * 1024))
|
||||
assertFalse(ZramSupport.belowTwelveGb(0, 15_600_380L * 1024))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun swapTotalComesFromMeminfo() {
|
||||
assertEquals(12582908L, ZramSupport.swapTotalKb(listOf("MemTotal: 15600380 kB", "SwapTotal: 12582908 kB")))
|
||||
|
||||
@@ -0,0 +1,163 @@
|
||||
package com.droiddeck.launcher.frontend
|
||||
|
||||
import com.droiddeck.launcher.frontend.AddedGameArt.Slot
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
import org.junit.Assert.assertArrayEquals
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Assert.fail
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.TemporaryFolder
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.annotation.Config
|
||||
import java.io.File
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [33])
|
||||
class AddedGameArtFillTest {
|
||||
private val app get() = RuntimeEnvironment.getApplication()
|
||||
@get:Rule val tmp = TemporaryFolder()
|
||||
|
||||
private val coverBytes = byteArrayOf(9, 9, 9)
|
||||
|
||||
private fun game(name: String, appId: Long, cover: Boolean = true, source: String = Library.ADDED): AddedGames.Game {
|
||||
val dir = tmp.newFolder(name)
|
||||
File(dir, "steam_appid.txt").writeText("504230")
|
||||
if (cover) File(dir, "cover.jpg").writeBytes(coverBytes)
|
||||
val exe = File(dir, "$name.exe").apply { writeText("x") }
|
||||
return AddedGames.Game(dir, name, exe, "/g/$name.exe", "/g", appId, appId, emptyList(), source = source)
|
||||
}
|
||||
|
||||
private class Calls {
|
||||
val steam = ArrayList<Set<Slot>>()
|
||||
val sgdb = ArrayList<Set<Slot>>()
|
||||
var lookups = 0
|
||||
var store = 0
|
||||
}
|
||||
|
||||
private val steamNames = mapOf(Slot.COVER to "p.jpg", Slot.WIDE to "header.jpg", Slot.BACKGROUND to "hero.jpg", Slot.LOGO to "logo.png")
|
||||
|
||||
private fun sources(
|
||||
calls: Calls, steamHas: Set<Slot> = emptySet(), sgdbHas: Set<Slot> = emptySet(),
|
||||
storeHas: Boolean = false, sgdbFails: Boolean = false,
|
||||
) = AddedGameArt.Sources(
|
||||
storeLogo = { g ->
|
||||
calls.store++
|
||||
if (storeHas) File(g.folder, "logo.png").writeBytes(byteArrayOf(4))
|
||||
storeHas
|
||||
},
|
||||
steamSearch = { fail("searched although the game names its appid"); null },
|
||||
steam = { id, cache, slots ->
|
||||
assertEquals("504230", id)
|
||||
calls.steam += slots
|
||||
(slots intersect steamHas).onEach { File(cache, steamNames.getValue(it)).writeBytes(byteArrayOf(1)) }.isNotEmpty()
|
||||
},
|
||||
sgdbGame = { _, steamId, _ ->
|
||||
calls.lookups++
|
||||
assertEquals(504230, steamId)
|
||||
77
|
||||
},
|
||||
sgdb = { _, id, cache, slots ->
|
||||
assertEquals(77, id)
|
||||
if (sgdbFails) throw SteamGridDb.Failed(SteamGridDb.Status.OFFLINE)
|
||||
calls.sgdb += slots
|
||||
(slots intersect sgdbHas).onEach { File(cache, SteamGridDb.cacheName(it)).writeBytes(byteArrayOf(2)) }.isNotEmpty()
|
||||
},
|
||||
)
|
||||
|
||||
@Test fun aGameWithItsOwnCoverStillGetsItsLogoAndIcon() {
|
||||
val g = game("Celeste", 0x81000001L)
|
||||
val calls = Calls()
|
||||
assertTrue(AddedGameArt.fetchMissing(app, listOf(g), "key", sources(calls, steamHas = setOf(Slot.LOGO), sgdbHas = setOf(Slot.ICON))))
|
||||
assertEquals(listOf(setOf(Slot.LOGO)), calls.steam)
|
||||
assertEquals(listOf(setOf(Slot.ICON)), calls.sgdb)
|
||||
assertEquals(0, calls.store)
|
||||
val cache = AddedGameArt.cacheDir(app, g)
|
||||
assertFalse(File(cache, "p.jpg").exists())
|
||||
assertArrayEquals(coverBytes, File(g.folder, "cover.jpg").readBytes())
|
||||
val art = AddedGameArt.resolve(app, g)
|
||||
assertEquals(File(g.folder, "cover.jpg"), art.portrait)
|
||||
assertEquals(File(cache, "logo.png"), art.logo)
|
||||
assertEquals(File(cache, "icon-sgdb.png"), art.icon)
|
||||
assertFalse(File(cache, AddedGameArt.EXTRAS_TRIED).exists())
|
||||
}
|
||||
|
||||
@Test fun filledOrChosenSlotsAreNeverAskedFor() {
|
||||
val g = game("Hades", 0x81000002L)
|
||||
File(g.folder, "logo.png").writeBytes(byteArrayOf(5))
|
||||
val picked = File(tmp.root, "mine.png").apply { writeBytes(byteArrayOf(6)) }
|
||||
assertTrue(AddedGameArt.store(AddedGameArt.cacheDir(app, g), Slot.ICON, AddedGameArt.Option(AddedGameArt.FILE, picked.path, picked.path)))
|
||||
val calls = Calls()
|
||||
assertFalse(AddedGameArt.fetchMissing(app, listOf(g), "key", sources(calls, steamHas = Slot.values().toSet(), sgdbHas = Slot.values().toSet())))
|
||||
assertTrue(calls.steam.isEmpty() && calls.sgdb.isEmpty() && calls.lookups == 0)
|
||||
assertArrayEquals(byteArrayOf(5), File(g.folder, "logo.png").readBytes())
|
||||
}
|
||||
|
||||
@Test fun withoutAKeyAMissingIconAloneAsksNothing() {
|
||||
val g = game("Inside", 0x81000003L)
|
||||
File(g.folder, "logo.png").writeBytes(byteArrayOf(5))
|
||||
val calls = Calls()
|
||||
assertFalse(AddedGameArt.fetchMissing(app, listOf(g), "", sources(calls)))
|
||||
assertTrue(calls.steam.isEmpty() && calls.sgdb.isEmpty() && calls.lookups == 0)
|
||||
assertFalse(AddedGameArt.cacheDir(app, g).exists())
|
||||
}
|
||||
|
||||
@Test fun aMissIsAskedAgainOnlyAfterAWeek() {
|
||||
val g = game("Limbo", 0x81000004L)
|
||||
val calls = Calls()
|
||||
assertFalse(AddedGameArt.fetchMissing(app, listOf(g), "key", sources(calls)))
|
||||
assertEquals(listOf(setOf(Slot.LOGO)), calls.steam)
|
||||
assertEquals(listOf(setOf(Slot.LOGO, Slot.ICON)), calls.sgdb)
|
||||
AddedGameArt.fetchMissing(app, listOf(g), "key", sources(calls))
|
||||
assertEquals(1, calls.steam.size)
|
||||
assertEquals(1, calls.sgdb.size)
|
||||
val tried = File(AddedGameArt.cacheDir(app, g), AddedGameArt.EXTRAS_TRIED)
|
||||
assertTrue(tried.setLastModified(System.currentTimeMillis() - 8L * 24 * 3600 * 1000))
|
||||
assertTrue(AddedGameArt.fetchMissing(app, listOf(g), "key", sources(calls, steamHas = setOf(Slot.LOGO), sgdbHas = setOf(Slot.ICON))))
|
||||
assertEquals(2, calls.steam.size)
|
||||
assertEquals(setOf(Slot.ICON), calls.sgdb.last())
|
||||
assertFalse(tried.exists())
|
||||
}
|
||||
|
||||
@Test fun theStoresOwnLogoComesFirst() {
|
||||
val g = game("Metalstorm", 0x81000005L, source = "gog")
|
||||
val calls = Calls()
|
||||
assertTrue(AddedGameArt.fetchMissing(app, listOf(g), "key", sources(calls, storeHas = true, steamHas = setOf(Slot.LOGO), sgdbHas = setOf(Slot.ICON))))
|
||||
assertEquals(1, calls.store)
|
||||
assertTrue(calls.steam.isEmpty())
|
||||
assertEquals(listOf(setOf(Slot.ICON)), calls.sgdb)
|
||||
assertEquals(File(g.folder, "logo.png"), AddedGameArt.resolve(app, g).logo)
|
||||
}
|
||||
|
||||
@Test fun aGameWithoutACoverStillGetsEverySlot() {
|
||||
val g = game("Tunic", 0x81000006L, cover = false)
|
||||
val calls = Calls()
|
||||
assertTrue(AddedGameArt.fetchMissing(app, listOf(g), "key",
|
||||
sources(calls, steamHas = setOf(Slot.COVER, Slot.WIDE, Slot.BACKGROUND), sgdbHas = setOf(Slot.LOGO, Slot.ICON))))
|
||||
assertEquals(listOf(setOf(Slot.COVER, Slot.WIDE, Slot.BACKGROUND, Slot.LOGO)), calls.steam)
|
||||
assertEquals(listOf(setOf(Slot.LOGO, Slot.ICON)), calls.sgdb)
|
||||
assertTrue(AddedGameArt.missing(app, g).isEmpty())
|
||||
}
|
||||
|
||||
@Test fun aSteamGridDbFailureIsNotRememberedAndStopsThePass() {
|
||||
val first = game("Gris", 0x81000007L)
|
||||
val second = game("Hollow", 0x81000008L)
|
||||
val calls = Calls()
|
||||
AddedGameArt.fetchMissing(app, listOf(first, second), "key", sources(calls, sgdbFails = true))
|
||||
assertEquals(2, calls.steam.size)
|
||||
assertEquals(1, calls.lookups)
|
||||
assertFalse(File(AddedGameArt.cacheDir(app, first), AddedGameArt.EXTRAS_TRIED).exists())
|
||||
assertFalse(File(AddedGameArt.cacheDir(app, second), AddedGameArt.EXTRAS_TRIED).exists())
|
||||
}
|
||||
|
||||
@Test fun nothingIsFetchedWhenArtIsOff() {
|
||||
SessionPrefs.setAddedGamesArt(app, false)
|
||||
val calls = Calls()
|
||||
assertFalse(AddedGameArt.fetchMissing(app, listOf(game("Off", 0x81000009L)), "key", sources(calls)))
|
||||
assertTrue(calls.steam.isEmpty())
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.app.Activity
|
||||
import com.droiddeck.launcher.LauncherIcon
|
||||
import com.droiddeck.launcher.MainActivity
|
||||
import com.droiddeck.launcher.FrontEndActivity
|
||||
import com.droiddeck.launcher.frontend.Library
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNotNull
|
||||
@@ -54,7 +54,7 @@ class GameShortcutIntentTest {
|
||||
|
||||
assertEquals(Intent.ACTION_VIEW, intent.action)
|
||||
assertEquals(Uri.parse("droiddeck://game/$id"), intent.data)
|
||||
assertEquals(MainActivity::class.java.name, intent.component?.className)
|
||||
assertEquals(FrontEndActivity::class.java.name, intent.component?.className)
|
||||
assertEquals(android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP or android.content.Intent.FLAG_ACTIVITY_SINGLE_TOP, intent.flags)
|
||||
}
|
||||
|
||||
@@ -69,8 +69,8 @@ class GameShortcutIntentTest {
|
||||
val launch = requireNotNull(shortcut.intent)
|
||||
assertEquals("game:8400", shortcut.id)
|
||||
assertEquals("Geometry Wars: Retro Evolved", shortcut.shortLabel.toString())
|
||||
assertEquals("com.droiddeck.launcher.LauncherDark", shortcut.activity?.className)
|
||||
assertEquals(MainActivity::class.java.name, launch.component?.className)
|
||||
assertEquals("com.droiddeck.launcher.MainActivity", shortcut.activity?.className)
|
||||
assertEquals(FrontEndActivity::class.java.name, launch.component?.className)
|
||||
assertEquals(Intent.ACTION_VIEW, launch.action)
|
||||
assertEquals(Uri.parse("droiddeck://game/8400"), launch.data)
|
||||
assertEquals(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP, launch.flags)
|
||||
@@ -93,4 +93,38 @@ class GameShortcutIntentTest {
|
||||
|
||||
assertNotNull(GameShortcuts.result(activity, game))
|
||||
}
|
||||
|
||||
@Test fun theDefaultLauncherEntryKeepsTheMainActivityName() {
|
||||
val activity = Robolectric.buildActivity(Activity::class.java).setup().get()
|
||||
val launchers = activity.packageManager.queryIntentActivities(
|
||||
Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER).setPackage(activity.packageName), 0)
|
||||
|
||||
assertEquals(listOf("com.droiddeck.launcher.MainActivity"), launchers.map { it.activityInfo.name })
|
||||
assertEquals(android.content.ComponentName(activity, "com.droiddeck.launcher.MainActivity"), LauncherIcon.activity(activity))
|
||||
}
|
||||
|
||||
@Test fun repairDropsTheDefaultIconLeftBesideAChosenLightIcon() {
|
||||
val activity = Robolectric.buildActivity(Activity::class.java).setup().get()
|
||||
val pm = activity.packageManager
|
||||
pm.setComponentEnabledSetting(android.content.ComponentName(activity, "com.droiddeck.launcher.LauncherLight"),
|
||||
android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_ENABLED, android.content.pm.PackageManager.DONT_KILL_APP)
|
||||
val dark = android.content.ComponentName(activity, "com.droiddeck.launcher.MainActivity")
|
||||
|
||||
LauncherIcon.repair(activity, dark)
|
||||
assertEquals(android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, pm.getComponentEnabledSetting(dark))
|
||||
|
||||
LauncherIcon.repair(activity, android.content.ComponentName(activity, "com.droiddeck.launcher.LauncherLight"))
|
||||
assertEquals(android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DISABLED, pm.getComponentEnabledSetting(dark))
|
||||
assertEquals(LauncherIcon.LIGHT, LauncherIcon.current(activity))
|
||||
}
|
||||
|
||||
@Test fun repairLeavesASingleIconAlone() {
|
||||
val activity = Robolectric.buildActivity(Activity::class.java).setup().get()
|
||||
val dark = android.content.ComponentName(activity, "com.droiddeck.launcher.MainActivity")
|
||||
|
||||
LauncherIcon.repair(activity, null)
|
||||
|
||||
assertEquals(android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, activity.packageManager.getComponentEnabledSetting(dark))
|
||||
assertEquals(LauncherIcon.DARK, LauncherIcon.current(activity))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package com.droiddeck.launcher.frontend
|
||||
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONObject
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.TemporaryFolder
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.annotation.Config
|
||||
import java.io.File
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [33])
|
||||
class GameLogoTest {
|
||||
private val app get() = RuntimeEnvironment.getApplication()
|
||||
@get:Rule val tmp = TemporaryFolder()
|
||||
|
||||
@Before fun noGamesFolders() {
|
||||
AddedGamesPublisher.now = true
|
||||
SessionPrefs.setGameStorage(app, SessionPrefs.GAME_STORAGE_OFF, "")
|
||||
SessionPrefs.setAddedGamesDirs(app, emptyList())
|
||||
}
|
||||
|
||||
private fun image(name: String) = File(tmp.root, name).apply { parentFile?.mkdirs(); writeBytes(ByteArray(8) { 1 }) }
|
||||
|
||||
@Test fun steamsCachedLogoIsFoundInTheAppFolderOrAHashedOne() {
|
||||
val cache = tmp.newFolder("librarycache")
|
||||
val logo = File(cache, "620/3f1c/logo.png").apply { parentFile?.mkdirs(); writeBytes(ByteArray(4) { 1 }) }
|
||||
assertEquals(logo, Library.steamCacheImage(cache, 620, Library.STEAM_LOGOS))
|
||||
File(cache, "730").mkdirs()
|
||||
File(cache, "730/logo.png").writeBytes(ByteArray(0))
|
||||
assertNull(Library.steamCacheImage(cache, 730, Library.STEAM_LOGOS))
|
||||
}
|
||||
|
||||
@Test fun aChosenLogoWinsOverSteamsAndKeepsTheRest() {
|
||||
val stock = image("logo.png")
|
||||
val game = Library.SteamGame(620, "Portal 2", null, "Steam library", logo = stock)
|
||||
assertTrue(SteamGameArt.withOverrides(app, game) === game)
|
||||
val picked = image("mine.png")
|
||||
assertTrue(SteamGameArt.choose(app, game, AddedGameArt.Slot.LOGO, AddedGameArt.Option(AddedGameArt.FILE, picked.path, picked.path)))
|
||||
val shown = SteamGameArt.withOverrides(app, game)
|
||||
assertTrue(shown.logo!!.name.startsWith("chosen-logo"))
|
||||
assertNull(shown.art)
|
||||
SteamGameArt.reset(app, game, AddedGameArt.Slot.LOGO)
|
||||
assertEquals(stock, SteamGameArt.withOverrides(app, game).logo)
|
||||
}
|
||||
|
||||
@Test fun anAddedGameShowsItsFolderLogoUnlessOneWasChosen() {
|
||||
val dir = tmp.newFolder("Celeste")
|
||||
val own = File(dir, "logo.png").apply { writeBytes(ByteArray(4) { 1 }) }
|
||||
val exe = File(dir, "Celeste.exe").apply { writeText("x") }
|
||||
val g = AddedGames.Game(dir, "Celeste", exe, "/g/Celeste.exe", "/g", 0x82000001L, 0x82000001L, emptyList(), source = "gog")
|
||||
assertEquals(own, Library.addedGame(app, g, emptyList()).logo)
|
||||
val picked = image("pick.png")
|
||||
assertTrue(AddedGameArt.choose(app, g, AddedGameArt.Slot.LOGO, AddedGameArt.Option(AddedGameArt.FILE, picked.path, picked.path)))
|
||||
assertTrue(Library.addedGame(app, g, emptyList()).logo!!.name.startsWith("chosen-logo"))
|
||||
val bare = AddedGames.Game(tmp.newFolder("Bare"), "Bare", exe, "/g/Bare.exe", "/g", 0x82000002L, 0x82000002L, emptyList())
|
||||
assertNull(Library.addedGame(app, bare, emptyList()).logo)
|
||||
}
|
||||
|
||||
@Test fun theLibraryCacheKeepsTheLogoAndReadsOlderEntries() {
|
||||
val logo = image("logo.png")
|
||||
val game = Library.SteamGame(620, "Portal 2", null, "Steam library", logo = logo)
|
||||
LibraryCache.save(app, listOf(game, Library.SteamGame(730, "CS2", null, "Steam library")))
|
||||
val back = LibraryCache.load(app)
|
||||
assertEquals(logo, back[0].logo)
|
||||
assertNull(back[1].logo)
|
||||
assertEquals(logo, game.withArt(null, null, null).logo)
|
||||
val file = File(app.filesDir, "library-cache.json")
|
||||
file.writeText(JSONArray().put(JSONObject().put("appId", 1).put("name", "Old").put("library", "x").put("gameId", 1L)).toString())
|
||||
assertNull(LibraryCache.load(app).single().logo)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
import android.os.Looper
|
||||
import java.util.concurrent.AbstractExecutorService
|
||||
import java.util.concurrent.TimeUnit
|
||||
import org.junit.After
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
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.annotation.LooperMode
|
||||
import org.robolectric.util.ReflectionHelpers
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [33])
|
||||
@LooperMode(LooperMode.Mode.PAUSED)
|
||||
class SessionSleepRequestTest {
|
||||
private lateinit var service: SessionService
|
||||
private val work = ArrayDeque<Runnable>()
|
||||
private val executor = object : AbstractExecutorService() {
|
||||
override fun execute(command: Runnable) { work.addLast(command) }
|
||||
override fun shutdown() {}
|
||||
override fun shutdownNow(): MutableList<Runnable> = mutableListOf()
|
||||
override fun isShutdown() = false
|
||||
override fun isTerminated() = false
|
||||
override fun awaitTermination(timeout: Long, unit: TimeUnit) = false
|
||||
}
|
||||
|
||||
@Before fun setUp() {
|
||||
service = Robolectric.buildService(SessionService::class.java).get()
|
||||
SessionState.running = true
|
||||
SessionState.suspended = false
|
||||
SessionState.mode = SessionService.MODE_RUN
|
||||
ReflectionHelpers.setField(service, "suspendPolicy", SessionPrefs.SUSPEND_NEVER)
|
||||
ReflectionHelpers.setField(service, "suspendController", SessionSuspendController(
|
||||
sessionRoot = { -1 }, helperRoots = { emptyList() },
|
||||
suspendAudio = {}, resumeAudio = {}, executor = executor,
|
||||
))
|
||||
}
|
||||
|
||||
@After fun tearDown() {
|
||||
SessionState.running = false
|
||||
SessionState.suspended = false
|
||||
SessionState.mode = SessionService.MODE_STEAM
|
||||
shadowOf(Looper.getMainLooper()).idle()
|
||||
work.clear()
|
||||
}
|
||||
|
||||
@Test fun cancelledFreezePreservesAndRetriesANewerSteamRequest() {
|
||||
ReflectionHelpers.setField(service, "steamSleepToken", "old-request")
|
||||
ReflectionHelpers.callInstanceMethod<Void>(service, "updateSuspendPolicy")
|
||||
assertEquals(1, work.size)
|
||||
ReflectionHelpers.setField(service, "freezeCancelled", true)
|
||||
ReflectionHelpers.setField(service, "steamSleepToken", "new-request")
|
||||
work.removeFirst().run()
|
||||
shadowOf(Looper.getMainLooper()).idle()
|
||||
assertEquals("new-request", ReflectionHelpers.getField<String>(service, "steamSleepToken"))
|
||||
assertEquals(1, work.size)
|
||||
assertFalse(ReflectionHelpers.getField(service, "suspendAttemptFailed"))
|
||||
}
|
||||
|
||||
@Test fun cancelledFreezeCompletesItsOwnRequestWithoutRetryingIt() {
|
||||
ReflectionHelpers.setField(service, "steamSleepToken", "old-request")
|
||||
ReflectionHelpers.callInstanceMethod<Void>(service, "updateSuspendPolicy")
|
||||
ReflectionHelpers.setField(service, "freezeCancelled", true)
|
||||
work.removeFirst().run()
|
||||
shadowOf(Looper.getMainLooper()).idle()
|
||||
assertEquals(null, ReflectionHelpers.getField<String?>(service, "steamSleepToken"))
|
||||
assertEquals(0, work.size)
|
||||
assertFalse(ReflectionHelpers.getField(service, "suspendAttemptFailed"))
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,66 @@ class SessionSuspendControllerTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun pageOutRunsInPreloadedGuestsBeforeTheyStop() {
|
||||
val fixture = fixture(17)
|
||||
fixture.control.writeText("0")
|
||||
fixture.controller.freeze(pageOut = true) { assertTrue(it) }
|
||||
val urgent = fixture.signals.filter { it.signal == URG }
|
||||
assertEquals(listOf(GAME), urgent.map { it.pid })
|
||||
assertTrue(fixture.signals.indexOfFirst { it.signal == URG } < fixture.signals.indexOfFirst { it.signal == STOP })
|
||||
assertEquals("1", fixture.control.readText())
|
||||
assertEquals(listOf(Triple(1, 1_000_000L, 3_000_000L)), fixture.pagedOut)
|
||||
assertEquals(0, fixture.unacknowledged)
|
||||
assertTrue(fixture.game.threads.all { it.state == 't' })
|
||||
assertFalse(File(fixture.control.parentFile, ".bl-zram.ack.$GAME").exists())
|
||||
}
|
||||
|
||||
@Test fun unchangedSwapIsNotTakenForAFinishedPageOut() {
|
||||
val fixture = fixture(17)
|
||||
fixture.control.writeText("0")
|
||||
fixture.handlerStalls = true
|
||||
var stoppedEarly = false
|
||||
fixture.afterSleep = {
|
||||
if (fixture.now == 3000L) fixture.handlerStalls = false
|
||||
if (fixture.handlerStalls && fixture.signals.any { it.signal == STOP }) stoppedEarly = true
|
||||
}
|
||||
fixture.controller.freeze(pageOut = true) { assertTrue(it) }
|
||||
assertFalse(stoppedEarly)
|
||||
assertEquals(0, fixture.unacknowledged)
|
||||
}
|
||||
|
||||
@Test fun replacedHandlerIsNotWaitedForPastTheStartWindow() {
|
||||
val fixture = fixture(17)
|
||||
fixture.control.writeText("0")
|
||||
fixture.handlerReplaced = true
|
||||
fixture.controller.freeze(pageOut = true) { assertTrue(it) }
|
||||
assertEquals(1, fixture.unacknowledged)
|
||||
assertTrue(fixture.now in 2000L..3000L)
|
||||
}
|
||||
|
||||
@Test fun cancelledFreezeRollsBackWithoutStopping() {
|
||||
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) }
|
||||
assertFalse(fixture.signals.any { it.signal == STOP })
|
||||
assertTrue(fixture.game.threads.all { it.state == 'S' })
|
||||
assertEquals(1, fixture.audioResumes)
|
||||
}
|
||||
|
||||
@Test fun noPageOutWithoutTheRequestOrTheControlFile() {
|
||||
val visible = fixture(17)
|
||||
visible.control.writeText("0")
|
||||
visible.controller.freeze { assertTrue(it) }
|
||||
assertFalse(visible.signals.any { it.signal == URG })
|
||||
assertEquals("0", visible.control.readText())
|
||||
val disabled = fixture(17)
|
||||
disabled.controller.freeze(pageOut = true) { assertTrue(it) }
|
||||
assertFalse(disabled.signals.any { it.signal == URG })
|
||||
assertTrue(disabled.pagedOut.isEmpty())
|
||||
}
|
||||
|
||||
@Test fun cpuMustBeStableAcrossTwoCompleteSnapshots() {
|
||||
val fixture = fixture(17)
|
||||
var changes = 0
|
||||
@@ -253,13 +313,13 @@ class SessionSuspendControllerTest {
|
||||
}
|
||||
|
||||
private fun fixture(count: Int, executor: QueueExecutor = InlineExecutor()) =
|
||||
Fixture(temporary.newFolder(), count, executor)
|
||||
Fixture(temporary.newFolder(), temporary.newFolder(), count, executor)
|
||||
|
||||
private data class Task(val tid: Int, var started: Long, var state: Char, var cpu: Long = 0)
|
||||
private data class Group(val pid: Int, var parent: Int, var tracer: Int, val threads: MutableList<Task>)
|
||||
private data class SentSignal(val pid: Int, val signal: Int)
|
||||
|
||||
private class Fixture(val proc: File, count: Int, executor: QueueExecutor) {
|
||||
private class Fixture(val proc: File, tmp: File, count: Int, executor: QueueExecutor) {
|
||||
val root = Group(ROOT, 9000, 0, mutableListOf(Task(ROOT, 1000, 'S')))
|
||||
val game = Group(GAME, ROOT, ROOT, MutableList(count) { Task(GAME + it, 2000L + it, 'S') })
|
||||
val groups = mutableListOf(root, game)
|
||||
@@ -276,10 +336,23 @@ class SessionSuspendControllerTest {
|
||||
var emptyGameTasks = false
|
||||
var rootGone = false
|
||||
var afterSleep: (() -> Unit)? = null
|
||||
val control = File(tmp, ".bl-zram")
|
||||
val pagedOut = mutableListOf<Triple<Int, Long, Long>>()
|
||||
private var gameResidentKb = 4_000_000L
|
||||
private var gameSwapKb = 0L
|
||||
private var pagingOut = false
|
||||
var unacknowledged = -1
|
||||
var handlerStalls = false
|
||||
var handlerReplaced = false
|
||||
private var continuing = false
|
||||
val controller = SessionSuspendController(
|
||||
{ rootPid }, { helpers }, { audioSuspends++ }, { audioResumes++ },
|
||||
proc, ::signal, ::threadSignal, ::sleep, { now }, executor,
|
||||
zramControl = control,
|
||||
pagedOut = { processes, unacknowledged, resident, swap, _, _ ->
|
||||
pagedOut += Triple(processes, resident, swap)
|
||||
this.unacknowledged = unacknowledged
|
||||
},
|
||||
)
|
||||
|
||||
init { sync() }
|
||||
@@ -293,6 +366,8 @@ class SessionSuspendControllerTest {
|
||||
else group.threads.firstOrNull {
|
||||
it.state !in listOf('T', 't', 'Z', 'X') && !(neverStop && it == game.threads.last())
|
||||
}?.state = 't'
|
||||
} else if (signal == URG) {
|
||||
pagingOut = true
|
||||
} else if (signal == CONT) {
|
||||
continuing = true
|
||||
if (!(pid == GAME && blockGameContinue)) group.threads.forEach { if (it.state != 'Z') it.state = 'S' }
|
||||
@@ -311,6 +386,18 @@ class SessionSuspendControllerTest {
|
||||
|
||||
private fun sleep(millis: Long) {
|
||||
now += millis
|
||||
if (pagingOut && !handlerReplaced) {
|
||||
File(control.parentFile, "${control.name}.ack.$GAME").apply { if (!exists()) writeText("") }
|
||||
}
|
||||
if (pagingOut && !handlerStalls && !handlerReplaced) {
|
||||
if (gameResidentKb > 1_000_000L) {
|
||||
gameResidentKb -= 1_000_000L
|
||||
gameSwapKb += 1_000_000L
|
||||
} else {
|
||||
File(control.parentFile, "${control.name}.ack.$GAME").writeText("1")
|
||||
pagingOut = false
|
||||
}
|
||||
}
|
||||
if (root.threads.first().state != 'T' && !continuing) game.threads.forEach {
|
||||
if (it.state != 'Z') { it.state = 'S'; it.cpu++ }
|
||||
}
|
||||
@@ -326,7 +413,11 @@ class SessionSuspendControllerTest {
|
||||
val stat = File(dir, "stat")
|
||||
if (group == game && missingGameStat) stat.delete()
|
||||
else stat.writeText(stat(group, group.threads.first()))
|
||||
File(dir, "status").writeText("TracerPid: ${group.tracer}\n")
|
||||
File(dir, "status").writeText(
|
||||
"TracerPid: ${group.tracer}\n" +
|
||||
if (group == game) "VmRSS:\t$gameResidentKb kB\nVmSwap:\t$gameSwapKb kB\n" else "",
|
||||
)
|
||||
if (group == game) File(dir, "maps").writeText("7f00000000-7f00001000 r-xp 00000000 fe:05 42 /usr/local/lib/libblsession.so\n")
|
||||
val taskDir = File(dir, "task")
|
||||
if (group == game && missingGameTasks) { taskDir.deleteRecursively(); continue }
|
||||
taskDir.mkdirs()
|
||||
@@ -375,5 +466,6 @@ class SessionSuspendControllerTest {
|
||||
const val GAME = 200
|
||||
const val STOP = 19
|
||||
const val CONT = 18
|
||||
const val URG = 23
|
||||
}
|
||||
}
|
||||
@@ -131,6 +131,25 @@ class StoreAccountsCipherTest {
|
||||
assertEquals("test@example.test", StoreAccounts.signedInAs(app, Store.XBOX))
|
||||
}
|
||||
|
||||
@Test fun xboxShowsTheGamertagElseAMaskedEmail() {
|
||||
StoreAccounts.write(app, Store.XBOX, JSONObject().put("username", "player@example.test"))
|
||||
assertEquals("p•••@example.test", StoreAccounts.displayName(app, Store.XBOX))
|
||||
StoreAccounts.write(app, Store.XBOX, JSONObject().put("username", "player@example.test").put("gamertag", "Some Gamertag"))
|
||||
assertEquals("Some Gamertag", StoreAccounts.displayName(app, Store.XBOX))
|
||||
assertEquals("player@example.test", StoreAccounts.signedInAs(app, Store.XBOX))
|
||||
StoreAccounts.write(app, Store.EPIC, creds)
|
||||
assertEquals("Someone", StoreAccounts.displayName(app, Store.EPIC))
|
||||
assertEquals("n•••", StoreAccounts.maskEmail("nickname"))
|
||||
}
|
||||
|
||||
@Test fun xboxDisplayNameDoesNotRevealEmailWhenCredentialsAreTemporarilyUnavailable() {
|
||||
StoreAccounts.write(app, Store.XBOX, JSONObject().put("username", "player@example.test"))
|
||||
StoreAccounts.keys = Flaky(key, 1) { java.security.ProviderException("busy") }
|
||||
assertEquals(Store.XBOX.label, StoreAccounts.displayName(app, Store.XBOX))
|
||||
assertTrue(StoreAccounts.isUnavailable(Store.XBOX))
|
||||
assertTrue(file(Store.XBOX).exists())
|
||||
}
|
||||
|
||||
@Test fun signOutRemovesTheFile() {
|
||||
StoreAccounts.write(app, Store.GOG, creds)
|
||||
StoreAccounts.clear(app, Store.GOG)
|
||||
|
||||
@@ -34,6 +34,17 @@ class StoreGameSidecarTest {
|
||||
assertEquals("ns", back.extra["namespace"])
|
||||
}
|
||||
|
||||
@Test fun theStoreLogoRoundTripsAndOlderFilesHaveNone() {
|
||||
val withLogo = sample.copy(logo = "https://x/logo.png")
|
||||
val back = StoreGameSidecar.parse(withLogo.toJson().toString())!!
|
||||
assertEquals("https://x/logo.png", back.logo)
|
||||
assertEquals("https://x/logo.png", back.copy(state = StoreGameSidecar.STATE_UPDATING).logo)
|
||||
assertFalse(sample.toJson().has("logo"))
|
||||
assertNull(StoreGameSidecar.parse(sample.toJson().toString())!!.logo)
|
||||
assertNull(StoreGameSidecar.parse("""{"store":"gog","id":"1","title":"T","exe":"game.exe","cover":"c","hero":"h"}""")!!.logo)
|
||||
assertNull(StoreGameSidecar.parse("""{"store":"gog","id":"1","title":"T","exe":"game.exe","logo":""}""")!!.logo)
|
||||
}
|
||||
|
||||
@Test fun defaultsWhenFieldsAreAbsent() {
|
||||
val back = StoreGameSidecar.parse("""{"store":"gog","id":"1","title":"T","exe":"bin\\game.exe","addToSteam":false}""")!!
|
||||
assertEquals("bin/game.exe", back.exe)
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
package com.droiddeck.launcher.stores
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.BitmapFactory
|
||||
import android.graphics.Color
|
||||
import com.droiddeck.launcher.stores.amazon.AmazonLibrary
|
||||
import com.droiddeck.launcher.stores.gog.GogBackend
|
||||
import org.json.JSONObject
|
||||
import org.junit.Assert.assertArrayEquals
|
||||
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 org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.annotation.Config
|
||||
import org.robolectric.annotation.GraphicsMode
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.File
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [33])
|
||||
@GraphicsMode(GraphicsMode.Mode.NATIVE)
|
||||
class StoreLogoTest {
|
||||
@get:Rule val tmp = TemporaryFolder()
|
||||
|
||||
private fun encoded(format: Bitmap.CompressFormat): ByteArray {
|
||||
val bmp = Bitmap.createBitmap(8, 4, Bitmap.Config.ARGB_8888)
|
||||
bmp.eraseColor(Color.TRANSPARENT)
|
||||
bmp.setPixel(1, 1, Color.RED)
|
||||
return ByteArrayOutputStream().also { bmp.compress(format, 100, it) }.toByteArray()
|
||||
}
|
||||
|
||||
@Test fun aPngLogoIsKeptAsItCameWithItsTransparency() {
|
||||
val png = encoded(Bitmap.CompressFormat.PNG)
|
||||
val dst = File(tmp.root, StoreArt.LOGO)
|
||||
assertTrue(StoreArt.writeLogo(png, dst))
|
||||
assertArrayEquals(png, dst.readBytes())
|
||||
val back = BitmapFactory.decodeFile(dst.path)
|
||||
assertEquals(0, Color.alpha(back.getPixel(0, 0)))
|
||||
assertEquals(Color.RED, back.getPixel(1, 1))
|
||||
assertFalse(File(dst.path + ".tmp").exists())
|
||||
}
|
||||
|
||||
@Test fun anotherImageFormatIsStoredAsPng() {
|
||||
val dst = File(tmp.root, StoreArt.LOGO)
|
||||
assertTrue(StoreArt.writeLogo(encoded(Bitmap.CompressFormat.JPEG), dst))
|
||||
val head = dst.readBytes().take(4)
|
||||
assertEquals(listOf(0x89.toByte(), 'P'.code.toByte(), 'N'.code.toByte(), 'G'.code.toByte()), head)
|
||||
assertEquals(8, BitmapFactory.decodeFile(dst.path).width)
|
||||
}
|
||||
|
||||
@Test fun whatIsNotAnImageIsRefusedAndAnExistingLogoStays() {
|
||||
val dst = File(tmp.root, StoreArt.LOGO)
|
||||
assertFalse(StoreArt.writeLogo("<html>not found</html>".toByteArray(), dst))
|
||||
assertFalse(dst.exists())
|
||||
dst.writeBytes(byteArrayOf(1, 2, 3))
|
||||
assertTrue(StoreArt.writeLogo(encoded(Bitmap.CompressFormat.PNG), dst))
|
||||
assertArrayEquals(byteArrayOf(1, 2, 3), dst.readBytes())
|
||||
assertTrue(StoreArt.fetchLogo(tmp.root, "https://invalid.example/logo.png"))
|
||||
}
|
||||
|
||||
@Test fun gogTakesTheV2LogoLinkOnly() {
|
||||
val v2 = JSONObject("""{"_links":{"logo":{"href":"https://images.gog-statics.com/abc_logo.png"},"galaxyBackgroundImage":{"href":"https://x/bg.jpg"}}}""")
|
||||
assertEquals("https://images.gog-statics.com/abc_logo.png", GogBackend.logoOf(v2))
|
||||
assertEquals("https://images.gog-statics.com/rel.png", GogBackend.logoOf(JSONObject("""{"_links":{"logo":{"href":"//images.gog-statics.com/rel.png"}}}""")))
|
||||
assertNull(GogBackend.logoOf(JSONObject("""{"_links":{}}""")))
|
||||
assertNull(GogBackend.logoOf(JSONObject("""{"images":{"logo2x":"https://x/glx_logo_2x.jpg"}}""")))
|
||||
assertNull(GogBackend.logoOf(JSONObject("""{"_links":{"logo":{"href":"http://x/logo.png"}}}""")))
|
||||
}
|
||||
|
||||
@Test fun amazonKeepsTheLogoFromTheLibraryAndItsCache() {
|
||||
val app = RuntimeEnvironment.getApplication()
|
||||
val fresh = AmazonLibrary.gameFrom(JSONObject().put("productId", "p").put("title", "Game").put("logo", "https://m/logo.png"), null)
|
||||
assertEquals("https://m/logo.png", fresh.logoUrl)
|
||||
assertEquals("https://m/logo.png", AmazonLibrary.toCatalogItem(app, fresh).logoUrl)
|
||||
assertEquals(listOf(fresh), AmazonLibrary.fromCacheJson(AmazonLibrary.toCacheJson(listOf(fresh))))
|
||||
val kept = AmazonLibrary.gameFrom(JSONObject().put("productId", "p").put("title", "Game"), fresh)
|
||||
assertEquals("https://m/logo.png", kept.logoUrl)
|
||||
val none = AmazonLibrary.gameFrom(JSONObject().put("productId", "q").put("title", "Other"), null)
|
||||
assertNull(AmazonLibrary.toCatalogItem(app, none).logoUrl)
|
||||
assertEquals("", AmazonLibrary.fromCacheJson("""[{"productId":"old","title":"Old"}]""").single().logoUrl)
|
||||
}
|
||||
}
|
||||
@@ -83,6 +83,18 @@ class EpicLibraryTest {
|
||||
assertEquals("Fig", EpicLibrary.gameFrom(record, null, null).title)
|
||||
}
|
||||
|
||||
@Test fun theCatalogLogoIsKeptInTheCacheAndHandedToTheInstall() {
|
||||
val record = JSONObject().put("appName", "Fig").put("namespace", "ns").put("catalogItemId", "cat")
|
||||
val fresh = EpicLibrary.gameFrom(record, JSONObject().put("logo", "https://e/logo.png"), null)
|
||||
assertEquals("https://e/logo.png", fresh.artLogo)
|
||||
assertEquals("https://e/logo.png", EpicLibrary.gameFrom(record, JSONObject().put("title", "Fig"), fresh).artLogo)
|
||||
assertEquals(listOf(fresh), EpicLibrary.fromCacheJson(EpicLibrary.toCacheJson(listOf(fresh))))
|
||||
assertEquals("https://e/logo.png", EpicLibrary.toCatalogItem(app, fresh).logoUrl)
|
||||
val plain = EpicGame("Old", "ns", "c", "Old")
|
||||
assertFalse(JSONArray(EpicLibrary.toCacheJson(listOf(plain))).getJSONObject(0).has("artLogo"))
|
||||
assertEquals(null, EpicLibrary.toCatalogItem(app, plain).logoUrl)
|
||||
}
|
||||
|
||||
@Test fun signOutForgetsOnlyTheLibrary() {
|
||||
EpicPrefs.get(app).edit().putString(EpicLibrary.KEY_CACHE, "[]").putLong(EpicLibrary.KEY_SYNCED_AT, 1L)
|
||||
.putString("cloud_template_Fig", "{AppData}/x").commit()
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.droiddeck.launcher.stores.xbox
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
@org.junit.runner.RunWith(org.robolectric.RobolectricTestRunner::class)
|
||||
@org.robolectric.annotation.Config(sdk = [33], application = android.app.Application::class)
|
||||
class XboxSignInMessagesTest {
|
||||
@Test fun ownCheckMessagesAreShownAndOtherTextIsNot() {
|
||||
assertEquals("the Xbox helper stopped with exit code 3", XboxLoginActivity.failure(IllegalStateException("the Xbox helper stopped with exit code 3")))
|
||||
assertEquals("IllegalStateException", XboxLoginActivity.failure(IllegalStateException("Check failed.")))
|
||||
assertEquals("JSONException", XboxLoginActivity.failure(org.json.JSONException("token=secret-value")))
|
||||
assertEquals("IllegalArgumentException", XboxLoginActivity.failure(IllegalArgumentException("secret-value")))
|
||||
}
|
||||
|
||||
@Test fun gamertagMustBeShortPrintableText() {
|
||||
assertTrue(XboxGamertag.valid("Some Gamertag"))
|
||||
assertFalse(XboxGamertag.valid(""))
|
||||
assertFalse(XboxGamertag.valid("a\nb"))
|
||||
assertFalse(XboxGamertag.valid("x".repeat(65)))
|
||||
}
|
||||
|
||||
@Test fun gamertagRefreshIsOncePerAccountGeneration() {
|
||||
val first = "account-generation-one-${System.nanoTime()}"
|
||||
val second = "account-generation-two-${System.nanoTime()}"
|
||||
assertTrue(XboxGamertag.shouldTryRefresh(first))
|
||||
assertFalse(XboxGamertag.shouldTryRefresh(first))
|
||||
assertTrue(XboxGamertag.shouldTryRefresh(second))
|
||||
assertFalse(XboxGamertag.shouldTryRefresh(second))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user