[PATCH 1/8] user32/tests: Add basic rawinput message tests.

Rémi Bernon rbernon at codeweavers.com
Sun Jun 7 06:21:13 CDT 2020


This tests basic functionality by injecting mouse event and checking
the number of each messages received.

Signed-off-by: Rémi Bernon <rbernon at codeweavers.com>
---
 dlls/user32/tests/input.c | 136 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 136 insertions(+)

diff --git a/dlls/user32/tests/input.c b/dlls/user32/tests/input.c
index 913fabfbd85..4d1a1c062ab 100644
--- a/dlls/user32/tests/input.c
+++ b/dlls/user32/tests/input.c
@@ -1819,6 +1819,141 @@ static void test_RegisterRawInputDevices(void)
     DestroyWindow(hwnd);
 }
 
+static int rawinput_test_count_legacy;
+static int rawinput_test_count_raw;
+static int rawinput_test_count_rawfg;
+
+static LRESULT CALLBACK rawinput_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
+{
+    UINT ret, raw_size;
+    RAWINPUT raw;
+
+    if (msg == WM_INPUT)
+    {
+        todo_wine_if(rawinput_test_count_raw)
+        ok(rawinput_test_count_raw == 0, "Unexpected spurious WM_INPUT message.\n");
+        ok(wparam == RIM_INPUT || wparam == RIM_INPUTSINK, "Unexpected wparam: %lu\n", wparam);
+
+        rawinput_test_count_raw++;
+        if (wparam == RIM_INPUT) rawinput_test_count_rawfg++;
+
+        ret = GetRawInputData((HRAWINPUT)lparam, RID_INPUT, NULL, &raw_size, sizeof(RAWINPUTHEADER));
+        ok(ret == 0, "GetRawInputData failed\n");
+        ok(raw_size <= sizeof(raw), "Unexpected rawinput data size: %u", raw_size);
+        if (raw_size > sizeof(raw))
+            return DefWindowProcA(hwnd, msg, wparam, lparam);
+
+        ret = GetRawInputData((HRAWINPUT)lparam, RID_INPUT, &raw, &raw_size, sizeof(RAWINPUTHEADER));
+        ok(ret > 0 && ret != (UINT)-1, "GetRawInputData failed\n");
+        ok(raw.header.dwType == RIM_TYPEMOUSE, "Unexpected rawinput type: %u\n", raw.header.dwType);
+        if (raw.header.dwType != RIM_TYPEMOUSE)
+            return DefWindowProcA(hwnd, msg, wparam, lparam);
+
+        ok(!(raw.data.mouse.usFlags & MOUSE_MOVE_ABSOLUTE), "Unexpected absolute rawinput motion\n");
+        ok(!(raw.data.mouse.usFlags & MOUSE_VIRTUAL_DESKTOP), "Unexpected virtual desktop rawinput motion\n");
+    }
+
+    if (msg == WM_MOUSEMOVE) rawinput_test_count_legacy++;
+
+    return DefWindowProcA(hwnd, msg, wparam, lparam);
+}
+
+struct rawinput_test
+{
+    BOOL register_device;
+    BOOL register_window;
+    DWORD register_flags;
+    int expect_legacy;
+    int expect_raw;
+    int expect_rawfg;
+    BOOL todo_legacy;
+    BOOL todo_raw;
+    BOOL todo_rawfg;
+};
+
+struct rawinput_test rawinput_tests[] =
+{
+    { FALSE, FALSE, 0,                TRUE, FALSE, FALSE, /* todos: */ FALSE, FALSE, FALSE },
+    { TRUE,  FALSE, 0,                TRUE,  TRUE,  TRUE, /* todos: */ FALSE, FALSE, FALSE },
+    { TRUE,  TRUE,  0,                TRUE,  TRUE,  TRUE, /* todos: */ FALSE, FALSE, FALSE },
+    { TRUE,  TRUE,  RIDEV_NOLEGACY,  FALSE,  TRUE,  TRUE, /* todos: */  TRUE, FALSE, FALSE },
+};
+
+static void test_rawinput(void)
+{
+    RAWINPUTDEVICE raw_devices[1];
+    DWORD ret;
+    POINT pt, newpt;
+    HWND hwnd;
+    int i;
+
+    SetCursorPos(100, 100);
+    empty_message_queue();
+
+    for (i = 0; i < ARRAY_SIZE(rawinput_tests); ++i)
+    {
+        GetCursorPos(&pt);
+
+        hwnd = CreateWindowA("static", "static", WS_VISIBLE | WS_POPUP,
+                             pt.x - 50, pt.y - 50, 100, 100, 0, NULL, NULL, NULL);
+        ok(hwnd != 0, "CreateWindow failed\n");
+        SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (LONG_PTR)rawinput_wndproc);
+        empty_message_queue();
+
+        ShowWindow(hwnd, SW_SHOW);
+        SetWindowPos(hwnd, NULL, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
+        SetForegroundWindow(hwnd);
+        UpdateWindow(hwnd);
+        empty_message_queue();
+
+        rawinput_test_count_legacy = 0;
+        rawinput_test_count_raw = 0;
+        rawinput_test_count_rawfg = 0;
+
+        raw_devices[0].usUsagePage = 0x01;
+        raw_devices[0].usUsage = 0x02;
+        raw_devices[0].dwFlags = rawinput_tests[i].register_flags;
+        raw_devices[0].hwndTarget = rawinput_tests[i].register_window ? hwnd : 0;
+
+        if (rawinput_tests[i].register_device)
+        {
+            SetLastError(0xdeadbeef);
+            ret = RegisterRawInputDevices(raw_devices, ARRAY_SIZE(raw_devices), sizeof(RAWINPUTDEVICE));
+            ok(ret, "%d: RegisterRawInputDevices failed\n", i);
+            ok(GetLastError() == 0xdeadbeef, "%d: RegisterRawInputDevices returned %08x\n", i, GetLastError());
+        }
+
+        mouse_event(MOUSEEVENTF_MOVE, 5, 0, 0, 0);
+        empty_message_queue();
+
+        todo_wine_if(rawinput_tests[i].todo_legacy)
+        ok(!!rawinput_test_count_legacy == rawinput_tests[i].expect_legacy,
+           "%d: Unexpected WM_MOUSEMOVE message count\n", i);
+        todo_wine_if(rawinput_tests[i].todo_raw)
+        ok(!!rawinput_test_count_raw == rawinput_tests[i].expect_raw,
+           "%d: Unexpected WM_INPUT message count\n", i);
+        todo_wine_if(rawinput_tests[i].todo_rawfg)
+        ok(!!rawinput_test_count_rawfg == rawinput_tests[i].expect_rawfg,
+           "%d: Unexpected RIM_INPUT message count\n", i);
+
+        GetCursorPos(&newpt);
+        ok((newpt.x - pt.x) == 5 || (newpt.x - pt.x) == 4, "%d: Unexpected cursor movement\n", i);
+
+        if (rawinput_tests[i].register_device)
+        {
+            raw_devices[0].dwFlags = RIDEV_REMOVE;
+            raw_devices[0].hwndTarget = 0;
+
+            SetLastError(0xdeadbeef);
+            ret = RegisterRawInputDevices(raw_devices, ARRAY_SIZE(raw_devices), sizeof(RAWINPUTDEVICE));
+            ok(ret, "%d: RegisterRawInputDevices failed\n", i);
+            ok(GetLastError() == 0xdeadbeef, "%d: RegisterRawInputDevices returned %08x\n", i, GetLastError());
+        }
+
+        DestroyWindow(hwnd);
+    }
+}
+
 static void test_key_map(void)
 {
     HKL kl = GetKeyboardLayout(0);
@@ -3034,6 +3169,7 @@ START_TEST(input)
     test_OemKeyScan();
     test_GetRawInputData();
     test_RegisterRawInputDevices();
+    test_rawinput();
 
     if(pGetMouseMovePointsEx)
         test_GetMouseMovePointsEx();
-- 
2.27.0




More information about the wine-devel mailing list