[DINPUT_WINETEST]

* Import from Wine 1.5.26.

svn path=/trunk/; revision=58769
This commit is contained in:
Amine Khaldi 2013-04-15 19:31:42 +00:00
parent f31ab09118
commit 192afa3ac1
8 changed files with 2096 additions and 0 deletions

View file

@ -15,6 +15,7 @@ add_subdirectory(credui)
add_subdirectory(crypt32)
add_subdirectory(cryptnet)
add_subdirectory(cryptui)
add_subdirectory(dinput)
add_subdirectory(dnsapi)
add_subdirectory(dsound)
add_subdirectory(fusion)

View file

@ -0,0 +1,15 @@
add_definitions(-D__ROS_LONG64__)
add_executable(dinput_winetest
device.c
dinput.c
joystick.c
keyboard.c
mouse.c
testlist.c)
target_link_libraries(dinput_winetest wine dinput_data_formats)
set_module_type(dinput_winetest win32cui)
add_importlibs(dinput_winetest dinput ole32 user32 msvcrt kernel32 ntdll)
add_cd_file(TARGET dinput_winetest DESTINATION reactos/bin FOR all)

View file

@ -0,0 +1,273 @@
/*
* Copyright (c) 2006 Vitaliy Margolen
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#define WIN32_NO_STATUS
#define _INC_WINDOWS
#define COM_NO_WINDOWS_H
#define DIRECTINPUT_VERSION 0x0700
#define COBJMACROS
//#include <windows.h>
#include <wine/test.h>
//#include "windef.h"
#include <dinput.h>
static const DIOBJECTDATAFORMAT obj_data_format[] = {
{ &GUID_YAxis, 16, DIDFT_OPTIONAL|DIDFT_AXIS |DIDFT_MAKEINSTANCE(1), 0},
{ &GUID_Button,15, DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_MAKEINSTANCE(3), 0},
{ &GUID_Key, 0, DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_MAKEINSTANCE(16),0},
{ &GUID_Key, 1, DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_MAKEINSTANCE(17),0},
{ &GUID_Key, 2, DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_MAKEINSTANCE(18),0},
{ &GUID_Key, 3, DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_MAKEINSTANCE(19),0},
{ &GUID_Key, 4, DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_MAKEINSTANCE(20),0},
{ &GUID_Key, 5, DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_MAKEINSTANCE(21),0},
{ &GUID_Key, 6, DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_MAKEINSTANCE(22),0},
{ &GUID_Key, 7, DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_MAKEINSTANCE(23),0},
{ &GUID_Key, 8, DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_MAKEINSTANCE(24),0},
{ &GUID_Key, 9, DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_MAKEINSTANCE(25),0},
{ &GUID_Key, 10, DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_MAKEINSTANCE(26),0},
{ &GUID_Key, 11, DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_MAKEINSTANCE(27),0},
{ &GUID_Key, 12, DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_MAKEINSTANCE(28),0},
{ NULL, 13, DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_MAKEINSTANCE(5),0},
{ &GUID_Button,14, DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_MAKEINSTANCE(32),0}
};
static const DIDATAFORMAT data_format = {
sizeof(DIDATAFORMAT),
sizeof(DIOBJECTDATAFORMAT),
DIDF_ABSAXIS,
32,
sizeof(obj_data_format) / sizeof(obj_data_format[0]),
(LPDIOBJECTDATAFORMAT)obj_data_format
};
static BOOL CALLBACK enum_callback(LPCDIDEVICEOBJECTINSTANCE oi, LPVOID info)
{
if (winetest_debug > 1)
trace(" Type:%4x Ofs:%3d Flags:%08x Name:%s\n",
oi->dwType, oi->dwOfs, oi->dwFlags, oi->tszName);
(*(int*)info)++;
return DIENUM_CONTINUE;
}
static BOOL CALLBACK enum_type_callback(LPCDIDEVICEOBJECTINSTANCE oi, LPVOID info)
{
DWORD expected = *(DWORD*)info;
ok (expected & DIDFT_GETTYPE(oi->dwType), "EnumObjects() enumerated wrong type for obj %s, expected: %08x got: %08x\n", oi->tszName, expected, oi->dwType);
return DIENUM_CONTINUE;
}
static void test_object_info(LPDIRECTINPUTDEVICE device, HWND hwnd)
{
HRESULT hr;
DIPROPDWORD dp;
DIDEVICEOBJECTINSTANCE obj_info;
DWORD obj_types[] = {DIDFT_BUTTON, DIDFT_AXIS, DIDFT_POV};
int type_index;
int cnt1 = 0;
DWORD cnt = 0;
DIDEVICEOBJECTDATA buffer[5];
hr = IDirectInputDevice_EnumObjects(device, enum_callback, &cnt, DIDFT_ALL);
ok(SUCCEEDED(hr), "EnumObjects() failed: %08x\n", hr);
hr = IDirectInputDevice_SetDataFormat(device, &data_format);
ok(SUCCEEDED(hr), "SetDataFormat() failed: %08x\n", hr);
hr = IDirectInputDevice_EnumObjects(device, enum_callback, &cnt1, DIDFT_ALL);
ok(SUCCEEDED(hr), "EnumObjects() failed: %08x\n", hr);
if (0) /* fails for joystick only */
ok(cnt == cnt1, "Enum count changed from %d to %d\n", cnt, cnt1);
/* Testing EnumObjects with different types of device objects */
for (type_index=0; type_index < sizeof(obj_types)/sizeof(obj_types[0]); type_index++)
{
hr = IDirectInputDevice_EnumObjects(device, enum_type_callback, &obj_types[type_index], obj_types[type_index]);
ok(SUCCEEDED(hr), "EnumObjects() failed: %08x\n", hr);
}
/* Test buffered mode */
memset(&dp, 0, sizeof(dp));
dp.diph.dwSize = sizeof(DIPROPDWORD);
dp.diph.dwHeaderSize = sizeof(DIPROPHEADER);
dp.diph.dwHow = DIPH_DEVICE;
dp.diph.dwObj = 0;
dp.dwData = 0;
hr = IDirectInputDevice_SetProperty(device, DIPROP_BUFFERSIZE, (LPCDIPROPHEADER)&dp.diph);
ok(hr == DI_OK, "SetProperty() failed: %08x\n", hr);
cnt = 5;
hr = IDirectInputDevice_GetDeviceData(device, sizeof(buffer[0]), buffer, &cnt, 0);
ok(hr == DI_OK && cnt == 5, "GetDeviceData() failed: %08x cnt: %d\n", hr, cnt);
hr = IDirectInputDevice_GetDeviceData(device, sizeof(DIDEVICEOBJECTDATA_DX3), buffer, &cnt, 0);
ok(hr == DIERR_NOTBUFFERED, "GetDeviceData() should have failed: %08x\n", hr);
IDirectInputDevice_Acquire(device);
hr = IDirectInputDevice_GetDeviceData(device, sizeof(DIDEVICEOBJECTDATA_DX3), buffer, &cnt, 0);
ok(hr == DIERR_NOTBUFFERED, "GetDeviceData() should have failed: %08x\n", hr);
IDirectInputDevice_Unacquire(device);
dp.dwData = 20;
hr = IDirectInputDevice_SetProperty(device, DIPROP_BUFFERSIZE, (LPCDIPROPHEADER)&dp.diph);
ok(hr == DI_OK, "SetProperty() failed: %08x\n", hr);
cnt = 5;
hr = IDirectInputDevice_GetDeviceData(device, sizeof(buffer[0]), buffer, &cnt, 0);
ok(hr == DI_OK, "GetDeviceData() failed: %08x\n", hr);
hr = IDirectInputDevice_GetDeviceData(device, sizeof(DIDEVICEOBJECTDATA_DX3), buffer, &cnt, 0);
ok(hr == DIERR_NOTACQUIRED, "GetDeviceData() should have failed: %08x\n", hr);
hr = IDirectInputDevice_Acquire(device);
ok(hr == DI_OK, "Acquire() failed: %08x\n", hr);
cnt = 1;
hr = IDirectInputDevice_GetDeviceData(device, sizeof(buffer[0]), buffer, &cnt, 0);
ok(hr == DI_OK, "GetDeviceData() failed: %08x\n", hr);
hr = IDirectInputDevice_Unacquire(device);
ok(hr == DI_OK, "Unacquire() failed: %08x\n", hr);
cnt = 1;
hr = IDirectInputDevice_GetDeviceData(device, sizeof(buffer[0]), buffer, &cnt, 0);
ok(hr == DI_OK, "GetDeviceData() failed: %08x\n", hr);
/* No need to test devices without axis */
obj_info.dwSize = sizeof(obj_info);
hr = IDirectInputDevice_GetObjectInfo(device, &obj_info, 16, DIPH_BYOFFSET);
if (SUCCEEDED(hr))
{
/* No device supports per axis relative/absolute mode */
dp.diph.dwHow = DIPH_BYOFFSET;
dp.diph.dwObj = 16;
dp.dwData = DIPROPAXISMODE_ABS;
hr = IDirectInputDevice_SetProperty(device, DIPROP_AXISMODE, &dp.diph);
ok(hr == DIERR_UNSUPPORTED, "SetProperty() returned: %08x\n", hr);
dp.diph.dwHow = DIPH_DEVICE;
hr = IDirectInputDevice_SetProperty(device, DIPROP_AXISMODE, &dp.diph);
ok(hr == DIERR_INVALIDPARAM, "SetProperty() returned: %08x\n", hr);
dp.diph.dwObj = 0;
hr = IDirectInputDevice_SetProperty(device, DIPROP_AXISMODE, &dp.diph);
ok(hr == DI_OK, "SetProperty() failed: %08x\n", hr);
/* Cannot change mode while acquired */
hr = IDirectInputDevice_Acquire(device);
ok(hr == DI_OK, "Acquire() failed: %08x\n", hr);
hr = IDirectInputDevice_SetProperty(device, DIPROP_AXISMODE, &dp.diph);
ok(hr == DIERR_ACQUIRED, "SetProperty() returned: %08x\n", hr);
hr = IDirectInputDevice_Unacquire(device);
ok(hr == DI_OK, "Unacquire() failed: %08x\n", hr);
}
}
struct enum_data
{
LPDIRECTINPUT pDI;
HWND hwnd;
};
static BOOL CALLBACK enum_devices(LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef)
{
struct enum_data *data = pvRef;
LPDIRECTINPUTDEVICE device, obj = NULL;
HRESULT hr;
hr = IDirectInput_GetDeviceStatus(data->pDI, &lpddi->guidInstance);
ok(hr == DI_OK, "IDirectInput_GetDeviceStatus() failed: %08x\n", hr);
if (hr == DI_OK)
{
hr = IDirectInput_CreateDevice(data->pDI, &lpddi->guidInstance, &device, NULL);
ok(SUCCEEDED(hr), "IDirectInput_CreateDevice() failed: %08x\n", hr);
trace("Testing device %p \"%s\"\n", device, lpddi->tszInstanceName);
hr = IUnknown_QueryInterface(device, &IID_IDirectInputDevice2A, (LPVOID*)&obj);
ok(SUCCEEDED(hr), "IUnknown_QueryInterface(IID_IDirectInputDevice7A) failed: %08x\n", hr);
test_object_info(obj, data->hwnd);
if (obj) IUnknown_Release(obj);
obj = NULL;
hr = IUnknown_QueryInterface(device, &IID_IDirectInputDevice2W, (LPVOID*)&obj);
ok(SUCCEEDED(hr), "IUnknown_QueryInterface(IID_IDirectInputDevice7W) failed: %08x\n", hr);
test_object_info(obj, data->hwnd);
if (obj) IUnknown_Release(obj);
IUnknown_Release(device);
}
return DIENUM_CONTINUE;
}
static void device_tests(void)
{
HRESULT hr;
LPDIRECTINPUT pDI = NULL, obj = NULL;
HINSTANCE hInstance = GetModuleHandle(NULL);
HWND hwnd;
struct enum_data data;
hr = CoCreateInstance(&CLSID_DirectInput, 0, 1, &IID_IDirectInput2A, (LPVOID*)&pDI);
if (hr == DIERR_OLDDIRECTINPUTVERSION || hr == DIERR_DEVICENOTREG)
{
skip("Tests require a newer dinput version\n");
return;
}
ok(SUCCEEDED(hr), "DirectInputCreate() failed: %08x\n", hr);
if (FAILED(hr)) return;
hr = IDirectInput_Initialize(pDI, hInstance, DIRECTINPUT_VERSION);
ok(SUCCEEDED(hr), "Initialize() failed: %08x\n", hr);
if (FAILED(hr)) return;
hr = IUnknown_QueryInterface(pDI, &IID_IDirectInput2W, (LPVOID*)&obj);
ok(SUCCEEDED(hr), "QueryInterface(IDirectInput7W) failed: %08x\n", hr);
hwnd = CreateWindow("static", "Title", WS_OVERLAPPEDWINDOW,
10, 10, 200, 200, NULL, NULL, NULL, NULL);
ok(hwnd != NULL, "err: %d\n", GetLastError());
if (hwnd)
{
ShowWindow(hwnd, SW_SHOW);
data.pDI = pDI;
data.hwnd = hwnd;
hr = IDirectInput_EnumDevices(pDI, 0, enum_devices, &data, DIEDFL_ALLDEVICES);
ok(SUCCEEDED(hr), "IDirectInput_EnumDevices() failed: %08x\n", hr);
/* If GetDeviceStatus returns DI_OK the device must exist */
hr = IDirectInput_GetDeviceStatus(pDI, &GUID_Joystick);
if (hr == DI_OK)
{
LPDIRECTINPUTDEVICE device = NULL;
hr = IDirectInput_CreateDevice(pDI, &GUID_Joystick, &device, NULL);
ok(SUCCEEDED(hr), "IDirectInput_CreateDevice() failed: %08x\n", hr);
if (device) IUnknown_Release(device);
}
DestroyWindow(hwnd);
}
if (obj) IUnknown_Release(obj);
if (pDI) IUnknown_Release(pDI);
}
START_TEST(device)
{
CoInitialize(NULL);
device_tests();
CoUninitialize();
}

