Commit dbcd42c5 authored by Simon Giesecke's avatar Simon Giesecke

Migrate tests/test_client_server.cpp to unity

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