Jon Griffiths : msvcrt: Tests for [w]makepath.

Alexandre Julliard julliard at winehq.org
Wed Jul 9 06:10:34 CDT 2008


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

Author: Jon Griffiths <jon_p_griffiths at yahoo.com>
Date:   Thu Jul  3 12:27:24 2008 -0700

msvcrt: Tests for [w]makepath.

---

 dlls/msvcrt/tests/dir.c |  101 +++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 93 insertions(+), 8 deletions(-)

diff --git a/dlls/msvcrt/tests/dir.c b/dlls/msvcrt/tests/dir.c
index 6929a76..507add2 100644
--- a/dlls/msvcrt/tests/dir.c
+++ b/dlls/msvcrt/tests/dir.c
@@ -31,19 +31,104 @@
 #include <process.h>
 #include <errno.h>
 
+typedef struct
+{
+    const char* buffer;
+    const char* drive;
+    const char* dir;
+    const char* file;
+    const char* ext;
+    const char* expected;
+    BOOL todoA;
+    BOOL todoW;
+} makepath_case;
+
+#define USE_BUFF ((char*)~0ul)
+static const makepath_case makepath_cases[] =
+{
+    { NULL, NULL, NULL, NULL, NULL, "", TRUE }, /* 0 */
+    { NULL, "c", NULL, NULL, NULL, "c:" },
+    { NULL, "c:", NULL, NULL, NULL, "c:" },
+    { NULL, "c:\\", NULL, NULL, NULL, "c:" },
+    { NULL, NULL, "dir", NULL, NULL, "dir\\" },
+    { NULL, NULL, "dir\\", NULL, NULL, "dir\\" },
+    { NULL, NULL, "\\dir", NULL, NULL, "\\dir\\" },
+    { NULL, NULL, NULL, "file", NULL, "file" },
+    { NULL, NULL, NULL, "\\file", NULL, "\\file" },
+    { NULL, NULL, NULL, "file", NULL, "file" },
+    { NULL, NULL, NULL, NULL, "ext", ".ext", TRUE, TRUE }, /* 10 */
+    { NULL, NULL, NULL, NULL, ".ext", ".ext", TRUE, TRUE },
+    { "foo", NULL, NULL, NULL, NULL, "", TRUE },
+    { "foo", USE_BUFF, NULL, NULL, NULL, "f:", FALSE, TRUE },
+    { "foo", NULL, USE_BUFF, NULL, NULL, "foo\\", FALSE, TRUE },
+    { "foo", NULL, NULL, USE_BUFF, NULL, "foo", FALSE, TRUE },
+    { "foo", NULL, USE_BUFF, "file", NULL, "foo\\file", FALSE, TRUE },
+    { "foo", NULL, USE_BUFF, "file", "ext", "foo\\file.ext", FALSE, TRUE },
+    { "foo", NULL, NULL, USE_BUFF, "ext", "foo.ext", FALSE, TRUE },
+    /* remaining combinations of USE_BUFF crash native */
+    { NULL, "c", "dir", "file", "ext", "c:dir\\file.ext" },
+    { NULL, "c:", "dir", "file", "ext", "c:dir\\file.ext" }, /* 20 */
+    { NULL, "c:\\", "dir", "file", "ext", "c:dir\\file.ext" }
+};
+
 static void test_makepath(void)
 {
+    WCHAR driveW[MAX_PATH];
+    WCHAR dirW[MAX_PATH];
+    WCHAR fileW[MAX_PATH];
+    WCHAR extW[MAX_PATH];
+    WCHAR bufferW[MAX_PATH];
     char buffer[MAX_PATH];
 
-    _makepath(buffer, "C", "\\foo", "dummy", "txt");
-    ok( strcmp(buffer, "C:\\foo\\dummy.txt") == 0, "unexpected result: %s\n", buffer);
-    _makepath(buffer, "C:", "\\foo\\", "dummy", ".txt");
-    ok( strcmp(buffer, "C:\\foo\\dummy.txt") == 0, "unexpected result: %s\n", buffer);
+    unsigned int i, n;
+
+    for (i = 0; i < sizeof(makepath_cases)/sizeof(makepath_cases[0]); ++i)
+    {
+        const makepath_case* p = &makepath_cases[i];
+
+        memset(buffer, 'X', MAX_PATH);
+        if (p->buffer)
+            strcpy(buffer, p->buffer);
+
+        /* Ascii */
+        _makepath(buffer,
+                  p->drive == USE_BUFF ? buffer : p->drive,
+                  p->dir == USE_BUFF ? buffer : p->dir,
+                  p->file == USE_BUFF? buffer : p->file,
+                  p->ext == USE_BUFF ? buffer : p->ext);
+
+        buffer[MAX_PATH - 1] = '\0';
+        if (p->todoA) todo_wine {
+            ok(!strcmp(p->expected, buffer), "got '%s' for case %d\n", buffer, i);
+        }
+        else
+            ok(!strcmp(p->expected, buffer), "got '%s' for case %d\n", buffer, i);
+
+        /* Unicode */
+        if (p->drive != USE_BUFF) MultiByteToWideChar(CP_ACP, 0, p->drive, -1, driveW, MAX_PATH);
+        if (p->dir != USE_BUFF) MultiByteToWideChar(CP_ACP, 0, p->dir, -1, dirW, MAX_PATH);
+        if (p->file != USE_BUFF) MultiByteToWideChar(CP_ACP, 0, p->file, -1, fileW, MAX_PATH);
+        if (p->ext != USE_BUFF) MultiByteToWideChar(CP_ACP, 0, p->ext, -1, extW, MAX_PATH);
+
+        memset(buffer, 0, MAX_PATH);
+        for (n = 0; n < MAX_PATH; ++n)
+            bufferW[n] = 'X';
+        if (p->buffer) MultiByteToWideChar( CP_ACP, 0, p->buffer, -1, bufferW, MAX_PATH);
+
+        _wmakepath(bufferW,
+                   p->drive == USE_BUFF ? bufferW : p->drive ? driveW : NULL,
+                   p->dir == USE_BUFF ? bufferW : p->dir ? dirW : NULL,
+                   p->file == USE_BUFF? bufferW : p->file ? fileW : NULL,
+                   p->ext == USE_BUFF ? bufferW : p->ext ? extW : NULL);
 
-    /* this works with native and e.g. Freelancer depends on it */
-    strcpy(buffer, "foo");
-    _makepath(buffer, NULL, buffer, "dummy.txt", NULL);
-    ok( strcmp(buffer, "foo\\dummy.txt") == 0, "unexpected result: %s\n", buffer);
+        bufferW[MAX_PATH - 1] = '\0';
+        WideCharToMultiByte(CP_ACP, 0, bufferW, -1, buffer, MAX_PATH, NULL, NULL);
+        if (p->todoW) todo_wine {
+            ok(!strcmp(p->expected, buffer), "got '%s' for unicode case %d\n", buffer, i);
+        }
+        else
+            ok(!strcmp(p->expected, buffer), "got '%s' for unicode case %d\n", buffer, i);
+    }
 }
 
 static void test_fullpath(void)




More information about the wine-cvs mailing list