Piotr Caban : msvcrt: Added basic _popen tests.

Alexandre Julliard julliard at winehq.org
Fri Jan 18 12:07:36 CST 2013


Module: wine
Branch: master
Commit: 0d0f705048aa5e56a17b9318ee0d3373ed20477f
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=0d0f705048aa5e56a17b9318ee0d3373ed20477f

Author: Piotr Caban <piotr at codeweavers.com>
Date:   Fri Jan 18 11:05:46 2013 +0100

msvcrt: Added basic _popen tests.

---

 dlls/msvcrt/tests/misc.c |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 46 insertions(+), 0 deletions(-)

diff --git a/dlls/msvcrt/tests/misc.c b/dlls/msvcrt/tests/misc.c
index a2bf0cb..26225f3 100644
--- a/dlls/msvcrt/tests/misc.c
+++ b/dlls/msvcrt/tests/misc.c
@@ -20,6 +20,7 @@
 
 #include "wine/test.h"
 #include <errno.h>
+#include <stdio.h>
 #include "msvcrt.h"
 
 static int (__cdecl *prand_s)(unsigned int *);
@@ -309,10 +310,54 @@ static void test__set_errno(void)
     ok(errno == 0xdeadbeef, "Expected errno to be 0xdeadbeef, got %d\n", errno);
 }
 
+static void test__popen_child(void)
+{
+    /* don't execute any tests here */
+    /* ExitProcess is used to set return code of _pclose */
+    printf("child output\n");
+    ExitProcess(0x37);
+}
+
+static void test__popen(const char *name)
+{
+    FILE *pipe;
+    char buf[1024];
+    int ret;
+
+    sprintf(buf, "%s misc popen", name);
+    pipe = _popen(buf, "r");
+    ok(pipe != NULL, "_popen failed with error: %d\n", errno);
+
+    fgets(buf, sizeof(buf), pipe);
+    ok(!strcmp(buf, "child output\n"), "buf = %s\n", buf);
+
+    ret = _pclose(pipe);
+    ok(ret == 0x37, "_pclose returned %x, expected 0x37\n", ret);
+
+    errno = 0xdeadbeef;
+    ret = _pclose((FILE*)0xdeadbeef);
+    ok(ret == -1, "_pclose returned %x, expected -1\n", ret);
+    if(p_set_errno)
+        ok(errno == EBADF, "errno = %d\n", errno);
+}
+
 START_TEST(misc)
 {
+    int arg_c;
+    char** arg_v;
+
     init();
 
+    arg_c = winetest_get_mainargs(&arg_v);
+    if(arg_c >= 3) {
+        if(!strcmp(arg_v[2], "popen"))
+            test__popen_child();
+        else
+            ok(0, "invalid argument '%s'\n", arg_v[2]);
+
+        return;
+    }
+
     test_rand_s();
     test_I10_OUTPUT();
     test_strerror_s();
@@ -320,4 +365,5 @@ START_TEST(misc)
     test__get_errno();
     test__set_doserrno();
     test__set_errno();
+    test__popen(arg_v[0]);
 }




More information about the wine-cvs mailing list