aboutsummaryrefslogtreecommitdiff
path: root/src/libs/dutil/test/DUtilUnitTest
diff options
context:
space:
mode:
authorSean Hall <r.sean.hall@gmail.com>2022-05-26 17:33:15 -0500
committerSean Hall <r.sean.hall@gmail.com>2022-05-31 13:20:44 -0500
commitfb4f8c7108f43d2341ba299424646c4963b21188 (patch)
tree7f3c907ac5406d2000056f6bcca41d7ae4d3a925 /src/libs/dutil/test/DUtilUnitTest
parent0f9931107ecf9e1f6714e6fd2cabc76d2ddb1153 (diff)
downloadwix-fb4f8c7108f43d2341ba299424646c4963b21188.tar.gz
wix-fb4f8c7108f43d2341ba299424646c4963b21188.tar.bz2
wix-fb4f8c7108f43d2341ba299424646c4963b21188.zip
Replace PathIsAbsolute with PathIsRooted and add PathIsFullyQualified.
Diffstat (limited to 'src/libs/dutil/test/DUtilUnitTest')
-rw-r--r--src/libs/dutil/test/DUtilUnitTest/PathUtilTest.cpp199
1 files changed, 199 insertions, 0 deletions
diff --git a/src/libs/dutil/test/DUtilUnitTest/PathUtilTest.cpp b/src/libs/dutil/test/DUtilUnitTest/PathUtilTest.cpp
index 6a05a45c..65856514 100644
--- a/src/libs/dutil/test/DUtilUnitTest/PathUtilTest.cpp
+++ b/src/libs/dutil/test/DUtilUnitTest/PathUtilTest.cpp
@@ -109,5 +109,204 @@ namespace DutilTests
109 ReleaseStrArray(rgsczPaths, cPaths); 109 ReleaseStrArray(rgsczPaths, cPaths);
110 } 110 }
111 } 111 }
112
113 [Fact]
114 void PathPrefixTest()
115 {
116 HRESULT hr = S_OK;
117 LPWSTR sczPath = NULL;
118 LPCWSTR rgwzPaths[12] =
119 {
120 L"\\\\", L"\\\\?\\UNC\\",
121 L"C:\\\\foo2", L"\\\\?\\C:\\\\foo2",
122 L"\\\\a\\b\\", L"\\\\?\\UNC\\a\\b\\",
123 L"\\\\?\\UNC\\test\\unc\\path\\to\\something", L"\\\\?\\UNC\\test\\unc\\path\\to\\something",
124 L"\\\\?\\C:\\foo\\bar.txt", L"\\\\?\\C:\\foo\\bar.txt",
125 L"\\??\\C:\\foo\\bar.txt", L"\\??\\C:\\foo\\bar.txt",
126 };
127
128 try
129 {
130 for (DWORD i = 0; i < countof(rgwzPaths) / 2; i += 2)
131 {
132 hr = StrAllocString(&sczPath, rgwzPaths[i], 0);
133 NativeAssert::Succeeded(hr, "Failed to copy string");
134
135 hr = PathPrefix(&sczPath);
136 NativeAssert::Succeeded(hr, "PathPrefix: {0}", rgwzPaths[i]);
137 NativeAssert::StringEqual(rgwzPaths[i + 1], sczPath);
138 }
139 }
140 finally
141 {
142 ReleaseStr(sczPath);
143 }
144 }
145
146 [Fact]
147 void PathPrefixFailureTest()
148 {
149 HRESULT hr = S_OK;
150 LPWSTR sczPath = NULL;
151 LPCWSTR rgwzPaths[8] =
152 {
153 L"\\",
154 L"C:",
155 L"C:foo.txt",
156 L"",
157 L"\\?",
158 L"\\dir",
159 L"dir",
160 L"dir\\subdir",
161 };
162
163 try
164 {
165 for (DWORD i = 0; i < countof(rgwzPaths); ++i)
166 {
167 hr = StrAllocString(&sczPath, rgwzPaths[i], 0);
168 NativeAssert::Succeeded(hr, "Failed to copy string");
169
170 hr = PathPrefix(&sczPath);
171 NativeAssert::SpecificReturnCode(E_INVALIDARG, hr, "PathPrefix: {0}, {1}", rgwzPaths[i], sczPath);
172 }
173 }
174 finally
175 {
176 ReleaseStr(sczPath);
177 }
178 }
179
180 [Fact]
181 void PathIsRootedAndFullyQualifiedTest()
182 {
183 LPCWSTR rgwzPaths[15] =
184 {
185 L"\\\\",
186 L"\\\\\\",
187 L"C:\\",
188 L"C:\\\\",
189 L"C:\\foo1",
190 L"C:\\\\foo2",
191 L"\\\\test\\unc\\path\\to\\something",
192 L"\\\\a\\b\\c\\d\\e",
193 L"\\\\a\\b\\",
194 L"\\\\a\\b",
195 L"\\\\test\\unc",
196 L"\\\\Server",
197 L"\\\\Server\\Foo.txt",
198 L"\\\\Server\\Share\\Foo.txt",
199 L"\\\\Server\\Share\\Test\\Foo.txt",
200 };
201
202 for (DWORD i = 0; i < countof(rgwzPaths); ++i)
203 {
204 ValidateFullyQualifiedPath(rgwzPaths[i], TRUE, FALSE);
205 ValidateRootedPath(rgwzPaths[i], TRUE);
206 }
207 }
208
209 [Fact]
210 void PathIsRootedAndFullyQualifiedWithPrefixTest()
211 {
212 LPCWSTR rgwzPaths[6] =
213 {
214 L"\\\\?\\UNC\\test\\unc\\path\\to\\something",
215 L"\\\\?\\UNC\\test\\unc",
216 L"\\\\?\\UNC\\a\\b1",
217 L"\\\\?\\UNC\\a\\b2\\",
218 L"\\\\?\\C:\\foo\\bar.txt",
219 L"\\??\\C:\\foo\\bar.txt",
220 };
221
222 for (DWORD i = 0; i < countof(rgwzPaths); ++i)
223 {
224 ValidateFullyQualifiedPath(rgwzPaths[i], TRUE, TRUE);
225 ValidateRootedPath(rgwzPaths[i], TRUE);
226 }
227 }
228
229 [Fact]
230 void PathIsRootedButNotFullyQualifiedTest()
231 {
232 LPCWSTR rgwzPaths[7] =
233 {
234 L"\\",
235 L"a:",
236 L"A:",
237 L"z:",
238 L"Z:",
239 L"C:foo.txt",
240 L"\\dir",
241 };
242
243 for (DWORD i = 0; i < countof(rgwzPaths); ++i)
244 {
245 ValidateFullyQualifiedPath(rgwzPaths[i], FALSE, FALSE);
246 ValidateRootedPath(rgwzPaths[i], TRUE);
247 }
248 }
249
250 [Fact]
251 void PathIsNotRootedAndNotFullyQualifiedTest()
252 {
253 LPCWSTR rgwzPaths[9] =
254 {
255 NULL,
256 L"",
257 L"dir",
258 L"dir\\subdir",
259 L"@:\\foo", // 064 = @ 065 = A
260 L"[:\\\\", // 091 = [ 090 = Z
261 L"`:\\foo ", // 096 = ` 097 = a
262 L"{:\\\\", // 123 = { 122 = z
263 L"[:",
264 };
265
266 for (DWORD i = 0; i < countof(rgwzPaths); ++i)
267 {
268 ValidateFullyQualifiedPath(rgwzPaths[i], FALSE, FALSE);
269 ValidateRootedPath(rgwzPaths[i], FALSE);
270 }
271 }
272
273 void ValidateFullyQualifiedPath(LPCWSTR wzPath, BOOL fExpected, BOOL fExpectedHasPrefix)
274 {
275 BOOL fHasLongPathPrefix = FALSE;
276 BOOL fRooted = PathIsFullyQualified(wzPath, &fHasLongPathPrefix);
277 String^ message = String::Format("IsFullyQualified: {0}", gcnew String(wzPath));
278 if (fExpected)
279 {
280 Assert::True(fRooted, message);
281 }
282 else
283 {
284 Assert::False(fRooted, message);
285 }
286
287 message = String::Format("HasLongPathPrefix: {0}", gcnew String(wzPath));
288 if (fExpectedHasPrefix)
289 {
290 Assert::True(fHasLongPathPrefix, message);
291 }
292 else
293 {
294 Assert::False(fHasLongPathPrefix, message);
295 }
296 }
297
298 void ValidateRootedPath(LPCWSTR wzPath, BOOL fExpected)
299 {
300 BOOL fRooted = PathIsRooted(wzPath);
301 String^ message = String::Format("IsRooted: {0}", gcnew String(wzPath));
302 if (fExpected)
303 {
304 Assert::True(fRooted, message);
305 }
306 else
307 {
308 Assert::False(fRooted, message);
309 }
310 }
112 }; 311 };
113} 312}