[2/2] shell32/tests: Copy the PathRemoveBackslashA() and PathAddBackslashW() implementations because shlwapi.dll is missing on Windows 95.

Francois Gouget fgouget at free.fr
Tue Dec 18 03:00:47 CST 2007


---
 dlls/shell32/tests/Makefile.in |    2 +-
 dlls/shell32/tests/shellpath.c |   31 ++++++++++++++++++++++++++-----
 dlls/shell32/tests/shlfolder.c |   30 +++++++++++++++++++++++++-----
 3 files changed, 52 insertions(+), 11 deletions(-)

diff --git a/dlls/shell32/tests/Makefile.in b/dlls/shell32/tests/Makefile.in
index cd15eb3..364bb3d 100644
--- a/dlls/shell32/tests/Makefile.in
+++ b/dlls/shell32/tests/Makefile.in
@@ -3,7 +3,7 @@ TOPOBJDIR = ../../..
 SRCDIR    = @srcdir@
 VPATH     = @srcdir@
 TESTDLL   = shell32.dll
-IMPORTS   = shell32 ole32 oleaut32 shlwapi user32 advapi32 kernel32
+IMPORTS   = shell32 ole32 oleaut32 user32 advapi32 kernel32
 EXTRALIBS = -luuid
 
 CTESTS = \
diff --git a/dlls/shell32/tests/shellpath.c b/dlls/shell32/tests/shellpath.c
index 8c237df..6fb485e 100644
--- a/dlls/shell32/tests/shellpath.c
+++ b/dlls/shell32/tests/shellpath.c
@@ -642,6 +642,27 @@ static void testEnvVars(void)
     matchSpecialFolderPathToEnv(CSIDL_SYSTEM, "winsysdir");
 }
 
