Commit 5d32828b authored by Simon Giesecke's avatar Simon Giesecke

Problem: test_reconnect_ivl not using unity

Solution: migrate to unity, and reduce code duplication
parent 1e217ac0
...@@ -669,7 +669,8 @@ tests_test_socket_null_LDADD = src/libzmq.la ${UNITY_LIBS} ...@@ -669,7 +669,8 @@ tests_test_socket_null_LDADD = src/libzmq.la ${UNITY_LIBS}
tests_test_socket_null_CPPFLAGS = ${UNITY_CPPFLAGS} tests_test_socket_null_CPPFLAGS = ${UNITY_CPPFLAGS}
tests_test_reconnect_ivl_SOURCES = tests/test_reconnect_ivl.cpp tests_test_reconnect_ivl_SOURCES = tests/test_reconnect_ivl.cpp
tests_test_reconnect_ivl_LDADD = src/libzmq.la tests_test_reconnect_ivl_LDADD = src/libzmq.la ${UNITY_LIBS}
tests_test_reconnect_ivl_CPPFLAGS = ${UNITY_CPPFLAGS}
if HAVE_CURVE if HAVE_CURVE
......
...@@ -28,52 +28,54 @@ ...@@ -28,52 +28,54 @@
*/ */
#include "testutil.hpp" #include "testutil.hpp"
#include "testutil_unity.hpp"
#include <unity.h>
#ifndef ZMQ_HAVE_WINDOWS void setUp ()
void test_reconnect_ivl_ipc (void)
{ {
void *ctx = zmq_ctx_new (); setup_test_context ();
assert (ctx); }
void *sb = zmq_socket (ctx, ZMQ_PAIR); void tearDown ()
assert (sb); {
int rc = zmq_bind (sb, "ipc:///tmp/test_reconnect_ivl"); teardown_test_context ();
assert (rc == 0); }
void *sc = zmq_socket (ctx, ZMQ_PAIR); void test_reconnect_ivl_against_pair_socket (const char *my_endpoint, void *sb)
assert (sc); {
void *sc = test_context_socket (ZMQ_PAIR);
int interval = -1; int interval = -1;
rc = zmq_setsockopt (sc, ZMQ_RECONNECT_IVL, &interval, sizeof (int)); TEST_ASSERT_SUCCESS_ERRNO (
assert (rc == 0); zmq_setsockopt (sc, ZMQ_RECONNECT_IVL, &interval, sizeof (int)));
rc = zmq_connect (sc, "ipc:///tmp/test_reconnect_ivl"); TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sc, my_endpoint));
assert (rc == 0);
bounce (sb, sc); bounce (sb, sc);
rc = zmq_unbind (sb, "ipc:///tmp/test_reconnect_ivl"); TEST_ASSERT_SUCCESS_ERRNO (zmq_unbind (sb, my_endpoint));
assert (rc == 0);
expect_bounce_fail (sb, sc); expect_bounce_fail (sb, sc);
rc = zmq_bind (sb, "ipc:///tmp/test_reconnect_ivl"); TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb, my_endpoint));
assert (rc == 0);
expect_bounce_fail (sb, sc); expect_bounce_fail (sb, sc);
rc = zmq_connect (sc, "ipc:///tmp/test_reconnect_ivl"); TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sc, my_endpoint));
assert (rc == 0);
bounce (sb, sc); bounce (sb, sc);
rc = zmq_close (sc); test_context_socket_close (sc);
assert (rc == 0); }
rc = zmq_close (sb); #ifndef ZMQ_HAVE_WINDOWS
assert (rc == 0); void test_reconnect_ivl_ipc (void)
{
const char *ipc_endpoint = "ipc:///tmp/test_reconnect_ivl";
void *sb = test_context_socket (ZMQ_PAIR);
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb, ipc_endpoint));
rc = zmq_ctx_term (ctx); test_reconnect_ivl_against_pair_socket (ipc_endpoint, sb);
assert (rc == 0); test_context_socket_close (sb);
} }
#endif #endif
...@@ -81,69 +83,39 @@ void test_reconnect_ivl_tcp (const char *address) ...@@ -81,69 +83,39 @@ void test_reconnect_ivl_tcp (const char *address)
{ {
size_t len = MAX_SOCKET_STRING; size_t len = MAX_SOCKET_STRING;
char my_endpoint[MAX_SOCKET_STRING]; char my_endpoint[MAX_SOCKET_STRING];
void *ctx = zmq_ctx_new ();
assert (ctx);
if (streq (address, "tcp://[::1]:*")) {
if (is_ipv6_available ()) {
zmq_ctx_set (ctx, ZMQ_IPV6, 1);
} else {
zmq_ctx_term (ctx);
return;
}
}
void *sb = zmq_socket (ctx, ZMQ_PAIR);
assert (sb);
int rc = zmq_bind (sb, address);
assert (rc == 0);
rc = zmq_getsockopt (sb, ZMQ_LAST_ENDPOINT, my_endpoint, &len);
assert (rc == 0);
void *sc = zmq_socket (ctx, ZMQ_PAIR);
assert (sc);
int interval = -1;
rc = zmq_setsockopt (sc, ZMQ_RECONNECT_IVL, &interval, sizeof (int));
assert (rc == 0);
rc = zmq_connect (sc, my_endpoint);
assert (rc == 0);
bounce (sb, sc);
rc = zmq_unbind (sb, my_endpoint); void *sb = test_context_socket (ZMQ_PAIR);
assert (rc == 0); TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb, address));
TEST_ASSERT_SUCCESS_ERRNO (
zmq_getsockopt (sb, ZMQ_LAST_ENDPOINT, my_endpoint, &len));
expect_bounce_fail (sb, sc); test_reconnect_ivl_against_pair_socket (my_endpoint, sb);
test_context_socket_close (sb);
rc = zmq_bind (sb, my_endpoint); }
assert (rc == 0);
expect_bounce_fail (sb, sc);
rc = zmq_connect (sc, my_endpoint);
assert (rc == 0);
bounce (sb, sc);
rc = zmq_close (sc);
assert (rc == 0);
rc = zmq_close (sb); void test_reconnect_ivl_tcp_ipv4 ()
assert (rc == 0); {
test_reconnect_ivl_tcp ("tcp://127.0.0.1:*");
}
rc = zmq_ctx_term (ctx); void test_reconnect_ivl_tcp_ipv6 ()
assert (rc == 0); {
if (is_ipv6_available ()) {
zmq_ctx_set (get_test_context (), ZMQ_IPV6, 1);
test_reconnect_ivl_tcp ("tcp://[::1]:*");
}
} }
int main (void) int main (void)
{ {
setup_test_environment (); setup_test_environment ();
UNITY_BEGIN ();
#ifndef ZMQ_HAVE_WINDOWS #ifndef ZMQ_HAVE_WINDOWS
test_reconnect_ivl_ipc (); RUN_TEST (test_reconnect_ivl_ipc);
#endif #endif
test_reconnect_ivl_tcp ("tcp://127.0.0.1:*"); RUN_TEST (test_reconnect_ivl_tcp_ipv4);
test_reconnect_ivl_tcp ("tcp://[::1]:*"); RUN_TEST (test_reconnect_ivl_tcp_ipv6);
return 0; return UNITY_END ();
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment