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 <thfabba@gmx.de>
8 #define WIN32_NO_STATUS
11 #include <wine/test.h>
12 #include <pseh/pseh2.h>
13 #include <ndk/rtlfuncs.h>
15 #define StartSeh() ExceptionStatus = STATUS_SUCCESS; _SEH2_TRY {
16 #define EndSeh(ExpectedStatus) } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { ExceptionStatus = _SEH2_GetExceptionCode(); } _SEH2_END; ok(ExceptionStatus == ExpectedStatus, "Exception %lx, expected %lx\n", ExceptionStatus, ExpectedStatus)
18 #define ok_bool_file(value, expected, file) do { \
20 ok(value == TRUE, "File '%ls' should exist, but does not\n", file); \
22 ok(value == FALSE, "File '%ls' should not exist, but does\n", file);\
25 #define ok_eq_ustr(str1, str2) do { \
26 ok((str1)->Buffer == (str2)->Buffer, "Buffer modified\n"); \
27 ok((str1)->Length == (str2)->Length, "Length modified\n"); \
28 ok((str1)->MaximumLength == (str2)->MaximumLength, "MaximumLength modified\n"); \
40 RtlDoesFileExists_UEx(
42 IN BOOLEAN SucceedIfBusy
47 RtlDoesFileExists_UStr(
48 IN PUNICODE_STRING FileName
53 RtlDoesFileExists_UstrEx(
54 IN PCUNICODE_STRING FileName,
55 IN BOOLEAN SucceedIfBusy
62 *RtlDoesFileExists_UEx
)(
64 IN BOOLEAN SucceedIfBusy
66 //= (PVOID)0x7c8187d0 // 2003 sp1 x86
67 //= (PVOID)0x7769aeb2 // win7 sp1 wow64
73 *RtlDoesFileExists_UStr
)(
74 IN PUNICODE_STRING FileName
76 //= (PVOID)0x7c8474e5 // 2003 sp1 x86
77 //= (PVOID)0x776ff304 // win7 sp1 wow64
83 *RtlDoesFileExists_UstrEx
)(
84 IN PCUNICODE_STRING FileName
,
85 IN BOOLEAN SucceedIfBusy
87 //= (PVOID)0x7c830f89 // 2003 sp1 x86
88 //= (PVOID)0x7769addb // win7 sp1 wow64
91 START_TEST(RtlDoesFileExists
)
93 NTSTATUS ExceptionStatus
;
116 { L
"\\/\\\\", FALSE
},
117 { L
"\\/\\/\\", FALSE
},
120 { L
"\\\\\\", FALSE
},
122 { L
"\\\\.\\", FALSE
},
123 { L
"\\\\.\\GLOBAL??", FALSE
},
124 { L
"\\\\.\\GLOBAL??\\", FALSE
},
126 { L
"\\\\??", FALSE
},
127 { L
"\\\\??\\", FALSE
},
128 { L
"\\\\??\\C:\\", FALSE
},
130 { L
"\\\\.\\", FALSE
},
135 { L
"C:\\/\\", TRUE
},
139 { L
"C:\\%ls", TRUE
},
141 { L
"C://%ls", TRUE
},
142 { L
"C:\\/%ls", TRUE
},
143 { L
"C:/\\%ls", TRUE
},
144 { L
"C:\\/\\%ls", TRUE
},
145 { L
"C:\\%ls\\", TRUE
},
146 { L
"C:\\%ls\\ThisFolderExists", TRUE
},
147 { L
"C:\\%ls\\ThisDoesntExist", FALSE
},
148 { L
"C:\\\\%ls\\\\ThisFolderExists", TRUE
},
149 { L
"C:\\%ls\\ThisFolderExists\\ThisFileExists", TRUE
},
150 { L
"c:\\%ls\\thisfolderexists\\thisfileexists", TRUE
},
151 { L
"C:\\%ls\\THISFOLDEREXISTS\\THISFILEEXISTS", TRUE
},
152 { L
"C:\\%ls;C:\\", FALSE
},
153 { L
"%%SystemRoot%%", FALSE
},
154 { L
"%%SystemRoot%%\\", FALSE
},
155 { L
"%%SystemRoot%%\\system32", FALSE
},
161 WCHAR FileName
[MAX_PATH
];
162 WCHAR CustomPath
[MAX_PATH
] = L
"RtlDoesFileExists_U_TestPath";
167 Ret
= RtlDoesFileExists_U(NULL
);
168 ok(Ret
== FALSE
, "NULL file exists?!\n");
169 EndSeh(STATUS_SUCCESS
);
171 swprintf(FileName
, L
"C:\\%ls", CustomPath
);
172 /* Make sure this directory doesn't exist */
173 while (GetFileAttributes(FileName
) != INVALID_FILE_ATTRIBUTES
)
175 wcscat(CustomPath
, L
"X");
176 swprintf(FileName
, L
"C:\\%ls", CustomPath
);
178 Success
= CreateDirectory(FileName
, NULL
);
179 ok(Success
, "CreateDirectory failed, results might not be accurate\n");
180 swprintf(FileName
, L
"C:\\%ls\\ThisFolderExists", CustomPath
);
181 Success
= CreateDirectory(FileName
, NULL
);
182 ok(Success
, "CreateDirectory failed, results might not be accurate\n");
183 swprintf(FileName
, L
"C:\\%ls\\ThisFolderExists\\ThisFileExists", CustomPath
);
184 Handle
= CreateFile(FileName
, 0, 0, NULL
, CREATE_NEW
, 0, NULL
);
185 ok(Handle
!= INVALID_HANDLE_VALUE
, "CreateFile failed, results might not be accurate\n");
186 if (Handle
!= INVALID_HANDLE_VALUE
)
188 /* Check SucceedIfBusy behavior */
189 if (RtlDoesFileExists_UEx
)
191 Ret
= RtlDoesFileExists_UEx(FileName
, TRUE
);
192 ok_bool_file(Ret
, TRUE
, FileName
);
193 /* TODO: apparently we have to do something worse to make this fail */
194 Ret
= RtlDoesFileExists_UEx(FileName
, FALSE
);
195 ok_bool_file(Ret
, TRUE
, FileName
);
197 if (RtlDoesFileExists_UstrEx
)
199 UNICODE_STRING FileNameString
;
200 UNICODE_STRING TempString
;
201 RtlInitUnicodeString(&FileNameString
, FileName
);
202 TempString
= FileNameString
;
203 Ret
= RtlDoesFileExists_UstrEx(&FileNameString
, TRUE
);
204 ok_eq_ustr(&FileNameString
, &TempString
);
205 ok_bool_file(Ret
, TRUE
, FileName
);
206 /* TODO: apparently we have to do something worse to make this fail */
207 Ret
= RtlDoesFileExists_UstrEx(&FileNameString
, FALSE
);
208 ok_eq_ustr(&FileNameString
, &TempString
);
209 ok_bool_file(Ret
, TRUE
, FileName
);
214 for (i
= 0; i
< sizeof(Tests
) / sizeof(Tests
[0]); i
++)
216 swprintf(FileName
, Tests
[i
].FileName
, CustomPath
);
218 Ret
= RtlDoesFileExists_U(FileName
);
219 ok_bool_file(Ret
, Tests
[i
].Exists
, FileName
);
220 EndSeh(STATUS_SUCCESS
);
221 if (RtlDoesFileExists_UEx
)
224 Ret
= RtlDoesFileExists_UEx(FileName
, TRUE
);
225 ok_bool_file(Ret
, Tests
[i
].Exists
, FileName
);
226 EndSeh(STATUS_SUCCESS
);
228 Ret
= RtlDoesFileExists_UEx(FileName
, FALSE
);
229 ok_bool_file(Ret
, Tests
[i
].Exists
, FileName
);
230 EndSeh(STATUS_SUCCESS
);
232 /* TODO: use guarded memory to make sure these don't touch the null terminator */
233 if (RtlDoesFileExists_UStr
)
235 UNICODE_STRING FileNameString
;
236 UNICODE_STRING TempString
;
237 RtlInitUnicodeString(&FileNameString
, FileName
);
238 TempString
= FileNameString
;
240 Ret
= RtlDoesFileExists_UStr(&FileNameString
);
241 ok_bool_file(Ret
, Tests
[i
].Exists
, FileName
);
242 EndSeh(STATUS_SUCCESS
);
243 ok_eq_ustr(&FileNameString
, &TempString
);
245 if (RtlDoesFileExists_UstrEx
)
247 UNICODE_STRING FileNameString
;
248 UNICODE_STRING TempString
;
249 RtlInitUnicodeString(&FileNameString
, FileName
);
250 TempString
= FileNameString
;
252 Ret
= RtlDoesFileExists_UstrEx(&FileNameString
, TRUE
);
253 ok_bool_file(Ret
, Tests
[i
].Exists
, FileName
);
254 EndSeh(STATUS_SUCCESS
);
255 ok_eq_ustr(&FileNameString
, &TempString
);
257 Ret
= RtlDoesFileExists_UstrEx(&FileNameString
, FALSE
);
258 ok_bool_file(Ret
, Tests
[i
].Exists
, FileName
);
259 EndSeh(STATUS_SUCCESS
);
260 ok_eq_ustr(&FileNameString
, &TempString
);
264 swprintf(FileName
, L
"C:\\%ls\\ThisFolderExists\\ThisFileExists", CustomPath
);
265 Success
= DeleteFile(FileName
);
266 ok(Success
, "DeleteFile failed, test might leave stale file\n");
267 swprintf(FileName
, L
"C:\\%ls\\ThisFolderExists", CustomPath
);
268 Success
= RemoveDirectory(FileName
);
269 ok(Success
, "RemoveDirectory failed, test might leave stale directory\n");
270 swprintf(FileName
, L
"C:\\%ls", CustomPath
);
271 Success
= RemoveDirectory(FileName
);
272 ok(Success
, "RemoveDirectory failed, test might leave stale directory\n");