2018-04-14 13:03:44 +02:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
#include <zmq.hpp>
|
|
|
|
|
2018-04-13 17:35:00 +02:00
|
|
|
#if defined(ZMQ_CPP11)
|
2018-05-12 18:28:28 +02:00
|
|
|
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");
|
2018-04-13 17:35:00 +02:00
|
|
|
#endif
|
|
|
|
|
2018-05-12 18:28:28 +02:00
|
|
|
TEST(message, constructor_default)
|
2018-04-14 13:03:44 +02:00
|
|
|
{
|
2018-04-13 17:20:07 +02:00
|
|
|
const zmq::message_t message;
|
2018-05-12 18:28:28 +02:00
|
|
|
ASSERT_EQ(0u, message.size());
|
2018-04-14 13:03:44 +02:00
|
|
|
}
|
|
|
|
|
2018-05-11 21:29:15 +02:00
|
|
|
const char *const data = "Hi";
|
2018-04-13 17:20:07 +02:00
|
|
|
|
2018-05-12 18:28:28 +02:00
|
|
|
TEST(message, constructor_iterators)
|
2018-04-14 13:03:44 +02:00
|
|
|
{
|
2018-05-12 18:28:28 +02:00
|
|
|
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));
|
2018-04-13 17:20:07 +02:00
|
|
|
}
|
|
|
|
|
2018-05-12 18:28:28 +02:00
|
|
|
TEST(message, constructor_pointer_size)
|
2018-04-13 17:20:07 +02:00
|
|
|
{
|
2018-05-12 18:28:28 +02:00
|
|
|
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));
|
2018-04-13 17:20:07 +02:00
|
|
|
}
|
|
|
|
|
2018-05-12 18:28:28 +02:00
|
|
|
TEST(message, constructor_char_array)
|
2018-05-11 21:29:15 +02:00
|
|
|
{
|
2018-05-12 18:28:28 +02:00
|
|
|
const zmq::message_t hi_msg(data, strlen(data));
|
|
|
|
ASSERT_EQ(2u, hi_msg.size());
|
|
|
|
ASSERT_EQ(0, memcmp(data, hi_msg.data(), 2));
|
2018-04-13 17:20:07 +02:00
|
|
|
}
|
|
|
|
|
2018-04-14 13:03:44 +02:00
|
|
|
#if defined(ZMQ_BUILD_DRAFT_API) && defined(ZMQ_CPP11)
|
2018-05-12 18:28:28 +02:00
|
|
|
TEST(message, constructor_container)
|
2018-04-13 17:20:07 +02:00
|
|
|
{
|
2018-05-12 18:28:28 +02:00
|
|
|
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));
|
2018-04-13 17:20:07 +02:00
|
|
|
}
|
2018-04-14 13:03:44 +02:00
|
|
|
#endif
|
2018-04-13 17:20:07 +02:00
|
|
|
|
2018-04-14 13:03:44 +02:00
|
|
|
#ifdef ZMQ_HAS_RVALUE_REFS
|
2018-05-12 18:28:28 +02:00
|
|
|
TEST(message, constructor_move)
|
2018-04-13 17:20:07 +02:00
|
|
|
{
|
2018-05-12 18:28:28 +02:00
|
|
|
zmq::message_t hi_msg(zmq::message_t(data, strlen(data)));
|
2018-04-13 17:20:07 +02:00
|
|
|
}
|
2018-04-13 17:35:00 +02:00
|
|
|
|
2018-05-12 18:28:28 +02:00
|
|
|
TEST(message, assign_move_empty_before)
|
2018-04-13 17:35:00 +02:00
|
|
|
{
|
|
|
|
zmq::message_t hi_msg;
|
2018-05-12 18:28:28 +02:00
|
|
|
hi_msg = zmq::message_t(data, strlen(data));
|
|
|
|
ASSERT_EQ(2u, hi_msg.size());
|
|
|
|
ASSERT_EQ(0, memcmp(data, hi_msg.data(), 2));
|
2018-04-13 17:35:00 +02:00
|
|
|
}
|
|
|
|
|
2018-05-12 18:28:28 +02:00
|
|
|
TEST(message, assign_move_empty_after)
|
2018-04-13 17:35:00 +02:00
|
|
|
{
|
2018-05-12 18:28:28 +02:00
|
|
|
zmq::message_t hi_msg(data, strlen(data));
|
|
|
|
hi_msg = zmq::message_t();
|
|
|
|
ASSERT_EQ(0u, hi_msg.size());
|
2018-04-13 17:35:00 +02:00
|
|
|
}
|
|
|
|
|
2018-05-12 18:28:28 +02:00
|
|
|
TEST(message, assign_move_empty_before_and_after)
|
2018-04-13 17:35:00 +02:00
|
|
|
{
|
|
|
|
zmq::message_t hi_msg;
|
2018-05-12 18:28:28 +02:00
|
|
|
hi_msg = zmq::message_t();
|
|
|
|
ASSERT_EQ(0u, hi_msg.size());
|
2018-04-13 17:35:00 +02:00
|
|
|
}
|
2018-04-14 13:03:44 +02:00
|
|
|
#endif
|
2018-04-13 17:20:07 +02:00
|
|
|
|
2018-05-12 18:28:28 +02:00
|
|
|
TEST(message, equality_self)
|
2018-05-11 21:29:15 +02:00
|
|
|
{
|
2018-05-12 18:28:28 +02:00
|
|
|
const zmq::message_t hi_msg(data, strlen(data));
|
|
|
|
ASSERT_EQ(hi_msg, hi_msg);
|
2018-04-13 17:20:07 +02:00
|
|
|
}
|
|
|
|
|
2018-05-12 18:28:28 +02:00
|
|
|
TEST(message, equality_equal)
|
2018-05-11 21:29:15 +02:00
|
|
|
{
|
2018-05-12 18:28:28 +02:00
|
|
|
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);
|
2018-04-14 13:03:44 +02:00
|
|
|
}
|
2018-04-13 17:20:07 +02:00
|
|
|
|
2018-05-12 18:28:28 +02:00
|
|
|
TEST(message, equality_equal_empty)
|
2018-05-11 21:29:15 +02:00
|
|
|
{
|
2018-04-13 17:24:36 +02:00
|
|
|
const zmq::message_t msg_a;
|
|
|
|
const zmq::message_t msg_b;
|
2018-05-12 18:28:28 +02:00
|
|
|
ASSERT_EQ(msg_a, msg_b);
|
2018-04-13 17:24:36 +02:00
|
|
|
}
|
|
|
|
|
2018-05-12 18:28:28 +02:00
|
|
|
TEST(message, equality_non_equal)
|
2018-05-11 21:29:15 +02:00
|
|
|
{
|
2018-05-12 18:28:28 +02:00
|
|
|
const zmq::message_t msg_a("Hi", 2);
|
|
|
|
const zmq::message_t msg_b("Hello", 5);
|
|
|
|
ASSERT_NE(msg_a, msg_b);
|
2018-04-13 17:20:07 +02:00
|
|
|
}
|
|
|
|
|
2018-05-12 18:28:28 +02:00
|
|
|
TEST(message, equality_non_equal_rhs_empty)
|
2018-05-11 21:29:15 +02:00
|
|
|
{
|
2018-05-12 18:28:28 +02:00
|
|
|
const zmq::message_t msg_a("Hi", 2);
|
2018-04-13 17:24:36 +02:00
|
|
|
const zmq::message_t msg_b;
|
2018-05-12 18:28:28 +02:00
|
|
|
ASSERT_NE(msg_a, msg_b);
|
2018-04-13 17:24:36 +02:00
|
|
|
}
|
|
|
|
|
2018-05-12 18:28:28 +02:00
|
|
|
TEST(message, equality_non_equal_lhs_empty)
|
2018-05-11 21:29:15 +02:00
|
|
|
{
|
2018-04-13 17:24:36 +02:00
|
|
|
const zmq::message_t msg_a;
|
2018-05-12 18:28:28 +02:00
|
|
|
const zmq::message_t msg_b("Hi", 2);
|
|
|
|
ASSERT_NE(msg_a, msg_b);
|
2018-04-13 17:24:36 +02:00
|
|
|
}
|
2018-05-19 07:44:41 +02:00
|
|
|
|
|
|
|
#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());
|
|
|
|
}
|
2018-07-13 15:01:15 +02:00
|
|
|
|
|
|
|
TEST(message, group_persists)
|
|
|
|
{
|
|
|
|
zmq::message_t msg;
|
|
|
|
msg.set_group("mygroup");
|
|
|
|
ASSERT_STREQ("mygroup", msg.group());
|
|
|
|
}
|
2018-05-19 07:44:41 +02:00
|
|
|
#endif
|