push 149f0a5527ac85057a8ef03858d34d91c36f97e8
[wine/hacks.git] / dlls / ntdll / tests / file.c
blob39e71a5584731a38a99392f9de6cd55450bd14ff
1 /* Unit test suite for Ntdll file functions
3 * Copyright 2007 Jeff Latimer
4 * Copyright 2007 Andrey Turkin
5 * Copyright 2008 Jeff Zaroyko
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 * NOTES
22 * We use function pointers here as there is no import library for NTDLL on
23 * windows.
26 #include <stdio.h>
27 #include <stdarg.h>
29 #include "ntstatus.h"
30 /* Define WIN32_NO_STATUS so MSVC does not give us duplicate macro
31 * definition errors when we get to winnt.h
33 #define WIN32_NO_STATUS
35 #include "wine/test.h"
36 #include "winternl.h"
37 #include "winuser.h"
39 #ifndef IO_COMPLETION_ALL_ACCESS
40 #define IO_COMPLETION_ALL_ACCESS 0x001F0003
41 #endif
43 static BOOL (WINAPI * pGetVolumePathNameW)(LPCWSTR, LPWSTR, DWORD);
44 static UINT (WINAPI *pGetSystemWow64DirectoryW)( LPWSTR, UINT );
46 static NTSTATUS (WINAPI *pRtlFreeUnicodeString)( PUNICODE_STRING );
47 static VOID (WINAPI *pRtlInitUnicodeString)( PUNICODE_STRING, LPCWSTR );
48 static BOOL (WINAPI *pRtlDosPathNameToNtPathName_U)( LPCWSTR, PUNICODE_STRING, PWSTR*, CURDIR* );
49 static NTSTATUS (WINAPI *pRtlWow64EnableFsRedirectionEx)( ULONG, ULONG * );
51 static NTSTATUS (WINAPI *pNtCreateMailslotFile)( PHANDLE, ULONG, POBJECT_ATTRIBUTES, PIO_STATUS_BLOCK,
52 ULONG, ULONG, ULONG, PLARGE_INTEGER );
53 static NTSTATUS (WINAPI *pNtOpenFile)(PHANDLE,ACCESS_MASK,POBJECT_ATTRIBUTES,PIO_STATUS_BLOCK,ULONG,ULONG);
54 static NTSTATUS (WINAPI *pNtDeleteFile)(POBJECT_ATTRIBUTES ObjectAttributes);
55 static NTSTATUS (WINAPI *pNtReadFile)(HANDLE hFile, HANDLE hEvent,
56 PIO_APC_ROUTINE apc, void* apc_user,
57 PIO_STATUS_BLOCK io_status, void* buffer, ULONG length,
58 PLARGE_INTEGER offset, PULONG key);
59 static NTSTATUS (WINAPI *pNtWriteFile)(HANDLE hFile, HANDLE hEvent,
60 PIO_APC_ROUTINE apc, void* apc_user,
61 PIO_STATUS_BLOCK io_status,
62 const void* buffer, ULONG length,
63 PLARGE_INTEGER offset, PULONG key);
64 static NTSTATUS (WINAPI *pNtCancelIoFile)(HANDLE hFile, PIO_STATUS_BLOCK io_status);
65 static NTSTATUS (WINAPI *pNtCancelIoFileEx)(HANDLE hFile, PIO_STATUS_BLOCK iosb, PIO_STATUS_BLOCK io_status);
66 static NTSTATUS (WINAPI *pNtClose)( PHANDLE );
68 static NTSTATUS (WINAPI *pNtCreateIoCompletion)(PHANDLE, ACCESS_MASK, POBJECT_ATTRIBUTES, ULONG);
69 static NTSTATUS (WINAPI *pNtOpenIoCompletion)(PHANDLE, ACCESS_MASK, POBJECT_ATTRIBUTES);
70 static NTSTATUS (WINAPI *pNtQueryIoCompletion)(HANDLE, IO_COMPLETION_INFORMATION_CLASS, PVOID, ULONG, PULONG);
71 static NTSTATUS (WINAPI *pNtRemoveIoCompletion)(HANDLE, PULONG_PTR, PULONG_PTR, PIO_STATUS_BLOCK, PLARGE_INTEGER);
72 static NTSTATUS (WINAPI *pNtSetIoCompletion)(HANDLE, ULONG_PTR, ULONG_PTR, NTSTATUS, ULONG);
73 static NTSTATUS (WINAPI *pNtSetInformationFile)(HANDLE, PIO_STATUS_BLOCK, PVOID, ULONG, FILE_INFORMATION_CLASS);
74 static NTSTATUS (WINAPI *pNtQueryInformationFile)(HANDLE, PIO_STATUS_BLOCK, PVOID, ULONG, FILE_INFORMATION_CLASS);
75 static NTSTATUS (WINAPI *pNtQueryDirectoryFile)(HANDLE,HANDLE,PIO_APC_ROUTINE,PVOID,PIO_STATUS_BLOCK,
76 PVOID,ULONG,FILE_INFORMATION_CLASS,BOOLEAN,PUNICODE_STRING,BOOLEAN);
78 static inline BOOL is_signaled( HANDLE obj )
80 return WaitForSingleObject( obj, 0 ) == 0;
83 #define PIPENAME "\\\\.\\pipe\\ntdll_tests_file.c"
84 #define TEST_BUF_LEN 3
86 static BOOL create_pipe( HANDLE *read, HANDLE *write, ULONG flags, ULONG size )
88 *read = CreateNamedPipe(PIPENAME, PIPE_ACCESS_INBOUND | flags, PIPE_TYPE_BYTE | PIPE_WAIT,
89 1, size, size, NMPWAIT_USE_DEFAULT_WAIT, NULL);
90 ok(*read != INVALID_HANDLE_VALUE, "CreateNamedPipe failed\n");
92 *write = CreateFileA(PIPENAME, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0);
93 ok(*write != INVALID_HANDLE_VALUE, "CreateFile failed (%d)\n", GetLastError());
95 return TRUE;
98 static HANDLE create_temp_file( ULONG flags )
100 char buffer[MAX_PATH];
101 HANDLE handle;
103 GetTempFileNameA( ".", "foo", 0, buffer );
104 handle = CreateFileA(buffer, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
105 flags | FILE_FLAG_DELETE_ON_CLOSE, 0);
106 ok( handle != INVALID_HANDLE_VALUE, "failed to create temp file\n" );
107 return (handle == INVALID_HANDLE_VALUE) ? 0 : handle;
110 #define CVALUE_FIRST 0xfffabbcc
111 #define CKEY_FIRST 0x1030341
112 #define CKEY_SECOND 0x132E46
114 ULONG_PTR completionKey;
115 IO_STATUS_BLOCK ioSb;
116 ULONG_PTR completionValue;
118 static long get_pending_msgs(HANDLE h)
120 NTSTATUS res;
121 ULONG a, req;
123 res = pNtQueryIoCompletion( h, IoCompletionBasicInformation, &a, sizeof(a), &req );
124 ok( res == STATUS_SUCCESS, "NtQueryIoCompletion failed: %x\n", res );
125 if (res != STATUS_SUCCESS) return -1;
126 ok( req == sizeof(a), "Unexpected response size: %x\n", req );
127 return a;
130 static BOOL get_msg(HANDLE h)
132 LARGE_INTEGER timeout = {{-10000000*3}};
133 DWORD res = pNtRemoveIoCompletion( h, &completionKey, &completionValue, &ioSb, &timeout);
134 ok( res == STATUS_SUCCESS, "NtRemoveIoCompletion failed: %x\n", res );
135 if (res != STATUS_SUCCESS)
137 completionKey = completionValue = 0;
138 memset(&ioSb, 0, sizeof(ioSb));
139 return FALSE;
141 return TRUE;
145 static void WINAPI apc( void *arg, IO_STATUS_BLOCK *iosb, ULONG reserved )
147 int *count = arg;
149 trace( "apc called block %p iosb.status %x iosb.info %lu\n",
150 iosb, U(*iosb).Status, iosb->Information );
151 (*count)++;
152 ok( !reserved, "reserved is not 0: %x\n", reserved );
155 static void open_file_test(void)
157 NTSTATUS status;
158 HANDLE dir, handle;
159 WCHAR path[MAX_PATH];
160 BYTE data[8192];
161 OBJECT_ATTRIBUTES attr;
162 IO_STATUS_BLOCK io;
163 UNICODE_STRING nameW;
164 UINT i, len;
165 BOOL restart = TRUE;
167 len = GetWindowsDirectoryW( path, MAX_PATH );
168 pRtlDosPathNameToNtPathName_U( path, &nameW, NULL, NULL );
169 attr.Length = sizeof(attr);
170 attr.RootDirectory = 0;
171 attr.ObjectName = &nameW;
172 attr.Attributes = OBJ_CASE_INSENSITIVE;
173 attr.SecurityDescriptor = NULL;
174 attr.SecurityQualityOfService = NULL;
175 status = pNtOpenFile( &dir, GENERIC_READ, &attr, &io,
176 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_DIRECTORY_FILE );
177 ok( !status, "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
179 /* test opening system dir with RootDirectory set to windows dir */
180 GetSystemDirectoryW( path, MAX_PATH );
181 while (path[len] == '\\') len++;
182 nameW.Buffer = path + len;
183 nameW.Length = lstrlenW(path + len) * sizeof(WCHAR);
184 attr.RootDirectory = dir;
185 status = pNtOpenFile( &handle, GENERIC_READ, &attr, &io,
186 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_DIRECTORY_FILE );
187 ok( !status, "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
188 CloseHandle( handle );
190 /* try uppercase name */
191 for (i = len; path[i]; i++) if (path[i] >= 'a' && path[i] <= 'z') path[i] -= 'a' - 'A';
192 status = pNtOpenFile( &handle, GENERIC_READ, &attr, &io,
193 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_DIRECTORY_FILE );
194 ok( !status, "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
195 CloseHandle( handle );
197 /* try with leading backslash */
198 nameW.Buffer--;
199 nameW.Length += sizeof(WCHAR);
200 status = pNtOpenFile( &handle, GENERIC_READ, &attr, &io,
201 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_DIRECTORY_FILE );
202 ok( status == STATUS_INVALID_PARAMETER ||
203 status == STATUS_OBJECT_NAME_INVALID ||
204 status == STATUS_OBJECT_PATH_SYNTAX_BAD,
205 "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
206 if (!status) CloseHandle( handle );
208 /* try with empty name */
209 nameW.Length = 0;
210 status = pNtOpenFile( &handle, GENERIC_READ, &attr, &io,
211 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_DIRECTORY_FILE );
212 ok( !status, "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
213 CloseHandle( handle );
215 /* try open by file id */
217 while (!pNtQueryDirectoryFile( dir, NULL, NULL, NULL, &io, data, sizeof(data),
218 FileIdBothDirectoryInformation, FALSE, NULL, restart ))
220 FILE_ID_BOTH_DIRECTORY_INFORMATION *info = (FILE_ID_BOTH_DIRECTORY_INFORMATION *)data;
222 restart = FALSE;
223 for (;;)
225 if (!info->FileId.QuadPart) goto next;
226 nameW.Buffer = (WCHAR *)&info->FileId;
227 nameW.Length = sizeof(info->FileId);
228 info->FileName[info->FileNameLength/sizeof(WCHAR)] = 0;
229 status = pNtOpenFile( &handle, GENERIC_READ, &attr, &io,
230 FILE_SHARE_READ|FILE_SHARE_WRITE,
231 FILE_OPEN_BY_FILE_ID |
232 ((info->FileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? FILE_DIRECTORY_FILE : 0) );
233 ok( status == STATUS_SUCCESS || status == STATUS_ACCESS_DENIED || status == STATUS_NOT_IMPLEMENTED,
234 "open %s failed %x\n", wine_dbgstr_w(info->FileName), status );
235 if (status == STATUS_NOT_IMPLEMENTED)
237 win_skip( "FILE_OPEN_BY_FILE_ID not supported\n" );
238 break;
240 if (!status)
242 FILE_ALL_INFORMATION all_info;
244 if (!pNtQueryInformationFile( handle, &io, &all_info, sizeof(all_info), FileAllInformation ))
246 /* check that it's the same file */
247 ok( info->EndOfFile.QuadPart == all_info.StandardInformation.EndOfFile.QuadPart,
248 "mismatched file size for %s\n", wine_dbgstr_w(info->FileName));
249 ok( info->LastWriteTime.QuadPart == all_info.BasicInformation.LastWriteTime.QuadPart,
250 "mismatched write time for %s\n", wine_dbgstr_w(info->FileName));
252 CloseHandle( handle );
254 next:
255 if (!info->NextEntryOffset) break;
256 info = (FILE_ID_BOTH_DIRECTORY_INFORMATION *)((char *)info + info->NextEntryOffset);
260 CloseHandle( dir );
263 static void delete_file_test(void)
265 NTSTATUS ret;
266 OBJECT_ATTRIBUTES attr;
267 UNICODE_STRING nameW;
268 WCHAR pathW[MAX_PATH];
269 WCHAR pathsubW[MAX_PATH];
270 static const WCHAR testdirW[] = {'n','t','d','e','l','e','t','e','f','i','l','e',0};
271 static const WCHAR subdirW[] = {'\\','s','u','b',0};
273 ret = GetTempPathW(MAX_PATH, pathW);
274 if (!ret)
276 ok(0, "couldn't get temp dir\n");
277 return;
279 if (ret + sizeof(testdirW)/sizeof(WCHAR)-1 + sizeof(subdirW)/sizeof(WCHAR)-1 >= MAX_PATH)
281 ok(0, "MAX_PATH exceeded in constructing paths\n");
282 return;
285 lstrcatW(pathW, testdirW);
286 lstrcpyW(pathsubW, pathW);
287 lstrcatW(pathsubW, subdirW);
289 ret = CreateDirectoryW(pathW, NULL);
290 ok(ret == TRUE, "couldn't create directory ntdeletefile\n");
291 if (!pRtlDosPathNameToNtPathName_U(pathW, &nameW, NULL, NULL))
293 ok(0,"RtlDosPathNametoNtPathName_U failed\n");
294 return;
297 attr.Length = sizeof(attr);
298 attr.RootDirectory = 0;
299 attr.Attributes = OBJ_CASE_INSENSITIVE;
300 attr.ObjectName = &nameW;
301 attr.SecurityDescriptor = NULL;
302 attr.SecurityQualityOfService = NULL;
304 /* test NtDeleteFile on an empty directory */
305 ret = pNtDeleteFile(&attr);
306 ok(ret == STATUS_SUCCESS, "NtDeleteFile should succeed in removing an empty directory\n");
307 ret = RemoveDirectoryW(pathW);
308 ok(ret == FALSE, "expected to fail removing directory, NtDeleteFile should have removed it\n");
310 /* test NtDeleteFile on a non-empty directory */
311 ret = CreateDirectoryW(pathW, NULL);
312 ok(ret == TRUE, "couldn't create directory ntdeletefile ?!\n");
313 ret = CreateDirectoryW(pathsubW, NULL);
314 ok(ret == TRUE, "couldn't create directory subdir\n");
315 ret = pNtDeleteFile(&attr);
316 ok(ret == STATUS_SUCCESS, "expected NtDeleteFile to ret STATUS_SUCCESS\n");
317 ret = RemoveDirectoryW(pathsubW);
318 ok(ret == TRUE, "expected to remove directory ntdeletefile\\sub\n");
319 ret = RemoveDirectoryW(pathW);
320 ok(ret == TRUE, "expected to remove directory ntdeletefile, NtDeleteFile failed.\n");
322 pRtlFreeUnicodeString( &nameW );
325 static void read_file_test(void)
327 const char text[] = "foobar";
328 HANDLE handle, read, write;
329 NTSTATUS status;
330 IO_STATUS_BLOCK iosb, iosb2;
331 DWORD written;
332 int apc_count = 0;
333 char buffer[128];
334 LARGE_INTEGER offset;
335 HANDLE event = CreateEventA( NULL, TRUE, FALSE, NULL );
337 buffer[0] = 1;
339 if (!create_pipe( &read, &write, FILE_FLAG_OVERLAPPED, 4096 )) return;
341 /* try read with no data */
342 U(iosb).Status = 0xdeadbabe;
343 iosb.Information = 0xdeadbeef;
344 ok( is_signaled( read ), "read handle is not signaled\n" );
345 status = pNtReadFile( read, event, apc, &apc_count, &iosb, buffer, 1, NULL, NULL );
346 ok( status == STATUS_PENDING, "wrong status %x\n", status );
347 ok( !is_signaled( read ), "read handle is signaled\n" );
348 ok( !is_signaled( event ), "event is signaled\n" );
349 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
350 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
351 ok( !apc_count, "apc was called\n" );
352 WriteFile( write, buffer, 1, &written, NULL );
353 /* iosb updated here by async i/o */
354 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
355 ok( U(iosb).Status == 0, "wrong status %x\n", U(iosb).Status );
356 ok( iosb.Information == 1, "wrong info %lu\n", iosb.Information );
357 ok( !is_signaled( read ), "read handle is signaled\n" );
358 ok( is_signaled( event ), "event is not signaled\n" );
359 ok( !apc_count, "apc was called\n" );
360 apc_count = 0;
361 SleepEx( 1, FALSE ); /* non-alertable sleep */
362 ok( !apc_count, "apc was called\n" );
363 SleepEx( 1, TRUE ); /* alertable sleep */
364 ok( apc_count == 1, "apc not called\n" );
366 /* with no event, the pipe handle itself gets signaled */
367 apc_count = 0;
368 U(iosb).Status = 0xdeadbabe;
369 iosb.Information = 0xdeadbeef;
370 ok( !is_signaled( read ), "read handle is not signaled\n" );
371 status = pNtReadFile( read, 0, apc, &apc_count, &iosb, buffer, 1, NULL, NULL );
372 ok( status == STATUS_PENDING, "wrong status %x\n", status );
373 ok( !is_signaled( read ), "read handle is signaled\n" );
374 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
375 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
376 ok( !apc_count, "apc was called\n" );
377 WriteFile( write, buffer, 1, &written, NULL );
378 /* iosb updated here by async i/o */
379 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
380 ok( U(iosb).Status == 0, "wrong status %x\n", U(iosb).Status );
381 ok( iosb.Information == 1, "wrong info %lu\n", iosb.Information );
382 ok( is_signaled( read ), "read handle is signaled\n" );
383 ok( !apc_count, "apc was called\n" );
384 apc_count = 0;
385 SleepEx( 1, FALSE ); /* non-alertable sleep */
386 ok( !apc_count, "apc was called\n" );
387 SleepEx( 1, TRUE ); /* alertable sleep */
388 ok( apc_count == 1, "apc not called\n" );
390 /* now read with data ready */
391 apc_count = 0;
392 U(iosb).Status = 0xdeadbabe;
393 iosb.Information = 0xdeadbeef;
394 ResetEvent( event );
395 WriteFile( write, buffer, 1, &written, NULL );
396 status = pNtReadFile( read, event, apc, &apc_count, &iosb, buffer, 1, NULL, NULL );
397 ok( status == STATUS_SUCCESS, "wrong status %x\n", status );
398 ok( U(iosb).Status == 0, "wrong status %x\n", U(iosb).Status );
399 ok( iosb.Information == 1, "wrong info %lu\n", iosb.Information );
400 ok( is_signaled( event ), "event is not signaled\n" );
401 ok( !apc_count, "apc was called\n" );
402 SleepEx( 1, FALSE ); /* non-alertable sleep */
403 ok( !apc_count, "apc was called\n" );
404 SleepEx( 1, TRUE ); /* alertable sleep */
405 ok( apc_count == 1, "apc not called\n" );
407 /* try read with no data */
408 apc_count = 0;
409 U(iosb).Status = 0xdeadbabe;
410 iosb.Information = 0xdeadbeef;
411 ok( is_signaled( event ), "event is not signaled\n" ); /* check that read resets the event */
412 status = pNtReadFile( read, event, apc, &apc_count, &iosb, buffer, 2, NULL, NULL );
413 ok( status == STATUS_PENDING, "wrong status %x\n", status );
414 ok( !is_signaled( event ), "event is signaled\n" );
415 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
416 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
417 ok( !apc_count, "apc was called\n" );
418 WriteFile( write, buffer, 1, &written, NULL );
419 /* partial read is good enough */
420 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
421 ok( is_signaled( event ), "event is signaled\n" );
422 ok( U(iosb).Status == 0, "wrong status %x\n", U(iosb).Status );
423 ok( iosb.Information == 1, "wrong info %lu\n", iosb.Information );
424 ok( !apc_count, "apc was called\n" );
425 SleepEx( 1, TRUE ); /* alertable sleep */
426 ok( apc_count == 1, "apc was not called\n" );
428 /* read from disconnected pipe */
429 apc_count = 0;
430 U(iosb).Status = 0xdeadbabe;
431 iosb.Information = 0xdeadbeef;
432 CloseHandle( write );
433 status = pNtReadFile( read, event, apc, &apc_count, &iosb, buffer, 1, NULL, NULL );
434 ok( status == STATUS_PIPE_BROKEN, "wrong status %x\n", status );
435 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
436 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
437 ok( !is_signaled( event ), "event is signaled\n" );
438 ok( !apc_count, "apc was called\n" );
439 SleepEx( 1, TRUE ); /* alertable sleep */
440 ok( !apc_count, "apc was called\n" );
441 CloseHandle( read );
443 /* read from closed handle */
444 apc_count = 0;
445 U(iosb).Status = 0xdeadbabe;
446 iosb.Information = 0xdeadbeef;
447 SetEvent( event );
448 status = pNtReadFile( read, event, apc, &apc_count, &iosb, buffer, 1, NULL, NULL );
449 ok( status == STATUS_INVALID_HANDLE, "wrong status %x\n", status );
450 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
451 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
452 ok( is_signaled( event ), "event is signaled\n" ); /* not reset on invalid handle */
453 ok( !apc_count, "apc was called\n" );
454 SleepEx( 1, TRUE ); /* alertable sleep */
455 ok( !apc_count, "apc was called\n" );
457 /* disconnect while async read is in progress */
458 if (!create_pipe( &read, &write, FILE_FLAG_OVERLAPPED, 4096 )) return;
459 apc_count = 0;
460 U(iosb).Status = 0xdeadbabe;
461 iosb.Information = 0xdeadbeef;
462 status = pNtReadFile( read, event, apc, &apc_count, &iosb, buffer, 2, NULL, NULL );
463 ok( status == STATUS_PENDING, "wrong status %x\n", status );
464 ok( !is_signaled( event ), "event is signaled\n" );
465 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
466 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
467 ok( !apc_count, "apc was called\n" );
468 CloseHandle( write );
469 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
470 ok( U(iosb).Status == STATUS_PIPE_BROKEN, "wrong status %x\n", U(iosb).Status );
471 ok( iosb.Information == 0, "wrong info %lu\n", iosb.Information );
472 ok( is_signaled( event ), "event is signaled\n" );
473 ok( !apc_count, "apc was called\n" );
474 SleepEx( 1, TRUE ); /* alertable sleep */
475 ok( apc_count == 1, "apc was not called\n" );
476 CloseHandle( read );
478 if (!create_pipe( &read, &write, FILE_FLAG_OVERLAPPED, 4096 )) return;
479 ok(DuplicateHandle(GetCurrentProcess(), read, GetCurrentProcess(), &handle, 0, TRUE, DUPLICATE_SAME_ACCESS),
480 "Failed to duplicate handle: %d\n", GetLastError());
482 apc_count = 0;
483 U(iosb).Status = 0xdeadbabe;
484 iosb.Information = 0xdeadbeef;
485 status = pNtReadFile( handle, event, apc, &apc_count, &iosb, buffer, 2, NULL, NULL );
486 ok( status == STATUS_PENDING, "wrong status %x\n", status );
487 ok( !is_signaled( event ), "event is signaled\n" );
488 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
489 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
490 ok( !apc_count, "apc was called\n" );
491 /* Cancel by other handle */
492 status = pNtCancelIoFile( read, &iosb2 );
493 ok(status == STATUS_SUCCESS, "failed to cancel by different handle: %x\n", status);
494 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
495 ok( U(iosb).Status == STATUS_CANCELLED, "wrong status %x\n", U(iosb).Status );
496 ok( iosb.Information == 0, "wrong info %lu\n", iosb.Information );
497 ok( is_signaled( event ), "event is signaled\n" );
498 todo_wine ok( !apc_count, "apc was called\n" );
499 SleepEx( 1, TRUE ); /* alertable sleep */
500 ok( apc_count == 1, "apc was not called\n" );
502 apc_count = 0;
503 U(iosb).Status = 0xdeadbabe;
504 iosb.Information = 0xdeadbeef;
505 status = pNtReadFile( read, event, apc, &apc_count, &iosb, buffer, 2, NULL, NULL );
506 ok( status == STATUS_PENDING, "wrong status %x\n", status );
507 ok( !is_signaled( event ), "event is signaled\n" );
508 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
509 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
510 ok( !apc_count, "apc was called\n" );
511 /* Close queued handle */
512 CloseHandle( read );
513 SleepEx( 1, TRUE ); /* alertable sleep */
514 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
515 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
516 status = pNtCancelIoFile( read, &iosb2 );
517 ok(status == STATUS_INVALID_HANDLE, "cancelled by closed handle?\n");
518 status = pNtCancelIoFile( handle, &iosb2 );
519 ok(status == STATUS_SUCCESS, "failed to cancel: %x\n", status);
520 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
521 ok( U(iosb).Status == STATUS_CANCELLED, "wrong status %x\n", U(iosb).Status );
522 ok( iosb.Information == 0, "wrong info %lu\n", iosb.Information );
523 ok( is_signaled( event ), "event is signaled\n" );
524 todo_wine ok( !apc_count, "apc was called\n" );
525 SleepEx( 1, TRUE ); /* alertable sleep */
526 ok( apc_count == 1, "apc was not called\n" );
527 CloseHandle( handle );
528 CloseHandle( write );
530 if (pNtCancelIoFileEx)
532 /* Basic Cancel Ex */
533 if (!create_pipe( &read, &write, FILE_FLAG_OVERLAPPED, 4096 )) return;
535 apc_count = 0;
536 U(iosb).Status = 0xdeadbabe;
537 iosb.Information = 0xdeadbeef;
538 status = pNtReadFile( read, event, apc, &apc_count, &iosb, buffer, 2, NULL, NULL );
539 ok( status == STATUS_PENDING, "wrong status %x\n", status );
540 ok( !is_signaled( event ), "event is signaled\n" );
541 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
542 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
543 ok( !apc_count, "apc was called\n" );
544 status = pNtCancelIoFileEx( read, &iosb, &iosb2 );
545 ok(status == STATUS_SUCCESS, "Failed to cancel I/O\n");
546 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
547 ok( U(iosb).Status == STATUS_CANCELLED, "wrong status %x\n", U(iosb).Status );
548 ok( iosb.Information == 0, "wrong info %lu\n", iosb.Information );
549 ok( is_signaled( event ), "event is signaled\n" );
550 todo_wine ok( !apc_count, "apc was called\n" );
551 SleepEx( 1, TRUE ); /* alertable sleep */
552 ok( apc_count == 1, "apc was not called\n" );
554 /* Duplicate iosb */
555 apc_count = 0;
556 U(iosb).Status = 0xdeadbabe;
557 iosb.Information = 0xdeadbeef;
558 status = pNtReadFile( read, event, apc, &apc_count, &iosb, buffer, 2, NULL, NULL );
559 ok( status == STATUS_PENDING, "wrong status %x\n", status );
560 ok( !is_signaled( event ), "event is signaled\n" );
561 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
562 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
563 ok( !apc_count, "apc was called\n" );
564 status = pNtReadFile( read, event, apc, &apc_count, &iosb, buffer, 2, NULL, NULL );
565 ok( status == STATUS_PENDING, "wrong status %x\n", status );
566 ok( !is_signaled( event ), "event is signaled\n" );
567 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
568 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
569 ok( !apc_count, "apc was called\n" );
570 status = pNtCancelIoFileEx( read, &iosb, &iosb2 );
571 ok(status == STATUS_SUCCESS, "Failed to cancel I/O\n");
572 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
573 ok( U(iosb).Status == STATUS_CANCELLED, "wrong status %x\n", U(iosb).Status );
574 ok( iosb.Information == 0, "wrong info %lu\n", iosb.Information );
575 ok( is_signaled( event ), "event is signaled\n" );
576 todo_wine ok( !apc_count, "apc was called\n" );
577 SleepEx( 1, TRUE ); /* alertable sleep */
578 ok( apc_count == 2, "apc was not called\n" );
580 CloseHandle( read );
581 CloseHandle( write );
584 /* now try a real file */
585 if (!(handle = create_temp_file( FILE_FLAG_OVERLAPPED ))) return;
586 apc_count = 0;
587 U(iosb).Status = 0xdeadbabe;
588 iosb.Information = 0xdeadbeef;
589 offset.QuadPart = 0;
590 ResetEvent( event );
591 status = pNtWriteFile( handle, event, apc, &apc_count, &iosb, text, strlen(text), &offset, NULL );
592 ok( status == STATUS_SUCCESS || status == STATUS_PENDING, "wrong status %x\n", status );
593 ok( U(iosb).Status == STATUS_SUCCESS, "wrong status %x\n", U(iosb).Status );
594 ok( iosb.Information == strlen(text), "wrong info %lu\n", iosb.Information );
595 ok( is_signaled( event ), "event is signaled\n" );
596 ok( !apc_count, "apc was called\n" );
597 SleepEx( 1, TRUE ); /* alertable sleep */
598 ok( apc_count == 1, "apc was not called\n" );
600 apc_count = 0;
601 U(iosb).Status = 0xdeadbabe;
602 iosb.Information = 0xdeadbeef;
603 offset.QuadPart = 0;
604 ResetEvent( event );
605 status = pNtReadFile( handle, event, apc, &apc_count, &iosb, buffer, strlen(text) + 10, &offset, NULL );
606 ok( status == STATUS_SUCCESS ||
607 status == STATUS_PENDING, /* vista */
608 "wrong status %x\n", status );
609 ok( U(iosb).Status == STATUS_SUCCESS, "wrong status %x\n", U(iosb).Status );
610 ok( iosb.Information == strlen(text), "wrong info %lu\n", iosb.Information );
611 ok( is_signaled( event ), "event is signaled\n" );
612 ok( !apc_count, "apc was called\n" );
613 SleepEx( 1, TRUE ); /* alertable sleep */
614 ok( apc_count == 1, "apc was not called\n" );
616 /* read beyond eof */
617 apc_count = 0;
618 U(iosb).Status = 0xdeadbabe;
619 iosb.Information = 0xdeadbeef;
620 offset.QuadPart = strlen(text) + 2;
621 status = pNtReadFile( handle, event, apc, &apc_count, &iosb, buffer, 2, &offset, NULL );
622 if (status == STATUS_PENDING) /* vista */
624 ok( U(iosb).Status == STATUS_END_OF_FILE, "wrong status %x\n", U(iosb).Status );
625 ok( iosb.Information == 0, "wrong info %lu\n", iosb.Information );
626 ok( is_signaled( event ), "event is signaled\n" );
627 ok( !apc_count, "apc was called\n" );
628 SleepEx( 1, TRUE ); /* alertable sleep */
629 ok( apc_count == 1, "apc was not called\n" );
631 else
633 ok( status == STATUS_END_OF_FILE, "wrong status %x\n", status );
634 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
635 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
636 ok( !is_signaled( event ), "event is signaled\n" );
637 ok( !apc_count, "apc was called\n" );
638 SleepEx( 1, TRUE ); /* alertable sleep */
639 ok( !apc_count, "apc was called\n" );
641 CloseHandle( handle );
643 /* now a non-overlapped file */
644 if (!(handle = create_temp_file(0))) return;
645 apc_count = 0;
646 U(iosb).Status = 0xdeadbabe;
647 iosb.Information = 0xdeadbeef;
648 offset.QuadPart = 0;
649 status = pNtWriteFile( handle, event, apc, &apc_count, &iosb, text, strlen(text), &offset, NULL );
650 ok( status == STATUS_END_OF_FILE ||
651 status == STATUS_SUCCESS ||
652 status == STATUS_PENDING, /* vista */
653 "wrong status %x\n", status );
654 ok( U(iosb).Status == STATUS_SUCCESS, "wrong status %x\n", U(iosb).Status );
655 ok( iosb.Information == strlen(text), "wrong info %lu\n", iosb.Information );
656 ok( is_signaled( event ), "event is signaled\n" );
657 ok( !apc_count, "apc was called\n" );
658 SleepEx( 1, TRUE ); /* alertable sleep */
659 ok( apc_count == 1, "apc was not called\n" );
661 apc_count = 0;
662 U(iosb).Status = 0xdeadbabe;
663 iosb.Information = 0xdeadbeef;
664 offset.QuadPart = 0;
665 ResetEvent( event );
666 status = pNtReadFile( handle, event, apc, &apc_count, &iosb, buffer, strlen(text) + 10, &offset, NULL );
667 ok( status == STATUS_SUCCESS, "wrong status %x\n", status );
668 ok( U(iosb).Status == STATUS_SUCCESS, "wrong status %x\n", U(iosb).Status );
669 ok( iosb.Information == strlen(text), "wrong info %lu\n", iosb.Information );
670 ok( is_signaled( event ), "event is signaled\n" );
671 ok( !apc_count, "apc was called\n" );
672 SleepEx( 1, TRUE ); /* alertable sleep */
673 todo_wine ok( !apc_count, "apc was called\n" );
675 /* read beyond eof */
676 apc_count = 0;
677 U(iosb).Status = 0xdeadbabe;
678 iosb.Information = 0xdeadbeef;
679 offset.QuadPart = strlen(text) + 2;
680 ResetEvent( event );
681 status = pNtReadFile( handle, event, apc, &apc_count, &iosb, buffer, 2, &offset, NULL );
682 ok( status == STATUS_END_OF_FILE, "wrong status %x\n", status );
683 todo_wine ok( U(iosb).Status == STATUS_END_OF_FILE, "wrong status %x\n", U(iosb).Status );
684 todo_wine ok( iosb.Information == 0, "wrong info %lu\n", iosb.Information );
685 todo_wine ok( is_signaled( event ), "event is not signaled\n" );
686 ok( !apc_count, "apc was called\n" );
687 SleepEx( 1, TRUE ); /* alertable sleep */
688 ok( !apc_count, "apc was called\n" );
690 CloseHandle( handle );
692 CloseHandle( event );
695 static void nt_mailslot_test(void)
697 HANDLE hslot;
698 ACCESS_MASK DesiredAccess;
699 OBJECT_ATTRIBUTES attr;
701 ULONG CreateOptions;
702 ULONG MailslotQuota;
703 ULONG MaxMessageSize;
704 LARGE_INTEGER TimeOut;
705 IO_STATUS_BLOCK IoStatusBlock;
706 NTSTATUS rc;
707 UNICODE_STRING str;
708 WCHAR buffer1[] = { '\\','?','?','\\','M','A','I','L','S','L','O','T','\\',
709 'R',':','\\','F','R','E','D','\0' };
711 TimeOut.QuadPart = -1;
713 pRtlInitUnicodeString(&str, buffer1);
714 InitializeObjectAttributes(&attr, &str, OBJ_CASE_INSENSITIVE, 0, NULL);
715 CreateOptions = MailslotQuota = MaxMessageSize = 0;
716 DesiredAccess = GENERIC_READ;
719 * Check for NULL pointer handling
721 rc = pNtCreateMailslotFile(NULL, DesiredAccess,
722 &attr, &IoStatusBlock, CreateOptions, MailslotQuota, MaxMessageSize,
723 &TimeOut);
724 ok( rc == STATUS_ACCESS_VIOLATION ||
725 rc == STATUS_INVALID_PARAMETER, /* win2k3 */
726 "rc = %x not STATUS_ACCESS_VIOLATION or STATUS_INVALID_PARAMETER\n", rc);
729 * Test to see if the Timeout can be NULL
731 hslot = (HANDLE)0xdeadbeef;
732 rc = pNtCreateMailslotFile(&hslot, DesiredAccess,
733 &attr, &IoStatusBlock, CreateOptions, MailslotQuota, MaxMessageSize,
734 NULL);
735 ok( rc == STATUS_SUCCESS ||
736 rc == STATUS_INVALID_PARAMETER, /* win2k3 */
737 "rc = %x not STATUS_SUCCESS or STATUS_INVALID_PARAMETER\n", rc);
738 ok( hslot != 0, "Handle is invalid\n");
740 if ( rc == STATUS_SUCCESS ) rc = pNtClose(hslot);
743 * Test that the length field is checked properly
745 attr.Length = 0;
746 rc = pNtCreateMailslotFile(&hslot, DesiredAccess,
747 &attr, &IoStatusBlock, CreateOptions, MailslotQuota, MaxMessageSize,
748 &TimeOut);
749 todo_wine ok( rc == STATUS_INVALID_PARAMETER, "rc = %x not c000000d STATUS_INVALID_PARAMETER\n", rc);
751 if (rc == STATUS_SUCCESS) pNtClose(hslot);
753 attr.Length = sizeof(OBJECT_ATTRIBUTES)+1;
754 rc = pNtCreateMailslotFile(&hslot, DesiredAccess,
755 &attr, &IoStatusBlock, CreateOptions, MailslotQuota, MaxMessageSize,
756 &TimeOut);
757 todo_wine ok( rc == STATUS_INVALID_PARAMETER, "rc = %x not c000000d STATUS_INVALID_PARAMETER\n", rc);
759 if (rc == STATUS_SUCCESS) pNtClose(hslot);
762 * Test handling of a NULL unicode string in ObjectName
764 InitializeObjectAttributes(&attr, &str, OBJ_CASE_INSENSITIVE, 0, NULL);
765 attr.ObjectName = NULL;
766 rc = pNtCreateMailslotFile(&hslot, DesiredAccess,
767 &attr, &IoStatusBlock, CreateOptions, MailslotQuota, MaxMessageSize,
768 &TimeOut);
769 ok( rc == STATUS_OBJECT_PATH_SYNTAX_BAD ||
770 rc == STATUS_INVALID_PARAMETER,
771 "rc = %x not STATUS_OBJECT_PATH_SYNTAX_BAD or STATUS_INVALID_PARAMETER\n", rc);
773 if (rc == STATUS_SUCCESS) pNtClose(hslot);
776 * Test a valid call
778 InitializeObjectAttributes(&attr, &str, OBJ_CASE_INSENSITIVE, 0, NULL);
779 rc = pNtCreateMailslotFile(&hslot, DesiredAccess,
780 &attr, &IoStatusBlock, CreateOptions, MailslotQuota, MaxMessageSize,
781 &TimeOut);
782 ok( rc == STATUS_SUCCESS, "Create MailslotFile failed rc = %x\n", rc);
783 ok( hslot != 0, "Handle is invalid\n");
785 rc = pNtClose(hslot);
786 ok( rc == STATUS_SUCCESS, "NtClose failed\n");
789 static void test_iocp_setcompletion(HANDLE h)
791 NTSTATUS res;
792 long count;
794 res = pNtSetIoCompletion( h, CKEY_FIRST, CVALUE_FIRST, STATUS_INVALID_DEVICE_REQUEST, 3 );
795 ok( res == STATUS_SUCCESS, "NtSetIoCompletion failed: %x\n", res );
797 count = get_pending_msgs(h);
798 ok( count == 1, "Unexpected msg count: %ld\n", count );
800 if (get_msg(h))
802 ok( completionKey == CKEY_FIRST, "Invalid completion key: %lx\n", completionKey );
803 ok( ioSb.Information == 3, "Invalid ioSb.Information: %ld\n", ioSb.Information );
804 ok( U(ioSb).Status == STATUS_INVALID_DEVICE_REQUEST, "Invalid ioSb.Status: %x\n", U(ioSb).Status);
805 ok( completionValue == CVALUE_FIRST, "Invalid completion value: %lx\n", completionValue );
808 count = get_pending_msgs(h);
809 ok( !count, "Unexpected msg count: %ld\n", count );
812 static void test_iocp_fileio(HANDLE h)
814 static const char pipe_name[] = "\\\\.\\pipe\\iocompletiontestnamedpipe";
816 IO_STATUS_BLOCK iosb;
817 FILE_COMPLETION_INFORMATION fci = {h, CKEY_SECOND};
818 HANDLE hPipeSrv, hPipeClt;
819 NTSTATUS res;
821 hPipeSrv = CreateNamedPipeA( pipe_name, PIPE_ACCESS_INBOUND, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, 4, 1024, 1024, 1000, NULL );
822 ok( hPipeSrv != INVALID_HANDLE_VALUE, "Cannot create named pipe\n" );
823 if (hPipeSrv != INVALID_HANDLE_VALUE )
825 hPipeClt = CreateFileA( pipe_name, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_NO_BUFFERING | FILE_FLAG_OVERLAPPED, NULL );
826 ok( hPipeClt != INVALID_HANDLE_VALUE, "Cannot connect to pipe\n" );
827 if (hPipeClt != INVALID_HANDLE_VALUE)
829 res = pNtSetInformationFile( hPipeSrv, &iosb, &fci, sizeof(fci), FileCompletionInformation );
830 ok( res == STATUS_INVALID_PARAMETER, "Unexpected NtSetInformationFile on non-overlapped handle: %x\n", res );
831 CloseHandle(hPipeClt);
833 CloseHandle( hPipeSrv );
836 hPipeSrv = CreateNamedPipeA( pipe_name, PIPE_ACCESS_INBOUND | FILE_FLAG_OVERLAPPED, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, 4, 1024, 1024, 1000, NULL );
837 ok( hPipeSrv != INVALID_HANDLE_VALUE, "Cannot create named pipe\n" );
838 if (hPipeSrv == INVALID_HANDLE_VALUE )
839 return;
841 hPipeClt = CreateFileA( pipe_name, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_NO_BUFFERING | FILE_FLAG_OVERLAPPED, NULL );
842 ok( hPipeClt != INVALID_HANDLE_VALUE, "Cannot connect to pipe\n" );
843 if (hPipeClt != INVALID_HANDLE_VALUE)
845 OVERLAPPED o = {0,};
846 BYTE send_buf[TEST_BUF_LEN], recv_buf[TEST_BUF_LEN];
847 DWORD read;
848 long count;
850 NTSTATUS res = pNtSetInformationFile( hPipeSrv, &iosb, &fci, sizeof(fci), FileCompletionInformation );
851 ok( res == STATUS_SUCCESS, "NtSetInformationFile failed: %x\n", res );
852 ok( U(iosb).Status == STATUS_SUCCESS, "iosb.Status invalid: %x\n", U(iosb).Status );
854 memset( send_buf, 0, TEST_BUF_LEN );
855 memset( recv_buf, 0xde, TEST_BUF_LEN );
856 count = get_pending_msgs(h);
857 ok( !count, "Unexpected msg count: %ld\n", count );
858 ReadFile( hPipeSrv, recv_buf, TEST_BUF_LEN, &read, &o);
859 count = get_pending_msgs(h);
860 ok( !count, "Unexpected msg count: %ld\n", count );
861 WriteFile( hPipeClt, send_buf, TEST_BUF_LEN, &read, NULL );
863 if (get_msg(h))
865 ok( completionKey == CKEY_SECOND, "Invalid completion key: %lx\n", completionKey );
866 ok( ioSb.Information == 3, "Invalid ioSb.Information: %ld\n", ioSb.Information );
867 ok( U(ioSb).Status == STATUS_SUCCESS, "Invalid ioSb.Status: %x\n", U(ioSb).Status);
868 ok( completionValue == (ULONG_PTR)&o, "Invalid completion value: %lx\n", completionValue );
869 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] );
871 count = get_pending_msgs(h);
872 ok( !count, "Unexpected msg count: %ld\n", count );
874 memset( send_buf, 0, TEST_BUF_LEN );
875 memset( recv_buf, 0xde, TEST_BUF_LEN );
876 WriteFile( hPipeClt, send_buf, 2, &read, NULL );
877 count = get_pending_msgs(h);
878 ok( !count, "Unexpected msg count: %ld\n", count );
879 ReadFile( hPipeSrv, recv_buf, 2, &read, &o);
880 count = get_pending_msgs(h);
881 ok( count == 1, "Unexpected msg count: %ld\n", count );
882 if (get_msg(h))
884 ok( completionKey == CKEY_SECOND, "Invalid completion key: %lx\n", completionKey );
885 ok( ioSb.Information == 2, "Invalid ioSb.Information: %ld\n", ioSb.Information );
886 ok( U(ioSb).Status == STATUS_SUCCESS, "Invalid ioSb.Status: %x\n", U(ioSb).Status);
887 ok( completionValue == (ULONG_PTR)&o, "Invalid completion value: %lx\n", completionValue );
888 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] );
891 ReadFile( hPipeSrv, recv_buf, TEST_BUF_LEN, &read, &o);
892 CloseHandle( hPipeSrv );
893 count = get_pending_msgs(h);
894 ok( count == 1, "Unexpected msg count: %ld\n", count );
895 if (get_msg(h))
897 ok( completionKey == CKEY_SECOND, "Invalid completion key: %lx\n", completionKey );
898 ok( ioSb.Information == 0, "Invalid ioSb.Information: %ld\n", ioSb.Information );
899 /* wine sends wrong status here */
900 todo_wine ok( U(ioSb).Status == STATUS_PIPE_BROKEN, "Invalid ioSb.Status: %x\n", U(ioSb).Status);
901 ok( completionValue == (ULONG_PTR)&o, "Invalid completion value: %lx\n", completionValue );
905 CloseHandle( hPipeClt );
908 static void test_file_basic_information(void)
910 IO_STATUS_BLOCK io;
911 FILE_BASIC_INFORMATION fbi;
912 HANDLE h;
913 int res;
914 int attrib_mask = FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_NORMAL;
916 if (!(h = create_temp_file(0))) return;
918 /* Check default first */
919 memset(&fbi, 0, sizeof(fbi));
920 res = pNtQueryInformationFile(h, &io, &fbi, sizeof fbi, FileBasicInformation);
921 ok ( res == STATUS_SUCCESS, "can't get attributes, res %x\n", res);
922 ok ( (fbi.FileAttributes & FILE_ATTRIBUTE_ARCHIVE) == FILE_ATTRIBUTE_ARCHIVE,
923 "attribute %x not expected\n", fbi.FileAttributes );
925 /* Then SYSTEM */
926 /* Clear fbi to avoid setting times */
927 memset(&fbi, 0, sizeof(fbi));
928 fbi.FileAttributes = FILE_ATTRIBUTE_SYSTEM;
929 res = pNtSetInformationFile(h, &io, &fbi, sizeof fbi, FileBasicInformation);
930 ok ( res == STATUS_SUCCESS, "can't set system attribute\n");
932 memset(&fbi, 0, sizeof(fbi));
933 res = pNtQueryInformationFile(h, &io, &fbi, sizeof fbi, FileBasicInformation);
934 ok ( res == STATUS_SUCCESS, "can't get attributes\n");
935 todo_wine ok ( (fbi.FileAttributes & attrib_mask) == FILE_ATTRIBUTE_SYSTEM, "attribute %x not FILE_ATTRIBUTE_SYSTEM\n", fbi.FileAttributes );
937 /* Then HIDDEN */
938 memset(&fbi, 0, sizeof(fbi));
939 fbi.FileAttributes = FILE_ATTRIBUTE_HIDDEN;
940 res = pNtSetInformationFile(h, &io, &fbi, sizeof fbi, FileBasicInformation);
941 ok ( res == STATUS_SUCCESS, "can't set system attribute\n");
943 memset(&fbi, 0, sizeof(fbi));
944 res = pNtQueryInformationFile(h, &io, &fbi, sizeof fbi, FileBasicInformation);
945 ok ( res == STATUS_SUCCESS, "can't get attributes\n");
946 todo_wine ok ( (fbi.FileAttributes & attrib_mask) == FILE_ATTRIBUTE_HIDDEN, "attribute %x not FILE_ATTRIBUTE_HIDDEN\n", fbi.FileAttributes );
948 /* Check NORMAL last of all (to make sure we can clear attributes) */
949 memset(&fbi, 0, sizeof(fbi));
950 fbi.FileAttributes = FILE_ATTRIBUTE_NORMAL;
951 res = pNtSetInformationFile(h, &io, &fbi, sizeof fbi, FileBasicInformation);
952 ok ( res == STATUS_SUCCESS, "can't set normal attribute\n");
954 memset(&fbi, 0, sizeof(fbi));
955 res = pNtQueryInformationFile(h, &io, &fbi, sizeof fbi, FileBasicInformation);
956 ok ( res == STATUS_SUCCESS, "can't get attributes\n");
957 todo_wine ok ( (fbi.FileAttributes & attrib_mask) == FILE_ATTRIBUTE_NORMAL, "attribute %x not 0\n", fbi.FileAttributes );
959 CloseHandle( h );
962 static void test_file_all_information(void)
964 IO_STATUS_BLOCK io;
965 /* FileAllInformation, like FileNameInformation, has a variable-length pathname
966 * buffer at the end. Vista objects with STATUS_BUFFER_OVERFLOW if you
967 * don't leave enough room there.
969 struct {
970 FILE_ALL_INFORMATION fai;
971 WCHAR buf[256];
972 } fai_buf;
973 HANDLE h;
974 int res;
975 int attrib_mask = FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_NORMAL;
977 if (!(h = create_temp_file(0))) return;
979 /* Check default first */
980 res = pNtQueryInformationFile(h, &io, &fai_buf.fai, sizeof fai_buf, FileAllInformation);
981 ok ( res == STATUS_SUCCESS, "can't get attributes, res %x\n", res);
982 ok ( (fai_buf.fai.BasicInformation.FileAttributes & FILE_ATTRIBUTE_ARCHIVE) == FILE_ATTRIBUTE_ARCHIVE,
983 "attribute %x not expected\n", fai_buf.fai.BasicInformation.FileAttributes );
985 /* Then SYSTEM */
986 /* Clear fbi to avoid setting times */
987 memset(&fai_buf.fai.BasicInformation, 0, sizeof(fai_buf.fai.BasicInformation));
988 fai_buf.fai.BasicInformation.FileAttributes = FILE_ATTRIBUTE_SYSTEM;
989 res = pNtSetInformationFile(h, &io, &fai_buf.fai, sizeof fai_buf, FileAllInformation);
990 ok ( res == STATUS_INVALID_INFO_CLASS || res == STATUS_NOT_IMPLEMENTED, "shouldn't be able to set FileAllInformation, res %x\n", res);
991 res = pNtSetInformationFile(h, &io, &fai_buf.fai.BasicInformation, sizeof fai_buf.fai.BasicInformation, FileBasicInformation);
992 ok ( res == STATUS_SUCCESS, "can't set system attribute\n");
994 memset(&fai_buf.fai, 0, sizeof(fai_buf.fai));
995 res = pNtQueryInformationFile(h, &io, &fai_buf.fai, sizeof fai_buf, FileAllInformation);
996 ok ( res == STATUS_SUCCESS, "can't get attributes, res %x\n", res);
997 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 );
999 /* Then HIDDEN */
1000 memset(&fai_buf.fai.BasicInformation, 0, sizeof(fai_buf.fai.BasicInformation));
1001 fai_buf.fai.BasicInformation.FileAttributes = FILE_ATTRIBUTE_HIDDEN;
1002 res = pNtSetInformationFile(h, &io, &fai_buf.fai.BasicInformation, sizeof fai_buf.fai.BasicInformation, FileBasicInformation);
1003 ok ( res == STATUS_SUCCESS, "can't set system attribute\n");
1005 memset(&fai_buf.fai, 0, sizeof(fai_buf.fai));
1006 res = pNtQueryInformationFile(h, &io, &fai_buf.fai, sizeof fai_buf, FileAllInformation);
1007 ok ( res == STATUS_SUCCESS, "can't get attributes\n");
1008 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 );
1010 /* Check NORMAL last of all (to make sure we can clear attributes) */
1011 memset(&fai_buf.fai.BasicInformation, 0, sizeof(fai_buf.fai.BasicInformation));
1012 fai_buf.fai.BasicInformation.FileAttributes = FILE_ATTRIBUTE_NORMAL;
1013 res = pNtSetInformationFile(h, &io, &fai_buf.fai.BasicInformation, sizeof fai_buf.fai.BasicInformation, FileBasicInformation);
1014 ok ( res == STATUS_SUCCESS, "can't set normal attribute\n");
1016 memset(&fai_buf.fai, 0, sizeof(fai_buf.fai));
1017 res = pNtQueryInformationFile(h, &io, &fai_buf.fai, sizeof fai_buf, FileAllInformation);
1018 ok ( res == STATUS_SUCCESS, "can't get attributes\n");
1019 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 );
1021 CloseHandle( h );
1024 static void test_file_both_information(void)
1026 IO_STATUS_BLOCK io;
1027 FILE_BOTH_DIR_INFORMATION fbi;
1028 HANDLE h;
1029 int res;
1031 if (!(h = create_temp_file(0))) return;
1033 memset(&fbi, 0, sizeof(fbi));
1034 res = pNtQueryInformationFile(h, &io, &fbi, sizeof fbi, FileBothDirectoryInformation);
1035 ok ( res == STATUS_INVALID_INFO_CLASS || res == STATUS_NOT_IMPLEMENTED, "shouldn't be able to query FileBothDirectoryInformation, res %x\n", res);
1037 CloseHandle( h );
1040 static void test_iocompletion(void)
1042 HANDLE h = INVALID_HANDLE_VALUE;
1043 NTSTATUS res;
1045 res = pNtCreateIoCompletion( &h, IO_COMPLETION_ALL_ACCESS, NULL, 0);
1047 ok( res == 0, "NtCreateIoCompletion anonymous failed: %x\n", res );
1048 ok( h && h != INVALID_HANDLE_VALUE, "Invalid handle returned\n" );
1050 if ( h && h != INVALID_HANDLE_VALUE)
1052 test_iocp_setcompletion(h);
1053 test_iocp_fileio(h);
1054 pNtClose(h);
1058 static void test_file_name_information(void)
1060 WCHAR *file_name, *volume_prefix, *expected;
1061 FILE_NAME_INFORMATION *info;
1062 ULONG old_redir = 1, tmp;
1063 UINT file_name_size;
1064 IO_STATUS_BLOCK io;
1065 UINT info_size;
1066 HRESULT hr;
1067 HANDLE h;
1068 UINT len;
1070 /* GetVolumePathName is not present before w2k */
1071 if (!pGetVolumePathNameW) {
1072 win_skip("GetVolumePathNameW not found\n");
1073 return;
1076 file_name_size = GetSystemDirectoryW( NULL, 0 );
1077 file_name = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*file_name) );
1078 volume_prefix = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*volume_prefix) );
1079 expected = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*volume_prefix) );
1081 len = GetSystemDirectoryW( file_name, file_name_size );
1082 ok(len == file_name_size - 1,
1083 "GetSystemDirectoryW returned %u, expected %u.\n",
1084 len, file_name_size - 1);
1086 len = pGetVolumePathNameW( file_name, volume_prefix, file_name_size );
1087 ok(len, "GetVolumePathNameW failed.\n");
1089 len = lstrlenW( volume_prefix );
1090 if (len && volume_prefix[len - 1] == '\\') --len;
1091 memcpy( expected, file_name + len, (file_name_size - len - 1) * sizeof(WCHAR) );
1092 expected[file_name_size - len - 1] = '\0';
1094 /* A bit more than we actually need, but it keeps the calculation simple. */
1095 info_size = sizeof(*info) + (file_name_size * sizeof(WCHAR));
1096 info = HeapAlloc( GetProcessHeap(), 0, info_size );
1098 if (pRtlWow64EnableFsRedirectionEx) pRtlWow64EnableFsRedirectionEx( TRUE, &old_redir );
1099 h = CreateFileW( file_name, GENERIC_READ,
1100 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
1101 NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0 );
1102 if (pRtlWow64EnableFsRedirectionEx) pRtlWow64EnableFsRedirectionEx( old_redir, &tmp );
1103 ok(h != INVALID_HANDLE_VALUE, "Failed to open file.\n");
1105 hr = pNtQueryInformationFile( h, &io, info, sizeof(*info) - 1, FileNameInformation );
1106 ok(hr == STATUS_INFO_LENGTH_MISMATCH, "NtQueryInformationFile returned %#x.\n", hr);
1108 memset( info, 0xcc, info_size );
1109 hr = pNtQueryInformationFile( h, &io, info, sizeof(*info), FileNameInformation );
1110 ok(hr == STATUS_BUFFER_OVERFLOW, "NtQueryInformationFile returned %#x, expected %#x.\n",
1111 hr, STATUS_BUFFER_OVERFLOW);
1112 ok(U(io).Status == STATUS_BUFFER_OVERFLOW, "io.Status is %#x, expected %#x.\n",
1113 U(io).Status, STATUS_BUFFER_OVERFLOW);
1114 ok(info->FileNameLength == lstrlenW( expected ) * sizeof(WCHAR), "info->FileNameLength is %u, expected %u.\n",
1115 info->FileNameLength, lstrlenW( expected ) * sizeof(WCHAR));
1116 ok(info->FileName[2] == 0xcccc, "info->FileName[2] is %#x, expected 0xcccc.\n", info->FileName[2]);
1117 ok(CharLowerW((LPWSTR)(UINT_PTR)info->FileName[1]) == CharLowerW((LPWSTR)(UINT_PTR)expected[1]),
1118 "info->FileName[1] is %p, expected %p.\n",
1119 CharLowerW((LPWSTR)(UINT_PTR)info->FileName[1]), CharLowerW((LPWSTR)(UINT_PTR)expected[1]));
1120 ok(io.Information == sizeof(*info), "io.Information is %lu, expected %u.\n", io.Information, sizeof(*info));
1122 memset( info, 0xcc, info_size );
1123 hr = pNtQueryInformationFile( h, &io, info, info_size, FileNameInformation );
1124 ok(hr == STATUS_SUCCESS, "NtQueryInformationFile returned %#x, expected %#x.\n", hr, STATUS_SUCCESS);
1125 ok(U(io).Status == STATUS_SUCCESS, "io.Status is %#x, expected %#x.\n", U(io).Status, STATUS_SUCCESS);
1126 ok(info->FileNameLength == lstrlenW( expected ) * sizeof(WCHAR), "info->FileNameLength is %u, expected %u.\n",
1127 info->FileNameLength, lstrlenW( expected ) * sizeof(WCHAR));
1128 ok(info->FileName[info->FileNameLength / sizeof(WCHAR)] == 0xcccc, "info->FileName[%u] is %#x, expected 0xcccc.\n",
1129 info->FileNameLength / sizeof(WCHAR), info->FileName[info->FileNameLength / sizeof(WCHAR)]);
1130 info->FileName[info->FileNameLength / sizeof(WCHAR)] = '\0';
1131 ok(!lstrcmpiW( info->FileName, expected ), "info->FileName is %s, expected %s.\n",
1132 wine_dbgstr_w( info->FileName ), wine_dbgstr_w( expected ));
1133 ok(io.Information == FIELD_OFFSET(FILE_NAME_INFORMATION, FileName) + info->FileNameLength,
1134 "io.Information is %lu, expected %u.\n",
1135 io.Information, FIELD_OFFSET(FILE_NAME_INFORMATION, FileName) + info->FileNameLength);
1137 CloseHandle( h );
1138 HeapFree( GetProcessHeap(), 0, info );
1139 HeapFree( GetProcessHeap(), 0, expected );
1140 HeapFree( GetProcessHeap(), 0, volume_prefix );
1142 if (old_redir || !pGetSystemWow64DirectoryW || !(file_name_size = pGetSystemWow64DirectoryW( NULL, 0 )))
1144 skip("Not running on WoW64, skipping test.\n");
1145 HeapFree( GetProcessHeap(), 0, file_name );
1146 return;
1149 h = CreateFileW( file_name, GENERIC_READ,
1150 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
1151 NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0 );
1152 ok(h != INVALID_HANDLE_VALUE, "Failed to open file.\n");
1153 HeapFree( GetProcessHeap(), 0, file_name );
1155 file_name = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*file_name) );
1156 volume_prefix = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*volume_prefix) );
1157 expected = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*expected) );
1159 len = pGetSystemWow64DirectoryW( file_name, file_name_size );
1160 ok(len == file_name_size - 1,
1161 "GetSystemWow64DirectoryW returned %u, expected %u.\n",
1162 len, file_name_size - 1);
1164 len = pGetVolumePathNameW( file_name, volume_prefix, file_name_size );
1165 ok(len, "GetVolumePathNameW failed.\n");
1167 len = lstrlenW( volume_prefix );
1168 if (len && volume_prefix[len - 1] == '\\') --len;
1169 memcpy( expected, file_name + len, (file_name_size - len - 1) * sizeof(WCHAR) );
1170 expected[file_name_size - len - 1] = '\0';
1172 info_size = sizeof(*info) + (file_name_size * sizeof(WCHAR));
1173 info = HeapAlloc( GetProcessHeap(), 0, info_size );
1175 memset( info, 0xcc, info_size );
1176 hr = pNtQueryInformationFile( h, &io, info, info_size, FileNameInformation );
1177 ok(hr == STATUS_SUCCESS, "NtQueryInformationFile returned %#x, expected %#x.\n", hr, STATUS_SUCCESS);
1178 info->FileName[info->FileNameLength / sizeof(WCHAR)] = '\0';
1179 ok(!lstrcmpiW( info->FileName, expected ), "info->FileName is %s, expected %s.\n",
1180 wine_dbgstr_w( info->FileName ), wine_dbgstr_w( expected ));
1182 CloseHandle( h );
1183 HeapFree( GetProcessHeap(), 0, info );
1184 HeapFree( GetProcessHeap(), 0, expected );
1185 HeapFree( GetProcessHeap(), 0, volume_prefix );
1186 HeapFree( GetProcessHeap(), 0, file_name );
1189 static void test_file_all_name_information(void)
1191 WCHAR *file_name, *volume_prefix, *expected;
1192 FILE_ALL_INFORMATION *info;
1193 ULONG old_redir = 1, tmp;
1194 UINT file_name_size;
1195 IO_STATUS_BLOCK io;
1196 UINT info_size;
1197 HRESULT hr;
1198 HANDLE h;
1199 UINT len;
1201 /* GetVolumePathName is not present before w2k */
1202 if (!pGetVolumePathNameW) {
1203 win_skip("GetVolumePathNameW not found\n");
1204 return;
1207 file_name_size = GetSystemDirectoryW( NULL, 0 );
1208 file_name = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*file_name) );
1209 volume_prefix = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*volume_prefix) );
1210 expected = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*volume_prefix) );
1212 len = GetSystemDirectoryW( file_name, file_name_size );
1213 ok(len == file_name_size - 1,
1214 "GetSystemDirectoryW returned %u, expected %u.\n",
1215 len, file_name_size - 1);
1217 len = pGetVolumePathNameW( file_name, volume_prefix, file_name_size );
1218 ok(len, "GetVolumePathNameW failed.\n");
1220 len = lstrlenW( volume_prefix );
1221 if (len && volume_prefix[len - 1] == '\\') --len;
1222 memcpy( expected, file_name + len, (file_name_size - len - 1) * sizeof(WCHAR) );
1223 expected[file_name_size - len - 1] = '\0';
1225 /* A bit more than we actually need, but it keeps the calculation simple. */
1226 info_size = sizeof(*info) + (file_name_size * sizeof(WCHAR));
1227 info = HeapAlloc( GetProcessHeap(), 0, info_size );
1229 if (pRtlWow64EnableFsRedirectionEx) pRtlWow64EnableFsRedirectionEx( TRUE, &old_redir );
1230 h = CreateFileW( file_name, GENERIC_READ,
1231 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
1232 NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0 );
1233 if (pRtlWow64EnableFsRedirectionEx) pRtlWow64EnableFsRedirectionEx( old_redir, &tmp );
1234 ok(h != INVALID_HANDLE_VALUE, "Failed to open file.\n");
1236 hr = pNtQueryInformationFile( h, &io, info, sizeof(*info) - 1, FileAllInformation );
1237 ok(hr == STATUS_INFO_LENGTH_MISMATCH, "NtQueryInformationFile returned %#x, expected %#x.\n",
1238 hr, STATUS_INFO_LENGTH_MISMATCH);
1240 memset( info, 0xcc, info_size );
1241 hr = pNtQueryInformationFile( h, &io, info, sizeof(*info), FileAllInformation );
1242 ok(hr == STATUS_BUFFER_OVERFLOW, "NtQueryInformationFile returned %#x, expected %#x.\n",
1243 hr, STATUS_BUFFER_OVERFLOW);
1244 ok(U(io).Status == STATUS_BUFFER_OVERFLOW, "io.Status is %#x, expected %#x.\n",
1245 U(io).Status, STATUS_BUFFER_OVERFLOW);
1246 ok(info->NameInformation.FileNameLength == lstrlenW( expected ) * sizeof(WCHAR),
1247 "info->NameInformation.FileNameLength is %u, expected %u.\n",
1248 info->NameInformation.FileNameLength, lstrlenW( expected ) * sizeof(WCHAR));
1249 ok(info->NameInformation.FileName[2] == 0xcccc,
1250 "info->NameInformation.FileName[2] is %#x, expected 0xcccc.\n", info->NameInformation.FileName[2]);
1251 ok(CharLowerW((LPWSTR)(UINT_PTR)info->NameInformation.FileName[1]) == CharLowerW((LPWSTR)(UINT_PTR)expected[1]),
1252 "info->NameInformation.FileName[1] is %p, expected %p.\n",
1253 CharLowerW((LPWSTR)(UINT_PTR)info->NameInformation.FileName[1]), CharLowerW((LPWSTR)(UINT_PTR)expected[1]));
1254 ok(io.Information == sizeof(*info), "io.Information is %lu, expected %u.\n", io.Information, sizeof(*info));
1256 memset( info, 0xcc, info_size );
1257 hr = pNtQueryInformationFile( h, &io, info, info_size, FileAllInformation );
1258 ok(hr == STATUS_SUCCESS, "NtQueryInformationFile returned %#x, expected %#x.\n", hr, STATUS_SUCCESS);
1259 ok(U(io).Status == STATUS_SUCCESS, "io.Status is %#x, expected %#x.\n", U(io).Status, STATUS_SUCCESS);
1260 ok(info->NameInformation.FileNameLength == lstrlenW( expected ) * sizeof(WCHAR),
1261 "info->NameInformation.FileNameLength is %u, expected %u.\n",
1262 info->NameInformation.FileNameLength, lstrlenW( expected ) * sizeof(WCHAR));
1263 ok(info->NameInformation.FileName[info->NameInformation.FileNameLength / sizeof(WCHAR)] == 0xcccc,
1264 "info->NameInformation.FileName[%u] is %#x, expected 0xcccc.\n",
1265 info->NameInformation.FileNameLength / sizeof(WCHAR),
1266 info->NameInformation.FileName[info->NameInformation.FileNameLength / sizeof(WCHAR)]);
1267 info->NameInformation.FileName[info->NameInformation.FileNameLength / sizeof(WCHAR)] = '\0';
1268 ok(!lstrcmpiW( info->NameInformation.FileName, expected ),
1269 "info->NameInformation.FileName is %s, expected %s.\n",
1270 wine_dbgstr_w( info->NameInformation.FileName ), wine_dbgstr_w( expected ));
1271 ok(io.Information == FIELD_OFFSET(FILE_ALL_INFORMATION, NameInformation.FileName)
1272 + info->NameInformation.FileNameLength,
1273 "io.Information is %lu, expected %u.\n",
1274 io.Information,
1275 FIELD_OFFSET(FILE_ALL_INFORMATION, NameInformation.FileName) + info->NameInformation.FileNameLength);
1277 CloseHandle( h );
1278 HeapFree( GetProcessHeap(), 0, info );
1279 HeapFree( GetProcessHeap(), 0, expected );
1280 HeapFree( GetProcessHeap(), 0, volume_prefix );
1282 if (old_redir || !pGetSystemWow64DirectoryW || !(file_name_size = pGetSystemWow64DirectoryW( NULL, 0 )))
1284 skip("Not running on WoW64, skipping test.\n");
1285 HeapFree( GetProcessHeap(), 0, file_name );
1286 return;
1289 h = CreateFileW( file_name, GENERIC_READ,
1290 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
1291 NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0 );
1292 ok(h != INVALID_HANDLE_VALUE, "Failed to open file.\n");
1293 HeapFree( GetProcessHeap(), 0, file_name );
1295 file_name = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*file_name) );
1296 volume_prefix = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*volume_prefix) );
1297 expected = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*expected) );
1299 len = pGetSystemWow64DirectoryW( file_name, file_name_size );
1300 ok(len == file_name_size - 1,
1301 "GetSystemWow64DirectoryW returned %u, expected %u.\n",
1302 len, file_name_size - 1);
1304 len = pGetVolumePathNameW( file_name, volume_prefix, file_name_size );
1305 ok(len, "GetVolumePathNameW failed.\n");
1307 len = lstrlenW( volume_prefix );
1308 if (len && volume_prefix[len - 1] == '\\') --len;
1309 memcpy( expected, file_name + len, (file_name_size - len - 1) * sizeof(WCHAR) );
1310 expected[file_name_size - len - 1] = '\0';
1312 info_size = sizeof(*info) + (file_name_size * sizeof(WCHAR));
1313 info = HeapAlloc( GetProcessHeap(), 0, info_size );
1315 memset( info, 0xcc, info_size );
1316 hr = pNtQueryInformationFile( h, &io, info, info_size, FileAllInformation );
1317 ok(hr == STATUS_SUCCESS, "NtQueryInformationFile returned %#x, expected %#x.\n", hr, STATUS_SUCCESS);
1318 info->NameInformation.FileName[info->NameInformation.FileNameLength / sizeof(WCHAR)] = '\0';
1319 ok(!lstrcmpiW( info->NameInformation.FileName, expected ), "info->NameInformation.FileName is %s, expected %s.\n",
1320 wine_dbgstr_w( info->NameInformation.FileName ), wine_dbgstr_w( expected ));
1322 CloseHandle( h );
1323 HeapFree( GetProcessHeap(), 0, info );
1324 HeapFree( GetProcessHeap(), 0, expected );
1325 HeapFree( GetProcessHeap(), 0, volume_prefix );
1326 HeapFree( GetProcessHeap(), 0, file_name );
1329 START_TEST(file)
1331 HMODULE hkernel32 = GetModuleHandleA("kernel32.dll");
1332 HMODULE hntdll = GetModuleHandleA("ntdll.dll");
1333 if (!hntdll)
1335 skip("not running on NT, skipping test\n");
1336 return;
1339 pGetVolumePathNameW = (void *)GetProcAddress(hkernel32, "GetVolumePathNameW");
1340 pGetSystemWow64DirectoryW = (void *)GetProcAddress(hkernel32, "GetSystemWow64DirectoryW");
1342 pRtlFreeUnicodeString = (void *)GetProcAddress(hntdll, "RtlFreeUnicodeString");
1343 pRtlInitUnicodeString = (void *)GetProcAddress(hntdll, "RtlInitUnicodeString");
1344 pRtlDosPathNameToNtPathName_U = (void *)GetProcAddress(hntdll, "RtlDosPathNameToNtPathName_U");
1345 pRtlWow64EnableFsRedirectionEx = (void *)GetProcAddress(hntdll, "RtlWow64EnableFsRedirectionEx");
1346 pNtCreateMailslotFile = (void *)GetProcAddress(hntdll, "NtCreateMailslotFile");
1347 pNtOpenFile = (void *)GetProcAddress(hntdll, "NtOpenFile");
1348 pNtDeleteFile = (void *)GetProcAddress(hntdll, "NtDeleteFile");
1349 pNtReadFile = (void *)GetProcAddress(hntdll, "NtReadFile");
1350 pNtWriteFile = (void *)GetProcAddress(hntdll, "NtWriteFile");
1351 pNtCancelIoFile = (void *)GetProcAddress(hntdll, "NtCancelIoFile");
1352 pNtCancelIoFileEx = (void *)GetProcAddress(hntdll, "NtCancelIoFileEx");
1353 pNtClose = (void *)GetProcAddress(hntdll, "NtClose");
1354 pNtCreateIoCompletion = (void *)GetProcAddress(hntdll, "NtCreateIoCompletion");
1355 pNtOpenIoCompletion = (void *)GetProcAddress(hntdll, "NtOpenIoCompletion");
1356 pNtQueryIoCompletion = (void *)GetProcAddress(hntdll, "NtQueryIoCompletion");
1357 pNtRemoveIoCompletion = (void *)GetProcAddress(hntdll, "NtRemoveIoCompletion");
1358 pNtSetIoCompletion = (void *)GetProcAddress(hntdll, "NtSetIoCompletion");
1359 pNtSetInformationFile = (void *)GetProcAddress(hntdll, "NtSetInformationFile");
1360 pNtQueryInformationFile = (void *)GetProcAddress(hntdll, "NtQueryInformationFile");
1361 pNtQueryDirectoryFile = (void *)GetProcAddress(hntdll, "NtQueryDirectoryFile");
1363 open_file_test();
1364 delete_file_test();
1365 read_file_test();
1366 nt_mailslot_test();
1367 test_iocompletion();
1368 test_file_basic_information();
1369 test_file_all_information();
1370 test_file_both_information();
1371 test_file_name_information();
1372 test_file_all_name_information();