ReactOS  0.4.14-dev-1314-gacf135d
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   0x0800
 
#define COBJMACROS
 

Enumerations

enum  {
  DITEST_AXIS, DITEST_BUTTON, DITEST_KEYBOARDSPACE, DITEST_MOUSEBUTTON0,
  DITEST_YAXIS
}
 

Functions

static void flush_events (void)
 
static void test_device_input (IDirectInputDevice8A *lpdid, DWORD event_type, DWORD event, DWORD expected)
 
static void test_build_action_map (IDirectInputDevice8A *lpdid, DIACTIONFORMATA *lpdiaf, int action_index, DWORD expected_type, DWORD expected_inst)
 
static BOOL CALLBACK enumeration_callback (const DIDEVICEINSTANCEA *lpddi, IDirectInputDevice8A *lpdid, DWORD dwFlags, DWORD dwRemaining, LPVOID pvRef)
 
static void test_action_mapping (void)
 
static void test_save_settings (void)
 
static void test_mouse_keyboard (void)
 
 START_TEST (device)
 

Variables

static const GUID ACTION_MAPPING_GUID = { 0x1, 0x2, 0x3, { 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb } }
 
static const GUID NULL_GUID = { 0, 0, 0, { 0, 0, 0, 0, 0, 0, 0, 0 } }
 
static DIACTIONA actionMapping []
 

Macro Definition Documentation

◆ COBJMACROS

#define COBJMACROS

Definition at line 22 of file device.c.

◆ DIRECTINPUT_VERSION

#define DIRECTINPUT_VERSION   0x0800

Definition at line 20 of file device.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
DITEST_AXIS 
DITEST_BUTTON 
DITEST_KEYBOARDSPACE 
DITEST_MOUSEBUTTON0 
DITEST_YAXIS 

Definition at line 43 of file device.c.

Function Documentation

◆ enumeration_callback()

static BOOL CALLBACK enumeration_callback ( const DIDEVICEINSTANCEA lpddi,
IDirectInputDevice8A *  lpdid,
DWORD  dwFlags,
DWORD  dwRemaining,
LPVOID  pvRef 
)
static

Definition at line 167 of file device.c.

169 {
170  HRESULT hr;
171  DIPROPDWORD dp;
172  DIPROPRANGE dpr;
173  DIPROPSTRING dps;
174  WCHAR usernameW[MAX_PATH];
175  DWORD username_size = MAX_PATH;
176  struct enum_data *data = pvRef;
177  DWORD cnt;
179  IDirectInputDevice8A *lpdid2;
180 
181  if (!data) return DIENUM_CONTINUE;
182 
183  data->ndevices++;
184 
185  /* Convert username to WCHAR */
186  if (data->username != NULL)
187  {
188  username_size = MultiByteToWideChar(CP_ACP, 0, data->username, -1, usernameW, 0);
189  MultiByteToWideChar(CP_ACP, 0, data->username, -1, usernameW, username_size);
190  }
191  else
192  GetUserNameW(usernameW, &username_size);
193 
194  /* collect the mouse and keyboard */
195  if (IsEqualGUID(&lpddi->guidInstance, &GUID_SysKeyboard))
196  {
198  data->keyboard = lpdid;
199 
200  ok (dwFlags & DIEDBS_MAPPEDPRI1, "Keyboard should be mapped as pri1 dwFlags=%08x\n", dwFlags);
201  }
202 
203  if (IsEqualGUID(&lpddi->guidInstance, &GUID_SysMouse))
204  {
206  data->mouse = lpdid;
207 
208  ok (dwFlags & DIEDBS_MAPPEDPRI1, "Mouse should be mapped as pri1 dwFlags=%08x\n", dwFlags);
209  }
210 
211  /* Creating second device object to check if it has the same username */
212  hr = IDirectInput_CreateDevice(data->pDI, &lpddi->guidInstance, &lpdid2, NULL);
213  ok(SUCCEEDED(hr), "IDirectInput_CreateDevice() failed: %08x\n", hr);
214 
215  /* Building and setting an action map */
216  /* It should not use any pre-stored mappings so we use DIDBAM_HWDEFAULTS */
218  ok (SUCCEEDED(hr), "BuildActionMap failed hr=%08x\n", hr);
219 
220  /* Device has no data format and thus can't be acquired */
222  ok (hr == DIERR_INVALIDPARAM, "Device was acquired before SetActionMap hr=%08x\n", hr);
223 
224  hr = IDirectInputDevice8_SetActionMap(lpdid, data->lpdiaf, data->username, 0);
225  ok (SUCCEEDED(hr), "SetActionMap failed hr=%08x\n", hr);
226 
227  /* Some joysticks may have no suitable actions and thus should not be tested */
228  if (hr == DI_NOEFFECT) return DIENUM_CONTINUE;
229 
230  /* Test username after SetActionMap */
231  dps.diph.dwSize = sizeof(dps);
232  dps.diph.dwHeaderSize = sizeof(DIPROPHEADER);
233  dps.diph.dwObj = 0;
234  dps.diph.dwHow = DIPH_DEVICE;
235  dps.wsz[0] = '\0';
236 
238  ok (SUCCEEDED(hr), "GetProperty failed hr=%08x\n", hr);
239  ok (!lstrcmpW(usernameW, dps.wsz), "Username not set correctly expected=%s, got=%s\n", wine_dbgstr_w(usernameW), wine_dbgstr_w(dps.wsz));
240 
241  dps.wsz[0] = '\0';
243  ok (SUCCEEDED(hr), "GetProperty failed hr=%08x\n", hr);
244  ok (!lstrcmpW(usernameW, dps.wsz), "Username not set correctly expected=%s, got=%s\n", wine_dbgstr_w(usernameW), wine_dbgstr_w(dps.wsz));
245 
246  /* Test buffer size */
247  memset(&dp, 0, sizeof(dp));
248  dp.diph.dwSize = sizeof(dp);
249  dp.diph.dwHeaderSize = sizeof(DIPROPHEADER);
250  dp.diph.dwHow = DIPH_DEVICE;
251 
253  ok (SUCCEEDED(hr), "GetProperty failed hr=%08x\n", hr);
254  ok (dp.dwData == data->lpdiaf->dwBufferSize, "SetActionMap must set the buffer, buffersize=%d\n", dp.dwData);
255 
256  cnt = 1;
257  hr = IDirectInputDevice_GetDeviceData(lpdid, sizeof(buffer[0]), buffer, &cnt, 0);
258  ok(hr == DIERR_NOTACQUIRED, "GetDeviceData() failed hr=%08x\n", hr);
259 
260  /* Test axis range */
261  memset(&dpr, 0, sizeof(dpr));
262  dpr.diph.dwSize = sizeof(dpr);
263  dpr.diph.dwHeaderSize = sizeof(DIPROPHEADER);
264  dpr.diph.dwHow = DIPH_DEVICE;
265 
267  /* Only test if device supports the range property */
268  if (SUCCEEDED(hr))
269  {
270  ok (dpr.lMin == data->lpdiaf->lAxisMin, "SetActionMap must set the min axis range expected=%d got=%d\n", data->lpdiaf->lAxisMin, dpr.lMin);
271  ok (dpr.lMax == data->lpdiaf->lAxisMax, "SetActionMap must set the max axis range expected=%d got=%d\n", data->lpdiaf->lAxisMax, dpr.lMax);
272  }
273 
274  /* SetActionMap has set the data format so now it should work */
276  ok (SUCCEEDED(hr), "Acquire failed hr=%08x\n", hr);
277 
278  cnt = 1;
279  hr = IDirectInputDevice_GetDeviceData(lpdid, sizeof(buffer[0]), buffer, &cnt, 0);
280  ok(hr == DI_OK, "GetDeviceData() failed hr=%08x\n", hr);
281 
282  /* SetActionMap should not work on an acquired device */
283  hr = IDirectInputDevice8_SetActionMap(lpdid, data->lpdiaf, NULL, 0);
284  ok (hr == DIERR_ACQUIRED, "SetActionMap succeeded with an acquired device hr=%08x\n", hr);
285 
287 
288  return DIENUM_CONTINUE;
289 }
GUID guidInstance
Definition: dinput.h:413
DWORD dwSize
Definition: dinput.h:828
HRESULT hr
Definition: shlfolder.c:183
#define DIERR_NOTACQUIRED
Definition: dinput.h:167
char * wine_dbgstr_w(const wchar_t *wstr)
Definition: atltest.h:87
#define IDirectInput_CreateDevice(p, a, b, c)
Definition: dinput.h:2296
#define CP_ACP
Definition: compat.h:99
int WINAPI lstrcmpW(LPCWSTR lpString1, LPCWSTR lpString2)
Definition: lstring.c:170
#define IDirectInputDevice_AddRef(p)
Definition: dinput.h:1601
GLuint buffer
Definition: glext.h:5915
#define DIPROP_RANGE
Definition: dinput.h:892
DWORD dwHow
Definition: dinput.h:831
#define IDirectInputDevice8_Acquire(p)
Definition: dinput.h:2042
#define IDirectInputDevice_GetProperty(p, a, b)
Definition: dinput.h:1606
#define IDirectInputDevice8_BuildActionMap(p, a, b, c)
Definition: dinput.h:2067
#define DIPH_DEVICE
Definition: dinput.h:835
DIPROPHEADER diph
Definition: dinput.h:843
smooth NULL
Definition: ftsmooth.c:416
#define IDirectInputDevice_Release(p)
Definition: dinput.h:1602
#define IDirectInputDevice8_SetActionMap(p, a, b, c)
Definition: dinput.h:2068
#define DIPROP_BUFFERSIZE
Definition: dinput.h:885
#define DIERR_INVALIDPARAM
Definition: dinput.h:152
BOOL WINAPI GetUserNameW(LPWSTR lpszName, LPDWORD lpSize)
Definition: misc.c:291
DIPROPHEADER diph
Definition: dinput.h:849
#define DIERR_ACQUIRED
Definition: dinput.h:165
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:78
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
WCHAR wsz[MAX_PATH]
Definition: dinput.h:875
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
#define DIDBAM_HWDEFAULTS
Definition: dinput.h:1355
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
DWORD dwData
Definition: dinput.h:844
#define IDirectInputDevice_GetDeviceData(p, a, b, c, d)
Definition: dinput.h:1611
#define DI_NOEFFECT
Definition: dinput.h:132
struct DIPROPHEADER DIPROPHEADER
#define DIEDBS_MAPPEDPRI1
Definition: dinput.h:445
#define ok(value,...)
Definition: atltest.h:57
DWORD dwObj
Definition: dinput.h:830
BOOL WINAPI IsEqualGUID(REFGUID rguid1, REFGUID rguid2)
Definition: compobj.c:4112
#define MultiByteToWideChar
Definition: compat.h:100
#define DIPROP_USERNAME
Definition: dinput.h:919
LONG lMin
Definition: dinput.h:850
#define DI_OK
Definition: dinput.h:128
#define DIENUM_CONTINUE
Definition: dinput.h:188
DWORD dwHeaderSize
Definition: dinput.h:829
LONG lMax
Definition: dinput.h:851
#define memset(x, y, z)
Definition: compat.h:39
DIPROPHEADER diph
Definition: dinput.h:874
#define SUCCEEDED(hr)
Definition: intsafe.h:57

