|
1 | 1 | #include <gtest/gtest.h>
|
2 | 2 | #include <zmq.hpp>
|
3 | 3 |
|
4 |
| -TEST (message, create_destroy) |
| 4 | +TEST (message, constructor_default) |
5 | 5 | {
|
6 |
| - zmq::message_t message; |
| 6 | + const zmq::message_t message; |
| 7 | + ASSERT_EQ (0u, message.size ()); |
7 | 8 | }
|
8 | 9 |
|
9 |
| -TEST (message, constructors) |
| 10 | +const char* const data = "Hi"; |
| 11 | + |
| 12 | +TEST (message, constructor_iterators) |
10 | 13 | {
|
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 | + |
17 | 34 | #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 | +} |
25 | 42 | #endif
|
| 43 | + |
26 | 44 | #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 | +} |
29 | 49 | #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); |
30 | 60 | }
|
| 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