Skip to content
Merged
18 changes: 9 additions & 9 deletions Assets/Tests/InputSystem/Plugins/HIDTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@
(id, commandPtr) =>
{
if (commandPtr == null)
return InputDeviceCommand.GenericFailure;

Check warning on line 302 in Assets/Tests/InputSystem/Plugins/HIDTests.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Assets/Tests/InputSystem/Plugins/HIDTests.cs#L302

Added line #L302 was not covered by tests

if (commandPtr->type == HID.QueryHIDReportDescriptorSizeDeviceCommandType)
return reportDescriptor.Length;
Expand Down Expand Up @@ -342,10 +342,14 @@
[TestCase(24, new byte[] {0x15, 0x00}, new byte[] {0x27, 0xFF, 0xFF, 0xFF, 0x00}, 0, 16777215)]
// Logical min -8388608, logical max 8388607 (24 bit)
[TestCase(24, new byte[] {0x17, 0x00, 0x00, 0x80, 0xFF}, new byte[] {0x27, 0xFF, 0xFF, 0x7F, 0x00}, -8388608, 8388607)]
public void Devices_CanParseHIDDescritpor_WithSignedLogicalMinAndMaxSticks(byte reportSizeBits, byte[] logicalMinBytes, byte[] logicalMaxBytes, int logicalMinExpected, int logicalMaxExpected)
{
// Dynamically create HID report descriptor for two analog sticks with parameterized logical min/max
// Logical min -72, logical max -35
[TestCase(8, new byte[] {0x15, 0xB8}, new byte[] {0x25, 0xDD}, -72, -35)]
// Logical min 30, logical max 78
[TestCase(8, new byte[] {0x15, 0x1E}, new byte[] {0x25, 0x4E}, 30, 78)]

public void Devices_CanParseHIDDescriptor_WithSignedLogicalMinAndMaxValues(byte reportSizeBits, byte[] logicalMinBytes, byte[] logicalMaxBytes, int logicalMinExpected, int logicalMaxExpected)
{
// Dynamically create HID report descriptor for one X-axis with parameterized logical min/max
var reportDescriptorStart = new byte[]
{
0x05, 0x01, // Usage Page (Generic Desktop Ctrls)
Expand Down Expand Up @@ -393,9 +397,8 @@

InputSystem.Update();

var device = (Joystick)InputSystem.GetDeviceById(deviceId);
var device = InputSystem.GetDeviceById(deviceId);
Assert.That(device, Is.Not.Null);
Assert.That(device, Is.TypeOf<Joystick>());

var parsedDescriptor = JsonUtility.FromJson<HID.HIDDeviceDescriptor>(device.description.capabilities);

Expand All @@ -408,11 +411,8 @@
Assert.That(element.logicalMax, Is.EqualTo(logicalMaxExpected));
}
else
Assert.Fail("Could not find X and Y elements in descriptor");
Assert.Fail("Could not find X element in descriptor");

Check warning on line 414 in Assets/Tests/InputSystem/Plugins/HIDTests.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Assets/Tests/InputSystem/Plugins/HIDTests.cs#L414

Added line #L414 was not covered by tests
}

// Stick vector 2 should be centered at (0,0) when initialized
Assert.That(device.stick.ReadValue(), Is.EqualTo(new Vector2(0f, 0f)).Using(Vector2EqualityComparer.Instance));
Copy link
Collaborator Author

@jfreire-unity jfreire-unity Oct 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this to limit this test to parsing the report descriptor logical values. We have other problems reported in https://jira.unity3d.com/browse/ISXB-1737 when reading values and this would expand the scope of the test.

This is basically because we only seem to support values centered around 0 in the report size bit value range. Those are the only ones being read properly.

}

[Test]
Expand Down