From 8353e8460f45b807b723655b3b0789397288d9fa Mon Sep 17 00:00:00 2001 From: Pawel Kurdybacha Date: Fri, 13 Apr 2018 17:35:41 +0100 Subject: [PATCH 1/2] Problem: non consistent whitespace formatting * Converted tabs to to 4 spaces to be consistend with the rest of the code * Stripped white spaces from the end of lines --- tests/poller.cpp | 58 ++++++++++++++++++++++++------------------------ zmq.hpp | 42 +++++++++++++++++------------------ 2 files changed, 50 insertions(+), 50 deletions(-) diff --git a/tests/poller.cpp b/tests/poller.cpp index 7fd5a6d..100f3e0 100644 --- a/tests/poller.cpp +++ b/tests/poller.cpp @@ -8,7 +8,7 @@ TEST(poller, create_destroy) { zmq::poller_t poller; - ASSERT_EQ(0u, poller.size ()); + ASSERT_EQ(0u, poller.size ()); } static_assert(!std::is_copy_constructible::value, "poller_t should not be copy-constructible"); @@ -16,24 +16,24 @@ static_assert(!std::is_copy_assignable::value, "poller_t should n TEST(poller, move_construct_empty) { - std::unique_ptr a{new zmq::poller_t}; - zmq::poller_t b = std::move(*a); + std::unique_ptr a{new zmq::poller_t}; + zmq::poller_t b = std::move(*a); - ASSERT_EQ(0u, a->size ()); - a.reset (); - ASSERT_EQ(0u, b.size ()); + ASSERT_EQ(0u, a->size ()); + a.reset (); + ASSERT_EQ(0u, b.size ()); } TEST(poller, move_assign_empty) { - std::unique_ptr a{new zmq::poller_t}; - zmq::poller_t b; + std::unique_ptr a{new zmq::poller_t}; + zmq::poller_t b; - b = std::move(*a); + b = std::move(*a); - ASSERT_EQ(0u, a->size ()); - a.reset (); - ASSERT_EQ(0u, b.size ()); + ASSERT_EQ(0u, a->size ()); + a.reset (); + ASSERT_EQ(0u, b.size ()); } TEST(poller, move_construct_non_empty) @@ -41,13 +41,13 @@ TEST(poller, move_construct_non_empty) zmq::context_t context; zmq::socket_t socket{context, zmq::socket_type::router}; - std::unique_ptr a{new zmq::poller_t}; - a->add(socket, ZMQ_POLLIN, [](short) {}); - zmq::poller_t b = std::move(*a); + std::unique_ptr a{new zmq::poller_t}; + a->add(socket, ZMQ_POLLIN, [](short) {}); + zmq::poller_t b = std::move(*a); - ASSERT_EQ(0u, a->size ()); - a.reset (); - ASSERT_EQ(1u, b.size ()); + ASSERT_EQ(0u, a->size ()); + a.reset (); + ASSERT_EQ(1u, b.size ()); } TEST(poller, move_assign_non_empty) @@ -55,15 +55,15 @@ TEST(poller, move_assign_non_empty) zmq::context_t context; zmq::socket_t socket{context, zmq::socket_type::router}; - std::unique_ptr a{new zmq::poller_t}; - a->add(socket, ZMQ_POLLIN, [](short) {}); - zmq::poller_t b; + std::unique_ptr a{new zmq::poller_t}; + a->add(socket, ZMQ_POLLIN, [](short) {}); + zmq::poller_t b; - b = std::move(*a); + b = std::move(*a); - ASSERT_EQ(0u, a->size ()); - a.reset (); - ASSERT_EQ(1u, b.size ()); + ASSERT_EQ(0u, a->size ()); + a.reset (); + ASSERT_EQ(1u, b.size ()); } TEST(poller, add_handler) @@ -92,14 +92,14 @@ TEST(poller, add_handler_twice_throws) zmq::poller_t poller; zmq::poller_t::handler_t handler; poller.add(socket, ZMQ_POLLIN, handler); - /// \todo the actual error code should be checked + /// \todo the actual error code should be checked ASSERT_THROW(poller.add(socket, ZMQ_POLLIN, handler), zmq::error_t); } TEST(poller, wait_with_no_handlers_throws) { zmq::poller_t poller; - /// \todo the actual error code should be checked + /// \todo the actual error code should be checked ASSERT_THROW(poller.wait(std::chrono::milliseconds{10}), zmq::error_t); } @@ -108,7 +108,7 @@ TEST(poller, remove_unregistered_throws) zmq::context_t context; zmq::socket_t socket{context, zmq::socket_type::router}; zmq::poller_t poller; - /// \todo the actual error code should be checked + /// \todo the actual error code should be checked ASSERT_THROW(poller.remove(socket), zmq::error_t); } @@ -126,7 +126,7 @@ TEST(poller, remove_registered_non_empty) { zmq::context_t context; zmq::socket_t socket{context, zmq::socket_type::router}; - zmq::poller_t poller; + zmq::poller_t poller; poller.add(socket, ZMQ_POLLIN, [](short) {}); ASSERT_NO_THROW(poller.remove(socket)); } diff --git a/zmq.hpp b/zmq.hpp index 984dbe6..899bd83 100644 --- a/zmq.hpp +++ b/zmq.hpp @@ -32,7 +32,7 @@ #define ZMQ_DEPRECATED(msg) __declspec(deprecated(msg)) #elif defined(__GNUC__) #define ZMQ_DEPRECATED(msg) __attribute__((deprecated(msg))) -#endif +#endif #if (__cplusplus >= 201103L) #define ZMQ_CPP11 @@ -1030,20 +1030,20 @@ namespace zmq using handler_t = std::function; - ZMQ_DEPRECATED("from 4.3.0, use overload accepting handler_t instead") + ZMQ_DEPRECATED("from 4.3.0, use overload accepting handler_t instead") void add (zmq::socket_t &socket, short events, std::function &handler) { - add (socket, events, [&handler](short) { handler(); }); - } + add (socket, events, [&handler](short) { handler(); }); + } void add (zmq::socket_t &socket, short events, handler_t handler) { - handler_t *handler_ptr = nullptr; - /// \todo is it sensible to allow handler to be empty? doesn't this lead to an error when the event is signalled? (perhaps it should already lead to an error in zmq_poller_add then) - if (handler) { - auto emplace_res = handlers.emplace(&socket, std::move(handler)); - handler_ptr = &emplace_res.first->second; - } + handler_t *handler_ptr = nullptr; + /// \todo is it sensible to allow handler to be empty? doesn't this lead to an error when the event is signalled? (perhaps it should already lead to an error in zmq_poller_add then) + if (handler) { + auto emplace_res = handlers.emplace(&socket, std::move(handler)); + handler_ptr = &emplace_res.first->second; + } if (0 == zmq_poller_add (poller_ptr, socket.ptr, handler_ptr, events)) { poller_events.emplace_back (zmq_poller_event_t ()); return; @@ -1054,11 +1054,11 @@ namespace zmq void remove (zmq::socket_t &socket) { if (0 == zmq_poller_remove (poller_ptr, socket.ptr)) { - auto it = handlers.find (&socket); - if (it != handlers.end ()) { /// \todo this may only be false if handler was empty on add - handlers.erase (it); - } - poller_events.pop_back (); + auto it = handlers.find (&socket); + if (it != handlers.end ()) { /// \todo this may only be false if handler was empty on add + handlers.erase (it); + } + poller_events.pop_back (); return; } throw error_t (); @@ -1084,16 +1084,16 @@ namespace zmq throw error_t (); } - - size_t size () - { - return poller_events.size(); - } + + size_t size () + { + return poller_events.size(); + } private: void *poller_ptr; std::vector poller_events; - std::map handlers; + std::map handlers; }; // class poller_t #endif // defined(ZMQ_BUILD_DRAFT_API) && defined(ZMQ_CPP11) && defined(ZMQ_HAVE_POLLER) From 40c55018b2a9bcd8c4898fcc1a064f01b07c4ac9 Mon Sep 17 00:00:00 2001 From: Pawel Kurdybacha Date: Fri, 13 Apr 2018 17:38:51 +0100 Subject: [PATCH 2/2] Problem: create_destroy test not assigned properly --- tests/poller.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/poller.cpp b/tests/poller.cpp index 100f3e0..af24146 100644 --- a/tests/poller.cpp +++ b/tests/poller.cpp @@ -5,8 +5,8 @@ #include - TEST(poller, create_destroy) - { +TEST(poller, create_destroy) +{ zmq::poller_t poller; ASSERT_EQ(0u, poller.size ()); }