ReactOS 0.4.15-dev-7834-g00c4b3d
mouse.c File Reference
#include <windows.h>
#include <math.h>
#include <stdlib.h>
#include "wine/test.h"
#include "windef.h"
#include "wingdi.h"
#include "dinput.h"
Include dependency graph for mouse.c:

Go to the source code of this file.

Macros

#define DIRECTINPUT_VERSION   0x0700
 
#define COBJMACROS
 

Functions

static void test_set_coop (IDirectInputA *pDI, HWND hwnd)
 
static void test_acquire (IDirectInputA *pDI, HWND hwnd)
 
static void test_GetDeviceInfo (IDirectInputA *pDI)
 
static BOOL CALLBACK EnumAxes (const DIDEVICEOBJECTINSTANCEA *pdidoi, void *pContext)
 
static void test_mouse_EnumObjects (IDirectInputA *pDI)
 
static void mouse_tests (void)
 
 START_TEST (mouse)
 

Variables

static const HRESULT SetCoop_null_window [16]
 
static const HRESULT SetCoop_real_window [16]
 
static const HRESULT SetCoop_child_window [16]
 

Macro Definition Documentation

◆ COBJMACROS

#define COBJMACROS

Definition at line 22 of file mouse.c.

◆ DIRECTINPUT_VERSION

#define DIRECTINPUT_VERSION   0x0700

Definition at line 20 of file mouse.c.

Function Documentation

◆ EnumAxes()

static BOOL CALLBACK EnumAxes ( const DIDEVICEOBJECTINSTANCEA pdidoi,
void pContext 
)
static

Definition at line 239 of file mouse.c.

240{
241 if (IsEqualIID(&pdidoi->guidType, &GUID_XAxis) ||
242 IsEqualIID(&pdidoi->guidType, &GUID_YAxis) ||
243 IsEqualIID(&pdidoi->guidType, &GUID_ZAxis))
244 {
245 ok(pdidoi->dwFlags & DIDOI_ASPECTPOSITION, "Missing DIDOI_ASPECTPOSITION, flags are 0x%x\n",
246 pdidoi->dwFlags);
247 }
248 else
249 ok(pdidoi->dwFlags == 0, "Flags are 0x%x\n", pdidoi->dwFlags);
250
251 return DIENUM_CONTINUE;
252}
#define ok(value,...)
Definition: atltest.h:57
#define DIENUM_CONTINUE
Definition: dinput.h:188
#define DIDOI_ASPECTPOSITION
Definition: dinput.h:820
#define IsEqualIID(riid1, riid2)
Definition: guiddef.h:95

Referenced by test_mouse_EnumObjects().

◆ mouse_tests()

static void mouse_tests ( void  )
static

Definition at line 269 of file mouse.c.

270{
271 HRESULT hr;
272 IDirectInputA *pDI = NULL;
274 HWND hwnd;
275 ULONG ref = 0;
276
279 {
280 skip("Tests require a newer dinput version\n");
281 return;
282 }
283 ok(SUCCEEDED(hr), "DirectInputCreateA() failed: %08x\n", hr);
284 if (FAILED(hr)) return;
285
286 hwnd = CreateWindowA("static", "Title", WS_OVERLAPPEDWINDOW, 10, 10, 200, 200, NULL, NULL,
287 NULL, NULL);
288 ok(hwnd != NULL, "err: %d\n", GetLastError());
289 if (hwnd)
290 {
292
293 test_set_coop(pDI, hwnd);
294 test_acquire(pDI, hwnd);
297
299 }
300 if (pDI) ref = IUnknown_Release(pDI);
301 ok(!ref, "IDirectInput_Release() reference count = %d\n", ref);
302}
#define skip(...)
Definition: atltest.h:64
HINSTANCE hInstance
Definition: charmap.c:19
#define DIERR_OLDDIRECTINPUTVERSION
Definition: dinput.h:141
HRESULT WINAPI DECLSPEC_HOTPATCH DirectInputCreateA(HINSTANCE hinst, DWORD dwVersion, LPDIRECTINPUTA *ppDI, LPUNKNOWN punkOuter)
Definition: dinput_main.c:229
#define NULL
Definition: types.h:112
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:838
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define FAILED(hr)
Definition: intsafe.h:51
static void test_mouse_EnumObjects(IDirectInputA *pDI)
Definition: mouse.c:254
#define DIRECTINPUT_VERSION
Definition: mouse.c:20
static void test_GetDeviceInfo(IDirectInputA *pDI)
Definition: mouse.c:210
static void test_set_coop(IDirectInputA *pDI, HWND hwnd)
Definition: mouse.c:51
static void test_acquire(IDirectInputA *pDI, HWND hwnd)
Definition: mouse.c:87
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
HRESULT hr
Definition: shlfolder.c:183
Definition: send.c:48
uint32_t ULONG
Definition: typedefs.h:59
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
#define CreateWindowA(a, b, c, d, e, f, g, h, i, j, k)
Definition: winuser.h:4315
#define SW_SHOW
Definition: winuser.h:775
BOOL WINAPI DestroyWindow(_In_ HWND)

