2 * Unit tests for named pipe functions in Wine
4 * Copyright (c) 2002 Dan Kegel
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include "wine/test.h"
29 #define START_TEST(name) main(int argc, char **argv)
30 #define ok(condition, msg) assert(condition)
38 #define PIPENAME "\\\\.\\PiPe\\tests_" __FILE__
40 void test_CreateNamedPipeA(void)
44 const char obuf[] = "Bit Bucket";
49 /* Bad parameter checks */
50 hnp = CreateNamedPipeA("not a named pipe",
51 PIPE_ACCESS_DUPLEX, PIPE_TYPE_BYTE|PIPE_WAIT,
52 /* nMaxInstances */ 1,
53 /* nOutBufSize */ 1024,
54 /* nInBufSize */ 1024,
55 /* nDefaultWait */ NMPWAIT_USE_DEFAULT_WAIT,
56 /* lpSecurityAttrib */ NULL);
58 if (hnp == INVALID_HANDLE_VALUE && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) {
59 /* Is this the right way to notify user of skipped tests? */
60 ok(hnp == INVALID_HANDLE_VALUE && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED,
61 "CreateNamedPipe not supported on this platform, skipping tests.");
64 ok(hnp == INVALID_HANDLE_VALUE && GetLastError() == ERROR_INVALID_NAME,
65 "CreateNamedPipe should fail if name doesn't start with \\\\.\\pipe");
67 hnp = CreateNamedPipeA(NULL,
68 PIPE_ACCESS_DUPLEX, PIPE_TYPE_BYTE|PIPE_WAIT,
69 1, 1024, 1024, NMPWAIT_USE_DEFAULT_WAIT, NULL);
70 ok(hnp == INVALID_HANDLE_VALUE && GetLastError() == ERROR_PATH_NOT_FOUND,
71 "CreateNamedPipe should fail if name is NULL");
73 /* Functional checks */
75 hnp = CreateNamedPipeA(PIPENAME,
76 PIPE_ACCESS_DUPLEX, PIPE_TYPE_BYTE|PIPE_WAIT,
77 /* nMaxInstances */ 1,
78 /* nOutBufSize */ 1024,
79 /* nInBufSize */ 1024,
80 /* nDefaultWait */ NMPWAIT_USE_DEFAULT_WAIT,
81 /* lpSecurityAttrib */ NULL);
82 ok(hnp != INVALID_HANDLE_VALUE, "CreateNamedPipe failed");
84 hFile = CreateFileA(PIPENAME, GENERIC_READ|GENERIC_WRITE, 0,
85 NULL, OPEN_EXISTING, 0, 0);
88 ok(hFile != INVALID_HANDLE_VALUE, "CreateFile failed");
91 /* don't try to do i/o if one side couldn't be opened, as it hangs */
92 if (hFile != INVALID_HANDLE_VALUE) {
93 /* Make sure we can read and write a few bytes in both directions*/
94 memset(ibuf, 0, sizeof(ibuf));
95 ok(WriteFile(hnp, obuf, sizeof(obuf), &written, NULL), "WriteFile");
96 ok(written == sizeof(obuf), "write file len");
97 ok(ReadFile(hFile, ibuf, sizeof(obuf), &gelesen, NULL), "ReadFile");
98 ok(gelesen == sizeof(obuf), "read file len");
99 ok(memcmp(obuf, ibuf, written) == 0, "content check");
101 memset(ibuf, 0, sizeof(ibuf));
102 ok(WriteFile(hFile, obuf, sizeof(obuf), &written, NULL), "WriteFile");
103 ok(written == sizeof(obuf), "write file len");
104 ok(ReadFile(hnp, ibuf, sizeof(obuf), &gelesen, NULL), "ReadFile");
105 ok(gelesen == sizeof(obuf), "read file len");
106 ok(memcmp(obuf, ibuf, written) == 0, "content check");
116 test_CreateNamedPipeA();