Skip to content

Commit 2908eee

Browse files
Add tests for Switch face buttons (hid + ios)
1 parent 9ab29ab commit 2908eee

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

Assets/Tests/InputSystem/Plugins/iOSTests.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,60 @@ public void Devices_SupportsiOSGamePad(string product, Type deviceType, Type par
5656
Assert.That(gamepad.rightTrigger.ReadValue(), Is.EqualTo(0.456).Within(0.000001));
5757

5858
AssertButtonPress(gamepad, new iOSGameControllerState().WithButton(iOSButton.A), gamepad.buttonSouth);
59+
AssertButtonPress(gamepad, new iOSGameControllerState().WithButton(iOSButton.A), gamepad.aButton);
5960
AssertButtonPress(gamepad, new iOSGameControllerState().WithButton(iOSButton.X), gamepad.buttonWest);
61+
AssertButtonPress(gamepad, new iOSGameControllerState().WithButton(iOSButton.X), gamepad.xButton);
6062
AssertButtonPress(gamepad, new iOSGameControllerState().WithButton(iOSButton.Y), gamepad.buttonNorth);
63+
AssertButtonPress(gamepad, new iOSGameControllerState().WithButton(iOSButton.Y), gamepad.yButton);
6164
AssertButtonPress(gamepad, new iOSGameControllerState().WithButton(iOSButton.B), gamepad.buttonEast);
65+
AssertButtonPress(gamepad, new iOSGameControllerState().WithButton(iOSButton.B), gamepad.bButton);
6266
AssertButtonPress(gamepad, new iOSGameControllerState().WithButton(iOSButton.LeftShoulder), gamepad.leftShoulder);
6367
AssertButtonPress(gamepad, new iOSGameControllerState().WithButton(iOSButton.RightShoulder), gamepad.rightShoulder);
6468
}
6569

70+
[Test]
71+
[Category("Devices")]
72+
// this is a new test, as we need to assert the Nintendo layout (e.g. buttonSouth == B button)
73+
public void Devices_SupportsProControlleriOS()
74+
{
75+
var device = InputSystem.AddDevice(
76+
new InputDeviceDescription
77+
{
78+
interfaceName = "iOS",
79+
deviceClass = "iOSGameController",
80+
product = "Pro Controller"
81+
});
82+
Assert.That(device, Is.TypeOf(typeof(SwitchProControlleriOS)));
83+
Assert.That(device, Is.InstanceOf(typeof(Gamepad)));
84+
85+
var gamepad = (SwitchProControlleriOS)device;
86+
87+
InputSystem.QueueStateEvent(gamepad,
88+
new iOSGameControllerStateSwappedFaceButtons()
89+
.WithButton(iOSButton.LeftTrigger, true, 0.123f)
90+
.WithButton(iOSButton.RightTrigger, true, 0.456f)
91+
.WithAxis(iOSAxis.LeftStickX, 0.789f)
92+
.WithAxis(iOSAxis.LeftStickY, 0.987f)
93+
.WithAxis(iOSAxis.RightStickX, 0.654f)
94+
.WithAxis(iOSAxis.RightStickY, 0.321f));
95+
InputSystem.Update();
96+
97+
var leftStickDeadzone = gamepad.leftStick.TryGetProcessor<StickDeadzoneProcessor>();
98+
var rightStickDeadzone = gamepad.leftStick.TryGetProcessor<StickDeadzoneProcessor>();
99+
100+
Assert.That(gamepad.leftStick.ReadValue(), Is.EqualTo(leftStickDeadzone.Process(new Vector2(0.789f, 0.987f))));
101+
Assert.That(gamepad.rightStick.ReadValue(), Is.EqualTo(rightStickDeadzone.Process(new Vector2(0.654f, 0.321f))));
102+
Assert.That(gamepad.leftTrigger.ReadValue(), Is.EqualTo(0.123).Within(0.000001));
103+
Assert.That(gamepad.rightTrigger.ReadValue(), Is.EqualTo(0.456).Within(0.000001));
104+
// testing for Pro Controller layout...
105+
AssertButtonPress(gamepad, new iOSGameControllerStateSwappedFaceButtons().WithButton(iOSButton.A), gamepad.buttonEast);
106+
AssertButtonPress(gamepad, new iOSGameControllerStateSwappedFaceButtons().WithButton(iOSButton.X), gamepad.buttonNorth);
107+
AssertButtonPress(gamepad, new iOSGameControllerStateSwappedFaceButtons().WithButton(iOSButton.Y), gamepad.buttonWest);
108+
AssertButtonPress(gamepad, new iOSGameControllerStateSwappedFaceButtons().WithButton(iOSButton.B), gamepad.buttonSouth);
109+
AssertButtonPress(gamepad, new iOSGameControllerStateSwappedFaceButtons().WithButton(iOSButton.LeftShoulder), gamepad.leftShoulder);
110+
AssertButtonPress(gamepad, new iOSGameControllerStateSwappedFaceButtons().WithButton(iOSButton.RightShoulder), gamepad.rightShoulder);
111+
}
112+
66113
[Test]
67114
[Category("Devices")]
68115
[TestCase("Gravity", typeof(GravitySensor))]

Assets/Tests/InputSystem/SwitchTests.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,13 @@ public void Devices_SupportsHIDNpad()
5656
Assert.That(currentRight, Is.EqualTo(expectedRight).Using(new Vector2EqualityComparer(0.01f)));
5757

5858
AssertButtonPress(controller, StateWithButton(SwitchProControllerHIDInputState.Button.A), controller.buttonEast);
59+
AssertButtonPress(controller, StateWithButton(SwitchProControllerHIDInputState.Button.A), controller.aButton);
5960
AssertButtonPress(controller, StateWithButton(SwitchProControllerHIDInputState.Button.B), controller.buttonSouth);
61+
AssertButtonPress(controller, StateWithButton(SwitchProControllerHIDInputState.Button.B), controller.bButton);
6062
AssertButtonPress(controller, StateWithButton(SwitchProControllerHIDInputState.Button.X), controller.buttonNorth);
63+
AssertButtonPress(controller, StateWithButton(SwitchProControllerHIDInputState.Button.X), controller.xButton);
6164
AssertButtonPress(controller, StateWithButton(SwitchProControllerHIDInputState.Button.Y), controller.buttonWest);
65+
AssertButtonPress(controller, StateWithButton(SwitchProControllerHIDInputState.Button.Y), controller.yButton);
6266
AssertButtonPress(controller, StateWithButton(SwitchProControllerHIDInputState.Button.StickL), controller.leftStickButton);
6367
AssertButtonPress(controller, StateWithButton(SwitchProControllerHIDInputState.Button.StickR), controller.rightStickButton);
6468
AssertButtonPress(controller, StateWithButton(SwitchProControllerHIDInputState.Button.L), controller.leftShoulder);

0 commit comments

Comments
 (0)