diff options
Diffstat (limited to 'src/libs/dutil/test/DUtilUnitTest/PathUtilTest.cpp')
| -rw-r--r-- | src/libs/dutil/test/DUtilUnitTest/PathUtilTest.cpp | 69 |
1 files changed, 69 insertions, 0 deletions
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 | |||
| 151 | NativeAssert::Succeeded(hr, "Failed to canonicalize path"); | 151 | NativeAssert::Succeeded(hr, "Failed to canonicalize path"); |
| 152 | NativeAssert::StringEqual(L"\\\\otherdir\\unc.exe", sczCanonicalized); | 152 | NativeAssert::StringEqual(L"\\\\otherdir\\unc.exe", sczCanonicalized); |
| 153 | 153 | ||
| 154 | hr = PathCanonicalizeForComparison(L"\\??\\UNC\\server\\share\\dir", PATH_CANONICALIZE_KEEP_UNC_ROOT, &sczCanonicalized); | ||
| 155 | NativeAssert::Succeeded(hr, "Failed to canonicalize path"); | ||
| 156 | NativeAssert::StringEqual(L"\\\\?\\UNC\\server\\share\\dir", sczCanonicalized); | ||
| 157 | |||
| 154 | hr = PathCanonicalizeForComparison(L"\\\\?\\UNC\\server\\share\\..\\..\\otherdir\\unc.exe", PATH_CANONICALIZE_KEEP_UNC_ROOT, &sczCanonicalized); | 158 | hr = PathCanonicalizeForComparison(L"\\\\?\\UNC\\server\\share\\..\\..\\otherdir\\unc.exe", PATH_CANONICALIZE_KEEP_UNC_ROOT, &sczCanonicalized); |
| 155 | NativeAssert::Succeeded(hr, "Failed to canonicalize path"); | 159 | NativeAssert::Succeeded(hr, "Failed to canonicalize path"); |
| 156 | NativeAssert::StringEqual(L"\\\\?\\UNC\\server\\share\\otherdir\\unc.exe", sczCanonicalized); | 160 | NativeAssert::StringEqual(L"\\\\?\\UNC\\server\\share\\otherdir\\unc.exe", sczCanonicalized); |
| @@ -203,6 +207,10 @@ namespace DutilTests | |||
| 203 | NativeAssert::Succeeded(hr, "Failed to canonicalize path"); | 207 | NativeAssert::Succeeded(hr, "Failed to canonicalize path"); |
| 204 | NativeAssert::StringEqual(L"\\\\?\\invalidlongpath.exe", sczCanonicalized); | 208 | NativeAssert::StringEqual(L"\\\\?\\invalidlongpath.exe", sczCanonicalized); |
| 205 | 209 | ||
| 210 | hr = PathCanonicalizeForComparison(L"\\??\\test\\..\\invalidlongpath.exe", 0, &sczCanonicalized); | ||
| 211 | NativeAssert::Succeeded(hr, "Failed to canonicalize path"); | ||
| 212 | NativeAssert::StringEqual(L"\\\\?\\invalidlongpath.exe", sczCanonicalized); | ||
| 213 | |||
| 206 | hr = PathCanonicalizeForComparison(L"C:\\.\\invalid:pathchars?.exe", 0, &sczCanonicalized); | 214 | hr = PathCanonicalizeForComparison(L"C:\\.\\invalid:pathchars?.exe", 0, &sczCanonicalized); |
| 207 | NativeAssert::Succeeded(hr, "Failed to canonicalize path"); | 215 | NativeAssert::Succeeded(hr, "Failed to canonicalize path"); |
| 208 | NativeAssert::StringEqual(L"C:\\invalid:pathchars?.exe", sczCanonicalized); | 216 | NativeAssert::StringEqual(L"C:\\invalid:pathchars?.exe", sczCanonicalized); |
| @@ -264,6 +272,67 @@ namespace DutilTests | |||
| 264 | } | 272 | } |
| 265 | 273 | ||
| 266 | [Fact] | 274 | [Fact] |
| 275 | void PathCompareCanonicalizeEqualTest() | ||
| 276 | { | ||
| 277 | HRESULT hr = S_OK; | ||
| 278 | LPWSTR sczPath = NULL; | ||
| 279 | BOOL fEqual = FALSE; | ||
| 280 | LPCWSTR rgwzPaths[14] = | ||
| 281 | { | ||
| 282 | L"C:\\simplepath", L"C:\\simplepath", | ||
| 283 | L"\\\\server\\share\\dir\\dir2\\..\\otherdir\\unc.exe", L"\\\\server\\share\\dir\\otherdir\\unc.exe", | ||
| 284 | L"\\\\server\\share\\..\\..\\otherdir\\unc.exe", L"\\\\server\\share\\otherdir\\unc.exe", | ||
| 285 | L"\\\\?\\UNC\\server\\share\\..\\..\\otherdir\\unc.exe", L"\\\\?\\UNC\\server\\share\\otherdir\\unc.exe", | ||
| 286 | L"C:\\dir\\subdir\\..\\..\\..\\otherdir\\pastroot.exe", L"C:\\otherdir\\pastroot.exe", | ||
| 287 | L"\\\\?\\C:\\dir\\subdir\\..\\..\\..\\otherdir\\pastroot.exe", L"C:\\..\\otherdir\\pastroot.exe", | ||
| 288 | L"\\??\\C:\\dir", L"\\\\?\\C:\\dir", | ||
| 289 | }; | ||
| 290 | |||
| 291 | try | ||
| 292 | { | ||
| 293 | for (DWORD i = 0; i < countof(rgwzPaths); i += 2) | ||
| 294 | { | ||
| 295 | hr = PathCompareCanonicalized(rgwzPaths[i], rgwzPaths[i + 1], &fEqual); | ||
| 296 | NativeAssert::Succeeded(hr, "PathCompareCanonicalized: {0}, {1}", rgwzPaths[i], rgwzPaths[i + 1]); | ||
| 297 | Assert::True(fEqual, String::Format("PathCompareCanonicalized: {0}, {1}", gcnew String(rgwzPaths[i]), gcnew String(rgwzPaths[i + 1]))); | ||
| 298 | } | ||
| 299 | } | ||
| 300 | finally | ||
| 301 | { | ||
| 302 | ReleaseStr(sczPath); | ||
| 303 | } | ||
| 304 | } | ||
| 305 | |||
| 306 | [Fact] | ||
| 307 | void PathCompareCanonicalizeNotEqualTest() | ||
| 308 | { | ||
| 309 | HRESULT hr = S_OK; | ||
| 310 | LPWSTR sczPath = NULL; | ||
| 311 | BOOL fEqual = FALSE; | ||
| 312 | LPCWSTR rgwzPaths[8] = | ||
| 313 | { | ||
| 314 | L"C:\\simplepath", L"D:\\simplepath", | ||
| 315 | L"\\\\.\\share\\otherdir\\unc.exe", L"\\\\share\\otherdir\\unc.exe", | ||
| 316 | L"\\\\server\\.\\otherdir\\unc.exe", L"\\\\server\\otherdir\\unc.exe", | ||
| 317 | L"\\\\server\\\\otherdir\\unc.exe", L"\\\\server\\otherdir\\unc.exe", | ||
| 318 | }; | ||
| 319 | |||
| 320 | try | ||
| 321 | { | ||
| 322 | for (DWORD i = 0; i < countof(rgwzPaths); i += 2) | ||
| 323 | { | ||
| 324 | hr = PathCompareCanonicalized(rgwzPaths[i], rgwzPaths[i + 1], &fEqual); | ||
| 325 | NativeAssert::Succeeded(hr, "PathCompareCanonicalized: {0}, {1}", rgwzPaths[i], rgwzPaths[i + 1]); | ||
| 326 | Assert::False(fEqual, String::Format("PathCompareCanonicalized: {0}, {1}", gcnew String(rgwzPaths[i]), gcnew String(rgwzPaths[i + 1]))); | ||
| 327 | } | ||
| 328 | } | ||
| 329 | finally | ||
| 330 | { | ||
| 331 | ReleaseStr(sczPath); | ||
| 332 | } | ||
| 333 | } | ||
| 334 | |||
| 335 | [Fact] | ||
| 267 | void PathConcatRelativeToBaseTest() | 336 | void PathConcatRelativeToBaseTest() |
| 268 | { | 337 | { |
| 269 | HRESULT hr = S_OK; | 338 | HRESULT hr = S_OK; |
