Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 137 lines (97 sloc) 3.431 kB
caf1a99 @mattstevens IPv6 support
mattstevens authored
1 /* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
2 *
3 * Permission is hereby granted, free of charge, to any person obtaining a copy
4 * of this software and associated documentation files (the "Software"), to
5 * deal in the Software without restriction, including without limitation the
6 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7 * sell copies of the Software, and to permit persons to whom the Software is
8 * furnished to do so, subject to the following conditions:
9 *
10 * The above copyright notice and this permission notice shall be included in
11 * all copies or substantial portions of the Software.
12 *
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19 * IN THE SOFTWARE.
20 */
21
ce8ff30 @ry src/ and include/ directories
ry authored
22 #include "uv.h"
caf1a99 @mattstevens IPv6 support
mattstevens authored
23 #include "task.h"
24 #include <stdio.h>
25 #include <stdlib.h>
26
27
afc9987 Add uv_pipe_bind tests
Igor Zinkovsky authored
28 #ifdef _WIN32
29 # define BAD_PIPENAME "bad-pipe"
30 #else
27999e8 @bnoordhuis test: update BAD_PIPENAME for Unices, check for UV_EACCESS
bnoordhuis authored
31 # define BAD_PIPENAME "/path/to/unix/socket/that/really/should/not/be/there"
afc9987 Add uv_pipe_bind tests
Igor Zinkovsky authored
32 #endif
33
34
caf1a99 @mattstevens IPv6 support
mattstevens authored
35 static int close_cb_called = 0;
36
37
38 static void close_cb(uv_handle_t* handle) {
39 ASSERT(handle != NULL);
40 close_cb_called++;
41 }
42
43
afc9987 Add uv_pipe_bind tests
Igor Zinkovsky authored
44 TEST_IMPL(pipe_bind_error_addrinuse) {
45 uv_pipe_t server1, server2;
caf1a99 @mattstevens IPv6 support
mattstevens authored
46 int r;
47
6921d2f @ry Add argument to uv_pipe_init for IPC, unix impl
ry authored
48 r = uv_pipe_init(uv_default_loop(), &server1, 0);
caf1a99 @mattstevens IPv6 support
mattstevens authored
49 ASSERT(r == 0);
afc9987 Add uv_pipe_bind tests
Igor Zinkovsky authored
50 r = uv_pipe_bind(&server1, TEST_PIPENAME);
caf1a99 @mattstevens IPv6 support
mattstevens authored
51 ASSERT(r == 0);
52
6921d2f @ry Add argument to uv_pipe_init for IPC, unix impl
ry authored
53 r = uv_pipe_init(uv_default_loop(), &server2, 0);
caf1a99 @mattstevens IPv6 support
mattstevens authored
54 ASSERT(r == 0);
afc9987 Add uv_pipe_bind tests
Igor Zinkovsky authored
55 r = uv_pipe_bind(&server2, TEST_PIPENAME);
3ee4d3f @bnoordhuis unix, windows: return error codes directly
bnoordhuis authored
56 ASSERT(r == UV_EADDRINUSE);
caf1a99 @mattstevens IPv6 support
mattstevens authored
57
e749722 merge uv_tcp_listen and uv_pipe_listen into uv_listen
Igor Zinkovsky authored
58 r = uv_listen((uv_stream_t*)&server1, SOMAXCONN, NULL);
caf1a99 @mattstevens IPv6 support
mattstevens authored
59 ASSERT(r == 0);
e749722 merge uv_tcp_listen and uv_pipe_listen into uv_listen
Igor Zinkovsky authored
60 r = uv_listen((uv_stream_t*)&server2, SOMAXCONN, NULL);
3ee4d3f @bnoordhuis unix, windows: return error codes directly
bnoordhuis authored
61 ASSERT(r == UV_EINVAL);
caf1a99 @mattstevens IPv6 support
mattstevens authored
62
63 uv_close((uv_handle_t*)&server1, close_cb);
64 uv_close((uv_handle_t*)&server2, close_cb);
65
4ba03dd @bnoordhuis unix, windows: rename uv_run2 to uv_run
bnoordhuis authored
66 uv_run(uv_default_loop(), UV_RUN_DEFAULT);
caf1a99 @mattstevens IPv6 support
mattstevens authored
67
68 ASSERT(close_cb_called == 2);
69
47eb034 @piscisaureus test: move loop cleanup code to the individual tests
piscisaureus authored
70 MAKE_VALGRIND_HAPPY();
caf1a99 @mattstevens IPv6 support
mattstevens authored
71 return 0;
72 }
73
74
afc9987 Add uv_pipe_bind tests
Igor Zinkovsky authored
75 TEST_IMPL(pipe_bind_error_addrnotavail) {
76 uv_pipe_t server;
caf1a99 @mattstevens IPv6 support
mattstevens authored
77 int r;
78
6921d2f @ry Add argument to uv_pipe_init for IPC, unix impl
ry authored
79 r = uv_pipe_init(uv_default_loop(), &server, 0);
caf1a99 @mattstevens IPv6 support
mattstevens authored
80 ASSERT(r == 0);
afc9987 Add uv_pipe_bind tests
Igor Zinkovsky authored
81
3ee4d3f @bnoordhuis unix, windows: return error codes directly
bnoordhuis authored
82 r = uv_pipe_bind(&server, BAD_PIPENAME);
83 ASSERT(r == UV_EACCES);
caf1a99 @mattstevens IPv6 support
mattstevens authored
84
85 uv_close((uv_handle_t*)&server, close_cb);
86
4ba03dd @bnoordhuis unix, windows: rename uv_run2 to uv_run
bnoordhuis authored
87 uv_run(uv_default_loop(), UV_RUN_DEFAULT);
caf1a99 @mattstevens IPv6 support
mattstevens authored
88
89 ASSERT(close_cb_called == 1);
90
47eb034 @piscisaureus test: move loop cleanup code to the individual tests
piscisaureus authored
91 MAKE_VALGRIND_HAPPY();
caf1a99 @mattstevens IPv6 support
mattstevens authored
92 return 0;
93 }
94
95
afc9987 Add uv_pipe_bind tests
Igor Zinkovsky authored
96 TEST_IMPL(pipe_bind_error_inval) {
97 uv_pipe_t server;
caf1a99 @mattstevens IPv6 support
mattstevens authored
98 int r;
99
6921d2f @ry Add argument to uv_pipe_init for IPC, unix impl
ry authored
100 r = uv_pipe_init(uv_default_loop(), &server, 0);
afc9987 Add uv_pipe_bind tests
Igor Zinkovsky authored
101 ASSERT(r == 0);
102 r = uv_pipe_bind(&server, TEST_PIPENAME);
caf1a99 @mattstevens IPv6 support
mattstevens authored
103 ASSERT(r == 0);
afc9987 Add uv_pipe_bind tests
Igor Zinkovsky authored
104 r = uv_pipe_bind(&server, TEST_PIPENAME_2);
3ee4d3f @bnoordhuis unix, windows: return error codes directly
bnoordhuis authored
105 ASSERT(r == UV_EINVAL);
caf1a99 @mattstevens IPv6 support
mattstevens authored
106
107 uv_close((uv_handle_t*)&server, close_cb);
108
4ba03dd @bnoordhuis unix, windows: rename uv_run2 to uv_run
bnoordhuis authored
109 uv_run(uv_default_loop(), UV_RUN_DEFAULT);
caf1a99 @mattstevens IPv6 support
mattstevens authored
110
111 ASSERT(close_cb_called == 1);
112
47eb034 @piscisaureus test: move loop cleanup code to the individual tests
piscisaureus authored
113 MAKE_VALGRIND_HAPPY();
caf1a99 @mattstevens IPv6 support
mattstevens authored
114 return 0;
115 }
116
117
afc9987 Add uv_pipe_bind tests
Igor Zinkovsky authored
118 TEST_IMPL(pipe_listen_without_bind) {
119 uv_pipe_t server;
caf1a99 @mattstevens IPv6 support
mattstevens authored
120 int r;
121
6921d2f @ry Add argument to uv_pipe_init for IPC, unix impl
ry authored
122 r = uv_pipe_init(uv_default_loop(), &server, 0);
caf1a99 @mattstevens IPv6 support
mattstevens authored
123 ASSERT(r == 0);
124
3ee4d3f @bnoordhuis unix, windows: return error codes directly
bnoordhuis authored
125 r = uv_listen((uv_stream_t*)&server, SOMAXCONN, NULL);
126 ASSERT(r == UV_EINVAL);
caf1a99 @mattstevens IPv6 support
mattstevens authored
127
128 uv_close((uv_handle_t*)&server, close_cb);
129
4ba03dd @bnoordhuis unix, windows: rename uv_run2 to uv_run
bnoordhuis authored
130 uv_run(uv_default_loop(), UV_RUN_DEFAULT);
caf1a99 @mattstevens IPv6 support
mattstevens authored
131
132 ASSERT(close_cb_called == 1);
133
47eb034 @piscisaureus test: move loop cleanup code to the individual tests
piscisaureus authored
134 MAKE_VALGRIND_HAPPY();
caf1a99 @mattstevens IPv6 support
mattstevens authored
135 return 0;
136 }
Something went wrong with that request. Please try again.