From 631de94563f26fef7b958989535b973bc0f89988 Mon Sep 17 00:00:00 2001 From: Simon Giesecke Date: Wed, 14 Mar 2018 15:09:13 +0100 Subject: [PATCH 1/8] Problem: test_router_hangover not yet using unity Solution: migrate to unity --- tests/test_router_handover.cpp | 115 ++++++++++++++++----------------- 1 file changed, 55 insertions(+), 60 deletions(-) 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 (); } From be33dce68e31df5ac61fa55704efb48378001e8e Mon Sep 17 00:00:00 2001 From: Simon Giesecke Date: Wed, 14 Mar 2018 18:45:25 +0100 Subject: [PATCH 2/8] Migrate tests/test_bind_after_connect_tcp.cpp to unity --- tests/test_bind_after_connect_tcp.cpp | 98 ++++++++++----------------- 1 file changed, 37 insertions(+), 61 deletions(-) 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 (); } From 0114572ce6d238a145f6b4d0cdfbee62c1b274ec Mon Sep 17 00:00:00 2001 From: Simon Giesecke Date: Wed, 14 Mar 2018 18:45:25 +0100 Subject: [PATCH 3/8] Migrate tests/test_bind_src_address.cpp to unity --- tests/test_bind_src_address.cpp | 51 +++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 21 deletions(-) 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 (); } From dbcd42c58d23d06e4e10c302810c570d157e7c12 Mon Sep 17 00:00:00 2001 From: Simon Giesecke Date: Wed, 14 Mar 2018 18:45:26 +0100 Subject: [PATCH 4/8] Migrate tests/test_client_server.cpp to unity --- tests/test_client_server.cpp | 160 ++++++++++++++++++++--------------- 1 file changed, 90 insertions(+), 70 deletions(-) diff --git a/tests/test_client_server.cpp b/tests/test_client_server.cpp index 92085937..98814be3 100644 --- a/tests/test_client_server.cpp +++ b/tests/test_client_server.cpp @@ -28,79 +28,99 @@ */ #include "testutil.hpp" +#include "testutil_unity.hpp" + +#include + +void setUp () +{ + setup_test_context (); +} + +void tearDown () +{ + teardown_test_context (); +} + +/** \todo this should be split up into separate test cases */ +void test_x () +{ + void *server = test_context_socket (ZMQ_SERVER); + void *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")); + + { + zmq_msg_t msg; + TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_init_size (&msg, 1)); + + char *data = (char *) zmq_msg_data (&msg); + data[0] = 1; + + int rc = zmq_msg_send (&msg, client, ZMQ_SNDMORE); + TEST_ASSERT_EQUAL_INT (-1, rc); + TEST_ASSERT_EQUAL_INT (EINVAL, errno); + + rc = TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_send (&msg, client, 0)); + TEST_ASSERT_EQUAL_INT (1, rc); + } + + 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, ZMQ_SNDMORE); + TEST_ASSERT_EQUAL_INT (-1, rc); + TEST_ASSERT_EQUAL_INT (EINVAL, errno); + + 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_x); + return UNITY_END (); } From d318c95bc2dba0b7bcd5047e743a109de4e008d0 Mon Sep 17 00:00:00 2001 From: Simon Giesecke Date: Wed, 14 Mar 2018 18:56:50 +0100 Subject: [PATCH 5/8] Problem: different aspects mixed in one test case Solution: split up test case --- tests/test_client_server.cpp | 65 +++++++++++++++++++++++------------- 1 file changed, 42 insertions(+), 23 deletions(-) diff --git a/tests/test_client_server.cpp b/tests/test_client_server.cpp index 98814be3..9b177630 100644 --- a/tests/test_client_server.cpp +++ b/tests/test_client_server.cpp @@ -42,31 +42,52 @@ void tearDown () teardown_test_context (); } -/** \todo this should be split up into separate test cases */ -void test_x () +void create_inproc_client_server_pair (void **server, void **client) { - void *server = test_context_socket (ZMQ_SERVER); - void *client = test_context_socket (ZMQ_CLIENT); + *server = test_context_socket (ZMQ_SERVER); + *client = test_context_socket (ZMQ_CLIENT); TEST_ASSERT_SUCCESS_ERRNO ( - zmq_bind (server, "inproc://test-client-server")); + zmq_bind (*server, "inproc://test-client-server")); TEST_ASSERT_SUCCESS_ERRNO ( - zmq_connect (client, "inproc://test-client-server")); + zmq_connect (*client, "inproc://test-client-server")); +} - { - zmq_msg_t msg; - TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_init_size (&msg, 1)); +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); +} - char *data = (char *) zmq_msg_data (&msg); - data[0] = 1; +void test_client_sndmore_fails () +{ + void *server, *client; + create_inproc_client_server_pair (&server, &client); - int rc = zmq_msg_send (&msg, client, ZMQ_SNDMORE); - TEST_ASSERT_EQUAL_INT (-1, rc); - TEST_ASSERT_EQUAL_INT (EINVAL, errno); + send_sndmore_expect_failure (client); - rc = TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_send (&msg, client, 0)); - TEST_ASSERT_EQUAL_INT (1, rc); - } + 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; { @@ -91,11 +112,7 @@ void test_x () TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_set_routing_id (&msg, routing_id)); - int rc = zmq_msg_send (&msg, server, ZMQ_SNDMORE); - TEST_ASSERT_EQUAL_INT (-1, rc); - TEST_ASSERT_EQUAL_INT (EINVAL, errno); - - rc = zmq_msg_send (&msg, server, 0); + int rc = zmq_msg_send (&msg, server, 0); TEST_ASSERT_EQUAL_INT (1, rc); } @@ -121,6 +138,8 @@ int main (void) setup_test_environment (); UNITY_BEGIN (); - RUN_TEST (test_x); + RUN_TEST (test_client_sndmore_fails); + RUN_TEST (test_server_sndmore_fails); + RUN_TEST (test_routing_id); return UNITY_END (); } From 6f9459e3fb0e261d3fead93e4f52488240bd5ddd Mon Sep 17 00:00:00 2001 From: Simon Giesecke Date: Wed, 14 Mar 2018 19:05:19 +0100 Subject: [PATCH 6/8] Migrate tests/test_conflate.cpp to unity --- tests/test_conflate.cpp | 74 ++++++++++++++++++++++------------------- 1 file changed, 39 insertions(+), 35 deletions(-) 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 (); } From 9553a1f33e16c307985e665577422a30ac91fe4b Mon Sep 17 00:00:00 2001 From: Simon Giesecke Date: Wed, 14 Mar 2018 22:29:02 +0100 Subject: [PATCH 7/8] Problem: test_connect_resolve not yet using unity Solution: migrate to unity --- tests/test_connect_resolve.cpp | 102 ++++++++++++++++++++++----------- 1 file changed, 68 insertions(+), 34 deletions(-) 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 (); } From fa89fb86397761f810d7f9eb264c64c8f812d3a5 Mon Sep 17 00:00:00 2001 From: Simon Giesecke Date: Wed, 14 Mar 2018 22:33:41 +0100 Subject: [PATCH 8/8] Problem: Makefile.am missing unity dependencies Solution: add unity dependencies/flags --- Makefile.am | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) 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