2 * Copyright (c) 2005 Robert Reif
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #define DIRECTINPUT_VERSION 0x0700
28 #include "wine/test.h"
33 #include "dinput_test.h"
35 const char * get_file_version(const char * file_name)
37 static char version[32];
38 static char backslash[] = "\\";
42 size = GetFileVersionInfoSizeA(file_name, &handle);
44 char * data = HeapAlloc(GetProcessHeap(), 0, size);
46 if (GetFileVersionInfoA(file_name, handle, size, data)) {
47 VS_FIXEDFILEINFO *pFixedVersionInfo;
49 if (VerQueryValueA(data, backslash, (LPVOID *)&pFixedVersionInfo, &len)) {
50 sprintf(version, "%d.%d.%d.%d",
51 pFixedVersionInfo->dwFileVersionMS >> 16,
52 pFixedVersionInfo->dwFileVersionMS & 0xffff,
53 pFixedVersionInfo->dwFileVersionLS >> 16,
54 pFixedVersionInfo->dwFileVersionLS & 0xffff);
56 sprintf(version, "not available");
58 sprintf(version, "failed");
60 HeapFree(GetProcessHeap(), 0, data);
62 sprintf(version, "failed");
64 sprintf(version, "not available");
69 static void acquire_tests(LPDIRECTINPUT pDI, HWND hwnd)
72 LPDIRECTINPUTDEVICE pKeyboard;
75 hr = IDirectInput_CreateDevice(pDI, &GUID_SysKeyboard, &pKeyboard, NULL);
76 ok(SUCCEEDED(hr), "IDirectInput_CreateDevice() failed: %s\n", DXGetErrorString8(hr));
77 if (FAILED(hr)) return;
79 hr = IDirectInputDevice_SetDataFormat(pKeyboard, &c_dfDIKeyboard);
80 ok(SUCCEEDED(hr), "IDirectInputDevice_SetDataFormat() failed: %s\n", DXGetErrorString8(hr));
81 hr = IDirectInputDevice_SetCooperativeLevel(pKeyboard, NULL, DISCL_NONEXCLUSIVE | DISCL_BACKGROUND);
82 ok(SUCCEEDED(hr), "IDirectInputDevice_SetCooperativeLevel() failed: %s\n", DXGetErrorString8(hr));
83 hr = IDirectInputDevice_GetDeviceState(pKeyboard, 10, kbd_state);
84 ok(hr == DIERR_NOTACQUIRED, "IDirectInputDevice_GetDeviceState(10,) should have failed: %s\n", DXGetErrorString8(hr));
85 hr = IDirectInputDevice_GetDeviceState(pKeyboard, sizeof(kbd_state), kbd_state);
86 ok(hr == DIERR_NOTACQUIRED, "IDirectInputDevice_GetDeviceState() should have failed: %s\n", DXGetErrorString8(hr));
87 hr = IDirectInputDevice_Unacquire(pKeyboard);
88 ok(hr == S_FALSE, "IDirectInputDevice_Unacquire() should have failed: %s\n", DXGetErrorString8(hr));
89 hr = IDirectInputDevice_Acquire(pKeyboard);
90 ok(SUCCEEDED(hr), "IDirectInputDevice_Acquire() failed: %s\n", DXGetErrorString8(hr));
91 hr = IDirectInputDevice_Acquire(pKeyboard);
92 ok(hr == S_FALSE, "IDirectInputDevice_Acquire() should have failed: %s\n", DXGetErrorString8(hr));
93 hr = IDirectInputDevice_GetDeviceState(pKeyboard, 10, kbd_state);
94 ok(hr == DIERR_INVALIDPARAM, "IDirectInputDevice_GetDeviceState(10,) should have failed: %s\n", DXGetErrorString8(hr));
95 hr = IDirectInputDevice_GetDeviceState(pKeyboard, sizeof(kbd_state), kbd_state);
96 ok(SUCCEEDED(hr), "IDirectInputDevice_GetDeviceState() failed: %s\n", DXGetErrorString8(hr));
98 if (pKeyboard) IUnknown_Release(pKeyboard);
101 static const HRESULT SetCoop_null_window[16] = {
102 E_INVALIDARG, E_INVALIDARG, E_INVALIDARG, E_INVALIDARG,
103 E_INVALIDARG, E_HANDLE, E_HANDLE, E_INVALIDARG,
104 E_INVALIDARG, E_HANDLE, S_OK, E_INVALIDARG,
105 E_INVALIDARG, E_INVALIDARG, E_INVALIDARG, E_INVALIDARG};
107 static const HRESULT SetCoop_real_window[16] = {
108 E_INVALIDARG, E_INVALIDARG, E_INVALIDARG, E_INVALIDARG,
109 E_INVALIDARG, S_OK, S_OK, E_INVALIDARG,
110 E_INVALIDARG, E_NOTIMPL, S_OK, E_INVALIDARG,
111 E_INVALIDARG, E_INVALIDARG, E_INVALIDARG, E_INVALIDARG};
113 static void test_set_coop(LPDIRECTINPUT pDI, HWND hwnd)
116 LPDIRECTINPUTDEVICE pKeyboard = NULL;
119 hr = IDirectInput_CreateDevice(pDI, &GUID_SysKeyboard, &pKeyboard, NULL);
120 ok(SUCCEEDED(hr), "IDirectInput_CreateDevice() failed: %s\n", DXGetErrorString8(hr));
121 if (FAILED(hr)) return;
125 hr = IDirectInputDevice_SetCooperativeLevel(pKeyboard, NULL, i);
126 ok(hr == SetCoop_null_window[i], "SetCooperativeLevel(NULL, %d): %s\n", i, DXGetErrorString8(hr));
130 hr = IDirectInputDevice_SetCooperativeLevel(pKeyboard, hwnd, i);
131 ok(hr == SetCoop_real_window[i], "SetCooperativeLevel(hwnd, %d): %s\n", i, DXGetErrorString8(hr));
134 if (pKeyboard) IUnknown_Release(pKeyboard);
137 static void keyboard_tests(DWORD version)
140 LPDIRECTINPUT pDI = NULL;
141 HINSTANCE hInstance = GetModuleHandle(NULL);
145 hr = DirectInputCreate(hInstance, version, &pDI, NULL);
146 ok(SUCCEEDED(hr), "DirectInputCreate() failed: %s\n", DXGetErrorString8(hr));
147 if (FAILED(hr)) return;
149 hwnd = CreateWindow("static", "Title", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
150 10, 10, 200, 200, NULL, NULL, NULL, NULL);
151 ok(hwnd != NULL, "err: %d\n", GetLastError());
155 acquire_tests(pDI, hwnd);
156 test_set_coop(pDI, hwnd);
160 if (pDI) ref = IUnknown_Release(pDI);
161 ok(!ref, "IDirectInput_Release() reference count = %d\n", ref);
168 trace("DLL Version: %s\n", get_file_version("dinput.dll"));
170 keyboard_tests(0x0700);