mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-19 12:56:06 +00:00
Unify input profiles and configurable controller surfaces
This commit is contained in:
1 parent
906e0d1f7d
commit
ab8f41b80e
33 files changed
+2526
-198
No files matched your search
@@ -0,0 +1,64 @@
|
||||
package com.droiddeck.launcher.input
|
||||
|
||||
import android.content.Context
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Before
|
||||
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 = [34], manifest = Config.NONE)
|
||||
class InputProfilesTest {
|
||||
private val context: Context get() = RuntimeEnvironment.getApplication()
|
||||
@Before fun reset() {
|
||||
context.getSharedPreferences("input-profiles", Context.MODE_PRIVATE).edit().clear().commit()
|
||||
context.getSharedPreferences("controller", Context.MODE_PRIVATE).edit().clear().commit()
|
||||
context.getSharedPreferences("input-surfaces", Context.MODE_PRIVATE).edit().clear().commit()
|
||||
}
|
||||
|
||||
@Test fun migrationKeepsLegacyTouchMappingSeparateFromPhysicalControls() {
|
||||
ControllerPrefs.setTarget(context, "a", "b")
|
||||
ControllerPrefs.setTarget(context, "x", "off")
|
||||
ControllerPrefs.setSelectSteam(context, true)
|
||||
val game = InputProfiles.read(context, InputProfile.GAME)
|
||||
assertEquals(InputAction.Native(InputControl.B), game.action(InputRole.PRIMARY, InputControl.A))
|
||||
assertEquals(InputAction.Disabled, game.action(InputRole.PRIMARY, InputControl.X))
|
||||
assertEquals(InputAction.Native(), game.action(InputRole.PHYSICAL, InputControl.A))
|
||||
assertEquals(InputAction.Native(InputControl.GUIDE), game.action(InputRole.PHYSICAL, InputControl.SELECT))
|
||||
InputProfiles.reset(context, InputProfile.GAME)
|
||||
assertEquals(InputAction.Native(), InputProfiles.read(context, InputProfile.GAME).action(InputRole.PRIMARY, InputControl.A))
|
||||
}
|
||||
|
||||
@Test fun bindingsAndDeviceKeysRoundTripWithoutAffectingOtherProfile() {
|
||||
val game = InputProfile.defaults(InputProfile.GAME)
|
||||
.withBinding(InputRole.SECONDARY, InputControl.A, InputAction.Keys(listOf(29, 30)))
|
||||
.copy(keys = listOf(PhysicalInputBinding(PhysicalInputKey("1:2:descriptor", "Thor", 131, 59), InputAction.Command(InputCommand.MENU))))
|
||||
InputProfiles.save(context, game)
|
||||
assertEquals(game, InputProfiles.read(context, InputProfile.GAME))
|
||||
assertEquals(InputAction.Pointer(), InputProfiles.read(context, InputProfile.DESKTOP).action(InputRole.PHYSICAL, InputControl.LS))
|
||||
}
|
||||
|
||||
@Test fun profileSelectionIsExplicitAndNeverDependsOnDisplayPresence() {
|
||||
assertEquals(InputProfile.DESKTOP, InputProfiles.active(context, true).id)
|
||||
assertEquals(InputProfile.GAME, InputProfiles.active(context, false).id)
|
||||
InputProfiles.select(context, InputProfile.GAME)
|
||||
assertEquals(InputProfile.GAME, InputProfiles.active(context, true).id)
|
||||
}
|
||||
|
||||
@Test fun unknownVersionDoesNotExecuteBindings() {
|
||||
context.getSharedPreferences("input-profiles", Context.MODE_PRIVATE).edit()
|
||||
.putString("profile.game", """{"version":999,"bindings":[]} """).commit()
|
||||
assertEquals(InputProfile.defaults(InputProfile.GAME), InputProfiles.read(context, InputProfile.GAME))
|
||||
}
|
||||
|
||||
@Test fun layoutsPersistIndependentOfBindingsAndStayInsideScreen() {
|
||||
InputSurfaceLayout.save(context, InputProfile.GAME, listOf(InputSurfaceElement(InputControl.A, .95f, -.1f, 2f, 2f)))
|
||||
val element = InputSurfaceLayout.read(context, InputProfile.GAME).single()
|
||||
assertEquals(.9f, element.x); assertEquals(0f, element.y)
|
||||
assertTrue(element.x + element.width <= 1f)
|
||||
assertEquals(InputAction.Native(), InputProfiles.read(context, InputProfile.GAME).action(InputRole.SECONDARY, InputControl.A))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
package com.droiddeck.launcher.input
|
||||
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Test
|
||||
|
||||
class InputRouterTest {
|
||||
private class Output : InputOutput {
|
||||
val events = mutableListOf<String>()
|
||||
override fun key(code: Int, down: Boolean) { events += "key $code $down" }
|
||||
override fun button(code: Int, down: Boolean) { events += "button $code $down" }
|
||||
override fun pointer(dx: Float, dy: Float) { events += "pointer $dx $dy" }
|
||||
override fun scroll(steps: Int) { events += "scroll $steps" }
|
||||
override fun command(command: InputCommand) { events += command.name }
|
||||
override fun requestMotion() { events += "motion" }
|
||||
}
|
||||
private val output = Output()
|
||||
private val router = InputRouter(output)
|
||||
private fun bind(control: InputControl, action: InputAction, role: InputRole = InputRole.PHYSICAL) =
|
||||
InputProfile.defaults(InputProfile.GAME).withBinding(role, control, action)
|
||||
|
||||
@Test fun nativeProfileReturnsOriginalStateWithoutScheduling() {
|
||||
val source = router.pad(InputRole.PHYSICAL)
|
||||
val state = PadState().apply { leftX = .7f; press(PadState.A, true) }
|
||||
repeat(1000) { assertSame(state, source.route(state)) }
|
||||
assertTrue(output.events.isEmpty())
|
||||
}
|
||||
|
||||
@Test fun localBindingConsumesOnlyItsOwnNativeControlAndReleasesModifiersLast() {
|
||||
router.setProfile(bind(InputControl.A, InputAction.Keys(listOf(29, 30))))
|
||||
val source = router.pad(InputRole.PHYSICAL)
|
||||
val state = PadState().apply { press(PadState.A, true); press(PadState.B, true); leftX = .4f }
|
||||
val routed = source.route(state)
|
||||
assertFalse(routed.isDown(PadState.A)); assertTrue(routed.isDown(PadState.B))
|
||||
assertEquals(.4f, routed.leftX)
|
||||
source.route(state)
|
||||
state.press(PadState.A, false); source.route(state)
|
||||
assertEquals(listOf("key 29 true", "key 30 true", "key 30 false", "key 29 false"), output.events)
|
||||
}
|
||||
|
||||
@Test fun twoSourcesHoldingOneKeyDoNotReleaseEachOther() {
|
||||
val p = bind(InputControl.A, InputAction.Keys(listOf(57)))
|
||||
.withBinding(InputRole.SECONDARY, InputControl.B, InputAction.Keys(listOf(57)))
|
||||
router.setProfile(p)
|
||||
val physical = router.pad(InputRole.PHYSICAL)
|
||||
val touch = router.pad(InputRole.SECONDARY)
|
||||
physical.route(PadState().apply { press(PadState.A, true) })
|
||||
touch.route(PadState().apply { press(PadState.B, true) })
|
||||
touch.close()
|
||||
assertEquals(listOf("key 57 true"), output.events)
|
||||
physical.release()
|
||||
assertEquals(listOf("key 57 true", "key 57 false"), output.events)
|
||||
}
|
||||
|
||||
@Test fun remapCombinesHeldTargetsRatherThanLastButtonWinning() {
|
||||
router.setProfile(bind(InputControl.A, InputAction.Native(InputControl.B)))
|
||||
val source = router.pad(InputRole.PHYSICAL)
|
||||
val raw = PadState().apply { press(PadState.A, true) }
|
||||
assertTrue(source.route(raw).isDown(PadState.B))
|
||||
raw.press(PadState.B, true); raw.press(PadState.A, false)
|
||||
assertTrue(source.route(raw).isDown(PadState.B))
|
||||
raw.press(PadState.B, false)
|
||||
assertFalse(source.route(raw).isDown(PadState.B))
|
||||
}
|
||||
|
||||
@Test fun profileChangeBlocksHeldNativeInputUntilNeutral() {
|
||||
val source = router.pad(InputRole.PHYSICAL)
|
||||
val raw = PadState().apply { press(PadState.A, true) }
|
||||
source.route(raw)
|
||||
router.setProfile(bind(InputControl.A, InputAction.Keys(listOf(1))))
|
||||
source.route(raw)
|
||||
assertTrue(output.events.isEmpty())
|
||||
raw.press(PadState.A, false); source.route(raw)
|
||||
raw.press(PadState.A, true); source.route(raw)
|
||||
assertEquals(listOf("key 1 true"), output.events)
|
||||
}
|
||||
|
||||
@Test fun changingLocalBindingReleasesOldKeyWithoutPressingNewOne() {
|
||||
router.setProfile(bind(InputControl.A, InputAction.Keys(listOf(1))))
|
||||
val source = router.pad(InputRole.PHYSICAL)
|
||||
val raw = PadState().apply { press(PadState.A, true) }
|
||||
source.route(raw)
|
||||
router.setProfile(bind(InputControl.A, InputAction.Keys(listOf(28))))
|
||||
source.route(raw)
|
||||
assertEquals(listOf("key 1 true", "key 1 false"), output.events)
|
||||
}
|
||||
|
||||
@Test fun triggersUseHysteresisAndCommandsFireOnce() {
|
||||
router.setProfile(bind(InputControl.LT, InputAction.Command(InputCommand.MENU)))
|
||||
val source = router.pad(InputRole.PHYSICAL)
|
||||
val raw = PadState()
|
||||
for (value in listOf(.6f, .5f, .4f, .6f, .3f, .6f)) { raw.leftTrigger = value; source.route(raw) }
|
||||
assertEquals(listOf("MENU", "MENU"), output.events)
|
||||
}
|
||||
|
||||
@Test fun pointerTicksOnlyWhileMovingAndOrdinaryKeysDoNotWaitForTick() {
|
||||
router.setProfile(InputProfile.defaults(InputProfile.DESKTOP))
|
||||
val source = router.pad(InputRole.PHYSICAL)
|
||||
val raw = PadState().apply { leftX = 1f; press(PadState.X, true) }
|
||||
source.route(raw)
|
||||
assertTrue(output.events.contains("key 28 true"))
|
||||
assertFalse(output.events.any { it.startsWith("pointer") })
|
||||
assertTrue(router.tick(.01f)); assertTrue(output.events.contains("pointer 9.0 0.0"))
|
||||
raw.clear(); source.route(raw)
|
||||
assertFalse(router.tick(.01f))
|
||||
}
|
||||
|
||||
@Test fun trackpadUsesContactRelativeDeltasWithoutFirstTouchJump() {
|
||||
router.setProfile(bind(InputControl.RIGHT_PAD, InputAction.Pointer(1000f), InputRole.SECONDARY))
|
||||
val channel = router.channel(InputRole.SECONDARY, InputControl.RIGHT_PAD)
|
||||
assertNull(channel.update(.5f, .5f, true))
|
||||
assertTrue(output.events.isEmpty())
|
||||
channel.update(.6f, .6f, true)
|
||||
assertEquals(1, output.events.size)
|
||||
assertTrue(output.events[0].startsWith("pointer 100."))
|
||||
channel.update(0f, 0f, false)
|
||||
channel.update(-.9f, -.9f, true)
|
||||
assertEquals(1, output.events.size)
|
||||
}
|
||||
|
||||
@Test fun disablingRoutingReleasesKeysAndBlocksHeldInputOnResume() {
|
||||
router.setProfile(bind(InputControl.A, InputAction.Keys(listOf(1))))
|
||||
val source = router.pad(InputRole.PHYSICAL)
|
||||
val raw = PadState().apply { press(PadState.A, true) }
|
||||
source.route(raw); router.setEnabled(false); source.route(raw); router.setEnabled(true); source.route(raw)
|
||||
assertEquals(listOf("key 1 true", "key 1 false"), output.events)
|
||||
raw.clear(); source.route(raw); raw.press(PadState.A, true); source.route(raw)
|
||||
assertEquals("key 1 true", output.events.last())
|
||||
}
|
||||
|
||||
@Test fun disabledSourcesDoNotLeakNativeButtons() {
|
||||
val source = router.pad(InputRole.PHYSICAL)
|
||||
router.setEnabled(false)
|
||||
assertFalse(source.route(PadState().apply { press(PadState.A, true) }).isDown(PadState.A))
|
||||
}
|
||||
|
||||
@Test fun lifecycleReleaseAlsoBlocksNativeIdentityRoute() {
|
||||
val source = router.pad(InputRole.PHYSICAL)
|
||||
val raw = PadState().apply { press(PadState.A, true) }
|
||||
source.route(raw); router.releaseAll()
|
||||
assertFalse(source.route(raw).isDown(PadState.A))
|
||||
}
|
||||
|
||||
@Test fun mergedPadKeepsPhysicalButtonAndWholeStickVector() {
|
||||
val physical = PadState().apply { press(PadState.A, true); leftX = .8f; leftY = -.6f }
|
||||
physical.merge(PadState().apply { leftX = -.2f; leftY = .1f })
|
||||
assertTrue(physical.isDown(PadState.A)); assertEquals(.8f, physical.leftX); assertEquals(-.6f, physical.leftY)
|
||||
}
|
||||
|
||||
@Test fun outputOwnershipKeepsKeyboardAndMappingHoldsIndependent() {
|
||||
val held = HeldInput(output::key)
|
||||
held.set(1, 29, true); held.set(4, 29, true); held.release(4)
|
||||
assertEquals(listOf("key 29 true"), output.events)
|
||||
held.clear(); assertEquals("key 29 false", output.events.last())
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.droiddeck.launcher.input
|
||||
|
||||
import java.io.File
|
||||
import org.junit.Assert.*
|
||||
import org.junit.After
|
||||
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 = [34], manifest = Config.NONE, shadows = [JoyConPadTest.RecordingWriter::class])
|
||||
class InputSourceOwnershipTest {
|
||||
private val bridge = PadBridge(File(RuntimeEnvironment.getApplication().cacheDir, "input-ownership"))
|
||||
private fun state() = JoyConPadTest.RecordingWriter.pads[0]!!
|
||||
@After fun close() { bridge.stop(); DeckControls.releaseAll(); DeckControls.setRouter(null) }
|
||||
|
||||
@Test fun closingOneSurfaceDoesNotReleaseAnotherSurfaceOrPhysicalPad() {
|
||||
val a = Any(); val b = Any()
|
||||
bridge.applyExternal({ it.press(PadState.A, true) }, true)
|
||||
bridge.applyTouch(a, InputRole.PRIMARY) { it.press(PadState.A, true); it.press(PadState.B, true) }
|
||||
bridge.applyTouch(b, InputRole.SECONDARY) { it.press(PadState.X, true) }
|
||||
bridge.releaseTouch(a)
|
||||
assertTrue(state().isDown(PadState.A)); assertTrue(state().isDown(PadState.X)); assertFalse(state().isDown(PadState.B))
|
||||
bridge.releaseTouch(b)
|
||||
assertTrue(state().isDown(PadState.A)); assertFalse(state().isDown(PadState.X))
|
||||
}
|
||||
|
||||
@Test fun disconnectingSecondaryDeckSurfaceKeepsPhysicalGripHeld() {
|
||||
val surface = DeckControls.source(InputRole.SECONDARY)
|
||||
DeckControls.setGrip(DeckControls.L4, true)
|
||||
surface.setGrip(DeckControls.L4, true)
|
||||
surface.close()
|
||||
assertEquals(DeckControls.L4, JoyConPadTest.RecordingWriter.grips)
|
||||
DeckControls.setGrip(DeckControls.L4, false)
|
||||
assertEquals(0, JoyConPadTest.RecordingWriter.grips)
|
||||
}
|
||||
|
||||
@Test fun nativePadAndTouchMappingsUseDifferentRoles() {
|
||||
val output = object : InputOutput {
|
||||
override fun key(code: Int, down: Boolean) {}
|
||||
override fun button(code: Int, down: Boolean) {}
|
||||
override fun pointer(dx: Float, dy: Float) {}
|
||||
override fun scroll(steps: Int) {}
|
||||
override fun command(command: InputCommand) {}
|
||||
override fun requestMotion() {}
|
||||
}
|
||||
val router = InputRouter(output)
|
||||
bridge.setInputRouter(router)
|
||||
bridge.setInputProfile(InputProfile.defaults(InputProfile.GAME).withBinding(InputRole.SECONDARY, InputControl.A, InputAction.Disabled))
|
||||
val touch = Any()
|
||||
bridge.applyTouch(touch, InputRole.SECONDARY) { it.press(PadState.A, true) }
|
||||
assertFalse(state().isDown(PadState.A))
|
||||
bridge.applyExternal({ it.press(PadState.A, true) }, true)
|
||||
assertTrue(state().isDown(PadState.A))
|
||||
bridge.releaseAll()
|
||||
assertFalse(state().isDown(PadState.A))
|
||||
bridge.applyExternal({ it.press(PadState.B, true) }, true)
|
||||
assertFalse(state().isDown(PadState.A))
|
||||
assertTrue(state().isDown(PadState.B))
|
||||
bridge.applyExternal({ it.press(PadState.A, false) }, true)
|
||||
bridge.applyExternal({ it.press(PadState.A, true) }, true)
|
||||
assertTrue(state().isDown(PadState.A))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package com.droiddeck.launcher.input
|
||||
|
||||
import android.hardware.input.InputManager
|
||||
import android.view.InputDevice
|
||||
import android.view.KeyEvent
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.Shadows.shadowOf
|
||||
import org.robolectric.annotation.Config
|
||||
import org.robolectric.shadows.InputDeviceBuilder
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [34], manifest = Config.NONE, shadows = [PadBridgeRoutingTest.RegisteredKeyEvent::class])
|
||||
class PhysicalInputBindingsTest {
|
||||
private val events = ArrayList<String>()
|
||||
private val router = InputRouter(object : InputOutput {
|
||||
override fun key(code: Int, down: Boolean) { events += "$code $down" }
|
||||
override fun button(code: Int, down: Boolean) {}
|
||||
override fun pointer(dx: Float, dy: Float) {}
|
||||
override fun scroll(steps: Int) {}
|
||||
override fun command(command: InputCommand) { events += command.name }
|
||||
override fun requestMotion() {}
|
||||
})
|
||||
private val bindings = PhysicalInputBindings(router)
|
||||
|
||||
private fun device(id: Int): InputDevice {
|
||||
val device = InputDeviceBuilder.newBuilder().setId(id).setName("Thor extra keys").setDescriptor("keys-$id")
|
||||
.setSources(InputDevice.SOURCE_KEYBOARD).setKeyboardType(InputDevice.KEYBOARD_TYPE_NON_ALPHABETIC).build()
|
||||
val manager = RuntimeEnvironment.getApplication().getSystemService(InputManager::class.java)
|
||||
shadowOf(manager).addInputDevice(device)
|
||||
return device
|
||||
}
|
||||
private fun event(id: Int, down: Boolean, code: Int = KeyEvent.KEYCODE_F1, repeat: Int = 0) =
|
||||
KeyEvent(0L, 0L, if (down) KeyEvent.ACTION_DOWN else KeyEvent.ACTION_UP, code, repeat, 0, id, 59, 0, InputDevice.SOURCE_KEYBOARD)
|
||||
|
||||
@Test fun captureReservesSystemKeysButAcceptsKeyboardBackButtons() {
|
||||
val device = device(40)
|
||||
assertNotNull(PhysicalInputKey.capture(event(device.id, true)))
|
||||
assertNull(PhysicalInputKey.capture(event(device.id, true, KeyEvent.KEYCODE_VOLUME_UP)))
|
||||
assertNull(PhysicalInputKey.capture(event(device.id, true, KeyEvent.KEYCODE_HOME)))
|
||||
}
|
||||
|
||||
@Test fun bindingMatchesOnlyItsDeviceAndReleasesAfterEditingProfile() {
|
||||
val device = device(40); val other = device(41)
|
||||
val key = PhysicalInputKey.capture(event(device.id, true))!!
|
||||
bindings.configure(listOf(PhysicalInputBinding(key, InputAction.Keys(listOf(29, 30)))))
|
||||
assertFalse(bindings.onKey(event(other.id, true), true))
|
||||
assertTrue(bindings.onKey(event(device.id, true), true))
|
||||
bindings.configure(listOf(PhysicalInputBinding(key, InputAction.Keys(listOf(28)))))
|
||||
assertTrue(bindings.onKey(event(device.id, true, repeat = 1), true))
|
||||
assertTrue(bindings.onKey(event(device.id, false), true))
|
||||
assertEquals(listOf("29 true", "30 true", "30 false", "29 false"), events)
|
||||
bindings.onKey(event(device.id, true), true)
|
||||
assertEquals("28 true", events.last())
|
||||
}
|
||||
|
||||
@Test fun releasesRemainConsumedAfterOpeningMenuAndVirtualKeysAreUntouched() {
|
||||
val device = device(40)
|
||||
val key = PhysicalInputKey.capture(event(device.id, true))!!
|
||||
bindings.configure(listOf(PhysicalInputBinding(key, InputAction.Keys(listOf(57)))))
|
||||
assertFalse(bindings.onKey(event(-1, true), true))
|
||||
bindings.onKey(event(device.id, true), true)
|
||||
bindings.release()
|
||||
assertTrue(bindings.onKey(event(device.id, false), false))
|
||||
assertEquals(listOf("57 true", "57 false"), events)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.droiddeck.launcher.input
|
||||
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Test
|
||||
|
||||
class TritonInputRouterTest {
|
||||
private val events = ArrayList<String>()
|
||||
private val router = InputRouter(object : InputOutput {
|
||||
override fun key(code: Int, down: Boolean) { events += "$code $down" }
|
||||
override fun button(code: Int, down: Boolean) {}
|
||||
override fun pointer(dx: Float, dy: Float) {}
|
||||
override fun scroll(steps: Int) {}
|
||||
override fun command(command: InputCommand) {}
|
||||
override fun requestMotion() {}
|
||||
})
|
||||
|
||||
@Test fun nativeReportIsPassedThroughWithoutCopyingOrReencoding() {
|
||||
val adapter = TritonInputRouter(router)
|
||||
val bytes = ByteArray(64) { (it * 11).toByte() }
|
||||
assertSame(bytes, adapter.route(bytes))
|
||||
assertTrue(events.isEmpty())
|
||||
adapter.close()
|
||||
}
|
||||
|
||||
@Test fun consumedButtonDoesNotChangeOtherBitsAxesPressureMotionOrExtension() {
|
||||
router.setProfile(InputProfile.defaults(InputProfile.GAME).withBinding(InputRole.PHYSICAL, InputControl.A, InputAction.Keys(listOf(57))))
|
||||
val adapter = TritonInputRouter(router)
|
||||
val bytes = ByteArray(64) { (it * 7).toByte() }
|
||||
bytes[1] = (bytes[1].toInt() or 1).toByte()
|
||||
val expected = bytes.copyOf().apply { this[1] = (this[1].toInt() and 1.inv()).toByte() }
|
||||
assertArrayEquals(expected, adapter.route(bytes))
|
||||
assertEquals(listOf("57 true"), events)
|
||||
adapter.release()
|
||||
assertEquals(listOf("57 true", "57 false"), events)
|
||||
}
|
||||
|
||||
@Test fun switchingProfileWhileNativeButtonHeldRequiresRelease() {
|
||||
val adapter = TritonInputRouter(router)
|
||||
val held = ByteArray(45).apply { this[1] = 1 }
|
||||
adapter.route(held)
|
||||
router.setProfile(InputProfile.defaults(InputProfile.GAME).withBinding(InputRole.PHYSICAL, InputControl.A, InputAction.Keys(listOf(57))))
|
||||
adapter.route(held)
|
||||
assertTrue(events.isEmpty())
|
||||
adapter.route(ByteArray(45)); adapter.route(held)
|
||||
assertEquals(listOf("57 true"), events)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import android.content.Context
|
||||
import androidx.compose.ui.test.*
|
||||
import com.droiddeck.launcher.input.*
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.annotation.Config
|
||||
import org.robolectric.annotation.GraphicsMode
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [28], qualifiers = "w1000dp-h900dp")
|
||||
@GraphicsMode(GraphicsMode.Mode.NATIVE)
|
||||
class InputSettingsTest {
|
||||
@get:Rule val compose = createRobolectricComposeRule()
|
||||
private val context get() = RuntimeEnvironment.getApplication()
|
||||
@Before fun reset() {
|
||||
context.getSharedPreferences("input-profiles", Context.MODE_PRIVATE).edit().clear().commit()
|
||||
context.getSharedPreferences("input-surfaces", Context.MODE_PRIVATE).edit().clear().commit()
|
||||
context.getSharedPreferences("controller", Context.MODE_PRIVATE).edit().clear().commit()
|
||||
}
|
||||
|
||||
@Test fun bindingEditorPersistsDisabledWithoutChangingTouchControls() {
|
||||
var changed = false
|
||||
compose.setContent { DroidDeckTheme { InputSettingsPage({}, { changed = true }) } }
|
||||
compose.onNodeWithTag("input-binding-a").performScrollTo().performClick()
|
||||
compose.onNodeWithText("Disabled", substring = false).performScrollTo().performClick()
|
||||
compose.runOnIdle {
|
||||
assertTrue(changed)
|
||||
val profile = InputProfiles.read(context, InputProfile.GAME)
|
||||
assertEquals(InputAction.Disabled, profile.action(InputRole.PHYSICAL, InputControl.A))
|
||||
assertEquals(InputAction.Native(), profile.action(InputRole.SECONDARY, InputControl.A))
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun customLayoutAddsExistingControlAndKeepsProfileBindings() {
|
||||
var changed = false
|
||||
compose.setContent { DroidDeckTheme { InputSurfaceDialog(InputProfile.GAME, {}, { changed = true }) } }
|
||||
compose.onNodeWithText("Add control").performScrollTo().performClick()
|
||||
compose.onNodeWithText("R1", substring = false).performScrollTo().performClick()
|
||||
compose.onNodeWithText("Save changes").performClick()
|
||||
compose.runOnIdle {
|
||||
assertTrue(changed)
|
||||
assertTrue(InputSurfaceLayout.read(context, InputProfile.GAME).any { it.control == InputControl.RB })
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user