Skip to content

Commit

Permalink
Merge pull request zeromq#380 from zeromq/reformat
Browse files Browse the repository at this point in the history
Reformat all files with clang-format
  • Loading branch information
bluca authored Jan 28, 2020
2 parents 47969cf + b6c79eb commit 4bd01bc
Showing 13 changed files with 358 additions and 338 deletions.
95 changes: 65 additions & 30 deletions tests/active_poller.cpp
Original file line number Diff line number Diff line change
@@ -14,9 +14,9 @@ TEST_CASE("create destroy", "[active_poller]")
}

static_assert(!std::is_copy_constructible<zmq::active_poller_t>::value,
"active_active_poller_t should not be copy-constructible");
"active_active_poller_t should not be copy-constructible");
static_assert(!std::is_copy_assignable<zmq::active_poller_t>::value,
"active_active_poller_t should not be copy-assignable");
"active_active_poller_t should not be copy-assignable");

TEST_CASE("move construct empty", "[active_poller]")
{
@@ -47,7 +47,9 @@ TEST_CASE("move construct non empty", "[active_poller]")
zmq::socket_t socket{context, zmq::socket_type::router};

zmq::active_poller_t a;
a.add(socket, zmq::event_flags::pollin, [](zmq::event_flags) {});
a.add(socket, zmq::event_flags::pollin, [](zmq::event_flags)
{
});
CHECK_FALSE(a.empty());
CHECK(1u == a.size());
zmq::active_poller_t b = std::move(a);
@@ -63,7 +65,9 @@ TEST_CASE("move assign non empty", "[active_poller]")
zmq::socket_t socket{context, zmq::socket_type::router};

zmq::active_poller_t a;
a.add(socket, zmq::event_flags::pollin, [](zmq::event_flags) {});
a.add(socket, zmq::event_flags::pollin, [](zmq::event_flags)
{
});
CHECK_FALSE(a.empty());
CHECK(1u == a.size());
zmq::active_poller_t b;
@@ -92,7 +96,9 @@ TEST_CASE("add handler invalid events type", "[active_poller]")
zmq::active_poller_t active_poller;
zmq::active_poller_t::handler_type handler;
short invalid_events_type = 2 << 10;
CHECK_THROWS_AS(active_poller.add(socket, static_cast<zmq::event_flags>(invalid_events_type), handler), const zmq::error_t&);
CHECK_THROWS_AS(
active_poller.add(socket, static_cast<zmq::event_flags>(invalid_events_type),
handler), const zmq::error_t&);
CHECK(active_poller.empty());
CHECK(0u == active_poller.size());
}
@@ -106,14 +112,16 @@ TEST_CASE("add handler twice throws", "[active_poller]")
zmq::active_poller_t::handler_type handler;
active_poller.add(socket, zmq::event_flags::pollin, handler);
/// \todo the actual error code should be checked
CHECK_THROWS_AS(active_poller.add(socket, zmq::event_flags::pollin, handler), const zmq::error_t&);
CHECK_THROWS_AS(active_poller.add(socket, zmq::event_flags::pollin, handler),
const zmq::error_t&);
}

TEST_CASE("wait with no handlers throws", "[active_poller]")
{
zmq::active_poller_t active_poller;
/// \todo the actual error code should be checked
CHECK_THROWS_AS(active_poller.wait(std::chrono::milliseconds{10}), const zmq::error_t&);
CHECK_THROWS_AS(active_poller.wait(std::chrono::milliseconds{10}),
const zmq::error_t&);
}

TEST_CASE("remove unregistered throws", "[active_poller]")
@@ -130,7 +138,8 @@ TEST_CASE("remove registered empty", "[active_poller]")
zmq::context_t context;
zmq::socket_t socket{context, zmq::socket_type::router};
zmq::active_poller_t active_poller;
active_poller.add(socket, zmq::event_flags::pollin, zmq::active_poller_t::handler_type{});
active_poller.add(socket, zmq::event_flags::pollin,
zmq::active_poller_t::handler_type{});
CHECK_NOTHROW(active_poller.remove(socket));
}

@@ -139,15 +148,20 @@ TEST_CASE("remove registered non empty", "[active_poller]")
zmq::context_t context;
zmq::socket_t socket{context, zmq::socket_type::router};
zmq::active_poller_t active_poller;
active_poller.add(socket, zmq::event_flags::pollin, [](zmq::event_flags) {});
active_poller.add(socket, zmq::event_flags::pollin, [](zmq::event_flags)
{
});
CHECK_NOTHROW(active_poller.remove(socket));
}

namespace
{
struct server_client_setup : common_server_client_setup
{
zmq::active_poller_t::handler_type handler = [&](zmq::event_flags e) { events = e; };
zmq::active_poller_t::handler_type handler = [&](zmq::event_flags e)
{
events = e;
};

zmq::event_flags events = zmq::event_flags::none;
};
@@ -161,7 +175,9 @@ TEST_CASE("poll basic", "[active_poller]")

zmq::active_poller_t active_poller;
bool message_received = false;
zmq::active_poller_t::handler_type handler = [&message_received](zmq::event_flags events) {
zmq::active_poller_t::handler_type handler = [&message_received
](zmq::event_flags events)
{
CHECK(zmq::event_flags::none != (events & zmq::event_flags::pollin));
message_received = true;
};
@@ -181,7 +197,8 @@ TEST_CASE("client server", "[active_poller]")
// Setup active_poller
zmq::active_poller_t active_poller;
zmq::event_flags events;
zmq::active_poller_t::handler_type handler = [&](zmq::event_flags e) {
zmq::active_poller_t::handler_type handler = [&](zmq::event_flags e)
{
if (zmq::event_flags::none != (e & zmq::event_flags::pollin)) {
zmq::message_t zmq_msg;
CHECK_NOTHROW(s.server.recv(zmq_msg)); // get message
@@ -204,7 +221,9 @@ TEST_CASE("client server", "[active_poller]")

// Re-add server socket with pollout flag
CHECK_NOTHROW(active_poller.remove(s.server));
CHECK_NOTHROW(active_poller.add(s.server, zmq::event_flags::pollin | zmq::event_flags::pollout, handler));
CHECK_NOTHROW(
active_poller.add(s.server, zmq::event_flags::pollin | zmq::event_flags::
pollout, handler));
CHECK(1 == active_poller.wait(std::chrono::milliseconds{-1}));
CHECK(events == zmq::event_flags::pollout);
}
@@ -215,8 +234,10 @@ TEST_CASE("add invalid socket throws", "[active_poller]")
zmq::active_poller_t active_poller;
zmq::socket_t a{context, zmq::socket_type::router};
zmq::socket_t b{std::move(a)};
CHECK_THROWS_AS(active_poller.add(a, zmq::event_flags::pollin, zmq::active_poller_t::handler_type{}),
const zmq::error_t&);
CHECK_THROWS_AS(
active_poller.add(a, zmq::event_flags::pollin, zmq::active_poller_t::
handler_type{}),
const zmq::error_t&);
}

TEST_CASE("remove invalid socket throws", "[active_poller]")
@@ -225,7 +246,8 @@ TEST_CASE("remove invalid socket throws", "[active_poller]")
zmq::socket_t socket{context, zmq::socket_type::router};
zmq::active_poller_t active_poller;
CHECK_NOTHROW(
active_poller.add(socket, zmq::event_flags::pollin, zmq::active_poller_t::handler_type{}));
active_poller.add(socket, zmq::event_flags::pollin, zmq::active_poller_t::
handler_type{}));
CHECK(1u == active_poller.size());
std::vector<zmq::socket_t> sockets;
sockets.emplace_back(std::move(socket));
@@ -248,7 +270,8 @@ TEST_CASE("modify empty throws", "[active_poller]")
zmq::context_t context;
zmq::socket_t socket{context, zmq::socket_type::push};
zmq::active_poller_t active_poller;
CHECK_THROWS_AS(active_poller.modify(socket, zmq::event_flags::pollin), const zmq::error_t&);
CHECK_THROWS_AS(active_poller.modify(socket, zmq::event_flags::pollin),
const zmq::error_t&);
}

TEST_CASE("modify invalid socket throws", "[active_poller]")
@@ -257,7 +280,8 @@ TEST_CASE("modify invalid socket throws", "[active_poller]")
zmq::socket_t a{context, zmq::socket_type::push};
zmq::socket_t b{std::move(a)};
zmq::active_poller_t active_poller;
CHECK_THROWS_AS(active_poller.modify(a, zmq::event_flags::pollin), const zmq::error_t&);
CHECK_THROWS_AS(active_poller.modify(a, zmq::event_flags::pollin),
const zmq::error_t&);
}

TEST_CASE("modify not added throws", "[active_poller]")
@@ -267,8 +291,10 @@ TEST_CASE("modify not added throws", "[active_poller]")
zmq::socket_t b{context, zmq::socket_type::push};
zmq::active_poller_t active_poller;
CHECK_NOTHROW(
active_poller.add(a, zmq::event_flags::pollin, zmq::active_poller_t::handler_type{}));
CHECK_THROWS_AS(active_poller.modify(b, zmq::event_flags::pollin), const zmq::error_t&);
active_poller.add(a, zmq::event_flags::pollin, zmq::active_poller_t::
handler_type{}));
CHECK_THROWS_AS(active_poller.modify(b, zmq::event_flags::pollin),
const zmq::error_t&);
}

TEST_CASE("modify simple", "[active_poller]")
@@ -277,8 +303,11 @@ TEST_CASE("modify simple", "[active_poller]")
zmq::socket_t a{context, zmq::socket_type::push};
zmq::active_poller_t active_poller;
CHECK_NOTHROW(
active_poller.add(a, zmq::event_flags::pollin, zmq::active_poller_t::handler_type{}));
CHECK_NOTHROW(active_poller.modify(a, zmq::event_flags::pollin | zmq::event_flags::pollout));
active_poller.add(a, zmq::event_flags::pollin, zmq::active_poller_t::
handler_type{}));
CHECK_NOTHROW(
active_poller.modify(a, zmq::event_flags::pollin | zmq::event_flags::pollout
));
}

TEST_CASE("poll client server", "[active_poller]")
@@ -298,7 +327,9 @@ TEST_CASE("poll client server", "[active_poller]")
CHECK(s.events == zmq::event_flags::pollin);

// Modify server socket with pollout flag
CHECK_NOTHROW(active_poller.modify(s.server, zmq::event_flags::pollin | zmq::event_flags::pollout));
CHECK_NOTHROW(
active_poller.modify(s.server, zmq::event_flags::pollin | zmq::event_flags::
pollout));
CHECK(1 == active_poller.wait(std::chrono::milliseconds{500}));
CHECK(s.events == (zmq::event_flags::pollin | zmq::event_flags::pollout));
}
@@ -313,7 +344,8 @@ TEST_CASE("wait one return", "[active_poller]")
// Setup active_poller
zmq::active_poller_t active_poller;
CHECK_NOTHROW(
active_poller.add(s.server, zmq::event_flags::pollin, [&count](zmq::event_flags) { ++count; }));
active_poller.add(s.server, zmq::event_flags::pollin, [&count](zmq::
event_flags) { ++count; }));

// client sends message
CHECK_NOTHROW(s.client.send(zmq::message_t{"Hi"}, zmq::send_flags::none));
@@ -359,7 +391,9 @@ TEST_CASE("received on move constructed active_poller", "[active_poller]")
int count = 0;
// Setup active_poller a
zmq::active_poller_t a;
CHECK_NOTHROW(a.add(s.server, zmq::event_flags::pollin, [&count](zmq::event_flags) { ++count; }));
CHECK_NOTHROW(
a.add(s.server, zmq::event_flags::pollin, [&count](zmq::event_flags) { ++
count; }));
// client sends message
CHECK_NOTHROW(s.client.send(zmq::message_t{"Hi"}, zmq::send_flags::none));
// wait for message and verify it is received
@@ -389,11 +423,12 @@ TEST_CASE("remove from handler", "[active_poller]")
int count = 0;
for (size_t i = 0; i < ITER_NO; ++i) {
CHECK_NOTHROW(
active_poller.add(setup_list[i].server, zmq::event_flags::pollin, [&, i](zmq::event_flags events) {
CHECK(events == zmq::event_flags::pollin);
active_poller.remove(setup_list[ITER_NO - i - 1].server);
CHECK((ITER_NO - i - 1) == active_poller.size());
}));
active_poller.add(setup_list[i].server, zmq::event_flags::pollin, [&, i](
zmq::event_flags events) {
CHECK(events == zmq::event_flags::pollin);
active_poller.remove(setup_list[ITER_NO - i - 1].server);
CHECK((ITER_NO - i - 1) == active_poller.size());
}));
++count;
}
CHECK(ITER_NO == active_poller.size());
12 changes: 6 additions & 6 deletions tests/buffer.cpp
Original file line number Diff line number Diff line change
@@ -35,10 +35,10 @@ TEST_CASE("buffer data ctor", "[buffer]")
CHECK(mb.size() == from_mut.size());
CHECK(mb.data() == from_mut.data());
const auto cmb = mb;
static_assert(std::is_same<decltype(cmb.data()), void*>::value, "");
static_assert(std::is_same<decltype(cmb.data()), void *>::value, "");

constexpr const void* cp = nullptr;
constexpr void* p = nullptr;
constexpr const void *cp = nullptr;
constexpr void *p = nullptr;
constexpr zmq::const_buffer cecb = zmq::buffer(p, 0);
constexpr zmq::mutable_buffer cemb = zmq::buffer(p, 0);
CHECK(cecb.data() == nullptr);
@@ -188,14 +188,14 @@ TEST_CASE("mutable_buffer creation vector", "[buffer]")
TEST_CASE("const_buffer creation vector", "[buffer]")
{
std::vector<BT> d(10);
zmq::const_buffer b = zmq::buffer(static_cast<const std::vector<BT>&>(d));
zmq::const_buffer b = zmq::buffer(static_cast<const std::vector<BT> &>(d));
CHECK(b.size() == d.size() * sizeof(BT));
CHECK(b.data() == d.data());
zmq::const_buffer b2 = zmq::buffer(static_cast<const std::vector<BT>&>(d), 4);
zmq::const_buffer b2 = zmq::buffer(static_cast<const std::vector<BT> &>(d), 4);
CHECK(b2.size() == 4);
CHECK(b2.data() == d.data());
d.clear();
b = zmq::buffer(static_cast<const std::vector<BT>&>(d));
b = zmq::buffer(static_cast<const std::vector<BT> &>(d));
CHECK(b.size() == 0);
CHECK(b.data() == nullptr);
}
7 changes: 4 additions & 3 deletions tests/message.cpp
Original file line number Diff line number Diff line change
@@ -4,9 +4,9 @@

#if defined(ZMQ_CPP11)
static_assert(!std::is_copy_constructible<zmq::message_t>::value,
"message_t should not be copy-constructible");
"message_t should not be copy-constructible");
static_assert(!std::is_copy_assignable<zmq::message_t>::value,
"message_t should not be copy-assignable");
"message_t should not be copy-assignable");
#endif
#if (__cplusplus >= 201703L)
static_assert(std::is_nothrow_swappable<zmq::message_t>::value,
@@ -36,7 +36,8 @@ TEST_CASE("message swap", "[message]")
}
#endif

namespace {
namespace
{
const char *const data = "Hi";
}

39 changes: 18 additions & 21 deletions tests/monitor.cpp
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@

class mock_monitor_t : public zmq::monitor_t
{
public:
public:
void on_event_connect_delayed(const zmq_event_t &, const char *) ZMQ_OVERRIDE
{
++connect_delayed;
@@ -38,13 +38,11 @@ TEST_CASE("monitor move construct", "[monitor]")
{
zmq::context_t ctx;
zmq::socket_t sock(ctx, ZMQ_DEALER);
SECTION("move ctor empty")
{
SECTION("move ctor empty") {
zmq::monitor_t monitor1;
zmq::monitor_t monitor2 = std::move(monitor1);
}
SECTION("move ctor init")
{
SECTION("move ctor init") {
zmq::monitor_t monitor1;
monitor1.init(sock, "inproc://monitor-client");
zmq::monitor_t monitor2 = std::move(monitor1);
@@ -55,21 +53,18 @@ TEST_CASE("monitor move assign", "[monitor]")
{
zmq::context_t ctx;
zmq::socket_t sock(ctx, ZMQ_DEALER);
SECTION("move assign empty")
{
zmq::monitor_t monitor1;
zmq::monitor_t monitor2;
monitor1 = std::move(monitor2);
SECTION("move assign empty") {
zmq::monitor_t monitor1;
zmq::monitor_t monitor2;
monitor1 = std::move(monitor2);
}
SECTION("move assign init")
{
SECTION("move assign init") {
zmq::monitor_t monitor1;
monitor1.init(sock, "inproc://monitor-client");
zmq::monitor_t monitor2;
monitor2 = std::move(monitor1);
}
SECTION("move assign init both")
{
SECTION("move assign init both") {
zmq::monitor_t monitor1;
monitor1.init(sock, "inproc://monitor-client");
zmq::monitor_t monitor2;
@@ -101,10 +96,11 @@ TEST_CASE("monitor init abort", "[monitor]")
{
class mock_monitor : public mock_monitor_t
{
public:
mock_monitor(std::function<void(void)> handle_connected)
: handle_connected{std::move(handle_connected)}
{}
public:
mock_monitor(std::function<void(void)> handle_connected) :
handle_connected{std::move(handle_connected)}
{
}

void on_event_connected(const zmq_event_t &e, const char *m) ZMQ_OVERRIDE
{
@@ -113,7 +109,6 @@ TEST_CASE("monitor init abort", "[monitor]")
}

std::function<void(void)> handle_connected;

};

common_server_client_setup s(false);
@@ -122,14 +117,16 @@ TEST_CASE("monitor init abort", "[monitor]")
std::condition_variable cond_var;
bool done{false};

mock_monitor monitor([&]() {
mock_monitor monitor([&]()
{
std::lock_guard<std::mutex> lock(mutex);
done = true;
cond_var.notify_one();
});
monitor.init(s.client, "inproc://foo");

auto thread = std::thread([&monitor] {
auto thread = std::thread([&monitor]
{
while (monitor.check_event(-1)) {
}
});
Loading

0 comments on commit 4bd01bc

Please sign in to comment.