context.cpp
Go to the documentation of this file.
1 #include <catch2/catch_all.hpp>
2 #include <zmq.hpp>
3 
4 #if (__cplusplus >= 201703L)
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;
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
TEST_CASE
TEST_CASE("context construct default and destroy", "[context]")
Definition: context.cpp:9
zmq::swap
void swap(message_t &a, message_t &b) ZMQ_NOTHROW
Definition: zmq.hpp:749
zmq::message_t
Definition: zmq.hpp:409
NULL
NULL
Definition: test_security_zap.cpp:405
sock
void * sock
Definition: test_connect_resolve.cpp:9
zmq::socket_t
Definition: zmq.hpp:2188
rep
void * rep[services]
Definition: test_req_relaxed.cpp:11
zmq::context_t::close
void close() ZMQ_NOTHROW
Definition: zmq.hpp:867
zmq.hpp
zmq::context_t
Definition: zmq.hpp:799
zmq::context_t::handle
ZMQ_NODISCARD void * handle() ZMQ_NOTHROW
Definition: zmq.hpp:899
zmq::error_t::num
int num() const ZMQ_NOTHROW
Definition: zmq.hpp:299
ETERM
#define ETERM
Definition: zmq.h:161
std::swap
void swap(Json::Value &a, Json::Value &b)
Specialize std::swap() for Json::Value.
Definition: json.h:1226
CHECK
#define CHECK(x)
Definition: php/ext/google/protobuf/upb.c:8393
zmq::context_t::shutdown
void shutdown() ZMQ_NOTHROW
Definition: zmq.hpp:884
void
typedef void(APIENTRY *GLDEBUGPROCARB)(GLenum source
value
GLsizei const GLfloat * value
Definition: glcorearb.h:3093
zmq::error_t
Definition: zmq.hpp:290


libaditof
Author(s):
autogenerated on Wed May 21 2025 02:06:48