0
0
mirror of https://github.com/zeromq/libzmq.git synced 2024-12-27 07:31:03 +08:00

Problem: missing test cases for zmq_poller_* functions called with invalid arguments

Solution: added test cases
This commit is contained in:
sigiesec 2017-08-22 17:37:39 +02:00
parent 6f665eb951
commit f9af5503b4

View File

@ -29,6 +29,78 @@
#include "testutil.hpp"
void test_null_poller_pointers (void *ctx)
{
int rc = zmq_poller_destroy (NULL);
assert (rc == -1 && errno == EFAULT);
void *null_poller = NULL;
rc = zmq_poller_destroy (&null_poller);
assert (rc == -1 && errno == EFAULT);
void *socket = zmq_socket (ctx, ZMQ_PAIR);
assert (socket != NULL);
rc = zmq_poller_add (NULL, socket, NULL, ZMQ_POLLIN);
assert (rc == -1 && errno == EFAULT);
rc = zmq_poller_add (&null_poller, socket, NULL, ZMQ_POLLIN);
assert (rc == -1 && errno == EFAULT);
rc = zmq_poller_modify (NULL, socket, ZMQ_POLLIN);
assert (rc == -1 && errno == EFAULT);
rc = zmq_poller_modify (&null_poller, socket, ZMQ_POLLIN);
assert (rc == -1 && errno == EFAULT);
rc = zmq_poller_remove (NULL, socket);
assert (rc == -1 && errno == EFAULT);
rc = zmq_poller_remove (&null_poller, socket);
assert (rc == -1 && errno == EFAULT);
#ifdef _WIN32
SOCKET fd;
#else
int fd;
#endif
size_t fd_size = sizeof fd;
rc = zmq_getsockopt(socket, ZMQ_FD, &fd, &fd_size);
assert (rc == 0);
rc = zmq_poller_add_fd (NULL, fd, NULL, ZMQ_POLLIN);
assert (rc == -1 && errno == EFAULT);
rc = zmq_poller_add_fd (&null_poller, fd, NULL, ZMQ_POLLIN);
assert (rc == -1 && errno == EFAULT);
rc = zmq_poller_modify_fd (NULL, fd, ZMQ_POLLIN);
assert (rc == -1 && errno == EFAULT);
rc = zmq_poller_modify_fd (&null_poller, fd, ZMQ_POLLIN);
assert (rc == -1 && errno == EFAULT);
rc = zmq_poller_remove_fd (NULL, fd);
assert (rc == -1 && errno == EFAULT);
rc = zmq_poller_remove_fd (&null_poller, fd);
assert (rc == -1 && errno == EFAULT);
rc = zmq_close (socket);
assert (rc == 0);
}
void test_null_socket_pointers ()
{
void *poller = zmq_poller_new ();
assert (poller != NULL);
int rc = zmq_poller_add (poller, NULL, NULL, ZMQ_POLLIN);
assert (rc == -1 && errno == ENOTSOCK);
rc = zmq_poller_modify (poller, NULL, ZMQ_POLLIN);
assert (rc == -1 && errno == ENOTSOCK);
rc = zmq_poller_remove (poller, NULL);
assert (rc == -1 && errno == ENOTSOCK);
rc = zmq_poller_destroy (&poller);
assert (rc == 0);
}
int main (void)
{
size_t len = MAX_SOCKET_STRING;
@ -70,11 +142,11 @@ int main (void)
#endif
// Set up poller
void* poller = zmq_poller_new ();
void *poller = zmq_poller_new ();
zmq_poller_event_t event;
// waiting on poller with no registered sockets should report error
rc = zmq_poller_wait(poller, &event, 0);
rc = zmq_poller_wait (poller, &event, 0);
assert (rc == -1);
assert (errno == ETIMEDOUT);
@ -170,15 +242,11 @@ int main (void)
assert (rc == 0);
#endif
// Test error - null poller pointers
rc = zmq_poller_destroy (NULL);
assert (rc == -1 && errno == EFAULT);
void *null_poller = NULL;
rc = zmq_poller_destroy (&null_poller);
assert (rc == -1 && errno == EFAULT);
test_null_poller_pointers (ctx);
test_null_socket_pointers ();
rc = zmq_poller_destroy (&poller);
assert(rc == 0);
assert (rc == 0);
rc = zmq_ctx_term (ctx);
assert (rc == 0);