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 #include "dinput_test.h"
35 static const HRESULT SetCoop_null_window
[16] = {
36 E_INVALIDARG
, E_INVALIDARG
, E_INVALIDARG
, E_INVALIDARG
,
37 E_INVALIDARG
, E_HANDLE
, E_HANDLE
, E_INVALIDARG
,
38 E_INVALIDARG
, E_HANDLE
, S_OK
, E_INVALIDARG
,
39 E_INVALIDARG
, E_INVALIDARG
, E_INVALIDARG
, E_INVALIDARG
};
41 static const HRESULT SetCoop_real_window
[16] = {
42 E_INVALIDARG
, E_INVALIDARG
, E_INVALIDARG
, E_INVALIDARG
,
43 E_INVALIDARG
, S_OK
, S_OK
, E_INVALIDARG
,
44 E_INVALIDARG
, E_NOTIMPL
, S_OK
, E_INVALIDARG
,
45 E_INVALIDARG
, E_INVALIDARG
, E_INVALIDARG
, E_INVALIDARG
};
47 static void test_set_coop(LPDIRECTINPUT pDI
, HWND hwnd
)
50 LPDIRECTINPUTDEVICE pMouse
= NULL
;
53 hr
= IDirectInput_CreateDevice(pDI
, &GUID_SysMouse
, &pMouse
, NULL
);
54 ok(SUCCEEDED(hr
), "IDirectInput_CreateDevice() failed: %s\n", DXGetErrorString8(hr
));
55 if (FAILED(hr
)) return;
59 hr
= IDirectInputDevice_SetCooperativeLevel(pMouse
, NULL
, i
);
60 ok(hr
== SetCoop_null_window
[i
], "SetCooperativeLevel(NULL, %d): %s\n", i
, DXGetErrorString8(hr
));
64 hr
= IDirectInputDevice_SetCooperativeLevel(pMouse
, hwnd
, i
);
65 ok(hr
== SetCoop_real_window
[i
], "SetCooperativeLevel(hwnd, %d): %s\n", i
, DXGetErrorString8(hr
));
68 if (pMouse
) IUnknown_Release(pMouse
);
71 static void test_acquire(LPDIRECTINPUT pDI
, HWND hwnd
)
74 LPDIRECTINPUTDEVICE pMouse
= NULL
;
75 DIMOUSESTATE2 m_state
;
77 hr
= IDirectInput_CreateDevice(pDI
, &GUID_SysMouse
, &pMouse
, NULL
);
78 ok(SUCCEEDED(hr
), "IDirectInput_CreateDevice() failed: %s\n", DXGetErrorString8(hr
));
79 if (FAILED(hr
)) return;
81 hr
= IDirectInputDevice_SetCooperativeLevel(pMouse
, hwnd
, DISCL_NONEXCLUSIVE
| DISCL_FOREGROUND
);
82 ok(hr
== S_OK
, "SetCooperativeLevel: %s\n", DXGetErrorString8(hr
));
84 hr
= IDirectInputDevice_SetDataFormat(pMouse
, &c_dfDIMouse
);
85 ok(SUCCEEDED(hr
), "IDirectInputDevice_SetDataFormat() failed: %s\n", DXGetErrorString8(hr
));
86 hr
= IDirectInputDevice_Unacquire(pMouse
);
87 ok(hr
== S_FALSE
, "IDirectInputDevice_Unacquire() should have failed: %s\n", DXGetErrorString8(hr
));
88 hr
= IDirectInputDevice_Acquire(pMouse
);
89 ok(SUCCEEDED(hr
), "IDirectInputDevice_Acquire() failed: %s\n", DXGetErrorString8(hr
));
90 hr
= IDirectInputDevice_Acquire(pMouse
);
91 ok(hr
== S_FALSE
, "IDirectInputDevice_Acquire() should have failed: %s\n", DXGetErrorString8(hr
));
93 /* Foreground coop level requires window to have focus */
94 /* This should make dinput loose mouse input */
97 hr
= IDirectInputDevice_GetDeviceState(pMouse
, sizeof(m_state
), &m_state
);
99 ok(hr
== DIERR_NOTACQUIRED
, "GetDeviceState() should have failed: %s\n", DXGetErrorString8(hr
));
100 /* Workaround so we can test other things. Remove when Wine is fixed */
101 IDirectInputDevice_Unacquire(pMouse
);
103 hr
= IDirectInputDevice_Acquire(pMouse
);
104 ok(hr
== DIERR_OTHERAPPHASPRIO
, "Acquire() should have failed: %s\n", DXGetErrorString8(hr
));
106 SetActiveWindow( hwnd
);
107 hr
= IDirectInputDevice_Acquire(pMouse
);
108 ok(hr
== S_OK
, "Acquire() failed: %s\n", DXGetErrorString8(hr
));
110 if (pMouse
) IUnknown_Release(pMouse
);
113 static void mouse_tests(void)
116 LPDIRECTINPUT pDI
= NULL
;
117 HINSTANCE hInstance
= GetModuleHandle(NULL
);
121 hr
= DirectInputCreate(hInstance
, DIRECTINPUT_VERSION
, &pDI
, NULL
);
122 ok(SUCCEEDED(hr
), "DirectInputCreate() failed: %s\n", DXGetErrorString8(hr
));
123 if (FAILED(hr
)) return;
125 hwnd
= CreateWindow("static", "Title", WS_OVERLAPPEDWINDOW
,
126 10, 10, 200, 200, NULL
, NULL
, NULL
, NULL
);
127 ok(hwnd
!= NULL
, "err: %d\n", GetLastError());
130 ShowWindow(hwnd
, SW_SHOW
);
132 test_set_coop(pDI
, hwnd
);
133 test_acquire(pDI
, hwnd
);
137 if (pDI
) ref
= IUnknown_Release(pDI
);
138 ok(!ref
, "IDirectInput_Release() reference count = %d\n", ref
);
145 trace("DLL Version: %s\n", get_file_version("dinput.dll"));