From b652e93a460b4b822a01382e5992f96f1d805ffe Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Fri, 3 Jun 2022 17:47:54 -0500 Subject: Replace PathCompare with PathCompareCanonicalized. --- src/libs/dutil/test/DUtilUnitTest/PathUtilTest.cpp | 69 ++++++++++++++++++++++ 1 file changed, 69 insertions(+) (limited to 'src/libs/dutil/test/DUtilUnitTest/PathUtilTest.cpp') diff --git a/src/libs/dutil/test/DUtilUnitTest/PathUtilTest.cpp b/src/libs/dutil/test/DUtilUnitTest/PathUtilTest.cpp index 554c6f00..2505c6bf 100644 --- a/src/libs/dutil/test/DUtilUnitTest/PathUtilTest.cpp +++ b/src/libs/dutil/test/DUtilUnitTest/PathUtilTest.cpp @@ -151,6 +151,10 @@ namespace DutilTests NativeAssert::Succeeded(hr, "Failed to canonicalize path"); NativeAssert::StringEqual(L"\\\\otherdir\\unc.exe", sczCanonicalized); + hr = PathCanonicalizeForComparison(L"\\??\\UNC\\server\\share\\dir", PATH_CANONICALIZE_KEEP_UNC_ROOT, &sczCanonicalized); + NativeAssert::Succeeded(hr, "Failed to canonicalize path"); + NativeAssert::StringEqual(L"\\\\?\\UNC\\server\\share\\dir", sczCanonicalized); + hr = PathCanonicalizeForComparison(L"\\\\?\\UNC\\server\\share\\..\\..\\otherdir\\unc.exe", PATH_CANONICALIZE_KEEP_UNC_ROOT, &sczCanonicalized); NativeAssert::Succeeded(hr, "Failed to canonicalize path"); NativeAssert::StringEqual(L"\\\\?\\UNC\\server\\share\\otherdir\\unc.exe", sczCanonicalized); @@ -203,6 +207,10 @@ namespace DutilTests NativeAssert::Succeeded(hr, "Failed to canonicalize path"); NativeAssert::StringEqual(L"\\\\?\\invalidlongpath.exe", sczCanonicalized); + hr = PathCanonicalizeForComparison(L"\\??\\test\\..\\invalidlongpath.exe", 0, &sczCanonicalized); + NativeAssert::Succeeded(hr, "Failed to canonicalize path"); + NativeAssert::StringEqual(L"\\\\?\\invalidlongpath.exe", sczCanonicalized); + hr = PathCanonicalizeForComparison(L"C:\\.\\invalid:pathchars?.exe", 0, &sczCanonicalized); NativeAssert::Succeeded(hr, "Failed to canonicalize path"); NativeAssert::StringEqual(L"C:\\invalid:pathchars?.exe", sczCanonicalized); @@ -263,6 +271,67 @@ namespace DutilTests } } + [Fact] + void PathCompareCanonicalizeEqualTest() + { + HRESULT hr = S_OK; + LPWSTR sczPath = NULL; + BOOL fEqual = FALSE; + LPCWSTR rgwzPaths[14] = + { + L"C:\\simplepath", L"C:\\simplepath", + L"\\\\server\\share\\dir\\dir2\\..\\otherdir\\unc.exe", L"\\\\server\\share\\dir\\otherdir\\unc.exe", + L"\\\\server\\share\\..\\..\\otherdir\\unc.exe", L"\\\\server\\share\\otherdir\\unc.exe", + L"\\\\?\\UNC\\server\\share\\..\\..\\otherdir\\unc.exe", L"\\\\?\\UNC\\server\\share\\otherdir\\unc.exe", + L"C:\\dir\\subdir\\..\\..\\..\\otherdir\\pastroot.exe", L"C:\\otherdir\\pastroot.exe", + L"\\\\?\\C:\\dir\\subdir\\..\\..\\..\\otherdir\\pastroot.exe", L"C:\\..\\otherdir\\pastroot.exe", + L"\\??\\C:\\dir", L"\\\\?\\C:\\dir", + }; + + try + { + for (DWORD i = 0; i < countof(rgwzPaths); i += 2) + { + hr = PathCompareCanonicalized(rgwzPaths[i], rgwzPaths[i + 1], &fEqual); + NativeAssert::Succeeded(hr, "PathCompareCanonicalized: {0}, {1}", rgwzPaths[i], rgwzPaths[i + 1]); + Assert::True(fEqual, String::Format("PathCompareCanonicalized: {0}, {1}", gcnew String(rgwzPaths[i]), gcnew String(rgwzPaths[i + 1]))); + } + } + finally + { + ReleaseStr(sczPath); + } + } + + [Fact] + void PathCompareCanonicalizeNotEqualTest() + { + HRESULT hr = S_OK; + LPWSTR sczPath = NULL; + BOOL fEqual = FALSE; + LPCWSTR rgwzPaths[8] = + { + L"C:\\simplepath", L"D:\\simplepath", + L"\\\\.\\share\\otherdir\\unc.exe", L"\\\\share\\otherdir\\unc.exe", + L"\\\\server\\.\\otherdir\\unc.exe", L"\\\\server\\otherdir\\unc.exe", + L"\\\\server\\\\otherdir\\unc.exe", L"\\\\server\\otherdir\\unc.exe", + }; + + try + { + for (DWORD i = 0; i < countof(rgwzPaths); i += 2) + { + hr = PathCompareCanonicalized(rgwzPaths[i], rgwzPaths[i + 1], &fEqual); + NativeAssert::Succeeded(hr, "PathCompareCanonicalized: {0}, {1}", rgwzPaths[i], rgwzPaths[i + 1]); + Assert::False(fEqual, String::Format("PathCompareCanonicalized: {0}, {1}", gcnew String(rgwzPaths[i]), gcnew String(rgwzPaths[i + 1]))); + } + } + finally + { + ReleaseStr(sczPath); + } + } + [Fact] void PathConcatRelativeToBaseTest() { -- cgit v1.2.3-55-g6feb