2 * Unit test suite for object manager functions
4 * Copyright 2005 Robert Shearman
5 * Copyright 2005 Vitaliy Margolen
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
22 #include "ntdll_test.h"
28 static HANDLE (WINAPI
*pCreateWaitableTimerA
)(SECURITY_ATTRIBUTES
*, BOOL
, LPCSTR
);
29 static BOOLEAN (WINAPI
*pRtlCreateUnicodeStringFromAsciiz
)(PUNICODE_STRING
, LPCSTR
);
30 static VOID (WINAPI
*pRtlInitUnicodeString
)( PUNICODE_STRING
, LPCWSTR
);
31 static VOID (WINAPI
*pRtlFreeUnicodeString
)(PUNICODE_STRING
);
32 static NTSTATUS (WINAPI
*pNtCreateEvent
) ( PHANDLE
, ACCESS_MASK
, const POBJECT_ATTRIBUTES
, BOOLEAN
, BOOLEAN
);
33 static NTSTATUS (WINAPI
*pNtOpenEvent
) ( PHANDLE
, ACCESS_MASK
, const POBJECT_ATTRIBUTES
);
34 static NTSTATUS (WINAPI
*pNtPulseEvent
) ( HANDLE
, PULONG
);
35 static NTSTATUS (WINAPI
*pNtQueryEvent
) ( HANDLE
, EVENT_INFORMATION_CLASS
, PVOID
, ULONG
, PULONG
);
36 static NTSTATUS (WINAPI
*pNtCreateMutant
)( PHANDLE
, ACCESS_MASK
, const POBJECT_ATTRIBUTES
, BOOLEAN
);
37 static NTSTATUS (WINAPI
*pNtOpenMutant
) ( PHANDLE
, ACCESS_MASK
, const POBJECT_ATTRIBUTES
);
38 static NTSTATUS (WINAPI
*pNtCreateSemaphore
)( PHANDLE
, ACCESS_MASK
,const POBJECT_ATTRIBUTES
,LONG
,LONG
);
39 static NTSTATUS (WINAPI
*pNtCreateTimer
) ( PHANDLE
, ACCESS_MASK
, const POBJECT_ATTRIBUTES
, TIMER_TYPE
);
40 static NTSTATUS (WINAPI
*pNtCreateSection
)( PHANDLE
, ACCESS_MASK
, const POBJECT_ATTRIBUTES
, const PLARGE_INTEGER
,
41 ULONG
, ULONG
, HANDLE
);
42 static NTSTATUS (WINAPI
*pNtOpenFile
) ( PHANDLE
, ACCESS_MASK
, POBJECT_ATTRIBUTES
, PIO_STATUS_BLOCK
, ULONG
, ULONG
);
43 static NTSTATUS (WINAPI
*pNtClose
) ( HANDLE
);
44 static NTSTATUS (WINAPI
*pNtCreateNamedPipeFile
)( PHANDLE
, ULONG
, POBJECT_ATTRIBUTES
, PIO_STATUS_BLOCK
,
45 ULONG
, ULONG
, ULONG
, ULONG
, ULONG
, ULONG
, ULONG
, ULONG
, ULONG
, PLARGE_INTEGER
);
46 static NTSTATUS (WINAPI
*pNtOpenDirectoryObject
)(PHANDLE
, ACCESS_MASK
, POBJECT_ATTRIBUTES
);
47 static NTSTATUS (WINAPI
*pNtCreateDirectoryObject
)(PHANDLE
, ACCESS_MASK
, POBJECT_ATTRIBUTES
);
48 static NTSTATUS (WINAPI
*pNtOpenSymbolicLinkObject
)(PHANDLE
, ACCESS_MASK
, POBJECT_ATTRIBUTES
);
49 static NTSTATUS (WINAPI
*pNtCreateSymbolicLinkObject
)(PHANDLE
, ACCESS_MASK
, POBJECT_ATTRIBUTES
, PUNICODE_STRING
);
50 static NTSTATUS (WINAPI
*pNtQuerySymbolicLinkObject
)(HANDLE
,PUNICODE_STRING
,PULONG
);
51 static NTSTATUS (WINAPI
*pNtQueryObject
)(HANDLE
,OBJECT_INFORMATION_CLASS
,PVOID
,ULONG
,PULONG
);
52 static NTSTATUS (WINAPI
*pNtReleaseSemaphore
)(HANDLE
, ULONG
, PULONG
);
53 static NTSTATUS (WINAPI
*pNtCreateKeyedEvent
)( HANDLE
*, ACCESS_MASK
, const OBJECT_ATTRIBUTES
*, ULONG
);
54 static NTSTATUS (WINAPI
*pNtOpenKeyedEvent
)( HANDLE
*, ACCESS_MASK
, const OBJECT_ATTRIBUTES
* );
55 static NTSTATUS (WINAPI
*pNtWaitForKeyedEvent
)( HANDLE
, const void *, BOOLEAN
, const LARGE_INTEGER
* );
56 static NTSTATUS (WINAPI
*pNtReleaseKeyedEvent
)( HANDLE
, const void *, BOOLEAN
, const LARGE_INTEGER
* );
58 #define KEYEDEVENT_WAIT 0x0001
59 #define KEYEDEVENT_WAKE 0x0002
60 #define KEYEDEVENT_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | 0x0003)
62 static void test_case_sensitive (void)
64 static const WCHAR buffer1
[] = {'\\','B','a','s','e','N','a','m','e','d','O','b','j','e','c','t','s','\\','t','e','s','t',0};
65 static const WCHAR buffer2
[] = {'\\','B','a','s','e','N','a','m','e','d','O','b','j','e','c','t','s','\\','T','e','s','t',0};
66 static const WCHAR buffer3
[] = {'\\','B','a','s','e','N','a','m','e','d','O','b','j','e','c','t','s','\\','T','E','s','t',0};
67 static const WCHAR buffer4
[] = {'\\','B','A','S','E','N','a','m','e','d','O','b','j','e','c','t','s','\\','t','e','s','t',0};
69 OBJECT_ATTRIBUTES attr
;
71 HANDLE Event
, Mutant
, h
;
73 pRtlInitUnicodeString(&str
, buffer1
);
74 InitializeObjectAttributes(&attr
, &str
, 0, 0, NULL
);
75 status
= pNtCreateMutant(&Mutant
, GENERIC_ALL
, &attr
, FALSE
);
76 ok(status
== STATUS_SUCCESS
, "Failed to create Mutant(%08x)\n", status
);
78 status
= pNtCreateEvent(&Event
, GENERIC_ALL
, &attr
, FALSE
, FALSE
);
79 ok(status
== STATUS_OBJECT_NAME_COLLISION
|| status
== STATUS_OBJECT_TYPE_MISMATCH
,
80 "NtCreateEvent should have failed with STATUS_OBJECT_NAME_COLLISION or STATUS_OBJECT_TYPE_MISMATCH got (%08x)\n", status
);
82 pRtlInitUnicodeString(&str
, buffer2
);
83 InitializeObjectAttributes(&attr
, &str
, 0, 0, NULL
);
84 status
= pNtCreateEvent(&Event
, GENERIC_ALL
, &attr
, FALSE
, FALSE
);
85 ok(status
== STATUS_SUCCESS
, "Failed to create Event(%08x)\n", status
);
87 pRtlInitUnicodeString(&str
, buffer3
);
88 InitializeObjectAttributes(&attr
, &str
, OBJ_CASE_INSENSITIVE
, 0, NULL
);
89 status
= pNtOpenMutant(&h
, GENERIC_ALL
, &attr
);
90 ok(status
== STATUS_OBJECT_TYPE_MISMATCH
,
91 "NtOpenMutant should have failed with STATUS_OBJECT_TYPE_MISMATCH got(%08x)\n", status
);
95 pRtlInitUnicodeString(&str
, buffer4
);
96 InitializeObjectAttributes(&attr
, &str
, OBJ_CASE_INSENSITIVE
, 0, NULL
);
97 status
= pNtCreateMutant(&Mutant
, GENERIC_ALL
, &attr
, FALSE
);
98 ok(status
== STATUS_OBJECT_NAME_COLLISION
|| status
== STATUS_OBJECT_TYPE_MISMATCH
,
99 "NtCreateMutant should have failed with STATUS_OBJECT_NAME_COLLISION or STATUS_OBJECT_TYPE_MISMATCH got (%08x)\n", status
);
101 status
= pNtCreateEvent(&h
, GENERIC_ALL
, &attr
, FALSE
, FALSE
);
102 ok(status
== STATUS_OBJECT_NAME_COLLISION
,
103 "NtCreateEvent should have failed with STATUS_OBJECT_NAME_COLLISION got(%08x)\n", status
);
106 status
= pNtCreateMutant(&Mutant
, GENERIC_ALL
, &attr
, FALSE
);
107 ok(status
== STATUS_OBJECT_PATH_NOT_FOUND
,
108 "NtCreateMutant should have failed with STATUS_OBJECT_PATH_NOT_FOUND got(%08x)\n", status
);
113 static void test_namespace_pipe(void)
115 static const WCHAR buffer1
[] = {'\\','?','?','\\','P','I','P','E','\\','t','e','s','t','\\','p','i','p','e',0};
116 static const WCHAR buffer2
[] = {'\\','?','?','\\','P','I','P','E','\\','T','E','S','T','\\','P','I','P','E',0};
117 static const WCHAR buffer3
[] = {'\\','?','?','\\','p','i','p','e','\\','t','e','s','t','\\','p','i','p','e',0};
118 static const WCHAR buffer4
[] = {'\\','?','?','\\','p','i','p','e','\\','t','e','s','t',0};
119 OBJECT_ATTRIBUTES attr
;
121 IO_STATUS_BLOCK iosb
;
123 LARGE_INTEGER timeout
;
126 timeout
.QuadPart
= -10000;
128 pRtlInitUnicodeString(&str
, buffer1
);
129 InitializeObjectAttributes(&attr
, &str
, 0, 0, NULL
);
130 status
= pNtCreateNamedPipeFile(&pipe
, GENERIC_READ
|GENERIC_WRITE
, &attr
, &iosb
, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
131 FILE_CREATE
, FILE_PIPE_FULL_DUPLEX
, FALSE
, FALSE
, FALSE
, 1, 256, 256, &timeout
);
132 ok(status
== STATUS_SUCCESS
, "Failed to create NamedPipe(%08x)\n", status
);
134 status
= pNtCreateNamedPipeFile(&pipe
, GENERIC_READ
|GENERIC_WRITE
, &attr
, &iosb
, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
135 FILE_CREATE
, FILE_PIPE_FULL_DUPLEX
, FALSE
, FALSE
, FALSE
, 1, 256, 256, &timeout
);
136 ok(status
== STATUS_INSTANCE_NOT_AVAILABLE
,
137 "NtCreateNamedPipeFile should have failed with STATUS_INSTANCE_NOT_AVAILABLE got(%08x)\n", status
);
139 pRtlInitUnicodeString(&str
, buffer2
);
140 InitializeObjectAttributes(&attr
, &str
, 0, 0, NULL
);
141 status
= pNtCreateNamedPipeFile(&pipe
, GENERIC_READ
|GENERIC_WRITE
, &attr
, &iosb
, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
142 FILE_CREATE
, FILE_PIPE_FULL_DUPLEX
, FALSE
, FALSE
, FALSE
, 1, 256, 256, &timeout
);
143 ok(status
== STATUS_INSTANCE_NOT_AVAILABLE
,
144 "NtCreateNamedPipeFile should have failed with STATUS_INSTANCE_NOT_AVAILABLE got(%08x)\n", status
);
146 h
= CreateFileA("\\\\.\\pipe\\test\\pipe", GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
,
147 OPEN_EXISTING
, 0, 0 );
148 ok(h
!= INVALID_HANDLE_VALUE
, "Failed to open NamedPipe (%u)\n", GetLastError());
151 pRtlInitUnicodeString(&str
, buffer3
);
152 InitializeObjectAttributes(&attr
, &str
, 0, 0, NULL
);
153 status
= pNtOpenFile(&h
, GENERIC_READ
, &attr
, &iosb
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OPEN
);
154 ok(status
== STATUS_OBJECT_PATH_NOT_FOUND
||
155 status
== STATUS_PIPE_NOT_AVAILABLE
||
156 status
== STATUS_OBJECT_NAME_INVALID
|| /* vista */
157 status
== STATUS_OBJECT_NAME_NOT_FOUND
, /* win8 */
158 "NtOpenFile should have failed with STATUS_OBJECT_PATH_NOT_FOUND got(%08x)\n", status
);
160 pRtlInitUnicodeString(&str
, buffer4
);
161 InitializeObjectAttributes(&attr
, &str
, OBJ_CASE_INSENSITIVE
, 0, NULL
);
162 status
= pNtOpenFile(&h
, GENERIC_READ
, &attr
, &iosb
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OPEN
);
163 ok(status
== STATUS_OBJECT_NAME_NOT_FOUND
||
164 status
== STATUS_OBJECT_NAME_INVALID
, /* vista */
165 "NtOpenFile should have failed with STATUS_OBJECT_NAME_NOT_FOUND got(%08x)\n", status
);
170 #define DIRECTORY_QUERY (0x0001)
171 #define SYMBOLIC_LINK_QUERY 0x0001
173 #define DIR_TEST_CREATE_FAILURE(h,e) \
174 status = pNtCreateDirectoryObject(h, DIRECTORY_QUERY, &attr);\
175 ok(status == e,"NtCreateDirectoryObject should have failed with %s got(%08x)\n", #e, status);
176 #define DIR_TEST_OPEN_FAILURE(h,e) \
177 status = pNtOpenDirectoryObject(h, DIRECTORY_QUERY, &attr);\
178 ok(status == e,"NtOpenDirectoryObject should have failed with %s got(%08x)\n", #e, status);
179 #define DIR_TEST_CREATE_OPEN_FAILURE(h,n,e) \
180 pRtlCreateUnicodeStringFromAsciiz(&str, n);\
181 DIR_TEST_CREATE_FAILURE(h,e) DIR_TEST_OPEN_FAILURE(h,e)\
182 pRtlFreeUnicodeString(&str);
184 #define DIR_TEST_CREATE_SUCCESS(h) \
185 status = pNtCreateDirectoryObject(h, DIRECTORY_QUERY, &attr); \
186 ok(status == STATUS_SUCCESS, "Failed to create Directory(%08x)\n", status);
187 #define DIR_TEST_OPEN_SUCCESS(h) \
188 status = pNtOpenDirectoryObject(h, DIRECTORY_QUERY, &attr); \
189 ok(status == STATUS_SUCCESS, "Failed to open Directory(%08x)\n", status);
190 #define DIR_TEST_CREATE_OPEN_SUCCESS(h,n) \
191 pRtlCreateUnicodeStringFromAsciiz(&str, n);\
192 DIR_TEST_CREATE_SUCCESS(&h) pNtClose(h); DIR_TEST_OPEN_SUCCESS(&h) pNtClose(h); \
193 pRtlFreeUnicodeString(&str);
195 static BOOL
is_correct_dir( HANDLE dir
, const char *name
)
199 OBJECT_ATTRIBUTES attr
;
202 pRtlCreateUnicodeStringFromAsciiz(&str
, name
);
203 InitializeObjectAttributes(&attr
, &str
, OBJ_OPENIF
, dir
, NULL
);
204 status
= pNtCreateMutant(&h
, GENERIC_ALL
, &attr
, FALSE
);
205 pRtlFreeUnicodeString(&str
);
206 if (h
) pNtClose( h
);
207 return (status
== STATUS_OBJECT_NAME_EXISTS
);
210 /* return a handle to the BaseNamedObjects dir where kernel32 objects get created */
211 static HANDLE
get_base_dir(void)
213 static const char objname
[] = "om.c_get_base_dir_obj";
216 OBJECT_ATTRIBUTES attr
;
220 h
= CreateMutexA(NULL
, FALSE
, objname
);
221 ok(h
!= 0, "CreateMutexA failed got ret=%p (%d)\n", h
, GetLastError());
222 InitializeObjectAttributes(&attr
, &str
, OBJ_OPENIF
, 0, NULL
);
224 pRtlCreateUnicodeStringFromAsciiz(&str
, "\\BaseNamedObjects\\Local");
225 status
= pNtOpenDirectoryObject(&dir
, DIRECTORY_QUERY
, &attr
);
226 pRtlFreeUnicodeString(&str
);
227 if (!status
&& is_correct_dir( dir
, objname
)) goto done
;
228 if (!status
) pNtClose( dir
);
230 pRtlCreateUnicodeStringFromAsciiz(&str
, "\\BaseNamedObjects");
231 status
= pNtOpenDirectoryObject(&dir
, DIRECTORY_QUERY
, &attr
);
232 pRtlFreeUnicodeString(&str
);
233 if (!status
&& is_correct_dir( dir
, objname
)) goto done
;
234 if (!status
) pNtClose( dir
);
236 for (i
= 0; i
< 20; i
++)
239 sprintf( name
, "\\BaseNamedObjects\\Session\\%u", i
);
240 pRtlCreateUnicodeStringFromAsciiz(&str
, name
);
241 status
= pNtOpenDirectoryObject(&dir
, DIRECTORY_QUERY
, &attr
);
242 pRtlFreeUnicodeString(&str
);
243 if (!status
&& is_correct_dir( dir
, objname
)) goto done
;
244 if (!status
) pNtClose( dir
);
253 static void test_name_collisions(void)
257 OBJECT_ATTRIBUTES attr
;
258 HANDLE dir
, h
, h1
, h2
;
262 InitializeObjectAttributes(&attr
, &str
, 0, 0, NULL
);
263 pRtlCreateUnicodeStringFromAsciiz(&str
, "\\");
264 DIR_TEST_CREATE_FAILURE(&h
, STATUS_OBJECT_NAME_COLLISION
)
265 InitializeObjectAttributes(&attr
, &str
, OBJ_OPENIF
, 0, NULL
);
267 DIR_TEST_CREATE_FAILURE(&h
, STATUS_OBJECT_NAME_EXISTS
)
269 status
= pNtCreateMutant(&h
, GENERIC_ALL
, &attr
, FALSE
);
270 ok(status
== STATUS_OBJECT_TYPE_MISMATCH
,
271 "NtCreateMutant should have failed with STATUS_OBJECT_TYPE_MISMATCH got(%08x)\n", status
);
272 pRtlFreeUnicodeString(&str
);
274 pRtlCreateUnicodeStringFromAsciiz(&str
, "\\??\\PIPE\\om.c-mutant");
275 status
= pNtCreateMutant(&h
, GENERIC_ALL
, &attr
, FALSE
);
276 ok(status
== STATUS_OBJECT_TYPE_MISMATCH
|| status
== STATUS_OBJECT_PATH_NOT_FOUND
,
277 "NtCreateMutant should have failed with STATUS_OBJECT_TYPE_MISMATCH got(%08x)\n", status
);
278 pRtlFreeUnicodeString(&str
);
280 if (!(dir
= get_base_dir()))
282 win_skip( "couldn't find the BaseNamedObjects dir\n" );
285 pRtlCreateUnicodeStringFromAsciiz(&str
, "om.c-test");
286 InitializeObjectAttributes(&attr
, &str
, OBJ_OPENIF
, dir
, NULL
);
287 h
= CreateMutexA(NULL
, FALSE
, "om.c-test");
288 ok(h
!= 0, "CreateMutexA failed got ret=%p (%d)\n", h
, GetLastError());
289 status
= pNtCreateMutant(&h1
, GENERIC_ALL
, &attr
, FALSE
);
290 ok(status
== STATUS_OBJECT_NAME_EXISTS
&& h1
!= NULL
,
291 "NtCreateMutant should have succeeded with STATUS_OBJECT_NAME_EXISTS got(%08x)\n", status
);
292 h2
= CreateMutexA(NULL
, FALSE
, "om.c-test");
293 winerr
= GetLastError();
294 ok(h2
!= 0 && winerr
== ERROR_ALREADY_EXISTS
,
295 "CreateMutexA should have succeeded with ERROR_ALREADY_EXISTS got ret=%p (%d)\n", h2
, winerr
);
300 h
= CreateEventA(NULL
, FALSE
, FALSE
, "om.c-test");
301 ok(h
!= 0, "CreateEventA failed got ret=%p (%d)\n", h
, GetLastError());
302 status
= pNtCreateEvent(&h1
, GENERIC_ALL
, &attr
, FALSE
, FALSE
);
303 ok(status
== STATUS_OBJECT_NAME_EXISTS
&& h1
!= NULL
,
304 "NtCreateEvent should have succeeded with STATUS_OBJECT_NAME_EXISTS got(%08x)\n", status
);
305 h2
= CreateEventA(NULL
, FALSE
, FALSE
, "om.c-test");
306 winerr
= GetLastError();
307 ok(h2
!= 0 && winerr
== ERROR_ALREADY_EXISTS
,
308 "CreateEventA should have succeeded with ERROR_ALREADY_EXISTS got ret=%p (%d)\n", h2
, winerr
);
313 h
= CreateSemaphoreA(NULL
, 1, 2, "om.c-test");
314 ok(h
!= 0, "CreateSemaphoreA failed got ret=%p (%d)\n", h
, GetLastError());
315 status
= pNtCreateSemaphore(&h1
, GENERIC_ALL
, &attr
, 1, 2);
316 ok(status
== STATUS_OBJECT_NAME_EXISTS
&& h1
!= NULL
,
317 "NtCreateSemaphore should have succeeded with STATUS_OBJECT_NAME_EXISTS got(%08x)\n", status
);
318 h2
= CreateSemaphoreA(NULL
, 1, 2, "om.c-test");
319 winerr
= GetLastError();
320 ok(h2
!= 0 && winerr
== ERROR_ALREADY_EXISTS
,
321 "CreateSemaphoreA should have succeeded with ERROR_ALREADY_EXISTS got ret=%p (%d)\n", h2
, winerr
);
326 h
= pCreateWaitableTimerA(NULL
, TRUE
, "om.c-test");
327 ok(h
!= 0, "CreateWaitableTimerA failed got ret=%p (%d)\n", h
, GetLastError());
328 status
= pNtCreateTimer(&h1
, GENERIC_ALL
, &attr
, NotificationTimer
);
329 ok(status
== STATUS_OBJECT_NAME_EXISTS
&& h1
!= NULL
,
330 "NtCreateTimer should have succeeded with STATUS_OBJECT_NAME_EXISTS got(%08x)\n", status
);
331 h2
= pCreateWaitableTimerA(NULL
, TRUE
, "om.c-test");
332 winerr
= GetLastError();
333 ok(h2
!= 0 && winerr
== ERROR_ALREADY_EXISTS
,
334 "CreateWaitableTimerA should have succeeded with ERROR_ALREADY_EXISTS got ret=%p (%d)\n", h2
, winerr
);
339 h
= CreateFileMappingA(INVALID_HANDLE_VALUE
, NULL
, PAGE_READWRITE
, 0, 256, "om.c-test");
340 ok(h
!= 0, "CreateFileMappingA failed got ret=%p (%d)\n", h
, GetLastError());
341 size
.u
.LowPart
= 256;
343 status
= pNtCreateSection(&h1
, SECTION_MAP_WRITE
, &attr
, &size
, PAGE_READWRITE
, SEC_COMMIT
, 0);
344 ok(status
== STATUS_OBJECT_NAME_EXISTS
&& h1
!= NULL
,
345 "NtCreateSection should have succeeded with STATUS_OBJECT_NAME_EXISTS got(%08x)\n", status
);
346 h2
= CreateFileMappingA(INVALID_HANDLE_VALUE
, NULL
, PAGE_READWRITE
, 0, 256, "om.c-test");
347 winerr
= GetLastError();
348 ok(h2
!= 0 && winerr
== ERROR_ALREADY_EXISTS
,
349 "CreateFileMappingA should have succeeded with ERROR_ALREADY_EXISTS got ret=%p (%d)\n", h2
, winerr
);
354 pRtlFreeUnicodeString(&str
);
358 static void test_directory(void)
362 OBJECT_ATTRIBUTES attr
;
366 /* No name and/or no attributes */
367 status
= pNtCreateDirectoryObject(NULL
, DIRECTORY_QUERY
, &attr
);
368 ok(status
== STATUS_ACCESS_VIOLATION
|| status
== STATUS_INVALID_PARAMETER
,
369 "NtCreateDirectoryObject should have failed with STATUS_ACCESS_VIOLATION got(%08x)\n", status
);
370 status
= pNtOpenDirectoryObject(NULL
, DIRECTORY_QUERY
, &attr
);
371 ok(status
== STATUS_ACCESS_VIOLATION
|| status
== STATUS_INVALID_PARAMETER
,
372 "NtOpenDirectoryObject should have failed with STATUS_ACCESS_VIOLATION got(%08x)\n", status
);
374 status
= pNtCreateDirectoryObject(&h
, DIRECTORY_QUERY
, NULL
);
375 ok(status
== STATUS_SUCCESS
, "Failed to create Directory without attributes(%08x)\n", status
);
377 status
= pNtOpenDirectoryObject(&h
, DIRECTORY_QUERY
, NULL
);
378 ok(status
== STATUS_INVALID_PARAMETER
,
379 "NtOpenDirectoryObject should have failed with STATUS_INVALID_PARAMETER got(%08x)\n", status
);
381 InitializeObjectAttributes(&attr
, NULL
, 0, 0, NULL
);
382 DIR_TEST_CREATE_SUCCESS(&dir
)
383 DIR_TEST_OPEN_FAILURE(&h
, STATUS_OBJECT_PATH_SYNTAX_BAD
)
386 InitializeObjectAttributes(&attr
, &str
, 0, 0, NULL
);
388 pRtlCreateUnicodeStringFromAsciiz(&str
, "");
389 DIR_TEST_CREATE_SUCCESS(&h
)
391 DIR_TEST_OPEN_FAILURE(&h
, STATUS_OBJECT_PATH_SYNTAX_BAD
)
392 pRtlFreeUnicodeString(&str
);
395 DIR_TEST_CREATE_OPEN_FAILURE(&h
, "BaseNamedObjects", STATUS_OBJECT_PATH_SYNTAX_BAD
)
396 DIR_TEST_CREATE_OPEN_FAILURE(&h
, "\\BaseNamedObjects\\", STATUS_OBJECT_NAME_INVALID
)
397 DIR_TEST_CREATE_OPEN_FAILURE(&h
, "\\\\BaseNamedObjects", STATUS_OBJECT_NAME_INVALID
)
398 DIR_TEST_CREATE_OPEN_FAILURE(&h
, "\\BaseNamedObjects\\\\om.c-test", STATUS_OBJECT_NAME_INVALID
)
399 DIR_TEST_CREATE_OPEN_FAILURE(&h
, "\\BaseNamedObjects\\om.c-test\\", STATUS_OBJECT_PATH_NOT_FOUND
)
401 pRtlCreateUnicodeStringFromAsciiz(&str
, "\\BaseNamedObjects\\om.c-test");
402 DIR_TEST_CREATE_SUCCESS(&h
)
403 DIR_TEST_OPEN_SUCCESS(&dir1
)
404 pRtlFreeUnicodeString(&str
);
409 /* Use of root directory */
411 /* Can't use symlinks as a directory */
412 pRtlCreateUnicodeStringFromAsciiz(&str
, "\\BaseNamedObjects\\Local");
413 InitializeObjectAttributes(&attr
, &str
, 0, 0, NULL
);
414 status
= pNtOpenSymbolicLinkObject(&dir
, SYMBOLIC_LINK_QUERY
, &attr
);
415 is_nt4
= (status
== STATUS_OBJECT_NAME_NOT_FOUND
); /* nt4 doesn't have Local\\ symlink */
421 ok(status
== STATUS_SUCCESS
, "Failed to open SymbolicLink(%08x)\n", status
);
422 pRtlFreeUnicodeString(&str
);
423 InitializeObjectAttributes(&attr
, &str
, 0, dir
, NULL
);
424 pRtlCreateUnicodeStringFromAsciiz(&str
, "one more level");
425 DIR_TEST_CREATE_FAILURE(&h
, STATUS_OBJECT_TYPE_MISMATCH
)
426 pRtlFreeUnicodeString(&str
);
429 str
.MaximumLength
= sizeof(buffer
);
431 memset( buffer
, 0xaa, sizeof(buffer
) );
432 status
= pNtQuerySymbolicLinkObject( dir
, &str
, &len
);
433 ok( status
== STATUS_SUCCESS
, "NtQuerySymbolicLinkObject failed %08x\n", status
);
434 if (status
!= STATUS_SUCCESS
)
436 full_len
= str
.Length
+ sizeof(WCHAR
);
437 ok( len
== full_len
, "bad length %u/%u\n", len
, full_len
);
439 ok( buffer
[len
/ sizeof(WCHAR
) - 1] == 0, "no terminating null\n" );
441 str
.MaximumLength
= str
.Length
;
443 status
= pNtQuerySymbolicLinkObject( dir
, &str
, &len
);
444 ok( status
== STATUS_BUFFER_TOO_SMALL
, "NtQuerySymbolicLinkObject failed %08x\n", status
);
445 ok( len
== full_len
, "bad length %u/%u\n", len
, full_len
);
447 str
.MaximumLength
= 0;
449 status
= pNtQuerySymbolicLinkObject( dir
, &str
, &len
);
450 ok( status
== STATUS_BUFFER_TOO_SMALL
, "NtQuerySymbolicLinkObject failed %08x\n", status
);
451 ok( len
== full_len
, "bad length %u/%u\n", len
, full_len
);
453 str
.MaximumLength
= str
.Length
+ sizeof(WCHAR
);
455 status
= pNtQuerySymbolicLinkObject( dir
, &str
, &len
);
456 ok( status
== STATUS_SUCCESS
, "NtQuerySymbolicLinkObject failed %08x\n", status
);
457 ok( len
== full_len
, "bad length %u/%u\n", len
, full_len
);
463 pRtlCreateUnicodeStringFromAsciiz(&str
, "\\BaseNamedObjects");
464 InitializeObjectAttributes(&attr
, &str
, 0, 0, NULL
);
465 DIR_TEST_OPEN_SUCCESS(&dir
)
466 pRtlFreeUnicodeString(&str
);
468 InitializeObjectAttributes(&attr
, NULL
, 0, dir
, NULL
);
469 DIR_TEST_OPEN_FAILURE(&h
, STATUS_OBJECT_NAME_INVALID
)
471 InitializeObjectAttributes(&attr
, &str
, 0, dir
, NULL
);
472 DIR_TEST_CREATE_OPEN_SUCCESS(h
, "")
473 DIR_TEST_CREATE_OPEN_FAILURE(&h
, "\\", STATUS_OBJECT_PATH_SYNTAX_BAD
)
474 DIR_TEST_CREATE_OPEN_FAILURE(&h
, "\\om.c-test", STATUS_OBJECT_PATH_SYNTAX_BAD
)
475 DIR_TEST_CREATE_OPEN_FAILURE(&h
, "\\om.c-test\\", STATUS_OBJECT_PATH_SYNTAX_BAD
)
476 DIR_TEST_CREATE_OPEN_FAILURE(&h
, "om.c-test\\", STATUS_OBJECT_PATH_NOT_FOUND
)
478 pRtlCreateUnicodeStringFromAsciiz(&str
, "om.c-test");
479 DIR_TEST_CREATE_SUCCESS(&dir1
)
480 DIR_TEST_OPEN_SUCCESS(&h
)
481 pRtlFreeUnicodeString(&str
);
487 /* Nested directories */
488 pRtlCreateUnicodeStringFromAsciiz(&str
, "\\");
489 InitializeObjectAttributes(&attr
, &str
, 0, 0, NULL
);
490 DIR_TEST_OPEN_SUCCESS(&dir
)
491 InitializeObjectAttributes(&attr
, &str
, 0, dir
, NULL
);
492 DIR_TEST_OPEN_FAILURE(&h
, STATUS_OBJECT_PATH_SYNTAX_BAD
)
493 pRtlFreeUnicodeString(&str
);
496 InitializeObjectAttributes(&attr
, &str
, 0, 0, NULL
);
497 pRtlCreateUnicodeStringFromAsciiz(&str
, "\\BaseNamedObjects\\om.c-test");
498 DIR_TEST_CREATE_SUCCESS(&dir
)
499 pRtlFreeUnicodeString(&str
);
500 pRtlCreateUnicodeStringFromAsciiz(&str
, "\\BaseNamedObjects\\om.c-test\\one more level");
501 DIR_TEST_CREATE_SUCCESS(&h
)
502 pRtlFreeUnicodeString(&str
);
504 InitializeObjectAttributes(&attr
, &str
, 0, dir
, NULL
);
505 pRtlCreateUnicodeStringFromAsciiz(&str
, "one more level");
506 DIR_TEST_CREATE_SUCCESS(&h
)
507 pRtlFreeUnicodeString(&str
);
514 InitializeObjectAttributes(&attr
, &str
, 0, 0, NULL
);
515 pRtlCreateUnicodeStringFromAsciiz(&str
, "\\BaseNamedObjects\\Global\\om.c-test");
516 DIR_TEST_CREATE_SUCCESS(&dir
)
517 pRtlFreeUnicodeString(&str
);
518 pRtlCreateUnicodeStringFromAsciiz(&str
, "\\BaseNamedObjects\\Local\\om.c-test\\one more level");
519 DIR_TEST_CREATE_SUCCESS(&h
)
520 pRtlFreeUnicodeString(&str
);
522 InitializeObjectAttributes(&attr
, &str
, 0, dir
, NULL
);
523 pRtlCreateUnicodeStringFromAsciiz(&str
, "one more level");
524 DIR_TEST_CREATE_SUCCESS(&dir
)
525 pRtlFreeUnicodeString(&str
);
530 /* Create other objects using RootDirectory */
532 InitializeObjectAttributes(&attr
, &str
, 0, 0, NULL
);
533 pRtlCreateUnicodeStringFromAsciiz(&str
, "\\BaseNamedObjects");
534 DIR_TEST_OPEN_SUCCESS(&dir
)
535 pRtlFreeUnicodeString(&str
);
536 InitializeObjectAttributes(&attr
, &str
, 0, dir
, NULL
);
538 /* Test invalid paths */
539 pRtlCreateUnicodeStringFromAsciiz(&str
, "\\om.c-mutant");
540 status
= pNtCreateMutant(&h
, GENERIC_ALL
, &attr
, FALSE
);
541 ok(status
== STATUS_OBJECT_PATH_SYNTAX_BAD
,
542 "NtCreateMutant should have failed with STATUS_OBJECT_PATH_SYNTAX_BAD got(%08x)\n", status
);
543 pRtlFreeUnicodeString(&str
);
544 pRtlCreateUnicodeStringFromAsciiz(&str
, "\\om.c-mutant\\");
545 status
= pNtCreateMutant(&h
, GENERIC_ALL
, &attr
, FALSE
);
546 ok(status
== STATUS_OBJECT_PATH_SYNTAX_BAD
,
547 "NtCreateMutant should have failed with STATUS_OBJECT_PATH_SYNTAX_BAD got(%08x)\n", status
);
548 pRtlFreeUnicodeString(&str
);
550 pRtlCreateUnicodeStringFromAsciiz(&str
, "om.c\\-mutant");
551 status
= pNtCreateMutant(&h
, GENERIC_ALL
, &attr
, FALSE
);
552 ok(status
== STATUS_OBJECT_PATH_NOT_FOUND
,
553 "NtCreateMutant should have failed with STATUS_OBJECT_PATH_NOT_FOUND got(%08x)\n", status
);
554 pRtlFreeUnicodeString(&str
);
556 pRtlCreateUnicodeStringFromAsciiz(&str
, "om.c-mutant");
557 status
= pNtCreateMutant(&h
, GENERIC_ALL
, &attr
, FALSE
);
558 ok(status
== STATUS_SUCCESS
, "Failed to create Mutant(%08x)\n", status
);
559 pRtlFreeUnicodeString(&str
);
565 #define SYMLNK_TEST_CREATE_OPEN_FAILURE2(h,n,t,e,e2) \
566 pRtlCreateUnicodeStringFromAsciiz(&str, n);\
567 pRtlCreateUnicodeStringFromAsciiz(&target, t);\
568 status = pNtCreateSymbolicLinkObject(h, SYMBOLIC_LINK_QUERY, &attr, &target);\
569 ok(status == e || status == e2, \
570 "NtCreateSymbolicLinkObject should have failed with %s or %s got(%08x)\n", #e, #e2, status);\
571 status = pNtOpenSymbolicLinkObject(h, SYMBOLIC_LINK_QUERY, &attr);\
572 ok(status == e || status == e2, \
573 "NtOpenSymbolicLinkObject should have failed with %s or %s got(%08x)\n", #e, #e2, status);\
574 pRtlFreeUnicodeString(&target);\
575 pRtlFreeUnicodeString(&str);
577 #define SYMLNK_TEST_CREATE_OPEN_FAILURE(h,n,t,e) SYMLNK_TEST_CREATE_OPEN_FAILURE2(h,n,t,e,e)
579 static void test_symboliclink(void)
582 UNICODE_STRING str
, target
;
583 OBJECT_ATTRIBUTES attr
;
585 IO_STATUS_BLOCK iosb
;
587 /* No name and/or no attributes */
588 InitializeObjectAttributes(&attr
, NULL
, 0, 0, NULL
);
589 SYMLNK_TEST_CREATE_OPEN_FAILURE2(NULL
, "", "", STATUS_ACCESS_VIOLATION
, STATUS_INVALID_PARAMETER
)
591 status
= pNtCreateSymbolicLinkObject(&h
, SYMBOLIC_LINK_QUERY
, NULL
, NULL
);
592 ok(status
== STATUS_ACCESS_VIOLATION
,
593 "NtCreateSymbolicLinkObject should have failed with STATUS_ACCESS_VIOLATION got(%08x)\n", status
);
594 status
= pNtOpenSymbolicLinkObject(&h
, SYMBOLIC_LINK_QUERY
, NULL
);
595 ok(status
== STATUS_INVALID_PARAMETER
,
596 "NtOpenSymbolicLinkObject should have failed with STATUS_INVALID_PARAMETER got(%08x)\n", status
);
599 pRtlCreateUnicodeStringFromAsciiz(&target
, "\\DosDevices");
600 status
= pNtCreateSymbolicLinkObject(&h
, SYMBOLIC_LINK_QUERY
, NULL
, &target
);
601 ok(status
== STATUS_SUCCESS
|| status
== STATUS_ACCESS_VIOLATION
, /* nt4 */
602 "NtCreateSymbolicLinkObject failed(%08x)\n", status
);
603 pRtlFreeUnicodeString(&target
);
604 if (!status
) pNtClose(h
);
606 InitializeObjectAttributes(&attr
, NULL
, 0, 0, NULL
);
607 status
= pNtCreateSymbolicLinkObject(&link
, SYMBOLIC_LINK_QUERY
, &attr
, &target
);
608 ok(status
== STATUS_INVALID_PARAMETER
||
609 broken(status
== STATUS_SUCCESS
), /* nt4 */
610 "NtCreateSymbolicLinkObject should have failed with STATUS_INVALID_PARAMETER got(%08x)\n", status
);
611 if (!status
) pNtClose(h
);
612 status
= pNtOpenSymbolicLinkObject(&h
, SYMBOLIC_LINK_QUERY
, &attr
);
613 ok(status
== STATUS_OBJECT_PATH_SYNTAX_BAD
,
614 "NtOpenSymbolicLinkObject should have failed with STATUS_OBJECT_PATH_SYNTAX_BAD got(%08x)\n", status
);
617 pRtlCreateUnicodeStringFromAsciiz(&target
, "anywhere");
618 InitializeObjectAttributes(&attr
, &str
, 0, 0, NULL
);
620 pRtlCreateUnicodeStringFromAsciiz(&str
, "");
621 status
= pNtCreateSymbolicLinkObject(&link
, SYMBOLIC_LINK_QUERY
, &attr
, &target
);
622 ok(status
== STATUS_SUCCESS
, "Failed to create SymbolicLink(%08x)\n", status
);
623 status
= pNtOpenSymbolicLinkObject(&h
, SYMBOLIC_LINK_QUERY
, &attr
);
624 ok(status
== STATUS_OBJECT_PATH_SYNTAX_BAD
,
625 "NtOpenSymbolicLinkObject should have failed with STATUS_OBJECT_PATH_SYNTAX_BAD got(%08x)\n", status
);
627 pRtlFreeUnicodeString(&str
);
629 pRtlCreateUnicodeStringFromAsciiz(&str
, "\\");
630 status
= pNtCreateSymbolicLinkObject(&h
, SYMBOLIC_LINK_QUERY
, &attr
, &target
);
631 todo_wine
ok(status
== STATUS_OBJECT_TYPE_MISMATCH
,
632 "NtCreateSymbolicLinkObject should have failed with STATUS_OBJECT_TYPE_MISMATCH got(%08x)\n", status
);
633 pRtlFreeUnicodeString(&str
);
634 pRtlFreeUnicodeString(&target
);
636 SYMLNK_TEST_CREATE_OPEN_FAILURE(&h
, "BaseNamedObjects", "->Somewhere", STATUS_OBJECT_PATH_SYNTAX_BAD
)
637 SYMLNK_TEST_CREATE_OPEN_FAILURE(&h
, "\\BaseNamedObjects\\", "->Somewhere", STATUS_OBJECT_NAME_INVALID
)
638 SYMLNK_TEST_CREATE_OPEN_FAILURE(&h
, "\\\\BaseNamedObjects", "->Somewhere", STATUS_OBJECT_NAME_INVALID
)
639 SYMLNK_TEST_CREATE_OPEN_FAILURE(&h
, "\\BaseNamedObjects\\\\om.c-test", "->Somewhere", STATUS_OBJECT_NAME_INVALID
)
640 SYMLNK_TEST_CREATE_OPEN_FAILURE2(&h
, "\\BaseNamedObjects\\om.c-test\\", "->Somewhere",
641 STATUS_OBJECT_NAME_INVALID
, STATUS_OBJECT_PATH_NOT_FOUND
)
645 if (!(dir
= get_base_dir()))
647 win_skip( "couldn't find the BaseNamedObjects dir\n" );
651 InitializeObjectAttributes(&attr
, &str
, 0, dir
, NULL
);
652 pRtlCreateUnicodeStringFromAsciiz(&str
, "test-link");
653 pRtlCreateUnicodeStringFromAsciiz(&target
, "\\DosDevices");
654 status
= pNtCreateSymbolicLinkObject(&link
, SYMBOLIC_LINK_QUERY
, &attr
, &target
);
655 ok(status
== STATUS_SUCCESS
, "Failed to create SymbolicLink(%08x)\n", status
);
656 pRtlFreeUnicodeString(&str
);
657 pRtlFreeUnicodeString(&target
);
659 pRtlCreateUnicodeStringFromAsciiz(&str
, "test-link\\NUL");
660 status
= pNtOpenFile(&h
, GENERIC_READ
, &attr
, &iosb
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OPEN
);
661 todo_wine
ok(status
== STATUS_SUCCESS
, "Failed to open NUL device(%08x)\n", status
);
662 pRtlFreeUnicodeString(&str
);
669 static void test_query_object(void)
671 static const WCHAR name
[] = {'\\','B','a','s','e','N','a','m','e','d','O','b','j','e','c','t','s',
672 '\\','t','e','s','t','_','e','v','e','n','t'};
673 static const WCHAR type_event
[] = {'E','v','e','n','t'};
674 static const WCHAR type_file
[] = {'F','i','l','e'};
678 ULONG len
, expected_len
;
682 handle
= CreateEventA( NULL
, FALSE
, FALSE
, "test_event" );
685 status
= pNtQueryObject( handle
, ObjectNameInformation
, buffer
, 0, &len
);
686 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "NtQueryObject failed %x\n", status
);
687 ok( len
>= sizeof(UNICODE_STRING
) + sizeof(name
) + sizeof(WCHAR
), "unexpected len %u\n", len
);
690 status
= pNtQueryObject( handle
, ObjectTypeInformation
, buffer
, 0, &len
);
691 todo_wine
ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "NtQueryObject failed %x\n", status
);
692 todo_wine
ok( len
>= sizeof(OBJECT_TYPE_INFORMATION
) + sizeof(type_event
) + sizeof(WCHAR
), "unexpected len %u\n", len
);
695 status
= pNtQueryObject( handle
, ObjectNameInformation
, buffer
, sizeof(UNICODE_STRING
), &len
);
696 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "NtQueryObject failed %x\n", status
);
697 ok( len
>= sizeof(UNICODE_STRING
) + sizeof(name
) + sizeof(WCHAR
), "unexpected len %u\n", len
);
700 status
= pNtQueryObject( handle
, ObjectTypeInformation
, buffer
, sizeof(OBJECT_TYPE_INFORMATION
), &len
);
701 todo_wine
ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "NtQueryObject failed %x\n", status
);
702 todo_wine
ok( len
>= sizeof(OBJECT_TYPE_INFORMATION
) + sizeof(type_event
) + sizeof(WCHAR
), "unexpected len %u\n", len
);
705 status
= pNtQueryObject( handle
, ObjectNameInformation
, buffer
, sizeof(buffer
), &len
);
706 ok( status
== STATUS_SUCCESS
, "NtQueryObject failed %x\n", status
);
707 ok( len
> sizeof(UNICODE_STRING
), "unexpected len %u\n", len
);
708 str
= (UNICODE_STRING
*)buffer
;
709 ok( sizeof(UNICODE_STRING
) + str
->Length
+ sizeof(WCHAR
) == len
, "unexpected len %u\n", len
);
710 ok( str
->Length
>= sizeof(name
), "unexpected len %u\n", str
->Length
);
711 /* there can be a \\Sessions prefix in the name */
712 ok( !memcmp( str
->Buffer
+ (str
->Length
- sizeof(name
)) / sizeof(WCHAR
), name
, sizeof(name
) ),
713 "wrong name %s\n", wine_dbgstr_w(str
->Buffer
) );
715 len
-= sizeof(WCHAR
);
716 status
= pNtQueryObject( handle
, ObjectNameInformation
, buffer
, len
, &len
);
717 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "NtQueryObject failed %x\n", status
);
718 ok( len
>= sizeof(UNICODE_STRING
) + sizeof(name
) + sizeof(WCHAR
), "unexpected len %u\n", len
);
721 memset( buffer
, 0, sizeof(buffer
) );
722 status
= pNtQueryObject( handle
, ObjectTypeInformation
, buffer
, sizeof(buffer
), &len
);
723 todo_wine
ok( status
== STATUS_SUCCESS
, "NtQueryObject failed %x\n", status
);
724 todo_wine
ok( len
> sizeof(OBJECT_TYPE_INFORMATION
), "unexpected len %u\n", len
);
725 str
= (UNICODE_STRING
*)buffer
;
726 todo_wine
ok( len
>= sizeof(OBJECT_TYPE_INFORMATION
) + str
->Length
+ sizeof(WCHAR
), "unexpected len %u\n", len
);
727 todo_wine
ok( str
->Buffer
&& !memcmp( str
->Buffer
, type_event
, sizeof(type_file
) ),
728 "wrong/bad type name %s (%p)\n", wine_dbgstr_w(str
->Buffer
), str
->Buffer
);
730 len
-= sizeof(WCHAR
);
731 status
= pNtQueryObject( handle
, ObjectTypeInformation
, buffer
, len
, &len
);
732 todo_wine
ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "NtQueryObject failed %x\n", status
);
733 todo_wine
ok( len
>= sizeof(OBJECT_TYPE_INFORMATION
) + sizeof(type_event
) + sizeof(WCHAR
), "unexpected len %u\n", len
);
737 handle
= CreateEventA( NULL
, FALSE
, FALSE
, NULL
);
739 status
= pNtQueryObject( handle
, ObjectNameInformation
, buffer
, sizeof(buffer
), &len
);
740 ok( status
== STATUS_SUCCESS
, "NtQueryObject failed %x\n", status
);
741 ok( len
== sizeof(UNICODE_STRING
), "unexpected len %u\n", len
);
742 str
= (UNICODE_STRING
*)buffer
;
743 ok( str
->Length
== 0, "unexpected len %u\n", len
);
744 ok( str
->Buffer
== NULL
, "unexpected ptr %p\n", str
->Buffer
);
747 GetWindowsDirectoryA( dir
, MAX_PATH
);
748 handle
= CreateFileA( dir
, GENERIC_READ
, FILE_SHARE_READ
| FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
,
749 FILE_FLAG_BACKUP_SEMANTICS
, 0 );
751 status
= pNtQueryObject( handle
, ObjectNameInformation
, buffer
, sizeof(buffer
), &len
);
752 ok( status
== STATUS_SUCCESS
, "NtQueryObject failed %x\n", status
);
753 ok( len
> sizeof(UNICODE_STRING
), "unexpected len %u\n", len
);
754 str
= (UNICODE_STRING
*)buffer
;
755 expected_len
= sizeof(UNICODE_STRING
) + str
->Length
+ sizeof(WCHAR
);
756 ok( len
== expected_len
|| broken(len
== expected_len
- sizeof(WCHAR
)), /* NT4 */
757 "unexpected len %u\n", len
);
758 trace( "got %s len %u\n", wine_dbgstr_w(str
->Buffer
), len
);
761 status
= pNtQueryObject( handle
, ObjectNameInformation
, buffer
, 0, &len
);
762 ok( status
== STATUS_INFO_LENGTH_MISMATCH
|| broken(status
== STATUS_INSUFFICIENT_RESOURCES
),
763 "NtQueryObject failed %x\n", status
);
764 ok( len
== expected_len
|| broken(!len
|| len
== sizeof(UNICODE_STRING
)),
765 "unexpected len %u\n", len
);
768 status
= pNtQueryObject( handle
, ObjectNameInformation
, buffer
, sizeof(UNICODE_STRING
), &len
);
769 ok( status
== STATUS_BUFFER_OVERFLOW
|| broken(status
== STATUS_INSUFFICIENT_RESOURCES
770 || status
== STATUS_INFO_LENGTH_MISMATCH
),
771 "NtQueryObject failed %x\n", status
);
772 ok( len
== expected_len
|| broken(!len
),
773 "unexpected len %u\n", len
);
776 memset( buffer
, 0, sizeof(buffer
) );
777 status
= pNtQueryObject( handle
, ObjectTypeInformation
, buffer
, sizeof(buffer
), &len
);
778 todo_wine
ok( status
== STATUS_SUCCESS
, "NtQueryObject failed %x\n", status
);
779 todo_wine
ok( len
> sizeof(OBJECT_TYPE_INFORMATION
), "unexpected len %u\n", len
);
780 str
= (UNICODE_STRING
*)buffer
;
781 expected_len
= sizeof(OBJECT_TYPE_INFORMATION
) + str
->Length
+ sizeof(WCHAR
);
782 todo_wine
ok( len
>= expected_len
, "unexpected len %u\n", len
);
783 todo_wine
ok( str
->Buffer
&& !memcmp( str
->Buffer
, type_file
, sizeof(type_file
) ),
784 "wrong/bad type name %s (%p)\n", wine_dbgstr_w(str
->Buffer
), str
->Buffer
);
789 static void test_type_mismatch(void)
793 OBJECT_ATTRIBUTES attr
;
795 attr
.Length
= sizeof(attr
);
796 attr
.RootDirectory
= 0;
797 attr
.ObjectName
= NULL
;
799 attr
.SecurityDescriptor
= NULL
;
800 attr
.SecurityQualityOfService
= NULL
;
802 res
= pNtCreateEvent( &h
, 0, &attr
, 0, 0 );
803 ok(!res
, "can't create event: %x\n", res
);
805 res
= pNtReleaseSemaphore( h
, 30, NULL
);
806 ok(res
== STATUS_OBJECT_TYPE_MISMATCH
, "expected 0xc0000024, got %x\n", res
);
811 static void test_event(void)
817 OBJECT_ATTRIBUTES attr
;
818 EVENT_BASIC_INFORMATION info
;
819 static const WCHAR eventName
[] = {'\\','B','a','s','e','N','a','m','e','d','O','b','j','e','c','t','s','\\','t','e','s','t','E','v','e','n','t',0};
821 pRtlInitUnicodeString(&str
, eventName
);
822 InitializeObjectAttributes(&attr
, &str
, 0, 0, NULL
);
824 status
= pNtCreateEvent(&Event
, GENERIC_ALL
, &attr
, 1, 0);
825 ok( status
== STATUS_SUCCESS
, "NtCreateEvent failed %08x\n", status
);
827 status
= pNtPulseEvent(Event
, NULL
);
828 ok( status
== STATUS_SUCCESS
, "NtPulseEvent failed %08x\n", status
);
830 status
= pNtQueryEvent(Event
, EventBasicInformation
, &info
, sizeof(info
), NULL
);
831 ok( status
== STATUS_SUCCESS
, "NtQueryEvent failed %08x\n", status
);
832 ok( info
.EventType
== 1 && info
.EventState
== 0,
833 "NtQueryEvent failed, expected 1 0, got %d %d\n", info
.EventType
, info
.EventState
);
835 status
= pNtOpenEvent(&Event2
, GENERIC_ALL
, &attr
);
836 ok( status
== STATUS_SUCCESS
, "NtOpenEvent failed %08x\n", status
);
840 status
= pNtQueryEvent(Event2
, EventBasicInformation
, &info
, sizeof(info
), NULL
);
841 ok( status
== STATUS_SUCCESS
, "NtQueryEvent failed %08x\n", status
);
842 ok( info
.EventType
== 1 && info
.EventState
== 0,
843 "NtQueryEvent failed, expected 1 0, got %d %d\n", info
.EventType
, info
.EventState
);
848 static const WCHAR keyed_nameW
[] = {'\\','B','a','s','e','N','a','m','e','d','O','b','j','e','c','t','s',
849 '\\','W','i','n','e','T','e','s','t','E','v','e','n','t',0};
851 static DWORD WINAPI
keyed_event_thread( void *arg
)
855 LARGE_INTEGER timeout
;
856 OBJECT_ATTRIBUTES attr
;
860 attr
.Length
= sizeof(attr
);
861 attr
.RootDirectory
= 0;
862 attr
.ObjectName
= &str
;
864 attr
.SecurityDescriptor
= NULL
;
865 attr
.SecurityQualityOfService
= NULL
;
866 RtlInitUnicodeString( &str
, keyed_nameW
);
868 status
= pNtOpenKeyedEvent( &handle
, KEYEDEVENT_ALL_ACCESS
, &attr
);
869 ok( !status
, "NtOpenKeyedEvent failed %x\n", status
);
871 for (i
= 0; i
< 20; i
++)
874 status
= pNtWaitForKeyedEvent( handle
, (void *)(i
* 2), 0, NULL
);
876 status
= pNtReleaseKeyedEvent( handle
, (void *)(i
* 2), 0, NULL
);
877 ok( status
== STATUS_SUCCESS
, "%li: failed %x\n", i
, status
);
881 status
= pNtReleaseKeyedEvent( handle
, (void *)0x1234, 0, NULL
);
882 ok( status
== STATUS_SUCCESS
, "NtReleaseKeyedEvent %x\n", status
);
884 timeout
.QuadPart
= -10000;
885 status
= pNtWaitForKeyedEvent( handle
, (void *)0x5678, 0, &timeout
);
886 ok( status
== STATUS_TIMEOUT
, "NtWaitForKeyedEvent %x\n", status
);
887 status
= pNtReleaseKeyedEvent( handle
, (void *)0x9abc, 0, &timeout
);
888 ok( status
== STATUS_TIMEOUT
, "NtReleaseKeyedEvent %x\n", status
);
894 static void test_keyed_events(void)
896 OBJECT_ATTRIBUTES attr
;
898 HANDLE handle
, event
, thread
;
900 LARGE_INTEGER timeout
;
903 if (!pNtCreateKeyedEvent
)
905 win_skip( "Keyed events not supported\n" );
909 attr
.Length
= sizeof(attr
);
910 attr
.RootDirectory
= 0;
911 attr
.ObjectName
= &str
;
913 attr
.SecurityDescriptor
= NULL
;
914 attr
.SecurityQualityOfService
= NULL
;
915 RtlInitUnicodeString( &str
, keyed_nameW
);
917 status
= pNtCreateKeyedEvent( &handle
, KEYEDEVENT_ALL_ACCESS
| SYNCHRONIZE
, &attr
, 0 );
918 ok( !status
, "NtCreateKeyedEvent failed %x\n", status
);
920 status
= WaitForSingleObject( handle
, 1000 );
921 ok( status
== 0, "WaitForSingleObject %x\n", status
);
923 timeout
.QuadPart
= -100000;
924 status
= pNtWaitForKeyedEvent( handle
, (void *)255, 0, &timeout
);
925 ok( status
== STATUS_INVALID_PARAMETER_1
, "NtWaitForKeyedEvent %x\n", status
);
926 status
= pNtReleaseKeyedEvent( handle
, (void *)255, 0, &timeout
);
927 ok( status
== STATUS_INVALID_PARAMETER_1
, "NtReleaseKeyedEvent %x\n", status
);
929 status
= pNtWaitForKeyedEvent( handle
, (void *)254, 0, &timeout
);
930 ok( status
== STATUS_TIMEOUT
, "NtWaitForKeyedEvent %x\n", status
);
931 status
= pNtReleaseKeyedEvent( handle
, (void *)254, 0, &timeout
);
932 ok( status
== STATUS_TIMEOUT
, "NtReleaseKeyedEvent %x\n", status
);
934 status
= pNtWaitForKeyedEvent( handle
, NULL
, 0, &timeout
);
935 ok( status
== STATUS_TIMEOUT
, "NtWaitForKeyedEvent %x\n", status
);
936 status
= pNtReleaseKeyedEvent( handle
, NULL
, 0, &timeout
);
937 ok( status
== STATUS_TIMEOUT
, "NtReleaseKeyedEvent %x\n", status
);
939 status
= pNtWaitForKeyedEvent( (HANDLE
)0xdeadbeef, (void *)9, 0, &timeout
);
940 ok( status
== STATUS_INVALID_PARAMETER_1
, "NtWaitForKeyedEvent %x\n", status
);
941 status
= pNtReleaseKeyedEvent( (HANDLE
)0xdeadbeef, (void *)9, 0, &timeout
);
942 ok( status
== STATUS_INVALID_PARAMETER_1
, "NtReleaseKeyedEvent %x\n", status
);
944 status
= pNtWaitForKeyedEvent( (HANDLE
)0xdeadbeef, (void *)8, 0, &timeout
);
945 ok( status
== STATUS_INVALID_HANDLE
, "NtWaitForKeyedEvent %x\n", status
);
946 status
= pNtReleaseKeyedEvent( (HANDLE
)0xdeadbeef, (void *)8, 0, &timeout
);
947 ok( status
== STATUS_INVALID_HANDLE
, "NtReleaseKeyedEvent %x\n", status
);
949 thread
= CreateThread( NULL
, 0, keyed_event_thread
, 0, 0, NULL
);
950 for (i
= 0; i
< 20; i
++)
953 status
= pNtReleaseKeyedEvent( handle
, (void *)(i
* 2), 0, NULL
);
955 status
= pNtWaitForKeyedEvent( handle
, (void *)(i
* 2), 0, NULL
);
956 ok( status
== STATUS_SUCCESS
, "%li: failed %x\n", i
, status
);
959 status
= pNtWaitForKeyedEvent( handle
, (void *)0x1234, 0, &timeout
);
960 ok( status
== STATUS_SUCCESS
, "NtWaitForKeyedEvent %x\n", status
);
961 status
= pNtWaitForKeyedEvent( handle
, (void *)0x5678, 0, &timeout
);
962 ok( status
== STATUS_TIMEOUT
, "NtWaitForKeyedEvent %x\n", status
);
963 status
= pNtReleaseKeyedEvent( handle
, (void *)0x9abc, 0, &timeout
);
964 ok( status
== STATUS_TIMEOUT
, "NtReleaseKeyedEvent %x\n", status
);
966 ok( WaitForSingleObject( thread
, 30000 ) == 0, "wait failed\n" );
970 /* test access rights */
972 status
= pNtCreateKeyedEvent( &handle
, KEYEDEVENT_WAIT
, &attr
, 0 );
973 ok( !status
, "NtCreateKeyedEvent failed %x\n", status
);
974 status
= pNtWaitForKeyedEvent( handle
, (void *)8, 0, &timeout
);
975 ok( status
== STATUS_TIMEOUT
, "NtWaitForKeyedEvent %x\n", status
);
976 status
= pNtReleaseKeyedEvent( handle
, (void *)8, 0, &timeout
);
977 ok( status
== STATUS_ACCESS_DENIED
, "NtReleaseKeyedEvent %x\n", status
);
980 status
= pNtCreateKeyedEvent( &handle
, KEYEDEVENT_WAKE
, &attr
, 0 );
981 ok( !status
, "NtCreateKeyedEvent failed %x\n", status
);
982 status
= pNtWaitForKeyedEvent( handle
, (void *)8, 0, &timeout
);
983 ok( status
== STATUS_ACCESS_DENIED
, "NtWaitForKeyedEvent %x\n", status
);
984 status
= pNtReleaseKeyedEvent( handle
, (void *)8, 0, &timeout
);
985 ok( status
== STATUS_TIMEOUT
, "NtReleaseKeyedEvent %x\n", status
);
988 status
= pNtCreateKeyedEvent( &handle
, KEYEDEVENT_ALL_ACCESS
, &attr
, 0 );
989 ok( !status
, "NtCreateKeyedEvent failed %x\n", status
);
990 status
= WaitForSingleObject( handle
, 1000 );
991 ok( status
== WAIT_FAILED
&& GetLastError() == ERROR_ACCESS_DENIED
,
992 "WaitForSingleObject %x err %u\n", status
, GetLastError() );
993 status
= pNtWaitForKeyedEvent( handle
, (void *)8, 0, &timeout
);
994 ok( status
== STATUS_TIMEOUT
, "NtWaitForKeyedEvent %x\n", status
);
995 status
= pNtReleaseKeyedEvent( handle
, (void *)8, 0, &timeout
);
996 ok( status
== STATUS_TIMEOUT
, "NtReleaseKeyedEvent %x\n", status
);
999 /* GENERIC_READ gives wait access */
1000 status
= pNtCreateKeyedEvent( &handle
, GENERIC_READ
, &attr
, 0 );
1001 ok( !status
, "NtCreateKeyedEvent failed %x\n", status
);
1002 status
= pNtWaitForKeyedEvent( handle
, (void *)8, 0, &timeout
);
1003 ok( status
== STATUS_TIMEOUT
, "NtWaitForKeyedEvent %x\n", status
);
1004 status
= pNtReleaseKeyedEvent( handle
, (void *)8, 0, &timeout
);
1005 ok( status
== STATUS_ACCESS_DENIED
, "NtReleaseKeyedEvent %x\n", status
);
1008 /* GENERIC_WRITE gives wake access */
1009 status
= pNtCreateKeyedEvent( &handle
, GENERIC_WRITE
, &attr
, 0 );
1010 ok( !status
, "NtCreateKeyedEvent failed %x\n", status
);
1011 status
= pNtWaitForKeyedEvent( handle
, (void *)8, 0, &timeout
);
1012 ok( status
== STATUS_ACCESS_DENIED
, "NtWaitForKeyedEvent %x\n", status
);
1013 status
= pNtReleaseKeyedEvent( handle
, (void *)8, 0, &timeout
);
1014 ok( status
== STATUS_TIMEOUT
, "NtReleaseKeyedEvent %x\n", status
);
1016 /* it's not an event */
1017 status
= pNtPulseEvent( handle
, NULL
);
1018 ok( status
== STATUS_OBJECT_TYPE_MISMATCH
, "NtPulseEvent %x\n", status
);
1020 status
= pNtCreateEvent( &event
, GENERIC_ALL
, &attr
, FALSE
, FALSE
);
1021 ok( status
== STATUS_OBJECT_NAME_COLLISION
|| status
== STATUS_OBJECT_TYPE_MISMATCH
,
1022 "CreateEvent %x\n", status
);
1026 status
= pNtCreateEvent( &event
, GENERIC_ALL
, &attr
, FALSE
, FALSE
);
1027 ok( status
== 0, "CreateEvent %x\n", status
);
1028 status
= pNtWaitForKeyedEvent( event
, (void *)8, 0, &timeout
);
1029 ok( status
== STATUS_OBJECT_TYPE_MISMATCH
, "NtWaitForKeyedEvent %x\n", status
);
1030 status
= pNtReleaseKeyedEvent( event
, (void *)8, 0, &timeout
);
1031 ok( status
== STATUS_OBJECT_TYPE_MISMATCH
, "NtReleaseKeyedEvent %x\n", status
);
1037 HMODULE hntdll
= GetModuleHandleA("ntdll.dll");
1038 HMODULE hkernel32
= GetModuleHandleA("kernel32.dll");
1042 skip("not running on NT, skipping test\n");
1046 pCreateWaitableTimerA
= (void *)GetProcAddress(hkernel32
, "CreateWaitableTimerA");
1048 pRtlCreateUnicodeStringFromAsciiz
= (void *)GetProcAddress(hntdll
, "RtlCreateUnicodeStringFromAsciiz");
1049 pRtlFreeUnicodeString
= (void *)GetProcAddress(hntdll
, "RtlFreeUnicodeString");
1050 pNtCreateEvent
= (void *)GetProcAddress(hntdll
, "NtCreateEvent");
1051 pNtCreateMutant
= (void *)GetProcAddress(hntdll
, "NtCreateMutant");
1052 pNtOpenEvent
= (void *)GetProcAddress(hntdll
, "NtOpenEvent");
1053 pNtQueryEvent
= (void *)GetProcAddress(hntdll
, "NtQueryEvent");
1054 pNtPulseEvent
= (void *)GetProcAddress(hntdll
, "NtPulseEvent");
1055 pNtOpenMutant
= (void *)GetProcAddress(hntdll
, "NtOpenMutant");
1056 pNtOpenFile
= (void *)GetProcAddress(hntdll
, "NtOpenFile");
1057 pNtClose
= (void *)GetProcAddress(hntdll
, "NtClose");
1058 pRtlInitUnicodeString
= (void *)GetProcAddress(hntdll
, "RtlInitUnicodeString");
1059 pNtCreateNamedPipeFile
= (void *)GetProcAddress(hntdll
, "NtCreateNamedPipeFile");
1060 pNtOpenDirectoryObject
= (void *)GetProcAddress(hntdll
, "NtOpenDirectoryObject");
1061 pNtCreateDirectoryObject
= (void *)GetProcAddress(hntdll
, "NtCreateDirectoryObject");
1062 pNtOpenSymbolicLinkObject
= (void *)GetProcAddress(hntdll
, "NtOpenSymbolicLinkObject");
1063 pNtCreateSymbolicLinkObject
= (void *)GetProcAddress(hntdll
, "NtCreateSymbolicLinkObject");
1064 pNtQuerySymbolicLinkObject
= (void *)GetProcAddress(hntdll
, "NtQuerySymbolicLinkObject");
1065 pNtCreateSemaphore
= (void *)GetProcAddress(hntdll
, "NtCreateSemaphore");
1066 pNtCreateTimer
= (void *)GetProcAddress(hntdll
, "NtCreateTimer");
1067 pNtCreateSection
= (void *)GetProcAddress(hntdll
, "NtCreateSection");
1068 pNtQueryObject
= (void *)GetProcAddress(hntdll
, "NtQueryObject");
1069 pNtReleaseSemaphore
= (void *)GetProcAddress(hntdll
, "NtReleaseSemaphore");
1070 pNtCreateKeyedEvent
= (void *)GetProcAddress(hntdll
, "NtCreateKeyedEvent");
1071 pNtOpenKeyedEvent
= (void *)GetProcAddress(hntdll
, "NtOpenKeyedEvent");
1072 pNtWaitForKeyedEvent
= (void *)GetProcAddress(hntdll
, "NtWaitForKeyedEvent");
1073 pNtReleaseKeyedEvent
= (void *)GetProcAddress(hntdll
, "NtReleaseKeyedEvent");
1075 test_case_sensitive();
1076 test_namespace_pipe();
1077 test_name_collisions();
1079 test_symboliclink();
1080 test_query_object();
1081 test_type_mismatch();
1083 test_keyed_events();