cppzmq/tests/testutil.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <catch2/catch_all.hpp>
4 #include <zmq.hpp>
5 
6 #if defined(ZMQ_CPP11)
7 
8 inline std::string bind_ip4_loopback(zmq::socket_t &socket)
9 {
10  socket.bind("tcp://127.0.0.1:*");
11  std::string endpoint(100, ' ');
12  endpoint.resize(socket.get(zmq::sockopt::last_endpoint, zmq::buffer(endpoint)));
13  return endpoint;
14 }
15 
16 struct common_server_client_setup
17 {
18  common_server_client_setup(bool initialize = true)
19  {
20  if (initialize)
21  init();
22  }
23 
24  void init()
25  {
26  endpoint = bind_ip4_loopback(server);
27  REQUIRE_NOTHROW(client.connect(endpoint));
28  }
29 
30  zmq::context_t context;
31  zmq::socket_t server{context, zmq::socket_type::pair};
32  zmq::socket_t client{context, zmq::socket_type::pair};
33  std::string endpoint;
34 };
35 #endif
36 
37 #define CHECK_THROWS_ZMQ_ERROR(ecode, expr) \
38  do { \
39  try { \
40  expr; \
41  CHECK(false); \
42  } \
43  catch (const zmq::error_t &ze) { \
44  INFO(std::string("Unexpected error code: ") + ze.what()); \
45  CHECK(ze.num() == ecode); \
46  } \
47  catch (const std::exception &ex) { \
48  INFO(std::string("Unexpected exception: ") + ex.what()); \
49  CHECK(false); \
50  } \
51  catch (...) { \
52  CHECK(false); \
53  } \
54  } while (false)
init
WEPOLL_INTERNAL int init(void)
Definition: wepoll.c:858
zmq::socket_t
Definition: zmq.hpp:2188
string
GLsizei const GLchar *const * string
Definition: glcorearb.h:3083
client
void client(int num)
Definition: test_multithread.cpp:134
zmq.hpp
zmq::context_t
Definition: zmq.hpp:799
buffer
GLuint buffer
Definition: glcorearb.h:2939
server
void * server
Definition: test_security_curve.cpp:29
zmq::detail::socket_base::bind
void bind(std::string const &addr)
Definition: zmq.hpp:1883


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