ReactOS  0.4.14-dev-358-gbef841c
device.c File Reference
#include <windows.h>
#include "wine/test.h"
#include "windef.h"
#include "dinput.h"
Include dependency graph for device.c:

Go to the source code of this file.

Classes

struct  enum_data
 

Macros

#define DIRECTINPUT_VERSION   0x0700
 
#define COBJMACROS
 

Functions

static BOOL CALLBACK enum_callback (const DIDEVICEOBJECTINSTANCEA *oi, void *info)
 
static BOOL CALLBACK enum_type_callback (const DIDEVICEOBJECTINSTANCEA *oi, void *info)
 
static void test_object_info (IDirectInputDeviceA *device, HWND hwnd)
 
static BOOL CALLBACK enum_devices (const DIDEVICEINSTANCEA *lpddi, void *pvRef)
 
static void device_tests (void)
 
 START_TEST (device)
 

Variables

static const DIOBJECTDATAFORMAT obj_data_format []
 
static const DIDATAFORMAT data_format
 

Macro Definition Documentation

◆ COBJMACROS

#define COBJMACROS

Definition at line 21 of file device.c.

◆ DIRECTINPUT_VERSION

#define DIRECTINPUT_VERSION   0x0700

Definition at line 19 of file device.c.

Function Documentation

◆ device_tests()

static void device_tests ( void  )
static

Definition at line 208 of file device.c.

209 {
210  HRESULT hr;
211  IDirectInputA *pDI = NULL, *obj = NULL;
213  HWND hwnd;
214  struct enum_data data;
215 
216  hr = CoCreateInstance(&CLSID_DirectInput, 0, 1, &IID_IDirectInput2A, (LPVOID*)&pDI);
218  {
219  skip("Tests require a newer dinput version\n");
220  return;
221  }
222  ok(SUCCEEDED(hr), "DirectInputCreateA() failed: %08x\n", hr);
223  if (FAILED(hr)) return;
224 
226  ok(SUCCEEDED(hr), "Initialize() failed: %08x\n", hr);
227  if (FAILED(hr)) return;
228 
229  hr = IUnknown_QueryInterface(pDI, &IID_IDirectInput2W, (LPVOID*)&obj);
230  ok(SUCCEEDED(hr), "QueryInterface(IDirectInput7W) failed: %08x\n", hr);
231 
232  hwnd = CreateWindowA("static", "Title", WS_OVERLAPPEDWINDOW, 10, 10, 200, 200, NULL, NULL,
233  NULL, NULL);
234  ok(hwnd != NULL, "err: %d\n", GetLastError());
235  if (hwnd)
236  {
238 
239  data.pDI = pDI;
240  data.hwnd = hwnd;
242  ok(SUCCEEDED(hr), "IDirectInput_EnumDevices() failed: %08x\n", hr);
243 
244 
245  /* If GetDeviceStatus returns DI_OK the device must exist */
246  hr = IDirectInput_GetDeviceStatus(pDI, &GUID_Joystick);
247  if (hr == DI_OK)
248  {
249  IDirectInputDeviceA *device = NULL;
250 
251  hr = IDirectInput_CreateDevice(pDI, &GUID_Joystick, &device, NULL);
252  ok(SUCCEEDED(hr), "IDirectInput_CreateDevice() failed: %08x\n", hr);
253  if (device) IUnknown_Release(device);
254  }
255 
257  }
258  if (obj) IUnknown_Release(obj);
259  if (pDI) IUnknown_Release(pDI);
260 }
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
HRESULT hr
Definition: shlfolder.c:183
#define IDirectInput_CreateDevice(p, a, b, c)
Definition: dinput.h:2296
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
static BOOL CALLBACK enum_devices(const DIDEVICEINSTANCEA *lpddi, void *pvRef)
Definition: device.c:177
BOOL WINAPI DestroyWindow(_In_ HWND)
HINSTANCE hInstance
Definition: charmap.c:20
Definition: devices.h:37
#define CreateWindowA(a, b, c, d, e, f, g, h, i, j, k)
Definition: winuser.h:4216
smooth NULL
Definition: ftsmooth.c:416
#define SW_SHOW
Definition: winuser.h:769
#define DIERR_OLDDIRECTINPUTVERSION
Definition: dinput.h:141
LONG HRESULT
Definition: typedefs.h:77
#define DIERR_DEVICENOTREG
Definition: dinput.h:147
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
#define DIEDFL_ALLDEVICES
Definition: dinput.h:190
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv)
Definition: compobj.c:3325
IDirectInputA * pDI
Definition: device.c:173
#define ok(value,...)
Definition: atltest.h:57
#define IDirectInput_EnumDevices(p, a, b, c, d)
Definition: dinput.h:2297
#define IDirectInput_GetDeviceStatus(p, a)
Definition: dinput.h:2298
#define skip(...)
Definition: atltest.h:64
#define DIRECTINPUT_VERSION
Definition: device.c:19
#define DI_OK
Definition: dinput.h:128
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:847
#define IDirectInput_Initialize(p, a, b)
Definition: dinput.h:2300
#define SUCCEEDED(hr)
Definition: intsafe.h:57

