Skip to content

Commit

Permalink
user32/tests: Add some ReleaseCapture() tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
zzhiyi authored and julliard committed Mar 8, 2024
1 parent c51c257 commit d47b13c
Showing 1 changed file with 77 additions and 0 deletions.
77 changes: 77 additions & 0 deletions dlls/user32/tests/win.c
Original file line number Diff line number Diff line change
Expand Up @@ -13064,6 +13064,82 @@ static void test_shell_tray(void)
DestroyWindow(hwnd);
}

static int wm_mousemove_count;
static BOOL do_release_capture;

static LRESULT WINAPI test_ReleaseCapture_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
{
if (msg == WM_MOUSEMOVE)
{
wm_mousemove_count++;
if (wm_mousemove_count >= 100)
return 1;

if (do_release_capture)
ReleaseCapture();
return 0;
}
return DefWindowProcA(hwnd, msg, wp, lp);
}

static void test_ReleaseCapture(void)
{
WNDCLASSA cls = {0};
ATOM atom;
HWND hwnd;
POINT pt;
BOOL ret;

cls.lpfnWndProc = test_ReleaseCapture_proc;
cls.hInstance = GetModuleHandleA(0);
cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
cls.hbrBackground = GetStockObject(BLACK_BRUSH);
cls.lpszClassName = "test_ReleaseCapture_class";
atom = RegisterClassA(&cls);
ok(!!atom, "RegisterClassA failed, error %#lx.\n", GetLastError());

hwnd = CreateWindowExA(WS_EX_TOPMOST, cls.lpszClassName, "", WS_POPUP | WS_VISIBLE, 100, 100,
100, 100, NULL, NULL, 0, NULL);
ok(!!hwnd, "CreateWindowA failed, error %#lx.\n", GetLastError());
ret = SetForegroundWindow(hwnd);
ok(ret, "SetForegroundWindow failed, error %#lx.\n", GetLastError());
GetCursorPos(&pt);
ret = SetCursorPos(150, 150);
ok(ret, "SetCursorPos failed, error %#lx.\n", GetLastError());
flush_events(TRUE);

/* Test a Wine bug that WM_MOUSEMOVE is post too many times when calling ReleaseCapture() during
* handling WM_MOUSEMOVE and the cursor is on the window */
do_release_capture = TRUE;
ret = ReleaseCapture();
ok(ret, "ReleaseCapture failed, error %#lx.\n", GetLastError());
flush_events(TRUE);
do_release_capture = FALSE;
todo_wine
ok(wm_mousemove_count < 10, "Got too many WM_MOUSEMOVE.\n");

/* Test that ReleaseCapture() should send a WM_MOUSEMOVE if a window is captured */
SetCapture(hwnd);
wm_mousemove_count = 0;
ret = ReleaseCapture();
ok(ret, "ReleaseCapture failed, error %#lx.\n", GetLastError());
flush_events(TRUE);
ok(wm_mousemove_count == 1, "Got no WM_MOUSEMOVE.\n");

/* Test that ReleaseCapture() shouldn't send WM_MOUSEMOVE if no window is captured */
wm_mousemove_count = 0;
ret = ReleaseCapture();
ok(ret, "ReleaseCapture failed, error %#lx.\n", GetLastError());
flush_events(TRUE);
todo_wine
ok(wm_mousemove_count == 0, "Got WM_MOUSEMOVE.\n");

ret = SetCursorPos(pt.x, pt.y);
ok(ret, "SetCursorPos failed, error %#lx.\n", GetLastError());
DestroyWindow(hwnd);
UnregisterClassA(cls.lpszClassName, GetModuleHandleA(0));
}

START_TEST(win)
{
char **argv;
Expand Down Expand Up @@ -13246,6 +13322,7 @@ START_TEST(win)
test_cancel_mode();
test_DragDetect();
test_WM_NCCALCSIZE();
test_ReleaseCapture();

/* add the tests above this line */
if (hhook) UnhookWindowsHookEx(hhook);
Expand Down

0 comments on commit d47b13c

Please sign in to comment.