test_proxy_single_socket.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 
6 #include <stdlib.h>
7 
8 void setUp ()
9 {
11 }
12 
13 // This is our server task.
14 // It runs a proxy with a single REP socket as both frontend and backend.
15 
16 void server_task (void * /*unused_*/)
17 {
19  void *rep = zmq_socket (get_test_context (), ZMQ_REP);
22 
23  // Control socket receives terminate command from main over inproc
24  void *control = zmq_socket (get_test_context (), ZMQ_REQ);
25  TEST_ASSERT_NOT_NULL (control);
26  TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (control, "inproc://control"));
28 
29  // Use rep as both frontend and backend
30  zmq_proxy (rep, rep, NULL);
31 
34 }
35 
36 
37 // The main thread simply starts several clients and a server, and then
38 // waits for the server to finish.
40 {
41  void *server_thread = zmq_threadstart (&server_task, NULL);
42 
43  // Control socket receives terminate command from main over inproc
44  void *control = test_context_socket (ZMQ_REP);
45  TEST_ASSERT_NOT_NULL (control);
46  TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (control, "inproc://control"));
47  char *my_endpoint = s_recv (control);
49 
50  // client socket pings proxy over tcp
54 
55  send_string_expect_success (req, "msg1", 0);
56  recv_string_expect_success (req, "msg1", 0);
57 
58  send_string_expect_success (req, "msg22", 0);
59  recv_string_expect_success (req, "msg22", 0);
60 
61  test_context_socket_close (control);
64  free (my_endpoint);
65 
66  zmq_threadclose (server_thread);
67 }
68 
69 int main (void)
70 {
72 
73  UNITY_BEGIN ();
75  return UNITY_END ();
76 }
NULL
NULL
Definition: test_security_zap.cpp:405
UNITY_END
return UNITY_END()
setUp
void setUp()
Definition: test_proxy_single_socket.cpp:8
zmq_threadstart
ZMQ_EXPORT void * zmq_threadstart(zmq_thread_fn *func_, void *arg_)
Definition: zmq_utils.cpp:54
RUN_TEST
#define RUN_TEST(func)
Definition: unity_internals.h:615
setup_test_context
void setup_test_context()
Definition: testutil_unity.cpp:179
bind_loopback_ipv4
void bind_loopback_ipv4(void *socket_, char *my_endpoint_, size_t len_)
Definition: testutil_unity.cpp:246
teardown_test_context
void teardown_test_context()
Definition: testutil_unity.cpp:189
get_test_context
void * get_test_context()
Definition: testutil_unity.cpp:184
rep
void * rep[services]
Definition: test_req_relaxed.cpp:11
s_recv
char * s_recv(void *socket_)
Definition: testutil.cpp:123
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
testutil_unity.hpp
server_task
void server_task(void *)
Definition: test_proxy_single_socket.cpp:16
zmq_threadclose
ZMQ_EXPORT void zmq_threadclose(void *thread_)
Definition: zmq_utils.cpp:62
testutil.hpp
ZMQ_REP
#define ZMQ_REP
Definition: zmq.h:262
my_endpoint
char my_endpoint[MAX_SOCKET_STRING]
Definition: test_security_curve.cpp:31
MAX_SOCKET_STRING
#define MAX_SOCKET_STRING
Definition: libzmq/tests/testutil.hpp:35
zmq_bind
ZMQ_EXPORT int zmq_bind(void *s_, const char *addr_)
Definition: zmq.cpp:299
zmq_socket
ZMQ_EXPORT void * zmq_socket(void *, int type_)
Definition: zmq.cpp:230
test_context_socket
void * test_context_socket(int type_)
Definition: testutil_unity.cpp:200
zmq_close
ZMQ_EXPORT int zmq_close(void *s_)
Definition: zmq.cpp:241
send_string_expect_success
void send_string_expect_success(void *socket_, const char *str_, int flags_)
Definition: testutil_unity.cpp:94
req
void * req
Definition: test_req_relaxed.cpp:10
test_proxy_single_socket
void test_proxy_single_socket()
Definition: test_proxy_single_socket.cpp:39
zmq_proxy
ZMQ_EXPORT int zmq_proxy(void *frontend_, void *backend_, void *capture_)
Definition: zmq.cpp:1726
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()
test_context_socket_close
void * test_context_socket_close(void *socket_)
Definition: testutil_unity.cpp:208
TEST_ASSERT_NOT_NULL
#define TEST_ASSERT_NOT_NULL(pointer)
Definition: unity.h:125
main
int main(void)
Definition: test_proxy_single_socket.cpp:69
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