mirror of
https://github.com/zeromq/cppzmq.git
synced 2025-10-17 19:25:56 +02:00
Problem: Missing swap functions
Solution: Implement for socket_t, context_t, message_t and poller_t Additionally remove dependency on <functional> by refactoring poller_t and remove unused <unordered_map> include.
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
#include <catch.hpp>
|
||||
#include <zmq.hpp>
|
||||
|
||||
#if (__cplusplus >= 201703L)
|
||||
static_assert(std::is_nothrow_swappable<zmq::context_t>::value,
|
||||
"context_t should be nothrow swappable");
|
||||
#endif
|
||||
|
||||
TEST_CASE("context construct default and destroy", "[context]")
|
||||
{
|
||||
zmq::context_t context;
|
||||
@@ -12,3 +17,13 @@ TEST_CASE("context create, close and destroy", "[context]")
|
||||
context.close();
|
||||
CHECK(NULL == (void *) context);
|
||||
}
|
||||
|
||||
#ifdef ZMQ_CPP11
|
||||
TEST_CASE("context swap", "[context]")
|
||||
{
|
||||
zmq::context_t context1;
|
||||
zmq::context_t context2;
|
||||
using std::swap;
|
||||
swap(context1, context2);
|
||||
}
|
||||
#endif
|
||||
|
@@ -8,6 +8,10 @@ static_assert(!std::is_copy_constructible<zmq::message_t>::value,
|
||||
static_assert(!std::is_copy_assignable<zmq::message_t>::value,
|
||||
"message_t should not be copy-assignable");
|
||||
#endif
|
||||
#if (__cplusplus >= 201703L)
|
||||
static_assert(std::is_nothrow_swappable<zmq::message_t>::value,
|
||||
"message_t should be nothrow swappable");
|
||||
#endif
|
||||
|
||||
TEST_CASE("message default constructed", "[message]")
|
||||
{
|
||||
@@ -15,6 +19,22 @@ TEST_CASE("message default constructed", "[message]")
|
||||
CHECK(0u == message.size());
|
||||
}
|
||||
|
||||
#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
|
||||
|
||||
namespace {
|
||||
const char *const data = "Hi";
|
||||
}
|
||||
|
@@ -4,6 +4,7 @@
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
#include <functional>
|
||||
|
||||
class mock_monitor_t : public zmq::monitor_t
|
||||
{
|
||||
|
@@ -5,6 +5,11 @@
|
||||
#include <array>
|
||||
#include <memory>
|
||||
|
||||
#if (__cplusplus >= 201703L)
|
||||
static_assert(std::is_nothrow_swappable<zmq::poller_t<>>::value,
|
||||
"poller_t should be nothrow swappable");
|
||||
#endif
|
||||
|
||||
TEST_CASE("poller create destroy", "[poller]")
|
||||
{
|
||||
zmq::poller_t<> poller;
|
||||
@@ -28,6 +33,14 @@ TEST_CASE("poller move assign empty", "[poller]")
|
||||
b = std::move(a);
|
||||
}
|
||||
|
||||
TEST_CASE("poller swap", "[poller]")
|
||||
{
|
||||
zmq::poller_t<> a;
|
||||
zmq::poller_t<> b;
|
||||
using std::swap;
|
||||
swap(a, b);
|
||||
}
|
||||
|
||||
TEST_CASE("poller move construct non empty", "[poller]")
|
||||
{
|
||||
zmq::context_t context;
|
||||
|
@@ -4,6 +4,11 @@
|
||||
#include <future>
|
||||
#endif
|
||||
|
||||
#if (__cplusplus >= 201703L)
|
||||
static_assert(std::is_nothrow_swappable<zmq::socket_t>::value,
|
||||
"socket_t should be nothrow swappable");
|
||||
#endif
|
||||
|
||||
TEST_CASE("socket create destroy", "[socket]")
|
||||
{
|
||||
zmq::context_t context;
|
||||
@@ -16,6 +21,15 @@ TEST_CASE("socket create by enum and destroy", "[socket]")
|
||||
zmq::context_t context;
|
||||
zmq::socket_t socket(context, zmq::socket_type::router);
|
||||
}
|
||||
|
||||
TEST_CASE("socket swap", "[socket]")
|
||||
{
|
||||
zmq::context_t context;
|
||||
zmq::socket_t socket1(context, zmq::socket_type::router);
|
||||
zmq::socket_t socket2(context, zmq::socket_type::dealer);
|
||||
using std::swap;
|
||||
swap(socket1, socket2);
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST_CASE("socket sends and receives const buffer", "[socket]")
|
||||
|
Reference in New Issue
Block a user