> I doubt shell32 function on windows does this check, also original windows shell32
> function is a lot more complicated and longer, I've compared the results between
> real and my code and they are correct.
I wrote a small test for this function showing that your implementation is almost
correct. It failes in two cases:
1. If a path ends with '\' and is compared with one that doesn't, then it's length is
less than the other one, but both are the same paths.
2. If a path doesn't end with '\' and is compared with a longer one that has the same
first len chars, but is not the same, ex:
c:\test
c:\test123
Changelog:
Added test for PathIsEqualOrSubFolder
Index: dlls/shell32/tests/shellpath.c
===================================================================
RCS file: /home/wine/wine/dlls/shell32/tests/shellpath.c,v
retrieving revision 1.6
diff -u -p -r1.6 shellpath.c
--- dlls/shell32/tests/shellpath.c 10 Feb 2005 19:19:35 -0000 1.6
+++ dlls/shell32/tests/shellpath.c 28 Feb 2005 21:19:31 -0000
@@ -871,6 +871,55 @@ static void testNonExistentPath(void)
userShellFolders);
}
+typedef BOOL (WINAPI*fnPathIsEqualOrSubFolder)(LPCWSTR path1, LPCWSTR path2);
+
+static void test_PathIsEqualOrSubFolder()
+{
+ fnPathIsEqualOrSubFolder pPathIsEqualOrSubFolder;
+ BOOL ret;
+ static const WCHAR path1[] = {'c',':','\\','t','e','s','t',0};
+ static const WCHAR path2[] = {'c',':','\\','t','e','s','t','\\','t','e','s','t',0};
+ static const WCHAR path3[] = {'c',':','\\','t','e','s','t','1','2','3',0};
+ static const WCHAR path4[] = {'c',':','\\','t','e','s','t','\\',0};
+ static const WCHAR path5[] = {'c',':','\\','t','e','s','t','\\','t','e','s','t','2',
+ '\\','.','.','\\','t','e','s','t',0};
+
+ pPathIsEqualOrSubFolder = GetProcAddress(hShell32, (LPSTR)755);
+ if(!pPathIsEqualOrSubFolder)
+ return;
+
+#define TEST_PATH(p1, p2, r) \
+ ret = pPathIsEqualOrSubFolder(p1, p2); \
+ ok(ret == r, "PathIsEqualOrSubFolder(" #p1 " " #p2 ") failed, expected: %x\n", r);
+
+ TEST_PATH(path1, path1, TRUE);
+ TEST_PATH(path1, path2, TRUE);
+ TEST_PATH(path1, path3, FALSE);
+ TEST_PATH(path1, path4, TRUE);
+ TEST_PATH(path2, path1, FALSE);
+ TEST_PATH(path2, path2, TRUE);
+ TEST_PATH(path2, path3, FALSE);
+ TEST_PATH(path2, path4, FALSE);
+ TEST_PATH(path3, path1, FALSE);
+ TEST_PATH(path3, path2, FALSE);
+ TEST_PATH(path3, path3, TRUE);
+ TEST_PATH(path3, path4, FALSE);
+ TEST_PATH(path4, path1, TRUE);
+ TEST_PATH(path4, path2, TRUE);
+ TEST_PATH(path4, path3, FALSE);
+ TEST_PATH(path4, path4, TRUE);
+ TEST_PATH(path5, path1, FALSE);
+ TEST_PATH(path5, path2, FALSE);
+ TEST_PATH(path5, path3, FALSE);
+ TEST_PATH(path5, path4, FALSE);
+ TEST_PATH(path5, path5, TRUE);
+ TEST_PATH(NULL, path1, FALSE);
+ TEST_PATH(path1, NULL, FALSE);
+ TEST_PATH(NULL, NULL, FALSE);
+
+#undef TEST_PATH
+}
+
START_TEST(shellpath)
{
if (!init()) return;
@@ -892,5 +941,6 @@ START_TEST(shellpath)
testWinDir();
testSystemDir();
testNonExistentPath();
+ test_PathIsEqualOrSubFolder();
}
}