Referenced by START_TEST().

◆ enum_callback()

static BOOL CALLBACK enum_callback ( const DIDEVICEOBJECTINSTANCEA oi,
void info 
)
static

Definition at line 58 of file device.c.

59 {
60  if (winetest_debug > 1)
61  trace(" Type:%4x Ofs:%3d Flags:%08x Name:%s\n",
62  oi->dwType, oi->dwOfs, oi->dwFlags, oi->tszName);
63  (*(int*)info)++;
64  return DIENUM_CONTINUE;
65 }
int winetest_debug
#define trace
Definition: atltest.h:70
CHAR tszName[MAX_PATH]
Definition: dinput.h:352
#define DIENUM_CONTINUE
Definition: dinput.h:188

Referenced by test_object_info().

◆ enum_devices()

static BOOL CALLBACK enum_devices ( const DIDEVICEINSTANCEA lpddi,
void pvRef 
)
static

Definition at line 177 of file device.c.

178 {
179  struct enum_data *data = pvRef;
180  IDirectInputDeviceA *device, *obj = NULL;
181  HRESULT hr;
182 
184  ok(hr == DI_OK, "IDirectInput_GetDeviceStatus() failed: %08x\n", hr);
185 
186  if (hr == DI_OK)
187  {
189  ok(SUCCEEDED(hr), "IDirectInput_CreateDevice() failed: %08x\n", hr);
190  trace("Testing device %p \"%s\"\n", device, lpddi->tszInstanceName);
191 
192  hr = IUnknown_QueryInterface(device, &IID_IDirectInputDevice2A, (LPVOID*)&obj);
193  ok(SUCCEEDED(hr), "IUnknown_QueryInterface(IID_IDirectInputDevice7A) failed: %08x\n", hr);
194  test_object_info(obj, data->hwnd);
195  if (obj) IUnknown_Release(obj);
196  obj = NULL;
197 
198  hr = IUnknown_QueryInterface(device, &IID_IDirectInputDevice2W, (LPVOID*)&obj);
199  ok(SUCCEEDED(hr), "IUnknown_QueryInterface(IID_IDirectInputDevice7W) failed: %08x\n", hr);
200  test_object_info(obj, data->hwnd);
201  if (obj) IUnknown_Release(obj);
202 
203  IUnknown_Release(device);
204  }
205  return DIENUM_CONTINUE;
206 }
GUID guidInstance
Definition: dinput.h:413
HRESULT hr
Definition: shlfolder.c:183
#define IDirectInput_CreateDevice(p, a, b, c)
Definition: dinput.h:2296
static void test_object_info(IDirectInputDeviceA *device, HWND hwnd)
Definition: device.c:74
Definition: devices.h:37
smooth NULL
Definition: ftsmooth.c:416
#define trace
Definition: atltest.h:70
LONG HRESULT
Definition: typedefs.h:77
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
CHAR tszInstanceName[MAX_PATH]
Definition: dinput.h:416
#define ok(value,...)
Definition: atltest.h:57
#define IDirectInput_GetDeviceStatus(p, a)
Definition: dinput.h:2298
#define DI_OK
Definition: dinput.h:128
#define DIENUM_CONTINUE
Definition: dinput.h:188
#define SUCCEEDED(hr)
Definition: intsafe.h:57

Referenced by device_tests().

◆ enum_type_callback()

static BOOL CALLBACK enum_type_callback ( const DIDEVICEOBJECTINSTANCEA oi,
void info 
)
static

Definition at line 67 of file device.c.

68 {
69  DWORD expected = *(DWORD*)info;
70  ok (expected & DIDFT_GETTYPE(oi->dwType), "EnumObjects() enumerated wrong type for obj %s, expected: %08x got: %08x\n", oi->tszName, expected, oi->dwType);
71  return DIENUM_CONTINUE;
72 }
unsigned long DWORD
Definition: ntddk_ex.h:95
CHAR tszName[MAX_PATH]
Definition: dinput.h:352
#define ok(value,...)
Definition: atltest.h:57
#define DIENUM_CONTINUE
Definition: dinput.h:188
#define DIDFT_GETTYPE(n)
Definition: dinput.h:763
BOOL expected
Definition: store.c:2063

Referenced by test_object_info().

◆ START_TEST()