+/* Loosely based on PathRemoveBackslashA from dlls/shlwapi/path.c */
+static BOOL myPathIsRootA(LPCSTR lpszPath)
+{
+  if (lpszPath && *lpszPath &&
+      lpszPath[1] == ':' && lpszPath[2] == '\\' && lpszPath[3] == '\0')
+      return TRUE; /* X:\ */
+  return FALSE;
+}
+static LPSTR myPathRemoveBackslashA( LPSTR lpszPath )
+{
+  LPSTR szTemp = NULL;
+
+  if(lpszPath)
+  {
+    szTemp = CharPrevA(lpszPath, lpszPath + strlen(lpszPath));
+    if (!myPathIsRootA(lpszPath) && *szTemp == '\\')
+      *szTemp = '\0';
+  }
+  return szTemp;
+}
+
 /* Verifies the shell path for CSIDL_WINDOWS matches the return from
  * GetWindowsDirectory.  If SHGetSpecialFolderPath fails, no harm, no foul--not
  * every shell32 version supports CSIDL_WINDOWS.
@@ -654,9 +675,9 @@ static void testWinDir(void)
 
     if (pSHGetSpecialFolderPathA(NULL, windowsShellPath, CSIDL_WINDOWS, FALSE))
     {
-        PathRemoveBackslashA(windowsShellPath);
+        myPathRemoveBackslashA(windowsShellPath);
         GetWindowsDirectoryA(windowsDir, sizeof(windowsDir));
-        PathRemoveBackslashA(windowsDir);
+        myPathRemoveBackslashA(windowsDir);
         ok(!lstrcmpiA(windowsDir, windowsShellPath),
          "GetWindowsDirectory does not match SHGetSpecialFolderPath:\n"
          "GetWindowsDirectory returns %s\nSHGetSpecialFolderPath returns %s\n",
@@ -675,10 +696,10 @@ static void testSystemDir(void)
     if (!pSHGetSpecialFolderPathA) return;
 
     GetSystemDirectoryA(systemDir, sizeof(systemDir));
-    PathRemoveBackslashA(systemDir);
+    myPathRemoveBackslashA(systemDir);
     if (pSHGetSpecialFolderPathA(NULL, systemShellPath, CSIDL_SYSTEM, FALSE))
     {
-        PathRemoveBackslashA(systemShellPath);
+        myPathRemoveBackslashA(systemShellPath);
         ok(!lstrcmpiA(systemDir, systemShellPath),
          "GetSystemDirectory does not match SHGetSpecialFolderPath:\n"
          "GetSystemDirectory returns %s\nSHGetSpecialFolderPath returns %s\n",
@@ -689,7 +710,7 @@ static void testSystemDir(void)
      */
     if (pSHGetSpecialFolderPathA(NULL, systemShellPath, CSIDL_SYSTEMX86, FALSE))
     {
-        PathRemoveBackslashA(systemShellPath);
+        myPathRemoveBackslashA(systemShellPath);
         ok(!lstrcmpiA(systemDir, systemShellPath),
          "GetSystemDirectory does not match SHGetSpecialFolderPath:\n"
          "GetSystemDirectory returns %s\nSHGetSpecialFolderPath returns %s\n",
diff --git a/dlls/shell32/tests/shlfolder.c b/dlls/shell32/tests/shlfolder.c
index 2941670..59e032e 100644
--- a/dlls/shell32/tests/shlfolder.c
+++ b/dlls/shell32/tests/shlfolder.c
@@ -326,7 +326,27 @@ static void test_BindToObject(void)
 
     IShellFolder_Release(psfSystemDir);
 }
-  
+
+/* Based on PathAddBackslashW from dlls/shlwapi/path.c */
+static LPWSTR myPathAddBackslashW( LPWSTR lpszPath )
+{
+  size_t iLen;
+
+  if (!lpszPath || (iLen = lstrlenW(lpszPath)) >= MAX_PATH)
+    return NULL;
+
+  if (iLen)
+  {
+    lpszPath += iLen;
+    if (lpszPath[-1] != '\\')
+    {
+      *lpszPath++ = '\\';
+      *lpszPath = '\0';
+    }
+  }
+  return lpszPath;
+}
+
 static void test_GetDisplayName(void)
 {
     BOOL result;
@@ -359,7 +379,7 @@ static void test_GetDisplayName(void)
     ok(result, "SHGetSpecialFolderPathW failed! Last error: %u\n", GetLastError());
     if (!result) return;
 
-    PathAddBackslashW(wszTestDir);
+    myPathAddBackslashW(wszTestDir);
     lstrcatW(wszTestDir, wszDirName);
     /* Use ANSI file functions so this works on Windows 9x */
     WideCharToMultiByte(CP_ACP, 0, wszTestDir, -1, szTestDir, MAX_PATH, 0, 0);
@@ -372,7 +392,7 @@ static void test_GetDisplayName(void)
     }
 
     lstrcpyW(wszTestFile, wszTestDir);
-    PathAddBackslashW(wszTestFile);
+    myPathAddBackslashW(wszTestFile);
     lstrcatW(wszTestFile, wszFileName);
     WideCharToMultiByte(CP_ACP, 0, wszTestFile, -1, szTestFile, MAX_PATH, 0, 0);
 
@@ -833,7 +853,7 @@ static void test_SHGetPathFromIDList(void)
         IShellFolder_Release(psfDesktop);
         return;
     }
-    PathAddBackslashW(wszFileName);
+    myPathAddBackslashW(wszFileName);
     lstrcatW(wszFileName, wszTestFile);
     hTestFile = CreateFileW(wszFileName, GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, NULL);
     ok(hTestFile != INVALID_HANDLE_VALUE, "CreateFileW failed! Last error: %u\n", GetLastError());
@@ -1162,7 +1182,7 @@ static void test_FolderShortcut(void) {
 
     /* Next few lines are meant to show that children of FolderShortcuts are not FolderShortcuts,
      * but ShellFSFolders. */
-    PathAddBackslashW(wszDesktopPath);
+    myPathAddBackslashW(wszDesktopPath);
     lstrcatW(wszDesktopPath, wszSomeSubFolder);
     if (!CreateDirectoryW(wszDesktopPath, NULL)) {
         IShellFolder_Release(pShellFolder);
-- 
1.5.3.4




More information about the wine-patches mailing list