test_invalid_rep.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 
9 {
10  // Create REQ/ROUTER wiring.
11  void *router_socket = test_context_socket (ZMQ_ROUTER);
12  void *req_socket = test_context_socket (ZMQ_REQ);
13 
14  int linger = 0;
16  zmq_setsockopt (router_socket, ZMQ_LINGER, &linger, sizeof (int)));
18  zmq_setsockopt (req_socket, ZMQ_LINGER, &linger, sizeof (int)));
19  TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (router_socket, "inproc://hi"));
20  TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (req_socket, "inproc://hi"));
21 
22  // Initial request.
23  send_string_expect_success (req_socket, "r", 0);
24 
25  // Receive the request.
26  char addr[32];
27  int addr_size;
28  char bottom[1];
29  char body[1];
31  addr_size = zmq_recv (router_socket, addr, sizeof (addr), 0));
33  router_socket, bottom, sizeof (bottom), 0)));
35  router_socket, body, sizeof (body), 0)));
36 
37  // Send invalid reply.
39  router_socket, addr, addr_size, 0)));
40 
41  // Send valid reply.
43  addr_size, TEST_ASSERT_SUCCESS_ERRNO (
44  zmq_send (router_socket, addr, addr_size, ZMQ_SNDMORE)));
46  router_socket, bottom, 0, ZMQ_SNDMORE)));
47  send_string_expect_success (router_socket, "b", 0);
48 
49  // Check whether we've got the valid reply.
50  recv_string_expect_success (req_socket, "b", 0);
51 
52  // Tear down the wiring.
53  test_context_socket_close (router_socket);
54  test_context_socket_close (req_socket);
55 }
56 
57 int main ()
58 {
60 
61  UNITY_BEGIN ();
63  return UNITY_END ();
64 }
UNITY_END
return UNITY_END()
RUN_TEST
#define RUN_TEST(func)
Definition: unity_internals.h:615
SETUP_TEARDOWN_TESTCONTEXT
#define SETUP_TEARDOWN_TESTCONTEXT
Definition: testutil_unity.hpp:172
ZMQ_REQ
#define ZMQ_REQ
Definition: zmq.h:261
zmq_connect
ZMQ_EXPORT int zmq_connect(void *s_, const char *addr_)
Definition: zmq.cpp:307
main
int main()
Definition: test_invalid_rep.cpp:57
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_ROUTER
#define ZMQ_ROUTER
Definition: zmq.h:264
zmq_bind
ZMQ_EXPORT int zmq_bind(void *s_, const char *addr_)
Definition: zmq.cpp:299
test_context_socket
void * test_context_socket(int type_)
Definition: testutil_unity.cpp:200
TEST_ASSERT_EQUAL_INT
#define TEST_ASSERT_EQUAL_INT(expected, actual)
Definition: unity.h:128
ZMQ_LINGER
#define ZMQ_LINGER
Definition: zmq.h:288
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
recv_string_expect_success
void recv_string_expect_success(void *socket_, const char *str_, int flags_)
Definition: testutil_unity.cpp:101
setup_test_environment
void setup_test_environment(int timeout_seconds_)
Definition: testutil.cpp:201
UNITY_BEGIN
UNITY_BEGIN()
ZMQ_SNDMORE
#define ZMQ_SNDMORE
Definition: zmq.h:359
test_invalid_rep
SETUP_TEARDOWN_TESTCONTEXT void test_invalid_rep()
Definition: test_invalid_rep.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
bottom
GLint GLint bottom
Definition: glcorearb.h:4150
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