Problem: message_t should be easier to construct

* Added overload constructor (c++11 only) taking iteratable object.
  It would be easier to use std::string, std::array etc to construct
  a message now. Making it a draft for now in case it is too greedy
  and needs to be more specialize.
* Added equal and not euqal operator to message_t as a recommended
  and expected way of comparing objects in C++.
* deprecated C style equal method as operator== should be used instead
  (point above).
* Added message_t test covering all available message_t's constructors
This commit is contained in:
Pawel Kurdybacha
2018-04-14 12:03:44 +01:00
parent 3185dd1051
commit 6caa5d19d3
4 changed files with 56 additions and 7 deletions

30
tests/message.cpp Normal file
View File

@@ -0,0 +1,30 @@
#include <gtest/gtest.h>
#include <zmq.hpp>
TEST (message, create_destroy)
{
zmq::message_t message;
}
TEST (message, constructors)
{
const std::string hi {"Hi"};
zmq::message_t hi_msg_a {hi.begin (), hi.end ()};
ASSERT_EQ (hi_msg_a.size (), hi.size ());
zmq::message_t hi_msg_b {hi.data (), hi.size ()};
ASSERT_EQ (hi_msg_b.size (), hi.size ());
ASSERT_EQ (hi_msg_a, hi_msg_b);
#if defined(ZMQ_BUILD_DRAFT_API) && defined(ZMQ_CPP11)
zmq::message_t hello_msg_a {"Hello"};
ASSERT_NE (hi_msg_a, hello_msg_a);
ASSERT_NE (hi_msg_b, hello_msg_a);
zmq::message_t hi_msg_c {hi};
ASSERT_EQ (hi_msg_c, hi_msg_a);
ASSERT_EQ (hi_msg_c, hi_msg_b);
ASSERT_NE (hi_msg_c, hello_msg_a);
#endif
#ifdef ZMQ_HAS_RVALUE_REFS
zmq::message_t hello_msg_b{zmq::message_t{"Hello"}};
ASSERT_EQ (hello_msg_a, hello_msg_b);
#endif
}