1 /* Unit test suite for rawinput. 2 * 3 * Copyright 2019 Remi Bernon for CodeWeavers 4 * 5 * This library is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Lesser General Public 7 * License as published by the Free Software Foundation; either 8 * version 2.1 of the License, or (at your option) any later version. 9 * 10 * This library is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public 16 * License along with this library; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 18 */ 19 20 #include <stdarg.h> 21 #include <stdio.h> 22 23 #define STRICT 24 #define WIN32_LEAN_AND_MEAN 25 #include <windows.h> 26 27 #include "wine/test.h" 28 29 static void test_RegisterRawInputDevices(void) 30 { 31 HWND hwnd; 32 RAWINPUTDEVICE raw_devices[1]; 33 BOOL res; 34 35 raw_devices[0].usUsagePage = 0x01; 36 raw_devices[0].usUsage = 0x05; 37 38 hwnd = CreateWindowExA(WS_EX_TOPMOST, "static", "dinput", WS_POPUP | WS_VISIBLE, 0, 0, 100, 100, NULL, NULL, NULL, NULL); 39 ok(hwnd != NULL, "CreateWindowExA failed\n"); 40 41 42 res = RegisterRawInputDevices(NULL, 0, 0); 43 ok(res == FALSE, "RegisterRawInputDevices succeeded\n"); 44 45 46 raw_devices[0].dwFlags = 0; 47 raw_devices[0].hwndTarget = 0; 48 49 SetLastError(0xdeadbeef); 50 res = RegisterRawInputDevices(raw_devices, ARRAY_SIZE(raw_devices), 0); 51 ok(res == FALSE, "RegisterRawInputDevices succeeded\n"); 52 ok(GetLastError() == ERROR_INVALID_PARAMETER, "RegisterRawInputDevices returned %08x\n", GetLastError()); 53 54 SetLastError(0xdeadbeef); 55 res = RegisterRawInputDevices(raw_devices, ARRAY_SIZE(raw_devices), sizeof(RAWINPUTDEVICE)); 56 ok(res == TRUE, "RegisterRawInputDevices failed\n"); 57 ok(GetLastError() == 0xdeadbeef, "RegisterRawInputDevices returned %08x\n", GetLastError()); 58 59 60 /* RIDEV_REMOVE requires hwndTarget == NULL */ 61 raw_devices[0].dwFlags = RIDEV_REMOVE; 62 raw_devices[0].hwndTarget = hwnd; 63 64 SetLastError(0xdeadbeef); 65 res = RegisterRawInputDevices(raw_devices, ARRAY_SIZE(raw_devices), sizeof(RAWINPUTDEVICE)); 66 ok(res == FALSE, "RegisterRawInputDevices succeeded\n"); 67 ok(GetLastError() == ERROR_INVALID_PARAMETER, "RegisterRawInputDevices returned %08x\n", GetLastError()); 68 69 raw_devices[0].hwndTarget = 0; 70 71 SetLastError(0xdeadbeef); 72 res = RegisterRawInputDevices(raw_devices, ARRAY_SIZE(raw_devices), sizeof(RAWINPUTDEVICE)); 73 ok(res == TRUE, "RegisterRawInputDevices failed\n"); 74 ok(GetLastError() == 0xdeadbeef, "RegisterRawInputDevices returned %08x\n", GetLastError()); 75 76 77 /* RIDEV_INPUTSINK requires hwndTarget != NULL */ 78 raw_devices[0].dwFlags = RIDEV_INPUTSINK; 79 raw_devices[0].hwndTarget = 0; 80 81 SetLastError(0xdeadbeef); 82 res = RegisterRawInputDevices(raw_devices, ARRAY_SIZE(raw_devices), sizeof(RAWINPUTDEVICE)); 83 todo_wine 84 ok(res == FALSE, "RegisterRawInputDevices failed\n"); 85 todo_wine 86 ok(GetLastError() == ERROR_INVALID_PARAMETER, "RegisterRawInputDevices returned %08x\n", GetLastError()); 87 88 raw_devices[0].hwndTarget = hwnd; 89 90 SetLastError(0xdeadbeef); 91 res = RegisterRawInputDevices(raw_devices, ARRAY_SIZE(raw_devices), sizeof(RAWINPUTDEVICE)); 92 ok(res == TRUE, "RegisterRawInputDevices succeeded\n"); 93 ok(GetLastError() == 0xdeadbeef, "RegisterRawInputDevices returned %08x\n", GetLastError()); 94 95 DestroyWindow(hwnd); 96 } 97 98 START_TEST(rawinput) 99 { 100 test_RegisterRawInputDevices(); 101 } 102