Commit bfec30b1 authored by Simon Giesecke's avatar Simon Giesecke

Problem: test_address_tipc is unnecessarily verbose

Solution: make use of custom Unity macros
parent 386de330
...@@ -30,41 +30,21 @@ ...@@ -30,41 +30,21 @@
#include "testutil.hpp" #include "testutil.hpp"
#include "testutil_unity.hpp" #include "testutil_unity.hpp"
#include <unity.h> SETUP_TEARDOWN_TESTCONTEXT
void setUp ()
{
}
void tearDown ()
{
}
void test_tipc_port_name_and_domain () void test_tipc_port_name_and_domain ()
{ {
void *ctx = zmq_ctx_new ();
TEST_ASSERT_NOT_NULL (ctx);
// test Port Name addressing // test Port Name addressing
void *sb = zmq_socket (ctx, ZMQ_REP); void *sb = test_context_socket (ZMQ_REP);
TEST_ASSERT_NOT_NULL (sb); TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb, "tipc://{5560,0,0}"));
int rc = zmq_bind (sb, "tipc://{5560,0,0}");
TEST_ASSERT_EQUAL_INT (0, rc);
void *sc = zmq_socket (ctx, ZMQ_REQ); void *sc = test_context_socket (ZMQ_REQ);
TEST_ASSERT_NOT_NULL (sc); TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sc, "tipc://{5560,0}@0.0.0"));
rc = zmq_connect (sc, "tipc://{5560,0}@0.0.0");
TEST_ASSERT_EQUAL_INT (0, rc);
bounce (sb, sc); bounce (sb, sc);
rc = zmq_close (sc); test_context_socket_close (sc);
TEST_ASSERT_EQUAL_INT (0, rc); test_context_socket_close (sb);
rc = zmq_close (sb);
TEST_ASSERT_EQUAL_INT (0, rc);
zmq_ctx_term (ctx);
} }
void test_tipc_port_identity () void test_tipc_port_identity ()
...@@ -72,14 +52,8 @@ void test_tipc_port_identity () ...@@ -72,14 +52,8 @@ void test_tipc_port_identity ()
char endpoint[256]; char endpoint[256];
unsigned int z, c, n, ref; unsigned int z, c, n, ref;
void *ctx = zmq_ctx_new (); void *sb = test_context_socket (ZMQ_REP);
TEST_ASSERT_NOT_NULL (ctx); void *sc = test_context_socket (ZMQ_REQ);
void *sb = zmq_socket (ctx, ZMQ_REP);
TEST_ASSERT_NOT_NULL (sb);
void *sc = zmq_socket (ctx, ZMQ_REQ);
TEST_ASSERT_NOT_NULL (sc);
// Test binding to random Port Identity and // Test binding to random Port Identity and
// test resolving assigned address, should return a properly formatted string // test resolving assigned address, should return a properly formatted string
...@@ -91,44 +65,27 @@ void test_tipc_port_identity () ...@@ -91,44 +65,27 @@ void test_tipc_port_identity ()
TEST_ASSERT_NOT_EQUAL_MESSAGE ( TEST_ASSERT_NOT_EQUAL_MESSAGE (
0, ref, "tipc port number must not be 0 after random assignment"); 0, ref, "tipc port number must not be 0 after random assignment");
rc = zmq_connect (sc, endpoint); TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sc, endpoint));
TEST_ASSERT_EQUAL_INT (0, rc);
bounce (sb, sc); bounce (sb, sc);
rc = zmq_close (sc); test_context_socket_close (sc);
TEST_ASSERT_EQUAL_INT (0, rc); test_context_socket_close (sb);
rc = zmq_close (sb);
TEST_ASSERT_EQUAL_INT (0, rc);
zmq_ctx_term (ctx);
} }
void test_tipc_bad_addresses () void test_tipc_bad_addresses ()
{ {
void *ctx = zmq_ctx_new ();
TEST_ASSERT_NOT_NULL (ctx);
// Test Port Name addressing // Test Port Name addressing
void *sb = zmq_socket (ctx, ZMQ_REP); void *sb = test_context_socket (ZMQ_REP);
TEST_ASSERT_NOT_NULL (sb);
// Test binding to a fixed address, should fail // Test binding to a fixed address, should fail
int rc = zmq_bind (sb, "tipc://<1.2.3:123123>"); TEST_ASSERT_FAILURE_ERRNO (EINVAL, zmq_bind (sb, "tipc://<1.2.3:123123>"));
TEST_ASSERT_EQUAL_INT (-1, rc);
TEST_ASSERT_EQUAL_INT (EINVAL, errno);
// Test connecting to random identity, should fail // Test connecting to random identity, should fail
rc = zmq_connect (sb, "tipc://<*>"); TEST_ASSERT_FAILURE_ERRNO (EINVAL, zmq_connect (sb, "tipc://<*>"));
TEST_ASSERT_EQUAL_INT (-1, rc);
TEST_ASSERT_EQUAL_INT (EINVAL, errno);
// Clean up // Clean up
rc = zmq_close (sb); test_context_socket_close (sb);
TEST_ASSERT_EQUAL_INT (0, rc);
zmq_ctx_term (ctx);
} }
......
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