[PATCH 1/6] kernel32/tests: Add console reallocation tests.
Torge Matthies
openglfreak at googlemail.com
Mon Apr 4 21:06:38 CDT 2022
Signed-off-by: Torge Matthies <openglfreak at googlemail.com>
---
dlls/kernel32/tests/console.c | 46 +++++++++++++++++++++++++++++++++--
1 file changed, 44 insertions(+), 2 deletions(-)
diff --git a/dlls/kernel32/tests/console.c b/dlls/kernel32/tests/console.c
index 98692760acf..9195ac204f7 100644
--- a/dlls/kernel32/tests/console.c
+++ b/dlls/kernel32/tests/console.c
@@ -4689,7 +4689,7 @@ static void copy_change_subsystem(const char* in, const char* out, DWORD subsyst
CloseHandle(hFile);
}
-static BOOL check_whether_child_attached(const char* exec, DWORD flags)
+static BOOL check_subprocess(const char* exec, const char* verb, DWORD flags)
{
STARTUPINFOA si = { sizeof(si) };
PROCESS_INFORMATION info;
@@ -4698,7 +4698,7 @@ static BOOL check_whether_child_attached(const char* exec, DWORD flags)
BOOL res;
DWORD ret;
- sprintf(buf, "\"%s\" console check_console", exec);
+ sprintf(buf, "\"%s\" console %s", exec, verb);
res = CreateProcessA(NULL, buf, NULL, NULL, FALSE, flags, NULL, NULL, &si, &info);
ok(res, "CreateProcess failed: %lu %s\n", GetLastError(), buf);
CloseHandle(info.hThread);
@@ -4711,6 +4711,18 @@ static BOOL check_whether_child_attached(const char* exec, DWORD flags)
return exit_code != 0;
}
+static BOOL check_whether_child_attached(const char* exec, DWORD flags)
+{
+ return check_subprocess(exec, "check_console", flags);
+}
+
+static BOOL check_same_console(const char* exec, DWORD flags)
+{
+ char buf[MAX_PATH];
+ sprintf(buf, "check_same_console %lx", GetCurrentProcessId());
+ return check_subprocess(exec, buf, flags);
+}
+
static void test_CreateProcessCUI(void)
{
char guiexec[MAX_PATH];
@@ -4726,14 +4738,33 @@ static void test_CreateProcessCUI(void)
strcat(cuiexec, "console_cui.exe");
copy_change_subsystem(argv[0], cuiexec, IMAGE_SUBSYSTEM_WINDOWS_CUI);
+ AllocConsole();
+
+ res = check_same_console(cuiexec, 0);
+ ok(res, "Expected child to be attached to the same console\n");
+ res = check_same_console(cuiexec, DETACHED_PROCESS);
+ ok(!res, "Expected child to be attached to a different console\n");
+ res = check_same_console(cuiexec, CREATE_NO_WINDOW);
+ todo_wine ok(!res, "Expected child to be attached to a different console\n");
+ res = check_same_console(cuiexec, CREATE_NO_WINDOW|DETACHED_PROCESS);
+ ok(!res, "Expected child to be attached to a different console\n");
+ res = check_same_console(cuiexec, CREATE_NO_WINDOW|CREATE_NEW_CONSOLE);
+ ok(!res, "Expected child to be attached to a different console\n");
+
FreeConsole();
res = check_whether_child_attached(guiexec, DETACHED_PROCESS);
ok(!res, "Don't expecting child to be attached to a console\n");
+ res = check_whether_child_attached(guiexec, CREATE_NO_WINDOW);
+ ok(!res, "Don't expecting child to be attached to a console\n");
res = check_whether_child_attached(guiexec, 0);
ok(!res, "Don't expecting child to be attached to a console\n");
res = check_whether_child_attached(cuiexec, DETACHED_PROCESS);
ok(!res, "Don't expecting child to be attached to a console\n");
+ res = check_whether_child_attached(cuiexec, CREATE_NO_WINDOW);
+ ok(res, "Expecting child to be attached to a console\n");
+ res = check_whether_child_attached(cuiexec, CREATE_NO_WINDOW|DETACHED_PROCESS);
+ ok(!res, "Don't expecting child to be attached to a console\n");
res = check_whether_child_attached(cuiexec, 0);
ok(res, "Expecting child to be attached to a console\n");
@@ -4774,6 +4805,17 @@ START_TEST(console)
ExitProcess(GetConsoleCP() != 0);
}
+ if (argc > 3 && !strcmp(argv[2], "check_same_console"))
+ {
+ DWORD parent_pid, count, pids[2];
+ sscanf(argv[3], "%lx", &parent_pid);
+ count = GetConsoleProcessList(pids, ARRAY_SIZE(pids));
+ while (count--)
+ if (pids[count] == parent_pid)
+ ExitProcess(1);
+ ExitProcess(0);
+ }
+
test_current = argc >= 3 && !strcmp(argv[2], "--current");
using_pseudo_console = argc >= 3 && !strcmp(argv[2], "--pseudo-console");
--
2.35.1
More information about the wine-devel
mailing list