Commit 12c6ae22 authored by Simon Giesecke's avatar Simon Giesecke

Problem: test_pub_invert_matching not using test framework

Solution: migrate to unity
parent fa467d34
...@@ -660,7 +660,8 @@ tests_test_stream_exceeds_buffer_SOURCES = tests/test_stream_exceeds_buffer.cpp ...@@ -660,7 +660,8 @@ tests_test_stream_exceeds_buffer_SOURCES = tests/test_stream_exceeds_buffer.cpp
tests_test_stream_exceeds_buffer_LDADD = src/libzmq.la tests_test_stream_exceeds_buffer_LDADD = src/libzmq.la
tests_test_pub_invert_matching_SOURCES = tests/test_pub_invert_matching.cpp tests_test_pub_invert_matching_SOURCES = tests/test_pub_invert_matching.cpp
tests_test_pub_invert_matching_LDADD = src/libzmq.la tests_test_pub_invert_matching_LDADD = src/libzmq.la ${UNITY_LIBS}
tests_test_pub_invert_matching_CPPFLAGS = ${UNITY_CPPFLAGS}
tests_test_bind_after_connect_tcp_SOURCES = tests/test_bind_after_connect_tcp.cpp tests_test_bind_after_connect_tcp_SOURCES = tests/test_bind_after_connect_tcp.cpp
tests_test_bind_after_connect_tcp_LDADD = src/libzmq.la ${UNITY_LIBS} tests_test_bind_after_connect_tcp_LDADD = src/libzmq.la ${UNITY_LIBS}
......
...@@ -28,109 +28,95 @@ ...@@ -28,109 +28,95 @@
*/ */
#include "testutil.hpp" #include "testutil.hpp"
#include "testutil_unity.hpp"
int main (void) void setUp ()
{ {
setup_test_environment (); setup_test_context ();
void *ctx = zmq_ctx_new (); }
assert (ctx);
void tearDown ()
{
teardown_test_context ();
}
void test ()
{
// Create a publisher // Create a publisher
void *pub = zmq_socket (ctx, ZMQ_PUB); void *pub = test_context_socket (ZMQ_PUB);
assert (pub); TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (pub, "inproc://soname"));
int rc = zmq_bind (pub, "inproc://soname");
assert (rc == 0);
// Create two subscribers // Create two subscribers
void *sub1 = zmq_socket (ctx, ZMQ_SUB); void *sub1 = test_context_socket (ZMQ_SUB);
assert (sub1); TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sub1, "inproc://soname"));
rc = zmq_connect (sub1, "inproc://soname");
assert (rc == 0);
void *sub2 = zmq_socket (ctx, ZMQ_SUB); void *sub2 = test_context_socket (ZMQ_SUB);
assert (sub2); TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sub2, "inproc://soname"));
rc = zmq_connect (sub2, "inproc://soname");
assert (rc == 0);
// Subscribe pub1 to one prefix // Subscribe pub1 to one prefix
// and pub2 to another prefix. // and pub2 to another prefix.
const char PREFIX1[] = "prefix1"; const char PREFIX1[] = "prefix1";
const char PREFIX2[] = "p2"; const char PREFIX2[] = "p2";
rc = zmq_setsockopt (sub1, ZMQ_SUBSCRIBE, PREFIX1, sizeof (PREFIX1)); TEST_ASSERT_SUCCESS_ERRNO (
assert (rc == 0); zmq_setsockopt (sub1, ZMQ_SUBSCRIBE, PREFIX1, strlen (PREFIX1)));
TEST_ASSERT_SUCCESS_ERRNO (
rc = zmq_setsockopt (sub2, ZMQ_SUBSCRIBE, PREFIX2, sizeof (PREFIX2)); zmq_setsockopt (sub2, ZMQ_SUBSCRIBE, PREFIX2, strlen (PREFIX2)));
assert (rc == 0);
// Send a message with the first prefix // Send a message with the first prefix
rc = zmq_send_const (pub, PREFIX1, sizeof (PREFIX1), 0); send_string_expect_success (pub, PREFIX1, 0);
assert (rc == sizeof (PREFIX1));
// sub1 should receive it, but not sub2 // sub1 should receive it, but not sub2
rc = zmq_recv (sub1, NULL, 0, ZMQ_DONTWAIT); recv_string_expect_success (sub1, PREFIX1, ZMQ_DONTWAIT);
assert (rc == sizeof (PREFIX1));
rc = zmq_recv (sub2, NULL, 0, ZMQ_DONTWAIT); TEST_ASSERT_FAILURE_ERRNO (EAGAIN, zmq_recv (sub2, NULL, 0, ZMQ_DONTWAIT));
assert (rc == -1);
assert (errno == EAGAIN);
// Send a message with the second prefix // Send a message with the second prefix
rc = zmq_send_const (pub, PREFIX2, sizeof (PREFIX2), 0); send_string_expect_success (pub, PREFIX2, 0);
assert (rc == sizeof (PREFIX2));
// sub2 should receive it, but not sub1 // sub2 should receive it, but not sub1
rc = zmq_recv (sub2, NULL, 0, ZMQ_DONTWAIT); recv_string_expect_success (sub2, PREFIX2, ZMQ_DONTWAIT);
assert (rc == sizeof (PREFIX2));
rc = zmq_recv (sub1, NULL, 0, ZMQ_DONTWAIT); TEST_ASSERT_FAILURE_ERRNO (EAGAIN, zmq_recv (sub1, NULL, 0, ZMQ_DONTWAIT));
assert (rc == -1);
assert (errno == EAGAIN);
// Now invert the matching // Now invert the matching
int invert = 1; int invert = 1;
rc = zmq_setsockopt (pub, ZMQ_INVERT_MATCHING, &invert, sizeof (invert)); TEST_ASSERT_SUCCESS_ERRNO (
assert (rc == 0); zmq_setsockopt (pub, ZMQ_INVERT_MATCHING, &invert, sizeof (invert)));
// ... on both sides, otherwise the SUB socket will filter the messages out // ... on both sides, otherwise the SUB socket will filter the messages out
rc = zmq_setsockopt (sub1, ZMQ_INVERT_MATCHING, &invert, sizeof (invert)); TEST_ASSERT_SUCCESS_ERRNO (
rc = zmq_setsockopt (sub2, ZMQ_INVERT_MATCHING, &invert, sizeof (invert)); zmq_setsockopt (sub1, ZMQ_INVERT_MATCHING, &invert, sizeof (invert)));
assert (rc == 0); TEST_ASSERT_SUCCESS_ERRNO (
zmq_setsockopt (sub2, ZMQ_INVERT_MATCHING, &invert, sizeof (invert)));
// Send a message with the first prefix // Send a message with the first prefix
rc = zmq_send_const (pub, PREFIX1, sizeof (PREFIX1), 0); send_string_expect_success (pub, PREFIX1, 0);
assert (rc == sizeof (PREFIX1));
// sub2 should receive it, but not sub1 // sub2 should receive it, but not sub1
rc = zmq_recv (sub2, NULL, 0, ZMQ_DONTWAIT); recv_string_expect_success (sub2, PREFIX1, ZMQ_DONTWAIT);
assert (rc == sizeof (PREFIX1));
rc = zmq_recv (sub1, NULL, 0, ZMQ_DONTWAIT); TEST_ASSERT_FAILURE_ERRNO (EAGAIN, zmq_recv (sub1, NULL, 0, ZMQ_DONTWAIT));
assert (rc == -1);
assert (errno == EAGAIN);
// Send a message with the second prefix // Send a message with the second prefix
rc = zmq_send_const (pub, PREFIX2, sizeof (PREFIX2), 0); send_string_expect_success (pub, PREFIX2, 0);
assert (rc == sizeof (PREFIX2));
// sub1 should receive it, but not sub2 // sub1 should receive it, but not sub2
rc = zmq_recv (sub1, NULL, 0, ZMQ_DONTWAIT); recv_string_expect_success (sub1, PREFIX2, ZMQ_DONTWAIT);
assert (rc == sizeof (PREFIX2));
rc = zmq_recv (sub2, NULL, 0, ZMQ_DONTWAIT);
assert (rc == -1);
assert (errno == EAGAIN);
TEST_ASSERT_FAILURE_ERRNO (EAGAIN, zmq_recv (sub2, NULL, 0, ZMQ_DONTWAIT));
// Clean up. // Clean up.
rc = zmq_close (pub); test_context_socket_close (pub);
assert (rc == 0); test_context_socket_close (sub1);
rc = zmq_close (sub1); test_context_socket_close (sub2);
assert (rc == 0); }
rc = zmq_close (sub2);
assert (rc == 0); int main ()
rc = zmq_ctx_term (ctx); {
assert (rc == 0); setup_test_environment ();
return 0; UNITY_BEGIN ();
RUN_TEST (test);
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