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

dinput/tests: Create all HID devices from the Bus driver.

parent 2a52c8dc
......@@ -44,6 +44,7 @@
#include "driver_hid.h"
#define EXPECT_VIDPID MAKELONG( 0x1209, 0x0001 )
extern const HID_DEVICE_ATTRIBUTES default_attributes;
extern const WCHAR expect_vidpid_str[];
extern const GUID expect_guid_product;
extern const WCHAR expect_path[];
......@@ -53,17 +54,13 @@ extern HANDLE device_added, device_removed;
extern HINSTANCE instance;
extern BOOL localized; /* object names get translated */
BOOL hid_device_start(void);
void hid_device_stop(void);
BOOL hid_device_start( struct hid_device_desc *desc );
void hid_device_stop( struct hid_device_desc *desc );
BOOL bus_device_start(void);
void bus_device_stop(void);
void cleanup_registry_keys(void);
#define dinput_driver_start( a, b, c, d, e ) dinput_driver_start_( __FILE__, __LINE__, a, b, c, d, e )
BOOL dinput_driver_start_( const char *file, int line, const BYTE *desc_buf, ULONG desc_len,
const HIDP_CAPS *caps, struct hid_expect *expect, ULONG expect_size );
#define dinput_test_init() dinput_test_init_( __FILE__, __LINE__ )
BOOL dinput_test_init_( const char *file, int line );
void dinput_test_exit(void);
......@@ -71,6 +68,17 @@ void dinput_test_exit(void);
HRESULT dinput_test_create_device( DWORD version, DIDEVICEINSTANCEW *devinst, IDirectInputDevice8W **device );
DWORD WINAPI dinput_test_device_thread( void *stop_event );
#define fill_context( line, a, b ) \
do \
{ \
const char *source_file; \
source_file = strrchr( __FILE__, '/' ); \
if (!source_file) source_file = strrchr( __FILE__, '\\' ); \
if (!source_file) source_file = __FILE__; \
else source_file++; \
snprintf( a, b, "%s:%d", source_file, line ); \
} while (0)
#define check_member_( file, line, val, exp, fmt, member ) \
ok_(file, line)( (val).member == (exp).member, "got " #member " " fmt "\n", (val).member )
#define check_member( val, exp, fmt, member ) \
......
......@@ -500,7 +500,7 @@ static NTSTATUS append_child_device( struct func_device *impl, DEVICE_OBJECT *de
return status;
}
static DEVICE_OBJECT *find_child_device( struct func_device *impl, struct bus_device_desc *desc )
static DEVICE_OBJECT *find_child_device( struct func_device *impl, struct hid_device_desc *desc )
{
DEVICE_OBJECT *device = NULL, **devices;
WCHAR device_id[MAX_PATH];
......@@ -785,7 +785,7 @@ static NTSTATUS pdo_pnp( DEVICE_OBJECT *device, IRP *irp )
return status;
}
static NTSTATUS create_child_pdo( DEVICE_OBJECT *device, struct bus_device_desc *desc )
static NTSTATUS create_child_pdo( DEVICE_OBJECT *device, struct hid_device_desc *desc )
{
static ULONG index;
......@@ -954,7 +954,8 @@ static NTSTATUS WINAPI pdo_internal_ioctl( DEVICE_OBJECT *device, IRP *irp )
KIRQL irql;
LONG index;
if (winetest_debug > 1) trace( "%s: device %p, code %#lx %s\n", __func__, device, code, debugstr_ioctl(code) );
if ((!impl->input_queue.is_polled || code != IOCTL_HID_READ_REPORT) && winetest_debug > 1)
trace( "%s: device %p, code %#lx %s\n", __func__, device, code, debugstr_ioctl(code) );
KeAcquireSpinLock( &impl->base.lock, &irql );
removed = impl->base.state == PNP_DEVICE_REMOVED;
......@@ -1252,7 +1253,7 @@ static NTSTATUS WINAPI fdo_ioctl( DEVICE_OBJECT *device, IRP *irp )
switch (code)
{
case IOCTL_WINETEST_CREATE_DEVICE:
if (in_size < sizeof(struct bus_device_desc)) status = STATUS_INVALID_PARAMETER;
if (in_size < sizeof(struct hid_device_desc)) status = STATUS_INVALID_PARAMETER;
else status = create_child_pdo( device, irp->AssociatedIrp.SystemBuffer );
break;
case IOCTL_WINETEST_REMOVE_DEVICE:
......@@ -1263,7 +1264,7 @@ static NTSTATUS WINAPI fdo_ioctl( DEVICE_OBJECT *device, IRP *irp )
IoInvalidateDeviceRelations( impl->pdo, BusRelations );
return status;
}
status = STATUS_SUCCESS;
status = STATUS_NO_SUCH_DEVICE;
break;
default:
ok( 0, "unexpected call\n" );
......
......@@ -62,7 +62,7 @@ struct hid_expect
};
/* create/remove device */
struct bus_device_desc
struct hid_device_desc
{
BOOL is_polled;
BOOL use_report_id;
......
......@@ -1968,9 +1968,11 @@ static BOOL test_force_feedback_joystick( DWORD version )
#undef REPORT_ID_OR_USAGE_PAGE
#include "pop_hid_macros.h"
static const HIDP_CAPS hid_caps =
struct hid_device_desc desc =
{
.InputReportByteLength = 5,
.use_report_id = TRUE,
.caps = { .InputReportByteLength = 5 },
.attributes = default_attributes,
};
const DIDEVCAPS expect_caps =
{
......@@ -2032,8 +2034,8 @@ static BOOL test_force_feedback_joystick( DWORD version )
.guidProduct = expect_guid_product,
.dwDevType = version >= 0x800 ? DIDEVTYPE_HID | (DI8DEVTYPEJOYSTICK_LIMITED << 8) | DI8DEVTYPE_JOYSTICK
: DIDEVTYPE_HID | (DIDEVTYPEJOYSTICK_UNKNOWN << 8) | DIDEVTYPE_JOYSTICK,
.tszInstanceName = L"Wine test root driver",
.tszProductName = L"Wine test root driver",
.tszInstanceName = L"Wine Test",
.tszProductName = L"Wine Test",
.guidFFDriver = IID_IDirectInputPIDDriver,
.wUsagePage = HID_USAGE_PAGE_GENERIC,
.wUsage = HID_USAGE_GENERIC_JOYSTICK,
......@@ -2774,7 +2776,6 @@ static BOOL test_force_feedback_joystick( DWORD version )
},
};
DIDEVICEINSTANCEW devinst = {.dwSize = sizeof(DIDEVICEINSTANCEW)};
WCHAR cwd[MAX_PATH], tempdir[MAX_PATH];
IDirectInputDevice8W *device = NULL;
DIDEVICEOBJECTDATA objdata = {0};
DIEFFECTINFOW effectinfo = {0};
......@@ -2787,13 +2788,13 @@ static BOOL test_force_feedback_joystick( DWORD version )
HWND hwnd;
winetest_push_context( "%#lx", version );
cleanup_registry_keys();
GetCurrentDirectoryW( ARRAY_SIZE(cwd), cwd );
GetTempPathW( ARRAY_SIZE(tempdir), tempdir );
SetCurrentDirectoryW( tempdir );
desc.report_descriptor_len = sizeof(report_descriptor);
memcpy( desc.report_descriptor_buf, report_descriptor, sizeof(report_descriptor) );
fill_context( __LINE__, desc.context, ARRAY_SIZE(desc.context) );
cleanup_registry_keys();
if (!dinput_driver_start( report_descriptor, sizeof(report_descriptor), &hid_caps, NULL, 0 )) goto done;
if (!hid_device_start( &desc )) goto done;
if (FAILED(hr = dinput_test_create_device( version, &devinst, &device ))) goto done;
check_dinput_devices( version, &devinst );
......@@ -2805,9 +2806,7 @@ static BOOL test_force_feedback_joystick( DWORD version )
check_member_guid( devinst, expect_devinst, guidInstance );
check_member_guid( devinst, expect_devinst, guidProduct );
check_member( devinst, expect_devinst, "%#lx", dwDevType );
todo_wine
check_member_wstr( devinst, expect_devinst, tszInstanceName );
todo_wine
check_member_wstr( devinst, expect_devinst, tszProductName );
check_member_guid( devinst, expect_devinst, guidFFDriver );
check_member( devinst, expect_devinst, "%04x", wUsagePage );
......@@ -2999,9 +2998,8 @@ static BOOL test_force_feedback_joystick( DWORD version )
CloseHandle( file );
done:
hid_device_stop();
hid_device_stop( &desc );
cleanup_registry_keys();
SetCurrentDirectoryW( cwd );
winetest_pop_context();
return device != NULL;
......@@ -3424,9 +3422,11 @@ static void test_device_managed_effect(void)
};
#include "pop_hid_macros.h"
static const HIDP_CAPS hid_caps =
struct hid_device_desc desc =
{
.InputReportByteLength = 5,
.use_report_id = TRUE,
.caps = { .InputReportByteLength = 5 },
.attributes = default_attributes,
};
struct hid_expect expect_acquire[] =
{
......@@ -3892,23 +3892,24 @@ static void test_device_managed_effect(void)
},
};
DIDEVICEINSTANCEW devinst = {.dwSize = sizeof(DIDEVICEINSTANCEW)};
WCHAR cwd[MAX_PATH], tempdir[MAX_PATH];
IDirectInputDevice8W *device;
IDirectInputEffect *effect, *effect2;
DIEFFECT effect_desc;
HANDLE file, event;
ULONG res, ref;
DIEFFECT desc;
DWORD flags;
HRESULT hr;
HWND hwnd;
GetCurrentDirectoryW( ARRAY_SIZE(cwd), cwd );
GetTempPathW( ARRAY_SIZE(tempdir), tempdir );
SetCurrentDirectoryW( tempdir );
cleanup_registry_keys();
if (!dinput_driver_start( report_descriptor, sizeof(report_descriptor), &hid_caps,
expect_pool, sizeof(expect_pool) )) goto done;
desc.report_descriptor_len = sizeof(report_descriptor);
memcpy( desc.report_descriptor_buf, report_descriptor, sizeof(report_descriptor) );
desc.expect_size = sizeof(expect_pool);
memcpy( desc.expect, expect_pool, sizeof(expect_pool) );
fill_context( __LINE__, desc.context, ARRAY_SIZE(desc.context) );
if (!hid_device_start( &desc )) goto done;
if (FAILED(hr = dinput_test_create_device( DIRECTINPUT_VERSION, &devinst, &device ))) goto done;
hr = IDirectInputDevice8_GetProperty( device, DIPROP_GUIDANDPATH, &prop_guid_path.diph );
......@@ -4255,10 +4256,10 @@ static void test_device_managed_effect(void)
ok( ref == 0, "Release returned %ld\n", ref );
/* start delay has no direct effect on effect status */
desc = expect_desc;
desc.dwStartDelay = 32767000;
effect_desc = expect_desc;
effect_desc.dwStartDelay = 32767000;
set_hid_expect( file, expect_create_delay, sizeof(expect_create_delay) );
hr = IDirectInputDevice8_CreateEffect( device, &GUID_Spring, &desc, &effect, NULL );
hr = IDirectInputDevice8_CreateEffect( device, &GUID_Spring, &effect_desc, &effect, NULL );
ok( hr == DI_OK, "CreateEffect returned %#lx\n", hr );
set_hid_expect( file, NULL, 0 );
res = 0xdeadbeef;
......@@ -4279,11 +4280,11 @@ static void test_device_managed_effect(void)
set_hid_expect( file, NULL, 0 );
/* duration has no direct effect on effect status */
desc = expect_desc;
desc.dwDuration = 100;
desc.dwStartDelay = 0;
effect_desc = expect_desc;
effect_desc.dwDuration = 100;
effect_desc.dwStartDelay = 0;
set_hid_expect( file, expect_create_duration, sizeof(expect_create_duration) );
hr = IDirectInputDevice8_CreateEffect( device, &GUID_Spring, &desc, &effect, NULL );
hr = IDirectInputDevice8_CreateEffect( device, &GUID_Spring, &effect_desc, &effect, NULL );
ok( hr == DI_OK, "CreateEffect returned %#lx\n", hr );
set_hid_expect( file, NULL, 0 );
res = 0xdeadbeef;
......@@ -4317,15 +4318,15 @@ static void test_device_managed_effect(void)
CloseHandle( file );
done:
hid_device_stop();
hid_device_stop( &desc );
cleanup_registry_keys();
SetCurrentDirectoryW( cwd );
winetest_pop_context();
}
START_TEST( force_feedback )
{
if (!dinput_test_init()) return;
if (!bus_device_start()) goto done;
CoInitialize( NULL );
if (test_force_feedback_joystick( 0x800 ))
......@@ -4336,5 +4337,7 @@ START_TEST( force_feedback )
}
CoUninitialize();
done:
bus_device_stop();
dinput_test_exit();
}
......@@ -48,6 +48,7 @@
#define WIDL_using_Windows_Gaming_Input
#define WIDL_using_Windows_Gaming_Input_Custom
#include "windows.gaming.input.custom.h"
#undef Size
#define MAKE_FUNC(f) static typeof(f) *p ## f
MAKE_FUNC( RoGetActivationFactory );
......@@ -134,9 +135,11 @@ static BOOL test_input_lost( DWORD version )
};
#include "pop_hid_macros.h"
static const HIDP_CAPS hid_caps =
struct hid_device_desc desc =
{
.InputReportByteLength = 1,
.use_report_id = TRUE,
.caps = { .InputReportByteLength = 1 },
.attributes = default_attributes,
};
static const DIPROPDWORD buffer_size =
{
......@@ -152,7 +155,6 @@ static BOOL test_input_lost( DWORD version )
DIDEVICEINSTANCEW devinst = {.dwSize = sizeof(DIDEVICEINSTANCEW)};
DIDEVICEOBJECTDATA objdata[32] = {{0}};
WCHAR cwd[MAX_PATH], tempdir[MAX_PATH];
IDirectInputDevice8W *device = NULL;
ULONG ref, count, size;
DIJOYSTATE2 state;
......@@ -160,12 +162,13 @@ static BOOL test_input_lost( DWORD version )
winetest_push_context( "%#lx", version );
GetCurrentDirectoryW( ARRAY_SIZE(cwd), cwd );
GetTempPathW( ARRAY_SIZE(tempdir), tempdir );
SetCurrentDirectoryW( tempdir );
cleanup_registry_keys();
if (!dinput_driver_start( report_desc, sizeof(report_desc), &hid_caps, NULL, 0 )) goto done;
desc.report_descriptor_len = sizeof(report_desc);
memcpy( desc.report_descriptor_buf, report_desc, sizeof(report_desc) );
fill_context( __LINE__, desc.context, ARRAY_SIZE(desc.context) );
if (!hid_device_start( &desc )) goto done;
if (FAILED(hr = dinput_test_create_device( version, &devinst, &device ))) goto done;
hr = IDirectInputDevice8_SetDataFormat( device, &c_dfDIJoystick2 );
......@@ -185,7 +188,7 @@ static BOOL test_input_lost( DWORD version )
ok( hr == DI_OK, "GetDeviceData returned %#lx\n", hr );
ok( count == 0, "got %lu expected 0\n", count );
hid_device_stop();
hid_device_stop( &desc );
hr = IDirectInputDevice8_GetDeviceState( device, sizeof(state), &state );
ok( hr == DIERR_INPUTLOST, "GetDeviceState returned %#lx\n", hr );
......@@ -205,22 +208,20 @@ static BOOL test_input_lost( DWORD version )
hr = IDirectInputDevice8_Unacquire( device );
ok( hr == DI_NOEFFECT, "Unacquire returned: %#lx\n", hr );
dinput_driver_start( report_desc, sizeof(report_desc), &hid_caps, NULL, 0 );
fill_context( __LINE__, desc.context, ARRAY_SIZE(desc.context) );
hid_device_start( &desc );
hr = IDirectInputDevice8_Acquire( device );
todo_wine
ok( hr == DIERR_UNPLUGGED, "Acquire returned %#lx\n", hr );
ok( hr == S_OK, "Acquire returned %#lx\n", hr );
hr = IDirectInputDevice8_GetDeviceState( device, sizeof(state), &state );
todo_wine
ok( hr == DIERR_NOTACQUIRED, "GetDeviceState returned %#lx\n", hr );
ok( hr == S_OK, "GetDeviceState returned %#lx\n", hr );
ref = IDirectInputDevice8_Release( device );
ok( ref == 0, "Release returned %ld\n", ref );
done:
hid_device_stop();
hid_device_stop( &desc );
cleanup_registry_keys();
SetCurrentDirectoryW( cwd );
winetest_pop_context();
return device != NULL;
......@@ -255,7 +256,7 @@ static LRESULT CALLBACK devnotify_wndproc( HWND hwnd, UINT msg, WPARAM wparam, L
if (device_change_all && (device_change_count == 0 || device_change_count == 3))
{
expect_guid = control_class;
expect_prefix = L"\\\\?\\ROOT#";
expect_prefix = L"\\\\?\\WINETEST#";
}
else
{
......@@ -1218,6 +1219,7 @@ next:
START_TEST( hotplug )
{
if (!dinput_test_init()) return;
if (!bus_device_start()) goto done;
CoInitialize( NULL );
if (test_input_lost( 0x500 ))
......@@ -1230,5 +1232,7 @@ START_TEST( hotplug )
}
CoUninitialize();
done:
bus_device_stop();
dinput_test_exit();
}
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