Referenced by test_action_mapping().

◆ flush_events()

static void flush_events ( void  )
static

Definition at line 70 of file device.c.

71 {
72  int diff = 200;
73  int min_timeout = 100;
74  DWORD time = GetTickCount() + diff;
75 
76  while (diff > 0)
77  {
79  break;
80  diff = time - GetTickCount();
81  min_timeout = 50;
82  }
83 }
DWORD WINAPI GetTickCount(VOID)
Definition: time.c:455
__u16 time
Definition: mkdosfs.c:366
smooth NULL
Definition: ftsmooth.c:416
unsigned long DWORD
Definition: ntddk_ex.h:95
#define WAIT_TIMEOUT
Definition: dderror.h:14
DWORD WINAPI MsgWaitForMultipleObjects(_In_ DWORD nCount, _In_reads_opt_(nCount) CONST HANDLE *pHandles, _In_ BOOL fWaitAll, _In_ DWORD dwMilliseconds, _In_ DWORD dwWakeMask)
#define QS_ALLINPUT
Definition: winuser.h:874

Referenced by test_device_input().

◆ START_TEST()

START_TEST ( device  )

Definition at line 795 of file device.c.

796 {
798 
802 
803  CoUninitialize();
804 }
static void test_save_settings(void)
Definition: device.c:426
static void test_action_mapping(void)
Definition: device.c:291
smooth NULL
Definition: ftsmooth.c:416
static void test_mouse_keyboard(void)
Definition: device.c:613
void WINAPI DECLSPEC_HOTPATCH CoUninitialize(void)
Definition: compobj.c:2067
HRESULT WINAPI CoInitialize(LPVOID lpReserved)
Definition: compobj.c:1964

◆ test_action_mapping()

static void test_action_mapping ( void  )
static

Definition at line 291 of file device.c.

