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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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];
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, "\\", (LPVOID *)&pFixedVersionInfo, &len)) {
50 sprintf(version, "%ld.%ld.%ld.%ld",
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 keyboard_tests(DWORD version)
73 LPDIRECTINPUTDEVICE pKeyboard;
74 HINSTANCE hInstance = GetModuleHandle(NULL);
78 hr = DirectInputCreate(hInstance, version, &pDI, NULL);
79 ok(SUCCEEDED(hr), "DirectInputCreate() failed: %s\n", DXGetErrorString8(hr));
80 if (FAILED(hr)) return;
83 hr = IDirectInput_CreateDevice(pDI, &GUID_SysKeyboard, &pKeyboard, NULL);
84 ok(SUCCEEDED(hr), "IDirectInput_CreateDevice() failed: %s\n", DXGetErrorString8(hr));
87 IDirectInput_Release(pDI);
91 hr = IDirectInputDevice_SetDataFormat(pKeyboard, &c_dfDIKeyboard);
92 ok(SUCCEEDED(hr), "IDirectInputDevice_SetDataFormat() failed: %s\n", DXGetErrorString8(hr));
93 hr = IDirectInputDevice_SetCooperativeLevel(pKeyboard, NULL, DISCL_NONEXCLUSIVE | DISCL_BACKGROUND);
94 ok(SUCCEEDED(hr), "IDirectInputDevice_SetCooperativeLevel() failed: %s\n", DXGetErrorString8(hr));
95 hr = IDirectInputDevice_GetDeviceState(pKeyboard, 10, kbd_state);
96 ok(hr == DIERR_NOTACQUIRED, "IDirectInputDevice_GetDeviceState(10,) should have failed: %s\n", DXGetErrorString8(hr));
97 hr = IDirectInputDevice_GetDeviceState(pKeyboard, sizeof(kbd_state), kbd_state);
98 ok(hr == DIERR_NOTACQUIRED, "IDirectInputDevice_GetDeviceState() should have failed: %s\n", DXGetErrorString8(hr));
99 hr = IDirectInputDevice_Acquire(pKeyboard);
100 ok(SUCCEEDED(hr), "IDirectInputDevice_Acquire() failed: %s\n", DXGetErrorString8(hr));
101 hr = IDirectInputDevice_GetDeviceState(pKeyboard, 10, kbd_state);
102 ok(hr == DIERR_INVALIDPARAM, "IDirectInputDevice_GetDeviceState(10,) should have failed: %s\n", DXGetErrorString8(hr));
103 hr = IDirectInputDevice_GetDeviceState(pKeyboard, sizeof(kbd_state), kbd_state);
104 ok(SUCCEEDED(hr), "IDirectInputDevice_GetDeviceState() failed: %s\n", DXGetErrorString8(hr));
106 ref = IDirectInput_Release(pDI);
107 ok(!ref, "IDirectInput_Release() reference count = %ld\n", ref);
114 trace("DLL Version: %s\n", get_file_version("dinput.dll"));
116 keyboard_tests(0x0700);