2023-06-05 01:16:05 +02:00
|
|
|
/* SPDX-License-Identifier: MPL-2.0 */
|
2013-10-30 16:03:27 +01:00
|
|
|
|
2014-07-24 03:00:21 +02:00
|
|
|
#include "testutil.hpp"
|
2018-12-07 13:51:30 +01:00
|
|
|
#include "testutil_unity.hpp"
|
2014-07-24 03:00:21 +02:00
|
|
|
|
2019-03-24 17:51:28 +01:00
|
|
|
SETUP_TEARDOWN_TESTCONTEXT
|
2013-10-30 16:03:27 +01:00
|
|
|
|
2018-12-07 13:51:30 +01:00
|
|
|
void test ()
|
|
|
|
{
|
2013-10-30 16:03:27 +01:00
|
|
|
// First, create an intermediate device.
|
2018-12-07 13:51:30 +01:00
|
|
|
void *xpub = test_context_socket (ZMQ_XPUB);
|
|
|
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (xpub, "tipc://{5560,0,0}"));
|
|
|
|
void *xsub = test_context_socket (ZMQ_XSUB);
|
|
|
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (xsub, "tipc://{5561,0,0}"));
|
2013-10-30 16:03:27 +01:00
|
|
|
|
|
|
|
// Create a publisher.
|
2018-12-07 13:51:30 +01:00
|
|
|
void *pub = test_context_socket (ZMQ_PUB);
|
|
|
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (pub, "tipc://{5561,0}@0.0.0"));
|
2013-10-30 16:03:27 +01:00
|
|
|
|
|
|
|
// Create a subscriber.
|
2018-12-07 13:51:30 +01:00
|
|
|
void *sub = test_context_socket (ZMQ_SUB);
|
|
|
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sub, "tipc://{5560,0}@0.0.0"));
|
|
|
|
|
|
|
|
// TODO the remainder of this method is duplicated with test_sub_forward
|
2013-10-30 16:03:27 +01:00
|
|
|
|
|
|
|
// Subscribe for all messages.
|
2018-12-07 13:51:30 +01:00
|
|
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_setsockopt (sub, ZMQ_SUBSCRIBE, "", 0));
|
2013-10-30 16:03:27 +01:00
|
|
|
|
2018-12-07 13:51:30 +01:00
|
|
|
// Pass the subscription upstream through the device
|
2013-10-30 16:03:27 +01:00
|
|
|
char buff[32];
|
2018-12-07 13:51:30 +01:00
|
|
|
int size;
|
|
|
|
TEST_ASSERT_SUCCESS_ERRNO (size = zmq_recv (xpub, buff, sizeof (buff), 0));
|
|
|
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_send (xsub, buff, size, 0));
|
2013-10-30 16:03:27 +01:00
|
|
|
|
2018-12-07 13:51:30 +01:00
|
|
|
// Wait a bit till the subscription gets to the publisher
|
2013-11-06 13:30:41 +01:00
|
|
|
msleep (SETTLE_TIME);
|
2013-10-30 16:03:27 +01:00
|
|
|
|
2018-12-07 13:51:30 +01:00
|
|
|
// Send an empty message
|
|
|
|
send_string_expect_success (pub, "", 0);
|
2013-10-30 16:03:27 +01:00
|
|
|
|
2018-12-07 13:51:30 +01:00
|
|
|
// Pass the message downstream through the device
|
|
|
|
TEST_ASSERT_SUCCESS_ERRNO (size = zmq_recv (xsub, buff, sizeof (buff), 0));
|
|
|
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_send (xpub, buff, size, 0));
|
2013-10-30 16:03:27 +01:00
|
|
|
|
2018-12-07 13:51:30 +01:00
|
|
|
// Receive the message in the subscriber
|
|
|
|
recv_string_expect_success (sub, "", 0);
|
2013-10-30 16:03:27 +01:00
|
|
|
|
|
|
|
// Clean up.
|
2018-12-07 13:51:30 +01:00
|
|
|
test_context_socket_close (xpub);
|
|
|
|
test_context_socket_close (xsub);
|
|
|
|
test_context_socket_close (pub);
|
|
|
|
test_context_socket_close (sub);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main ()
|
|
|
|
{
|
|
|
|
if (!is_tipc_available ()) {
|
|
|
|
printf ("TIPC environment unavailable, skipping test\n");
|
|
|
|
return 77;
|
|
|
|
}
|
|
|
|
|
|
|
|
UNITY_BEGIN ();
|
|
|
|
RUN_TEST (test);
|
|
|
|
return UNITY_END ();
|
2013-10-30 16:03:27 +01:00
|
|
|
}
|