292 {
293  HRESULT hr;
295  IDirectInput8A *pDI = NULL;
296  DIACTIONFORMATA af;
297  DIPROPSTRING dps;
298  struct enum_data data = {pDI, &af, NULL, NULL, NULL, 0};
299  HWND hwnd;
300 
301  hr = CoCreateInstance(&CLSID_DirectInput8, 0, CLSCTX_INPROC_SERVER, &IID_IDirectInput8A, (LPVOID*)&pDI);
305  {
306  win_skip("ActionMapping requires dinput8\n");
307  return;
308  }
309  ok(SUCCEEDED(hr), "DirectInput8 Create failed: hr=%08x\n", hr);
310  if (FAILED(hr)) return;
311 
314  {
315  win_skip("ActionMapping requires dinput8\n");
316  return;
317  }
318  ok(SUCCEEDED(hr), "DirectInput8 Initialize failed: hr=%08x\n", hr);
319  if (FAILED(hr)) return;
320 
321  memset (&af, 0, sizeof(af));
322  af.dwSize = sizeof(af);
323  af.dwActionSize = sizeof(DIACTIONA);
328  af.dwGenre = 0x01000000; /* DIVIRTUAL_DRIVING_RACE */
329  af.dwBufferSize = 32;
330 
331  /* This enumeration builds and sets the action map for all devices */
332  data.pDI = pDI;
334  ok (SUCCEEDED(hr), "EnumDevicesBySemantics failed: hr=%08x\n", hr);
335 
336  if (data.keyboard)
338 
339  if (data.mouse)
341 
342  /* Repeat tests with a non NULL user */
343  data.username = "Ninja Brian";
345  ok (SUCCEEDED(hr), "EnumDevicesBySemantics failed: hr=%08x\n", hr);
346 
347  hwnd = CreateWindowExA(WS_EX_TOPMOST, "static", "dinput",
348  WS_POPUP | WS_VISIBLE, 0, 0, 100, 100, NULL, NULL, NULL, NULL);
349  ok(hwnd != NULL, "failed to create window\n");
350  SetCursorPos(50, 50);
351 
352  if (data.keyboard != NULL)
353  {
354  /* Test keyboard BuildActionMap */
356  /* Test keyboard input */
358 
359  /* Test BuildActionMap with no suitable actions for a device */
363 
365  ok (hr == DI_NOEFFECT, "BuildActionMap should have no effect with no actions hr=%08x\n", hr);
366 
367  hr = IDirectInputDevice8_SetActionMap(data.keyboard, data.lpdiaf, NULL, 0);
368  ok (hr == DI_NOEFFECT, "SetActionMap should have no effect with no actions to map hr=%08x\n", hr);
369 
370  /* Test that after changing actionformat SetActionMap has effect and that second
371  * SetActionMap call with same empty actionformat has no effect */
372  af.dwDataSize = 4 * 1;
373  af.dwNumActions = 1;
374 
375  hr = IDirectInputDevice8_SetActionMap(data.keyboard, data.lpdiaf, NULL, 0);
376  ok (hr != DI_NOEFFECT, "SetActionMap should have effect as actionformat has changed hr=%08x\n", hr);
377 
378  hr = IDirectInputDevice8_SetActionMap(data.keyboard, data.lpdiaf, NULL, 0);
379  ok (hr == DI_NOEFFECT, "SetActionMap should have no effect with no actions to map hr=%08x\n", hr);
380 
383 
384  /* test DIDSAM_NOUSER */
385  dps.diph.dwSize = sizeof(dps);
386  dps.diph.dwHeaderSize = sizeof(DIPROPHEADER);
387  dps.diph.dwObj = 0;
388  dps.diph.dwHow = DIPH_DEVICE;
389  dps.wsz[0] = '\0';
390 
392  ok (SUCCEEDED(hr), "GetProperty failed hr=%08x\n", hr);
393  ok (dps.wsz[0] != 0, "Expected any username, got=%s\n", wine_dbgstr_w(dps.wsz));
394 
396  ok (SUCCEEDED(hr), "SetActionMap failed hr=%08x\n", hr);
397 
398  dps.diph.dwSize = sizeof(dps);
399  dps.diph.dwHeaderSize = sizeof(DIPROPHEADER);
400  dps.diph.dwObj = 0;
401  dps.diph.dwHow = DIPH_DEVICE;
402  dps.wsz[0] = '\0';
403 
405  ok (SUCCEEDED(hr), "GetProperty failed hr=%08x\n", hr);
406  ok (dps.wsz[0] == 0, "Expected empty username, got=%s\n", wine_dbgstr_w(dps.wsz));
407 
409  }
410 
411  if (data.mouse != NULL)
412  {
413  /* Test mouse BuildActionMap */
416 
418 
420  }
421 
424 }
#define MOUSEEVENTF_LEFTDOWN
Definition: winuser.h:1170
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
DWORD dwBufferSize
Definition: dinput.h:1315
DWORD dwSize
Definition: dinput.h:828
HRESULT hr
Definition: shlfolder.c:183
#define DIDFT_PSHBUTTON
Definition: dinput.h:754
char * wine_dbgstr_w(const wchar_t *wstr)
Definition: atltest.h:87
DWORD dwNumActions
Definition: dinput.h:1311
#define DIRECTINPUT_VERSION
Definition: device.c:20
DWORD dwHow
Definition: dinput.h:831
static const GUID ACTION_MAPPING_GUID
Definition: device.c:39
BOOL WINAPI DestroyWindow(_In_ HWND)
#define IDirectInputDevice_GetProperty(p, a, b)
Definition: dinput.h:1606
#define IDirectInputDevice8_BuildActionMap(p, a, b, c)
Definition: dinput.h:2067
#define DIPH_DEVICE
Definition: dinput.h:835
DWORD dwDataSize
Definition: dinput.h:1310
#define INPUT_KEYBOARD
Definition: winable.h:10
static void test_build_action_map(IDirectInputDevice8A *lpdid, DIACTIONFORMATA *lpdiaf, int action_index, DWORD expected_type, DWORD expected_inst)
Definition: device.c:140
struct _DIACTIONA DIACTIONA
smooth NULL
Definition: ftsmooth.c:416
static DIACTIONA actionMapping[]
Definition: device.c:51
#define DIK_SPACE
Definition: dinput.h:526
#define IDirectInputDevice_Release(p)
Definition: dinput.h:1602
#define IDirectInput8_Initialize(p, a, b)
Definition: dinput.h:2517
#define DIDSAM_NOUSER
Definition: dinput.h:1358
#define IDirectInputDevice8_SetActionMap(p, a, b, c)
Definition: dinput.h:2068
#define INPUT_MOUSE
Definition: winable.h:9
#define IDirectInput_Release(p)
Definition: dinput.h:2294
#define DIERR_OLDDIRECTINPUTVERSION
Definition: dinput.h:141
LONG HRESULT
Definition: typedefs.h:78
BOOL WINAPI SetCursorPos(_In_ int, _In_ int)
Definition: cursoricon.c:2627
WCHAR wsz[MAX_PATH]
Definition: dinput.h:875
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
#define DIDBAM_HWDEFAULTS
Definition: dinput.h:1355
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
#define WS_EX_TOPMOST
Definition: pedump.c:647
#define DI_NOEFFECT
Definition: dinput.h:132
static void test_device_input(IDirectInputDevice8A *lpdid, DWORD event_type, DWORD event, DWORD expected)
Definition: device.c:85
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv)
Definition: compobj.c:3325
struct DIPROPHEADER DIPROPHEADER
#define IDirectInput8_EnumDevicesBySemantics(p, a, b, c, d, e)
Definition: dinput.h:2519
#define REGDB_E_CLASSNOTREG
Definition: winerror.h:2696
IDirectInputA * pDI
Definition: device.c:173
#define ARRAY_SIZE(a)
Definition: main.h:24
#define ok(value,...)
Definition: atltest.h:57
DWORD dwActionSize
Definition: dinput.h:1309
DWORD dwObj
Definition: dinput.h:830
static BOOL CALLBACK enumeration_callback(const DIDEVICEINSTANCEA *lpddi, IDirectInputDevice8A *lpdid, DWORD dwFlags, DWORD dwRemaining, LPVOID pvRef)
Definition: device.c:167
#define WS_POPUP
Definition: pedump.c:616
LPDIACTIONA rgoAction
Definition: dinput.h:1312
#define VK_SPACE
Definition: winuser.h:2194
#define DIPROP_USERNAME
Definition: dinput.h:919
HWND WINAPI CreateWindowExA(_In_ DWORD dwExStyle, _In_opt_ LPCSTR lpClassName, _In_opt_ LPCSTR lpWindowName, _In_ DWORD dwStyle, _In_ int X, _In_ int Y, _In_ int nWidth, _In_ int nHeight, _In_opt_ HWND hWndParent, _In_opt_ HMENU hMenu, _In_opt_ HINSTANCE hInstance, _In_opt_ LPVOID lpParam)
#define IDirectInputDevice_Unacquire(p)
Definition: dinput.h:1609
DWORD dwHeaderSize
Definition: dinput.h:829
static HINSTANCE hinst
Definition: edit.c:551
#define WS_VISIBLE
Definition: pedump.c:620
#define memset(x, y, z)
Definition: compat.h:39
#define win_skip
Definition: test.h:149
DIPROPHEADER diph
Definition: dinput.h:874
#define DIEDBSFL_ATTACHEDONLY
Definition: dinput.h:450
#define DIERR_BETADIRECTINPUTVERSION
Definition: dinput.h:143
#define SUCCEEDED(hr)
Definition: intsafe.h:57
#define DIDFT_RELAXIS
Definition: dinput.h:751
GUID guidActionMap
Definition: dinput.h:1313

