Skip to content

Commit 59e6563

Browse files
committed
Add automated test to establish layout mapping
1 parent 41d5a3f commit 59e6563

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

Assets/Tests/InputSystem/Plugins/XInputTests.cs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using UnityEngine.InputSystem.Layouts;
66
using UnityEngine.InputSystem.Utilities;
77
using System.Runtime.InteropServices;
8+
using UnityEngine.InputSystem.HID;
89
using UnityEngine.InputSystem.Processors;
910

1011
#if UNITY_EDITOR_WIN || UNITY_EDITOR_OSX || UNITY_XBOXONE || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN
@@ -148,6 +149,63 @@ public void Devices_SupportXboxControllerOnOSX()
148149
AssertButtonPress(gamepad, new XInputControllerOSXState().WithButton(XInputControllerOSXState.Button.Select), gamepad.selectButton);
149150
}
150151

152+
[TestCase(0x045e, 0x02e0, 16, 11)] // Xbox One Wireless Controller
153+
[TestCase(0x045e, 0x02fd, 10, 11)] // Xbox Series X|S Wireless Controller
154+
// This test is used to establish the correct button map layout based on the PID and VIDs
155+
// If the layout is changed this test will fail and will need to be adapted either with a new device/layout or
156+
// a new button map.
157+
public void Devices_SupportWirelessXboxOneAndSeriesControllerOnOSX(int vendorId, int productId, int selectBit, int startBit)
158+
{
159+
// Fake a real Xbox Wireless Controller
160+
var xboxGamepad = InputSystem.AddDevice(new InputDeviceDescription
161+
{
162+
interfaceName = "HID",
163+
product = "Xbox Wireless Controller",
164+
manufacturer = "Microsoft",
165+
capabilities = new HID.HIDDeviceDescriptor
166+
{
167+
vendorId = vendorId,
168+
productId = productId,
169+
}.ToJson()
170+
});
171+
172+
173+
Assert.That(xboxGamepad, Is.AssignableTo<XInputController>());
174+
175+
var gamepad = (XInputController)xboxGamepad;
176+
Assert.That(gamepad.selectButton.isPressed, Is.False);
177+
178+
// Check if the controller is an Xbox One from a particular type where we know the select and start buttons are
179+
// different
180+
if (productId == 0x02e0)
181+
{
182+
Assert.That(xboxGamepad, Is.AssignableTo<XboxOneGampadMacOSWireless>());
183+
184+
InputSystem.QueueStateEvent(gamepad,
185+
new XInputControllerWirelessOSXState
186+
{
187+
buttons = (uint)(1 << selectBit |
188+
1 << startBit)
189+
});
190+
InputSystem.Update();
191+
}
192+
else
193+
{
194+
Assert.That(xboxGamepad, Is.AssignableTo<XboxGamepadMacOSWireless>());
195+
196+
InputSystem.QueueStateEvent(gamepad,
197+
new XInputControllerWirelessOSXState
198+
{
199+
buttons = (uint)(1 << selectBit |
200+
1 << startBit)
201+
});
202+
InputSystem.Update();
203+
}
204+
205+
Assert.That(gamepad.selectButton.isPressed);
206+
Assert.That(gamepad.startButton.isPressed);
207+
}
208+
151209
// Disable tests in standalone builds from 2022.1+ see UUM-19622
152210
#if !UNITY_STANDALONE_OSX || !TEMP_DISABLE_STANDALONE_OSX_XINPUT_TEST
153211
[Test]

0 commit comments

Comments
 (0)