mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-19 12:56:06 +00:00
Fix routed QAM publication and redundant input state writes
This commit is contained in:
1 parent
92b4361100
commit
ed121f247c
6 files changed
+85
-6
No files matched your search
@@ -37,6 +37,47 @@ class InputSourceOwnershipTest {
|
||||
assertFalse(state().isDown(PadState.A))
|
||||
}
|
||||
|
||||
@Test fun repeatedEnableStateDoesNotRepublishPadOrDeckReports() {
|
||||
val router = InputRouter(RecordingOutput())
|
||||
bridge.setInputRouter(router)
|
||||
DeckControls.setRouter(router)
|
||||
bridge.applyExternal({ it.press(PadState.A, true) }, true)
|
||||
DeckControls.setGrip(DeckControls.L4, true)
|
||||
for (enabled in listOf(true, false, true)) {
|
||||
bridge.setInputEnabled(enabled)
|
||||
val padWrites = JoyConPadTest.RecordingWriter.padWrites
|
||||
val deckWrites = JoyConPadTest.RecordingWriter.deckWrites
|
||||
repeat(10) { bridge.setInputEnabled(enabled) }
|
||||
assertEquals(padWrites, JoyConPadTest.RecordingWriter.padWrites)
|
||||
assertEquals(deckWrites, JoyConPadTest.RecordingWriter.deckWrites)
|
||||
}
|
||||
assertFalse(state().isDown(PadState.A))
|
||||
assertEquals(0, JoyConPadTest.RecordingWriter.grips)
|
||||
bridge.applyExternal({ it.press(PadState.A, false) }, true)
|
||||
DeckControls.setGrip(DeckControls.L4, false)
|
||||
bridge.applyExternal({ it.press(PadState.A, true) }, true)
|
||||
DeckControls.setGrip(DeckControls.L4, true)
|
||||
assertTrue(state().isDown(PadState.A))
|
||||
assertEquals(DeckControls.L4, JoyConPadTest.RecordingWriter.grips)
|
||||
}
|
||||
|
||||
@Test fun replacingADisabledRouterAllowsTheNewRouterToBeDisabled() {
|
||||
bridge.setInputRouter(InputRouter(RecordingOutput()))
|
||||
bridge.setInputEnabled(false)
|
||||
bridge.setInputRouter(InputRouter(RecordingOutput()))
|
||||
bridge.applyExternal({ it.press(PadState.A, true) }, true)
|
||||
assertTrue(state().isDown(PadState.A))
|
||||
bridge.setInputEnabled(false)
|
||||
assertFalse(state().isDown(PadState.A))
|
||||
}
|
||||
|
||||
@Test fun attachingADisabledRouterAllowsItToBeEnabled() {
|
||||
bridge.setInputRouter(InputRouter(RecordingOutput()).also { it.setEnabled(false) })
|
||||
bridge.setInputEnabled(true)
|
||||
bridge.applyExternal({ it.press(PadState.A, true) }, true)
|
||||
assertTrue(state().isDown(PadState.A))
|
||||
}
|
||||
|
||||
@Test fun replacingRouterReleasesRetainedPhysicalAndTouchHoldsUntilNeutral() {
|
||||
val before = RecordingOutput()
|
||||
val after = RecordingOutput()
|
||||
|
||||
@@ -240,10 +240,15 @@ class JoyConPadTest {
|
||||
@Implementation fun open(): Boolean = true
|
||||
@Implementation fun close() = Unit
|
||||
@Implementation fun destroy() = Unit
|
||||
@Implementation fun writePad(state: PadState) { pads[slot] = PadState().apply { copyFrom(state) } }
|
||||
@Implementation fun writePad(state: PadState) {
|
||||
pads[slot] = PadState().apply { copyFrom(state) }
|
||||
padWrites++
|
||||
}
|
||||
|
||||
companion object {
|
||||
val pads = HashMap<Int, PadState>()
|
||||
var padWrites = 0
|
||||
var deckWrites = 0
|
||||
var grips = 0
|
||||
var deckPads = ShortArray(4)
|
||||
|
||||
@@ -253,6 +258,7 @@ class JoyConPadTest {
|
||||
fun writeDeckControls(slot: Int, controls: Int, pads: ShortArray, pressure: ShortArray) {
|
||||
grips = controls
|
||||
deckPads = pads.copyOf()
|
||||
deckWrites++
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -385,6 +385,25 @@ class PadBridgeQamTest {
|
||||
assertEquals(0f, pad().leftX)
|
||||
}
|
||||
|
||||
@Test fun routedQamDuringAnActiveChordPublishesOtherInputImmediately() {
|
||||
ReflectionHelpers.setStaticField(FakeInputWriter::class.java, "padType", FakeInputWriter.PAD_TYPE_XBOX)
|
||||
routed(InputProfile.defaults(InputProfile.GAME)
|
||||
.withBinding(InputRole.PHYSICAL, InputControl.X, InputAction.Native(InputControl.QAM)))
|
||||
bridge.triggerQam()
|
||||
assertTrue(pad().isDown(PadState.GUIDE))
|
||||
bridge.applyExternal({ it.press(PadState.X, true); it.press(PadState.B, true); it.leftX = .6f }, true)
|
||||
assertTrue(pad().isDown(PadState.GUIDE))
|
||||
assertTrue(pad().isDown(PadState.B))
|
||||
assertEquals(.6f, pad().leftX)
|
||||
assertFalse(pad().isDown(PadState.QAM))
|
||||
bridge.applyExternal({ it.press(PadState.X, false); it.press(PadState.B, false); it.leftX = 0f }, true)
|
||||
assertFalse(pad().isDown(PadState.B))
|
||||
assertEquals(0f, pad().leftX)
|
||||
advanceTime()
|
||||
assertFalse(pad().isDown(PadState.GUIDE))
|
||||
assertFalse(pad().isDown(PadState.A))
|
||||
}
|
||||
|
||||
@Test fun queuedChordsKeepRoutedAndTouchAxesInsteadOfRawPhysicalAxes() {
|
||||
routed(InputProfile.defaults(InputProfile.GAME)
|
||||
.withBinding(InputRole.PHYSICAL, InputControl.LS, InputAction.Native(InputControl.RS)))
|
||||
|
||||
Reference in new issue
Block a user