[PATCH v3 6/6] user32: Implemented usage tests for RegisterDeviceNotification

Micah N Gorrell mgorrell at codeweavers.com
Sun May 19 10:38:18 CDT 2019


Signed-off-by: Micah N Gorrell <mgorrell at codeweavers.com>
---
 dlls/user32/tests/Makefile.in |  1 +
 dlls/user32/tests/misc.c      | 88 +++++++++++++++++++++++++++++++++++
 2 files changed, 89 insertions(+)
 create mode 100644 dlls/user32/tests/misc.c

diff --git a/dlls/user32/tests/Makefile.in b/dlls/user32/tests/Makefile.in
index 7149dc824e..da55fa58e5 100644
--- a/dlls/user32/tests/Makefile.in
+++ b/dlls/user32/tests/Makefile.in
@@ -15,6 +15,7 @@ C_SRCS = \
 	input.c \
 	listbox.c \
 	menu.c \
+	misc.c \
 	monitor.c \
 	msg.c \
 	resource.c \
diff --git a/dlls/user32/tests/misc.c b/dlls/user32/tests/misc.c
new file mode 100644
index 0000000000..d900576934
--- /dev/null
+++ b/dlls/user32/tests/misc.c
@@ -0,0 +1,88 @@
+/*
+ * Unit tests for misc functions
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <stdarg.h>
+
+#include "wine/test.h"
+#include "windef.h"
+#include "winbase.h"
+#include "winuser.h"
+#include "dbt.h"
+
+static void RegisterDeviceNotificationTest(void)
+{
+    static const WCHAR mainwindowclassW[] = {'M','a','i','n','W','i','n','d','o','w','C','l','a','s','s',0};
+    static const WCHAR message_windowW[] = {'m','e','s','s','a','g','e',' ','w','i','n','d','o','w',0};
+
+    HDEVNOTIFY hnotify1, hnotify2;
+    DEV_BROADCAST_DEVICEINTERFACE_W dbh;
+    HWND hwnd;
+    WNDCLASSEXW cls;
+    GUID GUID_DEVINTERFACE_HID = { 0x4D1E55B2L, 0xF16F, 0x11CF, { 0x88, 0xCB, 0x00, 0x11, 0x11, 0x00, 0x00, 0x30 } };
+
+    memset(&cls, 0, sizeof(cls));
+    cls.cbSize = sizeof(cls);
+    cls.hInstance = 0;
+    cls.lpszClassName = mainwindowclassW;
+    cls.lpfnWndProc = DefWindowProcW;
+
+    RegisterClassExW(&cls);
+
+    hwnd = CreateWindowExW(0, mainwindowclassW, message_windowW, 0,
+                           0, 0, 0, 0, HWND_MESSAGE, 0, 0, NULL);
+    ok( hwnd != 0, "CreateWindowExW with parent HWND_MESSAGE failed\n" );
+
+    memset(&dbh, 0, sizeof(dbh));
+
+    dbh.dbcc_size = sizeof(dbh);
+    dbh.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
+    dbh.dbcc_classguid = GUID_DEVINTERFACE_HID;
+
+    /* Test RegisterDeviceNotification behavior */
+
+    /* Prior to Windows 8 a NULL recipient handle caused a failure, but more
+     * recent versions of windows allow it.
+     */
+    hnotify1 = RegisterDeviceNotificationW( NULL, &dbh, DEVICE_NOTIFY_WINDOW_HANDLE );
+    /* ok( hnotify1 != 0, "RegisterDeviceNotificationW failed when called with a NULL recipient window handle\n" ); */
+    if ( hnotify1 != 0 )
+        ok( UnregisterDeviceNotification( hnotify1 ), "UnregisterDeviceNotification failed with a valid handle\n" );
+
+    hnotify1 = RegisterDeviceNotificationW( hwnd, &dbh, DEVICE_NOTIFY_WINDOW_HANDLE );
+    ok( hnotify1 != 0, "RegisterDeviceNotificationW failed when called with a message only window as recipient\n" );
+
+    hnotify2 = RegisterDeviceNotificationW( hwnd, &dbh, DEVICE_NOTIFY_WINDOW_HANDLE );
+    ok( hnotify2 != 0, "RegisterDeviceNotificationW failed when called with a window that has already been registered as a recipient\n" );
+
+    ok( UnregisterDeviceNotification( hnotify1 ), "UnregisterDeviceNotification failed with a valid handle\n" );
+    ok( UnregisterDeviceNotification( hnotify2 ), "UnregisterDeviceNotification failed with a valid handle\n" );
+    ok( !UnregisterDeviceNotification( hnotify1 ), "UnregisterDeviceNotification succeeded with an already released handle\n" );
+    ok( !UnregisterDeviceNotification( NULL ), "UnregisterDeviceNotification succeeded with NULL handle\n" );
+
+    hnotify1 = RegisterDeviceNotificationW( hwnd, &dbh, 0xffff );
+    ok( hnotify1 == 0, "RegisterDeviceNotificationW accepted invalid flags\n" );
+
+    /* FIXME: Find a way to trigger a device notification for testing */
+    DestroyWindow(hwnd);
+}
+
+
+START_TEST(misc)
+{
+    RegisterDeviceNotificationTest();
+}
-- 
2.21.0




More information about the wine-devel mailing list