ReactOS  0.4.15-dev-3453-gff89651
RtlDoesFileExists.c File Reference
#include "precomp.h"
Include dependency graph for RtlDoesFileExists.c:

Go to the source code of this file.

Macros

#define ok_bool_file(value, expected, file)
 
#define ok_eq_ustr(str1, str2)
 

Functions

static BOOLEAN (NTAPI *RtlDoesFileExists_UEx)(IN PCWSTR FileName
 
 START_TEST (RtlDoesFileExists)
 

Variables

static IN BOOLEAN SucceedIfBusy
 

Macro Definition Documentation

◆ ok_bool_file

#define ok_bool_file (   value,
  expected,
  file 
)
Value:
do { \
if (expected) \
ok(value == TRUE, "File '%ls' should exist, but does not\n", file); \
ok(value == FALSE, "File '%ls' should not exist, but does\n", file);\
} while (0)
Definition: pdh_main.c:93
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define ok(value,...)
Definition: atltest.h:57
BOOL expected
Definition: store.c:2063
Definition: fci.c:126

Definition at line 10 of file RtlDoesFileExists.c.

◆ ok_eq_ustr

#define ok_eq_ustr (   str1,
  str2 
)
Value:
do { \
ok((str1)->Buffer == (str2)->Buffer, "Buffer modified\n"); \
ok((str1)->Length == (str2)->Length, "Length modified\n"); \
ok((str1)->MaximumLength == (str2)->MaximumLength, "MaximumLength modified\n"); \
} while (0)
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
Definition: bufpool.h:45
_In_ WDFDMATRANSACTION _In_ size_t MaximumLength

Definition at line 17 of file RtlDoesFileExists.c.

Function Documentation

◆ BOOLEAN()

static BOOLEAN ( NTAPI RtlDoesFileExists_UEx)
static

◆ START_TEST()

START_TEST ( RtlDoesFileExists  )

Definition at line 83 of file RtlDoesFileExists.c.

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";
181  BOOL Success;
182  HANDLE Handle;
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()
206  Ret = RtlDoesFileExists_U(NULL);
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  {
252  ok_bool_file(Ret, TRUE, FileName);
253  /* TODO: apparently we have to do something worse to make this fail */
255  ok_bool_file(Ret, TRUE, FileName);
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);
265  ok_bool_file(Ret, TRUE, FileName);
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);
269  ok_bool_file(Ret, TRUE, FileName);
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 }
BOOL WINAPI CreateDirectoryW(IN LPCWSTR lpPathName, IN LPSECURITY_ATTRIBUTES lpSecurityAttributes)
Definition: dir.c:90
while(CdLookupNextInitialFileDirent(IrpContext, Fcb, FileContext))
const uint16_t * PCWSTR
Definition: typedefs.h:57
#define CloseHandle
Definition: compat.h:598
#define TRUE
Definition: types.h:120
#define RemoveDirectory
Definition: winbase.h:3751
GLdouble n
Definition: glext.h:7729
#define INVALID_HANDLE_VALUE
Definition: compat.h:590
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1040
#define test
Definition: rosglue.h:37
#define swprintf
Definition: precomp.h:40
if(dx==0 &&dy==0)
Definition: linetemp.h:174
#define DeleteFile
Definition: winbase.h:3620
Definition: terminate.cpp:23
#define StartSeh()
Definition: _sntprintf.h:16
void ls(int argc, const char *argv[])
Definition: cmds.c:1136
#define L(x)
Definition: ntvdm.h:50
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
DWORD WINAPI GetFileAttributesW(LPCWSTR lpFileName)
Definition: fileinfo.c:652
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
unsigned char BOOLEAN
#define leave
Definition: seh.h:23
void * PVOID
Definition: retypes.h:9
BOOL WINAPI RemoveDirectoryW(IN LPCWSTR lpPathName)
Definition: dir.c:732
NTSYSAPI BOOLEAN NTAPI RtlDoesFileExists_U(_In_ PCWSTR FileName)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:34
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
BOOLEAN NTAPI RtlDoesFileExists_UEx(IN PCWSTR FileName, IN BOOLEAN SucceedIfBusy)
Definition: path.c:1511
#define ok_eq_ustr(str1, str2)
struct _FileName FileName
Definition: fatprocs.h:893
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 STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:242
BOOLEAN NTAPI RtlDoesFileExists_UStr(IN PUNICODE_STRING FileName)
Definition: path.c:1503
#define ok(value,...)
Definition: atltest.h:57
BOOLEAN NTAPI RtlDoesFileExists_UstrEx(IN PCUNICODE_STRING FileName, IN BOOLEAN SucceedIfBusy)
Definition: path.c:1430
_CRTIMP wchar_t *__cdecl wcscat(_Inout_updates_z_(_String_length_(_Dest)+_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
#define NULL
Definition: types.h:112
#define CreateFileW
Definition: compat.h:600
#define skip(...)
Definition: atltest.h:64
_In_ HANDLE Handle
Definition: extypes.h:390
#define ok_bool_file(value, expected, file)
unsigned int ULONG
Definition: retypes.h:1
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:838
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define GetProcAddress(x, y)
Definition: compat.h:612
#define CREATE_NEW
Definition: disk.h:69
#define STATUS_SUCCESS
Definition: shellext.h:65
struct test_data Tests[]
#define EndSeh(ExpectedStatus)
Definition: _sntprintf.h:17
Definition: fci.c:126

Variable Documentation

◆ SucceedIfBusy

static IN BOOLEAN SucceedIfBusy

Definition at line 60 of file RtlDoesFileExists.c.

Referenced by RtlDoesFileExists_UEx(), and RtlDoesFileExists_UstrEx().