Skip to content

Commit

Permalink
Add CHECK_THROWS_ZMQ_ERROR and check error codes
Browse files Browse the repository at this point in the history
  • Loading branch information
gummif committed May 24, 2020
1 parent d2c5fef commit e9c5546
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
19 changes: 7 additions & 12 deletions tests/active_poller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,26 +108,21 @@ TEST_CASE("add handler twice throws", "[active_poller]")
zmq::active_poller_t 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_ZMQ_ERROR(EINVAL, active_poller.add(socket, zmq::event_flags::pollin, handler));
}

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_ZMQ_ERROR(EFAULT, active_poller.wait(std::chrono::milliseconds{10}));
}

TEST_CASE("remove unregistered throws", "[active_poller]")
{
zmq::context_t context;
zmq::socket_t socket{context, zmq::socket_type::router};
zmq::active_poller_t active_poller;
/// \todo the actual error code should be checked
CHECK_THROWS_AS(active_poller.remove(socket), const zmq::error_t &);
CHECK_THROWS_ZMQ_ERROR(EINVAL, active_poller.remove(socket));
}

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

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

Expand Down
19 changes: 19 additions & 0 deletions tests/testutil.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,22 @@ struct common_server_client_setup
std::string endpoint;
};
#endif

#define CHECK_THROWS_ZMQ_ERROR(ecode, expr) \
do { \
try { \
expr; \
CHECK(false); \
} \
catch (const zmq::error_t &ze) { \
INFO(std::string("Unexpected error code: ") + ze.what()); \
CHECK(ze.num() == ecode); \
} \
catch (const std::exception &ex) { \
INFO(std::string("Unexpected exception: ") + ex.what()); \
CHECK(false); \
} \
catch (...) { \
CHECK(false); \
} \
} while (false)

0 comments on commit e9c5546

Please sign in to comment.