[PATCH v2 6/6] user32: Implemented usage tests for RegisterDeviceNotification
Zhiyi Zhang
zzhang at codeweavers.com
Sun May 19 20:09:37 CDT 2019
On 5/19/19 10:58 PM, Micah N Gorrell wrote:
> On Sun, May 19, 2019 at 02:08:26PM +0800, Zhiyi Zhang wrote:
>>
>> On 5/19/19 5:43 AM, Micah N Gorrell wrote:
>>> Signed-off-by: Micah N Gorrell <mgorrell at codeweavers.com>
>>> ---
>>> dlls/user32/tests/Makefile.in | 1 +
>>> dlls/user32/tests/misc.c | 89 +++++++++++++++++++++++++++++++++++
>>> 2 files changed, 90 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..c0a4af6636
>>> --- /dev/null
>>> +++ b/dlls/user32/tests/misc.c
>>> @@ -0,0 +1,89 @@
>>> +/*
>>> + * 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 } };
>> Hi Micah,
>>
>> You could just include hidclass.h to get GUID_DEVINTERFACE_HID.
>> And testbots are failing. You need to fix the tests.
>>
> Just including hidclass.h does not appear to be sufficient since it is an extern
> and the user32 tests do not link with hid. What is the right way to handle this
> from a test like this?
Adding #include "initguid.h" should resolve it.
>
>>> +
>>> + 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));
>>> +
>> Unnecessary white lines and same in below.
>>> + dbh.dbcc_size = sizeof(dbh);
>>> + dbh.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
>>> + dbh.dbcc_classguid = GUID_DEVINTERFACE_HID;
>>> +
>>> + /* Test RegisterDeviceNotification behavior */
>>> + hnotify1 = RegisterDeviceNotificationW( NULL, &dbh, DEVICE_NOTIFY_WINDOW_HANDLE );
>>> + ok( hnotify1 != 0, "RegisterDeviceNotificationW failed when called with a NULL recipient window handle\n" );
>>> +
>>> + 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" );
>>> +
>>> + UnregisterDeviceNotification( hnotify1 );
>>> + UnregisterDeviceNotification( hnotify2 );
>>> +
>>> +
>>> + hnotify1 = RegisterDeviceNotificationW( hwnd, &dbh, 0xffff );
>>> + ok( hnotify1 == 0, "RegisterDeviceNotificationW accepted invalid flags\n" );
>>> +
>>> +
>>> + ok( !UnregisterDeviceNotification( hnotify1 ), "UnregisterDeviceNotification succeeded with an already released handle\n" );
>>> + ok( !UnregisterDeviceNotification( NULL ), "UnregisterDeviceNotification succeeded with NULL handle\n" );
>>> +
>>> + /* FIXME: Find a way to trigger a device notification for testing */
>>> +
>>> + DestroyWindow(hwnd);
>>> +}
>>> +
>>> +
>>> +START_TEST(misc)
>>> +{
>>> + RegisterDeviceNotificationTest();
>>> +}
>>> +
More information about the wine-devel
mailing list