[1/2] dinput8/tests: Added tests for saving and retrieving settings with SetActionMap
Lucas Zawacki
lfzawacki at gmail.com
Fri Aug 24 12:04:51 CDT 2012
From: Lucas Zawacki <lfzawacki at gmail.com>
Some instances of BuildActionMap that appear in the test were modified to use the flag DIDBAM_HWDEFAULTS. I was
under the impression that DIDBAM_INITIALIZE would ignore the pre-stored settings, but my tests proved me wrong and
only DIDBAM_HWDEFAULTS does this on Windows.
---
dlls/dinput8/tests/device.c | 134 +++++++++++++++++++++++++++++++++++++++++--
1 file changed, 130 insertions(+), 4 deletions(-)
diff --git a/dlls/dinput8/tests/device.c b/dlls/dinput8/tests/device.c
index 2deb348..e5b3f6a 100644
--- a/dlls/dinput8/tests/device.c
+++ b/dlls/dinput8/tests/device.c
@@ -132,7 +132,7 @@ static void test_build_action_map(
ddi.dwSize = sizeof(ddi);
IDirectInputDevice_GetDeviceInfo(lpdid, &ddi);
- hr = IDirectInputDevice8_BuildActionMap(lpdid, lpdiaf, NULL, DIDBAM_INITIALIZE);
+ hr = IDirectInputDevice8_BuildActionMap(lpdid, lpdiaf, NULL, DIDBAM_HWDEFAULTS);
ok (SUCCEEDED(hr), "BuildActionMap failed hr=%08x\n", hr);
actions = lpdiaf->rgoAction;
@@ -195,8 +195,8 @@ static BOOL CALLBACK enumeration_callback(
}
/* 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);
+ /* It should not use any pre-stored mappings so we use DIDBAM_HWDEFAULTS */
+ hr = IDirectInputDevice8_BuildActionMap(lpdid, data->lpdiaf, NULL, DIDBAM_HWDEFAULTS);
ok (SUCCEEDED(hr), "BuildActionMap failed hr=%08x\n", hr);
/* Device has no data format and thus can't be acquired */
@@ -322,7 +322,7 @@ static void test_action_mapping(void)
af.dwDataSize = 4 * DITEST_KEYBOARDSPACE;
af.dwNumActions = DITEST_KEYBOARDSPACE;
- hr = IDirectInputDevice8_BuildActionMap(data.keyboard, data.lpdiaf, NULL, DIDBAM_INITIALIZE);
+ hr = IDirectInputDevice8_BuildActionMap(data.keyboard, data.lpdiaf, NULL, DIDBAM_HWDEFAULTS);
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);
@@ -342,11 +342,137 @@ static void test_action_mapping(void)
}
}
+static void test_save_settings(void)
+{
+ HRESULT hr;
+ HINSTANCE hinst = GetModuleHandle(NULL);
+ LPDIRECTINPUT8 pDI = NULL;
+ DIACTIONFORMAT af;
+ IDirectInputDevice8A *pKey;
+
+ static const GUID mapping_guid = { 0xcafecafe, 0x2, 0x3, { 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb } };
+ static DIACTION actions[] = {
+ { 0, DIKEYBOARD_A , 0, { "Blam" } },
+ { 1, DIKEYBOARD_B , 0, { "Kapow"} }
+ };
+ static const DWORD results[] = {
+ DIDFT_MAKEINSTANCE(DIK_A) | DIDFT_PSHBUTTON,
+ DIDFT_MAKEINSTANCE(DIK_B) | DIDFT_PSHBUTTON
+ };
+ static const DWORD other_results[] = {
+ DIDFT_MAKEINSTANCE(DIK_C) | DIDFT_PSHBUTTON,
+ DIDFT_MAKEINSTANCE(DIK_D) | DIDFT_PSHBUTTON
+ };
+
+ hr = CoCreateInstance(&CLSID_DirectInput8, 0, CLSCTX_INPROC_SERVER, &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;
+
+ hr = IDirectInput_CreateDevice(pDI, &GUID_SysKeyboard, &pKey, NULL);
+ ok (SUCCEEDED(hr), "IDirectInput_Create device failed hr: 0x%08x\n", hr);
+ if (FAILED(hr)) return;
+
+ memset (&af, 0, sizeof(af));
+ af.dwSize = sizeof(af);
+ af.dwActionSize = sizeof(DIACTION);
+ af.dwDataSize = 4 * sizeof(actions) / sizeof(actions[0]);
+ af.dwNumActions = sizeof(actions) / sizeof(actions[0]);
+ af.rgoAction = actions;
+ af.guidActionMap = mapping_guid;
+ af.dwGenre = 0x01000000; /* DIVIRTUAL_DRIVING_RACE */
+ af.dwBufferSize = 32;
+
+ /* Easy case. Ask for default mapping, save, ask for previous map and read it back */
+ hr = IDirectInputDevice8_BuildActionMap(pKey, &af, NULL, DIDBAM_HWDEFAULTS);
+ ok (SUCCEEDED(hr), "BuildActionMap failed hr=%08x\n", hr);
+
+ ok (results[0] == af.rgoAction[0].dwObjID,
+ "Mapped incorrectly expected: 0x%08x got: 0x%08x\n", results[0], af.rgoAction[0].dwObjID);
+
+ ok (results[1] == af.rgoAction[1].dwObjID,
+ "Mapped incorrectly expected: 0x%08x got: 0x%08x\n", results[1], af.rgoAction[1].dwObjID);
+
+ hr = IDirectInputDevice8_SetActionMap(pKey, &af, NULL, DIDSAM_FORCESAVE);
+ ok (SUCCEEDED(hr), "SetActionMap failed hr=%08x\n", hr);
+
+ if (hr == DI_SETTINGSNOTSAVED)
+ {
+ skip ("Cant test saving settings if SetActionMap returns DI_SETTINGSNOTSAVED\n");
+ return;
+ }
+
+ af.rgoAction[0].dwObjID = 0;
+ af.rgoAction[1].dwObjID = 0;
+ memset(&af.rgoAction[0].guidInstance, 0, sizeof(GUID));
+ memset(&af.rgoAction[1].guidInstance, 0, sizeof(GUID));
+
+ hr = IDirectInputDevice8_BuildActionMap(pKey, &af, NULL, 0);
+ ok (SUCCEEDED(hr), "BuildActionMap failed hr=%08x\n", hr);
+
+ ok (results[0] == af.rgoAction[0].dwObjID,
+ "Mapped incorrectly expected: 0x%08x got: 0x%08x\n", results[0], af.rgoAction[0].dwObjID);
+ ok (IsEqualGUID(&GUID_SysKeyboard, &af.rgoAction[0].guidInstance), "Action should be mapped to keyboard\n");
+
+ ok (results[1] == af.rgoAction[1].dwObjID,
+ "Mapped incorrectly expected: 0x%08x got: 0x%08x\n", results[1], af.rgoAction[1].dwObjID);
+ ok (IsEqualGUID(&GUID_SysKeyboard, &af.rgoAction[1].guidInstance), "Action should be mapped to keyboard\n");
+
+ /* Hard case. Customized mapping, save, ask for previous map and read it back */
+ af.rgoAction[0].dwObjID = other_results[0];
+ af.rgoAction[0].dwHow = DIAH_USERCONFIG;
+ af.rgoAction[0].guidInstance = GUID_SysKeyboard;
+ af.rgoAction[1].dwObjID = other_results[1];
+ af.rgoAction[1].dwHow = DIAH_USERCONFIG;
+ af.rgoAction[1].guidInstance = GUID_SysKeyboard;
+
+ hr = IDirectInputDevice8_SetActionMap(pKey, &af, NULL, DIDSAM_FORCESAVE);
+ ok (SUCCEEDED(hr), "SetActionMap failed hr=%08x\n", hr);
+
+ if (hr == DI_SETTINGSNOTSAVED)
+ {
+ skip ("Cant test saving settings if SetActionMap returns DI_SETTINGSNOTSAVED\n");
+ return;
+ }
+
+ af.rgoAction[0].dwObjID = 0;
+ af.rgoAction[1].dwObjID = 0;
+ memset(&af.rgoAction[0].guidInstance, 0, sizeof(GUID));
+ memset(&af.rgoAction[1].guidInstance, 0, sizeof(GUID));
+
+ hr = IDirectInputDevice8_BuildActionMap(pKey, &af, NULL, 0);
+ ok (SUCCEEDED(hr), "BuildActionMap failed hr=%08x\n", hr);
+
+ todo_wine ok (other_results[0] == af.rgoAction[0].dwObjID,
+ "Mapped incorrectly expected: 0x%08x got: 0x%08x\n", other_results[0], af.rgoAction[0].dwObjID);
+ todo_wine ok (IsEqualGUID(&GUID_SysKeyboard, &af.rgoAction[0].guidInstance), "Action should be mapped to keyboard\n");
+
+ todo_wine ok (other_results[1] == af.rgoAction[1].dwObjID,
+ "Mapped incorrectly expected: 0x%08x got: 0x%08x\n", other_results[1], af.rgoAction[1].dwObjID);
+ todo_wine ok (IsEqualGUID(&GUID_SysKeyboard, &af.rgoAction[1].guidInstance), "Action should be mapped to keyboard\n");
+}
+
START_TEST(device)
{
CoInitialize(NULL);
test_action_mapping();
+ test_save_settings();
CoUninitialize();
}
--
1.7.9.5
More information about the wine-patches
mailing list