2005-05-11 14:05:17 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2005 Robert Reif
|
2006-09-16 20:25:29 +02:00
|
|
|
* Copyright (c) 2006 Vitaliy Margolen
|
2005-05-11 14:05:17 +02:00
|
|
|
*
|
|
|
|
* 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
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2005-05-11 14:05:17 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define DIRECTINPUT_VERSION 0x0700
|
|
|
|
|
2006-09-16 20:25:29 +02:00
|
|
|
#define COBJMACROS
|
2005-05-11 14:05:17 +02:00
|
|
|
#include <windows.h>
|
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "wine/test.h"
|
|
|
|
#include "windef.h"
|
|
|
|
#include "wingdi.h"
|
|
|
|
#include "dinput.h"
|
|
|
|
|
2006-09-16 20:25:29 +02:00
|
|
|
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};
|
|
|
|
|
2011-11-02 06:45:39 +01:00
|
|
|
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};
|
|
|
|
|
2013-10-29 23:13:02 +01:00
|
|
|
static void test_set_coop(IDirectInputA *pDI, HWND hwnd)
|
2006-09-16 20:25:29 +02:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
2013-10-29 23:13:02 +01:00
|
|
|
IDirectInputDeviceA *pMouse = NULL;
|
2006-09-16 20:25:29 +02:00
|
|
|
int i;
|
2011-11-02 06:45:39 +01:00
|
|
|
HWND child;
|
2006-09-16 20:25:29 +02:00
|
|
|
|
|
|
|
hr = IDirectInput_CreateDevice(pDI, &GUID_SysMouse, &pMouse, NULL);
|
2008-07-08 17:49:03 +02:00
|
|
|
ok(SUCCEEDED(hr), "IDirectInput_CreateDevice() failed: %08x\n", hr);
|
2006-09-16 20:25:29 +02:00
|
|
|
if (FAILED(hr)) return;
|
|
|
|
|
|
|
|
for (i=0; i<16; i++)
|
|
|
|
{
|
|
|
|
hr = IDirectInputDevice_SetCooperativeLevel(pMouse, NULL, i);
|
2008-07-08 17:49:03 +02:00
|
|
|
ok(hr == SetCoop_null_window[i], "SetCooperativeLevel(NULL, %d): %08x\n", i, hr);
|
2006-09-16 20:25:29 +02:00
|
|
|
}
|
|
|
|
for (i=0; i<16; i++)
|
|
|
|
{
|
|
|
|
hr = IDirectInputDevice_SetCooperativeLevel(pMouse, hwnd, i);
|
2008-07-08 17:49:03 +02:00
|
|
|
ok(hr == SetCoop_real_window[i], "SetCooperativeLevel(hwnd, %d): %08x\n", i, hr);
|
2006-09-16 20:25:29 +02:00
|
|
|
}
|
|
|
|
|
2013-10-29 23:13:02 +01:00
|
|
|
child = CreateWindowA("static", "Title", WS_CHILD | WS_VISIBLE, 10, 10, 50, 50, hwnd, NULL,
|
|
|
|
NULL, NULL);
|
2011-11-02 06:45:39 +01:00
|
|
|
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);
|
2006-09-16 20:25:29 +02:00
|
|
|
if (pMouse) IUnknown_Release(pMouse);
|
|
|
|
}
|
|
|
|
|
2013-10-29 23:13:02 +01:00
|
|
|
static void test_acquire(IDirectInputA *pDI, HWND hwnd)
|
2006-12-01 18:54:42 +01:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
2013-10-29 23:13:02 +01:00
|
|
|
IDirectInputDeviceA *pMouse = NULL;
|
2007-07-06 15:25:47 +02:00
|
|
|
DIMOUSESTATE m_state;
|
2009-10-15 09:20:00 +02:00
|
|
|
HWND hwnd2;
|
2011-10-14 05:22:31 +02:00
|
|
|
DIPROPDWORD di_op;
|
|
|
|
DIDEVICEOBJECTDATA mouse_state;
|
|
|
|
DWORD cnt;
|
2011-10-16 20:36:46 +02:00
|
|
|
int i;
|
2006-12-01 18:54:42 +01:00
|
|
|
|
2011-01-06 13:10:27 +01:00
|
|
|
if (! SetForegroundWindow(hwnd))
|
|
|
|
{
|
|
|
|
skip("Not running as foreground app, skipping acquire tests\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-12-01 18:54:42 +01:00
|
|
|
hr = IDirectInput_CreateDevice(pDI, &GUID_SysMouse, &pMouse, NULL);
|
2008-07-08 17:49:03 +02:00
|
|
|
ok(SUCCEEDED(hr), "IDirectInput_CreateDevice() failed: %08x\n", hr);
|
2006-12-01 18:54:42 +01:00
|
|
|
if (FAILED(hr)) return;
|
|
|
|
|
2007-06-03 17:09:35 +02:00
|
|
|
hr = IDirectInputDevice_SetCooperativeLevel(pMouse, hwnd, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND);
|
2008-07-08 17:49:03 +02:00
|
|
|
ok(hr == S_OK, "SetCooperativeLevel: %08x\n", hr);
|
2007-06-03 17:09:35 +02:00
|
|
|
|
2011-10-14 05:22:31 +02:00
|
|
|
memset(&di_op, 0, sizeof(di_op));
|
2011-10-16 20:36:46 +02:00
|
|
|
di_op.dwData = 5;
|
2011-10-14 05:22:31 +02:00
|
|
|
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);
|
|
|
|
|
2006-12-01 18:54:42 +01:00
|
|
|
hr = IDirectInputDevice_SetDataFormat(pMouse, &c_dfDIMouse);
|
2008-07-08 17:49:03 +02:00
|
|
|
ok(SUCCEEDED(hr), "IDirectInputDevice_SetDataFormat() failed: %08x\n", hr);
|
2006-12-01 18:54:42 +01:00
|
|
|
hr = IDirectInputDevice_Unacquire(pMouse);
|
2008-07-08 17:49:03 +02:00
|
|
|
ok(hr == S_FALSE, "IDirectInputDevice_Unacquire() should have failed: %08x\n", hr);
|
2006-12-01 18:54:42 +01:00
|
|
|
hr = IDirectInputDevice_Acquire(pMouse);
|
2008-07-08 17:49:03 +02:00
|
|
|
ok(SUCCEEDED(hr), "IDirectInputDevice_Acquire() failed: %08x\n", hr);
|
2006-12-01 18:54:42 +01:00
|
|
|
hr = IDirectInputDevice_Acquire(pMouse);
|
2008-07-08 17:49:03 +02:00
|
|
|
ok(hr == S_FALSE, "IDirectInputDevice_Acquire() should have failed: %08x\n", hr);
|
2007-06-03 17:09:35 +02:00
|
|
|
|
|
|
|
/* Foreground coop level requires window to have focus */
|
2009-10-15 09:20:00 +02:00
|
|
|
/* Create a temporary window, this should make dinput
|
2015-11-17 05:21:40 +01:00
|
|
|
* lose mouse input */
|
2013-10-29 23:13:02 +01:00
|
|
|
hwnd2 = CreateWindowA("static", "Temporary", WS_VISIBLE, 10, 210, 200, 200, NULL, NULL, NULL,
|
|
|
|
NULL);
|
2015-11-05 15:57:29 +01:00
|
|
|
ok(hwnd2 != NULL, "CreateWindowA failed with %u\n", GetLastError());
|
2007-06-03 17:09:35 +02:00
|
|
|
|
|
|
|
hr = IDirectInputDevice_GetDeviceState(pMouse, sizeof(m_state), &m_state);
|
2008-07-08 17:49:03 +02:00
|
|
|
ok(hr == DIERR_NOTACQUIRED, "GetDeviceState() should have failed: %08x\n", hr);
|
2007-06-03 17:09:35 +02:00
|
|
|
|
|
|
|
hr = IDirectInputDevice_Acquire(pMouse);
|
2008-07-08 17:49:03 +02:00
|
|
|
ok(hr == DIERR_OTHERAPPHASPRIO, "Acquire() should have failed: %08x\n", hr);
|
2007-06-03 17:09:35 +02:00
|
|
|
|
|
|
|
SetActiveWindow( hwnd );
|
|
|
|
hr = IDirectInputDevice_Acquire(pMouse);
|
2008-07-08 17:49:03 +02:00
|
|
|
ok(hr == S_OK, "Acquire() failed: %08x\n", hr);
|
2006-12-01 18:54:42 +01:00
|
|
|
|
2011-10-14 05:22:31 +02:00
|
|
|
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);
|
|
|
|
|
2018-03-06 20:03:41 +01:00
|
|
|
/* Check for buffer overflow */
|
2011-10-16 20:36:46 +02:00
|
|
|
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);
|
|
|
|
|
2018-03-06 20:03:41 +01:00
|
|
|
/* Check for granularity property using BYOFFSET */
|
|
|
|
memset(&di_op, 0, sizeof(di_op));
|
|
|
|
di_op.diph.dwHow = DIPH_BYOFFSET;
|
|
|
|
di_op.diph.dwObj = DIMOFS_Y;
|
|
|
|
di_op.diph.dwSize = sizeof(DIPROPDWORD);
|
|
|
|
di_op.diph.dwHeaderSize = sizeof(DIPROPHEADER);
|
|
|
|
hr = IDirectInputDevice_GetProperty(pMouse, DIPROP_GRANULARITY, &di_op.diph);
|
|
|
|
/* Granularity of Y axis should be 1! */
|
|
|
|
ok(hr == S_OK && di_op.dwData == 1, "GetProperty(): %08x, dwData: %i but should be 1.\n", hr, di_op.dwData);
|
|
|
|
|
|
|
|
/* Check for granularity property using BYID */
|
|
|
|
memset(&di_op, 0, sizeof(di_op));
|
|
|
|
di_op.diph.dwHow = DIPH_BYID;
|
|
|
|
/* WINE_MOUSE_Y_AXIS_INSTANCE := 1 */
|
|
|
|
di_op.diph.dwObj = (DIDFT_MAKEINSTANCE(1) | DIDFT_RELAXIS);
|
|
|
|
di_op.diph.dwSize = sizeof(DIPROPDWORD);
|
|
|
|
di_op.diph.dwHeaderSize = sizeof(DIPROPHEADER);
|
|
|
|
hr = IDirectInputDevice_GetProperty(pMouse, DIPROP_GRANULARITY, &di_op.diph);
|
|
|
|
/* Granularity of Y axis should be 1! */
|
|
|
|
ok(hr == S_OK && di_op.dwData == 1, "GetProperty(): %08x, dwData: %i but should be 1.\n", hr, di_op.dwData);
|
|
|
|
|
2006-12-01 18:54:42 +01:00
|
|
|
if (pMouse) IUnknown_Release(pMouse);
|
2009-10-15 09:20:00 +02:00
|
|
|
|
|
|
|
DestroyWindow( hwnd2 );
|
2006-12-01 18:54:42 +01:00
|
|
|
}
|
|
|
|
|
2019-05-04 07:30:52 +02:00
|
|
|
static void test_GetDeviceInfo(IDirectInputA *pDI)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
IDirectInputDeviceA *pMouse = NULL;
|
|
|
|
DIDEVICEINSTANCEA instA;
|
|
|
|
DIDEVICEINSTANCE_DX3A inst3A;
|
|
|
|
|
|
|
|
hr = IDirectInput_CreateDevice(pDI, &GUID_SysMouse, &pMouse, NULL);
|
|
|
|
ok(SUCCEEDED(hr), "IDirectInput_CreateDevice() failed: %08x\n", hr);
|
|
|
|
if (FAILED(hr)) return;
|
|
|
|
|
|
|
|
instA.dwSize = sizeof(instA);
|
|
|
|
hr = IDirectInputDevice_GetDeviceInfo(pMouse, &instA);
|
|
|
|
ok(SUCCEEDED(hr), "got %08x\n", hr);
|
|
|
|
|
|
|
|
inst3A.dwSize = sizeof(inst3A);
|
|
|
|
hr = IDirectInputDevice_GetDeviceInfo(pMouse, (DIDEVICEINSTANCEA *)&inst3A);
|
|
|
|
ok(SUCCEEDED(hr), "got %08x\n", hr);
|
|
|
|
|
|
|
|
ok(instA.dwSize != inst3A.dwSize, "got %d, %d \n", instA.dwSize, inst3A.dwSize);
|
|
|
|
ok(IsEqualGUID(&instA.guidInstance, &inst3A.guidInstance), "got %s, %s\n",
|
|
|
|
wine_dbgstr_guid(&instA.guidInstance), wine_dbgstr_guid(&inst3A.guidInstance) );
|
|
|
|
ok(IsEqualGUID(&instA.guidProduct, &inst3A.guidProduct), "got %s, %s\n",
|
|
|
|
wine_dbgstr_guid(&instA.guidProduct), wine_dbgstr_guid(&inst3A.guidProduct) );
|
|
|
|
ok(instA.dwDevType == inst3A.dwDevType, "got %d, %d\n", instA.dwDevType, inst3A.dwDevType);
|
|
|
|
|
2019-05-27 00:49:21 +02:00
|
|
|
IUnknown_Release(pMouse);
|
2019-05-04 07:30:52 +02:00
|
|
|
}
|
|
|
|
|
2019-05-17 04:25:31 +02:00
|
|
|
static BOOL CALLBACK EnumAxes(const DIDEVICEOBJECTINSTANCEA *pdidoi, void *pContext)
|
|
|
|
{
|
|
|
|
if (IsEqualIID(&pdidoi->guidType, &GUID_XAxis) ||
|
|
|
|
IsEqualIID(&pdidoi->guidType, &GUID_YAxis) ||
|
|
|
|
IsEqualIID(&pdidoi->guidType, &GUID_ZAxis))
|
|
|
|
{
|
|
|
|
ok(pdidoi->dwFlags & DIDOI_ASPECTPOSITION, "Missing DIDOI_ASPECTPOSITION, flags are 0x%x\n",
|
|
|
|
pdidoi->dwFlags);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ok(pdidoi->dwFlags == 0, "Flags are 0x%x\n", pdidoi->dwFlags);
|
|
|
|
|
|
|
|
return DIENUM_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_mouse_EnumObjects(IDirectInputA *pDI)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
IDirectInputDeviceA *pMouse = NULL;
|
|
|
|
|
|
|
|
hr = IDirectInput_CreateDevice(pDI, &GUID_SysMouse, &pMouse, NULL);
|
|
|
|
ok(SUCCEEDED(hr), "IDirectInput_CreateDevice() failed: %08x\n", hr);
|
|
|
|
if (FAILED(hr)) return;
|
|
|
|
|
|
|
|
hr = IDirectInputDevice_EnumObjects(pMouse, EnumAxes, NULL, DIDFT_ALL);
|
|
|
|
ok(hr==DI_OK,"IDirectInputDevice_EnumObjects() failed: %08x\n", hr);
|
|
|
|
|
|
|
|
if (pMouse) IUnknown_Release(pMouse);
|
|
|
|
}
|
|
|
|
|
2005-06-21 22:53:13 +02:00
|
|
|
static void mouse_tests(void)
|
2005-05-11 14:05:17 +02:00
|
|
|
{
|
2006-09-16 20:25:29 +02:00
|
|
|
HRESULT hr;
|
2013-10-29 23:13:02 +01:00
|
|
|
IDirectInputA *pDI = NULL;
|
|
|
|
HINSTANCE hInstance = GetModuleHandleW(NULL);
|
2006-09-16 20:25:29 +02:00
|
|
|
HWND hwnd;
|
2006-12-22 18:54:29 +01:00
|
|
|
ULONG ref = 0;
|
2006-09-16 20:25:29 +02:00
|
|
|
|
2013-10-29 23:13:02 +01:00
|
|
|
hr = DirectInputCreateA(hInstance, DIRECTINPUT_VERSION, &pDI, NULL);
|
2008-03-07 20:26:57 +01:00
|
|
|
if (hr == DIERR_OLDDIRECTINPUTVERSION)
|
|
|
|
{
|
|
|
|
skip("Tests require a newer dinput version\n");
|
|
|
|
return;
|
|
|
|
}
|
2013-10-29 23:13:02 +01:00
|
|
|
ok(SUCCEEDED(hr), "DirectInputCreateA() failed: %08x\n", hr);
|
2006-09-16 20:25:29 +02:00
|
|
|
if (FAILED(hr)) return;
|
|
|
|
|
2013-10-29 23:13:02 +01:00
|
|
|
hwnd = CreateWindowA("static", "Title", WS_OVERLAPPEDWINDOW, 10, 10, 200, 200, NULL, NULL,
|
|
|
|
NULL, NULL);
|
2006-10-12 02:22:27 +02:00
|
|
|
ok(hwnd != NULL, "err: %d\n", GetLastError());
|
2006-12-01 18:54:42 +01:00
|
|
|
if (hwnd)
|
|
|
|
{
|
|
|
|
ShowWindow(hwnd, SW_SHOW);
|
2006-09-16 20:25:29 +02:00
|
|
|
|
2006-12-01 18:54:42 +01:00
|
|
|
test_set_coop(pDI, hwnd);
|
|
|
|
test_acquire(pDI, hwnd);
|
2019-05-04 07:30:52 +02:00
|
|
|
test_GetDeviceInfo(pDI);
|
2019-05-17 04:25:31 +02:00
|
|
|
test_mouse_EnumObjects(pDI);
|
2006-09-16 20:25:29 +02:00
|
|
|
|
2006-12-01 18:54:42 +01:00
|
|
|
DestroyWindow(hwnd);
|
|
|
|
}
|
2006-12-22 18:54:29 +01:00
|
|
|
if (pDI) ref = IUnknown_Release(pDI);
|
|
|
|
ok(!ref, "IDirectInput_Release() reference count = %d\n", ref);
|
2005-05-11 14:05:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
START_TEST(mouse)
|
|
|
|
{
|
|
|
|
CoInitialize(NULL);
|
|
|
|
|
|
|
|
mouse_tests();
|
|
|
|
|
|
|
|
CoUninitialize();
|
|
|
|
}
|