2018-09-23 18:14:25 +02:00
|
|
|
#define CATCH_CONFIG_MAIN
|
|
|
|
#include <catch.hpp>
|
2018-04-14 13:03:44 +02:00
|
|
|
#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,
|
2020-01-26 10:09:20 +01:00
|
|
|
"message_t should not be copy-constructible");
|
2018-05-12 18:28:28 +02:00
|
|
|
static_assert(!std::is_copy_assignable<zmq::message_t>::value,
|
2020-01-26 10:09:20 +01:00
|
|
|
"message_t should not be copy-assignable");
|
2018-04-13 17:35:00 +02:00
|
|
|
#endif
|
2019-04-02 16:01:10 +02:00
|
|
|
#if (__cplusplus >= 201703L)
|
|
|
|
static_assert(std::is_nothrow_swappable<zmq::message_t>::value,
|
|
|
|
"message_t should be nothrow swappable");
|
|
|
|
#endif
|
2018-04-13 17:35:00 +02:00
|
|
|
|
2018-09-23 18:14:25 +02:00
|
|
|
TEST_CASE("message default constructed", "[message]")
|
2018-04-14 13:03:44 +02:00
|
|
|
{
|
2018-04-13 17:20:07 +02:00
|
|
|
const zmq::message_t message;
|
2018-09-23 18:14:25 +02:00
|
|
|
CHECK(0u == message.size());
|
2019-04-04 19:55:27 +02:00
|
|
|
CHECK(message.empty());
|
2018-04-14 13:03:44 +02:00
|
|
|
}
|
|
|
|
|
2019-04-02 16:01:10 +02:00
|
|
|
#ifdef ZMQ_CPP11
|
|
|
|
TEST_CASE("message swap", "[message]")
|
|
|
|
{
|
|
|
|
const std::string data = "foo";
|
|
|
|
zmq::message_t message1;
|
|
|
|
zmq::message_t message2(data.data(), data.size());
|
|
|
|
using std::swap;
|
|
|
|
swap(message1, message2);
|
|
|
|
CHECK(message1.size() == data.size());
|
|
|
|
CHECK(message2.size() == 0);
|
|
|
|
swap(message1, message2);
|
|
|
|
CHECK(message1.size() == 0);
|
|
|
|
CHECK(message2.size() == data.size());
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-01-26 10:09:20 +01:00
|
|
|
namespace
|
|
|
|
{
|
2018-05-11 21:29:15 +02:00
|
|
|
const char *const data = "Hi";
|
2018-09-23 18:14:25 +02:00
|
|
|
}
|
2018-04-13 17:20:07 +02:00
|
|
|
|
2018-09-23 18:14:25 +02:00
|
|
|
TEST_CASE("message constructor with iterators", "[message]")
|
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());
|
2018-09-23 18:14:25 +02:00
|
|
|
CHECK(2u == hi_msg.size());
|
|
|
|
CHECK(0 == memcmp(data, hi_msg.data(), 2));
|
2018-04-13 17:20:07 +02:00
|
|
|
}
|
|
|
|
|
2019-05-15 18:49:22 +02:00
|
|
|
TEST_CASE("message constructor with size", "[message]")
|
|
|
|
{
|
|
|
|
const zmq::message_t msg(5);
|
|
|
|
CHECK(msg.size() == 5);
|
|
|
|
}
|
|
|
|
|
2018-09-23 18:14:25 +02:00
|
|
|
TEST_CASE("message constructor with buffer and size", "[message]")
|
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());
|
2018-09-23 18:14:25 +02:00
|
|
|
CHECK(2u == hi_msg.size());
|
|
|
|
CHECK(0 == memcmp(data, hi_msg.data(), 2));
|
2018-04-13 17:20:07 +02:00
|
|
|
}
|
|
|
|
|
2018-09-23 18:14:25 +02:00
|
|
|
TEST_CASE("message constructor with char array", "[message]")
|
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));
|
2018-09-23 18:14:25 +02:00
|
|
|
CHECK(2u == hi_msg.size());
|
|
|
|
CHECK(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-09-23 18:14:25 +02:00
|
|
|
TEST_CASE("message constructor with container", "[message]")
|
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);
|
2018-09-23 18:14:25 +02:00
|
|
|
CHECK(2u == hi_msg.size());
|
|
|
|
CHECK(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-09-23 18:14:25 +02:00
|
|
|
TEST_CASE("message move constructor", "[message]")
|
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-09-23 18:14:25 +02:00
|
|
|
TEST_CASE("message assign move empty before", "[message]")
|
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));
|
2018-09-23 18:14:25 +02:00
|
|
|
CHECK(2u == hi_msg.size());
|
|
|
|
CHECK(0 == memcmp(data, hi_msg.data(), 2));
|
2018-04-13 17:35:00 +02:00
|
|
|
}
|
|
|
|
|
2018-09-23 18:14:25 +02:00
|
|
|
TEST_CASE("message assign move empty after", "[message]")
|
2018-04-13 17:35:00 +02:00
|
|
|
{
|
2018-05-12 18:28:28 +02:00
|
|
|
zmq::message_t hi_msg(data, strlen(data));
|
2019-04-04 19:55:27 +02:00
|
|
|
CHECK(!hi_msg.empty());
|
2018-05-12 18:28:28 +02:00
|
|
|
hi_msg = zmq::message_t();
|
2018-09-23 18:14:25 +02:00
|
|
|
CHECK(0u == hi_msg.size());
|
2019-04-04 19:55:27 +02:00
|
|
|
CHECK(hi_msg.empty());
|
2018-04-13 17:35:00 +02:00
|
|
|
}
|
|
|
|
|
2018-09-23 18:14:25 +02:00
|
|
|
TEST_CASE("message assign move empty before and after", "[message]")
|
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();
|
2018-09-23 18:14:25 +02:00
|
|
|
CHECK(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-09-23 18:14:25 +02:00
|
|
|
TEST_CASE("message equality self", "[message]")
|
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));
|
2018-09-23 18:14:25 +02:00
|
|
|
CHECK(hi_msg == hi_msg);
|
2018-04-13 17:20:07 +02:00
|
|
|
}
|
|
|
|
|
2018-09-23 18:14:25 +02:00
|
|
|
TEST_CASE("message equality equal", "[message]")
|
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));
|
2018-09-23 18:14:25 +02:00
|
|
|
CHECK(hi_msg_a == hi_msg_b);
|
2018-04-14 13:03:44 +02:00
|
|
|
}
|
2018-04-13 17:20:07 +02:00
|
|
|
|
2018-09-23 18:14:25 +02:00
|
|
|
TEST_CASE("message equality equal empty", "[message]")
|
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-09-23 18:14:25 +02:00
|
|
|
CHECK(msg_a == msg_b);
|
2018-04-13 17:24:36 +02:00
|
|
|
}
|
|
|
|
|
2018-09-23 18:14:25 +02:00
|
|
|
TEST_CASE("message equality non equal", "[message]")
|
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);
|
2018-09-23 18:14:25 +02:00
|
|
|
CHECK(msg_a != msg_b);
|
2018-04-13 17:20:07 +02:00
|
|
|
}
|
|
|
|
|
2018-09-23 18:14:25 +02:00
|
|
|
TEST_CASE("message equality non equal rhs empty", "[message]")
|
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-09-23 18:14:25 +02:00
|
|
|
CHECK(msg_a != msg_b);
|
2018-04-13 17:24:36 +02:00
|
|
|
}
|
|
|
|
|
2018-09-23 18:14:25 +02:00
|
|
|
TEST_CASE("message equality non equal lhs empty", "[message]")
|
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);
|
2018-09-23 18:14:25 +02:00
|
|
|
CHECK(msg_a != msg_b);
|
2018-04-13 17:24:36 +02:00
|
|
|
}
|
2018-05-19 07:44:41 +02:00
|
|
|
|
2020-01-07 20:54:47 +01:00
|
|
|
TEST_CASE("message to string", "[message]")
|
|
|
|
{
|
|
|
|
const zmq::message_t a;
|
|
|
|
const zmq::message_t b("Foo", 3);
|
|
|
|
CHECK(a.to_string() == "");
|
|
|
|
CHECK(b.to_string() == "Foo");
|
|
|
|
#ifdef ZMQ_CPP17
|
|
|
|
CHECK(a.to_string_view() == "");
|
|
|
|
CHECK(b.to_string_view() == "Foo");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-05-19 07:44:41 +02:00
|
|
|
#if defined(ZMQ_BUILD_DRAFT_API) && ZMQ_VERSION >= ZMQ_MAKE_VERSION(4, 2, 0)
|
2018-09-23 18:14:25 +02:00
|
|
|
TEST_CASE("message routing id persists", "[message]")
|
2018-05-19 07:44:41 +02:00
|
|
|
{
|
|
|
|
zmq::message_t msg;
|
|
|
|
msg.set_routing_id(123);
|
2018-09-23 18:14:25 +02:00
|
|
|
CHECK(123u == msg.routing_id());
|
2018-05-19 07:44:41 +02:00
|
|
|
}
|
2018-07-13 15:01:15 +02:00
|
|
|
|
2018-09-23 18:14:25 +02:00
|
|
|
TEST_CASE("message group persists", "[message]")
|
2018-07-13 15:01:15 +02:00
|
|
|
{
|
|
|
|
zmq::message_t msg;
|
|
|
|
msg.set_group("mygroup");
|
2018-09-23 18:14:25 +02:00
|
|
|
CHECK(std::string(msg.group()) == "mygroup");
|
2018-07-13 15:01:15 +02:00
|
|
|
}
|
2018-05-19 07:44:41 +02:00
|
|
|
#endif
|
2019-03-14 14:25:50 +01:00
|
|
|
|
|
|
|
#if ZMQ_VERSION >= ZMQ_MAKE_VERSION(3, 2, 0)
|
|
|
|
TEST_CASE("message is not shared", "[message]")
|
|
|
|
{
|
|
|
|
zmq::message_t msg;
|
|
|
|
CHECK(msg.get(ZMQ_SHARED) == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE("message is shared", "[message]")
|
|
|
|
{
|
|
|
|
size_t msg_sz = 1024; // large enough to be a type_lmsg
|
|
|
|
zmq::message_t msg1(msg_sz);
|
|
|
|
zmq::message_t msg2;
|
2019-04-03 15:56:11 +02:00
|
|
|
msg2.copy(msg1);
|
|
|
|
CHECK(msg1.get(ZMQ_SHARED) == 1);
|
2019-03-14 14:25:50 +01:00
|
|
|
CHECK(msg2.get(ZMQ_SHARED) == 1);
|
2019-04-03 15:56:11 +02:00
|
|
|
CHECK(msg1.size() == msg_sz);
|
|
|
|
CHECK(msg2.size() == msg_sz);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE("message move is not shared", "[message]")
|
|
|
|
{
|
|
|
|
size_t msg_sz = 1024; // large enough to be a type_lmsg
|
|
|
|
zmq::message_t msg1(msg_sz);
|
|
|
|
zmq::message_t msg2;
|
|
|
|
msg2.move(msg1);
|
|
|
|
CHECK(msg1.get(ZMQ_SHARED) == 0);
|
|
|
|
CHECK(msg2.get(ZMQ_SHARED) == 0);
|
|
|
|
CHECK(msg2.size() == msg_sz);
|
|
|
|
CHECK(msg1.size() == 0);
|
2019-03-14 14:25:50 +01:00
|
|
|
}
|
|
|
|
#endif
|