Lucas Fialho Zawacki : dinput8/tests: Tests for EnumDevicesBySemantics with different enumeration flags.

Alexandre Julliard julliard at winehq.org
Mon Jul 11 13:17:49 CDT 2011


Module: wine
Branch: master
Commit: a85f66e7a723bca960d5fb07044fbb838275ef10
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=a85f66e7a723bca960d5fb07044fbb838275ef10

Author: Lucas Fialho Zawacki <lfzawacki at gmail.com>
Date:   Fri Jul  8 15:00:21 2011 -0300

dinput8/tests: Tests for EnumDevicesBySemantics with different enumeration flags.

---

 dlls/dinput8/tests/device.c |   63 +++++++++++++++++++++++++++++++++++++++---
 1 files changed, 58 insertions(+), 5 deletions(-)

diff --git a/dlls/dinput8/tests/device.c b/dlls/dinput8/tests/device.c
index 3d35632..e86e0d8 100644
--- a/dlls/dinput8/tests/device.c
+++ b/dlls/dinput8/tests/device.c
@@ -187,6 +187,28 @@ static BOOL CALLBACK enumeration_callback(
     return DIENUM_CONTINUE;
 }
 
+/*  A simpler callback function used to count and check
+    the enumeration of devices.
+*/
+static BOOL CALLBACK counting_callback(
+    LPCDIDEVICEINSTANCE lpddi,
+    LPDIRECTINPUTDEVICE8 lpdid,
+    DWORD dwFlags,
+    DWORD dwRemaining,
+    LPVOID pvRef)
+{
+    struct enum_data *data = pvRef;
+    if (!data) return DIENUM_CONTINUE;
+
+    data->ndevices++;
+    if (IsEqualGUID(&lpddi->guidInstance, &GUID_SysKeyboard))
+        data->keyboard = lpdid;
+
+    if (IsEqualGUID(&lpddi->guidInstance, &GUID_SysMouse))
+        data->mouse = lpdid;
+
+    return DIENUM_CONTINUE;
+}
 
 static void test_action_mapping(void)
 {
@@ -194,7 +216,8 @@ 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, 0};
+    struct enum_data count = {pDI, &af, NULL, NULL, 0};
 
     hr = CoCreateInstance(&CLSID_DirectInput8, 0, 1, &IID_IDirectInput8A, (LPVOID*)&pDI);
     if (hr == DIERR_OLDDIRECTINPUTVERSION ||
@@ -226,12 +249,42 @@ static void test_action_mapping(void)
     af.dwGenre = 0x01000000; /* DIVIRTUAL_DRIVING_RACE */
     af.dwBufferSize = 32;
 
-    hr = IDirectInput8_EnumDevicesBySemantics(pDI, 0, &af, enumeration_callback, &data, 0);
+    /* Test enumerating all attached and installed devices */
+    count.keyboard = NULL;
+    count.mouse = NULL;
+    count.ndevices = 0;
+    hr = IDirectInput8_EnumDevicesBySemantics(pDI, 0, &af, counting_callback, &count, DIEDBSFL_ATTACHEDONLY);
+    ok (count.ndevices > 0, "EnumDevicesBySemantics did not call the callback hr=%08x\n", hr);
+    ok (count.keyboard != NULL, "EnumDevicesBySemantics should enumerate the keyboard\n");
+    ok (count.mouse != NULL, "EnumDevicesBySemantics should enumerate the mouse\n");
+
+    /* Enumerate Force feedback devices. We should get no mouse nor keyboard */
+    count.keyboard = NULL;
+    count.mouse = NULL;
+    hr = IDirectInput8_EnumDevicesBySemantics(pDI, 0, &af, counting_callback, &count, DIEDBSFL_FORCEFEEDBACK);
+    ok (SUCCEEDED(hr), "EnumDevicesBySemantics failed hr=%08x\n", hr);
+    todo_wine ok (count.keyboard == NULL, "Keyboard should not be enumerated when asking for forcefeedback\n");
+    todo_wine ok (count.mouse == NULL, "Mouse should not be enumerated when asking for forcefeedback\n");
+
+    /* Enumerate available devices. That is devices with not owned by any user.
+       Before setting the action map for all devices we still have them available.
+    */
+    count.ndevices = 0;
+    hr = IDirectInput8_EnumDevicesBySemantics(pDI, 0, &af, counting_callback, &count, DIEDBSFL_AVAILABLEDEVICES);
+    ok (SUCCEEDED(hr), "EnumDevicesBySemantics failed hr=%08x\n", hr);
+    ok (count.ndevices > 0, "There should be devices available before action mapping available=%d\n", count.ndevices);
+
+    /* This enumeration builds and sets the action map for all devices */
+    hr = IDirectInput8_EnumDevicesBySemantics(pDI, 0, &af, enumeration_callback, &data, DIEDBSFL_ATTACHEDONLY);
     ok (SUCCEEDED(hr), "EnumDevicesBySemantics failed: hr=%08x\n", hr);
-    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");
 
+    /* After a succesfull action mapping we should have no devices available */
+    count.ndevices = 0;
+    hr = IDirectInput8_EnumDevicesBySemantics(pDI, 0, &af, counting_callback, &count, DIEDBSFL_AVAILABLEDEVICES);
+    ok (SUCCEEDED(hr), "EnumDevicesBySemantics failed hr=%08x\n", hr);
+    todo_wine ok (count.ndevices == 0, "No device should be available after action mapping available=%d\n", count.ndevices);
+
+    /* Use the devices we collect for some tests */
     if (data.keyboard != NULL)
     {
         /* Test keyboard BuildActionMap */




More information about the wine-cvs mailing list