2018-05-11 11:43:41 +02:00
|
|
|
#pragma once
|
|
|
|
|
2021-01-02 10:34:04 +01:00
|
|
|
#include <catch2/catch.hpp>
|
2018-05-11 11:43:41 +02:00
|
|
|
#include <zmq.hpp>
|
|
|
|
|
2018-07-05 00:46:47 +02:00
|
|
|
#if defined(ZMQ_CPP11)
|
2018-05-11 11:43:41 +02:00
|
|
|
|
2020-03-24 09:33:50 +01:00
|
|
|
inline std::string bind_ip4_loopback(zmq::socket_t &socket)
|
2018-05-11 11:43:41 +02:00
|
|
|
{
|
2020-03-24 09:33:50 +01:00
|
|
|
socket.bind("tcp://127.0.0.1:*");
|
|
|
|
std::string endpoint(100, ' ');
|
|
|
|
endpoint.resize(socket.get(zmq::sockopt::last_endpoint, zmq::buffer(endpoint)));
|
|
|
|
return endpoint;
|
|
|
|
}
|
2018-05-11 11:43:41 +02:00
|
|
|
|
|
|
|
struct common_server_client_setup
|
|
|
|
{
|
2018-07-05 00:46:47 +02:00
|
|
|
common_server_client_setup(bool initialize = true)
|
|
|
|
{
|
|
|
|
if (initialize)
|
|
|
|
init();
|
|
|
|
}
|
2018-05-11 11:43:41 +02:00
|
|
|
|
|
|
|
void init()
|
|
|
|
{
|
2020-03-24 09:33:50 +01:00
|
|
|
endpoint = bind_ip4_loopback(server);
|
2018-09-23 18:14:25 +02:00
|
|
|
REQUIRE_NOTHROW(client.connect(endpoint));
|
2018-05-11 11:43:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
zmq::context_t context;
|
2018-07-05 00:46:47 +02:00
|
|
|
zmq::socket_t server{context, zmq::socket_type::pair};
|
|
|
|
zmq::socket_t client{context, zmq::socket_type::pair};
|
2018-05-11 11:43:41 +02:00
|
|
|
std::string endpoint;
|
|
|
|
};
|
|
|
|
#endif
|
2020-05-25 00:16:55 +02:00
|
|
|
|
|
|
|
#define CHECK_THROWS_ZMQ_ERROR(ecode, expr) \
|
|
|
|
do { \
|
|
|
|
try { \
|
|
|
|
expr; \
|
|
|
|
CHECK(false); \
|
|
|
|
} \
|
|
|
|
catch (const zmq::error_t &ze) { \
|
|
|
|
INFO(std::string("Unexpected error code: ") + ze.what()); \
|
|
|
|
CHECK(ze.num() == ecode); \
|
|
|
|
} \
|
|
|
|
catch (const std::exception &ex) { \
|
|
|
|
INFO(std::string("Unexpected exception: ") + ex.what()); \
|
|
|
|
CHECK(false); \
|
|
|
|
} \
|
|
|
|
catch (...) { \
|
|
|
|
CHECK(false); \
|
|
|
|
} \
|
|
|
|
} while (false)
|