test_term_endpoint.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: MPL-2.0 */
2 
3 #include "testutil.hpp"
4 #include "testutil_unity.hpp"
5 
7 
8 /* Use the worst case filename size for the buffer (+1 for trailing NUL), this
9  * is larger than MAX_SOCKET_STRING, which is not large enough for IPC */
10 #define BUF_SIZE (FILENAME_MAX + 1)
11 
12 const char *ep_wc_tcp = "tcp://127.0.0.1:*";
13 #if !defined ZMQ_HAVE_WINDOWS && !defined ZMQ_HAVE_OPENVMS
14 const char *ep_wc_ipc = "ipc://*";
15 #endif
16 #if defined ZMQ_HAVE_VMCI
17 const char *ep_wc_vmci = "vmci://*:*";
18 #endif
19 
21 {
22  char my_endpoint[BUF_SIZE];
23 
24  // Create infrastructure.
27 
28  void *pull = test_context_socket (ZMQ_PULL);
30 
31  // Pass one message through to ensure the connection is established
32  send_string_expect_success (push, "ABC", 0);
33  recv_string_expect_success (pull, "ABC", 0);
34 
35  // Unbind the listening endpoint
37 
38  // Allow unbind to settle
40 
41  // Check that sending would block (there's no outbound connection)
43 
44  // Clean up
47 }
48 
50 {
51  // Create infrastructure
52  void *pull = test_context_socket (ZMQ_PULL);
53  char my_endpoint[BUF_SIZE];
55 
58 
59  // Pass one message through to ensure the connection is established.
60  send_string_expect_success (push, "ABC", 0);
61  recv_string_expect_success (pull, "ABC", 0);
62 
63  // Disconnect the bound endpoint
65 
66  // Allow disconnect to settle
68 
69  // Check that sending would block (there's no inbound connections).
71 
72  // Clean up
75 }
76 
78 {
79  // Create infrastructure (wild-card binding)
81  char my_endpoint[BUF_SIZE];
83 
84  void *pull = test_context_socket (ZMQ_PULL);
85 
86 #if !defined ZMQ_HAVE_WINDOWS && !defined ZMQ_HAVE_OPENVMS
88 #endif
89 #if defined ZMQ_HAVE_VMCI
91  int rc = zmq_bind (req, ep_wc_vmci);
92  if (rc < 0 && errno == EAFNOSUPPORT)
93  TEST_IGNORE_MESSAGE ("VMCI not supported");
95 #endif
96 
97  // Unbind sockets binded by wild-card address
99 
100  size_t buf_size = 0;
101  (void) buf_size;
102 
103 #if !defined ZMQ_HAVE_WINDOWS && !defined ZMQ_HAVE_OPENVMS
104  buf_size = sizeof (my_endpoint);
106  zmq_getsockopt (pull, ZMQ_LAST_ENDPOINT, my_endpoint, &buf_size));
108 #endif
109 #if defined ZMQ_HAVE_VMCI
110  buf_size = sizeof (my_endpoint);
114 #endif
115 
116  // Clean up
119 }
120 
122 {
123  // Create infrastructure (wild-card binding)
126  void *pull = test_context_socket (ZMQ_PULL);
127 #if !defined ZMQ_HAVE_WINDOWS && !defined ZMQ_HAVE_OPENVMS
129 #endif
130 #if defined ZMQ_HAVE_VMCI
131  void *req = test_context_socket (ZMQ_REQ);
132  int rc = zmq_bind (req, ep_wc_vmci);
133  if (rc < 0 && errno == EAFNOSUPPORT)
134  TEST_IGNORE_MESSAGE ("VMCI not supported");
136 #endif
137 
138  // Sockets binded by wild-card address can't be unbinded by wild-card address
140 #if !defined ZMQ_HAVE_WINDOWS && !defined ZMQ_HAVE_OPENVMS
142 #endif
143 #if defined ZMQ_HAVE_VMCI
144  TEST_ASSERT_FAILURE_ERRNO (ENOENT, zmq_unbind (req, ep_wc_vmci));
145 #endif
146 
147  // Clean up
150 }
151 
152 int main ()
153 {
155 
156  UNITY_BEGIN ();
161  return UNITY_END ();
162 }
BUF_SIZE
#define BUF_SIZE
Definition: test_term_endpoint.cpp:10
EAFNOSUPPORT
#define EAFNOSUPPORT
Definition: zmq.h:134
test_wildcard_unbind_fails
void test_wildcard_unbind_fails()
Definition: test_term_endpoint.cpp:121
main
int main()
Definition: test_term_endpoint.cpp:152
UNITY_END
return UNITY_END()
msleep
void msleep(int milliseconds_)
Definition: testutil.cpp:227
zmq_unbind
ZMQ_EXPORT int zmq_unbind(void *s_, const char *addr_)
Definition: zmq.cpp:337
EAGAIN
#define EAGAIN
Definition: errno.hpp:14
RUN_TEST
#define RUN_TEST(func)
Definition: unity_internals.h:615
ZMQ_LAST_ENDPOINT
#define ZMQ_LAST_ENDPOINT
Definition: zmq.h:298
SETUP_TEARDOWN_TESTCONTEXT
#define SETUP_TEARDOWN_TESTCONTEXT
Definition: testutil_unity.hpp:172
errno
int errno
bind_loopback_ipv4
void bind_loopback_ipv4(void *socket_, char *my_endpoint_, size_t len_)
Definition: testutil_unity.cpp:246
ep_wc_tcp
const char * ep_wc_tcp
Definition: test_term_endpoint.cpp:12
ZMQ_REQ
#define ZMQ_REQ
Definition: zmq.h:261
zmq_connect
ZMQ_EXPORT int zmq_connect(void *s_, const char *addr_)
Definition: zmq.cpp:307
test_send_after_disconnect_fails
void test_send_after_disconnect_fails()
Definition: test_term_endpoint.cpp:49
testutil_unity.hpp
zmq_disconnect
ZMQ_EXPORT int zmq_disconnect(void *s_, const char *addr_)
Definition: zmq.cpp:345
ZMQ_PUSH
#define ZMQ_PUSH
Definition: zmq.h:266
testutil.hpp
test_unbind_via_last_endpoint
void test_unbind_via_last_endpoint()
Definition: test_term_endpoint.cpp:77
my_endpoint
char my_endpoint[MAX_SOCKET_STRING]
Definition: test_security_curve.cpp:31
zmq_bind
ZMQ_EXPORT int zmq_bind(void *s_, const char *addr_)
Definition: zmq.cpp:299
test_context_socket
void * test_context_socket(int type_)
Definition: testutil_unity.cpp:200
ZMQ_DONTWAIT
#define ZMQ_DONTWAIT
Definition: zmq.h:358
SETTLE_TIME
#define SETTLE_TIME
Definition: libzmq/tests/testutil.hpp:31
void
typedef void(APIENTRY *GLDEBUGPROCARB)(GLenum source
TEST_IGNORE_MESSAGE
#define TEST_IGNORE_MESSAGE(message)
Definition: unity.h:103
send_string_expect_success
void send_string_expect_success(void *socket_, const char *str_, int flags_)
Definition: testutil_unity.cpp:94
req
void * req
Definition: test_req_relaxed.cpp:10
recv_string_expect_success
void recv_string_expect_success(void *socket_, const char *str_, int flags_)
Definition: testutil_unity.cpp:101
setup_test_environment
void setup_test_environment(int timeout_seconds_)
Definition: testutil.cpp:201
UNITY_BEGIN
UNITY_BEGIN()
push
static void push(tarjan *t, const upb_refcounted *r)
Definition: ruby/ext/google/protobuf_c/upb.c:5890
TEST_ASSERT_FAILURE_ERRNO
#define TEST_ASSERT_FAILURE_ERRNO(error_code, expr)
Definition: testutil_unity.hpp:95
zmq_send
ZMQ_EXPORT int zmq_send(void *s_, const void *buf_, size_t len_, int flags_)
Definition: zmq.cpp:377
ZMQ_PULL
#define ZMQ_PULL
Definition: zmq.h:265
test_send_after_unbind_fails
void test_send_after_unbind_fails()
Definition: test_term_endpoint.cpp:20
test_context_socket_close
void * test_context_socket_close(void *socket_)
Definition: testutil_unity.cpp:208
TEST_ASSERT_SUCCESS_ERRNO
#define TEST_ASSERT_SUCCESS_ERRNO(expr)
Definition: proxy_thr.cpp:47
ep_wc_ipc
const char * ep_wc_ipc
Definition: test_term_endpoint.cpp:14
zmq_getsockopt
ZMQ_EXPORT int zmq_getsockopt(void *s_, int option_, void *optval_, size_t *optvallen_)
Definition: zmq.cpp:261


libaditof
Author(s):
autogenerated on Wed May 21 2025 02:06:59