https://git.reactos.org/?p=reactos.git;a=commitdiff;h=f3235f1074e32de0e0bc6…
commit f3235f1074e32de0e0bc60e8530d7c187fae21c3
Author: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com>
AuthorDate: Wed Apr 29 07:48:46 2020 +0900
Commit: GitHub <noreply(a)github.com>
CommitDate: Wed Apr 29 07:48:46 2020 +0900
[KERNEL32_APITEST] Add QueryUserAPC testcase (#2681)
Add a testcase for kernel32!QueryUserAPC, SleepEx and WaitForSingleObjectEx
functions.
CORE-13950
---
modules/rostests/apitests/kernel32/CMakeLists.txt | 1 +
modules/rostests/apitests/kernel32/QueryUserAPC.c | 152 ++++++++++++++++++++++
modules/rostests/apitests/kernel32/testlist.c | 2 +
3 files changed, 155 insertions(+)
diff --git a/modules/rostests/apitests/kernel32/CMakeLists.txt
b/modules/rostests/apitests/kernel32/CMakeLists.txt
index da3ea911884..5fdae336b6c 100644
--- a/modules/rostests/apitests/kernel32/CMakeLists.txt
+++ b/modules/rostests/apitests/kernel32/CMakeLists.txt
@@ -27,6 +27,7 @@ list(APPEND SOURCE
Mailslot.c
MultiByteToWideChar.c
PrivMoveFileIdentityW.c
+ QueryUserAPC.c
SetComputerNameExW.c
SetConsoleWindowInfo.c
SetCurrentDirectory.c
diff --git a/modules/rostests/apitests/kernel32/QueryUserAPC.c
b/modules/rostests/apitests/kernel32/QueryUserAPC.c
new file mode 100644
index 00000000000..f3a64498506
--- /dev/null
+++ b/modules/rostests/apitests/kernel32/QueryUserAPC.c
@@ -0,0 +1,152 @@
+/*
+ * PROJECT: ReactOS api tests
+ * LICENSE: LGPL-2.0-or-later (
https://spdx.org/licenses/LGPL-2.0-or-later)
+ * PURPOSE: Tests for QueryUserAPC, SleepEx, WaitForSingleObjectEx etc.
+ * COPYRIGHT: Copyright 2020 Katayama Hirofumi MZ (katayama.hirofumi.mz(a)gmail.com)
+ */
+#include "precomp.h"
+
+#define MAX_RECORD 30
+
+static DWORD s_record_count = 0;
+static DWORD s_record[MAX_RECORD + 1] = { 0 };
+static BOOL s_terminate_all = FALSE;
+
+static const DWORD s_expected[] =
+{
+ 0, 1, 7, 8, 4,
+ 2, 1, 9, 10, 5,
+ 2, 1, 11, 12, 13,
+ 6, 2, 3, 14, 15,
+ 16
+};
+static const SIZE_T s_expected_count = _countof(s_expected);
+
+static void AddValueToRecord(DWORD dwValue)
+{
+ s_record[s_record_count] = dwValue;
+ if (s_record_count < MAX_RECORD)
+ s_record_count++;
+}
+
+static VOID CheckRecord(void)
+{
+ SIZE_T i, count = min(s_record_count, s_expected_count);
+
+ for (i = 0; i < count; ++i)
+ {
+ ok(s_record[i] == s_expected[i], "s_record[%u]: got %lu vs expected
%lu\n",
+ (INT)i, s_record[i], s_expected[i]);
+ }
+
+ count = abs((int)s_record_count - (int)s_expected_count);
+ for (i = 0; i < count; ++i)
+ {
+ ok(s_record_count == s_expected_count,
+ "s_record_count: got %u vs expected %u\n",
+ (int)s_record_count, (int)s_expected_count);
+ }
+}
+
+static DWORD WINAPI ThreadFunc1(LPVOID arg)
+{
+ AddValueToRecord(0);
+ while (!s_terminate_all)
+ {
+ AddValueToRecord(1);
+ ok_long(SleepEx(INFINITE, TRUE), WAIT_IO_COMPLETION);
+ AddValueToRecord(2);
+ }
+ AddValueToRecord(3);
+ return 0;
+}
+
+static DWORD WINAPI ThreadFunc2(LPVOID arg)
+{
+ AddValueToRecord(0);
+ while (!s_terminate_all)
+ {
+ AddValueToRecord(1);
+ ok_long(WaitForSingleObjectEx(GetCurrentThread(), INFINITE, TRUE),
WAIT_IO_COMPLETION);
+ AddValueToRecord(2);
+ }
+ AddValueToRecord(3);
+ return 0;
+}
+
+static VOID NTAPI DoUserAPC1(ULONG_PTR Parameter)
+{
+ ok_int((int)Parameter, 1);
+ AddValueToRecord(4);
+}
+
+static VOID NTAPI DoUserAPC2(ULONG_PTR Parameter)
+{
+ ok_int((int)Parameter, 2);
+ AddValueToRecord(5);
+}
+
+static VOID NTAPI DoUserAPC3(ULONG_PTR Parameter)
+{
+ ok_int((int)Parameter, 3);
+ AddValueToRecord(6);
+ s_terminate_all = TRUE;
+}
+
+static void JustDoIt(LPTHREAD_START_ROUTINE fn)
+{
+ HANDLE hThread;
+ DWORD dwThreadId;
+
+ s_terminate_all = FALSE;
+ s_record_count = 0;
+ ZeroMemory(s_record, sizeof(s_record));
+
+ hThread = CreateThread(NULL, 0, fn, NULL, 0, &dwThreadId);
+ ok(hThread != NULL, "hThread was NULL\n");
+
+ Sleep(100);
+
+ AddValueToRecord(7);
+ ok_long(QueueUserAPC(DoUserAPC1, hThread, 1), 1);
+ AddValueToRecord(8);
+
+ Sleep(100);
+
+ AddValueToRecord(9);
+ ok_long(QueueUserAPC(DoUserAPC2, hThread, 2), 1);
+ AddValueToRecord(10);
+
+ Sleep(100);
+
+ AddValueToRecord(11);
+ ok_long(QueueUserAPC(DoUserAPC3, hThread, 3), 1);
+ AddValueToRecord(12);
+
+ AddValueToRecord(13);
+ ok_long(WaitForSingleObject(hThread, 5 * 1000), WAIT_OBJECT_0);
+ AddValueToRecord(14);
+
+ AddValueToRecord(15);
+ ok_int(CloseHandle(hThread), TRUE);
+ hThread = NULL;
+ AddValueToRecord(16);
+
+ CheckRecord();
+}
+
+static void TestForSleepEx(void)
+{
+ JustDoIt(ThreadFunc1);
+}
+
+static void TestForWaitForSingleObjectEx(void)
+{
+ JustDoIt(ThreadFunc2);
+}
+
+START_TEST(QueryUserAPC)
+{
+ TestForSleepEx();
+ TestForWaitForSingleObjectEx();
+}
diff --git a/modules/rostests/apitests/kernel32/testlist.c
b/modules/rostests/apitests/kernel32/testlist.c
index 19217012a9b..1db6b3ff377 100644
--- a/modules/rostests/apitests/kernel32/testlist.c
+++ b/modules/rostests/apitests/kernel32/testlist.c
@@ -26,6 +26,7 @@ extern void func_lstrlen(void);
extern void func_Mailslot(void);
extern void func_MultiByteToWideChar(void);
extern void func_PrivMoveFileIdentityW(void);
+extern void func_QueryUserAPC(void);
extern void func_SetComputerNameExW(void);
extern void func_SetConsoleWindowInfo(void);
extern void func_SetCurrentDirectory(void);
@@ -60,6 +61,7 @@ const struct test winetest_testlist[] =
{ "MailslotRead", func_Mailslot },
{ "MultiByteToWideChar", func_MultiByteToWideChar },
{ "PrivMoveFileIdentityW", func_PrivMoveFileIdentityW },
+ { "QueryUserAPC", func_QueryUserAPC },
{ "SetComputerNameExW", func_SetComputerNameExW },
{ "SetConsoleWindowInfo", func_SetConsoleWindowInfo },
{ "SetCurrentDirectory", func_SetCurrentDirectory },