Module: wine Branch: master Commit: 8feeb883e13121bc592885e49f21697c1cc5c3b3 URL: https://source.winehq.org/git/wine.git/?a=commit;h=8feeb883e13121bc592885e49...
Author: Rémi Bernon rbernon@codeweavers.com Date: Thu Dec 2 10:47:42 2021 +0100
dinput8/tests: Add more effect direction tests.
Making sure we are actually writing the correctly values to PID reports, regardless of user provided coordinate space.
Signed-off-by: Rémi Bernon rbernon@codeweavers.com Signed-off-by: Alexandre Julliard julliard@winehq.org
---
dlls/dinput/joystick_hid.c | 14 +++++- dlls/dinput8/tests/hid.c | 103 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 116 insertions(+), 1 deletion(-)
diff --git a/dlls/dinput/joystick_hid.c b/dlls/dinput/joystick_hid.c index 99fe98d95ce..49a8f28e864 100644 --- a/dlls/dinput/joystick_hid.c +++ b/dlls/dinput/joystick_hid.c @@ -2764,6 +2764,13 @@ static void set_parameter_value_us( struct hid_joystick_effect *impl, char *repo set_parameter_value( impl, report_buf, caps, value ); }
+static BOOL is_axis_usage_enabled( struct hid_joystick_effect *impl, USAGE usage ) +{ + DWORD i = impl->params.cAxes; + while (i--) if (LOWORD(impl->params.rgdwAxes[i]) == usage) return TRUE; + return FALSE; +} + static HRESULT WINAPI hid_joystick_effect_Download( IDirectInputEffect *iface ) { static const DWORD complete_mask = DIEP_AXES | DIEP_DIRECTION | DIEP_TYPESPECIFICPARAMS; @@ -2937,7 +2944,12 @@ static HRESULT WINAPI hid_joystick_effect_Download( IDirectInputEffect *iface ) spherical.rglDirection = directions; convert_directions_to_spherical( &impl->params, &spherical );
- for (i = 0; i < min( effect_update->direction_count, spherical.cAxes ); ++i) + /* FIXME: as far as the test cases go, directions are only written if + * either X or Y axes are enabled, maybe need more tests though */ + if (!is_axis_usage_enabled( impl, HID_USAGE_GENERIC_X ) && + !is_axis_usage_enabled( impl, HID_USAGE_GENERIC_Y )) + WARN( "neither X or Y axes are selected, skipping direction\n" ); + else for (i = 0; i < min( effect_update->direction_count, spherical.cAxes ); ++i) { tmp = directions[i] + (i == 0 ? 9000 : 0); caps = effect_update->direction_caps[effect_update->direction_count - i - 1]; diff --git a/dlls/dinput8/tests/hid.c b/dlls/dinput8/tests/hid.c index d9ecf4a5dd5..2efa817f00e 100644 --- a/dlls/dinput8/tests/hid.c +++ b/dlls/dinput8/tests/hid.c @@ -6357,6 +6357,54 @@ static void test_periodic_effect( IDirectInputDevice8W *device, HANDLE file, DWO
for (i = 1; i < 4; i++) { + struct hid_expect expect_directions[] = + { + /* set periodic */ + { + .code = IOCTL_HID_WRITE_REPORT, + .report_id = 5, + .report_len = 2, + .report_buf = {0x05,0x19}, + }, + /* set envelope */ + { + .code = IOCTL_HID_WRITE_REPORT, + .report_id = 6, + .report_len = 7, + .report_buf = {0x06,0x19,0x4c,0x02,0x00,0x04,0x00}, + }, + /* update effect */ + {0}, + /* effect control */ + { + .code = IOCTL_HID_WRITE_REPORT, + .report_id = 2, + .report_len = 4, + .report_buf = {0x02,0x01,0x03,0x00}, + }, + }; + struct hid_expect expect_spherical = + { + .code = IOCTL_HID_WRITE_REPORT, + .report_id = 3, + .report_len = 11, + .report_buf = {0x03,0x01,0x02,0x08,0x01,0x00,version >= 0x700 ? 0x06 : 0x00,0x00,0x01,i >= 2 ? 0x55 : 0,i >= 3 ? 0x1c : 0}, + }; + struct hid_expect expect_cartesian = + { + .code = IOCTL_HID_WRITE_REPORT, + .report_id = 3, + .report_len = 11, + .report_buf = {0x03,0x01,0x02,0x08,0x01,0x00,version >= 0x700 ? 0x06 : 0x00,0x00,0x01,i >= 2 ? 0x63 : 0,i >= 3 ? 0x1d : 0}, + }; + struct hid_expect expect_polar = + { + .code = IOCTL_HID_WRITE_REPORT, + .report_id = 3, + .report_len = 11, + .report_buf = {0x03,0x01,0x02,0x08,0x01,0x00,version >= 0x700 ? 0x06 : 0x00,0x00,0x01,i >= 2 ? 0x3f : 0,i >= 3 ? 0x00 : 0}, + }; + winetest_push_context( "%u axes", i ); hr = IDirectInputDevice8_CreateEffect( device, &GUID_Sine, NULL, &effect, NULL ); ok( hr == DI_OK, "CreateEffect returned %#x\n", hr ); @@ -6465,6 +6513,61 @@ static void test_periodic_effect( IDirectInputDevice8W *device, HANDLE file, DWO
ref = IDirectInputEffect_Release( effect ); ok( ref == 0, "Release returned %d\n", ref ); + + desc = expect_desc; + desc.dwFlags = DIEFF_SPHERICAL | DIEFF_OBJECTIDS; + desc.cAxes = i; + desc.rgdwAxes = axes; + desc.rglDirection = directions; + desc.rglDirection[0] = 3000; + desc.rglDirection[1] = 4000; + desc.rglDirection[2] = 5000; + flags = version >= 0x700 ? DIEP_ALLPARAMS : DIEP_ALLPARAMS_DX5; + expect_directions[2] = expect_spherical; + set_hid_expect( file, expect_directions, sizeof(expect_directions) ); + hr = IDirectInputDevice8_CreateEffect( device, &GUID_Sine, &desc, &effect, NULL ); + ok( hr == DI_OK, "CreateEffect returned %#x\n", hr ); + ref = IDirectInputEffect_Release( effect ); + ok( ref == 0, "Release returned %d\n", ref ); + set_hid_expect( file, NULL, 0 ); + + desc = expect_desc; + desc.dwFlags = DIEFF_CARTESIAN | DIEFF_OBJECTIDS; + desc.cAxes = i; + desc.rgdwAxes = axes; + desc.rglDirection = directions; + desc.rglDirection[0] = 6000; + desc.rglDirection[1] = 7000; + desc.rglDirection[2] = 8000; + flags = version >= 0x700 ? DIEP_ALLPARAMS : DIEP_ALLPARAMS_DX5; + expect_directions[2] = expect_cartesian; + set_hid_expect( file, expect_directions, sizeof(expect_directions) ); + hr = IDirectInputDevice8_CreateEffect( device, &GUID_Sine, &desc, &effect, NULL ); + ok( hr == DI_OK, "CreateEffect returned %#x\n", hr ); + ref = IDirectInputEffect_Release( effect ); + ok( ref == 0, "Release returned %d\n", ref ); + set_hid_expect( file, NULL, 0 ); + + if (i == 2) + { + desc = expect_desc; + desc.dwFlags = DIEFF_POLAR | DIEFF_OBJECTIDS; + desc.cAxes = i; + desc.rgdwAxes = axes; + desc.rglDirection = directions; + desc.rglDirection[0] = 9000; + desc.rglDirection[1] = 10000; + desc.rglDirection[2] = 11000; + flags = version >= 0x700 ? DIEP_ALLPARAMS : DIEP_ALLPARAMS_DX5; + expect_directions[2] = expect_polar; + set_hid_expect( file, expect_directions, sizeof(expect_directions) ); + hr = IDirectInputDevice8_CreateEffect( device, &GUID_Sine, &desc, &effect, NULL ); + ok( hr == DI_OK, "CreateEffect returned %#x\n", hr ); + ref = IDirectInputEffect_Release( effect ); + ok( ref == 0, "Release returned %d\n", ref ); + set_hid_expect( file, NULL, 0 ); + } + winetest_pop_context(); }