START_TEST ( device  )

Definition at line 262 of file device.c.

263 {
265 
266  device_tests();
267 
268  CoUninitialize();
269 }
static void device_tests(void)
Definition: device.c:208
smooth NULL
Definition: ftsmooth.c:416
void WINAPI DECLSPEC_HOTPATCH CoUninitialize(void)
Definition: compobj.c:2067
HRESULT WINAPI CoInitialize(LPVOID lpReserved)
Definition: compobj.c:1964

◆ test_object_info()

static void test_object_info ( IDirectInputDeviceA *  device,
HWND  hwnd 
)
static

Definition at line 74 of file device.c.

75 {
76  HRESULT hr;
77  DIPROPDWORD dp;
78  DIDEVICEOBJECTINSTANCEA obj_info;
79  DWORD obj_types[] = {DIDFT_BUTTON, DIDFT_AXIS, DIDFT_POV};
80  int type_index;
81  int cnt1 = 0;
82  DWORD cnt = 0;
84 
86  ok(SUCCEEDED(hr), "EnumObjects() failed: %08x\n", hr);
87 
89  ok(SUCCEEDED(hr), "SetDataFormat() failed: %08x\n", hr);
90 
92  ok(SUCCEEDED(hr), "EnumObjects() failed: %08x\n", hr);
93  if (0) /* fails for joystick only */
94  ok(cnt == cnt1, "Enum count changed from %d to %d\n", cnt, cnt1);
95 
96  /* Testing EnumObjects with different types of device objects */
97  for (type_index=0; type_index < ARRAY_SIZE(obj_types); type_index++)
98  {
99  hr = IDirectInputDevice_EnumObjects(device, enum_type_callback, &obj_types[type_index], obj_types[type_index]);
100  ok(SUCCEEDED(hr), "EnumObjects() failed: %08x\n", hr);
101  }
102 
103  /* Test buffered mode */
104  memset(&dp, 0, sizeof(dp));
105  dp.diph.dwSize = sizeof(DIPROPDWORD);
106  dp.diph.dwHeaderSize = sizeof(DIPROPHEADER);
107  dp.diph.dwHow = DIPH_DEVICE;
108  dp.diph.dwObj = 0;
109  dp.dwData = 0;
110 
112  ok(hr == DI_OK, "SetProperty() failed: %08x\n", hr);
113  cnt = 5;
114  hr = IDirectInputDevice_GetDeviceData(device, sizeof(buffer[0]), buffer, &cnt, 0);
115  ok(hr == DI_OK && cnt == 5, "GetDeviceData() failed: %08x cnt: %d\n", hr, cnt);
117  ok(hr == DIERR_NOTBUFFERED, "GetDeviceData() should have failed: %08x\n", hr);
120  ok(hr == DIERR_NOTBUFFERED, "GetDeviceData() should have failed: %08x\n", hr);
122 
123  dp.dwData = 20;
125  ok(hr == DI_OK, "SetProperty() failed: %08x\n", hr);
126  cnt = 5;
127  hr = IDirectInputDevice_GetDeviceData(device, sizeof(buffer[0]), buffer, &cnt, 0);
128  ok(hr == DI_OK, "GetDeviceData() failed: %08x\n", hr);
130  ok(hr == DIERR_NOTACQUIRED, "GetDeviceData() should have failed: %08x\n", hr);
132  ok(hr == DI_OK, "Acquire() failed: %08x\n", hr);
133  cnt = 1;
134  hr = IDirectInputDevice_GetDeviceData(device, sizeof(buffer[0]), buffer, &cnt, 0);
135  ok(hr == DI_OK, "GetDeviceData() failed: %08x\n", hr);
137  ok(hr == DI_OK, "Unacquire() failed: %08x\n", hr);
138  cnt = 1;
139  hr = IDirectInputDevice_GetDeviceData(device, sizeof(buffer[0]), buffer, &cnt, 0);
140  ok(hr == DI_OK, "GetDeviceData() failed: %08x\n", hr);
141 
142  /* No need to test devices without axis */
143  obj_info.dwSize = sizeof(obj_info);
145  if (SUCCEEDED(hr))
146  {
147  /* No device supports per axis relative/absolute mode */
148  dp.diph.dwHow = DIPH_BYOFFSET;
149  dp.diph.dwObj = 16;
152  ok(hr == DIERR_UNSUPPORTED, "SetProperty() returned: %08x\n", hr);
153  dp.diph.dwHow = DIPH_DEVICE;
155  ok(hr == DIERR_INVALIDPARAM, "SetProperty() returned: %08x\n", hr);
156  dp.diph.dwObj = 0;
158  ok(hr == DI_OK, "SetProperty() failed: %08x\n", hr);
159 
160  /* Cannot change mode while acquired */
162  ok(hr == DI_OK, "Acquire() failed: %08x\n", hr);
163 
165  ok(hr == DIERR_ACQUIRED, "SetProperty() returned: %08x\n", hr);
167  ok(hr == DI_OK, "Unacquire() failed: %08x\n", hr);
168  }
169 }
DWORD dwSize
Definition: dinput.h:828
#define DIPROPAXISMODE_ABS
Definition: dinput.h:888
HRESULT hr
Definition: shlfolder.c:183
#define IDirectInputDevice_EnumObjects(p, a, b, c)
Definition: dinput.h:1605
#define DIERR_NOTACQUIRED
Definition: dinput.h:167
GLuint buffer
Definition: glext.h:5915
DWORD dwHow
Definition: dinput.h:831
#define DIPH_DEVICE
Definition: dinput.h:835
#define DIERR_UNSUPPORTED
Definition: dinput.h:156
DIPROPHEADER diph
Definition: dinput.h:843
Definition: devices.h:37
#define DIDFT_BUTTON
Definition: dinput.h:756
#define DIPH_BYOFFSET
Definition: dinput.h:836
#define IDirectInputDevice_GetObjectInfo(p, a, b, c)
Definition: dinput.h:1615
static const DIDATAFORMAT data_format
Definition: device.c:49
#define DIPROP_BUFFERSIZE
Definition: dinput.h:885
#define DIERR_INVALIDPARAM
Definition: dinput.h:152
#define DIERR_ACQUIRED
Definition: dinput.h:165
LONG HRESULT
Definition: typedefs.h:77
static BOOL CALLBACK enum_callback(const DIDEVICEOBJECTINSTANCEA *oi, void *info)
Definition: device.c:58
unsigned long DWORD
Definition: ntddk_ex.h:95
#define DIDFT_AXIS
Definition: dinput.h:753
DWORD dwData
Definition: dinput.h:844
#define IDirectInputDevice_GetDeviceData(p, a, b, c, d)
Definition: dinput.h:1611
#define IDirectInputDevice_SetProperty(p, a, b)
Definition: dinput.h:1607
#define IDirectInputDevice_Acquire(p)
Definition: dinput.h:1608
struct DIPROPHEADER DIPROPHEADER
#define DIPROP_AXISMODE
Definition: dinput.h:886
#define ARRAY_SIZE(a)
Definition: main.h:24
#define DIDFT_POV
Definition: dinput.h:757
#define ok(value,...)
Definition: atltest.h:57
DWORD dwObj
Definition: dinput.h:830
#define IDirectInputDevice_SetDataFormat(p, a)
Definition: dinput.h:1612
#define DIERR_NOTBUFFERED
Definition: dinput.h:181
static BOOL CALLBACK enum_type_callback(const DIDEVICEOBJECTINSTANCEA *oi, void *info)
Definition: device.c:67
#define DI_OK
Definition: dinput.h:128
#define IDirectInputDevice_Unacquire(p)
Definition: dinput.h:1609
DWORD dwHeaderSize
Definition: dinput.h:829
#define DIDFT_ALL
Definition: dinput.h:750
struct DIPROPDWORD DIPROPDWORD
#define memset(x, y, z)
Definition: compat.h:39
#define SUCCEEDED(hr)
Definition: intsafe.h:57

