ReactOS 0.4.15-dev-7842-g558ab78
RtlDoesFileExists.c
Go to the documentation of this file.
1/*
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>
6 */
7
8#include "precomp.h"
9
10#define ok_bool_file(value, expected, file) do { \
11 if (expected) \
12 ok(value == TRUE, "File '%ls' should exist, but does not\n", file); \
13 else \
14 ok(value == FALSE, "File '%ls' should not exist, but does\n", file);\
15 } while (0)
16
17#define ok_eq_ustr(str1, str2) do { \
18 ok((str1)->Buffer == (str2)->Buffer, "Buffer modified\n"); \
19 ok((str1)->Length == (str2)->Length, "Length modified\n"); \
20 ok((str1)->MaximumLength == (str2)->MaximumLength, "MaximumLength modified\n"); \
21 } while (0)
22
23/*
24BOOLEAN
25NTAPI
26RtlDoesFileExists_U(
27 IN PCWSTR FileName
28);
29
30BOOLEAN
31NTAPI
32RtlDoesFileExists_UEx(
33 IN PCWSTR FileName,
34 IN BOOLEAN SucceedIfBusy
35);
36
37BOOLEAN
38NTAPI
39RtlDoesFileExists_UStr(
40 IN PUNICODE_STRING FileName
41);
42
43BOOLEAN
44NTAPI
45RtlDoesFileExists_UstrEx(
46 IN PCUNICODE_STRING FileName,
47 IN BOOLEAN SucceedIfBusy
48);
49*/
50
51static
53(NTAPI
57)
58//= (PVOID)0x7c8187d0 // 2003 sp1 x86
59//= (PVOID)0x7769aeb2 // win7 sp1 wow64
60;
61
62static
64(NTAPI
67)
68//= (PVOID)0x7c8474e5 // 2003 sp1 x86
69//= (PVOID)0x776ff304 // win7 sp1 wow64
70;
71
72static
74(NTAPI
78)
79//= (PVOID)0x7c830f89 // 2003 sp1 x86
80//= (PVOID)0x7769addb // win7 sp1 wow64
81;
82
83START_TEST(RtlDoesFileExists)
84{
85 BOOLEAN Ret;
86 struct
87 {
89 BOOLEAN Exists;
90 } Tests[] =
91 {
92 { L"", FALSE },
93 { L"?", FALSE },
94 { L"*", FALSE },
95 { L":", FALSE },
96 { L";", FALSE },
97 { L"\"", FALSE },
98 { L".", TRUE },
99 { L"..", TRUE },
100 { L"/", TRUE },
101 { L"//", FALSE },
102 { L"///", FALSE },
103 { L"\\/", FALSE },
104 { L"\\//", FALSE },
105 { L"\\\\/", FALSE },
106 { L"\\/\\", FALSE },
107 { L"\\/\\\\", FALSE },
108 { L"\\/\\/\\", FALSE },
109 { L"\\", TRUE },
110 { L"\\\\", FALSE },
111 { L"\\\\\\", FALSE },
112 { L"\\\\.", FALSE },
113 { L"\\\\.\\", FALSE },
114 { L"\\\\.\\GLOBAL??", FALSE },
115 { L"\\\\.\\GLOBAL??\\", FALSE },
116 { L"\\\\?", FALSE },
117 { L"\\\\??", FALSE },
118 { L"\\\\??\\", FALSE },
119 { L"\\\\??\\C:\\", FALSE },
120 { L"\\\\.", FALSE },
121 { L"\\\\.\\", FALSE },
122 { L"C:", TRUE },
123 { L"C:/", TRUE },
124 { L"C:/\\", TRUE },
125 { L"C:\\/", TRUE },
126 { L"C:\\/\\", TRUE },
127 { L"C://", TRUE },
128 { L"C:\\", TRUE },
129 { L"C:\\\\", TRUE },
130 { L"C:\\%ls", TRUE },
131 { L"C:/%ls", TRUE },
132 { L"C://%ls", TRUE },
133 { L"C:\\/%ls", TRUE },
134 { L"C:/\\%ls", TRUE },
135 { L"C:\\/\\%ls", TRUE },
136 { L"C:\\%ls\\", TRUE },
137 { L"C:\\%ls\\ThisFolderExists", TRUE },
138 { L"C:\\%ls\\ThisFolderExists\\", TRUE },
139 { L"C:\\%ls\\ThisFolderExists ", TRUE },
140 { L"C:\\%ls\\ThisFolderExists ", TRUE },
141 { L"C:\\%ls\\ThisFolderExists ", TRUE },
142 { L"C:\\%ls\\ThisFolderExists:", FALSE },
143 { L"C:\\%ls\\ThisFolderExists\t", FALSE },
144 { L"C:\\%ls\\ThisFolderExists\n", FALSE },
145 { L"C:\\%ls\\ThisFolderExists\r", FALSE },
146 { L" C:\\%ls\\ThisFolderExists", FALSE },
147 { L"C:\\%ls\\ ThisFolderExists", FALSE },
148 { L"C:\\%ls \\ThisFolderExists", FALSE },
149 { L"C:\\%ls\\ThisDoesntExist", FALSE },
150 { L"C:\\\\%ls\\\\ThisFolderExists", TRUE },
151 { L"C:\\%ls\\ThisFolderExists\\ThisFileExists", TRUE },
152 { L"c:\\%ls\\thisfolderexists\\thisfileexists", TRUE },
153 { L"C:\\%ls\\THISFOLDEREXISTS\\THISFILEEXISTS", TRUE },
154 { L"C:\\%ls\\ThisFolderExists\\SomeProgram.exe",TRUE },
155 { L"C:\\%ls\\ThisFolderExists\\SomeProgram", FALSE },
156 { L"C:\\%ls\\ThisFolderExists\\With", FALSE },
157 { L"C:\\%ls\\ThisFolderExists\\With Space", TRUE },
158 { L"C:\\%ls\\ThisFolderExists\\Without", TRUE },
159 { L"C:\\%ls\\ThisFolderExists\\Without Space", FALSE },
160 { L"C:\\%ls abc", FALSE },
161 { L"\"C:\\%ls\" abc", FALSE },
162 { L"\"C:\\\"", FALSE },
163 { L"C:\\%ls;C:\\", FALSE },
164 { L"%%SystemRoot%%", FALSE },
165 { L"%%SystemRoot%%\\", FALSE },
166 { L"%%SystemRoot%%\\system32", FALSE },
167 { L"NUL", FALSE },
168 { L"CON", FALSE },
169 { L"COM1", FALSE },
170 { L"\\?", FALSE },
171 { L"\\??", FALSE },
172 { L"\\??\\", FALSE },
173 { L"\\??\\C", FALSE },
174 { L"\\??\\C:", FALSE },
175 { L"\\??\\C:\\", FALSE }, // TRUE on Win7
176 { L"\\??\\C:\\%ls\\ThisFolderExists", FALSE }, // TRUE on Win7
177 };
178 ULONG i;
180 WCHAR CustomPath[MAX_PATH] = L"RtlDoesFileExists_U_TestPath";
183
185 {
186 RtlDoesFileExists_UEx = (PVOID)GetProcAddress(GetModuleHandleW(L"ntdll"), "RtlDoesFileExists_UEx");
188 skip("RtlDoesFileExists_UEx unavailable\n");
189 }
190
192 {
193 RtlDoesFileExists_UStr = (PVOID)GetProcAddress(GetModuleHandleW(L"ntdll"), "RtlDoesFileExists_UStr");
195 skip("RtlDoesFileExists_UStr unavailable\n");
196 }
197
199 {
200 RtlDoesFileExists_UstrEx = (PVOID)GetProcAddress(GetModuleHandleW(L"ntdll"), "RtlDoesFileExists_UstrEx");
202 skip("RtlDoesFileExists_UstrEx unavailable\n");
203 }
204
205 StartSeh()
207 ok(Ret == FALSE, "NULL file exists?!\n");
209
211 {
212 StartSeh()
214 ok(Ret == FALSE, "NULL file exists?!\n");
216 ok(Ret == FALSE, "NULL file exists?!\n");
218 }
219
221 {
223 }
224
226 {
229 }
230
231 swprintf(FileName, L"C:\\%ls", CustomPath);
232 /* Make sure this directory doesn't exist */
234 {
235 wcscat(CustomPath, L"X");
236 swprintf(FileName, L"C:\\%ls", CustomPath);
237 }
239 ok(Success, "CreateDirectory failed, results might not be accurate\n");
240 swprintf(FileName, L"C:\\%ls\\ThisFolderExists", CustomPath);
242 ok(Success, "CreateDirectory failed, results might not be accurate\n");
243 swprintf(FileName, L"C:\\%ls\\ThisFolderExists\\ThisFileExists", CustomPath);
245 ok(Handle != INVALID_HANDLE_VALUE, "CreateFile failed, results might not be accurate\n");
247 {
248 /* Check SucceedIfBusy behavior */
250 {
253 /* TODO: apparently we have to do something worse to make this fail */
256 }
258 {
259 UNICODE_STRING FileNameString;
260 UNICODE_STRING TempString;
261 RtlInitUnicodeString(&FileNameString, FileName);
262 TempString = FileNameString;
263 Ret = RtlDoesFileExists_UstrEx(&FileNameString, TRUE);
264 ok_eq_ustr(&FileNameString, &TempString);
266 /* TODO: apparently we have to do something worse to make this fail */
267 Ret = RtlDoesFileExists_UstrEx(&FileNameString, FALSE);
268 ok_eq_ustr(&FileNameString, &TempString);
270 }
272 }
273
274 swprintf(FileName, L"C:\\%ls\\ThisFolderExists\\SomeProgram.exe", CustomPath);
276 ok(Handle != INVALID_HANDLE_VALUE, "CreateFile failed, results might not be accurate\n");
278
279 swprintf(FileName, L"C:\\%ls\\ThisFolderExists\\With Space", CustomPath);
281 ok(Handle != INVALID_HANDLE_VALUE, "CreateFile failed, results might not be accurate\n");
283
284 swprintf(FileName, L"C:\\%ls\\ThisFolderExists\\Without", CustomPath);
286 ok(Handle != INVALID_HANDLE_VALUE, "CreateFile failed, results might not be accurate\n");
288
289 for (i = 0; i < sizeof(Tests) / sizeof(Tests[0]); i++)
290 {
291 swprintf(FileName, Tests[i].FileName, CustomPath);
292 StartSeh()
294 ok_bool_file(Ret, Tests[i].Exists, FileName);
297 {
298 StartSeh()
300 ok_bool_file(Ret, Tests[i].Exists, FileName);
302 StartSeh()
304 ok_bool_file(Ret, Tests[i].Exists, FileName);
306 }
307 /* TODO: use guarded memory to make sure these don't touch the null terminator */
309 {
310 UNICODE_STRING FileNameString;
311 UNICODE_STRING TempString;
312 RtlInitUnicodeString(&FileNameString, FileName);
313 TempString = FileNameString;
314 StartSeh()
315 Ret = RtlDoesFileExists_UStr(&FileNameString);
316 ok_bool_file(Ret, Tests[i].Exists, FileName);
318 ok_eq_ustr(&FileNameString, &TempString);
319 }
321 {
322 UNICODE_STRING FileNameString;
323 UNICODE_STRING TempString;
324 RtlInitUnicodeString(&FileNameString, FileName);
325 TempString = FileNameString;
326 StartSeh()
327 Ret = RtlDoesFileExists_UstrEx(&FileNameString, TRUE);
328 ok_bool_file(Ret, Tests[i].Exists, FileName);
330 ok_eq_ustr(&FileNameString, &TempString);
331 StartSeh()
332 Ret = RtlDoesFileExists_UstrEx(&FileNameString, FALSE);
333 ok_bool_file(Ret, Tests[i].Exists, FileName);
335 ok_eq_ustr(&FileNameString, &TempString);
336 }
337 }
338
339 swprintf(FileName, L"C:\\%ls\\ThisFolderExists\\Without", CustomPath);
341 ok(Success, "DeleteFile failed (%lu), test might leave stale file\n", GetLastError());
342 swprintf(FileName, L"C:\\%ls\\ThisFolderExists\\With Space", CustomPath);
344 ok(Success, "DeleteFile failed (%lu), test might leave stale file\n", GetLastError());
345 swprintf(FileName, L"C:\\%ls\\ThisFolderExists\\SomeProgram.exe", CustomPath);
347 ok(Success, "DeleteFile failed (%lu), test might leave stale file\n", GetLastError());
348
349 swprintf(FileName, L"C:\\%ls\\ThisFolderExists\\ThisFileExists", CustomPath);
351 ok(Success, "DeleteFile failed (%lu), test might leave stale file\n", GetLastError());
352 swprintf(FileName, L"C:\\%ls\\ThisFolderExists", CustomPath);
354 ok(Success, "RemoveDirectory failed (%lu), test might leave stale directory\n", GetLastError());
355 swprintf(FileName, L"C:\\%ls", CustomPath);
357 ok(Success, "RemoveDirectory failed (%lu), test might leave stale directory\n", GetLastError());
358}
unsigned char BOOLEAN
static IN BOOLEAN SucceedIfBusy
#define ok_eq_ustr(str1, str2)
#define ok_bool_file(value, expected, file)
struct test_data Tests[]
#define StartSeh()
Definition: _sntprintf.h:16
#define EndSeh(ExpectedStatus)
Definition: _sntprintf.h:17
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define START_TEST(x)
Definition: atltest.h:75
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define CloseHandle
Definition: compat.h:739
#define GetProcAddress(x, y)
Definition: compat.h:753
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define MAX_PATH
Definition: compat.h:34
#define CreateFileW
Definition: compat.h:741
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
BOOL WINAPI CreateDirectoryW(IN LPCWSTR lpPathName, IN LPSECURITY_ATTRIBUTES lpSecurityAttributes)
Definition: dir.c:90
BOOL WINAPI RemoveDirectoryW(IN LPCWSTR lpPathName)
Definition: dir.c:732
DWORD WINAPI GetFileAttributesW(LPCWSTR lpFileName)
Definition: fileinfo.c:652
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:838
#define swprintf
Definition: precomp.h:40
@ Success
Definition: eventcreate.c:712
struct _FileName FileName
Definition: fatprocs.h:896
unsigned int BOOL
Definition: ntddk_ex.h:94
ULONG Handle
Definition: gdb_input.c:15
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define CREATE_NEW
Definition: disk.h:69
NTSYSAPI BOOLEAN NTAPI RtlDoesFileExists_U(_In_ PCWSTR FileName)
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
BOOLEAN NTAPI RtlDoesFileExists_UStr(IN PUNICODE_STRING FileName)
Definition: path.c:1503
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:242
#define L(x)
Definition: ntvdm.h:50
#define BOOLEAN
Definition: pedump.c:73
_CRTIMP wchar_t *__cdecl wcscat(_Inout_updates_z_(_String_length_(_Dest)+_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
BOOLEAN NTAPI RtlDoesFileExists_UstrEx(IN PCUNICODE_STRING FileName, IN BOOLEAN SucceedIfBusy)
Definition: path.c:1430
BOOLEAN NTAPI RtlDoesFileExists_UEx(IN PCWSTR FileName, IN BOOLEAN SucceedIfBusy)
Definition: path.c:1511
#define STATUS_SUCCESS
Definition: shellext.h:65
const uint16_t * PCWSTR
Definition: typedefs.h:57
#define NTAPI
Definition: typedefs.h:36
void * PVOID
Definition: typedefs.h:50
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
__wchar_t WCHAR
Definition: xmlstorage.h:180