2 * Copyright (c) 2005 Robert Reif
3 * Copyright (c) 2006 Vitaliy Margolen
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #define DIRECTINPUT_VERSION 0x0700
28 #include "wine/test.h"
33 static const HRESULT SetCoop_null_window
[16] = {
34 E_INVALIDARG
, E_INVALIDARG
, E_INVALIDARG
, E_INVALIDARG
,
35 E_INVALIDARG
, E_HANDLE
, E_HANDLE
, E_INVALIDARG
,
36 E_INVALIDARG
, E_HANDLE
, S_OK
, E_INVALIDARG
,
37 E_INVALIDARG
, E_INVALIDARG
, E_INVALIDARG
, E_INVALIDARG
};
39 static const HRESULT SetCoop_real_window
[16] = {
40 E_INVALIDARG
, E_INVALIDARG
, E_INVALIDARG
, E_INVALIDARG
,
41 E_INVALIDARG
, S_OK
, S_OK
, E_INVALIDARG
,
42 E_INVALIDARG
, E_NOTIMPL
, S_OK
, E_INVALIDARG
,
43 E_INVALIDARG
, E_INVALIDARG
, E_INVALIDARG
, E_INVALIDARG
};
45 static void test_set_coop(LPDIRECTINPUT pDI
, HWND hwnd
)
48 LPDIRECTINPUTDEVICE pMouse
= NULL
;
51 hr
= IDirectInput_CreateDevice(pDI
, &GUID_SysMouse
, &pMouse
, NULL
);
52 ok(SUCCEEDED(hr
), "IDirectInput_CreateDevice() failed: %08x\n", hr
);
53 if (FAILED(hr
)) return;
57 hr
= IDirectInputDevice_SetCooperativeLevel(pMouse
, NULL
, i
);
58 ok(hr
== SetCoop_null_window
[i
], "SetCooperativeLevel(NULL, %d): %08x\n", i
, hr
);
62 hr
= IDirectInputDevice_SetCooperativeLevel(pMouse
, hwnd
, i
);
63 ok(hr
== SetCoop_real_window
[i
], "SetCooperativeLevel(hwnd, %d): %08x\n", i
, hr
);
66 if (pMouse
) IUnknown_Release(pMouse
);
69 static void test_acquire(LPDIRECTINPUT pDI
, HWND hwnd
)
72 LPDIRECTINPUTDEVICE pMouse
= NULL
;
75 hr
= IDirectInput_CreateDevice(pDI
, &GUID_SysMouse
, &pMouse
, NULL
);
76 ok(SUCCEEDED(hr
), "IDirectInput_CreateDevice() failed: %08x\n", hr
);
77 if (FAILED(hr
)) return;
79 hr
= IDirectInputDevice_SetCooperativeLevel(pMouse
, hwnd
, DISCL_NONEXCLUSIVE
| DISCL_FOREGROUND
);
80 ok(hr
== S_OK
, "SetCooperativeLevel: %08x\n", hr
);
82 hr
= IDirectInputDevice_SetDataFormat(pMouse
, &c_dfDIMouse
);
83 ok(SUCCEEDED(hr
), "IDirectInputDevice_SetDataFormat() failed: %08x\n", hr
);
84 hr
= IDirectInputDevice_Unacquire(pMouse
);
85 ok(hr
== S_FALSE
, "IDirectInputDevice_Unacquire() should have failed: %08x\n", hr
);
86 hr
= IDirectInputDevice_Acquire(pMouse
);
87 ok(SUCCEEDED(hr
), "IDirectInputDevice_Acquire() failed: %08x\n", hr
);
88 hr
= IDirectInputDevice_Acquire(pMouse
);
89 ok(hr
== S_FALSE
, "IDirectInputDevice_Acquire() should have failed: %08x\n", hr
);
91 /* Foreground coop level requires window to have focus */
92 /* This should make dinput loose mouse input */
95 hr
= IDirectInputDevice_GetDeviceState(pMouse
, sizeof(m_state
), &m_state
);
96 ok(hr
== DIERR_NOTACQUIRED
, "GetDeviceState() should have failed: %08x\n", hr
);
97 /* Workaround so we can test other things. Remove when Wine is fixed */
98 IDirectInputDevice_Unacquire(pMouse
);
100 hr
= IDirectInputDevice_Acquire(pMouse
);
101 ok(hr
== DIERR_OTHERAPPHASPRIO
, "Acquire() should have failed: %08x\n", hr
);
103 SetActiveWindow( hwnd
);
104 hr
= IDirectInputDevice_Acquire(pMouse
);
105 ok(hr
== S_OK
, "Acquire() failed: %08x\n", hr
);
107 if (pMouse
) IUnknown_Release(pMouse
);
110 static void mouse_tests(void)
113 LPDIRECTINPUT pDI
= NULL
;
114 HINSTANCE hInstance
= GetModuleHandle(NULL
);
118 hr
= DirectInputCreate(hInstance
, DIRECTINPUT_VERSION
, &pDI
, NULL
);
119 if (hr
== DIERR_OLDDIRECTINPUTVERSION
)
121 skip("Tests require a newer dinput version\n");
124 ok(SUCCEEDED(hr
), "DirectInputCreate() failed: %08x\n", hr
);
125 if (FAILED(hr
)) return;
127 hwnd
= CreateWindow("static", "Title", WS_OVERLAPPEDWINDOW
,
128 10, 10, 200, 200, NULL
, NULL
, NULL
, NULL
);
129 ok(hwnd
!= NULL
, "err: %d\n", GetLastError());
132 ShowWindow(hwnd
, SW_SHOW
);
134 test_set_coop(pDI
, hwnd
);
135 test_acquire(pDI
, hwnd
);
139 if (pDI
) ref
= IUnknown_Release(pDI
);
140 ok(!ref
, "IDirectInput_Release() reference count = %d\n", ref
);