2011-04-30 00:29:19 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2011 Lucas Fialho Zawacki
|
|
|
|
* Copyright (c) 2006 Vitaliy Margolen
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define DIRECTINPUT_VERSION 0x0800
|
|
|
|
|
|
|
|
#define COBJMACROS
|
|
|
|
#include <windows.h>
|
|
|
|
|
|
|
|
#include "wine/test.h"
|
|
|
|
#include "windef.h"
|
|
|
|
#include "dinput.h"
|
|
|
|
|
2011-06-28 18:54:20 +02:00
|
|
|
struct enum_data {
|
|
|
|
LPDIRECTINPUT8 pDI;
|
|
|
|
LPDIACTIONFORMAT lpdiaf;
|
|
|
|
LPDIRECTINPUTDEVICE8 keyboard;
|
|
|
|
LPDIRECTINPUTDEVICE8 mouse;
|
|
|
|
int ndevices;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Dummy GUID */
|
|
|
|
static const GUID ACTION_MAPPING_GUID = { 0x1, 0x2, 0x3, { 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb } };
|
|
|
|
|
2011-06-28 18:54:49 +02:00
|
|
|
enum {
|
|
|
|
DITEST_AXIS,
|
|
|
|
DITEST_BUTTON,
|
|
|
|
DITEST_KEYBOARDSPACE,
|
|
|
|
DITEST_MOUSEBUTTON0,
|
2011-07-02 06:06:01 +02:00
|
|
|
DITEST_YAXIS
|
2011-06-28 18:54:49 +02:00
|
|
|
};
|
|
|
|
|
2011-06-28 18:54:20 +02:00
|
|
|
static DIACTION actionMapping[]=
|
|
|
|
{
|
|
|
|
/* axis */
|
|
|
|
{ 0, 0x01008A01 /* DIAXIS_DRIVINGR_STEER */ , 0, { "Steer" } },
|
|
|
|
/* button */
|
|
|
|
{ 1, 0x01000C01 /* DIBUTTON_DRIVINGR_SHIFTUP */ , 0, { "Upshift" } },
|
|
|
|
/* keyboard key */
|
|
|
|
{ 2, DIKEYBOARD_SPACE , 0, { "Missile" } },
|
|
|
|
/* mouse button */
|
2011-07-02 06:06:01 +02:00
|
|
|
{ 3, DIMOUSE_BUTTON0, 0, { "Select" } },
|
|
|
|
/* mouse axis */
|
|
|
|
{ 4, DIMOUSE_YAXIS, 0, { "Y Axis" } }
|
2011-06-28 18:54:20 +02:00
|
|
|
};
|
|
|
|
|
2011-07-02 06:06:01 +02:00
|
|
|
static void test_device_input(
|
2011-06-28 18:54:49 +02:00
|
|
|
LPDIRECTINPUTDEVICE8 lpdid,
|
2011-07-02 06:06:01 +02:00
|
|
|
DWORD event_type,
|
|
|
|
DWORD event,
|
2011-06-28 18:54:49 +02:00
|
|
|
DWORD expected
|
|
|
|
)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
DIDEVICEOBJECTDATA obj_data;
|
|
|
|
DWORD data_size = 1;
|
|
|
|
|
|
|
|
hr = IDirectInputDevice8_Acquire(lpdid);
|
2011-07-02 06:06:54 +02:00
|
|
|
ok (SUCCEEDED(hr), "Failed to acquire device hr=%08x\n", hr);
|
2011-06-28 18:54:49 +02:00
|
|
|
|
2011-07-02 06:06:01 +02:00
|
|
|
if (event_type == INPUT_KEYBOARD)
|
|
|
|
keybd_event( event, 0, 0, 0);
|
|
|
|
|
|
|
|
if (event_type == INPUT_MOUSE)
|
|
|
|
mouse_event( event, 0, 0, 0, 0);
|
2011-06-28 18:54:49 +02:00
|
|
|
|
|
|
|
IDirectInputDevice8_Poll(lpdid);
|
|
|
|
hr = IDirectInputDevice8_GetDeviceData(lpdid, sizeof(obj_data), &obj_data, &data_size, 0);
|
|
|
|
|
|
|
|
if (data_size != 1)
|
|
|
|
{
|
|
|
|
win_skip("We're not able to inject input into Windows dinput8 with events\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-07-02 06:07:15 +02:00
|
|
|
ok (obj_data.uAppData == expected, "Retrieval of action failed uAppData=%lu expected=%d\n", obj_data.uAppData, expected);
|
2011-06-28 18:54:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_build_action_map(
|
|
|
|
LPDIRECTINPUTDEVICE8 lpdid,
|
|
|
|
LPDIACTIONFORMAT lpdiaf,
|
|
|
|
int action_index,
|
2011-07-02 06:06:01 +02:00
|
|
|
DWORD expected_type,
|
|
|
|
DWORD expected_inst
|
2011-06-28 18:54:49 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
DIACTION *actions;
|
2011-07-02 06:06:01 +02:00
|
|
|
DWORD instance, type, how;
|
2011-06-28 18:54:49 +02:00
|
|
|
GUID assigned_to;
|
|
|
|
DIDEVICEINSTANCEA ddi;
|
|
|
|
|
|
|
|
ddi.dwSize = sizeof(ddi);
|
|
|
|
IDirectInputDevice_GetDeviceInfo(lpdid, &ddi);
|
|
|
|
|
|
|
|
hr = IDirectInputDevice8_BuildActionMap(lpdid, lpdiaf, NULL, DIDBAM_INITIALIZE);
|
|
|
|
ok (SUCCEEDED(hr), "BuildActionMap failed hr=%08x\n", hr);
|
|
|
|
|
|
|
|
actions = lpdiaf->rgoAction;
|
2011-07-02 06:06:01 +02:00
|
|
|
instance = DIDFT_GETINSTANCE(actions[action_index].dwObjID);
|
|
|
|
type = DIDFT_GETTYPE(actions[action_index].dwObjID);
|
2011-06-28 18:54:49 +02:00
|
|
|
how = actions[action_index].dwHow;
|
|
|
|
assigned_to = actions[action_index].guidInstance;
|
|
|
|
|
2011-07-02 06:06:37 +02:00
|
|
|
ok (how == DIAH_USERCONFIG || how == DIAH_DEFAULT, "Action was not set dwHow=%08x\n", how);
|
|
|
|
ok (instance == expected_inst, "Action not mapped correctly instance=%08x expected=%08x\n", instance, expected_inst);
|
|
|
|
ok (type == expected_type, "Action type not mapped correctly type=%08x expected=%08x\n", type, expected_type);
|
|
|
|
ok (IsEqualGUID(&assigned_to, &ddi.guidInstance), "Action and device GUID do not match action=%d\n", action_index);
|
2011-06-28 18:54:49 +02:00
|
|
|
}
|
|
|
|
|
2011-06-28 18:54:20 +02:00
|
|
|
static BOOL CALLBACK enumeration_callback(
|
2011-04-30 00:29:19 +02:00
|
|
|
LPCDIDEVICEINSTANCE lpddi,
|
|
|
|
LPDIRECTINPUTDEVICE8 lpdid,
|
|
|
|
DWORD dwFlags,
|
|
|
|
DWORD dwRemaining,
|
|
|
|
LPVOID pvRef)
|
|
|
|
{
|
2011-06-28 18:54:49 +02:00
|
|
|
HRESULT hr;
|
|
|
|
DIPROPDWORD dp;
|
2011-06-28 18:54:20 +02:00
|
|
|
struct enum_data *data = pvRef;
|
|
|
|
if (!data) return DIENUM_CONTINUE;
|
|
|
|
|
|
|
|
data->ndevices++;
|
|
|
|
|
|
|
|
/* collect the mouse and keyboard */
|
|
|
|
if (IsEqualGUID(&lpddi->guidInstance, &GUID_SysKeyboard))
|
|
|
|
{
|
|
|
|
IDirectInputDevice_AddRef(lpdid);
|
|
|
|
data->keyboard = lpdid;
|
|
|
|
|
2011-06-28 18:54:36 +02:00
|
|
|
ok (dwFlags & DIEDBS_MAPPEDPRI1, "Keyboard should be mapped as pri1 dwFlags=%08x\n", dwFlags);
|
2011-06-28 18:54:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (IsEqualGUID(&lpddi->guidInstance, &GUID_SysMouse))
|
|
|
|
{
|
|
|
|
IDirectInputDevice_AddRef(lpdid);
|
|
|
|
data->mouse = lpdid;
|
|
|
|
|
2011-06-28 18:54:36 +02:00
|
|
|
ok (dwFlags & DIEDBS_MAPPEDPRI1, "Mouse should be mapped as pri1 dwFlags=%08x\n", dwFlags);
|
2011-06-28 18:54:20 +02:00
|
|
|
}
|
|
|
|
|
2011-06-28 18:54:49 +02:00
|
|
|
/* Building and setting an action map */
|
|
|
|
/* It should not use any pre-stored mappings so we use DIDBAM_INITIALIZE */
|
|
|
|
hr = IDirectInputDevice8_BuildActionMap(lpdid, data->lpdiaf, NULL, DIDBAM_INITIALIZE);
|
|
|
|
ok (SUCCEEDED(hr), "BuildActionMap failed hr=%08x\n", hr);
|
|
|
|
|
|
|
|
/* Device has no data format and thus can't be acquired */
|
|
|
|
hr = IDirectInputDevice8_Acquire(lpdid);
|
|
|
|
ok (hr == DIERR_INVALIDPARAM, "Device was acquired before SetActionMap hr=%08x\n", hr);
|
|
|
|
|
|
|
|
hr = IDirectInputDevice8_SetActionMap(lpdid, data->lpdiaf, NULL, 0);
|
|
|
|
ok (SUCCEEDED(hr), "SetActionMap failed hr=%08x\n", hr);
|
|
|
|
|
|
|
|
/* Test buffer size */
|
|
|
|
memset(&dp, 0, sizeof(dp));
|
|
|
|
dp.diph.dwSize = sizeof(dp);
|
|
|
|
dp.diph.dwHeaderSize = sizeof(DIPROPHEADER);
|
|
|
|
dp.diph.dwHow = DIPH_DEVICE;
|
|
|
|
|
|
|
|
hr = IDirectInputDevice_GetProperty(lpdid, DIPROP_BUFFERSIZE, &dp.diph);
|
|
|
|
ok (SUCCEEDED(hr), "GetProperty failed hr=%08x\n", hr);
|
2011-06-28 18:55:24 +02:00
|
|
|
ok (dp.dwData == data->lpdiaf->dwBufferSize, "SetActionMap must set the buffer, buffersize=%d\n", dp.dwData);
|
2011-06-28 18:54:49 +02:00
|
|
|
|
|
|
|
/* SetActionMap has set the data format so now it should work */
|
|
|
|
hr = IDirectInputDevice8_Acquire(lpdid);
|
2011-07-02 06:06:54 +02:00
|
|
|
ok (SUCCEEDED(hr), "Acquire failed hr=%08x\n", hr);
|
2011-06-28 18:54:49 +02:00
|
|
|
|
|
|
|
/* SetActionMap should not work on an acquired device */
|
|
|
|
hr = IDirectInputDevice8_SetActionMap(lpdid, data->lpdiaf, NULL, 0);
|
2011-07-02 06:06:54 +02:00
|
|
|
ok (hr == DIERR_ACQUIRED, "SetActionMap succeeded with an acquired device hr=%08x\n", hr);
|
2011-06-28 18:54:49 +02:00
|
|
|
|
2011-04-30 00:29:19 +02:00
|
|
|
return DIENUM_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void test_action_mapping(void)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
HINSTANCE hinst = GetModuleHandle(NULL);
|
|
|
|
LPDIRECTINPUT8 pDI = NULL;
|
|
|
|
DIACTIONFORMAT af;
|
2011-06-28 18:54:20 +02:00
|
|
|
struct enum_data data = {pDI, &af, NULL, NULL, 0};
|
2011-04-30 00:29:19 +02:00
|
|
|
|
|
|
|
hr = CoCreateInstance(&CLSID_DirectInput8, 0, 1, &IID_IDirectInput8A, (LPVOID*)&pDI);
|
|
|
|
if (hr == DIERR_OLDDIRECTINPUTVERSION ||
|
|
|
|
hr == DIERR_BETADIRECTINPUTVERSION ||
|
|
|
|
hr == REGDB_E_CLASSNOTREG)
|
|
|
|
{
|
|
|
|
win_skip("ActionMapping requires dinput8\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ok(SUCCEEDED(hr), "DirectInput8 Create failed: hr=%08x\n", hr);
|
|
|
|
if (FAILED(hr)) return;
|
|
|
|
|
|
|
|
hr = IDirectInput8_Initialize(pDI,hinst, DIRECTINPUT_VERSION);
|
|
|
|
if (hr == DIERR_OLDDIRECTINPUTVERSION || hr == DIERR_BETADIRECTINPUTVERSION)
|
|
|
|
{
|
|
|
|
win_skip("ActionMapping requires dinput8\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ok(SUCCEEDED(hr), "DirectInput8 Initialize failed: hr=%08x\n", hr);
|
|
|
|
if (FAILED(hr)) return;
|
|
|
|
|
|
|
|
memset (&af, 0, sizeof(af));
|
|
|
|
af.dwSize = sizeof(af);
|
|
|
|
af.dwActionSize = sizeof(DIACTION);
|
|
|
|
af.dwDataSize = 4 * sizeof(actionMapping) / sizeof(actionMapping[0]);
|
|
|
|
af.dwNumActions = sizeof(actionMapping) / sizeof(actionMapping[0]);
|
|
|
|
af.rgoAction = actionMapping;
|
|
|
|
af.guidActionMap = ACTION_MAPPING_GUID;
|
|
|
|
af.dwGenre = 0x01000000; /* DIVIRTUAL_DRIVING_RACE */
|
2011-06-28 18:54:49 +02:00
|
|
|
af.dwBufferSize = 32;
|
2011-04-30 00:29:19 +02:00
|
|
|
|
2011-06-28 18:54:20 +02:00
|
|
|
hr = IDirectInput8_EnumDevicesBySemantics(pDI, 0, &af, enumeration_callback, &data, 0);
|
|
|
|
ok (SUCCEEDED(hr), "EnumDevicesBySemantics failed: hr=%08x\n", hr);
|
2011-06-28 18:54:36 +02:00
|
|
|
ok (data.ndevices > 0, "EnumDevicesBySemantics did not call the callback hr=%08x\n", hr);
|
|
|
|
ok (data.keyboard != NULL, "EnumDevicesBySemantics should enumerate the keyboard\n");
|
|
|
|
ok (data.mouse != NULL, "EnumDevicesBySemantics should enumerate the mouse\n");
|
2011-04-30 00:29:19 +02:00
|
|
|
|
2011-06-28 18:54:49 +02:00
|
|
|
if (data.keyboard != NULL)
|
|
|
|
{
|
|
|
|
/* Test keyboard BuildActionMap */
|
2011-07-02 06:06:01 +02:00
|
|
|
test_build_action_map(data.keyboard, data.lpdiaf, DITEST_KEYBOARDSPACE, DIDFT_PSHBUTTON, DIK_SPACE);
|
2011-06-28 18:54:49 +02:00
|
|
|
/* Test keyboard input */
|
2011-07-02 06:06:01 +02:00
|
|
|
test_device_input(data.keyboard, INPUT_KEYBOARD, VK_SPACE, 2);
|
2011-06-28 18:54:49 +02:00
|
|
|
|
|
|
|
/* Test BuildActionMap with no suitable actions for a device */
|
|
|
|
IDirectInputDevice_Unacquire(data.keyboard);
|
|
|
|
af.dwDataSize = 4 * DITEST_KEYBOARDSPACE;
|
|
|
|
af.dwNumActions = DITEST_KEYBOARDSPACE;
|
|
|
|
|
|
|
|
hr = IDirectInputDevice8_BuildActionMap(data.keyboard, data.lpdiaf, NULL, DIDBAM_INITIALIZE);
|
2011-07-02 06:06:37 +02:00
|
|
|
ok (hr == DI_NOEFFECT, "BuildActionMap should have no effect with no actions hr=%08x\n", hr);
|
2011-06-28 18:54:49 +02:00
|
|
|
|
|
|
|
hr = IDirectInputDevice8_SetActionMap(data.keyboard, data.lpdiaf, NULL, 0);
|
2011-07-02 06:06:54 +02:00
|
|
|
ok (hr == DI_NOEFFECT, "SetActionMap should have no effect with no actions to map hr=%08x\n", hr);
|
2011-06-28 18:54:49 +02:00
|
|
|
|
|
|
|
af.dwDataSize = 4 * sizeof(actionMapping) / sizeof(actionMapping[0]);
|
|
|
|
af.dwNumActions = sizeof(actionMapping) / sizeof(actionMapping[0]);
|
|
|
|
}
|
|
|
|
|
2011-07-02 06:06:01 +02:00
|
|
|
if (data.mouse != NULL)
|
|
|
|
{
|
|
|
|
/* Test mouse BuildActionMap */
|
|
|
|
test_build_action_map(data.mouse, data.lpdiaf, DITEST_MOUSEBUTTON0, DIDFT_PSHBUTTON, 0x03);
|
|
|
|
test_build_action_map(data.mouse, data.lpdiaf, DITEST_YAXIS, DIDFT_RELAXIS, 0x01);
|
|
|
|
|
|
|
|
test_device_input(data.mouse, INPUT_MOUSE, MOUSEEVENTF_LEFTDOWN, 3);
|
|
|
|
}
|
|
|
|
|
2011-04-30 00:29:19 +02:00
|
|
|
/* The call fails with a zeroed GUID */
|
|
|
|
memset(&af.guidActionMap, 0, sizeof(GUID));
|
2011-06-28 18:54:20 +02:00
|
|
|
hr = IDirectInput8_EnumDevicesBySemantics(pDI, 0, &af, enumeration_callback, 0, 0);
|
2011-04-30 00:29:19 +02:00
|
|
|
todo_wine ok(FAILED(hr), "EnumDevicesBySemantics succeeded with invalid GUID hr=%08x\n", hr);
|
|
|
|
}
|
|
|
|
|
|
|
|
START_TEST(device)
|
|
|
|
{
|
|
|
|
CoInitialize(NULL);
|
|
|
|
|
|
|
|
test_action_mapping();
|
|
|
|
|
|
|
|
CoUninitialize();
|
|
|
|
}
|