From fb960147ca5673ecda34cdb87d963ffd022189b4 Mon Sep 17 00:00:00 2001 From: Kapp Arnaud Date: Thu, 4 Jun 2015 01:38:45 +0200 Subject: [PATCH] Introduce a failing test against zmq_setsockpt(). Problem: zmq_setsockpt() returns success when changing the HWM after a bind or connect() even though the call has no effect. Solution: Introduce a failing test a reminder we need to patch it. --- Makefile.am | 6 ++++- tests/CMakeLists.txt | 1 + tests/test_sockopt_hwm.cpp | 52 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 tests/test_sockopt_hwm.cpp diff --git a/Makefile.am b/Makefile.am index 3efd488c..e58511d6 100644 --- a/Makefile.am +++ b/Makefile.am @@ -355,7 +355,8 @@ test_apps = \ tests/test_client_server \ tests/test_server_drop_more \ tests/test_client_drop_more \ - tests/test_thread_safe + tests/test_thread_safe \ + tests/test_socketopt_hwm tests_test_system_SOURCES = tests/test_system.cpp tests_test_system_LDADD = src/libzmq.la @@ -542,6 +543,9 @@ tests_test_client_drop_more_LDADD = src/libzmq.la tests_test_thread_safe_SOURCES = tests/test_thread_safe.cpp tests_test_thread_safe_LDADD = src/libzmq.la +tests_test_socketopt_hwm_SOURCES = tests/test_sockopt_hwm.cpp +tests_test_socketopt_hwm_LDADD = src/libzmq.la + if !ON_MINGW diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 3daa8164..b166e6d3 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -47,6 +47,7 @@ set(tests test_pub_invert_matching test_thread_safe test_client_server + test_sockopt_hwm ) if(NOT WIN32) list(APPEND tests diff --git a/tests/test_sockopt_hwm.cpp b/tests/test_sockopt_hwm.cpp new file mode 100644 index 00000000..ef81daf4 --- /dev/null +++ b/tests/test_sockopt_hwm.cpp @@ -0,0 +1,52 @@ +#include "testutil.hpp" + +void test_valid_hwm_change() +{ + void *ctx = zmq_ctx_new (); + assert (ctx); + int rc; + + void *bind_socket = zmq_socket (ctx, ZMQ_SUB); + assert (bind_socket); + + int val = 500; + rc = zmq_setsockopt(bind_socket, ZMQ_RCVHWM, &val, sizeof(val)); + assert (rc == 0); + + rc = zmq_bind (bind_socket, "inproc://a"); + assert (rc == 0); + + size_t placeholder = sizeof(val); + val = 0; + rc = zmq_getsockopt(bind_socket, ZMQ_RCVHWM, &val, &placeholder); + assert (rc == 0); + assert(val == 500); +} + + +/** + * Test that zmq_setsockopt() fails to change the RCVHWM when called + * after a call to zmq_bind(). + */ +void test_invalid_hwm_change() +{ + void *ctx = zmq_ctx_new (); + assert (ctx); + int rc; + + void *bind_socket = zmq_socket (ctx, ZMQ_SUB); + assert (bind_socket); + + rc = zmq_bind (bind_socket, "inproc://a"); + assert (rc == 0); + + int val = 500; + rc = zmq_setsockopt(bind_socket, ZMQ_RCVHWM, &val, sizeof(val)); + assert (rc == -1); +} + +int main() +{ + test_valid_hwm_change(); + test_invalid_hwm_change(); +}