mirror of
git://source.winehq.org/git/wine.git
synced 2024-10-14 23:47:16 +00:00
user32/tests: Add more parameter checks for SetWindowsHookExA().
This commit is contained in:
parent
6af8b70409
commit
d2284bb6df
|
@ -1,7 +1,9 @@
|
|||
TESTDLL = user32.dll
|
||||
IMPORTS = user32 gdi32 advapi32 hid imm32 setupapi
|
||||
|
||||
C_SRCS = \
|
||||
testdll_IMPORTS = user32
|
||||
|
||||
SOURCES = \
|
||||
broadcast.c \
|
||||
class.c \
|
||||
clipboard.c \
|
||||
|
@ -18,13 +20,14 @@ C_SRCS = \
|
|||
monitor.c \
|
||||
msg.c \
|
||||
resource.c \
|
||||
resource.rc \
|
||||
scroll.c \
|
||||
static.c \
|
||||
sysparams.c \
|
||||
testdll.c \
|
||||
testdll.spec \
|
||||
text.c \
|
||||
uitools.c \
|
||||
win.c \
|
||||
winstation.c \
|
||||
wsprintf.c
|
||||
|
||||
RC_SRCS = resource.rc
|
||||
|
|
|
@ -12223,11 +12223,41 @@ skip_mouse_ll_hook_test:
|
|||
ok(DestroyWindow(hwnd), "failed to destroy window\n");
|
||||
}
|
||||
|
||||
static char *get_test_dll_path(void)
|
||||
{
|
||||
static const char *dll_name = "testdll.dll";
|
||||
static char path[MAX_PATH];
|
||||
DWORD written;
|
||||
HANDLE file;
|
||||
HRSRC res;
|
||||
void *ptr;
|
||||
|
||||
GetTempPathA(ARRAY_SIZE(path), path);
|
||||
strcat(path, dll_name);
|
||||
|
||||
file = CreateFileA(path, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0);
|
||||
ok(file != INVALID_HANDLE_VALUE, "Failed to create file %s: %lu.\n", debugstr_a(path), GetLastError());
|
||||
|
||||
res = FindResourceA(NULL, dll_name, "TESTDLL");
|
||||
ok(!!res, "Failed to load resource: %lu\n", GetLastError());
|
||||
ptr = LockResource(LoadResource(GetModuleHandleA(NULL), res));
|
||||
WriteFile(file, ptr, SizeofResource(GetModuleHandleA(NULL), res), &written, NULL);
|
||||
ok(written == SizeofResource(GetModuleHandleA(NULL), res), "Failed to write resource\n");
|
||||
CloseHandle(file);
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
static void test_set_hook(void)
|
||||
{
|
||||
LRESULT (CALLBACK *p_dummy_hook_proc)(int code, WPARAM wp, LPARAM lp);
|
||||
HMODULE test_dll_module;
|
||||
char *test_dll_path;
|
||||
DWORD error;
|
||||
BOOL ret;
|
||||
HHOOK hhook;
|
||||
HWINEVENTHOOK hwinevent_hook;
|
||||
int i;
|
||||
|
||||
hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, GetModuleHandleA(0), GetCurrentThreadId());
|
||||
ok(hhook != 0, "local hook does not require hModule set to 0\n");
|
||||
|
@ -12253,6 +12283,58 @@ static void test_set_hook(void)
|
|||
ok(!UnhookWindowsHookEx((HHOOK)0xdeadbeef), "UnhookWindowsHookEx succeeded\n");
|
||||
ok(GetLastError() == ERROR_INVALID_HOOK_HANDLE, "unexpected error %ld\n", GetLastError());
|
||||
|
||||
test_dll_path = get_test_dll_path();
|
||||
test_dll_module = LoadLibraryA(test_dll_path);
|
||||
p_dummy_hook_proc = (void *)GetProcAddress(test_dll_module, "dummy_hook_proc");
|
||||
for (i = WH_MIN; i <= WH_MAX; i++)
|
||||
{
|
||||
winetest_push_context("ID %d", i);
|
||||
|
||||
/* Test that setting hooks should succeed for hook procs in a library. But for WH_JOURNALRECORD
|
||||
* and WH_JOURNALPLAYBACK, ERROR_ACCESS_DENIED is returned, even with administrator rights */
|
||||
SetLastError(0xdeadbeef);
|
||||
hhook = SetWindowsHookExA(i, p_dummy_hook_proc, test_dll_module, 0);
|
||||
error = GetLastError();
|
||||
if (i == WH_JOURNALRECORD || i == WH_JOURNALPLAYBACK)
|
||||
{
|
||||
todo_wine
|
||||
ok(!hhook, "SetWinEventHook succeeded.\n");
|
||||
todo_wine
|
||||
ok(error == ERROR_ACCESS_DENIED, "Got unexpected error %ld.\n", GetLastError());
|
||||
}
|
||||
else
|
||||
{
|
||||
ok(!!hhook, "SetWinEventHook failed.\n");
|
||||
ok(error == NO_ERROR, "Got unexpected error %ld.\n", GetLastError());
|
||||
}
|
||||
if (hhook)
|
||||
UnhookWindowsHookEx(hhook);
|
||||
|
||||
/* Test settings global hooks with a thread ID */
|
||||
SetLastError(0xdeadbeef);
|
||||
hhook = SetWindowsHookExA(i, p_dummy_hook_proc, test_dll_module, GetCurrentThreadId());
|
||||
error = GetLastError();
|
||||
if (i == WH_JOURNALRECORD || i == WH_JOURNALPLAYBACK || i == WH_SYSMSGFILTER
|
||||
|| i == WH_KEYBOARD_LL || i == WH_MOUSE_LL)
|
||||
{
|
||||
ok(!hhook, "SetWinEventHook succeeded.\n");
|
||||
todo_wine
|
||||
ok(error == ERROR_GLOBAL_ONLY_HOOK, "Got unexpected error %ld.\n", GetLastError());
|
||||
}
|
||||
else
|
||||
{
|
||||
ok(!!hhook, "SetWinEventHook failed.\n");
|
||||
ok(error == NO_ERROR, "Got unexpected error %ld.\n", GetLastError());
|
||||
}
|
||||
if (hhook)
|
||||
UnhookWindowsHookEx(hhook);
|
||||
|
||||
winetest_pop_context();
|
||||
}
|
||||
FreeLibrary(test_dll_module);
|
||||
ret = DeleteFileA(test_dll_path);
|
||||
ok(ret, "Failed to remove the test dll, error %ld.\n", GetLastError());
|
||||
|
||||
if (!pSetWinEventHook || !pUnhookWinEvent) return;
|
||||
|
||||
/* even process local incontext hooks require hmodule */
|
||||
|
|
32
dlls/user32/tests/testdll.c
Normal file
32
dlls/user32/tests/testdll.c
Normal file
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* Copyright 2023 Zhiyi Zhang for CodeWeavers
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#if 0
|
||||
#pragma makedep testdll
|
||||
#endif
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
#include <windef.h>
|
||||
#include <winbase.h>
|
||||
#include <winuser.h>
|
||||
|
||||
LRESULT CALLBACK dummy_hook_proc(int code, WPARAM wp, LPARAM lp)
|
||||
{
|
||||
return CallNextHookEx(0, code, wp, lp);
|
||||
}
|
1
dlls/user32/tests/testdll.spec
Normal file
1
dlls/user32/tests/testdll.spec
Normal file
|
@ -0,0 +1 @@
|
|||
@ stdcall dummy_hook_proc(long ptr ptr)
|
Loading…
Reference in a new issue