Commit 7ad0ff5e authored by Simon Giesecke's avatar Simon Giesecke

Problem: test_stream_empty not yet using unity

Solution: migrate to unity
parent 7b39d2cb
......@@ -547,7 +547,8 @@ tests_test_stream_SOURCES = tests/test_stream.cpp
tests_test_stream_LDADD = src/libzmq.la
tests_test_stream_empty_SOURCES = tests/test_stream_empty.cpp
tests_test_stream_empty_LDADD = src/libzmq.la
tests_test_stream_empty_LDADD = src/libzmq.la ${UNITY_LIBS}
tests_test_stream_empty_CPPFLAGS = ${UNITY_CPPFLAGS}
tests_test_stream_timeout_SOURCES = tests/test_stream_timeout.cpp
tests_test_stream_timeout_LDADD = src/libzmq.la
......
......@@ -28,48 +28,52 @@
*/
#include "testutil.hpp"
#include "testutil_unity.hpp"
int main (void)
void setUp ()
{
setup_test_context ();
}
void tearDown ()
{
teardown_test_context ();
}
void test_stream_empty ()
{
setup_test_environment ();
size_t len = MAX_SOCKET_STRING;
char my_endpoint[MAX_SOCKET_STRING];
void *ctx = zmq_ctx_new ();
assert (ctx);
void *stream = zmq_socket (ctx, ZMQ_STREAM);
assert (stream);
void *dealer = zmq_socket (ctx, ZMQ_DEALER);
assert (dealer);
int rc = zmq_bind (stream, "tcp://127.0.0.1:*");
assert (rc >= 0);
rc = zmq_getsockopt (stream, ZMQ_LAST_ENDPOINT, my_endpoint, &len);
assert (rc == 0);
rc = zmq_connect (dealer, my_endpoint);
assert (rc >= 0);
zmq_send (dealer, "", 0, 0);
void *stream = test_context_socket (ZMQ_STREAM);
void *dealer = test_context_socket (ZMQ_DEALER);
bind_loopback_ipv4 (stream, my_endpoint, sizeof my_endpoint);
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (dealer, my_endpoint));
send_string_expect_success (dealer, "", 0);
zmq_msg_t ident, empty;
zmq_msg_init (&ident);
rc = zmq_msg_recv (&ident, stream, 0);
assert (rc >= 0);
rc = zmq_msg_init_data (&empty, (void *) "", 0, NULL, NULL);
assert (rc >= 0);
TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_recv (&ident, stream, 0));
TEST_ASSERT_SUCCESS_ERRNO (
zmq_msg_init_data (&empty, (void *) "", 0, NULL, NULL));
rc = zmq_msg_send (&ident, stream, ZMQ_SNDMORE);
assert (rc >= 0);
rc = zmq_msg_close (&ident);
assert (rc >= 0);
TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_send (&ident, stream, ZMQ_SNDMORE));
TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_close (&ident));
rc = zmq_msg_send (&empty, stream, 0);
assert (rc >= 0);
TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_send (&empty, stream, 0));
// This close used to fail with Bad Address
rc = zmq_msg_close (&empty);
assert (rc >= 0);
TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_close (&empty));
test_context_socket_close_zero_linger (dealer);
test_context_socket_close_zero_linger (stream);
}
int main ()
{
setup_test_environment ();
close_zero_linger (dealer);
close_zero_linger (stream);
zmq_ctx_term (ctx);
UNITY_BEGIN ();
RUN_TEST (test_stream_empty);
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