[PATCH 5/6] dinput/tests: Run keyboard info tests for every dinput version.

Rémi Bernon wine at gitlab.winehq.org
Fri Jun 10 03:55:27 CDT 2022


From: Rémi Bernon <rbernon at codeweavers.com>

Signed-off-by: Rémi Bernon <rbernon at codeweavers.com>
---
 dlls/dinput/tests/device8.c  |  51 ++++++++++++------
 dlls/dinput/tests/keyboard.c | 101 -----------------------------------
 2 files changed, 34 insertions(+), 118 deletions(-)

diff --git a/dlls/dinput/tests/device8.c b/dlls/dinput/tests/device8.c
index 08fccd00551..7ad3f98af24 100644
--- a/dlls/dinput/tests/device8.c
+++ b/dlls/dinput/tests/device8.c
@@ -2047,13 +2047,14 @@ static void test_sys_mouse( DWORD version )
     localized = old_localized;
 }
 
-static void test_keyboard_info(void)
+static void test_sys_keyboard( DWORD version )
 {
-    static const DIDEVCAPS expect_caps =
+    const DIDEVCAPS expect_caps =
     {
         .dwSize = sizeof(DIDEVCAPS),
         .dwFlags = DIDC_ATTACHED | DIDC_EMULATED,
-        .dwDevType = (DI8DEVTYPEKEYBOARD_PCENH << 8) | DI8DEVTYPE_KEYBOARD,
+        .dwDevType = version < 0x800 ? (DIDEVTYPEKEYBOARD_PCENH << 8) | DIDEVTYPE_KEYBOARD
+                                     : (DI8DEVTYPEKEYBOARD_PCENH << 8) | DI8DEVTYPE_KEYBOARD,
         .dwButtons = 128,
     };
     const DIDEVICEINSTANCEW expect_devinst =
@@ -2061,7 +2062,8 @@ static void test_keyboard_info(void)
         .dwSize = sizeof(DIDEVICEINSTANCEW),
         .guidInstance = GUID_SysKeyboard,
         .guidProduct = GUID_SysKeyboard,
-        .dwDevType = (DI8DEVTYPEKEYBOARD_PCENH << 8) | DI8DEVTYPE_KEYBOARD,
+        .dwDevType = version < 0x800 ? (DIDEVTYPEKEYBOARD_PCENH << 8) | DIDEVTYPE_KEYBOARD
+                                     : (DI8DEVTYPEKEYBOARD_PCENH << 8) | DI8DEVTYPE_KEYBOARD,
         .tszInstanceName = L"Keyboard",
         .tszProductName = L"Keyboard",
         .guidFFDriver = GUID_NULL,
@@ -2151,21 +2153,19 @@ static void test_keyboard_info(void)
     };
     DIDEVICEOBJECTINSTANCEW objinst = {0};
     DIDEVICEINSTANCEW devinst = {0};
+    BOOL old_localized = localized;
     IDirectInputDevice8W *device;
     DIDEVCAPS caps = {0};
-    IDirectInput8W *di;
     ULONG res, ref;
     HRESULT hr;
     GUID guid;
 
-    localized = TRUE; /* Skip name tests, Wine sometimes succeeds depending on the host key names */
+    if (FAILED(create_dinput_device( version, &GUID_SysKeyboard, &device ))) return;
 
-    hr = DirectInput8Create( instance, DIRECTINPUT_VERSION, &IID_IDirectInput8W, (void **)&di, NULL );
-    ok( hr == DI_OK, "DirectInput8Create returned %#lx\n", hr );
-    hr = IDirectInput8_CreateDevice( di, &GUID_SysKeyboard, &device, NULL );
-    ok( hr == DI_OK, "CreateDevice returned %#lx\n", hr );
+    localized = TRUE; /* Skip name tests, Wine sometimes succeeds depending on the host key names */
+    winetest_push_context( "%#lx", version );
 
