Merge remote-tracking branch 'origin/main' into review/malibridge-1950

This commit is contained in:
Kurt Himebauch committed 2026-11-02 18:14:00 -05:00
commit f05e0df39e
135 files changed
+5415 -979

No files matched your search

@@ -0,0 +1,76 @@
package com.droiddeck.launcher.input
import android.os.Looper
import android.view.accessibility.AccessibilityWindowInfo
import com.droiddeck.launcher.input.BottomScreenGuests.Top
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.Shadows.shadowOf
import org.robolectric.annotation.Config
@RunWith(RobolectricTestRunner::class)
@Config(manifest = Config.NONE)
class BottomScreenGuestsTest {
private val homes = setOf("com.android.launcher3", "com.retroidpocket.gamelauncher")
@After fun clear() = DualScreen.setTaken(emptySet())
@Test fun onlyTheRetroidPocketDuoAndAynThorWatchTheirBottomScreen() {
assertTrue(BottomScreenGuests.supported("Retroid Pocket Duo", 36))
assertTrue(BottomScreenGuests.supported(" retroid pocket duo ", 33))
assertFalse(BottomScreenGuests.supported("Retroid Pocket Duo", 32))
assertTrue(BottomScreenGuests.supported("AYN Thor", 33))
assertTrue(BottomScreenGuests.supported("AYN Thor Max", 34))
assertFalse(BottomScreenGuests.supported("AYN Odin 2", 36))
assertFalse(BottomScreenGuests.supported("Pixel 8", 36))
}
@Test fun anyWindowButTheHomeScreenHoldsTheScreen() {
assertEquals(Top.HOME, BottomScreenGuests.classify("com.android.launcher3", homes))
assertEquals(Top.GUEST, BottomScreenGuests.classify("com.android.chrome", homes))
assertEquals(Top.GUEST, BottomScreenGuests.classify("com.retroidpocket.dualscreen.assistant", homes))
assertEquals(Top.NONE, BottomScreenGuests.classify(null, homes))
}
@Test fun theWindowListDecidesWhenItSeesPastDroidDeck() {
assertEquals("com.android.chrome", BottomScreenGuests.holder("com.android.chrome", null, homes))
assertEquals(null, BottomScreenGuests.holder("com.android.launcher3", "com.android.chrome", homes))
}
@Test fun anAppOpenedUnderDroidDeckHoldsTheScreenUntilTheListSeesIt() {
assertEquals("com.google.android.youtube", BottomScreenGuests.holder(null, "com.google.android.youtube", homes))
assertEquals(null, BottomScreenGuests.holder(null, "com.android.launcher3", homes))
assertEquals(null, BottomScreenGuests.holder(null, null, homes))
}
@Test fun keyboardsAndOverlaysNeverTakeTheScreen() {
assertTrue(BottomScreenGuests.ignorable(AccessibilityWindowInfo.TYPE_INPUT_METHOD))
assertTrue(BottomScreenGuests.ignorable(AccessibilityWindowInfo.TYPE_ACCESSIBILITY_OVERLAY))
assertFalse(BottomScreenGuests.ignorable(AccessibilityWindowInfo.TYPE_APPLICATION))
assertFalse(BottomScreenGuests.ignorable(AccessibilityWindowInfo.TYPE_SYSTEM))
}
@Test fun listenersHearWhenTheScreenIsTakenAndFreed() {
var calls = 0
val listener: () -> Unit = { calls++ }
DualScreen.watchTaken(listener)
DualScreen.setTaken(setOf(2))
shadowOf(Looper.getMainLooper()).idle()
assertTrue(DualScreen.taken(2))
assertFalse(DualScreen.taken(0))
DualScreen.setTaken(setOf(2))
DualScreen.setTaken(emptySet())
shadowOf(Looper.getMainLooper()).idle()
assertFalse(DualScreen.taken(2))
assertEquals(2, calls)
DualScreen.unwatchTaken(listener)
DualScreen.setTaken(setOf(2))
shadowOf(Looper.getMainLooper()).idle()
assertEquals(2, calls)
}
}
@@ -29,6 +29,7 @@ class DualScreenTest {
@Test fun knownModelsCountWhenTheTypeIsHidden() {
assertTrue(DualScreen.isBuiltIn(null, "Retroid Pocket Duo"))
assertTrue(DualScreen.isBuiltIn(null, " AYN Thor "))
assertTrue(DualScreen.isBuiltIn(null, "AYN Thor Max"))
assertFalse(DualScreen.isBuiltIn(null, "Pixel 8"))
}
@@ -65,4 +66,19 @@ class DualScreenTest {
SessionPrefs.setDualScreenMode(context, DualScreen.MODE_OFF)
assertEquals(DualScreen.MODE_OFF, SessionPrefs.dualScreenMode(context))
}
@Test fun launcherAndSessionsKeepSeparateModes() {
SessionPrefs.setDualScreenMode(context, DualScreen.MODE_OFF)
assertEquals(DualScreen.MODE_OFF, SessionPrefs.dualScreenMode(context))
assertEquals(DualScreen.MODE_AUTO, SessionPrefs.dualScreenSessionMode(context))
SessionPrefs.setDualScreenSessionMode(context, DualScreen.MODE_ON)
assertEquals(DualScreen.MODE_OFF, SessionPrefs.dualScreenMode(context))
assertEquals(DualScreen.MODE_ON, SessionPrefs.dualScreenSessionMode(context))
}
@Test fun anOldDisabledMenuToggleTurnsBothOff() {
context.getSharedPreferences("session", Context.MODE_PRIVATE).edit().putBoolean("dualScreenLauncher", false).commit()
assertEquals(DualScreen.MODE_OFF, SessionPrefs.dualScreenMode(context))
assertEquals(DualScreen.MODE_OFF, SessionPrefs.dualScreenSessionMode(context))
}
}
@@ -259,6 +259,78 @@ class BattleNetTest {
BattleNet.hostFolder(context, "Z:/root/Games/Stores/Battle.net/Hearthstone/"))
}
@Test fun wowForeverIsListedBesideRetailInTheSharedWorldOfWarcraftFolder() {
val pfx = File(BattleNet.prefix(context), "pfx").apply { mkdirs() }
val wow = File(pfx, "drive_c/Program Files (x86)/World of Warcraft").apply { mkdirs() }
File(wow, "_retail_").mkdirs()
File(wow, "_forever_").mkdirs()
File(pfx, "drive_c/ProgramData/Battle.net/Agent").mkdirs()
File(pfx, "drive_c/ProgramData/Battle.net/Agent/product.db").writeBytes(message(
field(1, message(field(1, "wow"), field(2, "wow"), field(3, message(field(1, "C:/Program Files (x86)/World of Warcraft"))))),
field(1, message(field(1, "wow_forever"), field(2, "wowf"), field(3, message(field(1, "C:/Program Files (x86)/World of Warcraft"))))),
))
val games = BattleNet.games(context)
assertEquals(listOf("WoW", "WoWF"), games.map { it.code })
assertEquals(listOf(wow, File(wow, "_forever_")), games.map { it.folder })
assertEquals("World of Warcraft: Forever", games[1].name)
assertEquals(2, games.map { it.folder.canonicalPath }.distinct().size)
val shortcut = BattleNet.shortcut(context, games[1])!!
assertTrue(shortcut.launchOptions.endsWith("--exec=\"launch WoWF\""))
}
@Test fun anInstallWithAnUnknownUidIsListedByItsProductCode() {
val pfx = File(BattleNet.prefix(context), "pfx").apply { mkdirs() }
File(pfx, "drive_c/Games/World of Warcraft").mkdirs()
File(pfx, "drive_c/ProgramData/Battle.net/Agent").mkdirs()
File(pfx, "drive_c/ProgramData/Battle.net/Agent/product.db").writeBytes(message(
field(1, message(field(1, "wowf_live"), field(2, "wowf"), field(3, message(field(1, "C:/Games/World of Warcraft"))))),
field(1, message(field(1, "unknown_thing"), field(2, "nothing"), field(3, message(field(1, "C:/Games/World of Warcraft"))))),
))
val games = BattleNet.games(context)
assertEquals(listOf("WoWF"), games.map { it.code })
assertEquals("wowf_live", games[0].installUid)
assertEquals("wow_forever", games[0].uid)
assertEquals("WoWF", BattleNet.titleForProduct("WOWF")?.code)
assertEquals("WTCG", BattleNet.titleForProduct("wtcg")?.code)
assertNull(BattleNet.titleForProduct(""))
assertEquals(listOf(Triple("wowf_live", "C:/Games/World of Warcraft", "wowf")),
BattleNet.productDbInstalls(message(field(1, message(field(1, "wowf_live"), field(2, "wowf"), field(3, message(field(1, "C:/Games/World of Warcraft")))))))!!
.map { Triple(it.uid, it.path, it.product) })
}
@Test fun aGameKeepsTheFolderItWasListedWithWhenAnotherVersionComesOrGoes() {
val root = File(context.filesDir, "World of Warcraft").apply { mkdirs() }
val retailDir = File(root, "_retail_").apply { mkdirs() }
val foreverDir = File(root, "_forever_").apply { mkdirs() }
val wow = BattleNet.title("wow")!!
val forever = BattleNet.title("wow_forever")!!
val classic = BattleNet.title("wow_classic")!!
assertEquals(mapOf("WoWF" to root), BattleNet.ownFolders(mapOf("WoWF" to (forever to root)), mapOf("WoWF" to null)))
assertEquals(mapOf("WoW" to root, "WoWF" to foreverDir),
BattleNet.ownFolders(linkedMapOf("WoW" to (wow to root), "WoWF" to (forever to root)), mapOf("WoW" to null, "WoWF" to null)))
assertEquals(mapOf("WoWF" to foreverDir), BattleNet.ownFolders(mapOf("WoWF" to (forever to root)), mapOf("WoWF" to foreverDir.path)))
assertEquals(mapOf("WoW" to retailDir, "WoWC" to root),
BattleNet.ownFolders(linkedMapOf("WoW" to (wow to root), "WoWC" to (classic to root)), mapOf("WoW" to null, "WoWC" to root.path)))
assertEquals(mapOf("WoW" to root, "WoWC" to root),
BattleNet.ownFolders(linkedMapOf("WoW" to (wow to root), "WoWC" to (classic to root)), mapOf("WoW" to null, "WoWC" to null)))
assertEquals(mapOf("WoWF" to root), BattleNet.ownFolders(mapOf("WoWF" to (forever to root)), mapOf("WoWF" to "/elsewhere")))
}
@Test fun theListedFolderIsRememberedAcrossScans() {
val pfx = File(BattleNet.prefix(context), "pfx").apply { mkdirs() }
val wow = File(pfx, "drive_c/Program Files (x86)/World of Warcraft").apply { mkdirs() }
File(wow, "_forever_").mkdirs()
val db = File(pfx, "drive_c/ProgramData/Battle.net/Agent/product.db").apply { parentFile!!.mkdirs() }
val retail = field(1, message(field(1, "wow"), field(2, "wow"), field(3, message(field(1, "C:/Program Files (x86)/World of Warcraft")))))
val forever = field(1, message(field(1, "wow_forever"), field(2, "wowf"), field(3, message(field(1, "C:/Program Files (x86)/World of Warcraft")))))
db.writeBytes(message(retail, forever))
assertEquals(listOf(wow, File(wow, "_forever_")), BattleNet.games(context).map { it.folder })
db.writeBytes(message(forever))
assertEquals(listOf(File(wow, "_forever_")), BattleNet.games(context).map { it.folder })
db.writeBytes(message(forever, retail))
assertEquals(listOf(File(wow, "_forever_"), wow), BattleNet.games(context).map { it.folder })
}
@Test fun aGamesShortcutHasBattleNetLaunchItInItsPrefix() {
val folder = File(BattleNet.prefix(context), "pfx/drive_c/Program Files (x86)/Diablo IV").apply { mkdirs() }
File(folder, "Diablo IV Launcher.exe").writeBytes(byteArrayOf(0x4d, 0x5a))
@@ -291,6 +363,7 @@ class BattleNetTest {
assertEquals(codes.distinct(), codes)
assertTrue("Fen" in codes && "OSI" in codes && "WTCG" in codes)
assertFalse(BattleNet.STORE.any { it.uid == "d3cn" || it.uid == "fen" })
assertFalse(BattleNet.STORE.any { it.code == "WoWC" || it.code == "WoWF" })
assertEquals("fenris", BattleNet.STORE.first { it.code == "Fen" }.uid)
assertTrue(BattleNet.STORE.all { it.uid.matches(Regex("[a-z0-9_]{1,32}")) })
val installed = listOf("fenris", "diablo3_enus", null)
@@ -0,0 +1,32 @@
package com.droiddeck.launcher.runtime
import java.util.Locale
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
class DesktopLanguageTest {
private val sha = "a".repeat(64)
@Test fun indexListsPacksAndSkipsMalformedLines() {
val index = DesktopLanguage.parseIndex("pt_BR $sha 1200\ntr $sha 900\nbad line\nxx short 5\n")
assertEquals(setOf("pt_BR", "tr"), index.keys)
assertTrue(DesktopLanguage.parseIndex("../../x $sha 5\n").isEmpty())
assertEquals(1200L, index.getValue("pt_BR").size)
}
@Test fun regionPackThenBareLanguage() {
assertEquals(listOf("pt_BR", "pt"), DesktopLanguage.candidates(Locale.forLanguageTag("pt-BR")))
assertEquals(listOf("tr_TR", "tr"), DesktopLanguage.candidates(Locale.forLanguageTag("tr")))
assertEquals(listOf("zh_HK", "zh_TW", "zh"), DesktopLanguage.candidates(Locale.forLanguageTag("zh-HK")))
}
@Test fun englishAndUnknownNeedNoPack() {
assertTrue(DesktopLanguage.candidates(Locale.forLanguageTag("en")).isEmpty())
assertTrue(DesktopLanguage.candidates(Locale.forLanguageTag("sw")).isEmpty())
}
@Test fun packsLiveBesideTheDesktopArchive() {
assertEquals("https://h/r/t/", DesktopLanguage.baseUrl("https://h/r/t/desktop-kde.tar.zst"))
}
}
@@ -0,0 +1,25 @@
package com.droiddeck.launcher.session
import org.junit.Assert.assertEquals
import org.junit.Test
class BottomDesktopSizeTest {
@Test fun theDuosBottomPanelKeepsItsPixels() {
assertEquals(1280 to 848, desktopOutputSize(1280, 848, false, 720f))
}
@Test fun aLargerPanelRendersBelowItsResolution() {
assertEquals(826 to 646, desktopOutputSize(1240, 970, false, 720f))
assertEquals(1280 to 644, desktopOutputSize(1920, 968, false, 720f))
}
@Test fun theTopScreenAfterASwapGetsItsOwnPixelsAndTheWideShape() {
assertEquals(1920 to 968, desktopOutputSize(1920, 968, true, 720f))
assertEquals(1920 to 968, desktopOutputSize(1920, 969, true, 720f))
}
@Test fun noPanelNoSize() {
assertEquals(0 to 0, desktopOutputSize(0, 848, true, 720f))
assertEquals(0 to 0, desktopOutputSize(1280, 0, false, 720f))
}
}
@@ -0,0 +1,51 @@
package com.droiddeck.launcher.session
import com.droiddeck.launcher.core.AppLanguage
import java.util.Locale
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Test
class DesktopLocaleTest {
private fun lang(tag: String) = DesktopLocale.lang(Locale.forLanguageTag(tag))
@Test fun appLanguagesMapToGlibcLocales() {
assertEquals("en_US.UTF-8", lang("en"))
assertEquals("tr_TR.UTF-8", lang("tr"))
assertEquals("pt_BR.UTF-8", lang("pt-BR"))
assertEquals("pt_PT.UTF-8", lang("pt-PT"))
assertEquals("es_MX.UTF-8", lang("es-419"))
assertEquals("zh_CN.UTF-8", lang("zh-CN"))
assertEquals("zh_TW.UTF-8", lang("zh-TW"))
assertEquals("zh_HK.UTF-8", lang("zh-HK"))
}
@Test fun chineseScriptBeatsRegion() {
assertEquals("zh_CN.UTF-8", lang("zh-Hans-HK"))
assertEquals("zh_TW.UTF-8", lang("zh-Hant-CN"))
assertEquals("zh_TW.UTF-8", lang("zh-MO"))
assertEquals("zh_HK:zh_TW:zh", DesktopLocale.language(Locale.forLanguageTag("zh-HK")))
}
@Test fun systemRegionsSurvive() {
assertEquals("en_GB.UTF-8", lang("en-GB"))
assertEquals("fr_CA.UTF-8", lang("fr-CA"))
assertEquals("de_DE.UTF-8", lang("de-XX"))
}
@Test fun everyAppLanguageHasALocale() {
AppLanguage.supported.forEach { assertTrue(it, lang(it) != DesktopLocale.DEFAULT) }
}
@Test fun unknownLanguagesFallBack() {
assertEquals(DesktopLocale.DEFAULT, lang("sw"))
}
@Test fun languageListPrefersTheRegionThenTheLanguage() {
assertEquals("pt_BR:pt", DesktopLocale.language(Locale.forLanguageTag("pt-BR")))
assertEquals("tr_TR:tr", DesktopLocale.language(Locale.forLanguageTag("tr")))
assertEquals("en_US", DesktopLocale.language(Locale.forLanguageTag("en")))
assertNull(DesktopLocale.language(Locale.forLanguageTag("sw")))
}
}
@@ -0,0 +1,30 @@
package com.droiddeck.launcher.session
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Test
class GpuReaderStatusTest {
@After fun reset() {
KgslBusy.status = "not tried"
KgslClock.status = "not tried"
}
@Test fun emptyWhereTheReadersWereNotNeeded() {
assertEquals("", GpuStatsComponent.readerStatus())
}
@Test fun namesBothReaders() {
KgslBusy.status = "per-context stamps (hardware-scheduled kernel)"
KgslClock.status = "working (680 MHz at start)"
assertEquals(
"kgsl memstore per-context stamps (hardware-scheduled kernel); GPU cycle counter working (680 MHz at start)",
GpuStatsComponent.readerStatus(),
)
}
@Test fun rangeCheckFailureIsNamed() {
assertEquals("sample out of range", KgslErrors.describe(KgslClock.RANGE_CHECK_FAILED))
assertEquals("no error code", KgslErrors.describe(0))
}
}
@@ -65,6 +65,30 @@ class SteamLibrariesTest {
assertTrue(SteamLibraries.add(app, nested.path) is SteamLibraries.AddResult.Refused)
}
private fun library(dir: File): File = dir.apply { File(this, "steamapps").mkdirs(); File(this, "steamapps/appmanifest_220.acf").writeText("x") }
@Test fun pickingTheFolderAboveALibraryAddsTheLibraryInside() {
SessionPrefs.setGameStorage(app, SessionPrefs.GAME_STORAGE_OFF, "")
val app2 = tmp.newFolder("OtherApp")
library(File(app2, "Steam"))
val entry = (SteamLibraries.add(app, app2.path) as SteamLibraries.AddResult.Added).entry
assertEquals(File(app2, "Steam").path, entry.path)
assertEquals("OtherApp", entry.label)
val empty = tmp.newFolder("Empty")
assertEquals(empty.path, (SteamLibraries.add(app, empty.path) as SteamLibraries.AddResult.Added).entry.path)
}
@Test fun scanLooksTwoLevelsDownAndSkipsHiddenAndAppFolders() {
val volume = tmp.newFolder("volume")
val shallow = library(File(volume, "SteamLibrary"))
val deep = library(File(volume, "Some App/Steam"))
library(File(volume, "Android/data/x"))
library(File(volume, ".hidden/Steam"))
library(File(volume, "a/b/c"))
val withGames = SteamLibraries.candidates(volume, 2).filter { SteamLibraries.gameCount(it) > 0 }
assertEquals(setOf(shallow, deep), withGames.toSet())
}
@Test fun unreadableOrInvalidEntriesAreDropped() {
assertTrue(SteamLibraries.parse("{oops").isEmpty())
assertEquals(listOf("2"), SteamLibraries.parse("""[{"id":"../x","path":"/a"},{"id":"2","path":"/b","label":""}]""").map { it.id })
@@ -201,6 +201,15 @@ class StoreInstallRootTest {
assertTrue(StoreInstallRoot.unfinished(app).none { it.folder.absolutePath == half.absolutePath })
}
@Test fun aGameBeingUpdatedIsNotAnUnfinishedInstallForAnyStore() {
SessionPrefs.setGameStorage(app, SessionPrefs.GAME_STORAGE_OFF, "")
for (store in listOf(Store.EPIC, Store.ITCH, Store.XBOX, Store.AMAZON)) {
val folder = File(StoreInstallRoot.storeDir(StoreInstallRoot.internalRoot(app), store), StoreInstallRoot.folderName("Updating", "u1")).apply { mkdirs() }
StoreGameSidecar(store, "u1", "Updating", "Updating.exe", state = StoreGameSidecar.STATE_UPDATING).write(folder)
assertTrue(StoreInstallRoot.unfinished(app).none { it.folder.absolutePath == folder.absolutePath })
}
}
@Test fun theScratchCacheIsPrivateAndNamedSafely() {
val dir = StoreInstallRoot.scratchDir(app, Store.EPIC, "a/b:c")
assertTrue(dir.absolutePath.startsWith(app.cacheDir.absolutePath))
@@ -289,4 +298,9 @@ class StoreInstallRootTest {
assertFalse(StoreInstallRoot.insufficientSpace(1L, 1L))
assertFalse(StoreInstallRoot.insufficientSpace(0L, 0L))
}
@Test fun itchKeepsTheFolderItsGamesWereInstalledInWhateverItsDisplayName() {
assertEquals("itch", StoreInstallRoot.storeDir(File("/games"), Store.ITCH).name)
assertEquals("Game Jolt", StoreInstallRoot.storeDir(File("/games"), Store.GAMEJOLT).name)
}
}
@@ -0,0 +1,36 @@
package com.droiddeck.launcher.stores.gamejolt
import org.junit.Assert.assertEquals
import org.junit.Test
class GameJoltBrowseTest {
private fun qs(query: GameJoltQuery = GameJoltQuery(), page: Int = 1) = GameJoltBrowse.queryString(query, page)
@Test fun theDefaultQueryAsksForTheFeaturedSectionByName() {
assertEquals("section=featured", qs())
}
@Test fun sectionsPriceAndPagesUseTheSiteNames() {
assertEquals("section=hot", qs(GameJoltQuery(section = GameJoltBrowse.SECTION_HOT)))
assertEquals("section=featured&f_price=5-less&page=3", qs(GameJoltQuery(price = GameJoltBrowse.PRICE_UNDER_5), 3))
assertEquals("section=featured&f_price=free", qs(GameJoltQuery(price = GameJoltBrowse.PRICE_FREE)))
}
@Test fun listFiltersKeepTheSiteOrderWhateverTheSelectionOrder() {
assertEquals("section=featured&f_os%5B%5D=windows&f_os%5B%5D=linux", qs(GameJoltQuery(os = setOf("linux", "windows"))))
assertEquals("section=featured&f_browser%5B%5D=html&f_maturity%5B%5D=everyone&f_status%5B%5D=complete&f_partners%5B%5D=partners",
qs(GameJoltQuery(browser = setOf("html"), maturity = setOf("everyone"), status = setOf("complete"), partners = true)))
}
@Test fun devlogGamesAreNeverAskedFor() {
assertEquals(setOf("complete", "wip"), GameJoltBrowse.effective(GameJoltQuery(), true).status)
assertEquals(setOf("complete", "wip"), GameJoltBrowse.effective(GameJoltQuery(status = setOf("devlog")), true).status)
assertEquals(setOf("wip"), GameJoltBrowse.effective(GameJoltQuery(status = setOf("wip", "devlog")), false).status)
assertEquals("section=featured&f_status%5B%5D=complete&f_status%5B%5D=wip", qs(GameJoltBrowse.effective(GameJoltQuery(), true).copy(maturity = emptySet())))
}
@Test fun tagsAreSluggedAndRepeatable() {
assertEquals("co-op", GameJoltBrowse.tagSlug(" Co-Op "))
assertEquals("section=featured&tag=action&tag=co-op", qs(GameJoltQuery(tags = listOf("Action", "co op"))))
}
}
@@ -0,0 +1,41 @@
package com.droiddeck.launcher.stores.gamejolt
import org.json.JSONArray
import org.json.JSONObject
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 GameJoltBuildsTest {
private fun build(id: Int, pkg: Int, release: Int, name: String, vararg flags: String) = JSONObject()
.put("id", id).put("game_package_id", pkg).put("game_release_id", release)
.put("primary_file", JSONObject().put("filename", name).put("filesize", 100))
.also { b -> flags.forEach { b.put(it, true) } }
private fun payload(vararg builds: JSONObject) = JSONObject()
.put("packages", JSONArray().put(JSONObject().put("id", 1).put("title", "Main")))
.put("releases", JSONArray().put(JSONObject().put("id", 10).put("published_on", 100).put("version_number", "1.0")).put(JSONObject().put("id", 11).put("published_on", 200).put("version_number", "1.1")))
.put("builds", JSONArray(builds.toList()))
.put("launchOptions", JSONArray())
@Test fun onlyTheNewestReleaseOfAPackageIsKept() {
val list = GameJoltBuilds.parse(payload(build(1, 1, 10, "old.zip", "os_windows"), build(2, 1, 11, "new.zip", "os_windows")))
assertEquals(listOf("2"), list.map { it.id })
assertEquals("1.1", list.first().version)
}
@Test fun windowsBuildsAreInstallableAndSortFirst() {
val list = GameJoltBuilds.parse(payload(build(1, 1, 11, "game-linux.zip", "os_linux"), build(2, 1, 11, "game-win.zip", "os_windows")))
assertEquals(listOf("2", "1"), list.map { it.id })
assertTrue(list[0].installable)
assertFalse(list[1].installable)
}
@Test fun aBuildWithoutAnOsFlagIsWeb() {
assertEquals(setOf("web"), GameJoltBuilds.platforms(JSONObject()))
assertEquals(setOf("windows", "osx"), GameJoltBuilds.platforms(JSONObject().put("os_windows", true).put("os_mac", true)))
}
}
@@ -0,0 +1,28 @@
package com.droiddeck.launcher.stores.gamejolt
import org.json.JSONArray
import org.json.JSONObject
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Test
@org.junit.runner.RunWith(org.robolectric.RobolectricTestRunner::class)
@org.robolectric.annotation.Config(sdk = [33], application = android.app.Application::class)
class GameJoltCollectionsTest {
@Test fun playlistsBecomeCollectionsByIdAndName() {
val list = JSONArray()
.put(JSONObject().put("id", 7).put("name", "test list"))
.put(JSONObject().put("id", 0).put("name", "no id"))
.put(JSONObject().put("id", 9).put("name", ""))
val parsed = GameJoltCollections.parse(list)
assertEquals(listOf("playlist:7"), parsed.map { it.id })
assertEquals(listOf("test list"), parsed.map { it.title })
}
@Test fun eachCollectionHasItsOwnGameListEndpoint() {
assertEquals("/web/library/games/followed/@some+one", GameJoltCollections.path(GameJoltCollections.FOLLOWED, "some one"))
assertEquals("/web/library/games/playlist/7", GameJoltCollections.path("playlist:7", "x"))
assertNull(GameJoltCollections.path("playlist:abc", "x"))
assertNull(GameJoltCollections.path("other", "x"))
}
}
@@ -0,0 +1,52 @@
package com.droiddeck.launcher.stores.gamejolt
import org.json.JSONArray
import org.json.JSONObject
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Test
@org.junit.runner.RunWith(org.robolectric.RobolectricTestRunner::class)
@org.robolectric.annotation.Config(sdk = [33], application = android.app.Application::class)
class GameJoltPricingTest {
private fun pricing(amount: Long, promotional: Boolean = false, currency: Any = JSONObject.NULL) =
JSONObject().put("amount", amount).put("promotional", promotional).put("currency_code", currency)
private fun sellable(vararg pricings: JSONObject) = JSONObject().put("type", "paid").put("pricings", JSONArray(pricings.toList()))
@Test fun aRegularPriceIsShownInDollars() {
val price = GameJoltPricing.of(sellable(pricing(99)))!!
assertEquals("$0.99", price.final)
assertEquals("", price.original)
assertEquals(0, price.discount)
}
@Test fun aPromotionalPriceBesideTheRegularOneIsASale() {
val price = GameJoltPricing.of(sellable(pricing(500), pricing(350, promotional = true)))!!
assertEquals("$3.50", price.final)
assertEquals("$5.00", price.original)
assertEquals(30, price.discount)
}
@Test fun aPromotionalPriceAloneShowsNoDiscount() {
val price = GameJoltPricing.of(sellable(pricing(350, promotional = true)))!!
assertEquals("$3.50", price.final)
assertEquals("", price.original)
assertEquals(0, price.discount)
}
@Test fun aPromotionalPriceNotBelowTheRegularOneIsNotASale() {
val price = GameJoltPricing.of(sellable(pricing(500), pricing(500, promotional = true)))!!
assertEquals("", price.original)
assertEquals(0, price.discount)
}
@Test fun aGameWithoutPricingsHasNoPrice() {
assertNull(GameJoltPricing.of(sellable()))
assertNull(GameJoltPricing.of(null))
}
@Test fun anotherCurrencyIsNamed() {
assertEquals("1.50 EUR", GameJoltPricing.of(sellable(pricing(150, currency = "EUR")))!!.final)
}
}
@@ -0,0 +1,63 @@
package com.droiddeck.launcher.stores.gamejolt
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNull
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 GameJoltUpdatesTest {
private fun build(id: String, pkg: String, stamp: String, windows: Boolean = true, name: String = "game.zip") =
GameJoltBuild(id, pkg, "Main", "1.0", name, 100L, stamp, if (windows) setOf("windows") else setOf("linux"), "", "")
@Test fun aNewerReleaseOfTheSamePackageIsAnUpdate() {
val update = GameJoltUpdates.evaluate(listOf(build("20", "1", "200", name = "new.zip")), "10", "1", "100")!!
assertEquals("20", update.buildId)
assertEquals("new.zip", update.filename)
assertFalse(update.replaced)
}
@Test fun theInstalledBuildIsNotAnUpdate() {
assertNull(GameJoltUpdates.evaluate(listOf(build("10", "1", "100")), "10", "1", "100"))
}
@Test fun anOlderBuildIsNotAnUpdate() {
assertNull(GameJoltUpdates.evaluate(listOf(build("5", "1", "50")), "10", "1", "100"))
}
@Test fun theSameReleaseTimeWithAHigherBuildIdIsAnUpdate() {
assertEquals("11", GameJoltUpdates.evaluate(listOf(build("11", "1", "100")), "10", "1", "100")?.buildId)
}
@Test fun otherPackagesDoNotCount() {
assertEquals("30", GameJoltUpdates.evaluate(listOf(build("40", "2", "900"), build("30", "1", "300")), "10", "1", "100")?.buildId)
}
@Test fun aRemovedPackageFallsBackToTheNewPreferredBuildAndSaysSo() {
val update = GameJoltUpdates.evaluate(listOf(build("40", "2", "900")), "10", "1", "100")!!
assertEquals("40", update.buildId)
assertTrue(update.replaced)
}
@Test fun nonWindowsBuildsAreNeverOffered() {
assertNull(GameJoltUpdates.evaluate(listOf(build("40", "1", "900", windows = false)), "10", "1", "100"))
}
@Test fun nothingToCompareMeansNoUpdate() {
assertNull(GameJoltUpdates.evaluate(null, "10", "1", "100"))
assertNull(GameJoltUpdates.evaluate(listOf(build("40", "1", "900")), "", "1", "100"))
}
@Test fun foundUpdatesSurviveEncodingAndDropEntriesWithoutABuild() {
val saved = GameJoltUpdates.encode(mapOf("gamejolt:1" to GameJoltUpdate("20", "200", "new.zip", true)))
val back = GameJoltUpdates.decode(saved).getValue("gamejolt:1")
assertEquals("20", back.buildId)
assertEquals("200", back.stamp)
assertEquals("new.zip", back.filename)
assertTrue(back.replaced)
assertEquals(emptyMap<String, GameJoltUpdate>(), GameJoltUpdates.decode("""{"gamejolt:1":{"stamp":"1"}}"""))
assertEquals(emptyMap<String, GameJoltUpdate>(), GameJoltUpdates.decode("not json"))
}
}
@@ -0,0 +1,21 @@
package com.droiddeck.launcher.ui
import org.junit.Assert.assertEquals
import org.junit.Test
class BottomDesktopFitTest {
@Test fun aDesktopOfThePanelsShapeFillsThePanel() {
assertEquals(1280 to 870, fitDesktop(1280, 870, 1280, 870))
assertEquals(1280 to 870, fitDesktop(1280, 870, 1278, 868))
}
@Test fun aDesktopOfAnotherShapeIsFittedNotStretched() {
val (w, h) = fitDesktop(1920, 1016, 1280, 870)
assertEquals(1016, h)
assertEquals(1494, w)
}
@Test fun nothingToFitLeavesThePanelSize() {
assertEquals(1920 to 1016, fitDesktop(1920, 1016, 0, 0))
}
}
@@ -0,0 +1,35 @@
package com.droiddeck.launcher.ui
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
class GameScreenSwapTest {
private fun wanted(
requested: Boolean = true,
activityStarted: Boolean = true,
sessionEnded: Boolean = false,
inPip: Boolean = false,
glassesOutput: Boolean = false,
bottomScreenFree: Boolean = true,
) = GameScreenSwap.wanted(requested, activityStarted, sessionEnded, inPip, glassesOutput, bottomScreenFree)
@Test fun thePickedSwapPutsTheGameOnTheBottomScreen() {
assertTrue(wanted())
}
@Test fun withoutAPickTheGameStaysOnTop() {
assertFalse(wanted(requested = false))
}
@Test fun theGameComesBackToTheTopWhenTheSessionIsHiddenOrEnds() {
assertFalse(wanted(activityStarted = false))
assertFalse(wanted(sessionEnded = true))
assertFalse(wanted(inPip = true))
}
@Test fun glassesAndAHeldBottomScreenWin() {
assertFalse(wanted(glassesOutput = true))
assertFalse(wanted(bottomScreenFree = false))
}
}
@@ -87,6 +87,11 @@ class LibraryEntriesTest {
assertEquals(listOf("epic", "gog", "battlenet"), librarySources(entries, listOf("missing", "epic", "epic", "amazon")))
}
@Test fun aSignedInStoreWithNoGamesKeepsItsPlaceInTheStoreOrder() {
val entries = listOf("steam", "xbox").map { LibraryEntry(it, it, it, null, null, true) }
assertEquals(listOf("steam", "xbox", "itch", "gamejolt"), librarySources(entries, listOf("xbox", "itch", "gamejolt"), setOf("itch", "gamejolt")))
}
@Test fun gameKeysNameEitherAnAppOrAStoreProduct() {
GameRef.parse("app:440").let { assertEquals(440, it.appId); assertNull(it.store) }
GameRef.parse("app:-12").let { assertEquals(-12, it.appId) }