mirror of
https://github.com/reactos/reactos.git
synced 2025-08-03 22:56:00 +00:00
[USER32_APITEST] Add SetFocus testcase (#3732)
Investigate about setting keyboard focus. CORE-17550
This commit is contained in:
parent
d220ea3e3c
commit
94d9e9c2a8
4 changed files with 232 additions and 0 deletions
|
@ -38,6 +38,7 @@ list(APPEND SOURCE
|
||||||
SendMessageTimeout.c
|
SendMessageTimeout.c
|
||||||
SetActiveWindow.c
|
SetActiveWindow.c
|
||||||
SetCursorPos.c
|
SetCursorPos.c
|
||||||
|
SetFocus.c
|
||||||
SetParent.c
|
SetParent.c
|
||||||
SetProp.c
|
SetProp.c
|
||||||
SetScrollInfo.c
|
SetScrollInfo.c
|
||||||
|
|
219
modules/rostests/apitests/user32/SetFocus.c
Normal file
219
modules/rostests/apitests/user32/SetFocus.c
Normal file
|
@ -0,0 +1,219 @@
|
||||||
|
/*
|
||||||
|
* PROJECT: ReactOS API tests
|
||||||
|
* LICENSE: LGPL-2.1+ (https://spdx.org/licenses/LGPL-2.1+)
|
||||||
|
* PURPOSE: Test for SetFocus/GetFocus/GetGUIThreadInfo
|
||||||
|
* COPYRIGHT: Copyright 2021 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "precomp.h"
|
||||||
|
#include <dlgs.h> // psh1, ...
|
||||||
|
#include <process.h>
|
||||||
|
|
||||||
|
#define INTERVAL 80
|
||||||
|
|
||||||
|
static DWORD s_dwMainThreadID;
|
||||||
|
|
||||||
|
static HWND GetMainThreadFocus(void)
|
||||||
|
{
|
||||||
|
GUITHREADINFO gui = { sizeof(gui) };
|
||||||
|
GetGUIThreadInfo(s_dwMainThreadID, &gui);
|
||||||
|
return gui.hwndFocus;
|
||||||
|
}
|
||||||
|
|
||||||
|
static unsigned __stdcall thread_proc_0(void *arg)
|
||||||
|
{
|
||||||
|
HWND hwnd = arg;
|
||||||
|
|
||||||
|
ok_int(GetFocus() == NULL, TRUE);
|
||||||
|
ok_int(GetMainThreadFocus() == GetDlgItem(hwnd, IDOK), TRUE);
|
||||||
|
SendMessageA(hwnd, WM_NEXTDLGCTL, FALSE, FALSE);
|
||||||
|
|
||||||
|
ok_int(GetFocus() == NULL, TRUE);
|
||||||
|
ok_int(GetMainThreadFocus() == GetDlgItem(hwnd, IDCANCEL), TRUE);
|
||||||
|
SendMessageA(hwnd, WM_NEXTDLGCTL, FALSE, FALSE);
|
||||||
|
|
||||||
|
ok_int(GetFocus() == NULL, TRUE);
|
||||||
|
ok_int(GetMainThreadFocus() == GetDlgItem(hwnd, psh1), TRUE);
|
||||||
|
SendMessageA(hwnd, WM_NEXTDLGCTL, FALSE, FALSE);
|
||||||
|
|
||||||
|
ok_int(GetFocus() == NULL, TRUE);
|
||||||
|
ok_int(GetMainThreadFocus() == GetDlgItem(hwnd, IDOK), TRUE);
|
||||||
|
SendMessageA(hwnd, WM_NEXTDLGCTL, TRUE, FALSE);
|
||||||
|
|
||||||
|
ok_int(GetFocus() == NULL, TRUE);
|
||||||
|
ok_int(GetMainThreadFocus() == GetDlgItem(hwnd, psh1), TRUE);
|
||||||
|
keybd_event(VK_TAB, KEYEVENTF_KEYUP, 0, 0);
|
||||||
|
Sleep(INTERVAL);
|
||||||
|
|
||||||
|
ok_int(GetFocus() == NULL, TRUE);
|
||||||
|
ok_int(GetMainThreadFocus() == GetDlgItem(hwnd, IDOK), TRUE);
|
||||||
|
keybd_event(VK_TAB, KEYEVENTF_KEYUP, 0, 0);
|
||||||
|
Sleep(INTERVAL);
|
||||||
|
|
||||||
|
ok_int(GetFocus() == NULL, TRUE);
|
||||||
|
ok_int(GetMainThreadFocus() == GetDlgItem(hwnd, IDCANCEL), TRUE);
|
||||||
|
keybd_event(VK_TAB, KEYEVENTF_KEYUP, 0, 0);
|
||||||
|
Sleep(INTERVAL);
|
||||||
|
|
||||||
|
ok_int(GetFocus() == NULL, TRUE);
|
||||||
|
ok_int(GetMainThreadFocus() == GetDlgItem(hwnd, psh1), TRUE);
|
||||||
|
keybd_event(VK_TAB, KEYEVENTF_KEYUP, 0, 0);
|
||||||
|
Sleep(INTERVAL);
|
||||||
|
|
||||||
|
ok_int(GetFocus() == NULL, TRUE);
|
||||||
|
ok_int(GetMainThreadFocus() == GetDlgItem(hwnd, IDOK), TRUE);
|
||||||
|
|
||||||
|
PostMessageA(hwnd, WM_COMMAND, psh3, 0);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static unsigned __stdcall thread_proc_1(void *arg)
|
||||||
|
{
|
||||||
|
HWND hwnd = arg;
|
||||||
|
|
||||||
|
ok_int(GetFocus() == NULL, TRUE);
|
||||||
|
ok_int(GetMainThreadFocus() == NULL, TRUE);
|
||||||
|
keybd_event(VK_TAB, KEYEVENTF_KEYUP, 0, 0);
|
||||||
|
Sleep(INTERVAL);
|
||||||
|
|
||||||
|
ok_int(GetFocus() == NULL, TRUE);
|
||||||
|
ok_int(GetMainThreadFocus() == NULL, TRUE);
|
||||||
|
keybd_event(VK_TAB, KEYEVENTF_KEYUP, 0, 0);
|
||||||
|
Sleep(INTERVAL);
|
||||||
|
|
||||||
|
ok_int(GetFocus() == NULL, TRUE);
|
||||||
|
ok_int(GetMainThreadFocus() == NULL, TRUE);
|
||||||
|
|
||||||
|
PostMessageA(hwnd, WM_COMMAND, psh3, 0);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static unsigned __stdcall thread_proc_2(void *arg)
|
||||||
|
{
|
||||||
|
HWND hwnd = arg;
|
||||||
|
|
||||||
|
ok_int(GetFocus() == NULL, TRUE);
|
||||||
|
ok_int(GetMainThreadFocus() == GetDlgItem(hwnd, IDCANCEL), TRUE);
|
||||||
|
keybd_event(VK_TAB, KEYEVENTF_KEYUP, 0, 0);
|
||||||
|
Sleep(INTERVAL);
|
||||||
|
|
||||||
|
ok_int(GetFocus() == NULL, TRUE);
|
||||||
|
ok_int(GetMainThreadFocus() == GetDlgItem(hwnd, psh1), TRUE);
|
||||||
|
keybd_event(VK_TAB, KEYEVENTF_KEYUP, 0, 0);
|
||||||
|
Sleep(INTERVAL);
|
||||||
|
|
||||||
|
ok_int(GetFocus() == NULL, TRUE);
|
||||||
|
ok_int(GetMainThreadFocus() == GetDlgItem(hwnd, IDOK), TRUE);
|
||||||
|
keybd_event(VK_TAB, KEYEVENTF_KEYUP, 0, 0);
|
||||||
|
Sleep(INTERVAL);
|
||||||
|
|
||||||
|
PostMessageA(hwnd, WM_COMMAND, psh4, 0);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static INT_PTR CALLBACK
|
||||||
|
DialogProc_0(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||||
|
{
|
||||||
|
HANDLE hThread;
|
||||||
|
switch (uMsg)
|
||||||
|
{
|
||||||
|
case WM_INITDIALOG:
|
||||||
|
ok_int(GetFocus() == NULL, TRUE);
|
||||||
|
SetFocus(GetDlgItem(hwnd, IDOK));
|
||||||
|
ok_int(GetFocus() == GetDlgItem(hwnd, IDOK), TRUE);
|
||||||
|
SendMessageA(hwnd, WM_NEXTDLGCTL, FALSE, FALSE);
|
||||||
|
|
||||||
|
ok_int(GetFocus() == GetDlgItem(hwnd, IDCANCEL), TRUE);
|
||||||
|
SendMessageA(hwnd, WM_NEXTDLGCTL, TRUE, FALSE);
|
||||||
|
|
||||||
|
ok_int(GetFocus() == GetDlgItem(hwnd, IDOK), TRUE);
|
||||||
|
SendMessageA(hwnd, WM_NEXTDLGCTL, FALSE, FALSE);
|
||||||
|
|
||||||
|
ok_int(GetFocus() == GetDlgItem(hwnd, IDCANCEL), TRUE);
|
||||||
|
SendMessageA(hwnd, WM_NEXTDLGCTL, FALSE, FALSE);
|
||||||
|
|
||||||
|
ok_int(GetFocus() == GetDlgItem(hwnd, psh1), TRUE);
|
||||||
|
SendMessageA(hwnd, WM_NEXTDLGCTL, FALSE, FALSE);
|
||||||
|
|
||||||
|
ok_int(GetFocus() == GetDlgItem(hwnd, IDOK), TRUE);
|
||||||
|
SetFocus(GetDlgItem(hwnd, IDCANCEL));
|
||||||
|
PostMessageA(hwnd, WM_COMMAND, psh2, 0);
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
case WM_COMMAND:
|
||||||
|
switch (LOWORD(wParam))
|
||||||
|
{
|
||||||
|
case psh2:
|
||||||
|
ok_int(GetFocus() == GetDlgItem(hwnd, IDOK), TRUE);
|
||||||
|
hThread = (HANDLE)_beginthreadex(NULL, 0, thread_proc_0, hwnd, 0, NULL);
|
||||||
|
CloseHandle(hThread);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case psh3:
|
||||||
|
ok_int(GetFocus() == GetDlgItem(hwnd, IDOK), TRUE);
|
||||||
|
EndDialog(hwnd, IDCLOSE);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static INT_PTR CALLBACK
|
||||||
|
DialogProc_1(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||||
|
{
|
||||||
|
HANDLE hThread;
|
||||||
|
switch (uMsg)
|
||||||
|
{
|
||||||
|
case WM_INITDIALOG:
|
||||||
|
SetFocus(GetDlgItem(hwnd, IDCANCEL));
|
||||||
|
PostMessageA(hwnd, WM_COMMAND, psh2, 0);
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
case WM_COMMAND:
|
||||||
|
switch (LOWORD(wParam))
|
||||||
|
{
|
||||||
|
case psh2:
|
||||||
|
ok_int(GetFocus() == GetDlgItem(hwnd, IDCANCEL), TRUE);
|
||||||
|
EnableWindow(GetDlgItem(hwnd, IDCANCEL), FALSE);
|
||||||
|
ok_int(GetFocus() == NULL, TRUE);
|
||||||
|
|
||||||
|
hThread = (HANDLE)_beginthreadex(NULL, 0, thread_proc_1, hwnd, 0, NULL);
|
||||||
|
CloseHandle(hThread);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case psh3:
|
||||||
|
ok_int(GetFocus() == NULL, TRUE);
|
||||||
|
EnableWindow(GetDlgItem(hwnd, IDCANCEL), TRUE);
|
||||||
|
|
||||||
|
ok_int(GetFocus() == NULL, TRUE);
|
||||||
|
SetFocus(GetDlgItem(hwnd, IDCANCEL));
|
||||||
|
ok_int(GetFocus() == GetDlgItem(hwnd, IDCANCEL), TRUE);
|
||||||
|
|
||||||
|
hThread = (HANDLE)_beginthreadex(NULL, 0, thread_proc_2, hwnd, 0, NULL);
|
||||||
|
CloseHandle(hThread);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case psh4:
|
||||||
|
ok_int(GetFocus() == GetDlgItem(hwnd, IDCANCEL), TRUE);
|
||||||
|
ShowWindow(GetDlgItem(hwnd, IDCANCEL), SW_HIDE);
|
||||||
|
|
||||||
|
ok_int(GetFocus() == GetDlgItem(hwnd, IDOK), TRUE);
|
||||||
|
ShowWindow(GetDlgItem(hwnd, IDCANCEL), SW_SHOW);
|
||||||
|
|
||||||
|
ok_int(GetFocus() == GetDlgItem(hwnd, IDOK), TRUE);
|
||||||
|
EndDialog(hwnd, IDCLOSE);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
START_TEST(SetFocus)
|
||||||
|
{
|
||||||
|
s_dwMainThreadID = GetCurrentThreadId();
|
||||||
|
Sleep(INTERVAL);
|
||||||
|
ok_int((INT)DialogBoxA(GetModuleHandleA(NULL), "SETFOCUS", NULL, DialogProc_0), IDCLOSE);
|
||||||
|
ok_int((INT)DialogBoxA(GetModuleHandleA(NULL), "SETFOCUS", NULL, DialogProc_1), IDCLOSE);
|
||||||
|
}
|
|
@ -40,6 +40,7 @@ extern void func_ScrollWindowEx(void);
|
||||||
extern void func_SendMessageTimeout(void);
|
extern void func_SendMessageTimeout(void);
|
||||||
extern void func_SetActiveWindow(void);
|
extern void func_SetActiveWindow(void);
|
||||||
extern void func_SetCursorPos(void);
|
extern void func_SetCursorPos(void);
|
||||||
|
extern void func_SetFocus(void);
|
||||||
extern void func_SetParent(void);
|
extern void func_SetParent(void);
|
||||||
extern void func_SetProp(void);
|
extern void func_SetProp(void);
|
||||||
extern void func_SetScrollInfo(void);
|
extern void func_SetScrollInfo(void);
|
||||||
|
@ -90,6 +91,7 @@ const struct test winetest_testlist[] =
|
||||||
{ "SendMessageTimeout", func_SendMessageTimeout },
|
{ "SendMessageTimeout", func_SendMessageTimeout },
|
||||||
{ "SetActiveWindow", func_SetActiveWindow },
|
{ "SetActiveWindow", func_SetActiveWindow },
|
||||||
{ "SetCursorPos", func_SetCursorPos },
|
{ "SetCursorPos", func_SetCursorPos },
|
||||||
|
{ "SetFocus", func_SetFocus },
|
||||||
{ "SetParent", func_SetParent },
|
{ "SetParent", func_SetParent },
|
||||||
{ "SetProp", func_SetProp },
|
{ "SetProp", func_SetProp },
|
||||||
{ "SetScrollInfo", func_SetScrollInfo },
|
{ "SetScrollInfo", func_SetScrollInfo },
|
||||||
|
|
|
@ -38,3 +38,13 @@ CAPTION "DM_REPOSITION"
|
||||||
FONT 8, "MS Shell Dlg"
|
FONT 8, "MS Shell Dlg"
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SETFOCUS DIALOG 0, 0, 175, 101
|
||||||
|
CAPTION "user32_apitest SetFocus"
|
||||||
|
STYLE DS_CENTER | DS_MODALFRAME | WS_POPUPWINDOW | WS_CAPTION
|
||||||
|
FONT 9, "MS Shell Dlg"
|
||||||
|
{
|
||||||
|
DEFPUSHBUTTON "OK", IDOK, 14, 23, 60, 14
|
||||||
|
PUSHBUTTON "Cancel", IDCANCEL, 42, 45, 60, 14
|
||||||
|
PUSHBUTTON "psh1", psh1, 75, 73, 60, 14
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue