From d072d57e2e22fd0af3d5e73f40efc86ad36d7bf2 Mon Sep 17 00:00:00 2001 From: sigiesec Date: Wed, 23 Aug 2017 09:13:07 +0200 Subject: [PATCH] Problem: no tests for zmq_timer_* with NULL timers argument Solution: added tests --- tests/test_timers.cpp | 55 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/tests/test_timers.cpp b/tests/test_timers.cpp index 3b637c5d..9babbd91 100644 --- a/tests/test_timers.cpp +++ b/tests/test_timers.cpp @@ -48,6 +48,59 @@ int sleep_and_execute(void *timers_) return zmq_timers_execute(timers_); } +void test_null_timer_pointers () +{ + void *timers = NULL; + + int rc = zmq_timers_destroy (&timers); + assert (rc == -1 && errno == EFAULT); + +// TODO this currently triggers an access violation +#if 0 + rc = zmq_timers_destroy (NULL); + assert (rc == -1 && errno == EFAULT); +#endif + + const size_t dummy_interval = 100; + const int dummy_timer_id = 1; + + rc = zmq_timers_add (timers, dummy_interval, &handler, NULL); + assert (rc == -1 && errno == EFAULT); + + rc = zmq_timers_add (&timers, dummy_interval, &handler, NULL); + assert (rc == -1 && errno == EFAULT); + + rc = zmq_timers_cancel (timers, dummy_timer_id); + assert (rc == -1 && errno == EFAULT); + + rc = zmq_timers_cancel (&timers, dummy_timer_id); + assert (rc == -1 && errno == EFAULT); + + rc = zmq_timers_set_interval (timers, dummy_timer_id, dummy_interval); + assert (rc == -1 && errno == EFAULT); + + rc = zmq_timers_set_interval (&timers, dummy_timer_id, dummy_interval); + assert (rc == -1 && errno == EFAULT); + + rc = zmq_timers_reset (timers, dummy_timer_id); + assert (rc == -1 && errno == EFAULT); + + rc = zmq_timers_reset (&timers, dummy_timer_id); + assert (rc == -1 && errno == EFAULT); + + rc = zmq_timers_timeout (timers); + assert (rc == -1 && errno == EFAULT); + + rc = zmq_timers_timeout (&timers); + assert (rc == -1 && errno == EFAULT); + + rc = zmq_timers_execute (timers); + assert (rc == -1 && errno == EFAULT); + + rc = zmq_timers_execute (&timers); + assert (rc == -1 && errno == EFAULT); +} + int main (void) { setup_test_environment (); @@ -115,5 +168,7 @@ int main (void) rc = zmq_timers_destroy (&timers); assert (rc == 0); + test_null_timer_pointers (); + return 0; }