From 636cc9acff29666ebf7f1d0043db49c37518c7fd Mon Sep 17 00:00:00 2001 From: Lucas Fialho Zawacki Date: Tue, 28 Jun 2011 13:54:49 -0300 Subject: [PATCH] dinput8/tests: Testing BuildActionMap and SetActionMap with keyboard input. --- dlls/dinput8/tests/device.c | 119 ++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) diff --git a/dlls/dinput8/tests/device.c b/dlls/dinput8/tests/device.c index 83444862bf..af14d608b8 100644 --- a/dlls/dinput8/tests/device.c +++ b/dlls/dinput8/tests/device.c @@ -38,6 +38,13 @@ struct enum_data { /* Dummy GUID */ static const GUID ACTION_MAPPING_GUID = { 0x1, 0x2, 0x3, { 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb } }; +enum { + DITEST_AXIS, + DITEST_BUTTON, + DITEST_KEYBOARDSPACE, + DITEST_MOUSEBUTTON0, +}; + static DIACTION actionMapping[]= { /* axis */ @@ -50,6 +57,63 @@ static DIACTION actionMapping[]= { 3, DIMOUSE_BUTTON0 , 0, { "Select" } } }; +static void test_keyboard_input( + LPDIRECTINPUTDEVICE8 lpdid, + DWORD key, + DWORD expected +) +{ + HRESULT hr; + DIDEVICEOBJECTDATA obj_data; + DWORD data_size = 1; + + hr = IDirectInputDevice8_Acquire(lpdid); + todo_wine ok (SUCCEEDED(hr), "Failed to acquire device hr=%08x\n", hr); + + keybd_event( key, 0, 0, 0); + + 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; + } + + ok (data_size == 1, "GetDeviceData did not read any event\n"); + todo_wine ok (obj_data.uAppData == expected, "Retrieval of action failed uAppData=%lu expected=%d\n", obj_data.uAppData, expected); +} + +static void test_build_action_map( + LPDIRECTINPUTDEVICE8 lpdid, + LPDIACTIONFORMAT lpdiaf, + int action_index, + DWORD obj_expected +) +{ + HRESULT hr; + DIACTION *actions; + DWORD obj_instance, how; + 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; + obj_instance = DIDFT_GETINSTANCE(actions[action_index].dwObjID); + how = actions[action_index].dwHow; + assigned_to = actions[action_index].guidInstance; + + todo_wine ok (how == DIAH_USERCONFIG || how == DIAH_DEFAULT, "Action was not set dwHow=%08x\n", how); + todo_wine ok (obj_instance == obj_expected, "Action not mapped correctly instance=%08x expected=%08x\n", obj_instance, obj_expected); + todo_wine ok (IsEqualGUID(&assigned_to, &ddi.guidInstance), "Action and device GUID do not match action=%d\n", action_index); +} + static BOOL CALLBACK enumeration_callback( LPCDIDEVICEINSTANCE lpddi, LPDIRECTINPUTDEVICE8 lpdid, @@ -57,6 +121,8 @@ static BOOL CALLBACK enumeration_callback( DWORD dwRemaining, LPVOID pvRef) { + HRESULT hr; + DIPROPDWORD dp; struct enum_data *data = pvRef; if (!data) return DIENUM_CONTINUE; @@ -79,6 +145,36 @@ static BOOL CALLBACK enumeration_callback( ok (dwFlags & DIEDBS_MAPPEDPRI1, "Mouse should be mapped as pri1 dwFlags=%08x\n", dwFlags); } + /* 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); + todo_wine ok (dp.dwData == data->lpdiaf->dwBufferSize, "SetActionMap must set the buffer, buffersize=%d\n", dp.dwData); + + /* SetActionMap has set the data format so now it should work */ + hr = IDirectInputDevice8_Acquire(lpdid); + todo_wine ok (SUCCEEDED(hr), "Acquire failed hr=%08x\n", hr); + + /* SetActionMap should not work on an acquired device */ + hr = IDirectInputDevice8_SetActionMap(lpdid, data->lpdiaf, NULL, 0); + todo_wine ok (hr == DIERR_ACQUIRED, "SetActionMap succeeded with an acquired device hr=%08x\n", hr); + return DIENUM_CONTINUE; } @@ -119,6 +215,7 @@ static void test_action_mapping(void) af.rgoAction = actionMapping; af.guidActionMap = ACTION_MAPPING_GUID; af.dwGenre = 0x01000000; /* DIVIRTUAL_DRIVING_RACE */ + af.dwBufferSize = 32; hr = IDirectInput8_EnumDevicesBySemantics(pDI, 0, &af, enumeration_callback, &data, 0); ok (SUCCEEDED(hr), "EnumDevicesBySemantics failed: hr=%08x\n", hr); @@ -126,6 +223,28 @@ static void test_action_mapping(void) ok (data.keyboard != NULL, "EnumDevicesBySemantics should enumerate the keyboard\n"); ok (data.mouse != NULL, "EnumDevicesBySemantics should enumerate the mouse\n"); + if (data.keyboard != NULL) + { + /* Test keyboard BuildActionMap */ + test_build_action_map(data.keyboard, data.lpdiaf, DITEST_KEYBOARDSPACE, DIK_SPACE); + /* Test keyboard input */ + test_keyboard_input(data.keyboard, VK_SPACE, 2); + + /* 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); + todo_wine ok (hr == DI_NOEFFECT, "BuildActionMap should have no effect with no actions hr=%08x\n", hr); + + hr = IDirectInputDevice8_SetActionMap(data.keyboard, data.lpdiaf, NULL, 0); + todo_wine ok (hr == DI_NOEFFECT, "SetActionMap should have no effect with no actions to map hr=%08x\n", hr); + + af.dwDataSize = 4 * sizeof(actionMapping) / sizeof(actionMapping[0]); + af.dwNumActions = sizeof(actionMapping) / sizeof(actionMapping[0]); + } + /* The call fails with a zeroed GUID */ memset(&af.guidActionMap, 0, sizeof(GUID)); hr = IDirectInput8_EnumDevicesBySemantics(pDI, 0, &af, enumeration_callback, 0, 0);