forked from zeromq/cppzmq
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Problem: several test cases mixed in message.constructors
Solution: split up into test cases for various ctors and equality operators
- Loading branch information
Showing
1 changed file
with
55 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,67 @@ | ||
#include <gtest/gtest.h> | ||
#include <zmq.hpp> | ||
|
||
TEST (message, create_destroy) | ||
TEST (message, constructor_default) | ||
{ | ||
zmq::message_t message; | ||
const zmq::message_t message; | ||
ASSERT_EQ (0u, message.size ()); | ||
} | ||
|
||
TEST (message, constructors) | ||
const char* const data = "Hi"; | ||
|
||
TEST (message, constructor_iterators) | ||
{ | ||
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); | ||
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)); | ||
} | ||
|
||
TEST (message, constructor_pointer_size) | ||
{ | ||
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)); | ||
} | ||
|
||
TEST (message, constructor_char_array) { | ||
const zmq::message_t hi_msg (data, strlen (data)); | ||
ASSERT_EQ (2u, hi_msg.size ()); | ||
ASSERT_EQ (0, memcmp (data, hi_msg.data (), 2)); | ||
} | ||
|
||
#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); | ||
TEST (message, constructor_container) | ||
{ | ||
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)); | ||
} | ||
#endif | ||
|
||
#ifdef ZMQ_HAS_RVALUE_REFS | ||
zmq::message_t hello_msg_b(zmq::message_t("Hello")); | ||
ASSERT_EQ (hello_msg_a, hello_msg_b); | ||
TEST (message, constructor_move) | ||
{ | ||
zmq::message_t hi_msg (zmq::message_t(data, strlen (data))); | ||
} | ||
#endif | ||
|
||
TEST (message, equality_self) { | ||
const zmq::message_t hi_msg (data, strlen (data)); | ||
ASSERT_EQ (hi_msg, hi_msg); | ||
} | ||
|
||
TEST (message, equality_equal) { | ||
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); | ||
} | ||
|
||
TEST (message, equality_non_equal) { | ||
const zmq::message_t msg_a ("Hi", 2); | ||
const zmq::message_t msg_b ("Hello", 5); | ||
ASSERT_NE (msg_a, msg_b); | ||
} | ||
|