https://git.reactos.org/?p=reactos.git;a=commitdiff;h=94d9e9c2a8d6436b6f1e5…
commit 94d9e9c2a8d6436b6f1e50e5180acf19f74f60e0
Author: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com>
AuthorDate: Wed Jun 9 16:14:31 2021 +0900
Commit: GitHub <noreply(a)github.com>
CommitDate: Wed Jun 9 16:14:31 2021 +0900
[USER32_APITEST] Add SetFocus testcase (#3732)
Investigate about setting keyboard focus. CORE-17550
---
modules/rostests/apitests/user32/CMakeLists.txt | 1 +
modules/rostests/apitests/user32/SetFocus.c | 219 +++++++++++++++++++++
modules/rostests/apitests/user32/testlist.c | 2 +
modules/rostests/apitests/user32/user32_apitest.rc | 10 +
4 files changed, 232 insertions(+)
diff --git a/modules/rostests/apitests/user32/CMakeLists.txt
b/modules/rostests/apitests/user32/CMakeLists.txt
index f0dca068549..99d7b4d3168 100644
--- a/modules/rostests/apitests/user32/CMakeLists.txt
+++ b/modules/rostests/apitests/user32/CMakeLists.txt
@@ -38,6 +38,7 @@ list(APPEND SOURCE
SendMessageTimeout.c
SetActiveWindow.c
SetCursorPos.c
+ SetFocus.c
SetParent.c
SetProp.c
SetScrollInfo.c
diff --git a/modules/rostests/apitests/user32/SetFocus.c
b/modules/rostests/apitests/user32/SetFocus.c
new file mode 100644
index 00000000000..3c6e78302ca
--- /dev/null
+++ b/modules/rostests/apitests/user32/SetFocus.c
@@ -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(a)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);
+}
diff --git a/modules/rostests/apitests/user32/testlist.c
b/modules/rostests/apitests/user32/testlist.c
index b4ef3e04e4c..26325af0571 100644
--- a/modules/rostests/apitests/user32/testlist.c
+++ b/modules/rostests/apitests/user32/testlist.c
@@ -40,6 +40,7 @@ extern void func_ScrollWindowEx(void);
extern void func_SendMessageTimeout(void);
extern void func_SetActiveWindow(void);
extern void func_SetCursorPos(void);
+extern void func_SetFocus(void);
extern void func_SetParent(void);
extern void func_SetProp(void);
extern void func_SetScrollInfo(void);
@@ -90,6 +91,7 @@ const struct test winetest_testlist[] =
{ "SendMessageTimeout", func_SendMessageTimeout },
{ "SetActiveWindow", func_SetActiveWindow },
{ "SetCursorPos", func_SetCursorPos },
+ { "SetFocus", func_SetFocus },
{ "SetParent", func_SetParent },
{ "SetProp", func_SetProp },
{ "SetScrollInfo", func_SetScrollInfo },
diff --git a/modules/rostests/apitests/user32/user32_apitest.rc
b/modules/rostests/apitests/user32/user32_apitest.rc
index 6c7cfe5ec81..c6da5676f18 100644
--- a/modules/rostests/apitests/user32/user32_apitest.rc
+++ b/modules/rostests/apitests/user32/user32_apitest.rc
@@ -38,3 +38,13 @@ CAPTION "DM_REPOSITION"
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
+}