Commit dbcd42c5 authored by Simon Giesecke's avatar Simon Giesecke

Migrate tests/test_client_server.cpp to unity

parent 0114572c
......@@ -28,79 +28,99 @@
*/
#include "testutil.hpp"
#include "testutil_unity.hpp"
int main (void)
#include <unity.h>
void setUp ()
{
setup_test_environment ();
void *ctx = zmq_ctx_new ();
assert (ctx);
setup_test_context ();
}
void *server = zmq_socket (ctx, ZMQ_SERVER);
void *client = zmq_socket (ctx, ZMQ_CLIENT);
void tearDown ()
{
teardown_test_context ();
}
int rc = zmq_bind (server, "inproc://test-client-server");
assert (rc == 0);
/** \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);
rc = zmq_connect (client, "inproc://test-client-server");
assert (rc == 0);
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;
rc = zmq_msg_init_size (&msg, 1);
assert (rc == 0);
{
zmq_msg_t msg;
TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_init_size (&msg, 1));
char *data = (char *) zmq_msg_data (&msg);
data[0] = 1;
char *data = (char *) zmq_msg_data (&msg);
data[0] = 1;
rc = zmq_msg_send (&msg, client, ZMQ_SNDMORE);
assert (rc == -1);
int rc = zmq_msg_send (&msg, client, ZMQ_SNDMORE);
TEST_ASSERT_EQUAL_INT (-1, rc);
TEST_ASSERT_EQUAL_INT (EINVAL, errno);
rc = zmq_msg_send (&msg, client, 0);
assert (rc == 1);
rc = TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_send (&msg, client, 0));
TEST_ASSERT_EQUAL_INT (1, rc);
}
rc = zmq_msg_init (&msg);
assert (rc == 0);
uint32_t routing_id;
{
zmq_msg_t msg;
TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_init (&msg));
rc = zmq_msg_recv (&msg, server, 0);
assert (rc == 1);
int rc = TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_recv (&msg, server, 0));
TEST_ASSERT_EQUAL_INT (1, rc);
uint32_t routing_id = zmq_msg_routing_id (&msg);
assert (routing_id != 0);
routing_id = zmq_msg_routing_id (&msg);
TEST_ASSERT_NOT_EQUAL (0, routing_id);
rc = zmq_msg_close (&msg);
assert (rc == 0);
TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_close (&msg));
}
rc = zmq_msg_init_size (&msg, 1);
assert (rc == 0);
{
zmq_msg_t msg;
TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_init_size (&msg, 1));
data = (char *) zmq_msg_data (&msg);
data[0] = 2;
char *data = (char *) zmq_msg_data (&msg);
data[0] = 2;
rc = zmq_msg_set_routing_id (&msg, routing_id);
assert (rc == 0);
TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_set_routing_id (&msg, routing_id));
rc = zmq_msg_send (&msg, server, ZMQ_SNDMORE);
assert (rc == -1);
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);
assert (rc == 1);
rc = zmq_msg_send (&msg, server, 0);
TEST_ASSERT_EQUAL_INT (1, rc);
}
rc = zmq_msg_recv (&msg, client, 0);
assert (rc == 1);
{
zmq_msg_t msg;
TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_init (&msg));
routing_id = zmq_msg_routing_id (&msg);
assert (routing_id == 0);
int rc = zmq_msg_recv (&msg, client, 0);
TEST_ASSERT_EQUAL_INT (1, rc);
rc = zmq_msg_close (&msg);
assert (rc == 0);
routing_id = zmq_msg_routing_id (&msg);
TEST_ASSERT_EQUAL_UINT32 (0, routing_id);
rc = zmq_close (server);
assert (rc == 0);
TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_close (&msg));
}
rc = zmq_close (client);
assert (rc == 0);
test_context_socket_close (server);
test_context_socket_close (client);
}
rc = zmq_ctx_term (ctx);
assert (rc == 0);
int main (void)
{
setup_test_environment ();
return 0;
UNITY_BEGIN ();
RUN_TEST (test_x);
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