Sweden-Number/dlls/dinput/tests/keyboard.c

120 lines
4.4 KiB
C
Raw Normal View History

2005-05-11 14:05:17 +02:00
/*
* Copyright (c) 2005 Robert Reif
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
2005-05-11 14:05:17 +02:00
*/
#define DIRECTINPUT_VERSION 0x0700
#define NONAMELESSSTRUCT
#define NONAMELESSUNION
#include <windows.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include "wine/test.h"
#include "windef.h"
#include "wingdi.h"
#include "dinput.h"
#include "dxerr8.h"
#include "dinput_test.h"
const char * get_file_version(const char * file_name)
{
static char version[32];
DWORD size;
DWORD handle;
size = GetFileVersionInfoSizeA(file_name, &handle);
if (size) {
char * data = HeapAlloc(GetProcessHeap(), 0, size);
if (data) {
if (GetFileVersionInfoA(file_name, handle, size, data)) {
VS_FIXEDFILEINFO *pFixedVersionInfo;
UINT len;
if (VerQueryValueA(data, "\\", (LPVOID *)&pFixedVersionInfo, &len)) {
sprintf(version, "%ld.%ld.%ld.%ld",
pFixedVersionInfo->dwFileVersionMS >> 16,
pFixedVersionInfo->dwFileVersionMS & 0xffff,
pFixedVersionInfo->dwFileVersionLS >> 16,
pFixedVersionInfo->dwFileVersionLS & 0xffff);
} else
sprintf(version, "not available");
} else
sprintf(version, "failed");
HeapFree(GetProcessHeap(), 0, data);
} else
sprintf(version, "failed");
} else
sprintf(version, "not available");
return version;
}
static void keyboard_tests(DWORD version)
2005-05-11 14:05:17 +02:00
{
HRESULT hr;
LPDIRECTINPUT pDI;
LPDIRECTINPUTDEVICE pKeyboard;
HINSTANCE hInstance = GetModuleHandle(NULL);
BYTE kbd_state[256];
ULONG ref;
hr = DirectInputCreate(hInstance, version, &pDI, NULL);
ok(SUCCEEDED(hr), "DirectInputCreate() failed: %s\n", DXGetErrorString8(hr));
if (FAILED(hr)) return;
hr = IDirectInput_CreateDevice(pDI, &GUID_SysKeyboard, &pKeyboard, NULL);
ok(SUCCEEDED(hr), "IDirectInput_CreateDevice() failed: %s\n", DXGetErrorString8(hr));
if (FAILED(hr))
{
IDirectInput_Release(pDI);
return;
}
hr = IDirectInputDevice_SetDataFormat(pKeyboard, &c_dfDIKeyboard);
ok(SUCCEEDED(hr), "IDirectInputDevice_SetDataFormat() failed: %s\n", DXGetErrorString8(hr));
hr = IDirectInputDevice_SetCooperativeLevel(pKeyboard, NULL, DISCL_NONEXCLUSIVE | DISCL_BACKGROUND);
ok(SUCCEEDED(hr), "IDirectInputDevice_SetCooperativeLevel() failed: %s\n", DXGetErrorString8(hr));
hr = IDirectInputDevice_GetDeviceState(pKeyboard, 10, kbd_state);
ok(hr == DIERR_NOTACQUIRED, "IDirectInputDevice_GetDeviceState(10,) should have failed: %s\n", DXGetErrorString8(hr));
hr = IDirectInputDevice_GetDeviceState(pKeyboard, sizeof(kbd_state), kbd_state);
ok(hr == DIERR_NOTACQUIRED, "IDirectInputDevice_GetDeviceState() should have failed: %s\n", DXGetErrorString8(hr));
hr = IDirectInputDevice_Acquire(pKeyboard);
ok(SUCCEEDED(hr), "IDirectInputDevice_Acquire() failed: %s\n", DXGetErrorString8(hr));
hr = IDirectInputDevice_GetDeviceState(pKeyboard, 10, kbd_state);
ok(hr == DIERR_INVALIDPARAM, "IDirectInputDevice_GetDeviceState(10,) should have failed: %s\n", DXGetErrorString8(hr));
hr = IDirectInputDevice_GetDeviceState(pKeyboard, sizeof(kbd_state), kbd_state);
ok(SUCCEEDED(hr), "IDirectInputDevice_GetDeviceState() failed: %s\n", DXGetErrorString8(hr));
ref = IDirectInput_Release(pDI);
ok(!ref, "IDirectInput_Release() reference count = %ld\n", ref);
2005-05-11 14:05:17 +02:00
}
START_TEST(keyboard)
{
CoInitialize(NULL);
trace("DLL Version: %s\n", get_file_version("dinput.dll"));
keyboard_tests(0x0700);
2005-05-11 14:05:17 +02:00
CoUninitialize();
}