cppzmq/tests/testutil.hpp
Gudmundur Adalsteinsson a3e5b54c3c
Problem: Socket options lack type-safety (#393)
Solution: Implement a type for each socket option.

Each option has an associated type, therefore they
can't be simply defined as an enum class.

Use new sockopt getter in test util

Add socket option get function for strings and tests
2020-03-24 09:33:50 +01:00

36 lines
780 B
C++

#pragma once
#include <catch.hpp>
#include <zmq.hpp>
#if defined(ZMQ_CPP11)
inline std::string bind_ip4_loopback(zmq::socket_t &socket)
{
socket.bind("tcp://127.0.0.1:*");
std::string endpoint(100, ' ');
endpoint.resize(socket.get(zmq::sockopt::last_endpoint, zmq::buffer(endpoint)));
return endpoint;
}
struct common_server_client_setup
{
common_server_client_setup(bool initialize = true)
{
if (initialize)
init();
}
void init()
{
endpoint = bind_ip4_loopback(server);
REQUIRE_NOTHROW(client.connect(endpoint));
}
zmq::context_t context;
zmq::socket_t server{context, zmq::socket_type::pair};
zmq::socket_t client{context, zmq::socket_type::pair};
std::string endpoint;
};
#endif