View file

@ -0,0 +1,632 @@
/*
* Copyright (c) 2011 Andrew Nguyen
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#define WIN32_NO_STATUS
#define _INC_WINDOWS
#define COM_NO_WINDOWS_H
#define DIRECTINPUT_VERSION 0x0700
#define COBJMACROS
#include <wine/test.h>
#include <initguid.h>
//#include <windows.h>
#include <dinput.h>
#include <dinputd.h>
HINSTANCE hInstance;
enum directinput_versions
{
DIRECTINPUT_VERSION_300 = 0x0300,
DIRECTINPUT_VERSION_500 = 0x0500,
DIRECTINPUT_VERSION_50A = 0x050A,
DIRECTINPUT_VERSION_5B2 = 0x05B2,
DIRECTINPUT_VERSION_602 = 0x0602,
DIRECTINPUT_VERSION_61A = 0x061A,
DIRECTINPUT_VERSION_700 = 0x0700,
};
static const DWORD directinput_version_list[] =
{
DIRECTINPUT_VERSION_300,
DIRECTINPUT_VERSION_500,
DIRECTINPUT_VERSION_50A,
DIRECTINPUT_VERSION_5B2,
DIRECTINPUT_VERSION_602,
DIRECTINPUT_VERSION_61A,
DIRECTINPUT_VERSION_700,
};
static HRESULT (WINAPI *pDirectInputCreateEx)(HINSTANCE, DWORD, REFIID, LPVOID *, LPUNKNOWN);
static BOOL CALLBACK dummy_callback(const DIDEVICEINSTANCEA *instance, void *context)
{
ok(0, "Callback was invoked with parameters (%p, %p)\n", instance, context);
return DIENUM_STOP;
}
static void test_preinitialization(void)
{
static const struct
{
REFGUID rguid;
BOOL pdev;
HRESULT expected_hr;
} create_device_tests[] =
{
{NULL, FALSE, E_POINTER},
{NULL, TRUE, E_POINTER},
{&GUID_Unknown, FALSE, E_POINTER},
{&GUID_Unknown, TRUE, DIERR_NOTINITIALIZED},
{&GUID_SysMouse, FALSE, E_POINTER},
{&GUID_SysMouse, TRUE, DIERR_NOTINITIALIZED},
};
static const struct
{
DWORD dwDevType;
LPDIENUMDEVICESCALLBACKA lpCallback;
DWORD dwFlags;
HRESULT expected_hr;
int todo;
} enum_devices_tests[] =
{
{0, NULL, 0, DIERR_INVALIDPARAM},
{0, NULL, ~0u, DIERR_INVALIDPARAM},
{0, dummy_callback, 0, DIERR_NOTINITIALIZED},
{0, dummy_callback, ~0u, DIERR_INVALIDPARAM},
{0xdeadbeef, NULL, 0, DIERR_INVALIDPARAM},
{0xdeadbeef, NULL, ~0u, DIERR_INVALIDPARAM},
{0xdeadbeef, dummy_callback, 0, DIERR_INVALIDPARAM},
{0xdeadbeef, dummy_callback, ~0u, DIERR_INVALIDPARAM},
};
IDirectInputA *pDI;
HRESULT hr;
int i;
IDirectInputDeviceA *pDID;
hr = CoCreateInstance(&CLSID_DirectInput, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectInputA, (void **)&pDI);
if (FAILED(hr))
{
skip("Failed to instantiate a IDirectInputA instance: 0x%08x\n", hr);
return;
}
for (i = 0; i < sizeof(create_device_tests)/sizeof(create_device_tests[0]); i++)
{
if (create_device_tests[i].pdev) pDID = (void *)0xdeadbeef;
hr = IDirectInput_CreateDevice(pDI, create_device_tests[i].rguid,
create_device_tests[i].pdev ? &pDID : NULL,
NULL);
ok(hr == create_device_tests[i].expected_hr, "[%d] IDirectInput_CreateDevice returned 0x%08x\n", i, hr);
if (create_device_tests[i].pdev)
ok(pDID == NULL, "[%d] Output interface pointer is %p\n", i, pDID);
}
for (i = 0; i < sizeof(enum_devices_tests)/sizeof(enum_devices_tests[0]); i++)
{
hr = IDirectInput_EnumDevices(pDI, enum_devices_tests[i].dwDevType,
enum_devices_tests[i].lpCallback,
NULL,
enum_devices_tests[i].dwFlags);
if (enum_devices_tests[i].todo)
{
todo_wine
ok(hr == enum_devices_tests[i].expected_hr, "[%d] IDirectInput_EnumDevice returned 0x%08x\n", i, hr);
}
else
ok(hr == enum_devices_tests[i].expected_hr, "[%d] IDirectInput_EnumDevice returned 0x%08x\n", i, hr);
}
hr = IDirectInput_GetDeviceStatus(pDI, NULL);
ok(hr == E_POINTER, "IDirectInput_GetDeviceStatus returned 0x%08x\n", hr);
hr = IDirectInput_GetDeviceStatus(pDI, &GUID_Unknown);
ok(hr == DIERR_NOTINITIALIZED, "IDirectInput_GetDeviceStatus returned 0x%08x\n", hr);
hr = IDirectInput_GetDeviceStatus(pDI, &GUID_SysMouse);
ok(hr == DIERR_NOTINITIALIZED, "IDirectInput_GetDeviceStatus returned 0x%08x\n", hr);
hr = IDirectInput_RunControlPanel(pDI, NULL, 0);
ok(hr == DIERR_NOTINITIALIZED, "IDirectInput_RunControlPanel returned 0x%08x\n", hr);
hr = IDirectInput_RunControlPanel(pDI, NULL, ~0u);
ok(hr == DIERR_INVALIDPARAM, "IDirectInput_RunControlPanel returned 0x%08x\n", hr);
hr = IDirectInput_RunControlPanel(pDI, (HWND)0xdeadbeef, 0);
ok(hr == E_HANDLE, "IDirectInput_RunControlPanel returned 0x%08x\n", hr);
hr = IDirectInput_RunControlPanel(pDI, (HWND)0xdeadbeef, ~0u);
ok(hr == E_HANDLE, "IDirectInput_RunControlPanel returned 0x%08x\n", hr);
IDirectInput_Release(pDI);
}
static void test_DirectInputCreateEx(void)
{
static const struct
{
BOOL hinst;
DWORD dwVersion;
REFIID riid;
BOOL ppdi;
HRESULT expected_hr;
IUnknown *expected_ppdi;
} invalid_param_list[] =
{
{FALSE, 0, &IID_IUnknown, FALSE, DIERR_NOINTERFACE},
{FALSE, 0, &IID_IUnknown, TRUE, DIERR_NOINTERFACE, (void *)0xdeadbeef},
{FALSE, 0, &IID_IDirectInputA, FALSE, E_POINTER},
{FALSE, 0, &IID_IDirectInputA, TRUE, DIERR_INVALIDPARAM, NULL},
{FALSE, DIRECTINPUT_VERSION, &IID_IUnknown, FALSE, DIERR_NOINTERFACE},
{FALSE, DIRECTINPUT_VERSION, &IID_IUnknown, TRUE, DIERR_NOINTERFACE, (void *)0xdeadbeef},
{FALSE, DIRECTINPUT_VERSION, &IID_IDirectInputA, FALSE, E_POINTER},
{FALSE, DIRECTINPUT_VERSION, &IID_IDirectInputA, TRUE, DIERR_INVALIDPARAM, NULL},
{FALSE, DIRECTINPUT_VERSION - 1, &IID_IUnknown, FALSE, DIERR_NOINTERFACE},
{FALSE, DIRECTINPUT_VERSION - 1, &IID_IUnknown, TRUE, DIERR_NOINTERFACE, (void *)0xdeadbeef},
{FALSE, DIRECTINPUT_VERSION - 1, &IID_IDirectInputA, FALSE, E_POINTER},
{FALSE, DIRECTINPUT_VERSION - 1, &IID_IDirectInputA, TRUE, DIERR_INVALIDPARAM, NULL},
{FALSE, DIRECTINPUT_VERSION + 1, &IID_IUnknown, FALSE, DIERR_NOINTERFACE},
{FALSE, DIRECTINPUT_VERSION + 1, &IID_IUnknown, TRUE, DIERR_NOINTERFACE, (void *)0xdeadbeef},
{FALSE, DIRECTINPUT_VERSION + 1, &IID_IDirectInputA, FALSE, E_POINTER},
{FALSE, DIRECTINPUT_VERSION + 1, &IID_IDirectInputA, TRUE, DIERR_INVALIDPARAM, NULL},
{TRUE, 0, &IID_IUnknown, FALSE, DIERR_NOINTERFACE},
{TRUE, 0, &IID_IUnknown, TRUE, DIERR_NOINTERFACE, (void *)0xdeadbeef},
{TRUE, 0, &IID_IDirectInputA, FALSE, E_POINTER},
{TRUE, 0, &IID_IDirectInputA, TRUE, DIERR_NOTINITIALIZED, NULL},
{TRUE, DIRECTINPUT_VERSION, &IID_IUnknown, FALSE, DIERR_NOINTERFACE},
{TRUE, DIRECTINPUT_VERSION, &IID_IUnknown, TRUE, DIERR_NOINTERFACE, (void *)0xdeadbeef},
{TRUE, DIRECTINPUT_VERSION, &IID_IDirectInputA, FALSE, E_POINTER},
{TRUE, DIRECTINPUT_VERSION - 1, &IID_IUnknown, FALSE, DIERR_NOINTERFACE},
{TRUE, DIRECTINPUT_VERSION - 1, &IID_IUnknown, TRUE, DIERR_NOINTERFACE, (void *)0xdeadbeef},
{TRUE, DIRECTINPUT_VERSION - 1, &IID_IDirectInputA, FALSE, E_POINTER},
{TRUE, DIRECTINPUT_VERSION - 1, &IID_IDirectInputA, TRUE, DIERR_BETADIRECTINPUTVERSION, NULL},
{TRUE, DIRECTINPUT_VERSION + 1, &IID_IUnknown, FALSE, DIERR_NOINTERFACE},
{TRUE, DIRECTINPUT_VERSION + 1, &IID_IUnknown, TRUE, DIERR_NOINTERFACE, (void *)0xdeadbeef},
{TRUE, DIRECTINPUT_VERSION + 1, &IID_IDirectInputA, FALSE, E_POINTER},
{TRUE, DIRECTINPUT_VERSION + 1, &IID_IDirectInputA, TRUE, DIERR_OLDDIRECTINPUTVERSION, NULL},
};
static REFIID no_interface_list[] = {&IID_IUnknown, &IID_IDirectInput8A,
&IID_IDirectInput8W, &IID_IDirectInputDeviceA,
&IID_IDirectInputDeviceW, &IID_IDirectInputDevice2A,
&IID_IDirectInputDevice2W, &IID_IDirectInputDevice7A,
&IID_IDirectInputDevice7W, &IID_IDirectInputDevice8A,
&IID_IDirectInputDevice8W, &IID_IDirectInputEffect};
static REFIID iid_list[] = {&IID_IDirectInputA, &IID_IDirectInputW,
&IID_IDirectInput2A, &IID_IDirectInput2W,
&IID_IDirectInput7A, &IID_IDirectInput7W};
int i, j;
IUnknown *pUnk;
HRESULT hr;
if (!pDirectInputCreateEx)
{
win_skip("DirectInputCreateEx is not available\n");
return;
}
for (i = 0; i < sizeof(invalid_param_list)/sizeof(invalid_param_list[0]); i++)
{
if (invalid_param_list[i].ppdi) pUnk = (void *)0xdeadbeef;
hr = pDirectInputCreateEx(invalid_param_list[i].hinst ? hInstance : NULL,
invalid_param_list[i].dwVersion,
invalid_param_list[i].riid,
invalid_param_list[i].ppdi ? (void **)&pUnk : NULL,
NULL);
ok(hr == invalid_param_list[i].expected_hr, "[%d] DirectInputCreateEx returned 0x%08x\n", i, hr);
if (invalid_param_list[i].ppdi)
ok(pUnk == invalid_param_list[i].expected_ppdi, "[%d] Output interface pointer is %p\n", i, pUnk);
}
for (i = 0; i < sizeof(no_interface_list)/sizeof(no_interface_list[0]); i++)
{
pUnk = (void *)0xdeadbeef;
hr = pDirectInputCreateEx(hInstance, DIRECTINPUT_VERSION, no_interface_list[i], (void **)&pUnk, NULL);
ok(hr == DIERR_NOINTERFACE, "[%d] DirectInputCreateEx returned 0x%08x\n", i, hr);
ok(pUnk == (void *)0xdeadbeef, "[%d] Output interface pointer is %p\n", i, pUnk);
}
for (i = 0; i < sizeof(iid_list)/sizeof(iid_list[0]); i++)
{
pUnk = NULL;
hr = pDirectInputCreateEx(hInstance, DIRECTINPUT_VERSION, iid_list[i], (void **)&pUnk, NULL);
ok(hr == DI_OK, "[%d] DirectInputCreateEx returned 0x%08x\n", i, hr);
ok(pUnk != NULL, "[%d] Output interface pointer is NULL\n", i);
if (pUnk)
IUnknown_Release(pUnk);
}
/* Examine combinations of requested interfaces and version numbers. */
for (i = 0; i < sizeof(directinput_version_list)/sizeof(directinput_version_list[0]); i++)
{
for (j = 0; j < sizeof(iid_list)/sizeof(iid_list[0]); j++)
{
pUnk = NULL;
hr = pDirectInputCreateEx(hInstance, directinput_version_list[i], iid_list[j], (void **)&pUnk, NULL);
ok(hr == DI_OK, "[%d/%d] DirectInputCreateEx returned 0x%08x\n", i, j, hr);
ok(pUnk != NULL, "[%d] Output interface pointer is NULL\n", i);
if (pUnk)
IUnknown_Release(pUnk);
}
}
}
static void test_QueryInterface(void)
{
static REFIID iid_list[] = {&IID_IUnknown, &IID_IDirectInputA, &IID_IDirectInputW,
&IID_IDirectInput2A, &IID_IDirectInput2W,
&IID_IDirectInput7A, &IID_IDirectInput7W};
static const struct
{
REFIID riid;
int test_todo;
} no_interface_list[] =
{
{&IID_IDirectInput8A, 1},
{&IID_IDirectInput8W, 1},
{&IID_IDirectInputDeviceA},
{&IID_IDirectInputDeviceW},
{&IID_IDirectInputDevice2A},
{&IID_IDirectInputDevice2W},
{&IID_IDirectInputDevice7A},
{&IID_IDirectInputDevice7W},
{&IID_IDirectInputDevice8A},
{&IID_IDirectInputDevice8W},
{&IID_IDirectInputEffect},
};
IDirectInputA *pDI;
HRESULT hr;
IUnknown *pUnk;
int i;
hr = DirectInputCreateA(hInstance, DIRECTINPUT_VERSION, &pDI, NULL);
if (FAILED(hr))
{
win_skip("Failed to instantiate a IDirectInputA instance: 0x%08x\n", hr);
return;
}
hr = IDirectInput_QueryInterface(pDI, NULL, NULL);
ok(hr == E_POINTER, "IDirectInput_QueryInterface returned 0x%08x\n", hr);
pUnk = (void *)0xdeadbeef;
hr = IDirectInput_QueryInterface(pDI, NULL, (void **)&pUnk);
ok(hr == E_POINTER, "IDirectInput_QueryInterface returned 0x%08x\n", hr);
ok(pUnk == (void *)0xdeadbeef, "Output interface pointer is %p\n", pUnk);
hr = IDirectInput_QueryInterface(pDI, &IID_IUnknown, NULL);
ok(hr == E_POINTER, "IDirectInput_QueryInterface returned 0x%08x\n", hr);
for (i = 0; i < sizeof(iid_list)/sizeof(iid_list[0]); i++)
{
pUnk = NULL;
hr = IDirectInput_QueryInterface(pDI, iid_list[i], (void **)&pUnk);
ok(hr == S_OK, "[%d] IDirectInput_QueryInterface returned 0x%08x\n", i, hr);
ok(pUnk != NULL, "[%d] Output interface pointer is NULL\n", i);
if (pUnk) IUnknown_Release(pUnk);
}
for (i = 0; i < sizeof(no_interface_list)/sizeof(no_interface_list[0]); i++)
{
pUnk = (void *)0xdeadbeef;
hr = IDirectInput_QueryInterface(pDI, no_interface_list[i].riid, (void **)&pUnk);
if (no_interface_list[i].test_todo)
{
todo_wine
ok(hr == E_NOINTERFACE, "[%d] IDirectInput_QueryInterface returned 0x%08x\n", i, hr);
todo_wine
ok(pUnk == NULL, "[%d] Output interface pointer is %p\n", i, pUnk);
if (pUnk) IUnknown_Release(pUnk);
}
else
{
ok(hr == E_NOINTERFACE, "[%d] IDirectInput_QueryInterface returned 0x%08x\n", i, hr);
ok(pUnk == NULL, "[%d] Output interface pointer is %p\n", i, pUnk);
}
}
IDirectInput_Release(pDI);
}
static void test_CreateDevice(void)
{
IDirectInputA *pDI;
HRESULT hr;
IDirectInputDeviceA *pDID;
hr = DirectInputCreateA(hInstance, DIRECTINPUT_VERSION, &pDI, NULL);
if (FAILED(hr))
{
win_skip("Failed to instantiate a IDirectInputA instance: 0x%08x\n", hr);
return;
}
hr = IDirectInput_CreateDevice(pDI, NULL, NULL, NULL);
ok(hr == E_POINTER, "IDirectInput_CreateDevice returned 0x%08x\n", hr);
pDID = (void *)0xdeadbeef;
hr = IDirectInput_CreateDevice(pDI, NULL, &pDID, NULL);
ok(hr == E_POINTER, "IDirectInput_CreateDevice returned 0x%08x\n", hr);
ok(pDID == NULL, "Output interface pointer is %p\n", pDID);
hr = IDirectInput_CreateDevice(pDI, &GUID_Unknown, NULL, NULL);
ok(hr == E_POINTER, "IDirectInput_CreateDevice returned 0x%08x\n", hr);
pDID = (void *)0xdeadbeef;
hr = IDirectInput_CreateDevice(pDI, &GUID_Unknown, &pDID, NULL);
ok(hr == DIERR_DEVICENOTREG, "IDirectInput_CreateDevice returned 0x%08x\n", hr);
ok(pDID == NULL, "Output interface pointer is %p\n", pDID);
hr = IDirectInput_CreateDevice(pDI, &GUID_SysMouse, NULL, NULL);
ok(hr == E_POINTER, "IDirectInput_CreateDevice returned 0x%08x\n", hr);
hr = IDirectInput_CreateDevice(pDI, &GUID_SysMouse, &pDID, NULL);
ok(hr == DI_OK, "IDirectInput_CreateDevice returned 0x%08x\n", hr);
IDirectInputDevice_Release(pDID);
IDirectInput_Release(pDI);
}
struct enum_devices_test
{
unsigned int device_count;
BOOL return_value;
};
static BOOL CALLBACK enum_devices_callback(const DIDEVICEINSTANCEA *instance, void *context)
{
struct enum_devices_test *enum_test = context;
enum_test->device_count++;
return enum_test->return_value;
}
static void test_EnumDevices(void)
{
IDirectInputA *pDI;
HRESULT hr;
struct enum_devices_test enum_test, enum_test_return;
hr = DirectInputCreateA(hInstance, DIRECTINPUT_VERSION, &pDI, NULL);
if (FAILED(hr))
{
win_skip("Failed to instantiate a IDirectInputA instance: 0x%08x\n", hr);
return;
}
hr = IDirectInput_EnumDevices(pDI, 0, NULL, NULL, 0);
ok(hr == DIERR_INVALIDPARAM, "IDirectInput_EnumDevices returned 0x%08x\n", hr);
hr = IDirectInput_EnumDevices(pDI, 0, NULL, NULL, ~0u);
ok(hr == DIERR_INVALIDPARAM, "IDirectInput_EnumDevices returned 0x%08x\n", hr);
/* Test crashes on Wine. */
if (0)
{
hr = IDirectInput_EnumDevices(pDI, 0, enum_devices_callback, NULL, ~0u);
ok(hr == DIERR_INVALIDPARAM, "IDirectInput_EnumDevices returned 0x%08x\n", hr);
}
hr = IDirectInput_EnumDevices(pDI, 0xdeadbeef, NULL, NULL, 0);
ok(hr == DIERR_INVALIDPARAM, "IDirectInput_EnumDevices returned 0x%08x\n", hr);
hr = IDirectInput_EnumDevices(pDI, 0xdeadbeef, NULL, NULL, ~0u);
ok(hr == DIERR_INVALIDPARAM, "IDirectInput_EnumDevices returned 0x%08x\n", hr);
hr = IDirectInput_EnumDevices(pDI, 0xdeadbeef, enum_devices_callback, NULL, 0);
ok(hr == DIERR_INVALIDPARAM, "IDirectInput_EnumDevices returned 0x%08x\n", hr);
hr = IDirectInput_EnumDevices(pDI, 0xdeadbeef, enum_devices_callback, NULL, ~0u);
ok(hr == DIERR_INVALIDPARAM, "IDirectInput_EnumDevices returned 0x%08x\n", hr);
enum_test.device_count = 0;
enum_test.return_value = DIENUM_CONTINUE;
hr = IDirectInput_EnumDevices(pDI, 0, enum_devices_callback, &enum_test, 0);
ok(hr == DI_OK, "IDirectInput_EnumDevices returned 0x%08x\n", hr);
ok(enum_test.device_count != 0, "Device count is %u\n", enum_test.device_count);
/* Enumeration only stops with an explicit DIENUM_STOP. */
enum_test_return.device_count = 0;
enum_test_return.return_value = 42;
hr = IDirectInput_EnumDevices(pDI, 0, enum_devices_callback, &enum_test_return, 0);
ok(hr == DI_OK, "IDirectInput_EnumDevices returned 0x%08x\n", hr);
ok(enum_test_return.device_count == enum_test.device_count,
"Device count is %u vs. %u\n", enum_test_return.device_count, enum_test.device_count);
enum_test.device_count = 0;
enum_test.return_value = DIENUM_STOP;
hr = IDirectInput_EnumDevices(pDI, 0, enum_devices_callback, &enum_test, 0);
ok(hr == DI_OK, "IDirectInput_EnumDevices returned 0x%08x\n", hr);
ok(enum_test.device_count == 1, "Device count is %u\n", enum_test.device_count);
IDirectInput_Release(pDI);
}
static void test_GetDeviceStatus(void)
{
IDirectInputA *pDI;
HRESULT hr;
hr = DirectInputCreateA(hInstance, DIRECTINPUT_VERSION, &pDI, NULL);
if (FAILED(hr))
{
win_skip("Failed to instantiate a IDirectInputA instance: 0x%08x\n", hr);
return;
}
hr = IDirectInput_GetDeviceStatus(pDI, NULL);
ok(hr == E_POINTER, "IDirectInput_GetDeviceStatus returned 0x%08x\n", hr);
hr = IDirectInput_GetDeviceStatus(pDI, &GUID_Unknown);
todo_wine
ok(hr == DIERR_DEVICENOTREG, "IDirectInput_GetDeviceStatus returned 0x%08x\n", hr);
hr = IDirectInput_GetDeviceStatus(pDI, &GUID_SysMouse);
ok(hr == DI_OK, "IDirectInput_GetDeviceStatus returned 0x%08x\n", hr);
IDirectInput_Release(pDI);
}
static void test_Initialize(void)
{
IDirectInputA *pDI;
HRESULT hr;
int i;
hr = CoCreateInstance(&CLSID_DirectInput, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectInputA, (void **)&pDI);
if (FAILED(hr))
{
win_skip("Failed to instantiate a IDirectInputA instance: 0x%08x\n", hr);
return;
}
hr = IDirectInput_Initialize(pDI, NULL, 0);
ok(hr == DIERR_INVALIDPARAM, "IDirectInput_Initialize returned 0x%08x\n", hr);
hr = IDirectInput_Initialize(pDI, NULL, DIRECTINPUT_VERSION);
ok(hr == DIERR_INVALIDPARAM, "IDirectInput_Initialize returned 0x%08x\n", hr);
hr = IDirectInput_Initialize(pDI, hInstance, 0);
ok(hr == DIERR_NOTINITIALIZED, "IDirectInput_Initialize returned 0x%08x\n", hr);
/* Invalid DirectInput versions less than 0x0700 yield DIERR_BETADIRECTINPUTVERSION. */
hr = IDirectInput_Initialize(pDI, hInstance, 0x0123);
ok(hr == DIERR_BETADIRECTINPUTVERSION, "IDirectInput_Initialize returned 0x%08x\n", hr);
/* Invalid DirectInput versions greater than 0x0700 yield DIERR_BETADIRECTINPUTVERSION. */
hr = IDirectInput_Initialize(pDI, hInstance, 0xcafe);
ok(hr == DIERR_OLDDIRECTINPUTVERSION, "IDirectInput_Initialize returned 0x%08x\n", hr);
for (i = 0; i < sizeof(directinput_version_list)/sizeof(directinput_version_list[0]); i++)
{
hr = IDirectInput_Initialize(pDI, hInstance, directinput_version_list[i]);
ok(hr == DI_OK, "IDirectInput_Initialize returned 0x%08x\n", hr);
}
/* Parameters are still validated after successful initialization. */
hr = IDirectInput_Initialize(pDI, hInstance, 0);
ok(hr == DIERR_NOTINITIALIZED, "IDirectInput_Initialize returned 0x%08x\n", hr);
IDirectInput_Release(pDI);
}
static void test_RunControlPanel(void)
{
IDirectInputA *pDI;
HRESULT hr;
hr = DirectInputCreateA(hInstance, DIRECTINPUT_VERSION, &pDI, NULL);
if (FAILED(hr))
{
win_skip("Failed to instantiate a IDirectInputA instance: 0x%08x\n", hr);
return;
}
if (winetest_interactive)
{
hr = IDirectInput_RunControlPanel(pDI, NULL, 0);
ok(hr == S_OK, "IDirectInput_RunControlPanel returned 0x%08x\n", hr);
hr = IDirectInput_RunControlPanel(pDI, GetDesktopWindow(), 0);
ok(hr == S_OK, "IDirectInput_RunControlPanel returned 0x%08x\n", hr);
}
hr = IDirectInput_RunControlPanel(pDI, NULL, ~0u);
ok(hr == DIERR_INVALIDPARAM, "IDirectInput_RunControlPanel returned 0x%08x\n", hr);
hr = IDirectInput_RunControlPanel(pDI, (HWND)0xdeadbeef, 0);
ok(hr == E_HANDLE, "IDirectInput_RunControlPanel returned 0x%08x\n", hr);
hr = IDirectInput_RunControlPanel(pDI, (HWND)0xdeadbeef, ~0u);
ok(hr == E_HANDLE, "IDirectInput_RunControlPanel returned 0x%08x\n", hr);
IDirectInput_Release(pDI);
}
static void test_DirectInputJoyConfig8(void)
{
IDirectInputA *pDI;
IDirectInputDeviceA *pDID;
IDirectInputJoyConfig8 *pDIJC;
DIJOYCONFIG info;
HRESULT hr;
int i;
hr = DirectInputCreateA(hInstance, DIRECTINPUT_VERSION, &pDI, NULL);
if (FAILED(hr))
{
win_skip("Failed to instantiate a IDirectInputA instance: 0x%08x\n", hr);
return;
}
hr = IDirectInput_QueryInterface(pDI, &IID_IDirectInputJoyConfig8, (void **)&pDIJC);
if (FAILED(hr))
{
win_skip("Failed to instantiate a IDirectInputJoyConfig8 instance: 0x%08x\n", hr);
return;
}
info.dwSize = sizeof(info);
hr = DI_OK;
i = 0;
/* Enumerate all connected joystick GUIDs and try to create the respective devices */
for (i = 0; SUCCEEDED(hr); i++)
{
hr = IDirectInputJoyConfig8_GetConfig(pDIJC, i, &info, DIJC_GUIDINSTANCE);
ok (hr == DI_OK || hr == DIERR_NOMOREITEMS,
"IDirectInputJoyConfig8_GetConfig returned 0x%08x\n", hr);
if (SUCCEEDED(hr))
ok (SUCCEEDED(IDirectInput_CreateDevice(pDI, &info.guidInstance, &pDID, NULL)),
"IDirectInput_CreateDevice failed with guid from GetConfig hr = 0x%08x\n", hr);
}
}
START_TEST(dinput)
{
HMODULE dinput_mod = GetModuleHandleA("dinput.dll");
hInstance = GetModuleHandleA(NULL);
pDirectInputCreateEx = (void *)GetProcAddress(dinput_mod, "DirectInputCreateEx");
CoInitialize(NULL);
test_preinitialization();
test_DirectInputCreateEx();
test_QueryInterface();
test_CreateDevice();
test_EnumDevices();
test_GetDeviceStatus();
test_Initialize();
test_RunControlPanel();
test_DirectInputJoyConfig8();
CoUninitialize();
}

