diff --git a/tests/test_pair_tcp.cpp b/tests/test_pair_tcp.cpp index 61e52f6d..2b16ffb3 100644 --- a/tests/test_pair_tcp.cpp +++ b/tests/test_pair_tcp.cpp @@ -80,6 +80,36 @@ void test_pair_tcp_regular () test_pair_tcp (); } +void test_pair_tcp_connect_by_name () +{ + // all other tcp test cases bind to a loopback wildcard address, then + // retrieve the bound endpoint, which is numerical, and use that to + // connect. this test cases specifically uses "localhost" to connect + // to ensure that names are correctly resolved + void *sb = test_context_socket (ZMQ_PAIR); + + char bound_endpoint[MAX_SOCKET_STRING]; + bind_loopback_ipv4 (sb, bound_endpoint, sizeof bound_endpoint); + + // extract the bound port number + const char *pos = strrchr (bound_endpoint, ':'); + TEST_ASSERT_NOT_NULL (pos); + const char connect_endpoint_prefix[] = "tcp://localhost"; + char connect_endpoint[MAX_SOCKET_STRING]; + strcpy (connect_endpoint, connect_endpoint_prefix); + strcat (connect_endpoint, pos); + + void *sc = test_context_socket (ZMQ_PAIR); + + TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sc, connect_endpoint)); + + bounce (sb, sc); + + test_context_socket_close (sc); + test_context_socket_close (sb); +} + + #ifdef ZMQ_BUILD_DRAFT void test_pair_tcp_fastpath () { @@ -93,6 +123,7 @@ int main () UNITY_BEGIN (); RUN_TEST (test_pair_tcp_regular); + RUN_TEST (test_pair_tcp_connect_by_name); #ifdef ZMQ_BUILD_DRAFT RUN_TEST (test_pair_tcp_fastpath); #endif