2 * PROJECT: ReactOS api tests
3 * LICENSE: GPLv2+ - See COPYING in the top level directory
4 * PURPOSE: Test for RtlGetFullPathName_U
5 * PROGRAMMER: Thomas Faber <thfabba@gmx.de>
8 #define WIN32_NO_STATUS
10 #include <pseh/pseh2.h>
11 #include <ndk/rtlfuncs.h>
24 #define StartSeh() ExceptionStatus = STATUS_SUCCESS; _SEH2_TRY {
25 #define EndSeh(ExpectedStatus) } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { ExceptionStatus = _SEH2_GetExceptionCode(); } _SEH2_END; ok(ExceptionStatus == ExpectedStatus, "Exception %lx, expected %lx\n", ExceptionStatus, ExpectedStatus)
35 USHORT ExpectedLength
= wcslen(Expected
) * sizeof(WCHAR
);
37 BOOLEAN Result
= TRUE
;
40 if (Length
!= ExpectedLength
)
42 ok(0, "String length is %u, expected %u\n", Length
, ExpectedLength
);
46 EqualLength
= RtlCompareMemory(Buffer
, Expected
, Length
);
47 if (EqualLength
!= Length
)
49 ok(0, "String is '%S', expected '%S'\n", Buffer
, Expected
);
53 if (Buffer
[Length
/ sizeof(WCHAR
)] != UNICODE_NULL
)
55 ok(0, "Not null terminated\n");
59 /* The function nulls the rest of the buffer! */
60 for (i
= Length
+ sizeof(UNICODE_NULL
); i
< MaximumLength
; i
++)
62 UCHAR Char
= ((PUCHAR
)Buffer
)[i
];
65 ok(0, "Found 0x%x at offset %lu, expected 0x%x\n", Char
, (ULONG
)i
, 0);
66 /* Don't count this as a failure unless the string was actually wrong */
68 /* Don't flood the log */
76 #define InvalidPointer ((PVOID)0x0123456789ABCDEFULL)
78 /* winetest_platform is "windows" for us, so broken() doesn't do what it should :( */
87 PrefixCurrentPathWithoutLastPart
94 /* TODO: don't duplicate this in the other tests */
95 /* TODO: Drive Relative tests don't work yet if the current drive isn't C: */
99 PREFIX_TYPE PrefixType
;
101 PREFIX_TYPE FilePartPrefixType
;
105 { L
"C:", PrefixCurrentPath
, L
"", PrefixCurrentPathWithoutLastPart
},
106 { L
"C:\\", PrefixNone
, L
"C:\\" },
107 { L
"C:\\test", PrefixNone
, L
"C:\\test", PrefixCurrentDrive
},
108 { L
"C:\\test\\", PrefixNone
, L
"C:\\test\\" },
109 { L
"C:/test/", PrefixNone
, L
"C:\\test\\" },
111 { L
"C:\\\\test", PrefixNone
, L
"C:\\test", PrefixCurrentDrive
},
112 { L
"test", PrefixCurrentPath
, L
"\\test", PrefixCurrentPath
, sizeof(WCHAR
) },
113 { L
"\\test", PrefixCurrentDrive
, L
"test", PrefixCurrentDrive
},
114 { L
"/test", PrefixCurrentDrive
, L
"test", PrefixCurrentDrive
},
115 { L
".\\test", PrefixCurrentPath
, L
"\\test", PrefixCurrentPath
, sizeof(WCHAR
) },
117 { L
"\\.", PrefixCurrentDrive
, L
"" },
118 { L
"\\.\\", PrefixCurrentDrive
, L
"" },
119 { L
"\\\\.", PrefixNone
, L
"\\\\.\\" },
120 { L
"\\\\.\\", PrefixNone
, L
"\\\\.\\" },
121 { L
"\\\\.\\Something\\", PrefixNone
, L
"\\\\.\\Something\\" },
123 { L
"\\??\\", PrefixCurrentDrive
, L
"??\\" },
124 { L
"\\??\\C:", PrefixCurrentDrive
, L
"??\\C:", PrefixCurrentDrive
, 3 * sizeof(WCHAR
) },
125 { L
"\\??\\C:\\", PrefixCurrentDrive
, L
"??\\C:\\" },
126 { L
"\\??\\C:\\test", PrefixCurrentDrive
, L
"??\\C:\\test", PrefixCurrentDrive
, 6 * sizeof(WCHAR
) },
127 { L
"\\??\\C:\\test\\", PrefixCurrentDrive
, L
"??\\C:\\test\\" },
129 { L
"\\\\??\\", PrefixNone
, L
"\\\\??\\" },
130 { L
"\\\\??\\C:", PrefixNone
, L
"\\\\??\\C:" },
131 { L
"\\\\??\\C:\\", PrefixNone
, L
"\\\\??\\C:\\" },
132 { L
"\\\\??\\C:\\test", PrefixNone
, L
"\\\\??\\C:\\test", PrefixNone
, sizeof(L
"\\\\??\\C:\\") },
133 { L
"\\\\??\\C:\\test\\", PrefixNone
, L
"\\\\??\\C:\\test\\" },
135 NTSTATUS ExceptionStatus
;
136 WCHAR FullPathNameBuffer
[MAX_PATH
];
139 WCHAR ExpectedPathName
[MAX_PATH
];
141 SIZE_T ExpectedFilePartSize
;
142 const INT TestCount
= sizeof(TestCases
) / sizeof(TestCases
[0]);
145 for (i
= 0; i
< TestCount
; i
++)
147 trace("i = %d\n", i
);
148 switch (TestCases
[i
].PrefixType
)
151 ExpectedPathName
[0] = UNICODE_NULL
;
153 case PrefixCurrentDrive
:
154 GetCurrentDirectoryW(sizeof(ExpectedPathName
) / sizeof(WCHAR
), ExpectedPathName
);
155 ExpectedPathName
[3] = UNICODE_NULL
;
157 case PrefixCurrentPath
:
158 Length
= GetCurrentDirectoryW(sizeof(ExpectedPathName
) / sizeof(WCHAR
), ExpectedPathName
);
159 if (Length
== 3 && TestCases
[i
].FullPathName
[0])
160 ExpectedPathName
[2] = UNICODE_NULL
;
163 skip(0, "Invalid test!\n");
166 wcscat(ExpectedPathName
, TestCases
[i
].FullPathName
);
167 RtlFillMemory(FullPathNameBuffer
, sizeof(FullPathNameBuffer
), 0xAA);
170 Length
= RtlGetFullPathName_U(TestCases
[i
].FileName
,
171 sizeof(FullPathNameBuffer
),
174 EndSeh(STATUS_SUCCESS
);
176 ok(CheckStringBuffer(FullPathNameBuffer
, Length
, sizeof(FullPathNameBuffer
), ExpectedPathName
),
177 "Wrong path name '%S', expected '%S'\n", FullPathNameBuffer
, ExpectedPathName
);
182 FilePartSize
= ShortName
- FullPathNameBuffer
;
184 switch (TestCases
[i
].FilePartPrefixType
)
187 ExpectedFilePartSize
= 0;
189 case PrefixCurrentDrive
:
190 ExpectedFilePartSize
= sizeof(L
"C:\\");
192 case PrefixCurrentPath
:
193 ExpectedFilePartSize
= GetCurrentDirectoryW(0, NULL
) * sizeof(WCHAR
);
194 if (ExpectedFilePartSize
== sizeof(L
"C:\\"))
195 ExpectedFilePartSize
-= sizeof(WCHAR
);
197 case PrefixCurrentPathWithoutLastPart
:
199 WCHAR CurrentPath
[MAX_PATH
];
201 ExpectedFilePartSize
= GetCurrentDirectoryW(sizeof(CurrentPath
) / sizeof(WCHAR
), CurrentPath
) * sizeof(WCHAR
) + sizeof(UNICODE_NULL
);
202 if (ExpectedFilePartSize
== sizeof(L
"C:\\"))
203 ExpectedFilePartSize
= 0;
206 BackSlash
= wcsrchr(CurrentPath
, L
'\\');
208 ExpectedFilePartSize
-= wcslen(BackSlash
+ 1) * sizeof(WCHAR
);
210 ok(0, "GetCurrentDirectory returned %S\n", CurrentPath
);
215 skip(0, "Invalid test!\n");
218 ExpectedFilePartSize
+= TestCases
[i
].FilePartSize
;
219 if (ExpectedFilePartSize
!= 0)
220 ExpectedFilePartSize
= (ExpectedFilePartSize
- sizeof(UNICODE_NULL
)) / sizeof(WCHAR
);
221 ok(FilePartSize
== ExpectedFilePartSize
,
222 "FilePartSize = %lu, expected %lu\n", (ULONG
)FilePartSize
, (ULONG
)ExpectedFilePartSize
);
226 START_TEST(RtlGetFullPathName_U
)
228 NTSTATUS ExceptionStatus
;
233 /* Parameter checks */
235 Length
= RtlGetFullPathName_U(NULL
, 0, NULL
, NULL
);
236 ok(Length
== 0, "Length = %lu\n", Length
);
237 EndSeh(STATUS_SUCCESS
);
240 Length
= RtlGetFullPathName_U(L
"", 0, NULL
, NULL
);
241 ok(Length
== 0, "Length = %lu\n", Length
);
242 EndSeh(STATUS_SUCCESS
);
244 ShortName
= InvalidPointer
;
246 Length
= RtlGetFullPathName_U(NULL
, 0, NULL
, &ShortName
);
247 ok(Length
== 0, "Length = %lu\n", Length
);
248 EndSeh(STATUS_SUCCESS
);
249 ok(ShortName
== InvalidPointer
||
250 broken(ShortName
== NULL
) /* Win7 */, "ShortName = %p\n", ShortName
);
253 Length
= RtlGetFullPathName_U(L
"", 0, NULL
, NULL
);
254 ok(Length
== 0, "Length = %lu\n", Length
);
255 EndSeh(STATUS_SUCCESS
);
257 ShortName
= InvalidPointer
;
259 Length
= RtlGetFullPathName_U(L
"", 0, NULL
, &ShortName
);
260 ok(Length
== 0, "Length = %lu\n", Length
);
261 EndSeh(STATUS_SUCCESS
);
262 ok(ShortName
== InvalidPointer
||
263 broken(ShortName
== NULL
) /* Win7 */, "ShortName = %p\n", ShortName
);
266 Length
= RtlGetFullPathName_U(L
"C:\\test", 0, NULL
, NULL
);
267 ok(Length
== sizeof(L
"C:\\test"), "Length = %lu\n", Length
);
268 EndSeh(STATUS_SUCCESS
);
270 FileName
= L
"C:\\test";
271 ShortName
= InvalidPointer
;
273 Length
= RtlGetFullPathName_U(FileName
, 0, NULL
, &ShortName
);
274 ok(Length
== sizeof(L
"C:\\test"), "Length = %lu\n", Length
);
275 EndSeh(STATUS_SUCCESS
);
276 ok(ShortName
== InvalidPointer
||
277 broken(ShortName
== NULL
) /* Win7 */, "ShortName = %p\n", ShortName
);
279 /* Check the actual functionality with different paths */