Referenced by START_TEST().

◆ test_build_action_map()

static void test_build_action_map ( IDirectInputDevice8A *  lpdid,
DIACTIONFORMATA lpdiaf,
int  action_index,
DWORD  expected_type,
DWORD  expected_inst 
)
static

Definition at line 140 of file device.c.

142 {
143  HRESULT hr;
144  DIACTIONA *actions;
145  DWORD instance, type, how;
146  GUID assigned_to;
147  DIDEVICEINSTANCEA ddi;
148 
149  ddi.dwSize = sizeof(ddi);
151 
153  ok (SUCCEEDED(hr), "BuildActionMap failed hr=%08x\n", hr);
154 
155  actions = lpdiaf->rgoAction;
156  instance = DIDFT_GETINSTANCE(actions[action_index].dwObjID);
157  type = DIDFT_GETTYPE(actions[action_index].dwObjID);
158  how = actions[action_index].dwHow;
159  assigned_to = actions[action_index].guidInstance;
160 
161  ok (how == DIAH_USERCONFIG || how == DIAH_DEFAULT, "Action was not set dwHow=%08x\n", how);
162  ok (instance == expected_inst, "Action not mapped correctly instance=%08x expected=%08x\n", instance, expected_inst);
163  ok (type == expected_type, "Action type not mapped correctly type=%08x expected=%08x\n", type, expected_type);
164  ok (IsEqualGUID(&assigned_to, &ddi.guidInstance), "Action and device GUID do not match action=%d\n", action_index);
165 }
GUID guidInstance
Definition: dinput.h:413
HRESULT hr
Definition: shlfolder.c:183
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
#define DIDFT_GETINSTANCE(n)
Definition: dinput.h:764
#define IDirectInputDevice8_BuildActionMap(p, a, b, c)
Definition: dinput.h:2067
GUID guidInstance
Definition: dinput.h:1269
smooth NULL
Definition: ftsmooth.c:416
DWORD dwHow
Definition: dinput.h:1271
LONG HRESULT
Definition: typedefs.h:78
unsigned long DWORD
Definition: ntddk_ex.h:95
DIACTIONFORMATA * lpdiaf
Definition: device.c:31
#define DIDBAM_HWDEFAULTS
Definition: dinput.h:1355
#define DIAH_USERCONFIG
Definition: dinput.h:1300
#define ok(value,...)
Definition: atltest.h:57
static HINSTANCE instance
Definition: main.c:40
#define DIAH_DEFAULT
Definition: dinput.h:1304
#define IDirectInputDevice_GetDeviceInfo(p, a)
Definition: dinput.h:1616
LPDIACTIONA rgoAction
Definition: dinput.h:1312
BOOL WINAPI IsEqualGUID(REFGUID rguid1, REFGUID rguid2)
Definition: compobj.c:4112
#define DIDFT_GETTYPE(n)
Definition: dinput.h:763
#define SUCCEEDED(hr)
Definition: intsafe.h:57

Referenced by test_action_mapping().

◆ test_device_input()

static void test_device_input ( IDirectInputDevice8A *  lpdid,
DWORD  event_type,
DWORD  event,
DWORD  expected 
)
static

Definition at line 85 of file device.c.

86 {
87  HRESULT hr;
88  DIDEVICEOBJECTDATA obj_data;
89  DWORD data_size = 1;
90  int i;
91 
93  ok (SUCCEEDED(hr), "Failed to acquire device hr=%08x\n", hr);
94 
95  if (event_type == INPUT_KEYBOARD)
96  keybd_event( event, DIK_SPACE, 0, 0);
97 
98  if (event_type == INPUT_MOUSE)
99  mouse_event( event, 0, 0, 0, 0);
100 
101  flush_events();
103  hr = IDirectInputDevice8_GetDeviceData(lpdid, sizeof(obj_data), &obj_data, &data_size, 0);
104 
105  if (data_size != 1)
106  {
107  win_skip("We're not able to inject input into Windows dinput8 with events\n");
109  return;
110  }
111 
112  ok (obj_data.uAppData == expected, "Retrieval of action failed uAppData=%lu expected=%d\n", obj_data.uAppData, expected);
113 
114  /* Check for buffer overflow */
115  for (i = 0; i < 17; i++)
116  if (event_type == INPUT_KEYBOARD)
117  {
118  keybd_event( VK_SPACE, DIK_SPACE, 0, 0);
120  }
121  else if (event_type == INPUT_MOUSE)
122  {
123  mouse_event(MOUSEEVENTF_LEFTDOWN, 1, 1, 0, 0);
124  mouse_event(MOUSEEVENTF_LEFTUP, 1, 1, 0, 0);
125  }
126 
127  flush_events();
129 
130  data_size = 1;
131  hr = IDirectInputDevice8_GetDeviceData(lpdid, sizeof(obj_data), &obj_data, &data_size, 0);
132  ok(hr == DI_BUFFEROVERFLOW, "GetDeviceData() failed: %08x\n", hr);
133  data_size = 1;
134  hr = IDirectInputDevice8_GetDeviceData(lpdid, sizeof(obj_data), &obj_data, &data_size, 0);
135  ok(hr == DI_OK && data_size == 1, "GetDeviceData() failed: %08x cnt:%d\n", hr, data_size);
136 
138 }
#define MOUSEEVENTF_LEFTDOWN
Definition: winuser.h:1170
HRESULT hr
Definition: shlfolder.c:183
#define KEYEVENTF_KEYUP
Definition: winuser.h:1092
#define IDirectInputDevice8_Acquire(p)
Definition: dinput.h:2042
#define DI_BUFFEROVERFLOW
Definition: dinput.h:130
#define IDirectInputDevice8_GetDeviceData(p, a, b, c, d)
Definition: dinput.h:2045
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define INPUT_KEYBOARD
Definition: winable.h:10
void WINAPI mouse_event(_In_ DWORD, _In_ DWORD, _In_ DWORD, _In_ DWORD, _In_ ULONG_PTR)
#define DIK_SPACE
Definition: dinput.h:526
#define IDirectInputDevice8_Poll(p)
Definition: dinput.h:2061
#define INPUT_MOUSE
Definition: winable.h:9
LONG HRESULT
Definition: typedefs.h:78
VOID WINAPI keybd_event(_In_ BYTE, _In_ BYTE, _In_ DWORD, _In_ ULONG_PTR)
unsigned long DWORD
Definition: ntddk_ex.h:95
#define MOUSEEVENTF_LEFTUP
Definition: winuser.h:1171
struct _cl_event * event
Definition: glext.h:7739
#define ok(value,...)
Definition: atltest.h:57
#define VK_SPACE
Definition: winuser.h:2194
static void flush_events(void)
Definition: device.c:70
#define DI_OK
Definition: dinput.h:128
#define IDirectInputDevice_Unacquire(p)
Definition: dinput.h:1609
#define win_skip
Definition: test.h:149
BOOL expected
Definition: store.c:2063
#define SUCCEEDED(hr)
Definition: intsafe.h:57
UINT_PTR uAppData
Definition: dinput.h:795

Referenced by test_action_mapping().

◆ test_mouse_keyboard()

static void test_mouse_keyboard ( void  )
static

Definition at line 613 of file device.c.

