Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wine-winehq
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wine
wine-winehq
Commits
d2284bb6
Commit
d2284bb6
authored
Oct 25, 2023
by
Zhiyi Zhang
Committed by
Alexandre Julliard
Oct 30, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
user32/tests: Add more parameter checks for SetWindowsHookExA().
parent
6af8b704
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
121 additions
and
3 deletions
+121
-3
Makefile.in
dlls/user32/tests/Makefile.in
+6
-3
msg.c
dlls/user32/tests/msg.c
+82
-0
testdll.c
dlls/user32/tests/testdll.c
+32
-0
testdll.spec
dlls/user32/tests/testdll.spec
+1
-0
No files found.
dlls/user32/tests/Makefile.in
View file @
d2284bb6
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
dlls/user32/tests/msg.c
View file @
d2284bb6
...
...
@@ -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 */
...
...
dlls/user32/tests/testdll.c
0 → 100644
View file @
d2284bb6
/*
* 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
);
}
dlls/user32/tests/testdll.spec
0 → 100644
View file @
d2284bb6
@ stdcall dummy_hook_proc(long ptr ptr)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment