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 <thomas.faber@reactos.org>
10 #define WIN32_NO_STATUS
11 #include <ndk/rtlfuncs.h>
32 SIZE_T ExpectedLength
= wcslen(Expected
) * sizeof(WCHAR
);
34 BOOLEAN Result
= TRUE
;
37 if (Length
!= ExpectedLength
)
39 ok(0, "String length is %lu, expected %lu\n", (ULONG
)Length
, (ULONG
)ExpectedLength
);
43 EqualLength
= RtlCompareMemory(Buffer
, Expected
, Length
);
44 if (EqualLength
!= Length
)
46 ok(0, "String is '%S', expected '%S'\n", Buffer
, Expected
);
50 if (Buffer
[Length
/ sizeof(WCHAR
)] != UNICODE_NULL
)
52 ok(0, "Not null terminated\n");
56 /* The function nulls the rest of the buffer! */
57 for (i
= Length
+ sizeof(UNICODE_NULL
); i
< MaximumLength
; i
++)
59 UCHAR Char
= ((PUCHAR
)Buffer
)[i
];
62 ok(0, "Found 0x%x at offset %lu, expected 0x%x\n", Char
, (ULONG
)i
, 0);
63 /* Don't count this as a failure unless the string was actually wrong */
65 /* Don't flood the log */
73 /* winetest_platform is "windows" for us, so broken() doesn't do what it should :( */
82 PrefixCurrentPathWithoutLastPart
89 /* TODO: don't duplicate this in the other tests */
90 /* TODO: Drive Relative tests don't work yet if the current drive isn't C: */
94 PREFIX_TYPE PrefixType
;
96 PREFIX_TYPE FilePartPrefixType
;
100 { L
"C:", PrefixCurrentPath
, L
"", PrefixCurrentPathWithoutLastPart
},
101 { L
"C:\\", PrefixNone
, L
"C:\\" },
102 { L
"C:\\test", PrefixNone
, L
"C:\\test", PrefixCurrentDrive
},
103 { L
"C:\\test\\", PrefixNone
, L
"C:\\test\\" },
104 { L
"C:/test/", PrefixNone
, L
"C:\\test\\" },
106 { L
"C:\\\\test", PrefixNone
, L
"C:\\test", PrefixCurrentDrive
},
107 { L
"test", PrefixCurrentPath
, L
"\\test", PrefixCurrentPath
, sizeof(WCHAR
) },
108 { L
"\\test", PrefixCurrentDrive
, L
"test", PrefixCurrentDrive
},
109 { L
"/test", PrefixCurrentDrive
, L
"test", PrefixCurrentDrive
},
110 { L
".\\test", PrefixCurrentPath
, L
"\\test", PrefixCurrentPath
, sizeof(WCHAR
) },
112 { L
"\\.", PrefixCurrentDrive
, L
"" },
113 { L
"\\.\\", PrefixCurrentDrive
, L
"" },
114 { L
"\\\\.", PrefixNone
, L
"\\\\.\\" },
115 { L
"\\\\.\\", PrefixNone
, L
"\\\\.\\" },
116 { L
"\\\\.\\Something\\", PrefixNone
, L
"\\\\.\\Something\\" },
118 { L
"\\??\\", PrefixCurrentDrive
, L
"??\\" },
119 { L
"\\??\\C:", PrefixCurrentDrive
, L
"??\\C:", PrefixCurrentDrive
, 3 * sizeof(WCHAR
) },
120 { L
"\\??\\C:\\", PrefixCurrentDrive
, L
"??\\C:\\" },
121 { L
"\\??\\C:\\test", PrefixCurrentDrive
, L
"??\\C:\\test", PrefixCurrentDrive
, 6 * sizeof(WCHAR
) },
122 { L
"\\??\\C:\\test\\", PrefixCurrentDrive
, L
"??\\C:\\test\\" },
124 { L
"\\\\??\\", PrefixNone
, L
"\\\\??\\" },
125 { L
"\\\\??\\C:", PrefixNone
, L
"\\\\??\\C:" },
126 { L
"\\\\??\\C:\\", PrefixNone
, L
"\\\\??\\C:\\" },
127 { L
"\\\\??\\C:\\test", PrefixNone
, L
"\\\\??\\C:\\test", PrefixNone
, sizeof(L
"\\\\??\\C:\\") },
128 { L
"\\\\??\\C:\\test\\", PrefixNone
, L
"\\\\??\\C:\\test\\" },
130 WCHAR FullPathNameBuffer
[MAX_PATH
];
133 WCHAR ExpectedPathName
[MAX_PATH
];
135 SIZE_T ExpectedFilePartSize
;
136 const INT TestCount
= sizeof(TestCases
) / sizeof(TestCases
[0]);
140 for (i
= 0; i
< TestCount
; i
++)
142 trace("i = %d\n", i
);
143 switch (TestCases
[i
].PrefixType
)
146 ExpectedPathName
[0] = UNICODE_NULL
;
148 case PrefixCurrentDrive
:
149 GetCurrentDirectoryW(sizeof(ExpectedPathName
) / sizeof(WCHAR
), ExpectedPathName
);
150 ExpectedPathName
[3] = UNICODE_NULL
;
152 case PrefixCurrentPath
:
153 Length
= GetCurrentDirectoryW(sizeof(ExpectedPathName
) / sizeof(WCHAR
), ExpectedPathName
);
154 if (Length
== 3 && TestCases
[i
].FullPathName
[0])
155 ExpectedPathName
[2] = UNICODE_NULL
;
158 skip("Invalid test!\n");
161 wcscat(ExpectedPathName
, TestCases
[i
].FullPathName
);
162 RtlFillMemory(FullPathNameBuffer
, sizeof(FullPathNameBuffer
), 0xAA);
165 Length
= RtlGetFullPathName_U(TestCases
[i
].FileName
,
166 sizeof(FullPathNameBuffer
),
169 EndSeh(STATUS_SUCCESS
);
171 Okay
= CheckStringBuffer(FullPathNameBuffer
, Length
, sizeof(FullPathNameBuffer
), ExpectedPathName
);
172 ok(Okay
, "Wrong path name '%S', expected '%S'\n", FullPathNameBuffer
, ExpectedPathName
);
177 FilePartSize
= ShortName
- FullPathNameBuffer
;
179 switch (TestCases
[i
].FilePartPrefixType
)
182 ExpectedFilePartSize
= 0;
184 case PrefixCurrentDrive
:
185 ExpectedFilePartSize
= sizeof(L
"C:\\");
187 case PrefixCurrentPath
:
188 ExpectedFilePartSize
= GetCurrentDirectoryW(0, NULL
) * sizeof(WCHAR
);
189 if (ExpectedFilePartSize
== sizeof(L
"C:\\"))
190 ExpectedFilePartSize
-= sizeof(WCHAR
);
192 case PrefixCurrentPathWithoutLastPart
:
194 WCHAR CurrentPath
[MAX_PATH
];
196 ExpectedFilePartSize
= GetCurrentDirectoryW(sizeof(CurrentPath
) / sizeof(WCHAR
), CurrentPath
) * sizeof(WCHAR
) + sizeof(UNICODE_NULL
);
197 if (ExpectedFilePartSize
== sizeof(L
"C:\\"))
198 ExpectedFilePartSize
= 0;
201 BackSlash
= wcsrchr(CurrentPath
, L
'\\');
203 ExpectedFilePartSize
-= wcslen(BackSlash
+ 1) * sizeof(WCHAR
);
205 ok(0, "GetCurrentDirectory returned %S\n", CurrentPath
);
210 skip("Invalid test!\n");
213 ExpectedFilePartSize
+= TestCases
[i
].FilePartSize
;
214 if (ExpectedFilePartSize
!= 0)
215 ExpectedFilePartSize
= (ExpectedFilePartSize
- sizeof(UNICODE_NULL
)) / sizeof(WCHAR
);
216 ok(FilePartSize
== ExpectedFilePartSize
,
217 "FilePartSize = %lu, expected %lu\n", (ULONG
)FilePartSize
, (ULONG
)ExpectedFilePartSize
);
221 START_TEST(RtlGetFullPathName_U
)
227 /* Parameter checks */
229 Length
= RtlGetFullPathName_U(NULL
, 0, NULL
, NULL
);
230 ok(Length
== 0, "Length = %lu\n", Length
);
231 EndSeh(STATUS_SUCCESS
);
234 Length
= RtlGetFullPathName_U(L
"", 0, NULL
, NULL
);
235 ok(Length
== 0, "Length = %lu\n", Length
);
236 EndSeh(STATUS_SUCCESS
);
238 ShortName
= InvalidPointer
;
240 Length
= RtlGetFullPathName_U(NULL
, 0, NULL
, &ShortName
);
241 ok(Length
== 0, "Length = %lu\n", Length
);
242 EndSeh(STATUS_SUCCESS
);
243 ok(ShortName
== InvalidPointer
||
244 broken(ShortName
== NULL
) /* Win7 */, "ShortName = %p\n", ShortName
);
247 Length
= RtlGetFullPathName_U(L
"", 0, NULL
, NULL
);
248 ok(Length
== 0, "Length = %lu\n", Length
);
249 EndSeh(STATUS_SUCCESS
);
251 ShortName
= InvalidPointer
;
253 Length
= RtlGetFullPathName_U(L
"", 0, NULL
, &ShortName
);
254 ok(Length
== 0, "Length = %lu\n", Length
);
255 EndSeh(STATUS_SUCCESS
);
256 ok(ShortName
== InvalidPointer
||
257 broken(ShortName
== NULL
) /* Win7 */, "ShortName = %p\n", ShortName
);
260 Length
= RtlGetFullPathName_U(L
"C:\\test", 0, NULL
, NULL
);
261 ok(Length
== sizeof(L
"C:\\test"), "Length = %lu\n", Length
);
262 EndSeh(STATUS_SUCCESS
);
264 FileName
= L
"C:\\test";
265 ShortName
= InvalidPointer
;
267 Length
= RtlGetFullPathName_U(FileName
, 0, NULL
, &ShortName
);
268 ok(Length
== sizeof(L
"C:\\test"), "Length = %lu\n", Length
);
269 EndSeh(STATUS_SUCCESS
);
270 ok(ShortName
== InvalidPointer
||
271 broken(ShortName
== NULL
) /* Win7 */, "ShortName = %p\n", ShortName
);
273 /* Check the actual functionality with different paths */