[PATCH 2/4] dlls/kernel32/tests: add tests about CreateProcess on CUI programs with console inheritance

Eric Pouech eric.pouech at gmail.com
Thu Feb 10 08:55:16 CST 2022


adding console_cui as a CUI submodule

Signed-off-by: Eric Pouech <eric.pouech at gmail.com>

---
 dlls/kernel32/tests/Makefile.in      |    4 ++
 dlls/kernel32/tests/console.c        |   56 ++++++++++++++++++++++++++++++++++
 dlls/kernel32/tests/console_cui.c    |   31 +++++++++++++++++++
 dlls/kernel32/tests/console_cui.spec |    0 
 4 files changed, 91 insertions(+)
 create mode 100644 dlls/kernel32/tests/console_cui.c
 create mode 100644 dlls/kernel32/tests/console_cui.spec

diff --git a/dlls/kernel32/tests/Makefile.in b/dlls/kernel32/tests/Makefile.in
index db106ab9fc9..772ca0fe7c3 100644
--- a/dlls/kernel32/tests/Makefile.in
+++ b/dlls/kernel32/tests/Makefile.in
@@ -2,6 +2,8 @@ EXTRADEFS = -DWINE_NO_LONG_TYPES
 TESTDLL   = kernel32.dll
 IMPORTS   = user32 advapi32
 
+console_cui_EXTRADLLFLAGS = -mconsole -municode
+
 SOURCES = \
 	actctx.c \
 	atom.c \
@@ -9,6 +11,8 @@ SOURCES = \
 	codepage.c \
 	comm.c \
 	console.c \
+	console_cui.c \
+	console_cui.spec \
 	debugger.c \
 	directory.c \
 	drive.c \
diff --git a/dlls/kernel32/tests/console.c b/dlls/kernel32/tests/console.c
index e4d9d43f4c4..16cbb234c21 100644
--- a/dlls/kernel32/tests/console.c
+++ b/dlls/kernel32/tests/console.c
@@ -4647,6 +4647,61 @@ static void test_pseudo_console(void)
     pClosePseudoConsole(pseudo_console);
 }
 
+static void extract_resource(const char *name, const char *where)
+{
+    DWORD written;
+    HANDLE file;
+    HRSRC res;
+    void *ptr;
+
+    trace("foobar %s %s\n", name, where);
+    file = CreateFileA(where, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0);
+    ok(file != INVALID_HANDLE_VALUE, "file creation failed, at %s, error %u\n", where, GetLastError());
+
+    res = FindResourceA(NULL, name, "TESTDLL");
+    ok( res != 0, "couldn't find resource\n" );
+    ptr = LockResource( LoadResource( GetModuleHandleA(NULL), res ));
+    WriteFile( file, ptr, SizeofResource( GetModuleHandleA(NULL), res ), &written, NULL );
+    ok( written == SizeofResource( GetModuleHandleA(NULL), res ), "couldn't write resource\n" );
+    CloseHandle( file );
+}
+
+static void test_CreateProcess_CUI(void)
+{
+    STARTUPINFOA si = { sizeof(si) };
+    PROCESS_INFORMATION info;
+    char buf[MAX_PATH];
+    BOOL res;
+    DWORD ec = 255;
+
+    FreeConsole();
+
+    GetTempPathA(ARRAY_SIZE(buf), buf);
+    strcat(buf, "console_cui.exe");
+    extract_resource("console_cui.exe", buf);
+
+    res = CreateProcessA(NULL, buf, NULL, NULL, FALSE, DETACHED_PROCESS, NULL, NULL, &si, &info);
+    ok(res, "CreateProcess failed: %u %s\n", GetLastError(), buf);
+    CloseHandle(info.hThread);
+
+    res = WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0 &&
+            GetExitCodeProcess(info.hProcess, &ec);
+    ok(res, "Couldn't grab exit code %u\n", GetLastError());
+    ok(!res || ec == 1, "Got unexpected error code %u\n", ec);
+    CloseHandle(info.hProcess);
+
+    res = CreateProcessA(NULL, buf, NULL, NULL, FALSE, 0, NULL, NULL, &si, &info);
+    ok(res, "CreateProcess failed: %u\n", GetLastError());
+    CloseHandle(info.hThread);
+
+    res = WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0 &&
+            GetExitCodeProcess(info.hProcess, &ec);
+    res = GetExitCodeProcess(info.hProcess, &ec);
+    ok(res, "Couldn't grab exit code %u\n", GetLastError());
+    todo_wine ok(!res || ec == 0, "Got unexpected error code %u\n", ec);
+    CloseHandle(info.hProcess);
+}
+
 START_TEST(console)
 {
     HANDLE hConIn, hConOut, revert_output = NULL, unbound_output;
@@ -4865,6 +4920,7 @@ START_TEST(console)
         test_AttachConsole(hConOut);
         test_AllocConsole();
         test_FreeConsole();
+        test_CreateProcess_CUI();
     }
     else if (revert_output) SetConsoleActiveScreenBuffer(revert_output);
 
diff --git a/dlls/kernel32/tests/console_cui.c b/dlls/kernel32/tests/console_cui.c
new file mode 100644
index 00000000000..2b6f01d5b67
--- /dev/null
+++ b/dlls/kernel32/tests/console_cui.c
@@ -0,0 +1,31 @@
+/*
+ * a CUI application for testing
+ *
+ * Copyright 2022 Eric Pouech
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <stdarg.h>
+
+#include "windef.h"
+#include "winbase.h"
+#include "wincon.h"
+
+int WINAPI wWinMain( HINSTANCE inst, HINSTANCE prev, WCHAR *cmdline, INT show )
+{
+    /* We assume GetConsoleCP() returns 0 only when not attached to a console */
+    return GetConsoleCP() == 0;
+}
diff --git a/dlls/kernel32/tests/console_cui.spec b/dlls/kernel32/tests/console_cui.spec
new file mode 100644
index 00000000000..e69de29bb2d




More information about the wine-devel mailing list