test_sub_forward_tipc.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: MPL-2.0 */
2 
3 #include "testutil.hpp"
4 #include "testutil_unity.hpp"
5 
7 
8 void test ()
9 {
10  // First, create an intermediate device.
11  void *xpub = test_context_socket (ZMQ_XPUB);
12  TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (xpub, "tipc://{5560,0,0}"));
13  void *xsub = test_context_socket (ZMQ_XSUB);
14  TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (xsub, "tipc://{5561,0,0}"));
15 
16  // Create a publisher.
17  void *pub = test_context_socket (ZMQ_PUB);
18  TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (pub, "tipc://{5561,0}@0.0.0"));
19 
20  // Create a subscriber.
21  void *sub = test_context_socket (ZMQ_SUB);
22  TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sub, "tipc://{5560,0}@0.0.0"));
23 
24  // TODO the remainder of this method is duplicated with test_sub_forward
25 
26  // Subscribe for all messages.
28 
29  // Pass the subscription upstream through the device
30  char buff[32];
31  int size;
32  TEST_ASSERT_SUCCESS_ERRNO (size = zmq_recv (xpub, buff, sizeof (buff), 0));
33  TEST_ASSERT_SUCCESS_ERRNO (zmq_send (xsub, buff, size, 0));
34 
35  // Wait a bit till the subscription gets to the publisher
37 
38  // Send an empty message
39  send_string_expect_success (pub, "", 0);
40 
41  // Pass the message downstream through the device
42  TEST_ASSERT_SUCCESS_ERRNO (size = zmq_recv (xsub, buff, sizeof (buff), 0));
43  TEST_ASSERT_SUCCESS_ERRNO (zmq_send (xpub, buff, size, 0));
44 
45  // Receive the message in the subscriber
46  recv_string_expect_success (sub, "", 0);
47 
48  // Clean up.
53 }
54 
55 int main ()
56 {
57  if (!is_tipc_available ()) {
58  printf ("TIPC environment unavailable, skipping test\n");
59  return 77;
60  }
61 
62  UNITY_BEGIN ();
63  RUN_TEST (test);
64  return UNITY_END ();
65 }
UNITY_END
return UNITY_END()
ZMQ_XPUB
#define ZMQ_XPUB
Definition: zmq.h:267
ZMQ_PUB
#define ZMQ_PUB
Definition: zmq.h:259
msleep
void msleep(int milliseconds_)
Definition: testutil.cpp:227
RUN_TEST
#define RUN_TEST(func)
Definition: unity_internals.h:615
SETUP_TEARDOWN_TESTCONTEXT
#define SETUP_TEARDOWN_TESTCONTEXT
Definition: testutil_unity.hpp:172
ZMQ_SUBSCRIBE
#define ZMQ_SUBSCRIBE
Definition: zmq.h:278
ZMQ_XSUB
#define ZMQ_XSUB
Definition: zmq.h:268
ZMQ_SUB
#define ZMQ_SUB
Definition: zmq.h:260
main
int main()
Definition: test_sub_forward_tipc.cpp:55
zmq_connect
ZMQ_EXPORT int zmq_connect(void *s_, const char *addr_)
Definition: zmq.cpp:307
testutil_unity.hpp
zmq_setsockopt
ZMQ_EXPORT int zmq_setsockopt(void *s_, int option_, const void *optval_, size_t optvallen_)
Definition: zmq.cpp:250
testutil.hpp
zmq_bind
ZMQ_EXPORT int zmq_bind(void *s_, const char *addr_)
Definition: zmq.cpp:299
size
#define size
Definition: glcorearb.h:2944
is_tipc_available
int is_tipc_available()
Definition: testutil.cpp:283
test_context_socket
void * test_context_socket(int type_)
Definition: testutil_unity.cpp:200
SETTLE_TIME
#define SETTLE_TIME
Definition: libzmq/tests/testutil.hpp:31
send_string_expect_success
void send_string_expect_success(void *socket_, const char *str_, int flags_)
Definition: testutil_unity.cpp:94
zmq_recv
ZMQ_EXPORT int zmq_recv(void *s_, void *buf_, size_t len_, int flags_)
Definition: zmq.cpp:487
size
GLsizeiptr size
Definition: glcorearb.h:2943
recv_string_expect_success
void recv_string_expect_success(void *socket_, const char *str_, int flags_)
Definition: testutil_unity.cpp:101
UNITY_BEGIN
UNITY_BEGIN()
test
SETUP_TEARDOWN_TESTCONTEXT void test()
Definition: test_sub_forward_tipc.cpp:8
zmq_send
ZMQ_EXPORT int zmq_send(void *s_, const void *buf_, size_t len_, int flags_)
Definition: zmq.cpp:377
test_context_socket_close
void * test_context_socket_close(void *socket_)
Definition: testutil_unity.cpp:208
TEST_ASSERT_SUCCESS_ERRNO
#define TEST_ASSERT_SUCCESS_ERRNO(expr)
Definition: proxy_thr.cpp:47


libaditof
Author(s):
autogenerated on Wed May 21 2025 02:06:59