forked from zeromq/cppzmq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmessage.cpp
129 lines (111 loc) · 3 KB
/
message.cpp
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include <gtest/gtest.h>
#include <zmq.hpp>
#if defined(ZMQ_CPP11)
static_assert(!std::is_copy_constructible<zmq::message_t>::value,
"message_t should not be copy-constructible");
static_assert(!std::is_copy_assignable<zmq::message_t>::value,
"message_t should not be copy-assignable");
#endif
TEST(message, constructor_default)
{
const zmq::message_t message;
ASSERT_EQ(0u, message.size());
}
const char *const data = "Hi";
TEST(message, constructor_iterators)
{
const std::string hi(data);
const zmq::message_t hi_msg(hi.begin(), hi.end());
ASSERT_EQ(2u, hi_msg.size());
ASSERT_EQ(0, memcmp(data, hi_msg.data(), 2));
}
TEST(message, constructor_pointer_size)
{
const std::string hi(data);
const zmq::message_t hi_msg(hi.data(), hi.size());
ASSERT_EQ(2u, hi_msg.size());
ASSERT_EQ(0, memcmp(data, hi_msg.data(), 2));
}
TEST(message, constructor_char_array)
{
const zmq::message_t hi_msg(data, strlen(data));
ASSERT_EQ(2u, hi_msg.size());
ASSERT_EQ(0, memcmp(data, hi_msg.data(), 2));
}
#if defined(ZMQ_BUILD_DRAFT_API) && defined(ZMQ_CPP11)
TEST(message, constructor_container)
{
const std::string hi(data);
zmq::message_t hi_msg(hi);
ASSERT_EQ(2u, hi_msg.size());
ASSERT_EQ(0, memcmp(data, hi_msg.data(), 2));
}
#endif
#ifdef ZMQ_HAS_RVALUE_REFS
TEST(message, constructor_move)
{
zmq::message_t hi_msg(zmq::message_t(data, strlen(data)));
}
TEST(message, assign_move_empty_before)
{
zmq::message_t hi_msg;
hi_msg = zmq::message_t(data, strlen(data));
ASSERT_EQ(2u, hi_msg.size());
ASSERT_EQ(0, memcmp(data, hi_msg.data(), 2));
}
TEST(message, assign_move_empty_after)
{
zmq::message_t hi_msg(data, strlen(data));
hi_msg = zmq::message_t();
ASSERT_EQ(0u, hi_msg.size());
}
TEST(message, assign_move_empty_before_and_after)
{
zmq::message_t hi_msg;
hi_msg = zmq::message_t();
ASSERT_EQ(0u, hi_msg.size());
}
#endif
TEST(message, equality_self)
{
const zmq::message_t hi_msg(data, strlen(data));
ASSERT_EQ(hi_msg, hi_msg);
}
TEST(message, equality_equal)
{
const zmq::message_t hi_msg_a(data, strlen(data));
const zmq::message_t hi_msg_b(data, strlen(data));
ASSERT_EQ(hi_msg_a, hi_msg_b);
}
TEST(message, equality_equal_empty)
{
const zmq::message_t msg_a;
const zmq::message_t msg_b;
ASSERT_EQ(msg_a, msg_b);
}
TEST(message, equality_non_equal)
{
const zmq::message_t msg_a("Hi", 2);
const zmq::message_t msg_b("Hello", 5);
ASSERT_NE(msg_a, msg_b);
}
TEST(message, equality_non_equal_rhs_empty)
{
const zmq::message_t msg_a("Hi", 2);
const zmq::message_t msg_b;
ASSERT_NE(msg_a, msg_b);
}
TEST(message, equality_non_equal_lhs_empty)
{
const zmq::message_t msg_a;
const zmq::message_t msg_b("Hi", 2);
ASSERT_NE(msg_a, msg_b);
}
#if defined(ZMQ_BUILD_DRAFT_API) && ZMQ_VERSION >= ZMQ_MAKE_VERSION(4, 2, 0)
TEST(message, routing_id_persists)
{
zmq::message_t msg;
msg.set_routing_id(123);
ASSERT_EQ(123u, msg.routing_id());
}
#endif