-    hr = IDirectInputDevice8_Initialize( device, instance, DIRECTINPUT_VERSION, &GUID_SysKeyboardEm );
+    hr = IDirectInputDevice8_Initialize( device, instance, version, &GUID_SysKeyboardEm );
     ok( hr == DI_OK, "Initialize returned %#lx\n", hr );
     guid = GUID_SysKeyboardEm;
     memset( &devinst, 0, sizeof(devinst) );
@@ -2175,7 +2175,7 @@ static void test_keyboard_info(void)
     ok( IsEqualGUID( &guid, &GUID_SysKeyboardEm ), "got %s expected %s\n", debugstr_guid( &guid ),
         debugstr_guid( &GUID_SysKeyboardEm ) );
 
-    hr = IDirectInputDevice8_Initialize( device, instance, DIRECTINPUT_VERSION, &GUID_SysKeyboard );
+    hr = IDirectInputDevice8_Initialize( device, instance, version, &GUID_SysKeyboard );
     ok( hr == DI_OK, "Initialize returned %#lx\n", hr );
 
     memset( &devinst, 0, sizeof(devinst) );
@@ -2192,6 +2192,15 @@ static void test_keyboard_info(void)
     check_member( devinst, expect_devinst, "%04x", wUsagePage );
     check_member( devinst, expect_devinst, "%04x", wUsage );
 
+    devinst.dwSize = sizeof(DIDEVICEINSTANCE_DX3W);
+    hr = IDirectInputDevice8_GetDeviceInfo( device, &devinst );
+    ok( hr == DI_OK, "GetDeviceInfo returned %#lx\n", hr );
+    check_member_guid( devinst, expect_devinst, guidInstance );
+    check_member_guid( devinst, expect_devinst, guidProduct );
+    check_member( devinst, expect_devinst, "%#lx", dwDevType );
+    if (!localized) check_member_wstr( devinst, expect_devinst, tszInstanceName );
+    if (!localized) todo_wine check_member_wstr( devinst, expect_devinst, tszProductName );
+
     caps.dwSize = sizeof(DIDEVCAPS);
     hr = IDirectInputDevice8_GetCapabilities( device, &caps );
     ok( hr == DI_OK, "GetCapabilities returned %#lx\n", hr );
@@ -2270,8 +2279,13 @@ static void test_keyboard_info(void)
     hr = IDirectInputDevice8_GetProperty( device, DIPROP_TYPENAME, &prop_string.diph );
     ok( hr == DIERR_UNSUPPORTED, "GetProperty DIPROP_TYPENAME returned %#lx\n", hr );
     hr = IDirectInputDevice8_GetProperty( device, DIPROP_USERNAME, &prop_string.diph );
-    ok( hr == S_FALSE, "GetProperty DIPROP_USERNAME returned %#lx\n", hr );
-    ok( !wcscmp( prop_string.wsz, L"" ), "got user %s\n", debugstr_w(prop_string.wsz) );
+    if (version < 0x0800)
+        ok( hr == DIERR_UNSUPPORTED, "GetProperty DIPROP_USERNAME returned %#lx\n", hr );
+    else
+    {
+        ok( hr == DI_NOEFFECT, "GetProperty DIPROP_USERNAME returned %#lx\n", hr );
+        ok( !wcscmp( prop_string.wsz, L"" ), "got user %s\n", debugstr_w(prop_string.wsz) );
+    }
 
     hr = IDirectInputDevice8_GetProperty( device, DIPROP_JOYSTICKID, &prop_dword.diph );
     ok( hr == DIERR_UNSUPPORTED, "GetProperty DIPROP_VIDPID returned %#lx\n", hr );
@@ -2377,8 +2391,8 @@ static void test_keyboard_info(void)
     ref = IDirectInputDevice8_Release( device );
     ok( ref == 0, "Release returned %ld\n", ref );
 
-    ref = IDirectInput8_Release( di );
-    ok( ref == 0, "Release returned %ld\n", ref );
+    winetest_pop_context();
+    localized = old_localized;
 }
 
 START_TEST(device8)
