diff --git a/tests/test_conflate.cpp b/tests/test_conflate.cpp index 16281a43..dce3fb32 100644 --- a/tests/test_conflate.cpp +++ b/tests/test_conflate.cpp @@ -34,8 +34,6 @@ SETUP_TEARDOWN_TESTCONTEXT void test_conflate () { - const char *bind_to = "tcp://127.0.0.1:*"; - size_t len = MAX_SOCKET_STRING; char my_endpoint[MAX_SOCKET_STRING]; int rc; @@ -45,9 +43,7 @@ void test_conflate () int conflate = 1; TEST_ASSERT_SUCCESS_ERRNO ( zmq_setsockopt (s_in, ZMQ_CONFLATE, &conflate, sizeof (conflate))); - TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (s_in, bind_to)); - TEST_ASSERT_SUCCESS_ERRNO ( - zmq_getsockopt (s_in, ZMQ_LAST_ENDPOINT, my_endpoint, &len)); + bind_loopback_ipv4 (s_in, my_endpoint, sizeof my_endpoint); void *s_out = test_context_socket (ZMQ_PUSH); diff --git a/tests/test_ctx_options.cpp b/tests/test_ctx_options.cpp index 53fe35f5..e17f898c 100644 --- a/tests/test_ctx_options.cpp +++ b/tests/test_ctx_options.cpp @@ -168,13 +168,10 @@ void test_ctx_zero_copy () // Create a TCP socket pair using the context and test that messages can be // received. Note that inproc sockets cannot be used for this test. void *pull = zmq_socket (get_test_context (), ZMQ_PULL); - TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (pull, "tcp://127.0.0.1:*")); + char endpoint[MAX_SOCKET_STRING]; + bind_loopback_ipv4 (pull, endpoint, sizeof endpoint); void *push = zmq_socket (get_test_context (), ZMQ_PUSH); - size_t endpoint_len = MAX_SOCKET_STRING; - char endpoint[MAX_SOCKET_STRING]; - TEST_ASSERT_SUCCESS_ERRNO ( - zmq_getsockopt (pull, ZMQ_LAST_ENDPOINT, endpoint, &endpoint_len)); TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (push, endpoint)); const char *small_str = "abcd"; diff --git a/tests/test_hwm_pubsub.cpp b/tests/test_hwm_pubsub.cpp index c88a568f..25306607 100644 --- a/tests/test_hwm_pubsub.cpp +++ b/tests/test_hwm_pubsub.cpp @@ -40,14 +40,11 @@ SETUP_TEARDOWN_TESTCONTEXT int test_defaults (int send_hwm_, int msg_cnt_, const char *endpoint) { - size_t len = SOCKET_STRING_LEN; char pub_endpoint[SOCKET_STRING_LEN]; // Set up and bind XPUB socket void *pub_socket = test_context_socket (ZMQ_XPUB); - TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (pub_socket, endpoint)); - TEST_ASSERT_SUCCESS_ERRNO ( - zmq_getsockopt (pub_socket, ZMQ_LAST_ENDPOINT, pub_endpoint, &len)); + test_bind (pub_socket, endpoint, pub_endpoint, sizeof pub_endpoint); // Set up and connect SUB socket void *sub_socket = test_context_socket (ZMQ_SUB); diff --git a/tests/test_reconnect_ivl.cpp b/tests/test_reconnect_ivl.cpp index ca4f15ed..4e15795f 100644 --- a/tests/test_reconnect_ivl.cpp +++ b/tests/test_reconnect_ivl.cpp @@ -72,15 +72,12 @@ void test_reconnect_ivl_ipc (void) } #endif -void test_reconnect_ivl_tcp (const char *address_) +void test_reconnect_ivl_tcp (bind_function_t bind_function_) { - size_t len = MAX_SOCKET_STRING; char my_endpoint[MAX_SOCKET_STRING]; void *sb = test_context_socket (ZMQ_PAIR); - TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb, address_)); - TEST_ASSERT_SUCCESS_ERRNO ( - zmq_getsockopt (sb, ZMQ_LAST_ENDPOINT, my_endpoint, &len)); + bind_function_ (sb, my_endpoint, sizeof my_endpoint); test_reconnect_ivl_against_pair_socket (my_endpoint, sb); test_context_socket_close (sb); @@ -88,14 +85,14 @@ void test_reconnect_ivl_tcp (const char *address_) void test_reconnect_ivl_tcp_ipv4 () { - test_reconnect_ivl_tcp ("tcp://127.0.0.1:*"); + test_reconnect_ivl_tcp (bind_loopback_ipv4); } void test_reconnect_ivl_tcp_ipv6 () { if (is_ipv6_available ()) { zmq_ctx_set (get_test_context (), ZMQ_IPV6, 1); - test_reconnect_ivl_tcp ("tcp://[::1]:*"); + test_reconnect_ivl_tcp (bind_loopback_ipv6); } } diff --git a/tests/test_router_handover.cpp b/tests/test_router_handover.cpp index c43fc587..65cd82ed 100644 --- a/tests/test_router_handover.cpp +++ b/tests/test_router_handover.cpp @@ -34,14 +34,9 @@ SETUP_TEARDOWN_TESTCONTEXT void test_with_handover () { - size_t len = MAX_SOCKET_STRING; char my_endpoint[MAX_SOCKET_STRING]; void *router = test_context_socket (ZMQ_ROUTER); - - TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (router, "tcp://127.0.0.1:*")); - - TEST_ASSERT_SUCCESS_ERRNO ( - zmq_getsockopt (router, ZMQ_LAST_ENDPOINT, my_endpoint, &len)); + bind_loopback_ipv4 (router, my_endpoint, sizeof my_endpoint); // Enable the handover flag int handover = 1; diff --git a/tests/test_router_mandatory.cpp b/tests/test_router_mandatory.cpp index ec8b8314..021f6715 100644 --- a/tests/test_router_mandatory.cpp +++ b/tests/test_router_mandatory.cpp @@ -184,13 +184,9 @@ void test_get_peer_state_corner_cases () void test_basic () { - size_t len = MAX_SOCKET_STRING; char my_endpoint[MAX_SOCKET_STRING]; void *router = test_context_socket (ZMQ_ROUTER); - - TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (router, "tcp://127.0.0.1:*")); - TEST_ASSERT_SUCCESS_ERRNO ( - zmq_getsockopt (router, ZMQ_LAST_ENDPOINT, my_endpoint, &len)); + bind_loopback_ipv4 (router, my_endpoint, sizeof my_endpoint); // Send a message to an unknown peer with the default setting // This will not report any error diff --git a/tests/test_thread_safe.cpp b/tests/test_thread_safe.cpp index 99451dff..bbd2f0dc 100644 --- a/tests/test_thread_safe.cpp +++ b/tests/test_thread_safe.cpp @@ -43,13 +43,10 @@ void client_thread (void *client_) void test_thread_safe () { - size_t len = MAX_SOCKET_STRING; char my_endpoint[MAX_SOCKET_STRING]; void *server = test_context_socket (ZMQ_SERVER); - TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (server, "tcp://127.0.0.1:*")); - TEST_ASSERT_SUCCESS_ERRNO ( - zmq_getsockopt (server, ZMQ_LAST_ENDPOINT, my_endpoint, &len)); + bind_loopback_ipv4 (server, my_endpoint, sizeof my_endpoint); void *client = test_context_socket (ZMQ_CLIENT);