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
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2005-05-11 14:05:17 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define DIRECTINPUT_VERSION 0x0700
|
|
|
|
|
2006-10-15 19:30:22 +02:00
|
|
|
#define COBJMACROS
|
2005-05-11 14:05:17 +02:00
|
|
|
#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];
|
2006-07-31 20:51:00 +02:00
|
|
|
static char backslash[] = "\\";
|
2005-05-11 14:05:17 +02:00
|
|
|
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;
|
2006-07-31 20:51:00 +02:00
|
|
|
if (VerQueryValueA(data, backslash, (LPVOID *)&pFixedVersionInfo, &len)) {
|
2006-10-12 02:22:27 +02:00
|
|
|
sprintf(version, "%d.%d.%d.%d",
|
2005-05-11 14:05:17 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2006-10-15 19:30:22 +02:00
|
|
|
static void acquire_tests(LPDIRECTINPUT pDI, HWND hwnd)
|
2005-05-11 14:05:17 +02:00
|
|
|
{
|
2006-04-02 04:55:00 +02:00
|
|
|
HRESULT hr;
|
|
|
|
LPDIRECTINPUTDEVICE pKeyboard;
|
|
|
|
BYTE kbd_state[256];
|
2008-04-17 23:29:24 +02:00
|
|
|
BYTE custom_state[4];
|
|
|
|
DIOBJECTDATAFORMAT dodf[] =
|
|
|
|
{
|
|
|
|
{ &GUID_Key, 0, DIDFT_MAKEINSTANCE(DIK_Q)|DIDFT_BUTTON, 0 },
|
|
|
|
{ &GUID_Key, 1, DIDFT_MAKEINSTANCE(DIK_W)|DIDFT_BUTTON, 0 },
|
|
|
|
{ &GUID_Key, 2, DIDFT_MAKEINSTANCE(DIK_E)|DIDFT_BUTTON, 0 },
|
|
|
|
{ &GUID_Key, 3, DIDFT_MAKEINSTANCE(DIK_R)|DIDFT_BUTTON, 0 },
|
|
|
|
};
|
|
|
|
|
|
|
|
DIDATAFORMAT df;
|
|
|
|
df.dwSize = sizeof( df );
|
|
|
|
df.dwObjSize = sizeof( DIOBJECTDATAFORMAT );
|
|
|
|
df.dwFlags = DIDF_RELAXIS;
|
|
|
|
df.dwDataSize = sizeof( dodf )/sizeof( dodf[0] );
|
|
|
|
df.dwNumObjs = sizeof( dodf )/sizeof( dodf[0] );
|
|
|
|
df.rgodf = dodf;
|
2006-04-02 04:55:00 +02:00
|
|
|
|
|
|
|
hr = IDirectInput_CreateDevice(pDI, &GUID_SysKeyboard, &pKeyboard, NULL);
|
|
|
|
ok(SUCCEEDED(hr), "IDirectInput_CreateDevice() failed: %s\n", DXGetErrorString8(hr));
|
2006-10-15 19:30:22 +02:00
|
|
|
if (FAILED(hr)) return;
|
2006-04-02 04:55:00 +02:00
|
|
|
|
|
|
|
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));
|
2006-12-01 18:54:42 +01:00
|
|
|
hr = IDirectInputDevice_Unacquire(pKeyboard);
|
|
|
|
ok(hr == S_FALSE, "IDirectInputDevice_Unacquire() should have failed: %s\n", DXGetErrorString8(hr));
|
2006-04-02 04:55:00 +02:00
|
|
|
hr = IDirectInputDevice_Acquire(pKeyboard);
|
|
|
|
ok(SUCCEEDED(hr), "IDirectInputDevice_Acquire() failed: %s\n", DXGetErrorString8(hr));
|
2006-12-01 18:54:42 +01:00
|
|
|
hr = IDirectInputDevice_Acquire(pKeyboard);
|
|
|
|
ok(hr == S_FALSE, "IDirectInputDevice_Acquire() should have failed: %s\n", DXGetErrorString8(hr));
|
2006-04-02 04:55:00 +02:00
|
|
|
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));
|
2008-04-17 23:29:24 +02:00
|
|
|
hr = IDirectInputDevice_Unacquire(pKeyboard);
|
|
|
|
ok(SUCCEEDED(hr), "IDirectInputDevice_Uncquire() failed: %s\n", DXGetErrorString8(hr));
|
|
|
|
hr = IDirectInputDevice_SetDataFormat( pKeyboard , &df );
|
|
|
|
ok(SUCCEEDED(hr), "IDirectInputDevice_SetDataFormat() failed: %s\n", DXGetErrorString8(hr));
|
|
|
|
hr = IDirectInputDevice_Acquire(pKeyboard);
|
|
|
|
ok(SUCCEEDED(hr), "IDirectInputDevice_Acquire() failed: %s\n", DXGetErrorString8(hr));
|
2008-04-24 22:32:32 +02:00
|
|
|
hr = IDirectInputDevice_GetDeviceState(pKeyboard, sizeof(custom_state), custom_state);
|
|
|
|
ok(SUCCEEDED(hr), "IDirectInputDevice_GetDeviceState(4,) failed: %s\n", DXGetErrorString8(hr));
|
|
|
|
hr = IDirectInputDevice_GetDeviceState(pKeyboard, sizeof(kbd_state), kbd_state);
|
|
|
|
ok(hr == DIERR_INVALIDPARAM, "IDirectInputDevice_GetDeviceState(256,) should have failed: %s\n", DXGetErrorString8(hr));
|
2006-12-22 18:54:29 +01:00
|
|
|
|
|
|
|
if (pKeyboard) IUnknown_Release(pKeyboard);
|
2006-10-15 19:30:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static const HRESULT SetCoop_null_window[16] = {
|
|
|
|
E_INVALIDARG, E_INVALIDARG, E_INVALIDARG, E_INVALIDARG,
|
|
|
|
E_INVALIDARG, E_HANDLE, E_HANDLE, E_INVALIDARG,
|
|
|
|
E_INVALIDARG, E_HANDLE, S_OK, E_INVALIDARG,
|
|
|
|
E_INVALIDARG, E_INVALIDARG, E_INVALIDARG, E_INVALIDARG};
|
|
|
|
|
|
|
|
static const HRESULT SetCoop_real_window[16] = {
|
|
|
|
E_INVALIDARG, E_INVALIDARG, E_INVALIDARG, E_INVALIDARG,
|
|
|
|
E_INVALIDARG, S_OK, S_OK, E_INVALIDARG,
|
|
|
|
E_INVALIDARG, E_NOTIMPL, S_OK, E_INVALIDARG,
|
|
|
|
E_INVALIDARG, E_INVALIDARG, E_INVALIDARG, E_INVALIDARG};
|
|
|
|
|
|
|
|
static void test_set_coop(LPDIRECTINPUT pDI, HWND hwnd)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
LPDIRECTINPUTDEVICE pKeyboard = NULL;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
hr = IDirectInput_CreateDevice(pDI, &GUID_SysKeyboard, &pKeyboard, NULL);
|
|
|
|
ok(SUCCEEDED(hr), "IDirectInput_CreateDevice() failed: %s\n", DXGetErrorString8(hr));
|
|
|
|
if (FAILED(hr)) return;
|
|
|
|
|
|
|
|
for (i=0; i<16; i++)
|
|
|
|
{
|
|
|
|
hr = IDirectInputDevice_SetCooperativeLevel(pKeyboard, NULL, i);
|
|
|
|
ok(hr == SetCoop_null_window[i], "SetCooperativeLevel(NULL, %d): %s\n", i, DXGetErrorString8(hr));
|
|
|
|
}
|
|
|
|
for (i=0; i<16; i++)
|
|
|
|
{
|
|
|
|
hr = IDirectInputDevice_SetCooperativeLevel(pKeyboard, hwnd, i);
|
|
|
|
ok(hr == SetCoop_real_window[i], "SetCooperativeLevel(hwnd, %d): %s\n", i, DXGetErrorString8(hr));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pKeyboard) IUnknown_Release(pKeyboard);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void keyboard_tests(DWORD version)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
LPDIRECTINPUT pDI = NULL;
|
|
|
|
HINSTANCE hInstance = GetModuleHandle(NULL);
|
|
|
|
HWND hwnd;
|
|
|
|
ULONG ref = 0;
|
|
|
|
|
|
|
|
hr = DirectInputCreate(hInstance, version, &pDI, NULL);
|
2008-03-07 20:26:57 +01:00
|
|
|
if (hr == DIERR_OLDDIRECTINPUTVERSION)
|
|
|
|
{
|
|
|
|
skip("Tests require a newer dinput version\n");
|
|
|
|
return;
|
|
|
|
}
|
2006-10-15 19:30:22 +02:00
|
|
|
ok(SUCCEEDED(hr), "DirectInputCreate() failed: %s\n", DXGetErrorString8(hr));
|
|
|
|
if (FAILED(hr)) return;
|
|
|
|
|
|
|
|
hwnd = CreateWindow("static", "Title", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
|
|
|
|
10, 10, 200, 200, NULL, NULL, NULL, NULL);
|
|
|
|
ok(hwnd != NULL, "err: %d\n", GetLastError());
|
|
|
|
|
|
|
|
if (hwnd)
|
|
|
|
{
|
|
|
|
acquire_tests(pDI, hwnd);
|
|
|
|
test_set_coop(pDI, hwnd);
|
|
|
|
}
|
|
|
|
|
|
|
|
DestroyWindow(hwnd);
|
|
|
|
if (pDI) ref = IUnknown_Release(pDI);
|
2006-10-12 02:22:27 +02:00
|
|
|
ok(!ref, "IDirectInput_Release() reference count = %d\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"));
|
|
|
|
|
2006-04-02 04:55:00 +02:00
|
|
|
keyboard_tests(0x0700);
|
2005-05-11 14:05:17 +02:00
|
|
|
|
|
|
|
CoUninitialize();
|
|
|
|
}
|