2 * PROJECT: ReactOS api tests
3 * LICENSE: GPLv2+ - See COPYING in the top level directory
4 * PURPOSE: Test for RtlGetFullPathName_UstrEx
5 * PROGRAMMER: Thomas Faber <thomas.faber@reactos.org>
10 #define WIN32_NO_STATUS
11 #include <ndk/rtlfuncs.h>
16 RtlGetFullPathName_UstrEx(
17 IN PUNICODE_STRING FileName,
18 IN PUNICODE_STRING StaticString,
19 IN PUNICODE_STRING DynamicString,
20 IN PUNICODE_STRING *StringUsed,
21 IN PSIZE_T FilePartSize OPTIONAL,
22 OUT PBOOLEAN NameInvalid,
23 OUT RTL_PATH_TYPE* PathType,
24 OUT PSIZE_T LengthNeeded OPTIONAL
30 *pRtlGetFullPathName_UstrEx
)(
31 IN PUNICODE_STRING FileName
,
32 IN PUNICODE_STRING StaticString
,
33 IN PUNICODE_STRING DynamicString
,
34 IN PUNICODE_STRING
*StringUsed
,
35 IN PSIZE_T FilePartSize OPTIONAL
,
36 OUT PBOOLEAN NameInvalid
,
37 OUT RTL_PATH_TYPE
* PathType
,
38 OUT PSIZE_T LengthNeeded OPTIONAL
41 #define ok_eq_ustr(str1, str2) do { \
42 ok((str1)->Buffer == (str2)->Buffer, "Buffer modified\n"); \
43 ok((str1)->Length == (str2)->Length, "Length modified\n"); \
44 ok((str1)->MaximumLength == (str2)->MaximumLength, "MaximumLength modified\n"); \
50 PCUNICODE_STRING String
,
53 SIZE_T ExpectedLength
= wcslen(Expected
) * sizeof(WCHAR
);
55 BOOLEAN Result
= TRUE
;
58 if (String
->Length
!= ExpectedLength
)
60 ok(0, "String length is %u, expected %lu\n", String
->Length
, (ULONG
)ExpectedLength
);
64 EqualLength
= RtlCompareMemory(String
->Buffer
, Expected
, ExpectedLength
);
65 if (EqualLength
!= ExpectedLength
)
67 ok(0, "String is '%wZ', expected '%S'\n", String
, Expected
);
71 if (String
->Buffer
[String
->Length
/ sizeof(WCHAR
)] != UNICODE_NULL
)
73 ok(0, "Not null terminated\n");
77 /* the function nulls the rest of the buffer! */
78 for (i
= String
->Length
+ sizeof(UNICODE_NULL
); i
< String
->MaximumLength
; i
++)
80 UCHAR Char
= ((PUCHAR
)String
->Buffer
)[i
];
83 ok(0, "Found 0x%x at offset %lu, expected 0x%x\n", Char
, (ULONG
)i
, 0);
84 /* don't count this as a failure unless the string was actually wrong */
86 /* don't flood the log */
101 PUCHAR Array
= Buffer
;
104 for (i
= 0; i
< Size
; i
++)
106 if (Array
[i
] != Value
)
108 trace("Expected %x, found %x at offset %lu\n", Value
, Array
[i
], (ULONG
)i
);
115 #define RtlPathTypeNotSet 123
117 /* winetest_platform is "windows" for us, so broken() doesn't do what it should :( */
126 PrefixCurrentPathWithoutLastPart
133 /* TODO: don't duplicate this in the other tests */
134 /* TODO: Drive Relative tests don't work yet if the current drive isn't C: */
138 PREFIX_TYPE PrefixType
;
140 RTL_PATH_TYPE PathType
;
141 PREFIX_TYPE FilePartPrefixType
;
145 { L
"C:", PrefixCurrentPath
, L
"", RtlPathTypeDriveRelative
, PrefixCurrentPathWithoutLastPart
},
146 { L
"C:\\", PrefixNone
, L
"C:\\", RtlPathTypeDriveAbsolute
},
147 { L
"C:\\test", PrefixNone
, L
"C:\\test", RtlPathTypeDriveAbsolute
, PrefixCurrentDrive
},
148 { L
"C:\\test\\", PrefixNone
, L
"C:\\test\\", RtlPathTypeDriveAbsolute
},
149 { L
"C:/test/", PrefixNone
, L
"C:\\test\\", RtlPathTypeDriveAbsolute
},
151 { L
"C:\\\\test", PrefixNone
, L
"C:\\test", RtlPathTypeDriveAbsolute
, PrefixCurrentDrive
},
152 { L
"test", PrefixCurrentPath
, L
"\\test", RtlPathTypeRelative
, PrefixCurrentPath
, sizeof(WCHAR
) },
153 { L
"\\test", PrefixCurrentDrive
, L
"test", RtlPathTypeRooted
, PrefixCurrentDrive
},
154 { L
"/test", PrefixCurrentDrive
, L
"test", RtlPathTypeRooted
, PrefixCurrentDrive
},
155 { L
".\\test", PrefixCurrentPath
, L
"\\test", RtlPathTypeRelative
, PrefixCurrentPath
, sizeof(WCHAR
) },
157 { L
"\\.", PrefixCurrentDrive
, L
"", RtlPathTypeRooted
},
158 { L
"\\.\\", PrefixCurrentDrive
, L
"", RtlPathTypeRooted
},
159 { L
"\\\\.", PrefixNone
, L
"\\\\.\\", RtlPathTypeRootLocalDevice
},
160 { L
"\\\\.\\", PrefixNone
, L
"\\\\.\\", RtlPathTypeLocalDevice
},
161 { L
"\\\\.\\Something\\", PrefixNone
, L
"\\\\.\\Something\\", RtlPathTypeLocalDevice
},
163 { L
"\\??\\", PrefixCurrentDrive
, L
"??\\", RtlPathTypeRooted
},
164 { L
"\\??\\C:", PrefixCurrentDrive
, L
"??\\C:", RtlPathTypeRooted
, PrefixCurrentDrive
, 3 * sizeof(WCHAR
) },
165 { L
"\\??\\C:\\", PrefixCurrentDrive
, L
"??\\C:\\", RtlPathTypeRooted
},
166 { L
"\\??\\C:\\test", PrefixCurrentDrive
, L
"??\\C:\\test", RtlPathTypeRooted
, PrefixCurrentDrive
, 6 * sizeof(WCHAR
) },
167 { L
"\\??\\C:\\test\\", PrefixCurrentDrive
, L
"??\\C:\\test\\", RtlPathTypeRooted
},
169 { L
"\\\\??\\", PrefixNone
, L
"\\\\??\\", RtlPathTypeUncAbsolute
},
170 { L
"\\\\??\\C:", PrefixNone
, L
"\\\\??\\C:", RtlPathTypeUncAbsolute
},
171 { L
"\\\\??\\C:\\", PrefixNone
, L
"\\\\??\\C:\\", RtlPathTypeUncAbsolute
},
172 { L
"\\\\??\\C:\\test", PrefixNone
, L
"\\\\??\\C:\\test", RtlPathTypeUncAbsolute
, PrefixNone
, sizeof(L
"\\\\??\\C:\\") },
173 { L
"\\\\??\\C:\\test\\", PrefixNone
, L
"\\\\??\\C:\\test\\", RtlPathTypeUncAbsolute
},
176 UNICODE_STRING FileName
;
177 UNICODE_STRING FullPathName
;
178 WCHAR FullPathNameBuffer
[MAX_PATH
];
179 UNICODE_STRING TempString
;
180 PUNICODE_STRING StringUsed
;
183 RTL_PATH_TYPE PathType
;
185 WCHAR ExpectedPathName
[MAX_PATH
];
186 SIZE_T ExpectedFilePartSize
;
187 const INT TestCount
= sizeof(TestCases
) / sizeof(TestCases
[0]);
191 for (i
= 0; i
< TestCount
; i
++)
193 switch (TestCases
[i
].PrefixType
)
196 ExpectedPathName
[0] = UNICODE_NULL
;
198 case PrefixCurrentDrive
:
199 GetCurrentDirectoryW(sizeof(ExpectedPathName
) / sizeof(WCHAR
), ExpectedPathName
);
200 ExpectedPathName
[3] = UNICODE_NULL
;
202 case PrefixCurrentPath
:
205 Length
= GetCurrentDirectoryW(sizeof(ExpectedPathName
) / sizeof(WCHAR
), ExpectedPathName
);
206 if (Length
== 3 && TestCases
[i
].FullPathName
[0])
207 ExpectedPathName
[2] = UNICODE_NULL
;
211 skip("Invalid test!\n");
214 wcscat(ExpectedPathName
, TestCases
[i
].FullPathName
);
215 RtlInitUnicodeString(&FileName
, TestCases
[i
].FileName
);
216 RtlInitEmptyUnicodeString(&FullPathName
, FullPathNameBuffer
, sizeof(FullPathNameBuffer
));
217 RtlFillMemory(FullPathName
.Buffer
, FullPathName
.MaximumLength
, 0xAA);
218 TempString
= FileName
;
219 PathType
= RtlPathTypeNotSet
;
220 StringUsed
= InvalidPointer
;
222 NameInvalid
= (BOOLEAN
)-1;
225 Status
= pRtlGetFullPathName_UstrEx(&FileName
,
233 ok(Status
== STATUS_SUCCESS
, "status = %lx\n", Status
);
234 EndSeh(STATUS_SUCCESS
);
235 ok_eq_ustr(&FileName
, &TempString
);
236 ok(FullPathName
.Buffer
== FullPathNameBuffer
, "Buffer modified\n");
237 ok(FullPathName
.MaximumLength
== sizeof(FullPathNameBuffer
), "MaximumLength modified\n");
238 Okay
= CheckStringBuffer(&FullPathName
, ExpectedPathName
);
239 ok(Okay
, "Wrong path name '%wZ', expected '%S'\n", &FullPathName
, ExpectedPathName
);
240 ok(StringUsed
== &FullPathName
, "StringUsed = %p, expected %p\n", StringUsed
, &FullPathName
);
241 switch (TestCases
[i
].FilePartPrefixType
)
244 ExpectedFilePartSize
= 0;
246 case PrefixCurrentDrive
:
247 ExpectedFilePartSize
= sizeof(L
"C:\\");
249 case PrefixCurrentPath
:
250 ExpectedFilePartSize
= GetCurrentDirectoryW(0, NULL
) * sizeof(WCHAR
);
251 if (ExpectedFilePartSize
== sizeof(L
"C:\\"))
252 ExpectedFilePartSize
-= sizeof(WCHAR
);
254 case PrefixCurrentPathWithoutLastPart
:
256 WCHAR CurrentPath
[MAX_PATH
];
258 ExpectedFilePartSize
= GetCurrentDirectoryW(sizeof(CurrentPath
) / sizeof(WCHAR
), CurrentPath
) * sizeof(WCHAR
) + sizeof(UNICODE_NULL
);
259 if (ExpectedFilePartSize
== sizeof(L
"C:\\"))
260 ExpectedFilePartSize
= 0;
263 BackSlash
= wcsrchr(CurrentPath
, L
'\\');
265 ExpectedFilePartSize
-= wcslen(BackSlash
+ 1) * sizeof(WCHAR
);
267 ok(0, "GetCurrentDirectory returned %S\n", CurrentPath
);
272 skip("Invalid test!\n");
275 ExpectedFilePartSize
+= TestCases
[i
].FilePartSize
;
276 if (ExpectedFilePartSize
!= 0)
277 ExpectedFilePartSize
= (ExpectedFilePartSize
- sizeof(UNICODE_NULL
)) / sizeof(WCHAR
);
278 ok(FilePartSize
== ExpectedFilePartSize
,
279 "FilePartSize = %lu, expected %lu\n", (ULONG
)FilePartSize
, (ULONG
)ExpectedFilePartSize
);
280 ok(NameInvalid
== FALSE
, "NameInvalid = %u\n", NameInvalid
);
281 ok(PathType
== TestCases
[i
].PathType
, "PathType = %d, expected %d\n", PathType
, TestCases
[i
].PathType
);
282 ok(LengthNeeded
== 0, "LengthNeeded = %lu\n", (ULONG
)LengthNeeded
);
286 START_TEST(RtlGetFullPathName_UstrEx
)
289 UNICODE_STRING FileName
;
290 UNICODE_STRING TempString
;
291 UNICODE_STRING StaticString
;
292 PUNICODE_STRING StringUsed
;
295 BOOLEAN NameInvalidArray
[sizeof(ULONGLONG
)];
296 RTL_PATH_TYPE PathType
;
300 pRtlGetFullPathName_UstrEx
= (PVOID
)GetProcAddress(GetModuleHandleW(L
"ntdll"), "RtlGetFullPathName_UstrEx");
301 if (!pRtlGetFullPathName_UstrEx
)
303 skip("RtlGetFullPathName_UstrEx unavailable\n");
307 /* NULL parameters */
309 pRtlGetFullPathName_UstrEx(NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
310 EndSeh(STATUS_ACCESS_VIOLATION
);
312 RtlInitUnicodeString(&FileName
, NULL
);
313 TempString
= FileName
;
315 pRtlGetFullPathName_UstrEx(&FileName
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
316 EndSeh(STATUS_ACCESS_VIOLATION
);
317 ok_eq_ustr(&FileName
, &TempString
);
319 RtlInitUnicodeString(&FileName
, L
"");
320 TempString
= FileName
;
322 pRtlGetFullPathName_UstrEx(&FileName
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
323 EndSeh(STATUS_ACCESS_VIOLATION
);
324 ok_eq_ustr(&FileName
, &TempString
);
326 PathType
= RtlPathTypeNotSet
;
328 pRtlGetFullPathName_UstrEx(NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, &PathType
, NULL
);
329 EndSeh(STATUS_ACCESS_VIOLATION
);
330 ok(PathType
== RtlPathTypeUnknown
||
331 broken(PathType
== RtlPathTypeNotSet
) /* Win7 */, "PathType = %d\n", PathType
);
333 /* Check what else is initialized before it crashes */
334 PathType
= RtlPathTypeNotSet
;
335 StringUsed
= InvalidPointer
;
337 NameInvalid
= (BOOLEAN
)-1;
340 pRtlGetFullPathName_UstrEx(NULL
, NULL
, NULL
, &StringUsed
, &FilePartSize
, &NameInvalid
, &PathType
, &LengthNeeded
);
341 EndSeh(STATUS_ACCESS_VIOLATION
);
342 ok(StringUsed
== NULL
, "StringUsed = %p\n", StringUsed
);
343 ok(FilePartSize
== 0, "FilePartSize = %lu\n", (ULONG
)FilePartSize
);
344 ok(NameInvalid
== FALSE
, "NameInvalid = %u\n", NameInvalid
);
345 ok(PathType
== RtlPathTypeUnknown
||
346 broken(PathType
== RtlPathTypeNotSet
) /* Win7 */, "PathType = %d\n", PathType
);
347 ok(LengthNeeded
== 0, "LengthNeeded = %lu\n", (ULONG
)LengthNeeded
);
349 RtlInitUnicodeString(&FileName
, L
"");
350 TempString
= FileName
;
351 StringUsed
= InvalidPointer
;
353 NameInvalid
= (BOOLEAN
)-1;
356 pRtlGetFullPathName_UstrEx(&FileName
, NULL
, NULL
, &StringUsed
, &FilePartSize
, &NameInvalid
, NULL
, &LengthNeeded
);
357 EndSeh(STATUS_ACCESS_VIOLATION
);
358 ok_eq_ustr(&FileName
, &TempString
);
359 ok(StringUsed
== NULL
, "StringUsed = %p\n", StringUsed
);
360 ok(FilePartSize
== 0, "FilePartSize = %lu\n", (ULONG
)FilePartSize
);
361 ok(NameInvalid
== FALSE
||
362 broken(NameInvalid
== (BOOLEAN
)-1) /* Win7 */, "NameInvalid = %u\n", NameInvalid
);
363 ok(LengthNeeded
== 0, "LengthNeeded = %lu\n", (ULONG
)LengthNeeded
);
365 /* This is the first one that doesn't crash. FileName and PathType cannot be NULL */
366 RtlInitUnicodeString(&FileName
, NULL
);
367 TempString
= FileName
;
368 PathType
= RtlPathTypeNotSet
;
370 Status
= pRtlGetFullPathName_UstrEx(&FileName
, NULL
, NULL
, NULL
, NULL
, NULL
, &PathType
, NULL
);
371 ok(Status
== STATUS_OBJECT_NAME_INVALID
, "status = %lx\n", Status
);
372 EndSeh(STATUS_SUCCESS
);
373 ok_eq_ustr(&FileName
, &TempString
);
374 ok(PathType
== RtlPathTypeUnknown
, "PathType = %d\n", PathType
);
376 RtlInitUnicodeString(&FileName
, L
"");
377 TempString
= FileName
;
378 PathType
= RtlPathTypeNotSet
;
380 Status
= pRtlGetFullPathName_UstrEx(&FileName
, NULL
, NULL
, NULL
, NULL
, NULL
, &PathType
, NULL
);
381 ok(Status
== STATUS_OBJECT_NAME_INVALID
, "status = %lx\n", Status
);
382 EndSeh(STATUS_SUCCESS
);
383 ok_eq_ustr(&FileName
, &TempString
);
384 ok(PathType
== RtlPathTypeUnknown
, "PathType = %d\n", PathType
);
386 /* Show that NameInvalid is indeed BOOLEAN */
387 RtlInitUnicodeString(&FileName
, L
"");
388 TempString
= FileName
;
389 PathType
= RtlPathTypeNotSet
;
390 RtlFillMemory(NameInvalidArray
, sizeof(NameInvalidArray
), 0x55);
392 Status
= pRtlGetFullPathName_UstrEx(&FileName
, NULL
, NULL
, NULL
, NULL
, NameInvalidArray
, &PathType
, NULL
);
393 ok(Status
== STATUS_OBJECT_NAME_INVALID
, "status = %lx\n", Status
);
394 EndSeh(STATUS_SUCCESS
);
395 ok_eq_ustr(&FileName
, &TempString
);
396 ok(PathType
== RtlPathTypeUnknown
, "PathType = %d\n", PathType
);
397 ok(NameInvalidArray
[0] == FALSE
, "NameInvalid = %u\n", NameInvalidArray
[0]);
398 Okay
= CheckBuffer(NameInvalidArray
+ 1, sizeof(NameInvalidArray
) - sizeof(NameInvalidArray
[0]), 0x55);
399 ok(Okay
, "CheckBuffer failed\n");
401 /* Give it a valid path */
402 RtlInitUnicodeString(&FileName
, L
"C:\\test");
403 TempString
= FileName
;
404 PathType
= RtlPathTypeNotSet
;
406 Status
= pRtlGetFullPathName_UstrEx(&FileName
, NULL
, NULL
, NULL
, NULL
, NULL
, &PathType
, NULL
);
407 ok(Status
== STATUS_BUFFER_TOO_SMALL
, "status = %lx\n", Status
);
408 EndSeh(STATUS_SUCCESS
);
409 ok_eq_ustr(&FileName
, &TempString
);
410 ok(PathType
== RtlPathTypeDriveAbsolute
, "PathType = %d\n", PathType
);
412 /* Zero-length static string */
413 RtlInitUnicodeString(&FileName
, L
"C:\\test");
414 TempString
= FileName
;
415 RtlInitUnicodeString(&StaticString
, NULL
);
416 PathType
= RtlPathTypeNotSet
;
418 Status
= pRtlGetFullPathName_UstrEx(&FileName
, &StaticString
, NULL
, NULL
, NULL
, NULL
, &PathType
, NULL
);
419 ok(Status
== STATUS_BUFFER_TOO_SMALL
, "status = %lx\n", Status
);
420 EndSeh(STATUS_SUCCESS
);
421 ok_eq_ustr(&FileName
, &TempString
);
422 ok(PathType
== RtlPathTypeDriveAbsolute
, "PathType = %d\n", PathType
);
424 /* TODO: play around with StaticString and DynamicString */
426 /* Check the actual functionality with different paths */