Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/hid/hidp.c | 5 +++-- dlls/ntoskrnl.exe/tests/ntoskrnl.c | 36 ++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-)
diff --git a/dlls/hid/hidp.c b/dlls/hid/hidp.c index e936da418f2..9c7bac55abc 100644 --- a/dlls/hid/hidp.c +++ b/dlls/hid/hidp.c @@ -162,14 +162,14 @@ NTSTATUS WINAPI HidP_GetButtonCaps(HIDP_REPORT_TYPE ReportType, PHIDP_BUTTON_CAP PUSHORT ButtonCapsLength, PHIDP_PREPARSED_DATA PreparsedData) { PWINE_HIDP_PREPARSED_DATA data = (PWINE_HIDP_PREPARSED_DATA)PreparsedData; - WINE_HID_ELEMENT *elems = HID_ELEMS(data); + WINE_HID_ELEMENT *elems; WINE_HID_REPORT *report = NULL; USHORT b_count = 0, r_count = 0; int i,j,u;
TRACE("(%i, %p, %p, %p)\n",ReportType, ButtonCaps, ButtonCapsLength, PreparsedData);
- if (data->magic != HID_MAGIC) + if (!data || data->magic != HID_MAGIC) return HIDP_STATUS_INVALID_PREPARSED_DATA;
switch(ReportType) @@ -200,6 +200,7 @@ NTSTATUS WINAPI HidP_GetButtonCaps(HIDP_REPORT_TYPE ReportType, PHIDP_BUTTON_CAP b_count = min(b_count, *ButtonCapsLength);
u = 0; + elems = HID_ELEMS(data); for (j = 0; j < r_count && u < b_count; j++) { for (i = 0; i < report[j].elementCount && u < b_count; i++) diff --git a/dlls/ntoskrnl.exe/tests/ntoskrnl.c b/dlls/ntoskrnl.exe/tests/ntoskrnl.c index 27c8bcb33db..ca253dae7e5 100644 --- a/dlls/ntoskrnl.exe/tests/ntoskrnl.c +++ b/dlls/ntoskrnl.exe/tests/ntoskrnl.c @@ -1505,6 +1505,7 @@ static void test_hid_device(void) SP_DEVICE_INTERFACE_DATA iface = {sizeof(iface)}; SP_DEVINFO_DATA device = {sizeof(device)}; PHIDP_PREPARSED_DATA preparsed_data; + HIDP_BUTTON_CAPS button_caps[16]; BOOL ret, found = FALSE; OBJECT_ATTRIBUTES attr; UNICODE_STRING string; @@ -1513,6 +1514,7 @@ static void test_hid_device(void) HIDP_CAPS caps; unsigned int i; HDEVINFO set; + USHORT count; HANDLE file;
set = SetupDiGetClassDevsA(&GUID_DEVINTERFACE_HID, NULL, NULL, DIGCF_DEVICEINTERFACE | DIGCF_PRESENT); @@ -1569,6 +1571,40 @@ static void test_hid_device(void) ok(caps.NumberFeatureValueCaps == 0, "unexpected caps NumberFeatureValueCaps %d, expected %d\n", caps.NumberFeatureValueCaps, 0); ok(caps.NumberFeatureDataIndices == 0, "unexpected caps NumberFeatureDataIndices %d, expected %d\n", caps.NumberFeatureDataIndices, 0);
+ count = 0; + status = HidP_GetButtonCaps(HidP_Output, button_caps, &count, preparsed_data); + todo_wine ok(status == HIDP_STATUS_USAGE_NOT_FOUND, "HidP_GetButtonCaps returned %#x\n", status); + status = HidP_GetButtonCaps(HidP_Feature + 1, button_caps, &count, preparsed_data); + ok(status == HIDP_STATUS_INVALID_REPORT_TYPE, "HidP_GetButtonCaps returned %#x\n", status); + status = HidP_GetButtonCaps(HidP_Input, button_caps, &count, preparsed_data); + todo_wine ok(status == HIDP_STATUS_BUFFER_TOO_SMALL, "HidP_GetButtonCaps returned %#x\n", status); + count = ARRAY_SIZE(button_caps); + status = HidP_GetButtonCaps(HidP_Input, button_caps, &count, NULL); + ok(status == HIDP_STATUS_INVALID_PREPARSED_DATA, "HidP_GetButtonCaps returned %#x\n", status); + status = HidP_GetButtonCaps(HidP_Input, button_caps, &count, preparsed_data); + ok(status == HIDP_STATUS_SUCCESS, "HidP_GetButtonCaps returned %#x\n", status); + ok(count == caps.NumberInputButtonCaps, "HidP_GetButtonCaps returned count %d, expected %d\n", count, caps.NumberInputButtonCaps); + + ok(button_caps[0].UsagePage == HID_USAGE_PAGE_BUTTON, "unexpected button caps UsagePage %x, expected %x\n", button_caps[0].UsagePage, HID_USAGE_PAGE_BUTTON); + ok(button_caps[0].ReportID == 0, "unexpected button caps ReportID %d, expected %d\n", button_caps[0].ReportID, 0); + ok(!button_caps[0].IsAlias, "unexpected button caps IsAlias %d, expected %d\n", button_caps[0].IsAlias, 0); + todo_wine ok(button_caps[0].BitField == 2, "unexpected button caps BitField %d, expected %d\n", button_caps[0].BitField, 2); + ok(button_caps[0].LinkCollection == 0, "unexpected button caps LinkCollection %d, expected %d\n", button_caps[0].LinkCollection, 0); + ok(button_caps[0].LinkUsage == HID_USAGE_GENERIC_JOYSTICK, "unexpected button caps LinkUsage %x, expected %x\n", button_caps[0].LinkUsage, HID_USAGE_GENERIC_JOYSTICK); + ok(button_caps[0].LinkUsagePage == HID_USAGE_PAGE_GENERIC, "unexpected button caps LinkUsagePage %x, expected %x\n", button_caps[0].LinkUsagePage, HID_USAGE_PAGE_GENERIC); + ok(button_caps[0].IsRange, "unexpected button caps IsRange %d, expected %d\n", button_caps[0].IsRange, 1); + ok(!button_caps[0].IsStringRange, "unexpected button caps IsStringRange %d, expected %d\n", button_caps[0].IsStringRange, 0); + ok(!button_caps[0].IsDesignatorRange, "unexpected button caps IsDesignatorRange %d, expected %d\n", button_caps[0].IsDesignatorRange, 0); + ok(button_caps[0].IsAbsolute, "unexpected button caps IsAbsolute %d, expected %d\n", button_caps[0].IsAbsolute, 1); + ok(button_caps[0].Range.UsageMin == 1, "unexpected button caps Range.UsageMin %d, expected %d\n", button_caps[0].Range.UsageMin, 1); + ok(button_caps[0].Range.UsageMax == 8, "unexpected button caps Range.UsageMax %d, expected %d\n", button_caps[0].Range.UsageMax, 8); + ok(button_caps[0].Range.StringMin == 0, "unexpected button caps Range.StringMin %d, expected %d\n", button_caps[0].Range.StringMin, 0); + ok(button_caps[0].Range.StringMax == 0, "unexpected button caps Range.StringMax %d, expected %d\n", button_caps[0].Range.StringMax, 0); + ok(button_caps[0].Range.DesignatorMin == 0, "unexpected button caps Range.DesignatorMin %d, expected %d\n", button_caps[0].Range.DesignatorMin, 0); + ok(button_caps[0].Range.DesignatorMax == 0, "unexpected button caps Range.DesignatorMax %d, expected %d\n", button_caps[0].Range.DesignatorMax, 0); + ok(button_caps[0].Range.DataIndexMin == 2, "unexpected button caps Range.DataIndexMin %d, expected %d\n", button_caps[0].Range.DataIndexMin, 2); + ok(button_caps[0].Range.DataIndexMax == 9, "unexpected button caps Range.DataIndexMax %d, expected %d\n", button_caps[0].Range.DataIndexMax, 9); + HidD_FreePreparsedData(preparsed_data); CloseHandle(file);