[2/2] dinput8/tests: Tests for DIPROP_USERNAME property (try 2)

Lucas Fialho Zawacki lfzawacki at gmail.com
Mon Aug 22 16:47:43 CDT 2011


From: Lucas Fialho Zawacki <lfzawacki at gmail.com>

Makefile needs to link advapi32 for GetUserName

Changes after first try:

* Added the missing DIPROPSTRING header dwObj initialization to 0
---
 dlls/dinput8/tests/Makefile.in |    2 +-
 dlls/dinput8/tests/device.c    |   35 ++++++++++++++++++++++++++++++++---
 2 files changed, 33 insertions(+), 4 deletions(-)

diff --git a/dlls/dinput8/tests/Makefile.in b/dlls/dinput8/tests/Makefile.in
index 7584858..fe87118 100644
--- a/dlls/dinput8/tests/Makefile.in
+++ b/dlls/dinput8/tests/Makefile.in
@@ -1,5 +1,5 @@
 TESTDLL   = dinput8.dll
-IMPORTS   = dinput8 ole32 user32
+IMPORTS   = dinput8 ole32 user32 advapi32
 
 C_SRCS = \
 	device.c \
diff --git a/dlls/dinput8/tests/device.c b/dlls/dinput8/tests/device.c
index 63bf55a..a188aa5 100644
--- a/dlls/dinput8/tests/device.c
+++ b/dlls/dinput8/tests/device.c
@@ -31,6 +31,7 @@ struct enum_data {
     LPDIACTIONFORMAT lpdiaf;
     LPDIRECTINPUTDEVICE8 keyboard;
     LPDIRECTINPUTDEVICE8 mouse;
+    const char* username;
     int ndevices;
 };
 
@@ -133,11 +134,24 @@ static BOOL CALLBACK enumeration_callback(
     HRESULT hr;
     DIPROPDWORD dp;
     DIPROPRANGE dpr;
+    DIPROPSTRING dps;
+    WCHAR usernameW[MAX_PATH];
+    DWORD username_size = MAX_PATH;
     struct enum_data *data = pvRef;
+
     if (!data) return DIENUM_CONTINUE;
 
     data->ndevices++;
 
+    /* Convert username to WCHAR */
+    if (data->username != NULL)
+    {
+        username_size = MultiByteToWideChar(CP_ACP, 0, data->username, -1, usernameW, 0);
+        MultiByteToWideChar(CP_ACP, 0, data->username, -1, usernameW, username_size);
+    }
+    else
+        GetUserNameW(usernameW, &username_size);
+
     /* collect the mouse and keyboard */
     if (IsEqualGUID(&lpddi->guidInstance, &GUID_SysKeyboard))
     {
@@ -164,12 +178,22 @@ static BOOL CALLBACK enumeration_callback(
     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);
+    hr = IDirectInputDevice8_SetActionMap(lpdid, data->lpdiaf, data->username, 0);
     ok (SUCCEEDED(hr), "SetActionMap failed hr=%08x\n", hr);
 
     /* Some joysticks may have no suitable actions and thus should not be tested */
     if (hr == DI_NOEFFECT) return DIENUM_CONTINUE;
 
+    /* Test username after SetActionMap */
+    dps.diph.dwSize = sizeof(dps);
+    dps.diph.dwHeaderSize = sizeof(DIPROPHEADER);
+    dps.diph.dwObj = 0;
+    dps.diph.dwHow  = DIPH_DEVICE;
+
+    hr = IDirectInputDevice_GetProperty(lpdid, DIPROP_USERNAME, &dps.diph);
+    todo_wine ok (SUCCEEDED(hr), "GetProperty failed hr=%08x\n", hr);
+    todo_wine ok (!lstrcmpW(usernameW, dps.wsz), "Username not set correctly expected=%s, got=%s\n", wine_dbgstr_wn(usernameW, -1), wine_dbgstr_wn(dps.wsz,-1));
+
     /* Test buffer size */
     memset(&dp, 0, sizeof(dp));
     dp.diph.dwSize = sizeof(dp);
@@ -211,7 +235,7 @@ static void test_action_mapping(void)
     HINSTANCE hinst = GetModuleHandle(NULL);
     LPDIRECTINPUT8 pDI = NULL;
     DIACTIONFORMAT af;
-    struct enum_data data =  {pDI, &af, NULL, NULL, 0};
+    struct enum_data data =  {pDI, &af, NULL, NULL, NULL, 0};
 
     hr = CoCreateInstance(&CLSID_DirectInput8, 0, 1, &IID_IDirectInput8A, (LPVOID*)&pDI);
     if (hr == DIERR_OLDDIRECTINPUTVERSION ||
@@ -244,7 +268,12 @@ static void test_action_mapping(void)
     af.dwBufferSize = 32;
 
     /* This enumeration builds and sets the action map for all devices */
-    hr = IDirectInput8_EnumDevicesBySemantics(pDI, 0, &af, enumeration_callback, &data, DIEDBSFL_ATTACHEDONLY);
+    hr = IDirectInput8_EnumDevicesBySemantics(pDI, NULL, &af, enumeration_callback, &data, DIEDBSFL_ATTACHEDONLY);
+    ok (SUCCEEDED(hr), "EnumDevicesBySemantics failed: hr=%08x\n", hr);
+
+    /* Repeat tests with a non NULL user */
+    data.username = "Ninja Brian";
+    hr = IDirectInput8_EnumDevicesBySemantics(pDI, NULL, &af, enumeration_callback, &data, DIEDBSFL_ATTACHEDONLY);
     ok (SUCCEEDED(hr), "EnumDevicesBySemantics failed: hr=%08x\n", hr);
 
     if (data.keyboard != NULL)
-- 
1.7.0.4



More information about the wine-patches mailing list