Skip to content

Commit 4bd01bc

Browse files
authored
Merge pull request #380 from zeromq/reformat
Reformat all files with clang-format
2 parents 47969cf + b6c79eb commit 4bd01bc

13 files changed

+358
-338
lines changed

tests/active_poller.cpp

Lines changed: 65 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ TEST_CASE("create destroy", "[active_poller]")
1414
}
1515

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

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

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

6567
zmq::active_poller_t a;
66-
a.add(socket, zmq::event_flags::pollin, [](zmq::event_flags) {});
68+
a.add(socket, zmq::event_flags::pollin, [](zmq::event_flags)
69+
{
70+
});
6771
CHECK_FALSE(a.empty());
6872
CHECK(1u == a.size());
6973
zmq::active_poller_t b;
@@ -92,7 +96,9 @@ TEST_CASE("add handler invalid events type", "[active_poller]")
9296
zmq::active_poller_t active_poller;
9397
zmq::active_poller_t::handler_type handler;
9498
short invalid_events_type = 2 << 10;
95-
CHECK_THROWS_AS(active_poller.add(socket, static_cast<zmq::event_flags>(invalid_events_type), handler), const zmq::error_t&);
99+
CHECK_THROWS_AS(
100+
active_poller.add(socket, static_cast<zmq::event_flags>(invalid_events_type),
101+
handler), const zmq::error_t&);
96102
CHECK(active_poller.empty());
97103
CHECK(0u == active_poller.size());
98104
}
@@ -106,14 +112,16 @@ TEST_CASE("add handler twice throws", "[active_poller]")
106112
zmq::active_poller_t::handler_type handler;
107113
active_poller.add(socket, zmq::event_flags::pollin, handler);
108114
/// \todo the actual error code should be checked
109-
CHECK_THROWS_AS(active_poller.add(socket, zmq::event_flags::pollin, handler), const zmq::error_t&);
115+
CHECK_THROWS_AS(active_poller.add(socket, zmq::event_flags::pollin, handler),
116+
const zmq::error_t&);
110117
}
111118

112119
TEST_CASE("wait with no handlers throws", "[active_poller]")
113120
{
114121
zmq::active_poller_t active_poller;
115122
/// \todo the actual error code should be checked
116-
CHECK_THROWS_AS(active_poller.wait(std::chrono::milliseconds{10}), const zmq::error_t&);
123+
CHECK_THROWS_AS(active_poller.wait(std::chrono::milliseconds{10}),
124+
const zmq::error_t&);
117125
}
118126

119127
TEST_CASE("remove unregistered throws", "[active_poller]")
@@ -130,7 +138,8 @@ TEST_CASE("remove registered empty", "[active_poller]")
130138
zmq::context_t context;
131139
zmq::socket_t socket{context, zmq::socket_type::router};
132140
zmq::active_poller_t active_poller;
133-
active_poller.add(socket, zmq::event_flags::pollin, zmq::active_poller_t::handler_type{});
141+
active_poller.add(socket, zmq::event_flags::pollin,
142+
zmq::active_poller_t::handler_type{});
134143
CHECK_NOTHROW(active_poller.remove(socket));
135144
}
136145

@@ -139,15 +148,20 @@ TEST_CASE("remove registered non empty", "[active_poller]")
139148
zmq::context_t context;
140149
zmq::socket_t socket{context, zmq::socket_type::router};
141150
zmq::active_poller_t active_poller;
142-
active_poller.add(socket, zmq::event_flags::pollin, [](zmq::event_flags) {});
151+
active_poller.add(socket, zmq::event_flags::pollin, [](zmq::event_flags)
152+
{
153+
});
143154
CHECK_NOTHROW(active_poller.remove(socket));
144155
}
145156