@@ -2397,7 +2411,10 @@ START_TEST(device8)
     test_sys_mouse( 0x700 );
     test_sys_mouse( 0x800 );
 
-    test_keyboard_info();
+    test_sys_keyboard( 0x500 );
+    test_sys_keyboard( 0x700 );
+    test_sys_keyboard( 0x800 );
+
     test_action_mapping();
     test_save_settings();
     test_mouse_keyboard();
diff --git a/dlls/dinput/tests/keyboard.c b/dlls/dinput/tests/keyboard.c
index 0d3cf7b10c2..2aa4fa86f98 100644
--- a/dlls/dinput/tests/keyboard.c
+++ b/dlls/dinput/tests/keyboard.c
@@ -251,75 +251,6 @@ static void test_set_coop(IDirectInputA *pDI, HWND hwnd)
     if (pKeyboard) IUnknown_Release(pKeyboard);
 }
 
-static void test_get_prop(IDirectInputA *pDI, HWND hwnd)
-{
-    HRESULT hr;
-    IDirectInputDeviceA *pKeyboard = NULL;
-    DIPROPRANGE diprg;
-    DIPROPDWORD vidpid;
-
-    hr = IDirectInput_CreateDevice(pDI, &GUID_SysKeyboard, &pKeyboard, NULL);
-    ok(SUCCEEDED(hr), "IDirectInput_CreateDevice() failed: %#lx\n", hr);
-    if (FAILED(hr)) return;
-
-    memset(&diprg, 0, sizeof(diprg));
-    diprg.diph.dwSize       = sizeof(DIPROPRANGE);
-    diprg.diph.dwHeaderSize = sizeof(DIPROPHEADER);
-    diprg.diph.dwHow        = DIPH_DEVICE;
-    diprg.diph.dwObj        = 0;
-
-    hr = IDirectInputDevice_GetProperty(pKeyboard, DIPROP_RANGE, &diprg.diph);
-    ok(hr == DIERR_UNSUPPORTED, "IDirectInputDevice_GetProperty() did not return DIPROP_RANGE but: %#lx\n", hr);
-
-    memset(&vidpid, 0, sizeof(vidpid));
-    vidpid.diph.dwSize       = sizeof(DIPROPDWORD);
-    vidpid.diph.dwHeaderSize = sizeof(DIPROPHEADER);
-    vidpid.diph.dwHow        = DIPH_DEVICE;
-    vidpid.diph.dwObj        = 0;
-
-    hr = IDirectInputDevice_GetProperty(pKeyboard, DIPROP_VIDPID, &vidpid.diph);
-    ok(hr == DIERR_UNSUPPORTED, "got %#lx\n", hr);
-
-    IUnknown_Release(pKeyboard);
-}
-
-static void test_capabilities(IDirectInputA *pDI, HWND hwnd)
-{
-    HRESULT hr;
-    IDirectInputDeviceA *pKeyboard = NULL;
-    DIDEVCAPS caps;
-    int kbd_type, kbd_subtype, dev_subtype;
-
-    hr = IDirectInput_CreateDevice(pDI, &GUID_SysKeyboard, &pKeyboard, NULL);
-    ok(SUCCEEDED(hr), "IDirectInput_CreateDevice() failed: %#lx\n", hr);
-    if (FAILED(hr)) return;
-
-    caps.dwSize = sizeof(caps);
-    hr = IDirectInputDevice_GetCapabilities(pKeyboard, &caps);
-
-    ok (SUCCEEDED(hr), "GetCapabilities failed: 0x%#lx\n", hr);
-    ok (caps.dwFlags & DIDC_ATTACHED, "GetCapabilities dwFlags: 0x%#lx\n", caps.dwFlags);
-    ok (GET_DIDEVICE_TYPE(caps.dwDevType) == DIDEVTYPE_KEYBOARD,
-        "GetCapabilities invalid device type for dwDevType: 0x%#lx\n", caps.dwDevType);
-    kbd_type = GetKeyboardType(0);
-    kbd_subtype = GetKeyboardType(1);
-    dev_subtype = GET_DIDEVICE_SUBTYPE(caps.dwDevType);
-    if (kbd_type == 4 || (kbd_type == 7 && kbd_subtype == 0))
-        ok (dev_subtype == DIDEVTYPEKEYBOARD_PCENH,
-            "GetCapabilities invalid device subtype for dwDevType: 0x%#lx (%04x:%04x)\n",
-            caps.dwDevType, kbd_type, kbd_subtype);
-    else if (kbd_type == 7 && kbd_subtype == 2)
-        ok (dev_subtype == DIDEVTYPEKEYBOARD_JAPAN106,
-            "GetCapabilities invalid device subtype for dwDevType: 0x%#lx (%04x:%04x)\n",
-            caps.dwDevType, kbd_type, kbd_subtype);
-    else
-        ok (dev_subtype != DIDEVTYPEKEYBOARD_UNKNOWN,
-            "GetCapabilities invalid device subtype for dwDevType: 0x%#lx (%04x:%04x)\n",
-            caps.dwDevType, kbd_type, kbd_subtype);
-
-    IUnknown_Release(pKeyboard);
-}
-
 static void test_dik_codes(IDirectInputA *dI, HWND hwnd, LANGID langid)
 {
     static const struct key2dik
@@ -478,35 +409,6 @@ fail:
     IUnknown_Release(device);
 }
 
