https://git.reactos.org/?p=reactos.git;a=commitdiff;h=f831ec7e0a4699a817eac…
commit f831ec7e0a4699a817eacb3cdf35a62a1437d9c8
Author: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com>
AuthorDate: Sun Aug 22 09:02:02 2021 +0900
Commit: GitHub <noreply(a)github.com>
CommitDate: Sun Aug 22 09:02:02 2021 +0900
[WIN32KNT_APITEST] Add NtUserGetThreadState testcase (#3922)
CORE-17732, CORE-11700
---
modules/rostests/apitests/win32nt/CMakeLists.txt | 3 +-
.../apitests/win32nt/ntuser/NtUserGetThreadState.c | 243 +++++++++++++++++++++
modules/rostests/apitests/win32nt/testlist.c | 2 +
3 files changed, 247 insertions(+), 1 deletion(-)
diff --git a/modules/rostests/apitests/win32nt/CMakeLists.txt
b/modules/rostests/apitests/win32nt/CMakeLists.txt
index 22db4f5cb7a..2ff69348a04 100644
--- a/modules/rostests/apitests/win32nt/CMakeLists.txt
+++ b/modules/rostests/apitests/win32nt/CMakeLists.txt
@@ -54,6 +54,7 @@ list(APPEND SOURCE
ntuser/NtUserFindExistingCursorIcon.c
ntuser/NtUserGetClassInfo.c
# ntuser/NtUserGetIconInfo.c
+ ntuser/NtUserGetThreadState.c
ntuser/NtUserGetTitleBarInfo.c
ntuser/NtUserProcessConnect.c
ntuser/NtUserRedrawWindow.c
@@ -85,7 +86,7 @@ add_importlibs(win32knt_apitest
msvcrt
kernel32
ntdll)
-add_delay_importlibs(win32knt_apitest win32u)
+add_delay_importlibs(win32knt_apitest win32u imm32)
add_dependencies(win32knt_apitest xdk)
add_pch(win32knt_apitest win32nt.h "${PCH_SKIP_SOURCE}")
add_rostests_file(TARGET win32knt_apitest)
diff --git a/modules/rostests/apitests/win32nt/ntuser/NtUserGetThreadState.c
b/modules/rostests/apitests/win32nt/ntuser/NtUserGetThreadState.c
new file mode 100644
index 00000000000..2ff394838b2
--- /dev/null
+++ b/modules/rostests/apitests/win32nt/ntuser/NtUserGetThreadState.c
@@ -0,0 +1,243 @@
+/*
+ * PROJECT: ReactOS api tests
+ * LICENSE: LGPL-2.0-or-later (
https://spdx.org/licenses/LGPL-2.0-or-later)
+ * PURPOSE: Test for NtUserGetThreadState
+ * COPYRIGHT: Copyright 2021 Katayama Hirofumi MZ
<katayama.hirofumi.mz(a)gmail.com>
+ */
+
+#include <win32nt.h>
+#include <pseh/pseh2.h>
+
+#define MAX_COUNT 8
+#define IGNORED 0xDEADFACE
+#define RAISED 0xBADBEEF
+#define DO_CHECK(i, value) CheckThreadState(__LINE__, (i), (DWORD_PTR)(value))
+
+#undef DO_PRINT
+
+#ifdef DO_PRINT
+static VOID PrintThreadState(INT lineno, HWND hWnd)
+{
+ INT i;
+ HIMC hIMC = ImmGetContext(hWnd);
+ HWND hImeWnd = ImmGetDefaultIMEWnd(hWnd);
+
+ trace("---\n");
+ trace("__LINE__: %d\n", lineno);
+ trace("hWnd: %p\n", (LPVOID)hWnd);
+ trace("GetFocus(): %p\n", (LPVOID)GetFocus());
+ trace("GetCapture(): %p\n", (LPVOID)GetCapture());
+ trace("GetActiveWindow(): %p\n", (LPVOID)GetActiveWindow());
+ trace("ImmGetContext(): %p\n", (LPVOID)hIMC);
+ trace("ImmGetDefaultIMEWnd(): %p\n", (LPVOID)hImeWnd);
+
+ for (i = 0; i < MAX_COUNT; ++i)
+ {
+ _SEH2_TRY
+ {
+ trace("ThreadState[%d]: %p\n", i,
(LPVOID)NtUserGetThreadState(i));
+ }
+ _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
+ {
+ trace("ThreadState[%d]: exception\n", i);
+ }
+ _SEH2_END;
+ }
+
+ ImmReleaseContext(hWnd, hIMC);
+}
+#endif
+
+static VOID CheckThreadState(INT lineno, INT i, DWORD_PTR dwState)
+{
+ DWORD_PTR dwValue;
+
+ _SEH2_TRY
+ {
+ dwValue = (DWORD_PTR)NtUserGetThreadState(i);
+ }
+ _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
+ {
+ dwValue = RAISED;
+ }
+ _SEH2_END;
+
+ if (dwState != IGNORED)
+ {
+ ok(dwValue == dwState, "Line %d: Mismatch 0x%lX vs. 0x%lX\n",
+ lineno, (DWORD)dwValue, (DWORD)dwState);
+ }
+}
+
+static VOID DoTest_EDIT(VOID)
+{
+ HWND hWnd, hImeWnd;
+ HIMC hIMC;
+
+ hWnd = CreateWindowA("EDIT", "Test", ES_LEFT | ES_MULTILINE |
WS_VISIBLE,
+ 0, 0, 50, 30,
+ NULL, NULL, GetModuleHandleW(NULL), NULL);
+ hImeWnd = ImmGetDefaultIMEWnd(hWnd);
+ ok_int(hImeWnd != NULL, TRUE);
+
+ hIMC = ImmGetContext(hWnd);
+ ok_int(hIMC != NULL, TRUE);
+ ok_int(hIMC == (HIMC)NtUserGetThreadState(4), TRUE);
+
+#ifdef DO_PRINT
+ PrintThreadState(__LINE__, hWnd);
+#endif
+ DO_CHECK(0, hWnd);
+ DO_CHECK(1, hWnd);
+ DO_CHECK(2, 0);
+ DO_CHECK(3, hImeWnd);
+ DO_CHECK(4, hIMC);
+
+ SetCapture(hWnd);
+
+#ifdef DO_PRINT
+ PrintThreadState(__LINE__, hWnd);
+#endif
+ DO_CHECK(0, hWnd);
+ DO_CHECK(1, hWnd);
+ DO_CHECK(2, hWnd);
+ DO_CHECK(3, hImeWnd);
+ DO_CHECK(4, hIMC);
+
+ ReleaseCapture();
+
+#ifdef DO_PRINT
+ PrintThreadState(__LINE__, hWnd);
+#endif
+ DO_CHECK(0, hWnd);
+ DO_CHECK(1, hWnd);
+ DO_CHECK(2, 0);
+ DO_CHECK(3, hImeWnd);
+ DO_CHECK(4, hIMC);
+
+ SetFocus(hWnd);
+
+#ifdef DO_PRINT
+ PrintThreadState(__LINE__, hWnd);
+#endif
+ DO_CHECK(0, hWnd);
+ DO_CHECK(1, hWnd);
+ DO_CHECK(2, 0);
+ DO_CHECK(3, hImeWnd);
+ DO_CHECK(4, hIMC);
+
+ SetActiveWindow(hWnd);
+
+#ifdef DO_PRINT
+ PrintThreadState(__LINE__, hWnd);
+#endif
+ DO_CHECK(0, hWnd);
+ DO_CHECK(1, hWnd);
+ DO_CHECK(2, 0);
+ DO_CHECK(3, hImeWnd);
+ DO_CHECK(4, hIMC);
+
+ SetActiveWindow(NULL);
+
+#ifdef DO_PRINT
+ PrintThreadState(__LINE__, hWnd);
+#endif
+ DO_CHECK(0, IGNORED);
+ DO_CHECK(1, IGNORED);
+ DO_CHECK(2, 0);
+ DO_CHECK(3, hImeWnd);
+ DO_CHECK(4, hIMC);
+
+ ImmReleaseContext(hWnd, hIMC);
+ DestroyWindow(hWnd);
+}
+
+static VOID DoTest_BUTTON(VOID)
+{
+ HWND hWnd, hImeWnd;
+ HIMC hIMC;
+
+ hWnd = CreateWindowA("BUTTON", "Test", BS_PUSHBUTTON |
WS_VISIBLE,
+ 0, 0, 50, 30,
+ NULL, NULL, GetModuleHandleW(NULL), NULL);
+ hImeWnd = ImmGetDefaultIMEWnd(hWnd);
+ ok_int(hImeWnd != NULL, TRUE);
+
+ hIMC = ImmGetContext(hWnd);
+ ok_int(hIMC != NULL, FALSE);
+
+ hIMC = (HIMC)NtUserGetThreadState(4);
+ ok_int(hIMC != NULL, TRUE);
+
+#ifdef DO_PRINT
+ PrintThreadState(__LINE__, hWnd);
+#endif
+ DO_CHECK(0, hWnd);
+ DO_CHECK(1, hWnd);
+ DO_CHECK(2, 0);
+ DO_CHECK(3, hImeWnd);
+ DO_CHECK(4, hIMC);
+
+ SetCapture(hWnd);
+
+#ifdef DO_PRINT
+ PrintThreadState(__LINE__, hWnd);
+#endif
+ DO_CHECK(0, hWnd);
+ DO_CHECK(1, hWnd);
+ DO_CHECK(2, hWnd);
+ DO_CHECK(3, hImeWnd);
+ DO_CHECK(4, hIMC);
+
+ ReleaseCapture();
+
+#ifdef DO_PRINT
+ PrintThreadState(__LINE__, hWnd);
+#endif
+ DO_CHECK(0, hWnd);
+ DO_CHECK(1, hWnd);
+ DO_CHECK(2, 0);
+ DO_CHECK(3, hImeWnd);
+ DO_CHECK(4, hIMC);
+
+ SetFocus(hWnd);
+
+#ifdef DO_PRINT
+ PrintThreadState(__LINE__, hWnd);
+#endif
+ DO_CHECK(0, hWnd);
+ DO_CHECK(1, hWnd);
+ DO_CHECK(2, 0);
+ DO_CHECK(3, hImeWnd);
+ DO_CHECK(4, hIMC);
+
+ SetActiveWindow(hWnd);
+
+#ifdef DO_PRINT
+ PrintThreadState(__LINE__, hWnd);
+#endif
+ DO_CHECK(0, hWnd);
+ DO_CHECK(1, hWnd);
+ DO_CHECK(2, 0);
+ DO_CHECK(3, hImeWnd);
+ DO_CHECK(4, hIMC);
+
+ SetActiveWindow(NULL);
+
+#ifdef DO_PRINT
+ PrintThreadState(__LINE__, hWnd);
+#endif
+ DO_CHECK(0, IGNORED);
+ DO_CHECK(1, IGNORED);
+ DO_CHECK(2, 0);
+ DO_CHECK(3, hImeWnd);
+ DO_CHECK(4, hIMC);
+
+ DestroyWindow(hWnd);
+}
+
+START_TEST(NtUserGetThreadState)
+{
+ DoTest_EDIT();
+ DoTest_BUTTON();
+}
diff --git a/modules/rostests/apitests/win32nt/testlist.c
b/modules/rostests/apitests/win32nt/testlist.c
index bbf0756fc31..d58f6b5a5d0 100644
--- a/modules/rostests/apitests/win32nt/testlist.c
+++ b/modules/rostests/apitests/win32nt/testlist.c
@@ -53,6 +53,7 @@ extern void func_NtUserCreateWindowEx(void);
extern void func_NtUserEnumDisplaySettings(void);
extern void func_NtUserFindExistingCursorIcon(void);
extern void func_NtUserGetClassInfo(void);
+extern void func_NtUserGetThreadState(void);
//extern void func_NtUserGetIconInfo(void);
extern void func_NtUserGetTitleBarInfo(void);
extern void func_NtUserProcessConnect(void);
@@ -119,6 +120,7 @@ const struct test winetest_testlist[] =
{ "NtUserEnumDisplaySettings", func_NtUserEnumDisplaySettings },
{ "NtUserFindExistingCursorIcon", func_NtUserFindExistingCursorIcon },
{ "NtUserGetClassInfo", func_NtUserGetClassInfo },
+ { "NtUserGetThreadState", func_NtUserGetThreadState },
//{ "NtUserGetIconInfo", func_NtUserGetIconInfo },
{ "NtUserGetTitleBarInfo", func_NtUserGetTitleBarInfo },
{ "NtUserProcessConnect", func_NtUserProcessConnect },