Commit 367246bb authored by Simon Giesecke's avatar Simon Giesecke Committed by Simon Giesecke

Problem: test_monitor is not using a test framework

Solution: migrate to unity
parent 478e4244
...@@ -541,7 +541,8 @@ tests_test_srcfd_LDADD = src/libzmq.la ${UNITY_LIBS} ...@@ -541,7 +541,8 @@ tests_test_srcfd_LDADD = src/libzmq.la ${UNITY_LIBS}
tests_test_srcfd_CPPFLAGS = ${UNITY_CPPFLAGS} tests_test_srcfd_CPPFLAGS = ${UNITY_CPPFLAGS}
tests_test_monitor_SOURCES = tests/test_monitor.cpp tests_test_monitor_SOURCES = tests/test_monitor.cpp
tests_test_monitor_LDADD = src/libzmq.la tests_test_monitor_LDADD = src/libzmq.la ${UNITY_LIBS}
tests_test_monitor_CPPFLAGS = ${UNITY_CPPFLAGS}
tests_test_router_mandatory_SOURCES = tests/test_router_mandatory.cpp tests/testutil_unity.hpp tests_test_router_mandatory_SOURCES = tests/test_router_mandatory.cpp tests/testutil_unity.hpp
tests_test_router_mandatory_LDADD = src/libzmq.la ${UNITY_LIBS} tests_test_router_mandatory_LDADD = src/libzmq.la ${UNITY_LIBS}
......
...@@ -30,56 +30,61 @@ ...@@ -30,56 +30,61 @@
#include "testutil.hpp" #include "testutil.hpp"
#include "testutil_security.hpp" #include "testutil_security.hpp"
int main (void) #include "testutil_unity.hpp"
void setUp ()
{ {
setup_test_environment (); setup_test_context ();
}
size_t len = MAX_SOCKET_STRING; void tearDown ()
char my_endpoint[MAX_SOCKET_STRING]; {
void *ctx = zmq_ctx_new (); teardown_test_context ();
assert (ctx); }
// We'll monitor these two sockets void test_monitor_invalid_protocol_fails ()
void *client = zmq_socket (ctx, ZMQ_DEALER); {
assert (client); void *client = test_context_socket (ZMQ_DEALER);
void *server = zmq_socket (ctx, ZMQ_DEALER);
assert (server);
// Socket monitoring only works over inproc:// // Socket monitoring only works over inproc://
int rc = zmq_socket_monitor (client, "tcp://127.0.0.1:*", 0); TEST_ASSERT_FAILURE_ERRNO (
assert (rc == -1); EPROTONOSUPPORT, zmq_socket_monitor (client, "tcp://127.0.0.1:*", 0));
assert (zmq_errno () == EPROTONOSUPPORT); }
void test_monitor_basic ()
{
char my_endpoint[MAX_SOCKET_STRING];
// We'll monitor these two sockets
void *client = test_context_socket (ZMQ_DEALER);
void *server = test_context_socket (ZMQ_DEALER);
// Monitor all events on client and server sockets // Monitor all events on client and server sockets
rc = zmq_socket_monitor (client, "inproc://monitor-client", ZMQ_EVENT_ALL); TEST_ASSERT_SUCCESS_ERRNO (
assert (rc == 0); zmq_socket_monitor (client, "inproc://monitor-client", ZMQ_EVENT_ALL));
rc = zmq_socket_monitor (server, "inproc://monitor-server", ZMQ_EVENT_ALL); TEST_ASSERT_SUCCESS_ERRNO (
assert (rc == 0); zmq_socket_monitor (server, "inproc://monitor-server", ZMQ_EVENT_ALL));
// Create two sockets for collecting monitor events // Create two sockets for collecting monitor events
void *client_mon = zmq_socket (ctx, ZMQ_PAIR); void *client_mon = test_context_socket (ZMQ_PAIR);
assert (client_mon); void *server_mon = test_context_socket (ZMQ_PAIR);
void *server_mon = zmq_socket (ctx, ZMQ_PAIR);
assert (server_mon);
// Connect these to the inproc endpoints so they'll get events // Connect these to the inproc endpoints so they'll get events
rc = zmq_connect (client_mon, "inproc://monitor-client"); TEST_ASSERT_SUCCESS_ERRNO (
assert (rc == 0); zmq_connect (client_mon, "inproc://monitor-client"));
rc = zmq_connect (server_mon, "inproc://monitor-server"); TEST_ASSERT_SUCCESS_ERRNO (
assert (rc == 0); zmq_connect (server_mon, "inproc://monitor-server"));
// Now do a basic ping test // Now do a basic ping test
rc = zmq_bind (server, "tcp://127.0.0.1:*"); bind_loopback_ipv4 (server, my_endpoint, sizeof my_endpoint);
assert (rc == 0);
rc = zmq_getsockopt (server, ZMQ_LAST_ENDPOINT, my_endpoint, &len); TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (client, my_endpoint));
assert (rc == 0);
rc = zmq_connect (client, my_endpoint);
assert (rc == 0);
bounce (server, client); bounce (server, client);
// Close client and server // Close client and server
close_zero_linger (client); // TODO why does this use zero_linger?
close_zero_linger (server); test_context_socket_close_zero_linger (client);
test_context_socket_close_zero_linger (server);
// Now collect and check events from both sockets // Now collect and check events from both sockets
int event = get_monitor_event (client_mon, NULL, NULL); int event = get_monitor_event (client_mon, NULL, NULL);
...@@ -96,17 +101,25 @@ int main (void) ...@@ -96,17 +101,25 @@ int main (void)
event = get_monitor_event (server_mon, NULL, NULL); event = get_monitor_event (server_mon, NULL, NULL);
// Sometimes the server sees the client closing before it gets closed. // Sometimes the server sees the client closing before it gets closed.
if (event != ZMQ_EVENT_DISCONNECTED) { if (event != ZMQ_EVENT_DISCONNECTED) {
assert (event == ZMQ_EVENT_CLOSED); TEST_ASSERT_EQUAL_INT (ZMQ_EVENT_CLOSED, event);
event = get_monitor_event (server_mon, NULL, NULL); event = get_monitor_event (server_mon, NULL, NULL);
} }
if (event != ZMQ_EVENT_DISCONNECTED) { if (event != ZMQ_EVENT_DISCONNECTED) {
assert (event == ZMQ_EVENT_MONITOR_STOPPED); TEST_ASSERT_EQUAL_INT (ZMQ_EVENT_MONITOR_STOPPED, event);
} }
// Close down the sockets // Close down the sockets
close_zero_linger (client_mon); // TODO why does this use zero_linger?
close_zero_linger (server_mon); test_context_socket_close_zero_linger (client_mon);
zmq_ctx_term (ctx); test_context_socket_close_zero_linger (server_mon);
}
int main ()
{
setup_test_environment ();
return 0; UNITY_BEGIN ();
RUN_TEST (test_monitor_invalid_protocol_fails);
RUN_TEST (test_monitor_basic);
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