Referenced by START_TEST().

◆ START_TEST()

START_TEST ( mouse  )

Definition at line 304 of file mouse.c.

305{
307
308 mouse_tests();
309
311}
HRESULT WINAPI CoInitialize(LPVOID lpReserved)
Definition: compobj.c:1964
void WINAPI DECLSPEC_HOTPATCH CoUninitialize(void)
Definition: compobj.c:2067
static void mouse_tests(void)
Definition: mouse.c:269

◆ test_acquire()

static void test_acquire ( IDirectInputA *  pDI,
HWND  hwnd 
)
static

Definition at line 87 of file mouse.c.

88{
89 HRESULT hr;
90 IDirectInputDeviceA *pMouse = NULL;
91 DIMOUSESTATE m_state;
92 HWND hwnd2;
93 DIPROPDWORD di_op;
94 DIDEVICEOBJECTDATA mouse_state;
95 DWORD cnt;
96 int i;
97
99 {
100 skip("Not running as foreground app, skipping acquire tests\n");
101 return;
102 }
103
104 hr = IDirectInput_CreateDevice(pDI, &GUID_SysMouse, &pMouse, NULL);
105 ok(SUCCEEDED(hr), "IDirectInput_CreateDevice() failed: %08x\n", hr);
106 if (FAILED(hr)) return;
107
109 ok(hr == S_OK, "SetCooperativeLevel: %08x\n", hr);
110
111 memset(&di_op, 0, sizeof(di_op));
112 di_op.dwData = 5;
113 di_op.diph.dwHow = DIPH_DEVICE;
114 di_op.diph.dwSize = sizeof(DIPROPDWORD);
115 di_op.diph.dwHeaderSize = sizeof(DIPROPHEADER);
117 ok(hr == S_OK, "SetProperty() failed: %08x\n", hr);
118
120 ok(SUCCEEDED(hr), "IDirectInputDevice_SetDataFormat() failed: %08x\n", hr);
122 ok(hr == S_FALSE, "IDirectInputDevice_Unacquire() should have failed: %08x\n", hr);
124 ok(SUCCEEDED(hr), "IDirectInputDevice_Acquire() failed: %08x\n", hr);
126 ok(hr == S_FALSE, "IDirectInputDevice_Acquire() should have failed: %08x\n", hr);
127
128 /* Foreground coop level requires window to have focus */
129 /* Create a temporary window, this should make dinput
130 * lose mouse input */
131 hwnd2 = CreateWindowA("static", "Temporary", WS_VISIBLE, 10, 210, 200, 200, NULL, NULL, NULL,
132 NULL);
133 ok(hwnd2 != NULL, "CreateWindowA failed with %u\n", GetLastError());
134
135 hr = IDirectInputDevice_GetDeviceState(pMouse, sizeof(m_state), &m_state);
136 ok(hr == DIERR_NOTACQUIRED, "GetDeviceState() should have failed: %08x\n", hr);
137
139 ok(hr == DIERR_OTHERAPPHASPRIO, "Acquire() should have failed: %08x\n", hr);
140
143 ok(hr == S_OK, "Acquire() failed: %08x\n", hr);
144
146 skip("ROSTESTS-176/CORE-9710: Skipping randomly failing tests\n");
147else {
148
149 mouse_event(MOUSEEVENTF_MOVE, 10, 10, 0, 0);
150 cnt = 1;
151 hr = IDirectInputDevice_GetDeviceData(pMouse, sizeof(mouse_state), &mouse_state, &cnt, 0);
152 ok(hr == S_OK && cnt > 0, "GetDeviceData() failed: %08x cnt:%d\n", hr, cnt);
153
154 mouse_event(MOUSEEVENTF_MOVE, 10, 10, 0, 0);
156 ok(hr == S_OK, "Failed: %08x\n", hr);
157 cnt = 1;
158 hr = IDirectInputDevice_GetDeviceData(pMouse, sizeof(mouse_state), &mouse_state, &cnt, 0);
159 ok(hr == S_OK && cnt > 0, "GetDeviceData() failed: %08x cnt:%d\n", hr, cnt);
160
162 ok(hr == S_OK, "Failed: %08x\n", hr);
163 mouse_event(MOUSEEVENTF_MOVE, 10, 10, 0, 0);
165 ok(hr == S_OK, "Failed: %08x\n", hr);
166
168 ok(hr == S_OK, "Failed: %08x\n", hr);
169 cnt = 1;
170 hr = IDirectInputDevice_GetDeviceData(pMouse, sizeof(mouse_state), &mouse_state, &cnt, 0);
171 ok(hr == S_OK && cnt > 0, "GetDeviceData() failed: %08x cnt:%d\n", hr, cnt);
172
173 /* Check for buffer overflow */
174 for (i = 0; i < 6; i++)
175 mouse_event(MOUSEEVENTF_MOVE, 10 + i, 10 + i, 0, 0);
176
177 cnt = 1;
178 hr = IDirectInputDevice_GetDeviceData(pMouse, sizeof(mouse_state), &mouse_state, &cnt, 0);
179 ok(hr == DI_OK, "GetDeviceData() failed: %08x cnt:%d\n", hr, cnt);
180 cnt = 1;
181 hr = IDirectInputDevice_GetDeviceData(pMouse, sizeof(mouse_state), &mouse_state, &cnt, 0);
182 ok(hr == DI_OK && cnt == 1, "GetDeviceData() failed: %08x cnt:%d\n", hr, cnt);
183
184 /* Check for granularity property using BYOFFSET */
185 memset(&di_op, 0, sizeof(di_op));
186 di_op.diph.dwHow = DIPH_BYOFFSET;
187 di_op.diph.dwObj = DIMOFS_Y;
188 di_op.diph.dwSize = sizeof(DIPROPDWORD);
189 di_op.diph.dwHeaderSize = sizeof(DIPROPHEADER);
191 /* Granularity of Y axis should be 1! */
192 ok(hr == S_OK && di_op.dwData == 1, "GetProperty(): %08x, dwData: %i but should be 1.\n", hr, di_op.dwData);
193
194 /* Check for granularity property using BYID */
195 memset(&di_op, 0, sizeof(di_op));
196 di_op.diph.dwHow = DIPH_BYID;
197 /* WINE_MOUSE_Y_AXIS_INSTANCE := 1 */
199 di_op.diph.dwSize = sizeof(DIPROPDWORD);
200 di_op.diph.dwHeaderSize = sizeof(DIPROPHEADER);
202 /* Granularity of Y axis should be 1! */
203 ok(hr == S_OK && di_op.dwData == 1, "GetProperty(): %08x, dwData: %i but should be 1.\n", hr, di_op.dwData);
204}
205 if (pMouse) IUnknown_Release(pMouse);
206
207 DestroyWindow( hwnd2 );
208}
const DIDATAFORMAT c_dfDIMouse
Definition: data_formats.c:270
#define IDirectInputDevice_Acquire(p)
Definition: dinput.h:1608
#define DIPROP_GRANULARITY
Definition: dinput.h:891
#define DISCL_FOREGROUND
Definition: dinput.h:965
#define IDirectInputDevice_SetDataFormat(p, a)
Definition: dinput.h:1612
#define DIPH_BYOFFSET
Definition: dinput.h:836
#define IDirectInputDevice_SetCooperativeLevel(p, a, b)
Definition: dinput.h:1614
#define DIDFT_RELAXIS
Definition: dinput.h:751
#define IDirectInputDevice_GetProperty(p, a, b)
Definition: dinput.h:1606
#define DIERR_NOTACQUIRED
Definition: dinput.h:167
#define DIMOFS_Y
Definition: dinput.h:2127
#define IDirectInput_CreateDevice(p, a, b, c)
Definition: dinput.h:2296
#define DIPH_BYID
Definition: dinput.h:837
#define DI_OK
Definition: dinput.h:128
#define DIERR_OTHERAPPHASPRIO
Definition: dinput.h:162
#define IDirectInputDevice_SetProperty(p, a, b)
Definition: dinput.h:1607
#define DIDFT_MAKEINSTANCE(n)
Definition: dinput.h:762
#define IDirectInputDevice_Unacquire(p)
Definition: dinput.h:1609
#define DISCL_NONEXCLUSIVE
Definition: dinput.h:964
#define DIPH_DEVICE
Definition: dinput.h:835
#define IDirectInputDevice_GetDeviceState(p, a, b)
Definition: dinput.h:1610
#define DIPROP_BUFFERSIZE
Definition: dinput.h:885
#define IDirectInputDevice_GetDeviceData(p, a, b, c, d)
Definition: dinput.h:1611
unsigned long DWORD
Definition: ntddk_ex.h:95
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 S_OK
Definition: intsafe.h:52
POINT pMouse
Definition: magnifier.c:62
#define WS_VISIBLE
Definition: pedump.c:620
int winetest_interactive
#define memset(x, y, z)
Definition: compat.h:39
DIPROPHEADER diph
Definition: dinput.h:843
DWORD dwData
Definition: dinput.h:844
DWORD dwObj
Definition: dinput.h:830
DWORD dwSize
Definition: dinput.h:828
DWORD dwHeaderSize
Definition: dinput.h:829
DWORD dwHow
Definition: dinput.h:831
#define S_FALSE
Definition: winerror.h:2357
void WINAPI mouse_event(_In_ DWORD, _In_ DWORD, _In_ DWORD, _In_ DWORD, _In_ ULONG_PTR)
BOOL WINAPI SetForegroundWindow(_In_ HWND)
#define MOUSEEVENTF_MOVE
Definition: winuser.h:1183
HWND WINAPI SetActiveWindow(_In_ HWND)

Referenced by mouse_tests().

◆ test_GetDeviceInfo()

static void test_GetDeviceInfo ( IDirectInputA *  pDI)
static

Definition at line 210 of file mouse.c.

211{
212 HRESULT hr;
213 IDirectInputDeviceA *pMouse = NULL;
214 DIDEVICEINSTANCEA instA;
216
217 hr = IDirectInput_CreateDevice(pDI, &GUID_SysMouse, &pMouse, NULL);
218 ok(SUCCEEDED(hr), "IDirectInput_CreateDevice() failed: %08x\n", hr);
219 if (FAILED(hr)) return;
220
221 instA.dwSize = sizeof(instA);
223 ok(SUCCEEDED(hr), "got %08x\n", hr);
224
225 inst3A.dwSize = sizeof(inst3A);
227 ok(SUCCEEDED(hr), "got %08x\n", hr);
228
229 ok(instA.dwSize != inst3A.dwSize, "got %d, %d \n", instA.dwSize, inst3A.dwSize);
230 ok(IsEqualGUID(&instA.guidInstance, &inst3A.guidInstance), "got %s, %s\n",
232 ok(IsEqualGUID(&instA.guidProduct, &inst3A.guidProduct), "got %s, %s\n",
234 ok(instA.dwDevType == inst3A.dwDevType, "got %d, %d\n", instA.dwDevType, inst3A.dwDevType);
235
236 IUnknown_Release(pMouse);
237}
#define IDirectInputDevice_GetDeviceInfo(p, a)
Definition: dinput.h:1616
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147
static __inline const char * wine_dbgstr_guid(const GUID *id)
Definition: debug.h:197
GUID guidProduct
Definition: dinput.h:414
GUID guidInstance
Definition: dinput.h:413
DWORD dwDevType
Definition: dinput.h:415

Referenced by mouse_tests().

◆ test_mouse_EnumObjects()

static void test_mouse_EnumObjects ( IDirectInputA *  pDI)
static

Definition at line 254 of file mouse.c.

255{
256 HRESULT hr;
257 IDirectInputDeviceA *pMouse = NULL;
258
259 hr = IDirectInput_CreateDevice(pDI, &GUID_SysMouse, &pMouse, NULL);
260 ok(SUCCEEDED(hr), "IDirectInput_CreateDevice() failed: %08x\n", hr);
261 if (FAILED(hr)) return;
262
264 ok(hr==DI_OK,"IDirectInputDevice_EnumObjects() failed: %08x\n", hr);
265
266 if (pMouse) IUnknown_Release(pMouse);
267}
#define IDirectInputDevice_EnumObjects(p, a, b, c)
Definition: dinput.h:1605
#define DIDFT_ALL
Definition: dinput.h:750
static BOOL CALLBACK EnumAxes(const DIDEVICEOBJECTINSTANCEA *pdidoi, void *pContext)
Definition: mouse.c:239

Referenced by mouse_tests().

◆ test_set_coop()

static void test_set_coop ( IDirectInputA *  pDI,
HWND  hwnd 
)
static

Definition at line 51 of file mouse.c.

52{
53 HRESULT hr;
54 IDirectInputDeviceA *pMouse = NULL;
55 int i;
56 HWND child;
57
58 hr = IDirectInput_CreateDevice(pDI, &GUID_SysMouse, &pMouse, NULL);
59 ok(SUCCEEDED(hr), "IDirectInput_CreateDevice() failed: %08x\n", hr);
60 if (FAILED(hr)) return;
61
62 for (i=0; i<16; i++)
63 {
65 ok(hr == SetCoop_null_window[i], "SetCooperativeLevel(NULL, %d): %08x\n", i, hr);
66 }
67 for (i=0; i<16; i++)
68 {
70 ok(hr == SetCoop_real_window[i], "SetCooperativeLevel(hwnd, %d): %08x\n", i, hr);
71 }
72
73 child = CreateWindowA("static", "Title", WS_CHILD | WS_VISIBLE, 10, 10, 50, 50, hwnd, NULL,
74 NULL, NULL);
75 ok(child != NULL, "err: %d\n", GetLastError());
76
77 for (i=0; i<16; i++)
78 {
80 ok(hr == SetCoop_child_window[i], "SetCooperativeLevel(child, %d): %08x\n", i, hr);
81 }
82
84 if (pMouse) IUnknown_Release(pMouse);
85}
static const HRESULT SetCoop_child_window[16]
Definition: mouse.c:45
static const HRESULT SetCoop_null_window[16]
Definition: mouse.c:33
static const HRESULT SetCoop_real_window[16]
Definition: mouse.c:39
static HWND child
Definition: cursoricon.c:298
#define WS_CHILD
Definition: pedump.c:617

Referenced by mouse_tests().

Variable Documentation

◆ SetCoop_child_window

const HRESULT SetCoop_child_window[16]
static

◆ SetCoop_null_window

◆ SetCoop_real_window

const HRESULT SetCoop_real_window[16]
static