Skip to content

Commit a6fe061

Browse files
zzhiyirbernon
authored andcommitted
user32/tests: Add some ReleaseCapture() tests.
(cherry picked from commit d47b13c) CW-Bug-Id: #23531
1 parent 1dce5ba commit a6fe061

File tree

1 file changed

+108
-0
lines changed

1 file changed

+108
-0
lines changed

dlls/user32/tests/win.c

+108
Original file line numberDiff line numberDiff line change
@@ -13030,6 +13030,113 @@ static void test_WM_NCCALCSIZE(void)
1303013030
DestroyWindow(hwnd);
1303113031
}
1303213032

13033+
#define TRAY_MINIMIZE_ALL 419
13034+
#define TRAY_MINIMIZE_ALL_UNDO 416
13035+
13036+
static void test_shell_tray(void)
13037+
{
13038+
HWND hwnd, traywnd;
13039+
13040+
if (!(traywnd = FindWindowA( "Shell_TrayWnd", NULL )))
13041+
{
13042+
skip( "Shell_TrayWnd not found, skipping tests.\n" );
13043+
return;
13044+
}
13045+
13046+
hwnd = CreateWindowW( L"static", L"parent", WS_OVERLAPPEDWINDOW|WS_VISIBLE,
13047+
100, 100, 200, 200, 0, 0, 0, NULL );
13048+
ok( !!hwnd, "failed, error %lu.\n", GetLastError() );
13049+
flush_events( TRUE );
13050+
13051+
ok( !IsIconic( hwnd ), "window is minimized.\n" );
13052+
13053+
SendMessageA( traywnd, WM_COMMAND, TRAY_MINIMIZE_ALL, 0xdeadbeef );
13054+
flush_events( TRUE );
13055+
todo_wine ok( IsIconic( hwnd ), "window is not minimized.\n" );
13056+
13057+
SendMessageA( traywnd, WM_COMMAND, TRAY_MINIMIZE_ALL_UNDO, 0xdeadbeef );
13058+
flush_events( TRUE );
13059+
ok( !IsIconic( hwnd ), "window is minimized.\n" );
13060+
13061+
DestroyWindow(hwnd);
13062+
}
13063+
13064+
static int wm_mousemove_count;
13065+
static BOOL do_release_capture;
13066+
13067+
static LRESULT WINAPI test_ReleaseCapture_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
13068+
{
13069+
if (msg == WM_MOUSEMOVE)
13070+
{
13071+
wm_mousemove_count++;
13072+
if (wm_mousemove_count >= 100)
13073+
return 1;
13074+
13075+
if (do_release_capture)
13076+
ReleaseCapture();
13077+
return 0;
13078+
}
13079+
return DefWindowProcA(hwnd, msg, wp, lp);
13080+
}
13081+
13082+
static void test_ReleaseCapture(void)
13083+
{
13084+
WNDCLASSA cls = {0};
13085+
ATOM atom;
13086+
HWND hwnd;
13087+
POINT pt;
13088+
BOOL ret;
13089+
13090+
cls.lpfnWndProc = test_ReleaseCapture_proc;
13091+
cls.hInstance = GetModuleHandleA(0);
13092+
cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
13093+
cls.hbrBackground = GetStockObject(BLACK_BRUSH);
13094+
cls.lpszClassName = "test_ReleaseCapture_class";
13095+
atom = RegisterClassA(&cls);
13096+
ok(!!atom, "RegisterClassA failed, error %#lx.\n", GetLastError());
13097+
13098+
hwnd = CreateWindowExA(WS_EX_TOPMOST, cls.lpszClassName, "", WS_POPUP | WS_VISIBLE, 100, 100,
13099+
100, 100, NULL, NULL, 0, NULL);
13100+
ok(!!hwnd, "CreateWindowA failed, error %#lx.\n", GetLastError());
13101+
ret = SetForegroundWindow(hwnd);
13102+
ok(ret, "SetForegroundWindow failed, error %#lx.\n", GetLastError());
13103+
GetCursorPos(&pt);
13104+
ret = SetCursorPos(150, 150);
13105+
ok(ret, "SetCursorPos failed, error %#lx.\n", GetLastError());
13106+
flush_events(TRUE);
13107+
13108+
/* Test a Wine bug that WM_MOUSEMOVE is post too many times when calling ReleaseCapture() during
13109+
* handling WM_MOUSEMOVE and the cursor is on the window */
13110+
do_release_capture = TRUE;
13111+
ret = ReleaseCapture();
13112+
ok(ret, "ReleaseCapture failed, error %#lx.\n", GetLastError());
13113+
flush_events(TRUE);
13114+
do_release_capture = FALSE;
13115+
todo_wine
13116+
ok(wm_mousemove_count < 10, "Got too many WM_MOUSEMOVE.\n");
13117+
13118+
/* Test that ReleaseCapture() should send a WM_MOUSEMOVE if a window is captured */
13119+
SetCapture(hwnd);
13120+
wm_mousemove_count = 0;
13121+
ret = ReleaseCapture();
13122+
ok(ret, "ReleaseCapture failed, error %#lx.\n", GetLastError());
13123+
flush_events(TRUE);
13124+
ok(wm_mousemove_count == 1, "Got no WM_MOUSEMOVE.\n");
13125+
13126+
/* Test that ReleaseCapture() shouldn't send WM_MOUSEMOVE if no window is captured */
13127+
wm_mousemove_count = 0;
13128+
ret = ReleaseCapture();
13129+
ok(ret, "ReleaseCapture failed, error %#lx.\n", GetLastError());
13130+
flush_events(TRUE);
13131+
todo_wine
13132+
ok(wm_mousemove_count == 0, "Got WM_MOUSEMOVE.\n");
13133+
13134+
ret = SetCursorPos(pt.x, pt.y);
13135+
ok(ret, "SetCursorPos failed, error %#lx.\n", GetLastError());
13136+
DestroyWindow(hwnd);
13137+
UnregisterClassA(cls.lpszClassName, GetModuleHandleA(0));
13138+
}
13139+
1303313140
START_TEST(win)
1303413141
{
1303513142
char **argv;
@@ -13212,6 +13319,7 @@ START_TEST(win)
1321213319
test_cancel_mode();
1321313320
test_DragDetect();
1321413321
test_WM_NCCALCSIZE();
13322+
test_ReleaseCapture();
1321513323

1321613324
/* add the tests above this line */
1321713325
if (hhook) UnhookWindowsHookEx(hhook);

0 commit comments

Comments
 (0)