Paul Vriens : kernel32/tests: Add some GetLongPathNameA tests.

Alexandre Julliard julliard at winehq.org
Wed Dec 2 10:22:14 CST 2009


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

Author: Paul Vriens <Paul.Vriens.Wine at gmail.com>
Date:   Wed Dec  2 15:18:16 2009 +0100

kernel32/tests: Add some GetLongPathNameA tests.

---

 dlls/kernel32/tests/path.c |  100 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 100 insertions(+), 0 deletions(-)

diff --git a/dlls/kernel32/tests/path.c b/dlls/kernel32/tests/path.c
index de26fc9..ca56002 100644
--- a/dlls/kernel32/tests/path.c
+++ b/dlls/kernel32/tests/path.c
@@ -952,6 +952,99 @@ static void test_GetTempPath(void)
     SetEnvironmentVariableA("TMP", save_TMP);
 }
 
+static void test_GetLongPathNameA(void)
+{
+    DWORD length, templength, hostsize;
+    char tempfile[MAX_PATH];
+    char longpath[MAX_PATH];
+    char unc_prefix[MAX_PATH];
+    char unc_short[MAX_PATH], unc_long[MAX_PATH];
+    char temppath[MAX_PATH], temppath2[MAX_PATH];
+    HANDLE file;
+
+    if (!pGetLongPathNameA)
+        return;
+
+    GetTempPathA(MAX_PATH, tempfile);
+    lstrcatA(tempfile, "longfilename.longext");
+
+    file = CreateFileA(tempfile, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
+    CloseHandle(file);
+
+    /* Test a normal path with a small buffer size */
+    memset(temppath, 0, MAX_PATH);
+    length = pGetLongPathNameA(tempfile, temppath, 4);
+    /* We have a failure so length should be the minumum plus the terminating '0'  */
+    ok(length >= lstrlen(tempfile) + 1, "Wrong length\n");
+    ok(temppath[0] == 0, "Buffer should not have been touched\n");
+
+    /* Some UNC syntax tests */
+
+    memset(temppath, 0, MAX_PATH);
+    memset(temppath2, 0, MAX_PATH);
+    lstrcpyA(temppath2, "\\\\?\\");
+    lstrcatA(temppath2, tempfile);
+    templength = length;
+
+    length = pGetLongPathNameA(temppath2, NULL, 0);
+    ok(length == templength + 4, "Wrong length %d, expected %d\n", length, templength + 4);
+
+    length = pGetLongPathNameA(temppath2, NULL, MAX_PATH);
+    ok(length == templength + 4, "Wrong length %d, expected %d\n", length, templength + 4);
+
+    length = pGetLongPathNameA(temppath2, temppath, 4);
+    ok(length == templength + 4, "Wrong length %d, expected %d\n", length, templength + 4);
+    ok(temppath[0] == 0, "Buffer should not have been touched\n");
+
+    /* Now an UNC path with the computername */
+    lstrcpyA(unc_prefix, "\\\\");
+    hostsize = sizeof(unc_prefix) - 2;
+    GetComputerName(unc_prefix + 2, &hostsize);
+    lstrcatA(unc_prefix, "\\");
+
+    /* Create a short syntax for the whole unc path */
+    memset(unc_short, 0, MAX_PATH);
+    GetShortPathNameA(tempfile, temppath, MAX_PATH);
+    lstrcpyA(unc_short, unc_prefix);
+    unc_short[lstrlenA(unc_short)] = temppath[0];
+    lstrcatA(unc_short, "$\\");
+    lstrcatA(unc_short, strchr(temppath, '\\') + 1);
+
+    /* Create a long syntax for reference */
+    memset(longpath, 0, MAX_PATH);
+    pGetLongPathNameA(tempfile, temppath, MAX_PATH);
+    lstrcpyA(longpath, unc_prefix);
+    longpath[lstrlenA(longpath)] = temppath[0];
+    lstrcatA(longpath, "$\\");
+    lstrcatA(longpath, strchr(temppath, '\\') + 1);
+
+    /* NULL test */
+    length = pGetLongPathNameA(unc_short, NULL, 0);
+    todo_wine
+    ok(length == lstrlenA(longpath) + 1, "Wrong length, expected %d\n", length);
+
+    length = pGetLongPathNameA(unc_short, NULL, MAX_PATH);
+    todo_wine
+    ok(length == lstrlenA(longpath) + 1, "Wrong length, expected %d\n", length);
+
+    memset(unc_long, 0, MAX_PATH);
+    length = pGetLongPathNameA(unc_short, unc_long, lstrlenA(unc_short));
+    /* length will include terminating '0' on failure */
+    todo_wine
+    ok(length == lstrlenA(longpath) + 1, "Wrong length, expected %d\n", length);
+    ok(unc_long[0] == 0, "Buffer should not have been touched\n");
+
+    memset(unc_long, 0, MAX_PATH);
+    templength = length;
+    length = pGetLongPathNameA(unc_short, unc_long, length);
+    /* length doesn't include terminating '0' on success */
+    ok(length == templength - 1, "Wrong length %d, expected %d\n", length, templength - 1);
+    todo_wine
+    ok(!lstrcmpiA(unc_long, longpath), "Expected (%s), got (%s)\n", longpath, unc_long);
+
+    DeleteFileA(tempfile);
+}
+
 static void test_GetLongPathNameW(void)
 {
     DWORD length; 
@@ -1273,11 +1366,18 @@ START_TEST(path)
         (void*)GetProcAddress( GetModuleHandleA("kernel32.dll"),
                                "NeedCurrentDirectoryForExePathW" );
 
+    /* Report only once */
+    if (!pGetLongPathNameA)
+        win_skip("GetLongPathNameA is not available\n");
+    if (!pGetLongPathNameW)
+        win_skip("GetLongPathNameW is not available\n");
+
     test_InitPathA(curdir, &curDrive, &otherDrive);
     test_CurrentDirectoryA(origdir,curdir);
     test_PathNameA(curdir, curDrive, otherDrive);
     test_CleanupPathA(origdir,curdir);
     test_GetTempPath();
+    test_GetLongPathNameA();
     test_GetLongPathNameW();
     test_GetShortPathNameW();
     test_GetSystemDirectory();




More information about the wine-cvs mailing list