diff --git a/Makefile.am b/Makefile.am index 51dd3df5..944819c6 100644 --- a/Makefile.am +++ b/Makefile.am @@ -485,7 +485,8 @@ tests_test_msg_ffn_SOURCES = tests/test_msg_ffn.cpp tests_test_msg_ffn_LDADD = src/libzmq.la tests_test_connect_resolve_SOURCES = tests/test_connect_resolve.cpp -tests_test_connect_resolve_LDADD = src/libzmq.la +tests_test_connect_resolve_LDADD = src/libzmq.la ${UNITY_LIBS} +tests_test_connect_resolve_CPPFLAGS = ${UNITY_CPPFLAGS} tests_test_immediate_SOURCES = tests/test_immediate.cpp tests_test_immediate_LDADD = src/libzmq.la @@ -510,7 +511,8 @@ tests_test_router_mandatory_hwm_SOURCES = tests/test_router_mandatory_hwm.cpp tests_test_router_mandatory_hwm_LDADD = src/libzmq.la tests_test_router_handover_SOURCES = tests/test_router_handover.cpp -tests_test_router_handover_LDADD = src/libzmq.la +tests_test_router_handover_LDADD = src/libzmq.la ${UNITY_LIBS} +tests_test_router_handover_CPPFLAGS = ${UNITY_CPPFLAGS} tests_test_probe_router_SOURCES = tests/test_probe_router.cpp tests_test_probe_router_LDADD = src/libzmq.la @@ -579,7 +581,8 @@ tests_test_req_relaxed_SOURCES = tests/test_req_relaxed.cpp tests_test_req_relaxed_LDADD = src/libzmq.la tests_test_conflate_SOURCES = tests/test_conflate.cpp -tests_test_conflate_LDADD = src/libzmq.la +tests_test_conflate_LDADD = src/libzmq.la ${UNITY_LIBS} +tests_test_conflate_CPPFLAGS = ${UNITY_CPPFLAGS} tests_test_inproc_connect_SOURCES = tests/test_inproc_connect.cpp tests_test_inproc_connect_LDADD = src/libzmq.la @@ -609,7 +612,8 @@ tests_test_connect_rid_SOURCES = tests/test_connect_rid.cpp tests_test_connect_rid_LDADD = src/libzmq.la tests_test_bind_src_address_SOURCES = tests/test_bind_src_address.cpp -tests_test_bind_src_address_LDADD = src/libzmq.la +tests_test_bind_src_address_LDADD = src/libzmq.la ${UNITY_LIBS} +tests_test_bind_src_address_CPPFLAGS = ${UNITY_CPPFLAGS} tests_test_metadata_SOURCES = tests/test_metadata.cpp tests_test_metadata_LDADD = src/libzmq.la @@ -650,7 +654,8 @@ tests_test_pub_invert_matching_SOURCES = tests/test_pub_invert_matching.cpp tests_test_pub_invert_matching_LDADD = src/libzmq.la tests_test_bind_after_connect_tcp_SOURCES = tests/test_bind_after_connect_tcp.cpp -tests_test_bind_after_connect_tcp_LDADD = src/libzmq.la +tests_test_bind_after_connect_tcp_LDADD = src/libzmq.la ${UNITY_LIBS} +tests_test_bind_after_connect_tcp_CPPFLAGS = ${UNITY_CPPFLAGS} tests_test_base85_SOURCES = tests/test_base85.cpp tests_test_base85_LDADD = src/libzmq.la @@ -854,7 +859,8 @@ tests_test_poller_SOURCES = tests/test_poller.cpp tests_test_poller_LDADD = src/libzmq.la tests_test_client_server_SOURCES = tests/test_client_server.cpp -tests_test_client_server_LDADD = src/libzmq.la +tests_test_client_server_LDADD = src/libzmq.la ${UNITY_LIBS} +tests_test_client_server_CPPFLAGS = ${UNITY_CPPFLAGS} tests_test_thread_safe_SOURCES = tests/test_thread_safe.cpp tests_test_thread_safe_LDADD = src/libzmq.la diff --git a/tests/test_bind_after_connect_tcp.cpp b/tests/test_bind_after_connect_tcp.cpp index e7941823..ec02f8f9 100644 --- a/tests/test_bind_after_connect_tcp.cpp +++ b/tests/test_bind_after_connect_tcp.cpp @@ -28,70 +28,46 @@ */ #include "testutil.hpp" +#include "testutil_unity.hpp" + +#include + +void setUp () +{ + setup_test_context (); +} + +void tearDown () +{ + teardown_test_context (); +} + +void test_x () +{ + void *sb = test_context_socket (ZMQ_DEALER); + void *sc = test_context_socket (ZMQ_DEALER); + + TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sc, ENDPOINT_3)); + + send_string_expect_success (sc, "foobar", 0); + send_string_expect_success (sc, "baz", 0); + send_string_expect_success (sc, "buzz", 0); + + TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb, ENDPOINT_3)); + + recv_string_expect_success (sb, "foobar", 0); + recv_string_expect_success (sb, "baz", 0); + recv_string_expect_success (sb, "buzz", 0); + + test_context_socket_close (sc); + test_context_socket_close (sb); +} int main (void) { setup_test_environment (); - void *ctx = zmq_ctx_new (); - assert (ctx); - void *sb = zmq_socket (ctx, ZMQ_DEALER); - assert (sb); - - void *sc = zmq_socket (ctx, ZMQ_DEALER); - assert (sc); - - int rc = zmq_connect (sc, ENDPOINT_3); - assert (rc == 0); - - rc = zmq_send_const (sc, "foobar", 6, 0); - assert (rc == 6); - - rc = zmq_send_const (sc, "baz", 3, 0); - assert (rc == 3); - - rc = zmq_send_const (sc, "buzz", 4, 0); - assert (rc == 4); - - rc = zmq_bind (sb, ENDPOINT_3); - assert (rc == 0); - - zmq_msg_t msg; - rc = zmq_msg_init (&msg); - assert (rc == 0); - rc = zmq_msg_recv (&msg, sb, 0); - assert (rc == 6); - void *data = zmq_msg_data (&msg); - assert (memcmp ("foobar", data, 6) == 0); - rc = zmq_msg_close (&msg); - assert (rc == 0); - - rc = zmq_msg_init (&msg); - assert (rc == 0); - rc = zmq_msg_recv (&msg, sb, 0); - assert (rc == 3); - data = zmq_msg_data (&msg); - assert (memcmp ("baz", data, 3) == 0); - rc = zmq_msg_close (&msg); - assert (rc == 0); - - rc = zmq_msg_init (&msg); - assert (rc == 0); - rc = zmq_msg_recv (&msg, sb, 0); - assert (rc == 4); - data = zmq_msg_data (&msg); - assert (memcmp ("buzz", data, 4) == 0); - rc = zmq_msg_close (&msg); - assert (rc == 0); - - rc = zmq_close (sc); - assert (rc == 0); - - rc = zmq_close (sb); - assert (rc == 0); - - rc = zmq_ctx_term (ctx); - assert (rc == 0); - - return 0; + UNITY_BEGIN (); + RUN_TEST (test_x); + return UNITY_END (); } diff --git a/tests/test_bind_src_address.cpp b/tests/test_bind_src_address.cpp index 05fc7713..1221c3f8 100644 --- a/tests/test_bind_src_address.cpp +++ b/tests/test_bind_src_address.cpp @@ -28,30 +28,39 @@ */ #include "testutil.hpp" +#include "testutil_unity.hpp" + +#include + +void setUp () +{ + setup_test_context (); +} + +void tearDown () +{ + teardown_test_context (); +} + +void test_x () +{ + void *sock = test_context_socket (ZMQ_PUB); + + TEST_ASSERT_SUCCESS_ERRNO ( + zmq_connect (sock, "tcp://127.0.0.1:0;localhost:1234")); + TEST_ASSERT_SUCCESS_ERRNO ( + zmq_connect (sock, "tcp://localhost:5555;localhost:1235")); + TEST_ASSERT_SUCCESS_ERRNO ( + zmq_connect (sock, "tcp://lo:5555;localhost:1235")); + + test_context_socket_close (sock); +} int main (void) { setup_test_environment (); - void *ctx = zmq_ctx_new (); - assert (ctx); - void *sock = zmq_socket (ctx, ZMQ_PUB); - assert (sock); - - int rc = zmq_connect (sock, "tcp://127.0.0.1:0;localhost:1234"); - assert (rc == 0); - - rc = zmq_connect (sock, "tcp://localhost:5555;localhost:1235"); - assert (rc == 0); - - rc = zmq_connect (sock, "tcp://lo:5555;localhost:1235"); - assert (rc == 0); - - rc = zmq_close (sock); - assert (rc == 0); - - rc = zmq_ctx_term (ctx); - assert (rc == 0); - - return 0; + UNITY_BEGIN (); + RUN_TEST (test_x); + return UNITY_END (); } diff --git a/tests/test_client_server.cpp b/tests/test_client_server.cpp index 92085937..9b177630 100644 --- a/tests/test_client_server.cpp +++ b/tests/test_client_server.cpp @@ -28,79 +28,118 @@ */ #include "testutil.hpp" +#include "testutil_unity.hpp" + +#include + +void setUp () +{ + setup_test_context (); +} + +void tearDown () +{ + teardown_test_context (); +} + +void create_inproc_client_server_pair (void **server, void **client) +{ + *server = test_context_socket (ZMQ_SERVER); + *client = test_context_socket (ZMQ_CLIENT); + + TEST_ASSERT_SUCCESS_ERRNO ( + zmq_bind (*server, "inproc://test-client-server")); + TEST_ASSERT_SUCCESS_ERRNO ( + zmq_connect (*client, "inproc://test-client-server")); +} + +void send_sndmore_expect_failure (void *socket) +{ + int rc = zmq_send (socket, "X", 1, ZMQ_SNDMORE); + TEST_ASSERT_EQUAL_INT (-1, rc); + TEST_ASSERT_EQUAL_INT (EINVAL, errno); +} + +void test_client_sndmore_fails () +{ + void *server, *client; + create_inproc_client_server_pair (&server, &client); + + send_sndmore_expect_failure (client); + + test_context_socket_close (server); + test_context_socket_close (client); +} + +void test_server_sndmore_fails () +{ + void *server, *client; + create_inproc_client_server_pair (&server, &client); + + send_sndmore_expect_failure (server); + + test_context_socket_close (server); + test_context_socket_close (client); +} + +void test_routing_id () +{ + void *server, *client; + create_inproc_client_server_pair (&server, &client); + + send_string_expect_success (client, "X", 0); + + uint32_t routing_id; + { + zmq_msg_t msg; + TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_init (&msg)); + + int rc = TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_recv (&msg, server, 0)); + TEST_ASSERT_EQUAL_INT (1, rc); + + routing_id = zmq_msg_routing_id (&msg); + TEST_ASSERT_NOT_EQUAL (0, routing_id); + + TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_close (&msg)); + } + + { + zmq_msg_t msg; + TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_init_size (&msg, 1)); + + char *data = (char *) zmq_msg_data (&msg); + data[0] = 2; + + TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_set_routing_id (&msg, routing_id)); + + int rc = zmq_msg_send (&msg, server, 0); + TEST_ASSERT_EQUAL_INT (1, rc); + } + + { + zmq_msg_t msg; + TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_init (&msg)); + + int rc = zmq_msg_recv (&msg, client, 0); + TEST_ASSERT_EQUAL_INT (1, rc); + + routing_id = zmq_msg_routing_id (&msg); + TEST_ASSERT_EQUAL_UINT32 (0, routing_id); + + TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_close (&msg)); + } + + test_context_socket_close (server); + test_context_socket_close (client); +} int main (void) { setup_test_environment (); - void *ctx = zmq_ctx_new (); - assert (ctx); - void *server = zmq_socket (ctx, ZMQ_SERVER); - void *client = zmq_socket (ctx, ZMQ_CLIENT); - - int rc = zmq_bind (server, "inproc://test-client-server"); - assert (rc == 0); - - rc = zmq_connect (client, "inproc://test-client-server"); - assert (rc == 0); - - zmq_msg_t msg; - rc = zmq_msg_init_size (&msg, 1); - assert (rc == 0); - - char *data = (char *) zmq_msg_data (&msg); - data[0] = 1; - - rc = zmq_msg_send (&msg, client, ZMQ_SNDMORE); - assert (rc == -1); - - rc = zmq_msg_send (&msg, client, 0); - assert (rc == 1); - - rc = zmq_msg_init (&msg); - assert (rc == 0); - - rc = zmq_msg_recv (&msg, server, 0); - assert (rc == 1); - - uint32_t routing_id = zmq_msg_routing_id (&msg); - assert (routing_id != 0); - - rc = zmq_msg_close (&msg); - assert (rc == 0); - - rc = zmq_msg_init_size (&msg, 1); - assert (rc == 0); - - data = (char *) zmq_msg_data (&msg); - data[0] = 2; - - rc = zmq_msg_set_routing_id (&msg, routing_id); - assert (rc == 0); - - rc = zmq_msg_send (&msg, server, ZMQ_SNDMORE); - assert (rc == -1); - - rc = zmq_msg_send (&msg, server, 0); - assert (rc == 1); - - rc = zmq_msg_recv (&msg, client, 0); - assert (rc == 1); - - routing_id = zmq_msg_routing_id (&msg); - assert (routing_id == 0); - - rc = zmq_msg_close (&msg); - assert (rc == 0); - - rc = zmq_close (server); - assert (rc == 0); - - rc = zmq_close (client); - assert (rc == 0); - - rc = zmq_ctx_term (ctx); - assert (rc == 0); - - return 0; + UNITY_BEGIN (); + RUN_TEST (test_client_sndmore_fails); + RUN_TEST (test_server_sndmore_fails); + RUN_TEST (test_routing_id); + return UNITY_END (); } diff --git a/tests/test_conflate.cpp b/tests/test_conflate.cpp index 8d3d89e3..14730cdb 100644 --- a/tests/test_conflate.cpp +++ b/tests/test_conflate.cpp @@ -28,8 +28,21 @@ */ #include "testutil.hpp" +#include "testutil_unity.hpp" -int main (int, char *[]) +#include + +void setUp () +{ + setup_test_context (); +} + +void tearDown () +{ + teardown_test_context (); +} + +void test_x () { const char *bind_to = "tcp://127.0.0.1:*"; size_t len = MAX_SOCKET_STRING; @@ -37,50 +50,41 @@ int main (int, char *[]) int rc; - void *ctx = zmq_init (1); - assert (ctx); - - void *s_in = zmq_socket (ctx, ZMQ_PULL); - assert (s_in); + void *s_in = test_context_socket (ZMQ_PULL); int conflate = 1; - rc = zmq_setsockopt (s_in, ZMQ_CONFLATE, &conflate, sizeof (conflate)); - assert (rc == 0); + 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)); - rc = zmq_bind (s_in, bind_to); - assert (rc == 0); - rc = zmq_getsockopt (s_in, ZMQ_LAST_ENDPOINT, my_endpoint, &len); - assert (rc == 0); + void *s_out = test_context_socket (ZMQ_PUSH); - void *s_out = zmq_socket (ctx, ZMQ_PUSH); - assert (s_out); - - rc = zmq_connect (s_out, my_endpoint); - assert (rc == 0); + TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (s_out, my_endpoint)); int message_count = 20; for (int j = 0; j < message_count; ++j) { - rc = zmq_send (s_out, (void *) &j, sizeof (int), 0); - if (rc < 0) { - printf ("error in zmq_sendmsg: %s\n", zmq_strerror (errno)); - return -1; - } + TEST_ASSERT_SUCCESS_ERRNO ( + zmq_send (s_out, (void *) &j, sizeof (int), 0)); } msleep (SETTLE_TIME); int payload_recved = 0; - rc = zmq_recv (s_in, (void *) &payload_recved, sizeof (int), 0); - assert (rc > 0); - assert (payload_recved == message_count - 1); + rc = TEST_ASSERT_SUCCESS_ERRNO ( + zmq_recv (s_in, (void *) &payload_recved, sizeof (int), 0)); + TEST_ASSERT_GREATER_THAN_INT (0, rc); + TEST_ASSERT_EQUAL_INT (message_count - 1, payload_recved); - rc = zmq_close (s_in); - assert (rc == 0); - - rc = zmq_close (s_out); - assert (rc == 0); - - rc = zmq_ctx_term (ctx); - assert (rc == 0); - - return 0; + test_context_socket_close (s_in); + test_context_socket_close (s_out); +} + +int main (int, char *[]) +{ + setup_test_environment (); + + UNITY_BEGIN (); + RUN_TEST (test_x); + return UNITY_END (); } diff --git a/tests/test_connect_resolve.cpp b/tests/test_connect_resolve.cpp index 692dac77..b846ca39 100644 --- a/tests/test_connect_resolve.cpp +++ b/tests/test_connect_resolve.cpp @@ -29,42 +29,76 @@ #include "testutil.hpp" +#include "testutil_unity.hpp" + +#include + +void *sock; + +void setUp () +{ + setup_test_context (); + sock = test_context_socket (ZMQ_PUB); +} + +void tearDown () +{ + test_context_socket_close (sock); + sock = NULL; + teardown_test_context (); +} + +void test_hostname_ipv4 () +{ + TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sock, "tcp://localhost:1234")); +} + +void test_loopback_ipv6 () +{ + TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sock, "tcp://[::1]:1234")); +} + +void test_invalid_service_fails () +{ + int rc = zmq_connect (sock, "tcp://localhost:invalid"); + TEST_ASSERT_EQUAL_INT (-1, rc); +} + +void test_hostname_with_spaces_fails () +{ + int rc = zmq_connect (sock, "tcp://in val id:1234"); + TEST_ASSERT_EQUAL_INT (-1, rc); +} + +void test_no_hostname_fails () +{ + int rc = zmq_connect (sock, "tcp://"); + TEST_ASSERT_EQUAL_INT (-1, rc); +} + +void test_x () +{ + int rc = zmq_connect (sock, "tcp://192.168.0.200:*"); + TEST_ASSERT_EQUAL_INT (-1, rc); +} + +void test_invalid_proto_fails () +{ + int rc = zmq_connect (sock, "invalid://localhost:1234"); + TEST_ASSERT_EQUAL_INT (-1, rc); + TEST_ASSERT_EQUAL_INT (EPROTONOSUPPORT, errno); +} + int main (void) { setup_test_environment (); - void *ctx = zmq_ctx_new (); - assert (ctx); - void *sock = zmq_socket (ctx, ZMQ_PUB); - assert (sock); - - int rc = zmq_connect (sock, "tcp://localhost:1234"); - assert (rc == 0); - - rc = zmq_connect (sock, "tcp://[::1]:1234"); - assert (rc == 0); - - rc = zmq_connect (sock, "tcp://localhost:invalid"); - assert (rc == -1); - - rc = zmq_connect (sock, "tcp://in val id:1234"); - assert (rc == -1); - - rc = zmq_connect (sock, "tcp://"); - assert (rc == -1); - - rc = zmq_connect (sock, "tcp://192.168.0.200:*"); - assert (rc == -1); - - rc = zmq_connect (sock, "invalid://localhost:1234"); - assert (rc == -1); - assert (errno == EPROTONOSUPPORT); - - rc = zmq_close (sock); - assert (rc == 0); - - rc = zmq_ctx_term (ctx); - assert (rc == 0); - - return 0; + UNITY_BEGIN (); + RUN_TEST (test_hostname_ipv4); + RUN_TEST (test_loopback_ipv6); + RUN_TEST (test_hostname_with_spaces_fails); + RUN_TEST (test_no_hostname_fails); + RUN_TEST (test_invalid_service_fails); + RUN_TEST (test_invalid_proto_fails); + return UNITY_END (); } diff --git a/tests/test_router_handover.cpp b/tests/test_router_handover.cpp index 3916d3b5..4457731e 100644 --- a/tests/test_router_handover.cpp +++ b/tests/test_router_handover.cpp @@ -29,89 +29,84 @@ #include "testutil.hpp" -int main (void) +#include "testutil_unity.hpp" + +#include + +void setUp () +{ + setup_test_context (); +} + +void tearDown () +{ + teardown_test_context (); +} + +void test_x () { - setup_test_environment (); size_t len = MAX_SOCKET_STRING; char my_endpoint[MAX_SOCKET_STRING]; - void *ctx = zmq_ctx_new (); - assert (ctx); - void *router = zmq_socket (ctx, ZMQ_ROUTER); - assert (router); + void *router = test_context_socket (ZMQ_ROUTER); - int rc = zmq_bind (router, "tcp://127.0.0.1:*"); - assert (rc == 0); + TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (router, "tcp://127.0.0.1:*")); - rc = zmq_getsockopt (router, ZMQ_LAST_ENDPOINT, my_endpoint, &len); - assert (rc == 0); + TEST_ASSERT_SUCCESS_ERRNO ( + zmq_getsockopt (router, ZMQ_LAST_ENDPOINT, my_endpoint, &len)); // Enable the handover flag int handover = 1; - rc = zmq_setsockopt (router, ZMQ_ROUTER_HANDOVER, &handover, - sizeof (handover)); - assert (rc == 0); + TEST_ASSERT_SUCCESS_ERRNO (zmq_setsockopt (router, ZMQ_ROUTER_HANDOVER, + &handover, sizeof (handover))); // Create dealer called "X" and connect it to our router - void *dealer_one = zmq_socket (ctx, ZMQ_DEALER); - assert (dealer_one); - rc = zmq_setsockopt (dealer_one, ZMQ_ROUTING_ID, "X", 1); - assert (rc == 0); - rc = zmq_connect (dealer_one, my_endpoint); - assert (rc == 0); + void *dealer_one = test_context_socket (ZMQ_DEALER); + TEST_ASSERT_SUCCESS_ERRNO ( + zmq_setsockopt (dealer_one, ZMQ_ROUTING_ID, "X", 1)); + TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (dealer_one, my_endpoint)); // Get message from dealer to know when connection is ready char buffer[255]; - rc = zmq_send (dealer_one, "Hello", 5, 0); - assert (rc == 5); - rc = zmq_recv (router, buffer, 255, 0); - assert (rc == 1); - assert (buffer[0] == 'X'); - rc = zmq_recv (router, buffer, 255, 0); - assert (rc == 5); + send_string_expect_success (dealer_one, "Hello", 0); + + recv_string_expect_success (router, "X", 0); + recv_string_expect_success (router, "Hello", 0); // Now create a second dealer that uses the same routing id - void *dealer_two = zmq_socket (ctx, ZMQ_DEALER); - assert (dealer_two); - rc = zmq_setsockopt (dealer_two, ZMQ_ROUTING_ID, "X", 1); - assert (rc == 0); - rc = zmq_connect (dealer_two, my_endpoint); - assert (rc == 0); + void *dealer_two = test_context_socket (ZMQ_DEALER); + TEST_ASSERT_SUCCESS_ERRNO ( + zmq_setsockopt (dealer_two, ZMQ_ROUTING_ID, "X", 1)); + TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (dealer_two, my_endpoint)); // Get message from dealer to know when connection is ready - rc = zmq_send (dealer_two, "Hello", 5, 0); - assert (rc == 5); - rc = zmq_recv (router, buffer, 255, 0); - assert (rc == 1); - assert (buffer[0] == 'X'); - rc = zmq_recv (router, buffer, 255, 0); - assert (rc == 5); + send_string_expect_success (dealer_two, "Hello", 0); + + recv_string_expect_success (router, "X", 0); + recv_string_expect_success (router, "Hello", 0); // Send a message to 'X' routing id. This should be delivered // to the second dealer, instead of the first beccause of the handover. - rc = zmq_send (router, "X", 1, ZMQ_SNDMORE); - assert (rc == 1); - rc = zmq_send (router, "Hello", 5, 0); - assert (rc == 5); + send_string_expect_success (router, "X", ZMQ_SNDMORE); + send_string_expect_success (router, "Hello", 0); // Ensure that the first dealer doesn't receive the message // but the second one does - rc = zmq_recv (dealer_one, buffer, 255, ZMQ_NOBLOCK); - assert (rc == -1); + int rc = zmq_recv (dealer_one, buffer, 255, ZMQ_NOBLOCK); + TEST_ASSERT_EQUAL_INT (-1, rc); + TEST_ASSERT_EQUAL_INT (EAGAIN, errno); - rc = zmq_recv (dealer_two, buffer, 255, 0); - assert (rc == 5); + recv_string_expect_success (dealer_two, "Hello", 0); - rc = zmq_close (router); - assert (rc == 0); - - rc = zmq_close (dealer_one); - assert (rc == 0); - - rc = zmq_close (dealer_two); - assert (rc == 0); - - rc = zmq_ctx_term (ctx); - assert (rc == 0); - - return 0; + test_context_socket_close (router); + test_context_socket_close (dealer_one); + test_context_socket_close (dealer_two); +} + +int main (void) +{ + setup_test_environment (); + + UNITY_BEGIN (); + RUN_TEST (test_x); + return UNITY_END (); }