614 {
615  HRESULT hr;
616  HWND hwnd, di_hwnd = INVALID_HANDLE_VALUE;
617  IDirectInput8A *di = NULL;
618  IDirectInputDevice8A *di_mouse, *di_keyboard;
619  UINT raw_devices_count;
620  RAWINPUTDEVICE raw_devices[3];
621 
622  hwnd = CreateWindowExA(WS_EX_TOPMOST, "static", "dinput", WS_POPUP | WS_VISIBLE, 0, 0, 100, 100, NULL, NULL, NULL, NULL);
623  ok(hwnd != NULL, "CreateWindowExA failed\n");
624 
625  hr = CoCreateInstance(&CLSID_DirectInput8, 0, CLSCTX_INPROC_SERVER, &IID_IDirectInput8A, (LPVOID*)&di);
629  {
630  win_skip("test_mouse_keyboard requires dinput8\n");
631  return;
632  }
633  ok(SUCCEEDED(hr), "DirectInput8Create failed: %08x\n", hr);
634 
637  {
638  win_skip("test_mouse_keyboard requires dinput8\n");
639  return;
640  }
641  ok(SUCCEEDED(hr), "IDirectInput8_Initialize failed: %08x\n", hr);
642 
643  hr = IDirectInput8_CreateDevice(di, &GUID_SysMouse, &di_mouse, NULL);
644  ok(SUCCEEDED(hr), "IDirectInput8_CreateDevice failed: %08x\n", hr);
646  ok(SUCCEEDED(hr), "IDirectInputDevice8_SetDataFormat failed: %08x\n", hr);
647 
648  hr = IDirectInput8_CreateDevice(di, &GUID_SysKeyboard, &di_keyboard, NULL);
649  ok(SUCCEEDED(hr), "IDirectInput8_CreateDevice failed: %08x\n", hr);
651  ok(SUCCEEDED(hr), "IDirectInputDevice8_SetDataFormat failed: %08x\n", hr);
652 
653  raw_devices_count = ARRAY_SIZE(raw_devices);
654  GetRegisteredRawInputDevices(NULL, &raw_devices_count, sizeof(RAWINPUTDEVICE));
655  todo_wine
656  ok(raw_devices_count == 0, "Unexpected raw devices registered: %d\n", raw_devices_count);
657 
658  hr = IDirectInputDevice8_Acquire(di_keyboard);
659  ok(SUCCEEDED(hr), "IDirectInputDevice8_Acquire failed: %08x\n", hr);
660  raw_devices_count = ARRAY_SIZE(raw_devices);
661  memset(raw_devices, 0, sizeof(raw_devices));
662  hr = GetRegisteredRawInputDevices(raw_devices, &raw_devices_count, sizeof(RAWINPUTDEVICE));
663  todo_wine
664  ok(hr == 1, "GetRegisteredRawInputDevices returned %d, raw_devices_count: %d\n", hr, raw_devices_count);
665  todo_wine
666  ok(raw_devices[0].usUsagePage == 1, "Unexpected raw device usage page: %x\n", raw_devices[0].usUsagePage);
667  todo_wine
668  ok(raw_devices[0].usUsage == 6, "Unexpected raw device usage: %x\n", raw_devices[0].usUsage);
669  todo_wine
670  ok(raw_devices[0].dwFlags == RIDEV_INPUTSINK, "Unexpected raw device flags: %x\n", raw_devices[0].dwFlags);
671  todo_wine
672  ok(raw_devices[0].hwndTarget != NULL, "Unexpected raw device target: %p\n", raw_devices[0].hwndTarget);
673  hr = IDirectInputDevice8_Unacquire(di_keyboard);
674  ok(SUCCEEDED(hr), "IDirectInputDevice8_Acquire failed: %08x\n", hr);
675  raw_devices_count = ARRAY_SIZE(raw_devices);
676  GetRegisteredRawInputDevices(NULL, &raw_devices_count, sizeof(RAWINPUTDEVICE));
677  todo_wine
678  ok(raw_devices_count == 0, "Unexpected raw devices registered: %d\n", raw_devices_count);
679 
680  if (raw_devices[0].hwndTarget != NULL)
681  {
682  WCHAR di_hwnd_class[] = {'D','I','E','m','W','i','n',0};
683  WCHAR str[16];
684  int i;
685 
686  di_hwnd = raw_devices[0].hwndTarget;
687  i = GetClassNameW(di_hwnd, str, ARRAY_SIZE(str));
688  ok(i == lstrlenW(di_hwnd_class), "GetClassName returned incorrect length\n");
689  ok(!lstrcmpW(di_hwnd_class, str), "GetClassName returned incorrect name for this window's class\n");
690 
691  i = GetWindowTextW(di_hwnd, str, ARRAY_SIZE(str));
692  ok(i == lstrlenW(di_hwnd_class), "GetClassName returned incorrect length\n");
693  ok(!lstrcmpW(di_hwnd_class, str), "GetClassName returned incorrect name for this window's class\n");
694  }
695 
696  hr = IDirectInputDevice8_Acquire(di_mouse);
697  ok(SUCCEEDED(hr), "IDirectInputDevice8_Acquire failed: %08x\n", hr);
698  raw_devices_count = ARRAY_SIZE(raw_devices);
699  memset(raw_devices, 0, sizeof(raw_devices));
700  hr = GetRegisteredRawInputDevices(raw_devices, &raw_devices_count, sizeof(RAWINPUTDEVICE));
701  todo_wine
702  ok(hr == 1, "GetRegisteredRawInputDevices returned %d, raw_devices_count: %d\n", hr, raw_devices_count);
703  todo_wine
704  ok(raw_devices[0].usUsagePage == 1, "Unexpected raw device usage page: %x\n", raw_devices[0].usUsagePage);
705  todo_wine
706  ok(raw_devices[0].usUsage == 2, "Unexpected raw device usage: %x\n", raw_devices[0].usUsage);
707  todo_wine
708  ok(raw_devices[0].dwFlags == RIDEV_INPUTSINK, "Unexpected raw device flags: %x\n", raw_devices[0].dwFlags);
709  todo_wine
710  ok(raw_devices[0].hwndTarget == di_hwnd, "Unexpected raw device target: %p\n", raw_devices[0].hwndTarget);
711  hr = IDirectInputDevice8_Unacquire(di_mouse);
712  ok(SUCCEEDED(hr), "IDirectInputDevice8_Acquire failed: %08x\n", hr);
713  raw_devices_count = ARRAY_SIZE(raw_devices);
714  GetRegisteredRawInputDevices(NULL, &raw_devices_count, sizeof(RAWINPUTDEVICE));
715  todo_wine
716  ok(raw_devices_count == 0, "Unexpected raw devices registered: %d\n", raw_devices_count);
717 
718  /* expect dinput8 to take over any activated raw input devices */
719  raw_devices[0].usUsagePage = 0x01;
720  raw_devices[0].usUsage = 0x05;
721  raw_devices[0].dwFlags = 0;
722  raw_devices[0].hwndTarget = hwnd;
723  raw_devices[1].usUsagePage = 0x01;
724  raw_devices[1].usUsage = 0x06;
725  raw_devices[1].dwFlags = 0;
726  raw_devices[1].hwndTarget = hwnd;
727  raw_devices[2].usUsagePage = 0x01;
728  raw_devices[2].usUsage = 0x02;
729  raw_devices[2].dwFlags = 0;
730  raw_devices[2].hwndTarget = hwnd;
731  raw_devices_count = ARRAY_SIZE(raw_devices);
732  hr = RegisterRawInputDevices(raw_devices, raw_devices_count, sizeof(RAWINPUTDEVICE));
733  ok(hr == TRUE, "RegisterRawInputDevices failed\n");
734 
735  hr = IDirectInputDevice8_Acquire(di_keyboard);
736  ok(SUCCEEDED(hr), "IDirectInputDevice8_Acquire failed: %08x\n", hr);
737  hr = IDirectInputDevice8_Acquire(di_mouse);
738  ok(SUCCEEDED(hr), "IDirectInputDevice8_Acquire failed: %08x\n", hr);
739  raw_devices_count = ARRAY_SIZE(raw_devices);
740  memset(raw_devices, 0, sizeof(raw_devices));
741  hr = GetRegisteredRawInputDevices(raw_devices, &raw_devices_count, sizeof(RAWINPUTDEVICE));
742  todo_wine
743  ok(hr == 3, "GetRegisteredRawInputDevices returned %d, raw_devices_count: %d\n", hr, raw_devices_count);
744  todo_wine
745  ok(raw_devices[0].usUsagePage == 1, "Unexpected raw device usage page: %x\n", raw_devices[0].usUsagePage);
746  todo_wine
747  ok(raw_devices[0].usUsage == 2, "Unexpected raw device usage: %x\n", raw_devices[0].usUsage);
748  todo_wine
749  ok(raw_devices[0].dwFlags == RIDEV_INPUTSINK, "Unexpected raw device flags: %x\n", raw_devices[0].dwFlags);
750  todo_wine
751  ok(raw_devices[0].hwndTarget == di_hwnd, "Unexpected raw device target: %p\n", raw_devices[0].hwndTarget);
752  todo_wine
753  ok(raw_devices[1].usUsagePage == 1, "Unexpected raw device usage page: %x\n", raw_devices[1].usUsagePage);
754  todo_wine
755  ok(raw_devices[1].usUsage == 5, "Unexpected raw device usage: %x\n", raw_devices[1].usUsage);
756  ok(raw_devices[1].dwFlags == 0, "Unexpected raw device flags: %x\n", raw_devices[1].dwFlags);
757  todo_wine
758  ok(raw_devices[1].hwndTarget == hwnd, "Unexpected raw device target: %p\n", raw_devices[1].hwndTarget);
759  todo_wine
760  ok(raw_devices[2].usUsagePage == 1, "Unexpected raw device usage page: %x\n", raw_devices[1].usUsagePage);
761  todo_wine
762  ok(raw_devices[2].usUsage == 6, "Unexpected raw device usage: %x\n", raw_devices[1].usUsage);
763  todo_wine
764  ok(raw_devices[2].dwFlags == RIDEV_INPUTSINK, "Unexpected raw device flags: %x\n", raw_devices[1].dwFlags);
765  todo_wine
766  ok(raw_devices[2].hwndTarget == di_hwnd, "Unexpected raw device target: %p\n", raw_devices[1].hwndTarget);
767  hr = IDirectInputDevice8_Unacquire(di_keyboard);
768  ok(SUCCEEDED(hr), "IDirectInputDevice8_Acquire failed: %08x\n", hr);
769  hr = IDirectInputDevice8_Unacquire(di_mouse);
770  ok(SUCCEEDED(hr), "IDirectInputDevice8_Acquire failed: %08x\n", hr);
771  raw_devices_count = ARRAY_SIZE(raw_devices);
772  GetRegisteredRawInputDevices(NULL, &raw_devices_count, sizeof(RAWINPUTDEVICE));
773  todo_wine
774  ok(raw_devices_count == 1, "Unexpected raw devices registered: %d\n", raw_devices_count);
775 
776  raw_devices_count = ARRAY_SIZE(raw_devices);
777  hr = GetRegisteredRawInputDevices(raw_devices, &raw_devices_count, sizeof(RAWINPUTDEVICE));
778  todo_wine
779  ok(hr == 1, "GetRegisteredRawInputDevices returned %d, raw_devices_count: %d\n", hr, raw_devices_count);
780  todo_wine
781  ok(raw_devices[0].usUsagePage == 1, "Unexpected raw device usage page: %x\n", raw_devices[0].usUsagePage);
782  todo_wine
783  ok(raw_devices[0].usUsage == 5, "Unexpected raw device usage: %x\n", raw_devices[0].usUsage);
784  ok(raw_devices[0].dwFlags == 0, "Unexpected raw device flags: %x\n", raw_devices[0].dwFlags);
785  todo_wine
786  ok(raw_devices[0].hwndTarget == hwnd, "Unexpected raw device target: %p\n", raw_devices[0].hwndTarget);
787 
788  IDirectInputDevice8_Release(di_mouse);
789  IDirectInputDevice8_Release(di_keyboard);
791 
793 }
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
#define TRUE
Definition: types.h:120
HRESULT hr
Definition: shlfolder.c:183
const DIDATAFORMAT c_dfDIMouse
Definition: data_formats.c:270
int WINAPI lstrcmpW(LPCWSTR lpString1, LPCWSTR lpString2)
Definition: lstring.c:170
#define IDirectInput8_CreateDevice(p, a, b, c)
Definition: dinput.h:2513
#define INVALID_HANDLE_VALUE
Definition: compat.h:399
#define DIRECTINPUT_VERSION
Definition: device.c:20
#define IDirectInputDevice8_Acquire(p)
Definition: dinput.h:2042
#define lstrlenW
Definition: compat.h:415
BOOL WINAPI DestroyWindow(_In_ HWND)
int WINAPI GetClassNameW(_In_ HWND hWnd, _Out_writes_to_(nMaxCount, return) LPWSTR lpClassName, _In_ int nMaxCount)
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
const WCHAR * str
smooth NULL
Definition: ftsmooth.c:416
#define IDirectInput8_Initialize(p, a, b)
Definition: dinput.h:2517
#define IDirectInputDevice8_Release(p)
Definition: dinput.h:2036
#define DIERR_OLDDIRECTINPUTVERSION
Definition: dinput.h:141
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:78
#define todo_wine
Definition: test.h:162
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
#define IDirectInputDevice8_Unacquire(p)
Definition: dinput.h:2043
UINT WINAPI DECLSPEC_HOTPATCH GetRegisteredRawInputDevices(PRAWINPUTDEVICE pRawInputDevices, PUINT puiNumDevices, UINT cbSize)
Definition: stubs.c:349
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
#define WS_EX_TOPMOST
Definition: pedump.c:647
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv)
Definition: compobj.c:3325
#define REGDB_E_CLASSNOTREG
Definition: winerror.h:2696
int WINAPI GetWindowTextW(HWND hWnd, LPWSTR lpString, int nMaxCount)
Definition: window.c:1412
#define ARRAY_SIZE(a)
Definition: main.h:24
#define ok(value,...)
Definition: atltest.h:57
#define WS_POPUP
Definition: pedump.c:616
unsigned int UINT
Definition: ndis.h:50
BOOL WINAPI DECLSPEC_HOTPATCH RegisterRawInputDevices(PCRAWINPUTDEVICE pRawInputDevices, UINT uiNumDevices, UINT cbSize)
Definition: stubs.c:364
const DIDATAFORMAT c_dfDIKeyboard
Definition: data_formats.c:561
#define IDirectInputDevice8_SetDataFormat(p, a)
Definition: dinput.h:2046
HWND WINAPI CreateWindowExA(_In_ DWORD dwExStyle, _In_opt_ LPCSTR lpClassName, _In_opt_ LPCSTR lpWindowName, _In_ DWORD dwStyle, _In_ int X, _In_ int Y, _In_ int nWidth, _In_ int nHeight, _In_opt_ HWND hWndParent, _In_opt_ HMENU hMenu, _In_opt_ HINSTANCE hInstance, _In_opt_ LPVOID lpParam)
#define WS_VISIBLE
Definition: pedump.c:620
#define memset(x, y, z)
Definition: compat.h:39
#define win_skip
Definition: test.h:149
#define DIERR_BETADIRECTINPUTVERSION
Definition: dinput.h:143
#define SUCCEEDED(hr)
Definition: intsafe.h:57
#define IDirectInput8_Release(p)
Definition: dinput.h:2511