View file

@ -0,0 +1,689 @@
/*
* Copyright (c) 2004-2005 Robert Reif
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#define WIN32_NO_STATUS
#define _INC_WINDOWS
#define COM_NO_WINDOWS_H
#define DIRECTINPUT_VERSION 0x0700
#define COBJMACROS
//#include <windows.h>
//#include <math.h>
#include <stdio.h>
//#include <stdlib.h>
#include <wine/test.h>
//#include "windef.h"
//#include "wingdi.h"
#include <winnls.h>
#include <dinput.h>
#define numObjects(x) (sizeof(x) / sizeof(x[0]))
typedef struct tagUserData {
LPDIRECTINPUT pDI;
DWORD version;
} UserData;
static const DIOBJECTDATAFORMAT dfDIJoystickTest[] = {
{ &GUID_XAxis,DIJOFS_X,DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0},
{ &GUID_YAxis,DIJOFS_Y,DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0},
{ &GUID_ZAxis,DIJOFS_Z,DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0},
{ &GUID_RxAxis,DIJOFS_RX,DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0},
{ &GUID_RyAxis,DIJOFS_RY,DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0},
{ &GUID_RzAxis,DIJOFS_RZ,DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0},
{ &GUID_Button,DIJOFS_BUTTON(0),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
{ &GUID_Button,DIJOFS_BUTTON(1),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
{ &GUID_Button,DIJOFS_BUTTON(2),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
{ &GUID_Button,DIJOFS_BUTTON(3),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
{ &GUID_Button,DIJOFS_BUTTON(4),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
{ &GUID_Button,DIJOFS_BUTTON(5),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
{ &GUID_Button,DIJOFS_BUTTON(6),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
{ &GUID_Button,DIJOFS_BUTTON(7),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
{ &GUID_Button,DIJOFS_BUTTON(8),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
{ &GUID_Button,DIJOFS_BUTTON(9),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
{ &GUID_Button,DIJOFS_BUTTON(10),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
};
static const DIDATAFORMAT c_dfDIJoystickTest = {
sizeof(DIDATAFORMAT),
sizeof(DIOBJECTDATAFORMAT),
DIDF_ABSAXIS,
sizeof(DIJOYSTATE2),
numObjects(dfDIJoystickTest),
(LPDIOBJECTDATAFORMAT)dfDIJoystickTest
};
static HWND get_hwnd(void)
{
HWND hwnd=GetForegroundWindow();
if (!hwnd)
hwnd=GetDesktopWindow();
return hwnd;
}
typedef struct tagJoystickInfo
{
LPDIRECTINPUTDEVICE pJoystick;
DWORD axis;
DWORD pov;
DWORD button;
LONG lMin, lMax;
DWORD dZone;
} JoystickInfo;
static int get_refcount(IUnknown *object)
{
IUnknown_AddRef( object );
return IUnknown_Release( object );
}
static BOOL CALLBACK EnumAxes(
const DIDEVICEOBJECTINSTANCE* pdidoi,
VOID* pContext)
{
HRESULT hr;
JoystickInfo * info = pContext;
if (IsEqualIID(&pdidoi->guidType, &GUID_XAxis) ||
IsEqualIID(&pdidoi->guidType, &GUID_YAxis) ||
IsEqualIID(&pdidoi->guidType, &GUID_ZAxis) ||
IsEqualIID(&pdidoi->guidType, &GUID_RxAxis) ||
IsEqualIID(&pdidoi->guidType, &GUID_RyAxis) ||
IsEqualIID(&pdidoi->guidType, &GUID_RzAxis) ||
IsEqualIID(&pdidoi->guidType, &GUID_Slider))
{
DIPROPRANGE diprg;
DIPROPDWORD dipdw;
diprg.diph.dwSize = sizeof(DIPROPRANGE);
diprg.diph.dwHeaderSize = sizeof(DIPROPHEADER);
diprg.diph.dwHow = DIPH_BYID;
diprg.diph.dwObj = pdidoi->dwType;
dipdw.diph.dwSize = sizeof(dipdw);
dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
dipdw.diph.dwHow = DIPH_BYID;
dipdw.diph.dwObj = pdidoi->dwType;
hr = IDirectInputDevice_GetProperty(info->pJoystick, DIPROP_RANGE, &diprg.diph);
ok(SUCCEEDED(hr), "IDirectInputDevice_GetProperty() failed: %08x\n", hr);
ok(info->lMin == diprg.lMin && info->lMax == diprg.lMax, "Min/Max range invalid: "
"expected %d..%d got %d..%d\n", info->lMin, info->lMax, diprg.lMin, diprg.lMax);
diprg.lMin = -2000;
diprg.lMax = +2000;
hr = IDirectInputDevice_SetProperty(info->pJoystick, DIPROP_RANGE, NULL);
ok(hr==E_INVALIDARG,"IDirectInputDevice_SetProperty() should have returned "
"E_INVALIDARG, returned: %08x\n", hr);
hr = IDirectInputDevice_SetProperty(info->pJoystick, DIPROP_RANGE, &diprg.diph);
ok(hr==DI_OK,"IDirectInputDevice_SetProperty() failed: %08x\n", hr);
/* dead zone */
hr = IDirectInputDevice_GetProperty(info->pJoystick, DIPROP_DEADZONE, &dipdw.diph);
ok(SUCCEEDED(hr), "IDirectInputDevice_GetProperty() failed: %08x\n", hr);
ok(info->dZone == dipdw.dwData, "deadzone invalid: expected %d got %d\n",
info->dZone, dipdw.dwData);
dipdw.dwData = 123;
hr = IDirectInputDevice_SetProperty(info->pJoystick, DIPROP_DEADZONE, &dipdw.diph);
ok(hr==DI_OK,"IDirectInputDevice_SetProperty() failed: %08x\n", hr);
info->axis++;
} else if (IsEqualIID(&pdidoi->guidType, &GUID_POV))
info->pov++;
else if (IsEqualIID(&pdidoi->guidType, &GUID_Button))
info->button++;
return DIENUM_CONTINUE;
}
static const HRESULT SetCoop_null_window[16] = {
E_INVALIDARG, E_INVALIDARG, E_INVALIDARG, E_INVALIDARG,
E_INVALIDARG, E_HANDLE, E_HANDLE, E_INVALIDARG,
E_INVALIDARG, E_HANDLE, S_OK, E_INVALIDARG,
E_INVALIDARG, E_INVALIDARG, E_INVALIDARG, E_INVALIDARG};
static const HRESULT SetCoop_real_window[16] = {
E_INVALIDARG, E_INVALIDARG, E_INVALIDARG, E_INVALIDARG,
E_INVALIDARG, S_OK, S_OK, E_INVALIDARG,
E_INVALIDARG, S_OK, S_OK, E_INVALIDARG,
E_INVALIDARG, E_INVALIDARG, E_INVALIDARG, E_INVALIDARG};
static BOOL CALLBACK EnumJoysticks(
LPCDIDEVICEINSTANCE lpddi,
LPVOID pvRef)
{
HRESULT hr;
UserData * data = pvRef;
LPDIRECTINPUTDEVICE pJoystick;
DIDATAFORMAT format;
DIDEVCAPS caps;
DIJOYSTATE2 js;
JoystickInfo info;
int i, count;
ULONG ref;
DIDEVICEINSTANCE inst;
DIDEVICEINSTANCE_DX3 inst3;
DIPROPDWORD dipw;
DIPROPSTRING dps;
DIPROPGUIDANDPATH dpg;
WCHAR nameBuffer[MAX_PATH];
HWND hWnd = get_hwnd();
char oldstate[248], curstate[248];
ok(data->version > 0x0300, "Joysticks not supported in version 0x%04x\n", data->version);
hr = IDirectInput_CreateDevice(data->pDI, &lpddi->guidInstance, NULL, NULL);
ok(hr==E_POINTER,"IDirectInput_CreateDevice() should have returned "
"E_POINTER, returned: %08x\n", hr);
hr = IDirectInput_CreateDevice(data->pDI, NULL, &pJoystick, NULL);
ok(hr==E_POINTER,"IDirectInput_CreateDevice() should have returned "
"E_POINTER, returned: %08x\n", hr);
hr = IDirectInput_CreateDevice(data->pDI, NULL, NULL, NULL);
ok(hr==E_POINTER,"IDirectInput_CreateDevice() should have returned "
"E_POINTER, returned: %08x\n", hr);
hr = IDirectInput_CreateDevice(data->pDI, &lpddi->guidInstance,
&pJoystick, NULL);
ok(hr==DI_OK,"IDirectInput_CreateDevice() failed: %08x\n", hr);
if (hr!=DI_OK)
goto DONE;
trace("---- %s ----\n", lpddi->tszProductName);
/* Test for joystick ID property */
ZeroMemory(&dipw, sizeof(dipw));
dipw.diph.dwSize = sizeof(DIPROPDWORD);
dipw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
dipw.diph.dwObj = 0;
dipw.diph.dwHow = DIPH_DEVICE;
hr = IDirectInputDevice_GetProperty(pJoystick, DIPROP_JOYSTICKID, &dipw.diph);
ok(SUCCEEDED(hr), "IDirectInputDevice_GetProperty() for DIPROP_JOYSTICKID failed\n");
/* Test for INSTANCENAME property */
memset(&dps, 0, sizeof(dps));
dps.diph.dwSize = sizeof(DIPROPSTRING);
dps.diph.dwHeaderSize = sizeof(DIPROPHEADER);
dps.diph.dwHow = DIPH_DEVICE;
hr = IDirectInputDevice_GetProperty(pJoystick, DIPROP_INSTANCENAME, &dps.diph);
ok(SUCCEEDED(hr), "IDirectInput_GetProperty() for DIPROP_INSTANCENAME failed: %08x\n", hr);
/* Test if instance name is the same as present in DIDEVICEINSTANCE */
MultiByteToWideChar(CP_ACP, 0, lpddi->tszInstanceName, -1, nameBuffer, MAX_PATH);
ok(!lstrcmpW(nameBuffer, dps.wsz), "DIPROP_INSTANCENAME returned is wrong. Expected: %s Got: %s\n",
wine_dbgstr_w(nameBuffer), wine_dbgstr_w(dps.wsz));
/* Test for GUIDPATH properties */
memset(&dpg, 0, sizeof(dpg));
dpg.diph.dwSize = sizeof(DIPROPGUIDANDPATH);
dpg.diph.dwHeaderSize = sizeof(DIPROPHEADER);
dpg.diph.dwHow = DIPH_DEVICE;
hr = IDirectInputDevice_GetProperty(pJoystick, DIPROP_GUIDANDPATH, &dpg.diph);
todo_wine ok(SUCCEEDED(hr), "IDirectInput_GetProperty() for DIPROP_GUIDANDPATH failed: %08x\n", hr);
hr = IDirectInputDevice_SetDataFormat(pJoystick, NULL);
ok(hr==E_POINTER,"IDirectInputDevice_SetDataFormat() should have returned "
"E_POINTER, returned: %08x\n", hr);
ZeroMemory(&format, sizeof(format));
hr = IDirectInputDevice_SetDataFormat(pJoystick, &format);
ok(hr==DIERR_INVALIDPARAM,"IDirectInputDevice_SetDataFormat() should have "
"returned DIERR_INVALIDPARAM, returned: %08x\n", hr);
/* try the default formats */
hr = IDirectInputDevice_SetDataFormat(pJoystick, &c_dfDIJoystick);
ok(hr==DI_OK,"IDirectInputDevice_SetDataFormat() failed: %08x\n", hr);
hr = IDirectInputDevice_SetDataFormat(pJoystick, &c_dfDIJoystick2);
ok(hr==DI_OK,"IDirectInputDevice_SetDataFormat() failed: %08x\n", hr);
/* try an alternate format */
hr = IDirectInputDevice_SetDataFormat(pJoystick, &c_dfDIJoystickTest);
ok(hr==DI_OK,"IDirectInputDevice_SetDataFormat() failed: %08x\n", hr);
hr = IDirectInputDevice_SetDataFormat(pJoystick, &c_dfDIJoystick2);
ok(hr==DI_OK,"IDirectInputDevice_SetDataFormat() failed: %08x\n", hr);
if (hr != DI_OK)
goto RELEASE;
for (i=0; i<16; i++)
{
hr = IDirectInputDevice_SetCooperativeLevel(pJoystick, NULL, i);
ok(hr == SetCoop_null_window[i], "SetCooperativeLevel(NULL, %d): %08x\n", i, hr);
}
for (i=0; i<16; i++)
{
hr = IDirectInputDevice_SetCooperativeLevel(pJoystick, hWnd, i);
ok(hr == SetCoop_real_window[i], "SetCooperativeLevel(hwnd, %d): %08x\n", i, hr);
}
hr = IDirectInputDevice_SetCooperativeLevel(pJoystick, hWnd,
DISCL_NONEXCLUSIVE | DISCL_BACKGROUND);
ok(hr==DI_OK,"IDirectInputDevice_SetCooperativeLevel() failed: %08x\n", hr);
/* get capabilities */
hr = IDirectInputDevice_GetCapabilities(pJoystick, NULL);
ok(hr==E_POINTER,"IDirectInputDevice_GetCapabilities() "
"should have returned E_POINTER, returned: %08x\n", hr);
ZeroMemory(&caps, sizeof(caps));
hr = IDirectInputDevice_GetCapabilities(pJoystick, &caps);
ok(hr==DIERR_INVALIDPARAM,"IDirectInputDevice_GetCapabilities() "
"should have returned DIERR_INVALIDPARAM, returned: %08x\n", hr);
caps.dwSize = sizeof(caps);
hr = IDirectInputDevice_GetCapabilities(pJoystick, &caps);
ok(hr==DI_OK,"IDirectInputDevice_GetCapabilities() failed: %08x\n", hr);
ZeroMemory(&info, sizeof(info));
info.pJoystick = pJoystick;
/* default min/max limits */
info.lMin = 0;
info.lMax = 0xffff;
/* enumerate objects */
hr = IDirectInputDevice_EnumObjects(pJoystick, EnumAxes, &info, DIDFT_ALL);
ok(hr==DI_OK,"IDirectInputDevice_EnumObjects() failed: %08x\n", hr);
ok(caps.dwAxes == info.axis, "Number of enumerated axes (%d) doesn't match capabilities (%d)\n", info.axis, caps.dwAxes);
ok(caps.dwButtons == info.button, "Number of enumerated buttons (%d) doesn't match capabilities (%d)\n", info.button, caps.dwButtons);
ok(caps.dwPOVs == info.pov, "Number of enumerated POVs (%d) doesn't match capabilities (%d)\n", info.pov, caps.dwPOVs);
/* Set format and check limits again */
hr = IDirectInputDevice_SetDataFormat(pJoystick, &c_dfDIJoystick2);
ok(hr==DI_OK,"IDirectInputDevice_SetDataFormat() failed: %08x\n", hr);
info.lMin = -2000;
info.lMax = +2000;
info.dZone= 123;
hr = IDirectInputDevice_EnumObjects(pJoystick, EnumAxes, &info, DIDFT_ALL);
ok(hr==DI_OK,"IDirectInputDevice_EnumObjects() failed: %08x\n", hr);
hr = IDirectInputDevice_GetDeviceInfo(pJoystick, 0);
ok(hr==E_POINTER, "IDirectInputDevice_GetDeviceInfo() "
"should have returned E_POINTER, returned: %08x\n", hr);
ZeroMemory(&inst, sizeof(inst));
ZeroMemory(&inst3, sizeof(inst3));
hr = IDirectInputDevice_GetDeviceInfo(pJoystick, &inst);
ok(hr==DIERR_INVALIDPARAM, "IDirectInputDevice_GetDeviceInfo() "
"should have returned DIERR_INVALIDPARAM, returned: %08x\n", hr);
inst.dwSize = sizeof(inst);
hr = IDirectInputDevice_GetDeviceInfo(pJoystick, &inst);
ok(hr==DI_OK,"IDirectInputDevice_GetDeviceInfo() failed: %08x\n", hr);
inst3.dwSize = sizeof(inst3);
hr = IDirectInputDevice_GetDeviceInfo(pJoystick, (LPDIDEVICEINSTANCE)&inst3);
ok(hr==DI_OK,"IDirectInputDevice_GetDeviceInfo() failed: %08x\n", hr);
hr = IDirectInputDevice_Unacquire(pJoystick);
ok(hr == S_FALSE, "IDirectInputDevice_Unacquire() should have returned S_FALSE, got: %08x\n", hr);
hr = IDirectInputDevice_Acquire(pJoystick);
ok(hr==DI_OK,"IDirectInputDevice_Acquire() failed: %08x\n", hr);
if (hr != DI_OK)
goto RELEASE;
hr = IDirectInputDevice_Acquire(pJoystick);
ok(hr == S_FALSE, "IDirectInputDevice_Acquire() should have returned S_FALSE, got: %08x\n", hr);
if (info.pov < 4)
{
hr = IDirectInputDevice_GetDeviceState(pJoystick, sizeof(DIJOYSTATE2), &js);
ok(hr == DI_OK, "IDirectInputDevice_GetDeviceState() failed: %08x\n", hr);
ok(js.rgdwPOV[3] == -1, "Default for unassigned POV should be -1 not: %d\n", js.rgdwPOV[3]);
}
if (caps.dwFlags & DIDC_FORCEFEEDBACK)
{
DWORD axes[2] = {DIJOFS_X, DIJOFS_Y};
LONG direction[2] = {0, 0};
DICONSTANTFORCE force = {0};
DIEFFECT eff;
LPDIRECTINPUTEFFECT effect = NULL;
LONG cnt1, cnt2;
HWND real_hWnd;
HINSTANCE hInstance = GetModuleHandle(NULL);
DIPROPDWORD dip_gain_set, dip_gain_get;
trace("Testing force-feedback\n");
memset(&eff, 0, sizeof(eff));
eff.dwSize = sizeof(eff);
eff.dwFlags = DIEFF_CARTESIAN | DIEFF_OBJECTOFFSETS;
eff.dwDuration = INFINITE;
eff.dwGain = DI_FFNOMINALMAX;
eff.dwTriggerButton = DIEB_NOTRIGGER;
eff.cAxes = sizeof(axes) / sizeof(axes[0]);
eff.rgdwAxes = axes;
eff.rglDirection = direction;
eff.cbTypeSpecificParams = sizeof(force);
eff.lpvTypeSpecificParams = &force;
/* Sending effects to joystick requires
* calling IDirectInputEffect_Initialize, which requires
* having exclusive access to the device, which requires
* - not having acquired the joystick when calling
* IDirectInputDevice_SetCooperativeLevel
* - a visible window
*/
real_hWnd = CreateWindowEx(0, "EDIT", "Test text", 0, 10, 10, 300,
300, NULL, NULL, hInstance, NULL);
ok(real_hWnd!=0,"CreateWindowEx failed: %p\n", real_hWnd);
ShowWindow(real_hWnd, SW_SHOW);
hr = IDirectInputDevice_Unacquire(pJoystick);
ok(hr==DI_OK,"IDirectInputDevice_Unacquire() failed: %08x\n", hr);
hr = IDirectInputDevice_SetCooperativeLevel(pJoystick, real_hWnd,
DISCL_EXCLUSIVE | DISCL_FOREGROUND);
ok(hr==DI_OK,"IDirectInputDevice_SetCooperativeLevel() failed: %08x\n", hr);
hr = IDirectInputDevice_Acquire(pJoystick);
ok(hr==DI_OK,"IDirectInputDevice_Acquire() failed: %08x\n", hr);
cnt1 = get_refcount((IUnknown*)pJoystick);
hr = IDirectInputDevice2_CreateEffect((LPDIRECTINPUTDEVICE2)pJoystick, &GUID_ConstantForce,
&eff, &effect, NULL);
ok(hr == DI_OK, "IDirectInputDevice_CreateEffect() failed: %08x\n", hr);
cnt2 = get_refcount((IUnknown*)pJoystick);
ok(cnt1 == cnt2, "Ref count is wrong %d != %d\n", cnt1, cnt2);
if (effect)
{
DWORD effect_status;
struct DIPROPDWORD diprop_word;
GUID guid = {0};
hr = IDirectInputEffect_Initialize(effect, hInstance, data->version,
&GUID_ConstantForce);
ok(hr==DI_OK,"IDirectInputEffect_Initialize failed: %08x\n", hr);
hr = IDirectInputEffect_SetParameters(effect, &eff, DIEP_AXES | DIEP_DIRECTION |
DIEP_TYPESPECIFICPARAMS);
ok(hr==DI_OK,"IDirectInputEffect_SetParameters failed: %08x\n", hr);
if (hr==DI_OK) {
/* Test that upload, unacquire, acquire still permits updating
* uploaded effect. */
hr = IDirectInputDevice_Unacquire(pJoystick);
ok(hr==DI_OK,"IDirectInputDevice_Unacquire() failed: %08x\n", hr);
hr = IDirectInputDevice_Acquire(pJoystick);
ok(hr==DI_OK,"IDirectInputDevice_Acquire() failed: %08x\n", hr);
hr = IDirectInputEffect_SetParameters(effect, &eff, DIEP_GAIN);
ok(hr==DI_OK,"IDirectInputEffect_SetParameters failed: %08x\n", hr);
}
/* Check effect status.
* State: initially stopped
* start
* State: started
* unacquire, acquire, download
* State: stopped
* start
* State: started
*
* Shows that:
* - effects are stopped after Unacquire + Acquire
* - effects are preserved (Download + Start doesn't complain
* about incomplete effect)
*/
hr = IDirectInputEffect_GetEffectStatus(effect, &effect_status);
ok(hr==DI_OK,"IDirectInputEffect_GetEffectStatus() failed: %08x\n", hr);
ok(effect_status==0,"IDirectInputEffect_GetEffectStatus() reported effect as started\n");
hr = IDirectInputEffect_SetParameters(effect, &eff, DIEP_START);
ok(hr==DI_OK,"IDirectInputEffect_SetParameters failed: %08x\n", hr);
hr = IDirectInputEffect_GetEffectStatus(effect, &effect_status);
ok(hr==DI_OK,"IDirectInputEffect_GetEffectStatus() failed: %08x\n", hr);
todo_wine ok(effect_status!=0,"IDirectInputEffect_GetEffectStatus() reported effect as stopped\n");
hr = IDirectInputDevice_Unacquire(pJoystick);
ok(hr==DI_OK,"IDirectInputDevice_Unacquire() failed: %08x\n", hr);
hr = IDirectInputDevice_Acquire(pJoystick);
ok(hr==DI_OK,"IDirectInputDevice_Acquire() failed: %08x\n", hr);
hr = IDirectInputEffect_Download(effect);
ok(hr==DI_OK,"IDirectInputEffect_Download() failed: %08x\n", hr);
hr = IDirectInputEffect_GetEffectStatus(effect, &effect_status);
ok(hr==DI_OK,"IDirectInputEffect_GetEffectStatus() failed: %08x\n", hr);
ok(effect_status==0,"IDirectInputEffect_GetEffectStatus() reported effect as started\n");
hr = IDirectInputEffect_Start(effect, 1, 0);
ok(hr==DI_OK,"IDirectInputEffect_Start() failed: %08x\n", hr);
hr = IDirectInputEffect_GetEffectStatus(effect, &effect_status);
ok(hr==DI_OK,"IDirectInputEffect_GetEffectStatus() failed: %08x\n", hr);
todo_wine ok(effect_status!=0,"IDirectInputEffect_GetEffectStatus() reported effect as stopped\n");
hr = IDirectInputEffect_GetEffectGuid(effect, &guid);
ok(hr==DI_OK,"IDirectInputEffect_GetEffectGuid() failed: %08x\n", hr);
ok(IsEqualGUID(&GUID_ConstantForce, &guid), "Wrong guid returned\n");
/* Check autocenter status
* State: initially stopped
* enable
* State: enabled
* acquire
* State: enabled
* unacquire
* State: enabled
*
* IDirectInputDevice2_SetProperty(DIPROP_AUTOCENTER) can only be
* executed when the device is released.
*
* If Executed interactively, user can feel that autocenter is
* only disabled when the joystick is acquired.
*/
diprop_word.diph.dwSize = sizeof(diprop_word);
diprop_word.diph.dwHeaderSize = sizeof(diprop_word.diph);
diprop_word.diph.dwObj = 0;
diprop_word.diph.dwHow = DIPH_DEVICE;
hr = IDirectInputDevice_Unacquire(pJoystick);
ok(hr==DI_OK,"IDirectInputDevice_Unacquire() failed: %08x\n", hr);
hr = IDirectInputDevice2_GetProperty(pJoystick, DIPROP_AUTOCENTER, &diprop_word.diph);
ok(hr==DI_OK,"IDirectInputDevice2_GetProperty() failed: %08x\n", hr);
ok(diprop_word.dwData==DIPROPAUTOCENTER_ON,"IDirectInputDevice2_GetProperty() reported autocenter as disabled\n");
diprop_word.dwData = DIPROPAUTOCENTER_OFF;
hr = IDirectInputDevice2_SetProperty(pJoystick, DIPROP_AUTOCENTER, &diprop_word.diph);
ok(hr==DI_OK,"IDirectInputDevice2_SetProperty() failed: %08x\n", hr);
hr = IDirectInputDevice2_GetProperty(pJoystick, DIPROP_AUTOCENTER, &diprop_word.diph);
ok(hr==DI_OK,"IDirectInputDevice2_GetProperty() failed: %08x\n", hr);
ok(diprop_word.dwData==DIPROPAUTOCENTER_OFF,"IDirectInputDevice2_GetProperty() reported autocenter as enabled\n");
if (winetest_interactive) {
trace("Acquiring in 2s, autocenter will be disabled.\n");
Sleep(2000);
}
hr = IDirectInputDevice_Acquire(pJoystick);
ok(hr==DI_OK,"IDirectInputDevice_Acquire() failed: %08x\n", hr);
if (winetest_interactive)
trace("Acquired.\n");
hr = IDirectInputDevice2_GetProperty(pJoystick, DIPROP_AUTOCENTER, &diprop_word.diph);
ok(hr==DI_OK,"IDirectInputDevice2_GetProperty() failed: %08x\n", hr);
ok(diprop_word.dwData==DIPROPAUTOCENTER_OFF,"IDirectInputDevice2_GetProperty() reported autocenter as enabled\n");
if (winetest_interactive) {
trace("Releasing in 2s, autocenter will be re-enabled.\n");
Sleep(2000);
}
hr = IDirectInputDevice_Unacquire(pJoystick);
ok(hr==DI_OK,"IDirectInputDevice_Unacquire() failed: %08x\n", hr);
if (winetest_interactive)
trace("Released\n");
hr = IDirectInputDevice2_GetProperty(pJoystick, DIPROP_AUTOCENTER, &diprop_word.diph);
ok(hr==DI_OK,"IDirectInputDevice2_GetProperty() failed: %08x\n", hr);
ok(diprop_word.dwData==DIPROPAUTOCENTER_OFF,"IDirectInputDevice2_GetProperty() reported autocenter as enabled\n");
hr = IDirectInputDevice_Acquire(pJoystick);
ok(hr==DI_OK,"IDirectInputDevice_Acquire() failed: %08x\n", hr);
hr = IDirectInputDevice2_GetProperty(pJoystick, DIPROP_AUTOCENTER, &diprop_word.diph);
ok(hr==DI_OK,"IDirectInputDevice2_GetProperty() failed: %08x\n", hr);
/* Device gain (DIPROP_FFGAIN).
* From MSDN:
* 0..10000 range, otherwise DIERR_INVALIDPARAM.
* Can be changed even if device is acquired.
* Difference found by tests:
* <0 is refused, >10000 is accepted
*/
dip_gain_set.diph.dwSize = sizeof(DIPROPDWORD);
dip_gain_set.diph.dwHeaderSize = sizeof(DIPROPHEADER);
dip_gain_set.diph.dwObj = 0;
dip_gain_set.diph.dwHow = DIPH_DEVICE;
dip_gain_set.dwData = 10000;
dip_gain_get.diph.dwSize = sizeof(DIPROPDWORD);
dip_gain_get.diph.dwHeaderSize = sizeof(DIPROPHEADER);
dip_gain_get.diph.dwObj = 0;
dip_gain_get.diph.dwHow = DIPH_DEVICE;
dip_gain_get.dwData = 0;
/* Test device is acquisition (non)impact. */
hr = IDirectInputDevice_Unacquire(pJoystick);
ok(hr == DI_OK, "IDirectInputDevice_Unacquire() should have returned S_FALSE, got: %08x\n", hr);
dip_gain_set.dwData = 1;
hr = IDirectInputDevice_SetProperty(pJoystick, DIPROP_FFGAIN, &dip_gain_set.diph);
ok(hr==DI_OK, "IDirectInputDevice_SetProperty() failed: %08x\n", hr);
hr = IDirectInputDevice_GetProperty(pJoystick, DIPROP_FFGAIN, &dip_gain_get.diph);
ok(hr==DI_OK, "IDirectInputDevice_GetProperty() failed: %08x\n", hr);
ok(dip_gain_get.dwData==dip_gain_set.dwData, "Gain not udated: %i\n", dip_gain_get.dwData);
hr = IDirectInputDevice_Acquire(pJoystick);
ok(hr==DI_OK,"IDirectInputDevice_Acquire() failed: %08x\n", hr);
dip_gain_set.dwData = 2;
hr = IDirectInputDevice_SetProperty(pJoystick, DIPROP_FFGAIN, &dip_gain_set.diph);
ok(hr==DI_OK, "IDirectInputDevice_SetProperty() failed: %08x\n", hr);
hr = IDirectInputDevice_GetProperty(pJoystick, DIPROP_FFGAIN, &dip_gain_get.diph);
ok(hr==DI_OK, "IDirectInputDevice_GetProperty() failed: %08x\n", hr);
ok(dip_gain_get.dwData==dip_gain_set.dwData, "Gain not udated: %i\n", dip_gain_get.dwData);
/* Test range and internal clamping. */
dip_gain_set.dwData = -1;
hr = IDirectInputDevice_SetProperty(pJoystick, DIPROP_FFGAIN, &dip_gain_set.diph);
todo_wine ok(hr==DIERR_INVALIDPARAM, "IDirectInputDevice_SetProperty() should have returned %08x: %08x\n", DIERR_INVALIDPARAM, hr);
dip_gain_set.dwData = 0;
hr = IDirectInputDevice_SetProperty(pJoystick, DIPROP_FFGAIN, &dip_gain_set.diph);
ok(hr==DI_OK, "IDirectInputDevice_SetProperty() failed: %08x\n", hr);
hr = IDirectInputDevice_GetProperty(pJoystick, DIPROP_FFGAIN, &dip_gain_get.diph);
ok(hr==DI_OK, "IDirectInputDevice_GetProperty() failed: %08x\n", hr);
ok(dip_gain_get.dwData==dip_gain_set.dwData, "Gain not updated: %i\n", dip_gain_get.dwData);
dip_gain_set.dwData = 10000;
hr = IDirectInputDevice_SetProperty(pJoystick, DIPROP_FFGAIN, &dip_gain_set.diph);
ok(hr==DI_OK, "IDirectInputDevice_SetProperty() failed: %08x\n", hr);
hr = IDirectInputDevice_GetProperty(pJoystick, DIPROP_FFGAIN, &dip_gain_get.diph);
ok(hr==DI_OK, "IDirectInputDevice_GetProperty() failed: %08x\n", hr);
ok(dip_gain_get.dwData==dip_gain_set.dwData, "Gain not updated: %i\n", dip_gain_get.dwData);
/* WARNING: This call succeeds, on the contrary of what is stated on MSDN. */
dip_gain_set.dwData = 10001;
hr = IDirectInputDevice_SetProperty(pJoystick, DIPROP_FFGAIN, &dip_gain_set.diph);
ok(hr==DI_OK, "IDirectInputDevice_SetProperty() failed: %08x\n", hr);
hr = IDirectInputDevice_GetProperty(pJoystick, DIPROP_FFGAIN, &dip_gain_get.diph);
ok(hr==DI_OK, "IDirectInputDevice_GetProperty() failed: %08x\n", hr);
ok(dip_gain_get.dwData==dip_gain_set.dwData, "Gain not updated: %i\n", dip_gain_get.dwData);
ref = IUnknown_Release(effect);
ok(ref == 0, "IDirectInputDevice_Release() reference count = %d\n", ref);
}
cnt1 = get_refcount((IUnknown*)pJoystick);
ok(cnt1 == cnt2, "Ref count is wrong %d != %d\n", cnt1, cnt2);
/* Before destroying the window, release joystick to revert to
* non-exclusive, background cooperative level. */
hr = IDirectInputDevice_Unacquire(pJoystick);
ok(hr==DI_OK,"IDirectInputDevice_Unacquire() failed: %08x\n", hr);
hr = IDirectInputDevice_SetCooperativeLevel(pJoystick, hWnd,
DISCL_NONEXCLUSIVE | DISCL_BACKGROUND);
ok(hr==DI_OK,"IDirectInputDevice_SetCooperativeLevel() failed: %08x\n", hr);
DestroyWindow (real_hWnd);
hr = IDirectInputDevice_Acquire(pJoystick);
ok(hr==DI_OK,"IDirectInputDevice_Acquire() failed: %08x\n", hr);
}
if (winetest_interactive) {
trace("You have 30 seconds to test all axes, sliders, POVs and buttons\n");
count = 300;
} else
count = 1;
trace("\n");
oldstate[0]='\0';
for (i = 0; i < count; i++) {
hr = IDirectInputDevice_GetDeviceState(pJoystick, sizeof(DIJOYSTATE2), &js);
ok(hr==DI_OK,"IDirectInputDevice_GetDeviceState() failed: %08x\n", hr);
if (hr != DI_OK)
break;
sprintf(curstate, "X%5d Y%5d Z%5d Rx%5d Ry%5d Rz%5d "
"S0%5d S1%5d POV0%5d POV1%5d POV2%5d POV3%5d "
"B %d %d %d %d %d %d %d %d %d %d %d %d\n",
js.lX, js.lY, js.lZ, js.lRx, js.lRy, js.lRz,
js.rglSlider[0], js.rglSlider[1],
js.rgdwPOV[0], js.rgdwPOV[1], js.rgdwPOV[2], js.rgdwPOV[3],
js.rgbButtons[0]>>7, js.rgbButtons[1]>>7, js.rgbButtons[2]>>7,
js.rgbButtons[3]>>7, js.rgbButtons[4]>>7, js.rgbButtons[5]>>7,
js.rgbButtons[6]>>7, js.rgbButtons[7]>>7, js.rgbButtons[8]>>7,
js.rgbButtons[9]>>7, js.rgbButtons[10]>>7, js.rgbButtons[11]>>7);
if (strcmp(oldstate, curstate) != 0)
{
trace("%s\n", curstate);
strcpy(oldstate, curstate);
}
Sleep(100);
}
trace("\n");
hr = IDirectInputDevice_Unacquire(pJoystick);
ok(hr==DI_OK,"IDirectInputDevice_Unacquire() failed: %08x\n", hr);
RELEASE:
ref = IDirectInputDevice_Release(pJoystick);
ok(ref==0,"IDirectInputDevice_Release() reference count = %d\n", ref);
DONE:
return DIENUM_CONTINUE;
}
static void joystick_tests(DWORD version)
{
HRESULT hr;
LPDIRECTINPUT pDI;
ULONG ref;
HINSTANCE hInstance = GetModuleHandle(NULL);
trace("-- Testing Direct Input Version 0x%04x --\n", version);
hr = DirectInputCreate(hInstance, version, &pDI, NULL);
ok(hr==DI_OK||hr==DIERR_OLDDIRECTINPUTVERSION,
"DirectInputCreate() failed: %08x\n", hr);
if (hr==DI_OK && pDI!=0) {
UserData data;
data.pDI = pDI;
data.version = version;
hr = IDirectInput_EnumDevices(pDI, DIDEVTYPE_JOYSTICK, EnumJoysticks,
&data, DIEDFL_ALLDEVICES);
ok(hr==DI_OK,"IDirectInput_EnumDevices() failed: %08x\n", hr);
ref = IDirectInput_Release(pDI);
ok(ref==0,"IDirectInput_Release() reference count = %d\n", ref);
} else if (hr==DIERR_OLDDIRECTINPUTVERSION)
trace(" Version Not Supported\n");
}
START_TEST(joystick)
{
CoInitialize(NULL);
joystick_tests(0x0700);
joystick_tests(0x0500);
joystick_tests(0x0300);
CoUninitialize();
}

