ReactOS  0.4.14-dev-1007-g90d795b
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 /*
24 BOOLEAN
25 NTAPI
26 RtlDoesFileExists_U(
27  IN PCWSTR FileName
28 );
29 
30 BOOLEAN
31 NTAPI
32 RtlDoesFileExists_UEx(
33  IN PCWSTR FileName,
34  IN BOOLEAN SucceedIfBusy
35 );
36 
37 BOOLEAN
38 NTAPI
39 RtlDoesFileExists_UStr(
40  IN PUNICODE_STRING FileName
41 );
42 
43 BOOLEAN
44 NTAPI
45 RtlDoesFileExists_UstrEx(
46  IN PCUNICODE_STRING FileName,
47  IN BOOLEAN SucceedIfBusy
48 );
49 */
50 
51 static
52 BOOLEAN
53 (NTAPI
57 )
58 //= (PVOID)0x7c8187d0 // 2003 sp1 x86
59 //= (PVOID)0x7769aeb2 // win7 sp1 wow64
60 ;
61 
62 static
63 BOOLEAN
64 (NTAPI
67 )
68 //= (PVOID)0x7c8474e5 // 2003 sp1 x86
69 //= (PVOID)0x776ff304 // win7 sp1 wow64
70 ;
71 
72 static
73 BOOLEAN
74 (NTAPI
78 )
79 //= (PVOID)0x7c830f89 // 2003 sp1 x86
80 //= (PVOID)0x7769addb // win7 sp1 wow64
81 ;
82 
83 START_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";
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
const uint16_t * PCWSTR
Definition: typedefs.h:56
#define IN
Definition: typedefs.h:39
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:406
#define INVALID_HANDLE_VALUE
Definition: compat.h:399
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define StartSeh()
Definition: _sntprintf.h:16
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
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
unsigned int BOOL
Definition: ntddk_ex.h:94
DWORD WINAPI GetFileAttributesW(LPCWSTR lpFileName)
Definition: fileinfo.c:802
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
void * PVOID
Definition: retypes.h:9
BOOL WINAPI RemoveDirectoryW(IN LPCWSTR lpPathName)
Definition: dir.c:732
NTSYSAPI BOOLEAN NTAPI RtlDoesFileExists_U(_In_ PCWSTR FileName)
_In_ HANDLE Handle
Definition: extypes.h:390
__wchar_t WCHAR
Definition: xmlstorage.h:180
START_TEST(RtlDoesFileExists)
#define MAX_PATH
Definition: compat.h:26
#define swprintf(buf, format,...)
Definition: sprintf.c:56
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
static const WCHAR L[]
Definition: oid.c:1250
BOOLEAN NTAPI RtlDoesFileExists_UEx(IN PCWSTR FileName, IN BOOLEAN SucceedIfBusy)
Definition: path.c:1392
static IN BOOLEAN SucceedIfBusy
#define ok_eq_ustr(str1, str2)
struct _FileName FileName
Definition: fatprocs.h:884
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:228
BOOLEAN NTAPI RtlDoesFileExists_UStr(IN PUNICODE_STRING FileName)
Definition: path.c:1384
#define ok(value,...)
Definition: atltest.h:57
BOOLEAN NTAPI RtlDoesFileExists_UstrEx(IN PCUNICODE_STRING FileName, IN BOOLEAN SucceedIfBusy)
Definition: path.c:1311
_CRTIMP wchar_t *__cdecl wcscat(_Inout_updates_z_(_String_length_(_Dest)+_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
static BOOLEAN(NTAPI *RtlDoesFileExists_UEx)(IN PCWSTR FileName
#define CreateFileW
Definition: compat.h:408
#define skip(...)
Definition: atltest.h:64
#define ok_bool_file(value, expected, file)
unsigned int ULONG
Definition: retypes.h:1
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:847
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define GetProcAddress(x, y)
Definition: compat.h:418
#define CREATE_NEW
Definition: disk.h:69
return STATUS_SUCCESS
Definition: btrfs.c:2938
struct test_data Tests[]
#define EndSeh(ExpectedStatus)
Definition: _sntprintf.h:17