Skip to content

Commit 828dbc9

Browse files
committed
Expand testing cases
1 parent 7bba345 commit 828dbc9

1 file changed

Lines changed: 19 additions & 9 deletions

File tree

Assets/Tests/InputSystem/Plugins/HIDTests.cs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,9 @@ unsafe void SetDeviceCommandCallbackToReturnReportDescriptor(int deviceId, byte[
298298
runtime.SetDeviceCommandCallback(deviceId,
299299
(id, commandPtr) =>
300300
{
301+
if (commandPtr == null)
302+
return InputDeviceCommand.GenericFailure;
303+
301304
if (commandPtr->type == HID.QueryHIDReportDescriptorSizeDeviceCommandType)
302305
return reportDescriptor.Length;
303306

@@ -317,22 +320,29 @@ unsafe void SetDeviceCommandCallbackToReturnReportDescriptor(int deviceId, byte[
317320

318321
[Test]
319322
[Category("HID Devices")]
320-
321323
// These descriptor values were generated with the Microsoft HID Authoring descriptor tool in
322-
// https://github.com/microsoft/hidtools for the expexted values.
324+
// https://github.com/microsoft/hidtools for the expected value:
323325
// Logical min 0, logical max 65535
324-
[TestCase(16, new byte[] {0x16, 0x00, 0x00}, new byte[] { 0x27, 0xFF, 0xFF, 0x00, 0x00 }, 0, 65535, 0.01f)]
326+
[TestCase(16, new byte[] {0x16, 0x00, 0x00}, new byte[] { 0x27, 0xFF, 0xFF, 0x00, 0x00 }, 0, 65535)]
325327
// Logical min -32768, logical max 32767
326-
[TestCase(16, new byte[] {0x16, 0x00, 0x80}, new byte[] {0x26, 0xFF, 0x7F}, -32768, 32767, 0.01f)]
328+
[TestCase(16, new byte[] {0x16, 0x00, 0x80}, new byte[] {0x26, 0xFF, 0x7F}, -32768, 32767)]
327329
// Logical min 0, logical max 255
328-
[TestCase(8, new byte[] {0x15, 00}, new byte[] {0x26, 0xFF, 0x00}, 0, 255, 0.01f)]
330+
[TestCase(8, new byte[] {0x15, 00}, new byte[] {0x26, 0xFF, 0x00}, 0, 255)]
329331
// Logical min -128, logical max 127
330-
[TestCase(8, new byte[] {0x15, 0x80}, new byte[] {0x25, 0x7F}, -128, 127, 0.01f)]
332+
[TestCase(8, new byte[] {0x15, 0x80}, new byte[] {0x25, 0x7F}, -128, 127)]
331333
// Logical min -16, logical max 15 (below 8 bit boundary)
332-
[TestCase(5, new byte[] {0x15, 0xF0}, new byte[] {0x25, 0x0F}, -16, 15, 0)]
334+
[TestCase(5, new byte[] {0x15, 0xF0}, new byte[] {0x25, 0x0F}, -16, 15)]
333335
// Logical min 0, logical max 31 (below 8 bit boundary)
334-
[TestCase(5, new byte[] {0x15, 0x00}, new byte[] {0x25, 0x1F}, 0, 31, 0)]
335-
public void Devices_CanParseHIDDescritpor_WithSignedLogicalMinAndMaxSticks(byte reportSizeBits, byte[] logicalMinBytes, byte[] logicalMaxBytes, int logicalMinExpected, int logicalMaxExpected, float errorMargin)
336+
[TestCase(5, new byte[] {0x15, 0x00}, new byte[] {0x25, 0x1F}, 0, 31)]
337+
// Logical min -4096, logical max 4095 (crosses byte boundary)
338+
[TestCase(13, new byte[] {0x16, 0x00, 0xF0}, new byte[] {0x26, 0xFF, 0x0F}, -4096, 4095)]
339+
// Logical min 0, logical max 8191 (crosses byte boundary)
340+
[TestCase(13, new byte[] {0x15, 0x00}, new byte[] {0x26, 0xFF, 0x1F}, 0, 8191)]
341+
// Logical min 0, logical max 16777215 (24 bit)
342+
[TestCase(24, new byte[] {0x15, 0x00}, new byte[] {0x27, 0xFF, 0xFF, 0xFF, 0x00}, 0, 16777215)]
343+
// Logical min -8388608, logical max 8388607 (24 bit)
344+
[TestCase(24, new byte[] {0x17, 0x00, 0x00, 0x80, 0xFF}, new byte[] {0x27, 0xFF, 0xFF, 0x7F, 0x00}, -8388608, 8388607)]
345+
public void Devices_CanParseHIDDescritpor_WithSignedLogicalMinAndMaxSticks(byte reportSizeBits, byte[] logicalMinBytes, byte[] logicalMaxBytes, int logicalMinExpected, int logicalMaxExpected)
336346
{
337347
// Dynamically create HID report descriptor for two analog sticks with parameterized logical min/max
338348

0 commit comments

Comments
 (0)