#include <catch2/catch.hpp>#include <zmq.hpp>#if (__cplusplus >= 201703L)static_assert(std::is_nothrow_swappable<zmq::context_t>::value,"context_t should be nothrow swappable");#endifTEST_CASE("context construct default and destroy", "[context]"){zmq::context_t context;}TEST_CASE("context create, close and destroy", "[context]"){zmq::context_t context;context.close();CHECK(NULL == context.handle());}TEST_CASE("context shutdown", "[context]"){zmq::context_t context;context.shutdown();CHECK(NULL != context.handle());context.close();CHECK(NULL == context.handle());}TEST_CASE("context shutdown again", "[context]"){zmq::context_t context;context.shutdown();context.shutdown();CHECK(NULL != context.handle());context.close();CHECK(NULL == context.handle());}#ifdef ZMQ_CPP11TEST_CASE("context swap", "[context]"){zmq::context_t context1;zmq::context_t context2;using std::swap;swap(context1, context2);}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;(void)sock.recv(msg, zmq::recv_flags::dontwait);REQUIRE(false);}catch (const zmq::error_t& e){REQUIRE(e.num() == ETERM);}}TEST_CASE("context set/get options", "[context]"){zmq::context_t context;#if defined(ZMQ_BLOCKY) && defined(ZMQ_IO_THREADS)context.set(zmq::ctxopt::blocky, false);context.set(zmq::ctxopt::io_threads, 5);CHECK(context.get(zmq::ctxopt::io_threads) == 5);#endifCHECK_THROWS_AS(context.set(static_cast<zmq::ctxopt>(-42), 5),zmq::error_t);CHECK_THROWS_AS(context.get(static_cast<zmq::ctxopt>(-42)),zmq::error_t);}#endif
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。