2023-06-05 00:16:05 +01:00
|
|
|
/* SPDX-License-Identifier: MPL-2.0 */
|
2011-07-11 15:54:13 +02:00
|
|
|
|
2013-08-17 13:43:45 +01:00
|
|
|
#include "testutil.hpp"
|
2018-12-07 07:51:30 -05:00
|
|
|
#include "testutil_unity.hpp"
|
2011-07-11 15:54:13 +02:00
|
|
|
|
2019-03-24 12:51:28 -04:00
|
|
|
SETUP_TEARDOWN_TESTCONTEXT
|
2018-12-07 07:51:30 -05:00
|
|
|
|
|
|
|
void test ()
|
2011-07-11 15:54:13 +02:00
|
|
|
{
|
2017-05-01 12:11:11 +01:00
|
|
|
char endpoint1[MAX_SOCKET_STRING];
|
|
|
|
char endpoint2[MAX_SOCKET_STRING];
|
2011-07-11 15:54:13 +02:00
|
|
|
|
2013-01-31 19:46:22 +01:00
|
|
|
// First, create an intermediate device
|
2018-12-07 07:51:30 -05:00
|
|
|
void *xpub = test_context_socket (ZMQ_XPUB);
|
|
|
|
bind_loopback_ipv4 (xpub, endpoint1, sizeof (endpoint1));
|
|
|
|
|
|
|
|
void *xsub = test_context_socket (ZMQ_XSUB);
|
|
|
|
bind_loopback_ipv4 (xsub, endpoint2, sizeof (endpoint2));
|
2011-07-11 15:54:13 +02:00
|
|
|
|
2013-01-31 19:46:22 +01:00
|
|
|
// Create a publisher
|
2018-12-07 07:51:30 -05:00
|
|
|
void *pub = test_context_socket (ZMQ_PUB);
|
|
|
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (pub, endpoint2));
|
2011-07-11 15:54:13 +02:00
|
|
|
|
2013-01-31 19:46:22 +01:00
|
|
|
// Create a subscriber
|
2018-12-07 07:51:30 -05:00
|
|
|
void *sub = test_context_socket (ZMQ_SUB);
|
|
|
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sub, endpoint1));
|
2011-07-11 15:54:13 +02:00
|
|
|
|
|
|
|
// Subscribe for all messages.
|
2018-12-07 07:51:30 -05:00
|
|
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_setsockopt (sub, ZMQ_SUBSCRIBE, "", 0));
|
2011-07-11 15:54:13 +02:00
|
|
|
|
2013-01-31 19:46:22 +01:00
|
|
|
// Pass the subscription upstream through the device
|
2011-07-11 15:54:13 +02:00
|
|
|
char buff[32];
|
2018-12-07 07:51:30 -05: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));
|
2011-07-11 15:54:13 +02:00
|
|
|
|
2013-01-31 19:46:22 +01:00
|
|
|
// Wait a bit till the subscription gets to the publisher
|
2013-11-06 13:30:41 +01:00
|
|
|
msleep (SETTLE_TIME);
|
2011-07-11 15:54:13 +02:00
|
|
|
|
2013-01-31 19:46:22 +01:00
|
|
|
// Send an empty message
|
2018-12-07 07:51:30 -05:00
|
|
|
send_string_expect_success (pub, "", 0);
|
2011-07-11 15:54:13 +02:00
|
|
|
|
2013-01-31 19:46:22 +01:00
|
|
|
// Pass the message downstream through the device
|
2018-12-07 07:51:30 -05:00
|
|
|
TEST_ASSERT_SUCCESS_ERRNO (size = zmq_recv (xsub, buff, sizeof (buff), 0));
|
|
|
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_send (xpub, buff, size, 0));
|
2011-07-11 15:54:13 +02:00
|
|
|
|
2013-01-31 19:46:22 +01:00
|
|
|
// Receive the message in the subscriber
|
2018-12-07 07:51:30 -05:00
|
|
|
recv_string_expect_success (sub, "", 0);
|
2011-07-11 15:54:13 +02:00
|
|
|
|
|
|
|
// Clean up.
|
2018-12-07 07:51:30 -05:00
|
|
|
test_context_socket_close (xpub);
|
|
|
|
test_context_socket_close (xsub);
|
|
|
|
test_context_socket_close (pub);
|
|
|
|
test_context_socket_close (sub);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main ()
|
|
|
|
{
|
|
|
|
setup_test_environment ();
|
|
|
|
|
|
|
|
UNITY_BEGIN ();
|
|
|
|
RUN_TEST (test);
|
|
|
|
return UNITY_END ();
|
2011-07-11 15:54:13 +02:00
|
|
|
}
|