Referenced by START_TEST().

◆ test_save_settings()

static void test_save_settings ( void  )
static

Definition at line 426 of file device.c.

427 {
428  HRESULT hr;
430  IDirectInput8A *pDI = NULL;
431  DIACTIONFORMATA af;
432  IDirectInputDevice8A *pKey;
433 
434  static const GUID mapping_guid = { 0xcafecafe, 0x2, 0x3, { 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb } };
435  static const GUID other_guid = { 0xcafe, 0xcafe, 0x3, { 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb } };
436 
437  static DIACTIONA actions[] = {
438  { 0, DIKEYBOARD_A , 0, { "Blam" } },
439  { 1, DIKEYBOARD_B , 0, { "Kapow"} }
440  };
441  static const DWORD results[] = {
444  };
445  static const DWORD other_results[] = {
448  };
449 
450  hr = CoCreateInstance(&CLSID_DirectInput8, 0, CLSCTX_INPROC_SERVER, &IID_IDirectInput8A, (LPVOID*)&pDI);
454  {
455  win_skip("ActionMapping requires dinput8\n");
456  return;
457  }
458  ok (SUCCEEDED(hr), "DirectInput8 Create failed: hr=%08x\n", hr);
459  if (FAILED(hr)) return;
460 
463  {
464  win_skip("ActionMapping requires dinput8\n");
465  return;
466  }
467  ok (SUCCEEDED(hr), "DirectInput8 Initialize failed: hr=%08x\n", hr);
468  if (FAILED(hr)) return;
469 
470  hr = IDirectInput_CreateDevice(pDI, &GUID_SysKeyboard, &pKey, NULL);
471  ok (SUCCEEDED(hr), "IDirectInput_Create device failed hr: 0x%08x\n", hr);
472  if (FAILED(hr)) return;
473 
474  memset (&af, 0, sizeof(af));
475  af.dwSize = sizeof(af);
476  af.dwActionSize = sizeof(DIACTIONA);
477  af.dwDataSize = 4 * ARRAY_SIZE(actions);
478  af.dwNumActions = ARRAY_SIZE(actions);
479  af.rgoAction = actions;
480  af.guidActionMap = mapping_guid;
481  af.dwGenre = 0x01000000; /* DIVIRTUAL_DRIVING_RACE */
482  af.dwBufferSize = 32;
483 
484  /* Easy case. Ask for default mapping, save, ask for previous map and read it back */
486  ok (SUCCEEDED(hr), "BuildActionMap failed hr=%08x\n", hr);
487  ok (results[0] == af.rgoAction[0].dwObjID,
488  "Mapped incorrectly expected: 0x%08x got: 0x%08x\n", results[0], af.rgoAction[0].dwObjID);
489 
490  ok (results[1] == af.rgoAction[1].dwObjID,
491  "Mapped incorrectly expected: 0x%08x got: 0x%08x\n", results[1], af.rgoAction[1].dwObjID);
492 
494  ok (SUCCEEDED(hr), "SetActionMap failed hr=%08x\n", hr);
495 
496  if (hr == DI_SETTINGSNOTSAVED)
497  {
498  skip ("Can't test saving settings if SetActionMap returns DI_SETTINGSNOTSAVED\n");
499  return;
500  }
501 
502  af.rgoAction[0].dwObjID = 0;
503  af.rgoAction[1].dwObjID = 0;
504  memset(&af.rgoAction[0].guidInstance, 0, sizeof(GUID));
505  memset(&af.rgoAction[1].guidInstance, 0, sizeof(GUID));
506 
507  hr = IDirectInputDevice8_BuildActionMap(pKey, &af, NULL, 0);
508  ok (SUCCEEDED(hr), "BuildActionMap failed hr=%08x\n", hr);
509 
510  ok (results[0] == af.rgoAction[0].dwObjID,
511  "Mapped incorrectly expected: 0x%08x got: 0x%08x\n", results[0], af.rgoAction[0].dwObjID);
512  ok (IsEqualGUID(&GUID_SysKeyboard, &af.rgoAction[0].guidInstance), "Action should be mapped to keyboard\n");
513 
514  ok (results[1] == af.rgoAction[1].dwObjID,
515  "Mapped incorrectly expected: 0x%08x got: 0x%08x\n", results[1], af.rgoAction[1].dwObjID);
516  ok (IsEqualGUID(&GUID_SysKeyboard, &af.rgoAction[1].guidInstance), "Action should be mapped to keyboard\n");
517 
518  /* Test that a different action map with no pre-stored settings, in spite of the flags,
519  does not try to load mappings and instead applies the default mapping */
520  af.guidActionMap = other_guid;
521 
522  af.rgoAction[0].dwObjID = 0;
523  af.rgoAction[1].dwObjID = 0;
524  memset(&af.rgoAction[0].guidInstance, 0, sizeof(GUID));
525  memset(&af.rgoAction[1].guidInstance, 0, sizeof(GUID));
526 
527  hr = IDirectInputDevice8_BuildActionMap(pKey, &af, NULL, 0);
528  ok (SUCCEEDED(hr), "BuildActionMap failed hr=%08x\n", hr);
529 
530  ok (results[0] == af.rgoAction[0].dwObjID,
531  "Mapped incorrectly expected: 0x%08x got: 0x%08x\n", results[0], af.rgoAction[0].dwObjID);
532  ok (IsEqualGUID(&GUID_SysKeyboard, &af.rgoAction[0].guidInstance), "Action should be mapped to keyboard\n");
533 
534  ok (results[1] == af.rgoAction[1].dwObjID,
535  "Mapped incorrectly expected: 0x%08x got: 0x%08x\n", results[1], af.rgoAction[1].dwObjID);
536  ok (IsEqualGUID(&GUID_SysKeyboard, &af.rgoAction[1].guidInstance), "Action should be mapped to keyboard\n");
537 
538  af.guidActionMap = mapping_guid;
539  /* Hard case. Customized mapping, save, ask for previous map and read it back */
540  af.rgoAction[0].dwObjID = other_results[0];
542  af.rgoAction[0].guidInstance = GUID_SysKeyboard;
543  af.rgoAction[1].dwObjID = other_results[1];
545  af.rgoAction[1].guidInstance = GUID_SysKeyboard;
546 
548  ok (SUCCEEDED(hr), "SetActionMap failed hr=%08x\n", hr);
549 
550  if (hr == DI_SETTINGSNOTSAVED)
551  {
552  skip ("Can't test saving settings if SetActionMap returns DI_SETTINGSNOTSAVED\n");
553  return;
554  }
555 
556  af.rgoAction[0].dwObjID = 0;
557  af.rgoAction[1].dwObjID = 0;
558  memset(&af.rgoAction[0].guidInstance, 0, sizeof(GUID));
559  memset(&af.rgoAction[1].guidInstance, 0, sizeof(GUID));
560 
561  hr = IDirectInputDevice8_BuildActionMap(pKey, &af, NULL, 0);
562  ok (SUCCEEDED(hr), "BuildActionMap failed hr=%08x\n", hr);
563 
564  ok (other_results[0] == af.rgoAction[0].dwObjID,
565  "Mapped incorrectly expected: 0x%08x got: 0x%08x\n", other_results[0], af.rgoAction[0].dwObjID);
566  ok (IsEqualGUID(&GUID_SysKeyboard, &af.rgoAction[0].guidInstance), "Action should be mapped to keyboard\n");
567 
568  ok (other_results[1] == af.rgoAction[1].dwObjID,
569  "Mapped incorrectly expected: 0x%08x got: 0x%08x\n", other_results[1], af.rgoAction[1].dwObjID);
570  ok (IsEqualGUID(&GUID_SysKeyboard, &af.rgoAction[1].guidInstance), "Action should be mapped to keyboard\n");
571 
572  /* Save and load empty mapping */
573  af.rgoAction[0].dwObjID = 0;
574  af.rgoAction[0].dwHow = 0;
575  memset(&af.rgoAction[0].guidInstance, 0, sizeof(GUID));
576  af.rgoAction[1].dwObjID = 0;
577  af.rgoAction[1].dwHow = 0;
578  memset(&af.rgoAction[1].guidInstance, 0, sizeof(GUID));
579 
581  ok (SUCCEEDED(hr), "SetActionMap failed hr=%08x\n", hr);
582 
583  if (hr == DI_SETTINGSNOTSAVED)
584  {
585  skip ("Can't test saving settings if SetActionMap returns DI_SETTINGSNOTSAVED\n");
586  return;
587  }
588 
589  af.rgoAction[0].dwObjID = other_results[0];
591  af.rgoAction[0].guidInstance = GUID_SysKeyboard;
592  af.rgoAction[1].dwObjID = other_results[1];
594  af.rgoAction[1].guidInstance = GUID_SysKeyboard;
595 
596  hr = IDirectInputDevice8_BuildActionMap(pKey, &af, NULL, 0);
597  ok (SUCCEEDED(hr), "BuildActionMap failed hr=%08x\n", hr);
598 
599  ok (other_results[0] == af.rgoAction[0].dwObjID,
600  "Mapped incorrectly expected: 0x%08x got: 0x%08x\n", other_results[0], af.rgoAction[0].dwObjID);
601  ok (af.rgoAction[0].dwHow == DIAH_UNMAPPED, "dwHow should have been DIAH_UNMAPPED\n");
602  ok (IsEqualGUID(&NULL_GUID, &af.rgoAction[0].guidInstance), "Action should not be mapped\n");
603 
604  ok (other_results[1] == af.rgoAction[1].dwObjID,
605  "Mapped incorrectly expected: 0x%08x got: 0x%08x\n", other_results[1], af.rgoAction[1].dwObjID);
606  ok (af.rgoAction[1].dwHow == DIAH_UNMAPPED, "dwHow should have been DIAH_UNMAPPED\n");
607  ok (IsEqualGUID(&NULL_GUID, &af.rgoAction[1].guidInstance), "Action should not be mapped\n");
608 
611 }
DWORD dwBufferSize
Definition: dinput.h:1315
DWORD dwObjID
Definition: dinput.h:1270
#define DIK_B
Definition: dinput.h:517
#define DIK_A
Definition: dinput.h:499
HRESULT hr
Definition: shlfolder.c:183
#define DIDFT_PSHBUTTON
Definition: dinput.h:754
#define IDirectInput_CreateDevice(p, a, b, c)
Definition: dinput.h:2296
#define DIDFT_MAKEINSTANCE(n)
Definition: dinput.h:762
DWORD dwNumActions
Definition: dinput.h:1311
#define DIRECTINPUT_VERSION
Definition: device.c:20
#define IDirectInputDevice8_BuildActionMap(p, a, b, c)
Definition: dinput.h:2067
DWORD dwDataSize
Definition: dinput.h:1310
GUID guidInstance
Definition: dinput.h:1269
struct _DIACTIONA DIACTIONA
smooth NULL
Definition: ftsmooth.c:416
#define IDirectInputDevice_Release(p)
Definition: dinput.h:1602
#define IDirectInput8_Initialize(p, a, b)
Definition: dinput.h:2517
#define IDirectInputDevice8_SetActionMap(p, a, b, c)
Definition: dinput.h:2068
DWORD dwHow
Definition: dinput.h:1271
#define DIAH_UNMAPPED
Definition: dinput.h:1299
#define IDirectInput_Release(p)
Definition: dinput.h:2294
#define DIK_C
Definition: dinput.h:515
#define DIERR_OLDDIRECTINPUTVERSION
Definition: dinput.h:141
#define DI_SETTINGSNOTSAVED
Definition: dinput.h:137
LONG HRESULT
Definition: typedefs.h:78
unsigned long DWORD
Definition: ntddk_ex.h:95
#define DIKEYBOARD_B
Definition: dinput.h:658
struct _test_info results[8]
Definition: SetCursorPos.c:29
#define DIDBAM_HWDEFAULTS
Definition: dinput.h:1355
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv)
Definition: compobj.c:3325
#define REGDB_E_CLASSNOTREG
Definition: winerror.h:2696
IDirectInputA * pDI
Definition: device.c:173
#define DIAH_USERCONFIG
Definition: dinput.h:1300
#define ARRAY_SIZE(a)
Definition: main.h:24
#define ok(value,...)
Definition: atltest.h:57
DWORD dwActionSize
Definition: dinput.h:1309
static const GUID NULL_GUID
Definition: device.c:41
LPDIACTIONA rgoAction
Definition: dinput.h:1312
BOOL WINAPI IsEqualGUID(REFGUID rguid1, REFGUID rguid2)
Definition: compobj.c:4112
#define skip(...)
Definition: atltest.h:64
#define DIKEYBOARD_A
Definition: dinput.h:640
static HINSTANCE hinst
Definition: edit.c:551
#define memset(x, y, z)
Definition: compat.h:39
#define DIK_D
Definition: dinput.h:501
#define win_skip
Definition: test.h:149
#define DIERR_BETADIRECTINPUTVERSION
Definition: dinput.h:143
#define DIDSAM_FORCESAVE
Definition: dinput.h:1359
#define SUCCEEDED(hr)
Definition: intsafe.h:57
GUID guidActionMap
Definition: dinput.h:1313

