Skip to content

Commit e9c5546

Browse files
committed
Add CHECK_THROWS_ZMQ_ERROR and check error codes
1 parent d2c5fef commit e9c5546

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

tests/active_poller.cpp

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -108,26 +108,21 @@ TEST_CASE("add handler twice throws", "[active_poller]")
108108
zmq::active_poller_t active_poller;
109109
zmq::active_poller_t::handler_type handler;
110110
active_poller.add(socket, zmq::event_flags::pollin, handler);
111-
/// \todo the actual error code should be checked
112-
CHECK_THROWS_AS(active_poller.add(socket, zmq::event_flags::pollin, handler),
113-
const zmq::error_t &);
111+
CHECK_THROWS_ZMQ_ERROR(EINVAL, active_poller.add(socket, zmq::event_flags::pollin, handler));
114112
}
115113

116114
TEST_CASE("wait with no handlers throws", "[active_poller]")
117115
{
118116
zmq::active_poller_t active_poller;
119-
/// \todo the actual error code should be checked
120-
CHECK_THROWS_AS(active_poller.wait(std::chrono::milliseconds{10}),
121-
const zmq::error_t &);
117+
CHECK_THROWS_ZMQ_ERROR(EFAULT, active_poller.wait(std::chrono::milliseconds{10}));
122118
}
123119

124120
TEST_CASE("remove unregistered throws", "[active_poller]")
125121
{
126122
zmq::context_t context;
127123
zmq::socket_t socket{context, zmq::socket_type::router};
128124
zmq::active_poller_t active_poller;
129-
/// \todo the actual error code should be checked
130-
CHECK_THROWS_AS(active_poller.remove(socket), const zmq::error_t &);
125+
CHECK_THROWS_ZMQ_ERROR(EINVAL, active_poller.remove(socket));
131126
}
132127

133128
TEST_CASE("remove registered empty", "[active_poller]")
@@ -351,8 +346,8 @@ TEST_CASE("wait on move constructed active_poller", "[active_poller]")
351346
CHECK_NOTHROW(a.add(s.server, zmq::event_flags::pollin, handler));
352347
zmq::active_poller_t b{std::move(a)};
353348
CHECK(1u == b.size());
354-
/// \todo the actual error code should be checked
355-
CHECK_THROWS_AS(a.wait(std::chrono::milliseconds{10}), const zmq::error_t &);
349+
CHECK(0u == a.size());
350+
CHECK_THROWS_ZMQ_ERROR(EFAULT, a.wait(std::chrono::milliseconds{10}));
356351
CHECK(b.wait(std::chrono::milliseconds{-1}));
357352
}
358353

@@ -366,8 +361,8 @@ TEST_CASE("wait on move assigned active_poller", "[active_poller]")
366361
zmq::active_poller_t b;
367362
b = {std::move(a)};
368363
CHECK(1u == b.size());
369-
/// \todo the actual error code should be checked
370-
CHECK_THROWS_AS(a.wait(std::chrono::milliseconds{10}), const zmq::error_t &);
364+
CHECK(0u == a.size());
365+
CHECK_THROWS_ZMQ_ERROR(EFAULT, a.wait(std::chrono::milliseconds{10}));
371366
CHECK(b.wait(std::chrono::milliseconds{-1}));
372367
}
373368

tests/testutil.hpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,22 @@ struct common_server_client_setup
3333
std::string endpoint;
3434
};
3535
#endif
36+
37+
#define CHECK_THROWS_ZMQ_ERROR(ecode, expr) \
38+
do { \
39+
try { \
40+
expr; \
41+
CHECK(false); \
42+
} \
43+
catch (const zmq::error_t &ze) { \
44+
INFO(std::string("Unexpected error code: ") + ze.what()); \
45+
CHECK(ze.num() == ecode); \
46+
} \
47+
catch (const std::exception &ex) { \
48+
INFO(std::string("Unexpected exception: ") + ex.what()); \
49+
CHECK(false); \
50+
} \
51+
catch (...) { \
52+
CHECK(false); \
53+
} \
54+
} while (false)

0 commit comments

Comments
 (0)