mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-19 04:46:08 +00:00
Add opt-in GOG achievements through Comet (#651)
This commit is contained in:
1 parent
3ed756b067
commit
8f36eb7f54
35 files changed
+1364
-45
No files matched your search
@@ -0,0 +1,29 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Test
|
||||
|
||||
class SessionAchievementGameTest {
|
||||
private val installed = setOf(10L, 20L)
|
||||
|
||||
@Test fun exitingGameCannotRemainSelectedWithoutItsWindow() {
|
||||
assertNull(SessionAchievementGame.activeAppId(10, listOf(769), installed))
|
||||
}
|
||||
|
||||
@Test fun steamOverlayKeepsTheRunningGameSelected() {
|
||||
assertEquals(10L, SessionAchievementGame.activeAppId(769, listOf(769, 10), installed))
|
||||
}
|
||||
|
||||
@Test fun anotherForegroundAppCannotBorrowABackgroundGamesAchievements() {
|
||||
assertNull(SessionAchievementGame.activeAppId(30, listOf(30, 10), installed))
|
||||
}
|
||||
|
||||
@Test fun ambiguousBackgroundGamesDoNotPickAnArbitraryGame() {
|
||||
assertNull(SessionAchievementGame.activeAppId(769, listOf(769, 10, 20), installed))
|
||||
}
|
||||
|
||||
@Test fun theForegroundGameWinsWhenSeveralGamesAreRunning() {
|
||||
assertEquals(20L, SessionAchievementGame.activeAppId(20, listOf(769, 10, 20), installed))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.droiddeck.launcher.stores
|
||||
|
||||
import android.os.Looper
|
||||
import org.json.JSONObject
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Before
|
||||
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(sdk = [33])
|
||||
class AchievementNotificationsTest {
|
||||
private val unlock = AchievementNotifications.Unlock("123", "first", "First Steps", "", null, "Hollow Valley")
|
||||
private fun drain() = shadowOf(Looper.getMainLooper()).idle()
|
||||
|
||||
@Before fun reset() { AchievementNotifications.begin("test"); drain() }
|
||||
|
||||
@Test fun duplicatesAndOldSessionEventsDoNotQueue() {
|
||||
AchievementNotifications.unlock("old", unlock)
|
||||
AchievementNotifications.unlock("test", unlock)
|
||||
AchievementNotifications.unlock("test", unlock.copy(name = "Repeated"))
|
||||
drain()
|
||||
assertEquals(listOf(unlock), AchievementNotifications.pending)
|
||||
}
|
||||
|
||||
@Test fun oldTeardownAndDismissCannotRemoveReplacementUnlock() {
|
||||
AchievementNotifications.unlock("test", unlock); drain()
|
||||
AchievementNotifications.begin("replacement")
|
||||
val replacement = unlock.copy(id = "second")
|
||||
AchievementNotifications.unlock("replacement", replacement)
|
||||
AchievementNotifications.end("test"); drain()
|
||||
AchievementNotifications.dismiss(unlock)
|
||||
assertEquals(listOf(replacement), AchievementNotifications.pending)
|
||||
AchievementNotifications.end("replacement"); drain()
|
||||
assertTrue(AchievementNotifications.pending.isEmpty())
|
||||
}
|
||||
|
||||
@Test fun burstIsBoundedAndKeepsOrder() {
|
||||
repeat(30) { AchievementNotifications.unlock("test", unlock.copy(id = "$it")) }; drain()
|
||||
assertEquals((0..15).map { "$it" }, AchievementNotifications.pending.map { it.id })
|
||||
AchievementNotifications.dismiss(AchievementNotifications.pending.first())
|
||||
assertEquals("1", AchievementNotifications.pending.first().id)
|
||||
}
|
||||
|
||||
@Test fun malformedEventsAndNonHttpsIconsAreRejected() {
|
||||
assertNull(AchievementNotifications.parse(JSONObject().put("client_id", "123"), ""))
|
||||
val event = JSONObject().put("client_id", "123").put("id", "first").put("name", "First Steps").put("icon", "file:///private/icon")
|
||||
assertNull(AchievementNotifications.parse(event, "Game")!!.icon)
|
||||
event.put("client_id", "null")
|
||||
assertNull(AchievementNotifications.parse(event, "Game"))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.droiddeck.launcher.stores
|
||||
|
||||
import com.droiddeck.launcher.session.SessionState
|
||||
import com.droiddeck.launcher.stores.gog.GogComet
|
||||
import org.junit.After
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.annotation.Config
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [33])
|
||||
class GogCometGenerationTest {
|
||||
@After fun reset() {
|
||||
GogComet.end(SessionState.sessionId)
|
||||
SessionState.running = false
|
||||
SessionState.sessionId = null
|
||||
}
|
||||
|
||||
@Test fun anOldTeardownCannotDisableTheReplacementSession() {
|
||||
SessionState.running = true
|
||||
SessionState.sessionId = "old"
|
||||
GogComet.begin()
|
||||
SessionState.sessionId = "replacement"
|
||||
GogComet.begin()
|
||||
GogComet.end("old")
|
||||
val app = RuntimeEnvironment.getApplication()
|
||||
assertEquals("no-game", GogComet.prepare(app, "missing").getString("reason"))
|
||||
GogComet.end("replacement")
|
||||
assertEquals("no-session", GogComet.prepare(app, "missing").getString("reason"))
|
||||
}
|
||||
}
|
||||
@@ -74,6 +74,16 @@ class StoreGameSidecarTest {
|
||||
assertEquals(null, StoreGameSidecar.updateEpic(java.io.File(folder, "missing")) { it })
|
||||
}
|
||||
|
||||
@Test fun gogAchievementsAreIndependentOfCloudAndSurviveEdits() {
|
||||
val folder = java.io.File(org.robolectric.RuntimeEnvironment.getApplication().filesDir, "gog-achievements").apply { mkdirs() }
|
||||
StoreGameSidecar(Store.GOG, "1", "Game", "game.exe", cloud = false).write(folder)
|
||||
assertTrue(StoreGameSidecar.read(folder)!!.achievements)
|
||||
StoreGameSidecar.updateAchievements(folder, false)
|
||||
StoreGameSidecar.updateCloud(folder, true)
|
||||
assertFalse(StoreGameSidecar.read(folder)!!.achievements)
|
||||
assertTrue(StoreGameSidecar.read(folder)!!.cloud)
|
||||
}
|
||||
|
||||
@Test fun anInstallUnderWayHasNoExeYetAndIsNotInstalled() {
|
||||
val started = StoreGameSidecar(Store.EPIC, "Metalstorm", "Metalstorm", exe = "", state = StoreGameSidecar.STATE_INSTALLING)
|
||||
val back = StoreGameSidecar.parse(started.toJson().toString())!!
|
||||
|
||||
Reference in new issue
Block a user