Referenced by START_TEST().

Variable Documentation

◆ ACTION_MAPPING_GUID

const GUID ACTION_MAPPING_GUID = { 0x1, 0x2, 0x3, { 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb } }
static

Definition at line 39 of file device.c.

Referenced by test_action_mapping(), and test_EnumDevicesBySemantics().

◆ actionMapping

DIACTIONA actionMapping[]
static
Initial value:
=
{
{ 0, 0x01008A01 , 0, { "Steer.\0" } },
{ 1, 0x01000C01 , 0, { "Upshift.\0" } },
{ 2, DIKEYBOARD_SPACE, 0, { "Missile.\0" } },
{ 3, DIMOUSE_BUTTON0, 0, { "Select\0" } },
{ 4, DIMOUSE_YAXIS, 0, { "Y Axis\0" } }
}
#define DIMOUSE_YAXIS
Definition: dinput.h:2143
#define DIKEYBOARD_SPACE
Definition: dinput.h:667
#define DIMOUSE_BUTTON0
Definition: dinput.h:2145

Definition at line 51 of file device.c.

Referenced by test_action_mapping().

◆ NULL_GUID

const GUID NULL_GUID = { 0, 0, 0, { 0, 0, 0, 0, 0, 0, 0, 0 } }
static

Definition at line 41 of file device.c.

Referenced by test_save_settings().