Unverified Commit 12005bd9 authored by Luca Boccassi's avatar Luca Boccassi Committed by GitHub

Merge pull request #3228 from sigiesec/migrate-tests-to-unity

Migrate further tests to unity
parents 9f0b83a1 1a55100d
......@@ -455,7 +455,8 @@ external_unity_libunity_a_SOURCES = external/unity/unity.c \
external/unity/unity_internals.h
tests_test_ancillaries_SOURCES = tests/test_ancillaries.cpp
tests_test_ancillaries_LDADD = src/libzmq.la
tests_test_ancillaries_LDADD = src/libzmq.la ${UNITY_LIBS}
tests_test_ancillaries_CPPFLAGS = ${UNITY_CPPFLAGS}
tests_test_system_SOURCES = tests/test_system.cpp
tests_test_system_LDADD = src/libzmq.la
......@@ -468,7 +469,8 @@ tests_test_pair_inproc_LDADD = src/libzmq.la
tests_test_pair_tcp_SOURCES = \
tests/test_pair_tcp.cpp \
tests/testutil.hpp
tests_test_pair_tcp_LDADD = src/libzmq.la
tests_test_pair_tcp_LDADD = src/libzmq.la ${UNITY_LIBS}
tests_test_pair_tcp_CPPFLAGS = ${UNITY_CPPFLAGS}
tests_test_reqrep_inproc_SOURCES = \
tests/test_reqrep_inproc.cpp \
......@@ -542,10 +544,12 @@ tests_test_probe_router_LDADD = src/libzmq.la ${UNITY_LIBS}
tests_test_probe_router_CPPFLAGS = ${UNITY_CPPFLAGS}
tests_test_stream_SOURCES = tests/test_stream.cpp
tests_test_stream_LDADD = src/libzmq.la
tests_test_stream_LDADD = src/libzmq.la ${UNITY_LIBS}
tests_test_stream_CPPFLAGS = ${UNITY_CPPFLAGS}
tests_test_stream_empty_SOURCES = tests/test_stream_empty.cpp
tests_test_stream_empty_LDADD = src/libzmq.la
tests_test_stream_empty_LDADD = src/libzmq.la ${UNITY_LIBS}
tests_test_stream_empty_CPPFLAGS = ${UNITY_CPPFLAGS}
tests_test_stream_timeout_SOURCES = tests/test_stream_timeout.cpp
tests_test_stream_timeout_LDADD = src/libzmq.la
......@@ -557,7 +561,8 @@ tests_test_disconnect_inproc_SOURCES = tests/test_disconnect_inproc.cpp
tests_test_disconnect_inproc_LDADD = src/libzmq.la
tests_test_unbind_wildcard_SOURCES = tests/test_unbind_wildcard.cpp
tests_test_unbind_wildcard_LDADD = src/libzmq.la
tests_test_unbind_wildcard_LDADD = src/libzmq.la ${UNITY_LIBS}
tests_test_unbind_wildcard_CPPFLAGS = ${UNITY_CPPFLAGS}
tests_test_ctx_options_SOURCES = tests/test_ctx_options.cpp
tests_test_ctx_options_LDADD = src/libzmq.la
......@@ -596,10 +601,12 @@ tests_test_spec_router_LDADD = src/libzmq.la ${UNITY_LIBS}
tests_test_spec_router_CPPFLAGS = ${UNITY_CPPFLAGS}
tests_test_spec_pushpull_SOURCES = tests/test_spec_pushpull.cpp
tests_test_spec_pushpull_LDADD = src/libzmq.la
tests_test_spec_pushpull_LDADD = src/libzmq.la ${UNITY_LIBS}
tests_test_spec_pushpull_CPPFLAGS = ${UNITY_CPPFLAGS}
tests_test_req_correlate_SOURCES = tests/test_req_correlate.cpp
tests_test_req_correlate_LDADD = src/libzmq.la
tests_test_req_correlate_LDADD = src/libzmq.la ${UNITY_LIBS}
tests_test_req_correlate_CPPFLAGS = ${UNITY_CPPFLAGS}
tests_test_req_relaxed_SOURCES = tests/test_req_relaxed.cpp
tests_test_req_relaxed_LDADD = src/libzmq.la
......@@ -645,14 +652,16 @@ tests_test_metadata_SOURCES = tests/test_metadata.cpp
tests_test_metadata_LDADD = src/libzmq.la
tests_test_capabilities_SOURCES = tests/test_capabilities.cpp
tests_test_capabilities_LDADD = src/libzmq.la
tests_test_capabilities_LDADD = src/libzmq.la ${UNITY_LIBS}
tests_test_capabilities_CPPFLAGS = ${UNITY_CPPFLAGS}
tests_test_xpub_nodrop_SOURCES = tests/test_xpub_nodrop.cpp
tests_test_xpub_nodrop_LDADD = src/libzmq.la ${UNITY_LIBS}
tests_test_xpub_nodrop_CPPFLAGS = ${UNITY_CPPFLAGS}
tests_test_xpub_manual_SOURCES = tests/test_xpub_manual.cpp
tests_test_xpub_manual_LDADD = src/libzmq.la
tests_test_xpub_manual_LDADD = src/libzmq.la ${UNITY_LIBS}
tests_test_xpub_manual_CPPFLAGS = ${UNITY_CPPFLAGS}
tests_test_xpub_welcome_msg_SOURCES = tests/test_xpub_welcome_msg.cpp
tests_test_xpub_welcome_msg_LDADD = src/libzmq.la
......@@ -688,7 +697,8 @@ tests_test_bind_after_connect_tcp_LDADD = src/libzmq.la ${UNITY_LIBS}
tests_test_bind_after_connect_tcp_CPPFLAGS = ${UNITY_CPPFLAGS}
tests_test_base85_SOURCES = tests/test_base85.cpp
tests_test_base85_LDADD = src/libzmq.la
tests_test_base85_LDADD = src/libzmq.la ${UNITY_LIBS}
tests_test_base85_CPPFLAGS = ${UNITY_CPPFLAGS}
tests_test_sodium_SOURCES = tests/test_sodium.cpp
tests_test_sodium_LDADD = src/libzmq.la
......
......@@ -35,16 +35,37 @@
*/
#include "testutil.hpp"
#include "testutil_unity.hpp"
int main (void)
void setUp ()
{
}
void tearDown ()
{
}
void test_version ()
{
int major, minor, patch;
zmq_version (&major, &minor, &patch);
assert (major == ZMQ_VERSION_MAJOR && minor == ZMQ_VERSION_MINOR
&& patch == ZMQ_VERSION_PATCH);
TEST_ASSERT_EQUAL_INT (ZMQ_VERSION_MAJOR, major);
TEST_ASSERT_EQUAL_INT (ZMQ_VERSION_MINOR, minor);
TEST_ASSERT_EQUAL_INT (ZMQ_VERSION_PATCH, patch);
}
void test_strerrror ()
{
assert (zmq_strerror (EINVAL));
}
int main ()
{
setup_test_environment ();
return 0;
UNITY_BEGIN ();
RUN_TEST (test_version);
RUN_TEST (test_strerrror);
return UNITY_END ();
}
......@@ -28,6 +28,15 @@
*/
#include "testutil.hpp"
#include "testutil_unity.hpp"
void setUp ()
{
}
void tearDown ()
{
}
// Test vector: rfc.zeromq.org/spec:32/Z85
void test__zmq_z85_encode__valid__success ()
......@@ -40,17 +49,17 @@ void test__zmq_z85_encode__valid__success ()
char out_encoded[length + 1] = {0};
errno = 0;
assert (zmq_z85_encode (out_encoded, decoded, size) != NULL);
assert (streq (out_encoded, expected));
assert (zmq_errno () == 0);
TEST_ASSERT_NOT_NULL (zmq_z85_encode (out_encoded, decoded, size));
TEST_ASSERT_EQUAL_STRING (expected, out_encoded);
TEST_ASSERT_EQUAL_INT (0, zmq_errno ());
}
// Buffer length must be evenly divisible by 4 or must fail with EINVAL.
void test__zmq_z85_encode__invalid__failure (size_t size_)
{
errno = 0;
assert (zmq_z85_encode (NULL, NULL, size_) == NULL);
assert (zmq_errno () == EINVAL);
TEST_ASSERT_NULL (zmq_z85_encode (NULL, NULL, size_));
TEST_ASSERT_EQUAL_INT (EINVAL, zmq_errno ());
}
// Test vector: rfc.zeromq.org/spec:32/Z85
......@@ -63,9 +72,9 @@ void test__zmq_z85_decode__valid__success ()
uint8_t out_decoded[size] = {0};
errno = 0;
assert (zmq_z85_decode (out_decoded, encoded) != NULL);
assert (zmq_errno () == 0);
assert (memcmp (out_decoded, expected, size) == 0);
TEST_ASSERT_NOT_NULL (zmq_z85_decode (out_decoded, encoded));
TEST_ASSERT_EQUAL_INT (0, zmq_errno ());
TEST_ASSERT_EQUAL_UINT8_ARRAY (expected, out_decoded, size);
}
// Invalid input data must fail with EINVAL.
......@@ -74,8 +83,8 @@ void test__zmq_z85_decode__invalid__failure (const char (&encoded_)[SIZE])
{
uint8_t decoded[SIZE * 4 / 5 + 1];
errno = 0;
assert (zmq_z85_decode (decoded, encoded_) == NULL);
assert (zmq_errno () == EINVAL);
TEST_ASSERT_NULL (zmq_z85_decode (decoded, encoded_));
TEST_ASSERT_EQUAL_INT (EINVAL, zmq_errno ());
}
......@@ -86,14 +95,13 @@ void test__zmq_z85_encode__zmq_z85_decode__roundtrip (
{
char test_data_z85[SIZE * 5 / 4 + 1];
char *res1 = zmq_z85_encode (test_data_z85, test_data_, SIZE);
assert (res1 != NULL);
TEST_ASSERT_NOT_NULL (res1);
uint8_t test_data_decoded[SIZE];
uint8_t *res2 = zmq_z85_decode (test_data_decoded, test_data_z85);
assert (res2 != NULL);
TEST_ASSERT_NOT_NULL (res2);
int res3 = memcmp (test_data_, test_data_decoded, SIZE);
assert (res3 == 0);
TEST_ASSERT_EQUAL_UINT8_ARRAY (test_data_, test_data_decoded, SIZE);
}
// call zmq_z85_encode, then zmq_z85_decode, and compare the results with the original
......@@ -104,61 +112,92 @@ void test__zmq_z85_decode__zmq_z85_encode__roundtrip (
const size_t decoded_size = (SIZE - 1) * 4 / 5;
uint8_t test_data_decoded[decoded_size];
uint8_t *res1 = zmq_z85_decode (test_data_decoded, test_data_);
assert (res1 != NULL);
TEST_ASSERT_NOT_NULL (res1);
char test_data_z85[SIZE];
char *res2 =
zmq_z85_encode (test_data_z85, test_data_decoded, decoded_size);
assert (res2 != NULL);
TEST_ASSERT_NOT_NULL (res2);
int res3 = memcmp (test_data_, test_data_z85, SIZE);
assert (res3 == 0);
TEST_ASSERT_EQUAL_UINT8_ARRAY (test_data_, test_data_z85, SIZE);
}
int main (void)
{
test__zmq_z85_encode__valid__success ();
test__zmq_z85_encode__invalid__failure (1);
test__zmq_z85_encode__invalid__failure (42);
test__zmq_z85_decode__valid__success ();
// String length must be evenly divisible by 5 or must fail with EINVAL.
test__zmq_z85_decode__invalid__failure ("01234567");
test__zmq_z85_decode__invalid__failure ("0");
// decode invalid data with the maximum representable value
test__zmq_z85_decode__invalid__failure ("#####");
// decode invalid data with the minimum value beyond the limit
// "%nSc0" is 0xffffffff
test__zmq_z85_decode__invalid__failure ("%nSc1");
// decode invalid data with an invalid character in the range of valid
// characters
test__zmq_z85_decode__invalid__failure ("####\0047");
// decode invalid data with an invalid character just below the range of valid
// characters
test__zmq_z85_decode__invalid__failure ("####\0200");
// decode invalid data with an invalid character just above the range of valid
// characters
test__zmq_z85_decode__invalid__failure ("####\0037");
// round-trip encoding and decoding with minimum value
{
const uint8_t test_data[] = {0x00, 0x00, 0x00, 0x00};
test__zmq_z85_encode__zmq_z85_decode__roundtrip (test_data);
}
// round-trip encoding and decoding with maximum value
{
const uint8_t test_data[] = {0xff, 0xff, 0xff, 0xff};
test__zmq_z85_encode__zmq_z85_decode__roundtrip (test_data);
#define def_test__zmq_z85_basename(basename, name, param) \
void test__zmq_z85_##basename##_##name () \
{ \
test__zmq_z85_##basename (param); \
}
test__zmq_z85_decode__zmq_z85_encode__roundtrip (
"r^/rM9M=rMToK)63O8dCvd9D<PY<7iGlC+{BiSnG");
#define def_test__zmq_z85_encode__invalid__failure(name, param) \
def_test__zmq_z85_basename (encode__invalid__failure, name, param)
def_test__zmq_z85_encode__invalid__failure (1, 1)
def_test__zmq_z85_encode__invalid__failure (42, 42)
#define def_test__zmq_z85_decode__invalid__failure(name, param) \
def_test__zmq_z85_basename (decode__invalid__failure, name, param)
// String length must be evenly divisible by 5 or must fail with EINVAL.
def_test__zmq_z85_decode__invalid__failure (indivisble_by_5_multiple_chars,
"01234567")
def_test__zmq_z85_decode__invalid__failure (indivisble_by_5_one_char, "0")
return 0;
// decode invalid data with the maximum representable value
def_test__zmq_z85_decode__invalid__failure (max, "#####")
// decode invalid data with the minimum value beyond the limit
// "%nSc0" is 0xffffffff
def_test__zmq_z85_decode__invalid__failure (above_limit, "%nSc1")
// decode invalid data with an invalid character in the range of valid
// characters
def_test__zmq_z85_decode__invalid__failure (char_within, "####\0047")
// decode invalid data with an invalid character just below the range of valid
// characters
def_test__zmq_z85_decode__invalid__failure (char_adjacent_below, "####\0200")
// decode invalid data with an invalid character just above the range of valid
// characters
def_test__zmq_z85_decode__invalid__failure (char_adjacent_above, "####\0037")
#define def_test__encode__zmq_z85_decode__roundtrip(name, param) \
def_test__zmq_z85_basename (encode__zmq_z85_decode__roundtrip, name, param)
const uint8_t test_data_min[] = {0x00, 0x00, 0x00, 0x00};
const uint8_t test_data_max[] = {0xff, 0xff, 0xff, 0xff};
def_test__encode__zmq_z85_decode__roundtrip (min, test_data_min)
def_test__encode__zmq_z85_decode__roundtrip (max, test_data_max)
#define def_test__decode__zmq_z85_encode__roundtrip(name, param) \
def_test__zmq_z85_basename (decode__zmq_z85_encode__roundtrip, name, param)
const char test_data_regular[] = "r^/rM9M=rMToK)63O8dCvd9D<PY<7iGlC+{BiSnG";
def_test__decode__zmq_z85_encode__roundtrip (regular, test_data_regular)
int main ()
{
UNITY_BEGIN ();
RUN_TEST (test__zmq_z85_encode__valid__success);
RUN_TEST (test__zmq_z85_encode__invalid__failure_1);
RUN_TEST (test__zmq_z85_encode__invalid__failure_42);
RUN_TEST (test__zmq_z85_decode__valid__success);
RUN_TEST (
test__zmq_z85_decode__invalid__failure_indivisble_by_5_multiple_chars);
RUN_TEST (test__zmq_z85_decode__invalid__failure_indivisble_by_5_one_char);
RUN_TEST (test__zmq_z85_decode__invalid__failure_max);
RUN_TEST (test__zmq_z85_decode__invalid__failure_above_limit);
RUN_TEST (test__zmq_z85_decode__invalid__failure_char_within);
RUN_TEST (test__zmq_z85_decode__invalid__failure_char_adjacent_below);
RUN_TEST (test__zmq_z85_decode__invalid__failure_char_adjacent_above);
RUN_TEST (test__zmq_z85_encode__zmq_z85_decode__roundtrip_min);
RUN_TEST (test__zmq_z85_encode__zmq_z85_decode__roundtrip_max);
RUN_TEST (test__zmq_z85_decode__zmq_z85_encode__roundtrip_regular);
return UNITY_END ();
}
......@@ -28,55 +28,72 @@
*/
#include "testutil.hpp"
#include "testutil_unity.hpp"
int main (void)
void setUp ()
{
}
void tearDown ()
{
}
void test_capabilities ()
{
#if !defined(ZMQ_HAVE_WINDOWS) && !defined(ZMQ_HAVE_OPENVMS)
assert (zmq_has ("ipc"));
TEST_ASSERT_TRUE (zmq_has ("ipc"));
#else
assert (!zmq_has ("ipc"));
TEST_ASSERT_TRUE (!zmq_has ("ipc"));
#endif
#if defined(ZMQ_HAVE_OPENPGM)
assert (zmq_has ("pgm"));
TEST_ASSERT_TRUE (zmq_has ("pgm"));
#else
assert (!zmq_has ("pgm"));
TEST_ASSERT_TRUE (!zmq_has ("pgm"));
#endif
#if defined(ZMQ_HAVE_TIPC)
assert (zmq_has ("tipc"));
TEST_ASSERT_TRUE (zmq_has ("tipc"));
#else
assert (!zmq_has ("tipc"));
TEST_ASSERT_TRUE (!zmq_has ("tipc"));
#endif
#if defined(ZMQ_HAVE_NORM)
assert (zmq_has ("norm"));
TEST_ASSERT_TRUE (zmq_has ("norm"));
#else
assert (!zmq_has ("norm"));
TEST_ASSERT_TRUE (!zmq_has ("norm"));
#endif
#if defined(ZMQ_HAVE_CURVE)
assert (zmq_has ("curve"));
TEST_ASSERT_TRUE (zmq_has ("curve"));
#else
assert (!zmq_has ("curve"));
TEST_ASSERT_TRUE (!zmq_has ("curve"));
#endif
#if defined(HAVE_LIBGSSAPI_KRB5)
assert (zmq_has ("gssapi"));
TEST_ASSERT_TRUE (zmq_has ("gssapi"));
#else
assert (!zmq_has ("gssapi"));
TEST_ASSERT_TRUE (!zmq_has ("gssapi"));
#endif
#if defined(ZMQ_HAVE_VMCI)
assert (zmq_has ("vmci"));
TEST_ASSERT_TRUE (zmq_has ("vmci"));
#else
assert (!zmq_has ("vmci"));
TEST_ASSERT_TRUE (!zmq_has ("vmci"));
#endif
#if defined(ZMQ_BUILD_DRAFT_API)
assert (zmq_has ("draft"));
TEST_ASSERT_TRUE (zmq_has ("draft"));
#else
assert (!zmq_has ("draft"));
TEST_ASSERT_TRUE (!zmq_has ("draft"));
#endif
return 0;
}
int main ()
{
setup_test_environment ();
UNITY_BEGIN ();
RUN_TEST (test_capabilities);
return UNITY_END ();
}
......@@ -28,6 +28,18 @@
*/
#include "testutil.hpp"
#include "testutil_unity.hpp"
void setUp ()
{
setup_test_context ();
}
void tearDown ()
{
teardown_test_context ();
}
typedef void (*extra_func_t) (void *socket_);
......@@ -43,50 +55,47 @@ void set_sockopt_fastpath (void *socket)
void test_pair_tcp (extra_func_t extra_func_ = NULL)
{
size_t len = MAX_SOCKET_STRING;
char my_endpoint[MAX_SOCKET_STRING];
void *ctx = zmq_ctx_new ();
assert (ctx);
void *sb = zmq_socket (ctx, ZMQ_PAIR);
assert (sb);
void *sb = test_context_socket (ZMQ_PAIR);
if (extra_func_)
extra_func_ (sb);
int rc = zmq_bind (sb, "tcp://127.0.0.1:*");
assert (rc == 0);
rc = zmq_getsockopt (sb, ZMQ_LAST_ENDPOINT, my_endpoint, &len);
assert (rc == 0);
char my_endpoint[MAX_SOCKET_STRING];
bind_loopback_ipv4 (sb, my_endpoint, sizeof my_endpoint);
void *sc = zmq_socket (ctx, ZMQ_PAIR);
assert (sc);
void *sc = test_context_socket (ZMQ_PAIR);
if (extra_func_)
extra_func_ (sc);
rc = zmq_connect (sc, my_endpoint);
assert (rc == 0);
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sc, my_endpoint));
bounce (sb, sc);
rc = zmq_close (sc);
assert (rc == 0);
test_context_socket_close (sc);
test_context_socket_close (sb);
}
rc = zmq_close (sb);
assert (rc == 0);
void test_pair_tcp_regular ()
{
test_pair_tcp ();
}
rc = zmq_ctx_term (ctx);
assert (rc == 0);
#ifdef ZMQ_BUILD_DRAFT
void test_pair_tcp_fastpath ()
{
test_pair_tcp (set_sockopt_fastpath);
}
#endif
int main (void)
int main ()
{
setup_test_environment ();
test_pair_tcp ();
UNITY_BEGIN ();
RUN_TEST (test_pair_tcp_regular);
#ifdef ZMQ_BUILD_DRAFT
test_pair_tcp (set_sockopt_fastpath);
RUN_TEST (test_pair_tcp_fastpath);
#endif
return 0;
return UNITY_END ();
}
......@@ -28,36 +28,35 @@
*/
#include "testutil.hpp"
#include "testutil_unity.hpp"
int main (void)
void setUp ()
{
setup_test_environment ();
size_t len = MAX_SOCKET_STRING;
char my_endpoint[MAX_SOCKET_STRING];
void *ctx = zmq_ctx_new ();
assert (ctx);
setup_test_context ();
}
void *req = zmq_socket (ctx, ZMQ_REQ);
assert (req);
void tearDown ()
{
teardown_test_context ();
}
void *router = zmq_socket (ctx, ZMQ_ROUTER);
assert (router);
void test_req_correlate ()
{
void *req = test_context_socket (ZMQ_REQ);
void *router = test_context_socket (ZMQ_ROUTER);
int enabled = 1;
int rc = zmq_setsockopt (req, ZMQ_REQ_CORRELATE, &enabled, sizeof (int));
assert (rc == 0);
TEST_ASSERT_SUCCESS_ERRNO (
zmq_setsockopt (req, ZMQ_REQ_CORRELATE, &enabled, sizeof (int)));
int rcvtimeo = 100;
rc = zmq_setsockopt (req, ZMQ_RCVTIMEO, &rcvtimeo, sizeof (int));
assert (rc == 0);
TEST_ASSERT_SUCCESS_ERRNO (
zmq_setsockopt (req, ZMQ_RCVTIMEO, &rcvtimeo, sizeof (int)));
rc = zmq_bind (router, "tcp://127.0.0.1:*");
assert (rc == 0);
rc = zmq_getsockopt (router, ZMQ_LAST_ENDPOINT, my_endpoint, &len);
assert (rc == 0);
char my_endpoint[MAX_SOCKET_STRING];
bind_loopback_ipv4 (router, my_endpoint, sizeof my_endpoint);
rc = zmq_connect (req, my_endpoint);
assert (rc == 0);
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (req, my_endpoint));
// Send a multi-part request.
s_send_seq (req, "ABC", "DEF", SEQ_END);
......@@ -66,33 +65,31 @@ int main (void)
zmq_msg_init (&msg);
// Receive peer routing id
rc = zmq_msg_recv (&msg, router, 0);
assert (rc != -1);
assert (zmq_msg_size (&msg) > 0);
TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_recv (&msg, router, 0));
TEST_ASSERT_GREATER_THAN_INT (0, zmq_msg_size (&msg));
zmq_msg_t peer_id_msg;
zmq_msg_init (&peer_id_msg);
zmq_msg_copy (&peer_id_msg, &msg);
int more = 0;
size_t more_size = sizeof (more);
rc = zmq_getsockopt (router, ZMQ_RCVMORE, &more, &more_size);
assert (rc == 0);
assert (more);
TEST_ASSERT_SUCCESS_ERRNO (
zmq_getsockopt (router, ZMQ_RCVMORE, &more, &more_size));
TEST_ASSERT_TRUE (more);
// Receive request id 1
rc = zmq_msg_recv (&msg, router, 0);
assert (rc != -1);
TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_recv (&msg, router, 0));
assert (zmq_msg_size (&msg) == sizeof (uint32_t));
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_init (&req_id_msg);
zmq_msg_copy (&req_id_msg, &msg);
more = 0;
more_size = sizeof (more);
rc = zmq_getsockopt (router, ZMQ_RCVMORE, &more, &more_size);
assert (rc == 0);
assert (more);
TEST_ASSERT_SUCCESS_ERRNO (
zmq_getsockopt (router, ZMQ_RCVMORE, &more, &more_size));
TEST_ASSERT_TRUE (more);
// Receive the rest.
s_recv_seq (router, 0, "ABC", "DEF", SEQ_END);
......@@ -101,40 +98,35 @@ int main (void)
// Send back a bad reply: wrong req id, 0, data
zmq_msg_copy (&msg, &peer_id_msg);
rc = zmq_msg_send (&msg, router, ZMQ_SNDMORE);
assert (rc != -1);
TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_send (&msg, router, ZMQ_SNDMORE));
zmq_msg_init_data (&msg, &bad_req_id, sizeof (uint32_t), NULL, NULL);
rc = zmq_msg_send (&msg, router, ZMQ_SNDMORE);
assert (rc != -1);
TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_send (&msg, router, ZMQ_SNDMORE));
s_send_seq (router, 0, "DATA", SEQ_END);
// Send back a good reply: good req id, 0, data
zmq_msg_copy (&msg, &peer_id_msg);
rc = zmq_msg_send (&msg, router, ZMQ_SNDMORE);
assert (rc != -1);
TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_send (&msg, router, ZMQ_SNDMORE));
zmq_msg_copy (&msg, &req_id_msg);
rc = zmq_msg_send (&msg, router, ZMQ_SNDMORE);
assert (rc != -1);
TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_send (&msg, router, ZMQ_SNDMORE));
s_send_seq (router, 0, "GHI", SEQ_END);
// Receive reply. If bad reply got through, we wouldn't see
// this particular data.
s_recv_seq (req, "GHI", SEQ_END);
rc = zmq_msg_close (&msg);
assert (rc == 0);
rc = zmq_msg_close (&peer_id_msg);
assert (rc == 0);
rc = zmq_msg_close (&req_id_msg);
assert (rc == 0);
TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_close (&msg));
TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_close (&peer_id_msg));
TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_close (&req_id_msg));
close_zero_linger (req);
close_zero_linger (router);
test_context_socket_close_zero_linger (req);
test_context_socket_close_zero_linger (router);
}
rc = zmq_ctx_term (ctx);
assert (rc == 0);
int main ()
{
setup_test_environment ();
return 0;
UNITY_BEGIN ();
RUN_TEST (test_req_correlate);
return UNITY_END ();
}
This diff is collapsed.
This diff is collapsed.
......@@ -28,48 +28,52 @@
*/
#include "testutil.hpp"
#include "testutil_unity.hpp"
int main (void)
void setUp ()
{
setup_test_context ();
}
void tearDown ()
{
teardown_test_context ();
}
void test_stream_empty ()
{
setup_test_environment ();
size_t len = MAX_SOCKET_STRING;
char my_endpoint[MAX_SOCKET_STRING];
void *ctx = zmq_ctx_new ();
assert (ctx);
void *stream = zmq_socket (ctx, ZMQ_STREAM);
assert (stream);
void *dealer = zmq_socket (ctx, ZMQ_DEALER);
assert (dealer);
int rc = zmq_bind (stream, "tcp://127.0.0.1:*");
assert (rc >= 0);
rc = zmq_getsockopt (stream, ZMQ_LAST_ENDPOINT, my_endpoint, &len);
assert (rc == 0);
rc = zmq_connect (dealer, my_endpoint);
assert (rc >= 0);
zmq_send (dealer, "", 0, 0);
void *stream = test_context_socket (ZMQ_STREAM);
void *dealer = test_context_socket (ZMQ_DEALER);
bind_loopback_ipv4 (stream, my_endpoint, sizeof my_endpoint);
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (dealer, my_endpoint));
send_string_expect_success (dealer, "", 0);
zmq_msg_t ident, empty;
zmq_msg_init (&ident);
rc = zmq_msg_recv (&ident, stream, 0);
assert (rc >= 0);
rc = zmq_msg_init_data (&empty, (void *) "", 0, NULL, NULL);
assert (rc >= 0);
TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_recv (&ident, stream, 0));
TEST_ASSERT_SUCCESS_ERRNO (
zmq_msg_init_data (&empty, (void *) "", 0, NULL, NULL));
rc = zmq_msg_send (&ident, stream, ZMQ_SNDMORE);
assert (rc >= 0);
rc = zmq_msg_close (&ident);
assert (rc >= 0);
TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_send (&ident, stream, ZMQ_SNDMORE));
TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_close (&ident));
rc = zmq_msg_send (&empty, stream, 0);
assert (rc >= 0);
TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_send (&empty, stream, 0));
// This close used to fail with Bad Address
rc = zmq_msg_close (&empty);
assert (rc >= 0);
TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_close (&empty));
test_context_socket_close_zero_linger (dealer);
test_context_socket_close_zero_linger (stream);
}
int main ()
{
setup_test_environment ();
close_zero_linger (dealer);
close_zero_linger (stream);
zmq_ctx_term (ctx);
UNITY_BEGIN ();
RUN_TEST (test_stream_empty);
return UNITY_END ();
}
......@@ -18,28 +18,31 @@
*/
#include "testutil.hpp"
#include "testutil_unity.hpp"
int main (void)
void setUp ()
{
setup_test_environment ();
void *ctx = zmq_ctx_new ();
assert (ctx);
int ipv6 = is_ipv6_available ();
setup_test_context ();
}
void tearDown ()
{
teardown_test_context ();
}
void test_address_wildcard_ipv4 ()
{
/* Address wildcard, IPv6 disabled */
void *sb = zmq_socket (ctx, ZMQ_REP);
assert (sb);
void *sc = zmq_socket (ctx, ZMQ_REQ);
assert (sc);
void *sb = test_context_socket (ZMQ_REP);
void *sc = test_context_socket (ZMQ_REQ);
int rc = zmq_bind (sb, "tcp://*:*");
assert (rc == 0);
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb, "tcp://*:*"));
char bind_endpoint[256];
char connect_endpoint[256];
size_t endpoint_len = sizeof (bind_endpoint);
rc = zmq_getsockopt (sb, ZMQ_LAST_ENDPOINT, bind_endpoint, &endpoint_len);
assert (rc == 0);
TEST_ASSERT_SUCCESS_ERRNO (
zmq_getsockopt (sb, ZMQ_LAST_ENDPOINT, bind_endpoint, &endpoint_len));
// Apparently Windows can't connect to 0.0.0.0. A better fix would be welcome.
#ifdef ZMQ_HAVE_WINDOWS
......@@ -49,39 +52,38 @@ int main (void)
strcpy (connect_endpoint, bind_endpoint);
#endif
rc = zmq_connect (sc, connect_endpoint);
assert (rc == 0);
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sc, connect_endpoint));
bounce (sb, sc);
rc = zmq_disconnect (sc, connect_endpoint);
assert (rc == 0);
rc = zmq_unbind (sb, bind_endpoint);
assert (rc == 0);
TEST_ASSERT_SUCCESS_ERRNO (zmq_disconnect (sc, connect_endpoint));
TEST_ASSERT_SUCCESS_ERRNO (zmq_unbind (sb, bind_endpoint));
rc = zmq_close (sc);
assert (rc == 0);
rc = zmq_close (sb);
assert (rc == 0);
test_context_socket_close (sc);
test_context_socket_close (sb);
}
void test_address_wildcard_ipv6 ()
{
int ipv6 = is_ipv6_available ();
/* Address wildcard, IPv6 enabled */
sb = zmq_socket (ctx, ZMQ_REP);
assert (sb);
sc = zmq_socket (ctx, ZMQ_REQ);
assert (sc);
void *sb = test_context_socket (ZMQ_REP);
void *sc = test_context_socket (ZMQ_REQ);
rc = zmq_setsockopt (sb, ZMQ_IPV6, &ipv6, sizeof (int));
assert (rc == 0);
rc = zmq_setsockopt (sc, ZMQ_IPV6, &ipv6, sizeof (int));
assert (rc == 0);
TEST_ASSERT_SUCCESS_ERRNO (
zmq_setsockopt (sb, ZMQ_IPV6, &ipv6, sizeof (int)));
TEST_ASSERT_SUCCESS_ERRNO (
zmq_setsockopt (sc, ZMQ_IPV6, &ipv6, sizeof (int)));
rc = zmq_bind (sb, "tcp://*:*");
assert (rc == 0);
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb, "tcp://*:*"));
endpoint_len = sizeof (bind_endpoint);
char bind_endpoint[256];
char connect_endpoint[256];
size_t endpoint_len = sizeof (bind_endpoint);
memset (bind_endpoint, 0, endpoint_len);
rc = zmq_getsockopt (sb, ZMQ_LAST_ENDPOINT, bind_endpoint, &endpoint_len);
assert (rc == 0);
TEST_ASSERT_SUCCESS_ERRNO (
zmq_getsockopt (sb, ZMQ_LAST_ENDPOINT, bind_endpoint, &endpoint_len));
#ifdef ZMQ_HAVE_WINDOWS
if (ipv6)
......@@ -94,123 +96,116 @@ int main (void)
strcpy (connect_endpoint, bind_endpoint);
#endif
rc = zmq_connect (sc, connect_endpoint);
assert (rc == 0);
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sc, connect_endpoint));
bounce (sb, sc);
rc = zmq_disconnect (sc, connect_endpoint);
assert (rc == 0);
rc = zmq_unbind (sb, bind_endpoint);
assert (rc == 0);
TEST_ASSERT_SUCCESS_ERRNO (zmq_disconnect (sc, connect_endpoint));
TEST_ASSERT_SUCCESS_ERRNO (zmq_unbind (sb, bind_endpoint));
rc = zmq_close (sc);
assert (rc == 0);
rc = zmq_close (sb);
assert (rc == 0);
test_context_socket_close (sc);
test_context_socket_close (sb);
}
void test_port_wildcard_ipv4_address ()
{
/* Port wildcard, IPv4 address, IPv6 disabled */
sb = zmq_socket (ctx, ZMQ_REP);
assert (sb);
sc = zmq_socket (ctx, ZMQ_REQ);
assert (sc);
void *sb = test_context_socket (ZMQ_REP);
void *sc = test_context_socket (ZMQ_REQ);
rc = zmq_bind (sb, "tcp://127.0.0.1:*");
assert (rc == 0);
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb, "tcp://127.0.0.1:*"));
char endpoint[256];
endpoint_len = sizeof (endpoint);
size_t endpoint_len = sizeof (endpoint);
memset (endpoint, 0, endpoint_len);
rc = zmq_getsockopt (sb, ZMQ_LAST_ENDPOINT, endpoint, &endpoint_len);
assert (rc == 0);
TEST_ASSERT_SUCCESS_ERRNO (
zmq_getsockopt (sb, ZMQ_LAST_ENDPOINT, endpoint, &endpoint_len));
rc = zmq_connect (sc, endpoint);
assert (rc == 0);
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sc, endpoint));
bounce (sb, sc);
rc = zmq_disconnect (sc, endpoint);
assert (rc == 0);
rc = zmq_unbind (sb, endpoint);
assert (rc == 0);
TEST_ASSERT_SUCCESS_ERRNO (zmq_disconnect (sc, endpoint));
TEST_ASSERT_SUCCESS_ERRNO (zmq_unbind (sb, endpoint));
rc = zmq_close (sc);
assert (rc == 0);
rc = zmq_close (sb);
assert (rc == 0);
test_context_socket_close (sc);
test_context_socket_close (sb);
}
void test_port_wildcard_ipv4_address_ipv6 ()
{
/* Port wildcard, IPv4 address, IPv6 enabled */
sb = zmq_socket (ctx, ZMQ_REP);
assert (sb);
sc = zmq_socket (ctx, ZMQ_REQ);
assert (sc);
void *sb = test_context_socket (ZMQ_REP);
void *sc = test_context_socket (ZMQ_REQ);
rc = zmq_setsockopt (sb, ZMQ_IPV6, &ipv6, sizeof (int));
assert (rc == 0);
rc = zmq_setsockopt (sc, ZMQ_IPV6, &ipv6, sizeof (int));
assert (rc == 0);
const int ipv6 = is_ipv6_available ();
TEST_ASSERT_SUCCESS_ERRNO (
zmq_setsockopt (sb, ZMQ_IPV6, &ipv6, sizeof (int)));
TEST_ASSERT_SUCCESS_ERRNO (
zmq_setsockopt (sc, ZMQ_IPV6, &ipv6, sizeof (int)));
rc = zmq_bind (sb, "tcp://127.0.0.1:*");
assert (rc == 0);
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb, "tcp://127.0.0.1:*"));
endpoint_len = sizeof (endpoint);
char endpoint[256];
size_t endpoint_len = sizeof (endpoint);
memset (endpoint, 0, endpoint_len);
rc = zmq_getsockopt (sb, ZMQ_LAST_ENDPOINT, endpoint, &endpoint_len);
assert (rc == 0);
TEST_ASSERT_SUCCESS_ERRNO (
zmq_getsockopt (sb, ZMQ_LAST_ENDPOINT, endpoint, &endpoint_len));
rc = zmq_connect (sc, endpoint);
assert (rc == 0);
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sc, endpoint));
bounce (sb, sc);
rc = zmq_disconnect (sc, endpoint);
assert (rc == 0);
rc = zmq_unbind (sb, endpoint);
assert (rc == 0);
TEST_ASSERT_SUCCESS_ERRNO (zmq_disconnect (sc, endpoint));
TEST_ASSERT_SUCCESS_ERRNO (zmq_unbind (sb, endpoint));
test_context_socket_close (sc);
test_context_socket_close (sb);
}
rc = zmq_close (sc);
assert (rc == 0);
rc = zmq_close (sb);
assert (rc == 0);
void test_port_wildcard_ipv6_address ()
{
const int ipv6 = is_ipv6_available ();
if (!ipv6)
TEST_IGNORE_MESSAGE ("ipv6 is not available");
if (ipv6) {
/* Port wildcard, IPv6 address, IPv6 enabled */
sb = zmq_socket (ctx, ZMQ_REP);
assert (sb);
sc = zmq_socket (ctx, ZMQ_REQ);
assert (sc);
/* Port wildcard, IPv6 address, IPv6 enabled */
void *sb = test_context_socket (ZMQ_REP);
void *sc = test_context_socket (ZMQ_REQ);
rc = zmq_setsockopt (sb, ZMQ_IPV6, &ipv6, sizeof (int));
assert (rc == 0);
rc = zmq_setsockopt (sc, ZMQ_IPV6, &ipv6, sizeof (int));
assert (rc == 0);
TEST_ASSERT_SUCCESS_ERRNO (
zmq_setsockopt (sb, ZMQ_IPV6, &ipv6, sizeof (int)));
TEST_ASSERT_SUCCESS_ERRNO (
zmq_setsockopt (sc, ZMQ_IPV6, &ipv6, sizeof (int)));
rc = zmq_bind (sb, "tcp://[::1]:*");
assert (rc == 0);
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb, "tcp://[::1]:*"));
endpoint_len = sizeof (endpoint);
memset (endpoint, 0, endpoint_len);
rc = zmq_getsockopt (sb, ZMQ_LAST_ENDPOINT, endpoint, &endpoint_len);
assert (rc == 0);
char endpoint[256];
size_t endpoint_len = sizeof (endpoint);
memset (endpoint, 0, endpoint_len);
TEST_ASSERT_SUCCESS_ERRNO (
zmq_getsockopt (sb, ZMQ_LAST_ENDPOINT, endpoint, &endpoint_len));
rc = zmq_connect (sc, endpoint);
assert (rc == 0);
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sc, endpoint));
bounce (sb, sc);
bounce (sb, sc);
rc = zmq_disconnect (sc, endpoint);
assert (rc == 0);
rc = zmq_unbind (sb, endpoint);
assert (rc == 0);
TEST_ASSERT_SUCCESS_ERRNO (zmq_disconnect (sc, endpoint));
TEST_ASSERT_SUCCESS_ERRNO (zmq_unbind (sb, endpoint));
rc = zmq_close (sc);
assert (rc == 0);
rc = zmq_close (sb);
assert (rc == 0);
}
test_context_socket_close (sc);
test_context_socket_close (sb);
}
rc = zmq_ctx_term (ctx);
assert (rc == 0);
int main ()
{
setup_test_environment ();
return 0;
UNITY_BEGIN ();
RUN_TEST (test_address_wildcard_ipv4);
RUN_TEST (test_address_wildcard_ipv6);
RUN_TEST (test_port_wildcard_ipv4_address);
RUN_TEST (test_port_wildcard_ipv4_address_ipv6);
RUN_TEST (test_port_wildcard_ipv6_address);
return UNITY_END ();
}
This diff is collapsed.
This diff is collapsed.
......@@ -118,6 +118,32 @@ void recv_string_expect_success (void *socket_, const char *str_, int flags_)
TEST_ASSERT_EQUAL_STRING_LEN (str_, buffer, len);
}
template <size_t SIZE>
void send_array_expect_success (void *socket_,
const uint8_t (&array_)[SIZE],
int flags_)
{
const int rc = zmq_send (socket_, array_, SIZE, flags_);
TEST_ASSERT_EQUAL_INT (static_cast<int> (SIZE), rc);
}
template <size_t SIZE>
void recv_array_expect_success (void *socket_,
const uint8_t (&array_)[SIZE],
int flags_)
{
char buffer[255];
TEST_ASSERT_LESS_OR_EQUAL_MESSAGE (sizeof (buffer), SIZE,
"recv_string_expect_success cannot be "
"used for strings longer than 255 "
"characters");
const int rc = TEST_ASSERT_SUCCESS_ERRNO (
zmq_recv (socket_, buffer, sizeof (buffer), flags_));
TEST_ASSERT_EQUAL_INT (static_cast<int> (SIZE), rc);
TEST_ASSERT_EQUAL_UINT8_ARRAY (array_, buffer, SIZE);
}
// do not call from tests directly, use setup_test_context, get_test_context and teardown_test_context only
void *internal_manage_test_context (bool init_, bool clear_)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment