File: context.cpp

package info (click to toggle)
cppzmq 4.10.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 420 kB
  • sloc: cpp: 5,715; sh: 23; makefile: 4
file content (84 lines) | stat: -rw-r--r-- 1,955 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#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");
#endif

TEST_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_CPP11
TEST_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);
#endif

    CHECK_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