mirror of
https://github.com/zeromq/libzmq.git
synced 2025-10-22 16:02:31 +02:00
Problem: remaining basic assertions
Solution: use unity assertions instead
This commit is contained in:
@@ -57,7 +57,7 @@ void test_version ()
|
|||||||
|
|
||||||
void test_strerrror ()
|
void test_strerrror ()
|
||||||
{
|
{
|
||||||
assert (zmq_strerror (EINVAL));
|
TEST_ASSERT_NOT_NULL (zmq_strerror (EINVAL));
|
||||||
}
|
}
|
||||||
|
|
||||||
int main ()
|
int main ()
|
||||||
|
@@ -44,7 +44,8 @@ static void receiver (void *socket_)
|
|||||||
{
|
{
|
||||||
char buffer[16];
|
char buffer[16];
|
||||||
int rc = zmq_recv (socket_, &buffer, sizeof (buffer), 0);
|
int rc = zmq_recv (socket_, &buffer, sizeof (buffer), 0);
|
||||||
assert (rc == -1);
|
// TODO which error is expected here? use TEST_ASSERT_FAILURE_ERRNO instead
|
||||||
|
TEST_ASSERT_EQUAL_INT (-1, rc);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_ctx_destroy ()
|
void test_ctx_destroy ()
|
||||||
|
@@ -117,7 +117,7 @@ void init_groups ()
|
|||||||
// Get the group and supplemental groups of the process owner
|
// Get the group and supplemental groups of the process owner
|
||||||
gid_t groups[100];
|
gid_t groups[100];
|
||||||
int ngroups = getgroups (100, groups);
|
int ngroups = getgroups (100, groups);
|
||||||
assert (ngroups != -1);
|
TEST_ASSERT_NOT_EQUAL (-1, ngroups);
|
||||||
group = getgid ();
|
group = getgid ();
|
||||||
supgroup = group;
|
supgroup = group;
|
||||||
notgroup = group + 1;
|
notgroup = group + 1;
|
||||||
|
@@ -30,6 +30,8 @@
|
|||||||
#include "testutil.hpp"
|
#include "testutil.hpp"
|
||||||
#include "testutil_unity.hpp"
|
#include "testutil_unity.hpp"
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
void setUp ()
|
void setUp ()
|
||||||
{
|
{
|
||||||
setup_test_context ();
|
setup_test_context ();
|
||||||
@@ -53,6 +55,8 @@ void test_fork ()
|
|||||||
|
|
||||||
int pid = fork ();
|
int pid = fork ();
|
||||||
if (pid == 0) {
|
if (pid == 0) {
|
||||||
|
// use regular assertions in the child process
|
||||||
|
|
||||||
// Child process
|
// Child process
|
||||||
// Immediately close parent sockets and context
|
// Immediately close parent sockets and context
|
||||||
zmq_close (pull);
|
zmq_close (pull);
|
||||||
|
@@ -55,7 +55,9 @@ struct iovec
|
|||||||
|
|
||||||
static void do_check (void *sb_, void *sc_, size_t msg_size_)
|
static void do_check (void *sb_, void *sc_, size_t msg_size_)
|
||||||
{
|
{
|
||||||
assert (sb_ && sc_ && msg_size_ > 0);
|
TEST_ASSERT_NOT_NULL (sb_);
|
||||||
|
TEST_ASSERT_NOT_NULL (sc_);
|
||||||
|
TEST_ASSERT_GREATER_THAN (0, msg_size_);
|
||||||
|
|
||||||
const char msg_val = '1';
|
const char msg_val = '1';
|
||||||
const int num_messages = 10;
|
const int num_messages = 10;
|
||||||
@@ -76,8 +78,8 @@ static void do_check (void *sb_, void *sc_, size_t msg_size_)
|
|||||||
send_iov[i].iov_len = msg_size_;
|
send_iov[i].iov_len = msg_size_;
|
||||||
memcpy (send_iov[i].iov_base, ref_msg, msg_size_);
|
memcpy (send_iov[i].iov_base, ref_msg, msg_size_);
|
||||||
|
|
||||||
// TODO: this assertion only checks if memcpy behaves as expected... remove this?
|
// TODO: this assertion only checks if memcpy behaves as expected... remove this or assert something else?
|
||||||
assert (memcmp (ref_msg, send_iov[i].iov_base, msg_size_) == 0);
|
TEST_ASSERT_EQUAL_HEX8_ARRAY (ref_msg, send_iov[i].iov_base, msg_size_);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test errors - zmq_recviov - null socket
|
// Test errors - zmq_recviov - null socket
|
||||||
|
@@ -44,12 +44,12 @@ void tearDown ()
|
|||||||
|
|
||||||
static void do_bind_and_verify (void *s_, const char *endpoint_)
|
static void do_bind_and_verify (void *s_, const char *endpoint_)
|
||||||
{
|
{
|
||||||
int rc = zmq_bind (s_, endpoint_);
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (s_, endpoint_));
|
||||||
assert (rc == 0);
|
|
||||||
char reported[255];
|
char reported[255];
|
||||||
size_t size = 255;
|
size_t size = 255;
|
||||||
rc = zmq_getsockopt (s_, ZMQ_LAST_ENDPOINT, reported, &size);
|
TEST_ASSERT_SUCCESS_ERRNO (
|
||||||
assert (rc == 0 && strcmp (reported, endpoint_) == 0);
|
zmq_getsockopt (s_, ZMQ_LAST_ENDPOINT, reported, &size));
|
||||||
|
TEST_ASSERT_EQUAL_STRING (endpoint_, reported);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_last_endpoint ()
|
void test_last_endpoint ()
|
||||||
|
@@ -57,8 +57,8 @@ static void zap_handler (void *handler_)
|
|||||||
char *routing_id = s_recv (handler_);
|
char *routing_id = s_recv (handler_);
|
||||||
char *mechanism = s_recv (handler_);
|
char *mechanism = s_recv (handler_);
|
||||||
|
|
||||||
assert (streq (version, "1.0"));
|
TEST_ASSERT_EQUAL_STRING ("1.0", version);
|
||||||
assert (streq (mechanism, "NULL"));
|
TEST_ASSERT_EQUAL_STRING ("NULL", mechanism);
|
||||||
|
|
||||||
s_sendmore (handler_, version);
|
s_sendmore (handler_, version);
|
||||||
s_sendmore (handler_, sequence);
|
s_sendmore (handler_, sequence);
|
||||||
|
@@ -99,7 +99,7 @@ void test_monitor_basic ()
|
|||||||
int event = get_monitor_event (client_mon, NULL, NULL);
|
int event = get_monitor_event (client_mon, NULL, NULL);
|
||||||
if (event == ZMQ_EVENT_CONNECT_DELAYED)
|
if (event == ZMQ_EVENT_CONNECT_DELAYED)
|
||||||
event = get_monitor_event (client_mon, NULL, NULL);
|
event = get_monitor_event (client_mon, NULL, NULL);
|
||||||
assert (event == ZMQ_EVENT_CONNECTED);
|
TEST_ASSERT_EQUAL_INT (ZMQ_EVENT_CONNECTED, event);
|
||||||
expect_monitor_event (client_mon, ZMQ_EVENT_HANDSHAKE_SUCCEEDED);
|
expect_monitor_event (client_mon, ZMQ_EVENT_HANDSHAKE_SUCCEEDED);
|
||||||
event = get_monitor_event (client_mon, NULL, NULL);
|
event = get_monitor_event (client_mon, NULL, NULL);
|
||||||
if (event == ZMQ_EVENT_DISCONNECTED) {
|
if (event == ZMQ_EVENT_DISCONNECTED) {
|
||||||
|
@@ -45,9 +45,8 @@ typedef void (*extra_func_t) (void *socket_);
|
|||||||
void set_sockopt_bind_to_device (void *socket)
|
void set_sockopt_bind_to_device (void *socket)
|
||||||
{
|
{
|
||||||
const char device[] = "lo";
|
const char device[] = "lo";
|
||||||
int rc =
|
TEST_ASSERT_SUCCESS_ERRNO (
|
||||||
zmq_setsockopt (socket, ZMQ_BINDTODEVICE, &device, sizeof (device) - 1);
|
zmq_setsockopt (socket, ZMQ_BINDTODEVICE, &device, sizeof (device) - 1));
|
||||||
assert (rc == 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO this is duplicated from test_pair_tcp
|
// TODO this is duplicated from test_pair_tcp
|
||||||
|
@@ -30,6 +30,7 @@
|
|||||||
#include "testutil.hpp"
|
#include "testutil.hpp"
|
||||||
#include "testutil_unity.hpp"
|
#include "testutil_unity.hpp"
|
||||||
#include <unity.h>
|
#include <unity.h>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
//
|
//
|
||||||
// Asynchronous proxy test using ZMQ_XPUB_NODROP and HWM:
|
// Asynchronous proxy test using ZMQ_XPUB_NODROP and HWM:
|
||||||
|
@@ -79,7 +79,7 @@ void test_req_correlate ()
|
|||||||
|
|
||||||
// Receive request id 1
|
// Receive request id 1
|
||||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_recv (&msg, router, 0));
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_recv (&msg, router, 0));
|
||||||
assert (zmq_msg_size (&msg) == sizeof (uint32_t));
|
TEST_ASSERT_EQUAL_UINT (sizeof (uint32_t), zmq_msg_size (&msg));
|
||||||
const uint32_t req_id = *static_cast<uint32_t *> (zmq_msg_data (&msg));
|
const uint32_t req_id = *static_cast<uint32_t *> (zmq_msg_data (&msg));
|
||||||
zmq_msg_t req_id_msg;
|
zmq_msg_t req_id_msg;
|
||||||
zmq_msg_init (&req_id_msg);
|
zmq_msg_init (&req_id_msg);
|
||||||
|
@@ -56,8 +56,8 @@ static void zap_handler (void *handler_)
|
|||||||
char *routing_id = s_recv (handler_);
|
char *routing_id = s_recv (handler_);
|
||||||
char *mechanism = s_recv (handler_);
|
char *mechanism = s_recv (handler_);
|
||||||
|
|
||||||
assert (streq (version, "1.0"));
|
TEST_ASSERT_EQUAL_STRING ("1.0", version);
|
||||||
assert (streq (mechanism, "NULL"));
|
TEST_ASSERT_EQUAL_STRING ("NULL", mechanism);
|
||||||
|
|
||||||
s_sendmore (handler_, version);
|
s_sendmore (handler_, version);
|
||||||
s_sendmore (handler_, sequence);
|
s_sendmore (handler_, sequence);
|
||||||
|
@@ -57,9 +57,9 @@ static void zap_handler (void *zap_)
|
|||||||
char *username = s_recv (zap_);
|
char *username = s_recv (zap_);
|
||||||
char *password = s_recv (zap_);
|
char *password = s_recv (zap_);
|
||||||
|
|
||||||
assert (streq (version, "1.0"));
|
TEST_ASSERT_EQUAL_STRING ("1.0", version);
|
||||||
assert (streq (mechanism, "PLAIN"));
|
TEST_ASSERT_EQUAL_STRING ("PLAIN", mechanism);
|
||||||
assert (streq (routing_id, "IDENT"));
|
TEST_ASSERT_EQUAL_STRING ("IDENT", routing_id);
|
||||||
|
|
||||||
s_sendmore (zap_, version);
|
s_sendmore (zap_, version);
|
||||||
s_sendmore (zap_, sequence);
|
s_sendmore (zap_, sequence);
|
||||||
@@ -83,8 +83,7 @@ static void zap_handler (void *zap_)
|
|||||||
free (username);
|
free (username);
|
||||||
free (password);
|
free (password);
|
||||||
}
|
}
|
||||||
int rc = zmq_close (zap_);
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_close (zap_));
|
||||||
assert (rc == 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void *zap_thread;
|
void *zap_thread;
|
||||||
|
@@ -27,97 +27,82 @@
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
#include "testutil.hpp"
|
#include "testutil.hpp"
|
||||||
|
#include "testutil_unity.hpp"
|
||||||
|
|
||||||
const char *SEQ_END = (const char *) 1;
|
const char *SEQ_END = (const char *) 1;
|
||||||
|
|
||||||
void bounce (void *server_, void *client_)
|
const char bounce_content[] = "12345678ABCDEFGH12345678abcdefgh";
|
||||||
|
|
||||||
|
static void send_bounce_msg (void *socket_)
|
||||||
{
|
{
|
||||||
const char content[] = "12345678ABCDEFGH12345678abcdefgh";
|
send_string_expect_success (socket_, bounce_content, ZMQ_SNDMORE);
|
||||||
|
send_string_expect_success (socket_, bounce_content, 0);
|
||||||
|
}
|
||||||
|
|
||||||
// Send message from client to server
|
static void recv_bounce_msg (void *socket_)
|
||||||
int rc = zmq_send (client_, content, 32, ZMQ_SNDMORE);
|
{
|
||||||
assert (rc == 32);
|
recv_string_expect_success (socket_, bounce_content, 0);
|
||||||
rc = zmq_send (client_, content, 32, 0);
|
|
||||||
assert (rc == 32);
|
|
||||||
|
|
||||||
// Receive message at server side
|
|
||||||
char buffer[32];
|
|
||||||
rc = zmq_recv (server_, buffer, 32, 0);
|
|
||||||
assert (rc == 32);
|
|
||||||
// Check that message is still the same
|
|
||||||
assert (memcmp (buffer, content, 32) == 0);
|
|
||||||
int rcvmore;
|
int rcvmore;
|
||||||
size_t sz = sizeof (rcvmore);
|
size_t sz = sizeof (rcvmore);
|
||||||
rc = zmq_getsockopt (server_, ZMQ_RCVMORE, &rcvmore, &sz);
|
TEST_ASSERT_SUCCESS_ERRNO (
|
||||||
assert (rc == 0);
|
zmq_getsockopt (socket_, ZMQ_RCVMORE, &rcvmore, &sz));
|
||||||
assert (rcvmore);
|
TEST_ASSERT_TRUE (rcvmore);
|
||||||
rc = zmq_recv (server_, buffer, 32, 0);
|
recv_string_expect_success (socket_, bounce_content, 0);
|
||||||
assert (rc == 32);
|
TEST_ASSERT_SUCCESS_ERRNO (
|
||||||
// Check that message is still the same
|
zmq_getsockopt (socket_, ZMQ_RCVMORE, &rcvmore, &sz));
|
||||||
assert (memcmp (buffer, content, 32) == 0);
|
TEST_ASSERT_FALSE (rcvmore);
|
||||||
rc = zmq_getsockopt (server_, ZMQ_RCVMORE, &rcvmore, &sz);
|
}
|
||||||
assert (rc == 0);
|
|
||||||
assert (!rcvmore);
|
void bounce (void *server_, void *client_)
|
||||||
|
{
|
||||||
|
// Send message from client to server
|
||||||
|
send_bounce_msg (client_);
|
||||||
|
|
||||||
|
// Receive message at server side and
|
||||||
|
// check that message is still the same
|
||||||
|
recv_bounce_msg (server_);
|
||||||
|
|
||||||
// Send two parts back to client
|
// Send two parts back to client
|
||||||
rc = zmq_send (server_, buffer, 32, ZMQ_SNDMORE);
|
send_bounce_msg (server_);
|
||||||
assert (rc == 32);
|
|
||||||
rc = zmq_send (server_, buffer, 32, 0);
|
|
||||||
assert (rc == 32);
|
|
||||||
|
|
||||||
// Receive the two parts at the client side
|
// Receive the two parts at the client side
|
||||||
rc = zmq_recv (client_, buffer, 32, 0);
|
recv_bounce_msg (client_);
|
||||||
assert (rc == 32);
|
}
|
||||||
// Check that message is still the same
|
|
||||||
assert (memcmp (buffer, content, 32) == 0);
|
static void send_bounce_msg_may_fail (void *socket_)
|
||||||
rc = zmq_getsockopt (client_, ZMQ_RCVMORE, &rcvmore, &sz);
|
{
|
||||||
assert (rc == 0);
|
int timeout = 250;
|
||||||
assert (rcvmore);
|
TEST_ASSERT_SUCCESS_ERRNO (
|
||||||
rc = zmq_recv (client_, buffer, 32, 0);
|
zmq_setsockopt (socket_, ZMQ_SNDTIMEO, &timeout, sizeof (int)));
|
||||||
assert (rc == 32);
|
int rc = zmq_send (socket_, bounce_content, 32, ZMQ_SNDMORE);
|
||||||
// Check that message is still the same
|
TEST_ASSERT_TRUE ((rc == 32) || ((rc == -1) && (errno == EAGAIN)));
|
||||||
assert (memcmp (buffer, content, 32) == 0);
|
rc = zmq_send (socket_, bounce_content, 32, 0);
|
||||||
rc = zmq_getsockopt (client_, ZMQ_RCVMORE, &rcvmore, &sz);
|
TEST_ASSERT_TRUE ((rc == 32) || ((rc == -1) && (errno == EAGAIN)));
|
||||||
assert (rc == 0);
|
}
|
||||||
assert (!rcvmore);
|
|
||||||
|
static void recv_bounce_msg_fail (void *socket_)
|
||||||
|
{
|
||||||
|
int timeout = 250;
|
||||||
|
char buffer[32];
|
||||||
|
TEST_ASSERT_SUCCESS_ERRNO (
|
||||||
|
zmq_setsockopt (socket_, ZMQ_RCVTIMEO, &timeout, sizeof (int)));
|
||||||
|
TEST_ASSERT_FAILURE_ERRNO (EAGAIN, zmq_recv (socket_, buffer, 32, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
void expect_bounce_fail (void *server_, void *client_)
|
void expect_bounce_fail (void *server_, void *client_)
|
||||||
{
|
{
|
||||||
const char *content = "12345678ABCDEFGH12345678abcdefgh";
|
|
||||||
char buffer[32];
|
|
||||||
int timeout = 250;
|
|
||||||
|
|
||||||
// Send message from client to server
|
// Send message from client to server
|
||||||
int rc = zmq_setsockopt (client_, ZMQ_SNDTIMEO, &timeout, sizeof (int));
|
send_bounce_msg_may_fail (client_);
|
||||||
assert (rc == 0);
|
|
||||||
rc = zmq_send (client_, content, 32, ZMQ_SNDMORE);
|
|
||||||
assert ((rc == 32) || ((rc == -1) && (errno == EAGAIN)));
|
|
||||||
rc = zmq_send (client_, content, 32, 0);
|
|
||||||
assert ((rc == 32) || ((rc == -1) && (errno == EAGAIN)));
|
|
||||||
|
|
||||||
// Receive message at server side (should not succeed)
|
// Receive message at server side (should not succeed)
|
||||||
rc = zmq_setsockopt (server_, ZMQ_RCVTIMEO, &timeout, sizeof (int));
|
recv_bounce_msg_fail (server_);
|
||||||
assert (rc == 0);
|
|
||||||
rc = zmq_recv (server_, buffer, 32, 0);
|
|
||||||
assert (rc == -1);
|
|
||||||
assert (zmq_errno () == EAGAIN);
|
|
||||||
|
|
||||||
// Send message from server to client to test other direction
|
// Send message from server to client to test other direction
|
||||||
// If connection failed, send may block, without a timeout
|
// If connection failed, send may block, without a timeout
|
||||||
rc = zmq_setsockopt (server_, ZMQ_SNDTIMEO, &timeout, sizeof (int));
|
send_bounce_msg_may_fail (server_);
|
||||||
assert (rc == 0);
|
|
||||||
rc = zmq_send (server_, content, 32, ZMQ_SNDMORE);
|
|
||||||
assert (rc == 32 || (rc == -1 && zmq_errno () == EAGAIN));
|
|
||||||
rc = zmq_send (server_, content, 32, 0);
|
|
||||||
assert (rc == 32 || (rc == -1 && zmq_errno () == EAGAIN));
|
|
||||||
|
|
||||||
// Receive message at client side (should not succeed)
|
// Receive message at client side (should not succeed)
|
||||||
rc = zmq_setsockopt (client_, ZMQ_RCVTIMEO, &timeout, sizeof (int));
|
recv_bounce_msg_fail (client_);
|
||||||
assert (rc == 0);
|
|
||||||
rc = zmq_recv (client_, buffer, 32, 0);
|
|
||||||
assert (rc == -1);
|
|
||||||
assert (zmq_errno () == EAGAIN);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char *s_recv (void *socket_)
|
char *s_recv (void *socket_)
|
||||||
@@ -155,12 +140,11 @@ void s_send_seq (void *socket_, ...)
|
|||||||
bool end = data == SEQ_END;
|
bool end = data == SEQ_END;
|
||||||
|
|
||||||
if (!prev) {
|
if (!prev) {
|
||||||
int rc = zmq_send (socket_, 0, 0, end ? 0 : ZMQ_SNDMORE);
|
TEST_ASSERT_SUCCESS_ERRNO (
|
||||||
assert (rc != -1);
|
zmq_send (socket_, 0, 0, end ? 0 : ZMQ_SNDMORE));
|
||||||
} else {
|
} else {
|
||||||
int rc = zmq_send (socket_, prev, strlen (prev) + 1,
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_send (
|
||||||
end ? 0 : ZMQ_SNDMORE);
|
socket_, prev, strlen (prev) + 1, end ? 0 : ZMQ_SNDMORE));
|
||||||
assert (rc != -1);
|
|
||||||
}
|
}
|
||||||
if (end)
|
if (end)
|
||||||
break;
|
break;
|
||||||
@@ -181,21 +165,20 @@ void s_recv_seq (void *socket_, ...)
|
|||||||
const char *data = va_arg (ap, const char *);
|
const char *data = va_arg (ap, const char *);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
int rc = zmq_msg_recv (&msg, socket_, 0);
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_recv (&msg, socket_, 0));
|
||||||
assert (rc != -1);
|
|
||||||
|
|
||||||
if (!data)
|
if (!data)
|
||||||
assert (zmq_msg_size (&msg) == 0);
|
TEST_ASSERT_EQUAL_INT (0, zmq_msg_size (&msg));
|
||||||
else
|
else
|
||||||
assert (strcmp (data, (const char *) zmq_msg_data (&msg)) == 0);
|
TEST_ASSERT_EQUAL_STRING (data, (const char *) zmq_msg_data (&msg));
|
||||||
|
|
||||||
data = va_arg (ap, const char *);
|
data = va_arg (ap, const char *);
|
||||||
bool end = data == SEQ_END;
|
bool end = data == SEQ_END;
|
||||||
|
|
||||||
rc = zmq_getsockopt (socket_, ZMQ_RCVMORE, &more, &more_size);
|
TEST_ASSERT_SUCCESS_ERRNO (
|
||||||
assert (rc == 0);
|
zmq_getsockopt (socket_, ZMQ_RCVMORE, &more, &more_size));
|
||||||
|
|
||||||
assert (!more == end);
|
TEST_ASSERT_TRUE (!more == end);
|
||||||
if (end)
|
if (end)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -208,9 +191,8 @@ void close_zero_linger (void *socket_)
|
|||||||
{
|
{
|
||||||
int linger = 0;
|
int linger = 0;
|
||||||
int rc = zmq_setsockopt (socket_, ZMQ_LINGER, &linger, sizeof (linger));
|
int rc = zmq_setsockopt (socket_, ZMQ_LINGER, &linger, sizeof (linger));
|
||||||
assert (rc == 0 || errno == ETERM);
|
TEST_ASSERT_TRUE (rc == 0 || errno == ETERM);
|
||||||
rc = zmq_close (socket_);
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_close (socket_));
|
||||||
assert (rc == 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup_test_environment ()
|
void setup_test_environment ()
|
||||||
@@ -302,9 +284,9 @@ int is_tipc_available ()
|
|||||||
int tipc = 0;
|
int tipc = 0;
|
||||||
|
|
||||||
void *ctx = zmq_init (1);
|
void *ctx = zmq_init (1);
|
||||||
assert (ctx);
|
TEST_ASSERT_NOT_NULL (ctx);
|
||||||
void *rep = zmq_socket (ctx, ZMQ_REP);
|
void *rep = zmq_socket (ctx, ZMQ_REP);
|
||||||
assert (rep);
|
TEST_ASSERT_NOT_NULL (rep);
|
||||||
tipc = zmq_bind (rep, "tipc://{5560,0,0}");
|
tipc = zmq_bind (rep, "tipc://{5560,0,0}");
|
||||||
|
|
||||||
zmq_close (rep);
|
zmq_close (rep);
|
||||||
@@ -352,13 +334,13 @@ sockaddr_in bind_bsd_socket (int socket)
|
|||||||
saddr.sin_port = htons (PORT_6);
|
saddr.sin_port = htons (PORT_6);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int rc = bind (socket, (struct sockaddr *) &saddr, sizeof (saddr));
|
TEST_ASSERT_SUCCESS_RAW_ERRNO (
|
||||||
assert (rc == 0);
|
bind (socket, (struct sockaddr *) &saddr, sizeof (saddr)));
|
||||||
|
|
||||||
#if !defined(_WIN32_WINNT) || (_WIN32_WINNT >= 0x0600)
|
#if !defined(_WIN32_WINNT) || (_WIN32_WINNT >= 0x0600)
|
||||||
socklen_t saddr_len = sizeof (saddr);
|
socklen_t saddr_len = sizeof (saddr);
|
||||||
rc = getsockname (socket, (struct sockaddr *) &saddr, &saddr_len);
|
TEST_ASSERT_SUCCESS_RAW_ERRNO (
|
||||||
assert (rc == 0);
|
getsockname (socket, (struct sockaddr *) &saddr, &saddr_len));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return saddr;
|
return saddr;
|
||||||
|
@@ -59,7 +59,6 @@
|
|||||||
|
|
||||||
#undef NDEBUG
|
#undef NDEBUG
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <assert.h>
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@@ -146,7 +146,7 @@ void internal_manage_test_sockets (void *socket_, bool add_)
|
|||||||
static void *test_sockets[MAX_TEST_SOCKETS];
|
static void *test_sockets[MAX_TEST_SOCKETS];
|
||||||
static size_t test_socket_count = 0;
|
static size_t test_socket_count = 0;
|
||||||
if (!socket_) {
|
if (!socket_) {
|
||||||
assert (!add_);
|
TEST_ASSERT_FALSE (add_);
|
||||||
|
|
||||||
// force-close all sockets
|
// force-close all sockets
|
||||||
if (test_socket_count) {
|
if (test_socket_count) {
|
||||||
|
@@ -62,7 +62,7 @@ class test_ip_resolver_t : public zmq::ip_resolver_t
|
|||||||
unsigned lut_len = sizeof (dns_lut) / sizeof (dns_lut[0]);
|
unsigned lut_len = sizeof (dns_lut) / sizeof (dns_lut[0]);
|
||||||
struct addrinfo ai;
|
struct addrinfo ai;
|
||||||
|
|
||||||
assert (service_ == NULL);
|
TEST_ASSERT_NULL (service_);
|
||||||
|
|
||||||
bool ipv6 = (hints_->ai_family == AF_INET6);
|
bool ipv6 = (hints_->ai_family == AF_INET6);
|
||||||
bool no_dns = (hints_->ai_flags & AI_NUMERICHOST) != 0;
|
bool no_dns = (hints_->ai_flags & AI_NUMERICHOST) != 0;
|
||||||
@@ -805,9 +805,7 @@ static void test_addr (int family_, const char *addr_, bool multicast_)
|
|||||||
test_ip_resolver_t resolver (resolver_opts);
|
test_ip_resolver_t resolver (resolver_opts);
|
||||||
zmq::ip_addr_t addr;
|
zmq::ip_addr_t addr;
|
||||||
|
|
||||||
int rc = resolver.resolve (&addr, addr_);
|
TEST_ASSERT_SUCCESS_ERRNO (resolver.resolve (&addr, addr_));
|
||||||
|
|
||||||
assert (rc == 0);
|
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL (family_, addr.family ());
|
TEST_ASSERT_EQUAL (family_, addr.family ());
|
||||||
TEST_ASSERT_EQUAL (multicast_, addr.is_multicast ());
|
TEST_ASSERT_EQUAL (multicast_, addr.is_multicast ());
|
||||||
|
@@ -27,22 +27,23 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
// On windows we can receive an IPv4 address even when an IPv6 is requested, if
|
// On windows we can receive an IPv4 address even when an IPv6 is requested, if
|
||||||
// we're in this situation then we compare to 'expected_addr_v4_failover_'
|
// we're in this situation then we compare to 'expected_addr_v4_failover_'
|
||||||
// instead.
|
// instead.
|
||||||
void validate_address(int family, const zmq::ip_addr_t *addr_,
|
void validate_address (int family,
|
||||||
const char *expected_addr_,
|
const zmq::ip_addr_t *addr_,
|
||||||
uint16_t expected_port_ = 0,
|
const char *expected_addr_,
|
||||||
uint16_t expected_zone_ = 0,
|
uint16_t expected_port_ = 0,
|
||||||
const char *expected_addr_v4_failover_ = NULL)
|
uint16_t expected_zone_ = 0,
|
||||||
|
const char *expected_addr_v4_failover_ = NULL)
|
||||||
{
|
{
|
||||||
#if defined ZMQ_HAVE_WINDOWS
|
#if defined ZMQ_HAVE_WINDOWS
|
||||||
if (family == AF_INET6 && expected_addr_v4_failover_ != NULL &&
|
if (family == AF_INET6 && expected_addr_v4_failover_ != NULL
|
||||||
addr_->family () == AF_INET) {
|
&& addr_->family () == AF_INET) {
|
||||||
// We've requested an IPv6 but the system gave us an IPv4, use the
|
// We've requested an IPv6 but the system gave us an IPv4, use the
|
||||||
// failover address
|
// failover address
|
||||||
family = AF_INET;
|
family = AF_INET;
|
||||||
expected_addr_ = expected_addr_v4_failover_;
|
expected_addr_ = expected_addr_v4_failover_;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
(void)expected_addr_v4_failover_;
|
(void) expected_addr_v4_failover_;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL (family, addr_->family ());
|
TEST_ASSERT_EQUAL (family, addr_->family ());
|
||||||
@@ -51,7 +52,8 @@ void validate_address(int family, const zmq::ip_addr_t *addr_,
|
|||||||
struct in6_addr expected_addr;
|
struct in6_addr expected_addr;
|
||||||
const sockaddr_in6 *ip6_addr = &addr_->ipv6;
|
const sockaddr_in6 *ip6_addr = &addr_->ipv6;
|
||||||
|
|
||||||
assert (test_inet_pton (AF_INET6, expected_addr_, &expected_addr) == 1);
|
TEST_ASSERT_EQUAL (
|
||||||
|
1, test_inet_pton (AF_INET6, expected_addr_, &expected_addr));
|
||||||
|
|
||||||
int neq = memcmp (&ip6_addr->sin6_addr, &expected_addr,
|
int neq = memcmp (&ip6_addr->sin6_addr, &expected_addr,
|
||||||
sizeof (expected_addr_));
|
sizeof (expected_addr_));
|
||||||
@@ -63,7 +65,8 @@ void validate_address(int family, const zmq::ip_addr_t *addr_,
|
|||||||
struct in_addr expected_addr;
|
struct in_addr expected_addr;
|
||||||
const sockaddr_in *ip4_addr = &addr_->ipv4;
|
const sockaddr_in *ip4_addr = &addr_->ipv4;
|
||||||
|
|
||||||
assert (test_inet_pton (AF_INET, expected_addr_, &expected_addr) == 1);
|
TEST_ASSERT_EQUAL (
|
||||||
|
1, test_inet_pton (AF_INET, expected_addr_, &expected_addr));
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL (expected_addr.s_addr, ip4_addr->sin_addr.s_addr);
|
TEST_ASSERT_EQUAL (expected_addr.s_addr, ip4_addr->sin_addr.s_addr);
|
||||||
TEST_ASSERT_EQUAL (htons (expected_port_), ip4_addr->sin_port);
|
TEST_ASSERT_EQUAL (htons (expected_port_), ip4_addr->sin_port);
|
||||||
|
Reference in New Issue
Block a user