| 1 |
#include <catch2/catch.hpp> |
| 2 |
#include <zmq.hpp> |
| 3 |
|
| 4 |
#if (__cplusplus >= 201703L) |
| 5 |
static_assert(std::is_nothrow_swappable<zmq::context_t>::value, |
| 6 |
"context_t should be nothrow swappable"); |
| 7 |
#endif |
| 8 |
|
| 9 |
TEST_CASE("context construct default and destroy", "[context]") |
| 10 |
{ |
| 11 |
zmq::context_t context; |
| 12 |
} |
| 13 |
|
| 14 |
TEST_CASE("context create, close and destroy", "[context]") |
| 15 |
{ |
| 16 |
zmq::context_t context; |
| 17 |
context.close(); |
| 18 |
CHECK(NULL == context.handle()); |
| 19 |
} |
| 20 |
|
| 21 |
TEST_CASE("context shutdown", "[context]") |
| 22 |
{ |
| 23 |
zmq::context_t context; |
| 24 |
context.shutdown(); |
| 25 |
CHECK(NULL != context.handle()); |
| 26 |
context.close(); |
| 27 |
CHECK(NULL == context.handle()); |
| 28 |
} |
| 29 |
|
| 30 |
TEST_CASE("context shutdown again", "[context]") |
| 31 |
{ |
| 32 |
zmq::context_t context; |
| 33 |
context.shutdown(); |
| 34 |
context.shutdown(); |
| 35 |
CHECK(NULL != context.handle()); |
| 36 |
context.close(); |
| 37 |
CHECK(NULL == context.handle()); |
| 38 |
} |
| 39 |
|
| 40 |
#ifdef ZMQ_CPP11 |
| 41 |
TEST_CASE("context swap", "[context]") |
| 42 |
{ |
| 43 |
zmq::context_t context1; |
| 44 |
zmq::context_t context2; |
| 45 |
using std::swap; |
| 46 |
swap(context1, context2); |
| 47 |
} |
| 48 |
|
| 49 |
TEST_CASE("context - use socket after shutdown", "[context]") |
| 50 |
{ |
| 51 |
zmq::context_t context; |
| 52 |
zmq::socket_t sock(context, zmq::socket_type::rep); |
| 53 |
context.shutdown(); |
| 54 |
try |
| 55 |
{ |
| 56 |
sock.connect("inproc://test"); |
| 57 |
zmq::message_t msg; |
| 58 |
(void)sock.recv(msg, zmq::recv_flags::dontwait); |
| 59 |
REQUIRE(false); |
| 60 |
} |
| 61 |
catch (const zmq::error_t& e) |
| 62 |
{ |
| 63 |
REQUIRE(e.num() == ETERM); |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
TEST_CASE("context set/get options", "[context]") |
| 68 |
{ |
| 69 |
zmq::context_t context; |
| 70 |
#if defined(ZMQ_BLOCKY) && defined(ZMQ_IO_THREADS) |
| 71 |
context.set(zmq::ctxopt::blocky, false); |
| 72 |
context.set(zmq::ctxopt::io_threads, 5); |
| 73 |
CHECK(context.get(zmq::ctxopt::io_threads) == 5); |
| 74 |
#endif |
| 75 |
|
| 76 |
CHECK_THROWS_AS( |
| 77 |
context.set(static_cast<zmq::ctxopt>(-42), 5), |
| 78 |
zmq::error_t); |
| 79 |
|
| 80 |
CHECK_THROWS_AS( |
| 81 |
context.get(static_cast<zmq::ctxopt>(-42)), |
| 82 |
zmq::error_t); |
| 83 |
} |
| 84 |
#endif |