2018-09-23 18:14:25 +02:00
|
|
|
#include <catch.hpp>
|
2018-03-29 18:14:34 +02:00
|
|
|
#include <zmq.hpp>
|
2018-03-29 17:34:21 +02:00
|
|
|
|
2019-04-02 16:01:10 +02:00
|
|
|
#if (__cplusplus >= 201703L)
|
|
|
|
static_assert(std::is_nothrow_swappable<zmq::context_t>::value,
|
|
|
|
"context_t should be nothrow swappable");
|
|
|
|
#endif
|
|
|
|
|
2018-09-23 18:14:25 +02:00
|
|
|
TEST_CASE("context construct default and destroy", "[context]")
|
2018-03-29 17:34:21 +02:00
|
|
|
{
|
2018-03-29 18:14:34 +02:00
|
|
|
zmq::context_t context;
|
2018-04-02 13:15:34 +02:00
|
|
|
}
|
|
|
|
|
2018-09-23 18:14:25 +02:00
|
|
|
TEST_CASE("context create, close and destroy", "[context]")
|
2018-04-02 13:15:34 +02:00
|
|
|
{
|
|
|
|
zmq::context_t context;
|
2018-05-12 18:28:28 +02:00
|
|
|
context.close();
|
2018-09-23 18:14:25 +02:00
|
|
|
CHECK(NULL == (void *) context);
|
2018-04-02 13:15:34 +02:00
|
|
|
}
|
2019-04-02 16:01:10 +02:00
|
|
|
|
2020-01-27 08:31:46 +01:00
|
|
|
TEST_CASE("context shutdown", "[context]")
|
|
|
|
{
|
|
|
|
zmq::context_t context;
|
|
|
|
context.shutdown();
|
|
|
|
CHECK(NULL != (void *) context);
|
|
|
|
context.close();
|
|
|
|
CHECK(NULL == (void *) context);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE("context shutdown again", "[context]")
|
|
|
|
{
|
|
|
|
zmq::context_t context;
|
|
|
|
context.shutdown();
|
|
|
|
context.shutdown();
|
|
|
|
CHECK(NULL != (void *) context);
|
|
|
|
context.close();
|
|
|
|
CHECK(NULL == (void *) context);
|
|
|
|
}
|
|
|
|
|
2019-04-02 16:01:10 +02:00
|
|
|
#ifdef ZMQ_CPP11
|
|
|
|
TEST_CASE("context swap", "[context]")
|
|
|
|
{
|
|
|
|
zmq::context_t context1;
|
|
|
|
zmq::context_t context2;
|
|
|
|
using std::swap;
|
|
|
|
swap(context1, context2);
|
|
|
|
}
|
2020-01-27 08:31:46 +01:00
|
|
|
|
|
|
|
TEST_CASE("context - use socket after shutdown", "[context]")
|
|
|
|
{
|
|
|
|
zmq::context_t context;
|
|
|
|
zmq::socket_t sock(context, zmq::socket_type::rep);
|
|
|
|
context.shutdown();
|
|
|
|
try
|
|
|
|
{
|
|
|
|
sock.connect("inproc://test");
|
|
|
|
zmq::message_t msg;
|
|
|
|
sock.recv(msg, zmq::recv_flags::dontwait);
|
|
|
|
REQUIRE(false);
|
|
|
|
}
|
|
|
|
catch (const zmq::error_t& e)
|
|
|
|
{
|
|
|
|
REQUIRE(e.num() == ETERM);
|
|
|
|
}
|
|
|
|
}
|
2019-04-02 16:01:10 +02:00
|
|
|
#endif
|