mirror of
https://github.com/zeromq/libzmq.git
synced 2025-05-02 07:31:39 +02:00
Problem: tests without test framework
Solution: migrate to unity
This commit is contained in:
parent
b70d31c432
commit
00f4bd05be
24
Makefile.am
24
Makefile.am
@ -503,7 +503,8 @@ tests_test_sub_forward_LDADD = src/libzmq.la ${UNITY_LIBS}
|
|||||||
tests_test_sub_forward_CPPFLAGS = ${UNITY_CPPFLAGS}
|
tests_test_sub_forward_CPPFLAGS = ${UNITY_CPPFLAGS}
|
||||||
|
|
||||||
tests_test_invalid_rep_SOURCES = tests/test_invalid_rep.cpp
|
tests_test_invalid_rep_SOURCES = tests/test_invalid_rep.cpp
|
||||||
tests_test_invalid_rep_LDADD = src/libzmq.la
|
tests_test_invalid_rep_LDADD = src/libzmq.la ${UNITY_LIBS}
|
||||||
|
tests_test_invalid_rep_CPPFLAGS = ${UNITY_CPPFLAGS}
|
||||||
|
|
||||||
tests_test_msg_flags_SOURCES = tests/test_msg_flags.cpp
|
tests_test_msg_flags_SOURCES = tests/test_msg_flags.cpp
|
||||||
tests_test_msg_flags_LDADD = src/libzmq.la
|
tests_test_msg_flags_LDADD = src/libzmq.la
|
||||||
@ -528,7 +529,8 @@ tests_test_term_endpoint_LDADD = src/libzmq.la ${UNITY_LIBS}
|
|||||||
tests_test_term_endpoint_CPPFLAGS = ${UNITY_CPPFLAGS}
|
tests_test_term_endpoint_CPPFLAGS = ${UNITY_CPPFLAGS}
|
||||||
|
|
||||||
tests_test_srcfd_SOURCES = tests/test_srcfd.cpp
|
tests_test_srcfd_SOURCES = tests/test_srcfd.cpp
|
||||||
tests_test_srcfd_LDADD = src/libzmq.la
|
tests_test_srcfd_LDADD = src/libzmq.la ${UNITY_LIBS}
|
||||||
|
tests_test_srcfd_CPPFLAGS = ${UNITY_CPPFLAGS}
|
||||||
|
|
||||||
tests_test_monitor_SOURCES = tests/test_monitor.cpp
|
tests_test_monitor_SOURCES = tests/test_monitor.cpp
|
||||||
tests_test_monitor_LDADD = src/libzmq.la
|
tests_test_monitor_LDADD = src/libzmq.la
|
||||||
@ -664,7 +666,8 @@ tests_test_bind_src_address_LDADD = src/libzmq.la ${UNITY_LIBS}
|
|||||||
tests_test_bind_src_address_CPPFLAGS = ${UNITY_CPPFLAGS}
|
tests_test_bind_src_address_CPPFLAGS = ${UNITY_CPPFLAGS}
|
||||||
|
|
||||||
tests_test_metadata_SOURCES = tests/test_metadata.cpp
|
tests_test_metadata_SOURCES = tests/test_metadata.cpp
|
||||||
tests_test_metadata_LDADD = src/libzmq.la
|
tests_test_metadata_LDADD = src/libzmq.la ${UNITY_LIBS}
|
||||||
|
tests_test_metadata_CPPFLAGS = ${UNITY_CPPFLAGS}
|
||||||
|
|
||||||
tests_test_capabilities_SOURCES = tests/test_capabilities.cpp
|
tests_test_capabilities_SOURCES = tests/test_capabilities.cpp
|
||||||
tests_test_capabilities_LDADD = src/libzmq.la ${UNITY_LIBS}
|
tests_test_capabilities_LDADD = src/libzmq.la ${UNITY_LIBS}
|
||||||
@ -703,7 +706,8 @@ tests_test_heartbeats_LDADD = src/libzmq.la ${UNITY_LIBS}
|
|||||||
tests_test_heartbeats_CPPFLAGS = ${UNITY_CPPFLAGS}
|
tests_test_heartbeats_CPPFLAGS = ${UNITY_CPPFLAGS}
|
||||||
|
|
||||||
tests_test_stream_exceeds_buffer_SOURCES = tests/test_stream_exceeds_buffer.cpp
|
tests_test_stream_exceeds_buffer_SOURCES = tests/test_stream_exceeds_buffer.cpp
|
||||||
tests_test_stream_exceeds_buffer_LDADD = src/libzmq.la
|
tests_test_stream_exceeds_buffer_LDADD = src/libzmq.la ${UNITY_LIBS}
|
||||||
|
tests_test_stream_exceeds_buffer_CPPFLAGS = ${UNITY_CPPFLAGS}
|
||||||
|
|
||||||
tests_test_pub_invert_matching_SOURCES = tests/test_pub_invert_matching.cpp
|
tests_test_pub_invert_matching_SOURCES = tests/test_pub_invert_matching.cpp
|
||||||
tests_test_pub_invert_matching_LDADD = src/libzmq.la ${UNITY_LIBS}
|
tests_test_pub_invert_matching_LDADD = src/libzmq.la ${UNITY_LIBS}
|
||||||
@ -718,7 +722,8 @@ tests_test_base85_LDADD = src/libzmq.la ${UNITY_LIBS}
|
|||||||
tests_test_base85_CPPFLAGS = ${UNITY_CPPFLAGS}
|
tests_test_base85_CPPFLAGS = ${UNITY_CPPFLAGS}
|
||||||
|
|
||||||
tests_test_sodium_SOURCES = tests/test_sodium.cpp
|
tests_test_sodium_SOURCES = tests/test_sodium.cpp
|
||||||
tests_test_sodium_LDADD = src/libzmq.la
|
tests_test_sodium_LDADD = src/libzmq.la ${UNITY_LIBS}
|
||||||
|
tests_test_sodium_CPPFLAGS = ${UNITY_CPPFLAGS}
|
||||||
|
|
||||||
tests_test_socket_null_SOURCES = tests/test_socket_null.cpp
|
tests_test_socket_null_SOURCES = tests/test_socket_null.cpp
|
||||||
tests_test_socket_null_LDADD = src/libzmq.la ${UNITY_LIBS}
|
tests_test_socket_null_LDADD = src/libzmq.la ${UNITY_LIBS}
|
||||||
@ -783,7 +788,8 @@ test_apps += \
|
|||||||
tests/test_filter_ipc
|
tests/test_filter_ipc
|
||||||
|
|
||||||
tests_test_shutdown_stress_SOURCES = tests/test_shutdown_stress.cpp
|
tests_test_shutdown_stress_SOURCES = tests/test_shutdown_stress.cpp
|
||||||
tests_test_shutdown_stress_LDADD = src/libzmq.la
|
tests_test_shutdown_stress_LDADD = src/libzmq.la ${UNITY_LIBS}
|
||||||
|
tests_test_shutdown_stress_CPPFLAGS = ${UNITY_CPPFLAGS}
|
||||||
|
|
||||||
tests_test_ipc_wildcard_SOURCES = tests/test_ipc_wildcard.cpp
|
tests_test_ipc_wildcard_SOURCES = tests/test_ipc_wildcard.cpp
|
||||||
tests_test_ipc_wildcard_LDADD = src/libzmq.la
|
tests_test_ipc_wildcard_LDADD = src/libzmq.la
|
||||||
@ -865,7 +871,8 @@ tests_test_router_mandatory_tipc_SOURCES = tests/test_router_mandatory_tipc.cpp
|
|||||||
tests_test_router_mandatory_tipc_LDADD = src/libzmq.la
|
tests_test_router_mandatory_tipc_LDADD = src/libzmq.la
|
||||||
|
|
||||||
tests_test_shutdown_stress_tipc_SOURCES = tests/test_shutdown_stress_tipc.cpp
|
tests_test_shutdown_stress_tipc_SOURCES = tests/test_shutdown_stress_tipc.cpp
|
||||||
tests_test_shutdown_stress_tipc_LDADD = src/libzmq.la
|
tests_test_shutdown_stress_tipc_LDADD = src/libzmq.la ${UNITY_LIBS}
|
||||||
|
tests_test_shutdown_stress_tipc_CPPFLAGS = ${UNITY_CPPFLAGS}
|
||||||
|
|
||||||
tests_test_sub_forward_tipc_SOURCES = tests/test_sub_forward_tipc.cpp
|
tests_test_sub_forward_tipc_SOURCES = tests/test_sub_forward_tipc.cpp
|
||||||
tests_test_sub_forward_tipc_LDADD = src/libzmq.la ${UNITY_LIBS}
|
tests_test_sub_forward_tipc_LDADD = src/libzmq.la ${UNITY_LIBS}
|
||||||
@ -945,7 +952,8 @@ tests_test_radio_dish_LDADD = src/libzmq.la ${UNITY_LIBS}
|
|||||||
tests_test_radio_dish_CPPFLAGS = ${UNITY_CPPFLAGS}
|
tests_test_radio_dish_CPPFLAGS = ${UNITY_CPPFLAGS}
|
||||||
|
|
||||||
tests_test_scatter_gather_SOURCES = tests/test_scatter_gather.cpp
|
tests_test_scatter_gather_SOURCES = tests/test_scatter_gather.cpp
|
||||||
tests_test_scatter_gather_LDADD = src/libzmq.la
|
tests_test_scatter_gather_LDADD = src/libzmq.la ${UNITY_LIBS}
|
||||||
|
tests_test_scatter_gather_CPPFLAGS = ${UNITY_CPPFLAGS}
|
||||||
|
|
||||||
tests_test_dgram_SOURCES = tests/test_dgram.cpp
|
tests_test_dgram_SOURCES = tests/test_dgram.cpp
|
||||||
tests_test_dgram_LDADD = src/libzmq.la ${UNITY_LIBS}
|
tests_test_dgram_LDADD = src/libzmq.la ${UNITY_LIBS}
|
||||||
|
@ -28,70 +28,74 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "testutil.hpp"
|
#include "testutil.hpp"
|
||||||
|
#include "testutil_unity.hpp"
|
||||||
|
|
||||||
int main (void)
|
#include <unity.h>
|
||||||
|
|
||||||
|
void setUp ()
|
||||||
|
{
|
||||||
|
setup_test_context ();
|
||||||
|
}
|
||||||
|
|
||||||
|
void tearDown ()
|
||||||
|
{
|
||||||
|
teardown_test_context ();
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_invalid_rep ()
|
||||||
{
|
{
|
||||||
setup_test_environment ();
|
|
||||||
// Create REQ/ROUTER wiring.
|
// Create REQ/ROUTER wiring.
|
||||||
void *ctx = zmq_ctx_new ();
|
void *router_socket = test_context_socket (ZMQ_ROUTER);
|
||||||
assert (ctx);
|
void *req_socket = test_context_socket (ZMQ_REQ);
|
||||||
|
|
||||||
void *router_socket = zmq_socket (ctx, ZMQ_ROUTER);
|
|
||||||
assert (router_socket);
|
|
||||||
|
|
||||||
void *req_socket = zmq_socket (ctx, ZMQ_REQ);
|
|
||||||
assert (req_socket);
|
|
||||||
|
|
||||||
int linger = 0;
|
int linger = 0;
|
||||||
int rc = zmq_setsockopt (router_socket, ZMQ_LINGER, &linger, sizeof (int));
|
TEST_ASSERT_SUCCESS_ERRNO (
|
||||||
assert (rc == 0);
|
zmq_setsockopt (router_socket, ZMQ_LINGER, &linger, sizeof (int)));
|
||||||
rc = zmq_setsockopt (req_socket, ZMQ_LINGER, &linger, sizeof (int));
|
TEST_ASSERT_SUCCESS_ERRNO (
|
||||||
assert (rc == 0);
|
zmq_setsockopt (req_socket, ZMQ_LINGER, &linger, sizeof (int)));
|
||||||
rc = zmq_bind (router_socket, "inproc://hi");
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (router_socket, "inproc://hi"));
|
||||||
assert (rc == 0);
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (req_socket, "inproc://hi"));
|
||||||
rc = zmq_connect (req_socket, "inproc://hi");
|
|
||||||
assert (rc == 0);
|
|
||||||
|
|
||||||
// Initial request.
|
// Initial request.
|
||||||
rc = zmq_send (req_socket, "r", 1, 0);
|
send_string_expect_success (req_socket, "r", 0);
|
||||||
assert (rc == 1);
|
|
||||||
|
|
||||||
// Receive the request.
|
// Receive the request.
|
||||||
char addr[32];
|
char addr[32];
|
||||||
int addr_size;
|
int addr_size;
|
||||||
char bottom[1];
|
char bottom[1];
|
||||||
char body[1];
|
char body[1];
|
||||||
addr_size = zmq_recv (router_socket, addr, sizeof (addr), 0);
|
TEST_ASSERT_SUCCESS_ERRNO (
|
||||||
assert (addr_size >= 0);
|
addr_size = zmq_recv (router_socket, addr, sizeof (addr), 0));
|
||||||
rc = zmq_recv (router_socket, bottom, sizeof (bottom), 0);
|
TEST_ASSERT_EQUAL_INT (0, TEST_ASSERT_SUCCESS_ERRNO (zmq_recv (
|
||||||
assert (rc == 0);
|
router_socket, bottom, sizeof (bottom), 0)));
|
||||||
rc = zmq_recv (router_socket, body, sizeof (body), 0);
|
TEST_ASSERT_EQUAL_INT (1, TEST_ASSERT_SUCCESS_ERRNO (zmq_recv (
|
||||||
assert (rc == 1);
|
router_socket, body, sizeof (body), 0)));
|
||||||
|
|
||||||
// Send invalid reply.
|
// Send invalid reply.
|
||||||
rc = zmq_send (router_socket, addr, addr_size, 0);
|
TEST_ASSERT_EQUAL_INT (addr_size, TEST_ASSERT_SUCCESS_ERRNO (zmq_send (
|
||||||
assert (rc == addr_size);
|
router_socket, addr, addr_size, 0)));
|
||||||
|
|
||||||
// Send valid reply.
|
// Send valid reply.
|
||||||
rc = zmq_send (router_socket, addr, addr_size, ZMQ_SNDMORE);
|
TEST_ASSERT_EQUAL_INT (
|
||||||
assert (rc == addr_size);
|
addr_size, TEST_ASSERT_SUCCESS_ERRNO (
|
||||||
rc = zmq_send (router_socket, bottom, 0, ZMQ_SNDMORE);
|
zmq_send (router_socket, addr, addr_size, ZMQ_SNDMORE)));
|
||||||
assert (rc == 0);
|
TEST_ASSERT_EQUAL_INT (0, TEST_ASSERT_SUCCESS_ERRNO (zmq_send (
|
||||||
rc = zmq_send (router_socket, "b", 1, 0);
|
router_socket, bottom, 0, ZMQ_SNDMORE)));
|
||||||
assert (rc == 1);
|
send_string_expect_success (router_socket, "b", 0);
|
||||||
|
|
||||||
// Check whether we've got the valid reply.
|
// Check whether we've got the valid reply.
|
||||||
rc = zmq_recv (req_socket, body, sizeof (body), 0);
|
recv_string_expect_success (req_socket, "b", 0);
|
||||||
assert (rc == 1);
|
|
||||||
assert (body[0] == 'b');
|
|
||||||
|
|
||||||
// Tear down the wiring.
|
// Tear down the wiring.
|
||||||
rc = zmq_close (router_socket);
|
test_context_socket_close (router_socket);
|
||||||
assert (rc == 0);
|
test_context_socket_close (req_socket);
|
||||||
rc = zmq_close (req_socket);
|
}
|
||||||
assert (rc == 0);
|
|
||||||
rc = zmq_ctx_term (ctx);
|
int main ()
|
||||||
assert (rc == 0);
|
{
|
||||||
|
setup_test_environment ();
|
||||||
return 0;
|
|
||||||
|
UNITY_BEGIN ();
|
||||||
|
RUN_TEST (test_invalid_rep);
|
||||||
|
return UNITY_END ();
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,17 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "testutil.hpp"
|
#include "testutil.hpp"
|
||||||
|
#include "testutil_unity.hpp"
|
||||||
|
|
||||||
|
#include <unity.h>
|
||||||
|
|
||||||
|
void setUp ()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void tearDown ()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
static void zap_handler (void *handler_)
|
static void zap_handler (void *handler_)
|
||||||
{
|
{
|
||||||
@ -72,59 +83,53 @@ static void zap_handler (void *handler_)
|
|||||||
close_zero_linger (handler_);
|
close_zero_linger (handler_);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main (void)
|
void test_metadata ()
|
||||||
{
|
{
|
||||||
setup_test_environment ();
|
|
||||||
size_t len = MAX_SOCKET_STRING;
|
|
||||||
char my_endpoint[MAX_SOCKET_STRING];
|
char my_endpoint[MAX_SOCKET_STRING];
|
||||||
void *ctx = zmq_ctx_new ();
|
setup_test_context ();
|
||||||
assert (ctx);
|
|
||||||
|
|
||||||
// Spawn ZAP handler
|
// Spawn ZAP handler
|
||||||
// We create and bind ZAP socket in main thread to avoid case
|
// We create and bind ZAP socket in main thread to avoid case
|
||||||
// where child thread does not start up fast enough.
|
// where child thread does not start up fast enough.
|
||||||
void *handler = zmq_socket (ctx, ZMQ_REP);
|
void *handler = zmq_socket (get_test_context (), ZMQ_REP);
|
||||||
assert (handler);
|
TEST_ASSERT_NOT_NULL (handler);
|
||||||
int rc = zmq_bind (handler, "inproc://zeromq.zap.01");
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (handler, "inproc://zeromq.zap.01"));
|
||||||
assert (rc == 0);
|
|
||||||
void *zap_thread = zmq_threadstart (&zap_handler, handler);
|
void *zap_thread = zmq_threadstart (&zap_handler, handler);
|
||||||
|
|
||||||
void *server = zmq_socket (ctx, ZMQ_DEALER);
|
void *server = test_context_socket (ZMQ_DEALER);
|
||||||
assert (server);
|
void *client = test_context_socket (ZMQ_DEALER);
|
||||||
void *client = zmq_socket (ctx, ZMQ_DEALER);
|
TEST_ASSERT_SUCCESS_ERRNO (
|
||||||
assert (client);
|
zmq_setsockopt (server, ZMQ_ZAP_DOMAIN, "DOMAIN", 6));
|
||||||
rc = zmq_setsockopt (server, ZMQ_ZAP_DOMAIN, "DOMAIN", 6);
|
bind_loopback_ipv4 (server, my_endpoint, sizeof (my_endpoint));
|
||||||
assert (rc == 0);
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (client, my_endpoint));
|
||||||
rc = zmq_bind (server, "tcp://127.0.0.1:*");
|
|
||||||
assert (rc == 0);
|
|
||||||
rc = zmq_getsockopt (server, ZMQ_LAST_ENDPOINT, my_endpoint, &len);
|
|
||||||
assert (rc == 0);
|
|
||||||
rc = zmq_connect (client, my_endpoint);
|
|
||||||
assert (rc == 0);
|
|
||||||
|
|
||||||
s_send (client, "This is a message");
|
s_send (client, "This is a message");
|
||||||
zmq_msg_t msg;
|
zmq_msg_t msg;
|
||||||
zmq_msg_init (&msg);
|
zmq_msg_init (&msg);
|
||||||
rc = zmq_msg_recv (&msg, server, 0);
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_recv (&msg, server, 0));
|
||||||
assert (rc != -1);
|
TEST_ASSERT_EQUAL_STRING ("World", zmq_msg_gets (&msg, "Hello"));
|
||||||
assert (streq (zmq_msg_gets (&msg, "Hello"), "World"));
|
TEST_ASSERT_EQUAL_STRING ("DEALER", zmq_msg_gets (&msg, "Socket-Type"));
|
||||||
assert (streq (zmq_msg_gets (&msg, "Socket-Type"), "DEALER"));
|
TEST_ASSERT_EQUAL_STRING ("anonymous", zmq_msg_gets (&msg, "User-Id"));
|
||||||
assert (streq (zmq_msg_gets (&msg, "User-Id"), "anonymous"));
|
TEST_ASSERT_EQUAL_STRING ("127.0.0.1", zmq_msg_gets (&msg, "Peer-Address"));
|
||||||
assert (streq (zmq_msg_gets (&msg, "Peer-Address"), "127.0.0.1"));
|
|
||||||
|
|
||||||
assert (zmq_msg_gets (&msg, "No Such") == NULL);
|
TEST_ASSERT_NULL (zmq_msg_gets (&msg, "No Such"));
|
||||||
assert (zmq_errno () == EINVAL);
|
TEST_ASSERT_EQUAL_INT (EINVAL, zmq_errno ());
|
||||||
zmq_msg_close (&msg);
|
zmq_msg_close (&msg);
|
||||||
|
|
||||||
close_zero_linger (client);
|
test_context_socket_close_zero_linger (client);
|
||||||
close_zero_linger (server);
|
test_context_socket_close_zero_linger (server);
|
||||||
|
|
||||||
// Shutdown
|
// Shutdown
|
||||||
rc = zmq_ctx_term (ctx);
|
teardown_test_context ();
|
||||||
assert (rc == 0);
|
|
||||||
|
|
||||||
// Wait until ZAP handler terminates
|
// Wait until ZAP handler terminates
|
||||||
zmq_threadclose (zap_thread);
|
zmq_threadclose (zap_thread);
|
||||||
|
}
|
||||||
return 0;
|
|
||||||
|
int main ()
|
||||||
|
{
|
||||||
|
setup_test_environment ();
|
||||||
|
UNITY_BEGIN ();
|
||||||
|
RUN_TEST (test_metadata);
|
||||||
|
return UNITY_END ();
|
||||||
}
|
}
|
||||||
|
@ -28,57 +28,70 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "testutil.hpp"
|
#include "testutil.hpp"
|
||||||
|
#include "testutil_unity.hpp"
|
||||||
|
|
||||||
int main (void)
|
#include <unity.h>
|
||||||
|
|
||||||
|
void setUp ()
|
||||||
{
|
{
|
||||||
setup_test_environment ();
|
setup_test_context ();
|
||||||
void *ctx = zmq_ctx_new ();
|
}
|
||||||
assert (ctx);
|
|
||||||
|
|
||||||
void *scatter = zmq_socket (ctx, ZMQ_SCATTER);
|
void tearDown ()
|
||||||
void *gather = zmq_socket (ctx, ZMQ_GATHER);
|
{
|
||||||
void *gather2 = zmq_socket (ctx, ZMQ_GATHER);
|
teardown_test_context ();
|
||||||
|
}
|
||||||
|
|
||||||
int rc = zmq_bind (scatter, "inproc://test-scatter-gather");
|
void test_scatter_gather_multipart_fails ()
|
||||||
assert (rc == 0);
|
{
|
||||||
|
void *scatter = test_context_socket (ZMQ_SCATTER);
|
||||||
|
void *gather = test_context_socket (ZMQ_GATHER);
|
||||||
|
|
||||||
rc = zmq_connect (gather, "inproc://test-scatter-gather");
|
TEST_ASSERT_SUCCESS_ERRNO (
|
||||||
assert (rc == 0);
|
zmq_bind (scatter, "inproc://test-scatter-gather"));
|
||||||
|
|
||||||
rc = zmq_connect (gather2, "inproc://test-scatter-gather");
|
TEST_ASSERT_SUCCESS_ERRNO (
|
||||||
assert (rc == 0);
|
zmq_connect (gather, "inproc://test-scatter-gather"));
|
||||||
|
|
||||||
// Should fail, multipart is not supported
|
// Should fail, multipart is not supported
|
||||||
rc = s_sendmore (scatter, "1");
|
TEST_ASSERT_FAILURE_ERRNO (EINVAL, s_sendmore (scatter, "1"));
|
||||||
assert (rc == -1);
|
|
||||||
|
|
||||||
rc = s_send (scatter, "1");
|
test_context_socket_close (scatter);
|
||||||
assert (rc == 1);
|
test_context_socket_close (gather);
|
||||||
|
}
|
||||||
rc = s_send (scatter, "2");
|
|
||||||
assert (rc == 1);
|
void test_scatter_gather ()
|
||||||
|
{
|
||||||
char *message = s_recv (gather);
|
void *scatter = test_context_socket (ZMQ_SCATTER);
|
||||||
assert (message);
|
void *gather = test_context_socket (ZMQ_GATHER);
|
||||||
assert (streq (message, "1"));
|
void *gather2 = test_context_socket (ZMQ_GATHER);
|
||||||
free (message);
|
|
||||||
|
TEST_ASSERT_SUCCESS_ERRNO (
|
||||||
message = s_recv (gather2);
|
zmq_bind (scatter, "inproc://test-scatter-gather"));
|
||||||
assert (message);
|
|
||||||
assert (streq (message, "2"));
|
TEST_ASSERT_SUCCESS_ERRNO (
|
||||||
free (message);
|
zmq_connect (gather, "inproc://test-scatter-gather"));
|
||||||
|
|
||||||
rc = zmq_close (scatter);
|
TEST_ASSERT_SUCCESS_ERRNO (
|
||||||
assert (rc == 0);
|
zmq_connect (gather2, "inproc://test-scatter-gather"));
|
||||||
|
|
||||||
rc = zmq_close (gather);
|
send_string_expect_success (scatter, "1", 0);
|
||||||
assert (rc == 0);
|
send_string_expect_success (scatter, "2", 0);
|
||||||
|
|
||||||
rc = zmq_close (gather2);
|
recv_string_expect_success (gather, "1", 0);
|
||||||
assert (rc == 0);
|
recv_string_expect_success (gather2, "2", 0);
|
||||||
|
|
||||||
rc = zmq_ctx_term (ctx);
|
test_context_socket_close (scatter);
|
||||||
assert (rc == 0);
|
test_context_socket_close (gather);
|
||||||
|
test_context_socket_close (gather2);
|
||||||
return 0;
|
}
|
||||||
|
|
||||||
|
int main ()
|
||||||
|
{
|
||||||
|
setup_test_environment ();
|
||||||
|
|
||||||
|
UNITY_BEGIN ();
|
||||||
|
RUN_TEST (test_scatter_gather);
|
||||||
|
RUN_TEST (test_scatter_gather_multipart_fails);
|
||||||
|
return UNITY_END ();
|
||||||
}
|
}
|
||||||
|
@ -28,73 +28,70 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "testutil.hpp"
|
#include "testutil.hpp"
|
||||||
|
#include "testutil_unity.hpp"
|
||||||
|
|
||||||
|
void setUp ()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void tearDown ()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
#define THREAD_COUNT 100
|
#define THREAD_COUNT 100
|
||||||
|
|
||||||
struct thread_data
|
struct thread_data
|
||||||
{
|
{
|
||||||
void *ctx;
|
|
||||||
char endpoint[MAX_SOCKET_STRING];
|
char endpoint[MAX_SOCKET_STRING];
|
||||||
};
|
};
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
static void worker (void *data_)
|
static void worker (void *data_)
|
||||||
{
|
{
|
||||||
int rc;
|
|
||||||
void *socket;
|
|
||||||
struct thread_data *tdata = (struct thread_data *) data_;
|
struct thread_data *tdata = (struct thread_data *) data_;
|
||||||
|
|
||||||
socket = zmq_socket (tdata->ctx, ZMQ_SUB);
|
void *socket = zmq_socket (get_test_context (), ZMQ_SUB);
|
||||||
assert (socket);
|
|
||||||
|
|
||||||
rc = zmq_connect (socket, tdata->endpoint);
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (socket, tdata->endpoint));
|
||||||
assert (rc == 0);
|
|
||||||
|
|
||||||
// Start closing the socket while the connecting process is underway.
|
// Start closing the socket while the connecting process is underway.
|
||||||
rc = zmq_close (socket);
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_close (socket));
|
||||||
assert (rc == 0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main (void)
|
void test_shutdown_stress ()
|
||||||
{
|
{
|
||||||
setup_test_environment ();
|
|
||||||
void *socket;
|
|
||||||
int i;
|
|
||||||
int j;
|
|
||||||
int rc;
|
|
||||||
void *threads[THREAD_COUNT];
|
void *threads[THREAD_COUNT];
|
||||||
|
|
||||||
for (j = 0; j != 10; j++) {
|
for (int j = 0; j != 10; j++) {
|
||||||
// Check the shutdown with many parallel I/O threads.
|
// Check the shutdown with many parallel I/O threads.
|
||||||
struct thread_data tdata;
|
struct thread_data tdata;
|
||||||
tdata.ctx = zmq_ctx_new ();
|
setup_test_context ();
|
||||||
assert (tdata.ctx);
|
zmq_ctx_set (get_test_context (), ZMQ_IO_THREADS, 7);
|
||||||
zmq_ctx_set (tdata.ctx, ZMQ_IO_THREADS, 7);
|
|
||||||
|
|
||||||
socket = zmq_socket (tdata.ctx, ZMQ_PUB);
|
void *socket = test_context_socket (ZMQ_PUB);
|
||||||
assert (socket);
|
|
||||||
|
|
||||||
rc = zmq_bind (socket, "tcp://127.0.0.1:*");
|
bind_loopback_ipv4 (socket, tdata.endpoint, sizeof (tdata.endpoint));
|
||||||
assert (rc == 0);
|
|
||||||
size_t len = MAX_SOCKET_STRING;
|
|
||||||
rc = zmq_getsockopt (socket, ZMQ_LAST_ENDPOINT, tdata.endpoint, &len);
|
|
||||||
assert (rc == 0);
|
|
||||||
|
|
||||||
for (i = 0; i != THREAD_COUNT; i++) {
|
for (int i = 0; i != THREAD_COUNT; i++) {
|
||||||
threads[i] = zmq_threadstart (&worker, &tdata);
|
threads[i] = zmq_threadstart (&worker, &tdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i != THREAD_COUNT; i++) {
|
for (int i = 0; i != THREAD_COUNT; i++) {
|
||||||
zmq_threadclose (threads[i]);
|
zmq_threadclose (threads[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = zmq_close (socket);
|
test_context_socket_close (socket);
|
||||||
assert (rc == 0);
|
|
||||||
|
|
||||||
rc = zmq_ctx_term (tdata.ctx);
|
teardown_test_context ();
|
||||||
assert (rc == 0);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return 0;
|
|
||||||
|
int main ()
|
||||||
|
{
|
||||||
|
setup_test_environment ();
|
||||||
|
|
||||||
|
UNITY_BEGIN ();
|
||||||
|
RUN_TEST (test_shutdown_stress);
|
||||||
|
return UNITY_END ();
|
||||||
}
|
}
|
||||||
|
@ -28,71 +28,71 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "testutil.hpp"
|
#include "testutil.hpp"
|
||||||
|
#include "testutil_unity.hpp"
|
||||||
|
|
||||||
|
void setUp ()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void tearDown ()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
#define THREAD_COUNT 100
|
#define THREAD_COUNT 100
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
static void *worker (void *s_)
|
static void *worker (void *s_)
|
||||||
{
|
{
|
||||||
int rc;
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (s_, "tipc://{5560,0}@0.0.0"));
|
||||||
|
|
||||||
rc = zmq_connect (s_, "tipc://{5560,0}@0.0.0");
|
|
||||||
assert (rc == 0);
|
|
||||||
|
|
||||||
// Start closing the socket while the connecting process is underway.
|
// Start closing the socket while the connecting process is underway.
|
||||||
rc = zmq_close (s_);
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_close (s_));
|
||||||
assert (rc == 0);
|
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main (void)
|
void test_shutdown_stress_tipc ()
|
||||||
|
{
|
||||||
|
void *s1;
|
||||||
|
void *s2;
|
||||||
|
int i;
|
||||||
|
int j;
|
||||||
|
pthread_t threads[THREAD_COUNT];
|
||||||
|
|
||||||
|
for (j = 0; j != 10; j++) {
|
||||||
|
// Check the shutdown with many parallel I/O threads.
|
||||||
|
setup_test_context ();
|
||||||
|
zmq_ctx_set (get_test_context (), ZMQ_IO_THREADS, 7);
|
||||||
|
|
||||||
|
s1 = test_context_socket (ZMQ_PUB);
|
||||||
|
|
||||||
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (s1, "tipc://{5560,0,0}"));
|
||||||
|
|
||||||
|
for (i = 0; i != THREAD_COUNT; i++) {
|
||||||
|
s2 = zmq_socket (get_test_context (), ZMQ_SUB);
|
||||||
|
TEST_ASSERT_SUCCESS_RAW_ERRNO (
|
||||||
|
pthread_create (&threads[i], NULL, worker, s2));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i != THREAD_COUNT; i++) {
|
||||||
|
TEST_ASSERT_SUCCESS_RAW_ERRNO (pthread_join (threads[i], NULL));
|
||||||
|
}
|
||||||
|
|
||||||
|
test_context_socket_close (s1);
|
||||||
|
|
||||||
|
teardown_test_context ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main ()
|
||||||
{
|
{
|
||||||
if (!is_tipc_available ()) {
|
if (!is_tipc_available ()) {
|
||||||
printf ("TIPC environment unavailable, skipping test\n");
|
printf ("TIPC environment unavailable, skipping test\n");
|
||||||
return 77;
|
return 77;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *ctx;
|
UNITY_BEGIN ();
|
||||||
void *s1;
|
RUN_TEST (test_shutdown_stress_tipc);
|
||||||
void *s2;
|
return UNITY_END ();
|
||||||
int i;
|
|
||||||
int j;
|
|
||||||
int rc;
|
|
||||||
pthread_t threads[THREAD_COUNT];
|
|
||||||
|
|
||||||
fprintf (stderr, "test_shutdown_stress_tipc running...\n");
|
|
||||||
|
|
||||||
for (j = 0; j != 10; j++) {
|
|
||||||
// Check the shutdown with many parallel I/O threads.
|
|
||||||
ctx = zmq_init (7);
|
|
||||||
assert (ctx);
|
|
||||||
|
|
||||||
s1 = zmq_socket (ctx, ZMQ_PUB);
|
|
||||||
assert (s1);
|
|
||||||
|
|
||||||
rc = zmq_bind (s1, "tipc://{5560,0,0}");
|
|
||||||
assert (rc == 0);
|
|
||||||
|
|
||||||
for (i = 0; i != THREAD_COUNT; i++) {
|
|
||||||
s2 = zmq_socket (ctx, ZMQ_SUB);
|
|
||||||
assert (s2);
|
|
||||||
rc = pthread_create (&threads[i], NULL, worker, s2);
|
|
||||||
assert (rc == 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i != THREAD_COUNT; i++) {
|
|
||||||
rc = pthread_join (threads[i], NULL);
|
|
||||||
assert (rc == 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
rc = zmq_close (s1);
|
|
||||||
assert (rc == 0);
|
|
||||||
|
|
||||||
rc = zmq_ctx_term (ctx);
|
|
||||||
assert (rc == 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,15 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "testutil.hpp"
|
#include "testutil.hpp"
|
||||||
|
#include "testutil_unity.hpp"
|
||||||
|
|
||||||
|
void setUp ()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void tearDown ()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
// There is no way to test for correctness because of the embedded RNG.
|
// There is no way to test for correctness because of the embedded RNG.
|
||||||
void test__zmq_curve_keypair__always__success (void)
|
void test__zmq_curve_keypair__always__success (void)
|
||||||
@ -39,10 +48,9 @@ void test__zmq_curve_keypair__always__success (void)
|
|||||||
const int rc = zmq_curve_keypair (public_key, secret_key);
|
const int rc = zmq_curve_keypair (public_key, secret_key);
|
||||||
|
|
||||||
#if defined(ZMQ_HAVE_CURVE)
|
#if defined(ZMQ_HAVE_CURVE)
|
||||||
assert (rc == 0);
|
TEST_ASSERT_SUCCESS_ERRNO (rc);
|
||||||
#else
|
#else
|
||||||
assert (rc == -1);
|
TEST_ASSERT_FAILURE_ERRNO (ENOTSUP, rc);
|
||||||
assert (zmq_errno () == ENOTSUP);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,12 +66,10 @@ void test__zmq_curve_public__valid__success ()
|
|||||||
const int rc = zmq_curve_public (out_public, secret_key);
|
const int rc = zmq_curve_public (out_public, secret_key);
|
||||||
|
|
||||||
#if defined(ZMQ_HAVE_CURVE)
|
#if defined(ZMQ_HAVE_CURVE)
|
||||||
assert (rc == 0);
|
TEST_ASSERT_SUCCESS_ERRNO (rc);
|
||||||
assert (zmq_errno () == 0);
|
TEST_ASSERT_EQUAL_STRING (public_key, out_public);
|
||||||
assert (streq (out_public, public_key));
|
|
||||||
#else
|
#else
|
||||||
assert (rc == -1);
|
TEST_ASSERT_FAILURE_ERRNO (ENOTSUP, rc);
|
||||||
assert (zmq_errno () == ENOTSUP);
|
|
||||||
(void) public_key;
|
(void) public_key;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -77,23 +83,32 @@ void test__zmq_curve_public__invalid__failure (const char *secret_)
|
|||||||
const int rc = zmq_curve_public (out_public, secret_);
|
const int rc = zmq_curve_public (out_public, secret_);
|
||||||
|
|
||||||
#if defined(ZMQ_HAVE_CURVE)
|
#if defined(ZMQ_HAVE_CURVE)
|
||||||
assert (rc == -1);
|
TEST_ASSERT_FAILURE_ERRNO (EINVAL, rc);
|
||||||
assert (zmq_errno () == EINVAL);
|
TEST_ASSERT_EQUAL_STRING ("", out_public);
|
||||||
assert (streq (out_public, ""));
|
|
||||||
#else
|
#else
|
||||||
assert (rc == -1);
|
TEST_ASSERT_FAILURE_ERRNO (ENOTSUP, rc);
|
||||||
assert (zmq_errno () == ENOTSUP);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int main (void)
|
void test__zmq_curve_public__invalid__failure_short ()
|
||||||
{
|
{
|
||||||
test__zmq_curve_keypair__always__success ();
|
|
||||||
|
|
||||||
test__zmq_curve_public__valid__success ();
|
|
||||||
test__zmq_curve_public__invalid__failure ("42");
|
test__zmq_curve_public__invalid__failure ("42");
|
||||||
|
}
|
||||||
|
|
||||||
|
void test__zmq_curve_public__invalid__failure_long ()
|
||||||
|
{
|
||||||
test__zmq_curve_public__invalid__failure (
|
test__zmq_curve_public__invalid__failure (
|
||||||
"0123456789012345678901234567890123456789.");
|
"0123456789012345678901234567890123456789.");
|
||||||
|
}
|
||||||
return 0;
|
|
||||||
|
int main ()
|
||||||
|
{
|
||||||
|
UNITY_BEGIN ();
|
||||||
|
RUN_TEST (test__zmq_curve_keypair__always__success);
|
||||||
|
|
||||||
|
RUN_TEST (test__zmq_curve_public__valid__success);
|
||||||
|
RUN_TEST (test__zmq_curve_public__invalid__failure_short);
|
||||||
|
RUN_TEST (test__zmq_curve_public__invalid__failure_long);
|
||||||
|
|
||||||
|
return UNITY_END ();
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,19 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "testutil.hpp"
|
#include "testutil.hpp"
|
||||||
|
#include "testutil_unity.hpp"
|
||||||
|
|
||||||
|
#include <unity.h>
|
||||||
|
|
||||||
|
void setUp ()
|
||||||
|
{
|
||||||
|
setup_test_context ();
|
||||||
|
}
|
||||||
|
|
||||||
|
void tearDown ()
|
||||||
|
{
|
||||||
|
teardown_test_context ();
|
||||||
|
}
|
||||||
|
|
||||||
#define MSG_SIZE 20
|
#define MSG_SIZE 20
|
||||||
|
|
||||||
@ -40,48 +53,34 @@
|
|||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int main (void)
|
void test_srcfd ()
|
||||||
{
|
{
|
||||||
int rc;
|
|
||||||
size_t len = MAX_SOCKET_STRING;
|
|
||||||
char my_endpoint[MAX_SOCKET_STRING];
|
char my_endpoint[MAX_SOCKET_STRING];
|
||||||
|
|
||||||
setup_test_environment ();
|
|
||||||
// Create the infrastructure
|
// Create the infrastructure
|
||||||
void *ctx = zmq_ctx_new ();
|
|
||||||
assert (ctx);
|
|
||||||
|
|
||||||
void *rep = zmq_socket (ctx, ZMQ_REP);
|
void *rep = test_context_socket (ZMQ_REP);
|
||||||
assert (rep);
|
void *req = test_context_socket (ZMQ_REQ);
|
||||||
void *req = zmq_socket (ctx, ZMQ_REQ);
|
|
||||||
assert (req);
|
|
||||||
|
|
||||||
rc = zmq_bind (rep, "tcp://127.0.0.1:*");
|
bind_loopback_ipv4 (rep, my_endpoint, sizeof (my_endpoint));
|
||||||
assert (rc == 0);
|
|
||||||
|
|
||||||
rc = zmq_getsockopt (rep, ZMQ_LAST_ENDPOINT, my_endpoint, &len);
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (req, my_endpoint));
|
||||||
assert (rc == 0);
|
|
||||||
|
|
||||||
rc = zmq_connect (req, my_endpoint);
|
|
||||||
assert (rc == 0);
|
|
||||||
|
|
||||||
char tmp[MSG_SIZE];
|
char tmp[MSG_SIZE];
|
||||||
memset (tmp, 0, MSG_SIZE);
|
memset (tmp, 0, MSG_SIZE);
|
||||||
zmq_send (req, tmp, MSG_SIZE, 0);
|
zmq_send (req, tmp, MSG_SIZE, 0);
|
||||||
|
|
||||||
zmq_msg_t msg;
|
zmq_msg_t msg;
|
||||||
rc = zmq_msg_init (&msg);
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_init (&msg));
|
||||||
assert (rc == 0);
|
|
||||||
|
|
||||||
zmq_recvmsg (rep, &msg, 0);
|
zmq_recvmsg (rep, &msg, 0);
|
||||||
assert (zmq_msg_size (&msg) == MSG_SIZE);
|
TEST_ASSERT_EQUAL_UINT (MSG_SIZE, zmq_msg_size (&msg));
|
||||||
|
|
||||||
// get the messages source file descriptor
|
// get the messages source file descriptor
|
||||||
int src_fd = zmq_msg_get (&msg, ZMQ_SRCFD);
|
int src_fd = zmq_msg_get (&msg, ZMQ_SRCFD);
|
||||||
assert (src_fd >= 0);
|
TEST_ASSERT_GREATER_OR_EQUAL (0, src_fd);
|
||||||
|
|
||||||
rc = zmq_msg_close (&msg);
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_close (&msg));
|
||||||
assert (rc == 0);
|
|
||||||
|
|
||||||
// get the remote endpoint
|
// get the remote endpoint
|
||||||
struct sockaddr_storage ss;
|
struct sockaddr_storage ss;
|
||||||
@ -90,37 +89,38 @@ int main (void)
|
|||||||
#else
|
#else
|
||||||
socklen_t addrlen = sizeof ss;
|
socklen_t addrlen = sizeof ss;
|
||||||
#endif
|
#endif
|
||||||
rc = getpeername (src_fd, (struct sockaddr *) &ss, &addrlen);
|
TEST_ASSERT_SUCCESS_RAW_ERRNO (
|
||||||
assert (rc == 0);
|
getpeername (src_fd, (struct sockaddr *) &ss, &addrlen));
|
||||||
|
|
||||||
char host[NI_MAXHOST];
|
char host[NI_MAXHOST];
|
||||||
rc = getnameinfo ((struct sockaddr *) &ss, addrlen, host, sizeof host, NULL,
|
TEST_ASSERT_SUCCESS_RAW_ERRNO (getnameinfo ((struct sockaddr *) &ss,
|
||||||
0, NI_NUMERICHOST);
|
addrlen, host, sizeof host,
|
||||||
assert (rc == 0);
|
NULL, 0, NI_NUMERICHOST));
|
||||||
|
|
||||||
// assert it is localhost which connected
|
// assert it is localhost which connected
|
||||||
assert (strcmp (host, "127.0.0.1") == 0);
|
TEST_ASSERT_EQUAL_STRING ("127.0.0.1", host);
|
||||||
|
|
||||||
rc = zmq_close (rep);
|
test_context_socket_close (rep);
|
||||||
assert (rc == 0);
|
test_context_socket_close (req);
|
||||||
rc = zmq_close (req);
|
|
||||||
assert (rc == 0);
|
|
||||||
|
|
||||||
// sleep a bit for the socket to be freed
|
// sleep a bit for the socket to be freed
|
||||||
msleep (SETTLE_TIME);
|
msleep (SETTLE_TIME);
|
||||||
|
|
||||||
// getting name from closed socket will fail
|
// getting name from closed socket will fail
|
||||||
rc = getpeername (src_fd, (struct sockaddr *) &ss, &addrlen);
|
|
||||||
#ifdef ZMQ_HAVE_WINDOWS
|
#ifdef ZMQ_HAVE_WINDOWS
|
||||||
assert (rc == SOCKET_ERROR);
|
const int expected_errno = WSAENOTSOCK;
|
||||||
assert (WSAGetLastError () == WSAENOTSOCK);
|
|
||||||
#else
|
#else
|
||||||
assert (rc == -1);
|
const int expected_errno = EBADF;
|
||||||
assert (errno == EBADF);
|
|
||||||
#endif
|
#endif
|
||||||
|
TEST_ASSERT_FAILURE_RAW_ERRNO (
|
||||||
rc = zmq_ctx_term (ctx);
|
expected_errno, getpeername (src_fd, (struct sockaddr *) &ss, &addrlen));
|
||||||
assert (rc == 0);
|
}
|
||||||
|
|
||||||
return 0;
|
int main ()
|
||||||
|
{
|
||||||
|
setup_test_environment ();
|
||||||
|
|
||||||
|
UNITY_BEGIN ();
|
||||||
|
RUN_TEST (test_srcfd);
|
||||||
|
return UNITY_END ();
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,17 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "testutil.hpp"
|
#include "testutil.hpp"
|
||||||
|
#include "testutil_unity.hpp"
|
||||||
|
|
||||||
|
void setUp ()
|
||||||
|
{
|
||||||
|
setup_test_context ();
|
||||||
|
}
|
||||||
|
|
||||||
|
void tearDown ()
|
||||||
|
{
|
||||||
|
teardown_test_context ();
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(ZMQ_HAVE_WINDOWS)
|
#if defined(ZMQ_HAVE_WINDOWS)
|
||||||
#include <winsock2.h>
|
#include <winsock2.h>
|
||||||
@ -36,19 +47,19 @@
|
|||||||
#define close closesocket
|
#define close closesocket
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int main ()
|
void test_stream_exceeds_buffer ()
|
||||||
{
|
{
|
||||||
const int msgsize = 8193;
|
const int msgsize = 8193;
|
||||||
char sndbuf[msgsize] = "\xde\xad\xbe\xef";
|
char sndbuf[msgsize] = "\xde\xad\xbe\xef";
|
||||||
unsigned char rcvbuf[msgsize];
|
unsigned char rcvbuf[msgsize];
|
||||||
char my_endpoint[MAX_SOCKET_STRING];
|
char my_endpoint[MAX_SOCKET_STRING];
|
||||||
|
|
||||||
int server_sock = socket (AF_INET, SOCK_STREAM, 0);
|
int server_sock =
|
||||||
assert (server_sock != -1);
|
TEST_ASSERT_SUCCESS_RAW_ERRNO (socket (AF_INET, SOCK_STREAM, 0));
|
||||||
int enable = 1;
|
int enable = 1;
|
||||||
int rc = setsockopt (server_sock, SOL_SOCKET, SO_REUSEADDR,
|
TEST_ASSERT_SUCCESS_RAW_ERRNO (setsockopt (server_sock, SOL_SOCKET,
|
||||||
(char *) &enable, sizeof (enable));
|
SO_REUSEADDR, (char *) &enable,
|
||||||
assert (rc != -1);
|
sizeof (enable)));
|
||||||
|
|
||||||
struct sockaddr_in saddr;
|
struct sockaddr_in saddr;
|
||||||
memset (&saddr, 0, sizeof (saddr));
|
memset (&saddr, 0, sizeof (saddr));
|
||||||
@ -60,33 +71,26 @@ int main ()
|
|||||||
saddr.sin_port = htons (12345);
|
saddr.sin_port = htons (12345);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
rc = bind (server_sock, (struct sockaddr *) &saddr, sizeof (saddr));
|
TEST_ASSERT_SUCCESS_RAW_ERRNO (
|
||||||
assert (rc != -1);
|
bind (server_sock, (struct sockaddr *) &saddr, sizeof (saddr)));
|
||||||
rc = listen (server_sock, 1);
|
TEST_ASSERT_SUCCESS_RAW_ERRNO (listen (server_sock, 1));
|
||||||
assert (rc != -1);
|
|
||||||
|
|
||||||
#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 (server_sock, (struct sockaddr *) &saddr, &saddr_len);
|
TEST_ASSERT_SUCCESS_RAW_ERRNO (
|
||||||
assert (rc != -1);
|
getsockname (server_sock, (struct sockaddr *) &saddr, &saddr_len));
|
||||||
#endif
|
#endif
|
||||||
sprintf (my_endpoint, "tcp://127.0.0.1:%d", ntohs (saddr.sin_port));
|
sprintf (my_endpoint, "tcp://127.0.0.1:%d", ntohs (saddr.sin_port));
|
||||||
|
|
||||||
void *zctx = zmq_ctx_new ();
|
void *zsock = test_context_socket (ZMQ_STREAM);
|
||||||
assert (zctx);
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (zsock, my_endpoint));
|
||||||
void *zsock = zmq_socket (zctx, ZMQ_STREAM);
|
|
||||||
assert (zsock);
|
|
||||||
rc = zmq_connect (zsock, my_endpoint);
|
|
||||||
assert (rc != -1);
|
|
||||||
|
|
||||||
int client_sock = accept (server_sock, NULL, NULL);
|
int client_sock =
|
||||||
assert (client_sock != -1);
|
TEST_ASSERT_SUCCESS_RAW_ERRNO (accept (server_sock, NULL, NULL));
|
||||||
|
|
||||||
rc = close (server_sock);
|
TEST_ASSERT_SUCCESS_RAW_ERRNO (close (server_sock));
|
||||||
assert (rc != -1);
|
|
||||||
|
|
||||||
rc = send (client_sock, sndbuf, msgsize, 0);
|
TEST_ASSERT_EQUAL_INT (msgsize, send (client_sock, sndbuf, msgsize, 0));
|
||||||
assert (rc == msgsize);
|
|
||||||
|
|
||||||
zmq_msg_t msg;
|
zmq_msg_t msg;
|
||||||
zmq_msg_init (&msg);
|
zmq_msg_init (&msg);
|
||||||
@ -94,12 +98,10 @@ int main ()
|
|||||||
int rcvbytes = 0;
|
int rcvbytes = 0;
|
||||||
while (rcvbytes == 0) // skip connection notification, if any
|
while (rcvbytes == 0) // skip connection notification, if any
|
||||||
{
|
{
|
||||||
rc = zmq_msg_recv (&msg, zsock, 0); // peerid
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_recv (&msg, zsock, 0)); // peerid
|
||||||
assert (rc != -1);
|
TEST_ASSERT_TRUE (zmq_msg_more (&msg));
|
||||||
assert (zmq_msg_more (&msg));
|
rcvbytes = TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_recv (&msg, zsock, 0));
|
||||||
rcvbytes = zmq_msg_recv (&msg, zsock, 0);
|
TEST_ASSERT_FALSE (zmq_msg_more (&msg));
|
||||||
assert (rcvbytes != -1);
|
|
||||||
assert (!zmq_msg_more (&msg));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// for this test, we only collect the first chunk
|
// for this test, we only collect the first chunk
|
||||||
@ -107,18 +109,21 @@ int main ()
|
|||||||
memcpy (rcvbuf, zmq_msg_data (&msg), zmq_msg_size (&msg));
|
memcpy (rcvbuf, zmq_msg_data (&msg), zmq_msg_size (&msg));
|
||||||
|
|
||||||
zmq_msg_close (&msg);
|
zmq_msg_close (&msg);
|
||||||
zmq_close (zsock);
|
test_context_socket_close (zsock);
|
||||||
close (client_sock);
|
close (client_sock);
|
||||||
|
|
||||||
zmq_ctx_destroy (zctx);
|
TEST_ASSERT_GREATER_OR_EQUAL (4, rcvbytes);
|
||||||
|
|
||||||
assert (rcvbytes >= 4);
|
|
||||||
|
|
||||||
// notice that only the 1st byte gets corrupted
|
// notice that only the 1st byte gets corrupted
|
||||||
assert (rcvbuf[3] == 0xef);
|
TEST_ASSERT_EQUAL_UINT (0xef, rcvbuf[3]);
|
||||||
assert (rcvbuf[2] == 0xbe);
|
TEST_ASSERT_EQUAL_UINT (0xbe, rcvbuf[2]);
|
||||||
assert (rcvbuf[1] == 0xad);
|
TEST_ASSERT_EQUAL_UINT (0xad, rcvbuf[1]);
|
||||||
assert (rcvbuf[0] == 0xde);
|
TEST_ASSERT_EQUAL_UINT (0xde, rcvbuf[0]);
|
||||||
|
}
|
||||||
(void) (rc); // avoid -Wunused-but-set-variable warning in release build
|
|
||||||
|
int main ()
|
||||||
|
{
|
||||||
|
UNITY_BEGIN ();
|
||||||
|
RUN_TEST (test_stream_exceeds_buffer);
|
||||||
|
return UNITY_END ();
|
||||||
}
|
}
|
||||||
|
@ -79,6 +79,40 @@ int test_assert_success_message_raw_errno_helper (int rc_,
|
|||||||
return rc_;
|
return rc_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int test_assert_failure_message_raw_errno_helper (int rc_,
|
||||||
|
int expected_errno_,
|
||||||
|
const char *msg_,
|
||||||
|
const char *expr_)
|
||||||
|
{
|
||||||
|
char buffer[512];
|
||||||
|
buffer[sizeof (buffer) - 1] =
|
||||||
|
0; // to ensure defined behavior with VC++ <= 2013
|
||||||
|
if (rc_ != -1) {
|
||||||
|
snprintf (buffer, sizeof (buffer) - 1,
|
||||||
|
"%s was unexpectedly successful%s%s%s, expected "
|
||||||
|
"errno = %i, actual return value = %i",
|
||||||
|
expr_, msg_ ? " (additional info: " : "", msg_ ? msg_ : "",
|
||||||
|
msg_ ? ")" : "", expected_errno_, rc_);
|
||||||
|
TEST_FAIL_MESSAGE (buffer);
|
||||||
|
} else {
|
||||||
|
#if defined ZMQ_HAVE_WINDOWS
|
||||||
|
int current_errno = WSAGetLastError ();
|
||||||
|
#else
|
||||||
|
int current_errno = errno;
|
||||||
|
#endif
|
||||||
|
if (current_errno != expected_errno_) {
|
||||||
|
snprintf (buffer, sizeof (buffer) - 1,
|
||||||
|
"%s failed with an unexpected error%s%s%s, expected "
|
||||||
|
"errno = %i, actual errno = %i",
|
||||||
|
expr_, msg_ ? " (additional info: " : "",
|
||||||
|
msg_ ? msg_ : "", msg_ ? ")" : "", expected_errno_,
|
||||||
|
current_errno);
|
||||||
|
TEST_FAIL_MESSAGE (buffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return rc_;
|
||||||
|
}
|
||||||
|
|
||||||
#define TEST_ASSERT_SUCCESS_MESSAGE_ERRNO(expr, msg) \
|
#define TEST_ASSERT_SUCCESS_MESSAGE_ERRNO(expr, msg) \
|
||||||
test_assert_success_message_errno_helper (expr, msg, #expr)
|
test_assert_success_message_errno_helper (expr, msg, #expr)
|
||||||
|
|
||||||
@ -88,6 +122,9 @@ int test_assert_success_message_raw_errno_helper (int rc_,
|
|||||||
#define TEST_ASSERT_SUCCESS_RAW_ERRNO(expr) \
|
#define TEST_ASSERT_SUCCESS_RAW_ERRNO(expr) \
|
||||||
test_assert_success_message_raw_errno_helper (expr, NULL, #expr)
|
test_assert_success_message_raw_errno_helper (expr, NULL, #expr)
|
||||||
|
|
||||||
|
#define TEST_ASSERT_FAILURE_RAW_ERRNO(error_code, expr) \
|
||||||
|
test_assert_failure_message_raw_errno_helper (expr, error_code, NULL, #expr)
|
||||||
|
|
||||||
#define TEST_ASSERT_FAILURE_ERRNO(error_code, expr) \
|
#define TEST_ASSERT_FAILURE_ERRNO(error_code, expr) \
|
||||||
{ \
|
{ \
|
||||||
int _rc = (expr); \
|
int _rc = (expr); \
|
||||||
|
Loading…
x
Reference in New Issue
Block a user