Rémi Bernon : dinput8/tests: Read the expected lengths from the registry.

Alexandre Julliard julliard at winehq.org
Fri Sep 10 15:29:46 CDT 2021


Module: wine
Branch: master
Commit: 03e68ae3fc683ab9a41ac7072a49c319c33877af
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=03e68ae3fc683ab9a41ac7072a49c319c33877af

Author: Rémi Bernon <rbernon at codeweavers.com>
Date:   Fri Sep 10 09:22:43 2021 +0200

dinput8/tests: Read the expected lengths from the registry.

Signed-off-by: Rémi Bernon <rbernon at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/dinput8/tests/driver_hid.c | 19 +++++++++----
 dlls/dinput8/tests/hid.c        | 61 ++++++++++++++++-------------------------
 2 files changed, 36 insertions(+), 44 deletions(-)

diff --git a/dlls/dinput8/tests/driver_hid.c b/dlls/dinput8/tests/driver_hid.c
index 06b223d1611..eefdc05d1a3 100644
--- a/dlls/dinput8/tests/driver_hid.c
+++ b/dlls/dinput8/tests/driver_hid.c
@@ -42,6 +42,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;
 
@@ -242,7 +243,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 );
 
@@ -266,7 +267,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 );
@@ -284,7 +285,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 );
 
@@ -303,7 +304,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 );
 
@@ -319,7 +320,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 );
 
@@ -337,7 +338,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 );
 
@@ -470,6 +471,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/dinput8/tests/hid.c b/dlls/dinput8/tests/hid.c
index 51b204c736d..4483a5ec479 100644
--- a/dlls/dinput8/tests/hid.c
+++ b/dlls/dinput8/tests/hid.c
@@ -724,41 +724,8 @@ static BOOL sync_ioctl( HANDLE file, DWORD code, void *in_buf, DWORD in_len, voi
     return ret;
 }
 
-static void test_hidp( HANDLE file, HANDLE async_file, int report_id, BOOL polled )
+static void test_hidp( HANDLE file, HANDLE async_file, int report_id, BOOL polled, const HIDP_CAPS *expect_caps )
 {
-    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[] =
     {
         {
@@ -942,7 +909,7 @@ static void test_hidp( HANDLE file, HANDLE async_file, int report_id, BOOL polle
     ok( status == HIDP_STATUS_INVALID_PREPARSED_DATA, "HidP_GetCaps returned %#x\n", status );
     status = HidP_GetCaps( preparsed_data, &caps );
     ok( status == HIDP_STATUS_SUCCESS, "HidP_GetCaps returned %#x\n", status );
-    check_hidp_caps( &caps, &expect_hidp_caps[report_id] );
+    check_hidp_caps( &caps, expect_caps );
 
     collection_count = 0;
     status = HidP_GetLinkCollectionNodes( collections, &collection_count, preparsed_data );
@@ -1883,7 +1850,7 @@ static void test_hidp( HANDLE file, HANDLE async_file, int report_id, BOOL polle
     HidD_FreePreparsedData( preparsed_data );
 }
 
-static void test_hid_device( DWORD report_id, DWORD polled )
+static void test_hid_device( DWORD report_id, DWORD polled, const HIDP_CAPS *expect_caps )
 {
     char buffer[FIELD_OFFSET( SP_DEVICE_INTERFACE_DETAIL_DATA_W, DevicePath[MAX_PATH] )];
     SP_DEVICE_INTERFACE_DATA iface = {sizeof(SP_DEVICE_INTERFACE_DATA)};
@@ -2038,7 +2005,7 @@ static void test_hid_device( DWORD report_id, DWORD polled )
         ok( poll_freq == 500, "got poll_freq %u, expected 500\n", poll_freq );
     }
 
-    test_hidp( file, async_file, report_id, polled );
+    test_hidp( file, async_file, report_id, polled, expect_caps );
 
     CloseHandle( async_file );
     CloseHandle( file );
@@ -2308,6 +2275,21 @@ static void test_hid_driver( DWORD report_id, DWORD polled )
         .ProductID = 0x0001,
         .VersionNumber = 0x0100,
     };
+    const HIDP_CAPS caps =
+    {
+        .Usage = HID_USAGE_GENERIC_JOYSTICK,
+        .UsagePage = HID_USAGE_PAGE_GENERIC,
+        .InputReportByteLength = report_id ? 25 : 26,
+        .OutputReportByteLength = report_id ? 2 : 3,
+        .FeatureReportByteLength = report_id ? 21 : 22,
+        .NumberLinkCollectionNodes = 10,
+        .NumberInputButtonCaps = 17,
+        .NumberInputValueCaps = 7,
+        .NumberInputDataIndices = 47,
+        .NumberFeatureButtonCaps = 1,
+        .NumberFeatureValueCaps = 6,
+        .NumberFeatureDataIndices = 8,
+    };
 
     WCHAR cwd[MAX_PATH], tempdir[MAX_PATH];
     LSTATUS status;
@@ -2333,7 +2315,10 @@ static void test_hid_driver( DWORD report_id, DWORD polled )
     status = RegSetValueExW( hkey, L"Attributes", 0, REG_BINARY, (void *)&attributes, sizeof(attributes) );
     ok( !status, "RegSetValueExW returned %#x\n", status );
 
-    if (pnp_driver_start( L"driver_hid.dll" )) test_hid_device( report_id, polled );
+    status = RegSetValueExW( hkey, L"Caps", 0, REG_BINARY, (void *)&caps, sizeof(caps) );
+    ok( !status, "RegSetValueExW returned %#x\n", status );
+
+    if (pnp_driver_start( L"driver_hid.dll" )) test_hid_device( report_id, polled, &caps );
 
     pnp_driver_stop();
     SetCurrentDirectoryW( cwd );




More information about the wine-cvs mailing list