View file

@ -0,0 +1,241 @@
/*
* Copyright (c) 2005 Robert Reif
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#define WIN32_NO_STATUS
#define _INC_WINDOWS
#define COM_NO_WINDOWS_H
#define DIRECTINPUT_VERSION 0x0700
#define COBJMACROS
//#include <windows.h>
//#include <math.h>
//#include <stdio.h>
//#include <stdlib.h>
#include <wine/test.h>
//#include "windef.h"
//#include "wingdi.h"
#include <dinput.h>
static void acquire_tests(LPDIRECTINPUT pDI, HWND hwnd)
{
HRESULT hr;
LPDIRECTINPUTDEVICE pKeyboard;
BYTE kbd_state[256];
LONG custom_state[6];
int i;
DIOBJECTDATAFORMAT dodf[] =
{
{ &GUID_Key, sizeof(LONG) * 0, DIDFT_MAKEINSTANCE(DIK_Q)|DIDFT_BUTTON, 0 },
{ &GUID_Key, sizeof(LONG) * 1, DIDFT_MAKEINSTANCE(DIK_W)|DIDFT_BUTTON, 0 },
{ &GUID_Key, sizeof(LONG) * 2, DIDFT_MAKEINSTANCE(DIK_E)|DIDFT_BUTTON, 0 },
{ &GUID_Key, sizeof(LONG) * 4, DIDFT_MAKEINSTANCE(DIK_R)|DIDFT_BUTTON, 0 },
};
DIDATAFORMAT df;
df.dwSize = sizeof( df );
df.dwObjSize = sizeof( DIOBJECTDATAFORMAT );
df.dwFlags = DIDF_RELAXIS;
df.dwDataSize = sizeof( custom_state );
df.dwNumObjs = sizeof( dodf )/sizeof( dodf[0] );
df.rgodf = dodf;
hr = IDirectInput_CreateDevice(pDI, &GUID_SysKeyboard, &pKeyboard, NULL);
ok(SUCCEEDED(hr), "IDirectInput_CreateDevice() failed: %08x\n", hr);
if (FAILED(hr)) return;
hr = IDirectInputDevice_SetDataFormat(pKeyboard, &c_dfDIKeyboard);
ok(SUCCEEDED(hr), "IDirectInputDevice_SetDataFormat() failed: %08x\n", hr);
hr = IDirectInputDevice_SetCooperativeLevel(pKeyboard, NULL, DISCL_NONEXCLUSIVE | DISCL_BACKGROUND);
ok(SUCCEEDED(hr), "IDirectInputDevice_SetCooperativeLevel() failed: %08x\n", hr);
hr = IDirectInputDevice_GetDeviceState(pKeyboard, 10, kbd_state);
ok(hr == DIERR_NOTACQUIRED, "IDirectInputDevice_GetDeviceState(10,) should have failed: %08x\n", hr);
hr = IDirectInputDevice_GetDeviceState(pKeyboard, sizeof(kbd_state), kbd_state);
ok(hr == DIERR_NOTACQUIRED, "IDirectInputDevice_GetDeviceState() should have failed: %08x\n", hr);
hr = IDirectInputDevice_Unacquire(pKeyboard);
ok(hr == S_FALSE, "IDirectInputDevice_Unacquire() should have failed: %08x\n", hr);
hr = IDirectInputDevice_Acquire(pKeyboard);
ok(SUCCEEDED(hr), "IDirectInputDevice_Acquire() failed: %08x\n", hr);
hr = IDirectInputDevice_Acquire(pKeyboard);
ok(hr == S_FALSE, "IDirectInputDevice_Acquire() should have failed: %08x\n", hr);
hr = IDirectInputDevice_GetDeviceState(pKeyboard, 10, kbd_state);
ok(hr == DIERR_INVALIDPARAM, "IDirectInputDevice_GetDeviceState(10,) should have failed: %08x\n", hr);
hr = IDirectInputDevice_GetDeviceState(pKeyboard, sizeof(kbd_state), kbd_state);
ok(SUCCEEDED(hr), "IDirectInputDevice_GetDeviceState() failed: %08x\n", hr);
hr = IDirectInputDevice_Unacquire(pKeyboard);
ok(SUCCEEDED(hr), "IDirectInputDevice_Uncquire() failed: %08x\n", hr);
hr = IDirectInputDevice_SetDataFormat( pKeyboard , &df );
ok(SUCCEEDED(hr), "IDirectInputDevice_SetDataFormat() failed: %08x\n", hr);
hr = IDirectInputDevice_Acquire(pKeyboard);
ok(SUCCEEDED(hr), "IDirectInputDevice_Acquire() failed: %08x\n", hr);
hr = IDirectInputDevice_GetDeviceState(pKeyboard, sizeof(custom_state), custom_state);
ok(SUCCEEDED(hr), "IDirectInputDevice_GetDeviceState(4,) failed: %08x\n", hr);
hr = IDirectInputDevice_GetDeviceState(pKeyboard, sizeof(kbd_state), kbd_state);
ok(hr == DIERR_INVALIDPARAM, "IDirectInputDevice_GetDeviceState(256,) should have failed: %08x\n", hr);
memset(custom_state, 0x56, sizeof(custom_state));
IDirectInputDevice_GetDeviceState(pKeyboard, sizeof(custom_state), custom_state);
for (i = 0; i < sizeof(custom_state) / sizeof(custom_state[0]); i++)
ok(custom_state[i] == 0, "Should be zeroed, got 0x%08x\n", custom_state[i]);
if (pKeyboard) IUnknown_Release(pKeyboard);
}
static const HRESULT SetCoop_null_window[16] = {
E_INVALIDARG, E_INVALIDARG, E_INVALIDARG, E_INVALIDARG,
E_INVALIDARG, E_HANDLE, E_HANDLE, E_INVALIDARG,
E_INVALIDARG, E_HANDLE, S_OK, E_INVALIDARG,
E_INVALIDARG, E_INVALIDARG, E_INVALIDARG, E_INVALIDARG};
static const HRESULT SetCoop_real_window[16] = {
E_INVALIDARG, E_INVALIDARG, E_INVALIDARG, E_INVALIDARG,
E_INVALIDARG, S_OK, S_OK, E_INVALIDARG,
E_INVALIDARG, E_NOTIMPL, S_OK, E_INVALIDARG,
E_INVALIDARG, E_INVALIDARG, E_INVALIDARG, E_INVALIDARG};
static const HRESULT SetCoop_child_window[16] = {
E_INVALIDARG, E_INVALIDARG, E_INVALIDARG, E_INVALIDARG,
E_INVALIDARG, E_HANDLE, E_HANDLE, E_INVALIDARG,
E_INVALIDARG, E_HANDLE, E_HANDLE, E_INVALIDARG,
E_INVALIDARG, E_INVALIDARG, E_INVALIDARG, E_INVALIDARG};
static void test_set_coop(LPDIRECTINPUT pDI, HWND hwnd)
{
HRESULT hr;
LPDIRECTINPUTDEVICE pKeyboard = NULL;
int i;
HWND child;
hr = IDirectInput_CreateDevice(pDI, &GUID_SysKeyboard, &pKeyboard, NULL);
ok(SUCCEEDED(hr), "IDirectInput_CreateDevice() failed: %08x\n", hr);
if (FAILED(hr)) return;
for (i=0; i<16; i++)
{
hr = IDirectInputDevice_SetCooperativeLevel(pKeyboard, NULL, i);
ok(hr == SetCoop_null_window[i], "SetCooperativeLevel(NULL, %d): %08x\n", i, hr);
}
for (i=0; i<16; i++)
{
hr = IDirectInputDevice_SetCooperativeLevel(pKeyboard, hwnd, i);
ok(hr == SetCoop_real_window[i], "SetCooperativeLevel(hwnd, %d): %08x\n", i, hr);
}
child = CreateWindow("static", "Title", WS_CHILD | WS_VISIBLE,
10, 10, 50, 50, hwnd, NULL, NULL, NULL);
ok(child != NULL, "err: %d\n", GetLastError());
for (i=0; i<16; i++)
{
hr = IDirectInputDevice_SetCooperativeLevel(pKeyboard, child, i);
ok(hr == SetCoop_child_window[i], "SetCooperativeLevel(child, %d): %08x\n", i, hr);
}
DestroyWindow(child);
if (pKeyboard) IUnknown_Release(pKeyboard);
}
static void test_get_prop(LPDIRECTINPUT pDI, HWND hwnd)
{
HRESULT hr;
LPDIRECTINPUTDEVICE pKeyboard = NULL;
DIPROPRANGE diprg;
hr = IDirectInput_CreateDevice(pDI, &GUID_SysKeyboard, &pKeyboard, NULL);
ok(SUCCEEDED(hr), "IDirectInput_CreateDevice() failed: %08x\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: %08x\n", hr);
if (pKeyboard) IUnknown_Release(pKeyboard);
}
static void test_capabilities(LPDIRECTINPUT pDI, HWND hwnd)
{
HRESULT hr;
LPDIRECTINPUTDEVICE pKeyboard = NULL;
DIDEVCAPS caps;
hr = IDirectInput_CreateDevice(pDI, &GUID_SysKeyboard, &pKeyboard, NULL);
ok(SUCCEEDED(hr), "IDirectInput_CreateDevice() failed: %08x\n", hr);
if (FAILED(hr)) return;
caps.dwSize = sizeof(caps);
hr = IDirectInputDevice_GetCapabilities(pKeyboard, &caps);
ok (SUCCEEDED(hr), "GetCapabilities failed: 0x%08x\n", hr);
ok (caps.dwFlags & DIDC_ATTACHED, "GetCapabilities dwFlags: 0x%08x\n", caps.dwFlags);
ok (LOWORD(LOBYTE(caps.dwDevType)) == DIDEVTYPE_KEYBOARD,
"GetCapabilities invalid device type for dwDevType: 0x%08x\n", caps.dwDevType);
ok (LOWORD(HIBYTE(caps.dwDevType)) != DIDEVTYPEKEYBOARD_UNKNOWN,
"GetCapabilities invalid device subtype for dwDevType: 0x%08x\n", caps.dwDevType);
IUnknown_Release(pKeyboard);
}
static void keyboard_tests(DWORD version)
{
HRESULT hr;
LPDIRECTINPUT pDI = NULL;
HINSTANCE hInstance = GetModuleHandle(NULL);
HWND hwnd;
ULONG ref = 0;
hr = DirectInputCreate(hInstance, version, &pDI, NULL);
if (hr == DIERR_OLDDIRECTINPUTVERSION)
{
skip("Tests require a newer dinput version\n");
return;
}
ok(SUCCEEDED(hr), "DirectInputCreate() failed: %08x\n", hr);
if (FAILED(hr)) return;
hwnd = CreateWindow("static", "Title", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
10, 10, 200, 200, NULL, NULL, NULL, NULL);
ok(hwnd != NULL, "err: %d\n", GetLastError());
if (hwnd)
{
acquire_tests(pDI, hwnd);
test_set_coop(pDI, hwnd);
test_get_prop(pDI, hwnd);
test_capabilities(pDI, hwnd);
}
DestroyWindow(hwnd);
if (pDI) ref = IUnknown_Release(pDI);
ok(!ref, "IDirectInput_Release() reference count = %d\n", ref);
}
START_TEST(keyboard)
{
CoInitialize(NULL);
keyboard_tests(0x0700);
CoUninitialize();
}

View file

@ -0,0 +1,225 @@
/*
* Copyright (c) 2005 Robert Reif
* Copyright (c) 2006 Vitaliy Margolen
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#define WIN32_NO_STATUS
#define _INC_WINDOWS
#define COM_NO_WINDOWS_H
#define DIRECTINPUT_VERSION 0x0700
#define COBJMACROS
//#include <windows.h>
//#include <math.h>
//#include <stdlib.h>
#include <wine/test.h>
//#include "windef.h"
//#include "wingdi.h"
#include <dinput.h>
static const HRESULT SetCoop_null_window[16] = {
E_INVALIDARG, E_INVALIDARG, E_INVALIDARG, E_INVALIDARG,
E_INVALIDARG, E_HANDLE, E_HANDLE, E_INVALIDARG,
E_INVALIDARG, E_HANDLE, S_OK, E_INVALIDARG,
E_INVALIDARG, E_INVALIDARG, E_INVALIDARG, E_INVALIDARG};
static const HRESULT SetCoop_real_window[16] = {
E_INVALIDARG, E_INVALIDARG, E_INVALIDARG, E_INVALIDARG,
E_INVALIDARG, S_OK, S_OK, E_INVALIDARG,
E_INVALIDARG, E_NOTIMPL, S_OK, E_INVALIDARG,
E_INVALIDARG, E_INVALIDARG, E_INVALIDARG, E_INVALIDARG};
static const HRESULT SetCoop_child_window[16] = {
E_INVALIDARG, E_INVALIDARG, E_INVALIDARG, E_INVALIDARG,
E_INVALIDARG, E_HANDLE, E_HANDLE, E_INVALIDARG,
E_INVALIDARG, E_HANDLE, E_HANDLE, E_INVALIDARG,
E_INVALIDARG, E_INVALIDARG, E_INVALIDARG, E_INVALIDARG};
static void test_set_coop(LPDIRECTINPUT pDI, HWND hwnd)
{
HRESULT hr;
LPDIRECTINPUTDEVICE pMouse = NULL;
int i;
HWND child;
hr = IDirectInput_CreateDevice(pDI, &GUID_SysMouse, &pMouse, NULL);
ok(SUCCEEDED(hr), "IDirectInput_CreateDevice() failed: %08x\n", hr);
if (FAILED(hr)) return;
for (i=0; i<16; i++)
{
hr = IDirectInputDevice_SetCooperativeLevel(pMouse, NULL, i);
ok(hr == SetCoop_null_window[i], "SetCooperativeLevel(NULL, %d): %08x\n", i, hr);
}
for (i=0; i<16; i++)
{
hr = IDirectInputDevice_SetCooperativeLevel(pMouse, hwnd, i);
ok(hr == SetCoop_real_window[i], "SetCooperativeLevel(hwnd, %d): %08x\n", i, hr);
}
child = CreateWindow("static", "Title", WS_CHILD | WS_VISIBLE,
10, 10, 50, 50, hwnd, NULL, NULL, NULL);
ok(child != NULL, "err: %d\n", GetLastError());
for (i=0; i<16; i++)
{
hr = IDirectInputDevice_SetCooperativeLevel(pMouse, child, i);
ok(hr == SetCoop_child_window[i], "SetCooperativeLevel(child, %d): %08x\n", i, hr);
}
DestroyWindow(child);
if (pMouse) IUnknown_Release(pMouse);
}
static void test_acquire(LPDIRECTINPUT pDI, HWND hwnd)
{
HRESULT hr;
LPDIRECTINPUTDEVICE pMouse = NULL;
DIMOUSESTATE m_state;
HWND hwnd2;
DIPROPDWORD di_op;
DIDEVICEOBJECTDATA mouse_state;
DWORD cnt;
int i;
if (! SetForegroundWindow(hwnd))
{
skip("Not running as foreground app, skipping acquire tests\n");
return;
}
hr = IDirectInput_CreateDevice(pDI, &GUID_SysMouse, &pMouse, NULL);
ok(SUCCEEDED(hr), "IDirectInput_CreateDevice() failed: %08x\n", hr);
if (FAILED(hr)) return;
hr = IDirectInputDevice_SetCooperativeLevel(pMouse, hwnd, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND);
ok(hr == S_OK, "SetCooperativeLevel: %08x\n", hr);
memset(&di_op, 0, sizeof(di_op));
di_op.dwData = 5;
di_op.diph.dwHow = DIPH_DEVICE;
di_op.diph.dwSize = sizeof(DIPROPDWORD);
di_op.diph.dwHeaderSize = sizeof(DIPROPHEADER);
hr = IDirectInputDevice_SetProperty(pMouse, DIPROP_BUFFERSIZE, (LPCDIPROPHEADER)&di_op);
ok(hr == S_OK, "SetProperty() failed: %08x\n", hr);
hr = IDirectInputDevice_SetDataFormat(pMouse, &c_dfDIMouse);
ok(SUCCEEDED(hr), "IDirectInputDevice_SetDataFormat() failed: %08x\n", hr);
hr = IDirectInputDevice_Unacquire(pMouse);
ok(hr == S_FALSE, "IDirectInputDevice_Unacquire() should have failed: %08x\n", hr);
hr = IDirectInputDevice_Acquire(pMouse);
ok(SUCCEEDED(hr), "IDirectInputDevice_Acquire() failed: %08x\n", hr);
hr = IDirectInputDevice_Acquire(pMouse);
ok(hr == S_FALSE, "IDirectInputDevice_Acquire() should have failed: %08x\n", hr);
/* Foreground coop level requires window to have focus */
/* Create a temporary window, this should make dinput
* loose mouse input */
hwnd2 = CreateWindow("static", "Temporary", WS_VISIBLE,
10, 210, 200, 200, NULL, NULL, NULL, NULL);
hr = IDirectInputDevice_GetDeviceState(pMouse, sizeof(m_state), &m_state);
ok(hr == DIERR_NOTACQUIRED, "GetDeviceState() should have failed: %08x\n", hr);
/* Workaround so we can test other things. Remove when Wine is fixed */
IDirectInputDevice_Unacquire(pMouse);
hr = IDirectInputDevice_Acquire(pMouse);
ok(hr == DIERR_OTHERAPPHASPRIO, "Acquire() should have failed: %08x\n", hr);
SetActiveWindow( hwnd );
hr = IDirectInputDevice_Acquire(pMouse);
ok(hr == S_OK, "Acquire() failed: %08x\n", hr);
mouse_event(MOUSEEVENTF_MOVE, 10, 10, 0, 0);
cnt = 1;
hr = IDirectInputDevice_GetDeviceData(pMouse, sizeof(mouse_state), &mouse_state, &cnt, 0);
ok(hr == S_OK && cnt > 0, "GetDeviceData() failed: %08x cnt:%d\n", hr, cnt);
mouse_event(MOUSEEVENTF_MOVE, 10, 10, 0, 0);
IDirectInputDevice_Unacquire(pMouse);
cnt = 1;
hr = IDirectInputDevice_GetDeviceData(pMouse, sizeof(mouse_state), &mouse_state, &cnt, 0);
ok(hr == S_OK && cnt > 0, "GetDeviceData() failed: %08x cnt:%d\n", hr, cnt);
IDirectInputDevice_Acquire(pMouse);
mouse_event(MOUSEEVENTF_MOVE, 10, 10, 0, 0);
IDirectInputDevice_Unacquire(pMouse);
IDirectInputDevice_Acquire(pMouse);
cnt = 1;
hr = IDirectInputDevice_GetDeviceData(pMouse, sizeof(mouse_state), &mouse_state, &cnt, 0);
ok(hr == S_OK && cnt > 0, "GetDeviceData() failed: %08x cnt:%d\n", hr, cnt);
/* Check for buffer owerflow */
for (i = 0; i < 6; i++)
mouse_event(MOUSEEVENTF_MOVE, 10 + i, 10 + i, 0, 0);
cnt = 1;
hr = IDirectInputDevice_GetDeviceData(pMouse, sizeof(mouse_state), &mouse_state, &cnt, 0);
ok(hr == DI_OK, "GetDeviceData() failed: %08x cnt:%d\n", hr, cnt);
cnt = 1;
hr = IDirectInputDevice_GetDeviceData(pMouse, sizeof(mouse_state), &mouse_state, &cnt, 0);
ok(hr == DI_OK && cnt == 1, "GetDeviceData() failed: %08x cnt:%d\n", hr, cnt);
if (pMouse) IUnknown_Release(pMouse);
DestroyWindow( hwnd2 );
}
static void mouse_tests(void)
{
HRESULT hr;
LPDIRECTINPUT pDI = NULL;
HINSTANCE hInstance = GetModuleHandle(NULL);
HWND hwnd;
ULONG ref = 0;
hr = DirectInputCreate(hInstance, DIRECTINPUT_VERSION, &pDI, NULL);
if (hr == DIERR_OLDDIRECTINPUTVERSION)
{
skip("Tests require a newer dinput version\n");
return;
}
ok(SUCCEEDED(hr), "DirectInputCreate() failed: %08x\n", hr);
if (FAILED(hr)) return;
hwnd = CreateWindow("static", "Title", WS_OVERLAPPEDWINDOW,
10, 10, 200, 200, NULL, NULL, NULL, NULL);
ok(hwnd != NULL, "err: %d\n", GetLastError());
if (hwnd)
{
ShowWindow(hwnd, SW_SHOW);
test_set_coop(pDI, hwnd);
test_acquire(pDI, hwnd);
DestroyWindow(hwnd);
}
if (pDI) ref = IUnknown_Release(pDI);
ok(!ref, "IDirectInput_Release() reference count = %d\n", ref);
}
START_TEST(mouse)
{
CoInitialize(NULL);
mouse_tests();
CoUninitialize();
}

View file

@ -0,0 +1,20 @@
/* Automatically generated file; DO NOT EDIT!! */
#define STANDALONE
#include <wine/test.h>
extern void func_device(void);
extern void func_dinput(void);
extern void func_joystick(void);
extern void func_keyboard(void);
extern void func_mouse(void);
const struct test winetest_testlist[] =
{
{ "device", func_device },
{ "dinput", func_dinput },
{ "joystick", func_joystick },
{ "keyboard", func_keyboard },
{ "mouse", func_mouse },
{ 0, 0 }
};