libzmq/tests/test_sockopt_hwm.cpp
Kapp Arnaud fb960147ca 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.
2015-06-04 01:38:45 +02:00

53 lines
1.0 KiB
C++

#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();
}