2 * PROJECT: ReactOS api tests
3 * LICENSE: GPLv2+ - See COPYING in the top level directory
4 * PURPOSE: Test for RtlDoesFileExists_U*
5 * PROGRAMMER: Thomas Faber <thomas.faber@reactos.org>
10 #define WIN32_NO_STATUS
12 #include <ndk/rtlfuncs.h>
14 #define ok_bool_file(value, expected, file) do { \
16 ok(value == TRUE, "File '%ls' should exist, but does not\n", file); \
18 ok(value == FALSE, "File '%ls' should not exist, but does\n", file);\
21 #define ok_eq_ustr(str1, str2) do { \
22 ok((str1)->Buffer == (str2)->Buffer, "Buffer modified\n"); \
23 ok((str1)->Length == (str2)->Length, "Length modified\n"); \
24 ok((str1)->MaximumLength == (str2)->MaximumLength, "MaximumLength modified\n"); \
36 RtlDoesFileExists_UEx(
38 IN BOOLEAN SucceedIfBusy
43 RtlDoesFileExists_UStr(
44 IN PUNICODE_STRING FileName
49 RtlDoesFileExists_UstrEx(
50 IN PCUNICODE_STRING FileName,
51 IN BOOLEAN SucceedIfBusy
58 *RtlDoesFileExists_UEx
)(
60 IN BOOLEAN SucceedIfBusy
62 //= (PVOID)0x7c8187d0 // 2003 sp1 x86
63 //= (PVOID)0x7769aeb2 // win7 sp1 wow64
69 *RtlDoesFileExists_UStr
)(
70 IN PUNICODE_STRING FileName
72 //= (PVOID)0x7c8474e5 // 2003 sp1 x86
73 //= (PVOID)0x776ff304 // win7 sp1 wow64
79 *RtlDoesFileExists_UstrEx
)(
80 IN PCUNICODE_STRING FileName
,
81 IN BOOLEAN SucceedIfBusy
83 //= (PVOID)0x7c830f89 // 2003 sp1 x86
84 //= (PVOID)0x7769addb // win7 sp1 wow64
87 START_TEST(RtlDoesFileExists
)
111 { L
"\\/\\\\", FALSE
},
112 { L
"\\/\\/\\", FALSE
},
115 { L
"\\\\\\", FALSE
},
117 { L
"\\\\.\\", FALSE
},
118 { L
"\\\\.\\GLOBAL??", FALSE
},
119 { L
"\\\\.\\GLOBAL??\\", FALSE
},
121 { L
"\\\\??", FALSE
},
122 { L
"\\\\??\\", FALSE
},
123 { L
"\\\\??\\C:\\", FALSE
},
125 { L
"\\\\.\\", FALSE
},
130 { L
"C:\\/\\", TRUE
},
134 { L
"C:\\%ls", TRUE
},
136 { L
"C://%ls", TRUE
},
137 { L
"C:\\/%ls", TRUE
},
138 { L
"C:/\\%ls", TRUE
},
139 { L
"C:\\/\\%ls", TRUE
},
140 { L
"C:\\%ls\\", TRUE
},
141 { L
"C:\\%ls\\ThisFolderExists", TRUE
},
142 { L
"C:\\%ls\\ThisDoesntExist", FALSE
},
143 { L
"C:\\\\%ls\\\\ThisFolderExists", TRUE
},
144 { L
"C:\\%ls\\ThisFolderExists\\ThisFileExists", TRUE
},
145 { L
"c:\\%ls\\thisfolderexists\\thisfileexists", TRUE
},
146 { L
"C:\\%ls\\THISFOLDEREXISTS\\THISFILEEXISTS", TRUE
},
147 { L
"C:\\%ls abc", FALSE
},
148 { L
"\"C:\\%ls\" abc", FALSE
},
149 { L
"\"C:\\\"", FALSE
},
150 { L
"C:\\%ls;C:\\", FALSE
},
151 { L
"%%SystemRoot%%", FALSE
},
152 { L
"%%SystemRoot%%\\", FALSE
},
153 { L
"%%SystemRoot%%\\system32", FALSE
},
159 WCHAR FileName
[MAX_PATH
];
160 WCHAR CustomPath
[MAX_PATH
] = L
"RtlDoesFileExists_U_TestPath";
164 if (!RtlDoesFileExists_UEx
)
166 RtlDoesFileExists_UEx
= (PVOID
)GetProcAddress(GetModuleHandleW(L
"ntdll"), "RtlDoesFileExists_UEx");
167 if (!RtlDoesFileExists_UEx
)
168 skip("RtlDoesFileExists_UEx unavailable\n");
171 if (!RtlDoesFileExists_UStr
)
173 RtlDoesFileExists_UStr
= (PVOID
)GetProcAddress(GetModuleHandleW(L
"ntdll"), "RtlDoesFileExists_UStr");
174 if (!RtlDoesFileExists_UStr
)
175 skip("RtlDoesFileExists_UStr unavailable\n");
178 if (!RtlDoesFileExists_UstrEx
)
180 RtlDoesFileExists_UstrEx
= (PVOID
)GetProcAddress(GetModuleHandleW(L
"ntdll"), "RtlDoesFileExists_UstrEx");
181 if (!RtlDoesFileExists_UstrEx
)
182 skip("RtlDoesFileExists_UstrEx unavailable\n");
186 Ret
= RtlDoesFileExists_U(NULL
);
187 ok(Ret
== FALSE
, "NULL file exists?!\n");
188 EndSeh(STATUS_SUCCESS
);
190 if (RtlDoesFileExists_UEx
)
193 Ret
= RtlDoesFileExists_UEx(NULL
, TRUE
);
194 ok(Ret
== FALSE
, "NULL file exists?!\n");
195 Ret
= RtlDoesFileExists_UEx(NULL
, FALSE
);
196 ok(Ret
== FALSE
, "NULL file exists?!\n");
197 EndSeh(STATUS_SUCCESS
);
200 if (RtlDoesFileExists_UStr
)
202 StartSeh() Ret
= RtlDoesFileExists_UStr(NULL
); EndSeh(STATUS_ACCESS_VIOLATION
);
205 if (RtlDoesFileExists_UstrEx
)
207 StartSeh() RtlDoesFileExists_UstrEx(NULL
, FALSE
); EndSeh(STATUS_ACCESS_VIOLATION
);
208 StartSeh() RtlDoesFileExists_UstrEx(NULL
, TRUE
); EndSeh(STATUS_ACCESS_VIOLATION
);
211 swprintf(FileName
, L
"C:\\%ls", CustomPath
);
212 /* Make sure this directory doesn't exist */
213 while (GetFileAttributesW(FileName
) != INVALID_FILE_ATTRIBUTES
)
215 wcscat(CustomPath
, L
"X");
216 swprintf(FileName
, L
"C:\\%ls", CustomPath
);
218 Success
= CreateDirectoryW(FileName
, NULL
);
219 ok(Success
, "CreateDirectory failed, results might not be accurate\n");
220 swprintf(FileName
, L
"C:\\%ls\\ThisFolderExists", CustomPath
);
221 Success
= CreateDirectoryW(FileName
, NULL
);
222 ok(Success
, "CreateDirectory failed, results might not be accurate\n");
223 swprintf(FileName
, L
"C:\\%ls\\ThisFolderExists\\ThisFileExists", CustomPath
);
224 Handle
= CreateFileW(FileName
, 0, 0, NULL
, CREATE_NEW
, 0, NULL
);
225 ok(Handle
!= INVALID_HANDLE_VALUE
, "CreateFile failed, results might not be accurate\n");
226 if (Handle
!= INVALID_HANDLE_VALUE
)
228 /* Check SucceedIfBusy behavior */
229 if (RtlDoesFileExists_UEx
)
231 Ret
= RtlDoesFileExists_UEx(FileName
, TRUE
);
232 ok_bool_file(Ret
, TRUE
, FileName
);
233 /* TODO: apparently we have to do something worse to make this fail */
234 Ret
= RtlDoesFileExists_UEx(FileName
, FALSE
);
235 ok_bool_file(Ret
, TRUE
, FileName
);
237 if (RtlDoesFileExists_UstrEx
)
239 UNICODE_STRING FileNameString
;
240 UNICODE_STRING TempString
;
241 RtlInitUnicodeString(&FileNameString
, FileName
);
242 TempString
= FileNameString
;
243 Ret
= RtlDoesFileExists_UstrEx(&FileNameString
, TRUE
);
244 ok_eq_ustr(&FileNameString
, &TempString
);
245 ok_bool_file(Ret
, TRUE
, FileName
);
246 /* TODO: apparently we have to do something worse to make this fail */
247 Ret
= RtlDoesFileExists_UstrEx(&FileNameString
, FALSE
);
248 ok_eq_ustr(&FileNameString
, &TempString
);
249 ok_bool_file(Ret
, TRUE
, FileName
);
254 for (i
= 0; i
< sizeof(Tests
) / sizeof(Tests
[0]); i
++)
256 swprintf(FileName
, Tests
[i
].FileName
, CustomPath
);
258 Ret
= RtlDoesFileExists_U(FileName
);
259 ok_bool_file(Ret
, Tests
[i
].Exists
, FileName
);
260 EndSeh(STATUS_SUCCESS
);
261 if (RtlDoesFileExists_UEx
)
264 Ret
= RtlDoesFileExists_UEx(FileName
, TRUE
);
265 ok_bool_file(Ret
, Tests
[i
].Exists
, FileName
);
266 EndSeh(STATUS_SUCCESS
);
268 Ret
= RtlDoesFileExists_UEx(FileName
, FALSE
);
269 ok_bool_file(Ret
, Tests
[i
].Exists
, FileName
);
270 EndSeh(STATUS_SUCCESS
);
272 /* TODO: use guarded memory to make sure these don't touch the null terminator */
273 if (RtlDoesFileExists_UStr
)
275 UNICODE_STRING FileNameString
;
276 UNICODE_STRING TempString
;
277 RtlInitUnicodeString(&FileNameString
, FileName
);
278 TempString
= FileNameString
;
280 Ret
= RtlDoesFileExists_UStr(&FileNameString
);
281 ok_bool_file(Ret
, Tests
[i
].Exists
, FileName
);
282 EndSeh(STATUS_SUCCESS
);
283 ok_eq_ustr(&FileNameString
, &TempString
);
285 if (RtlDoesFileExists_UstrEx
)
287 UNICODE_STRING FileNameString
;
288 UNICODE_STRING TempString
;
289 RtlInitUnicodeString(&FileNameString
, FileName
);
290 TempString
= FileNameString
;
292 Ret
= RtlDoesFileExists_UstrEx(&FileNameString
, TRUE
);
293 ok_bool_file(Ret
, Tests
[i
].Exists
, FileName
);
294 EndSeh(STATUS_SUCCESS
);
295 ok_eq_ustr(&FileNameString
, &TempString
);
297 Ret
= RtlDoesFileExists_UstrEx(&FileNameString
, FALSE
);
298 ok_bool_file(Ret
, Tests
[i
].Exists
, FileName
);
299 EndSeh(STATUS_SUCCESS
);
300 ok_eq_ustr(&FileNameString
, &TempString
);
304 swprintf(FileName
, L
"C:\\%ls\\ThisFolderExists\\ThisFileExists", CustomPath
);
305 Success
= DeleteFileW(FileName
);
306 ok(Success
, "DeleteFile failed, test might leave stale file\n");
307 swprintf(FileName
, L
"C:\\%ls\\ThisFolderExists", CustomPath
);
308 Success
= RemoveDirectoryW(FileName
);
309 ok(Success
, "RemoveDirectory failed, test might leave stale directory\n");
310 swprintf(FileName
, L
"C:\\%ls", CustomPath
);
311 Success
= RemoveDirectoryW(FileName
);
312 ok(Success
, "RemoveDirectory failed, test might leave stale directory\n");