1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
/* SPDX-License-Identifier: MPL-2.0 */
#include "testutil.hpp"
#include "testutil_unity.hpp"
SETUP_TEARDOWN_TESTCONTEXT
const char ep[] = "tipc://{5560,0,0}";
const char name[] = "tipc://{5560,0}@0.0.0";
void test_term_endpoint_unbind_tipc ()
{
if (!is_tipc_available ()) {
TEST_IGNORE_MESSAGE ("TIPC environment unavailable, skipping test\n");
}
// Create infrastructure.
void *push = test_context_socket (ZMQ_PUSH);
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (push, ep));
void *pull = test_context_socket (ZMQ_PULL);
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (pull, name));
// Pass one message through to ensure the connection is established.
send_string_expect_success (push, "ABC", 0);
recv_string_expect_success (pull, "ABC", 0);
// Unbind the lisnening endpoint
TEST_ASSERT_SUCCESS_ERRNO (zmq_unbind (push, ep));
// Let events some time
msleep (SETTLE_TIME);
// Check that sending would block (there's no outbound connection).
TEST_ASSERT_FAILURE_ERRNO (EAGAIN, zmq_send (push, "ABC", 3, ZMQ_DONTWAIT));
// Clean up.
test_context_socket_close (pull);
test_context_socket_close (push);
}
void test_term_endpoint_disconnect_tipc ()
{
if (!is_tipc_available ()) {
TEST_IGNORE_MESSAGE ("TIPC environment unavailable, skipping test\n");
}
// Create infrastructure.
void *push = test_context_socket (ZMQ_PUSH);
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (push, name));
void *pull = test_context_socket (ZMQ_PULL);
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (pull, ep));
// Pass one message through to ensure the connection is established.
send_string_expect_success (push, "ABC", 0);
recv_string_expect_success (pull, "ABC", 0);
// Disconnect the bound endpoint
TEST_ASSERT_SUCCESS_ERRNO (zmq_disconnect (push, name));
msleep (SETTLE_TIME);
// Check that sending would block (there's no inbound connections).
TEST_ASSERT_FAILURE_ERRNO (EAGAIN, zmq_send (push, "ABC", 3, ZMQ_DONTWAIT));
// Clean up.
test_context_socket_close (pull);
test_context_socket_close (push);
}
int main (void)
{
UNITY_BEGIN ();
RUN_TEST (test_term_endpoint_unbind_tipc);
RUN_TEST (test_term_endpoint_disconnect_tipc);
return UNITY_END ();
}
|