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 \ ...@@ -455,7 +455,8 @@ external_unity_libunity_a_SOURCES = external/unity/unity.c \
external/unity/unity_internals.h external/unity/unity_internals.h
tests_test_ancillaries_SOURCES = tests/test_ancillaries.cpp 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_SOURCES = tests/test_system.cpp
tests_test_system_LDADD = src/libzmq.la tests_test_system_LDADD = src/libzmq.la
...@@ -468,7 +469,8 @@ tests_test_pair_inproc_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_SOURCES = \
tests/test_pair_tcp.cpp \ tests/test_pair_tcp.cpp \
tests/testutil.hpp 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_SOURCES = \
tests/test_reqrep_inproc.cpp \ tests/test_reqrep_inproc.cpp \
...@@ -542,10 +544,12 @@ tests_test_probe_router_LDADD = src/libzmq.la ${UNITY_LIBS} ...@@ -542,10 +544,12 @@ tests_test_probe_router_LDADD = src/libzmq.la ${UNITY_LIBS}
tests_test_probe_router_CPPFLAGS = ${UNITY_CPPFLAGS} tests_test_probe_router_CPPFLAGS = ${UNITY_CPPFLAGS}
tests_test_stream_SOURCES = tests/test_stream.cpp 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_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_SOURCES = tests/test_stream_timeout.cpp
tests_test_stream_timeout_LDADD = src/libzmq.la tests_test_stream_timeout_LDADD = src/libzmq.la
...@@ -557,7 +561,8 @@ tests_test_disconnect_inproc_SOURCES = tests/test_disconnect_inproc.cpp ...@@ -557,7 +561,8 @@ tests_test_disconnect_inproc_SOURCES = tests/test_disconnect_inproc.cpp
tests_test_disconnect_inproc_LDADD = src/libzmq.la tests_test_disconnect_inproc_LDADD = src/libzmq.la
tests_test_unbind_wildcard_SOURCES = tests/test_unbind_wildcard.cpp 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_SOURCES = tests/test_ctx_options.cpp
tests_test_ctx_options_LDADD = src/libzmq.la tests_test_ctx_options_LDADD = src/libzmq.la
...@@ -596,10 +601,12 @@ tests_test_spec_router_LDADD = src/libzmq.la ${UNITY_LIBS} ...@@ -596,10 +601,12 @@ tests_test_spec_router_LDADD = src/libzmq.la ${UNITY_LIBS}
tests_test_spec_router_CPPFLAGS = ${UNITY_CPPFLAGS} tests_test_spec_router_CPPFLAGS = ${UNITY_CPPFLAGS}
tests_test_spec_pushpull_SOURCES = tests/test_spec_pushpull.cpp 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_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_SOURCES = tests/test_req_relaxed.cpp
tests_test_req_relaxed_LDADD = src/libzmq.la tests_test_req_relaxed_LDADD = src/libzmq.la
...@@ -645,14 +652,16 @@ tests_test_metadata_SOURCES = tests/test_metadata.cpp ...@@ -645,14 +652,16 @@ tests_test_metadata_SOURCES = tests/test_metadata.cpp
tests_test_metadata_LDADD = src/libzmq.la tests_test_metadata_LDADD = src/libzmq.la
tests_test_capabilities_SOURCES = tests/test_capabilities.cpp 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_SOURCES = tests/test_xpub_nodrop.cpp
tests_test_xpub_nodrop_LDADD = src/libzmq.la ${UNITY_LIBS} tests_test_xpub_nodrop_LDADD = src/libzmq.la ${UNITY_LIBS}
tests_test_xpub_nodrop_CPPFLAGS = ${UNITY_CPPFLAGS} tests_test_xpub_nodrop_CPPFLAGS = ${UNITY_CPPFLAGS}
tests_test_xpub_manual_SOURCES = tests/test_xpub_manual.cpp 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_SOURCES = tests/test_xpub_welcome_msg.cpp
tests_test_xpub_welcome_msg_LDADD = src/libzmq.la 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} ...@@ -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_bind_after_connect_tcp_CPPFLAGS = ${UNITY_CPPFLAGS}
tests_test_base85_SOURCES = tests/test_base85.cpp 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_SOURCES = tests/test_sodium.cpp
tests_test_sodium_LDADD = src/libzmq.la tests_test_sodium_LDADD = src/libzmq.la
......
...@@ -35,16 +35,37 @@ ...@@ -35,16 +35,37 @@
*/ */
#include "testutil.hpp" #include "testutil.hpp"
#include "testutil_unity.hpp"
int main (void) void setUp ()
{
}
void tearDown ()
{
}
void test_version ()
{ {
int major, minor, patch; int major, minor, patch;
zmq_version (&major, &minor, &patch); zmq_version (&major, &minor, &patch);
assert (major == ZMQ_VERSION_MAJOR && minor == ZMQ_VERSION_MINOR TEST_ASSERT_EQUAL_INT (ZMQ_VERSION_MAJOR, major);
&& patch == ZMQ_VERSION_PATCH); TEST_ASSERT_EQUAL_INT (ZMQ_VERSION_MINOR, minor);
TEST_ASSERT_EQUAL_INT (ZMQ_VERSION_PATCH, patch);
}
void test_strerrror ()
{
assert (zmq_strerror (EINVAL)); 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 @@ ...@@ -28,6 +28,15 @@
*/ */
#include "testutil.hpp" #include "testutil.hpp"
#include "testutil_unity.hpp"
void setUp ()
{
}
void tearDown ()
{
}
// Test vector: rfc.zeromq.org/spec:32/Z85 // Test vector: rfc.zeromq.org/spec:32/Z85
void test__zmq_z85_encode__valid__success () void test__zmq_z85_encode__valid__success ()
...@@ -40,17 +49,17 @@ void test__zmq_z85_encode__valid__success () ...@@ -40,17 +49,17 @@ void test__zmq_z85_encode__valid__success ()
char out_encoded[length + 1] = {0}; char out_encoded[length + 1] = {0};
errno = 0; errno = 0;
assert (zmq_z85_encode (out_encoded, decoded, size) != NULL); TEST_ASSERT_NOT_NULL (zmq_z85_encode (out_encoded, decoded, size));
assert (streq (out_encoded, expected)); TEST_ASSERT_EQUAL_STRING (expected, out_encoded);
assert (zmq_errno () == 0); TEST_ASSERT_EQUAL_INT (0, zmq_errno ());
} }
// Buffer length must be evenly divisible by 4 or must fail with EINVAL. // Buffer length must be evenly divisible by 4 or must fail with EINVAL.
void test__zmq_z85_encode__invalid__failure (size_t size_) void test__zmq_z85_encode__invalid__failure (size_t size_)
{ {
errno = 0; errno = 0;
assert (zmq_z85_encode (NULL, NULL, size_) == NULL); TEST_ASSERT_NULL (zmq_z85_encode (NULL, NULL, size_));
assert (zmq_errno () == EINVAL); TEST_ASSERT_EQUAL_INT (EINVAL, zmq_errno ());
} }
// Test vector: rfc.zeromq.org/spec:32/Z85 // Test vector: rfc.zeromq.org/spec:32/Z85
...@@ -63,9 +72,9 @@ void test__zmq_z85_decode__valid__success () ...@@ -63,9 +72,9 @@ void test__zmq_z85_decode__valid__success ()
uint8_t out_decoded[size] = {0}; uint8_t out_decoded[size] = {0};
errno = 0; errno = 0;
assert (zmq_z85_decode (out_decoded, encoded) != NULL); TEST_ASSERT_NOT_NULL (zmq_z85_decode (out_decoded, encoded));
assert (zmq_errno () == 0); TEST_ASSERT_EQUAL_INT (0, zmq_errno ());
assert (memcmp (out_decoded, expected, size) == 0); TEST_ASSERT_EQUAL_UINT8_ARRAY (expected, out_decoded, size);
} }
// Invalid input data must fail with EINVAL. // Invalid input data must fail with EINVAL.
...@@ -74,8 +83,8 @@ void test__zmq_z85_decode__invalid__failure (const char (&encoded_)[SIZE]) ...@@ -74,8 +83,8 @@ void test__zmq_z85_decode__invalid__failure (const char (&encoded_)[SIZE])
{ {
uint8_t decoded[SIZE * 4 / 5 + 1]; uint8_t decoded[SIZE * 4 / 5 + 1];
errno = 0; errno = 0;
assert (zmq_z85_decode (decoded, encoded_) == NULL); TEST_ASSERT_NULL (zmq_z85_decode (decoded, encoded_));
assert (zmq_errno () == EINVAL); TEST_ASSERT_EQUAL_INT (EINVAL, zmq_errno ());
} }
...@@ -86,14 +95,13 @@ void test__zmq_z85_encode__zmq_z85_decode__roundtrip ( ...@@ -86,14 +95,13 @@ void test__zmq_z85_encode__zmq_z85_decode__roundtrip (
{ {
char test_data_z85[SIZE * 5 / 4 + 1]; char test_data_z85[SIZE * 5 / 4 + 1];
char *res1 = zmq_z85_encode (test_data_z85, test_data_, SIZE); 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 test_data_decoded[SIZE];
uint8_t *res2 = zmq_z85_decode (test_data_decoded, test_data_z85); 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); TEST_ASSERT_EQUAL_UINT8_ARRAY (test_data_, test_data_decoded, SIZE);
assert (res3 == 0);
} }
// call zmq_z85_encode, then zmq_z85_decode, and compare the results with the original // 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 ( ...@@ -104,61 +112,92 @@ void test__zmq_z85_decode__zmq_z85_encode__roundtrip (
const size_t decoded_size = (SIZE - 1) * 4 / 5; const size_t decoded_size = (SIZE - 1) * 4 / 5;
uint8_t test_data_decoded[decoded_size]; uint8_t test_data_decoded[decoded_size];
uint8_t *res1 = zmq_z85_decode (test_data_decoded, test_data_); 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 test_data_z85[SIZE];
char *res2 = char *res2 =
zmq_z85_encode (test_data_z85, test_data_decoded, decoded_size); 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); TEST_ASSERT_EQUAL_UINT8_ARRAY (test_data_, test_data_z85, SIZE);
assert (res3 == 0);
} }
#define def_test__zmq_z85_basename(basename, name, param) \
int main (void) void test__zmq_z85_##basename##_##name () \
{ { \
test__zmq_z85_encode__valid__success (); test__zmq_z85_##basename (param); \
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);
} }
test__zmq_z85_decode__zmq_z85_encode__roundtrip ( #define def_test__zmq_z85_encode__invalid__failure(name, param) \
"r^/rM9M=rMToK)63O8dCvd9D<PY<7iGlC+{BiSnG"); 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 @@ ...@@ -28,55 +28,72 @@
*/ */
#include "testutil.hpp" #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) #if !defined(ZMQ_HAVE_WINDOWS) && !defined(ZMQ_HAVE_OPENVMS)
assert (zmq_has ("ipc")); TEST_ASSERT_TRUE (zmq_has ("ipc"));
#else #else
assert (!zmq_has ("ipc")); TEST_ASSERT_TRUE (!zmq_has ("ipc"));
#endif #endif
#if defined(ZMQ_HAVE_OPENPGM) #if defined(ZMQ_HAVE_OPENPGM)
assert (zmq_has ("pgm")); TEST_ASSERT_TRUE (zmq_has ("pgm"));
#else #else
assert (!zmq_has ("pgm")); TEST_ASSERT_TRUE (!zmq_has ("pgm"));
#endif #endif
#if defined(ZMQ_HAVE_TIPC) #if defined(ZMQ_HAVE_TIPC)
assert (zmq_has ("tipc")); TEST_ASSERT_TRUE (zmq_has ("tipc"));
#else #else
assert (!zmq_has ("tipc")); TEST_ASSERT_TRUE (!zmq_has ("tipc"));
#endif #endif
#if defined(ZMQ_HAVE_NORM) #if defined(ZMQ_HAVE_NORM)
assert (zmq_has ("norm")); TEST_ASSERT_TRUE (zmq_has ("norm"));
#else #else
assert (!zmq_has ("norm")); TEST_ASSERT_TRUE (!zmq_has ("norm"));
#endif #endif
#if defined(ZMQ_HAVE_CURVE) #if defined(ZMQ_HAVE_CURVE)
assert (zmq_has ("curve")); TEST_ASSERT_TRUE (zmq_has ("curve"));
#else #else
assert (!zmq_has ("curve")); TEST_ASSERT_TRUE (!zmq_has ("curve"));
#endif #endif
#if defined(HAVE_LIBGSSAPI_KRB5) #if defined(HAVE_LIBGSSAPI_KRB5)
assert (zmq_has ("gssapi")); TEST_ASSERT_TRUE (zmq_has ("gssapi"));
#else #else
assert (!zmq_has ("gssapi")); TEST_ASSERT_TRUE (!zmq_has ("gssapi"));
#endif #endif
#if defined(ZMQ_HAVE_VMCI) #if defined(ZMQ_HAVE_VMCI)
assert (zmq_has ("vmci")); TEST_ASSERT_TRUE (zmq_has ("vmci"));
#else #else
assert (!zmq_has ("vmci")); TEST_ASSERT_TRUE (!zmq_has ("vmci"));
#endif #endif
#if defined(ZMQ_BUILD_DRAFT_API) #if defined(ZMQ_BUILD_DRAFT_API)
assert (zmq_has ("draft")); TEST_ASSERT_TRUE (zmq_has ("draft"));
#else #else
assert (!zmq_has ("draft")); TEST_ASSERT_TRUE (!zmq_has ("draft"));
#endif #endif
return 0; }
int main ()
{
setup_test_environment ();
UNITY_BEGIN ();
RUN_TEST (test_capabilities);
return UNITY_END ();
} }
...@@ -28,6 +28,18 @@ ...@@ -28,6 +28,18 @@
*/ */
#include "testutil.hpp" #include "testutil.hpp"
#include "testutil_unity.hpp"
void setUp ()
{
setup_test_context ();
}
void tearDown ()
{
teardown_test_context ();
}
typedef void (*extra_func_t) (void *socket_); typedef void (*extra_func_t) (void *socket_);
...@@ -43,50 +55,47 @@ void set_sockopt_fastpath (void *socket) ...@@ -43,50 +55,47 @@ void set_sockopt_fastpath (void *socket)
void test_pair_tcp (extra_func_t extra_func_ = NULL) void test_pair_tcp (extra_func_t extra_func_ = NULL)
{ {
size_t len = MAX_SOCKET_STRING; void *sb = test_context_socket (ZMQ_PAIR);
char my_endpoint[MAX_SOCKET_STRING];
void *ctx = zmq_ctx_new ();
assert (ctx);
void *sb = zmq_socket (ctx, ZMQ_PAIR);
assert (sb);
if (extra_func_) if (extra_func_)
extra_func_ (sb); extra_func_ (sb);
int rc = zmq_bind (sb, "tcp://127.0.0.1:*"); char my_endpoint[MAX_SOCKET_STRING];
assert (rc == 0); bind_loopback_ipv4 (sb, my_endpoint, sizeof my_endpoint);
rc = zmq_getsockopt (sb, ZMQ_LAST_ENDPOINT, my_endpoint, &len);
assert (rc == 0);
void *sc = zmq_socket (ctx, ZMQ_PAIR); void *sc = test_context_socket (ZMQ_PAIR);
assert (sc);
if (extra_func_) if (extra_func_)
extra_func_ (sc); extra_func_ (sc);
rc = zmq_connect (sc, my_endpoint); TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sc, my_endpoint));
assert (rc == 0);
bounce (sb, sc); bounce (sb, sc);
rc = zmq_close (sc); test_context_socket_close (sc);
assert (rc == 0); test_context_socket_close (sb);
}
rc = zmq_close (sb); void test_pair_tcp_regular ()
assert (rc == 0); {
test_pair_tcp ();
}
rc = zmq_ctx_term (ctx); #ifdef ZMQ_BUILD_DRAFT
assert (rc == 0); void test_pair_tcp_fastpath ()
{
test_pair_tcp (set_sockopt_fastpath);
} }
#endif
int main (void) int main ()
{ {
setup_test_environment (); setup_test_environment ();
test_pair_tcp (); UNITY_BEGIN ();
RUN_TEST (test_pair_tcp_regular);
#ifdef ZMQ_BUILD_DRAFT #ifdef ZMQ_BUILD_DRAFT
test_pair_tcp (set_sockopt_fastpath); RUN_TEST (test_pair_tcp_fastpath);
#endif #endif
return 0; return UNITY_END ();
} }
...@@ -28,36 +28,35 @@ ...@@ -28,36 +28,35 @@
*/ */
#include "testutil.hpp" #include "testutil.hpp"
#include "testutil_unity.hpp"
int main (void) void setUp ()
{ {
setup_test_environment (); setup_test_context ();
size_t len = MAX_SOCKET_STRING; }
char my_endpoint[MAX_SOCKET_STRING];
void *ctx = zmq_ctx_new ();
assert (ctx);
void *req = zmq_socket (ctx, ZMQ_REQ); void tearDown ()
assert (req); {
teardown_test_context ();
}
void *router = zmq_socket (ctx, ZMQ_ROUTER); void test_req_correlate ()
assert (router); {
void *req = test_context_socket (ZMQ_REQ);
void *router = test_context_socket (ZMQ_ROUTER);
int enabled = 1; int enabled = 1;
int rc = zmq_setsockopt (req, ZMQ_REQ_CORRELATE, &enabled, sizeof (int)); TEST_ASSERT_SUCCESS_ERRNO (
assert (rc == 0); zmq_setsockopt (req, ZMQ_REQ_CORRELATE, &enabled, sizeof (int)));
int rcvtimeo = 100; int rcvtimeo = 100;
rc = zmq_setsockopt (req, ZMQ_RCVTIMEO, &rcvtimeo, sizeof (int)); TEST_ASSERT_SUCCESS_ERRNO (
assert (rc == 0); zmq_setsockopt (req, ZMQ_RCVTIMEO, &rcvtimeo, sizeof (int)));
rc = zmq_bind (router, "tcp://127.0.0.1:*"); char my_endpoint[MAX_SOCKET_STRING];
assert (rc == 0); bind_loopback_ipv4 (router, my_endpoint, sizeof my_endpoint);
rc = zmq_getsockopt (router, ZMQ_LAST_ENDPOINT, my_endpoint, &len);
assert (rc == 0);
rc = zmq_connect (req, my_endpoint); TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (req, my_endpoint));
assert (rc == 0);
// Send a multi-part request. // Send a multi-part request.
s_send_seq (req, "ABC", "DEF", SEQ_END); s_send_seq (req, "ABC", "DEF", SEQ_END);
...@@ -66,33 +65,31 @@ int main (void) ...@@ -66,33 +65,31 @@ int main (void)
zmq_msg_init (&msg); zmq_msg_init (&msg);
// Receive peer routing id // Receive peer routing id
rc = zmq_msg_recv (&msg, router, 0); TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_recv (&msg, router, 0));
assert (rc != -1); TEST_ASSERT_GREATER_THAN_INT (0, zmq_msg_size (&msg));
assert (zmq_msg_size (&msg) > 0);
zmq_msg_t peer_id_msg; zmq_msg_t peer_id_msg;
zmq_msg_init (&peer_id_msg); zmq_msg_init (&peer_id_msg);
zmq_msg_copy (&peer_id_msg, &msg); zmq_msg_copy (&peer_id_msg, &msg);
int more = 0; int more = 0;
size_t more_size = sizeof (more); size_t more_size = sizeof (more);
rc = zmq_getsockopt (router, ZMQ_RCVMORE, &more, &more_size); TEST_ASSERT_SUCCESS_ERRNO (
assert (rc == 0); zmq_getsockopt (router, ZMQ_RCVMORE, &more, &more_size));
assert (more); TEST_ASSERT_TRUE (more);
// Receive request id 1 // Receive request id 1
rc = zmq_msg_recv (&msg, router, 0); TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_recv (&msg, router, 0));
assert (rc != -1);
assert (zmq_msg_size (&msg) == sizeof (uint32_t)); 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_t req_id_msg;
zmq_msg_init (&req_id_msg); zmq_msg_init (&req_id_msg);
zmq_msg_copy (&req_id_msg, &msg); zmq_msg_copy (&req_id_msg, &msg);
more = 0; more = 0;
more_size = sizeof (more); more_size = sizeof (more);
rc = zmq_getsockopt (router, ZMQ_RCVMORE, &more, &more_size); TEST_ASSERT_SUCCESS_ERRNO (
assert (rc == 0); zmq_getsockopt (router, ZMQ_RCVMORE, &more, &more_size));
assert (more); TEST_ASSERT_TRUE (more);
// Receive the rest. // Receive the rest.
s_recv_seq (router, 0, "ABC", "DEF", SEQ_END); s_recv_seq (router, 0, "ABC", "DEF", SEQ_END);
...@@ -101,40 +98,35 @@ int main (void) ...@@ -101,40 +98,35 @@ int main (void)
// Send back a bad reply: wrong req id, 0, data // Send back a bad reply: wrong req id, 0, data
zmq_msg_copy (&msg, &peer_id_msg); zmq_msg_copy (&msg, &peer_id_msg);
rc = zmq_msg_send (&msg, router, ZMQ_SNDMORE); TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_send (&msg, router, ZMQ_SNDMORE));
assert (rc != -1);
zmq_msg_init_data (&msg, &bad_req_id, sizeof (uint32_t), NULL, NULL); zmq_msg_init_data (&msg, &bad_req_id, sizeof (uint32_t), NULL, NULL);
rc = zmq_msg_send (&msg, router, ZMQ_SNDMORE); TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_send (&msg, router, ZMQ_SNDMORE));
assert (rc != -1);
s_send_seq (router, 0, "DATA", SEQ_END); s_send_seq (router, 0, "DATA", SEQ_END);
// Send back a good reply: good req id, 0, data // Send back a good reply: good req id, 0, data
zmq_msg_copy (&msg, &peer_id_msg); zmq_msg_copy (&msg, &peer_id_msg);
rc = zmq_msg_send (&msg, router, ZMQ_SNDMORE); TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_send (&msg, router, ZMQ_SNDMORE));
assert (rc != -1);
zmq_msg_copy (&msg, &req_id_msg); zmq_msg_copy (&msg, &req_id_msg);
rc = zmq_msg_send (&msg, router, ZMQ_SNDMORE); TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_send (&msg, router, ZMQ_SNDMORE));
assert (rc != -1);
s_send_seq (router, 0, "GHI", SEQ_END); s_send_seq (router, 0, "GHI", SEQ_END);
// Receive reply. If bad reply got through, we wouldn't see // Receive reply. If bad reply got through, we wouldn't see
// this particular data. // this particular data.
s_recv_seq (req, "GHI", SEQ_END); s_recv_seq (req, "GHI", SEQ_END);
rc = zmq_msg_close (&msg); TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_close (&msg));
assert (rc == 0); TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_close (&peer_id_msg));
TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_close (&req_id_msg));
rc = zmq_msg_close (&peer_id_msg);
assert (rc == 0);
rc = zmq_msg_close (&req_id_msg);
assert (rc == 0);
close_zero_linger (req); test_context_socket_close_zero_linger (req);
close_zero_linger (router); test_context_socket_close_zero_linger (router);
}
rc = zmq_ctx_term (ctx); int main ()
assert (rc == 0); {
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 @@ ...@@ -28,48 +28,52 @@
*/ */
#include "testutil.hpp" #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]; char my_endpoint[MAX_SOCKET_STRING];
void *ctx = zmq_ctx_new ();
assert (ctx); void *stream = test_context_socket (ZMQ_STREAM);
void *dealer = test_context_socket (ZMQ_DEALER);
void *stream = zmq_socket (ctx, ZMQ_STREAM);
assert (stream); bind_loopback_ipv4 (stream, my_endpoint, sizeof my_endpoint);
void *dealer = zmq_socket (ctx, ZMQ_DEALER); TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (dealer, my_endpoint));
assert (dealer); send_string_expect_success (dealer, "", 0);
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);
zmq_msg_t ident, empty; zmq_msg_t ident, empty;
zmq_msg_init (&ident); zmq_msg_init (&ident);
rc = zmq_msg_recv (&ident, stream, 0); TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_recv (&ident, stream, 0));
assert (rc >= 0); TEST_ASSERT_SUCCESS_ERRNO (
rc = zmq_msg_init_data (&empty, (void *) "", 0, NULL, NULL); zmq_msg_init_data (&empty, (void *) "", 0, NULL, NULL));
assert (rc >= 0);
rc = zmq_msg_send (&ident, stream, ZMQ_SNDMORE); TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_send (&ident, stream, ZMQ_SNDMORE));
assert (rc >= 0); TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_close (&ident));
rc = zmq_msg_close (&ident);
assert (rc >= 0);
rc = zmq_msg_send (&empty, stream, 0); TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_send (&empty, stream, 0));
assert (rc >= 0);
// This close used to fail with Bad Address // This close used to fail with Bad Address
rc = zmq_msg_close (&empty); TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_close (&empty));
assert (rc >= 0);
test_context_socket_close_zero_linger (dealer);
test_context_socket_close_zero_linger (stream);
}
int main ()
{
setup_test_environment ();
close_zero_linger (dealer); UNITY_BEGIN ();
close_zero_linger (stream); RUN_TEST (test_stream_empty);
zmq_ctx_term (ctx); return UNITY_END ();
} }
...@@ -18,28 +18,31 @@ ...@@ -18,28 +18,31 @@
*/ */
#include "testutil.hpp" #include "testutil.hpp"
#include "testutil_unity.hpp"
int main (void) void setUp ()
{ {
setup_test_environment (); setup_test_context ();
void *ctx = zmq_ctx_new (); }
assert (ctx);
int ipv6 = is_ipv6_available ();
void tearDown ()
{
teardown_test_context ();
}
void test_address_wildcard_ipv4 ()
{
/* Address wildcard, IPv6 disabled */ /* Address wildcard, IPv6 disabled */
void *sb = zmq_socket (ctx, ZMQ_REP); void *sb = test_context_socket (ZMQ_REP);
assert (sb); void *sc = test_context_socket (ZMQ_REQ);
void *sc = zmq_socket (ctx, ZMQ_REQ);
assert (sc);
int rc = zmq_bind (sb, "tcp://*:*"); TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb, "tcp://*:*"));
assert (rc == 0);
char bind_endpoint[256]; char bind_endpoint[256];
char connect_endpoint[256]; char connect_endpoint[256];
size_t endpoint_len = sizeof (bind_endpoint); size_t endpoint_len = sizeof (bind_endpoint);
rc = zmq_getsockopt (sb, ZMQ_LAST_ENDPOINT, bind_endpoint, &endpoint_len); TEST_ASSERT_SUCCESS_ERRNO (
assert (rc == 0); 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. // Apparently Windows can't connect to 0.0.0.0. A better fix would be welcome.
#ifdef ZMQ_HAVE_WINDOWS #ifdef ZMQ_HAVE_WINDOWS
...@@ -49,39 +52,38 @@ int main (void) ...@@ -49,39 +52,38 @@ int main (void)
strcpy (connect_endpoint, bind_endpoint); strcpy (connect_endpoint, bind_endpoint);
#endif #endif
rc = zmq_connect (sc, connect_endpoint); TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sc, connect_endpoint));
assert (rc == 0);
bounce (sb, sc); bounce (sb, sc);
rc = zmq_disconnect (sc, connect_endpoint); TEST_ASSERT_SUCCESS_ERRNO (zmq_disconnect (sc, connect_endpoint));
assert (rc == 0); TEST_ASSERT_SUCCESS_ERRNO (zmq_unbind (sb, bind_endpoint));
rc = zmq_unbind (sb, bind_endpoint);
assert (rc == 0);
rc = zmq_close (sc); test_context_socket_close (sc);
assert (rc == 0); test_context_socket_close (sb);
rc = zmq_close (sb); }
assert (rc == 0);
void test_address_wildcard_ipv6 ()
{
int ipv6 = is_ipv6_available ();
/* Address wildcard, IPv6 enabled */ /* Address wildcard, IPv6 enabled */
sb = zmq_socket (ctx, ZMQ_REP); void *sb = test_context_socket (ZMQ_REP);
assert (sb); void *sc = test_context_socket (ZMQ_REQ);
sc = zmq_socket (ctx, ZMQ_REQ);
assert (sc);
rc = zmq_setsockopt (sb, ZMQ_IPV6, &ipv6, sizeof (int)); TEST_ASSERT_SUCCESS_ERRNO (
assert (rc == 0); zmq_setsockopt (sb, ZMQ_IPV6, &ipv6, sizeof (int)));
rc = zmq_setsockopt (sc, ZMQ_IPV6, &ipv6, sizeof (int)); TEST_ASSERT_SUCCESS_ERRNO (
assert (rc == 0); zmq_setsockopt (sc, ZMQ_IPV6, &ipv6, sizeof (int)));
rc = zmq_bind (sb, "tcp://*:*"); TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb, "tcp://*:*"));
assert (rc == 0);
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); memset (bind_endpoint, 0, endpoint_len);
rc = zmq_getsockopt (sb, ZMQ_LAST_ENDPOINT, bind_endpoint, &endpoint_len); TEST_ASSERT_SUCCESS_ERRNO (
assert (rc == 0); zmq_getsockopt (sb, ZMQ_LAST_ENDPOINT, bind_endpoint, &endpoint_len));
#ifdef ZMQ_HAVE_WINDOWS #ifdef ZMQ_HAVE_WINDOWS
if (ipv6) if (ipv6)
...@@ -94,123 +96,116 @@ int main (void) ...@@ -94,123 +96,116 @@ int main (void)
strcpy (connect_endpoint, bind_endpoint); strcpy (connect_endpoint, bind_endpoint);
#endif #endif
rc = zmq_connect (sc, connect_endpoint); TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sc, connect_endpoint));
assert (rc == 0);
bounce (sb, sc); bounce (sb, sc);
rc = zmq_disconnect (sc, connect_endpoint); TEST_ASSERT_SUCCESS_ERRNO (zmq_disconnect (sc, connect_endpoint));
assert (rc == 0); TEST_ASSERT_SUCCESS_ERRNO (zmq_unbind (sb, bind_endpoint));
rc = zmq_unbind (sb, bind_endpoint);
assert (rc == 0);
rc = zmq_close (sc); test_context_socket_close (sc);
assert (rc == 0); test_context_socket_close (sb);
rc = zmq_close (sb); }
assert (rc == 0);
void test_port_wildcard_ipv4_address ()
{
/* Port wildcard, IPv4 address, IPv6 disabled */ /* Port wildcard, IPv4 address, IPv6 disabled */
sb = zmq_socket (ctx, ZMQ_REP); void *sb = test_context_socket (ZMQ_REP);
assert (sb); void *sc = test_context_socket (ZMQ_REQ);
sc = zmq_socket (ctx, ZMQ_REQ);
assert (sc);
rc = zmq_bind (sb, "tcp://127.0.0.1:*"); TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb, "tcp://127.0.0.1:*"));
assert (rc == 0);
char endpoint[256]; char endpoint[256];
endpoint_len = sizeof (endpoint); size_t endpoint_len = sizeof (endpoint);
memset (endpoint, 0, endpoint_len); memset (endpoint, 0, endpoint_len);
rc = zmq_getsockopt (sb, ZMQ_LAST_ENDPOINT, endpoint, &endpoint_len); TEST_ASSERT_SUCCESS_ERRNO (
assert (rc == 0); zmq_getsockopt (sb, ZMQ_LAST_ENDPOINT, endpoint, &endpoint_len));
rc = zmq_connect (sc, endpoint); TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sc, endpoint));
assert (rc == 0);
bounce (sb, sc); bounce (sb, sc);
rc = zmq_disconnect (sc, endpoint); TEST_ASSERT_SUCCESS_ERRNO (zmq_disconnect (sc, endpoint));
assert (rc == 0); TEST_ASSERT_SUCCESS_ERRNO (zmq_unbind (sb, endpoint));
rc = zmq_unbind (sb, endpoint);
assert (rc == 0);
rc = zmq_close (sc); test_context_socket_close (sc);
assert (rc == 0); test_context_socket_close (sb);
rc = zmq_close (sb); }
assert (rc == 0);
void test_port_wildcard_ipv4_address_ipv6 ()
{
/* Port wildcard, IPv4 address, IPv6 enabled */ /* Port wildcard, IPv4 address, IPv6 enabled */
sb = zmq_socket (ctx, ZMQ_REP); void *sb = test_context_socket (ZMQ_REP);
assert (sb); void *sc = test_context_socket (ZMQ_REQ);
sc = zmq_socket (ctx, ZMQ_REQ);
assert (sc);
rc = zmq_setsockopt (sb, ZMQ_IPV6, &ipv6, sizeof (int)); const int ipv6 = is_ipv6_available ();
assert (rc == 0); TEST_ASSERT_SUCCESS_ERRNO (
rc = zmq_setsockopt (sc, ZMQ_IPV6, &ipv6, sizeof (int)); zmq_setsockopt (sb, ZMQ_IPV6, &ipv6, sizeof (int)));
assert (rc == 0); TEST_ASSERT_SUCCESS_ERRNO (
zmq_setsockopt (sc, ZMQ_IPV6, &ipv6, sizeof (int)));
rc = zmq_bind (sb, "tcp://127.0.0.1:*"); TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb, "tcp://127.0.0.1:*"));
assert (rc == 0);
endpoint_len = sizeof (endpoint); char endpoint[256];
size_t endpoint_len = sizeof (endpoint);
memset (endpoint, 0, endpoint_len); memset (endpoint, 0, endpoint_len);
rc = zmq_getsockopt (sb, ZMQ_LAST_ENDPOINT, endpoint, &endpoint_len); TEST_ASSERT_SUCCESS_ERRNO (
assert (rc == 0); zmq_getsockopt (sb, ZMQ_LAST_ENDPOINT, endpoint, &endpoint_len));
rc = zmq_connect (sc, endpoint); TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sc, endpoint));
assert (rc == 0);
bounce (sb, sc); bounce (sb, sc);
rc = zmq_disconnect (sc, endpoint); TEST_ASSERT_SUCCESS_ERRNO (zmq_disconnect (sc, endpoint));
assert (rc == 0); TEST_ASSERT_SUCCESS_ERRNO (zmq_unbind (sb, endpoint));
rc = zmq_unbind (sb, endpoint);
assert (rc == 0); test_context_socket_close (sc);
test_context_socket_close (sb);
}
rc = zmq_close (sc); void test_port_wildcard_ipv6_address ()
assert (rc == 0); {
rc = zmq_close (sb); const int ipv6 = is_ipv6_available ();
assert (rc == 0); if (!ipv6)
TEST_IGNORE_MESSAGE ("ipv6 is not available");
if (ipv6) { /* Port wildcard, IPv6 address, IPv6 enabled */
/* Port wildcard, IPv6 address, IPv6 enabled */ void *sb = test_context_socket (ZMQ_REP);
sb = zmq_socket (ctx, ZMQ_REP); void *sc = test_context_socket (ZMQ_REQ);
assert (sb);
sc = zmq_socket (ctx, ZMQ_REQ);
assert (sc);
rc = zmq_setsockopt (sb, ZMQ_IPV6, &ipv6, sizeof (int)); TEST_ASSERT_SUCCESS_ERRNO (
assert (rc == 0); zmq_setsockopt (sb, ZMQ_IPV6, &ipv6, sizeof (int)));
rc = zmq_setsockopt (sc, ZMQ_IPV6, &ipv6, sizeof (int)); TEST_ASSERT_SUCCESS_ERRNO (
assert (rc == 0); zmq_setsockopt (sc, ZMQ_IPV6, &ipv6, sizeof (int)));
rc = zmq_bind (sb, "tcp://[::1]:*"); TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb, "tcp://[::1]:*"));
assert (rc == 0);
endpoint_len = sizeof (endpoint); char endpoint[256];
memset (endpoint, 0, endpoint_len); size_t endpoint_len = sizeof (endpoint);
rc = zmq_getsockopt (sb, ZMQ_LAST_ENDPOINT, endpoint, &endpoint_len); memset (endpoint, 0, endpoint_len);
assert (rc == 0); TEST_ASSERT_SUCCESS_ERRNO (
zmq_getsockopt (sb, ZMQ_LAST_ENDPOINT, endpoint, &endpoint_len));
rc = zmq_connect (sc, endpoint); TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sc, endpoint));
assert (rc == 0);
bounce (sb, sc); bounce (sb, sc);
rc = zmq_disconnect (sc, endpoint); TEST_ASSERT_SUCCESS_ERRNO (zmq_disconnect (sc, endpoint));
assert (rc == 0); TEST_ASSERT_SUCCESS_ERRNO (zmq_unbind (sb, endpoint));
rc = zmq_unbind (sb, endpoint);
assert (rc == 0);
rc = zmq_close (sc); test_context_socket_close (sc);
assert (rc == 0); test_context_socket_close (sb);
rc = zmq_close (sb); }
assert (rc == 0);
}
rc = zmq_ctx_term (ctx); int main ()
assert (rc == 0); {
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_) ...@@ -118,6 +118,32 @@ void recv_string_expect_success (void *socket_, const char *str_, int flags_)
TEST_ASSERT_EQUAL_STRING_LEN (str_, buffer, len); 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 // 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_) 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