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
;
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
);
98 ok(hr
== DIERR_NOTACQUIRED
, "GetDeviceState() should have failed: %s\n", DXGetErrorString8(hr
));
99 /* Workaround so we can test other things. Remove when Wine is fixed */
100 IDirectInputDevice_Unacquire(pMouse
);
102 hr
= IDirectInputDevice_Acquire(pMouse
);
103 ok(hr
== DIERR_OTHERAPPHASPRIO
, "Acquire() should have failed: %s\n", DXGetErrorString8(hr
));
105 SetActiveWindow( hwnd
);
106 hr
= IDirectInputDevice_Acquire(pMouse
);
107 ok(hr
== S_OK
, "Acquire() failed: %s\n", DXGetErrorString8(hr
));
109 if (pMouse
) IUnknown_Release(pMouse
);
112 static void mouse_tests(void)
115 LPDIRECTINPUT pDI
= NULL
;
116 HINSTANCE hInstance
= GetModuleHandle(NULL
);
120 hr
= DirectInputCreate(hInstance
, DIRECTINPUT_VERSION
, &pDI
, NULL
);
121 if (hr
== DIERR_OLDDIRECTINPUTVERSION
)
123 skip("Tests require a newer dinput version\n");
126 ok(SUCCEEDED(hr
), "DirectInputCreate() failed: %s\n", DXGetErrorString8(hr
));
127 if (FAILED(hr
)) return;
129 hwnd
= CreateWindow("static", "Title", WS_OVERLAPPEDWINDOW
,
130 10, 10, 200, 200, NULL
, NULL
, NULL
, NULL
);
131 ok(hwnd
!= NULL
, "err: %d\n", GetLastError());
134 ShowWindow(hwnd
, SW_SHOW
);
136 test_set_coop(pDI
, hwnd
);
137 test_acquire(pDI
, hwnd
);
141 if (pDI
) ref
= IUnknown_Release(pDI
);
142 ok(!ref
, "IDirectInput_Release() reference count = %d\n", ref
);
149 trace("DLL Version: %s\n", get_file_version("dinput.dll"));