diff options
author | Sean Hall <r.sean.hall@gmail.com> | 2022-06-24 12:28:27 -0500 |
---|---|---|
committer | Sean Hall <r.sean.hall@gmail.com> | 2022-06-27 11:14:21 -0500 |
commit | eb53852d7ae6838e54525eb57df1d8ce8a722f9b (patch) | |
tree | 7fa05bd6df1bce2e20d87c5fbacc1c658dc000aa /src/libs/dutil/test/DUtilUnitTest | |
parent | 6ee12a64cb75097a238e60d4fd0ea542e8312214 (diff) | |
download | wix-eb53852d7ae6838e54525eb57df1d8ce8a722f9b.tar.gz wix-eb53852d7ae6838e54525eb57df1d8ce8a722f9b.tar.bz2 wix-eb53852d7ae6838e54525eb57df1d8ce8a722f9b.zip |
Add longPathAware to Burn manifest to support long paths.
Fixes 3455
Diffstat (limited to 'src/libs/dutil/test/DUtilUnitTest')
-rw-r--r-- | src/libs/dutil/test/DUtilUnitTest/PathUtilTest.cpp | 182 |
1 files changed, 180 insertions, 2 deletions
diff --git a/src/libs/dutil/test/DUtilUnitTest/PathUtilTest.cpp b/src/libs/dutil/test/DUtilUnitTest/PathUtilTest.cpp index e9ef1047..109c558c 100644 --- a/src/libs/dutil/test/DUtilUnitTest/PathUtilTest.cpp +++ b/src/libs/dutil/test/DUtilUnitTest/PathUtilTest.cpp | |||
@@ -7,6 +7,11 @@ using namespace System::IO; | |||
7 | using namespace Xunit; | 7 | using namespace Xunit; |
8 | using namespace WixBuildTools::TestSupport; | 8 | using namespace WixBuildTools::TestSupport; |
9 | 9 | ||
10 | // from PathCch.h | ||
11 | #ifndef PATHCCH_ALLOW_LONG_PATHS | ||
12 | #define PATHCCH_ALLOW_LONG_PATHS 0x01 | ||
13 | #endif | ||
14 | |||
10 | namespace DutilTests | 15 | namespace DutilTests |
11 | { | 16 | { |
12 | public ref class PathUtil | 17 | public ref class PathUtil |
@@ -102,18 +107,54 @@ namespace DutilTests | |||
102 | } | 107 | } |
103 | 108 | ||
104 | [Fact] | 109 | [Fact] |
110 | void PathCanonicalizeForComparisonFallbackTest() | ||
111 | { | ||
112 | Path2FunctionForceFallback(); | ||
113 | |||
114 | try | ||
115 | { | ||
116 | PathCanonicalizeForComparisonTestCore(FALSE); | ||
117 | } | ||
118 | finally | ||
119 | { | ||
120 | Path2FunctionAllowFallback(); | ||
121 | } | ||
122 | } | ||
123 | |||
124 | [Fact] | ||
105 | void PathCanonicalizeForComparisonTest() | 125 | void PathCanonicalizeForComparisonTest() |
106 | { | 126 | { |
127 | PathCanonicalizeForComparisonTestCore(TRUE); | ||
128 | } | ||
129 | |||
130 | void PathCanonicalizeForComparisonTestCore(BOOL fLongPathSupported) | ||
131 | { | ||
107 | HRESULT hr = S_OK; | 132 | HRESULT hr = S_OK; |
108 | LPWSTR sczCanonicalized = NULL; | 133 | LPWSTR sczCanonicalized = NULL; |
109 | 134 | ||
110 | try | 135 | try |
111 | { | 136 | { |
112 | hr = PathCanonicalizeForComparison(L"C:\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789", 0, &sczCanonicalized); | 137 | hr = PathCanonicalizeForComparison(L"C:\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789", 0, &sczCanonicalized); |
113 | Assert::Equal<HRESULT>(HRESULT_FROM_WIN32(ERROR_FILENAME_EXCED_RANGE), hr); | 138 | if (!fLongPathSupported) |
139 | { | ||
140 | Assert::Equal<HRESULT>(HRESULT_FROM_WIN32(ERROR_FILENAME_EXCED_RANGE), hr); | ||
141 | } | ||
142 | else | ||
143 | { | ||
144 | NativeAssert::Succeeded(hr, "Failed to canonicalize path"); | ||
145 | NativeAssert::StringEqual(L"\\\\?\\C:\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789", sczCanonicalized); | ||
146 | } | ||
114 | 147 | ||
115 | hr = PathCanonicalizeForComparison(L"\\\\?\\C:\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789", 0, &sczCanonicalized); | 148 | hr = PathCanonicalizeForComparison(L"\\\\?\\C:\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789", 0, &sczCanonicalized); |
116 | Assert::Equal<HRESULT>(HRESULT_FROM_WIN32(ERROR_FILENAME_EXCED_RANGE), hr); | 149 | if (!fLongPathSupported) |
150 | { | ||
151 | Assert::Equal<HRESULT>(HRESULT_FROM_WIN32(ERROR_FILENAME_EXCED_RANGE), hr); | ||
152 | } | ||
153 | else | ||
154 | { | ||
155 | NativeAssert::Succeeded(hr, "Failed to canonicalize path"); | ||
156 | NativeAssert::StringEqual(L"\\\\?\\C:\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789", sczCanonicalized); | ||
157 | } | ||
117 | 158 | ||
118 | hr = PathCanonicalizeForComparison(L"\\\\server", PATH_CANONICALIZE_KEEP_UNC_ROOT, &sczCanonicalized); | 159 | hr = PathCanonicalizeForComparison(L"\\\\server", PATH_CANONICALIZE_KEEP_UNC_ROOT, &sczCanonicalized); |
119 | NativeAssert::Succeeded(hr, "Failed to canonicalize path"); | 160 | NativeAssert::Succeeded(hr, "Failed to canonicalize path"); |
@@ -238,6 +279,52 @@ namespace DutilTests | |||
238 | } | 279 | } |
239 | 280 | ||
240 | [Fact] | 281 | [Fact] |
282 | void PathAllocCanonicalizePathTest() | ||
283 | { | ||
284 | HRESULT hr = S_OK; | ||
285 | LPWSTR sczCanonicalized = NULL; | ||
286 | |||
287 | try | ||
288 | { | ||
289 | hr = PathAllocCanonicalizePath(L"C:\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789", PATHCCH_ALLOW_LONG_PATHS, &sczCanonicalized); | ||
290 | NativeAssert::Succeeded(hr, "Failed to canonicalize path"); | ||
291 | NativeAssert::StringEqual(L"\\\\?\\C:\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789", sczCanonicalized); | ||
292 | |||
293 | hr = PathAllocCanonicalizePath(L"abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789", PATHCCH_ALLOW_LONG_PATHS, &sczCanonicalized); | ||
294 | NativeAssert::Succeeded(hr, "Failed to canonicalize path"); | ||
295 | NativeAssert::StringEqual(L"abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789", sczCanonicalized); | ||
296 | |||
297 | hr = PathAllocCanonicalizePath(L"\\\\server\\share\\..\\..\\otherdir\\unc.exe", PATHCCH_ALLOW_LONG_PATHS, &sczCanonicalized); | ||
298 | NativeAssert::Succeeded(hr, "Failed to canonicalize path"); | ||
299 | NativeAssert::StringEqual(L"\\\\otherdir\\unc.exe", sczCanonicalized); // This is surprising. | ||
300 | |||
301 | hr = PathAllocCanonicalizePath(L"C:\\dir\\subdir\\..\\..\\otherdir\\backslashes.exe", PATHCCH_ALLOW_LONG_PATHS, &sczCanonicalized); | ||
302 | NativeAssert::Succeeded(hr, "Failed to canonicalize path"); | ||
303 | NativeAssert::StringEqual(L"C:\\otherdir\\backslashes.exe", sczCanonicalized); | ||
304 | |||
305 | hr = PathAllocCanonicalizePath(L"C:/dir/subdir/../../otherdir/forwardslashes.exe", PATHCCH_ALLOW_LONG_PATHS, &sczCanonicalized); | ||
306 | NativeAssert::Succeeded(hr, "Failed to canonicalize path"); | ||
307 | NativeAssert::StringEqual(L"C:/dir/subdir/../../otherdir/forwardslashes.exe", sczCanonicalized); | ||
308 | |||
309 | hr = PathAllocCanonicalizePath(L"\\\\?\\C:\\test\\..\\validlongpath.exe", PATHCCH_ALLOW_LONG_PATHS, &sczCanonicalized); | ||
310 | NativeAssert::Succeeded(hr, "Failed to canonicalize path"); | ||
311 | NativeAssert::StringEqual(L"C:\\validlongpath.exe", sczCanonicalized); | ||
312 | |||
313 | hr = PathAllocCanonicalizePath(L"\\\\?\\test\\..\\invalidlongpath.exe", PATHCCH_ALLOW_LONG_PATHS, &sczCanonicalized); | ||
314 | NativeAssert::Succeeded(hr, "Failed to canonicalize path"); | ||
315 | NativeAssert::StringEqual(L"\\\\?\\invalidlongpath.exe", sczCanonicalized); | ||
316 | |||
317 | hr = PathAllocCanonicalizePath(L"C:\\.\\invalid:pathchars?.exe", PATHCCH_ALLOW_LONG_PATHS, &sczCanonicalized); | ||
318 | NativeAssert::Succeeded(hr, "Failed to canonicalize path"); | ||
319 | NativeAssert::StringEqual(L"C:\\invalid:pathchars?.exe", sczCanonicalized); | ||
320 | } | ||
321 | finally | ||
322 | { | ||
323 | ReleaseStr(sczCanonicalized); | ||
324 | } | ||
325 | } | ||
326 | |||
327 | [Fact] | ||
241 | void PathConcatTest() | 328 | void PathConcatTest() |
242 | { | 329 | { |
243 | HRESULT hr = S_OK; | 330 | HRESULT hr = S_OK; |
@@ -545,6 +632,25 @@ namespace DutilTests | |||
545 | } | 632 | } |
546 | 633 | ||
547 | [Fact] | 634 | [Fact] |
635 | void PathForCurrentProcessTest() | ||
636 | { | ||
637 | HRESULT hr = S_OK; | ||
638 | LPWSTR sczPath = NULL; | ||
639 | |||
640 | try | ||
641 | { | ||
642 | hr = PathForCurrentProcess(&sczPath, NULL); | ||
643 | NativeAssert::Succeeded(hr, "Failed to get current process path."); | ||
644 | |||
645 | WixAssert::StringEqual(System::Diagnostics::Process::GetCurrentProcess()->MainModule->FileName, gcnew String(sczPath), false); | ||
646 | } | ||
647 | finally | ||
648 | { | ||
649 | ReleaseStr(sczPath); | ||
650 | } | ||
651 | } | ||
652 | |||
653 | [Fact] | ||
548 | void PathGetDirectoryTest() | 654 | void PathGetDirectoryTest() |
549 | { | 655 | { |
550 | HRESULT hr = S_OK; | 656 | HRESULT hr = S_OK; |
@@ -828,6 +934,78 @@ namespace DutilTests | |||
828 | } | 934 | } |
829 | 935 | ||
830 | [Fact] | 936 | [Fact] |
937 | void PathGetTempPathTest() | ||
938 | { | ||
939 | HRESULT hr = S_OK; | ||
940 | LPCWSTR wzEnvName = L"TMP"; | ||
941 | LPCWSTR wzEnvName2 = L"TEMP"; | ||
942 | LPCWSTR wzLongTempPath = L"C:\\aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\\cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\\"; | ||
943 | LPWSTR sczTempPath = NULL; | ||
944 | WCHAR wzOriginalTemp[MAX_PATH + 1] = { }; | ||
945 | WCHAR wzOriginalTemp2[MAX_PATH + 1] = { }; | ||
946 | DWORD cch = 0; | ||
947 | DWORD cch2 = 0; | ||
948 | SIZE_T cchTemp = 0; | ||
949 | size_t cchTemp2 = 0; | ||
950 | |||
951 | try | ||
952 | { | ||
953 | cch = ::GetEnvironmentVariableW(wzEnvName, wzOriginalTemp, countof(wzOriginalTemp)); | ||
954 | Assert::NotEqual<DWORD>(0, cch); | ||
955 | |||
956 | if (!::SetEnvironmentVariableW(wzEnvName, wzLongTempPath)) | ||
957 | { | ||
958 | Assert::Equal<DWORD>(0xFFFFFFFF, ::GetLastError()); | ||
959 | } | ||
960 | |||
961 | cch2 = ::GetEnvironmentVariableW(wzEnvName2, wzOriginalTemp2, countof(wzOriginalTemp2)); | ||
962 | Assert::NotEqual<DWORD>(0, cch2); | ||
963 | |||
964 | hr = PathGetTempPath(&sczTempPath, &cchTemp); | ||
965 | NativeAssert::Succeeded(hr, "Failed to get temp path."); | ||
966 | |||
967 | PathFixedBackslashTerminate(wzOriginalTemp2, countof(wzOriginalTemp2)); | ||
968 | |||
969 | hr = ::StringCchLengthW(wzOriginalTemp2, countof(wzOriginalTemp2), &cchTemp2); | ||
970 | NativeAssert::Succeeded(hr, "Failed to get temp path length."); | ||
971 | |||
972 | NativeAssert::StringEqual(wzOriginalTemp2, sczTempPath); | ||
973 | Assert::Equal<SIZE_T>(cchTemp2, cchTemp); | ||
974 | } | ||
975 | finally | ||
976 | { | ||
977 | if (cch) | ||
978 | { | ||
979 | ::SetEnvironmentVariableW(wzEnvName, wzOriginalTemp); | ||
980 | } | ||
981 | |||
982 | ReleaseStr(sczTempPath); | ||
983 | } | ||
984 | } | ||
985 | |||
986 | [Fact] | ||
987 | void PathGetVolumePathNameTest() | ||
988 | { | ||
989 | HRESULT hr = S_OK; | ||
990 | LPWSTR sczVolumePathName = NULL; | ||
991 | |||
992 | try | ||
993 | { | ||
994 | hr = StrAlloc(&sczVolumePathName, 1); | ||
995 | NativeAssert::Succeeded(hr, "Failed to alloc volume path name."); | ||
996 | |||
997 | hr = PathGetVolumePathName(L"C:\\Windows", &sczVolumePathName); | ||
998 | NativeAssert::Succeeded(hr, "PathGetVolumePathName failed."); | ||
999 | |||
1000 | NativeAssert::StringEqual(L"C:\\", sczVolumePathName); | ||
1001 | } | ||
1002 | finally | ||
1003 | { | ||
1004 | ReleaseStr(sczVolumePathName); | ||
1005 | } | ||
1006 | } | ||
1007 | |||
1008 | [Fact] | ||
831 | void PathNormalizeSlashesFixedTest() | 1009 | void PathNormalizeSlashesFixedTest() |
832 | { | 1010 | { |
833 | HRESULT hr = S_OK; | 1011 | HRESULT hr = S_OK; |