146157
namespace
147158
{
148159
struct server_client_setup : common_server_client_setup
149160
{
150-
zmq::active_poller_t::handler_type handler = [&](zmq::event_flags e) { events = e; };
161+
zmq::active_poller_t::handler_type handler = [&](zmq::event_flags e)
162+
{
163+
events = e;
164+
};
151165

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

162176
zmq::active_poller_t active_poller;
163177
bool message_received = false;
164-
zmq::active_poller_t::handler_type handler = [&message_received](zmq::event_flags events) {
178+
zmq::active_poller_t::handler_type handler = [&message_received
179+
](zmq::event_flags events)
180+
{
165181
CHECK(zmq::event_flags::none != (events & zmq::event_flags::pollin));
166182
message_received = true;
167183
};
@@ -181,7 +197,8 @@ TEST_CASE("client server", "[active_poller]")
181197
// Setup active_poller
182198
zmq::active_poller_t active_poller;
183199
zmq::event_flags events;
184-
zmq::active_poller_t::handler_type handler = [&](zmq::event_flags e) {
200+
zmq::active_poller_t::handler_type handler = [&](zmq::event_flags e)
201+
{
185202
if (zmq::event_flags::none != (e & zmq::event_flags::pollin)) {
186203
zmq::message_t zmq_msg;
187204
CHECK_NOTHROW(s.server.recv(zmq_msg)); // get message
@@ -204,7 +221,9 @@ TEST_CASE("client server", "[active_poller]")
204221

205222
// Re-add server socket with pollout flag
206223
CHECK_NOTHROW(active_poller.remove(s.server));
207-
CHECK_NOTHROW(active_poller.add(s.server, zmq::event_flags::pollin | zmq::event_flags::pollout, handler));
224+
CHECK_NOTHROW(
225+
active_poller.add(s.server, zmq::event_flags::pollin | zmq::event_flags::
226+
pollout, handler));
208227
CHECK(1 == active_poller.wait(std::chrono::milliseconds{-1}));
209228
CHECK(events == zmq::event_flags::pollout);
210229
}
@@ -215,8 +234,10 @@ TEST_CASE("add invalid socket throws", "[active_poller]")
215234
zmq::active_poller_t active_poller;
216235
zmq::socket_t a{context, zmq::socket_type::router};
217236
zmq::socket_t b{std::move(a)};
218-
CHECK_THROWS_AS(active_poller.add(a, zmq::event_flags::pollin, zmq::active_poller_t::handler_type{}),
219-
const zmq::error_t&);
237+
CHECK_THROWS_AS(
238+
active_poller.add(a, zmq::event_flags::pollin, zmq::active_poller_t::
239+
handler_type{}),
240+
const zmq::error_t&);
220241
}
221242

222243
TEST_CASE("remove invalid socket throws", "[active_poller]")
@@ -225,7 +246,8 @@ TEST_CASE("remove invalid socket throws", "[active_poller]")
225246
zmq::socket_t socket{context, zmq::socket_type::router};
226247
zmq::active_poller_t active_poller;
227248
CHECK_NOTHROW(
228-
active_poller.add(socket, zmq::event_flags::pollin, zmq::active_poller_t::handler_type{}));
249+
active_poller.add(socket, zmq::event_flags::pollin, zmq::active_poller_t::
250+
handler_type{}));
229251
CHECK(1u == active_poller.size());
230252
std::vector<zmq::socket_t> sockets;
231253
sockets.emplace_back(std::move(socket));
@@ -248,7 +270,8 @@ TEST_CASE("modify empty throws", "[active_poller]")
248270
zmq::context_t context;
249271
zmq::socket_t socket{context, zmq::socket_type::push};
250272
zmq::active_poller_t active_poller;
251-
CHECK_THROWS_AS(active_poller.modify(socket, zmq::event_flags::pollin), const zmq::error_t&);
273+
CHECK_THROWS_AS(active_poller.modify(socket, zmq::event_flags::pollin),
274+
const zmq::error_t&);
252275
}
253276

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

263287
TEST_CASE("modify not added throws", "[active_poller]")
@@ -267,8 +291,10 @@ TEST_CASE("modify not added throws", "[active_poller]")
267291
zmq::socket_t b{context, zmq::socket_type::push};
268292
zmq::active_poller_t active_poller;
269293
CHECK_NOTHROW(
270-
active_poller.add(a, zmq::event_flags::pollin, zmq::active_poller_t::handler_type{}));
271-
CHECK_THROWS_AS(active_poller.modify(b, zmq::event_flags::pollin), const zmq::error_t&);
294+
active_poller.add(a, zmq::event_flags::pollin, zmq::active_poller_t::
295+
handler_type{}));
296+
CHECK_THROWS_AS(active_poller.modify(b, zmq::event_flags::pollin),
297+
const zmq::error_t&);
272298
}
273299

274300
TEST_CASE("modify simple", "[active_poller]")
@@ -277,8 +303,11 @@ TEST_CASE("modify simple", "[active_poller]")
277303
zmq::socket_t a{context, zmq::socket_type::push};
278304
zmq::active_poller_t active_poller;
279305
CHECK_NOTHROW(
280-
active_poller.add(a, zmq::event_flags::pollin, zmq::active_poller_t::handler_type{}));
281-
CHECK_NOTHROW(active_poller.modify(a, zmq::event_flags::pollin | zmq::event_flags::pollout));
306+
active_poller.add(a, zmq::event_flags::pollin, zmq::active_poller_t::
307+
handler_type{}));
308+
CHECK_NOTHROW(
309+
active_poller.modify(a, zmq::event_flags::pollin | zmq::event_flags::pollout
310+
));
282311
}
283312

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

300329
// Modify server socket with pollout flag
301-
CHECK_NOTHROW(active_poller.modify(s.server, zmq::event_flags::pollin | zmq::event_flags::pollout));
330+
CHECK_NOTHROW(
331+
active_poller.modify(s.server, zmq::event_flags::pollin | zmq::event_flags::
332+
pollout));
302333
CHECK(1 == active_poller.wait(std::chrono::milliseconds{500}));
303334
CHECK(s.events == (zmq::event_flags::pollin | zmq::event_flags::pollout));
304335
}
@@ -313,7 +344,8 @@ TEST_CASE("wait one return", "[active_poller]")
313344
// Setup active_poller
314345
zmq::active_poller_t active_poller;
315346
CHECK_NOTHROW(
316-
active_poller.add(s.server, zmq::event_flags::pollin, [&count](zmq::event_flags) { ++count; }));
347+
active_poller.add(s.server, zmq::event_flags::pollin, [&count](zmq::
348+
event_flags) { ++count; }));
317349

318350
// client sends message
319351
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]")
359391
int count = 0;
360392
// Setup active_poller a
361393
zmq::active_poller_t a;
362-
CHECK_NOTHROW(a.add(s.server, zmq::event_flags::pollin, [&count](zmq::event_flags) { ++count; }));
394+
CHECK_NOTHROW(
395+
a.add(s.server, zmq::event_flags::pollin, [&count](zmq::event_flags) { ++
396+
count; }));
363397
// client sends message
364398
CHECK_NOTHROW(s.client.send(zmq::message_t{"Hi"}, zmq::send_flags::none));
365399
// wait for message and verify it is received
@@ -389,11 +423,12 @@ TEST_CASE("remove from handler", "[active_poller]")
389423
int count = 0;
390424
for (size_t i = 0; i < ITER_NO; ++i) {
391425
CHECK_NOTHROW(
392-
active_poller.add(setup_list[i].server, zmq::event_flags::pollin, [&, i](zmq::event_flags events) {
393-
CHECK(events == zmq::event_flags::pollin);
394-
active_poller.remove(setup_list[ITER_NO - i - 1].server);
395-
CHECK((ITER_NO - i - 1) == active_poller.size());
396-
}));
426+
active_poller.add(setup_list[i].server, zmq::event_flags::pollin, [&, i](
427+
zmq::event_flags events) {
428+
CHECK(events == zmq::event_flags::pollin);
429+
active_poller.remove(setup_list[ITER_NO - i - 1].server);
430+
CHECK((ITER_NO - i - 1) == active_poller.size());
431+
}));
397432
++count;
398433
}
399434
CHECK(ITER_NO == active_poller.size());

tests/buffer.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ TEST_CASE("buffer data ctor", "[buffer]")
3535
CHECK(mb.size() == from_mut.size());
3636
CHECK(mb.data() == from_mut.data());
3737
const auto cmb = mb;
38-
static_assert(std::is_same<decltype(cmb.data()), void*>::value, "");
38+
static_assert(std::is_same<decltype(cmb.data()), void *>::value, "");
3939

40-
constexpr const void* cp = nullptr;
41-
constexpr void* p = nullptr;
40+
constexpr const void *cp = nullptr;
41+
constexpr void *p = nullptr;
4242
constexpr zmq::const_buffer cecb = zmq::buffer(p, 0);
4343
constexpr zmq::mutable_buffer cemb = zmq::buffer(p, 0);
4444
CHECK(cecb.data() == nullptr);
@@ -188,14 +188,14 @@ TEST_CASE("mutable_buffer creation vector", "[buffer]")
188188
TEST_CASE("const_buffer creation vector", "[buffer]")
189189
{
190190
std::vector<BT> d(10);
191-
zmq::const_buffer b = zmq::buffer(static_cast<const std::vector<BT>&>(d));
191+
zmq::const_buffer b = zmq::buffer(static_cast<const std::vector<BT> &>(d));
192192
CHECK(b.size() == d.size() * sizeof(BT));
193193
CHECK(b.data() == d.data());
194-
zmq::const_buffer b2 = zmq::buffer(static_cast<const std::vector<BT>&>(d), 4);
194+
zmq::const_buffer b2 = zmq::buffer(static_cast<const std::vector<BT> &>(d), 4);
195195
CHECK(b2.size() == 4);
196196
CHECK(b2.data() == d.data());
197197
d.clear();
198-
b = zmq::buffer(static_cast<const std::vector<BT>&>(d));
198+
b = zmq::buffer(static_cast<const std::vector<BT> &>(d));
199199
CHECK(b.size() == 0);
200200
CHECK(b.data() == nullptr);
201201
}

tests/message.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

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

39-
namespace {
39+
namespace
40+
{
4041
const char *const data = "Hi";
4142
}
4243

tests/monitor.cpp

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
class mock_monitor_t : public zmq::monitor_t
1010
{
11-
public:
11+
public:
1212
void on_event_connect_delayed(const zmq_event_t &, const char *) ZMQ_OVERRIDE
1313
{
1414
++connect_delayed;
@@ -38,13 +38,11 @@ TEST_CASE("monitor move construct", "[monitor]")
3838
{
3939
zmq::context_t ctx;
4040
zmq::socket_t sock(ctx, ZMQ_DEALER);
41-
SECTION("move ctor empty")
42-
{
41+
SECTION("move ctor empty") {
4342
zmq::monitor_t monitor1;
4443
zmq::monitor_t monitor2 = std::move(monitor1);
4544
}
46-
SECTION("move ctor init")
47-
{
45+
SECTION("move ctor init") {
4846
zmq::monitor_t monitor1;
4947
monitor1.init(sock, "inproc://monitor-client");
5048
zmq::monitor_t monitor2 = std::move(monitor1);
@@ -55,21 +53,18 @@ TEST_CASE("monitor move assign", "[monitor]")
5553
{
5654
zmq::context_t ctx;
5755
zmq::socket_t sock(ctx, ZMQ_DEALER);
58-
SECTION("move assign empty")
59-
{
60-
zmq::monitor_t monitor1;
61-
zmq::monitor_t monitor2;
62-
monitor1 = std::move(monitor2);
56+
SECTION("move assign empty") {
57+
zmq::monitor_t monitor1;
58+
zmq::monitor_t monitor2;
59+
monitor1 = std::move(monitor2);
6360
}
64-
SECTION("move assign init")
65-
{
61+
SECTION("move assign init") {
6662
zmq::monitor_t monitor1;
6763
monitor1.init(sock, "inproc://monitor-client");
6864
zmq::monitor_t monitor2;
6965
monitor2 = std::move(monitor1);
7066
}
71-
SECTION("move assign init both")
72-
{
67+
SECTION("move assign init both") {
7368
zmq::monitor_t monitor1;
7469
monitor1.init(sock, "inproc://monitor-client");
7570
zmq::monitor_t monitor2;
@@ -101,10 +96,11 @@ TEST_CASE("monitor init abort", "[monitor]")
10196
{
10297
class mock_monitor : public mock_monitor_t
10398
{
104-
public:
105-
mock_monitor(std::function<void(void)> handle_connected)
106-
: handle_connected{std::move(handle_connected)}
107-
{}
99+
public:
100+
mock_monitor(std::function<void(void)> handle_connected) :
101+
handle_connected{std::move(handle_connected)}
102+
{
103+
}
108104

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

115111
std::function<void(void)> handle_connected;
116-
117112
};
118113

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

125-
mock_monitor monitor([&]() {
120+
mock_monitor monitor([&]()
121+
{
126122
std::lock_guard<std::mutex> lock(mutex);
127123
done = true;
128124
cond_var.notify_one();
129125
});
130126
monitor.init(s.client, "inproc://foo");
131127

132-
auto thread = std::thread([&monitor] {
128+
auto thread = std::thread([&monitor]
129+
{
133130
while (monitor.check_event(-1)) {
134131
}
135132
});

0 commit comments

Comments
 (0)