|
1 | 1 | #include <gtest/gtest.h>
|
2 | 2 | #include <zmq.hpp>
|
3 | 3 |
|
4 |
| -TEST (message, create_destroy) |
| 4 | +#if defined(ZMQ_CPP11) |
| 5 | +static_assert(!std::is_copy_constructible<zmq::message_t>::value, "message_t should not be copy-constructible"); |
| 6 | +static_assert(!std::is_copy_assignable<zmq::message_t>::value, "message_t should not be copy-assignable"); |
| 7 | +#endif |
| 8 | + |
| 9 | +TEST (message, constructor_default) |
5 | 10 | {
|
6 |
| - zmq::message_t message; |
| 11 | + const zmq::message_t message; |
| 12 | + ASSERT_EQ (0u, message.size ()); |
7 | 13 | }
|
8 | 14 |
|
9 |
| -TEST (message, constructors) |
| 15 | +const char* const data = "Hi"; |
| 16 | + |
| 17 | +TEST (message, constructor_iterators) |
10 | 18 | {
|
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); |
| 19 | + const std::string hi (data); |
| 20 | + const zmq::message_t hi_msg (hi.begin (), hi.end ()); |
| 21 | + ASSERT_EQ (2u, hi_msg.size ()); |
| 22 | + ASSERT_EQ (0, memcmp (data, hi_msg.data (), 2)); |
| 23 | +} |
| 24 | + |
| 25 | +TEST (message, constructor_pointer_size) |
| 26 | +{ |
| 27 | + const std::string hi (data); |
| 28 | + const zmq::message_t hi_msg (hi.data (), hi.size ()); |
| 29 | + ASSERT_EQ (2u, hi_msg.size ()); |
| 30 | + ASSERT_EQ (0, memcmp (data, hi_msg.data (), 2)); |
| 31 | +} |
| 32 | + |
| 33 | +TEST (message, constructor_char_array) { |
| 34 | + const zmq::message_t hi_msg (data, strlen (data)); |
| 35 | + ASSERT_EQ (2u, hi_msg.size ()); |
| 36 | + ASSERT_EQ (0, memcmp (data, hi_msg.data (), 2)); |
| 37 | +} |
| 38 | + |
17 | 39 | #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); |
| 40 | +TEST (message, constructor_container) |
| 41 | +{ |
| 42 | + const std::string hi (data); |
| 43 | + zmq::message_t hi_msg (hi); |
| 44 | + ASSERT_EQ (2u, hi_msg.size ()); |
| 45 | + ASSERT_EQ (0, memcmp (data, hi_msg.data (), 2)); |
| 46 | +} |
25 | 47 | #endif
|
| 48 | + |
26 | 49 | #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); |
| 50 | +TEST (message, constructor_move) |
| 51 | +{ |
| 52 | + zmq::message_t hi_msg (zmq::message_t(data, strlen (data))); |
| 53 | +} |
| 54 | + |
| 55 | +TEST (message, assign_move_empty_before) |
| 56 | +{ |
| 57 | + zmq::message_t hi_msg; |
| 58 | + hi_msg = zmq::message_t (data, strlen (data)); |
| 59 | + ASSERT_EQ (2u, hi_msg.size ()); |
| 60 | + ASSERT_EQ (0, memcmp (data, hi_msg.data (), 2)); |
| 61 | +} |
| 62 | + |
| 63 | +TEST (message, assign_move_empty_after) |
| 64 | +{ |
| 65 | + zmq::message_t hi_msg (data, strlen (data)); |
| 66 | + hi_msg = zmq::message_t(); |
| 67 | + ASSERT_EQ (0u, hi_msg.size ()); |
| 68 | +} |
| 69 | + |
| 70 | +TEST (message, assign_move_empty_before_and_after) |
| 71 | +{ |
| 72 | + zmq::message_t hi_msg; |
| 73 | + hi_msg = zmq::message_t(); |
| 74 | + ASSERT_EQ (0u, hi_msg.size ()); |
| 75 | +} |
29 | 76 | #endif
|
| 77 | + |
| 78 | +TEST (message, equality_self) { |
| 79 | + const zmq::message_t hi_msg (data, strlen (data)); |
| 80 | + ASSERT_EQ (hi_msg, hi_msg); |
| 81 | +} |
| 82 | + |
| 83 | +TEST (message, equality_equal) { |
| 84 | + const zmq::message_t hi_msg_a (data, strlen (data)); |
| 85 | + const zmq::message_t hi_msg_b (data, strlen (data)); |
| 86 | + ASSERT_EQ (hi_msg_a, hi_msg_b); |
30 | 87 | }
|
| 88 | + |
| 89 | +TEST (message, equality_equal_empty) { |
| 90 | + const zmq::message_t msg_a; |
| 91 | + const zmq::message_t msg_b; |
| 92 | + ASSERT_EQ (msg_a, msg_b); |
| 93 | +} |
| 94 | + |
| 95 | +TEST (message, equality_non_equal) { |
| 96 | + const zmq::message_t msg_a ("Hi", 2); |
| 97 | + const zmq::message_t msg_b ("Hello", 5); |
| 98 | + ASSERT_NE (msg_a, msg_b); |
| 99 | +} |
| 100 | + |
| 101 | +TEST (message, equality_non_equal_rhs_empty) { |
| 102 | + const zmq::message_t msg_a ("Hi", 2); |
| 103 | + const zmq::message_t msg_b; |
| 104 | + ASSERT_NE (msg_a, msg_b); |
| 105 | +} |
| 106 | + |
| 107 | +TEST (message, equality_non_equal_lhs_empty) { |
| 108 | + const zmq::message_t msg_a; |
| 109 | + const zmq::message_t msg_b ("Hi", 2); |
| 110 | + ASSERT_NE (msg_a, msg_b); |
| 111 | +} |
| 112 | + |
0 commit comments