[PATCH] kernel32/tests: Detect and handle a redirected stdin.

Alex Henrie alexhenrie24 at gmail.com
Thu Nov 2 03:36:53 CDT 2017


Signed-off-by: Alex Henrie <alexhenrie24 at gmail.com>
---
Fixes test failures on both Windows and Linux (bug 43952).

If stdin is connected to a pipe when the ReadConsole tests run (a common
testing configuration although it's not clear why AllocConsole doesn't
reconnect stdin to the console window input), these tests fail because
they are trying to test the properties of a console input handle, which
are different from the properties of a pipe input handle.

I could not find any way to directly check whether stdin is redirected,
so I decided to instead check whether GetFileSize succeeds, which
should only happen when stdin is redirected.

Many thanks to Stefan Dösinger and Francois Gouget for helping debug
this!
---
 dlls/kernel32/tests/console.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/dlls/kernel32/tests/console.c b/dlls/kernel32/tests/console.c
index a14bc45034..3d40b9696e 100644
--- a/dlls/kernel32/tests/console.c
+++ b/dlls/kernel32/tests/console.c
@@ -2572,7 +2572,7 @@ static void test_ReadConsoleOutputAttribute(HANDLE output_handle)
     ok(count == 1, "Expected count to be 1, got %u\n", count);
 }
 
-static void test_ReadConsole(void)
+static void test_ReadConsole(HANDLE input_handle)
 {
     HANDLE std_input;
     DWORD ret, bytes;
@@ -2582,6 +2582,13 @@ static void test_ReadConsole(void)
 
     SetLastError(0xdeadbeef);
     ret = GetFileSize(std_input, NULL);
+    if (GetLastError() == 0xdeadbeef)
+    {
+        /* print a warning and cheat a little so that the tests can continue */
+        skip("stdin appears to be redirected; if it's not then this is an error");
+        std_input = input_handle;
+        ret = GetFileSize(std_input, NULL);
+    }
     ok(ret == INVALID_FILE_SIZE, "expected INVALID_FILE_SIZE, got %#x\n", ret);
     ok(GetLastError() == ERROR_INVALID_HANDLE ||
        GetLastError() == ERROR_INVALID_FUNCTION, /* Win 8, 10 */
@@ -3107,7 +3114,7 @@ START_TEST(console)
     ok(sbi.dwSize.Y == size, "Unexpected buffer size: %d instead of %d\n", sbi.dwSize.Y, size);
     if (!ret) return;
 
-    test_ReadConsole();
+    test_ReadConsole(hConIn);
     /* Non interactive tests */
     testCursor(hConOut, sbi.dwSize);
     /* test parameters (FIXME: test functionality) */
-- 
2.14.2




More information about the wine-patches mailing list