ntdll/tests: Wait for async I/O to complete when the result is STATUS_PENDING.
[wine/multimedia.git] / dlls / ntdll / tests / file.c
blobec62fe7bba926c4a3d24b7b697872c74ec2f7f05
1 /* Unit test suite for Ntdll file functions
3 * Copyright 2007 Jeff Latimer
4 * Copyright 2007 Andrey Turkin
5 * Copyright 2008 Jeff Zaroyko
6 * Copyright 2011 Dmitry Timoshkov
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 * NOTES
23 * We use function pointers here as there is no import library for NTDLL on
24 * windows.
27 #include <stdio.h>
28 #include <stdarg.h>
30 #include "ntstatus.h"
31 /* Define WIN32_NO_STATUS so MSVC does not give us duplicate macro
32 * definition errors when we get to winnt.h
34 #define WIN32_NO_STATUS
36 #include "wine/test.h"
37 #include "winternl.h"
38 #include "winuser.h"
39 #include "winioctl.h"
41 #ifndef IO_COMPLETION_ALL_ACCESS
42 #define IO_COMPLETION_ALL_ACCESS 0x001F0003
43 #endif
45 static BOOL (WINAPI * pGetVolumePathNameW)(LPCWSTR, LPWSTR, DWORD);
46 static UINT (WINAPI *pGetSystemWow64DirectoryW)( LPWSTR, UINT );
48 static VOID (WINAPI *pRtlFreeUnicodeString)( PUNICODE_STRING );
49 static VOID (WINAPI *pRtlInitUnicodeString)( PUNICODE_STRING, LPCWSTR );
50 static BOOL (WINAPI *pRtlDosPathNameToNtPathName_U)( LPCWSTR, PUNICODE_STRING, PWSTR*, CURDIR* );
51 static NTSTATUS (WINAPI *pRtlWow64EnableFsRedirectionEx)( ULONG, ULONG * );
53 static NTSTATUS (WINAPI *pNtCreateMailslotFile)( PHANDLE, ULONG, POBJECT_ATTRIBUTES, PIO_STATUS_BLOCK,
54 ULONG, ULONG, ULONG, PLARGE_INTEGER );
55 static NTSTATUS (WINAPI *pNtCreateFile)(PHANDLE,ACCESS_MASK,POBJECT_ATTRIBUTES,PIO_STATUS_BLOCK,PLARGE_INTEGER,ULONG,ULONG,ULONG,ULONG,PVOID,ULONG);
56 static NTSTATUS (WINAPI *pNtOpenFile)(PHANDLE,ACCESS_MASK,POBJECT_ATTRIBUTES,PIO_STATUS_BLOCK,ULONG,ULONG);
57 static NTSTATUS (WINAPI *pNtDeleteFile)(POBJECT_ATTRIBUTES ObjectAttributes);
58 static NTSTATUS (WINAPI *pNtReadFile)(HANDLE hFile, HANDLE hEvent,
59 PIO_APC_ROUTINE apc, void* apc_user,
60 PIO_STATUS_BLOCK io_status, void* buffer, ULONG length,
61 PLARGE_INTEGER offset, PULONG key);
62 static NTSTATUS (WINAPI *pNtWriteFile)(HANDLE hFile, HANDLE hEvent,
63 PIO_APC_ROUTINE apc, void* apc_user,
64 PIO_STATUS_BLOCK io_status,
65 const void* buffer, ULONG length,
66 PLARGE_INTEGER offset, PULONG key);
67 static NTSTATUS (WINAPI *pNtCancelIoFile)(HANDLE hFile, PIO_STATUS_BLOCK io_status);
68 static NTSTATUS (WINAPI *pNtCancelIoFileEx)(HANDLE hFile, PIO_STATUS_BLOCK iosb, PIO_STATUS_BLOCK io_status);
69 static NTSTATUS (WINAPI *pNtClose)( PHANDLE );
71 static NTSTATUS (WINAPI *pNtCreateIoCompletion)(PHANDLE, ACCESS_MASK, POBJECT_ATTRIBUTES, ULONG);
72 static NTSTATUS (WINAPI *pNtOpenIoCompletion)(PHANDLE, ACCESS_MASK, POBJECT_ATTRIBUTES);
73 static NTSTATUS (WINAPI *pNtQueryIoCompletion)(HANDLE, IO_COMPLETION_INFORMATION_CLASS, PVOID, ULONG, PULONG);
74 static NTSTATUS (WINAPI *pNtRemoveIoCompletion)(HANDLE, PULONG_PTR, PULONG_PTR, PIO_STATUS_BLOCK, PLARGE_INTEGER);
75 static NTSTATUS (WINAPI *pNtSetIoCompletion)(HANDLE, ULONG_PTR, ULONG_PTR, NTSTATUS, ULONG);
76 static NTSTATUS (WINAPI *pNtSetInformationFile)(HANDLE, PIO_STATUS_BLOCK, PVOID, ULONG, FILE_INFORMATION_CLASS);
77 static NTSTATUS (WINAPI *pNtQueryInformationFile)(HANDLE, PIO_STATUS_BLOCK, PVOID, ULONG, FILE_INFORMATION_CLASS);
78 static NTSTATUS (WINAPI *pNtQueryDirectoryFile)(HANDLE,HANDLE,PIO_APC_ROUTINE,PVOID,PIO_STATUS_BLOCK,
79 PVOID,ULONG,FILE_INFORMATION_CLASS,BOOLEAN,PUNICODE_STRING,BOOLEAN);
80 static NTSTATUS (WINAPI *pNtQueryVolumeInformationFile)(HANDLE,PIO_STATUS_BLOCK,PVOID,ULONG,FS_INFORMATION_CLASS);
82 static inline BOOL is_signaled( HANDLE obj )
84 return WaitForSingleObject( obj, 0 ) == 0;
87 #define PIPENAME "\\\\.\\pipe\\ntdll_tests_file.c"
88 #define TEST_BUF_LEN 3
90 static BOOL create_pipe( HANDLE *read, HANDLE *write, ULONG flags, ULONG size )
92 *read = CreateNamedPipe(PIPENAME, PIPE_ACCESS_INBOUND | flags, PIPE_TYPE_BYTE | PIPE_WAIT,
93 1, size, size, NMPWAIT_USE_DEFAULT_WAIT, NULL);
94 ok(*read != INVALID_HANDLE_VALUE, "CreateNamedPipe failed\n");
96 *write = CreateFileA(PIPENAME, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0);
97 ok(*write != INVALID_HANDLE_VALUE, "CreateFile failed (%d)\n", GetLastError());
99 return TRUE;
102 static HANDLE create_temp_file( ULONG flags )
104 char buffer[MAX_PATH];
105 HANDLE handle;
107 GetTempFileNameA( ".", "foo", 0, buffer );
108 handle = CreateFileA(buffer, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
109 flags | FILE_FLAG_DELETE_ON_CLOSE, 0);
110 ok( handle != INVALID_HANDLE_VALUE, "failed to create temp file\n" );
111 return (handle == INVALID_HANDLE_VALUE) ? 0 : handle;
114 #define CVALUE_FIRST 0xfffabbcc
115 #define CKEY_FIRST 0x1030341
116 #define CKEY_SECOND 0x132E46
118 static ULONG_PTR completionKey;
119 static IO_STATUS_BLOCK ioSb;
120 static ULONG_PTR completionValue;
122 static ULONG get_pending_msgs(HANDLE h)
124 NTSTATUS res;
125 ULONG a, req;
127 res = pNtQueryIoCompletion( h, IoCompletionBasicInformation, &a, sizeof(a), &req );
128 ok( res == STATUS_SUCCESS, "NtQueryIoCompletion failed: %x\n", res );
129 if (res != STATUS_SUCCESS) return -1;
130 ok( req == sizeof(a), "Unexpected response size: %x\n", req );
131 return a;
134 static BOOL get_msg(HANDLE h)
136 LARGE_INTEGER timeout = {{-10000000*3}};
137 DWORD res = pNtRemoveIoCompletion( h, &completionKey, &completionValue, &ioSb, &timeout);
138 ok( res == STATUS_SUCCESS, "NtRemoveIoCompletion failed: %x\n", res );
139 if (res != STATUS_SUCCESS)
141 completionKey = completionValue = 0;
142 memset(&ioSb, 0, sizeof(ioSb));
143 return FALSE;
145 return TRUE;
149 static void WINAPI apc( void *arg, IO_STATUS_BLOCK *iosb, ULONG reserved )
151 int *count = arg;
153 trace( "apc called block %p iosb.status %x iosb.info %lu\n",
154 iosb, U(*iosb).Status, iosb->Information );
155 (*count)++;
156 ok( !reserved, "reserved is not 0: %x\n", reserved );
159 static void create_file_test(void)
161 static const WCHAR systemrootW[] = {'\\','S','y','s','t','e','m','R','o','o','t',
162 '\\','f','a','i','l','i','n','g',0};
163 NTSTATUS status;
164 HANDLE dir;
165 WCHAR path[MAX_PATH];
166 OBJECT_ATTRIBUTES attr;
167 IO_STATUS_BLOCK io;
168 UNICODE_STRING nameW;
170 GetCurrentDirectoryW( MAX_PATH, path );
171 pRtlDosPathNameToNtPathName_U( path, &nameW, NULL, NULL );
172 attr.Length = sizeof(attr);
173 attr.RootDirectory = 0;
174 attr.ObjectName = &nameW;
175 attr.Attributes = OBJ_CASE_INSENSITIVE;
176 attr.SecurityDescriptor = NULL;
177 attr.SecurityQualityOfService = NULL;
179 /* try various open modes and options on directories */
180 status = pNtCreateFile( &dir, GENERIC_READ, &attr, &io, NULL, 0, FILE_SHARE_READ|FILE_SHARE_WRITE,
181 FILE_OPEN, FILE_DIRECTORY_FILE, NULL, 0 );
182 ok( !status, "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
183 CloseHandle( dir );
185 status = pNtCreateFile( &dir, GENERIC_READ, &attr, &io, NULL, 0, FILE_SHARE_READ|FILE_SHARE_WRITE,
186 FILE_CREATE, FILE_DIRECTORY_FILE, NULL, 0 );
187 ok( status == STATUS_OBJECT_NAME_COLLISION || status == STATUS_ACCESS_DENIED,
188 "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
190 status = pNtCreateFile( &dir, GENERIC_READ, &attr, &io, NULL, 0, FILE_SHARE_READ|FILE_SHARE_WRITE,
191 FILE_OPEN_IF, FILE_DIRECTORY_FILE, NULL, 0 );
192 ok( !status, "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
193 CloseHandle( dir );
195 status = pNtCreateFile( &dir, GENERIC_READ, &attr, &io, NULL, 0, FILE_SHARE_READ|FILE_SHARE_WRITE,
196 FILE_SUPERSEDE, FILE_DIRECTORY_FILE, NULL, 0 );
197 ok( status == STATUS_INVALID_PARAMETER, "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
199 status = pNtCreateFile( &dir, GENERIC_READ, &attr, &io, NULL, 0, FILE_SHARE_READ|FILE_SHARE_WRITE,
200 FILE_OVERWRITE, FILE_DIRECTORY_FILE, NULL, 0 );
201 ok( status == STATUS_INVALID_PARAMETER, "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
203 status = pNtCreateFile( &dir, GENERIC_READ, &attr, &io, NULL, 0, FILE_SHARE_READ|FILE_SHARE_WRITE,
204 FILE_OVERWRITE_IF, FILE_DIRECTORY_FILE, NULL, 0 );
205 ok( status == STATUS_INVALID_PARAMETER, "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
207 status = pNtCreateFile( &dir, GENERIC_READ, &attr, &io, NULL, 0, FILE_SHARE_READ|FILE_SHARE_WRITE,
208 FILE_OPEN, 0, NULL, 0 );
209 ok( !status, "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
210 CloseHandle( dir );
212 status = pNtCreateFile( &dir, GENERIC_READ, &attr, &io, NULL, 0, FILE_SHARE_READ|FILE_SHARE_WRITE,
213 FILE_CREATE, 0, NULL, 0 );
214 ok( status == STATUS_OBJECT_NAME_COLLISION || status == STATUS_ACCESS_DENIED,
215 "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
217 status = pNtCreateFile( &dir, GENERIC_READ, &attr, &io, NULL, 0, FILE_SHARE_READ|FILE_SHARE_WRITE,
218 FILE_OPEN_IF, 0, NULL, 0 );
219 ok( !status, "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
220 CloseHandle( dir );
222 status = pNtCreateFile( &dir, GENERIC_READ, &attr, &io, NULL, 0, FILE_SHARE_READ|FILE_SHARE_WRITE,
223 FILE_SUPERSEDE, 0, NULL, 0 );
224 ok( status == STATUS_OBJECT_NAME_COLLISION || status == STATUS_ACCESS_DENIED,
225 "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
227 status = pNtCreateFile( &dir, GENERIC_READ, &attr, &io, NULL, 0, FILE_SHARE_READ|FILE_SHARE_WRITE,
228 FILE_OVERWRITE, 0, NULL, 0 );
229 ok( status == STATUS_OBJECT_NAME_COLLISION || status == STATUS_ACCESS_DENIED,
230 "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
232 status = pNtCreateFile( &dir, GENERIC_READ, &attr, &io, NULL, 0, FILE_SHARE_READ|FILE_SHARE_WRITE,
233 FILE_OVERWRITE_IF, 0, NULL, 0 );
234 ok( status == STATUS_OBJECT_NAME_COLLISION || status == STATUS_ACCESS_DENIED,
235 "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
237 pRtlFreeUnicodeString( &nameW );
239 pRtlInitUnicodeString( &nameW, systemrootW );
240 attr.Length = sizeof(attr);
241 attr.RootDirectory = NULL;
242 attr.ObjectName = &nameW;
243 attr.Attributes = OBJ_CASE_INSENSITIVE;
244 attr.SecurityDescriptor = NULL;
245 attr.SecurityQualityOfService = NULL;
246 dir = NULL;
247 status = pNtCreateFile( &dir, FILE_APPEND_DATA, &attr, &io, NULL, FILE_ATTRIBUTE_NORMAL, 0,
248 FILE_OPEN_IF, FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0 );
249 todo_wine
250 ok( status == STATUS_INVALID_PARAMETER,
251 "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
254 static void open_file_test(void)
256 NTSTATUS status;
257 HANDLE dir, root, handle;
258 WCHAR path[MAX_PATH];
259 BYTE data[1024];
260 OBJECT_ATTRIBUTES attr;
261 IO_STATUS_BLOCK io;
262 UNICODE_STRING nameW;
263 UINT i, len;
264 BOOL restart = TRUE;
266 len = GetWindowsDirectoryW( path, MAX_PATH );
267 pRtlDosPathNameToNtPathName_U( path, &nameW, NULL, NULL );
268 attr.Length = sizeof(attr);
269 attr.RootDirectory = 0;
270 attr.ObjectName = &nameW;
271 attr.Attributes = OBJ_CASE_INSENSITIVE;
272 attr.SecurityDescriptor = NULL;
273 attr.SecurityQualityOfService = NULL;
274 status = pNtOpenFile( &dir, SYNCHRONIZE|FILE_LIST_DIRECTORY, &attr, &io,
275 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_DIRECTORY_FILE|FILE_SYNCHRONOUS_IO_NONALERT );
276 ok( !status, "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
277 pRtlFreeUnicodeString( &nameW );
279 path[3] = 0; /* root of the drive */
280 pRtlDosPathNameToNtPathName_U( path, &nameW, NULL, NULL );
281 status = pNtOpenFile( &root, GENERIC_READ, &attr, &io,
282 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_DIRECTORY_FILE );
283 ok( !status, "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
284 pRtlFreeUnicodeString( &nameW );
286 /* test opening system dir with RootDirectory set to windows dir */
287 GetSystemDirectoryW( path, MAX_PATH );
288 while (path[len] == '\\') len++;
289 nameW.Buffer = path + len;
290 nameW.Length = lstrlenW(path + len) * sizeof(WCHAR);
291 attr.RootDirectory = dir;
292 status = pNtOpenFile( &handle, GENERIC_READ, &attr, &io,
293 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_DIRECTORY_FILE );
294 ok( !status, "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
295 CloseHandle( handle );
297 /* try uppercase name */
298 for (i = len; path[i]; i++) if (path[i] >= 'a' && path[i] <= 'z') path[i] -= 'a' - 'A';
299 status = pNtOpenFile( &handle, GENERIC_READ, &attr, &io,
300 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_DIRECTORY_FILE );
301 ok( !status, "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
302 CloseHandle( handle );
304 /* try with leading backslash */
305 nameW.Buffer--;
306 nameW.Length += sizeof(WCHAR);
307 status = pNtOpenFile( &handle, GENERIC_READ, &attr, &io,
308 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_DIRECTORY_FILE );
309 ok( status == STATUS_INVALID_PARAMETER ||
310 status == STATUS_OBJECT_NAME_INVALID ||
311 status == STATUS_OBJECT_PATH_SYNTAX_BAD,
312 "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
313 if (!status) CloseHandle( handle );
315 /* try with empty name */
316 nameW.Length = 0;
317 status = pNtOpenFile( &handle, GENERIC_READ, &attr, &io,
318 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_DIRECTORY_FILE );
319 ok( !status, "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
320 CloseHandle( handle );
322 /* try open by file id */
324 while (!pNtQueryDirectoryFile( dir, NULL, NULL, NULL, &io, data, sizeof(data),
325 FileIdBothDirectoryInformation, TRUE, NULL, restart ))
327 FILE_ID_BOTH_DIRECTORY_INFORMATION *info = (FILE_ID_BOTH_DIRECTORY_INFORMATION *)data;
329 restart = FALSE;
331 if (!info->FileId.QuadPart) continue;
333 nameW.Buffer = (WCHAR *)&info->FileId;
334 nameW.Length = sizeof(info->FileId);
335 info->FileName[info->FileNameLength/sizeof(WCHAR)] = 0;
336 attr.RootDirectory = dir;
337 /* We skip 'open' files by not specifying FILE_SHARE_WRITE */
338 status = pNtOpenFile( &handle, GENERIC_READ, &attr, &io,
339 FILE_SHARE_READ,
340 FILE_OPEN_BY_FILE_ID |
341 ((info->FileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? FILE_DIRECTORY_FILE : 0) );
342 ok( status == STATUS_SUCCESS || status == STATUS_ACCESS_DENIED || status == STATUS_NOT_IMPLEMENTED || status == STATUS_SHARING_VIOLATION,
343 "open %s failed %x\n", wine_dbgstr_w(info->FileName), status );
344 if (status == STATUS_NOT_IMPLEMENTED)
346 win_skip( "FILE_OPEN_BY_FILE_ID not supported\n" );
347 break;
349 if (status == STATUS_SHARING_VIOLATION)
350 trace( "%s is currently open\n", wine_dbgstr_w(info->FileName) );
351 if (!status)
353 BYTE buf[sizeof(FILE_ALL_INFORMATION) + MAX_PATH * sizeof(WCHAR)];
355 if (!pNtQueryInformationFile( handle, &io, buf, sizeof(buf), FileAllInformation ))
357 FILE_ALL_INFORMATION *fai = (FILE_ALL_INFORMATION *)buf;
359 /* check that it's the same file/directory */
361 /* don't check the size for directories */
362 if (!(info->FileAttributes & FILE_ATTRIBUTE_DIRECTORY))
363 ok( info->EndOfFile.QuadPart == fai->StandardInformation.EndOfFile.QuadPart,
364 "mismatched file size for %s\n", wine_dbgstr_w(info->FileName));
366 ok( info->CreationTime.QuadPart == fai->BasicInformation.CreationTime.QuadPart,
367 "mismatched creation time for %s\n", wine_dbgstr_w(info->FileName));
369 CloseHandle( handle );
371 /* try same thing from drive root */
372 attr.RootDirectory = root;
373 status = pNtOpenFile( &handle, GENERIC_READ, &attr, &io,
374 FILE_SHARE_READ|FILE_SHARE_WRITE,
375 FILE_OPEN_BY_FILE_ID |
376 ((info->FileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? FILE_DIRECTORY_FILE : 0) );
377 ok( status == STATUS_SUCCESS || status == STATUS_NOT_IMPLEMENTED,
378 "open %s failed %x\n", wine_dbgstr_w(info->FileName), status );
379 if (!status) CloseHandle( handle );
383 CloseHandle( dir );
384 CloseHandle( root );
387 static void delete_file_test(void)
389 NTSTATUS ret;
390 OBJECT_ATTRIBUTES attr;
391 UNICODE_STRING nameW;
392 WCHAR pathW[MAX_PATH];
393 WCHAR pathsubW[MAX_PATH];
394 static const WCHAR testdirW[] = {'n','t','d','e','l','e','t','e','f','i','l','e',0};
395 static const WCHAR subdirW[] = {'\\','s','u','b',0};
397 ret = GetTempPathW(MAX_PATH, pathW);
398 if (!ret)
400 ok(0, "couldn't get temp dir\n");
401 return;
403 if (ret + sizeof(testdirW)/sizeof(WCHAR)-1 + sizeof(subdirW)/sizeof(WCHAR)-1 >= MAX_PATH)
405 ok(0, "MAX_PATH exceeded in constructing paths\n");
406 return;
409 lstrcatW(pathW, testdirW);
410 lstrcpyW(pathsubW, pathW);
411 lstrcatW(pathsubW, subdirW);
413 ret = CreateDirectoryW(pathW, NULL);
414 ok(ret == TRUE, "couldn't create directory ntdeletefile\n");
415 if (!pRtlDosPathNameToNtPathName_U(pathW, &nameW, NULL, NULL))
417 ok(0,"RtlDosPathNametoNtPathName_U failed\n");
418 return;
421 attr.Length = sizeof(attr);
422 attr.RootDirectory = 0;
423 attr.Attributes = OBJ_CASE_INSENSITIVE;
424 attr.ObjectName = &nameW;
425 attr.SecurityDescriptor = NULL;
426 attr.SecurityQualityOfService = NULL;
428 /* test NtDeleteFile on an empty directory */
429 ret = pNtDeleteFile(&attr);
430 ok(ret == STATUS_SUCCESS, "NtDeleteFile should succeed in removing an empty directory\n");
431 ret = RemoveDirectoryW(pathW);
432 ok(ret == FALSE, "expected to fail removing directory, NtDeleteFile should have removed it\n");
434 /* test NtDeleteFile on a non-empty directory */
435 ret = CreateDirectoryW(pathW, NULL);
436 ok(ret == TRUE, "couldn't create directory ntdeletefile ?!\n");
437 ret = CreateDirectoryW(pathsubW, NULL);
438 ok(ret == TRUE, "couldn't create directory subdir\n");
439 ret = pNtDeleteFile(&attr);
440 ok(ret == STATUS_SUCCESS, "expected NtDeleteFile to ret STATUS_SUCCESS\n");
441 ret = RemoveDirectoryW(pathsubW);
442 ok(ret == TRUE, "expected to remove directory ntdeletefile\\sub\n");
443 ret = RemoveDirectoryW(pathW);
444 ok(ret == TRUE, "expected to remove directory ntdeletefile, NtDeleteFile failed.\n");
446 pRtlFreeUnicodeString( &nameW );
449 static void read_file_test(void)
451 const char text[] = "foobar";
452 HANDLE handle, read, write;
453 NTSTATUS status;
454 IO_STATUS_BLOCK iosb, iosb2;
455 DWORD written;
456 int apc_count = 0;
457 char buffer[128];
458 LARGE_INTEGER offset;
459 HANDLE event = CreateEventA( NULL, TRUE, FALSE, NULL );
460 BOOL ret;
462 buffer[0] = 1;
464 if (!create_pipe( &read, &write, FILE_FLAG_OVERLAPPED, 4096 )) return;
466 /* try read with no data */
467 U(iosb).Status = 0xdeadbabe;
468 iosb.Information = 0xdeadbeef;
469 ok( is_signaled( read ), "read handle is not signaled\n" );
470 status = pNtReadFile( read, event, apc, &apc_count, &iosb, buffer, 1, NULL, NULL );
471 ok( status == STATUS_PENDING, "wrong status %x\n", status );
472 ok( !is_signaled( read ), "read handle is signaled\n" );
473 ok( !is_signaled( event ), "event is signaled\n" );
474 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
475 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
476 ok( !apc_count, "apc was called\n" );
477 WriteFile( write, buffer, 1, &written, NULL );
478 /* iosb updated here by async i/o */
479 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
480 ok( U(iosb).Status == 0, "wrong status %x\n", U(iosb).Status );
481 ok( iosb.Information == 1, "wrong info %lu\n", iosb.Information );
482 ok( !is_signaled( read ), "read handle is signaled\n" );
483 ok( is_signaled( event ), "event is not signaled\n" );
484 ok( !apc_count, "apc was called\n" );
485 apc_count = 0;
486 SleepEx( 1, FALSE ); /* non-alertable sleep */
487 ok( !apc_count, "apc was called\n" );
488 SleepEx( 1, TRUE ); /* alertable sleep */
489 ok( apc_count == 1, "apc not called\n" );
491 /* with no event, the pipe handle itself gets signaled */
492 apc_count = 0;
493 U(iosb).Status = 0xdeadbabe;
494 iosb.Information = 0xdeadbeef;
495 ok( !is_signaled( read ), "read handle is not signaled\n" );
496 status = pNtReadFile( read, 0, apc, &apc_count, &iosb, buffer, 1, NULL, NULL );
497 ok( status == STATUS_PENDING, "wrong status %x\n", status );
498 ok( !is_signaled( read ), "read handle is signaled\n" );
499 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
500 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
501 ok( !apc_count, "apc was called\n" );
502 WriteFile( write, buffer, 1, &written, NULL );
503 /* iosb updated here by async i/o */
504 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
505 ok( U(iosb).Status == 0, "wrong status %x\n", U(iosb).Status );
506 ok( iosb.Information == 1, "wrong info %lu\n", iosb.Information );
507 ok( is_signaled( read ), "read handle is signaled\n" );
508 ok( !apc_count, "apc was called\n" );
509 apc_count = 0;
510 SleepEx( 1, FALSE ); /* non-alertable sleep */
511 ok( !apc_count, "apc was called\n" );
512 SleepEx( 1, TRUE ); /* alertable sleep */
513 ok( apc_count == 1, "apc not called\n" );
515 /* now read with data ready */
516 apc_count = 0;
517 U(iosb).Status = 0xdeadbabe;
518 iosb.Information = 0xdeadbeef;
519 ResetEvent( event );
520 WriteFile( write, buffer, 1, &written, NULL );
521 status = pNtReadFile( read, event, apc, &apc_count, &iosb, buffer, 1, NULL, NULL );
522 ok( status == STATUS_SUCCESS, "wrong status %x\n", status );
523 ok( U(iosb).Status == 0, "wrong status %x\n", U(iosb).Status );
524 ok( iosb.Information == 1, "wrong info %lu\n", iosb.Information );
525 ok( is_signaled( event ), "event is not signaled\n" );
526 ok( !apc_count, "apc was called\n" );
527 SleepEx( 1, FALSE ); /* non-alertable sleep */
528 ok( !apc_count, "apc was called\n" );
529 SleepEx( 1, TRUE ); /* alertable sleep */
530 ok( apc_count == 1, "apc not called\n" );
532 /* try read with no data */
533 apc_count = 0;
534 U(iosb).Status = 0xdeadbabe;
535 iosb.Information = 0xdeadbeef;
536 ok( is_signaled( event ), "event is not signaled\n" ); /* check that read resets the event */
537 status = pNtReadFile( read, event, apc, &apc_count, &iosb, buffer, 2, NULL, NULL );
538 ok( status == STATUS_PENDING, "wrong status %x\n", status );
539 ok( !is_signaled( event ), "event is signaled\n" );
540 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
541 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
542 ok( !apc_count, "apc was called\n" );
543 WriteFile( write, buffer, 1, &written, NULL );
544 /* partial read is good enough */
545 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
546 ok( is_signaled( event ), "event is signaled\n" );
547 ok( U(iosb).Status == 0, "wrong status %x\n", U(iosb).Status );
548 ok( iosb.Information == 1, "wrong info %lu\n", iosb.Information );
549 ok( !apc_count, "apc was called\n" );
550 SleepEx( 1, TRUE ); /* alertable sleep */
551 ok( apc_count == 1, "apc was not called\n" );
553 /* read from disconnected pipe */
554 apc_count = 0;
555 U(iosb).Status = 0xdeadbabe;
556 iosb.Information = 0xdeadbeef;
557 CloseHandle( write );
558 status = pNtReadFile( read, event, apc, &apc_count, &iosb, buffer, 1, NULL, NULL );
559 ok( status == STATUS_PIPE_BROKEN, "wrong status %x\n", status );
560 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
561 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
562 ok( !is_signaled( event ), "event is signaled\n" );
563 ok( !apc_count, "apc was called\n" );
564 SleepEx( 1, TRUE ); /* alertable sleep */
565 ok( !apc_count, "apc was called\n" );
566 CloseHandle( read );
568 /* read from closed handle */
569 apc_count = 0;
570 U(iosb).Status = 0xdeadbabe;
571 iosb.Information = 0xdeadbeef;
572 SetEvent( event );
573 status = pNtReadFile( read, event, apc, &apc_count, &iosb, buffer, 1, NULL, NULL );
574 ok( status == STATUS_INVALID_HANDLE, "wrong status %x\n", status );
575 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
576 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
577 ok( is_signaled( event ), "event is signaled\n" ); /* not reset on invalid handle */
578 ok( !apc_count, "apc was called\n" );
579 SleepEx( 1, TRUE ); /* alertable sleep */
580 ok( !apc_count, "apc was called\n" );
582 /* disconnect while async read is in progress */
583 if (!create_pipe( &read, &write, FILE_FLAG_OVERLAPPED, 4096 )) return;
584 apc_count = 0;
585 U(iosb).Status = 0xdeadbabe;
586 iosb.Information = 0xdeadbeef;
587 status = pNtReadFile( read, event, apc, &apc_count, &iosb, buffer, 2, NULL, NULL );
588 ok( status == STATUS_PENDING, "wrong status %x\n", status );
589 ok( !is_signaled( event ), "event is signaled\n" );
590 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
591 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
592 ok( !apc_count, "apc was called\n" );
593 CloseHandle( write );
594 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
595 ok( U(iosb).Status == STATUS_PIPE_BROKEN, "wrong status %x\n", U(iosb).Status );
596 ok( iosb.Information == 0, "wrong info %lu\n", iosb.Information );
597 ok( is_signaled( event ), "event is signaled\n" );
598 ok( !apc_count, "apc was called\n" );
599 SleepEx( 1, TRUE ); /* alertable sleep */
600 ok( apc_count == 1, "apc was not called\n" );
601 CloseHandle( read );
603 if (!create_pipe( &read, &write, FILE_FLAG_OVERLAPPED, 4096 )) return;
604 ret = DuplicateHandle(GetCurrentProcess(), read, GetCurrentProcess(), &handle, 0, TRUE, DUPLICATE_SAME_ACCESS);
605 ok(ret, "Failed to duplicate handle: %d\n", GetLastError());
607 apc_count = 0;
608 U(iosb).Status = 0xdeadbabe;
609 iosb.Information = 0xdeadbeef;
610 status = pNtReadFile( handle, event, apc, &apc_count, &iosb, buffer, 2, NULL, NULL );
611 ok( status == STATUS_PENDING, "wrong status %x\n", status );
612 ok( !is_signaled( event ), "event is signaled\n" );
613 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
614 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
615 ok( !apc_count, "apc was called\n" );
616 /* Cancel by other handle */
617 status = pNtCancelIoFile( read, &iosb2 );
618 ok(status == STATUS_SUCCESS, "failed to cancel by different handle: %x\n", status);
619 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
620 ok( U(iosb).Status == STATUS_CANCELLED, "wrong status %x\n", U(iosb).Status );
621 ok( iosb.Information == 0, "wrong info %lu\n", iosb.Information );
622 ok( is_signaled( event ), "event is signaled\n" );
623 todo_wine ok( !apc_count, "apc was called\n" );
624 SleepEx( 1, TRUE ); /* alertable sleep */
625 ok( apc_count == 1, "apc was not called\n" );
627 apc_count = 0;
628 U(iosb).Status = 0xdeadbabe;
629 iosb.Information = 0xdeadbeef;
630 status = pNtReadFile( read, event, apc, &apc_count, &iosb, buffer, 2, NULL, NULL );
631 ok( status == STATUS_PENDING, "wrong status %x\n", status );
632 ok( !is_signaled( event ), "event is signaled\n" );
633 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
634 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
635 ok( !apc_count, "apc was called\n" );
636 /* Close queued handle */
637 CloseHandle( read );
638 SleepEx( 1, TRUE ); /* alertable sleep */
639 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
640 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
641 status = pNtCancelIoFile( read, &iosb2 );
642 ok(status == STATUS_INVALID_HANDLE, "cancelled by closed handle?\n");
643 status = pNtCancelIoFile( handle, &iosb2 );
644 ok(status == STATUS_SUCCESS, "failed to cancel: %x\n", status);
645 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
646 ok( U(iosb).Status == STATUS_CANCELLED, "wrong status %x\n", U(iosb).Status );
647 ok( iosb.Information == 0, "wrong info %lu\n", iosb.Information );
648 ok( is_signaled( event ), "event is signaled\n" );
649 todo_wine ok( !apc_count, "apc was called\n" );
650 SleepEx( 1, TRUE ); /* alertable sleep */
651 ok( apc_count == 1, "apc was not called\n" );
652 CloseHandle( handle );
653 CloseHandle( write );
655 if (pNtCancelIoFileEx)
657 /* Basic Cancel Ex */
658 if (!create_pipe( &read, &write, FILE_FLAG_OVERLAPPED, 4096 )) return;
660 apc_count = 0;
661 U(iosb).Status = 0xdeadbabe;
662 iosb.Information = 0xdeadbeef;
663 status = pNtReadFile( read, event, apc, &apc_count, &iosb, buffer, 2, NULL, NULL );
664 ok( status == STATUS_PENDING, "wrong status %x\n", status );
665 ok( !is_signaled( event ), "event is signaled\n" );
666 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
667 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
668 ok( !apc_count, "apc was called\n" );
669 status = pNtCancelIoFileEx( read, &iosb, &iosb2 );
670 ok(status == STATUS_SUCCESS, "Failed to cancel I/O\n");
671 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
672 ok( U(iosb).Status == STATUS_CANCELLED, "wrong status %x\n", U(iosb).Status );
673 ok( iosb.Information == 0, "wrong info %lu\n", iosb.Information );
674 ok( is_signaled( event ), "event is signaled\n" );
675 todo_wine ok( !apc_count, "apc was called\n" );
676 SleepEx( 1, TRUE ); /* alertable sleep */
677 ok( apc_count == 1, "apc was not called\n" );
679 /* Duplicate iosb */
680 apc_count = 0;
681 U(iosb).Status = 0xdeadbabe;
682 iosb.Information = 0xdeadbeef;
683 status = pNtReadFile( read, event, apc, &apc_count, &iosb, buffer, 2, NULL, NULL );
684 ok( status == STATUS_PENDING, "wrong status %x\n", status );
685 ok( !is_signaled( event ), "event is signaled\n" );
686 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
687 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
688 ok( !apc_count, "apc was called\n" );
689 status = pNtReadFile( read, event, apc, &apc_count, &iosb, buffer, 2, NULL, NULL );
690 ok( status == STATUS_PENDING, "wrong status %x\n", status );
691 ok( !is_signaled( event ), "event is signaled\n" );
692 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
693 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
694 ok( !apc_count, "apc was called\n" );
695 status = pNtCancelIoFileEx( read, &iosb, &iosb2 );
696 ok(status == STATUS_SUCCESS, "Failed to cancel I/O\n");
697 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
698 ok( U(iosb).Status == STATUS_CANCELLED, "wrong status %x\n", U(iosb).Status );
699 ok( iosb.Information == 0, "wrong info %lu\n", iosb.Information );
700 ok( is_signaled( event ), "event is signaled\n" );
701 todo_wine ok( !apc_count, "apc was called\n" );
702 SleepEx( 1, TRUE ); /* alertable sleep */
703 ok( apc_count == 2, "apc was not called\n" );
705 CloseHandle( read );
706 CloseHandle( write );
709 /* now try a real file */
710 if (!(handle = create_temp_file( FILE_FLAG_OVERLAPPED ))) return;
711 apc_count = 0;
712 U(iosb).Status = 0xdeadbabe;
713 iosb.Information = 0xdeadbeef;
714 offset.QuadPart = 0;
715 ResetEvent( event );
716 status = pNtWriteFile( handle, event, apc, &apc_count, &iosb, text, strlen(text), &offset, NULL );
717 ok( status == STATUS_SUCCESS || status == STATUS_PENDING, "wrong status %x\n", status );
718 if (status == STATUS_PENDING) WaitForSingleObject( event, 1000 );
719 ok( U(iosb).Status == STATUS_SUCCESS, "wrong status %x\n", U(iosb).Status );
720 ok( iosb.Information == strlen(text), "wrong info %lu\n", iosb.Information );
721 ok( is_signaled( event ), "event is signaled\n" );
722 ok( !apc_count, "apc was called\n" );
723 SleepEx( 1, TRUE ); /* alertable sleep */
724 ok( apc_count == 1, "apc was not called\n" );
726 apc_count = 0;
727 U(iosb).Status = 0xdeadbabe;
728 iosb.Information = 0xdeadbeef;
729 offset.QuadPart = 0;
730 ResetEvent( event );
731 status = pNtReadFile( handle, event, apc, &apc_count, &iosb, buffer, strlen(text) + 10, &offset, NULL );
732 ok( status == STATUS_SUCCESS ||
733 status == STATUS_PENDING, /* vista */
734 "wrong status %x\n", status );
735 if (status == STATUS_PENDING) WaitForSingleObject( event, 1000 );
736 ok( U(iosb).Status == STATUS_SUCCESS, "wrong status %x\n", U(iosb).Status );
737 ok( iosb.Information == strlen(text), "wrong info %lu\n", iosb.Information );
738 ok( is_signaled( event ), "event is signaled\n" );
739 ok( !apc_count, "apc was called\n" );
740 SleepEx( 1, TRUE ); /* alertable sleep */
741 ok( apc_count == 1, "apc was not called\n" );
743 /* read beyond eof */
744 apc_count = 0;
745 U(iosb).Status = 0xdeadbabe;
746 iosb.Information = 0xdeadbeef;
747 offset.QuadPart = strlen(text) + 2;
748 status = pNtReadFile( handle, event, apc, &apc_count, &iosb, buffer, 2, &offset, NULL );
749 if (status == STATUS_PENDING) /* vista */
751 WaitForSingleObject( event, 1000 );
752 ok( U(iosb).Status == STATUS_END_OF_FILE, "wrong status %x\n", U(iosb).Status );
753 ok( iosb.Information == 0, "wrong info %lu\n", iosb.Information );
754 ok( is_signaled( event ), "event is signaled\n" );
755 ok( !apc_count, "apc was called\n" );
756 SleepEx( 1, TRUE ); /* alertable sleep */
757 ok( apc_count == 1, "apc was not called\n" );
759 else
761 ok( status == STATUS_END_OF_FILE, "wrong status %x\n", status );
762 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
763 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
764 ok( !is_signaled( event ), "event is signaled\n" );
765 ok( !apc_count, "apc was called\n" );
766 SleepEx( 1, TRUE ); /* alertable sleep */
767 ok( !apc_count, "apc was called\n" );
769 CloseHandle( handle );
771 /* now a non-overlapped file */
772 if (!(handle = create_temp_file(0))) return;
773 apc_count = 0;
774 U(iosb).Status = 0xdeadbabe;
775 iosb.Information = 0xdeadbeef;
776 offset.QuadPart = 0;
777 status = pNtWriteFile( handle, event, apc, &apc_count, &iosb, text, strlen(text), &offset, NULL );
778 ok( status == STATUS_END_OF_FILE ||
779 status == STATUS_SUCCESS ||
780 status == STATUS_PENDING, /* vista */
781 "wrong status %x\n", status );
782 if (status == STATUS_PENDING) WaitForSingleObject( event, 1000 );
783 ok( U(iosb).Status == STATUS_SUCCESS, "wrong status %x\n", U(iosb).Status );
784 ok( iosb.Information == strlen(text), "wrong info %lu\n", iosb.Information );
785 ok( is_signaled( event ), "event is signaled\n" );
786 ok( !apc_count, "apc was called\n" );
787 SleepEx( 1, TRUE ); /* alertable sleep */
788 ok( apc_count == 1, "apc was not called\n" );
790 apc_count = 0;
791 U(iosb).Status = 0xdeadbabe;
792 iosb.Information = 0xdeadbeef;
793 offset.QuadPart = 0;
794 ResetEvent( event );
795 status = pNtReadFile( handle, event, apc, &apc_count, &iosb, buffer, strlen(text) + 10, &offset, NULL );
796 ok( status == STATUS_SUCCESS, "wrong status %x\n", status );
797 ok( U(iosb).Status == STATUS_SUCCESS, "wrong status %x\n", U(iosb).Status );
798 ok( iosb.Information == strlen(text), "wrong info %lu\n", iosb.Information );
799 ok( is_signaled( event ), "event is signaled\n" );
800 ok( !apc_count, "apc was called\n" );
801 SleepEx( 1, TRUE ); /* alertable sleep */
802 todo_wine ok( !apc_count, "apc was called\n" );
804 /* read beyond eof */
805 apc_count = 0;
806 U(iosb).Status = 0xdeadbabe;
807 iosb.Information = 0xdeadbeef;
808 offset.QuadPart = strlen(text) + 2;
809 ResetEvent( event );
810 status = pNtReadFile( handle, event, apc, &apc_count, &iosb, buffer, 2, &offset, NULL );
811 ok( status == STATUS_END_OF_FILE, "wrong status %x\n", status );
812 todo_wine ok( U(iosb).Status == STATUS_END_OF_FILE, "wrong status %x\n", U(iosb).Status );
813 todo_wine ok( iosb.Information == 0, "wrong info %lu\n", iosb.Information );
814 todo_wine ok( is_signaled( event ), "event is not signaled\n" );
815 ok( !apc_count, "apc was called\n" );
816 SleepEx( 1, TRUE ); /* alertable sleep */
817 ok( !apc_count, "apc was called\n" );
819 CloseHandle( handle );
821 CloseHandle( event );
824 static void append_file_test(void)
826 const char text[] = "foobar";
827 HANDLE handle;
828 NTSTATUS status;
829 IO_STATUS_BLOCK iosb;
830 DWORD written;
831 char buffer[128];
833 GetTempFileNameA( ".", "foo", 0, buffer );
834 /* It is possible to open a file with only FILE_APPEND_DATA access flags.
835 It matches the O_WRONLY|O_APPEND open() posix behavior */
836 handle = CreateFileA(buffer, FILE_APPEND_DATA, 0, NULL, CREATE_ALWAYS,
837 FILE_FLAG_DELETE_ON_CLOSE, 0);
838 ok( handle != INVALID_HANDLE_VALUE, "Failed to create a temp file in FILE_APPEND_DATA mode.\n" );
839 if(handle == INVALID_HANDLE_VALUE)
841 skip("Couldn't create a temporary file, skipping FILE_APPEND_DATA test\n");
842 return;
845 U(iosb).Status = STATUS_PENDING;
846 iosb.Information = 0;
848 status = pNtWriteFile(handle, NULL, NULL, NULL, &iosb,
849 text, sizeof(text), NULL, NULL);
851 if (status == STATUS_PENDING)
853 WaitForSingleObject( handle, 1000 );
854 status = U(iosb).Status;
856 written = iosb.Information;
858 todo_wine
859 ok(status == STATUS_SUCCESS && written == sizeof(text), "FILE_APPEND_DATA NtWriteFile failed\n");
861 CloseHandle(handle);
864 static void nt_mailslot_test(void)
866 HANDLE hslot;
867 ACCESS_MASK DesiredAccess;
868 OBJECT_ATTRIBUTES attr;
870 ULONG CreateOptions;
871 ULONG MailslotQuota;
872 ULONG MaxMessageSize;
873 LARGE_INTEGER TimeOut;
874 IO_STATUS_BLOCK IoStatusBlock;
875 NTSTATUS rc;
876 UNICODE_STRING str;
877 WCHAR buffer1[] = { '\\','?','?','\\','M','A','I','L','S','L','O','T','\\',
878 'R',':','\\','F','R','E','D','\0' };
880 TimeOut.QuadPart = -1;
882 pRtlInitUnicodeString(&str, buffer1);
883 InitializeObjectAttributes(&attr, &str, OBJ_CASE_INSENSITIVE, 0, NULL);
884 CreateOptions = MailslotQuota = MaxMessageSize = 0;
885 DesiredAccess = GENERIC_READ;
888 * Check for NULL pointer handling
890 rc = pNtCreateMailslotFile(NULL, DesiredAccess,
891 &attr, &IoStatusBlock, CreateOptions, MailslotQuota, MaxMessageSize,
892 &TimeOut);
893 ok( rc == STATUS_ACCESS_VIOLATION ||
894 rc == STATUS_INVALID_PARAMETER, /* win2k3 */
895 "rc = %x not STATUS_ACCESS_VIOLATION or STATUS_INVALID_PARAMETER\n", rc);
898 * Test to see if the Timeout can be NULL
900 hslot = (HANDLE)0xdeadbeef;
901 rc = pNtCreateMailslotFile(&hslot, DesiredAccess,
902 &attr, &IoStatusBlock, CreateOptions, MailslotQuota, MaxMessageSize,
903 NULL);
904 ok( rc == STATUS_SUCCESS ||
905 rc == STATUS_INVALID_PARAMETER, /* win2k3 */
906 "rc = %x not STATUS_SUCCESS or STATUS_INVALID_PARAMETER\n", rc);
907 ok( hslot != 0, "Handle is invalid\n");
909 if ( rc == STATUS_SUCCESS ) pNtClose(hslot);
912 * Test that the length field is checked properly
914 attr.Length = 0;
915 rc = pNtCreateMailslotFile(&hslot, DesiredAccess,
916 &attr, &IoStatusBlock, CreateOptions, MailslotQuota, MaxMessageSize,
917 &TimeOut);
918 todo_wine ok( rc == STATUS_INVALID_PARAMETER, "rc = %x not c000000d STATUS_INVALID_PARAMETER\n", rc);
920 if (rc == STATUS_SUCCESS) pNtClose(hslot);
922 attr.Length = sizeof(OBJECT_ATTRIBUTES)+1;
923 rc = pNtCreateMailslotFile(&hslot, DesiredAccess,
924 &attr, &IoStatusBlock, CreateOptions, MailslotQuota, MaxMessageSize,
925 &TimeOut);
926 todo_wine ok( rc == STATUS_INVALID_PARAMETER, "rc = %x not c000000d STATUS_INVALID_PARAMETER\n", rc);
928 if (rc == STATUS_SUCCESS) pNtClose(hslot);
931 * Test handling of a NULL unicode string in ObjectName
933 InitializeObjectAttributes(&attr, &str, OBJ_CASE_INSENSITIVE, 0, NULL);
934 attr.ObjectName = NULL;
935 rc = pNtCreateMailslotFile(&hslot, DesiredAccess,
936 &attr, &IoStatusBlock, CreateOptions, MailslotQuota, MaxMessageSize,
937 &TimeOut);
938 ok( rc == STATUS_OBJECT_PATH_SYNTAX_BAD ||
939 rc == STATUS_INVALID_PARAMETER,
940 "rc = %x not STATUS_OBJECT_PATH_SYNTAX_BAD or STATUS_INVALID_PARAMETER\n", rc);
942 if (rc == STATUS_SUCCESS) pNtClose(hslot);
945 * Test a valid call
947 InitializeObjectAttributes(&attr, &str, OBJ_CASE_INSENSITIVE, 0, NULL);
948 rc = pNtCreateMailslotFile(&hslot, DesiredAccess,
949 &attr, &IoStatusBlock, CreateOptions, MailslotQuota, MaxMessageSize,
950 &TimeOut);
951 ok( rc == STATUS_SUCCESS, "Create MailslotFile failed rc = %x\n", rc);
952 ok( hslot != 0, "Handle is invalid\n");
954 rc = pNtClose(hslot);
955 ok( rc == STATUS_SUCCESS, "NtClose failed\n");
958 static void test_iocp_setcompletion(HANDLE h)
960 NTSTATUS res;
961 ULONG count;
963 res = pNtSetIoCompletion( h, CKEY_FIRST, CVALUE_FIRST, STATUS_INVALID_DEVICE_REQUEST, 3 );
964 ok( res == STATUS_SUCCESS, "NtSetIoCompletion failed: %x\n", res );
966 count = get_pending_msgs(h);
967 ok( count == 1, "Unexpected msg count: %d\n", count );
969 if (get_msg(h))
971 ok( completionKey == CKEY_FIRST, "Invalid completion key: %lx\n", completionKey );
972 ok( ioSb.Information == 3, "Invalid ioSb.Information: %ld\n", ioSb.Information );
973 ok( U(ioSb).Status == STATUS_INVALID_DEVICE_REQUEST, "Invalid ioSb.Status: %x\n", U(ioSb).Status);
974 ok( completionValue == CVALUE_FIRST, "Invalid completion value: %lx\n", completionValue );
977 count = get_pending_msgs(h);
978 ok( !count, "Unexpected msg count: %d\n", count );
981 static void test_iocp_fileio(HANDLE h)
983 static const char pipe_name[] = "\\\\.\\pipe\\iocompletiontestnamedpipe";
985 IO_STATUS_BLOCK iosb;
986 FILE_COMPLETION_INFORMATION fci = {h, CKEY_SECOND};
987 HANDLE hPipeSrv, hPipeClt;
988 NTSTATUS res;
990 hPipeSrv = CreateNamedPipeA( pipe_name, PIPE_ACCESS_INBOUND, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, 4, 1024, 1024, 1000, NULL );
991 ok( hPipeSrv != INVALID_HANDLE_VALUE, "Cannot create named pipe\n" );
992 if (hPipeSrv != INVALID_HANDLE_VALUE )
994 hPipeClt = CreateFileA( pipe_name, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_NO_BUFFERING | FILE_FLAG_OVERLAPPED, NULL );
995 ok( hPipeClt != INVALID_HANDLE_VALUE, "Cannot connect to pipe\n" );
996 if (hPipeClt != INVALID_HANDLE_VALUE)
998 U(iosb).Status = 0xdeadbeef;
999 res = pNtSetInformationFile( hPipeSrv, &iosb, &fci, sizeof(fci), FileCompletionInformation );
1000 ok( res == STATUS_INVALID_PARAMETER, "Unexpected NtSetInformationFile on non-overlapped handle: %x\n", res );
1001 ok( U(iosb).Status == STATUS_INVALID_PARAMETER /* 98 */ || U(iosb).Status == 0xdeadbeef /* NT4+ */,
1002 "Unexpected iosb.Status on non-overlapped handle: %x\n", U(iosb).Status );
1003 CloseHandle(hPipeClt);
1005 CloseHandle( hPipeSrv );
1008 hPipeSrv = CreateNamedPipeA( pipe_name, PIPE_ACCESS_INBOUND | FILE_FLAG_OVERLAPPED, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, 4, 1024, 1024, 1000, NULL );
1009 ok( hPipeSrv != INVALID_HANDLE_VALUE, "Cannot create named pipe\n" );
1010 if (hPipeSrv == INVALID_HANDLE_VALUE )
1011 return;
1013 hPipeClt = CreateFileA( pipe_name, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_NO_BUFFERING | FILE_FLAG_OVERLAPPED, NULL );
1014 ok( hPipeClt != INVALID_HANDLE_VALUE, "Cannot connect to pipe\n" );
1015 if (hPipeClt != INVALID_HANDLE_VALUE)
1017 OVERLAPPED o = {0,};
1018 BYTE send_buf[TEST_BUF_LEN], recv_buf[TEST_BUF_LEN];
1019 DWORD read;
1020 long count;
1022 U(iosb).Status = 0xdeadbeef;
1023 res = pNtSetInformationFile( hPipeSrv, &iosb, &fci, sizeof(fci), FileCompletionInformation );
1024 ok( res == STATUS_SUCCESS, "NtSetInformationFile failed: %x\n", res );
1025 ok( U(iosb).Status == STATUS_SUCCESS, "iosb.Status invalid: %x\n", U(iosb).Status );
1027 memset( send_buf, 0, TEST_BUF_LEN );
1028 memset( recv_buf, 0xde, TEST_BUF_LEN );
1029 count = get_pending_msgs(h);
1030 ok( !count, "Unexpected msg count: %ld\n", count );
1031 ReadFile( hPipeSrv, recv_buf, TEST_BUF_LEN, &read, &o);
1032 count = get_pending_msgs(h);
1033 ok( !count, "Unexpected msg count: %ld\n", count );
1034 WriteFile( hPipeClt, send_buf, TEST_BUF_LEN, &read, NULL );
1036 if (get_msg(h))
1038 ok( completionKey == CKEY_SECOND, "Invalid completion key: %lx\n", completionKey );
1039 ok( ioSb.Information == 3, "Invalid ioSb.Information: %ld\n", ioSb.Information );
1040 ok( U(ioSb).Status == STATUS_SUCCESS, "Invalid ioSb.Status: %x\n", U(ioSb).Status);
1041 ok( completionValue == (ULONG_PTR)&o, "Invalid completion value: %lx\n", completionValue );
1042 ok( !memcmp( send_buf, recv_buf, TEST_BUF_LEN ), "Receive buffer (%x %x %x) did not match send buffer (%x %x %x)\n", recv_buf[0], recv_buf[1], recv_buf[2], send_buf[0], send_buf[1], send_buf[2] );
1044 count = get_pending_msgs(h);
1045 ok( !count, "Unexpected msg count: %ld\n", count );
1047 memset( send_buf, 0, TEST_BUF_LEN );
1048 memset( recv_buf, 0xde, TEST_BUF_LEN );
1049 WriteFile( hPipeClt, send_buf, 2, &read, NULL );
1050 count = get_pending_msgs(h);
1051 ok( !count, "Unexpected msg count: %ld\n", count );
1052 ReadFile( hPipeSrv, recv_buf, 2, &read, &o);
1053 count = get_pending_msgs(h);
1054 ok( count == 1, "Unexpected msg count: %ld\n", count );
1055 if (get_msg(h))
1057 ok( completionKey == CKEY_SECOND, "Invalid completion key: %lx\n", completionKey );
1058 ok( ioSb.Information == 2, "Invalid ioSb.Information: %ld\n", ioSb.Information );
1059 ok( U(ioSb).Status == STATUS_SUCCESS, "Invalid ioSb.Status: %x\n", U(ioSb).Status);
1060 ok( completionValue == (ULONG_PTR)&o, "Invalid completion value: %lx\n", completionValue );
1061 ok( !memcmp( send_buf, recv_buf, 2 ), "Receive buffer (%x %x) did not match send buffer (%x %x)\n", recv_buf[0], recv_buf[1], send_buf[0], send_buf[1] );
1064 ReadFile( hPipeSrv, recv_buf, TEST_BUF_LEN, &read, &o);
1065 CloseHandle( hPipeSrv );
1066 count = get_pending_msgs(h);
1067 ok( count == 1, "Unexpected msg count: %ld\n", count );
1068 if (get_msg(h))
1070 ok( completionKey == CKEY_SECOND, "Invalid completion key: %lx\n", completionKey );
1071 ok( ioSb.Information == 0, "Invalid ioSb.Information: %ld\n", ioSb.Information );
1072 /* wine sends wrong status here */
1073 todo_wine ok( U(ioSb).Status == STATUS_PIPE_BROKEN, "Invalid ioSb.Status: %x\n", U(ioSb).Status);
1074 ok( completionValue == (ULONG_PTR)&o, "Invalid completion value: %lx\n", completionValue );
1078 CloseHandle( hPipeClt );
1081 static void test_file_basic_information(void)
1083 IO_STATUS_BLOCK io;
1084 FILE_BASIC_INFORMATION fbi;
1085 HANDLE h;
1086 int res;
1087 int attrib_mask = FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_NORMAL;
1089 if (!(h = create_temp_file(0))) return;
1091 /* Check default first */
1092 memset(&fbi, 0, sizeof(fbi));
1093 res = pNtQueryInformationFile(h, &io, &fbi, sizeof fbi, FileBasicInformation);
1094 ok ( res == STATUS_SUCCESS, "can't get attributes, res %x\n", res);
1095 ok ( (fbi.FileAttributes & FILE_ATTRIBUTE_ARCHIVE) == FILE_ATTRIBUTE_ARCHIVE,
1096 "attribute %x not expected\n", fbi.FileAttributes );
1098 /* Then SYSTEM */
1099 /* Clear fbi to avoid setting times */
1100 memset(&fbi, 0, sizeof(fbi));
1101 fbi.FileAttributes = FILE_ATTRIBUTE_SYSTEM;
1102 U(io).Status = 0xdeadbeef;
1103 res = pNtSetInformationFile(h, &io, &fbi, sizeof fbi, FileBasicInformation);
1104 ok ( res == STATUS_SUCCESS, "can't set system attribute, NtSetInformationFile returned %x\n", res );
1105 ok ( U(io).Status == STATUS_SUCCESS, "can't set system attribute, io.Status is %x\n", U(io).Status );
1107 memset(&fbi, 0, sizeof(fbi));
1108 res = pNtQueryInformationFile(h, &io, &fbi, sizeof fbi, FileBasicInformation);
1109 ok ( res == STATUS_SUCCESS, "can't get attributes\n");
1110 todo_wine ok ( (fbi.FileAttributes & attrib_mask) == FILE_ATTRIBUTE_SYSTEM, "attribute %x not FILE_ATTRIBUTE_SYSTEM\n", fbi.FileAttributes );
1112 /* Then HIDDEN */
1113 memset(&fbi, 0, sizeof(fbi));
1114 fbi.FileAttributes = FILE_ATTRIBUTE_HIDDEN;
1115 U(io).Status = 0xdeadbeef;
1116 res = pNtSetInformationFile(h, &io, &fbi, sizeof fbi, FileBasicInformation);
1117 ok ( res == STATUS_SUCCESS, "can't set system attribute, NtSetInformationFile returned %x\n", res );
1118 ok ( U(io).Status == STATUS_SUCCESS, "can't set system attribute, io.Status is %x\n", U(io).Status );
1120 memset(&fbi, 0, sizeof(fbi));
1121 res = pNtQueryInformationFile(h, &io, &fbi, sizeof fbi, FileBasicInformation);
1122 ok ( res == STATUS_SUCCESS, "can't get attributes\n");
1123 todo_wine ok ( (fbi.FileAttributes & attrib_mask) == FILE_ATTRIBUTE_HIDDEN, "attribute %x not FILE_ATTRIBUTE_HIDDEN\n", fbi.FileAttributes );
1125 /* Check NORMAL last of all (to make sure we can clear attributes) */
1126 memset(&fbi, 0, sizeof(fbi));
1127 fbi.FileAttributes = FILE_ATTRIBUTE_NORMAL;
1128 U(io).Status = 0xdeadbeef;
1129 res = pNtSetInformationFile(h, &io, &fbi, sizeof fbi, FileBasicInformation);
1130 ok ( res == STATUS_SUCCESS, "can't set normal attribute, NtSetInformationFile returned %x\n", res );
1131 ok ( U(io).Status == STATUS_SUCCESS, "can't set normal attribute, io.Status is %x\n", U(io).Status );
1133 memset(&fbi, 0, sizeof(fbi));
1134 res = pNtQueryInformationFile(h, &io, &fbi, sizeof fbi, FileBasicInformation);
1135 ok ( res == STATUS_SUCCESS, "can't get attributes\n");
1136 todo_wine ok ( (fbi.FileAttributes & attrib_mask) == FILE_ATTRIBUTE_NORMAL, "attribute %x not 0\n", fbi.FileAttributes );
1138 CloseHandle( h );
1141 static void test_file_all_information(void)
1143 IO_STATUS_BLOCK io;
1144 /* FileAllInformation, like FileNameInformation, has a variable-length pathname
1145 * buffer at the end. Vista objects with STATUS_BUFFER_OVERFLOW if you
1146 * don't leave enough room there.
1148 struct {
1149 FILE_ALL_INFORMATION fai;
1150 WCHAR buf[256];
1151 } fai_buf;
1152 HANDLE h;
1153 int res;
1154 int attrib_mask = FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_NORMAL;
1156 if (!(h = create_temp_file(0))) return;
1158 /* Check default first */
1159 res = pNtQueryInformationFile(h, &io, &fai_buf.fai, sizeof fai_buf, FileAllInformation);
1160 ok ( res == STATUS_SUCCESS, "can't get attributes, res %x\n", res);
1161 ok ( (fai_buf.fai.BasicInformation.FileAttributes & FILE_ATTRIBUTE_ARCHIVE) == FILE_ATTRIBUTE_ARCHIVE,
1162 "attribute %x not expected\n", fai_buf.fai.BasicInformation.FileAttributes );
1164 /* Then SYSTEM */
1165 /* Clear fbi to avoid setting times */
1166 memset(&fai_buf.fai.BasicInformation, 0, sizeof(fai_buf.fai.BasicInformation));
1167 fai_buf.fai.BasicInformation.FileAttributes = FILE_ATTRIBUTE_SYSTEM;
1168 U(io).Status = 0xdeadbeef;
1169 res = pNtSetInformationFile(h, &io, &fai_buf.fai, sizeof fai_buf, FileAllInformation);
1170 ok ( res == STATUS_INVALID_INFO_CLASS || broken(res == STATUS_NOT_IMPLEMENTED), "shouldn't be able to set FileAllInformation, res %x\n", res);
1171 todo_wine ok ( U(io).Status == 0xdeadbeef, "shouldn't be able to set FileAllInformation, io.Status is %x\n", U(io).Status);
1172 U(io).Status = 0xdeadbeef;
1173 res = pNtSetInformationFile(h, &io, &fai_buf.fai.BasicInformation, sizeof fai_buf.fai.BasicInformation, FileBasicInformation);
1174 ok ( res == STATUS_SUCCESS, "can't set system attribute, res: %x\n", res );
1175 ok ( U(io).Status == STATUS_SUCCESS, "can't set system attribute, io.Status: %x\n", U(io).Status );
1177 memset(&fai_buf.fai, 0, sizeof(fai_buf.fai));
1178 res = pNtQueryInformationFile(h, &io, &fai_buf.fai, sizeof fai_buf, FileAllInformation);
1179 ok ( res == STATUS_SUCCESS, "can't get attributes, res %x\n", res);
1180 todo_wine ok ( (fai_buf.fai.BasicInformation.FileAttributes & attrib_mask) == FILE_ATTRIBUTE_SYSTEM, "attribute %x not FILE_ATTRIBUTE_SYSTEM\n", fai_buf.fai.BasicInformation.FileAttributes );
1182 /* Then HIDDEN */
1183 memset(&fai_buf.fai.BasicInformation, 0, sizeof(fai_buf.fai.BasicInformation));
1184 fai_buf.fai.BasicInformation.FileAttributes = FILE_ATTRIBUTE_HIDDEN;
1185 U(io).Status = 0xdeadbeef;
1186 res = pNtSetInformationFile(h, &io, &fai_buf.fai.BasicInformation, sizeof fai_buf.fai.BasicInformation, FileBasicInformation);
1187 ok ( res == STATUS_SUCCESS, "can't set system attribute, res: %x\n", res );
1188 ok ( U(io).Status == STATUS_SUCCESS, "can't set system attribute, io.Status: %x\n", U(io).Status );
1190 memset(&fai_buf.fai, 0, sizeof(fai_buf.fai));
1191 res = pNtQueryInformationFile(h, &io, &fai_buf.fai, sizeof fai_buf, FileAllInformation);
1192 ok ( res == STATUS_SUCCESS, "can't get attributes\n");
1193 todo_wine ok ( (fai_buf.fai.BasicInformation.FileAttributes & attrib_mask) == FILE_ATTRIBUTE_HIDDEN, "attribute %x not FILE_ATTRIBUTE_HIDDEN\n", fai_buf.fai.BasicInformation.FileAttributes );
1195 /* Check NORMAL last of all (to make sure we can clear attributes) */
1196 memset(&fai_buf.fai.BasicInformation, 0, sizeof(fai_buf.fai.BasicInformation));
1197 fai_buf.fai.BasicInformation.FileAttributes = FILE_ATTRIBUTE_NORMAL;
1198 U(io).Status = 0xdeadbeef;
1199 res = pNtSetInformationFile(h, &io, &fai_buf.fai.BasicInformation, sizeof fai_buf.fai.BasicInformation, FileBasicInformation);
1200 ok ( res == STATUS_SUCCESS, "can't set system attribute, res: %x\n", res );
1201 ok ( U(io).Status == STATUS_SUCCESS, "can't set system attribute, io.Status: %x\n", U(io).Status );
1203 memset(&fai_buf.fai, 0, sizeof(fai_buf.fai));
1204 res = pNtQueryInformationFile(h, &io, &fai_buf.fai, sizeof fai_buf, FileAllInformation);
1205 ok ( res == STATUS_SUCCESS, "can't get attributes\n");
1206 todo_wine ok ( (fai_buf.fai.BasicInformation.FileAttributes & attrib_mask) == FILE_ATTRIBUTE_NORMAL, "attribute %x not FILE_ATTRIBUTE_NORMAL\n", fai_buf.fai.BasicInformation.FileAttributes );
1208 CloseHandle( h );
1211 static void test_file_both_information(void)
1213 IO_STATUS_BLOCK io;
1214 FILE_BOTH_DIR_INFORMATION fbi;
1215 HANDLE h;
1216 int res;
1218 if (!(h = create_temp_file(0))) return;
1220 memset(&fbi, 0, sizeof(fbi));
1221 res = pNtQueryInformationFile(h, &io, &fbi, sizeof fbi, FileBothDirectoryInformation);
1222 ok ( res == STATUS_INVALID_INFO_CLASS || res == STATUS_NOT_IMPLEMENTED, "shouldn't be able to query FileBothDirectoryInformation, res %x\n", res);
1224 CloseHandle( h );
1227 static void test_iocompletion(void)
1229 HANDLE h = INVALID_HANDLE_VALUE;
1230 NTSTATUS res;
1232 res = pNtCreateIoCompletion( &h, IO_COMPLETION_ALL_ACCESS, NULL, 0);
1234 ok( res == 0, "NtCreateIoCompletion anonymous failed: %x\n", res );
1235 ok( h && h != INVALID_HANDLE_VALUE, "Invalid handle returned\n" );
1237 if ( h && h != INVALID_HANDLE_VALUE)
1239 test_iocp_setcompletion(h);
1240 test_iocp_fileio(h);
1241 pNtClose(h);
1245 static void test_file_name_information(void)
1247 WCHAR *file_name, *volume_prefix, *expected;
1248 FILE_NAME_INFORMATION *info;
1249 ULONG old_redir = 1, tmp;
1250 UINT file_name_size;
1251 IO_STATUS_BLOCK io;
1252 UINT info_size;
1253 HRESULT hr;
1254 HANDLE h;
1255 UINT len;
1257 /* GetVolumePathName is not present before w2k */
1258 if (!pGetVolumePathNameW) {
1259 win_skip("GetVolumePathNameW not found\n");
1260 return;
1263 file_name_size = GetSystemDirectoryW( NULL, 0 );
1264 file_name = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*file_name) );
1265 volume_prefix = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*volume_prefix) );
1266 expected = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*volume_prefix) );
1268 len = GetSystemDirectoryW( file_name, file_name_size );
1269 ok(len == file_name_size - 1,
1270 "GetSystemDirectoryW returned %u, expected %u.\n",
1271 len, file_name_size - 1);
1273 len = pGetVolumePathNameW( file_name, volume_prefix, file_name_size );
1274 ok(len, "GetVolumePathNameW failed.\n");
1276 len = lstrlenW( volume_prefix );
1277 if (len && volume_prefix[len - 1] == '\\') --len;
1278 memcpy( expected, file_name + len, (file_name_size - len - 1) * sizeof(WCHAR) );
1279 expected[file_name_size - len - 1] = '\0';
1281 /* A bit more than we actually need, but it keeps the calculation simple. */
1282 info_size = sizeof(*info) + (file_name_size * sizeof(WCHAR));
1283 info = HeapAlloc( GetProcessHeap(), 0, info_size );
1285 if (pRtlWow64EnableFsRedirectionEx) pRtlWow64EnableFsRedirectionEx( TRUE, &old_redir );
1286 h = CreateFileW( file_name, GENERIC_READ,
1287 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
1288 NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0 );
1289 if (pRtlWow64EnableFsRedirectionEx) pRtlWow64EnableFsRedirectionEx( old_redir, &tmp );
1290 ok(h != INVALID_HANDLE_VALUE, "Failed to open file.\n");
1292 hr = pNtQueryInformationFile( h, &io, info, sizeof(*info) - 1, FileNameInformation );
1293 ok(hr == STATUS_INFO_LENGTH_MISMATCH, "NtQueryInformationFile returned %#x.\n", hr);
1295 memset( info, 0xcc, info_size );
1296 hr = pNtQueryInformationFile( h, &io, info, sizeof(*info), FileNameInformation );
1297 ok(hr == STATUS_BUFFER_OVERFLOW, "NtQueryInformationFile returned %#x, expected %#x.\n",
1298 hr, STATUS_BUFFER_OVERFLOW);
1299 ok(U(io).Status == STATUS_BUFFER_OVERFLOW, "io.Status is %#x, expected %#x.\n",
1300 U(io).Status, STATUS_BUFFER_OVERFLOW);
1301 ok(info->FileNameLength == lstrlenW( expected ) * sizeof(WCHAR), "info->FileNameLength is %u\n", info->FileNameLength);
1302 ok(info->FileName[2] == 0xcccc, "info->FileName[2] is %#x, expected 0xcccc.\n", info->FileName[2]);
1303 ok(CharLowerW((LPWSTR)(UINT_PTR)info->FileName[1]) == CharLowerW((LPWSTR)(UINT_PTR)expected[1]),
1304 "info->FileName[1] is %p, expected %p.\n",
1305 CharLowerW((LPWSTR)(UINT_PTR)info->FileName[1]), CharLowerW((LPWSTR)(UINT_PTR)expected[1]));
1306 ok(io.Information == sizeof(*info), "io.Information is %lu\n", io.Information);
1308 memset( info, 0xcc, info_size );
1309 hr = pNtQueryInformationFile( h, &io, info, info_size, FileNameInformation );
1310 ok(hr == STATUS_SUCCESS, "NtQueryInformationFile returned %#x, expected %#x.\n", hr, STATUS_SUCCESS);
1311 ok(U(io).Status == STATUS_SUCCESS, "io.Status is %#x, expected %#x.\n", U(io).Status, STATUS_SUCCESS);
1312 ok(info->FileNameLength == lstrlenW( expected ) * sizeof(WCHAR), "info->FileNameLength is %u\n", info->FileNameLength);
1313 ok(info->FileName[info->FileNameLength / sizeof(WCHAR)] == 0xcccc, "info->FileName[len] is %#x, expected 0xcccc.\n",
1314 info->FileName[info->FileNameLength / sizeof(WCHAR)]);
1315 info->FileName[info->FileNameLength / sizeof(WCHAR)] = '\0';
1316 ok(!lstrcmpiW( info->FileName, expected ), "info->FileName is %s, expected %s.\n",
1317 wine_dbgstr_w( info->FileName ), wine_dbgstr_w( expected ));
1318 ok(io.Information == FIELD_OFFSET(FILE_NAME_INFORMATION, FileName) + info->FileNameLength,
1319 "io.Information is %lu, expected %u.\n",
1320 io.Information, FIELD_OFFSET(FILE_NAME_INFORMATION, FileName) + info->FileNameLength);
1322 CloseHandle( h );
1323 HeapFree( GetProcessHeap(), 0, info );
1324 HeapFree( GetProcessHeap(), 0, expected );
1325 HeapFree( GetProcessHeap(), 0, volume_prefix );
1327 if (old_redir || !pGetSystemWow64DirectoryW || !(file_name_size = pGetSystemWow64DirectoryW( NULL, 0 )))
1329 skip("Not running on WoW64, skipping test.\n");
1330 HeapFree( GetProcessHeap(), 0, file_name );
1331 return;
1334 h = CreateFileW( file_name, GENERIC_READ,
1335 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
1336 NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0 );
1337 ok(h != INVALID_HANDLE_VALUE, "Failed to open file.\n");
1338 HeapFree( GetProcessHeap(), 0, file_name );
1340 file_name = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*file_name) );
1341 volume_prefix = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*volume_prefix) );
1342 expected = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*expected) );
1344 len = pGetSystemWow64DirectoryW( file_name, file_name_size );
1345 ok(len == file_name_size - 1,
1346 "GetSystemWow64DirectoryW returned %u, expected %u.\n",
1347 len, file_name_size - 1);
1349 len = pGetVolumePathNameW( file_name, volume_prefix, file_name_size );
1350 ok(len, "GetVolumePathNameW failed.\n");
1352 len = lstrlenW( volume_prefix );
1353 if (len && volume_prefix[len - 1] == '\\') --len;
1354 memcpy( expected, file_name + len, (file_name_size - len - 1) * sizeof(WCHAR) );
1355 expected[file_name_size - len - 1] = '\0';
1357 info_size = sizeof(*info) + (file_name_size * sizeof(WCHAR));
1358 info = HeapAlloc( GetProcessHeap(), 0, info_size );
1360 memset( info, 0xcc, info_size );
1361 hr = pNtQueryInformationFile( h, &io, info, info_size, FileNameInformation );
1362 ok(hr == STATUS_SUCCESS, "NtQueryInformationFile returned %#x, expected %#x.\n", hr, STATUS_SUCCESS);
1363 info->FileName[info->FileNameLength / sizeof(WCHAR)] = '\0';
1364 ok(!lstrcmpiW( info->FileName, expected ), "info->FileName is %s, expected %s.\n",
1365 wine_dbgstr_w( info->FileName ), wine_dbgstr_w( expected ));
1367 CloseHandle( h );
1368 HeapFree( GetProcessHeap(), 0, info );
1369 HeapFree( GetProcessHeap(), 0, expected );
1370 HeapFree( GetProcessHeap(), 0, volume_prefix );
1371 HeapFree( GetProcessHeap(), 0, file_name );
1374 static void test_file_all_name_information(void)
1376 WCHAR *file_name, *volume_prefix, *expected;
1377 FILE_ALL_INFORMATION *info;
1378 ULONG old_redir = 1, tmp;
1379 UINT file_name_size;
1380 IO_STATUS_BLOCK io;
1381 UINT info_size;
1382 HRESULT hr;
1383 HANDLE h;
1384 UINT len;
1386 /* GetVolumePathName is not present before w2k */
1387 if (!pGetVolumePathNameW) {
1388 win_skip("GetVolumePathNameW not found\n");
1389 return;
1392 file_name_size = GetSystemDirectoryW( NULL, 0 );
1393 file_name = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*file_name) );
1394 volume_prefix = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*volume_prefix) );
1395 expected = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*volume_prefix) );
1397 len = GetSystemDirectoryW( file_name, file_name_size );
1398 ok(len == file_name_size - 1,
1399 "GetSystemDirectoryW returned %u, expected %u.\n",
1400 len, file_name_size - 1);
1402 len = pGetVolumePathNameW( file_name, volume_prefix, file_name_size );
1403 ok(len, "GetVolumePathNameW failed.\n");
1405 len = lstrlenW( volume_prefix );
1406 if (len && volume_prefix[len - 1] == '\\') --len;
1407 memcpy( expected, file_name + len, (file_name_size - len - 1) * sizeof(WCHAR) );
1408 expected[file_name_size - len - 1] = '\0';
1410 /* A bit more than we actually need, but it keeps the calculation simple. */
1411 info_size = sizeof(*info) + (file_name_size * sizeof(WCHAR));
1412 info = HeapAlloc( GetProcessHeap(), 0, info_size );
1414 if (pRtlWow64EnableFsRedirectionEx) pRtlWow64EnableFsRedirectionEx( TRUE, &old_redir );
1415 h = CreateFileW( file_name, GENERIC_READ,
1416 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
1417 NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0 );
1418 if (pRtlWow64EnableFsRedirectionEx) pRtlWow64EnableFsRedirectionEx( old_redir, &tmp );
1419 ok(h != INVALID_HANDLE_VALUE, "Failed to open file.\n");
1421 hr = pNtQueryInformationFile( h, &io, info, sizeof(*info) - 1, FileAllInformation );
1422 ok(hr == STATUS_INFO_LENGTH_MISMATCH, "NtQueryInformationFile returned %#x, expected %#x.\n",
1423 hr, STATUS_INFO_LENGTH_MISMATCH);
1425 memset( info, 0xcc, info_size );
1426 hr = pNtQueryInformationFile( h, &io, info, sizeof(*info), FileAllInformation );
1427 ok(hr == STATUS_BUFFER_OVERFLOW, "NtQueryInformationFile returned %#x, expected %#x.\n",
1428 hr, STATUS_BUFFER_OVERFLOW);
1429 ok(U(io).Status == STATUS_BUFFER_OVERFLOW, "io.Status is %#x, expected %#x.\n",
1430 U(io).Status, STATUS_BUFFER_OVERFLOW);
1431 ok(info->NameInformation.FileNameLength == lstrlenW( expected ) * sizeof(WCHAR),
1432 "info->NameInformation.FileNameLength is %u\n", info->NameInformation.FileNameLength );
1433 ok(info->NameInformation.FileName[2] == 0xcccc,
1434 "info->NameInformation.FileName[2] is %#x, expected 0xcccc.\n", info->NameInformation.FileName[2]);
1435 ok(CharLowerW((LPWSTR)(UINT_PTR)info->NameInformation.FileName[1]) == CharLowerW((LPWSTR)(UINT_PTR)expected[1]),
1436 "info->NameInformation.FileName[1] is %p, expected %p.\n",
1437 CharLowerW((LPWSTR)(UINT_PTR)info->NameInformation.FileName[1]), CharLowerW((LPWSTR)(UINT_PTR)expected[1]));
1438 ok(io.Information == sizeof(*info), "io.Information is %lu\n", io.Information);
1440 memset( info, 0xcc, info_size );
1441 hr = pNtQueryInformationFile( h, &io, info, info_size, FileAllInformation );
1442 ok(hr == STATUS_SUCCESS, "NtQueryInformationFile returned %#x, expected %#x.\n", hr, STATUS_SUCCESS);
1443 ok(U(io).Status == STATUS_SUCCESS, "io.Status is %#x, expected %#x.\n", U(io).Status, STATUS_SUCCESS);
1444 ok(info->NameInformation.FileNameLength == lstrlenW( expected ) * sizeof(WCHAR),
1445 "info->NameInformation.FileNameLength is %u\n", info->NameInformation.FileNameLength );
1446 ok(info->NameInformation.FileName[info->NameInformation.FileNameLength / sizeof(WCHAR)] == 0xcccc,
1447 "info->NameInformation.FileName[len] is %#x, expected 0xcccc.\n",
1448 info->NameInformation.FileName[info->NameInformation.FileNameLength / sizeof(WCHAR)]);
1449 info->NameInformation.FileName[info->NameInformation.FileNameLength / sizeof(WCHAR)] = '\0';
1450 ok(!lstrcmpiW( info->NameInformation.FileName, expected ),
1451 "info->NameInformation.FileName is %s, expected %s.\n",
1452 wine_dbgstr_w( info->NameInformation.FileName ), wine_dbgstr_w( expected ));
1453 ok(io.Information == FIELD_OFFSET(FILE_ALL_INFORMATION, NameInformation.FileName)
1454 + info->NameInformation.FileNameLength,
1455 "io.Information is %lu\n", io.Information );
1457 CloseHandle( h );
1458 HeapFree( GetProcessHeap(), 0, info );
1459 HeapFree( GetProcessHeap(), 0, expected );
1460 HeapFree( GetProcessHeap(), 0, volume_prefix );
1462 if (old_redir || !pGetSystemWow64DirectoryW || !(file_name_size = pGetSystemWow64DirectoryW( NULL, 0 )))
1464 skip("Not running on WoW64, skipping test.\n");
1465 HeapFree( GetProcessHeap(), 0, file_name );
1466 return;
1469 h = CreateFileW( file_name, GENERIC_READ,
1470 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
1471 NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0 );
1472 ok(h != INVALID_HANDLE_VALUE, "Failed to open file.\n");
1473 HeapFree( GetProcessHeap(), 0, file_name );
1475 file_name = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*file_name) );
1476 volume_prefix = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*volume_prefix) );
1477 expected = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*expected) );
1479 len = pGetSystemWow64DirectoryW( file_name, file_name_size );
1480 ok(len == file_name_size - 1,
1481 "GetSystemWow64DirectoryW returned %u, expected %u.\n",
1482 len, file_name_size - 1);
1484 len = pGetVolumePathNameW( file_name, volume_prefix, file_name_size );
1485 ok(len, "GetVolumePathNameW failed.\n");
1487 len = lstrlenW( volume_prefix );
1488 if (len && volume_prefix[len - 1] == '\\') --len;
1489 memcpy( expected, file_name + len, (file_name_size - len - 1) * sizeof(WCHAR) );
1490 expected[file_name_size - len - 1] = '\0';
1492 info_size = sizeof(*info) + (file_name_size * sizeof(WCHAR));
1493 info = HeapAlloc( GetProcessHeap(), 0, info_size );
1495 memset( info, 0xcc, info_size );
1496 hr = pNtQueryInformationFile( h, &io, info, info_size, FileAllInformation );
1497 ok(hr == STATUS_SUCCESS, "NtQueryInformationFile returned %#x, expected %#x.\n", hr, STATUS_SUCCESS);
1498 info->NameInformation.FileName[info->NameInformation.FileNameLength / sizeof(WCHAR)] = '\0';
1499 ok(!lstrcmpiW( info->NameInformation.FileName, expected ), "info->NameInformation.FileName is %s, expected %s.\n",
1500 wine_dbgstr_w( info->NameInformation.FileName ), wine_dbgstr_w( expected ));
1502 CloseHandle( h );
1503 HeapFree( GetProcessHeap(), 0, info );
1504 HeapFree( GetProcessHeap(), 0, expected );
1505 HeapFree( GetProcessHeap(), 0, volume_prefix );
1506 HeapFree( GetProcessHeap(), 0, file_name );
1509 static void test_query_volume_information_file(void)
1511 NTSTATUS status;
1512 HANDLE dir;
1513 WCHAR path[MAX_PATH];
1514 OBJECT_ATTRIBUTES attr;
1515 IO_STATUS_BLOCK io;
1516 UNICODE_STRING nameW;
1517 FILE_FS_VOLUME_INFORMATION *ffvi;
1518 BYTE buf[sizeof(FILE_FS_VOLUME_INFORMATION) + MAX_PATH * sizeof(WCHAR)];
1520 GetWindowsDirectoryW( path, MAX_PATH );
1521 pRtlDosPathNameToNtPathName_U( path, &nameW, NULL, NULL );
1522 attr.Length = sizeof(attr);
1523 attr.RootDirectory = 0;
1524 attr.ObjectName = &nameW;
1525 attr.Attributes = OBJ_CASE_INSENSITIVE;
1526 attr.SecurityDescriptor = NULL;
1527 attr.SecurityQualityOfService = NULL;
1529 status = pNtOpenFile( &dir, SYNCHRONIZE|FILE_LIST_DIRECTORY, &attr, &io,
1530 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_DIRECTORY_FILE|FILE_SYNCHRONOUS_IO_NONALERT );
1531 ok( !status, "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
1532 pRtlFreeUnicodeString( &nameW );
1534 ZeroMemory( buf, sizeof(buf) );
1535 U(io).Status = 0xdadadada;
1536 io.Information = 0xcacacaca;
1538 status = pNtQueryVolumeInformationFile( dir, &io, buf, sizeof(buf), FileFsVolumeInformation );
1540 ffvi = (FILE_FS_VOLUME_INFORMATION *)buf;
1542 todo_wine
1544 ok(status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %d\n", status);
1545 ok(U(io).Status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %d\n", U(io).Status);
1547 ok(io.Information == (FIELD_OFFSET(FILE_FS_VOLUME_INFORMATION, VolumeLabel) + ffvi->VolumeLabelLength),
1548 "expected %d, got %lu\n", (FIELD_OFFSET(FILE_FS_VOLUME_INFORMATION, VolumeLabel) + ffvi->VolumeLabelLength),
1549 io.Information);
1551 ok(ffvi->VolumeCreationTime.QuadPart != 0, "Missing VolumeCreationTime\n");
1552 ok(ffvi->VolumeSerialNumber != 0, "Missing VolumeSerialNumber\n");
1553 ok(ffvi->SupportsObjects == 1,"expected 1, got %d\n", ffvi->SupportsObjects);
1555 ok(ffvi->VolumeLabelLength == lstrlenW(ffvi->VolumeLabel) * sizeof(WCHAR), "got %d\n", ffvi->VolumeLabelLength);
1557 trace("VolumeSerialNumber: %x VolumeLabelName: %s\n", ffvi->VolumeSerialNumber, wine_dbgstr_w(ffvi->VolumeLabel));
1559 CloseHandle( dir );
1562 static void test_NtCreateFile(void)
1564 static const struct test_data
1566 DWORD disposition, attrib_in, status, result, attrib_out, needs_cleanup;
1567 } td[] =
1569 /* 0*/{ FILE_CREATE, FILE_ATTRIBUTE_READONLY, 0, FILE_CREATED, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY, FALSE },
1570 /* 1*/{ FILE_CREATE, 0, STATUS_OBJECT_NAME_COLLISION, 0, 0, TRUE },
1571 /* 2*/{ FILE_CREATE, 0, 0, FILE_CREATED, FILE_ATTRIBUTE_ARCHIVE, FALSE },
1572 /* 3*/{ FILE_OPEN, FILE_ATTRIBUTE_READONLY, 0, FILE_OPENED, FILE_ATTRIBUTE_ARCHIVE, TRUE },
1573 /* 4*/{ FILE_OPEN, FILE_ATTRIBUTE_READONLY, STATUS_OBJECT_NAME_NOT_FOUND, 0, 0, FALSE },
1574 /* 5*/{ FILE_OPEN_IF, 0, 0, FILE_CREATED, FILE_ATTRIBUTE_ARCHIVE, FALSE },
1575 /* 6*/{ FILE_OPEN_IF, FILE_ATTRIBUTE_READONLY, 0, FILE_OPENED, FILE_ATTRIBUTE_ARCHIVE, TRUE },
1576 /* 7*/{ FILE_OPEN_IF, FILE_ATTRIBUTE_READONLY, 0, FILE_CREATED, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY, FALSE },
1577 /* 8*/{ FILE_OPEN_IF, 0, 0, FILE_OPENED, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY, FALSE },
1578 /* 9*/{ FILE_OVERWRITE, 0, STATUS_ACCESS_DENIED, 0, 0, TRUE },
1579 /*10*/{ FILE_OVERWRITE, 0, STATUS_OBJECT_NAME_NOT_FOUND, 0, 0, FALSE },
1580 /*11*/{ FILE_CREATE, 0, 0, FILE_CREATED, FILE_ATTRIBUTE_ARCHIVE, FALSE },
1581 /*12*/{ FILE_OVERWRITE, FILE_ATTRIBUTE_READONLY, 0, FILE_OVERWRITTEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY, FALSE },
1582 /*13*/{ FILE_OVERWRITE_IF, 0, STATUS_ACCESS_DENIED, 0, 0, TRUE },
1583 /*14*/{ FILE_OVERWRITE_IF, 0, 0, FILE_CREATED, FILE_ATTRIBUTE_ARCHIVE, FALSE },
1584 /*15*/{ FILE_OVERWRITE_IF, FILE_ATTRIBUTE_READONLY, 0, FILE_OVERWRITTEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY, FALSE },
1585 /*16*/{ FILE_SUPERSEDE, 0, 0, FILE_SUPERSEDED, FILE_ATTRIBUTE_ARCHIVE, FALSE },
1586 /*17*/{ FILE_SUPERSEDE, FILE_ATTRIBUTE_READONLY, 0, FILE_SUPERSEDED, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY, TRUE },
1587 /*18*/{ FILE_SUPERSEDE, 0, 0, FILE_CREATED, FILE_ATTRIBUTE_ARCHIVE, TRUE }
1589 static const WCHAR fooW[] = {'f','o','o',0};
1590 static const WCHAR dotW[] = {'.',0};
1591 NTSTATUS status;
1592 HANDLE handle;
1593 WCHAR path[MAX_PATH];
1594 OBJECT_ATTRIBUTES attr;
1595 IO_STATUS_BLOCK io;
1596 UNICODE_STRING nameW;
1597 DWORD ret, i;
1599 GetTempFileNameW(dotW, fooW, 0, path);
1600 DeleteFileW(path);
1601 pRtlDosPathNameToNtPathName_U(path, &nameW, NULL, NULL);
1603 attr.Length = sizeof(attr);
1604 attr.RootDirectory = NULL;
1605 attr.ObjectName = &nameW;
1606 attr.Attributes = OBJ_CASE_INSENSITIVE;
1607 attr.SecurityDescriptor = NULL;
1608 attr.SecurityQualityOfService = NULL;
1610 for (i = 0; i < sizeof(td)/sizeof(td[0]); i++)
1612 status = pNtCreateFile(&handle, GENERIC_READ, &attr, &io, NULL,
1613 td[i].attrib_in, FILE_SHARE_READ|FILE_SHARE_WRITE,
1614 td[i].disposition, 0, NULL, 0);
1616 ok(status == td[i].status, "%d: expected %#x got %#x\n", i, td[i].status, status);
1618 if (!status)
1620 ok(io.Information == td[i].result,"%d: expected %#x got %#lx\n", i, td[i].result, io.Information);
1622 ret = GetFileAttributesW(path);
1623 ret &= ~FILE_ATTRIBUTE_NOT_CONTENT_INDEXED;
1624 /* FIXME: leave only 'else' case below once Wine is fixed */
1625 if (ret != td[i].attrib_out)
1627 todo_wine
1628 ok(ret == td[i].attrib_out, "%d: expected %#x got %#x\n", i, td[i].attrib_out, ret);
1629 SetFileAttributesW(path, td[i].attrib_out);
1631 else
1632 ok(ret == td[i].attrib_out, "%d: expected %#x got %#x\n", i, td[i].attrib_out, ret);
1634 CloseHandle(handle);
1637 if (td[i].needs_cleanup)
1639 SetFileAttributesW(path, FILE_ATTRIBUTE_ARCHIVE);
1640 DeleteFileW(path);
1644 SetFileAttributesW(path, FILE_ATTRIBUTE_ARCHIVE);
1645 DeleteFileW( path );
1648 START_TEST(file)
1650 HMODULE hkernel32 = GetModuleHandleA("kernel32.dll");
1651 HMODULE hntdll = GetModuleHandleA("ntdll.dll");
1652 if (!hntdll)
1654 skip("not running on NT, skipping test\n");
1655 return;
1658 pGetVolumePathNameW = (void *)GetProcAddress(hkernel32, "GetVolumePathNameW");
1659 pGetSystemWow64DirectoryW = (void *)GetProcAddress(hkernel32, "GetSystemWow64DirectoryW");
1661 pRtlFreeUnicodeString = (void *)GetProcAddress(hntdll, "RtlFreeUnicodeString");
1662 pRtlInitUnicodeString = (void *)GetProcAddress(hntdll, "RtlInitUnicodeString");
1663 pRtlDosPathNameToNtPathName_U = (void *)GetProcAddress(hntdll, "RtlDosPathNameToNtPathName_U");
1664 pRtlWow64EnableFsRedirectionEx = (void *)GetProcAddress(hntdll, "RtlWow64EnableFsRedirectionEx");
1665 pNtCreateMailslotFile = (void *)GetProcAddress(hntdll, "NtCreateMailslotFile");
1666 pNtCreateFile = (void *)GetProcAddress(hntdll, "NtCreateFile");
1667 pNtOpenFile = (void *)GetProcAddress(hntdll, "NtOpenFile");
1668 pNtDeleteFile = (void *)GetProcAddress(hntdll, "NtDeleteFile");
1669 pNtReadFile = (void *)GetProcAddress(hntdll, "NtReadFile");
1670 pNtWriteFile = (void *)GetProcAddress(hntdll, "NtWriteFile");
1671 pNtCancelIoFile = (void *)GetProcAddress(hntdll, "NtCancelIoFile");
1672 pNtCancelIoFileEx = (void *)GetProcAddress(hntdll, "NtCancelIoFileEx");
1673 pNtClose = (void *)GetProcAddress(hntdll, "NtClose");
1674 pNtCreateIoCompletion = (void *)GetProcAddress(hntdll, "NtCreateIoCompletion");
1675 pNtOpenIoCompletion = (void *)GetProcAddress(hntdll, "NtOpenIoCompletion");
1676 pNtQueryIoCompletion = (void *)GetProcAddress(hntdll, "NtQueryIoCompletion");
1677 pNtRemoveIoCompletion = (void *)GetProcAddress(hntdll, "NtRemoveIoCompletion");
1678 pNtSetIoCompletion = (void *)GetProcAddress(hntdll, "NtSetIoCompletion");
1679 pNtSetInformationFile = (void *)GetProcAddress(hntdll, "NtSetInformationFile");
1680 pNtQueryInformationFile = (void *)GetProcAddress(hntdll, "NtQueryInformationFile");
1681 pNtQueryDirectoryFile = (void *)GetProcAddress(hntdll, "NtQueryDirectoryFile");
1682 pNtQueryVolumeInformationFile = (void *)GetProcAddress(hntdll, "NtQueryVolumeInformationFile");
1684 test_NtCreateFile();
1685 create_file_test();
1686 open_file_test();
1687 delete_file_test();
1688 read_file_test();
1689 append_file_test();
1690 nt_mailslot_test();
1691 test_iocompletion();
1692 test_file_basic_information();
1693 test_file_all_information();
1694 test_file_both_information();
1695 test_file_name_information();
1696 test_file_all_name_information();
1697 test_query_volume_information_file();