-static void test_GetDeviceInfo(IDirectInputA *pDI)
-{
-    HRESULT hr;
-    IDirectInputDeviceA *pKey = NULL;
-    DIDEVICEINSTANCEA instA;
-    DIDEVICEINSTANCE_DX3A inst3A;
-
-    hr = IDirectInput_CreateDevice(pDI, &GUID_SysKeyboard, &pKey, NULL);
-    ok(SUCCEEDED(hr), "IDirectInput_CreateDevice() failed: %#lx\n", hr);
-    if (FAILED(hr)) return;
-
-    instA.dwSize = sizeof(instA);
-    hr = IDirectInputDevice_GetDeviceInfo(pKey, &instA);
-    ok(SUCCEEDED(hr), "got %#lx\n", hr);
-
-    inst3A.dwSize = sizeof(inst3A);
-    hr = IDirectInputDevice_GetDeviceInfo(pKey, (DIDEVICEINSTANCEA *)&inst3A);
-    ok(SUCCEEDED(hr), "got %#lx\n", hr);
-
-    ok(instA.dwSize != inst3A.dwSize, "got %ld, %ld\n", instA.dwSize, inst3A.dwSize);
-    ok(IsEqualGUID(&instA.guidInstance, &inst3A.guidInstance), "got %s, %s\n",
-            wine_dbgstr_guid(&instA.guidInstance), wine_dbgstr_guid(&inst3A.guidInstance) );
-    ok(IsEqualGUID(&instA.guidProduct, &inst3A.guidProduct), "got %s, %s\n",
-            wine_dbgstr_guid(&instA.guidProduct), wine_dbgstr_guid(&inst3A.guidProduct) );
-    ok(instA.dwDevType == inst3A.dwDevType, "got %ld, %ld\n", instA.dwDevType, inst3A.dwDevType);
-
-    IUnknown_Release(pKey);
-}
-
 static void keyboard_tests(DWORD version)
 {
     HRESULT hr;
@@ -534,9 +436,6 @@ static void keyboard_tests(DWORD version)
 
         acquire_tests(pDI, hwnd);
         test_set_coop(pDI, hwnd);
-        test_get_prop(pDI, hwnd);
-        test_capabilities(pDI, hwnd);
-        test_GetDeviceInfo(pDI);
 
         test_dik_codes(pDI, hwnd, MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT));
         test_dik_codes(pDI, hwnd, MAKELANGID(LANG_FRENCH, SUBLANG_FRENCH));
-- 
GitLab


https://gitlab.winehq.org/wine/wine/-/merge_requests/223



More information about the wine-devel mailing list