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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "ntdll_test.h"
28 static NTSTATUS (WINAPI *pRtlCreateUnicodeStringFromAsciiz)(PUNICODE_STRING, LPCSTR);
29 static VOID (WINAPI *pRtlInitUnicodeString)( PUNICODE_STRING, LPCWSTR );
30 static VOID (WINAPI *pRtlFreeUnicodeString)(PUNICODE_STRING);
31 static NTSTATUS (WINAPI *pNtCreateEvent) ( PHANDLE, ACCESS_MASK, const POBJECT_ATTRIBUTES, BOOLEAN, BOOLEAN);
32 static NTSTATUS (WINAPI *pNtCreateMutant)( PHANDLE, ACCESS_MASK, const POBJECT_ATTRIBUTES, BOOLEAN );
33 static NTSTATUS (WINAPI *pNtOpenMutant) ( PHANDLE, ACCESS_MASK, const POBJECT_ATTRIBUTES );
34 static NTSTATUS (WINAPI *pNtCreateSemaphore)( PHANDLE, ACCESS_MASK,const POBJECT_ATTRIBUTES,LONG,LONG );
35 static NTSTATUS (WINAPI *pNtCreateTimer) ( PHANDLE, ACCESS_MASK, const POBJECT_ATTRIBUTES, TIMER_TYPE );
36 static NTSTATUS (WINAPI *pNtCreateSection)( PHANDLE, ACCESS_MASK, const POBJECT_ATTRIBUTES, const PLARGE_INTEGER,
37 ULONG, ULONG, HANDLE );
38 static NTSTATUS (WINAPI *pNtOpenFile) ( PHANDLE, ACCESS_MASK, POBJECT_ATTRIBUTES, PIO_STATUS_BLOCK, ULONG, ULONG );
39 static NTSTATUS (WINAPI *pNtClose) ( HANDLE );
40 static NTSTATUS (WINAPI *pNtCreateNamedPipeFile)( PHANDLE, ULONG, POBJECT_ATTRIBUTES, PIO_STATUS_BLOCK,
41 ULONG, ULONG, ULONG, ULONG, ULONG, ULONG, ULONG, ULONG, ULONG, PLARGE_INTEGER );
42 static NTSTATUS (WINAPI *pNtOpenDirectoryObject)(PHANDLE, ACCESS_MASK, POBJECT_ATTRIBUTES);
43 static NTSTATUS (WINAPI *pNtCreateDirectoryObject)(PHANDLE, ACCESS_MASK, POBJECT_ATTRIBUTES);
44 static NTSTATUS (WINAPI *pNtOpenSymbolicLinkObject)(PHANDLE, ACCESS_MASK, POBJECT_ATTRIBUTES);
45 static NTSTATUS (WINAPI *pNtCreateSymbolicLinkObject)(PHANDLE, ACCESS_MASK, POBJECT_ATTRIBUTES, PUNICODE_STRING);
48 void test_case_sensitive (void)
50 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};
51 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};
52 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};
53 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};
55 OBJECT_ATTRIBUTES attr;
57 HANDLE Event, Mutant, h;
59 pRtlInitUnicodeString(&str, buffer1);
60 InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
61 status = pNtCreateMutant(&Mutant, GENERIC_ALL, &attr, FALSE);
62 ok(status == STATUS_SUCCESS, "Failed to create Mutant(%08lx)\n", status);
64 status = pNtCreateEvent(&Event, GENERIC_ALL, &attr, FALSE, FALSE);
65 ok(status == STATUS_OBJECT_NAME_COLLISION,
66 "NtCreateEvent should have failed with STATUS_OBJECT_NAME_COLLISION got(%08lx)\n", status);
68 pRtlInitUnicodeString(&str, buffer2);
69 InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
70 status = pNtCreateEvent(&Event, GENERIC_ALL, &attr, FALSE, FALSE);
71 ok(status == STATUS_SUCCESS, "Failed to create Event(%08lx)\n", status);
73 pRtlInitUnicodeString(&str, buffer3);
74 InitializeObjectAttributes(&attr, &str, OBJ_CASE_INSENSITIVE, 0, NULL);
75 status = pNtOpenMutant(&h, GENERIC_ALL, &attr);
76 ok(status == STATUS_OBJECT_TYPE_MISMATCH,
77 "NtOpenMutant should have failed with STATUS_OBJECT_TYPE_MISMATCH got(%08lx)\n", status);
81 pRtlInitUnicodeString(&str, buffer4);
82 InitializeObjectAttributes(&attr, &str, OBJ_CASE_INSENSITIVE, 0, NULL);
83 status = pNtCreateMutant(&Mutant, GENERIC_ALL, &attr, FALSE);
84 ok(status == STATUS_OBJECT_NAME_COLLISION,
85 "NtCreateMutant should have failed with STATUS_OBJECT_NAME_COLLISION got(%08lx)\n", status);
87 status = pNtCreateEvent(&h, GENERIC_ALL, &attr, FALSE, FALSE);
88 ok(status == STATUS_OBJECT_NAME_COLLISION,
89 "NtCreateEvent should have failed with STATUS_OBJECT_NAME_COLLISION got(%08lx)\n", status);
92 status = pNtCreateMutant(&Mutant, GENERIC_ALL, &attr, FALSE);
93 ok(status == STATUS_OBJECT_PATH_NOT_FOUND,
94 "NtCreateMutant should have failed with STATUS_OBJECT_PATH_NOT_FOUND got(%08lx)\n", status);
99 void test_namespace_pipe(void)
101 static const WCHAR buffer1[] = {'\\','?','?','\\','P','I','P','E','\\','t','e','s','t','\\','p','i','p','e',0};
102 static const WCHAR buffer2[] = {'\\','?','?','\\','P','I','P','E','\\','T','E','S','T','\\','P','I','P','E',0};
103 static const WCHAR buffer3[] = {'\\','?','?','\\','p','i','p','e','\\','t','e','s','t','\\','p','i','p','e',0};
104 static const WCHAR buffer4[] = {'\\','?','?','\\','p','i','p','e','\\','t','e','s','t',0};
105 OBJECT_ATTRIBUTES attr;
107 IO_STATUS_BLOCK iosb;
109 LARGE_INTEGER timeout;
112 timeout.QuadPart = -10000;
114 pRtlInitUnicodeString(&str, buffer1);
115 InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
116 status = pNtCreateNamedPipeFile(&pipe, GENERIC_READ|GENERIC_WRITE, &attr, &iosb, FILE_SHARE_READ|FILE_SHARE_WRITE,
117 FILE_CREATE, FILE_PIPE_FULL_DUPLEX, FALSE, FALSE, FALSE, 1, 256, 256, &timeout);
118 ok(status == STATUS_SUCCESS, "Failed to create NamedPipe(%08lx)\n", status);
120 status = pNtCreateNamedPipeFile(&pipe, GENERIC_READ|GENERIC_WRITE, &attr, &iosb, FILE_SHARE_READ|FILE_SHARE_WRITE,
121 FILE_CREATE, FILE_PIPE_FULL_DUPLEX, FALSE, FALSE, FALSE, 1, 256, 256, &timeout);
122 ok(status == STATUS_INSTANCE_NOT_AVAILABLE,
123 "NtCreateNamedPipeFile should have failed with STATUS_INSTANCE_NOT_AVAILABLE got(%08lx)\n", status);
125 pRtlInitUnicodeString(&str, buffer2);
126 InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
127 status = pNtCreateNamedPipeFile(&pipe, GENERIC_READ|GENERIC_WRITE, &attr, &iosb, FILE_SHARE_READ|FILE_SHARE_WRITE,
128 FILE_CREATE, FILE_PIPE_FULL_DUPLEX, FALSE, FALSE, FALSE, 1, 256, 256, &timeout);
129 ok(status == STATUS_INSTANCE_NOT_AVAILABLE,
130 "NtCreateNamedPipeFile should have failed with STATUS_INSTANCE_NOT_AVAILABLE got(%08lx)\n", status);
132 attr.Attributes = OBJ_CASE_INSENSITIVE;
133 status = pNtOpenFile(&h, GENERIC_READ, &attr, &iosb, FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN);
134 ok(status == STATUS_SUCCESS, "Failed to open NamedPipe(%08lx)\n", status);
137 pRtlInitUnicodeString(&str, buffer3);
138 InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
139 status = pNtOpenFile(&h, GENERIC_READ, &attr, &iosb, FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN);
140 ok(status == STATUS_OBJECT_PATH_NOT_FOUND || status == STATUS_PIPE_NOT_AVAILABLE,
141 "pNtOpenFile should have failed with STATUS_OBJECT_PATH_NOT_FOUND got(%08lx)\n", status);
143 pRtlInitUnicodeString(&str, buffer4);
144 InitializeObjectAttributes(&attr, &str, OBJ_CASE_INSENSITIVE, 0, NULL);
145 status = pNtOpenFile(&h, GENERIC_READ, &attr, &iosb, FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN);
146 ok(status == STATUS_OBJECT_NAME_NOT_FOUND,
147 "pNtOpenFile should have failed with STATUS_OBJECT_NAME_NOT_FOUND got(%08lx)\n", status);
152 #define DIRECTORY_QUERY (0x0001)
153 #define SYMBOLIC_LINK_QUERY 0x0001
155 #define DIR_TEST_CREATE_FAILURE(h,e) \
156 status = pNtCreateDirectoryObject(h, DIRECTORY_QUERY, &attr);\
157 ok(status == e,"NtCreateDirectoryObject should have failed with %s got(%08lx)\n", #e, status);
158 #define DIR_TEST_OPEN_FAILURE(h,e) \
159 status = pNtOpenDirectoryObject(h, DIRECTORY_QUERY, &attr);\
160 ok(status == e,"NtOpenDirectoryObject should have failed with %s got(%08lx)\n", #e, status);
161 #define DIR_TEST_CREATE_OPEN_FAILURE(h,n,e) \
162 pRtlCreateUnicodeStringFromAsciiz(&str, n);\
163 DIR_TEST_CREATE_FAILURE(h,e) DIR_TEST_OPEN_FAILURE(h,e)\
164 pRtlFreeUnicodeString(&str);
166 #define DIR_TEST_CREATE_SUCCESS(h) \
167 status = pNtCreateDirectoryObject(h, DIRECTORY_QUERY, &attr); \
168 ok(status == STATUS_SUCCESS, "Failed to create Directory(%08lx)\n", status);
169 #define DIR_TEST_OPEN_SUCCESS(h) \
170 status = pNtOpenDirectoryObject(h, DIRECTORY_QUERY, &attr); \
171 ok(status == STATUS_SUCCESS, "Failed to open Directory(%08lx)\n", status);
172 #define DIR_TEST_CREATE_OPEN_SUCCESS(h,n) \
173 pRtlCreateUnicodeStringFromAsciiz(&str, n);\
174 DIR_TEST_CREATE_SUCCESS(h) pNtClose(h); DIR_TEST_OPEN_SUCCESS(h) pNtClose(h); \
175 pRtlFreeUnicodeString(&str);
177 static void test_name_collisions(void)
181 OBJECT_ATTRIBUTES attr;
182 HANDLE dir, h, h1, h2;
186 InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
187 pRtlCreateUnicodeStringFromAsciiz(&str, "\\");
188 DIR_TEST_CREATE_FAILURE(&h, STATUS_OBJECT_NAME_COLLISION)
189 InitializeObjectAttributes(&attr, &str, OBJ_OPENIF, 0, NULL);
191 DIR_TEST_CREATE_FAILURE(&h, STATUS_OBJECT_NAME_EXISTS)
193 status = pNtCreateMutant(&h, GENERIC_ALL, &attr, FALSE);
194 ok(status == STATUS_OBJECT_TYPE_MISMATCH,
195 "NtCreateMutant should have failed with STATUS_OBJECT_TYPE_MISMATCH got(%08lx)\n", status);
196 pRtlFreeUnicodeString(&str);
198 pRtlCreateUnicodeStringFromAsciiz(&str, "\\??\\PIPE\\om.c-mutant");
199 status = pNtCreateMutant(&h, GENERIC_ALL, &attr, FALSE);
200 ok(status == STATUS_OBJECT_TYPE_MISMATCH || status == STATUS_OBJECT_PATH_NOT_FOUND,
201 "NtCreateMutant should have failed with STATUS_OBJECT_TYPE_MISMATCH got(%08lx)\n", status);
202 pRtlFreeUnicodeString(&str);
205 pRtlCreateUnicodeStringFromAsciiz(&str, "\\BaseNamedObjects");
206 DIR_TEST_OPEN_SUCCESS(&dir)
207 pRtlCreateUnicodeStringFromAsciiz(&str, "om.c-test");
208 InitializeObjectAttributes(&attr, &str, OBJ_OPENIF, dir, NULL);
210 h = CreateMutexA(NULL, FALSE, "om.c-test");
211 ok(h != 0, "CreateMutexA failed got ret=%p (%ld)\n", h, GetLastError());
212 status = pNtCreateMutant(&h1, GENERIC_ALL, &attr, FALSE);
213 ok(status == STATUS_OBJECT_NAME_EXISTS && h1 != NULL,
214 "NtCreateMutant should have succeeded with STATUS_OBJECT_NAME_EXISTS got(%08lx)\n", status);
215 h2 = CreateMutexA(NULL, FALSE, "om.c-test");
216 winerr = GetLastError();
217 ok(h2 != 0 && winerr == ERROR_ALREADY_EXISTS,
218 "CreateMutexA should have succeeded with ERROR_ALREADY_EXISTS got ret=%p (%ld)\n", h2, winerr);
223 h = CreateEventA(NULL, FALSE, FALSE, "om.c-test");
224 ok(h != 0, "CreateEventA failed got ret=%p (%ld)\n", h, GetLastError());
225 status = pNtCreateEvent(&h1, GENERIC_ALL, &attr, FALSE, FALSE);
226 ok(status == STATUS_OBJECT_NAME_EXISTS && h1 != NULL,
227 "NtCreateEvent should have succeeded with STATUS_OBJECT_NAME_EXISTS got(%08lx)\n", status);
228 h2 = CreateEventA(NULL, FALSE, FALSE, "om.c-test");
229 winerr = GetLastError();
230 ok(h2 != 0 && winerr == ERROR_ALREADY_EXISTS,
231 "CreateEventA should have succeeded with ERROR_ALREADY_EXISTS got ret=%p (%ld)\n", h2, winerr);
236 h = CreateSemaphoreA(NULL, 1, 2, "om.c-test");
237 ok(h != 0, "CreateSemaphoreA failed got ret=%p (%ld)\n", h, GetLastError());
238 status = pNtCreateSemaphore(&h1, GENERIC_ALL, &attr, 1, 2);
239 ok(status == STATUS_OBJECT_NAME_EXISTS && h1 != NULL,
240 "NtCreateSemaphore should have succeeded with STATUS_OBJECT_NAME_EXISTS got(%08lx)\n", status);
241 h2 = CreateSemaphoreA(NULL, 1, 2, "om.c-test");
242 winerr = GetLastError();
243 ok(h2 != 0 && winerr == ERROR_ALREADY_EXISTS,
244 "CreateSemaphoreA should have succeeded with ERROR_ALREADY_EXISTS got ret=%p (%ld)\n", h2, winerr);
249 h = CreateWaitableTimerA(NULL, TRUE, "om.c-test");
250 ok(h != 0, "CreateWaitableTimerA failed got ret=%p (%ld)\n", h, GetLastError());
251 status = pNtCreateTimer(&h1, GENERIC_ALL, &attr, NotificationTimer);
252 ok(status == STATUS_OBJECT_NAME_EXISTS && h1 != NULL,
253 "NtCreateTimer should have succeeded with STATUS_OBJECT_NAME_EXISTS got(%08lx)\n", status);
254 h2 = CreateWaitableTimerA(NULL, TRUE, "om.c-test");
255 winerr = GetLastError();
256 ok(h2 != 0 && winerr == ERROR_ALREADY_EXISTS,
257 "CreateWaitableTimerA should have succeeded with ERROR_ALREADY_EXISTS got ret=%p (%ld)\n", h2, winerr);
262 h = CreateFileMappingA(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, 256, "om.c-test");
263 ok(h != 0, "CreateFileMappingA failed got ret=%p (%ld)\n", h, GetLastError());
264 size.u.LowPart = 256;
266 status = pNtCreateSection(&h1, SECTION_MAP_WRITE, &attr, &size, PAGE_READWRITE, SEC_COMMIT, 0);
267 ok(status == STATUS_OBJECT_NAME_EXISTS && h1 != NULL,
268 "NtCreateSection should have succeeded with STATUS_OBJECT_NAME_EXISTS got(%08lx)\n", status);
269 h2 = CreateFileMappingA(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, 256, "om.c-test");
270 winerr = GetLastError();
271 ok(h2 != 0 && winerr == ERROR_ALREADY_EXISTS,
272 "CreateFileMappingA should have succeeded with ERROR_ALREADY_EXISTS got ret=%p (%ld)\n", h2, winerr);
277 pRtlFreeUnicodeString(&str);
281 void test_directory(void)
285 OBJECT_ATTRIBUTES attr;
288 /* No name and/or no attributes */
289 status = pNtCreateDirectoryObject(NULL, DIRECTORY_QUERY, &attr);
290 ok(status == STATUS_ACCESS_VIOLATION,
291 "NtCreateDirectoryObject should have failed with STATUS_ACCESS_VIOLATION got(%08lx)\n", status);
292 status = pNtOpenDirectoryObject(NULL, DIRECTORY_QUERY, &attr);
293 ok(status == STATUS_ACCESS_VIOLATION,
294 "NtOpenDirectoryObject should have failed with STATUS_ACCESS_VIOLATION got(%08lx)\n", status);
296 status = pNtCreateDirectoryObject(&h, DIRECTORY_QUERY, NULL);
297 ok(status == STATUS_SUCCESS, "Failed to create Directory without attributes(%08lx)\n", status);
299 status = pNtOpenDirectoryObject(&h, DIRECTORY_QUERY, NULL);
300 ok(status == STATUS_INVALID_PARAMETER,
301 "NtOpenDirectoryObject should have failed with STATUS_INVALID_PARAMETER got(%08lx)\n", status);
303 InitializeObjectAttributes(&attr, NULL, 0, 0, NULL);
304 DIR_TEST_CREATE_SUCCESS(&dir)
305 DIR_TEST_OPEN_FAILURE(&h, STATUS_OBJECT_PATH_SYNTAX_BAD)
308 InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
310 pRtlCreateUnicodeStringFromAsciiz(&str, "");
311 DIR_TEST_CREATE_SUCCESS(&h)
313 DIR_TEST_OPEN_FAILURE(&h, STATUS_OBJECT_PATH_SYNTAX_BAD)
314 pRtlFreeUnicodeString(&str);
317 DIR_TEST_CREATE_OPEN_FAILURE(&h, "BaseNamedObjects", STATUS_OBJECT_PATH_SYNTAX_BAD)
318 DIR_TEST_CREATE_OPEN_FAILURE(&h, "\\BaseNamedObjects\\", STATUS_OBJECT_NAME_INVALID)
319 DIR_TEST_CREATE_OPEN_FAILURE(&h, "\\\\BaseNamedObjects", STATUS_OBJECT_NAME_INVALID)
320 DIR_TEST_CREATE_OPEN_FAILURE(&h, "\\BaseNamedObjects\\\\om.c-test", STATUS_OBJECT_NAME_INVALID)
321 DIR_TEST_CREATE_OPEN_FAILURE(&h, "\\BaseNamedObjects\\om.c-test\\", STATUS_OBJECT_PATH_NOT_FOUND)
323 pRtlCreateUnicodeStringFromAsciiz(&str, "\\BaseNamedObjects\\om.c-test");
324 DIR_TEST_CREATE_SUCCESS(&h)
325 DIR_TEST_OPEN_SUCCESS(&dir1)
326 pRtlFreeUnicodeString(&str);
331 /* Use of root directory */
333 /* Can't use symlinks as a directory */
334 pRtlCreateUnicodeStringFromAsciiz(&str, "\\BaseNamedObjects\\Local");
335 InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
336 status = pNtOpenSymbolicLinkObject(&dir, SYMBOLIC_LINK_QUERY, &attr);\
337 ok(status == STATUS_SUCCESS, "Failed to open SymbolicLink(%08lx)\n", status);
338 pRtlFreeUnicodeString(&str);
339 InitializeObjectAttributes(&attr, &str, 0, dir, NULL);
340 pRtlCreateUnicodeStringFromAsciiz(&str, "one more level");
341 DIR_TEST_CREATE_FAILURE(&h, STATUS_OBJECT_TYPE_MISMATCH)
342 pRtlFreeUnicodeString(&str);
346 pRtlCreateUnicodeStringFromAsciiz(&str, "\\BaseNamedObjects");
347 InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
348 DIR_TEST_OPEN_SUCCESS(&dir)
349 pRtlFreeUnicodeString(&str);
351 InitializeObjectAttributes(&attr, NULL, 0, dir, NULL);
352 DIR_TEST_OPEN_FAILURE(&h, STATUS_OBJECT_NAME_INVALID)
354 InitializeObjectAttributes(&attr, &str, 0, dir, NULL);
355 DIR_TEST_CREATE_OPEN_SUCCESS(&h, "")
356 DIR_TEST_CREATE_OPEN_FAILURE(&h, "\\", STATUS_OBJECT_PATH_SYNTAX_BAD)
357 DIR_TEST_CREATE_OPEN_FAILURE(&h, "\\om.c-test", STATUS_OBJECT_PATH_SYNTAX_BAD)
358 DIR_TEST_CREATE_OPEN_FAILURE(&h, "\\om.c-test\\", STATUS_OBJECT_PATH_SYNTAX_BAD)
359 DIR_TEST_CREATE_OPEN_FAILURE(&h, "om.c-test\\", STATUS_OBJECT_PATH_NOT_FOUND)
361 pRtlCreateUnicodeStringFromAsciiz(&str, "om.c-test");
362 DIR_TEST_CREATE_SUCCESS(&dir1)
363 DIR_TEST_OPEN_SUCCESS(&h)
364 pRtlFreeUnicodeString(&str);
370 /* Nested directories */
371 pRtlCreateUnicodeStringFromAsciiz(&str, "\\");
372 InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
373 DIR_TEST_OPEN_SUCCESS(&dir)
374 InitializeObjectAttributes(&attr, &str, 0, dir, NULL);
375 DIR_TEST_OPEN_FAILURE(&h, STATUS_OBJECT_PATH_SYNTAX_BAD)
376 pRtlFreeUnicodeString(&str);
379 InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
380 pRtlCreateUnicodeStringFromAsciiz(&str, "\\BaseNamedObjects\\om.c-test");
381 DIR_TEST_CREATE_SUCCESS(&dir)
382 pRtlFreeUnicodeString(&str);
383 pRtlCreateUnicodeStringFromAsciiz(&str, "\\BaseNamedObjects\\om.c-test\\one more level");
384 DIR_TEST_CREATE_SUCCESS(&h)
385 pRtlFreeUnicodeString(&str);
387 InitializeObjectAttributes(&attr, &str, 0, dir, NULL);
388 pRtlCreateUnicodeStringFromAsciiz(&str, "one more level");
389 DIR_TEST_CREATE_SUCCESS(&h)
390 pRtlFreeUnicodeString(&str);
395 InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
396 pRtlCreateUnicodeStringFromAsciiz(&str, "\\BaseNamedObjects\\Global\\om.c-test");
397 DIR_TEST_CREATE_SUCCESS(&dir)
398 pRtlFreeUnicodeString(&str);
399 pRtlCreateUnicodeStringFromAsciiz(&str, "\\BaseNamedObjects\\Local\\om.c-test\\one more level");
400 DIR_TEST_CREATE_SUCCESS(&h)
401 pRtlFreeUnicodeString(&str);
403 InitializeObjectAttributes(&attr, &str, 0, dir, NULL);
404 pRtlCreateUnicodeStringFromAsciiz(&str, "one more level");
405 DIR_TEST_CREATE_SUCCESS(&dir)
406 pRtlFreeUnicodeString(&str);
412 /* Create other objects using RootDirectory */
414 InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
415 pRtlCreateUnicodeStringFromAsciiz(&str, "\\BaseNamedObjects");
416 DIR_TEST_OPEN_SUCCESS(&dir)
417 pRtlFreeUnicodeString(&str);
418 InitializeObjectAttributes(&attr, &str, 0, dir, NULL);
420 /* Test inavalid paths */
421 pRtlCreateUnicodeStringFromAsciiz(&str, "\\om.c-mutant");
422 status = pNtCreateMutant(&h, GENERIC_ALL, &attr, FALSE);
423 ok(status == STATUS_OBJECT_PATH_SYNTAX_BAD,
424 "NtCreateMutant should have failed with STATUS_OBJECT_PATH_SYNTAX_BAD got(%08lx)\n", status);
425 pRtlFreeUnicodeString(&str);
426 pRtlCreateUnicodeStringFromAsciiz(&str, "\\om.c-mutant\\");
427 status = pNtCreateMutant(&h, GENERIC_ALL, &attr, FALSE);
428 ok(status == STATUS_OBJECT_PATH_SYNTAX_BAD,
429 "NtCreateMutant should have failed with STATUS_OBJECT_PATH_SYNTAX_BAD got(%08lx)\n", status);
430 pRtlFreeUnicodeString(&str);
432 pRtlCreateUnicodeStringFromAsciiz(&str, "om.c\\-mutant");
433 status = pNtCreateMutant(&h, GENERIC_ALL, &attr, FALSE);
434 ok(status == STATUS_OBJECT_PATH_NOT_FOUND,
435 "NtCreateMutant should have failed with STATUS_OBJECT_PATH_NOT_FOUND got(%08lx)\n", status);
436 pRtlFreeUnicodeString(&str);
438 pRtlCreateUnicodeStringFromAsciiz(&str, "om.c-mutant");
439 status = pNtCreateMutant(&h, GENERIC_ALL, &attr, FALSE);
440 ok(status == STATUS_SUCCESS, "Failed to create Mutant(%08lx)\n", status);
441 pRtlFreeUnicodeString(&str);
447 #define SYMLNK_TEST_CREATE_FAILURE(h,e) \
448 status = pNtCreateSymbolicLinkObject(h, SYMBOLIC_LINK_QUERY, &attr, &target);\
449 ok(status == e,"NtCreateSymbolicLinkObject should have failed with %s got(%08lx)\n", #e, status);
450 #define SYMLNK_TEST_OPEN_FAILURE(h,e) \
451 status = pNtOpenSymbolicLinkObject(h, SYMBOLIC_LINK_QUERY, &attr);\
452 ok(status == e,"NtOpenSymbolicLinkObject should have failed with %s got(%08lx)\n", #e, status);
453 #define SYMLNK_TEST_CREATE_OPEN_FAILURE(h,n,t,e) \
454 pRtlCreateUnicodeStringFromAsciiz(&str, n);\
455 pRtlCreateUnicodeStringFromAsciiz(&target, t);\
456 SYMLNK_TEST_CREATE_FAILURE(h,e)\
457 SYMLNK_TEST_OPEN_FAILURE(h,e)\
458 pRtlFreeUnicodeString(&target);\
459 pRtlFreeUnicodeString(&str);
461 #define SYMLNK_TEST_CREATE_SUCCESS(h) \
462 status = pNtCreateSymbolicLinkObject(h, SYMBOLIC_LINK_QUERY, &attr, &target); \
463 ok(status == STATUS_SUCCESS, "Failed to create SymbolicLink(%08lx)\n", status);
464 #define SYMLNK_TEST_OPEN_SUCCESS(h) \
465 status = pNtOpenSymbolicLinkObject(h, SYMBOLIC_LINK_QUERY, &attr); \
466 ok(status == STATUS_SUCCESS, "Failed to open SymbolicLink(%08lx)\n", status);
468 void test_symboliclink(void)
471 UNICODE_STRING str, target;
472 OBJECT_ATTRIBUTES attr;
474 IO_STATUS_BLOCK iosb;
476 /* No name and/or no attributes */
477 SYMLNK_TEST_CREATE_OPEN_FAILURE(NULL, "", "", STATUS_ACCESS_VIOLATION)
479 status = pNtCreateSymbolicLinkObject(&h, SYMBOLIC_LINK_QUERY, NULL, NULL);
480 ok(status == STATUS_ACCESS_VIOLATION,
481 "NtCreateSymbolicLinkObject should have failed with STATUS_ACCESS_VIOLATION got(%08lx)\n", status);
482 status = pNtOpenSymbolicLinkObject(&h, SYMBOLIC_LINK_QUERY, NULL);
483 ok(status == STATUS_INVALID_PARAMETER,
484 "NtOpenSymbolicLinkObject should have failed with STATUS_INVALID_PARAMETER got(%08lx)\n", status);
486 InitializeObjectAttributes(&attr, NULL, 0, 0, NULL);
487 SYMLNK_TEST_CREATE_FAILURE(&link, STATUS_INVALID_PARAMETER)
488 SYMLNK_TEST_OPEN_FAILURE(&h, STATUS_OBJECT_PATH_SYNTAX_BAD)
491 pRtlCreateUnicodeStringFromAsciiz(&target, "anywhere");
492 InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
494 pRtlCreateUnicodeStringFromAsciiz(&str, "");
495 SYMLNK_TEST_CREATE_SUCCESS(&link)
496 SYMLNK_TEST_OPEN_FAILURE(&h, STATUS_OBJECT_PATH_SYNTAX_BAD)
498 pRtlFreeUnicodeString(&str);
500 pRtlCreateUnicodeStringFromAsciiz(&str, "\\");
501 todo_wine {SYMLNK_TEST_CREATE_FAILURE(&h, STATUS_OBJECT_TYPE_MISMATCH)}
502 pRtlFreeUnicodeString(&str);
503 pRtlFreeUnicodeString(&target);
505 SYMLNK_TEST_CREATE_OPEN_FAILURE(&h, "BaseNamedObjects", "->Somewhere", STATUS_OBJECT_PATH_SYNTAX_BAD)
506 SYMLNK_TEST_CREATE_OPEN_FAILURE(&h, "\\BaseNamedObjects\\", "->Somewhere", STATUS_OBJECT_NAME_INVALID)
507 SYMLNK_TEST_CREATE_OPEN_FAILURE(&h, "\\\\BaseNamedObjects", "->Somewhere", STATUS_OBJECT_NAME_INVALID)
508 SYMLNK_TEST_CREATE_OPEN_FAILURE(&h, "\\BaseNamedObjects\\\\om.c-test", "->Somewhere", STATUS_OBJECT_NAME_INVALID)
509 SYMLNK_TEST_CREATE_OPEN_FAILURE(&h, "\\BaseNamedObjects\\om.c-test\\", "->Somewhere", STATUS_OBJECT_NAME_INVALID)
513 pRtlCreateUnicodeStringFromAsciiz(&str, "\\BaseNamedObjects");
514 DIR_TEST_OPEN_SUCCESS(&dir)
515 pRtlFreeUnicodeString(&str);
517 InitializeObjectAttributes(&attr, &str, 0, dir, NULL);
518 pRtlCreateUnicodeStringFromAsciiz(&str, "Local\\test-link");
519 pRtlCreateUnicodeStringFromAsciiz(&target, "\\DosDevices");
520 SYMLNK_TEST_CREATE_SUCCESS(&link)
521 pRtlFreeUnicodeString(&str);
522 pRtlFreeUnicodeString(&target);
524 pRtlCreateUnicodeStringFromAsciiz(&str, "Local\\test-link\\PIPE");
525 status = pNtOpenFile(&h, GENERIC_READ, &attr, &iosb, FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN);
526 todo_wine ok(status == STATUS_SUCCESS, "Failed to open NamedPipe(%08lx)\n", status);
527 pRtlFreeUnicodeString(&str);
536 HMODULE hntdll = GetModuleHandleA("ntdll.dll");
539 pRtlCreateUnicodeStringFromAsciiz = (void *)GetProcAddress(hntdll, "RtlCreateUnicodeStringFromAsciiz");
540 pRtlFreeUnicodeString = (void *)GetProcAddress(hntdll, "RtlFreeUnicodeString");
541 pNtCreateEvent = (void *)GetProcAddress(hntdll, "NtCreateEvent");
542 pNtCreateMutant = (void *)GetProcAddress(hntdll, "NtCreateMutant");
543 pNtOpenMutant = (void *)GetProcAddress(hntdll, "NtOpenMutant");
544 pNtOpenFile = (void *)GetProcAddress(hntdll, "NtOpenFile");
545 pNtClose = (void *)GetProcAddress(hntdll, "NtClose");
546 pRtlInitUnicodeString = (void *)GetProcAddress(hntdll, "RtlInitUnicodeString");
547 pNtCreateNamedPipeFile = (void *)GetProcAddress(hntdll, "NtCreateNamedPipeFile");
548 pNtOpenDirectoryObject = (void *)GetProcAddress(hntdll, "NtOpenDirectoryObject");
549 pNtCreateDirectoryObject= (void *)GetProcAddress(hntdll, "NtCreateDirectoryObject");
550 pNtOpenSymbolicLinkObject = (void *)GetProcAddress(hntdll, "NtOpenSymbolicLinkObject");
551 pNtCreateSymbolicLinkObject = (void *)GetProcAddress(hntdll, "NtCreateSymbolicLinkObject");
552 pNtCreateSemaphore = (void *)GetProcAddress(hntdll, "NtCreateSemaphore");
553 pNtCreateTimer = (void *)GetProcAddress(hntdll, "NtCreateTimer");
554 pNtCreateSection = (void *)GetProcAddress(hntdll, "NtCreateSection");
556 test_case_sensitive();
557 test_namespace_pipe();
558 test_name_collisions();