Referenced by enum_devices().

Variable Documentation

◆ data_format

const DIDATAFORMAT data_format
static
Initial value:
= {
sizeof(DIDATAFORMAT),
32,
}
#define DIDF_ABSAXIS
Definition: dinput.h:775
struct _DIOBJECTDATAFORMAT * LPDIOBJECTDATAFORMAT
struct _DIDATAFORMAT DIDATAFORMAT
#define ARRAY_SIZE(a)
Definition: main.h:24
static const DIOBJECTDATAFORMAT obj_data_format[]
Definition: device.c:28

Definition at line 49 of file device.c.

Referenced by _set_action_map(), and test_object_info().

◆ obj_data_format

const DIOBJECTDATAFORMAT obj_data_format[]
static
Initial value:
= {
{ &GUID_YAxis, 16, DIDFT_OPTIONAL|DIDFT_AXIS |DIDFT_MAKEINSTANCE(1), 0},
{ &GUID_Button,15, DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_MAKEINSTANCE(3), 0},
}
#define DIDFT_MAKEINSTANCE(n)
Definition: dinput.h:762
#define DIDFT_BUTTON
Definition: dinput.h:756
smooth NULL
Definition: ftsmooth.c:416
#define DIDFT_OPTIONAL
Definition: dinput.h:771
#define DIDFT_AXIS
Definition: dinput.h:753

Definition at line 28 of file device.c.