[PATCH 08/10] hid/tests: Read the expected lengths from the registry.

Rémi Bernon rbernon at codeweavers.com
Thu Sep 2 02:24:22 CDT 2021


Signed-off-by: Rémi Bernon <rbernon at codeweavers.com>
---
 dlls/ntoskrnl.exe/tests/driver_hid.c | 19 +++++---
 dlls/ntoskrnl.exe/tests/ntoskrnl.c   | 70 +++++++++++++++-------------
 2 files changed, 50 insertions(+), 39 deletions(-)

diff --git a/dlls/ntoskrnl.exe/tests/driver_hid.c b/dlls/ntoskrnl.exe/tests/driver_hid.c
index 7819c5556bb..a525d845569 100644
--- a/dlls/ntoskrnl.exe/tests/driver_hid.c
+++ b/dlls/ntoskrnl.exe/tests/driver_hid.c
@@ -43,6 +43,7 @@ static unsigned int got_start_device;
 static HID_DEVICE_ATTRIBUTES attributes;
 static char report_descriptor_buf[4096];
 static DWORD report_descriptor_len;
+static HIDP_CAPS caps;
 static DWORD report_id;
 static DWORD polled;
 
@@ -244,7 +245,7 @@ static NTSTATUS WINAPI driver_internal_ioctl(DEVICE_OBJECT *device, IRP *irp)
 
         case IOCTL_HID_READ_REPORT:
         {
-            ULONG expected_size = 25;
+            ULONG expected_size = caps.InputReportByteLength - (report_id ? 0 : 1);
             ok(!in_size, "got input size %u\n", in_size);
             ok(out_size == expected_size, "got output size %u\n", out_size);
 
@@ -268,7 +269,7 @@ static NTSTATUS WINAPI driver_internal_ioctl(DEVICE_OBJECT *device, IRP *irp)
         case IOCTL_HID_WRITE_REPORT:
         {
             HID_XFER_PACKET *packet = irp->UserBuffer;
-            ULONG expected_size = 2;
+            ULONG expected_size = caps.OutputReportByteLength - (report_id ? 0 : 1);
 
             ok(in_size == sizeof(*packet), "got input size %u\n", in_size);
             ok(!out_size, "got output size %u\n", out_size);
@@ -287,7 +288,7 @@ static NTSTATUS WINAPI driver_internal_ioctl(DEVICE_OBJECT *device, IRP *irp)
         case IOCTL_HID_GET_INPUT_REPORT:
         {
             HID_XFER_PACKET *packet = irp->UserBuffer;
-            ULONG expected_size = 23;
+            ULONG expected_size = caps.InputReportByteLength - (report_id ? 0 : 1);
             ok(!in_size, "got input size %u\n", in_size);
             ok(out_size == sizeof(*packet), "got output size %u\n", out_size);
 
@@ -306,7 +307,7 @@ static NTSTATUS WINAPI driver_internal_ioctl(DEVICE_OBJECT *device, IRP *irp)
         case IOCTL_HID_SET_OUTPUT_REPORT:
         {
             HID_XFER_PACKET *packet = irp->UserBuffer;
-            ULONG expected_size = 2;
+            ULONG expected_size = caps.OutputReportByteLength - (report_id ? 0 : 1);
             ok(in_size == sizeof(*packet), "got input size %u\n", in_size);
             ok(!out_size, "got output size %u\n", out_size);
 
@@ -322,7 +323,7 @@ static NTSTATUS WINAPI driver_internal_ioctl(DEVICE_OBJECT *device, IRP *irp)
         case IOCTL_HID_GET_FEATURE:
         {
             HID_XFER_PACKET *packet = irp->UserBuffer;
-            ULONG expected_size = 17;
+            ULONG expected_size = caps.FeatureReportByteLength - (report_id ? 0 : 1);
             ok(!in_size, "got input size %u\n", in_size);
             ok(out_size == sizeof(*packet), "got output size %u\n", out_size);
 
@@ -340,7 +341,7 @@ static NTSTATUS WINAPI driver_internal_ioctl(DEVICE_OBJECT *device, IRP *irp)
         case IOCTL_HID_SET_FEATURE:
         {
             HID_XFER_PACKET *packet = irp->UserBuffer;
-            ULONG expected_size = 17;
+            ULONG expected_size = caps.FeatureReportByteLength - (report_id ? 0 : 1);
             ok(in_size == sizeof(*packet), "got input size %u\n", in_size);
             ok(!out_size, "got output size %u\n", out_size);
 
@@ -473,6 +474,12 @@ NTSTATUS WINAPI DriverEntry(DRIVER_OBJECT *driver, UNICODE_STRING *registry)
     ok(!ret, "ZwQueryValueKey returned %#x\n", ret);
     memcpy(&attributes, buffer + info_size, size - info_size);
 
+    RtlInitUnicodeString(&name_str, L"Caps");
+    size = info_size + sizeof(caps);
+    ret = ZwQueryValueKey(hkey, &name_str, KeyValuePartialInformation, buffer, size, &size);
+    ok(!ret, "ZwQueryValueKey returned %#x\n", ret);
+    memcpy(&caps, buffer + info_size, size - info_size);
+
     driver->DriverExtension->AddDevice = driver_add_device;
     driver->DriverUnload = driver_unload;
     driver->MajorFunction[IRP_MJ_PNP] = driver_pnp;
diff --git a/dlls/ntoskrnl.exe/tests/ntoskrnl.c b/dlls/ntoskrnl.exe/tests/ntoskrnl.c
index b80927b6999..4bafc786f87 100644
--- a/dlls/ntoskrnl.exe/tests/ntoskrnl.c
+++ b/dlls/ntoskrnl.exe/tests/ntoskrnl.c
@@ -2014,41 +2014,42 @@ static BOOL sync_ioctl(HANDLE file, DWORD code, void *in_buf, DWORD in_len, void
     return ret;
 }
 
+static const HIDP_CAPS expect_hidp_caps[] =
+{
+    /* without report id */
+    {
+        .Usage = HID_USAGE_GENERIC_JOYSTICK,
+        .UsagePage = HID_USAGE_PAGE_GENERIC,
+        .InputReportByteLength = 26,
+        .OutputReportByteLength = 3,
+        .FeatureReportByteLength = 22,
+        .NumberLinkCollectionNodes = 10,
+        .NumberInputButtonCaps = 17,
+        .NumberInputValueCaps = 7,
+        .NumberInputDataIndices = 47,
+        .NumberFeatureButtonCaps = 1,
+        .NumberFeatureValueCaps = 6,
+        .NumberFeatureDataIndices = 8,
+    },
+    /* with report id */
+    {
+        .Usage = HID_USAGE_GENERIC_JOYSTICK,
+        .UsagePage = HID_USAGE_PAGE_GENERIC,
+        .InputReportByteLength = 25,
+        .OutputReportByteLength = 2,
+        .FeatureReportByteLength = 21,
+        .NumberLinkCollectionNodes = 10,
+        .NumberInputButtonCaps = 17,
+        .NumberInputValueCaps = 7,
+        .NumberInputDataIndices = 47,
+        .NumberFeatureButtonCaps = 1,
+        .NumberFeatureValueCaps = 6,
+        .NumberFeatureDataIndices = 8,
+    },
+};
+
 static void test_hidp(HANDLE file, HANDLE async_file, int report_id, BOOL polled)
 {
-    const HIDP_CAPS expect_hidp_caps[] =
-    {
-        /* without report id */
-        {
-            .Usage = HID_USAGE_GENERIC_JOYSTICK,
-            .UsagePage = HID_USAGE_PAGE_GENERIC,
-            .InputReportByteLength = 26,
-            .OutputReportByteLength = 3,
-            .FeatureReportByteLength = 22,
-            .NumberLinkCollectionNodes = 10,
-            .NumberInputButtonCaps = 17,
-            .NumberInputValueCaps = 7,
-            .NumberInputDataIndices = 47,
-            .NumberFeatureButtonCaps = 1,
-            .NumberFeatureValueCaps = 6,
-            .NumberFeatureDataIndices = 8,
-        },
-        /* with report id */
-        {
-            .Usage = HID_USAGE_GENERIC_JOYSTICK,
-            .UsagePage = HID_USAGE_PAGE_GENERIC,
-            .InputReportByteLength = 25,
-            .OutputReportByteLength = 2,
-            .FeatureReportByteLength = 21,
-            .NumberLinkCollectionNodes = 10,
-            .NumberInputButtonCaps = 17,
-            .NumberInputValueCaps = 7,
-            .NumberInputDataIndices = 47,
-            .NumberFeatureButtonCaps = 1,
-            .NumberFeatureValueCaps = 6,
-            .NumberFeatureDataIndices = 8,
-        },
-    };
     const HIDP_BUTTON_CAPS expect_button_caps[] =
     {
         {
@@ -3609,6 +3610,9 @@ static void test_hid_driver(struct testsign_context *ctx, DWORD report_id, DWORD
     status = RegSetValueExW(hkey, L"Attributes", 0, REG_BINARY, (void *)&attributes, sizeof(attributes));
     ok(!status, "RegSetValueExW returned %#x\n", status);
 
+    status = RegSetValueExW(hkey, L"Caps", 0, REG_BINARY, (void *)&expect_hidp_caps[report_id], sizeof(*expect_hidp_caps));
+    ok(!status, "RegSetValueExW returned %#x\n", status);
+
     driver_start(ctx, L"driver_hid.dll");
     test_hid_device(report_id, polled);
     driver_stop();
-- 
2.33.0




More information about the wine-devel mailing list