Skip to content

Commit 799c89c

Browse files
committed
Problem: several test cases mixed in message.constructors
Solution: split up into test cases for various ctors and equality operators
1 parent a186ed6 commit 799c89c

File tree

1 file changed

+55
-18
lines changed

1 file changed

+55
-18
lines changed

tests/message.cpp

Lines changed: 55 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,67 @@
11
#include <gtest/gtest.h>
22
#include <zmq.hpp>
33

4-
TEST (message, create_destroy)
4+
TEST (message, constructor_default)
55
{
6-
zmq::message_t message;
6+
const zmq::message_t message;
7+
ASSERT_EQ (0u, message.size ());
78
}
89

9-
TEST (message, constructors)
10+
const char* const data = "Hi";
11+
12+
TEST (message, constructor_iterators)
1013
{
11-
const std::string hi ("Hi");
12-
zmq::message_t hi_msg_a (hi.begin (), hi.end ());
13-
ASSERT_EQ (hi_msg_a.size (), hi.size ());
14-
zmq::message_t hi_msg_b (hi.data (), hi.size ());
15-
ASSERT_EQ (hi_msg_b.size (), hi.size ());
16-
ASSERT_EQ (hi_msg_a, hi_msg_b);
14+
const std::string hi (data);
15+
const zmq::message_t hi_msg (hi.begin (), hi.end ());
16+
ASSERT_EQ (2u, hi_msg.size ());
17+
ASSERT_EQ (0, memcmp (data, hi_msg.data (), 2));
18+
}
19+
20+
TEST (message, constructor_pointer_size)
21+
{
22+
const std::string hi (data);
23+
const zmq::message_t hi_msg (hi.data (), hi.size ());
24+
ASSERT_EQ (2u, hi_msg.size ());
25+
ASSERT_EQ (0, memcmp (data, hi_msg.data (), 2));
26+
}
27+
28+
TEST (message, constructor_char_array) {
29+
const zmq::message_t hi_msg (data, strlen (data));
30+
ASSERT_EQ (2u, hi_msg.size ());
31+
ASSERT_EQ (0, memcmp (data, hi_msg.data (), 2));
32+
}
33+
1734
#if defined(ZMQ_BUILD_DRAFT_API) && defined(ZMQ_CPP11)
18-
zmq::message_t hello_msg_a ("Hello");
19-
ASSERT_NE (hi_msg_a, hello_msg_a);
20-
ASSERT_NE (hi_msg_b, hello_msg_a);
21-
zmq::message_t hi_msg_c (hi);
22-
ASSERT_EQ (hi_msg_c, hi_msg_a);
23-
ASSERT_EQ (hi_msg_c, hi_msg_b);
24-
ASSERT_NE (hi_msg_c, hello_msg_a);
35+
TEST (message, constructor_container)
36+
{
37+
const std::string hi (data);
38+
zmq::message_t hi_msg (hi);
39+
ASSERT_EQ (2u, hi_msg.size ());
40+
ASSERT_EQ (0, memcmp (data, hi_msg.data (), 2));
41+
}
2542
#endif
43+
2644
#ifdef ZMQ_HAS_RVALUE_REFS
27-
zmq::message_t hello_msg_b(zmq::message_t("Hello"));
28-
ASSERT_EQ (hello_msg_a, hello_msg_b);
45+
TEST (message, constructor_move)
46+
{
47+
zmq::message_t hi_msg (zmq::message_t(data, strlen (data)));
48+
}
2949
#endif
50+
51+
TEST (message, equality_self) {
52+
const zmq::message_t hi_msg (data, strlen (data));
53+
ASSERT_EQ (hi_msg, hi_msg);
54+
}
55+
56+
TEST (message, equality_equal) {
57+
const zmq::message_t hi_msg_a (data, strlen (data));
58+
const zmq::message_t hi_msg_b (data, strlen (data));
59+
ASSERT_EQ (hi_msg_a, hi_msg_b);
3060
}
61+
62+
TEST (message, equality_non_equal) {
63+
const zmq::message_t msg_a ("Hi", 2);
64+
const zmq::message_t msg_b ("Hello", 5);
65+
ASSERT_NE (msg_a, msg_b);
66+
}
67+

0 commit comments

Comments
 (0)