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
22 #define NONAMELESSSTRUCT
23 #define NONAMELESSUNION
30 #include "wine/test.h"
35 #include "dinput_test.h"
37 const char * get_file_version(const char * file_name)
39 static char version[32];
40 static char backslash[] = "\\";
44 size = GetFileVersionInfoSizeA(file_name, &handle);
46 char * data = HeapAlloc(GetProcessHeap(), 0, size);
48 if (GetFileVersionInfoA(file_name, handle, size, data)) {
49 VS_FIXEDFILEINFO *pFixedVersionInfo;
51 if (VerQueryValueA(data, backslash, (LPVOID *)&pFixedVersionInfo, &len)) {
52 sprintf(version, "%d.%d.%d.%d",
53 pFixedVersionInfo->dwFileVersionMS >> 16,
54 pFixedVersionInfo->dwFileVersionMS & 0xffff,
55 pFixedVersionInfo->dwFileVersionLS >> 16,
56 pFixedVersionInfo->dwFileVersionLS & 0xffff);
58 sprintf(version, "not available");
60 sprintf(version, "failed");
62 HeapFree(GetProcessHeap(), 0, data);
64 sprintf(version, "failed");
66 sprintf(version, "not available");
71 static void acquire_tests(LPDIRECTINPUT pDI, HWND hwnd)
74 LPDIRECTINPUTDEVICE pKeyboard;
77 hr = IDirectInput_CreateDevice(pDI, &GUID_SysKeyboard, &pKeyboard, NULL);
78 ok(SUCCEEDED(hr), "IDirectInput_CreateDevice() failed: %s\n", DXGetErrorString8(hr));
79 if (FAILED(hr)) return;
81 hr = IDirectInputDevice_SetDataFormat(pKeyboard, &c_dfDIKeyboard);
82 ok(SUCCEEDED(hr), "IDirectInputDevice_SetDataFormat() failed: %s\n", DXGetErrorString8(hr));
83 hr = IDirectInputDevice_SetCooperativeLevel(pKeyboard, NULL, DISCL_NONEXCLUSIVE | DISCL_BACKGROUND);
84 ok(SUCCEEDED(hr), "IDirectInputDevice_SetCooperativeLevel() failed: %s\n", DXGetErrorString8(hr));
85 hr = IDirectInputDevice_GetDeviceState(pKeyboard, 10, kbd_state);
86 ok(hr == DIERR_NOTACQUIRED, "IDirectInputDevice_GetDeviceState(10,) should have failed: %s\n", DXGetErrorString8(hr));
87 hr = IDirectInputDevice_GetDeviceState(pKeyboard, sizeof(kbd_state), kbd_state);
88 ok(hr == DIERR_NOTACQUIRED, "IDirectInputDevice_GetDeviceState() 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_GetDeviceState(pKeyboard, 10, kbd_state);
92 ok(hr == DIERR_INVALIDPARAM, "IDirectInputDevice_GetDeviceState(10,) should have failed: %s\n", DXGetErrorString8(hr));
93 hr = IDirectInputDevice_GetDeviceState(pKeyboard, sizeof(kbd_state), kbd_state);
94 ok(SUCCEEDED(hr), "IDirectInputDevice_GetDeviceState() failed: %s\n", DXGetErrorString8(hr));
97 static const HRESULT SetCoop_null_window[16] = {
98 E_INVALIDARG, E_INVALIDARG, E_INVALIDARG, E_INVALIDARG,
99 E_INVALIDARG, E_HANDLE, E_HANDLE, E_INVALIDARG,
100 E_INVALIDARG, E_HANDLE, S_OK, E_INVALIDARG,
101 E_INVALIDARG, E_INVALIDARG, E_INVALIDARG, E_INVALIDARG};
103 static const HRESULT SetCoop_real_window[16] = {
104 E_INVALIDARG, E_INVALIDARG, E_INVALIDARG, E_INVALIDARG,
105 E_INVALIDARG, S_OK, S_OK, E_INVALIDARG,
106 E_INVALIDARG, E_NOTIMPL, S_OK, E_INVALIDARG,
107 E_INVALIDARG, E_INVALIDARG, E_INVALIDARG, E_INVALIDARG};
109 static void test_set_coop(LPDIRECTINPUT pDI, HWND hwnd)
112 LPDIRECTINPUTDEVICE pKeyboard = NULL;
115 hr = IDirectInput_CreateDevice(pDI, &GUID_SysKeyboard, &pKeyboard, NULL);
116 ok(SUCCEEDED(hr), "IDirectInput_CreateDevice() failed: %s\n", DXGetErrorString8(hr));
117 if (FAILED(hr)) return;
121 hr = IDirectInputDevice_SetCooperativeLevel(pKeyboard, NULL, i);
122 ok(hr == SetCoop_null_window[i], "SetCooperativeLevel(NULL, %d): %s\n", i, DXGetErrorString8(hr));
126 hr = IDirectInputDevice_SetCooperativeLevel(pKeyboard, hwnd, i);
127 ok(hr == SetCoop_real_window[i], "SetCooperativeLevel(hwnd, %d): %s\n", i, DXGetErrorString8(hr));
130 if (pKeyboard) IUnknown_Release(pKeyboard);
133 static void keyboard_tests(DWORD version)
136 LPDIRECTINPUT pDI = NULL;
137 HINSTANCE hInstance = GetModuleHandle(NULL);
141 hr = DirectInputCreate(hInstance, version, &pDI, NULL);
142 ok(SUCCEEDED(hr), "DirectInputCreate() failed: %s\n", DXGetErrorString8(hr));
143 if (FAILED(hr)) return;
145 hwnd = CreateWindow("static", "Title", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
146 10, 10, 200, 200, NULL, NULL, NULL, NULL);
147 ok(hwnd != NULL, "err: %d\n", GetLastError());
151 acquire_tests(pDI, hwnd);
152 test_set_coop(pDI, hwnd);
156 if (pDI) ref = IUnknown_Release(pDI);
157 ok(!ref, "IDirectInput_Release() reference count = %d\n", ref);
164 trace("DLL Version: %s\n", get_file_version("dinput.dll"));
166 keyboard_tests(0x0700);