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
21 #define NONAMELESSSTRUCT
22 #define NONAMELESSUNION
29 #include "wine/test.h"
34 #include "dinput_test.h"
36 const char * get_file_version(const char * file_name)
38 static char version[32];
39 static char backslash[] = "\\";
43 size = GetFileVersionInfoSizeA(file_name, &handle);
45 char * data = HeapAlloc(GetProcessHeap(), 0, size);
47 if (GetFileVersionInfoA(file_name, handle, size, data)) {
48 VS_FIXEDFILEINFO *pFixedVersionInfo;
50 if (VerQueryValueA(data, backslash, (LPVOID *)&pFixedVersionInfo, &len)) {
51 sprintf(version, "%ld.%ld.%ld.%ld",
52 pFixedVersionInfo->dwFileVersionMS >> 16,
53 pFixedVersionInfo->dwFileVersionMS & 0xffff,
54 pFixedVersionInfo->dwFileVersionLS >> 16,
55 pFixedVersionInfo->dwFileVersionLS & 0xffff);
57 sprintf(version, "not available");
59 sprintf(version, "failed");
61 HeapFree(GetProcessHeap(), 0, data);
63 sprintf(version, "failed");
65 sprintf(version, "not available");
70 static void keyboard_tests(DWORD version)
74 LPDIRECTINPUTDEVICE pKeyboard;
75 HINSTANCE hInstance = GetModuleHandle(NULL);
79 hr = DirectInputCreate(hInstance, version, &pDI, NULL);
80 ok(SUCCEEDED(hr), "DirectInputCreate() failed: %s\n", DXGetErrorString8(hr));
81 if (FAILED(hr)) return;
84 hr = IDirectInput_CreateDevice(pDI, &GUID_SysKeyboard, &pKeyboard, NULL);
85 ok(SUCCEEDED(hr), "IDirectInput_CreateDevice() failed: %s\n", DXGetErrorString8(hr));
88 IDirectInput_Release(pDI);
92 hr = IDirectInputDevice_SetDataFormat(pKeyboard, &c_dfDIKeyboard);
93 ok(SUCCEEDED(hr), "IDirectInputDevice_SetDataFormat() failed: %s\n", DXGetErrorString8(hr));
94 hr = IDirectInputDevice_SetCooperativeLevel(pKeyboard, NULL, DISCL_NONEXCLUSIVE | DISCL_BACKGROUND);
95 ok(SUCCEEDED(hr), "IDirectInputDevice_SetCooperativeLevel() failed: %s\n", DXGetErrorString8(hr));
96 hr = IDirectInputDevice_GetDeviceState(pKeyboard, 10, kbd_state);
97 ok(hr == DIERR_NOTACQUIRED, "IDirectInputDevice_GetDeviceState(10,) should have failed: %s\n", DXGetErrorString8(hr));
98 hr = IDirectInputDevice_GetDeviceState(pKeyboard, sizeof(kbd_state), kbd_state);
99 ok(hr == DIERR_NOTACQUIRED, "IDirectInputDevice_GetDeviceState() should have failed: %s\n", DXGetErrorString8(hr));
100 hr = IDirectInputDevice_Acquire(pKeyboard);
101 ok(SUCCEEDED(hr), "IDirectInputDevice_Acquire() failed: %s\n", DXGetErrorString8(hr));
102 hr = IDirectInputDevice_GetDeviceState(pKeyboard, 10, kbd_state);
103 ok(hr == DIERR_INVALIDPARAM, "IDirectInputDevice_GetDeviceState(10,) should have failed: %s\n", DXGetErrorString8(hr));
104 hr = IDirectInputDevice_GetDeviceState(pKeyboard, sizeof(kbd_state), kbd_state);
105 ok(SUCCEEDED(hr), "IDirectInputDevice_GetDeviceState() failed: %s\n", DXGetErrorString8(hr));
107 ref = IDirectInput_Release(pDI);
108 ok(!ref, "IDirectInput_Release() reference count = %ld\n", ref);
115 trace("DLL Version: %s\n", get_file_version("dinput.dll"));
117 keyboard_tests(0x0700);