2024-03-05 11:56:14 +01:00
|
|
|
#include <catch2/catch_all.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();
|
2020-05-04 19:36:08 +02:00
|
|
|
CHECK(NULL == context.handle());
|
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();
|
2020-05-04 19:36:08 +02:00
|
|
|
CHECK(NULL != context.handle());
|
2020-01-27 08:31:46 +01:00
|
|
|
context.close();
|
2020-05-04 19:36:08 +02:00
|
|
|
CHECK(NULL == context.handle());
|
2020-01-27 08:31:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE("context shutdown again", "[context]")
|
|
|
|
{
|
|
|
|
zmq::context_t context;
|
|
|
|
context.shutdown();
|
|
|
|
context.shutdown();
|
2020-05-04 19:36:08 +02:00
|
|
|
CHECK(NULL != context.handle());
|
2020-01-27 08:31:46 +01:00
|
|
|
context.close();
|
2020-05-04 19:36:08 +02:00
|
|
|
CHECK(NULL == context.handle());
|
2020-01-27 08:31:46 +01:00
|
|
|
}
|
|
|
|
|
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;
|
2020-05-16 15:20:48 +02:00
|
|
|
(void)sock.recv(msg, zmq::recv_flags::dontwait);
|
2020-01-27 08:31:46 +01:00
|
|
|
REQUIRE(false);
|
|
|
|
}
|
|
|
|
catch (const zmq::error_t& e)
|
|
|
|
{
|
|
|
|
REQUIRE(e.num() == ETERM);
|
|
|
|
}
|
|
|
|
}
|
2020-02-07 15:39:58 +01:00
|
|
|
|
|
|
|
TEST_CASE("context set/get options", "[context]")
|
|
|
|
{
|
|
|
|
zmq::context_t context;
|
2020-02-21 11:29:12 +01:00
|
|
|
#if defined(ZMQ_BLOCKY) && defined(ZMQ_IO_THREADS)
|
2020-02-07 15:39:58 +01:00
|
|
|
context.set(zmq::ctxopt::blocky, false);
|
|
|
|
context.set(zmq::ctxopt::io_threads, 5);
|
|
|
|
CHECK(context.get(zmq::ctxopt::io_threads) == 5);
|
2020-02-21 11:29:12 +01:00
|
|
|
#endif
|
2020-02-07 15:39:58 +01:00
|
|
|
|
|
|
|
CHECK_THROWS_AS(
|
|
|
|
context.set(static_cast<zmq::ctxopt>(-42), 5),
|
2021-01-02 10:36:02 +01:00
|
|
|
zmq::error_t);
|
2020-02-07 15:39:58 +01:00
|
|
|
|
|
|
|
CHECK_THROWS_AS(
|
|
|
|
context.get(static_cast<zmq::ctxopt>(-42)),
|
2021-01-02 10:36:02 +01:00
|
|
|
zmq::error_t);
|
2020-02-07 15:39:58 +01:00
|
|
|
}
|
2019-04-02 16:01:10 +02:00
|
|
|
#endif
|