Commit c7691595 authored by Rémi Bernon's avatar Rémi Bernon Committed by Alexandre Julliard

dinput/tests: Support test IOCTLs on the bus control interface.

parent 56113351
......@@ -92,14 +92,21 @@ void fill_context_( const char *file, int line, char *buffer, SIZE_T size );
BOOL sync_ioctl_( const char *file, int line, HANDLE device, DWORD code, void *in_buf, DWORD in_len,
void *out_buf, DWORD *ret_len, DWORD timeout );
#define set_hid_expect( a, b, c ) set_hid_expect_( __FILE__, __LINE__, a, b, c )
void set_hid_expect_( const char *file, int line, HANDLE device, struct hid_expect *expect, DWORD expect_size );
#define wait_hid_expect( a, b ) wait_hid_expect_( __FILE__, __LINE__, a, b, FALSE, FALSE )
#define wait_hid_pending( a, b ) wait_hid_expect_( __FILE__, __LINE__, a, b, TRUE, FALSE )
void wait_hid_expect_( const char *file, int line, HANDLE device, DWORD timeout, BOOL wait_pending, BOOL todo );
#define send_hid_input( a, b, c ) send_hid_input_( __FILE__, __LINE__, a, b, c )
void send_hid_input_( const char *file, int line, HANDLE device, struct hid_expect *expect, DWORD expect_size );
#define set_hid_expect( a, b, c ) set_hid_expect_( __FILE__, __LINE__, a, NULL, b, c )
#define bus_set_hid_expect( a, b, c, d ) set_hid_expect_( __FILE__, __LINE__, a, b, c, d )
void set_hid_expect_( const char *file, int line, HANDLE device, struct hid_device_desc *desc,
struct hid_expect *expect, DWORD expect_size );
#define wait_hid_expect( a, b ) wait_hid_expect_( __FILE__, __LINE__, a, NULL, b, FALSE, FALSE )
#define wait_hid_pending( a, b ) wait_hid_expect_( __FILE__, __LINE__, a, NULL, b, TRUE, FALSE )
#define bus_wait_hid_expect( a, b, c ) wait_hid_expect_( __FILE__, __LINE__, a, b, c, FALSE, FALSE )
#define bus_wait_hid_pending( a, b, c ) wait_hid_expect_( __FILE__, __LINE__, a, b, c, TRUE, FALSE )
void wait_hid_expect_( const char *file, int line, HANDLE device, struct hid_device_desc *desc,
DWORD timeout, BOOL wait_pending, BOOL todo );
#define send_hid_input( a, b, c ) send_hid_input_( __FILE__, __LINE__, a, NULL, b, c )
#define bus_send_hid_input( a, b, c, d ) send_hid_input_( __FILE__, __LINE__, a, b, c, d )
void send_hid_input_( const char *file, int line, HANDLE device, struct hid_device_desc *desc,
struct hid_expect *expect, DWORD expect_size );
#endif /* __WINE_DINPUT_TEST_H */
......@@ -58,8 +58,6 @@ static void check_buffer_( int line, HID_XFER_PACKET *packet, struct hid_expect
}
}
#define EXPECT_QUEUE_BUFFER_SIZE (64 * sizeof(struct hid_expect))
struct expect_queue
{
KSPIN_LOCK lock;
......@@ -1293,12 +1291,13 @@ static NTSTATUS WINAPI pdo_ioctl( DEVICE_OBJECT *device, IRP *irp )
IO_STACK_LOCATION *stack = IoGetCurrentIrpStackLocation( irp );
struct phys_device *impl = pdo_from_DEVICE_OBJECT( device );
ULONG in_size = stack->Parameters.DeviceIoControl.InputBufferLength;
struct hid_device_desc *desc = irp->AssociatedIrp.SystemBuffer;
ULONG code = stack->Parameters.DeviceIoControl.IoControlCode;
NTSTATUS status;
if (winetest_debug > 1) trace( "%s: device %p, code %#lx %s\n", __func__, device, code, debugstr_ioctl(code) );
status = pdo_handle_ioctl( impl, irp, code, irp->AssociatedIrp.SystemBuffer, in_size );
status = pdo_handle_ioctl( impl, irp, code, desc + 1, in_size - sizeof(*desc) );
if (status != STATUS_PENDING)
{
......@@ -1312,8 +1311,10 @@ static NTSTATUS WINAPI fdo_ioctl( DEVICE_OBJECT *device, IRP *irp )
{
IO_STACK_LOCATION *stack = IoGetCurrentIrpStackLocation( irp );
ULONG in_size = stack->Parameters.DeviceIoControl.InputBufferLength;
struct hid_device_desc *desc = irp->AssociatedIrp.SystemBuffer;
ULONG code = stack->Parameters.DeviceIoControl.IoControlCode;
struct func_device *impl = fdo_from_DEVICE_OBJECT( device );
struct phys_device *pdo;
NTSTATUS status;
if (winetest_debug > 1) trace( "%s: device %p, code %#lx %s\n", __func__, device, code, debugstr_ioctl(code) );
......@@ -1321,18 +1322,31 @@ static NTSTATUS WINAPI fdo_ioctl( DEVICE_OBJECT *device, IRP *irp )
switch (code)
{
case IOCTL_WINETEST_CREATE_DEVICE:
if (in_size < sizeof(struct hid_device_desc)) status = STATUS_INVALID_PARAMETER;
else status = create_child_pdo( device, irp->AssociatedIrp.SystemBuffer );
if (in_size < sizeof(*desc)) status = STATUS_INVALID_PARAMETER;
else status = create_child_pdo( device, desc );
break;
case IOCTL_WINETEST_REMOVE_DEVICE:
if ((device = find_child_device( impl, irp->AssociatedIrp.SystemBuffer )) &&
!remove_child_device( impl, device ))
if (in_size < sizeof(*desc))
status = STATUS_INVALID_PARAMETER;
else if (!(device = find_child_device( impl, desc )) || remove_child_device( impl, device ))
status = STATUS_NO_SUCH_DEVICE;
else
{
status = pdo_ioctl( device, irp );
IoInvalidateDeviceRelations( impl->pdo, BusRelations );
return status;
}
status = STATUS_NO_SUCH_DEVICE;
break;
case IOCTL_WINETEST_HID_SET_EXPECT:
case IOCTL_WINETEST_HID_WAIT_EXPECT:
case IOCTL_WINETEST_HID_SEND_INPUT:
case IOCTL_WINETEST_HID_SET_CONTEXT:
if (in_size < sizeof(*desc))
status = STATUS_INVALID_PARAMETER;
else if (!(device = find_child_device( impl, desc )) || !(pdo = pdo_from_DEVICE_OBJECT( device )))
status = STATUS_NO_SUCH_DEVICE;
else
status = pdo_handle_ioctl( pdo, irp, code, desc + 1, in_size - sizeof(*desc) );
break;
default:
ok( 0, "unexpected call\n" );
......
......@@ -61,6 +61,8 @@ struct hid_expect
BYTE report_buf[128];
};
#define EXPECT_QUEUE_BUFFER_SIZE (64 * sizeof(struct hid_expect))
struct wait_expect_params
{
BOOL wait_pending;
......
......@@ -909,39 +909,70 @@ void fill_context_( const char *file, int line, char *buffer, SIZE_T size )
snprintf( buffer, size, "%s:%d", source_file, line );
}
void set_hid_expect_( const char *file, int line, HANDLE device, struct hid_expect *expect, DWORD expect_size )
void set_hid_expect_( const char *file, int line, HANDLE device, struct hid_device_desc *desc,
struct hid_expect *expect, DWORD expect_size )
{
char context[64];
char buffer[sizeof(*desc) + EXPECT_QUEUE_BUFFER_SIZE];
SIZE_T size;
BOOL ret;
fill_context_( file, line, context, ARRAY_SIZE(context) );
ret = sync_ioctl_( file, line, device, IOCTL_WINETEST_HID_SET_CONTEXT, context, ARRAY_SIZE(context), NULL, 0, INFINITE );
if (desc) memcpy( buffer, desc, sizeof(*desc) );
else memset( buffer, 0, sizeof(*desc) );
fill_context_( file, line, buffer + sizeof(*desc), ARRAY_SIZE(buffer) - sizeof(*desc) );
size = sizeof(*desc) + strlen( buffer + sizeof(*desc) ) + 1;
ret = sync_ioctl_( file, line, device, IOCTL_WINETEST_HID_SET_CONTEXT, buffer, size, NULL, 0, INFINITE );
ok_(file, line)( ret, "IOCTL_WINETEST_HID_SET_CONTEXT failed, last error %lu\n", GetLastError() );
ret = sync_ioctl_( file, line, device, IOCTL_WINETEST_HID_SET_EXPECT, expect, expect_size, NULL, 0, INFINITE );
if (expect) memcpy( buffer + sizeof(*desc), expect, expect_size );
else memset( buffer + sizeof(*desc), 0, expect_size );
size = sizeof(*desc) + expect_size;
ret = sync_ioctl_( file, line, device, IOCTL_WINETEST_HID_SET_EXPECT, buffer, size, NULL, 0, INFINITE );
ok_(file, line)( ret, "IOCTL_WINETEST_HID_SET_EXPECT failed, last error %lu\n", GetLastError() );
}
void wait_hid_expect_( const char *file, int line, HANDLE device, DWORD timeout, BOOL wait_pending, BOOL todo )
void wait_hid_expect_( const char *file, int line, HANDLE device, struct hid_device_desc *desc,
DWORD timeout, BOOL wait_pending, BOOL todo )
{
struct wait_expect_params params = {.wait_pending = wait_pending};
char buffer[sizeof(*desc) + sizeof(params)];
SIZE_T size;
if (desc) memcpy( buffer, desc, sizeof(*desc) );
else memset( buffer, 0, sizeof(*desc) );
memcpy( buffer + sizeof(*desc), &params, sizeof(params) );
size = sizeof(*desc) + sizeof(params);
todo_wine_if(todo) {
BOOL ret = sync_ioctl_( file, line, device, IOCTL_WINETEST_HID_WAIT_EXPECT, &params, sizeof(params), NULL, 0, timeout );
BOOL ret = sync_ioctl_( file, line, device, IOCTL_WINETEST_HID_WAIT_EXPECT, buffer, size, NULL, 0, timeout );
ok_(file, line)( ret, "IOCTL_WINETEST_HID_WAIT_EXPECT failed, last error %lu\n", GetLastError() );
}
set_hid_expect_( file, line, device, NULL, 0 );
set_hid_expect_( file, line, device, desc, NULL, 0 );
}
void send_hid_input_( const char *file, int line, HANDLE device, struct hid_expect *expect, DWORD expect_size )
void send_hid_input_( const char *file, int line, HANDLE device, struct hid_device_desc *desc,
struct hid_expect *expect, DWORD expect_size )
{
char context[64];
char buffer[sizeof(*desc) + EXPECT_QUEUE_BUFFER_SIZE];
SIZE_T size;
BOOL ret;
fill_context_( file, line, context, ARRAY_SIZE(context) );
ret = sync_ioctl_( file, line, device, IOCTL_WINETEST_HID_SET_CONTEXT, context, ARRAY_SIZE(context), NULL, 0, INFINITE );
if (desc) memcpy( buffer, desc, sizeof(*desc) );
else memset( buffer, 0, sizeof(*desc) );
fill_context_( file, line, buffer + sizeof(*desc), ARRAY_SIZE(buffer) - sizeof(*desc) );
size = sizeof(*desc) + strlen( buffer + sizeof(*desc) ) + 1;
ret = sync_ioctl_( file, line, device, IOCTL_WINETEST_HID_SET_CONTEXT, buffer, size, NULL, 0, INFINITE );
ok_(file, line)( ret, "IOCTL_WINETEST_HID_SET_CONTEXT failed, last error %lu\n", GetLastError() );
ret = sync_ioctl_( file, line, device, IOCTL_WINETEST_HID_SEND_INPUT, expect, expect_size, NULL, 0, INFINITE );
if (expect) memcpy( buffer + sizeof(*desc), expect, expect_size );
else memset( buffer + sizeof(*desc), 0, expect_size );
size = sizeof(*desc) + expect_size;
ret = sync_ioctl_( file, line, device, IOCTL_WINETEST_HID_SEND_INPUT, buffer, size, NULL, 0, INFINITE );
ok_(file, line)( ret, "IOCTL_WINETEST_HID_SEND_INPUT failed, last error %lu\n", GetLastError() );
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment