diff --git a/tests/test_poller.cpp b/tests/test_poller.cpp index 50fe8647..b2d075ee 100644 --- a/tests/test_poller.cpp +++ b/tests/test_poller.cpp @@ -165,6 +165,66 @@ void test_null_event_pointers (void *ctx) assert (rc == 0); } +void test_add_modify_remove_corner_cases(void *ctx) +{ + void *poller = zmq_poller_new (); + assert (poller != NULL); + + void *zeromq_socket = zmq_socket (ctx, ZMQ_PAIR); + assert (zeromq_socket != NULL); + + int rc = zmq_poller_add (poller, zeromq_socket, NULL, ZMQ_POLLIN); + assert (rc == 0); + + // attempt to add the same socket twice + rc = zmq_poller_add (poller, zeromq_socket, NULL, ZMQ_POLLIN); + assert (rc == -1 && errno == EINVAL); + + rc = zmq_poller_remove (poller, zeromq_socket); + assert (rc == 0); + + // attempt to remove socket that is not present + rc = zmq_poller_remove (poller, zeromq_socket); + assert (rc == -1 && errno == EINVAL); + + // attempt to modify socket that is not present + rc = zmq_poller_modify (poller, zeromq_socket, ZMQ_POLLIN); + assert (rc == -1 && errno == EINVAL); + + // add a socket with no events + // TODO should this really be legal? it does not make any sense... + rc = zmq_poller_add (poller, zeromq_socket, NULL, 0); + assert (rc == 0); + + fd_t plain_socket = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP); + rc = zmq_poller_add_fd (poller, plain_socket, NULL, ZMQ_POLLIN); + assert (rc == 0); + + // attempt to add the same plain socket twice + rc = zmq_poller_add_fd (poller, plain_socket, NULL, ZMQ_POLLIN); + assert (rc == -1 && errno == EINVAL); + + rc = zmq_poller_remove_fd (poller, plain_socket); + assert (rc == 0); + + // attempt to remove plain socket that is not present + rc = zmq_poller_remove_fd (poller, plain_socket); + assert (rc == -1 && errno == EINVAL); + + // attempt to modify plain socket that is not present + rc = zmq_poller_modify_fd (poller, plain_socket, ZMQ_POLLIN); + assert (rc == -1 && errno == EINVAL); + + rc = zmq_poller_destroy (&poller); + assert (rc == 0); + + rc = zmq_close (zeromq_socket); + assert (rc == 0); + + rc = close (plain_socket); + assert (rc == 0); +} + void test_wait_corner_cases (void *ctx) { void *poller = zmq_poller_new (); @@ -332,6 +392,7 @@ int main (void) test_null_socket_pointers (); test_null_event_pointers (ctx); + test_add_modify_remove_corner_cases (ctx); test_wait_corner_cases (ctx); rc = zmq_poller_destroy (&poller); diff --git a/tests/test_system.cpp b/tests/test_system.cpp index 68f79b58..96d82caa 100644 --- a/tests/test_system.cpp +++ b/tests/test_system.cpp @@ -47,11 +47,6 @@ void initialise_network (void) throw std::runtime_error("Could not start WSA"); } -int close (int fd) -{ - return closesocket (fd); -} - #else void initialise_network (void) diff --git a/tests/testutil.hpp b/tests/testutil.hpp index 3061c8e8..cd7928ce 100644 --- a/tests/testutil.hpp +++ b/tests/testutil.hpp @@ -396,4 +396,13 @@ is_ipv6_available(void) #endif // _WIN32_WINNT < 0x0600 } +#if defined (ZMQ_HAVE_WINDOWS) + +int close (int fd) +{ + return closesocket (fd); +} + +#endif + #endif