Problem: tests without test framework

Solution: migrate to Unity
This commit is contained in:
Simon Giesecke 2019-03-22 10:09:11 -04:00
parent 6f083df5fb
commit 4ab381436d
2 changed files with 52 additions and 65 deletions

View File

@ -912,7 +912,8 @@ tests_test_sub_forward_tipc_LDADD = src/libzmq.la ${UNITY_LIBS}
tests_test_sub_forward_tipc_CPPFLAGS = ${UNITY_CPPFLAGS} tests_test_sub_forward_tipc_CPPFLAGS = ${UNITY_CPPFLAGS}
tests_test_term_endpoint_tipc_SOURCES = tests/test_term_endpoint_tipc.cpp tests_test_term_endpoint_tipc_SOURCES = tests/test_term_endpoint_tipc.cpp
tests_test_term_endpoint_tipc_LDADD = src/libzmq.la tests_test_term_endpoint_tipc_LDADD = src/libzmq.la ${UNITY_LIBS}
tests_test_term_endpoint_tipc_CPPFLAGS = ${UNITY_CPPFLAGS}
tests_test_address_tipc_SOURCES = tests/test_address_tipc.cpp tests_test_address_tipc_SOURCES = tests/test_address_tipc.cpp
tests_test_address_tipc_LDADD = src/libzmq.la ${UNITY_LIBS} tests_test_address_tipc_LDADD = src/libzmq.la ${UNITY_LIBS}

View File

@ -28,98 +28,84 @@
*/ */
#include "testutil.hpp" #include "testutil.hpp"
#include "testutil_unity.hpp"
int main (void) void setUp ()
{
setup_test_context ();
}
void tearDown ()
{
teardown_test_context ();
}
const char ep[] = "tipc://{5560,0,0}";
const char name[] = "tipc://{5560,0}@0.0.0";
void test_term_endpoint_unbind_tipc ()
{ {
if (!is_tipc_available ()) { if (!is_tipc_available ()) {
printf ("TIPC environment unavailable, skipping test\n"); TEST_IGNORE_MESSAGE ("TIPC environment unavailable, skipping test\n");
return 77;
} }
int rc;
char buf[32];
const char *ep = "tipc://{5560,0,0}";
const char *name = "tipc://{5560,0}@0.0.0";
fprintf (stderr, "unbind endpoint test running...\n");
// Create infrastructure. // Create infrastructure.
void *ctx = zmq_init (1); void *push = test_context_socket (ZMQ_PUSH);
assert (ctx); TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (push, ep));
void *push = zmq_socket (ctx, ZMQ_PUSH); void *pull = test_context_socket (ZMQ_PULL);
assert (push); TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (pull, name));
rc = zmq_bind (push, ep);
assert (rc == 0);
void *pull = zmq_socket (ctx, ZMQ_PULL);
assert (pull);
rc = zmq_connect (pull, name);
assert (rc == 0);
// Pass one message through to ensure the connection is established. // Pass one message through to ensure the connection is established.
rc = zmq_send (push, "ABC", 3, 0); send_string_expect_success (push, "ABC", 0);
assert (rc == 3); recv_string_expect_success (pull, "ABC", 0);
rc = zmq_recv (pull, buf, sizeof (buf), 0);
assert (rc == 3);
// Unbind the lisnening endpoint // Unbind the lisnening endpoint
rc = zmq_unbind (push, ep); TEST_ASSERT_SUCCESS_ERRNO (zmq_unbind (push, ep));
assert (rc == 0);
// Let events some time // Let events some time
msleep (SETTLE_TIME); msleep (SETTLE_TIME);
// Check that sending would block (there's no outbound connection). // Check that sending would block (there's no outbound connection).
rc = zmq_send (push, "ABC", 3, ZMQ_DONTWAIT); TEST_ASSERT_FAILURE_ERRNO (EAGAIN, zmq_send (push, "ABC", 3, ZMQ_DONTWAIT));
assert (rc == -1 && zmq_errno () == EAGAIN);
// Clean up. // Clean up.
rc = zmq_close (pull); test_context_socket_close (pull);
assert (rc == 0); test_context_socket_close (push);
rc = zmq_close (push); }
assert (rc == 0);
rc = zmq_ctx_term (ctx);
assert (rc == 0);
// Now the other way round.
fprintf (stderr, "disconnect endpoint test running...\n");
void test_term_endpoint_disconnect_tipc ()
{
if (!is_tipc_available ()) {
TEST_IGNORE_MESSAGE ("TIPC environment unavailable, skipping test\n");
}
// Create infrastructure. // Create infrastructure.
ctx = zmq_init (1); void *push = test_context_socket (ZMQ_PUSH);
assert (ctx); TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (push, name));
push = zmq_socket (ctx, ZMQ_PUSH); void *pull = test_context_socket (ZMQ_PULL);
assert (push); TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (pull, ep));
rc = zmq_connect (push, name);
assert (rc == 0);
pull = zmq_socket (ctx, ZMQ_PULL);
assert (pull);
rc = zmq_bind (pull, ep);
assert (rc == 0);
// Pass one message through to ensure the connection is established. // Pass one message through to ensure the connection is established.
rc = zmq_send (push, "ABC", 3, 0); send_string_expect_success (push, "ABC", 0);
assert (rc == 3); recv_string_expect_success (pull, "ABC", 0);
rc = zmq_recv (pull, buf, sizeof (buf), 0);
assert (rc == 3);
// Disconnect the bound endpoint // Disconnect the bound endpoint
rc = zmq_disconnect (push, name); TEST_ASSERT_SUCCESS_ERRNO (zmq_disconnect (push, name));
assert (rc == 0);
msleep (SETTLE_TIME); msleep (SETTLE_TIME);
// Check that sending would block (there's no inbound connections). // Check that sending would block (there's no inbound connections).
rc = zmq_send (push, "ABC", 3, ZMQ_DONTWAIT); TEST_ASSERT_FAILURE_ERRNO (EAGAIN, zmq_send (push, "ABC", 3, ZMQ_DONTWAIT));
assert (rc == -1 && zmq_errno () == EAGAIN);
// Clean up. // Clean up.
rc = zmq_close (pull); test_context_socket_close (pull);
assert (rc == 0); test_context_socket_close (push);
rc = zmq_close (push); }
assert (rc == 0);
rc = zmq_ctx_term (ctx); int main (void)
assert (rc == 0); {
UNITY_BEGIN ();
return 0; RUN_TEST (test_term_endpoint_unbind_tipc);
RUN_TEST (test_term_endpoint_disconnect_tipc);
return UNITY_END ();
} }